Hi,

Thanks for the bug report. In the 1.4.- version hydrogens are not automatically added. Hence you need something like this:

MDLV2000Reader cdkMdlReader = new MDLV2000Reader(is, Mode.STRICT);

Molecule m = cdkMdlReader.read(new Molecule());
AtomContainerManipulator.perceiveAndConfigureAtomTypes(m);
CDKHydrogenAdder.getInstance(m.getBuilder()).addImplicitHydrogens(m);
ValidationReport report = engine.validateMolecule(m);

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:


[bugs:#1335] NullPointerException in BasicValidator.validateHydrogenCount()

Status: open
Group: cdk-1.4.x
Created: Fri Mar 28, 2014 08:35 AM UTC by elboato
Last Updated: Fri Mar 28, 2014 08:35 AM UTC
Owner: nobody

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


Sent from sourceforge.net because cdk-bugs@lists.sf.net is subscribed to https://sourceforge.net/p/cdk/bugs/

To unsubscribe from further messages, a project admin can change settings at https://sourceforge.net/p/cdk/admin/bugs/options. Or, if this is a mailing list, you can unsubscribe from the mailing list.

------------------------------------------------------------------------------
_______________________________________________
Cdk-bugs mailing list
Cdk-bugs@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/cdk-bugs