symcrys 0.8.1 → 0.9.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 (50) hide show
  1. package/README.md +11 -2
  2. package/dist/plane.d.ts +225 -0
  3. package/dist/plane.d.ts.map +1 -0
  4. package/dist/plane.js +219 -0
  5. package/dist/plane.js.map +1 -0
  6. package/dist/spaceGroups/affine.d.ts +81 -0
  7. package/dist/spaceGroups/affine.d.ts.map +1 -0
  8. package/dist/spaceGroups/affine.js +245 -0
  9. package/dist/spaceGroups/affine.js.map +1 -0
  10. package/dist/spaceGroups/cell.d.ts +58 -0
  11. package/dist/spaceGroups/cell.d.ts.map +1 -0
  12. package/dist/spaceGroups/cell.js +297 -0
  13. package/dist/spaceGroups/cell.js.map +1 -0
  14. package/dist/spaceGroups/describe.d.ts +44 -0
  15. package/dist/spaceGroups/describe.d.ts.map +1 -0
  16. package/dist/spaceGroups/describe.js +92 -0
  17. package/dist/spaceGroups/describe.js.map +1 -0
  18. package/dist/spaceGroups/planeGroupData.d.ts +44 -0
  19. package/dist/spaceGroups/planeGroupData.d.ts.map +1 -0
  20. package/dist/spaceGroups/planeGroupData.js +371 -0
  21. package/dist/spaceGroups/planeGroupData.js.map +1 -0
  22. package/dist/spaceGroups/planeGroups.d.ts +28 -0
  23. package/dist/spaceGroups/planeGroups.d.ts.map +1 -0
  24. package/dist/spaceGroups/planeGroups.js +61 -0
  25. package/dist/spaceGroups/planeGroups.js.map +1 -0
  26. package/dist/spaceGroups/planePointGroups.d.ts +31 -0
  27. package/dist/spaceGroups/planePointGroups.d.ts.map +1 -0
  28. package/dist/spaceGroups/planePointGroups.js +77 -0
  29. package/dist/spaceGroups/planePointGroups.js.map +1 -0
  30. package/dist/spaceGroups/positions.d.ts +65 -0
  31. package/dist/spaceGroups/positions.d.ts.map +1 -0
  32. package/dist/spaceGroups/positions.js +183 -0
  33. package/dist/spaceGroups/positions.js.map +1 -0
  34. package/dist/spaceGroups/rational.d.ts +43 -0
  35. package/dist/spaceGroups/rational.d.ts.map +1 -0
  36. package/dist/spaceGroups/rational.js +95 -0
  37. package/dist/spaceGroups/rational.js.map +1 -0
  38. package/dist/version.d.ts +1 -1
  39. package/dist/version.js +1 -1
  40. package/package.json +7 -2
  41. package/src/plane.ts +455 -0
  42. package/src/spaceGroups/affine.ts +315 -0
  43. package/src/spaceGroups/cell.ts +371 -0
  44. package/src/spaceGroups/describe.ts +133 -0
  45. package/src/spaceGroups/planeGroupData.ts +407 -0
  46. package/src/spaceGroups/planeGroups.ts +75 -0
  47. package/src/spaceGroups/planePointGroups.ts +90 -0
  48. package/src/spaceGroups/positions.ts +237 -0
  49. package/src/spaceGroups/rational.ts +115 -0
  50. package/src/version.ts +1 -1
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rational.js","sourceRoot":"","sources":["../../src/spaceGroups/rational.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAKH,sBAAsB;AACtB,MAAM,CAAC,MAAM,IAAI,GAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAErC,sBAAsB;AACtB,MAAM,CAAC,MAAM,GAAG,GAAa,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC;AAEpC,SAAS,GAAG,CAAC,CAAS,EAAE,CAAS;IAC/B,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB,IAAI,CAAC,GAAG,IAAI,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC;IACpB,OAAO,CAAC,KAAK,CAAC,EAAE,CAAC;QACf,CAAC,CAAC,EAAE,CAAC,CAAC,GAAG,CAAC,CAAC,EAAE,CAAC,GAAG,CAAC,CAAC,CAAC;IACtB,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,+CAA+C;AAC/C,MAAM,UAAU,gBAAgB,CAAC,KAAa,EAAE,IAAY;IAC1D,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC,KAAK,CAAC,EAAE,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,5 +3,5 @@
3
3
  *
