Parameters:
interceptor
- this function is called with the MarvinJS HTTP request header builder before a new request is sent to the webservices.
E.g.: If the communication with the server requires Bearer (token) authentication,
you can add an authorization header with a cryptic string.
marvin.Sketch.addRequestInterceptor( (config) => {
config.setRequestHeader("Authorization", "Bearer <token>");
});
E.g.: Angular applications may require X-XSRF-TOKEN to avoid cross-site request forgery.
Look for a cookie named XSRF-TOKEN and setup the X-XSRF-TOKEN header.
marvin.Sketch.addRequestInterceptor( (config) => {
if (config.method !== "GET") {
var token = getCookie("XSRF-TOKEN"); // please, declare a getCookie function earlier to lookup the desired cookie
if(token) {
config.setRequestHeader("X-XSRF-TOKEN", token );
}
}
});
E.g.: Set the XMLHttpRequest's withCredentials property:
marvin.Sketch.addRequestInterceptor( (config) => {
config.setWithCredentials(true);
});
Parameters:
handler
- the callback function is called when any internal HTTP request return with a response error. The function expects a string parameter.
The the response text (with status code and other properties) are passed to the callback function.marvin.Sketch.addResponseErrorHandler( (message) => {
console.log(message);
});
Parameters:
handler
- the response error handler to remove
Returns: true if HTML5 canvas is supported, false otherwise.
Parameters:
licenseURL
- the URL of the license fileisDynamic
- Optional. Controls whether the license is granted by the license server in runtime. The default value is false.Parameters:
source
- molecule source in MDL molfile or null to apply an empty moleculeimageType
- output image data stream MIME type (default value is "image/png").optionalSettings
- JavaScript object that describes display settings.
The object contains key - value pairs.
Key | Type | Values | Default value | Notes |
---|---|---|---|---|
"carbonLabelVisible" | Boolean | {true, false} | false | does not apply in "BALLSTICK" displaymode |
"chiralFlagVisible" | Boolean | {true, false} | true | - |
"valenceErrorVisible" | Boolean | {true, false} | true | - |
"lonePairsVisible" | Boolean | {true, false} | false | show lone pairs if MRV source contains proper info or auto lone pair calculation is enabled |
"lonepaircalculationenabled" | Boolean | {true, false} | false | Set it to true to calculate lone pair on the current structure. |
"circledsign" | Boolean | {true, false} | false | Draw circle around positive and negative sign at charge or not. |
"atomIndicesVisible" | Boolean | {true, false} | false | - |
"atomMapsVisible" | Boolean | {true, false} | true | - |
"cpkColoring" | Boolean | {true, false} | true | - |
"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" | String | css color | - | do not set this to leave it transparent (png) or white |
"zoomMode" | String | {"fit", "autoshrink"} | "fit" | "fit" will expand every molecule to the given size, "autoshrink" scales down large molecules only. |
"width" | Number | positive integer | 200 | - |
"height" | Number | positive integer | 200 | - |
{ 'carbonLabelVisible' : false, 'atomMapsVisible' : true, 'chiralFlagVisible' : true, 'valenceErrorVisible' : true, 'lonePairsVisible' : false, 'implicitHydrogen' : "TERMINAL_AND_HETERO", 'displayMode' : "WIREFRAME", 'backgroundColor' : "#ff00ff", 'width' : 300, 'height' : 350 }
Returns: image stream encoded as an image data URL if image width/height is greater than zero
Parameters:
source
- molecule source in MRV or null to apply an empty moleculeimagType
- output image data stream MIME type (default value is "image/png").optionalSettings
- JavaScript object that describes display settings.
The object contains key - value pairs.
Key | Type | Values | Default value | Notes |
---|---|---|---|---|
"carbonLabelVisible" | Boolean | {true, false} | false | does not apply in "BALLSTICK" displaymode |
"chiralFlagVisible" | Boolean | {true, false} | true | - |
"valenceErrorVisible" | Boolean | {true, false} | true | - |
"lonePairsVisible" | Boolean | {true, false} | false | show lone pairs if MRV source contains proper info or auto lone pair calculation is enabled |
"lonepaircalculationenabled" | Boolean | {true, false} | false | Set it to true to calculate lone pair on the current structure. |
"circledsign" | Boolean | {true, false} | false | Draw circle around positive and negative sign at charge or not. |
"atomIndicesVisible" | Boolean | {true, false} | false | - |
"atomMapsVisible" | Boolean | {true, false} | true | - |
"cpkColoring" | Boolean | {true, false} | true | - |
"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" | String | css color | - | do not set this to leave it transparent (png) or white |
"zoomMode" | String | {"fit", "autoshrink"} | "fit" | "fit" will expand every molecule to the given size, "autoshrink" scales down large molecules only. |
"width" | Number | positive integer | 200 | - |
"height" | Number | positive integer | 200 | - |
{ "carbonLabelVisible" : false, "atomMapsVisible" : true, "chiralFlagVisible" : true, "valenceErrorVisible" : true, "lonePairsVisible" : false, "implicitHydrogen" : "TERMINAL_AND_HETERO", "displayMode" : "WIREFRAME", "backgroundColor" : "#ff00ff", "zoomMode" : autoshrink, "width" : 300, "height" : 350 }
Returns: image stream encoded as an image data URL if image width/height is greater than zero
Parameters:
interceptor
- the function to remove.Constructor with predefine parameters for the rendering.
Parameters:
params
- parameters enclosed into a JavaScript Objects.
imageType | the format of the generated image (image/png , image/jpeg , image/svg ) | "image/png" |
settings | display settings. Applies the same values than marvin.ImageExporter.mrvToDataUrl(String,String,JavaScriptObject). | { width: 200, height: 200 } |
inputFormat | predefine the format of the molecule source to be converted (or null to auto recognize) (If webservices are not specified, only "mol" and "mrv" are accepted, if it presents any format are accepted that molconverter service supports.) | null |
services | Optinally, you can specify webservice settings to inject molconverter and stereo calculation functionality. See marvin.Sketch.setServices(JavaScriptObject). | null |
Constructor with default parameters.
Parameters:
source
- the source of the molecule to render (the input format is determined by the creation of the ImageExporter instance).Returns: a Promise object
Creates a new editor widget and inserts it into the body of the current page.
Creates a new editor widget and inserts it into the specified DOM element.
Parameters:
id
- the ID of the DOM element whose child will be the editor widget.config
- initial parameters.Returns: map of display setting is wrapped into a JavaScript object.
Key | Type | Values | Default value | Notes |
---|---|---|---|---|
"carbonLabelVisible" | Boolean | {true, false} | false | does not apply in "BALLSTICK" displaymode |
"chiralFlagVisible" | Boolean | String | {true, false, "disabled"} | true | When set to false, the absolute stereo chiral flag is hidden from the canvas. When set to "disabled", the absolute stereo chiral flag is hidden from the canvas and the absolute stereo property cannot be set from the context menu anymore. The visibility of the stereo chiral flag cannot be changed from the View Settings dialog. |
"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" | String | css color | - | custom non-transparent color |
"circledsign" | Boolean | {true, false} | false | Draw circle around positive and negative sign at charge or not. |
"fogEffect3D" | Boolean | {true, false} | true | Fog effect in 3D mode. |
"mdlExportDisabled" | Boolean | {true, false} | false | Removes the V2000 MDL-related formats (Molfile, Rxnfile, RGfile, RDFile, SDFile) from the export dialog. |
{ "carbonLabelVisible" : false, "atomIndicesVisible" : false, "atomMapsVisible" : true, "chiralFlagVisible" : true, "valenceErrorVisible" : true, "lonePairsVisible" : false, "cpkColoring" : true, "implicitHydrogen" : "TERMINAL_AND_HETERO", "displayMode" : "WIREFRAME", "backgroundColor" : "#ffffff", "fogEffect3D" : true, "mdlExportDisabled": false }
Parameters:
jso
- map of display setting is wrapped into a JavaScript object.
Key | Type | Values | Default value | Notes |
---|---|---|---|---|
"carbonLabelVisible" | Boolean | {true, false} | false | does not apply in "BALLSTICK" displaymode |
"chiralFlagVisible" | Boolean | String | {true, false, "disabled"} | true | When set to false, the absolute stereo chiral flag is hidden from the canvas. When set to "disabled", the absolute stereo chiral flag is hidden from the canvas and the absolute stereo property cannot be set from the context menu anymore. The visibility of the stereo chiral flag cannot be changed from the View Settings dialog. |
"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" | String | css color | - | - |
"defaultTool" | String | {"rectangleSelection", "lassoSelection", "rotate3d"} | "rectangleSelection" | set default tool |
"toolbars" | String | {"standard", "education", "reaction", "markush", "search", "basicSearch", "reporting", "view3d", "ws_view3d", "searchWithReaxys"} | "standard" | to render toolbars by the given predefined layout |
"copyasmrv" | Boolean | {true, false} | false | To prefer MRV instead of MDL molfile format at copy |
"lonepaircalculationenabled" | Boolean | {true, false} | true | Enable automatic lone pair calculation |
"circledsign" | Boolean | {true, false} | false | Draw circle around positive and negative sign at charge or not. |
"fogEffect3D" | Boolean | {true, false} | true | Fog effect in 3D mode. |
"disableContextMenu" | Boolean | {true, false} | false | Set true to disable the context menu |
"multiplesgroup" | Boolean | {true, false} | true | The property specifies how the repeating groups with exact repetition numbers are represented in the generated molecule source. If the value is set true, these are represented as multiple groups; if the value is false, these are represented as repeating units. The setting affects the generated molecule source in the Export dialog, and the sources placed on the clipboard in MRV and Mol formats. It may influence the result of a web service call (triggered by web service based actions like Clean 2D). |
"mdlExportDisabled" | Boolean | {true, false} | false | Removes the V2000 MDL-related formats (Molfile, Rxnfile, RGfile, RDFile, SDFile) from the export dialog. |
{ "carbonLabelVisible" : false, "atomIndicesVisible" : false, "atomMapsVisible" : true, "chiralFlagVisible" : true, "valenceErrorVisible" : true, "lonePairsVisible" : false, "cpkColoring" : true, "implicitHydrogen" : "TERMINAL_AND_HETERO", "displayMode" : "WIREFRAME", "backgroundColor" : "#ffffff", "defaultTool" : "lassoSelection", "toolbars" : "standard", "fogEffect3D" : false, "mdlExportDisabled": true }
Returns: True if nothing on the canvas, else false.
Parameters:
format
- the input format getSupportedFormats() or null to recognize the format automatically.source
- the molecule sourceReturns: the Promise object
Returns: the JavaScript object.
webservices.js
for the list of supported services.Parameters:
jso
- map of services wrapped into a JavaScript object.
The property names correspond to the supported web services.
The property values can either be a single string, representing the URL, or an other JavaScript object, containing the URL and the protocol name of the web service.
If the protocol is not specified, its value is set to "default".
{ "clean2dws" : <url of Clean2D webservice> "clean3dws" : <url of Clean3D webservice> "molconvertws" : <url of MolConvert webservice> "stereoinfows" : <url of CIP Stereo Info webservice> "reactionconvertws" : <url of Reaction converter webservice> "hydrogenizews" : <url of hydrogenize webservice> "automapperws" : <url of auto mapper webservice> "aromatizews" : { "url" : <url of aromatize webservice> "protocol" : <protocol of aromatize webservice> } }
Parameters:
jso
- attributes of button is wrapped into a JavaScript object. E.g.:
{ "name": "customButton", // JS String "image-url": "images/custom-button.png" // JS String "toolbar": "W" // JS String: "W" as West, "E" as East, "N" as North, "S" as South toolbar }
Parameters:
jso
- a JavaScript object that describes the template. It has to contains the following properties:
Name | Type | Description |
---|---|---|
structure | String | MRV source of the template structure |
name | String | title of the template button (optional, auto generated) |
icon | String | 24x24 pixel size icon for the button as base64 encoded data image (optional, auto generated) |
{ "structure": "<cml><MDocument><MChemicalStruct><molecule molID=\"m1\"><atomArray><atom id=\"a1\" elementType=\"C\" x2=\"-12.5625\" y2=\"6.539048685882614\"/><atom id=\"a2\" elementType=\"C\" x2=\"-13.808366329017026\" y2=\"5.633832087370612\"/><atom id=\"a3\" elementType=\"C\" x2=\"-13.332503911629807\" y2=\"4.169284647450719\"/><atom id=\"a4\" elementType=\"C\" x2=\"-11.792496088370193\" y2=\"4.169284647450719\"/><atom id=\"a5\" elementType=\"C\" x2=\"-11.316633670982972\" y2=\"5.633832087370612\"/></atomArray><bondArray><bond atomRefs2=\"a1 a2\" order=\"1\"/><bond atomRefs2=\"a1 a5\" order=\"1\"/><bond atomRefs2=\"a2 a3\" order=\"1\"/><bond atomRefs2=\"a3 a4\" order=\"1\"/><bond atomRefs2=\"a4 a5\" order=\"1\"/></bondArray></molecule></MChemicalStruct></MDocument></cml>", "name": "CycloPentane", "icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAABgAAAAYCAYAAADgdz34AAABBElEQVRIie3UK08DQRiF4UdW1q4CfgISW7kSRYIrihBEJQkKi0OiCKJQSVAEtRJD0CgkqYGAIhjEzCYFlr1Mi+ubfMlezpyZPd/ssGTBHOPwP4z7uME9HnCNbFHmG3jCSbzv4TQ+G8xrfoBX5BXvcjziKMV4DQXu4nWT7rZB940tTDFqqe9F7RTbTeJLIdv1tquZYRDHXtSt5B0rCeYlq3iLXpWcYW+OCXajx5/kQtNSKTRs3Z7QrH6CeYZnNfGUTKTF1BhPyaZwLHSlUP1D/iIlpgwfWsRTMsFOhwmGuOqg7xxTIfSgNX28YF/4kp81nKkRPiXsvHOMhZ1RV2M1x8OSRr4A1pQ2FuhcylgAAAAASUVORK5CYII=" }
Returns: JavaScript object with indices of selected atoms and bonds. E.g.:
{ "atoms" : "1,2,3", "bonds" : "1-2,2-3" }
Parameters:
selection
- JavaScript object that describes atoms and bonds to select. E.g.:
{ "atoms" : "1,2,3", "bonds" : "1-2,2-3" }
Parameters:
jsoArray
- array of JavaScriptObject that describes highlight in the following format:
{ // give uids or indexes field (depend on how you would like to specify atoms/bonds to highlight) uids: { // string array with UIDs of atom atoms: [], // string array with UIDs of bond bonds: [] }, indexes: { // string array of indeces of atom atoms: [], // string array of pair of atom indeces to describe bond bonds: [] }, style: { // CSS color (rgb, rgba, hsl, hsla, hexa or web-safe color name) color: <string>, // value between 0.0 and 1.0 (default value is 1.0), if color has alpha value (rgb, rgba) this field is ignored. opacity: <number> // size of the patch that is relative to the selection patch, 1.0 means the same patch than the selection. size: <double> } }In the following example, there are two definitions, at the first one atoms and bonds are specified by UIDs, at the second atom indeces are used. In the first case, color contains alpha value, so the opacity property is needless in this case. At the second case, the pink color is defined and specified the desired opacity explicitly.
sketch.setHighlight( [ { uids: { atoms: ["e2ff0039baee12e2", "be3f1024c1f5e3f1"], bonds: ["3e1a21c74df9ae81"] }, style: { color: "rgba(20,230,50, 0.5)", size: 0.8 } }, { indexes: { atoms: ["1","2","3"], bonds: ["1-2","1-3"] }, style: { color: "pink", opacity: 0.6, size: 0.8 } } ] );
Parameter:
callback
- this function is performed after the event happened. The molecule source is passed to the function as a string parameter.Parameter:
callback
- the reference of a previously attached event handler function to remove. At null value, all event handlers are removed.Parameters:
type
- the event type ("molchange" or "selectionchange")callback
- this function is performed after the specified event is invoked.Parameters:
type
- the event type (accept same types as on(String,function()))callback
- the reference of a previously attached event handler function to remove or null
to remove all event handlers for the specified event.Parameters:
format
- the output molecule format getSupportedFormats().options
- a JavaScript object that describes further options for export (optional).
hasUID
property. If it is true, export atom/bond UIDs as atom/bond properties (_mjs::uid
). Its default value is false.Returns: the Promise object
Parameters:
format
- the input format getSupportedFormats() or null to recognize the format automatically.source
- the molecule sourceReturns: the Promise object