symcrys 0.10.1 → 0.12.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 (248) hide show
  1. package/README.md +6 -6
  2. package/dist/cell.d.ts +19 -16
  3. package/dist/cell.d.ts.map +1 -1
  4. package/dist/cell.js +63 -35
  5. package/dist/cell.js.map +1 -1
  6. package/dist/checks.d.ts +29 -0
  7. package/dist/checks.d.ts.map +1 -0
  8. package/dist/checks.js +79 -0
  9. package/dist/checks.js.map +1 -0
  10. package/dist/closure.d.ts +43 -0
  11. package/dist/closure.d.ts.map +1 -0
  12. package/dist/closure.js +201 -0
  13. package/dist/closure.js.map +1 -0
  14. package/dist/coordinates.d.ts +143 -0
  15. package/dist/coordinates.d.ts.map +1 -0
  16. package/dist/coordinates.js +198 -0
  17. package/dist/coordinates.js.map +1 -0
  18. package/dist/crystalClasses.d.ts +170 -117
  19. package/dist/crystalClasses.d.ts.map +1 -1
  20. package/dist/crystalClasses.js +190 -121
  21. package/dist/crystalClasses.js.map +1 -1
  22. package/dist/freeze.d.ts +7 -0
  23. package/dist/freeze.d.ts.map +1 -0
  24. package/dist/freeze.js +15 -0
  25. package/dist/freeze.js.map +1 -0
  26. package/dist/index.d.ts +13 -10
  27. package/dist/index.d.ts.map +1 -1
  28. package/dist/index.js +5 -3
  29. package/dist/index.js.map +1 -1
  30. package/dist/indices.d.ts +30 -20
  31. package/dist/indices.d.ts.map +1 -1
  32. package/dist/indices.js +101 -31
  33. package/dist/indices.js.map +1 -1
  34. package/dist/lattice.d.ts +15 -1
  35. package/dist/lattice.d.ts.map +1 -1
  36. package/dist/lattice.js +30 -1
  37. package/dist/lattice.js.map +1 -1
  38. package/dist/linalg.d.ts +2 -2
  39. package/dist/linalg.d.ts.map +1 -1
  40. package/dist/linalg.js +3 -3
  41. package/dist/linalg.js.map +1 -1
  42. package/dist/magnetic.d.ts +14 -10
  43. package/dist/magnetic.d.ts.map +1 -1
  44. package/dist/magnetic.js +10 -6
  45. package/dist/magnetic.js.map +1 -1
  46. package/dist/notation.d.ts +16 -0
  47. package/dist/notation.d.ts.map +1 -0
  48. package/dist/notation.js +66 -0
  49. package/dist/notation.js.map +1 -0
  50. package/dist/operations.d.ts +40 -26
  51. package/dist/operations.d.ts.map +1 -1
  52. package/dist/operations.js +48 -60
  53. package/dist/operations.js.map +1 -1
  54. package/dist/plane.d.ts +297 -80
  55. package/dist/plane.d.ts.map +1 -1
  56. package/dist/plane.js +289 -94
  57. package/dist/plane.js.map +1 -1
  58. package/dist/pointGroups/crystalForms.d.ts +6 -21
  59. package/dist/pointGroups/crystalForms.d.ts.map +1 -1
  60. package/dist/pointGroups/crystalForms.js +9 -16
  61. package/dist/pointGroups/crystalForms.js.map +1 -1
  62. package/dist/pointGroups/crystalFormsData.d.ts +4 -1
  63. package/dist/pointGroups/crystalFormsData.d.ts.map +1 -1
  64. package/dist/pointGroups/crystalFormsData.js +64 -1
  65. package/dist/pointGroups/crystalFormsData.js.map +1 -1
  66. package/dist/pointGroups/elements.d.ts +19 -17
  67. package/dist/pointGroups/elements.d.ts.map +1 -1
  68. package/dist/pointGroups/elements.js +65 -83
  69. package/dist/pointGroups/elements.js.map +1 -1
  70. package/dist/pointGroups/identify.d.ts +10 -18
  71. package/dist/pointGroups/identify.d.ts.map +1 -1
  72. package/dist/pointGroups/identify.js +27 -79
  73. package/dist/pointGroups/identify.js.map +1 -1
  74. package/dist/pointGroups/itaOrder.d.ts +15 -14
  75. package/dist/pointGroups/itaOrder.d.ts.map +1 -1
  76. package/dist/pointGroups/itaOrder.js +116 -94
  77. package/dist/pointGroups/itaOrder.js.map +1 -1
  78. package/dist/pointGroups/itcData.d.ts +96 -0
  79. package/dist/pointGroups/itcData.d.ts.map +1 -0
  80. package/dist/pointGroups/itcData.js +336 -0
  81. package/dist/pointGroups/itcData.js.map +1 -0
  82. package/dist/pointGroups/itcMagneticData.d.ts +55 -0
  83. package/dist/pointGroups/itcMagneticData.d.ts.map +1 -0
  84. package/dist/pointGroups/itcMagneticData.js +172 -0
  85. package/dist/pointGroups/itcMagneticData.js.map +1 -0
  86. package/dist/pointGroups/keys.d.ts +32 -0
  87. package/dist/pointGroups/keys.d.ts.map +1 -0
  88. package/dist/pointGroups/keys.js +120 -0
  89. package/dist/pointGroups/keys.js.map +1 -0
  90. package/dist/pointGroups/magneticSymbols.d.ts +6 -5
  91. package/dist/pointGroups/magneticSymbols.d.ts.map +1 -1
  92. package/dist/pointGroups/magneticSymbols.js +15 -12
  93. package/dist/pointGroups/magneticSymbols.js.map +1 -1
  94. package/dist/pointGroups/orbits.d.ts +23 -42
  95. package/dist/pointGroups/orbits.d.ts.map +1 -1
  96. package/dist/pointGroups/orbits.js +20 -62
  97. package/dist/pointGroups/orbits.js.map +1 -1
  98. package/dist/pointGroups/pointGroups.d.ts +145 -68
  99. package/dist/pointGroups/pointGroups.d.ts.map +1 -1
  100. package/dist/pointGroups/pointGroups.js +455 -243
  101. package/dist/pointGroups/pointGroups.js.map +1 -1
  102. package/dist/pointGroups/properties.d.ts +21 -22
  103. package/dist/pointGroups/properties.d.ts.map +1 -1
  104. package/dist/pointGroups/properties.js +40 -37
  105. package/dist/pointGroups/properties.js.map +1 -1
  106. package/dist/pointGroups/seitzData.d.ts +26 -0
  107. package/dist/pointGroups/seitzData.d.ts.map +1 -0
  108. package/dist/pointGroups/seitzData.js +130 -0
  109. package/dist/pointGroups/seitzData.js.map +1 -0
  110. package/dist/pointGroups/shubnikovData.d.ts +11 -0
  111. package/dist/pointGroups/shubnikovData.d.ts.map +1 -0
  112. package/dist/pointGroups/shubnikovData.js +101 -0
  113. package/dist/pointGroups/shubnikovData.js.map +1 -0
  114. package/dist/pointGroups/wyckoff.d.ts +70 -40
  115. package/dist/pointGroups/wyckoff.d.ts.map +1 -1
  116. package/dist/pointGroups/wyckoff.js +98 -91
  117. package/dist/pointGroups/wyckoff.js.map +1 -1
  118. package/dist/pointGroups/wyckoffData.d.ts +7 -4
  119. package/dist/pointGroups/wyckoffData.d.ts.map +1 -1
  120. package/dist/pointGroups/wyckoffData.js +789 -168
  121. package/dist/pointGroups/wyckoffData.js.map +1 -1
  122. package/dist/siteSymmetry.d.ts +8 -16
  123. package/dist/siteSymmetry.d.ts.map +1 -1
  124. package/dist/siteSymmetry.js +34 -24
  125. package/dist/siteSymmetry.js.map +1 -1
  126. package/dist/spaceGroups/affine.d.ts.map +1 -1
  127. package/dist/spaceGroups/affine.js +3 -2
  128. package/dist/spaceGroups/affine.js.map +1 -1
  129. package/dist/spaceGroups/cell.d.ts +43 -31
  130. package/dist/spaceGroups/cell.d.ts.map +1 -1
  131. package/dist/spaceGroups/cell.js +173 -85
  132. package/dist/spaceGroups/cell.js.map +1 -1
  133. package/dist/spaceGroups/describe.d.ts +13 -10
  134. package/dist/spaceGroups/describe.d.ts.map +1 -1
  135. package/dist/spaceGroups/describe.js +11 -10
  136. package/dist/spaceGroups/describe.js.map +1 -1
  137. package/dist/spaceGroups/planeGroupData.d.ts +3 -1
  138. package/dist/spaceGroups/planeGroupData.d.ts.map +1 -1
  139. package/dist/spaceGroups/planeGroupData.js +25 -8
  140. package/dist/spaceGroups/planeGroupData.js.map +1 -1
  141. package/dist/spaceGroups/planeGroups.d.ts.map +1 -1
  142. package/dist/spaceGroups/planeGroups.js +2 -1
  143. package/dist/spaceGroups/planeGroups.js.map +1 -1
  144. package/dist/spaceGroups/planeLattice.d.ts +78 -0
  145. package/dist/spaceGroups/planeLattice.d.ts.map +1 -0
  146. package/dist/spaceGroups/planeLattice.js +143 -0
  147. package/dist/spaceGroups/planeLattice.js.map +1 -0
  148. package/dist/spaceGroups/planePointGroups.d.ts +6 -2
  149. package/dist/spaceGroups/planePointGroups.d.ts.map +1 -1
  150. package/dist/spaceGroups/planePointGroups.js +14 -2
  151. package/dist/spaceGroups/planePointGroups.js.map +1 -1
  152. package/dist/spaceGroups/positions.d.ts +48 -19
  153. package/dist/spaceGroups/positions.d.ts.map +1 -1
  154. package/dist/spaceGroups/positions.js +166 -67
  155. package/dist/spaceGroups/positions.js.map +1 -1
  156. package/dist/spaceGroups/rational.d.ts +18 -0
  157. package/dist/spaceGroups/rational.d.ts.map +1 -1
  158. package/dist/spaceGroups/rational.js +58 -0
  159. package/dist/spaceGroups/rational.js.map +1 -1
  160. package/dist/tensors/propertyTable.d.ts +3 -1
  161. package/dist/tensors/propertyTable.d.ts.map +1 -1
  162. package/dist/tensors/propertyTable.js +17 -10
  163. package/dist/tensors/propertyTable.js.map +1 -1
  164. package/dist/tensors/rowEchelon.d.ts +3 -3
  165. package/dist/tensors/rowEchelon.d.ts.map +1 -1
  166. package/dist/tensors/rowEchelon.js +4 -4
  167. package/dist/tensors/rowEchelon.js.map +1 -1
  168. package/dist/tensors/tensorForm.d.ts +75 -34
  169. package/dist/tensors/tensorForm.d.ts.map +1 -1
  170. package/dist/tensors/tensorForm.js +171 -67
  171. package/dist/tensors/tensorForm.js.map +1 -1
  172. package/dist/tensors/tensorProperties.d.ts +10 -9
  173. package/dist/tensors/tensorProperties.d.ts.map +1 -1
  174. package/dist/tensors/tensorProperties.js +22 -12
  175. package/dist/tensors/tensorProperties.js.map +1 -1
  176. package/dist/tensors/voigt.d.ts +56 -0
  177. package/dist/tensors/voigt.d.ts.map +1 -0
  178. package/dist/tensors/voigt.js +188 -0
  179. package/dist/tensors/voigt.js.map +1 -0
  180. package/dist/tolerances.d.ts +56 -1
  181. package/dist/tolerances.d.ts.map +1 -1
  182. package/dist/tolerances.js +51 -1
  183. package/dist/tolerances.js.map +1 -1
  184. package/dist/version.d.ts +1 -1
  185. package/dist/version.js +1 -1
  186. package/package.json +1 -1
  187. package/src/cell.ts +78 -51
  188. package/src/checks.ts +84 -0
  189. package/src/closure.ts +214 -0
  190. package/src/coordinates.ts +370 -0
  191. package/src/crystalClasses.ts +271 -157
  192. package/src/freeze.ts +14 -0
  193. package/src/index.ts +33 -12
  194. package/src/indices.ts +102 -42
  195. package/src/lattice.ts +41 -1
  196. package/src/linalg.ts +3 -3
  197. package/src/magnetic.ts +24 -11
  198. package/src/notation.ts +73 -0
  199. package/src/operations.ts +78 -71
  200. package/src/plane.ts +531 -151
  201. package/src/pointGroups/crystalForms.ts +11 -44
  202. package/src/pointGroups/crystalFormsData.ts +66 -1
  203. package/src/pointGroups/elements.ts +82 -92
  204. package/src/pointGroups/identify.ts +38 -97
  205. package/src/pointGroups/itaOrder.ts +117 -101
  206. package/src/pointGroups/itcData.ts +404 -0
  207. package/src/pointGroups/itcMagneticData.ts +206 -0
  208. package/src/pointGroups/keys.ts +144 -0
  209. package/src/pointGroups/magneticSymbols.ts +18 -17
  210. package/src/pointGroups/orbits.ts +41 -89
  211. package/src/pointGroups/pointGroups.ts +593 -298
  212. package/src/pointGroups/properties.ts +44 -40
  213. package/src/pointGroups/seitzData.ts +147 -0
  214. package/src/pointGroups/shubnikovData.ts +103 -0
  215. package/src/pointGroups/wyckoff.ts +137 -112
  216. package/src/pointGroups/wyckoffData.ts +793 -170
  217. package/src/siteSymmetry.ts +43 -40
  218. package/src/spaceGroups/affine.ts +3 -2
  219. package/src/spaceGroups/cell.ts +227 -116
  220. package/src/spaceGroups/describe.ts +23 -19
  221. package/src/spaceGroups/planeGroupData.ts +28 -9
  222. package/src/spaceGroups/planeGroups.ts +2 -1
  223. package/src/spaceGroups/planeLattice.ts +208 -0
  224. package/src/spaceGroups/planePointGroups.ts +23 -3
  225. package/src/spaceGroups/positions.ts +202 -78
  226. package/src/spaceGroups/rational.ts +59 -0
  227. package/src/tensors/propertyTable.ts +26 -14
  228. package/src/tensors/rowEchelon.ts +4 -3
  229. package/src/tensors/tensorForm.ts +258 -88
  230. package/src/tensors/tensorProperties.ts +34 -14
  231. package/src/tensors/voigt.ts +268 -0
  232. package/src/tolerances.ts +66 -1
  233. package/src/version.ts +1 -1
  234. package/dist/pointGroups/data.d.ts +0 -75
  235. package/dist/pointGroups/data.d.ts.map +0 -1
  236. package/dist/pointGroups/data.js +0 -212
  237. package/dist/pointGroups/data.js.map +0 -1
  238. package/dist/pointGroups/magneticData.d.ts +0 -66
  239. package/dist/pointGroups/magneticData.d.ts.map +0 -1
  240. package/dist/pointGroups/magneticData.js +0 -184
  241. package/dist/pointGroups/magneticData.js.map +0 -1
  242. package/dist/spaceGroups/snap.d.ts +0 -20
  243. package/dist/spaceGroups/snap.d.ts.map +0 -1
  244. package/dist/spaceGroups/snap.js +0 -103
  245. package/dist/spaceGroups/snap.js.map +0 -1
  246. package/src/pointGroups/data.ts +0 -305
  247. package/src/pointGroups/magneticData.ts +0 -328
  248. package/src/spaceGroups/snap.ts +0 -121