4
4
  * @remarks Kept equal to `version` in package.json (checked by version.test.ts).
5
5
  */
6
- export declare const VERSION = "0.8.1";
6
+ export declare const VERSION = "0.9.0";
7
7
  //# sourceMappingURL=version.d.ts.map
package/dist/version.js CHANGED
@@ -3,5 +3,5 @@
3
3
  *
4
4
  * @remarks Kept equal to `version` in package.json (checked by version.test.ts).
5
5
  */
6
- export const VERSION = '0.8.1';
6
+ export const VERSION = '0.9.0';
7
7
  //# sourceMappingURL=version.js.map
package/package.json CHANGED
@@ -1,12 +1,13 @@
1
1
  {
2
2
  "name": "symcrys",
3
- "version": "0.8.1",
4
- "description": "Crystallographic symmetry calculations: point groups (crystallographic and magnetic), their settings, symbols and properties, and property tensors. TypeScript library without dependencies.",
3
+ "version": "0.9.0",
4
+ "description": "Crystallographic symmetry calculations: point groups (crystallographic and magnetic) and plane groups, their settings, symbols and properties, and property tensors. TypeScript library without dependencies.",
5
5
  "keywords": [
6
6
  "crystallography",
7
7
  "symmetry",
8
8
  "point-groups",
9
9
  "magnetic-point-groups",
10
+ "plane-groups",
10
11
  "tensors"
11
12
  ],
12
13
  "author": "Thomas Lottermoser",
@@ -28,6 +29,10 @@
28
29
  "types": "./dist/magnetic.d.ts",
29
30
  "default": "./dist/magnetic.js"
30
31
  },
32
+ "./plane": {
33
+ "types": "./dist/plane.d.ts",
34
+ "default": "./dist/plane.js"
35
+ },
31
36
  "./package.json": "./package.json"
32
37
  },
33
38
  "main": "./dist/index.js",
