User 870ab5b546
03-02-2016 17:17:31
Hi,
The code:
final int EXACTLY = 0;
final int ATLEAST = 1;
final int oper = ATLEAST;
private boolean matchMapPattern(Molecule respMol, Molecule authMol)
throws VerifyException {
final String SELF = "MapProperty.matchMapPattern: ";
try {
final MolSearchOptions searchOpts = new MolSearchOptions(FULL);
searchOpts.setStereoSearchType(STEREO_SPECIFIC);
// checkEnant is irrelevant for map patterns
searchOpts.setDoubleBondStereoMatchingMode(DBS_ALL);
searchOpts.setExactBondMatching(true);
searchOpts.setStereoModel(STEREO_MODEL_LOCAL);
// required for diastereotopic atoms not to match
searchOpts.setOrderSensitiveSearch(true); // want multiple results
searchOpts.setIgnoreCumuleneOrRingCisTransStereo(false); // odd-numbered cumulenes
searchOpts.setIgnoreAxialStereo(false); // allenes & biaryls
searchOpts.setIgnoreSynAntiStereo(true);
final MolSearch search = new MolSearch();
search.setSearchOptions(searchOpts);
search.setTarget(respMol);
search.setQuery(authMol);
final int MAX_MAP_NUMBER = 99;
boolean haveMatch = false;
while (true) {
final int[] isomorphism = search.findNext(); // *** throws OutOfMemoryError
if (isomorphism == null) {
debugPrint(SELF + "no more isomorphisms found.");
break;
} else debugPrint(SELF + "looking at isomorphism: {",
Utils.join(isomorphism, 1), "}");
final int[] maps = new int[MAX_MAP_NUMBER + 1]; // maps[respMap] = refMap
final int[] mapsInvert = new int[MAX_MAP_NUMBER + 1]; // mapsInvert[refMap] = respMap
haveMatch = true;
for (int atomNum = 0; atomNum < isomorphism.length; atomNum++) {
final MolAtom authAtom = authMol.getAtom(atomNum);
final MolAtom respAtom = (isomorphism[atomNum] >= 0
? respMol.getAtom(isomorphism[atomNum])
: new MolAtom(1));
final int refMap = authAtom.getAtomMap();
final int respMap = respAtom.getAtomMap();
if (refMap == 0 && (respMap == 0 || oper == ATLEAST))
continue; // maps are OK; next atom in array
if (respMap == 0 || (refMap == 0 && oper == EXACTLY)) {
haveMatch = false; // bad isomorphism; keep looking
break;
} // if response atom is unmapped
// both atoms are mapped; compare
if (maps[respMap] == 0 && mapsInvert[refMap] == 0) {
// first encounter with respMap && refMap
maps[respMap] = refMap;
mapsInvert[refMap] = respMap;
} // if maps[] and mapsInvert[]
if (maps[respMap] != refMap) {
haveMatch = false;
break;
}
} // for each atom atomNum
if (haveMatch) {
debugPrint(SELF + "found a match!");
break;
} // if there's a match
} // loop until match found or no more isomorphisms
debugPrint(SELF + "returning ", haveMatch);
return haveMatch;
} catch (Exception e1) {
e1.printStackTrace();
throw new VerifyException("internal error in matchMapPattern");
}
} // matchMapPattern(Molecule, Molecule)
respMol has MRV:
<?xml version="1.0" encoding="UTF-8"?>
<cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/schema/mrvSchema_14_12_01.xsd" version="ChemAxon file format v14.12.01, generated by v15.11.23.0">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28" elementType="C C C C C C C C C C C C C C C C C C C C C C C C C C C O" mrvMap="2 2 1 2 0 0 1 1 2 1 2 2 1 0 2 2 0 1 3 2 2 2 0 3 3 3 0 0" lonePair="0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2" x2="-4.427499771118164 -5.761169112166423 -5.761169112166423 -4.427499771118164 -3.0938304300699055 -3.0938304300699055 -1.760161089021647 -1.760161089021647 -0.42649174797338874 -0.42649174797338874 -0.42649174797338874 -1.760161089021647 0.9071775930748696 0.9071775930748696 2.3717158407834664 3.27693703783083 2.371825489897502 2.8477760950171014 1.514096973189066 4.181455216845137 5.515134338673173 6.8488134605012085 8.182492582329244 9.51617170415728 8.182492582329244 0.9071775930748697 -3.0938304300699055 -7.094848233994458" y2="1.5881588799259883 0.8181419393669477 -0.7218919417511335 -1.491908882310174 -0.7218919417511335 0.8181419393669477 1.5881588799259883 -1.491908882310174 -0.7218919417511335 0.8181419393669477 3.89820970160311 3.1281927610440694 1.5881588799259885 3.1281927610440694 1.112268172876402 2.3581408309426073 3.6039808406771088 5.068586938399731 5.8385869383997315 5.838586938399731 5.068586938399731 5.838586938399731 5.068586938399731 5.838586938399731 3.528586938399731 4.66819276104407 2.3581419393669476 -1.491891941751134"/>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="1"/>
<bond id="b2" atomRefs2="a2 a3" order="1"/>
<bond id="b3" atomRefs2="a3 a4" order="1"/>
<bond id="b4" atomRefs2="a4 a5" order="1"/>
<bond id="b5" atomRefs2="a1 a6" order="1"/>
<bond id="b6" atomRefs2="a7 a6" order="1"/>
<bond id="b7" atomRefs2="a6 a5" order="1"/>
<bond id="b8" atomRefs2="a5 a8" order="2"/>
<bond id="b9" atomRefs2="a8 a9" order="1"/>
<bond id="b10" atomRefs2="a9 a10" order="1"/>
<bond id="b11" atomRefs2="a10 a13" order="1"/>
<bond id="b12" atomRefs2="a7 a10" order="1"/>
<bond id="b13" atomRefs2="a12 a7" order="1"/>
<bond id="b14" atomRefs2="a11 a12" order="1"/>
<bond id="b15" atomRefs2="a11 a14" order="1"/>
<bond id="b16" atomRefs2="a13 a15" order="1"/>
<bond id="b17" atomRefs2="a14 a13" order="1"/>
<bond id="b18" atomRefs2="a14 a17" order="1"/>
<bond id="b19" atomRefs2="a15 a16" order="1"/>
<bond id="b20" atomRefs2="a16 a17" order="1"/>
<bond id="b21" atomRefs2="a17 a18" order="1"/>
<bond id="b22" atomRefs2="a18 a19" order="1"/>
<bond id="b23" atomRefs2="a18 a20" order="1"/>
<bond id="b24" atomRefs2="a20 a21" order="1"/>
<bond id="b25" atomRefs2="a21 a22" order="1"/>
<bond id="b26" atomRefs2="a22 a23" order="1"/>
<bond id="b27" atomRefs2="a23 a24" order="1"/>
<bond id="b28" atomRefs2="a23 a25" order="1"/>
<bond id="b29" atomRefs2="a14 a26" order="1"/>
<bond id="b30" atomRefs2="a6 a27" order="1"/>
<bond id="b31" atomRefs2="a3 a28" order="1"/>
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>
authMol has MRV:
<?xml version="1.0" encoding="UTF-8"?>
<cml xmlns="http://www.chemaxon.com" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.chemaxon.com/marvin/schema/mrvSchema_14_12_01.xsd" version="ChemAxon file format v14.12.01, generated by v15.11.23.0">
<MDocument>
<MChemicalStruct>
<molecule molID="m1">
<atomArray atomID="a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14 a15 a16 a17 a18 a19 a20 a21 a22 a23 a24 a25 a26 a27 a28" elementType="C C C C C C C C C C C C C C C C C C C C C C C C C C C O" mrvMap="0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0" x2="-4.427499771118164 -5.761169112166423 -5.761169112166423 -4.427499771118164 -3.0938304300699055 -3.0938304300699055 -1.760161089021647 -1.760161089021647 -0.42649174797338874 -0.42649174797338874 -0.42649174797338874 -1.760161089021647 0.9071775930748696 0.9071775930748696 2.3717158407834664 3.27693703783083 2.371825489897502 2.8477760950171014 1.514096973189066 4.181455216845137 5.515134338673173 6.8488134605012085 8.182492582329244 9.51617170415728 8.182492582329244 0.9071775930748697 -3.0938304300699055 -7.094848233994458" y2="1.5881588799259883 0.8181419393669477 -0.7218919417511335 -1.491908882310174 -0.7218919417511335 0.8181419393669477 1.5881588799259883 -1.491908882310174 -0.7218919417511335 0.8181419393669477 3.89820970160311 3.1281927610440694 1.5881588799259885 3.1281927610440694 1.112268172876402 2.3581408309426073 3.6039808406771088 5.068586938399731 5.8385869383997315 5.838586938399731 5.068586938399731 5.838586938399731 5.068586938399731 5.838586938399731 3.528586938399731 4.66819276104407 2.3581419393669476 -1.491891941751134"/>
<bondArray>
<bond id="b1" atomRefs2="a1 a2" order="1"/>
<bond id="b2" atomRefs2="a2 a3" order="1"/>
<bond id="b3" atomRefs2="a3 a4" order="1"/>
<bond id="b4" atomRefs2="a4 a5" order="1"/>
<bond id="b5" atomRefs2="a1 a6" order="1"/>
<bond id="b6" atomRefs2="a7 a6" order="1"/>
<bond id="b7" atomRefs2="a6 a5" order="1"/>
<bond id="b8" atomRefs2="a5 a8" order="2"/>
<bond id="b9" atomRefs2="a8 a9" order="1"/>
<bond id="b10" atomRefs2="a9 a10" order="1"/>
<bond id="b11" atomRefs2="a10 a13" order="1"/>
<bond id="b12" atomRefs2="a7 a10" order="1"/>
<bond id="b13" atomRefs2="a12 a7" order="1"/>
<bond id="b14" atomRefs2="a11 a12" order="1"/>
<bond id="b15" atomRefs2="a11 a14" order="1"/>
<bond id="b16" atomRefs2="a13 a15" order="1"/>
<bond id="b17" atomRefs2="a14 a13" order="1"/>
<bond id="b18" atomRefs2="a14 a17" order="1"/>
<bond id="b19" atomRefs2="a15 a16" order="1"/>
<bond id="b20" atomRefs2="a16 a17" order="1"/>
<bond id="b21" atomRefs2="a17 a18" order="1"/>
<bond id="b22" atomRefs2="a18 a19" order="1"/>
<bond id="b23" atomRefs2="a18 a20" order="1"/>
<bond id="b24" atomRefs2="a20 a21" order="1"/>
<bond id="b25" atomRefs2="a21 a22" order="1"/>
<bond id="b26" atomRefs2="a22 a23" order="1"/>
<bond id="b27" atomRefs2="a23 a24" order="1"/>
<bond id="b28" atomRefs2="a23 a25" order="1"/>
<bond id="b29" atomRefs2="a14 a26" order="1"/>
<bond id="b30" atomRefs2="a6 a27" order="1"/>
<bond id="b31" atomRefs2="a3 a28" order="1"/>
</bondArray>
</molecule>
</MChemicalStruct>
</MDocument>
</cml>
The program goes into what seems like an infinite loop, eating up 100% of the CPU, and eventually throws this error:
INFO: java.lang.OutOfMemoryError: GC overhead limit exceeded
at chemaxon.common.util.IntVector.<init>(IntVector.java:72)
at chemaxon.common.util.IntVector.<init>(IntVector.java:59)
at chemaxon.sss.search.SearchHitUtils.transformHit(SearchHitUtils.java:147)
at chemaxon.sss.search.BaseMolSearchCore.getTransformedSearchHit(BaseMolSearchCore.java:406)
at chemaxon.sss.search.BaseMolSearchCore.findNextHit(BaseMolSearchCore.java:225)
at chemaxon.sss.search.pipeline.QueryEnumeratorElement.findNextHit(QueryEnumeratorElement.java:79)
at chemaxon.sss.search.pipeline.AbstractDelegatorSearchElement.findNextHit(AbstractDelegatorSearchElement.java:56)
at chemaxon.sss.search.pipeline.AbstractDelegatorSearchElement.findNextHit(AbstractDelegatorSearchElement.java:56)
at chemaxon.sss.search.pipeline.HitFilterElement.findNextHit(HitFilterElement.java:44)
at chemaxon.sss.search.pipeline.AbstractDelegatorSearchElement.findNextHit(AbstractDelegatorSearchElement.java:56)
at chemaxon.sss.search.pipeline.TrivialSearchCaseFilter.findNextHit(TrivialSearchCaseFilter.java:77)
at chemaxon.sss.search.pipeline.TimeoutHandler.findNextHit(TimeoutHandler.java:34)
at chemaxon.sss.search.BaseMolSearch$1.call(BaseMolSearch.java:176)
at chemaxon.sss.search.BaseMolSearch$1.call(BaseMolSearch.java:172)
at chemaxon.sss.search.SearchUtil.invokeSearchWithExceptionWrapping(SearchUtil.java:528)
at chemaxon.sss.search.SearchUtil.invokeSearchWithExceptionWrapping(SearchUtil.java:522)
at chemaxon.sss.search.BaseMolSearch.findNextCoreHit(BaseMolSearch.java:179)
at chemaxon.sss.search.BaseMolSearch.findNextHit(BaseMolSearch.java:168)
at chemaxon.sss.search.MolSearch$2.call(MolSearch.java:399)
at chemaxon.sss.search.MolSearch$2.call(MolSearch.java:394)
at chemaxon.sss.search.SearchUtil.invokeSearchWithExceptionWrapping(SearchUtil.java:528)
at chemaxon.sss.search.MolSearch.findNextHit(MolSearch.java:404)
at chemaxon.sss.search.Search.findNext(Search.java:168)
at com.epoch.evals.impl.chemEvals.MapProperty.matchMapPattern(MapProperty.java:258)
at com.epoch.evals.impl.chemEvals.MapProperty.isResponseMatching(MapProperty.java:162)
at com.epoch.evals.Subevaluator.isResponseMatching(Subevaluator.java:120)
at com.epoch.evals.Evaluator.matchResponse(Evaluator.java:249)
at com.epoch.qBank.Question.evaluateResponse(Question.java:1195)
at com.epoch.session.HWSession.submitResponse(HWSession.java:1124)
at org.apache.jsp.homework.answerPreview_jsp._jspService(answerPreview_jsp.java:600)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
It seems to me that just one isomorphism should be found, so I don't understand why it's going into an infinite loop. Can you help? The only difference between the two molecules is that one of them has many mapping numbers, and the other has only one (on a different C). My understanding was that map numbers were ignored by MolSearch; has this changed? (When we want to compare exact map numbers, we add a MolComparator, and it is not throwing exceptions.)