@@ -1,21 +1,26 @@
1
1
  /**
2
- * Wyckoff positions of the crystal classes for directions (face normals), in the ITC convention:
3
- * ITA's letters, multiplicities and oriented site-symmetry symbols, a representative face, and the
2
+ * Wyckoff positions of the crystal classes for directions (face normals), as ITA gives them:
3
+ * ITA's letters, multiplicities, oriented site-symmetry symbols, coordinates and faces as printed, and the
4
4
  * Wyckoff position of any direction (docs/conventions.md, "Site symmetry and Wyckoff positions").
5
5
  */
6
6
 
7
+ import { checkOptions, pick, SETTING_KEYS, shown, TOLERANCE_KEYS } from '../checks.js';
7
8
  import { apply, inverse, transpose, type Mat3, type Vec3 } from '../linalg.js';
8
- import { crystalFamily, latticeBasis } from '../lattice.js';
9
- import { POINT_GROUP_DATA } from './data.js';
9
+ import { crystalFamily } from '../lattice.js';
10
+ import { substituteMillerIndices } from '../indices.js';
11
+ import { itcBasis, itcClass, itcSetting as itcClassSetting } from './itcData.js';
10
12
  import {
13
+ settingIndexOf,
11
14
  isMagneticPointGroupKey,
12
15
  isPointGroupKey,
13
16
  operations,
14
17
  settings,
18
+ type MagneticPointGroupKey,
15
19
  type PointGroupKey,
16
20
  type SettingOptions,
17
21
  } from './pointGroups.js';
