symcrys 0.10.1 → 0.11.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 (218) 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/crystalClasses.d.ts +145 -117
  15. package/dist/crystalClasses.d.ts.map +1 -1
  16. package/dist/crystalClasses.js +161 -121
  17. package/dist/crystalClasses.js.map +1 -1
  18. package/dist/freeze.d.ts +7 -0
  19. package/dist/freeze.d.ts.map +1 -0
  20. package/dist/freeze.js +15 -0
  21. package/dist/freeze.js.map +1 -0
  22. package/dist/index.d.ts +11 -10
  23. package/dist/index.d.ts.map +1 -1
  24. package/dist/index.js +4 -3
  25. package/dist/index.js.map +1 -1
  26. package/dist/indices.d.ts +31 -5
  27. package/dist/indices.d.ts.map +1 -1
  28. package/dist/indices.js +104 -13
  29. package/dist/indices.js.map +1 -1
  30. package/dist/lattice.d.ts +15 -1
  31. package/dist/lattice.d.ts.map +1 -1
  32. package/dist/lattice.js +30 -1
  33. package/dist/lattice.js.map +1 -1
  34. package/dist/linalg.d.ts +2 -2
  35. package/dist/linalg.d.ts.map +1 -1
  36. package/dist/linalg.js +3 -3
  37. package/dist/linalg.js.map +1 -1
  38. package/dist/magnetic.d.ts +12 -10
  39. package/dist/magnetic.d.ts.map +1 -1
  40. package/dist/magnetic.js +8 -6
  41. package/dist/magnetic.js.map +1 -1
  42. package/dist/notation.d.ts +16 -0
  43. package/dist/notation.d.ts.map +1 -0
  44. package/dist/notation.js +66 -0
  45. package/dist/notation.js.map +1 -0
  46. package/dist/operations.d.ts +40 -26
  47. package/dist/operations.d.ts.map +1 -1
  48. package/dist/operations.js +48 -60
  49. package/dist/operations.js.map +1 -1
  50. package/dist/plane.d.ts +141 -79
  51. package/dist/plane.d.ts.map +1 -1
  52. package/dist/plane.js +147 -77
  53. package/dist/plane.js.map +1 -1
  54. package/dist/pointGroups/crystalForms.d.ts +6 -21
  55. package/dist/pointGroups/crystalForms.d.ts.map +1 -1
  56. package/dist/pointGroups/crystalForms.js +9 -16
  57. package/dist/pointGroups/crystalForms.js.map +1 -1
  58. package/dist/pointGroups/crystalFormsData.d.ts +4 -1
  59. package/dist/pointGroups/crystalFormsData.d.ts.map +1 -1
  60. package/dist/pointGroups/crystalFormsData.js +64 -1
  61. package/dist/pointGroups/crystalFormsData.js.map +1 -1
  62. package/dist/pointGroups/elements.d.ts +19 -17
  63. package/dist/pointGroups/elements.d.ts.map +1 -1
  64. package/dist/pointGroups/elements.js +65 -83
  65. package/dist/pointGroups/elements.js.map +1 -1
  66. package/dist/pointGroups/identify.d.ts +10 -18
  67. package/dist/pointGroups/identify.d.ts.map +1 -1
  68. package/dist/pointGroups/identify.js +27 -79
  69. package/dist/pointGroups/identify.js.map +1 -1
  70. package/dist/pointGroups/itaOrder.d.ts +15 -14
  71. package/dist/pointGroups/itaOrder.d.ts.map +1 -1
  72. package/dist/pointGroups/itaOrder.js +116 -94
  73. package/dist/pointGroups/itaOrder.js.map +1 -1
  74. package/dist/pointGroups/itcData.d.ts +96 -0
  75. package/dist/pointGroups/itcData.d.ts.map +1 -0
  76. package/dist/pointGroups/itcData.js +336 -0
  77. package/dist/pointGroups/itcData.js.map +1 -0
  78. package/dist/pointGroups/itcMagneticData.d.ts +55 -0
  79. package/dist/pointGroups/itcMagneticData.d.ts.map +1 -0
  80. package/dist/pointGroups/itcMagneticData.js +172 -0
  81. package/dist/pointGroups/itcMagneticData.js.map +1 -0
  82. package/dist/pointGroups/keys.d.ts +32 -0
  83. package/dist/pointGroups/keys.d.ts.map +1 -0
  84. package/dist/pointGroups/keys.js +120 -0
  85. package/dist/pointGroups/keys.js.map +1 -0
  86. package/dist/pointGroups/magneticSymbols.d.ts +6 -5
  87. package/dist/pointGroups/magneticSymbols.d.ts.map +1 -1
  88. package/dist/pointGroups/magneticSymbols.js +15 -12
  89. package/dist/pointGroups/magneticSymbols.js.map +1 -1
  90. package/dist/pointGroups/orbits.d.ts +23 -42
  91. package/dist/pointGroups/orbits.d.ts.map +1 -1
  92. package/dist/pointGroups/orbits.js +20 -62
  93. package/dist/pointGroups/orbits.js.map +1 -1
  94. package/dist/pointGroups/pointGroups.d.ts +135 -67
  95. package/dist/pointGroups/pointGroups.d.ts.map +1 -1
  96. package/dist/pointGroups/pointGroups.js +409 -244
  97. package/dist/pointGroups/pointGroups.js.map +1 -1
  98. package/dist/pointGroups/properties.d.ts +21 -22
  99. package/dist/pointGroups/properties.d.ts.map +1 -1
  100. package/dist/pointGroups/properties.js +40 -37
  101. package/dist/pointGroups/properties.js.map +1 -1
  102. package/dist/pointGroups/seitzData.d.ts +26 -0
  103. package/dist/pointGroups/seitzData.d.ts.map +1 -0
  104. package/dist/pointGroups/seitzData.js +130 -0
  105. package/dist/pointGroups/seitzData.js.map +1 -0
  106. package/dist/pointGroups/wyckoff.d.ts +70 -40
  107. package/dist/pointGroups/wyckoff.d.ts.map +1 -1
  108. package/dist/pointGroups/wyckoff.js +98 -91
  109. package/dist/pointGroups/wyckoff.js.map +1 -1
  110. package/dist/pointGroups/wyckoffData.d.ts +7 -4
  111. package/dist/pointGroups/wyckoffData.d.ts.map +1 -1
  112. package/dist/pointGroups/wyckoffData.js +789 -168
  113. package/dist/pointGroups/wyckoffData.js.map +1 -1
  114. package/dist/siteSymmetry.d.ts +8 -16
  115. package/dist/siteSymmetry.d.ts.map +1 -1
  116. package/dist/siteSymmetry.js +34 -24
  117. package/dist/siteSymmetry.js.map +1 -1
  118. package/dist/spaceGroups/affine.d.ts.map +1 -1
  119. package/dist/spaceGroups/affine.js +3 -2
  120. package/dist/spaceGroups/affine.js.map +1 -1
  121. package/dist/spaceGroups/cell.d.ts +43 -31
  122. package/dist/spaceGroups/cell.d.ts.map +1 -1
  123. package/dist/spaceGroups/cell.js +173 -85
  124. package/dist/spaceGroups/cell.js.map +1 -1
  125. package/dist/spaceGroups/describe.d.ts +12 -10
  126. package/dist/spaceGroups/describe.d.ts.map +1 -1
  127. package/dist/spaceGroups/describe.js +11 -10
  128. package/dist/spaceGroups/describe.js.map +1 -1
  129. package/dist/spaceGroups/planeGroupData.d.ts +1 -1
  130. package/dist/spaceGroups/planeGroupData.d.ts.map +1 -1
  131. package/dist/spaceGroups/planeGroupData.js +8 -8
  132. package/dist/spaceGroups/planeGroupData.js.map +1 -1
  133. package/dist/spaceGroups/planeGroups.d.ts.map +1 -1
  134. package/dist/spaceGroups/planeGroups.js +2 -1
  135. package/dist/spaceGroups/planeGroups.js.map +1 -1
  136. package/dist/spaceGroups/positions.d.ts +48 -19
  137. package/dist/spaceGroups/positions.d.ts.map +1 -1
  138. package/dist/spaceGroups/positions.js +166 -67
  139. package/dist/spaceGroups/positions.js.map +1 -1
  140. package/dist/tensors/propertyTable.d.ts +3 -1
  141. package/dist/tensors/propertyTable.d.ts.map +1 -1
  142. package/dist/tensors/propertyTable.js +17 -10
  143. package/dist/tensors/propertyTable.js.map +1 -1
  144. package/dist/tensors/rowEchelon.d.ts +3 -3
  145. package/dist/tensors/rowEchelon.d.ts.map +1 -1
  146. package/dist/tensors/rowEchelon.js +4 -4
  147. package/dist/tensors/rowEchelon.js.map +1 -1
  148. package/dist/tensors/tensorForm.d.ts +75 -34
  149. package/dist/tensors/tensorForm.d.ts.map +1 -1
  150. package/dist/tensors/tensorForm.js +171 -67
  151. package/dist/tensors/tensorForm.js.map +1 -1
  152. package/dist/tensors/tensorProperties.d.ts +10 -9
  153. package/dist/tensors/tensorProperties.d.ts.map +1 -1
  154. package/dist/tensors/tensorProperties.js +22 -12
  155. package/dist/tensors/tensorProperties.js.map +1 -1
  156. package/dist/tolerances.d.ts +56 -1
  157. package/dist/tolerances.d.ts.map +1 -1
  158. package/dist/tolerances.js +51 -1
  159. package/dist/tolerances.js.map +1 -1
  160. package/dist/version.d.ts +1 -1
  161. package/dist/version.js +1 -1
  162. package/package.json +1 -1
  163. package/src/cell.ts +78 -51
  164. package/src/checks.ts +84 -0
  165. package/src/closure.ts +214 -0
  166. package/src/crystalClasses.ts +232 -157
  167. package/src/freeze.ts +14 -0
  168. package/src/index.ts +21 -10
  169. package/src/indices.ts +108 -18
  170. package/src/lattice.ts +41 -1
  171. package/src/linalg.ts +3 -3
  172. package/src/magnetic.ts +14 -9
  173. package/src/notation.ts +73 -0
  174. package/src/operations.ts +78 -71
  175. package/src/plane.ts +253 -127
  176. package/src/pointGroups/crystalForms.ts +11 -44
  177. package/src/pointGroups/crystalFormsData.ts +66 -1
  178. package/src/pointGroups/elements.ts +82 -92
  179. package/src/pointGroups/identify.ts +38 -97
  180. package/src/pointGroups/itaOrder.ts +117 -101
  181. package/src/pointGroups/itcData.ts +404 -0
  182. package/src/pointGroups/itcMagneticData.ts +206 -0
  183. package/src/pointGroups/keys.ts +144 -0
  184. package/src/pointGroups/magneticSymbols.ts +18 -17
  185. package/src/pointGroups/orbits.ts +41 -89
  186. package/src/pointGroups/pointGroups.ts +540 -297
  187. package/src/pointGroups/properties.ts +44 -40
  188. package/src/pointGroups/seitzData.ts +147 -0
  189. package/src/pointGroups/wyckoff.ts +137 -112
  190. package/src/pointGroups/wyckoffData.ts +793 -170
  191. package/src/siteSymmetry.ts +43 -40
  192. package/src/spaceGroups/affine.ts +3 -2
  193. package/src/spaceGroups/cell.ts +227 -116
  194. package/src/spaceGroups/describe.ts +22 -19
  195. package/src/spaceGroups/planeGroupData.ts +9 -9
  196. package/src/spaceGroups/planeGroups.ts +2 -1
  197. package/src/spaceGroups/positions.ts +202 -78
  198. package/src/tensors/propertyTable.ts +26 -14
  199. package/src/tensors/rowEchelon.ts +4 -3
  200. package/src/tensors/tensorForm.ts +258 -88
  201. package/src/tensors/tensorProperties.ts +34 -14
  202. package/src/tolerances.ts +66 -1
  203. package/src/version.ts +1 -1
  204. package/dist/pointGroups/data.d.ts +0 -75
  205. package/dist/pointGroups/data.d.ts.map +0 -1
  206. package/dist/pointGroups/data.js +0 -212
  207. package/dist/pointGroups/data.js.map +0 -1
  208. package/dist/pointGroups/magneticData.d.ts +0 -66
  209. package/dist/pointGroups/magneticData.d.ts.map +0 -1
  210. package/dist/pointGroups/magneticData.js +0 -184
  211. package/dist/pointGroups/magneticData.js.map +0 -1
  212. package/dist/spaceGroups/snap.d.ts +0 -20
  213. package/dist/spaceGroups/snap.d.ts.map +0 -1
  214. package/dist/spaceGroups/snap.js +0 -103
  215. package/dist/spaceGroups/snap.js.map +0 -1
  216. package/src/pointGroups/data.ts +0 -305
  217. package/src/pointGroups/magneticData.ts +0 -328
  218. package/src/spaceGroups/snap.ts +0 -121
