reymond-group / smilesDrawer

A small, highly performant JavaScript component for parsing and drawing SMILES strings. Released under the MIT license.
https://smilesdrawer.rocks
MIT License
416 stars 66 forks source link

Highlighting Atoms #145

Closed davidzqhuang closed 2 years ago

davidzqhuang commented 2 years ago

Many packages allow the render of structures with certain atoms highlighted which is useful for visualization purposes. This can be naturally integrated into smilesDrawer.

Atoms can be highlighted by assigning atoms to be highlighted an atom map number (i.e. class). highlight_atoms is now a parameter in the Drawers which allows the assignment of an atom map number to a color which is used to highlight the atom.

An example is [CH2:10]1CCCCC1

Changes required were to save the "class" attribute for each atom which wasn't previously logged, to introduce another graphics object on the svg ("highlights") which exists beneath the path and vertices graphics objects, and a highlight_atoms parameter to specify the atom class to highlight color mapping.

The highlight_atoms parameter, however, may be argued to be better served to live within a Theme. However ,on occasion it may be useful to have a spectrum of colors to highlight with (e.g. a colorscale) or have a discrete range of colors for discrete atom properties, thus making more sense as an inputted property.

@daenuprobst

daenuprobst commented 2 years ago

Hey David, thanks a lot. I'll review the code and merge ASAP (I hope later today or tomorrow). Really great feature!