@spglib/moyo-wasm 0.4.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +59 -0
- package/moyo_wasm.d.ts +77 -0
- package/moyo_wasm.js +250 -0
- package/moyo_wasm_bg.wasm +0 -0
- package/package.json +21 -0
package/README.md
ADDED
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
# `moyo-wasm`
|
|
2
|
+
|
|
3
|
+
WASM bindings for the Rust crystal symmetry library `moyo`, for use in web apps.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
Install from a registry or local path:
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
pnpm add moyo-wasm
|
|
11
|
+
# or from cloned repo during development
|
|
12
|
+
pnpm add file:/path/to/moyo/moyo-wasm/pkg
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Initialize and analyze a structure:
|
|
16
|
+
|
|
17
|
+
```ts
|
|
18
|
+
import init, { analyze_cell, type MoyoDataset, type MoyoCell } from 'moyo-wasm'
|
|
19
|
+
import wasm_url from 'moyo-wasm/moyo_wasm_bg.wasm?url'
|
|
20
|
+
|
|
21
|
+
await init(wasm_url)
|
|
22
|
+
|
|
23
|
+
// Build a JSON cell (row-major lattice matrix; fractional positions; atomic numbers)
|
|
24
|
+
const cell: MoyoCell = {
|
|
25
|
+
lattice: { basis: [m00, m01, m02, m10, m11, m12, m20, m21, m22] },
|
|
26
|
+
positions: [[fx, fy, fz], ...],
|
|
27
|
+
numbers: [int, ...],
|
|
28
|
+
}
|
|
29
|
+
const result: MoyoDataset = analyze_cell(JSON.stringify(cell), 1e-4, 'Standard')
|
|
30
|
+
console.log(`Space group: ${result.number} (${result.hm_symbol})`)
|
|
31
|
+
console.log(`Hall number: ${result.hall_number}`)
|
|
32
|
+
console.log(`Pearson: ${result.pearson_symbol}`)
|
|
33
|
+
console.log(`# operations: ${result.operations.length}`)
|
|
34
|
+
console.log(`Wyckoffs: ${result.wyckoffs.join(', ')}`)
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
The package exports TypeScript types generated from Rust (e.g. `MoyoDataset`).
|
|
38
|
+
|
|
39
|
+
## Building
|
|
40
|
+
|
|
41
|
+
```bash
|
|
42
|
+
wasm-pack build moyo-wasm --target web --release
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
The package code ready for publishing is in `moyo-wasm/pkg`.
|
|
46
|
+
|
|
47
|
+
## Testing
|
|
48
|
+
|
|
49
|
+
```bash
|
|
50
|
+
cd moyo-wasm
|
|
51
|
+
# Install dependencies
|
|
52
|
+
npm install
|
|
53
|
+
# Run tests
|
|
54
|
+
npm test
|
|
55
|
+
```
|
|
56
|
+
|
|
57
|
+
## Publish
|
|
58
|
+
|
|
59
|
+
This crate is published as an [NPM package](https://www.npmjs.com/package/moyo-wasm) with CI when a new `git` tag is pushed to the Rust monorepo.
|
package/moyo_wasm.d.ts
ADDED
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
/* tslint:disable */
|
|
2
|
+
/* eslint-disable */
|
|
3
|
+
/**
|
|
4
|
+
* Return a strongly-typed DTO; wasm-bindgen + tsify will emit .d.ts based on these Rust types
|
|
5
|
+
*/
|
|
6
|
+
export function analyze_cell(cell_json: string, symprec: number, setting: string): MoyoDataset;
|
|
7
|
+
export interface MoyoCell {
|
|
8
|
+
lattice: Lattice;
|
|
9
|
+
positions: [number, number, number][];
|
|
10
|
+
numbers: number[];
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export interface Lattice {
|
|
14
|
+
basis: [number, number, number, number, number, number, number, number, number];
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export interface MoyoOperation {
|
|
18
|
+
rotation: [number, number, number, number, number, number, number, number, number];
|
|
19
|
+
translation: [number, number, number];
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
export type AngleTolerance = { type: "Radian"; value: number } | { type: "Default" };
|
|
23
|
+
|
|
24
|
+
export interface MoyoDataset {
|
|
25
|
+
number: number;
|
|
26
|
+
hall_number: number;
|
|
27
|
+
hm_symbol: string;
|
|
28
|
+
operations: MoyoOperation[];
|
|
29
|
+
orbits: number[];
|
|
30
|
+
wyckoffs: string[];
|
|
31
|
+
site_symmetry_symbols: string[];
|
|
32
|
+
std_cell: MoyoCell;
|
|
33
|
+
std_linear: [number, number, number, number, number, number, number, number, number];
|
|
34
|
+
std_origin_shift: [number, number, number];
|
|
35
|
+
std_rotation_matrix: [number, number, number, number, number, number, number, number, number];
|
|
36
|
+
pearson_symbol: string;
|
|
37
|
+
prim_std_cell: MoyoCell;
|
|
38
|
+
prim_std_linear: [number, number, number, number, number, number, number, number, number];
|
|
39
|
+
prim_std_origin_shift: [number, number, number];
|
|
40
|
+
mapping_std_prim: number[];
|
|
41
|
+
symprec: number;
|
|
42
|
+
angle_tolerance: AngleTolerance;
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
export type InitInput = RequestInfo | URL | Response | BufferSource | WebAssembly.Module;
|
|
47
|
+
|
|
48
|
+
export interface InitOutput {
|
|
49
|
+
readonly memory: WebAssembly.Memory;
|
|
50
|
+
readonly analyze_cell: (a: number, b: number, c: number, d: number, e: number) => [number, number, number];
|
|
51
|
+
readonly __wbindgen_export_0: WebAssembly.Table;
|
|
52
|
+
readonly __wbindgen_malloc: (a: number, b: number) => number;
|
|
53
|
+
readonly __wbindgen_realloc: (a: number, b: number, c: number, d: number) => number;
|
|
54
|
+
readonly __externref_table_dealloc: (a: number) => void;
|
|
55
|
+
readonly __wbindgen_start: () => void;
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
export type SyncInitInput = BufferSource | WebAssembly.Module;
|
|
59
|
+
/**
|
|
60
|
+
* Instantiates the given `module`, which can either be bytes or
|
|
61
|
+
* a precompiled `WebAssembly.Module`.
|
|
62
|
+
*
|
|
63
|
+
* @param {{ module: SyncInitInput }} module - Passing `SyncInitInput` directly is deprecated.
|
|
64
|
+
*
|
|
65
|
+
* @returns {InitOutput}
|
|
66
|
+
*/
|
|
67
|
+
export function initSync(module: { module: SyncInitInput } | SyncInitInput): InitOutput;
|
|
68
|
+
|
|
69
|
+
/**
|
|
70
|
+
* If `module_or_path` is {RequestInfo} or {URL}, makes a request and
|
|
71
|
+
* for everything else, calls `WebAssembly.instantiate` directly.
|
|
72
|
+
*
|
|
73
|
+
* @param {{ module_or_path: InitInput | Promise<InitInput> }} module_or_path - Passing `InitInput` directly is deprecated.
|
|
74
|
+
*
|
|
75
|
+
* @returns {Promise<InitOutput>}
|
|
76
|
+
*/
|
|
77
|
+
export default function __wbg_init (module_or_path?: { module_or_path: InitInput | Promise<InitInput> } | InitInput | Promise<InitInput>): Promise<InitOutput>;
|
package/moyo_wasm.js
ADDED
|
@@ -0,0 +1,250 @@
|
|
|
1
|
+
let wasm;
|
|
2
|
+
|
|
3
|
+
const cachedTextDecoder = (typeof TextDecoder !== 'undefined' ? new TextDecoder('utf-8', { ignoreBOM: true, fatal: true }) : { decode: () => { throw Error('TextDecoder not available') } } );
|
|
4
|
+
|
|
5
|
+
if (typeof TextDecoder !== 'undefined') { cachedTextDecoder.decode(); };
|
|
6
|
+
|
|
7
|
+
let cachedUint8ArrayMemory0 = null;
|
|
8
|
+
|
|
9
|
+
function getUint8ArrayMemory0() {
|
|
10
|
+
if (cachedUint8ArrayMemory0 === null || cachedUint8ArrayMemory0.byteLength === 0) {
|
|
11
|
+
cachedUint8ArrayMemory0 = new Uint8Array(wasm.memory.buffer);
|
|
12
|
+
}
|
|
13
|
+
return cachedUint8ArrayMemory0;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
function getStringFromWasm0(ptr, len) {
|
|
17
|
+
ptr = ptr >>> 0;
|
|
18
|
+
return cachedTextDecoder.decode(getUint8ArrayMemory0().subarray(ptr, ptr + len));
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
let WASM_VECTOR_LEN = 0;
|
|
22
|
+
|
|
23
|
+
const cachedTextEncoder = (typeof TextEncoder !== 'undefined' ? new TextEncoder('utf-8') : { encode: () => { throw Error('TextEncoder not available') } } );
|
|
24
|
+
|
|
25
|
+
const encodeString = (typeof cachedTextEncoder.encodeInto === 'function'
|
|
26
|
+
? function (arg, view) {
|
|
27
|
+
return cachedTextEncoder.encodeInto(arg, view);
|
|
28
|
+
}
|
|
29
|
+
: function (arg, view) {
|
|
30
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
31
|
+
view.set(buf);
|
|
32
|
+
return {
|
|
33
|
+
read: arg.length,
|
|
34
|
+
written: buf.length
|
|
35
|
+
};
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
function passStringToWasm0(arg, malloc, realloc) {
|
|
39
|
+
|
|
40
|
+
if (realloc === undefined) {
|
|
41
|
+
const buf = cachedTextEncoder.encode(arg);
|
|
42
|
+
const ptr = malloc(buf.length, 1) >>> 0;
|
|
43
|
+
getUint8ArrayMemory0().subarray(ptr, ptr + buf.length).set(buf);
|
|
44
|
+
WASM_VECTOR_LEN = buf.length;
|
|
45
|
+
return ptr;
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
let len = arg.length;
|
|
49
|
+
let ptr = malloc(len, 1) >>> 0;
|
|
50
|
+
|
|
51
|
+
const mem = getUint8ArrayMemory0();
|
|
52
|
+
|
|
53
|
+
let offset = 0;
|
|
54
|
+
|
|
55
|
+
for (; offset < len; offset++) {
|
|
56
|
+
const code = arg.charCodeAt(offset);
|
|
57
|
+
if (code > 0x7F) break;
|
|
58
|
+
mem[ptr + offset] = code;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
if (offset !== len) {
|
|
62
|
+
if (offset !== 0) {
|
|
63
|
+
arg = arg.slice(offset);
|
|
64
|
+
}
|
|
65
|
+
ptr = realloc(ptr, len, len = offset + arg.length * 3, 1) >>> 0;
|
|
66
|
+
const view = getUint8ArrayMemory0().subarray(ptr + offset, ptr + len);
|
|
67
|
+
const ret = encodeString(arg, view);
|
|
68
|
+
|
|
69
|
+
offset += ret.written;
|
|
70
|
+
ptr = realloc(ptr, len, offset, 1) >>> 0;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
WASM_VECTOR_LEN = offset;
|
|
74
|
+
return ptr;
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
function takeFromExternrefTable0(idx) {
|
|
78
|
+
const value = wasm.__wbindgen_export_0.get(idx);
|
|
79
|
+
wasm.__externref_table_dealloc(idx);
|
|
80
|
+
return value;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Return a strongly-typed DTO; wasm-bindgen + tsify will emit .d.ts based on these Rust types
|
|
84
|
+
* @param {string} cell_json
|
|
85
|
+
* @param {number} symprec
|
|
86
|
+
* @param {string} setting
|
|
87
|
+
* @returns {MoyoDataset}
|
|
88
|
+
*/
|
|
89
|
+
export function analyze_cell(cell_json, symprec, setting) {
|
|
90
|
+
const ptr0 = passStringToWasm0(cell_json, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
91
|
+
const len0 = WASM_VECTOR_LEN;
|
|
92
|
+
const ptr1 = passStringToWasm0(setting, wasm.__wbindgen_malloc, wasm.__wbindgen_realloc);
|
|
93
|
+
const len1 = WASM_VECTOR_LEN;
|
|
94
|
+
const ret = wasm.analyze_cell(ptr0, len0, symprec, ptr1, len1);
|
|
95
|
+
if (ret[2]) {
|
|
96
|
+
throw takeFromExternrefTable0(ret[1]);
|
|
97
|
+
}
|
|
98
|
+
return takeFromExternrefTable0(ret[0]);
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
async function __wbg_load(module, imports) {
|
|
102
|
+
if (typeof Response === 'function' && module instanceof Response) {
|
|
103
|
+
if (typeof WebAssembly.instantiateStreaming === 'function') {
|
|
104
|
+
try {
|
|
105
|
+
return await WebAssembly.instantiateStreaming(module, imports);
|
|
106
|
+
|
|
107
|
+
} catch (e) {
|
|
108
|
+
if (module.headers.get('Content-Type') != 'application/wasm') {
|
|
109
|
+
console.warn("`WebAssembly.instantiateStreaming` failed because your server does not serve Wasm with `application/wasm` MIME type. Falling back to `WebAssembly.instantiate` which is slower. Original error:\n", e);
|
|
110
|
+
|
|
111
|
+
} else {
|
|
112
|
+
throw e;
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
const bytes = await module.arrayBuffer();
|
|
118
|
+
return await WebAssembly.instantiate(bytes, imports);
|
|
119
|
+
|
|
120
|
+
} else {
|
|
121
|
+
const instance = await WebAssembly.instantiate(module, imports);
|
|
122
|
+
|
|
123
|
+
if (instance instanceof WebAssembly.Instance) {
|
|
124
|
+
return { instance, module };
|
|
125
|
+
|
|
126
|
+
} else {
|
|
127
|
+
return instance;
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
function __wbg_get_imports() {
|
|
133
|
+
const imports = {};
|
|
134
|
+
imports.wbg = {};
|
|
135
|
+
imports.wbg.__wbg_new_405e22f390576ce2 = function() {
|
|
136
|
+
const ret = new Object();
|
|
137
|
+
return ret;
|
|
138
|
+
};
|
|
139
|
+
imports.wbg.__wbg_new_78feb108b6472713 = function() {
|
|
140
|
+
const ret = new Array();
|
|
141
|
+
return ret;
|
|
142
|
+
};
|
|
143
|
+
imports.wbg.__wbg_set_37837023f3d740e8 = function(arg0, arg1, arg2) {
|
|
144
|
+
arg0[arg1 >>> 0] = arg2;
|
|
145
|
+
};
|
|
146
|
+
imports.wbg.__wbg_set_3807d5f0bfc24aa7 = function(arg0, arg1, arg2) {
|
|
147
|
+
arg0[arg1] = arg2;
|
|
148
|
+
};
|
|
149
|
+
imports.wbg.__wbindgen_bigint_from_u64 = function(arg0) {
|
|
150
|
+
const ret = BigInt.asUintN(64, arg0);
|
|
151
|
+
return ret;
|
|
152
|
+
};
|
|
153
|
+
imports.wbg.__wbindgen_error_new = function(arg0, arg1) {
|
|
154
|
+
const ret = new Error(getStringFromWasm0(arg0, arg1));
|
|
155
|
+
return ret;
|
|
156
|
+
};
|
|
157
|
+
imports.wbg.__wbindgen_init_externref_table = function() {
|
|
158
|
+
const table = wasm.__wbindgen_export_0;
|
|
159
|
+
const offset = table.grow(4);
|
|
160
|
+
table.set(0, undefined);
|
|
161
|
+
table.set(offset + 0, undefined);
|
|
162
|
+
table.set(offset + 1, null);
|
|
163
|
+
table.set(offset + 2, true);
|
|
164
|
+
table.set(offset + 3, false);
|
|
165
|
+
;
|
|
166
|
+
};
|
|
167
|
+
imports.wbg.__wbindgen_number_new = function(arg0) {
|
|
168
|
+
const ret = arg0;
|
|
169
|
+
return ret;
|
|
170
|
+
};
|
|
171
|
+
imports.wbg.__wbindgen_string_new = function(arg0, arg1) {
|
|
172
|
+
const ret = getStringFromWasm0(arg0, arg1);
|
|
173
|
+
return ret;
|
|
174
|
+
};
|
|
175
|
+
imports.wbg.__wbindgen_throw = function(arg0, arg1) {
|
|
176
|
+
throw new Error(getStringFromWasm0(arg0, arg1));
|
|
177
|
+
};
|
|
178
|
+
|
|
179
|
+
return imports;
|
|
180
|
+
}
|
|
181
|
+
|
|
182
|
+
function __wbg_init_memory(imports, memory) {
|
|
183
|
+
|
|
184
|
+
}
|
|
185
|
+
|
|
186
|
+
function __wbg_finalize_init(instance, module) {
|
|
187
|
+
wasm = instance.exports;
|
|
188
|
+
__wbg_init.__wbindgen_wasm_module = module;
|
|
189
|
+
cachedUint8ArrayMemory0 = null;
|
|
190
|
+
|
|
191
|
+
|
|
192
|
+
wasm.__wbindgen_start();
|
|
193
|
+
return wasm;
|
|
194
|
+
}
|
|
195
|
+
|
|
196
|
+
function initSync(module) {
|
|
197
|
+
if (wasm !== undefined) return wasm;
|
|
198
|
+
|
|
199
|
+
|
|
200
|
+
if (typeof module !== 'undefined') {
|
|
201
|
+
if (Object.getPrototypeOf(module) === Object.prototype) {
|
|
202
|
+
({module} = module)
|
|
203
|
+
} else {
|
|
204
|
+
console.warn('using deprecated parameters for `initSync()`; pass a single object instead')
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
const imports = __wbg_get_imports();
|
|
209
|
+
|
|
210
|
+
__wbg_init_memory(imports);
|
|
211
|
+
|
|
212
|
+
if (!(module instanceof WebAssembly.Module)) {
|
|
213
|
+
module = new WebAssembly.Module(module);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
const instance = new WebAssembly.Instance(module, imports);
|
|
217
|
+
|
|
218
|
+
return __wbg_finalize_init(instance, module);
|
|
219
|
+
}
|
|
220
|
+
|
|
221
|
+
async function __wbg_init(module_or_path) {
|
|
222
|
+
if (wasm !== undefined) return wasm;
|
|
223
|
+
|
|
224
|
+
|
|
225
|
+
if (typeof module_or_path !== 'undefined') {
|
|
226
|
+
if (Object.getPrototypeOf(module_or_path) === Object.prototype) {
|
|
227
|
+
({module_or_path} = module_or_path)
|
|
228
|
+
} else {
|
|
229
|
+
console.warn('using deprecated parameters for the initialization function; pass a single object instead')
|
|
230
|
+
}
|
|
231
|
+
}
|
|
232
|
+
|
|
233
|
+
if (typeof module_or_path === 'undefined') {
|
|
234
|
+
module_or_path = new URL('moyo_wasm_bg.wasm', import.meta.url);
|
|
235
|
+
}
|
|
236
|
+
const imports = __wbg_get_imports();
|
|
237
|
+
|
|
238
|
+
if (typeof module_or_path === 'string' || (typeof Request === 'function' && module_or_path instanceof Request) || (typeof URL === 'function' && module_or_path instanceof URL)) {
|
|
239
|
+
module_or_path = fetch(module_or_path);
|
|
240
|
+
}
|
|
241
|
+
|
|
242
|
+
__wbg_init_memory(imports);
|
|
243
|
+
|
|
244
|
+
const { instance, module } = await __wbg_load(await module_or_path, imports);
|
|
245
|
+
|
|
246
|
+
return __wbg_finalize_init(instance, module);
|
|
247
|
+
}
|
|
248
|
+
|
|
249
|
+
export { initSync };
|
|
250
|
+
export default __wbg_init;
|
|
Binary file
|
package/package.json
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@spglib/moyo-wasm",
|
|
3
|
+
"type": "module",
|
|
4
|
+
"description": "WebAssembly bindings for moyo crystal symmetry analysis",
|
|
5
|
+
"version": "0.4.4",
|
|
6
|
+
"license": "MIT OR Apache-2.0",
|
|
7
|
+
"repository": {
|
|
8
|
+
"type": "git",
|
|
9
|
+
"url": "https://github.com/spglib/moyo"
|
|
10
|
+
},
|
|
11
|
+
"files": [
|
|
12
|
+
"moyo_wasm_bg.wasm",
|
|
13
|
+
"moyo_wasm.js",
|
|
14
|
+
"moyo_wasm.d.ts"
|
|
15
|
+
],
|
|
16
|
+
"main": "moyo_wasm.js",
|
|
17
|
+
"types": "moyo_wasm.d.ts",
|
|
18
|
+
"sideEffects": [
|
|
19
|
+
"./snippets/*"
|
|
20
|
+
]
|
|
21
|
+
}
|