react-cheminfo 0.134.1 → 0.136.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 (454) hide show
  1. package/README.md +13 -0
  2. package/lib/crystal/core/bondGrid.d.ts +26 -0
  3. package/lib/crystal/core/bondGrid.d.ts.map +1 -0
  4. package/lib/crystal/core/bondGrid.js +76 -0
  5. package/lib/crystal/core/bondGrid.js.map +1 -0
  6. package/lib/crystal/core/cellAtoms.d.ts +43 -0
  7. package/lib/crystal/core/cellAtoms.d.ts.map +1 -0
  8. package/lib/crystal/core/cellAtoms.js +70 -0
  9. package/lib/crystal/core/cellAtoms.js.map +1 -0
  10. package/lib/crystal/core/cellBonds.d.ts +21 -0
  11. package/lib/crystal/core/cellBonds.d.ts.map +1 -0
  12. package/lib/crystal/core/cellBonds.js +100 -0
  13. package/lib/crystal/core/cellBonds.js.map +1 -0
  14. package/lib/crystal/core/cif/element.d.ts +9 -0
  15. package/lib/crystal/core/cif/element.d.ts.map +1 -0
  16. package/lib/crystal/core/cif/element.js +41 -0
  17. package/lib/crystal/core/cif/element.js.map +1 -0
  18. package/lib/crystal/core/cif/index.d.ts +4 -0
  19. package/lib/crystal/core/cif/index.d.ts.map +1 -0
  20. package/lib/crystal/core/cif/index.js +3 -0
  21. package/lib/crystal/core/cif/index.js.map +1 -0
  22. package/lib/crystal/core/cif/number.d.ts +27 -0
  23. package/lib/crystal/core/cif/number.d.ts.map +1 -0
  24. package/lib/crystal/core/cif/number.js +57 -0
  25. package/lib/crystal/core/cif/number.js.map +1 -0
  26. package/lib/crystal/core/cif/read.d.ts +12 -0
  27. package/lib/crystal/core/cif/read.d.ts.map +1 -0
  28. package/lib/crystal/core/cif/read.js +183 -0
  29. package/lib/crystal/core/cif/read.js.map +1 -0
  30. package/lib/crystal/core/cif/readGeometry.d.ts +17 -0
  31. package/lib/crystal/core/cif/readGeometry.d.ts.map +1 -0
  32. package/lib/crystal/core/cif/readGeometry.js +93 -0
  33. package/lib/crystal/core/cif/readGeometry.js.map +1 -0
  34. package/lib/crystal/core/cif/tags.d.ts +62 -0
  35. package/lib/crystal/core/cif/tags.d.ts.map +1 -0
  36. package/lib/crystal/core/cif/tags.js +115 -0
  37. package/lib/crystal/core/cif/tags.js.map +1 -0
  38. package/lib/crystal/core/cif/types.d.ts +158 -0
  39. package/lib/crystal/core/cif/types.d.ts.map +1 -0
  40. package/lib/crystal/core/cif/types.js +2 -0
  41. package/lib/crystal/core/cif/types.js.map +1 -0
  42. package/lib/crystal/core/components.d.ts +56 -0
  43. package/lib/crystal/core/components.d.ts.map +1 -0
  44. package/lib/crystal/core/components.js +132 -0
  45. package/lib/crystal/core/components.js.map +1 -0
  46. package/lib/crystal/core/covalentRadii.d.ts +24 -0
  47. package/lib/crystal/core/covalentRadii.d.ts.map +1 -0
  48. package/lib/crystal/core/covalentRadii.js +55 -0
  49. package/lib/crystal/core/covalentRadii.js.map +1 -0
  50. package/lib/crystal/core/disorder.d.ts +59 -0
  51. package/lib/crystal/core/disorder.d.ts.map +1 -0
  52. package/lib/crystal/core/disorder.js +168 -0
  53. package/lib/crystal/core/disorder.js.map +1 -0
  54. package/lib/crystal/core/expand.d.ts +62 -0
  55. package/lib/crystal/core/expand.d.ts.map +1 -0
  56. package/lib/crystal/core/expand.js +61 -0
  57. package/lib/crystal/core/expand.js.map +1 -0
  58. package/lib/crystal/core/index.d.ts +20 -0
  59. package/lib/crystal/core/index.d.ts.map +1 -0
  60. package/lib/crystal/core/index.js +13 -0
  61. package/lib/crystal/core/index.js.map +1 -0
  62. package/lib/crystal/core/moleculeOf.d.ts +31 -0
  63. package/lib/crystal/core/moleculeOf.d.ts.map +1 -0
  64. package/lib/crystal/core/moleculeOf.js +128 -0
  65. package/lib/crystal/core/moleculeOf.js.map +1 -0
  66. package/lib/crystal/core/moleculeTypes.d.ts +80 -0
  67. package/lib/crystal/core/moleculeTypes.d.ts.map +1 -0
  68. package/lib/crystal/core/moleculeTypes.js +2 -0
  69. package/lib/crystal/core/moleculeTypes.js.map +1 -0
  70. package/lib/crystal/core/molecules.d.ts +39 -0
  71. package/lib/crystal/core/molecules.d.ts.map +1 -0
  72. package/lib/crystal/core/molecules.js +106 -0
  73. package/lib/crystal/core/molecules.js.map +1 -0
  74. package/lib/crystal/core/operations.d.ts +19 -0
  75. package/lib/crystal/core/operations.d.ts.map +1 -0
  76. package/lib/crystal/core/operations.js +68 -0
  77. package/lib/crystal/core/operations.js.map +1 -0
  78. package/lib/crystal/core/packing.d.ts +43 -0
  79. package/lib/crystal/core/packing.d.ts.map +1 -0
  80. package/lib/crystal/core/packing.js +89 -0
  81. package/lib/crystal/core/packing.js.map +1 -0
  82. package/lib/crystal/core/periodicBonds.d.ts +57 -0
  83. package/lib/crystal/core/periodicBonds.d.ts.map +1 -0
  84. package/lib/crystal/core/periodicBonds.js +167 -0
  85. package/lib/crystal/core/periodicBonds.js.map +1 -0
  86. package/lib/crystal/core/resolve.d.ts +61 -0
  87. package/lib/crystal/core/resolve.d.ts.map +1 -0
  88. package/lib/crystal/core/resolve.js +149 -0
  89. package/lib/crystal/core/resolve.js.map +1 -0
  90. package/lib/crystal/core/spaceGroups/index.d.ts +5 -0
  91. package/lib/crystal/core/spaceGroups/index.d.ts.map +1 -0
  92. package/lib/crystal/core/spaceGroups/index.js +4 -0
  93. package/lib/crystal/core/spaceGroups/index.js.map +1 -0
  94. package/lib/crystal/core/spaceGroups/spaceGroupOperations.d.ts +14 -0
  95. package/lib/crystal/core/spaceGroups/spaceGroupOperations.d.ts.map +1 -0
  96. package/lib/crystal/core/spaceGroups/spaceGroupOperations.js +24 -0
  97. package/lib/crystal/core/spaceGroups/spaceGroupOperations.js.map +1 -0
  98. package/lib/crystal/core/spaceGroups/spaceGroupRows.d.ts +3 -0
  99. package/lib/crystal/core/spaceGroups/spaceGroupRows.d.ts.map +1 -0
  100. package/lib/crystal/core/spaceGroups/spaceGroupRows.js +536 -0
  101. package/lib/crystal/core/spaceGroups/spaceGroupRows.js.map +1 -0
  102. package/lib/crystal/core/spaceGroups/spaceGroupSymbols.d.ts +43 -0
  103. package/lib/crystal/core/spaceGroups/spaceGroupSymbols.d.ts.map +1 -0
  104. package/lib/crystal/core/spaceGroups/spaceGroupSymbols.js +169 -0
  105. package/lib/crystal/core/spaceGroups/spaceGroupSymbols.js.map +1 -0
  106. package/lib/crystal/core/spaceGroups/spaceGroups.d.ts +78 -0
  107. package/lib/crystal/core/spaceGroups/spaceGroups.d.ts.map +1 -0
  108. package/lib/crystal/core/spaceGroups/spaceGroups.js +83 -0
  109. package/lib/crystal/core/spaceGroups/spaceGroups.js.map +1 -0
  110. package/lib/crystal/core/symmetry/group.d.ts +15 -0
  111. package/lib/crystal/core/symmetry/group.d.ts.map +1 -0
  112. package/lib/crystal/core/symmetry/group.js +37 -0
  113. package/lib/crystal/core/symmetry/group.js.map +1 -0
  114. package/lib/crystal/core/symmetry/index.d.ts +8 -0
  115. package/lib/crystal/core/symmetry/index.d.ts.map +1 -0
  116. package/lib/crystal/core/symmetry/index.js +6 -0
  117. package/lib/crystal/core/symmetry/index.js.map +1 -0
  118. package/lib/crystal/core/symmetry/integerMatrix.d.ts +45 -0
  119. package/lib/crystal/core/symmetry/integerMatrix.d.ts.map +1 -0
  120. package/lib/crystal/core/symmetry/integerMatrix.js +139 -0
  121. package/lib/crystal/core/symmetry/integerMatrix.js.map +1 -0
  122. package/lib/crystal/core/symmetry/lattice.d.ts +64 -0
  123. package/lib/crystal/core/symmetry/lattice.d.ts.map +1 -0
  124. package/lib/crystal/core/symmetry/lattice.js +113 -0
  125. package/lib/crystal/core/symmetry/lattice.js.map +1 -0
  126. package/lib/crystal/core/symmetry/operation.d.ts +91 -0
  127. package/lib/crystal/core/symmetry/operation.d.ts.map +1 -0
  128. package/lib/crystal/core/symmetry/operation.js +184 -0
  129. package/lib/crystal/core/symmetry/operation.js.map +1 -0
  130. package/lib/crystal/core/symmetry/parseOperation.d.ts +18 -0
  131. package/lib/crystal/core/symmetry/parseOperation.d.ts.map +1 -0
  132. package/lib/crystal/core/symmetry/parseOperation.js +145 -0
  133. package/lib/crystal/core/symmetry/parseOperation.js.map +1 -0
  134. package/lib/crystal/core/symmetry/types.d.ts +29 -0
  135. package/lib/crystal/core/symmetry/types.d.ts.map +1 -0
  136. package/lib/crystal/core/symmetry/types.js +5 -0
  137. package/lib/crystal/core/symmetry/types.js.map +1 -0
  138. package/lib/crystal/core/symmetryClasses.d.ts +28 -0
  139. package/lib/crystal/core/symmetryClasses.d.ts.map +1 -0
  140. package/lib/crystal/core/symmetryClasses.js +93 -0
  141. package/lib/crystal/core/symmetryClasses.js.map +1 -0
  142. package/lib/crystal.d.ts +12 -0
  143. package/lib/crystal.d.ts.map +1 -0
  144. package/lib/crystal.js +12 -0
  145. package/lib/crystal.js.map +1 -0
  146. package/lib/crystal3d/core/cellClip.d.ts +46 -0
  147. package/lib/crystal3d/core/cellClip.d.ts.map +1 -0
  148. package/lib/crystal3d/core/cellClip.js +198 -0
  149. package/lib/crystal3d/core/cellClip.js.map +1 -0
  150. package/lib/crystal3d/core/cellGeometry.d.ts +63 -0
  151. package/lib/crystal3d/core/cellGeometry.d.ts.map +1 -0
  152. package/lib/crystal3d/core/cellGeometry.js +153 -0
  153. package/lib/crystal3d/core/cellGeometry.js.map +1 -0
  154. package/lib/crystal3d/core/cellStack.d.ts +51 -0
  155. package/lib/crystal3d/core/cellStack.d.ts.map +1 -0
  156. package/lib/crystal3d/core/cellStack.js +79 -0
  157. package/lib/crystal3d/core/cellStack.js.map +1 -0
  158. package/lib/crystal3d/core/crystalView.d.ts +71 -0
  159. package/lib/crystal3d/core/crystalView.d.ts.map +1 -0
  160. package/lib/crystal3d/core/crystalView.js +48 -0
  161. package/lib/crystal3d/core/crystalView.js.map +1 -0
  162. package/lib/crystal3d/core/drawingSet.d.ts +31 -0
  163. package/lib/crystal3d/core/drawingSet.d.ts.map +1 -0
  164. package/lib/crystal3d/core/drawingSet.js +63 -0
  165. package/lib/crystal3d/core/drawingSet.js.map +1 -0
  166. package/lib/crystal3d/core/elementDrawing.d.ts +50 -0
  167. package/lib/crystal3d/core/elementDrawing.d.ts.map +1 -0
  168. package/lib/crystal3d/core/elementDrawing.js +100 -0
  169. package/lib/crystal3d/core/elementDrawing.js.map +1 -0
  170. package/lib/crystal3d/core/elementExtent.d.ts +42 -0
  171. package/lib/crystal3d/core/elementExtent.d.ts.map +1 -0
  172. package/lib/crystal3d/core/elementExtent.js +56 -0
  173. package/lib/crystal3d/core/elementExtent.js.map +1 -0
  174. package/lib/crystal3d/core/elementLabels.d.ts +31 -0
  175. package/lib/crystal3d/core/elementLabels.d.ts.map +1 -0
  176. package/lib/crystal3d/core/elementLabels.js +99 -0
  177. package/lib/crystal3d/core/elementLabels.js.map +1 -0
  178. package/lib/crystal3d/core/elementShapes.d.ts +43 -0
  179. package/lib/crystal3d/core/elementShapes.d.ts.map +1 -0
  180. package/lib/crystal3d/core/elementShapes.js +115 -0
  181. package/lib/crystal3d/core/elementShapes.js.map +1 -0
  182. package/lib/crystal3d/core/frame.d.ts +36 -0
  183. package/lib/crystal3d/core/frame.d.ts.map +1 -0
  184. package/lib/crystal3d/core/frame.js +35 -0
  185. package/lib/crystal3d/core/frame.js.map +1 -0
  186. package/lib/crystal3d/core/framing.d.ts +41 -0
  187. package/lib/crystal3d/core/framing.d.ts.map +1 -0
  188. package/lib/crystal3d/core/framing.js +79 -0
  189. package/lib/crystal3d/core/framing.js.map +1 -0
  190. package/lib/crystal3d/core/index.d.ts +42 -0
  191. package/lib/crystal3d/core/index.d.ts.map +1 -0
  192. package/lib/crystal3d/core/index.js +29 -0
  193. package/lib/crystal3d/core/index.js.map +1 -0
  194. package/lib/crystal3d/core/labelText.d.ts +19 -0
  195. package/lib/crystal3d/core/labelText.d.ts.map +1 -0
  196. package/lib/crystal3d/core/labelText.js +42 -0
  197. package/lib/crystal3d/core/labelText.js.map +1 -0
  198. package/lib/crystal3d/core/latticeBasis.d.ts +49 -0
  199. package/lib/crystal3d/core/latticeBasis.d.ts.map +1 -0
  200. package/lib/crystal3d/core/latticeBasis.js +89 -0
  201. package/lib/crystal3d/core/latticeBasis.js.map +1 -0
  202. package/lib/crystal3d/core/mat3.d.ts +68 -0
  203. package/lib/crystal3d/core/mat3.d.ts.map +1 -0
  204. package/lib/crystal3d/core/mat3.js +146 -0
  205. package/lib/crystal3d/core/mat3.js.map +1 -0
  206. package/lib/crystal3d/core/operationMatrix.d.ts +44 -0
  207. package/lib/crystal3d/core/operationMatrix.d.ts.map +1 -0
  208. package/lib/crystal3d/core/operationMatrix.js +172 -0
  209. package/lib/crystal3d/core/operationMatrix.js.map +1 -0
  210. package/lib/crystal3d/core/orientation.d.ts +62 -0
  211. package/lib/crystal3d/core/orientation.d.ts.map +1 -0
  212. package/lib/crystal3d/core/orientation.js +166 -0
  213. package/lib/crystal3d/core/orientation.js.map +1 -0
  214. package/lib/crystal3d/core/palette.d.ts +24 -0
  215. package/lib/crystal3d/core/palette.d.ts.map +1 -0
  216. package/lib/crystal3d/core/palette.js +34 -0
  217. package/lib/crystal3d/core/palette.js.map +1 -0
  218. package/lib/crystal3d/core/primitives.d.ts +133 -0
  219. package/lib/crystal3d/core/primitives.d.ts.map +1 -0
  220. package/lib/crystal3d/core/primitives.js +80 -0
  221. package/lib/crystal3d/core/primitives.js.map +1 -0
  222. package/lib/crystal3d/core/structureText.d.ts +20 -0
  223. package/lib/crystal3d/core/structureText.d.ts.map +1 -0
  224. package/lib/crystal3d/core/structureText.js +37 -0
  225. package/lib/crystal3d/core/structureText.js.map +1 -0
  226. package/lib/crystal3d/core/supercell.d.ts +20 -0
  227. package/lib/crystal3d/core/supercell.d.ts.map +1 -0
  228. package/lib/crystal3d/core/supercell.js +35 -0
  229. package/lib/crystal3d/core/supercell.js.map +1 -0
  230. package/lib/crystal3d/core/types.d.ts +166 -0
  231. package/lib/crystal3d/core/types.d.ts.map +1 -0
  232. package/lib/crystal3d/core/types.js +10 -0
  233. package/lib/crystal3d/core/types.js.map +1 -0
  234. package/lib/crystal3d/core/vec3.d.ts +75 -0
  235. package/lib/crystal3d/core/vec3.d.ts.map +1 -0
  236. package/lib/crystal3d/core/vec3.js +119 -0
  237. package/lib/crystal3d/core/vec3.js.map +1 -0
  238. package/lib/crystal3d/ui/CrystalCanvas3D.d.ts +52 -0
  239. package/lib/crystal3d/ui/CrystalCanvas3D.d.ts.map +1 -0
  240. package/lib/crystal3d/ui/CrystalCanvas3D.js +242 -0
  241. package/lib/crystal3d/ui/CrystalCanvas3D.js.map +1 -0
  242. package/lib/crystal3d/ui/CrystalStructureView.d.ts +17 -0
  243. package/lib/crystal3d/ui/CrystalStructureView.d.ts.map +1 -0
  244. package/lib/crystal3d/ui/CrystalStructureView.js +76 -0
  245. package/lib/crystal3d/ui/CrystalStructureView.js.map +1 -0
  246. package/lib/crystal3d/ui/CrystalStructureViewer.d.ts +22 -0
  247. package/lib/crystal3d/ui/CrystalStructureViewer.d.ts.map +1 -0
  248. package/lib/crystal3d/ui/CrystalStructureViewer.js +29 -0
  249. package/lib/crystal3d/ui/CrystalStructureViewer.js.map +1 -0
  250. package/lib/crystal3d/ui/CrystalViewControls.d.ts +25 -0
  251. package/lib/crystal3d/ui/CrystalViewControls.d.ts.map +1 -0
  252. package/lib/crystal3d/ui/CrystalViewControls.js +22 -0
  253. package/lib/crystal3d/ui/CrystalViewControls.js.map +1 -0
  254. package/lib/crystal3d/ui/CrystalViewer3D.d.ts +72 -0
  255. package/lib/crystal3d/ui/CrystalViewer3D.d.ts.map +1 -0
  256. package/lib/crystal3d/ui/CrystalViewer3D.js +70 -0
  257. package/lib/crystal3d/ui/CrystalViewer3D.js.map +1 -0
  258. package/lib/crystal3d/ui/crystalScene.d.ts +91 -0
  259. package/lib/crystal3d/ui/crystalScene.d.ts.map +1 -0
  260. package/lib/crystal3d/ui/crystalScene.js +10 -0
  261. package/lib/crystal3d/ui/crystalScene.js.map +1 -0
  262. package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts +52 -0
  263. package/lib/crystal3d/ui/crystalStructureViewerProps.d.ts.map +1 -0
  264. package/lib/crystal3d/ui/crystalStructureViewerProps.js +2 -0
  265. package/lib/crystal3d/ui/crystalStructureViewerProps.js.map +1 -0
  266. package/lib/crystal3d/ui/index.d.ts +16 -0
  267. package/lib/crystal3d/ui/index.d.ts.map +1 -0
  268. package/lib/crystal3d/ui/index.js +12 -0
  269. package/lib/crystal3d/ui/index.js.map +1 -0
  270. package/lib/crystal3d/ui/useCrystalCaption.d.ts +14 -0
  271. package/lib/crystal3d/ui/useCrystalCaption.d.ts.map +1 -0
  272. package/lib/crystal3d/ui/useCrystalCaption.js +32 -0
  273. package/lib/crystal3d/ui/useCrystalCaption.js.map +1 -0
  274. package/lib/crystal3d/viewer/animate.d.ts +49 -0
  275. package/lib/crystal3d/viewer/animate.d.ts.map +1 -0
  276. package/lib/crystal3d/viewer/animate.js +83 -0
  277. package/lib/crystal3d/viewer/animate.js.map +1 -0
  278. package/lib/crystal3d/viewer/camera.d.ts +44 -0
  279. package/lib/crystal3d/viewer/camera.d.ts.map +1 -0
  280. package/lib/crystal3d/viewer/camera.js +103 -0
  281. package/lib/crystal3d/viewer/camera.js.map +1 -0
  282. package/lib/crystal3d/viewer/index.d.ts +13 -0
  283. package/lib/crystal3d/viewer/index.d.ts.map +1 -0
  284. package/lib/crystal3d/viewer/index.js +8 -0
  285. package/lib/crystal3d/viewer/index.js.map +1 -0
  286. package/lib/crystal3d/viewer/layerRegistry.d.ts +24 -0
  287. package/lib/crystal3d/viewer/layerRegistry.d.ts.map +1 -0
  288. package/lib/crystal3d/viewer/layerRegistry.js +39 -0
  289. package/lib/crystal3d/viewer/layerRegistry.js.map +1 -0
  290. package/lib/crystal3d/viewer/meshPrimitives.d.ts +13 -0
  291. package/lib/crystal3d/viewer/meshPrimitives.d.ts.map +1 -0
  292. package/lib/crystal3d/viewer/meshPrimitives.js +76 -0
  293. package/lib/crystal3d/viewer/meshPrimitives.js.map +1 -0
  294. package/lib/crystal3d/viewer/plugin.d.ts +133 -0
  295. package/lib/crystal3d/viewer/plugin.d.ts.map +1 -0
  296. package/lib/crystal3d/viewer/plugin.js +181 -0
  297. package/lib/crystal3d/viewer/plugin.js.map +1 -0
  298. package/lib/crystal3d/viewer/renderCell.d.ts +43 -0
  299. package/lib/crystal3d/viewer/renderCell.d.ts.map +1 -0
  300. package/lib/crystal3d/viewer/renderCell.js +53 -0
  301. package/lib/crystal3d/viewer/renderCell.js.map +1 -0
  302. package/lib/crystal3d/viewer/renderElements.d.ts +54 -0
  303. package/lib/crystal3d/viewer/renderElements.d.ts.map +1 -0
  304. package/lib/crystal3d/viewer/renderElements.js +77 -0
  305. package/lib/crystal3d/viewer/renderElements.js.map +1 -0
  306. package/lib/crystal3d/viewer/renderStructure.d.ts +55 -0
  307. package/lib/crystal3d/viewer/renderStructure.d.ts.map +1 -0
  308. package/lib/crystal3d/viewer/renderStructure.js +103 -0
  309. package/lib/crystal3d/viewer/renderStructure.js.map +1 -0
  310. package/lib/crystal3d/viewer/sceneParts.d.ts +32 -0
  311. package/lib/crystal3d/viewer/sceneParts.d.ts.map +1 -0
  312. package/lib/crystal3d/viewer/sceneParts.js +77 -0
  313. package/lib/crystal3d/viewer/sceneParts.js.map +1 -0
  314. package/lib/crystal3d/viewer/shapeLayer.d.ts +41 -0
  315. package/lib/crystal3d/viewer/shapeLayer.d.ts.map +1 -0
  316. package/lib/crystal3d/viewer/shapeLayer.js +57 -0
  317. package/lib/crystal3d/viewer/shapeLayer.js.map +1 -0
  318. package/lib/crystal3d/viewer/textLayer.d.ts +21 -0
  319. package/lib/crystal3d/viewer/textLayer.d.ts.map +1 -0
  320. package/lib/crystal3d/viewer/textLayer.js +59 -0
  321. package/lib/crystal3d/viewer/textLayer.js.map +1 -0
  322. package/lib/crystal3d/viewer/viewer.d.ts +110 -0
  323. package/lib/crystal3d/viewer/viewer.d.ts.map +1 -0
  324. package/lib/crystal3d/viewer/viewer.js +157 -0
  325. package/lib/crystal3d/viewer/viewer.js.map +1 -0
  326. package/lib/crystal3d.d.ts +12 -0
  327. package/lib/crystal3d.d.ts.map +1 -0
  328. package/lib/crystal3d.js +12 -0
  329. package/lib/crystal3d.js.map +1 -0
  330. package/lib/i18n/core/chromeCatalog.d.ts +1 -1
  331. package/lib/i18n/core/chromeCatalog.d.ts.map +1 -1
  332. package/lib/locales/de.json +19 -1
  333. package/lib/locales/en.json +19 -1
  334. package/lib/locales/es.json +19 -1
  335. package/lib/locales/fr.json +19 -1
  336. package/lib/locales/it.json +19 -1
  337. package/lib/molecule3d/ui/MoleculeCanvas3D.d.ts.map +1 -1
  338. package/lib/molecule3d/ui/MoleculeCanvas3D.js +16 -27
  339. package/lib/molecule3d/ui/MoleculeCanvas3D.js.map +1 -1
  340. package/lib/molstar/bonds/bondRule.d.ts +16 -0
  341. package/lib/molstar/bonds/bondRule.d.ts.map +1 -0
  342. package/lib/molstar/bonds/bondRule.js +23 -0
  343. package/lib/molstar/bonds/bondRule.js.map +1 -0
  344. package/lib/molstar/bonds/index.d.ts +9 -0
  345. package/lib/molstar/bonds/index.d.ts.map +1 -0
  346. package/lib/molstar/bonds/index.js +9 -0
  347. package/lib/molstar/bonds/index.js.map +1 -0
  348. package/lib/molstar/ui/MolstarToolbar.d.ts +47 -0
  349. package/lib/molstar/ui/MolstarToolbar.d.ts.map +1 -0
  350. package/lib/molstar/ui/MolstarToolbar.js +28 -0
  351. package/lib/molstar/ui/MolstarToolbar.js.map +1 -0
  352. package/lib/molstar/ui/index.d.ts +10 -0
  353. package/lib/molstar/ui/index.d.ts.map +1 -0
  354. package/lib/molstar/ui/index.js +8 -0
  355. package/lib/molstar/ui/index.js.map +1 -0
  356. package/lib/molstar/ui/useMolstarTools.d.ts +63 -0
  357. package/lib/molstar/ui/useMolstarTools.d.ts.map +1 -0
  358. package/lib/molstar/ui/useMolstarTools.js +36 -0
  359. package/lib/molstar/ui/useMolstarTools.js.map +1 -0
  360. package/package.json +4 -1
  361. package/src/crystal/core/bondGrid.ts +98 -0
  362. package/src/crystal/core/cellAtoms.ts +106 -0
  363. package/src/crystal/core/cellBonds.ts +121 -0
  364. package/src/crystal/core/cif/element.ts +40 -0
  365. package/src/crystal/core/cif/index.ts +12 -0
  366. package/src/crystal/core/cif/number.ts +62 -0
  367. package/src/crystal/core/cif/read.ts +218 -0
  368. package/src/crystal/core/cif/readGeometry.ts +104 -0
  369. package/src/crystal/core/cif/tags.ts +143 -0
  370. package/src/crystal/core/cif/types.ts +164 -0
  371. package/src/crystal/core/components.ts +183 -0
  372. package/src/crystal/core/covalentRadii.ts +56 -0
  373. package/src/crystal/core/disorder.ts +190 -0
  374. package/src/crystal/core/expand.ts +105 -0
  375. package/src/crystal/core/index.ts +46 -0
  376. package/src/crystal/core/moleculeOf.ts +169 -0
  377. package/src/crystal/core/moleculeTypes.ts +85 -0
  378. package/src/crystal/core/molecules.ts +128 -0
  379. package/src/crystal/core/operations.ts +79 -0
  380. package/src/crystal/core/packing.ts +116 -0
  381. package/src/crystal/core/periodicBonds.ts +234 -0
  382. package/src/crystal/core/resolve.ts +187 -0
  383. package/src/crystal/core/spaceGroups/index.ts +16 -0
  384. package/src/crystal/core/spaceGroups/spaceGroupOperations.ts +32 -0
  385. package/src/crystal/core/spaceGroups/spaceGroupRows.ts +536 -0
  386. package/src/crystal/core/spaceGroups/spaceGroupSymbols.ts +179 -0
  387. package/src/crystal/core/spaceGroups/spaceGroups.ts +154 -0
  388. package/src/crystal/core/symmetry/group.ts +42 -0
  389. package/src/crystal/core/symmetry/index.ts +23 -0
  390. package/src/crystal/core/symmetry/integerMatrix.ts +153 -0
  391. package/src/crystal/core/symmetry/lattice.ts +152 -0
  392. package/src/crystal/core/symmetry/operation.ts +223 -0
  393. package/src/crystal/core/symmetry/parseOperation.ts +180 -0
  394. package/src/crystal/core/symmetry/types.ts +32 -0
  395. package/src/crystal/core/symmetryClasses.ts +105 -0
  396. package/src/crystal.ts +12 -0
  397. package/src/crystal3d/core/cellClip.ts +229 -0
  398. package/src/crystal3d/core/cellGeometry.ts +193 -0
  399. package/src/crystal3d/core/cellStack.ts +87 -0
  400. package/src/crystal3d/core/crystalView.ts +114 -0
  401. package/src/crystal3d/core/drawingSet.ts +71 -0
  402. package/src/crystal3d/core/elementDrawing.ts +147 -0
  403. package/src/crystal3d/core/elementExtent.ts +81 -0
  404. package/src/crystal3d/core/elementLabels.ts +130 -0
  405. package/src/crystal3d/core/elementShapes.ts +141 -0
  406. package/src/crystal3d/core/frame.ts +56 -0
  407. package/src/crystal3d/core/framing.ts +101 -0
  408. package/src/crystal3d/core/index.ts +132 -0
  409. package/src/crystal3d/core/labelText.ts +44 -0
  410. package/src/crystal3d/core/latticeBasis.ts +110 -0
  411. package/src/crystal3d/core/mat3.ts +163 -0
  412. package/src/crystal3d/core/operationMatrix.ts +255 -0
  413. package/src/crystal3d/core/orientation.ts +229 -0
  414. package/src/crystal3d/core/palette.ts +43 -0
  415. package/src/crystal3d/core/primitives.ts +183 -0
  416. package/src/crystal3d/core/structureText.ts +43 -0
  417. package/src/crystal3d/core/supercell.ts +40 -0
  418. package/src/crystal3d/core/types.ts +186 -0
  419. package/src/crystal3d/core/vec3.ts +127 -0
  420. package/src/crystal3d/ui/CrystalCanvas3D.tsx +384 -0
  421. package/src/crystal3d/ui/CrystalStructureView.tsx +148 -0
  422. package/src/crystal3d/ui/CrystalStructureViewer.tsx +39 -0
  423. package/src/crystal3d/ui/CrystalViewControls.tsx +100 -0
  424. package/src/crystal3d/ui/CrystalViewer3D.tsx +183 -0
  425. package/src/crystal3d/ui/crystalScene.ts +100 -0
  426. package/src/crystal3d/ui/crystalStructureViewerProps.ts +54 -0
  427. package/src/crystal3d/ui/index.ts +20 -0
  428. package/src/crystal3d/ui/useCrystalCaption.ts +38 -0
  429. package/src/crystal3d/viewer/animate.ts +113 -0
  430. package/src/crystal3d/viewer/camera.ts +139 -0
  431. package/src/crystal3d/viewer/index.ts +13 -0
  432. package/src/crystal3d/viewer/layerRegistry.ts +47 -0
  433. package/src/crystal3d/viewer/meshPrimitives.ts +102 -0
  434. package/src/crystal3d/viewer/plugin.ts +258 -0
  435. package/src/crystal3d/viewer/renderCell.ts +98 -0
  436. package/src/crystal3d/viewer/renderElements.ts +121 -0
  437. package/src/crystal3d/viewer/renderStructure.ts +144 -0
  438. package/src/crystal3d/viewer/sceneParts.ts +119 -0
  439. package/src/crystal3d/viewer/shapeLayer.ts +108 -0
  440. package/src/crystal3d/viewer/textLayer.ts +85 -0
  441. package/src/crystal3d/viewer/viewer.ts +207 -0
  442. package/src/crystal3d.ts +12 -0
  443. package/src/locales/de.json +19 -1
  444. package/src/locales/en.json +19 -1
  445. package/src/locales/es.json +19 -1
  446. package/src/locales/fr.json +19 -1
  447. package/src/locales/it.json +19 -1
  448. package/src/molecule3d/ui/MoleculeCanvas3D.tsx +45 -71
  449. package/src/molstar/bonds/bondRule.ts +34 -0
  450. package/src/molstar/bonds/index.ts +9 -0
  451. package/src/molstar/ui/MolstarToolbar.tsx +103 -0
  452. package/src/molstar/ui/index.ts +14 -0
  453. package/src/molstar/ui/useMolstarTools.ts +98 -0
  454. package/styles/chrome.css +90 -0
