#1302 SMARTSParser and HydrogenAtom class - another SMARTS error

master
closed
nobody
None
5
2015-02-12
2013-06-06
Duece99
No

Hello,

Whenever I use the SMARTSParser static method "parse" to generate an IQueryAtomContainer, I find that whenever I have hydrogen atoms in the molecule, there's a matching error.

Specifically I'm using the Isomorphism class to perform subgraph mapping. I get this error whenever I call the init() method:

Exception in thread "main" java.lang.NullPointerException
    at org.openscience.cdk.isomorphism.matchers.smarts.TotalHCountAtom.getHC(TotalHCountAtom.java:48)
    at org.openscience.cdk.isomorphism.matchers.smarts.TotalHCountAtom.matches(TotalHCountAtom.java:52)
    at org.openscience.cdk.isomorphism.matchers.smarts.LogicalOperatorAtom.matches(LogicalOperatorAtom.java:87)
    at org.openscience.cdk.isomorphism.matchers.smarts.LogicalOperatorAtom.matches(LogicalOperatorAtom.java:87)
    at org.openscience.cdk.isomorphism.matchers.smarts.LogicalOperatorAtom.matches(LogicalOperatorAtom.java:87)
    at org.openscience.cdk.smsd.algorithm.matchers.DefaultVFAtomMatcher.matches(DefaultVFAtomMatcher.java:176)
    at org.openscience.cdk.smsd.algorithm.vflib.map.VFState.matchAtoms(VFState.java:216)
    at org.openscience.cdk.smsd.algorithm.vflib.map.VFState.isMatchFeasible(VFState.java:158)
    at org.openscience.cdk.smsd.algorithm.vflib.map.VFMCSMapper.mapAll(VFMCSMapper.java:233)
    at org.openscience.cdk.smsd.algorithm.vflib.map.VFMCSMapper.mapAll(VFMCSMapper.java:235)
    at org.openscience.cdk.smsd.algorithm.vflib.map.VFMCSMapper.getMaps(VFMCSMapper.java:140)
    at org.openscience.cdk.smsd.algorithm.vflib.VFlibMCSHandler.searchVFMCSMappings(VFlibMCSHandler.java:228)
    at org.openscience.cdk.smsd.algorithm.vflib.VFlibMCSHandler.searchMCS(VFlibMCSHandler.java:109)
    at org.openscience.cdk.smsd.Isomorphism.vfLibMCS(Isomorphism.java:403)
    at org.openscience.cdk.smsd.Isomorphism.vfLibMCSAlgorithm(Isomorphism.java:552)
    at org.openscience.cdk.smsd.Isomorphism.chooseAlgorithm(Isomorphism.java:325)
    at org.openscience.cdk.smsd.Isomorphism.mcsBuilder(Isomorphism.java:246)
    at org.openscience.cdk.smsd.Isomorphism.init(Isomorphism.java:603)
    at org.knime.cisrg.hyperstructures.construction.CDKSMARTSMatchingBugTest.main(CDKSMARTSMatchingBugTest.java:33)

My code is here to highlight this issue:

package org.knime.cisrg.hyperstructures.construction;

import org.openscience.cdk.DefaultChemObjectBuilder;
import org.openscience.cdk.exception.CDKException;
import org.openscience.cdk.exception.InvalidSmilesException;
import org.openscience.cdk.interfaces.IAtomContainer;
import org.openscience.cdk.isomorphism.matchers.IQueryAtomContainer;
import org.openscience.cdk.isomorphism.matchers.QueryAtomContainer;
import org.openscience.cdk.smiles.SmilesGenerator;
import org.openscience.cdk.smiles.SmilesParser;
import org.openscience.cdk.smiles.smarts.parser.SMARTSParser;
import org.openscience.cdk.smsd.Isomorphism;
import org.openscience.cdk.smsd.interfaces.Algorithm;

public class CDKSMARTSMatchingBugTest {

    public static void main( String[] argv ) {

        SmilesGenerator sg = new SmilesGenerator(true);
        SmilesParser sp = new SmilesParser( DefaultChemObjectBuilder.getInstance() );
        IQueryAtomContainer mol1 = null;
        IAtomContainer mol2 = null;
        try {
            mol1 = SMARTSParser.parse("C=C[C@H]1CN2CC[C@H]1CC2[C@@H](O)c1ccnc2ccc(OC)cc21", DefaultChemObjectBuilder.getInstance() );
            mol2 = sp.parseSmiles("C=C[C@H]1CN2CC[C@H]1CC2[C@@H](O)c1ccnc2ccc(OC)cc21");
        } catch (InvalidSmilesException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

        Isomorphism comparator = new Isomorphism(Algorithm.VFLibMCS, true);
        try {
            comparator.init( new QueryAtomContainer(mol1, mol1.getBuilder()), mol2 );
        } catch (CDKException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

}

The constant in the TotalHCountAtom objects aren't being set for some reason. One of the developers helpfully pointed me to this line of code where this' supposed to be set:

https://github.com/johnmay/cdk/blob/master/src/main/org/openscience/cdk/smiles/smarts/SMARTSQueryTool.java#L486

Thanks in advance,
Ed.

Discussion

  • John May

    John May - 2013-06-06

    Just to clarify, the issue is SMSD Isomophism.init() doesn't configure (all) the query chem objects before matching.

    J

     
  • John May

    John May - 2013-06-06

    So I know you want the QueryAtomContainer but just noting that

    C=C[C@H]1CN2CC[C@H]1CC2C@@Hc1ccnc2ccc(OC)cc21

    isn't smarts, you need not treat it as such. You can load these both as SMILES and don't need to do the query container at all.

    J

     
    Last edit: John May 2013-06-06
  • John May

    John May - 2013-06-06
    • Group: cdk-1.6.x --> master
     
  • John May

    John May - 2013-06-06

    Did you try using the other init() method with the 'cleanAndConfigure' molecule setting?

    ~~~~~:::java

    public class CDKSMARTSMatchingBugTest {

    public static void main( String[] argv ) throws Exception  {
        IAtomContainer a = smiles("C=C[C@H]1CN2CC[C@H]1CC2[C@@H](O)c1ccnc2ccc(OC)cc21");
        IAtomContainer b = smiles("C=C[C@H]1CN2CC[C@H]1CC2[C@@H](O)c1ccnc2ccc(OC)cc21");
    
        Isomorphism smsd = new Isomorphism(Algorithm.VFLibMCS, true);       
        smsd.init(a, b, false, true);       
    }
    
    static IAtomContainer smiles(String smi) throws Exception {
        return new SmilesParser(SilentChemObjectBuilder.getInstance()).parseSmiles(smi);
    }
    

    }
    ~~~~~

     
    Last edit: John May 2013-06-06
  • John May

    John May - 2013-12-18

    Resolved - SMARTS invariants are now configured in a single location (SMARTSInvariants) removing the error > 1.5.

     
  • John May

    John May - 2013-12-18
    • status: open --> closed
     

Log in to post a comment.

Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:





No, thanks