matterviz 0.3.6 → 0.3.7

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 (863) hide show
  1. package/dist/EmptyState.svelte.d.ts +9 -0
  2. package/dist/FilePicker.svelte +360 -0
  3. package/dist/FilePicker.svelte.d.ts +17 -0
  4. package/dist/Icon.svelte.d.ts +13 -0
  5. package/dist/MillerIndexInput.svelte +66 -0
  6. package/dist/MillerIndexInput.svelte.d.ts +7 -0
  7. package/dist/api/mp.d.ts +6 -0
  8. package/dist/api/mp.js +22 -0
  9. package/dist/api/optimade.d.ts +45 -0
  10. package/dist/api/optimade.js +135 -0
  11. package/dist/brillouin/BrillouinZone.svelte +549 -0
  12. package/dist/brillouin/BrillouinZone.svelte.d.ts +83 -0
  13. package/dist/brillouin/BrillouinZoneControls.svelte +144 -0
  14. package/dist/brillouin/BrillouinZoneControls.svelte.d.ts +17 -0
  15. package/dist/brillouin/BrillouinZoneExportPane.svelte +146 -0
  16. package/dist/brillouin/BrillouinZoneExportPane.svelte.d.ts +15 -0
  17. package/dist/brillouin/BrillouinZoneInfoPane.svelte +146 -0
  18. package/dist/brillouin/BrillouinZoneInfoPane.svelte.d.ts +13 -0
  19. package/dist/brillouin/BrillouinZoneScene.svelte +476 -0
  20. package/dist/brillouin/BrillouinZoneScene.svelte.d.ts +48 -0
  21. package/dist/brillouin/BrillouinZoneTooltip.svelte +92 -0
  22. package/dist/brillouin/BrillouinZoneTooltip.svelte.d.ts +8 -0
  23. package/dist/brillouin/compute.d.ts +17 -0
  24. package/dist/brillouin/compute.js +426 -0
  25. package/dist/brillouin/index.d.ts +8 -0
  26. package/dist/brillouin/index.js +7 -0
  27. package/dist/brillouin/types.d.ts +43 -0
  28. package/dist/brillouin/types.js +1 -0
  29. package/dist/chempot-diagram/ChemPotDiagram.svelte +327 -0
  30. package/dist/chempot-diagram/ChemPotDiagram.svelte.d.ts +13 -0
  31. package/dist/chempot-diagram/ChemPotDiagram2D.svelte +846 -0
  32. package/dist/chempot-diagram/ChemPotDiagram2D.svelte.d.ts +16 -0
  33. package/dist/chempot-diagram/ChemPotDiagram3D.svelte +3193 -0
  34. package/dist/chempot-diagram/ChemPotDiagram3D.svelte.d.ts +16 -0
  35. package/dist/chempot-diagram/ChemPotScene3D.svelte.d.ts +7 -0
  36. package/dist/chempot-diagram/async-compute.svelte.d.ts +3 -0
  37. package/dist/chempot-diagram/async-compute.svelte.js +78 -0
  38. package/dist/chempot-diagram/chempot-worker.d.ts +1 -0
  39. package/dist/chempot-diagram/chempot-worker.js +11 -0
  40. package/dist/chempot-diagram/color.d.ts +10 -0
  41. package/dist/chempot-diagram/color.js +32 -0
  42. package/dist/chempot-diagram/compute.d.ts +48 -0
  43. package/dist/chempot-diagram/compute.js +806 -0
  44. package/dist/chempot-diagram/index.d.ts +6 -0
  45. package/dist/chempot-diagram/index.js +6 -0
  46. package/dist/chempot-diagram/pointer.d.ts +16 -0
  47. package/dist/chempot-diagram/pointer.js +40 -0
  48. package/dist/chempot-diagram/temperature.d.ts +15 -0
  49. package/dist/chempot-diagram/temperature.js +34 -0
  50. package/dist/chempot-diagram/types.d.ts +81 -0
  51. package/dist/chempot-diagram/types.js +28 -0
  52. package/dist/colors/index.d.ts +47 -0
  53. package/dist/colors/index.js +203 -0
  54. package/dist/composition/BarChart.svelte +297 -0
  55. package/dist/composition/BarChart.svelte.d.ts +39 -0
  56. package/dist/composition/BubbleChart.svelte +218 -0
  57. package/dist/composition/BubbleChart.svelte.d.ts +28 -0
  58. package/dist/composition/Composition.svelte +165 -0
  59. package/dist/composition/Composition.svelte.d.ts +15 -0
  60. package/dist/composition/Formula.svelte +268 -0
  61. package/dist/composition/Formula.svelte.d.ts +19 -0
  62. package/dist/composition/FormulaFilter.svelte +1257 -0
  63. package/dist/composition/FormulaFilter.svelte.d.ts +51 -0
  64. package/dist/composition/PieChart.svelte +323 -0
  65. package/dist/composition/PieChart.svelte.d.ts +37 -0
  66. package/dist/composition/format.d.ts +15 -0
  67. package/dist/composition/format.js +109 -0
  68. package/dist/composition/index.d.ts +20 -0
  69. package/dist/composition/index.js +14 -0
  70. package/dist/composition/parse.d.ts +56 -0
  71. package/dist/composition/parse.js +474 -0
  72. package/dist/constants.d.ts +29 -0
  73. package/dist/constants.js +99 -0
  74. package/dist/controls.d.ts +14 -0
  75. package/dist/controls.js +30 -0
  76. package/dist/convex-hull/ConvexHull.svelte +157 -0
  77. package/dist/convex-hull/ConvexHull.svelte.d.ts +13 -0
  78. package/dist/convex-hull/ConvexHull2D.svelte +825 -0
  79. package/dist/convex-hull/ConvexHull2D.svelte.d.ts +11 -0
  80. package/dist/convex-hull/ConvexHull3D.svelte +1801 -0
  81. package/dist/convex-hull/ConvexHull3D.svelte.d.ts +8 -0
  82. package/dist/convex-hull/ConvexHull4D.svelte +1398 -0
  83. package/dist/convex-hull/ConvexHull4D.svelte.d.ts +8 -0
  84. package/dist/convex-hull/ConvexHullControls.svelte +535 -0
  85. package/dist/convex-hull/ConvexHullControls.svelte.d.ts +48 -0
  86. package/dist/convex-hull/ConvexHullInfoPane.svelte +125 -0
  87. package/dist/convex-hull/ConvexHullInfoPane.svelte.d.ts +20 -0
  88. package/dist/convex-hull/ConvexHullStats.svelte +929 -0
  89. package/dist/convex-hull/ConvexHullStats.svelte.d.ts +17 -0
  90. package/dist/convex-hull/ConvexHullTooltip.svelte +131 -0
  91. package/dist/convex-hull/ConvexHullTooltip.svelte.d.ts +33 -0
  92. package/dist/convex-hull/GasPressureControls.svelte +247 -0
  93. package/dist/convex-hull/GasPressureControls.svelte.d.ts +11 -0
  94. package/dist/convex-hull/StructurePopup.svelte +151 -0
  95. package/dist/convex-hull/StructurePopup.svelte.d.ts +18 -0
  96. package/dist/convex-hull/TemperatureSlider.svelte.d.ts +8 -0
  97. package/dist/convex-hull/barycentric-coords.d.ts +18 -0
  98. package/dist/convex-hull/barycentric-coords.js +182 -0
  99. package/dist/convex-hull/demo-temperature.d.ts +6 -0
  100. package/dist/convex-hull/demo-temperature.js +40 -0
  101. package/dist/convex-hull/gas-thermodynamics.d.ts +16 -0
  102. package/dist/convex-hull/gas-thermodynamics.js +314 -0
  103. package/dist/convex-hull/helpers.d.ts +114 -0
  104. package/dist/convex-hull/helpers.js +710 -0
  105. package/dist/convex-hull/index.d.ts +119 -0
  106. package/dist/convex-hull/index.js +58 -0
  107. package/dist/convex-hull/thermodynamics.d.ts +67 -0
  108. package/dist/convex-hull/thermodynamics.js +1752 -0
  109. package/dist/convex-hull/types.d.ts +162 -0
  110. package/dist/convex-hull/types.js +36 -0
  111. package/dist/coordination/CoordinationBarPlot.svelte +311 -0
  112. package/dist/coordination/CoordinationBarPlot.svelte.d.ts +30 -0
  113. package/dist/coordination/calc-coordination.d.ts +15 -0
  114. package/dist/coordination/calc-coordination.js +63 -0
  115. package/dist/coordination/index.d.ts +8 -0
  116. package/dist/coordination/index.js +7 -0
  117. package/dist/effects.svelte.d.ts +12 -0
  118. package/dist/effects.svelte.js +37 -0
  119. package/dist/element/BohrAtom.svelte.d.ts +20 -0
  120. package/dist/element/ElementHeading.svelte +26 -0
  121. package/dist/element/ElementHeading.svelte.d.ts +8 -0
  122. package/dist/element/ElementPhoto.svelte +57 -0
  123. package/dist/element/ElementPhoto.svelte.d.ts +9 -0
  124. package/dist/element/ElementStats.svelte +80 -0
  125. package/dist/element/ElementStats.svelte.d.ts +8 -0
  126. package/dist/element/ElementTile.svelte +484 -0
  127. package/dist/element/ElementTile.svelte.d.ts +29 -0
  128. package/dist/element/Nucleus.svelte.d.ts +17 -0
  129. package/dist/element/data.d.ts +2 -0
  130. package/dist/element/data.js +2 -0
  131. package/dist/element/index.d.ts +8 -0
  132. package/dist/element/index.js +7 -0
  133. package/dist/element/types.d.ts +57 -0
  134. package/dist/element/types.js +1 -0
  135. package/dist/feedback/ClickFeedback.svelte +58 -0
  136. package/dist/feedback/ClickFeedback.svelte.d.ts +12 -0
  137. package/dist/feedback/DragOverlay.svelte +42 -0
  138. package/dist/feedback/DragOverlay.svelte.d.ts +7 -0
  139. package/dist/feedback/Spinner.svelte.d.ts +7 -0
  140. package/dist/feedback/StatusMessage.svelte.d.ts +9 -0
  141. package/dist/feedback/index.d.ts +4 -0
  142. package/dist/feedback/index.js +4 -0
  143. package/dist/fermi-surface/FermiSlice.svelte +189 -0
  144. package/dist/fermi-surface/FermiSlice.svelte.d.ts +24 -0
  145. package/dist/fermi-surface/FermiSurface.svelte +600 -0
  146. package/dist/fermi-surface/FermiSurface.svelte.d.ts +83 -0
  147. package/dist/fermi-surface/FermiSurfaceControls.svelte +448 -0
  148. package/dist/fermi-surface/FermiSurfaceControls.svelte.d.ts +35 -0
  149. package/dist/fermi-surface/FermiSurfaceScene.svelte +794 -0
  150. package/dist/fermi-surface/FermiSurfaceScene.svelte.d.ts +50 -0
  151. package/dist/fermi-surface/FermiSurfaceTooltip.svelte +111 -0
  152. package/dist/fermi-surface/FermiSurfaceTooltip.svelte.d.ts +8 -0
  153. package/dist/fermi-surface/compute.d.ts +5 -0
  154. package/dist/fermi-surface/compute.js +538 -0
  155. package/dist/fermi-surface/constants.d.ts +9 -0
  156. package/dist/fermi-surface/constants.js +27 -0
  157. package/dist/fermi-surface/export.d.ts +5 -0
  158. package/dist/fermi-surface/export.js +50 -0
  159. package/dist/fermi-surface/index.d.ts +12 -0
  160. package/dist/fermi-surface/index.js +13 -0
  161. package/dist/fermi-surface/marching-cubes.d.ts +2 -0
  162. package/dist/fermi-surface/marching-cubes.js +2 -0
  163. package/dist/fermi-surface/parse.d.ts +2 -0
  164. package/dist/fermi-surface/parse.js +491 -0
  165. package/dist/fermi-surface/symmetry.d.ts +3 -0
  166. package/dist/fermi-surface/symmetry.js +46 -0
  167. package/dist/fermi-surface/types.d.ts +110 -0
  168. package/dist/fermi-surface/types.js +4 -0
  169. package/dist/heatmap-matrix/HeatmapMatrix.svelte +1545 -0
  170. package/dist/heatmap-matrix/HeatmapMatrix.svelte.d.ts +110 -0
  171. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte +225 -0
  172. package/dist/heatmap-matrix/HeatmapMatrixControls.svelte.d.ts +30 -0
  173. package/dist/heatmap-matrix/index.d.ts +53 -0
  174. package/dist/heatmap-matrix/index.js +100 -0
  175. package/dist/heatmap-matrix/shared.d.ts +2 -0
  176. package/dist/heatmap-matrix/shared.js +4 -0
  177. package/dist/icons.d.ts +569 -0
  178. package/dist/icons.js +648 -0
  179. package/dist/index.d.ts +39 -0
  180. package/dist/index.js +39 -0
  181. package/dist/io/decompress.d.ts +11 -0
  182. package/dist/io/decompress.js +74 -0
  183. package/dist/io/export.d.ts +16 -0
  184. package/dist/io/export.js +316 -0
  185. package/dist/io/fetch.d.ts +5 -0
  186. package/dist/io/fetch.js +39 -0
  187. package/dist/io/file-drop.d.ts +7 -0
  188. package/dist/io/file-drop.js +43 -0
  189. package/dist/io/index.d.ts +7 -0
  190. package/dist/io/index.js +6 -0
  191. package/dist/io/is-binary.d.ts +1 -0
  192. package/dist/io/is-binary.js +20 -0
  193. package/dist/io/types.d.ts +8 -0
  194. package/dist/io/types.js +1 -0
  195. package/dist/io/url-drop.d.ts +2 -0
  196. package/dist/io/url-drop.js +123 -0
  197. package/dist/isosurface/Isosurface.svelte +285 -0
  198. package/dist/isosurface/Isosurface.svelte.d.ts +8 -0
  199. package/dist/isosurface/IsosurfaceControls.svelte +277 -0
  200. package/dist/isosurface/IsosurfaceControls.svelte.d.ts +9 -0
  201. package/dist/isosurface/index.d.ts +5 -0
  202. package/dist/isosurface/index.js +6 -0
  203. package/dist/isosurface/parse.d.ts +6 -0
  204. package/dist/isosurface/parse.js +553 -0
  205. package/dist/isosurface/slice.d.ts +11 -0
  206. package/dist/isosurface/slice.js +140 -0
  207. package/dist/isosurface/types.d.ts +56 -0
  208. package/dist/isosurface/types.js +227 -0
  209. package/dist/labels.d.ts +53 -0
  210. package/dist/labels.js +277 -0
  211. package/dist/layout/FullscreenToggle.svelte +50 -0
  212. package/dist/layout/FullscreenToggle.svelte.d.ts +7 -0
  213. package/dist/layout/InfoCard.svelte +120 -0
  214. package/dist/layout/InfoCard.svelte.d.ts +21 -0
  215. package/dist/layout/InfoTag.svelte +185 -0
  216. package/dist/layout/InfoTag.svelte.d.ts +19 -0
  217. package/dist/layout/PropertyFilter.svelte +246 -0
  218. package/dist/layout/PropertyFilter.svelte.d.ts +24 -0
  219. package/dist/layout/SettingsSection.svelte +148 -0
  220. package/dist/layout/SettingsSection.svelte.d.ts +17 -0
  221. package/dist/layout/SubpageGrid.svelte +82 -0
  222. package/dist/layout/SubpageGrid.svelte.d.ts +14 -0
  223. package/dist/layout/fullscreen.d.ts +9 -0
  224. package/dist/layout/fullscreen.js +53 -0
  225. package/dist/layout/index.d.ts +10 -0
  226. package/dist/layout/index.js +8 -0
  227. package/dist/layout/json-tree/JsonNode.svelte +548 -0
  228. package/dist/layout/json-tree/JsonNode.svelte.d.ts +11 -0
  229. package/dist/layout/json-tree/JsonTree.svelte +1230 -0
  230. package/dist/layout/json-tree/JsonTree.svelte.d.ts +6 -0
  231. package/dist/layout/json-tree/JsonValue.svelte.d.ts +9 -0
  232. package/dist/layout/json-tree/index.d.ts +3 -0
  233. package/dist/layout/json-tree/index.js +3 -0
  234. package/dist/layout/json-tree/types.d.ts +74 -0
  235. package/dist/layout/json-tree/types.js +2 -0
  236. package/dist/layout/json-tree/utils.d.ts +29 -0
  237. package/dist/layout/json-tree/utils.js +641 -0
  238. package/dist/marching-cubes.d.ts +14 -0
  239. package/dist/marching-cubes.js +540 -0
  240. package/dist/math.d.ts +101 -0
  241. package/dist/math.js +905 -0
  242. package/dist/overlays/ContextMenu.svelte +162 -0
  243. package/dist/overlays/ContextMenu.svelte.d.ts +25 -0
  244. package/dist/overlays/CopyButton.svelte +45 -0
  245. package/dist/overlays/CopyButton.svelte.d.ts +8 -0
  246. package/dist/overlays/DragControlTab.svelte +98 -0
  247. package/dist/overlays/DragControlTab.svelte.d.ts +8 -0
  248. package/dist/overlays/DraggablePane.svelte +487 -0
  249. package/dist/overlays/DraggablePane.svelte.d.ts +36 -0
  250. package/dist/overlays/InfoPaneCards.svelte +149 -0
  251. package/dist/overlays/InfoPaneCards.svelte.d.ts +22 -0
  252. package/dist/overlays/index.d.ts +3 -0
  253. package/dist/overlays/index.js +3 -0
  254. package/dist/periodic-table/PeriodicTable.svelte +469 -0
  255. package/dist/periodic-table/PeriodicTable.svelte.d.ts +55 -0
  256. package/dist/periodic-table/PeriodicTableControls.svelte +557 -0
  257. package/dist/periodic-table/PeriodicTableControls.svelte.d.ts +24 -0
  258. package/dist/periodic-table/PropertySelect.svelte +37 -0
  259. package/dist/periodic-table/PropertySelect.svelte.d.ts +13 -0
  260. package/dist/periodic-table/TableInset.svelte.d.ts +9 -0
  261. package/dist/periodic-table/index.d.ts +10 -0
  262. package/dist/periodic-table/index.js +4 -0
  263. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +1086 -0
  264. package/dist/phase-diagram/IsobaricBinaryPhaseDiagram.svelte.d.ts +44 -0
  265. package/dist/phase-diagram/PhaseDiagramControls.svelte +444 -0
  266. package/dist/phase-diagram/PhaseDiagramControls.svelte.d.ts +30 -0
  267. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte +126 -0
  268. package/dist/phase-diagram/PhaseDiagramEditorPane.svelte.d.ts +15 -0
  269. package/dist/phase-diagram/PhaseDiagramExportPane.svelte +184 -0
  270. package/dist/phase-diagram/PhaseDiagramExportPane.svelte.d.ts +19 -0
  271. package/dist/phase-diagram/PhaseDiagramTooltip.svelte +391 -0
  272. package/dist/phase-diagram/PhaseDiagramTooltip.svelte.d.ts +16 -0
  273. package/dist/phase-diagram/TdbInfoPanel.svelte +203 -0
  274. package/dist/phase-diagram/TdbInfoPanel.svelte.d.ts +12 -0
  275. package/dist/phase-diagram/build-diagram.d.ts +11 -0
  276. package/dist/phase-diagram/build-diagram.js +160 -0
  277. package/dist/phase-diagram/colors.d.ts +35 -0
  278. package/dist/phase-diagram/colors.js +51 -0
  279. package/dist/phase-diagram/diagram-input.d.ts +29 -0
  280. package/dist/phase-diagram/diagram-input.js +3 -0
  281. package/dist/phase-diagram/index.d.ts +13 -0
  282. package/dist/phase-diagram/index.js +11 -0
  283. package/dist/phase-diagram/parse.d.ts +55 -0
  284. package/dist/phase-diagram/parse.js +272 -0
  285. package/dist/phase-diagram/svg-to-diagram.d.ts +2 -0
  286. package/dist/phase-diagram/svg-to-diagram.js +867 -0
  287. package/dist/phase-diagram/types.d.ts +93 -0
  288. package/dist/phase-diagram/types.js +1 -0
  289. package/dist/phase-diagram/utils.d.ts +118 -0
  290. package/dist/phase-diagram/utils.js +604 -0
  291. package/dist/plot/AxisLabel.svelte +51 -0
  292. package/dist/plot/AxisLabel.svelte.d.ts +16 -0
  293. package/dist/plot/BarPlot.svelte +2113 -0
  294. package/dist/plot/BarPlot.svelte.d.ts +84 -0
  295. package/dist/plot/BarPlotControls.svelte +66 -0
  296. package/dist/plot/BarPlotControls.svelte.d.ts +18 -0
  297. package/dist/plot/BinnedScatterPlot.svelte +1114 -0
  298. package/dist/plot/BinnedScatterPlot.svelte.d.ts +66 -0
  299. package/dist/plot/ColorBar.svelte +721 -0
  300. package/dist/plot/ColorBar.svelte.d.ts +31 -0
  301. package/dist/plot/ColorScaleSelect.svelte +54 -0
  302. package/dist/plot/ColorScaleSelect.svelte.d.ts +15 -0
  303. package/dist/plot/ElementScatter.svelte +63 -0
  304. package/dist/plot/ElementScatter.svelte.d.ts +14 -0
  305. package/dist/plot/FillArea.svelte.d.ts +21 -0
  306. package/dist/plot/Histogram.svelte +1558 -0
  307. package/dist/plot/Histogram.svelte.d.ts +50 -0
  308. package/dist/plot/HistogramControls.svelte +212 -0
  309. package/dist/plot/HistogramControls.svelte.d.ts +22 -0
  310. package/dist/plot/InteractiveAxisLabel.svelte +96 -0
  311. package/dist/plot/InteractiveAxisLabel.svelte.d.ts +14 -0
  312. package/dist/plot/Line.svelte +84 -0
  313. package/dist/plot/Line.svelte.d.ts +15 -0
  314. package/dist/plot/PlotAxis.svelte +169 -0
  315. package/dist/plot/PlotAxis.svelte.d.ts +24 -0
  316. package/dist/plot/PlotControls.svelte +537 -0
  317. package/dist/plot/PlotControls.svelte.d.ts +4 -0
  318. package/dist/plot/PlotLegend.svelte +569 -0
  319. package/dist/plot/PlotLegend.svelte.d.ts +29 -0
  320. package/dist/plot/PlotTooltip.svelte +67 -0
  321. package/dist/plot/PlotTooltip.svelte.d.ts +17 -0
  322. package/dist/plot/PortalSelect.svelte +253 -0
  323. package/dist/plot/PortalSelect.svelte.d.ts +16 -0
  324. package/dist/plot/ReferenceLine.svelte.d.ts +20 -0
  325. package/dist/plot/ReferenceLine3D.svelte +156 -0
  326. package/dist/plot/ReferenceLine3D.svelte.d.ts +14 -0
  327. package/dist/plot/ReferencePlane.svelte +175 -0
  328. package/dist/plot/ReferencePlane.svelte.d.ts +14 -0
  329. package/dist/plot/ScatterPlot.svelte +2778 -0
  330. package/dist/plot/ScatterPlot.svelte.d.ts +96 -0
  331. package/dist/plot/ScatterPlot3D.svelte +529 -0
  332. package/dist/plot/ScatterPlot3D.svelte.d.ts +95 -0
  333. package/dist/plot/ScatterPlot3DControls.svelte +437 -0
  334. package/dist/plot/ScatterPlot3DControls.svelte.d.ts +20 -0
  335. package/dist/plot/ScatterPlot3DScene.svelte +912 -0
  336. package/dist/plot/ScatterPlot3DScene.svelte.d.ts +74 -0
  337. package/dist/plot/ScatterPlotControls.svelte +306 -0
  338. package/dist/plot/ScatterPlotControls.svelte.d.ts +17 -0
  339. package/dist/plot/ScatterPoint.svelte +182 -0
  340. package/dist/plot/ScatterPoint.svelte.d.ts +22 -0
  341. package/dist/plot/SpacegroupBarPlot.svelte +293 -0
  342. package/dist/plot/SpacegroupBarPlot.svelte.d.ts +9 -0
  343. package/dist/plot/Surface3D.svelte +197 -0
  344. package/dist/plot/Surface3D.svelte.d.ts +13 -0
  345. package/dist/plot/ZeroLines.svelte +97 -0
  346. package/dist/plot/ZeroLines.svelte.d.ts +33 -0
  347. package/dist/plot/ZoomRect.svelte +23 -0
  348. package/dist/plot/ZoomRect.svelte.d.ts +8 -0
  349. package/dist/plot/adaptive-density.d.ts +69 -0
  350. package/dist/plot/adaptive-density.js +191 -0
  351. package/dist/plot/auto-place.d.ts +43 -0
  352. package/dist/plot/auto-place.js +122 -0
  353. package/dist/plot/axis-utils.d.ts +19 -0
  354. package/dist/plot/axis-utils.js +78 -0
  355. package/dist/plot/binned-scatter-types.d.ts +59 -0
  356. package/dist/plot/binned-scatter-types.js +1 -0
  357. package/dist/plot/data-cleaning.d.ts +37 -0
  358. package/dist/plot/data-cleaning.js +855 -0
  359. package/dist/plot/data-transform.d.ts +16 -0
  360. package/dist/plot/data-transform.js +45 -0
  361. package/dist/plot/defaults.d.ts +19 -0
  362. package/dist/plot/defaults.js +9 -0
  363. package/dist/plot/fill-utils.d.ts +46 -0
  364. package/dist/plot/fill-utils.js +322 -0
  365. package/dist/plot/hover-lock.svelte.d.ts +14 -0
  366. package/dist/plot/hover-lock.svelte.js +46 -0
  367. package/dist/plot/index.d.ts +41 -0
  368. package/dist/plot/index.js +39 -0
  369. package/dist/plot/interactions.d.ts +12 -0
  370. package/dist/plot/interactions.js +101 -0
  371. package/dist/plot/layout.d.ts +78 -0
  372. package/dist/plot/layout.js +273 -0
  373. package/dist/plot/reference-line.d.ts +60 -0
  374. package/dist/plot/reference-line.js +314 -0
  375. package/dist/plot/scales.d.ts +48 -0
  376. package/dist/plot/scales.js +481 -0
  377. package/dist/plot/svg.d.ts +1 -0
  378. package/dist/plot/svg.js +11 -0
  379. package/dist/plot/types.d.ts +831 -0
  380. package/dist/plot/types.js +99 -0
  381. package/dist/plot/utils/label-placement.d.ts +68 -0
  382. package/dist/plot/utils/label-placement.js +326 -0
  383. package/dist/plot/utils/series-visibility.d.ts +15 -0
  384. package/dist/plot/utils/series-visibility.js +85 -0
  385. package/dist/plot/utils.d.ts +1 -0
  386. package/dist/plot/utils.js +14 -0
  387. package/dist/rdf/RdfPlot.svelte +247 -0
  388. package/dist/rdf/RdfPlot.svelte.d.ts +27 -0
  389. package/dist/rdf/calc-rdf.d.ts +4 -0
  390. package/dist/rdf/calc-rdf.js +111 -0
  391. package/dist/rdf/index.d.ts +23 -0
  392. package/dist/rdf/index.js +2 -0
  393. package/dist/sanitize.d.ts +6 -0
  394. package/dist/sanitize.js +116 -0
  395. package/dist/settings.d.ts +255 -0
  396. package/dist/settings.js +1132 -0
  397. package/dist/spectral/Bands.svelte +1040 -0
  398. package/dist/spectral/Bands.svelte.d.ts +40 -0
  399. package/dist/spectral/BandsAndDos.svelte +134 -0
  400. package/dist/spectral/BandsAndDos.svelte.d.ts +18 -0
  401. package/dist/spectral/BrillouinBandsDos.svelte +252 -0
  402. package/dist/spectral/BrillouinBandsDos.svelte.d.ts +20 -0
  403. package/dist/spectral/Dos.svelte +697 -0
  404. package/dist/spectral/Dos.svelte.d.ts +29 -0
  405. package/dist/spectral/helpers.d.ts +119 -0
  406. package/dist/spectral/helpers.js +1032 -0
  407. package/dist/spectral/index.d.ts +6 -0
  408. package/dist/spectral/index.js +6 -0
  409. package/dist/spectral/types.d.ts +84 -0
  410. package/dist/spectral/types.js +2 -0
  411. package/dist/state.svelte.d.ts +25 -0
  412. package/dist/state.svelte.js +45 -0
  413. package/dist/structure/Arrow.svelte +72 -0
  414. package/dist/structure/Arrow.svelte.d.ts +15 -0
  415. package/dist/structure/AtomLegend.svelte +815 -0
  416. package/dist/structure/AtomLegend.svelte.d.ts +35 -0
  417. package/dist/structure/Bond.svelte +140 -0
  418. package/dist/structure/Bond.svelte.d.ts +9 -0
  419. package/dist/structure/CanvasTooltip.svelte +33 -0
  420. package/dist/structure/CanvasTooltip.svelte.d.ts +12 -0
  421. package/dist/structure/CellSelect.svelte +349 -0
  422. package/dist/structure/CellSelect.svelte.d.ts +13 -0
  423. package/dist/structure/Cylinder.svelte +45 -0
  424. package/dist/structure/Cylinder.svelte.d.ts +10 -0
  425. package/dist/structure/Lattice.svelte +196 -0
  426. package/dist/structure/Lattice.svelte.d.ts +17 -0
  427. package/dist/structure/Structure.svelte +2248 -0
  428. package/dist/structure/Structure.svelte.d.ts +89 -0
  429. package/dist/structure/StructureControls.svelte +1273 -0
  430. package/dist/structure/StructureControls.svelte.d.ts +31 -0
  431. package/dist/structure/StructureExportPane.svelte +252 -0
  432. package/dist/structure/StructureExportPane.svelte.d.ts +17 -0
  433. package/dist/structure/StructureInfoPane.svelte +737 -0
  434. package/dist/structure/StructureInfoPane.svelte.d.ts +19 -0
  435. package/dist/structure/StructureScene.svelte +2255 -0
  436. package/dist/structure/StructureScene.svelte.d.ts +111 -0
  437. package/dist/structure/atom-properties.d.ts +37 -0
  438. package/dist/structure/atom-properties.js +200 -0
  439. package/dist/structure/bond-order-perception.d.ts +13 -0
  440. package/dist/structure/bond-order-perception.js +384 -0
  441. package/dist/structure/bonding.d.ts +68 -0
  442. package/dist/structure/bonding.js +696 -0
  443. package/dist/structure/export.d.ts +20 -0
  444. package/dist/structure/export.js +727 -0
  445. package/dist/structure/index.d.ts +126 -0
  446. package/dist/structure/index.js +169 -0
  447. package/dist/structure/label-placement.d.ts +14 -0
  448. package/dist/structure/label-placement.js +72 -0
  449. package/dist/structure/measure.d.ts +6 -0
  450. package/dist/structure/measure.js +29 -0
  451. package/dist/structure/parse.d.ts +66 -0
  452. package/dist/structure/parse.js +1392 -0
  453. package/dist/structure/partial-occupancy.d.ts +25 -0
  454. package/dist/structure/partial-occupancy.js +99 -0
  455. package/dist/structure/pbc.d.ts +9 -0
  456. package/dist/structure/pbc.js +123 -0
  457. package/dist/structure/supercell.d.ts +8 -0
  458. package/dist/structure/supercell.js +170 -0
  459. package/dist/structure/validation.d.ts +2 -0
  460. package/dist/structure/validation.js +10 -0
  461. package/dist/symmetry/SymmetryStats.svelte +226 -0
  462. package/dist/symmetry/SymmetryStats.svelte.d.ts +21 -0
  463. package/dist/symmetry/WyckoffTable.svelte +120 -0
  464. package/dist/symmetry/WyckoffTable.svelte.d.ts +11 -0
  465. package/dist/symmetry/cell-transform.d.ts +12 -0
  466. package/dist/symmetry/cell-transform.js +91 -0
  467. package/dist/symmetry/index.d.ts +43 -0
  468. package/dist/symmetry/index.js +228 -0
  469. package/dist/symmetry/spacegroups.d.ts +9 -0
  470. package/dist/symmetry/spacegroups.js +394 -0
  471. package/dist/table/HeatmapTable.svelte +1833 -0
  472. package/dist/table/HeatmapTable.svelte.d.ts +49 -0
  473. package/dist/table/ToggleMenu.svelte +385 -0
  474. package/dist/table/ToggleMenu.svelte.d.ts +11 -0
  475. package/dist/table/index.d.ts +74 -0
  476. package/dist/table/index.js +38 -0
  477. package/dist/theme/ThemeControl.svelte +53 -0
  478. package/dist/theme/ThemeControl.svelte.d.ts +9 -0
  479. package/dist/theme/index.d.ts +29 -0
  480. package/dist/theme/index.js +79 -0
  481. package/dist/time.d.ts +4 -0
  482. package/dist/time.js +70 -0
  483. package/dist/tooltip/TooltipContent.svelte +58 -0
  484. package/dist/tooltip/TooltipContent.svelte.d.ts +31 -0
  485. package/dist/tooltip/index.d.ts +2 -0
  486. package/dist/tooltip/index.js +1 -0
  487. package/dist/tooltip/types.d.ts +8 -0
  488. package/dist/tooltip/types.js +1 -0
  489. package/dist/trajectory/Trajectory.svelte +1545 -0
  490. package/dist/trajectory/Trajectory.svelte.d.ts +77 -0
  491. package/dist/trajectory/TrajectoryError.svelte +128 -0
  492. package/dist/trajectory/TrajectoryError.svelte.d.ts +13 -0
  493. package/dist/trajectory/TrajectoryExportPane.svelte +357 -0
  494. package/dist/trajectory/TrajectoryExportPane.svelte.d.ts +17 -0
  495. package/dist/trajectory/TrajectoryInfoPane.svelte +313 -0
  496. package/dist/trajectory/TrajectoryInfoPane.svelte.d.ts +17 -0
  497. package/dist/trajectory/constants.d.ts +6 -0
  498. package/dist/trajectory/constants.js +7 -0
  499. package/dist/trajectory/extract.d.ts +5 -0
  500. package/dist/trajectory/extract.js +162 -0
  501. package/dist/trajectory/format-detect.d.ts +9 -0
  502. package/dist/trajectory/format-detect.js +76 -0
  503. package/dist/trajectory/frame-reader.d.ts +17 -0
  504. package/dist/trajectory/frame-reader.js +332 -0
  505. package/dist/trajectory/helpers.d.ts +15 -0
  506. package/dist/trajectory/helpers.js +164 -0
  507. package/dist/trajectory/index.d.ts +63 -0
  508. package/dist/trajectory/index.js +126 -0
  509. package/dist/trajectory/parse/ase.d.ts +2 -0
  510. package/dist/trajectory/parse/ase.js +73 -0
  511. package/dist/trajectory/parse/hdf5.d.ts +2 -0
  512. package/dist/trajectory/parse/hdf5.js +127 -0
  513. package/dist/trajectory/parse/index.d.ts +12 -0
  514. package/dist/trajectory/parse/index.js +298 -0
  515. package/dist/trajectory/parse/lammps.d.ts +5 -0
  516. package/dist/trajectory/parse/lammps.js +179 -0
  517. package/dist/trajectory/parse/vasp.d.ts +2 -0
  518. package/dist/trajectory/parse/vasp.js +68 -0
  519. package/dist/trajectory/parse/xyz.d.ts +2 -0
  520. package/dist/trajectory/parse/xyz.js +110 -0
  521. package/dist/trajectory/plotting.d.ts +28 -0
  522. package/dist/trajectory/plotting.js +423 -0
  523. package/dist/trajectory/types.d.ts +11 -0
  524. package/dist/trajectory/types.js +1 -0
  525. package/dist/utils.d.ts +6 -0
  526. package/dist/utils.js +45 -0
  527. package/dist/xrd/XrdPlot.svelte +615 -0
  528. package/dist/xrd/XrdPlot.svelte.d.ts +28 -0
  529. package/dist/xrd/broadening.d.ts +20 -0
  530. package/dist/xrd/broadening.js +97 -0
  531. package/dist/xrd/calc-xrd.d.ts +37 -0
  532. package/dist/xrd/calc-xrd.js +336 -0
  533. package/dist/xrd/index.d.ts +37 -0
  534. package/dist/xrd/index.js +4 -0
  535. package/dist/xrd/parse.d.ts +13 -0
  536. package/dist/xrd/parse.js +749 -0
  537. package/license +1 -1
  538. package/package.json +232 -1457
  539. package/readme.md +98 -171
  540. package/.vscode/launch.json +0 -13
  541. package/.vscodeignore +0 -7
  542. package/dist/assets/STLExporter-BpTH3YHE.js +0 -8
  543. package/dist/assets/browser-DdDecX_W.js +0 -1
  544. package/dist/assets/export-qgn-H9y6.js +0 -2
  545. package/dist/assets/main-DiKYzti2.css +0 -1
  546. package/dist/assets/moyo_wasm_bg-0ocwg7xY.wasm +0 -0
  547. package/dist/extension.js +0 -31293
  548. package/dist/src/lib/FilePicker.svelte +0 -360
  549. package/dist/src/lib/MillerIndexInput.svelte +0 -66
  550. package/dist/src/lib/api/mp.ts +0 -26
  551. package/dist/src/lib/api/optimade.ts +0 -204
  552. package/dist/src/lib/brillouin/BrillouinZone.svelte +0 -549
  553. package/dist/src/lib/brillouin/BrillouinZoneControls.svelte +0 -144
  554. package/dist/src/lib/brillouin/BrillouinZoneExportPane.svelte +0 -146
  555. package/dist/src/lib/brillouin/BrillouinZoneInfoPane.svelte +0 -146
  556. package/dist/src/lib/brillouin/BrillouinZoneScene.svelte +0 -476
  557. package/dist/src/lib/brillouin/BrillouinZoneTooltip.svelte +0 -92
  558. package/dist/src/lib/brillouin/compute.ts +0 -529
  559. package/dist/src/lib/brillouin/index.ts +0 -8
  560. package/dist/src/lib/brillouin/types.ts +0 -51
  561. package/dist/src/lib/chempot-diagram/ChemPotDiagram.svelte +0 -327
  562. package/dist/src/lib/chempot-diagram/ChemPotDiagram2D.svelte +0 -846
  563. package/dist/src/lib/chempot-diagram/ChemPotDiagram3D.svelte +0 -3193
  564. package/dist/src/lib/chempot-diagram/async-compute.svelte.ts +0 -94
  565. package/dist/src/lib/chempot-diagram/chempot-worker.ts +0 -11
  566. package/dist/src/lib/chempot-diagram/color.ts +0 -42
  567. package/dist/src/lib/chempot-diagram/compute.ts +0 -1014
  568. package/dist/src/lib/chempot-diagram/index.ts +0 -6
  569. package/dist/src/lib/chempot-diagram/pointer.ts +0 -56
  570. package/dist/src/lib/chempot-diagram/temperature.ts +0 -77
  571. package/dist/src/lib/chempot-diagram/types.ts +0 -130
  572. package/dist/src/lib/colors/index.ts +0 -249
  573. package/dist/src/lib/composition/BarChart.svelte +0 -297
  574. package/dist/src/lib/composition/BubbleChart.svelte +0 -218
  575. package/dist/src/lib/composition/Composition.svelte +0 -165
  576. package/dist/src/lib/composition/Formula.svelte +0 -268
  577. package/dist/src/lib/composition/FormulaFilter.svelte +0 -1257
  578. package/dist/src/lib/composition/PieChart.svelte +0 -323
  579. package/dist/src/lib/composition/format.ts +0 -155
  580. package/dist/src/lib/composition/index.ts +0 -37
  581. package/dist/src/lib/composition/parse.ts +0 -605
  582. package/dist/src/lib/constants.ts +0 -134
  583. package/dist/src/lib/controls.ts +0 -42
  584. package/dist/src/lib/convex-hull/ConvexHull.svelte +0 -157
  585. package/dist/src/lib/convex-hull/ConvexHull2D.svelte +0 -825
  586. package/dist/src/lib/convex-hull/ConvexHull3D.svelte +0 -1801
  587. package/dist/src/lib/convex-hull/ConvexHull4D.svelte +0 -1398
  588. package/dist/src/lib/convex-hull/ConvexHullControls.svelte +0 -535
  589. package/dist/src/lib/convex-hull/ConvexHullInfoPane.svelte +0 -125
  590. package/dist/src/lib/convex-hull/ConvexHullStats.svelte +0 -929
  591. package/dist/src/lib/convex-hull/ConvexHullTooltip.svelte +0 -131
  592. package/dist/src/lib/convex-hull/GasPressureControls.svelte +0 -247
  593. package/dist/src/lib/convex-hull/StructurePopup.svelte +0 -151
  594. package/dist/src/lib/convex-hull/barycentric-coords.ts +0 -246
  595. package/dist/src/lib/convex-hull/demo-temperature.ts +0 -63
  596. package/dist/src/lib/convex-hull/gas-thermodynamics.ts +0 -405
  597. package/dist/src/lib/convex-hull/helpers.ts +0 -932
  598. package/dist/src/lib/convex-hull/index.ts +0 -202
  599. package/dist/src/lib/convex-hull/thermodynamics.ts +0 -2192
  600. package/dist/src/lib/convex-hull/types.ts +0 -267
  601. package/dist/src/lib/coordination/CoordinationBarPlot.svelte +0 -311
  602. package/dist/src/lib/coordination/calc-coordination.ts +0 -93
  603. package/dist/src/lib/coordination/index.ts +0 -9
  604. package/dist/src/lib/effects.svelte.ts +0 -48
  605. package/dist/src/lib/element/ElementHeading.svelte +0 -26
  606. package/dist/src/lib/element/ElementPhoto.svelte +0 -57
  607. package/dist/src/lib/element/ElementStats.svelte +0 -80
  608. package/dist/src/lib/element/ElementTile.svelte +0 -484
  609. package/dist/src/lib/element/data.ts +0 -14
  610. package/dist/src/lib/element/index.ts +0 -8
  611. package/dist/src/lib/element/types.ts +0 -62
  612. package/dist/src/lib/feedback/ClickFeedback.svelte +0 -58
  613. package/dist/src/lib/feedback/DragOverlay.svelte +0 -42
  614. package/dist/src/lib/feedback/index.ts +0 -4
  615. package/dist/src/lib/fermi-surface/FermiSlice.svelte +0 -189
  616. package/dist/src/lib/fermi-surface/FermiSurface.svelte +0 -600
  617. package/dist/src/lib/fermi-surface/FermiSurfaceControls.svelte +0 -448
  618. package/dist/src/lib/fermi-surface/FermiSurfaceScene.svelte +0 -794
  619. package/dist/src/lib/fermi-surface/FermiSurfaceTooltip.svelte +0 -111
  620. package/dist/src/lib/fermi-surface/compute.ts +0 -728
  621. package/dist/src/lib/fermi-surface/constants.ts +0 -32
  622. package/dist/src/lib/fermi-surface/export.ts +0 -64
  623. package/dist/src/lib/fermi-surface/index.ts +0 -14
  624. package/dist/src/lib/fermi-surface/marching-cubes.ts +0 -3
  625. package/dist/src/lib/fermi-surface/parse.ts +0 -574
  626. package/dist/src/lib/fermi-surface/symmetry.ts +0 -56
  627. package/dist/src/lib/fermi-surface/types.ts +0 -159
  628. package/dist/src/lib/heatmap-matrix/HeatmapMatrix.svelte +0 -1545
  629. package/dist/src/lib/heatmap-matrix/HeatmapMatrixControls.svelte +0 -225
  630. package/dist/src/lib/heatmap-matrix/index.ts +0 -167
  631. package/dist/src/lib/heatmap-matrix/shared.ts +0 -7
  632. package/dist/src/lib/icons.ts +0 -650
  633. package/dist/src/lib/index.ts +0 -61
  634. package/dist/src/lib/io/decompress.ts +0 -92
  635. package/dist/src/lib/io/export.ts +0 -385
  636. package/dist/src/lib/io/fetch.ts +0 -46
  637. package/dist/src/lib/io/file-drop.ts +0 -51
  638. package/dist/src/lib/io/index.ts +0 -7
  639. package/dist/src/lib/io/is-binary.ts +0 -24
  640. package/dist/src/lib/io/types.ts +0 -8
  641. package/dist/src/lib/io/url-drop.ts +0 -141
  642. package/dist/src/lib/isosurface/Isosurface.svelte +0 -285
  643. package/dist/src/lib/isosurface/IsosurfaceControls.svelte +0 -277
  644. package/dist/src/lib/isosurface/index.ts +0 -7
  645. package/dist/src/lib/isosurface/parse.ts +0 -656
  646. package/dist/src/lib/isosurface/slice.ts +0 -175
  647. package/dist/src/lib/isosurface/types.ts +0 -309
  648. package/dist/src/lib/labels.ts +0 -320
  649. package/dist/src/lib/layout/FullscreenToggle.svelte +0 -50
  650. package/dist/src/lib/layout/InfoCard.svelte +0 -120
  651. package/dist/src/lib/layout/InfoTag.svelte +0 -185
  652. package/dist/src/lib/layout/PropertyFilter.svelte +0 -246
  653. package/dist/src/lib/layout/SettingsSection.svelte +0 -148
  654. package/dist/src/lib/layout/SubpageGrid.svelte +0 -82
  655. package/dist/src/lib/layout/fullscreen.ts +0 -65
  656. package/dist/src/lib/layout/index.ts +0 -11
  657. package/dist/src/lib/layout/json-tree/JsonNode.svelte +0 -548
  658. package/dist/src/lib/layout/json-tree/JsonTree.svelte +0 -1230
  659. package/dist/src/lib/layout/json-tree/index.ts +0 -3
  660. package/dist/src/lib/layout/json-tree/types.ts +0 -126
  661. package/dist/src/lib/layout/json-tree/utils.ts +0 -682
  662. package/dist/src/lib/marching-cubes.ts +0 -614
  663. package/dist/src/lib/math.ts +0 -1081
  664. package/dist/src/lib/overlays/ContextMenu.svelte +0 -162
  665. package/dist/src/lib/overlays/CopyButton.svelte +0 -45
  666. package/dist/src/lib/overlays/DragControlTab.svelte +0 -98
  667. package/dist/src/lib/overlays/DraggablePane.svelte +0 -487
  668. package/dist/src/lib/overlays/InfoPaneCards.svelte +0 -149
  669. package/dist/src/lib/overlays/index.ts +0 -3
  670. package/dist/src/lib/periodic-table/PeriodicTable.svelte +0 -469
  671. package/dist/src/lib/periodic-table/PeriodicTableControls.svelte +0 -557
  672. package/dist/src/lib/periodic-table/PropertySelect.svelte +0 -37
  673. package/dist/src/lib/periodic-table/index.ts +0 -12
  674. package/dist/src/lib/phase-diagram/IsobaricBinaryPhaseDiagram.svelte +0 -1086
  675. package/dist/src/lib/phase-diagram/PhaseDiagramControls.svelte +0 -444
  676. package/dist/src/lib/phase-diagram/PhaseDiagramEditorPane.svelte +0 -126
  677. package/dist/src/lib/phase-diagram/PhaseDiagramExportPane.svelte +0 -184
  678. package/dist/src/lib/phase-diagram/PhaseDiagramTooltip.svelte +0 -391
  679. package/dist/src/lib/phase-diagram/TdbInfoPanel.svelte +0 -203
  680. package/dist/src/lib/phase-diagram/build-diagram.ts +0 -186
  681. package/dist/src/lib/phase-diagram/colors.ts +0 -58
  682. package/dist/src/lib/phase-diagram/diagram-input.ts +0 -40
  683. package/dist/src/lib/phase-diagram/index.ts +0 -13
  684. package/dist/src/lib/phase-diagram/parse.ts +0 -348
  685. package/dist/src/lib/phase-diagram/svg-to-diagram.ts +0 -1023
  686. package/dist/src/lib/phase-diagram/types.ts +0 -144
  687. package/dist/src/lib/phase-diagram/utils.ts +0 -775
  688. package/dist/src/lib/plot/AxisLabel.svelte +0 -51
  689. package/dist/src/lib/plot/BarPlot.svelte +0 -2113
  690. package/dist/src/lib/plot/BarPlotControls.svelte +0 -66
  691. package/dist/src/lib/plot/BinnedScatterPlot.svelte +0 -1114
  692. package/dist/src/lib/plot/ColorBar.svelte +0 -721
  693. package/dist/src/lib/plot/ColorScaleSelect.svelte +0 -54
  694. package/dist/src/lib/plot/ElementScatter.svelte +0 -63
  695. package/dist/src/lib/plot/Histogram.svelte +0 -1558
  696. package/dist/src/lib/plot/HistogramControls.svelte +0 -212
  697. package/dist/src/lib/plot/InteractiveAxisLabel.svelte +0 -96
  698. package/dist/src/lib/plot/Line.svelte +0 -84
  699. package/dist/src/lib/plot/PlotAxis.svelte +0 -169
  700. package/dist/src/lib/plot/PlotControls.svelte +0 -537
  701. package/dist/src/lib/plot/PlotLegend.svelte +0 -569
  702. package/dist/src/lib/plot/PlotTooltip.svelte +0 -67
  703. package/dist/src/lib/plot/PortalSelect.svelte +0 -253
  704. package/dist/src/lib/plot/ReferenceLine3D.svelte +0 -156
  705. package/dist/src/lib/plot/ReferencePlane.svelte +0 -175
  706. package/dist/src/lib/plot/ScatterPlot.svelte +0 -2778
  707. package/dist/src/lib/plot/ScatterPlot3D.svelte +0 -529
  708. package/dist/src/lib/plot/ScatterPlot3DControls.svelte +0 -437
  709. package/dist/src/lib/plot/ScatterPlot3DScene.svelte +0 -912
  710. package/dist/src/lib/plot/ScatterPlotControls.svelte +0 -306
  711. package/dist/src/lib/plot/ScatterPoint.svelte +0 -182
  712. package/dist/src/lib/plot/SpacegroupBarPlot.svelte +0 -293
  713. package/dist/src/lib/plot/Surface3D.svelte +0 -197
  714. package/dist/src/lib/plot/ZeroLines.svelte +0 -97
  715. package/dist/src/lib/plot/ZoomRect.svelte +0 -23
  716. package/dist/src/lib/plot/adaptive-density.ts +0 -316
  717. package/dist/src/lib/plot/auto-place.ts +0 -184
  718. package/dist/src/lib/plot/axis-utils.ts +0 -122
  719. package/dist/src/lib/plot/binned-scatter-types.ts +0 -83
  720. package/dist/src/lib/plot/data-cleaning.ts +0 -1069
  721. package/dist/src/lib/plot/data-transform.ts +0 -69
  722. package/dist/src/lib/plot/defaults.ts +0 -9
  723. package/dist/src/lib/plot/fill-utils.ts +0 -494
  724. package/dist/src/lib/plot/hover-lock.svelte.ts +0 -60
  725. package/dist/src/lib/plot/index.ts +0 -53
  726. package/dist/src/lib/plot/interactions.ts +0 -119
  727. package/dist/src/lib/plot/layout.ts +0 -425
  728. package/dist/src/lib/plot/reference-line.ts +0 -426
  729. package/dist/src/lib/plot/scales.ts +0 -654
  730. package/dist/src/lib/plot/svg.ts +0 -23
  731. package/dist/src/lib/plot/types.ts +0 -1144
  732. package/dist/src/lib/plot/utils/label-placement.ts +0 -541
  733. package/dist/src/lib/plot/utils/series-visibility.ts +0 -140
  734. package/dist/src/lib/plot/utils.ts +0 -11
  735. package/dist/src/lib/rdf/RdfPlot.svelte +0 -247
  736. package/dist/src/lib/rdf/calc-rdf.ts +0 -167
  737. package/dist/src/lib/rdf/index.ts +0 -27
  738. package/dist/src/lib/sanitize.ts +0 -126
  739. package/dist/src/lib/settings.ts +0 -1479
  740. package/dist/src/lib/spectral/Bands.svelte +0 -1040
  741. package/dist/src/lib/spectral/BandsAndDos.svelte +0 -134
  742. package/dist/src/lib/spectral/BrillouinBandsDos.svelte +0 -252
  743. package/dist/src/lib/spectral/Dos.svelte +0 -697
  744. package/dist/src/lib/spectral/helpers.ts +0 -1381
  745. package/dist/src/lib/spectral/index.ts +0 -8
  746. package/dist/src/lib/spectral/types.ts +0 -112
  747. package/dist/src/lib/state.svelte.ts +0 -64
  748. package/dist/src/lib/structure/Arrow.svelte +0 -72
  749. package/dist/src/lib/structure/AtomLegend.svelte +0 -815
  750. package/dist/src/lib/structure/Bond.svelte +0 -140
  751. package/dist/src/lib/structure/CanvasTooltip.svelte +0 -33
  752. package/dist/src/lib/structure/CellSelect.svelte +0 -349
  753. package/dist/src/lib/structure/Cylinder.svelte +0 -45
  754. package/dist/src/lib/structure/Lattice.svelte +0 -196
  755. package/dist/src/lib/structure/Structure.svelte +0 -2248
  756. package/dist/src/lib/structure/StructureControls.svelte +0 -1273
  757. package/dist/src/lib/structure/StructureExportPane.svelte +0 -252
  758. package/dist/src/lib/structure/StructureInfoPane.svelte +0 -737
  759. package/dist/src/lib/structure/StructureScene.svelte +0 -2255
  760. package/dist/src/lib/structure/atom-properties.ts +0 -316
  761. package/dist/src/lib/structure/bond-order-perception.ts +0 -447
  762. package/dist/src/lib/structure/bonding.ts +0 -944
  763. package/dist/src/lib/structure/export.ts +0 -861
  764. package/dist/src/lib/structure/index.ts +0 -291
  765. package/dist/src/lib/structure/label-placement.ts +0 -130
  766. package/dist/src/lib/structure/measure.ts +0 -45
  767. package/dist/src/lib/structure/parse.ts +0 -1705
  768. package/dist/src/lib/structure/partial-occupancy.ts +0 -183
  769. package/dist/src/lib/structure/pbc.ts +0 -164
  770. package/dist/src/lib/structure/supercell.ts +0 -226
  771. package/dist/src/lib/structure/validation.ts +0 -11
  772. package/dist/src/lib/symmetry/SymmetryStats.svelte +0 -226
  773. package/dist/src/lib/symmetry/WyckoffTable.svelte +0 -120
  774. package/dist/src/lib/symmetry/cell-transform.ts +0 -118
  775. package/dist/src/lib/symmetry/index.ts +0 -348
  776. package/dist/src/lib/symmetry/spacegroups.ts +0 -404
  777. package/dist/src/lib/table/HeatmapTable.svelte +0 -1833
  778. package/dist/src/lib/table/ToggleMenu.svelte +0 -385
  779. package/dist/src/lib/table/index.ts +0 -139
  780. package/dist/src/lib/theme/ThemeControl.svelte +0 -53
  781. package/dist/src/lib/theme/index.ts +0 -107
  782. package/dist/src/lib/time.ts +0 -71
  783. package/dist/src/lib/tooltip/TooltipContent.svelte +0 -58
  784. package/dist/src/lib/tooltip/index.ts +0 -2
  785. package/dist/src/lib/tooltip/types.ts +0 -13
  786. package/dist/src/lib/trajectory/Trajectory.svelte +0 -1545
  787. package/dist/src/lib/trajectory/TrajectoryError.svelte +0 -128
  788. package/dist/src/lib/trajectory/TrajectoryExportPane.svelte +0 -357
  789. package/dist/src/lib/trajectory/TrajectoryInfoPane.svelte +0 -313
  790. package/dist/src/lib/trajectory/constants.ts +0 -7
  791. package/dist/src/lib/trajectory/extract.ts +0 -196
  792. package/dist/src/lib/trajectory/format-detect.ts +0 -96
  793. package/dist/src/lib/trajectory/frame-reader.ts +0 -456
  794. package/dist/src/lib/trajectory/helpers.ts +0 -217
  795. package/dist/src/lib/trajectory/index.ts +0 -218
  796. package/dist/src/lib/trajectory/parse/ase.ts +0 -109
  797. package/dist/src/lib/trajectory/parse/hdf5.ts +0 -173
  798. package/dist/src/lib/trajectory/parse/index.ts +0 -411
  799. package/dist/src/lib/trajectory/parse/lammps.ts +0 -215
  800. package/dist/src/lib/trajectory/parse/vasp.ts +0 -102
  801. package/dist/src/lib/trajectory/parse/xyz.ts +0 -143
  802. package/dist/src/lib/trajectory/plotting.ts +0 -599
  803. package/dist/src/lib/trajectory/types.ts +0 -13
  804. package/dist/src/lib/utils.ts +0 -56
  805. package/dist/src/lib/xrd/XrdPlot.svelte +0 -615
  806. package/dist/src/lib/xrd/broadening.ts +0 -130
  807. package/dist/src/lib/xrd/calc-xrd.ts +0 -397
  808. package/dist/src/lib/xrd/index.ts +0 -38
  809. package/dist/src/lib/xrd/parse.ts +0 -858
  810. package/dist/webview.js +0 -29421
  811. package/icon.png +0 -0
  812. package/matterviz-0.3.2.vsix +0 -0
  813. package/matterviz-0.3.4.vsix +0 -0
  814. package/matterviz-0.3.5.vsix +0 -0
  815. package/scripts/sync-config.ts +0 -101
  816. package/src/declarations.d.ts +0 -2
  817. package/src/extension.ts +0 -972
  818. package/src/node-io.ts +0 -65
  819. package/src/types.ts +0 -17
  820. package/src/webview/JsonBrowser.svelte +0 -1079
  821. package/src/webview/PlotPanel.svelte +0 -346
  822. package/src/webview/detect.ts +0 -444
  823. package/src/webview/main.ts +0 -764
  824. package/src/webview/plot-utils.ts +0 -250
  825. package/test-fixtures/all-viz-types.json.gz +0 -0
  826. package/test-fixtures/plot-demo-data.json.gz +0 -0
  827. package/tests/detect.test.ts +0 -604
  828. package/tests/extension.test.ts +0 -2041
  829. package/tests/node-io.test.ts +0 -39
  830. package/tests/plot-utils.test.ts +0 -302
  831. package/tests/vite-plugin-json-gz.test.ts +0 -114
  832. package/tests/vscode-mock.ts +0 -18
  833. package/tests/webview.test.ts +0 -231
  834. package/tsconfig.json +0 -20
  835. package/vite-plugin-json-gz.ts +0 -29
  836. package/vite.config.ts +0 -34
  837. package/vite.extension.config.ts +0 -34
  838. /package/dist/{src/lib/EmptyState.svelte → EmptyState.svelte} +0 -0
  839. /package/dist/{src/lib/Icon.svelte → Icon.svelte} +0 -0
  840. /package/dist/{src/lib/app.css → app.css} +0 -0
  841. /package/dist/{src/lib/chempot-diagram → chempot-diagram}/ChemPotScene3D.svelte +0 -0
  842. /package/dist/{src/lib/colors → colors}/alloy-colors.json +0 -0
  843. /package/dist/{src/lib/colors → colors}/dark-mode-colors.json +0 -0
  844. /package/dist/{src/lib/colors → colors}/jmol-colors.json +0 -0
  845. /package/dist/{src/lib/colors → colors}/muted-colors.json +0 -0
  846. /package/dist/{src/lib/colors → colors}/pastel-colors.json +0 -0
  847. /package/dist/{src/lib/colors → colors}/vesta-colors.json +0 -0
  848. /package/dist/{src/lib/convex-hull → convex-hull}/TemperatureSlider.svelte +0 -0
  849. /package/dist/{src/lib/element → element}/BohrAtom.svelte +0 -0
  850. /package/dist/{src/lib/element → element}/Nucleus.svelte +0 -0
  851. /package/dist/{src/lib/element → element}/data.json +0 -0
  852. /package/dist/{src/lib/element → element}/data.json.gz +0 -0
  853. /package/dist/{src/lib/element → element}/data.json.gz.d.ts +0 -0
  854. /package/dist/{src/lib/element → element}/data.schema.json +0 -0
  855. /package/dist/{src/lib/element-image-urls.json → element-image-urls.json} +0 -0
  856. /package/dist/{src/lib/feedback → feedback}/Spinner.svelte +0 -0
  857. /package/dist/{src/lib/feedback → feedback}/StatusMessage.svelte +0 -0
  858. /package/dist/{src/lib/layout → layout}/json-tree/JsonValue.svelte +0 -0
  859. /package/dist/{src/lib/periodic-table → periodic-table}/TableInset.svelte +0 -0
  860. /package/dist/{src/lib/plot → plot}/FillArea.svelte +0 -0
  861. /package/dist/{src/lib/plot → plot}/ReferenceLine.svelte +0 -0
  862. /package/dist/{src/lib/theme → theme}/themes.mjs +0 -0
  863. /package/dist/{src/lib/xrd → xrd}/atomic_scattering_params.json +0 -0
