This example demonstrates how to retrieve a structure from Marvin JS editor, using extra export options.
JChem Webservices (the web service implementation provided by Chemaxon) can accept special export options . The exportStructure() API function of Marvin JS gives the chance to specify export parameters for the molExport service.
In this example, +H export option (adding explicit Hydrogens to the structure) is passed to the molExport service. If the extra option has been specified, the exportStructure passes the request directly to the remote service instead of evaluating it on client side. If the location of the service has not been specified, an error message is thrown.
Please, take care that Marvin JS does not check whether the extra export options passed to WS are valid or not.
When the Get mol button is pressed, the current molecule is retrieved from the editor in mol format and the result is displayed in the textbox.
By unchecking the webservice checkbox, you can switch off the molExport web service. After this, pressing the Get mol button results in an error message, saying: "Unsupported format mol:+H".
var marvinSketcherInstance;
$(document).ready(function handleDocumentReady (e) {
var p = MarvinJSUtil.getEditor("#sketch");
p.then(function (sketcherInstance) {
marvinSketcherInstance = sketcherInstance;
initControl();
}, function (error) {
alert("Cannot retrieve sketcher instance from iframe:"+error);
});
});
function initControl () {
// get mol button
$("#btn-getmol").on("click", function (e) {
marvinSketcherInstance.exportStructure("mol", {"extra": "+H"}).then(function(source) {
$("#molsource").text(source);
}, function(error) {
alert("Molecule export failed:"+error);
});
});
var molconvertws_value = getDefaultServices()["molconvertws"]
$("#btn-service").change(function(e) {
var services = {
"molconvertws" : (e.target['checked']) ? molconvertws_value : null
};
marvinSketcherInstance.setServices(services);
});
}