matterviz 0.3.1 → 0.3.3
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/EmptyState.svelte +10 -2
- package/dist/FilePicker.svelte +154 -96
- package/dist/Icon.svelte +20 -14
- package/dist/MillerIndexInput.svelte +27 -21
- package/dist/api/optimade.js +6 -6
- package/dist/app.css +216 -178
- package/dist/brillouin/BrillouinZone.svelte +299 -198
- package/dist/brillouin/BrillouinZone.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneControls.svelte +32 -5
- package/dist/brillouin/BrillouinZoneExportPane.svelte +74 -55
- package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneInfoPane.svelte +99 -68
- package/dist/brillouin/BrillouinZoneScene.svelte +277 -165
- package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneTooltip.svelte +17 -7
- package/dist/brillouin/compute.js +11 -6
- package/dist/chempot-diagram/ChemPotDiagram.svelte +327 -0
- package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +13 -0
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte +847 -0
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +16 -0
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte +3194 -0
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +16 -0
- package/dist/chempot-diagram/ChemPotScene3D.svelte +11 -0
- package/dist/chempot-diagram/ChemPotScene3D.svelte.d.ts +7 -0
- package/dist/chempot-diagram/async-compute.svelte.d.ts +3 -0
- package/dist/chempot-diagram/async-compute.svelte.js +77 -0
- package/dist/chempot-diagram/chempot-worker.d.ts +1 -0
- package/dist/chempot-diagram/chempot-worker.js +11 -0
- package/dist/chempot-diagram/color.d.ts +10 -0
- package/dist/chempot-diagram/color.js +32 -0
- package/dist/chempot-diagram/compute.d.ts +48 -0
- package/dist/chempot-diagram/compute.js +812 -0
- package/dist/chempot-diagram/index.d.ts +6 -0
- package/dist/chempot-diagram/index.js +6 -0
- package/dist/chempot-diagram/pointer.d.ts +16 -0
- package/dist/chempot-diagram/pointer.js +40 -0
- package/dist/chempot-diagram/temperature.d.ts +15 -0
- package/dist/chempot-diagram/temperature.js +36 -0
- package/dist/chempot-diagram/types.d.ts +86 -0
- package/dist/chempot-diagram/types.js +28 -0
- package/dist/colors/index.d.ts +3 -1
- package/dist/colors/index.js +9 -3
- package/dist/composition/BarChart.svelte +141 -77
- package/dist/composition/BubbleChart.svelte +107 -52
- package/dist/composition/Composition.svelte +100 -79
- package/dist/composition/Formula.svelte +108 -62
- package/dist/composition/FormulaFilter.svelte +973 -353
- package/dist/composition/FormulaFilter.svelte.d.ts +35 -1
- package/dist/composition/PieChart.svelte +199 -99
- package/dist/composition/PieChart.svelte.d.ts +1 -1
- package/dist/composition/format.d.ts +5 -0
- package/dist/composition/format.js +20 -3
- package/dist/composition/parse.js +14 -9
- package/dist/convex-hull/ConvexHull.svelte +93 -38
- package/dist/convex-hull/ConvexHull2D.svelte +551 -393
- package/dist/convex-hull/ConvexHull3D.svelte +1303 -825
- package/dist/convex-hull/ConvexHull4D.svelte +1012 -686
- package/dist/convex-hull/ConvexHullControls.svelte +115 -28
- package/dist/convex-hull/ConvexHullInfoPane.svelte +29 -3
- package/dist/convex-hull/ConvexHullStats.svelte +821 -249
- package/dist/convex-hull/ConvexHullStats.svelte.d.ts +6 -1
- package/dist/convex-hull/ConvexHullTooltip.svelte +41 -16
- package/dist/convex-hull/GasPressureControls.svelte +104 -61
- package/dist/convex-hull/StructurePopup.svelte +25 -4
- package/dist/convex-hull/TemperatureSlider.svelte +45 -25
- package/dist/convex-hull/barycentric-coords.js +13 -7
- package/dist/convex-hull/demo-temperature.d.ts +6 -0
- package/dist/convex-hull/demo-temperature.js +40 -0
- package/dist/convex-hull/gas-thermodynamics.js +17 -12
- package/dist/convex-hull/helpers.d.ts +10 -1
- package/dist/convex-hull/helpers.js +79 -38
- package/dist/convex-hull/index.d.ts +1 -0
- package/dist/convex-hull/index.js +1 -0
- package/dist/convex-hull/thermodynamics.d.ts +8 -21
- package/dist/convex-hull/thermodynamics.js +163 -69
- package/dist/convex-hull/types.d.ts +12 -12
- package/dist/convex-hull/types.js +0 -12
- package/dist/coordination/CoordinationBarPlot.svelte +232 -176
- package/dist/element/BohrAtom.svelte +56 -13
- package/dist/element/ElementHeading.svelte +7 -2
- package/dist/element/ElementPhoto.svelte +15 -9
- package/dist/element/ElementStats.svelte +10 -4
- package/dist/element/ElementTile.svelte +137 -73
- package/dist/element/Nucleus.svelte +39 -11
- package/dist/element/data.js +2 -14
- package/dist/element/data.json.gz +0 -0
- package/dist/element/types.d.ts +1 -0
- package/dist/feedback/ClickFeedback.svelte +16 -5
- package/dist/feedback/DragOverlay.svelte +10 -2
- package/dist/feedback/Spinner.svelte +4 -2
- package/dist/feedback/StatusMessage.svelte +8 -2
- package/dist/fermi-surface/FermiSlice.svelte +118 -88
- package/dist/fermi-surface/FermiSurface.svelte +336 -239
- package/dist/fermi-surface/FermiSurface.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceControls.svelte +113 -46
- package/dist/fermi-surface/FermiSurfaceScene.svelte +536 -343
- package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceTooltip.svelte +14 -5
- package/dist/fermi-surface/compute.js +16 -20
- package/dist/fermi-surface/parse.js +37 -33
- package/dist/fermi-surface/symmetry.js +2 -7
- package/dist/fermi-surface/types.d.ts +3 -5
- package/dist/heatmap-matrix/HeatmapMatrix.svelte +1527 -0
- package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +110 -0
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +225 -0
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +30 -0
- package/dist/heatmap-matrix/index.d.ts +53 -0
- package/dist/heatmap-matrix/index.js +100 -0
- package/dist/heatmap-matrix/shared.d.ts +2 -0
- package/dist/heatmap-matrix/shared.js +4 -0
- package/dist/icons.d.ts +111 -0
- package/dist/icons.js +158 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +5 -2
- package/dist/io/decompress.js +1 -1
- package/dist/io/export.d.ts +3 -0
- package/dist/io/export.js +138 -140
- package/dist/io/file-drop.d.ts +7 -0
- package/dist/io/file-drop.js +43 -0
- package/dist/io/index.d.ts +2 -2
- package/dist/io/index.js +2 -112
- package/dist/io/is-binary.js +2 -3
- package/dist/io/types.d.ts +1 -0
- package/dist/io/url-drop.d.ts +2 -0
- package/dist/io/url-drop.js +117 -0
- package/dist/isosurface/Isosurface.svelte +220 -110
- package/dist/isosurface/IsosurfaceControls.svelte +65 -28
- package/dist/isosurface/parse.js +104 -56
- package/dist/isosurface/slice.d.ts +2 -1
- package/dist/isosurface/slice.js +8 -13
- package/dist/isosurface/types.d.ts +14 -1
- package/dist/isosurface/types.js +152 -5
- package/dist/labels.d.ts +2 -1
- package/dist/labels.js +12 -8
- package/dist/layout/FullscreenToggle.svelte +11 -2
- package/dist/layout/InfoCard.svelte +38 -6
- package/dist/layout/InfoTag.svelte +125 -94
- package/dist/layout/PropertyFilter.svelte +82 -37
- package/dist/layout/SettingsSection.svelte +85 -55
- package/dist/layout/SubpageGrid.svelte +82 -0
- package/dist/layout/SubpageGrid.svelte.d.ts +14 -0
- package/dist/layout/index.d.ts +1 -0
- package/dist/layout/index.js +1 -0
- package/dist/layout/json-tree/JsonNode.svelte +266 -223
- package/dist/layout/json-tree/JsonTree.svelte +516 -429
- package/dist/layout/json-tree/JsonTree.svelte.d.ts +1 -1
- package/dist/layout/json-tree/JsonValue.svelte +281 -173
- package/dist/layout/json-tree/types.d.ts +10 -2
- package/dist/layout/json-tree/utils.d.ts +2 -0
- package/dist/layout/json-tree/utils.js +37 -2
- package/dist/marching-cubes.js +25 -2
- package/dist/math.d.ts +20 -17
- package/dist/math.js +474 -57
- package/dist/overlays/ContextMenu.svelte +66 -40
- package/dist/overlays/DraggablePane.svelte +331 -154
- package/dist/overlays/DraggablePane.svelte.d.ts +2 -0
- package/dist/periodic-table/PeriodicTable.svelte +278 -145
- package/dist/periodic-table/PeriodicTableControls.svelte +178 -128
- package/dist/periodic-table/PropertySelect.svelte +25 -7
- package/dist/periodic-table/TableInset.svelte +8 -3
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +559 -267
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +6 -2
- package/dist/phase-diagram/PhaseDiagramControls.svelte +131 -51
- package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +3 -2
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +126 -0
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +15 -0
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte +160 -110
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +8 -1
- package/dist/phase-diagram/PhaseDiagramTooltip.svelte +217 -86
- package/dist/phase-diagram/PhaseDiagramTooltip.svelte.d.ts +6 -3
- package/dist/phase-diagram/TdbInfoPanel.svelte +28 -4
- package/dist/phase-diagram/build-diagram.js +9 -9
- package/dist/phase-diagram/colors.js +1 -3
- package/dist/phase-diagram/index.d.ts +2 -0
- package/dist/phase-diagram/index.js +2 -0
- package/dist/phase-diagram/parse.js +10 -9
- package/dist/phase-diagram/svg-to-diagram.d.ts +2 -0
- package/dist/phase-diagram/svg-to-diagram.js +869 -0
- package/dist/phase-diagram/types.d.ts +10 -0
- package/dist/phase-diagram/utils.d.ts +8 -4
- package/dist/phase-diagram/utils.js +219 -74
- package/dist/plot/AxisLabel.svelte +51 -0
- package/dist/plot/AxisLabel.svelte.d.ts +16 -0
- package/dist/plot/BarPlot.svelte +1461 -768
- package/dist/plot/BarPlot.svelte.d.ts +3 -3
- package/dist/plot/BarPlotControls.svelte +33 -6
- package/dist/plot/BarPlotControls.svelte.d.ts +1 -1
- package/dist/plot/ColorBar.svelte +533 -383
- package/dist/plot/ColorBar.svelte.d.ts +1 -1
- package/dist/plot/ColorScaleSelect.svelte +28 -7
- package/dist/plot/ElementScatter.svelte +38 -16
- package/dist/plot/FillArea.svelte +152 -92
- package/dist/plot/Histogram.svelte +1162 -709
- package/dist/plot/Histogram.svelte.d.ts +1 -1
- package/dist/plot/HistogramControls.svelte +81 -18
- package/dist/plot/HistogramControls.svelte.d.ts +6 -2
- package/dist/plot/InteractiveAxisLabel.svelte +34 -11
- package/dist/plot/InteractiveAxisLabel.svelte.d.ts +1 -1
- package/dist/plot/Line.svelte +63 -28
- package/dist/plot/PlotControls.svelte +221 -96
- package/dist/plot/PlotControls.svelte.d.ts +1 -1
- package/dist/plot/PlotLegend.svelte +174 -91
- package/dist/plot/PlotTooltip.svelte +45 -6
- package/dist/plot/PortalSelect.svelte +175 -146
- package/dist/plot/ReferenceLine.svelte +77 -22
- package/dist/plot/ReferenceLine.svelte.d.ts +1 -0
- package/dist/plot/ReferenceLine3D.svelte +132 -107
- package/dist/plot/ReferencePlane.svelte +146 -123
- package/dist/plot/ScatterPlot.svelte +1880 -1156
- package/dist/plot/ScatterPlot.svelte.d.ts +3 -3
- package/dist/plot/ScatterPlot3D.svelte +256 -131
- package/dist/plot/ScatterPlot3D.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlot3DControls.svelte +300 -297
- package/dist/plot/ScatterPlot3DControls.svelte.d.ts +2 -1
- package/dist/plot/ScatterPlot3DScene.svelte +608 -406
- package/dist/plot/ScatterPlot3DScene.svelte.d.ts +2 -2
- package/dist/plot/ScatterPlotControls.svelte +150 -70
- package/dist/plot/ScatterPlotControls.svelte.d.ts +1 -1
- package/dist/plot/ScatterPoint.svelte +98 -26
- package/dist/plot/ScatterPoint.svelte.d.ts +1 -0
- package/dist/plot/SpacegroupBarPlot.svelte +142 -85
- package/dist/plot/Surface3D.svelte +159 -108
- package/dist/plot/ZeroLines.svelte +96 -0
- package/dist/plot/ZeroLines.svelte.d.ts +32 -0
- package/dist/plot/ZoomRect.svelte +23 -0
- package/dist/plot/ZoomRect.svelte.d.ts +8 -0
- package/dist/plot/axis-utils.d.ts +1 -1
- package/dist/plot/axis-utils.js +1 -3
- package/dist/plot/data-cleaning.js +12 -28
- package/dist/plot/data-transform.js +2 -1
- package/dist/plot/fill-utils.js +2 -0
- package/dist/plot/index.d.ts +6 -2
- package/dist/plot/index.js +6 -2
- package/dist/plot/interactions.d.ts +8 -10
- package/dist/plot/interactions.js +2 -3
- package/dist/plot/layout.d.ts +11 -2
- package/dist/plot/layout.js +44 -17
- package/dist/plot/reference-line.d.ts +5 -22
- package/dist/plot/reference-line.js +12 -84
- package/dist/plot/scales.js +24 -36
- package/dist/plot/types.d.ts +53 -40
- package/dist/plot/types.js +12 -7
- package/dist/plot/utils/label-placement.d.ts +32 -15
- package/dist/plot/utils/label-placement.js +227 -63
- package/dist/plot/utils/series-visibility.js +2 -3
- package/dist/plot/utils.d.ts +1 -0
- package/dist/plot/utils.js +14 -0
- package/dist/rdf/RdfPlot.svelte +173 -132
- package/dist/rdf/calc-rdf.js +4 -5
- package/dist/sanitize.d.ts +4 -0
- package/dist/sanitize.js +107 -0
- package/dist/settings.d.ts +21 -6
- package/dist/settings.js +63 -19
- package/dist/spectral/Bands.svelte +963 -412
- package/dist/spectral/Bands.svelte.d.ts +22 -2
- package/dist/spectral/BandsAndDos.svelte +90 -49
- package/dist/spectral/BrillouinBandsDos.svelte +151 -93
- package/dist/spectral/Dos.svelte +389 -258
- package/dist/spectral/helpers.d.ts +23 -1
- package/dist/spectral/helpers.js +119 -51
- package/dist/spectral/types.d.ts +2 -0
- package/dist/state.svelte.d.ts +1 -1
- package/dist/state.svelte.js +3 -2
- package/dist/structure/Arrow.svelte +59 -20
- package/dist/structure/AtomLegend.svelte +231 -129
- package/dist/structure/AtomLegend.svelte.d.ts +1 -1
- package/dist/structure/Bond.svelte +73 -47
- package/dist/structure/CanvasTooltip.svelte +10 -2
- package/dist/structure/CellSelect.svelte +148 -51
- package/dist/structure/Cylinder.svelte +33 -17
- package/dist/structure/Lattice.svelte +88 -33
- package/dist/structure/Structure.svelte +1077 -821
- package/dist/structure/Structure.svelte.d.ts +1 -1
- package/dist/structure/StructureControls.svelte +373 -139
- package/dist/structure/StructureControls.svelte.d.ts +1 -1
- package/dist/structure/StructureExportPane.svelte +124 -89
- package/dist/structure/StructureExportPane.svelte.d.ts +1 -1
- package/dist/structure/StructureInfoPane.svelte +304 -231
- package/dist/structure/StructureScene.svelte +919 -445
- package/dist/structure/StructureScene.svelte.d.ts +16 -7
- package/dist/structure/atom-properties.d.ts +6 -2
- package/dist/structure/atom-properties.js +42 -29
- package/dist/structure/bonding.js +6 -7
- package/dist/structure/export.js +22 -34
- package/dist/structure/ferrox-wasm-types.d.ts +3 -2
- package/dist/structure/ferrox-wasm-types.js +0 -3
- package/dist/structure/ferrox-wasm.d.ts +3 -2
- package/dist/structure/ferrox-wasm.js +2 -3
- package/dist/structure/index.d.ts +16 -0
- package/dist/structure/index.js +88 -6
- package/dist/structure/measure.d.ts +2 -2
- package/dist/structure/measure.js +4 -44
- package/dist/structure/parse.js +130 -155
- package/dist/structure/partial-occupancy.d.ts +25 -0
- package/dist/structure/partial-occupancy.js +99 -0
- package/dist/structure/pbc.d.ts +1 -0
- package/dist/structure/pbc.js +16 -6
- package/dist/structure/supercell.d.ts +2 -2
- package/dist/structure/supercell.js +12 -22
- package/dist/structure/validation.js +5 -3
- package/dist/symmetry/SymmetryStats.svelte +94 -37
- package/dist/symmetry/WyckoffTable.svelte +42 -14
- package/dist/symmetry/cell-transform.js +5 -3
- package/dist/symmetry/index.d.ts +7 -4
- package/dist/symmetry/index.js +87 -21
- package/dist/symmetry/spacegroups.js +148 -148
- package/dist/table/HeatmapTable.svelte +1112 -516
- package/dist/table/HeatmapTable.svelte.d.ts +12 -1
- package/dist/table/ToggleMenu.svelte +125 -90
- package/dist/table/index.d.ts +2 -0
- package/dist/table/index.js +2 -4
- package/dist/theme/ThemeControl.svelte +21 -12
- package/dist/time.js +4 -1
- package/dist/tooltip/TooltipContent.svelte +33 -8
- package/dist/trajectory/Trajectory.svelte +889 -687
- package/dist/trajectory/TrajectoryError.svelte +14 -3
- package/dist/trajectory/TrajectoryExportPane.svelte +148 -90
- package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +1 -1
- package/dist/trajectory/TrajectoryInfoPane.svelte +272 -143
- package/dist/trajectory/constants.d.ts +6 -0
- package/dist/trajectory/constants.js +7 -0
- package/dist/trajectory/extract.js +13 -31
- package/dist/trajectory/format-detect.d.ts +9 -0
- package/dist/trajectory/format-detect.js +76 -0
- package/dist/trajectory/frame-reader.d.ts +17 -0
- package/dist/trajectory/frame-reader.js +332 -0
- package/dist/trajectory/helpers.d.ts +14 -0
- package/dist/trajectory/helpers.js +172 -0
- package/dist/trajectory/index.d.ts +1 -0
- package/dist/trajectory/index.js +23 -14
- package/dist/trajectory/parse/ase.d.ts +2 -0
- package/dist/trajectory/parse/ase.js +77 -0
- package/dist/trajectory/parse/hdf5.d.ts +2 -0
- package/dist/trajectory/parse/hdf5.js +129 -0
- package/dist/trajectory/parse/index.d.ts +12 -0
- package/dist/trajectory/parse/index.js +299 -0
- package/dist/trajectory/parse/lammps.d.ts +5 -0
- package/dist/trajectory/parse/lammps.js +179 -0
- package/dist/trajectory/parse/vasp.d.ts +2 -0
- package/dist/trajectory/parse/vasp.js +68 -0
- package/dist/trajectory/parse/xyz.d.ts +2 -0
- package/dist/trajectory/parse/xyz.js +110 -0
- package/dist/trajectory/plotting.js +13 -8
- package/dist/trajectory/types.d.ts +11 -0
- package/dist/trajectory/types.js +1 -0
- package/dist/utils.d.ts +3 -0
- package/dist/utils.js +17 -0
- package/dist/xrd/XrdPlot.svelte +337 -245
- package/dist/xrd/broadening.js +14 -9
- package/dist/xrd/calc-xrd.js +12 -19
- package/dist/xrd/parse.d.ts +1 -1
- package/dist/xrd/parse.js +17 -17
- package/package.json +103 -101
- package/readme.md +4 -4
- package/dist/trajectory/parse.d.ts +0 -42
- package/dist/trajectory/parse.js +0 -1267
- /package/dist/element/{data.json.d.ts → data.json.gz.d.ts} +0 -0
- /package/dist/theme/{themes.js → themes.mjs} +0 -0
package/dist/trajectory/index.js
CHANGED
|
@@ -3,6 +3,7 @@ export { default as TrajectoryError } from './TrajectoryError.svelte';
|
|
|
3
3
|
export { default as TrajectoryExportPane } from './TrajectoryExportPane.svelte';
|
|
4
4
|
export { default as TrajectoryInfoPane } from './TrajectoryInfoPane.svelte';
|
|
5
5
|
export function validate_trajectory(trajectory) {
|
|
6
|
+
// with detailed error reporting
|
|
6
7
|
const errors = [];
|
|
7
8
|
const { frames, total_frames, indexed_frames, plot_metadata, is_indexed } = trajectory;
|
|
8
9
|
if (!frames?.length)
|
|
@@ -20,8 +21,11 @@ export function validate_trajectory(trajectory) {
|
|
|
20
21
|
if (typeof total_frames !== `number` || total_frames < 1) {
|
|
21
22
|
errors.push(`total_frames must be a positive number, got ${total_frames}`);
|
|
22
23
|
}
|
|
23
|
-
else if (indexed_frames
|
|
24
|
-
|
|
24
|
+
else if (indexed_frames?.length) {
|
|
25
|
+
const last_indexed_frame = indexed_frames.at(-1);
|
|
26
|
+
if (last_indexed_frame && last_indexed_frame.frame_number >= total_frames) {
|
|
27
|
+
errors.push(`indexed_frames contains frame_number >= total_frames (${total_frames})`);
|
|
28
|
+
}
|
|
25
29
|
}
|
|
26
30
|
}
|
|
27
31
|
if (is_indexed === true && !indexed_frames?.length) {
|
|
@@ -36,8 +40,11 @@ export function validate_trajectory(trajectory) {
|
|
|
36
40
|
if (typeof frame_idx.frame_number !== `number`) {
|
|
37
41
|
errors.push(`indexed_frames[${idx}] missing or invalid frame_number`);
|
|
38
42
|
}
|
|
39
|
-
else if (frame_idx.frame_number
|
|
40
|
-
errors.push(`indexed_frames[${idx}] frame_number (${frame_idx.frame_number})
|
|
43
|
+
else if (frame_idx.frame_number < 0) {
|
|
44
|
+
errors.push(`indexed_frames[${idx}] frame_number (${frame_idx.frame_number}) must be non-negative`);
|
|
45
|
+
}
|
|
46
|
+
else if (idx > 0 && frame_idx.frame_number <= indexed_frames[idx - 1].frame_number) {
|
|
47
|
+
errors.push(`indexed_frames[${idx}] frame_number (${frame_idx.frame_number}) must be strictly increasing`);
|
|
41
48
|
}
|
|
42
49
|
if (typeof frame_idx.byte_offset !== `number`) {
|
|
43
50
|
errors.push(`indexed_frames[${idx}] missing or invalid byte_offset`);
|
|
@@ -78,16 +85,18 @@ export function get_trajectory_stats(trajectory) {
|
|
|
78
85
|
if (frames.length > 0) {
|
|
79
86
|
const [first_frame, last_frame] = [frames[0], frames.at(-1) ?? frames[0]];
|
|
80
87
|
const max_sample = 100;
|
|
81
|
-
const sampled = frames.length <= max_sample
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
result
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
88
|
+
const sampled = frames.length <= max_sample
|
|
89
|
+
? frames
|
|
90
|
+
: (() => {
|
|
91
|
+
const interval = Math.floor(frames.length / max_sample);
|
|
92
|
+
const result = [first_frame];
|
|
93
|
+
for (let idx = interval; idx < frames.length - 1; idx += interval) {
|
|
94
|
+
result.push(frames[idx]);
|
|
95
|
+
}
|
|
96
|
+
if (result.at(-1) !== last_frame)
|
|
97
|
+
result.push(last_frame);
|
|
98
|
+
return result;
|
|
99
|
+
})();
|
|
91
100
|
const counts = sampled.map((frame) => frame.structure.sites.length);
|
|
92
101
|
const constant = counts.every((c) => c === counts[0]);
|
|
93
102
|
const all_counts = constant
|
|
@@ -0,0 +1,77 @@
|
|
|
1
|
+
// ASE trajectory (.traj) parsing - binary format
|
|
2
|
+
import { MAX_SAFE_STRING_LENGTH } from '../constants';
|
|
3
|
+
import { convert_atomic_numbers, create_trajectory_frame, read_ndarray_from_view, validate_3x3_matrix, } from '../helpers';
|
|
4
|
+
export function parse_ase_trajectory(buffer, filename) {
|
|
5
|
+
const view = new DataView(buffer);
|
|
6
|
+
let offset = 0;
|
|
7
|
+
const signature = new TextDecoder().decode(new Uint8Array(buffer, 0, 8));
|
|
8
|
+
if (signature !== `- of Ulm`)
|
|
9
|
+
throw new Error(`Invalid ASE trajectory`);
|
|
10
|
+
offset += 24;
|
|
11
|
+
const _version = Number(view.getBigInt64(offset, true));
|
|
12
|
+
offset += 8;
|
|
13
|
+
const n_items = Number(view.getBigInt64(offset, true));
|
|
14
|
+
offset += 8;
|
|
15
|
+
const offsets_pos = Number(view.getBigInt64(offset, true));
|
|
16
|
+
if (n_items <= 0)
|
|
17
|
+
throw new Error(`Invalid frame count`);
|
|
18
|
+
if (offsets_pos < 0 || offsets_pos + n_items * 8 > buffer.byteLength) {
|
|
19
|
+
throw new Error(`Invalid ASE frame offsets table bounds: offsets_pos=${offsets_pos}, n_items=${n_items}, byte_length=${buffer.byteLength}`);
|
|
20
|
+
}
|
|
21
|
+
const frame_offsets = Array.from({ length: n_items }, (_, idx) => Number(view.getBigInt64(offsets_pos + idx * 8, true)));
|
|
22
|
+
const frames = [];
|
|
23
|
+
let global_numbers;
|
|
24
|
+
for (let idx = 0; idx < n_items; idx++) {
|
|
25
|
+
try {
|
|
26
|
+
offset = frame_offsets[idx];
|
|
27
|
+
const json_length = Number(view.getBigInt64(offset, true));
|
|
28
|
+
offset += 8;
|
|
29
|
+
if (json_length > MAX_SAFE_STRING_LENGTH) {
|
|
30
|
+
console.warn(`Skipping frame ${idx + 1}/${n_items}: too large`);
|
|
31
|
+
continue;
|
|
32
|
+
}
|
|
33
|
+
const frame_data = JSON.parse(new TextDecoder().decode(new Uint8Array(buffer, offset, json_length)));
|
|
34
|
+
const positions_ref = frame_data[`positions.`] || frame_data.positions;
|
|
35
|
+
const positions = positions_ref?.ndarray
|
|
36
|
+
? read_ndarray_from_view(view, positions_ref)
|
|
37
|
+
: positions_ref;
|
|
38
|
+
const numbers_ref = frame_data[`numbers.`] || frame_data.numbers || global_numbers;
|
|
39
|
+
const numbers = numbers_ref?.ndarray
|
|
40
|
+
? read_ndarray_from_view(view, numbers_ref).flat()
|
|
41
|
+
: numbers_ref;
|
|
42
|
+
if (numbers)
|
|
43
|
+
global_numbers = numbers;
|
|
44
|
+
if (!numbers || !positions) {
|
|
45
|
+
console.warn(`Skipping ASE frame ${idx + 1}/${n_items}: missing ${!numbers ? `numbers` : `positions`}`);
|
|
46
|
+
continue;
|
|
47
|
+
}
|
|
48
|
+
const elements = convert_atomic_numbers(numbers);
|
|
49
|
+
const metadata = {
|
|
50
|
+
step: idx,
|
|
51
|
+
...(frame_data.calculator || {}),
|
|
52
|
+
...(frame_data.info || {}),
|
|
53
|
+
};
|
|
54
|
+
frames.push(create_trajectory_frame(positions, elements, frame_data.cell ? validate_3x3_matrix(frame_data.cell) : undefined, frame_data.pbc || [true, true, true], idx, metadata));
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
console.warn(`Error processing frame ${idx + 1}/${n_items}:`, error);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
if (frames.length === 0)
|
|
61
|
+
throw new Error(`No valid frames found`);
|
|
62
|
+
const first_struct = frames[0]?.structure;
|
|
63
|
+
const periodic_boundary_conditions = first_struct !== null &&
|
|
64
|
+
first_struct !== undefined &&
|
|
65
|
+
typeof first_struct === `object` &&
|
|
66
|
+
`lattice` in first_struct
|
|
67
|
+
? first_struct.lattice.pbc
|
|
68
|
+
: [true, true, true];
|
|
69
|
+
const metadata = {
|
|
70
|
+
filename,
|
|
71
|
+
source_format: `ase_trajectory`,
|
|
72
|
+
frame_count: frames.length,
|
|
73
|
+
total_atoms: global_numbers?.length || 0,
|
|
74
|
+
periodic_boundary_conditions,
|
|
75
|
+
};
|
|
76
|
+
return { frames, metadata };
|
|
77
|
+
}
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
// HDF5 trajectory parsing (torch-sim / generic format)
|
|
2
|
+
import { calc_lattice_params, transpose_3x3_matrix } from '../../math';
|
|
3
|
+
import * as h5wasm from 'h5wasm';
|
|
4
|
+
import { convert_atomic_numbers, create_trajectory_frame, validate_3x3_matrix, } from '../helpers';
|
|
5
|
+
const is_hdf5_dataset = (entity) => entity !== null && `to_array` in entity && entity instanceof h5wasm.Dataset;
|
|
6
|
+
const is_hdf5_group = (entity) => entity !== null && `keys` in entity && entity instanceof h5wasm.Group;
|
|
7
|
+
export async function parse_torch_sim_hdf5(buffer, filename) {
|
|
8
|
+
const { FS } = await h5wasm.ready;
|
|
9
|
+
const file_basename = filename
|
|
10
|
+
?.split(`/`)
|
|
11
|
+
.at(-1)
|
|
12
|
+
?.replace(/[^\w.-]/g, `_`) || `temp`;
|
|
13
|
+
const unique_suffix = `${Date.now()}-${Math.random().toString(36).slice(2)}`;
|
|
14
|
+
const temp_filename = `${file_basename}-${unique_suffix}.h5`;
|
|
15
|
+
FS.writeFile(temp_filename, new Uint8Array(buffer));
|
|
16
|
+
let h5_file = null;
|
|
17
|
+
try {
|
|
18
|
+
h5_file = new h5wasm.File(temp_filename, `r`);
|
|
19
|
+
const found_paths = {};
|
|
20
|
+
let total_groups_found = 0;
|
|
21
|
+
const find_dataset = (names) => {
|
|
22
|
+
const discover = (parent, path = ``) => {
|
|
23
|
+
total_groups_found++;
|
|
24
|
+
for (const name of parent.keys()) {
|
|
25
|
+
const item = parent.get(name);
|
|
26
|
+
const full_path = path ? `${path}/${name}` : `/${name}`;
|
|
27
|
+
if (names.includes(name) && is_hdf5_dataset(item)) {
|
|
28
|
+
const found_name = names.find((n) => n === name);
|
|
29
|
+
if (found_name)
|
|
30
|
+
found_paths[found_name] = full_path;
|
|
31
|
+
return item;
|
|
32
|
+
}
|
|
33
|
+
if (is_hdf5_group(item)) {
|
|
34
|
+
const result = discover(item, full_path);
|
|
35
|
+
if (result)
|
|
36
|
+
return result;
|
|
37
|
+
}
|
|
38
|
+
}
|
|
39
|
+
return null;
|
|
40
|
+
};
|
|
41
|
+
return discover(h5_file);
|
|
42
|
+
};
|
|
43
|
+
const positions_data = find_dataset([`positions`, `coords`, `coordinates`])?.to_array();
|
|
44
|
+
const atomic_numbers_data = find_dataset([
|
|
45
|
+
`atomic_numbers`,
|
|
46
|
+
`numbers`,
|
|
47
|
+
`Z`,
|
|
48
|
+
`species`,
|
|
49
|
+
])?.to_array();
|
|
50
|
+
const cells_data = find_dataset([`cell`, `cells`, `lattice`])?.to_array();
|
|
51
|
+
const energies_data = find_dataset([`potential_energy`, `energy`])?.to_array();
|
|
52
|
+
if (!positions_data || !atomic_numbers_data) {
|
|
53
|
+
const missing_datasets = [];
|
|
54
|
+
if (!positions_data) {
|
|
55
|
+
missing_datasets.push(`positions (tried: positions, coords, coordinates)`);
|
|
56
|
+
}
|
|
57
|
+
if (!atomic_numbers_data) {
|
|
58
|
+
missing_datasets.push(`atomic numbers (tried: atomic_numbers, numbers, Z, species)`);
|
|
59
|
+
}
|
|
60
|
+
const missing_str = missing_datasets.join(`, `);
|
|
61
|
+
const available_str = Array.from(h5_file.keys()).join(`, `);
|
|
62
|
+
throw new Error(`Missing required dataset(s) in HDF5 file: ${missing_str}. Available datasets: ${available_str}`);
|
|
63
|
+
}
|
|
64
|
+
const positions_are_frames = positions_data.length > 0 &&
|
|
65
|
+
positions_data.every((entry) => Array.isArray(entry) && entry.every((coord) => Array.isArray(coord)));
|
|
66
|
+
const positions = positions_are_frames
|
|
67
|
+
? positions_data
|
|
68
|
+
: [positions_data];
|
|
69
|
+
const atomic_numbers_are_frames = atomic_numbers_data.length > 0 &&
|
|
70
|
+
atomic_numbers_data.every((entry) => Array.isArray(entry));
|
|
71
|
+
const atomic_numbers = atomic_numbers_are_frames
|
|
72
|
+
? atomic_numbers_data
|
|
73
|
+
: [atomic_numbers_data];
|
|
74
|
+
const frames = positions.map((frame_pos, idx) => {
|
|
75
|
+
const frame_atomic_numbers = atomic_numbers[idx] || atomic_numbers[0];
|
|
76
|
+
const frame_elements = convert_atomic_numbers(frame_atomic_numbers);
|
|
77
|
+
const cell = cells_data?.[idx];
|
|
78
|
+
const lattice_mat = cell ? transpose_3x3_matrix(validate_3x3_matrix(cell)) : undefined;
|
|
79
|
+
const energy_entry = energies_data?.[idx];
|
|
80
|
+
const energy = Array.isArray(energy_entry) ? energy_entry[0] : energy_entry;
|
|
81
|
+
const metadata = {};
|
|
82
|
+
if (energy !== undefined)
|
|
83
|
+
metadata.energy = energy;
|
|
84
|
+
if (lattice_mat) {
|
|
85
|
+
metadata.volume = calc_lattice_params(lattice_mat).volume;
|
|
86
|
+
}
|
|
87
|
+
const pbc = lattice_mat ? [true, true, true] : [false, false, false];
|
|
88
|
+
return create_trajectory_frame(frame_pos, frame_elements, lattice_mat, pbc, idx, metadata);
|
|
89
|
+
});
|
|
90
|
+
const first_frame_elements = frames[0]?.structure.sites.map((site) => site.species[0].element) ?? [];
|
|
91
|
+
return {
|
|
92
|
+
frames,
|
|
93
|
+
metadata: {
|
|
94
|
+
source_format: `hdf5_trajectory`,
|
|
95
|
+
frame_count: frames.length,
|
|
96
|
+
num_atoms: first_frame_elements.length,
|
|
97
|
+
periodic_boundary_conditions: cells_data ? [true, true, true] : [false, false, false],
|
|
98
|
+
element_counts: first_frame_elements.reduce((counts, element) => {
|
|
99
|
+
counts[element] = (counts[element] || 0) + 1;
|
|
100
|
+
return counts;
|
|
101
|
+
}, {}),
|
|
102
|
+
discovered_datasets: {
|
|
103
|
+
positions: found_paths.positions ||
|
|
104
|
+
found_paths.coords ||
|
|
105
|
+
found_paths.coordinates ||
|
|
106
|
+
`unknown`,
|
|
107
|
+
atomic_numbers: found_paths.atomic_numbers ||
|
|
108
|
+
found_paths.numbers ||
|
|
109
|
+
found_paths.Z ||
|
|
110
|
+
found_paths.species ||
|
|
111
|
+
`unknown`,
|
|
112
|
+
cells: found_paths.cell || found_paths.cells || found_paths.lattice,
|
|
113
|
+
energies: found_paths.potential_energy || found_paths.energy,
|
|
114
|
+
},
|
|
115
|
+
total_groups_found,
|
|
116
|
+
has_cell_info: Boolean(cells_data),
|
|
117
|
+
},
|
|
118
|
+
};
|
|
119
|
+
}
|
|
120
|
+
finally {
|
|
121
|
+
h5_file?.close();
|
|
122
|
+
try {
|
|
123
|
+
FS.unlink(temp_filename);
|
|
124
|
+
}
|
|
125
|
+
catch {
|
|
126
|
+
/* temp file cleanup is best-effort */
|
|
127
|
+
}
|
|
128
|
+
}
|
|
129
|
+
}
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { is_trajectory_file } from '../format-detect';
|
|
2
|
+
import { TrajFrameReader } from '../frame-reader';
|
|
3
|
+
import type { FrameLoader, ParseProgress, TrajectoryType } from '../index';
|
|
4
|
+
import type { AtomTypeMapping, LoadingOptions } from '../types';
|
|
5
|
+
export { INDEX_SAMPLE_RATE, LARGE_FILE_THRESHOLD, MAX_BIN_FILE_SIZE, MAX_METADATA_SIZE, MAX_SAFE_STRING_LENGTH, MAX_TEXT_FILE_SIZE, } from '../constants';
|
|
6
|
+
export type { AtomTypeMapping, LoadingOptions } from '../types';
|
|
7
|
+
export { is_trajectory_file, TrajFrameReader };
|
|
8
|
+
export declare function parse_trajectory_data(data: unknown, filename?: string, atom_type_mapping?: AtomTypeMapping): Promise<TrajectoryType>;
|
|
9
|
+
export declare function get_unsupported_format_message(filename: string, content: string): string | null;
|
|
10
|
+
export declare function parse_trajectory_async(data: ArrayBuffer | string, filename: string, on_progress?: (progress: ParseProgress) => void, options?: LoadingOptions): Promise<TrajectoryType>;
|
|
11
|
+
export declare function create_frame_loader(filename: string): FrameLoader;
|
|
12
|
+
export declare function load_binary_traj(resp: Response, type: string, fallback?: boolean): Promise<ArrayBuffer | string>;
|
|
@@ -0,0 +1,299 @@
|
|
|
1
|
+
import { is_binary } from '../../io/is-binary';
|
|
2
|
+
import * as math from '../../math';
|
|
3
|
+
import { parse_xyz } from '../../structure/parse';
|
|
4
|
+
import { INDEX_SAMPLE_RATE, LARGE_FILE_THRESHOLD } from '../constants';
|
|
5
|
+
import { FORMAT_PATTERNS, is_trajectory_file, strip_compression_extensions, } from '../format-detect';
|
|
6
|
+
import { TrajFrameReader } from '../frame-reader';
|
|
7
|
+
import { create_trajectory_frame, validate_3x3_matrix } from '../helpers';
|
|
8
|
+
import { parse_ase_trajectory } from './ase';
|
|
9
|
+
import { parse_torch_sim_hdf5 } from './hdf5';
|
|
10
|
+
import { parse_lammps_trajectory } from './lammps';
|
|
11
|
+
import { parse_vasp_xdatcar } from './vasp';
|
|
12
|
+
import { parse_xyz_trajectory } from './xyz';
|
|
13
|
+
// Silently swallow expected parse fallbacks — the caller throws if ALL formats fail
|
|
14
|
+
const log_parse_debug = (_message, _error) => { };
|
|
15
|
+
// Re-export constants and types for consumers
|
|
16
|
+
export { INDEX_SAMPLE_RATE, LARGE_FILE_THRESHOLD, MAX_BIN_FILE_SIZE, MAX_METADATA_SIZE, MAX_SAFE_STRING_LENGTH, MAX_TEXT_FILE_SIZE, } from '../constants';
|
|
17
|
+
export { is_trajectory_file, TrajFrameReader };
|
|
18
|
+
export async function parse_trajectory_data(data, filename, atom_type_mapping) {
|
|
19
|
+
if (data instanceof ArrayBuffer) {
|
|
20
|
+
if (FORMAT_PATTERNS.ase(data, filename))
|
|
21
|
+
return parse_ase_trajectory(data, filename);
|
|
22
|
+
if (FORMAT_PATTERNS.hdf5(data, filename)) {
|
|
23
|
+
return await parse_torch_sim_hdf5(data, filename);
|
|
24
|
+
}
|
|
25
|
+
throw new Error(`Unsupported binary format${filename ? `: ${filename}` : ``}`);
|
|
26
|
+
}
|
|
27
|
+
if (typeof data === `string`) {
|
|
28
|
+
const content = data.trim();
|
|
29
|
+
if (FORMAT_PATTERNS.xyz_multi(content, filename))
|
|
30
|
+
return parse_xyz_trajectory(content);
|
|
31
|
+
if (FORMAT_PATTERNS.vasp(content, filename)) {
|
|
32
|
+
return parse_vasp_xdatcar(content, filename);
|
|
33
|
+
}
|
|
34
|
+
if (FORMAT_PATTERNS.lammpstrj(content, filename)) {
|
|
35
|
+
return parse_lammps_trajectory(content, filename, atom_type_mapping);
|
|
36
|
+
}
|
|
37
|
+
// Single XYZ fallback
|
|
38
|
+
if (filename?.toLowerCase().match(/\.(?:xyz|extxyz)$/)) {
|
|
39
|
+
try {
|
|
40
|
+
const structure = parse_xyz(content);
|
|
41
|
+
if (structure) {
|
|
42
|
+
return {
|
|
43
|
+
frames: [{ structure, step: 0, metadata: {} }],
|
|
44
|
+
metadata: { source_format: `single_xyz`, frame_count: 1 },
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
catch (error) {
|
|
49
|
+
// Single-frame XYZ parsing failed, continue to JSON parsing.
|
|
50
|
+
log_parse_debug(`Single XYZ parse fallback failed for ${filename ?? `unknown file`}:`, error);
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
try {
|
|
54
|
+
data = JSON.parse(content);
|
|
55
|
+
}
|
|
56
|
+
catch (error) {
|
|
57
|
+
log_parse_debug(`JSON parse failed for ${filename ?? `unknown file`}:`, error);
|
|
58
|
+
throw new Error(`Unsupported text format`, { cause: error });
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
if (!data || typeof data !== `object`)
|
|
62
|
+
throw new Error(`Invalid data format`);
|
|
63
|
+
// Handle JSON formats
|
|
64
|
+
if (Array.isArray(data)) {
|
|
65
|
+
const frames = data.map((frame_data, idx) => {
|
|
66
|
+
const frame_obj = frame_data;
|
|
67
|
+
const frame_step = frame_obj.step;
|
|
68
|
+
return {
|
|
69
|
+
structure: (frame_obj.structure || frame_obj),
|
|
70
|
+
step: typeof frame_step === `number` ? frame_step : idx,
|
|
71
|
+
metadata: frame_obj.metadata || {},
|
|
72
|
+
};
|
|
73
|
+
});
|
|
74
|
+
return { frames, metadata: { source_format: `array`, frame_count: frames.length } };
|
|
75
|
+
}
|
|
76
|
+
const obj = data;
|
|
77
|
+
// Pymatgen format
|
|
78
|
+
if (obj[`@class`] === `Trajectory` && obj.species && obj.coords && obj.lattice) {
|
|
79
|
+
const species = obj.species;
|
|
80
|
+
const frame_elements = species.map((specie) => specie.element);
|
|
81
|
+
const coords = obj.coords;
|
|
82
|
+
const matrix = validate_3x3_matrix(obj.lattice);
|
|
83
|
+
const frame_properties = obj.frame_properties || [];
|
|
84
|
+
const frac_to_cart = math.create_frac_to_cart(matrix);
|
|
85
|
+
const frames = coords.map((frame_coords, idx) => {
|
|
86
|
+
const positions = frame_coords.map((abc) => frac_to_cart(abc));
|
|
87
|
+
// Process frame properties to extract numpy arrays
|
|
88
|
+
const raw_properties = frame_properties[idx] || {};
|
|
89
|
+
const processed_properties = {};
|
|
90
|
+
Object.entries(raw_properties).forEach(([key, value]) => {
|
|
91
|
+
if (value &&
|
|
92
|
+
typeof value === `object` &&
|
|
93
|
+
value[`@class`] === `array`) {
|
|
94
|
+
// Extract numpy array data
|
|
95
|
+
const array_obj = value;
|
|
96
|
+
processed_properties[key] = array_obj.data;
|
|
97
|
+
// Calculate force statistics for forces
|
|
98
|
+
if (key === `forces` && Array.isArray(array_obj.data)) {
|
|
99
|
+
const forces = array_obj.data;
|
|
100
|
+
const force_magnitudes = forces.map((force) => Math.hypot(...force));
|
|
101
|
+
if (force_magnitudes.length > 0) {
|
|
102
|
+
processed_properties.force_max = force_magnitudes.reduce((max_val, magnitude) => (magnitude > max_val ? magnitude : max_val), force_magnitudes[0]);
|
|
103
|
+
processed_properties.force_norm = Math.sqrt(force_magnitudes.reduce((sum, f) => sum + f ** 2, 0) / force_magnitudes.length);
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
// Calculate stress statistics for stress tensor
|
|
107
|
+
if (key === `stress` && Array.isArray(array_obj.data)) {
|
|
108
|
+
const stress_tensor = array_obj.data;
|
|
109
|
+
if (!math.is_square_matrix(stress_tensor, 3)) {
|
|
110
|
+
console.warn(`Invalid stress tensor structure in frame ${idx}`);
|
|
111
|
+
}
|
|
112
|
+
else {
|
|
113
|
+
// Calculate stress components (diagonal elements represent normal stresses)
|
|
114
|
+
const normal_stresses = [
|
|
115
|
+
stress_tensor[0][0],
|
|
116
|
+
stress_tensor[1][1],
|
|
117
|
+
stress_tensor[2][2],
|
|
118
|
+
];
|
|
119
|
+
processed_properties.stress_max = Math.max(...normal_stresses.map(Math.abs));
|
|
120
|
+
// Calculate hydrostatic pressure (negative of mean normal stress)
|
|
121
|
+
processed_properties.pressure =
|
|
122
|
+
-(normal_stresses[0] + normal_stresses[1] + normal_stresses[2]) / 3;
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
else {
|
|
127
|
+
processed_properties[key] = value;
|
|
128
|
+
}
|
|
129
|
+
});
|
|
130
|
+
return create_trajectory_frame(positions, frame_elements, matrix, [true, true, true], idx, processed_properties);
|
|
131
|
+
});
|
|
132
|
+
return {
|
|
133
|
+
frames,
|
|
134
|
+
metadata: {
|
|
135
|
+
filename,
|
|
136
|
+
source_format: `pymatgen_trajectory`,
|
|
137
|
+
frame_count: frames.length,
|
|
138
|
+
species_list: [...new Set(species.map((specie) => specie.element))],
|
|
139
|
+
periodic_boundary_conditions: [true, true, true],
|
|
140
|
+
},
|
|
141
|
+
};
|
|
142
|
+
}
|
|
143
|
+
// Object with frames
|
|
144
|
+
if (Array.isArray(obj.frames)) {
|
|
145
|
+
const metadata = (obj.metadata ?? {});
|
|
146
|
+
return {
|
|
147
|
+
frames: obj.frames,
|
|
148
|
+
metadata: { ...metadata, source_format: `object_with_frames` },
|
|
149
|
+
};
|
|
150
|
+
}
|
|
151
|
+
// Single structure
|
|
152
|
+
if (obj.sites) {
|
|
153
|
+
return {
|
|
154
|
+
frames: [{ structure: obj, step: 0, metadata: {} }],
|
|
155
|
+
metadata: { source_format: `single_structure`, frame_count: 1 },
|
|
156
|
+
};
|
|
157
|
+
}
|
|
158
|
+
throw new Error(`Unrecognized trajectory format`);
|
|
159
|
+
}
|
|
160
|
+
export function get_unsupported_format_message(filename, content) {
|
|
161
|
+
const lower = filename.toLowerCase();
|
|
162
|
+
// Check for unsupported compression formats first
|
|
163
|
+
const unsupported_compression = [
|
|
164
|
+
{ ext: `.bz2`, name: `BZ2` },
|
|
165
|
+
{ ext: `.xz`, name: `XZ` },
|
|
166
|
+
{ ext: `.zip`, name: `ZIP` },
|
|
167
|
+
];
|
|
168
|
+
for (const { ext, name } of unsupported_compression) {
|
|
169
|
+
if (lower.endsWith(ext)) {
|
|
170
|
+
return `🚫 ${name} compression not supported in browser\nPlease decompress the file first`;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
// .dump files are LAMMPS binary dumps which require external tools to parse.
|
|
174
|
+
// .lammpstrj files are LAMMPS text-based trajectory files supported by parse_lammps_trajectory().
|
|
175
|
+
const formats = [
|
|
176
|
+
{ extensions: [`.dump`], name: `LAMMPS binary dump`, tool: `pymatgen` },
|
|
177
|
+
{ extensions: [`.nc`, `.netcdf`], name: `NetCDF`, tool: `MDAnalysis` },
|
|
178
|
+
{ extensions: [`.dcd`], name: `DCD`, tool: `MDAnalysis` },
|
|
179
|
+
];
|
|
180
|
+
for (const { extensions, name, tool } of formats) {
|
|
181
|
+
if (extensions.some((ext) => lower.endsWith(ext))) {
|
|
182
|
+
return `🚫 ${name} format not supported\nConvert with ${tool} first`;
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
return is_binary(content)
|
|
186
|
+
? `🚫 Binary format not supported${filename ? `: ${filename}` : ``}`
|
|
187
|
+
: null;
|
|
188
|
+
}
|
|
189
|
+
// Unified async parser with streaming support
|
|
190
|
+
export async function parse_trajectory_async(data, filename, on_progress, options = {}) {
|
|
191
|
+
const { use_indexing, index_sample_rate = INDEX_SAMPLE_RATE, extract_plot_metadata = true, atom_type_mapping, } = options;
|
|
192
|
+
const update_progress = (current, stage) => on_progress?.({ current, total: 100, stage });
|
|
193
|
+
try {
|
|
194
|
+
update_progress(0, `Detecting format...`);
|
|
195
|
+
const data_size = data instanceof ArrayBuffer ? data.byteLength : new TextEncoder().encode(data).byteLength;
|
|
196
|
+
const is_large_file = data_size > LARGE_FILE_THRESHOLD;
|
|
197
|
+
const should_use_indexing = use_indexing ?? is_large_file;
|
|
198
|
+
if (is_large_file) {
|
|
199
|
+
update_progress(5, `Large file detected (${Math.round(data_size / 1024 / 1024)}MB)`);
|
|
200
|
+
}
|
|
201
|
+
// Use indexed loading for supported large files (including compressed names).
|
|
202
|
+
const base_filename = strip_compression_extensions(filename);
|
|
203
|
+
if (should_use_indexing && /\.(xyz|extxyz|traj)$/.test(base_filename)) {
|
|
204
|
+
return await parse_with_unified_loader(data, filename, {
|
|
205
|
+
index_sample_rate,
|
|
206
|
+
extract_plot_metadata,
|
|
207
|
+
}, on_progress);
|
|
208
|
+
}
|
|
209
|
+
// Fallback to direct parsing
|
|
210
|
+
update_progress(10, `Parsing trajectory...`);
|
|
211
|
+
const result = await parse_trajectory_data(data, filename, atom_type_mapping);
|
|
212
|
+
update_progress(100, `Complete`);
|
|
213
|
+
return result;
|
|
214
|
+
}
|
|
215
|
+
catch (error) {
|
|
216
|
+
const error_message = error instanceof Error ? error.message : `Unknown error`;
|
|
217
|
+
update_progress(100, `Error: ${error_message}`);
|
|
218
|
+
throw error;
|
|
219
|
+
}
|
|
220
|
+
}
|
|
221
|
+
// Unified frame loading using new TrajFrameReader
|
|
222
|
+
async function parse_with_unified_loader(data, filename, options, on_progress) {
|
|
223
|
+
const { index_sample_rate, extract_plot_metadata } = options;
|
|
224
|
+
const loader = new TrajFrameReader(filename);
|
|
225
|
+
on_progress?.({ current: 10, total: 100, stage: `Counting frames...` });
|
|
226
|
+
const total_frames = await loader.get_total_frames(data);
|
|
227
|
+
on_progress?.({ current: 20, total: 100, stage: `Building frame index...` });
|
|
228
|
+
const frame_index = await loader.build_frame_index(data, index_sample_rate, (progress) => {
|
|
229
|
+
const adjusted = 20 + (progress.current / 100) * 30;
|
|
230
|
+
on_progress?.({
|
|
231
|
+
current: adjusted,
|
|
232
|
+
total: 100,
|
|
233
|
+
stage: `Building index: ${progress.stage}`,
|
|
234
|
+
});
|
|
235
|
+
});
|
|
236
|
+
on_progress?.({ current: 50, total: 100, stage: `Loading initial frames...` });
|
|
237
|
+
const initial_frame_count = Math.min(10, total_frames);
|
|
238
|
+
const frame_promises = Array.from({ length: initial_frame_count }, (_, idx) => loader.load_frame(data, idx));
|
|
239
|
+
const loaded_frames = await Promise.all(frame_promises);
|
|
240
|
+
const frames = loaded_frames.filter((frame) => frame !== null);
|
|
241
|
+
let plot_metadata;
|
|
242
|
+
if (extract_plot_metadata) {
|
|
243
|
+
on_progress?.({ current: 70, total: 100, stage: `Extracting plot metadata...` });
|
|
244
|
+
try {
|
|
245
|
+
plot_metadata = await loader.extract_plot_metadata(data, { sample_rate: 1 }, (progress) => {
|
|
246
|
+
const adjusted = 70 + (progress.current / 100) * 20;
|
|
247
|
+
on_progress?.({
|
|
248
|
+
current: adjusted,
|
|
249
|
+
total: 100,
|
|
250
|
+
stage: `Extracting: ${progress.stage}`,
|
|
251
|
+
});
|
|
252
|
+
});
|
|
253
|
+
}
|
|
254
|
+
catch (error) {
|
|
255
|
+
console.warn(`Failed to extract plot metadata:`, error);
|
|
256
|
+
}
|
|
257
|
+
}
|
|
258
|
+
const stage = `Ready: ${total_frames} frames indexed`;
|
|
259
|
+
on_progress?.({ current: 100, total: 100, stage });
|
|
260
|
+
const source_format = filename.toLowerCase().endsWith(`.traj`)
|
|
261
|
+
? `ase_trajectory`
|
|
262
|
+
: `xyz_trajectory`;
|
|
263
|
+
return {
|
|
264
|
+
frames,
|
|
265
|
+
metadata: { source_format, frame_count: total_frames },
|
|
266
|
+
total_frames,
|
|
267
|
+
indexed_frames: frame_index,
|
|
268
|
+
plot_metadata,
|
|
269
|
+
is_indexed: true,
|
|
270
|
+
frame_loader: loader,
|
|
271
|
+
};
|
|
272
|
+
}
|
|
273
|
+
// Factory function for frame loader (simplified)
|
|
274
|
+
export function create_frame_loader(filename) {
|
|
275
|
+
if (!/\.(xyz|extxyz|traj)$/.exec(filename.toLowerCase())) {
|
|
276
|
+
throw new Error(`Unsupported format for frame loading: ${filename}`);
|
|
277
|
+
}
|
|
278
|
+
return new TrajFrameReader(filename);
|
|
279
|
+
}
|
|
280
|
+
export async function load_binary_traj(resp, type, fallback = false) {
|
|
281
|
+
try {
|
|
282
|
+
// Read binary from a clone so the original can be used for text fallback
|
|
283
|
+
return await resp.clone().arrayBuffer();
|
|
284
|
+
}
|
|
285
|
+
catch (binary_error) {
|
|
286
|
+
if (fallback) {
|
|
287
|
+
console.warn(`Binary load failed for ${type}, using text fallback:`, binary_error);
|
|
288
|
+
try {
|
|
289
|
+
return await resp.text();
|
|
290
|
+
}
|
|
291
|
+
catch (text_error) {
|
|
292
|
+
const combined_error = new AggregateError([binary_error, text_error], `Failed to load ${type} as binary or text`);
|
|
293
|
+
console.error(`Binary and text fallback both failed for ${type}:`, combined_error);
|
|
294
|
+
throw combined_error;
|
|
295
|
+
}
|
|
296
|
+
}
|
|
297
|
+
throw new Error(`Failed to load ${type} as binary`, { cause: binary_error });
|
|
298
|
+
}
|
|
299
|
+
}
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import * as math from '../../math';
|
|
2
|
+
import type { TrajectoryType } from '../index';
|
|
3
|
+
import type { AtomTypeMapping } from '../types';
|
|
4
|
+
export declare function parse_lammps_box(box_lines: string[], is_triclinic: boolean): math.Matrix3x3 | null;
|
|
5
|
+
export declare function parse_lammps_trajectory(content: string, filename?: string, atom_type_mapping?: AtomTypeMapping): TrajectoryType;
|