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.
Files changed (326) hide show
  1. package/dist/brillouin/BrillouinZone.svelte +68 -145
  2. package/dist/brillouin/BrillouinZone.svelte.d.ts +5 -14
  3. package/dist/brillouin/BrillouinZoneExportPane.svelte +43 -96
  4. package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +1 -1
  5. package/dist/brillouin/BrillouinZoneInfoPane.svelte +9 -32
  6. package/dist/brillouin/BrillouinZoneInfoPane.svelte.d.ts +2 -3
  7. package/dist/brillouin/BrillouinZoneScene.svelte +49 -203
  8. package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +3 -23
  9. package/dist/brillouin/ReciprocalVectors.svelte +39 -0
  10. package/dist/brillouin/ReciprocalVectors.svelte.d.ts +9 -0
  11. package/dist/brillouin/compute.d.ts +2 -0
  12. package/dist/brillouin/compute.js +80 -77
  13. package/dist/brillouin/geometry.d.ts +8 -0
  14. package/dist/brillouin/geometry.js +57 -0
  15. package/dist/brillouin/index.d.ts +2 -0
  16. package/dist/brillouin/index.js +2 -0
  17. package/dist/brillouin/types.d.ts +2 -2
  18. package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +1 -1
  19. package/dist/chempot-diagram/ChemPotDiagram2D.svelte +100 -191
  20. package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +4 -1
  21. package/dist/chempot-diagram/ChemPotDiagram3D.svelte +176 -464
  22. package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +7 -1
  23. package/dist/chempot-diagram/color.d.ts +3 -6
  24. package/dist/chempot-diagram/color.js +5 -5
  25. package/dist/chempot-diagram/compute.d.ts +3 -3
  26. package/dist/chempot-diagram/compute.js +3 -1
  27. package/dist/chempot-diagram/controls-state.svelte.d.ts +10 -0
  28. package/dist/chempot-diagram/controls-state.svelte.js +42 -0
  29. package/dist/chempot-diagram/export.d.ts +47 -0
  30. package/dist/chempot-diagram/export.js +133 -0
  31. package/dist/chempot-diagram/index.d.ts +1 -0
  32. package/dist/chempot-diagram/index.js +1 -0
  33. package/dist/chempot-diagram/pointer.d.ts +0 -10
  34. package/dist/chempot-diagram/pointer.js +4 -4
  35. package/dist/chempot-diagram/types.d.ts +3 -3
  36. package/dist/colors/index.js +2 -2
  37. package/dist/composition/FormulaFilter.svelte +6 -5
  38. package/dist/composition/PieChart.svelte +5 -5
  39. package/dist/composition/chem-sys.js +3 -2
  40. package/dist/composition/format.js +3 -2
  41. package/dist/composition/parse.d.ts +0 -1
  42. package/dist/composition/parse.js +17 -19
  43. package/dist/controls.d.ts +1 -0
  44. package/dist/controls.js +0 -1
  45. package/dist/convex-hull/ConvexHull.svelte +8 -10
  46. package/dist/convex-hull/ConvexHull.svelte.d.ts +1 -4
  47. package/dist/convex-hull/ConvexHull2D.svelte +94 -175
  48. package/dist/convex-hull/ConvexHull2D.svelte.d.ts +1 -1
  49. package/dist/convex-hull/ConvexHull3D.svelte +176 -680
  50. package/dist/convex-hull/ConvexHull3D.svelte.d.ts +1 -1
  51. package/dist/convex-hull/ConvexHull4D.svelte +180 -680
  52. package/dist/convex-hull/ConvexHull4D.svelte.d.ts +1 -1
  53. package/dist/convex-hull/ConvexHullChrome.svelte +268 -0
  54. package/dist/convex-hull/ConvexHullChrome.svelte.d.ts +30 -0
  55. package/dist/convex-hull/ConvexHullControls.svelte +88 -7
  56. package/dist/convex-hull/ConvexHullControls.svelte.d.ts +7 -6
  57. package/dist/convex-hull/ConvexHullInfoPane.svelte +18 -5
  58. package/dist/convex-hull/ConvexHullInfoPane.svelte.d.ts +6 -5
  59. package/dist/convex-hull/ConvexHullStats.svelte +29 -168
  60. package/dist/convex-hull/ConvexHullStats.svelte.d.ts +3 -1
  61. package/dist/convex-hull/ConvexHullTooltip.svelte +11 -2
  62. package/dist/convex-hull/ConvexHullTooltip.svelte.d.ts +2 -1
  63. package/dist/convex-hull/barycentric-coords.d.ts +2 -4
  64. package/dist/convex-hull/barycentric-coords.js +6 -33
  65. package/dist/convex-hull/canvas-interactions.svelte.d.ts +79 -0
  66. package/dist/convex-hull/canvas-interactions.svelte.js +278 -0
  67. package/dist/convex-hull/helpers.d.ts +39 -7
  68. package/dist/convex-hull/helpers.js +154 -69
  69. package/dist/convex-hull/hull-state.svelte.d.ts +44 -0
  70. package/dist/convex-hull/hull-state.svelte.js +124 -0
  71. package/dist/convex-hull/index.d.ts +9 -7
  72. package/dist/convex-hull/index.js +7 -2
  73. package/dist/convex-hull/thermodynamics.js +91 -920
  74. package/dist/convex-hull/types.d.ts +12 -4
  75. package/dist/convex-hull/types.js +12 -0
  76. package/dist/coordination/CoordinationBarPlot.svelte +4 -11
  77. package/dist/element/BohrAtom.svelte +2 -1
  78. package/dist/element/ElementTile.svelte.d.ts +1 -1
  79. package/dist/element/index.d.ts +4 -0
  80. package/dist/element/index.js +18 -0
  81. package/dist/feedback/DragOverlay.svelte +3 -1
  82. package/dist/feedback/DragOverlay.svelte.d.ts +1 -0
  83. package/dist/feedback/StatusMessage.svelte +13 -3
  84. package/dist/fermi-surface/FermiSurface.svelte +67 -146
  85. package/dist/fermi-surface/FermiSurface.svelte.d.ts +5 -14
  86. package/dist/fermi-surface/FermiSurfaceControls.svelte.d.ts +1 -1
  87. package/dist/fermi-surface/FermiSurfaceScene.svelte +72 -224
  88. package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +3 -23
  89. package/dist/fermi-surface/compute.js +11 -10
  90. package/dist/fermi-surface/export.js +4 -15
  91. package/dist/fermi-surface/index.d.ts +0 -1
  92. package/dist/fermi-surface/index.js +0 -1
  93. package/dist/fermi-surface/parse.d.ts +1 -1
  94. package/dist/fermi-surface/parse.js +64 -75
  95. package/dist/fermi-surface/types.d.ts +2 -2
  96. package/dist/heatmap-matrix/HeatmapMatrix.svelte +55 -40
  97. package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +4 -3
  98. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +3 -2
  99. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +5 -5
  100. package/dist/heatmap-matrix/index.d.ts +3 -2
  101. package/dist/index.d.ts +1 -0
  102. package/dist/index.js +1 -0
  103. package/dist/io/ExportPane.svelte +166 -0
  104. package/dist/io/ExportPane.svelte.d.ts +17 -0
  105. package/dist/io/decompress.js +1 -2
  106. package/dist/io/export.d.ts +5 -1
  107. package/dist/io/export.js +32 -28
  108. package/dist/io/fetch.d.ts +2 -1
  109. package/dist/io/file-drop.d.ts +7 -0
  110. package/dist/io/file-drop.js +13 -0
  111. package/dist/io/index.d.ts +2 -0
  112. package/dist/io/index.js +10 -0
  113. package/dist/io/types.d.ts +13 -0
  114. package/dist/isosurface/parse.js +46 -44
  115. package/dist/labels.js +1 -1
  116. package/dist/layout/FullscreenButton.svelte +33 -0
  117. package/dist/layout/FullscreenButton.svelte.d.ts +10 -0
  118. package/dist/layout/FullscreenToggle.svelte +8 -14
  119. package/dist/layout/ViewerChrome.svelte +116 -0
  120. package/dist/layout/ViewerChrome.svelte.d.ts +17 -0
  121. package/dist/layout/fullscreen.d.ts +4 -0
  122. package/dist/layout/fullscreen.svelte.d.ts +8 -0
  123. package/dist/layout/fullscreen.svelte.js +37 -0
  124. package/dist/layout/index.d.ts +3 -0
  125. package/dist/layout/index.js +3 -0
  126. package/dist/math.d.ts +7 -3
  127. package/dist/math.js +18 -21
  128. package/dist/overlays/index.d.ts +4 -0
  129. package/dist/periodic-table/PeriodicTable.svelte +9 -8
  130. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +1 -1
  131. package/dist/phase-diagram/PhaseDiagramControls.svelte +3 -2
  132. package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +4 -3
  133. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +2 -1
  134. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +2 -3
  135. package/dist/phase-diagram/PhaseDiagramExportPane.svelte +47 -132
  136. package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +3 -4
  137. package/dist/phase-diagram/colors.js +1 -1
  138. package/dist/phase-diagram/parse.d.ts +2 -1
  139. package/dist/plot/bar/BarPlot.svelte +79 -316
  140. package/dist/plot/bar/BarPlot.svelte.d.ts +7 -15
  141. package/dist/plot/bar/BarPlotControls.svelte.d.ts +1 -1
  142. package/dist/plot/bar/SpacegroupBarPlot.svelte +2 -1
  143. package/dist/plot/box/BoxPlot.svelte +76 -246
  144. package/dist/plot/box/BoxPlot.svelte.d.ts +4 -3
  145. package/dist/plot/box/BoxPlotControls.svelte.d.ts +1 -1
  146. package/dist/plot/box/Violin.svelte.d.ts +1 -1
  147. package/dist/plot/box/box-plot.d.ts +3 -2
  148. package/dist/plot/box/box-plot.js +5 -2
  149. package/dist/plot/box/kde.d.ts +2 -1
  150. package/dist/plot/box/kde.js +4 -4
  151. package/dist/plot/core/auto-place.d.ts +1 -1
  152. package/dist/plot/core/auto-place.js +4 -1
  153. package/dist/plot/core/components/ColorBar.svelte +5 -5
  154. package/dist/plot/core/components/ColorBar.svelte.d.ts +5 -4
  155. package/dist/plot/core/components/Line.svelte +3 -2
  156. package/dist/plot/core/components/Line.svelte.d.ts +3 -2
  157. package/dist/plot/core/components/PlotAxis.svelte +2 -1
  158. package/dist/plot/core/components/PlotAxis.svelte.d.ts +2 -1
  159. package/dist/plot/core/components/PlotControls.svelte.d.ts +1 -1
  160. package/dist/plot/core/components/ReferenceLine3D.svelte +2 -2
  161. package/dist/plot/core/components/ReferenceLine3D.svelte.d.ts +4 -4
  162. package/dist/plot/core/components/ReferencePlane.svelte +2 -2
  163. package/dist/plot/core/components/ReferencePlane.svelte.d.ts +4 -4
  164. package/dist/plot/core/data-cleaning.js +18 -18
  165. package/dist/plot/core/fill-utils.d.ts +4 -3
  166. package/dist/plot/core/fill-utils.js +6 -3
  167. package/dist/plot/core/interactions.d.ts +5 -1
  168. package/dist/plot/core/interactions.js +14 -0
  169. package/dist/plot/core/pan-zoom.svelte.d.ts +35 -0
  170. package/dist/plot/core/pan-zoom.svelte.js +221 -0
  171. package/dist/plot/core/placed-tween.svelte.d.ts +21 -0
  172. package/dist/plot/core/placed-tween.svelte.js +68 -0
  173. package/dist/plot/core/reference-line.d.ts +10 -10
  174. package/dist/plot/core/reference-line.js +6 -6
  175. package/dist/plot/core/scales.d.ts +17 -25
  176. package/dist/plot/core/scales.js +10 -8
  177. package/dist/plot/core/svg.d.ts +2 -1
  178. package/dist/plot/core/types.d.ts +18 -7
  179. package/dist/plot/core/utils/label-placement.d.ts +1 -1
  180. package/dist/plot/core/utils/label-placement.js +3 -3
  181. package/dist/plot/core/utils.d.ts +2 -1
  182. package/dist/plot/histogram/Histogram.svelte +77 -314
  183. package/dist/plot/histogram/HistogramControls.svelte.d.ts +1 -1
  184. package/dist/plot/sankey/Sankey.svelte +2 -5
  185. package/dist/plot/sankey/Sankey.svelte.d.ts +1 -1
  186. package/dist/plot/sankey/sankey.js +3 -1
  187. package/dist/plot/scatter/BinnedScatterPlot.svelte +3 -5
  188. package/dist/plot/scatter/BinnedScatterPlot.svelte.d.ts +4 -4
  189. package/dist/plot/scatter/ScatterPlot.svelte +160 -450
  190. package/dist/plot/scatter/ScatterPlot.svelte.d.ts +7 -15
  191. package/dist/plot/scatter/ScatterPlotControls.svelte.d.ts +1 -1
  192. package/dist/plot/scatter/binned-scatter-types.d.ts +4 -11
  193. package/dist/plot/scatter/index.d.ts +1 -1
  194. package/dist/plot/scatter-3d/ScatterPlot3D.svelte +15 -26
  195. package/dist/plot/scatter-3d/ScatterPlot3D.svelte.d.ts +6 -14
  196. package/dist/plot/scatter-3d/ScatterPlot3DControls.svelte +9 -10
  197. package/dist/plot/scatter-3d/ScatterPlot3DControls.svelte.d.ts +5 -5
  198. package/dist/plot/scatter-3d/ScatterPlot3DScene.svelte +122 -121
  199. package/dist/plot/scatter-3d/ScatterPlot3DScene.svelte.d.ts +5 -14
  200. package/dist/plot/scatter-3d/Surface3D.svelte +6 -5
  201. package/dist/plot/scatter-3d/Surface3D.svelte.d.ts +4 -3
  202. package/dist/plot/sunburst/Sunburst.svelte +16 -20
  203. package/dist/plot/sunburst/Sunburst.svelte.d.ts +4 -3
  204. package/dist/plot/sunburst/SunburstControls.svelte.d.ts +1 -1
  205. package/dist/plot/sunburst/sunburst.js +4 -1
  206. package/dist/rdf/RdfPlot.svelte.d.ts +1 -1
  207. package/dist/sanitize.js +13 -2
  208. package/dist/scene/SceneCamera.svelte +62 -0
  209. package/dist/scene/SceneCamera.svelte.d.ts +19 -0
  210. package/dist/scene/bind-renderer.svelte.d.ts +2 -0
  211. package/dist/scene/bind-renderer.svelte.js +14 -0
  212. package/dist/scene/index.d.ts +4 -0
  213. package/dist/scene/index.js +5 -0
  214. package/dist/scene/props.js +52 -0
  215. package/dist/scene/types.d.ts +26 -0
  216. package/dist/scene/types.js +1 -0
  217. package/dist/settings.d.ts +14 -2
  218. package/dist/settings.js +59 -1
  219. package/dist/spectral/Bands.svelte +8 -7
  220. package/dist/spectral/Bands.svelte.d.ts +3 -2
  221. package/dist/spectral/BandsAndDos.svelte +22 -24
  222. package/dist/spectral/BrillouinBandsDos.svelte +3 -3
  223. package/dist/spectral/Dos.svelte +5 -4
  224. package/dist/spectral/Dos.svelte.d.ts +2 -1
  225. package/dist/spectral/helpers.d.ts +6 -6
  226. package/dist/spectral/helpers.js +43 -37
  227. package/dist/state.svelte.d.ts +0 -7
  228. package/dist/state.svelte.js +0 -6
  229. package/dist/structure/Arrow.svelte +2 -4
  230. package/dist/structure/AtomLegend.svelte.d.ts +1 -1
  231. package/dist/structure/CanvasTooltip.svelte +1 -0
  232. package/dist/structure/CellSelect.svelte +11 -3
  233. package/dist/structure/CellSelect.svelte.d.ts +2 -1
  234. package/dist/structure/Lattice.svelte +2 -2
  235. package/dist/structure/Structure.svelte +291 -355
  236. package/dist/structure/Structure.svelte.d.ts +5 -15
  237. package/dist/structure/StructureControls.svelte +217 -2
  238. package/dist/structure/StructureControls.svelte.d.ts +5 -3
  239. package/dist/structure/StructureExportPane.svelte +54 -156
  240. package/dist/structure/StructureExportPane.svelte.d.ts +4 -5
  241. package/dist/structure/StructureInfoPane.svelte +5 -3
  242. package/dist/structure/StructureInfoPane.svelte.d.ts +5 -5
  243. package/dist/structure/StructureScene.svelte +365 -198
  244. package/dist/structure/StructureScene.svelte.d.ts +22 -20
  245. package/dist/structure/{label-placement.d.ts → atom-label-placement.d.ts} +3 -3
  246. package/dist/structure/{label-placement.js → atom-label-placement.js} +12 -2
  247. package/dist/structure/atom-properties.d.ts +1 -1
  248. package/dist/structure/atom-properties.js +11 -16
  249. package/dist/structure/bond-order-perception.js +2 -4
  250. package/dist/structure/bonding.d.ts +3 -0
  251. package/dist/structure/bonding.js +91 -48
  252. package/dist/structure/export.d.ts +24 -4
  253. package/dist/structure/export.js +64 -122
  254. package/dist/structure/index.d.ts +2 -0
  255. package/dist/structure/index.js +2 -0
  256. package/dist/structure/parse.d.ts +3 -2
  257. package/dist/structure/parse.js +333 -370
  258. package/dist/structure/partial-occupancy.d.ts +0 -1
  259. package/dist/structure/partial-occupancy.js +1 -1
  260. package/dist/structure/pbc.d.ts +1 -1
  261. package/dist/structure/pbc.js +186 -13
  262. package/dist/structure/polyhedra.d.ts +41 -0
  263. package/dist/structure/polyhedra.js +602 -0
  264. package/dist/structure/site.d.ts +4 -0
  265. package/dist/structure/site.js +1 -0
  266. package/dist/structure/supercell.js +3 -2
  267. package/dist/structure/validation.js +5 -6
  268. package/dist/symmetry/SymmetryElementControls.svelte +69 -0
  269. package/dist/symmetry/SymmetryElementControls.svelte.d.ts +9 -0
  270. package/dist/symmetry/SymmetryElements.svelte +354 -0
  271. package/dist/symmetry/SymmetryElements.svelte.d.ts +24 -0
  272. package/dist/symmetry/SymmetryStats.svelte +111 -6
  273. package/dist/symmetry/WyckoffTable.svelte +68 -7
  274. package/dist/symmetry/WyckoffTable.svelte.d.ts +3 -0
  275. package/dist/symmetry/cell-transform.js +7 -14
  276. package/dist/symmetry/index.d.ts +14 -4
  277. package/dist/symmetry/index.js +301 -80
  278. package/dist/symmetry/spacegroups.d.ts +5 -1
  279. package/dist/symmetry/spacegroups.js +15 -1
  280. package/dist/symmetry/symmetry-elements.d.ts +33 -0
  281. package/dist/symmetry/symmetry-elements.js +521 -0
  282. package/dist/symmetry/wyckoff-db.d.ts +9 -0
  283. package/dist/symmetry/wyckoff-db.js +87 -0
  284. package/dist/table/HeatmapTable.svelte +4 -15
  285. package/dist/table/HeatmapTable.svelte.d.ts +1 -1
  286. package/dist/trajectory/Trajectory.svelte +58 -61
  287. package/dist/trajectory/Trajectory.svelte.d.ts +10 -22
  288. package/dist/trajectory/TrajectoryExportPane.svelte +15 -24
  289. package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +4 -5
  290. package/dist/trajectory/TrajectoryInfoPane.svelte +3 -2
  291. package/dist/trajectory/TrajectoryInfoPane.svelte.d.ts +3 -2
  292. package/dist/trajectory/constants.js +6 -2
  293. package/dist/trajectory/extract.js +17 -37
  294. package/dist/trajectory/format-detect.d.ts +0 -1
  295. package/dist/trajectory/format-detect.js +3 -9
  296. package/dist/trajectory/frame-reader.d.ts +0 -1
  297. package/dist/trajectory/frame-reader.js +62 -128
  298. package/dist/trajectory/helpers.d.ts +10 -2
  299. package/dist/trajectory/helpers.js +56 -36
  300. package/dist/trajectory/parse/ase.d.ts +9 -1
  301. package/dist/trajectory/parse/ase.js +47 -32
  302. package/dist/trajectory/parse/diagnostics.d.ts +3 -0
  303. package/dist/trajectory/parse/diagnostics.js +14 -0
  304. package/dist/trajectory/parse/index.d.ts +1 -1
  305. package/dist/trajectory/parse/index.js +54 -102
  306. package/dist/trajectory/parse/lammps.d.ts +0 -2
  307. package/dist/trajectory/parse/lammps.js +8 -6
  308. package/dist/trajectory/parse/pymatgen.d.ts +2 -0
  309. package/dist/trajectory/parse/pymatgen.js +74 -0
  310. package/dist/trajectory/parse/vasp.js +4 -3
  311. package/dist/trajectory/parse/xyz.d.ts +9 -21
  312. package/dist/trajectory/parse/xyz.js +28 -33
  313. package/dist/trajectory/plotting.d.ts +0 -1
  314. package/dist/trajectory/plotting.js +3 -100
  315. package/dist/utils.d.ts +1 -0
  316. package/dist/utils.js +1 -1
  317. package/dist/xrd/XrdPlot.svelte +14 -29
  318. package/dist/xrd/broadening.d.ts +2 -1
  319. package/dist/xrd/calc-xrd.js +6 -11
  320. package/dist/xrd/index.d.ts +2 -2
  321. package/package.json +29 -16
  322. package/dist/element/data.json +0 -11864
  323. package/dist/fermi-surface/marching-cubes.d.ts +0 -2
  324. package/dist/fermi-surface/marching-cubes.js +0 -2
  325. package/dist/plot/core/hover-lock.svelte.d.ts +0 -14
  326. 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 mat3x3_multiply(mat3x3_multiply(B_T, W_inv_T), math.matrix_inverse_3x3(B_T));
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 { normal: normalize(pt), dist: Math.sqrt(dist_sq) / 2, dist_sq };
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 normalize(math.cross_3d(math.subtract(v1, v0), math.subtract(v2, v0)));
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
- // Test points for IBZ plane detection. These are chosen to:
281
- // 1. Avoid common rotation axes (2-fold, 3-fold, 4-fold, 6-fold)
282
- // 2. Span different directions to catch all symmetry operations
283
- // 3. Include a generic point [1,2,3] that lies on no special axis
284
- const IBZ_TEST_POINTS = [
285
- [1, 0, 0],
286
- [0, 1, 0],
287
- [0, 0, 1], // basis vectors (avoid 4-fold axes)
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
- // Compute clipping planes from point group operations.
295
- // For each non-identity rotation, we define a plane that selects one representative
296
- // from each equivalence class.
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 point_group_ops) {
301
- if (is_identity_rotation(rot))
302
- continue;
303
- for (const test_pt of IBZ_TEST_POINTS) {
304
- const rotated = math.mat3x3_vec3_multiply(rot, test_pt);
305
- const diff = math.subtract(rotated, test_pt);
306
- if (Math.hypot(...diff) < TOL)
307
- continue; // point on rotation axis
308
- const plane_normal = normalize(diff);
309
- const key = plane_normal.map((val) => Math.round(val * 1000)).join(`,`);
310
- const neg_key = plane_normal.map((val) => Math.round(-val * 1000)).join(`,`);
311
- if (!seen_normals.has(key) && !seen_normals.has(neg_key)) {
312
- seen_normals.add(key);
313
- planes.push({ normal: plane_normal, dist: 0 });
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 t = d1 / denom;
360
+ const frac = d1 / denom;
354
361
  // Only add intersection if it's not at an endpoint (which is already kept)
355
- if (t > TOL && t < 1 - TOL) {
362
+ if (frac > TOL && frac < 1 - TOL) {
356
363
  const [v1, v2] = [vertices[i1], vertices[i2]];
357
364
  result.push([
358
- v1[0] + t * (v2[0] - v1[0]),
359
- v1[1] + t * (v2[1] - v1[1]),
360
- v1[2] + t * (v2[2] - 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
- // Try clipping with plane, then flipped plane if needed
397
- let clipped_successfully = false;
398
- for (const try_plane of [plane, flip_plane(plane)]) {
399
- const clipped = clip_polyhedron_by_plane(current_vertices, current_faces, try_plane);
400
- const hull = try_build_hull(clipped, edge_sharp_angle_deg);
401
- if (hull) {
402
- current_vertices = hull.vertices;
403
- current_faces = hull.faces;
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
- // If both orientations failed, vertices unchanged - continue with best effort
409
- if (!clipped_successfully) {
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';
@@ -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: [number, number][];
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, {}, "temperature" | "height" | "width" | "hover_info">;
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;