SearchException

User 870ab5b546

14-04-2009 13:05:27

JChem 5.1.0.  The code:


 


 



    private static boolean matchSigmaNetworkNoClone(Molecule respMol,

            Molecule authMol, boolean respIsLewis) throws MolFileException {

        // respMol may have been drawn with LewisSketch

        sigmaNormalize(respMol, respIsLewis);

        // authMol always drawn with Marvin

        sigmaNormalize(authMol, false);

        debugPrint("matchSigmaNetwork: response after "

                + "adding H atoms and sigmanormalizing: \n"

                + respMol.toFormat("mrv"));

        debugPrint("matchSigmaNetwork: author structure after "

                + "adding H atoms and sigmanormalizing: \n"

                + authMol.toFormat("mrv"));

        MolSearch search = new MolSearch();

        MolSearchOptions searchOpts = new MolSearchOptions();

        searchOpts.setSearchType(SearchConstants.EXACT);

        searchOpts.setExactBondMatching(false);

        searchOpts.setChargeMatching(SearchConstants.CHARGE_MATCHING_IGNORE);

        searchOpts.setRadicalMatching(SearchConstants.RADICAL_MATCHING_IGNORE);

        searchOpts.setIsotopeMatching(SearchConstants.ISOTOPE_MATCHING_EXACT);

        searchOpts.setValenceMatching(false);

        searchOpts.setStereoSearchType(SearchConstants.STEREO_SPECIFIC);

        searchOpts.setStereoModel(SearchConstants.STEREO_MODEL_GLOBAL);

        search.setSearchOptions(searchOpts);

        search.addComparator(new ExplicitHMatcher());

        search.setTarget(authMol);

        search.setQuery(respMol);

        try {

            boolean match = search.isMatching();

            debugPrint("MolFunctions.matchSigmaNetwork: returning " + match);

            return match;

        } catch (SearchException e2) {

            System.out.println("Error in matchSigmaNetwork ");

            throw new MolFileException(e2.getMessage());

        }

    } // matchSigmaNetworkNoClone(Molecule, Molecule, boolean)


The output:




matchSigmaNetwork: response after adding H atoms and sigmanormalizing: 

<?xml version="1.0" ?>

<cml>

<MDocument>

  <MChemicalStruct>

    <molecule molID="m1">

      <atomArray

          atomID="a1"

          elementType="H"

          formalCharge="1"

          x2="48.125"

          y2="55.680625915527344"

          />

      <bondArray>

      </bondArray>

    </molecule>

  </MChemicalStruct>

</MDocument>

</cml>



matchSigmaNetwork: author structure after adding H atoms and sigmanormalizing: 

<?xml version="1.0" ?>

<cml>

<MDocument>

  <MChemicalStruct>

    <molecule molID="m1">

      <atomArray

          atomID="a1 a2 a3 a4 a5"

          elementType="H C O H H"

          formalCharge="0 0 1 0 0"

          x2="-21.140705430069907 -19.807026308241873 -19.807026308241873 -18.71808186521459 -18.47334718641384"

          y2="1.443766923869739 2.21376692386974 3.75376692386974 1.1248224808424567 4.52376692386974"

          />

      <bondArray>

        <bond atomRefs2="a1 a2" order="1" />

        <bond atomRefs2="a2 a3" order="1" />

        <bond atomRefs2="a2 a4" order="1" />

        <bond atomRefs2="a3 a5" order="1" />

      </bondArray>

    </molecule>

  </MChemicalStruct>

</MDocument>

</cml>



Error in matchSigmaNetwork 

Caught exception:

An error occured during search:java.lang.ArrayIndexOutOfBoundsException

  Query:[H+]

  Target:[H][OH+]C([H])[H]


Caused by:

java.lang. ArrayIndexOutOfBoundsException







 


Why am I getting an ArrayIndexOutOfBoundsException?

ChemAxon a9ded07333

14-04-2009 13:54:14

Hi Bob,


I think the exception is thrown by your ExplicitHMatcher MolComparator (commenting it out the exception does not occur).


Could you send its source?


Regards,
Tamás

User 870ab5b546

14-04-2009 15:54:45

 


