test_class.file: tool/hash/src/test/java/org/openscience/cdk/hash/stereo/GeometricTetrahedralEncoderFactoryTest.java
test_class.identifier: GeometricTetrahedralEncoderFactoryTest
test_case.body: @Test
      public void testCreate_3D_Implicit() throws Exception {
  
          IAtomContainer container = mock(IAtomContainer.class);
          when(container.getAtomCount()).thenReturn(4);
  
          IAtom c1 = mock(IAtom.class);
          IAtom o2 = mock(IAtom.class);
          IAtom n3 = mock(IAtom.class);
          IAtom c4 = mock(IAtom.class);
  
          when(container.getAtom(0)).thenReturn(c1);
          when(container.getAtom(1)).thenReturn(o2);
          when(container.getAtom(2)).thenReturn(n3);
          when(container.getAtom(3)).thenReturn(c4);
  
          Point3d p1 = new Point3d(1.23, -0.29, 0);
          Point3d p2 = new Point3d(-0.30, -0.29, 0);
          Point3d p3 = new Point3d(2.00, -1.63, 0);
          Point3d p4 = new Point3d(2.00, 1.03, 0);
  
          when(c1.getPoint3d()).thenReturn(p1);
          when(o2.getPoint3d()).thenReturn(p2);
          when(n3.getPoint3d()).thenReturn(p3);
          when(c4.getPoint3d()).thenReturn(p4);
  
          IBond c1c4 = mock(IBond.class);
          IBond c1o2 = mock(IBond.class);
          IBond c1n3 = mock(IBond.class);
  
          int[][] graph = new int[][]{{1, 2, 3}, {0}, {0}, {0}};
  
          when(container.getConnectedBondsList(c1)).thenReturn(Arrays.asList(c1c4, c1o2, c1n3));
  
          // let's say c1 is a chiral carbon
          when(c1.getHybridization()).thenReturn(IAtomType.Hybridization.SP3);
          // with a hatch bond from c1 to n3
          when(c1n3.getStereo()).thenReturn(NONE);
          when(c1n3.getBegin()).thenReturn(c1);
          when(c1n3.getEnd()).thenReturn(n3);
          when(c1o2.getStereo()).thenReturn(NONE);
          when(c1o2.getBegin()).thenReturn(c1);
          when(c1o2.getEnd()).thenReturn(o2);
          when(c1c4.getStereo()).thenReturn(NONE);
          when(c1c4.getBegin()).thenReturn(c1);
          when(c1c4.getEnd()).thenReturn(c4);
  
          StereoEncoder encoder = new GeometricTetrahedralEncoderFactory().create(container, graph);
  
          assertThat(extractEncoders(encoder).size(), is(1));
  
          GeometricParity geometricParity = getGeometricParity(extractEncoders(encoder).get(0));
  
          assertTrue(geometricParity instanceof Tetrahedral3DParity);
  
          assertThat(coords3D(geometricParity), CoreMatchers.is(new Point3d[]{p2, p3, p4, p1 // p1 = central atom
                  }));
  
      }
test_case.class_method_signature: GeometricTetrahedralEncoderFactoryTest.testCreate_3D_Implicit()
test_case.full_signature: @Test public void testCreate_3D_Implicit()
test_case.identifier: testCreate_3D_Implicit
test_case.invocations: mock thenReturn when getAtomCount mock mock mock mock thenReturn when getAtom thenReturn when getAtom thenReturn when getAtom thenReturn when getAtom thenReturn when getPoint3d thenReturn when getPoint3d thenReturn when getPoint3d thenReturn when getPoint3d mock mock mock thenReturn when getConnectedBondsList asList thenReturn when getHybridization thenReturn when getStereo thenReturn when getBegin thenReturn when getEnd thenReturn when getStereo thenReturn when getBegin thenReturn when getEnd thenReturn when getStereo thenReturn when getBegin thenReturn when getEnd create assertThat size extractEncoders is getGeometricParity get extractEncoders assertTrue assertThat coords3D is
test_case.modifiers: @Test public
test_case.parameters: ()
test_case.return: void
test_case.signature: void testCreate_3D_Implicit()
focal_class.file: tool/hash/src/main/java/org/openscience/cdk/hash/stereo/GeometricTetrahedralEncoderFactory.java
focal_class.identifier: GeometricTetrahedralEncoderFactory
focal_class.interfaces: implements StereoEncoderFactory
focal_class.class_method_signature: GeometricTetrahedralEncoderFactory.create(IAtomContainer container, int[][] graph)
focal_class.full_signature: @Override public StereoEncoder create(IAtomContainer container, int[][] graph)
focal_class.identifier: create
focal_class.modifiers: @Override public
focal_class.parameters: (IAtomContainer container, int[][] graph)
focal_class.return: StereoEncoder
focal_class.signature: StereoEncoder create(IAtomContainer container, int[][] graph)
focal_class.class_method_signature: GeometricTetrahedralEncoderFactory.geometric(Map<IAtom, Integer> elevationMap, List<IBond> bonds, int i,
              int[] adjacent, IAtomContainer container)
focal_class.full_signature: private static GeometricParity geometric(Map<IAtom, Integer> elevationMap, List<IBond> bonds, int i,
              int[] adjacent, IAtomContainer container)
focal_class.identifier: geometric
focal_class.modifiers: private static
focal_class.parameters: (Map<IAtom, Integer> elevationMap, List<IBond> bonds, int i,
              int[] adjacent, IAtomContainer container)
focal_class.return: GeometricParity
focal_class.signature: GeometricParity geometric(Map<IAtom, Integer> elevationMap, List<IBond> bonds, int i,
              int[] adjacent, IAtomContainer container)
