symcrys 0.10.0 → 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 +146 -118
  15. package/dist/crystalClasses.d.ts.map +1 -1
  16. package/dist/crystalClasses.js +163 -124
  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 +9 -17
  115. package/dist/siteSymmetry.d.ts.map +1 -1
  116. package/dist/siteSymmetry.js +62 -47
  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 +12 -4
  145. package/dist/tensors/rowEchelon.d.ts.map +1 -1
  146. package/dist/tensors/rowEchelon.js +24 -11
  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 +173 -68
  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 +234 -160
  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 -69
  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 +71 -64
  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 +29 -17
  199. package/src/tensors/rowEchelon.ts +28 -9
  200. package/src/tensors/tensorForm.ts +260 -89
  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
package/src/freeze.ts ADDED
@@ -0,0 +1,14 @@
1
+ /**
2
+ * Freezing of results: every result of the API is frozen, nested arrays and objects included
3
+ * (#137 C4), so that a caller who wants to change one copies it. Internal.
4
+ */
5
+
6
+ /** `value`, frozen with everything it holds (plain arrays and objects). */
7
+ export function deepFreeze<T>(value: T): T {
8
+ if (value !== null && typeof value === 'object') {
9
+ // Also into a container that is frozen already: its children need not be.
10
+ for (const v of Object.values(value)) deepFreeze(v);
11
+ Object.freeze(value);
12
+ }
13
+ return value;
14
+ }
package/src/index.ts CHANGED
@@ -6,6 +6,7 @@
6
6
  * SemVer (see CLAUDE.md); everything else is internal.
7
7
  */
8
8
  export { VERSION } from './version.js';
9
+ export { EPSILON, type ToleranceOptions } from './tolerances.js';
9
10
 
10
11
  export type { Mat3, Vec3 } from './linalg.js';
