rdkit-esm 0.1.0 → 0.2.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 +4 -4
- package/dist/index.d.ts +107 -49
- package/dist/index.js +182 -95
- package/package.json +1 -1
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.
|
|
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()`, `
|
|
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** — `
|
|
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
|
-
| `
|
|
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
|
-
//
|
|
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
|
|
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.
|
|
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
|
-
/**
|
|
1227
|
-
|
|
1228
|
-
|
|
1229
|
-
|
|
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.
|
|
1257
|
+
* const svg = mol.getSVG();
|
|
1239
1258
|
*
|
|
1240
1259
|
* // Custom size with atom indices
|
|
1241
|
-
* const svg = mol.
|
|
1260
|
+
* const svg = mol.getSVG({ width: 400, height: 300, addAtomIndices: true });
|
|
1242
1261
|
*
|
|
1243
1262
|
* // With atom highlighting
|
|
1244
|
-
* const svg = mol.
|
|
1263
|
+
* const svg = mol.getSVG({ atoms: [0, 1, 2], highlightColour: [1, 0, 0, 1] });
|
|
1245
1264
|
*/
|
|
1246
|
-
|
|
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):
|
|
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
|
|
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
|
-
|
|
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
|
-
|
|
1348
|
+
get numAtoms(): number;
|
|
1323
1349
|
/** Returns the number of bonds in the molecule */
|
|
1324
|
-
|
|
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
|
-
|
|
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/
|
|
1486
|
-
/**
|
|
1487
|
-
interface
|
|
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
|
-
*
|
|
1490
|
-
*
|
|
1491
|
-
*
|
|
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
|
-
|
|
1526
|
+
get qmol(): Mol | null;
|
|
1494
1527
|
}
|
|
1495
|
-
/**
|
|
1496
|
-
|
|
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
|
-
|
|
1592
|
+
get module(): RDKitModule;
|
|
1547
1593
|
}
|
|
1548
|
-
|
|
1549
|
-
|
|
1550
|
-
|
|
1551
|
-
|
|
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
|
-
*
|
|
1557
|
-
*
|
|
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
|
-
|
|
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,
|
|
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
|
@@ -3919,6 +3919,14 @@ const buildCxSmilesRawOptions = (options) => {
|
|
|
3919
3919
|
return raw;
|
|
3920
3920
|
};
|
|
3921
3921
|
|
|
3922
|
+
//#endregion
|
|
3923
|
+
//#region src/formats/pickle.ts
|
|
3924
|
+
const buildGetMolAsUint8ArrayOptions = (options) => {
|
|
3925
|
+
const raw = {};
|
|
3926
|
+
for (const key of options) raw[key] = true;
|
|
3927
|
+
return { propertyFlags: raw };
|
|
3928
|
+
};
|
|
3929
|
+
|
|
3922
3930
|
//#endregion
|
|
3923
3931
|
//#region src/mol.ts
|
|
3924
3932
|
/**
|
|
@@ -3931,7 +3939,7 @@ const buildCxSmilesRawOptions = (options) => {
|
|
|
3931
3939
|
* Implements `Disposable` for use with the `using` keyword:
|
|
3932
3940
|
* ```ts
|
|
3933
3941
|
* using mol = rdkit.getMol('c1ccccc1')!;
|
|
3934
|
-
* const svg = mol.
|
|
3942
|
+
* const svg = mol.getSVG();
|
|
3935
3943
|
* // mol is automatically deleted when the scope exits
|
|
3936
3944
|
* ```
|
|
3937
3945
|
*/
|
|
@@ -4022,12 +4030,19 @@ var Mol = class Mol {
|
|
|
4022
4030
|
const inchi = this.getInchi(args);
|
|
4023
4031
|
return this.#module.get_inchikey_for_inchi(inchi);
|
|
4024
4032
|
}
|
|
4025
|
-
/**
|
|
4026
|
-
|
|
4033
|
+
/**
|
|
4034
|
+
* Returns the serialized JSON representation of the molecule
|
|
4035
|
+
* Based on the CommonChem specifications @link https://github.com/CommonChem/CommonChem
|
|
4036
|
+
* */
|
|
4037
|
+
getJSON() {
|
|
4027
4038
|
return JSON.parse(this.jsMol.get_json());
|
|
4028
4039
|
}
|
|
4029
|
-
/** Returns
|
|
4030
|
-
getAsUint8Array() {
|
|
4040
|
+
/** Returns a binary representation of the molecule (pickle) as an unsigned integer array */
|
|
4041
|
+
getAsUint8Array(options) {
|
|
4042
|
+
if (options?.properties) {
|
|
4043
|
+
const rawOptions = buildGetMolAsUint8ArrayOptions(options.properties);
|
|
4044
|
+
return this.jsMol.get_as_uint8array(JSON.stringify(rawOptions));
|
|
4045
|
+
}
|
|
4031
4046
|
return this.jsMol.get_as_uint8array();
|
|
4032
4047
|
}
|
|
4033
4048
|
/**
|
|
@@ -4038,15 +4053,15 @@ var Mol = class Mol {
|
|
|
4038
4053
|
*
|
|
4039
4054
|
* @example
|
|
4040
4055
|
* // Default SVG
|
|
4041
|
-
* const svg = mol.
|
|
4056
|
+
* const svg = mol.getSVG();
|
|
4042
4057
|
*
|
|
4043
4058
|
* // Custom size with atom indices
|
|
4044
|
-
* const svg = mol.
|
|
4059
|
+
* const svg = mol.getSVG({ width: 400, height: 300, addAtomIndices: true });
|
|
4045
4060
|
*
|
|
4046
4061
|
* // With atom highlighting
|
|
4047
|
-
* const svg = mol.
|
|
4062
|
+
* const svg = mol.getSVG({ atoms: [0, 1, 2], highlightColour: [1, 0, 0, 1] });
|
|
4048
4063
|
*/
|
|
4049
|
-
|
|
4064
|
+
getSVG(options) {
|
|
4050
4065
|
const mol = this.jsMol;
|
|
4051
4066
|
if (!options) return mol.get_svg();
|
|
4052
4067
|
return mol.get_svg_with_highlights(JSON.stringify(options));
|
|
@@ -4158,6 +4173,17 @@ var Mol = class Mol {
|
|
|
4158
4173
|
return this.jsMol.get_maccs_fp_as_uint8array();
|
|
4159
4174
|
}
|
|
4160
4175
|
/**
|
|
4176
|
+
* Parses a property value string, attempting JSON.parse first.
|
|
4177
|
+
* Returns the parsed value on success, or the raw string on failure.
|
|
4178
|
+
*/
|
|
4179
|
+
parsePropValue(value) {
|
|
4180
|
+
try {
|
|
4181
|
+
return JSON.parse(value);
|
|
4182
|
+
} catch {
|
|
4183
|
+
return value;
|
|
4184
|
+
}
|
|
4185
|
+
}
|
|
4186
|
+
/**
|
|
4161
4187
|
* Checks whether the molecule has a given property
|
|
4162
4188
|
* @param key - Property name
|
|
4163
4189
|
*/
|
|
@@ -4165,11 +4191,12 @@ var Mol = class Mol {
|
|
|
4165
4191
|
return this.jsMol.has_prop(key);
|
|
4166
4192
|
}
|
|
4167
4193
|
/**
|
|
4168
|
-
* Gets a property value from the molecule
|
|
4194
|
+
* Gets a property value from the molecule.
|
|
4195
|
+
* Attempts to parse the raw string as JSON; returns the raw string if parsing fails.
|
|
4169
4196
|
* @param key - Property name
|
|
4170
4197
|
*/
|
|
4171
4198
|
getProp(key) {
|
|
4172
|
-
return this.jsMol.get_prop(key);
|
|
4199
|
+
return this.parsePropValue(this.jsMol.get_prop(key));
|
|
4173
4200
|
}
|
|
4174
4201
|
/**
|
|
4175
4202
|
* Sets a property on the molecule
|
|
@@ -4187,14 +4214,18 @@ var Mol = class Mol {
|
|
|
4187
4214
|
return this.jsMol.clear_prop(key);
|
|
4188
4215
|
}
|
|
4189
4216
|
/**
|
|
4190
|
-
* Returns
|
|
4217
|
+
* Returns a map of all property names to their parsed values.
|
|
4218
|
+
* Values are parsed from JSON when possible, otherwise returned as raw strings.
|
|
4191
4219
|
* @param options - Filter options
|
|
4192
4220
|
*/
|
|
4193
|
-
|
|
4221
|
+
getPropMap(options) {
|
|
4194
4222
|
const mol = this.jsMol;
|
|
4195
|
-
const sl = options ? mol.get_prop_list(options.includePrivate ??
|
|
4196
|
-
const result =
|
|
4197
|
-
for (let i = 0; i < sl.size(); i++)
|
|
4223
|
+
const sl = options ? mol.get_prop_list(options.includePrivate ?? true, options.includeComputed ?? true) : mol.get_prop_list();
|
|
4224
|
+
const result = /* @__PURE__ */ new Map();
|
|
4225
|
+
for (let i = 0; i < sl.size(); i++) {
|
|
4226
|
+
const key = sl.get(i);
|
|
4227
|
+
result.set(key, this.getProp(key));
|
|
4228
|
+
}
|
|
4198
4229
|
sl.delete();
|
|
4199
4230
|
return result;
|
|
4200
4231
|
}
|
|
@@ -4203,11 +4234,11 @@ var Mol = class Mol {
|
|
|
4203
4234
|
return this.jsMol.is_valid();
|
|
4204
4235
|
}
|
|
4205
4236
|
/** Returns the number of atoms in the molecule */
|
|
4206
|
-
|
|
4237
|
+
get numAtoms() {
|
|
4207
4238
|
return this.jsMol.get_num_atoms();
|
|
4208
4239
|
}
|
|
4209
4240
|
/** Returns the number of bonds in the molecule */
|
|
4210
|
-
|
|
4241
|
+
get numBonds() {
|
|
4211
4242
|
return this.jsMol.get_num_bonds();
|
|
4212
4243
|
}
|
|
4213
4244
|
/** Returns 0 if no coords, 2 for 2D, 3 for 3D */
|
|
@@ -4444,7 +4475,7 @@ var Reaction = class {
|
|
|
4444
4475
|
* @param options - Drawing options including highlighting.
|
|
4445
4476
|
* When omitted, uses RDKit defaults.
|
|
4446
4477
|
*/
|
|
4447
|
-
|
|
4478
|
+
getSVG(options) {
|
|
4448
4479
|
const rxn = this.jsReaction;
|
|
4449
4480
|
if (!options) return rxn.get_svg();
|
|
4450
4481
|
return rxn.get_svg_with_highlights(JSON.stringify(options));
|
|
@@ -4529,24 +4560,11 @@ function decomposeRGroups(core, molecules, options, module$1) {
|
|
|
4529
4560
|
}
|
|
4530
4561
|
|
|
4531
4562
|
//#endregion
|
|
4532
|
-
//#region src/
|
|
4533
|
-
/**
|
|
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
|
-
}
|
|
4563
|
+
//#region src/rdkit.ts
|
|
4545
4564
|
/**
|
|
4546
|
-
*
|
|
4565
|
+
* The main RDKit wrapper providing a typed, camelCase API over the WASM module.
|
|
4547
4566
|
*
|
|
4548
|
-
* @
|
|
4549
|
-
* @returns A promise that resolves to the RDKit wrapper
|
|
4567
|
+
* Instances are created via {@link initRDKit}, not directly by consumers.
|
|
4550
4568
|
*
|
|
4551
4569
|
* @example
|
|
4552
4570
|
* ```ts
|
|
@@ -4554,70 +4572,139 @@ function resolveWasmUrl() {
|
|
|
4554
4572
|
* const mol = rdkit.getMol('c1ccccc1');
|
|
4555
4573
|
* ```
|
|
4556
4574
|
*/
|
|
4557
|
-
|
|
4558
|
-
|
|
4559
|
-
|
|
4560
|
-
|
|
4561
|
-
|
|
4562
|
-
|
|
4563
|
-
|
|
4564
|
-
|
|
4565
|
-
|
|
4566
|
-
|
|
4567
|
-
|
|
4568
|
-
|
|
4569
|
-
|
|
4570
|
-
|
|
4571
|
-
|
|
4572
|
-
|
|
4573
|
-
|
|
4574
|
-
|
|
4575
|
-
|
|
4576
|
-
|
|
4577
|
-
|
|
4575
|
+
var RDKit = class {
|
|
4576
|
+
#mod;
|
|
4577
|
+
/** @internal */
|
|
4578
|
+
constructor(mod) {
|
|
4579
|
+
this.#mod = mod;
|
|
4580
|
+
}
|
|
4581
|
+
/**
|
|
4582
|
+
* Creates a molecule from a variety of input formats.
|
|
4583
|
+
*
|
|
4584
|
+
* @param input - SMILES, SMARTS, MolFile, or JSON string
|
|
4585
|
+
* @param options - Molecule parsing options
|
|
4586
|
+
* @returns A Mol instance, or null if the input is invalid
|
|
4587
|
+
*/
|
|
4588
|
+
getMol(input, options) {
|
|
4589
|
+
let jsMol;
|
|
4590
|
+
if (input instanceof Uint8Array) {
|
|
4591
|
+
if (options) console.warn("Options are ignored when getMol is called with a binary input (pikkle).");
|
|
4592
|
+
jsMol = this.#mod.get_mol_from_uint8array(input);
|
|
4593
|
+
} else jsMol = options ? this.#mod.get_mol(input, JSON.stringify(options)) : this.#mod.get_mol(input);
|
|
4594
|
+
if (!jsMol) return null;
|
|
4595
|
+
return new Mol(jsMol, this.#mod);
|
|
4596
|
+
}
|
|
4597
|
+
/**
|
|
4598
|
+
* Creates a query molecule from a SMARTS string.
|
|
4599
|
+
*
|
|
4600
|
+
* @param input - SMARTS string
|
|
4601
|
+
* @returns A Mol instance, or null if the input is invalid
|
|
4602
|
+
*/
|
|
4603
|
+
getQMol(input) {
|
|
4604
|
+
const jsMol = this.#mod.get_qmol(input);
|
|
4605
|
+
if (!jsMol) return null;
|
|
4606
|
+
return new Mol(jsMol, this.#mod);
|
|
4607
|
+
}
|
|
4608
|
+
/**
|
|
4609
|
+
* Computes the Maximum Common Substructure (MCS) of a set of molecules.
|
|
4610
|
+
*
|
|
4611
|
+
* @param mols - An array of Mol instances or SMILES strings
|
|
4612
|
+
* @param options - MCS algorithm options
|
|
4613
|
+
* @returns An MCSResult with match info and a lazy `qmol` getter
|
|
4614
|
+
*/
|
|
4615
|
+
getMCS(mols, options) {
|
|
4616
|
+
let molList;
|
|
4617
|
+
if (mols.length < 2) throw new Error("getMCS requires at least 2 molecules");
|
|
4618
|
+
if (isMolArray(mols)) molList = fromMolArraytoMolList(mols, this.#mod);
|
|
4619
|
+
else molList = fromStringArraytoMolList(mols, this.#mod);
|
|
4620
|
+
if (molList.size() < 2) {
|
|
4578
4621
|
molList.delete();
|
|
4579
|
-
|
|
4580
|
-
|
|
4581
|
-
|
|
4582
|
-
|
|
4583
|
-
|
|
4584
|
-
|
|
4585
|
-
|
|
4586
|
-
|
|
4587
|
-
|
|
4588
|
-
|
|
4589
|
-
|
|
4590
|
-
|
|
4591
|
-
|
|
4592
|
-
|
|
4622
|
+
throw new Error("getMCS requires at least 2 valid molecules");
|
|
4623
|
+
}
|
|
4624
|
+
const json = options ? this.#mod.get_mcs_as_json(molList, JSON.stringify(options)) : this.#mod.get_mcs_as_json(molList);
|
|
4625
|
+
molList.delete();
|
|
4626
|
+
const parsed = JSON.parse(json);
|
|
4627
|
+
let cachedQmol;
|
|
4628
|
+
const mod = this.#mod;
|
|
4629
|
+
return {
|
|
4630
|
+
...parsed,
|
|
4631
|
+
get qmol() {
|
|
4632
|
+
if (cachedQmol !== void 0) return cachedQmol;
|
|
4633
|
+
const s = Array.isArray(parsed.smarts) ? parsed.smarts[0] : parsed.smarts;
|
|
4634
|
+
if (!s) {
|
|
4635
|
+
cachedQmol = null;
|
|
4636
|
+
return null;
|
|
4593
4637
|
}
|
|
4594
|
-
|
|
4595
|
-
|
|
4596
|
-
|
|
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;
|
|
4638
|
+
const jsMol = mod.get_qmol(s);
|
|
4639
|
+
cachedQmol = jsMol ? new Mol(jsMol, mod) : null;
|
|
4640
|
+
return cachedQmol;
|
|
4603
4641
|
}
|
|
4604
|
-
}
|
|
4605
|
-
|
|
4606
|
-
|
|
4607
|
-
|
|
4608
|
-
|
|
4609
|
-
|
|
4610
|
-
|
|
4611
|
-
|
|
4612
|
-
|
|
4613
|
-
|
|
4614
|
-
|
|
4615
|
-
|
|
4616
|
-
|
|
4617
|
-
return mod;
|
|
4642
|
+
};
|
|
4643
|
+
}
|
|
4644
|
+
/**
|
|
4645
|
+
* Creates a Reaction from a reaction SMARTS, SMILES, or RXN block.
|
|
4646
|
+
*
|
|
4647
|
+
* @param input - Reaction SMARTS, SMILES, or RXN block string
|
|
4648
|
+
* @param options - Reaction parsing options
|
|
4649
|
+
* @returns A Reaction instance, or null if the input is invalid
|
|
4650
|
+
*/
|
|
4651
|
+
getRxn(input, options) {
|
|
4652
|
+
try {
|
|
4653
|
+
const jsRxn = options ? this.#mod.get_rxn(input, JSON.stringify(options)) : this.#mod.get_rxn(input);
|
|
4654
|
+
if (!jsRxn) return null;
|
|
4655
|
+
return new Reaction(jsRxn, this.#mod);
|
|
4656
|
+
} catch {
|
|
4657
|
+
return null;
|
|
4618
4658
|
}
|
|
4619
|
-
}
|
|
4659
|
+
}
|
|
4660
|
+
/**
|
|
4661
|
+
* Performs R-Group Decomposition on a set of molecules against one or more cores.
|
|
4662
|
+
*
|
|
4663
|
+
* **WARNING:** The caller is responsible for deleting each `Mol` in the
|
|
4664
|
+
* returned rows (via `.delete()` or `using`) to avoid memory leaks.
|
|
4665
|
+
*
|
|
4666
|
+
* @param core - Core structure(s): a SMARTS string, an array of SMARTS strings,
|
|
4667
|
+
* a Mol instance, or an array of Mol instances
|
|
4668
|
+
* @param molecules - Molecules to decompose: an array of SMILES strings or Mol instances
|
|
4669
|
+
* @param options - R-Group decomposition options
|
|
4670
|
+
* @returns An array of rows, one per molecule. Each row maps R-group labels
|
|
4671
|
+
* (`Core`, `R1`, `R2`, …) to Mol instances.
|
|
4672
|
+
*/
|
|
4673
|
+
getRGD(core, molecules, options) {
|
|
4674
|
+
return decomposeRGroups(core, molecules, options, this.#mod);
|
|
4675
|
+
}
|
|
4676
|
+
molzip(mol1, mol2) {
|
|
4677
|
+
const jsMol = this.#mod.molzip(mol1.jsMol, mol2.jsMol);
|
|
4678
|
+
if (!jsMol) return null;
|
|
4679
|
+
return new Mol(jsMol, this.#mod);
|
|
4680
|
+
}
|
|
4681
|
+
/** Returns the RDKit version string */
|
|
4682
|
+
get version() {
|
|
4683
|
+
return this.#mod.version();
|
|
4684
|
+
}
|
|
4685
|
+
/** The underlying RDKitModule for direct access to the raw API */
|
|
4686
|
+
get module() {
|
|
4687
|
+
return this.#mod;
|
|
4688
|
+
}
|
|
4689
|
+
};
|
|
4690
|
+
|
|
4691
|
+
//#endregion
|
|
4692
|
+
//#region src/init.ts
|
|
4693
|
+
/**
|
|
4694
|
+
* Resolves the WASM URL for the current environment.
|
|
4695
|
+
* In browsers, uses `import.meta.url` to resolve the WASM filename relative
|
|
4696
|
+
* to the JS bundle's location — works regardless of where the page is served.
|
|
4697
|
+
* In Node.js (e.g. vitest), the `?url` import returns a root-relative path
|
|
4698
|
+
* like `/src/minimalib/RDKit_minimal.wasm` which needs to be joined with cwd.
|
|
4699
|
+
*/
|
|
4700
|
+
function resolveWasmUrl() {
|
|
4701
|
+
const url = RDKit_minimal_default;
|
|
4702
|
+
if (typeof process !== "undefined" && process.versions != null && process.versions.node != null && url.startsWith("/") && !url.startsWith("//")) return process.cwd() + url;
|
|
4703
|
+
return new URL(url, import.meta.url).href;
|
|
4704
|
+
}
|
|
4705
|
+
async function initRDKit(options, constructor = RDKit) {
|
|
4706
|
+
return new constructor(await (0, import_RDKit_minimal.default)({ locateFile: options?.locateFile ?? (() => resolveWasmUrl()) }));
|
|
4620
4707
|
}
|
|
4621
4708
|
|
|
4622
4709
|
//#endregion
|
|
4623
|
-
export { Mol, MolArray, Reaction, initRDKit };
|
|
4710
|
+
export { Mol, MolArray, RDKit, Reaction, initRDKit };
|