We are using the Ambit SMIRKS library in our application, SMIRKS are used to transform structures, and on certain transformation products, we get a NullPointerExceptuion when validating the compound using CDK. I attached an example code where this happens. I think CDK should avoid this and not throw a NullPointer, but there seems to be something wrong with the IAtomContainer which is produced by the SMIRKS library. The Exception is:
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 Test.main(Test.java:38)
This happens in both Version 2.4.2 and Version 2.5.1.
I attached an example class which can be used to reproduce the problem. If you get the SMILES from the structure and create a new IAtomContainer, the validation works.
The newly created atoms by Ambit-SMIRKS did not have implicit H atoms set which causes this bug.
Since SVN rev 5042 the newly created atoms implicit H should be initialized with a non null object.
Deployed at Maven repository as 2.5.2-SNAPSHOT (ambit.uni-plovdiv.bg)
Last edit: Nina Jeliazkova 2013-10-17
I would propose to revert the fix setting implicit hydrogens to Integer[0], as this might not be the correct chemistry.
Instead, provide an optional function (as below) to set the correct atom parameters (implicit H is only one of the parameters which are not set correctly after applying the transformation).
Last edit: Nina Jeliazkova 2013-10-22