partridgejiang / Kekule.js

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

Is it possible to choose the starting atom when converting to smiles #279

Closed agrodet closed 2 years ago

agrodet commented 2 years ago

Maybe it is not a question directly related to Kekule, but I was wondering if there was a way to choose an atom to be the first of the SMILES string when using saveFormatData() (or any other way, if there is).

partridgejiang commented 2 years ago

Unfortunately such a task is not available when saving SMILES currently. A molecule canonicalization will always be processed before outputting SMILES in Kekule.js. However, when saving to MOL or JSON format data, such a canonicalization can be bypassed and the atom sequence may be customized, e.g.:

let atoms = molecule.getNodes();
// change atom orders here, atoms is a simple array and can be sorted
atoms.sort(myCustomSortMethod);
// and then output directly
let molData = Kekule.IO.saveFormatData(molecule, Kekule.IO.DataFormat.MOL);
agrodet commented 2 years ago

Thank you for your explanation.