Open nixondevph opened 3 years ago
Hi @DineshOng, class OBOp is not exported in current JavaScript compilation of OpenBabel, so the codes above should not work at present. I'll check it and try to include OBOp in the future.
@DineshOng, please check the compilation base on OpenBabel3 at OpenBabel3/OpenBabel-js/bin/. In this new compilation, OBOp is exported and the code above should be work now.
@DineshOng, please check the compilation base on OpenBabel3 at OpenBabel3/OpenBabel-js/bin/. In this new compilation, OBOp is exported and the code above should be work now.
Hello @partridgejiang, do you have a demo of the new OpenBabel3?
Hi @DineshOng, the OpenBabel demo page has been updated, please check it on https://partridgejiang.github.io/cheminfo-to-web/demos/items/OpenBabel/openBabelDemo.html, in which a gen3D operation demo has been added. Generally, if a 3D structure need to be generated from a SMILES string, the following codes can be used:
var smiles= 'C(Cl)(=O)CCC(=O)Cl';
var conv = new OpenBabel.ObConversionWrapper();
conv.setInFormat('', 'smi');
var mol = new OpenBabel.OBMol();
conv.readString(mol, smiles);
var gen3d = OpenBabel.OBOp.FindType('Gen3D'); // FindType is actually a factory constructor, no need to use "new" here
if (!gen3d.Do(mol, ''))
console.error('Generate 3D failed');
else
{
conv.setOutFormat('', 'mol');
var outputData = conv.writeString(mol, false);
console.log(outputData);
}
conv.delete();
mol.delete();
By the way, please use the latest compiliation including openbabel.js, openbabel.wasm and openbabel.data.
How to instantiate OpenBabel?
Hi @DineshOng, please check the overview section of the OpenBabel demo (https://partridgejiang.github.io/cheminfo-to-web/demos/items/OpenBabel/openBabelDemo.html), the OpenBabel module can be created with calling to function OpenBabelModule()
, and a callback function can be used to acknowledge the ready state of OpenBabel module:
var OpenBabel = OpenBabelModule();
OpenBabel.onRuntimeInitialized = function()
{
// Now the OpenBabel module is ready
var conv = new OpenBabel.ObConversionWrapper();
// ...
}
My code doesn't seem to work