@kent-tokyo/chematic 0.1.10 → 0.1.19

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
@@ -13,11 +13,23 @@ npm install @kent-tokyo/chematic
13
13
  ## Features
14
14
 
15
15
  - Parse SMILES strings into molecule handles
16
- - Molecular descriptors: MW, TPSA, LogP, Fsp3, QED, exact mass, rotatable bonds, HBD/HBA, aromatic ring count
17
- - Lipinski Rule-of-Five check
16
+ - Molecular descriptors: MW, TPSA, LogP, Fsp3, QED, exact mass, rotatable bonds, HBD/HBA, aromatic ring count, Labute ASA
17
+ - Drug-likeness filters: Lipinski, Veber, Egan, REOS, Ghose
18
+ - EState indices (Hall & Kier 1991): per-atom values, sum/max/min
19
+ - Gasteiger-Marsili PEOE partial charges: per-heavy-atom charges
20
+ - VSA descriptors: SlogP_VSA (×12), SMR_VSA (×10), PEOE_VSA (×14)
21
+ - SA score: synthetic accessibility estimate [1, 10]
22
+ - Functional group identification (Ertl 2017 IFG)
18
23
  - Canonical SMILES generation
19
- - ECFP4, AtomPair, and Topological Torsion fingerprints with Tanimoto similarity
24
+ - ECFP4/6, AtomPair, Torsion, and path fingerprints with Tanimoto similarity
20
25
  - BRICS fragment count
26
+ - SDF/MOL block parsing
27
+ - Topological descriptors: Wiener index, Hall-Kier κ, χ connectivity indices, Bertz CT
28
+ - Shape descriptors (with 3D coordinates): PMI, NPR, radius of gyration, asphericity
29
+ - 2D SVG depiction with CPK colors and atom/bond highlighting
30
+ - SVG grid layout for multiple molecules
31
+ - Reaction SMILES/SMIRKS parsing and transform
32
+ - Add/remove explicit hydrogens
21
33
 
22
34
  ## Usage
23
35
 
@@ -28,6 +40,11 @@ import init, {
28
40
  tanimoto_atom_pair,
29
41
  tanimoto_torsion,
30
42
  brics_fragment_count,
43
+ gasteiger_charges_json,
44
+ slogp_vsa_json,
45
+ smr_vsa_json,
46
+ peoe_vsa_json,
47
+ identify_functional_groups,
31
48
  } from '@kent-tokyo/chematic';
32
49
 
33
50
  await init();
@@ -60,6 +77,25 @@ console.log(tanimoto_atom_pair(mol, caffeine)); // AtomPair Tanimoto
60
77
  console.log(tanimoto_torsion(mol, caffeine)); // Torsion Tanimoto
61
78
  ```
62
79
 
80
+ ```js
81
+ // Sprint Q: New descriptors (v0.1.15)
82
+ console.log(mol.sa_score()); // synthetic accessibility [1,10]
83
+ console.log(mol.labute_asa()); // Labute approx. surface area (Ų)
84
+
85
+ // Gasteiger partial charges (per heavy atom)
86
+ const charges = JSON.parse(gasteiger_charges_json(mol));
87
+ console.log(charges); // [-0.08, 0.12, -0.43, ...]
88
+
89
+ // VSA descriptor bins
90
+ const slogpVsa = JSON.parse(slogp_vsa_json(mol));
91
+ const smrVsa = JSON.parse(smr_vsa_json(mol));
92
+ const peoeVsa = JSON.parse(peoe_vsa_json(mol));
93
+
94
+ // Functional group identification
95
+ const ifg = JSON.parse(identify_functional_groups(mol));
96
+ console.log(ifg); // [{"atoms":[1,2,3],"types":"OC=O"}, ...]
97
+ ```
98
+
63
99
  ## Building from source
64
100
 
65
101
  ```sh
