matterviz 0.3.6 → 0.4.0

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