package/src/plane.ts ADDED
@@ -0,0 +1,455 @@
1
+ /**
2
+ * The plane API of symcrys (`symcrys/plane`): the 17 plane groups and the 10 plane point groups, in
3
+ * the lattice basis, as ITA (6th ed., 2016) prints them in Chapter 2.2 and Table 3.2.1.1.
4
+ * Everything exported here is covered by SemVer (see CLAUDE.md), like the exports of `index.ts`.
5
+ *
6
+ * Inside, the operations are exact (integer matrices, rational translations); here they are plain
7
+ * numbers: a translation of 1/3 is the nearest double. Keys are the symbols ITA prints: `'p2mg'`,
8
+ * `'c2mm'` for the plane groups, `'2mm'`, `'3m'` for the plane point groups; the two sets do not
9
+ * overlap. Functions that take a point take its coordinates in the lattice basis and an optional
10
+ * `tolerance` (docs/conventions.md, "Plane groups").
11
+ */
12
+
13
+ import { describePlaneOperation } from './spaceGroups/describe.js';
14
+ import { planeAsymmetricUnit, planeCellElements } from './spaceGroups/cell.js';
15
+ import { toPlain, type ExactOperation } from './spaceGroups/affine.js';
16
+ import { type PlaneSystem } from './spaceGroups/planeGroupData.js';
17
+ import {
18
+ PLANE_GROUP_KEYS as GROUP_KEYS,
19
+ planeGroupEntry,
20
+ planeGroupGenerators,
21
+ planeGroupOperations,
22
+ } from './spaceGroups/planeGroups.js';
23
+ import {
24
+ PLANE_POINT_GROUP_KEYS,
25
+ isPlanePointGroupKey,
26
+ planePointGroupGenerators,
27
+ planePointGroupOf,
28
+ planePointGroupOperations,
29
+ planePointGroupSettingCount,
30
+ planePointGroupSymbol,
31
+ planePointGroupSystem,
32
+ type PlanePointGroupKey,
33
+ } from './spaceGroups/planePointGroups.js';
34
+ import { planeOrbit, planeSiteSymmetry, planeWyckoffPositionOf } from './spaceGroups/positions.js';
35
+ import { parseRational, toNumber, type Rational } from './spaceGroups/rational.js';
36
+
37
+ export { VERSION } from './version.js';
38
+ export type { PlaneSystem } from './spaceGroups/planeGroupData.js';
39
+
40
+ /** The short symbol of a plane group, e.g. `'p2mg'`. */
41
+ export type PlaneGroupKey =
42
+ | 'p1'
43
+ | 'p2'
44
+ | 'pm'
45
+ | 'pg'
46
+ | 'cm'
47
+ | 'p2mm'
48
+ | 'p2mg'
49
+ | 'p2gg'
50
+ | 'c2mm'
51
+ | 'p4'
52
+ | 'p4mm'
53
+ | 'p4gm'
54
+ | 'p3'
55
+ | 'p3m1'
56
+ | 'p31m'
57
+ | 'p6'
58
+ | 'p6mm';
59
+
60
+ /** The key of a plane point group, e.g. `'2mm'`. */
61
+ export type PointGroupKey = PlanePointGroupKey;
62
+
63
+ /** The short symbols of the 17 plane groups, in ITA's order (plane group n at index n − 1). */
64
+ export const PLANE_GROUP_KEYS: readonly PlaneGroupKey[] = Object.freeze([...GROUP_KEYS] as PlaneGroupKey[]);
65
+
66
+ /** The keys of the 10 plane point groups, in the order of ITA Table 3.2.1.1. */
67
+ export const POINT_GROUP_KEYS: readonly PointGroupKey[] = Object.freeze([...PLANE_POINT_GROUP_KEYS]);
68
+
69
+ /** Options that choose the setting of a plane point group. */
70
+ export interface SettingOptions {
71
+ /** 1-based setting: for the point group `3m` 1 is `3m1` (default) and 2 is `31m`; the other point groups have one, and a plane group takes only 1. */
72
+ readonly setting?: number;
73
+ }
74
+
75
+ /** Options of the functions that take a point. */
76
+ export interface PointOptions {
77
+ /**
78
+ * Two points count as the same, modulo the lattice, if each coordinate (lattice basis) differs
79
+ * by less than this from an integer. Default 10⁻⁶; must be below 1/2.
80
+ */
81
+ readonly tolerance?: number;
82
+ }
83
+
84
+ /** An operation (W, w) in the lattice basis: x ↦ W·x + w. */
85
+ export interface PlaneOperation {
86
+ /** The linear part W, a 2 × 2 matrix with integer entries, rows first. */
87
+ readonly matrix: readonly (readonly number[])[];
88
+ /** The translation part w; for a plane group in [0, 1), for a point group zero. */
89
+ readonly translation: readonly number[];
90
+ }
91
+
92
+ /** A plane group. */
93
+ export interface PlaneGroup {
94
+ /** The short symbol, e.g. `'p2mg'`. */
95
+ readonly key: PlaneGroupKey;
96
+ /** The number of the plane group, 1 to 17. */
97
+ readonly number: number;
98
+ /** The full symbol as ITA prints it, e.g. `'p2mg'` or `'p1m1'`. */
99
+ readonly fullSymbol: string;
100
+ /** The plane point group. */
101
+ readonly pointGroup: PointGroupKey;
102
+ /** The setting of the point group: 2 for `p31m`, otherwise 1. */
103
+ readonly pointGroupSetting: number;
104
+ /** The crystal system. */
105
+ readonly crystalSystem: PlaneSystem;
106
+ /** The centring translations besides (0, 0): `[[0.5, 0.5]]` for `cm` and `c2mm`, otherwise none. */
107
+ readonly centring: readonly (readonly number[])[];
108
+ /** The block "Origin" as ITA prints it, e.g. `'at 2mm'`. */
109
+ readonly origin: string;
110
+ /** The order of the group modulo the lattice: the number of `operations`. */
111
+ readonly order: number;
112
+ }
113
+
114
+ /** A plane point group. */
115
+ export interface PointGroup {
116
+ /** The key, e.g. `'2mm'`. */
117
+ readonly key: PointGroupKey;
118
+ /** The crystal system. */
119
+ readonly crystalSystem: PlaneSystem;
120
+ /** The order of the group. */
121
+ readonly order: number;
122
+ }
123
+
124
+ /** A setting of a plane point group. */
125
+ export interface Setting {
126
+ /** 1-based. */
127
+ readonly index: number;
128
+ /** Its symbol: `'3m1'` or `'31m'` for `3m`, otherwise the key. */
129
+ readonly symbol: string;
130
+ /** True for the default setting (setting 1). */
131
+ readonly default: boolean;
132
+ }
133
+
134
+ /** What an operation is, geometrically, as ITA describes it under "Symmetry operations". */
135
+ export interface OperationDescription {
136
+ /** `'identity'`, `'translation'`, `'rotation'`, `'mirror'` (a reflection in a line) or `'glide'` (a glide reflection). */
137
+ readonly kind: 'identity' | 'translation' | 'rotation' | 'mirror' | 'glide';
138
+ /** The order of the linear part: 1 for the identity and a translation, 2 for a mirror or glide. */
139
+ readonly order: number;
140
+ /** For a rotation of order 3 or more: `'+'` if it turns a towards b, `'-'` otherwise. */
141
+ readonly sense?: '+' | '-';
142
+ /** For a translation: the translation vector. */
143
+ readonly translation?: readonly number[];
144
+ /**
145
+ * For a rotation: its centre. For a mirror or glide: a point of its line, on y = 0 unless the line
146
+ * is parallel to it, then on x = 0. Not reduced modulo the lattice.
147
+ */
148
+ readonly location?: readonly number[];
149
+ /** For a mirror or glide: the direction of its line, the shortest integer vector, first non-zero component positive. */
150
+ readonly direction?: readonly number[];
151
+ /** For a glide: the glide vector (w + W·w)/2, not reduced modulo the lattice. */
152
+ readonly glide?: readonly number[];
153
+ }
154
+
155
+ /** A Wyckoff position of a plane group, as ITA prints it. */
156
+ export interface WyckoffPosition {
157
+ /** The Wyckoff letter. */
158
+ readonly letter: string;
159
+ /** The multiplicity: the number of points in the conventional cell. */
160
+ readonly multiplicity: number;
161
+ /** The oriented site-symmetry symbol, e.g. `'.m.'`, `'2mm'` (without the spaces of the print). */
162
+ readonly siteSymmetry: string;
163
+ /** The printed coordinates of the (0,0)+ set, e.g. `['x,0', '-x,0']`; a leading `-` is an overbar. */
164
+ readonly coordinates: readonly string[];
165
+ }
166
+
167
+ /** The site symmetry of a point under a plane group. */
168
+ export interface SiteSymmetry {
169
+ /** Indices into `operations` of those that map the point onto itself modulo the lattice, ascending: a subgroup. */
170
+ readonly operations: readonly number[];
171
+ /** The point set onto the fixed space of its site symmetry, in [0, 1), which removes rounding errors within the tolerance. */
172
+ readonly point: readonly number[];
173
+ /** The number of points in the conventional cell equivalent to it. */
174
+ readonly multiplicity: number;
175
+ /** True if no operation other than the identity maps the point onto itself (general position). */
176
+ readonly general: boolean;
177
+ }
178
+
179
+ /** The asymmetric unit of a plane group, a convex polygon in the lattice basis. */
180
+ export interface AsymmetricUnit {
181
+ /** Its vertices, counter-clockwise (a towards b), starting at the lowest (smallest y, then x). */
182
+ readonly vertices: readonly (readonly number[])[];
183
+ /** Per edge, the inequality [a, b, c] for a·x + b·y ≤ c (integers, no common factor); entry i holds the edge from vertex i to vertex i + 1. */
184
+ readonly inequalities: readonly (readonly number[])[];
185
+ }
186
+
187
+ /** A rotation centre in the cell. */
188
+ export interface RotationCentre {
189
+ /** The highest order of a rotation about it. */
190
+ readonly order: number;
191
+ /** Its position in [0, 1]². */
192
+ readonly point: readonly number[];
193
+ }
194
+
195
+ /** A mirror or glide line: the part of it in the cell. */
196
+ export interface SymmetryLine {
197
+ /** `'mirror'` or `'glide'`. */
198
+ readonly kind: 'mirror' | 'glide';
199
+ /** The direction of the line, the shortest integer vector, first non-zero component positive. */
200
+ readonly direction: readonly number[];
201
+ /** For a glide line its glide vector s·direction, 0 < s < 1; for a mirror line (0, 0). */
202
+ readonly glide: readonly number[];
203
+ /** The two ends of the segment of the line in the cell [0, 1]², in the order of `direction`. */
204
+ readonly segment: readonly (readonly number[])[];
205
+ }
206
+
207
+ /** The symmetry elements of a plane group in its conventional cell [0, 1]², boundary included. */
208
+ export interface SymmetryElements {
209
+ /** The rotation centres, by descending order, then by y and x. */
210
+ readonly rotations: readonly RotationCentre[];
211
+ /** The mirror and glide lines that cross the cell, by direction, then by the start of the segment (y, then x). */
212
+ readonly lines: readonly SymmetryLine[];
213
+ }
214
+
215
+ // ---------------------------------------------------------------------------------------------
216
+
217
+ const numbers = (v: readonly Rational[]): number[] => v.map(toNumber);
218
+
219
+ function isPlaneGroupKey(key: unknown): key is PlaneGroupKey {
220
+ return typeof key === 'string' && (GROUP_KEYS as readonly string[]).includes(key);
221
+ }
222
+
223
+ function unknownKey(key: unknown, what = 'plane group or plane point group'): never {
224
+ throw new RangeError(`Unknown ${what}: ${JSON.stringify(key)}`);
225
+ }
226
+
227
+ /** The plane group of a key; throws for a point group or an unknown key. */
228
+ function groupKey(key: unknown, what: string): PlaneGroupKey {
229
+ if (isPlaneGroupKey(key)) return key;
230
+ if (isPlanePointGroupKey(key)) {
231
+ throw new RangeError(`${what} takes the key of a plane group, not of the point group ${key}`);
232
+ }
233
+ return unknownKey(key, 'plane group');
234
+ }
235
+
236
+ /** The key of a plane point group; throws for a plane group or an unknown key. */
237
+ function pointKey(key: unknown, what: string): PointGroupKey {
238
+ if (isPlanePointGroupKey(key)) return key;
239
+ if (isPlaneGroupKey(key)) {
240
+ throw new RangeError(`${what} takes the key of a plane point group; ${key} is a plane group (planeGroup)`);
241
+ }
242
+ return unknownKey(key, 'plane point group');
243
+ }
244
+
245
+ function settingOf(options: SettingOptions | undefined): number | undefined {
246
+ return options?.setting;
247
+ }
248
+
249
+ /** The exact operations for a key: a plane group (setting 1 only) or a point group in a setting. */
250
+ function exact(key: unknown, options: SettingOptions | undefined, generatorsOnly: boolean): ExactOperation[] {
251
+ const setting = settingOf(options);
252
+ if (isPlaneGroupKey(key)) {
253
+ if (setting !== undefined && setting !== 1) {
254
+ throw new RangeError(`The plane group ${key} has no setting ${String(setting)}`);
255
+ }
256
+ return generatorsOnly ? planeGroupGenerators(key) : planeGroupOperations(key);
257
+ }
258
+ if (isPlanePointGroupKey(key)) {
259
+ return generatorsOnly ? planePointGroupGenerators(key, setting) : planePointGroupOperations(key, setting);
260
+ }
261
+ return unknownKey(key);
262
+ }
263
+
264
+ const plain = (op: ExactOperation): PlaneOperation => {
265
+ const { matrix, translation } = toPlain(op);
266
+ return Object.freeze({
267
+ matrix: Object.freeze(matrix.map((row) => Object.freeze([...row]))),
268
+ translation: Object.freeze([...translation]),
269
+ });
270
+ };
271
+
272
+ /** The plane group with this key (short symbol). Throws a RangeError for an unknown key. */
273
+ export function planeGroup(key: PlaneGroupKey): PlaneGroup {
274
+ const entry = planeGroupEntry(groupKey(key, 'planeGroup'));
275
+ const point = planePointGroupOf(entry.symbol);
276
+ return Object.freeze({
277
+ key: entry.symbol as PlaneGroupKey,
278
+ number: entry.number,
279
+ fullSymbol: entry.fullSymbol,
280
+ pointGroup: point.key,
281
+ pointGroupSetting: point.setting,
282
+ crystalSystem: entry.system,
283
+ centring: Object.freeze(
284
+ entry.centring.map((t) => Object.freeze(t.split(',').map((c) => toNumber(parseRational(c))))),
285
+ ),
286
+ origin: entry.origin,
287
+ order: planeGroupOperations(entry.symbol).length,
288
+ });
289
+ }
290
+
291
+ /** The plane point group with this key. Throws a RangeError for an unknown key. */
292
+ export function pointGroup(key: PointGroupKey): PointGroup {
293
+ const k = pointKey(key, 'pointGroup');
294
+ return Object.freeze({ key: k, crystalSystem: planePointGroupSystem(k), order: planePointGroupOperations(k).length });
295
+ }
296
+
297
+ /**
298
+ * The settings of a plane point group: two for `3m` (`3m1`, the default, and `31m`), one for the
299
+ * others. Throws a RangeError for an unknown key.
300
+ */
301
+ export function settings(key: PointGroupKey): readonly Setting[] {
302
+ const k = pointKey(key, 'settings');
303
+ return Object.freeze(
304
+ Array.from({ length: planePointGroupSettingCount(k) }, (_, i) =>
305
+ Object.freeze({ index: i + 1, symbol: planePointGroupSymbol(k, i + 1), default: i === 0 }),
306
+ ),
307
+ );
308
+ }
309
+
310
+ /** The symbol of a plane point group in a setting: `'3m1'` or `'31m'` for `3m`, otherwise the key. */
311
+ export function symbol(key: PointGroupKey, options?: SettingOptions): string {
312
+ return planePointGroupSymbol(pointKey(key, 'symbol'), settingOf(options));
313
+ }
314
+
315
+ /**
316
+ * The operations of a plane group or a plane point group, in ITA's order, identity first. A plane
317
+ * group: one per coset of the integer translations, translations in [0, 1), the general position
318
+ * as numbered, then for a centred group the same sequence with the centring added (the
319
+ * "(1/2,1/2)+ set"). A point group: the linear parts of its symmorphic plane group (pm for m,
320
+ * p3m1 and p31m for the settings of 3m), translation zero. Throws a RangeError for an unknown key
321
+ * or setting.
322
+ */
323
+ export function operations(key: PlaneGroupKey | PointGroupKey, options?: SettingOptions): readonly PlaneOperation[] {
324
+ return Object.freeze(exact(key, options, false).map(plain));
325
+ }
326
+
327
+ /**
328
+ * ITA's selected generators, in printed order, without the identity and the integer translations:
329
+ * for a centred plane group the centring translation first. A point group: the linear parts of the
330
+ * generators of its symmorphic plane group. Throws a RangeError for an unknown key or setting.
331
+ */
332
+ export function generators(key: PlaneGroupKey | PointGroupKey, options?: SettingOptions): readonly PlaneOperation[] {
333
+ return Object.freeze(exact(key, options, true).map(plain));
334
+ }
335
+
336
+ /**
337
+ * Each operation of `operations` (same key and setting) described geometrically, index for index:
338
+ * what it is, its order and sense, where its symmetry element lies, its glide part. Throws a
339
+ * RangeError for an unknown key or setting.
340
+ */
341
+ export function describeOperations(
342
+ key: PlaneGroupKey | PointGroupKey,
343
+ options?: SettingOptions,
344
+ ): readonly OperationDescription[] {
345
+ return Object.freeze(
346
+ exact(key, options, false).map((op) => {
347
+ const d = describePlaneOperation(op);
348
+ return Object.freeze({
349
+ kind: d.kind,
350
+ order: d.order,
351
+ ...(d.sense ? { sense: d.sense } : {}),
352
+ ...(d.translation ? { translation: Object.freeze(numbers(d.translation)) } : {}),
353
+ ...(d.location ? { location: Object.freeze(numbers(d.location)) } : {}),
354
+ ...(d.direction ? { direction: Object.freeze([...d.direction]) } : {}),
355
+ ...(d.glide ? { glide: Object.freeze(numbers(d.glide)) } : {}),
356
+ });
357
+ }),
358
+ );
359
+ }
360
+
361
+ /**
362
+ * The Wyckoff positions of a plane group as ITA prints them, general position first. Throws a
363
+ * RangeError for an unknown key and for a plane point group, whose positions are not in symcrys
364
+ * yet.
365
+ */
366
+ export function wyckoffPositions(key: PlaneGroupKey): readonly WyckoffPosition[] {
367
+ const entry = planeGroupEntry(groupKey(key, 'wyckoffPositions'));
368
+ return Object.freeze(
369
+ entry.wyckoff.map(([multiplicity, letter, siteSymmetry, coordinates]) =>
370
+ Object.freeze({ letter, multiplicity, siteSymmetry, coordinates: Object.freeze([...coordinates]) }),
371
+ ),
372
+ );
373
+ }
374
+
375
+ /**
376
+ * The site symmetry of a point (lattice basis) under a plane group: the operations that map it
377
+ * onto itself modulo the lattice within the tolerance, closed into a group, and the point set onto
378
+ * their fixed space. Throws a RangeError for an unknown key, a point that is not two finite
379
+ * numbers, or a tolerance outside (0, 1/2).
380
+ */
381
+ export function siteSymmetry(key: PlaneGroupKey, point: readonly number[], options?: PointOptions): SiteSymmetry {
382
+ const site = planeSiteSymmetry(groupKey(key, 'siteSymmetry'), point, options);
383
+ return Object.freeze({
384
+ operations: Object.freeze([...site.operations]),
385
+ point: Object.freeze([...site.point]),
386
+ multiplicity: site.multiplicity,
387
+ general: site.operations.length === 1,
388
+ });
389
+ }
390
+
391
+ /**
392
+ * The Wyckoff position of a point (lattice basis) under a plane group, as `wyckoffPositions` gives
393
+ * it: the printed position of the point's multiplicity whose coordinates, with the centring, reach
394
+ * the point set onto its site symmetry. Throws a RangeError as `siteSymmetry`.
395
+ */
396
+ export function wyckoffPositionOf(
397
+ key: PlaneGroupKey,
398
+ point: readonly number[],
399
+ options?: PointOptions,
400
+ ): WyckoffPosition {
401
+ const k = groupKey(key, 'wyckoffPositionOf');
402
+ const { letter } = planeWyckoffPositionOf(k, point, options);
403
+ const found = wyckoffPositions(k).find((w) => w.letter === letter);
404
+ if (!found) throw new Error(`No Wyckoff position ${letter} in ${k}`);
405
+ return found;
406
+ }
407
+
408
+ /**
409
+ * The orbit of a point (lattice basis) under a plane group: its distinct images in the
410
+ * conventional cell, each in [0, 1), in the order of the operations that first give them; images
411
+ * that coincide within the tolerance are merged. Throws a RangeError as `siteSymmetry`.
412
+ */
413
+ export function orbit(
414
+ key: PlaneGroupKey,
415
+ point: readonly number[],
416
+ options?: PointOptions,
417
+ ): readonly (readonly number[])[] {
418
+ return Object.freeze(planeOrbit(groupKey(key, 'orbit'), point, options).map((p) => Object.freeze(p)));
419
+ }
420
+
421
+ /**
422
+ * The asymmetric unit of a plane group as ITA prints it: a convex polygon given by its vertices and,
423
+ * per edge, the printed inequality that holds it. Throws a RangeError for an unknown key.
424
+ */
425
+ export function asymmetricUnit(key: PlaneGroupKey): AsymmetricUnit {
426
+ const unit = planeAsymmetricUnit(groupKey(key, 'asymmetricUnit'));
427
+ return Object.freeze({
428
+ vertices: Object.freeze(unit.vertices.map((v) => Object.freeze(numbers(v)))),
429
+ inequalities: Object.freeze(unit.inequalities.map((q) => Object.freeze([...q]))),
430
+ });
431
+ }
432
+
433
+ /**
434
+ * The symmetry elements of a plane group in its conventional cell [0, 1]², boundary included:
435
+ * every rotation centre with the highest order of a rotation about it, and every mirror and glide
436
+ * line that crosses the cell, with the segment inside it. Throws a RangeError for an unknown key.
437
+ */
438
+ export function symmetryElements(key: PlaneGroupKey): SymmetryElements {
439
+ const e = planeCellElements(groupKey(key, 'symmetryElements'));
440
+ return Object.freeze({
441
+ rotations: Object.freeze(
442
+ e.rotations.map((r) => Object.freeze({ order: r.order, point: Object.freeze(numbers(r.point)) })),
443
+ ),
444
+ lines: Object.freeze(
445
+ e.lines.map((l) =>
446
+ Object.freeze({
447
+ kind: l.kind,
448
+ direction: Object.freeze([...l.direction]),
449
+ glide: Object.freeze(numbers(l.glide)),
450
+ segment: Object.freeze(l.segment.map((p) => Object.freeze(numbers(p)))),
451
+ }),
452
+ ),
453
+ ),
454
+ });
455
+ }