How to Load CML file in Marvin

User 21178756d4

03-11-2011 07:17:24

Hi All,


 


 I facing a problem regarding CML file format. I have to display CML Code in Marvin Applet using javascript, i have the cml file code and not able to load this in marvin applet.


 


I am using this javascript method


document.MSketch.setMol(value,'cml');

ChemAxon 7c2d26e5cf

04-11-2011 09:02:25

Have you tried to copy the CML into the running MarvinSketch applet via the clipboard?


If it is unsuccessful, the CML may be invalid.


If it works via the clipboard but it fails via document.MSketch.setMol(...), it means that the CML string is not properly encoded for the JavaScript.


If the cml content is directly inserted into the javascript code, it has to be encoded like this (escape line breaks and quotation characters):


 


var value = "<?xml version=\"1.0\" ?>\n<cml>\n<MDocument>\n  <MChemicalStruct>\n    <molecule title=\"3,7-Dihydro-1,3,7-trimethyl-1H-purine-2,6-dione\" molID=\"m1\">\n      <atomArray\n          atomID=\"a1 a2 a3 a4 a5 a6 a7 a8 a9 a10 a11 a12 a13 a14\"\n          elementType=\"N N C C C C C C C C O O N N\"\n          x2=\"-3.117706666666667 -3.117706666666667 -2.6420800000000004 -2.2125600000000003 -5.916026666666667 -8.583306666666669 -7.249760000000001 -5.916026666666667 -4.582293333333334 -4.582293333333334 -5.916026666666667 -8.583306666666669 -7.249760000000001 -5.916026666666667\"\n          y2=\"-4.04824 -1.5564266666666668 -0.09184000000000002 -2.8024266666666673 -1.2624266666666668 -1.2624266666666668 -3.5722400000000003 -5.882426666666667 -3.5722400000000003 -2.032426666666667 0.27776 -4.342426666666667 -2.032426666666667 -4.342426666666667\"\n          />\n      <bondArray>\n        <bond atomRefs2=\"a5 a13\" order=\"1\" />\n        <bond atomRefs2=\"a13 a7\" order=\"1\" />\n        <bond atomRefs2=\"a7 a14\" order=\"1\" />\n        <bond atomRefs2=\"a14 a9\" order=\"1\" />\n        <bond atomRefs2=\"a9 a10\" order=\"2\" />\n        <bond atomRefs2=\"a5 a10\" order=\"1\" />\n        <bond atomRefs2=\"a4 a2\" order=\"1\" />\n        <bond atomRefs2=\"a2 a10\" order=\"1\" />\n        <bond atomRefs2=\"a9 a1\" order=\"1\" />\n        <bond atomRefs2=\"a4 a1\" order=\"2\" />\n        <bond atomRefs2=\"a2 a3\" order=\"1\" />\n        <bond atomRefs2=\"a5 a11\" order=\"2\" />\n        <bond atomRefs2=\"a13 a6\" order=\"1\" />\n        <bond atomRefs2=\"a7 a12\" order=\"2\" />\n        <bond atomRefs2=\"a14 a8\" order=\"1\" />\n      </bondArray>\n    </molecule>\n  </MChemicalStruct>\n</MDocument>\n</cml>\n";

If it is retrieved from a form field, escaping of special characters is unecessary:




var s = document.MolForm.MolTxt.value;
document.MSketch.setMol(s, opts);