ArrayIndexOutOfBoundsException in StructureSearch.initMolecu

User 870ab5b546

31-05-2007 17:53:58

The code:





Code:
    public static boolean matchPrecise_JChem(Molecule respMol,


            Molecule authMol) throws MolFileException {


        try {


            MolSearch s1 = new MolSearch();


            s1.setSearchType(SearchConstants.PERFECT);


            // required for comparing nonaromatized aromatic rings


            s1.setOption(SearchConstants.OPTION_VAGUE_BOND,


                SearchConstants.VAGUE_BOND_OFF);


            s1.setOption(SearchConstants.OPTION_STEREO_MODEL,


                SearchConstants.STEREO_MODEL_GLOBAL); // JChem 3.2.2





            s1.setTarget(respMol);


            s1.setQuery(authMol);


            System.out.println("matchPrecise_JChem: Match resp "


                    + respMol.toFormat("mrv"));


            System.out.println("matchPrecise_JChem: Match struct "


                    + authMol.toFormat("mrv"));


            boolean res1 = s1.isMatching();


            println("matchPrecise_JChem: search result is " + res1);


            return res1;


        } catch (SearchException e2) {


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


            e2.printStackTrace();


            throw new MolFileException("MolFile error " + e2.getMessage());


        }


    } // matchPrecise_JChem(Molecule, Molecule)






The log output:





Code:
matchPrecise_JChem: Match resp <?xml version="1.0" ?>


<MDocument>


  <MChemicalStruct>


    <molecule molID="m1">


      <atomArray


          atomID="a1 a2 a3 a4 a5 a6"


          elementType="C C C C C O"


          x2="49.467529296875 48.133859955826736 50.801198637923264 52.13486797897153 53.46853732001979 52.13486797897153"


          y2="61.61229187672355 60.84227493616451 60.84227493616451 61.61229187672355 60.84227493616451 63.15229187672355"


          />


      <bondArray>


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


        <bond atomRefs2="a1 a3" order="2" />


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


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


        <bond atomRefs2="a4 a6" order="2" />


      </bondArray>


    </molecule>


  </MChemicalStruct>


</MDocument>





matchPrecise_JChem: Match struct <?xml version="1.0" ?>


<MDocument>


  <MChemicalStruct>


    <molecule molID="m1">


      <atomArray


          atomID="a1 a2 a3 a4 a5 a6"


          elementType="C C C C C O"


          formalCharge="0 0 0 0 0 1"


          x2="61.75486633925228 60.1691904674423 63.088535680300545 64.42220502134882 65.75587436239707 64.42220502134882"


          y2="61.7246171332027 61.14205823097373 60.95460019264365 61.7246171332027 60.95460019264365 63.2646171332027"


          />


      <bondArray>


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


        <bond atomRefs2="a1 a3" order="2" />


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


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


        <bond atomRefs2="a4 a6" order="2">


          <bondStereo>C</bondStereo>


        </bond>


      </bondArray>


    </molecule>


  </MChemicalStruct>


</MDocument>





java.lang.ArrayIndexOutOfBoundsException: -1


        at chemaxon.sss.search.StructureSearch.initMolecule(StructureSearch.java:1873)


        at chemaxon.sss.search.StructureSearch.initSearch(StructureSearch.java:1430)


        at chemaxon.sss.search.StructureSearch.findFirst0(StructureSearch.java:5163)


        at chemaxon.sss.search.StructureSearch.isMatching0(StructureSearch.java:5656)


        at chemaxon.sss.search.StructureSearch.isMatching(StructureSearch.java:5648)


        at chemaxon.sss.search.MolSearch.isMatching(MolSearch.java:856)


        at com.prenhall.epoch.chem.MolFunctions.matchPrecise_JChem(MolFunctions.java:211)


        at com.prenhall.epoch.chem.MolFunctions.areResonanceStructures(MolFunctions.java:2064)








We're using JChem 3.2.4. Any ideas what's going wrong? The code and the substrates look fine to me.

ChemAxon a9ded07333

31-05-2007 22:52:18

I could not reproduce the error using the molecules in your post. Would you send the original source of these molecules?





Tamás

User 870ab5b546

01-06-2007 01:18:00

They were not entered in Marvin as such, but as part of a much larger document that was then parsed.





I've fiddled around with the code, and I am no longer generating the errors. They seemed to go away when I stopped replacing H atoms with pseudoatoms. (But in the particular example above, there *were* no pseudoatoms.) Anyway, I'll let you know if they pop up again.

User 870ab5b546

19-06-2007 19:57:15

I came across another error that I think may be the source of the above-reported one.





In the command below, the value of mol is converted to an empty Molecule. Not null, because you can still do operations like mol.toFormat("mrv"). But empty. I was under the impression that an operation that generated a new variable type would not affect the original variable's value. However, cloning the molecule and fragmenting the clone solves the problem.





Code:
Molecule[] c = mol.convertToFrags();






I think I might have had this command prior to sending a Molecule to the method described above, and that may be why there was a search error.

User f359e526a1

20-06-2007 08:23:21

Hm, will see, just debugging the undo process, certainly something is fishy about cloning...

User f359e526a1

20-06-2007 12:18:18

Apparently managed to fix the original undo bug - will a second look at the converToFrags() problem. Bob; does it come forward only for reactions or for any molecules?

User 870ab5b546

20-06-2007 13:35:38

We don't use reactions as you define them, so molecules only.

ChemAxon a3d59b832c

29-06-2007 11:56:24

Bob,





I quote from the apidoc of Molecule.convertToFrags():
Quote:
Warning: Atoms are removed from the original molecule object to the created fragments, therefore the original molecule becomes inconsistent.
http://www.chemaxon.com/jchem/doc/api/chemaxon/struc/Molecule.html#convertToFrags()





So I recommend to clone the molecule before calling Molecule.convertToFrags(), if you still want to use it to any purpose afterwards.





Regards,


Szabolcs

ChemAxon a3d59b832c

29-06-2007 11:58:58

Sorry, I just realized that you wrote the same above.





In summary: yes, that is the correct solution.