@@ -0,0 +1,144 @@
1
+ /**
2
+ * The keys of the point groups: the 32 crystal classes (type I), the 32 grey groups (type II) and
3
+ * the 58 black-and-white groups (type III), the 122 magnetic point groups (docs/conventions.md,
4
+ * "Keys"). Their data are in itcData.ts and itcMagneticData.ts.
5
+ */
6
+
7
+ import { IDENTITY } from '../linalg.js';
8
+ import type { CartesianOperation } from '../operations.js';
9
+
10
+ /** Keys of the 32 crystal classes: the ITC short symbol of the class (docs/conventions.md, "Keys"). */
11
+ export const POINT_GROUP_KEYS = Object.freeze([
12
+ '1',
13
+ '-1',
14
+ '2',
15
+ 'm',
16
+ '2/m',
17
+ '222',
18
+ 'mm2',
19
+ 'mmm',
20
+ '4',
21
+ '-4',
22
+ '4/m',
23
+ '422',
24
+ '4mm',
25
+ '-42m',
26
+ '4/mmm',
27
+ '3',
28
+ '-3',
29
+ '32',
30
+ '3m',
31
+ '-3m',
32
+ '6',
33
+ '-6',
34
+ '6/m',
35
+ '622',
36
+ '6mm',
37
+ '-6m2',
38
+ '6/mmm',
39
+ '23',
40
+ 'm-3',
41
+ '432',
42
+ '-43m',
43
+ 'm-3m',
44
+ ] as const);
45
+
46
+ /** The key of one of the 32 crystal classes (`POINT_GROUP_KEYS`). */
47
+ // `Extract<…, string>` is the same type; written so, the documentation (TypeDoc) names it instead of
48
+ // listing the 32 keys at every use.
49
+ export type PointGroupKey = Extract<(typeof POINT_GROUP_KEYS)[number], string>;
50
+
51
+ /** Keys of the 32 grey groups: the key of the crystal class followed by `1'`. */
52
+ export type GreyPointGroupKey = `${PointGroupKey}1'`;
53
+
54
+ export const GREY_POINT_GROUP_KEYS: readonly GreyPointGroupKey[] = Object.freeze(
55
+ POINT_GROUP_KEYS.map((key): GreyPointGroupKey => `${key}1'`),
56
+ );
57
+
58
+ /**
59
+ * Keys of the 58 black-and-white groups: the short Hermann–Mauguin symbol of ITC Vol. D
60
+ * Table 1.5.2.3, in the order of the table (docs/conventions.md, "Keys").
61
+ */
62
+ export const BLACK_WHITE_POINT_GROUP_KEYS = Object.freeze([
63
+ "-1'",
64
+ "2'",
65
+ "m'",
66
+ "2'/m'",
67
+ "2/m'",
68
+ "2'/m",
69
+ "2'2'2",
70
+ "m'm'2",
71
+ "2'm'm",
72
+ "mm'm'",
73
+ "m'm'm'",
74
+ "mmm'",
75
+ "4'",
76
+ "-4'",
77
+ "4'/m",
78
+ "4/m'",
79
+ "4'/m'",
80
+ "4'22'",
81
+ "42'2'",
82
+ "4'mm'",
83
+ "4m'm'",
84
+ "-4'2m'",
85
+ "-4'm2'",
86
+ "-42'm'",
87
+ "4'/mmm'",
88
+ "4/mm'm'",
89
+ "4/m'm'm'",
90
+ "4/m'mm",
91
+ "4'/m'm'm",
92
+ "-3'",
93
+ "32'",
94
+ "3m'",
95
+ "-3m'",
96
+ "-3'm'",
97
+ "-3'm",
98
+ "6'",
99
+ "-6'",
100
+ "6'/m'",
101
+ "6/m'",
102
+ "6'/m",
103
+ "6'22'",
104
+ "62'2'",
105
+ "6'mm'",
106
+ "6m'm'",
107
+ "-6'2m'",
108
+ "-6'm2'",
109
+ "-6m'2'",
110
+ "6'/m'mm'",
111
+ "6/mm'm'",
112
+ "6/m'm'm'",
113
+ "6/m'mm",
114
+ "6'/mmm'",
115
+ "m'-3'",
116
+ "4'32'",
117
+ "-4'3m'",
118
+ "m-3m'",
119
+ "m'-3'm'",
120
+ "m'-3'm",
121
+ ] as const);
122
+
123
+ /** The key of one of the 58 black-and-white magnetic point groups. */
124
+ // `Extract<…, string>`: the same type, named by the documentation (see `PointGroupKey`).
125
+ export type BlackWhitePointGroupKey = Extract<(typeof BLACK_WHITE_POINT_GROUP_KEYS)[number], string>;
126
+
127
+ /** Keys of all 122 magnetic point groups: the 32 crystal classes, the 32 grey groups, the 58 black-and-white groups. */
128
+ export type MagneticPointGroupKey = PointGroupKey | GreyPointGroupKey | BlackWhitePointGroupKey;
129
+
130
+ /**
131
+ * Keys of the 122 magnetic point groups: the 32 crystal classes (white groups), the 32 grey groups
132
+ * and the 58 black-and-white groups, in this order (docs/conventions.md, "Keys").
133
+ */
134
+ export const MAGNETIC_POINT_GROUP_KEYS: readonly MagneticPointGroupKey[] = Object.freeze([
135
+ ...POINT_GROUP_KEYS,
136
+ ...GREY_POINT_GROUP_KEYS,
137
+ ...BLACK_WHITE_POINT_GROUP_KEYS,
138
+ ]);
139
+
140
+ /** Time reversal alone: the identity combined with time reversal (1'). */
141
+ export const TIME_REVERSAL: CartesianOperation = Object.freeze({ cartesian: IDENTITY, timeReversal: true });
142
+
143
+ /** Schoenflies symbol of a grey group: that of its class with the subscript R (ITC Vol. D, Table 1.5.2.1). */
144
+ export const greySchoenflies = (classSymbol: string): string => `${classSymbol}R`;
@@ -2,22 +2,20 @@
2
2
  * Hermann–Mauguin symbols of the black-and-white point groups. The symbol of such a group in a
