Menu

#74 NullPointerException when validating SMIRKS transformation output

ambit2-smirks
open
5
2016-03-29
2013-10-14
jorro
No

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.

1 Attachments

Discussion

  • Nina Jeliazkova

    Nina Jeliazkova - 2013-10-14
    • assigned_to: ntk
     
  • Nina Jeliazkova

    Nina Jeliazkova - 2013-10-17

    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

     

    Last edit: Nina Jeliazkova 2013-10-17
  • Nina Jeliazkova

    Nina Jeliazkova - 2013-10-17
    • labels: --> ambit2-smarts
    • Group: ambit2-2.4.12 --> ambit2-www-2.5.2
     
  • Nina Jeliazkova

    Nina Jeliazkova - 2013-10-22

    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).

    for (IAtomContainer ac : products.atomContainers()) {
        for (IAtom atom: ac.atoms()) {
            atom.setFormalNeighbourCount((Integer) CDKConstants.UNSET);
        atom.setAtomTypeName((String) CDKConstants.UNSET);
        atom.setMaxBondOrder((IBond.Order) CDKConstants.UNSET);
        atom.setBondOrderSum((Double) CDKConstants.UNSET);
        atom.setHybridization((IAtomType.Hybridization) CDKConstants.UNSET);
        atom.setFlag(CDKConstants.ISAROMATIC, false);
        }
        for (IBond bond : ac.bonds()) {
        bond.setFlag(CDKConstants.ISAROMATIC, false);
        }
        //once unset, perceive the correct atom types. This will set all the atom parameters
         AtomContainerManipulator.percieveAtomTypesAndConfigureAtoms(ac);
    }
    
     

    Last edit: Nina Jeliazkova 2013-10-22
  • Nina Jeliazkova

    Nina Jeliazkova - 2015-11-23
    • Group: ambit2-www-2.7.5 --> ambit-3.0.1
     
  • Nina Jeliazkova

    Nina Jeliazkova - 2016-03-29
    • Group: ambit-3.0.2 --> ambit2-smirks
     

Log in to post a comment.