/** * Obtain the number of centres adjacent to the atom at the index, i. * * @param i atom index * @return number of adjacent centres */ private int nAdjacentCentres(int i) { int n = 0; for (IAtom atom : tetrahedralElements[i].getLigands()) if (tetrahedralElements[atomToIndex.get(atom)] != null) n++; return n; }
/** * Obtain the number of centres adjacent to the atom at the index, i. * * @param i atom index * @return number of adjacent centres */ private int nAdjacentCentres(int i) { int n = 0; for (IAtom atom : tetrahedralElements[i].getLigands()) if (tetrahedralElements[atomToIndex.get(atom)] != null) n++; return n; }
/** * Access the neighbors of {@code element} as their indices. * * @param element tetrahedral element * @param map atom index lookup * @return the neighbors */ private int[] neighbors(ITetrahedralChirality element, Map<IAtom, Integer> map) { IAtom[] atoms = element.getLigands(); int[] vs = new int[atoms.length]; for (int i = 0; i < atoms.length; i++) vs[i] = map.get(atoms[i]); return vs; }
/** * Access the neighbors of {@code element} as their indices. * * @param element tetrahedral element * @param map atom index lookup * @return the neighbors */ private int[] neighbors(ITetrahedralChirality element, Map<IAtom, Integer> map) { IAtom[] atoms = element.getLigands(); int[] vs = new int[atoms.length]; for (int i = 0; i < atoms.length; i++) vs[i] = map.get(atoms[i]); return vs; }
/** * Access the neighbors of {@code element} as their indices. * * @param element tetrahedral element * @param map atom index lookup * @return the neighbors */ private int[] neighbors(ITetrahedralChirality element, Map<IAtom, Integer> map) { IAtom[] atoms = element.getLigands(); int[] vs = new int[atoms.length]; for (int i = 0; i < atoms.length; i++) vs[i] = map.get(atoms[i]); return vs; }
/** * Add tetrahedral stereo configuration to the Beam GraphBuilder. * * @param tc stereo element specifying tetrahedral configuration * @param gb the current graph builder * @param indices atom indices */ private static void addTetrahedralConfiguration(ITetrahedralChirality tc, GraphBuilder gb, Map<IAtom, Integer> indices) { IAtom[] ligands = tc.getLigands(); int u = indices.get(tc.getChiralAtom()); int vs[] = new int[]{indices.get(ligands[0]), indices.get(ligands[1]), indices.get(ligands[2]), indices.get(ligands[3])}; gb.tetrahedral(u).lookingFrom(vs[0]).neighbors(vs[1], vs[2], vs[3]) .winding(tc.getStereo() == CLOCKWISE ? Configuration.CLOCKWISE : Configuration.ANTI_CLOCKWISE).build(); }
@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 // <-- represents implicit H }); 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]); // graph not used assertThat(getGeometricParity(encoder).parity(), is(-1)); // clockwise (we didn't have to move the implied H) }
static void assertTetrahedralCenter(IStereoElement element, IAtom focus, Stereo winding, IAtom ... neighbors) { Assert.assertThat(element, is(instanceOf(ITetrahedralChirality.class))); ITetrahedralChirality actual = (ITetrahedralChirality) element; Assert.assertThat(actual.getChiralAtom(), is(sameInstance(focus))); Assert.assertThat(actual.getStereo(), is(winding)); Assert.assertThat(actual.getLigands(), is(neighbors)); }
static void assertTetrahedralCenter(IStereoElement element, IAtom focus, ITetrahedralChirality.Stereo winding, IAtom ... neighbors) { Assert.assertThat(element, is(instanceOf(ITetrahedralChirality.class))); ITetrahedralChirality actual = (ITetrahedralChirality) element; Assert.assertThat(actual.getChiralAtom(), is(sameInstance(focus))); Assert.assertThat(actual.getStereo(), is(winding)); Assert.assertThat(actual.getLigands(), is(neighbors)); }
@Test public void testReading0DStereochemistryWithHydrogen() throws Exception { try (MDLV2000Reader mdlr = new MDLV2000Reader(getClass().getResourceAsStream("/data/mdl/tetrahedral-parity-withExpH.mol"))) { IAtomContainer container = mdlr.read(new AtomContainer()); Iterable<IStereoElement> selements = container.stereoElements(); Iterator<IStereoElement> siter = selements.iterator(); assertTrue(siter.hasNext()); IStereoElement se = siter.next(); assertThat(se, is(instanceOf(ITetrahedralChirality.class))); assertThat(((ITetrahedralChirality) se).getStereo(), is(ITetrahedralChirality.Stereo.ANTI_CLOCKWISE)); assertThat(((ITetrahedralChirality) se).getLigands(), is(new IAtom[]{container.getAtom(0), container.getAtom(2), container.getAtom(3), container.getAtom(4)})); assertFalse(siter.hasNext()); } }
@Test public void testReading0DStereochemistry() throws Exception { try (MDLV2000Reader mdlr = new MDLV2000Reader(getClass().getResourceAsStream("/data/mdl/tetrahedral-parity-withImplH.mol"))) { IAtomContainer container = mdlr.read(new AtomContainer()); Iterable<IStereoElement> selements = container.stereoElements(); Iterator<IStereoElement> siter = selements.iterator(); assertTrue(siter.hasNext()); IStereoElement se = siter.next(); assertThat(se, is(instanceOf(ITetrahedralChirality.class))); assertThat(((ITetrahedralChirality) se).getStereo(), is(ITetrahedralChirality.Stereo.CLOCKWISE)); assertThat(((ITetrahedralChirality) se).getLigands(), is(new IAtom[]{container.getAtom(1), container.getAtom(3), container.getAtom(4), container.getAtom(0)})); assertFalse(siter.hasNext()); } }
@Test public void createCenterWithThreeNeighbors_right() { IAtom focus = atom("C", 0, 0.80d, 0.42d); IAtom north = atom("C", 0, 0.80d, 1.24d); IAtom east = atom("O", 1, 1.63d, 0.42d); IAtom south = atom("C", 2, 0.80d, -0.41d); IBond[] bonds = new IBond[]{ new Bond(focus, south), new Bond(focus, north), new Bond(focus, east) }; ITetrahedralChirality element = FischerRecognition.newTetrahedralCenter(focus, bonds); Assert.assertThat(element.getChiralAtom(), is(sameInstance(focus))); Assert.assertThat(element.getStereo(), is(ANTI_CLOCKWISE)); Assert.assertThat(element.getLigands()[0], is(sameInstance(north))); Assert.assertThat(element.getLigands()[1], is(sameInstance(east))); Assert.assertThat(element.getLigands()[2], is(sameInstance(south))); Assert.assertThat(element.getLigands()[3], is(sameInstance(focus))); }
/** * (2R)-butan-2-ol * * @cdk.inchi InChI=1/C4H10O/c1-3-4(2)5/h4-5H,3H2,1-2H3/t4-/s2 */ @Test public void _2R_butan_2_ol() throws Exception { IAtomContainer ac = convert("CC[C@@](C)(O)[H]"); IStereoElement se = FluentIterable.from(ac.stereoElements()).first().get(); assertThat(se, is(instanceOf(ITetrahedralChirality.class))); ITetrahedralChirality tc = (ITetrahedralChirality) se; assertThat(tc.getChiralAtom(), is(ac.getAtom(2))); assertThat(tc.getLigands(), is(new IAtom[]{ac.getAtom(1), ac.getAtom(3), ac.getAtom(4), ac.getAtom(5)})); assertThat(tc.getStereo(), is(ITetrahedralChirality.Stereo.CLOCKWISE)); }
@Test public void createCenterWithThreeNeighbors_left() { IAtom focus = atom("C", 0, 0.80d, 0.42d); IAtom north = atom("C", 0, 0.80d, 1.24d); IAtom south = atom("C", 2, 0.80d, -0.41d); IAtom west = atom("O", 1, -0.02d, 0.42d); IBond[] bonds = new IBond[]{ new Bond(focus, south), new Bond(focus, north), new Bond(focus, west) }; ITetrahedralChirality element = FischerRecognition.newTetrahedralCenter(focus, bonds); Assert.assertThat(element.getChiralAtom(), is(sameInstance(focus))); Assert.assertThat(element.getStereo(), is(ANTI_CLOCKWISE)); Assert.assertThat(element.getLigands()[0], is(sameInstance(north))); Assert.assertThat(element.getLigands()[1], is(sameInstance(focus))); Assert.assertThat(element.getLigands()[2], is(sameInstance(south))); Assert.assertThat(element.getLigands()[3], is(sameInstance(west))); }
/** * (2S)-butan-2-ol * * @cdk.inchi InChI=1/C4H10O/c1-3-4(2)5/h4-5H,3H2,1-2H3/t4-/s2 */ @Test public void _2S_butan_2_ol() throws Exception { IAtomContainer ac = convert("CC[C@](C)(O)[H]"); IStereoElement se = FluentIterable.from(ac.stereoElements()).first().get(); assertThat(se, is(instanceOf(ITetrahedralChirality.class))); ITetrahedralChirality tc = (ITetrahedralChirality) se; assertThat(tc.getChiralAtom(), is(ac.getAtom(2))); assertThat(tc.getLigands(), is(new IAtom[]{ac.getAtom(1), ac.getAtom(3), ac.getAtom(4), ac.getAtom(5)})); assertThat(tc.getStereo(), is(ANTI_CLOCKWISE)); }
@Test public void createCenterWithFourNeighbors() { IAtom focus = atom("C", 0, 0.80d, 0.42d); IAtom north = atom("C", 0, 0.80d, 1.24d); IAtom east = atom("O", 1, 1.63d, 0.42d); IAtom south = atom("C", 2, 0.80d, -0.41d); IAtom west = atom("H", 0, -0.02d, 0.42d); IBond[] bonds = new IBond[]{ new Bond(focus, south), new Bond(focus, west), new Bond(focus, north), new Bond(focus, east) }; ITetrahedralChirality element = FischerRecognition.newTetrahedralCenter(focus, bonds); Assert.assertThat(element.getChiralAtom(), is(sameInstance(focus))); Assert.assertThat(element.getStereo(), is(ANTI_CLOCKWISE)); Assert.assertThat(element.getLigands()[0], is(sameInstance(north))); Assert.assertThat(element.getLigands()[1], is(sameInstance(east))); Assert.assertThat(element.getLigands()[2], is(sameInstance(south))); Assert.assertThat(element.getLigands()[3], is(sameInstance(west))); }
@Test public void testAtAt_ExplicitHydrogen() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("Br[C@@]([H])(Cl)I"); Iterator<IStereoElement> stereoElements = mol.stereoElements().iterator(); assertTrue(stereoElements.hasNext()); IStereoElement stereoElement = stereoElements.next(); Assert.assertNotNull(stereoElement); assertTrue(stereoElement instanceof ITetrahedralChirality); ITetrahedralChirality l4Chiral = (ITetrahedralChirality) stereoElement; Assert.assertEquals("C", l4Chiral.getChiralAtom().getSymbol()); IAtom[] ligands = l4Chiral.getLigands(); for (IAtom atom : ligands) Assert.assertNotNull(atom); Assert.assertEquals("Br", ligands[0].getSymbol()); Assert.assertEquals("H", ligands[1].getSymbol()); Assert.assertEquals("Cl", ligands[2].getSymbol()); Assert.assertEquals("I", ligands[3].getSymbol()); Assert.assertEquals(Stereo.CLOCKWISE, l4Chiral.getStereo()); }
@Test public void testChiralAtomWithDisconnectedLastAtom() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("Br1.[C@]1(Cl)(OC)CCC"); Iterator<IStereoElement> stereoElements = mol.stereoElements().iterator(); assertTrue(stereoElements.hasNext()); IStereoElement stereoElement = stereoElements.next(); Assert.assertNotNull(stereoElement); assertTrue(stereoElement instanceof ITetrahedralChirality); ITetrahedralChirality l4Chiral = (ITetrahedralChirality) stereoElement; Assert.assertEquals("C", l4Chiral.getChiralAtom().getSymbol()); IAtom[] ligands = l4Chiral.getLigands(); for (IAtom atom : ligands) Assert.assertNotNull(atom); Assert.assertEquals("Br", ligands[0].getSymbol()); Assert.assertEquals("Cl", ligands[1].getSymbol()); Assert.assertEquals("O", ligands[2].getSymbol()); Assert.assertEquals("C", ligands[3].getSymbol()); Assert.assertEquals(Stereo.ANTI_CLOCKWISE, l4Chiral.getStereo()); }
@Test public void testFromBlog1() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("[C@@H]231.C2.N1.F3"); Iterator<IStereoElement> stereoElements = mol.stereoElements().iterator(); assertTrue(stereoElements.hasNext()); IStereoElement stereoElement = stereoElements.next(); Assert.assertNotNull(stereoElement); assertTrue(stereoElement instanceof ITetrahedralChirality); ITetrahedralChirality l4Chiral = (ITetrahedralChirality) stereoElement; Assert.assertEquals("C", l4Chiral.getChiralAtom().getSymbol()); IAtom[] ligands = l4Chiral.getLigands(); for (IAtom atom : ligands) Assert.assertNotNull(atom); // note: ligands are given in the order they appear in (hence in this // case the winding (getStereo) has flipped (0,1,3,2) -> (0,1,2,3) Assert.assertEquals(mol.getAtom(0), ligands[0]); Assert.assertEquals(mol.getAtom(1), ligands[1]); Assert.assertEquals(mol.getAtom(2), ligands[2]); Assert.assertEquals(mol.getAtom(3), ligands[3]); Assert.assertEquals(Stereo.ANTI_CLOCKWISE, l4Chiral.getStereo()); }
@Test public void testChiralityWithTonsOfDots() throws Exception { SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles("I1.Cl2.Br3.[C@]123CCC"); Iterator<IStereoElement> stereoElements = mol.stereoElements().iterator(); assertTrue(stereoElements.hasNext()); IStereoElement stereoElement = stereoElements.next(); Assert.assertNotNull(stereoElement); assertTrue(stereoElement instanceof ITetrahedralChirality); ITetrahedralChirality l4Chiral = (ITetrahedralChirality) stereoElement; Assert.assertEquals("C", l4Chiral.getChiralAtom().getSymbol()); IAtom[] ligands = l4Chiral.getLigands(); for (IAtom atom : ligands) Assert.assertNotNull(atom); Assert.assertEquals("I", ligands[0].getSymbol()); Assert.assertEquals("Cl", ligands[1].getSymbol()); Assert.assertEquals("Br", ligands[2].getSymbol()); Assert.assertEquals("C", ligands[3].getSymbol()); Assert.assertEquals(Stereo.ANTI_CLOCKWISE, l4Chiral.getStereo()); }