react-cheminfo 0.134.0 → 0.135.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 (181) 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/cellBonds.d.ts +21 -0
  7. package/lib/crystal/core/cellBonds.d.ts.map +1 -0
  8. package/lib/crystal/core/cellBonds.js +100 -0
  9. package/lib/crystal/core/cellBonds.js.map +1 -0
  10. package/lib/crystal/core/cif/element.d.ts +9 -0
  11. package/lib/crystal/core/cif/element.d.ts.map +1 -0
  12. package/lib/crystal/core/cif/element.js +41 -0
  13. package/lib/crystal/core/cif/element.js.map +1 -0
  14. package/lib/crystal/core/cif/index.d.ts +4 -0
  15. package/lib/crystal/core/cif/index.d.ts.map +1 -0
  16. package/lib/crystal/core/cif/index.js +3 -0
  17. package/lib/crystal/core/cif/index.js.map +1 -0
  18. package/lib/crystal/core/cif/number.d.ts +27 -0
  19. package/lib/crystal/core/cif/number.d.ts.map +1 -0
  20. package/lib/crystal/core/cif/number.js +57 -0
  21. package/lib/crystal/core/cif/number.js.map +1 -0
  22. package/lib/crystal/core/cif/read.d.ts +12 -0
  23. package/lib/crystal/core/cif/read.d.ts.map +1 -0
  24. package/lib/crystal/core/cif/read.js +183 -0
  25. package/lib/crystal/core/cif/read.js.map +1 -0
  26. package/lib/crystal/core/cif/readGeometry.d.ts +17 -0
  27. package/lib/crystal/core/cif/readGeometry.d.ts.map +1 -0
  28. package/lib/crystal/core/cif/readGeometry.js +93 -0
  29. package/lib/crystal/core/cif/readGeometry.js.map +1 -0
  30. package/lib/crystal/core/cif/tags.d.ts +62 -0
  31. package/lib/crystal/core/cif/tags.d.ts.map +1 -0
  32. package/lib/crystal/core/cif/tags.js +115 -0
  33. package/lib/crystal/core/cif/tags.js.map +1 -0
  34. package/lib/crystal/core/cif/types.d.ts +158 -0
  35. package/lib/crystal/core/cif/types.d.ts.map +1 -0
  36. package/lib/crystal/core/cif/types.js +2 -0
  37. package/lib/crystal/core/cif/types.js.map +1 -0
  38. package/lib/crystal/core/components.d.ts +56 -0
  39. package/lib/crystal/core/components.d.ts.map +1 -0
  40. package/lib/crystal/core/components.js +132 -0
  41. package/lib/crystal/core/components.js.map +1 -0
  42. package/lib/crystal/core/covalentRadii.d.ts +24 -0
  43. package/lib/crystal/core/covalentRadii.d.ts.map +1 -0
  44. package/lib/crystal/core/covalentRadii.js +55 -0
  45. package/lib/crystal/core/covalentRadii.js.map +1 -0
  46. package/lib/crystal/core/disorder.d.ts +59 -0
  47. package/lib/crystal/core/disorder.d.ts.map +1 -0
  48. package/lib/crystal/core/disorder.js +168 -0
  49. package/lib/crystal/core/disorder.js.map +1 -0
  50. package/lib/crystal/core/expand.d.ts +62 -0
  51. package/lib/crystal/core/expand.d.ts.map +1 -0
  52. package/lib/crystal/core/expand.js +61 -0
  53. package/lib/crystal/core/expand.js.map +1 -0
  54. package/lib/crystal/core/index.d.ts +18 -0
  55. package/lib/crystal/core/index.d.ts.map +1 -0
  56. package/lib/crystal/core/index.js +12 -0
  57. package/lib/crystal/core/index.js.map +1 -0
  58. package/lib/crystal/core/moleculeOf.d.ts +31 -0
  59. package/lib/crystal/core/moleculeOf.d.ts.map +1 -0
  60. package/lib/crystal/core/moleculeOf.js +128 -0
  61. package/lib/crystal/core/moleculeOf.js.map +1 -0
  62. package/lib/crystal/core/moleculeTypes.d.ts +80 -0
  63. package/lib/crystal/core/moleculeTypes.d.ts.map +1 -0
  64. package/lib/crystal/core/moleculeTypes.js +2 -0
  65. package/lib/crystal/core/moleculeTypes.js.map +1 -0
  66. package/lib/crystal/core/molecules.d.ts +39 -0
  67. package/lib/crystal/core/molecules.d.ts.map +1 -0
  68. package/lib/crystal/core/molecules.js +140 -0
  69. package/lib/crystal/core/molecules.js.map +1 -0
  70. package/lib/crystal/core/operations.d.ts +19 -0
  71. package/lib/crystal/core/operations.d.ts.map +1 -0
  72. package/lib/crystal/core/operations.js +68 -0
  73. package/lib/crystal/core/operations.js.map +1 -0
  74. package/lib/crystal/core/packing.d.ts +43 -0
  75. package/lib/crystal/core/packing.d.ts.map +1 -0
  76. package/lib/crystal/core/packing.js +89 -0
  77. package/lib/crystal/core/packing.js.map +1 -0
  78. package/lib/crystal/core/periodicBonds.d.ts +57 -0
  79. package/lib/crystal/core/periodicBonds.d.ts.map +1 -0
  80. package/lib/crystal/core/periodicBonds.js +167 -0
  81. package/lib/crystal/core/periodicBonds.js.map +1 -0
  82. package/lib/crystal/core/resolve.d.ts +61 -0
  83. package/lib/crystal/core/resolve.d.ts.map +1 -0
  84. package/lib/crystal/core/resolve.js +149 -0
  85. package/lib/crystal/core/resolve.js.map +1 -0
  86. package/lib/crystal/core/spaceGroups/index.d.ts +5 -0
  87. package/lib/crystal/core/spaceGroups/index.d.ts.map +1 -0
  88. package/lib/crystal/core/spaceGroups/index.js +4 -0
  89. package/lib/crystal/core/spaceGroups/index.js.map +1 -0
  90. package/lib/crystal/core/spaceGroups/spaceGroupOperations.d.ts +14 -0
  91. package/lib/crystal/core/spaceGroups/spaceGroupOperations.d.ts.map +1 -0
  92. package/lib/crystal/core/spaceGroups/spaceGroupOperations.js +24 -0
  93. package/lib/crystal/core/spaceGroups/spaceGroupOperations.js.map +1 -0
  94. package/lib/crystal/core/spaceGroups/spaceGroupRows.d.ts +3 -0
  95. package/lib/crystal/core/spaceGroups/spaceGroupRows.d.ts.map +1 -0
  96. package/lib/crystal/core/spaceGroups/spaceGroupRows.js +536 -0
  97. package/lib/crystal/core/spaceGroups/spaceGroupRows.js.map +1 -0
  98. package/lib/crystal/core/spaceGroups/spaceGroupSymbols.d.ts +43 -0
  99. package/lib/crystal/core/spaceGroups/spaceGroupSymbols.d.ts.map +1 -0
  100. package/lib/crystal/core/spaceGroups/spaceGroupSymbols.js +169 -0
  101. package/lib/crystal/core/spaceGroups/spaceGroupSymbols.js.map +1 -0
  102. package/lib/crystal/core/spaceGroups/spaceGroups.d.ts +78 -0
  103. package/lib/crystal/core/spaceGroups/spaceGroups.d.ts.map +1 -0
  104. package/lib/crystal/core/spaceGroups/spaceGroups.js +83 -0
  105. package/lib/crystal/core/spaceGroups/spaceGroups.js.map +1 -0
  106. package/lib/crystal/core/symmetry/group.d.ts +15 -0
  107. package/lib/crystal/core/symmetry/group.d.ts.map +1 -0
  108. package/lib/crystal/core/symmetry/group.js +37 -0
  109. package/lib/crystal/core/symmetry/group.js.map +1 -0
  110. package/lib/crystal/core/symmetry/index.d.ts +8 -0
  111. package/lib/crystal/core/symmetry/index.d.ts.map +1 -0
  112. package/lib/crystal/core/symmetry/index.js +6 -0
  113. package/lib/crystal/core/symmetry/index.js.map +1 -0
  114. package/lib/crystal/core/symmetry/integerMatrix.d.ts +45 -0
  115. package/lib/crystal/core/symmetry/integerMatrix.d.ts.map +1 -0
  116. package/lib/crystal/core/symmetry/integerMatrix.js +139 -0
  117. package/lib/crystal/core/symmetry/integerMatrix.js.map +1 -0
  118. package/lib/crystal/core/symmetry/lattice.d.ts +64 -0
  119. package/lib/crystal/core/symmetry/lattice.d.ts.map +1 -0
  120. package/lib/crystal/core/symmetry/lattice.js +113 -0
  121. package/lib/crystal/core/symmetry/lattice.js.map +1 -0
  122. package/lib/crystal/core/symmetry/operation.d.ts +91 -0
  123. package/lib/crystal/core/symmetry/operation.d.ts.map +1 -0
  124. package/lib/crystal/core/symmetry/operation.js +184 -0
  125. package/lib/crystal/core/symmetry/operation.js.map +1 -0
  126. package/lib/crystal/core/symmetry/parseOperation.d.ts +18 -0
  127. package/lib/crystal/core/symmetry/parseOperation.d.ts.map +1 -0
  128. package/lib/crystal/core/symmetry/parseOperation.js +145 -0
  129. package/lib/crystal/core/symmetry/parseOperation.js.map +1 -0
  130. package/lib/crystal/core/symmetry/types.d.ts +29 -0
  131. package/lib/crystal/core/symmetry/types.d.ts.map +1 -0
  132. package/lib/crystal/core/symmetry/types.js +5 -0
  133. package/lib/crystal/core/symmetry/types.js.map +1 -0
  134. package/lib/crystal/core/symmetryClasses.d.ts +28 -0
  135. package/lib/crystal/core/symmetryClasses.d.ts.map +1 -0
  136. package/lib/crystal/core/symmetryClasses.js +93 -0
  137. package/lib/crystal/core/symmetryClasses.js.map +1 -0
  138. package/lib/crystal.d.ts +12 -0
  139. package/lib/crystal.d.ts.map +1 -0
  140. package/lib/crystal.js +12 -0
  141. package/lib/crystal.js.map +1 -0
  142. package/lib/server/spaSite.d.ts.map +1 -1
  143. package/lib/server/spaSite.js +9 -0
  144. package/lib/server/spaSite.js.map +1 -1
  145. package/package.json +3 -1
  146. package/src/crystal/core/bondGrid.ts +98 -0
  147. package/src/crystal/core/cellBonds.ts +121 -0
  148. package/src/crystal/core/cif/element.ts +40 -0
  149. package/src/crystal/core/cif/index.ts +12 -0
  150. package/src/crystal/core/cif/number.ts +62 -0
  151. package/src/crystal/core/cif/read.ts +218 -0
  152. package/src/crystal/core/cif/readGeometry.ts +104 -0
  153. package/src/crystal/core/cif/tags.ts +143 -0
  154. package/src/crystal/core/cif/types.ts +164 -0
  155. package/src/crystal/core/components.ts +183 -0
  156. package/src/crystal/core/covalentRadii.ts +56 -0
  157. package/src/crystal/core/disorder.ts +190 -0
  158. package/src/crystal/core/expand.ts +105 -0
  159. package/src/crystal/core/index.ts +44 -0
  160. package/src/crystal/core/moleculeOf.ts +169 -0
  161. package/src/crystal/core/moleculeTypes.ts +85 -0
  162. package/src/crystal/core/molecules.ts +165 -0
  163. package/src/crystal/core/operations.ts +79 -0
  164. package/src/crystal/core/packing.ts +116 -0
  165. package/src/crystal/core/periodicBonds.ts +234 -0
  166. package/src/crystal/core/resolve.ts +187 -0
  167. package/src/crystal/core/spaceGroups/index.ts +16 -0
  168. package/src/crystal/core/spaceGroups/spaceGroupOperations.ts +32 -0
  169. package/src/crystal/core/spaceGroups/spaceGroupRows.ts +536 -0
  170. package/src/crystal/core/spaceGroups/spaceGroupSymbols.ts +179 -0
  171. package/src/crystal/core/spaceGroups/spaceGroups.ts +154 -0
  172. package/src/crystal/core/symmetry/group.ts +42 -0
  173. package/src/crystal/core/symmetry/index.ts +23 -0
  174. package/src/crystal/core/symmetry/integerMatrix.ts +153 -0
  175. package/src/crystal/core/symmetry/lattice.ts +152 -0
  176. package/src/crystal/core/symmetry/operation.ts +223 -0
  177. package/src/crystal/core/symmetry/parseOperation.ts +180 -0
  178. package/src/crystal/core/symmetry/types.ts +32 -0
  179. package/src/crystal/core/symmetryClasses.ts +105 -0
  180. package/src/crystal.ts +12 -0
  181. package/src/server/spaSite.ts +9 -0
