Files
rdkit/Code/MinimalLib
Greg Landrum 45681a1c04 Switch from using RapidJSON to Boost::JSON for MolInterchange (#8859)
* First pass at port

Mostly auto-converted using claude sonnet 4

Things are a bit slower in this initial port. Here's some timing data for molecules from SMILES (no coords) and from SDF (with coords)

# MASTER
## smiles
read: 50000 mols.
 9.260000s wall, 8.650000s user + 0.600000s system = 9.250000s CPU (99.9%)
serialize
 3.060000s wall, 2.400000s user + 0.660000s system = 3.060000s CPU (100.0%)
deserialize
 1.350000s wall, 1.250000s user + 0.090000s system = 1.340000s CPU (99.3%)

## SDF
read: 50000 mols.
 9.340000s wall, 8.930000s user + 0.400000s system = 9.330000s CPU (99.9%)
serialize
 6.630000s wall, 5.960000s user + 0.680000s system = 6.640000s CPU (100.2%)
deserialize
 1.450000s wall, 1.450000s user + 0.000000s system = 1.450000s CPU (100.0%)

# Boost::JSON
## smiles
read: 50000 mols.
 9.250000s wall, 8.830000s user + 0.420000s system = 9.250000s CPU (100.0%)
serialize
 4.770000s wall, 4.410000s user + 0.350000s system = 4.760000s CPU (99.8%)
deserialize
 2.320000s wall, 2.100000s user + 0.230000s system = 2.330000s CPU (100.4%)

## SDF
read: 50000 mols.
 9.500000s wall, 9.100000s user + 0.400000s system = 9.500000s CPU (100.0%)
serialize
 8.760000s wall, 8.330000s user + 0.420000s system = 8.750000s CPU (99.9%)
deserialize
 2.540000s wall, 2.330000s user + 0.210000s system = 2.540000s CPU (100.0%)

* some json parser optimization

* around the edges

* optimizations for the writer

* hopefully get things compiling

* convert the MinimalLib stuff to use boost::json

Again, a lot of the lifting here was done using Claude Sonnet 4 in VS Code Copilot

* fix Windows DLL build

* response to review

Co-authored-by: Paolo Tosco <paolo.tosco.mail@gmail.com>

* better not to blindly accept suggestions

* fix the problems in MinimalLib

---------

Co-authored-by: Paolo Tosco <paolo.tosco.mail@gmail.com>
Co-authored-by: = <=>
2025-11-11 11:54:44 +01:00
..
2025-09-29 17:33:02 +02:00
2025-09-29 17:33:02 +02:00
2025-09-29 17:33:02 +02:00
2025-09-29 17:33:02 +02:00

IMPORTANT NOTE:

The NPM release process has now moved to the official repository of rdkit-js.

The official rdkit-js repository will now be the centralized place for everything built "on top of" the core RDKit MinimalLib source code (this repository). Please read this for more context.

RDKit MinimalLib

Build Status License DOI
NPM Latest Version NPM Weekly Downloads NPM Monthly Downloads NPM Yearly Downloads NPM Total Downloads

Table of contents

Introduction

The idea of the MinimalLib is to allow the RDKit to be used from JavaScript so that we can add chemical capabilities to web applications.

This initial set of functionality does not cover all of RDKit's functionality, but it is intended to be directly useful.

Install

The most popular way of installing the MinimalLib is with NPM.

npm i @rdkit/rdkit
# yarn add @rdkit/rdkit

To build the MinimalLib manually, refer to this section.

Usage

Using the RDKit package assets

Option 1: Use the npm package distribution files

Once you have the RDKit package installed in your node modules, copy the following distribution files anywhere in your deployed assets.

  • node_modules/@rdkit/rdkit/dist/RDKit_minimal.js
  • node_modules/@rdkit/rdkit/dist/RDKit_minimal.wasm

NOTE: Both files must be copied at the same location in your deployed assets for the library to work properly.

Option 2: Use the remote distribution files from unpkg.com

  • https://unpkg.com/@rdkit/rdkit/dist/RDKit_minimal.js
  • https://unpkg.com/@rdkit/rdkit/dist/RDKit_minimal.wasm

Option 3: Build your own distribution files

For this method, refer to Building the MinimalLib.

Running RDKit in your JavaScript code

To use RDKit, load the javascript file and instantiate the wasm module inside the head tag of your index.html, before you run your application code:

<head>
    <!-- ...other files and HTML tags... -->
    <!-- Load the RDKit JS file -->
    <script src="https://unpkg.com/@rdkit/rdkit/Code/MinimalLib/dist/RDKit_minimal.js"></script>

    <!-- Instantiate the WASM module. The inline script below could live elsewhere inside your application code. -->
    <script>
        window.initRDKitModule()
            .then(function(RDKit) {
                console.log("RDKit version: " + RDKit.version());
                window.RDKit = RDKit;
                /**
                 * The RDKit module is now loaded.
                 * You can use it anywhere.
                 */
            })
            .catch(() => {
                // handle loading errors here...
            });
    </script>
    <!-- ...your application code goes here... -->
</head>

Live demos

If you are using the MinimalLib for the first time, see the getting started examples at https://www.rdkitjs.com/ .

All live demos

Building the MinimalLib

Building from Github

Make sure you are at the root of the MinimalLib, and run the following script:

scripts/build_rdkitjs.sh <RDKit git release tag name>
# Example: scripts/build_rdkitjs.sh Release_2025_03_2

This command will take several minutes to complete, and will default to using the master branch if no version is provided. Also, checkout the build_rdkitjs.sh file to see how things are tied together.

Building from the local source tree

Make sure you are at the root of the MinimalLib, and run the following script:

GET_SRC=copy_from_local scripts/build_rdkitjs.sh

This command will take several minutes to complete, and will use the local source tree

Using the RDKit package assets

Once you have verified that the distribution files have been properly added in Code/MinimalLib/dist, refer to the Using the RDKit package assets section for the next steps.