GeometricTetrahedralEncoderFactory implements StereoEncoderFactory { @Override public StereoEncoder create(IAtomContainer container, int[][] graph) { 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; if (degree < 3 || degree > 4) continue; IAtom atom = container.getAtom(i); if (!sp3(atom)) continue; if (Integer.valueOf(7).equals(atom.getAtomicNumber()) && degree == 3) continue; List<IBond> bonds = container.getConnectedBondsList(atom); GeometricParity geometric = geometric(elevation, bonds, i, graph[i], container); if (geometric != null) { encoders.add(new GeometryEncoder(i, new BasicPermutationParity(graph[i]), geometric)); } } return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders); }  @Override StereoEncoder create(IAtomContainer container, int[][] graph);  }
@Test public void testCreate_2D() throws Exception { IAtomContainer container = mock(IAtomContainer.class); when(container.getAtomCount()).thenReturn(5); IAtom c1 = mock(IAtom.class); IAtom o2 = mock(IAtom.class); IAtom n3 = mock(IAtom.class); IAtom c4 = mock(IAtom.class); IAtom h5 = 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); when(container.getAtom(4)).thenReturn(h5); Point2d p1 = new Point2d(1.23, -0.29); Point2d p2 = new Point2d(-0.30, -0.29); Point2d p3 = new Point2d(2.00, -1.63); Point2d p4 = new Point2d(2.00, 1.03); Point2d p5 = new Point2d(2.32, -0.29); when(c1.getPoint2d()).thenReturn(p1); when(o2.getPoint2d()).thenReturn(p2); when(n3.getPoint2d()).thenReturn(p3); when(c4.getPoint2d()).thenReturn(p4); when(h5.getPoint2d()).thenReturn(p5); IBond c1c4 = mock(IBond.class); IBond c1o2 = mock(IBond.class); IBond c1n3 = mock(IBond.class); IBond c1h5 = mock(IBond.class); int[][] graph = new int[][]{{1, 2, 3, 4}, {0}, {0}, {0}, {0}}; when(container.getConnectedBondsList(c1)).thenReturn(Arrays.asList(c1c4, c1o2, c1n3, c1h5)); when(c1.getHybridization()).thenReturn(IAtomType.Hybridization.SP3); when(c1n3.getStereo()).thenReturn(DOWN); 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); when(c1h5.getStereo()).thenReturn(NONE); when(c1h5.getBegin()).thenReturn(c1); when(c1h5.getEnd()).thenReturn(h5); StereoEncoder encoder = new GeometricTetrahedralEncoderFactory().create(container, graph); assertThat(extractEncoders(encoder).size(), is(1)); GeometricParity geometricParity = getGeometricParity(extractEncoders(encoder).get(0)); assertTrue(geometricParity instanceof Tetrahedral2DParity); assertThat(coords2D(geometricParity), CoreMatchers.is(new Point2d[]{p2, p3, p4, p5})); }
@Test public void testCreate_2D_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); Point2d p1 = new Point2d(1.23, -0.29); Point2d p2 = new Point2d(-0.30, -0.29); Point2d p3 = new Point2d(2.00, -1.63); Point2d p4 = new Point2d(2.00, 1.03); when(c1.getPoint2d()).thenReturn(p1); when(o2.getPoint2d()).thenReturn(p2); when(n3.getPoint2d()).thenReturn(p3); when(c4.getPoint2d()).thenReturn(p4); IBond c1c4 = mock(IBond.class); IBond c1o2 = mock(IBond.class); IBond c1n3 = mock(IBond.class); IBond c1h5 = mock(IBond.class); int[][] graph = new int[][]{{1, 2, 3}, {0}, {0}, {0},}; when(container.getConnectedBondsList(c1)).thenReturn(Arrays.asList(c1c4, c1o2, c1n3)); when(c1.getHybridization()).thenReturn(IAtomType.Hybridization.SP3); when(c1n3.getStereo()).thenReturn(DOWN); 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 Tetrahedral2DParity); assertThat(coords2D(geometricParity), CoreMatchers.is(new Point2d[]{p2, p3, p4, p1 })); }
@Test public void testCreate_3D() throws Exception { IAtomContainer container = mock(IAtomContainer.class); when(container.getAtomCount()).thenReturn(5); IAtom c1 = mock(IAtom.class); IAtom o2 = mock(IAtom.class); IAtom n3 = mock(IAtom.class); IAtom c4 = mock(IAtom.class); IAtom h5 = 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); when(container.getAtom(4)).thenReturn(h5); 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); Point3d p5 = new Point3d(2.32, -0.29, 0); when(c1.getPoint3d()).thenReturn(p1); when(o2.getPoint3d()).thenReturn(p2); when(n3.getPoint3d()).thenReturn(p3); when(c4.getPoint3d()).thenReturn(p4); when(h5.getPoint3d()).thenReturn(p5); IBond c1c4 = mock(IBond.class); IBond c1o2 = mock(IBond.class); IBond c1n3 = mock(IBond.class); IBond c1h5 = mock(IBond.class); int[][] graph = new int[][]{{1, 2, 3, 4}, {0}, {0}, {0}, {0}}; when(container.getConnectedBondsList(c1)).thenReturn(Arrays.asList(c1c4, c1o2, c1n3, c1h5)); when(c1.getHybridization()).thenReturn(IAtomType.Hybridization.SP3); 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); when(c1h5.getStereo()).thenReturn(NONE); when(c1h5.getBegin()).thenReturn(c1); when(c1h5.getEnd()).thenReturn(h5); 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, p5})); }
@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)); when(c1.getHybridization()).thenReturn(IAtomType.Hybridization.SP3); 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 })); }
@Test public void testCreate_NonSP3() throws Exception { IAtomContainer container = mock(IAtomContainer.class); when(container.getAtomCount()).thenReturn(5); IAtom c1 = mock(IAtom.class); IAtom o2 = mock(IAtom.class); IAtom n3 = mock(IAtom.class); IAtom c4 = mock(IAtom.class); IAtom h5 = 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); when(container.getAtom(4)).thenReturn(h5); when(c1.getPoint2d()).thenReturn(new Point2d(1.23, -0.29)); when(o2.getPoint2d()).thenReturn(new Point2d(-0.30, -0.29)); when(n3.getPoint2d()).thenReturn(new Point2d(2.00, -1.63)); when(c4.getPoint2d()).thenReturn(new Point2d(2.00, 1.03)); when(h5.getPoint2d()).thenReturn(new Point2d(2.32, -0.29)); IBond c1c4 = mock(IBond.class); IBond c1o2 = mock(IBond.class); IBond c1n3 = mock(IBond.class); IBond c1h5 = mock(IBond.class); int[][] graph = new int[][]{{1, 2, 3, 4}, {0}, {0}, {0}, {0}}; when(container.getConnectedBondsList(c1)).thenReturn(Arrays.asList(c1c4, c1o2, c1n3, c1h5)); when(c1n3.getStereo()).thenReturn(DOWN); 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); when(c1h5.getStereo()).thenReturn(NONE); when(c1h5.getBegin()).thenReturn(c1); when(c1h5.getEnd()).thenReturn(h5); StereoEncoder encoder = new GeometricTetrahedralEncoderFactory().create(container, graph); assertThat(encoder, is(StereoEncoder.EMPTY)); }
@Test public void testCreate_NoStereoBonds() throws Exception { IAtomContainer container = mock(IAtomContainer.class); when(container.getAtomCount()).thenReturn(5); IAtom c1 = mock(IAtom.class); IAtom o2 = mock(IAtom.class); IAtom n3 = mock(IAtom.class); IAtom c4 = mock(IAtom.class); IAtom h5 = 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); when(container.getAtom(4)).thenReturn(h5); when(c1.getPoint2d()).thenReturn(new Point2d(1.23, -0.29)); when(o2.getPoint2d()).thenReturn(new Point2d(-0.30, -0.29)); when(n3.getPoint2d()).thenReturn(new Point2d(2.00, -1.63)); when(c4.getPoint2d()).thenReturn(new Point2d(2.00, 1.03)); when(h5.getPoint2d()).thenReturn(new Point2d(2.32, -0.29)); IBond c1c4 = mock(IBond.class); IBond c1o2 = mock(IBond.class); IBond c1n3 = mock(IBond.class); IBond c1h5 = mock(IBond.class); int[][] graph = new int[][]{{1, 2, 3, 4}, {0}, {0}, {0}, {0}}; when(container.getConnectedBondsList(c1)).thenReturn(Arrays.asList(c1c4, c1o2, c1n3, c1h5)); when(c1.getHybridization()).thenReturn(IAtomType.Hybridization.SP3); 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); when(c1h5.getStereo()).thenReturn(NONE); when(c1h5.getBegin()).thenReturn(c1); when(c1h5.getEnd()).thenReturn(h5); StereoEncoder encoder = new GeometricTetrahedralEncoderFactory().create(container, graph); assertThat(encoder, is(StereoEncoder.EMPTY)); }
@Test public void testCreate_WrongDegree() throws Exception { IAtomContainer container = mock(IAtomContainer.class); when(container.getAtomCount()).thenReturn(5); IAtom c1 = mock(IAtom.class); IAtom o2 = mock(IAtom.class); IAtom n3 = mock(IAtom.class); IAtom c4 = mock(IAtom.class); IAtom h5 = 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); when(container.getAtom(4)).thenReturn(h5); when(c1.getPoint2d()).thenReturn(new Point2d(1.23, -0.29)); when(o2.getPoint2d()).thenReturn(new Point2d(-0.30, -0.29)); when(n3.getPoint2d()).thenReturn(new Point2d(2.00, -1.63)); when(c4.getPoint2d()).thenReturn(new Point2d(2.00, 1.03)); when(h5.getPoint2d()).thenReturn(new Point2d(2.32, -0.29)); IBond c1c4 = mock(IBond.class); IBond c1o2 = mock(IBond.class); IBond c1n3 = mock(IBond.class); IBond c1h5 = mock(IBond.class); int[][] graph = new int[][]{{1, 2}, {0}, {0}, {0}, {0}}; when(container.getConnectedBondsList(c1)).thenReturn(Arrays.asList(c1c4, c1o2, c1n3, c1h5)); when(c1.getHybridization()).thenReturn(IAtomType.Hybridization.SP3); when(c1n3.getStereo()).thenReturn(DOWN); 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); when(c1h5.getStereo()).thenReturn(NONE); when(c1h5.getBegin()).thenReturn(c1); when(c1h5.getEnd()).thenReturn(h5); StereoEncoder encoder = new GeometricTetrahedralEncoderFactory().create(container, graph); assertThat(encoder, is(StereoEncoder.EMPTY)); }