focal_class.class_method_signature: GeometricTetrahedralEncoderFactory.geometric2D(Map<IAtom, Integer> elevationMap, List<IBond> bonds, int i,
              int[] adjacent, IAtomContainer container)
focal_class.full_signature: private static GeometricParity geometric2D(Map<IAtom, Integer> elevationMap, List<IBond> bonds, int i,
              int[] adjacent, IAtomContainer container)
focal_class.identifier: geometric2D
focal_class.modifiers: private static
focal_class.parameters: (Map<IAtom, Integer> elevationMap, List<IBond> bonds, int i,
              int[] adjacent, IAtomContainer container)
focal_class.return: GeometricParity
focal_class.signature: GeometricParity geometric2D(Map<IAtom, Integer> elevationMap, List<IBond> bonds, int i,
              int[] adjacent, IAtomContainer container)
focal_class.class_method_signature: GeometricTetrahedralEncoderFactory.geometric3D(int i, int[] adjacent, IAtomContainer container)
focal_class.full_signature: private static GeometricParity geometric3D(int i, int[] adjacent, IAtomContainer container)
focal_class.identifier: geometric3D
focal_class.modifiers: private static
focal_class.parameters: (int i, int[] adjacent, IAtomContainer container)
focal_class.return: GeometricParity
focal_class.signature: GeometricParity geometric3D(int i, int[] adjacent, IAtomContainer container)
focal_class.class_method_signature: GeometricTetrahedralEncoderFactory.sp3(IAtom atom)
focal_class.full_signature: private static boolean sp3(IAtom atom)
focal_class.identifier: sp3
focal_class.modifiers: private static
focal_class.parameters: (IAtom atom)
focal_class.return: boolean
focal_class.signature: boolean sp3(IAtom atom)
focal_class.class_method_signature: GeometricTetrahedralEncoderFactory.nStereoBonds(List<IBond> bonds)
focal_class.full_signature: private static int nStereoBonds(List<IBond> bonds)
focal_class.identifier: nStereoBonds
focal_class.modifiers: private static
focal_class.parameters: (List<IBond> bonds)
focal_class.return: int
focal_class.signature: int nStereoBonds(List<IBond> bonds)
focal_class.class_method_signature: GeometricTetrahedralEncoderFactory.makeElevationMap(IAtom atom, List<IBond> bonds, Map<IAtom, Integer> map)
focal_class.full_signature: private static void makeElevationMap(IAtom atom, List<IBond> bonds, Map<IAtom, Integer> map)
focal_class.identifier: makeElevationMap
focal_class.modifiers: private static
focal_class.parameters: (IAtom atom, List<IBond> bonds, Map<IAtom, Integer> map)
focal_class.return: void
focal_class.signature: void makeElevationMap(IAtom atom, List<IBond> bonds, Map<IAtom, Integer> map)
focal_method.body: @Override
      public StereoEncoder create(IAtomContainer container, int[][] graph) {
  
          // XXX: this code isn't pretty, the current IAtomContainer
          // implementations are  slow for the queries (i.e. looking at connected
          // atoms/bonds) we need to ask to decide if something is a potential
          // tetrahedral centre. We can help out a little with the adjacency list
          // (int[][]) but this doesn't help with the bonds.
  
          int n = container.getAtomCount();
  
          List<StereoEncoder> encoders = new ArrayList<StereoEncoder>();
          Map<IAtom, Integer> elevation = new HashMap<IAtom, Integer>(10);
  
          ATOMS: for (int i = 0; i < n; i++) {
  
              int degree = graph[i].length;
  
              // ignore those which don't have 3 or 4 neighbors
              if (degree < 3 || degree > 4) continue;
  
              IAtom atom = container.getAtom(i);
  
              // only create encoders for SP3 hybridized atom. atom typing is
              // currently wrong for some atoms, in sulfoxide for example the atom
              // type sets SP2... but there we don't to fuss about with that here
              if (!sp3(atom)) continue;
  
              // avoid nitrogen-inversion
              if (Integer.valueOf(7).equals(atom.getAtomicNumber()) && degree == 3) continue;
  
              // TODO: we could be more strict with our selection, InChI uses C,
              // Si, Ge, P, As, B, Sn, N, P, S, Se but has preconditions for
              // certain cases. An atom or ion N, P, As, S or Se is not stereogenic
              // if it has a terminal H or two terminal neighbors -XHm, -XHn (n+m>0)
              // where X is O, S, Se, Te, or N
  
              // XXX: likely bottle neck
              List<IBond> bonds = container.getConnectedBondsList(atom);
  
              // try to create geometric parity
              GeometricParity geometric = geometric(elevation, bonds, i, graph[i], container);
  
              if (geometric != null) {
                  // add a new encoder if a geometric parity
                  encoders.add(new GeometryEncoder(i, new BasicPermutationParity(graph[i]), geometric));
              }
          }
  
          // no encoders, replace with the empty encoder
          return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders);
      }
focal_method.class_method_signature: GeometricTetrahedralEncoderFactory.create(IAtomContainer container, int[][] graph)
focal_method.full_signature: @Override public StereoEncoder create(IAtomContainer container, int[][] graph)
focal_method.identifier: create
focal_method.invocations: getAtomCount getAtom sp3 equals valueOf getAtomicNumber getConnectedBondsList geometric add isEmpty
focal_method.modifiers: @Override public
focal_method.parameters: (IAtomContainer container, int[][] graph)
focal_method.return: StereoEncoder
focal_method.signature: StereoEncoder create(IAtomContainer container, int[][] graph)