rdkit-esm 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2026 - now, RDKit-wrapper contributors
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,128 @@
1
+ # RDKit-ESM
2
+
3
+ RDKit minimal lib for the modern web.
4
+
5
+ A typed ESM wrapper around [RDKit](https://www.rdkit.org/)'s WebAssembly MinimalLib. Instead of manually serializing and deserializing JSON strings to interact with the raw WASM API, you get a direct TypeScript interface with full autocomplete and compile-time validation of every option.
6
+
7
+ **Features:** molecule parsing, substructure search, molecular descriptors, fingerprints (Morgan, MACCS, pattern, ...), reactions, Maximum Common Substructure, R-group decomposition, SVG and Canvas rendering.
8
+
9
+ ## Acknowledgment
10
+
11
+ This library is based on the RDKit project and it's RDKit-js distribution. We thank the RDKit community for their contributions,
12
+ in particular Michel Moreau and Paolo Tosco for maintaining the MinimalLib and the RDKit-js distribution. The initial types
13
+ definitions at the basis of this project had been written by Ádám Baróthi.
14
+
15
+ ## Installation
16
+
17
+ ```bash
18
+ npm install rdkit-esm
19
+ ```
20
+
21
+ ## Quick Start
22
+
23
+ ```ts
24
+ import { initRDKit } from 'rdkit-esm';
25
+
26
+ // Initialization is async — await it before calling any other method
27
+ const rdkit = await initRDKit();
28
+
29
+ const mol = rdkit.getMol('c1ccccc1');
30
+ if (mol) {
31
+ mol.getSmiles(); // 'c1ccccc1'
32
+ mol.getDescriptors(); // { exactMW: 78.047, ClogP: 1.6816, ... }
33
+ mol.getSvg({ width: 350, height: 300 });
34
+
35
+ mol.delete(); // free WASM memory when done
36
+ }
37
+ ```
38
+
39
+ ## API Overview
40
+
41
+ ### `initRDKit(options?): Promise<RDKit>`
42
+
43
+ Loads the WASM module and returns the main interface. **Must be awaited** before any other call.
44
+
45
+ ### `RDKit`
46
+
47
+ The main entry point for creating molecules, reactions, and collections.
48
+
49
+ | Method | Description |
50
+ | ----------------------------------- | ------------------------------------------------------------------------------------------ |
51
+ | `getMol(input, options?)` | Create a `Mol` from SMILES, SMARTS, MolFile, or JSON. Returns `null` on invalid input. |
52
+ | `getQMol(input)` | Create a query `Mol` from a SMARTS string or a query MolFile. |
53
+ | `getRxn(input, options?)` | Create a `Reaction` from reaction SMARTS, SMILES, or an RXN block. |
54
+ | `getMCS(mols, options?)` | Compute the Maximum Common Substructure across a set of molecules (`Mol[]` or `string[]`). |
55
+ | `getRGD(core, molecules, options?)` | R-Group Decomposition against one or more core structures. |
56
+ | `molzip(mol1, mol2)` | Combine two molecules. |
57
+ | `version` | RDKit version string. |
58
+ | `module` | Raw `RDKitModule` for direct WASM access. |
59
+
60
+ ### `Mol`
61
+
62
+ Wraps a single molecule with a typed, camelCase API.
63
+
64
+ - **String representations** — `getSmiles()`, `getCxSmiles()`, `getSmarts()`, `getMolblock()`, `getV3KMolblock()`, `getInchi()`, `getInchikey()`, `getJson()`
65
+ - **Fingerprints** — `getMorganFp()`, `getMaccsFp()`, `getPatternFp()`, `getTopologicalTorsionFp()`, `getRdkitFp()`, `getAtomPairFp()` (each also available as `…AsUint8Array()`)
66
+ - **Descriptors** — `getDescriptors()` returns MW, ClogP, HBA, HBD, ring counts, etc.
67
+ - **Substructure** — `getSubstructMatch(query)`, `getSubstructMatches(query)`
68
+ - **Drawing** — `getSvg(options?)`, `drawToCanvas(canvas, ...)`
69
+ - **Coordinates** — `setNewCoords()`, `generateAlignedCoords(template, options?)`
70
+ - **Mutations** — `addHs()` / `removeHs()`, `convertToAromaticForm()` / `convertToKekuleForm()`, `combineWith()`, `zipWith()`
71
+ - **Properties** — `hasProp()`, `getProp()`, `setProp()`, `clearProp()`, `getPropList()`
72
+ - **Info** — `isValid()`, `getNumAtoms()`, `getNumBonds()`, `hasCoords()`, `getStereoTags()`
73
+
74
+ ### `MolArray`
75
+
76
+ Extends `Array<Mol>` with batch lifecycle management. Returned by `getFrags()`. Call `.delete()` to free all contained molecules at once. Supports all standard array methods (indexing, iteration, `map`, `filter`, ...).
77
+
78
+ ### `Reaction`
79
+
80
+ | Method | Description |
81
+ | --------------------------------------- | ------------------------------------------------------------- |
82
+ | `runReactants(reactants, maxProducts?)` | Run the reaction on a set of reactants. Returns product sets. |
83
+ | `getSvg(options?)` | Render the reaction as SVG. |
84
+ | `drawToCanvas(canvas, ...)` | Draw the reaction to an HTML canvas. |
85
+
86
+ ## Memory Management
87
+
88
+ RDKit objects live in WASM memory and **must** be freed explicitly to avoid leaks. Call `.delete()` on every `Mol`, `MolArray`, and `Reaction` when you are done with it.
89
+
90
+ ```ts
91
+ const mol = rdkit.getMol('CCO');
92
+ // ... use mol ...
93
+ mol?.delete();
94
+ ```
95
+
96
+ All classes also implement the `Disposable` interface. In environments that support `using` declarations (Node.js 22+, or TypeScript with downlevel emit), you can let scope exit handle cleanup automatically — note that this is not yet widely supported in browsers.
97
+
98
+ ```ts
99
+ using mol = rdkit.getMol('CCO')!;
100
+ // mol is deleted automatically when the scope exits
101
+ ```
102
+
103
+ ## Development
104
+
105
+ ```bash
106
+ # Install dependencies
107
+ pnpm install
108
+
109
+ # Run the unit tests
110
+ pnpm test
111
+
112
+ # Build for distribution
113
+ pnpm build
114
+
115
+ # Type-check
116
+ pnpm typecheck
117
+
118
+ # Format code
119
+ pnpm fmt
120
+ ```
121
+
122
+ ### Upgrading RDKit MinimalLib
123
+
124
+ The `MinimalLib/` directory contains a copy of the RDKit MinimalLib compilation output. To upgrade to a newer RDKit version, replace the contents of `MinimalLib/dist/` with the WASM and JS files from the new build.
125
+
126
+ ## License
127
+
128
+ [MIT](LICENSE)
Binary file