rdkit-esm 0.1.0 → 0.2.2-rc.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 CHANGED
@@ -30,7 +30,7 @@ const mol = rdkit.getMol('c1ccccc1');
30
30
  if (mol) {
31
31
  mol.getSmiles(); // 'c1ccccc1'
32
32
  mol.getDescriptors(); // { exactMW: 78.047, ClogP: 1.6816, ... }
33
- mol.getSvg({ width: 350, height: 300 });
33
+ mol.getSVG({ width: 350, height: 300 });
34
34
 
35
35
  mol.delete(); // free WASM memory when done
36
36
  }
@@ -61,11 +61,11 @@ The main entry point for creating molecules, reactions, and collections.
61
61
 
62
62
  Wraps a single molecule with a typed, camelCase API.
63
63
 
64
- - **String representations** — `getSmiles()`, `getCxSmiles()`, `getSmarts()`, `getMolblock()`, `getV3KMolblock()`, `getInchi()`, `getInchikey()`, `getJson()`
64
+ - **String representations** — `getSmiles()`, `getCxSmiles()`, `getSmarts()`, `getMolblock()`, `getV3KMolblock()`, `getInchi()`, `getInchikey()`, `getJSON()`
65
65
  - **Fingerprints** — `getMorganFp()`, `getMaccsFp()`, `getPatternFp()`, `getTopologicalTorsionFp()`, `getRdkitFp()`, `getAtomPairFp()` (each also available as `…AsUint8Array()`)
66
66
  - **Descriptors** — `getDescriptors()` returns MW, ClogP, HBA, HBD, ring counts, etc.
67
67
  - **Substructure** — `getSubstructMatch(query)`, `getSubstructMatches(query)`
68
- - **Drawing** — `getSvg(options?)`, `drawToCanvas(canvas, ...)`
68
+ - **Drawing** — `getSVG(options?)`, `drawToCanvas(canvas, ...)`
69
69
  - **Coordinates** — `setNewCoords()`, `generateAlignedCoords(template, options?)`
70
70
  - **Mutations** — `addHs()` / `removeHs()`, `convertToAromaticForm()` / `convertToKekuleForm()`, `combineWith()`, `zipWith()`
71
71
  - **Properties** — `hasProp()`, `getProp()`, `setProp()`, `clearProp()`, `getPropList()`
@@ -80,7 +80,7 @@ Extends `Array<Mol>` with batch lifecycle management. Returned by `getFrags()`.
80
80
  | Method | Description |
81
81
  | --------------------------------------- | ------------------------------------------------------------- |
82
82
  | `runReactants(reactants, maxProducts?)` | Run the reaction on a set of reactants. Returns product sets. |
83
- | `getSvg(options?)` | Render the reaction as SVG. |
83
+ | `getSVG(options?)` | Render the reaction as SVG. |
84
84
  | `drawToCanvas(canvas, ...)` | Draw the reaction to an HTML canvas. |
85
85
 
86
86
  ## Memory Management
package/dist/index.d.ts CHANGED
@@ -1,7 +1,7 @@
1
1
  //#region src/types/rdkit-minimalib-typings.d.ts
2
2
  // Type definitons for RDKit.js
3
- // Project: https://github.com/rdkit/rdkit-js
4
- // Definitions by: adam-of-barot <https://github.com/adam-of-barot>
3
+ // Based on Project: https://github.com/rdkit/rdkit-js
4
+ // Adapted from definitions by: adam-of-barot <https://github.com/adam-of-barot>
5
5
 
6
6
  type JSONString = string;
7
7
 
