I just used CDK for the first time (cdk-src+libs-1.4.19) and ran into a java.lang.NullPointerException.
WHAT I DID:
(The molecule I read is from the public ChEMBL database.)
MDLV2000Reader cdkMdlReader = new MDLV2000Reader(is, Mode.STRICT);
Molecule m = cdkMdlReader.read(new Molecule());
ValidationReport report = engine.validateMolecule(m);
EXCEPTION:
I'm not totally sure if I used it right, however, I should probably not have gotten the following exception...
Exception in thread "main" java.lang.NullPointerException
at org.openscience.cdk.validate.BasicValidator.validateHydrogenCount(BasicValidator.java:162)
at org.openscience.cdk.validate.BasicValidator.validateAtom(BasicValidator.java:58)
at org.openscience.cdk.validate.ValidatorEngine.validateAtom(ValidatorEngine.java:94)
at org.openscience.cdk.validate.ValidatorEngine.validateAtomContainer(ValidatorEngine.java:113)
at org.openscience.cdk.validate.ValidatorEngine.validateMolecule(ValidatorEngine.java:273)
MY WORKAROUND:
It seems that atom.getImplicitHydrogenCount() returns null, and, therefore, cannot be compared using the '<' operator. I did not look into the source code of that method. My quick (and probably dirty) workaround:
I changed BasicValidator.java, line 162:
if (atom.getImplicitHydrogenCount() < 0 ) {
to:
if (atom != null && atom.getImplicitHydrogenCount() != null && atom.getImplicitHydrogenCount() < 0 ) {
If can be of any more assistence, please let me know.
All the best,
elboato
Hi,
Thanks for the bug report. In the 1.4.- version hydrogens are not automatically added. Hence you need something like this:
In 1.5.- versions the hydrogens are added in the V2000 reader automatically.
This is still a bug though as it should do a null check, will fix in 1.5.-
John
On 28 Mar 2014, at 08:35, elboato elboato@users.sf.net wrote:
Related
Bugs:
#1335Resolved /patches/753/.
I would also strongly recommend using the 1.5.- releases (latest: 1.5.5).