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
@@ -0,0 +1,1392 @@
1
+ import { COMPRESSION_EXTENSIONS_REGEX, CONFIG_DIRS_REGEX, STRUCT_KEYWORDS_REGEX, STRUCT_KEYWORDS_STRICT_REGEX, STRUCTURE_EXTENSIONS_REGEX, TRAJ_KEYWORDS_REGEX, VASP_FILES_REGEX, XYZ_EXTXYZ_REGEX, } from '../constants';
2
+ import { ELEM_SYMBOLS } from '../labels';
3
+ import * as math from '../math';
4
+ import { wrap_to_unit_cell } from './pbc';
5
+ import { normalize_scientific_notation } from '../utils';
6
+ import { load as yaml_load } from 'js-yaml';
7
+ const cif_coords_key = (coords) => `${coords[0].toFixed(6)},${coords[1].toFixed(6)},${coords[2].toFixed(6)}`;
8
+ const cif_site_key = (element, abc, label) => `${element}|${label}|${cif_coords_key(abc)}`;
9
+ const clone_structure_properties = (properties) => structuredClone(properties);
10
+ const FALLBACK_ELEMENTS = [`H`, `He`, `Li`, `Be`, `B`, `C`, `N`, `O`, `F`, `Ne`];
11
+ const is_known_element_symbol = (symbol) => ELEM_SYMBOLS.includes(symbol);
12
+ const vec3_from_values = (values, context) => {
13
+ if (values?.length !== 3) {
14
+ throw new Error(`Invalid ${context}: expected 3 coordinates, got ${values?.length ?? 0}`);
15
+ }
16
+ const coords = math.finite_vec3_from_values(values);
17
+ if (coords)
18
+ return coords;
19
+ for (let idx = 0; idx < 3; idx++) {
20
+ const value = values[idx];
21
+ if (typeof value !== `number` || !Number.isFinite(value)) {
22
+ throw new TypeError(`Invalid ${context}: coordinate ${idx} must be finite, got ${String(value)}`);
23
+ }
24
+ }
25
+ throw new Error(`Invalid ${context}: expected 3 finite coordinates`);
26
+ };
27
+ // Parse a coordinate value that might be in various scientific notation formats
28
+ function parse_coordinate(str) {
29
+ const normalized = normalize_scientific_notation(str.trim());
30
+ const value = parseFloat(normalized);
31
+ if (isNaN(value))
32
+ throw new Error(`Invalid coordinate value: ${str}`);
33
+ return value;
34
+ }
35
+ // Parse coordinates from a line, handling malformed formatting
36
+ function parse_coordinate_line(line) {
37
+ let tokens = line.trim().split(/\s+/);
38
+ // Handle malformed coordinates like "1.0-2.0-3.0" (missing spaces)
39
+ if (tokens.length < 3) {
40
+ // Insert a space only for subtraction between numbers, not exponent signs (e/E)
41
+ const sanitized = line
42
+ .trim()
43
+ // Add space when '-' follows a digit and precedes a digit or dot
44
+ .replace(/(\d)-(?=[\d.])/g, `$1 -`)
45
+ // Revert accidental spaces after exponent markers
46
+ .replace(/([eE])\s-\s/g, `$1-`);
47
+ tokens = sanitized.split(/\s+/);
48
+ }
49
+ if (tokens.length < 3)
50
+ throw new Error(`Insufficient coordinates in line: ${line}`);
51
+ return tokens.slice(0, 3).map(parse_coordinate);
52
+ }
53
+ // Validate element symbol and provide fallback
54
+ function validate_element_symbol(symbol, index) {
55
+ // Clean symbol (remove suffixes like _pv, /hash)
56
+ const clean_symbol = symbol.split(/[_/]/)[0];
57
+ if (is_known_element_symbol(clean_symbol))
58
+ return clean_symbol;
59
+ // Fallback to default elements by atomic number
60
+ const fallback = FALLBACK_ELEMENTS[index % FALLBACK_ELEMENTS.length] ?? `H`;
61
+ console.warn(`Invalid element symbol '${symbol}', using fallback '${fallback}'`);
62
+ return fallback;
63
+ }
64
+ const try_create_cart_to_frac = (lattice_matrix) => {
65
+ try {
66
+ return math.create_cart_to_frac(lattice_matrix);
67
+ }
68
+ catch {
69
+ return null;
70
+ }
71
+ };
72
+ const approximate_cart_to_frac = (xyz, axis_lengths) => [
73
+ Math.abs(axis_lengths[0]) > math.EPS ? xyz[0] / axis_lengths[0] : 0,
74
+ Math.abs(axis_lengths[1]) > math.EPS ? xyz[1] / axis_lengths[1] : 0,
75
+ Math.abs(axis_lengths[2]) > math.EPS ? xyz[2] / axis_lengths[2] : 0,
76
+ ];
77
+ // Parse VASP POSCAR file format
78
+ export function parse_poscar(content) {
79
+ try {
80
+ const lines = content.replace(/^\s+/, ``).split(/\r?\n/);
81
+ if (lines.length < 8) {
82
+ console.error(`POSCAR file too short`);
83
+ return null;
84
+ }
85
+ // Parse scaling factor (line 2)
86
+ let scale_factor = parseFloat(lines[1]);
87
+ if (isNaN(scale_factor)) {
88
+ console.error(`Invalid scaling factor in POSCAR`);
89
+ return null;
90
+ }
91
+ // Parse lattice vectors (lines 3-5)
92
+ const parse_vector = (line, line_num) => {
93
+ const coords = line.trim().split(/\s+/).map(parse_coordinate);
94
+ return vec3_from_values(coords, `lattice vector on line ${line_num}`);
95
+ };
96
+ const lattice_vecs = [
97
+ parse_vector(lines[2], 3),
98
+ parse_vector(lines[3], 4),
99
+ parse_vector(lines[4], 5),
100
+ ];
101
+ // Handle negative scale factor (volume-based scaling)
102
+ if (scale_factor < 0) {
103
+ const volume = Math.abs(math.det_3x3(lattice_vecs));
104
+ scale_factor = Math.pow(-scale_factor / volume, 1 / 3);
105
+ }
106
+ // Scale lattice vectors
107
+ const scaled_lattice = [
108
+ math.scale(lattice_vecs[0], scale_factor),
109
+ math.scale(lattice_vecs[1], scale_factor),
110
+ math.scale(lattice_vecs[2], scale_factor),
111
+ ];
112
+ // Parse element symbols and atom counts (may span multiple lines)
113
+ let line_index = 5;
114
+ let element_symbols = [];
115
+ let atom_counts = [];
116
+ // Detect if this is VASP 5+ format (has element symbols)
117
+ // Try to parse the first token as a number - if it succeeds, it's VASP 4 format
118
+ const first_token = lines[line_index].trim().split(/\s+/)[0];
119
+ const first_token_as_number = parseInt(first_token);
120
+ const has_element_symbols = isNaN(first_token_as_number);
121
+ if (has_element_symbols) {
122
+ // VASP 5+ format - parse element symbols (may span multiple lines)
123
+ let symbol_lines = 1;
124
+ // Look ahead to find where numbers start (atom counts)
125
+ for (let lookahead_idx = 1; lookahead_idx < 10; lookahead_idx++) {
126
+ if (line_index + lookahead_idx >= lines.length)
127
+ break;
128
+ const next_line_first_token = lines[line_index + lookahead_idx].trim().split(/\s+/)[0];
129
+ const next_token_as_number = parseInt(next_line_first_token);
130
+ if (!isNaN(next_token_as_number)) {
131
+ symbol_lines = lookahead_idx;
132
+ break;
133
+ }
134
+ }
135
+ // Collect all element symbols from the symbol lines
136
+ for (let symbol_line_idx = 0; symbol_line_idx < symbol_lines; symbol_line_idx++) {
137
+ if (line_index + symbol_line_idx < lines.length) {
138
+ element_symbols.push(...lines[line_index + symbol_line_idx].trim().split(/\s+/));
139
+ }
140
+ }
141
+ // Parse atom counts (may span multiple lines)
142
+ for (let count_line_idx = 0; count_line_idx < symbol_lines; count_line_idx++) {
143
+ if (line_index + symbol_lines + count_line_idx < lines.length) {
144
+ const counts = lines[line_index + symbol_lines + count_line_idx]
145
+ .trim()
146
+ .split(/\s+/)
147
+ .map(Number);
148
+ atom_counts.push(...counts);
149
+ }
150
+ }
151
+ line_index += 2 * symbol_lines;
152
+ }
153
+ else {
154
+ // VASP 4 format - only atom counts, generate default element symbols
155
+ atom_counts = lines[line_index].trim().split(/\s+/).map(Number);
156
+ element_symbols = atom_counts.map((_, idx) => validate_element_symbol(`Element${idx}`, idx));
157
+ line_index += 1;
158
+ }
159
+ if (element_symbols.length !== atom_counts.length) {
160
+ console.error(`Mismatch between element symbols and atom counts`);
161
+ return null;
162
+ }
163
+ // Check for selective dynamics
164
+ let has_selective_dynamics = false;
165
+ if (line_index < lines.length) {
166
+ let coordinate_mode = lines[line_index].trim().toUpperCase();
167
+ if (coordinate_mode.startsWith(`S`)) {
168
+ has_selective_dynamics = true;
169
+ line_index += 1;
170
+ if (line_index < lines.length) {
171
+ coordinate_mode = lines[line_index].trim().toUpperCase();
172
+ }
173
+ else {
174
+ console.error(`Missing coordinate mode after selective dynamics`);
175
+ return null;
176
+ }
177
+ }
178
+ // Determine coordinate mode
179
+ const is_direct = coordinate_mode.startsWith(`D`);
180
+ const is_cartesian = coordinate_mode.startsWith(`C`) || coordinate_mode.startsWith(`K`);
181
+ if (!is_direct && !is_cartesian) {
182
+ console.error(`Unknown coordinate mode in POSCAR: ${coordinate_mode}`);
183
+ return null;
184
+ }
185
+ // Parse atomic positions
186
+ const poscar_axis_lengths = [
187
+ Math.hypot(...scaled_lattice[0]),
188
+ Math.hypot(...scaled_lattice[1]),
189
+ Math.hypot(...scaled_lattice[2]),
190
+ ];
191
+ const poscar_frac_to_cart = math.create_frac_to_cart(scaled_lattice);
192
+ const poscar_cart_to_frac = try_create_cart_to_frac(scaled_lattice);
193
+ if (!is_direct && !poscar_cart_to_frac) {
194
+ console.warn(`POSCAR: singular lattice, using axis-length fallback for cart→frac`);
195
+ }
196
+ const sites = [];
197
+ let atom_index = 0;
198
+ for (let elem_idx = 0; elem_idx < element_symbols.length; elem_idx++) {
199
+ const element = validate_element_symbol(element_symbols[elem_idx], elem_idx);
200
+ const count = atom_counts[elem_idx];
201
+ for (let atom_count_idx = 0; atom_count_idx < count; atom_count_idx++) {
202
+ const coord_line_idx = line_index + 1 + atom_index + atom_count_idx;
203
+ if (coord_line_idx >= lines.length) {
204
+ console.error(`Not enough coordinate lines in POSCAR`);
205
+ return null;
206
+ }
207
+ const coords = vec3_from_values(parse_coordinate_line(lines[coord_line_idx]), `POSCAR atom coordinates on line ${coord_line_idx + 1}`);
208
+ // Parse selective dynamics if present
209
+ let selective_dynamics;
210
+ if (has_selective_dynamics) {
211
+ const tokens = lines[coord_line_idx].trim().split(/\s+/);
212
+ if (tokens.length >= 6) {
213
+ selective_dynamics = [tokens[3] === `T`, tokens[4] === `T`, tokens[5] === `T`];
214
+ }
215
+ }
216
+ let xyz;
217
+ let abc;
218
+ if (is_direct) {
219
+ // Store fractional coordinates, wrapping to [0, 1) range
220
+ abc = wrap_to_unit_cell(coords);
221
+ xyz = poscar_frac_to_cart(abc);
222
+ }
223
+ else {
224
+ // Already Cartesian, scale if needed
225
+ xyz = math.scale(coords, scale_factor);
226
+ const raw_abc = poscar_cart_to_frac
227
+ ? poscar_cart_to_frac(xyz)
228
+ : approximate_cart_to_frac(xyz, poscar_axis_lengths);
229
+ // Wrap fractional coordinates to [0, 1) range
230
+ abc = wrap_to_unit_cell(raw_abc);
231
+ }
232
+ const site = {
233
+ species: [{ element, occu: 1, oxidation_state: 0 }],
234
+ abc,
235
+ xyz,
236
+ label: `${element}${atom_index + atom_count_idx + 1}`,
237
+ properties: selective_dynamics ? { selective_dynamics: selective_dynamics } : {},
238
+ };
239
+ sites.push(site);
240
+ }
241
+ atom_index += count;
242
+ }
243
+ const lattice_params = math.calc_lattice_params(scaled_lattice);
244
+ const structure = {
245
+ sites,
246
+ lattice: { matrix: scaled_lattice, ...lattice_params },
247
+ };
248
+ return structure;
249
+ }
250
+ else {
251
+ console.error(`Missing coordinate mode line in POSCAR`);
252
+ return null;
253
+ }
254
+ }
255
+ catch (error) {
256
+ console.error(`Error parsing POSCAR file:`, error);
257
+ return null;
258
+ }
259
+ }
260
+ // Parse XYZ file format. Supports both standard XYZ and extended XYZ formats with multi-frame support
261
+ export function parse_xyz(content) {
262
+ try {
263
+ const normalized_content = content.trim();
264
+ if (!normalized_content) {
265
+ console.error(`Empty XYZ file`);
266
+ return null;
267
+ }
268
+ // Split into frames by reading the atom count and slicing lines
269
+ const all_lines = normalized_content.split(/\r?\n/);
270
+ const frames = [];
271
+ let frame_line_idx = 0;
272
+ while (frame_line_idx < all_lines.length) {
273
+ const numAtoms = parseInt(all_lines[frame_line_idx].trim(), 10);
274
+ if (!isNaN(numAtoms) &&
275
+ numAtoms > 0 &&
276
+ frame_line_idx + numAtoms + 1 < all_lines.length) {
277
+ const frameLines = all_lines.slice(frame_line_idx, frame_line_idx + numAtoms + 2);
278
+ frames.push(frameLines.join(`\n`));
279
+ frame_line_idx += numAtoms + 2;
280
+ }
281
+ else
282
+ frame_line_idx++;
283
+ }
284
+ // If no frames found, try simple parsing
285
+ if (frames.length === 0)
286
+ frames.push(normalized_content);
287
+ // Parse the last frame (or only frame)
288
+ const frame_content = frames.at(-1) ?? ``;
289
+ const lines = frame_content.trim().split(/\r?\n/);
290
+ if (lines.length < 2) {
291
+ console.error(`XYZ frame too short`);
292
+ return null;
293
+ }
294
+ // Parse number of atoms (line 1)
295
+ const num_atoms = parseInt(lines[0].trim());
296
+ if (isNaN(num_atoms) || num_atoms <= 0) {
297
+ console.error(`Invalid number of atoms in XYZ file`);
298
+ return null;
299
+ }
300
+ // Parse comment line (line 2) - may contain lattice info for extended XYZ
301
+ const comment_line = lines[1];
302
+ let lattice;
303
+ // Check for extended XYZ lattice information in comment line
304
+ const lattice_match = /Lattice="([^"]+)"/.exec(comment_line);
305
+ if (lattice_match) {
306
+ const lattice_values = lattice_match[1].split(/\s+/).map(parse_coordinate);
307
+ if (lattice_values.length === 9) {
308
+ const lattice_vectors = [
309
+ vec3_from_values(lattice_values.slice(0, 3), `XYZ lattice vector 1`),
310
+ vec3_from_values(lattice_values.slice(3, 6), `XYZ lattice vector 2`),
311
+ vec3_from_values(lattice_values.slice(6, 9), `XYZ lattice vector 3`),
312
+ ];
313
+ const lattice_params = math.calc_lattice_params(lattice_vectors);
314
+ lattice = { matrix: lattice_vectors, ...lattice_params };
315
+ }
316
+ }
317
+ // Parse atomic coordinates (starting from line 3)
318
+ const xyz_axis_lengths = lattice ? [lattice.a, lattice.b, lattice.c] : null;
319
+ let xyz_frac_to_cart = null;
320
+ let xyz_cart_to_frac = null;
321
+ if (lattice) {
322
+ xyz_frac_to_cart = math.create_frac_to_cart(lattice.matrix);
323
+ xyz_cart_to_frac = try_create_cart_to_frac(lattice.matrix);
324
+ }
325
+ const sites = [];
326
+ for (let atom_idx = 0; atom_idx < num_atoms; atom_idx++) {
327
+ const line_idx = atom_idx + 2;
328
+ if (line_idx >= lines.length) {
329
+ console.error(`Not enough coordinate lines in XYZ file`);
330
+ return null;
331
+ }
332
+ const parts = lines[line_idx].trim().split(/\s+/);
333
+ if (parts.length < 4) {
334
+ console.error(`Invalid coordinate line in XYZ file`);
335
+ return null;
336
+ }
337
+ const element = validate_element_symbol(parts[0], atom_idx);
338
+ const xyz = vec3_from_values(parts.slice(1, 4).map(parse_coordinate), `XYZ atom position ${atom_idx + 1}`);
339
+ // Calculate fractional coordinates if lattice is available
340
+ let abc = [0, 0, 0];
341
+ if (lattice && xyz_frac_to_cart && xyz_axis_lengths) {
342
+ abc = xyz_cart_to_frac
343
+ ? xyz_cart_to_frac(xyz)
344
+ : approximate_cart_to_frac(xyz, xyz_axis_lengths);
345
+ // Ensure fractional coordinates are wrapped into [0, 1) for consistency
346
+ abc = wrap_to_unit_cell(abc);
347
+ // Keep rendered atoms inside primary unit cell by recomputing xyz
348
+ const wrapped_xyz = xyz_frac_to_cart(abc);
349
+ xyz[0] = wrapped_xyz[0];
350
+ xyz[1] = wrapped_xyz[1];
351
+ xyz[2] = wrapped_xyz[2];
352
+ }
353
+ const species = [{ element, occu: 1, oxidation_state: 0 }];
354
+ const label = `${element}${atom_idx + 1}`;
355
+ const site = { species, abc, xyz, label, properties: {} };
356
+ sites.push(site);
357
+ }
358
+ const structure = { sites, ...(lattice && { lattice }) };
359
+ return structure;
360
+ }
361
+ catch (error) {
362
+ console.error(`Error parsing XYZ file:`, error);
363
+ return null;
364
+ }
365
+ }
366
+ // Parse a single symmetry expression dimension (e.g., "x-y+1/3" or "-x+y")
367
+ // Returns the numeric coefficient for each variable and the translation constant
368
+ const parse_symmetry_expression = (expr_input) => {
369
+ const coefficients = [0, 0, 0];
370
+ let translation = 0;
371
+ // Remove all whitespace
372
+ const expr = expr_input.replace(/\s+/g, ``);
373
+ if (!expr)
374
+ return { coefficients, translation };
375
+ // Tokenize: split into terms while preserving signs
376
+ // E.g., "x-y+1/3" → ["x", "-y", "+1/3"] or "-x+y" → ["-x", "+y"]
377
+ const tokens = [];
378
+ let current_token = ``;
379
+ for (let idx = 0; idx < expr.length; idx++) {
380
+ const char = expr[idx];
381
+ if ((char === `+` || char === `-`) && current_token.length > 0) {
382
+ tokens.push(current_token);
383
+ current_token = char;
384
+ }
385
+ else {
386
+ current_token += char;
387
+ }
388
+ }
389
+ if (current_token)
390
+ tokens.push(current_token);
391
+ for (const token of tokens) {
392
+ // Check if this token is a variable term (x, y, or z with optional sign)
393
+ const var_match = /^([+-]?)([xyz])$/.exec(token);
394
+ if (var_match) {
395
+ const sign = var_match[1] === `-` ? -1 : 1;
396
+ const var_char = var_match[2];
397
+ const var_idx = var_char === `x` ? 0 : var_char === `y` ? 1 : 2;
398
+ coefficients[var_idx] += sign;
399
+ continue;
400
+ }
401
+ // Check if this is a numeric term (integer, decimal, or fraction)
402
+ let sign = 1;
403
+ let num_str = token;
404
+ // Handle leading sign
405
+ if (num_str.startsWith(`+`)) {
406
+ num_str = num_str.slice(1);
407
+ }
408
+ else if (num_str.startsWith(`-`)) {
409
+ sign = -1;
410
+ num_str = num_str.slice(1);
411
+ }
412
+ // Skip empty tokens (from dangling operators like "x+")
413
+ if (!num_str || num_str === `+` || num_str === `-`)
414
+ continue;
415
+ if (num_str.includes(`/`)) {
416
+ // Fraction
417
+ const parts = num_str.split(`/`);
418
+ if (parts.length === 2) {
419
+ const numerator = parseFloat(parts[0]);
420
+ const denominator = parseFloat(parts[1]);
421
+ if (!isNaN(numerator) && !isNaN(denominator) && denominator !== 0) {
422
+ translation += sign * (numerator / denominator);
423
+ }
424
+ }
425
+ }
426
+ else {
427
+ // Integer or decimal
428
+ const val = parseFloat(num_str);
429
+ if (!isNaN(val)) {
430
+ translation += sign * val;
431
+ }
432
+ }
433
+ }
434
+ return { coefficients, translation };
435
+ };
436
+ // Apply symmetry operations to generate equivalent positions
437
+ const apply_symmetry_ops = (atom, symmetry_ops, wrap_fractional_coords) => {
438
+ if (symmetry_ops.length === 0)
439
+ return [atom];
440
+ const equivalent_atoms = [];
441
+ const seen = new Set();
442
+ const wrap = (coords) => wrap_fractional_coords ? wrap_to_unit_cell(coords) : coords;
443
+ // Use 6 decimal places for deduplication to handle floating point imprecision
444
+ // from compound symmetry operations like x-y, -x+y which can produce small errors
445
+ // Always include base atom (optionally wrapped)
446
+ const base_coords = wrap(atom.coords);
447
+ seen.add(cif_coords_key(base_coords));
448
+ equivalent_atoms.push({ ...atom, coords: base_coords });
449
+ for (const operation of symmetry_ops) {
450
+ const operation_match = /['"]([^'"]+)['"]/.exec(operation);
451
+ const expr_str = operation_match ? operation_match[1] : operation.trim();
452
+ const parts = expr_str.split(`,`).map((part) => part.trim());
453
+ if (parts.length !== 3)
454
+ continue;
455
+ const new_coords = [0, 0, 0];
456
+ for (let dim = 0; dim < 3; dim++) {
457
+ const { coefficients, translation } = parse_symmetry_expression(parts[dim]);
458
+ // Apply: new_coord = coeff_x * x + coeff_y * y + coeff_z * z + translation
459
+ new_coords[dim] =
460
+ coefficients[0] * atom.coords[0] +
461
+ coefficients[1] * atom.coords[1] +
462
+ coefficients[2] * atom.coords[2] +
463
+ translation;
464
+ }
465
+ // Wrap and deduplicate transformed coordinates
466
+ const wrapped = wrap(new_coords);
467
+ const cache_key = cif_coords_key(wrapped);
468
+ if (seen.has(cache_key))
469
+ continue;
470
+ seen.add(cache_key);
471
+ equivalent_atoms.push({
472
+ ...atom,
473
+ coords: wrapped,
474
+ id: `${atom.id}_${equivalent_atoms.length}`,
475
+ });
476
+ }
477
+ return equivalent_atoms;
478
+ };
479
+ const extract_cif_cell_parameters = (text, type, strict = true) => text
480
+ .split(`\n`)
481
+ .filter((line) => line.startsWith(`_${type}`))
482
+ .map((line) => {
483
+ const tokens = line.split(/\s+/).filter((token) => token.length > 0);
484
+ if (tokens.length < 2) {
485
+ if (strict)
486
+ throw new Error(`Invalid CIF cell parameter line format: ${line}`);
487
+ return null;
488
+ }
489
+ const value = parseFloat((tokens.at(-1) ?? ``).split(`(`)[0]);
490
+ if (isNaN(value)) {
491
+ if (strict)
492
+ throw new Error(`Invalid CIF cell parameter in line: ${line}`);
493
+ return null; // Return null for invalid values in non-strict mode
494
+ }
495
+ return value;
496
+ })
497
+ .filter((val) => val !== null);
498
+ // build header index mapping for atom site data (supports fract and Cartn coordinates)
499
+ const build_cif_atom_site_header_indices = (headers) => {
500
+ const indices = {};
501
+ const mappings = [
502
+ [`_atom_site_label`, `label`],
503
+ [`_atom_site_type_symbol`, `symbol`],
504
+ [`_atom_site_fract_x`, `x`],
505
+ [`_atom_site_fract_y`, `y`],
506
+ [`_atom_site_fract_z`, `z`],
507
+ [`_atom_site_cartn_x`, `cart_x`],
508
+ [`_atom_site_cartn_y`, `cart_y`],
509
+ [`_atom_site_cartn_z`, `cart_z`],
510
+ [`_atom_site_occupancy`, `occupancy`],
511
+ [`_atom_site_disorder_group`, `disorder`],
512
+ ];
513
+ headers.forEach((header, idx) => {
514
+ const lower = header.trim().toLowerCase();
515
+ const mapping = mappings.find(([suffix]) => lower.endsWith(suffix));
516
+ if (mapping)
517
+ indices[mapping[1]] = idx;
518
+ });
519
+ return indices;
520
+ };
521
+ // Parse atom data from CIF with robust error handling
522
+ const parse_cif_atom_data = (raw_data, indices, coords_type) => {
523
+ const { label = 0, symbol = -1, occupancy = -1 } = indices;
524
+ const coord_indices = coords_type === `fract`
525
+ ? [indices.x, indices.y, indices.z]
526
+ : [indices.cart_x, indices.cart_y, indices.cart_z];
527
+ if (coord_indices.some((idx) => idx === undefined)) {
528
+ throw new Error(`Missing coordinate indices`);
529
+ }
530
+ const coords_triplet = vec3_from_values(coord_indices.map((idx) => {
531
+ if (idx === undefined)
532
+ throw new Error(`Invalid coordinate index`);
533
+ const coord_str = raw_data[idx];
534
+ if (!coord_str)
535
+ throw new Error(`Missing coordinate at index ${idx}`);
536
+ const coord = parseFloat(coord_str.split(`(`)[0]);
537
+ if (isNaN(coord))
538
+ throw new Error(`Invalid coordinate: ${coord_str}`);
539
+ return coord;
540
+ }), `CIF atom coordinates`);
541
+ const occu = occupancy >= 0 && raw_data[occupancy]
542
+ ? parseFloat(raw_data[occupancy].split(`(`)[0]) || 1.0
543
+ : 1.0;
544
+ const element_symbol = (symbol >= 0 && /^([A-Z][a-z]*)/.exec(raw_data[symbol])?.[1]) ||
545
+ raw_data[label]?.match(/([A-Z][a-z]*)/g)?.[0] ||
546
+ (() => {
547
+ throw new Error(`Could not extract element symbol from: ${raw_data.join(` `)}`);
548
+ })();
549
+ return {
550
+ id: raw_data[label],
551
+ element: element_symbol,
552
+ coords: coords_triplet,
553
+ coords_type,
554
+ occupancy: occu,
555
+ };
556
+ };
557
+ // Parse CIF (Crystallographic Information File) format
558
+ export function parse_cif(content, wrap_fractional_coords = true, strict = true) {
559
+ try {
560
+ const text = content.trim();
561
+ if (!text) {
562
+ console.error(`CIF file is empty`);
563
+ return null;
564
+ }
565
+ // Find atom site loop that actually contains coordinates (fract or Cartn)
566
+ const lines = text.split(`\n`);
567
+ let atom_headers = [];
568
+ const atom_data_lines = [];
569
+ const symmetry_ops = [];
570
+ for (let ii = 0; ii < lines.length; ii++) {
571
+ if (lines[ii].trim() !== `loop_`)
572
+ continue;
573
+ let jj = ii + 1;
574
+ const headers = [];
575
+ // Collect headers for this loop
576
+ while (jj < lines.length && lines[jj].trim().startsWith(`_`)) {
577
+ headers.push(lines[jj].trim());
578
+ jj++;
579
+ }
580
+ // Check if this is a symmetry operations loop
581
+ if (headers.some((header) => header.includes(`_symmetry_equiv_pos_as_xyz`) ||
582
+ header.includes(`_space_group_symop_operation_xyz`))) {
583
+ // Collect symmetry operations
584
+ while (jj < lines.length) {
585
+ const line = lines[jj].trim();
586
+ if (line === `loop_` || line.startsWith(`data_`))
587
+ break;
588
+ if (line && !line.startsWith(`#`) && !line.startsWith(`;`)) {
589
+ symmetry_ops.push(line);
590
+ }
591
+ jj++;
592
+ }
593
+ continue;
594
+ }
595
+ // Not an atom-site loop → continue search
596
+ if (!headers.some((header) => header.includes(`_atom_site_`)))
597
+ continue;
598
+ // Check if this loop contains coordinate headers
599
+ const indices_preview = build_cif_atom_site_header_indices(headers);
600
+ const has_coords = (indices_preview.x !== undefined &&
601
+ indices_preview.y !== undefined &&
602
+ indices_preview.z !== undefined) ||
603
+ (indices_preview.cart_x !== undefined &&
604
+ indices_preview.cart_y !== undefined &&
605
+ indices_preview.cart_z !== undefined);
606
+ if (!has_coords) {
607
+ ii = jj - 1;
608
+ continue;
609
+ }
610
+ // This is the desired atom-site loop with coordinates: collect data lines
611
+ atom_headers = headers;
612
+ while (jj < lines.length) {
613
+ const line = lines[jj].trim();
614
+ if (line === `loop_` || line.startsWith(`data_`))
615
+ break;
616
+ if (line && !line.startsWith(`#`)) {
617
+ if (line.startsWith(`;`)) {
618
+ let multi_line_data = ``;
619
+ while (jj < lines.length && !lines[jj].trim().endsWith(`;`)) {
620
+ multi_line_data += lines[jj] + `\n`;
621
+ jj++;
622
+ }
623
+ multi_line_data += lines[jj];
624
+ atom_data_lines.push(multi_line_data.trim());
625
+ }
626
+ else {
627
+ atom_data_lines.push(line);
628
+ }
629
+ }
630
+ jj++;
631
+ }
632
+ if (atom_data_lines.length > 0)
633
+ break;
634
+ }
635
+ if (!atom_headers.length || !atom_data_lines.length) {
636
+ console.error(`No valid atom site loop found in CIF file`);
637
+ return null;
638
+ }
639
+ // Parse atom data with error handling
640
+ const header_indices = build_cif_atom_site_header_indices(atom_headers);
641
+ // Determine available coordinate type
642
+ const coords_type = header_indices.x !== undefined &&
643
+ header_indices.y !== undefined &&
644
+ header_indices.z !== undefined
645
+ ? `fract`
646
+ : header_indices.cart_x !== undefined &&
647
+ header_indices.cart_y !== undefined &&
648
+ header_indices.cart_z !== undefined
649
+ ? `cart`
650
+ : null;
651
+ if (!coords_type) {
652
+ console.error(`CIF atom site loop missing coordinates (fract or Cartn)`);
653
+ return null;
654
+ }
655
+ // Collect required coordinate indices
656
+ const required_indices = coords_type === `fract`
657
+ ? [header_indices.x, header_indices.y, header_indices.z]
658
+ : [header_indices.cart_x, header_indices.cart_y, header_indices.cart_z];
659
+ const atoms = atom_data_lines
660
+ .map((line) => {
661
+ // Handle quoted multi-word values by splitting only on whitespace
662
+ // that is not inside quotes.
663
+ const tokens = line.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || [];
664
+ return tokens.map((token) => token.replace(/['"]/g, ``));
665
+ })
666
+ .filter((tokens) => {
667
+ const { disorder } = header_indices;
668
+ const max_required_idx = Math.max(...required_indices);
669
+ return (!(disorder !== undefined && tokens[disorder] === `2`) &&
670
+ tokens.length > max_required_idx);
671
+ })
672
+ .map((tokens) => {
673
+ try {
674
+ return parse_cif_atom_data(tokens, header_indices, coords_type);
675
+ }
676
+ catch (error) {
677
+ console.warn(`Skipping invalid atom data: ${error}`);
678
+ return null;
679
+ }
680
+ })
681
+ .filter((atom) => atom !== null);
682
+ if (!atoms.length) {
683
+ console.error(`No valid atoms found in CIF file`);
684
+ return null;
685
+ }
686
+ // Extract cell parameters and build lattice
687
+ const lengths = extract_cif_cell_parameters(text, `cell_length`, strict);
688
+ const angles = extract_cif_cell_parameters(text, `cell_angle`, strict);
689
+ if (lengths.length < 3 || angles.length < 3) {
690
+ console.error(`Insufficient cell parameters in CIF file`);
691
+ return null;
692
+ }
693
+ // Build lattice and create sites
694
+ const [a, b, c] = lengths;
695
+ const [alpha, beta, gamma] = angles;
696
+ const lattice_matrix = math.cell_to_lattice_matrix(a, b, c, alpha, beta, gamma);
697
+ const lattice_params = math.calc_lattice_params(lattice_matrix);
698
+ const frac_to_cart = math.create_frac_to_cart(lattice_matrix);
699
+ const cart_to_frac = try_create_cart_to_frac(lattice_matrix);
700
+ // Create sites with coordinate conversion and symmetry operations
701
+ const wrap_vec3 = (v) => (wrap_fractional_coords ? wrap_to_unit_cell(v) : v);
702
+ // Apply symmetry operations to generate all equivalent positions
703
+ const all_sites = [];
704
+ // Normalize symmetry operations (trim/strip quotes) but preserve duplicates; we deduplicate positions later
705
+ const normalized_ops = symmetry_ops
706
+ .map((op) => /['"]([^'"]+)['"]/.exec(op)?.[1] || op.trim())
707
+ .map((op) => op.replace(/\s+/g, ``));
708
+ // Rely on symmetry operations list for all centering/translations to avoid double-counting
709
+ // TODO: Support conventional cells with centering by discovering centering from space group metadata
710
+ // when present (e.g. P, I, F, C, R centering types)
711
+ const centering_vectors = [[0, 0, 0]];
712
+ // Inspect optional _atom_type_number_in_cell loop to see if atom sites are already expanded
713
+ const atom_type_counts = (() => {
714
+ const map = {};
715
+ const text_lines = text.split(`\n`);
716
+ for (let li = 0; li < text_lines.length; li++) {
717
+ if (text_lines[li].trim() !== `loop_`) {
718
+ continue;
719
+ }
720
+ let lj = li + 1;
721
+ const hdrs = [];
722
+ while (lj < text_lines.length && text_lines[lj].trim().startsWith(`_`)) {
723
+ hdrs.push(text_lines[lj].trim().toLowerCase());
724
+ lj++;
725
+ }
726
+ const sym_idx = hdrs.findIndex((hdr) => hdr.endsWith(`_atom_type_symbol`));
727
+ const num_idx = hdrs.findIndex((hdr) => hdr.endsWith(`_atom_type_number_in_cell`));
728
+ if (sym_idx !== -1 && num_idx !== -1) {
729
+ while (lj < text_lines.length) {
730
+ const line = text_lines[lj].trim();
731
+ if (!line || line === `loop_` || line.startsWith(`data_`))
732
+ break;
733
+ if (line.startsWith(`#`)) {
734
+ lj++;
735
+ continue;
736
+ }
737
+ const toks = (line.match(/(?:[^\s"']+|"[^"]*"|'[^']*')+/g) || []).map((tok) => tok.replace(/['"]/g, ``));
738
+ if (toks.length > Math.max(sym_idx, num_idx)) {
739
+ // Normalize type symbol to bare element (e.g. 'Sn2+' -> 'Sn')
740
+ const match = /^([A-Z][a-z]*)/.exec(toks[sym_idx]);
741
+ const sym = match ? match[1] : toks[sym_idx];
742
+ const num = parseInt(toks[num_idx]);
743
+ if (sym && !Number.isNaN(num))
744
+ map[sym] = num;
745
+ }
746
+ lj++;
747
+ }
748
+ break;
749
+ }
750
+ }
751
+ return map;
752
+ })();
753
+ const observed_counts = {};
754
+ for (const atom of atoms) {
755
+ observed_counts[atom.element] = (observed_counts[atom.element] || 0) + 1;
756
+ }
757
+ const has_expected_counts = Object.keys(atom_type_counts).length > 0;
758
+ const already_enumerated = has_expected_counts &&
759
+ Object.entries(atom_type_counts).every(([el, exp]) => (observed_counts[el] || 0) >= exp);
760
+ const ops_to_use = already_enumerated ? [] : normalized_ops;
761
+ // Global deduplication of final sites (per element + coordinates + label)
762
+ // Use 6 decimal places to handle floating point imprecision from compound symmetry ops
763
+ const seen_site_keys = new Set();
764
+ for (const atom of atoms) {
765
+ const element = validate_element_symbol(atom.element, all_sites.length);
766
+ // Convert to fractional coordinates if needed
767
+ let fractional_atom;
768
+ if (atom.coords_type === `fract`) {
769
+ fractional_atom = {
770
+ ...atom,
771
+ coords: wrap_vec3(atom.coords),
772
+ coords_type: `fract`,
773
+ };
774
+ }
775
+ else {
776
+ const xyz_base = [atom.coords[0], atom.coords[1], atom.coords[2]];
777
+ const atom_abc = wrap_vec3(cart_to_frac
778
+ ? cart_to_frac(xyz_base)
779
+ : approximate_cart_to_frac(xyz_base, [a, b, c]));
780
+ fractional_atom = { ...atom, coords: atom_abc, coords_type: `fract` };
781
+ }
782
+ // First apply symmetry operations in fractional space
783
+ const equiv_atoms = apply_symmetry_ops(fractional_atom, ops_to_use, wrap_fractional_coords);
784
+ // Then apply lattice centering shifts to each equivalent position
785
+ for (const equiv_atom of equiv_atoms) {
786
+ for (const cv of centering_vectors) {
787
+ const abc = wrap_vec3([
788
+ equiv_atom.coords[0] + cv[0],
789
+ equiv_atom.coords[1] + cv[1],
790
+ equiv_atom.coords[2] + cv[2],
791
+ ]);
792
+ const key = cif_site_key(element, abc, equiv_atom.id);
793
+ if (seen_site_keys.has(key))
794
+ continue;
795
+ seen_site_keys.add(key);
796
+ const xyz = frac_to_cart(abc);
797
+ all_sites.push({
798
+ species: [{ element, occu: equiv_atom.occupancy, oxidation_state: 0 }],
799
+ abc,
800
+ xyz,
801
+ label: equiv_atom.id,
802
+ properties: {},
803
+ });
804
+ }
805
+ }
806
+ }
807
+ const sites = all_sites;
808
+ return { sites, lattice: { matrix: lattice_matrix, ...lattice_params } };
809
+ }
810
+ catch (error) {
811
+ console.error(`Error parsing CIF file:`, error);
812
+ return null;
813
+ }
814
+ }
815
+ // Convert phonopy cell to ParsedStructure
816
+ function convert_phonopy_cell(cell) {
817
+ const sites = [];
818
+ // Phonopy stores lattice vectors as rows, use them directly
819
+ const lattice_matrix = [
820
+ vec3_from_values(cell.lattice[0], `phonopy lattice vector 1`),
821
+ vec3_from_values(cell.lattice[1], `phonopy lattice vector 2`),
822
+ vec3_from_values(cell.lattice[2], `phonopy lattice vector 3`),
823
+ ];
824
+ // Process each atomic site
825
+ const phonopy_frac_to_cart = math.create_frac_to_cart(lattice_matrix);
826
+ for (const point of cell.points) {
827
+ const element = validate_element_symbol(point.symbol, sites.length);
828
+ const abc = vec3_from_values(point.coordinates, `phonopy point coordinates`);
829
+ const xyz = phonopy_frac_to_cart(abc);
830
+ const properties = {
831
+ mass: point.mass,
832
+ ...(point.reduced_to !== undefined && { reduced_to: point.reduced_to }),
833
+ };
834
+ const species = [{ element, occu: 1.0, oxidation_state: 0 }];
835
+ const site = { species, abc, xyz, label: point.symbol, properties };
836
+ sites.push(site);
837
+ }
838
+ // Calculate lattice parameters
839
+ const calculated_lattice_params = math.calc_lattice_params(lattice_matrix);
840
+ return { sites, lattice: { matrix: lattice_matrix, ...calculated_lattice_params } };
841
+ }
842
+ const is_phonopy_cell = (value) => {
843
+ if (!value || typeof value !== `object`)
844
+ return false;
845
+ const lattice = `lattice` in value ? value.lattice : undefined;
846
+ const points = `points` in value ? value.points : undefined;
847
+ return Array.isArray(lattice) && Array.isArray(points);
848
+ };
849
+ const get_phonopy_cell = (data, cell_type) => {
850
+ if (!data || typeof data !== `object`)
851
+ return undefined;
852
+ const cell = Reflect.get(data, cell_type);
853
+ return is_phonopy_cell(cell) ? cell : undefined;
854
+ };
855
+ // Parse phonopy YAML file and return the requested cell type (or preferred single structure)
856
+ export function parse_phonopy_yaml(content, cell_type) {
857
+ try {
858
+ // Parse YAML content but exclude large phonon_displacements array for performance
859
+ const lines = content.split(`\n`);
860
+ const filtered_lines = [];
861
+ let skip_displacements = false;
862
+ for (const line of lines) {
863
+ // Skip phonon_displacements section for performance
864
+ if (line.trim().startsWith(`phonon_displacements:`)) {
865
+ skip_displacements = true;
866
+ continue;
867
+ }
868
+ // Check if we're still in the phonon_displacements section
869
+ if (skip_displacements) {
870
+ if (/^[a-zA-Z_]/.exec(line)) {
871
+ // New top-level key, stop skipping
872
+ skip_displacements = false;
873
+ }
874
+ else
875
+ continue; // Still in phonon_displacements, skip this line
876
+ }
877
+ filtered_lines.push(line);
878
+ }
879
+ const filtered_content = filtered_lines.join(`\n`);
880
+ const data = yaml_load(filtered_content);
881
+ if (!data) {
882
+ console.error(`Failed to parse phonopy YAML`);
883
+ return null;
884
+ }
885
+ // If specific cell type requested, parse only that one
886
+ if (cell_type && cell_type !== `auto`) {
887
+ const cell = get_phonopy_cell(data, cell_type);
888
+ if (cell)
889
+ return convert_phonopy_cell(cell);
890
+ else {
891
+ console.error(`Requested cell type '${cell_type}' not found in phonopy YAML`);
892
+ return null;
893
+ }
894
+ }
895
+ // Auto mode: return preferred structure in order of preference
896
+ // 1. supercell (most detailed)
897
+ // 2. phonon_supercell
898
+ // 3. unit_cell
899
+ // 4. phonon_primitive_cell
900
+ // 5. primitive_cell
901
+ const auto_cell = get_phonopy_cell(data, `supercell`) ??
902
+ get_phonopy_cell(data, `phonon_supercell`) ??
903
+ get_phonopy_cell(data, `unit_cell`) ??
904
+ get_phonopy_cell(data, `phonon_primitive_cell`) ??
905
+ get_phonopy_cell(data, `primitive_cell`);
906
+ if (auto_cell)
907
+ return convert_phonopy_cell(auto_cell);
908
+ console.error(`No valid cells found in phonopy YAML`);
909
+ return null;
910
+ }
911
+ catch (error) {
912
+ console.error(`Error parsing phonopy YAML:`, error);
913
+ return null;
914
+ }
915
+ }
916
+ // Recursively search for a valid structure object in nested JSON
917
+ function find_structure_in_json(obj, visited = new WeakSet()) {
918
+ // Check if current object is null or undefined
919
+ if (obj == null)
920
+ return null;
921
+ if (typeof obj !== `object`)
922
+ return null; // If it's not an object, skip it
923
+ if (visited.has(obj))
924
+ return null; // Check for circular references
925
+ visited.add(obj);
926
+ // If it's an array, search through each element
927
+ if (Array.isArray(obj)) {
928
+ for (const item of obj) {
929
+ const result = find_structure_in_json(item, visited);
930
+ if (result)
931
+ return result;
932
+ }
933
+ return null;
934
+ }
935
+ // Check if this object looks like a valid structure
936
+ if (is_parsed_structure(obj))
937
+ return obj;
938
+ // Otherwise, recursively search through all properties
939
+ for (const value of Object.values(obj)) {
940
+ const result = find_structure_in_json(value, visited);
941
+ if (result)
942
+ return result;
943
+ }
944
+ return null;
945
+ }
946
+ // Type guard to validate structure-like objects
947
+ function is_parsed_structure(obj) {
948
+ if (!obj || typeof obj !== `object`)
949
+ return false;
950
+ const sites = `sites` in obj ? obj.sites : undefined;
951
+ if (!Array.isArray(sites) || sites.length === 0)
952
+ return false;
953
+ const first_site = sites[0];
954
+ if (!first_site || typeof first_site !== `object`)
955
+ return false;
956
+ const species = `species` in first_site ? first_site.species : undefined;
957
+ const abc = `abc` in first_site ? first_site.abc : undefined;
958
+ const xyz = `xyz` in first_site ? first_site.xyz : undefined;
959
+ const has_species = Array.isArray(species) && species.length > 0;
960
+ const has_coords = Array.isArray(abc) || Array.isArray(xyz);
961
+ return has_species && has_coords;
962
+ }
963
+ // Normalize structure coordinates: wrap fractional coords to [0,1) and recompute Cartesian
964
+ // Only normalizes when lattice matrix is available to ensure abc/xyz stay consistent
965
+ export function normalize_fractional_coords(structure) {
966
+ if (!structure.sites || structure.sites.length === 0)
967
+ return structure;
968
+ // Require lattice to ensure we can keep abc and xyz consistent after wrapping
969
+ if (!structure.lattice?.matrix)
970
+ return structure;
971
+ // Check if any sites have fractional coords outside [0, 1) range
972
+ const needs_wrapping = structure.sites.some((site) => site.abc?.some((coord) => coord < 0 || coord >= 1));
973
+ if (!needs_wrapping)
974
+ return structure;
975
+ const frac_to_cart = math.create_frac_to_cart(structure.lattice.matrix);
976
+ // Wrap fractional coordinates and recompute Cartesian
977
+ const normalized_sites = structure.sites.map((site) => {
978
+ if (!site.abc)
979
+ return site;
980
+ const wrapped_abc = wrap_to_unit_cell(site.abc);
981
+ return { ...site, abc: wrapped_abc, xyz: frac_to_cart(wrapped_abc) };
982
+ });
983
+ return { ...structure, sites: normalized_sites };
984
+ }
985
+ // Auto-detect file format and parse accordingly
986
+ export function parse_structure_file(content, filename) {
987
+ // If a filename is provided, try to detect format by file extension first
988
+ if (filename) {
989
+ // Handle compressed files by removing compression extensions
990
+ let base_filename = filename.toLowerCase();
991
+ while (COMPRESSION_EXTENSIONS_REGEX.test(base_filename)) {
992
+ base_filename = base_filename.replace(COMPRESSION_EXTENSIONS_REGEX, ``);
993
+ }
994
+ const ext = base_filename.split(`.`).pop();
995
+ // Try to detect format by file extension
996
+ if (ext === `xyz` || ext === `extxyz`)
997
+ return parse_xyz(content);
998
+ // CIF files
999
+ if (ext === `cif`)
1000
+ return parse_cif(content);
1001
+ // JSON files - try OPTIMADE JSON structure format first, then pymatgen
1002
+ if (ext === `json`) {
1003
+ try {
1004
+ // Parse once, reuse for detection and parsing
1005
+ const parsed = JSON.parse(content);
1006
+ if (is_optimade_raw(parsed)) {
1007
+ const result = parse_optimade_from_raw(parsed);
1008
+ if (result)
1009
+ return result;
1010
+ }
1011
+ // Otherwise, try to parse as pymatgen/nested structure JSON
1012
+ const structure = find_structure_in_json(parsed);
1013
+ if (structure)
1014
+ return normalize_fractional_coords(structure);
1015
+ console.error(`JSON file does not contain a valid structure format`);
1016
+ return null;
1017
+ }
1018
+ catch (error) {
1019
+ console.error(`Error parsing JSON file:`, error);
1020
+ return null;
1021
+ }
1022
+ }
1023
+ // YAML files (phonopy)
1024
+ if (ext === `yaml` || ext === `yml`)
1025
+ return parse_phonopy_yaml(content);
1026
+ // POSCAR files may not have extensions or have various names
1027
+ if (ext === `poscar` || base_filename.includes(`poscar`)) {
1028
+ return parse_poscar(content);
1029
+ }
1030
+ }
1031
+ // Try to auto-detect based on content
1032
+ const lines = content.trim().split(/\r?\n/);
1033
+ if (lines.length < 2) {
1034
+ console.error(`File too short to determine format`);
1035
+ return null;
1036
+ }
1037
+ // JSON format detection: try to parse as JSON first
1038
+ try {
1039
+ const parsed = JSON.parse(content);
1040
+ if (is_optimade_raw(parsed)) {
1041
+ const result = parse_optimade_from_raw(parsed);
1042
+ if (result)
1043
+ return result;
1044
+ }
1045
+ // Otherwise try parsing as regular JSON structure
1046
+ const structure = find_structure_in_json(parsed);
1047
+ if (structure) {
1048
+ return normalize_fractional_coords(structure);
1049
+ }
1050
+ }
1051
+ catch {
1052
+ // Not JSON, continue with other format detection
1053
+ }
1054
+ // XYZ format detection: first line should be a number, second line is comment
1055
+ const first_line_number = parseInt(lines[0].trim());
1056
+ if (!isNaN(first_line_number) && first_line_number > 0) {
1057
+ // Check if this looks like XYZ format
1058
+ if (lines.length >= first_line_number + 2) {
1059
+ // Try to parse a coordinate line to see if it looks like XYZ
1060
+ const coord_line_idx = 2; // First coordinate line in XYZ
1061
+ if (coord_line_idx < lines.length) {
1062
+ const parts = lines[coord_line_idx].trim().split(/\s+/);
1063
+ // XYZ format: element symbol followed by 3 coordinates
1064
+ if (parts.length >= 4) {
1065
+ const first_token = parts[0];
1066
+ const coords = parts.slice(1, 4);
1067
+ // Check if first token looks like an element symbol (not a number)
1068
+ // and the next 3 tokens look like coordinates (numbers)
1069
+ const is_element_symbol = isNaN(parseInt(first_token)) && first_token.length <= 3;
1070
+ const are_coordinates = coords.every((coord) => !isNaN(parseFloat(coord)));
1071
+ if (is_element_symbol && are_coordinates) {
1072
+ // First token is likely an element symbol, likely XYZ
1073
+ return parse_xyz(content);
1074
+ }
1075
+ }
1076
+ }
1077
+ }
1078
+ }
1079
+ // POSCAR format detection: look for typical structure
1080
+ if (lines.length >= 8) {
1081
+ const second_line_number = parseFloat(lines[1].trim());
1082
+ // Second line is a number (scale factor), likely POSCAR
1083
+ if (!isNaN(second_line_number))
1084
+ return parse_poscar(content);
1085
+ }
1086
+ // CIF format detection: look for CIF-specific keywords
1087
+ const has_cif_keywords = lines.some((line) => line.startsWith(`data_`) ||
1088
+ line.includes(`_cell_length_`) ||
1089
+ line.includes(`_atom_site_`) ||
1090
+ line.trim() === `loop_`);
1091
+ if (has_cif_keywords)
1092
+ return parse_cif(content);
1093
+ // YAML format detection: look for phonopy-specific keywords
1094
+ const has_phonopy_keywords = lines.some((line) => line.includes(`phono3py:`) ||
1095
+ line.includes(`phonopy:`) ||
1096
+ line.includes(`primitive_cell:`) ||
1097
+ line.includes(`supercell:`) ||
1098
+ line.includes(`phonon_supercell:`));
1099
+ if (has_phonopy_keywords)
1100
+ return parse_phonopy_yaml(content);
1101
+ console.error(`Unable to determine file format`);
1102
+ return null;
1103
+ }
1104
+ // Universal parser that handles JSON and structure files
1105
+ export function parse_any_structure(content, filename) {
1106
+ const finalize_structure = (structure) => ({
1107
+ sites: structure.sites,
1108
+ charge: 0,
1109
+ ...(structure.properties && {
1110
+ properties: clone_structure_properties(structure.properties),
1111
+ }),
1112
+ ...(structure.lattice && {
1113
+ lattice: { ...structure.lattice, pbc: [true, true, true] },
1114
+ }),
1115
+ });
1116
+ // Try JSON first, but handle nested structures properly
1117
+ try {
1118
+ const parsed = JSON.parse(content);
1119
+ // Check if it's already a valid structure using proper type guard
1120
+ if (is_parsed_structure(parsed)) {
1121
+ // Normalize coordinates (wrap fractional to [0,1) and recompute Cartesian)
1122
+ return finalize_structure(normalize_fractional_coords(parsed));
1123
+ }
1124
+ // If not, use parse_structure_file to find nested structures
1125
+ const structure = parse_structure_file(content, filename);
1126
+ return structure ? finalize_structure(structure) : null;
1127
+ }
1128
+ catch {
1129
+ // Try structure file formats
1130
+ const parsed = parse_structure_file(content, filename);
1131
+ return parsed ? finalize_structure(parsed) : null;
1132
+ }
1133
+ }
1134
+ // Parse OPTIMADE JSON format
1135
+ export function parse_optimade_json(content) {
1136
+ try {
1137
+ const raw = JSON.parse(content);
1138
+ return parse_optimade_from_raw(raw);
1139
+ }
1140
+ catch (error) {
1141
+ console.error(`Error parsing OPTIMADE JSON:`, error);
1142
+ return null;
1143
+ }
1144
+ }
1145
+ // Parse OPTIMADE from already-parsed JSON
1146
+ export function parse_optimade_from_raw(raw) {
1147
+ try {
1148
+ const structure = extract_optimade_structure_from_raw(raw);
1149
+ if (!structure) {
1150
+ console.error(`No valid OPTIMADE structure found in JSON`);
1151
+ return null;
1152
+ }
1153
+ const attrs = structure.attributes;
1154
+ // Inline validation for conciseness
1155
+ const positions_raw = attrs.cartesian_site_positions;
1156
+ const species_raw = attrs.species_at_sites;
1157
+ if (!(Array.isArray(positions_raw) && Array.isArray(species_raw))) {
1158
+ console.error(`OPTIMADE JSON missing required position or species data`);
1159
+ return null;
1160
+ }
1161
+ if (positions_raw.length !== species_raw.length) {
1162
+ console.error(`OPTIMADE JSON position/species count mismatch`);
1163
+ return null;
1164
+ }
1165
+ const positions = positions_raw;
1166
+ const species = species_raw;
1167
+ // Optimade stores lattice vectors as rows, so use as is
1168
+ const lattice_matrix = attrs.lattice_vectors
1169
+ ? [
1170
+ vec3_from_values(attrs.lattice_vectors[0], `OPTIMADE lattice vector 1`),
1171
+ vec3_from_values(attrs.lattice_vectors[1], `OPTIMADE lattice vector 2`),
1172
+ vec3_from_values(attrs.lattice_vectors[2], `OPTIMADE lattice vector 3`),
1173
+ ]
1174
+ : undefined;
1175
+ const optimade_lattice_params = lattice_matrix
1176
+ ? math.calc_lattice_params(lattice_matrix)
1177
+ : null;
1178
+ // Parse atomic sites
1179
+ const optimade_exact_cart_to_frac = lattice_matrix
1180
+ ? try_create_cart_to_frac(lattice_matrix)
1181
+ : null;
1182
+ const optimade_cart_to_frac = lattice_matrix && optimade_lattice_params
1183
+ ? (optimade_exact_cart_to_frac ??
1184
+ ((xyz) => approximate_cart_to_frac(xyz, [
1185
+ optimade_lattice_params.a,
1186
+ optimade_lattice_params.b,
1187
+ optimade_lattice_params.c,
1188
+ ])))
1189
+ : null;
1190
+ if (lattice_matrix && !optimade_exact_cart_to_frac) {
1191
+ console.warn(`Failed to create exact coordinate converter for OPTIMADE structure`);
1192
+ }
1193
+ const sites = [];
1194
+ for (let idx = 0; idx < positions.length; idx++) {
1195
+ const pos = positions[idx];
1196
+ const element_symbol = species[idx];
1197
+ let xyz;
1198
+ try {
1199
+ xyz = vec3_from_values(pos, `OPTIMADE site ${idx} position`);
1200
+ }
1201
+ catch (error) {
1202
+ console.warn(`Invalid position data at site ${idx}: ${error}`);
1203
+ continue;
1204
+ }
1205
+ const element = validate_element_symbol(element_symbol, idx);
1206
+ // Calculate fractional coordinates if lattice is available
1207
+ const abc = optimade_cart_to_frac ? optimade_cart_to_frac(xyz) : [0, 0, 0];
1208
+ const site = {
1209
+ species: [{ element, occu: 1, oxidation_state: 0 }],
1210
+ abc,
1211
+ xyz,
1212
+ label: `${element}${idx + 1}`,
1213
+ properties: {},
1214
+ };
1215
+ sites.push(site);
1216
+ }
1217
+ if (sites.length === 0) {
1218
+ console.error(`No valid sites found in OPTIMADE JSON`);
1219
+ return null;
1220
+ }
1221
+ // Create structure object
1222
+ let lattice;
1223
+ if (lattice_matrix && optimade_lattice_params) {
1224
+ lattice = { matrix: lattice_matrix, ...optimade_lattice_params };
1225
+ }
1226
+ const structure_result = {
1227
+ sites,
1228
+ ...(lattice && { lattice }),
1229
+ };
1230
+ return structure_result;
1231
+ }
1232
+ catch (error) {
1233
+ console.error(`Error parsing OPTIMADE JSON:`, error);
1234
+ return null;
1235
+ }
1236
+ }
1237
+ // Check if JSON content is OPTIMADE format by looking for structure attributes
1238
+ export function is_optimade_json(content) {
1239
+ try {
1240
+ const raw = JSON.parse(content);
1241
+ return is_optimade_raw(raw);
1242
+ }
1243
+ catch {
1244
+ return false;
1245
+ }
1246
+ }
1247
+ // Check if already-parsed JSON is OPTIMADE-like
1248
+ export const is_optimade_raw = (raw) => Boolean(extract_optimade_structure_from_raw(raw));
1249
+ // Shared helper to extract an OPTIMADE structure from raw JSON-like data
1250
+ function extract_optimade_structure_from_raw(raw) {
1251
+ const payload = unwrap_data(raw);
1252
+ const candidate = Array.isArray(payload) ? payload[0] : payload;
1253
+ return is_optimade_structure_object(candidate) ? candidate : null;
1254
+ }
1255
+ const unwrap_data = (value) => value && typeof value === `object` && `data` in value
1256
+ ? value.data
1257
+ : value;
1258
+ // Type guard: verify minimal OPTIMADE structure shape
1259
+ function is_optimade_structure_object(value) {
1260
+ if (!value || typeof value !== `object`)
1261
+ return false;
1262
+ const obj = value;
1263
+ const type = obj.type;
1264
+ const id = obj.id;
1265
+ const attributes = obj.attributes;
1266
+ return (type === `structures` &&
1267
+ typeof id === `string` &&
1268
+ typeof attributes === `object` &&
1269
+ attributes !== null);
1270
+ }
1271
+ // Convert OPTIMADE structure to Crystal format
1272
+ export function optimade_to_crystal(optimade_structure) {
1273
+ const { lattice_vectors, cartesian_site_positions, species_at_sites, species, ...properties } = optimade_structure.attributes;
1274
+ if (!lattice_vectors || !cartesian_site_positions || !species_at_sites) {
1275
+ console.error(`Missing required OPTIMADE structure data`);
1276
+ return null;
1277
+ }
1278
+ try {
1279
+ const lattice_matrix = [
1280
+ vec3_from_values(lattice_vectors[0], `OPTIMADE lattice vector 1`),
1281
+ vec3_from_values(lattice_vectors[1], `OPTIMADE lattice vector 2`),
1282
+ vec3_from_values(lattice_vectors[2], `OPTIMADE lattice vector 3`),
1283
+ ];
1284
+ const lattice_params = math.calc_lattice_params(lattice_matrix);
1285
+ // Build species lookup for site properties (mass, concentration, etc.)
1286
+ const species_map = new Map(species?.map((spec) => [spec.name, spec]));
1287
+ const crystal_cart_to_frac = try_create_cart_to_frac(lattice_matrix) ??
1288
+ ((xyz) => approximate_cart_to_frac(xyz, [lattice_params.a, lattice_params.b, lattice_params.c]));
1289
+ const sites = cartesian_site_positions.map((pos, idx) => {
1290
+ const element_symbol = species_at_sites[idx];
1291
+ if (!element_symbol)
1292
+ throw new Error(`Missing species for site ${idx}`);
1293
+ const element = validate_element_symbol(element_symbol, idx);
1294
+ const xyz = vec3_from_values(pos, `OPTIMADE atom position ${idx + 1}`);
1295
+ const abc = crystal_cart_to_frac ? crystal_cart_to_frac(xyz) : [0, 0, 0];
1296
+ // Extract mass/concentration from species data
1297
+ const spec = species_map.get(element_symbol);
1298
+ const site_props = {};
1299
+ if (spec?.mass?.[0] !== undefined)
1300
+ site_props.mass = spec.mass[0];
1301
+ if (spec?.concentration?.[0] !== undefined && spec.concentration[0] !== 1) {
1302
+ site_props.concentration = spec.concentration[0];
1303
+ }
1304
+ return {
1305
+ species: [{ element, occu: 1, oxidation_state: 0 }],
1306
+ abc,
1307
+ xyz,
1308
+ label: `${element}${idx + 1}`,
1309
+ properties: site_props,
1310
+ };
1311
+ });
1312
+ return {
1313
+ sites,
1314
+ lattice: { matrix: lattice_matrix, ...lattice_params, pbc: [true, true, true] },
1315
+ id: optimade_structure.id,
1316
+ properties,
1317
+ };
1318
+ }
1319
+ catch (err) {
1320
+ console.error(`Error converting OPTIMADE to Crystal format:`, err);
1321
+ return null;
1322
+ }
1323
+ }
1324
+ // Check if filename indicates a structure file
1325
+ export function is_structure_file(filename) {
1326
+ const name = filename.toLowerCase();
1327
+ // Trajectory-only formats (can't be structures)
1328
+ if (/\.(traj|xtc|h5|hdf5)$/i.test(name) || /xdatcar/i.test(name))
1329
+ return false;
1330
+ // Always structure formats
1331
+ if (STRUCTURE_EXTENSIONS_REGEX.test(name))
1332
+ return true;
1333
+ if (VASP_FILES_REGEX.test(name))
1334
+ return true;
1335
+ // .xyz/.extxyz files: structure unless they have trajectory keywords
1336
+ if (/\.(xyz|extxyz)$/i.test(name))
1337
+ return !TRAJ_KEYWORDS_REGEX.test(name);
1338
+ // Keyword-based detection for YAML/XML
1339
+ if (/\.(yaml|yml|xml)$/i.test(name) && STRUCT_KEYWORDS_REGEX.test(name))
1340
+ return true;
1341
+ // More restrictive keyword detection for JSON files
1342
+ if (/\.json$/i.test(name) &&
1343
+ STRUCT_KEYWORDS_STRICT_REGEX.test(name) &&
1344
+ !TRAJ_KEYWORDS_REGEX.test(name) &&
1345
+ !CONFIG_DIRS_REGEX.test(name))
1346
+ return true;
1347
+ // Compressed files - check base filename recursively
1348
+ if (COMPRESSION_EXTENSIONS_REGEX.test(name)) {
1349
+ return is_structure_file(name.replace(COMPRESSION_EXTENSIONS_REGEX, ``));
1350
+ }
1351
+ return false;
1352
+ }
1353
+ export const detect_structure_type = (filename, content) => {
1354
+ const lower_filename = filename.toLowerCase();
1355
+ // Normalize compressed suffixes (gz, gzip, zip, xz, bz2) for detection parity
1356
+ let name_to_check = lower_filename;
1357
+ while (COMPRESSION_EXTENSIONS_REGEX.test(name_to_check)) {
1358
+ name_to_check = name_to_check.replace(COMPRESSION_EXTENSIONS_REGEX, ``);
1359
+ }
1360
+ if (name_to_check.endsWith(`.json`)) {
1361
+ try {
1362
+ const parsed = JSON.parse(content);
1363
+ // Check for crystal indicators: lattice, lattice_vectors, or periodic dimensions
1364
+ const dims = parsed.data?.attributes?.dimension_types;
1365
+ if (parsed.lattice ||
1366
+ parsed.data?.attributes?.lattice_vectors ||
1367
+ (Array.isArray(dims) && dims.some((dim) => dim > 0)) ||
1368
+ parsed.data?.attributes?.nperiodic_dimensions > 0) {
1369
+ return `crystal`;
1370
+ }
1371
+ return `molecule`;
1372
+ }
1373
+ catch {
1374
+ return `unknown`;
1375
+ }
1376
+ }
1377
+ if (name_to_check.endsWith(`.cif`))
1378
+ return `crystal`;
1379
+ if (name_to_check.includes(`poscar`))
1380
+ return `crystal`;
1381
+ if (name_to_check.endsWith(`.yaml`) || name_to_check.endsWith(`.yml`)) {
1382
+ const lower_content = content.toLowerCase();
1383
+ return lower_content.includes(`phono3py:`) || lower_content.includes(`phonopy:`)
1384
+ ? `crystal`
1385
+ : `unknown`;
1386
+ }
1387
+ if (XYZ_EXTXYZ_REGEX.test(name_to_check)) {
1388
+ const lines = content.trim().split(/\r?\n/);
1389
+ return lines.length >= 2 && lines[1].includes(`Lattice=`) ? `crystal` : `molecule`;
1390
+ }
1391
+ return `unknown`;
1392
+ };