partridgejiang / Kekule.js

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

Question - Forcing Explicit Atom Drawing and Smiles #219

Open cleblond opened 3 years ago

cleblond commented 3 years ago

Hi @partridgejiang,

For educational purposes, I'd like to have my students draw structures in composer, but explicitly draw every atom. In composer I can display atom labels (default atom display mode = SHOWN), and not show the hydrogens (Default hydrogen display level = EXPLICIT). That works as I expect and as I want. However, If I draw a lone C atom, and export it to smiles the smiles string is C, which is methane. How can I get the smiles to show [C] indicating its a C atom, and not methane.

Likewise if I draw C-H, the smiles should be [CH], however, the smiles is again exported as C, which is methane.

Is there anyway I can achieve this? Maybe turn off the valence check or something?

Thanks

Carl

partridgejiang commented 3 years ago

Hi @cleblond, it seems that the need is to output SMILES by only the explicit bond and hydrogens? C: [C] C-H: [CH] CH4: C The valence check is still essential here (e.g., in the CH4 sample above). To achieve these, the code of SMILES generation need to be modified a little. Please wait for a few days.

cleblond commented 3 years ago

Yes that would be awesome. If the exported molfiles would also reflect the correct explicit structure that would be great too. Carl

partridgejiang commented 3 years ago

Hi @cleblond, an extra option field has been introduced in outputting SMILES:

Kekule.IO.saveFormatData(mol, Kekule.IO.DataFormat.SMILES, {ignoreImplicitHydrogens: true});

With such a option, only the atoms connected with explicit bonds are output to SMILES string. Please check the latest dist files.

cleblond commented 3 years ago

Awesome! Thanks much! Looking forward to testing.