Files
rdkit/Code/MinimalLib
Paolo Tosco 948f7d231a Expose reaction drawing and additional FPs in MinimalLib (#5277)
* - exposed reaction drawing in MinimalLib
- fixed a typo in the error message "JSON doesn't contain 'atoms' field, or it is not an array"
- replaced RapidJson HasMember() with FindMember() to avoid a duplicate lookup in case the member exists and can be accessed
- some cosmetic style changes (avoid multiple variable declarations on a single line, use curly bracket also for one-liner if clauses, use auto where possible)
- capitalized "greg Landrum" to "Greg Landrum" (well deserved)
- exposed other FPs in addition to Morgan and Pattern FPs in MinimalLib
- added relevant tests

* - update CXSMARTS test in MinimalLib

* Changes in response to review:
- exposed reaction drawing functionality to CFFI and added relevant tests
- refactored fingerprint code to use JSON details and deprecated the Morgan/pattern fingerprint functions that used multiple parameters
- all fingerprints are now exposed to both JS and CFFI with no code duplication
- fixed a potential crash bug in the CFFI library where calling get_morgan_fp(), get_rdkit_fp() or get_pattern_fp with a NULL mol_pkl would result in dereferencing a nullptr

* removed debugging printouts committed accidentally

Co-authored-by: Tosco, Paolo <paolo.tosco@novartis.com>
2022-09-06 14:27:10 +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

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

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

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 and the minimallib Dockerfile to see how things are tied together.

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.