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