ConjugatedPiSystemsDetector { public static IAtomContainerSet detect(IAtomContainer ac) { IAtomContainerSet piSystemSet = ac.getBuilder().newInstance(IAtomContainerSet.class); for (int i = 0; i < ac.getAtomCount(); i++) { IAtom atom = ac.getAtom(i); atom.setFlag(CDKConstants.VISITED, false); } for (int i = 0; i < ac.getAtomCount(); i++) { IAtom firstAtom = ac.getAtom(i); if (firstAtom.getFlag(CDKConstants.VISITED) || checkAtom(ac, firstAtom) == -1) { continue; } IAtomContainer piSystem = ac.getBuilder().newInstance(IAtomContainer.class); Stack<IAtom> stack = new Stack<IAtom>(); piSystem.addAtom(firstAtom); stack.push(firstAtom); firstAtom.setFlag(CDKConstants.VISITED, true); while (!stack.empty()) { IAtom currentAtom = stack.pop(); List<IAtom> atoms = ac.getConnectedAtomsList(currentAtom); List<IBond> bonds = ac.getConnectedBondsList(currentAtom); for (int j = 0; j < atoms.size(); j++) { IAtom atom = atoms.get(j); IBond bond = bonds.get(j); if (!atom.getFlag(CDKConstants.VISITED)) { int check = checkAtom(ac, atom); if (check == 1) { piSystem.addAtom(atom); piSystem.addBond(bond); continue; } else if (check == 0) { piSystem.addAtom(atom); piSystem.addBond(bond); stack.push(atom); } atom.setFlag(CDKConstants.VISITED, true); } else if (!piSystem.contains(bond) && piSystem.contains(atom)) { piSystem.addBond(bond); } } } if (piSystem.getAtomCount() > 2) { piSystemSet.addAtomContainer(piSystem); } } return piSystemSet; }  static IAtomContainerSet detect(IAtomContainer ac);  }
@Test public void testDetectButadiene() throws Exception { logger.info("Entering testDetectButadiene."); IAtomContainer mol = null; String filename = "data/cml/butadiene.cml"; mol = readCMLMolecule(filename); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac = acSet.getAtomContainer(0); Assert.assertEquals(4, ac.getAtomCount()); Assert.assertEquals(3, ac.getBondCount()); for (int i = 0; i < ac.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac.getAtom(i))); } for (int i = 0; i < ac.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac.getBond(i))); } }
@Test public void testDetectNaphtalene() throws Exception { logger.info("Entering testDetectNaphtalene."); IAtomContainer mol = null; String filename = "data/cml/naphtalene.cml"; mol = readCMLMolecule(filename); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac = acSet.getAtomContainer(0); Assert.assertEquals(10, ac.getAtomCount()); Assert.assertEquals(11, ac.getBondCount()); for (int i = 0; i < ac.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac.getAtom(i))); } for (int i = 0; i < ac.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac.getBond(i))); } }
@Test public void testDetectToluene() throws Exception { logger.info("Entering testDetectToluene."); IAtomContainer mol = null; String filename = "data/cml/toluene.cml"; mol = readCMLMolecule(filename); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac = acSet.getAtomContainer(0); Assert.assertEquals(6, ac.getAtomCount()); Assert.assertEquals(6, ac.getBondCount()); for (int i = 0; i < ac.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac.getAtom(i))); } for (int i = 0; i < ac.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac.getBond(i))); } }
@Test public void testNonConnectedPiSystems() throws Exception { logger.info("Entering testNonConnectedPiSystems."); IAtomContainer mol = null; String filename = "data/mdl/nonConnectedPiSystems.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); IChemFile chemFile = (IChemFile) reader.read((ChemObject) new ChemFile()); mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(2, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(4, ac1.getAtomCount()); Assert.assertEquals(3, ac1.getBondCount()); for (int i = 0; i < ac1.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac1.getAtom(i))); } for (int i = 0; i < ac1.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac1.getBond(i))); } IAtomContainer ac2 = acSet.getAtomContainer(1); Assert.assertEquals(4, ac2.getAtomCount()); Assert.assertEquals(3, ac2.getBondCount()); for (int i = 0; i < ac2.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac2.getAtom(i))); } for (int i = 0; i < ac2.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac2.getBond(i))); } }
@Test public void testPiSystemWithCarbokation() throws Exception { logger.info("Entering testPiSystemWithCarbokation."); IAtomContainer mol = null; String filename = "data/mdl/piSystemWithCarbokation.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); IChemFile chemFile = (IChemFile) reader.read((ChemObject) new ChemFile()); mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(2, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(4, ac1.getAtomCount()); Assert.assertEquals(3, ac1.getBondCount()); for (int i = 0; i < ac1.getAtomCount(); i++) Assert.assertTrue(mol.contains(ac1.getAtom(i))); for (int i = 0; i < ac1.getBondCount(); i++) Assert.assertTrue(mol.contains(ac1.getBond(i))); IAtomContainer ac2 = acSet.getAtomContainer(0); Assert.assertEquals(4, ac2.getAtomCount()); Assert.assertEquals(3, ac2.getBondCount()); for (int i = 0; i < ac2.getAtomCount(); i++) Assert.assertTrue(mol.contains(ac2.getAtom(i))); for (int i = 0; i < ac2.getBondCount(); i++) Assert.assertTrue(mol.contains(ac2.getBond(i))); }
@Test public void testPiSystemWithCumulativeDB() throws Exception { logger.info("Entering testPiSystemWithCumulativeDB."); IAtomContainer mol = null; String filename = "data/mdl/piSystemCumulative.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLReader reader = new MDLReader(ins); IChemFile chemFile = (IChemFile) reader.read((ChemObject) new ChemFile()); mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(2, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(4, ac1.getAtomCount()); Assert.assertEquals(3, ac1.getBondCount()); for (int i = 0; i < ac1.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac1.getAtom(i))); } for (int i = 0; i < ac1.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac1.getBond(i))); } IAtomContainer ac2 = acSet.getAtomContainer(0); Assert.assertEquals(4, ac2.getAtomCount()); Assert.assertEquals(3, ac2.getBondCount()); for (int i = 0; i < ac2.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac1.getAtom(i))); } for (int i = 0; i < ac2.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac1.getBond(i))); } }
@Test public void testAceticAcid() throws Exception { IAtomContainer mol = null; mol = (new SmilesParser(builder)).parseSmiles("CC(=O)O"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); addImplicitHydrogens(mol); lpcheck.saturate(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(3, ac1.getAtomCount()); Assert.assertEquals(2, ac1.getBondCount()); for (int i = 0; i < ac1.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac1.getAtom(i))); } for (int i = 0; i < ac1.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac1.getBond(i))); } }
@Test public void testNN_dimethylaniline_cation() throws Exception { IAtomContainer mol = null; String filename = "data/mdl/NN_dimethylaniline.mol"; InputStream ins = this.getClass().getClassLoader().getResourceAsStream(filename); MDLV2000Reader reader = new MDLV2000Reader(ins); IChemFile chemFile = (IChemFile) reader.read((ChemObject) new ChemFile()); mol = chemFile.getChemSequence(0).getChemModel(0).getMoleculeSet().getAtomContainer(0); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); addImplicitHydrogens(mol); lpcheck.saturate(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(6, ac1.getAtomCount()); Assert.assertEquals(5, ac1.getBondCount()); }
@Test public void test1_fluorobutadienene() throws Exception { IAtomContainer mol = (new SmilesParser(builder)).parseSmiles("FC=CC=C"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); addImplicitHydrogens(mol); lpcheck.saturate(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(5, ac1.getAtomCount()); Assert.assertEquals(4, ac1.getBondCount()); }
@Test public void testEthyne_difluoro() throws Exception { IAtomContainer mol = null; mol = (new SmilesParser(builder)).parseSmiles("FC#CF"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); addImplicitHydrogens(mol); lpcheck.saturate(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(4, ac1.getAtomCount()); Assert.assertEquals(3, ac1.getBondCount()); }
@Test public void test3Aminomethane_cation() throws Exception { IAtomContainer mol = builder.newInstance(IAtomContainer.class); mol.addAtom(builder.newInstance(IAtom.class, "N")); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(0, 1, Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(0, 2, Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(0, 3, Order.SINGLE); mol.getAtom(3).setFormalCharge(+1); mol.addAtom(builder.newInstance(IAtom.class, "N")); mol.addBond(3, 4, Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(4, 5, Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(4, 6, Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "N")); mol.addBond(3, 7, Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(7, 8, Order.SINGLE); mol.addAtom(builder.newInstance(IAtom.class, "C")); mol.addBond(7, 8, Order.SINGLE); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); addImplicitHydrogens(mol); lpcheck.saturate(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(4, ac1.getAtomCount()); Assert.assertEquals(3, ac1.getBondCount()); }
@Test public void testCyanoallene() throws Exception { IAtomContainer mol = null; mol = (new SmilesParser(builder)).parseSmiles("C=C=CC#N"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); addImplicitHydrogens(mol); lpcheck.saturate(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(4, ac1.getAtomCount()); Assert.assertEquals(3, ac1.getBondCount()); for (int i = 0; i < ac1.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac1.getAtom(i))); } for (int i = 0; i < ac1.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac1.getBond(i))); } }
@Test public void testChargeWithProtonExplicit() throws ClassNotFoundException, CDKException, java.lang.Exception { SmilesParser sp = new SmilesParser(builder); IAtomContainer mol = sp.parseSmiles("[H]C([H])=C([H])[C+]([H])[H]"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); lpcheck.saturate(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(3, ac1.getAtomCount()); Assert.assertEquals(2, ac1.getBondCount()); for (int i = 0; i < ac1.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac1.getAtom(i))); } for (int i = 0; i < ac1.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac1.getBond(i))); } }
@Test public void testChargeWithProtonImplicit() throws ClassNotFoundException, CDKException, java.lang.Exception { SmilesParser sp = new SmilesParser(builder); IAtomContainer mol = sp.parseSmiles("C=C[C+]"); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(mol); lpcheck.saturate(mol); Aromaticity.cdkLegacy().apply(mol); IAtomContainerSet acSet = ConjugatedPiSystemsDetector.detect(mol); Assert.assertEquals(1, acSet.getAtomContainerCount()); IAtomContainer ac1 = acSet.getAtomContainer(0); Assert.assertEquals(3, ac1.getAtomCount()); Assert.assertEquals(2, ac1.getBondCount()); for (int i = 0; i < ac1.getAtomCount(); i++) { Assert.assertTrue(mol.contains(ac1.getAtom(i))); } for (int i = 0; i < ac1.getBondCount(); i++) { Assert.assertTrue(mol.contains(ac1.getBond(i))); } }