MoleculeSanityCheck { public static IAtomContainer checkAndCleanMolecule(IAtomContainer molecule) { boolean isMarkush = false; for (IAtom atom : molecule.atoms()) { if (atom.getSymbol().equals("R")) { isMarkush = true; break; } } if (isMarkush) { System.err.println("Skipping Markush structure for sanity check"); } if (!ConnectivityChecker.isConnected(molecule)) { IAtomContainerSet fragments = ConnectivityChecker.partitionIntoMolecules(molecule); if (fragments.getAtomContainerCount() > 2) { System.err.println("More than 2 components. Skipped"); } else { IAtomContainer frag1 = fragments.getAtomContainer(0); IAtomContainer frag2 = fragments.getAtomContainer(1); if (frag1.getAtomCount() > frag2.getAtomCount()) { molecule = frag1; } else { molecule = frag2; } } } configure(molecule); return molecule; }  static IAtomContainer checkAndCleanMolecule(IAtomContainer molecule); static void configure(IAtomContainer mol);  }
@Test public void testCheckAndCleanMolecule() throws InvalidSmilesException { String fragmentMolSmiles = "C1=CC=CC=C1.C1=CC2=C(C=C1)C=CC=C2"; SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer molecule = sp.parseSmiles(fragmentMolSmiles); IAtomContainer expResult = sp.parseSmiles("C1=CC2=C(C=C1)C=CC=C2"); IAtomContainer result = MoleculeSanityCheck.checkAndCleanMolecule(molecule); assertEquals(expResult.getBondCount(), result.getBondCount()); }
@Test public void testFixAromaticity() throws InvalidSmilesException { String rawMolSmiles = "C1=CC2=C(C=C1)C=CC=C2"; SmilesParser sp = new SmilesParser(DefaultChemObjectBuilder.getInstance()); IAtomContainer mol = sp.parseSmiles(rawMolSmiles); MoleculeSanityCheck.checkAndCleanMolecule(mol); int count = 0; for (IBond b : mol.bonds()) { if (b.getFlag(CDKConstants.ISAROMATIC) && b.getOrder().equals(IBond.Order.DOUBLE)) { count++; } } assertEquals(5, count); }