Yes, you're right.  I added more debugging output to compareAtoms:


 




    public boolean compareAtoms(int queryAtomNum, int targetAtomNum) {

        debugPrint("Entering ExplicitHMatcher.compareAtoms: "

                + "query = " + query.toFormat("smiles")

                + ", target = " + target.toFormat("smiles")

                + "; internal qAtomNum = " + (queryAtomNum + 1)

                + ", internal tAtomNum = " + (targetAtomNum + 1)

                );

        int qAtomNum = getOrigQueryAtom(queryAtomNum);

        int tAtomNum = getOrigTargetAtom(targetAtomNum);

        debugPrint("ExplicitHMatcher.compareAtoms: "

                + "getting query atom " + (qAtomNum + 1)

                + ", target atom " + (tAtomNum + 1)

                );

        MolAtom qAtom = query.getAtom(qAtomNum);

        MolAtom tAtom = target.getAtom(tAtomNum);

        debugPrint("ExplicitHMatcher.compareAtoms: "

                + "getting qAtom.getExplicitHcount() for "

                + qAtom.getSymbol() + (qAtomNum + 1));

        int qHCount = qAtom.getExplicitHcount();

        debugPrint("ExplicitHMatcher.compareAtoms: "

                + "getting tAtom.getExplicitHcount() for "

                + tAtom.getSymbol() + (tAtomNum + 1));

        int tHCount = tAtom.getExplicitHcount();

        boolean match = (qHCount == tHCount);

        debugPrint("qAtom " + qAtom.getSymbol() + (qAtomNum + 1)

                + " has " + qHCount + " explicit H atoms"

                + "; tAtom " + tAtom.getSymbol() + (tAtomNum + 1)

                + " has " + tHCount + " explicit H atoms"

                + "; atoms " + (match ? "" : "do not ") + "match.");

        return match;

    } // compareAtoms(int, int)



And I get this output in the log:



Entering ExplicitHMatcher.compareAtoms: query = [H+], target = [H][OH+]C([H])[H]; internal qAtomNum = 1, internal tAtomNum = 1

ExplicitHMatcher.compareAtoms: getting query atom 1, target atom 1

ExplicitHMatcher.compareAtoms: getting qAtom.getExplicitHcount() for H1

ExplicitHMatcher.compareAtoms: getting tAtom.getExplicitHcount() for H1

qAtom H1 has 0 explicit H atoms; tAtom H1 has 0 explicit H atoms; atoms match.

Entering ExplicitHMatcher.compareAtoms: query = [H+], target = [H][OH+]C([H])[H]; internal qAtomNum = 1, internal tAtomNum = 4

ExplicitHMatcher.compareAtoms: getting query atom 1, target atom 4

ExplicitHMatcher.compareAtoms: getting qAtom.getExplicitHcount() for H1

ExplicitHMatcher.compareAtoms: getting tAtom.getExplicitHcount() for H4

qAtom H1 has 0 explicit H atoms; tAtom H4 has 0 explicit H atoms; atoms match.

Entering ExplicitHMatcher.compareAtoms: query = [H+], target = [H][OH+]C([H])[H]; internal qAtomNum = 1, internal tAtomNum = 5

ExplicitHMatcher.compareAtoms: getting query atom 1, target atom 5

ExplicitHMatcher.compareAtoms: getting qAtom.getExplicitHcount() for H1

ExplicitHMatcher.compareAtoms: getting tAtom.getExplicitHcount() for H5

qAtom H1 has 0 explicit H atoms; tAtom H5 has 0 explicit H atoms; atoms match.

Entering ExplicitHMatcher.compareAtoms: query = [H+], target = [H][OH+]C([H])[H]; internal qAtomNum = 1, internal tAtomNum = 6

ExplicitHMatcher.compareAtoms: getting query atom 1, target atom 0

Error in matchSigmaNetwork 

Caught exception:

An error occured during search:java.lang.ArrayIndexOutOfBoundsException: -1

  Query:[H+]

  Target:[H][OH+]C([H])[H]


Caused by:

-1




So, now the question is why compareAtoms() is getting an index of -1 for an atom in the target.




 

ChemAxon a9ded07333

15-04-2009 09:52:33

Hi Bob,


Since there is an explicit hydrogen in the query molecule, search initialises implicit hydrogens as well and -1 represents an implicit H (of O and C) in the target. You should handle this case in ExplicitHMatcher, e.g.


        int tAtomNum = getOrigTargetAtom(targetAtomNum);
        int tHCount = 0;
        if (tAtomNum != -1) {
            MolAtom tAtom = target.getAtom(tAtomNum);
            tHCount = tAtom.getExplicitHcount();
        }


Regards,
Tamás

User 870ab5b546

15-04-2009 13:10:43

Thanks, that solves the problem.