symcrys 0.4.0 → 0.6.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 (75) hide show
  1. package/README.md +15 -132
  2. package/dist/crystalClasses.d.ts +211 -0
  3. package/dist/crystalClasses.d.ts.map +1 -0
  4. package/dist/crystalClasses.js +295 -0
  5. package/dist/crystalClasses.js.map +1 -0
  6. package/dist/index.d.ts +11 -9
  7. package/dist/index.d.ts.map +1 -1
  8. package/dist/index.js +6 -8
  9. package/dist/index.js.map +1 -1
  10. package/dist/magnetic.d.ts +35 -0
  11. package/dist/magnetic.d.ts.map +1 -0
  12. package/dist/magnetic.js +22 -0
  13. package/dist/magnetic.js.map +1 -0
  14. package/dist/operations.d.ts +8 -0
  15. package/dist/operations.d.ts.map +1 -1
  16. package/dist/operations.js +25 -0
  17. package/dist/operations.js.map +1 -1
  18. package/dist/pointGroups/data.d.ts +34 -0
  19. package/dist/pointGroups/data.d.ts.map +1 -1
  20. package/dist/pointGroups/data.js +29 -21
  21. package/dist/pointGroups/data.js.map +1 -1
  22. package/dist/pointGroups/elements.d.ts +12 -5
  23. package/dist/pointGroups/elements.d.ts.map +1 -1
  24. package/dist/pointGroups/elements.js +6 -1
  25. package/dist/pointGroups/elements.js.map +1 -1
  26. package/dist/pointGroups/magneticData.d.ts +61 -0
  27. package/dist/pointGroups/magneticData.d.ts.map +1 -0
  28. package/dist/pointGroups/magneticData.js +180 -0
  29. package/dist/pointGroups/magneticData.js.map +1 -0
  30. package/dist/pointGroups/magneticSymbols.d.ts +22 -0
  31. package/dist/pointGroups/magneticSymbols.d.ts.map +1 -0
  32. package/dist/pointGroups/magneticSymbols.js +103 -0
  33. package/dist/pointGroups/magneticSymbols.js.map +1 -0
  34. package/dist/pointGroups/pointGroups.d.ts +94 -24
  35. package/dist/pointGroups/pointGroups.d.ts.map +1 -1
  36. package/dist/pointGroups/pointGroups.js +293 -47
  37. package/dist/pointGroups/pointGroups.js.map +1 -1
  38. package/dist/pointGroups/properties.d.ts +25 -16
  39. package/dist/pointGroups/properties.d.ts.map +1 -1
  40. package/dist/pointGroups/properties.js +46 -56
  41. package/dist/pointGroups/properties.js.map +1 -1
  42. package/dist/pointGroups/wyckoff.d.ts +2 -1
  43. package/dist/pointGroups/wyckoff.d.ts.map +1 -1
  44. package/dist/pointGroups/wyckoff.js +6 -2
  45. package/dist/pointGroups/wyckoff.js.map +1 -1
  46. package/dist/tensors/propertyTable.d.ts +35 -0
  47. package/dist/tensors/propertyTable.d.ts.map +1 -0
  48. package/dist/tensors/propertyTable.js +32 -0
  49. package/dist/tensors/propertyTable.js.map +1 -0
  50. package/dist/tensors/tensorForm.d.ts +16 -10
  51. package/dist/tensors/tensorForm.d.ts.map +1 -1
  52. package/dist/tensors/tensorForm.js +23 -24
  53. package/dist/tensors/tensorForm.js.map +1 -1
  54. package/dist/tensors/tensorProperties.d.ts +30 -0
  55. package/dist/tensors/tensorProperties.d.ts.map +1 -0
  56. package/dist/tensors/tensorProperties.js +44 -0
  57. package/dist/tensors/tensorProperties.js.map +1 -0
  58. package/dist/version.d.ts +1 -1
  59. package/dist/version.js +1 -1
  60. package/package.json +9 -26
  61. package/src/crystalClasses.ts +436 -0
  62. package/src/index.ts +32 -38
  63. package/src/magnetic.ts +87 -0
  64. package/src/operations.ts +29 -0
  65. package/src/pointGroups/data.ts +29 -21
  66. package/src/pointGroups/elements.ts +23 -7
  67. package/src/pointGroups/magneticData.ts +322 -0
  68. package/src/pointGroups/magneticSymbols.ts +110 -0
  69. package/src/pointGroups/pointGroups.ts +380 -65
  70. package/src/pointGroups/properties.ts +47 -56
  71. package/src/pointGroups/wyckoff.ts +15 -2
  72. package/src/tensors/propertyTable.ts +79 -0
  73. package/src/tensors/tensorForm.ts +34 -28
  74. package/src/tensors/tensorProperties.ts +50 -0
  75. package/src/version.ts +1 -1