18
- import { siteSymmetry, siteTolerance, type SiteSymmetryOptions } from '../siteSymmetry.js';
22
+ import { siteSymmetryOf, siteTolerance, type SiteSymmetry } from '../siteSymmetry.js';
23
+ import type { ToleranceOptions } from '../tolerances.js';
19
24
  import { ITA_WYCKOFF, type WyckoffRow } from './wyckoffData.js';
20
25
 
21
26
  /** A face (hkl): three Miller indices in the conventional basis (for hexagonal axes without i = −(h + k)). */
@@ -29,50 +34,45 @@ export interface WyckoffPosition {
29
34
  readonly multiplicity: number;
30
35
  /** Oriented site-symmetry symbol as ITA prints it, e.g. `..m`, `4m.m`, `1`. */
31
36
  readonly siteSymmetry: string;
32
- /** ITA's representative point as printed, e.g. `x,x,z` (a leading `-` is an overbar). */
33
- readonly coordinates: string;
37
+ /**
38
+ * ITA's coordinate triplets of the position as printed, in printed order, the first being the
39
+ * representative point, e.g. `['x,x,z', '-x,-x,z', …]` (a leading `-` is an overbar); one per
40
+ * equivalent direction, as in `symcrys/plane`.
41
+ */
42
+ readonly coordinates: readonly string[];
34
43
  /**
35
44
  * ITA's representative face as printed, components separated by commas, e.g. `h,h,l`, or
36
- * `h,h,-2h,l` (Bravais–Miller indices) for hexagonal axes.
45
+ * `h,h,-2h,l` (Bravais–Miller indices) for hexagonal axes. `millerIndices(printed, { h, k, l })` gives
46
+ * a face with numbers, `faceNormal(basis, hkl)` its normal in a cell.
37
47
  */
38
48
  readonly millerIndices: string;
39
- /** A representative face with numbers: `millerIndices` with h = 3, k = 2, l = 1. */
40
- readonly representative: {
41
- /** The Miller indices (hkl) of the face. */
42
- readonly hkl: Hkl;
43
- /**
44
- * Its face normal, a Cartesian unit vector. Monoclinic and triclinic: the normal for a, b, c along
45
- * x, y, z (no cell angles), exact for the unique axis only, but with the correct site symmetry.
46
- */
47
- readonly cartesian: Vec3;
48
- };
49
- /** Indices into `operations` (same setting, ITC convention) of the site symmetry of the representative. */
49
+ /**
50
+ * Indices into `operations` (same setting) of the site symmetry of the position: of the operations
51
+ * that fix its first printed face for values of h, k, l that keep the face in the position.
52
+ */
50
53
  readonly siteSymmetryOperations: readonly number[];
51
54
  }
