@molcrafts/molrs 0.0.6 → 0.0.8

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/molrs.d.ts CHANGED
@@ -5,14 +5,14 @@
5
5
  * Column-oriented data store with typed arrays.
6
6
  *
7
7
  * Each column is identified by a string key and has a fixed data type
8
- * (`f32`, `i32`, `u32`, `string`). All columns in a block must have
8
+ * (`F`, `i32`, `u32`, `string`). All columns in a block must have
9
9
  * the same number of rows.
10
10
  *
11
11
  * # Supported column types
12
12
  *
13
13
  * | JS type | Rust type | dtype string | Setter | Getter (copy) | Getter (view) |
14
14
  * |---------|-----------|-------------|--------|---------------|---------------|
15
- * | `Float32Array` | `f32` | `"f32"` | `setColF32` | `copyColF32` | `viewColF32` |
15
+ * | `Float32Array` / `Float64Array` | `F` | `"f32"` / `"f64"` | `setColF` | `copyColF` | `viewColF` |
16
16
  * | `Int32Array` | `i32` | `"i32"` | `setColI32` | `copyColI32` | `viewColI32` |
17
17
  * | `Uint32Array` | `u32` | `"u32"` | `setColU32` | `copyColU32` | `viewColU32` |
18
18
  * | `string[]` | `String` | `"string"` | `setColStr` | `copyColStr` | -- |
@@ -21,21 +21,21 @@
21
21
  *
22
22
  * ```js
23
23
  * const block = new Block();
24
- * block.setColF32("x", new Float32Array([1.0, 2.0, 3.0]));
25
- * block.setColF32("y", new Float32Array([0.0, 0.0, 0.0]));
24
+ * block.setColF("x", coordsX);
25
+ * block.setColF("y", coordsY);
26
26
  * console.log(block.nrows()); // 3
27
27
  * console.log(block.keys()); // ["x", "y"]
28
28
  *
29
- * const x = block.copyColF32("x"); // owned copy, safe to keep
29
+ * const x = block.copyColF("x"); // owned copy, safe to keep
30
30
  * ```
31
31
  */
