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