Marvin JS Example - Get The Molecule with Multiple Sgroups

Back to index
Export as
Editor settings

When you export an sgroup whose connectivity has not specified and its repetition count is a number greater than zero there are two options how to represent it. The multiplesgroup export option help to control it. When its value is true these sgroups appears as contracted multiple sgroups in the generated molecule source. If it is false, these groups are represented as SRU sgroup.

This option is applied by both the exportStructure and the setDisplaySettings methods of the Sketcher API. In first case, it is effect only those exportStructure calling when it is explicitly given. In the second case, it is an editor settings to pass export options for internal export calling (like Export dialog, copy and webservice based commands) thatn you can do by the setDisplaySettings method of the editor

This example demonstrates how to switch on/off this options in various exportStructure callings and also shows how to specify it at at setDisplaySettings calling.

The Submit button trigger exportStructure with the parameters given in the above form. The result of the exportStructure calling has been displayed in the textbox below the button. As you can see the printStructure method has been bind to the onClick event of the button. This method do the export described above. In the event handler there is an getEditor calling that returns with a promise object. When the promise returns with success it call the printStructure called immediately. The getEditor function is responsible to provide the reference to the sketcher object. It is retrieved at each request to avoid reloading issue (if the reference of the editor is cached and you reload the page, the reference can be deprecated).

In the Editor settings form, you can control the given editor options. To apply them, push the Set settings button. In default, the copy command place the structure in MolV2000 format. To see the MRV on the clipboard at CTRL+C, swith on the CopyAsMrvEnabled checkbox.

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

			function initControl () {
				setupForm();
				// get mol button
				$("#exportAs").on("click", function (e) {
					getEditor().then(printStructure, alert);
				});
				$("#setDisplaySettings").on("click", function(e) {
					getEditor().then(updateSettings, alert);
				});
			}

			function printStructure(marvinSketcherInstance) {
				marvinSketcherInstance.exportStructure(getFormat(),getOptions()).then(function(source) {
						$("#molsource").text(source);
					}, function(error) {
						alert("Molecule export failed:"+error);
					});
			}

			function updateSettings(marvinSketcherInstance) {
				marvinSketcherInstance.setDisplaySettings(getDisplaySettings());
			}

			function getEditor() {
				return MarvinJSUtil.getEditor("#sketch");
			}
			function setupForm() {
				$("#format").val("mol")
				$("#multiplesgroup").prop("checked",true)
				$("#editor-multiplesgroup").prop("checked",true)
				$("#editor-copyasmrv").prop("checked", false)
				// setup initial settings
				getEditor().then(updateSettings, console.log);
			}

			function getFormat() {
				return $("#format").val();
			}

			function getOptions() {
				return {
					multiplesgroup: $("#multiplesgroup").prop("checked")
				}
			}

			function getDisplaySettings() {
				return {
					multiplesgroup: $("#editor-multiplesgroup").prop("checked"),
					copyasmrv: $("#editor-copyasmrv").prop("checked")
				}
			}
Back to index