@@ -1,1705 +0,0 @@
1
- import type { OptimadeStructure } from '$lib/api/optimade'
2
- import {
3
- COMPRESSION_EXTENSIONS_REGEX,
4
- CONFIG_DIRS_REGEX,
5
- STRUCT_KEYWORDS_REGEX,
6
- STRUCT_KEYWORDS_STRICT_REGEX,
7
- STRUCTURE_EXTENSIONS_REGEX,
8
- TRAJ_KEYWORDS_REGEX,
9
- VASP_FILES_REGEX,
10
- XYZ_EXTXYZ_REGEX,
11
- } from '$lib/constants'
12
- import type { ElementSymbol } from '$lib/element'
13
- import { ELEM_SYMBOLS } from '$lib/labels'
14
- import type { Vec3 } from '$lib/math'
15
- import * as math from '$lib/math'
16
- import type { AnyStructure, Crystal, Site, StructureProperties } from '$lib/structure'
17
- import type { Pbc } from '$lib/structure/pbc'
18
- import { wrap_to_unit_cell } from '$lib/structure/pbc'
19
- import { normalize_scientific_notation } from '$lib/utils'
20
- import { load as yaml_load } from 'js-yaml'
21
-
22
- export interface ParsedStructure {
23
- sites: Site[]
24
- properties?: StructureProperties
25
- lattice?: {
26
- matrix: math.Matrix3x3
27
- a: number
28
- b: number
29
- c: number
30
- alpha: number
31
- beta: number
32
- gamma: number
33
- volume: number
34
- pbc?: Pbc
35
- }
36
- }
37
-
38
- const cif_coords_key = (coords: Vec3): string =>
39
- `${coords[0].toFixed(6)},${coords[1].toFixed(6)},${coords[2].toFixed(6)}`
40
- const cif_site_key = (element: string, abc: Vec3, label: string): string =>
41
- `${element}|${label}|${cif_coords_key(abc)}`
42
- const clone_structure_properties = (properties: StructureProperties): StructureProperties =>
43
- structuredClone(properties)
44
- const FALLBACK_ELEMENTS = [`H`, `He`, `Li`, `Be`, `B`, `C`, `N`, `O`, `F`, `Ne`] as const
45
- const is_known_element_symbol = (symbol: string): symbol is ElementSymbol =>
46
- (ELEM_SYMBOLS as readonly string[]).includes(symbol)
47
- const vec3_from_values = (values: readonly unknown[] | undefined, context: string): Vec3 => {
48
- if (values?.length !== 3) {
49
- throw new Error(`Invalid ${context}: expected 3 coordinates, got ${values?.length ?? 0}`)
50
- }
51
- const coords = math.finite_vec3_from_values(values)
52
- if (coords) return coords
53
- for (let idx = 0; idx < 3; idx++) {
54
- const value = values[idx]
55
- if (typeof value !== `number` || !Number.isFinite(value)) {
56
- throw new TypeError(
57
- `Invalid ${context}: coordinate ${idx} must be finite, got ${String(value)}`,
58
- )
59
- }
60
- }
61
- throw new Error(`Invalid ${context}: expected 3 finite coordinates`)
62
- }
63
-
64
- export interface PhonopyCell {
65
- lattice: number[][]
66
- points: {
67
- symbol: string
68
- coordinates: number[]
69
- mass: number
70
- reduced_to?: number
71
- }[]
72
- reciprocal_lattice?: number[][]
73
- }
74
-
75
- export interface PhonopyData {
76
- phono3py?: {
77
- version: string
78
- [key: string]: unknown
79
- }
80
- phonopy?: {
81
- version: string
82
- [key: string]: unknown
83
- }
84
- space_group?: {
85
- type: string
86
- number: number
87
- Hall_symbol: string
88
- }
89
- primitive_cell?: PhonopyCell
90
- unit_cell?: PhonopyCell
91
- supercell?: PhonopyCell
92
- phonon_primitive_cell?: PhonopyCell
93
- phonon_supercell?: PhonopyCell
94
- phonon_displacements?: unknown[] // Ignored for performance
95
- [key: string]: unknown
96
- }
97
-
98
- // Parse a coordinate value that might be in various scientific notation formats
99
- function parse_coordinate(str: string): number {
100
- const normalized = normalize_scientific_notation(str.trim())
101
- const value = parseFloat(normalized)
102
- if (isNaN(value)) throw new Error(`Invalid coordinate value: ${str}`)
103
- return value
104
- }
105
-
106
- // Parse coordinates from a line, handling malformed formatting
107
- function parse_coordinate_line(line: string): number[] {
108
- let tokens = line.trim().split(/\s+/)
109
-
110
- // Handle malformed coordinates like "1.0-2.0-3.0" (missing spaces)
111
- if (tokens.length < 3) {
112
- // Insert a space only for subtraction between numbers, not exponent signs (e/E)
113
- const sanitized = line
114
- .trim()
115
- // Add space when '-' follows a digit and precedes a digit or dot
116
- .replace(/(\d)-(?=[\d.])/g, `$1 -`)
117
- // Revert accidental spaces after exponent markers
118
- .replace(/([eE])\s-\s/g, `$1-`)
119
- tokens = sanitized.split(/\s+/)
120
- }
121
-
122
- if (tokens.length < 3) throw new Error(`Insufficient coordinates in line: ${line}`)
123
-
124
- return tokens.slice(0, 3).map(parse_coordinate)
125
- }
126
-
127
- // Validate element symbol and provide fallback
128
- function validate_element_symbol(symbol: string, index: number): ElementSymbol {
129
- // Clean symbol (remove suffixes like _pv, /hash)
130
- const clean_symbol = symbol.split(/[_/]/)[0]
131
-
132
- if (is_known_element_symbol(clean_symbol)) return clean_symbol
133
-
134
- // Fallback to default elements by atomic number
135
- const fallback = FALLBACK_ELEMENTS[index % FALLBACK_ELEMENTS.length] ?? `H`
136
- console.warn(`Invalid element symbol '${symbol}', using fallback '${fallback}'`)
137
- return fallback
138
- }
139
-
140
- const try_create_cart_to_frac = (
141
- lattice_matrix: math.Matrix3x3,
142
- ): ((v: Vec3) => Vec3) | null => {
143
- try {
144
- return math.create_cart_to_frac(lattice_matrix)
145
- } catch {
146
- return null
147
- }
148
- }
149
-
150
- const approximate_cart_to_frac = (xyz: Vec3, axis_lengths: Vec3): Vec3 => [
151
- Math.abs(axis_lengths[0]) > math.EPS ? xyz[0] / axis_lengths[0] : 0,
152
- Math.abs(axis_lengths[1]) > math.EPS ? xyz[1] / axis_lengths[1] : 0,
153
- Math.abs(axis_lengths[2]) > math.EPS ? xyz[2] / axis_lengths[2] : 0,
154
- ]
155
-
156
- // Parse VASP POSCAR file format
157
- export function parse_poscar(content: string): ParsedStructure | null {
158
- try {
159
- const lines = content.replace(/^\s+/, ``).split(/\r?\n/)
160
-
161
- if (lines.length < 8) {
162
- console.error(`POSCAR file too short`)
163
- return null
164
- }
165
-
166
- // Parse scaling factor (line 2)
167
- let scale_factor = parseFloat(lines[1])
168
- if (isNaN(scale_factor)) {
169
- console.error(`Invalid scaling factor in POSCAR`)
170
- return null
171
- }
172
-
173
- // Parse lattice vectors (lines 3-5)
174
- const parse_vector = (line: string, line_num: number): Vec3 => {
175
- const coords = line.trim().split(/\s+/).map(parse_coordinate)
176
- return vec3_from_values(coords, `lattice vector on line ${line_num}`)
177
- }
178
-
179
- const lattice_vecs: math.Matrix3x3 = [
180
- parse_vector(lines[2], 3),
181
- parse_vector(lines[3], 4),
182
- parse_vector(lines[4], 5),
183
- ]
184
-
185
- // Handle negative scale factor (volume-based scaling)
186
- if (scale_factor < 0) {
187
- const volume = Math.abs(math.det_3x3(lattice_vecs))
188
- scale_factor = Math.pow(-scale_factor / volume, 1 / 3)
189
- }
190
-
191
- // Scale lattice vectors
192
- const scaled_lattice: math.Matrix3x3 = [
193
- math.scale(lattice_vecs[0], scale_factor),
194
- math.scale(lattice_vecs[1], scale_factor),
195
- math.scale(lattice_vecs[2], scale_factor),
196
- ]
197
-
198
- // Parse element symbols and atom counts (may span multiple lines)
199
- let line_index = 5
200
- let element_symbols: string[] = []
201
- let atom_counts: number[] = []
202
-
203
- // Detect if this is VASP 5+ format (has element symbols)
204
- // Try to parse the first token as a number - if it succeeds, it's VASP 4 format
205
- const first_token = lines[line_index].trim().split(/\s+/)[0]
206
- const first_token_as_number = parseInt(first_token)
207
- const has_element_symbols = isNaN(first_token_as_number)
208
-
209
- if (has_element_symbols) {
210
- // VASP 5+ format - parse element symbols (may span multiple lines)
211
- let symbol_lines = 1
212
-
213
- // Look ahead to find where numbers start (atom counts)
214
- for (let lookahead_idx = 1; lookahead_idx < 10; lookahead_idx++) {
215
- if (line_index + lookahead_idx >= lines.length) break
216
- const next_line_first_token = lines[line_index + lookahead_idx].trim().split(/\s+/)[0]
217
- const next_token_as_number = parseInt(next_line_first_token)
218
- if (!isNaN(next_token_as_number)) {
219
- symbol_lines = lookahead_idx
220
- break
221
- }
222
- }
223
-
224
- // Collect all element symbols from the symbol lines
225
- for (let symbol_line_idx = 0; symbol_line_idx < symbol_lines; symbol_line_idx++) {
226
- if (line_index + symbol_line_idx < lines.length) {
227
- element_symbols.push(...lines[line_index + symbol_line_idx].trim().split(/\s+/))
228
- }
229
- }
230
-
231
- // Parse atom counts (may span multiple lines)
232
- for (let count_line_idx = 0; count_line_idx < symbol_lines; count_line_idx++) {
233
- if (line_index + symbol_lines + count_line_idx < lines.length) {
234
- const counts = lines[line_index + symbol_lines + count_line_idx]
235
- .trim()
236
- .split(/\s+/)
237
- .map(Number)
238
- atom_counts.push(...counts)
239
- }
240
- }
241
-
242
- line_index += 2 * symbol_lines
243
- } else {
244
- // VASP 4 format - only atom counts, generate default element symbols
245
- atom_counts = lines[line_index].trim().split(/\s+/).map(Number)
246
- element_symbols = atom_counts.map((_, idx) =>
247
- validate_element_symbol(`Element${idx}`, idx),
248
- )
249
- line_index += 1
250
- }
251
-
252
- if (element_symbols.length !== atom_counts.length) {
253
- console.error(`Mismatch between element symbols and atom counts`)
254
- return null
255
- }
256
-
257
- // Check for selective dynamics
258
- let has_selective_dynamics = false
259
- if (line_index < lines.length) {
260
- let coordinate_mode = lines[line_index].trim().toUpperCase()
261
-
262
- if (coordinate_mode.startsWith(`S`)) {
263
- has_selective_dynamics = true
264
- line_index += 1
265
- if (line_index < lines.length) {
266
- coordinate_mode = lines[line_index].trim().toUpperCase()
267
- } else {
268
- console.error(`Missing coordinate mode after selective dynamics`)
269
- return null
270
- }
271
- }
272
-
273
- // Determine coordinate mode
274
- const is_direct = coordinate_mode.startsWith(`D`)
275
- const is_cartesian = coordinate_mode.startsWith(`C`) || coordinate_mode.startsWith(`K`)
276
-
277
- if (!is_direct && !is_cartesian) {
278
- console.error(`Unknown coordinate mode in POSCAR: ${coordinate_mode}`)
279
- return null
280
- }
281
-
282
- // Parse atomic positions
283
- const poscar_axis_lengths: Vec3 = [
284
- Math.hypot(...scaled_lattice[0]),
285
- Math.hypot(...scaled_lattice[1]),
286
- Math.hypot(...scaled_lattice[2]),
287
- ]
288
- const poscar_frac_to_cart = math.create_frac_to_cart(scaled_lattice)
289
- const poscar_cart_to_frac = try_create_cart_to_frac(scaled_lattice)
290
- if (!is_direct && !poscar_cart_to_frac) {
291
- console.warn(`POSCAR: singular lattice, using axis-length fallback for cart→frac`)
292
- }
293
- const sites: Site[] = []
294
- let atom_index = 0
295
-
296
- for (let elem_idx = 0; elem_idx < element_symbols.length; elem_idx++) {
297
- const element = validate_element_symbol(element_symbols[elem_idx], elem_idx)
298
- const count = atom_counts[elem_idx]
299
-
300
- for (let atom_count_idx = 0; atom_count_idx < count; atom_count_idx++) {
301
- const coord_line_idx = line_index + 1 + atom_index + atom_count_idx
302
- if (coord_line_idx >= lines.length) {
303
- console.error(`Not enough coordinate lines in POSCAR`)
304
- return null
305
- }
306
-
307
- const coords = vec3_from_values(
308
- parse_coordinate_line(lines[coord_line_idx]),
309
- `POSCAR atom coordinates on line ${coord_line_idx + 1}`,
310
- )
311
-
312
- // Parse selective dynamics if present
313
- let selective_dynamics: [boolean, boolean, boolean] | undefined
314
- if (has_selective_dynamics) {
315
- const tokens = lines[coord_line_idx].trim().split(/\s+/)
316
- if (tokens.length >= 6) {
317
- selective_dynamics = [tokens[3] === `T`, tokens[4] === `T`, tokens[5] === `T`]
318
- }
319
- }
320
- let xyz: Vec3
321
- let abc: Vec3
322
-
323
- if (is_direct) {
324
- // Store fractional coordinates, wrapping to [0, 1) range
325
- abc = wrap_to_unit_cell(coords)
326
- xyz = poscar_frac_to_cart(abc)
327
- } else {
328
- // Already Cartesian, scale if needed
329
- xyz = math.scale(coords, scale_factor)
330
- const raw_abc = poscar_cart_to_frac
331
- ? poscar_cart_to_frac(xyz)
332
- : approximate_cart_to_frac(xyz, poscar_axis_lengths)
333
- // Wrap fractional coordinates to [0, 1) range
334
- abc = wrap_to_unit_cell(raw_abc)
335
- }
336
-
337
- const site: Site = {
338
- species: [{ element, occu: 1, oxidation_state: 0 }],
339
- abc,
340
- xyz,
341
- label: `${element}${atom_index + atom_count_idx + 1}`,
342
- properties: selective_dynamics ? { selective_dynamics: selective_dynamics } : {},
343
- }
344
-
345
- sites.push(site)
346
- }
347
-
348
- atom_index += count
349
- }
350
-
351
- const lattice_params = math.calc_lattice_params(scaled_lattice)
352
- const structure: ParsedStructure = {
353
- sites,
354
- lattice: { matrix: scaled_lattice, ...lattice_params },
355
- }
356
-
357
- return structure
358
- } else {
359
- console.error(`Missing coordinate mode line in POSCAR`)
360
- return null
361
- }
362
- } catch (error) {
363
- console.error(`Error parsing POSCAR file:`, error)
364
- return null
365
- }
366
- }
367
-
368
- // Parse XYZ file format. Supports both standard XYZ and extended XYZ formats with multi-frame support
369
- export function parse_xyz(content: string): ParsedStructure | null {
370
- try {
371
- const normalized_content = content.trim()
372
- if (!normalized_content) {
373
- console.error(`Empty XYZ file`)
374
- return null
375
- }
376
-
377
- // Split into frames by reading the atom count and slicing lines
378
- const all_lines = normalized_content.split(/\r?\n/)
379
- const frames: string[] = []
380
- let frame_line_idx = 0
381
-
382
- while (frame_line_idx < all_lines.length) {
383
- const numAtoms = parseInt(all_lines[frame_line_idx].trim(), 10)
384
- if (
385
- !isNaN(numAtoms) &&
386
- numAtoms > 0 &&
387
- frame_line_idx + numAtoms + 1 < all_lines.length
388
- ) {
389
- const frameLines = all_lines.slice(frame_line_idx, frame_line_idx + numAtoms + 2)
390
- frames.push(frameLines.join(`\n`))
391
- frame_line_idx += numAtoms + 2
392
- } else frame_line_idx++
393
- }
394
-
395
- // If no frames found, try simple parsing
396
- if (frames.length === 0) frames.push(normalized_content)
397
-
398
- // Parse the last frame (or only frame)
399
- const frame_content = frames.at(-1) ?? ``
400
- const lines = frame_content.trim().split(/\r?\n/)
401
-
402
- if (lines.length < 2) {
403
- console.error(`XYZ frame too short`)
404
- return null
405
- }
406
-
407
- // Parse number of atoms (line 1)
408
- const num_atoms = parseInt(lines[0].trim())
409
- if (isNaN(num_atoms) || num_atoms <= 0) {
410
- console.error(`Invalid number of atoms in XYZ file`)
411
- return null
412
- }
413
-
414
- // Parse comment line (line 2) - may contain lattice info for extended XYZ
415
- const comment_line = lines[1]
416
- let lattice: ParsedStructure[`lattice`] | undefined
417
-
418
- // Check for extended XYZ lattice information in comment line
419
- const lattice_match = /Lattice="([^"]+)"/.exec(comment_line)
420
- if (lattice_match) {
421
- const lattice_values = lattice_match[1].split(/\s+/).map(parse_coordinate)
422
- if (lattice_values.length === 9) {
423
- const lattice_vectors: math.Matrix3x3 = [
424
- vec3_from_values(lattice_values.slice(0, 3), `XYZ lattice vector 1`),
425
- vec3_from_values(lattice_values.slice(3, 6), `XYZ lattice vector 2`),
426
- vec3_from_values(lattice_values.slice(6, 9), `XYZ lattice vector 3`),
427
- ]
428
-
429
- const lattice_params = math.calc_lattice_params(lattice_vectors)
430
- lattice = { matrix: lattice_vectors, ...lattice_params }
431
- }
432
- }
433
-
434
- // Parse atomic coordinates (starting from line 3)
435
- const xyz_axis_lengths = lattice ? ([lattice.a, lattice.b, lattice.c] as Vec3) : null
436
- let xyz_frac_to_cart: ((v: Vec3) => Vec3) | null = null
437
- let xyz_cart_to_frac: ((v: Vec3) => Vec3) | null = null
438
- if (lattice) {
439
- xyz_frac_to_cart = math.create_frac_to_cart(lattice.matrix)
440
- xyz_cart_to_frac = try_create_cart_to_frac(lattice.matrix)
441
- }
442
- const sites: Site[] = []
443
-
444
- for (let atom_idx = 0; atom_idx < num_atoms; atom_idx++) {
445
- const line_idx = atom_idx + 2
446
- if (line_idx >= lines.length) {
447
- console.error(`Not enough coordinate lines in XYZ file`)
448
- return null
449
- }
450
-
451
- const parts = lines[line_idx].trim().split(/\s+/)
452
- if (parts.length < 4) {
453
- console.error(`Invalid coordinate line in XYZ file`)
454
- return null
455
- }
456
-
457
- const element = validate_element_symbol(parts[0], atom_idx)
458
- const xyz = vec3_from_values(
459
- parts.slice(1, 4).map(parse_coordinate),
460
- `XYZ atom position ${atom_idx + 1}`,
461
- )
462
-
463
- // Calculate fractional coordinates if lattice is available
464
- let abc: Vec3 = [0, 0, 0]
465
- if (lattice && xyz_frac_to_cart && xyz_axis_lengths) {
466
- abc = xyz_cart_to_frac
467
- ? xyz_cart_to_frac(xyz)
468
- : approximate_cart_to_frac(xyz, xyz_axis_lengths)
469
-
470
- // Ensure fractional coordinates are wrapped into [0, 1) for consistency
471
- abc = wrap_to_unit_cell(abc)
472
-
473
- // Keep rendered atoms inside primary unit cell by recomputing xyz
474
- const wrapped_xyz = xyz_frac_to_cart(abc)
475
- xyz[0] = wrapped_xyz[0]
476
- xyz[1] = wrapped_xyz[1]
477
- xyz[2] = wrapped_xyz[2]
478
- }
479
-
480
- const species = [{ element, occu: 1, oxidation_state: 0 }]
481
- const label = `${element}${atom_idx + 1}`
482
- const site: Site = { species, abc, xyz, label, properties: {} }
483
-
484
- sites.push(site)
485
- }
486
-
487
- const structure: ParsedStructure = { sites, ...(lattice && { lattice }) }
488
-
489
- return structure
490
- } catch (error) {
491
- console.error(`Error parsing XYZ file:`, error)
492
- return null
493
- }
494
- }
495
-
496
- // Parse a single symmetry expression dimension (e.g., "x-y+1/3" or "-x+y")
497
- // Returns the numeric coefficient for each variable and the translation constant
498
- const parse_symmetry_expression = (
499
- expr_input: string,
500
- ): { coefficients: Vec3; translation: number } => {
501
- const coefficients: Vec3 = [0, 0, 0]
502
- let translation = 0
503
-
504
- // Remove all whitespace
505
- const expr = expr_input.replace(/\s+/g, ``)
506
- if (!expr) return { coefficients, translation }
507
-
508
- // Tokenize: split into terms while preserving signs
509
- // E.g., "x-y+1/3" → ["x", "-y", "+1/3"] or "-x+y" → ["-x", "+y"]
510
- const tokens: string[] = []
511
- let current_token = ``
512
-
513
- for (let idx = 0; idx < expr.length; idx++) {
514
- const char = expr[idx]
515
- if ((char === `+` || char === `-`) && current_token.length > 0) {
516
- tokens.push(current_token)
517
- current_token = char
518
- } else {
519
- current_token += char
520
- }
521
- }
522
- if (current_token) tokens.push(current_token)
523
-
524
- for (const token of tokens) {
525
- // Check if this token is a variable term (x, y, or z with optional sign)
526
- const var_match = /^([+-]?)([xyz])$/.exec(token)
527
- if (var_match) {
528
- const sign = var_match[1] === `-` ? -1 : 1
529
- const var_char = var_match[2]
530
- const var_idx = var_char === `x` ? 0 : var_char === `y` ? 1 : 2
531
- coefficients[var_idx] += sign
532
- continue
533
- }
534
-
535
- // Check if this is a numeric term (integer, decimal, or fraction)
536
- let sign = 1
537
- let num_str = token
538
-
539
- // Handle leading sign
540
- if (num_str.startsWith(`+`)) {
541
- num_str = num_str.slice(1)
542
- } else if (num_str.startsWith(`-`)) {
543
- sign = -1
544
- num_str = num_str.slice(1)
545
- }
546
-
547
- // Skip empty tokens (from dangling operators like "x+")
548
- if (!num_str || num_str === `+` || num_str === `-`) continue
549
-
550
- if (num_str.includes(`/`)) {
551
- // Fraction
552
- const parts = num_str.split(`/`)
553
- if (parts.length === 2) {
554
- const numerator = parseFloat(parts[0])
555
- const denominator = parseFloat(parts[1])
556
- if (!isNaN(numerator) && !isNaN(denominator) && denominator !== 0) {
557
- translation += sign * (numerator / denominator)
558
- }
559
- }
560
- } else {
561
- // Integer or decimal
562
- const val = parseFloat(num_str)
563
- if (!isNaN(val)) {
564
- translation += sign * val
565
- }
566
- }
567
- }
568
-
569
- return { coefficients, translation }
570
- }
571
-
572
- // Apply symmetry operations to generate equivalent positions
573
- const apply_symmetry_ops = (
574
- atom: CifAtom,
575
- symmetry_ops: string[],
576
- wrap_fractional_coords: boolean,
577
- ): CifAtom[] => {
578
- if (symmetry_ops.length === 0) return [atom]
579
-
580
- const equivalent_atoms: CifAtom[] = []
581
- const seen = new Set<string>()
582
- const wrap = (coords: Vec3): Vec3 =>
583
- wrap_fractional_coords ? wrap_to_unit_cell(coords) : coords
584
- // Use 6 decimal places for deduplication to handle floating point imprecision
585
- // from compound symmetry operations like x-y, -x+y which can produce small errors
586
-
587
- // Always include base atom (optionally wrapped)
588
- const base_coords = wrap(atom.coords)
589
- seen.add(cif_coords_key(base_coords))
590
- equivalent_atoms.push({ ...atom, coords: base_coords })
591
-
592
- for (const operation of symmetry_ops) {
593
- const operation_match = /['"]([^'"]+)['"]/.exec(operation)
594
- const expr_str = operation_match ? operation_match[1] : operation.trim()
595
- const parts = expr_str.split(`,`).map((part) => part.trim())
596
- if (parts.length !== 3) continue
597
-
598
- const new_coords: Vec3 = [0, 0, 0]
599
-
600
- for (let dim = 0; dim < 3; dim++) {
601
- const { coefficients, translation } = parse_symmetry_expression(parts[dim])
602
- // Apply: new_coord = coeff_x * x + coeff_y * y + coeff_z * z + translation
603
- new_coords[dim] =
604
- coefficients[0] * atom.coords[0] +
605
- coefficients[1] * atom.coords[1] +
606
- coefficients[2] * atom.coords[2] +
607
- translation
608
- }
609
-
610
- // Wrap and deduplicate transformed coordinates
611
- const wrapped = wrap(new_coords)
612
- const cache_key = cif_coords_key(wrapped)
613
- if (seen.has(cache_key)) continue
614
- seen.add(cache_key)
615
-
616
- equivalent_atoms.push({
617
- ...atom,
618
- coords: wrapped,
619
- id: `${atom.id}_${equivalent_atoms.length}`,
620
- })
621
- }
622
-
623
- return equivalent_atoms
624
- }
625
-
626
- const extract_cif_cell_parameters = (text: string, type: string, strict = true): number[] =>
627
- text
628
- .split(`\n`)
629
- .filter((line) => line.startsWith(`_${type}`))
630
- .map((line) => {
631
- const tokens = line.split(/\s+/).filter((token) => token.length > 0)
632
- if (tokens.length < 2) {
633
- if (strict) throw new Error(`Invalid CIF cell parameter line format: ${line}`)
634
- return null
635
- }
636
- const value = parseFloat((tokens.at(-1) ?? ``).split(`(`)[0])
637
- if (isNaN(value)) {
638
- if (strict) throw new Error(`Invalid CIF cell parameter in line: ${line}`)
639
- return null // Return null for invalid values in non-strict mode
640
- }
641
- return value
642
- })
643
- .filter((val): val is number => val !== null)
644
-
645
- // build header index mapping for atom site data (supports fract and Cartn coordinates)
646
- const build_cif_atom_site_header_indices = (headers: string[]): Record<string, number> => {
647
- const indices: Record<string, number> = {}
648
- const mappings = [
649
- [`_atom_site_label`, `label`],
650
- [`_atom_site_type_symbol`, `symbol`],
651
- [`_atom_site_fract_x`, `x`],
652
- [`_atom_site_fract_y`, `y`],
653
- [`_atom_site_fract_z`, `z`],
654
- [`_atom_site_cartn_x`, `cart_x`],
655
- [`_atom_site_cartn_y`, `cart_y`],
656
- [`_atom_site_cartn_z`, `cart_z`],
657
- [`_atom_site_occupancy`, `occupancy`],
658
- [`_atom_site_disorder_group`, `disorder`],
659
- ]
660
-
661
- headers.forEach((header, idx) => {
662
- const lower = header.trim().toLowerCase()
663
- const mapping = mappings.find(([suffix]) => lower.endsWith(suffix))
664
- if (mapping) indices[mapping[1]] = idx
665
- })
666
-
667
- return indices
668
- }
669
-
670
- type CifAtom = {
671
- id: string
672
- element: string
673
- coords: Vec3
674
- coords_type: `fract` | `cart`
675
- occupancy: number
676
- }
677
-
678
- // Parse atom data from CIF with robust error handling
679
- const parse_cif_atom_data = (
680
- raw_data: string[],
681
- indices: Record<string, number>,
682
- coords_type: `fract` | `cart`,
683
- ): CifAtom => {
684
- const { label = 0, symbol = -1, occupancy = -1 } = indices
685
- const coord_indices =
686
- coords_type === `fract`
687
- ? [indices.x, indices.y, indices.z]
688
- : [indices.cart_x, indices.cart_y, indices.cart_z]
689
-
690
- if (coord_indices.some((idx) => idx === undefined)) {
691
- throw new Error(`Missing coordinate indices`)
692
- }
693
-
694
- const coords_triplet = vec3_from_values(
695
- coord_indices.map((idx) => {
696
- if (idx === undefined) throw new Error(`Invalid coordinate index`)
697
- const coord_str = raw_data[idx]
698
- if (!coord_str) throw new Error(`Missing coordinate at index ${idx}`)
699
- const coord = parseFloat(coord_str.split(`(`)[0])
700
- if (isNaN(coord)) throw new Error(`Invalid coordinate: ${coord_str}`)
701
- return coord
702
- }),
703
- `CIF atom coordinates`,
704
- )
705
-
706
- const occu =
707
- occupancy >= 0 && raw_data[occupancy]
708
- ? parseFloat(raw_data[occupancy].split(`(`)[0]) || 1.0
709
- : 1.0
710
-
711
- const element_symbol =
712
- (symbol >= 0 && /^([A-Z][a-z]*)/.exec(raw_data[symbol])?.[1]) ||
713
- raw_data[label]?.match(/([A-Z][a-z]*)/g)?.[0] ||
714
- (() => {
715
- throw new Error(`Could not extract element symbol from: ${raw_data.join(` `)}`)
716
- })()
717
-
718
- return {
719
- id: raw_data[label],
720
- element: element_symbol,
721
- coords: coords_triplet,
722
- coords_type,
723
- occupancy: occu,
724
- }
725
- }
726
-
727
- // Parse CIF (Crystallographic Information File) format
728
- export function parse_cif(
729
- content: string,
730
- wrap_fractional_coords: boolean = true,
731
- strict: boolean = true,
732
- ): ParsedStructure | null {
733
- try {
734
- const text = content.trim()
735
- if (!text) {
736
- console.error(`CIF file is empty`)
737
- return null
738
- }
739
-
740
- // Find atom site loop that actually contains coordinates (fract or Cartn)
741
- const lines = text.split(`\n`)
742
- let atom_headers: string[] = []
743
- const atom_data_lines: string[] = []
744
- const symmetry_ops: string[] = []
745
-
746
- for (let ii = 0; ii < lines.length; ii++) {
747
- if (lines[ii].trim() !== `loop_`) continue
748
-
749
- let jj = ii + 1
750
- const headers: string[] = []
751
-
752
- // Collect headers for this loop
753
- while (jj < lines.length && lines[jj].trim().startsWith(`_`)) {
754
- headers.push(lines[jj].trim())
755
- jj++
756
- }
757
-
758
- // Check if this is a symmetry operations loop
759
- if (
760
- headers.some(
761
- (header) =>
762
- header.includes(`_symmetry_equiv_pos_as_xyz`) ||
763
- header.includes(`_space_group_symop_operation_xyz`),
764
- )
765
- ) {
766
- // Collect symmetry operations
767
- while (jj < lines.length) {
768
- const line = lines[jj].trim()
769
- if (line === `loop_` || line.startsWith(`data_`)) break
770
- if (line && !line.startsWith(`#`) && !line.startsWith(`;`)) {
771
- symmetry_ops.push(line)
772
- }
773
- jj++
774
- }
775
- continue
776
- }
777
-
778
- // Not an atom-site loop → continue search
779
- if (!headers.some((header) => header.includes(`_atom_site_`))) continue
780
-
781
- // Check if this loop contains coordinate headers
782
- const indices_preview = build_cif_atom_site_header_indices(headers)
783
- const has_coords =
784
- (indices_preview.x !== undefined &&
785
- indices_preview.y !== undefined &&
786
- indices_preview.z !== undefined) ||
787
- (indices_preview.cart_x !== undefined &&
788
- indices_preview.cart_y !== undefined &&
789
- indices_preview.cart_z !== undefined)
790
-
791
- if (!has_coords) {
792
- ii = jj - 1
793
- continue
794
- }
795
-
796
- // This is the desired atom-site loop with coordinates: collect data lines
797
- atom_headers = headers
798
- while (jj < lines.length) {
799
- const line = lines[jj].trim()
800
- if (line === `loop_` || line.startsWith(`data_`)) break
801
- if (line && !line.startsWith(`#`)) {
802
- if (line.startsWith(`;`)) {
803
- let multi_line_data = ``
804
- while (jj < lines.length && !lines[jj].trim().endsWith(`;`)) {
805
- multi_line_data += lines[jj] + `\n`
806
- jj++
807
- }
808
- multi_line_data += lines[jj]
809
- atom_data_lines.push(multi_line_data.trim())
810
- } else {
811
- atom_data_lines.push(line)
812
- }
813
- }
814
- jj++
815
- }
816
- if (atom_data_lines.length > 0) break
817
- }
818
-
819
- if (!atom_headers.length || !atom_data_lines.length) {
820
- console.error(`No valid atom site loop found in CIF file`)
821
- return null
822
- }
823
-
824
- // Parse atom data with error handling
825
- const header_indices = build_cif_atom_site_header_indices(atom_headers)
826
-
827
- // Determine available coordinate type
828
- const coords_type: `fract` | `cart` | null =
829
- header_indices.x !== undefined &&
830
- header_indices.y !== undefined &&
831
- header_indices.z !== undefined
832
- ? `fract`
833
- : header_indices.cart_x !== undefined &&
834
- header_indices.cart_y !== undefined &&
835
- header_indices.cart_z !== undefined
836
- ? `cart`
837
- : null
838
-
839
- if (!coords_type) {
840
- console.error(`CIF atom site loop missing coordinates (fract or Cartn)`)
841
- return null
842
- }
843
-
844
- // Collect required coordinate indices
845
- const required_indices =
846
- coords_type === `fract`
847
- ? [header_indices.x, header_indices.y, header_indices.z]
848
- : [header_indices.cart_x, header_indices.cart_y, header_indices.cart_z]
849
-
850
- const atoms = atom_data_lines
851
- .map((line) => {
852
- // Handle quoted multi-word values by splitting only on whitespace
853
- // that is not inside quotes.
854
- const tokens = line.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || []
855
- return tokens.map((token) => token.replace(/['"]/g, ``))
856
- })
857
- .filter((tokens) => {
858
- const { disorder } = header_indices
859
- const max_required_idx = Math.max(...required_indices)
860
- return (
861
- !(disorder !== undefined && tokens[disorder] === `2`) &&
862
- tokens.length > max_required_idx
863
- )
864
- })
865
- .map((tokens) => {
866
- try {
867
- return parse_cif_atom_data(tokens, header_indices, coords_type)
868
- } catch (error) {
869
- console.warn(`Skipping invalid atom data: ${error}`)
870
- return null
871
- }
872
- })
873
- .filter((atom): atom is NonNullable<typeof atom> => atom !== null)
874
-
875
- if (!atoms.length) {
876
- console.error(`No valid atoms found in CIF file`)
877
- return null
878
- }
879
-
880
- // Extract cell parameters and build lattice
881
- const lengths = extract_cif_cell_parameters(text, `cell_length`, strict)
882
- const angles = extract_cif_cell_parameters(text, `cell_angle`, strict)
883
-
884
- if (lengths.length < 3 || angles.length < 3) {
885
- console.error(`Insufficient cell parameters in CIF file`)
886
- return null
887
- }
888
-
889
- // Build lattice and create sites
890
- const [a, b, c] = lengths
891
- const [alpha, beta, gamma] = angles
892
- const lattice_matrix = math.cell_to_lattice_matrix(a, b, c, alpha, beta, gamma)
893
- const lattice_params = math.calc_lattice_params(lattice_matrix)
894
- const frac_to_cart = math.create_frac_to_cart(lattice_matrix)
895
- const cart_to_frac = try_create_cart_to_frac(lattice_matrix)
896
-
897
- // Create sites with coordinate conversion and symmetry operations
898
- const wrap_vec3 = (v: Vec3): Vec3 => (wrap_fractional_coords ? wrap_to_unit_cell(v) : v)
899
-
900
- // Apply symmetry operations to generate all equivalent positions
901
- const all_sites: Site[] = []
902
-
903
- // Normalize symmetry operations (trim/strip quotes) but preserve duplicates; we deduplicate positions later
904
- const normalized_ops = symmetry_ops
905
- .map((op) => /['"]([^'"]+)['"]/.exec(op)?.[1] || op.trim())
906
- .map((op) => op.replace(/\s+/g, ``))
907
-
908
- // Rely on symmetry operations list for all centering/translations to avoid double-counting
909
- // TODO: Support conventional cells with centering by discovering centering from space group metadata
910
- // when present (e.g. P, I, F, C, R centering types)
911
- const centering_vectors: Vec3[] = [[0, 0, 0]]
912
-
913
- // Inspect optional _atom_type_number_in_cell loop to see if atom sites are already expanded
914
- const atom_type_counts: Record<string, number> = (() => {
915
- const map: Record<string, number> = {}
916
- const text_lines = text.split(`\n`)
917
- for (let li = 0; li < text_lines.length; li++) {
918
- if (text_lines[li].trim() !== `loop_`) {
919
- continue
920
- }
921
- let lj = li + 1
922
- const hdrs: string[] = []
923
- while (lj < text_lines.length && text_lines[lj].trim().startsWith(`_`)) {
924
- hdrs.push(text_lines[lj].trim().toLowerCase())
925
- lj++
926
- }
927
- const sym_idx = hdrs.findIndex((hdr) => hdr.endsWith(`_atom_type_symbol`))
928
- const num_idx = hdrs.findIndex((hdr) => hdr.endsWith(`_atom_type_number_in_cell`))
929
- if (sym_idx !== -1 && num_idx !== -1) {
930
- while (lj < text_lines.length) {
931
- const line = text_lines[lj].trim()
932
- if (!line || line === `loop_` || line.startsWith(`data_`)) break
933
- if (line.startsWith(`#`)) {
934
- lj++
935
- continue
936
- }
937
- const toks = (line.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || []).map((tok) =>
938
- tok.replace(/['"]/g, ``),
939
- )
940
- if (toks.length > Math.max(sym_idx, num_idx)) {
941
- // Normalize type symbol to bare element (e.g. 'Sn2+' -> 'Sn')
942
- const match = /^([A-Z][a-z]*)/.exec(toks[sym_idx])
943
- const sym = match ? match[1] : toks[sym_idx]
944
- const num = parseInt(toks[num_idx])
945
- if (sym && !Number.isNaN(num)) map[sym] = num
946
- }
947
- lj++
948
- }
949
- break
950
- }
951
- }
952
- return map
953
- })()
954
-
955
- const observed_counts: Record<string, number> = {}
956
- for (const atom of atoms) {
957
- observed_counts[atom.element] = (observed_counts[atom.element] || 0) + 1
958
- }
959
-
960
- const has_expected_counts = Object.keys(atom_type_counts).length > 0
961
- const already_enumerated =
962
- has_expected_counts &&
963
- Object.entries(atom_type_counts).every(([el, exp]) => (observed_counts[el] || 0) >= exp)
964
-
965
- const ops_to_use = already_enumerated ? [] : normalized_ops
966
-
967
- // Global deduplication of final sites (per element + coordinates + label)
968
- // Use 6 decimal places to handle floating point imprecision from compound symmetry ops
969
- const seen_site_keys = new Set<string>()
970
-
971
- for (const atom of atoms) {
972
- const element = validate_element_symbol(atom.element, all_sites.length)
973
-
974
- // Convert to fractional coordinates if needed
975
- let fractional_atom: CifAtom
976
- if (atom.coords_type === `fract`) {
977
- fractional_atom = {
978
- ...atom,
979
- coords: wrap_vec3(atom.coords),
980
- coords_type: `fract`,
981
- }
982
- } else {
983
- const xyz_base: Vec3 = [atom.coords[0], atom.coords[1], atom.coords[2]]
984
- const atom_abc = wrap_vec3(
985
- cart_to_frac
986
- ? cart_to_frac(xyz_base)
987
- : approximate_cart_to_frac(xyz_base, [a, b, c]),
988
- )
989
- fractional_atom = { ...atom, coords: atom_abc, coords_type: `fract` }
990
- }
991
-
992
- // First apply symmetry operations in fractional space
993
- const equiv_atoms = apply_symmetry_ops(
994
- fractional_atom,
995
- ops_to_use,
996
- wrap_fractional_coords,
997
- )
998
-
999
- // Then apply lattice centering shifts to each equivalent position
1000
- for (const equiv_atom of equiv_atoms) {
1001
- for (const cv of centering_vectors) {
1002
- const abc = wrap_vec3([
1003
- equiv_atom.coords[0] + cv[0],
1004
- equiv_atom.coords[1] + cv[1],
1005
- equiv_atom.coords[2] + cv[2],
1006
- ] as Vec3)
1007
- const key = cif_site_key(element, abc, equiv_atom.id)
1008
- if (seen_site_keys.has(key)) continue
1009
- seen_site_keys.add(key)
1010
- const xyz = frac_to_cart(abc)
1011
- all_sites.push({
1012
- species: [{ element, occu: equiv_atom.occupancy, oxidation_state: 0 }],
1013
- abc,
1014
- xyz,
1015
- label: equiv_atom.id,
1016
- properties: {},
1017
- })
1018
- }
1019
- }
1020
- }
1021
-
1022
- const sites = all_sites
1023
- return { sites, lattice: { matrix: lattice_matrix, ...lattice_params } }
1024
- } catch (error) {
1025
- console.error(`Error parsing CIF file:`, error)
1026
- return null
1027
- }
1028
- }
1029
-
1030
- // Convert phonopy cell to ParsedStructure
1031
- function convert_phonopy_cell(cell: PhonopyCell): ParsedStructure {
1032
- const sites: Site[] = []
1033
- // Phonopy stores lattice vectors as rows, use them directly
1034
- const lattice_matrix: math.Matrix3x3 = [
1035
- vec3_from_values(cell.lattice[0], `phonopy lattice vector 1`),
1036
- vec3_from_values(cell.lattice[1], `phonopy lattice vector 2`),
1037
- vec3_from_values(cell.lattice[2], `phonopy lattice vector 3`),
1038
- ]
1039
-
1040
- // Process each atomic site
1041
- const phonopy_frac_to_cart = math.create_frac_to_cart(lattice_matrix)
1042
- for (const point of cell.points) {
1043
- const element = validate_element_symbol(point.symbol, sites.length)
1044
- const abc = vec3_from_values(point.coordinates, `phonopy point coordinates`)
1045
-
1046
- const xyz = phonopy_frac_to_cart(abc)
1047
-
1048
- const properties = {
1049
- mass: point.mass,
1050
- ...(point.reduced_to !== undefined && { reduced_to: point.reduced_to }),
1051
- }
1052
- const species = [{ element, occu: 1.0, oxidation_state: 0 }]
1053
- const site: Site = { species, abc, xyz, label: point.symbol, properties }
1054
- sites.push(site)
1055
- }
1056
-
1057
- // Calculate lattice parameters
1058
- const calculated_lattice_params = math.calc_lattice_params(lattice_matrix)
1059
-
1060
- return { sites, lattice: { matrix: lattice_matrix, ...calculated_lattice_params } }
1061
- }
1062
-
1063
- export type CellType =
1064
- | `primitive_cell`
1065
- | `unit_cell`
1066
- | `supercell`
1067
- | `phonon_primitive_cell`
1068
- | `phonon_supercell`
1069
- | `auto`
1070
-
1071
- const is_phonopy_cell = (value: unknown): value is PhonopyCell => {
1072
- if (!value || typeof value !== `object`) return false
1073
- const lattice = `lattice` in value ? value.lattice : undefined
1074
- const points = `points` in value ? value.points : undefined
1075
- return Array.isArray(lattice) && Array.isArray(points)
1076
- }
1077
-
1078
- const get_phonopy_cell = (
1079
- data: unknown,
1080
- cell_type: Exclude<CellType, `auto`>,
1081
- ): PhonopyCell | undefined => {
1082
- if (!data || typeof data !== `object`) return undefined
1083
- const cell = Reflect.get(data, cell_type)
1084
- return is_phonopy_cell(cell) ? cell : undefined
1085
- }
1086
-
1087
- // Parse phonopy YAML file and return the requested cell type (or preferred single structure)
1088
- export function parse_phonopy_yaml(
1089
- content: string,
1090
- cell_type?: CellType,
1091
- ): ParsedStructure | null {
1092
- try {
1093
- // Parse YAML content but exclude large phonon_displacements array for performance
1094
- const lines = content.split(`\n`)
1095
- const filtered_lines = []
1096
- let skip_displacements = false
1097
-
1098
- for (const line of lines) {
1099
- // Skip phonon_displacements section for performance
1100
- if (line.trim().startsWith(`phonon_displacements:`)) {
1101
- skip_displacements = true
1102
- continue
1103
- }
1104
-
1105
- // Check if we're still in the phonon_displacements section
1106
- if (skip_displacements) {
1107
- if (/^[a-zA-Z_]/.exec(line)) {
1108
- // New top-level key, stop skipping
1109
- skip_displacements = false
1110
- } else continue // Still in phonon_displacements, skip this line
1111
- }
1112
-
1113
- filtered_lines.push(line)
1114
- }
1115
-
1116
- const filtered_content = filtered_lines.join(`\n`)
1117
- const data = yaml_load(filtered_content)
1118
-
1119
- if (!data) {
1120
- console.error(`Failed to parse phonopy YAML`)
1121
- return null
1122
- }
1123
-
1124
- // If specific cell type requested, parse only that one
1125
- if (cell_type && cell_type !== `auto`) {
1126
- const cell = get_phonopy_cell(data, cell_type)
1127
- if (cell) return convert_phonopy_cell(cell)
1128
- else {
1129
- console.error(`Requested cell type '${cell_type}' not found in phonopy YAML`)
1130
- return null
1131
- }
1132
- }
1133
-
1134
- // Auto mode: return preferred structure in order of preference
1135
- // 1. supercell (most detailed)
1136
- // 2. phonon_supercell
1137
- // 3. unit_cell
1138
- // 4. phonon_primitive_cell
1139
- // 5. primitive_cell
1140
-
1141
- const auto_cell =
1142
- get_phonopy_cell(data, `supercell`) ??
1143
- get_phonopy_cell(data, `phonon_supercell`) ??
1144
- get_phonopy_cell(data, `unit_cell`) ??
1145
- get_phonopy_cell(data, `phonon_primitive_cell`) ??
1146
- get_phonopy_cell(data, `primitive_cell`)
1147
- if (auto_cell) return convert_phonopy_cell(auto_cell)
1148
-
1149
- console.error(`No valid cells found in phonopy YAML`)
1150
- return null
1151
- } catch (error) {
1152
- console.error(`Error parsing phonopy YAML:`, error)
1153
- return null
1154
- }
1155
- }
1156
-
1157
- // Recursively search for a valid structure object in nested JSON
1158
- function find_structure_in_json(
1159
- obj: unknown,
1160
- visited = new WeakSet(),
1161
- ): ParsedStructure | null {
1162
- // Check if current object is null or undefined
1163
- if (obj == null) return null
1164
-
1165
- if (typeof obj !== `object`) return null // If it's not an object, skip it
1166
-
1167
- if (visited.has(obj)) return null // Check for circular references
1168
- visited.add(obj)
1169
-
1170
- // If it's an array, search through each element
1171
- if (Array.isArray(obj)) {
1172
- for (const item of obj) {
1173
- const result = find_structure_in_json(item, visited)
1174
- if (result) return result
1175
- }
1176
- return null
1177
- }
1178
-
1179
- // Check if this object looks like a valid structure
1180
- if (is_parsed_structure(obj)) return obj
1181
-
1182
- // Otherwise, recursively search through all properties
1183
- for (const value of Object.values(obj)) {
1184
- const result = find_structure_in_json(value, visited)
1185
- if (result) return result
1186
- }
1187
-
1188
- return null
1189
- }
1190
-
1191
- // Type guard to validate structure-like objects
1192
- function is_parsed_structure(obj: unknown): obj is ParsedStructure {
1193
- if (!obj || typeof obj !== `object`) return false
1194
- const sites = `sites` in obj ? obj.sites : undefined
1195
- if (!Array.isArray(sites) || sites.length === 0) return false
1196
-
1197
- const first_site = sites[0]
1198
- if (!first_site || typeof first_site !== `object`) return false
1199
-
1200
- const species = `species` in first_site ? first_site.species : undefined
1201
- const abc = `abc` in first_site ? first_site.abc : undefined
1202
- const xyz = `xyz` in first_site ? first_site.xyz : undefined
1203
- const has_species = Array.isArray(species) && species.length > 0
1204
- const has_coords = Array.isArray(abc) || Array.isArray(xyz)
1205
- return has_species && has_coords
1206
- }
1207
-
1208
- // Normalize structure coordinates: wrap fractional coords to [0,1) and recompute Cartesian
1209
- // Only normalizes when lattice matrix is available to ensure abc/xyz stay consistent
1210
- export function normalize_fractional_coords(structure: ParsedStructure): ParsedStructure {
1211
- if (!structure.sites || structure.sites.length === 0) return structure
1212
-
1213
- // Require lattice to ensure we can keep abc and xyz consistent after wrapping
1214
- if (!structure.lattice?.matrix) return structure
1215
-
1216
- // Check if any sites have fractional coords outside [0, 1) range
1217
- const needs_wrapping = structure.sites.some((site) =>
1218
- site.abc?.some((coord) => coord < 0 || coord >= 1),
1219
- )
1220
- if (!needs_wrapping) return structure
1221
-
1222
- const frac_to_cart = math.create_frac_to_cart(structure.lattice.matrix)
1223
-
1224
- // Wrap fractional coordinates and recompute Cartesian
1225
- const normalized_sites = structure.sites.map((site) => {
1226
- if (!site.abc) return site
1227
- const wrapped_abc = wrap_to_unit_cell(site.abc)
1228
- return { ...site, abc: wrapped_abc, xyz: frac_to_cart(wrapped_abc) }
1229
- })
1230
-
1231
- return { ...structure, sites: normalized_sites }
1232
- }
1233
-
1234
- // Auto-detect file format and parse accordingly
1235
- export function parse_structure_file(
1236
- content: string,
1237
- filename?: string,
1238
- ): ParsedStructure | null {
1239
- // If a filename is provided, try to detect format by file extension first
1240
- if (filename) {
1241
- // Handle compressed files by removing compression extensions
1242
- let base_filename = filename.toLowerCase()
1243
- while (COMPRESSION_EXTENSIONS_REGEX.test(base_filename)) {
1244
- base_filename = base_filename.replace(COMPRESSION_EXTENSIONS_REGEX, ``)
1245
- }
1246
-
1247
- const ext = base_filename.split(`.`).pop()
1248
-
1249
- // Try to detect format by file extension
1250
- if (ext === `xyz` || ext === `extxyz`) return parse_xyz(content)
1251
-
1252
- // CIF files
1253
- if (ext === `cif`) return parse_cif(content)
1254
-
1255
- // JSON files - try OPTIMADE JSON structure format first, then pymatgen
1256
- if (ext === `json`) {
1257
- try {
1258
- // Parse once, reuse for detection and parsing
1259
- const parsed = JSON.parse(content)
1260
- if (is_optimade_raw(parsed)) {
1261
- const result = parse_optimade_from_raw(parsed)
1262
- if (result) return result
1263
- }
1264
- // Otherwise, try to parse as pymatgen/nested structure JSON
1265
- const structure = find_structure_in_json(parsed)
1266
- if (structure) return normalize_fractional_coords(structure)
1267
- console.error(`JSON file does not contain a valid structure format`)
1268
- return null
1269
- } catch (error) {
1270
- console.error(`Error parsing JSON file:`, error)
1271
- return null
1272
- }
1273
- }
1274
-
1275
- // YAML files (phonopy)
1276
- if (ext === `yaml` || ext === `yml`) return parse_phonopy_yaml(content)
1277
-
1278
- // POSCAR files may not have extensions or have various names
1279
- if (ext === `poscar` || base_filename.includes(`poscar`)) {
1280
- return parse_poscar(content)
1281
- }
1282
- }
1283
-
1284
- // Try to auto-detect based on content
1285
- const lines = content.trim().split(/\r?\n/)
1286
-
1287
- if (lines.length < 2) {
1288
- console.error(`File too short to determine format`)
1289
- return null
1290
- }
1291
-
1292
- // JSON format detection: try to parse as JSON first
1293
- try {
1294
- const parsed = JSON.parse(content)
1295
- if (is_optimade_raw(parsed)) {
1296
- const result = parse_optimade_from_raw(parsed)
1297
- if (result) return result
1298
- }
1299
- // Otherwise try parsing as regular JSON structure
1300
- const structure = find_structure_in_json(parsed)
1301
- if (structure) {
1302
- return normalize_fractional_coords(structure)
1303
- }
1304
- } catch {
1305
- // Not JSON, continue with other format detection
1306
- }
1307
-
1308
- // XYZ format detection: first line should be a number, second line is comment
1309
- const first_line_number = parseInt(lines[0].trim())
1310
- if (!isNaN(first_line_number) && first_line_number > 0) {
1311
- // Check if this looks like XYZ format
1312
- if (lines.length >= first_line_number + 2) {
1313
- // Try to parse a coordinate line to see if it looks like XYZ
1314
- const coord_line_idx = 2 // First coordinate line in XYZ
1315
- if (coord_line_idx < lines.length) {
1316
- const parts = lines[coord_line_idx].trim().split(/\s+/)
1317
- // XYZ format: element symbol followed by 3 coordinates
1318
- if (parts.length >= 4) {
1319
- const first_token = parts[0]
1320
- const coords = parts.slice(1, 4)
1321
-
1322
- // Check if first token looks like an element symbol (not a number)
1323
- // and the next 3 tokens look like coordinates (numbers)
1324
- const is_element_symbol = isNaN(parseInt(first_token)) && first_token.length <= 3
1325
- const are_coordinates = coords.every((coord) => !isNaN(parseFloat(coord)))
1326
-
1327
- if (is_element_symbol && are_coordinates) {
1328
- // First token is likely an element symbol, likely XYZ
1329
- return parse_xyz(content)
1330
- }
1331
- }
1332
- }
1333
- }
1334
- }
1335
-
1336
- // POSCAR format detection: look for typical structure
1337
- if (lines.length >= 8) {
1338
- const second_line_number = parseFloat(lines[1].trim())
1339
- // Second line is a number (scale factor), likely POSCAR
1340
- if (!isNaN(second_line_number)) return parse_poscar(content)
1341
- }
1342
-
1343
- // CIF format detection: look for CIF-specific keywords
1344
- const has_cif_keywords = lines.some(
1345
- (line) =>
1346
- line.startsWith(`data_`) ||
1347
- line.includes(`_cell_length_`) ||
1348
- line.includes(`_atom_site_`) ||
1349
- line.trim() === `loop_`,
1350
- )
1351
- if (has_cif_keywords) return parse_cif(content)
1352
-
1353
- // YAML format detection: look for phonopy-specific keywords
1354
- const has_phonopy_keywords = lines.some(
1355
- (line) =>
1356
- line.includes(`phono3py:`) ||
1357
- line.includes(`phonopy:`) ||
1358
- line.includes(`primitive_cell:`) ||
1359
- line.includes(`supercell:`) ||
1360
- line.includes(`phonon_supercell:`),
1361
- )
1362
- if (has_phonopy_keywords) return parse_phonopy_yaml(content)
1363
-
1364
- console.error(`Unable to determine file format`)
1365
- return null
1366
- }
1367
-
1368
- // Universal parser that handles JSON and structure files
1369
- export function parse_any_structure(content: string, filename: string): AnyStructure | null {
1370
- const finalize_structure = (structure: ParsedStructure): AnyStructure => ({
1371
- sites: structure.sites,
1372
- charge: 0,
1373
- ...(structure.properties && {
1374
- properties: clone_structure_properties(structure.properties),
1375
- }),
1376
- ...(structure.lattice && {
1377
- lattice: { ...structure.lattice, pbc: [true, true, true] },
1378
- }),
1379
- })
1380
-
1381
- // Try JSON first, but handle nested structures properly
1382
- try {
1383
- const parsed = JSON.parse(content)
1384
-
1385
- // Check if it's already a valid structure using proper type guard
1386
- if (is_parsed_structure(parsed)) {
1387
- // Normalize coordinates (wrap fractional to [0,1) and recompute Cartesian)
1388
- return finalize_structure(normalize_fractional_coords(parsed))
1389
- }
1390
- // If not, use parse_structure_file to find nested structures
1391
- const structure = parse_structure_file(content, filename)
1392
-
1393
- return structure ? finalize_structure(structure) : null
1394
- } catch {
1395
- // Try structure file formats
1396
- const parsed = parse_structure_file(content, filename)
1397
- return parsed ? finalize_structure(parsed) : null
1398
- }
1399
- }
1400
-
1401
- // Parse OPTIMADE JSON format
1402
- export function parse_optimade_json(content: string): ParsedStructure | null {
1403
- try {
1404
- const raw = JSON.parse(content) as unknown
1405
- return parse_optimade_from_raw(raw)
1406
- } catch (error) {
1407
- console.error(`Error parsing OPTIMADE JSON:`, error)
1408
- return null
1409
- }
1410
- }
1411
-
1412
- // Parse OPTIMADE from already-parsed JSON
1413
- export function parse_optimade_from_raw(raw: unknown): ParsedStructure | null {
1414
- try {
1415
- const structure = extract_optimade_structure_from_raw(raw)
1416
- if (!structure) {
1417
- console.error(`No valid OPTIMADE structure found in JSON`)
1418
- return null
1419
- }
1420
- const attrs = structure.attributes
1421
-
1422
- // Inline validation for conciseness
1423
- const positions_raw = attrs.cartesian_site_positions
1424
- const species_raw = attrs.species_at_sites
1425
- if (!(Array.isArray(positions_raw) && Array.isArray(species_raw))) {
1426
- console.error(`OPTIMADE JSON missing required position or species data`)
1427
- return null
1428
- }
1429
- if (positions_raw.length !== species_raw.length) {
1430
- console.error(`OPTIMADE JSON position/species count mismatch`)
1431
- return null
1432
- }
1433
- const positions = positions_raw
1434
- const species = species_raw
1435
-
1436
- // Optimade stores lattice vectors as rows, so use as is
1437
- const lattice_matrix = attrs.lattice_vectors
1438
- ? ([
1439
- vec3_from_values(attrs.lattice_vectors[0], `OPTIMADE lattice vector 1`),
1440
- vec3_from_values(attrs.lattice_vectors[1], `OPTIMADE lattice vector 2`),
1441
- vec3_from_values(attrs.lattice_vectors[2], `OPTIMADE lattice vector 3`),
1442
- ] satisfies math.Matrix3x3)
1443
- : undefined
1444
- const optimade_lattice_params = lattice_matrix
1445
- ? math.calc_lattice_params(lattice_matrix)
1446
- : null
1447
-
1448
- // Parse atomic sites
1449
- const optimade_exact_cart_to_frac = lattice_matrix
1450
- ? try_create_cart_to_frac(lattice_matrix)
1451
- : null
1452
- const optimade_cart_to_frac =
1453
- lattice_matrix && optimade_lattice_params
1454
- ? (optimade_exact_cart_to_frac ??
1455
- ((xyz: Vec3): Vec3 =>
1456
- approximate_cart_to_frac(xyz, [
1457
- optimade_lattice_params.a,
1458
- optimade_lattice_params.b,
1459
- optimade_lattice_params.c,
1460
- ])))
1461
- : null
1462
- if (lattice_matrix && !optimade_exact_cart_to_frac) {
1463
- console.warn(`Failed to create exact coordinate converter for OPTIMADE structure`)
1464
- }
1465
- const sites: Site[] = []
1466
- for (let idx = 0; idx < positions.length; idx++) {
1467
- const pos = positions[idx]
1468
- const element_symbol = species[idx]
1469
-
1470
- let xyz: Vec3
1471
- try {
1472
- xyz = vec3_from_values(pos, `OPTIMADE site ${idx} position`)
1473
- } catch (error) {
1474
- console.warn(`Invalid position data at site ${idx}: ${error}`)
1475
- continue
1476
- }
1477
-
1478
- const element = validate_element_symbol(element_symbol, idx)
1479
-
1480
- // Calculate fractional coordinates if lattice is available
1481
- const abc: Vec3 = optimade_cart_to_frac ? optimade_cart_to_frac(xyz) : [0, 0, 0]
1482
-
1483
- const site: Site = {
1484
- species: [{ element, occu: 1, oxidation_state: 0 }],
1485
- abc,
1486
- xyz,
1487
- label: `${element}${idx + 1}`,
1488
- properties: {},
1489
- }
1490
-
1491
- sites.push(site)
1492
- }
1493
-
1494
- if (sites.length === 0) {
1495
- console.error(`No valid sites found in OPTIMADE JSON`)
1496
- return null
1497
- }
1498
-
1499
- // Create structure object
1500
- let lattice: ParsedStructure[`lattice`] | undefined
1501
- if (lattice_matrix && optimade_lattice_params) {
1502
- lattice = { matrix: lattice_matrix, ...optimade_lattice_params }
1503
- }
1504
-
1505
- const structure_result: ParsedStructure = {
1506
- sites,
1507
- ...(lattice && { lattice }),
1508
- }
1509
-
1510
- return structure_result
1511
- } catch (error) {
1512
- console.error(`Error parsing OPTIMADE JSON:`, error)
1513
- return null
1514
- }
1515
- }
1516
-
1517
- // Check if JSON content is OPTIMADE format by looking for structure attributes
1518
- export function is_optimade_json(content: string): boolean {
1519
- try {
1520
- const raw = JSON.parse(content) as unknown
1521
- return is_optimade_raw(raw)
1522
- } catch {
1523
- return false
1524
- }
1525
- }
1526
-
1527
- // Check if already-parsed JSON is OPTIMADE-like
1528
- export const is_optimade_raw = (raw: unknown): boolean =>
1529
- Boolean(extract_optimade_structure_from_raw(raw))
1530
-
1531
- // Shared helper to extract an OPTIMADE structure from raw JSON-like data
1532
- function extract_optimade_structure_from_raw(raw: unknown): OptimadeStructure | null {
1533
- const payload = unwrap_data(raw)
1534
- const candidate = Array.isArray(payload) ? payload[0] : payload
1535
- return is_optimade_structure_object(candidate) ? candidate : null
1536
- }
1537
-
1538
- const unwrap_data = (value: unknown): unknown =>
1539
- value && typeof value === `object` && `data` in value
1540
- ? (value as { data?: unknown }).data
1541
- : value
1542
-
1543
- // Type guard: verify minimal OPTIMADE structure shape
1544
- function is_optimade_structure_object(value: unknown): value is OptimadeStructure {
1545
- if (!value || typeof value !== `object`) return false
1546
- const obj = value as { type?: unknown; id?: unknown; attributes?: unknown }
1547
- const type = obj.type
1548
- const id = obj.id
1549
- const attributes = obj.attributes
1550
- return (
1551
- type === `structures` &&
1552
- typeof id === `string` &&
1553
- typeof attributes === `object` &&
1554
- attributes !== null
1555
- )
1556
- }
1557
-
1558
- // Convert OPTIMADE structure to Crystal format
1559
- export function optimade_to_crystal(optimade_structure: OptimadeStructure): Crystal | null {
1560
- const {
1561
- lattice_vectors,
1562
- cartesian_site_positions,
1563
- species_at_sites,
1564
- species,
1565
- ...properties
1566
- } = optimade_structure.attributes
1567
-
1568
- if (!lattice_vectors || !cartesian_site_positions || !species_at_sites) {
1569
- console.error(`Missing required OPTIMADE structure data`)
1570
- return null
1571
- }
1572
-
1573
- try {
1574
- const lattice_matrix: math.Matrix3x3 = [
1575
- vec3_from_values(lattice_vectors[0], `OPTIMADE lattice vector 1`),
1576
- vec3_from_values(lattice_vectors[1], `OPTIMADE lattice vector 2`),
1577
- vec3_from_values(lattice_vectors[2], `OPTIMADE lattice vector 3`),
1578
- ]
1579
- const lattice_params = math.calc_lattice_params(lattice_matrix)
1580
-
1581
- // Build species lookup for site properties (mass, concentration, etc.)
1582
- const species_map = new Map(species?.map((spec) => [spec.name, spec]))
1583
- const crystal_cart_to_frac =
1584
- try_create_cart_to_frac(lattice_matrix) ??
1585
- ((xyz: Vec3): Vec3 =>
1586
- approximate_cart_to_frac(xyz, [lattice_params.a, lattice_params.b, lattice_params.c]))
1587
-
1588
- const sites = cartesian_site_positions.map((pos, idx) => {
1589
- const element_symbol = species_at_sites[idx]
1590
- if (!element_symbol) throw new Error(`Missing species for site ${idx}`)
1591
- const element = validate_element_symbol(element_symbol, idx)
1592
-
1593
- const xyz = vec3_from_values(pos, `OPTIMADE atom position ${idx + 1}`)
1594
- const abc: Vec3 = crystal_cart_to_frac ? crystal_cart_to_frac(xyz) : [0, 0, 0]
1595
-
1596
- // Extract mass/concentration from species data
1597
- const spec = species_map.get(element_symbol)
1598
- const site_props: Record<string, unknown> = {}
1599
- if (spec?.mass?.[0] !== undefined) site_props.mass = spec.mass[0]
1600
- if (spec?.concentration?.[0] !== undefined && spec.concentration[0] !== 1) {
1601
- site_props.concentration = spec.concentration[0]
1602
- }
1603
- return {
1604
- species: [{ element, occu: 1, oxidation_state: 0 }],
1605
- abc,
1606
- xyz,
1607
- label: `${element}${idx + 1}`,
1608
- properties: site_props,
1609
- }
1610
- })
1611
-
1612
- return {
1613
- sites,
1614
- lattice: { matrix: lattice_matrix, ...lattice_params, pbc: [true, true, true] },
1615
- id: optimade_structure.id,
1616
- properties,
1617
- }
1618
- } catch (err) {
1619
- console.error(`Error converting OPTIMADE to Crystal format:`, err)
1620
- return null
1621
- }
1622
- }
1623
-
1624
- // Check if filename indicates a structure file
1625
- export function is_structure_file(filename: string): boolean {
1626
- const name = filename.toLowerCase()
1627
-
1628
- // Trajectory-only formats (can't be structures)
1629
- if (/\.(traj|xtc|h5|hdf5)$/i.test(name) || /xdatcar/i.test(name)) return false
1630
-
1631
- // Always structure formats
1632
- if (STRUCTURE_EXTENSIONS_REGEX.test(name)) return true
1633
- if (VASP_FILES_REGEX.test(name)) return true
1634
-
1635
- // .xyz/.extxyz files: structure unless they have trajectory keywords
1636
- if (/\.(xyz|extxyz)$/i.test(name)) return !TRAJ_KEYWORDS_REGEX.test(name)
1637
-
1638
- // Keyword-based detection for YAML/XML
1639
- if (/\.(yaml|yml|xml)$/i.test(name) && STRUCT_KEYWORDS_REGEX.test(name)) return true
1640
-
1641
- // More restrictive keyword detection for JSON files
1642
- if (
1643
- /\.json$/i.test(name) &&
1644
- STRUCT_KEYWORDS_STRICT_REGEX.test(name) &&
1645
- !TRAJ_KEYWORDS_REGEX.test(name) &&
1646
- !CONFIG_DIRS_REGEX.test(name)
1647
- )
1648
- return true
1649
-
1650
- // Compressed files - check base filename recursively
1651
- if (COMPRESSION_EXTENSIONS_REGEX.test(name)) {
1652
- return is_structure_file(name.replace(COMPRESSION_EXTENSIONS_REGEX, ``))
1653
- }
1654
-
1655
- return false
1656
- }
1657
-
1658
- export const detect_structure_type = (
1659
- filename: string,
1660
- content: string,
1661
- ): `crystal` | `molecule` | `unknown` => {
1662
- const lower_filename = filename.toLowerCase()
1663
-
1664
- // Normalize compressed suffixes (gz, gzip, zip, xz, bz2) for detection parity
1665
- let name_to_check = lower_filename
1666
- while (COMPRESSION_EXTENSIONS_REGEX.test(name_to_check)) {
1667
- name_to_check = name_to_check.replace(COMPRESSION_EXTENSIONS_REGEX, ``)
1668
- }
1669
-
1670
- if (name_to_check.endsWith(`.json`)) {
1671
- try {
1672
- const parsed = JSON.parse(content)
1673
- // Check for crystal indicators: lattice, lattice_vectors, or periodic dimensions
1674
- const dims = parsed.data?.attributes?.dimension_types
1675
- if (
1676
- parsed.lattice ||
1677
- parsed.data?.attributes?.lattice_vectors ||
1678
- (Array.isArray(dims) && dims.some((dim: number) => dim > 0)) ||
1679
- parsed.data?.attributes?.nperiodic_dimensions > 0
1680
- ) {
1681
- return `crystal`
1682
- }
1683
- return `molecule`
1684
- } catch {
1685
- return `unknown`
1686
- }
1687
- }
1688
-
1689
- if (name_to_check.endsWith(`.cif`)) return `crystal`
1690
- if (name_to_check.includes(`poscar`)) return `crystal`
1691
-
1692
- if (name_to_check.endsWith(`.yaml`) || name_to_check.endsWith(`.yml`)) {
1693
- const lower_content = content.toLowerCase()
1694
- return lower_content.includes(`phono3py:`) || lower_content.includes(`phonopy:`)
1695
- ? `crystal`
1696
- : `unknown`
1697
- }
1698
-
1699
- if (XYZ_EXTXYZ_REGEX.test(name_to_check)) {
1700
- const lines = content.trim().split(/\r?\n/)
1701
- return lines.length >= 2 && lines[1].includes(`Lattice=`) ? `crystal` : `molecule`
1702
- }
1703
-
1704
- return `unknown`
1705
- }