Marvin JS Example - Calculate physical-chemical properties of structures

Back to index

This example demonstrates how to calculate dynamically some physical-chemical properties, like mass and formula, of a chemical structure. When the content of the Marvin JS sketcher is modified, the calculated properties are automatically updated in the textbox.

When the structure is edited in the sketcher, the source of the molecule is exported in MRV format and sent to Marvin JS web services via an $.ajax() call for calculation. If the calculation was successful, the returned result object is accessed and the calculated mass and formula are displayed in the textbox. In case of an unsuccessful event, "ERROR" shows up in the textbox along with a response message from Marvin JS web services.

function calc() {
	marvinSketcherInstance.exportStructure("mrv").then(function(source) {
		$.ajax({
			type: "POST",
			url: SERVICE_URL,
			contentType:"application/json; charset=utf-8",
			dataType:"json",
			data: JSON.stringify({
				"inputFormat": "mrv",
				"mass": true,
				"formula": true,
				"structure": source
			}),
			success: function(result) {
				$("#results").text(createResult(result[0].mass, result[0].formula));
			},
			error: function(result) {
				$("#results").text('ERROR \nStatus code: ' + result.status + '\nResponse: ' + result.responseText);
			}
		});
	});
}
	
Back to index