Kekule.js icon indicating copy to clipboard operation
Kekule.js copied to clipboard

kekule-json and useAtomSpecifiedColor: true

Open cleblond opened this issue 6 years ago • 4 comments

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?

cleblond avatar Dec 23 '18 22:12 cleblond

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);

partridgejiang avatar Dec 24 '18 01:12 partridgejiang

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)

cleblond avatar Dec 26 '18 02:12 cleblond

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');

partridgejiang avatar Dec 27 '18 14:12 partridgejiang

OK thank you.

cleblond avatar Dec 31 '18 13:12 cleblond