partridgejiang / Kekule.js

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

Can't find the way to set the specified colors for atoms #197

Closed xjjius closed 3 years ago

xjjius commented 3 years ago

I have gone through all the API documents on the demo website. Still can not find a way to set the viewer using specified colors for atoms by code. The only way to do it is click through the setting menu. How can I program it when initiating the viewer component?

partridgejiang commented 3 years ago

Hi @xjjius, most of the configurations of viewer widget can be accessed by viewer.getRenderConfigs(), and by default, all viewers in one HTML page shares the same render configuration instance. You can check the /render/kekule.render.configs.js to overview all the options. To use specified color of atoms in molecule, just:

viewer.getRenderConfigs().getColorConfigs().setUseAtomSpecifiedColor(true);  // for 2D viewer
// or
viewer.getRenderConfigs().getMoleculeDisplayConfigs().setUseAtomSpecifiedColor(true);  // for 3D viewer
// force repainting
viewer.repaint();
xjjius commented 3 years ago

That works!! Thanks again for your help and the great work!!