partridgejiang / Kekule.js

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

Adding custom templates to Kekule #228

Open registerme1963 opened 3 years ago

registerme1963 commented 3 years ago

Is there a way to add my own templates in the kekule Chem composer. I want to add templates of amino acids, sugars, polycycles, functional groups, reagents etc Thanks

partridgejiang commented 3 years ago

Hi @registerme1963, to add a subgroup template, firstly you need to create its JSON data. There is a tool (/src/_devUtils/repositoryUtil/repItemSetter.html) for that task. Please open it in a web browser and then do the following steps (as in the attached image):

  1. Draw the subgroup structure in composer on the left.
  2. Ensure the drop box is set to class Kekule.Subgroup.
  3. Select an atom in structure, then click the "Set Anchor(s)" button to appoint the atom as the connection point to other part of the molecule.
  4. Input abbreviation label of the subgroup (OTMS here), which will be displayed in editor. Another choice is using Formula text (e.g., C6H5). The formula text will be displayed only if the abbreviation is empty.
  5. Enter input texts. Multiple lines of input text can be used here. In the editor, when user inputs a label matching either of those input texts, this subgroup will be created. For example, both "Et" and "C2H5" will create the same subgroup.
  6. Click on "Get Data" button to generate JSON string.

Then, in your own JS code, register the new subgroup:

Kekule.Editor.RepositoryData.subGroups.push({"inputTexts":["OTMS"],"dataFormat":"Kekule-JSON"...../* The JSON string generated above*/ });

After that, the new template subgroup will be displayed in the atom/subgroup panel of composer.

image

registerme1963 commented 3 years ago

I want add these templates in the kekule moodle editor. Where will I add these subgroups? Sorry, I have little knowledge in javascript

partridgejiang commented 3 years ago

The code to add new subgroups should be put at any time after Kekule.js is loaded. For the Kekule Moodle plugin, you may insert it inside the init() function of [moodle dir]/local/kekulejs/amd/src/kekuleInitials.js and rebuild the moodle plugin (see https://docs.moodle.org/dev/Javascript_Modules), After those steps, the subgroup buttons will be automatically added to the atom panel of editor: 图片 图片

joeolu14 commented 1 year ago

@partridgejiang, I followed these steps, I was able to copy the JSON and also created a button with an onclick event to call

Kekule.Editor.RepositoryData.subGroups.push({"inputTexts":["OTMS"],"dataFormat":"Kekule-JSON"...../* The JSON string generated above*/ });

But when I checked the Subgroups, I do not see the Subgroup Abbr among the list.

image

After I click on the "Save Subgroup" button, and then check the Subgroup, I do not see the new subgroup I created

Any thing I am missing here?