@@ -66,7 +66,7 @@ interface JSMol {
66
66
  // array representation
67
67
 
68
68
  /** Returns an unsigned integer array representation */
69
- get_as_uint8array(): Uint8Array;
69
+ get_as_uint8array(options?: JSONString): Uint8Array;
70
70
 
71
71
  // SVG representations
72
72
 
@@ -623,7 +623,7 @@ interface RDKitModule {
623
623
  * This will return null if the input is invalid.
624
624
  *
625
625
  * @param input SMILES / SMARTS / MolFile / JSON string
626
- * @param details_json @type {RDKitGetMolOpt}
626
+ * @param details_json RDKitGetMolOpt
627
627
  */
628
628
  get_mol(input: string, details_json?: string): JSMol | null;
629
629
 
@@ -631,8 +631,9 @@ interface RDKitModule {
631
631
  * Create a molecule from an integer array
632
632
  *
633
633
  * @param pklAsUInt8Array unsigned integer array
634
+ * @param details_json RDKitGetMolFromPickleOtions
634
635
  */
635
- get_mol_from_uint8array(pklAsUInt8Array: Uint8Array): JSMol;
636
+ get_mol_from_uint8array(pklAsUInt8Array: Uint8Array, details_json?: string): JSMol;
636
637
 
637
638
  /**
638
639
  * Create a copy of a molecule
@@ -949,6 +950,15 @@ type RDKitGetSmilesOptions = {
949
950
  };
950
951
  /** CX extension field names (without the `CX_` prefix) */
951
952
  type CxSmilesField = 'NONE' | 'ATOM_LABELS' | 'MOLFILE_VALUES' | 'COORDS' | 'RADICALS' | 'ATOM_PROPS' | 'LINKNODES' | 'ENHANCEDSTEREO' | 'SGROUPS' | 'POLYMER' | 'BOND_CFG' | 'BOND_ATROPISOMER' | 'COORDINATE_BONDS' | 'HYDROGEN_BONDS' | 'ZERO_BONDS' | 'ALL' | 'ALL_BUT_COORDS';
953
+ type PropertyPickleOptionsKeys = 'NoProps' // no data pickled, single precision coordinates
954
+ | 'MolProps' // only public non computed properties
955
+ | 'AtomProps' | 'BondProps'
956
+ // | 'QueryAtomData' // DEPRECATED, same as AtomProps when set
957
+ | 'PrivateProps' | 'ComputedProps' | 'AllProps' // all data pickled
958
+ | 'CoordsAsDouble' // save coordinates in double precision
959
+ | 'NoConformers';
960
+ // do not include conformers or associated properties
961
+
952
962
  type RDKitGetMCSOptions = {
953
963
  MaximizeBonds: boolean;
954
964
  Threshold: number;
@@ -1157,6 +1167,12 @@ type RDKitGetCxSmilesOptions = RDKitGetSmilesOptions & {
1157
1167
  /** Restore bond direction option. Accepts `true`, `'true'`, or `'clear'`. */
1158
1168
  restoreBondDirOption: true | 'true' | 'clear';
1159
1169
  };
1170
+ type RDKitGetUint8ArrayOptions = {
1171
+ /** Properties to include in the binary export (pickle)
1172
+ * @default: when `properties` is omitted, all data properties are included except the computed properties.
1173
+ */
1174
+ properties: PropertyPickleOptionsKeys[];
1175
+ };
1160
1176
  //#endregion
1161
1177
  //#region src/mol.d.ts
1162
1178
  /**
@@ -1169,7 +1185,7 @@ type RDKitGetCxSmilesOptions = RDKitGetSmilesOptions & {
1169
1185
  * Implements `Disposable` for use with the `using` keyword:
1170
1186
  * ```ts
1171
1187
  * using mol = rdkit.getMol('c1ccccc1')!;
1172
- * const svg = mol.getSvg();
1188
+ * const svg = mol.getSVG();
1173
1189
  * // mol is automatically deleted when the scope exits
1174
1190
  * ```
1175
1191
  */
@@ -1223,10 +1239,13 @@ declare class Mol implements Disposable {
1223
1239
  * @example mol.getInchi(["FixedH", "RecMet", "SaveOpt", "SUU", "SLUUD"])
1224
1240
  */
1225
1241
  getInchikey(args?: InChI_Flags[]): string;
1226
- /** Returns the parsed JSON representation of the molecule */
1227
- getJson(): RDKitJson;
1228
- /** Returns an unsigned integer array representation of the molecule */
1229
- getAsUint8Array(): Uint8Array;
1242
+ /**
1243
+ * Returns the serialized JSON representation of the molecule
1244
+ * Based on the CommonChem specifications @link https://github.com/CommonChem/CommonChem
1245
+ * */
1246
+ getJSON(): RDKitJson;
1247
+ /** Returns a binary representation of the molecule (pickle) as an unsigned integer array */
1248
+ getAsUint8Array(options?: Partial<RDKitGetUint8ArrayOptions>): Uint8Array;
1230
1249
  /**
1231
1250
  * Returns an SVG depiction of the molecule
1232
1251
  *
@@ -1235,15 +1254,15 @@ declare class Mol implements Disposable {
1235
1254
  *
1236
1255
  * @example
1237
1256
  * // Default SVG
1238
- * const svg = mol.getSvg();
1257
+ * const svg = mol.getSVG();
1239
1258
  *
1240
1259
  * // Custom size with atom indices
1241
- * const svg = mol.getSvg({ width: 400, height: 300, addAtomIndices: true });
1260
+ * const svg = mol.getSVG({ width: 400, height: 300, addAtomIndices: true });
1242
1261
  *
1243
1262
  * // With atom highlighting
1244
- * const svg = mol.getSvg({ atoms: [0, 1, 2], highlightColour: [1, 0, 0, 1] });
1263
+ * const svg = mol.getSVG({ atoms: [0, 1, 2], highlightColour: [1, 0, 0, 1] });
1245
1264
  */
1246
- getSvg(options?: Partial<RDKitDepictionDetails>): string;
1265
+ getSVG(options?: Partial<RDKitDepictionDetails>): string;
1247
1266
  /**
1248
1267
  * Returns the first substructure match
1249
1268
  *
@@ -1287,16 +1306,22 @@ declare class Mol implements Disposable {
1287
1306
  getAtomPairFpAsUint8Array(options?: Partial<RDKitAtomPairFPOptions>): Uint8Array;
1288
1307
  /** Returns the MACCS fingerprint as a Uint8Array */
1289
1308
  getMaccsFpAsUint8Array(): Uint8Array;
1309
+ /**
1310
+ * Parses a property value string, attempting JSON.parse first.
1311
+ * Returns the parsed value on success, or the raw string on failure.
1312
+ */
1313
+ private parsePropValue;
1290
1314
  /**
1291
1315
  * Checks whether the molecule has a given property
1292
1316
  * @param key - Property name
1293
1317
  */
1294
1318
  hasProp(key: string): boolean;
1295
1319
  /**
1296
- * Gets a property value from the molecule
1320
+ * Gets a property value from the molecule.
1321
+ * Attempts to parse the raw string as JSON; returns the raw string if parsing fails.
1297
1322
  * @param key - Property name
1298
1323
  */
1299
- getProp(key: string): string;
1324
+ getProp(key: string): any;
1300
1325
  /**
1301
1326
  * Sets a property on the molecule
1302
1327
  * @param key - Property name
@@ -1309,19 +1334,20 @@ declare class Mol implements Disposable {
1309
1334
  */
1310
1335
  clearProp(key: string): boolean;
1311
1336
  /**
1312
- * Returns the list of property names
1337
+ * Returns a map of all property names to their parsed values.
1338
+ * Values are parsed from JSON when possible, otherwise returned as raw strings.
1313
1339
  * @param options - Filter options
1314
1340
  */
1315
- getPropList(options?: {
1341
+ getPropMap(options?: {
1316
1342
  includePrivate?: boolean;
1317
1343
  includeComputed?: boolean;
1318
- }): string[];
1344
+ }): Map<string, any>;
1319
1345
  /** Returns true if the molecule's structure is valid */
1320
1346
  isValid(): boolean;
1321
1347
  /** Returns the number of atoms in the molecule */
1322
- getNumAtoms(): number;
1348
+ get numAtoms(): number;
1323
1349
  /** Returns the number of bonds in the molecule */
1324
- getNumBonds(): number;
1350
+ get numBonds(): number;
1325
1351
  /** Returns 0 if no coords, 2 for 2D, 3 for 3D */
1326
1352
  hasCoords(): 0 | 2 | 3;
1327
1353
  /** Returns stereo tags (CIP codes) for the molecule */
@@ -1458,7 +1484,7 @@ declare class Reaction implements Disposable {
1458
1484
  * @param options - Drawing options including highlighting.
1459
1485
  * When omitted, uses RDKit defaults.
1460
1486
  */
1461
- getSvg(options?: Partial<RDKitRxnDepictionDetails>): string;
1487
+ getSVG(options?: Partial<RDKitRxnDepictionDetails>): string;
1462
1488
  /**
1463
1489
  * Draws the reaction to an HTML5 canvas with highlighting options
1464
1490
  * @param canvas - Target canvas element
@@ -1482,18 +1508,38 @@ declare class Reaction implements Disposable {
1482
1508
  */
1483
1509
  type RGDRow = Record<string, Mol>;
1484
1510
  //#endregion
1485
- //#region src/init.d.ts
1486
- /** Options for initializing the RDKit module */
1487
- interface InitRDKitOptions {
1511
+ //#region src/rdkit.d.ts
1512
+ /** Result of a Maximum Common Substructure (MCS) computation */
1513
+ interface MCSResult {
1514
+ numAtoms: number;
1515
+ numBonds: number;
1516
+ canceled: boolean;
1517
+ /** SMARTS string(s) — an array when the `StoreAll` option is used */
1518
+ smarts: string | string[];
1488
1519
  /**
1489
- * Custom function to locate the WASM file.
1490
- * By default, the WASM file is resolved relative to the bundled JS output
1491
- * using the Vite/Rolldown `?url` import.
1520
+ * Lazily creates a query Mol from the first SMARTS.
1521
+ * Returns null if SMARTS is empty.
1522
+ *
1523
+ * **WARNING:** The caller is responsible for explicitly deleting this
1524
+ * object (via `.delete()` or `using`) to avoid memory leaks.
1492
1525
  */
1493
- locateFile?: () => string;
1526
+ get qmol(): Mol | null;
1494
1527
  }
1495
- /** The main RDKit wrapper interface returned by {@link initRDKit} */
1496
- interface RDKit {
1528
+ /**
1529
+ * The main RDKit wrapper providing a typed, camelCase API over the WASM module.
1530
+ *
1531
+ * Instances are created via {@link initRDKit}, not directly by consumers.
1532
+ *
1533
+ * @example
1534
+ * ```ts
1535
+ * const rdkit = await initRDKit();
1536
+ * const mol = rdkit.getMol('c1ccccc1');
1537
+ * ```
1538
+ */
1539
+ declare class RDKit {
1540
+ #private;
1541
+ /** @internal */
1542
+ constructor(mod: RDKitModule);
1497
1543
  /**
1498
1544
  * Creates a molecule from a variety of input formats.
1499
1545
  *
@@ -1501,7 +1547,7 @@ interface RDKit {
1501
1547
  * @param options - Molecule parsing options
1502
1548
  * @returns A Mol instance, or null if the input is invalid
1503
1549
  */
1504
- getMol(input: string, options?: Partial<RDKitGetMolOpt>): Mol | null;
1550
+ getMol(input: string | Uint8Array, options?: Partial<RDKitGetMolOpt>): Mol | null;
1505
1551
  /**
1506
1552
  * Creates a query molecule from a SMARTS string.
1507
1553
  *
@@ -1541,30 +1587,26 @@ interface RDKit {
1541
1587
  getRGD(core: string | string[] | Mol | Mol[], molecules: string[] | Mol[], options?: Partial<RDKitGetRgdOptions>): RGDRow[] | null;
1542
1588
  molzip(mol1: Mol, mol2: Mol): Mol | null;
1543
1589
  /** Returns the RDKit version string */
1544
- version: string;
1590
+ get version(): string;
1545
1591
  /** The underlying RDKitModule for direct access to the raw API */
1546
- readonly module: RDKitModule;
1592
+ get module(): RDKitModule;
1547
1593
  }
1548
- /** Result of a Maximum Common Substructure (MCS) computation */
1549
- interface MCSResult {
1550
- numAtoms: number;
1551
- numBonds: number;
1552
- canceled: boolean;
1553
- /** SMARTS string(s) — an array when the `StoreAll` option is used */
1554
- smarts: string | string[];
1594
+ //#endregion
1595
+ //#region src/init.d.ts
1596
+ /** Options for initializing the RDKit module */
1597
+ interface InitRDKitOptions {
1555
1598
  /**
1556
- * Lazily creates a query Mol from the first SMARTS.
1557
- * Returns null if SMARTS is empty.
1558
- *
1559
- * **WARNING:** The caller is responsible for explicitly deleting this
1560
- * object (via `.delete()` or `using`) to avoid memory leaks.
1599
+ * Custom function to locate the WASM file.
1600
+ * By default, the WASM file is resolved relative to the bundled JS output
1601
+ * using the Vite/Rolldown `?url` import.
1561
1602
  */
1562
- get qmol(): Mol | null;
1603
+ locateFile: () => string;
1563
1604
  }
1564
1605
  /**
1565
1606
  * Initializes the RDKit WASM module and returns a typed wrapper.
1566
1607
  *
1567
1608
  * @param options - Initialization options
1609
+ * @params constructor - Advanced use only. Optional custom constructor to allow extending the RDKit class
1568
1610
  * @returns A promise that resolves to the RDKit wrapper
1569
1611
  *
1570
1612
  * @example
@@ -1572,7 +1614,23 @@ interface MCSResult {
1572
1614
  * const rdkit = await initRDKit();
1573
1615
  * const mol = rdkit.getMol('c1ccccc1');
1574
1616
  * ```
1617
+ *
1618
+ * @example with custom constructor
1619
+ * ```ts
1620
+ * class ExtendedRDKit extends RDKit {
1621
+ * constructor(mod: RDKitModule) {
1622
+ * super(mod);
1623
+ * console.log("ExtendedRDKit initialized. Version:", this.version);
1624
+ * }
1625
+ * }
1626
+ *
1627
+ * const initExtendedRDKit = async () => {
1628
+ * const rdkit = await initRDKit({}, ExtendedRDKit);
1629
+ * return rdkit;
1630
+ * };
1631
+ * ```
1575
1632
  */
1576
- declare function initRDKit(options?: InitRDKitOptions): Promise<RDKit>;
1633
+ declare function initRDKit(options?: Partial<InitRDKitOptions>): Promise<RDKit>;
1634
+ declare function initRDKit<T extends typeof RDKit>(options: Partial<InitRDKitOptions> | undefined, constructor: T): Promise<InstanceType<T>>;
1577
1635
  //#endregion
1578
- export { type InitRDKitOptions, type JSMol, type JSReaction, type MCSResult, Mol, MolArray, type MolList, type RDKit, type RDKitAlignedCoordsOptions, type RDKitAtomPairFPOptions, type RDKitDepictionDetails, type RDKitDescriptors, type RDKitGetMCSOptions, type RDKitGetMolBlockOptions, type RDKitGetMolOpt, type RDKitGetRgdOptions, type RDKitGetSmilesOptions, type RDKitJson, type RDKitMCSResult, type RDKitModule, type RDKitMorganFPOptions, type RDKitPatternFPOptions, type RDKitRdkitFpOptions, type RDKitRemoveHsOptions, type RDKitRxnDetails, type RDKitStereoTags, type RDKitSubstructMatch, type RDKitTopologicalTorsionFPOptions, type RGDRow, Reaction, initRDKit };
1636
+ export { type InitRDKitOptions, type JSMol, type JSReaction, type MCSResult, Mol, MolArray, type MolList, RDKit, type RDKitAlignedCoordsOptions, type RDKitAtomPairFPOptions, type RDKitDepictionDetails, type RDKitDescriptors, type RDKitGetMCSOptions, type RDKitGetMolBlockOptions, type RDKitGetMolOpt, type RDKitGetRgdOptions, type RDKitGetSmilesOptions, type RDKitJson, type RDKitMCSResult, type RDKitModule, type RDKitMorganFPOptions, type RDKitPatternFPOptions, type RDKitRdkitFpOptions, type RDKitRemoveHsOptions, type RDKitRxnDetails, type RDKitStereoTags, type RDKitSubstructMatch, type RDKitTopologicalTorsionFPOptions, type RGDRow, Reaction, initRDKit };
package/dist/index.js CHANGED
@@ -24,45 +24,27 @@ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__ge
24
24
  value: mod,
25
25
  enumerable: true
26
26
  }) : target, mod));
27
- var __require = /* @__PURE__ */ ((x) => typeof require !== "undefined" ? require : typeof Proxy !== "undefined" ? new Proxy(x, { get: (a, b) => (typeof require !== "undefined" ? require : a)[b] }) : x)(function(x) {
28
- if (typeof require !== "undefined") return require.apply(this, arguments);
29
- throw Error("Calling `require` for \"" + x + "\" in an environment that doesn't expose the `require` function.");
30
- });
31
27
 
32
28
  //#endregion
33
29
  //#region MinimalLib/dist/RDKit_minimal.js
34
30
  var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) => {
35
- var initRDKitModule$1 = (() => {
31
+ var initRDKitModule = (() => {
36
32
  var _scriptName = globalThis.document?.currentScript?.src;
37
33
  return async function(moduleArg = {}) {
38
34
  var moduleRtn;
39
35
  var Module = moduleArg;
40
36
  var ENVIRONMENT_IS_WEB = !!globalThis.window;
41
37
  var ENVIRONMENT_IS_WORKER = !!globalThis.WorkerGlobalScope;
42
- var ENVIRONMENT_IS_NODE = globalThis.process?.versions?.node && globalThis.process?.type != "renderer";
38
+ globalThis.process?.versions?.node && globalThis.process?.type;
43
39
  var thisProgram = "./this.program";
44
- if (typeof __filename != "undefined") _scriptName = __filename;
45
- else if (ENVIRONMENT_IS_WORKER) _scriptName = self.location.href;
40
+ if (ENVIRONMENT_IS_WORKER) _scriptName = self.location.href;
46
41
  var scriptDirectory = "";
47
42
  function locateFile(path) {
48
43
  if (Module["locateFile"]) return Module["locateFile"](path, scriptDirectory);
49
44
  return scriptDirectory + path;
50
45
  }
51
46
  var readAsync, readBinary;
52
- if (ENVIRONMENT_IS_NODE) {
53
- var fs = __require("node:fs");
54
- scriptDirectory = __dirname + "/";
55
- readBinary = (filename) => {
56
- filename = isFileURI(filename) ? new URL(filename) : filename;
57
- return fs.readFileSync(filename);
58
- };
59
- readAsync = async (filename, binary = true) => {
60
- filename = isFileURI(filename) ? new URL(filename) : filename;
61
- return fs.readFileSync(filename, binary ? void 0 : "utf8");
62
- };
63
- if (process.argv.length > 1) thisProgram = process.argv[1].replace(/\\/g, "/");
64
- process.argv.slice(2);
65
- } else if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
47
+ if (ENVIRONMENT_IS_WEB || ENVIRONMENT_IS_WORKER) {
66
48
  try {
67
49
  scriptDirectory = new URL(".", _scriptName).href;
68
50
  } catch {}
@@ -74,20 +56,6 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
74
56
  return new Uint8Array(xhr.response);
75
57
  };
76
58
  readAsync = async (url) => {
77
- if (isFileURI(url)) return new Promise((resolve, reject) => {
78
- var xhr = new XMLHttpRequest();
79
- xhr.open("GET", url, true);
80
- xhr.responseType = "arraybuffer";
81
- xhr.onload = () => {
82
- if (xhr.status == 200 || xhr.status == 0 && xhr.response) {
83
- resolve(xhr.response);
84
- return;
85
- }
86
- reject(xhr.status);
87
- };
88
- xhr.onerror = reject;
89
- xhr.send(null);
90
- });
91
59
  var response = await fetch(url, { credentials: "same-origin" });
92
60
  if (response.ok) return response.arrayBuffer();
93
61
  throw new Error(response.status + " : " + response.url);
@@ -97,7 +65,6 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
97
65
  var err = console.error.bind(console);
98
66
  var wasmBinary;
99
67
  var ABORT = false;
100
- var isFileURI = (filename) => filename.startsWith("file://");
101
68
  function writeStackCookie() {
102
69
  var max = _emscripten_stack_get_end();
103
70
  if (max == 0) max += 4;
@@ -191,7 +158,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
191
158
  }
192
159
  }
193
160
  async function instantiateAsync(binary, binaryFile, imports) {
194
- if (!binary && !isFileURI(binaryFile) && !ENVIRONMENT_IS_NODE) try {
161
+ if (!binary) try {
195
162
  var response = fetch(binaryFile, { credentials: "same-origin" });
196
163
  return await WebAssembly.instantiateStreaming(response, imports);
197
164
  } catch (reason) {
@@ -278,13 +245,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
278
245
  join: (...paths) => PATH.normalize(paths.join("/")),
279
246
  join2: (l, r) => PATH.normalize(l + "/" + r)
280
247
  };
281
- var initRandomFill = () => {
282
- if (ENVIRONMENT_IS_NODE) {
283
- var nodeCrypto = __require("node:crypto");
284
- return (view) => nodeCrypto.randomFillSync(view);
285
- }
286
- return (view) => crypto.getRandomValues(view);
287
- };
248
+ var initRandomFill = () => (view) => crypto.getRandomValues(view);
288
249
  var randomFill = (view) => {
289
250
  (randomFill = initRandomFill())(view);
290
251
  };
@@ -415,19 +376,7 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
415
376
  var FS_stdin_getChar = () => {
416
377
  if (!FS_stdin_getChar_buffer.length) {
417
378
  var result = null;
418
- if (ENVIRONMENT_IS_NODE) {
419
- var BUFSIZE = 256;
420
- var buf = Buffer.alloc(BUFSIZE);
421
- var bytesRead = 0;
422
- var fd = process.stdin.fd;
423
- try {
424
- bytesRead = fs.readSync(fd, buf, 0, BUFSIZE);
425
- } catch (e) {
426
- if (e.toString().includes("EOF")) bytesRead = 0;
427
- else throw e;
428
- }
429
- if (bytesRead > 0) result = buf.slice(0, bytesRead).toString("utf-8");
430
- } else if (globalThis.window?.prompt) {
379
+ if (globalThis.window?.prompt) {
431
380
  result = window.prompt("Input: ");
432
381
  if (result !== null) result += "\n";
433
382
  }
@@ -3844,15 +3793,15 @@ var require_RDKit_minimal = /* @__PURE__ */ __commonJSMin(((exports, module) =>
3844
3793
  };
3845
3794
  })();
3846
3795
  if (typeof exports === "object" && typeof module === "object") {
3847
- module.exports = initRDKitModule$1;
3848
- module.exports.default = initRDKitModule$1;
3849
- } else if (typeof define === "function" && define["amd"]) define([], () => initRDKitModule$1);
3796
+ module.exports = initRDKitModule;
3797
+ module.exports.default = initRDKitModule;
3798
+ } else if (typeof define === "function" && define["amd"]) define([], () => initRDKitModule);
3850
3799
  }));
3851
3800
 
3852
3801
  //#endregion
3853
3802
  //#region MinimalLib/dist/RDKit_minimal.wasm?url
3854
3803
  var import_RDKit_minimal = /* @__PURE__ */ __toESM(require_RDKit_minimal(), 1);
3855
- var RDKit_minimal_default = "daf0220ca047b78d.wasm";
3804
+ var RDKit_minimal_default = "2e30dd9094dea95c.wasm";
3856
3805
 
3857
3806
  //#endregion
3858
3807
  //#region src/mol-array.ts
@@ -3919,6 +3868,14 @@ const buildCxSmilesRawOptions = (options) => {
3919
3868
  return raw;
3920
3869
  };
3921
3870
 
3871
+ //#endregion
3872
+ //#region src/formats/pickle.ts
3873
+ const buildGetMolAsUint8ArrayOptions = (options) => {
3874
+ const raw = {};
3875
+ for (const key of options) raw[key] = true;
3876
+ return { propertyFlags: raw };
3877
+ };
3878
+
3922
3879
  //#endregion
3923
3880
  //#region src/mol.ts
3924
3881
  /**
@@ -3931,7 +3888,7 @@ const buildCxSmilesRawOptions = (options) => {
3931
3888
  * Implements `Disposable` for use with the `using` keyword:
3932
3889
  * ```ts
3933
3890
  * using mol = rdkit.getMol('c1ccccc1')!;
3934
- * const svg = mol.getSvg();
3891
+ * const svg = mol.getSVG();
3935
3892
  * // mol is automatically deleted when the scope exits
3936
3893
  * ```
3937
3894
  */
@@ -4022,12 +3979,19 @@ var Mol = class Mol {
4022
3979
  const inchi = this.getInchi(args);
4023
3980
  return this.#module.get_inchikey_for_inchi(inchi);
4024
3981
  }
4025
- /** Returns the parsed JSON representation of the molecule */
4026
- getJson() {
3982
+ /**
3983
+ * Returns the serialized JSON representation of the molecule
3984
+ * Based on the CommonChem specifications @link https://github.com/CommonChem/CommonChem
3985
+ * */
3986
+ getJSON() {
4027
3987
  return JSON.parse(this.jsMol.get_json());
4028
3988
  }
4029
- /** Returns an unsigned integer array representation of the molecule */
4030
- getAsUint8Array() {
3989
+ /** Returns a binary representation of the molecule (pickle) as an unsigned integer array */
3990
+ getAsUint8Array(options) {
3991
+ if (options?.properties) {
3992
+ const rawOptions = buildGetMolAsUint8ArrayOptions(options.properties);
3993
+ return this.jsMol.get_as_uint8array(JSON.stringify(rawOptions));
3994
+ }
4031
3995
  return this.jsMol.get_as_uint8array();
4032
3996
  }
4033
3997
  /**
@@ -4038,15 +4002,15 @@ var Mol = class Mol {
4038
4002
  *
4039
4003
  * @example
4040
4004
  * // Default SVG
4041
- * const svg = mol.getSvg();
4005
+ * const svg = mol.getSVG();
4042
4006
  *
4043
4007
  * // Custom size with atom indices
4044
- * const svg = mol.getSvg({ width: 400, height: 300, addAtomIndices: true });
4008
+ * const svg = mol.getSVG({ width: 400, height: 300, addAtomIndices: true });
4045
4009
  *
4046
4010
  * // With atom highlighting
4047
- * const svg = mol.getSvg({ atoms: [0, 1, 2], highlightColour: [1, 0, 0, 1] });
4011
+ * const svg = mol.getSVG({ atoms: [0, 1, 2], highlightColour: [1, 0, 0, 1] });
4048
4012
  */
4049
- getSvg(options) {
4013
+ getSVG(options) {
4050
4014
  const mol = this.jsMol;
4051
4015
  if (!options) return mol.get_svg();
4052
4016
  return mol.get_svg_with_highlights(JSON.stringify(options));
@@ -4158,6 +4122,17 @@ var Mol = class Mol {
4158
4122
  return this.jsMol.get_maccs_fp_as_uint8array();
4159
4123
  }
4160
4124
  /**
4125
+ * Parses a property value string, attempting JSON.parse first.
4126
+ * Returns the parsed value on success, or the raw string on failure.
4127
+ */
4128
+ parsePropValue(value) {
4129
+ try {
4130
+ return JSON.parse(value);
4131
+ } catch {
4132
+ return value;
4133
+ }
4134
+ }
4135
+ /**
4161
4136
  * Checks whether the molecule has a given property
4162
4137
  * @param key - Property name
4163
4138
  */
@@ -4165,11 +4140,12 @@ var Mol = class Mol {
4165
4140
  return this.jsMol.has_prop(key);
4166
4141
  }
4167
4142
  /**
4168
- * Gets a property value from the molecule
4143
+ * Gets a property value from the molecule.
4144
+ * Attempts to parse the raw string as JSON; returns the raw string if parsing fails.
4169
4145
  * @param key - Property name
4170
4146
  */
4171
4147
  getProp(key) {
4172
- return this.jsMol.get_prop(key);
4148
+ return this.parsePropValue(this.jsMol.get_prop(key));
4173
4149
  }
4174
4150
  /**
4175
4151
  * Sets a property on the molecule
@@ -4187,14 +4163,18 @@ var Mol = class Mol {
4187
4163
  return this.jsMol.clear_prop(key);
4188
4164
  }
4189
4165
  /**
4190
- * Returns the list of property names
4166
+ * Returns a map of all property names to their parsed values.
4167
+ * Values are parsed from JSON when possible, otherwise returned as raw strings.
4191
4168
  * @param options - Filter options
4192
4169
  */
4193
- getPropList(options) {
4170
+ getPropMap(options) {
4194
4171
  const mol = this.jsMol;
4195
- const sl = options ? mol.get_prop_list(options.includePrivate ?? false, options.includeComputed ?? false) : mol.get_prop_list();
4196
- const result = [];
4197
- for (let i = 0; i < sl.size(); i++) result.push(sl.get(i));
4172
+ const sl = options ? mol.get_prop_list(options.includePrivate ?? true, options.includeComputed ?? true) : mol.get_prop_list();
4173
+ const result = /* @__PURE__ */ new Map();
4174
+ for (let i = 0; i < sl.size(); i++) {
4175
+ const key = sl.get(i);
4176
+ result.set(key, this.getProp(key));
4177
+ }
4198
4178
  sl.delete();
4199
4179
  return result;
4200
4180
  }
@@ -4203,11 +4183,11 @@ var Mol = class Mol {
4203
4183
  return this.jsMol.is_valid();
4204
4184
  }
4205
4185
  /** Returns the number of atoms in the molecule */
4206
- getNumAtoms() {
4186
+ get numAtoms() {
4207
4187
  return this.jsMol.get_num_atoms();
4208
4188
  }
4209
4189
  /** Returns the number of bonds in the molecule */
4210
- getNumBonds() {
4190
+ get numBonds() {
4211
4191
  return this.jsMol.get_num_bonds();
4212
4192
  }
4213
4193
  /** Returns 0 if no coords, 2 for 2D, 3 for 3D */
@@ -4444,7 +4424,7 @@ var Reaction = class {
4444
4424
  * @param options - Drawing options including highlighting.
4445
4425
  * When omitted, uses RDKit defaults.
4446
4426
  */
4447
- getSvg(options) {
4427
+ getSVG(options) {
4448
4428
  const rxn = this.jsReaction;
4449
4429
  if (!options) return rxn.get_svg();
4450
4430
  return rxn.get_svg_with_highlights(JSON.stringify(options));
@@ -4529,24 +4509,11 @@ function decomposeRGroups(core, molecules, options, module$1) {
4529
4509
  }
4530
4510
 
4531
4511
  //#endregion
4532
- //#region src/init.ts
4512
+ //#region src/rdkit.ts
4533
4513
  /**
4534
- * Resolves the WASM URL for the current environment.
4535
- * In browsers, uses `import.meta.url` to resolve the WASM filename relative
4536
- * to the JS bundle's location — works regardless of where the page is served.
4537
- * In Node.js (e.g. vitest), the `?url` import returns a root-relative path
4538
- * like `/src/minimalib/RDKit_minimal.wasm` which needs to be joined with cwd.
4539
- */
4540
- function resolveWasmUrl() {
4541
- const url = RDKit_minimal_default;
4542
- if (typeof process !== "undefined" && process.versions != null && process.versions.node != null && url.startsWith("/") && !url.startsWith("//")) return process.cwd() + url;
4543
- return new URL(url, import.meta.url).href;
4544
- }
4545
- /**
4546
- * Initializes the RDKit WASM module and returns a typed wrapper.
4514
+ * The main RDKit wrapper providing a typed, camelCase API over the WASM module.
4547
4515
  *
4548
- * @param options - Initialization options
4549
- * @returns A promise that resolves to the RDKit wrapper
4516
+ * Instances are created via {@link initRDKit}, not directly by consumers.
4550
4517
  *
4551
4518
  * @example
4552
4519
  * ```ts
@@ -4554,70 +4521,149 @@ function resolveWasmUrl() {
4554
4521
  * const mol = rdkit.getMol('c1ccccc1');
4555
4522
  * ```
4556
4523
  */
4557
- async function initRDKit(options) {
4558
- const mod = await (0, import_RDKit_minimal.default)({ locateFile: options?.locateFile ?? (() => resolveWasmUrl()) });
4559
- return {
4560
- getMol(input, opts) {
4561
- const jsMol = opts ? mod.get_mol(input, JSON.stringify(opts)) : mod.get_mol(input);
4562
- if (!jsMol || !jsMol.is_valid()) {
4563
- jsMol?.delete();
4564
- return null;
4565
- }
4566
- return new Mol(jsMol, mod);
4567
- },
4568
- getQMol(input) {
4569
- const jsMol = mod.get_qmol(input);
4570
- if (!jsMol) return null;
4571
- return new Mol(jsMol, mod);
4572
- },
4573
- getMCS(mols, options$1) {
4574
- let molList;
4575
- if (isMolArray(mols)) molList = fromMolArraytoMolList(mols, mod);
4576
- else molList = fromStringArraytoMolList(mols, mod);
4577
- const json = options$1 ? mod.get_mcs_as_json(molList, JSON.stringify(options$1)) : mod.get_mcs_as_json(molList);
4524
+ var RDKit = class {
4525
+ #mod;
4526
+ /** @internal */
4527
+ constructor(mod) {
4528
+ this.#mod = mod;
4529
+ }
4530
+ /**
4531
+ * Creates a molecule from a variety of input formats.
4532
+ *
4533
+ * @param input - SMILES, SMARTS, MolFile, or JSON string
4534
+ * @param options - Molecule parsing options
4535
+ * @returns A Mol instance, or null if the input is invalid
4536
+ */
4537
+ getMol(input, options) {
4538
+ let jsMol;
4539
+ if (input instanceof Uint8Array) {
4540
+ if (options) console.warn("Options are ignored when getMol is called with a binary input (pikkle).");
4541
+ jsMol = this.#mod.get_mol_from_uint8array(input);
4542
+ } else jsMol = options ? this.#mod.get_mol(input, JSON.stringify(options)) : this.#mod.get_mol(input);
4543
+ if (!jsMol) return null;
4544
+ return new Mol(jsMol, this.#mod);
4545
+ }
4546
+ /**
4547
+ * Creates a query molecule from a SMARTS string.
4548
+ *
4549
+ * @param input - SMARTS string
4550
+ * @returns A Mol instance, or null if the input is invalid
4551
+ */
4552
+ getQMol(input) {
4553
+ const jsMol = this.#mod.get_qmol(input);
4554
+ if (!jsMol) return null;
4555
+ return new Mol(jsMol, this.#mod);
4556
+ }
4557
+ /**
4558
+ * Computes the Maximum Common Substructure (MCS) of a set of molecules.
4559
+ *
4560
+ * @param mols - An array of Mol instances or SMILES strings
4561
+ * @param options - MCS algorithm options
4562
+ * @returns An MCSResult with match info and a lazy `qmol` getter
4563
+ */
4564
+ getMCS(mols, options) {
4565
+ let molList;
4566
+ if (mols.length < 2) throw new Error("getMCS requires at least 2 molecules");
4567
+ if (isMolArray(mols)) molList = fromMolArraytoMolList(mols, this.#mod);
4568
+ else molList = fromStringArraytoMolList(mols, this.#mod);
4569
+ if (molList.size() < 2) {
4578
4570
  molList.delete();
4579
- const parsed = JSON.parse(json);
4580
- let cachedQmol;
4581
- return {
4582
- ...parsed,
4583
- get qmol() {
4584
- if (cachedQmol !== void 0) return cachedQmol;
4585
- const s = Array.isArray(parsed.smarts) ? parsed.smarts[0] : parsed.smarts;
4586
- if (!s) {
4587
- cachedQmol = null;
4588
- return null;
4589
- }
4590
- const jsMol = mod.get_qmol(s);
4591
- cachedQmol = jsMol ? new Mol(jsMol, mod) : null;
4592
- return cachedQmol;
4571
+ throw new Error("getMCS requires at least 2 valid molecules");
4572
+ }
4573
+ const json = options ? this.#mod.get_mcs_as_json(molList, JSON.stringify(options)) : this.#mod.get_mcs_as_json(molList);
4574
+ molList.delete();
4575
+ const parsed = JSON.parse(json);
4576
+ let cachedQmol;
4577
+ const mod = this.#mod;
4578
+ return {
4579
+ ...parsed,
4580
+ get qmol() {
4581
+ if (cachedQmol !== void 0) return cachedQmol;
4582
+ const s = Array.isArray(parsed.smarts) ? parsed.smarts[0] : parsed.smarts;
4583
+ if (!s) {
4584
+ cachedQmol = null;
4585
+ return null;
4593
4586
  }
4594
- };
4595
- },
4596
- getRxn(input, options$1) {
4597
- try {
4598
- const jsRxn = options$1 ? mod.get_rxn(input, JSON.stringify(options$1)) : mod.get_rxn(input);
4599
- if (!jsRxn) return null;
4600
- return new Reaction(jsRxn, mod);
4601
- } catch {
4602
- return null;
4587
+ const jsMol = mod.get_qmol(s);
4588
+ cachedQmol = jsMol ? new Mol(jsMol, mod) : null;
4589
+ return cachedQmol;
4603
4590
  }
4604
- },
4605
- getRGD(core, molecules, options$1) {
4606
- return decomposeRGroups(core, molecules, options$1, mod);
4607
- },
4608
- molzip(mol1, mol2) {
4609
- const jsMol = mod.molzip(mol1.jsMol, mol2.jsMol);
4610
- if (!jsMol) return null;
4611
- return new Mol(jsMol, mod);
4612
- },
4613
- get version() {
4614
- return mod.version();
4615
- },
4616
- get module() {
4617
- return mod;
4591
+ };
4592
+ }
4593
+ /**
4594
+ * Creates a Reaction from a reaction SMARTS, SMILES, or RXN block.
4595
+ *
4596
+ * @param input - Reaction SMARTS, SMILES, or RXN block string
4597
+ * @param options - Reaction parsing options
4598
+ * @returns A Reaction instance, or null if the input is invalid
4599
+ */
4600
+ getRxn(input, options) {
4601
+ try {
4602
+ const jsRxn = options ? this.#mod.get_rxn(input, JSON.stringify(options)) : this.#mod.get_rxn(input);
4603
+ if (!jsRxn) return null;
4604
+ return new Reaction(jsRxn, this.#mod);
4605
+ } catch {
4606
+ return null;
4618
4607
  }
4619
- };
4608
+ }
4609
+ /**
4610
+ * Performs R-Group Decomposition on a set of molecules against one or more cores.
4611
+ *
4612
+ * **WARNING:** The caller is responsible for deleting each `Mol` in the
4613
+ * returned rows (via `.delete()` or `using`) to avoid memory leaks.
4614
+ *
4615
+ * @param core - Core structure(s): a SMARTS string, an array of SMARTS strings,
4616
+ * a Mol instance, or an array of Mol instances
4617
+ * @param molecules - Molecules to decompose: an array of SMILES strings or Mol instances
4618
+ * @param options - R-Group decomposition options
4619
+ * @returns An array of rows, one per molecule. Each row maps R-group labels
4620
+ * (`Core`, `R1`, `R2`, …) to Mol instances.
4621
+ */
4622
+ getRGD(core, molecules, options) {
4623
+ return decomposeRGroups(core, molecules, options, this.#mod);
4624
+ }
4625
+ molzip(mol1, mol2) {
4626
+ const jsMol = this.#mod.molzip(mol1.jsMol, mol2.jsMol);
4627
+ if (!jsMol) return null;
4628
+ return new Mol(jsMol, this.#mod);
4629
+ }
4630
+ /** Returns the RDKit version string */
4631
+ get version() {
4632
+ return this.#mod.version();
4633
+ }
4634
+ /** The underlying RDKitModule for direct access to the raw API */
4635
+ get module() {
4636
+ return this.#mod;
4637
+ }
4638
+ };
4639
+
4640
+ //#endregion
4641
+ //#region src/init.ts
4642
+ /**
4643
+ * Resolves the WASM URL for the current environment.
4644
+ * In browsers, uses `import.meta.url` to resolve the WASM filename relative
4645
+ * to the JS bundle's location — works regardless of where the page is served.
4646
+ */
4647
+ function resolveWasmUrl() {
4648
+ const url = RDKit_minimal_default;
4649
+ return new URL(url, import.meta.url).href;
4650
+ }
4651
+ async function initRDKit(options, constructor = RDKit) {
4652
+ const locateFile = options?.locateFile ?? (() => resolveWasmUrl());
4653
+ const moduleArgs = { locateFile };
4654
+ if (typeof process !== "undefined" && process.versions?.node) {
4655
+ const fs = await import("node:fs");
4656
+ const { fileURLToPath } = await import("node:url");
4657
+ const wasmFileUrl = locateFile();
4658
+ let wasmPath = wasmFileUrl.startsWith("file://") ? fileURLToPath(wasmFileUrl) : wasmFileUrl;
4659
+ if (!fs.existsSync(wasmPath)) {
4660
+ const { join } = await import("node:path");
4661
+ wasmPath = join(process.cwd(), wasmPath);
4662
+ }
4663
+ moduleArgs.wasmBinary = fs.readFileSync(wasmPath);
4664
+ }
4665
+ return new constructor(await (0, import_RDKit_minimal.default)(moduleArgs));
4620
4666
  }
4621
4667
 
4622
4668
  //#endregion
4623
- export { Mol, MolArray, Reaction, initRDKit };
4669
+ export { Mol, MolArray, RDKit, Reaction, initRDKit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rdkit-esm",
3
- "version": "0.1.0",
3
+ "version": "0.2.2-rc.0",
4
4
  "description": "RDKit minimal lib for the modern web.",
5
5
  "homepage": "https://github.com/tandemai/rdkit-esm#readme",
6
6
  "bugs": {