partridgejiang / Kekule.js

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

Can I import using import #250

Open FreedomClannad opened 2 years ago

FreedomClannad commented 2 years ago

In the environment where I use vue3 + ts, if I want to use this plug-in, I can only use import. I think the document can only be used in the required format. Ask if there are any other solutions.

partridgejiang commented 2 years ago

Perhaps you can just import the kekule.min.js file? Something like the following:

import * as K from 'kekule-dist-dir/kekule.min.js';
console.log(Kekule.VERSION);  // the `Kekule` namespace is automatically imported to the global scope

By the way, The latest dist files solves some minor issues with import and are recommended for your test, :).

FreedomClannad commented 2 years ago

thank you very much

ZhitaoTian commented 2 years ago

@partridgejiang and how to read a smiles string using vue3 + ts. The below script doesn't work, while Kekule.IO.loadFormatData(cmlData, 'cml') work.

import * as K from 'kekule/dist/kekule.min.js'
let Smiles= "C2=Cc1ccccc1C2"
var mol = Kekule.IO.loadFormatData(Smiles, 'smi')
partridgejiang commented 2 years ago

Hi @ZhitaoTian, the SMILES output is supported natively with Kekule.js, while the input relies on the external OpenBabel module. So you need to manually enable it before load a SMILES format string:

Kekule.OpenBabel.enable(function(error){
  if (!error)
  {
    let mol = Kekule.IO.loadFormatData('C2=Cc1ccccc1C2', 'smi');
  }
});