LibraryMCS NullPointerException

User 2347372188

25-03-2014 15:48:20

Hello.  I'm getting a NullPointerException while using the LibraryMCS Java API.  This is what I get for a stack trace:


java.lang.NullPointerException


at chemaxon.clustering.LibraryMCS$ClusterEnumerator.next(LibraryMCS.java:744)


 


I'm using version 6.2.0.  Please let me know if you have a fix/work-around.  Thanks.


-&

ChemAxon 5fc3e8d7d0

28-03-2014 10:28:16

Dear Steven,

We cannot reproduce this issue.
Could you send us a short example code which does not work for you? Is NPE thrown by every molecule set or only by a specific?

Best regards,
Laszlo

User 2347372188

28-03-2014 17:28:50

I'm doing several thousand pairwise comparisons.  The vast majority of the comparisons work fine.  There may be a better way of doing what I'm trying to do.  Please see my method below.  The NPE is thrown at the ce.next() method call.  Unfortunately, catching the NPE doesn't work.


    public static Molecule calcMcs(Molecule m1, Molecule m2) {


        log.debug("Entered calcMcs()");


        LibraryMCS mcs = new LibraryMCS();


//        mcs.setAtomTypeMatch(false);


        mcs.setAtomTypeMatch(true);


        LibraryMCS.ClusterEnumerator ce = null;


        mcs.addMolecule(m1);


        mcs.addMolecule(m2);


        Boolean srch = null;


        Molecule rcore = null;


        Integer cnt = 0;


        try {


            srch = mcs.search();


        } catch (InterruptedException ex) {


            ex.printStackTrace();


        }


        if (!srch) {


            try {


                log.error("could not find MCSS: " + MolExporter.exportToFormat(m1, "smiles:u") + "  " + MolExporter.exportToFormat(m2, "smiles:u"));


            } catch (IOException ex) {


                ex.printStackTrace();


            }


            return null;


        } else {


            ce = mcs.getClusterEnumerator(false);


            Molecule core = null;


            while (ce != null && ce.hasNext()) {


                try {


                    core = ce.next();


                } catch (NullPointerException npe) {


                    log.error("Caught NullPointerException", npe);


                    return null;


                }


                cnt++;


                if (rcore != null) {


                    if (rcore.getMass() < core.getMass()) {


                        rcore = core;


                    }


                } else {


                    rcore = core;


                }


            }


        }


        log.debug("leaving calcMcs: " + cnt);


        return rcore;


    }

ChemAxon 5fc3e8d7d0

16-04-2014 12:42:52

Dear Steven,

Sorry for the very late answer.
We have investigated the issue and hopefully we will fix it in the next release.

There are a simpler way to find the MCS of two molecules. Please try the following code:


MaxCommonSubstructure mcs = MaxCommonSubstructure.newInstance();
mcs.setMolecules(Molecule m1, Molecule m2);
McsSearchResult result = mcs.nextResult();
        
result.getAsMolecule();

API documentation: https://www.chemaxon.com/jchem/doc/dev/java/api/com/chemaxon/search/mcs/MaxCommonSubstructure.html />
Best regards,
Laszlo