@@ -0,0 +1,110 @@
1
+ /**
2
+ * Hermann–Mauguin symbols of the black-and-white point groups. The symbol of such a group in a
3
+ * given frame is the symbol of its crystal class in that frame, each position carrying a prime if
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").
7
+ */
8
+
9
+ import { matricesEqual, type Mat3, type Vec3 } from '../linalg.js';
10
+ import { crystalFamily, latticeBasis, type CrystalFamily, type CrystalSystem } from '../lattice.js';
11
+ import type { Operation } from '../operations.js';
12
+ import { LATTICE_SYMMETRY_DIRECTIONS } from '../symmetryDirections.js';
13
+
14
+ /** 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[] {
16
+ 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
+ // Monoclinic: a, b, c along x, y, z, exact for the unique axis, the only one with an element.
22
+ const b: Mat3 =
23
+ family === 'monoclinic' || family === 'triclinic'
24
+ ? [
25
+ [1, 0, 0],
26
+ [0, 1, 0],
27
+ [0, 0, 1],
28
+ ]
29
+ : latticeBasis(family);
30
+ return ordered.map(([uvw]) => [
31
+ b[0][0] * uvw[0] + b[0][1] * uvw[1] + b[0][2] * uvw[2],
32
+ b[1][0] * uvw[0] + b[1][1] * uvw[1] + b[1][2] * uvw[2],
33
+ b[2][0] * uvw[0] + b[2][1] * uvw[1] + b[2][2] * uvw[2],
34
+ ]);
35
+ }
36
+
37
+ /** Proper rotation by 360°/n about the direction u (Rodrigues' formula), times `sign`. */
38
+ function rotation(u: Vec3, n: number, sign: 1 | -1): Mat3 {
39
+ const length = Math.hypot(u[0], u[1], u[2]);
40
+ const [x, y, z] = [u[0] / length, u[1] / length, u[2] / length];
41
+ const a = (2 * Math.PI) / n;
42
+ const c = Math.cos(a);
43
+ const s = Math.sin(a);
44
+ const t = 1 - c;
45
+ const r = [
46
+ [t * x * x + c, t * x * y - s * z, t * x * z + s * y],
47
+ [t * x * y + s * z, t * y * y + c, t * y * z - s * x],
48
+ [t * x * z - s * y, t * y * z + s * x, t * z * z + c],
49
+ ];
50
+ return r.map((row) => row.map((v) => sign * v)) as unknown as Mat3;
51
+ }
52
+
53
+ /** `'` 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));
56
+ if (!op) throw new Error(`${what}: the group does not contain the operation its symbol names`);
57
+ return op.timeReversal ? "'" : '';
58
+ }
59
+
60
+ /** 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 {
62
+ if (token === '1') return token;
63
+ const parts = /^(?:(-?)([1-6]))?(\/?m)?$/.exec(token);
64
+ if (!parts || token === '') throw new Error(`${what}: unreadable position ${JSON.stringify(token)}`);
65
+ const [, bar, n, mirror] = parts;
66
+ let result = '';
67
+ if (n) {
68
+ // -1 is the inversion and needs no direction; every other axis lies along u.
69
+ if (n === '1') result = `${bar}1${prime(ops, rotation([0, 0, 1], 1, -1), what)}`;
70
+ else {
71
+ if (!u) throw new Error(`${what}: no symmetry direction for position ${token}`);
72
+ result = `${bar}${n}${prime(ops, rotation(u, Number(n), bar ? -1 : 1), what)}`;
73
+ }
74
+ }
75
+ if (mirror) {
76
+ if (!u) throw new Error(`${what}: no symmetry direction for position ${token}`);
77
+ result += `${mirror}${prime(ops, rotation(u, 2, -1), what)}`;
78
+ }
79
+ return result;
80
+ }
81
+
82
+ /** The positions of a short symbol: `N`, `-N`, `N/m`, `m`. */
83
+ function shortTokens(symbol: string): string[] {
84
+ const list = symbol.match(/-?[1-6](\/m)?|m/g) ?? [];
85
+ if (list.join('') !== symbol) throw new Error(`Unreadable symbol: ${symbol}`);
86
+ return list;
87
+ }
88
+
89
+ /**
90
+ * 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
92
+ * operations of the group in that frame.
93
+ */
94
+ export function primedSymbols(
95
+ classSymbols: { readonly short: string; readonly full: string },
96
+ system: CrystalSystem,
97
+ convention: 'itc' | 'birss',
98
+ ops: readonly Operation[],
99
+ ): { short: string; full: string } {
100
+ const family = crystalFamily(system);
101
+ const directions = positionDirections(family, convention);
102
+ const what = `Symbol ${classSymbols.short}`;
103
+ const fullTokens = classSymbols.full.split(' ');
104
+ const full = fullTokens.map((t, i) => primedToken(t, directions[i], ops, what)).join(' ');
105
+ const tokens = shortTokens(classSymbols.short);
106
+ // A monoclinic short symbol has one position: the one of the unique axis in the full symbol.
107
+ const offset = family === 'monoclinic' && tokens.length === 1 ? fullTokens.findIndex((t) => t !== '1') : 0;
108
+ const short = tokens.map((t, i) => primedToken(t, directions[i + offset], ops, what)).join('');
109
+ return { short, full };
110
+ }