@@ -17,6 +17,12 @@ export class DepictOptions {
17
17
  free(): void;
18
18
  [Symbol.dispose](): void;
19
19
  constructor();
20
+ /**
21
+ * Set a per-atom color override (CSS color string). Calling multiple times
22
+ * for the same `idx` uses the last value. The atom is highlighted even if
23
+ * not in `set_highlight_atoms`.
24
+ */
25
+ set_atom_color(idx: number, color: string): void;
20
26
  set_atom_ids(v: boolean): void;
21
27
  set_background(bg: string): void;
22
28
  set_dark(dark: boolean): void;
@@ -168,6 +174,14 @@ export class MolHandle {
168
174
  * Crippen–Wildman octanol/water partition coefficient (LogP).
169
175
  */
170
176
  logp_crippen(): number;
177
+ /**
178
+ * Maximum EState index across all heavy atoms.
179
+ */
180
+ max_estate(): number;
181
+ /**
182
+ * Minimum EState index across all heavy atoms.
183
+ */
184
+ min_estate(): number;
171
185
  /**
172
186
  * Wildman–Crippen molar refractivity (MR).
173
187
  */
@@ -230,6 +244,10 @@ export class MolHandle {
230
244
  * Number of rotatable bonds.
231
245
  */
232
246
  rotatable_bond_count(): number;
247
+ /**
248
+ * Sum of EState indices over all heavy atoms.
249
+ */
250
+ sum_estate(): number;
233
251
  /**
234
252
  * Topological polar surface area (Ų).
235
253
  */
@@ -257,6 +275,14 @@ export function add_hydrogens(mol: MolHandle): MolHandle;
257
275
  */
258
276
  export function brics_fragment_count(mol: MolHandle): number;
259
277
 
278
+ /**
279
+ * Render a reaction SMILES string (e.g. `"CC(=O)O.CCO>>CC(=O)OCC.O"`) as a
280
+ * single SVG showing reactants → products with `+` separators.
281
+ *
282
+ * Returns a self-contained SVG string. Returns a JS error on invalid input.
283
+ */
284
+ export function depict_reaction_svg(rxn_smiles: string): string;
285
+
260
286
  /**
261
287
  * Render a grid SVG from newline-separated SMILES (one per line).
262
288
  *
@@ -265,16 +291,110 @@ export function brics_fragment_count(mol: MolHandle): number;
265
291
  */
266
292
  export function depict_svg_grid(smiles_block: string, cols: number): string;
267
293
 
294
+ /**
295
+ * Detect named functional groups in `mol`.
296
+ *
297
+ * Returns a JSON array of `{"name":"hydroxyl","atoms":[3]}` objects.
298
+ * Multiple matches of the same group (e.g. two hydroxyl groups) each appear
299
+ * as a separate entry. Overlapping groups (carboxylic acid → "carboxyl" +
300
+ * "hydroxyl" + "carbonyl") are all returned.
301
+ */
302
+ export function detect_functional_groups(mol: MolHandle): string;
303
+
268
304
  /**
269
305
  * Compute the ECFP4 fingerprint as a bit-packed byte vector (256 bytes = 2048 bits).
270
306
  */
271
307
  export function ecfp4_bitvec(mol: MolHandle): Uint8Array;
272
308
 
309
+ /**
310
+ * Per-atom EState values as a JSON array of f64.
311
+ *
312
+ * Indices match `mol.atoms()` order. Hydrogen atoms get 0.0.
313
+ */
314
+ export function estate_indices_json(mol: MolHandle): string;
315
+
316
+ /**
317
+ * Gasteiger-Marsili PEOE partial charges as a JSON array of f64.
318
+ */
319
+ export function gasteiger_charges_json(mol: MolHandle): string;
320
+
321
+ /**
322
+ * Generate 3D coordinates for the molecule and return a PDB string.
323
+ *
324
+ * Coordinates are generated using distance-geometry placement with ring templates.
325
+ * Returns heavy-atom PDB (HETATM records, no explicit H).
326
+ */
327
+ export function generate_3d_pdb(mol: MolHandle): string;
328
+
329
+ /**
330
+ * Return information about a single atom as a JSON object.
331
+ *
332
+ * `idx` is the 0-based atom index (matching `atoms()` order).
333
+ * Returns `"null"` if `idx` is out of range.
334
+ *
335
+ * Fields: `element` (symbol), `hybridization` ("sp"/"sp2"/"sp3"),
336
+ * `charge` (formal charge integer), `isAromatic` (bool),
337
+ * `totalHydrogens` (explicit + implicit H count, integer).
338
+ * sp3d/sp3d2 (hypervalent P/S) are not distinguished from sp3/sp2.
339
+ */
340
+ export function get_atom_info(mol: MolHandle, idx: number): string;
341
+
342
+ /**
343
+ * Return bond information as a JSON object, looked up by the two bonded atom indices.
344
+ *
345
+ * Useful when you know the atom indices from SMARTS matching or `data-atom-idx` SVG
346
+ * attributes but not the bond index. Returns `"null"` if no bond exists between them.
347
+ *
348
+ * Fields: same as `get_bond_info` plus `bondIdx` (u32).
349
+ */
350
+ export function get_bond_between(mol: MolHandle, atom1: number, atom2: number): string;
351
+
352
+ /**
353
+ * Return bond information as a JSON object, looked up by bond index.
354
+ *
355
+ * `idx` is the 0-based bond index (order matches `mol.bonds()` iteration).
356
+ * Returns `"null"` if `idx` is out of range.
357
+ *
358
+ * Fields: `bondOrder` (1.0/1.5/2.0/3.0), `isAromatic` (bool),
359
+ * `isInRing` (bool), `atomFrom` (u32), `atomTo` (u32).
360
+ */
361
+ export function get_bond_info(mol: MolHandle, idx: number): string;
362
+
363
+ /**
364
+ * Identify functional groups. Returns a JSON array of objects:
365
+ * `[{"atoms":[0,2,3],"type":"C,N,O"}, …]`
366
+ */
367
+ export function identify_functional_groups(mol: MolHandle): string;
368
+
273
369
  /**
274
370
  * Returns `true` if the SMILES string can be parsed without error.
275
371
  */
276
372
  export function is_valid_smiles(s: string): boolean;
277
373
 
374
+ /**
375
+ * Find all SMARTS matches in a molecule given only SMILES strings.
376
+ *
377
+ * Convenience wrapper around `smarts_match_atoms` that accepts raw SMILES
378
+ * instead of a `MolHandle`. Returns the same JSON format: `[[0,1],[3,4]]`.
379
+ * Returns a JS error on SMILES or SMARTS parse failure.
380
+ */
381
+ export function match_smarts_smiles(smiles: string, smarts: string): string;
382
+
383
+ /**
384
+ * Serialize a SMILES string directly to a MOL V2000 block.
385
+ *
386
+ * Convenience wrapper; all atom coordinates are 0.0.
387
+ * Returns a JS error on SMILES parse failure.
388
+ */
389
+ export function mol_block_from_smiles(smiles: string): string;
390
+
391
+ /**
392
+ * Parse a MOL V2000 block and return a `MolHandle`.
393
+ *
394
+ * Returns a JS error string on parse failure.
395
+ */
396
+ export function mol_from_sdf_block(block: string): MolHandle;
397
+
278
398
  /**
279
399
  * Parse a SMILES string into a `MolHandle`.
280
400
  *
@@ -282,6 +402,11 @@ export function is_valid_smiles(s: string): boolean;
282
402
  */
283
403
  export function parse_smiles(s: string): MolHandle;
284
404
 
405
+ /**
406
+ * PEOE_VSA descriptors (14 bins) as a JSON array.
407
+ */
408
+ export function peoe_vsa_json(mol: MolHandle): string;
409
+
285
410
  /**
286
411
  * Return a copy of the molecule with all explicit hydrogen atoms removed.
287
412
  */
@@ -296,6 +421,50 @@ export function remove_hydrogens(mol: MolHandle): MolHandle;
296
421
  */
297
422
  export function run_reactants(smirks: string, reactants_smiles: string): string;
298
423
 
424
+ /**
425
+ * Synthetic Accessibility Score (1 = easy, 10 = hard).
426
+ */
427
+ export function sa_score(mol: MolHandle): number;
428
+
429
+ /**
430
+ * Parse an SDF string and return a JSON array of canonical SMILES strings.
431
+ *
432
+ * Invalid records are represented as `null` in the array.
433
+ */
434
+ export function sdf_to_smiles_json(sdf: string): string;
435
+
436
+ /**
437
+ * SlogP_VSA descriptors (12 bins) as a JSON array.
438
+ */
439
+ export function slogp_vsa_json(mol: MolHandle): string;
440
+
441
+ /**
442
+ * Find all substructure matches of a SMARTS pattern in `mol`.
443
+ *
444
+ * Returns JSON array of arrays of atom indices (sorted, 0-based).
445
+ * Example: `[[0,1,2],[3,4,5]]` — two matches.
446
+ * Returns `"[]"` if no match. Returns a JS error on invalid SMARTS.
447
+ */
448
+ export function smarts_match_atoms(smarts: string, mol: MolHandle): string;
449
+
450
+ /**
451
+ * Render a highlighted SVG from a SMILES string in one call.
452
+ *
453
+ * `atoms` — 0-based atom indices to highlight (Uint32Array in JS).
454
+ * `bonds` — 0-based bond indices to highlight (Uint32Array in JS).
455
+ * `color` — CSS color for highlights (e.g. `"#ef4444"`); empty string uses default yellow.
456
+ *
457
+ * Returns a JS error on SMILES parse failure.
458
+ */
459
+ export function smiles_to_svg_highlighted(smiles: string, atoms: Uint32Array, bonds: Uint32Array, color: string): string;
460
+
461
+ /**
462
+ * SMR_VSA descriptors (10 bins) as a JSON array.
463
+ */
464
+ export function smr_vsa_json(mol: MolHandle): string;
465
+
466
+ export function start(): void;
467
+
299
468
  /**
300
469
  * Tanimoto similarity between two molecules using AtomPair fingerprints.
301
470
  */
@@ -311,7 +480,164 @@ export function tanimoto_ecfp4(a: MolHandle, b: MolHandle): number;
311
480
  */
312
481
  export function tanimoto_fcfp4(a: MolHandle, b: MolHandle): number;
313
482
 
483
+ /**
484
+ * Tanimoto similarity between two molecules given only SMILES strings (ECFP4).
485
+ *
486
+ * Returns a JS error on parse failure.
487
+ */
488
+ export function tanimoto_smiles(smiles1: string, smiles2: string): number;
489
+
490
+ /**
491
+ * Tanimoto similarity between two molecules using topological path fingerprints.
492
+ */
493
+ export function tanimoto_topo_path(a: MolHandle, b: MolHandle): number;
494
+
314
495
  /**
315
496
  * Tanimoto similarity between two molecules using Topological Torsion fingerprints.
316
497
  */
317
498
  export function tanimoto_torsion(a: MolHandle, b: MolHandle): number;
499
+
500
+ /**
501
+ * Serialize a molecule to a MOL V2000 block.
502
+ *
503
+ * All atom coordinates are written as 0.0 (the `Molecule` type has no 2D
504
+ * coordinate storage; real coordinates would require a separate layout pass).
505
+ */
506
+ export function to_mol_block(mol: MolHandle): string;
507
+
508
+ export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
509
+
510
+ export interface InitOutput {
511
+ readonly memory: WebAssembly.Memory;
512
+ readonly __wbg_depictoptions_free: (a: number, b: number) => void;
513
+ readonly __wbg_molhandle_free: (a: number, b: number) => void;
514
+ readonly add_hydrogens: (a: number) => number;
515
+ readonly brics_fragment_count: (a: number) => number;
516
+ readonly depict_reaction_svg: (a: number, b: number) => [number, number, number, number];
517
+ readonly depict_svg_grid: (a: number, b: number, c: number) => [number, number];
518
+ readonly depictoptions_new: () => number;
519
+ readonly depictoptions_set_atom_color: (a: number, b: number, c: number, d: number) => void;
520
+ readonly depictoptions_set_atom_ids: (a: number, b: number) => void;
521
+ readonly depictoptions_set_background: (a: number, b: number, c: number) => void;
522
+ readonly depictoptions_set_dark: (a: number, b: number) => void;
523
+ readonly depictoptions_set_height: (a: number, b: number) => void;
524
+ readonly depictoptions_set_highlight_atoms: (a: number, b: number, c: number) => void;
525
+ readonly depictoptions_set_highlight_bonds: (a: number, b: number, c: number) => void;
526
+ readonly depictoptions_set_highlight_color: (a: number, b: number, c: number) => void;
527
+ readonly depictoptions_set_kekulize: (a: number, b: number) => void;
528
+ readonly depictoptions_set_padding: (a: number, b: number) => void;
529
+ readonly depictoptions_set_show_atom_indices: (a: number, b: number) => void;
530
+ readonly depictoptions_set_width: (a: number, b: number) => void;
531
+ readonly detect_functional_groups: (a: number) => [number, number];
532
+ readonly ecfp4_bitvec: (a: number) => [number, number];
533
+ readonly estate_indices_json: (a: number) => [number, number];
534
+ readonly gasteiger_charges_json: (a: number) => [number, number];
535
+ readonly generate_3d_pdb: (a: number) => [number, number];
536
+ readonly get_atom_info: (a: number, b: number) => [number, number];
537
+ readonly get_bond_between: (a: number, b: number, c: number) => [number, number];
538
+ readonly get_bond_info: (a: number, b: number) => [number, number];
539
+ readonly identify_functional_groups: (a: number) => [number, number];
540
+ readonly is_valid_smiles: (a: number, b: number) => number;
541
+ readonly match_smarts_smiles: (a: number, b: number, c: number, d: number) => [number, number, number, number];
542
+ readonly mol_block_from_smiles: (a: number, b: number) => [number, number, number, number];
543
+ readonly mol_from_sdf_block: (a: number, b: number) => [number, number, number];
544
+ readonly molhandle_aromatic_ring_count: (a: number) => number;
545
+ readonly molhandle_atom_count: (a: number) => number;
546
+ readonly molhandle_bertz_ct: (a: number) => number;
547
+ readonly molhandle_bond_count: (a: number) => number;
548
+ readonly molhandle_canonical_smiles: (a: number) => [number, number];
549
+ readonly molhandle_chi0: (a: number) => number;
550
+ readonly molhandle_chi0v: (a: number) => number;
551
+ readonly molhandle_chi1: (a: number) => number;
552
+ readonly molhandle_chi1v: (a: number) => number;
553
+ readonly molhandle_chi2: (a: number) => number;
554
+ readonly molhandle_chi2v: (a: number) => number;
555
+ readonly molhandle_chi3: (a: number) => number;
556
+ readonly molhandle_chi3v: (a: number) => number;
557
+ readonly molhandle_chi4: (a: number) => number;
558
+ readonly molhandle_chi4v: (a: number) => number;
559
+ readonly molhandle_depict_svg: (a: number) => [number, number];
560
+ readonly molhandle_depict_svg_opts: (a: number, b: number) => [number, number];
561
+ readonly molhandle_egan_passes: (a: number) => number;
562
+ readonly molhandle_exact_mass: (a: number) => number;
563
+ readonly molhandle_formal_charge_sum: (a: number) => number;
564
+ readonly molhandle_formula: (a: number) => [number, number];
565
+ readonly molhandle_fsp3: (a: number) => number;
566
+ readonly molhandle_ghose_passes: (a: number) => number;
567
+ readonly molhandle_hba_count: (a: number) => number;
568
+ readonly molhandle_hbd_count: (a: number) => number;
569
+ readonly molhandle_heavy_atom_count: (a: number) => number;
570
+ readonly molhandle_kappa1: (a: number) => number;
571
+ readonly molhandle_kappa2: (a: number) => number;
572
+ readonly molhandle_kappa3: (a: number) => number;
573
+ readonly molhandle_labute_asa: (a: number) => number;
574
+ readonly molhandle_lipinski_passes: (a: number) => number;
575
+ readonly molhandle_logp_crippen: (a: number) => number;
576
+ readonly molhandle_max_estate: (a: number) => number;
577
+ readonly molhandle_min_estate: (a: number) => number;
578
+ readonly molhandle_molar_refractivity: (a: number) => number;
579
+ readonly molhandle_molecular_weight: (a: number) => number;
580
+ readonly molhandle_morgan_fp_counts_json: (a: number, b: number) => [number, number];
581
+ readonly molhandle_num_aliphatic_heterocycles: (a: number) => number;
582
+ readonly molhandle_num_aromatic_heterocycles: (a: number) => number;
583
+ readonly molhandle_num_bridgehead_atoms: (a: number) => number;
584
+ readonly molhandle_num_heteroatoms: (a: number) => number;
585
+ readonly molhandle_num_saturated_heterocycles: (a: number) => number;
586
+ readonly molhandle_num_spiro_atoms: (a: number) => number;
587
+ readonly molhandle_num_stereocenters: (a: number) => number;
588
+ readonly molhandle_pains_passes: (a: number) => number;
589
+ readonly molhandle_qed: (a: number) => number;
590
+ readonly molhandle_reos_passes: (a: number) => number;
591
+ readonly molhandle_ring_count: (a: number) => number;
592
+ readonly molhandle_rotatable_bond_count: (a: number) => number;
593
+ readonly molhandle_sum_estate: (a: number) => number;
594
+ readonly molhandle_tpsa: (a: number) => number;
595
+ readonly molhandle_veber_passes: (a: number) => number;
596
+ readonly molhandle_wiener_index: (a: number) => number;
597
+ readonly parse_smiles: (a: number, b: number) => [number, number, number];
598
+ readonly peoe_vsa_json: (a: number) => [number, number];
599
+ readonly remove_hydrogens: (a: number) => number;
600
+ readonly run_reactants: (a: number, b: number, c: number, d: number) => [number, number, number, number];
601
+ readonly sa_score: (a: number) => number;
602
+ readonly sdf_to_smiles_json: (a: number, b: number) => [number, number];
603
+ readonly slogp_vsa_json: (a: number) => [number, number];
604
+ readonly smarts_match_atoms: (a: number, b: number, c: number) => [number, number, number, number];
605
+ readonly smiles_to_svg_highlighted: (a: number, b: number, c: number, d: number, e: number, f: number, g: number, h: number) => [number, number, number, number];
606
+ readonly smr_vsa_json: (a: number) => [number, number];
607
+ readonly tanimoto_atom_pair: (a: number, b: number) => number;
608
+ readonly tanimoto_ecfp4: (a: number, b: number) => number;
609
+ readonly tanimoto_fcfp4: (a: number, b: number) => number;
610
+ readonly tanimoto_smiles: (a: number, b: number, c: number, d: number) => [number, number, number];
611
+ readonly tanimoto_topo_path: (a: number, b: number) => number;
612
+ readonly tanimoto_torsion: (a: number, b: number) => number;
613
+ readonly to_mol_block: (a: number) => [number, number];
614
+ readonly start: () => void;
615
+ readonly __wbindgen_free: (a: number, b: number, c: number) => void;
616
+ readonly __wbindgen_malloc: (a: number, b: number) => number;
617
+ readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
618
+ readonly __wbindgen_externrefs: WebAssembly.Table;
619
+ readonly __externref_table_dealloc: (a: number) => void;
620
+ readonly __wbindgen_start: () => void;
621
+ }
622
+
623
+ export type SyncInitInput = BufferSource | WebAssembly.Module;
624
+
625
+ /**
626
+ * Instantiates the given `module`, which can either be bytes or
627
+ * a precompiled `WebAssembly.Module`.
628
+ *
629
+ * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
630
+ *
631
+ * @returns {InitOutput}
632
+ */
633
+ export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
634
+
635
+ /**
636
+ * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
637
+ * for everything else, calls `WebAssembly.instantiate` directly.
638
+ *
639
+ * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
640
+ *
641
+ * @returns {Promise<InitOutput>}
642
+ */
643
+ export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;