Closed joeolu14 closed 1 year ago
Hi @joeolu14, since InChI is actually a external wasm module, you need to manual enable the InChI functions before using them, e.g.:
Kekule.InChI.enable( error => {
if (!error) {
let inchi = Kekule.IO.saveFormatData(mol, 'inchi');
console.log(inchi);
}
});
@partridgejiang I tried the above and got this error:
This is what the code looks like:
const generateMoleCules = async () => {
const composer = Kekule.Widget.getWidgetById("composer");
const mols = composer.exportObjs(Kekule.Molecule);
const msg = "Molecule count: " + mols.length + "\n ";
const m = [];
for (let i = 0, l = mols.length; i < l; ++i) {
const mol = mols[i];
m.push(Kekule.IO.saveFormatData(mol, "smi"));
Kekule.InChI.enable((error: any) => {
if (!error) {
let inchi = Kekule.IO.saveFormatData(mol, "inchi");
console.log(inchi);
}
});
setMole(m);
}
};
Hi @joeolu14, The error displayed ( Unexpected token '<'
) seems caused by the web server? Is content of inchi.wasm properly returned by server? Perhaps you could switch to the network panel of developer tools in web browser to check which files and contents are transfered when Kekule.InChI.enable()
being called.
@partridgejiang I saw the error, I had to copy the libs to my static folder to avoid the error, but the issue now is, the inchi is not being created and does not look like anything inside the enable block gets read. This is what my code looks like
const generateMoleCules = async () => {
const composer = Kekule.Widget.getWidgetById("composer");
const mols = composer.exportObjs(Kekule.Molecule);
const msg = "Molecule count: " + mols.length + "\n ";
const m = [];
for (let i = 0, l = mols.length; i < l; ++i) {
const mol = mols[i];
m.push(Kekule.IO.saveFormatData(mol, "mol"));
Kekule.InChI.enable((error: any) => {
if (error) {
console.log(error);
}
if (!error) {
let inchi = Kekule.IO.saveFormatData(mol, "inchi");
console.log(inchi, "inchi");
}
});
setMole(m);
}
};
is there anything to do to get this working?
Hi @joeolu14, you may check the status of Kekule InChI module in the console of the web development tool to find out whether the module is properly loaded and initialized:
Kekule.InChI.isScriptLoaded() // should returns true if the wasm is loaded
Kekule.InChI.getInChIScriptUrl() // should returns the path to the inchi.js
If the Kekule.InChI.getInChIScriptUrl()
is different from the actual location of inchi.js (and inchi.wasm), you need to manually set it before calling Kekule.InChI.enable()
:
Kekule.environment.setEnvVar('inchi.scriptSrc', '/the/real/path/to/inchi.js');
// ...
Kekule.InChI.enable(...);
@partridgejiang when I checked isScriptLoaded() it returns false. the getInchiScriptUrl() is pointed to where I have the inchi.js and the wasm. I feel Kekule.InChI.enable is not being called or executed.
from the image below the inchi.js script is loaded and read
@joeolu14, would you please provide a simple demo file of you app here? So that I may debug it in my environment? Thanks.
Is there a way to saveFormatData in Inchi format?
This what I tried but did not work