partridgejiang / Kekule.js

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

I want to add a function to a common button. #288

Open chj93 opened 2 years ago

chj93 commented 2 years ago

@partridgejiang First off, I am huge fan of the project. Thanks for all the work :)

I am using Kekule.Editor.Composer.

  1. I want to set the default value of the 'save data' button to smi.
  2. I want to add smi to the selectable field of the 'Load data' button.

I searched the documentation for a day and couldn't find a way. Is there any easy way to solve it? thank you!

partridgejiang commented 2 years ago

Hi @chj93, it's a pity that some hacks are needed to accomplish the default input/output format before. So some new commits are submitted today. With these new dist files, you may use the following codes:

composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
composer.getEditor().setDefaultOutputFormatId(Kekule.IO.DataFormat.SMILES);

By the way, the loading SMILES depends on the extra OpenBabel.wasm module, so you need to enable that module first:

Kekule.OpenBabel.enable(function(error){
  if (!error)
  {
    composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
  }
});
chj93 commented 2 years ago

Hi @partridgejiang, Thanks for your kind reply! I'm using 'Kekule' by installing it as an npm package. The latest release (v.0.9.7) cannot be used because the new commit history is not reflected. Can I request a new release that reflects the new commits?

partridgejiang commented 2 years ago

Just getting the files in /dist directory of this repo and replacing the ones downloaded with npm should work, :).

chj93 commented 2 years ago

With help, in case 1, it works normally. However, in case 2, it does not work because 'Smi' does not exist in the 'Load data' button in the first place. Can you help me with this?? thank you :)

Kekule.OpenBabel.enable(function(error) {
  if (!error) {
    composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
  }
});
// composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
composer.getEditor().setDefaultOutputFormatId(Kekule.IO.DataFormat.SMILES);
partridgejiang commented 2 years ago

Hi @chj93, please check if there are errors in the browser console and whether openbabel.wasm is properly loaded when running the following code:

Kekule.OpenBabel.enable(function(error) {
  if (!error) {
    composer.getEditor().setDefaultInputFormatId(Kekule.IO.DataFormat.SMILES);
  }
});

Since the OpenBabel is a web assembly module, the whole page should be launched in a web server with http(s) protocal, and the mime type of .wasm file may also need to be correctly configurated in the web server.

By the way, a small demo page is attached below, you may run it in your own web server, :)

defInOutFormat.zip