search exception

User 870ab5b546

17-12-2009 18:25:03

Our code:


public static boolean matchExact(Molecule respMol, Molecule authMol,
            int stereoType) throws MolFileException {
final MolSearch search = new MolSearch();
        final MolSearchOptions searchOpts = search.getSearchOptions();
        searchOpts.setSearchType(SearchConstants.FULL);
        final boolean ignore3D = ((stereoType & IGNORE_TETRAHEDRAL_STEREO) != 0);
        if (ignore3D) {
            debugPrint(SELF + "ignoring 3D stereochemistry.");
            searchOpts.setStereoSearchType(SearchConstants.STEREO_IGNORE);
        } else {
            searchOpts.setStereoSearchType(SearchConstants.STEREO_SPECIFIC);
            final int wavyType = (stereoType & WAVY_AND);
            if (wavyType == WAVY_AND) {
                debugPrint(SELF + "adding WavyBondMatcher.");
                search.addComparator(new WavyBondMatcher());
                // following line needed to avoid bug in JChem 5.1.3_2 and earlier
                searchOpts.setKeepQueryOrder(true);
            } else { // WAVY_XOR
                debugPrint(SELF + "not adding WavyBondMatcher.");
            } // if stereoType == WAVY_AND
        } // if ignore3D
        final boolean ignore2D = ((stereoType & IGNORE_DBL_BOND_STEREO) != 0);
        if (ignore2D) {
            debugPrint(SELF + "ignoring 2D stereochemistry.");
            searchOpts.setDoubleBondStereoMatchingMode(StereoConstants.DBS_NONE);
        } else {
            searchOpts.setDoubleBondStereoMatchingMode(StereoConstants.DBS_ALL);
        } // if ignore2D
        searchOpts.setVagueBondLevel(SearchConstants.VAGUE_BOND_OFF);
                // required for comparing nonaromatized aromatic rings
        searchOpts.setStereoModel(SearchConstants.STEREO_MODEL_GLOBAL);
        searchOpts.setChargeMatching(SearchConstants.CHARGE_MATCHING_EXACT);
        searchOpts.setIsotopeMatching(SearchConstants.ISOTOPE_MATCHING_EXACT);
        searchOpts.setRadicalMatching(SearchConstants.RADICAL_MATCHING_EXACT);
        searchOpts.setValenceMatching(true);
        search.setSearchOptions(searchOpts);
        search.setTarget(respMol);
        search.setQuery(authMol);
        debugPrintMRV(SELF + "Match exact response:\n", respMol);
        debugPrintMRV(SELF + "Match exact author structure:\n", authMol);
        try {
            final boolean match = search.isMatching();
            debugPrint(SELF + "JChem search result is ", match);
            return match;
        } catch (SearchException e2) {
            Utils.alwaysPrint("Error in " + SELF);
            e2.printStackTrace();
            throw new MolFileException(ERROR + e2.getMessage());
        } // try


The code in WavyBondMatcher:


public boolean compareAtoms(int queryAtomNum, int targetAtomNum) {
        final int qAtomNum = getOrigQueryAtom(queryAtomNum);
        final int tAtomNum = getOrigTargetAtom(targetAtomNum);
        final int qParity = query.getLocalParity(qAtomNum);
        final int tParity = target.getLocalParity(tAtomNum);
        final boolean match = !(qParity == PARITY_EITHER && tParity != PARITY_EITHER);
        return match;

} // compareAtoms(int, int)

The exception:


MolFunctions.matchExact: Match exact response:
<?xml version="1.0" ?>
<cml>
<MDocument>
  <MChemicalStruct>
    <molecule molID="m1">
      <atomArray
          atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9"
          elementType="C C C C C C C H H"
          x2="-6.352499961853027 -5.018820840024992 -3.6851417181969564 -2.35146259636892 -1.017783474540885 0.315895647287151 -7.686179083681063 0.31589564728715114 -1.017783474540885"
          y2="0.5293750166893005 1.2993750166893006 0.5293750166893005 1.2993750166893 0.5293750166892996 1.2993750166892992 1.299375016689301 2.8393750166892993 -1.0106249833107004"
          />
      <bondArray>
        <bond atomRefs2="a1 a2" order="2" />
        <bond atomRefs2="a1 a7" order="1" />
        <bond atomRefs2="a2 a3" order="1" />
        <bond atomRefs2="a3 a4" order="1" />
        <bond atomRefs2="a4 a5" order="1" />
        <bond atomRefs2="a5 a6" order="2" />
        <bond atomRefs2="a5 a9" order="1" />
        <bond atomRefs2="a6 a8" order="1" />
      </bondArray>
    </molecule>
  </MChemicalStruct>
</MDocument>
</cml>

MolFunctions.matchExact: Match exact author structure:
<?xml version="1.0" ?>
<cml>
<MDocument>
  <MChemicalStruct>
    <molecule molID="m1">
      <atomArray
          atomID="a1 a2 a3 a4 a5 a6 a7"
          elementType="C C C C C C C"
          x2="-5.630624771118164 -4.296945649290128 -2.9632665274620926 -1.6295874056340571 -0.29590828380602163 1.0377708380220139 1.0377708380220139"
          y2="-0.48124998807907104 0.28875001192092886 -0.48124998807907104 0.28875001192092886 -0.48124998807907104 0.28875001192092886 1.828750011920929"
          />
      <bondArray>
        <bond atomRefs2="a1 a2" order="1" />
        <bond atomRefs2="a2 a3" order="2" />
        <bond atomRefs2="a3 a4" order="1" />
        <bond atomRefs2="a4 a5" order="1" />
        <bond atomRefs2="a5 a6" order="2" />
        <bond atomRefs2="a6 a7" order="1" />
      </bondArray>
    </molecule>
  </MChemicalStruct>
</MDocument>
</cml>

Error in MolFunctions.matchExact:
chemaxon.sss.search.SearchException: An error occured during search:java.lang.ArrayIndexOutOfBoundsException: -1
  Query:[#6]\C=C\C\C=C/[#6]
  Target:[H]\C=C(\[H])CC\C=C\C

Caused by:
-1
    at chemaxon.sss.search.MolSearch.getWrapperSearchException(MolSearch.java:640)
    at chemaxon.sss.search.MolSearch.isMatching(MolSearch.java:630)
    at com.prenhall.epoch.chem.MolFunctions.matchExact(MolFunctions.java:299)



We're using JChem 5.2.6.  The error occurs when there is a terminal explicit H but not if the only explicit H is internal.


P.S.  This forum software does not work well at all with Safari for Mac.  I had to switch to Firefox to format this post properly.

ChemAxon 42004978e8

18-12-2009 16:24:05

Hi Bob,


Please post the full stack trace so that we can know at which row exactly the call fails.


I guess it fails in you custom comparator after the call 



getOrigTargetAtom(targetAtomNum);


Please note that this index is not necesarly a valid index in the original molecule:


http://chemaxon.com/jchem/doc/api/chemaxon/sss/search/MolComparator.html#getOrigTargetAtom(int)


e.g. in your case explicit H atoms are present in the molecule, hence in case of full (exact) search the implicit hydrogens are initialized in the search process. For such an atom the index retrieved by the above method is -1.


Please check for non equality with -1 before calling the stereo calculation functions for these indexes.


This should eliminate the problem. Does it?


Bye,


Robert

User 870ab5b546

18-12-2009 16:47:23

Thanks for your help.  We added a check for qAtomNum and tAtomNum != -1 in WavyBondMatcher.compare() before getting the parities of the atoms, and that solved the problem.


public boolean compareAtoms(int queryAtomNum, int targetAtomNum) {
        boolean match = true;
        final int qAtomNum = getOrigQueryAtom(queryAtomNum);
        final int tAtomNum = getOrigTargetAtom(targetAtomNum);
        if (qAtomNum != -1 && tAtomNum != -1) {
            final int qParity = query.getLocalParity(qAtomNum);
            final int tParity = target.getLocalParity(tAtomNum);
            match = !(qParity == PARITY_EITHER && tParity != PARITY_EITHER);
        } // if neither query nor target atom is implicit H
        return match;
} // compareAtoms(int, int)