ChemWriter

ChemWriter 2

API

Editor Functions

chemwriter.loadEditor

Creates an editor instance within the DOM element identified by a DOM id and parameters object, which supports the following properties:

var editor = chemwriter.loadEditor('dom-id', {
  licensePath: '/path/to/licenseFile',
  molfile: 'molfile\ngoes\nhere', // returns must be escaped
  appletPath: '/path/to/chemwriter-util.jar',
  enableClipboard: true,
  enableTools: ['wildcard-atom-bond']
});
 
Editor#getMolfiles

Returns a representation of the Editor's document in MDL molfile format.

// var editor = ...

console.log(editor.getMolfile());
 

Editor#setMolfile

Clears the editor, loads molfile, and centers the resulting document in the Canvas area.

var molfile = '[NO NAME]\n  CHEMW2  0518110854232D                              \nCreated with ChemWriter - http://chemwriter.com\n  6  6  0  0  0  0            999 V2000\n   -5.8703   -1.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.0043   -2.2528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.1383   -1.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.1383   -0.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.0043   -0.2528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.8703   -0.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n  1  2  2  0  0  0  0\n  2  3  1  0  0  0  0\n  3  4  2  0  0  0  0\n  4  5  1  0  0  0  0\n  5  6  2  0  0  0  0\n  6  1  1  0  0  0  0\nM  END\n';

editor.setMolfile(molfile);
 
Editor#autocenter

Centers the document within the Editor's Canvas area.

// var editor = ...

editor.autocenter();
 
Editor#autoscale

Scales the document to fit the bounds of the editor and centers the resulting view.

// var editor = ...

editor.autoscale();
 
Editor#clear

Removes the contents of the Editor's document. This operation is not undoable.

// var editor = ...

editor.clear();
 
Editor#isBlank

Returns true if the Editor's document contains any elements, or false otherwise.

// var editor = ...

editor.setFile('[NO NAME]\n  CHEMW2  0518110854232D                              \nCreated with ChemWriter - http://chemwriter.com\n  6  6  0  0  0  0            999 V2000\n   -5.8703   -1.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.0043   -2.2528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.1383   -1.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.1383   -0.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.0043   -0.2528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.8703   -0.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n  1  2  2  0  0  0  0\n  2  3  1  0  0  0  0\n  3  4  2  0  0  0  0\n  4  5  1  0  0  0  0\n  5  6  2  0  0  0  0\n  6  1  1  0  0  0  0\nM  END\n');
editor.isBlank(); // returns false
 
Editor#getLineWidth

Returns the width of bond lines.

// var editor = ...

console.log(editor.getLineWidth());
 
Editor#setsLineWidth

Sets the width of bond lines.

// var editor = ...

// set line width thinner than default
editor.setLineWidth(0.05);
 
Editor#getLineOffset

Returns the distance between multiple bond parallel lines.

// var editor = ...

console.log(editor.getLineOffset());
 
Editor#setLineOffset

Sets the distance between multiple bond parallel lines.

// var editor = ...

// set line offset than default
editor.setLineOffset(0.05);
 
Editor#getHoverRadius

Returns the radius around which atoms and bond midpoints will be detected as hovered.

// var editor = ...

console.log(editor.getHoverRadius());
 
Editor#setHoverRadius

Sets the radius around which atoms and bond midpoints will be detected as hovered.

// var editor = ...

 // set hover radius wider than default
editor.setHoverRadius(0.7);
 
Editor#getAtomLabelHeight

Returns the relative height of atom labels.

// var editor = ...

console.log(editor.getAtomLabelHeight());
 
Editor#setAtomLabelHeight

Sets the relative hight of atom labels.

// var editor = ...

// use smaller atom labels than default
editor.setAtomLabelHeight(0.3);
 

Editor#getDeviceBondLength

Returns the bond length in device units.

// var editor = ...

console.log(editor.getDeviceBondLength());
 
Editor#setDeviceBondLength

Sets the bond length in device units.

// var editor = ...

// use shorter than default device bond length
editor.setDeviceBondLength(20);
 

Painter Functions

chemwriter.loadPainter

Creates a painter instance using a string DOM id and a parameters object, which supports the following properties:

var painter = chemwriter.loadEditor('dom-id', {
  licensePath: '/path/to/licenseFile',
  molfile: 'molfile\ngoes\nhere' // returns must be escaped
});
 
Painter#getFile

Returns a representation of the current document encoded according the specified mimeType parameter. The only MIME type supported at this time is chemwriter.app.MIMEType.MOLFILE.

// var painter = ...

console.log(painter.getFile(chemwriter.app.MIMEType.MOLFILE));
 
Painter#setFile

Clears the painter, loads the string parameter, then scales and centers the resulting document. The only currently supported format at this time is chemwriter.app.MIMEType.MOLFILE.

// var painter = ...;
var file = '[NO NAME]\n  CHEMW2  0518110854232D                              \nCreated with ChemWriter - http://chemwriter.com\n  6  6  0  0  0  0            999 V2000\n   -5.8703   -1.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.0043   -2.2528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.1383   -1.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -4.1383   -0.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.0043   -0.2528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n   -5.8703   -0.7528    0.0000 C   0  0  0  0  0  0  0  0  0  0  0  0\n  1  2  2  0  0  0  0\n  2  3  1  0  0  0  0\n  3  4  2  0  0  0  0\n  4  5  1  0  0  0  0\n  5  6  2  0  0  0  0\n  6  1  1  0  0  0  0\nM  END\n';

painter.setFile(molfile);
 

System Functions

chemwriter.system.Clipboard.getInstance()

Returns a clipboard to be used together with an optional applet for pasting structure into the ChemWriter editor from Windows desktop applications.

chemwriter.app.MIMEType.MOLFILE

Identifier for Molfile MIME type, chemical/x-mdl-molfile.