partridgejiang / Kekule.js

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

Show atom colors in molecule representation #50

Closed gbayarri closed 6 years ago

gbayarri commented 6 years ago

Hi, I have a simple representation:

function showMolecule2D(mol) {
  Kekule.Widget.getWidgetById('chemViewer2D').setChemObj(mol);
  Kekule.Widget.getWidgetById('chemViewer2D').setToolButtons(['molDisplayType', 'zoomIn', 'zoomOut']);
}

The output for this function is a molecule representation:

screenshot

But the Nitrogens and Oxygens of this molecule have not the typical blue / red color as in the kekule composer. Is there any way to pass a parameter or call a method to do that in my code?

Thanks.

partridgejiang commented 6 years ago

Hi @gbayarri, you can use the following code in the initialization part of your program to ensure the viewer rendering atoms with different colors:

var viewer = Kekule.Widget.getWidgetById('chemViewer2D');
viewer.getRenderConfigs().getColorConfigs().setUseAtomSpecifiedColor(true);
// ......
viewer.setChemObj(mol);
gbayarri commented 6 years ago

Hi, @partridgejiang, it works perfectly.

Thank you!