@@ -0,0 +1,152 @@
1
+ /** The six parameters of a unit cell: three edges in Å, three angles in degrees. */
2
+ export interface UnitCell {
3
+ readonly a: number;
4
+ readonly b: number;
5
+ readonly c: number;
6
+ /** Angle between b and c, in degrees. */
7
+ readonly alpha: number;
8
+ /** Angle between c and a, in degrees. */
9
+ readonly beta: number;
10
+ /** Angle between a and b, in degrees. */
11
+ readonly gamma: number;
12
+ }
13
+
14
+ /** A cell with everything derived from it computed once. */
15
+ export interface Lattice {
16
+ readonly cell: UnitCell;
17
+ /** The cell volume in ų. */
18
+ readonly volume: number;
19
+ /** M, whose columns are the Cartesian components of a, b and c. */
20
+ readonly cartesian: number[][];
21
+ /** M⁻¹. */
22
+ readonly fractional: number[][];
23
+ }
24
+
25
+ /**
26
+ * Everything a cell implies, computed once.
27
+ *
28
+ * **The Cartesian convention is the PDB / CCP4 one**, which is what molstar and
29
+ * every CIF consumer assumes: **a** lies along **x**, **b** lies in the **xy**
30
+ * plane with a positive **y** component, and **c** completes a right-handed set.
31
+ * There are two other conventions in common use and they disagree with this one,
32
+ * so never mix Cartesian coordinates from another source without checking.
33
+ * @param cell - The six cell parameters.
34
+ * @returns The lattice.
35
+ */
36
+ export function createLattice(cell: UnitCell): Lattice {
37
+ const cartesian = cartesianMatrix(cell);
38
+ return {
39
+ cell,
40
+ volume: cellVolume(cell),
41
+ cartesian,
42
+ fractional: invertUpperTriangular(cartesian),
43
+ };
44
+ }
45
+
46
+ /**
47
+ * The cell volume in ų, from the closed form; it equals `sqrt(det G)`.
48
+ * @param cell - The six cell parameters.
49
+ * @throws {RangeError} When the three angles describe no cell that exists. A CIF can carry
50
+ * such a triple, and without this the volume is `NaN` and every coordinate
51
+ * downstream of it silently becomes one too.
52
+ * @returns The volume, ų.
53
+ */
54
+ export function cellVolume(cell: UnitCell): number {
55
+ const cosAlpha = Math.cos(toRadians(cell.alpha));
56
+ const cosBeta = Math.cos(toRadians(cell.beta));
57
+ const cosGamma = Math.cos(toRadians(cell.gamma));
58
+ const factor =
59
+ 1 -
60
+ cosAlpha * cosAlpha -
61
+ cosBeta * cosBeta -
62
+ cosGamma * cosGamma +
63
+ 2 * cosAlpha * cosBeta * cosGamma;
64
+ if (factor <= 0) {
65
+ throw new RangeError(
66
+ `no cell has the angles ${cell.alpha}, ${cell.beta}, ${cell.gamma} degrees`,
67
+ );
68
+ }
69
+ return cell.a * cell.b * cell.c * Math.sqrt(factor);
70
+ }
71
+
72
+ /**
73
+ * M, whose columns are the Cartesian components of a, b and c. `G = Mᵀ M`.
74
+ * @param cell - The six cell parameters.
75
+ * @returns M, row-major.
76
+ */
77
+ export function cartesianMatrix(cell: UnitCell): number[][] {
78
+ const { a, b, c, alpha, beta, gamma } = cell;
79
+ const cosAlpha = Math.cos(toRadians(alpha));
80
+ const cosBeta = Math.cos(toRadians(beta));
81
+ const cosGamma = Math.cos(toRadians(gamma));
82
+ const sinGamma = Math.sin(toRadians(gamma));
83
+ return [
84
+ [a, b * cosGamma, c * cosBeta],
85
+ [0, b * sinGamma, (c * (cosAlpha - cosBeta * cosGamma)) / sinGamma],
86
+ [0, 0, cellVolume(cell) / (a * b * sinGamma)],
87
+ ];
88
+ }
89
+
90
+ /**
91
+ * The Cartesian coordinates, in Å, of a fractional point.
92
+ * @param lattice - The cell.
93
+ * @param point - Fractional coordinates.
94
+ * @returns The Cartesian coordinates, Å.
95
+ */
96
+ export function fractionalToCartesian(
97
+ lattice: Lattice,
98
+ point: readonly number[],
99
+ ): number[] {
100
+ return applyMatrix(lattice.cartesian, point);
101
+ }
102
+
103
+ /**
104
+ * The fractional coordinates of a Cartesian point given in Å.
105
+ * @param lattice - The cell.
106
+ * @param point - Cartesian coordinates, Å.
107
+ * @returns The fractional coordinates.
108
+ */
109
+ export function cartesianToFractional(
110
+ lattice: Lattice,
111
+ point: readonly number[],
112
+ ): number[] {
113
+ return applyMatrix(lattice.fractional, point);
114
+ }
115
+
116
+ function applyMatrix(matrix: number[][], point: readonly number[]): number[] {
117
+ const image = new Array<number>(matrix.length).fill(0);
118
+ for (let i = 0; i < matrix.length; i++) {
119
+ const row = matrix[i];
120
+ let sum = 0;
121
+ for (let j = 0; j < matrix.length; j++) {
122
+ sum += (row?.[j] ?? 0) * (point[j] ?? 0);
123
+ }
124
+ image[i] = sum;
125
+ }
126
+ return image;
127
+ }
128
+
129
+ function toRadians(degrees: number): number {
130
+ return (degrees * Math.PI) / 180;
131
+ }
132
+
133
+ /**
134
+ * M⁻¹ in closed form: M has a along x and b in the xy plane, so it is upper
135
+ * triangular and its diagonal is never zero for a cell that exists.
136
+ * @param matrix - M.
137
+ * @returns M⁻¹.
138
+ */
139
+ function invertUpperTriangular(matrix: number[][]): number[][] {
140
+ const [row0 = [], row1 = [], row2 = []] = matrix;
141
+ const m00 = row0[0] ?? 1;
142
+ const m01 = row0[1] ?? 0;
143
+ const m02 = row0[2] ?? 0;
144
+ const m11 = row1[1] ?? 1;
145
+ const m12 = row1[2] ?? 0;
146
+ const m22 = row2[2] ?? 1;
147
+ return [
148
+ [1 / m00, -m01 / (m00 * m11), (m01 * m12 - m02 * m11) / (m00 * m11 * m22)],
149
+ [0, 1 / m11, -m12 / (m11 * m22)],
150
+ [0, 0, 1 / m22],
151
+ ];
152
+ }
@@ -0,0 +1,223 @@
1
+ import {
2
+ identityMatrix,
3
+ matricesEqual,
4
+ matrixAdjugate,
5
+ matrixDeterminant,
6
+ multiplyMatrices,
7
+ multiplyMatrixVector,
8
+ } from './integerMatrix.ts';
9
+ import type { CrystalOperation, Dimension } from './types.ts';
10
+ import { TWELFTHS_PER_CELL } from './types.ts';
11
+
12
+ /** How close two fractional coordinates must be to count as the same atom. */
13
+ const DEFAULT_TOLERANCE = 1e-4;
14
+
15
+ /**
16
+ * The composition `a ∘ b`: apply `b` first, then `a`, so
17
+ * `compose(a, b)(point)` is `apply(a, apply(b, point))`.
18
+ *
19
+ * The rotation part is `Wa · Wb` and the translation is `Wa · wb + wa`, reduced
20
+ * into the cell — exact integer arithmetic throughout.
21
+ * @param a - The operation applied second.
22
+ * @param b - The operation applied first.
23
+ * @returns The composed operation.
24
+ */
25
+ export function compose<D extends Dimension>(
26
+ a: CrystalOperation<D>,
27
+ b: CrystalOperation<D>,
28
+ ): CrystalOperation<D> {
29
+ const rotation = multiplyMatrices(a.rotation, b.rotation);
30
+ const rotated = multiplyMatrixVector(a.rotation, b.translation);
31
+ const translation = new Array<number>(rotated.length).fill(0);
32
+ for (let index = 0; index < rotated.length; index++) {
33
+ translation[index] = wrapTwelfths(
34
+ (rotated[index] ?? 0) + (a.translation[index] ?? 0),
35
+ );
36
+ }
37
+ return { dimension: a.dimension, rotation, translation };
38
+ }
39
+
40
+ /**
41
+ * The inverse operation: rotation `W⁻¹`, translation `−W⁻¹ · w`.
42
+ * @param operation - The operation.
43
+ * @returns The inverse operation.
44
+ */
45
+ export function inverse<D extends Dimension>(
46
+ operation: CrystalOperation<D>,
47
+ ): CrystalOperation<D> {
48
+ const determinant = matrixDeterminant(operation.rotation);
49
+ const adjugate = matrixAdjugate(operation.rotation);
50
+ const rotation: number[][] = [];
51
+ for (const row of adjugate) {
52
+ const values = new Array<number>(adjugate.length).fill(0);
53
+ for (let j = 0; j < adjugate.length; j++) {
54
+ values[j] = (row[j] ?? 0) / determinant;
55
+ }
56
+ rotation.push(values);
57
+ }
58
+ const rotated = multiplyMatrixVector(rotation, operation.translation);
59
+ const translation = new Array<number>(rotated.length).fill(0);
60
+ for (let index = 0; index < rotated.length; index++) {
61
+ translation[index] = wrapTwelfths(-(rotated[index] ?? 0));
62
+ }
63
+ return { dimension: operation.dimension, rotation, translation };
64
+ }
65
+
66
+ /**
67
+ * The image `W · point + w` of a fractional point. The result is **not** wrapped
68
+ * into the cell: pass it through {@link wrapFractional} when the cell is what you
69
+ * want, and leave it alone when you are following a bond out of the cell.
70
+ * @param operation - The operation.
71
+ * @param point - A fractional point.
72
+ * @returns The image, not wrapped.
73
+ */
74
+ export function apply(
75
+ operation: CrystalOperation<Dimension>,
76
+ point: readonly number[],
77
+ ): number[] {
78
+ const size = operation.rotation.length;
79
+ const image = new Array<number>(size).fill(0);
80
+ for (let i = 0; i < size; i++) {
81
+ let sum = (operation.translation[i] ?? 0) / TWELFTHS_PER_CELL;
82
+ const row = operation.rotation[i];
83
+ for (let j = 0; j < size; j++) sum += (row?.[j] ?? 0) * (point[j] ?? 0);
84
+ image[i] = sum;
85
+ }
86
+ return image;
87
+ }
88
+
89
+ /**
90
+ * Each coordinate moved into [0, 1) by a whole number of cells.
91
+ * @param point - A fractional point.
92
+ * @returns The point, in [0, 1).
93
+ */
94
+ export function wrapFractional(point: readonly number[]): number[] {
95
+ const wrapped = new Array<number>(point.length).fill(0);
96
+ for (let index = 0; index < point.length; index++) {
97
+ const value = point[index] ?? 0;
98
+ wrapped[index] = value - Math.floor(value);
99
+ }
100
+ return wrapped;
101
+ }
102
+
103
+ /**
104
+ * The exact key of an operation modulo the lattice: two operations share a key
105
+ * when they are the same coset representative. Integers only, so the comparison
106
+ * is exact and a group expansion terminates.
107
+ * @param operation - The operation.
108
+ * @returns The key.
109
+ */
110
+ export function operationKey(operation: CrystalOperation<Dimension>): string {
111
+ let key = '';
112
+ for (const row of operation.rotation) {
113
+ for (let j = 0; j < operation.rotation.length; j++) {
114
+ key += `${row[j] ?? 0},`;
115
+ }
116
+ }
117
+ key += '|';
118
+ for (const twelfths of operation.translation) {
119
+ key += `${wrapTwelfths(twelfths)},`;
120
+ }
121
+ return key;
122
+ }
123
+
124
+ /**
125
+ * The identity operation of the given dimension.
126
+ * @param dimension - 2 or 3.
127
+ * @returns The identity.
128
+ */
129
+ export function identityOperation<D extends Dimension>(
130
+ dimension: D,
131
+ ): CrystalOperation<D> {
132
+ return {
133
+ dimension,
134
+ rotation: identityMatrix(dimension),
135
+ translation: new Array<number>(dimension).fill(0),
136
+ };
137
+ }
138
+
139
+ /**
140
+ * Whether the operation is the identity, translation included.
141
+ * @param operation - The operation.
142
+ * @returns Whether it is the identity.
143
+ */
144
+ export function isIdentity(operation: CrystalOperation<Dimension>): boolean {
145
+ for (const twelfths of operation.translation) {
146
+ if (wrapTwelfths(twelfths) !== 0) return false;
147
+ }
148
+ return matricesEqual(
149
+ operation.rotation,
150
+ identityMatrix(operation.rotation.length),
151
+ );
152
+ }
153
+
154
+ /**
155
+ * The orbit of one fractional position: every distinct image under the
156
+ * operations, wrapped into the cell.
157
+ *
158
+ * The returned `operationIndex` is what lets the page say *which* operation put
159
+ * an atom where it is, and hovering it highlight the element that generated it.
160
+ * Its length is the multiplicity of the position, which is exact.
161
+ * @param position - A fractional position; it need not be inside the cell.
162
+ * @param operations - The full coset list, centring translations included.
163
+ * @param tolerance - Fractional distance below which two images are one atom.
164
+ * @default 1e-4
165
+ * @returns One image per distinct position, with the index of the operation that made it.
166
+ */
167
+ export function orbit(
168
+ position: readonly number[],
169
+ operations: ReadonlyArray<CrystalOperation<Dimension>>,
170
+ tolerance = DEFAULT_TOLERANCE,
171
+ ): Array<{ position: number[]; operationIndex: number }> {
172
+ const images: Array<{ position: number[]; operationIndex: number }> = [];
173
+ for (let index = 0; index < operations.length; index++) {
174
+ const operation = operations[index];
175
+ if (operation === undefined) continue;
176
+ const image = wrapFractional(apply(operation, position));
177
+ let seen = false;
178
+ for (let other = 0; other < images.length && !seen; other++) {
179
+ seen = sameSite(image, images[other]?.position ?? [], tolerance);
180
+ }
181
+ if (!seen) images.push({ position: image, operationIndex: index });
182
+ }
183
+ return images;
184
+ }
185
+
186
+ /**
187
+ * Whether two wrapped fractional positions are the same site, across the cell edge.
188
+ * @param a - One wrapped fractional position.
189
+ * @param b - The other.
190
+ * @param tolerance - Fractional distance below which they are one site.
191
+ * @returns Whether they are the same site.
192
+ */
193
+ export function sameSite(
194
+ a: readonly number[],
195
+ b: readonly number[],
196
+ tolerance = DEFAULT_TOLERANCE,
197
+ ): boolean {
198
+ for (let index = 0; index < a.length; index++) {
199
+ const difference = Math.abs((a[index] ?? 0) - (b[index] ?? 0));
200
+ if (Math.min(difference, 1 - difference) > tolerance) return false;
201
+ }
202
+ return true;
203
+ }
204
+
205
+ /**
206
+ * A count of twelfths reduced into [0, 12).
207
+ * @param twelfths - A translation, in twelfths.
208
+ * @returns The count, in [0, 12).
209
+ */
210
+ export function wrapTwelfths(twelfths: number): number {
211
+ return (
212
+ ((twelfths % TWELFTHS_PER_CELL) + TWELFTHS_PER_CELL) % TWELFTHS_PER_CELL
213
+ );
214
+ }
215
+
216
+ /**
217
+ * The dimension an operation lives in, read off its rotation part.
218
+ * @param operation - The operation.
219
+ * @returns 2 or 3.
220
+ */
221
+ export function dimensionOf(operation: CrystalOperation<Dimension>): Dimension {
222
+ return operation.rotation.length === 2 ? 2 : 3;
223
+ }
@@ -0,0 +1,180 @@
1
+ import { matrixDeterminant } from './integerMatrix.ts';
2
+ import type { CrystalOperation, Dimension } from './types.ts';
3
+ import { AXIS_NAMES, TWELFTHS_PER_CELL } from './types.ts';
4
+
5
+ /** How far a decimal translation may sit from a twelfth and still be snapped to it. */
6
+ const DECIMAL_TOLERANCE = 5e-3;
7
+
8
+ /**
9
+ * Parse one coordinate triplet — `x,y,z`, `-x+1/2,-y,z+1/2`, `-x+y+2/3,-x+1/3,z+1/3`
10
+ * — into an exact operation.
11
+ *
12
+ * Accepts what the International Tables print and what a CIF may carry: any
13
+ * ordering of the terms (`1/2-x` as well as `-x+1/2`), a leading `+`, upper or
14
+ * lower case, decimal translations (`0.5+x`, `0.33333+y`), a translation of a
15
+ * whole cell, and whitespace anywhere. A two-dimensional operation is `x,y`.
16
+ * @param xyz - The triplet, with or without surrounding whitespace.
17
+ * @param dimension - 2 for a plane group, 3 for a space group.
18
+ * @throws {SyntaxError | RangeError} When the triplet has the wrong number of components, carries a
19
+ * variable coefficient outside {−1, 0, +1}, names an axis the dimension does
20
+ * not have, has a translation that is not a multiple of 1/12, or is singular.
21
+ * @returns The exact operation.
22
+ */
23
+ export function parseOperation<D extends Dimension>(
24
+ xyz: string,
25
+ dimension: D,
26
+ ): CrystalOperation<D> {
27
+ const components = xyz.split(',');
28
+ if (components.length !== dimension) {
29
+ throw new SyntaxError(
30
+ `expected ${dimension} components in "${xyz.trim()}", received ${components.length}`,
31
+ );
32
+ }
33
+ const rotation: number[][] = [];
34
+ const translation: number[] = [];
35
+ for (let index = 0; index < dimension; index++) {
36
+ const component = parseComponent(components[index] ?? '', dimension, xyz);
37
+ rotation.push(component.row);
38
+ translation.push(component.translation);
39
+ }
40
+ const determinant = matrixDeterminant(rotation);
41
+ if (determinant !== 1 && determinant !== -1) {
42
+ throw new RangeError(
43
+ `"${xyz.trim()}" is not a symmetry operation: its determinant is ${determinant}, not ±1`,
44
+ );
45
+ }
46
+ return { dimension, rotation, translation };
47
+ }
48
+
49
+ /**
50
+ * One component of the triplet: a row of the matrix and one translation.
51
+ * @param source - The component, e.g. `-x+1/2`.
52
+ * @param dimension - 2 or 3.
53
+ * @param xyz - The whole triplet, for the error message.
54
+ * @returns One row of the matrix and the translation.
55
+ */
56
+ function parseComponent(
57
+ source: string,
58
+ dimension: Dimension,
59
+ xyz: string,
60
+ ): { row: number[]; translation: number } {
61
+ const text = source.replaceAll(/\s+/g, '').toLowerCase();
62
+ if (text.length === 0) {
63
+ throw new SyntaxError(`empty component in "${xyz.trim()}"`);
64
+ }
65
+ const row = new Array<number>(dimension).fill(0);
66
+ let twelfths = 0;
67
+ let cursor = 0;
68
+ while (cursor < text.length) {
69
+ let sign = 1;
70
+ const character = text[cursor];
71
+ if (character === '+') {
72
+ cursor += 1;
73
+ } else if (character === '-') {
74
+ sign = -1;
75
+ cursor += 1;
76
+ } else if (cursor > 0) {
77
+ throw new SyntaxError(
78
+ `missing a sign before "${text.slice(cursor)}" in "${xyz.trim()}"`,
79
+ );
80
+ }
81
+ const number = readNumber(text, cursor, xyz);
82
+ cursor = number.cursor;
83
+ if (text[cursor] === '*') cursor += 1;
84
+ const axis = AXIS_NAMES.indexOf(
85
+ (text[cursor] ?? '') as (typeof AXIS_NAMES)[number],
86
+ );
87
+ if (axis === -1) {
88
+ if (number.value === null) {
89
+ throw new SyntaxError(
90
+ `"${text}" of "${xyz.trim()}" has a term with nothing in it`,
91
+ );
92
+ }
93
+ twelfths += sign * toTwelfths(number.value, xyz);
94
+ continue;
95
+ }
96
+ if (axis >= dimension) {
97
+ throw new SyntaxError(
98
+ `"${xyz.trim()}" names the axis ${AXIS_NAMES[axis]} in ${dimension}D`,
99
+ );
100
+ }
101
+ const coefficient = number.value ?? 1;
102
+ if (coefficient !== 1) {
103
+ throw new RangeError(
104
+ `"${xyz.trim()}" carries the coefficient ${sign * coefficient} on ${AXIS_NAMES[axis]}`,
105
+ );
106
+ }
107
+ const current = row[axis] ?? 0;
108
+ const updated = current + sign;
109
+ if (Math.abs(updated) > 1) {
110
+ throw new RangeError(
111
+ `"${xyz.trim()}" carries the coefficient ${updated} on ${AXIS_NAMES[axis]}`,
112
+ );
113
+ }
114
+ row[axis] = updated;
115
+ cursor += 1;
116
+ }
117
+ return {
118
+ row,
119
+ translation:
120
+ ((twelfths % TWELFTHS_PER_CELL) + TWELFTHS_PER_CELL) % TWELFTHS_PER_CELL,
121
+ };
122
+ }
123
+
124
+ /**
125
+ * A fraction, a decimal or an integer at `cursor`, or `null` when none is there.
126
+ * @param text - The component, whitespace removed.
127
+ * @param cursor - Where to read.
128
+ * @param xyz - The whole triplet, for the error message.
129
+ * @returns The number, or `null` when none is there, and where reading stopped.
130
+ */
131
+ function readNumber(
132
+ text: string,
133
+ cursor: number,
134
+ xyz: string,
135
+ ): { value: number | null; cursor: number } {
136
+ let end = cursor;
137
+ while (end < text.length && (isDigit(text[end]) || text[end] === '.')) {
138
+ end += 1;
139
+ }
140
+ if (end === cursor) return { value: null, cursor };
141
+ const numerator = Number(text.slice(cursor, end));
142
+ if (!Number.isFinite(numerator)) {
143
+ throw new SyntaxError(
144
+ `"${text.slice(cursor, end)}" is not a number, in "${xyz.trim()}"`,
145
+ );
146
+ }
147
+ if (text[end] !== '/') return { value: numerator, cursor: end };
148
+ let denominatorEnd = end + 1;
149
+ while (denominatorEnd < text.length && isDigit(text[denominatorEnd])) {
150
+ denominatorEnd += 1;
151
+ }
152
+ const denominator = Number(text.slice(end + 1, denominatorEnd));
153
+ if (denominatorEnd === end + 1 || denominator === 0) {
154
+ throw new SyntaxError(
155
+ `"${text}" of "${xyz.trim()}" has an unusable denominator`,
156
+ );
157
+ }
158
+ return { value: numerator / denominator, cursor: denominatorEnd };
159
+ }
160
+
161
+ /**
162
+ * A translation in twelfths, snapping `0.33333` to 4 and refusing `0.4`.
163
+ * @param value - A translation, in cells.
164
+ * @param xyz - The whole triplet, for the error message.
165
+ * @returns The translation, in twelfths.
166
+ */
167
+ function toTwelfths(value: number, xyz: string): number {
168
+ const scaled = value * TWELFTHS_PER_CELL;
169
+ const twelfths = Math.round(scaled);
170
+ if (Math.abs(scaled - twelfths) > DECIMAL_TOLERANCE) {
171
+ throw new RangeError(
172
+ `the translation ${value} of "${xyz.trim()}" is not a multiple of 1/12`,
173
+ );
174
+ }
175
+ return twelfths;
176
+ }
177
+
178
+ function isDigit(character: string | undefined): boolean {
179
+ return character !== undefined && character >= '0' && character <= '9';
180
+ }
@@ -0,0 +1,32 @@
1
+ /**
2
+ * The dimension of a crystallographic group: 2 for the plane groups, 3 for the
3
+ * space groups.
4
+ */
5
+ export type Dimension = 2 | 3;
6
+
7
+ /**
8
+ * A symmetry operation of a crystallographic group, in the crystal basis.
9
+ *
10
+ * The rotation part is an exact integer matrix and the translation part is an
11
+ * exact integer count of {@link TWELFTHS_PER_CELL}, so two operations compare
12
+ * with `===` on their `operationKey` and a group expansion terminates. Every
13
+ * translation occurring in the 230 space groups and the 17 wallpaper groups is a
14
+ * twelfth: the denominators that occur are 2, 3, 4 and 6.
15
+ */
16
+ export interface CrystalOperation<D extends Dimension = 3> {
17
+ /** How many axes the operation acts on. A `CrystalOperation<2>` is not a `CrystalOperation<3>`. */
18
+ readonly dimension: D;
19
+ /** Rows of the D×D integer matrix W, acting on the fractional column (x, y, z). */
20
+ readonly rotation: ReadonlyArray<readonly number[]>;
21
+ /** Translation w, in twelfths of a cell edge, reduced into [0, 12). */
22
+ readonly translation: readonly number[];
23
+ }
24
+
25
+ /** An exact integer matrix, row-major. */
26
+ export type IntegerMatrix = ReadonlyArray<readonly number[]>;
27
+
28
+ /** The unit a translation is counted in: `6` is 1/2, `4` is 1/3, `3` is 1/4. */
29
+ export const TWELFTHS_PER_CELL = 12;
30
+
31
+ /** Variable names of a fractional coordinate, in order. */
32
+ export const AXIS_NAMES = ['x', 'y', 'z'] as const;
@@ -0,0 +1,105 @@
1
+ import type { PeriodicComponent } from './components.ts';
2
+ import type { ExpandedAtom } from './expand.ts';
3
+
4
+ /**
5
+ * The connected sets grouped by the sites they are built from: sets sharing a
6
+ * site are symmetry copies of one another.
7
+ * @param components - The connected sets of the cell.
8
+ * @param atoms - The atoms of the cell.
9
+ * @param siteCount - How many sites the asymmetric unit holds.
10
+ * @returns The groups, ordered on their first site.
11
+ */
12
+ export function symmetryClasses(
13
+ components: readonly PeriodicComponent[],
14
+ atoms: readonly ExpandedAtom[],
15
+ siteCount: number,
16
+ ): PeriodicComponent[][] {
17
+ const parent = new Int32Array(siteCount);
18
+ for (let site = 0; site < siteCount; site++) parent[site] = site;
19
+ for (const component of components) {
20
+ const first = (atoms[component.atoms[0] ?? 0] as ExpandedAtom).siteIndex;
21
+ for (const index of component.atoms) {
22
+ unite(parent, first, (atoms[index] as ExpandedAtom).siteIndex);
23
+ }
24
+ }
25
+ const classes = new Map<number, PeriodicComponent[]>();
26
+ for (const component of components) {
27
+ const site = (atoms[component.atoms[0] ?? 0] as ExpandedAtom).siteIndex;
28
+ const root = rootOf(parent, site);
29
+ const members = classes.get(root);
30
+ if (members === undefined) classes.set(root, [component]);
31
+ else members.push(component);
32
+ }
33
+ const roots = Int32Array.from(classes.keys()).toSorted();
34
+ const ordered: PeriodicComponent[][] = [];
35
+ for (let index = 0; index < roots.length; index++) {
36
+ ordered.push(classes.get(roots[index] ?? 0) ?? []);
37
+ }
38
+ return ordered;
39
+ }
40
+
41
+ function rootOf(parent: Int32Array, site: number): number {
42
+ let current = site;
43
+ while (parent[current] !== current) {
44
+ const next = parent[current] ?? current;
45
+ parent[current] = parent[next] ?? next;
46
+ current = next;
47
+ }
48
+ return current;
49
+ }
50
+
51
+ function unite(parent: Int32Array, a: number, b: number) {
52
+ const rootA = rootOf(parent, a);
53
+ const rootB = rootOf(parent, b);
54
+ if (rootA < rootB) parent[rootB] = rootA;
55
+ else if (rootB < rootA) parent[rootA] = rootB;
56
+ }
57
+
58
+ /**
59
+ * The copy of a molecule closest to the file: the one holding the most atoms
60
+ * the identity made, the first on a tie.
61
+ * @param members - The copies.
62
+ * @param atoms - The atoms of the cell.
63
+ * @param identityIndex - Index of the identity in the operation list.
64
+ * @returns The copy.
65
+ */
66
+ export function representative(
67
+ members: readonly PeriodicComponent[],
68
+ atoms: readonly ExpandedAtom[],
69
+ identityIndex: number,
70
+ ): PeriodicComponent {
71
+ let best = members[0] as PeriodicComponent;
72
+ let bestCount = -1;
73
+ for (const component of members) {
74
+ let count = 0;
75
+ for (const index of component.atoms) {
76
+ if ((atoms[index] as ExpandedAtom).operationIndex === identityIndex) {
77
+ count++;
78
+ }
79
+ }
80
+ if (count > bestCount) {
81
+ best = component;
82
+ bestCount = count;
83
+ }
84
+ }
85
+ return best;
86
+ }
87
+
88
+ /**
89
+ * The sites a group of connected sets is built from.
90
+ * @param members - The sets.
91
+ * @param atoms - The atoms of the cell.
92
+ * @returns The site indices, ascending.
93
+ */
94
+ export function siteIndicesOf(
95
+ members: readonly PeriodicComponent[],
96
+ atoms: readonly ExpandedAtom[],
97
+ ): number[] {
98
+ const seen = new Set<number>();
99
+ for (const component of members) {
100
+ for (const index of component.atoms) {
101
+ seen.add((atoms[index] as ExpandedAtom).siteIndex);
102
+ }
103
+ }
104
+ return Array.from(Int32Array.from(seen).toSorted());
105
+ }