Re: [Cdk-user] NoSuchAtomException when switching to AtomContainer2

2022-09-05 Thread John Mayfield
Yes Java doesn't the bytecode/JVM does :-). Here is the setup to show it would break without recompilation downstream: [john@sentinel:test]% cat Upstream_void.java > public class Upstream { > static void Hello() { > System.out.println("Hello (void)!"); > } > } > > [john@sentinel:

Re: [Cdk-user] NoSuchAtomException when switching to AtomContainer2

2022-09-05 Thread Uli Fechner
To the best of my knowledge the return type is not part of the method signature as such in Java. You might think of covariant return types which come into play when overriding a method in a child class, and the child’s return type can be a subtype of the parent’s return type. This was introduced i

Re: [Cdk-user] NoSuchAtomException when switching to AtomContainer2

2022-09-05 Thread John Mayfield
I did contemplate making the addAtom() return the new "ref" the container has... however I think this is technically an API breakage (void => IAtom return type). This would not have been in prior Java versions but at some point they added the return type to the signature. It's kind of a minor break

Re: [Cdk-user] NoSuchAtomException when switching to AtomContainer2

2022-09-05 Thread John Mayfield
Yup! Sorry just drafting stuff out :-) Made the same mistake in the PR which used predicates: https://github.com/cdk/cdk/pull/889/commits/a160def65f79218a410c8fa4fe6ece5e2ed40dde On Mon, 5 Sept 2022 at 14:47, Daniel Katzel wrote: > Surely that line output.getAtom( atom.getAtomicNumber() -1 ) >

Re: [Cdk-user] NoSuchAtomException when switching to AtomContainer2

2022-09-05 Thread Daniel Katzel
Surely that line output.getAtom( atom.getAtomicNumber() -1 ) Was meant to use output.getAtomCount() -1 To get the last atom added? On Mon, Sep 5, 2022, 6:44 AM John Mayfield wrote: > Yes and it's correct, your code is adding bonds to atoms which don't exist > yet! You need to add the atoms of

Re: [Cdk-user] NoSuchAtomException when switching to AtomContainer2

2022-09-05 Thread John Mayfield
Yes and it's correct, your code is adding bonds to atoms which don't exist yet! You need to add the atoms of the bond before the bond - 0..k not k .. n. As an aside the Mappings API has this method already (toSubstructureStream()) if you're coming via CDK substructure Pattern (although it doesn't

[Cdk-user] NoSuchAtomException when switching to AtomContainer2

2022-09-05 Thread Uli Fechner
Hi, I get a NoSuchAtomException when executing the following code (that I inherited): public static IAtomContainer extractSubstructure(IAtomContainer source, List atoms) { IAtomContainer output = SilentChemObjectBuilder.getInstance().newAtomContainer(); int k = 0; for (IAtom atom : at