Skip to content

Instantly share code, notes, and snippets.

@gilleain
Created March 18, 2009 11:23
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gilleain/81069 to your computer and use it in GitHub Desktop.
Save gilleain/81069 to your computer and use it in GitHub Desktop.
public void clone(IAtomContainer source, IAtomContainer target) {
for (int i = 0; i < source.getAtomCount(); i++) {
IAtom atom = (IAtom) source.getAtom(i).clone();
target.addAtom(atom);
}
for (IBond bond : source.bonds()) {
IBond newBond = (IBond)bond.clone();
IAtom[] newAtoms = new IAtom[bond.getAtomCount()];
for (int j = 0; j < bond.getAtomCount(); ++j) {
IAtom atom = bond.getAtom(j);
newAtoms[j] = getAtomByEquals(target, source, atom);
// newAtoms[j] = getAtomByID(target, atom.getID());
}
newBond.setAtoms(newAtoms);
target.addBond(newBond);
}
}
public IAtom getAtomByID(IAtomContainer container, String id) {
for (IAtom atom : container.atoms()) {
if (atom.getID().equals(id)) {
return atom;
}
}
return null;
}
public IAtom getAtomByEquals(IAtomContainer target, IAtomContainer source, IAtom atom) {
return target.getAtom(source.getAtomNumber(atom));
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment