RDKit.js Documentation
RDKit.js is the official JavaScript distribution of cheminformatics functionality from the RDKit, C++ library for cheminformatics.
The core WASM module comes from RDKit’s MinimalLib. MinimalLib wraps a subset of RDKit’s API so it can be compiled to WebAssembly and used from JavaScript. The package is built and published from RDKit main repository, while JavaScript documentation lives here.
The package is only three files, with zero dependencies:
RDKit_minimal.js- Emscripten JavaScript glue that loads the WASM moduleRDKit_minimal.wasm- compiled RDKit MinimalLib binaryRDKit_minimal.d.ts- TypeScript types generated at compile time
High-level UI components are not included, as these are usually framework specific. You will need to implement those yourself.
Install
npm i @rdkit/rdkit
# yarn add @rdkit/rdkit
# pnpm i @rdkit/rdkit
Or via CDN:
<script src="https://unpkg.com/@rdkit/rdkit/dist/RDKit_minimal.js"></script>
Loading the WASM module
initRDKitModule() initializes the WASM module and returns a Promise for the RDKit library object.
const RDKit = await initRDKitModule();
console.log("RDKit version:", RDKit.version());
Or with .then:
initRDKitModule().then((RDKit) => {
console.log("RDKit version:", RDKit.version());
});
Loading is asynchronous.
For bundlers most friction is not related to RDKit, but how Emscripten-compiled modules ship compiled module. Most common issues are
Making
.wasmfetchable after bundling. After bundling, the glue JS usually no longer sits next toRDKit_minimal.wasm.
There is a code branch in the
.jsfile that checks forENVIRONMENT_IS_NODEenv variable, which hasnode:function calls. Although these are never executed outside explicitlynodejs, some static analysis fails at build time, because the functions does not exist.
Both requires framework specific fixes.
Getting started
const RDKit = await initRDKitModule();
console.log(RDKit.version());
const mol = RDKit.get_mol("CCO");
if (!mol) throw new Error("Failed to parse SMILES");
console.log(mol.get_smiles());
console.log(mol.get_num_atoms());
console.log(JSON.parse(mol.get_descriptors()).amw);
mol.delete();
Examples being used with different frameworks
- RDKit.js + Vanilla JS
- RDKit.js + React (Vite)
- RDKit.js + Vue (Vite)
- RDKit.js + Angular
- RDKit.js + Svelte (Vite)
- RDKit.js + Next.js
- RDKit.js + Node.js
Using RDKit.js Pro Tips
- The module can also run inside a Web Worker so heavy work does not block the UI thread
- Always call
mol.delete()when you dont need the molecule anymore, to free some memory - You can make your molecule SVG transparent with
.molecule-structure-svg svg rect:first-of-type {fill: transparent !important;} - The package is compiled with emscripten
-fwasm-exceptions, e.i. WebAssembly.Exception. - Have fun!
Note on versions
Previously versions was formatted as “RDKit release 2022.3.3-1.0.0”, noting the version of RDKit and iteration of JavaScript.
But from 2026 and onwards there will only be the RDKit version, as it is published from the main repository. E.i. “2022.3.3”.
Old versions are kept of course.
License
BSD 3-Clause (same as RDKit).
Citation
See rdkit.org. Note the installed version when citing.