symcrys 0.8.1 → 0.10.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 (57) hide show
  1. package/README.md +11 -2
  2. package/dist/plane.d.ts +262 -0
  3. package/dist/plane.d.ts.map +1 -0
  4. package/dist/plane.js +300 -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 +60 -0
  11. package/dist/spaceGroups/cell.d.ts.map +1 -0
  12. package/dist/spaceGroups/cell.js +305 -0
  13. package/dist/spaceGroups/cell.js.map +1 -0
  14. package/dist/spaceGroups/describe.d.ts +51 -0
  15. package/dist/spaceGroups/describe.d.ts.map +1 -0
  16. package/dist/spaceGroups/describe.js +101 -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 +200 -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/spaceGroups/snap.d.ts +20 -0
  39. package/dist/spaceGroups/snap.d.ts.map +1 -0
  40. package/dist/spaceGroups/snap.js +103 -0
  41. package/dist/spaceGroups/snap.js.map +1 -0
  42. package/dist/version.d.ts +1 -1
  43. package/dist/version.d.ts.map +1 -1
  44. package/dist/version.js +1 -1
  45. package/dist/version.js.map +1 -1
  46. package/package.json +7 -2
  47. package/src/plane.ts +562 -0
  48. package/src/spaceGroups/affine.ts +315 -0
  49. package/src/spaceGroups/cell.ts +382 -0
  50. package/src/spaceGroups/describe.ts +149 -0
  51. package/src/spaceGroups/planeGroupData.ts +407 -0
  52. package/src/spaceGroups/planeGroups.ts +75 -0
  53. package/src/spaceGroups/planePointGroups.ts +90 -0
  54. package/src/spaceGroups/positions.ts +267 -0
  55. package/src/spaceGroups/rational.ts +115 -0
  56. package/src/spaceGroups/snap.ts +121 -0
  57. package/src/version.ts +1 -1
