partridgejiang / Kekule.js

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

Can I check is it contain specific Molecule? #301

Open keeper1030 opened 1 year ago

keeper1030 commented 1 year ago

Can I check is it contain specific Molecule? I'm trying to change color of that specific Molecule in Editor's objects like below picture. FurtherMore, if color changed Molecule's atom or bond are change, it should back to origin color.

example

스크린샷 2023-02-15 오전 10 54 35

specific Molecule

스크린샷 2023-02-15 오전 10 54 59

partridgejiang commented 1 year ago

Hi @keeper1030, you may refer to the ring perception demo (http://partridgejiang.github.io/Kekule.js/demos/items/algorithm/ringSearch.html) and sub structure search demo (http://partridgejiang.github.io/Kekule.js/demos/items/algorithm/structureSearch.html). In those demos, part of atoms/bonds in editor or viewer are highlighited to illustrate a matched sub structure. Actually, you can change the color of any object (atom, bond, molecule, etc.) by changing its renderOptions property, e.g.:

bond.setRenderOption('color', '#00ff00');

Then you may also listener to the userModificationDone event of editor to clear the color of those objects:

editor.on('userModificationDone', evt => {
  bond.setRenderOption('color', null);
});