FragmentUtils { protected static List<IAtomContainer> splitMolecule(IAtomContainer atomContainer, IBond bond) { List<IAtomContainer> ret = new ArrayList<IAtomContainer>(); for (IAtom atom : bond.atoms()) { IAtom excludedAtom; if (atom.equals(bond.getBegin())) excludedAtom = bond.getEnd(); else excludedAtom = bond.getBegin(); List<IBond> part = new ArrayList<IBond>(); part.add(bond); part = traverse(atomContainer, atom, part); IAtomContainer partContainer; partContainer = makeAtomContainer(atom, part, excludedAtom); if (partContainer.getAtomCount() > 2 && partContainer.getAtomCount() != atomContainer.getAtomCount()) ret.add(partContainer); part.remove(0); partContainer = makeAtomContainer(atom, part, excludedAtom); if (partContainer.getAtomCount() > 2 && partContainer.getAtomCount() != atomContainer.getAtomCount()) ret.add(partContainer); } return ret; }    }
@Test public void testSplit() throws CDKException { IAtomContainer mol = smilesParser.parseSmiles("C1CC1C2CCC2"); SpanningTree st = new SpanningTree(mol); IRingSet rings = st.getAllRings(); IBond splitBond = null; for (int i = 0; i < mol.getBondCount(); i++) { if (rings.getRings(mol.getBond(i)).getAtomContainerCount() == 0) { splitBond = mol.getBond(i); break; } } List<IAtomContainer> frags = FragmentUtils.splitMolecule(mol, splitBond); SmilesGenerator sg = new SmilesGenerator(); Set<String> uniqueFrags = new HashSet<String>(); for (IAtomContainer frag : frags) { uniqueFrags.add(sg.create(frag)); } Assert.assertEquals(2, uniqueFrags.size()); org.hamcrest.MatcherAssert.assertThat(uniqueFrags, hasItems("[CH]1CC1", "[CH]1CCC1")); }