rdkit-esm 0.5.1 → 0.6.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/README.md +48 -39
- package/dist/index.d.ts +314 -57
- package/dist/index.js +347 -92
- package/package.json +2 -2
package/README.md
CHANGED
|
@@ -2,23 +2,34 @@
|
|
|
2
2
|
|
|
3
3
|
RDKit minimal lib for the modern web.
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
## About
|
|
6
|
+
|
|
7
|
+
> A scientific library for Cheminformatics (depict, search, compare, process molecular data). Same features as the RDKit.js library, distributed as a standard ES module for modern development environments (install from npm, import in your code). Type safety for every method and parameters, autocomplete and documentation in your IDE.
|
|
8
|
+
|
|
9
|
+
RDKit ESM is a wrapper around [RDKit-js](https://www.rdkitjs.com/), the official JavaScript distribution of RDKit's main functionalities.
|
|
10
|
+
Based on the same MinimalLib Web Assembly (WASM) binary, it simplifies writing code by wrapping all the conversions for the user: no need for 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. No need to build specific object like MolList: regular JS arrays of Mol objects can be used instead.
|
|
11
|
+
|
|
12
|
+

|
|
6
13
|
|
|
7
14
|
**Features:** molecule parsing, substructure search, molecular descriptors, fingerprints (Morgan, MACCS, pattern, ...), reactions, Maximum Common Substructure, R-group decomposition, SVG and Canvas rendering.
|
|
8
15
|
|
|
9
16
|
## Acknowledgment
|
|
10
17
|
|
|
11
|
-
This library is based on the RDKit project and
|
|
12
|
-
in particular Michel Moreau and Paolo Tosco for maintaining the MinimalLib and the RDKit-js distribution. The
|
|
13
|
-
definitions
|
|
18
|
+
This library is based on the RDKit project and its RDKit-js distribution. We thank the RDKit community for their contributions,
|
|
19
|
+
in particular Michel Moreau and Paolo Tosco for maintaining the MinimalLib and the RDKit-js distribution. The original types
|
|
20
|
+
definitions in RDKit-js had been written by Ádám Baróthi.
|
|
14
21
|
|
|
15
|
-
|
|
22
|
+
The examples in this repository and the unit-tests are based on the code and the data in the MinimalLib repository, written mostly by Greg Landrum and Paolo Tosco.
|
|
23
|
+
|
|
24
|
+
## Quick Start
|
|
25
|
+
|
|
26
|
+
### Installation
|
|
16
27
|
|
|
17
28
|
```bash
|
|
18
29
|
npm install rdkit-esm
|
|
19
30
|
```
|
|
20
31
|
|
|
21
|
-
|
|
32
|
+
### Usage
|
|
22
33
|
|
|
23
34
|
```ts
|
|
24
35
|
import { initRDKit } from 'rdkit-esm';
|
|
@@ -36,6 +47,26 @@ if (mol) {
|
|
|
36
47
|
}
|
|
37
48
|
```
|
|
38
49
|
|
|
50
|
+
### Important note about code bundling
|
|
51
|
+
|
|
52
|
+
If your application deployment involves a build step, the bundler requires a hint about
|
|
53
|
+
the WASM binary file location, so that it gets copied with the other assets (such as images).
|
|
54
|
+
The code will vary depending on your bundler.
|
|
55
|
+
|
|
56
|
+
With Vite.js, the initialization code will look like:
|
|
57
|
+
|
|
58
|
+
```ts
|
|
59
|
+
import { initRDKit } from 'rdkit-esm';
|
|
60
|
+
import wasmUrl from 'rdkit-esm/dist/RDKit_minimal.wasm?url'; // the `?url` part is a directive for rolldown wasm plugin
|
|
61
|
+
|
|
62
|
+
// Pass the `locateFile` function which returns the path where the WASM is located
|
|
63
|
+
// During the build process, Vite will replace it with the path to the assets directory
|
|
64
|
+
// where the WASM file has been copied to
|
|
65
|
+
const rdkit = await initRDKit({ locateFile: () => wasmUrl });
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
Note that using a distribution as a WASM file is the most efficient (can be compressed by the server and is processed more rapidly by the browser than a base64 encoded string).
|
|
69
|
+
|
|
39
70
|
## API Overview
|
|
40
71
|
|
|
41
72
|
### `initRDKit(options?): Promise<RDKit>`
|
|
@@ -46,16 +77,17 @@ Loads the WASM module and returns the main interface. **Must be awaited** before
|
|
|
46
77
|
|
|
47
78
|
The main entry point for creating molecules, reactions, and collections.
|
|
48
79
|
|
|
49
|
-
| Method | Description
|
|
50
|
-
| ----------------------------------- |
|
|
51
|
-
| `getMol(input, options?)` | Create a `Mol` from SMILES,
|
|
52
|
-
| `getQMol(input)` | Create a query `Mol` from a SMARTS string or a query
|
|
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
|
-
| `
|
|
80
|
+
| Method | Description |
|
|
81
|
+
| ----------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
82
|
+
| `getMol(input, options?)` | Create a `Mol` from strings (SMILES, V2000/V3000 Mol, CXSMILES), commonchem/RDKit JSON, RDKit pickle (as a Uint8Array). Returns `null` on invalid input or throws with the reason if `{ throwOnError }` is passed |
|
|
83
|
+
| `getQMol(input)` | Create a query `Mol` from a SMARTS string or a query Mol File. |
|
|
84
|
+
| `getRxn(input, options?)` | Create a `Reaction` from reaction SMARTS, SMILES, or an RXN block. |
|
|
85
|
+
| `getMCS(mols, options?)` | Compute the Maximum Common Substructure across a set of molecules (`Mol[]` or `string[]`). |
|
|
86
|
+
| `getRGD(core, molecules, options?)` | R-Group Decomposition against one or more core structures (`Mol`, `Mol[]`, `string` or `string[]`). |
|
|
87
|
+
| `molzip(mol1, mol2)` | Combine two molecules using matching RGroups, labels, etc... |
|
|
88
|
+
| `version` | RDKit version string. |
|
|
89
|
+
| `createSubstructLibrary` | Returns a Substructure Library wrapper for optimized substructure searches |
|
|
90
|
+
| `configure(options)` | General configuration options for the library, including `enableLogging` |
|
|
59
91
|
|
|
60
92
|
### `Mol`
|
|
61
93
|
|
|
@@ -100,29 +132,6 @@ using mol = rdkit.getMol('CCO')!;
|
|
|
100
132
|
// mol is deleted automatically when the scope exits
|
|
101
133
|
```
|
|
102
134
|
|
|
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
135
|
## License
|
|
127
136
|
|
|
128
137
|
[MIT](LICENSE)
|
package/dist/index.d.ts
CHANGED
|
@@ -291,7 +291,7 @@ interface JSMol {
|
|
|
291
291
|
/** Returns the V2000 Molfile representation of the kekule form of the molecule */
|
|
292
292
|
get_kekule_form(): string;
|
|
293
293
|
/** Returns the disconnected fragments of the molecule */
|
|
294
|
-
get_frags(): {
|
|
294
|
+
get_frags(details_json?: string): {
|
|
295
295
|
mappings: JSONString;
|
|
296
296
|
molList: MolList;
|
|
297
297
|
};
|
|
@@ -548,6 +548,8 @@ interface SubstructLibrary {
|
|
|
548
548
|
* @param maxResults maximum number of results
|
|
549
549
|
*/
|
|
550
550
|
get_matches_as_uint32array(q: JSMol, useChirality: boolean, numThreads: number, maxResults: number): Uint32Array;
|
|
551
|
+
delete(): void;
|
|
552
|
+
isDeleted(): boolean;
|
|
551
553
|
}
|
|
552
554
|
interface MolList {
|
|
553
555
|
/**
|
|
@@ -608,7 +610,7 @@ interface StringList extends EmscriptenVector<string> {}
|
|
|
608
610
|
/** Returns a new SubstructLibrary instance */
|
|
609
611
|
interface SubstructLibraryConstructor {
|
|
610
612
|
new (): SubstructLibrary;
|
|
611
|
-
new (
|
|
613
|
+
new (numBits: number): SubstructLibrary;
|
|
612
614
|
}
|
|
613
615
|
interface MolListConstructor {
|
|
614
616
|
new (): MolList;
|
|
@@ -616,12 +618,8 @@ interface MolListConstructor {
|
|
|
616
618
|
interface RGroupDecomposition {
|
|
617
619
|
add(mol: JSMol): number;
|
|
618
620
|
process(): boolean;
|
|
619
|
-
get_rgroups_as_columns(): {
|
|
620
|
-
|
|
621
|
-
};
|
|
622
|
-
get_rgroups_as_rows(): {
|
|
623
|
-
[key: 'Core' | `R${number}`]: JSMol;
|
|
624
|
-
}[];
|
|
621
|
+
get_rgroups_as_columns(): { [key in 'Core' | `R${number}`]: MolList };
|
|
622
|
+
get_rgroups_as_rows(): { [key in 'Core' | `R${number}`]: JSMol }[];
|
|
625
623
|
delete(): void;
|
|
626
624
|
}
|
|
627
625
|
/** The main RDKit module */
|
|
@@ -802,6 +800,11 @@ type DrawColour = [number, number, number, number?];
|
|
|
802
800
|
type ColourPalette = {
|
|
803
801
|
[k: number]: DrawColour;
|
|
804
802
|
};
|
|
803
|
+
type ColourPaletteName = 'default' | 'avalon' | 'cdk' | 'darkmode' | 'bw';
|
|
804
|
+
/** Flags controlling which elements are included when computing drawing extents.
|
|
805
|
+
* Each key corresponds to a DrawElement enum value; `true` includes it, `false` excludes it.
|
|
806
|
+
* Example: `{ ALL: true, HIGHLIGHTS: false }` includes everything except highlights. */
|
|
807
|
+
type DrawingExtentsInclude = Partial<Record<'NONE' | 'PRESHAPES' | 'BONDS' | 'ATOMLABELS' | 'HIGHLIGHTS' | 'ANNOTATIONS' | 'RADICALS' | 'POSTSHAPES' | 'ALL', boolean>>;
|
|
805
808
|
type RDKitDepictionDetails = {
|
|
806
809
|
/** Drawing width in pixels */width: number; /** Drawing height in pixels */
|
|
807
810
|
height: number; /** X offset for drawing origin in pixels */
|
|
@@ -845,7 +848,7 @@ type RDKitDepictionDetails = {
|
|
|
845
848
|
highlightBondWidthMultiplier: number; /** Call prepareMolForDrawing() on each molecule passed to drawMolecules() */
|
|
846
849
|
prepareMolsBeforeDrawing: boolean; /** Defines 10 default colors for highlighting atoms and bonds or reactants in reactions */
|
|
847
850
|
highlightColourPalette: DrawColour[]; /** The palette used to assign colors to atoms based on atomic number */
|
|
848
|
-
atomColourPalette: ColourPalette; /** Fixes scale to this fraction of draw window width so an average bond is this fraction of the width; -1.0 means no fix */
|
|
851
|
+
atomColourPalette: ColourPalette | ColourPaletteName; /** Fixes scale to this fraction of draw window width so an average bond is this fraction of the width; -1.0 means no fix */
|
|
849
852
|
fixedScale: number; /** Fixes the bond length (and hence the scale) to always be this number of pixels; -1.0 means no fix. If both fixedScale and fixedBondLength are > 0, fixedScale wins */
|
|
850
853
|
fixedBondLength: number; /** Angle in degrees to rotate coords by about centre before drawing */
|
|
851
854
|
rotate: number; /** Adds atom indices to drawings */
|
|
@@ -857,8 +860,11 @@ type RDKitDepictionDetails = {
|
|
|
857
860
|
showAllCIPCodes: boolean; /** Forces atom highlights always to be circles; default (false) puts ellipses round longer labels */
|
|
858
861
|
atomHighlightsAreCircles: boolean; /** Highlight style for multi-colour highlights */
|
|
859
862
|
multiColourHighlightStyle: 'CIRCLEANDLINE' | 'LASSO'; /** Moves the centre of the drawn molecule to (0,0) */
|
|
860
|
-
centreMoleculesBeforeDrawing: boolean;
|
|
861
|
-
|
|
863
|
+
centreMoleculesBeforeDrawing: boolean;
|
|
864
|
+
/** Which elements should be included when computing drawing extents.
|
|
865
|
+
* Pass an object with DrawElement flag names as keys and boolean values.
|
|
866
|
+
* Example: `{ ALL: true, HIGHLIGHTS: false }` = include everything except highlights. */
|
|
867
|
+
drawingExtentsInclude: DrawingExtentsInclude; /** Draw terminal methyl and related groups as CH3 */
|
|
862
868
|
explicitMethyl: boolean; /** Include radicals in the drawing; can be useful to turn off for reactions and queries */
|
|
863
869
|
includeRadicals: boolean; /** When possible, include metadata about molecules and reactions in the output to allow them to be reconstructed */
|
|
864
870
|
includeMetadata: boolean; /** Simulate hand-drawn lines for bonds; when combined with a font like Comic-Sans or Comic-Neue, gives xkcd-like drawings */
|
|
@@ -879,7 +885,8 @@ type RDKitDepictionDetails = {
|
|
|
879
885
|
atoms: number[]; /** Bond indices to highlight */
|
|
880
886
|
bonds: number[]; /** Per-atom highlight colors, keyed by atom index */
|
|
881
887
|
highlightAtomColors: Record<number, DrawColour>; /** Per-bond highlight colors, keyed by bond index */
|
|
882
|
-
highlightBondColors: Record<number, DrawColour>; /**
|
|
888
|
+
highlightBondColors: Record<number, DrawColour>; /** Per-atom highlight radii, keyed by atom index */
|
|
889
|
+
highlightAtomRadii: Record<number, number>; /** If true, highlighted hetero atoms are drawn in standard colours rather than black */
|
|
883
890
|
standardColoursForHighlightedAtoms: boolean; // Drawing call parameters (parsed from the details JSON by common.h, not part of MolDrawOptions)
|
|
884
891
|
/** Caption text to display below the molecule (distinct from legendFontSize/legendColour which control its appearance) */
|
|
885
892
|
legend: string; /** Panel width in pixels for multi-panel or grid drawings */
|
|
@@ -916,19 +923,36 @@ type RDKitSubstructMatch = {
|
|
|
916
923
|
atoms: number[];
|
|
917
924
|
bonds: number[];
|
|
918
925
|
};
|
|
926
|
+
/**
|
|
927
|
+
* Flags controlling which sanitization steps are run when `sanitize` is an object.
|
|
928
|
+
* Each key corresponds to a `MolOps::SanitizeFlags` enum value; `true` enables it,
|
|
929
|
+
* `false` disables it. Omitted keys are left at their default (all enabled).
|
|
930
|
+
* Example: `{ SANITIZE_KEKULIZE: false }` runs all steps except kekulization.
|
|
931
|
+
*/
|
|
932
|
+
type RDKitSanitizeFlags = Partial<Record<'SANITIZE_NONE' | 'SANITIZE_CLEANUP' | 'SANITIZE_PROPERTIES' | 'SANITIZE_SYMMRINGS' | 'SANITIZE_KEKULIZE' | 'SANITIZE_FINDRADICALS' | 'SANITIZE_SETAROMATICITY' | 'SANITIZE_SETCONJUGATION' | 'SANITIZE_SETHYBRIDIZATION' | 'SANITIZE_CLEANUPCHIRALITY' | 'SANITIZE_ADJUSTHS' | 'SANITIZE_CLEANUP_ORGANOMETALLICS' | 'SANITIZE_CLEANUPATROPISOMERS' | 'SANITIZE_ALL', boolean>>;
|
|
919
933
|
type RDKitGetMolOpt = {
|
|
920
934
|
kekulize: boolean;
|
|
921
935
|
setAromaticity: boolean;
|
|
922
936
|
fastFindRings: boolean;
|
|
923
937
|
mappedDummiesAreRGroups: boolean;
|
|
924
|
-
|
|
938
|
+
/**
|
|
939
|
+
* `true`/`false` to fully enable/disable sanitization, or a `RDKitSanitizeFlags`
|
|
940
|
+
* object for partial sanitization (selectively enable/disable individual steps).
|
|
941
|
+
* @default true
|
|
942
|
+
*/
|
|
943
|
+
sanitize: boolean | RDKitSanitizeFlags;
|
|
925
944
|
removeHs: boolean;
|
|
926
945
|
assignStereo: boolean;
|
|
927
|
-
mergeQueryHs: boolean;
|
|
946
|
+
mergeQueryHs: boolean;
|
|
947
|
+
assignCIPLabels: boolean; /** Assign chiral types from molfile parity flags */
|
|
928
948
|
assignChiralTypesFromMolParity: boolean; /** Convert mapped dummy atoms to query atoms */
|
|
929
949
|
makeDummiesQueries: boolean; /** Apply strict parsing rules to CXSMILES input */
|
|
930
|
-
strictCXSMILES: boolean; /** Apply strict parsing rules to Molfile input */
|
|
931
|
-
strictParsing: boolean;
|
|
950
|
+
strictCXSMILES: boolean; /** Apply strict parsing rules to Molfile input (molblock input only) */
|
|
951
|
+
strictParsing: boolean; /** Parse aromatic bond type from RDKit JSON input (RDKit JSON input only) */
|
|
952
|
+
setAromaticBonds: boolean; /** Apply strict valence check when parsing RDKit JSON input (RDKit JSON input only) */
|
|
953
|
+
strictValenceCheck: boolean; /** Parse molecule properties from RDKit JSON input (RDKit JSON input only) */
|
|
954
|
+
parseProperties: boolean; /** Parse conformers from RDKit JSON input (RDKit JSON input only) */
|
|
955
|
+
parseConformers: boolean;
|
|
932
956
|
};
|
|
933
957
|
type RDKitGetMolBlockOptions = {
|
|
934
958
|
/** @default true */includeStereo: boolean; /** @default true */
|
|
@@ -986,10 +1010,6 @@ type RDKitGetMCSOptions = {
|
|
|
986
1010
|
AtomRingMatchesRingOnly: boolean;
|
|
987
1011
|
BondRingMatchesRingOnly: boolean;
|
|
988
1012
|
MaxDistance: number;
|
|
989
|
-
/**
|
|
990
|
-
* @alias BondCompleteRingsOnly
|
|
991
|
-
*/
|
|
992
|
-
CompleteRingsOnly: boolean;
|
|
993
1013
|
AtomCompleteRingsOnly: boolean;
|
|
994
1014
|
BondCompleteRingsOnly: boolean;
|
|
995
1015
|
/**
|
|
@@ -1107,6 +1127,10 @@ type RDKitGetRgdOptions = {
|
|
|
1107
1127
|
timeout: number;
|
|
1108
1128
|
chunkSize: number;
|
|
1109
1129
|
};
|
|
1130
|
+
type RDKitGetFragsOptions = {
|
|
1131
|
+
/** Whether to sanitize the fragment molecules. @default true */sanitizeFrags: boolean; /** Whether to copy conformers to the fragment molecules. @default true */
|
|
1132
|
+
copyConformers: boolean;
|
|
1133
|
+
};
|
|
1110
1134
|
//#endregion
|
|
1111
1135
|
//#region src/mol-array.d.ts
|
|
1112
1136
|
/**
|
|
@@ -1167,6 +1191,50 @@ type RDKitGetQMolOptions = {
|
|
|
1167
1191
|
type RDKitGetRxnOptions = RDKitRxnDetails & {
|
|
1168
1192
|
throwOnError: boolean;
|
|
1169
1193
|
};
|
|
1194
|
+
type RDKitMmpaFragsOptions = {
|
|
1195
|
+
/** Minimum number of bonds to simultaneously cut. */minCuts: number; /** Maximum number of bonds to simultaneously cut. */
|
|
1196
|
+
maxCuts: number;
|
|
1197
|
+
/**
|
|
1198
|
+
* Fragmentation is aborted when the molecule has more cuttable bonds
|
|
1199
|
+
* than this limit. Prevents combinatorial explosion on highly connected molecules.
|
|
1200
|
+
*/
|
|
1201
|
+
fragmentableBondLimit: number;
|
|
1202
|
+
};
|
|
1203
|
+
type SubstructLibraryOptions = {
|
|
1204
|
+
/**
|
|
1205
|
+
* Pattern fingerprint bit size for pre-screening.
|
|
1206
|
+
* Larger values reduce false positives at the cost of memory.
|
|
1207
|
+
* Ignored if `disableFingerprints` is true.
|
|
1208
|
+
* Default: WASM default (2048).
|
|
1209
|
+
*/
|
|
1210
|
+
nBits?: number;
|
|
1211
|
+
/**
|
|
1212
|
+
* Disable fingerprint pre-screening (brute-force matching only).
|
|
1213
|
+
* Overrides `nBits`. Useful for tiny libraries or testing.
|
|
1214
|
+
* Internally passes `numBits=0` to the WASM constructor.
|
|
1215
|
+
*/
|
|
1216
|
+
disableFingerprints?: boolean;
|
|
1217
|
+
};
|
|
1218
|
+
type SubstructLibraryAddOptions = {
|
|
1219
|
+
/**
|
|
1220
|
+
* Skip SMILES validation and sanitization.
|
|
1221
|
+
* Use only with RDKit-canonical SMILES strings (e.g. from a previous `getSmiles()` call).
|
|
1222
|
+
* Improves add performance on large libraries.
|
|
1223
|
+
*/
|
|
1224
|
+
trusted?: boolean;
|
|
1225
|
+
};
|
|
1226
|
+
type SubstructLibrarySearchOptions = {
|
|
1227
|
+
/**
|
|
1228
|
+
* Enable chiral substructure searching.
|
|
1229
|
+
* Default: false
|
|
1230
|
+
*/
|
|
1231
|
+
useChirality?: boolean;
|
|
1232
|
+
/**
|
|
1233
|
+
* Stop after finding this many matches.
|
|
1234
|
+
* Default: no limit.
|
|
1235
|
+
*/
|
|
1236
|
+
maxResults?: number;
|
|
1237
|
+
};
|
|
1170
1238
|
type RDKitCondenseAbbreviationsOptions = {
|
|
1171
1239
|
/** @default 0.4 */maxCoverage: number; /** @default false */
|
|
1172
1240
|
useLinkers: boolean;
|
|
@@ -1174,7 +1242,12 @@ type RDKitCondenseAbbreviationsOptions = {
|
|
|
1174
1242
|
//#endregion
|
|
1175
1243
|
//#region src/fingerprints/fingerprints.types.d.ts
|
|
1176
1244
|
type FingerprintType = 'Morgan' | 'Pattern' | 'AtomPair' | 'TopologicalTorsion' | 'RDKit' | 'MACCS';
|
|
1177
|
-
type SimilarityMetric = 'tanimoto';
|
|
1245
|
+
type SimilarityMetric = 'tanimoto' | 'dice' | 'cosine' | 'tversky' | 'asymmetric';
|
|
1246
|
+
/** Options for Tversky similarity. `alpha` weights molecule A's unique bits, `beta` weights molecule B's. */
|
|
1247
|
+
type TverskySimilarityOptions = {
|
|
1248
|
+
alpha: number;
|
|
1249
|
+
beta: number;
|
|
1250
|
+
};
|
|
1178
1251
|
//#endregion
|
|
1179
1252
|
//#region src/fingerprints/fingerprint.d.ts
|
|
1180
1253
|
declare class Fingerprint {
|
|
@@ -1190,6 +1263,32 @@ declare class Fingerprint {
|
|
|
1190
1263
|
}
|
|
1191
1264
|
//#endregion
|
|
1192
1265
|
//#region src/mol.d.ts
|
|
1266
|
+
type MMPAFragmentation = {
|
|
1267
|
+
/**
|
|
1268
|
+
* Core fragment with dummy atoms ([*:n]) at cut points.
|
|
1269
|
+
*
|
|
1270
|
+
* @remarks For single-cut fragmentations, this is the largest fragment
|
|
1271
|
+
* after splitting the combined sidechains mol. This differs from the
|
|
1272
|
+
* raw RDKit result, which returns no core for single-cut pairs.
|
|
1273
|
+
*/
|
|
1274
|
+
core: Mol;
|
|
1275
|
+
/**
|
|
1276
|
+
* Sidechains fragment with dummy atoms ([*:n]) at cut points.
|
|
1277
|
+
* For 2+ cut, this is the combined sidechains mol returned by RDKit.
|
|
1278
|
+
* For single-cut, this is the smallest fragment after splitting.
|
|
1279
|
+
* Distinct sidechains can be obtained with `sidechains.getFrags()`.
|
|
1280
|
+
* `molzip(core, sidechains)` reconstructs the original molecule.
|
|
1281
|
+
*/
|
|
1282
|
+
sidechains: Mol;
|
|
1283
|
+
};
|
|
1284
|
+
type RDKitMmpaFragsResult = {
|
|
1285
|
+
/** Core fragments. */cores: MolArray; /** Sidechains fragments. */
|
|
1286
|
+
sidechains: MolArray; /** Number of fragmentations. */
|
|
1287
|
+
readonly length: number; /** Iterate over fragmentations by index. */
|
|
1288
|
+
[Symbol.iterator](): Iterator<MMPAFragmentation>;
|
|
1289
|
+
delete(): void;
|
|
1290
|
+
[Symbol.dispose](): void;
|
|
1291
|
+
};
|
|
1193
1292
|
/**
|
|
1194
1293
|
* A wrapper around RDKit's JSMol object providing a typed, camelCase API.
|
|
1195
1294
|
*
|
|
@@ -1205,7 +1304,8 @@ declare class Fingerprint {
|
|
|
1205
1304
|
* ```
|
|
1206
1305
|
*/
|
|
1207
1306
|
declare class Mol implements Disposable {
|
|
1208
|
-
|
|
1307
|
+
protected _jsMol: JSMol | null;
|
|
1308
|
+
protected module: RDKitModule;
|
|
1209
1309
|
constructor(jsMol: JSMol, module: RDKitModule);
|
|
1210
1310
|
/**
|
|
1211
1311
|
* The underlying JSMol object for direct access to the raw API.
|
|
@@ -1220,11 +1320,11 @@ declare class Mol implements Disposable {
|
|
|
1220
1320
|
*/
|
|
1221
1321
|
private resolveQuery;
|
|
1222
1322
|
/** Returns the canonical SMILES string */
|
|
1223
|
-
getSmiles(options?: RDKitGetSmilesOptions): string;
|
|
1323
|
+
getSmiles(options?: Partial<RDKitGetSmilesOptions>): string;
|
|
1224
1324
|
/** Returns the Chemaxon Extended SMILES string */
|
|
1225
1325
|
getCxSmiles(options?: Partial<RDKitGetCxSmilesOptions>): string;
|
|
1226
1326
|
/** Returns the SMARTS string */
|
|
1227
|
-
getSmarts(options?: RDKitGetSmilesOptions): string;
|
|
1327
|
+
getSmarts(options?: Partial<RDKitGetSmilesOptions>): string;
|
|
1228
1328
|
/** Returns the Chemaxon Extended SMARTS string */
|
|
1229
1329
|
getCxSmarts(options?: Partial<RDKitGetCxSmilesOptions>): string;
|
|
1230
1330
|
/**
|
|
@@ -1426,7 +1526,7 @@ declare class Mol implements Disposable {
|
|
|
1426
1526
|
* manually deleted by the caller to avoid memory leaks.
|
|
1427
1527
|
* @returns An object with atom/fragment mappings and a `MolArray` of fragments
|
|
1428
1528
|
*/
|
|
1429
|
-
getFrags(): {
|
|
1529
|
+
getFrags(options?: Partial<RDKitGetFragsOptions>): {
|
|
1430
1530
|
mappings: {
|
|
1431
1531
|
atomToFrag: number[];
|
|
1432
1532
|
fragToAtoms: number[][];
|
|
@@ -1435,6 +1535,19 @@ declare class Mol implements Disposable {
|
|
|
1435
1535
|
delete: () => void;
|
|
1436
1536
|
[Symbol.dispose](): void;
|
|
1437
1537
|
};
|
|
1538
|
+
/**
|
|
1539
|
+
* Performs MMPA (Matched Molecular Pairs Analysis) fragmentation.
|
|
1540
|
+
*
|
|
1541
|
+
* Each fragmentation yields a `core` and `sidechains` mol, both with dummy
|
|
1542
|
+
* atoms ([*:n]) at cut points. `mol.zipWith(fragmentation.sidechain, fragmentation.core)`
|
|
1543
|
+
* reconstructs the original molecule.
|
|
1544
|
+
*
|
|
1545
|
+
* @throws If `minCuts < 1` or `maxCuts < minCuts`.
|
|
1546
|
+
*
|
|
1547
|
+
* @warning The returned `RDKitMmpaFragsResult` contains new `Mol` instances
|
|
1548
|
+
* that must be deleted by the caller to avoid memory leaks.
|
|
1549
|
+
*/
|
|
1550
|
+
getMmpaFrags(options: RDKitMmpaFragsOptions): RDKitMmpaFragsResult;
|
|
1438
1551
|
/** Returns a copy of the molecule */
|
|
1439
1552
|
copy(): Mol;
|
|
1440
1553
|
/** Returns true if the underlying C++ object has been deleted */
|
|
@@ -1463,7 +1576,8 @@ declare class Mol implements Disposable {
|
|
|
1463
1576
|
* ```
|
|
1464
1577
|
*/
|
|
1465
1578
|
declare class Reaction implements Disposable {
|
|
1466
|
-
|
|
1579
|
+
protected _jsReaction: JSReaction | null;
|
|
1580
|
+
protected module: RDKitModule;
|
|
1467
1581
|
constructor(jsReaction: JSReaction, module: RDKitModule);
|
|
1468
1582
|
/**
|
|
1469
1583
|
* The underlying JSReaction object for direct access to the raw API.
|
|
@@ -1509,15 +1623,171 @@ declare class Reaction implements Disposable {
|
|
|
1509
1623
|
[Symbol.dispose](): void;
|
|
1510
1624
|
}
|
|
1511
1625
|
//#endregion
|
|
1626
|
+
//#region src/substruct-library.d.ts
|
|
1627
|
+
type SubstructLibraryEntry = {
|
|
1628
|
+
/** Index in the library */index: number; /** RDKit-canonical SMILES */
|
|
1629
|
+
smiles: string; /** Pattern fingerprint used for pre-screening */
|
|
1630
|
+
patternFp: Fingerprint;
|
|
1631
|
+
/**
|
|
1632
|
+
* Lazily creates a Mol from the stored SMILES.
|
|
1633
|
+
* Returns null if the molecule is invalid.
|
|
1634
|
+
*
|
|
1635
|
+
* **WARNING:** The caller is responsible for explicitly deleting this
|
|
1636
|
+
* object (via `.delete()` or `using`) to avoid memory leaks.
|
|
1637
|
+
*/
|
|
1638
|
+
get mol(): Mol | null;
|
|
1639
|
+
delete(): void;
|
|
1640
|
+
[Symbol.dispose](): void;
|
|
1641
|
+
};
|
|
1642
|
+
/** Result of a {@link SubstructLibraryWrapper.getMatches} call */
|
|
1643
|
+
type SubstructLibrarySearchResult = {
|
|
1644
|
+
/** Matching molecule indices */readonly indices: Uint32Array; /** Number of matches (same as `indices.length`) */
|
|
1645
|
+
readonly count: number; /** Iterate over the matching library entries */
|
|
1646
|
+
[Symbol.iterator](): Iterator<SubstructLibraryEntry>;
|
|
1647
|
+
};
|
|
1648
|
+
/**
|
|
1649
|
+
* A collection of molecules for efficient batch substructure searching.
|
|
1650
|
+
*
|
|
1651
|
+
* Molecules are stored as canonical SMILES with pre-computed pattern
|
|
1652
|
+
* fingerprints used to pre-screen candidates before full substructure matching.
|
|
1653
|
+
*
|
|
1654
|
+
* @example
|
|
1655
|
+
* ```ts
|
|
1656
|
+
* using lib = rdkit.createSubstructLibrary();
|
|
1657
|
+
* for (const smi of smilesList) lib.add(smi);
|
|
1658
|
+
* const result = lib.getMatches('C1CCCCN1');
|
|
1659
|
+
* console.log(result.count, Array.from(result.indices));
|
|
1660
|
+
* ```
|
|
1661
|
+
*/
|
|
1662
|
+
declare class SubstructLibraryWrapper implements Disposable {
|
|
1663
|
+
protected readonly lib: SubstructLibrary;
|
|
1664
|
+
protected readonly module: RDKitModule;
|
|
1665
|
+
/** use {@link RDKit.createSubstructLibraryWrapper} */
|
|
1666
|
+
constructor(module: RDKitModule, options?: SubstructLibraryOptions);
|
|
1667
|
+
/**
|
|
1668
|
+
* Add a molecule to the library.
|
|
1669
|
+
* - `Mol` instance: added via `add_mol` (already parsed and sanitized)
|
|
1670
|
+
* - `string`: treated as SMILES; validated unless `options.trusted` is set
|
|
1671
|
+
*
|
|
1672
|
+
* @returns the index of the added molecule, or -1 on failure
|
|
1673
|
+
*/
|
|
1674
|
+
add(mol: Mol | string, options?: SubstructLibraryAddOptions): number;
|
|
1675
|
+
/**
|
|
1676
|
+
* Add a molecule with a pre-computed pattern fingerprint.
|
|
1677
|
+
* Skips both SMILES validation and fingerprint computation.
|
|
1678
|
+
*
|
|
1679
|
+
* @param smiles RDKit-canonical SMILES string
|
|
1680
|
+
* @param fp pre-computed pattern fingerprint (a `Fingerprint` object)
|
|
1681
|
+
* @returns the index of the added molecule
|
|
1682
|
+
*/
|
|
1683
|
+
addPrecomputed(smiles: string, fp: Fingerprint): number;
|
|
1684
|
+
/**
|
|
1685
|
+
* Returns the entry at index `i`: stored SMILES, pattern fingerprint, and a lazy mol getter.
|
|
1686
|
+
*
|
|
1687
|
+
* The `mol` getter lazily allocates a WASM object on first access.
|
|
1688
|
+
* **WARNING:** The caller is responsible for deleting it via `.delete()` or `using`.
|
|
1689
|
+
*
|
|
1690
|
+
* @example Iterate for serialization:
|
|
1691
|
+
* ```ts
|
|
1692
|
+
* for (let i = 0; i < lib.size; i++) {
|
|
1693
|
+
* const { smiles, patternFp } = lib.at(i);
|
|
1694
|
+
* }
|
|
1695
|
+
* ```
|
|
1696
|
+
*/
|
|
1697
|
+
at(i: number): SubstructLibraryEntry;
|
|
1698
|
+
/**
|
|
1699
|
+
* Runs a substructure search and returns a result object with `count`,
|
|
1700
|
+
* `indices`, and an iterator that yields {@link SubstructLibraryEntry} objects.
|
|
1701
|
+
*
|
|
1702
|
+
* @param query `Mol` instance or SMARTS string
|
|
1703
|
+
*/
|
|
1704
|
+
getMatches(query: Mol | string, options?: SubstructLibrarySearchOptions): SubstructLibrarySearchResult;
|
|
1705
|
+
/** Number of molecules in the library */
|
|
1706
|
+
get size(): number;
|
|
1707
|
+
delete(): void;
|
|
1708
|
+
[Symbol.dispose](): void;
|
|
1709
|
+
/** SMARTS strings resolve to a QueryMol that must be deleted internally */
|
|
1710
|
+
private resolveQuery;
|
|
1711
|
+
}
|
|
1712
|
+
//#endregion
|
|
1512
1713
|
//#region src/rgd.d.ts
|
|
1513
1714
|
/**
|
|
1514
1715
|
* A row from R-Group Decomposition, mapping labels like `Core`, `R1`, `R2`, …
|
|
1515
1716
|
* to Mol instances.
|
|
1516
1717
|
*/
|
|
1517
1718
|
type RGDRow = Record<string, Mol>;
|
|
1719
|
+
/**
|
|
1720
|
+
* The result of an R-Group Decomposition, as an array of {@link RGDRow} with
|
|
1721
|
+
* batch lifecycle management.
|
|
1722
|
+
*
|
|
1723
|
+
* Call {@link delete} (or use the `using` keyword) to delete every `Mol`
|
|
1724
|
+
* in all rows at once.
|
|
1725
|
+
*/
|
|
1726
|
+
declare class RGDResult extends Array<RGDRow> implements Disposable {
|
|
1727
|
+
/** Deletes every non-deleted Mol across all rows */
|
|
1728
|
+
delete(): void;
|
|
1729
|
+
/** Disposable support — allows use with the `using` keyword */
|
|
1730
|
+
[Symbol.dispose](): void;
|
|
1731
|
+
}
|
|
1518
1732
|
//#endregion
|
|
1519
1733
|
//#region src/fingerprints/bitops.d.ts
|
|
1520
|
-
declare const computeFingerprintSimilarity: (a: Fingerprint, b: Fingerprint, metric?: SimilarityMetric) => number;
|
|
1734
|
+
declare const computeFingerprintSimilarity: (a: Fingerprint, b: Fingerprint, metric?: SimilarityMetric, options?: TverskySimilarityOptions) => number;
|
|
1735
|
+
//#endregion
|
|
1736
|
+
//#region src/logger.d.ts
|
|
1737
|
+
declare class RDKitParseError extends Error {
|
|
1738
|
+
readonly input: string | Uint8Array;
|
|
1739
|
+
readonly rdkitMessage: string;
|
|
1740
|
+
constructor(input: string | Uint8Array, rdkitMessage: string);
|
|
1741
|
+
}
|
|
1742
|
+
/**
|
|
1743
|
+
* Type guard for RDKitParseError.
|
|
1744
|
+
* @param error The error to check.
|
|
1745
|
+
* @returns True if the error is an instance of RDKitParseError, false otherwise.
|
|
1746
|
+
* @example
|
|
1747
|
+
* ```ts
|
|
1748
|
+
* try {
|
|
1749
|
+
* rdkit.getMol('invalid input', { throwOnError: true });
|
|
1750
|
+
* } catch (e) {
|
|
1751
|
+
* if (isRDKitParseError(e)) {
|
|
1752
|
+
* console.error('Parsing failed for input:', e.input);
|
|
1753
|
+
* console.error('RDKit message:', e.rdkitMessage);
|
|
1754
|
+
* } else {
|
|
1755
|
+
* console.error('Unexpected error:', e);
|
|
1756
|
+
* }
|
|
1757
|
+
* }
|
|
1758
|
+
* ```
|
|
1759
|
+
*/
|
|
1760
|
+
declare const isRDKitParseError: (error: unknown) => error is RDKitParseError;
|
|
1761
|
+
/**
|
|
1762
|
+
* RDKitLogger manages RDKit error capture and dispatch to listeners, as well as optional console logging.
|
|
1763
|
+
*/
|
|
1764
|
+
declare class RDKitLogger {
|
|
1765
|
+
private readonly mod;
|
|
1766
|
+
private capture;
|
|
1767
|
+
private callback;
|
|
1768
|
+
private enableLogging;
|
|
1769
|
+
private throwOnError;
|
|
1770
|
+
constructor(mod: RDKitModule);
|
|
1771
|
+
private activate;
|
|
1772
|
+
/**
|
|
1773
|
+
* Called from configure({ enableLogging }). Switches between tee and capture
|
|
1774
|
+
* if already active; otherwise applies enable/disable_logging for the no-capture case.
|
|
1775
|
+
*/
|
|
1776
|
+
setEnableLogging(enable: boolean): void;
|
|
1777
|
+
/** Single callback slot — replaces any previous. Returns cleanup function. */
|
|
1778
|
+
addCallback(fn: RDKitFailCallback): () => void;
|
|
1779
|
+
/**
|
|
1780
|
+
* Call before each WASM parse operation.
|
|
1781
|
+
* Stores throwOnError state, activates capture if needed, clears the buffer.
|
|
1782
|
+
* Fast path: no-op when neither throwOnError nor capture is active.
|
|
1783
|
+
*/
|
|
1784
|
+
reset(throwOnError: boolean): void;
|
|
1785
|
+
/**
|
|
1786
|
+
* Call on null return from WASM. Reads buffer, fires callback, throws if throwOnError.
|
|
1787
|
+
* No-op when reset() took the fast path (capture still null).
|
|
1788
|
+
*/
|
|
1789
|
+
handleError(input: string | Uint8Array, operation: RDKitParseOperation): void;
|
|
1790
|
+
}
|
|
1521
1791
|
//#endregion
|
|
1522
1792
|
//#region src/rdkit.d.ts
|
|
1523
1793
|
/** Result of a Maximum Common Substructure (MCS) computation */
|
|
@@ -1549,7 +1819,8 @@ interface MCSResult extends Disposable {
|
|
|
1549
1819
|
* ```
|
|
1550
1820
|
*/
|
|
1551
1821
|
declare class RDKit {
|
|
1552
|
-
|
|
1822
|
+
protected readonly mod: RDKitModule;
|
|
1823
|
+
protected readonly logger: RDKitLogger;
|
|
1553
1824
|
readonly events: RDKitEvents;
|
|
1554
1825
|
/** @internal */
|
|
1555
1826
|
constructor(mod: RDKitModule);
|
|
@@ -1609,8 +1880,20 @@ declare class RDKit {
|
|
|
1609
1880
|
* @returns An array of rows, one per molecule. Each row maps R-group labels
|
|
1610
1881
|
* (`Core`, `R1`, `R2`, …) to Mol instances.
|
|
1611
1882
|
*/
|
|
1612
|
-
getRGD(core: string | string[] | Mol | Mol[], molecules: string[] | Mol[], options?: Partial<RDKitGetRgdOptions>):
|
|
1613
|
-
|
|
1883
|
+
getRGD(core: string | string[] | Mol | Mol[], molecules: string[] | Mol[], options?: Partial<RDKitGetRgdOptions>): RGDResult | null;
|
|
1884
|
+
/**
|
|
1885
|
+
* Creates an empty {@link SubstructLibraryWrapper} for batch substructure searching.
|
|
1886
|
+
*
|
|
1887
|
+
* @example
|
|
1888
|
+
* ```ts
|
|
1889
|
+
* using lib = rdkit.createSubstructLibrary();
|
|
1890
|
+
* for (const smi of smilesList) lib.add(smi);
|
|
1891
|
+
* const result = lib.getMatches('C1CCCCN1'); // SMARTS query
|
|
1892
|
+
* console.log(result.count, Array.from(result.indices));
|
|
1893
|
+
* ```
|
|
1894
|
+
*/
|
|
1895
|
+
createSubstructLibrary(options?: SubstructLibraryOptions): SubstructLibraryWrapper;
|
|
1896
|
+
molzip(mol1: Mol, mol2: Mol, options?: Partial<RDKitMolZipOptions>): Mol | null;
|
|
1614
1897
|
computeFingerprintsSimilarity(...args: Parameters<typeof computeFingerprintSimilarity>): number;
|
|
1615
1898
|
/**
|
|
1616
1899
|
* Applies global configuration options to the RDKit module.
|
|
@@ -1665,30 +1948,4 @@ interface InitRDKitOptions {
|
|
|
1665
1948
|
declare function initRDKit(options?: Partial<InitRDKitOptions>): Promise<RDKit>;
|
|
1666
1949
|
declare function initRDKit<T extends typeof RDKit>(options: Partial<InitRDKitOptions> | undefined, constructor: T): Promise<InstanceType<T>>;
|
|
1667
1950
|
//#endregion
|
|
1668
|
-
|
|
1669
|
-
declare class RDKitParseError extends Error {
|
|
1670
|
-
readonly input: string | Uint8Array;
|
|
1671
|
-
readonly rdkitMessage: string;
|
|
1672
|
-
constructor(input: string | Uint8Array, rdkitMessage: string);
|
|
1673
|
-
}
|
|
1674
|
-
/**
|
|
1675
|
-
* Type guard for RDKitParseError.
|
|
1676
|
-
* @param error The error to check.
|
|
1677
|
-
* @returns True if the error is an instance of RDKitParseError, false otherwise.
|
|
1678
|
-
* @example
|
|
1679
|
-
* ```ts
|
|
1680
|
-
* try {
|
|
1681
|
-
* rdkit.getMol('invalid input', { throwOnError: true });
|
|
1682
|
-
* } catch (e) {
|
|
1683
|
-
* if (isRDKitParseError(e)) {
|
|
1684
|
-
* console.error('Parsing failed for input:', e.input);
|
|
1685
|
-
* console.error('RDKit message:', e.rdkitMessage);
|
|
1686
|
-
* } else {
|
|
1687
|
-
* console.error('Unexpected error:', e);
|
|
1688
|
-
* }
|
|
1689
|
-
* }
|
|
1690
|
-
* ```
|
|
1691
|
-
*/
|
|
1692
|
-
declare const isRDKitParseError: (error: unknown) => error is RDKitParseError;
|
|
1693
|
-
//#endregion
|
|
1694
|
-
export { type ColourPalette, type DrawColour, Fingerprint, type InitRDKitOptions, type JSMol, type JSReaction, type MCSResult, Mol, MolArray, type MolList, RDKit, type RDKitAlignedCoordsOptions, type RDKitAtomPairFPOptions, type RDKitConfigureOptions, type RDKitDepictionDetails, type RDKitDescriptors, type RDKitEvents, type RDKitFailCallback, type RDKitGetMCSOptions, type RDKitGetMolBlockOptions, type RDKitGetMolOpt, type RDKitGetMolOptions, type RDKitGetQMolOptions, type RDKitGetRgdOptions, type RDKitGetRxnOptions, type RDKitGetSmilesOptions, type RDKitJson, type RDKitJsonAtom, type RDKitJsonBond, type RDKitJsonConformer2D, type RDKitJsonConformer3D, type RDKitJsonExtension, type RDKitJsonMolecule, type RDKitMCSResult, type RDKitModule, type RDKitMorganFPOptions, RDKitParseError, type RDKitParseErrorEvent, type RDKitParseOperation, type RDKitPatternFPOptions, type RDKitRdkitFpOptions, type RDKitRemoveHsOptions, type RDKitRxnDetails, type RDKitStereoTags, type RDKitSubstructMatch, type RDKitTopologicalTorsionFPOptions, type RGDRow, Reaction, initRDKit, isRDKitParseError };
|
|
1951
|
+
export { type ColourPalette, type ColourPaletteName, type DrawColour, type DrawingExtentsInclude, Fingerprint, type InitRDKitOptions, type JSMol, type JSReaction, type MCSResult, type MMPAFragmentation, Mol, MolArray, type MolList, RDKit, type RDKitAlignedCoordsOptions, type RDKitAtomPairFPOptions, type RDKitConfigureOptions, type RDKitDepictionDetails, type RDKitDescriptors, type RDKitEvents, type RDKitFailCallback, type RDKitGetFragsOptions, type RDKitGetMCSOptions, type RDKitGetMolBlockOptions, type RDKitGetMolOpt, type RDKitGetMolOptions, type RDKitGetQMolOptions, type RDKitGetRgdOptions, type RDKitGetRxnOptions, type RDKitGetSmilesOptions, type RDKitJson, type RDKitJsonAtom, type RDKitJsonBond, type RDKitJsonConformer2D, type RDKitJsonConformer3D, type RDKitJsonExtension, type RDKitJsonMolecule, type RDKitMCSResult, type RDKitMmpaFragsOptions, type RDKitMmpaFragsResult, type RDKitModule, type RDKitMorganFPOptions, RDKitParseError, type RDKitParseErrorEvent, type RDKitParseOperation, type RDKitPatternFPOptions, type RDKitRdkitFpOptions, type RDKitRemoveHsOptions, type RDKitRxnDetails, type RDKitSanitizeFlags, type RDKitStereoTags, type RDKitSubstructMatch, type RDKitTopologicalTorsionFPOptions, type RGDRow, Reaction, type SimilarityMetric, type SubstructLibraryAddOptions, type SubstructLibraryEntry, type SubstructLibraryOptions, type SubstructLibrarySearchOptions, type SubstructLibrarySearchResult, SubstructLibraryWrapper, type TverskySimilarityOptions, initRDKit, isRDKitParseError };
|
package/dist/index.js
CHANGED
|
@@ -3916,17 +3916,50 @@ const hammingWeight = (v) => {
|
|
|
3916
3916
|
v = (v & 858993459) + (v >>> 2 & 858993459);
|
|
3917
3917
|
return (v + (v >>> 4) & 252645135) * 16843009 >>> 24;
|
|
3918
3918
|
};
|
|
3919
|
-
|
|
3919
|
+
/** Count the number of on-bits in the intersection of two fingerprints. */
|
|
3920
|
+
const intersectionSize = (a, b) => {
|
|
3921
|
+
let c = 0;
|
|
3922
|
+
for (let i = 0; i < a.fpU32.length; i++) c += hammingWeight(a.fpU32[i] & b.fpU32[i]);
|
|
3923
|
+
return c;
|
|
3924
|
+
};
|
|
3925
|
+
const computeFingerprintSimilarity = (a, b, metric = "tanimoto", options) => {
|
|
3920
3926
|
if (a.nBits !== b.nBits) throw new Error("Fingerprints must be of the same length");
|
|
3921
3927
|
switch (metric) {
|
|
3922
3928
|
case "tanimoto": return tanimotoSimilarity(a, b);
|
|
3929
|
+
case "dice": return diceSimilarity(a, b);
|
|
3930
|
+
case "cosine": return cosineSimilarity(a, b);
|
|
3931
|
+
case "asymmetric": return asymmetricSimilarity(a, b);
|
|
3932
|
+
case "tversky": {
|
|
3933
|
+
const { alpha = 1, beta = 1 } = options ?? {};
|
|
3934
|
+
return tverskySimilarity(a, b, alpha, beta);
|
|
3935
|
+
}
|
|
3923
3936
|
default: throw new Error(`Unsupported similarity metric: ${metric}`);
|
|
3924
3937
|
}
|
|
3925
3938
|
};
|
|
3926
3939
|
const tanimotoSimilarity = (a, b) => {
|
|
3927
|
-
|
|
3928
|
-
|
|
3929
|
-
|
|
3940
|
+
const c = intersectionSize(a, b);
|
|
3941
|
+
return c / (a.onBits + b.onBits - c);
|
|
3942
|
+
};
|
|
3943
|
+
/** Dice similarity: `2c / (a + b)` */
|
|
3944
|
+
const diceSimilarity = (a, b) => {
|
|
3945
|
+
return 2 * intersectionSize(a, b) / (a.onBits + b.onBits);
|
|
3946
|
+
};
|
|
3947
|
+
/** Cosine similarity: `c / sqrt(a * b)` */
|
|
3948
|
+
const cosineSimilarity = (a, b) => {
|
|
3949
|
+
return intersectionSize(a, b) / Math.sqrt(a.onBits * b.onBits);
|
|
3950
|
+
};
|
|
3951
|
+
/** Asymmetric similarity (containment): `c / min(a, b)` */
|
|
3952
|
+
const asymmetricSimilarity = (a, b) => {
|
|
3953
|
+
return intersectionSize(a, b) / Math.min(a.onBits, b.onBits);
|
|
3954
|
+
};
|
|
3955
|
+
/**
|
|
3956
|
+
* Tversky similarity: `c / (α·a + β·b + (1−α−β)·c)`
|
|
3957
|
+
*
|
|
3958
|
+
* Special cases: Tversky(1,1) = Tanimoto; Tversky(0.5,0.5) = Dice.
|
|
3959
|
+
*/
|
|
3960
|
+
const tverskySimilarity = (a, b, alpha, beta) => {
|
|
3961
|
+
const c = intersectionSize(a, b);
|
|
3962
|
+
return c / (alpha * a.onBits + beta * b.onBits + (1 - alpha - beta) * c);
|
|
3930
3963
|
};
|
|
3931
3964
|
//#endregion
|
|
3932
3965
|
//#region src/fingerprints/fingerprint.ts
|
|
@@ -3979,19 +4012,19 @@ var Fingerprint = class {
|
|
|
3979
4012
|
* ```
|
|
3980
4013
|
*/
|
|
3981
4014
|
var Mol = class Mol {
|
|
3982
|
-
|
|
3983
|
-
|
|
4015
|
+
_jsMol;
|
|
4016
|
+
module;
|
|
3984
4017
|
constructor(jsMol, module) {
|
|
3985
|
-
this
|
|
3986
|
-
this
|
|
4018
|
+
this._jsMol = jsMol;
|
|
4019
|
+
this.module = module;
|
|
3987
4020
|
}
|
|
3988
4021
|
/**
|
|
3989
4022
|
* The underlying JSMol object for direct access to the raw API.
|
|
3990
4023
|
* @throws If the molecule has been deleted.
|
|
3991
4024
|
*/
|
|
3992
4025
|
get jsMol() {
|
|
3993
|
-
if (!this
|
|
3994
|
-
return this
|
|
4026
|
+
if (!this._jsMol) throw new Error("Mol has been deleted");
|
|
4027
|
+
return this._jsMol;
|
|
3995
4028
|
}
|
|
3996
4029
|
/**
|
|
3997
4030
|
* Resolves a substructure query argument to a JSMol.
|
|
@@ -4001,7 +4034,7 @@ var Mol = class Mol {
|
|
|
4001
4034
|
*/
|
|
4002
4035
|
resolveQuery(query) {
|
|
4003
4036
|
if (query instanceof Mol) return [query.jsMol, false];
|
|
4004
|
-
const qmol = this
|
|
4037
|
+
const qmol = this.module.get_qmol(query);
|
|
4005
4038
|
if (!qmol) throw new Error(`Invalid SMARTS query: ${query}`);
|
|
4006
4039
|
return [qmol, true];
|
|
4007
4040
|
}
|
|
@@ -4063,7 +4096,7 @@ var Mol = class Mol {
|
|
|
4063
4096
|
*/
|
|
4064
4097
|
getInchikey(args) {
|
|
4065
4098
|
const inchi = this.getInchi(args);
|
|
4066
|
-
return this
|
|
4099
|
+
return this.module.get_inchikey_for_inchi(inchi);
|
|
4067
4100
|
}
|
|
4068
4101
|
/**
|
|
4069
4102
|
* Returns the serialized JSON representation of the molecule
|
|
@@ -4310,10 +4343,10 @@ var Mol = class Mol {
|
|
|
4310
4343
|
}
|
|
4311
4344
|
zipWith(other, options) {
|
|
4312
4345
|
const mol = this.jsMol;
|
|
4313
|
-
const newMol = options ? this
|
|
4346
|
+
const newMol = options ? this.module.molzip(mol, other.jsMol, JSON.stringify(options)) : this.module.molzip(mol, other.jsMol);
|
|
4314
4347
|
if (!newMol || !newMol.is_valid()) return;
|
|
4315
4348
|
mol.delete();
|
|
4316
|
-
this
|
|
4349
|
+
this._jsMol = newMol;
|
|
4317
4350
|
}
|
|
4318
4351
|
/**
|
|
4319
4352
|
* Generates new 2D coordinates for the molecule
|
|
@@ -4384,13 +4417,13 @@ var Mol = class Mol {
|
|
|
4384
4417
|
* manually deleted by the caller to avoid memory leaks.
|
|
4385
4418
|
* @returns An object with atom/fragment mappings and a `MolArray` of fragments
|
|
4386
4419
|
*/
|
|
4387
|
-
getFrags() {
|
|
4388
|
-
const { mappings, molList } = this.jsMol.get_frags();
|
|
4420
|
+
getFrags(options) {
|
|
4421
|
+
const { mappings, molList } = options ? this.jsMol.get_frags(JSON.stringify(options)) : this.jsMol.get_frags();
|
|
4389
4422
|
const parsed = JSON.parse(mappings);
|
|
4390
4423
|
const mols = new MolArray();
|
|
4391
4424
|
for (let i = 0; i < molList.size(); i++) {
|
|
4392
4425
|
const jsMol = molList.at(i);
|
|
4393
|
-
if (jsMol) mols.push(new Mol(jsMol, this
|
|
4426
|
+
if (jsMol) mols.push(new Mol(jsMol, this.module));
|
|
4394
4427
|
}
|
|
4395
4428
|
molList.delete();
|
|
4396
4429
|
return {
|
|
@@ -4405,13 +4438,85 @@ var Mol = class Mol {
|
|
|
4405
4438
|
}
|
|
4406
4439
|
};
|
|
4407
4440
|
}
|
|
4441
|
+
/**
|
|
4442
|
+
* Performs MMPA (Matched Molecular Pairs Analysis) fragmentation.
|
|
4443
|
+
*
|
|
4444
|
+
* Each fragmentation yields a `core` and `sidechains` mol, both with dummy
|
|
4445
|
+
* atoms ([*:n]) at cut points. `mol.zipWith(fragmentation.sidechain, fragmentation.core)`
|
|
4446
|
+
* reconstructs the original molecule.
|
|
4447
|
+
*
|
|
4448
|
+
* @throws If `minCuts < 1` or `maxCuts < minCuts`.
|
|
4449
|
+
*
|
|
4450
|
+
* @warning The returned `RDKitMmpaFragsResult` contains new `Mol` instances
|
|
4451
|
+
* that must be deleted by the caller to avoid memory leaks.
|
|
4452
|
+
*/
|
|
4453
|
+
getMmpaFrags(options) {
|
|
4454
|
+
const { minCuts, maxCuts, fragmentableBondLimit } = options;
|
|
4455
|
+
if (minCuts < 1) throw new Error("getMmpaFrags: minCuts must be at least 1");
|
|
4456
|
+
if (maxCuts < minCuts) throw new Error(`getMmpaFrags: maxCuts (${maxCuts}) must be >= minCuts (${minCuts})`);
|
|
4457
|
+
const raw = this.jsMol.get_mmpa_frags(minCuts, maxCuts, fragmentableBondLimit);
|
|
4458
|
+
const cores = new MolArray();
|
|
4459
|
+
const sidechains = new MolArray();
|
|
4460
|
+
const fragmentations = [];
|
|
4461
|
+
if (raw?.cores && raw?.sidechains) {
|
|
4462
|
+
const n = raw.cores.size();
|
|
4463
|
+
for (let i = 0; i < n; i++) {
|
|
4464
|
+
const rawCore = raw.cores.at(i);
|
|
4465
|
+
const rawSidechain = raw.sidechains.at(i);
|
|
4466
|
+
if (!rawSidechain) continue;
|
|
4467
|
+
if (rawCore) {
|
|
4468
|
+
const core = new Mol(rawCore, this.module);
|
|
4469
|
+
const sidechain = new Mol(rawSidechain, this.module);
|
|
4470
|
+
cores.push(core);
|
|
4471
|
+
sidechains.push(sidechain);
|
|
4472
|
+
fragmentations.push({
|
|
4473
|
+
core,
|
|
4474
|
+
sidechains: sidechain
|
|
4475
|
+
});
|
|
4476
|
+
} else {
|
|
4477
|
+
const combined = new Mol(rawSidechain, this.module);
|
|
4478
|
+
const { mols: frags } = combined.getFrags();
|
|
4479
|
+
combined.delete();
|
|
4480
|
+
frags.sort((a, b) => b.numAtoms - a.numAtoms);
|
|
4481
|
+
const core = frags[0];
|
|
4482
|
+
const sidechain = frags[1];
|
|
4483
|
+
cores.push(core);
|
|
4484
|
+
sidechains.push(sidechain);
|
|
4485
|
+
fragmentations.push({
|
|
4486
|
+
core,
|
|
4487
|
+
sidechains: sidechain
|
|
4488
|
+
});
|
|
4489
|
+
}
|
|
4490
|
+
}
|
|
4491
|
+
raw.cores.delete();
|
|
4492
|
+
raw.sidechains.delete();
|
|
4493
|
+
}
|
|
4494
|
+
return {
|
|
4495
|
+
cores,
|
|
4496
|
+
sidechains,
|
|
4497
|
+
get length() {
|
|
4498
|
+
return fragmentations.length;
|
|
4499
|
+
},
|
|
4500
|
+
*[Symbol.iterator]() {
|
|
4501
|
+
yield* fragmentations;
|
|
4502
|
+
},
|
|
4503
|
+
delete() {
|
|
4504
|
+
cores.delete();
|
|
4505
|
+
sidechains.delete();
|
|
4506
|
+
},
|
|
4507
|
+
[Symbol.dispose]() {
|
|
4508
|
+
cores.delete();
|
|
4509
|
+
sidechains.delete();
|
|
4510
|
+
}
|
|
4511
|
+
};
|
|
4512
|
+
}
|
|
4408
4513
|
/** Returns a copy of the molecule */
|
|
4409
4514
|
copy() {
|
|
4410
|
-
return new Mol(this.jsMol.copy(), this
|
|
4515
|
+
return new Mol(this.jsMol.copy(), this.module);
|
|
4411
4516
|
}
|
|
4412
4517
|
/** Returns true if the underlying C++ object has been deleted */
|
|
4413
4518
|
get isDeleted() {
|
|
4414
|
-
return this
|
|
4519
|
+
return this._jsMol === null || this._jsMol.isDeleted();
|
|
4415
4520
|
}
|
|
4416
4521
|
/**
|
|
4417
4522
|
* Deletes the underlying C++ molecule object from memory.
|
|
@@ -4419,8 +4524,8 @@ var Mol = class Mol {
|
|
|
4419
4524
|
* @see {@link https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management | Emscripten docs}
|
|
4420
4525
|
*/
|
|
4421
4526
|
delete() {
|
|
4422
|
-
this
|
|
4423
|
-
this
|
|
4527
|
+
this._jsMol?.delete();
|
|
4528
|
+
this._jsMol = null;
|
|
4424
4529
|
}
|
|
4425
4530
|
/** Disposable support — allows use with the `using` keyword */
|
|
4426
4531
|
[Symbol.dispose]() {
|
|
@@ -4442,19 +4547,19 @@ var Mol = class Mol {
|
|
|
4442
4547
|
* ```
|
|
4443
4548
|
*/
|
|
4444
4549
|
var Reaction = class {
|
|
4445
|
-
|
|
4446
|
-
|
|
4550
|
+
_jsReaction;
|
|
4551
|
+
module;
|
|
4447
4552
|
constructor(jsReaction, module) {
|
|
4448
|
-
this
|
|
4449
|
-
this
|
|
4553
|
+
this._jsReaction = jsReaction;
|
|
4554
|
+
this.module = module;
|
|
4450
4555
|
}
|
|
4451
4556
|
/**
|
|
4452
4557
|
* The underlying JSReaction object for direct access to the raw API.
|
|
4453
4558
|
* @throws If the reaction has been deleted.
|
|
4454
4559
|
*/
|
|
4455
4560
|
get jsReaction() {
|
|
4456
|
-
if (!this
|
|
4457
|
-
return this
|
|
4561
|
+
if (!this._jsReaction) throw new Error("Reaction has been deleted");
|
|
4562
|
+
return this._jsReaction;
|
|
4458
4563
|
}
|
|
4459
4564
|
/**
|
|
4460
4565
|
* Runs the reaction on a set of reactants.
|
|
@@ -4473,8 +4578,8 @@ var Reaction = class {
|
|
|
4473
4578
|
*/
|
|
4474
4579
|
runReactants(reactants, maxProducts = 1e3) {
|
|
4475
4580
|
let molList;
|
|
4476
|
-
if (isMolArray(reactants)) molList = fromMolArraytoMolList(reactants, this
|
|
4477
|
-
else molList = fromStringArraytoMolList(reactants, this
|
|
4581
|
+
if (isMolArray(reactants)) molList = fromMolArraytoMolList(reactants, this.module);
|
|
4582
|
+
else molList = fromStringArraytoMolList(reactants, this.module);
|
|
4478
4583
|
const products = this.jsReaction.run_reactants(molList, maxProducts);
|
|
4479
4584
|
molList.delete();
|
|
4480
4585
|
const result = [];
|
|
@@ -4486,7 +4591,7 @@ var Reaction = class {
|
|
|
4486
4591
|
while (!productSet.at_end()) {
|
|
4487
4592
|
const jsMol = productSet.next();
|
|
4488
4593
|
if (!jsMol) break;
|
|
4489
|
-
mols.push(new Mol(jsMol, this
|
|
4594
|
+
mols.push(new Mol(jsMol, this.module));
|
|
4490
4595
|
}
|
|
4491
4596
|
productSet.delete();
|
|
4492
4597
|
result.push(mols);
|
|
@@ -4521,8 +4626,8 @@ var Reaction = class {
|
|
|
4521
4626
|
* @see {@link https://emscripten.org/docs/porting/connecting_cpp_and_javascript/embind.html#memory-management | Emscripten docs}
|
|
4522
4627
|
*/
|
|
4523
4628
|
delete() {
|
|
4524
|
-
this
|
|
4525
|
-
this
|
|
4629
|
+
this._jsReaction?.delete();
|
|
4630
|
+
this._jsReaction = null;
|
|
4526
4631
|
}
|
|
4527
4632
|
/** Disposable support — allows use with the `using` keyword */
|
|
4528
4633
|
[Symbol.dispose]() {
|
|
@@ -4530,6 +4635,142 @@ var Reaction = class {
|
|
|
4530
4635
|
}
|
|
4531
4636
|
};
|
|
4532
4637
|
//#endregion
|
|
4638
|
+
//#region src/substruct-library.ts
|
|
4639
|
+
var SubstructLibraryEntryImpl = class {
|
|
4640
|
+
index;
|
|
4641
|
+
smiles;
|
|
4642
|
+
patternFp;
|
|
4643
|
+
module;
|
|
4644
|
+
_cachedMol;
|
|
4645
|
+
constructor(i, smiles, patternFpU8, module) {
|
|
4646
|
+
this.index = i;
|
|
4647
|
+
this.smiles = smiles;
|
|
4648
|
+
this.patternFp = new Fingerprint(patternFpU8, void 0, "Pattern");
|
|
4649
|
+
this.module = module;
|
|
4650
|
+
}
|
|
4651
|
+
get mol() {
|
|
4652
|
+
if (this._cachedMol !== void 0) return this._cachedMol;
|
|
4653
|
+
const jsMol = this.module.get_mol(this.smiles);
|
|
4654
|
+
this._cachedMol = jsMol ? new Mol(jsMol, this.module) : null;
|
|
4655
|
+
return this._cachedMol;
|
|
4656
|
+
}
|
|
4657
|
+
delete() {
|
|
4658
|
+
if (!this._cachedMol) return;
|
|
4659
|
+
this._cachedMol.delete();
|
|
4660
|
+
this._cachedMol = null;
|
|
4661
|
+
}
|
|
4662
|
+
[Symbol.dispose]() {
|
|
4663
|
+
this.delete();
|
|
4664
|
+
}
|
|
4665
|
+
};
|
|
4666
|
+
/**
|
|
4667
|
+
* A collection of molecules for efficient batch substructure searching.
|
|
4668
|
+
*
|
|
4669
|
+
* Molecules are stored as canonical SMILES with pre-computed pattern
|
|
4670
|
+
* fingerprints used to pre-screen candidates before full substructure matching.
|
|
4671
|
+
*
|
|
4672
|
+
* @example
|
|
4673
|
+
* ```ts
|
|
4674
|
+
* using lib = rdkit.createSubstructLibrary();
|
|
4675
|
+
* for (const smi of smilesList) lib.add(smi);
|
|
4676
|
+
* const result = lib.getMatches('C1CCCCN1');
|
|
4677
|
+
* console.log(result.count, Array.from(result.indices));
|
|
4678
|
+
* ```
|
|
4679
|
+
*/
|
|
4680
|
+
var SubstructLibraryWrapper = class {
|
|
4681
|
+
lib;
|
|
4682
|
+
module;
|
|
4683
|
+
/** use {@link RDKit.createSubstructLibraryWrapper} */
|
|
4684
|
+
constructor(module, options) {
|
|
4685
|
+
this.module = module;
|
|
4686
|
+
if (options?.disableFingerprints) this.lib = new module.SubstructLibrary(0);
|
|
4687
|
+
else if (options?.nBits !== void 0) this.lib = new module.SubstructLibrary(options.nBits);
|
|
4688
|
+
else this.lib = new module.SubstructLibrary();
|
|
4689
|
+
}
|
|
4690
|
+
/**
|
|
4691
|
+
* Add a molecule to the library.
|
|
4692
|
+
* - `Mol` instance: added via `add_mol` (already parsed and sanitized)
|
|
4693
|
+
* - `string`: treated as SMILES; validated unless `options.trusted` is set
|
|
4694
|
+
*
|
|
4695
|
+
* @returns the index of the added molecule, or -1 on failure
|
|
4696
|
+
*/
|
|
4697
|
+
add(mol, options) {
|
|
4698
|
+
if (mol instanceof Mol) return this.lib.add_mol(mol.jsMol);
|
|
4699
|
+
if (options?.trusted) return this.lib.add_trusted_smiles(mol);
|
|
4700
|
+
return this.lib.add_smiles(mol);
|
|
4701
|
+
}
|
|
4702
|
+
/**
|
|
4703
|
+
* Add a molecule with a pre-computed pattern fingerprint.
|
|
4704
|
+
* Skips both SMILES validation and fingerprint computation.
|
|
4705
|
+
*
|
|
4706
|
+
* @param smiles RDKit-canonical SMILES string
|
|
4707
|
+
* @param fp pre-computed pattern fingerprint (a `Fingerprint` object)
|
|
4708
|
+
* @returns the index of the added molecule
|
|
4709
|
+
*/
|
|
4710
|
+
addPrecomputed(smiles, fp) {
|
|
4711
|
+
return this.lib.add_trusted_smiles_and_pattern_fp(smiles, fp.fpU8);
|
|
4712
|
+
}
|
|
4713
|
+
/**
|
|
4714
|
+
* Returns the entry at index `i`: stored SMILES, pattern fingerprint, and a lazy mol getter.
|
|
4715
|
+
*
|
|
4716
|
+
* The `mol` getter lazily allocates a WASM object on first access.
|
|
4717
|
+
* **WARNING:** The caller is responsible for deleting it via `.delete()` or `using`.
|
|
4718
|
+
*
|
|
4719
|
+
* @example Iterate for serialization:
|
|
4720
|
+
* ```ts
|
|
4721
|
+
* for (let i = 0; i < lib.size; i++) {
|
|
4722
|
+
* const { smiles, patternFp } = lib.at(i);
|
|
4723
|
+
* }
|
|
4724
|
+
* ```
|
|
4725
|
+
*/
|
|
4726
|
+
at(i) {
|
|
4727
|
+
return new SubstructLibraryEntryImpl(i, this.lib.get_trusted_smiles(i), this.lib.get_pattern_fp_as_uint8array(i), this.module);
|
|
4728
|
+
}
|
|
4729
|
+
/**
|
|
4730
|
+
* Runs a substructure search and returns a result object with `count`,
|
|
4731
|
+
* `indices`, and an iterator that yields {@link SubstructLibraryEntry} objects.
|
|
4732
|
+
*
|
|
4733
|
+
* @param query `Mol` instance or SMARTS string
|
|
4734
|
+
*/
|
|
4735
|
+
getMatches(query, options) {
|
|
4736
|
+
const [qmol, shouldDelete] = this.resolveQuery(query);
|
|
4737
|
+
const opts = {
|
|
4738
|
+
useChirality: false,
|
|
4739
|
+
maxResults: -1,
|
|
4740
|
+
...options
|
|
4741
|
+
};
|
|
4742
|
+
const indices = this.lib.get_matches_as_uint32array(qmol, opts.useChirality, 0, opts.maxResults);
|
|
4743
|
+
if (shouldDelete) qmol.delete();
|
|
4744
|
+
const lib = this;
|
|
4745
|
+
return {
|
|
4746
|
+
indices,
|
|
4747
|
+
get count() {
|
|
4748
|
+
return indices.length;
|
|
4749
|
+
},
|
|
4750
|
+
*[Symbol.iterator]() {
|
|
4751
|
+
for (const i of indices) yield lib.at(i);
|
|
4752
|
+
}
|
|
4753
|
+
};
|
|
4754
|
+
}
|
|
4755
|
+
/** Number of molecules in the library */
|
|
4756
|
+
get size() {
|
|
4757
|
+
return this.lib.size();
|
|
4758
|
+
}
|
|
4759
|
+
delete() {
|
|
4760
|
+
this.lib.delete();
|
|
4761
|
+
}
|
|
4762
|
+
[Symbol.dispose]() {
|
|
4763
|
+
this.delete();
|
|
4764
|
+
}
|
|
4765
|
+
/** SMARTS strings resolve to a QueryMol that must be deleted internally */
|
|
4766
|
+
resolveQuery(query) {
|
|
4767
|
+
if (query instanceof Mol) return [query.jsMol, false];
|
|
4768
|
+
const qmol = this.module.get_qmol(query);
|
|
4769
|
+
if (!qmol) throw new Error(`Invalid SMARTS query: ${query}`);
|
|
4770
|
+
return [qmol, true];
|
|
4771
|
+
}
|
|
4772
|
+
};
|
|
4773
|
+
//#endregion
|
|
4533
4774
|
//#region src/rgd.ts
|
|
4534
4775
|
/**
|
|
4535
4776
|
* The result of an R-Group Decomposition, as an array of {@link RGDRow} with
|
|
@@ -4639,36 +4880,36 @@ const isRDKitParseError = (error) => {
|
|
|
4639
4880
|
* RDKitLogger manages RDKit error capture and dispatch to listeners, as well as optional console logging.
|
|
4640
4881
|
*/
|
|
4641
4882
|
var RDKitLogger = class {
|
|
4642
|
-
|
|
4643
|
-
|
|
4644
|
-
|
|
4645
|
-
|
|
4646
|
-
|
|
4883
|
+
mod;
|
|
4884
|
+
capture = null;
|
|
4885
|
+
callback = null;
|
|
4886
|
+
enableLogging = false;
|
|
4887
|
+
throwOnError = false;
|
|
4647
4888
|
constructor(mod) {
|
|
4648
|
-
this
|
|
4889
|
+
this.mod = mod;
|
|
4649
4890
|
}
|
|
4650
|
-
|
|
4651
|
-
if (this
|
|
4652
|
-
this
|
|
4891
|
+
activate() {
|
|
4892
|
+
if (this.capture) return;
|
|
4893
|
+
this.capture = (this.enableLogging ? this.mod.set_log_tee : this.mod.set_log_capture)("rdApp.error") ?? null;
|
|
4653
4894
|
}
|
|
4654
4895
|
/**
|
|
4655
4896
|
* Called from configure({ enableLogging }). Switches between tee and capture
|
|
4656
4897
|
* if already active; otherwise applies enable/disable_logging for the no-capture case.
|
|
4657
4898
|
*/
|
|
4658
4899
|
setEnableLogging(enable) {
|
|
4659
|
-
this
|
|
4660
|
-
if (this
|
|
4661
|
-
this
|
|
4662
|
-
this
|
|
4663
|
-
this
|
|
4664
|
-
} else enable ? this
|
|
4900
|
+
this.enableLogging = enable;
|
|
4901
|
+
if (this.capture) {
|
|
4902
|
+
this.capture.delete();
|
|
4903
|
+
this.capture = null;
|
|
4904
|
+
this.activate();
|
|
4905
|
+
} else enable ? this.mod.enable_logging("rdApp.error") : this.mod.disable_logging("rdApp.error");
|
|
4665
4906
|
}
|
|
4666
4907
|
/** Single callback slot — replaces any previous. Returns cleanup function. */
|
|
4667
4908
|
addCallback(fn) {
|
|
4668
|
-
this
|
|
4669
|
-
this
|
|
4909
|
+
this.callback = fn;
|
|
4910
|
+
this.activate();
|
|
4670
4911
|
return () => {
|
|
4671
|
-
if (this
|
|
4912
|
+
if (this.callback === fn) this.callback = null;
|
|
4672
4913
|
};
|
|
4673
4914
|
}
|
|
4674
4915
|
/**
|
|
@@ -4677,25 +4918,25 @@ var RDKitLogger = class {
|
|
|
4677
4918
|
* Fast path: no-op when neither throwOnError nor capture is active.
|
|
4678
4919
|
*/
|
|
4679
4920
|
reset(throwOnError) {
|
|
4680
|
-
this
|
|
4681
|
-
if (!throwOnError && !this
|
|
4682
|
-
if (throwOnError) this
|
|
4683
|
-
this
|
|
4921
|
+
this.throwOnError = throwOnError;
|
|
4922
|
+
if (!throwOnError && !this.capture) return;
|
|
4923
|
+
if (throwOnError) this.activate();
|
|
4924
|
+
this.capture?.clear_buffer();
|
|
4684
4925
|
}
|
|
4685
4926
|
/**
|
|
4686
4927
|
* Call on null return from WASM. Reads buffer, fires callback, throws if throwOnError.
|
|
4687
4928
|
* No-op when reset() took the fast path (capture still null).
|
|
4688
4929
|
*/
|
|
4689
4930
|
handleError(input, operation) {
|
|
4690
|
-
if (!this
|
|
4691
|
-
const message = this
|
|
4692
|
-
this
|
|
4693
|
-
this
|
|
4931
|
+
if (!this.capture) return;
|
|
4932
|
+
const message = this.capture.get_buffer().trim();
|
|
4933
|
+
this.capture.clear_buffer();
|
|
4934
|
+
this.callback?.({
|
|
4694
4935
|
input,
|
|
4695
4936
|
message,
|
|
4696
4937
|
operation
|
|
4697
4938
|
});
|
|
4698
|
-
if (this
|
|
4939
|
+
if (this.throwOnError) throw new RDKitParseError(input, message);
|
|
4699
4940
|
}
|
|
4700
4941
|
};
|
|
4701
4942
|
//#endregion
|
|
@@ -4712,38 +4953,38 @@ var RDKitLogger = class {
|
|
|
4712
4953
|
* ```
|
|
4713
4954
|
*/
|
|
4714
4955
|
var RDKit = class {
|
|
4715
|
-
|
|
4716
|
-
|
|
4956
|
+
mod;
|
|
4957
|
+
logger;
|
|
4717
4958
|
events;
|
|
4718
4959
|
/** @internal */
|
|
4719
4960
|
constructor(mod) {
|
|
4720
|
-
this
|
|
4721
|
-
this
|
|
4722
|
-
this.events = { addErrorListener: (cb) => this
|
|
4961
|
+
this.mod = mod;
|
|
4962
|
+
this.logger = new RDKitLogger(mod);
|
|
4963
|
+
this.events = { addErrorListener: (cb) => this.logger.addCallback(cb) };
|
|
4723
4964
|
}
|
|
4724
4965
|
getMol(input, options) {
|
|
4725
4966
|
const { throwOnError = false, ...wasmOptions } = options ?? {};
|
|
4726
|
-
this
|
|
4967
|
+
this.logger.reset(throwOnError);
|
|
4727
4968
|
let jsMol;
|
|
4728
4969
|
if (input instanceof Uint8Array) {
|
|
4729
4970
|
if (options) console.warn("Options are ignored when getMol is called with a binary input (pikkle).");
|
|
4730
|
-
jsMol = this
|
|
4731
|
-
} else jsMol = Object.keys(wasmOptions).length > 0 ? this
|
|
4971
|
+
jsMol = this.mod.get_mol_from_uint8array(input);
|
|
4972
|
+
} else jsMol = Object.keys(wasmOptions).length > 0 ? this.mod.get_mol(input, JSON.stringify(wasmOptions)) : this.mod.get_mol(input);
|
|
4732
4973
|
if (!jsMol) {
|
|
4733
|
-
this
|
|
4974
|
+
this.logger.handleError(input, "getMol");
|
|
4734
4975
|
return null;
|
|
4735
4976
|
}
|
|
4736
|
-
return new Mol(jsMol, this
|
|
4977
|
+
return new Mol(jsMol, this.mod);
|
|
4737
4978
|
}
|
|
4738
4979
|
getQMol(input, options) {
|
|
4739
4980
|
const { throwOnError = false } = options ?? {};
|
|
4740
|
-
this
|
|
4741
|
-
const jsMol = this
|
|
4981
|
+
this.logger.reset(throwOnError);
|
|
4982
|
+
const jsMol = this.mod.get_qmol(input);
|
|
4742
4983
|
if (!jsMol) {
|
|
4743
|
-
this
|
|
4984
|
+
this.logger.handleError(input, "getQMol");
|
|
4744
4985
|
return null;
|
|
4745
4986
|
}
|
|
4746
|
-
return new Mol(jsMol, this
|
|
4987
|
+
return new Mol(jsMol, this.mod);
|
|
4747
4988
|
}
|
|
4748
4989
|
/**
|
|
4749
4990
|
* Computes the Maximum Common Substructure (MCS) of a set of molecules.
|
|
@@ -4755,17 +4996,17 @@ var RDKit = class {
|
|
|
4755
4996
|
getMCS(mols, options) {
|
|
4756
4997
|
let molList;
|
|
4757
4998
|
if (mols.length < 2) throw new Error("getMCS requires at least 2 molecules");
|
|
4758
|
-
if (isMolArray(mols)) molList = fromMolArraytoMolList(mols, this
|
|
4759
|
-
else molList = fromStringArraytoMolList(mols, this
|
|
4999
|
+
if (isMolArray(mols)) molList = fromMolArraytoMolList(mols, this.mod);
|
|
5000
|
+
else molList = fromStringArraytoMolList(mols, this.mod);
|
|
4760
5001
|
if (molList.size() < 2) {
|
|
4761
5002
|
molList.delete();
|
|
4762
5003
|
throw new Error("getMCS requires at least 2 valid molecules");
|
|
4763
5004
|
}
|
|
4764
|
-
const json = options ? this
|
|
5005
|
+
const json = options ? this.mod.get_mcs_as_json(molList, JSON.stringify(options)) : this.mod.get_mcs_as_json(molList);
|
|
4765
5006
|
molList.delete();
|
|
4766
5007
|
const parsed = JSON.parse(json);
|
|
4767
5008
|
let cachedQmol;
|
|
4768
|
-
const mod = this
|
|
5009
|
+
const mod = this.mod;
|
|
4769
5010
|
return {
|
|
4770
5011
|
...parsed,
|
|
4771
5012
|
get qmol() {
|
|
@@ -4789,18 +5030,18 @@ var RDKit = class {
|
|
|
4789
5030
|
}
|
|
4790
5031
|
getRxn(input, options) {
|
|
4791
5032
|
const { throwOnError = false, ...wasmOptions } = options ?? {};
|
|
4792
|
-
this
|
|
5033
|
+
this.logger.reset(throwOnError);
|
|
4793
5034
|
let jsRxn = null;
|
|
4794
5035
|
try {
|
|
4795
|
-
jsRxn = Object.keys(wasmOptions).length > 0 ? this
|
|
5036
|
+
jsRxn = Object.keys(wasmOptions).length > 0 ? this.mod.get_rxn(input, JSON.stringify(wasmOptions)) : this.mod.get_rxn(input);
|
|
4796
5037
|
} catch {
|
|
4797
5038
|
jsRxn = null;
|
|
4798
5039
|
}
|
|
4799
5040
|
if (!jsRxn) {
|
|
4800
|
-
this
|
|
5041
|
+
this.logger.handleError(input, "getRxn");
|
|
4801
5042
|
return null;
|
|
4802
5043
|
}
|
|
4803
|
-
return new Reaction(jsRxn, this
|
|
5044
|
+
return new Reaction(jsRxn, this.mod);
|
|
4804
5045
|
}
|
|
4805
5046
|
/**
|
|
4806
5047
|
* Performs R-Group Decomposition on a set of molecules against one or more cores.
|
|
@@ -4816,12 +5057,26 @@ var RDKit = class {
|
|
|
4816
5057
|
* (`Core`, `R1`, `R2`, …) to Mol instances.
|
|
4817
5058
|
*/
|
|
4818
5059
|
getRGD(core, molecules, options) {
|
|
4819
|
-
return decomposeRGroups(core, molecules, options, this
|
|
5060
|
+
return decomposeRGroups(core, molecules, options, this.mod);
|
|
5061
|
+
}
|
|
5062
|
+
/**
|
|
5063
|
+
* Creates an empty {@link SubstructLibraryWrapper} for batch substructure searching.
|
|
5064
|
+
*
|
|
5065
|
+
* @example
|
|
5066
|
+
* ```ts
|
|
5067
|
+
* using lib = rdkit.createSubstructLibrary();
|
|
5068
|
+
* for (const smi of smilesList) lib.add(smi);
|
|
5069
|
+
* const result = lib.getMatches('C1CCCCN1'); // SMARTS query
|
|
5070
|
+
* console.log(result.count, Array.from(result.indices));
|
|
5071
|
+
* ```
|
|
5072
|
+
*/
|
|
5073
|
+
createSubstructLibrary(options) {
|
|
5074
|
+
return new SubstructLibraryWrapper(this.mod, options);
|
|
4820
5075
|
}
|
|
4821
|
-
molzip(mol1, mol2) {
|
|
4822
|
-
const jsMol = this
|
|
5076
|
+
molzip(mol1, mol2, options) {
|
|
5077
|
+
const jsMol = options ? this.mod.molzip(mol1.jsMol, mol2.jsMol, JSON.stringify(options)) : this.mod.molzip(mol1.jsMol, mol2.jsMol);
|
|
4823
5078
|
if (!jsMol) return null;
|
|
4824
|
-
return new Mol(jsMol, this
|
|
5079
|
+
return new Mol(jsMol, this.mod);
|
|
4825
5080
|
}
|
|
4826
5081
|
computeFingerprintsSimilarity(...args) {
|
|
4827
5082
|
return computeFingerprintSimilarity(...args);
|
|
@@ -4833,18 +5088,18 @@ var RDKit = class {
|
|
|
4833
5088
|
*/
|
|
4834
5089
|
configure(options) {
|
|
4835
5090
|
const { preferCoordgen, useLegacyStereoPerception, allowNonTetrahedralChirality, enableLogging } = options;
|
|
4836
|
-
if (preferCoordgen !== void 0) this
|
|
4837
|
-
if (useLegacyStereoPerception !== void 0) this
|
|
4838
|
-
if (allowNonTetrahedralChirality !== void 0) this
|
|
4839
|
-
if (enableLogging !== void 0) this
|
|
5091
|
+
if (preferCoordgen !== void 0) this.mod.prefer_coordgen(preferCoordgen);
|
|
5092
|
+
if (useLegacyStereoPerception !== void 0) this.mod.use_legacy_stereo_perception(useLegacyStereoPerception);
|
|
5093
|
+
if (allowNonTetrahedralChirality !== void 0) this.mod.allow_non_tetrahedral_chirality(allowNonTetrahedralChirality);
|
|
5094
|
+
if (enableLogging !== void 0) this.logger.setEnableLogging(enableLogging);
|
|
4840
5095
|
}
|
|
4841
5096
|
/** Returns the RDKit version string */
|
|
4842
5097
|
get version() {
|
|
4843
|
-
return this
|
|
5098
|
+
return this.mod.version();
|
|
4844
5099
|
}
|
|
4845
5100
|
/** The underlying RDKitModule for direct access to the raw API */
|
|
4846
5101
|
get module() {
|
|
4847
|
-
return this
|
|
5102
|
+
return this.mod;
|
|
4848
5103
|
}
|
|
4849
5104
|
};
|
|
4850
5105
|
//#endregion
|
|
@@ -4874,4 +5129,4 @@ async function initRDKit(options, constructor = RDKit) {
|
|
|
4874
5129
|
return new constructor(await (0, import_RDKit_minimal.default)(moduleArgs));
|
|
4875
5130
|
}
|
|
4876
5131
|
//#endregion
|
|
4877
|
-
export { Fingerprint, Mol, MolArray, RDKit, RDKitParseError, Reaction, initRDKit, isRDKitParseError };
|
|
5132
|
+
export { Fingerprint, Mol, MolArray, RDKit, RDKitParseError, Reaction, SubstructLibraryWrapper, initRDKit, isRDKitParseError };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "rdkit-esm",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.6.0",
|
|
4
4
|
"description": "RDKit minimal lib for the modern web.",
|
|
5
5
|
"homepage": "https://github.com/tandemai/rdkit-esm#readme",
|
|
6
6
|
"bugs": {
|
|
@@ -43,4 +43,4 @@
|
|
|
43
43
|
"typescript": "^6.0.2",
|
|
44
44
|
"vitest": "^4.0.16"
|
|
45
45
|
}
|
|
46
|
-
}
|
|
46
|
+
}
|