symcrys 0.1.1 → 0.3.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.
- package/README.md +28 -5
- package/dist/index.d.ts +9 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/dist/lattice.d.ts +22 -0
- package/dist/lattice.d.ts.map +1 -0
- package/dist/lattice.js +43 -0
- package/dist/lattice.js.map +1 -0
- package/dist/linalg.d.ts +32 -0
- package/dist/linalg.d.ts.map +1 -0
- package/dist/linalg.js +120 -0
- package/dist/linalg.js.map +1 -0
- package/dist/operations.d.ts +30 -0
- package/dist/operations.d.ts.map +1 -0
- package/dist/operations.js +49 -0
- package/dist/operations.js.map +1 -0
- package/dist/pointGroups/data.d.ts +40 -0
- package/dist/pointGroups/data.d.ts.map +1 -0
- package/dist/pointGroups/data.js +204 -0
- package/dist/pointGroups/data.js.map +1 -0
- package/dist/pointGroups/elements.d.ts +75 -0
- package/dist/pointGroups/elements.d.ts.map +1 -0
- package/dist/pointGroups/elements.js +181 -0
- package/dist/pointGroups/elements.js.map +1 -0
- package/dist/pointGroups/itaOrder.d.ts +22 -0
- package/dist/pointGroups/itaOrder.d.ts.map +1 -0
- package/dist/pointGroups/itaOrder.js +675 -0
- package/dist/pointGroups/itaOrder.js.map +1 -0
- package/dist/pointGroups/pointGroups.d.ts +84 -0
- package/dist/pointGroups/pointGroups.d.ts.map +1 -0
- package/dist/pointGroups/pointGroups.js +229 -0
- package/dist/pointGroups/pointGroups.js.map +1 -0
- package/dist/pointGroups/properties.d.ts +18 -0
- package/dist/pointGroups/properties.d.ts.map +1 -0
- package/dist/pointGroups/properties.js +60 -0
- package/dist/pointGroups/properties.js.map +1 -0
- package/dist/pointGroups/wyckoff.d.ts +53 -0
- package/dist/pointGroups/wyckoff.d.ts.map +1 -0
- package/dist/pointGroups/wyckoff.js +189 -0
- package/dist/pointGroups/wyckoff.js.map +1 -0
- package/dist/pointGroups/wyckoffData.d.ts +24 -0
- package/dist/pointGroups/wyckoffData.d.ts.map +1 -0
- package/dist/pointGroups/wyckoffData.js +423 -0
- package/dist/pointGroups/wyckoffData.js.map +1 -0
- package/dist/siteSymmetry.d.ts +40 -0
- package/dist/siteSymmetry.d.ts.map +1 -0
- package/dist/siteSymmetry.js +57 -0
- package/dist/siteSymmetry.js.map +1 -0
- package/dist/symmetryDirections.d.ts +18 -0
- package/dist/symmetryDirections.d.ts.map +1 -0
- package/dist/symmetryDirections.js +65 -0
- package/dist/symmetryDirections.js.map +1 -0
- package/dist/tolerances.d.ts +11 -0
- package/dist/tolerances.d.ts.map +1 -0
- package/dist/tolerances.js +11 -0
- package/dist/tolerances.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +6 -4
- package/src/index.ts +49 -0
- package/src/lattice.ts +59 -0
- package/src/linalg.ts +138 -0
- package/src/operations.ts +63 -0
- package/src/pointGroups/data.ts +294 -0
- package/src/pointGroups/elements.ts +264 -0
- package/src/pointGroups/itaOrder.ts +688 -0
- package/src/pointGroups/pointGroups.ts +304 -0
- package/src/pointGroups/properties.ts +62 -0
- package/src/pointGroups/wyckoff.ts +233 -0
- package/src/pointGroups/wyckoffData.ts +437 -0
- package/src/siteSymmetry.ts +89 -0
- package/src/symmetryDirections.ts +72 -0
- package/src/tolerances.ts +12 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,294 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The 32 crystallographic point groups (crystal classes) as data: generators, settings and symbols.
|
|
3
|
+
*
|
|
4
|
+
* Generators are stored in the Birss frame (docs/conventions.md); every setting is a rotation of
|
|
5
|
+
* that frame, and the ITC settings are among them. The print anchors and their tests are listed in
|
|
6
|
+
* docs/conventions.md, "Sources"; never derive data here from symcrys output.
|
|
7
|
+
*/
|
|
8
|
+
|
|
9
|
+
import { IDENTITY, INVERSION, multiply, rotationX, rotationY, rotationZ, type Mat3 } from '../linalg.js';
|
|
10
|
+
import { operation, type Operation } from '../operations.js';
|
|
11
|
+
import type { CrystalSystem } from '../lattice.js';
|
|
12
|
+
|
|
13
|
+
/** Keys of the 32 crystal classes: the ITC short symbol of the class (docs/conventions.md, "Keys"). */
|
|
14
|
+
export const POINT_GROUP_KEYS = Object.freeze([
|
|
15
|
+
'1',
|
|
16
|
+
'-1',
|
|
17
|
+
'2',
|
|
18
|
+
'm',
|
|
19
|
+
'2/m',
|
|
20
|
+
'222',
|
|
21
|
+
'mm2',
|
|
22
|
+
'mmm',
|
|
23
|
+
'4',
|
|
24
|
+
'-4',
|
|
25
|
+
'4/m',
|
|
26
|
+
'422',
|
|
27
|
+
'4mm',
|
|
28
|
+
'-42m',
|
|
29
|
+
'4/mmm',
|
|
30
|
+
'3',
|
|
31
|
+
'-3',
|
|
32
|
+
'32',
|
|
33
|
+
'3m',
|
|
34
|
+
'-3m',
|
|
35
|
+
'6',
|
|
36
|
+
'-6',
|
|
37
|
+
'6/m',
|
|
38
|
+
'622',
|
|
39
|
+
'6mm',
|
|
40
|
+
'-6m2',
|
|
41
|
+
'6/mmm',
|
|
42
|
+
'23',
|
|
43
|
+
'm-3',
|
|
44
|
+
'432',
|
|
45
|
+
'-43m',
|
|
46
|
+
'm-3m',
|
|
47
|
+
] as const);
|
|
48
|
+
|
|
49
|
+
export type PointGroupKey = (typeof POINT_GROUP_KEYS)[number];
|
|
50
|
+
|
|
51
|
+
/** A symbol in one convention: the short symbol of the setting and the full symbol, positions separated by spaces. */
|
|
52
|
+
interface SymbolForms {
|
|
53
|
+
readonly short: string;
|
|
54
|
+
readonly full: string;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
export interface SettingData {
|
|
58
|
+
/** Orthogonal matrix s: the setting's operations are s·W·sᵀ for the stored operations W. */
|
|
59
|
+
readonly frame: Mat3;
|
|
60
|
+
/** Monoclinic: the unique axis; orthorhombic mm2: the axis of the twofold rotation. */
|
|
61
|
+
readonly uniqueAxis?: 'a' | 'b' | 'c';
|
|
62
|
+
readonly itc: SymbolForms;
|
|
63
|
+
readonly birss: SymbolForms;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
export interface PointGroupData {
|
|
67
|
+
readonly key: PointGroupKey;
|
|
68
|
+
readonly crystalSystem: CrystalSystem;
|
|
69
|
+
readonly schoenflies: string;
|
|
70
|
+
/** Generators in the stored (Birss) frame, which is setting 1. */
|
|
71
|
+
readonly generators: readonly Operation[];
|
|
72
|
+
/** Setting 1 first; its frame is the identity. */
|
|
73
|
+
readonly settings: readonly SettingData[];
|
|
74
|
+
/** The ITC default setting (1-based). The Birss default is always setting 1. */
|
|
75
|
+
readonly itcDefault: number;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
// --- Matrices in the stored (Birss) frame ---------------------------------------------------------
|
|
79
|
+
|
|
80
|
+
const ROT2_Z = rotationZ(180);
|
|
81
|
+
const ROT2_X = rotationX(180);
|
|
82
|
+
const ROT2_Y = rotationY(180);
|
|
83
|
+
const ROT4_Z = rotationZ(90);
|
|
84
|
+
const ROT3_Z = rotationZ(120);
|
|
85
|
+
const ROT6_Z = rotationZ(60);
|
|
86
|
+
const ROT4_X = rotationX(90);
|
|
87
|
+
const ROTINV4_Z = multiply(ROT4_Z, INVERSION);
|
|
88
|
+
const ROTINV3_Z = multiply(ROT3_Z, INVERSION);
|
|
89
|
+
const ROTINV6_Z = multiply(ROT6_Z, INVERSION);
|
|
90
|
+
const MIRROR_X: Mat3 = [
|
|
91
|
+
[-1, 0, 0],
|
|
92
|
+
[0, 1, 0],
|
|
93
|
+
[0, 0, 1],
|
|
94
|
+
];
|
|
95
|
+
const MIRROR_Y: Mat3 = [
|
|
96
|
+
[1, 0, 0],
|
|
97
|
+
[0, -1, 0],
|
|
98
|
+
[0, 0, 1],
|
|
99
|
+
];
|
|
100
|
+
const MIRROR_Z: Mat3 = [
|
|
101
|
+
[1, 0, 0],
|
|
102
|
+
[0, 1, 0],
|
|
103
|
+
[0, 0, -1],
|
|
104
|
+
];
|
|
105
|
+
/** Mirror with normal [1-10] (swaps x and y). */
|
|
106
|
+
const MIRROR_XY: Mat3 = [
|
|
107
|
+
[0, 1, 0],
|
|
108
|
+
[1, 0, 0],
|
|
109
|
+
[0, 0, 1],
|
|
110
|
+
];
|
|
111
|
+
/** Threefold rotation about [111], mapping the vector x to y, y to z, z to x. */
|
|
112
|
+
const ROT3_111: Mat3 = [
|
|
113
|
+
[0, 0, 1],
|
|
114
|
+
[1, 0, 0],
|
|
115
|
+
[0, 1, 0],
|
|
116
|
+
];
|
|
117
|
+
|
|
118
|
+
// --- Setting frames -------------------------------------------------------------------------------
|
|
119
|
+
|
|
120
|
+
const SAME: Mat3 = [
|
|
121
|
+
[1, 0, 0],
|
|
122
|
+
[0, 1, 0],
|
|
123
|
+
[0, 0, 1],
|
|
124
|
+
];
|
|
125
|
+
/** Monoclinic, c-unique (stored) → b-unique: z → y. Proper rotation. */
|
|
126
|
+
const MONOCLINIC_B: Mat3 = [
|
|
127
|
+
[-1, 0, 0],
|
|
128
|
+
[0, 0, 1],
|
|
129
|
+
[0, 1, 0],
|
|
130
|
+
];
|
|
131
|
+
/** Orthorhombic: the axis along z (stored) moves to x (cyclic x → y → z → x). */
|
|
132
|
+
const ORTHO_TO_A: Mat3 = [
|
|
133
|
+
[0, 0, 1],
|
|
134
|
+
[1, 0, 0],
|
|
135
|
+
[0, 1, 0],
|
|
136
|
+
];
|
|
137
|
+
/** Orthorhombic: the axis along z (stored) moves to y (cyclic x → z → y → x). */
|
|
138
|
+
const ORTHO_TO_B: Mat3 = [
|
|
139
|
+
[0, 1, 0],
|
|
140
|
+
[0, 0, 1],
|
|
141
|
+
[1, 0, 0],
|
|
142
|
+
];
|
|
143
|
+
const ROT45_Z = rotationZ(45);
|
|
144
|
+
const ROT30_Z = rotationZ(30);
|
|
145
|
+
|
|
146
|
+
// --- Helpers ---------------------------------------------------------------------------------------
|
|
147
|
+
|
|
148
|
+
const ops = (...matrices: Mat3[]): Operation[] => matrices.map(operation);
|
|
149
|
+
|
|
150
|
+
/** A setting whose symbols are the same in both conventions. */
|
|
151
|
+
function setting(frame: Mat3, short: string, full: string, uniqueAxis?: 'a' | 'b' | 'c'): SettingData {
|
|
152
|
+
const forms = { short, full };
|
|
153
|
+
return uniqueAxis ? { frame, uniqueAxis, itc: forms, birss: forms } : { frame, itc: forms, birss: forms };
|
|
154
|
+
}
|
|
155
|
+
|
|
156
|
+
/** A group with one setting whose symbols agree in both conventions. */
|
|
157
|
+
function group(
|
|
158
|
+
key: PointGroupKey,
|
|
159
|
+
crystalSystem: CrystalSystem,
|
|
160
|
+
schoenflies: string,
|
|
161
|
+
generators: Operation[],
|
|
162
|
+
full: string = key,
|
|
163
|
+
): PointGroupData {
|
|
164
|
+
return { key, crystalSystem, schoenflies, generators, settings: [setting(SAME, key, full)], itcDefault: 1 };
|
|
165
|
+
}
|
|
166
|
+
|
|
167
|
+
/**
|
|
168
|
+
* Trigonal and hexagonal groups whose two settings differ by 30° about z. Symbol position 2 means
|
|
169
|
+
* the a direction (x) in ITC and the y direction in Birss, so each frame carries, in one
|
|
170
|
+
* convention, the symbol the other convention gives to the other frame (docs/conventions.md).
|
|
171
|
+
* `secondary` is the ITC symbol with the lateral elements in the a direction; ITC's default is
|
|
172
|
+
* that frame, setting 2. Birss's default, setting 1, carries Birss's printed short symbol, the key.
|
|
173
|
+
*/
|
|
174
|
+
function trigonalPair(
|
|
175
|
+
key: PointGroupKey,
|
|
176
|
+
crystalSystem: CrystalSystem,
|
|
177
|
+
schoenflies: string,
|
|
178
|
+
generators: Operation[],
|
|
179
|
+
secondary: SymbolForms,
|
|
180
|
+
tertiary: SymbolForms,
|
|
181
|
+
): PointGroupData {
|
|
182
|
+
return {
|
|
183
|
+
key,
|
|
184
|
+
crystalSystem,
|
|
185
|
+
schoenflies,
|
|
186
|
+
generators,
|
|
187
|
+
settings: [
|
|
188
|
+
{ frame: SAME, itc: tertiary, birss: { short: key, full: secondary.full } },
|
|
189
|
+
{ frame: ROT30_Z, itc: secondary, birss: tertiary },
|
|
190
|
+
],
|
|
191
|
+
itcDefault: 2,
|
|
192
|
+
};
|
|
193
|
+
}
|
|
194
|
+
|
|
195
|
+
function monoclinic(key: PointGroupKey, schoenflies: string, generators: Operation[], full: (axis: string) => string) {
|
|
196
|
+
const data: PointGroupData = {
|
|
197
|
+
key,
|
|
198
|
+
crystalSystem: 'monoclinic',
|
|
199
|
+
schoenflies,
|
|
200
|
+
generators,
|
|
201
|
+
settings: [setting(SAME, key, full('c'), 'c'), setting(MONOCLINIC_B, key, full('b'), 'b')],
|
|
202
|
+
itcDefault: 2,
|
|
203
|
+
};
|
|
204
|
+
return data;
|
|
205
|
+
}
|
|
206
|
+
|
|
207
|
+
// --- The 32 crystal classes -----------------------------------------------------------------------
|
|
208
|
+
|
|
209
|
+
export const POINT_GROUP_DATA: readonly PointGroupData[] = [
|
|
210
|
+
group('1', 'triclinic', 'C1', ops(IDENTITY)),
|
|
211
|
+
group('-1', 'triclinic', 'Ci', ops(INVERSION)),
|
|
212
|
+
|
|
213
|
+
monoclinic('2', 'C2', ops(ROT2_Z), (u) => (u === 'c' ? '1 1 2' : '1 2 1')),
|
|
214
|
+
monoclinic('m', 'Cs', ops(MIRROR_Z), (u) => (u === 'c' ? '1 1 m' : '1 m 1')),
|
|
215
|
+
monoclinic('2/m', 'C2h', ops(ROT2_Z, INVERSION), (u) => (u === 'c' ? '1 1 2/m' : '1 2/m 1')),
|
|
216
|
+
|
|
217
|
+
group('222', 'orthorhombic', 'D2', ops(ROT2_Z, ROT2_X), '2 2 2'),
|
|
218
|
+
{
|
|
219
|
+
key: 'mm2',
|
|
220
|
+
crystalSystem: 'orthorhombic',
|
|
221
|
+
schoenflies: 'C2v',
|
|
222
|
+
generators: ops(ROT2_Z, MIRROR_X),
|
|
223
|
+
settings: [
|
|
224
|
+
setting(SAME, 'mm2', 'm m 2', 'c'),
|
|
225
|
+
setting(ORTHO_TO_A, '2mm', '2 m m', 'a'),
|
|
226
|
+
setting(ORTHO_TO_B, 'm2m', 'm 2 m', 'b'),
|
|
227
|
+
],
|
|
228
|
+
itcDefault: 1,
|
|
229
|
+
},
|
|
230
|
+
group('mmm', 'orthorhombic', 'D2h', ops(ROT2_Z, ROT2_X, INVERSION), '2/m 2/m 2/m'),
|
|
231
|
+
|
|
232
|
+
group('4', 'tetragonal', 'C4', ops(ROT4_Z)),
|
|
233
|
+
group('-4', 'tetragonal', 'S4', ops(ROTINV4_Z)),
|
|
234
|
+
group('4/m', 'tetragonal', 'C4h', ops(ROT4_Z, INVERSION)),
|
|
235
|
+
group('422', 'tetragonal', 'D4', ops(ROT4_Z, ROT2_X), '4 2 2'),
|
|
236
|
+
group('4mm', 'tetragonal', 'C4v', ops(ROT4_Z, MIRROR_X), '4 m m'),
|
|
237
|
+
{
|
|
238
|
+
key: '-42m',
|
|
239
|
+
crystalSystem: 'tetragonal',
|
|
240
|
+
schoenflies: 'D2d',
|
|
241
|
+
generators: ops(ROTINV4_Z, ROT2_X),
|
|
242
|
+
settings: [setting(SAME, '-42m', '-4 2 m'), setting(ROT45_Z, '-4m2', '-4 m 2')],
|
|
243
|
+
itcDefault: 1,
|
|
244
|
+
},
|
|
245
|
+
group('4/mmm', 'tetragonal', 'D4h', ops(ROT4_Z, ROT2_X, INVERSION), '4/m 2/m 2/m'),
|
|
246
|
+
|
|
247
|
+
group('3', 'trigonal', 'C3', ops(ROT3_Z)),
|
|
248
|
+
group('-3', 'trigonal', 'C3i', ops(ROTINV3_Z)),
|
|
249
|
+
trigonalPair(
|
|
250
|
+
'32',
|
|
251
|
+
'trigonal',
|
|
252
|
+
'D3',
|
|
253
|
+
ops(ROT3_Z, ROT2_Y),
|
|
254
|
+
{ short: '321', full: '3 2 1' },
|
|
255
|
+
{ short: '312', full: '3 1 2' },
|
|
256
|
+
),
|
|
257
|
+
trigonalPair(
|
|
258
|
+
'3m',
|
|
259
|
+
'trigonal',
|
|
260
|
+
'C3v',
|
|
261
|
+
ops(ROT3_Z, MIRROR_Y),
|
|
262
|
+
{ short: '3m1', full: '3 m 1' },
|
|
263
|
+
{ short: '31m', full: '3 1 m' },
|
|
264
|
+
),
|
|
265
|
+
trigonalPair(
|
|
266
|
+
'-3m',
|
|
267
|
+
'trigonal',
|
|
268
|
+
'D3d',
|
|
269
|
+
ops(ROT3_Z, ROT2_Y, INVERSION),
|
|
270
|
+
{ short: '-3m1', full: '-3 2/m 1' },
|
|
271
|
+
{ short: '-31m', full: '-3 1 2/m' },
|
|
272
|
+
),
|
|
273
|
+
|
|
274
|
+
group('6', 'hexagonal', 'C6', ops(ROT6_Z)),
|
|
275
|
+
group('-6', 'hexagonal', 'C3h', ops(ROTINV6_Z)),
|
|
276
|
+
group('6/m', 'hexagonal', 'C6h', ops(ROT6_Z, INVERSION)),
|
|
277
|
+
group('622', 'hexagonal', 'D6', ops(ROT6_Z, ROT2_Y), '6 2 2'),
|
|
278
|
+
group('6mm', 'hexagonal', 'C6v', ops(ROT6_Z, MIRROR_Y), '6 m m'),
|
|
279
|
+
trigonalPair(
|
|
280
|
+
'-6m2',
|
|
281
|
+
'hexagonal',
|
|
282
|
+
'D3h',
|
|
283
|
+
ops(ROTINV6_Z, MIRROR_Y),
|
|
284
|
+
{ short: '-6m2', full: '-6 m 2' },
|
|
285
|
+
{ short: '-62m', full: '-6 2 m' },
|
|
286
|
+
),
|
|
287
|
+
group('6/mmm', 'hexagonal', 'D6h', ops(ROT6_Z, ROT2_Y, INVERSION), '6/m 2/m 2/m'),
|
|
288
|
+
|
|
289
|
+
group('23', 'cubic', 'T', ops(ROT2_Z, ROT2_X, ROT3_111), '2 3'),
|
|
290
|
+
group('m-3', 'cubic', 'Th', ops(ROT2_Z, ROT2_X, ROT3_111, INVERSION), '2/m -3'),
|
|
291
|
+
group('432', 'cubic', 'O', ops(ROT4_Z, ROT4_X, ROT3_111), '4 3 2'),
|
|
292
|
+
group('-43m', 'cubic', 'Td', ops(ROTINV4_Z, ROT3_111, MIRROR_XY), '-4 3 m'),
|
|
293
|
+
group('m-3m', 'cubic', 'Oh', ops(ROT4_Z, ROT4_X, ROT3_111, INVERSION), '4/m -3 2/m'),
|
|
294
|
+
];
|
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The geometry of a point group's operations: what each operation is (rotation, mirror, …), about
|
|
3
|
+
* which axis and in which sense, and which symmetry elements lie along each symmetry direction of
|
|
4
|
+
* the full Hermann–Mauguin symbol. Structured data only; symbols such as `3⁺ x,x,x` or `2_z` are
|
|
5
|
+
* left to the applications (docs/conventions.md, "Symmetry directions and elements").
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import { det, trace, type Mat3, type Vec3 } from '../linalg.js';
|
|
9
|
+
import { crystalFamily, latticeBasis, type CrystalFamily } from '../lattice.js';
|
|
10
|
+
import type { Operation } from '../operations.js';
|
|
11
|
+
import { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from '../symmetryDirections.js';
|
|
12
|
+
import {
|
|
13
|
+
operations,
|
|
14
|
+
pointGroup,
|
|
15
|
+
symbol,
|
|
16
|
+
type Convention,
|
|
17
|
+
type PointGroupKey,
|
|
18
|
+
type SettingOptions,
|
|
19
|
+
} from './pointGroups.js';
|
|
20
|
+
|
|
21
|
+
/** What a point operation is; a rotoinversion n̄ is the inversion times the rotation n (n = 3, 4, 6). */
|
|
22
|
+
export type OperationKind = 'identity' | 'inversion' | 'rotation' | 'rotoinversion' | 'mirror';
|
|
23
|
+
|
|
24
|
+
/** A symmetry direction: as a lattice direction [uvw] and as a Cartesian unit vector. */
|
|
25
|
+
export interface Axis {
|
|
26
|
+
/**
|
|
27
|
+
* Integer coordinates in the conventional basis. ITC convention: sign as in ITA Table 2.1.3.1;
|
|
28
|
+
* Birss convention, in `describeOperations`: first non-zero Cartesian component positive.
|
|
29
|
+
*/
|
|
30
|
+
readonly lattice: Uvw;
|
|
31
|
+
/**
|
|
32
|
+
* Unit vector in the Cartesian frame of symcrys. Monoclinic: a, b, c taken along x, y, z, exact for
|
|
33
|
+
* the unique axis only (docs/conventions.md, "Symmetry directions and elements").
|
|
34
|
+
*/
|
|
35
|
+
readonly cartesian: Vec3;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/** One point operation described geometrically. */
|
|
39
|
+
export interface OperationDescription {
|
|
40
|
+
readonly kind: OperationKind;
|
|
41
|
+
/**
|
|
42
|
+
* The n of the symbol n or n̄: 1 for the identity and the inversion, 2 for a mirror (m = 2̄),
|
|
43
|
+
* otherwise the order of the rotation part.
|
|
44
|
+
*/
|
|
45
|
+
readonly order: number;
|
|
46
|
+
/** Rotation axis, rotoinversion axis or mirror normal; absent for the identity and the inversion. */
|
|
47
|
+
readonly axis?: Axis;
|
|
48
|
+
/**
|
|
49
|
+
* For n ≥ 3: `'+'` if the rotation part turns by +360°/n about `axis` (counter-clockwise seen
|
|
50
|
+
* from the tip of `axis` looking towards the origin), `'-'` if by −360°/n.
|
|
51
|
+
*/
|
|
52
|
+
readonly sense?: '+' | '-';
|
|
53
|
+
readonly timeReversal: boolean;
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
/** The symmetry elements along one symmetry direction. */
|
|
57
|
+
export interface DirectionElements extends Axis {
|
|
58
|
+
/** Highest n of a rotation n about this direction; 1 if there is none. */
|
|
59
|
+
readonly rotation: number;
|
|
60
|
+
/** Highest n of a rotoinversion n̄ (n = 3, 4, 6) about this direction; 0 if there is none. */
|
|
61
|
+
readonly rotoinversion: number;
|
|
62
|
+
/** True if a mirror plane is perpendicular to this direction. */
|
|
63
|
+
readonly mirror: boolean;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
/** One position of the full Hermann–Mauguin symbol: its symbol and its symmetry directions. */
|
|
67
|
+
export interface SymmetryDirection {
|
|
68
|
+
/** 1-based position in the full symbol. */
|
|
69
|
+
readonly position: number;
|
|
70
|
+
/** The symbol at this position of the full symbol, if the full symbol has this position. */
|
|
71
|
+
readonly symbol?: string;
|
|
72
|
+
readonly directions: readonly DirectionElements[];
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
const AXIS_TOLERANCE = 1e-6;
|
|
76
|
+
|
|
77
|
+
function normalize(v: Vec3): Vec3 {
|
|
78
|
+
const n = Math.hypot(v[0], v[1], v[2]);
|
|
79
|
+
return [v[0] / n, v[1] / n, v[2] / n];
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
const dot = (a: Vec3, b: Vec3): number => a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* The basis used to turn [uvw] into a Cartesian direction. Monoclinic and triclinic have no fixed
|
|
86
|
+
* basis (`latticeBasis`); there the axes a, b, c are taken along x, y, z, which is exact for the
|
|
87
|
+
* monoclinic unique axis, the only symmetry direction that carries an element in a symcrys frame.
|
|
88
|
+
*/
|
|
89
|
+
function basisOf(family: CrystalFamily): Mat3 {
|
|
90
|
+
if (family === 'monoclinic' || family === 'triclinic')
|
|
91
|
+
return [
|
|
92
|
+
[1, 0, 0],
|
|
93
|
+
[0, 1, 0],
|
|
94
|
+
[0, 0, 1],
|
|
95
|
+
];
|
|
96
|
+
return latticeBasis(family);
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function axisOf(family: CrystalFamily, uvw: Uvw): Axis {
|
|
100
|
+
const b = basisOf(family);
|
|
101
|
+
const v: Vec3 = [
|
|
102
|
+
b[0][0] * uvw[0] + b[0][1] * uvw[1] + b[0][2] * uvw[2],
|
|
103
|
+
b[1][0] * uvw[0] + b[1][1] * uvw[1] + b[1][2] * uvw[2],
|
|
104
|
+
b[2][0] * uvw[0] + b[2][1] * uvw[1] + b[2][2] * uvw[2],
|
|
105
|
+
];
|
|
106
|
+
return Object.freeze({ lattice: uvw, cartesian: Object.freeze(normalize(v)) as unknown as Vec3 });
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* The symmetry directions of a family, per position of the full symbol, in the reading of a
|
|
111
|
+
* convention. Birss reads position 2 of the hexagonal family along y, a tertiary direction, and
|
|
112
|
+
* position 3 along x, a secondary one (docs/conventions.md, "Where ITC and Birss differ").
|
|
113
|
+
*/
|
|
114
|
+
function positionsOf(family: CrystalFamily, c: Convention): readonly (readonly Uvw[])[] {
|
|
115
|
+
const p = LATTICE_SYMMETRY_DIRECTIONS[family];
|
|
116
|
+
return c === 'birss' && family === 'hexagonal' ? [p[0], p[2], p[1]] : p;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
/** The proper rotation part of a matrix and its order n (1 for the identity). */
|
|
120
|
+
function rotationPart(m: Mat3): { r: Mat3; n: number } {
|
|
121
|
+
const r = det(m) > 0 ? m : (m.map((row) => row.map((v) => -v)) as unknown as Mat3);
|
|
122
|
+
const cos = Math.max(-1, Math.min(1, (trace(r) - 1) / 2));
|
|
123
|
+
const angle = Math.acos(cos);
|
|
124
|
+
const n = angle < 1e-6 ? 1 : Math.round((2 * Math.PI) / angle);
|
|
125
|
+
if (![1, 2, 3, 4, 6].includes(n)) throw new Error(`Not a crystallographic operation (rotation order ${n})`);
|
|
126
|
+
return { r, n };
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/** The axis of a proper rotation of order n ≥ 2 (sign arbitrary for n = 2). */
|
|
130
|
+
function rotationAxis(r: Mat3, n: number): Vec3 {
|
|
131
|
+
if (n === 2) {
|
|
132
|
+
// r + 1 has rank 1; its columns are parallel to the axis.
|
|
133
|
+
let best: Vec3 = [0, 0, 0];
|
|
134
|
+
let size = 0;
|
|
135
|
+
for (let j = 0; j < 3; j++) {
|
|
136
|
+
const col: Vec3 = [r[0][j] + (j === 0 ? 1 : 0), r[1][j] + (j === 1 ? 1 : 0), r[2][j] + (j === 2 ? 1 : 0)];
|
|
137
|
+
const l = Math.hypot(col[0], col[1], col[2]);
|
|
138
|
+
if (l > size) {
|
|
139
|
+
size = l;
|
|
140
|
+
best = col;
|
|
141
|
+
}
|
|
142
|
+
}
|
|
143
|
+
return normalize(best);
|
|
144
|
+
}
|
|
145
|
+
return normalize(axialVector(r));
|
|
146
|
+
}
|
|
147
|
+
|
|
148
|
+
/** (r − rᵀ)/2 as a vector: sin θ times the unit axis for a rotation by θ. */
|
|
149
|
+
const axialVector = (r: Mat3): Vec3 => [(r[2][1] - r[1][2]) / 2, (r[0][2] - r[2][0]) / 2, (r[1][0] - r[0][1]) / 2];
|
|
150
|
+
|
|
151
|
+
function findAxis(axes: readonly Axis[], u: Vec3, what: string): Axis {
|
|
152
|
+
const a = axes.find((x) => Math.abs(Math.abs(dot(x.cartesian, u)) - 1) < AXIS_TOLERANCE);
|
|
153
|
+
if (!a) throw new Error(`${what}: axis [${u.map((v) => v.toFixed(4)).join(', ')}] is not a symmetry direction`);
|
|
154
|
+
return a;
|
|
155
|
+
}
|
|
156
|
+
|
|
157
|
+
function describe(op: Operation, axes: readonly Axis[], what: string): OperationDescription {
|
|
158
|
+
const proper = det(op.matrix) > 0;
|
|
159
|
+
const { r, n } = rotationPart(op.matrix);
|
|
160
|
+
const timeReversal = op.timeReversal;
|
|
161
|
+
if (n === 1) return Object.freeze({ kind: proper ? 'identity' : 'inversion', order: 1, timeReversal });
|
|
162
|
+
const axis = findAxis(axes, rotationAxis(r, n), what);
|
|
163
|
+
const kind: OperationKind = proper ? 'rotation' : n === 2 ? 'mirror' : 'rotoinversion';
|
|
164
|
+
if (n === 2) return Object.freeze({ kind, order: 2, axis, timeReversal });
|
|
165
|
+
const sense = dot(axialVector(r), axis.cartesian) > 0 ? '+' : '-';
|
|
166
|
+
return Object.freeze({ kind, order: n, axis, sense, timeReversal });
|
|
167
|
+
}
|
|
168
|
+
|
|
169
|
+
interface Analysis {
|
|
170
|
+
readonly descriptions: readonly OperationDescription[];
|
|
171
|
+
readonly directions: readonly SymmetryDirection[];
|
|
172
|
+
}
|
|
173
|
+
|
|
174
|
+
const cache = new Map<string, Analysis>();
|
|
175
|
+
|
|
176
|
+
function analysis(key: PointGroupKey, options?: SettingOptions): Analysis {
|
|
177
|
+
const ops = operations(key, options); // checks key, convention and setting
|
|
178
|
+
const c = options?.convention ?? 'itc';
|
|
179
|
+
const setting = options?.setting ?? 0;
|
|
180
|
+
const cacheKey = `${key}#${setting}#${c}`;
|
|
181
|
+
const hit = cache.get(cacheKey);
|
|
182
|
+
if (hit) return hit;
|
|
183
|
+
|
|
184
|
+
const family = crystalFamily(pointGroup(key).crystalSystem);
|
|
185
|
+
const positions = positionsOf(family, c).map((dirs) => dirs.map((d) => axisOf(family, d)));
|
|
186
|
+
const all = positions.flat();
|
|
187
|
+
const what = `Point group ${key}`;
|
|
188
|
+
const descriptions = Object.freeze(ops.map((op) => describe(op, all, what)));
|
|
189
|
+
|
|
190
|
+
const tokens = family === 'triclinic' ? [] : symbol(key, { ...options, form: 'full' }).split(' ');
|
|
191
|
+
const directions = Object.freeze(
|
|
192
|
+
positions.map((axes, i) => {
|
|
193
|
+
const elements = axes.map((a) => {
|
|
194
|
+
const on = descriptions.filter((d) => d.axis === a);
|
|
195
|
+
const max = (kind: OperationKind, none: number) =>
|
|
196
|
+
on.filter((d) => d.kind === kind).reduce((m, d) => Math.max(m, d.order), none);
|
|
197
|
+
return Object.freeze({
|
|
198
|
+
...a,
|
|
199
|
+
rotation: max('rotation', 1),
|
|
200
|
+
rotoinversion: max('rotoinversion', 0),
|
|
201
|
+
mirror: on.some((d) => d.kind === 'mirror'),
|
|
202
|
+
});
|
|
203
|
+
});
|
|
204
|
+
const position: SymmetryDirection =
|
|
205
|
+
tokens[i] === undefined
|
|
206
|
+
? { position: i + 1, directions: Object.freeze(elements) }
|
|
207
|
+
: { position: i + 1, symbol: tokens[i], directions: Object.freeze(elements) };
|
|
208
|
+
return Object.freeze(position);
|
|
209
|
+
}),
|
|
210
|
+
);
|
|
211
|
+
const result = {
|
|
212
|
+
descriptions: c === 'birss' ? Object.freeze(descriptions.map(birssSigned)) : descriptions,
|
|
213
|
+
directions,
|
|
214
|
+
};
|
|
215
|
+
cache.set(cacheKey, result);
|
|
216
|
+
return result;
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
const flipped = new Map<Axis, Axis>();
|
|
220
|
+
|
|
221
|
+
/**
|
|
222
|
+
* The description with the axis signed as in birss-app (docs/conventions.md, "Birss convention and
|
|
223
|
+
* birss-app"): its first non-zero Cartesian component, in the order x, y, z, is positive. If the
|
|
224
|
+
* axis of ITA Table 2.1.3.1 points the other way, axis and sense are reversed; the rotation stays
|
|
225
|
+
* the same.
|
|
226
|
+
*/
|
|
227
|
+
function birssSigned(d: OperationDescription): OperationDescription {
|
|
228
|
+
const a = d.axis;
|
|
229
|
+
if (!a) return d;
|
|
230
|
+
const first = a.cartesian.find((x) => Math.abs(x) > 1e-9) ?? 0;
|
|
231
|
+
if (first > 0) return d;
|
|
232
|
+
let axis = flipped.get(a);
|
|
233
|
+
if (!axis) {
|
|
234
|
+
axis = Object.freeze({
|
|
235
|
+
lattice: Object.freeze(a.lattice.map((x) => (x === 0 ? 0 : -x))) as unknown as Uvw,
|
|
236
|
+
cartesian: Object.freeze(a.cartesian.map((x) => (x === 0 ? 0 : -x))) as unknown as Vec3,
|
|
237
|
+
});
|
|
238
|
+
flipped.set(a, axis);
|
|
239
|
+
}
|
|
240
|
+
const sense = d.sense === '+' ? '-' : d.sense === '-' ? '+' : undefined;
|
|
241
|
+
return Object.freeze({ ...d, axis, ...(sense ? { sense } : {}) });
|
|
242
|
+
}
|
|
243
|
+
|
|
244
|
+
/**
|
|
245
|
+
* Each operation of the point group described geometrically, in the order of `operations` for
|
|
246
|
+
* the same key and options. Axes are named by the symmetry direction they lie along: in the ITC
|
|
247
|
+
* convention with the sign of ITA Table 2.1.3.1, in the Birss convention signed as birss-app signs
|
|
248
|
+
* them (first non-zero Cartesian component positive); the sign fixes what the sense refers to.
|
|
249
|
+
*/
|
|
250
|
+
export function describeOperations(key: PointGroupKey, options?: SettingOptions): readonly OperationDescription[] {
|
|
251
|
+
return analysis(key, options).descriptions;
|
|
252
|
+
}
|
|
253
|
+
|
|
254
|
+
/**
|
|
255
|
+
* The positions of the full Hermann–Mauguin symbol in the requested convention and setting, each
|
|
256
|
+
* with its symmetry directions (ITA Table 2.1.3.1) and the symmetry elements along them. All
|
|
257
|
+
* positions of the crystal family are listed, also those the symbol of the class leaves out (then
|
|
258
|
+
* without `symbol`); the triclinic family has none. The directions keep the sign of Table 2.1.3.1
|
|
259
|
+
* in both conventions; in the Birss convention an axis of `describeOperations` may be reversed, so
|
|
260
|
+
* match it to a direction by |dot| = 1, not by identity.
|
|
261
|
+
*/
|
|
262
|
+
export function symmetryDirections(key: PointGroupKey, options?: SettingOptions): readonly SymmetryDirection[] {
|
|
263
|
+
return analysis(key, options).directions;
|
|
264
|
+
}
|