@kent-tokyo/chematic 0.1.4 → 0.1.9

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
@@ -2,38 +2,66 @@
2
2
 
3
3
  WebAssembly bindings for [chematic](https://github.com/kent-tokyo/chematic), a pure-Rust cheminformatics library.
4
4
 
5
- This crate exposes `#[wasm_bindgen]` bindings so that chematic can be used directly from JavaScript and TypeScript in the browser or Node.js.
5
+ Published to npm as [`@kent-tokyo/chematic`](https://www.npmjs.com/package/@kent-tokyo/chematic).
6
+
7
+ ## Installation
8
+
9
+ ```sh
10
+ npm install @kent-tokyo/chematic
11
+ ```
6
12
 
7
13
  ## Features
8
14
 
9
15
  - Parse SMILES strings into molecule handles
10
- - Compute molecular descriptors: molecular weight, TPSA, formula, heavy atom count, H-bond donors/acceptors
16
+ - Molecular descriptors: MW, TPSA, LogP, Fsp3, QED, exact mass, rotatable bonds, HBD/HBA, aromatic ring count
11
17
  - Lipinski Rule-of-Five check
12
18
  - Canonical SMILES generation
13
- - ECFP4 fingerprints and Tanimoto similarity
19
+ - ECFP4, AtomPair, and Topological Torsion fingerprints with Tanimoto similarity
20
+ - BRICS fragment count
14
21
 
15
22
  ## Usage
16
23
 
17
- Build with [wasm-pack](https://rustwasm.github.io/wasm-pack/):
24
+ ```js
25
+ import init, {
26
+ parse_smiles,
27
+ tanimoto_ecfp4,
28
+ tanimoto_atom_pair,
29
+ tanimoto_torsion,
30
+ brics_fragment_count,
31
+ } from '@kent-tokyo/chematic';
18
32
 
19
- ```sh
20
- wasm-pack build --target web
21
- ```
33
+ await init();
22
34
 
23
- Then in JavaScript/TypeScript:
35
+ const mol = parse_smiles('CC(=O)Oc1ccccc1C(=O)O'); // aspirin
24
36
 
25
- ```js
26
- import init, { parse_smiles, tanimoto_ecfp4 } from './pkg/chematic_wasm.js';
37
+ // Descriptors
38
+ console.log(mol.atom_count()); // 13
39
+ console.log(mol.molecular_weight()); // ~180.16
40
+ console.log(mol.formula()); // "C9H8O4"
41
+ console.log(mol.tpsa()); // ~63.6
42
+ console.log(mol.logp_crippen()); // ~1.2
43
+ console.log(mol.fsp3()); // ~0.111
44
+ console.log(mol.qed()); // drug-likeness score [0, 1]
45
+ console.log(mol.exact_mass()); // ~180.042
46
+ console.log(mol.hbd_count()); // 1
47
+ console.log(mol.hba_count()); // 4
48
+ console.log(mol.rotatable_bond_count()); // 3
49
+ console.log(mol.aromatic_ring_count()); // 1
50
+ console.log(mol.lipinski_passes()); // true
51
+ console.log(mol.canonical_smiles()); // canonical SMILES string
27
52
 
28
- await init();
53
+ // BRICS fragmentation
54
+ console.log(brics_fragment_count(mol)); // ≥ 2
29
55
 
30
- const mol = parse_smiles('c1ccccc1');
31
- console.log(mol.atom_count()); // 6
32
- console.log(mol.molecular_weight()); // ~78.11
33
- console.log(mol.formula()); // "C6H6"
34
- console.log(mol.lipinski_passes()); // true
56
+ // Fingerprint similarity
57
+ const caffeine = parse_smiles('Cn1cnc2c1c(=O)n(c(=O)n2C)C');
58
+ console.log(tanimoto_ecfp4(mol, caffeine)); // ECFP4 Tanimoto
59
+ console.log(tanimoto_atom_pair(mol, caffeine)); // AtomPair Tanimoto
60
+ console.log(tanimoto_torsion(mol, caffeine)); // Torsion Tanimoto
61
+ ```
62
+
63
+ ## Building from source
35
64
 
36
- const aspirin = parse_smiles('CC(=O)Oc1ccccc1C(=O)O');
37
- const sim = tanimoto_ecfp4(mol, aspirin);
38
- console.log(sim); // < 1.0
65
+ ```sh
66
+ wasm-pack build --target bundler --release
39
67
  ```
@@ -1,6 +1,32 @@
1
1
  /* tslint:disable */
2
2
  /* eslint-disable */
3
3
 
4
+ /**
5
+ * Style options for [`MolHandle::depict_svg_opts`].
6
+ *
7
+ * Construct with `new DepictOptions()`, then call setters:
8
+ * ```js
9
+ * const opts = new DepictOptions();
10
+ * opts.set_background("transparent");
11
+ * opts.set_dark(true);
12
+ * opts.set_width(240);
13
+ * opts.set_height(240);
14
+ * ```
15
+ */
16
+ export class DepictOptions {
17
+ free(): void;
18
+ [Symbol.dispose](): void;
19
+ constructor();
20
+ set_background(bg: string): void;
21
+ set_dark(dark: boolean): void;
22
+ set_height(h: number): void;
23
+ set_highlight_atoms(atoms: Uint32Array): void;
24
+ set_highlight_bonds(bonds: Uint32Array): void;
25
+ set_highlight_color(color: string): void;
26
+ set_padding(p: number): void;
27
+ set_width(w: number): void;
28
+ }
29
+
4
30
  /**
5
31
  * A handle to a parsed molecule. Owns the molecule behind an `Rc` so that
6
32
  * it can be cheaply cloned on the JS side without copying atom/bond data.
@@ -17,6 +43,10 @@ export class MolHandle {
17
43
  * Number of heavy atoms (explicit atoms in the graph; does not count implicit H).
18
44
  */
19
45
  atom_count(): number;
46
+ /**
47
+ * Bertz complexity index (BertzCT).
48
+ */
49
+ bertz_ct(): number;
20
50
  /**
21
51
  * Number of bonds.
22
52
  */
@@ -25,10 +55,67 @@ export class MolHandle {
25
55
  * Canonical SMILES string.
26
56
  */
27
57
  canonical_smiles(): string;
58
+ /**
59
+ * Kier–Hall χ0 molecular connectivity index.
60
+ */
61
+ chi0(): number;
62
+ /**
63
+ * Kier–Hall χ0v valence-weighted connectivity index.
64
+ */
65
+ chi0v(): number;
66
+ /**
67
+ * Kier–Hall χ1 molecular connectivity index.
68
+ */
69
+ chi1(): number;
70
+ /**
71
+ * Kier–Hall χ1v valence-weighted connectivity index.
72
+ */
73
+ chi1v(): number;
74
+ /**
75
+ * Kier–Hall χ2 molecular connectivity index.
76
+ */
77
+ chi2(): number;
78
+ /**
79
+ * Kier–Hall χ2v valence-weighted connectivity index.
80
+ */
81
+ chi2v(): number;
82
+ /**
83
+ * Kier–Hall χ3 molecular connectivity index.
84
+ */
85
+ chi3(): number;
86
+ /**
87
+ * Kier–Hall χ3v valence-weighted connectivity index.
88
+ */
89
+ chi3v(): number;
90
+ /**
91
+ * Kier–Hall χ4 molecular connectivity index.
92
+ */
93
+ chi4(): number;
94
+ /**
95
+ * Kier–Hall χ4v valence-weighted connectivity index.
96
+ */
97
+ chi4v(): number;
98
+ /**
99
+ * 2D SVG depiction of the molecule (CPK coloring).
100
+ */
101
+ depict_svg(): string;
102
+ /**
103
+ * 2D SVG depiction with style options.
104
+ */
105
+ depict_svg_opts(opts: DepictOptions): string;
106
+ /**
107
+ * Returns `true` if the molecule passes Egan's absorption criteria
108
+ * (TPSA ≤ 131.6 Ų and LogP ≤ 5.88).
109
+ */
110
+ egan_passes(): boolean;
28
111
  /**
29
112
  * Monoisotopic (exact) mass.
30
113
  */
31
114
  exact_mass(): number;
115
+ /**
116
+ * Sum of formal charges.
117
+ */
118
+ formal_charge_sum(): number;
32
119
  /**
33
120
  * Molecular formula string (Hill notation: C first, H second, then alphabetical).
34
121
  */
@@ -37,6 +124,11 @@ export class MolHandle {
37
124
  * Fraction of sp3 carbons (Fsp3).
38
125
  */
39
126
  fsp3(): number;
127
+ /**
128
+ * Returns `true` if the molecule passes Ghose's drug-likeness filter
129
+ * (MW 160–480, LogP −0.4–5.6, HeavyAtoms 20–70, MR 40–130).
130
+ */
131
+ ghose_passes(): boolean;
40
132
  /**
41
133
  * Number of hydrogen bond acceptors (Lipinski: all N and O atoms).
42
134
  */
@@ -49,6 +141,22 @@ export class MolHandle {
49
141
  * Number of non-hydrogen heavy atoms.
50
142
  */
51
143
  heavy_atom_count(): number;
144
+ /**
145
+ * Hall–Kier κ1 shape index.
146
+ */
147
+ kappa1(): number;
148
+ /**
149
+ * Hall–Kier κ2 shape index.
150
+ */
151
+ kappa2(): number;
152
+ /**
153
+ * Hall–Kier κ3 shape index.
154
+ */
155
+ kappa3(): number;
156
+ /**
157
+ * Labute approximate surface area (Ų).
158
+ */
159
+ labute_asa(): number;
52
160
  /**
53
161
  * Returns `true` if the molecule satisfies Lipinski's Rule of Five.
54
162
  */
@@ -57,14 +165,64 @@ export class MolHandle {
57
165
  * Crippen–Wildman octanol/water partition coefficient (LogP).
58
166
  */
59
167
  logp_crippen(): number;
168
+ /**
169
+ * Wildman–Crippen molar refractivity (MR).
170
+ */
171
+ molar_refractivity(): number;
60
172
  /**
61
173
  * Average molecular weight (Da).
62
174
  */
63
175
  molecular_weight(): number;
176
+ /**
177
+ * Morgan count fingerprint as a JSON object string (`{"<hash>": count, …}`).
178
+ *
179
+ * `radius` controls the ECFP radius (2 = ECFP4-equivalent).
180
+ */
181
+ morgan_fp_counts_json(radius: number): string;
182
+ /**
183
+ * Number of non-aromatic rings containing at least one heteroatom.
184
+ */
185
+ num_aliphatic_heterocycles(): number;
186
+ /**
187
+ * Number of aromatic rings containing at least one heteroatom (N, O, S, …).
188
+ */
189
+ num_aromatic_heterocycles(): number;
190
+ /**
191
+ * Number of bridgehead atoms (shared by ≥2 rings with ≥3 ring bonds).
192
+ */
193
+ num_bridgehead_atoms(): number;
194
+ /**
195
+ * Number of heteroatoms (non-C, non-H heavy atoms).
196
+ */
197
+ num_heteroatoms(): number;
198
+ /**
199
+ * Number of fully saturated rings containing at least one heteroatom.
200
+ */
201
+ num_saturated_heterocycles(): number;
202
+ /**
203
+ * Number of spiro atoms (sole shared atom between exactly 2 rings).
204
+ */
205
+ num_spiro_atoms(): number;
206
+ /**
207
+ * Number of assigned stereocenters (R/S).
208
+ */
209
+ num_stereocenters(): number;
210
+ /**
211
+ * Returns `true` if the molecule has no PAINS structural alerts.
212
+ */
213
+ pains_passes(): boolean;
64
214
  /**
65
215
  * Quantitative Estimate of Drug-likeness (QED); range [0, 1].
66
216
  */
67
217
  qed(): number;
218
+ /**
219
+ * Returns `true` if the molecule passes the REOS (Rapid Elimination Of Swill) filter.
220
+ */
221
+ reos_passes(): boolean;
222
+ /**
223
+ * Total number of rings (SSSR count).
224
+ */
225
+ ring_count(): number;
68
226
  /**
69
227
  * Number of rotatable bonds.
70
228
  */
@@ -73,8 +231,22 @@ export class MolHandle {
73
231
  * Topological polar surface area (Ų).
74
232
  */
75
233
  tpsa(): number;
234
+ /**
235
+ * Returns `true` if the molecule passes Veber's oral bioavailability criteria
236
+ * (TPSA ≤ 140 Ų and rotatable bonds ≤ 10).
237
+ */
238
+ veber_passes(): boolean;
239
+ /**
240
+ * Wiener topological index (sum of all pairwise shortest-path distances).
241
+ */
242
+ wiener_index(): number;
76
243
  }
77
244
 
245
+ /**
246
+ * Return a copy of the molecule with all implicit hydrogens converted to explicit H atoms.
247
+ */
248
+ export function add_hydrogens(mol: MolHandle): MolHandle;
249
+
78
250
  /**
79
251
  * Number of BRICS fragments produced by fragmenting the molecule.
80
252
  *
@@ -82,11 +254,24 @@ export class MolHandle {
82
254
  */
83
255
  export function brics_fragment_count(mol: MolHandle): number;
84
256
 
257
+ /**
258
+ * Render a grid SVG from newline-separated SMILES (one per line).
259
+ *
260
+ * Lines that fail to parse are silently skipped.
261
+ * `cols` controls the number of columns (each cell is 200×200 px).
262
+ */
263
+ export function depict_svg_grid(smiles_block: string, cols: number): string;
264
+
85
265
  /**
86
266
  * Compute the ECFP4 fingerprint as a bit-packed byte vector (256 bytes = 2048 bits).
87
267
  */
88
268
  export function ecfp4_bitvec(mol: MolHandle): Uint8Array;
89
269
 
270
+ /**
271
+ * Returns `true` if the SMILES string can be parsed without error.
272
+ */
273
+ export function is_valid_smiles(s: string): boolean;
274
+
90
275
  /**
91
276
  * Parse a SMILES string into a `MolHandle`.
92
277
  *
@@ -94,6 +279,20 @@ export function ecfp4_bitvec(mol: MolHandle): Uint8Array;
94
279
  */
95
280
  export function parse_smiles(s: string): MolHandle;
96
281
 
282
+ /**
283
+ * Return a copy of the molecule with all explicit hydrogen atoms removed.
284
+ */
285
+ export function remove_hydrogens(mol: MolHandle): MolHandle;
286
+
287
+ /**
288
+ * Apply a SMIRKS reaction template and return product SMILES as a JSON string.
289
+ *
290
+ * `reactants_smiles`: pipe-separated SMILES, one per reactant slot in the SMIRKS.
291
+ * Returns a JSON array of arrays: `[["product_smi", …], …]`.
292
+ * Returns a JS error on parse failure or arity mismatch.
293
+ */
294
+ export function run_reactants(smirks: string, reactants_smiles: string): string;
295
+
97
296
  /**
98
297
  * Tanimoto similarity between two molecules using AtomPair fingerprints.
99
298
  */
@@ -104,7 +303,119 @@ export function tanimoto_atom_pair(a: MolHandle, b: MolHandle): number;
104
303
  */
105
304
  export function tanimoto_ecfp4(a: MolHandle, b: MolHandle): number;
106
305
 
306
+ /**
307
+ * Tanimoto similarity between two molecules using FCFP4 fingerprints (pharmacophore-based).
308
+ */
309
+ export function tanimoto_fcfp4(a: MolHandle, b: MolHandle): number;
310
+
107
311
  /**
108
312
  * Tanimoto similarity between two molecules using Topological Torsion fingerprints.
109
313
  */
110
314
  export function tanimoto_torsion(a: MolHandle, b: MolHandle): number;
315
+
316
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
317
+
318
+ export interface InitOutput {
319
+ readonly memory: WebAssembly.Memory;
320
+ readonly __wbg_depictoptions_free: (a: number, b: number) => void;
321
+ readonly __wbg_molhandle_free: (a: number, b: number) => void;
322
+ readonly add_hydrogens: (a: number) => number;
323
+ readonly brics_fragment_count: (a: number) => number;
324
+ readonly depict_svg_grid: (a: number, b: number, c: number) => [number, number];
325
+ readonly depictoptions_new: () => number;
326
+ readonly depictoptions_set_background: (a: number, b: number, c: number) => void;
327
+ readonly depictoptions_set_dark: (a: number, b: number) => void;
328
+ readonly depictoptions_set_height: (a: number, b: number) => void;
329
+ readonly depictoptions_set_highlight_atoms: (a: number, b: number, c: number) => void;
330
+ readonly depictoptions_set_highlight_bonds: (a: number, b: number, c: number) => void;
331
+ readonly depictoptions_set_highlight_color: (a: number, b: number, c: number) => void;
332
+ readonly depictoptions_set_padding: (a: number, b: number) => void;
333
+ readonly depictoptions_set_width: (a: number, b: number) => void;
334
+ readonly ecfp4_bitvec: (a: number) => [number, number];
335
+ readonly is_valid_smiles: (a: number, b: number) => number;
336
+ readonly molhandle_aromatic_ring_count: (a: number) => number;
337
+ readonly molhandle_atom_count: (a: number) => number;
338
+ readonly molhandle_bertz_ct: (a: number) => number;
339
+ readonly molhandle_bond_count: (a: number) => number;
340
+ readonly molhandle_canonical_smiles: (a: number) => [number, number];
341
+ readonly molhandle_chi0: (a: number) => number;
342
+ readonly molhandle_chi0v: (a: number) => number;
343
+ readonly molhandle_chi1: (a: number) => number;
344
+ readonly molhandle_chi1v: (a: number) => number;
345
+ readonly molhandle_chi2: (a: number) => number;
346
+ readonly molhandle_chi2v: (a: number) => number;
347
+ readonly molhandle_chi3: (a: number) => number;
348
+ readonly molhandle_chi3v: (a: number) => number;
349
+ readonly molhandle_chi4: (a: number) => number;
350
+ readonly molhandle_chi4v: (a: number) => number;
351
+ readonly molhandle_depict_svg: (a: number) => [number, number];
352
+ readonly molhandle_depict_svg_opts: (a: number, b: number) => [number, number];
353
+ readonly molhandle_egan_passes: (a: number) => number;
354
+ readonly molhandle_exact_mass: (a: number) => number;
355
+ readonly molhandle_formal_charge_sum: (a: number) => number;
356
+ readonly molhandle_formula: (a: number) => [number, number];
357
+ readonly molhandle_fsp3: (a: number) => number;
358
+ readonly molhandle_ghose_passes: (a: number) => number;
359
+ readonly molhandle_hba_count: (a: number) => number;
360
+ readonly molhandle_hbd_count: (a: number) => number;
361
+ readonly molhandle_heavy_atom_count: (a: number) => number;
362
+ readonly molhandle_kappa1: (a: number) => number;
363
+ readonly molhandle_kappa2: (a: number) => number;
364
+ readonly molhandle_kappa3: (a: number) => number;
365
+ readonly molhandle_labute_asa: (a: number) => number;
366
+ readonly molhandle_lipinski_passes: (a: number) => number;
367
+ readonly molhandle_logp_crippen: (a: number) => number;
368
+ readonly molhandle_molar_refractivity: (a: number) => number;
369
+ readonly molhandle_molecular_weight: (a: number) => number;
370
+ readonly molhandle_morgan_fp_counts_json: (a: number, b: number) => [number, number];
371
+ readonly molhandle_num_aliphatic_heterocycles: (a: number) => number;
372
+ readonly molhandle_num_aromatic_heterocycles: (a: number) => number;
373
+ readonly molhandle_num_bridgehead_atoms: (a: number) => number;
374
+ readonly molhandle_num_heteroatoms: (a: number) => number;
375
+ readonly molhandle_num_saturated_heterocycles: (a: number) => number;
376
+ readonly molhandle_num_spiro_atoms: (a: number) => number;
377
+ readonly molhandle_num_stereocenters: (a: number) => number;
378
+ readonly molhandle_pains_passes: (a: number) => number;
379
+ readonly molhandle_qed: (a: number) => number;
380
+ readonly molhandle_reos_passes: (a: number) => number;
381
+ readonly molhandle_ring_count: (a: number) => number;
382
+ readonly molhandle_rotatable_bond_count: (a: number) => number;
383
+ readonly molhandle_tpsa: (a: number) => number;
384
+ readonly molhandle_veber_passes: (a: number) => number;
385
+ readonly molhandle_wiener_index: (a: number) => number;
386
+ readonly parse_smiles: (a: number, b: number) => [number, number, number];
387
+ readonly remove_hydrogens: (a: number) => number;
388
+ readonly run_reactants: (a: number, b: number, c: number, d: number) => [number, number, number, number];
389
+ readonly tanimoto_atom_pair: (a: number, b: number) => number;
390
+ readonly tanimoto_ecfp4: (a: number, b: number) => number;
391
+ readonly tanimoto_fcfp4: (a: number, b: number) => number;
392
+ readonly tanimoto_torsion: (a: number, b: number) => number;
393
+ readonly __wbindgen_externrefs: WebAssembly.Table;
394
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
395
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
396
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
397
+ readonly __externref_table_dealloc: (a: number) => void;
398
+ readonly __wbindgen_start: () => void;
399
+ }
400
+
401
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
402
+
403
+ /**
404
+ * Instantiates the given `module`, which can either be bytes or
405
+ * a precompiled `WebAssembly.Module`.
406
+ *
407
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
408
+ *
409
+ * @returns {InitOutput}
410
+ */
411
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
412
+
413
+ /**
414
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
415
+ * for everything else, calls `WebAssembly.instantiate` directly.
416
+ *
417
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
418
+ *
419
+ * @returns {Promise<InitOutput>}
420
+ */
421
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;