matterviz 0.4.0 → 0.4.1
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/brillouin/BrillouinZone.svelte +68 -145
- package/dist/brillouin/BrillouinZone.svelte.d.ts +5 -14
- package/dist/brillouin/BrillouinZoneExportPane.svelte +43 -96
- package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
- package/dist/brillouin/BrillouinZoneInfoPane.svelte +9 -32
- package/dist/brillouin/BrillouinZoneInfoPane.svelte.d.ts +2 -3
- package/dist/brillouin/BrillouinZoneScene.svelte +49 -203
- package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +3 -23
- package/dist/brillouin/ReciprocalVectors.svelte +39 -0
- package/dist/brillouin/ReciprocalVectors.svelte.d.ts +9 -0
- package/dist/brillouin/compute.d.ts +2 -0
- package/dist/brillouin/compute.js +80 -77
- package/dist/brillouin/geometry.d.ts +8 -0
- package/dist/brillouin/geometry.js +57 -0
- package/dist/brillouin/index.d.ts +2 -0
- package/dist/brillouin/index.js +2 -0
- package/dist/brillouin/types.d.ts +2 -2
- package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +1 -1
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte +100 -191
- package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +4 -1
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte +176 -464
- package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +7 -1
- package/dist/chempot-diagram/color.d.ts +3 -6
- package/dist/chempot-diagram/color.js +5 -5
- package/dist/chempot-diagram/compute.d.ts +3 -3
- package/dist/chempot-diagram/compute.js +3 -1
- package/dist/chempot-diagram/controls-state.svelte.d.ts +10 -0
- package/dist/chempot-diagram/controls-state.svelte.js +42 -0
- package/dist/chempot-diagram/export.d.ts +47 -0
- package/dist/chempot-diagram/export.js +133 -0
- package/dist/chempot-diagram/index.d.ts +1 -0
- package/dist/chempot-diagram/index.js +1 -0
- package/dist/chempot-diagram/pointer.d.ts +0 -10
- package/dist/chempot-diagram/pointer.js +4 -4
- package/dist/chempot-diagram/types.d.ts +3 -3
- package/dist/colors/index.js +2 -2
- package/dist/composition/FormulaFilter.svelte +6 -5
- package/dist/composition/PieChart.svelte +5 -5
- package/dist/composition/chem-sys.js +3 -2
- package/dist/composition/format.js +3 -2
- package/dist/composition/parse.d.ts +0 -1
- package/dist/composition/parse.js +17 -19
- package/dist/controls.d.ts +1 -0
- package/dist/controls.js +0 -1
- package/dist/convex-hull/ConvexHull.svelte +8 -10
- package/dist/convex-hull/ConvexHull.svelte.d.ts +1 -4
- package/dist/convex-hull/ConvexHull2D.svelte +94 -175
- package/dist/convex-hull/ConvexHull2D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHull3D.svelte +176 -680
- package/dist/convex-hull/ConvexHull3D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHull4D.svelte +180 -680
- package/dist/convex-hull/ConvexHull4D.svelte.d.ts +1 -1
- package/dist/convex-hull/ConvexHullChrome.svelte +268 -0
- package/dist/convex-hull/ConvexHullChrome.svelte.d.ts +30 -0
- package/dist/convex-hull/ConvexHullControls.svelte +88 -7
- package/dist/convex-hull/ConvexHullControls.svelte.d.ts +7 -6
- package/dist/convex-hull/ConvexHullInfoPane.svelte +18 -5
- package/dist/convex-hull/ConvexHullInfoPane.svelte.d.ts +6 -5
- package/dist/convex-hull/ConvexHullStats.svelte +29 -168
- package/dist/convex-hull/ConvexHullStats.svelte.d.ts +3 -1
- package/dist/convex-hull/ConvexHullTooltip.svelte +11 -2
- package/dist/convex-hull/ConvexHullTooltip.svelte.d.ts +2 -1
- package/dist/convex-hull/barycentric-coords.d.ts +2 -4
- package/dist/convex-hull/barycentric-coords.js +6 -33
- package/dist/convex-hull/canvas-interactions.svelte.d.ts +79 -0
- package/dist/convex-hull/canvas-interactions.svelte.js +278 -0
- package/dist/convex-hull/helpers.d.ts +39 -7
- package/dist/convex-hull/helpers.js +154 -69
- package/dist/convex-hull/hull-state.svelte.d.ts +44 -0
- package/dist/convex-hull/hull-state.svelte.js +124 -0
- package/dist/convex-hull/index.d.ts +9 -7
- package/dist/convex-hull/index.js +7 -2
- package/dist/convex-hull/thermodynamics.js +91 -920
- package/dist/convex-hull/types.d.ts +12 -4
- package/dist/convex-hull/types.js +12 -0
- package/dist/coordination/CoordinationBarPlot.svelte +4 -11
- package/dist/element/BohrAtom.svelte +2 -1
- package/dist/element/ElementTile.svelte.d.ts +1 -1
- package/dist/element/index.d.ts +4 -0
- package/dist/element/index.js +18 -0
- package/dist/feedback/DragOverlay.svelte +3 -1
- package/dist/feedback/DragOverlay.svelte.d.ts +1 -0
- package/dist/feedback/StatusMessage.svelte +13 -3
- package/dist/fermi-surface/FermiSurface.svelte +67 -146
- package/dist/fermi-surface/FermiSurface.svelte.d.ts +5 -14
- package/dist/fermi-surface/FermiSurfaceControls.svelte.d.ts +1 -1
- package/dist/fermi-surface/FermiSurfaceScene.svelte +72 -224
- package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +3 -23
- package/dist/fermi-surface/compute.js +11 -10
- package/dist/fermi-surface/export.js +4 -15
- package/dist/fermi-surface/index.d.ts +0 -1
- package/dist/fermi-surface/index.js +0 -1
- package/dist/fermi-surface/parse.d.ts +1 -1
- package/dist/fermi-surface/parse.js +64 -75
- package/dist/fermi-surface/types.d.ts +2 -2
- package/dist/heatmap-matrix/HeatmapMatrix.svelte +55 -40
- package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +4 -3
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +3 -2
- package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +5 -5
- package/dist/heatmap-matrix/index.d.ts +3 -2
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/io/ExportPane.svelte +166 -0
- package/dist/io/ExportPane.svelte.d.ts +17 -0
- package/dist/io/decompress.js +1 -2
- package/dist/io/export.d.ts +5 -1
- package/dist/io/export.js +32 -28
- package/dist/io/fetch.d.ts +2 -1
- package/dist/io/file-drop.d.ts +7 -0
- package/dist/io/file-drop.js +13 -0
- package/dist/io/index.d.ts +2 -0
- package/dist/io/index.js +10 -0
- package/dist/io/types.d.ts +13 -0
- package/dist/isosurface/parse.js +46 -44
- package/dist/labels.js +1 -1
- package/dist/layout/FullscreenButton.svelte +33 -0
- package/dist/layout/FullscreenButton.svelte.d.ts +10 -0
- package/dist/layout/FullscreenToggle.svelte +8 -14
- package/dist/layout/ViewerChrome.svelte +116 -0
- package/dist/layout/ViewerChrome.svelte.d.ts +17 -0
- package/dist/layout/fullscreen.d.ts +4 -0
- package/dist/layout/fullscreen.svelte.d.ts +8 -0
- package/dist/layout/fullscreen.svelte.js +37 -0
- package/dist/layout/index.d.ts +3 -0
- package/dist/layout/index.js +3 -0
- package/dist/math.d.ts +7 -3
- package/dist/math.js +18 -21
- package/dist/overlays/index.d.ts +4 -0
- package/dist/periodic-table/PeriodicTable.svelte +9 -8
- package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +1 -1
- package/dist/phase-diagram/PhaseDiagramControls.svelte +3 -2
- package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +4 -3
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +2 -1
- package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +2 -3
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte +47 -132
- package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +3 -4
- package/dist/phase-diagram/colors.js +1 -1
- package/dist/phase-diagram/parse.d.ts +2 -1
- package/dist/plot/bar/BarPlot.svelte +79 -316
- package/dist/plot/bar/BarPlot.svelte.d.ts +7 -15
- package/dist/plot/bar/BarPlotControls.svelte.d.ts +1 -1
- package/dist/plot/bar/SpacegroupBarPlot.svelte +2 -1
- package/dist/plot/box/BoxPlot.svelte +76 -246
- package/dist/plot/box/BoxPlot.svelte.d.ts +4 -3
- package/dist/plot/box/BoxPlotControls.svelte.d.ts +1 -1
- package/dist/plot/box/Violin.svelte.d.ts +1 -1
- package/dist/plot/box/box-plot.d.ts +3 -2
- package/dist/plot/box/box-plot.js +5 -2
- package/dist/plot/box/kde.d.ts +2 -1
- package/dist/plot/box/kde.js +4 -4
- package/dist/plot/core/auto-place.d.ts +1 -1
- package/dist/plot/core/auto-place.js +4 -1
- package/dist/plot/core/components/ColorBar.svelte +5 -5
- package/dist/plot/core/components/ColorBar.svelte.d.ts +5 -4
- package/dist/plot/core/components/Line.svelte +3 -2
- package/dist/plot/core/components/Line.svelte.d.ts +3 -2
- package/dist/plot/core/components/PlotAxis.svelte +2 -1
- package/dist/plot/core/components/PlotAxis.svelte.d.ts +2 -1
- package/dist/plot/core/components/PlotControls.svelte.d.ts +1 -1
- package/dist/plot/core/components/ReferenceLine3D.svelte +2 -2
- package/dist/plot/core/components/ReferenceLine3D.svelte.d.ts +4 -4
- package/dist/plot/core/components/ReferencePlane.svelte +2 -2
- package/dist/plot/core/components/ReferencePlane.svelte.d.ts +4 -4
- package/dist/plot/core/data-cleaning.js +18 -18
- package/dist/plot/core/fill-utils.d.ts +4 -3
- package/dist/plot/core/fill-utils.js +6 -3
- package/dist/plot/core/interactions.d.ts +5 -1
- package/dist/plot/core/interactions.js +14 -0
- package/dist/plot/core/pan-zoom.svelte.d.ts +35 -0
- package/dist/plot/core/pan-zoom.svelte.js +221 -0
- package/dist/plot/core/placed-tween.svelte.d.ts +21 -0
- package/dist/plot/core/placed-tween.svelte.js +68 -0
- package/dist/plot/core/reference-line.d.ts +10 -10
- package/dist/plot/core/reference-line.js +6 -6
- package/dist/plot/core/scales.d.ts +17 -25
- package/dist/plot/core/scales.js +10 -8
- package/dist/plot/core/svg.d.ts +2 -1
- package/dist/plot/core/types.d.ts +18 -7
- package/dist/plot/core/utils/label-placement.d.ts +1 -1
- package/dist/plot/core/utils/label-placement.js +3 -3
- package/dist/plot/core/utils.d.ts +2 -1
- package/dist/plot/histogram/Histogram.svelte +77 -314
- package/dist/plot/histogram/HistogramControls.svelte.d.ts +1 -1
- package/dist/plot/sankey/Sankey.svelte +2 -5
- package/dist/plot/sankey/Sankey.svelte.d.ts +1 -1
- package/dist/plot/sankey/sankey.js +3 -1
- package/dist/plot/scatter/BinnedScatterPlot.svelte +3 -5
- package/dist/plot/scatter/BinnedScatterPlot.svelte.d.ts +4 -4
- package/dist/plot/scatter/ScatterPlot.svelte +160 -450
- package/dist/plot/scatter/ScatterPlot.svelte.d.ts +7 -15
- package/dist/plot/scatter/ScatterPlotControls.svelte.d.ts +1 -1
- package/dist/plot/scatter/binned-scatter-types.d.ts +4 -11
- package/dist/plot/scatter/index.d.ts +1 -1
- package/dist/plot/scatter-3d/ScatterPlot3D.svelte +15 -26
- package/dist/plot/scatter-3d/ScatterPlot3D.svelte.d.ts +6 -14
- package/dist/plot/scatter-3d/ScatterPlot3DControls.svelte +9 -10
- package/dist/plot/scatter-3d/ScatterPlot3DControls.svelte.d.ts +5 -5
- package/dist/plot/scatter-3d/ScatterPlot3DScene.svelte +122 -121
- package/dist/plot/scatter-3d/ScatterPlot3DScene.svelte.d.ts +5 -14
- package/dist/plot/scatter-3d/Surface3D.svelte +6 -5
- package/dist/plot/scatter-3d/Surface3D.svelte.d.ts +4 -3
- package/dist/plot/sunburst/Sunburst.svelte +16 -20
- package/dist/plot/sunburst/Sunburst.svelte.d.ts +4 -3
- package/dist/plot/sunburst/SunburstControls.svelte.d.ts +1 -1
- package/dist/plot/sunburst/sunburst.js +4 -1
- package/dist/rdf/RdfPlot.svelte.d.ts +1 -1
- package/dist/sanitize.js +13 -2
- package/dist/scene/SceneCamera.svelte +62 -0
- package/dist/scene/SceneCamera.svelte.d.ts +19 -0
- package/dist/scene/bind-renderer.svelte.d.ts +2 -0
- package/dist/scene/bind-renderer.svelte.js +14 -0
- package/dist/scene/index.d.ts +4 -0
- package/dist/scene/index.js +5 -0
- package/dist/scene/props.js +52 -0
- package/dist/scene/types.d.ts +26 -0
- package/dist/scene/types.js +1 -0
- package/dist/settings.d.ts +14 -2
- package/dist/settings.js +59 -1
- package/dist/spectral/Bands.svelte +8 -7
- package/dist/spectral/Bands.svelte.d.ts +3 -2
- package/dist/spectral/BandsAndDos.svelte +22 -24
- package/dist/spectral/BrillouinBandsDos.svelte +3 -3
- package/dist/spectral/Dos.svelte +5 -4
- package/dist/spectral/Dos.svelte.d.ts +2 -1
- package/dist/spectral/helpers.d.ts +6 -6
- package/dist/spectral/helpers.js +43 -37
- package/dist/state.svelte.d.ts +0 -7
- package/dist/state.svelte.js +0 -6
- package/dist/structure/Arrow.svelte +2 -4
- package/dist/structure/AtomLegend.svelte.d.ts +1 -1
- package/dist/structure/CanvasTooltip.svelte +1 -0
- package/dist/structure/CellSelect.svelte +11 -3
- package/dist/structure/CellSelect.svelte.d.ts +2 -1
- package/dist/structure/Lattice.svelte +2 -2
- package/dist/structure/Structure.svelte +291 -355
- package/dist/structure/Structure.svelte.d.ts +5 -15
- package/dist/structure/StructureControls.svelte +217 -2
- package/dist/structure/StructureControls.svelte.d.ts +5 -3
- package/dist/structure/StructureExportPane.svelte +54 -156
- package/dist/structure/StructureExportPane.svelte.d.ts +4 -5
- package/dist/structure/StructureInfoPane.svelte +5 -3
- package/dist/structure/StructureInfoPane.svelte.d.ts +5 -5
- package/dist/structure/StructureScene.svelte +365 -198
- package/dist/structure/StructureScene.svelte.d.ts +22 -20
- package/dist/structure/{label-placement.d.ts → atom-label-placement.d.ts} +3 -3
- package/dist/structure/{label-placement.js → atom-label-placement.js} +12 -2
- package/dist/structure/atom-properties.d.ts +1 -1
- package/dist/structure/atom-properties.js +11 -16
- package/dist/structure/bond-order-perception.js +2 -4
- package/dist/structure/bonding.d.ts +3 -0
- package/dist/structure/bonding.js +91 -48
- package/dist/structure/export.d.ts +24 -4
- package/dist/structure/export.js +64 -122
- package/dist/structure/index.d.ts +2 -0
- package/dist/structure/index.js +2 -0
- package/dist/structure/parse.d.ts +3 -2
- package/dist/structure/parse.js +333 -370
- package/dist/structure/partial-occupancy.d.ts +0 -1
- package/dist/structure/partial-occupancy.js +1 -1
- package/dist/structure/pbc.d.ts +1 -1
- package/dist/structure/pbc.js +186 -13
- package/dist/structure/polyhedra.d.ts +41 -0
- package/dist/structure/polyhedra.js +602 -0
- package/dist/structure/site.d.ts +4 -0
- package/dist/structure/site.js +1 -0
- package/dist/structure/supercell.js +3 -2
- package/dist/structure/validation.js +5 -6
- package/dist/symmetry/SymmetryElementControls.svelte +69 -0
- package/dist/symmetry/SymmetryElementControls.svelte.d.ts +9 -0
- package/dist/symmetry/SymmetryElements.svelte +354 -0
- package/dist/symmetry/SymmetryElements.svelte.d.ts +24 -0
- package/dist/symmetry/SymmetryStats.svelte +111 -6
- package/dist/symmetry/WyckoffTable.svelte +68 -7
- package/dist/symmetry/WyckoffTable.svelte.d.ts +3 -0
- package/dist/symmetry/cell-transform.js +7 -14
- package/dist/symmetry/index.d.ts +14 -4
- package/dist/symmetry/index.js +301 -80
- package/dist/symmetry/spacegroups.d.ts +5 -1
- package/dist/symmetry/spacegroups.js +15 -1
- package/dist/symmetry/symmetry-elements.d.ts +33 -0
- package/dist/symmetry/symmetry-elements.js +521 -0
- package/dist/symmetry/wyckoff-db.d.ts +9 -0
- package/dist/symmetry/wyckoff-db.js +87 -0
- package/dist/table/HeatmapTable.svelte +4 -15
- package/dist/table/HeatmapTable.svelte.d.ts +1 -1
- package/dist/trajectory/Trajectory.svelte +58 -61
- package/dist/trajectory/Trajectory.svelte.d.ts +10 -22
- package/dist/trajectory/TrajectoryExportPane.svelte +15 -24
- package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +4 -5
- package/dist/trajectory/TrajectoryInfoPane.svelte +3 -2
- package/dist/trajectory/TrajectoryInfoPane.svelte.d.ts +3 -2
- package/dist/trajectory/constants.js +6 -2
- package/dist/trajectory/extract.js +17 -37
- package/dist/trajectory/format-detect.d.ts +0 -1
- package/dist/trajectory/format-detect.js +3 -9
- package/dist/trajectory/frame-reader.d.ts +0 -1
- package/dist/trajectory/frame-reader.js +62 -128
- package/dist/trajectory/helpers.d.ts +10 -2
- package/dist/trajectory/helpers.js +56 -36
- package/dist/trajectory/parse/ase.d.ts +9 -1
- package/dist/trajectory/parse/ase.js +47 -32
- package/dist/trajectory/parse/diagnostics.d.ts +3 -0
- package/dist/trajectory/parse/diagnostics.js +14 -0
- package/dist/trajectory/parse/index.d.ts +1 -1
- package/dist/trajectory/parse/index.js +54 -102
- package/dist/trajectory/parse/lammps.d.ts +0 -2
- package/dist/trajectory/parse/lammps.js +8 -6
- package/dist/trajectory/parse/pymatgen.d.ts +2 -0
- package/dist/trajectory/parse/pymatgen.js +74 -0
- package/dist/trajectory/parse/vasp.js +4 -3
- package/dist/trajectory/parse/xyz.d.ts +9 -21
- package/dist/trajectory/parse/xyz.js +28 -33
- package/dist/trajectory/plotting.d.ts +0 -1
- package/dist/trajectory/plotting.js +3 -100
- package/dist/utils.d.ts +1 -0
- package/dist/utils.js +1 -1
- package/dist/xrd/XrdPlot.svelte +14 -29
- package/dist/xrd/broadening.d.ts +2 -1
- package/dist/xrd/calc-xrd.js +6 -11
- package/dist/xrd/index.d.ts +2 -2
- package/package.json +29 -16
- package/dist/element/data.json +0 -11864
- package/dist/fermi-surface/marching-cubes.d.ts +0 -2
- package/dist/fermi-surface/marching-cubes.js +0 -2
- package/dist/plot/core/hover-lock.svelte.d.ts +0 -14
- package/dist/plot/core/hover-lock.svelte.js +0 -45
|
@@ -3,10 +3,6 @@ import * as math from '../math';
|
|
|
3
3
|
import { Vector3 } from 'three';
|
|
4
4
|
import { ConvexGeometry } from 'three/examples/jsm/geometries/ConvexGeometry.js';
|
|
5
5
|
const TOL = 1e-8;
|
|
6
|
-
const normalize = (vec) => {
|
|
7
|
-
const mag = Math.hypot(...vec);
|
|
8
|
-
return mag < 1e-10 ? [0, 0, 0] : [vec[0] / mag, vec[1] / mag, vec[2] / mag];
|
|
9
|
-
};
|
|
10
6
|
// Check if rotation matrix is identity
|
|
11
7
|
const is_identity_rotation = (rot) => rot.every((row, idx) => row.every((val, jdx) => Math.abs(val - (idx === jdx ? 1 : 0)) < TOL));
|
|
12
8
|
// Extract unique point group rotation matrices from space group operations.
|
|
@@ -26,20 +22,6 @@ export function extract_point_group_from_operations(operations) {
|
|
|
26
22
|
}
|
|
27
23
|
return unique_rotations;
|
|
28
24
|
}
|
|
29
|
-
// Multiply two 3x3 matrices: C = A · B
|
|
30
|
-
function mat3x3_multiply(A, B) {
|
|
31
|
-
const result = [
|
|
32
|
-
[0, 0, 0],
|
|
33
|
-
[0, 0, 0],
|
|
34
|
-
[0, 0, 0],
|
|
35
|
-
];
|
|
36
|
-
for (let row = 0; row < 3; row++) {
|
|
37
|
-
for (let col = 0; col < 3; col++) {
|
|
38
|
-
result[row][col] = A[row][0] * B[0][col] + A[row][1] * B[1][col] + A[row][2] * B[2][col];
|
|
39
|
-
}
|
|
40
|
-
}
|
|
41
|
-
return result;
|
|
42
|
-
}
|
|
43
25
|
// Convert fractional rotation W to Cartesian k-space rotation. k_lattice stores reciprocal
|
|
44
26
|
// vectors as ROWS (k_cart = Bᵀ·q) and reciprocal fractional rotation is q' = W^{-T}·q, so
|
|
45
27
|
// R_cart = Bᵀ·W^{-T}·B^{-T}. For non-orthogonal lattices W^{-1} ≠ Wᵀ, so the transpose matters.
|
|
@@ -48,7 +30,7 @@ export function fractional_to_cartesian_rotation(W, k_lattice) {
|
|
|
48
30
|
const B_T = math.transpose_3x3_matrix(k_lattice);
|
|
49
31
|
const W_inv_T = math.transpose_3x3_matrix(math.matrix_inverse_3x3(W));
|
|
50
32
|
// R_cart = Bᵀ · W^{-T} · B^{-T}
|
|
51
|
-
return
|
|
33
|
+
return math.dot(math.dot(B_T, W_inv_T), math.matrix_inverse_3x3(B_T));
|
|
52
34
|
}
|
|
53
35
|
catch {
|
|
54
36
|
// Fallback to identity if inversion fails (shouldn't happen for valid rotations)
|
|
@@ -141,7 +123,11 @@ max_planes_by_order = { 1: 26, 2: 80, 3: 150 }) {
|
|
|
141
123
|
if (idx === center_idx)
|
|
142
124
|
return null;
|
|
143
125
|
const dist_sq = pt[0] ** 2 + pt[1] ** 2 + pt[2] ** 2;
|
|
144
|
-
return {
|
|
126
|
+
return {
|
|
127
|
+
normal: math.normalize_vec(pt, [0, 0, 0]),
|
|
128
|
+
dist: Math.sqrt(dist_sq) / 2,
|
|
129
|
+
dist_sq,
|
|
130
|
+
};
|
|
145
131
|
})
|
|
146
132
|
.filter((plane) => plane !== null)
|
|
147
133
|
.sort((a, b) => a.dist_sq - b.dist_sq)
|
|
@@ -231,7 +217,7 @@ export function compute_convex_hull(vertices, edge_sharp_angle_deg = 5) {
|
|
|
231
217
|
// Compute face normals and build edge-to-face adjacency
|
|
232
218
|
const face_normals = faces.map((face) => {
|
|
233
219
|
const [v0, v1, v2] = face.slice(0, 3).map((vertex_idx) => unique_verts[vertex_idx]);
|
|
234
|
-
return
|
|
220
|
+
return math.normalize_vec(math.cross_3d(math.subtract(v1, v0), math.subtract(v2, v0)), [0, 0, 0]);
|
|
235
221
|
});
|
|
236
222
|
const edge_to_faces = new Map();
|
|
237
223
|
faces.forEach((face, face_idx) => {
|
|
@@ -277,51 +263,72 @@ max_planes_by_order = { 1: 26, 2: 80, 3: 150 }) {
|
|
|
277
263
|
volume: compute_hull_volume(hull.vertices, hull.faces),
|
|
278
264
|
};
|
|
279
265
|
}
|
|
280
|
-
//
|
|
281
|
-
//
|
|
282
|
-
//
|
|
283
|
-
//
|
|
284
|
-
const
|
|
285
|
-
[1,
|
|
286
|
-
[
|
|
287
|
-
[
|
|
288
|
-
[1, 1, 0],
|
|
289
|
-
[1, 0, 1],
|
|
290
|
-
[0, 1, 1], // face diagonals (avoid 2-fold axes)
|
|
291
|
-
[1, 1, 1], // body diagonal (avoid 3-fold axis)
|
|
292
|
-
[1, 2, 3], // generic point on no special axis
|
|
266
|
+
// Generic reference directions for the Dirichlet-domain construction. Irrational-ish
|
|
267
|
+
// component ratios keep them off every rotation axis and mirror plane of crystallographic
|
|
268
|
+
// point groups in practice; the later directions are fallbacks in case a pathological
|
|
269
|
+
// Cartesian orientation pins the first onto a symmetry element.
|
|
270
|
+
export const IBZ_REFERENCE_DIRECTIONS = [
|
|
271
|
+
[1, Math.SQRT2 / 3, Math.E / 7],
|
|
272
|
+
[Math.PI / 5, 1, Math.SQRT1_2 / 4],
|
|
273
|
+
[Math.E / 9, Math.LN2, 1],
|
|
293
274
|
];
|
|
294
|
-
//
|
|
295
|
-
//
|
|
296
|
-
//
|
|
275
|
+
// A reference direction is valid for the Dirichlet construction iff it has a trivial
|
|
276
|
+
// stabilizer: no non-identity operation fixes it (R·t ≠ t for every R). Such a direction
|
|
277
|
+
// always exists because the fixed-point sets (rotation axes, mirror planes) have measure
|
|
278
|
+
// zero. Try the curated generic directions first, then deterministic pseudo-random ones,
|
|
279
|
+
// and throw in the (mathematically unreachable) case where none qualify — rather than
|
|
280
|
+
// silently using a non-generic direction, which would drop that operation's clipping
|
|
281
|
+
// plane and inflate the IBZ volume above V_BZ/|G|.
|
|
282
|
+
export function find_ibz_reference_direction(non_identity_ops) {
|
|
283
|
+
const has_trivial_stabilizer = (dir) => non_identity_ops.every((rot) => Math.hypot(...math.subtract(math.mat3x3_vec3_multiply(rot, dir), dir)) > TOL);
|
|
284
|
+
const curated = IBZ_REFERENCE_DIRECTIONS.find(has_trivial_stabilizer);
|
|
285
|
+
if (curated)
|
|
286
|
+
return curated;
|
|
287
|
+
// Park-Miller minstd PRNG (safe-integer arithmetic) keeps the rare fallback
|
|
288
|
+
// reproducible across runs while sampling generic directions
|
|
289
|
+
let seed = 16807;
|
|
290
|
+
const next_component = () => {
|
|
291
|
+
seed = (seed * 16807) % 2147483647;
|
|
292
|
+
return (seed / 2147483647) * 2 - 1;
|
|
293
|
+
};
|
|
294
|
+
for (let attempt = 0; attempt < 128; attempt++) {
|
|
295
|
+
const dir = [next_component(), next_component(), next_component()];
|
|
296
|
+
if (Math.hypot(...dir) > 0.1 && has_trivial_stabilizer(dir))
|
|
297
|
+
return dir;
|
|
298
|
+
}
|
|
299
|
+
throw new Error(`IBZ construction: no generic reference direction found for ${non_identity_ops.length} symmetry operations`);
|
|
300
|
+
}
|
|
301
|
+
// Compute clipping planes from point group operations via the Dirichlet (Voronoi)
|
|
302
|
+
// fundamental-domain construction: pick ONE generic direction t with trivial stabilizer,
|
|
303
|
+
// then for every non-identity operation R keep the half-space x·t ≥ x·(R·t), i.e.
|
|
304
|
+
// (R·t − t)·x ≤ 0. Intersecting all half-spaces with the BZ yields an irreducible wedge
|
|
305
|
+
// of exactly volume(BZ)/|G|. (Using a different reference point per operation — or
|
|
306
|
+
// flipping individual planes — does NOT yield a fundamental domain in general.)
|
|
297
307
|
export function compute_ibz_clipping_planes(point_group_ops) {
|
|
308
|
+
const non_identity_ops = point_group_ops.filter((rot) => !is_identity_rotation(rot));
|
|
309
|
+
if (non_identity_ops.length === 0)
|
|
310
|
+
return [];
|
|
311
|
+
const ref_dir = find_ibz_reference_direction(non_identity_ops);
|
|
298
312
|
const planes = [];
|
|
299
313
|
const seen_normals = new Set();
|
|
300
|
-
for (const rot of
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
}
|
|
315
|
-
break;
|
|
314
|
+
for (const rot of non_identity_ops) {
|
|
315
|
+
const rotated = math.mat3x3_vec3_multiply(rot, ref_dir);
|
|
316
|
+
const diff = math.subtract(rotated, ref_dir);
|
|
317
|
+
// ref_dir has a trivial stabilizer, so every op must move it; a zero diff would
|
|
318
|
+
// silently drop a plane and inflate the IBZ — surface it instead
|
|
319
|
+
if (Math.hypot(...diff) < TOL) {
|
|
320
|
+
throw new Error(`IBZ construction: reference direction unexpectedly fixed by an operation`);
|
|
321
|
+
}
|
|
322
|
+
const plane_normal = math.normalize_vec(diff, [0, 0, 0]);
|
|
323
|
+
// NOTE: do NOT merge antiparallel normals — n and −n select opposite half-spaces
|
|
324
|
+
const key = plane_normal.map((val) => Math.round(val * 1e6)).join(`,`);
|
|
325
|
+
if (!seen_normals.has(key)) {
|
|
326
|
+
seen_normals.add(key);
|
|
327
|
+
planes.push({ normal: plane_normal, dist: 0 });
|
|
316
328
|
}
|
|
317
329
|
}
|
|
318
330
|
return planes;
|
|
319
331
|
}
|
|
320
|
-
// Flip a clipping plane to the opposite half-space
|
|
321
|
-
const flip_plane = (plane) => ({
|
|
322
|
-
normal: math.scale(plane.normal, -1),
|
|
323
|
-
dist: -plane.dist,
|
|
324
|
-
});
|
|
325
332
|
// Clip polyhedron vertices by a half-space, adding intersection points where edges cross
|
|
326
333
|
function clip_polyhedron_by_plane(vertices, faces, plane) {
|
|
327
334
|
const { normal, dist } = plane;
|
|
@@ -350,14 +357,14 @@ function clip_polyhedron_by_plane(vertices, faces, plane) {
|
|
|
350
357
|
// Skip if denominator too small (tighter than TOL for numerical stability)
|
|
351
358
|
if (Math.abs(denom) < 1e-12)
|
|
352
359
|
continue;
|
|
353
|
-
const
|
|
360
|
+
const frac = d1 / denom;
|
|
354
361
|
// Only add intersection if it's not at an endpoint (which is already kept)
|
|
355
|
-
if (
|
|
362
|
+
if (frac > TOL && frac < 1 - TOL) {
|
|
356
363
|
const [v1, v2] = [vertices[i1], vertices[i2]];
|
|
357
364
|
result.push([
|
|
358
|
-
v1[0] +
|
|
359
|
-
v1[1] +
|
|
360
|
-
v1[2] +
|
|
365
|
+
v1[0] + frac * (v2[0] - v1[0]),
|
|
366
|
+
v1[1] + frac * (v2[1] - v1[1]),
|
|
367
|
+
v1[2] + frac * (v2[2] - v1[2]),
|
|
361
368
|
]);
|
|
362
369
|
}
|
|
363
370
|
}
|
|
@@ -393,21 +400,17 @@ export function compute_irreducible_bz(bz_data, point_group_ops, edge_sharp_angl
|
|
|
393
400
|
let current_vertices = [...bz_data.vertices];
|
|
394
401
|
let current_faces = [...bz_data.faces];
|
|
395
402
|
for (const plane of clipping_planes) {
|
|
396
|
-
//
|
|
397
|
-
|
|
398
|
-
|
|
399
|
-
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
clipped_successfully = true;
|
|
405
|
-
break;
|
|
406
|
-
}
|
|
403
|
+
// Planes from the Dirichlet construction are consistently oriented (the kept side
|
|
404
|
+
// n·x ≤ 0 always contains the reference direction) so clip directly — flipping a
|
|
405
|
+
// plane would select the wrong half-space and break the fundamental-domain property
|
|
406
|
+
const clipped = clip_polyhedron_by_plane(current_vertices, current_faces, plane);
|
|
407
|
+
const hull = try_build_hull(clipped, edge_sharp_angle_deg);
|
|
408
|
+
if (hull) {
|
|
409
|
+
current_vertices = hull.vertices;
|
|
410
|
+
current_faces = hull.faces;
|
|
407
411
|
}
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
console.warn(`IBZ clipping: plane orientation failed, continuing with current geometry`);
|
|
412
|
+
else {
|
|
413
|
+
console.warn(`IBZ clipping: degenerate clip result, skipping plane`);
|
|
411
414
|
}
|
|
412
415
|
}
|
|
413
416
|
const hull = try_build_hull(current_vertices, edge_sharp_angle_deg);
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
import type { Matrix3x3, Vec3 } from '../math';
|
|
2
|
+
import { BufferGeometry } from 'three';
|
|
3
|
+
export declare function polyhedron_geometry(vertices: Vec3[], faces: number[][]): BufferGeometry | null;
|
|
4
|
+
export declare function k_lattice_inverse(k_lattice: Matrix3x3 | undefined): Matrix3x3 | null;
|
|
5
|
+
export declare const cartesian_to_fractional: (k_lattice_inv: Matrix3x3 | null, cart: Vec3) => Vec3 | null;
|
|
6
|
+
export declare const polyhedron_centroid: (vertices: Vec3[] | undefined) => Vec3;
|
|
7
|
+
export declare const k_space_size: (k_lattice: Matrix3x3 | undefined) => number;
|
|
8
|
+
export declare const default_camera_position: (size: number) => Vec3;
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
import * as math from '../math';
|
|
2
|
+
import { BufferAttribute, BufferGeometry } from 'three';
|
|
3
|
+
// Build a renderable mesh from polyhedron vertices + polygonal faces via fan triangulation with flat per-face normals. Assumes convex faces (true for BZ/IBZ polyhedra); non-convex faces would triangulate incorrectly. Shared by BrillouinZoneScene (BZ + IBZ meshes) and FermiSurfaceScene (BZ overlay). Caller owns disposal.
|
|
4
|
+
export function polyhedron_geometry(vertices, faces) {
|
|
5
|
+
if (faces.length === 0)
|
|
6
|
+
return null;
|
|
7
|
+
const positions = [];
|
|
8
|
+
const normals = [];
|
|
9
|
+
for (const face of faces) {
|
|
10
|
+
if (face.length < 3)
|
|
11
|
+
continue;
|
|
12
|
+
for (let face_idx = 1; face_idx < face.length - 1; face_idx++) {
|
|
13
|
+
const indices = [face[0], face[face_idx], face[face_idx + 1]];
|
|
14
|
+
if (indices.some((idx) => idx < 0 || idx >= vertices.length))
|
|
15
|
+
continue;
|
|
16
|
+
const [vertex_a, vertex_b, vertex_c] = indices.map((idx) => vertices[idx]);
|
|
17
|
+
positions.push(...vertex_a, ...vertex_b, ...vertex_c);
|
|
18
|
+
const edge_ab = math.subtract(vertex_b, vertex_a);
|
|
19
|
+
const edge_ac = math.subtract(vertex_c, vertex_a);
|
|
20
|
+
const face_normal = math.cross_3d(edge_ab, edge_ac);
|
|
21
|
+
const normal_length = Math.hypot(...face_normal);
|
|
22
|
+
const unit_normal = normal_length > 1e-10 ? face_normal.map((coord) => coord / normal_length) : [0, 0, 0];
|
|
23
|
+
normals.push(...unit_normal, ...unit_normal, ...unit_normal);
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
// All faces degenerate or out-of-range -> no triangles, so return null instead of an empty geometry
|
|
27
|
+
if (positions.length === 0)
|
|
28
|
+
return null;
|
|
29
|
+
const geometry = new BufferGeometry();
|
|
30
|
+
geometry.setAttribute(`position`, new BufferAttribute(new Float32Array(positions), 3));
|
|
31
|
+
geometry.setAttribute(`normal`, new BufferAttribute(new Float32Array(normals), 3));
|
|
32
|
+
geometry.computeBoundingSphere();
|
|
33
|
+
return geometry;
|
|
34
|
+
}
|
|
35
|
+
// Inverse of the reciprocal lattice for Cartesian -> fractional conversion; null if the lattice is missing or singular
|
|
36
|
+
export function k_lattice_inverse(k_lattice) {
|
|
37
|
+
if (!k_lattice)
|
|
38
|
+
return null;
|
|
39
|
+
try {
|
|
40
|
+
return math.matrix_inverse_3x3(k_lattice);
|
|
41
|
+
}
|
|
42
|
+
catch {
|
|
43
|
+
return null;
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
// Convert Cartesian k-coordinates to fractional (reciprocal lattice units); null if the (pre-computed) lattice inverse is unavailable
|
|
47
|
+
export const cartesian_to_fractional = (k_lattice_inv, cart) => k_lattice_inv && math.mat3x3_vec3_multiply(k_lattice_inv, cart);
|
|
48
|
+
// Centroid of polyhedron vertices, used as orbit/rotation target by BZ + Fermi scenes
|
|
49
|
+
export const polyhedron_centroid = (vertices) => vertices?.length
|
|
50
|
+
? math.scale(vertices.reduce((acc, vert) => math.add(acc, vert), [0, 0, 0]), 1 / vertices.length)
|
|
51
|
+
: [0, 0, 0];
|
|
52
|
+
// Mean reciprocal-lattice vector magnitude: characteristic scene size for camera placement
|
|
53
|
+
// and arrow scaling. Fallback 10 (upper end of typical |b_i| ~ 2pi/a in 1/A) keeps the
|
|
54
|
+
// camera at a sensible distance while no data is loaded.
|
|
55
|
+
export const k_space_size = (k_lattice) => k_lattice ? k_lattice.reduce((sum, vec) => sum + Math.hypot(...vec), 0) / 3 : 10;
|
|
56
|
+
// Default camera position scaled to the scene size
|
|
57
|
+
export const default_camera_position = (size) => [10, 3, 8].map((coord) => coord * Math.max(1, size));
|
|
@@ -5,4 +5,6 @@ export { default as BrillouinZoneInfoPane } from './BrillouinZoneInfoPane.svelte
|
|
|
5
5
|
export { default as BrillouinZoneScene } from './BrillouinZoneScene.svelte';
|
|
6
6
|
export { default as BrillouinZoneTooltip } from './BrillouinZoneTooltip.svelte';
|
|
7
7
|
export * from './compute';
|
|
8
|
+
export * from './geometry';
|
|
9
|
+
export { default as ReciprocalVectors } from './ReciprocalVectors.svelte';
|
|
8
10
|
export type * from './types';
|
package/dist/brillouin/index.js
CHANGED
|
@@ -5,3 +5,5 @@ export { default as BrillouinZoneInfoPane } from './BrillouinZoneInfoPane.svelte
|
|
|
5
5
|
export { default as BrillouinZoneScene } from './BrillouinZoneScene.svelte';
|
|
6
6
|
export { default as BrillouinZoneTooltip } from './BrillouinZoneTooltip.svelte';
|
|
7
7
|
export * from './compute';
|
|
8
|
+
export * from './geometry';
|
|
9
|
+
export { default as ReciprocalVectors } from './ReciprocalVectors.svelte';
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type { Matrix3x3, Point2D, Vec3 } from '../math';
|
|
1
|
+
import type { Matrix3x3, Point2D, Vec2, Vec3 } from '../math';
|
|
2
2
|
import type { Crystal } from '../structure';
|
|
3
3
|
import type { TooltipConfig, TooltipProp } from '../tooltip';
|
|
4
4
|
export type BZHoverData = {
|
|
@@ -38,6 +38,6 @@ export type BrillouinZoneProps = {
|
|
|
38
38
|
show_vectors?: boolean;
|
|
39
39
|
};
|
|
40
40
|
export type ConvexHullData = Pick<BZMeshData, `vertices` | `faces`> & {
|
|
41
|
-
edges: [
|
|
41
|
+
edges: Vec2[];
|
|
42
42
|
};
|
|
43
43
|
export {};
|
|
@@ -8,6 +8,6 @@ type $$ComponentProps = {
|
|
|
8
8
|
temperature?: number;
|
|
9
9
|
hover_info?: ChemPotHoverInfo | null;
|
|
10
10
|
};
|
|
11
|
-
declare const ChemPotDiagram: import("svelte").Component<$$ComponentProps, {}, "
|
|
11
|
+
declare const ChemPotDiagram: import("svelte").Component<$$ComponentProps, {}, "height" | "width" | "temperature" | "hover_info">;
|
|
12
12
|
type ChemPotDiagram = ReturnType<typeof ChemPotDiagram>;
|
|
13
13
|
export default ChemPotDiagram;
|