rdkit-esm 0.3.0-rc.0 → 0.4.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/dist/index.d.ts CHANGED
@@ -116,7 +116,7 @@ interface JSMol {
116
116
  * You can also specify the following options
117
117
  * (passed as a stringified JSON object)
118
118
  * @param {number} radius fingerprint radius
119
- * @param {number} len fingerprint length
119
+ * @param {number} nBits fingerprint length
120
120
  */
121
121
  get_morgan_fp(options: JSONString): string;
122
122
 
@@ -131,7 +131,7 @@ interface JSMol {
131
131
  * You can also specify the following options
132
132
  * (passed as a stringified JSON object)
133
133
  * @param {number} radius fingerprint radius
134
- * @param {number} fplen fingerprint length
134
+ * @param {number} nBits fingerprint length
135
135
  */
136
136
  get_morgan_fp_as_uint8array(options: JSONString): Uint8Array;
137
137
 
@@ -145,7 +145,7 @@ interface JSMol {
145
145
  *
146
146
  * you can also specify the following options
147
147
  * (passed as a stringified JSON object)
148
- * @param {number} len fingerprint length
148
+ * @param {number} nBits fingerprint length
149
149
  */
150
150
  get_pattern_fp(options: JSONString): string;
151
151
 
@@ -159,7 +159,7 @@ interface JSMol {
159
159
  *
160
160
  * you can also specify the following options
161
161
  * (passed as a stringified JSON object)
162
- * @param {number} fplen fingerprint length
162
+ * @param {number} nBits fingerprint length
163
163
  */
164
164
  get_pattern_fp_as_uint8array(options: JSONString): Uint8Array;
165
165
 
@@ -173,7 +173,7 @@ interface JSMol {
173
173
  *
174
174
  * you can also specify the following options
175
175
  * (passed as a stringified JSON object)
176
- * @param {number} len fingerprint length
176
+ * @param {number} nBits fingerprint length
177
177
  */
178
178
  get_topological_torsion_fp(options: JSONString): string;
179
179
 
@@ -187,7 +187,7 @@ interface JSMol {
187
187
  *
188
188
  * you can also specify the following options
189
189
  * (passed as a stringified JSON object)
190
- * @param {number} fplen fingerprint length
190
+ * @param {number} nBits fingerprint length
191
191
  */
192
192
  get_topological_torsion_fp_as_uint8array(options: JSONString): Uint8Array;
193
193
 
@@ -201,7 +201,7 @@ interface JSMol {
201
201
  *
202
202
  * you can also specify the following options
203
203
  * (passed as a stringified JSON object)
204
- * @param {number} len fingerprint length
204
+ * @param {number} nBits fingerprint length
205
205
  */
206
206
  get_rdkit_fp(options: JSONString): string;
207
207
 
@@ -215,7 +215,7 @@ interface JSMol {
215
215
  *
216
216
  * you can also specify the following options
217
217
  * (passed as a stringified JSON object)
218
- * @param {number} fplen fingerprint length
218
+ * @param {number} nBits fingerprint length
219
219
  */
220
220
  get_rdkit_fp_as_uint8array(options: JSONString): Uint8Array;
221
221
 
@@ -229,7 +229,7 @@ interface JSMol {
229
229
  *
230
230
  * you can also specify the following options
231
231
  * (passed as a stringified JSON object)
232
- * @param {number} len fingerprint length
232
+ * @param {number} nBits fingerprint length
233
233
  */
234
234
  get_atom_pair_fp(options: JSONString): string;
235
235
 
@@ -243,7 +243,7 @@ interface JSMol {
243
243
  *
244
244
  * you can also specify the following options
245
245
  * (passed as a stringified JSON object)
246
- * @param {number} fplen fingerprint length
246
+ * @param {number} nBits fingerprint length
247
247
  */
248
248
  get_atom_pair_fp_as_uint8array(options: JSONString): Uint8Array;
249
249
 
@@ -257,7 +257,7 @@ interface JSMol {
257
257
  *
258
258
  * you can also specify the following options
259
259
  * (passed as a stringified JSON object)
260
- * @param {number} len fingerprint length
260
+ * @param {number} nBits fingerprint length
261
261
  */
262
262
  get_maccs_fp(options: JSONString): string;
263
263
 
@@ -649,7 +649,6 @@ interface RDKitModule {
649
649
  * @param input SMARTS string
650
650
  */
651
651
  get_qmol(input: string): JSMol | null;
652
- get_qmol(input: string, details_json?: string): JSMol | null;
653
652
 
654
653
  /**
655
654
  * Create a reaction instance
@@ -1174,6 +1173,23 @@ type RDKitGetUint8ArrayOptions = {
1174
1173
  properties: PropertyPickleOptionsKeys[];
1175
1174
  };
1176
1175
  //#endregion
1176
+ //#region src/fingerprints/fingerprints.types.d.ts
1177
+ type FingerprintType = 'Morgan' | 'Pattern' | 'AtomPair' | 'TopologicalTorsion' | 'RDKit' | 'MACCS';
1178
+ type SimilarityMetric = 'tanimoto';
1179
+ //#endregion
1180
+ //#region src/fingerprints/fingerprint.d.ts
1181
+ declare class Fingerprint {
1182
+ readonly nBits: number;
1183
+ readonly fpU32: Uint32Array;
1184
+ readonly fpU8: Uint8Array;
1185
+ private _onBits;
1186
+ type?: FingerprintType;
1187
+ constructor(fpU8: Uint8Array, nBits?: number, type?: FingerprintType);
1188
+ get onBits(): number;
1189
+ get uint8Array(): Uint8Array<ArrayBufferLike>;
1190
+ toString(): string;
1191
+ }
1192
+ //#endregion
1177
1193
  //#region src/mol.d.ts
1178
1194
  /**
1179
1195
  * A wrapper around RDKit's JSMol object providing a typed, camelCase API.
@@ -1283,29 +1299,17 @@ declare class Mol implements Disposable {
1283
1299
  * Returns the Morgan fingerprint as a bit string
1284
1300
  * @param options - Fingerprint options
1285
1301
  */
1286
- getMorganFp(options?: Partial<RDKitMorganFPOptions>): string;
1302
+ getMorganFp(options?: Partial<RDKitMorganFPOptions>): Fingerprint;
1287
1303
  /** Returns the pattern fingerprint as a bit string */
1288
- getPatternFp(options?: Partial<RDKitPatternFPOptions>): string;
1304
+ getPatternFp(options?: Partial<RDKitPatternFPOptions>): Fingerprint;
1289
1305
  /** Returns the topological torsion fingerprint as a bit string */
1290
- getTopologicalTorsionFp(options?: Partial<RDKitTopologicalTorsionFPOptions>): string;
1306
+ getTopologicalTorsionFp(options?: Partial<RDKitTopologicalTorsionFPOptions>): Fingerprint;
1291
1307
  /** Returns the RDKit fingerprint as a bit string */
1292
- getRdkitFp(options?: Partial<RDKitRdkitFpOptions>): string;
1308
+ getRdkitFp(options?: Partial<RDKitRdkitFpOptions>): Fingerprint;
1293
1309
  /** Returns the atom pair fingerprint as a bit string */
1294
- getAtomPairFp(options?: Partial<RDKitAtomPairFPOptions>): string;
1310
+ getAtomPairFp(options?: Partial<RDKitAtomPairFPOptions>): Fingerprint;
1295
1311
  /** Returns the MACCS fingerprint as a bit string (fixed 167-bit) */
1296
- getMaccsFp(): string;
1297
- /** Returns the Morgan fingerprint as a Uint8Array */
1298
- getMorganFpAsUint8Array(options?: Partial<RDKitMorganFPOptions>): Uint8Array;
1299
- /** Returns the pattern fingerprint as a Uint8Array */
1300
- getPatternFpAsUint8Array(options?: Partial<RDKitPatternFPOptions>): Uint8Array;
1301
- /** Returns the topological torsion fingerprint as a Uint8Array */
1302
- getTopologicalTorsionFpAsUint8Array(options?: Partial<RDKitTopologicalTorsionFPOptions>): Uint8Array;
1303
- /** Returns the RDKit fingerprint as a Uint8Array */
1304
- getRdkitFpAsUint8Array(options?: Partial<RDKitRdkitFpOptions>): Uint8Array;
1305
- /** Returns the atom pair fingerprint as a Uint8Array */
1306
- getAtomPairFpAsUint8Array(options?: Partial<RDKitAtomPairFPOptions>): Uint8Array;
1307
- /** Returns the MACCS fingerprint as a Uint8Array */
1308
- getMaccsFpAsUint8Array(): Uint8Array;
1312
+ getMaccsFp(): Fingerprint;
1309
1313
  /**
1310
1314
  * Parses a property value string, attempting JSON.parse first.
1311
1315
  * Returns the parsed value on success, or the raw string on failure.
@@ -1508,6 +1512,9 @@ declare class Reaction implements Disposable {
1508
1512
  */
1509
1513
  type RGDRow = Record<string, Mol>;
1510
1514
  //#endregion
1515
+ //#region src/fingerprints/bitops.d.ts
1516
+ declare const computeFingerprintSimilarity: (a: Fingerprint, b: Fingerprint, metric?: SimilarityMetric) => number;
1517
+ //#endregion
1511
1518
  //#region src/rdkit.d.ts
1512
1519
  /** Result of a Maximum Common Substructure (MCS) computation */
1513
1520
  interface MCSResult {
@@ -1586,6 +1593,7 @@ declare class RDKit {
1586
1593
  */
1587
1594
  getRGD(core: string | string[] | Mol | Mol[], molecules: string[] | Mol[], options?: Partial<RDKitGetRgdOptions>): RGDRow[] | null;
1588
1595
  molzip(mol1: Mol, mol2: Mol): Mol | null;
1596
+ computeFingerprintsSimilarity(...args: Parameters<typeof computeFingerprintSimilarity>): number;
1589
1597
  /** Returns the RDKit version string */
1590
1598
  get version(): string;
1591
1599
  /** The underlying RDKitModule for direct access to the raw API */
@@ -1633,4 +1641,4 @@ interface InitRDKitOptions {
1633
1641
  declare function initRDKit(options?: Partial<InitRDKitOptions>): Promise<RDKit>;
1634
1642
  declare function initRDKit<T extends typeof RDKit>(options: Partial<InitRDKitOptions> | undefined, constructor: T): Promise<InstanceType<T>>;
1635
1643
  //#endregion
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 };
1644
+ export { Fingerprint, 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
@@ -3913,6 +3913,67 @@ const buildGetMolAsUint8ArrayOptions = (options) => {
3913
3913
  return { propertyFlags: raw };
3914
3914
  };
3915
3915
 
3916
+ //#endregion
3917
+ //#region src/fingerprints/bitops.ts
3918
+ /**
3919
+ * From FastBitSet
3920
+ * @link https://github.com/lemire/FastBitSet.js
3921
+ *
3922
+ * Compute the Hamming weight of a 32-bit unsigned integer
3923
+ */
3924
+ const hammingWeight = (v) => {
3925
+ v -= v >>> 1 & 1431655765;
3926
+ v = (v & 858993459) + (v >>> 2 & 858993459);
3927
+ return (v + (v >>> 4) & 252645135) * 16843009 >>> 24;
3928
+ };
3929
+ const computeFingerprintSimilarity = (a, b, metric) => {
3930
+ if (a.nBits !== b.nBits) throw new Error("Fingerprints must be of the same length");
3931
+ switch (metric) {
3932
+ case "tanimoto": return tanimotoSimilarity(a, b);
3933
+ default: throw new Error(`Unsupported similarity metric: ${metric}`);
3934
+ }
3935
+ };
3936
+ const tanimotoSimilarity = (a, b) => {
3937
+ let interBits = 0;
3938
+ for (let i = 0; i < a.fpU32.length; i++) interBits += hammingWeight(a.fpU32[i] & b.fpU32[i]);
3939
+ return interBits / (a.onBits + b.onBits - interBits);
3940
+ };
3941
+
3942
+ //#endregion
3943
+ //#region src/fingerprints/fingerprint.ts
3944
+ var Fingerprint = class {
3945
+ nBits;
3946
+ fpU32;
3947
+ fpU8;
3948
+ _onBits = null;
3949
+ type;
3950
+ constructor(fpU8, nBits, type) {
3951
+ this.nBits = nBits ?? fpU8.length * 8;
3952
+ this.type = type;
3953
+ this.fpU8 = fpU8;
3954
+ if (fpU8.length % 4) {
3955
+ const padded = new Uint8Array(fpU8.length + (4 - fpU8.length % 4));
3956
+ padded.set(fpU8);
3957
+ this.fpU32 = new Uint32Array(padded.buffer);
3958
+ } else this.fpU32 = new Uint32Array(fpU8.buffer);
3959
+ }
3960
+ get onBits() {
3961
+ if (this._onBits !== null) return this._onBits;
3962
+ let count = 0;
3963
+ for (let i = 0; i < this.fpU32.length; i++) count += hammingWeight(this.fpU32[i]);
3964
+ this._onBits = count;
3965
+ return this._onBits;
3966
+ }
3967
+ get uint8Array() {
3968
+ return this.fpU8;
3969
+ }
3970
+ toString() {
3971
+ const pieces = [];
3972
+ for (const byte of this.fpU8) pieces.push(...byte.toString(2).split("").reverse());
3973
+ return pieces.join("").substring(0, this.nBits);
3974
+ }
3975
+ };
3976
+
3916
3977
  //#endregion
3917
3978
  //#region src/mol.ts
3918
3979
  /**
@@ -4103,60 +4164,31 @@ var Mol = class Mol {
4103
4164
  */
4104
4165
  getMorganFp(options) {
4105
4166
  const mol = this.jsMol;
4106
- return options ? mol.get_morgan_fp(JSON.stringify(options)) : mol.get_morgan_fp();
4167
+ return new Fingerprint(options ? mol.get_morgan_fp_as_uint8array(JSON.stringify(options)) : mol.get_morgan_fp_as_uint8array(), options?.nBits, "Morgan");
4107
4168
  }
4108
4169
  /** Returns the pattern fingerprint as a bit string */
4109
4170
  getPatternFp(options) {
4110
4171
  const mol = this.jsMol;
4111
- return options ? mol.get_pattern_fp(JSON.stringify(options)) : mol.get_pattern_fp();
4172
+ return new Fingerprint(options ? mol.get_pattern_fp_as_uint8array(JSON.stringify(options)) : mol.get_pattern_fp_as_uint8array(), options?.nBits, "Pattern");
4112
4173
  }
4113
4174
  /** Returns the topological torsion fingerprint as a bit string */
4114
4175
  getTopologicalTorsionFp(options) {
4115
4176
  const mol = this.jsMol;
4116
- return options ? mol.get_topological_torsion_fp(JSON.stringify(options)) : mol.get_topological_torsion_fp();
4177
+ return new Fingerprint(options ? mol.get_topological_torsion_fp_as_uint8array(JSON.stringify(options)) : mol.get_topological_torsion_fp_as_uint8array(), options?.nBits, "TopologicalTorsion");
4117
4178
  }
4118
4179
  /** Returns the RDKit fingerprint as a bit string */
4119
4180
  getRdkitFp(options) {
4120
4181
  const mol = this.jsMol;
4121
- return options ? mol.get_rdkit_fp(JSON.stringify(options)) : mol.get_rdkit_fp();
4182
+ return new Fingerprint(options ? mol.get_rdkit_fp_as_uint8array(JSON.stringify(options)) : mol.get_rdkit_fp_as_uint8array(), options?.nBits, "RDKit");
4122
4183
  }
4123
4184
  /** Returns the atom pair fingerprint as a bit string */
4124
4185
  getAtomPairFp(options) {
4125
4186
  const mol = this.jsMol;
4126
- return options ? mol.get_atom_pair_fp(JSON.stringify(options)) : mol.get_atom_pair_fp();
4187
+ return new Fingerprint(options ? mol.get_atom_pair_fp_as_uint8array(JSON.stringify(options)) : mol.get_atom_pair_fp_as_uint8array(), options?.nBits, "AtomPair");
4127
4188
  }
4128
4189
  /** Returns the MACCS fingerprint as a bit string (fixed 167-bit) */
4129
4190
  getMaccsFp() {
4130
- return this.jsMol.get_maccs_fp();
4131
- }
4132
- /** Returns the Morgan fingerprint as a Uint8Array */
4133
- getMorganFpAsUint8Array(options) {
4134
- const mol = this.jsMol;
4135
- return options ? mol.get_morgan_fp_as_uint8array(JSON.stringify(options)) : mol.get_morgan_fp_as_uint8array();
4136
- }
4137
- /** Returns the pattern fingerprint as a Uint8Array */
4138
- getPatternFpAsUint8Array(options) {
4139
- const mol = this.jsMol;
4140
- return options ? mol.get_pattern_fp_as_uint8array(JSON.stringify(options)) : mol.get_pattern_fp_as_uint8array();
4141
- }
4142
- /** Returns the topological torsion fingerprint as a Uint8Array */
4143
- getTopologicalTorsionFpAsUint8Array(options) {
4144
- const mol = this.jsMol;
4145
- return options ? mol.get_topological_torsion_fp_as_uint8array(JSON.stringify(options)) : mol.get_topological_torsion_fp_as_uint8array();
4146
- }
4147
- /** Returns the RDKit fingerprint as a Uint8Array */
4148
- getRdkitFpAsUint8Array(options) {
4149
- const mol = this.jsMol;
4150
- return options ? mol.get_rdkit_fp_as_uint8array(JSON.stringify(options)) : mol.get_rdkit_fp_as_uint8array();
4151
- }
4152
- /** Returns the atom pair fingerprint as a Uint8Array */
4153
- getAtomPairFpAsUint8Array(options) {
4154
- const mol = this.jsMol;
4155
- return options ? mol.get_atom_pair_fp_as_uint8array(JSON.stringify(options)) : mol.get_atom_pair_fp_as_uint8array();
4156
- }
4157
- /** Returns the MACCS fingerprint as a Uint8Array */
4158
- getMaccsFpAsUint8Array() {
4159
- return this.jsMol.get_maccs_fp_as_uint8array();
4191
+ return new Fingerprint(this.jsMol.get_maccs_fp_as_uint8array(), 167, "MACCS");
4160
4192
  }
4161
4193
  /**
4162
4194
  * Parses a property value string, attempting JSON.parse first.
@@ -4664,6 +4696,9 @@ var RDKit = class {
4664
4696
  if (!jsMol) return null;
4665
4697
  return new Mol(jsMol, this.#mod);
4666
4698
  }
4699
+ computeFingerprintsSimilarity(...args) {
4700
+ return computeFingerprintSimilarity(...args);
4701
+ }
4667
4702
  /** Returns the RDKit version string */
4668
4703
  get version() {
4669
4704
  return this.#mod.version();
@@ -4703,4 +4738,4 @@ async function initRDKit(options, constructor = RDKit) {
4703
4738
  }
4704
4739
 
4705
4740
  //#endregion
4706
- export { Mol, MolArray, RDKit, Reaction, initRDKit };
4741
+ export { Fingerprint, Mol, MolArray, RDKit, Reaction, initRDKit };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "rdkit-esm",
3
- "version": "0.3.0-rc.0",
3
+ "version": "0.4.0",
4
4
  "description": "RDKit minimal lib for the modern web.",
5
5
  "homepage": "https://github.com/tandemai/rdkit-esm#readme",
6
6
  "bugs": {