Marvin JS Example - Get The Molecule

Back to index

This example demonstrates how to retrieve the molecule from the sketcher. When you push the Get mol button, the current molecule is retrieved from the editor in MRV format and the result is displayed in the textbox.

First of all, you need a reference for the editor. MarvinJSUtil.getEditor(String) provides a Promise object for you to get it when the editor is ready.

After the editor is loaded, run the initcontrol() function to bind action the the Get mol button.

When the button is clicked, the exportStructure(String) function of the editor is called. Its provides a Promise object to access the result of the export process. Call its then(...) function with the callback function that describes what you would like to do with the export result. In this case, it is displayed in the molsource textbox.

var marvinSketcherInstance;

$(document).ready(function handleDocumentReady (e) {
	var p = MarvinJSUtil.getEditor("#sketch");
	p.then(function (sketcherInstance) {
		marvinSketcherInstance = sketcherInstance;
	}, function (error) {
		alert("Cannot retrieve sketcher instance from iframe:"+error);

function initControl () {

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

Back to index