@molcrafts/molrs 0.0.1 → 0.0.4

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_bg.js ADDED
@@ -0,0 +1,4017 @@
1
+ /**
2
+ * Axis-aligned bounding box spatial query for neighbor search.
3
+ *
4
+ * Builds a cell-list spatial index from a [`Frame`]'s atom positions
5
+ * and simulation box, then supports both self-queries (unique pairs
6
+ * within the reference set) and cross-queries (pairs between a
7
+ * query set and the reference set).
8
+ *
9
+ * All distances are in angstrom (A).
10
+ *
11
+ * # Example (JavaScript)
12
+ *
13
+ * ```js
14
+ * const nq = new AABBQuery(frame, 3.0); // cutoff = 3.0 A
15
+ * const selfPairs = nq.querySelf(); // unique pairs (i < j)
16
+ * const crossPairs = nq.query(otherFrame); // cross-query
17
+ *
18
+ * console.log(selfPairs.numPairs);
19
+ * ```
20
+ */
21
+ export class AABBQuery {
22
+ __destroy_into_raw() {
23
+ const ptr = this.__wbg_ptr;
24
+ this.__wbg_ptr = 0;
25
+ AABBQueryFinalization.unregister(this);
26
+ return ptr;
27
+ }
28
+ free() {
29
+ const ptr = this.__destroy_into_raw();
30
+ wasm.__wbg_aabbquery_free(ptr, 0);
31
+ }
32
+ /**
33
+ * Create a spatial query from a [`Frame`] with a given distance cutoff.
34
+ *
35
+ * The frame must have:
36
+ * - An `"atoms"` block with `x`, `y`, `z` (f32) columns
37
+ * - A `simbox` (simulation box) set on the frame
38
+ *
39
+ * # Arguments
40
+ *
41
+ * * `frame` - Reference frame with atom positions and simbox
42
+ * * `cutoff` - Maximum neighbor distance in angstrom (A)
43
+ *
44
+ * # Returns
45
+ *
46
+ * A new `AABBQuery` ready for `query()` or `querySelf()`.
47
+ *
48
+ * # Errors
49
+ *
50
+ * Throws if the frame has no `"atoms"` block, is missing `x`/`y`/`z`
51
+ * columns, or has no `simbox`.
52
+ *
53
+ * # Example (JavaScript)
54
+ *
55
+ * ```js
56
+ * const nq = new AABBQuery(frame, 5.0);
57
+ * ```
58
+ * @param {Frame} frame
59
+ * @param {number} cutoff
60
+ */
61
+ constructor(frame, cutoff) {
62
+ _assertClass(frame, Frame);
63
+ const ret = wasm.aabbquery_new(frame.__wbg_ptr, cutoff);
64
+ if (ret[2]) {
65
+ throw takeFromExternrefTable0(ret[1]);
66
+ }
67
+ this.__wbg_ptr = ret[0] >>> 0;
68
+ AABBQueryFinalization.register(this, this.__wbg_ptr, this);
69
+ return this;
70
+ }
71
+ /**
72
+ * Cross-query: find all pairs where `i` indexes query points and
73
+ * `j` indexes the reference points (from the constructor frame).
74
+ *
75
+ * # Arguments
76
+ *
77
+ * * `query_frame` - Frame with query atom positions (must have
78
+ * `"atoms"` block with `x`, `y`, `z` columns)
79
+ *
80
+ * # Returns
81
+ *
82
+ * A [`NeighborList`] containing all `(i, j, distance)` pairs
83
+ * within the cutoff.
84
+ *
85
+ * # Errors
86
+ *
87
+ * Throws if `query_frame` is missing required columns.
88
+ *
89
+ * # Example (JavaScript)
90
+ *
91
+ * ```js
92
+ * const crossPairs = nq.query(otherFrame);
93
+ * console.log(crossPairs.numPairs);
94
+ * ```
95
+ * @param {Frame} query_frame
96
+ * @returns {NeighborList}
97
+ */
98
+ query(query_frame) {
99
+ _assertClass(query_frame, Frame);
100
+ const ret = wasm.aabbquery_query(this.__wbg_ptr, query_frame.__wbg_ptr);
101
+ if (ret[2]) {
102
+ throw takeFromExternrefTable0(ret[1]);
103
+ }
104
+ return NeighborList.__wrap(ret[0]);
105
+ }
106
+ /**
107
+ * Self-query: find all unique pairs `(i < j)` within the reference
108
+ * point set (the frame used to construct this query).
109
+ *
110
+ * # Returns
111
+ *
112
+ * A [`NeighborList`] containing all unique pairs within the cutoff.
113
+ * The `isSelfQuery` property will be `true`.
114
+ *
115
+ * # Example (JavaScript)
116
+ *
117
+ * ```js
118
+ * const pairs = nq.querySelf();
119
+ * console.log(pairs.isSelfQuery); // true
120
+ * console.log(pairs.numPairs); // number of unique pairs
121
+ * ```
122
+ * @returns {NeighborList}
123
+ */
124
+ querySelf() {
125
+ const ret = wasm.aabbquery_querySelf(this.__wbg_ptr);
126
+ return NeighborList.__wrap(ret);
127
+ }
128
+ }
129
+ if (Symbol.dispose) AABBQuery.prototype[Symbol.dispose] = AABBQuery.prototype.free;
130
+
131
+ /**
132
+ * Column-oriented data store with typed arrays.
133
+ *
134
+ * Each column is identified by a string key and has a fixed data type
135
+ * (`f32`, `i32`, `u32`, `string`). All columns in a block must have
136
+ * the same number of rows.
137
+ *
138
+ * # Supported column types
139
+ *
140
+ * | JS type | Rust type | dtype string | Setter | Getter (copy) | Getter (view) |
141
+ * |---------|-----------|-------------|--------|---------------|---------------|
142
+ * | `Float32Array` | `f32` | `"f32"` | `setColF32` | `copyColF32` | `viewColF32` |
143
+ * | `Int32Array` | `i32` | `"i32"` | `setColI32` | `copyColI32` | `viewColI32` |
144
+ * | `Uint32Array` | `u32` | `"u32"` | `setColU32` | `copyColU32` | `viewColU32` |
145
+ * | `Array<string>` | `String` | `"string"` | `setColStr` | `copyColStr` | -- |
146
+ *
147
+ * # Example (JavaScript)
148
+ *
149
+ * ```js
150
+ * const block = new Block();
151
+ * block.setColF32("x", new Float32Array([1.0, 2.0, 3.0]));
152
+ * block.setColF32("y", new Float32Array([0.0, 0.0, 0.0]));
153
+ * console.log(block.nrows()); // 3
154
+ * console.log(block.keys()); // ["x", "y"]
155
+ *
156
+ * const x = block.copyColF32("x"); // owned copy, safe to keep
157
+ * ```
158
+ */
159
+ export class Block {
160
+ static __wrap(ptr) {
161
+ ptr = ptr >>> 0;
162
+ const obj = Object.create(Block.prototype);
163
+ obj.__wbg_ptr = ptr;
164
+ BlockFinalization.register(obj, obj.__wbg_ptr, obj);
165
+ return obj;
166
+ }
167
+ __destroy_into_raw() {
168
+ const ptr = this.__wbg_ptr;
169
+ this.__wbg_ptr = 0;
170
+ BlockFinalization.unregister(this);
171
+ return ptr;
172
+ }
173
+ free() {
174
+ const ptr = this.__destroy_into_raw();
175
+ wasm.__wbg_block_free(ptr, 0);
176
+ }
177
+ /**
178
+ * Owned `Float32Array` copy of a column.
179
+ *
180
+ * Returns a new JS `Float32Array` that is an independent copy of
181
+ * the column data. Safe to store and use across allocations.
182
+ *
183
+ * # Arguments
184
+ *
185
+ * * `key` - Column name
186
+ *
187
+ * # Returns
188
+ *
189
+ * An owned `Float32Array` copy of the column.
190
+ *
191
+ * # Errors
192
+ *
193
+ * Throws if the column does not exist or is not of type `f32`.
194
+ *
195
+ * # Example (JavaScript)
196
+ *
197
+ * ```js
198
+ * const x = block.copyColF32("x");
199
+ * console.log(x[0]); // 1.0
200
+ * ```
201
+ * @param {string} key
202
+ * @returns {Float32Array}
203
+ */
204
+ copyColF32(key) {
205
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
206
+ const len0 = WASM_VECTOR_LEN;
207
+ const ret = wasm.block_copyColF32(this.__wbg_ptr, ptr0, len0);
208
+ if (ret[2]) {
209
+ throw takeFromExternrefTable0(ret[1]);
210
+ }
211
+ return takeFromExternrefTable0(ret[0]);
212
+ }
213
+ /**
214
+ * Owned `Int32Array` copy of a column.
215
+ *
216
+ * # Arguments
217
+ *
218
+ * * `key` - Column name
219
+ *
220
+ * # Errors
221
+ *
222
+ * Throws if the column does not exist or is not of type `i32`.
223
+ *
224
+ * # Example (JavaScript)
225
+ *
226
+ * ```js
227
+ * const types = block.copyColI32("type_id");
228
+ * ```
229
+ * @param {string} key
230
+ * @returns {Int32Array}
231
+ */
232
+ copyColI32(key) {
233
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
234
+ const len0 = WASM_VECTOR_LEN;
235
+ const ret = wasm.block_copyColI32(this.__wbg_ptr, ptr0, len0);
236
+ if (ret[2]) {
237
+ throw takeFromExternrefTable0(ret[1]);
238
+ }
239
+ return takeFromExternrefTable0(ret[0]);
240
+ }
241
+ /**
242
+ * Owned `Array<string>` copy of a string column.
243
+ *
244
+ * # Arguments
245
+ *
246
+ * * `key` - Column name
247
+ *
248
+ * # Returns
249
+ *
250
+ * A JS `Array` of strings.
251
+ *
252
+ * # Errors
253
+ *
254
+ * Throws if the column does not exist or is not of type `string`.
255
+ *
256
+ * # Example (JavaScript)
257
+ *
258
+ * ```js
259
+ * const symbols = block.copyColStr("symbol"); // ["C", "C", "O"]
260
+ * ```
261
+ * @param {string} key
262
+ * @returns {Array<any>}
263
+ */
264
+ copyColStr(key) {
265
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
266
+ const len0 = WASM_VECTOR_LEN;
267
+ const ret = wasm.block_copyColStr(this.__wbg_ptr, ptr0, len0);
268
+ if (ret[2]) {
269
+ throw takeFromExternrefTable0(ret[1]);
270
+ }
271
+ return takeFromExternrefTable0(ret[0]);
272
+ }
273
+ /**
274
+ * Owned `Uint32Array` copy of a column.
275
+ *
276
+ * # Arguments
277
+ *
278
+ * * `key` - Column name
279
+ *
280
+ * # Errors
281
+ *
282
+ * Throws if the column does not exist or is not of type `u32`.
283
+ *
284
+ * # Example (JavaScript)
285
+ *
286
+ * ```js
287
+ * const bondI = block.copyColU32("i");
288
+ * const bondJ = block.copyColU32("j");
289
+ * ```
290
+ * @param {string} key
291
+ * @returns {Uint32Array}
292
+ */
293
+ copyColU32(key) {
294
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
295
+ const len0 = WASM_VECTOR_LEN;
296
+ const ret = wasm.block_copyColU32(this.__wbg_ptr, ptr0, len0);
297
+ if (ret[2]) {
298
+ throw takeFromExternrefTable0(ret[1]);
299
+ }
300
+ return takeFromExternrefTable0(ret[0]);
301
+ }
302
+ /**
303
+ * Return the data type string for a column.
304
+ *
305
+ * Possible return values: `"f32"`, `"i32"`, `"u32"`, `"bool"`,
306
+ * `"string"`, `"u8"`. Returns `undefined` if the column does
307
+ * not exist.
308
+ *
309
+ * # Arguments
310
+ *
311
+ * * `key` - Column name
312
+ *
313
+ * # Returns
314
+ *
315
+ * The dtype string, or `undefined` if the column is not found.
316
+ *
317
+ * # Example (JavaScript)
318
+ *
319
+ * ```js
320
+ * console.log(block.dtype("x")); // "f32"
321
+ * console.log(block.dtype("symbol")); // "string"
322
+ * ```
323
+ * @param {string} key
324
+ * @returns {string | undefined}
325
+ */
326
+ dtype(key) {
327
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
328
+ const len0 = WASM_VECTOR_LEN;
329
+ const ret = wasm.block_dtype(this.__wbg_ptr, ptr0, len0);
330
+ let v2;
331
+ if (ret[0] !== 0) {
332
+ v2 = getStringFromWasm0(ret[0], ret[1]).slice();
333
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 1, 1);
334
+ }
335
+ return v2;
336
+ }
337
+ /**
338
+ * Check whether this block has zero columns.
339
+ *
340
+ * # Errors
341
+ *
342
+ * Throws if the block handle has been invalidated.
343
+ *
344
+ * # Example (JavaScript)
345
+ *
346
+ * ```js
347
+ * if (block.isEmpty()) { /* no columns yet */ }
348
+ * ```
349
+ * @returns {boolean}
350
+ */
351
+ isEmpty() {
352
+ const ret = wasm.block_isEmpty(this.__wbg_ptr);
353
+ if (ret[2]) {
354
+ throw takeFromExternrefTable0(ret[1]);
355
+ }
356
+ return ret[0] !== 0;
357
+ }
358
+ /**
359
+ * Return all column names as a JS `Array<string>`.
360
+ *
361
+ * # Errors
362
+ *
363
+ * Throws if the block handle has been invalidated.
364
+ *
365
+ * # Example (JavaScript)
366
+ *
367
+ * ```js
368
+ * const names = block.keys(); // ["x", "y", "z", "symbol"]
369
+ * ```
370
+ * @returns {Array<any>}
371
+ */
372
+ keys() {
373
+ const ret = wasm.block_keys(this.__wbg_ptr);
374
+ if (ret[2]) {
375
+ throw takeFromExternrefTable0(ret[1]);
376
+ }
377
+ return takeFromExternrefTable0(ret[0]);
378
+ }
379
+ /**
380
+ * Return the number of columns in this block.
381
+ *
382
+ * # Errors
383
+ *
384
+ * Throws if the block handle has been invalidated.
385
+ *
386
+ * # Example (JavaScript)
387
+ *
388
+ * ```js
389
+ * console.log(block.len()); // e.g., 3
390
+ * ```
391
+ * @returns {number}
392
+ */
393
+ len() {
394
+ const ret = wasm.block_len(this.__wbg_ptr);
395
+ if (ret[2]) {
396
+ throw takeFromExternrefTable0(ret[1]);
397
+ }
398
+ return ret[0] >>> 0;
399
+ }
400
+ /**
401
+ * Create a new, standalone empty `Block`.
402
+ *
403
+ * The block is backed by its own temporary store. Prefer
404
+ * [`Frame.createBlock()`](crate::Frame::create_block) to create
405
+ * blocks that are immediately attached to a frame.
406
+ *
407
+ * # Errors
408
+ *
409
+ * Throws a `JsValue` string if the internal store allocation fails.
410
+ *
411
+ * # Example (JavaScript)
412
+ *
413
+ * ```js
414
+ * const block = new Block();
415
+ * block.setColF32("values", new Float32Array([1, 2, 3]));
416
+ * ```
417
+ */
418
+ constructor() {
419
+ const ret = wasm.block_new();
420
+ if (ret[2]) {
421
+ throw takeFromExternrefTable0(ret[1]);
422
+ }
423
+ this.__wbg_ptr = ret[0] >>> 0;
424
+ BlockFinalization.register(this, this.__wbg_ptr, this);
425
+ return this;
426
+ }
427
+ /**
428
+ * Return the number of rows (shared across all columns).
429
+ *
430
+ * Returns `0` if the block has no columns.
431
+ *
432
+ * # Errors
433
+ *
434
+ * Throws if the block handle has been invalidated.
435
+ *
436
+ * # Example (JavaScript)
437
+ *
438
+ * ```js
439
+ * console.log(block.nrows()); // e.g., 100
440
+ * ```
441
+ * @returns {number}
442
+ */
443
+ nrows() {
444
+ const ret = wasm.block_nrows(this.__wbg_ptr);
445
+ if (ret[2]) {
446
+ throw takeFromExternrefTable0(ret[1]);
447
+ }
448
+ return ret[0] >>> 0;
449
+ }
450
+ /**
451
+ * Rename a column from `old_key` to `new_key`.
452
+ *
453
+ * # Arguments
454
+ *
455
+ * * `old_key` - Current column name
456
+ * * `new_key` - New column name
457
+ *
458
+ * # Returns
459
+ *
460
+ * `true` if the column was found and renamed, `false` otherwise.
461
+ *
462
+ * # Errors
463
+ *
464
+ * Throws if the block handle has been invalidated.
465
+ *
466
+ * # Example (JavaScript)
467
+ *
468
+ * ```js
469
+ * block.renameColumn("element", "symbol"); // true
470
+ * ```
471
+ * @param {string} old_key
472
+ * @param {string} new_key
473
+ * @returns {boolean}
474
+ */
475
+ renameColumn(old_key, new_key) {
476
+ const ptr0 = passStringToWasm0(old_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
477
+ const len0 = WASM_VECTOR_LEN;
478
+ const ptr1 = passStringToWasm0(new_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
479
+ const len1 = WASM_VECTOR_LEN;
480
+ const ret = wasm.block_renameColumn(this.__wbg_ptr, ptr0, len0, ptr1, len1);
481
+ if (ret[2]) {
482
+ throw takeFromExternrefTable0(ret[1]);
483
+ }
484
+ return ret[0] !== 0;
485
+ }
486
+ /**
487
+ * Set a float column from a `Float32Array`.
488
+ *
489
+ * # Arguments
490
+ *
491
+ * * `key` - Column name (e.g., `"x"`, `"mass"`, `"charge"`)
492
+ * * `data` - `Float32Array` with the column values
493
+ * * `shape` - Optional shape array for multi-dimensional data
494
+ * (e.g., `[N, 3]` for an Nx3 matrix stored flat). If omitted,
495
+ * the data is stored as a 1D column.
496
+ *
497
+ * # Errors
498
+ *
499
+ * Throws if `shape` product does not match `data.length`, or if
500
+ * the resulting row count is inconsistent with existing columns.
501
+ *
502
+ * # Example (JavaScript)
503
+ *
504
+ * ```js
505
+ * block.setColF32("x", new Float32Array([1.0, 2.0, 3.0]));
506
+ * // Multi-dimensional: 2 rows x 3 columns
507
+ * block.setColF32("pos", new Float32Array([1,2,3, 4,5,6]), [2, 3]);
508
+ * ```
509
+ * @param {string} key
510
+ * @param {Float32Array} data
511
+ * @param {Uint32Array | null} [shape]
512
+ */
513
+ setColF32(key, data, shape) {
514
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
515
+ const len0 = WASM_VECTOR_LEN;
516
+ var ptr1 = isLikeNone(shape) ? 0 : passArray32ToWasm0(shape, wasm.__wbindgen_malloc_command_export);
517
+ var len1 = WASM_VECTOR_LEN;
518
+ const ret = wasm.block_setColF32(this.__wbg_ptr, ptr0, len0, data, ptr1, len1);
519
+ if (ret[1]) {
520
+ throw takeFromExternrefTable0(ret[0]);
521
+ }
522
+ }
523
+ /**
524
+ * Set a signed integer column from an `Int32Array`.
525
+ *
526
+ * # Arguments
527
+ *
528
+ * * `key` - Column name
529
+ * * `data` - `Int32Array` with the column values
530
+ *
531
+ * # Errors
532
+ *
533
+ * Throws if the row count is inconsistent with existing columns.
534
+ *
535
+ * # Example (JavaScript)
536
+ *
537
+ * ```js
538
+ * block.setColI32("charge_sign", new Int32Array([1, -1, 0]));
539
+ * ```
540
+ * @param {string} key
541
+ * @param {Int32Array} data
542
+ */
543
+ setColI32(key, data) {
544
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
545
+ const len0 = WASM_VECTOR_LEN;
546
+ const ret = wasm.block_setColI32(this.__wbg_ptr, ptr0, len0, data);
547
+ if (ret[1]) {
548
+ throw takeFromExternrefTable0(ret[0]);
549
+ }
550
+ }
551
+ /**
552
+ * Set a string column from a JS `Array<string>`.
553
+ *
554
+ * # Arguments
555
+ *
556
+ * * `key` - Column name (e.g., `"symbol"`, `"name"`)
557
+ * * `data` - JS `Array` where every element must be a string
558
+ *
559
+ * # Errors
560
+ *
561
+ * Throws if any element is not a string, or if the row count is
562
+ * inconsistent with existing columns.
563
+ *
564
+ * # Example (JavaScript)
565
+ *
566
+ * ```js
567
+ * atoms.setColStr("symbol", ["C", "C", "O"]);
568
+ * ```
569
+ * @param {string} key
570
+ * @param {Array<any>} data
571
+ */
572
+ setColStr(key, data) {
573
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
574
+ const len0 = WASM_VECTOR_LEN;
575
+ const ret = wasm.block_setColStr(this.__wbg_ptr, ptr0, len0, data);
576
+ if (ret[1]) {
577
+ throw takeFromExternrefTable0(ret[0]);
578
+ }
579
+ }
580
+ /**
581
+ * Set an unsigned integer column from a `Uint32Array`.
582
+ *
583
+ * # Arguments
584
+ *
585
+ * * `key` - Column name (e.g., `"i"`, `"j"` for bond indices)
586
+ * * `data` - `Uint32Array` with the column values
587
+ *
588
+ * # Errors
589
+ *
590
+ * Throws if the row count is inconsistent with existing columns.
591
+ *
592
+ * # Example (JavaScript)
593
+ *
594
+ * ```js
595
+ * // Bond topology: atom indices
596
+ * bonds.setColU32("i", new Uint32Array([0, 1]));
597
+ * bonds.setColU32("j", new Uint32Array([1, 2]));
598
+ * ```
599
+ * @param {string} key
600
+ * @param {Uint32Array} data
601
+ */
602
+ setColU32(key, data) {
603
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
604
+ const len0 = WASM_VECTOR_LEN;
605
+ const ret = wasm.block_setColU32(this.__wbg_ptr, ptr0, len0, data);
606
+ if (ret[1]) {
607
+ throw takeFromExternrefTable0(ret[0]);
608
+ }
609
+ }
610
+ /**
611
+ * Zero-copy `Float32Array` view into WASM linear memory.
612
+ *
613
+ * Returns a view backed directly by the block's storage in WASM
614
+ * memory. This avoids copying but the view becomes **invalid**
615
+ * if WASM linear memory grows (due to any allocation).
616
+ *
617
+ * Use [`copyColF32`](Block::copy_col_f32) for a safe, long-lived copy.
618
+ *
619
+ * # Arguments
620
+ *
621
+ * * `key` - Column name
622
+ *
623
+ * # Returns
624
+ *
625
+ * A `Float32Array` view into WASM memory.
626
+ *
627
+ * # Errors
628
+ *
629
+ * Throws if the column does not exist or is not of type `f32`.
630
+ *
631
+ * # Example (JavaScript)
632
+ *
633
+ * ```js
634
+ * const view = block.viewColF32("x"); // zero-copy, use immediately
635
+ * const copy = block.copyColF32("x"); // safe to keep
636
+ * ```
637
+ * @param {string} key
638
+ * @returns {Float32Array}
639
+ */
640
+ viewColF32(key) {
641
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
642
+ const len0 = WASM_VECTOR_LEN;
643
+ const ret = wasm.block_viewColF32(this.__wbg_ptr, ptr0, len0);
644
+ if (ret[2]) {
645
+ throw takeFromExternrefTable0(ret[1]);
646
+ }
647
+ return takeFromExternrefTable0(ret[0]);
648
+ }
649
+ /**
650
+ * Zero-copy `Int32Array` view into WASM linear memory.
651
+ *
652
+ * **Warning**: invalidated if WASM linear memory grows.
653
+ * Use [`copyColI32`](Block::copy_col_i32) for a safe copy.
654
+ *
655
+ * # Arguments
656
+ *
657
+ * * `key` - Column name
658
+ *
659
+ * # Errors
660
+ *
661
+ * Throws if the column does not exist or is not of type `i32`.
662
+ *
663
+ * # Example (JavaScript)
664
+ *
665
+ * ```js
666
+ * const view = block.viewColI32("type_id");
667
+ * ```
668
+ * @param {string} key
669
+ * @returns {Int32Array}
670
+ */
671
+ viewColI32(key) {
672
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
673
+ const len0 = WASM_VECTOR_LEN;
674
+ const ret = wasm.block_viewColI32(this.__wbg_ptr, ptr0, len0);
675
+ if (ret[2]) {
676
+ throw takeFromExternrefTable0(ret[1]);
677
+ }
678
+ return takeFromExternrefTable0(ret[0]);
679
+ }
680
+ /**
681
+ * Zero-copy `Uint32Array` view into WASM linear memory.
682
+ *
683
+ * **Warning**: invalidated if WASM linear memory grows.
684
+ * Use [`copyColU32`](Block::copy_col_u32) for a safe copy.
685
+ *
686
+ * # Arguments
687
+ *
688
+ * * `key` - Column name
689
+ *
690
+ * # Errors
691
+ *
692
+ * Throws if the column does not exist or is not of type `u32`.
693
+ *
694
+ * # Example (JavaScript)
695
+ *
696
+ * ```js
697
+ * const view = block.viewColU32("i");
698
+ * ```
699
+ * @param {string} key
700
+ * @returns {Uint32Array}
701
+ */
702
+ viewColU32(key) {
703
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
704
+ const len0 = WASM_VECTOR_LEN;
705
+ const ret = wasm.block_viewColU32(this.__wbg_ptr, ptr0, len0);
706
+ if (ret[2]) {
707
+ throw takeFromExternrefTable0(ret[1]);
708
+ }
709
+ return takeFromExternrefTable0(ret[0]);
710
+ }
711
+ }
712
+ if (Symbol.dispose) Block.prototype[Symbol.dispose] = Block.prototype.free;
713
+
714
+ /**
715
+ * Simulation box defining periodic boundary conditions and coordinate
716
+ * transformations.
717
+ *
718
+ * Represents a parallelepiped defined by a 3x3 matrix `h` and an
719
+ * origin point. Supports periodic boundary conditions (PBC)
720
+ * independently in x, y, z directions.
721
+ *
722
+ * Exported as `Box` in JavaScript.
723
+ *
724
+ * # Example (JavaScript)
725
+ *
726
+ * ```js
727
+ * const h = new Float32Array([10, 0, 0, 0, 10, 0, 0, 0, 10]);
728
+ * const origin = new Float32Array([0, 0, 0]);
729
+ * const box = new Box(h, origin, true, true, true);
730
+ * console.log(box.volume()); // 1000.0
731
+ * console.log(box.lengths().toCopy()); // [10, 10, 10]
732
+ * ```
733
+ */
734
+ export class Box {
735
+ static __wrap(ptr) {
736
+ ptr = ptr >>> 0;
737
+ const obj = Object.create(Box.prototype);
738
+ obj.__wbg_ptr = ptr;
739
+ BoxFinalization.register(obj, obj.__wbg_ptr, obj);
740
+ return obj;
741
+ }
742
+ __destroy_into_raw() {
743
+ const ptr = this.__wbg_ptr;
744
+ this.__wbg_ptr = 0;
745
+ BoxFinalization.unregister(this);
746
+ return ptr;
747
+ }
748
+ free() {
749
+ const ptr = this.__destroy_into_raw();
750
+ wasm.__wbg_box_free(ptr, 0);
751
+ }
752
+ /**
753
+ * Create a cubic box with equal side lengths.
754
+ *
755
+ * # Arguments
756
+ *
757
+ * * `a` - Side length of the cube in angstrom (A)
758
+ * * `origin` - 3D origin vector as `Float32Array` with 3 elements
759
+ * `[x, y, z]` in angstrom
760
+ * * `pbc_x` - Enable periodic boundary in x direction
761
+ * * `pbc_y` - Enable periodic boundary in y direction
762
+ * * `pbc_z` - Enable periodic boundary in z direction
763
+ *
764
+ * # Returns
765
+ *
766
+ * A new cubic `Box` with side length `a`.
767
+ *
768
+ * # Errors
769
+ *
770
+ * Throws if `origin` does not have 3 elements.
771
+ *
772
+ * # Example (JavaScript)
773
+ *
774
+ * ```js
775
+ * const origin = new Float32Array([0, 0, 0]);
776
+ * const box = Box.cube(10.0, origin, true, true, true);
777
+ * console.log(box.volume()); // 1000.0
778
+ * ```
779
+ * @param {number} a
780
+ * @param {Float32Array} origin
781
+ * @param {boolean} pbc_x
782
+ * @param {boolean} pbc_y
783
+ * @param {boolean} pbc_z
784
+ * @returns {Box}
785
+ */
786
+ static cube(a, origin, pbc_x, pbc_y, pbc_z) {
787
+ const ret = wasm.box_cube(a, origin, pbc_x, pbc_y, pbc_z);
788
+ if (ret[2]) {
789
+ throw takeFromExternrefTable0(ret[1]);
790
+ }
791
+ return Box.__wrap(ret[0]);
792
+ }
793
+ /**
794
+ * Calculate displacement vectors between two sets of coordinates.
795
+ *
796
+ * Computes `delta = b - a` for each pair of points. When
797
+ * `minimum_image` is `true`, the minimum-image convention is
798
+ * applied so that the displacement uses the shortest vector
799
+ * under periodic boundary conditions.
800
+ *
801
+ * # Arguments
802
+ *
803
+ * * `a` - `WasmArray` with shape `[N, 3]` (reference positions in A)
804
+ * * `b` - `WasmArray` with shape `[N, 3]` (target positions in A)
805
+ * * `minimum_image` - If `true`, apply minimum image convention
806
+ * for PBC-enabled axes
807
+ *
808
+ * # Returns
809
+ *
810
+ * `WasmArray` with shape `[N, 3]` containing displacement vectors
811
+ * `(b - a)` in angstrom (A).
812
+ *
813
+ * # Errors
814
+ *
815
+ * Throws if `a` or `b` does not have shape `[N, 3]`, or if the
816
+ * two arrays have different numbers of rows.
817
+ *
818
+ * # Example (JavaScript)
819
+ *
820
+ * ```js
821
+ * const a = WasmArray.from(new Float32Array([1,1,1]), [1,3]);
822
+ * const b = WasmArray.from(new Float32Array([9,9,9]), [1,3]);
823
+ * const d = box.delta(a, b, true); // minimum-image displacement
824
+ * ```
825
+ * @param {WasmArray} a
826
+ * @param {WasmArray} b
827
+ * @param {boolean} minimum_image
828
+ * @returns {WasmArray}
829
+ */
830
+ delta(a, b, minimum_image) {
831
+ _assertClass(a, WasmArray);
832
+ _assertClass(b, WasmArray);
833
+ const ret = wasm.box_delta(this.__wbg_ptr, a.__wbg_ptr, b.__wbg_ptr, minimum_image);
834
+ if (ret[2]) {
835
+ throw takeFromExternrefTable0(ret[1]);
836
+ }
837
+ return WasmArray.__wrap(ret[0]);
838
+ }
839
+ /**
840
+ * Calculate displacement vectors and write the result directly into
841
+ * a [`Block`] column.
842
+ *
843
+ * This is an allocation-efficient alternative to [`delta`](Box::delta).
844
+ *
845
+ * # Arguments
846
+ *
847
+ * * `a` - `WasmArray` with shape `[N, 3]` (reference positions in A)
848
+ * * `b` - `WasmArray` with shape `[N, 3]` (target positions in A)
849
+ * * `minimum_image` - If `true`, apply minimum image convention
850
+ * * `out_block` - Target [`Block`] to write the result into
851
+ * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
852
+ *
853
+ * # Errors
854
+ *
855
+ * Throws if shapes are invalid or if the block write fails.
856
+ *
857
+ * # Example (JavaScript)
858
+ *
859
+ * ```js
860
+ * box.deltaToBlock(a, b, true, outBlock, "displacements");
861
+ * ```
862
+ * @param {WasmArray} a
863
+ * @param {WasmArray} b
864
+ * @param {boolean} minimum_image
865
+ * @param {Block} out_block
866
+ * @param {string} out_key
867
+ */
868
+ deltaToBlock(a, b, minimum_image, out_block, out_key) {
869
+ _assertClass(a, WasmArray);
870
+ _assertClass(b, WasmArray);
871
+ _assertClass(out_block, Block);
872
+ const ptr0 = passStringToWasm0(out_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
873
+ const len0 = WASM_VECTOR_LEN;
874
+ const ret = wasm.box_deltaToBlock(this.__wbg_ptr, a.__wbg_ptr, b.__wbg_ptr, minimum_image, out_block.__wbg_ptr, ptr0, len0);
875
+ if (ret[1]) {
876
+ throw takeFromExternrefTable0(ret[0]);
877
+ }
878
+ }
879
+ /**
880
+ * Return the 8 corner vertices of the parallelepiped.
881
+ *
882
+ * # Returns
883
+ *
884
+ * `WasmArray` with shape `[8, 3]` containing the corner
885
+ * coordinates in angstrom (A). The flat array has 24 elements.
886
+ *
887
+ * # Example (JavaScript)
888
+ *
889
+ * ```js
890
+ * const corners = box.getCorners();
891
+ * console.log(corners.len()); // 24 (8 corners x 3 coords)
892
+ * ```
893
+ * @returns {WasmArray}
894
+ */
895
+ get_corners() {
896
+ const ret = wasm.box_get_corners(this.__wbg_ptr);
897
+ return WasmArray.__wrap(ret);
898
+ }
899
+ /**
900
+ * Return the box edge lengths as a `WasmArray` with shape `[3]`.
901
+ *
902
+ * For orthorhombic boxes these are `[lx, ly, lz]`. For triclinic
903
+ * boxes these are the lengths of the three cell vectors.
904
+ *
905
+ * # Returns
906
+ *
907
+ * `WasmArray` containing `[lx, ly, lz]` in angstrom (A).
908
+ *
909
+ * # Example (JavaScript)
910
+ *
911
+ * ```js
912
+ * const L = box.lengths().toCopy(); // Float32Array [10, 10, 10]
913
+ * ```
914
+ * @returns {WasmArray}
915
+ */
916
+ lengths() {
917
+ const ret = wasm.box_lengths(this.__wbg_ptr);
918
+ return WasmArray.__wrap(ret);
919
+ }
920
+ /**
921
+ * Create a new box from a 3x3 cell matrix and origin.
922
+ *
923
+ * # Arguments
924
+ *
925
+ * * `h` - 3x3 cell matrix as `Float32Array` with 9 elements in
926
+ * row-major order: `[h00, h01, h02, h10, h11, h12, h20, h21, h22]`.
927
+ * All values in angstrom (A).
928
+ * * `origin` - 3D origin vector as `Float32Array` with 3 elements
929
+ * `[x, y, z]` in angstrom.
930
+ * * `pbc_x` - Enable periodic boundary in x direction
931
+ * * `pbc_y` - Enable periodic boundary in y direction
932
+ * * `pbc_z` - Enable periodic boundary in z direction
933
+ *
934
+ * # Returns
935
+ *
936
+ * A new `Box` instance.
937
+ *
938
+ * # Errors
939
+ *
940
+ * Throws if `h` does not have 9 elements or `origin` does not have
941
+ * 3 elements, or if the matrix is singular.
942
+ *
943
+ * # Example (JavaScript)
944
+ *
945
+ * ```js
946
+ * // Triclinic box
947
+ * const h = new Float32Array([10, 2, 0, 0, 10, 0, 0, 0, 10]);
948
+ * const origin = new Float32Array([0, 0, 0]);
949
+ * const box = new Box(h, origin, true, true, true);
950
+ * ```
951
+ * @param {Float32Array} h
952
+ * @param {Float32Array} origin
953
+ * @param {boolean} pbc_x
954
+ * @param {boolean} pbc_y
955
+ * @param {boolean} pbc_z
956
+ */
957
+ constructor(h, origin, pbc_x, pbc_y, pbc_z) {
958
+ const ret = wasm.box_new(h, origin, pbc_x, pbc_y, pbc_z);
959
+ if (ret[2]) {
960
+ throw takeFromExternrefTable0(ret[1]);
961
+ }
962
+ this.__wbg_ptr = ret[0] >>> 0;
963
+ BoxFinalization.register(this, this.__wbg_ptr, this);
964
+ return this;
965
+ }
966
+ /**
967
+ * Return the box origin as a `WasmArray` with shape `[3]`.
968
+ *
969
+ * The origin is the lower-left corner of the box in angstrom (A).
970
+ *
971
+ * # Returns
972
+ *
973
+ * `WasmArray` containing `[ox, oy, oz]` in angstrom.
974
+ *
975
+ * # Example (JavaScript)
976
+ *
977
+ * ```js
978
+ * const o = box.origin().toCopy(); // Float32Array [0, 0, 0]
979
+ * ```
980
+ * @returns {WasmArray}
981
+ */
982
+ origin() {
983
+ const ret = wasm.box_origin(this.__wbg_ptr);
984
+ return WasmArray.__wrap(ret);
985
+ }
986
+ /**
987
+ * Create an orthorhombic (rectangular) box with axis-aligned edges.
988
+ *
989
+ * # Arguments
990
+ *
991
+ * * `lengths` - Box dimensions as `Float32Array` with 3 elements
992
+ * `[lx, ly, lz]` in angstrom (A)
993
+ * * `origin` - 3D origin vector as `Float32Array` with 3 elements
994
+ * `[x, y, z]` in angstrom
995
+ * * `pbc_x` - Enable periodic boundary in x direction
996
+ * * `pbc_y` - Enable periodic boundary in y direction
997
+ * * `pbc_z` - Enable periodic boundary in z direction
998
+ *
999
+ * # Returns
1000
+ *
1001
+ * A new orthorhombic `Box`.
1002
+ *
1003
+ * # Errors
1004
+ *
1005
+ * Throws if `lengths` or `origin` does not have 3 elements.
1006
+ *
1007
+ * # Example (JavaScript)
1008
+ *
1009
+ * ```js
1010
+ * const origin = new Float32Array([0, 0, 0]);
1011
+ * const box = Box.ortho(new Float32Array([10, 20, 30]), origin, true, true, true);
1012
+ * console.log(box.volume()); // 6000.0
1013
+ * ```
1014
+ * @param {Float32Array} lengths
1015
+ * @param {Float32Array} origin
1016
+ * @param {boolean} pbc_x
1017
+ * @param {boolean} pbc_y
1018
+ * @param {boolean} pbc_z
1019
+ * @returns {Box}
1020
+ */
1021
+ static ortho(lengths, origin, pbc_x, pbc_y, pbc_z) {
1022
+ const ret = wasm.box_ortho(lengths, origin, pbc_x, pbc_y, pbc_z);
1023
+ if (ret[2]) {
1024
+ throw takeFromExternrefTable0(ret[1]);
1025
+ }
1026
+ return Box.__wrap(ret[0]);
1027
+ }
1028
+ /**
1029
+ * Return the box tilt factors as a `WasmArray` with shape `[3]`.
1030
+ *
1031
+ * Tilt factors `[xy, xz, yz]` define the off-diagonal elements
1032
+ * of the cell matrix (LAMMPS convention). For orthorhombic boxes
1033
+ * all tilts are zero.
1034
+ *
1035
+ * # Returns
1036
+ *
1037
+ * `WasmArray` containing `[xy, xz, yz]` (dimensionless ratios
1038
+ * multiplied by the corresponding box length, so effectively in A).
1039
+ *
1040
+ * # Example (JavaScript)
1041
+ *
1042
+ * ```js
1043
+ * const t = box.tilts().toCopy(); // Float32Array [0, 0, 0]
1044
+ * ```
1045
+ * @returns {WasmArray}
1046
+ */
1047
+ tilts() {
1048
+ const ret = wasm.box_tilts(this.__wbg_ptr);
1049
+ return WasmArray.__wrap(ret);
1050
+ }
1051
+ /**
1052
+ * Convert fractional to Cartesian coordinates and write the result
1053
+ * directly into a [`Block`] column.
1054
+ *
1055
+ * # Arguments
1056
+ *
1057
+ * * `coords` - `WasmArray` with shape `[N, 3]` (fractional, dimensionless)
1058
+ * * `out_block` - Target [`Block`]
1059
+ * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
1060
+ *
1061
+ * # Errors
1062
+ *
1063
+ * Throws if `coords` does not have shape `[N, 3]`.
1064
+ *
1065
+ * # Example (JavaScript)
1066
+ *
1067
+ * ```js
1068
+ * box.toCartToBlock(fracCoords, outBlock, "cart_coords");
1069
+ * ```
1070
+ * @param {WasmArray} coords
1071
+ * @param {Block} out_block
1072
+ * @param {string} out_key
1073
+ */
1074
+ toCartToBlock(coords, out_block, out_key) {
1075
+ _assertClass(coords, WasmArray);
1076
+ _assertClass(out_block, Block);
1077
+ const ptr0 = passStringToWasm0(out_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1078
+ const len0 = WASM_VECTOR_LEN;
1079
+ const ret = wasm.box_toCartToBlock(this.__wbg_ptr, coords.__wbg_ptr, out_block.__wbg_ptr, ptr0, len0);
1080
+ if (ret[1]) {
1081
+ throw takeFromExternrefTable0(ret[0]);
1082
+ }
1083
+ }
1084
+ /**
1085
+ * Convert Cartesian to fractional coordinates and write the result
1086
+ * directly into a [`Block`] column.
1087
+ *
1088
+ * # Arguments
1089
+ *
1090
+ * * `coords` - `WasmArray` with shape `[N, 3]` (Cartesian, A)
1091
+ * * `out_block` - Target [`Block`]
1092
+ * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
1093
+ *
1094
+ * # Errors
1095
+ *
1096
+ * Throws if `coords` does not have shape `[N, 3]`.
1097
+ *
1098
+ * # Example (JavaScript)
1099
+ *
1100
+ * ```js
1101
+ * box.toFracToBlock(cartCoords, outBlock, "frac_coords");
1102
+ * ```
1103
+ * @param {WasmArray} coords
1104
+ * @param {Block} out_block
1105
+ * @param {string} out_key
1106
+ */
1107
+ toFracToBlock(coords, out_block, out_key) {
1108
+ _assertClass(coords, WasmArray);
1109
+ _assertClass(out_block, Block);
1110
+ const ptr0 = passStringToWasm0(out_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1111
+ const len0 = WASM_VECTOR_LEN;
1112
+ const ret = wasm.box_toFracToBlock(this.__wbg_ptr, coords.__wbg_ptr, out_block.__wbg_ptr, ptr0, len0);
1113
+ if (ret[1]) {
1114
+ throw takeFromExternrefTable0(ret[0]);
1115
+ }
1116
+ }
1117
+ /**
1118
+ * Convert fractional coordinates to Cartesian coordinates.
1119
+ *
1120
+ * # Arguments
1121
+ *
1122
+ * * `coords` - `WasmArray` with shape `[N, 3]` containing
1123
+ * fractional coordinates (dimensionless)
1124
+ *
1125
+ * # Returns
1126
+ *
1127
+ * `WasmArray` with shape `[N, 3]` containing Cartesian coordinates
1128
+ * in angstrom (A).
1129
+ *
1130
+ * # Errors
1131
+ *
1132
+ * Throws if `coords` does not have shape `[N, 3]`.
1133
+ *
1134
+ * # Example (JavaScript)
1135
+ *
1136
+ * ```js
1137
+ * const frac = WasmArray.from(new Float32Array([0.5, 0.5, 0.5]), [1, 3]);
1138
+ * const cart = box.toCart(frac);
1139
+ * console.log(cart.toCopy()); // [5, 5, 5] for a 10x10x10 box
1140
+ * ```
1141
+ * @param {WasmArray} coords
1142
+ * @returns {WasmArray}
1143
+ */
1144
+ to_cart(coords) {
1145
+ _assertClass(coords, WasmArray);
1146
+ const ret = wasm.box_to_cart(this.__wbg_ptr, coords.__wbg_ptr);
1147
+ if (ret[2]) {
1148
+ throw takeFromExternrefTable0(ret[1]);
1149
+ }
1150
+ return WasmArray.__wrap(ret[0]);
1151
+ }
1152
+ /**
1153
+ * Convert Cartesian coordinates to fractional coordinates.
1154
+ *
1155
+ * Fractional coordinates are in the range [0, 1) for atoms
1156
+ * inside the primary image of the box.
1157
+ *
1158
+ * # Arguments
1159
+ *
1160
+ * * `coords` - `WasmArray` with shape `[N, 3]` containing
1161
+ * Cartesian coordinates in angstrom (A)
1162
+ *
1163
+ * # Returns
1164
+ *
1165
+ * `WasmArray` with shape `[N, 3]` containing fractional coordinates
1166
+ * (dimensionless).
1167
+ *
1168
+ * # Errors
1169
+ *
1170
+ * Throws if `coords` does not have shape `[N, 3]`.
1171
+ *
1172
+ * # Example (JavaScript)
1173
+ *
1174
+ * ```js
1175
+ * const cart = WasmArray.from(new Float32Array([5, 5, 5]), [1, 3]);
1176
+ * const frac = box.toFrac(cart);
1177
+ * console.log(frac.toCopy()); // [0.5, 0.5, 0.5] for a 10x10x10 box
1178
+ * ```
1179
+ * @param {WasmArray} coords
1180
+ * @returns {WasmArray}
1181
+ */
1182
+ to_frac(coords) {
1183
+ _assertClass(coords, WasmArray);
1184
+ const ret = wasm.box_to_frac(this.__wbg_ptr, coords.__wbg_ptr);
1185
+ if (ret[2]) {
1186
+ throw takeFromExternrefTable0(ret[1]);
1187
+ }
1188
+ return WasmArray.__wrap(ret[0]);
1189
+ }
1190
+ /**
1191
+ * Return the box volume in cubic angstrom (A^3).
1192
+ *
1193
+ * # Example (JavaScript)
1194
+ *
1195
+ * ```js
1196
+ * console.log(box.volume()); // e.g., 1000.0
1197
+ * ```
1198
+ * @returns {number}
1199
+ */
1200
+ volume() {
1201
+ const ret = wasm.box_volume(this.__wbg_ptr);
1202
+ return ret;
1203
+ }
1204
+ /**
1205
+ * Wrap Cartesian coordinates into the primary image of the box.
1206
+ *
1207
+ * Atoms outside the box are translated back into the primary image
1208
+ * using the periodic boundary conditions. Only axes with PBC
1209
+ * enabled are wrapped.
1210
+ *
1211
+ * # Arguments
1212
+ *
1213
+ * * `coords` - `WasmArray` with shape `[N, 3]` containing
1214
+ * Cartesian coordinates in angstrom (A)
1215
+ *
1216
+ * # Returns
1217
+ *
1218
+ * `WasmArray` with shape `[N, 3]` containing wrapped coordinates
1219
+ * in angstrom (A).
1220
+ *
1221
+ * # Errors
1222
+ *
1223
+ * Throws if `coords` does not have shape `[N, 3]`.
1224
+ *
1225
+ * # Example (JavaScript)
1226
+ *
1227
+ * ```js
1228
+ * const pos = WasmArray.from(new Float32Array([12, -1, 5]), [1, 3]);
1229
+ * const wrapped = box.wrap(pos); // wraps into [0, lx) x [0, ly) x [0, lz)
1230
+ * ```
1231
+ * @param {WasmArray} coords
1232
+ * @returns {WasmArray}
1233
+ */
1234
+ wrap(coords) {
1235
+ _assertClass(coords, WasmArray);
1236
+ const ret = wasm.box_wrap(this.__wbg_ptr, coords.__wbg_ptr);
1237
+ if (ret[2]) {
1238
+ throw takeFromExternrefTable0(ret[1]);
1239
+ }
1240
+ return WasmArray.__wrap(ret[0]);
1241
+ }
1242
+ /**
1243
+ * Wrap coordinates and write the result directly into a [`Block`] column.
1244
+ *
1245
+ * This is an allocation-efficient alternative to [`wrap`](Box::wrap)
1246
+ * that avoids creating an intermediate `WasmArray`.
1247
+ *
1248
+ * # Arguments
1249
+ *
1250
+ * * `coords` - `WasmArray` with shape `[N, 3]` containing
1251
+ * Cartesian coordinates in angstrom (A)
1252
+ * * `out_block` - Target [`Block`] to write the result into
1253
+ * * `out_key` - Column name for the result (f32, shape `[N, 3]`)
1254
+ *
1255
+ * # Errors
1256
+ *
1257
+ * Throws if `coords` does not have shape `[N, 3]` or if the
1258
+ * block write fails.
1259
+ *
1260
+ * # Example (JavaScript)
1261
+ *
1262
+ * ```js
1263
+ * box.wrapToBlock(coords, outBlock, "wrapped_pos");
1264
+ * ```
1265
+ * @param {WasmArray} coords
1266
+ * @param {Block} out_block
1267
+ * @param {string} out_key
1268
+ */
1269
+ wrapToBlock(coords, out_block, out_key) {
1270
+ _assertClass(coords, WasmArray);
1271
+ _assertClass(out_block, Block);
1272
+ const ptr0 = passStringToWasm0(out_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1273
+ const len0 = WASM_VECTOR_LEN;
1274
+ const ret = wasm.box_wrapToBlock(this.__wbg_ptr, coords.__wbg_ptr, out_block.__wbg_ptr, ptr0, len0);
1275
+ if (ret[1]) {
1276
+ throw takeFromExternrefTable0(ret[0]);
1277
+ }
1278
+ }
1279
+ }
1280
+ if (Symbol.dispose) Box.prototype[Symbol.dispose] = Box.prototype.free;
1281
+
1282
+ /**
1283
+ * Distance-based cluster analysis using BFS on the neighbor graph.
1284
+ *
1285
+ * Particles that are connected (directly or transitively) through
1286
+ * neighbor-list pairs are grouped into clusters. Clusters smaller
1287
+ * than `minClusterSize` are filtered out (their particles get
1288
+ * cluster ID = -1).
1289
+ *
1290
+ * # Example (JavaScript)
1291
+ *
1292
+ * ```js
1293
+ * const ns = new NeighborSearch(2.0);
1294
+ * const nlist = ns.build(frame);
1295
+ *
1296
+ * const cluster = new Cluster(5); // min 5 particles per cluster
1297
+ * const result = cluster.compute(frame, nlist);
1298
+ *
1299
+ * console.log(result.numClusters); // number of valid clusters
1300
+ * console.log(result.clusterIdx()); // Int32Array, per-particle IDs
1301
+ * console.log(result.clusterSizes()); // Uint32Array, size of each cluster
1302
+ * ```
1303
+ */
1304
+ export class Cluster {
1305
+ __destroy_into_raw() {
1306
+ const ptr = this.__wbg_ptr;
1307
+ this.__wbg_ptr = 0;
1308
+ ClusterFinalization.unregister(this);
1309
+ return ptr;
1310
+ }
1311
+ free() {
1312
+ const ptr = this.__destroy_into_raw();
1313
+ wasm.__wbg_cluster_free(ptr, 0);
1314
+ }
1315
+ /**
1316
+ * Run cluster analysis on a frame with pre-built neighbor pairs.
1317
+ *
1318
+ * # Arguments
1319
+ *
1320
+ * * `frame` - Frame with atom positions
1321
+ * * `neighbors` - Pre-built [`NeighborList`] defining connectivity
1322
+ *
1323
+ * # Returns
1324
+ *
1325
+ * A [`ClusterResult`] with per-particle cluster IDs and cluster sizes.
1326
+ *
1327
+ * # Errors
1328
+ *
1329
+ * Throws if the frame cannot be cloned or the analysis fails.
1330
+ *
1331
+ * # Example (JavaScript)
1332
+ *
1333
+ * ```js
1334
+ * const result = cluster.compute(frame, nlist);
1335
+ * ```
1336
+ * @param {Frame} frame
1337
+ * @param {NeighborList} neighbors
1338
+ * @returns {ClusterResult}
1339
+ */
1340
+ compute(frame, neighbors) {
1341
+ _assertClass(frame, Frame);
1342
+ _assertClass(neighbors, NeighborList);
1343
+ const ret = wasm.cluster_compute(this.__wbg_ptr, frame.__wbg_ptr, neighbors.__wbg_ptr);
1344
+ if (ret[2]) {
1345
+ throw takeFromExternrefTable0(ret[1]);
1346
+ }
1347
+ return ClusterResult.__wrap(ret[0]);
1348
+ }
1349
+ /**
1350
+ * Create a cluster analysis with a minimum cluster size filter.
1351
+ *
1352
+ * # Arguments
1353
+ *
1354
+ * * `min_cluster_size` - Minimum number of particles for a cluster
1355
+ * to be considered valid. Clusters with fewer particles are
1356
+ * discarded (their particles get cluster ID = -1).
1357
+ *
1358
+ * # Example (JavaScript)
1359
+ *
1360
+ * ```js
1361
+ * const cluster = new Cluster(5); // ignore clusters < 5 particles
1362
+ * ```
1363
+ * @param {number} min_cluster_size
1364
+ */
1365
+ constructor(min_cluster_size) {
1366
+ const ret = wasm.cluster_new(min_cluster_size);
1367
+ this.__wbg_ptr = ret >>> 0;
1368
+ ClusterFinalization.register(this, this.__wbg_ptr, this);
1369
+ return this;
1370
+ }
1371
+ }
1372
+ if (Symbol.dispose) Cluster.prototype[Symbol.dispose] = Cluster.prototype.free;
1373
+
1374
+ /**
1375
+ * Result of a distance-based cluster analysis.
1376
+ *
1377
+ * # Example (JavaScript)
1378
+ *
1379
+ * ```js
1380
+ * const result = cluster.compute(frame, nlist);
1381
+ * console.log(result.numClusters); // number
1382
+ *
1383
+ * const ids = result.clusterIdx(); // Int32Array (per-particle)
1384
+ * const sizes = result.clusterSizes(); // Uint32Array (per-cluster)
1385
+ *
1386
+ * // Particles in filtered-out clusters have id = -1
1387
+ * for (let i = 0; i < ids.length; i++) {
1388
+ * if (ids[i] === -1) console.log(`Particle ${i} not in any valid cluster`);
1389
+ * }
1390
+ * ```
1391
+ */
1392
+ export class ClusterResult {
1393
+ static __wrap(ptr) {
1394
+ ptr = ptr >>> 0;
1395
+ const obj = Object.create(ClusterResult.prototype);
1396
+ obj.__wbg_ptr = ptr;
1397
+ ClusterResultFinalization.register(obj, obj.__wbg_ptr, obj);
1398
+ return obj;
1399
+ }
1400
+ __destroy_into_raw() {
1401
+ const ptr = this.__wbg_ptr;
1402
+ this.__wbg_ptr = 0;
1403
+ ClusterResultFinalization.unregister(this);
1404
+ return ptr;
1405
+ }
1406
+ free() {
1407
+ const ptr = this.__destroy_into_raw();
1408
+ wasm.__wbg_clusterresult_free(ptr, 0);
1409
+ }
1410
+ /**
1411
+ * Per-particle cluster ID assignment as `Int32Array`.
1412
+ *
1413
+ * `clusterIdx()[i]` is the cluster ID for particle `i`.
1414
+ * Particles in clusters smaller than `minClusterSize` are
1415
+ * assigned ID = -1 (filtered out).
1416
+ *
1417
+ * Cluster IDs are zero-based and contiguous: `0, 1, ..., numClusters-1`.
1418
+ * @returns {Int32Array}
1419
+ */
1420
+ clusterIdx() {
1421
+ const ret = wasm.clusterresult_clusterIdx(this.__wbg_ptr);
1422
+ var v1 = getArrayI32FromWasm0(ret[0], ret[1]).slice();
1423
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
1424
+ return v1;
1425
+ }
1426
+ /**
1427
+ * Size (particle count) of each valid cluster as `Uint32Array`.
1428
+ *
1429
+ * `clusterSizes()[c]` is the number of particles in cluster `c`.
1430
+ * Length equals `numClusters`.
1431
+ * @returns {Uint32Array}
1432
+ */
1433
+ clusterSizes() {
1434
+ const ret = wasm.clusterresult_clusterSizes(this.__wbg_ptr);
1435
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
1436
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
1437
+ return v1;
1438
+ }
1439
+ /**
1440
+ * Number of valid clusters found (after min-size filtering).
1441
+ * @returns {number}
1442
+ */
1443
+ get numClusters() {
1444
+ const ret = wasm.clusterresult_numClusters(this.__wbg_ptr);
1445
+ return ret >>> 0;
1446
+ }
1447
+ }
1448
+ if (Symbol.dispose) ClusterResult.prototype[Symbol.dispose] = ClusterResult.prototype.free;
1449
+
1450
+ /**
1451
+ * Hierarchical data container mapping string keys to typed [`Block`]s.
1452
+ *
1453
+ * A `Frame` owns a set of named blocks (column stores) and an optional
1454
+ * simulation box ([`Box`](super::region::simbox::Box)). This is the
1455
+ * primary interchange type for molecular data in the WASM API.
1456
+ *
1457
+ * # Conventions
1458
+ *
1459
+ * - The `"atoms"` block should contain per-atom properties: `symbol`
1460
+ * (string), `x`/`y`/`z` (f32, coordinates in angstrom), and optionally
1461
+ * `mass` (f32, atomic mass units) and `charge` (f32, elementary charges).
1462
+ * - The `"bonds"` block should contain bond topology: `i`/`j` (u32,
1463
+ * zero-based atom indices) and `order` (f32, bond order: 1.0 = single,
1464
+ * 1.5 = aromatic, 2.0 = double, 3.0 = triple).
1465
+ *
1466
+ * # Example (JavaScript)
1467
+ *
1468
+ * ```js
1469
+ * const frame = new Frame();
1470
+ * const atoms = frame.createBlock("atoms");
1471
+ * atoms.setColF32("x", new Float32Array([0.0, 1.54]));
1472
+ * ```
1473
+ */
1474
+ export class Frame {
1475
+ static __wrap(ptr) {
1476
+ ptr = ptr >>> 0;
1477
+ const obj = Object.create(Frame.prototype);
1478
+ obj.__wbg_ptr = ptr;
1479
+ FrameFinalization.register(obj, obj.__wbg_ptr, obj);
1480
+ return obj;
1481
+ }
1482
+ __destroy_into_raw() {
1483
+ const ptr = this.__wbg_ptr;
1484
+ this.__wbg_ptr = 0;
1485
+ FrameFinalization.unregister(this);
1486
+ return ptr;
1487
+ }
1488
+ free() {
1489
+ const ptr = this.__destroy_into_raw();
1490
+ wasm.__wbg_frame_free(ptr, 0);
1491
+ }
1492
+ /**
1493
+ * Remove all blocks from this frame (but keep the frame alive).
1494
+ *
1495
+ * # Errors
1496
+ *
1497
+ * Throws a `JsValue` string if the frame has already been dropped.
1498
+ *
1499
+ * # Example (JavaScript)
1500
+ *
1501
+ * ```js
1502
+ * frame.clear();
1503
+ * ```
1504
+ */
1505
+ clear() {
1506
+ const ret = wasm.frame_clear(this.__wbg_ptr);
1507
+ if (ret[1]) {
1508
+ throw takeFromExternrefTable0(ret[0]);
1509
+ }
1510
+ }
1511
+ /**
1512
+ * Create a new empty [`Block`] and register it under `key`.
1513
+ *
1514
+ * If a block with the same key already exists it is replaced.
1515
+ *
1516
+ * # Arguments
1517
+ *
1518
+ * * `key` - Block name (e.g., `"atoms"`, `"bonds"`)
1519
+ *
1520
+ * # Returns
1521
+ *
1522
+ * A mutable [`Block`] handle that can be used to add columns.
1523
+ *
1524
+ * # Errors
1525
+ *
1526
+ * Throws a `JsValue` string if the underlying store operation fails
1527
+ * (e.g., the frame has been dropped).
1528
+ *
1529
+ * # Example (JavaScript)
1530
+ *
1531
+ * ```js
1532
+ * const atoms = frame.createBlock("atoms");
1533
+ * atoms.setColF32("x", new Float32Array([1.0, 2.0]));
1534
+ * ```
1535
+ * @param {string} key
1536
+ * @returns {Block}
1537
+ */
1538
+ createBlock(key) {
1539
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1540
+ const len0 = WASM_VECTOR_LEN;
1541
+ const ret = wasm.frame_createBlock(this.__wbg_ptr, ptr0, len0);
1542
+ if (ret[2]) {
1543
+ throw takeFromExternrefTable0(ret[1]);
1544
+ }
1545
+ return Block.__wrap(ret[0]);
1546
+ }
1547
+ /**
1548
+ * Explicitly release this frame and all its blocks from the store.
1549
+ *
1550
+ * After calling `drop()`, any subsequent operations on this frame
1551
+ * or its blocks will throw. This is optional -- the frame will also
1552
+ * be released when garbage-collected by the JS engine.
1553
+ *
1554
+ * # Errors
1555
+ *
1556
+ * Throws a `JsValue` string if the frame was already dropped.
1557
+ *
1558
+ * # Example (JavaScript)
1559
+ *
1560
+ * ```js
1561
+ * frame.drop();
1562
+ * // frame.clear() would now throw
1563
+ * ```
1564
+ */
1565
+ drop() {
1566
+ const ret = wasm.frame_drop(this.__wbg_ptr);
1567
+ if (ret[1]) {
1568
+ throw takeFromExternrefTable0(ret[0]);
1569
+ }
1570
+ }
1571
+ /**
1572
+ * Retrieve an existing [`Block`] by name.
1573
+ *
1574
+ * # Arguments
1575
+ *
1576
+ * * `key` - Block name to look up
1577
+ *
1578
+ * # Returns
1579
+ *
1580
+ * The [`Block`] if found, or `undefined` if no block with that key
1581
+ * exists in this frame.
1582
+ *
1583
+ * # Example (JavaScript)
1584
+ *
1585
+ * ```js
1586
+ * const atoms = frame.getBlock("atoms");
1587
+ * if (atoms) {
1588
+ * const x = atoms.copyColF32("x");
1589
+ * }
1590
+ * ```
1591
+ * @param {string} key
1592
+ * @returns {Block | undefined}
1593
+ */
1594
+ getBlock(key) {
1595
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1596
+ const len0 = WASM_VECTOR_LEN;
1597
+ const ret = wasm.frame_getBlock(this.__wbg_ptr, ptr0, len0);
1598
+ return ret === 0 ? undefined : Block.__wrap(ret);
1599
+ }
1600
+ /**
1601
+ * Insert a block by deep-copying its data into this frame's store.
1602
+ *
1603
+ * This is useful for transferring a block from one frame to another.
1604
+ * The source block's data is cloned; subsequent modifications to the
1605
+ * source will not affect this frame.
1606
+ *
1607
+ * # Arguments
1608
+ *
1609
+ * * `key` - Name under which to store the block
1610
+ * * `block` - The source [`Block`] whose data will be copied
1611
+ *
1612
+ * # Errors
1613
+ *
1614
+ * Throws a `JsValue` string if either the source block or the
1615
+ * destination frame handle is invalid.
1616
+ *
1617
+ * # Example (JavaScript)
1618
+ *
1619
+ * ```js
1620
+ * const otherFrame = new Frame();
1621
+ * const atoms = otherFrame.createBlock("atoms");
1622
+ * // ... populate atoms ...
1623
+ * frame.insertBlock("atoms", atoms);
1624
+ * ```
1625
+ * @param {string} key
1626
+ * @param {Block} block
1627
+ */
1628
+ insertBlock(key, block) {
1629
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1630
+ const len0 = WASM_VECTOR_LEN;
1631
+ _assertClass(block, Block);
1632
+ var ptr1 = block.__destroy_into_raw();
1633
+ const ret = wasm.frame_insertBlock(this.__wbg_ptr, ptr0, len0, ptr1);
1634
+ if (ret[1]) {
1635
+ throw takeFromExternrefTable0(ret[0]);
1636
+ }
1637
+ }
1638
+ /**
1639
+ * Create a new, empty `Frame` with no blocks and no simulation box.
1640
+ *
1641
+ * # Example (JavaScript)
1642
+ *
1643
+ * ```js
1644
+ * const frame = new Frame();
1645
+ * ```
1646
+ */
1647
+ constructor() {
1648
+ const ret = wasm.frame_new();
1649
+ this.__wbg_ptr = ret >>> 0;
1650
+ FrameFinalization.register(this, this.__wbg_ptr, this);
1651
+ return this;
1652
+ }
1653
+ /**
1654
+ * Remove a block by name.
1655
+ *
1656
+ * # Arguments
1657
+ *
1658
+ * * `key` - Block name to remove
1659
+ *
1660
+ * # Errors
1661
+ *
1662
+ * Throws a `JsValue` string if the frame has been dropped or the
1663
+ * key does not exist.
1664
+ *
1665
+ * # Example (JavaScript)
1666
+ *
1667
+ * ```js
1668
+ * frame.removeBlock("bonds");
1669
+ * ```
1670
+ * @param {string} key
1671
+ */
1672
+ removeBlock(key) {
1673
+ const ptr0 = passStringToWasm0(key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1674
+ const len0 = WASM_VECTOR_LEN;
1675
+ const ret = wasm.frame_removeBlock(this.__wbg_ptr, ptr0, len0);
1676
+ if (ret[1]) {
1677
+ throw takeFromExternrefTable0(ret[0]);
1678
+ }
1679
+ }
1680
+ /**
1681
+ * Rename a block from `old_key` to `new_key`.
1682
+ *
1683
+ * # Arguments
1684
+ *
1685
+ * * `old_key` - Current block name
1686
+ * * `new_key` - New block name
1687
+ *
1688
+ * # Returns
1689
+ *
1690
+ * `true` if the block was found and renamed, `false` if `old_key`
1691
+ * did not exist.
1692
+ *
1693
+ * # Errors
1694
+ *
1695
+ * Throws a `JsValue` string if the frame has been dropped.
1696
+ *
1697
+ * # Example (JavaScript)
1698
+ *
1699
+ * ```js
1700
+ * frame.renameBlock("atoms", "particles");
1701
+ * ```
1702
+ * @param {string} old_key
1703
+ * @param {string} new_key
1704
+ * @returns {boolean}
1705
+ */
1706
+ renameBlock(old_key, new_key) {
1707
+ const ptr0 = passStringToWasm0(old_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1708
+ const len0 = WASM_VECTOR_LEN;
1709
+ const ptr1 = passStringToWasm0(new_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1710
+ const len1 = WASM_VECTOR_LEN;
1711
+ const ret = wasm.frame_renameBlock(this.__wbg_ptr, ptr0, len0, ptr1, len1);
1712
+ if (ret[2]) {
1713
+ throw takeFromExternrefTable0(ret[1]);
1714
+ }
1715
+ return ret[0] !== 0;
1716
+ }
1717
+ /**
1718
+ * Rename a column within a specific block.
1719
+ *
1720
+ * # Arguments
1721
+ *
1722
+ * * `block_key` - Name of the block containing the column
1723
+ * * `old_col` - Current column name
1724
+ * * `new_col` - New column name
1725
+ *
1726
+ * # Returns
1727
+ *
1728
+ * `true` if the column was found and renamed, `false` if
1729
+ * `old_col` did not exist in the block.
1730
+ *
1731
+ * # Errors
1732
+ *
1733
+ * Throws a `JsValue` string if the frame or block does not exist.
1734
+ *
1735
+ * # Example (JavaScript)
1736
+ *
1737
+ * ```js
1738
+ * frame.renameColumn("atoms", "element", "symbol");
1739
+ * ```
1740
+ * @param {string} block_key
1741
+ * @param {string} old_col
1742
+ * @param {string} new_col
1743
+ * @returns {boolean}
1744
+ */
1745
+ renameColumn(block_key, old_col, new_col) {
1746
+ const ptr0 = passStringToWasm0(block_key, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1747
+ const len0 = WASM_VECTOR_LEN;
1748
+ const ptr1 = passStringToWasm0(old_col, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1749
+ const len1 = WASM_VECTOR_LEN;
1750
+ const ptr2 = passStringToWasm0(new_col, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1751
+ const len2 = WASM_VECTOR_LEN;
1752
+ const ret = wasm.frame_renameColumn(this.__wbg_ptr, ptr0, len0, ptr1, len1, ptr2, len2);
1753
+ if (ret[2]) {
1754
+ throw takeFromExternrefTable0(ret[1]);
1755
+ }
1756
+ return ret[0] !== 0;
1757
+ }
1758
+ /**
1759
+ * Attach or detach a simulation box.
1760
+ *
1761
+ * Pass a [`Box`](super::region::simbox::Box) to attach, or
1762
+ * `undefined`/`null` to detach.
1763
+ *
1764
+ * # Arguments
1765
+ *
1766
+ * * `simbox` - The simulation box, or `undefined`/`null` to remove it
1767
+ *
1768
+ * # Errors
1769
+ *
1770
+ * Throws a `JsValue` string if the frame has been dropped.
1771
+ *
1772
+ * # Example (JavaScript)
1773
+ *
1774
+ * ```js
1775
+ * const origin = new Float32Array([0, 0, 0]);
1776
+ * frame.simbox = Box.cube(10.0, origin, true, true, true);
1777
+ * ```
1778
+ * @param {Box | null} [simbox]
1779
+ */
1780
+ set simbox(simbox) {
1781
+ let ptr0 = 0;
1782
+ if (!isLikeNone(simbox)) {
1783
+ _assertClass(simbox, Box);
1784
+ ptr0 = simbox.__destroy_into_raw();
1785
+ }
1786
+ const ret = wasm.frame_set_simbox(this.__wbg_ptr, ptr0);
1787
+ if (ret[1]) {
1788
+ throw takeFromExternrefTable0(ret[0]);
1789
+ }
1790
+ }
1791
+ /**
1792
+ * Get the simulation box attached to this frame (if any).
1793
+ *
1794
+ * # Returns
1795
+ *
1796
+ * The [`Box`](super::region::simbox::Box) if one has been set,
1797
+ * or `undefined` otherwise.
1798
+ *
1799
+ * # Example (JavaScript)
1800
+ *
1801
+ * ```js
1802
+ * const box = frame.simbox;
1803
+ * if (box) {
1804
+ * console.log("Volume:", box.volume());
1805
+ * }
1806
+ * ```
1807
+ * @returns {Box | undefined}
1808
+ */
1809
+ get simbox() {
1810
+ const ret = wasm.frame_simbox(this.__wbg_ptr);
1811
+ return ret === 0 ? undefined : Box.__wrap(ret);
1812
+ }
1813
+ }
1814
+ if (Symbol.dispose) Frame.prototype[Symbol.dispose] = Frame.prototype.free;
1815
+
1816
+ /**
1817
+ * LAMMPS data file reader.
1818
+ *
1819
+ * Reads LAMMPS data files (the format written by `write_data`). The
1820
+ * reader produces a [`Frame`] containing:
1821
+ *
1822
+ * - `"atoms"` block: `type` (i32), `x`, `y`, `z` (f32, angstrom),
1823
+ * and optionally `charge` (f32)
1824
+ * - `"bonds"` block (if present): `i`, `j` (u32), `type` (i32)
1825
+ * - Simulation box (`simbox`) with PBC
1826
+ *
1827
+ * Only a single frame is supported (`step = 0`).
1828
+ *
1829
+ * # Example (JavaScript)
1830
+ *
1831
+ * ```js
1832
+ * const reader = new LAMMPSReader(dataFileContent);
1833
+ * const frame = reader.read(0);
1834
+ * const atoms = frame.getBlock("atoms");
1835
+ * const bonds = frame.getBlock("bonds");
1836
+ * const box = frame.simbox;
1837
+ * ```
1838
+ */
1839
+ export class LAMMPSReader {
1840
+ __destroy_into_raw() {
1841
+ const ptr = this.__wbg_ptr;
1842
+ this.__wbg_ptr = 0;
1843
+ LAMMPSReaderFinalization.unregister(this);
1844
+ return ptr;
1845
+ }
1846
+ free() {
1847
+ const ptr = this.__destroy_into_raw();
1848
+ wasm.__wbg_lammpsreader_free(ptr, 0);
1849
+ }
1850
+ /**
1851
+ * Check whether the file contains no valid frames.
1852
+ *
1853
+ * # Errors
1854
+ *
1855
+ * Throws a `JsValue` string on parse errors.
1856
+ * @returns {boolean}
1857
+ */
1858
+ isEmpty() {
1859
+ const ret = wasm.lammpsreader_isEmpty(this.__wbg_ptr);
1860
+ if (ret[2]) {
1861
+ throw takeFromExternrefTable0(ret[1]);
1862
+ }
1863
+ return ret[0] !== 0;
1864
+ }
1865
+ /**
1866
+ * Return the number of frames (always 0 or 1 for LAMMPS data files).
1867
+ *
1868
+ * # Errors
1869
+ *
1870
+ * Throws a `JsValue` string on parse errors.
1871
+ * @returns {number}
1872
+ */
1873
+ len() {
1874
+ const ret = wasm.lammpsreader_len(this.__wbg_ptr);
1875
+ if (ret[2]) {
1876
+ throw takeFromExternrefTable0(ret[1]);
1877
+ }
1878
+ return ret[0] >>> 0;
1879
+ }
1880
+ /**
1881
+ * Create a new LAMMPS data file reader from string content.
1882
+ *
1883
+ * # Arguments
1884
+ *
1885
+ * * `content` - The full text content of a LAMMPS data file
1886
+ *
1887
+ * # Example (JavaScript)
1888
+ *
1889
+ * ```js
1890
+ * const reader = new LAMMPSReader(dataFileString);
1891
+ * ```
1892
+ * @param {string} content
1893
+ */
1894
+ constructor(content) {
1895
+ const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
1896
+ const len0 = WASM_VECTOR_LEN;
1897
+ const ret = wasm.lammpsreader_new(ptr0, len0);
1898
+ this.__wbg_ptr = ret >>> 0;
1899
+ LAMMPSReaderFinalization.register(this, this.__wbg_ptr, this);
1900
+ return this;
1901
+ }
1902
+ /**
1903
+ * Read the frame at the given step index.
1904
+ *
1905
+ * LAMMPS data files contain a single configuration, so only
1906
+ * `step = 0` is valid. Passing any other step returns `undefined`.
1907
+ *
1908
+ * # Arguments
1909
+ *
1910
+ * * `step` - Frame index (must be `0`)
1911
+ *
1912
+ * # Returns
1913
+ *
1914
+ * A [`Frame`] with atoms, optional bonds, and simbox, or `undefined`.
1915
+ *
1916
+ * # Errors
1917
+ *
1918
+ * Throws a `JsValue` string on parse errors.
1919
+ *
1920
+ * # Example (JavaScript)
1921
+ *
1922
+ * ```js
1923
+ * const frame = reader.read(0);
1924
+ * ```
1925
+ * @param {number} step
1926
+ * @returns {Frame | undefined}
1927
+ */
1928
+ read(step) {
1929
+ const ret = wasm.lammpsreader_read(this.__wbg_ptr, step);
1930
+ if (ret[2]) {
1931
+ throw takeFromExternrefTable0(ret[1]);
1932
+ }
1933
+ return ret[0] === 0 ? undefined : Frame.__wrap(ret[0]);
1934
+ }
1935
+ }
1936
+ if (Symbol.dispose) LAMMPSReader.prototype[Symbol.dispose] = LAMMPSReader.prototype.free;
1937
+
1938
+ /**
1939
+ * Mean squared displacement (MSD) relative to a reference configuration.
1940
+ *
1941
+ * Computes MSD = <|r(t) - r(0)|^2> for each particle and the
1942
+ * system average. Useful for measuring diffusion coefficients
1943
+ * via the Einstein relation D = MSD / (6t).
1944
+ *
1945
+ * All distances are in angstrom (A), so MSD is in A^2.
1946
+ *
1947
+ * # Example (JavaScript)
1948
+ *
1949
+ * ```js
1950
+ * const msd = MSD.fromReference(refFrame);
1951
+ *
1952
+ * for (let t = 0; t < nFrames; t++) {
1953
+ * const frame = reader.read(t);
1954
+ * const result = msd.compute(frame);
1955
+ * console.log(`t=${t}: MSD = ${result.mean} A^2`);
1956
+ * }
1957
+ * ```
1958
+ *
1959
+ * # References
1960
+ *
1961
+ * - Einstein, A. (1905). *Annalen der Physik*, 322(8), 549-560.
1962
+ */
1963
+ export class MSD {
1964
+ static __wrap(ptr) {
1965
+ ptr = ptr >>> 0;
1966
+ const obj = Object.create(MSD.prototype);
1967
+ obj.__wbg_ptr = ptr;
1968
+ MSDFinalization.register(obj, obj.__wbg_ptr, obj);
1969
+ return obj;
1970
+ }
1971
+ __destroy_into_raw() {
1972
+ const ptr = this.__wbg_ptr;
1973
+ this.__wbg_ptr = 0;
1974
+ MSDFinalization.unregister(this);
1975
+ return ptr;
1976
+ }
1977
+ free() {
1978
+ const ptr = this.__destroy_into_raw();
1979
+ wasm.__wbg_msd_free(ptr, 0);
1980
+ }
1981
+ /**
1982
+ * Compute MSD for a frame relative to the stored reference.
1983
+ *
1984
+ * # Arguments
1985
+ *
1986
+ * * `frame` - Current frame with `"atoms"` block containing
1987
+ * `x`, `y`, `z` (f32) columns
1988
+ *
1989
+ * # Returns
1990
+ *
1991
+ * An [`MSDResult`] with per-particle and system-average MSD
1992
+ * values in A^2.
1993
+ *
1994
+ * # Errors
1995
+ *
1996
+ * Throws if the frame is missing required columns.
1997
+ *
1998
+ * # Example (JavaScript)
1999
+ *
2000
+ * ```js
2001
+ * const result = msd.compute(currentFrame);
2002
+ * console.log(result.mean); // system-average MSD in A^2
2003
+ * ```
2004
+ * @param {Frame} frame
2005
+ * @returns {MSDResult}
2006
+ */
2007
+ compute(frame) {
2008
+ _assertClass(frame, Frame);
2009
+ const ret = wasm.msd_compute(this.__wbg_ptr, frame.__wbg_ptr);
2010
+ if (ret[2]) {
2011
+ throw takeFromExternrefTable0(ret[1]);
2012
+ }
2013
+ return MSDResult.__wrap(ret[0]);
2014
+ }
2015
+ /**
2016
+ * Create an MSD analysis from a reference (t=0) frame.
2017
+ *
2018
+ * The reference frame's `"atoms"` block must have `x`, `y`, `z`
2019
+ * (f32) columns. These positions are stored internally and used
2020
+ * as the baseline for all subsequent `compute()` calls.
2021
+ *
2022
+ * # Arguments
2023
+ *
2024
+ * * `ref_frame` - Reference frame (typically the initial
2025
+ * configuration at t=0)
2026
+ *
2027
+ * # Returns
2028
+ *
2029
+ * A new `MSD` instance.
2030
+ *
2031
+ * # Errors
2032
+ *
2033
+ * Throws if the frame is missing required columns.
2034
+ *
2035
+ * # Example (JavaScript)
2036
+ *
2037
+ * ```js
2038
+ * const msd = MSD.fromReference(initialFrame);
2039
+ * ```
2040
+ * @param {Frame} ref_frame
2041
+ * @returns {MSD}
2042
+ */
2043
+ static fromReference(ref_frame) {
2044
+ _assertClass(ref_frame, Frame);
2045
+ const ret = wasm.msd_fromReference(ref_frame.__wbg_ptr);
2046
+ if (ret[2]) {
2047
+ throw takeFromExternrefTable0(ret[1]);
2048
+ }
2049
+ return MSD.__wrap(ret[0]);
2050
+ }
2051
+ }
2052
+ if (Symbol.dispose) MSD.prototype[Symbol.dispose] = MSD.prototype.free;
2053
+
2054
+ /**
2055
+ * Result of a mean squared displacement computation.
2056
+ *
2057
+ * # Example (JavaScript)
2058
+ *
2059
+ * ```js
2060
+ * const result = msd.compute(frame);
2061
+ * console.log(result.mean); // number (A^2)
2062
+ * console.log(result.perParticle()); // Float32Array (A^2)
2063
+ * ```
2064
+ */
2065
+ export class MSDResult {
2066
+ static __wrap(ptr) {
2067
+ ptr = ptr >>> 0;
2068
+ const obj = Object.create(MSDResult.prototype);
2069
+ obj.__wbg_ptr = ptr;
2070
+ MSDResultFinalization.register(obj, obj.__wbg_ptr, obj);
2071
+ return obj;
2072
+ }
2073
+ __destroy_into_raw() {
2074
+ const ptr = this.__wbg_ptr;
2075
+ this.__wbg_ptr = 0;
2076
+ MSDResultFinalization.unregister(this);
2077
+ return ptr;
2078
+ }
2079
+ free() {
2080
+ const ptr = this.__destroy_into_raw();
2081
+ wasm.__wbg_msdresult_free(ptr, 0);
2082
+ }
2083
+ /**
2084
+ * System-average mean squared displacement in A^2.
2085
+ *
2086
+ * This is the arithmetic mean of all per-particle squared
2087
+ * displacements: `mean = sum(|r_i(t) - r_i(0)|^2) / N`.
2088
+ * @returns {number}
2089
+ */
2090
+ get mean() {
2091
+ const ret = wasm.msdresult_mean(this.__wbg_ptr);
2092
+ return ret;
2093
+ }
2094
+ /**
2095
+ * Per-particle squared displacements as `Float32Array` in A^2.
2096
+ *
2097
+ * `perParticle()[i]` is `|r_i(t) - r_i(0)|^2` for particle `i`.
2098
+ * Length equals the number of atoms.
2099
+ * @returns {Float32Array}
2100
+ */
2101
+ perParticle() {
2102
+ const ret = wasm.msdresult_perParticle(this.__wbg_ptr);
2103
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
2104
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2105
+ return v1;
2106
+ }
2107
+ }
2108
+ if (Symbol.dispose) MSDResult.prototype[Symbol.dispose] = MSDResult.prototype.free;
2109
+
2110
+ /**
2111
+ * Result of a neighbor search: all atom pairs within a distance cutoff.
2112
+ *
2113
+ * Contains pair indices, distances, and squared distances for every
2114
+ * neighbor pair found. This object is produced by [`AABBQuery`] or
2115
+ * [`NeighborSearch`] and consumed by analysis classes like [`RDF`]
2116
+ * and [`Cluster`].
2117
+ *
2118
+ * # Properties
2119
+ *
2120
+ * | Property | Type | Description |
2121
+ * |----------|------|-------------|
2122
+ * | `numPairs` | `number` | Total number of neighbor pairs |
2123
+ * | `numPoints` | `number` | Number of reference points |
2124
+ * | `numQueryPoints` | `number` | Number of query points |
2125
+ * | `isSelfQuery` | `boolean` | Whether this is a self-query result |
2126
+ *
2127
+ * # Example (JavaScript)
2128
+ *
2129
+ * ```js
2130
+ * const nlist = nq.querySelf();
2131
+ * console.log(nlist.numPairs);
2132
+ *
2133
+ * const i = nlist.queryPointIndices(); // Uint32Array
2134
+ * const j = nlist.pointIndices(); // Uint32Array
2135
+ * const d = nlist.distances(); // Float32Array (in A)
2136
+ * ```
2137
+ */
2138
+ export class NeighborList {
2139
+ static __wrap(ptr) {
2140
+ ptr = ptr >>> 0;
2141
+ const obj = Object.create(NeighborList.prototype);
2142
+ obj.__wbg_ptr = ptr;
2143
+ NeighborListFinalization.register(obj, obj.__wbg_ptr, obj);
2144
+ return obj;
2145
+ }
2146
+ __destroy_into_raw() {
2147
+ const ptr = this.__wbg_ptr;
2148
+ this.__wbg_ptr = 0;
2149
+ NeighborListFinalization.unregister(this);
2150
+ return ptr;
2151
+ }
2152
+ free() {
2153
+ const ptr = this.__destroy_into_raw();
2154
+ wasm.__wbg_neighborlist_free(ptr, 0);
2155
+ }
2156
+ /**
2157
+ * Squared pairwise distances in A^2, as a `Float32Array`.
2158
+ *
2159
+ * More efficient than `distances()` when you only need to
2160
+ * compare or threshold distances.
2161
+ * @returns {Float32Array}
2162
+ */
2163
+ distSq() {
2164
+ const ret = wasm.neighborlist_distSq(this.__wbg_ptr);
2165
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
2166
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2167
+ return v1;
2168
+ }
2169
+ /**
2170
+ * Pairwise distances in angstrom (A), as a `Float32Array`.
2171
+ *
2172
+ * `distances()[k]` is the distance between query point
2173
+ * `queryPointIndices()[k]` and reference point `pointIndices()[k]`.
2174
+ * @returns {Float32Array}
2175
+ */
2176
+ distances() {
2177
+ const ret = wasm.neighborlist_distances(this.__wbg_ptr);
2178
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
2179
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2180
+ return v1;
2181
+ }
2182
+ /**
2183
+ * **Deprecated**: Use `queryPointIndices()` instead.
2184
+ *
2185
+ * First particle index per pair as `Uint32Array`.
2186
+ * @returns {Uint32Array}
2187
+ */
2188
+ idxI() {
2189
+ const ret = wasm.neighborlist_idxI(this.__wbg_ptr);
2190
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
2191
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2192
+ return v1;
2193
+ }
2194
+ /**
2195
+ * **Deprecated**: Use `pointIndices()` instead.
2196
+ *
2197
+ * Second particle index per pair as `Uint32Array`.
2198
+ * @returns {Uint32Array}
2199
+ */
2200
+ idxJ() {
2201
+ const ret = wasm.neighborlist_idxJ(this.__wbg_ptr);
2202
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
2203
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2204
+ return v1;
2205
+ }
2206
+ /**
2207
+ * Whether this result came from a self-query (`querySelf()`).
2208
+ *
2209
+ * In self-queries, only unique pairs `(i < j)` are reported.
2210
+ * @returns {boolean}
2211
+ */
2212
+ get isSelfQuery() {
2213
+ const ret = wasm.neighborlist_isSelfQuery(this.__wbg_ptr);
2214
+ return ret !== 0;
2215
+ }
2216
+ /**
2217
+ * Total number of neighbor pairs found.
2218
+ * @returns {number}
2219
+ */
2220
+ get numPairs() {
2221
+ const ret = wasm.neighborlist_numPairs(this.__wbg_ptr);
2222
+ return ret >>> 0;
2223
+ }
2224
+ /**
2225
+ * Number of reference (target) points in the search.
2226
+ * @returns {number}
2227
+ */
2228
+ get numPoints() {
2229
+ const ret = wasm.neighborlist_numPoints(this.__wbg_ptr);
2230
+ return ret >>> 0;
2231
+ }
2232
+ /**
2233
+ * Number of query points in the search.
2234
+ *
2235
+ * For self-queries, this equals `numPoints`.
2236
+ * @returns {number}
2237
+ */
2238
+ get numQueryPoints() {
2239
+ const ret = wasm.neighborlist_numQueryPoints(this.__wbg_ptr);
2240
+ return ret >>> 0;
2241
+ }
2242
+ /**
2243
+ * Reference point indices (`j`) for each pair, as a `Uint32Array`.
2244
+ * @returns {Uint32Array}
2245
+ */
2246
+ pointIndices() {
2247
+ const ret = wasm.neighborlist_pointIndices(this.__wbg_ptr);
2248
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
2249
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2250
+ return v1;
2251
+ }
2252
+ /**
2253
+ * Query point indices (`i`) for each pair, as a `Uint32Array`.
2254
+ *
2255
+ * The `k`-th pair connects query point `queryPointIndices()[k]`
2256
+ * to reference point `pointIndices()[k]`.
2257
+ * @returns {Uint32Array}
2258
+ */
2259
+ queryPointIndices() {
2260
+ const ret = wasm.neighborlist_queryPointIndices(this.__wbg_ptr);
2261
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
2262
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2263
+ return v1;
2264
+ }
2265
+ }
2266
+ if (Symbol.dispose) NeighborList.prototype[Symbol.dispose] = NeighborList.prototype.free;
2267
+
2268
+ /**
2269
+ * **Deprecated**: backward-compatible alias for [`NeighborList`].
2270
+ *
2271
+ * Use [`NeighborList`] instead. This type is kept only for API
2272
+ * compatibility with older code.
2273
+ */
2274
+ export class NeighborResult {
2275
+ __destroy_into_raw() {
2276
+ const ptr = this.__wbg_ptr;
2277
+ this.__wbg_ptr = 0;
2278
+ NeighborResultFinalization.unregister(this);
2279
+ return ptr;
2280
+ }
2281
+ free() {
2282
+ const ptr = this.__destroy_into_raw();
2283
+ wasm.__wbg_neighborresult_free(ptr, 0);
2284
+ }
2285
+ /**
2286
+ * Squared pairwise distances in A^2 as `Float32Array`.
2287
+ * @returns {Float32Array}
2288
+ */
2289
+ distSq() {
2290
+ const ret = wasm.neighborresult_distSq(this.__wbg_ptr);
2291
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
2292
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2293
+ return v1;
2294
+ }
2295
+ /**
2296
+ * First particle index per pair as `Uint32Array`.
2297
+ * @returns {Uint32Array}
2298
+ */
2299
+ idxI() {
2300
+ const ret = wasm.neighborresult_idxI(this.__wbg_ptr);
2301
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
2302
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2303
+ return v1;
2304
+ }
2305
+ /**
2306
+ * Second particle index per pair as `Uint32Array`.
2307
+ * @returns {Uint32Array}
2308
+ */
2309
+ idxJ() {
2310
+ const ret = wasm.neighborresult_idxJ(this.__wbg_ptr);
2311
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
2312
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2313
+ return v1;
2314
+ }
2315
+ /**
2316
+ * Total number of neighbor pairs found.
2317
+ * @returns {number}
2318
+ */
2319
+ get numPairs() {
2320
+ const ret = wasm.neighborresult_numPairs(this.__wbg_ptr);
2321
+ return ret >>> 0;
2322
+ }
2323
+ }
2324
+ if (Symbol.dispose) NeighborResult.prototype[Symbol.dispose] = NeighborResult.prototype.free;
2325
+
2326
+ /**
2327
+ * Neighbor search using the cell-list (link-cell) algorithm.
2328
+ *
2329
+ * This is a simpler, backward-compatible interface compared to
2330
+ * [`AABBQuery`]. It performs a self-query in a single `build()` call.
2331
+ *
2332
+ * Prefer [`AABBQuery`] for more flexibility (cross-queries, reusable
2333
+ * spatial index).
2334
+ *
2335
+ * # Example (JavaScript)
2336
+ *
2337
+ * ```js
2338
+ * const ns = new NeighborSearch(3.0); // cutoff = 3.0 A
2339
+ * const nbrs = ns.build(frame);
2340
+ * console.log(nbrs.numPairs);
2341
+ * ```
2342
+ */
2343
+ export class NeighborSearch {
2344
+ __destroy_into_raw() {
2345
+ const ptr = this.__wbg_ptr;
2346
+ this.__wbg_ptr = 0;
2347
+ NeighborSearchFinalization.unregister(this);
2348
+ return ptr;
2349
+ }
2350
+ free() {
2351
+ const ptr = this.__destroy_into_raw();
2352
+ wasm.__wbg_neighborsearch_free(ptr, 0);
2353
+ }
2354
+ /**
2355
+ * Build a neighbor list from a [`Frame`].
2356
+ *
2357
+ * Performs a self-query: finds all unique pairs `(i < j)` of atoms
2358
+ * within the cutoff distance, using the cell-list algorithm.
2359
+ *
2360
+ * The frame must have:
2361
+ * - An `"atoms"` block with `x`, `y`, `z` (f32) columns
2362
+ * - A `simbox` (simulation box) set on the frame
2363
+ *
2364
+ * # Arguments
2365
+ *
2366
+ * * `frame` - Frame with atom positions and simbox
2367
+ *
2368
+ * # Returns
2369
+ *
2370
+ * A [`NeighborList`] containing all pairs within the cutoff.
2371
+ *
2372
+ * # Errors
2373
+ *
2374
+ * Throws if the frame is missing required data.
2375
+ *
2376
+ * # Example (JavaScript)
2377
+ *
2378
+ * ```js
2379
+ * const nbrs = ns.build(frame);
2380
+ * const dists = nbrs.distances(); // Float32Array
2381
+ * ```
2382
+ * @param {Frame} frame
2383
+ * @returns {NeighborList}
2384
+ */
2385
+ build(frame) {
2386
+ _assertClass(frame, Frame);
2387
+ const ret = wasm.neighborsearch_build(this.__wbg_ptr, frame.__wbg_ptr);
2388
+ if (ret[2]) {
2389
+ throw takeFromExternrefTable0(ret[1]);
2390
+ }
2391
+ return NeighborList.__wrap(ret[0]);
2392
+ }
2393
+ /**
2394
+ * Create a neighbor search with the given distance cutoff.
2395
+ *
2396
+ * # Arguments
2397
+ *
2398
+ * * `cutoff` - Maximum neighbor distance in angstrom (A)
2399
+ *
2400
+ * # Example (JavaScript)
2401
+ *
2402
+ * ```js
2403
+ * const ns = new NeighborSearch(5.0);
2404
+ * ```
2405
+ * @param {number} cutoff
2406
+ */
2407
+ constructor(cutoff) {
2408
+ const ret = wasm.neighborsearch_new(cutoff);
2409
+ this.__wbg_ptr = ret >>> 0;
2410
+ NeighborSearchFinalization.register(this, this.__wbg_ptr, this);
2411
+ return this;
2412
+ }
2413
+ }
2414
+ if (Symbol.dispose) NeighborSearch.prototype[Symbol.dispose] = NeighborSearch.prototype.free;
2415
+
2416
+ /**
2417
+ * Protein Data Bank (PDB) file reader.
2418
+ *
2419
+ * PDB files contain a single molecular structure. The reader produces
2420
+ * a [`Frame`] with an `"atoms"` block containing columns such as
2421
+ * `name` (string), `resname` (string), `x`, `y`, `z` (f32, angstrom),
2422
+ * and optionally `occupancy` and `bfactor` (f32).
2423
+ *
2424
+ * # Example (JavaScript)
2425
+ *
2426
+ * ```js
2427
+ * const reader = new PDBReader(pdbContent);
2428
+ * const frame = reader.read(0);
2429
+ * const atoms = frame.getBlock("atoms");
2430
+ * const names = atoms.copyColStr("name"); // ["CA", "CB", ...]
2431
+ * const x = atoms.copyColF32("x");
2432
+ * ```
2433
+ */
2434
+ export class PDBReader {
2435
+ __destroy_into_raw() {
2436
+ const ptr = this.__wbg_ptr;
2437
+ this.__wbg_ptr = 0;
2438
+ PDBReaderFinalization.unregister(this);
2439
+ return ptr;
2440
+ }
2441
+ free() {
2442
+ const ptr = this.__destroy_into_raw();
2443
+ wasm.__wbg_pdbreader_free(ptr, 0);
2444
+ }
2445
+ /**
2446
+ * Check whether the file contains no valid frames.
2447
+ *
2448
+ * # Errors
2449
+ *
2450
+ * Throws a `JsValue` string on parse errors.
2451
+ * @returns {boolean}
2452
+ */
2453
+ isEmpty() {
2454
+ const ret = wasm.pdbreader_isEmpty(this.__wbg_ptr);
2455
+ if (ret[2]) {
2456
+ throw takeFromExternrefTable0(ret[1]);
2457
+ }
2458
+ return ret[0] !== 0;
2459
+ }
2460
+ /**
2461
+ * Return the number of frames (always 0 or 1 for PDB files).
2462
+ *
2463
+ * # Errors
2464
+ *
2465
+ * Throws a `JsValue` string on parse errors.
2466
+ * @returns {number}
2467
+ */
2468
+ len() {
2469
+ const ret = wasm.pdbreader_len(this.__wbg_ptr);
2470
+ if (ret[2]) {
2471
+ throw takeFromExternrefTable0(ret[1]);
2472
+ }
2473
+ return ret[0] >>> 0;
2474
+ }
2475
+ /**
2476
+ * Create a new PDB reader from a string containing the file content.
2477
+ *
2478
+ * # Arguments
2479
+ *
2480
+ * * `content` - The full text content of a PDB file
2481
+ *
2482
+ * # Example (JavaScript)
2483
+ *
2484
+ * ```js
2485
+ * const reader = new PDBReader(pdbString);
2486
+ * ```
2487
+ * @param {string} content
2488
+ */
2489
+ constructor(content) {
2490
+ const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
2491
+ const len0 = WASM_VECTOR_LEN;
2492
+ const ret = wasm.pdbreader_new(ptr0, len0);
2493
+ this.__wbg_ptr = ret >>> 0;
2494
+ PDBReaderFinalization.register(this, this.__wbg_ptr, this);
2495
+ return this;
2496
+ }
2497
+ /**
2498
+ * Read the frame at the given step index.
2499
+ *
2500
+ * PDB files contain a single structure, so only `step = 0` is
2501
+ * valid. Passing any other step returns `undefined`.
2502
+ *
2503
+ * # Arguments
2504
+ *
2505
+ * * `step` - Frame index (must be `0` for PDB files)
2506
+ *
2507
+ * # Returns
2508
+ *
2509
+ * A [`Frame`] if `step == 0` and the file is valid, or `undefined`.
2510
+ *
2511
+ * # Errors
2512
+ *
2513
+ * Throws a `JsValue` string on parse errors.
2514
+ *
2515
+ * # Example (JavaScript)
2516
+ *
2517
+ * ```js
2518
+ * const frame = reader.read(0);
2519
+ * ```
2520
+ * @param {number} step
2521
+ * @returns {Frame | undefined}
2522
+ */
2523
+ read(step) {
2524
+ const ret = wasm.pdbreader_read(this.__wbg_ptr, step);
2525
+ if (ret[2]) {
2526
+ throw takeFromExternrefTable0(ret[1]);
2527
+ }
2528
+ return ret[0] === 0 ? undefined : Frame.__wrap(ret[0]);
2529
+ }
2530
+ }
2531
+ if (Symbol.dispose) PDBReader.prototype[Symbol.dispose] = PDBReader.prototype.free;
2532
+
2533
+ /**
2534
+ * Radial distribution function g(r) analysis.
2535
+ *
2536
+ * Computes the pair correlation function by binning neighbor-pair
2537
+ * distances into a histogram and normalizing by the ideal-gas
2538
+ * density (spherical shell volume normalization).
2539
+ *
2540
+ * # Algorithm
2541
+ *
2542
+ * g(r) = n(r) / (rho * V_shell(r) * N_ref)
2543
+ *
2544
+ * where `n(r)` is the pair count in bin `r`, `rho` is the number
2545
+ * density, and `V_shell(r)` is the shell volume for that bin.
2546
+ *
2547
+ * # Example (JavaScript)
2548
+ *
2549
+ * ```js
2550
+ * const nq = new AABBQuery(frame, 5.0);
2551
+ * const nlist = nq.querySelf();
2552
+ *
2553
+ * const rdf = new RDF(100, 5.0);
2554
+ * const result = rdf.compute(frame, nlist);
2555
+ *
2556
+ * const r = result.binCenters(); // Float32Array, bin centers in A
2557
+ * const gr = result.rdf(); // Float32Array, g(r) values
2558
+ * ```
2559
+ */
2560
+ export class RDF {
2561
+ __destroy_into_raw() {
2562
+ const ptr = this.__wbg_ptr;
2563
+ this.__wbg_ptr = 0;
2564
+ RDFFinalization.unregister(this);
2565
+ return ptr;
2566
+ }
2567
+ free() {
2568
+ const ptr = this.__destroy_into_raw();
2569
+ wasm.__wbg_rdf_free(ptr, 0);
2570
+ }
2571
+ /**
2572
+ * Compute the RDF from a pre-built neighbor list.
2573
+ *
2574
+ * The frame is needed to read the simulation box volume for
2575
+ * normalization.
2576
+ *
2577
+ * # Arguments
2578
+ *
2579
+ * * `frame` - Frame with a `simbox` set (for volume normalization)
2580
+ * * `neighbors` - Pre-built [`NeighborList`] from [`AABBQuery`]
2581
+ * or [`NeighborSearch`]
2582
+ *
2583
+ * # Returns
2584
+ *
2585
+ * An [`RDFResult`] containing bin centers, g(r) values, and raw
2586
+ * pair counts.
2587
+ *
2588
+ * # Errors
2589
+ *
2590
+ * Throws if the frame cannot be cloned or the computation fails.
2591
+ *
2592
+ * # Example (JavaScript)
2593
+ *
2594
+ * ```js
2595
+ * const result = rdf.compute(frame, nlist);
2596
+ * const gr = result.rdf(); // Float32Array
2597
+ * ```
2598
+ * @param {Frame} frame
2599
+ * @param {NeighborList} neighbors
2600
+ * @returns {RDFResult}
2601
+ */
2602
+ compute(frame, neighbors) {
2603
+ _assertClass(frame, Frame);
2604
+ _assertClass(neighbors, NeighborList);
2605
+ const ret = wasm.rdf_compute(this.__wbg_ptr, frame.__wbg_ptr, neighbors.__wbg_ptr);
2606
+ if (ret[2]) {
2607
+ throw takeFromExternrefTable0(ret[1]);
2608
+ }
2609
+ return RDFResult.__wrap(ret[0]);
2610
+ }
2611
+ /**
2612
+ * Create a new RDF analysis with specified binning.
2613
+ *
2614
+ * # Arguments
2615
+ *
2616
+ * * `n_bins` - Number of histogram bins
2617
+ * * `r_max` - Maximum radial distance in angstrom (A). Should
2618
+ * match or be less than the neighbor-search cutoff.
2619
+ *
2620
+ * # Example (JavaScript)
2621
+ *
2622
+ * ```js
2623
+ * const rdf = new RDF(100, 5.0); // 100 bins up to 5 A
2624
+ * ```
2625
+ * @param {number} n_bins
2626
+ * @param {number} r_max
2627
+ */
2628
+ constructor(n_bins, r_max) {
2629
+ const ret = wasm.rdf_new(n_bins, r_max);
2630
+ this.__wbg_ptr = ret >>> 0;
2631
+ RDFFinalization.register(this, this.__wbg_ptr, this);
2632
+ return this;
2633
+ }
2634
+ }
2635
+ if (Symbol.dispose) RDF.prototype[Symbol.dispose] = RDF.prototype.free;
2636
+
2637
+ /**
2638
+ * Result of a radial distribution function computation.
2639
+ *
2640
+ * Contains the binned g(r) values, bin geometry, raw pair counts,
2641
+ * and normalization metadata.
2642
+ *
2643
+ * # Example (JavaScript)
2644
+ *
2645
+ * ```js
2646
+ * const result = rdf.compute(frame, nlist);
2647
+ * const r = result.binCenters(); // Float32Array [0.025, 0.075, ...]
2648
+ * const gr = result.rdf(); // Float32Array, normalized g(r)
2649
+ * const nr = result.pairCounts(); // Float32Array, raw counts
2650
+ * console.log("Volume:", result.volume, "A^3");
2651
+ * console.log("N_ref:", result.numPoints);
2652
+ * ```
2653
+ */
2654
+ export class RDFResult {
2655
+ static __wrap(ptr) {
2656
+ ptr = ptr >>> 0;
2657
+ const obj = Object.create(RDFResult.prototype);
2658
+ obj.__wbg_ptr = ptr;
2659
+ RDFResultFinalization.register(obj, obj.__wbg_ptr, obj);
2660
+ return obj;
2661
+ }
2662
+ __destroy_into_raw() {
2663
+ const ptr = this.__wbg_ptr;
2664
+ this.__wbg_ptr = 0;
2665
+ RDFResultFinalization.unregister(this);
2666
+ return ptr;
2667
+ }
2668
+ free() {
2669
+ const ptr = this.__destroy_into_raw();
2670
+ wasm.__wbg_rdfresult_free(ptr, 0);
2671
+ }
2672
+ /**
2673
+ * Bin center positions as `Float32Array` in angstrom (A).
2674
+ *
2675
+ * Length equals `n_bins` (the value passed to the `RDF` constructor).
2676
+ * @returns {Float32Array}
2677
+ */
2678
+ binCenters() {
2679
+ const ret = wasm.rdfresult_binCenters(this.__wbg_ptr);
2680
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
2681
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2682
+ return v1;
2683
+ }
2684
+ /**
2685
+ * Bin edge positions as `Float32Array` in angstrom (A).
2686
+ *
2687
+ * Length is `n_bins + 1` (one more than bin centers).
2688
+ * @returns {Float32Array}
2689
+ */
2690
+ binEdges() {
2691
+ const ret = wasm.rdfresult_binEdges(this.__wbg_ptr);
2692
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
2693
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2694
+ return v1;
2695
+ }
2696
+ /**
2697
+ * Number of reference points used in the normalization.
2698
+ * @returns {number}
2699
+ */
2700
+ get numPoints() {
2701
+ const ret = wasm.rdfresult_numPoints(this.__wbg_ptr);
2702
+ return ret >>> 0;
2703
+ }
2704
+ /**
2705
+ * Raw (un-normalized) pair counts per bin as `Float32Array`.
2706
+ * @returns {Float32Array}
2707
+ */
2708
+ pairCounts() {
2709
+ const ret = wasm.rdfresult_pairCounts(this.__wbg_ptr);
2710
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
2711
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2712
+ return v1;
2713
+ }
2714
+ /**
2715
+ * Normalized g(r) values as `Float32Array` (dimensionless).
2716
+ *
2717
+ * A uniform ideal gas has g(r) = 1.0 everywhere. Peaks indicate
2718
+ * preferred interatomic distances (coordination shells).
2719
+ * @returns {Float32Array}
2720
+ */
2721
+ rdf() {
2722
+ const ret = wasm.rdfresult_rdf(this.__wbg_ptr);
2723
+ var v1 = getArrayF32FromWasm0(ret[0], ret[1]).slice();
2724
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
2725
+ return v1;
2726
+ }
2727
+ /**
2728
+ * Simulation box volume used in the normalization, in A^3.
2729
+ * @returns {number}
2730
+ */
2731
+ get volume() {
2732
+ const ret = wasm.rdfresult_volume(this.__wbg_ptr);
2733
+ return ret;
2734
+ }
2735
+ }
2736
+ if (Symbol.dispose) RDFResult.prototype[Symbol.dispose] = RDFResult.prototype.free;
2737
+
2738
+ /**
2739
+ * Reader for Zarr V3 simulation archives.
2740
+ *
2741
+ * Wraps [`SimulationStore`] from `molrs-core` for reading trajectory
2742
+ * frames and system metadata from an in-memory Zarr store. The store
2743
+ * is populated from a `Map<string, Uint8Array>` of file paths to
2744
+ * binary content.
2745
+ *
2746
+ * # Example (JavaScript)
2747
+ *
2748
+ * ```js
2749
+ * const files = new Map();
2750
+ * files.set("zarr.json", new Uint8Array([...]));
2751
+ * files.set("system/.zarray", new Uint8Array([...]));
2752
+ * // ... etc.
2753
+ *
2754
+ * const reader = new SimulationReader(files);
2755
+ * const frame = reader.readFrame(0);
2756
+ * ```
2757
+ */
2758
+ export class SimulationReader {
2759
+ __destroy_into_raw() {
2760
+ const ptr = this.__wbg_ptr;
2761
+ this.__wbg_ptr = 0;
2762
+ SimulationReaderFinalization.unregister(this);
2763
+ return ptr;
2764
+ }
2765
+ free() {
2766
+ const ptr = this.__destroy_into_raw();
2767
+ wasm.__wbg_simulationreader_free(ptr, 0);
2768
+ }
2769
+ /**
2770
+ * Return the number of atoms in the system topology.
2771
+ *
2772
+ * # Example (JavaScript)
2773
+ *
2774
+ * ```js
2775
+ * console.log(reader.countAtoms()); // e.g., 256
2776
+ * ```
2777
+ * @returns {number}
2778
+ */
2779
+ countAtoms() {
2780
+ const ret = wasm.simulationreader_countAtoms(this.__wbg_ptr);
2781
+ return ret >>> 0;
2782
+ }
2783
+ /**
2784
+ * Return the number of trajectory frames in the archive.
2785
+ *
2786
+ * Returns `0` if no trajectory data is present.
2787
+ *
2788
+ * # Errors
2789
+ *
2790
+ * Throws a `JsValue` string on I/O errors.
2791
+ *
2792
+ * # Example (JavaScript)
2793
+ *
2794
+ * ```js
2795
+ * console.log(reader.countFrames()); // e.g., 1000
2796
+ * ```
2797
+ * @returns {number}
2798
+ */
2799
+ countFrames() {
2800
+ const ret = wasm.simulationreader_countFrames(this.__wbg_ptr);
2801
+ if (ret[2]) {
2802
+ throw takeFromExternrefTable0(ret[1]);
2803
+ }
2804
+ return ret[0] >>> 0;
2805
+ }
2806
+ /**
2807
+ * Create a reader from a map of file paths to binary content.
2808
+ *
2809
+ * The map keys are relative paths within the Zarr archive
2810
+ * (e.g., `"zarr.json"`, `"system/.zarray"`). Values are the
2811
+ * raw bytes of each file as `Uint8Array`.
2812
+ *
2813
+ * # Arguments
2814
+ *
2815
+ * * `files` - `Map<string, Uint8Array>` mapping archive paths
2816
+ * to their binary content
2817
+ *
2818
+ * # Returns
2819
+ *
2820
+ * A new `SimulationReader` ready to read frames.
2821
+ *
2822
+ * # Errors
2823
+ *
2824
+ * Throws a `JsValue` string if the archive cannot be opened
2825
+ * (e.g., missing required metadata files).
2826
+ *
2827
+ * # Example (JavaScript)
2828
+ *
2829
+ * ```js
2830
+ * const reader = new SimulationReader(filesMap);
2831
+ * ```
2832
+ * @param {Map<any, any>} files
2833
+ */
2834
+ constructor(files) {
2835
+ const ret = wasm.simulationreader_new(files);
2836
+ if (ret[2]) {
2837
+ throw takeFromExternrefTable0(ret[1]);
2838
+ }
2839
+ this.__wbg_ptr = ret[0] >>> 0;
2840
+ SimulationReaderFinalization.register(this, this.__wbg_ptr, this);
2841
+ return this;
2842
+ }
2843
+ /**
2844
+ * Read a trajectory frame at the given time index.
2845
+ *
2846
+ * The returned [`Frame`] merges the static system topology
2847
+ * (atoms, bonds) with the per-frame trajectory data (positions,
2848
+ * velocities, etc.) at time step `t`.
2849
+ *
2850
+ * # Arguments
2851
+ *
2852
+ * * `t` - Zero-based time step index
2853
+ *
2854
+ * # Returns
2855
+ *
2856
+ * A [`Frame`] with merged system + trajectory data, or `undefined`
2857
+ * if no trajectory is present.
2858
+ *
2859
+ * # Errors
2860
+ *
2861
+ * Throws a `JsValue` string on I/O or deserialization errors.
2862
+ *
2863
+ * # Example (JavaScript)
2864
+ *
2865
+ * ```js
2866
+ * const frame = reader.readFrame(0);
2867
+ * if (frame) {
2868
+ * const x = frame.getBlock("atoms").copyColF32("x");
2869
+ * }
2870
+ * ```
2871
+ * @param {number} t
2872
+ * @returns {Frame | undefined}
2873
+ */
2874
+ readFrame(t) {
2875
+ const ret = wasm.simulationreader_readFrame(this.__wbg_ptr, t);
2876
+ if (ret[2]) {
2877
+ throw takeFromExternrefTable0(ret[1]);
2878
+ }
2879
+ return ret[0] === 0 ? undefined : Frame.__wrap(ret[0]);
2880
+ }
2881
+ }
2882
+ if (Symbol.dispose) SimulationReader.prototype[Symbol.dispose] = SimulationReader.prototype.free;
2883
+
2884
+ /**
2885
+ * Intermediate representation of a parsed SMILES string.
2886
+ *
2887
+ * Holds the molecular graph(s) parsed from a SMILES string. A single
2888
+ * SMILES string can encode multiple disconnected molecules separated
2889
+ * by `.` (e.g., `"[Na+].[Cl-]"`).
2890
+ *
2891
+ * Call [`toFrame()`](WasmSmilesIR::to_frame) to convert to a [`Frame`]
2892
+ * with `"atoms"` and `"bonds"` blocks.
2893
+ *
2894
+ * # Example (JavaScript)
2895
+ *
2896
+ * ```js
2897
+ * const ir = parseSMILES("CCO");
2898
+ * console.log(ir.nComponents); // 1
2899
+ *
2900
+ * const frame = ir.toFrame();
2901
+ * const atoms = frame.getBlock("atoms");
2902
+ * console.log(atoms.copyColStr("symbol")); // ["C", "C", "O", "H", ...]
2903
+ * ```
2904
+ */
2905
+ export class SmilesIR {
2906
+ static __wrap(ptr) {
2907
+ ptr = ptr >>> 0;
2908
+ const obj = Object.create(SmilesIR.prototype);
2909
+ obj.__wbg_ptr = ptr;
2910
+ SmilesIRFinalization.register(obj, obj.__wbg_ptr, obj);
2911
+ return obj;
2912
+ }
2913
+ __destroy_into_raw() {
2914
+ const ptr = this.__wbg_ptr;
2915
+ this.__wbg_ptr = 0;
2916
+ SmilesIRFinalization.unregister(this);
2917
+ return ptr;
2918
+ }
2919
+ free() {
2920
+ const ptr = this.__destroy_into_raw();
2921
+ wasm.__wbg_smilesir_free(ptr, 0);
2922
+ }
2923
+ /**
2924
+ * Return the number of disconnected components in the SMILES.
2925
+ *
2926
+ * Components are separated by `.` in the SMILES string. For
2927
+ * example, `"[Na+].[Cl-]"` has 2 components.
2928
+ *
2929
+ * # Example (JavaScript)
2930
+ *
2931
+ * ```js
2932
+ * const ir = parseSMILES("[Na+].[Cl-]");
2933
+ * console.log(ir.nComponents); // 2
2934
+ * ```
2935
+ * @returns {number}
2936
+ */
2937
+ get nComponents() {
2938
+ const ret = wasm.smilesir_nComponents(this.__wbg_ptr);
2939
+ return ret >>> 0;
2940
+ }
2941
+ /**
2942
+ * Convert the intermediate representation to a [`Frame`].
2943
+ *
2944
+ * The resulting frame contains:
2945
+ *
2946
+ * - `"atoms"` block: `symbol` (string), and implicit hydrogens
2947
+ * are added. No 3D coordinates are present -- use
2948
+ * [`generate3D`](crate::generate_3d_wasm) to embed coordinates.
2949
+ * - `"bonds"` block: `i`, `j` (u32, zero-based atom indices),
2950
+ * `order` (f32, bond order: 1.0 = single, 1.5 = aromatic,
2951
+ * 2.0 = double, 3.0 = triple).
2952
+ *
2953
+ * # Returns
2954
+ *
2955
+ * A new [`Frame`] with atoms and bonds.
2956
+ *
2957
+ * # Errors
2958
+ *
2959
+ * Throws a `JsValue` string if the conversion fails (e.g.,
2960
+ * invalid valence).
2961
+ *
2962
+ * # Example (JavaScript)
2963
+ *
2964
+ * ```js
2965
+ * const frame = ir.toFrame();
2966
+ * const bonds = frame.getBlock("bonds");
2967
+ * const order = bonds.copyColF32("order");
2968
+ * ```
2969
+ * @returns {Frame}
2970
+ */
2971
+ toFrame() {
2972
+ const ret = wasm.smilesir_toFrame(this.__wbg_ptr);
2973
+ if (ret[2]) {
2974
+ throw takeFromExternrefTable0(ret[1]);
2975
+ }
2976
+ return Frame.__wrap(ret[0]);
2977
+ }
2978
+ }
2979
+ if (Symbol.dispose) SmilesIR.prototype[Symbol.dispose] = SmilesIR.prototype.free;
2980
+
2981
+ /**
2982
+ * Owned f32 array with ndarray-compatible shape metadata.
2983
+ *
2984
+ * Stores a flat `Vec<f32>` together with a shape descriptor (e.g.,
2985
+ * `[N, 3]` for an Nx3 coordinate matrix). Used for passing
2986
+ * multi-dimensional numeric data across the WASM boundary.
2987
+ *
2988
+ * # Memory layout
2989
+ *
2990
+ * Data is stored in row-major (C) order, matching ndarray's default
2991
+ * and JavaScript's `Float32Array` convention.
2992
+ *
2993
+ * # Example (JavaScript)
2994
+ *
2995
+ * ```js
2996
+ * // Create a 2x3 zero array
2997
+ * const arr = new WasmArray([2, 3]);
2998
+ * arr.writeFrom(new Float32Array([1,2,3, 4,5,6]));
2999
+ *
3000
+ * // Or from existing data
3001
+ * const arr2 = WasmArray.from(new Float32Array([1,2,3]), [1, 3]);
3002
+ *
3003
+ * // Get data back
3004
+ * const copy = arr.toCopy(); // safe owned copy
3005
+ * const view = arr.toTypedArray(); // zero-copy (invalidated on alloc)
3006
+ * ```
3007
+ */
3008
+ export class WasmArray {
3009
+ static __wrap(ptr) {
3010
+ ptr = ptr >>> 0;
3011
+ const obj = Object.create(WasmArray.prototype);
3012
+ obj.__wbg_ptr = ptr;
3013
+ WasmArrayFinalization.register(obj, obj.__wbg_ptr, obj);
3014
+ return obj;
3015
+ }
3016
+ __destroy_into_raw() {
3017
+ const ptr = this.__wbg_ptr;
3018
+ this.__wbg_ptr = 0;
3019
+ WasmArrayFinalization.unregister(this);
3020
+ return ptr;
3021
+ }
3022
+ free() {
3023
+ const ptr = this.__destroy_into_raw();
3024
+ wasm.__wbg_wasmarray_free(ptr, 0);
3025
+ }
3026
+ /**
3027
+ * Return the data type string. Always `"float"` for `WasmArray`.
3028
+ * @returns {string}
3029
+ */
3030
+ dtype() {
3031
+ let deferred1_0;
3032
+ let deferred1_1;
3033
+ try {
3034
+ const ret = wasm.wasmarray_dtype(this.__wbg_ptr);
3035
+ deferred1_0 = ret[0];
3036
+ deferred1_1 = ret[1];
3037
+ return getStringFromWasm0(ret[0], ret[1]);
3038
+ } finally {
3039
+ wasm.__wbindgen_free_command_export(deferred1_0, deferred1_1, 1);
3040
+ }
3041
+ }
3042
+ /**
3043
+ * Create a `WasmArray` from an existing JS `Float32Array`.
3044
+ *
3045
+ * # Arguments
3046
+ *
3047
+ * * `data` - Source `Float32Array`
3048
+ * * `shape` - Optional shape. If omitted, defaults to `[data.length]` (1D).
3049
+ *
3050
+ * # Returns
3051
+ *
3052
+ * A new `WasmArray` owning a copy of the data.
3053
+ *
3054
+ * # Errors
3055
+ *
3056
+ * Throws if `shape` product does not equal `data.length`.
3057
+ *
3058
+ * # Example (JavaScript)
3059
+ *
3060
+ * ```js
3061
+ * const arr = WasmArray.from(new Float32Array([1,2,3,4,5,6]), [2, 3]);
3062
+ * console.log(arr.shape()); // [2, 3]
3063
+ * ```
3064
+ * @param {Float32Array} data
3065
+ * @param {Uint32Array | null} [shape]
3066
+ * @returns {WasmArray}
3067
+ */
3068
+ static from(data, shape) {
3069
+ var ptr0 = isLikeNone(shape) ? 0 : passArray32ToWasm0(shape, wasm.__wbindgen_malloc_command_export);
3070
+ var len0 = WASM_VECTOR_LEN;
3071
+ const ret = wasm.wasmarray_from(data, ptr0, len0);
3072
+ if (ret[2]) {
3073
+ throw takeFromExternrefTable0(ret[1]);
3074
+ }
3075
+ return WasmArray.__wrap(ret[0]);
3076
+ }
3077
+ /**
3078
+ * Check whether the array contains no elements.
3079
+ * @returns {boolean}
3080
+ */
3081
+ is_empty() {
3082
+ const ret = wasm.wasmarray_is_empty(this.__wbg_ptr);
3083
+ return ret !== 0;
3084
+ }
3085
+ /**
3086
+ * Return the total number of elements (product of all shape dimensions).
3087
+ *
3088
+ * # Example (JavaScript)
3089
+ *
3090
+ * ```js
3091
+ * const arr = new WasmArray([10, 3]);
3092
+ * console.log(arr.len()); // 30
3093
+ * ```
3094
+ * @returns {number}
3095
+ */
3096
+ len() {
3097
+ const ret = wasm.wasmarray_len(this.__wbg_ptr);
3098
+ return ret >>> 0;
3099
+ }
3100
+ /**
3101
+ * Create a zero-initialized array with the given shape.
3102
+ *
3103
+ * The total number of elements is the product of all dimensions.
3104
+ *
3105
+ * # Arguments
3106
+ *
3107
+ * * `shape` - Array of dimension sizes (e.g., `[10, 3]` for 10 rows x 3 columns)
3108
+ *
3109
+ * # Example (JavaScript)
3110
+ *
3111
+ * ```js
3112
+ * const coords = new WasmArray([100, 3]); // 100 atoms, 3D
3113
+ * console.log(coords.len()); // 300
3114
+ * ```
3115
+ * @param {Uint32Array} shape
3116
+ */
3117
+ constructor(shape) {
3118
+ const ptr0 = passArray32ToWasm0(shape, wasm.__wbindgen_malloc_command_export);
3119
+ const len0 = WASM_VECTOR_LEN;
3120
+ const ret = wasm.wasmarray_new(ptr0, len0);
3121
+ this.__wbg_ptr = ret >>> 0;
3122
+ WasmArrayFinalization.register(this, this.__wbg_ptr, this);
3123
+ return this;
3124
+ }
3125
+ /**
3126
+ * Return a raw pointer to the underlying data buffer.
3127
+ *
3128
+ * This is intended for advanced interop with other WASM modules
3129
+ * that need direct memory access. The pointer is only valid as
3130
+ * long as this `WasmArray` is alive and no WASM memory growth
3131
+ * has occurred.
3132
+ * @returns {number}
3133
+ */
3134
+ ptr() {
3135
+ const ret = wasm.wasmarray_ptr(this.__wbg_ptr);
3136
+ return ret >>> 0;
3137
+ }
3138
+ /**
3139
+ * Return a copy of the shape metadata as a JS array.
3140
+ *
3141
+ * # Example (JavaScript)
3142
+ *
3143
+ * ```js
3144
+ * const s = arr.shape(); // e.g., [10, 3]
3145
+ * ```
3146
+ * @returns {Uint32Array}
3147
+ */
3148
+ shape() {
3149
+ const ret = wasm.wasmarray_shape(this.__wbg_ptr);
3150
+ var v1 = getArrayU32FromWasm0(ret[0], ret[1]).slice();
3151
+ wasm.__wbindgen_free_command_export(ret[0], ret[1] * 4, 4);
3152
+ return v1;
3153
+ }
3154
+ /**
3155
+ * Compute the sum of all elements.
3156
+ *
3157
+ * Primarily useful for quick sanity checks and testing.
3158
+ *
3159
+ * # Example (JavaScript)
3160
+ *
3161
+ * ```js
3162
+ * const arr = WasmArray.from(new Float32Array([1, 2, 3]));
3163
+ * console.log(arr.sum()); // 6.0
3164
+ * ```
3165
+ * @returns {number}
3166
+ */
3167
+ sum() {
3168
+ const ret = wasm.wasmarray_sum(this.__wbg_ptr);
3169
+ return ret;
3170
+ }
3171
+ /**
3172
+ * Create an owned JS `Float32Array` copy of the data.
3173
+ *
3174
+ * The returned array is an independent copy that is safe to store
3175
+ * and use regardless of subsequent WASM memory operations.
3176
+ *
3177
+ * # Example (JavaScript)
3178
+ *
3179
+ * ```js
3180
+ * const copy = arr.toCopy(); // safe to keep indefinitely
3181
+ * ```
3182
+ * @returns {Float32Array}
3183
+ */
3184
+ toCopy() {
3185
+ const ret = wasm.wasmarray_toCopy(this.__wbg_ptr);
3186
+ return ret;
3187
+ }
3188
+ /**
3189
+ * Zero-copy `Float32Array` view over this array's backing storage.
3190
+ *
3191
+ * **Warning**: The returned view becomes **invalid** if WASM linear
3192
+ * memory grows (due to any allocation). Use [`toCopy`](WasmArray::to_copy)
3193
+ * if you need to keep the data.
3194
+ *
3195
+ * # Safety (internal)
3196
+ *
3197
+ * Uses `Float32Array::view` which creates an unowned view into
3198
+ * WASM memory. The view must not outlive the `WasmArray` and must
3199
+ * not be used after any allocation that could trigger memory growth.
3200
+ *
3201
+ * # Example (JavaScript)
3202
+ *
3203
+ * ```js
3204
+ * const view = arr.toTypedArray(); // use immediately
3205
+ * // Do NOT allocate between view creation and use
3206
+ * ```
3207
+ * @returns {Float32Array}
3208
+ */
3209
+ toTypedArray() {
3210
+ const ret = wasm.wasmarray_toTypedArray(this.__wbg_ptr);
3211
+ return ret;
3212
+ }
3213
+ /**
3214
+ * Overwrite the array contents from a JS `Float32Array`.
3215
+ *
3216
+ * The source array must have exactly the same number of elements
3217
+ * as this `WasmArray` (i.e., the shape is preserved).
3218
+ *
3219
+ * # Arguments
3220
+ *
3221
+ * * `arr` - Source `Float32Array` with matching length
3222
+ *
3223
+ * # Errors
3224
+ *
3225
+ * Throws if `arr.length` does not match this array's element count.
3226
+ *
3227
+ * # Example (JavaScript)
3228
+ *
3229
+ * ```js
3230
+ * const wa = new WasmArray([3]);
3231
+ * wa.writeFrom(new Float32Array([1.0, 2.0, 3.0]));
3232
+ * ```
3233
+ * @param {Float32Array} arr
3234
+ */
3235
+ write_from(arr) {
3236
+ const ret = wasm.wasmarray_write_from(this.__wbg_ptr, arr);
3237
+ if (ret[1]) {
3238
+ throw takeFromExternrefTable0(ret[0]);
3239
+ }
3240
+ }
3241
+ }
3242
+ if (Symbol.dispose) WasmArray.prototype[Symbol.dispose] = WasmArray.prototype.free;
3243
+
3244
+ /**
3245
+ * XYZ / Extended XYZ file reader.
3246
+ *
3247
+ * Supports multi-frame trajectory files. Each frame produces a
3248
+ * [`Frame`] with an `"atoms"` block containing `element` (string)
3249
+ * and `x`, `y`, `z` (f32, coordinates in angstrom) columns.
3250
+ *
3251
+ * # Example (JavaScript)
3252
+ *
3253
+ * ```js
3254
+ * const content = await file.text(); // read file in browser
3255
+ * const reader = new XYZReader(content);
3256
+ * console.log(reader.len()); // number of frames
3257
+ *
3258
+ * const frame = reader.read(0); // first frame
3259
+ * const atoms = frame.getBlock("atoms");
3260
+ * const x = atoms.copyColF32("x");
3261
+ * ```
3262
+ */
3263
+ export class XYZReader {
3264
+ __destroy_into_raw() {
3265
+ const ptr = this.__wbg_ptr;
3266
+ this.__wbg_ptr = 0;
3267
+ XYZReaderFinalization.unregister(this);
3268
+ return ptr;
3269
+ }
3270
+ free() {
3271
+ const ptr = this.__destroy_into_raw();
3272
+ wasm.__wbg_xyzreader_free(ptr, 0);
3273
+ }
3274
+ /**
3275
+ * Check whether the file contains no frames.
3276
+ *
3277
+ * # Errors
3278
+ *
3279
+ * Throws a `JsValue` string if the file cannot be scanned.
3280
+ * @returns {boolean}
3281
+ */
3282
+ isEmpty() {
3283
+ const ret = wasm.xyzreader_isEmpty(this.__wbg_ptr);
3284
+ if (ret[2]) {
3285
+ throw takeFromExternrefTable0(ret[1]);
3286
+ }
3287
+ return ret[0] !== 0;
3288
+ }
3289
+ /**
3290
+ * Return the number of frames in the file.
3291
+ *
3292
+ * # Returns
3293
+ *
3294
+ * The total frame count.
3295
+ *
3296
+ * # Errors
3297
+ *
3298
+ * Throws a `JsValue` string if the file cannot be scanned.
3299
+ *
3300
+ * # Example (JavaScript)
3301
+ *
3302
+ * ```js
3303
+ * console.log(reader.len()); // e.g., 100
3304
+ * ```
3305
+ * @returns {number}
3306
+ */
3307
+ len() {
3308
+ const ret = wasm.xyzreader_len(this.__wbg_ptr);
3309
+ if (ret[2]) {
3310
+ throw takeFromExternrefTable0(ret[1]);
3311
+ }
3312
+ return ret[0] >>> 0;
3313
+ }
3314
+ /**
3315
+ * Create a new XYZ reader from a string containing the file content.
3316
+ *
3317
+ * # Arguments
3318
+ *
3319
+ * * `content` - The full text content of an XYZ or Extended XYZ file
3320
+ *
3321
+ * # Example (JavaScript)
3322
+ *
3323
+ * ```js
3324
+ * const reader = new XYZReader(fileContent);
3325
+ * ```
3326
+ * @param {string} content
3327
+ */
3328
+ constructor(content) {
3329
+ const ptr0 = passStringToWasm0(content, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
3330
+ const len0 = WASM_VECTOR_LEN;
3331
+ const ret = wasm.xyzreader_new(ptr0, len0);
3332
+ this.__wbg_ptr = ret >>> 0;
3333
+ XYZReaderFinalization.register(this, this.__wbg_ptr, this);
3334
+ return this;
3335
+ }
3336
+ /**
3337
+ * Read a frame at the given step index.
3338
+ *
3339
+ * # Arguments
3340
+ *
3341
+ * * `step` - Zero-based frame index
3342
+ *
3343
+ * # Returns
3344
+ *
3345
+ * A [`Frame`] if the step exists, or `undefined` if `step` is
3346
+ * out of range.
3347
+ *
3348
+ * # Errors
3349
+ *
3350
+ * Throws a `JsValue` string on parse errors.
3351
+ *
3352
+ * # Example (JavaScript)
3353
+ *
3354
+ * ```js
3355
+ * const frame = reader.read(0);
3356
+ * if (frame) {
3357
+ * const atoms = frame.getBlock("atoms");
3358
+ * }
3359
+ * ```
3360
+ * @param {number} step
3361
+ * @returns {Frame | undefined}
3362
+ */
3363
+ read(step) {
3364
+ const ret = wasm.xyzreader_read(this.__wbg_ptr, step);
3365
+ if (ret[2]) {
3366
+ throw takeFromExternrefTable0(ret[1]);
3367
+ }
3368
+ return ret[0] === 0 ? undefined : Frame.__wrap(ret[0]);
3369
+ }
3370
+ }
3371
+ if (Symbol.dispose) XYZReader.prototype[Symbol.dispose] = XYZReader.prototype.free;
3372
+
3373
+ /**
3374
+ * Generate 3D coordinates for a molecular [`Frame`].
3375
+ *
3376
+ * The input frame must have an `"atoms"` block with a `"symbol"`
3377
+ * string column (element symbols like `"C"`, `"N"`, `"O"`). A
3378
+ * `"bonds"` block with `i`, `j` (u32) and `order` (f32) columns
3379
+ * is required for correct geometry.
3380
+ *
3381
+ * Returns a **new** [`Frame`] with 3D coordinates added as `x`, `y`,
3382
+ * `z` (f32, angstrom) columns in the `"atoms"` block.
3383
+ *
3384
+ * # Arguments
3385
+ *
3386
+ * * `frame` - Input molecular frame with atoms and bonds (from
3387
+ * [`parseSMILES`](crate::parse_smiles) or file readers)
3388
+ * * `speed` - Quality/speed preset:
3389
+ * - `"fast"` -- minimal refinement, suitable for visualization
3390
+ * - `"medium"` (default) -- balanced quality/speed
3391
+ * - `"better"` -- thorough conformer search, best geometry
3392
+ * * `seed` - Optional RNG seed (`u32`) for reproducibility. If
3393
+ * omitted, a random seed is used.
3394
+ *
3395
+ * # Returns
3396
+ *
3397
+ * A new [`Frame`] with 3D coordinates. The original frame is
3398
+ * not modified.
3399
+ *
3400
+ * # Errors
3401
+ *
3402
+ * Throws a `JsValue` string if:
3403
+ * - The frame has no `"atoms"` block or is missing required columns
3404
+ * - The molecular graph has invalid valences or topology
3405
+ * - The 3D embedding fails to converge
3406
+ *
3407
+ * # Example (JavaScript)
3408
+ *
3409
+ * ```js
3410
+ * const ir = parseSMILES("c1ccccc1"); // benzene
3411
+ * const frame2d = ir.toFrame();
3412
+ * const frame3d = generate3D(frame2d, "fast", 42);
3413
+ *
3414
+ * const atoms = frame3d.getBlock("atoms");
3415
+ * const x = atoms.copyColF32("x"); // Float32Array with 3D x-coords
3416
+ * const y = atoms.copyColF32("y");
3417
+ * const z = atoms.copyColF32("z");
3418
+ * ```
3419
+ * @param {Frame} frame
3420
+ * @param {string | null} [speed]
3421
+ * @param {number | null} [seed]
3422
+ * @returns {Frame}
3423
+ */
3424
+ export function generate3D(frame, speed, seed) {
3425
+ _assertClass(frame, Frame);
3426
+ var ptr0 = isLikeNone(speed) ? 0 : passStringToWasm0(speed, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
3427
+ var len0 = WASM_VECTOR_LEN;
3428
+ const ret = wasm.generate3D(frame.__wbg_ptr, ptr0, len0, isLikeNone(seed) ? 0x100000001 : (seed) >>> 0);
3429
+ if (ret[2]) {
3430
+ throw takeFromExternrefTable0(ret[1]);
3431
+ }
3432
+ return Frame.__wrap(ret[0]);
3433
+ }
3434
+
3435
+ /**
3436
+ * Parse a SMILES notation string into an intermediate representation.
3437
+ *
3438
+ * Supports standard SMILES features including ring closures,
3439
+ * branching, stereochemistry markers, and aromatic atoms.
3440
+ *
3441
+ * # Arguments
3442
+ *
3443
+ * * `smiles` - SMILES notation string (e.g., `"CCO"` for ethanol,
3444
+ * `"c1ccccc1"` for benzene, `"[Na+].[Cl-]"` for NaCl)
3445
+ *
3446
+ * # Returns
3447
+ *
3448
+ * A [`SmilesIR`](WasmSmilesIR) object. Call `.toFrame()` to convert
3449
+ * to a [`Frame`] with atoms and bonds blocks.
3450
+ *
3451
+ * # Errors
3452
+ *
3453
+ * Throws a `JsValue` string if the SMILES string is malformed
3454
+ * (e.g., unmatched ring closure digits, invalid atom symbols).
3455
+ *
3456
+ * # Example (JavaScript)
3457
+ *
3458
+ * ```js
3459
+ * const ir = parseSMILES("CCO");
3460
+ * const frame = ir.toFrame();
3461
+ * const mol3d = generate3D(frame, "fast");
3462
+ * ```
3463
+ * @param {string} smiles
3464
+ * @returns {SmilesIR}
3465
+ */
3466
+ export function parseSMILES(smiles) {
3467
+ const ptr0 = passStringToWasm0(smiles, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
3468
+ const len0 = WASM_VECTOR_LEN;
3469
+ const ret = wasm.parseSMILES(ptr0, len0);
3470
+ if (ret[2]) {
3471
+ throw takeFromExternrefTable0(ret[1]);
3472
+ }
3473
+ return SmilesIR.__wrap(ret[0]);
3474
+ }
3475
+
3476
+ /**
3477
+ * WASM module entry point. Installs the panic hook so that Rust panics
3478
+ * are forwarded to the browser console as readable stack traces.
3479
+ */
3480
+ export function start() {
3481
+ wasm.start();
3482
+ }
3483
+
3484
+ /**
3485
+ * Return a handle to the WASM linear memory.
3486
+ *
3487
+ * Useful for advanced interop where JS code needs direct access to the
3488
+ * WASM memory buffer (e.g., for zero-copy typed-array views).
3489
+ *
3490
+ * # Example (JavaScript)
3491
+ *
3492
+ * ```js
3493
+ * const mem = wasmMemory();
3494
+ * const buf = new Float32Array(mem.buffer, ptr, len);
3495
+ * ```
3496
+ * @returns {WebAssembly.Memory}
3497
+ */
3498
+ export function wasmMemory() {
3499
+ const ret = wasm.wasmMemory();
3500
+ return ret;
3501
+ }
3502
+
3503
+ /**
3504
+ * Serialize a [`Frame`] to a string in the specified format.
3505
+ *
3506
+ * The frame must have an `"atoms"` block with at least an element/name
3507
+ * string column and `x`, `y`, `z` float columns (coordinates in
3508
+ * angstrom).
3509
+ *
3510
+ * # Arguments
3511
+ *
3512
+ * * `frame` - The [`Frame`] to write
3513
+ * * `format` - Output format string: `"xyz"` or `"pdb"`
3514
+ * (case-insensitive)
3515
+ *
3516
+ * # Returns
3517
+ *
3518
+ * The formatted file content as a string.
3519
+ *
3520
+ * # Errors
3521
+ *
3522
+ * Throws a `JsValue` string if:
3523
+ * - The format is not recognized
3524
+ * - The frame is missing required columns
3525
+ * - The writer encounters an error
3526
+ *
3527
+ * # Example (JavaScript)
3528
+ *
3529
+ * ```js
3530
+ * const xyzStr = writeFrame(frame, "xyz");
3531
+ * console.log(xyzStr);
3532
+ * // 2
3533
+ * //
3534
+ * // H 0.000000 0.000000 0.000000
3535
+ * // O 1.000000 0.000000 0.500000
3536
+ *
3537
+ * const pdbStr = writeFrame(frame, "pdb");
3538
+ * // download or display the PDB string
3539
+ * ```
3540
+ * @param {Frame} frame
3541
+ * @param {string} format
3542
+ * @returns {string}
3543
+ */
3544
+ export function writeFrame(frame, format) {
3545
+ let deferred3_0;
3546
+ let deferred3_1;
3547
+ try {
3548
+ _assertClass(frame, Frame);
3549
+ const ptr0 = passStringToWasm0(format, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
3550
+ const len0 = WASM_VECTOR_LEN;
3551
+ const ret = wasm.writeFrame(frame.__wbg_ptr, ptr0, len0);
3552
+ var ptr2 = ret[0];
3553
+ var len2 = ret[1];
3554
+ if (ret[3]) {
3555
+ ptr2 = 0; len2 = 0;
3556
+ throw takeFromExternrefTable0(ret[2]);
3557
+ }
3558
+ deferred3_0 = ptr2;
3559
+ deferred3_1 = len2;
3560
+ return getStringFromWasm0(ptr2, len2);
3561
+ } finally {
3562
+ wasm.__wbindgen_free_command_export(deferred3_0, deferred3_1, 1);
3563
+ }
3564
+ }
3565
+ export function __wbg___wbindgen_debug_string_5398f5bb970e0daa(arg0, arg1) {
3566
+ const ret = debugString(arg1);
3567
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
3568
+ const len1 = WASM_VECTOR_LEN;
3569
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
3570
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
3571
+ }
3572
+ export function __wbg___wbindgen_memory_edb3f01e3930bbf6() {
3573
+ const ret = wasm.memory;
3574
+ return ret;
3575
+ }
3576
+ export function __wbg___wbindgen_string_get_395e606bd0ee4427(arg0, arg1) {
3577
+ const obj = arg1;
3578
+ const ret = typeof(obj) === 'string' ? obj : undefined;
3579
+ var ptr1 = isLikeNone(ret) ? 0 : passStringToWasm0(ret, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
3580
+ var len1 = WASM_VECTOR_LEN;
3581
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
3582
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
3583
+ }
3584
+ export function __wbg___wbindgen_throw_6ddd609b62940d55(arg0, arg1) {
3585
+ throw new Error(getStringFromWasm0(arg0, arg1));
3586
+ }
3587
+ export function __wbg_done_08ce71ee07e3bd17(arg0) {
3588
+ const ret = arg0.done;
3589
+ return ret;
3590
+ }
3591
+ export function __wbg_error_a6fa202b58aa1cd3(arg0, arg1) {
3592
+ let deferred0_0;
3593
+ let deferred0_1;
3594
+ try {
3595
+ deferred0_0 = arg0;
3596
+ deferred0_1 = arg1;
3597
+ console.error(getStringFromWasm0(arg0, arg1));
3598
+ } finally {
3599
+ wasm.__wbindgen_free_command_export(deferred0_0, deferred0_1, 1);
3600
+ }
3601
+ }
3602
+ export function __wbg_getRandomValues_3f44b700395062e5() { return handleError(function (arg0, arg1) {
3603
+ globalThis.crypto.getRandomValues(getArrayU8FromWasm0(arg0, arg1));
3604
+ }, arguments); }
3605
+ export function __wbg_get_10ee87d86a58fb49(arg0, arg1) {
3606
+ const ret = arg0.get(arg1);
3607
+ return ret;
3608
+ }
3609
+ export function __wbg_get_unchecked_329cfe50afab7352(arg0, arg1) {
3610
+ const ret = arg0[arg1 >>> 0];
3611
+ return ret;
3612
+ }
3613
+ export function __wbg_keys_3fff7686656d707e(arg0) {
3614
+ const ret = arg0.keys();
3615
+ return ret;
3616
+ }
3617
+ export function __wbg_length_259ee9d041e381ad(arg0) {
3618
+ const ret = arg0.length;
3619
+ return ret;
3620
+ }
3621
+ export function __wbg_length_27280eca2d70010e(arg0) {
3622
+ const ret = arg0.length;
3623
+ return ret;
3624
+ }
3625
+ export function __wbg_length_76eefdd571f24b00(arg0) {
3626
+ const ret = arg0.length;
3627
+ return ret;
3628
+ }
3629
+ export function __wbg_length_b3416cf66a5452c8(arg0) {
3630
+ const ret = arg0.length;
3631
+ return ret;
3632
+ }
3633
+ export function __wbg_length_ea16607d7b61445b(arg0) {
3634
+ const ret = arg0.length;
3635
+ return ret;
3636
+ }
3637
+ export function __wbg_new_227d7c05414eb861() {
3638
+ const ret = new Error();
3639
+ return ret;
3640
+ }
3641
+ export function __wbg_new_5f486cdf45a04d78(arg0) {
3642
+ const ret = new Uint8Array(arg0);
3643
+ return ret;
3644
+ }
3645
+ export function __wbg_new_a70fbab9066b301f() {
3646
+ const ret = new Array();
3647
+ return ret;
3648
+ }
3649
+ export function __wbg_new_from_slice_898ac63cbd46f332(arg0, arg1) {
3650
+ const ret = new Uint32Array(getArrayU32FromWasm0(arg0, arg1));
3651
+ return ret;
3652
+ }
3653
+ export function __wbg_new_from_slice_c62f8165d6102476(arg0, arg1) {
3654
+ const ret = new Int32Array(getArrayI32FromWasm0(arg0, arg1));
3655
+ return ret;
3656
+ }
3657
+ export function __wbg_new_from_slice_ff2c15e8e05ffdfc(arg0, arg1) {
3658
+ const ret = new Float32Array(getArrayF32FromWasm0(arg0, arg1));
3659
+ return ret;
3660
+ }
3661
+ export function __wbg_next_11b99ee6237339e3() { return handleError(function (arg0) {
3662
+ const ret = arg0.next();
3663
+ return ret;
3664
+ }, arguments); }
3665
+ export function __wbg_prototypesetcall_247ac4333d4d3cb4(arg0, arg1, arg2) {
3666
+ Float32Array.prototype.set.call(getArrayF32FromWasm0(arg0, arg1), arg2);
3667
+ }
3668
+ export function __wbg_prototypesetcall_52ca14fb142bc37b(arg0, arg1, arg2) {
3669
+ Int32Array.prototype.set.call(getArrayI32FromWasm0(arg0, arg1), arg2);
3670
+ }
3671
+ export function __wbg_prototypesetcall_d62e5099504357e6(arg0, arg1, arg2) {
3672
+ Uint8Array.prototype.set.call(getArrayU8FromWasm0(arg0, arg1), arg2);
3673
+ }
3674
+ export function __wbg_prototypesetcall_f04613188bde902d(arg0, arg1, arg2) {
3675
+ Uint32Array.prototype.set.call(getArrayU32FromWasm0(arg0, arg1), arg2);
3676
+ }
3677
+ export function __wbg_push_e87b0e732085a946(arg0, arg1) {
3678
+ const ret = arg0.push(arg1);
3679
+ return ret;
3680
+ }
3681
+ export function __wbg_stack_3b0d974bbf31e44f(arg0, arg1) {
3682
+ const ret = arg1.stack;
3683
+ const ptr1 = passStringToWasm0(ret, wasm.__wbindgen_malloc_command_export, wasm.__wbindgen_realloc_command_export);
3684
+ const len1 = WASM_VECTOR_LEN;
3685
+ getDataViewMemory0().setInt32(arg0 + 4 * 1, len1, true);
3686
+ getDataViewMemory0().setInt32(arg0 + 4 * 0, ptr1, true);
3687
+ }
3688
+ export function __wbg_value_21fc78aab0322612(arg0) {
3689
+ const ret = arg0.value;
3690
+ return ret;
3691
+ }
3692
+ export function __wbindgen_cast_0000000000000001(arg0, arg1) {
3693
+ // Cast intrinsic for `Ref(Slice(F32)) -> NamedExternref("Float32Array")`.
3694
+ const ret = getArrayF32FromWasm0(arg0, arg1);
3695
+ return ret;
3696
+ }
3697
+ export function __wbindgen_cast_0000000000000002(arg0, arg1) {
3698
+ // Cast intrinsic for `Ref(Slice(I32)) -> NamedExternref("Int32Array")`.
3699
+ const ret = getArrayI32FromWasm0(arg0, arg1);
3700
+ return ret;
3701
+ }
3702
+ export function __wbindgen_cast_0000000000000003(arg0, arg1) {
3703
+ // Cast intrinsic for `Ref(Slice(U32)) -> NamedExternref("Uint32Array")`.
3704
+ const ret = getArrayU32FromWasm0(arg0, arg1);
3705
+ return ret;
3706
+ }
3707
+ export function __wbindgen_cast_0000000000000004(arg0, arg1) {
3708
+ // Cast intrinsic for `Ref(String) -> Externref`.
3709
+ const ret = getStringFromWasm0(arg0, arg1);
3710
+ return ret;
3711
+ }
3712
+ export function __wbindgen_init_externref_table() {
3713
+ const table = wasm.__wbindgen_externrefs;
3714
+ const offset = table.grow(4);
3715
+ table.set(0, undefined);
3716
+ table.set(offset + 0, undefined);
3717
+ table.set(offset + 1, null);
3718
+ table.set(offset + 2, true);
3719
+ table.set(offset + 3, false);
3720
+ }
3721
+ const AABBQueryFinalization = (typeof FinalizationRegistry === 'undefined')
3722
+ ? { register: () => {}, unregister: () => {} }
3723
+ : new FinalizationRegistry(ptr => wasm.__wbg_aabbquery_free(ptr >>> 0, 1));
3724
+ const BlockFinalization = (typeof FinalizationRegistry === 'undefined')
3725
+ ? { register: () => {}, unregister: () => {} }
3726
+ : new FinalizationRegistry(ptr => wasm.__wbg_block_free(ptr >>> 0, 1));
3727
+ const BoxFinalization = (typeof FinalizationRegistry === 'undefined')
3728
+ ? { register: () => {}, unregister: () => {} }
3729
+ : new FinalizationRegistry(ptr => wasm.__wbg_box_free(ptr >>> 0, 1));
3730
+ const ClusterFinalization = (typeof FinalizationRegistry === 'undefined')
3731
+ ? { register: () => {}, unregister: () => {} }
3732
+ : new FinalizationRegistry(ptr => wasm.__wbg_cluster_free(ptr >>> 0, 1));
3733
+ const ClusterResultFinalization = (typeof FinalizationRegistry === 'undefined')
3734
+ ? { register: () => {}, unregister: () => {} }
3735
+ : new FinalizationRegistry(ptr => wasm.__wbg_clusterresult_free(ptr >>> 0, 1));
3736
+ const FrameFinalization = (typeof FinalizationRegistry === 'undefined')
3737
+ ? { register: () => {}, unregister: () => {} }
3738
+ : new FinalizationRegistry(ptr => wasm.__wbg_frame_free(ptr >>> 0, 1));
3739
+ const LAMMPSReaderFinalization = (typeof FinalizationRegistry === 'undefined')
3740
+ ? { register: () => {}, unregister: () => {} }
3741
+ : new FinalizationRegistry(ptr => wasm.__wbg_lammpsreader_free(ptr >>> 0, 1));
3742
+ const MSDFinalization = (typeof FinalizationRegistry === 'undefined')
3743
+ ? { register: () => {}, unregister: () => {} }
3744
+ : new FinalizationRegistry(ptr => wasm.__wbg_msd_free(ptr >>> 0, 1));
3745
+ const MSDResultFinalization = (typeof FinalizationRegistry === 'undefined')
3746
+ ? { register: () => {}, unregister: () => {} }
3747
+ : new FinalizationRegistry(ptr => wasm.__wbg_msdresult_free(ptr >>> 0, 1));
3748
+ const NeighborListFinalization = (typeof FinalizationRegistry === 'undefined')
3749
+ ? { register: () => {}, unregister: () => {} }
3750
+ : new FinalizationRegistry(ptr => wasm.__wbg_neighborlist_free(ptr >>> 0, 1));
3751
+ const NeighborResultFinalization = (typeof FinalizationRegistry === 'undefined')
3752
+ ? { register: () => {}, unregister: () => {} }
3753
+ : new FinalizationRegistry(ptr => wasm.__wbg_neighborresult_free(ptr >>> 0, 1));
3754
+ const NeighborSearchFinalization = (typeof FinalizationRegistry === 'undefined')
3755
+ ? { register: () => {}, unregister: () => {} }
3756
+ : new FinalizationRegistry(ptr => wasm.__wbg_neighborsearch_free(ptr >>> 0, 1));
3757
+ const PDBReaderFinalization = (typeof FinalizationRegistry === 'undefined')
3758
+ ? { register: () => {}, unregister: () => {} }
3759
+ : new FinalizationRegistry(ptr => wasm.__wbg_pdbreader_free(ptr >>> 0, 1));
3760
+ const RDFFinalization = (typeof FinalizationRegistry === 'undefined')
3761
+ ? { register: () => {}, unregister: () => {} }
3762
+ : new FinalizationRegistry(ptr => wasm.__wbg_rdf_free(ptr >>> 0, 1));
3763
+ const RDFResultFinalization = (typeof FinalizationRegistry === 'undefined')
3764
+ ? { register: () => {}, unregister: () => {} }
3765
+ : new FinalizationRegistry(ptr => wasm.__wbg_rdfresult_free(ptr >>> 0, 1));
3766
+ const SimulationReaderFinalization = (typeof FinalizationRegistry === 'undefined')
3767
+ ? { register: () => {}, unregister: () => {} }
3768
+ : new FinalizationRegistry(ptr => wasm.__wbg_simulationreader_free(ptr >>> 0, 1));
3769
+ const WasmArrayFinalization = (typeof FinalizationRegistry === 'undefined')
3770
+ ? { register: () => {}, unregister: () => {} }
3771
+ : new FinalizationRegistry(ptr => wasm.__wbg_wasmarray_free(ptr >>> 0, 1));
3772
+ const SmilesIRFinalization = (typeof FinalizationRegistry === 'undefined')
3773
+ ? { register: () => {}, unregister: () => {} }
3774
+ : new FinalizationRegistry(ptr => wasm.__wbg_smilesir_free(ptr >>> 0, 1));
3775
+ const XYZReaderFinalization = (typeof FinalizationRegistry === 'undefined')
3776
+ ? { register: () => {}, unregister: () => {} }
3777
+ : new FinalizationRegistry(ptr => wasm.__wbg_xyzreader_free(ptr >>> 0, 1));
3778
+
3779
+ function addToExternrefTable0(obj) {
3780
+ const idx = wasm.__externref_table_alloc_command_export();
3781
+ wasm.__wbindgen_externrefs.set(idx, obj);
3782
+ return idx;
3783
+ }
3784
+
3785
+ function _assertClass(instance, klass) {
3786
+ if (!(instance instanceof klass)) {
3787
+ throw new Error(`expected instance of ${klass.name}`);
3788
+ }
3789
+ }
3790
+
3791
+ function debugString(val) {
3792
+ // primitive types
3793
+ const type = typeof val;
3794
+ if (type == 'number' || type == 'boolean' || val == null) {
3795
+ return `${val}`;
3796
+ }
3797
+ if (type == 'string') {
3798
+ return `"${val}"`;
3799
+ }
3800
+ if (type == 'symbol') {
3801
+ const description = val.description;
3802
+ if (description == null) {
3803
+ return 'Symbol';
3804
+ } else {
3805
+ return `Symbol(${description})`;
3806
+ }
3807
+ }
3808
+ if (type == 'function') {
3809
+ const name = val.name;
3810
+ if (typeof name == 'string' && name.length > 0) {
3811
+ return `Function(${name})`;
3812
+ } else {
3813
+ return 'Function';
3814
+ }
3815
+ }
3816
+ // objects
3817
+ if (Array.isArray(val)) {
3818
+ const length = val.length;
3819
+ let debug = '[';
3820
+ if (length > 0) {
3821
+ debug += debugString(val[0]);
3822
+ }
3823
+ for(let i = 1; i < length; i++) {
3824
+ debug += ', ' + debugString(val[i]);
3825
+ }
3826
+ debug += ']';
3827
+ return debug;
3828
+ }
3829
+ // Test for built-in
3830
+ const builtInMatches = /\[object ([^\]]+)\]/.exec(toString.call(val));
3831
+ let className;
3832
+ if (builtInMatches && builtInMatches.length > 1) {
3833
+ className = builtInMatches[1];
3834
+ } else {
3835
+ // Failed to match the standard '[object ClassName]'
3836
+ return toString.call(val);
3837
+ }
3838
+ if (className == 'Object') {
3839
+ // we're a user defined class or Object
3840
+ // JSON.stringify avoids problems with cycles, and is generally much
3841
+ // easier than looping through ownProperties of `val`.
3842
+ try {
3843
+ return 'Object(' + JSON.stringify(val) + ')';
3844
+ } catch (_) {
3845
+ return 'Object';
3846
+ }
3847
+ }
3848
+ // errors
3849
+ if (val instanceof Error) {
3850
+ return `${val.name}: ${val.message}\n${val.stack}`;
3851
+ }
3852
+ // TODO we could test for more things here, like `Set`s and `Map`s.
3853
+ return className;
3854
+ }
3855
+
3856
+ function getArrayF32FromWasm0(ptr, len) {
3857
+ ptr = ptr >>> 0;
3858
+ return getFloat32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
3859
+ }
3860
+
3861
+ function getArrayI32FromWasm0(ptr, len) {
3862
+ ptr = ptr >>> 0;
3863
+ return getInt32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
3864
+ }
3865
+
3866
+ function getArrayU32FromWasm0(ptr, len) {
3867
+ ptr = ptr >>> 0;
3868
+ return getUint32ArrayMemory0().subarray(ptr / 4, ptr / 4 + len);
3869
+ }
3870
+
3871
+ function getArrayU8FromWasm0(ptr, len) {
3872
+ ptr = ptr >>> 0;
3873
+ return getUint8ArrayMemory0().subarray(ptr / 1, ptr / 1 + len);
3874
+ }
3875
+
3876
+ let cachedDataViewMemory0 = null;
3877
+ function getDataViewMemory0() {
3878
+ if (cachedDataViewMemory0 === null || cachedDataViewMemory0.buffer.detached === true || (cachedDataViewMemory0.buffer.detached === undefined && cachedDataViewMemory0.buffer !== wasm.memory.buffer)) {
3879
+ cachedDataViewMemory0 = new DataView(wasm.memory.buffer);
3880
+ }
3881
+ return cachedDataViewMemory0;
3882
+ }
3883
+
3884
+ let cachedFloat32ArrayMemory0 = null;
3885
+ function getFloat32ArrayMemory0() {
3886
+ if (cachedFloat32ArrayMemory0 === null || cachedFloat32ArrayMemory0.byteLength === 0) {
3887
+ cachedFloat32ArrayMemory0 = new Float32Array(wasm.memory.buffer);
3888
+ }
3889
+ return cachedFloat32ArrayMemory0;
3890
+ }
3891
+
3892
+ let cachedInt32ArrayMemory0 = null;
3893
+ function getInt32ArrayMemory0() {
3894
+ if (cachedInt32ArrayMemory0 === null || cachedInt32ArrayMemory0.byteLength === 0) {
3895
+ cachedInt32ArrayMemory0 = new Int32Array(wasm.memory.buffer);
3896
+ }
3897
+ return cachedInt32ArrayMemory0;
3898
+ }
3899
+
3900
+ function getStringFromWasm0(ptr, len) {
3901
+ ptr = ptr >>> 0;
3902
+ return decodeText(ptr, len);
3903
+ }
3904
+
3905
+ let cachedUint32ArrayMemory0 = null;
3906
+ function getUint32ArrayMemory0() {
3907
+ if (cachedUint32ArrayMemory0 === null || cachedUint32ArrayMemory0.byteLength === 0) {
3908
+ cachedUint32ArrayMemory0 = new Uint32Array(wasm.memory.buffer);
3909
+ }
3910
+ return cachedUint32ArrayMemory0;
3911
+ }
3912
+
3913
+ let cachedUint8ArrayMemory0 = null;
3914
+ function getUint8ArrayMemory0() {
3915
+ if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
3916
+ cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
3917
+ }
3918
+ return cachedUint8ArrayMemory0;
3919
+ }
3920
+
3921
+ function handleError(f, args) {
3922
+ try {
3923
+ return f.apply(this, args);
3924
+ } catch (e) {
3925
+ const idx = addToExternrefTable0(e);
3926
+ wasm.__wbindgen_exn_store_command_export(idx);
3927
+ }
3928
+ }
3929
+
3930
+ function isLikeNone(x) {
3931
+ return x === undefined || x === null;
3932
+ }
3933
+
3934
+ function passArray32ToWasm0(arg, malloc) {
3935
+ const ptr = malloc(arg.length * 4, 4) >>> 0;
3936
+ getUint32ArrayMemory0().set(arg, ptr / 4);
3937
+ WASM_VECTOR_LEN = arg.length;
3938
+ return ptr;
3939
+ }
3940
+
3941
+ function passStringToWasm0(arg, malloc, realloc) {
3942
+ if (realloc === undefined) {
3943
+ const buf = cachedTextEncoder.encode(arg);
3944
+ const ptr = malloc(buf.length, 1) >>> 0;
3945
+ getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
3946
+ WASM_VECTOR_LEN = buf.length;
3947
+ return ptr;
3948
+ }
3949
+
3950
+ let len = arg.length;
3951
+ let ptr = malloc(len, 1) >>> 0;
3952
+
3953
+ const mem = getUint8ArrayMemory0();
3954
+
3955
+ let offset = 0;
3956
+
3957
+ for (; offset < len; offset++) {
3958
+ const code = arg.charCodeAt(offset);
3959
+ if (code > 0x7F) break;
3960
+ mem[ptr + offset] = code;
3961
+ }
3962
+ if (offset !== len) {
3963
+ if (offset !== 0) {
3964
+ arg = arg.slice(offset);
3965
+ }
3966
+ ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
3967
+ const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
3968
+ const ret = cachedTextEncoder.encodeInto(arg, view);
3969
+
3970
+ offset += ret.written;
3971
+ ptr = realloc(ptr, len, offset, 1) >>> 0;
3972
+ }
3973
+
3974
+ WASM_VECTOR_LEN = offset;
3975
+ return ptr;
3976
+ }
3977
+
3978
+ function takeFromExternrefTable0(idx) {
3979
+ const value = wasm.__wbindgen_externrefs.get(idx);
3980
+ wasm.__externref_table_dealloc_command_export(idx);
3981
+ return value;
3982
+ }
3983
+
3984
+ let cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
3985
+ cachedTextDecoder.decode();
3986
+ const MAX_SAFARI_DECODE_BYTES = 2146435072;
3987
+ let numBytesDecoded = 0;
3988
+ function decodeText(ptr, len) {
3989
+ numBytesDecoded += len;
3990
+ if (numBytesDecoded >= MAX_SAFARI_DECODE_BYTES) {
3991
+ cachedTextDecoder = new TextDecoder('utf-8', { ignoreBOM: true, fatal: true });
3992
+ cachedTextDecoder.decode();
3993
+ numBytesDecoded = len;
3994
+ }
3995
+ return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
3996
+ }
3997
+
3998
+ const cachedTextEncoder = new TextEncoder();
3999
+
4000
+ if (!('encodeInto' in cachedTextEncoder)) {
4001
+ cachedTextEncoder.encodeInto = function (arg, view) {
4002
+ const buf = cachedTextEncoder.encode(arg);
4003
+ view.set(buf);
4004
+ return {
4005
+ read: arg.length,
4006
+ written: buf.length
4007
+ };
4008
+ };
4009
+ }
4010
+
4011
+ let WASM_VECTOR_LEN = 0;
4012
+
4013
+
4014
+ let wasm;
4015
+ export function __wbg_set_wasm(val) {
4016
+ wasm = val;
4017
+ }