TetrahedralElementEncoderFactory implements StereoEncoderFactory { @Override public StereoEncoder create(IAtomContainer container, int[][] graph) { Map<IAtom, Integer> atomToIndex = null; List<StereoEncoder> encoders = new ArrayList<StereoEncoder>(); for (IStereoElement se : container.stereoElements()) { if (se instanceof ITetrahedralChirality) { encoders.add(encoder((ITetrahedralChirality) se, atomToIndex = indexMap(atomToIndex, container))); } } return encoders.isEmpty() ? StereoEncoder.EMPTY : new MultiStereoEncoder(encoders); }  @Override StereoEncoder create(IAtomContainer container, int[][] graph);  }
@Test public void createExplicitH() 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(container.atoms()).thenReturn(Arrays.asList(c1, o2, n3, c4, h5)); ITetrahedralChirality tc = mock(ITetrahedralChirality.class); when(tc.getChiralAtom()).thenReturn(c1); when(tc.getLigands()).thenReturn(new IAtom[]{o2, n3, c4, h5}); when(tc.getStereo()).thenReturn(ITetrahedralChirality.Stereo.CLOCKWISE); when(container.stereoElements()).thenReturn(Collections.<IStereoElement> singleton(tc)); StereoEncoder encoder = new TetrahedralElementEncoderFactory().create(container, new int[0][0]); assertThat(getGeometricParity(encoder).parity(), is(-1)); }
@Test public void createImplicitH_back() throws Exception { IAtomContainer container = mock(IAtomContainer.class); 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); when(container.atoms()).thenReturn(Arrays.asList(c1, o2, n3, c4)); ITetrahedralChirality tc = mock(ITetrahedralChirality.class); when(tc.getChiralAtom()).thenReturn(c1); when(tc.getLigands()).thenReturn(new IAtom[]{o2, n3, c4, c1 }); when(tc.getStereo()).thenReturn(ITetrahedralChirality.Stereo.CLOCKWISE); when(container.stereoElements()).thenReturn(Collections.<IStereoElement> singleton(tc)); StereoEncoder encoder = new TetrahedralElementEncoderFactory().create(container, new int[0][0]); assertThat(getGeometricParity(encoder).parity(), is(-1)); }
@Test public void createImplicitH_front() throws Exception { IAtomContainer container = mock(IAtomContainer.class); 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); when(container.atoms()).thenReturn(Arrays.asList(c1, o2, n3, c4)); ITetrahedralChirality tc = mock(ITetrahedralChirality.class); when(tc.getChiralAtom()).thenReturn(c1); when(tc.getLigands()).thenReturn(new IAtom[]{c1, o2, n3, c4,}); when(tc.getStereo()).thenReturn(ITetrahedralChirality.Stereo.CLOCKWISE); when(container.stereoElements()).thenReturn(Collections.<IStereoElement> singleton(tc)); StereoEncoder encoder = new TetrahedralElementEncoderFactory().create(container, new int[0][0]); assertThat(getGeometricParity(encoder).parity(), is(1)); }
@Test public void createImplicitH_middle() throws Exception { IAtomContainer container = mock(IAtomContainer.class); 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); when(container.atoms()).thenReturn(Arrays.asList(c1, o2, n3, c4)); ITetrahedralChirality tc = mock(ITetrahedralChirality.class); when(tc.getChiralAtom()).thenReturn(c1); when(tc.getLigands()).thenReturn(new IAtom[]{o2, c1, n3, c4,}); when(tc.getStereo()).thenReturn(ITetrahedralChirality.Stereo.CLOCKWISE); when(container.stereoElements()).thenReturn(Collections.<IStereoElement> singleton(tc)); StereoEncoder encoder = new TetrahedralElementEncoderFactory().create(container, new int[0][0]); assertThat(getGeometricParity(encoder).parity(), is(-1)); }