@molcrafts/molrs 0.0.1 → 0.0.5

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
@@ -2,554 +2,2346 @@
2
2
  /* eslint-disable */
3
3
 
4
4
  /**
5
- * A block containing columnar data.
5
+ * Column-oriented data store with typed arrays.
6
+ *
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
9
+ * the same number of rows.
10
+ *
11
+ * # Supported column types
12
+ *
13
+ * | JS type | Rust type | dtype string | Setter | Getter (copy) | Getter (view) |
14
+ * |---------|-----------|-------------|--------|---------------|---------------|
15
+ * | `Float32Array` | `f32` | `"f32"` | `setColF32` | `copyColF32` | `viewColF32` |
16
+ * | `Int32Array` | `i32` | `"i32"` | `setColI32` | `copyColI32` | `viewColI32` |
17
+ * | `Uint32Array` | `u32` | `"u32"` | `setColU32` | `copyColU32` | `viewColU32` |
18
+ * | `string[]` | `String` | `"string"` | `setColStr` | `copyColStr` | -- |
19
+ *
20
+ * # Example (JavaScript)
21
+ *
22
+ * ```js
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]));
26
+ * console.log(block.nrows()); // 3
27
+ * console.log(block.keys()); // ["x", "y"]
28
+ *
29
+ * const x = block.copyColF32("x"); // owned copy, safe to keep
30
+ * ```
6
31
  */
7
32
  export class Block {
8
33
  free(): void;
9
34
  [Symbol.dispose](): void;
10
35
  /**
11
- * Gets an f32 column as Float32Array.
36
+ * Owned `Float32Array` copy of a column.
37
+ *
38
+ * Returns a new JS `Float32Array` that is an independent copy of
39
+ * the column data. Safe to store and use across allocations.
40
+ *
41
+ * # Arguments
42
+ *
43
+ * * `key` - Column name
44
+ *
45
+ * # Returns
46
+ *
47
+ * An owned `Float32Array` copy of the column.
48
+ *
49
+ * # Errors
50
+ *
51
+ * Throws if the column does not exist or is not of type `f32`.
52
+ *
53
+ * # Example (JavaScript)
54
+ *
55
+ * ```js
56
+ * const x = block.copyColF32("x");
57
+ * console.log(x[0]); // 1.0
58
+ * ```
12
59
  */
13
- getColumnF32(key: string): Float32Array;
60
+ copyColF32(key: string): Float32Array;
14
61
  /**
15
- * Gets an f32 column with shape (for compatibility).
62
+ * Owned `Int32Array` copy of a column.
63
+ *
64
+ * # Arguments
65
+ *
66
+ * * `key` - Column name
67
+ *
68
+ * # Errors
69
+ *
70
+ * Throws if the column does not exist or is not of type `i32`.
71
+ *
72
+ * # Example (JavaScript)
73
+ *
74
+ * ```js
75
+ * const types = block.copyColI32("type_id");
76
+ * ```
16
77
  */
17
- getColumnF32WithShape(key: string): any;
78
+ copyColI32(key: string): Int32Array;
18
79
  /**
19
- * Gets an i64 column.
80
+ * Owned `string[]` copy of a string column.
81
+ *
82
+ * # Arguments
83
+ *
84
+ * * `key` - Column name
85
+ *
86
+ * # Returns
87
+ *
88
+ * A JS `Array` of strings.
89
+ *
90
+ * # Errors
91
+ *
92
+ * Throws if the column does not exist or is not of type `string`.
93
+ *
94
+ * # Example (JavaScript)
95
+ *
96
+ * ```js
97
+ * const symbols = block.copyColStr("symbol"); // ["C", "C", "O"]
98
+ * ```
20
99
  */
21
- getColumnI64(key: string): BigInt64Array;
100
+ copyColStr(key: string): Array<any>;
22
101
  /**
23
- * Gets a string column.
102
+ * Owned `Uint32Array` copy of a column.
103
+ *
104
+ * # Arguments
105
+ *
106
+ * * `key` - Column name
107
+ *
108
+ * # Errors
109
+ *
110
+ * Throws if the column does not exist or is not of type `u32`.
111
+ *
112
+ * # Example (JavaScript)
113
+ *
114
+ * ```js
115
+ * const bondI = block.copyColU32("i");
116
+ * const bondJ = block.copyColU32("j");
117
+ * ```
24
118
  */
25
- getColumnStrings(key: string): Array<any> | undefined;
119
+ copyColU32(key: string): Uint32Array;
26
120
  /**
27
- * Gets a u32 column.
121
+ * Return the data type string for a column.
122
+ *
123
+ * Possible return values: `"f32"`, `"i32"`, `"u32"`, `"bool"`,
124
+ * `"string"`, `"u8"`. Returns `undefined` if the column does
125
+ * not exist.
126
+ *
127
+ * # Arguments
128
+ *
129
+ * * `key` - Column name
130
+ *
131
+ * # Returns
132
+ *
133
+ * The dtype string, or `undefined` if the column is not found.
134
+ *
135
+ * # Example (JavaScript)
136
+ *
137
+ * ```js
138
+ * console.log(block.dtype("x")); // "f32"
139
+ * console.log(block.dtype("symbol")); // "string"
140
+ * ```
28
141
  */
29
- getColumnU32(key: string): Uint32Array;
142
+ dtype(key: string): string | undefined;
30
143
  /**
31
- * Gets a u8 column.
144
+ * Check whether this block has zero columns.
145
+ *
146
+ * # Errors
147
+ *
148
+ * Throws if the block handle has been invalidated.
149
+ *
150
+ * # Example (JavaScript)
151
+ *
152
+ * ```js
153
+ * if (block.isEmpty()) { // no columns yet }
154
+ * ```
32
155
  */
33
- getColumnU8(key: string): Uint8Array | undefined;
156
+ isEmpty(): boolean;
34
157
  /**
35
- * Gets column keys.
158
+ * Return all column names as a JS `string[]`.
159
+ *
160
+ * # Errors
161
+ *
162
+ * Throws if the block handle has been invalidated.
163
+ *
164
+ * # Example (JavaScript)
165
+ *
166
+ * ```js
167
+ * const names = block.keys(); // ["x", "y", "z", "symbol"]
168
+ * ```
36
169
  */
37
170
  keys(): Array<any>;
38
171
  /**
39
- * Gets the number of columns.
172
+ * Return the number of columns in this block.
173
+ *
174
+ * # Errors
175
+ *
176
+ * Throws if the block handle has been invalidated.
177
+ *
178
+ * # Example (JavaScript)
179
+ *
180
+ * ```js
181
+ * console.log(block.len()); // e.g., 3
182
+ * ```
40
183
  */
41
184
  len(): number;
42
185
  /**
43
- * Creates a new empty Block.
186
+ * Create a new, standalone empty `Block`.
187
+ *
188
+ * The block is backed by its own temporary store. Prefer
189
+ * [`Frame.createBlock()`](crate::Frame::create_block) to create
190
+ * blocks that are immediately attached to a frame.
191
+ *
192
+ * # Errors
193
+ *
194
+ * Throws a `JsValue` string if the internal store allocation fails.
195
+ *
196
+ * # Example (JavaScript)
197
+ *
198
+ * ```js
199
+ * const block = new Block();
200
+ * block.setColF32("values", new Float32Array([1, 2, 3]));
201
+ * ```
44
202
  */
45
203
  constructor();
46
204
  /**
47
- * Gets the number of rows.
205
+ * Return the number of rows (shared across all columns).
206
+ *
207
+ * Returns `0` if the block has no columns.
208
+ *
209
+ * # Errors
210
+ *
211
+ * Throws if the block handle has been invalidated.
212
+ *
213
+ * # Example (JavaScript)
214
+ *
215
+ * ```js
216
+ * console.log(block.nrows()); // e.g., 100
217
+ * ```
48
218
  */
49
219
  nrows(): number;
50
220
  /**
51
- * Renames a column.
221
+ * Rename a column from `old_key` to `new_key`.
222
+ *
223
+ * # Arguments
224
+ *
225
+ * * `old_key` - Current column name
226
+ * * `new_key` - New column name
227
+ *
228
+ * # Returns
229
+ *
230
+ * `true` if the column was found and renamed, `false` otherwise.
231
+ *
232
+ * # Errors
233
+ *
234
+ * Throws if the block handle has been invalidated.
235
+ *
236
+ * # Example (JavaScript)
237
+ *
238
+ * ```js
239
+ * block.renameColumn("element", "symbol"); // true
240
+ * ```
52
241
  */
53
242
  renameColumn(old_key: string, new_key: string): boolean;
54
243
  /**
55
- * Sets an f32 column.
244
+ * Set a float column from a `Float32Array`.
245
+ *
246
+ * # Arguments
247
+ *
248
+ * * `key` - Column name (e.g., `"x"`, `"mass"`, `"charge"`)
249
+ * * `data` - `Float32Array` with the column values
250
+ * * `shape` - Optional shape array for multi-dimensional data
251
+ * (e.g., `[N, 3]` for an Nx3 matrix stored flat). If omitted,
252
+ * the data is stored as a 1D column.
253
+ *
254
+ * # Errors
255
+ *
256
+ * Throws if `shape` product does not match `data.length`, or if
257
+ * the resulting row count is inconsistent with existing columns.
258
+ *
259
+ * # Example (JavaScript)
260
+ *
261
+ * ```js
262
+ * block.setColF32("x", new Float32Array([1.0, 2.0, 3.0]));
263
+ * // Multi-dimensional: 2 rows x 3 columns
264
+ * block.setColF32("pos", new Float32Array([1,2,3, 4,5,6]), [2, 3]);
265
+ * ```
266
+ */
267
+ setColF32(key: string, data: Float32Array, shape?: Uint32Array | null): void;
268
+ /**
269
+ * Set a signed integer column from an `Int32Array`.
270
+ *
271
+ * # Arguments
272
+ *
273
+ * * `key` - Column name
274
+ * * `data` - `Int32Array` with the column values
275
+ *
276
+ * # Errors
277
+ *
278
+ * Throws if the row count is inconsistent with existing columns.
279
+ *
280
+ * # Example (JavaScript)
281
+ *
282
+ * ```js
283
+ * block.setColI32("charge_sign", new Int32Array([1, -1, 0]));
284
+ * ```
285
+ */
286
+ setColI32(key: string, data: Int32Array): void;
287
+ /**
288
+ * Set a string column from a JS `string[]`.
289
+ *
290
+ * # Arguments
291
+ *
292
+ * * `key` - Column name (e.g., `"symbol"`, `"name"`)
293
+ * * `data` - JS `Array` where every element must be a string
294
+ *
295
+ * # Errors
296
+ *
297
+ * Throws if any element is not a string, or if the row count is
298
+ * inconsistent with existing columns.
299
+ *
300
+ * # Example (JavaScript)
301
+ *
302
+ * ```js
303
+ * atoms.setColStr("symbol", ["C", "C", "O"]);
304
+ * ```
56
305
  */
57
- setColumnF32(key: string, data: Float32Array, shape?: Uint32Array | null): void;
306
+ setColStr(key: string, data: Array<any>): void;
58
307
  /**
59
- * Sets an i64 column.
308
+ * Set an unsigned integer column from a `Uint32Array`.
309
+ *
310
+ * # Arguments
311
+ *
312
+ * * `key` - Column name (e.g., `"i"`, `"j"` for bond indices)
313
+ * * `data` - `Uint32Array` with the column values
314
+ *
315
+ * # Errors
316
+ *
317
+ * Throws if the row count is inconsistent with existing columns.
318
+ *
319
+ * # Example (JavaScript)
320
+ *
321
+ * ```js
322
+ * // Bond topology: atom indices
323
+ * bonds.setColU32("i", new Uint32Array([0, 1]));
324
+ * bonds.setColU32("j", new Uint32Array([1, 2]));
325
+ * ```
60
326
  */
61
- setColumnI64(key: string, data: BigInt64Array, _shape?: Uint32Array | null): void;
327
+ setColU32(key: string, data: Uint32Array): void;
62
328
  /**
63
- * Sets a string column.
329
+ * Zero-copy `Float32Array` view into WASM linear memory.
330
+ *
331
+ * Returns a view backed directly by the block's storage in WASM
332
+ * memory. This avoids copying but the view becomes **invalid**
333
+ * if WASM linear memory grows (due to any allocation).
334
+ *
335
+ * Use [`copyColF32`](Block::copy_col_f32) for a safe, long-lived copy.
336
+ *
337
+ * # Arguments
338
+ *
339
+ * * `key` - Column name
340
+ *
341
+ * # Returns
342
+ *
343
+ * A `Float32Array` view into WASM memory.
344
+ *
345
+ * # Errors
346
+ *
347
+ * Throws if the column does not exist or is not of type `f32`.
348
+ *
349
+ * # Example (JavaScript)
350
+ *
351
+ * ```js
352
+ * const view = block.viewColF32("x"); // zero-copy, use immediately
353
+ * const copy = block.copyColF32("x"); // safe to keep
354
+ * ```
64
355
  */
65
- setColumnStrings(key: string, data: Array<any>, _shape?: Uint32Array | null): void;
356
+ viewColF32(key: string): Float32Array;
66
357
  /**
67
- * Sets a u32 column.
358
+ * Zero-copy `Int32Array` view into WASM linear memory.
359
+ *
360
+ * **Warning**: invalidated if WASM linear memory grows.
361
+ * Use [`copyColI32`](Block::copy_col_i32) for a safe copy.
362
+ *
363
+ * # Arguments
364
+ *
365
+ * * `key` - Column name
366
+ *
367
+ * # Errors
368
+ *
369
+ * Throws if the column does not exist or is not of type `i32`.
370
+ *
371
+ * # Example (JavaScript)
372
+ *
373
+ * ```js
374
+ * const view = block.viewColI32("type_id");
375
+ * ```
68
376
  */
69
- setColumnU32(key: string, data: Uint32Array, _shape?: Uint32Array | null): void;
377
+ viewColI32(key: string): Int32Array;
70
378
  /**
71
- * Sets a u8 column.
379
+ * Zero-copy `Uint32Array` view into WASM linear memory.
380
+ *
381
+ * **Warning**: invalidated if WASM linear memory grows.
382
+ * Use [`copyColU32`](Block::copy_col_u32) for a safe copy.
383
+ *
384
+ * # Arguments
385
+ *
386
+ * * `key` - Column name
387
+ *
388
+ * # Errors
389
+ *
390
+ * Throws if the column does not exist or is not of type `u32`.
391
+ *
392
+ * # Example (JavaScript)
393
+ *
394
+ * ```js
395
+ * const view = block.viewColU32("i");
396
+ * ```
72
397
  */
73
- setColumnU8(key: string, data: Uint8Array, _shape?: Uint32Array | null): void;
398
+ viewColU32(key: string): Uint32Array;
74
399
  }
75
400
 
76
401
  /**
77
- * Simulation box defining the periodic boundary conditions and coordinate transformations.
402
+ * Simulation box defining periodic boundary conditions and coordinate
403
+ * transformations.
404
+ *
405
+ * Represents a parallelepiped defined by a 3x3 matrix `h` and an
406
+ * origin point. Supports periodic boundary conditions (PBC)
407
+ * independently in x, y, z directions.
408
+ *
409
+ * Exported as `Box` in JavaScript.
410
+ *
411
+ * # Example (JavaScript)
78
412
  *
79
- * Represents a parallelepiped defined by a 3x3 matrix `h` and an origin.
80
- * Supports periodic boundary conditions (PBC) independently in x, y, z directions.
413
+ * ```js
414
+ * const h = new Float32Array([10, 0, 0, 0, 10, 0, 0, 0, 10]);
415
+ * const origin = new Float32Array([0, 0, 0]);
416
+ * const box = new Box(h, origin, true, true, true);
417
+ * console.log(box.volume()); // 1000.0
418
+ * console.log(box.lengths().toCopy()); // [10, 10, 10]
419
+ * ```
81
420
  */
82
421
  export class Box {
83
422
  free(): void;
84
423
  [Symbol.dispose](): void;
85
424
  /**
86
- * Create a cubic box.
425
+ * Create a cubic box with equal side lengths.
87
426
  *
88
427
  * # Arguments
89
- * * `a` - Side length of the cube
90
- * * `origin` - 3D origin vector as Float32Array with 3 elements
91
- * * `pbc_x`, `pbc_y`, `pbc_z` - Periodic boundary conditions for each axis
428
+ *
429
+ * * `a` - Side length of the cube in angstrom (A)
430
+ * * `origin` - 3D origin vector as `Float32Array` with 3 elements
431
+ * `[x, y, z]` in angstrom
432
+ * * `pbc_x` - Enable periodic boundary in x direction
433
+ * * `pbc_y` - Enable periodic boundary in y direction
434
+ * * `pbc_z` - Enable periodic boundary in z direction
435
+ *
436
+ * # Returns
437
+ *
438
+ * A new cubic `Box` with side length `a`.
439
+ *
440
+ * # Errors
441
+ *
442
+ * Throws if `origin` does not have 3 elements.
443
+ *
444
+ * # Example (JavaScript)
445
+ *
446
+ * ```js
447
+ * const origin = new Float32Array([0, 0, 0]);
448
+ * const box = Box.cube(10.0, origin, true, true, true);
449
+ * console.log(box.volume()); // 1000.0
450
+ * ```
92
451
  */
93
452
  static cube(a: number, origin: Float32Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean): Box;
94
453
  /**
95
454
  * Calculate displacement vectors between two sets of coordinates.
96
455
  *
456
+ * Computes `delta = b - a` for each pair of points. When
457
+ * `minimum_image` is `true`, the minimum-image convention is
458
+ * applied so that the displacement uses the shortest vector
459
+ * under periodic boundary conditions.
460
+ *
461
+ * # Arguments
462
+ *
463
+ * * `a` - `WasmArray` with shape `[N, 3]` (reference positions in A)
464
+ * * `b` - `WasmArray` with shape `[N, 3]` (target positions in A)
465
+ * * `minimum_image` - If `true`, apply minimum image convention
466
+ * for PBC-enabled axes
467
+ *
468
+ * # Returns
469
+ *
470
+ * `WasmArray` with shape `[N, 3]` containing displacement vectors
471
+ * `(b - a)` in angstrom (A).
472
+ *
473
+ * # Errors
474
+ *
475
+ * Throws if `a` or `b` does not have shape `[N, 3]`, or if the
476
+ * two arrays have different numbers of rows.
477
+ *
478
+ * # Example (JavaScript)
479
+ *
480
+ * ```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]);
483
+ * const d = box.delta(a, b, true); // minimum-image displacement
484
+ * ```
485
+ */
486
+ delta(a: WasmArray, b: WasmArray, minimum_image: boolean): WasmArray;
487
+ /**
488
+ * Calculate displacement vectors and write the result directly into
489
+ * a [`Block`] column.
490
+ *
491
+ * This is an allocation-efficient alternative to [`delta`](Box::delta).
492
+ *
493
+ * # Arguments
494
+ *
495
+ * * `a` - `WasmArray` with shape `[N, 3]` (reference positions in A)
496
+ * * `b` - `WasmArray` with shape `[N, 3]` (target positions in A)
497
+ * * `minimum_image` - If `true`, apply minimum image convention
498
+ * * `out_block` - Target [`Block`] to write the result into
499
+ * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
500
+ *
501
+ * # Errors
502
+ *
503
+ * Throws if shapes are invalid or if the block write fails.
504
+ *
505
+ * # Example (JavaScript)
506
+ *
507
+ * ```js
508
+ * box.deltaToBlock(a, b, true, outBlock, "displacements");
509
+ * ```
510
+ */
511
+ deltaToBlock(a: WasmArray, b: WasmArray, minimum_image: boolean, out_block: Block, out_key: string): void;
512
+ /**
513
+ * Return the 8 corner vertices of the parallelepiped.
514
+ *
515
+ * # Returns
516
+ *
517
+ * `WasmArray` with shape `[8, 3]` containing the corner
518
+ * coordinates in angstrom (A). The flat array has 24 elements.
519
+ *
520
+ * # Example (JavaScript)
521
+ *
522
+ * ```js
523
+ * const corners = box.getCorners();
524
+ * console.log(corners.len()); // 24 (8 corners x 3 coords)
525
+ * ```
526
+ */
527
+ get_corners(): WasmArray;
528
+ /**
529
+ * Return the box edge lengths as a `WasmArray` with shape `[3]`.
530
+ *
531
+ * For orthorhombic boxes these are `[lx, ly, lz]`. For triclinic
532
+ * boxes these are the lengths of the three cell vectors.
533
+ *
534
+ * # Returns
535
+ *
536
+ * `WasmArray` containing `[lx, ly, lz]` in angstrom (A).
537
+ *
538
+ * # Example (JavaScript)
539
+ *
540
+ * ```js
541
+ * const L = box.lengths().toCopy(); // Float32Array [10, 10, 10]
542
+ * ```
543
+ */
544
+ lengths(): WasmArray;
545
+ /**
546
+ * Create a new box from a 3x3 cell matrix and origin.
547
+ *
97
548
  * # Arguments
98
- * * `a` - F32View with Nx3 coordinates
99
- * * `b` - F32View with Nx3 coordinates
100
- * * `minimum_image` - If true, apply minimum image convention
549
+ *
550
+ * * `h` - 3x3 cell matrix as `Float32Array` with 9 elements in
551
+ * row-major order: `[h00, h01, h02, h10, h11, h12, h20, h21, h22]`.
552
+ * All values in angstrom (A).
553
+ * * `origin` - 3D origin vector as `Float32Array` with 3 elements
554
+ * `[x, y, z]` in angstrom.
555
+ * * `pbc_x` - Enable periodic boundary in x direction
556
+ * * `pbc_y` - Enable periodic boundary in y direction
557
+ * * `pbc_z` - Enable periodic boundary in z direction
101
558
  *
102
559
  * # Returns
103
- * F32View with Nx3 displacement vectors (b - a)
560
+ *
561
+ * A new `Box` instance.
562
+ *
563
+ * # Errors
564
+ *
565
+ * Throws if `h` does not have 9 elements or `origin` does not have
566
+ * 3 elements, or if the matrix is singular.
567
+ *
568
+ * # Example (JavaScript)
569
+ *
570
+ * ```js
571
+ * // Triclinic box
572
+ * const h = new Float32Array([10, 2, 0, 0, 10, 0, 0, 0, 10]);
573
+ * const origin = new Float32Array([0, 0, 0]);
574
+ * const box = new Box(h, origin, true, true, true);
575
+ * ```
104
576
  */
105
- delta(a: F32View, b: F32View, minimum_image: boolean): F32View;
106
- get_corners(): F32View;
577
+ constructor(h: Float32Array, origin: Float32Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean);
107
578
  /**
108
- * Get the box edge lengths as F32View [lx, ly, lz].
579
+ * Return the box origin as a `WasmArray` with shape `[3]`.
580
+ *
581
+ * The origin is the lower-left corner of the box in angstrom (A).
582
+ *
583
+ * # Returns
584
+ *
585
+ * `WasmArray` containing `[ox, oy, oz]` in angstrom.
586
+ *
587
+ * # Example (JavaScript)
588
+ *
589
+ * ```js
590
+ * const o = box.origin().toCopy(); // Float32Array [0, 0, 0]
591
+ * ```
109
592
  */
110
- lengths(): F32View;
593
+ origin(): WasmArray;
594
+ /**
595
+ * Create an orthorhombic (rectangular) box with axis-aligned edges.
596
+ *
597
+ * # Arguments
598
+ *
599
+ * * `lengths` - Box dimensions as `Float32Array` with 3 elements
600
+ * `[lx, ly, lz]` in angstrom (A)
601
+ * * `origin` - 3D origin vector as `Float32Array` with 3 elements
602
+ * `[x, y, z]` in angstrom
603
+ * * `pbc_x` - Enable periodic boundary in x direction
604
+ * * `pbc_y` - Enable periodic boundary in y direction
605
+ * * `pbc_z` - Enable periodic boundary in z direction
606
+ *
607
+ * # Returns
608
+ *
609
+ * A new orthorhombic `Box`.
610
+ *
611
+ * # Errors
612
+ *
613
+ * Throws if `lengths` or `origin` does not have 3 elements.
614
+ *
615
+ * # Example (JavaScript)
616
+ *
617
+ * ```js
618
+ * const origin = new Float32Array([0, 0, 0]);
619
+ * const box = Box.ortho(new Float32Array([10, 20, 30]), origin, true, true, true);
620
+ * console.log(box.volume()); // 6000.0
621
+ * ```
622
+ */
623
+ static ortho(lengths: Float32Array, origin: Float32Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean): Box;
624
+ /**
625
+ * Return the box tilt factors as a `WasmArray` with shape `[3]`.
626
+ *
627
+ * Tilt factors `[xy, xz, yz]` define the off-diagonal elements
628
+ * of the cell matrix (LAMMPS convention). For orthorhombic boxes
629
+ * all tilts are zero.
630
+ *
631
+ * # Returns
632
+ *
633
+ * `WasmArray` containing `[xy, xz, yz]` (dimensionless ratios
634
+ * multiplied by the corresponding box length, so effectively in A).
635
+ *
636
+ * # Example (JavaScript)
637
+ *
638
+ * ```js
639
+ * const t = box.tilts().toCopy(); // Float32Array [0, 0, 0]
640
+ * ```
641
+ */
642
+ tilts(): WasmArray;
643
+ /**
644
+ * Convert fractional to Cartesian coordinates and write the result
645
+ * directly into a [`Block`] column.
646
+ *
647
+ * # Arguments
648
+ *
649
+ * * `coords` - `WasmArray` with shape `[N, 3]` (fractional, dimensionless)
650
+ * * `out_block` - Target [`Block`]
651
+ * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
652
+ *
653
+ * # Errors
654
+ *
655
+ * Throws if `coords` does not have shape `[N, 3]`.
656
+ *
657
+ * # Example (JavaScript)
658
+ *
659
+ * ```js
660
+ * box.toCartToBlock(fracCoords, outBlock, "cart_coords");
661
+ * ```
662
+ */
663
+ toCartToBlock(coords: WasmArray, out_block: Block, out_key: string): void;
664
+ /**
665
+ * Convert Cartesian to fractional coordinates and write the result
666
+ * directly into a [`Block`] column.
667
+ *
668
+ * # Arguments
669
+ *
670
+ * * `coords` - `WasmArray` with shape `[N, 3]` (Cartesian, A)
671
+ * * `out_block` - Target [`Block`]
672
+ * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
673
+ *
674
+ * # Errors
675
+ *
676
+ * Throws if `coords` does not have shape `[N, 3]`.
677
+ *
678
+ * # Example (JavaScript)
679
+ *
680
+ * ```js
681
+ * box.toFracToBlock(cartCoords, outBlock, "frac_coords");
682
+ * ```
683
+ */
684
+ toFracToBlock(coords: WasmArray, out_block: Block, out_key: string): void;
685
+ /**
686
+ * Convert fractional coordinates to Cartesian coordinates.
687
+ *
688
+ * # Arguments
689
+ *
690
+ * * `coords` - `WasmArray` with shape `[N, 3]` containing
691
+ * fractional coordinates (dimensionless)
692
+ *
693
+ * # Returns
694
+ *
695
+ * `WasmArray` with shape `[N, 3]` containing Cartesian coordinates
696
+ * in angstrom (A).
697
+ *
698
+ * # Errors
699
+ *
700
+ * Throws if `coords` does not have shape `[N, 3]`.
701
+ *
702
+ * # Example (JavaScript)
703
+ *
704
+ * ```js
705
+ * const frac = WasmArray.from(new Float32Array([0.5, 0.5, 0.5]), [1, 3]);
706
+ * const cart = box.toCart(frac);
707
+ * console.log(cart.toCopy()); // [5, 5, 5] for a 10x10x10 box
708
+ * ```
709
+ */
710
+ to_cart(coords: WasmArray): WasmArray;
711
+ /**
712
+ * Convert Cartesian coordinates to fractional coordinates.
713
+ *
714
+ * Fractional coordinates are in the range [0, 1) for atoms
715
+ * inside the primary image of the box.
716
+ *
717
+ * # Arguments
718
+ *
719
+ * * `coords` - `WasmArray` with shape `[N, 3]` containing
720
+ * Cartesian coordinates in angstrom (A)
721
+ *
722
+ * # Returns
723
+ *
724
+ * `WasmArray` with shape `[N, 3]` containing fractional coordinates
725
+ * (dimensionless).
726
+ *
727
+ * # Errors
728
+ *
729
+ * Throws if `coords` does not have shape `[N, 3]`.
730
+ *
731
+ * # Example (JavaScript)
732
+ *
733
+ * ```js
734
+ * const cart = WasmArray.from(new Float32Array([5, 5, 5]), [1, 3]);
735
+ * const frac = box.toFrac(cart);
736
+ * console.log(frac.toCopy()); // [0.5, 0.5, 0.5] for a 10x10x10 box
737
+ * ```
738
+ */
739
+ to_frac(coords: WasmArray): WasmArray;
740
+ /**
741
+ * Return the box volume in cubic angstrom (A^3).
742
+ *
743
+ * # Example (JavaScript)
744
+ *
745
+ * ```js
746
+ * console.log(box.volume()); // e.g., 1000.0
747
+ * ```
748
+ */
749
+ volume(): number;
750
+ /**
751
+ * Wrap Cartesian coordinates into the primary image of the box.
752
+ *
753
+ * Atoms outside the box are translated back into the primary image
754
+ * using the periodic boundary conditions. Only axes with PBC
755
+ * enabled are wrapped.
756
+ *
757
+ * # Arguments
758
+ *
759
+ * * `coords` - `WasmArray` with shape `[N, 3]` containing
760
+ * Cartesian coordinates in angstrom (A)
761
+ *
762
+ * # Returns
763
+ *
764
+ * `WasmArray` with shape `[N, 3]` containing wrapped coordinates
765
+ * in angstrom (A).
766
+ *
767
+ * # Errors
768
+ *
769
+ * Throws if `coords` does not have shape `[N, 3]`.
770
+ *
771
+ * # Example (JavaScript)
772
+ *
773
+ * ```js
774
+ * const pos = WasmArray.from(new Float32Array([12, -1, 5]), [1, 3]);
775
+ * const wrapped = box.wrap(pos); // wraps into [0, lx) x [0, ly) x [0, lz)
776
+ * ```
777
+ */
778
+ wrap(coords: WasmArray): WasmArray;
779
+ /**
780
+ * Wrap coordinates and write the result directly into a [`Block`] column.
781
+ *
782
+ * This is an allocation-efficient alternative to [`wrap`](Box::wrap)
783
+ * that avoids creating an intermediate `WasmArray`.
784
+ *
785
+ * # Arguments
786
+ *
787
+ * * `coords` - `WasmArray` with shape `[N, 3]` containing
788
+ * Cartesian coordinates in angstrom (A)
789
+ * * `out_block` - Target [`Block`] to write the result into
790
+ * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
791
+ *
792
+ * # Errors
793
+ *
794
+ * Throws if `coords` does not have shape `[N, 3]` or if the
795
+ * block write fails.
796
+ *
797
+ * # Example (JavaScript)
798
+ *
799
+ * ```js
800
+ * box.wrapToBlock(coords, outBlock, "wrapped_pos");
801
+ * ```
802
+ */
803
+ wrapToBlock(coords: WasmArray, out_block: Block, out_key: string): void;
804
+ }
805
+
806
+ /**
807
+ * Distance-based cluster analysis using BFS on the neighbor graph.
808
+ *
809
+ * Particles that are connected (directly or transitively) through
810
+ * neighbor-list pairs are grouped into clusters. Clusters smaller
811
+ * than `minClusterSize` are filtered out (their particles get
812
+ * cluster ID = -1).
813
+ *
814
+ * # Example (JavaScript)
815
+ *
816
+ * ```js
817
+ * const lc = new LinkedCell(2.0);
818
+ * const nlist = lc.build(frame);
819
+ *
820
+ * const cluster = new Cluster(5); // min 5 particles per cluster
821
+ * const result = cluster.compute(frame, nlist);
822
+ *
823
+ * console.log(result.numClusters); // number of valid clusters
824
+ * console.log(result.clusterIdx()); // Int32Array, per-particle IDs
825
+ * console.log(result.clusterSizes()); // Uint32Array, size of each cluster
826
+ * ```
827
+ */
828
+ export class Cluster {
829
+ free(): void;
830
+ [Symbol.dispose](): void;
831
+ /**
832
+ * Run cluster analysis on a frame with pre-built neighbor pairs.
833
+ *
834
+ * # Arguments
835
+ *
836
+ * * `frame` - Frame with atom positions
837
+ * * `neighbors` - Pre-built [`NeighborList`] defining connectivity
838
+ *
839
+ * # Returns
840
+ *
841
+ * A [`ClusterResult`] with per-particle cluster IDs and cluster sizes.
842
+ *
843
+ * # Errors
844
+ *
845
+ * Throws if the frame cannot be cloned or the analysis fails.
846
+ *
847
+ * # Example (JavaScript)
848
+ *
849
+ * ```js
850
+ * const result = cluster.compute(frame, nlist);
851
+ * ```
852
+ */
853
+ compute(frame: Frame, neighbors: NeighborList): ClusterResult;
854
+ /**
855
+ * Create a cluster analysis with a minimum cluster size filter.
856
+ *
857
+ * # Arguments
858
+ *
859
+ * * `min_cluster_size` - Minimum number of particles for a cluster
860
+ * to be considered valid. Clusters with fewer particles are
861
+ * discarded (their particles get cluster ID = -1).
862
+ *
863
+ * # Example (JavaScript)
864
+ *
865
+ * ```js
866
+ * const cluster = new Cluster(5); // ignore clusters < 5 particles
867
+ * ```
868
+ */
869
+ constructor(min_cluster_size: number);
870
+ }
871
+
872
+ /**
873
+ * Result of a distance-based cluster analysis.
874
+ *
875
+ * # Example (JavaScript)
876
+ *
877
+ * ```js
878
+ * const result = cluster.compute(frame, nlist);
879
+ * console.log(result.numClusters); // number
880
+ *
881
+ * const ids = result.clusterIdx(); // Int32Array (per-particle)
882
+ * const sizes = result.clusterSizes(); // Uint32Array (per-cluster)
883
+ *
884
+ * // Particles in filtered-out clusters have id = -1
885
+ * for (let i = 0; i < ids.length; i++) {
886
+ * if (ids[i] === -1) console.log(`Particle ${i} not in any valid cluster`);
887
+ * }
888
+ * ```
889
+ */
890
+ export class ClusterResult {
891
+ private constructor();
892
+ free(): void;
893
+ [Symbol.dispose](): void;
894
+ /**
895
+ * Per-particle cluster ID assignment as `Int32Array`.
896
+ *
897
+ * `clusterIdx()[i]` is the cluster ID for particle `i`.
898
+ * Particles in clusters smaller than `minClusterSize` are
899
+ * assigned ID = -1 (filtered out).
900
+ *
901
+ * Cluster IDs are zero-based and contiguous: `0, 1, ..., numClusters-1`.
902
+ */
903
+ clusterIdx(): Int32Array;
904
+ /**
905
+ * Size (particle count) of each valid cluster as `Uint32Array`.
906
+ *
907
+ * `clusterSizes()[c]` is the number of particles in cluster `c`.
908
+ * Length equals `numClusters`.
909
+ */
910
+ clusterSizes(): Uint32Array;
911
+ /**
912
+ * Number of valid clusters found (after min-size filtering).
913
+ */
914
+ readonly numClusters: number;
915
+ }
916
+
917
+ /**
918
+ * Hierarchical data container mapping string keys to typed [`Block`]s.
919
+ *
920
+ * A `Frame` owns a set of named blocks (column stores) and an optional
921
+ * simulation box ([`Box`](super::region::simbox::Box)). This is the
922
+ * primary interchange type for molecular data in the WASM API.
923
+ *
924
+ * # Conventions
925
+ *
926
+ * - 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).
929
+ * - The `"bonds"` block should contain bond topology: `i`/`j` (u32,
930
+ * zero-based atom indices) and `order` (f32, bond order: 1.0 = single,
931
+ * 1.5 = aromatic, 2.0 = double, 3.0 = triple).
932
+ *
933
+ * # Example (JavaScript)
934
+ *
935
+ * ```js
936
+ * const frame = new Frame();
937
+ * const atoms = frame.createBlock("atoms");
938
+ * atoms.setColF32("x", new Float32Array([0.0, 1.54]));
939
+ * ```
940
+ */
941
+ export class Frame {
942
+ free(): void;
943
+ [Symbol.dispose](): void;
944
+ /**
945
+ * Remove all blocks from this frame (but keep the frame alive).
946
+ *
947
+ * # Errors
948
+ *
949
+ * Throws a `JsValue` string if the frame has already been dropped.
950
+ *
951
+ * # Example (JavaScript)
952
+ *
953
+ * ```js
954
+ * frame.clear();
955
+ * ```
956
+ */
957
+ clear(): void;
958
+ /**
959
+ * Create a new empty [`Block`] and register it under `key`.
960
+ *
961
+ * If a block with the same key already exists it is replaced.
962
+ *
963
+ * # Arguments
964
+ *
965
+ * * `key` - Block name (e.g., `"atoms"`, `"bonds"`)
966
+ *
967
+ * # Returns
968
+ *
969
+ * A mutable [`Block`] handle that can be used to add columns.
970
+ *
971
+ * # Errors
972
+ *
973
+ * Throws a `JsValue` string if the underlying store operation fails
974
+ * (e.g., the frame has been dropped).
975
+ *
976
+ * # Example (JavaScript)
977
+ *
978
+ * ```js
979
+ * const atoms = frame.createBlock("atoms");
980
+ * atoms.setColF32("x", new Float32Array([1.0, 2.0]));
981
+ * ```
982
+ */
983
+ createBlock(key: string): Block;
984
+ /**
985
+ * Explicitly release this frame and all its blocks from the store.
986
+ *
987
+ * After calling `drop()`, any subsequent operations on this frame
988
+ * or its blocks will throw. This is optional -- the frame will also
989
+ * be released when garbage-collected by the JS engine.
990
+ *
991
+ * # Errors
992
+ *
993
+ * Throws a `JsValue` string if the frame was already dropped.
994
+ *
995
+ * # Example (JavaScript)
996
+ *
997
+ * ```js
998
+ * frame.drop();
999
+ * // frame.clear() would now throw
1000
+ * ```
1001
+ */
1002
+ drop(): void;
1003
+ /**
1004
+ * Retrieve an existing [`Block`] by name.
1005
+ *
1006
+ * # Arguments
1007
+ *
1008
+ * * `key` - Block name to look up
1009
+ *
1010
+ * # Returns
1011
+ *
1012
+ * The [`Block`] if found, or `undefined` if no block with that key
1013
+ * exists in this frame.
1014
+ *
1015
+ * # Example (JavaScript)
1016
+ *
1017
+ * ```js
1018
+ * const atoms = frame.getBlock("atoms");
1019
+ * if (atoms) {
1020
+ * const x = atoms.copyColF32("x");
1021
+ * }
1022
+ * ```
1023
+ */
1024
+ getBlock(key: string): Block | undefined;
1025
+ /**
1026
+ * Insert a block by deep-copying its data into this frame's store.
1027
+ *
1028
+ * This is useful for transferring a block from one frame to another.
1029
+ * The source block's data is cloned; subsequent modifications to the
1030
+ * source will not affect this frame.
1031
+ *
1032
+ * # Arguments
1033
+ *
1034
+ * * `key` - Name under which to store the block
1035
+ * * `block` - The source [`Block`] whose data will be copied
1036
+ *
1037
+ * # Errors
1038
+ *
1039
+ * Throws a `JsValue` string if either the source block or the
1040
+ * destination frame handle is invalid.
1041
+ *
1042
+ * # Example (JavaScript)
1043
+ *
1044
+ * ```js
1045
+ * const otherFrame = new Frame();
1046
+ * const atoms = otherFrame.createBlock("atoms");
1047
+ * // ... populate atoms ...
1048
+ * frame.insertBlock("atoms", atoms);
1049
+ * ```
1050
+ */
1051
+ insertBlock(key: string, block: Block): void;
1052
+ /**
1053
+ * Create a new, empty `Frame` with no blocks and no simulation box.
1054
+ *
1055
+ * # Example (JavaScript)
1056
+ *
1057
+ * ```js
1058
+ * const frame = new Frame();
1059
+ * ```
1060
+ */
1061
+ constructor();
1062
+ /**
1063
+ * Remove a block by name.
1064
+ *
1065
+ * # Arguments
1066
+ *
1067
+ * * `key` - Block name to remove
1068
+ *
1069
+ * # Errors
1070
+ *
1071
+ * Throws a `JsValue` string if the frame has been dropped or the
1072
+ * key does not exist.
1073
+ *
1074
+ * # Example (JavaScript)
1075
+ *
1076
+ * ```js
1077
+ * frame.removeBlock("bonds");
1078
+ * ```
1079
+ */
1080
+ removeBlock(key: string): void;
1081
+ /**
1082
+ * Rename a block from `old_key` to `new_key`.
1083
+ *
1084
+ * # Arguments
1085
+ *
1086
+ * * `old_key` - Current block name
1087
+ * * `new_key` - New block name
1088
+ *
1089
+ * # Returns
1090
+ *
1091
+ * `true` if the block was found and renamed, `false` if `old_key`
1092
+ * did not exist.
1093
+ *
1094
+ * # Errors
1095
+ *
1096
+ * Throws a `JsValue` string if the frame has been dropped.
1097
+ *
1098
+ * # Example (JavaScript)
1099
+ *
1100
+ * ```js
1101
+ * frame.renameBlock("atoms", "particles");
1102
+ * ```
1103
+ */
1104
+ renameBlock(old_key: string, new_key: string): boolean;
1105
+ /**
1106
+ * Rename a column within a specific block.
1107
+ *
1108
+ * # Arguments
1109
+ *
1110
+ * * `block_key` - Name of the block containing the column
1111
+ * * `old_col` - Current column name
1112
+ * * `new_col` - New column name
1113
+ *
1114
+ * # Returns
1115
+ *
1116
+ * `true` if the column was found and renamed, `false` if
1117
+ * `old_col` did not exist in the block.
1118
+ *
1119
+ * # Errors
1120
+ *
1121
+ * Throws a `JsValue` string if the frame or block does not exist.
1122
+ *
1123
+ * # Example (JavaScript)
1124
+ *
1125
+ * ```js
1126
+ * frame.renameColumn("atoms", "element", "symbol");
1127
+ * ```
1128
+ */
1129
+ renameColumn(block_key: string, old_col: string, new_col: string): boolean;
1130
+ /**
1131
+ * Get the simulation box attached to this frame (if any).
1132
+ *
1133
+ * # Returns
1134
+ *
1135
+ * The [`Box`](super::region::simbox::Box) if one has been set,
1136
+ * or `undefined` otherwise.
1137
+ *
1138
+ * # Example (JavaScript)
1139
+ *
1140
+ * ```js
1141
+ * const box = frame.simbox;
1142
+ * if (box) {
1143
+ * console.log("Volume:", box.volume());
1144
+ * }
1145
+ * ```
1146
+ */
1147
+ get simbox(): Box | undefined;
1148
+ /**
1149
+ * Attach or detach a simulation box.
1150
+ *
1151
+ * Pass a [`Box`](super::region::simbox::Box) to attach, or
1152
+ * `undefined`/`null` to detach.
1153
+ *
1154
+ * # Arguments
1155
+ *
1156
+ * * `simbox` - The simulation box, or `undefined`/`null` to remove it
1157
+ *
1158
+ * # Errors
1159
+ *
1160
+ * Throws a `JsValue` string if the frame has been dropped.
1161
+ *
1162
+ * # Example (JavaScript)
1163
+ *
1164
+ * ```js
1165
+ * const origin = new Float32Array([0, 0, 0]);
1166
+ * frame.simbox = Box.cube(10.0, origin, true, true, true);
1167
+ * ```
1168
+ */
1169
+ set simbox(value: Box | null | undefined);
1170
+ }
1171
+
1172
+ /**
1173
+ * LAMMPS data file reader.
1174
+ *
1175
+ * Reads LAMMPS data files (the format written by `write_data`). The
1176
+ * reader produces a [`Frame`] containing:
1177
+ *
1178
+ * - `"atoms"` block: `type` (i32), `x`, `y`, `z` (f32, angstrom),
1179
+ * and optionally `charge` (f32)
1180
+ * - `"bonds"` block (if present): `i`, `j` (u32), `type` (i32)
1181
+ * - Simulation box (`simbox`) with PBC
1182
+ *
1183
+ * Only a single frame is supported (`step = 0`).
1184
+ *
1185
+ * # Example (JavaScript)
1186
+ *
1187
+ * ```js
1188
+ * const reader = new LAMMPSReader(dataFileContent);
1189
+ * const frame = reader.read(0);
1190
+ * const atoms = frame.getBlock("atoms");
1191
+ * const bonds = frame.getBlock("bonds");
1192
+ * const box = frame.simbox;
1193
+ * ```
1194
+ */
1195
+ export class LAMMPSReader {
1196
+ free(): void;
1197
+ [Symbol.dispose](): void;
1198
+ /**
1199
+ * Check whether the file contains no valid frames.
1200
+ *
1201
+ * # Errors
1202
+ *
1203
+ * Throws a `JsValue` string on parse errors.
1204
+ */
1205
+ isEmpty(): boolean;
1206
+ /**
1207
+ * Return the number of frames (always 0 or 1 for LAMMPS data files).
1208
+ *
1209
+ * # Errors
1210
+ *
1211
+ * Throws a `JsValue` string on parse errors.
1212
+ */
1213
+ len(): number;
1214
+ /**
1215
+ * Create a new LAMMPS data file reader from string content.
1216
+ *
1217
+ * # Arguments
1218
+ *
1219
+ * * `content` - The full text content of a LAMMPS data file
1220
+ *
1221
+ * # Example (JavaScript)
1222
+ *
1223
+ * ```js
1224
+ * const reader = new LAMMPSReader(dataFileString);
1225
+ * ```
1226
+ */
1227
+ constructor(content: string);
1228
+ /**
1229
+ * Read the frame at the given step index.
1230
+ *
1231
+ * LAMMPS data files contain a single configuration, so only
1232
+ * `step = 0` is valid. Passing any other step returns `undefined`.
1233
+ *
1234
+ * # Arguments
1235
+ *
1236
+ * * `step` - Frame index (must be `0`)
1237
+ *
1238
+ * # Returns
1239
+ *
1240
+ * A [`Frame`] with atoms, optional bonds, and simbox, or `undefined`.
1241
+ *
1242
+ * # Errors
1243
+ *
1244
+ * Throws a `JsValue` string on parse errors.
1245
+ *
1246
+ * # Example (JavaScript)
1247
+ *
1248
+ * ```js
1249
+ * const frame = reader.read(0);
1250
+ * ```
1251
+ */
1252
+ read(step: number): Frame | undefined;
1253
+ }
1254
+
1255
+ /**
1256
+ * Cell-list (linked-cell) based neighbor search.
1257
+ *
1258
+ * Creates a spatial index from a [`Frame`]'s atom positions and
1259
+ * simulation box, then finds all neighbor pairs within the cutoff
1260
+ * distance.
1261
+ *
1262
+ * All distances are in angstrom (A).
1263
+ *
1264
+ * # Example (JavaScript)
1265
+ *
1266
+ * ```js
1267
+ * const lc = new LinkedCell(3.0); // cutoff = 3.0 A
1268
+ * const nlist = lc.build(frame); // self-query (unique pairs i < j)
1269
+ * const cross = lc.query(ref, other); // cross-query
1270
+ *
1271
+ * console.log(nlist.numPairs);
1272
+ * ```
1273
+ */
1274
+ export class LinkedCell {
1275
+ free(): void;
1276
+ [Symbol.dispose](): void;
1277
+ /**
1278
+ * Build a neighbor list from a [`Frame`] (self-query).
1279
+ *
1280
+ * Finds all unique pairs `(i < j)` of atoms within the cutoff
1281
+ * distance using the cell-list algorithm.
1282
+ *
1283
+ * The frame must have an `"atoms"` block with `x`, `y`, `z` (f32) columns.
1284
+ * If the frame has a `simbox`, periodic boundary conditions are used.
1285
+ * Otherwise, a free-boundary bounding box is auto-generated.
1286
+ *
1287
+ * # Arguments
1288
+ *
1289
+ * * `frame` - Frame with atom positions
1290
+ *
1291
+ * # Returns
1292
+ *
1293
+ * A [`NeighborList`] containing all unique pairs within the cutoff.
1294
+ *
1295
+ * # Errors
1296
+ *
1297
+ * Throws if the frame is missing required data.
1298
+ *
1299
+ * # Example (JavaScript)
1300
+ *
1301
+ * ```js
1302
+ * const lc = new LinkedCell(3.0);
1303
+ * const nlist = lc.build(frame);
1304
+ * const dists = nlist.distances(); // Float32Array
1305
+ * ```
1306
+ */
1307
+ build(frame: Frame): NeighborList;
1308
+ /**
1309
+ * Create a linked-cell neighbor search with the given distance cutoff.
1310
+ *
1311
+ * # Arguments
1312
+ *
1313
+ * * `cutoff` - Maximum neighbor distance in angstrom (A)
1314
+ *
1315
+ * # Example (JavaScript)
1316
+ *
1317
+ * ```js
1318
+ * const lc = new LinkedCell(5.0);
1319
+ * ```
1320
+ */
1321
+ constructor(cutoff: number);
1322
+ /**
1323
+ * Cross-query: find all pairs where `i` indexes query points and
1324
+ * `j` indexes the reference points.
1325
+ *
1326
+ * # Arguments
1327
+ *
1328
+ * * `ref_frame` - Frame with reference atom positions
1329
+ * * `query_frame` - Frame with query atom positions (must have
1330
+ * `"atoms"` block with `x`, `y`, `z` columns)
1331
+ *
1332
+ * # Returns
1333
+ *
1334
+ * A [`NeighborList`] containing all `(i, j, distance)` pairs
1335
+ * within the cutoff.
1336
+ *
1337
+ * # Errors
1338
+ *
1339
+ * Throws if either frame is missing required columns.
1340
+ *
1341
+ * # Example (JavaScript)
1342
+ *
1343
+ * ```js
1344
+ * const lc = new LinkedCell(3.0);
1345
+ * const crossPairs = lc.query(refFrame, otherFrame);
1346
+ * console.log(crossPairs.numPairs);
1347
+ * ```
1348
+ */
1349
+ query(ref_frame: Frame, query_frame: Frame): NeighborList;
1350
+ }
1351
+
1352
+ /**
1353
+ * Mean squared displacement (MSD) analysis.
1354
+ *
1355
+ * Computes MSD = |r(t) - r(0)|^2 for each particle and the system
1356
+ * average. The first frame fed is automatically used as the reference.
1357
+ * Useful for measuring diffusion coefficients via D = MSD / (6t).
1358
+ *
1359
+ * All distances are in angstrom (A), so MSD is in A^2.
1360
+ *
1361
+ * # Example (JavaScript)
1362
+ *
1363
+ * ```js
1364
+ * const msd = new MSD();
1365
+ * for (const frame of trajectory) {
1366
+ * msd.feed(frame); // first frame = reference
1367
+ * }
1368
+ * const results = msd.results(); // MSDResult[] per frame
1369
+ * console.log(results[10].mean); // MSD at frame 10 in A^2
1370
+ * ```
1371
+ *
1372
+ * # References
1373
+ *
1374
+ * - Einstein, A. (1905). *Annalen der Physik*, 322(8), 549-560.
1375
+ */
1376
+ export class MSD {
1377
+ free(): void;
1378
+ [Symbol.dispose](): void;
1379
+ /**
1380
+ * Feed a frame into the MSD analysis.
1381
+ *
1382
+ * The first frame sets the reference configuration.
1383
+ * Subsequent frames compute MSD relative to that reference.
1384
+ *
1385
+ * # Arguments
1386
+ *
1387
+ * * `frame` - Frame with `"atoms"` block containing
1388
+ * `x`, `y`, `z` (f32) columns
1389
+ *
1390
+ * # Errors
1391
+ *
1392
+ * Throws if the frame is missing required columns or has a
1393
+ * different number of atoms than the reference.
1394
+ *
1395
+ * # Example (JavaScript)
1396
+ *
1397
+ * ```js
1398
+ * const msd = new MSD();
1399
+ * msd.feed(frame0); // sets reference
1400
+ * msd.feed(frame1); // computes MSD vs frame0
1401
+ * ```
1402
+ */
1403
+ feed(frame: Frame): void;
1404
+ /**
1405
+ * Create an empty MSD analysis.
1406
+ *
1407
+ * The first frame passed to [`feed`] becomes the reference
1408
+ * configuration (t=0).
1409
+ *
1410
+ * # Example (JavaScript)
1411
+ *
1412
+ * ```js
1413
+ * const msd = new MSD();
1414
+ * ```
1415
+ */
1416
+ constructor();
1417
+ /**
1418
+ * Reset the analysis, clearing reference and all results.
1419
+ */
1420
+ reset(): void;
1421
+ /**
1422
+ * Return all accumulated MSD results as an array.
1423
+ *
1424
+ * Returns one [`MSDResult`] per frame fed (including the
1425
+ * reference frame, which has MSD = 0).
1426
+ *
1427
+ * # Example (JavaScript)
1428
+ *
1429
+ * ```js
1430
+ * const results = msd.results();
1431
+ * results.forEach((r, t) => console.log(`t=${t}: MSD=${r.mean}`));
1432
+ * ```
1433
+ */
1434
+ results(): MSDResult[];
1435
+ /**
1436
+ * Number of frames accumulated.
1437
+ */
1438
+ readonly count: number;
1439
+ }
1440
+
1441
+ /**
1442
+ * Result of a mean squared displacement computation.
1443
+ *
1444
+ * # Example (JavaScript)
1445
+ *
1446
+ * ```js
1447
+ * const result = msd.compute(frame);
1448
+ * console.log(result.mean); // number (A^2)
1449
+ * console.log(result.perParticle()); // Float32Array (A^2)
1450
+ * ```
1451
+ */
1452
+ export class MSDResult {
1453
+ private constructor();
1454
+ free(): void;
1455
+ [Symbol.dispose](): void;
1456
+ /**
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.
1461
+ */
1462
+ perParticle(): Float32Array;
1463
+ /**
1464
+ * System-average mean squared displacement in A^2.
1465
+ *
1466
+ * This is the arithmetic mean of all per-particle squared
1467
+ * displacements: `mean = sum(|r_i(t) - r_i(0)|^2) / N`.
1468
+ */
1469
+ readonly mean: number;
1470
+ }
1471
+
1472
+ /**
1473
+ * Result of a neighbor search: all atom pairs within a distance cutoff.
1474
+ *
1475
+ * Contains pair indices, distances, and squared distances for every
1476
+ * neighbor pair found. This object is produced by [`LinkedCell`]
1477
+ * and consumed by analysis classes like [`RDF`] and [`Cluster`].
1478
+ *
1479
+ * # Properties
1480
+ *
1481
+ * | Property | Type | Description |
1482
+ * |----------|------|-------------|
1483
+ * | `numPairs` | `number` | Total number of neighbor pairs |
1484
+ * | `numPoints` | `number` | Number of reference points |
1485
+ * | `numQueryPoints` | `number` | Number of query points |
1486
+ * | `isSelfQuery` | `boolean` | Whether this is a self-query result |
1487
+ *
1488
+ * # Example (JavaScript)
1489
+ *
1490
+ * ```js
1491
+ * const nlist = lc.build(frame);
1492
+ * console.log(nlist.numPairs);
1493
+ *
1494
+ * const i = nlist.queryPointIndices(); // Uint32Array
1495
+ * const j = nlist.pointIndices(); // Uint32Array
1496
+ * const d = nlist.distances(); // Float32Array (in A)
1497
+ * ```
1498
+ */
1499
+ export class NeighborList {
1500
+ private constructor();
1501
+ free(): void;
1502
+ [Symbol.dispose](): void;
1503
+ /**
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.
1508
+ */
1509
+ distSq(): Float32Array;
1510
+ /**
1511
+ * Pairwise distances in angstrom (A), as a `Float32Array`.
1512
+ *
1513
+ * `distances()[k]` is the distance between query point
1514
+ * `queryPointIndices()[k]` and reference point `pointIndices()[k]`.
1515
+ */
1516
+ distances(): Float32Array;
1517
+ /**
1518
+ * Reference point indices (`j`) for each pair, as a `Uint32Array`.
1519
+ */
1520
+ pointIndices(): Uint32Array;
1521
+ /**
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]`.
1526
+ */
1527
+ queryPointIndices(): Uint32Array;
1528
+ /**
1529
+ * Whether this result came from a self-query (`build()`).
1530
+ *
1531
+ * In self-queries, only unique pairs `(i < j)` are reported.
1532
+ */
1533
+ readonly isSelfQuery: boolean;
1534
+ /**
1535
+ * Total number of neighbor pairs found.
1536
+ */
1537
+ readonly numPairs: number;
1538
+ /**
1539
+ * Number of reference (target) points in the search.
1540
+ */
1541
+ readonly numPoints: number;
1542
+ /**
1543
+ * Number of query points in the search.
1544
+ *
1545
+ * For self-queries, this equals `numPoints`.
1546
+ */
1547
+ readonly numQueryPoints: number;
1548
+ }
1549
+
1550
+ /**
1551
+ * Protein Data Bank (PDB) file reader.
1552
+ *
1553
+ * PDB files contain a single molecular structure. The reader produces
1554
+ * 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).
1557
+ *
1558
+ * # Example (JavaScript)
1559
+ *
1560
+ * ```js
1561
+ * const reader = new PDBReader(pdbContent);
1562
+ * const frame = reader.read(0);
1563
+ * const atoms = frame.getBlock("atoms");
1564
+ * const names = atoms.copyColStr("name"); // ["CA", "CB", ...]
1565
+ * const x = atoms.copyColF32("x");
1566
+ * ```
1567
+ */
1568
+ export class PDBReader {
1569
+ free(): void;
1570
+ [Symbol.dispose](): void;
1571
+ /**
1572
+ * Check whether the file contains no valid frames.
1573
+ *
1574
+ * # Errors
1575
+ *
1576
+ * Throws a `JsValue` string on parse errors.
1577
+ */
1578
+ isEmpty(): boolean;
1579
+ /**
1580
+ * Return the number of frames (always 0 or 1 for PDB files).
1581
+ *
1582
+ * # Errors
1583
+ *
1584
+ * Throws a `JsValue` string on parse errors.
1585
+ */
1586
+ len(): number;
1587
+ /**
1588
+ * Create a new PDB reader from a string containing the file content.
1589
+ *
1590
+ * # Arguments
1591
+ *
1592
+ * * `content` - The full text content of a PDB file
1593
+ *
1594
+ * # Example (JavaScript)
1595
+ *
1596
+ * ```js
1597
+ * const reader = new PDBReader(pdbString);
1598
+ * ```
1599
+ */
1600
+ constructor(content: string);
1601
+ /**
1602
+ * Read the frame at the given step index.
1603
+ *
1604
+ * PDB files contain a single structure, so only `step = 0` is
1605
+ * valid. Passing any other step returns `undefined`.
1606
+ *
1607
+ * # Arguments
1608
+ *
1609
+ * * `step` - Frame index (must be `0` for PDB files)
1610
+ *
1611
+ * # Returns
1612
+ *
1613
+ * A [`Frame`] if `step == 0` and the file is valid, or `undefined`.
1614
+ *
1615
+ * # Errors
1616
+ *
1617
+ * Throws a `JsValue` string on parse errors.
1618
+ *
1619
+ * # Example (JavaScript)
1620
+ *
1621
+ * ```js
1622
+ * const frame = reader.read(0);
1623
+ * ```
1624
+ */
1625
+ read(step: number): Frame | undefined;
1626
+ }
1627
+
1628
+ /**
1629
+ * Radial distribution function g(r) analysis.
1630
+ *
1631
+ * Computes the pair correlation function by binning neighbor-pair
1632
+ * distances into a histogram and normalizing by the ideal-gas
1633
+ * density (spherical shell volume normalization).
1634
+ *
1635
+ * # Algorithm
1636
+ *
1637
+ * g(r) = n(r) / (rho * V_shell(r) * N_ref)
1638
+ *
1639
+ * where `n(r)` is the pair count in bin `r`, `rho` is the number
1640
+ * density, and `V_shell(r)` is the shell volume for that bin.
1641
+ *
1642
+ * # Example (JavaScript)
1643
+ *
1644
+ * ```js
1645
+ * const lc = new LinkedCell(5.0);
1646
+ * const nlist = lc.build(frame);
1647
+ *
1648
+ * const rdf = new RDF(100, 5.0);
1649
+ * const result = rdf.compute(frame, nlist);
1650
+ *
1651
+ * const r = result.binCenters(); // Float32Array, bin centers in A
1652
+ * const gr = result.rdf(); // Float32Array, g(r) values
1653
+ * ```
1654
+ */
1655
+ export class RDF {
1656
+ free(): void;
1657
+ [Symbol.dispose](): void;
1658
+ /**
1659
+ * Compute the RDF from a pre-built neighbor list.
1660
+ *
1661
+ * The frame is needed to read the simulation box volume for
1662
+ * normalization.
1663
+ *
1664
+ * # Arguments
1665
+ *
1666
+ * * `frame` - Frame with a `simbox` set (for volume normalization)
1667
+ * * `neighbors` - Pre-built [`NeighborList`] from [`LinkedCell`]
1668
+ *
1669
+ * # Returns
1670
+ *
1671
+ * An [`RDFResult`] containing bin centers, g(r) values, and raw
1672
+ * pair counts.
1673
+ *
1674
+ * # Errors
1675
+ *
1676
+ * Throws if the frame cannot be cloned or the computation fails.
1677
+ *
1678
+ * # Example (JavaScript)
1679
+ *
1680
+ * ```js
1681
+ * const result = rdf.compute(frame, nlist);
1682
+ * const gr = result.rdf(); // Float32Array
1683
+ * ```
1684
+ */
1685
+ compute(frame: Frame, neighbors: NeighborList): RDFResult;
1686
+ /**
1687
+ * Create a new RDF analysis with specified binning.
1688
+ *
1689
+ * # Arguments
1690
+ *
1691
+ * * `n_bins` - Number of histogram bins
1692
+ * * `r_max` - Maximum radial distance in angstrom (A). Should
1693
+ * match or be less than the neighbor-search cutoff.
1694
+ *
1695
+ * # Example (JavaScript)
1696
+ *
1697
+ * ```js
1698
+ * const rdf = new RDF(100, 5.0); // 100 bins up to 5 A
1699
+ * ```
1700
+ */
1701
+ constructor(n_bins: number, r_max: number);
1702
+ }
1703
+
1704
+ /**
1705
+ * Result of a radial distribution function computation.
1706
+ *
1707
+ * Contains the binned g(r) values, bin geometry, raw pair counts,
1708
+ * and normalization metadata.
1709
+ *
1710
+ * # Example (JavaScript)
1711
+ *
1712
+ * ```js
1713
+ * 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
1717
+ * console.log("Volume:", result.volume, "A^3");
1718
+ * console.log("N_ref:", result.numPoints);
1719
+ * ```
1720
+ */
1721
+ export class RDFResult {
1722
+ private constructor();
1723
+ free(): void;
1724
+ [Symbol.dispose](): void;
111
1725
  /**
112
- * Create a new box from a 3x3 matrix and origin.
1726
+ * Bin center positions as `Float32Array` in angstrom (A).
113
1727
  *
114
- * # Arguments
115
- * * `h` - 3x3 matrix as Float32Array with 9 elements (row-major: [h00, h01, h02, h10, ...])
116
- * * `origin` - 3D origin vector as Float32Array with 3 elements [x, y, z]
117
- * * `pbc_x`, `pbc_y`, `pbc_z` - Periodic boundary conditions for each axis
118
- */
119
- constructor(h: Float32Array, origin: Float32Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean);
120
- /**
121
- * Get the box origin as F32View [x, y, z].
1728
+ * Length equals `n_bins` (the value passed to the `RDF` constructor).
122
1729
  */
123
- origin(): F32View;
1730
+ binCenters(): Float32Array;
124
1731
  /**
125
- * Create an orthorhombic box (rectangular box with axis-aligned edges).
1732
+ * Bin edge positions as `Float32Array` in angstrom (A).
126
1733
  *
127
- * # Arguments
128
- * * `lengths` - Box dimensions as Float32Array with 3 elements [lx, ly, lz]
129
- * * `origin` - 3D origin vector as Float32Array with 3 elements
130
- * * `pbc_x`, `pbc_y`, `pbc_z` - Periodic boundary conditions for each axis
131
- */
132
- static ortho(lengths: Float32Array, origin: Float32Array, pbc_x: boolean, pbc_y: boolean, pbc_z: boolean): Box;
133
- /**
134
- * Get the box tilt factors as F32View [xy, xz, yz].
1734
+ * Length is `n_bins + 1` (one more than bin centers).
135
1735
  */
136
- tilts(): F32View;
1736
+ binEdges(): Float32Array;
137
1737
  /**
138
- * Convert fractional coordinates to Cartesian coordinates.
139
- *
140
- * # Arguments
141
- * * `coords` - F32View with Nx3 coordinates
142
- *
143
- * # Returns
144
- * F32View with Nx3 Cartesian coordinates
1738
+ * Raw (un-normalized) pair counts per bin as `Float32Array`.
145
1739
  */
146
- to_cart(coords: F32View): F32View;
1740
+ pairCounts(): Float32Array;
147
1741
  /**
148
- * Convert Cartesian coordinates to fractional coordinates.
149
- *
150
- * # Arguments
151
- * * `coords` - F32View with Nx3 coordinates
1742
+ * Normalized g(r) values as `Float32Array` (dimensionless).
152
1743
  *
153
- * # Returns
154
- * F32View with Nx3 fractional coordinates
1744
+ * A uniform ideal gas has g(r) = 1.0 everywhere. Peaks indicate
1745
+ * preferred interatomic distances (coordination shells).
155
1746
  */
156
- to_frac(coords: F32View): F32View;
1747
+ rdf(): Float32Array;
157
1748
  /**
158
- * Get the volume of the box.
1749
+ * Number of reference points used in the normalization.
159
1750
  */
160
- volume(): number;
1751
+ readonly numPoints: number;
161
1752
  /**
162
- * Wrap coordinates into the primary simulation box.
163
- *
164
- * # Arguments
165
- * * `coords` - F32View with Nx3 coordinates
166
- *
167
- * # Returns
168
- * F32View with Nx3 wrapped coordinates
1753
+ * Simulation box volume used in the normalization, in A^3.
169
1754
  */
170
- wrap(coords: F32View): F32View;
1755
+ readonly volume: number;
171
1756
  }
172
1757
 
173
1758
  /**
174
- * Zero-copy view over f32 array data shared between JavaScript and Rust.
175
- *
176
- * `F32View` provides a safe wrapper around f32 arrays that can be accessed from both
177
- * JavaScript and Rust without copying data. The data lives in WASM linear memory,
178
- * and JavaScript can create typed array views over this memory using `ptr()` and `len()`.
179
- *
180
- * # Memory Model
1759
+ * Reader for Zarr V3 simulation archives.
181
1760
  *
182
- * - Data is stored in `Vec<f32>` in WASM linear memory (Rust heap)
183
- * - JavaScript creates `Float32Array` views using `ptr()` and `len()`
184
- * - No copying occurs when JavaScript reads/writes via these views
185
- * - **Important**: Pointers are only valid until WASM memory grows
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.
186
1765
  *
187
- * # Safety Considerations
188
- *
189
- * - Views should be short-lived (don't store across async boundaries)
190
- * - JavaScript must not modify the underlying array while Rust holds a reference
191
- * - WASM memory can grow/relocate, invalidating pointers
192
- *
193
- * # Example
194
- *
195
- * ```javascript
196
- * // Create a view for 1000 atoms with 3D coordinates
197
- * const view = new F32View([1000, 3]);
198
- *
199
- * // Access the data from JavaScript without copying
200
- * const mem = new Float32Array(wasmMemory.buffer, view.ptr(), view.len());
201
- * mem.set([1.0, 2.0, 3.0, ...]); // Write data
1766
+ * # Example (JavaScript)
202
1767
  *
203
- * // Pass to Rust for zero-copy processing
204
- * const wrapped = box.wrap(view);
1768
+ * ```js
1769
+ * const files = new Map();
1770
+ * files.set("zarr.json", new Uint8Array([...]));
1771
+ * files.set("system/.zarray", new Uint8Array([...]));
1772
+ * // ... etc.
205
1773
  *
206
- * // Read results without copying
207
- * const result = new Float32Array(wasmMemory.buffer, wrapped.ptr(), wrapped.len());
1774
+ * const reader = new SimulationReader(files);
1775
+ * const frame = reader.readFrame(0);
208
1776
  * ```
209
1777
  */
