Marvin JS API Reference

Table of Contents

Static functions

marvin.Sketch.isSupported()boolean
Returns true if HTML5 canvas is supported, false otherwise.

Returns: true if HTML5 canvas is supported, false otherwise.

marvin.Sketch.license(String licenseURL)
Applies a license for the sketcher.

Parameters:

marvin.ImageExporter.molToDataUrl(String source, String imageType, JavaScriptObject optionalSettings)String
Creates image data stream from the given molecule source.

Parameters:

Returns: image stream encoded as an image data URL if image width/height is greater than zero

marvin.ImageExporter.mrvToDataUrl(String source, String imageType, JavaScriptObject optionalSettings)String
Creates image data stream from the given molecule source.

Parameters:

Returns: image stream encoded as an image data URL if image width/height is greater than zero

Classes

marvin.ImageExporter

marvin.ImageExporter(JavaScriptObject params)

Constructor with predefine parameters for the rendering.

Parameters:

marvin.ImageExporter()

Constructor with default parameters.

render(String source)JavaScriptObject
Generate image from the given molecule source. Returns a Promise object to get a notification when image conversion is ready.

Parameters:

Returns: a Promise object

marvin.Sketch

marvin.Sketch()

Creates a new editor widget and inserts it into the body of the current page.

marvin.Sketch(String id)

Creates a new editor widget and inserts it into the specified DOM element.

Parameters:

getDisplaySettings()JavaScriptObject
Retrieves the current display settings of the editor wrapped into a JavaScript object.

Returns: map of display setting is wrapped into a JavaScript object.

KeyTypeValuesDefault valueNotes
"carbonLabelVisible"Boolean{true, false}falsedoes not apply in "BALLSTICK" displaymode
"chiralFlagVisible"Boolean{true, false}true-
"atomIndicesVisible"Boolean{true, false}false-
"atomMapsVisible"Boolean{true, false}true-
"cpkColoring"Boolean{true, false}true-
"valenceErrorVisible"Boolean{true, false}true-
"lonePairsVisible"Boolean{true, false}false-
"displayMode"String{"WIREFRAME", "BALLSTICK", "STICK", "SPACEFILL"}"WIREFRAME"-
"implicitHydrogen"String{"ALL", "OFF", "HETERO", "TERMINAL_AND_HETERO"}"TERMINAL_AND_HETERO"If "carbonLabelVisible" value is true, "HETERO" and "TERMINAL_AND_HETERO" values will be considered as "ALL".
"backgroundColor"Stringcss color-custom non-transparent color
"circledsign"Boolean{true, false}falseDraw circle around positive and negative sign at charge or not.

E.g.:

 {
  "carbonLabelVisible" : false,
  "atomIndicesVisible" : false,
  "atomMapsVisible" : true,
  "chiralFlagVisible"  : true,
  "valenceErrorVisible"  : true,
  "lonePairsVisible" : false,
  "cpkColoring" : true,
  "implicitHydrogen" : "TERMINAL_AND_HETERO",
  "displayMode" : "WIREFRAME",
  "backgroundColor" : "#ffffff"
 }
 

setDisplaySettings(JavaScriptObject jso)
Applies a map of settings for the editor. Check the return value of the getDisplaySettings() function to look up the full display settings map.

Parameters:

clear()
Remove the canvas content.
isEmpty()boolean
Determines whether the canvas is empty or not.

Returns: True if nothing on the canvas, else false.

pasteStructure(String format, String source)JavaScriptObject
Returns a Promise object to paste a molecule source. If the paste operation is successful, the new structure will be added to the old one at the center of the current viewport. See also: importStructure(String,String).

Parameters:

Returns: the Promise object

getSupportedFormats()JavaScriptObject
Returns an object which describes the available import and export formats with the following properties: "importFormats", "exportFormats". The number of the available formats depend on whether the default webservices are set or not.

Returns: the JavaScript object.

setServices(JavaScriptObject jso)
Sets up services for the editor. See the webservices.js for the list of supported services.

Parameters:

addButton(JavaScriptObject jso, function() )
Appends a new button to the specified toolbar and binds its onClick event with the given function.

Parameters:

addTemplate(JavaScriptObject jso)
Append a new button to the template toolbar with the specified template structure.

Parameters:

getSelection()JavaScriptObject
Returns the indexes of the selected atoms and bonds. Atoms are indexed from 1.

Returns: JavaScript object with indices of selected atoms and bonds. E.g.:

 {
   "atoms" : "1,2,3",
   "bonds" : "1-2,2-3"
 }
 

setSelection(JavaScriptObject jso)
Selects bonds and atoms of the specified indices (assuming the indices start from 1). Bonds are identified by their atoms' indices (separate indices with '-').

Parameters:

setHighlight(JavaScriptObject[] jsoArray)
Overwrites the highlight definitions in the editor. You can specify multiple definitions if you would like to use various highlight style in the same time. The definition should contains information about the style (color, opacity, size) and the scope (which atoms/bonds should be painted with this style). You can specify atoms and bonds to highlight by unique ID (UID) or by atom indeces. If an atom or bond is given in several definitions, each patch is applied for the desired atom/bond. So the patch may overlap each other.

Parameters:

on(String eventType, function() )
Attaches an event handler function for the specified event to the editor. Supported events:

Parameters:

off(String eventType, function() )
Removes one or more event handlers for the specified event to the editor.

Parameters:

exportStructure(String format, JavaScriptObject options)JavaScriptObject
Returns a Promise object to access the molecule source.

Parameters:

Returns: the Promise object

importStructure(String format, String source)JavaScriptObject
Returns a Promise object to import a molecule source. If the import operation is successful, the old structure will be replaced by the new one. See also: pasteStructure(String,String).

Parameters:

Returns: the Promise object

setAutoChirality(boolean enable)
Setup auto chirality mode. When you activate it, setup chiral flag on current structure and force it on every imported structure later.

Parameters: