Created
January 11, 2011 18:44
-
-
Save gilleain/774884 to your computer and use it in GitHub Desktop.
Method to extract substructures from atom containers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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