@molcrafts/molrs 0.0.7 → 0.0.12

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
  *
@@ -816,9 +817,9 @@ export class CenterOfMass {
816
817
  /**
817
818
  * Create a center-of-mass calculator.
818
819
  *
819
- * Pass `null` for uniform masses, or a `Float32Array` of per-particle masses.
820
+ * Pass `null` for uniform masses, or a float typed array of per-particle masses.
820
821
  */
821
- constructor(masses?: Float32Array | null);
822
+ constructor(masses?: Float64Array | null);
822
823
  }
823
824
 
824
825
  /**
@@ -828,8 +829,8 @@ export class CenterOfMass {
828
829
  *
829
830
  * ```js
830
831
  * const com = new CenterOfMass().compute(frame, clusterResult);
831
- * com.centersOfMass(); // Float32Array [x0,y0,z0, ...]
832
- * com.clusterMasses(); // Float32Array
832
+ * com.centersOfMass(); // Float32Array or Float64Array [x0,y0,z0, ...]
833
+ * com.clusterMasses(); // Float32Array or Float64Array
833
834
  * ```
834
835
  */
835
836
  export class CenterOfMassResult {
@@ -837,13 +838,15 @@ export class CenterOfMassResult {
837
838
  free(): void;
838
839
  [Symbol.dispose](): void;
839
840
  /**
840
- * Mass-weighted centers, flat `[x0,y0,z0, x1,y1,z1, ...]`.
841
+ * Zero-copy `Float64Array` view of mass-weighted centers, flat
842
+ * `[x0,y0,z0, x1,y1,z1, ...]`. **Invalidated** on WASM memory growth.
841
843
  */
842
- centersOfMass(): Float32Array;
844
+ centersOfMass(): Float64Array;
843
845
  /**
844
- * Total mass per cluster.
846
+ * Zero-copy `Float64Array` view of total mass per cluster.
847
+ * **Invalidated** on WASM memory growth.
845
848
  */
846
- clusterMasses(): Float32Array;
849
+ clusterMasses(): Float64Array;
847
850
  /**
848
851
  * Number of clusters.
849
852
  */
@@ -923,16 +926,16 @@ export class Cluster {
923
926
  *
924
927
  * ```js
925
928
  * const centers = new ClusterCenters().compute(frame, clusterResult);
926
- * // Float32Array [x0,y0,z0, x1,y1,z1, ...]
929
+ * // Float32Array or Float64Array [x0,y0,z0, x1,y1,z1, ...]
927
930
  * ```
928
931
  */
929
932
  export class ClusterCenters {
930
933
  free(): void;
931
934
  [Symbol.dispose](): void;
932
935
  /**
933
- * Compute geometric centers. Returns flat `Float32Array` `[x0,y0,z0, ...]`.
936
+ * Compute geometric centers. Returns a flat float typed array `[x0,y0,z0, ...]`.
934
937
  */
935
- compute(frame: Frame, cluster_result: ClusterResult): Float32Array;
938
+ compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
936
939
  constructor();
937
940
  }
938
941
 
@@ -991,10 +994,10 @@ export class ClusterResult {
991
994
  * # Conventions
992
995
  *
993
996
  * - The `"atoms"` block should contain per-atom properties: `symbol`
994
- * (string), `x`/`y`/`z` (f32, coordinates in angstrom), and optionally
995
- * `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).
996
999
  * - The `"bonds"` block should contain bond topology: `i`/`j` (u32,
997
- * 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,
998
1001
  * 1.5 = aromatic, 2.0 = double, 3.0 = triple).
999
1002
  *
1000
1003
  * # Example (JavaScript)
@@ -1002,7 +1005,7 @@ export class ClusterResult {
1002
1005
  * ```js
1003
1006
  * const frame = new Frame();
1004
1007
  * const atoms = frame.createBlock("atoms");
1005
- * atoms.setColF32("x", new Float32Array([0.0, 1.54]));
1008
+ * atoms.setColF("x", xCoords);
1006
1009
  * ```
1007
1010
  */
1008
1011
  export class Frame {
@@ -1044,7 +1047,7 @@ export class Frame {
1044
1047
  *
1045
1048
  * ```js
1046
1049
  * const atoms = frame.createBlock("atoms");
1047
- * atoms.setColF32("x", new Float32Array([1.0, 2.0]));
1050
+ * atoms.setColF("x", xCoords);
1048
1051
  * ```
1049
1052
  */
1050
1053
  createBlock(key: string): Block;
@@ -1084,11 +1087,82 @@ export class Frame {
1084
1087
  * ```js
1085
1088
  * const atoms = frame.getBlock("atoms");
1086
1089
  * if (atoms) {
1087
- * const x = atoms.copyColF32("x");
1090
+ * const x = atoms.copyColF("x");
1088
1091
  * }
1089
1092
  * ```
1090
1093
  */
1091
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
+ * Read a per-frame metadata value as a numeric scalar.
1119
+ *
1120
+ * Returns `Some(v)` if the meta key exists AND its string value parses
1121
+ * as an `f64`. Returns `None` if the key is missing or the value is
1122
+ * non-numeric (e.g., `config="trans"`).
1123
+ *
1124
+ * `frame.meta` is a `HashMap<String, String>`; the ExtXYZ parser stores
1125
+ * all comment-line values as strings. This accessor reads numeric ones
1126
+ * via `str::parse::<f64>`.
1127
+ *
1128
+ * # Arguments
1129
+ *
1130
+ * * `name` — Meta key to look up (e.g., `"energy"`, `"temp"`).
1131
+ *
1132
+ * # Example (JavaScript)
1133
+ *
1134
+ * ```js
1135
+ * const energy = frame.getMetaScalar("energy");
1136
+ * if (energy !== undefined) {
1137
+ * console.log("Energy:", energy);
1138
+ * }
1139
+ * ```
1140
+ */
1141
+ getMetaScalar(name: string): number | undefined;
1142
+ /**
1143
+ * Return the names of all grids attached to this frame.
1144
+ *
1145
+ * # Example (JavaScript)
1146
+ *
1147
+ * ```js
1148
+ * const names = frame.gridNames(); // e.g. ["chgcar", "spin"]
1149
+ * ```
1150
+ */
1151
+ gridNames(): Array<any>;
1152
+ /**
1153
+ * Returns `true` if a named grid is attached to this frame.
1154
+ *
1155
+ * # Arguments
1156
+ *
1157
+ * * `name` — Grid name to look up.
1158
+ *
1159
+ * # Example (JavaScript)
1160
+ *
1161
+ * ```js
1162
+ * frame.hasGrid("chgcar"); // true or false
1163
+ * ```
1164
+ */
1165
+ hasGrid(name: string): boolean;
1092
1166
  /**
1093
1167
  * Insert a block by deep-copying its data into this frame's store.
1094
1168
  *
@@ -1116,6 +1190,45 @@ export class Frame {
1116
1190
  * ```
1117
1191
  */
1118
1192
  insertBlock(key: string, block: Block): void;
1193
+ /**
1194
+ * Attach a grid to this frame under the given name.
1195
+ *
1196
+ * If a grid with the same name already exists it is replaced. The grid
1197
+ * data is moved into the frame; the JS `Grid` object becomes empty after
1198
+ * this call and should not be reused.
1199
+ *
1200
+ * # Arguments
1201
+ *
1202
+ * * `name` — Name to store the grid under (e.g., `"chgcar"`).
1203
+ * * `grid` — The [`Grid`] to attach.
1204
+ *
1205
+ * # Errors
1206
+ *
1207
+ * Throws a `JsValue` string if the frame has been dropped.
1208
+ *
1209
+ * # Example (JavaScript)
1210
+ *
1211
+ * ```js
1212
+ * const grid = new Grid(10, 10, 10, origin, cell, true, true, true);
1213
+ * grid.insertArray("rho", rhoData);
1214
+ * frame.insertGrid("chgcar", grid);
1215
+ * ```
1216
+ */
1217
+ insertGrid(name: string, grid: Grid): void;
1218
+ /**
1219
+ * Return the names of all metadata keys on this frame.
1220
+ *
1221
+ * Includes all keys regardless of whether their values are numeric
1222
+ * or categorical. To filter to numeric keys, iterate and call
1223
+ * [`getMetaScalar`](Self::get_meta_scalar) on each.
1224
+ *
1225
+ * # Example (JavaScript)
1226
+ *
1227
+ * ```js
1228
+ * const names = frame.metaNames(); // e.g. ["energy", "config", "temp"]
1229
+ * ```
1230
+ */
1231
+ metaNames(): string[];
1119
1232
  /**
1120
1233
  * Create a new, empty `Frame` with no blocks and no simulation box.
1121
1234
  *
@@ -1145,6 +1258,24 @@ export class Frame {
1145
1258
  * ```
1146
1259
  */
1147
1260
  removeBlock(key: string): void;
1261
+ /**
1262
+ * Remove a named grid from this frame.
1263
+ *
1264
+ * # Arguments
1265
+ *
1266
+ * * `name` — Grid name to remove.
1267
+ *
1268
+ * # Errors
1269
+ *
1270
+ * Throws a `JsValue` string if the frame has been dropped.
1271
+ *
1272
+ * # Example (JavaScript)
1273
+ *
1274
+ * ```js
1275
+ * frame.removeGrid("chgcar");
1276
+ * ```
1277
+ */
1278
+ removeGrid(name: string): void;
1148
1279
  /**
1149
1280
  * Rename a block from `old_key` to `new_key`.
1150
1281
  *
@@ -1194,6 +1325,33 @@ export class Frame {
1194
1325
  * ```
1195
1326
  */
1196
1327
  renameColumn(block_key: string, old_col: string, new_col: string): boolean;
1328
+ /**
1329
+ * Set a per-frame metadata value.
1330
+ *
1331
+ * Stores `value` as the string backing for `name` on `frame.meta`.
1332
+ * Numeric values are read back via
1333
+ * [`getMetaScalar`](Self::get_meta_scalar) by parsing the string
1334
+ * form. `frame.meta` is the single source of truth for per-frame
1335
+ * scalars — no separate aggregation layer is needed on the JS side.
1336
+ *
1337
+ * # Arguments
1338
+ *
1339
+ * * `name` — Meta key (e.g., `"energy"`, `"temp"`).
1340
+ * * `value` — String value. For numeric labels, the caller is
1341
+ * responsible for converting (e.g., `num.toString()`).
1342
+ *
1343
+ * # Errors
1344
+ *
1345
+ * Throws a `JsValue` string if the frame has been dropped.
1346
+ *
1347
+ * # Example (JavaScript)
1348
+ *
1349
+ * ```js
1350
+ * frame.setMeta("energy", "-3.14");
1351
+ * frame.setMeta("note", "run-42");
1352
+ * ```
1353
+ */
1354
+ setMeta(name: string, value: string): void;
1197
1355
  /**
1198
1356
  * Get the simulation box attached to this frame (if any).
1199
1357
  *
@@ -1229,13 +1387,216 @@ export class Frame {
1229
1387
  * # Example (JavaScript)
1230
1388
  *
1231
1389
  * ```js
1232
- * const origin = new Float32Array([0, 0, 0]);
1390
+ * const origin = originVec;
1233
1391
  * frame.simbox = Box.cube(10.0, origin, true, true, true);
1234
1392
  * ```
1235
1393
  */
1236
1394
  set simbox(value: Box | null | undefined);
1237
1395
  }
1238
1396
 
1397
+ /**
1398
+ * A uniform spatial grid storing multiple named scalar arrays.
1399
+ *
1400
+ * All arrays in a `Grid` share the same spatial definition: dimensions
1401
+ * (`[nx, ny, nz]`), Cartesian origin, cell matrix (columns are lattice
1402
+ * vectors, matching VASP/molrs convention), and periodic boundary flags.
1403
+ *
1404
+ * # Example (JavaScript)
1405
+ *
1406
+ * ```js
1407
+ * // Create a 10×10×10 cubic grid
1408
+ * const origin = new Float32Array([0, 0, 0]);
1409
+ * const cell = new Float32Array([
1410
+ * 10, 0, 0, // first column (a vector)
1411
+ * 0,10, 0, // second column (b vector)
1412
+ * 0, 0,10, // third column (c vector)
1413
+ * ]);
1414
+ * const grid = new Grid(10, 10, 10, origin, cell, true, true, true);
1415
+ *
1416
+ * // Insert a density array (must have length = 10*10*10 = 1000)
1417
+ * const rho = new Float32Array(1000).fill(1.0);
1418
+ * grid.insertArray("rho", rho);
1419
+ *
1420
+ * // Retrieve it
1421
+ * const arr = grid.getArray("rho");
1422
+ * console.log(arr.toCopy());
1423
+ * ```
1424
+ */
1425
+ export class Grid {
1426
+ free(): void;
1427
+ [Symbol.dispose](): void;
1428
+ /**
1429
+ * Names of all scalar arrays stored in this grid.
1430
+ *
1431
+ * # Example (JavaScript)
1432
+ *
1433
+ * ```js
1434
+ * const names = grid.arrayNames(); // e.g. ["rho", "spin"]
1435
+ * ```
1436
+ */
1437
+ arrayNames(): Array<any>;
1438
+ /**
1439
+ * Cell matrix in Ångström as a flat array of length 9 in column-major
1440
+ * order (columns are lattice vectors, matching VASP/molrs convention).
1441
+ *
1442
+ * Layout: `[col0_x, col0_y, col0_z, col1_x, col1_y, col1_z, col2_x, col2_y, col2_z]`
1443
+ *
1444
+ * # Example (JavaScript)
1445
+ *
1446
+ * ```js
1447
+ * const c = grid.cell();
1448
+ * const flat = c.toCopy(); // Float32Array of length 9
1449
+ * ```
1450
+ */
1451
+ cell(): WasmArray;
1452
+ /**
1453
+ * Grid dimensions `[nx, ny, nz]`.
1454
+ *
1455
+ * # Example (JavaScript)
1456
+ *
1457
+ * ```js
1458
+ * console.log(grid.dim()); // [10, 10, 10]
1459
+ * ```
1460
+ */
1461
+ dim(): Uint32Array;
1462
+ /**
1463
+ * Retrieve a named scalar array as a zero-copy `Float64Array` view
1464
+ * over the underlying WASM memory. Flat row-major order, length
1465
+ * `nx * ny * nz`. Use [`Grid::dim`] for shape.
1466
+ *
1467
+ * **Warning**: the view is invalidated on any WASM memory growth.
1468
+ * Copy it in JS (`new Float64Array(view)`) if it needs to outlive
1469
+ * subsequent allocations.
1470
+ *
1471
+ * Returns `undefined` if the named array does not exist.
1472
+ *
1473
+ * # Example (JavaScript)
1474
+ *
1475
+ * ```js
1476
+ * const view = grid.getArray("rho"); // zero-copy
1477
+ * const copy = new Float64Array(view); // owned copy if needed
1478
+ * ```
1479
+ */
1480
+ getArray(name: string): Float64Array | undefined;
1481
+ /**
1482
+ * Returns `true` if a named array is present in this grid.
1483
+ *
1484
+ * # Arguments
1485
+ *
1486
+ * * `name` — Array name to look up.
1487
+ *
1488
+ * # Example (JavaScript)
1489
+ *
1490
+ * ```js
1491
+ * grid.hasArray("rho"); // true or false
1492
+ * ```
1493
+ */
1494
+ hasArray(name: string): boolean;
1495
+ /**
1496
+ * Insert (or replace) a named scalar array.
1497
+ *
1498
+ * The provided `data` must have exactly `nx * ny * nz` elements in
1499
+ * row-major `(ix, iy, iz)` order.
1500
+ *
1501
+ * # Arguments
1502
+ *
1503
+ * * `name` — Array name.
1504
+ * * `data` — Float32Array with length equal to `grid.total()`.
1505
+ *
1506
+ * # Errors
1507
+ *
1508
+ * Throws if `data.length != nx * ny * nz`.
1509
+ *
1510
+ * # Example (JavaScript)
1511
+ *
1512
+ * ```js
1513
+ * const rho = new Float32Array(grid.total()).fill(0.5);
1514
+ * grid.insertArray("rho", rho);
1515
+ * ```
1516
+ */
1517
+ insertArray(name: string, data: Float64Array): void;
1518
+ /**
1519
+ * Returns `true` if no arrays are stored.
1520
+ *
1521
+ * # Example (JavaScript)
1522
+ *
1523
+ * ```js
1524
+ * console.log(grid.isEmpty()); // true for a freshly created grid
1525
+ * ```
1526
+ */
1527
+ isEmpty(): boolean;
1528
+ /**
1529
+ * Number of named arrays stored in this grid.
1530
+ *
1531
+ * # Example (JavaScript)
1532
+ *
1533
+ * ```js
1534
+ * console.log(grid.len()); // e.g. 2
1535
+ * ```
1536
+ */
1537
+ len(): number;
1538
+ /**
1539
+ * Create a new empty grid with the given spatial definition.
1540
+ *
1541
+ * # Arguments
1542
+ *
1543
+ * * `dim_x`, `dim_y`, `dim_z` — Number of grid points along each axis.
1544
+ * * `origin` — Float32Array of length 3: Cartesian origin in Ångström.
1545
+ * * `cell` — Float32Array of length 9: cell matrix in column-major order.
1546
+ * `cell[0..3]` is the first lattice vector (a), `cell[3..6]` is b,
1547
+ * `cell[6..9]` is c (matching VASP/molrs convention where columns are
1548
+ * lattice vectors).
1549
+ * * `pbc_x`, `pbc_y`, `pbc_z` — Periodic boundary flags for each axis.
1550
+ *
1551
+ * # Errors
1552
+ *
1553
+ * Throws if `origin` does not have length 3, or `cell` does not have
1554
+ * length 9.
1555
+ *
1556
+ * # Example (JavaScript)
1557
+ *
1558
+ * ```js
1559
+ * const origin = new Float32Array([0, 0, 0]);
1560
+ * const cell = new Float32Array([10,0,0, 0,10,0, 0,0,10]);
1561
+ * const grid = new Grid(10, 10, 10, origin, cell, true, true, true);
1562
+ * ```
1563
+ */
1564
+ constructor(dim_x: number, dim_y: number, dim_z: number, origin: Float64Array, cell: Float64Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean);
1565
+ /**
1566
+ * Cartesian origin in Ångström as a 1-D array of length 3.
1567
+ *
1568
+ * # Example (JavaScript)
1569
+ *
1570
+ * ```js
1571
+ * const o = grid.origin();
1572
+ * const arr = o.toCopy(); // Float32Array [ox, oy, oz]
1573
+ * ```
1574
+ */
1575
+ origin(): WasmArray;
1576
+ /**
1577
+ * Periodic boundary flags as a `Uint8Array`-compatible slice.
1578
+ *
1579
+ * Each element is `1` (periodic) or `0` (not periodic).
1580
+ *
1581
+ * # Example (JavaScript)
1582
+ *
1583
+ * ```js
1584
+ * console.log(grid.pbc()); // [1, 1, 1]
1585
+ * ```
1586
+ */
1587
+ pbc(): Uint8Array;
1588
+ /**
1589
+ * Total number of voxels: `nx * ny * nz`.
1590
+ *
1591
+ * # Example (JavaScript)
1592
+ *
1593
+ * ```js
1594
+ * console.log(grid.total()); // 1000 for a 10×10×10 grid
1595
+ * ```
1596
+ */
1597
+ total(): number;
1598
+ }
1599
+
1239
1600
  /**
1240
1601
  * Gyration tensor per cluster.
1241
1602
  *
@@ -1245,9 +1606,13 @@ export class GyrationTensor {
1245
1606
  free(): void;
1246
1607
  [Symbol.dispose](): void;
1247
1608
  /**
1248
- * Compute gyration tensors. Returns flat `Float32Array` (9 values per cluster).
1609
+ * Compute gyration tensors. Returns a flat float typed array (9 values per cluster).
1610
+ *
1611
+ * Internally computes the cluster geometric centers (via
1612
+ * [`RsClusterCenters`]) since the new compute trait exposes them as a
1613
+ * required upstream — the old single-frame wasm API hides this detail.
1249
1614
  */
1250
- compute(frame: Frame, cluster_result: ClusterResult): Float32Array;
1615
+ compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
1251
1616
  constructor();
1252
1617
  }
1253
1618
 
@@ -1258,10 +1623,14 @@ export class InertiaTensor {
1258
1623
  free(): void;
1259
1624
  [Symbol.dispose](): void;
1260
1625
  /**
1261
- * Compute inertia tensors. Returns flat `Float32Array` (9 values per cluster).
1626
+ * Compute inertia tensors. Returns a flat float typed array (9 values per cluster).
1627
+ *
1628
+ * Internally computes the cluster centers of mass (via
1629
+ * [`RsCenterOfMass`]) since the new compute trait consumes them as a
1630
+ * required upstream — the old single-frame wasm API hides this detail.
1262
1631
  */
1263
- compute(frame: Frame, cluster_result: ClusterResult): Float32Array;
1264
- constructor(masses?: Float32Array | null);
1632
+ compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
1633
+ constructor(masses?: Float64Array | null);
1265
1634
  }
1266
1635
 
1267
1636
  /**
@@ -1308,8 +1677,8 @@ export class LAMMPSDumpReader {
1308
1677
  * Reads LAMMPS data files (the format written by `write_data`). The
1309
1678
  * reader produces a [`Frame`] containing:
1310
1679
  *
1311
- * - `"atoms"` block: `type` (i32), `x`, `y`, `z` (f32, angstrom),
1312
- * and optionally `charge` (f32)
1680
+ * - `"atoms"` block: `type` (i32), `x`, `y`, `z` (F, angstrom),
1681
+ * and optionally `charge` (F)
1313
1682
  * - `"bonds"` block (if present): `i`, `j` (u32), `type` (i32)
1314
1683
  * - Simulation box (`simbox`) with PBC
1315
1684
  *
@@ -1413,7 +1782,7 @@ export class LinkedCell {
1413
1782
  * Finds all unique pairs `(i < j)` of atoms within the cutoff
1414
1783
  * distance using the cell-list algorithm.
1415
1784
  *
1416
- * The frame must have an `"atoms"` block with `x`, `y`, `z` (f32) columns.
1785
+ * The frame must have an `"atoms"` block with `x`, `y`, `z` (F) columns.
1417
1786
  * If the frame has a `simbox`, periodic boundary conditions are used.
1418
1787
  * Otherwise, a free-boundary bounding box is auto-generated.
1419
1788
  *
@@ -1434,7 +1803,7 @@ export class LinkedCell {
1434
1803
  * ```js
1435
1804
  * const lc = new LinkedCell(3.0);
1436
1805
  * const nlist = lc.build(frame);
1437
- * const dists = nlist.distances(); // Float32Array
1806
+ * const dists = nlist.distances(); // Float32Array or Float64Array
1438
1807
  * ```
1439
1808
  */
1440
1809
  build(frame: Frame): NeighborList;
@@ -1512,25 +1881,23 @@ export class MSD {
1512
1881
  /**
1513
1882
  * Feed a frame into the MSD analysis.
1514
1883
  *
1515
- * The first frame sets the reference configuration.
1516
- * Subsequent frames compute MSD relative to that reference.
1884
+ * Internally clones the frame's core data so subsequent mutations on
1885
+ * the JS side (e.g. trajectory playback overwriting buffers) do not
1886
+ * race against pending [`results`](Self::results) calls. The first
1887
+ * frame sets the reference configuration.
1517
1888
  *
1518
1889
  * # Arguments
1519
1890
  *
1520
1891
  * * `frame` - Frame with `"atoms"` block containing
1521
- * `x`, `y`, `z` (f32) columns
1522
- *
1523
- * # Errors
1524
- *
1525
- * Throws if the frame is missing required columns or has a
1526
- * different number of atoms than the reference.
1892
+ * `x`, `y`, `z` (F) columns
1527
1893
  *
1528
1894
  * # Example (JavaScript)
1529
1895
  *
1530
1896
  * ```js
1531
1897
  * const msd = new MSD();
1532
1898
  * msd.feed(frame0); // sets reference
1533
- * msd.feed(frame1); // computes MSD vs frame0
1899
+ * msd.feed(frame1); // added to trajectory
1900
+ * const series = msd.results();
1534
1901
  * ```
1535
1902
  */
1536
1903
  feed(frame: Frame): void;
@@ -1548,14 +1915,14 @@ export class MSD {
1548
1915
  */
1549
1916
  constructor();
1550
1917
  /**
1551
- * Reset the analysis, clearing reference and all results.
1918
+ * Reset the analysis, clearing the trajectory buffer.
1552
1919
  */
1553
1920
  reset(): void;
1554
1921
  /**
1555
- * Return all accumulated MSD results as an array.
1922
+ * Run the stateless [`molrs_compute::MSD`] over every fed frame and
1923
+ * return the per-frame time series.
1556
1924
  *
1557
- * Returns one [`MSDResult`] per frame fed (including the
1558
- * reference frame, which has MSD = 0).
1925
+ * The first frame is always the reference, so `results()[0].mean ≈ 0`.
1559
1926
  *
1560
1927
  * # Example (JavaScript)
1561
1928
  *
@@ -1579,7 +1946,7 @@ export class MSD {
1579
1946
  * ```js
1580
1947
  * const result = msd.compute(frame);
1581
1948
  * console.log(result.mean); // number (A^2)
1582
- * console.log(result.perParticle()); // Float32Array (A^2)
1949
+ * console.log(result.perParticle()); // Float32Array or Float64Array (A^2)
1583
1950
  * ```
1584
1951
  */
1585
1952
  export class MSDResult {
@@ -1587,12 +1954,11 @@ export class MSDResult {
1587
1954
  free(): void;
1588
1955
  [Symbol.dispose](): void;
1589
1956
  /**
1590
- * Per-particle squared displacements as `Float32Array` in A^2.
1591
- *
1592
- * `perParticle()[i]` is `|r_i(t) - r_i(0)|^2` for particle `i`.
1593
- * Length equals the number of atoms.
1957
+ * Zero-copy `Float64Array` view of per-particle squared displacements
1958
+ * in A². `perParticle()[i]` is `|r_i(t) - r_i(0)|²` for particle `i`.
1959
+ * **Invalidated** on WASM memory growth; copy in JS if needed.
1594
1960
  */
1595
- perParticle(): Float32Array;
1961
+ perParticle(): Float64Array;
1596
1962
  /**
1597
1963
  * System-average mean squared displacement in A^2.
1598
1964
  *
@@ -1602,6 +1968,19 @@ export class MSDResult {
1602
1968
  readonly mean: number;
1603
1969
  }
1604
1970
 
1971
+ /**
1972
+ * Reader for MolRec Zarr v3 archives.
1973
+ */
1974
+ export class MolRecReader {
1975
+ free(): void;
1976
+ [Symbol.dispose](): void;
1977
+ countAtoms(): number;
1978
+ countFrames(): number;
1979
+ free(): void;
1980
+ constructor(files: Map<any, any>);
1981
+ readFrame(t: number): Frame | undefined;
1982
+ }
1983
+
1605
1984
  /**
1606
1985
  * Result of a neighbor search: all atom pairs within a distance cutoff.
1607
1986
  *
@@ -1626,7 +2005,7 @@ export class MSDResult {
1626
2005
  *
1627
2006
  * const i = nlist.queryPointIndices(); // Uint32Array
1628
2007
  * const j = nlist.pointIndices(); // Uint32Array
1629
- * const d = nlist.distances(); // Float32Array (in A)
2008
+ * const d = nlist.distances(); // Float32Array or Float64Array (in A)
1630
2009
  * ```
1631
2010
  */
1632
2011
  export class NeighborList {
@@ -1634,28 +2013,26 @@ export class NeighborList {
1634
2013
  free(): void;
1635
2014
  [Symbol.dispose](): void;
1636
2015
  /**
1637
- * Squared pairwise distances in A^2, as a `Float32Array`.
1638
- *
1639
- * More efficient than `distances()` when you only need to
1640
- * compare or threshold distances.
2016
+ * Zero-copy `Float64Array` view of squared pairwise distances in A^2.
2017
+ * Same invalidation caveat as [`queryPointIndices`](Self::query_point_indices).
1641
2018
  */
1642
- distSq(): Float32Array;
2019
+ distSq(): Float64Array;
1643
2020
  /**
1644
- * Pairwise distances in angstrom (A), as a `Float32Array`.
2021
+ * Pairwise distances in angstrom (A). Computed lazily from `distSq`.
1645
2022
  *
1646
- * `distances()[k]` is the distance between query point
1647
- * `queryPointIndices()[k]` and reference point `pointIndices()[k]`.
2023
+ * Returns an owned copy because distances are derived on the fly
2024
+ * (`sqrt` per pair) rather than stored.
1648
2025
  */
1649
- distances(): Float32Array;
2026
+ distances(): Float64Array;
1650
2027
  /**
1651
- * Reference point indices (`j`) for each pair, as a `Uint32Array`.
2028
+ * Zero-copy `Uint32Array` view of reference point indices (`j`).
2029
+ * Same invalidation caveat as [`queryPointIndices`](Self::query_point_indices).
1652
2030
  */
1653
2031
  pointIndices(): Uint32Array;
1654
2032
  /**
1655
- * Query point indices (`i`) for each pair, as a `Uint32Array`.
1656
- *
1657
- * The `k`-th pair connects query point `queryPointIndices()[k]`
1658
- * to reference point `pointIndices()[k]`.
2033
+ * Zero-copy `Uint32Array` view of query point indices (`i`) over
2034
+ * WASM memory. **Invalidated** on any WASM memory growth — copy
2035
+ * in JS (`new Uint32Array(view)`) if it needs to outlive later calls.
1659
2036
  */
1660
2037
  queryPointIndices(): Uint32Array;
1661
2038
  /**
@@ -1685,8 +2062,8 @@ export class NeighborList {
1685
2062
  *
1686
2063
  * PDB files contain a single molecular structure. The reader produces
1687
2064
  * a [`Frame`] with an `"atoms"` block containing columns such as
1688
- * `name` (string), `resname` (string), `x`, `y`, `z` (f32, angstrom),
1689
- * and optionally `occupancy` and `bfactor` (f32).
2065
+ * `name` (string), `resname` (string), `x`, `y`, `z` (F, angstrom),
2066
+ * and optionally `occupancy` and `bfactor` (F).
1690
2067
  *
1691
2068
  * # Example (JavaScript)
1692
2069
  *
@@ -1695,7 +2072,7 @@ export class NeighborList {
1695
2072
  * const frame = reader.read(0);
1696
2073
  * const atoms = frame.getBlock("atoms");
1697
2074
  * const names = atoms.copyColStr("name"); // ["CA", "CB", ...]
1698
- * const x = atoms.copyColF32("x");
2075
+ * const x = atoms.copyColF("x");
1699
2076
  * ```
1700
2077
  */
1701
2078
  export class PDBReader {
@@ -1761,15 +2138,16 @@ export class PDBReader {
1761
2138
  /**
1762
2139
  * Radial distribution function g(r) analysis.
1763
2140
  *
1764
- * Computes the pair correlation function by binning neighbor-pair
1765
- * distances into a histogram and normalizing by the ideal-gas
1766
- * density (spherical shell volume normalization).
2141
+ * Bins neighbor-pair distances in `[rMin, rMax]` and normalizes by the
2142
+ * ideal-gas pair density. Defaults follow freud (`rMin = 0`). Periodic
2143
+ * systems take their normalization volume from `frame.simbox`; non-periodic
2144
+ * systems must supply it explicitly via [`computeWithVolume`].
1767
2145
  *
1768
2146
  * # Algorithm
1769
2147
  *
1770
2148
  * g(r) = n(r) / (rho * V_shell(r) * N_ref)
1771
2149
  *
1772
- * where `n(r)` is the pair count in bin `r`, `rho` is the number
2150
+ * where `n(r)` is the pair count in bin `r`, `rho = N/V` is the number
1773
2151
  * density, and `V_shell(r)` is the shell volume for that bin.
1774
2152
  *
1775
2153
  * # Example (JavaScript)
@@ -1778,60 +2156,73 @@ export class PDBReader {
1778
2156
  * const lc = new LinkedCell(5.0);
1779
2157
  * const nlist = lc.build(frame);
1780
2158
  *
1781
- * const rdf = new RDF(100, 5.0);
2159
+ * const rdf = new RDF(100, 5.0); // rMin defaults to 0
1782
2160
  * const result = rdf.compute(frame, nlist);
1783
2161
  *
1784
- * const r = result.binCenters(); // Float32Array, bin centers in A
1785
- * const gr = result.rdf(); // Float32Array, g(r) values
2162
+ * // Non-periodic frame: supply the normalization volume.
2163
+ * const resultFree = rdf.computeWithVolume(nlist, volumeA3);
2164
+ *
2165
+ * const r = result.binCenters();
2166
+ * const gr = result.rdf();
1786
2167
  * ```
1787
2168
  */
1788
2169
  export class RDF {
1789
2170
  free(): void;
1790
2171
  [Symbol.dispose](): void;
1791
2172
  /**
1792
- * Compute the RDF from a pre-built neighbor list.
1793
- *
1794
- * The frame is needed to read the simulation box volume for
1795
- * normalization.
2173
+ * Compute g(r) using the simulation-box volume from `frame.simbox`.
1796
2174
  *
1797
2175
  * # Arguments
1798
2176
  *
1799
- * * `frame` - Frame with a `simbox` set (for volume normalization)
2177
+ * * `frame` - Frame with a `simbox` set (used only for volume)
1800
2178
  * * `neighbors` - Pre-built [`NeighborList`] from [`LinkedCell`]
1801
2179
  *
1802
- * # Returns
2180
+ * # Errors
2181
+ *
2182
+ * Throws if the frame has no `simbox` — use
2183
+ * [`computeWithVolume`](Self::compute_with_volume) for non-periodic frames.
2184
+ */
2185
+ compute(frame: Frame, neighbors: NeighborList): RDFResult;
2186
+ /**
2187
+ * Compute g(r) using an explicit normalization volume (A^3).
1803
2188
  *
1804
- * An [`RDFResult`] containing bin centers, g(r) values, and raw
1805
- * pair counts.
2189
+ * Use this for non-periodic systems or to override the box volume.
2190
+ * Internally wraps the supplied volume as a cubic SimBox since the
2191
+ * underlying [`molrs_compute::RDF`] pulls its normalization volume from
2192
+ * `frame.simbox`.
1806
2193
  *
1807
- * # Errors
2194
+ * # Arguments
1808
2195
  *
1809
- * Throws if the frame cannot be cloned or the computation fails.
2196
+ * * `neighbors` - Pre-built [`NeighborList`]
2197
+ * * `volume` - Normalization volume in A^3 (must be finite and > 0)
1810
2198
  *
1811
2199
  * # Example (JavaScript)
1812
2200
  *
1813
2201
  * ```js
1814
- * const result = rdf.compute(frame, nlist);
1815
- * const gr = result.rdf(); // Float32Array
2202
+ * const result = rdf.computeWithVolume(nlist, 1000.0);
1816
2203
  * ```
1817
2204
  */
1818
- compute(frame: Frame, neighbors: NeighborList): RDFResult;
2205
+ computeWithVolume(neighbors: NeighborList, volume: number): RDFResult;
1819
2206
  /**
1820
- * Create a new RDF analysis with specified binning.
2207
+ * Create a new RDF analysis.
1821
2208
  *
1822
2209
  * # Arguments
1823
2210
  *
1824
2211
  * * `n_bins` - Number of histogram bins
1825
- * * `r_max` - Maximum radial distance in angstrom (A). Should
1826
- * match or be less than the neighbor-search cutoff.
2212
+ * * `r_max` - Upper radial cutoff in angstrom (A). Should be ≤ the
2213
+ * neighbor-search cutoff.
2214
+ * * `r_min` - Lower radial cutoff in angstrom (A). Optional, defaults
2215
+ * to 0 (freud convention). Pairs with `d < rMin` or `d == 0` are
2216
+ * excluded from the histogram.
1827
2217
  *
1828
2218
  * # Example (JavaScript)
1829
2219
  *
1830
2220
  * ```js
1831
- * const rdf = new RDF(100, 5.0); // 100 bins up to 5 A
2221
+ * const rdf = new RDF(100, 5.0); // rMin = 0
2222
+ * const rdf2 = new RDF(100, 5.0, 0.5); // exclude d < 0.5 A
1832
2223
  * ```
1833
2224
  */
1834
- constructor(n_bins: number, r_max: number);
2225
+ constructor(n_bins: number, r_max: number, r_min?: number | null);
1835
2226
  }
1836
2227
 
1837
2228
  /**
@@ -1844,9 +2235,9 @@ export class RDF {
1844
2235
  *
1845
2236
  * ```js
1846
2237
  * const result = rdf.compute(frame, nlist);
1847
- * const r = result.binCenters(); // Float32Array [0.025, 0.075, ...]
1848
- * const gr = result.rdf(); // Float32Array, normalized g(r)
1849
- * const nr = result.pairCounts(); // Float32Array, raw counts
2238
+ * const r = result.binCenters(); // Float32Array or Float64Array [0.025, 0.075, ...]
2239
+ * const gr = result.rdf(); // Float32Array or Float64Array, normalized g(r)
2240
+ * const nr = result.pairCounts(); // Float32Array or Float64Array, raw counts
1850
2241
  * console.log("Volume:", result.volume, "A^3");
1851
2242
  * console.log("N_ref:", result.numPoints);
1852
2243
  * ```
@@ -1856,34 +2247,36 @@ export class RDFResult {
1856
2247
  free(): void;
1857
2248
  [Symbol.dispose](): void;
1858
2249
  /**
1859
- * Bin center positions as `Float32Array` in angstrom (A).
1860
- *
1861
- * Length equals `n_bins` (the value passed to the `RDF` constructor).
2250
+ * Zero-copy `Float64Array` view of bin center positions in A.
2251
+ * Length equals `n_bins`. **Invalidated** on WASM memory growth;
2252
+ * copy in JS if it needs to outlive later calls.
1862
2253
  */
1863
- binCenters(): Float32Array;
2254
+ binCenters(): Float64Array;
1864
2255
  /**
1865
- * Bin edge positions as `Float32Array` in angstrom (A).
1866
- *
1867
- * Length is `n_bins + 1` (one more than bin centers).
2256
+ * Zero-copy `Float64Array` view of bin edge positions in A.
2257
+ * Length is `n_bins + 1`. Same invalidation caveat.
1868
2258
  */
1869
- binEdges(): Float32Array;
2259
+ binEdges(): Float64Array;
1870
2260
  /**
1871
- * Raw (un-normalized) pair counts per bin as `Float32Array`.
2261
+ * Zero-copy `Float64Array` view of raw (un-normalized) pair counts
2262
+ * per bin. Same invalidation caveat.
1872
2263
  */
1873
- pairCounts(): Float32Array;
2264
+ pairCounts(): Float64Array;
1874
2265
  /**
1875
- * Normalized g(r) values as `Float32Array` (dimensionless).
1876
- *
1877
- * A uniform ideal gas has g(r) = 1.0 everywhere. Peaks indicate
1878
- * preferred interatomic distances (coordination shells).
2266
+ * Zero-copy `Float64Array` view of normalized g(r). Same invalidation
2267
+ * caveat.
1879
2268
  */
1880
- rdf(): Float32Array;
2269
+ rdf(): Float64Array;
1881
2270
  /**
1882
2271
  * Number of reference points used in the normalization.
1883
2272
  */
1884
2273
  readonly numPoints: number;
1885
2274
  /**
1886
- * Simulation box volume used in the normalization, in A^3.
2275
+ * Inner cutoff in A (lower edge of bin 0).
2276
+ */
2277
+ readonly rMin: number;
2278
+ /**
2279
+ * Normalization volume in A^3 (from the SimBox or the explicit caller value).
1887
2280
  */
1888
2281
  readonly volume: number;
1889
2282
  }
@@ -1895,119 +2288,61 @@ export class RadiusOfGyration {
1895
2288
  free(): void;
1896
2289
  [Symbol.dispose](): void;
1897
2290
  /**
1898
- * Compute radii of gyration. Returns `Float32Array` of length `numClusters`.
2291
+ * Compute radii of gyration. Returns a float typed array of length `numClusters`.
2292
+ *
2293
+ * Internally computes the cluster centers of mass so the single-frame
2294
+ * wasm signature `(frame, cluster)` stays stable despite the new
2295
+ * compute trait needing explicit COM upstream.
1899
2296
  */
1900
- compute(frame: Frame, cluster_result: ClusterResult): Float32Array;
1901
- constructor(masses?: Float32Array | null);
2297
+ compute(frame: Frame, cluster_result: ClusterResult): Float64Array;
2298
+ constructor(masses?: Float64Array | null);
1902
2299
  }
1903
2300
 
1904
2301
  /**
1905
- * Reader for Zarr V3 simulation archives.
2302
+ * MDL molfile / SDF (V2000 CTAB) reader.
2303
+ *
2304
+ * Parses the connection table found in `.mol` files and the record
2305
+ * blocks of `.sdf` files. Coordinates come directly from the file —
2306
+ * no 3D generation is performed. Only V2000 is supported; V3000
2307
+ * records throw on read.
1906
2308
  *
1907
- * Wraps [`SimulationStore`] from `molrs-core` for reading trajectory
1908
- * frames and system metadata from an in-memory Zarr store. The store
1909
- * is populated from a `Map<string, Uint8Array>` of file paths to
1910
- * binary content.
2309
+ * Produces a [`Frame`] with:
2310
+ * - `"atoms"` block: `element` (string), `id` (u32, 1-based),
2311
+ * `x`, `y`, `z` (F, angstrom)
2312
+ * - `"bonds"` block (if present): `atomi`, `atomj` (u32, 0-based),
2313
+ * `order` (u32)
2314
+ *
2315
+ * Multi-record SDF files expose each record as a separate frame via
2316
+ * `read(step)`.
1911
2317
  *
1912
2318
  * # Example (JavaScript)
1913
2319
  *
1914
2320
  * ```js
1915
- * const files = new Map();
1916
- * files.set("zarr.json", new Uint8Array([...]));
1917
- * files.set("system/.zarray", new Uint8Array([...]));
1918
- * // ... etc.
1919
- *
1920
- * const reader = new SimulationReader(files);
1921
- * const frame = reader.readFrame(0);
2321
+ * const reader = new SDFReader(sdfContent);
2322
+ * const frame = reader.read(0);
2323
+ * const atoms = frame.getBlock("atoms");
2324
+ * const x = atoms.copyColF("x");
1922
2325
  * ```
1923
2326
  */
1924
- export class SimulationReader {
2327
+ export class SDFReader {
1925
2328
  free(): void;
1926
2329
  [Symbol.dispose](): void;
1927
2330
  /**
1928
- * Return the number of atoms in the system topology.
1929
- *
1930
- * # Example (JavaScript)
1931
- *
1932
- * ```js
1933
- * console.log(reader.countAtoms()); // e.g., 256
1934
- * ```
2331
+ * Check whether the file contains no records.
1935
2332
  */
1936
- countAtoms(): number;
2333
+ isEmpty(): boolean;
1937
2334
  /**
1938
- * Return the number of trajectory frames in the archive.
1939
- *
1940
- * Returns `0` if no trajectory data is present.
1941
- *
1942
- * # Errors
1943
- *
1944
- * Throws a `JsValue` string on I/O errors.
1945
- *
1946
- * # Example (JavaScript)
1947
- *
1948
- * ```js
1949
- * console.log(reader.countFrames()); // e.g., 1000
1950
- * ```
2335
+ * Return the total number of records in the SDF file.
1951
2336
  */
1952
- countFrames(): number;
2337
+ len(): number;
1953
2338
  /**
1954
- * Create a reader from a map of file paths to binary content.
1955
- *
1956
- * The map keys are relative paths within the Zarr archive
1957
- * (e.g., `"zarr.json"`, `"system/.zarray"`). Values are the
1958
- * raw bytes of each file as `Uint8Array`.
1959
- *
1960
- * # Arguments
1961
- *
1962
- * * `files` - `Map<string, Uint8Array>` mapping archive paths
1963
- * to their binary content
1964
- *
1965
- * # Returns
1966
- *
1967
- * A new `SimulationReader` ready to read frames.
1968
- *
1969
- * # Errors
1970
- *
1971
- * Throws a `JsValue` string if the archive cannot be opened
1972
- * (e.g., missing required metadata files).
1973
- *
1974
- * # Example (JavaScript)
1975
- *
1976
- * ```js
1977
- * const reader = new SimulationReader(filesMap);
1978
- * ```
2339
+ * Create a new SDF reader from a string containing the file content.
1979
2340
  */
1980
- constructor(files: Map<any, any>);
2341
+ constructor(content: string);
1981
2342
  /**
1982
- * Read a trajectory frame at the given time index.
1983
- *
1984
- * The returned [`Frame`] merges the static system topology
1985
- * (atoms, bonds) with the per-frame trajectory data (positions,
1986
- * velocities, etc.) at time step `t`.
1987
- *
1988
- * # Arguments
1989
- *
1990
- * * `t` - Zero-based time step index
1991
- *
1992
- * # Returns
1993
- *
1994
- * A [`Frame`] with merged system + trajectory data, or `undefined`
1995
- * if no trajectory is present.
1996
- *
1997
- * # Errors
1998
- *
1999
- * Throws a `JsValue` string on I/O or deserialization errors.
2000
- *
2001
- * # Example (JavaScript)
2002
- *
2003
- * ```js
2004
- * const frame = reader.readFrame(0);
2005
- * if (frame) {
2006
- * const x = frame.getBlock("atoms").copyColF32("x");
2007
- * }
2008
- * ```
2343
+ * Read the frame (SDF record) at the given step index.
2009
2344
  */
2010
- readFrame(t: number): Frame | undefined;
2345
+ read(step: number): Frame | undefined;
2011
2346
  }
2012
2347
 
2013
2348
  /**
@@ -2028,7 +2363,7 @@ export class SimulationReader {
2028
2363
  *
2029
2364
  * const frame = ir.toFrame();
2030
2365
  * const atoms = frame.getBlock("atoms");
2031
- * console.log(atoms.copyColStr("symbol")); // ["C", "C", "O", "H", ...]
2366
+ * console.log(atoms.copyColStr("element")); // ["C", "C", "O", "H", ...]
2032
2367
  * ```
2033
2368
  */
2034
2369
  export class SmilesIR {
@@ -2044,7 +2379,7 @@ export class SmilesIR {
2044
2379
  * are added. No 3D coordinates are present -- use
2045
2380
  * [`generate3D`](crate::generate_3d_wasm) to embed coordinates.
2046
2381
  * - `"bonds"` block: `i`, `j` (u32, zero-based atom indices),
2047
- * `order` (f32, bond order: 1.0 = single, 1.5 = aromatic,
2382
+ * `order` (F, bond order: 1.0 = single, 1.5 = aromatic,
2048
2383
  * 2.0 = double, 3.0 = triple).
2049
2384
  *
2050
2385
  * # Returns
@@ -2061,7 +2396,7 @@ export class SmilesIR {
2061
2396
  * ```js
2062
2397
  * const frame = ir.toFrame();
2063
2398
  * const bonds = frame.getBlock("bonds");
2064
- * const order = bonds.copyColF32("order");
2399
+ * const order = bonds.copyColF("order");
2065
2400
  * ```
2066
2401
  */
2067
2402
  toFrame(): Frame;
@@ -2239,26 +2574,26 @@ export class TopologyRingInfo {
2239
2574
  }
2240
2575
 
2241
2576
  /**
2242
- * Owned f32 array with ndarray-compatible shape metadata.
2577
+ * Owned float array with ndarray-compatible shape metadata.
2243
2578
  *
2244
- * Stores a flat `Vec<f32>` together with a shape descriptor (e.g.,
2579
+ * Stores a flat `Vec<F>` together with a shape descriptor (e.g.,
2245
2580
  * `[N, 3]` for an Nx3 coordinate matrix). Used for passing
2246
2581
  * multi-dimensional numeric data across the WASM boundary.
2247
2582
  *
2248
2583
  * # Memory layout
2249
2584
  *
2250
2585
  * Data is stored in row-major (C) order, matching ndarray's default
2251
- * and JavaScript's `Float32Array` convention.
2586
+ * and JavaScript's float typed-array convention.
2252
2587
  *
2253
2588
  * # Example (JavaScript)
2254
2589
  *
2255
2590
  * ```js
2256
2591
  * // Create a 2x3 zero array
2257
2592
  * const arr = new WasmArray([2, 3]);
2258
- * arr.writeFrom(new Float32Array([1,2,3, 4,5,6]));
2593
+ * arr.writeFrom(floatArray);
2259
2594
  *
2260
2595
  * // Or from existing data
2261
- * const arr2 = WasmArray.from(new Float32Array([1,2,3]), [1, 3]);
2596
+ * const arr2 = WasmArray.from(floatArray, [1, 3]);
2262
2597
  *
2263
2598
  * // Get data back
2264
2599
  * const copy = arr.toCopy(); // safe owned copy
@@ -2269,15 +2604,15 @@ export class WasmArray {
2269
2604
  free(): void;
2270
2605
  [Symbol.dispose](): void;
2271
2606
  /**
2272
- * Return the data type string. Always `"float"` for `WasmArray`.
2607
+ * Return the concrete float dtype string for this build.
2273
2608
  */
2274
2609
  dtype(): string;
2275
2610
  /**
2276
- * Create a `WasmArray` from an existing JS `Float32Array`.
2611
+ * Create a `WasmArray` from an existing JS float typed array.
2277
2612
  *
2278
2613
  * # Arguments
2279
2614
  *
2280
- * * `data` - Source `Float32Array`
2615
+ * * `data` - Source float typed array (`Float32Array` or `Float64Array`)
2281
2616
  * * `shape` - Optional shape. If omitted, defaults to `[data.length]` (1D).
2282
2617
  *
2283
2618
  * # Returns
@@ -2291,11 +2626,11 @@ export class WasmArray {
2291
2626
  * # Example (JavaScript)
2292
2627
  *
2293
2628
  * ```js
2294
- * const arr = WasmArray.from(new Float32Array([1,2,3,4,5,6]), [2, 3]);
2629
+ * const arr = WasmArray.from(floatArray, [2, 3]);
2295
2630
  * console.log(arr.shape()); // [2, 3]
2296
2631
  * ```
2297
2632
  */
2298
- static from(data: Float32Array, shape?: Uint32Array | null): WasmArray;
2633
+ static from(data: Float64Array, shape?: Uint32Array | null): WasmArray;
2299
2634
  /**
2300
2635
  * Check whether the array contains no elements.
2301
2636
  */
@@ -2355,13 +2690,13 @@ export class WasmArray {
2355
2690
  * # Example (JavaScript)
2356
2691
  *
2357
2692
  * ```js
2358
- * const arr = WasmArray.from(new Float32Array([1, 2, 3]));
2693
+ * const arr = WasmArray.from(floatArray);
2359
2694
  * console.log(arr.sum()); // 6.0
2360
2695
  * ```
2361
2696
  */
2362
2697
  sum(): number;
2363
2698
  /**
2364
- * Create an owned JS `Float32Array` copy of the data.
2699
+ * Create an owned JS float typed-array copy of the data.
2365
2700
  *
2366
2701
  * The returned array is an independent copy that is safe to store
2367
2702
  * and use regardless of subsequent WASM memory operations.
@@ -2372,9 +2707,9 @@ export class WasmArray {
2372
2707
  * const copy = arr.toCopy(); // safe to keep indefinitely
2373
2708
  * ```
2374
2709
  */
2375
- toCopy(): Float32Array;
2710
+ toCopy(): Float64Array;
2376
2711
  /**
2377
- * Zero-copy `Float32Array` view over this array's backing storage.
2712
+ * Zero-copy float typed-array view over this array's backing storage.
2378
2713
  *
2379
2714
  * **Warning**: The returned view becomes **invalid** if WASM linear
2380
2715
  * memory grows (due to any allocation). Use [`toCopy`](WasmArray::to_copy)
@@ -2382,7 +2717,8 @@ export class WasmArray {
2382
2717
  *
2383
2718
  * # Safety (internal)
2384
2719
  *
2385
- * Uses `Float32Array::view` which creates an unowned view into
2720
+ * Uses the corresponding JS float typed-array `view` constructor,
2721
+ * which creates an unowned view into
2386
2722
  * WASM memory. The view must not outlive the `WasmArray` and must
2387
2723
  * not be used after any allocation that could trigger memory growth.
2388
2724
  *
@@ -2393,16 +2729,16 @@ export class WasmArray {
2393
2729
  * // Do NOT allocate between view creation and use
2394
2730
  * ```
2395
2731
  */
2396
- toTypedArray(): Float32Array;
2732
+ toTypedArray(): Float64Array;
2397
2733
  /**
2398
- * Overwrite the array contents from a JS `Float32Array`.
2734
+ * Overwrite the array contents from a JS float typed array.
2399
2735
  *
2400
2736
  * The source array must have exactly the same number of elements
2401
2737
  * as this `WasmArray` (i.e., the shape is preserved).
2402
2738
  *
2403
2739
  * # Arguments
2404
2740
  *
2405
- * * `arr` - Source `Float32Array` with matching length
2741
+ * * `arr` - Source float typed array with matching length
2406
2742
  *
2407
2743
  * # Errors
2408
2744
  *
@@ -2412,10 +2748,118 @@ export class WasmArray {
2412
2748
  *
2413
2749
  * ```js
2414
2750
  * const wa = new WasmArray([3]);
2415
- * wa.writeFrom(new Float32Array([1.0, 2.0, 3.0]));
2751
+ * wa.writeFrom(floatArray);
2416
2752
  * ```
2417
2753
  */
2418
- write_from(arr: Float32Array): void;
2754
+ write_from(arr: Float64Array): void;
2755
+ }
2756
+
2757
+ /**
2758
+ * Wrapper for [`molrs_compute::kmeans::KMeans`].
2759
+ *
2760
+ * # Example (JavaScript)
2761
+ *
2762
+ * ```js
2763
+ * const km = new WasmKMeans(3, 100, 42);
2764
+ * const labels = km.fit(coords, nRows, 2); // Int32Array
2765
+ * ```
2766
+ */
2767
+ export class WasmKMeans {
2768
+ free(): void;
2769
+ [Symbol.dispose](): void;
2770
+ /**
2771
+ * Cluster a row-major `n_rows × n_dims` coordinate matrix.
2772
+ *
2773
+ * # Returns
2774
+ *
2775
+ * Cluster labels in `0..k` as an owned `Int32Array`, one per row.
2776
+ *
2777
+ * # Errors
2778
+ *
2779
+ * Throws if `k > n_rows`, `n_dims == 0`, the length does not match
2780
+ * `n_rows * n_dims`, or any element is non-finite.
2781
+ */
2782
+ fit(coords: Float64Array, n_rows: number, n_dims: number): Int32Array;
2783
+ /**
2784
+ * Create a new k-means configuration.
2785
+ *
2786
+ * # Arguments
2787
+ *
2788
+ * * `k` — number of clusters (>= 1).
2789
+ * * `max_iter` — maximum Lloyd iterations (>= 1).
2790
+ * * `seed` — RNG seed for k-means++ initialization. Cast to `u64`
2791
+ * internally (JS numbers are `f64`; integers up to 2^53 pass
2792
+ * through losslessly).
2793
+ *
2794
+ * # Errors
2795
+ *
2796
+ * Throws if `k == 0` or `max_iter == 0`.
2797
+ */
2798
+ constructor(k: number, max_iter: number, seed: number);
2799
+ }
2800
+
2801
+ /**
2802
+ * Stateless wrapper for [`molrs_compute::pca::Pca2`].
2803
+ *
2804
+ * All configuration lives on [`fitTransform`](Self::fit_transform).
2805
+ *
2806
+ * # Example (JavaScript)
2807
+ *
2808
+ * ```js
2809
+ * const pca = new WasmPca2();
2810
+ * const result = pca.fitTransform(matrix, nRows, nCols);
2811
+ * const coords = result.coords(); // Float64Array, length 2 * nRows
2812
+ * const variance = result.variance(); // Float64Array, length 2
2813
+ * ```
2814
+ */
2815
+ export class WasmPca2 {
2816
+ free(): void;
2817
+ [Symbol.dispose](): void;
2818
+ /**
2819
+ * Fit 2-component PCA on a row-major observation matrix and return the
2820
+ * projected coordinates + per-component variance.
2821
+ *
2822
+ * # Arguments
2823
+ *
2824
+ * * `matrix` — row-major `n_rows × n_cols` observation matrix.
2825
+ * * `n_rows` — number of observations.
2826
+ * * `n_cols` — number of features.
2827
+ *
2828
+ * # Errors
2829
+ *
2830
+ * Throws if `n_rows < 3`, `n_cols < 2`, the length does not match
2831
+ * `n_rows * n_cols`, any element is non-finite, or any column has
2832
+ * zero variance.
2833
+ */
2834
+ fitTransform(matrix: Float64Array, n_rows: number, n_cols: number): WasmPcaResult;
2835
+ /**
2836
+ * Create a new PCA calculator. The struct carries no state — all
2837
+ * parameters are supplied on [`fitTransform`](Self::fit_transform).
2838
+ */
2839
+ constructor();
2840
+ }
2841
+
2842
+ /**
2843
+ * Result of a [`WasmPca2::fit_transform`] call.
2844
+ *
2845
+ * Each accessor returns an **owned** `Float64Array` (copy of the underlying
2846
+ * `Vec`) so JS is free to let this wrapper be GC'd without dangling views.
2847
+ */
2848
+ export class WasmPcaResult {
2849
+ private constructor();
2850
+ free(): void;
2851
+ [Symbol.dispose](): void;
2852
+ /**
2853
+ * Projected 2D coordinates as a row-major `Float64Array` of length
2854
+ * `2 * n_rows`. `coords[2 * i + 0]` is the PC1 score for row `i`,
2855
+ * `coords[2 * i + 1]` is PC2.
2856
+ */
2857
+ coords(): Float64Array;
2858
+ /**
2859
+ * Explained variance per component as `Float64Array` of length 2.
2860
+ * `variance[0] >= variance[1]` by construction.
2861
+ */
2862
+ variance(): Float64Array;
2419
2863
  }
2420
2864
 
2421
2865
  /**
@@ -2423,7 +2867,7 @@ export class WasmArray {
2423
2867
  *
2424
2868
  * Supports multi-frame trajectory files. Each frame produces a
2425
2869
  * [`Frame`] with an `"atoms"` block containing `element` (string)
2426
- * and `x`, `y`, `z` (f32, coordinates in angstrom) columns.
2870
+ * and `x`, `y`, `z` (F, coordinates in angstrom) columns.
2427
2871
  *
2428
2872
  * # Example (JavaScript)
2429
2873
  *
@@ -2434,7 +2878,7 @@ export class WasmArray {
2434
2878
  *
2435
2879
  * const frame = reader.read(0); // first frame
2436
2880
  * const atoms = frame.getBlock("atoms");
2437
- * const x = atoms.copyColF32("x");
2881
+ * const x = atoms.copyColF("x");
2438
2882
  * ```
2439
2883
  */
2440
2884
  export class XYZReader {
@@ -2511,13 +2955,13 @@ export class XYZReader {
2511
2955
  /**
2512
2956
  * Generate 3D coordinates for a molecular [`Frame`].
2513
2957
  *
2514
- * The input frame must have an `"atoms"` block with a `"symbol"`
2958
+ * The input frame must have an `"atoms"` block with a `"element"`
2515
2959
  * string column (element symbols like `"C"`, `"N"`, `"O"`). A
2516
- * `"bonds"` block with `i`, `j` (u32) and `order` (f32) columns
2960
+ * `"bonds"` block with `i`, `j` (u32) and `order` (F) columns
2517
2961
  * is required for correct geometry.
2518
2962
  *
2519
2963
  * Returns a **new** [`Frame`] with 3D coordinates added as `x`, `y`,
2520
- * `z` (f32, angstrom) columns in the `"atoms"` block.
2964
+ * `z` (F, angstrom) columns in the `"atoms"` block.
2521
2965
  *
2522
2966
  * # Arguments
2523
2967
  *
@@ -2550,9 +2994,9 @@ export class XYZReader {
2550
2994
  * const frame3d = generate3D(frame2d, "fast", 42);
2551
2995
  *
2552
2996
  * const atoms = frame3d.getBlock("atoms");
2553
- * const x = atoms.copyColF32("x"); // Float32Array with 3D x-coords
2554
- * const y = atoms.copyColF32("y");
2555
- * const z = atoms.copyColF32("z");
2997
+ * const x = atoms.copyColF("x"); // Float32Array or Float64Array with 3D x-coords
2998
+ * const y = atoms.copyColF("y");
2999
+ * const z = atoms.copyColF("z");
2556
3000
  * ```
2557
3001
  */
2558
3002
  export function generate3D(frame: Frame, speed?: string | null, seed?: number | null): Frame;
@@ -2604,7 +3048,7 @@ export function start(): void;
2604
3048
  *
2605
3049
  * ```js
2606
3050
  * const mem = wasmMemory();
2607
- * const buf = new Float32Array(mem.buffer, ptr, len);
3051
+ * const buf = new Float64Array(mem.buffer, ptr, len); // or Float32Array in default builds
2608
3052
  * ```
2609
3053
  */
2610
3054
  export function wasmMemory(): WebAssembly.Memory;