11
12
  export {
@@ -14,10 +15,12 @@ export {
14
15
  type CrystalFamily,
15
16
  type CrystalSystem,
16
17
  type FixedAngleFamily,
18
+ type LatticeSystem,
17
19
  } from './lattice.js';
18
20
  export {
19
21
  angleBetweenDirections,
20
22
  angleBetweenPlanes,
23
+ faceNormal,
21
24
  isValidCell,
22
25
  latticeFromParameters,
23
26
  latticeParameters,
@@ -27,7 +30,6 @@ export {
27
30
  type CellOperation,
28
31
  type IsValidCellOptions,
29
32
  type LatticeParameters,
30
- type ResidualOperationsOptions,
31
33
  } from './cell.js';
32
34
  export {
33
35
  changeOfAxes,
@@ -35,21 +37,29 @@ export {
35
37
  directionToFourIndices,
36
38
  planeFromFourIndices,
37
39
  planeToFourIndices,
40
+ millerIndices,
38
41
  reduceIndices,
39
42
  zoneAxis,
40
43
  type AxisChange,
41
44
  type FourIndices,
45
+ type MillerValues,
42
46
  } from './indices.js';
43
47
 
44
- export type { Convention, PointGroupKey, Setting, SettingOptions, SymbolOptions } from './pointGroups/pointGroups.js';
48
+ export type { PointGroupKey, Setting, AxesOptions, SettingOptions, SymbolOptions } from './pointGroups/pointGroups.js';
45
49
  export { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from './symmetryDirections.js';
46
50
  export type { Axis, DirectionElements, OperationKind, SymmetryDirection } from './pointGroups/elements.js';
47
- export type { SiteSymmetry, SiteSymmetryOptions } from './siteSymmetry.js';
48
- export type { Hkl, WyckoffOptions, WyckoffPosition } from './pointGroups/wyckoff.js';
51
+ export type { SiteSymmetry } from './siteSymmetry.js';
52
+ export type { Hkl, WyckoffPosition } from './pointGroups/wyckoff.js';
49
53
  export type { CrystalForm, CrystalFormType } from './pointGroups/crystalForms.js';
50
- export type { DirectionOrbitEntry, FaceOrbitEntry, OrbitOptions, OrbitPole } from './pointGroups/orbits.js';
51
- export type { CartesianAxis, PointGroupOfOptions } from './pointGroups/identify.js';
52
- export type { IntrinsicSymmetry, TensorForm, TensorParity, TensorRank } from './tensors/tensorForm.js';
54
+ export type {
55
+ DirectionIndices,
56
+ DirectionOrbitEntry,
57
+ FaceIndices,
58
+ FaceOrbitEntry,
59
+ OrbitPole,
60
+ } from './pointGroups/orbits.js';
61
+ export type { CartesianAxis } from './pointGroups/identify.js';
62
+ export type { IntrinsicSymmetry, TensorForm, TensorKind, TensorRank } from './tensors/tensorForm.js';
53
63
 
54
64
  export {
55
65
  CRYSTAL_FORM_TYPES,
@@ -66,9 +76,9 @@ export {
66
76
  generators,
67
77
  holohedry,
68
78
  isCentrosymmetricOf,
69
- isChiralOf,
79
+ isEnantiomorphicOf,
70
80
  isPointGroupKey,
71
- latticeOperations,
81
+ latticeSystems,
72
82
  residualOperations,
73
83
  operations,
74
84
  orbit,
@@ -79,11 +89,12 @@ export {
79
89
  rotateTensor,
80
90
  settings,
81
91
  siteSymmetry,
92
+ siteSymmetryOf,
82
93
  symbol,
83
94
  symmetryDirections,
84
95
  tensorForm,
85
96
  tensorFormOf,
86
- wyckoffPositionOf,
97
+ wyckoffPosition,
87
98
  wyckoffPositions,
88
99
  type CartesianOperationDescription,
89
100
  type IdentifiedPointGroup,
package/src/indices.ts CHANGED
@@ -1,11 +1,13 @@
1
1
  /**
2
- * Miller and Miller–Bravais indices, the zone law and the change of axes
2
+ * Miller and Bravais–Miller indices, the zone law and the change of axes
3
3
  * (docs/conventions.md, "Cell, metric and indices"). Plain integers and matrices in and out.
4
4
  */
5
5
 
6
+ import { shown } from './checks.js';
6
7
  import { det, inverse, isSingular, transpose, type Mat3, type Vec3 } from './linalg.js';
8
+ import { deepFreeze } from './freeze.js';
7
9
 
8
- /** A direction [UVTW] or a plane (hkil) in four indices (Miller–Bravais). */
10
+ /** A direction [UVTW] or a plane (hkil) in four indices (Bravais–Miller). */
9
11
  export type FourIndices = readonly [number, number, number, number];
10
12
 
11
13
  function gcd(a: number, b: number): number {
@@ -22,33 +24,31 @@ function integers(v: readonly number[], who: string, length?: number): void {
22
24
  v.length === 0 ||
23
25
  !v.every((x) => Number.isSafeInteger(x))
24
26
  ) {
25
- throw new RangeError(
26
- `${who}: ${length === undefined ? 'a list of' : length} integers expected, not ${JSON.stringify(v)}`,
27
- );
27
+ throw new RangeError(`${who}: ${length === undefined ? 'a list of' : length} integers expected, not ${shown(v)}`);
28
28
  }
29
29
  }
30
30
 
31
31
  /** The indices divided by their greatest common divisor, signs kept. Throws a RangeError for non-integers and for all zeros. */
32
- export function reduceIndices(indices: readonly number[]): number[] {
32
+ export function reduceIndices(indices: readonly number[]): readonly number[] {
33
33
  integers(indices, 'reduceIndices');
34
34
  const g = indices.reduce(gcd, 0);
35
35
  if (g === 0) throw new RangeError('reduceIndices: all indices are zero');
36
- return indices.map((x) => x / g + 0);
36
+ return deepFreeze(indices.map((x) => x / g + 0));
37
37
  }
38
38
 
39
39
  /** The plane (hkl) of hexagonal axes as (hkil) with i = −(h + k). */
40
40
  export function planeToFourIndices(hkl: Vec3): FourIndices {
41
41
  integers(hkl, 'planeToFourIndices', 3);
42
42
  if (hkl.every((x) => x === 0)) throw new RangeError('planeToFourIndices: zero vector');
43
- return [hkl[0] + 0, hkl[1] + 0, -(hkl[0] + hkl[1]) + 0, hkl[2] + 0];
43
+ return deepFreeze([hkl[0] + 0, hkl[1] + 0, -(hkl[0] + hkl[1]) + 0, hkl[2] + 0]);
44
44
  }
45
45
 
46
46
  /** The plane (hkil) as (hkl); throws a RangeError unless i = −(h + k). */
47
47
  export function planeFromFourIndices(hkil: FourIndices): Vec3 {
48
48
  integers(hkil, 'planeFromFourIndices', 4);
49
49
  if (hkil[2] !== -(hkil[0] + hkil[1]))
50
- throw new RangeError(`planeFromFourIndices: i must be −(h + k) in ${JSON.stringify(hkil)}`);
51
- return [hkil[0] + 0, hkil[1] + 0, hkil[3] + 0];
50
+ throw new RangeError(`planeFromFourIndices: i must be −(h + k) in ${shown(hkil)}`);
51
+ return deepFreeze([hkil[0] + 0, hkil[1] + 0, hkil[3] + 0]);
52
52
  }
53
53
 
54
54
  /**
@@ -59,7 +59,7 @@ export function directionToFourIndices(uvw: Vec3): FourIndices {
59
59
  integers(uvw, 'directionToFourIndices', 3);
60
60
  const [u, v, w] = uvw;
61
61
  if (u === 0 && v === 0 && w === 0) throw new RangeError('directionToFourIndices: zero vector');
62
- return reduceIndices([2 * u - v, 2 * v - u, -(u + v), 3 * w]) as unknown as FourIndices;
62
+ return deepFreeze(reduceIndices([2 * u - v, 2 * v - u, -(u + v), 3 * w]) as unknown as FourIndices);
63
63
  }
64
64
 
65
65
  /** The direction [UVTW] as [uvw], reduced: u = U − T, v = V − T, w = W; throws a RangeError unless T = −(U + V). */
@@ -67,23 +67,23 @@ export function directionFromFourIndices(uvtw: FourIndices): Vec3 {
67
67
  integers(uvtw, 'directionFromFourIndices', 4);
68
68
  if (uvtw.every((x) => x === 0)) throw new RangeError('directionFromFourIndices: zero vector');
69
69
  const [U, V, T, W] = uvtw;
70
- if (T !== -(U + V)) throw new RangeError(`directionFromFourIndices: T must be −(U + V) in ${JSON.stringify(uvtw)}`);
71
- return reduceIndices([U - T, V - T, W]) as unknown as Vec3;
70
+ if (T !== -(U + V)) throw new RangeError(`directionFromFourIndices: T must be −(U + V) in ${shown(uvtw)}`);
71
+ return deepFreeze(reduceIndices([U - T, V - T, W]) as unknown as Vec3);
72
72
  }
73
73
 
74
74
  /**
75
75
  * The zone axis [uvw] of two planes (hkl), which must not be zero vectors: the solution of the zone law hu + kv + lw = 0, the
76
- * cross product h₁ × h₂ reduced (so its sign follows the order of the planes), or `null` for parallel planes.
76
+ * cross product h₁ × h₂ reduced (so its sign follows the order of the planes), or `undefined` for parallel planes.
77
77
  */
78
- export function zoneAxis(h1: Vec3, h2: Vec3): Vec3 | null {
78
+ export function zoneAxis(h1: Vec3, h2: Vec3): Vec3 | undefined {
79
79
  integers(h1, 'zoneAxis', 3);
80
80
  integers(h2, 'zoneAxis', 3);
81
81
  if (h1.every((x) => x === 0) || h2.every((x) => x === 0)) throw new RangeError('zoneAxis: zero vector');
82
82
  const c = [h1[1] * h2[2] - h1[2] * h2[1], h1[2] * h2[0] - h1[0] * h2[2], h1[0] * h2[1] - h1[1] * h2[0]];
83
83
  if (!c.every((x) => Number.isSafeInteger(x)))
84
84
  throw new RangeError('zoneAxis: the cross product exceeds the safe integers');
85
- if (c.every((x) => x === 0)) return null;
86
- return reduceIndices(c) as unknown as Vec3;
85
+ if (c.every((x) => x === 0)) return undefined;
86
+ return deepFreeze(reduceIndices(c) as unknown as Vec3);
87
87
  }
88
88
 
89
89
  /** The matrices that carry coordinates of a direction and indices of a plane to a new basis. */
@@ -113,5 +113,95 @@ export function changeOfAxes(P: Mat3): AxisChange {
113
113
  if (!(det(P) > 0)) throw new RangeError('changeOfAxes: det P must be positive (a right-handed basis)');
114
114
  if (isSingular(P)) throw new RangeError('changeOfAxes: P is singular within rounding');
115
115
  const clean = (m: Mat3): Mat3 => m.map((r) => r.map((x) => x + 0)) as unknown as Mat3; // no −0
116
- return { direction: clean(inverse(P)), plane: clean(transpose(P)) };
116
+ return deepFreeze({ direction: clean(inverse(P)), plane: clean(transpose(P)) });
117
+ }
118
+
119
+ /** The values of h, k, l substituted into printed Miller indices. */
120
+ export interface MillerValues {
121
+ /** The value of h, an integer. */
122
+ readonly h?: number;
123
+ /** The value of k, an integer. */
124
+ readonly k?: number;
125
+ /** The value of l, an integer. */
126
+ readonly l?: number;
127
+ }
128
+
129
+ /**
130
+ * One printed index as a number: a term (`h`, `-2h`, `0`, `1`) or a sum of terms (`-h-k`, `2k-h`, as
131
+ * printed for rhombohedral axes); `i` is −(h + k). `fail` makes the error: a RangeError for a
132
+ * caller's string, a plain Error for the transcribed data.
133
+ */
134
+ function printedIndex(component: string, values: MillerValues, fail: (message: string) => Error): number {
135
+ // A term is a signed number, or a signed letter with an optional factor; terms after the first
136
+ // begin with their sign, so that run-together terms (`hk`, `h2`) are unreadable.
137
+ if (!/^-?(\d+|\d*[hkil])([+-](\d+|\d*[hkil]))*$/.test(component)) throw fail(`Unreadable Miller index: ${component}`);
138
+ const terms = component.match(/[+-]?\d*[hkil]?/g)!.filter((t) => t !== '');
139
+ const value = (letter: 'h' | 'k' | 'l'): number => {
140
+ const v = values[letter];
141
+ if (v === undefined) throw fail(`The Miller index ${component} needs a value of ${letter}`);
142
+ return v;
143
+ };
144
+ const result = terms.reduce((sum, term) => {
145
+ const m = /^([+-]?)(\d*)([hkil]?)$/.exec(term)!;
146
+ const sign = m[1] === '-' ? -1 : 1;
147
+ const factor = m[2] === '' ? 1 : Number(m[2]);
148
+ if (!Number.isSafeInteger(factor)) throw fail(`The factor in ${component} is not a safe integer`);
149
+ if (m[3] === '') return sum + sign * factor;
150
+ if (m[3] === 'i') return sum + sign * factor * -(value('h') + value('k'));
151
+ return sum + sign * factor * value(m[3] as 'h' | 'k' | 'l');
152
+ }, 0);
153
+ if (!Number.isSafeInteger(result)) throw fail(`The Miller index ${component} is not a safe integer: ${result}`);
154
+ return result;
155
+ }
156
+
157
+ /**
158
+ * Printed Miller indices, three or four (Bravais–Miller, hexagonal axes) separated by commas, as
159
+ * three numbers (hkl) with the given values of h, k, l; four lose i, which must be −(h + k). Internal:
160
+ * `fail` makes the error.
161
+ */
162
+ export function substituteMillerIndices(printed: string, values: MillerValues, fail: (message: string) => Error): Vec3 {
163
+ const components = printed.split(',').map((c) => c.trim());
164
+ // i is the third of four indices; ITA prints no i among three.
165
+ if (components.length === 3 && components.some((c) => c.includes('i'))) {
166
+ throw fail(`Unreadable Miller indices: ${printed} (i among three indices)`);
167
+ }
168
+ const parts = components.map((c) => printedIndex(c, values, fail) + 0);
169
+ if (parts.length === 3) return [parts[0], parts[1], parts[2]];
170
+ if (parts.length === 4 && parts[2] === -(parts[0] + parts[1])) return [parts[0], parts[1], parts[3]];
171
+ throw fail(`Unreadable Miller indices: ${printed}`);
172
+ }
173
+
174
+ /**
175
+ * The face (hkl) of printed Miller indices with the caller's values of h, k, l substituted (#137 G3):
176
+ * the printed `h,h,-2h,l` with h = 3 and l = 1 gives (3, 3, 1). The printed strings are those of
177
+ * `wyckoffPositions` and `crystalForms` (`millerIndices`), as ITA prints them: three indices, or four
178
+ * for hexagonal axes, of which i = −(h + k) is dropped, so that the face can be passed to `orbit`
179
+ * (`planeToFourIndices` gives the four). Each value is an integer; only the letters the string uses
180
+ * are needed. The face is not reduced, and whether the values keep it in its position (a general
181
+ * face (hkl) with h = k lies on a special one) is the caller's choice. Throws a RangeError for an
182
+ * unreadable string, a missing or non-integer value, an unknown key and the face (000).
183
+ */
184
+ export function millerIndices(printed: string, values: MillerValues): Vec3 {
185
+ if (typeof printed !== 'string')
186
+ throw new RangeError(`millerIndices: printed Miller indices expected, not ${shown(printed)}`);
187
+ if (values === null || typeof values !== 'object' || Array.isArray(values)) {
188
+ throw new RangeError(`millerIndices: values { h, k, l } expected, not ${shown(values)}`);
189
+ }
190
+ for (const key of Object.keys(values)) {
191
+ if (!['h', 'k', 'l'].includes(key)) throw new RangeError(`millerIndices: unknown value ${shown(key)} (h, k or l)`);
192
+ }
193
+ // The own values only, each checked as it is read (an inherited or non-enumerable one included).
194
+ const own: { h?: number; k?: number; l?: number } = {};
195
+ for (const letter of ['h', 'k', 'l'] as const) {
196
+ if (!Object.hasOwn(values, letter)) continue;
197
+ const v: unknown = values[letter];
198
+ if (v === undefined) continue;
199
+ if (!Number.isSafeInteger(v)) throw new RangeError(`millerIndices: ${letter} must be an integer, not ${shown(v)}`);
200
+ own[letter] = v as number;
201
+ }
202
+ // Spaces around the commas are allowed; a space inside an index is unreadable.
203
+ const hkl = substituteMillerIndices(printed, own, (m) => new RangeError(`millerIndices: ${m}`));
204
+ if (hkl.every((x) => x === 0))
205
+ throw new RangeError(`millerIndices: ${printed} gives the face (000) with ${shown(values)}`);
206
+ return deepFreeze(hkl);
117
207
  }
package/src/lattice.ts CHANGED
@@ -3,6 +3,7 @@
3
3
  * of symcrys (docs/conventions.md, "Cartesian frame").
4
4
  */
5
5
 
6
+ import { shown } from './checks.js';
6
7
  import type { Mat3 } from './linalg.js';
7
8
 
8
9
  /** One of the seven crystal systems. */
@@ -12,11 +13,50 @@ export type CrystalSystem =
12
13
  /** One of the six crystal families: the trigonal and the hexagonal system form the hexagonal family. */
13
14
  export type CrystalFamily = 'triclinic' | 'monoclinic' | 'orthorhombic' | 'tetragonal' | 'hexagonal' | 'cubic';
14
15
 
15
- /** The crystal family of a crystal system: trigonal and hexagonal form the hexagonal family. */
16
+ const SYSTEMS: readonly string[] = [
17
+ 'triclinic',
18
+ 'monoclinic',
19
+ 'orthorhombic',
20
+ 'tetragonal',
21
+ 'trigonal',
22
+ 'hexagonal',
23
+ 'cubic',
24
+ ];
25
+
26
+ /**
27
+ * The crystal family of a crystal system: trigonal and hexagonal form the hexagonal family. Throws
28
+ * a RangeError for anything that is not one of the seven crystal systems.
29
+ */
16
30
  export function crystalFamily(system: CrystalSystem): CrystalFamily {
31
+ if (!SYSTEMS.includes(system)) throw new RangeError(`Unknown crystal system: ${shown(system)}`);
17
32
  return system === 'trigonal' ? 'hexagonal' : system;
18
33
  }
19
34
 
35
+ /**
36
+ * One of the seven lattice systems of ITA Table 1.3.4.1 (p. 39): the lattices whose point symmetry
37
+ * is the same holohedry. The hexagonal family has two, `'hexagonal'` (hP) and `'rhombohedral'` (hR).
38
+ */
39
+ export type LatticeSystem =
40
+ 'triclinic' | 'monoclinic' | 'orthorhombic' | 'tetragonal' | 'hexagonal' | 'rhombohedral' | 'cubic';
41
+
42
+ /**
43
+ * The lattice systems on which the point groups of a crystal system act (ITA § 1.3.4.4.2, p. 39):
44
+ * both of the hexagonal family for the trigonal system, which belongs to either depending on the
45
+ * basis, otherwise the one of the same name.
46
+ */
47
+ export function latticeSystemsOfSystem(system: CrystalSystem): readonly LatticeSystem[] {
48
+ if (!SYSTEMS.includes(system)) throw new RangeError(`Unknown crystal system: ${shown(system)}`);
49
+ if (system === 'trigonal') return TRIGONAL;
50
+ return LATTICE_SYSTEM_OF[system];
51
+ }
52
+
53
+ const TRIGONAL: readonly LatticeSystem[] = Object.freeze(['hexagonal', 'rhombohedral']);
54
+ const LATTICE_SYSTEM_OF = Object.freeze(
55
+ Object.fromEntries(
56
+ ['triclinic', 'monoclinic', 'orthorhombic', 'tetragonal', 'hexagonal', 'cubic'].map((s) => [s, Object.freeze([s])]),
57
+ ),
58
+ ) as Readonly<Record<Exclude<CrystalSystem, 'trigonal'>, readonly LatticeSystem[]>>;
59
+
20
60
  /** The families whose cell angles are fixed, so that their lattice basis is fixed up to edge lengths. */
21
61
  export type FixedAngleFamily = 'orthorhombic' | 'tetragonal' | 'hexagonal' | 'cubic';
22
62
 
package/src/linalg.ts CHANGED
@@ -105,11 +105,11 @@ export function rotationY(angleDeg: number): Mat3 {
105
105
  */
106
106
  const SNAP_VALUES = [0, 1, -1, 0.5, -0.5, Math.SQRT1_2, -Math.SQRT1_2, Math.sqrt(3) / 2, -Math.sqrt(3) / 2];
107
107
 
108
- /** Replaces each entry within SNAP_EPSILON of an exact value by that value (this also turns −0 into 0). */
109
- export function snap(a: Mat3): Mat3 {
108
+ /** Replaces each entry within `epsilon` (default SNAP_EPSILON) of an exact value by that value (this also turns −0 into 0). */
109
+ export function snap(a: Mat3, epsilon = SNAP_EPSILON): Mat3 {
110
110
  return build((i, j) => {
111
111
  const v = a[i][j];
112
- for (const s of SNAP_VALUES) if (Math.abs(v - s) < SNAP_EPSILON) return s;
112
+ for (const s of SNAP_VALUES) if (Math.abs(v - s) < epsilon) return s;
113
113
  return v;
114
114
  });
115
115
  }
package/src/magnetic.ts CHANGED
@@ -10,19 +10,22 @@
10
10
  * allows no time-odd property (docs/conventions.md, "Two entry points").
11
11
  */
12
12
  export { VERSION } from './version.js';
13
+ export { EPSILON, type ToleranceOptions } from './tolerances.js';
13
14
 
14
15
  export type { Mat3, Vec3 } from './linalg.js';
15
- export type { Operation } from './operations.js';
16
+ export type { CartesianOperation, Operation } from './operations.js';
16
17
  export {
17
18
  crystalFamily,
18
19
  latticeBasis,
19
20
  type CrystalFamily,
20
21
  type CrystalSystem,
21
22
  type FixedAngleFamily,
23
+ type LatticeSystem,
22
24
  } from './lattice.js';
23
25
  export {
24
26
  angleBetweenDirections,
25
27
  angleBetweenPlanes,
28
+ faceNormal,
26
29
  isValidCell,
27
30
  latticeFromParameters,
28
31
  latticeParameters,
@@ -32,7 +35,6 @@ export {
32
35
  type CellOperation,
33
36
  type IsValidCellOptions,
34
37
  type LatticeParameters,
35
- type ResidualOperationsOptions,
36
38
  } from './cell.js';
37
39
  export {
38
40
  changeOfAxes,
@@ -40,10 +42,12 @@ export {
40
42
  directionToFourIndices,
41
43
  planeFromFourIndices,
42
44
  planeToFourIndices,
45
+ millerIndices,
43
46
  reduceIndices,
44
47
  zoneAxis,
45
48
  type AxisChange,
46
49
  type FourIndices,
50
+ type MillerValues,
47
51
  } from './indices.js';
48
52
 
49
53
  import type {
@@ -70,18 +74,19 @@ export {
70
74
  findMagneticPointGroup as findPointGroup,
71
75
  generators,
72
76
  isMagneticPointGroupKey as isPointGroupKey,
77
+ latticeSystems,
73
78
  magneticPointGroups as pointGroups,
74
79
  operations,
75
80
  pointGroup,
76
81
  settings,
77
82
  symbol,
78
- type Convention,
79
83
  type PointGroupType,
80
84
  type Setting,
85
+ type AxesOptions,
81
86
  type SettingOptions,
82
87
  type SymbolOptions,
83
88
  } from './pointGroups/pointGroups.js';
84
- export { holohedry, isCentrosymmetricOf, isChiralOf } from './pointGroups/properties.js';
89
+ export { holohedry, isCentrosymmetricOf, isEnantiomorphicOf } from './pointGroups/properties.js';
85
90
  export { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from './symmetryDirections.js';
86
91
  export {
87
92
  describeOperations,
@@ -93,22 +98,22 @@ export {
93
98
  type SymmetryDirection,
94
99
  } from './pointGroups/elements.js';
95
100
  export { residualMagneticOperations as residualOperations, type MagneticCellOperation } from './cell.js';
96
- export { siteSymmetry, type SiteSymmetry, type SiteSymmetryOptions } from './siteSymmetry.js';
101
+ export { siteSymmetryOf, type SiteSymmetry } from './siteSymmetry.js';
102
+ export { siteSymmetry } from './pointGroups/wyckoff.js';
97
103
  export {
98
104
  describeOperationsOf,
99
105
  pointGroupOf,
100
106
  type CartesianAxis,
101
107
  type CartesianOperationDescription,
102
108
  type IdentifiedPointGroup,
103
- type PointGroupOfOptions,
104
109
  } from './pointGroups/identify.js';
105
110
  export {
106
- latticeOperations,
107
111
  orbit,
108
112
  orbitOf,
113
+ type DirectionIndices,
109
114
  type DirectionOrbitEntry,
115
+ type FaceIndices,
110
116
  type FaceOrbitEntry,
111
- type OrbitOptions,
112
117
  type OrbitPole,
113
118
  } from './pointGroups/orbits.js';
114
119
  export {
@@ -117,7 +122,7 @@ export {
117
122
  tensorFormOf,
118
123
  type IntrinsicSymmetry,
119
124
  type TensorForm,
120
- type TensorParity,
125
+ type TensorKind,
121
126
  type TensorRank,
122
127
  type TensorSpec,
123
128
  type TimeParity,
@@ -0,0 +1,73 @@
1
+ /**
2
+ * Tolerant reading of symbols (#96): the spellings of the overbar, the prime and the Schoenflies
3
+ * subscripts that occur in print, on the web and in pasted text, brought to the one spelling of
4
+ * this library before a symbol is compared (docs/conventions.md, "Reading symbols"). A pure
5
+ * normalisation: it changes how a symbol is written, never which symbol it is. Internal; shared by
6
+ * the entry points. Characters outside ASCII are written as escapes, so that none is invisible.
7
+ */
8
+
9
+ /**
10
+ * Combining overbar (U+0304) and combining overline (U+0305), and the macron (U+00AF), as the text
11
+ * layer of the ITA 2016 PDFs gives the overbar, each written after the digit it marks.
12
+ */
13
+ const OVERBAR_AFTER = /(\d)[\u0304\u0305\u00AF]/g;
14
+
15
+ /**
16
+ * An overbar written as a word before the digit it marks: `bar3`, `bar{3}`, and LaTeX's `\bar{3}`,
17
+ * `\bar 3`, `\overline{3}`. A space after the digit is kept.
18
+ */
19
+ const BAR_WORD = /\\?(?:bar|overline)\s*(?:\{\s*(\d)\s*\}|(\d))/g;
20
+
21
+ /**
22
+ * Primes: the prime (U+2032), the modifier letter prime (U+02B9) and the right single quotation
23
+ * mark (U+2019), which text editors put for an apostrophe.
24
+ */
25
+ const PRIMES = /[\u2032\u02B9\u2019]/g;
26
+
27
+ /** The minus sign (U+2212) and the hyphens (U+2010, U+2011) as the overbar `-`. */
28
+ const MINUS = /[\u2212\u2010\u2011]/g;
29
+
30
+ /** Unicode subscripts of Schoenflies symbols: the digits, h, v, i, s. */
31
+ const SUBSCRIPTS: ReadonlyMap<string, string> = new Map([
32
+ ['\u2080', '0'],
33
+ ['\u2081', '1'],
34
+ ['\u2082', '2'],
35
+ ['\u2083', '3'],
36
+ ['\u2084', '4'],
37
+ ['\u2085', '5'],
38
+ ['\u2086', '6'],
39
+ ['\u2087', '7'],
40
+ ['\u2088', '8'],
41
+ ['\u2089', '9'],
42
+ ['\u2095', 'h'],
43
+ ['\u1D65', 'v'],
44
+ ['\u1D62', 'i'],
45
+ ['\u209B', 's'],
46
+ ]);
47
+ const SUBSCRIPT = /[\u2080-\u2089\u2095\u1D65\u1D62\u209B]/g;
48
+
49
+ /** LaTeX subscripts of Schoenflies symbols: `C_{3v}`, `C_3v`. */
50
+ const LATEX_SUBSCRIPT = /_\{([^{}]*)\}|_/g;
51
+
52
+ /**
53
+ * A symbol in the spelling of this library, its spaces normalized (trimmed, every run one space):
54
+ * overbars as `-` before the digit, primes as `'`, Schoenflies subscripts as plain characters
55
+ * (Unicode subscripts, LaTeX's `_{3v}` and `_3`).
56
+ */
57
+ export function normalizeSymbol(text: string): string {
58
+ return text
59
+ .normalize('NFD')
60
+ .replace(OVERBAR_AFTER, '-$1')
61
+ .replace(BAR_WORD, (_, braced: string | undefined, bare: string | undefined) => `-${braced ?? bare}`)
62
+ .replace(PRIMES, "'")
63
+ .replace(MINUS, '-')
64
+ .replace(SUBSCRIPT, (c) => SUBSCRIPTS.get(c)!)
65
+ .replace(LATEX_SUBSCRIPT, (_, inner: string | undefined) => inner ?? '')
66
+ .trim()
67
+ .replace(/\s+/g, ' ');
68
+ }
69
+
70
+ /** A normalized symbol without spaces. */
71
+ export function compactSymbol(text: string): string {
72
+ return normalizeSymbol(text).replace(/ /g, '');
73
+ }