Skip to content

Instantly share code, notes, and snippets.

@gilleain
Created January 11, 2011 18:44
Show Gist options
  • Save gilleain/774884 to your computer and use it in GitHub Desktop.
Save gilleain/774884 to your computer and use it in GitHub Desktop.
Method to extract substructures from atom containers
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.removeAtomAndConnectedElectronContainers(atom);
}
}
return substructure;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment