protected static List < IAtomContainer > splitMolecule ( IAtomContainer atomContainer , IBond bond ) { List < IAtomContainer > ret = new ArrayList < IAtomContainer > ( ) ; for ( IAtom atom : bond . atoms ( ) ) { // later on we'll want to make sure that the fragment doesn't contain // the bond joining the current atom and the atom that is on the other side 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 ) ; // at this point we have a partion which contains the bond we // split. This partition should actually 2 partitions: // - one with the splitting bond // - one without the splitting bond // note that this will lead to repeated fragments when we do this // with adjacent bonds, so when we gather all the fragments we need // to check for repeats IAtomContainer partContainer ; partContainer = makeAtomContainer ( atom , part , excludedAtom ) ; // by checking for more than 2 atoms, we exclude single bond fragments // also if a fragment has the same number of atoms as the parent molecule, // it is the parent molecule, so we exclude it. 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 ; }
Non destructively split a molecule into two parts at the specified bond .