partridgejiang / Kekule.js

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

kekule-json and useAtomSpecifiedColor: true #97

Open cleblond opened 5 years ago

cleblond commented 5 years ago

When I export to kekule-json object from a composer that has useAtomSpecifiedColor set to true, the useAtomSpecifiedColor: true is not set in the json. Is this possible?

partridgejiang commented 5 years ago

Hi @cleblond, if the useAtomSpecifiedColor is set in the composer configs, it will only affect the render style of this composer but not the exported object data. The following code is more suitable for your request:

composer.getChemObj().setRenderOption('useAtomSpecifiedColor', true);
cleblond commented 5 years ago

Thanks partridge!. I'm trying to capture the composer configs to a viewer and then insert into the dom as kekule-json. Here is what I'm trying and the error I'm seeing. It works fine if I skip the setRenderOptions(CurComposerRenderConfigs); line.

var CurComposerRenderConfigs = chemObjSetter.viewer.getEditorProperties(); var molecule = chemObjSetter.getChemObj(); molecule.setRenderOptions(CurComposerRenderConfigs); var testkjs = Kekule.IO.saveFormatData(molecule, 'Kekule-JSON'); console.log(testkjs);

Here is the html I generate wtih the kekule-json. Below it is the error.

`Question Image

` Here is the console log error. VM14883 common.min.js:1 Cannot read property 'x2' of null throwException @ VM14883 common.min.js:1 (anonymous) @ VM14881 root.min.js:1 throwException @ VM14971 widget.min.js:1 (anonymous) @ VM14881 root.min.js:1 Kekule.throwException @ VM14883 common.min.js:1 Kekule.warn @ VM14883 common.min.js:1 bindElement @ VM14971 widget.min.js:1 elementChanged @ VM14971 widget.min.js:1 setter @ VM14971 widget.min.js:1 (anonymous) @ VM14881 root.min.js:1 doSetElement @ VM15073 chemWidget.min.js:1 (anonymous) @ VM14881 root.min.js:1 getPrototype @ VM14881 root.min.js:1 initialize @ VM14971 widget.min.js:1 (anonymous) @ VM14881 root.min.js:1 (anonymous) @ VM14881 root.min.js:1 initialize @ VM15073 chemWidget.min.js:1 (anonymous) @ VM14881 root.min.js:1 (anonymous) @ VM14881 root.min.js:1 initialize @ VM15073 chemWidget.min.js:1 (anonymous) @ VM14881 root.min.js:1 klass @ VM14881 root.min.js:1 createWidgetOnElem @ VM14971 widget.min.js:1 executeOnElemBySelector @ VM14971 widget.min.js:1 execute @ VM14971 widget.min.js:1 (anonymous) @ VM14971 widget.min.js:1 VM14930 render.min.js:1 Uncaught TypeError: Cannot read property 'x2' of null at klass.getExposedContainerBox2D (VM10728 render.min.js:1) at klass.doEstimateSelfObjBox (VM10728 render.min.js:1) at klass.doEstimateObjBox (VM10728 render.min.js:1) at klass. (VM10679 root.min.js:1) at klass.doEstimateObjBox (VM10728 render.min.js:1) at klass.doEstimateObjBox (VM10679 root.min.js:1) at klass.estimateObjBox (VM10728 render.min.js:1) at klass.doEstimateRenderBox (VM10728 render.min.js:1) at klass.estimateRenderBox (VM10728 render.min.js:1) at klass.estimateRenderBox (VM10728 render.min.js:1) getExposedContainerBox2D @ VM14930 render.min.js:1 doEstimateSelfObjBox @ VM14930 render.min.js:1 doEstimateObjBox @ VM14930 render.min.js:1 (anonymous) @ VM14881 root.min.js:1 doEstimateObjBox @ VM14930 render.min.js:1 (anonymous) @ VM14881 root.min.js:1 estimateObjBox @ VM14930 render.min.js:1 doEstimateRenderBox @ VM14930 render.min.js:1 estimateRenderBox @ VM14930 render.min.js:1 estimateRenderBox @ VM14930 render.min.js:1 estimateRenderBox @ VM14930 render.min.js:1 estimateScreenBox @ VM14930 render.min.js:1 calcDrawBaseCoord @ VM15073 chemWidget.min.js:1 calcDrawParams @ VM15073 chemWidget.min.js:1 repaint @ VM15073 chemWidget.min.js:1 drawOptionChanged @ VM15073 chemWidget.min.js:1 setter @ VM15073 chemWidget.min.js:1 getPrototype @ VM14881 root.min.js:1 initialize @ VM15073 chemWidget.min.js:1 (anonymous) @ VM14881 root.min.js:1 klass @ VM14881 root.min.js:1 createWidgetOnElem @ VM14971 widget.min.js:1 executeOnElemBySelector @ VM14971 widget.min.js:1 execute @ VM14971 widget.min.js:1 (anonymous) @ VM14971 widget.min.js:1 VM14930 render.min.js:1 Uncaught TypeError: Cannot read property 'x2' of null at klass.getExposedContainerBox2D (VM10728 render.min.js:1) at klass.doEstimateSelfObjBox (VM10728 render.min.js:1) at klass.doEstimateObjBox (VM10728 render.min.js:1) at klass. (VM10679 root.min.js:1) at klass.doEstimateObjBox (VM10728 render.min.js:1) at klass.doEstimateObjBox (VM10679 root.min.js:1) at klass.estimateObjBox (VM10728 render.min.js:1) at klass.doEstimateRenderBox (VM10728 render.min.js:1) at klass.estimateRenderBox (VM10728 render.min.js:1) at klass.estimateRenderBox (VM10728 render.min.js:1)
partridgejiang commented 5 years ago

If I am not understand wrongly, the codes above is called after the code in issue #88? That means:

var renderConfigs = new Kekule.Render.Render2DConfigs();
renderConfigs.getColorConfigs().setUseAtomSpecifiedColor(true);
chemObjSetter.setEditorProperties({'renderConfigs': renderConfigs});

var CurComposerRenderConfigs = chemObjSetter.viewer.getEditorProperties();  
  // here CurComposerRenderConfigs object has value {'renderConfigs': renderConfigs}, and renderConfigs is an instance of class Kekule.Render.Render2DConfigs
var molecule = chemObjSetter.getChemObj();
molecule.setRenderOptions(CurComposerRenderConfigs);  
  // The renderOptions property of chemObj should be a simple object with {prop1: value1, prop2: value2} pairs, 
  // and  {'renderConfigs': renderConfigs} is not a valid value to set a render option of molecule, so the error may occur here
var testkjs = Kekule.IO.saveFormatData(molecule, 'Kekule-JSON');

The codes may be modified as the following ones, have a try?

var renderConfigs = new Kekule.Render.Render2DConfigs();
renderConfigs.getColorConfigs().setUseAtomSpecifiedColor(true);
chemObjSetter.setEditorProperties({'renderConfigs': renderConfigs});

var molecule = chemObjSetter.getChemObj();
molecule.setRenderOption('useAtomSpecifiedColor', true);
  // or molecule.setRenderOptions({'useAtomSpecifiedColor': true});
var testkjs = Kekule.IO.saveFormatData(molecule, 'Kekule-JSON');
cleblond commented 5 years ago

OK thank you.