partridgejiang / Kekule.js

A Javascript cheminformatics toolkit.
http://partridgejiang.github.io/Kekule.js
MIT License
250 stars 61 forks source link

Help getting SMILES from Chem Composer #119

Closed akulmehta closed 5 years ago

akulmehta commented 5 years ago

Firstly, thank you for creating this. I have implemented the Kekule Chem Composer to draw the structures. I know the easy way of getting SMILES is to go to the save button and then selecting SMILES output. However, I would like to get the SMILES programmatically, i.e. avoiding the user to need to do this mannually. Is there a function which we can call to get the SMILES for a structure drawn in the editor? The idea is to pass the SMILES to search pubchem api to retrieve information about the structure drawn.

akulmehta commented 5 years ago

Nevermind here is the solution:

  //get the molecule object from the chemComposer widget
  var molecule = chemComposer.getChemObj(); 
  //get the smiles :)
  var smiles = Kekule.IO.saveFormatData(molecule, 'smi')