52
55
 
53
- /** Convention and setting (`SettingOptions`) and the tolerance of `siteSymmetry` (`SiteSymmetryOptions`). */
54
- export type WyckoffOptions = SettingOptions & SiteSymmetryOptions;
55
-
56
56
  /** The values substituted into ITA's Miller indices for the numeric representative. */
57
57
  export const REPRESENTATIVE_VALUES: Readonly<Record<'h' | 'k' | 'l', number>> = { h: 3, k: 2, l: 1 };
58
58
 
59
- /** One printed index (`h`, `-2h`, `0`, `1`) as a number. */
60
- function index(component: string, values: Readonly<Record<'h' | 'k' | 'l', number>>): number {
61
- const m = /^(-?)(\d*)([hkil]?)$/.exec(component);
62
- if (!m || (m[2] === '' && m[3] === '')) throw new Error(`Unreadable Miller index: ${component}`);
63
- const sign = m[1] ? -1 : 1;
64
- const factor = m[2] === '' ? 1 : Number(m[2]);
65
- if (m[3] === '') return sign * factor;
66
- if (m[3] === 'i') return sign * factor * -(values.h + values.k);
67
- return sign * factor * values[m[3] as 'h' | 'k' | 'l'];
59
+ /**
60
+ * The values for rhombohedral axes: h = 5, k = 2, l = 1. With 3, 2, 1 the face (h,k,l) would lie on
61
+ * the limiting form (h,k,2k-h) that ITA prints there (Table 3.2.3.2, 32, 3m and -3m with rhombohedral
62
+ * axes, pp. 755–759): (321) is (116) in hexagonal axes. (521), (318) in hexagonal axes, lies on no
63
+ * printed limiting form, and every printed face with these values is in lowest terms ((5,2,-7),
64
+ * (5,2,-1), (5,5,1)); h = 4 would give (4,2,-6) and (4,2,0).
65
+ */
66
+ export const RHOMBOHEDRAL_VALUES: Readonly<Record<'h' | 'k' | 'l', number>> = { h: 5, k: 2, l: 1 };
67
+
68
+ /** The values of h, k, l for the representative faces of a setting. */
69
+ export function representativeValues(key: PointGroupKey, setting: number): Readonly<Record<'h' | 'k' | 'l', number>> {
70
+ return itcClassSetting(key, setting).axes === 'rhombohedral' ? RHOMBOHEDRAL_VALUES : REPRESENTATIVE_VALUES;
68
71
  }
69
72
 
70
73
  /** Printed Miller indices (three, or four for hexagonal axes) as three numbers, with the given values of h, k, l. */
71
74
  export function numericHkl(miller: string, values = REPRESENTATIVE_VALUES): Hkl {
72
- const parts = miller.split(',').map((c) => index(c, values));
73
- if (parts.length === 3) return [parts[0], parts[1], parts[2]];
74
- if (parts.length === 4 && parts[2] === -(parts[0] + parts[1])) return [parts[0], parts[1], parts[3]];
75
- throw new Error(`Unreadable Miller indices: ${miller}`);
75
+ return substituteMillerIndices(miller, values, (m) => new Error(m));
76
76
  }
77
77
 
78
78
  export const IDENTITY: Mat3 = [
@@ -121,45 +121,44 @@ function permuteSymbol(symbolText: string, r: Mat3): string {
121
121
  return [0, 1, 2].map((i) => symbolText[[0, 1, 2].find((k) => Math.abs(r[i][k]) === 1) ?? -1]).join('');
122
122
  }
123
123
 
124
- function isSignedPermutation(r: Mat3): boolean {
125
- return r.every(
126
- (row) => row.filter((v) => Math.abs(v) > 1e-9).length === 1 && row.some((v) => Math.abs(Math.abs(v) - 1) < 1e-9),
127
- );
128
- }
129
-
130
124
  /**
131
- * The signed permutation r that carries setting 1 of a class into `setting` (new axis i = r[i][j] ×
132
- * old axis j), for the settings ITA does not print (`mm2` settings 2 and 3). Throws if the frame of
133
- * the setting is not a permutation of that of setting 1.
125
+ * The permutation r that carries setting 1 of a class into `setting` (new axis i = r[i][j] × old
126
+ * axis j), for the settings ITA does not print (`mm2` settings 2 and 3, monoclinic unique axis a):
127
+ * the transpose of the change
128
+ * of basis P of the ITC class data ((a′, b′, c′) = (a, b, c)·P, itcData.ts). Coordinates (P⁻¹·x)
129
+ * and Miller indices (h·P) are carried by the same r only because P is a signed permutation
130
+ * (P⁻¹ = Pᵀ); throws for a setting that is not carried from setting 1 by one.
134
131
  */
135
132
  export function permutationFromSetting1(key: PointGroupKey, setting: number): Mat3 {
136
- const d = POINT_GROUP_DATA.find((x) => x.key === key);
137
- if (!d) throw new RangeError(`Unknown point group key: ${JSON.stringify(key)}`);
138
- const f1 = d.settings[0].frame;
139
- const fk = d.settings[setting - 1].frame;
140
- const raw = fk.map((row) => [0, 1, 2].map((j) => row[0] * f1[j][0] + row[1] * f1[j][1] + row[2] * f1[j][2]));
141
- const r = raw.map((row) => row.map((v) => Math.round(v))) as unknown as Mat3;
142
- if (
143
- !isSignedPermutation(raw as unknown as Mat3) ||
144
- !raw.every((row, i) => row.every((v, j) => Math.abs(v - r[i][j]) < 1e-9))
145
- ) {
146
- throw new Error(`Point group ${key}, setting ${setting}: frame is not a permutation of setting 1`);
147
- }
148
- return r;
133
+ const from = itcClassSetting(key, setting).from;
134
+ if (from?.index !== 1) throw new Error(`Point group ${key}, setting ${setting}: not carried from setting 1`);
135
+ const p = from.basis;
136
+ const signedPermutation = [0, 1, 2].every(
137
+ (i) =>
138
+ p[i].filter((v) => v !== 0).length === 1 &&
139
+ p[i].every((v) => v === 0 || Math.abs(v) === 1) &&
140
+ p.filter((row) => row[i] !== 0).length === 1,
141
+ );
142
+ if (!signedPermutation)
143
+ throw new Error(`Point group ${key}, setting ${setting}: not a signed permutation of setting 1`);
144
+ return [0, 1, 2].map((i) => [0, 1, 2].map((j) => p[j][i])) as unknown as Mat3;
149
145
  }
150
146
 
151
147
  /**
152
148
  * The entry of a table printed per setting (Wyckoff positions, face forms) for a setting of a class:
153
- * the one with the ITC short symbol (and unique axis) of the setting, or undefined if ITA does not
149
+ * the one with the ITC short symbol (and unique axis or axes) of the setting, or undefined if ITA does not
154
150
  * print the setting.
155
151
  */
156
- export function printedEntry<E extends { readonly symbol: string; readonly uniqueAxis?: 'b' | 'c' }>(
157
- table: readonly E[],
158
- key: PointGroupKey,
159
- setting: number,
160
- ): E | undefined {
161
- const s = settings(key, 'itc')[setting - 1];
162
- return table.find((e) => e.symbol === s.symbol && (e.uniqueAxis === undefined || e.uniqueAxis === s.uniqueAxis));
152
+ export function printedEntry<
153
+ E extends { readonly symbol: string; readonly uniqueAxis?: 'b' | 'c'; readonly axes?: 'rhombohedral' },
154
+ >(table: readonly E[], key: PointGroupKey, setting: number): E | undefined {
155
+ const s = settings(key)[setting - 1];
156
+ return table.find(
157
+ (e) =>
158
+ e.symbol === s.symbol &&
159
+ (e.uniqueAxis === undefined || e.uniqueAxis === s.uniqueAxis) &&
160
+ (e.axes === 'rhombohedral') === (s.axes === 'rhombohedral'),
161
+ );
163
162
  }
164
163
 
165
164
  /** The printed rows of a setting; for a setting ITA does not print, those of setting 1 carried into its frame. */
@@ -168,69 +167,80 @@ function printedRows(key: PointGroupKey, setting: number): readonly WyckoffRow[]
168
167
  if (entry) return entry.rows;
169
168
  if (setting === 1) throw new Error(`Point group ${key}: no printed Wyckoff positions for setting 1`);
170
169
  const r = permutationFromSetting1(key, setting);
170
+ // A monoclinic site symmetry (`2`, `m`, `2/m`) names the element on the unique axis, not a position.
171
+ const oriented = crystalFamily(itcClass(key).crystalSystem) !== 'monoclinic';
171
172
  return printedRows(key, 1).map(([letter, mult, site, coords, miller]) => [
172
173
  letter,
173
174
  mult,
174
- permuteSymbol(site, r),
175
- permutePattern(coords, r, XYZ),
175
+ oriented ? permuteSymbol(site, r) : site,
176
+ coords.map((c) => permutePattern(c, r, XYZ)),
176
177
  miller === '' ? '' : permutePattern(miller, r, HKL),
177
178
  ]);
178
179
  }
179
180
 
180
181
  /**
181
- * The lattice basis in which the Cartesian normals of the representatives are computed; monoclinic
182
- * and triclinic: a, b, c along x, y, z (docs/conventions.md, "Site symmetry and Wyckoff positions").
182
+ * The lattice basis in which the Cartesian normals of the representatives are computed, that of the
183
+ * setting (itcData.ts, `itcBasis`): monoclinic and triclinic a, b, c along x, y, z; rhombohedral
184
+ * axes in the hexagonal cell of `latticeBasis` (docs/conventions.md, "Site symmetry and Wyckoff
185
+ * positions").
186
+ */
187
+ export function faceBasis(key: PointGroupKey, setting: number): Mat3 {
188
+ return itcBasis(key, setting);
189
+ }
190
+
191
+ /** h, k, l of a representative face under the printed condition |h| < |l| (cubic forms (hhl)). */
192
+ export const SMALL_H: Readonly<Record<'h' | 'k' | 'l', number>> = Object.freeze({ h: 1, k: 2, l: 3 });
193
+
194
+ /**
195
+ * A face of a position or form with numbers, internal (#137 G3: the API gives the printed indices
196
+ * only): h, k, l = 3, 2, 1 (rhombohedral axes: 5, 2, 1; 1, 2, 3 under the condition |h| < |l|), and
197
+ * its normal in the basis of the setting (`faceBasis`; monoclinic and triclinic a, b, c along x, y,
198
+ * z, which gives the correct site symmetry but not the pole of a real cell, #137 G4).
183
199
  */
184
- export function faceBasis(key: PointGroupKey): Mat3 {
185
- const d = POINT_GROUP_DATA.find((x) => x.key === key);
186
- if (!d) throw new RangeError(`Unknown point group key: ${JSON.stringify(key)}`);
187
- const family = crystalFamily(d.crystalSystem);
188
- return family === 'monoclinic' || family === 'triclinic' ? IDENTITY : latticeBasis(family);
200
+ export function representativeFace(
201
+ key: PointGroupKey,
202
+ setting: number,
203
+ miller: string,
204
+ condition?: string,
205
+ ): { readonly hkl: Hkl; readonly cartesian: Vec3 } {
206
+ const hkl = numericHkl(miller, condition === '|h|<|l|' ? SMALL_H : representativeValues(key, setting));
207
+ return { hkl, cartesian: normal(faceBasis(key, setting), hkl) };
189
208
  }
190
209
 
191
210
  const cache = new Map<string, readonly WyckoffPosition[]>();
192
211
 
193
212
  /**
194
- * The setting index for a table that exists for the crystal classes in the ITC convention only
195
- * (`what`: 'Wyckoff positions', 'Crystal forms'); throws a RangeError for a magnetic point group
196
- * with time reversal and for another convention.
213
+ * The setting index for a table that exists for the crystal classes only (`what`: 'Wyckoff
214
+ * positions', 'Crystal forms'); throws a RangeError for a magnetic point group with time reversal.
197
215
  */
198
- export function itcSetting(key: PointGroupKey, options?: SettingOptions, what = 'Wyckoff positions'): number {
216
+ export function tableSetting(key: PointGroupKey, options?: SettingOptions, what = 'Wyckoff positions'): number {
199
217
  if (isMagneticPointGroupKey(key) && !isPointGroupKey(key)) {
200
- throw new RangeError(
201
- `${what} are given for the 32 crystal classes only; ${JSON.stringify(key)} is a magnetic point group`,
202
- );
203
- }
204
- if ((options?.convention ?? 'itc') !== 'itc') {
205
- throw new RangeError(`${what} exist in the ITC convention only (convention 'itc')`);
218
+ throw new RangeError(`${what} are given for the 32 crystal classes only; ${shown(key)} is a magnetic point group`);
206
219
  }
207
- const list = settings(key, 'itc');
208
- const index = options?.setting ?? list.find((s) => s.isDefault)?.index ?? 1;
209
- operations(key, { convention: 'itc', setting: index }); // validates the setting index
220
+ const index = settingIndexOf(key, options);
221
+ operations(key, pick(options, SETTING_KEYS)); // validates the setting index
210
222
  return index;
211
223
  }
212
224
 
213
225
  /**
214
226
  * The Wyckoff positions of a point group for directions, in ITA's printed order (general position
215
- * first), for the 32 crystal classes and in the ITC convention only (throws a RangeError for a
216
- * magnetic point group with time reversal and for `'birss'`). The point at the origin
217
- * (letter o) is not a direction and is left out. For `mm2` settings 2 and 3 (`2mm`, `m2m`), which
218
- * ITA does not print, the positions of setting 1 carried into their frame.
227
+ * first), for the 32 crystal classes only (throws a RangeError for a magnetic point group with
228
+ * time reversal). The point at the origin
229
+ * (letter o) is not a direction and is left out. For the settings ITA does not print (`mm2` settings 2 and 3, monoclinic unique axis a), the positions
230
+ * of setting 1 carried into their frame.
219
231
  */
220
232
  export function wyckoffPositions(key: PointGroupKey, options?: SettingOptions): readonly WyckoffPosition[] {
221
- const setting = itcSetting(key, options);
233
+ checkOptions(options, SETTING_KEYS, 'wyckoffPositions');
234
+ const setting = tableSetting(key, options);
222
235
  const cacheKey = `${key}#${setting}`;
223
236
  let result = cache.get(cacheKey);
224
237
  if (!result) {
225
- const ops = operations(key, { convention: 'itc', setting });
226
- const basis = faceBasis(key);
238
+ const ops = operations(key, { setting });
227
239
  result = Object.freeze(
228
240
  printedRows(key, setting)
229
241
  .filter(([letter]) => letter !== 'o')
230
242
  .map(([letter, multiplicity, site, coordinates, millerIndices]) => {
231
- const hkl = numericHkl(millerIndices);
232
- const cartesian = normal(basis, hkl);
233
- const stab = siteSymmetry(ops, cartesian);
243
+ const stab = siteSymmetryOf(ops, representativeFace(key, setting, millerIndices).cartesian);
234
244
  if (stab.multiplicity !== multiplicity) {
235
245
  throw new Error(
236
246
  `Point group ${key}, setting ${setting}, position ${letter}: multiplicity differs from print`,
@@ -240,12 +250,8 @@ export function wyckoffPositions(key: PointGroupKey, options?: SettingOptions):
240
250
  letter,
241
251
  multiplicity,
242
252
  siteSymmetry: site,
243
- coordinates,
253
+ coordinates: Object.freeze([...coordinates]),
244
254
  millerIndices,
245
- representative: Object.freeze({
246
- hkl: Object.freeze(hkl) as Hkl,
247
- cartesian: Object.freeze(cartesian) as Vec3,
248
- }),
249
255
  siteSymmetryOperations: stab.operations,
250
256
  });
251
257
  }),
@@ -255,27 +261,46 @@ export function wyckoffPositions(key: PointGroupKey, options?: SettingOptions):
255
261
  return result;
256
262
  }
257
263
 
264
+ /**
265
+ * The site symmetry of a direction (any non-zero Cartesian vector) under a point group in a
266
+ * setting: `siteSymmetryOf` applied to `operations(key, options)`, so the indices refer to those
267
+ * operations (#137 C1). Time reversal is ignored. Throws a RangeError as `siteSymmetryOf` does.
268
+ */
269
+ export function siteSymmetry(
270
+ key: MagneticPointGroupKey,
271
+ direction: Vec3,
272
+ options?: SettingOptions & ToleranceOptions,
273
+ ): SiteSymmetry {
274
+ checkOptions(options, [...SETTING_KEYS, ...TOLERANCE_KEYS], 'siteSymmetry');
275
+ return siteSymmetryOf(operations(key, pick(options, SETTING_KEYS)), direction, pick(options, TOLERANCE_KEYS));
276
+ }
277
+
258
278
  const sortedKey = (list: readonly number[]): string => [...list].sort((a, b) => a - b).join(',');
259
279
 
260
280
  /**
261
- * The Wyckoff position of a direction (any non-zero Cartesian vector) in a point group, ITC
262
- * convention only: the position whose representative has a site symmetry conjugate to that of the
263
- * direction (ITA's definition). `tolerance` as for `siteSymmetry`; throws a RangeError if the
281
+ * The Wyckoff position of a direction (any non-zero Cartesian vector) in a crystal class: the
282
+ * position whose printed face has a site symmetry conjugate to that of the
283
+ * direction (ITA's definition). `tolerance` as for `siteSymmetryOf`; throws a RangeError if the
264
284
  * operations found within it do not match any position (a tolerance too large).
265
285
  */
266
- export function wyckoffPositionOf(key: PointGroupKey, direction: Vec3, options?: WyckoffOptions): WyckoffPosition {
286
+ export function wyckoffPosition(
287
+ key: PointGroupKey,
288
+ direction: Vec3,
289
+ options?: SettingOptions & ToleranceOptions,
290
+ ): WyckoffPosition {
291
+ checkOptions(options, [...SETTING_KEYS, ...TOLERANCE_KEYS], 'wyckoffPosition');
267
292
  const tolerance = siteTolerance(options);
268
- const setting = itcSetting(key, options);
269
- const ops = operations(key, { convention: 'itc', setting });
270
- const rows = wyckoffPositions(key, { convention: 'itc', setting });
271
- const site = siteSymmetry(ops, direction, { tolerance });
293
+ const setting = tableSetting(key, options);
294
+ const ops = operations(key, { setting });
295
+ const rows = wyckoffPositions(key, { setting });
296
+ const site = siteSymmetryOf(ops, direction, { tolerance });
272
297
  const candidates = rows.filter((r) => r.siteSymmetryOperations.length === site.operations.length);
273
298
  for (const g of ops) {
274
- const k = sortedKey(siteSymmetry(ops, apply(g.matrix, site.direction), { tolerance }).operations);
299
+ const k = sortedKey(siteSymmetryOf(ops, apply(g.cartesian, site.direction), { tolerance }).operations);
275
300
  const row = candidates.find((r) => sortedKey(r.siteSymmetryOperations) === k);
276
301
  if (row) return row;
277
302
  }
278
303
  throw new RangeError(
279
- `Point group ${key}, setting ${setting}: no Wyckoff position for ${JSON.stringify(direction)} (tolerance too large?)`,
304
+ `Point group ${key}, setting ${setting}: no Wyckoff position for ${shown(direction)} (tolerance too large?)`,
280
305
  );
281
306
  }