rdkit / RDKitjs-legacy

Obsolete codebase, please do not use.
BSD 3-Clause "New" or "Revised" License
32 stars 12 forks source link

TypeError: bindings.SmilesToMol is not a function #20

Closed bmiles closed 5 years ago

bmiles commented 5 years ago

Error below when executing script in command line:

/Users/ben/node_modules/RDKit/lib/Mol.js:183
        bindings.SmilesToMol(
                 ^

TypeError: bindings.SmilesToMol is not a function
    at Function.fromSmiles (/Users/ben/node_modules/RDKit/lib/Mol.js:183:18)
    at atoms (/Users/ben/Documents/dev/comp_chem/rdkitjs/application.js:6:23)
    at Object.<anonymous> (/Users/ben/Documents/dev/comp_chem/rdkitjs/application.js:13:1)
    at Module._compile (internal/modules/cjs/loader.js:689:30)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:700:10)
    at Module.load (internal/modules/cjs/loader.js:599:32)
    at tryModuleLoad (internal/modules/cjs/loader.js:538:12)
    at Function.Module._load (internal/modules/cjs/loader.js:530:3)
    at Function.Module.runMain (internal/modules/cjs/loader.js:742:12)
    at startup (internal/bootstrap/node.js:283:19)

Script below launched in the terminal with node js node application.js

// applications.js
const RDKit = require('RDKit');
var my_mol = "COc1ccc(CCN(C(=O)CCCBr)C2c3cc(NC(C)=O)c([N+](=O)[O-])cc3OC(C)(C)C2O)cc1";

function atoms(smi) {
  var mol = RDKit.Mol.fromSmiles(smi);
  var num_atoms = mol.getNumAtoms();
  console.log( num_atoms );
}

atoms(my_mol)

If I open up a node js REPL and copy and paste in the script it works just fine. Any idea where this bindings.SmilesToMol( issue is arising?

bmiles commented 5 years ago

Working example here https://runkit.com/bmiles/runkit-npm-rdkit

JCorson commented 5 years ago

I am not familiar enough with the project to explain the internals, but I have seen examples that include await RDKit.load(). The following seems to work.

const RDKit = require('rdkit');

await RDKit.load();

var my_mol = "COc1ccc(CCN(C(=O)CCCBr)C2c3cc(NC(C)=O)c([N+](=O)[O-])cc3OC(C)(C)C2O)cc1";
var mol = RDKit.Mol.fromSmiles(my_mol);
mol.getNumAtoms();
bmiles commented 5 years ago

I am not familiar enough with the project to explain the internals, but I have seen examples that include await RDKit.load(). The following seems to work.

const RDKit = require('rdkit');

await RDKit.load();

var my_mol = "COc1ccc(CCN(C(=O)CCCBr)C2c3cc(NC(C)=O)c([N+](=O)[O-])cc3OC(C)(C)C2O)cc1";
var mol = RDKit.Mol.fromSmiles(my_mol);
mol.getNumAtoms();

That works, thanks @JCorson