DeduceBondSystemTool { public IAtomContainer fixAromaticBondOrders(IAtomContainer atomContainer) throws CDKException { for (IBond bond : atomContainer.bonds()) { if (bond.isAromatic() && bond.getOrder() == IBond.Order.UNSET) bond.setOrder(IBond.Order.SINGLE); } IRingSet rs = allRingsFinder.findAllRings(atomContainer, 7); storeRingSystem(atomContainer, rs); IRingSet ringSet; ringSet = removeExtraRings(atomContainer); if (ringSet == null) throw new CDKException("failure in AllRingsFinder.findAllRings"); List<List<List<String>>> MasterList = new ArrayList<List<List<String>>>(); this.FixPyridineNOxides(atomContainer, ringSet); for (int i = 0; i <= ringSet.getAtomContainerCount() - 1; i++) { IRing ring = (IRing) ringSet.getAtomContainer(i); if (ring.getAtomCount() == 5) { fiveMemberedRingPossibilities(atomContainer, ring, MasterList); } else if (ring.getAtomCount() == 6) { sixMemberedRingPossibilities(atomContainer, ring, MasterList); } else if (ring.getAtomCount() == 7) { sevenMemberedRingPossibilities(atomContainer, ring, MasterList); } else { logger.debug("Found ring of size: " + ring.getAtomCount()); } } IAtomContainerSet som = atomContainer.getBuilder().newInstance(IAtomContainerSet.class); int[] choices; choices = new int[MasterList.size()]; if (MasterList.size() > 0) { IAtomContainer iAtomContainer = loop(System.currentTimeMillis(), atomContainer, 0, MasterList, choices, som); if (iAtomContainer != null) return iAtomContainer; } int mincount = 99999999; int best = -1; for (int i = 0; i <= som.getAtomContainerCount() - 1; i++) { IAtomContainer mol = som.getAtomContainer(i); ringSet = removeExtraRings(mol); if (ringSet == null) continue; int count = getBadCount(mol, ringSet); if (count < mincount) { mincount = count; best = i; } } if (som.getAtomContainerCount() > 0) return som.getAtomContainer(best); return atomContainer; } DeduceBondSystemTool();  DeduceBondSystemTool(AllRingsFinder ringFinder); boolean isOK(IAtomContainer m); IAtomContainer fixAromaticBondOrders(IAtomContainer atomContainer); void setInterrupted(boolean interrupted); boolean isInterrupted();  }
@Test(timeout = 1000) public void testPyrrole() throws Exception { String smiles = "c2ccc3n([H])c1ccccc1c3(c2)"; SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance()); smilesParser.kekulise(false); IAtomContainer molecule = smilesParser.parseSmiles(smiles); AtomContainerManipulator.setSingleOrDoubleFlags(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); molecule = dbst.fixAromaticBondOrders(molecule); Assert.assertNotNull(molecule); molecule = AtomContainerManipulator.removeHydrogens(molecule); int doubleBondCount = 0; for (int i = 0; i < molecule.getBondCount(); i++) { IBond bond = molecule.getBond(i); Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); if (bond.getOrder() == Order.DOUBLE) doubleBondCount++; } Assert.assertEquals(6, doubleBondCount); }
@Test(timeout = 1000) public void testPyrrole_Silent() throws Exception { String smiles = "c2ccc3n([H])c1ccccc1c3(c2)"; SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance()); smilesParser.kekulise(false); IAtomContainer molecule = smilesParser.parseSmiles(smiles); AtomContainerManipulator.setSingleOrDoubleFlags(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); molecule = dbst.fixAromaticBondOrders(molecule); Assert.assertNotNull(molecule); molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule); int doubleBondCount = 0; for (int i = 0; i < molecule.getBondCount(); i++) { IBond bond = molecule.getBond(i); Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); if (bond.getOrder() == Order.DOUBLE) doubleBondCount++; } Assert.assertEquals(6, doubleBondCount); }
@Test public void testLargeRingSystem() throws Exception { String smiles = "O=C1Oc6ccccc6(C(O)C1C5c2ccccc2CC(c3ccc(cc3)c4ccccc4)C5)"; SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer molecule = smilesParser.parseSmiles(smiles); DeduceBondSystemTool dbst = new DeduceBondSystemTool(new AllRingsFinder()); molecule = dbst.fixAromaticBondOrders(molecule); Assert.assertNotNull(molecule); molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule); Assert.assertEquals(34, molecule.getAtomCount()); int doubleBondCount = 0; for (int i = 0; i < molecule.getBondCount(); i++) { IBond bond = molecule.getBond(i); if (bond.getOrder() == Order.DOUBLE) doubleBondCount++; } Assert.assertEquals(13, doubleBondCount); }
@Test(timeout = 1000) public void testPyrrole_CustomRingFinder() throws Exception { String smiles = "c2ccc3n([H])c1ccccc1c3(c2)"; SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance()); smilesParser.kekulise(false); IAtomContainer molecule = smilesParser.parseSmiles(smiles); AtomContainerManipulator.setSingleOrDoubleFlags(molecule); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(molecule); DeduceBondSystemTool dbst = new DeduceBondSystemTool(new AllRingsFinder()); molecule = dbst.fixAromaticBondOrders(molecule); Assert.assertNotNull(molecule); molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule); int doubleBondCount = 0; for (int i = 0; i < molecule.getBondCount(); i++) { IBond bond = molecule.getBond(i); Assert.assertTrue(bond.getFlag(CDKConstants.ISAROMATIC)); if (bond.getOrder() == Order.DOUBLE) doubleBondCount++; } Assert.assertEquals(6, doubleBondCount); }