public static IAtomContainer extractSubstructure ( IAtomContainer atomContainer , int ... atomIndices ) throws CloneNotSupportedException { IAtomContainer substructure = ( IAtomContainer ) atomContainer . clone ( ) ; int numberOfAtoms = substructure . getAtomCount ( ) ; IAtom [ ] atoms = new IAtom [ numberOfAtoms ] ; for ( int atomIndex = 0 ; atomIndex < numberOfAtoms ; atomIndex ++ ) { atoms [ atomIndex ] = substructure . getAtom ( atomIndex ) ; } Arrays . sort ( atomIndices ) ; for ( int index = 0 ; index < numberOfAtoms ; index ++ ) { if ( Arrays . binarySearch ( atomIndices , index ) < 0 ) { IAtom atom = atoms [ index ] ; substructure . removeAtom ( atom ) ; } } return substructure ; }
Extract a substructure from an atom container in the form of a new cloned atom container with only the atoms with indices in atomIndices and bonds that connect these atoms .