210
- export class F32View {
1778
+ export class SimulationReader {
211
1779
  free(): void;
212
1780
  [Symbol.dispose](): void;
213
1781
  /**
214
- * Get the total number of elements in the view.
1782
+ * Return the number of atoms in the system topology.
215
1783
  *
216
- * Returns the product of all shape dimensions.
1784
+ * # Example (JavaScript)
1785
+ *
1786
+ * ```js
1787
+ * console.log(reader.countAtoms()); // e.g., 256
1788
+ * ```
217
1789
  */
218
- len(): number;
1790
+ countAtoms(): number;
219
1791
  /**
220
- * Create a new F32View with the given shape.
1792
+ * Return the number of trajectory frames in the archive.
221
1793
  *
222
- * Allocates a buffer in WASM linear memory with size = product of shape dimensions.
1794
+ * Returns `0` if no trajectory data is present.
223
1795
  *
224
- * # Arguments
1796
+ * # Errors
225
1797
  *
226
- * * `shape` - Dimensions of the array (e.g., `[1000, 3]` for Nx3 coordinates)
1798
+ * Throws a `JsValue` string on I/O errors.
227
1799
  *
228
- * # Example
1800
+ * # Example (JavaScript)
229
1801
  *
230
- * ```javascript
231
- * const view = new F32View([100, 3]); // 100 atoms, 3D coordinates
232
- * console.log(view.len()); // 300
1802
+ * ```js
1803
+ * console.log(reader.countFrames()); // e.g., 1000
233
1804
  * ```
234
1805
  */
235
- constructor(shape: Uint32Array);
1806
+ countFrames(): number;
236
1807
  /**
237
- * Get a pointer to the underlying data for zero-copy access from JavaScript.
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
238
1818
  *
239
1819
  * # Returns
240
1820
  *
241
- * A raw pointer to the first element of the data buffer.
1821
+ * A new `SimulationReader` ready to read frames.
242
1822
  *
243
- * # Safety
1823
+ * # Errors
244
1824
  *
245
- * The pointer is only valid until the next WASM memory allocation.
246
- * JavaScript should create typed array views immediately and not store the pointer.
1825
+ * Throws a `JsValue` string if the archive cannot be opened
1826
+ * (e.g., missing required metadata files).
247
1827
  *
248
- * # Example
1828
+ * # Example (JavaScript)
249
1829
  *
250
- * ```javascript
251
- * const view = new F32View([10, 3]);
252
- * const ptr = view.ptr();
253
- * const arr = new Float32Array(wasmMemory.buffer, ptr, view.len());
1830
+ * ```js
1831
+ * const reader = new SimulationReader(filesMap);
254
1832
  * ```
255
1833
  */
256
- ptr(): number;
257
- /**
258
- * Get the shape of the array (cloned for JS boundary).
259
- */
260
- shape(): Uint32Array;
1834
+ constructor(files: Map<any, any>);
261
1835
  /**
262
- * Compute the sum of all elements (for testing).
1836
+ * Read a trajectory frame at the given time index.
263
1837
  *
264
- * # Returns
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`.
265
1841
  *
266
- * Sum of all elements in the view.
267
- */
268
- sum(): number;
269
- /**
270
- * Export the view data as a JavaScript Float32Array.
1842
+ * # Arguments
271
1843
  *
272
- * Creates a new JavaScript array and copies the data.
273
- * Use this for compatibility or when you need an owned JavaScript array.
1844
+ * * `t` - Zero-based time step index
274
1845
  *
275
1846
  * # Returns
276
1847
  *
277
- * A new Float32Array containing a copy of the data.
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.
278
1854
  *
279
- * # Example
1855
+ * # Example (JavaScript)
280
1856
  *
281
- * ```javascript
282
- * const view = new F32View([2, 3]);
283
- * // ... populate view ...
284
- * const arr = view.to_js_array(); // Copies data
1857
+ * ```js
1858
+ * const frame = reader.readFrame(0);
1859
+ * if (frame) {
1860
+ * const x = frame.getBlock("atoms").copyColF32("x");
1861
+ * }
285
1862
  * ```
286
1863
  */
287
- to_js_array(): Float32Array;
1864
+ readFrame(t: number): Frame | undefined;
1865
+ }
1866
+
1867
+ /**
1868
+ * Intermediate representation of a parsed SMILES string.
1869
+ *
1870
+ * Holds the molecular graph(s) parsed from a SMILES string. A single
1871
+ * SMILES string can encode multiple disconnected molecules separated
1872
+ * by `.` (e.g., `"[Na+].[Cl-]"`).
1873
+ *
1874
+ * Call [`toFrame()`](WasmSmilesIR::to_frame) to convert to a [`Frame`]
1875
+ * with `"atoms"` and `"bonds"` blocks.
1876
+ *
1877
+ * # Example (JavaScript)
1878
+ *
1879
+ * ```js
1880
+ * const ir = parseSMILES("CCO");
1881
+ * console.log(ir.nComponents); // 1
1882
+ *
1883
+ * const frame = ir.toFrame();
1884
+ * const atoms = frame.getBlock("atoms");
1885
+ * console.log(atoms.copyColStr("symbol")); // ["C", "C", "O", "H", ...]
1886
+ * ```
1887
+ */
1888
+ export class SmilesIR {
1889
+ private constructor();
1890
+ free(): void;
1891
+ [Symbol.dispose](): void;
288
1892
  /**
289
- * Write data from a JavaScript Float32Array into this view.
1893
+ * Convert the intermediate representation to a [`Frame`].
290
1894
  *
291
- * Copies data from the JavaScript array into WASM memory once.
292
- * The array length must match the view's total size.
1895
+ * The resulting frame contains:
293
1896
  *
294
- * # Arguments
1897
+ * - `"atoms"` block: `symbol` (string), and implicit hydrogens
1898
+ * are added. No 3D coordinates are present -- use
1899
+ * [`generate3D`](crate::generate_3d_wasm) to embed coordinates.
1900
+ * - `"bonds"` block: `i`, `j` (u32, zero-based atom indices),
1901
+ * `order` (f32, bond order: 1.0 = single, 1.5 = aromatic,
1902
+ * 2.0 = double, 3.0 = triple).
295
1903
  *
296
- * * `arr` - JavaScript Float32Array to copy from
1904
+ * # Returns
1905
+ *
1906
+ * A new [`Frame`] with atoms and bonds.
297
1907
  *
298
1908
  * # Errors
299
1909
  *
300
- * Returns an error if the array length doesn't match the view size.
1910
+ * Throws a `JsValue` string if the conversion fails (e.g.,
1911
+ * invalid valence).
301
1912
  *
302
- * # Example
1913
+ * # Example (JavaScript)
303
1914
  *
304
- * ```javascript
305
- * const view = new F32View([2, 3]);
306
- * const data = new Float32Array([1, 2, 3, 4, 5, 6]);
307
- * view.write_from(data);
1915
+ * ```js
1916
+ * const frame = ir.toFrame();
1917
+ * const bonds = frame.getBlock("bonds");
1918
+ * const order = bonds.copyColF32("order");
308
1919
  * ```
309
1920
  */
310
- write_from(arr: Float32Array): void;
1921
+ toFrame(): Frame;
1922
+ /**
1923
+ * Return the number of disconnected components in the SMILES.
1924
+ *
1925
+ * Components are separated by `.` in the SMILES string. For
1926
+ * example, `"[Na+].[Cl-]"` has 2 components.
1927
+ *
1928
+ * # Example (JavaScript)
1929
+ *
1930
+ * ```js
1931
+ * const ir = parseSMILES("[Na+].[Cl-]");
1932
+ * console.log(ir.nComponents); // 2
1933
+ * ```
1934
+ */
1935
+ readonly nComponents: number;
311
1936
  }
312
1937
 
313
1938
  /**
314
- * A frame that contains blocks of data.
1939
+ * Owned f32 array with ndarray-compatible shape metadata.
1940
+ *
1941
+ * Stores a flat `Vec<f32>` together with a shape descriptor (e.g.,
1942
+ * `[N, 3]` for an Nx3 coordinate matrix). Used for passing
1943
+ * multi-dimensional numeric data across the WASM boundary.
1944
+ *
1945
+ * # Memory layout
1946
+ *
1947
+ * Data is stored in row-major (C) order, matching ndarray's default
1948
+ * and JavaScript's `Float32Array` convention.
1949
+ *
1950
+ * # Example (JavaScript)
1951
+ *
1952
+ * ```js
1953
+ * // Create a 2x3 zero array
1954
+ * const arr = new WasmArray([2, 3]);
1955
+ * arr.writeFrom(new Float32Array([1,2,3, 4,5,6]));
1956
+ *
1957
+ * // Or from existing data
1958
+ * const arr2 = WasmArray.from(new Float32Array([1,2,3]), [1, 3]);
1959
+ *
1960
+ * // Get data back
1961
+ * const copy = arr.toCopy(); // safe owned copy
1962
+ * const view = arr.toTypedArray(); // zero-copy (invalidated on alloc)
1963
+ * ```
315
1964
  */
316
- export class Frame {
1965
+ export class WasmArray {
317
1966
  free(): void;
318
1967
  [Symbol.dispose](): void;
319
1968
  /**
320
- * Clears all blocks from the frame.
1969
+ * Return the data type string. Always `"float"` for `WasmArray`.
321
1970
  */
322
- clear(): void;
1971
+ dtype(): string;
323
1972
  /**
324
- * Creates a new block in this frame.
1973
+ * Create a `WasmArray` from an existing JS `Float32Array`.
1974
+ *
1975
+ * # Arguments
1976
+ *
1977
+ * * `data` - Source `Float32Array`
1978
+ * * `shape` - Optional shape. If omitted, defaults to `[data.length]` (1D).
1979
+ *
1980
+ * # Returns
1981
+ *
1982
+ * A new `WasmArray` owning a copy of the data.
1983
+ *
1984
+ * # Errors
1985
+ *
1986
+ * Throws if `shape` product does not equal `data.length`.
1987
+ *
1988
+ * # Example (JavaScript)
1989
+ *
1990
+ * ```js
1991
+ * const arr = WasmArray.from(new Float32Array([1,2,3,4,5,6]), [2, 3]);
1992
+ * console.log(arr.shape()); // [2, 3]
1993
+ * ```
325
1994
  */
326
- createBlock(key: string): Block;
1995
+ static from(data: Float32Array, shape?: Uint32Array | null): WasmArray;
327
1996
  /**
328
- * Drops this frame from the store.
1997
+ * Check whether the array contains no elements.
329
1998
  */
330
- drop(): void;
1999
+ is_empty(): boolean;
331
2000
  /**
332
- * Gets an existing block by key.
2001
+ * Return the total number of elements (product of all shape dimensions).
2002
+ *
2003
+ * # Example (JavaScript)
2004
+ *
2005
+ * ```js
2006
+ * const arr = new WasmArray([10, 3]);
2007
+ * console.log(arr.len()); // 30
2008
+ * ```
333
2009
  */
334
- getBlock(key: string): Block | undefined;
2010
+ len(): number;
335
2011
  /**
336
- * Inserts a block into the frame (takes ownership).
2012
+ * Create a zero-initialized array with the given shape.
2013
+ *
2014
+ * The total number of elements is the product of all dimensions.
2015
+ *
2016
+ * # Arguments
2017
+ *
2018
+ * * `shape` - Array of dimension sizes (e.g., `[10, 3]` for 10 rows x 3 columns)
2019
+ *
2020
+ * # Example (JavaScript)
2021
+ *
2022
+ * ```js
2023
+ * const coords = new WasmArray([100, 3]); // 100 atoms, 3D
2024
+ * console.log(coords.len()); // 300
2025
+ * ```
337
2026
  */
338
- insertBlock(key: string, block: Block): void;
2027
+ constructor(shape: Uint32Array);
339
2028
  /**
340
- * Creates a new Frame.
2029
+ * Return a raw pointer to the underlying data buffer.
2030
+ *
2031
+ * This is intended for advanced interop with other WASM modules
2032
+ * that need direct memory access. The pointer is only valid as
2033
+ * long as this `WasmArray` is alive and no WASM memory growth
2034
+ * has occurred.
341
2035
  */
342
- constructor();
2036
+ ptr(): number;
343
2037
  /**
344
- * Removes a block from the frame.
2038
+ * Return a copy of the shape metadata as a JS array.
2039
+ *
2040
+ * # Example (JavaScript)
2041
+ *
2042
+ * ```js
2043
+ * const s = arr.shape(); // e.g., [10, 3]
2044
+ * ```
345
2045
  */
346
- removeBlock(key: string): void;
2046
+ shape(): Uint32Array;
347
2047
  /**
348
- * Renames a block in the frame.
2048
+ * Compute the sum of all elements.
2049
+ *
2050
+ * Primarily useful for quick sanity checks and testing.
2051
+ *
2052
+ * # Example (JavaScript)
2053
+ *
2054
+ * ```js
2055
+ * const arr = WasmArray.from(new Float32Array([1, 2, 3]));
2056
+ * console.log(arr.sum()); // 6.0
2057
+ * ```
349
2058
  */
350
- renameBlock(old_key: string, new_key: string): boolean;
2059
+ sum(): number;
351
2060
  /**
352
- * Renames a column in the specified block.
2061
+ * Create an owned JS `Float32Array` copy of the data.
2062
+ *
2063
+ * The returned array is an independent copy that is safe to store
2064
+ * and use regardless of subsequent WASM memory operations.
2065
+ *
2066
+ * # Example (JavaScript)
2067
+ *
2068
+ * ```js
2069
+ * const copy = arr.toCopy(); // safe to keep indefinitely
2070
+ * ```
353
2071
  */
354
- renameColumn(block_key: string, old_col_key: string, new_col_key: string): boolean;
2072
+ toCopy(): Float32Array;
355
2073
  /**
356
- * Gets the simulation box (if any).
2074
+ * Zero-copy `Float32Array` view over this array's backing storage.
2075
+ *
2076
+ * **Warning**: The returned view becomes **invalid** if WASM linear
2077
+ * memory grows (due to any allocation). Use [`toCopy`](WasmArray::to_copy)
2078
+ * if you need to keep the data.
2079
+ *
2080
+ * # Safety (internal)
2081
+ *
2082
+ * Uses `Float32Array::view` which creates an unowned view into
2083
+ * WASM memory. The view must not outlive the `WasmArray` and must
2084
+ * not be used after any allocation that could trigger memory growth.
2085
+ *
2086
+ * # Example (JavaScript)
2087
+ *
2088
+ * ```js
2089
+ * const view = arr.toTypedArray(); // use immediately
2090
+ * // Do NOT allocate between view creation and use
2091
+ * ```
357
2092
  */
358
- get simbox(): Box | undefined;
2093
+ toTypedArray(): Float32Array;
359
2094
  /**
360
- * Sets the simulation box.
2095
+ * Overwrite the array contents from a JS `Float32Array`.
2096
+ *
2097
+ * The source array must have exactly the same number of elements
2098
+ * as this `WasmArray` (i.e., the shape is preserved).
2099
+ *
2100
+ * # Arguments
2101
+ *
2102
+ * * `arr` - Source `Float32Array` with matching length
2103
+ *
2104
+ * # Errors
2105
+ *
2106
+ * Throws if `arr.length` does not match this array's element count.
2107
+ *
2108
+ * # Example (JavaScript)
2109
+ *
2110
+ * ```js
2111
+ * const wa = new WasmArray([3]);
2112
+ * wa.writeFrom(new Float32Array([1.0, 2.0, 3.0]));
2113
+ * ```
361
2114
  */
362
- set simbox(value: Box | null | undefined);
2115
+ write_from(arr: Float32Array): void;
363
2116
  }
364
2117
 
365
2118
  /**
366
- * LAMMPS data file reader for WASM
2119
+ * XYZ / Extended XYZ file reader.
2120
+ *
2121
+ * Supports multi-frame trajectory files. Each frame produces a
2122
+ * [`Frame`] with an `"atoms"` block containing `element` (string)
2123
+ * and `x`, `y`, `z` (f32, coordinates in angstrom) columns.
367
2124
  *
368
2125
  * # Example (JavaScript)
2126
+ *
369
2127
  * ```js
370
- * const reader = new LammpsReader(fileContent);
371
- * const frame = reader.read(0);
2128
+ * const content = await file.text(); // read file in browser
2129
+ * const reader = new XYZReader(content);
2130
+ * console.log(reader.len()); // number of frames
2131
+ *
2132
+ * const frame = reader.read(0); // first frame
2133
+ * const atoms = frame.getBlock("atoms");
2134
+ * const x = atoms.copyColF32("x");
372
2135
  * ```
373
2136
  */
374
- export class LammpsReader {
2137
+ export class XYZReader {
375
2138
  free(): void;
376
2139
  [Symbol.dispose](): void;
377
2140
  /**
378
- * Returns the number of frames (always 1 for LAMMPS).
379
- * @returns {number}
2141
+ * Check whether the file contains no frames.
2142
+ *
2143
+ * # Errors
2144
+ *
2145
+ * Throws a `JsValue` string if the file cannot be scanned.
380
2146
  */
381
- len(): number;
382
- constructor(content: string);
2147
+ isEmpty(): boolean;
383
2148
  /**
384
- * Reads a frame at the given step.
385
- * @param {number} step - Frame index (LAMMPS only supports single frame, so only step=0 is valid)
386
- * @returns {Frame | undefined}
2149
+ * Return the number of frames in the file.
2150
+ *
2151
+ * # Returns
2152
+ *
2153
+ * The total frame count.
2154
+ *
2155
+ * # Errors
2156
+ *
2157
+ * Throws a `JsValue` string if the file cannot be scanned.
2158
+ *
2159
+ * # Example (JavaScript)
2160
+ *
2161
+ * ```js
2162
+ * console.log(reader.len()); // e.g., 100
2163
+ * ```
387
2164
  */
388
- read(step: number): Frame | undefined;
389
- }
390
-
391
- /**
392
- * PDB file reader for WASM
393
- *
394
- * # Example (JavaScript)
395
- * ```js
396
- * const reader = new PdbReader(fileContent);
397
- * const frame = reader.read(0);
398
- * ```
399
- */
400
- export class PdbReader {
401
- free(): void;
402
- [Symbol.dispose](): void;
2165
+ len(): number;
403
2166
  /**
404
- * Returns the number of frames (always 1 for PDB).
405
- * @returns {number}
2167
+ * Create a new XYZ reader from a string containing the file content.
2168
+ *
2169
+ * # Arguments
2170
+ *
2171
+ * * `content` - The full text content of an XYZ or Extended XYZ file
2172
+ *
2173
+ * # Example (JavaScript)
2174
+ *
2175
+ * ```js
2176
+ * const reader = new XYZReader(fileContent);
2177
+ * ```
406
2178
  */
407
- len(): number;
408
2179
  constructor(content: string);
409
2180
  /**
410
- * Reads a frame at the given step.
411
- * @param {number} step - Frame index (PDB only supports single frame, so only step=0 is valid)
412
- * @returns {Frame | undefined}
2181
+ * Read a frame at the given step index.
2182
+ *
2183
+ * # Arguments
2184
+ *
2185
+ * * `step` - Zero-based frame index
2186
+ *
2187
+ * # Returns
2188
+ *
2189
+ * A [`Frame`] if the step exists, or `undefined` if `step` is
2190
+ * out of range.
2191
+ *
2192
+ * # Errors
2193
+ *
2194
+ * Throws a `JsValue` string on parse errors.
2195
+ *
2196
+ * # Example (JavaScript)
2197
+ *
2198
+ * ```js
2199
+ * const frame = reader.read(0);
2200
+ * if (frame) {
2201
+ * const atoms = frame.getBlock("atoms");
2202
+ * }
2203
+ * ```
413
2204
  */
414
2205
  read(step: number): Frame | undefined;
415
2206
  }
416
2207
 
417
2208
  /**
418
- * XYZ/ExtXYZ file reader for WASM
2209
+ * Generate 3D coordinates for a molecular [`Frame`].
2210
+ *
2211
+ * The input frame must have an `"atoms"` block with a `"symbol"`
2212
+ * string column (element symbols like `"C"`, `"N"`, `"O"`). A
2213
+ * `"bonds"` block with `i`, `j` (u32) and `order` (f32) columns
2214
+ * is required for correct geometry.
2215
+ *
2216
+ * Returns a **new** [`Frame`] with 3D coordinates added as `x`, `y`,
2217
+ * `z` (f32, angstrom) columns in the `"atoms"` block.
2218
+ *
2219
+ * # Arguments
2220
+ *
2221
+ * * `frame` - Input molecular frame with atoms and bonds (from
2222
+ * [`parseSMILES`](crate::parse_smiles) or file readers)
2223
+ * * `speed` - Quality/speed preset:
2224
+ * - `"fast"` -- minimal refinement, suitable for visualization
2225
+ * - `"medium"` (default) -- balanced quality/speed
2226
+ * - `"better"` -- thorough conformer search, best geometry
2227
+ * * `seed` - Optional RNG seed (`u32`) for reproducibility. If
2228
+ * omitted, a random seed is used.
2229
+ *
2230
+ * # Returns
2231
+ *
2232
+ * A new [`Frame`] with 3D coordinates. The original frame is
2233
+ * not modified.
2234
+ *
2235
+ * # Errors
2236
+ *
2237
+ * Throws a `JsValue` string if:
2238
+ * - The frame has no `"atoms"` block or is missing required columns
2239
+ * - The molecular graph has invalid valences or topology
2240
+ * - The 3D embedding fails to converge
419
2241
  *
420
2242
  * # Example (JavaScript)
2243
+ *
421
2244
  * ```js
422
- * const reader = new XyzReader(fileContent);
423
- * const frame = reader.read(0);
2245
+ * const ir = parseSMILES("c1ccccc1"); // benzene
2246
+ * const frame2d = ir.toFrame();
2247
+ * const frame3d = generate3D(frame2d, "fast", 42);
2248
+ *
2249
+ * 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");
424
2253
  * ```
425
2254
  */
426
- export class XyzReader {
427
- free(): void;
428
- [Symbol.dispose](): void;
429
- /**
430
- * Returns the number of frames in the file.
431
- * @returns {number}
432
- */
433
- len(): number;
434
- constructor(content: string);
435
- /**
436
- * Reads a frame at the given step.
437
- * @param {number} step - Frame index
438
- * @returns {Frame | undefined}
439
- */
440
- read(step: number): Frame | undefined;
441
- }
2255
+ export function generate3D(frame: Frame, speed?: string | null, seed?: number | null): Frame;
442
2256
 
443
2257
  /**
444
- * Writes a frame to a string in the specified format.
2258
+ * Parse a SMILES notation string into an intermediate representation.
2259
+ *
2260
+ * Supports standard SMILES features including ring closures,
2261
+ * branching, stereochemistry markers, and aromatic atoms.
2262
+ *
2263
+ * # Arguments
2264
+ *
2265
+ * * `smiles` - SMILES notation string (e.g., `"CCO"` for ethanol,
2266
+ * `"c1ccccc1"` for benzene, `"[Na+].[Cl-]"` for NaCl)
2267
+ *
2268
+ * # Returns
2269
+ *
2270
+ * A [`SmilesIR`](WasmSmilesIR) object. Call `.toFrame()` to convert
2271
+ * to a [`Frame`] with atoms and bonds blocks.
2272
+ *
2273
+ * # Errors
2274
+ *
2275
+ * Throws a `JsValue` string if the SMILES string is malformed
2276
+ * (e.g., unmatched ring closure digits, invalid atom symbols).
445
2277
  *
446
2278
  * # Example (JavaScript)
2279
+ *
447
2280
  * ```js
448
- * const output = writeFrame(frame, "xyz");
449
- * console.log(output); // XYZ format string
2281
+ * const ir = parseSMILES("CCO");
2282
+ * const frame = ir.toFrame();
2283
+ * const mol3d = generate3D(frame, "fast");
450
2284
  * ```
451
- *
452
- * @param {Frame} frame - Frame to write
453
- * @param {string} format - Output format ("xyz" or "pdb")
454
- * @returns {string} Formatted output
455
2285
  */
456
- export function writeFrame(frame: Frame, format: string): string;
457
-
458
- export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
2286
+ export function parseSMILES(smiles: string): SmilesIR;
459
2287
 
460
- export interface InitOutput {
461
- readonly memory: WebAssembly.Memory;
462
- readonly __wbg_block_free: (a: number, b: number) => void;
463
- readonly __wbg_frame_free: (a: number, b: number) => void;
464
- readonly block_getColumnF32: (a: number, b: number, c: number) => [number, number, number];
465
- readonly block_getColumnF32WithShape: (a: number, b: number, c: number) => [number, number, number];
466
- readonly block_getColumnI64: (a: number, b: number, c: number) => [number, number, number];
467
- readonly block_getColumnStrings: (a: number, b: number, c: number) => any;
468
- readonly block_getColumnU32: (a: number, b: number, c: number) => [number, number, number];
469
- readonly block_getColumnU8: (a: number, b: number, c: number) => any;
470
- readonly block_keys: (a: number) => [number, number, number];
471
- readonly block_len: (a: number) => [number, number, number];
472
- readonly block_new: () => number;
473
- readonly block_nrows: (a: number) => [number, number, number];
474
- readonly block_renameColumn: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
475
- readonly block_setColumnF32: (a: number, b: number, c: number, d: any, e: number) => [number, number];
476
- readonly block_setColumnI64: (a: number, b: number, c: number, d: any, e: number) => [number, number];
477
- readonly block_setColumnStrings: (a: number, b: number, c: number, d: any, e: number) => [number, number];
478
- readonly block_setColumnU32: (a: number, b: number, c: number, d: any, e: number) => [number, number];
479
- readonly block_setColumnU8: (a: number, b: number, c: number, d: any, e: number) => [number, number];
480
- readonly frame_clear: (a: number) => [number, number];
481
- readonly frame_createBlock: (a: number, b: number, c: number) => [number, number, number];
482
- readonly frame_drop: (a: number) => [number, number];
483
- readonly frame_getBlock: (a: number, b: number, c: number) => number;
484
- readonly frame_insertBlock: (a: number, b: number, c: number, d: number) => [number, number];
485
- readonly frame_new: () => number;
486
- readonly frame_removeBlock: (a: number, b: number, c: number) => [number, number];
487
- readonly frame_renameBlock: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
488
- readonly frame_renameColumn: (a: number, b: number, c: number, d: number, e: number, f: number, g: number) => [number, number, number];
489
- readonly frame_set_simbox: (a: number, b: number) => void;
490
- readonly frame_simbox: (a: number) => number;
491
- readonly __wbg_f32view_free: (a: number, b: number) => void;
492
- readonly f32view_len: (a: number) => number;
493
- readonly f32view_new: (a: number, b: number) => number;
494
- readonly f32view_ptr: (a: number) => number;
495
- readonly f32view_shape: (a: number) => [number, number];
496
- readonly f32view_sum: (a: number) => number;
497
- readonly f32view_to_js_array: (a: number) => any;
498
- readonly f32view_write_from: (a: number, b: any) => [number, number];
499
- readonly __wbg_lammpsreader_free: (a: number, b: number) => void;
500
- readonly __wbg_pdbreader_free: (a: number, b: number) => void;
501
- readonly __wbg_xyzreader_free: (a: number, b: number) => void;
502
- readonly lammpsreader_len: (a: number) => [number, number, number];
503
- readonly lammpsreader_new: (a: number, b: number) => number;
504
- readonly lammpsreader_read: (a: number, b: number) => [number, number, number];
505
- readonly pdbreader_len: (a: number) => [number, number, number];
506
- readonly pdbreader_new: (a: number, b: number) => number;
507
- readonly pdbreader_read: (a: number, b: number) => [number, number, number];
508
- readonly xyzreader_len: (a: number) => [number, number, number];
509
- readonly xyzreader_new: (a: number, b: number) => number;
510
- readonly xyzreader_read: (a: number, b: number) => [number, number, number];
511
- readonly __wbg_box_free: (a: number, b: number) => void;
512
- readonly box_cube: (a: number, b: any, c: number, d: number, e: number) => [number, number, number];
513
- readonly box_delta: (a: number, b: number, c: number, d: number) => [number, number, number];
514
- readonly box_get_corners: (a: number) => number;
515
- readonly box_lengths: (a: number) => number;
516
- readonly box_new: (a: any, b: any, c: number, d: number, e: number) => [number, number, number];
517
- readonly box_origin: (a: number) => number;
518
- readonly box_ortho: (a: any, b: any, c: number, d: number, e: number) => [number, number, number];
519
- readonly box_tilts: (a: number) => number;
520
- readonly box_to_cart: (a: number, b: number) => [number, number, number];
521
- readonly box_to_frac: (a: number, b: number) => [number, number, number];
522
- readonly box_volume: (a: number) => number;
523
- readonly box_wrap: (a: number, b: number) => [number, number, number];
524
- readonly writeFrame: (a: number, b: number, c: number) => [number, number, number, number];
525
- readonly __wbindgen_malloc: (a: number, b: number) => number;
526
- readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
527
- readonly __wbindgen_exn_store: (a: number) => void;
528
- readonly __externref_table_alloc: () => number;
529
- readonly __wbindgen_externrefs: WebAssembly.Table;
530
- readonly __externref_table_dealloc: (a: number) => void;
531
- readonly __wbindgen_free: (a: number, b: number, c: number) => void;
532
- readonly __wbindgen_start: () => void;
533
- }
534
-
535
- export type SyncInitInput = BufferSource | WebAssembly.Module;
2288
+ /**
2289
+ * WASM module entry point. Installs the panic hook so that Rust panics
2290
+ * are forwarded to the browser console as readable stack traces.
2291
+ */
2292
+ export function start(): void;
536
2293
 
537
2294
  /**
538
- * Instantiates the given `module`, which can either be bytes or
539
- * a precompiled `WebAssembly.Module`.
2295
+ * Return a handle to the WASM linear memory.
540
2296
  *
541
- * @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
2297
+ * Useful for advanced interop where JS code needs direct access to the
2298
+ * WASM memory buffer (e.g., for zero-copy typed-array views).
542
2299
  *
543
- * @returns {InitOutput}
2300
+ * # Example (JavaScript)
2301
+ *
2302
+ * ```js
2303
+ * const mem = wasmMemory();
2304
+ * const buf = new Float32Array(mem.buffer, ptr, len);
2305
+ * ```
544
2306
  */
545
- export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
2307
+ export function wasmMemory(): WebAssembly.Memory;
546
2308
 
547
2309
  /**
548
- * If `module_or_path` is {RequestInfo} or {URL}, makes a request and
549
- * for everything else, calls `WebAssembly.instantiate` directly.
2310
+ * Serialize a [`Frame`] to a string in the specified format.
2311
+ *
2312
+ * The frame must have an `"atoms"` block with at least an element/name
2313
+ * string column and `x`, `y`, `z` float columns (coordinates in
2314
+ * angstrom).
2315
+ *
2316
+ * # Arguments
2317
+ *
2318
+ * * `frame` - The [`Frame`] to write
2319
+ * * `format` - Output format string: `"xyz"` or `"pdb"`
2320
+ * (case-insensitive)
2321
+ *
2322
+ * # Returns
550
2323
  *
551
- * @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
2324
+ * The formatted file content as a string.
552
2325
  *
553
- * @returns {Promise<InitOutput>}
2326
+ * # Errors
2327
+ *
2328
+ * Throws a `JsValue` string if:
2329
+ * - The format is not recognized
2330
+ * - The frame is missing required columns
2331
+ * - The writer encounters an error
2332
+ *
2333
+ * # Example (JavaScript)
2334
+ *
2335
+ * ```js
2336
+ * const xyzStr = writeFrame(frame, "xyz");
2337
+ * console.log(xyzStr);
2338
+ * // 2
2339
+ * //
2340
+ * // H 0.000000 0.000000 0.000000
2341
+ * // O 1.000000 0.000000 0.500000
2342
+ *
2343
+ * const pdbStr = writeFrame(frame, "pdb");
2344
+ * // download or display the PDB string
2345
+ * ```
554
2346
  */
555
- export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
2347
+ export function writeFrame(frame: Frame, format: string): string;