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,106 @@
1
+ import type { CrystalSite, CrystalStructure } from './cif/types.ts';
2
+ import { chooseDisorder, isDummy } from './disorder.ts';
3
+ import type { ExpandedAtom } from './expand.ts';
4
+ import { expandSite } from './expand.ts';
5
+ import { structureOperations } from './operations.ts';
6
+ import type { Lattice } from './symmetry/lattice.ts';
7
+ import { createLattice } from './symmetry/lattice.ts';
8
+ import type { CrystalOperation } from './symmetry/types.ts';
9
+
10
+ /** Options of {@link crystalCellAtoms}. */
11
+ export interface CellAtomsOptions {
12
+ /**
13
+ * The most atoms one cell is expanded into; past it, none is returned.
14
+ * @default 100000
15
+ */
16
+ maxAtoms?: number;
17
+ }
18
+
19
+ /** What one cell of a crystal holds. */
20
+ export interface CellAtoms {
21
+ /** The cell. */
22
+ readonly lattice: Lattice;
23
+ /** The space group's operations, as the file states or implies them. */
24
+ readonly operations: ReadonlyArray<CrystalOperation<3>>;
25
+ /**
26
+ * Every atom of the cell, fractional and wrapped into [0, 1): each site that
27
+ * is not a dummy, expanded, with the major part of each disorder kept. Empty
28
+ * when the cell holds more than `maxAtoms`.
29
+ */
30
+ readonly atoms: readonly ExpandedAtom[];
31
+ /** How many atoms the expansion made, disorder included, counted past the cap. */
32
+ readonly count: number;
33
+ /** Whether the cell holds more than `maxAtoms`. */
34
+ readonly tooLarge: boolean;
35
+ }
36
+
37
+ /**
38
+ * The atoms one cell of a crystal holds, which is what a page draws or bonds.
39
+ *
40
+ * Every site that is not a dummy is expanded by the space group, and the
41
+ * disorder is resolved as `chooseDisorder` does: the atoms in no disorder group,
42
+ * and the major part of each.
43
+ * @param structure - What `readCif` returned.
44
+ * @param options - See {@link CellAtomsOptions}.
45
+ * @returns The cell's atoms, its lattice and its operations.
46
+ * @throws {Error} When the file names no space group and lists no operation, or
47
+ * its cell has angles no cell can have.
48
+ */
49
+ export function crystalCellAtoms(
50
+ structure: CrystalStructure,
51
+ options: CellAtomsOptions = {},
52
+ ): CellAtoms {
53
+ const { maxAtoms = 100_000 } = options;
54
+ const operations = structureOperations(structure);
55
+ const lattice = createLattice(structure.cell);
56
+ const { sites } = structure;
57
+ const expanded = expandSites(sites, operations, maxAtoms);
58
+ if (expanded.count > maxAtoms) {
59
+ return {
60
+ lattice,
61
+ operations,
62
+ atoms: [],
63
+ count: expanded.count,
64
+ tooLarge: true,
65
+ };
66
+ }
67
+ const kept = chooseDisorder(sites, expanded.atoms, lattice);
68
+ const atoms: ExpandedAtom[] = [];
69
+ for (const atom of expanded.atoms) {
70
+ if (kept[atom.siteIndex] === 1) atoms.push(atom);
71
+ }
72
+ return {
73
+ lattice,
74
+ operations,
75
+ atoms,
76
+ count: expanded.count,
77
+ tooLarge: false,
78
+ };
79
+ }
80
+
81
+ /**
82
+ * Every atom of the cell the sites that are not dummies make, counted past the cap.
83
+ * @param sites - The asymmetric unit.
84
+ * @param operations - The full coset list.
85
+ * @param maxAtoms - The most atoms kept.
86
+ * @returns The atoms, and how many the cell holds.
87
+ */
88
+ function expandSites(
89
+ sites: readonly CrystalSite[],
90
+ operations: ReadonlyArray<CrystalOperation<3>>,
91
+ maxAtoms: number,
92
+ ): { atoms: ExpandedAtom[]; count: number } {
93
+ const atoms: ExpandedAtom[] = [];
94
+ let count = 0;
95
+ for (let index = 0; index < sites.length; index++) {
96
+ const site = sites[index] as CrystalSite;
97
+ if (isDummy(site)) continue;
98
+ const images = expandSite(site, index, operations);
99
+ count += images.length;
100
+ if (count > maxAtoms) continue;
101
+ for (let image = 0; image < images.length; image++) {
102
+ atoms.push(images[image] as ExpandedAtom);
103
+ }
104
+ }
105
+ return { atoms, count };
106
+ }
@@ -0,0 +1,121 @@
1
+ import type { CrystalSite } from './cif/types.ts';
2
+ import { disorderGroupOf } from './disorder.ts';
3
+ import type { ExpandedAtom } from './expand.ts';
4
+ import type { PeriodicPairs } from './periodicBonds.ts';
5
+
6
+ /**
7
+ * The atoms to drop because another one already stands in their place.
8
+ * @param atoms - The atoms of one cell.
9
+ * @param coincident - The pairs of atoms closer than an atom to itself.
10
+ * @returns One flag per atom, 1 for an atom dropped.
11
+ */
12
+ export function writtenTwice(
13
+ atoms: readonly ExpandedAtom[],
14
+ coincident: Int32Array,
15
+ ): Uint8Array {
16
+ const removed = new Uint8Array(atoms.length);
17
+ for (let pair = 0; pair < coincident.length; pair += 2) {
18
+ const first = coincident[pair] ?? 0;
19
+ const second = coincident[pair + 1] ?? 0;
20
+ if (removed[first] === 1 || removed[second] === 1) continue;
21
+ const higher =
22
+ (atoms[second] as ExpandedAtom).occupancy >
23
+ (atoms[first] as ExpandedAtom).occupancy;
24
+ removed[higher ? first : second] = 1;
25
+ }
26
+ return removed;
27
+ }
28
+
29
+ /**
30
+ * The pairs kept as bonds: none to an atom dropped, none between the copies of
31
+ * a disorder about a special position, and one per hydrogen.
32
+ * @param pairs - The bonded pairs of the cell.
33
+ * @param atoms - The atoms of the cell.
34
+ * @param sites - The asymmetric unit.
35
+ * @param removed - One flag per atom, 1 for an atom dropped.
36
+ * @returns One flag per pair, 1 to keep it.
37
+ */
38
+ export function keptPairs(
39
+ pairs: PeriodicPairs,
40
+ atoms: readonly ExpandedAtom[],
41
+ sites: readonly CrystalSite[],
42
+ removed: Uint8Array,
43
+ ): Uint8Array {
44
+ const keep = new Uint8Array(pairs.count);
45
+ for (let pair = 0; pair < pairs.count; pair++) {
46
+ const first = pairs.from[pair] ?? 0;
47
+ const second = pairs.to[pair] ?? 0;
48
+ if (removed[first] === 1 || removed[second] === 1) continue;
49
+ if (keptApart(atoms[first], atoms[second], sites)) continue;
50
+ keep[pair] = 1;
51
+ }
52
+ keepNearestToHydrogen(pairs, atoms, keep);
53
+ return keep;
54
+ }
55
+
56
+ /**
57
+ * Whether two atoms are copies of a disorder that lies about a special
58
+ * position — a negative group, as SHELX writes it — made by different
59
+ * operations: such copies overlap on purpose, and are never bonded.
60
+ * @param a - One atom of the cell.
61
+ * @param b - Another one.
62
+ * @param sites - The asymmetric unit.
63
+ * @returns Whether they are kept apart.
64
+ */
65
+ function keptApart(
66
+ a: ExpandedAtom | undefined,
67
+ b: ExpandedAtom | undefined,
68
+ sites: readonly CrystalSite[],
69
+ ): boolean {
70
+ if (a === undefined || b === undefined) return false;
71
+ if (a.operationIndex === b.operationIndex) return false;
72
+ const groupA = disorderGroupOf(sites[a.siteIndex] as CrystalSite);
73
+ const groupB = disorderGroupOf(sites[b.siteIndex] as CrystalSite);
74
+ return (
75
+ groupA !== null &&
76
+ groupB !== null &&
77
+ (groupA.startsWith('-') || groupB.startsWith('-'))
78
+ );
79
+ }
80
+
81
+ /**
82
+ * A hydrogen holds one bond, to its nearest neighbour: one sitting between two
83
+ * oxygens of a short hydrogen bond would otherwise chain the molecules.
84
+ * @param pairs - The bonded pairs of the cell.
85
+ * @param atoms - The atoms of the cell.
86
+ * @param keep - One flag per pair, cleared where a hydrogen has a nearer partner.
87
+ */
88
+ function keepNearestToHydrogen(
89
+ pairs: PeriodicPairs,
90
+ atoms: readonly ExpandedAtom[],
91
+ keep: Uint8Array,
92
+ ) {
93
+ const nearest = new Int32Array(atoms.length).fill(-1);
94
+ for (let pair = 0; pair < pairs.count; pair++) {
95
+ if (keep[pair] === 0) continue;
96
+ for (let side = 0; side < 2; side++) {
97
+ const atom = (side === 0 ? pairs.from[pair] : pairs.to[pair]) ?? 0;
98
+ if ((atoms[atom] as ExpandedAtom).element !== 'H') continue;
99
+ const best = nearest[atom] ?? -1;
100
+ if (
101
+ best === -1 ||
102
+ (pairs.lengths[pair] ?? 0) < (pairs.lengths[best] ?? 0)
103
+ ) {
104
+ nearest[atom] = pair;
105
+ }
106
+ }
107
+ }
108
+ for (let pair = 0; pair < pairs.count; pair++) {
109
+ if (keep[pair] === 0) continue;
110
+ const from = pairs.from[pair] ?? 0;
111
+ const to = pairs.to[pair] ?? 0;
112
+ const fromHydrogen = (atoms[from] as ExpandedAtom).element === 'H';
113
+ const toHydrogen = (atoms[to] as ExpandedAtom).element === 'H';
114
+ if (
115
+ (fromHydrogen && nearest[from] !== pair) ||
116
+ (toHydrogen && nearest[to] !== pair)
117
+ ) {
118
+ keep[pair] = 0;
119
+ }
120
+ }
121
+ }
@@ -0,0 +1,40 @@
1
+ import { elementBySymbol } from '../../../periodic/core/elements.ts';
2
+
3
+ /**
4
+ * Read the element of an atom site: the type symbol's, else the label's.
5
+ * @param typeSymbol - `_atom_site_type_symbol`, or `null` when absent.
6
+ * @param label - `_atom_site_label`.
7
+ * @returns The chemical symbol.
8
+ * @throws {Error} When neither opens with an element symbol.
9
+ */
10
+ export function elementOf(typeSymbol: string | null, label: string): string {
11
+ const fromType = typeSymbol === null ? null : symbolOf(typeSymbol);
12
+ if (fromType !== null) return fromType;
13
+ const fromLabel = symbolOf(label);
14
+ if (fromLabel !== null) return fromLabel;
15
+ throw new Error(
16
+ `Atom site "${label}" names no element: neither its type symbol nor its label opens with one.`,
17
+ );
18
+ }
19
+
20
+ /**
21
+ * Read the chemical symbol a CIF token opens with.
22
+ *
23
+ * A type symbol carries the oxidation state (`Na1+`, `Cl1-`) and a label
24
+ * carries an index in whatever case the refinement wrote it (`NA1`, `CL2`), so
25
+ * the letters are taken, recapitalised and checked against the periodic table.
26
+ * Deuterium, which a neutron structure writes `D`, is hydrogen.
27
+ * @param token - a type symbol or an atom-site label.
28
+ * @returns the symbol, or `null` when the letters name no element.
29
+ */
30
+ function symbolOf(token: string): string | null {
31
+ const letters = /^(?<letters>[A-Za-z]{1,2})/.exec(token)?.groups?.letters;
32
+ if (letters === undefined) return null;
33
+ for (let length = letters.length; length >= 1; length--) {
34
+ const symbol =
35
+ letters.charAt(0).toUpperCase() + letters.slice(1, length).toLowerCase();
36
+ if (elementBySymbol(symbol) !== undefined) return symbol;
37
+ if (symbol === 'D') return 'H';
38
+ }
39
+ return null;
40
+ }
@@ -0,0 +1,12 @@
1
+ export { formatCifNumber, formatNumber, parseCifNumber } from './number.ts';
2
+ export { readCif } from './read.ts';
3
+ export type {
4
+ CifGeometryBond,
5
+ CifGeometryTorsion,
6
+ CifNumber,
7
+ CrystalCell,
8
+ CrystalSite,
9
+ CrystalSource,
10
+ CrystalSpaceGroup,
11
+ CrystalStructure,
12
+ } from './types.ts';
@@ -0,0 +1,62 @@
1
+ import type { CifNumber } from './types.ts';
2
+
3
+ /**
4
+ * Read a CIF numeric token.
5
+ *
6
+ * `cif-to-json` never converts anything: every field arrives as a string, with
7
+ * the standard uncertainty still attached and with `.` and `?` already
8
+ * collapsed to the empty string.
9
+ * @param token - the raw field, e.g. `0.30475(3)`, `90`, `.5`, `-1.5e2`, `.`, `?` or ``.
10
+ * @returns the number, or `null` when the field is absent, unknown or not a number.
11
+ */
12
+ export function parseCifNumber(
13
+ token: string | null | undefined,
14
+ ): CifNumber | null {
15
+ if (token === null || token === undefined) return null;
16
+ const raw = token.trim();
17
+ if (MISSING.has(raw)) return null;
18
+ const match = NUMBER.exec(raw);
19
+ if (match?.groups === undefined) return null;
20
+
21
+ const { sign, mantissa, digits, exponent } = match.groups;
22
+ if (mantissa === undefined) return null;
23
+ const power = exponent === undefined ? 0 : Number(exponent);
24
+ const value = Number(`${sign ?? ''}${mantissa}e${power}`);
25
+ if (!Number.isFinite(value)) return null;
26
+
27
+ const dot = mantissa.indexOf('.');
28
+ const decimals = dot === -1 ? 0 : mantissa.length - dot - 1;
29
+ const su =
30
+ digits === undefined ? null : Number(`${digits}e${power - decimals}`);
31
+ return { value, su, raw };
32
+ }
33
+
34
+ /**
35
+ * Write a CIF numeric token, re-attaching the standard uncertainty.
36
+ * @param number - the value to write.
37
+ * @returns `0.30475(3)` for `{ value: 0.30475, su: 0.00003 }`.
38
+ */
39
+ export function formatCifNumber(number: CifNumber): string {
40
+ const text = formatNumber(number.value);
41
+ if (number.su === null) return text;
42
+ const dot = text.indexOf('.');
43
+ const decimals = dot === -1 ? 0 : text.length - dot - 1;
44
+ return `${text}(${Math.round(number.su * 10 ** decimals)})`;
45
+ }
46
+
47
+ /**
48
+ * Write a plain number the way a CIF field wants it.
49
+ *
50
+ * `String` gives the shortest text that reads back as the same double, so a
51
+ * value written here and read by `parseCifNumber` is bit-identical.
52
+ * @param value - the value to write.
53
+ * @returns the field text.
54
+ */
55
+ export function formatNumber(value: number): string {
56
+ return Object.is(value, -0) ? '0' : String(value);
57
+ }
58
+
59
+ const MISSING = new Set(['', '.', '?']);
60
+
61
+ const NUMBER =
62
+ /^(?<sign>[+-]?)(?<mantissa>\d+\.?\d*|\.\d+)(?:\((?<digits>\d+)\))?(?:[Ee](?<exponent>[+-]?\d+))?$/;
@@ -0,0 +1,218 @@
1
+ import { parseCifBlocks } from 'cif-to-json';
2
+
3
+ import { elementOf } from './element.ts';
4
+ import { parseCifNumber } from './number.ts';
5
+ import { readGeometryBonds, readGeometryTorsions } from './readGeometry.ts';
6
+ import type { CifIndex, CifRowIndex } from './tags.ts';
7
+ import {
8
+ HALL_TAGS,
9
+ HM_TAGS,
10
+ IT_NUMBER_TAGS,
11
+ SYMOP_TAGS,
12
+ indexCif,
13
+ loopWith,
14
+ optionalRowTag,
15
+ rowTag,
16
+ scalarTag,
17
+ } from './tags.ts';
18
+ import type {
19
+ CrystalCell,
20
+ CrystalSite,
21
+ CrystalSource,
22
+ CrystalSpaceGroup,
23
+ CrystalStructure,
24
+ } from './types.ts';
25
+
26
+ /**
27
+ * Read one crystal structure from a CIF.
28
+ * @param text - CIF file content, one `data_` block.
29
+ * @returns the structure, with every value converted from the strings
30
+ * `cif-to-json` returns. `geometryBonds` and `geometryTorsions` are present
31
+ * only when the file carries the loop.
32
+ * @throws {Error} when the file holds more than one data block, carries no unit cell,
33
+ * or names an atom whose element cannot be read.
34
+ */
35
+ export function readCif(text: string): CrystalStructure {
36
+ const blocks = parseCifBlocks(text);
37
+ if (blocks.length > 1) {
38
+ const names = blocks.map((block) => block.name).join(', ');
39
+ throw new Error(
40
+ `This file holds ${blocks.length} data blocks (${names}). Split it and load one structure at a time.`,
41
+ );
42
+ }
43
+ const [block] = blocks;
44
+ const index = indexCif(block?.data ?? {});
45
+ const geometryBonds = readGeometryBonds(index);
46
+ const geometryTorsions = readGeometryTorsions(index);
47
+ return {
48
+ name: block?.name ?? '',
49
+ formula:
50
+ scalarTag(index, ['_chemical_formula_sum', '_chemical_formula_moiety']) ??
51
+ '',
52
+ cell: readCell(index),
53
+ spaceGroup: readSpaceGroup(index),
54
+ symopsXyz: readSymops(index),
55
+ sites: readSites(index),
56
+ source: readSource(index),
57
+ ...(geometryBonds === null ? {} : { geometryBonds }),
58
+ ...(geometryTorsions === null ? {} : { geometryTorsions }),
59
+ };
60
+ }
61
+
62
+ function readCell(index: CifIndex): CrystalCell {
63
+ return {
64
+ a: cellNumber(index, '_cell_length_a'),
65
+ b: cellNumber(index, '_cell_length_b'),
66
+ c: cellNumber(index, '_cell_length_c'),
67
+ alpha: cellNumber(index, '_cell_angle_alpha'),
68
+ beta: cellNumber(index, '_cell_angle_beta'),
69
+ gamma: cellNumber(index, '_cell_angle_gamma'),
70
+ };
71
+ }
72
+
73
+ function cellNumber(index: CifIndex, tag: string): number {
74
+ const parsed = parseCifNumber(scalarTag(index, [tag]));
75
+ if (parsed === null) {
76
+ throw new Error(
77
+ `This CIF has no unit cell: ${tag} is missing or is not a number.`,
78
+ );
79
+ }
80
+ return parsed.value;
81
+ }
82
+
83
+ function readSpaceGroup(index: CifIndex): CrystalSpaceGroup {
84
+ const parsed = parseCifNumber(scalarTag(index, IT_NUMBER_TAGS));
85
+ const number = parsed?.value ?? null;
86
+ return {
87
+ number:
88
+ number !== null &&
89
+ Number.isInteger(number) &&
90
+ number >= 1 &&
91
+ number <= 230
92
+ ? number
93
+ : null,
94
+ hm: scalarTag(index, HM_TAGS),
95
+ hall: scalarTag(index, HALL_TAGS),
96
+ };
97
+ }
98
+
99
+ function readSymops(index: CifIndex): string[] {
100
+ const rows = loopWith(index, SYMOP_TAGS);
101
+ if (rows === null) return [];
102
+ const operations: string[] = [];
103
+ for (const row of rows) {
104
+ const xyz = rowTag(row, SYMOP_TAGS);
105
+ if (xyz !== null) operations.push(xyz);
106
+ }
107
+ return operations;
108
+ }
109
+
110
+ function readSites(index: CifIndex): CrystalSite[] {
111
+ const rows = loopWith(index, FRACT_X_TAGS);
112
+ if (rows === null) return [];
113
+ const sites: CrystalSite[] = [];
114
+ for (const row of rows) sites.push(readSite(row));
115
+ return sites;
116
+ }
117
+
118
+ function readSite(row: CifRowIndex): CrystalSite {
119
+ const typeSymbol = rowTag(row, TYPE_SYMBOL_TAGS);
120
+ const label = rowTag(row, LABEL_TAGS) ?? typeSymbol;
121
+ if (label === null) {
122
+ throw new Error(
123
+ 'An atom site of this CIF carries neither a label nor a type symbol.',
124
+ );
125
+ }
126
+ const occupancy = parseCifNumber(rowTag(row, OCCUPANCY_TAGS));
127
+ const disorderGroup = optionalRowTag(row, DISORDER_GROUP_TAGS);
128
+ const disorderAssembly = optionalRowTag(row, DISORDER_ASSEMBLY_TAGS);
129
+ const calcFlag = optionalRowTag(row, CALC_FLAG_TAGS);
130
+ return {
131
+ label,
132
+ element: elementOf(typeSymbol, label),
133
+ x: siteNumber(row, FRACT_X_TAGS, label),
134
+ y: siteNumber(row, FRACT_Y_TAGS, label),
135
+ z: siteNumber(row, FRACT_Z_TAGS, label),
136
+ occupancy: occupancy?.value ?? 1,
137
+ uiso: readUiso(row),
138
+ ...(disorderGroup === null ? {} : { disorderGroup }),
139
+ ...(disorderAssembly === null ? {} : { disorderAssembly }),
140
+ ...(calcFlag === null ? {} : { calcFlag }),
141
+ };
142
+ }
143
+
144
+ function siteNumber(
145
+ row: CifRowIndex,
146
+ aliases: readonly string[],
147
+ label: string,
148
+ ): number {
149
+ const parsed = parseCifNumber(rowTag(row, aliases));
150
+ if (parsed === null) {
151
+ throw new Error(
152
+ `Atom site "${label}" has no fractional coordinate on ${aliases[0] ?? ''}.`,
153
+ );
154
+ }
155
+ return parsed.value;
156
+ }
157
+
158
+ /**
159
+ * Read the isotropic displacement parameter, in Ų.
160
+ *
161
+ * A file that gives `_atom_site_B_iso_or_equiv` instead is converted with
162
+ * `U = B / 8π²`, which is the definition of the two quantities.
163
+ * @param row - the atom-site row.
164
+ * @returns U_iso, or `null` when the file gives neither.
165
+ */
166
+ function readUiso(row: CifRowIndex): number | null {
167
+ const u = parseCifNumber(rowTag(row, U_ISO_TAGS));
168
+ if (u !== null) return u.value;
169
+ const b = parseCifNumber(rowTag(row, B_ISO_TAGS));
170
+ return b === null ? null : b.value / (8 * Math.PI * Math.PI);
171
+ }
172
+
173
+ function readSource(index: CifIndex): CrystalSource {
174
+ const source: { doi?: string; cod?: string; note?: string } = {};
175
+ const doi = scalarTag(index, ['_journal_paper_doi']);
176
+ if (doi !== null) source.doi = doi;
177
+ const cod = scalarTag(index, ['_cod_database_code']);
178
+ if (cod !== null) source.cod = cod;
179
+ const note = scalarTag(index, [
180
+ '_chemical_name_mineral',
181
+ '_chemical_name_common',
182
+ ]);
183
+ if (note !== null) source.note = note;
184
+ return source;
185
+ }
186
+
187
+ const FRACT_X_TAGS = ['_atom_site_fract_x', '_atom_site.fract_x'] as const;
188
+ const FRACT_Y_TAGS = ['_atom_site_fract_y', '_atom_site.fract_y'] as const;
189
+ const FRACT_Z_TAGS = ['_atom_site_fract_z', '_atom_site.fract_z'] as const;
190
+ const LABEL_TAGS = ['_atom_site_label', '_atom_site.label'] as const;
191
+ const TYPE_SYMBOL_TAGS = [
192
+ '_atom_site_type_symbol',
193
+ '_atom_site.type_symbol',
194
+ ] as const;
195
+ const OCCUPANCY_TAGS = [
196
+ '_atom_site_occupancy',
197
+ '_atom_site.occupancy',
198
+ ] as const;
199
+ const U_ISO_TAGS = [
200
+ '_atom_site_u_iso_or_equiv',
201
+ '_atom_site.u_iso_or_equiv',
202
+ ] as const;
203
+ const DISORDER_GROUP_TAGS = [
204
+ '_atom_site_disorder_group',
205
+ '_atom_site.disorder_group',
206
+ ] as const;
207
+ const DISORDER_ASSEMBLY_TAGS = [
208
+ '_atom_site_disorder_assembly',
209
+ '_atom_site.disorder_assembly',
210
+ ] as const;
211
+ const CALC_FLAG_TAGS = [
212
+ '_atom_site_calc_flag',
213
+ '_atom_site.calc_flag',
214
+ ] as const;
215
+ const B_ISO_TAGS = [
216
+ '_atom_site_b_iso_or_equiv',
217
+ '_atom_site.b_iso_or_equiv',
218
+ ] as const;
@@ -0,0 +1,104 @@
1
+ import { parseCifNumber } from './number.ts';
2
+ import type { CifIndex, CifRowIndex } from './tags.ts';
3
+ import { loopWith, optionalRowTag, rowTag } from './tags.ts';
4
+ import type { CifGeometryBond, CifGeometryTorsion } from './types.ts';
5
+
6
+ /**
7
+ * Read the `_geom_bond` loop: the distances the authors reported.
8
+ * @param index - the folded CIF.
9
+ * @returns the bonds in file order, or `null` when the file has no such loop.
10
+ * A row whose labels or distance cannot be read is left out.
11
+ */
12
+ export function readGeometryBonds(index: CifIndex): CifGeometryBond[] | null {
13
+ const rows = loopWith(index, BOND_LABEL_1);
14
+ if (rows === null) return null;
15
+ const bonds: CifGeometryBond[] = [];
16
+ for (const row of rows) {
17
+ const label1 = rowTag(row, BOND_LABEL_1);
18
+ const label2 = rowTag(row, BOND_LABEL_2);
19
+ const distance = parseCifNumber(rowTag(row, BOND_DISTANCE));
20
+ if (label1 === null || label2 === null || distance === null) continue;
21
+ bonds.push({
22
+ label1,
23
+ label2,
24
+ distance,
25
+ ...symmetryCode(row, 'siteSymmetry1', BOND_SYMMETRY_1),
26
+ ...symmetryCode(row, 'siteSymmetry2', BOND_SYMMETRY_2),
27
+ });
28
+ }
29
+ return bonds;
30
+ }
31
+
32
+ /**
33
+ * Read the `_geom_torsion` loop: the torsion angles the authors reported.
34
+ * @param index - the folded CIF.
35
+ * @returns the torsions in file order, or `null` when the file has no such
36
+ * loop. A row whose labels or angle cannot be read is left out.
37
+ */
38
+ export function readGeometryTorsions(
39
+ index: CifIndex,
40
+ ): CifGeometryTorsion[] | null {
41
+ const rows = loopWith(index, torsionTags('atom_site_label_1'));
42
+ if (rows === null) return null;
43
+ const torsions: CifGeometryTorsion[] = [];
44
+ for (const row of rows) {
45
+ const label1 = rowTag(row, torsionTags('atom_site_label_1'));
46
+ const label2 = rowTag(row, torsionTags('atom_site_label_2'));
47
+ const label3 = rowTag(row, torsionTags('atom_site_label_3'));
48
+ const label4 = rowTag(row, torsionTags('atom_site_label_4'));
49
+ const angle = parseCifNumber(rowTag(row, TORSION_ANGLE));
50
+ if (
51
+ label1 === null ||
52
+ label2 === null ||
53
+ label3 === null ||
54
+ label4 === null ||
55
+ angle === null
56
+ ) {
57
+ continue;
58
+ }
59
+ torsions.push({
60
+ label1,
61
+ label2,
62
+ label3,
63
+ label4,
64
+ angle,
65
+ ...symmetryCode(row, 'siteSymmetry1', torsionTags('site_symmetry_1')),
66
+ ...symmetryCode(row, 'siteSymmetry2', torsionTags('site_symmetry_2')),
67
+ ...symmetryCode(row, 'siteSymmetry3', torsionTags('site_symmetry_3')),
68
+ ...symmetryCode(row, 'siteSymmetry4', torsionTags('site_symmetry_4')),
69
+ });
70
+ }
71
+ return torsions;
72
+ }
73
+
74
+ function symmetryCode<K extends string>(
75
+ row: CifRowIndex,
76
+ key: K,
77
+ aliases: readonly string[],
78
+ ): Partial<Record<K, string>> {
79
+ const code = optionalRowTag(row, aliases);
80
+ return code === null ? {} : ({ [key]: code } as Record<K, string>);
81
+ }
82
+
83
+ function torsionTags(column: string): readonly string[] {
84
+ return [`_geom_torsion_${column}`, `_geom_torsion.${column}`];
85
+ }
86
+
87
+ const BOND_LABEL_1 = [
88
+ '_geom_bond_atom_site_label_1',
89
+ '_geom_bond.atom_site_label_1',
90
+ ] as const;
91
+ const BOND_LABEL_2 = [
92
+ '_geom_bond_atom_site_label_2',
93
+ '_geom_bond.atom_site_label_2',
94
+ ] as const;
95
+ const BOND_DISTANCE = ['_geom_bond_distance', '_geom_bond.distance'] as const;
96
+ const BOND_SYMMETRY_1 = [
97
+ '_geom_bond_site_symmetry_1',
98
+ '_geom_bond.site_symmetry_1',
99
+ ] as const;
100
+ const BOND_SYMMETRY_2 = [
101
+ '_geom_bond_site_symmetry_2',
102
+ '_geom_bond.site_symmetry_2',
103
+ ] as const;
104
+ const TORSION_ANGLE = ['_geom_torsion', '_geom_torsion.value'] as const;