How to sketch chemical reactions with MarvinJS?

Hello,

I have a question about how to get the MarvinJS sketcher on the webportal to generate a reaction object in the RXN format for my workflow. I have followed the Knime webportal admin guide to set up MarvinJS as the chemical sketcher. I have no problem pasting a reaction object into MarvinJS, but upon leaving the page it always exports the reaction as a Mol file with disconnected fragments.

I have tried running the same workflow on my AP client, and the GGA Ketcher processes the input correctly and generates an RXN object.

Upon examining your sketcher.html file used to integrate MarvinJS, it occurred to me the following code always exports the sketch as a Mol file regardless of the format parameter. Is it possible to change this code to account for the different chemical formats supported by MarvinJS?

                    getData: function(format) {
                    /* Optionally: adapt the body of this method to retrieve 
                    the sketch data and return it to the KNIME WebPortal. */
                    if (format == null) {
                        format = "MDL";
                    }
                    var sketcherFrame = document.getElementById('sketcherFrame').contentWindow; 
                    if (typeof sketcherFrame != 'undefined' && typeof sketcherFrame.marvin.sketcherInstance != 'undefined') {
                        return sketcherFrame.marvin.sketcherInstance.exportAsMol();
                    }
                    else {
                        return null;
                    }
                },

Thanks,
Ning

Hi Ning,

We recommend using the exportStructure() method instead of the deprecated exportAsMol() method.
Specifically, we recommend that you replace

return sketcherFrame.marvin.sketcherInstance.exportAsMol();

with

return sketcherFrame.marvin.sketcherInstance.exportStructure(“mrv”);

You may also find the documentation at https://marvinjs-demo.chemaxon.com/latest/jsdoc.html and https://marvinjs-demo.chemaxon.com/latest/docs/index.html helpful.

Best,

Tim

Hi Tim,

Unfortunately, the proposed change does not resolve the issue. According to the MarvinJS documentation at https://marvinjs-demo.chemaxon.com/latest/jsdoc.html,

exportStructure(String format, JavaScriptObject optionsJso)

Returns a Promise object to access the molecule source.

Unlike exportAsMol(), the exportStructure function works asynchronously because it relies on the JChem Web Services to render the output. In the context of the Knime wrapper, the getData function cannot directly use exportStructure in the asynchronous fashion. Indeed, the /sketcher.marvinJS/sketcher.html file which integrates MarvinJS into Knime clearly states the following at the top:

 The SketchTranslator is called by the KNIME webportal framework to initialize the
 sketcher and retrieve its data after sketching.

 Please not that the Marvin for Javascript sketcher only supports MDL files. If you wish to use
 other formats you have to adapt the setData and getData functions to utilize the Marvin webservices.

 You can modify this html page for your preferred sketcher by adapting
 - the sketcherFrame source
 - the setData(data) method
 - the getData() method
 to allow a communication between the sketcher and the webportal.
 Important: Do NOT change the name of the SketchTranslator or the method signatures!

Thus, I am guessing the easiest way to work around this is to make the getData() method wait for the asynchronous call to return and pass the response to its caller.

Our current workaround is to require the user to upload an RXN file, so there is no urgency to resolve this issue. But I think in the long run it might be worth enabling the asynchronous mechanism to allow JChem Web Services to translating between different structure formats, because without that the standalone MarvinJS only supports MRV and V2000 MOL formats and that is very limited.

Thanks,
Ning