FixBondOrdersTool { public IAtomContainer kekuliseAromaticRings(IAtomContainer molecule) throws CDKException { IAtomContainer mNew = null; try { mNew = (IAtomContainer) molecule.clone(); } catch (Exception e) { throw new CDKException("Failed to clone source molecule"); } IRingSet ringSet; try { ringSet = removeExtraRings(mNew); } catch (CDKException x) { throw x; } catch (Exception x) { throw new CDKException("failure in SSSRFinder.findAllRings", x); } if (ringSet == null) { throw new CDKException("failure in SSSRFinder.findAllRings"); } List<Integer[]> rBondsArray = null; List<List<Integer>> ringGroups = null; rBondsArray = getRingSystem(mNew, ringSet); ringGroups = assignRingGroups(rBondsArray); for (int i = 0; i < ringGroups.size(); i++) { setAllRingBondsSingleOrder(ringGroups.get(i), ringSet); List<Integer> atomNos = null; atomNos = getAtomNosForRingGroup(mNew, ringGroups.get(i), ringSet); List<Integer> bondNos = null; bondNos = getBondNosForRingGroup(mNew, ringGroups.get(i), ringSet); List<Integer[]> atomNoPairs = null; atomNoPairs = getAtomNoPairsForRingGroup(mNew, bondNos); Matrix M = new Matrix(atomNos.size(), bondNos.size()); for (int x = 0; x < M.getRows(); x++) { for (int y = 0; y < M.getCols(); y++) { if (Objects.equals(atomNos.get(x), atomNoPairs.get(y)[0])) { M.set(x, y, 1); } else { if (Objects.equals(atomNos.get(x), atomNoPairs.get(y)[1])) { M.set(x, y, 1); } else { M.set(x, y, 0); } } } } List<Integer> freeValencies = null; freeValencies = getFreeValenciesForRingGroup(mNew, atomNos, M, ringSet); List<Integer> bondOrders = new ArrayList<Integer>(); for (int j = 0; j < bondNos.size(); j++) { bondOrders.add(0); } if (solveMatrix(M, atomNos, bondNos, freeValencies, atomNoPairs, bondOrders)) { for (int j = 0; j < bondOrders.size(); j++) { mNew.getBond(bondNos.get(j)).setOrder( bondOrders.get(j) == 1 ? IBond.Order.SINGLE : IBond.Order.DOUBLE); } } else { } } return mNew; } FixBondOrdersTool(); IAtomContainer kekuliseAromaticRings(IAtomContainer molecule); 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 = fbot.kekuliseAromaticRings(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(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 = fbot.kekuliseAromaticRings(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); molecule = fbot.kekuliseAromaticRings(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 public void testLargeBioclipseUseCase() throws Exception { String smiles = "COc1ccc2[C@@H]3[C@H](COc2c1)C(C)(C)OC4=C3C(=O)C(=O)C5=C4OC(C)(C)[C@@H]6COc7cc(OC)ccc7[C@H]56"; SmilesParser smilesParser = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer molecule = smilesParser.parseSmiles(smiles); molecule = fbot.kekuliseAromaticRings(molecule); Assert.assertNotNull(molecule); molecule = (IAtomContainer) AtomContainerManipulator.removeHydrogens(molecule); Assert.assertEquals(40, 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(10, doubleBondCount); }
@Test public void xtestPyrrole() throws Exception { IAtomContainer enol = new AtomContainer(); IAtom atom1 = new Atom(Elements.CARBON); atom1.setHybridization(Hybridization.SP2); IAtom atom2 = new Atom(Elements.CARBON); atom2.setHybridization(Hybridization.SP2); IAtom atom3 = new Atom(Elements.CARBON); atom3.setHybridization(Hybridization.SP2); IAtom atom4 = new Atom(Elements.CARBON); atom4.setHybridization(Hybridization.SP2); IAtom atom5 = new Atom(Elements.NITROGEN); atom5.setHybridization(Hybridization.SP2); atom5.setImplicitHydrogenCount(1); IBond bond1 = new Bond(atom1, atom2); IBond bond2 = new Bond(atom2, atom3); IBond bond3 = new Bond(atom3, atom4); IBond bond4 = new Bond(atom4, atom5); IBond bond5 = new Bond(atom5, atom1); enol.addAtom(atom1); enol.addAtom(atom2); enol.addAtom(atom3); enol.addAtom(atom4); enol.addAtom(atom5); enol.addBond(bond1); enol.addBond(bond2); enol.addBond(bond3); enol.addBond(bond4); enol.addBond(bond5); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(enol); enol = fbot.kekuliseAromaticRings(enol); Assert.assertNotNull(enol); Assert.assertEquals(Order.DOUBLE, enol.getBond(0).getOrder());; Assert.assertEquals(Order.SINGLE, enol.getBond(1).getOrder());; Assert.assertEquals(Order.DOUBLE, enol.getBond(2).getOrder());; Assert.assertEquals(Order.SINGLE, enol.getBond(3).getOrder());; Assert.assertEquals(Order.SINGLE, enol.getBond(4).getOrder());; }
@Test public void xtestPyridine() throws Exception { IAtomContainer enol = new AtomContainer(); IAtom atom1 = new Atom(Elements.CARBON); atom1.setHybridization(Hybridization.SP2); IAtom atom2 = new Atom(Elements.CARBON); atom2.setHybridization(Hybridization.SP2); IAtom atom3 = new Atom(Elements.CARBON); atom3.setHybridization(Hybridization.SP2); IAtom atom4 = new Atom(Elements.CARBON); atom4.setHybridization(Hybridization.SP2); IAtom atom5 = new Atom(Elements.CARBON); atom5.setHybridization(Hybridization.SP2); IAtom atom6 = new Atom(Elements.NITROGEN); atom6.setHybridization(Hybridization.SP2); IBond bond1 = new Bond(atom1, atom2); IBond bond2 = new Bond(atom2, atom3); IBond bond3 = new Bond(atom3, atom4); IBond bond4 = new Bond(atom4, atom5); IBond bond5 = new Bond(atom5, atom6); IBond bond6 = new Bond(atom6, atom1); enol.addAtom(atom1); enol.addAtom(atom2); enol.addAtom(atom3); enol.addAtom(atom4); enol.addAtom(atom5); enol.addAtom(atom6); enol.addBond(bond1); enol.addBond(bond2); enol.addBond(bond3); enol.addBond(bond4); enol.addBond(bond5); enol.addBond(bond6); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(enol); enol = fbot.kekuliseAromaticRings(enol); Assert.assertNotNull(enol); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(0).getOrder().numeric() + enol.getBond(5).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(0).getOrder().numeric() + enol.getBond(1).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(1).getOrder().numeric() + enol.getBond(2).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(2).getOrder().numeric() + enol.getBond(3).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(3).getOrder().numeric() + enol.getBond(4).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(4).getOrder().numeric() + enol.getBond(5).getOrder().numeric()); }
@Test public void xtestBenzene() throws Exception { IAtomContainer enol = new AtomContainer(); IAtom atom1 = new Atom(Elements.CARBON); atom1.setHybridization(Hybridization.SP2); IAtom atom2 = new Atom(Elements.CARBON); atom2.setHybridization(Hybridization.SP2); IAtom atom3 = new Atom(Elements.CARBON); atom3.setHybridization(Hybridization.SP2); IAtom atom4 = new Atom(Elements.CARBON); atom4.setHybridization(Hybridization.SP2); IAtom atom5 = new Atom(Elements.CARBON); atom5.setHybridization(Hybridization.SP2); IAtom atom6 = new Atom(Elements.CARBON); atom6.setHybridization(Hybridization.SP2); IBond bond1 = new Bond(atom1, atom2); IBond bond2 = new Bond(atom2, atom3); IBond bond3 = new Bond(atom3, atom4); IBond bond4 = new Bond(atom4, atom5); IBond bond5 = new Bond(atom5, atom6); IBond bond6 = new Bond(atom6, atom1); enol.addAtom(atom1); enol.addAtom(atom2); enol.addAtom(atom3); enol.addAtom(atom4); enol.addAtom(atom5); enol.addAtom(atom6); enol.addBond(bond1); enol.addBond(bond2); enol.addBond(bond3); enol.addBond(bond4); enol.addBond(bond5); enol.addBond(bond6); AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(enol); enol = fbot.kekuliseAromaticRings(enol); Assert.assertNotNull(enol); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(0).getOrder().numeric() + enol.getBond(5).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(0).getOrder().numeric() + enol.getBond(1).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(1).getOrder().numeric() + enol.getBond(2).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(2).getOrder().numeric() + enol.getBond(3).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(3).getOrder().numeric() + enol.getBond(4).getOrder().numeric()); Assert.assertEquals(Order.SINGLE.numeric() + Order.DOUBLE.numeric(), enol .getBond(4).getOrder().numeric() + enol.getBond(5).getOrder().numeric()); }
@Test(timeout = 1000) public void testAcyclic() throws Exception { String smiles = "CCCCCCC"; SmilesParser smilesParser = new SmilesParser(SilentChemObjectBuilder.getInstance()); IAtomContainer molecule = smilesParser.parseSmiles(smiles); molecule = fbot.kekuliseAromaticRings(molecule); Assert.assertNotNull(molecule); }