partridgejiang / Kekule.js

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

Moodle Atto Editor #236

Open registerme1963 opened 3 years ago

registerme1963 commented 3 years ago

Hi Export to png/base64 works fine with kekule moodle atto editor plugin. Is it possible to export as cml or mol data format instead of png? I can then use simple text filter to display the structure on the fly. I already have working filter for converting mol data to svg.

niuzhenjiang commented 3 years ago

let mol = composer.getChemObj(); var data = Kekule.IO.saveFormatData(mol, 'cml'); // or Kekule.IO.saveMimeData(mol, 'chemical/x-cml'); console.log(data); var data = Kekule.IO.saveFormatData(mol, 'mol'); // or Kekule.IO.saveMimeData(mol, 'chemical/x-mdl-molfile'); console.log(data); var data = Kekule.IO.saveFormatData(mol, 'smi'); // or Kekule.IO.saveMimeData(mol, 'chemical/x-daylight-smiles'); console.log(data);

registerme1963 commented 3 years ago

Where do these line go? I believe at moodle/lib/editor/atto/plugins/kekulechem/yui/build/moodle-atto_kekulechem-button/moodle-atto_kekulechem-button.js

partridgejiang commented 3 years ago

The codes to insert molecule data to atto editor region locate in atto/plugins/kekulechem/yui/src/button/js/button.js. The core method is _submitChemObj at line 441 currently. You may modify the codes inside it into something like:

    _submitChemObj: function()
    {
        var mol = this._chemObjInserter.getChemObj();
        var molData = Kekule.IO.saveFormatData(mol, Kekule.IO.DataFormat.MOL);
        var editor = this.get('host');
        editor.focus();   // IMPORTANT: must focus back to editor, otherwise insertion may failed in blured editor
        editor.insertContentAtFocusPoint(molData);
        this.markUpdated();
    }
registerme1963 commented 3 years ago

Thanks, it is working fine.. I see another problem, when I press the 3D tab in the Insert-Chem-Object dialog it throws an error "it seems that your browser is not modern enough to support the drawing funtion. Please update it" I'm using edge Version 91.0.864.71 (Official build) (64-bit) and I tried with latest Chrome also. Alternatively, I do I create 3D structure (like get3D.html) inside moodle editor regards and Thanks

partridgejiang commented 3 years ago

The 3D rendering currently relies on Three.js, so don't forget to include it in the web page before using Kekule.js. The error message is somewhat bewildering and should be fixed soon, :).

registerme1963 commented 3 years ago

in the chem composer, 'use element specified color' in the setting is set to false. How to make it to true by default?

partridgejiang commented 3 years ago

A simple approach is to change the default render2DConfigs instance shared by all viewers/editors:

Kekule.Render.Render2DConfigs.getInstance().getColorConfigs().setUseAtomSpecifiedColor(true);
registerme1963 commented 2 years ago

The 3D rendering currently relies on Three.js, so don't forget to include it in the web page before using Kekule.js. The error message is somewhat bewildering and should be fixed soon, :).

Is there any update in this regard rV

partridgejiang commented 2 years ago

Yes, it has been fixed already. You may see a more clear error message about Three.js.