exportStructure(String format, JavaScriptObject options)

User 870ab5b546

23-10-2014 17:20:53

In the Marvin4JS API, you say that the exportAsMrv() method is deprecated in favor of the exportStructure() method. You also say that the exportAsMrv() method returns a String, whereas the exportStructure() method returns a JavaScriptObject. How do I extract the MRV string from the JavaScriptObject that is returned by exportStructure()?

ChemAxon 996dedebe0

24-10-2014 08:04:21

Dear Bob,


in this example please find: 


function initControl () {

// get mol button
$("#btn-getmol").on("click", function (e) {
marvinSketcherInstance.exportStructure("mrv").then(function(source) {
$("#molsource").text(source);
}, function(error) {
alert("Molecule export failed:"+error);
});
});
}

The short answer is that in this example the source object is what you need,



Let's see what it does line by line:


1: The initControl function will...


2: Add a  click handler to the button with "btn-getmol" id.which will


3: TRY to EXPORT the current structure in "mrv", AND IF the export is SUCCESSFUL, there will be a function with the source parameter...


4: ...and we pass this source text to a textarea witth "molsource" id..


5: BUT IF the EXPORT FAILS, there will be another function with error parameter


6: And the user will be notified through an alert popup cintaining the error message.

___________________________________________________________________________________________


This example might seem to be a little difficult, but it is based on the concept of the promise, which is a widely accepted technology in "js world". And since export happens in the server side, (eg: export in smiles, export a reaction in mrv, rgfile export etc.) the asynchronous process may fail because of different reasons. So there is a way to handle the successfull export as well as the failing one. 


In Marvin JS examples jquery is used, so some of those expressions are not available in pure javascript. Certainly there is a way to do the same in pure javascript.


I encourage you to look up our examples, because they are updated release by release, and there is at least one usecase for all our methods in the API.

User 870ab5b546

24-10-2014 13:44:14

Ack. OK, another question. In your example for importStructure(), you already know the format of the structure (MOL in your example). What if you don't know the format of the structure, and it could be MOL, or MRV, or CXSMILES, or CXSMARTS?

User 870ab5b546

24-10-2014 19:06:13

OK, I'm trying to follow your example. I am getting the following Javascript error in the console when I load the page:


Failed to load resource: the server responded with a status of 404 (Not Found) http://epoch.uky.edu:9138/ace/nosession/marvin4JS/js/lib/jquery.min.map

I did a search in the marvin4JS directory, and the file js/lib/jquery-1.9.1.min.js references jquery.min.map, but I can't find jquery.min.map anywhere in the directory. ???

ChemAxon 996dedebe0

24-10-2014 22:26:26

Dear Bob,


jquery is a third party library available at http://jquery.com/ . I recommend you to use the minified versions *.min.js in your final code. You can find their own examples and API on that site.

ChemAxon 996dedebe0

24-10-2014 22:32:25

You can use null instead of a format parameter to try to recognize it automatically (not as accurate in some cases eg: when the file is a MOL file containing a SMILES in the first few rows). 



Please open a new topic, if you have other questions next time (not connected to the original question), so others can find it by topic title.