Skip to content

Commit

Permalink
CXSMILES optimisation - don't create and swap a new Pseudo atom if th…
Browse files Browse the repository at this point in the history
…e atom to set the label on is already a pseudo atom.
  • Loading branch information
johnmay authored and egonw committed Feb 3, 2022
1 parent ade938a commit 454fbe9
Showing 1 changed file with 12 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,18 @@ private void assignCxSmilesInfo(IChemObjectBuilder bldr,
continue;

IAtom old = atoms.get(e.getKey());
IPseudoAtom pseudo = bldr.newInstance(IPseudoAtom.class);
IPseudoAtom pseudo;
if (old instanceof IPseudoAtom) {
pseudo = (IPseudoAtom) old;
} else {
// possibly a warning, is "CCO |$R$|" valid?
pseudo = bldr.newInstance(IPseudoAtom.class);
IAtomContainer mol = atomToMol.get(old);
AtomContainerManipulator.replaceAtomByAtom(mol, old, pseudo);
atomToMol.put(pseudo, mol);
atoms.set(e.getKey(), mol.getAtom(old.getIndex()));
}

String val = e.getValue();

// specialised label handling
Expand All @@ -509,10 +520,6 @@ else if (val.startsWith("_AP")) // attachment point
pseudo.setLabel(val);
pseudo.setAtomicNumber(0);
pseudo.setImplicitHydrogenCount(0);
IAtomContainer mol = atomToMol.get(old);
AtomContainerManipulator.replaceAtomByAtom(mol, old, pseudo);
atomToMol.put(pseudo, mol);
atoms.set(e.getKey(), mol.getAtom(old.getIndex()));
}
}

Expand Down

0 comments on commit 454fbe9

Please sign in to comment.