3
3
  * given frame is the symbol of its crystal class in that frame, each position carrying a prime if
4
4
  * the operation it names is combined with time reversal (ITC Vol. D, § 1.5.2.1, Table 1.5.2.3).
5
- * So no symbols are stored for these groups: they follow from the symbols of the class
6
- * (data.ts) and the operations (docs/conventions.md, "Symbols").
5
+ * The ITC symbols of these groups are stored (itcMagneticData.ts); this module writes the symbol a
6
+ * group has with given operations, from which the time reversal of the operations is derived
7
+ * (docs/conventions.md, "Symbols").
7
8
  */
8
9
 
10
+ import { shown } from '../checks.js';
9
11
  import { matricesEqual, type Mat3, type Vec3 } from '../linalg.js';
10
12
  import { crystalFamily, latticeBasis, type CrystalFamily, type CrystalSystem } from '../lattice.js';
11
- import type { Operation } from '../operations.js';
13
+ import type { CartesianOperation } from '../operations.js';
12
14
  import { LATTICE_SYMMETRY_DIRECTIONS } from '../symmetryDirections.js';
13
15
 
14
16
  /** The Cartesian direction of the first symmetry direction of each position of the full symbol. */
15
- function positionDirections(family: CrystalFamily, convention: 'itc' | 'birss'): readonly Vec3[] {
17
+ function positionDirections(family: CrystalFamily): readonly Vec3[] {
16
18
  const positions = LATTICE_SYMMETRY_DIRECTIONS[family];
17
- // Birss reads position 2 of the hexagonal family along y and position 3 along x
18
- // (docs/conventions.md, "Where ITC and Birss differ").
19
- const ordered =
20
- convention === 'birss' && family === 'hexagonal' ? [positions[0], positions[2], positions[1]] : positions;
21
19
  // Monoclinic: a, b, c along x, y, z, exact for the unique axis, the only one with an element.
22
20
  const b: Mat3 =
23
21
  family === 'monoclinic' || family === 'triclinic'
@@ -27,7 +25,7 @@ function positionDirections(family: CrystalFamily, convention: 'itc' | 'birss'):
27
25
  [0, 0, 1],
28
26
  ]
29
27
  : latticeBasis(family);
30
- return ordered.map(([uvw]) => [
28
+ return positions.map(([uvw]) => [
31
29
  b[0][0] * uvw[0] + b[0][1] * uvw[1] + b[0][2] * uvw[2],
32
30
  b[1][0] * uvw[0] + b[1][1] * uvw[1] + b[1][2] * uvw[2],
33
31
  b[2][0] * uvw[0] + b[2][1] * uvw[1] + b[2][2] * uvw[2],
@@ -51,17 +49,17 @@ function rotation(u: Vec3, n: number, sign: 1 | -1): Mat3 {
51
49
  }
52
50
 
53
51
  /** `'` if the operation with this matrix is combined with time reversal in `ops`, otherwise ``. */
54
- function prime(ops: readonly Operation[], matrix: Mat3, what: string): string {
55
- const op = ops.find((x) => matricesEqual(x.matrix, matrix));
52
+ function prime(ops: readonly CartesianOperation[], matrix: Mat3, what: string): string {
53
+ const op = ops.find((x) => matricesEqual(x.cartesian, matrix));
56
54
  if (!op) throw new Error(`${what}: the group does not contain the operation its symbol names`);
57
55
  return op.timeReversal ? "'" : '';
58
56
  }
59
57
 
60
58
  /** One position (`N`, `-N`, `N/m`, `m`, `1`) with the primes of the operations along `u`. */
61
- function primedToken(token: string, u: Vec3 | undefined, ops: readonly Operation[], what: string): string {
59
+ function primedToken(token: string, u: Vec3 | undefined, ops: readonly CartesianOperation[], what: string): string {
62
60
  if (token === '1') return token;
63
61
  const parts = /^(?:(-?)([1-6]))?(\/?m)?$/.exec(token);
64
- if (!parts || token === '') throw new Error(`${what}: unreadable position ${JSON.stringify(token)}`);
62
+ if (!parts || token === '') throw new Error(`${what}: unreadable position ${shown(token)}`);
65
63
  const [, bar, n, mirror] = parts;
66
64
  let result = '';
67
65
  if (n) {
@@ -88,17 +86,20 @@ function shortTokens(symbol: string): string[] {
88
86
 
89
87
  /**
90
88
  * The symbols of a black-and-white group in one frame: the short and the full symbol of its
91
- * crystal class in that frame, in the given convention, with primes taken from `ops`, the
89
+ * crystal class in that frame, with primes taken from `ops`, the
92
90
  * operations of the group in that frame.
93
91
  */
94
92
  export function primedSymbols(
95
93
  classSymbols: { readonly short: string; readonly full: string },
96
94
  system: CrystalSystem,
97
- convention: 'itc' | 'birss',
98
- ops: readonly Operation[],
95
+ ops: readonly CartesianOperation[],
99
96
  ): { short: string; full: string } {
100
97
  const family = crystalFamily(system);
101
- const directions = positionDirections(family, convention);
98
+ // The positions of the family, also for a setting with rhombohedral axes: their Cartesian
99
+ // directions are those of [111] and [1-10] in the obverse rhombohedral cell, the c and a axes of
100
+ // the hexagonal cell (docs/conventions.md, "Cartesian frame"), and its symbol has only these two
101
+ // positions, so reading it along the first two hexagonal positions gives the same primes.
102
+ const directions = positionDirections(family);
102
103
  const what = `Symbol ${classSymbols.short}`;
103
104
  const fullTokens = classSymbols.full.split(' ');
104
105
  const full = fullTokens.map((t, i) => primedToken(t, directions[i], ops, what)).join(' ');
@@ -1,80 +1,25 @@
1
1
  /**
2
- * Operations in the lattice basis and orbits of faces and directions (docs/conventions.md,
3
- * "Lattice basis and orbits"). Shared by both entry points.
2
+ * Orbits of faces and directions (docs/conventions.md, "Lattice basis and orbits"). Shared by both
3
+ * entry points.
4
4
  */
5
5
 
6
- import { crystalFamily, latticeBasis } from '../lattice.js';
7
- import { apply, inverse, multiply, type Mat3, type Vec3 } from '../linalg.js';
8
- import { checkOrthogonalWithin, type Operation } from '../operations.js';
6
+ import { checkNumbers, checkOptions, SETTING_KEYS, shown, TOLERANCE_KEYS } from '../checks.js';
7
+ import { apply, inverse, type Mat3, type Vec3 } from '../linalg.js';
8
+ import { checkCartesianOperations } from '../operations.js';
9
9
  import { siteTolerance } from '../siteSymmetry.js';
10
+ import { TOLERANCE_BOUND } from '../tolerances.js';
11
+ import type { ToleranceOptions } from '../tolerances.js';
10
12
  import type { Uvw } from '../symmetryDirections.js';
11
13
  import {
14
+ integer,
12
15
  operations as groupOperations,
13
- pointGroup,
14
16
  type MagneticPointGroupKey,
15
17
  type SettingOptions,
16
18
  } from './pointGroups.js';
17
19
  import type { Hkl } from './wyckoff.js';
18
20
 
19
- const IDENTITY: Mat3 = [
20
- [1, 0, 0],
21
- [0, 1, 0],
22
- [0, 0, 1],
23
- ];
24
-
25
- /**
26
- * The conventional basis a, b, c (columns) in the Cartesian frame of a point group: that of
27
- * `latticeBasis`, and for the monoclinic and triclinic families a, b, c along x, y, z, as for the
28
- * Wyckoff positions (the integer matrices do not depend on the cell angles).
29
- */
30
- function conventionalBasis(key: MagneticPointGroupKey): Mat3 {
31
- const family = crystalFamily(pointGroup(key).crystalSystem);
32
- return family === 'monoclinic' || family === 'triclinic' ? IDENTITY : latticeBasis(family);
33
- }
34
-
35
- /** An integer matrix from one that should be one; throws if it is not (a data error). */
36
- function integer(m: Mat3, what: string): Mat3 {
37
- const r = m.map((row) => row.map((v) => Math.round(v) + 0)) as unknown as Mat3;
38
- if (!m.every((row, i) => row.every((v, j) => Math.abs(v - r[i][j]) < 1e-9))) {
39
- throw new Error(`${what} is not an integer matrix in the lattice basis: ${JSON.stringify(m)}`);
40
- }
41
- return r;
42
- }
43
-
44
21
  const deepFreeze = (m: Mat3): Mat3 => Object.freeze(m.map((row) => Object.freeze([...row]))) as unknown as Mat3;
45
22
 
46
- const latticeCache = new WeakMap<readonly Operation[], readonly Operation[]>();
47
-
48
- /**
49
- * The operations of a point group in the conventional lattice basis (a, b, c; for the trigonal
50
- * classes the hexagonal axes), in the order and with the time reversal of `operations` for the same
51
- * setting and convention: integer matrices W acting on the coordinates of a lattice vector [uvw],
52
- * W = B⁻¹·R·B with the basis B of `latticeBasis` and the Cartesian matrix R. They do not depend on
53
- * the cell angles, so they exist for every family; for the monoclinic and triclinic families a, b,
54
- * c are taken along x, y, z, as for the Wyckoff positions. In the ITC convention they are the
55
- * matrices of ITA's general position (6th ed., Table 3.2.3.2). Not orthogonal in general: pass
56
- * them to no function that takes Cartesian operations (docs/conventions.md, "Lattice basis and
57
- * orbits").
58
- */
59
- export function latticeOperations(key: MagneticPointGroupKey, options?: SettingOptions): readonly Operation[] {
60
- const ops = groupOperations(key, options);
61
- let result = latticeCache.get(ops);
62
- if (!result) {
63
- const b = conventionalBasis(key);
64
- const bInv = inverse(b);
65
- result = Object.freeze(
66
- ops.map((op, i) =>
67
- Object.freeze({
68
- matrix: deepFreeze(integer(multiply(multiply(bInv, op.matrix), b), `Operation ${i} of ${key}`)),
69
- timeReversal: op.timeReversal,
70
- }),
71
- ),
72
- );
73
- latticeCache.set(ops, result);
74
- }
75
- return result;
76
- }
77
-
78
23
  /** The inverse of an integer matrix of determinant ±1, exactly (the adjugate). */
79
24
  function integerInverse(w: Mat3): Mat3 {
80
25
  return integer(inverse(w), 'The inverse of a lattice operation');
@@ -88,7 +33,7 @@ function indicesOf(value: unknown, name: string): readonly [number, number, numb
88
33
  !value.every((x) => typeof x === 'number' && Number.isSafeInteger(x)) ||
89
34
  value.every((x) => x === 0)
90
35
  ) {
91
- throw new RangeError(`${name} must be three (safe) integers, not all zero: ${JSON.stringify(value)}`);
36
+ throw new RangeError(`${name} must be three (safe) integers, not all zero: ${shown(value)}`);
92
37
  }
93
38
  return [value[0] + 0, value[1] + 0, value[2] + 0];
94
39
  }
@@ -97,7 +42,7 @@ function indicesOf(value: unknown, name: string): readonly [number, number, numb
97
42
  export interface FaceOrbitEntry {
98
43
  /** Miller indices (hkl) of the face, in the conventional basis (hexagonal axes: without i). */
99
44
  readonly hkl: Hkl;
100
- /** Indices into `operations` (same setting and convention) of the operations that map the given face onto this one, ascending. */
45
+ /** Indices into `operations` (same setting) of the operations that map the given face onto this one, ascending. */
101
46
  readonly operations: readonly number[];
102
47
  }
103
48
 
@@ -105,14 +50,26 @@ export interface FaceOrbitEntry {
105
50
  export interface DirectionOrbitEntry {
106
51
  /** The lattice direction [uvw] in the conventional basis. */
107
52
  readonly uvw: Uvw;
108
- /** Indices into `operations` (same setting and convention) of the operations that map the given direction onto this one, ascending. */
53
+ /** Indices into `operations` (same setting) of the operations that map the given direction onto this one, ascending. */
109
54
  readonly operations: readonly number[];
110
55
  }
111
56
 
57
+ /** A face (hkl) for `orbit`. */
58
+ export interface FaceIndices {
59
+ /** The face (hkl), three integers not all zero (hexagonal axes: three indices, without i). */
60
+ readonly hkl: Hkl;
61
+ }
62
+
63
+ /** A lattice direction [uvw] for `orbit`. */
64
+ export interface DirectionIndices {
65
+ /** The lattice direction [uvw], three integers not all zero. */
66
+ readonly uvw: Uvw;
67
+ }
68
+
112
69
  /**
113
70
  * The orbit of a face (hkl) or of a lattice direction [uvw] under a point group, exactly, in the
114
71
  * lattice basis: the distinct faces (directions), in the order in which the operations reach them
115
- * (so in the ITC convention the given face first), each with the indices of the operations that map
72
+ * (so the given face first), each with the indices of the operations that map
116
73
  * the given one onto it. A face transforms with the inverse transpose of a lattice operation,
117
74
  * h' = W⁻ᵀ·h, a direction with the operation itself, u' = W·u. The number of entries is the
118
75
  * multiplicity of the face (direction), and the operations of the first entry, if it is the given
@@ -122,31 +79,32 @@ export interface DirectionOrbitEntry {
122
79
  */
123
80
  export function orbit(
124
81
  key: MagneticPointGroupKey,
125
- indices: { readonly hkl: Hkl },
82
+ indices: FaceIndices,
126
83
  options?: SettingOptions,
127
84
  ): readonly FaceOrbitEntry[];
128
85
  export function orbit(
129
86
  key: MagneticPointGroupKey,
130
- indices: { readonly uvw: Uvw },
87
+ indices: DirectionIndices,
131
88
  options?: SettingOptions,
132
89
  ): readonly DirectionOrbitEntry[];
133
90
  export function orbit(
134
91
  key: MagneticPointGroupKey,
135
- indices: { readonly hkl: Hkl } | { readonly uvw: Uvw },
92
+ indices: FaceIndices | DirectionIndices,
136
93
  options?: SettingOptions,
137
94
  ): readonly FaceOrbitEntry[] | readonly DirectionOrbitEntry[];
138
95
  export function orbit(
139
96
  key: MagneticPointGroupKey,
140
- indices: { readonly hkl: Hkl } | { readonly uvw: Uvw },
97
+ indices: FaceIndices | DirectionIndices,
141
98
  options?: SettingOptions,
142
99
  ): readonly FaceOrbitEntry[] | readonly DirectionOrbitEntry[] {
100
+ checkOptions(options, SETTING_KEYS, 'orbit');
143
101
  const given = (indices ?? {}) as { readonly hkl?: unknown; readonly uvw?: unknown };
144
102
  const hasHkl = given.hkl !== undefined;
145
103
  const hasUvw = given.uvw !== undefined;
146
104
  if (hasHkl === hasUvw) throw new RangeError('orbit: give either hkl (a face) or uvw (a lattice direction)');
147
105
  const field = hasHkl ? 'hkl' : 'uvw';
148
106
  const v = indicesOf(hasHkl ? given.hkl : given.uvw, field);
149
- const ws = latticeOperations(key, options).map((op) => (hasHkl ? integerInverseTranspose(op.matrix) : op.matrix));
107
+ const ws = groupOperations(key, options).map((op) => (hasHkl ? integerInverseTranspose(op.matrix) : op.matrix));
150
108
  const images: { key: string; value: [number, number, number]; operations: number[] }[] = [];
151
109
  ws.forEach((w, i) => {
152
110
  const image = apply(w, v as unknown as Vec3).map((x) => x + 0) as [number, number, number];
@@ -172,15 +130,6 @@ function integerInverseTranspose(w: Mat3): Mat3 {
172
130
  return r;
173
131
  }
174
132
 
175
- /** Options of `orbitOf`. */
176
- export interface OrbitOptions {
177
- /**
178
- * Two images count as one pole if their unit vectors are closer than this (Euclidean distance).
179
- * Default 10⁻⁶; a caller whose directions carry rounding errors passes a larger value.
180
- */
181
- readonly tolerance?: number;
182
- }
183
-
184
133
  /** One pole of the orbit of a direction under a list of operations. */
185
134
  export interface OrbitPole {
186
135
  /** The image of the given direction as a Cartesian unit vector (the first operation's image where several coincide). */
@@ -193,24 +142,27 @@ export interface OrbitPole {
193
142
  * The orbit of a direction (any non-zero vector, Cartesian, e.g. a face normal) under a list of
194
143
  * operations, for instance those of a distorted crystal: the images of its unit vector under each
195
144
  * operation, coinciding images merged (closer than `tolerance`, default `EPSILON`, as for
196
- * `siteSymmetry`), in the order in which the operations reach them, each with the indices of the
145
+ * `siteSymmetryOf`), in the order in which the operations reach them, each with the indices of the
197
146
  * operations that map the direction there. The list is taken as it is, not closed into a group.
198
- * Time reversal is ignored. Throws a RangeError for a zero vector and for a matrix that is not
199
- * orthogonal (Cartesian, not one of `latticeOperations`; within `tolerance`, at least `EPSILON`).
147
+ * Time reversal is ignored. Throws a RangeError for a zero vector and for an operation without an orthogonal Cartesian matrix (`cartesian`; within `tolerance`, at least `EPSILON`).
200
148
  */
201
149
  export function orbitOf(
202
- operations: readonly { readonly matrix: Mat3 }[],
150
+ operations: readonly { readonly cartesian: Mat3 }[],
203
151
  direction: Vec3,
204
- options?: OrbitOptions,
152
+ options?: ToleranceOptions,
205
153
  ): readonly OrbitPole[] {
154
+ checkOptions(options, TOLERANCE_KEYS, 'orbitOf');
206
155
  const tolerance = siteTolerance(options);
207
- operations.forEach((op, i) => checkOrthogonalWithin(op.matrix, `Operation ${i}`, tolerance));
156
+ // Operations are checked in their own metric, at most with the bound for operations.
157
+ checkCartesianOperations(operations, Math.min(tolerance, TOLERANCE_BOUND.operations));
158
+ if (operations.length === 0) throw new RangeError('orbitOf takes a list of at least one operation');
159
+ checkNumbers(direction, 3, 'A direction');
208
160
  const n = Math.hypot(direction[0], direction[1], direction[2]);
209
- if (!(n > 0) || !Number.isFinite(n)) throw new RangeError(`Not a direction: ${JSON.stringify(direction)}`);
161
+ if (!(n > 0) || !Number.isFinite(n)) throw new RangeError(`Not a direction: ${shown(direction)}`);
210
162
  const u: Vec3 = [direction[0] / n, direction[1] / n, direction[2] / n];
211
163
  const poles: { direction: Vec3; operations: number[] }[] = [];
212
164
  operations.forEach((op, i) => {
213
- const w = apply(op.matrix, u);
165
+ const w = apply(op.cartesian, u);
214
166
  const pole = poles.find(
215
167
  (p) => Math.hypot(p.direction[0] - w[0], p.direction[1] - w[1], p.direction[2] - w[2]) < tolerance,
216
168
  );