Hi,
I get a NoSuchAtomException when executing the following code (that I
inherited):
public static IAtomContainer extractSubstructure(IAtomContainer
source, List<IAtom> atoms) {
IAtomContainer output =
SilentChemObjectBuilder.getInstance().newAtomContainer();
int k = 0;
for (IAtom atom : atoms) {
output.addAtom(atom);
source.getConnectedLonePairsList(atom).forEach(lp ->
output.addLonePair(lp));
source.getConnectedSingleElectronsList(atom).forEach(se ->
output.addSingleElectron(se));
k++;
for (int i = k; i < atoms.size(); i++) {
IBond bond = source.getBond(atom, atoms.get(i));
if (bond != null) {
output.addBond(bond);
}
}
}
return output;
}
The stack trace starts at the line with
output.addBond(bond);
and continues with the following lines:
org.openscience.cdk.exception.NoSuchAtomException: Atom is not a
member of this AtomContainer
at
app//org.openscience.cdk.silent.AtomContainer2.getAtomRef(AtomContainer2.java:185)
at
app//org.openscience.cdk.silent.AtomContainer2.newBondRef(AtomContainer2.java:221)
at
app//org.openscience.cdk.silent.AtomContainer2.addBond(AtomContainer2.java:908)
The exception *isn't* thrown if I replace the instantiation of the
IAtomContainer output with
IAtomContainer output = new AtomContainer();
I understand that the exception has something to do with the way
AtomContainer2 is implemented, but I don't know how to switch to the
AtomContainer2 implementation and still retain the intent of the code -
which is to only add atoms, their connected LPs, their connected single
electrons and their connected bonds, but not connected atoms - to the
returned subgraph. Best
Uli
_______________________________________________
Cdk-user mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/cdk-user