32
32
  export class Block {
33
33
  free(): void;
34
34
  [Symbol.dispose](): void;
35
35
  /**
36
- * Owned `Float32Array` copy of a column.
36
+ * Owned JS float typed-array copy of a column.
37
37
  *
38
- * Returns a new JS `Float32Array` that is an independent copy of
38
+ * Returns a new JS float typed array that is an independent copy of
39
39
  * the column data. Safe to store and use across allocations.
40
40
  *
41
41
  * # Arguments
@@ -44,20 +44,20 @@ export class Block {
44
44
  *
45
45
  * # Returns
46
46
  *
47
- * An owned `Float32Array` copy of the column.
47
+ * An owned JS float typed-array copy of the column.
48
48
  *
49
49
  * # Errors
50
50
  *
51
- * Throws if the column does not exist or is not of type `f32`.
51
+ * Throws if the column does not exist or is not of the active float type.
52
52
  *
53
53
  * # Example (JavaScript)
54
54
  *
55
55
  * ```js
56
- * const x = block.copyColF32("x");
56
+ * const x = block.copyColF("x");
57
57
  * console.log(x[0]); // 1.0
58
58
  * ```
59
59
  */
60
- copyColF32(key: string): Float32Array;
60
+ copyColF(key: string): Float64Array;
61
61
  /**
62
62
  * Owned `Int32Array` copy of a column.
63
63
  *
@@ -120,7 +120,8 @@ export class Block {
120
120
  /**
121
121
  * Return the data type string for a column.
122
122
  *
123
- * Possible return values: `"f32"`, `"i32"`, `"u32"`, `"bool"`,
123
+ * Possible return values: `"f32"` or `"f64"` for float columns,
124
+ * plus `"i32"`, `"u32"`, `"bool"`,
124
125
  * `"string"`, `"u8"`. Returns `undefined` if the column does
125
126
  * not exist.
126
127
  *
@@ -135,7 +136,7 @@ export class Block {
135
136
  * # Example (JavaScript)
136
137
  *
137
138
  * ```js
138
- * console.log(block.dtype("x")); // "f32"
139
+ * console.log(block.dtype("x")); // "f32" or "f64"
139
140
  * console.log(block.dtype("symbol")); // "string"
140
141
  * ```
141
142
  */
@@ -197,7 +198,7 @@ export class Block {
197
198
  *
198
199
  * ```js
199
200
  * const block = new Block();
200
- * block.setColF32("values", new Float32Array([1, 2, 3]));
201
+ * block.setColF("values", values);
201
202
  * ```
202
203
  */
203
204
  constructor();
@@ -241,12 +242,12 @@ export class Block {
241
242
  */
242
243
  renameColumn(old_key: string, new_key: string): boolean;
243
244
  /**
244
- * Set a float column from a `Float32Array`.
245
+ * Set a float column from a JS float typed array.
245
246
  *
246
247
  * # Arguments
247
248
  *
248
249
  * * `key` - Column name (e.g., `"x"`, `"mass"`, `"charge"`)
249
- * * `data` - `Float32Array` with the column values
250
+ * * `data` - JS float typed array with the column values
250
251
  * * `shape` - Optional shape array for multi-dimensional data
251
252
  * (e.g., `[N, 3]` for an Nx3 matrix stored flat). If omitted,
252
253
  * the data is stored as a 1D column.
@@ -259,12 +260,12 @@ export class Block {
259
260
  * # Example (JavaScript)
260
261
  *
261
262
  * ```js
262
- * block.setColF32("x", new Float32Array([1.0, 2.0, 3.0]));
263
+ * block.setColF("x", xCoords);
263
264
  * // Multi-dimensional: 2 rows x 3 columns
264
- * block.setColF32("pos", new Float32Array([1,2,3, 4,5,6]), [2, 3]);
265
+ * block.setColF("pos", positions, [2, 3]);
265
266
  * ```
266
267
  */
267
- setColF32(key: string, data: Float32Array, shape?: Uint32Array | null): void;
268
+ setColF(key: string, data: Float64Array, shape?: Uint32Array | null): void;
268
269
  /**
269
270
  * Set a signed integer column from an `Int32Array`.
270
271
  *
@@ -326,13 +327,13 @@ export class Block {
326
327
  */
327
328
  setColU32(key: string, data: Uint32Array): void;
328
329
  /**
329
- * Zero-copy `Float32Array` view into WASM linear memory.
330
+ * Zero-copy JS float typed-array view into WASM linear memory.
330
331
  *
331
332
  * Returns a view backed directly by the block's storage in WASM
332
333
  * memory. This avoids copying but the view becomes **invalid**
333
334
  * if WASM linear memory grows (due to any allocation).
334
335
  *
335
- * Use [`copyColF32`](Block::copy_col_f32) for a safe, long-lived copy.
336
+ * Use [`copyColF`](Block::copy_col_f) for a safe, long-lived copy.
336
337
  *
337
338
  * # Arguments
338
339
  *
@@ -340,20 +341,20 @@ export class Block {
340
341
  *
341
342
  * # Returns
342
343
  *
343
- * A `Float32Array` view into WASM memory.
344
+ * A JS float typed-array view into WASM memory.
344
345
  *
345
346
  * # Errors
346
347
  *
347
- * Throws if the column does not exist or is not of type `f32`.
348
+ * Throws if the column does not exist or is not of the active float type.
348
349
  *
349
350
  * # Example (JavaScript)
350
351
  *
351
352
  * ```js
352
- * const view = block.viewColF32("x"); // zero-copy, use immediately
353
- * const copy = block.copyColF32("x"); // safe to keep
353
+ * const view = block.viewColF("x"); // zero-copy, use immediately
354
+ * const copy = block.copyColF("x"); // safe to keep
354
355
  * ```
355
356
  */
356
- viewColF32(key: string): Float32Array;
357
+ viewColF(key: string): Float64Array;
357
358
  /**
358
359
  * Zero-copy `Int32Array` view into WASM linear memory.
359
360
  *
@@ -411,8 +412,8 @@ export class Block {
411
412
  * # Example (JavaScript)
412
413
  *
413
414
  * ```js
414
- * const h = new Float32Array([10, 0, 0, 0, 10, 0, 0, 0, 10]);
415
- * const origin = new Float32Array([0, 0, 0]);
415
+ * const h = floatArrayH;
416
+ * const origin = floatArrayOrigin;
416
417
  * const box = new Box(h, origin, true, true, true);
417
418
  * console.log(box.volume()); // 1000.0
418
419
  * console.log(box.lengths().toCopy()); // [10, 10, 10]
@@ -427,7 +428,7 @@ export class Box {
427
428
  * # Arguments
428
429
  *
429
430
  * * `a` - Side length of the cube in angstrom (A)
430
- * * `origin` - 3D origin vector as `Float32Array` with 3 elements
431
+ * * `origin` - 3D origin vector as a float typed array with 3 elements
431
432
  * `[x, y, z]` in angstrom
432
433
  * * `pbc_x` - Enable periodic boundary in x direction
433
434
  * * `pbc_y` - Enable periodic boundary in y direction
@@ -444,12 +445,12 @@ export class Box {
444
445
  * # Example (JavaScript)
445
446
  *
446
447
  * ```js
447
- * const origin = new Float32Array([0, 0, 0]);
448
+ * const origin = originVec;
448
449
  * const box = Box.cube(10.0, origin, true, true, true);
449
450
  * console.log(box.volume()); // 1000.0
450
451
  * ```
451
452
  */
452
- static cube(a: number, origin: Float32Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean): Box;
453
+ static cube(a: number, origin: Float64Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean): Box;
453
454
  /**
454
455
  * Calculate displacement vectors between two sets of coordinates.
455
456
  *
@@ -478,8 +479,8 @@ export class Box {
478
479
  * # Example (JavaScript)
479
480
  *
480
481
  * ```js
481
- * const a = WasmArray.from(new Float32Array([1,1,1]), [1,3]);
482
- * const b = WasmArray.from(new Float32Array([9,9,9]), [1,3]);
482
+ * const a = WasmArray.from(aCoords, [1, 3]);
483
+ * const b = WasmArray.from(bCoords, [1, 3]);
483
484
  * const d = box.delta(a, b, true); // minimum-image displacement
484
485
  * ```
485
486
  */
@@ -496,7 +497,7 @@ export class Box {
496
497
  * * `b` - `WasmArray` with shape `[N, 3]` (target positions in A)
497
498
  * * `minimum_image` - If `true`, apply minimum image convention
498
499
  * * `out_block` - Target [`Block`] to write the result into
499
- * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
500
+ * * `out_key` - Column name for the result (float, shape `[N, 3]`)
500
501
  *
501
502
  * # Errors
502
503
  *
@@ -538,7 +539,7 @@ export class Box {
538
539
  * # Example (JavaScript)
539
540
  *
540
541
  * ```js
541
- * const L = box.lengths().toCopy(); // Float32Array [10, 10, 10]
542
+ * const L = box.lengths().toCopy(); // Float32Array or Float64Array [10, 10, 10]
542
543
  * ```
543
544
  */
544
545
  lengths(): WasmArray;
@@ -547,10 +548,10 @@ export class Box {
547
548
  *
548
549
  * # Arguments
549
550
  *
550
- * * `h` - 3x3 cell matrix as `Float32Array` with 9 elements in
551
+ * * `h` - 3x3 cell matrix as a float typed array with 9 elements in
551
552
  * row-major order: `[h00, h01, h02, h10, h11, h12, h20, h21, h22]`.
552
553
  * All values in angstrom (A).
553
- * * `origin` - 3D origin vector as `Float32Array` with 3 elements
554
+ * * `origin` - 3D origin vector as a float typed array with 3 elements
554
555
  * `[x, y, z]` in angstrom.
555
556
  * * `pbc_x` - Enable periodic boundary in x direction
556
557
  * * `pbc_y` - Enable periodic boundary in y direction
@@ -569,12 +570,12 @@ export class Box {
569
570
  *
570
571
  * ```js
571
572
  * // Triclinic box
572
- * const h = new Float32Array([10, 2, 0, 0, 10, 0, 0, 0, 10]);
573
- * const origin = new Float32Array([0, 0, 0]);
573
+ * const h = hMatrix;
574
+ * const origin = originVec;
574
575
  * const box = new Box(h, origin, true, true, true);
575
576
  * ```
576
577
  */
577
- constructor(h: Float32Array, origin: Float32Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean);
578
+ constructor(h: Float64Array, origin: Float64Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean);
578
579
  /**
579
580
  * Return the box origin as a `WasmArray` with shape `[3]`.
580
581
  *
@@ -587,7 +588,7 @@ export class Box {
587
588
  * # Example (JavaScript)
588
589
  *
589
590
  * ```js
590
- * const o = box.origin().toCopy(); // Float32Array [0, 0, 0]
591
+ * const o = box.origin().toCopy(); // Float32Array or Float64Array [0, 0, 0]
591
592
  * ```
592
593
  */
593
594
  origin(): WasmArray;
@@ -596,9 +597,9 @@ export class Box {
596
597
  *
597
598
  * # Arguments
598
599
  *
599
- * * `lengths` - Box dimensions as `Float32Array` with 3 elements
600
+ * * `lengths` - Box dimensions as a float typed array with 3 elements
600
601
  * `[lx, ly, lz]` in angstrom (A)
601
- * * `origin` - 3D origin vector as `Float32Array` with 3 elements
602
+ * * `origin` - 3D origin vector as a float typed array with 3 elements
602
603
  * `[x, y, z]` in angstrom
603
604
  * * `pbc_x` - Enable periodic boundary in x direction
604
605
  * * `pbc_y` - Enable periodic boundary in y direction
@@ -615,12 +616,12 @@ export class Box {
615
616
  * # Example (JavaScript)
616
617
  *
617
618
  * ```js
618
- * const origin = new Float32Array([0, 0, 0]);
619
- * const box = Box.ortho(new Float32Array([10, 20, 30]), origin, true, true, true);
619
+ * const origin = originVec;
620
+ * const box = Box.ortho(lengthsVec, origin, true, true, true);
620
621
  * console.log(box.volume()); // 6000.0
621
622
  * ```
622
623
  */
623
- static ortho(lengths: Float32Array, origin: Float32Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean): Box;
624
+ static ortho(lengths: Float64Array, origin: Float64Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean): Box;
624
625
  /**
625
626
  * Return the box tilt factors as a `WasmArray` with shape `[3]`.
626
627
  *
@@ -636,7 +637,7 @@ export class Box {
636
637
  * # Example (JavaScript)
637
638
  *
638
639
  * ```js
639
- * const t = box.tilts().toCopy(); // Float32Array [0, 0, 0]
640
+ * const t = box.tilts().toCopy(); // Float32Array or Float64Array [0, 0, 0]
640
641
  * ```
641
642
  */
642
643
  tilts(): WasmArray;
@@ -648,7 +649,7 @@ export class Box {
648
649
  *
649
650
  * * `coords` - `WasmArray` with shape `[N, 3]` (fractional, dimensionless)
650
651
  * * `out_block` - Target [`Block`]
651
- * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
652
+ * * `out_key` - Column name for the result (float, shape `[N, 3]`)
652
653
  *
653
654
  * # Errors
654
655
  *
@@ -669,7 +670,7 @@ export class Box {
669
670
  *
670
671
  * * `coords` - `WasmArray` with shape `[N, 3]` (Cartesian, A)
671
672
  * * `out_block` - Target [`Block`]
672
- * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
673
+ * * `out_key` - Column name for the result (float, shape `[N, 3]`)
673
674
  *
674
675
  * # Errors
675
676
  *
@@ -702,7 +703,7 @@ export class Box {
702
703
  * # Example (JavaScript)
703
704
  *
704
705
  * ```js
705
- * const frac = WasmArray.from(new Float32Array([0.5, 0.5, 0.5]), [1, 3]);
706
+ * const frac = WasmArray.from(fracCoords, [1, 3]);
706
707
  * const cart = box.toCart(frac);
707
708
  * console.log(cart.toCopy()); // [5, 5, 5] for a 10x10x10 box
708
709
  * ```
@@ -731,7 +732,7 @@ export class Box {
731
732
  * # Example (JavaScript)
732
733
  *
733
734
  * ```js
734
- * const cart = WasmArray.from(new Float32Array([5, 5, 5]), [1, 3]);
735
+ * const cart = WasmArray.from(coords, [1, 3]);
735
736
  * const frac = box.toFrac(cart);
736
737
  * console.log(frac.toCopy()); // [0.5, 0.5, 0.5] for a 10x10x10 box
737
738
  * ```
@@ -771,7 +772,7 @@ export class Box {
771
772
  * # Example (JavaScript)
772
773
  *
773
774
  * ```js
774
- * const pos = WasmArray.from(new Float32Array([12, -1, 5]), [1, 3]);
775
+ * const pos = WasmArray.from(positions, [1, 3]);
775
776
  * const wrapped = box.wrap(pos); // wraps into [0, lx) x [0, ly) x [0, lz)
776
777
  * ```
777
778
  */
@@ -787,7 +788,7 @@ export class Box {
787
788
  * * `coords` - `WasmArray` with shape `[N, 3]` containing
788
789
  * Cartesian coordinates in angstrom (A)
789
790
  * * `out_block` - Target [`Block`] to write the result into
790
- * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
791
+ * * `out_key` - Column name for the result (float, shape `[N, 3]`)
791
792
  *
792
793
  * # Errors
793
794
  *
@@ -803,6 +804,55 @@ export class Box {
803
804
  wrapToBlock(coords: WasmArray, out_block: Block, out_key: string): void;
804
805
  }
805
806
 
807
+ /**
808
+ * Mass-weighted cluster center calculator.
809
+ */
810
+ export class CenterOfMass {
811
+ free(): void;
812
+ [Symbol.dispose](): void;
813
+ /**
814
+ * Compute centers of mass.
815
+ */
816
+ compute(frame: Frame, cluster_result: ClusterResult): CenterOfMassResult;
817
+ /**
818
+ * Create a center-of-mass calculator.
819
+ *
820
+ * Pass `null` for uniform masses, or a float typed array of per-particle masses.
821
+ */
822
+ constructor(masses?: Float64Array | null);
823
+ }
824
+
825
+ /**
826
+ * Result of center-of-mass computation.
827
+ *
828
+ * # Example (JavaScript)
829
+ *
830
+ * ```js
831
+ * const com = new CenterOfMass().compute(frame, clusterResult);
832
+ * com.centersOfMass(); // Float32Array or Float64Array [x0,y0,z0, ...]
833
+ * com.clusterMasses(); // Float32Array or Float64Array
834
+ * ```
835
+ */
836
+ export class CenterOfMassResult {
837
+ private constructor();
838
+ free(): void;
839
+ [Symbol.dispose](): void;
840
+ /**
841
+ * Zero-copy `Float64Array` view of mass-weighted centers, flat
842
+ * `[x0,y0,z0, x1,y1,z1, ...]`. **Invalidated** on WASM memory growth.
843
+ */
844
+ centersOfMass(): Float64Array;
845
+ /**
846
+ * Zero-copy `Float64Array` view of total mass per cluster.
847
+ * **Invalidated** on WASM memory growth.
848
+ */
849
+ clusterMasses(): Float64Array;
850
+ /**
851
+ * Number of clusters.
852
+ */
853
+ readonly numClusters: number;
854
+ }
855
+
806
856
  /**
807
857
  * Distance-based cluster analysis using BFS on the neighbor graph.
808
858
  *
@@ -869,6 +919,26 @@ export class Cluster {
869
919
  constructor(min_cluster_size: number);
870
920
  }
871
921
 
922
+ /**
923
+ * Geometric cluster centers with minimum image convention.
924
+ *
925
+ * # Example (JavaScript)
926
+ *
927
+ * ```js
928
+ * const centers = new ClusterCenters().compute(frame, clusterResult);
929
+ * // Float32Array or Float64Array [x0,y0,z0, x1,y1,z1, ...]
930
+ * ```
931
+ */
932
+ export class ClusterCenters {
933
+ free(): void;
934
+ [Symbol.dispose](): void;
935
+ /**
936
+ * Compute geometric centers. Returns a flat float typed array `[x0,y0,z0, ...]`.
937
+ */
938
+ compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
939
+ constructor();
940
+ }
941
+
872
942
  /**
873
943
  * Result of a distance-based cluster analysis.
874
944
  *
@@ -924,10 +994,10 @@ export class ClusterResult {
924
994
  * # Conventions
925
995
  *
926
996
  * - The `"atoms"` block should contain per-atom properties: `symbol`
927
- * (string), `x`/`y`/`z` (f32, coordinates in angstrom), and optionally
928
- * `mass` (f32, atomic mass units) and `charge` (f32, elementary charges).
997
+ * (string), `x`/`y`/`z` (F, coordinates in angstrom), and optionally
998
+ * `mass` (F, atomic mass units) and `charge` (F, elementary charges).
929
999
  * - The `"bonds"` block should contain bond topology: `i`/`j` (u32,
930
- * zero-based atom indices) and `order` (f32, bond order: 1.0 = single,
1000
+ * zero-based atom indices) and `order` (F, bond order: 1.0 = single,
931
1001
  * 1.5 = aromatic, 2.0 = double, 3.0 = triple).
932
1002
  *
933
1003
  * # Example (JavaScript)
@@ -935,7 +1005,7 @@ export class ClusterResult {
935
1005
  * ```js
936
1006
  * const frame = new Frame();
937
1007
  * const atoms = frame.createBlock("atoms");
938
- * atoms.setColF32("x", new Float32Array([0.0, 1.54]));
1008
+ * atoms.setColF("x", xCoords);
939
1009
  * ```
940
1010
  */
941
1011
  export class Frame {
@@ -977,7 +1047,7 @@ export class Frame {
977
1047
  *
978
1048
  * ```js
979
1049
  * const atoms = frame.createBlock("atoms");
980
- * atoms.setColF32("x", new Float32Array([1.0, 2.0]));
1050
+ * atoms.setColF("x", xCoords);
981
1051
  * ```
982
1052
  */
983
1053
  createBlock(key: string): Block;
@@ -1017,11 +1087,57 @@ export class Frame {
1017
1087
  * ```js
1018
1088
  * const atoms = frame.getBlock("atoms");
1019
1089
  * if (atoms) {
1020
- * const x = atoms.copyColF32("x");
1090
+ * const x = atoms.copyColF("x");
1021
1091
  * }
1022
1092
  * ```
1023
1093
  */
1024
1094
  getBlock(key: string): Block | undefined;
1095
+ /**
1096
+ * Retrieve a named grid attached to this frame.
1097
+ *
1098
+ * Returns a cloned [`Grid`] wrapper, or `undefined` if the grid does
1099
+ * not exist. The returned object is independent of the frame — mutations
1100
+ * to it are not reflected in the frame without a subsequent
1101
+ * [`insertGrid`](Frame::insert_grid) call.
1102
+ *
1103
+ * # Arguments
1104
+ *
1105
+ * * `name` — Grid name to retrieve.
1106
+ *
1107
+ * # Example (JavaScript)
1108
+ *
1109
+ * ```js
1110
+ * const g = frame.getGrid("chgcar");
1111
+ * if (g) {
1112
+ * const arr = g.getArray("rho");
1113
+ * }
1114
+ * ```
1115
+ */
1116
+ getGrid(name: string): Grid | undefined;
1117
+ /**
1118
+ * Return the names of all grids attached to this frame.
1119
+ *
1120
+ * # Example (JavaScript)
1121
+ *
1122
+ * ```js
1123
+ * const names = frame.gridNames(); // e.g. ["chgcar", "spin"]
1124
+ * ```
1125
+ */
1126
+ gridNames(): Array<any>;
1127
+ /**
1128
+ * Returns `true` if a named grid is attached to this frame.
1129
+ *
1130
+ * # Arguments
1131
+ *
1132
+ * * `name` — Grid name to look up.
1133
+ *
1134
+ * # Example (JavaScript)
1135
+ *
1136
+ * ```js
1137
+ * frame.hasGrid("chgcar"); // true or false
1138
+ * ```
1139
+ */
1140
+ hasGrid(name: string): boolean;
1025
1141
  /**
1026
1142
  * Insert a block by deep-copying its data into this frame's store.
1027
1143
  *
@@ -1049,6 +1165,31 @@ export class Frame {
1049
1165
  * ```
1050
1166
  */
1051
1167
  insertBlock(key: string, block: Block): void;
1168
+ /**
1169
+ * Attach a grid to this frame under the given name.
1170
+ *
1171
+ * If a grid with the same name already exists it is replaced. The grid
1172
+ * data is moved into the frame; the JS `Grid` object becomes empty after
1173
+ * this call and should not be reused.
1174
+ *
1175
+ * # Arguments
1176
+ *
1177
+ * * `name` — Name to store the grid under (e.g., `"chgcar"`).
1178
+ * * `grid` — The [`Grid`] to attach.
1179
+ *
1180
+ * # Errors
1181
+ *
1182
+ * Throws a `JsValue` string if the frame has been dropped.
1183
+ *
1184
+ * # Example (JavaScript)
1185
+ *
1186
+ * ```js
1187
+ * const grid = new Grid(10, 10, 10, origin, cell, true, true, true);
1188
+ * grid.insertArray("rho", rhoData);
1189
+ * frame.insertGrid("chgcar", grid);
1190
+ * ```
1191
+ */
1192
+ insertGrid(name: string, grid: Grid): void;
1052
1193
  /**
1053
1194
  * Create a new, empty `Frame` with no blocks and no simulation box.
1054
1195
  *
@@ -1078,6 +1219,24 @@ export class Frame {
1078
1219
  * ```
1079
1220
  */
1080
1221
  removeBlock(key: string): void;
1222
+ /**
1223
+ * Remove a named grid from this frame.
1224
+ *
1225
+ * # Arguments
1226
+ *
1227
+ * * `name` — Grid name to remove.
1228
+ *
1229
+ * # Errors
1230
+ *
1231
+ * Throws a `JsValue` string if the frame has been dropped.
1232
+ *
1233
+ * # Example (JavaScript)
1234
+ *
1235
+ * ```js
1236
+ * frame.removeGrid("chgcar");
1237
+ * ```
1238
+ */
1239
+ removeGrid(name: string): void;
1081
1240
  /**
1082
1241
  * Rename a block from `old_key` to `new_key`.
1083
1242
  *
@@ -1162,21 +1321,290 @@ export class Frame {
1162
1321
  * # Example (JavaScript)
1163
1322
  *
1164
1323
  * ```js
1165
- * const origin = new Float32Array([0, 0, 0]);
1324
+ * const origin = originVec;
1166
1325
  * frame.simbox = Box.cube(10.0, origin, true, true, true);
1167
1326
  * ```
1168
1327
  */
1169
1328
  set simbox(value: Box | null | undefined);
1170
1329
  }
1171
1330
 
1331
+ /**
1332
+ * A uniform spatial grid storing multiple named scalar arrays.
1333
+ *
1334
+ * All arrays in a `Grid` share the same spatial definition: dimensions
1335
+ * (`[nx, ny, nz]`), Cartesian origin, cell matrix (columns are lattice
1336
+ * vectors, matching VASP/molrs convention), and periodic boundary flags.
1337
+ *
1338
+ * # Example (JavaScript)
1339
+ *
1340
+ * ```js
1341
+ * // Create a 10×10×10 cubic grid
1342
+ * const origin = new Float32Array([0, 0, 0]);
1343
+ * const cell = new Float32Array([
1344
+ * 10, 0, 0, // first column (a vector)
1345
+ * 0,10, 0, // second column (b vector)
1346
+ * 0, 0,10, // third column (c vector)
1347
+ * ]);
1348
+ * const grid = new Grid(10, 10, 10, origin, cell, true, true, true);
1349
+ *
1350
+ * // Insert a density array (must have length = 10*10*10 = 1000)
1351
+ * const rho = new Float32Array(1000).fill(1.0);
1352
+ * grid.insertArray("rho", rho);
1353
+ *
1354
+ * // Retrieve it
1355
+ * const arr = grid.getArray("rho");
1356
+ * console.log(arr.toCopy());
1357
+ * ```
1358
+ */
1359
+ export class Grid {
1360
+ free(): void;
1361
+ [Symbol.dispose](): void;
1362
+ /**
1363
+ * Names of all scalar arrays stored in this grid.
1364
+ *
1365
+ * # Example (JavaScript)
1366
+ *
1367
+ * ```js
1368
+ * const names = grid.arrayNames(); // e.g. ["rho", "spin"]
1369
+ * ```
1370
+ */
1371
+ arrayNames(): Array<any>;
1372
+ /**
1373
+ * Cell matrix in Ångström as a flat array of length 9 in column-major
1374
+ * order (columns are lattice vectors, matching VASP/molrs convention).
1375
+ *
1376
+ * Layout: `[col0_x, col0_y, col0_z, col1_x, col1_y, col1_z, col2_x, col2_y, col2_z]`
1377
+ *
1378
+ * # Example (JavaScript)
1379
+ *
1380
+ * ```js
1381
+ * const c = grid.cell();
1382
+ * const flat = c.toCopy(); // Float32Array of length 9
1383
+ * ```
1384
+ */
1385
+ cell(): WasmArray;
1386
+ /**
1387
+ * Grid dimensions `[nx, ny, nz]`.
1388
+ *
1389
+ * # Example (JavaScript)
1390
+ *
1391
+ * ```js
1392
+ * console.log(grid.dim()); // [10, 10, 10]
1393
+ * ```
1394
+ */
1395
+ dim(): Uint32Array;
1396
+ /**
1397
+ * Retrieve a named scalar array as a zero-copy `Float64Array` view
1398
+ * over the underlying WASM memory. Flat row-major order, length
1399
+ * `nx * ny * nz`. Use [`Grid::dim`] for shape.
1400
+ *
1401
+ * **Warning**: the view is invalidated on any WASM memory growth.
1402
+ * Copy it in JS (`new Float64Array(view)`) if it needs to outlive
1403
+ * subsequent allocations.
1404
+ *
1405
+ * Returns `undefined` if the named array does not exist.
1406
+ *
1407
+ * # Example (JavaScript)
1408
+ *
1409
+ * ```js
1410
+ * const view = grid.getArray("rho"); // zero-copy
1411
+ * const copy = new Float64Array(view); // owned copy if needed
1412
+ * ```
1413
+ */
1414
+ getArray(name: string): Float64Array | undefined;
1415
+ /**
1416
+ * Returns `true` if a named array is present in this grid.
1417
+ *
1418
+ * # Arguments
1419
+ *
1420
+ * * `name` — Array name to look up.
1421
+ *
1422
+ * # Example (JavaScript)
1423
+ *
1424
+ * ```js
1425
+ * grid.hasArray("rho"); // true or false
1426
+ * ```
1427
+ */
1428
+ hasArray(name: string): boolean;
1429
+ /**
1430
+ * Insert (or replace) a named scalar array.
1431
+ *
1432
+ * The provided `data` must have exactly `nx * ny * nz` elements in
1433
+ * row-major `(ix, iy, iz)` order.
1434
+ *
1435
+ * # Arguments
1436
+ *
1437
+ * * `name` — Array name.
1438
+ * * `data` — Float32Array with length equal to `grid.total()`.
1439
+ *
1440
+ * # Errors
1441
+ *
1442
+ * Throws if `data.length != nx * ny * nz`.
1443
+ *
1444
+ * # Example (JavaScript)
1445
+ *
1446
+ * ```js
1447
+ * const rho = new Float32Array(grid.total()).fill(0.5);
1448
+ * grid.insertArray("rho", rho);
1449
+ * ```
1450
+ */
1451
+ insertArray(name: string, data: Float64Array): void;
1452
+ /**
1453
+ * Returns `true` if no arrays are stored.
1454
+ *
1455
+ * # Example (JavaScript)
1456
+ *
1457
+ * ```js
1458
+ * console.log(grid.isEmpty()); // true for a freshly created grid
1459
+ * ```
1460
+ */
1461
+ isEmpty(): boolean;
1462
+ /**
1463
+ * Number of named arrays stored in this grid.
1464
+ *
1465
+ * # Example (JavaScript)
1466
+ *
1467
+ * ```js
1468
+ * console.log(grid.len()); // e.g. 2
1469
+ * ```
1470
+ */
1471
+ len(): number;
1472
+ /**
1473
+ * Create a new empty grid with the given spatial definition.
1474
+ *
1475
+ * # Arguments
1476
+ *
1477
+ * * `dim_x`, `dim_y`, `dim_z` — Number of grid points along each axis.
1478
+ * * `origin` — Float32Array of length 3: Cartesian origin in Ångström.
1479
+ * * `cell` — Float32Array of length 9: cell matrix in column-major order.
1480
+ * `cell[0..3]` is the first lattice vector (a), `cell[3..6]` is b,
1481
+ * `cell[6..9]` is c (matching VASP/molrs convention where columns are
1482
+ * lattice vectors).
1483
+ * * `pbc_x`, `pbc_y`, `pbc_z` — Periodic boundary flags for each axis.
1484
+ *
1485
+ * # Errors
1486
+ *
1487
+ * Throws if `origin` does not have length 3, or `cell` does not have
1488
+ * length 9.
1489
+ *
1490
+ * # Example (JavaScript)
1491
+ *
1492
+ * ```js
1493
+ * const origin = new Float32Array([0, 0, 0]);
1494
+ * const cell = new Float32Array([10,0,0, 0,10,0, 0,0,10]);
1495
+ * const grid = new Grid(10, 10, 10, origin, cell, true, true, true);
1496
+ * ```
1497
+ */
1498
+ constructor(dim_x: number, dim_y: number, dim_z: number, origin: Float64Array, cell: Float64Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean);
1499
+ /**
1500
+ * Cartesian origin in Ångström as a 1-D array of length 3.
1501
+ *
1502
+ * # Example (JavaScript)
1503
+ *
1504
+ * ```js
1505
+ * const o = grid.origin();
1506
+ * const arr = o.toCopy(); // Float32Array [ox, oy, oz]
1507
+ * ```
1508
+ */
1509
+ origin(): WasmArray;
1510
+ /**
1511
+ * Periodic boundary flags as a `Uint8Array`-compatible slice.
1512
+ *
1513
+ * Each element is `1` (periodic) or `0` (not periodic).
1514
+ *
1515
+ * # Example (JavaScript)
1516
+ *
1517
+ * ```js
1518
+ * console.log(grid.pbc()); // [1, 1, 1]
1519
+ * ```
1520
+ */
1521
+ pbc(): Uint8Array;
1522
+ /**
1523
+ * Total number of voxels: `nx * ny * nz`.
1524
+ *
1525
+ * # Example (JavaScript)
1526
+ *
1527
+ * ```js
1528
+ * console.log(grid.total()); // 1000 for a 10×10×10 grid
1529
+ * ```
1530
+ */
1531
+ total(): number;
1532
+ }
1533
+
1534
+ /**
1535
+ * Gyration tensor per cluster.
1536
+ *
1537
+ * Returns flat array: `[g00,g01,g02, g10,g11,g12, g20,g21,g22, ...]` per cluster.
1538
+ */
1539
+ export class GyrationTensor {
1540
+ free(): void;
1541
+ [Symbol.dispose](): void;
1542
+ /**
1543
+ * Compute gyration tensors. Returns a flat float typed array (9 values per cluster).
1544
+ */
1545
+ compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
1546
+ constructor();
1547
+ }
1548
+
1549
+ /**
1550
+ * Moment of inertia tensor per cluster.
1551
+ */
1552
+ export class InertiaTensor {
1553
+ free(): void;
1554
+ [Symbol.dispose](): void;
1555
+ /**
1556
+ * Compute inertia tensors. Returns a flat float typed array (9 values per cluster).
1557
+ */
1558
+ compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
1559
+ constructor(masses?: Float64Array | null);
1560
+ }
1561
+
1562
+ /**
1563
+ * LAMMPS dump trajectory file reader.
1564
+ *
1565
+ * Reads multi-frame LAMMPS dump files (the format produced by the
1566
+ * `dump` command). Each frame produces a [`Frame`] containing an
1567
+ * `"atoms"` block with columns matching the dump header (e.g.
1568
+ * `id`, `type`, `x`, `y`, `z`, `vx`, `vy`, `vz`).
1569
+ *
1570
+ * # Example (JavaScript)
1571
+ *
1572
+ * ```js
1573
+ * const reader = new LAMMPSDumpReader(dumpContent);
1574
+ * console.log(reader.len()); // number of timesteps
1575
+ * const frame = reader.read(0);
1576
+ * const atoms = frame.getBlock("atoms");
1577
+ * ```
1578
+ */
1579
+ export class LAMMPSDumpReader {
1580
+ free(): void;
1581
+ [Symbol.dispose](): void;
1582
+ /**
1583
+ * Check whether the file contains no frames.
1584
+ */
1585
+ isEmpty(): boolean;
1586
+ /**
1587
+ * Return the number of frames in the dump file.
1588
+ */
1589
+ len(): number;
1590
+ /**
1591
+ * Create a new LAMMPS dump reader from string content.
1592
+ */
1593
+ constructor(content: string);
1594
+ /**
1595
+ * Read a frame at the given step index.
1596
+ */
1597
+ read(step: number): Frame | undefined;
1598
+ }
1599
+
1172
1600
  /**
1173
1601
  * LAMMPS data file reader.
1174
1602
  *
1175
1603
  * Reads LAMMPS data files (the format written by `write_data`). The
1176
1604
  * reader produces a [`Frame`] containing:
1177
1605
  *
1178
- * - `"atoms"` block: `type` (i32), `x`, `y`, `z` (f32, angstrom),
1179
- * and optionally `charge` (f32)
1606
+ * - `"atoms"` block: `type` (i32), `x`, `y`, `z` (F, angstrom),
1607
+ * and optionally `charge` (F)
1180
1608
  * - `"bonds"` block (if present): `i`, `j` (u32), `type` (i32)
1181
1609
  * - Simulation box (`simbox`) with PBC
1182
1610
  *
@@ -1280,7 +1708,7 @@ export class LinkedCell {
1280
1708
  * Finds all unique pairs `(i < j)` of atoms within the cutoff
1281
1709
  * distance using the cell-list algorithm.
1282
1710
  *
1283
- * The frame must have an `"atoms"` block with `x`, `y`, `z` (f32) columns.
1711
+ * The frame must have an `"atoms"` block with `x`, `y`, `z` (F) columns.
1284
1712
  * If the frame has a `simbox`, periodic boundary conditions are used.
1285
1713
  * Otherwise, a free-boundary bounding box is auto-generated.
1286
1714
  *
@@ -1301,7 +1729,7 @@ export class LinkedCell {
1301
1729
  * ```js
1302
1730
  * const lc = new LinkedCell(3.0);
1303
1731
  * const nlist = lc.build(frame);
1304
- * const dists = nlist.distances(); // Float32Array
1732
+ * const dists = nlist.distances(); // Float32Array or Float64Array
1305
1733
  * ```
1306
1734
  */
1307
1735
  build(frame: Frame): NeighborList;
@@ -1385,7 +1813,7 @@ export class MSD {
1385
1813
  * # Arguments
1386
1814
  *
1387
1815
  * * `frame` - Frame with `"atoms"` block containing
1388
- * `x`, `y`, `z` (f32) columns
1816
+ * `x`, `y`, `z` (F) columns
1389
1817
  *
1390
1818
  * # Errors
1391
1819
  *
@@ -1446,7 +1874,7 @@ export class MSD {
1446
1874
  * ```js
1447
1875
  * const result = msd.compute(frame);
1448
1876
  * console.log(result.mean); // number (A^2)
1449
- * console.log(result.perParticle()); // Float32Array (A^2)
1877
+ * console.log(result.perParticle()); // Float32Array or Float64Array (A^2)
1450
1878
  * ```
1451
1879
  */
1452
1880
  export class MSDResult {
@@ -1454,12 +1882,11 @@ export class MSDResult {
1454
1882
  free(): void;
1455
1883
  [Symbol.dispose](): void;
1456
1884
  /**
1457
- * Per-particle squared displacements as `Float32Array` in A^2.
1458
- *
1459
- * `perParticle()[i]` is `|r_i(t) - r_i(0)|^2` for particle `i`.
1460
- * Length equals the number of atoms.
1885
+ * Zero-copy `Float64Array` view of per-particle squared displacements
1886
+ * in A². `perParticle()[i]` is `|r_i(t) - r_i(0)|²` for particle `i`.
1887
+ * **Invalidated** on WASM memory growth; copy in JS if needed.
1461
1888
  */
1462
- perParticle(): Float32Array;
1889
+ perParticle(): Float64Array;
1463
1890
  /**
1464
1891
  * System-average mean squared displacement in A^2.
1465
1892
  *
@@ -1469,6 +1896,19 @@ export class MSDResult {
1469
1896
  readonly mean: number;
1470
1897
  }
1471
1898
 
1899
+ /**
1900
+ * Reader for MolRec Zarr v3 archives.
1901
+ */
1902
+ export class MolRecReader {
1903
+ free(): void;
1904
+ [Symbol.dispose](): void;
1905
+ countAtoms(): number;
1906
+ countFrames(): number;
1907
+ free(): void;
1908
+ constructor(files: Map<any, any>);
1909
+ readFrame(t: number): Frame | undefined;
1910
+ }
1911
+
1472
1912
  /**
1473
1913
  * Result of a neighbor search: all atom pairs within a distance cutoff.
1474
1914
  *
@@ -1493,7 +1933,7 @@ export class MSDResult {
1493
1933
  *
1494
1934
  * const i = nlist.queryPointIndices(); // Uint32Array
1495
1935
  * const j = nlist.pointIndices(); // Uint32Array
1496
- * const d = nlist.distances(); // Float32Array (in A)
1936
+ * const d = nlist.distances(); // Float32Array or Float64Array (in A)
1497
1937
  * ```
1498
1938
  */
1499
1939
  export class NeighborList {
@@ -1501,28 +1941,26 @@ export class NeighborList {
1501
1941
  free(): void;
1502
1942
  [Symbol.dispose](): void;
1503
1943
  /**
1504
- * Squared pairwise distances in A^2, as a `Float32Array`.
1505
- *
1506
- * More efficient than `distances()` when you only need to
1507
- * compare or threshold distances.
1944
+ * Zero-copy `Float64Array` view of squared pairwise distances in A^2.
1945
+ * Same invalidation caveat as [`queryPointIndices`](Self::query_point_indices).
1508
1946
  */
1509
- distSq(): Float32Array;
1947
+ distSq(): Float64Array;
1510
1948
  /**
1511
- * Pairwise distances in angstrom (A), as a `Float32Array`.
1949
+ * Pairwise distances in angstrom (A). Computed lazily from `distSq`.
1512
1950
  *
1513
- * `distances()[k]` is the distance between query point
1514
- * `queryPointIndices()[k]` and reference point `pointIndices()[k]`.
1951
+ * Returns an owned copy because distances are derived on the fly
1952
+ * (`sqrt` per pair) rather than stored.
1515
1953
  */
1516
- distances(): Float32Array;
1954
+ distances(): Float64Array;
1517
1955
  /**
1518
- * Reference point indices (`j`) for each pair, as a `Uint32Array`.
1956
+ * Zero-copy `Uint32Array` view of reference point indices (`j`).
1957
+ * Same invalidation caveat as [`queryPointIndices`](Self::query_point_indices).
1519
1958
  */
1520
1959
  pointIndices(): Uint32Array;
1521
1960
  /**
1522
- * Query point indices (`i`) for each pair, as a `Uint32Array`.
1523
- *
1524
- * The `k`-th pair connects query point `queryPointIndices()[k]`
1525
- * to reference point `pointIndices()[k]`.
1961
+ * Zero-copy `Uint32Array` view of query point indices (`i`) over
1962
+ * WASM memory. **Invalidated** on any WASM memory growth — copy
1963
+ * in JS (`new Uint32Array(view)`) if it needs to outlive later calls.
1526
1964
  */
1527
1965
  queryPointIndices(): Uint32Array;
1528
1966
  /**
@@ -1552,8 +1990,8 @@ export class NeighborList {
1552
1990
  *
1553
1991
  * PDB files contain a single molecular structure. The reader produces
1554
1992
  * a [`Frame`] with an `"atoms"` block containing columns such as
1555
- * `name` (string), `resname` (string), `x`, `y`, `z` (f32, angstrom),
1556
- * and optionally `occupancy` and `bfactor` (f32).
1993
+ * `name` (string), `resname` (string), `x`, `y`, `z` (F, angstrom),
1994
+ * and optionally `occupancy` and `bfactor` (F).
1557
1995
  *
1558
1996
  * # Example (JavaScript)
1559
1997
  *
@@ -1562,7 +2000,7 @@ export class NeighborList {
1562
2000
  * const frame = reader.read(0);
1563
2001
  * const atoms = frame.getBlock("atoms");
1564
2002
  * const names = atoms.copyColStr("name"); // ["CA", "CB", ...]
1565
- * const x = atoms.copyColF32("x");
2003
+ * const x = atoms.copyColF("x");
1566
2004
  * ```
1567
2005
  */
1568
2006
  export class PDBReader {
@@ -1648,8 +2086,8 @@ export class PDBReader {
1648
2086
  * const rdf = new RDF(100, 5.0);
1649
2087
  * const result = rdf.compute(frame, nlist);
1650
2088
  *
1651
- * const r = result.binCenters(); // Float32Array, bin centers in A
1652
- * const gr = result.rdf(); // Float32Array, g(r) values
2089
+ * const r = result.binCenters(); // Float32Array or Float64Array, bin centers in A
2090
+ * const gr = result.rdf(); // Float32Array or Float64Array, g(r) values
1653
2091
  * ```
1654
2092
  */
1655
2093
  export class RDF {
@@ -1679,7 +2117,7 @@ export class RDF {
1679
2117
  *
1680
2118
  * ```js
1681
2119
  * const result = rdf.compute(frame, nlist);
1682
- * const gr = result.rdf(); // Float32Array
2120
+ * const gr = result.rdf(); // Float32Array or Float64Array
1683
2121
  * ```
1684
2122
  */
1685
2123
  compute(frame: Frame, neighbors: NeighborList): RDFResult;
@@ -1711,9 +2149,9 @@ export class RDF {
1711
2149
  *
1712
2150
  * ```js
1713
2151
  * const result = rdf.compute(frame, nlist);
1714
- * const r = result.binCenters(); // Float32Array [0.025, 0.075, ...]
1715
- * const gr = result.rdf(); // Float32Array, normalized g(r)
1716
- * const nr = result.pairCounts(); // Float32Array, raw counts
2152
+ * const r = result.binCenters(); // Float32Array or Float64Array [0.025, 0.075, ...]
2153
+ * const gr = result.rdf(); // Float32Array or Float64Array, normalized g(r)
2154
+ * const nr = result.pairCounts(); // Float32Array or Float64Array, raw counts
1717
2155
  * console.log("Volume:", result.volume, "A^3");
1718
2156
  * console.log("N_ref:", result.numPoints);
1719
2157
  * ```
@@ -1723,28 +2161,26 @@ export class RDFResult {
1723
2161
  free(): void;
1724
2162
  [Symbol.dispose](): void;
1725
2163
  /**
1726
- * Bin center positions as `Float32Array` in angstrom (A).
1727
- *
1728
- * Length equals `n_bins` (the value passed to the `RDF` constructor).
2164
+ * Zero-copy `Float64Array` view of bin center positions in A.
2165
+ * Length equals `n_bins`. **Invalidated** on WASM memory growth;
2166
+ * copy in JS if it needs to outlive later calls.
1729
2167
  */
1730
- binCenters(): Float32Array;
2168
+ binCenters(): Float64Array;
1731
2169
  /**
1732
- * Bin edge positions as `Float32Array` in angstrom (A).
1733
- *
1734
- * Length is `n_bins + 1` (one more than bin centers).
2170
+ * Zero-copy `Float64Array` view of bin edge positions in A.
2171
+ * Length is `n_bins + 1`. Same invalidation caveat.
1735
2172
  */
1736
- binEdges(): Float32Array;
2173
+ binEdges(): Float64Array;
1737
2174
  /**
1738
- * Raw (un-normalized) pair counts per bin as `Float32Array`.
2175
+ * Zero-copy `Float64Array` view of raw (un-normalized) pair counts
2176
+ * per bin. Same invalidation caveat.
1739
2177
  */
1740
- pairCounts(): Float32Array;
2178
+ pairCounts(): Float64Array;
1741
2179
  /**
1742
- * Normalized g(r) values as `Float32Array` (dimensionless).
1743
- *
1744
- * A uniform ideal gas has g(r) = 1.0 everywhere. Peaks indicate
1745
- * preferred interatomic distances (coordination shells).
2180
+ * Zero-copy `Float64Array` view of normalized g(r). Same invalidation
2181
+ * caveat.
1746
2182
  */
1747
- rdf(): Float32Array;
2183
+ rdf(): Float64Array;
1748
2184
  /**
1749
2185
  * Number of reference points used in the normalization.
1750
2186
  */
@@ -1756,112 +2192,63 @@ export class RDFResult {
1756
2192
  }
1757
2193
 
1758
2194
  /**
1759
- * Reader for Zarr V3 simulation archives.
2195
+ * Radius of gyration per cluster.
2196
+ */
2197
+ export class RadiusOfGyration {
2198
+ free(): void;
2199
+ [Symbol.dispose](): void;
2200
+ /**
2201
+ * Compute radii of gyration. Returns a float typed array of length `numClusters`.
2202
+ */
2203
+ compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
2204
+ constructor(masses?: Float64Array | null);
2205
+ }
2206
+
2207
+ /**
2208
+ * MDL molfile / SDF (V2000 CTAB) reader.
2209
+ *
2210
+ * Parses the connection table found in `.mol` files and the record
2211
+ * blocks of `.sdf` files. Coordinates come directly from the file —
2212
+ * no 3D generation is performed. Only V2000 is supported; V3000
2213
+ * records throw on read.
1760
2214
  *
1761
- * Wraps [`SimulationStore`] from `molrs-core` for reading trajectory
1762
- * frames and system metadata from an in-memory Zarr store. The store
1763
- * is populated from a `Map<string, Uint8Array>` of file paths to
1764
- * binary content.
2215
+ * Produces a [`Frame`] with:
2216
+ * - `"atoms"` block: `element` (string), `id` (u32, 1-based),
2217
+ * `x`, `y`, `z` (F, angstrom)
2218
+ * - `"bonds"` block (if present): `atomi`, `atomj` (u32, 0-based),
2219
+ * `order` (u32)
2220
+ *
2221
+ * Multi-record SDF files expose each record as a separate frame via
2222
+ * `read(step)`.
1765
2223
  *
1766
2224
  * # Example (JavaScript)
1767
2225
  *
1768
2226
  * ```js
1769
- * const files = new Map();
1770
- * files.set("zarr.json", new Uint8Array([...]));
1771
- * files.set("system/.zarray", new Uint8Array([...]));
1772
- * // ... etc.
1773
- *
1774
- * const reader = new SimulationReader(files);
1775
- * const frame = reader.readFrame(0);
2227
+ * const reader = new SDFReader(sdfContent);
2228
+ * const frame = reader.read(0);
2229
+ * const atoms = frame.getBlock("atoms");
2230
+ * const x = atoms.copyColF("x");
1776
2231
  * ```
1777
2232
  */
1778
- export class SimulationReader {
2233
+ export class SDFReader {
1779
2234
  free(): void;
1780
2235
  [Symbol.dispose](): void;
1781
2236
  /**
1782
- * Return the number of atoms in the system topology.
1783
- *
1784
- * # Example (JavaScript)
1785
- *
1786
- * ```js
1787
- * console.log(reader.countAtoms()); // e.g., 256
1788
- * ```
2237
+ * Check whether the file contains no records.
1789
2238
  */
1790
- countAtoms(): number;
2239
+ isEmpty(): boolean;
1791
2240
  /**
1792
- * Return the number of trajectory frames in the archive.
1793
- *
1794
- * Returns `0` if no trajectory data is present.
1795
- *
1796
- * # Errors
1797
- *
1798
- * Throws a `JsValue` string on I/O errors.
1799
- *
1800
- * # Example (JavaScript)
1801
- *
1802
- * ```js
1803
- * console.log(reader.countFrames()); // e.g., 1000
1804
- * ```
2241
+ * Return the total number of records in the SDF file.
1805
2242
  */
1806
- countFrames(): number;
2243
+ len(): number;
1807
2244
  /**
1808
- * Create a reader from a map of file paths to binary content.
1809
- *
1810
- * The map keys are relative paths within the Zarr archive
1811
- * (e.g., `"zarr.json"`, `"system/.zarray"`). Values are the
1812
- * raw bytes of each file as `Uint8Array`.
1813
- *
1814
- * # Arguments
1815
- *
1816
- * * `files` - `Map<string, Uint8Array>` mapping archive paths
1817
- * to their binary content
1818
- *
1819
- * # Returns
1820
- *
1821
- * A new `SimulationReader` ready to read frames.
1822
- *
1823
- * # Errors
1824
- *
1825
- * Throws a `JsValue` string if the archive cannot be opened
1826
- * (e.g., missing required metadata files).
1827
- *
1828
- * # Example (JavaScript)
1829
- *
1830
- * ```js
1831
- * const reader = new SimulationReader(filesMap);
1832
- * ```
2245
+ * Create a new SDF reader from a string containing the file content.
1833
2246
  */
1834
- constructor(files: Map<any, any>);
2247
+ constructor(content: string);
1835
2248
  /**
1836
- * Read a trajectory frame at the given time index.
1837
- *
1838
- * The returned [`Frame`] merges the static system topology
1839
- * (atoms, bonds) with the per-frame trajectory data (positions,
1840
- * velocities, etc.) at time step `t`.
1841
- *
1842
- * # Arguments
1843
- *
1844
- * * `t` - Zero-based time step index
1845
- *
1846
- * # Returns
1847
- *
1848
- * A [`Frame`] with merged system + trajectory data, or `undefined`
1849
- * if no trajectory is present.
1850
- *
1851
- * # Errors
1852
- *
1853
- * Throws a `JsValue` string on I/O or deserialization errors.
1854
- *
1855
- * # Example (JavaScript)
1856
- *
1857
- * ```js
1858
- * const frame = reader.readFrame(0);
1859
- * if (frame) {
1860
- * const x = frame.getBlock("atoms").copyColF32("x");
1861
- * }
1862
- * ```
2249
+ * Read the frame (SDF record) at the given step index.
1863
2250
  */
1864
- readFrame(t: number): Frame | undefined;
2251
+ read(step: number): Frame | undefined;
1865
2252
  }
1866
2253
 
1867
2254
  /**
@@ -1882,7 +2269,7 @@ export class SimulationReader {
1882
2269
  *
1883
2270
  * const frame = ir.toFrame();
1884
2271
  * const atoms = frame.getBlock("atoms");
1885
- * console.log(atoms.copyColStr("symbol")); // ["C", "C", "O", "H", ...]
2272
+ * console.log(atoms.copyColStr("element")); // ["C", "C", "O", "H", ...]
1886
2273
  * ```
1887
2274
  */
1888
2275
  export class SmilesIR {
@@ -1898,7 +2285,7 @@ export class SmilesIR {
1898
2285
  * are added. No 3D coordinates are present -- use
1899
2286
  * [`generate3D`](crate::generate_3d_wasm) to embed coordinates.
1900
2287
  * - `"bonds"` block: `i`, `j` (u32, zero-based atom indices),
1901
- * `order` (f32, bond order: 1.0 = single, 1.5 = aromatic,
2288
+ * `order` (F, bond order: 1.0 = single, 1.5 = aromatic,
1902
2289
  * 2.0 = double, 3.0 = triple).
1903
2290
  *
1904
2291
  * # Returns
@@ -1915,7 +2302,7 @@ export class SmilesIR {
1915
2302
  * ```js
1916
2303
  * const frame = ir.toFrame();
1917
2304
  * const bonds = frame.getBlock("bonds");
1918
- * const order = bonds.copyColF32("order");
2305
+ * const order = bonds.copyColF("order");
1919
2306
  * ```
1920
2307
  */
1921
2308
  toFrame(): Frame;
@@ -1936,26 +2323,183 @@ export class SmilesIR {
1936
2323
  }
1937
2324
 
1938
2325
  /**
1939
- * Owned f32 array with ndarray-compatible shape metadata.
2326
+ * Graph-based molecular topology with automated detection of angles,
2327
+ * dihedrals, impropers, connected components, and rings (SSSR).
2328
+ *
2329
+ * API mirrors igraph / molpy conventions.
2330
+ *
2331
+ * # Example (JavaScript)
2332
+ *
2333
+ * ```js
2334
+ * const topo = Topology.fromFrame(frame);
2335
+ * console.log(topo.nAtoms, topo.nBonds);
2336
+ *
2337
+ * const angles = topo.angles(); // Uint32Array [i,j,k, ...]
2338
+ * const dihedrals = topo.dihedrals(); // Uint32Array [i,j,k,l, ...]
2339
+ * const cc = topo.connectedComponents(); // Int32Array per-atom labels
2340
+ *
2341
+ * const rings = topo.findRings();
2342
+ * console.log(rings.numRings);
2343
+ * ```
2344
+ */
2345
+ export class Topology {
2346
+ free(): void;
2347
+ [Symbol.dispose](): void;
2348
+ /**
2349
+ * Add a single atom.
2350
+ */
2351
+ addAtom(): void;
2352
+ /**
2353
+ * Add a bond between atoms `i` and `j`.
2354
+ */
2355
+ addBond(i: number, j: number): void;
2356
+ /**
2357
+ * All angle triplets as flat `Uint32Array` `[i,j,k, ...]`.
2358
+ */
2359
+ angles(): Uint32Array;
2360
+ /**
2361
+ * Whether atoms `i` and `j` are directly bonded.
2362
+ */
2363
+ areBonded(i: number, j: number): boolean;
2364
+ /**
2365
+ * All bond pairs as flat `Uint32Array` `[i0,j0, i1,j1, ...]`.
2366
+ */
2367
+ bonds(): Uint32Array;
2368
+ /**
2369
+ * Per-atom connected component labels as `Int32Array`.
2370
+ *
2371
+ * Labels are 0-based and contiguous. Each atom gets a component ID.
2372
+ * Atoms in the same connected subgraph share the same label.
2373
+ */
2374
+ connectedComponents(): Int32Array;
2375
+ /**
2376
+ * Degree (number of bonds) of atom `idx`.
2377
+ */
2378
+ degree(idx: number): number;
2379
+ /**
2380
+ * Delete an atom by index.
2381
+ */
2382
+ deleteAtom(idx: number): void;
2383
+ /**
2384
+ * Delete a bond by edge index.
2385
+ */
2386
+ deleteBond(idx: number): void;
2387
+ /**
2388
+ * All proper dihedral quartets as flat `Uint32Array` `[i,j,k,l, ...]`.
2389
+ */
2390
+ dihedrals(): Uint32Array;
2391
+ /**
2392
+ * Compute the Smallest Set of Smallest Rings (SSSR).
2393
+ */
2394
+ findRings(): TopologyRingInfo;
2395
+ /**
2396
+ * Build a topology from a Frame's `bonds` block.
2397
+ *
2398
+ * Reads the `atoms` block for atom count and `bonds` block for
2399
+ * `i`, `j` columns (Uint32).
2400
+ */
2401
+ static fromFrame(frame: Frame): Topology;
2402
+ /**
2403
+ * All improper dihedral quartets as flat `Uint32Array` `[center,i,j,k, ...]`.
2404
+ */
2405
+ impropers(): Uint32Array;
2406
+ /**
2407
+ * Neighbor atom indices of atom `idx` as `Uint32Array`.
2408
+ */
2409
+ neighbors(idx: number): Uint32Array;
2410
+ /**
2411
+ * Create a topology with `n` atoms and no bonds.
2412
+ */
2413
+ constructor(n_atoms: number);
2414
+ /**
2415
+ * Number of unique angles.
2416
+ */
2417
+ readonly nAngles: number;
2418
+ /**
2419
+ * Number of atoms (vertices).
2420
+ */
2421
+ readonly nAtoms: number;
2422
+ /**
2423
+ * Number of bonds (edges).
2424
+ */
2425
+ readonly nBonds: number;
2426
+ /**
2427
+ * Number of connected components.
2428
+ */
2429
+ readonly nComponents: number;
2430
+ /**
2431
+ * Number of unique proper dihedrals.
2432
+ */
2433
+ readonly nDihedrals: number;
2434
+ }
2435
+
2436
+ /**
2437
+ * Result of ring detection (SSSR) on a topology graph.
2438
+ *
2439
+ * # Example (JavaScript)
2440
+ *
2441
+ * ```js
2442
+ * const rings = topo.findRings();
2443
+ * console.log(rings.numRings);
2444
+ * console.log(rings.ringSizes()); // Uint32Array
2445
+ * console.log(rings.isAtomInRing(0));
2446
+ *
2447
+ * // Get all rings as flat array [size0, idx0_0, idx0_1, ..., size1, ...]
2448
+ * const data = rings.rings();
2449
+ * ```
2450
+ */
2451
+ export class TopologyRingInfo {
2452
+ private constructor();
2453
+ free(): void;
2454
+ [Symbol.dispose](): void;
2455
+ /**
2456
+ * Per-atom boolean mask as `Uint8Array` (0 or 1). 1 if atom is in any ring.
2457
+ */
2458
+ atomRingMask(n_atoms: number): Uint8Array;
2459
+ /**
2460
+ * Whether atom `idx` belongs to any ring.
2461
+ */
2462
+ isAtomInRing(idx: number): boolean;
2463
+ /**
2464
+ * Number of rings containing atom `idx`.
2465
+ */
2466
+ numAtomRings(idx: number): number;
2467
+ /**
2468
+ * Size of each ring as `Uint32Array`.
2469
+ */
2470
+ ringSizes(): Uint32Array;
2471
+ /**
2472
+ * All rings as flat `Uint32Array` with length-prefixed encoding:
2473
+ * `[size0, atom0, atom1, ..., size1, atom0, atom1, ...]`.
2474
+ */
2475
+ rings(): Uint32Array;
2476
+ /**
2477
+ * Total number of rings detected.
2478
+ */
2479
+ readonly numRings: number;
2480
+ }
2481
+
2482
+ /**
2483
+ * Owned float array with ndarray-compatible shape metadata.
1940
2484
  *
1941
- * Stores a flat `Vec<f32>` together with a shape descriptor (e.g.,
2485
+ * Stores a flat `Vec<F>` together with a shape descriptor (e.g.,
1942
2486
  * `[N, 3]` for an Nx3 coordinate matrix). Used for passing
1943
2487
  * multi-dimensional numeric data across the WASM boundary.
1944
2488
  *
1945
2489
  * # Memory layout
1946
2490
  *
1947
2491
  * Data is stored in row-major (C) order, matching ndarray's default
1948
- * and JavaScript's `Float32Array` convention.
2492
+ * and JavaScript's float typed-array convention.
1949
2493
  *
1950
2494
  * # Example (JavaScript)
1951
2495
  *
1952
2496
  * ```js
1953
2497
  * // Create a 2x3 zero array
1954
2498
  * const arr = new WasmArray([2, 3]);
1955
- * arr.writeFrom(new Float32Array([1,2,3, 4,5,6]));
2499
+ * arr.writeFrom(floatArray);
1956
2500
  *
1957
2501
  * // Or from existing data
1958
- * const arr2 = WasmArray.from(new Float32Array([1,2,3]), [1, 3]);
2502
+ * const arr2 = WasmArray.from(floatArray, [1, 3]);
1959
2503
  *
1960
2504
  * // Get data back
1961
2505
  * const copy = arr.toCopy(); // safe owned copy
@@ -1966,15 +2510,15 @@ export class WasmArray {
1966
2510
  free(): void;
1967
2511
  [Symbol.dispose](): void;
1968
2512
  /**
1969
- * Return the data type string. Always `"float"` for `WasmArray`.
2513
+ * Return the concrete float dtype string for this build.
1970
2514
  */
1971
2515
  dtype(): string;
1972
2516
  /**
1973
- * Create a `WasmArray` from an existing JS `Float32Array`.
2517
+ * Create a `WasmArray` from an existing JS float typed array.
1974
2518
  *
1975
2519
  * # Arguments
1976
2520
  *
1977
- * * `data` - Source `Float32Array`
2521
+ * * `data` - Source float typed array (`Float32Array` or `Float64Array`)
1978
2522
  * * `shape` - Optional shape. If omitted, defaults to `[data.length]` (1D).
1979
2523
  *
1980
2524
  * # Returns
@@ -1988,11 +2532,11 @@ export class WasmArray {
1988
2532
  * # Example (JavaScript)
1989
2533
  *
1990
2534
  * ```js
1991
- * const arr = WasmArray.from(new Float32Array([1,2,3,4,5,6]), [2, 3]);
2535
+ * const arr = WasmArray.from(floatArray, [2, 3]);
1992
2536
  * console.log(arr.shape()); // [2, 3]
1993
2537
  * ```
1994
2538
  */
1995
- static from(data: Float32Array, shape?: Uint32Array | null): WasmArray;
2539
+ static from(data: Float64Array, shape?: Uint32Array | null): WasmArray;
1996
2540
  /**
1997
2541
  * Check whether the array contains no elements.
1998
2542
  */
@@ -2052,13 +2596,13 @@ export class WasmArray {
2052
2596
  * # Example (JavaScript)
2053
2597
  *
2054
2598
  * ```js
2055
- * const arr = WasmArray.from(new Float32Array([1, 2, 3]));
2599
+ * const arr = WasmArray.from(floatArray);
2056
2600
  * console.log(arr.sum()); // 6.0
2057
2601
  * ```
2058
2602
  */
2059
2603
  sum(): number;
2060
2604
  /**
2061
- * Create an owned JS `Float32Array` copy of the data.
2605
+ * Create an owned JS float typed-array copy of the data.
2062
2606
  *
2063
2607
  * The returned array is an independent copy that is safe to store
2064
2608
  * and use regardless of subsequent WASM memory operations.
@@ -2069,9 +2613,9 @@ export class WasmArray {
2069
2613
  * const copy = arr.toCopy(); // safe to keep indefinitely
2070
2614
  * ```
2071
2615
  */
2072
- toCopy(): Float32Array;
2616
+ toCopy(): Float64Array;
2073
2617
  /**
2074
- * Zero-copy `Float32Array` view over this array's backing storage.
2618
+ * Zero-copy float typed-array view over this array's backing storage.
2075
2619
  *
2076
2620
  * **Warning**: The returned view becomes **invalid** if WASM linear
2077
2621
  * memory grows (due to any allocation). Use [`toCopy`](WasmArray::to_copy)
@@ -2079,7 +2623,8 @@ export class WasmArray {
2079
2623
  *
2080
2624
  * # Safety (internal)
2081
2625
  *
2082
- * Uses `Float32Array::view` which creates an unowned view into
2626
+ * Uses the corresponding JS float typed-array `view` constructor,
2627
+ * which creates an unowned view into
2083
2628
  * WASM memory. The view must not outlive the `WasmArray` and must
2084
2629
  * not be used after any allocation that could trigger memory growth.
2085
2630
  *
@@ -2090,16 +2635,16 @@ export class WasmArray {
2090
2635
  * // Do NOT allocate between view creation and use
2091
2636
  * ```
2092
2637
  */
2093
- toTypedArray(): Float32Array;
2638
+ toTypedArray(): Float64Array;
2094
2639
  /**
2095
- * Overwrite the array contents from a JS `Float32Array`.
2640
+ * Overwrite the array contents from a JS float typed array.
2096
2641
  *
2097
2642
  * The source array must have exactly the same number of elements
2098
2643
  * as this `WasmArray` (i.e., the shape is preserved).
2099
2644
  *
2100
2645
  * # Arguments
2101
2646
  *
2102
- * * `arr` - Source `Float32Array` with matching length
2647
+ * * `arr` - Source float typed array with matching length
2103
2648
  *
2104
2649
  * # Errors
2105
2650
  *
@@ -2109,10 +2654,10 @@ export class WasmArray {
2109
2654
  *
2110
2655
  * ```js
2111
2656
  * const wa = new WasmArray([3]);
2112
- * wa.writeFrom(new Float32Array([1.0, 2.0, 3.0]));
2657
+ * wa.writeFrom(floatArray);
2113
2658
  * ```
2114
2659
  */
2115
- write_from(arr: Float32Array): void;
2660
+ write_from(arr: Float64Array): void;
2116
2661
  }
2117
2662
 
2118
2663
  /**
@@ -2120,7 +2665,7 @@ export class WasmArray {
2120
2665
  *
2121
2666
  * Supports multi-frame trajectory files. Each frame produces a
2122
2667
  * [`Frame`] with an `"atoms"` block containing `element` (string)
2123
- * and `x`, `y`, `z` (f32, coordinates in angstrom) columns.
2668
+ * and `x`, `y`, `z` (F, coordinates in angstrom) columns.
2124
2669
  *
2125
2670
  * # Example (JavaScript)
2126
2671
  *
@@ -2131,7 +2676,7 @@ export class WasmArray {
2131
2676
  *
2132
2677
  * const frame = reader.read(0); // first frame
2133
2678
  * const atoms = frame.getBlock("atoms");
2134
- * const x = atoms.copyColF32("x");
2679
+ * const x = atoms.copyColF("x");
2135
2680
  * ```
2136
2681
  */
2137
2682
  export class XYZReader {
@@ -2208,13 +2753,13 @@ export class XYZReader {
2208
2753
  /**
2209
2754
  * Generate 3D coordinates for a molecular [`Frame`].
2210
2755
  *
2211
- * The input frame must have an `"atoms"` block with a `"symbol"`
2756
+ * The input frame must have an `"atoms"` block with a `"element"`
2212
2757
  * string column (element symbols like `"C"`, `"N"`, `"O"`). A
2213
- * `"bonds"` block with `i`, `j` (u32) and `order` (f32) columns
2758
+ * `"bonds"` block with `i`, `j` (u32) and `order` (F) columns
2214
2759
  * is required for correct geometry.
2215
2760
  *
2216
2761
  * Returns a **new** [`Frame`] with 3D coordinates added as `x`, `y`,
2217
- * `z` (f32, angstrom) columns in the `"atoms"` block.
2762
+ * `z` (F, angstrom) columns in the `"atoms"` block.
2218
2763
  *
2219
2764
  * # Arguments
2220
2765
  *
@@ -2247,9 +2792,9 @@ export class XYZReader {
2247
2792
  * const frame3d = generate3D(frame2d, "fast", 42);
2248
2793
  *
2249
2794
  * const atoms = frame3d.getBlock("atoms");
2250
- * const x = atoms.copyColF32("x"); // Float32Array with 3D x-coords
2251
- * const y = atoms.copyColF32("y");
2252
- * const z = atoms.copyColF32("z");
2795
+ * const x = atoms.copyColF("x"); // Float32Array or Float64Array with 3D x-coords
2796
+ * const y = atoms.copyColF("y");
2797
+ * const z = atoms.copyColF("z");
2253
2798
  * ```
2254
2799
  */
2255
2800
  export function generate3D(frame: Frame, speed?: string | null, seed?: number | null): Frame;
@@ -2301,7 +2846,7 @@ export function start(): void;
2301
2846
  *
2302
2847
  * ```js
2303
2848
  * const mem = wasmMemory();
2304
- * const buf = new Float32Array(mem.buffer, ptr, len);
2849
+ * const buf = new Float64Array(mem.buffer, ptr, len); // or Float32Array in default builds
2305
2850
  * ```
2306
2851
  */
2307
2852
  export function wasmMemory(): WebAssembly.Memory;