matterviz 0.3.4 → 0.3.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/dist/FilePicker.svelte +1 -1
- package/dist/app.css +7 -0
- package/dist/brillouin/BrillouinZone.svelte +5 -2
- package/dist/brillouin/compute.js +8 -4
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte +6 -6
- package/dist/chempot-diagram/async-compute.svelte.js +5 -4
- package/dist/chempot-diagram/chempot-worker.js +2 -2
- package/dist/chempot-diagram/compute.js +16 -16
- package/dist/composition/FormulaFilter.svelte +3 -3
- package/dist/constants.js +2 -8
- package/dist/convex-hull/ConvexHull.svelte +2 -2
- package/dist/convex-hull/ConvexHull2D.svelte +11 -10
- package/dist/convex-hull/ConvexHull3D.svelte +16 -14
- package/dist/convex-hull/ConvexHull4D.svelte +26 -14
- package/dist/convex-hull/ConvexHullControls.svelte +1 -1
- package/dist/convex-hull/ConvexHullInfoPane.svelte +68 -61
- package/dist/convex-hull/ConvexHullStats.svelte +23 -6
- package/dist/convex-hull/GasPressureControls.svelte +3 -3
- package/dist/convex-hull/TemperatureSlider.svelte +1 -1
- package/dist/convex-hull/barycentric-coords.js +2 -2
- package/dist/convex-hull/helpers.js +45 -27
- package/dist/convex-hull/thermodynamics.js +2 -2
- package/dist/element/BohrAtom.svelte +25 -27
- package/dist/element/BohrAtom.svelte.d.ts +2 -2
- package/dist/element/data.d.ts +2 -3
- package/dist/fermi-surface/FermiSurface.svelte +5 -2
- package/dist/fermi-surface/compute.js +3 -3
- package/dist/fermi-surface/parse.js +2 -2
- package/dist/fermi-surface/symmetry.js +1 -1
- package/dist/heatmap-matrix/HeatmapMatrix.svelte +8 -8
- package/dist/icons.d.ts +6 -6
- package/dist/icons.js +6 -6
- package/dist/io/decompress.js +12 -7
- package/dist/io/export.js +20 -16
- package/dist/io/is-binary.js +19 -4
- package/dist/isosurface/parse.js +8 -8
- package/dist/isosurface/types.js +9 -9
- package/dist/layout/InfoTag.svelte +1 -1
- package/dist/layout/json-tree/JsonNode.svelte +1 -0
- package/dist/layout/json-tree/utils.js +2 -1
- package/dist/marching-cubes.js +1 -1
- package/dist/math.js +1 -1
- package/dist/overlays/CopyButton.svelte +45 -0
- package/dist/overlays/CopyButton.svelte.d.ts +8 -0
- package/dist/overlays/InfoPaneCards.svelte +149 -0
- package/dist/overlays/InfoPaneCards.svelte.d.ts +22 -0
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +33 -35
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +2 -2
- package/dist/phase-diagram/PhaseDiagramControls.svelte +27 -29
- package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +2 -2
- package/dist/phase-diagram/parse.js +3 -3
- package/dist/phase-diagram/svg-to-diagram.js +10 -12
- package/dist/plot/BarPlot.svelte +24 -15
- package/dist/plot/BarPlot.svelte.d.ts +3 -2
- package/dist/plot/FillArea.svelte +2 -3
- package/dist/plot/FillArea.svelte.d.ts +3 -2
- package/dist/plot/Histogram.svelte +37 -19
- package/dist/plot/Line.svelte +2 -3
- package/dist/plot/Line.svelte.d.ts +2 -2
- package/dist/plot/PlotLegend.svelte +79 -8
- package/dist/plot/PlotLegend.svelte.d.ts +4 -0
- package/dist/plot/PortalSelect.svelte +5 -5
- package/dist/plot/ScatterPlot.svelte +47 -33
- package/dist/plot/ScatterPlot.svelte.d.ts +5 -4
- package/dist/plot/ScatterPlot3D.svelte +6 -3
- package/dist/plot/ScatterPoint.svelte +10 -4
- package/dist/plot/ScatterPoint.svelte.d.ts +4 -2
- package/dist/plot/SpacegroupBarPlot.svelte +5 -4
- package/dist/plot/data-cleaning.js +9 -9
- package/dist/plot/index.d.ts +0 -6
- package/dist/plot/scales.d.ts +3 -3
- package/dist/plot/scales.js +29 -29
- package/dist/plot/types.d.ts +5 -9
- package/dist/rdf/calc-rdf.js +1 -1
- package/dist/sanitize.js +22 -15
- package/dist/settings.d.ts +2 -0
- package/dist/settings.js +12 -3
- package/dist/spectral/Bands.svelte +6 -6
- package/dist/spectral/BandsAndDos.svelte +4 -4
- package/dist/spectral/BrillouinBandsDos.svelte +3 -3
- package/dist/spectral/Dos.svelte +2 -2
- package/dist/spectral/helpers.js +1 -1
- package/dist/structure/AtomLegend.svelte +4 -4
- package/dist/structure/AtomLegend.svelte.d.ts +1 -1
- package/dist/structure/Cylinder.svelte +7 -7
- package/dist/structure/Structure.svelte +169 -27
- package/dist/structure/Structure.svelte.d.ts +6 -2
- package/dist/structure/StructureControls.svelte +130 -16
- package/dist/structure/StructureControls.svelte.d.ts +1 -1
- package/dist/structure/StructureInfoPane.svelte +519 -218
- package/dist/structure/StructureInfoPane.svelte.d.ts +2 -1
- package/dist/structure/StructureScene.svelte +399 -68
- package/dist/structure/StructureScene.svelte.d.ts +8 -4
- package/dist/structure/atom-properties.js +3 -1
- package/dist/structure/bond-order-perception.d.ts +13 -0
- package/dist/structure/bond-order-perception.js +367 -0
- package/dist/structure/bonding.d.ts +10 -1
- package/dist/structure/bonding.js +232 -11
- package/dist/structure/export.js +6 -4
- package/dist/structure/index.d.ts +19 -4
- package/dist/structure/index.js +3 -0
- package/dist/structure/label-placement.d.ts +14 -0
- package/dist/structure/label-placement.js +72 -0
- package/dist/structure/parse.d.ts +2 -1
- package/dist/structure/parse.js +25 -36
- package/dist/structure/supercell.js +35 -2
- package/dist/symmetry/SymmetryStats.svelte +1 -1
- package/dist/symmetry/cell-transform.js +15 -1
- package/dist/symmetry/index.js +3 -3
- package/dist/table/HeatmapTable.svelte +3 -3
- package/dist/table/ToggleMenu.svelte +1 -1
- package/dist/trajectory/Trajectory.svelte +2 -2
- package/dist/trajectory/TrajectoryInfoPane.svelte +14 -88
- package/dist/trajectory/extract.js +4 -4
- package/dist/trajectory/frame-reader.js +2 -2
- package/dist/trajectory/parse/ase.js +2 -6
- package/dist/trajectory/parse/hdf5.js +1 -3
- package/dist/trajectory/plotting.js +1 -1
- package/dist/utils.js +1 -1
- package/dist/xrd/calc-xrd.js +1 -1
- package/package.json +22 -37
- package/dist/structure/ferrox-wasm-types.d.ts +0 -46
- package/dist/structure/ferrox-wasm-types.js +0 -18
- package/dist/structure/ferrox-wasm.d.ts +0 -94
- package/dist/structure/ferrox-wasm.js +0 -249
|
@@ -1,249 +0,0 @@
|
|
|
1
|
-
// TypeScript wrapper for matterviz-wasm WASM bindings
|
|
2
|
-
//
|
|
3
|
-
// Provides lazy initialization, typed wrappers, and result handling utilities
|
|
4
|
-
// for the matterviz WASM module (structure matching, analysis, etc).
|
|
5
|
-
import { is_ok } from './ferrox-wasm-types';
|
|
6
|
-
// Re-export all types and utilities (no WASM side effects)
|
|
7
|
-
export * from './ferrox-wasm-types';
|
|
8
|
-
// Lazy Initialization
|
|
9
|
-
let wasm_module = null;
|
|
10
|
-
let init_promise = null;
|
|
11
|
-
// Ensure the WASM module is loaded and initialized.
|
|
12
|
-
// Memoizes the init promise to prevent concurrent callers from racing and
|
|
13
|
-
// triggering duplicate WASM initialization.
|
|
14
|
-
export function ensure_ferrox_wasm_ready() {
|
|
15
|
-
// WASM only works in browser
|
|
16
|
-
if (typeof window === `undefined`) {
|
|
17
|
-
return Promise.reject(new Error(`ferrox-wasm can only be used in the browser`));
|
|
18
|
-
}
|
|
19
|
-
// Fast path: already initialized
|
|
20
|
-
if (wasm_module)
|
|
21
|
-
return Promise.resolve(wasm_module);
|
|
22
|
-
// Memoize the init promise to prevent race conditions where concurrent
|
|
23
|
-
// callers both start initialization before the first one completes
|
|
24
|
-
if (!init_promise) {
|
|
25
|
-
init_promise = (async () => {
|
|
26
|
-
try {
|
|
27
|
-
// Dynamic import to avoid loading WASM until needed
|
|
28
|
-
const { default: init } = (await import(`matterviz-wasm`));
|
|
29
|
-
// Initialize WASM module (the package handles WASM loading internally)
|
|
30
|
-
wasm_module = await init();
|
|
31
|
-
return wasm_module;
|
|
32
|
-
}
|
|
33
|
-
catch (err) {
|
|
34
|
-
// Clear the promise on failure so retry is possible
|
|
35
|
-
init_promise = null;
|
|
36
|
-
throw new Error(`Failed to load matterviz-wasm. Install with: npm add matterviz-wasm. Original error: ${err}`, { cause: err });
|
|
37
|
-
}
|
|
38
|
-
})();
|
|
39
|
-
}
|
|
40
|
-
return init_promise;
|
|
41
|
-
}
|
|
42
|
-
// Check if the module is already initialized
|
|
43
|
-
export function is_wasm_ready() {
|
|
44
|
-
return wasm_module !== null;
|
|
45
|
-
}
|
|
46
|
-
// Typed Wrapper Functions
|
|
47
|
-
// Create a configured matcher instance with builder pattern
|
|
48
|
-
function create_matcher(mod, opts) {
|
|
49
|
-
let matcher = new mod.WasmStructureMatcher();
|
|
50
|
-
if (!opts)
|
|
51
|
-
return matcher;
|
|
52
|
-
if (opts.latt_len_tol !== undefined) {
|
|
53
|
-
matcher = matcher.with_latt_len_tol(opts.latt_len_tol);
|
|
54
|
-
}
|
|
55
|
-
if (opts.site_pos_tol !== undefined) {
|
|
56
|
-
matcher = matcher.with_site_pos_tol(opts.site_pos_tol);
|
|
57
|
-
}
|
|
58
|
-
if (opts.angle_tol !== undefined)
|
|
59
|
-
matcher = matcher.with_angle_tol(opts.angle_tol);
|
|
60
|
-
if (opts.primitive_cell !== undefined) {
|
|
61
|
-
matcher = matcher.with_primitive_cell(opts.primitive_cell);
|
|
62
|
-
}
|
|
63
|
-
if (opts.scale !== undefined)
|
|
64
|
-
matcher = matcher.with_scale(opts.scale);
|
|
65
|
-
if (opts.element_only !== undefined) {
|
|
66
|
-
matcher = matcher.with_element_comparator(opts.element_only);
|
|
67
|
-
}
|
|
68
|
-
return matcher;
|
|
69
|
-
}
|
|
70
|
-
// Check if two structures are equivalent
|
|
71
|
-
export async function match_structures(struct1, struct2, options) {
|
|
72
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
73
|
-
const matcher = create_matcher(mod, options);
|
|
74
|
-
return matcher.fit(struct1, struct2);
|
|
75
|
-
}
|
|
76
|
-
// Check if two structures match under any species permutation
|
|
77
|
-
export async function match_structures_anonymous(struct1, struct2, options) {
|
|
78
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
79
|
-
const matcher = create_matcher(mod, options);
|
|
80
|
-
return matcher.fit_anonymous(struct1, struct2);
|
|
81
|
-
}
|
|
82
|
-
// Get RMS distance between two structures
|
|
83
|
-
export async function get_structure_rms_dist(struct1, struct2, options) {
|
|
84
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
85
|
-
const matcher = create_matcher(mod, options);
|
|
86
|
-
return matcher.get_rms_dist(struct1, struct2);
|
|
87
|
-
}
|
|
88
|
-
// Get universal structure distance (always returns a value, never null)
|
|
89
|
-
// Use this for consistent ranking - returns Infinity for incompatible structures
|
|
90
|
-
export async function get_structure_distance(struct1, struct2, options) {
|
|
91
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
92
|
-
const matcher = create_matcher(mod, options);
|
|
93
|
-
return matcher.get_structure_distance(struct1, struct2);
|
|
94
|
-
}
|
|
95
|
-
// Find a matching structure from a database
|
|
96
|
-
export async function find_matching_structure(query, database, options) {
|
|
97
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
98
|
-
const matcher = create_matcher(mod, options);
|
|
99
|
-
const results = matcher.find_matches([query], database);
|
|
100
|
-
if (is_ok(results)) {
|
|
101
|
-
return { ok: results.ok[0] ?? null };
|
|
102
|
-
}
|
|
103
|
-
return results;
|
|
104
|
-
}
|
|
105
|
-
// Deduplicate a set of structures
|
|
106
|
-
export async function deduplicate_structures(structures, options) {
|
|
107
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
108
|
-
const matcher = create_matcher(mod, options);
|
|
109
|
-
return matcher.deduplicate(structures);
|
|
110
|
-
}
|
|
111
|
-
// Parse structure from file content
|
|
112
|
-
export async function parse_structure_file(content, format) {
|
|
113
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
114
|
-
switch (format) {
|
|
115
|
-
case `cif`:
|
|
116
|
-
return mod.parse_cif(content);
|
|
117
|
-
case `poscar`:
|
|
118
|
-
return mod.parse_poscar(content);
|
|
119
|
-
case `json`: {
|
|
120
|
-
let parsed;
|
|
121
|
-
try {
|
|
122
|
-
parsed = JSON.parse(content);
|
|
123
|
-
}
|
|
124
|
-
catch (exc) {
|
|
125
|
-
const msg = exc instanceof Error ? exc.message : String(exc);
|
|
126
|
-
return { error: `Invalid JSON: ${msg}` };
|
|
127
|
-
}
|
|
128
|
-
return mod.parse_structure(parsed);
|
|
129
|
-
}
|
|
130
|
-
default:
|
|
131
|
-
return { error: `Unknown structure format: ${format}` };
|
|
132
|
-
}
|
|
133
|
-
}
|
|
134
|
-
// Create a supercell with diagonal scaling matrix
|
|
135
|
-
export async function create_supercell(structure, nx, ny, nz) {
|
|
136
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
137
|
-
return mod.make_supercell_diag(structure, nx, ny, nz);
|
|
138
|
-
}
|
|
139
|
-
// Reduce lattice using Niggli or LLL algorithm
|
|
140
|
-
export async function reduce_lattice(structure, algo = `niggli`) {
|
|
141
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
142
|
-
return mod.get_reduced_structure(structure, algo);
|
|
143
|
-
}
|
|
144
|
-
// Get the primitive cell of a structure
|
|
145
|
-
export async function get_primitive_cell(structure, symprec = 1e-4) {
|
|
146
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
147
|
-
return mod.get_primitive(structure, symprec);
|
|
148
|
-
}
|
|
149
|
-
// Get the spacegroup number of a structure
|
|
150
|
-
export async function get_spacegroup(structure, symprec = 1e-4) {
|
|
151
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
152
|
-
return mod.get_spacegroup_number(structure, symprec);
|
|
153
|
-
}
|
|
154
|
-
// Serialize structure to pymatgen-compatible JSON string
|
|
155
|
-
export async function serialize_structure(structure) {
|
|
156
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
157
|
-
return mod.structure_to_json(structure);
|
|
158
|
-
}
|
|
159
|
-
// Physical Properties
|
|
160
|
-
export async function get_volume(structure) {
|
|
161
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
162
|
-
return mod.get_volume(structure);
|
|
163
|
-
}
|
|
164
|
-
// Get total mass in atomic mass units (u)
|
|
165
|
-
export async function get_total_mass(structure) {
|
|
166
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
167
|
-
return mod.get_total_mass(structure);
|
|
168
|
-
}
|
|
169
|
-
// Get density in g/cm^3
|
|
170
|
-
export async function get_density(structure) {
|
|
171
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
172
|
-
return mod.get_density(structure);
|
|
173
|
-
}
|
|
174
|
-
// Neighbor Finding
|
|
175
|
-
export async function get_neighbor_list(structure, cutoff_radius, numerical_tol = 1e-8, exclude_self = true) {
|
|
176
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
177
|
-
return mod.get_neighbor_list(structure, cutoff_radius, numerical_tol, exclude_self);
|
|
178
|
-
}
|
|
179
|
-
// Get minimum image distance between two sites
|
|
180
|
-
export async function get_distance(structure, i, j) {
|
|
181
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
182
|
-
return mod.get_distance(structure, i, j);
|
|
183
|
-
}
|
|
184
|
-
// Get full NxN distance matrix
|
|
185
|
-
export async function get_distance_matrix(structure) {
|
|
186
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
187
|
-
return mod.get_distance_matrix(structure);
|
|
188
|
-
}
|
|
189
|
-
// Sorting
|
|
190
|
-
export async function get_sorted_structure(structure, reverse = false) {
|
|
191
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
192
|
-
return mod.get_sorted_structure(structure, reverse);
|
|
193
|
-
}
|
|
194
|
-
// Get structure sorted by electronegativity
|
|
195
|
-
export async function get_sorted_by_electronegativity(structure, reverse = false) {
|
|
196
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
197
|
-
return mod.get_sorted_by_electronegativity(structure, reverse);
|
|
198
|
-
}
|
|
199
|
-
// Interpolation
|
|
200
|
-
export async function interpolate_structures(start, end, n_images, options) {
|
|
201
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
202
|
-
return mod.interpolate_structures(start, end, n_images, options?.interpolate_lattices ?? false, options?.use_pbc ?? true);
|
|
203
|
-
}
|
|
204
|
-
// Copy and Wrap
|
|
205
|
-
export async function copy_structure(structure, sanitize = false) {
|
|
206
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
207
|
-
return mod.copy_structure(structure, sanitize);
|
|
208
|
-
}
|
|
209
|
-
// Wrap all fractional coordinates to [0, 1)
|
|
210
|
-
export async function wrap_to_unit_cell(structure) {
|
|
211
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
212
|
-
return mod.wrap_to_unit_cell(structure);
|
|
213
|
-
}
|
|
214
|
-
// Supercell with Full Matrix
|
|
215
|
-
export async function create_supercell_matrix(structure, matrix) {
|
|
216
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
217
|
-
return mod.make_supercell(structure, matrix);
|
|
218
|
-
}
|
|
219
|
-
// Site Manipulation
|
|
220
|
-
export async function translate_sites(structure, indices, vector, frac_coords = false) {
|
|
221
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
222
|
-
return mod.translate_sites(structure, indices, vector, frac_coords);
|
|
223
|
-
}
|
|
224
|
-
// Perturb all sites by random vectors
|
|
225
|
-
export async function perturb_structure(structure, distance, options) {
|
|
226
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
227
|
-
return mod.perturb_structure(structure, distance, options?.min_distance, options?.seed);
|
|
228
|
-
}
|
|
229
|
-
// Element Information
|
|
230
|
-
export async function get_atomic_mass(symbol) {
|
|
231
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
232
|
-
return mod.get_atomic_mass(symbol);
|
|
233
|
-
}
|
|
234
|
-
// Get electronegativity of an element by symbol
|
|
235
|
-
export async function get_electronegativity(symbol) {
|
|
236
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
237
|
-
return mod.get_electronegativity(symbol);
|
|
238
|
-
}
|
|
239
|
-
// XRD calculation using Rust WASM
|
|
240
|
-
export async function compute_xrd_wasm(structure, options) {
|
|
241
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
242
|
-
return mod.compute_xrd(structure, options);
|
|
243
|
-
}
|
|
244
|
-
// Get atomic scattering params (SSOT shared with Rust/Python)
|
|
245
|
-
// Returns the raw JSON string of Cromer-Mann coefficients
|
|
246
|
-
export async function get_atomic_scattering_params_wasm() {
|
|
247
|
-
const mod = await ensure_ferrox_wasm_ready();
|
|
248
|
-
return mod.get_atomic_scattering_params();
|
|
249
|
-
}
|