package/src/plane.ts ADDED
@@ -0,0 +1,562 @@
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 { planeSnapToWyckoffPosition } from './spaceGroups/snap.js';
36
+ import { parseRational, rational, toNumber, type Rational } from './spaceGroups/rational.js';
37
+
38
+ export { VERSION } from './version.js';
39
+ export type { PlaneSystem } from './spaceGroups/planeGroupData.js';
40
+
41
+ /** The short symbol of a plane group, e.g. `'p2mg'`. */
42
+ export type PlaneGroupKey =
43
+ | 'p1'
44
+ | 'p2'
45
+ | 'pm'
46
+ | 'pg'
47
+ | 'cm'
48
+ | 'p2mm'
49
+ | 'p2mg'
50
+ | 'p2gg'
51
+ | 'c2mm'
52
+ | 'p4'
53
+ | 'p4mm'
54
+ | 'p4gm'
55
+ | 'p3'
56
+ | 'p3m1'
57
+ | 'p31m'
58
+ | 'p6'
59
+ | 'p6mm';
60
+
61
+ /** The key of a plane point group, e.g. `'2mm'`. */
62
+ export type PointGroupKey = PlanePointGroupKey;
63
+
64
+ /** The short symbols of the 17 plane groups, in ITA's order (plane group n at index n − 1). */
65
+ export const PLANE_GROUP_KEYS: readonly PlaneGroupKey[] = Object.freeze([...GROUP_KEYS] as PlaneGroupKey[]);
66
+
67
+ /** The keys of the 10 plane point groups, in the order of ITA Table 3.2.1.1. */
68
+ export const POINT_GROUP_KEYS: readonly PointGroupKey[] = Object.freeze([...PLANE_POINT_GROUP_KEYS]);
69
+
70
+ /** Options that choose the setting of a plane point group. */
71
+ export interface SettingOptions {
72
+ /** 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. */
73
+ readonly setting?: number;
74
+ }
75
+
76
+ /** Options of the functions that take a point. */
77
+ export interface PointOptions {
78
+ /**
79
+ * Two points count as the same, modulo the lattice, if each coordinate (lattice basis) differs
80
+ * by less than this from an integer. Default 10⁻⁶; must be below 1/2.
81
+ */
82
+ readonly tolerance?: number;
83
+ }
84
+
85
+ /** An operation (W, w) in the lattice basis: x ↦ W·x + w. */
86
+ export interface PlaneOperation {
87
+ /** The linear part W, a 2 × 2 matrix with integer entries, rows first. */
88
+ readonly matrix: readonly (readonly number[])[];
89
+ /** The translation part w; for a plane group in [0, 1), for a point group zero. */
90
+ readonly translation: readonly number[];
91
+ }
92
+
93
+ /** A plane group. */
94
+ export interface PlaneGroup {
95
+ /** The short symbol, e.g. `'p2mg'`. */
96
+ readonly key: PlaneGroupKey;
97
+ /** The number of the plane group, 1 to 17. */
98
+ readonly number: number;
99
+ /** The full symbol as ITA prints it, e.g. `'p2mg'` or `'p1m1'`. */
100
+ readonly fullSymbol: string;
101
+ /** The plane point group. */
102
+ readonly pointGroup: PointGroupKey;
103
+ /** The setting of the point group: 2 for `p31m`, otherwise 1. */
104
+ readonly pointGroupSetting: number;
105
+ /** The crystal system. */
106
+ readonly crystalSystem: PlaneSystem;
107
+ /** The centring translations besides (0, 0): `[[0.5, 0.5]]` for `cm` and `c2mm`, otherwise none. */
108
+ readonly centring: readonly (readonly number[])[];
109
+ /** The block "Origin" as ITA prints it, e.g. `'at 2mm'`. */
110
+ readonly origin: string;
111
+ /** The order of the group modulo the lattice: the number of `operations`. */
112
+ readonly order: number;
113
+ }
114
+
115
+ /** A plane point group. */
116
+ export interface PointGroup {
117
+ /** The key, e.g. `'2mm'`. */
118
+ readonly key: PointGroupKey;
119
+ /** The crystal system. */
120
+ readonly crystalSystem: PlaneSystem;
121
+ /** The order of the group. */
122
+ readonly order: number;
123
+ }
124
+
125
+ /** A setting of a plane point group. */
126
+ export interface Setting {
127
+ /** 1-based. */
128
+ readonly index: number;
129
+ /** Its symbol: `'3m1'` or `'31m'` for `3m`, otherwise the key. */
130
+ readonly symbol: string;
131
+ /** True for the default setting (setting 1). */
132
+ readonly default: boolean;
133
+ }
134
+
135
+ /** What an operation is, geometrically, as ITA describes it under "Symmetry operations". */
136
+ export interface OperationDescription {
137
+ /** `'identity'`, `'translation'`, `'rotation'`, `'mirror'` (a reflection in a line) or `'glide'` (a glide reflection). */
138
+ readonly kind: 'identity' | 'translation' | 'rotation' | 'mirror' | 'glide';
139
+ /** The order of the linear part: 1 for the identity and a translation, 2 for a mirror or glide. */
140
+ readonly order: number;
141
+ /** For a rotation of order 3 or more: `'+'` if it turns a towards b, `'-'` otherwise. */
142
+ readonly sense?: '+' | '-';
143
+ /** For a translation: the translation vector. */
144
+ readonly translation?: readonly number[];
145
+ /**
146
+ * For a rotation: its centre. For a mirror or glide: a point of its line, on y = 0 unless the line
147
+ * is parallel to it, then on x = 0. Not reduced modulo the lattice.
148
+ */
149
+ readonly location?: readonly number[];
150
+ /** For a mirror or glide: the direction of its line, the shortest integer vector, first non-zero component positive. */
151
+ readonly direction?: readonly number[];
152
+ /**
153
+ * For a mirror or glide: the normal of its line in the lattice basis, its symmetry direction as in
154
+ * ITA Table 2.1.3.1: the shortest integer vector along the columns of W − I, first non-zero
155
+ * component positive. Without a metric it is not the perpendicular of `direction`: in a hexagonal
156
+ * basis the normal of a line along [1,0] is [1,2].
157
+ */
158
+ readonly normal?: readonly number[];
159
+ /** For a glide: the glide vector (w + W·w)/2, not reduced modulo the lattice. */
160
+ readonly glide?: readonly number[];
161
+ }
162
+
163
+ /** A Wyckoff position of a plane group, as ITA prints it. */
164
+ export interface WyckoffPosition {
165
+ /** The Wyckoff letter. */
166
+ readonly letter: string;
167
+ /** The multiplicity: the number of points in the conventional cell. */
168
+ readonly multiplicity: number;
169
+ /** The oriented site-symmetry symbol, e.g. `'.m.'`, `'2mm'` (without the spaces of the print). */
170
+ readonly siteSymmetry: string;
171
+ /** The printed coordinates of the (0,0)+ set, e.g. `['x,0', '-x,0']`; a leading `-` is an overbar. */
172
+ readonly coordinates: readonly string[];
173
+ }
174
+
175
+ /** A point snapped onto a Wyckoff position: the position, as `wyckoffPositions` gives it, and the point on it. */
176
+ export interface SnappedPosition extends WyckoffPosition {
177
+ /** The point on the position nearest to the given one, modulo the lattice, in [0, 1). */
178
+ readonly point: readonly number[];
179
+ }
180
+
181
+ /** The site symmetry of a point under a plane group. */
182
+ export interface SiteSymmetry {
183
+ /** Indices into `operations` of those that map the point onto itself modulo the lattice, ascending: a subgroup. */
184
+ readonly operations: readonly number[];
185
+ /** The point set onto the fixed space of its site symmetry, in [0, 1), which removes rounding errors within the tolerance. */
186
+ readonly point: readonly number[];
187
+ /** The number of points in the conventional cell equivalent to it. */
188
+ readonly multiplicity: number;
189
+ /** True if no operation other than the identity maps the point onto itself (general position). */
190
+ readonly general: boolean;
191
+ }
192
+
193
+ /** The asymmetric unit of a plane group, a convex polygon in the lattice basis. */
194
+ export interface AsymmetricUnit {
195
+ /** Its vertices, counter-clockwise (a towards b), starting at the lowest (smallest y, then x). */
196
+ readonly vertices: readonly (readonly number[])[];
197
+ /** 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. */
198
+ readonly inequalities: readonly (readonly number[])[];
199
+ }
200
+
201
+ /** A rotation centre in the cell. */
202
+ export interface RotationCentre {
203
+ /** The highest order of a rotation about it. */
204
+ readonly order: number;
205
+ /** Its position in [0, 1]². */
206
+ readonly point: readonly number[];
207
+ }
208
+
209
+ /** A mirror or glide line: the part of it in the cell. */
210
+ export interface SymmetryLine {
211
+ /** `'mirror'` or `'glide'`. */
212
+ readonly kind: 'mirror' | 'glide';
213
+ /** The direction of the line, the shortest integer vector, first non-zero component positive. */
214
+ readonly direction: readonly number[];
215
+ /** The normal of the line in the lattice basis, as in `describeOperations`. */
216
+ readonly normal: readonly number[];
217
+ /** For a glide line its glide vector s·direction, 0 < s < 1; for a mirror line (0, 0). */
218
+ readonly glide: readonly number[];
219
+ /** The two ends of the segment of the line in the cell [0, 1]², in the order of `direction`. */
220
+ readonly segment: readonly (readonly number[])[];
221
+ }
222
+
223
+ /** The symmetry elements of a plane group in its conventional cell [0, 1]², boundary included. */
224
+ export interface SymmetryElements {
225
+ /** The rotation centres, by descending order, then by y and x. */
226
+ readonly rotations: readonly RotationCentre[];
227
+ /** The mirror and glide lines that cross the cell, by direction, then by the start of the segment (y, then x). */
228
+ readonly lines: readonly SymmetryLine[];
229
+ }
230
+
231
+ // ---------------------------------------------------------------------------------------------
232
+
233
+ const numbers = (v: readonly Rational[]): number[] => v.map(toNumber);
234
+
235
+ function isPlaneGroupKey(key: unknown): key is PlaneGroupKey {
236
+ return typeof key === 'string' && (GROUP_KEYS as readonly string[]).includes(key);
237
+ }
238
+
239
+ function unknownKey(key: unknown, what = 'plane group or plane point group'): never {
240
+ throw new RangeError(`Unknown ${what}: ${JSON.stringify(key)}`);
241
+ }
242
+
243
+ /** The plane group of a key; throws for a point group or an unknown key. */
244
+ function groupKey(key: unknown, what: string): PlaneGroupKey {
245
+ if (isPlaneGroupKey(key)) return key;
246
+ if (isPlanePointGroupKey(key)) {
247
+ throw new RangeError(`${what} takes the key of a plane group, not of the point group ${key}`);
248
+ }
249
+ return unknownKey(key, 'plane group');
250
+ }
251
+
252
+ /** The key of a plane point group; throws for a plane group or an unknown key. */
253
+ function pointKey(key: unknown, what: string): PointGroupKey {
254
+ if (isPlanePointGroupKey(key)) return key;
255
+ if (isPlaneGroupKey(key)) {
256
+ throw new RangeError(`${what} takes the key of a plane point group; ${key} is a plane group (planeGroup)`);
257
+ }
258
+ return unknownKey(key, 'plane point group');
259
+ }
260
+
261
+ function settingOf(options: SettingOptions | undefined): number | undefined {
262
+ return options?.setting;
263
+ }
264
+
265
+ /** The exact operations for a key: a plane group (setting 1 only) or a point group in a setting. */
266
+ function exact(key: unknown, options: SettingOptions | undefined, generatorsOnly: boolean): ExactOperation[] {
267
+ const setting = settingOf(options);
268
+ if (isPlaneGroupKey(key)) {
269
+ if (setting !== undefined && setting !== 1) {
270
+ throw new RangeError(`The plane group ${key} has no setting ${String(setting)}`);
271
+ }
272
+ return generatorsOnly ? planeGroupGenerators(key) : planeGroupOperations(key);
273
+ }
274
+ if (isPlanePointGroupKey(key)) {
275
+ return generatorsOnly ? planePointGroupGenerators(key, setting) : planePointGroupOperations(key, setting);
276
+ }
277
+ return unknownKey(key);
278
+ }
279
+
280
+ const plain = (op: ExactOperation): PlaneOperation => {
281
+ const { matrix, translation } = toPlain(op);
282
+ return Object.freeze({
283
+ matrix: Object.freeze(matrix.map((row) => Object.freeze([...row]))),
284
+ translation: Object.freeze([...translation]),
285
+ });
286
+ };
287
+
288
+ /** The description of an exact operation with plain numbers. */
289
+ function describe(op: ExactOperation): OperationDescription {
290
+ const d = describePlaneOperation(op);
291
+ return Object.freeze({
292
+ kind: d.kind,
293
+ order: d.order,
294
+ ...(d.sense ? { sense: d.sense } : {}),
295
+ ...(d.translation ? { translation: Object.freeze(numbers(d.translation)) } : {}),
296
+ ...(d.location ? { location: Object.freeze(numbers(d.location)) } : {}),
297
+ ...(d.direction ? { direction: Object.freeze([...d.direction]) } : {}),
298
+ ...(d.normal ? { normal: Object.freeze([...d.normal]) } : {}),
299
+ ...(d.glide ? { glide: Object.freeze(numbers(d.glide)) } : {}),
300
+ });
301
+ }
302
+
303
+ /** Tolerance for reading an integer or a fraction from a double. */
304
+ const READ_TOLERANCE = 1e-9;
305
+ /** The largest denominator of a translation that `describeOperationsOf` reads. */
306
+ const MAX_DENOMINATOR = 12;
307
+
308
+ function fractionOf(value: unknown): Rational {
309
+ if (typeof value === 'number' && Number.isFinite(value)) {
310
+ for (let d = 1; d <= MAX_DENOMINATOR; d++) {
311
+ const n = Math.round(value * d);
312
+ if (Math.abs(value * d - n) < READ_TOLERANCE * d) return rational(n, d);
313
+ }
314
+ }
315
+ throw new RangeError(
316
+ `Not within 10⁻⁹ of a translation with a denominator of at most ${MAX_DENOMINATOR}: ${shown(value)}`,
317
+ );
318
+ }
319
+
320
+ /** A value for an error message; never throws (BigInt, circular objects). */
321
+ function shown(value: unknown): string {
322
+ try {
323
+ return JSON.stringify(value) ?? String(value);
324
+ } catch {
325
+ return String(value);
326
+ }
327
+ }
328
+
329
+ /** An operation from a caller as an exact operation; throws a RangeError unless it has the shape of a plane operation. */
330
+ function exactOf(op: unknown): ExactOperation {
331
+ const o = op as Partial<PlaneOperation> | null;
332
+ const m = o?.matrix;
333
+ const t = o?.translation;
334
+ const isRow = (row: unknown): row is readonly number[] => Array.isArray(row) && row.length === 2;
335
+ if (!Array.isArray(m) || m.length !== 2 || !m.every(isRow) || !Array.isArray(t) || t.length !== 2) {
336
+ throw new RangeError(`Not an operation of the plane { matrix (2 × 2), translation (2) }: ${shown(op)}`);
337
+ }
338
+ const matrix = m.map((row) =>
339
+ row.map((v) => {
340
+ if (!(typeof v === 'number' && Math.abs(v - Math.round(v)) < READ_TOLERANCE)) {
341
+ throw new RangeError(`The matrix of a plane operation has integer entries, not ${shown(m)}`);
342
+ }
343
+ return Math.round(v) + 0;
344
+ }),
345
+ );
346
+ return { matrix, translation: t.map(fractionOf) };
347
+ }
348
+
349
+ /** The plane group with this key (short symbol). Throws a RangeError for an unknown key. */
350
+ export function planeGroup(key: PlaneGroupKey): PlaneGroup {
351
+ const entry = planeGroupEntry(groupKey(key, 'planeGroup'));
352
+ const point = planePointGroupOf(entry.symbol);
353
+ return Object.freeze({
354
+ key: entry.symbol as PlaneGroupKey,
355
+ number: entry.number,
356
+ fullSymbol: entry.fullSymbol,
357
+ pointGroup: point.key,
358
+ pointGroupSetting: point.setting,
359
+ crystalSystem: entry.system,
360
+ centring: Object.freeze(
361
+ entry.centring.map((t) => Object.freeze(t.split(',').map((c) => toNumber(parseRational(c))))),
362
+ ),
363
+ origin: entry.origin,
364
+ order: planeGroupOperations(entry.symbol).length,
365
+ });
366
+ }
367
+
368
+ /** The plane point group with this key. Throws a RangeError for an unknown key. */
369
+ export function pointGroup(key: PointGroupKey): PointGroup {
370
+ const k = pointKey(key, 'pointGroup');
371
+ return Object.freeze({ key: k, crystalSystem: planePointGroupSystem(k), order: planePointGroupOperations(k).length });
372
+ }
373
+
374
+ /**
375
+ * The settings of a plane point group: two for `3m` (`3m1`, the default, and `31m`), one for the
376
+ * others. Throws a RangeError for an unknown key.
377
+ */
378
+ export function settings(key: PointGroupKey): readonly Setting[] {
379
+ const k = pointKey(key, 'settings');
380
+ return Object.freeze(
381
+ Array.from({ length: planePointGroupSettingCount(k) }, (_, i) =>
382
+ Object.freeze({ index: i + 1, symbol: planePointGroupSymbol(k, i + 1), default: i === 0 }),
383
+ ),
384
+ );
385
+ }
386
+
387
+ /** The symbol of a plane point group in a setting: `'3m1'` or `'31m'` for `3m`, otherwise the key. */
388
+ export function symbol(key: PointGroupKey, options?: SettingOptions): string {
389
+ return planePointGroupSymbol(pointKey(key, 'symbol'), settingOf(options));
390
+ }
391
+
392
+ /**
393
+ * The operations of a plane group or a plane point group, in ITA's order, identity first. A plane
394
+ * group: one per coset of the integer translations, translations in [0, 1), the general position
395
+ * as numbered, then for a centred group the same sequence with the centring added (the
396
+ * "(1/2,1/2)+ set"). A point group: the linear parts of its symmorphic plane group (pm for m,
397
+ * p3m1 and p31m for the settings of 3m), translation zero. Throws a RangeError for an unknown key
398
+ * or setting.
399
+ */
400
+ export function operations(key: PlaneGroupKey | PointGroupKey, options?: SettingOptions): readonly PlaneOperation[] {
401
+ return Object.freeze(exact(key, options, false).map(plain));
402
+ }
403
+
404
+ /**
405
+ * ITA's selected generators, in printed order, without the identity and the integer translations:
406
+ * for a centred plane group the centring translation first. A point group: the linear parts of the
407
+ * generators of its symmorphic plane group. Throws a RangeError for an unknown key or setting.
408
+ */
409
+ export function generators(key: PlaneGroupKey | PointGroupKey, options?: SettingOptions): readonly PlaneOperation[] {
410
+ return Object.freeze(exact(key, options, true).map(plain));
411
+ }
412
+
413
+ /**
414
+ * Each operation of `operations` (same key and setting) described geometrically, index for index:
415
+ * what it is, its order and sense, where its symmetry element lies, its glide part. Throws a
416
+ * RangeError for an unknown key or setting.
417
+ */
418
+ export function describeOperations(
419
+ key: PlaneGroupKey | PointGroupKey,
420
+ options?: SettingOptions,
421
+ ): readonly OperationDescription[] {
422
+ return Object.freeze(exact(key, options, false).map(describe));
423
+ }
424
+
425
+ /**
426
+ * Any operations of the plane (lattice basis) described geometrically, index for index, as
427
+ * `describeOperations` describes those of a group: for instance a product of operations, an
428
+ * operation shifted by a lattice translation, or the operations of a site symmetry. Each operation is
429
+ * `{ matrix, translation }` as `operations` gives it. Each matrix must have integer entries (within
430
+ * 10⁻⁹) and be the linear part of a crystallographic plane point group (determinant ±1, order 1,
431
+ * 2, 3, 4 or 6); each translation must lie within 10⁻⁹ of a fraction with a denominator of at most
432
+ * 12 (1/3 as 0.333…), as the translations of `operations` and their products do. Throws a
433
+ * RangeError otherwise.
434
+ */
435
+ export function describeOperationsOf(operations: readonly PlaneOperation[]): readonly OperationDescription[] {
436
+ if (!Array.isArray(operations)) {
437
+ throw new RangeError('describeOperationsOf takes a list of operations { matrix, translation }');
438
+ }
439
+ return Object.freeze(operations.map((op) => describe(exactOf(op))));
440
+ }
441
+
442
+ /**
443
+ * The Wyckoff positions of a plane group as ITA prints them, general position first. Throws a
444
+ * RangeError for an unknown key and for a plane point group, whose positions are not in symcrys
445
+ * yet.
446
+ */
447
+ export function wyckoffPositions(key: PlaneGroupKey): readonly WyckoffPosition[] {
448
+ const entry = planeGroupEntry(groupKey(key, 'wyckoffPositions'));
449
+ return Object.freeze(
450
+ entry.wyckoff.map(([multiplicity, letter, siteSymmetry, coordinates]) =>
451
+ Object.freeze({ letter, multiplicity, siteSymmetry, coordinates: Object.freeze([...coordinates]) }),
452
+ ),
453
+ );
454
+ }
455
+
456
+ /**
457
+ * The site symmetry of a point (lattice basis) under a plane group: the operations that map it
458
+ * onto itself modulo the lattice within the tolerance, closed into a group, and the point set onto
459
+ * their fixed space. Throws a RangeError for an unknown key, a point that is not two finite
460
+ * numbers, or a tolerance outside (0, 1/2).
461
+ */
462
+ export function siteSymmetry(key: PlaneGroupKey, point: readonly number[], options?: PointOptions): SiteSymmetry {
463
+ const site = planeSiteSymmetry(groupKey(key, 'siteSymmetry'), point, options);
464
+ return Object.freeze({
465
+ operations: Object.freeze([...site.operations]),
466
+ point: Object.freeze([...site.point]),
467
+ multiplicity: site.multiplicity,
468
+ general: site.operations.length === 1,
469
+ });
470
+ }
471
+
472
+ /**
473
+ * The Wyckoff position of a point (lattice basis) under a plane group, as `wyckoffPositions` gives
474
+ * it: the printed position of the point's multiplicity whose coordinates, with the centring, reach
475
+ * the point set onto its site symmetry. Throws a RangeError as `siteSymmetry`.
476
+ */
477
+ export function wyckoffPositionOf(
478
+ key: PlaneGroupKey,
479
+ point: readonly number[],
480
+ options?: PointOptions,
481
+ ): WyckoffPosition {
482
+ const k = groupKey(key, 'wyckoffPositionOf');
483
+ const { letter } = planeWyckoffPositionOf(k, point, options);
484
+ const found = wyckoffPositions(k).find((w) => w.letter === letter);
485
+ if (!found) throw new Error(`No Wyckoff position ${letter} in ${k}`);
486
+ return found;
487
+ }
488
+
489
+ /**
490
+ * Snaps a point (lattice basis) onto the most special Wyckoff position of a plane group that lies
491
+ * within the tolerance of it, measured per coordinate modulo the lattice: a position without a free
492
+ * parameter (a point) before one with one (a line), before the general position, which always holds
493
+ * the point; among positions of the same kind the nearest. Returns the position, as
494
+ * `wyckoffPositions` gives it, and the nearest point on it, in [0, 1). Unlike `wyckoffPositionOf`,
495
+ * which asks whether the images of the point lie within the tolerance of it, this asks whether the
496
+ * point lies within the tolerance of the position: an application that drags a point and lets it
497
+ * snap passes a tolerance such as 10⁻². The point on a line is found by least squares in the
498
+ * lattice coordinates. Throws a RangeError as `siteSymmetry`.
499
+ */
500
+ export function snapToWyckoffPosition(
501
+ key: PlaneGroupKey,
502
+ point: readonly number[],
503
+ options?: PointOptions,
504
+ ): SnappedPosition {
505
+ const k = groupKey(key, 'snapToWyckoffPosition');
506
+ if (!Array.isArray(point)) {
507
+ throw new RangeError(`A point of the plane has two finite coordinates, not ${JSON.stringify(point)}`);
508
+ }
509
+ const snapped = planeSnapToWyckoffPosition(k, point, options?.tolerance);
510
+ const position = wyckoffPositions(k)[snapped.row];
511
+ return Object.freeze({ ...position, point: Object.freeze([...snapped.point]) });
512
+ }
513
+
514
+ /**
515
+ * The orbit of a point (lattice basis) under a plane group: its distinct images in the
516
+ * conventional cell, each in [0, 1), in the order of the operations that first give them; images
517
+ * that coincide within the tolerance are merged. Throws a RangeError as `siteSymmetry`.
518
+ */
519
+ export function orbit(
520
+ key: PlaneGroupKey,
521
+ point: readonly number[],
522
+ options?: PointOptions,
523
+ ): readonly (readonly number[])[] {
524
+ return Object.freeze(planeOrbit(groupKey(key, 'orbit'), point, options).map((p) => Object.freeze(p)));
525
+ }
526
+
527
+ /**
528
+ * The asymmetric unit of a plane group as ITA prints it: a convex polygon given by its vertices and,
529
+ * per edge, the printed inequality that holds it. Throws a RangeError for an unknown key.
530
+ */
531
+ export function asymmetricUnit(key: PlaneGroupKey): AsymmetricUnit {
532
+ const unit = planeAsymmetricUnit(groupKey(key, 'asymmetricUnit'));
533
+ return Object.freeze({
534
+ vertices: Object.freeze(unit.vertices.map((v) => Object.freeze(numbers(v)))),
535
+ inequalities: Object.freeze(unit.inequalities.map((q) => Object.freeze([...q]))),
536
+ });
537
+ }
538
+
539
+ /**
540
+ * The symmetry elements of a plane group in its conventional cell [0, 1]², boundary included:
541
+ * every rotation centre with the highest order of a rotation about it, and every mirror and glide
542
+ * line that crosses the cell, with the segment inside it. Throws a RangeError for an unknown key.
543
+ */
544
+ export function symmetryElements(key: PlaneGroupKey): SymmetryElements {
545
+ const e = planeCellElements(groupKey(key, 'symmetryElements'));
546
+ return Object.freeze({
547
+ rotations: Object.freeze(
548
+ e.rotations.map((r) => Object.freeze({ order: r.order, point: Object.freeze(numbers(r.point)) })),
549
+ ),
550
+ lines: Object.freeze(
551
+ e.lines.map((l) =>
552
+ Object.freeze({
553
+ kind: l.kind,
554
+ direction: Object.freeze([...l.direction]),
555
+ normal: Object.freeze([...l.normal]),
556
+ glide: Object.freeze(numbers(l.glide)),
557
+ segment: Object.freeze(l.segment.map((p) => Object.freeze(numbers(p)))),
558
+ }),
559
+ ),
560
+ ),
561
+ });
562
+ }