What Is Ketcher JavaScript API

Q

What is Ketcher JavaScript API?

✍: FYIcenter.com

A

Ketcher JavaScript API is programming interface provided by Ketcher for your JavaScript code to interact with the Ketcher editor.

To access Ketcher JavaScript API, you need to access the "ketcher" object as a property of the content "window" object of the "iframe" where the Ketcher is loaded:

lst = document.getElementsByTagName("iframe");
frm = lst[0];
win = frm.contentWindow;
ketcher = win.ketcher;

With the "ketcher" object, you can then access the following main properties and methods provided by the Ketcher JavaScript API:

  • ketcher.addFragment(str) - AddS a structure fragment specified in SMILES, Molfile or RXN format to the editor. It returns a Promise object to perform the task asynchronously.
  • ketcher.containsReaction() - Returns true, if the structure in the editor represents a chemical reaction.
  • ketcher.generateImage(str, opts) - Generates an image with a given structure and options. It returns a Promise object to deliver the result asynchronously.
  • ketcher.generateInchIKey() - Generates the InChIKey of the structure in the editor. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getCDX() - Exports the structure in the editor as a CDX (ChemDraw) file. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getCDXml() - Exports the structure in the editor as a CDX (ChemDraw XML) file. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getCml() - Exports the structure in the editor as a CML (Chemical Markup Language) file. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getInchi() - Exports the structure in the editor as a InChI string. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getKet() - Exports the structure in the editor as a Ketcher file. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getMolfile() - Exports the structure in the editor as a Molfile file. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getRxn() - Exports the reaction structure in the editor as a RXN file. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getSmarts() - Exports the structure in the editor as a SMARTS string. It returns a Promise object to deliver the result asynchronously.
  • ketcher.getSmiles() - Exports the structure in the editor as a SMILES string. It returns a Promise object to deliver the result asynchronously.
  • ketcher.layout() - Updates the layout of the structure in the editor. It returns a Promise object to perform the task asynchronously.
  • ketcher.setMolecule(str) - Imports a structure specified in SMILES, SMARTS, Molfile, RXN, CDX, or Ketcher format to the editor. It returns a Promise object to perform the task asynchronously.
  • ketcher.setSettings(opts) - Sets editor settings.
  • ketcher.editor - Property to access the Editor interface.
  • ketcher.indigo - Property to access the Indigo interface.

See next tutorials for examples on how to use these properties and methods.

 

contentWindow.ketcher - Access "ketcher" Object

Ketcher JavaScript API

Ketcher JavaScript API

⇑⇑ Ketcher - Chemical Structure Editor

2023-10-05, 575🔥, 0💬