Hi Tim, Which version are you using? That should work in CDK 2.10 but before that you need to go via the builder. We changed the internals so atoms can know about the molecule they belong to... but an atom can still appear in multiple molecule at once.
public class MolTest { public static void main(String[] args) throws Exception { MDLV2000Reader parser = new MDLV2000Reader( new FileInputStream("../data/example.mol"), IChemObjectReader.Mode.RELAXED); IAtomContainer mol = parser.read(SilentChemObjectBuilder.getInstance().newAtomContainer()); IAtom atom = mol.getAtom(0); Iterable<IBond> bonds = atom.bonds(); } more info: https://github.com/cdk/cdk/wiki/AtomContainer2 (since 7/8 years ago :p) On Tue, 28 Jan 2025 at 11:31, Tim Dudgeon <tdudgeon...@gmail.com> wrote: > I've hit a strange problem with org.openscience.cdk.silent.Atom in that > several methods just throw a UnsupportedOperationException. This doesn't > make much sense to me. > I'm reading a molfile which generates that type of Atom, but if lots of > its methods are unsupported then that molecule isn't much use. What am I > missing? > This is using CDK 2.9. > > package org.squonk.cdk.depict; > > import org.openscience.cdk.interfaces.IAtom; > import org.openscience.cdk.interfaces.IAtomContainer; > import org.openscience.cdk.interfaces.IBond; > import org.openscience.cdk.io.IChemObjectReader; > import org.openscience.cdk.io.MDLV2000Reader; > import org.openscience.cdk.silent.AtomContainer; > > import java.io.FileInputStream; > > public class MolTest { > > public static void main(String[] args) throws Exception { > > MDLV2000Reader parser = new MDLV2000Reader( > new FileInputStream("../data/example.mol"), > IChemObjectReader.Mode.RELAXED); > IAtomContainer mol = parser.read(new AtomContainer()); > IAtom atom = mol.getAtom(0); > Iterable<IBond> bonds = atom.bonds(); > > } > } > _______________________________________________ > Cdk-user mailing list > Cdk-user@lists.sourceforge.net > https://lists.sourceforge.net/lists/listinfo/cdk-user >
_______________________________________________ Cdk-user mailing list Cdk-user@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/cdk-user