Auto-cleaning Before mol Export

User 8dec154d98

12-11-2009 03:53:04

Hello all! I'm working on a "MarvinSketch-to-Jmol" converter that allows a user to build a structure in MarvinSketch then view it in Jmol. I'd like MarvinSketch to clean the structures in 3D before sending them to Jmol, but my efforts to achieve this haven't borne fruit (try it out! ).


The first thing I tried was to use the Molecule.clean method, but MSketch.getMol() kept returning an undefined object (even when there was a molecule in the sketcher window).


Then, I tried setting the "importConv" parameter to "c" so that automatic cleaning would take place upon every load (which I assumed meant every time the setMol function is called). This worked in some cases, but broke if the molecule was erased or modified, or if the Undo button was pressed--after these operations, the molecule was not cleaned before getting passed to Jmol.


Any ideas? I feel like automatic cleaning should be easier than I'm making it out to be.

ChemAxon 7c2d26e5cf

12-11-2009 12:57:01

I assume that you do not use the proper class to retrieve the molecule from the sketcher.


Can you copy the a code snipplet where you get the molecule from the sketcher?


MSketch.getMol() function does not exists in the Marvin Beans API.


I guess you use Marvin Beans or JChem API (that also includes Marvin Beans classes) if you deploy a custom application.


In the Marvin Beans API, chemaxon.marvin.beans.MSketchPane represents the MarvinSketch GUI component. You can use its getMol() method to retrieve the drawn structure from the sketcher. It returns with a Molecule object.


http://www.chemaxon.com/marvin/help/developer/beans/api/chemaxon/marvin/beans/MSketchPane.html#getMol()

User 8dec154d98

12-11-2009 16:02:30

I'm pretty sure I'm using the Marvin Beans API, although a few functions within the MSketchPane class have been giving me trouble: getMol() and clearHistory(), for example. The JavaScript function I use to read the contents of the MarvinSketch window is below.



function exportMol(format) {
if(document.MSketch != null) {
var s = document.MSketch.getMol(format+":+H");
s = unix2local(s);
} else {
alert("Cannot import molecule:\n"+
     "no JavaScript to Java communication in your browser.\n");
}
jmolLoadInlineScript(s,"wireframe 20%; spacefill 15%; select all;");
if (document.Form2.axes.checked) {
jmolScript("axes on");
}
}


As you can see, I grab the structure using the getMol(format) function, not getMol(). When I attempted to clean the structure using MSketch.getMol().clean(3,null); just before the definition of the variable s, I get an error (when debugging with Safari) to the effect that MSketch.getMol() is not an object, as if the Molecule class is unrecognized.


As far as included files go, all I do is provide the marvin source directory when I call msketch_begin. Perhaps I need to download and/or include other js files?

ChemAxon 7c2d26e5cf

17-11-2009 13:07:11

Dear Michael,


I'm pretty sure I'm using the Marvin Beans API

I am afraid that you are in error.


As I see, you deploy web page(s) where you embed Marvin applets. To incorporate between applet and other components of the web page, JavaScript functions are used.


Marvin applets are part of the Marvin Applets package. You can access the applet via the Marvin Applets API:


http://www.chemaxon.com/marvin/help/developer/applets/api/


So, in your JavaScript code, you can refer only to the the Marvin Applets API, not Marvin Beans.


The Marvin Beans API is designed to integrate Marvin into desktop applications or use its certain util by server side programming (e.g. converting structures among different formats). Marvin Applets are not part of the Marvin Beans package.


The Molecule class is not part of the Marvin Applets API, that's why you can not find getMol() function in this API. You can retrieve only the molecule source (in mrv, in mol or in several other chemical format): JMSketch.getMol(String) .


Currently, there is no export option for getMol(String) method to clean in 3D on the fly.
I suggest to clean the structure by import and retrieve the cleaned structure from the applet.


If you would like to use Marvin Beans API, I recommend use beans on server side (e.g. in JSP). Send the structure that the user is drawn in the applet and process it there. Finally, send back result if it necessary.