@@ -0,0 +1,183 @@
1
+ import { parseCifBlocks } from 'cif-to-json';
2
+ import { elementOf } from "./element.js";
3
+ import { parseCifNumber } from "./number.js";
4
+ import { readGeometryBonds, readGeometryTorsions } from "./readGeometry.js";
5
+ import { HALL_TAGS, HM_TAGS, IT_NUMBER_TAGS, SYMOP_TAGS, indexCif, loopWith, optionalRowTag, rowTag, scalarTag, } from "./tags.js";
6
+ /**
7
+ * Read one crystal structure from a CIF.
8
+ * @param text - CIF file content, one `data_` block.
9
+ * @returns the structure, with every value converted from the strings
10
+ * `cif-to-json` returns. `geometryBonds` and `geometryTorsions` are present
11
+ * only when the file carries the loop.
12
+ * @throws {Error} when the file holds more than one data block, carries no unit cell,
13
+ * or names an atom whose element cannot be read.
14
+ */
15
+ export function readCif(text) {
16
+ const blocks = parseCifBlocks(text);
17
+ if (blocks.length > 1) {
18
+ const names = blocks.map((block) => block.name).join(', ');
19
+ throw new Error(`This file holds ${blocks.length} data blocks (${names}). Split it and load one structure at a time.`);
20
+ }
21
+ const [block] = blocks;
22
+ const index = indexCif(block?.data ?? {});
23
+ const geometryBonds = readGeometryBonds(index);
24
+ const geometryTorsions = readGeometryTorsions(index);
25
+ return {
26
+ name: block?.name ?? '',
27
+ formula: scalarTag(index, ['_chemical_formula_sum', '_chemical_formula_moiety']) ??
28
+ '',
29
+ cell: readCell(index),
30
+ spaceGroup: readSpaceGroup(index),
31
+ symopsXyz: readSymops(index),
32
+ sites: readSites(index),
33
+ source: readSource(index),
34
+ ...(geometryBonds === null ? {} : { geometryBonds }),
35
+ ...(geometryTorsions === null ? {} : { geometryTorsions }),
36
+ };
37
+ }
38
+ function readCell(index) {
39
+ return {
40
+ a: cellNumber(index, '_cell_length_a'),
41
+ b: cellNumber(index, '_cell_length_b'),
42
+ c: cellNumber(index, '_cell_length_c'),
43
+ alpha: cellNumber(index, '_cell_angle_alpha'),
44
+ beta: cellNumber(index, '_cell_angle_beta'),
45
+ gamma: cellNumber(index, '_cell_angle_gamma'),
46
+ };
47
+ }
48
+ function cellNumber(index, tag) {
49
+ const parsed = parseCifNumber(scalarTag(index, [tag]));
50
+ if (parsed === null) {
51
+ throw new Error(`This CIF has no unit cell: ${tag} is missing or is not a number.`);
52
+ }
53
+ return parsed.value;
54
+ }
55
+ function readSpaceGroup(index) {
56
+ const parsed = parseCifNumber(scalarTag(index, IT_NUMBER_TAGS));
57
+ const number = parsed?.value ?? null;
58
+ return {
59
+ number: number !== null &&
60
+ Number.isInteger(number) &&
61
+ number >= 1 &&
62
+ number <= 230
63
+ ? number
64
+ : null,
65
+ hm: scalarTag(index, HM_TAGS),
66
+ hall: scalarTag(index, HALL_TAGS),
67
+ };
68
+ }
69
+ function readSymops(index) {
70
+ const rows = loopWith(index, SYMOP_TAGS);
71
+ if (rows === null)
72
+ return [];
73
+ const operations = [];
74
+ for (const row of rows) {
75
+ const xyz = rowTag(row, SYMOP_TAGS);
76
+ if (xyz !== null)
77
+ operations.push(xyz);
78
+ }
79
+ return operations;
80
+ }
81
+ function readSites(index) {
82
+ const rows = loopWith(index, FRACT_X_TAGS);
83
+ if (rows === null)
84
+ return [];
85
+ const sites = [];
86
+ for (const row of rows)
87
+ sites.push(readSite(row));
88
+ return sites;
89
+ }
90
+ function readSite(row) {
91
+ const typeSymbol = rowTag(row, TYPE_SYMBOL_TAGS);
92
+ const label = rowTag(row, LABEL_TAGS) ?? typeSymbol;
93
+ if (label === null) {
94
+ throw new Error('An atom site of this CIF carries neither a label nor a type symbol.');
95
+ }
96
+ const occupancy = parseCifNumber(rowTag(row, OCCUPANCY_TAGS));
97
+ const disorderGroup = optionalRowTag(row, DISORDER_GROUP_TAGS);
98
+ const disorderAssembly = optionalRowTag(row, DISORDER_ASSEMBLY_TAGS);
99
+ const calcFlag = optionalRowTag(row, CALC_FLAG_TAGS);
100
+ return {
101
+ label,
102
+ element: elementOf(typeSymbol, label),
103
+ x: siteNumber(row, FRACT_X_TAGS, label),
104
+ y: siteNumber(row, FRACT_Y_TAGS, label),
105
+ z: siteNumber(row, FRACT_Z_TAGS, label),
106
+ occupancy: occupancy?.value ?? 1,
107
+ uiso: readUiso(row),
108
+ ...(disorderGroup === null ? {} : { disorderGroup }),
109
+ ...(disorderAssembly === null ? {} : { disorderAssembly }),
110
+ ...(calcFlag === null ? {} : { calcFlag }),
111
+ };
112
+ }
113
+ function siteNumber(row, aliases, label) {
114
+ const parsed = parseCifNumber(rowTag(row, aliases));
115
+ if (parsed === null) {
116
+ throw new Error(`Atom site "${label}" has no fractional coordinate on ${aliases[0] ?? ''}.`);
117
+ }
118
+ return parsed.value;
119
+ }
120
+ /**
121
+ * Read the isotropic displacement parameter, in Ų.
122
+ *
123
+ * A file that gives `_atom_site_B_iso_or_equiv` instead is converted with
124
+ * `U = B / 8π²`, which is the definition of the two quantities.
125
+ * @param row - the atom-site row.
126
+ * @returns U_iso, or `null` when the file gives neither.
127
+ */
128
+ function readUiso(row) {
129
+ const u = parseCifNumber(rowTag(row, U_ISO_TAGS));
130
+ if (u !== null)
131
+ return u.value;
132
+ const b = parseCifNumber(rowTag(row, B_ISO_TAGS));
133
+ return b === null ? null : b.value / (8 * Math.PI * Math.PI);
134
+ }
135
+ function readSource(index) {
136
+ const source = {};
137
+ const doi = scalarTag(index, ['_journal_paper_doi']);
138
+ if (doi !== null)
139
+ source.doi = doi;
140
+ const cod = scalarTag(index, ['_cod_database_code']);
141
+ if (cod !== null)
142
+ source.cod = cod;
143
+ const note = scalarTag(index, [
144
+ '_chemical_name_mineral',
145
+ '_chemical_name_common',
146
+ ]);
147
+ if (note !== null)
148
+ source.note = note;
149
+ return source;
150
+ }
151
+ const FRACT_X_TAGS = ['_atom_site_fract_x', '_atom_site.fract_x'];
152
+ const FRACT_Y_TAGS = ['_atom_site_fract_y', '_atom_site.fract_y'];
153
+ const FRACT_Z_TAGS = ['_atom_site_fract_z', '_atom_site.fract_z'];
154
+ const LABEL_TAGS = ['_atom_site_label', '_atom_site.label'];
155
+ const TYPE_SYMBOL_TAGS = [
156
+ '_atom_site_type_symbol',
157
+ '_atom_site.type_symbol',
158
+ ];
159
+ const OCCUPANCY_TAGS = [
160
+ '_atom_site_occupancy',
161
+ '_atom_site.occupancy',
162
+ ];
163
+ const U_ISO_TAGS = [
164
+ '_atom_site_u_iso_or_equiv',
165
+ '_atom_site.u_iso_or_equiv',
166
+ ];
167
+ const DISORDER_GROUP_TAGS = [
168
+ '_atom_site_disorder_group',
169
+ '_atom_site.disorder_group',
170
+ ];
171
+ const DISORDER_ASSEMBLY_TAGS = [
172
+ '_atom_site_disorder_assembly',
173
+ '_atom_site.disorder_assembly',
174
+ ];
175
+ const CALC_FLAG_TAGS = [
176
+ '_atom_site_calc_flag',
177
+ '_atom_site.calc_flag',
178
+ ];
179
+ const B_ISO_TAGS = [
180
+ '_atom_site_b_iso_or_equiv',
181
+ '_atom_site.b_iso_or_equiv',
182
+ ];
183
+ //# sourceMappingURL=read.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"read.js","sourceRoot":"","sources":["../../../../src/crystal/core/cif/read.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,CAAC;AAE7C,OAAO,EAAE,SAAS,EAAE,MAAM,cAAc,CAAC;AACzC,OAAO,EAAE,cAAc,EAAE,MAAM,aAAa,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YAAY,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,CAAU,CAAC;AAC3E,MAAM,YAAY,GAAG,CAAC,oBAAoB,EAAE,oBAAoB,CAAU,CAAC;AAC3E,MAAM,UAAU,GAAG,CAAC,kBAAkB,EAAE,kBAAkB,CAAU,CAAC;AACrE,MAAM,gBAAgB,GAAG;IACvB,wBAAwB;IACxB,wBAAwB;CAChB,CAAC;AACX,MAAM,cAAc,GAAG;IACrB,sBAAsB;IACtB,sBAAsB;CACd,CAAC;AACX,MAAM,UAAU,GAAG;IACjB,2BAA2B;IAC3B,2BAA2B;CACnB,CAAC;AACX,MAAM,mBAAmB,GAAG;IAC1B,2BAA2B;IAC3B,2BAA2B;CACnB,CAAC;AACX,MAAM,sBAAsB,GAAG;IAC7B,8BAA8B;IAC9B,8BAA8B;CACtB,CAAC;AACX,MAAM,cAAc,GAAG;IACrB,sBAAsB;IACtB,sBAAsB;CACd,CAAC;AACX,MAAM,UAAU,GAAG;IACjB,2BAA2B;IAC3B,2BAA2B;CACnB,CAAC"}
@@ -0,0 +1,17 @@
1
+ import type { CifIndex } from './tags.ts';
2
+ import type { CifGeometryBond, CifGeometryTorsion } from './types.ts';
3
+ /**
4
+ * Read the `_geom_bond` loop: the distances the authors reported.
5
+ * @param index - the folded CIF.
6
+ * @returns the bonds in file order, or `null` when the file has no such loop.
7
+ * A row whose labels or distance cannot be read is left out.
8
+ */
9
+ export declare function readGeometryBonds(index: CifIndex): CifGeometryBond[] | null;
10
+ /**
11
+ * Read the `_geom_torsion` loop: the torsion angles the authors reported.
12
+ * @param index - the folded CIF.
13
+ * @returns the torsions in file order, or `null` when the file has no such
14
+ * loop. A row whose labels or angle cannot be read is left out.
15
+ */
16
+ export declare function readGeometryTorsions(index: CifIndex): CifGeometryTorsion[] | null;
17
+ //# sourceMappingURL=readGeometry.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"readGeometry.d.ts","sourceRoot":"","sources":["../../../../src/crystal/core/cif/readGeometry.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,QAAQ,EAAe,MAAM,WAAW,CAAC;AAEvD,OAAO,KAAK,EAAE,eAAe,EAAE,kBAAkB,EAAE,MAAM,YAAY,CAAC;AAEtE;;;;;GAKG;AACH,wBAAgB,iBAAiB,CAAC,KAAK,EAAE,QAAQ,GAAG,eAAe,EAAE,GAAG,IAAI,CAkB3E;AAED;;;;;GAKG;AACH,wBAAgB,oBAAoB,CAClC,KAAK,EAAE,QAAQ,GACd,kBAAkB,EAAE,GAAG,IAAI,CAgC7B"}
@@ -0,0 +1,93 @@
1
+ import { parseCifNumber } from "./number.js";
2
+ import { loopWith, optionalRowTag, rowTag } from "./tags.js";
3
+ /**
4
+ * Read the `_geom_bond` loop: the distances the authors reported.
5
+ * @param index - the folded CIF.
6
+ * @returns the bonds in file order, or `null` when the file has no such loop.
7
+ * A row whose labels or distance cannot be read is left out.
8
+ */
9
+ export function readGeometryBonds(index) {
10
+ const rows = loopWith(index, BOND_LABEL_1);
11
+ if (rows === null)
12
+ return null;
13
+ const bonds = [];
14
+ for (const row of rows) {
15
+ const label1 = rowTag(row, BOND_LABEL_1);
16
+ const label2 = rowTag(row, BOND_LABEL_2);
17
+ const distance = parseCifNumber(rowTag(row, BOND_DISTANCE));
18
+ if (label1 === null || label2 === null || distance === null)
19
+ continue;
20
+ bonds.push({
21
+ label1,
22
+ label2,
23
+ distance,
24
+ ...symmetryCode(row, 'siteSymmetry1', BOND_SYMMETRY_1),
25
+ ...symmetryCode(row, 'siteSymmetry2', BOND_SYMMETRY_2),
26
+ });
27
+ }
28
+ return bonds;
29
+ }
30
+ /**
31
+ * Read the `_geom_torsion` loop: the torsion angles the authors reported.
32
+ * @param index - the folded CIF.
33
+ * @returns the torsions in file order, or `null` when the file has no such
34
+ * loop. A row whose labels or angle cannot be read is left out.
35
+ */
36
+ export function readGeometryTorsions(index) {
37
+ const rows = loopWith(index, torsionTags('atom_site_label_1'));
38
+ if (rows === null)
39
+ return null;
40
+ const torsions = [];
41
+ for (const row of rows) {
42
+ const label1 = rowTag(row, torsionTags('atom_site_label_1'));
43
+ const label2 = rowTag(row, torsionTags('atom_site_label_2'));
44
+ const label3 = rowTag(row, torsionTags('atom_site_label_3'));
45
+ const label4 = rowTag(row, torsionTags('atom_site_label_4'));
46
+ const angle = parseCifNumber(rowTag(row, TORSION_ANGLE));
47
+ if (label1 === null ||
48
+ label2 === null ||
49
+ label3 === null ||
50
+ label4 === null ||
51
+ angle === null) {
52
+ continue;
53
+ }
54
+ torsions.push({
55
+ label1,
56
+ label2,
57
+ label3,
58
+ label4,
59
+ angle,
60
+ ...symmetryCode(row, 'siteSymmetry1', torsionTags('site_symmetry_1')),
61
+ ...symmetryCode(row, 'siteSymmetry2', torsionTags('site_symmetry_2')),
62
+ ...symmetryCode(row, 'siteSymmetry3', torsionTags('site_symmetry_3')),
63
+ ...symmetryCode(row, 'siteSymmetry4', torsionTags('site_symmetry_4')),
64
+ });
65
+ }
66
+ return torsions;
67
+ }
68
+ function symmetryCode(row, key, aliases) {
69
+ const code = optionalRowTag(row, aliases);
70
+ return code === null ? {} : { [key]: code };
71
+ }
72
+ function torsionTags(column) {
73
+ return [`_geom_torsion_${column}`, `_geom_torsion.${column}`];
74
+ }
75
+ const BOND_LABEL_1 = [
76
+ '_geom_bond_atom_site_label_1',
77
+ '_geom_bond.atom_site_label_1',
78
+ ];
79
+ const BOND_LABEL_2 = [
80
+ '_geom_bond_atom_site_label_2',
81
+ '_geom_bond.atom_site_label_2',
82
+ ];
83
+ const BOND_DISTANCE = ['_geom_bond_distance', '_geom_bond.distance'];
84
+ const BOND_SYMMETRY_1 = [
85
+ '_geom_bond_site_symmetry_1',
86
+ '_geom_bond.site_symmetry_1',
87
+ ];
88
+ const BOND_SYMMETRY_2 = [
89
+ '_geom_bond_site_symmetry_2',
90
+ '_geom_bond.site_symmetry_2',
91
+ ];
92
+ const TORSION_ANGLE = ['_geom_torsion', '_geom_torsion.value'];
93
+ //# sourceMappingUR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1B,MAAM,IAAI,GAAG,cAAc,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC;IAC1C,OAAO,IAAI,KAAK,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAE,EAAE,CAAC,GAAG,CAAC,EAAE,IAAI,EAAwB,CAAC;AACrE,CAAC;AAED,SAAS,WAAW,CAAC,MAAc;IACjC,OAAO,CAAC,iBAAiB,MAAM,EAAE,EAAE,iBAAiB,MAAM,EAAE,CAAC,CAAC;AAChE,CAAC;AAED,MAAM,YAAY,GAAG;IACnB,8BAA8B;IAC9B,8BAA8B;CACtB,CAAC;AACX,MAAM,YAAY,GAAG;IACnB,8BAA8B;IAC9B,8BAA8B;CACtB,CAAC;AACX,MAAM,aAAa,GAAG,CAAC,qBAAqB,EAAE,qBAAqB,CAAU,CAAC;AAC9E,MAAM,eAAe,GAAG;IACtB,4BAA4B;IAC5B,4BAA4B;CACpB,CAAC;AACX,MAAM,eAAe,GAAG;IACtB,4BAA4B;IAC5B,4BAA4B;CACpB,CAAC;AACX,MAAM,aAAa,GAAG,CAAC,eAAe,EAAE,qBAAqB,CAAU,CAAC"}
@@ -0,0 +1,62 @@
1
+ import type { CifJson } from 'cif-to-json';
2
+ /** One `loop_` row, keyed on the lowercased tag of each column. */
3
+ export type CifRowIndex = ReadonlyMap<string, string>;
4
+ /** A parsed CIF, with every tag folded to lower case so lookups are case-blind. */
5
+ export interface CifIndex {
6
+ /** Every scalar tag of the block. */
7
+ readonly scalars: ReadonlyMap<string, string>;
8
+ /** Every `loop_` of the block, in file order. */
9
+ readonly loops: ReadonlyArray<readonly CifRowIndex[]>;
10
+ }
11
+ /**
12
+ * Fold a parsed CIF so every tag can be looked up whatever case it was written in.
13
+ *
14
+ * CIF tags are case-insensitive and real files disagree: COD writes
15
+ * `_symmetry_Int_Tables_number`, other producers write it all in lower case.
16
+ * `cif-to-json` stores the tag verbatim, so the folding has to happen here.
17
+ * @param parsed - the output of `cifParser`.
18
+ * @returns the folded index.
19
+ */
20
+ export declare function indexCif(parsed: CifJson): CifIndex;
21
+ /**
22
+ * Read a scalar tag, trying each alias in turn.
23
+ * @param index - the folded CIF.
24
+ * @param aliases - the tags to try, lowercased, most current first.
25
+ * @returns the trimmed value, or `null` when no alias carries one.
26
+ */
27
+ export declare function scalarTag(index: CifIndex, aliases: readonly string[]): string | null;
28
+ /**
29
+ * Find the loop that carries one of these columns.
30
+ *
31
+ * `cif-to-json` keys a loop on the longest common prefix of its column tags, so
32
+ * the key changes with the optional columns a file happened to write: the same
33
+ * operation list arrives as `_space_group_symop`, `_symmetry_equiv_pos` or the
34
+ * full tag. Searching the columns instead of the key is immune to that.
35
+ * @param index - the folded CIF.
36
+ * @param aliases - the column tags to look for, lowercased.
37
+ * @returns the loop's rows, or `null` when no loop carries any of them.
38
+ */
39
+ export declare function loopWith(index: CifIndex, aliases: readonly string[]): readonly CifRowIndex[] | null;
40
+ /**
41
+ * Read one cell of a loop row, trying each alias in turn.
42
+ * @param row - the row.
43
+ * @param aliases - the column tags to try, lowercased.
44
+ * @returns the trimmed value, or `null` when no alias carries one.
45
+ */
46
+ export declare function rowTag(row: CifRowIndex, aliases: readonly string[]): string | null;
47
+ /**
48
+ * Read one cell of a loop row that may be left unknown or inapplicable.
49
+ * @param row - the row.
50
+ * @param aliases - the column tags to try, lowercased.
51
+ * @returns the trimmed value, or `null` when it is absent, `.` or `?`.
52
+ */
53
+ export declare function optionalRowTag(row: CifRowIndex, aliases: readonly string[]): string | null;
54
+ /** The four tags a file may carry its symmetry operations under. */
55
+ export declare const SYMOP_TAGS: readonly ["_space_group_symop_operation_xyz", "_space_group_symop.operation_xyz", "_symmetry_equiv_pos_as_xyz", "_symmetry_equiv_pos.as_xyz"];
56
+ /** The two tags a file may carry its International Tables number under. */
57
+ export declare const IT_NUMBER_TAGS: readonly ["_space_group_it_number", "_symmetry_int_tables_number"];
58
+ /** The tags a file may carry its Hermann-Mauguin symbol under. */
59
+ export declare const HM_TAGS: readonly ["_space_group_name_h-m_alt", "_space_group_name_h-m_full", "_symmetry_space_group_name_h-m", "_cod_original_sg_symbol_h-m"];
60
+ /** The tags a file may carry its Hall symbol under. */
61
+ export declare const HALL_TAGS: readonly ["_space_group_name_hall", "_symmetry_space_group_name_hall"];
62
+ //# sourceMappingURL=tags.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.d.ts","sourceRoot":"","sources":["../../../../src/crystal/core/cif/tags.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,OAAO,EAAE,MAAM,aAAa,CAAC;AAE3C,mEAAmE;AACnE,MAAM,MAAM,WAAW,GAAG,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;AAEtD,mFAAmF;AACnF,MAAM,WAAW,QAAQ;IACvB,qCAAqC;IACrC,QAAQ,CAAC,OAAO,EAAE,WAAW,CAAC,MAAM,EAAE,MAAM,CAAC,CAAC;IAC9C,iDAAiD;IACjD,QAAQ,CAAC,KAAK,EAAE,aAAa,CAAC,SAAS,WAAW,EAAE,CAAC,CAAC;CACvD;AAED;;;;;;;;GAQG;AACH,wBAAgB,QAAQ,CAAC,MAAM,EAAE,OAAO,GAAG,QAAQ,CAmBlD;AAED;;;;;GAKG;AACH,wBAAgB,SAAS,CACvB,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,GAAG,IAAI,CAMf;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,QAAQ,CACtB,KAAK,EAAE,QAAQ,EACf,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,SAAS,WAAW,EAAE,GAAG,IAAI,CAS/B;AAED;;;;;GAKG;AACH,wBAAgB,MAAM,CACpB,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,GAAG,IAAI,CAMf;AAED;;;;;GAKG;AACH,wBAAgB,cAAc,CAC5B,GAAG,EAAE,WAAW,EAChB,OAAO,EAAE,SAAS,MAAM,EAAE,GACzB,MAAM,GAAG,IAAI,CAGf;AAED,oEAAoE;AACpE,eAAO,MAAM,UAAU,+IAKb,CAAC;AAEX,2EAA2E;AAC3E,eAAO,MAAM,cAAc,oEAGjB,CAAC;AAEX,kEAAkE;AAClE,eAAO,MAAM,OAAO,uIAKV,CAAC;AAEX,uDAAuD;AACvD,eAAO,MAAM,SAAS,wEAGZ,CAAC"}
@@ -0,0 +1,115 @@
1
+ /**
2
+ * Fold a parsed CIF so every tag can be looked up whatever case it was written in.
3
+ *
4
+ * CIF tags are case-insensitive and real files disagree: COD writes
5
+ * `_symmetry_Int_Tables_number`, other producers write it all in lower case.
6
+ * `cif-to-json` stores the tag verbatim, so the folding has to happen here.
7
+ * @param parsed - the output of `cifParser`.
8
+ * @returns the folded index.
9
+ */
10
+ export function indexCif(parsed) {
11
+ const scalars = new Map();
12
+ const loops = [];
13
+ for (const [tag, value] of Object.entries(parsed)) {
14
+ if (typeof value === 'string') {
15
+ scalars.set(tag.toLowerCase(), value);
16
+ continue;
17
+ }
18
+ const rows = [];
19
+ for (const source of value) {
20
+ const row = new Map();
21
+ for (const [column, cell] of Object.entries(source)) {
22
+ row.set(column.toLowerCase(), cell);
23
+ }
24
+ rows.push(row);
25
+ }
26
+ loops.push(rows);
27
+ }
28
+ return { scalars, loops };
29
+ }
30
+ /**
31
+ * Read a scalar tag, trying each alias in turn.
32
+ * @param index - the folded CIF.
33
+ * @param aliases - the tags to try, lowercased, most current first.
34
+ * @returns the trimmed value, or `null` when no alias carries one.
35
+ */
36
+ export function scalarTag(index, aliases) {
37
+ for (const alias of aliases) {
38
+ const value = index.scalars.get(alias);
39
+ if (value !== undefined && value.trim() !== '')
40
+ return value.trim();
41
+ }
42
+ return null;
43
+ }
44
+ /**
45
+ * Find the loop that carries one of these columns.
46
+ *
47
+ * `cif-to-json` keys a loop on the longest common prefix of its column tags, so
48
+ * the key changes with the optional columns a file happened to write: the same
49
+ * operation list arrives as `_space_group_symop`, `_symmetry_equiv_pos` or the
50
+ * full tag. Searching the columns instead of the key is immune to that.
51
+ * @param index - the folded CIF.
52
+ * @param aliases - the column tags to look for, lowercased.
53
+ * @returns the loop's rows, or `null` when no loop carries any of them.
54
+ */
55
+ export function loopWith(index, aliases) {
56
+ for (const rows of index.loops) {
57
+ const first = rows[0];
58
+ if (first === undefined)
59
+ continue;
60
+ for (const alias of aliases) {
61
+ if (first.has(alias))
62
+ return rows;
63
+ }
64
+ }
65
+ return null;
66
+ }
67
+ /**
68
+ * Read one cell of a loop row, trying each alias in turn.
69
+ * @param row - the row.
70
+ * @param aliases - the column tags to try, lowercased.
71
+ * @returns the trimmed value, or `null` when no alias carries one.
72
+ */
73
+ export function rowTag(row, aliases) {
74
+ for (const alias of aliases) {
75
+ const value = row.get(alias);
76
+ if (value !== undefined && value.trim() !== '')
77
+ return value.trim();
78
+ }
79
+ return null;
80
+ }
81
+ /**
82
+ * Read one cell of a loop row that may be left unknown or inapplicable.
83
+ * @param row - the row.
84
+ * @param aliases - the column tags to try, lowercased.
85
+ * @returns the trimmed value, or `null` when it is absent, `.` or `?`.
86
+ */
87
+ export function optionalRowTag(row, aliases) {
88
+ const value = rowTag(row, aliases);
89
+ return value === null || ['.', '?'].includes(value) ? null : value;
90
+ }
91
+ /** The four tags a file may carry its symmetry operations under. */
92
+ export const SYMOP_TAGS = [
93
+ '_space_group_symop_operation_xyz',
94
+ '_space_group_symop.operation_xyz',
95
+ '_symmetry_equiv_pos_as_xyz',
96
+ '_symmetry_equiv_pos.as_xyz',
97
+ ];
98
+ /** The two tags a file may carry its International Tables number under. */
99
+ export const IT_NUMBER_TAGS = [
100
+ '_space_group_it_number',
101
+ '_symmetry_int_tables_number',
102
+ ];
103
+ /** The tags a file may carry its Hermann-Mauguin symbol under. */
104
+ export const HM_TAGS = [
105
+ '_space_group_name_h-m_alt',
106
+ '_space_group_name_h-m_full',
107
+ '_symmetry_space_group_name_h-m',
108
+ '_cod_original_sg_symbol_h-m',
109
+ ];
110
+ /** The tags a file may carry its Hall symbol under. */
111
+ export const HALL_TAGS = [
112
+ '_space_group_name_hall',
113
+ '_symmetry_space_group_name_hall',
114
+ ];
115
+ //# sourceMappingURL=tags.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"tags.js","sourceRoot":"","sources":["../../../../src/crystal/core/cif/tags.ts"],"names":[],"mappings":"AAaA;;;;;;;;GAQG;AACH,MAAM,UAAU,QAAQ,CAAC,MAAe;IACtC,MAAM,OAAO,GAAG,IAAI,GAAG,EAAkB,CAAC;IAC1C,MAAM,KAAK,GAAkC,EAAE,CAAC;IAChD,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;QAClD,IAAI,OAAO,KAAK,KAAK,QAAQ,EAAE,CAAC;YAC9B,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,WAAW,EAAE,EAAE,KAAK,CAAC,CAAC;YACtC,SAAS;QACX,CAAC;QACD,MAAM,IAAI,GAAkB,EAAE,CAAC;QAC/B,KAAK,MAAM,MAAM,IAAI,KAAK,EAAE,CAAC;YAC3B,MAAM,GAAG,GAAG,IAAI,GAAG,EAAkB,CAAC;YACtC,KAAK,MAAM,CAAC,MAAM,EAAE,IAAI,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,MAAM,CAAC,EAAE,CAAC;gBACpD,GAAG,CAAC,GAAG,CAAC,MAAM,CAAC,WAAW,EAAE,EAAE,IAAI,CAAC,CAAC;YACtC,CAAC;YACD,IAAI,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;QACjB,CAAC;QACD,KAAK,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC;IACnB,CAAC;IACD,OAAO,EAAE,OAAO,EAAE,KAAK,EAAE,CAAC;AAC5B,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CACvB,KAAe,EACf,OAA0B;IAE1B,KAAK,MAAM,KAAK,IAAI,OAAO,EAAE,CAAC;QAC5B,M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AAI,CAAC,CAAC,CAAC,KAAK,CAAC;AACrE,CAAC;AAED,oEAAoE;AACpE,MAAM,CAAC,MAAM,UAAU,GAAG;IACxB,kCAAkC;IAClC,kCAAkC;IAClC,4BAA4B;IAC5B,4BAA4B;CACpB,CAAC;AAEX,2EAA2E;AAC3E,MAAM,CAAC,MAAM,cAAc,GAAG;IAC5B,wBAAwB;IACxB,6BAA6B;CACrB,CAAC;AAEX,kEAAkE;AAClE,MAAM,CAAC,MAAM,OAAO,GAAG;IACrB,2BAA2B;IAC3B,4BAA4B;IAC5B,gCAAgC;IAChC,6BAA6B;CACrB,CAAC;AAEX,uDAAuD;AACvD,MAAM,CAAC,MAAM,SAAS,GAAG;IACvB,wBAAwB;IACxB,iCAAiC;CACzB,CAAC"}
@@ -0,0 +1,158 @@
1
+ /** A number read from a CIF, with the standard uncertainty the file wrote it with. */
2
+ export interface CifNumber {
3
+ /** The value, with the parenthesised standard uncertainty removed. */
4
+ readonly value: number;
5
+ /**
6
+ * The standard uncertainty, in the unit of `value`: `0.30475(3)` gives `0.00003`.
7
+ * `null` when the token carried none.
8
+ */
9
+ readonly su: number | null;
10
+ /** The token exactly as the file wrote it, e.g. `0.30475(3)`. */
11
+ readonly raw: string;
12
+ }
13
+ /** The unit cell: three edges in ångström, three angles in degrees. */
14
+ export interface CrystalCell {
15
+ readonly a: number;
16
+ readonly b: number;
17
+ readonly c: number;
18
+ readonly alpha: number;
19
+ readonly beta: number;
20
+ readonly gamma: number;
21
+ }
22
+ /** The space group as the file names it, plus the number when the file gives one. */
23
+ export interface CrystalSpaceGroup {
24
+ /** `_space_group_IT_number`, else `_symmetry_Int_Tables_number`. 1 to 230. */
25
+ readonly number: number | null;
26
+ /** The Hermann-Mauguin symbol, spaced as the file wrote it, e.g. `F m -3 m`. */
27
+ readonly hm: string | null;
28
+ /** The Hall symbol, e.g. `-F 4 2 3`. */
29
+ readonly hall: string | null;
30
+ }
31
+ /** One entry of the `_atom_site` loop: an atom of the asymmetric unit. */
32
+ export interface CrystalSite {
33
+ /** `_atom_site_label`, e.g. `Na1`. Unique within the file, and not an element. */
34
+ readonly label: string;
35
+ /**
36
+ * The chemical symbol, from `_atom_site_type_symbol` with any charge removed,
37
+ * else from the letters that open `label`.
38
+ */
39
+ readonly element: string;
40
+ /** Fractional coordinate along **a**. */
41
+ readonly x: number;
42
+ /** Fractional coordinate along **b**. */
43
+ readonly y: number;
44
+ /** Fractional coordinate along **c**. */
45
+ readonly z: number;
46
+ /** `_atom_site_occupancy`, 1 when the file gives none. */
47
+ readonly occupancy: number;
48
+ /** `_atom_site_U_iso_or_equiv` in Ų, or `null` when the file gives none. */
49
+ readonly uiso: number | null;
50
+ /**
51
+ * `_atom_site_disorder_group`, as written: `1`, `2`, `-1`. Absent on an atom
52
+ * the file leaves in no group (`.`).
53
+ * @default undefined
54
+ */
55
+ readonly disorderGroup?: string;
56
+ /**
57
+ * `_atom_site_disorder_assembly`: which disorder the group is a part of,
58
+ * e.g. `A`. Absent when the file names none.
59
+ * @default undefined
60
+ */
61
+ readonly disorderAssembly?: string;
62
+ /**
63
+ * `_atom_site_calc_flag`: `d` refined from the diffraction data, `calc` or
64
+ * `c` placed geometrically, `dum` a dummy atom.
65
+ * @default undefined
66
+ */
67
+ readonly calcFlag?: string;
68
+ }
69
+ /** Where the structure came from, as far as the file says. */
70
+ export interface CrystalSource {
71
+ /** `_journal_paper_doi`. */
72
+ readonly doi?: string;
73
+ /** `_cod_database_code`, the Crystallography Open Database entry. */
74
+ readonly cod?: string;
75
+ /** `_chemical_name_mineral`, else `_chemical_name_common`, e.g. `Halite`. */
76
+ readonly note?: string;
77
+ }
78
+ /** One row of the `_geom_bond` loop: a distance the authors reported. */
79
+ export interface CifGeometryBond {
80
+ /** `_geom_bond_atom_site_label_1`. */
81
+ readonly label1: string;
82
+ /** `_geom_bond_atom_site_label_2`. */
83
+ readonly label2: string;
84
+ /** `_geom_bond_distance`, in ångström, with its standard uncertainty. */
85
+ readonly distance: CifNumber;
86
+ /**
87
+ * `_geom_bond_site_symmetry_1`, e.g. `2_655`. Absent when the atom is the
88
+ * one the file lists (`.`).
89
+ * @default undefined
90
+ */
91
+ readonly siteSymmetry1?: string;
92
+ /**
93
+ * `_geom_bond_site_symmetry_2`, e.g. `2_655`: the operation and the cell
94
+ * translation that carry the second atom to the bonded copy.
95
+ * @default undefined
96
+ */
97
+ readonly siteSymmetry2?: string;
98
+ }
99
+ /** One row of the `_geom_torsion` loop: a torsion angle the authors reported. */
100
+ export interface CifGeometryTorsion {
101
+ /** `_geom_torsion_atom_site_label_1`. */
102
+ readonly label1: string;
103
+ /** `_geom_torsion_atom_site_label_2`. */
104
+ readonly label2: string;
105
+ /** `_geom_torsion_atom_site_label_3`. */
106
+ readonly label3: string;
107
+ /** `_geom_torsion_atom_site_label_4`. */
108
+ readonly label4: string;
109
+ /** `_geom_torsion`, in degrees, with its standard uncertainty. */
110
+ readonly angle: CifNumber;
111
+ /**
112
+ * `_geom_torsion_site_symmetry_1`.
113
+ * @default undefined
114
+ */
115
+ readonly siteSymmetry1?: string;
116
+ /**
117
+ * `_geom_torsion_site_symmetry_2`.
118
+ * @default undefined
119
+ */
120
+ readonly siteSymmetry2?: string;
121
+ /**
122
+ * `_geom_torsion_site_symmetry_3`.
123
+ * @default undefined
124
+ */
125
+ readonly siteSymmetry3?: string;
126
+ /**
127
+ * `_geom_torsion_site_symmetry_4`.
128
+ * @default undefined
129
+ */
130
+ readonly siteSymmetry4?: string;
131
+ }
132
+ /** One crystal structure: the cell, the space group and the asymmetric unit. */
133
+ export interface CrystalStructure {
134
+ /** The text after `data_`, e.g. `9008671`. */
135
+ readonly name: string;
136
+ /** `_chemical_formula_sum`, else `_chemical_formula_moiety`; `''` when absent. */
137
+ readonly formula: string;
138
+ readonly cell: CrystalCell;
139
+ readonly spaceGroup: CrystalSpaceGroup;
140
+ /** The operations the file carries, verbatim and in file order, when it carries any. */
141
+ readonly symopsXyz: readonly string[];
142
+ /** The asymmetric unit, in file order. */
143
+ readonly sites: readonly CrystalSite[];
144
+ readonly source: CrystalSource;
145
+ /**
146
+ * The bond distances the authors reported, in file order. Absent when the
147
+ * file carries no `_geom_bond` loop.
148
+ * @default undefined
149
+ */
150
+ readonly geometryBonds?: readonly CifGeometryBond[];
151
+ /**
152
+ * The torsion angles the authors reported, in file order. Absent when the
153
+ * file carries no `_geom_torsion` loop.
154
+ * @default undefined
155
+ */
156
+ readonly geometryTorsions?: readonly CifGeometryTorsion[];
157
+ }
158
+ //# sourceMappingURL=types.d.ts.map