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,28 @@
1
+ /**
2
+ * The 17 plane groups as exact operations: the general position of ITA in its numbering, the
3
+ * centring and ITA's selected generators (CLAUDE.md, "Plane groups (and later space groups)").
4
+ * Internal for now; the entry point `symcrys/plane` comes later.
5
+ */
6
+ import { type ExactOperation } from './affine.js';
7
+ import { type PlaneGroupEntry } from './planeGroupData.js';
8
+ /** The short symbols of the 17 plane groups, in ITA's order. */
9
+ export declare const PLANE_GROUP_KEYS: string[];
10
+ /** The printed data of a plane group, by short symbol (`'p2mg'`) or number (7); throws if unknown. */
11
+ export declare function planeGroupEntry(key: string | number): PlaneGroupEntry;
12
+ /** The centring translations of a plane group as operations, (0,0) first. */
13
+ export declare function centringOperations(entry: PlaneGroupEntry): ExactOperation[];
14
+ /**
15
+ * The operations of a plane group, one per coset of the integer translations, translations in
16
+ * [0, 1): the general position in ITA's numbering, then, for a centred group, the same sequence
17
+ * with the centring (1/2, 1/2) added, as ITA prints the "(1/2,1/2)+ set". Throws if ITA's selected
18
+ * generators, with the integer translations and the centring, do not give exactly this set, which
19
+ * would be an error in the data.
20
+ */
21
+ export declare function planeGroupOperations(key: string | number): ExactOperation[];
22
+ /**
23
+ * ITA's "Generators selected" of a plane group as operations, in printed order: the centring
24
+ * translation (for a centred group), then the operations named by number. The identity and the
25
+ * integer translations, which begin the printed line, are left out.
26
+ */
27
+ export declare function planeGroupGenerators(key: string | number): ExactOperation[];
28
+ //# sourceMappingURL=planeGroups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planeGroups.d.ts","sourceRoot":"","sources":["../../src/spaceGroups/planeGroups.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EAOL,KAAK,cAAc,EACpB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAoB,KAAK,eAAe,EAAE,MAAM,qBAAqB,CAAC;AAG7E,gEAAgE;AAChE,eAAO,MAAM,gBAAgB,UAAwC,CAAC;AAEtE,sGAAsG;AACtG,wBAAgB,eAAe,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,eAAe,CAMrE;AAED,6EAA6E;AAC7E,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,eAAe,GAAG,cAAc,EAAE,CAK3E;AAID;;;;;;GAMG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,EAAE,CAgB3E;AAED;;;;GAIG;AACH,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,cAAc,EAAE,CAI3E"}
@@ -0,0 +1,61 @@
1
+ /**
2
+ * The 17 plane groups as exact operations: the general position of ITA in its numbering, the
3
+ * centring and ITA's selected generators (CLAUDE.md, "Plane groups (and later space groups)").
4
+ * Internal for now; the entry point `symcrys/plane` comes later.
5
+ */
6
+ import { closure, compose, equalModLattice, parseOperation, reduceModLattice, translationOperation, } from './affine.js';
7
+ import { PLANE_GROUP_DATA } from './planeGroupData.js';
8
+ import { parseRational } from './rational.js';
9
+ /** The short symbols of the 17 plane groups, in ITA's order. */
10
+ export const PLANE_GROUP_KEYS = PLANE_GROUP_DATA.map((g) => g.symbol);
11
+ /** The printed data of a plane group, by short symbol (`'p2mg'`) or number (7); throws if unknown. */
12
+ export function planeGroupEntry(key) {
13
+ const entry = PLANE_GROUP_DATA.find((g) => g.symbol === key || g.number === key);
14
+ if (!entry) {
15
+ throw new RangeError(`Unknown plane group: ${JSON.stringify(key)}`);
16
+ }
17
+ return entry;
18
+ }
19
+ /** The centring translations of a plane group as operations, (0,0) first. */
20
+ export function centringOperations(entry) {
21
+ return [
22
+ translationOperation([parseRational('0'), parseRational('0')]),
23
+ ...entry.centring.map((t) => translationOperation(t.split(',').map(parseRational))),
24
+ ];
25
+ }
26
+ const cache = new Map();
27
+ /**
28
+ * The operations of a plane group, one per coset of the integer translations, translations in
29
+ * [0, 1): the general position in ITA's numbering, then, for a centred group, the same sequence
30
+ * with the centring (1/2, 1/2) added, as ITA prints the "(1/2,1/2)+ set". Throws if ITA's selected
31
+ * generators, with the integer translations and the centring, do not give exactly this set, which
32
+ * would be an error in the data.
33
+ */
34
+ export function planeGroupOperations(key) {
35
+ const entry = planeGroupEntry(key);
36
+ const cached = cache.get(entry.number);
37
+ if (cached)
38
+ return cached;
39
+ const general = entry.generalPosition.map(parseOperation);
40
+ const ops = centringOperations(entry).flatMap((t) => general.map((op) => reduceModLattice(compose(t, op))));
41
+ const generated = closure(planeGroupGenerators(entry.number), { dimension: 2 });
42
+ const same = generated.length === ops.length &&
43
+ generated.every((g) => ops.some((op) => equalModLattice(op, g))) &&
44
+ ops.every((op, i) => ops.findIndex((o) => equalModLattice(o, op)) === i);
45
+ if (!same) {
46
+ throw new Error(`The selected generators of ${entry.symbol} do not give its general position`);
47
+ }
48
+ cache.set(entry.number, ops);
49
+ return ops;
50
+ }
51
+ /**
52
+ * ITA's "Generators selected" of a plane group as operations, in printed order: the centring
53
+ * translation (for a centred group), then the operations named by number. The identity and the
54
+ * integer translations, which begin the printed line, are left out.
55
+ */
56
+ export function planeGroupGenerators(key) {
57
+ const entry = planeGroupEntry(key);
58
+ const general = entry.generalPosition.map(parseOperation);
59
+ return [...centringOperations(entry).slice(1), ...entry.generators.map((n) => general[n - 1])];
60
+ }
61
+ //# sourceMappingURL=planeGroups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planeGroups.js","sourceRoot":"","sources":["../../src/spaceGroups/planeGroups.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AAEH,OAAO,EACL,OAAO,EACP,OAAO,EACP,eAAe,EACf,cAAc,EACd,gBAAgB,EAChB,oBAAoB,GAErB,MAAM,aAAa,CAAC;AACrB,OAAO,EAAE,gBAAgB,EAAwB,MAAM,qBAAqB,CAAC;AAC7E,OAAO,EAAE,aAAa,EAAE,MAAM,eAAe,CAAC;AAE9C,gEAAgE;AAChE,MAAM,CAAC,MAAM,gBAAgB,GAAG,gBAAgB,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC;AAEtE,sGAAsG;AACtG,MAAM,UAAU,eAAe,CAAC,GAAoB;IAClD,MAAM,KAAK,GAAG,gBAAgB,CAAC,IAAI,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,MAAM,KAAK,GAAG,IAAI,CAAC,CAAC,MAAM,KAAK,GAAG,CAAC,CAAC;IACjF,IAAI,CAAC,KAAK,EAAE,CAAC;QACX,MAAM,IAAI,UAAU,CAAC,wBAAwB,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,EAAE,CAAC,CAAC;IACtE,CAAC;IACD,OAAO,KAAK,CAAC;AACf,CAAC;AAED,6EAA6E;AAC7E,MAAM,UAAU,kBAAkB,CAAC,KAAsB;IACvD,OAAO;QACL,oBAAoB,CAAC,CAAC,aAAa,CAAC,GAAG,CAAC,EAAE,aAAa,CAAC,GAAG,CAAC,CAAC,CAAC;QAC9D,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,oBAAoB,CAAC,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,aAAa,CAAC,CAAC,CAAC;KACpF,CA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C,MAAM,mCAAmC,CAAC,CAAC;IACjG,CAAC;IACD,KAAK,CAAC,GAAG,CAAC,KAAK,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC;IAC7B,OAAO,GAAG,CAAC;AACb,CAAC;AAED;;;;GAIG;AACH,MAAM,UAAU,oBAAoB,CAAC,GAAoB;IACvD,MAAM,KAAK,GAAG,eAAe,CAAC,GAAG,CAAC,CAAC;IACnC,MAAM,OAAO,GAAG,KAAK,CAAC,eAAe,CAAC,GAAG,CAAC,cAAc,CAAC,CAAC;IAC1D,OAAO,CAAC,GAAG,kBAAkB,CAAC,KAAK,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,GAAG,KAAK,CAAC,UAAU,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,OAAO,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC;AACjG,CAAC"}
@@ -0,0 +1,31 @@
1
+ /**
2
+ * The ten plane point groups (ITA 6th ed., Table 3.2.1.1, p. 720), `3m` in its two orientations
3
+ * `3m1` and `31m` (Ch. 3.2, p. 721, item (d)). Their operations are the linear parts of the
4
+ * symmorphic plane group of each, in ITA's order (pm for m, p3m1 and p31m for the two settings of
5
+ * 3m), so that the point group of a plane group is its linear part and one data source serves both.
6
+ * Internal; exported through `symcrys/plane`.
7
+ */
8
+ import { type ExactOperation } from './affine.js';
9
+ import { type PlaneSystem } from './planeGroupData.js';
10
+ /** The keys of the ten plane point groups, in the order of ITA Table 3.2.1.1. */
11
+ export declare const PLANE_POINT_GROUP_KEYS: readonly ["1", "2", "m", "2mm", "4", "4mm", "3", "3m", "6", "6mm"];
12
+ /** The key of a plane point group. */
13
+ export type PlanePointGroupKey = (typeof PLANE_POINT_GROUP_KEYS)[number];
14
+ /** The point group of a plane group and its setting: the key under which the plane group's symbol appears in `SOURCE`. */
15
+ export declare function planePointGroupOf(groupSymbol: string): {
16
+ key: PlanePointGroupKey;
17
+ setting: number;
18
+ };
19
+ /** True if `key` is the key of a plane point group. */
20
+ export declare function isPlanePointGroupKey(key: unknown): key is PlanePointGroupKey;
21
+ /** The number of settings of a plane point group: 2 for `3m`, otherwise 1. */
22
+ export declare function planePointGroupSettingCount(key: PlanePointGroupKey): number;
23
+ /** The symbol of a plane point group in a setting: `3m1` or `31m` for `3m`, otherwise the key. */
24
+ export declare function planePointGroupSymbol(key: PlanePointGroupKey, setting?: number): string;
25
+ /** The crystal system of a plane point group. */
26
+ export declare function planePointGroupSystem(key: PlanePointGroupKey): PlaneSystem;
27
+ /** The operations of a plane point group in a setting, in ITA's order, as operations without translation. */
28
+ export declare function planePointGroupOperations(key: PlanePointGroupKey, setting?: number): ExactOperation[];
29
+ /** The generators of a plane point group: the linear parts of ITA's selected generators of its symmorphic plane group. */
30
+ export declare function planePointGroupGenerators(key: PlanePointGroupKey, setting?: number): ExactOperation[];
31
+ //# sourceMappingURL=planePointGroups.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planePointGroups.d.ts","sourceRoot":"","sources":["../../src/spaceGroups/planePointGroups.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAE,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAClD,OAAO,EAAE,KAAK,WAAW,EAAE,MAAM,qBAAqB,CAAC;AAIvD,iFAAiF;AACjF,eAAO,MAAM,sBAAsB,oEAAqE,CAAC;AAEzG,sCAAsC;AACtC,MAAM,MAAM,kBAAkB,GAAG,CAAC,OAAO,sBAAsB,CAAC,CAAC,MAAM,CAAC,CAAC;AAgBzE,0HAA0H;AAC1H,wBAAgB,iBAAiB,CAAC,WAAW,EAAE,MAAM,GAAG;IAAE,GAAG,EAAE,kBAAkB,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAQnG;AAED,uDAAuD;AACvD,wBAAgB,oBAAoB,CAAC,GAAG,EAAE,OAAO,GAAG,GAAG,IAAI,kBAAkB,CAE5E;AAWD,8EAA8E;AAC9E,wBAAgB,2BAA2B,CAAC,GAAG,EAAE,kBAAkB,GAAG,MAAM,CAE3E;AAED,kGAAkG;AAClG,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,SAAI,GAAG,MAAM,CAGlF;AAED,iDAAiD;AACjD,wBAAgB,qBAAqB,CAAC,GAAG,EAAE,kBAAkB,GAAG,WAAW,CAE1E;AAOD,6GAA6G;AAC7G,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,SAAI,GAAG,cAAc,EAAE,CAEhG;AAED,0HAA0H;AAC1H,wBAAgB,yBAAyB,CAAC,GAAG,EAAE,kBAAkB,EAAE,OAAO,SAAI,GAAG,cAAc,EAAE,CAIhG"}
@@ -0,0 +1,77 @@
1
+ /**
2
+ * The ten plane point groups (ITA 6th ed., Table 3.2.1.1, p. 720), `3m` in its two orientations
3
+ * `3m1` and `31m` (Ch. 3.2, p. 721, item (d)). Their operations are the linear parts of the
4
+ * symmorphic plane group of each, in ITA's order (pm for m, p3m1 and p31m for the two settings of
5
+ * 3m), so that the point group of a plane group is its linear part and one data source serves both.
6
+ * Internal; exported through `symcrys/plane`.
7
+ */
8
+ import {} from './affine.js';
9
+ import {} from './planeGroupData.js';
10
+ import { planeGroupEntry, planeGroupGenerators, planeGroupOperations } from './planeGroups.js';
11
+ import { ZERO } from './rational.js';
12
+ /** The keys of the ten plane point groups, in the order of ITA Table 3.2.1.1. */
13
+ export const PLANE_POINT_GROUP_KEYS = ['1', '2', 'm', '2mm', '4', '4mm', '3', '3m', '6', '6mm'];
14
+ /** The symmorphic plane group of each point group and setting, whose linear parts it is. */
15
+ const SOURCE = {
16
+ '1': ['p1'],
17
+ '2': ['p2'],
18
+ m: ['pm'],
19
+ '2mm': ['p2mm'],
20
+ '4': ['p4'],
21
+ '4mm': ['p4mm'],
22
+ '3': ['p3'],
23
+ '3m': ['p3m1', 'p31m'],
24
+ '6': ['p6'],
25
+ '6mm': ['p6mm'],
26
+ };
27
+ /** The point group of a plane group and its setting: the key under which the plane group's symbol appears in `SOURCE`. */
28
+ export function planePointGroupOf(groupSymbol) {
29
+ for (const key of PLANE_POINT_GROUP_KEYS) {
30
+ const i = SOURCE[key].indexOf(groupSymbol);
31
+ if (i >= 0)
32
+ return { key, setting: i + 1 };
33
+ }
34
+ // A plane group that is not symmorphic has the setting of the symmorphic group of its point group.
35
+ const entry = planeGroupEntry(groupSymbol);
36
+ return { key: entry.pointGroup, setting: 1 };
37
+ }
38
+ /** True if `key` is the key of a plane point group. */
39
+ export function isPlanePointGroupKey(key) {
40
+ return typeof key === 'string' && PLANE_POINT_GROUP_KEYS.includes(key);
41
+ }
42
+ /** The symmorphic plane group for a point group and a setting (1-based); throws for an unknown one. */
43
+ function source(key, setting = 1) {
44
+ const list = SOURCE[key];
45
+ if (!Number.isInteger(setting) || setting < 1 || setting > list.length) {
46
+ throw new RangeError(`The plane point group ${key} has no setting ${String(setting)}`);
47
+ }
48
+ return list[setting - 1];
49
+ }
50
+ /** The number of settings of a plane point group: 2 for `3m`, otherwise 1. */
51
+ export function planePointGroupSettingCount(key) {
52
+ return SOURCE[key].length;
53
+ }
54
+ /** The symbol of a plane point group in a setting: `3m1` or `31m` for `3m`, otherwise the key. */
55
+ export function planePointGroupSymbol(key, setting = 1) {
56
+ const full = planeGroupEntry(source(key, setting)).fullSymbol.slice(1);
57
+ return key === '3m' ? full : key;
58
+ }
59
+ /** The crystal system of a plane point group. */
60
+ export function planePointGroupSystem(key) {
61
+ return planeGroupEntry(source(key)).system;
62
+ }
63
+ const linear = (op) => ({
64
+ matrix: op.matrix,
65
+ translation: op.translation.map(() => ZERO),
66
+ });
67
+ /** The operations of a plane point group in a setting, in ITA's order, as operations without translation. */
68
+ export function planePointGroupOperations(key, setting = 1) {
69
+ return planeGroupOperations(source(key, setting)).map(linear);
70
+ }
71
+ /** The generators of a plane point group: the linear parts of ITA's selected generators of its symmorphic plane group. */
72
+ export function planePointGroupGenerators(key, setting = 1) {
73
+ return planeGroupGenerators(source(key, setting))
74
+ .filter((op) => !(op.matrix[0][0] === 1 && op.matrix[0][1] === 0 && op.matrix[1][0] === 0 && op.matrix[1][1] === 1))
75
+ .map(linear);
76
+ }
77
+ //# sourceMappingURL=planePointGroups.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"planePointGroups.js","sourceRoot":"","sources":["../../src/spaceGroups/planePointGroups.ts"],"names":[],"mappings":"AAAA;;;;;;GAMG;AAEH,OAAO,EAAuB,MAAM,aAAa,CAAC;AAClD,OAAO,EAAoB,MAAM,qBAAqB,CAAC;AACvD,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AAC/F,OAAO,EAAE,IAAI,EAAE,MAAM,eAAe,CAAC;AAErC,iFAAiF;AACjF,MAAM,CAAC,MAAM,sBAAsB,GAAG,CAAC,GAAG,EAAE,GAAG,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,KAAK,EAAE,GAAG,EAAE,IAAI,EAAE,GAAG,EAAE,KAAK,CAAU,CAAC;AAKzG,4FAA4F;AAC5F,MAAM,MAAM,GAAkD;IAC5D,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,CAAC,EAAE,CAAC,IAAI,CAAC;IACT,KAAK,EAAE,CAAC,MAAM,CAAC;IACf,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,KAAK,EAAE,CAAC,MAAM,CAAC;IACf,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,IAAI,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;IACtB,GAAG,EAAE,CAAC,IAAI,CAAC;IACX,KAAK,EAAE,CAAC,MAAM,CAAC;CAChB,CAAC;AAEF,0HAA0H;AAC1H,MAAM,UAAU,iBAAiB,CAAC,WAAmB;IACnD,KAAK,MAAM,GAAG,IAAI,sBAAsB,EAAE,CAAC;QACzC,MAAM,CAAC,GAAG,MAAM,CAAC,GA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bit, site symmetry and Wyckoff position (CLAUDE.md, "Plane
3
+ * groups (and later space groups)"). Points come from callers as floating-point coordinates in the
4
+ * lattice basis; whether an operation fixes a point is decided within a tolerance, as for the
5
+ * point groups (`siteSymmetry`). Internal for now.
6
+ */
7
+ import { type PlainOperation } from './affine.js';
8
+ /** Options of the functions that take a point. */
9
+ export interface PointOptions {
10
+ /**
11
+ * Two points count as the same, modulo the lattice, if each coordinate differs by less than this
12
+ * from an integer (coordinates in the lattice basis). Default 10⁻⁶.
13
+ */
14
+ readonly tolerance?: number;
15
+ }
16
+ /** The site symmetry of a point under a plane group. */
17
+ export interface PlaneSiteSymmetry {
18
+ /**
19
+ * Indices into the operations of the group (`planeGroupOperations`) of those that map the point
20
+ * to itself modulo the lattice, ascending.
21
+ */
22
+ readonly operations: readonly number[];
23
+ /**
24
+ * The operations of the site symmetry, each with the lattice translation that makes it fix the
25
+ * point (not only modulo the lattice).
26
+ */
27
+ readonly fixing: readonly PlainOperation[];
28
+ /**
29
+ * The point set onto the fixed space of its site symmetry (the mean of its images under the
30
+ * fixing operations), in [0, 1), which removes rounding errors within the tolerance.
31
+ */
32
+ readonly point: readonly number[];
33
+ /** The number of points in the conventional cell equivalent to it. */
34
+ readonly multiplicity: number;
35
+ }
36
+ /** The Wyckoff position of a point. */
37
+ export interface PlaneWyckoffPosition {
38
+ /** The Wyckoff letter, as ITA prints it. */
39
+ readonly letter: string;
40
+ /** The multiplicity, as ITA prints it. */
41
+ readonly multiplicity: number;
42
+ /** The oriented site-symmetry symbol, as ITA prints it. */
43
+ readonly siteSymmetry: string;
44
+ }
45
+ /**
46
+ * The orbit of a point under a plane group: its distinct images in the conventional cell, each in
47
+ * [0, 1), in the order of the operations that first produce them. Coinciding images (within the
48
+ * tolerance) are merged.
49
+ */
50
+ export declare function planeOrbit(key: string, point: readonly number[], options?: PointOptions): number[][];
51
+ /**
52
+ * The site symmetry of a point under a plane group. The operations that fix the point modulo the
53
+ * lattice within the tolerance are closed under products and the point is set onto the fixed space
54
+ * of the closure (the mean of its images), repeated until stable, as `siteSymmetry` does for the point
55
+ * groups; so the result is always a subgroup and the set point lies exactly on its elements. Throws a
56
+ * RangeError if that does not settle (a tolerance far too large).
57
+ */
58
+ export declare function planeSiteSymmetry(key: string, point: readonly number[], options?: PointOptions): PlaneSiteSymmetry;
59
+ /**
60
+ * The Wyckoff position of a point under a plane group, as ITA prints it: the point is first set
61
+ * onto the fixed space of its site symmetry (`planeSiteSymmetry`), then found among the printed
62
+ * coordinates of the positions with its multiplicity, the centring included.
63
+ */
64
+ export declare function planeWyckoffPositionOf(key: string, point: readonly number[], options?: PointOptions): PlaneWyckoffPosition;
65
+ //# sourceMappingURL=positions.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"positions.d.ts","sourceRoot":"","sources":["../../src/spaceGroups/positions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAqD,KAAK,cAAc,EAAE,MAAM,aAAa,CAAC;AAIrG,kDAAkD;AAClD,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wDAAwD;AACxD,MAAM,WAAW,iBAAiB;IAChC;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC;;;OAGG;IACH,QAAQ,CAAC,MAAM,EAAE,SAAS,cAAc,EAAE,CAAC;IAC3C;;;OAGG;IACH,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;IAClC,sEAAsE;IACtE,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AAED,uCAAuC;AACvC,MAAM,WAAW,oBAAoB;IACnC,4CAA4C;IAC5C,QAAQ,CAAC,MAAM,EAAE,MAAM,CAAC;IACxB,0CAA0C;IAC1C,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,2DAA2D;IAC3D,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;CAC/B;AA6CD;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,EAAE,EAAE,CASpG;AAgCD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,iBAAiB,CA4BlH;AAqCD;;;;GAIG;AACH,wBAAgB,sBAAsB,CACpC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,OAAO,CAAC,EAAE,YAAY,GACrB,oBAAoB,CAetB"}
@@ -0,0 +1,183 @@
1
+ /**
2
+ * Points of a plane group: their orbit, site symmetry and Wyckoff position (CLAUDE.md, "Plane
3
+ * groups (and later space groups)"). Points come from callers as floating-point coordinates in the
4
+ * lattice basis; whether an operation fixes a point is decided within a tolerance, as for the
5
+ * point groups (`siteSymmetry`). Internal for now.
6
+ */
7
+ import { compose, equalModLattice, parseOperation, toPlain } from './affine.js';
8
+ import { planeGroupEntry, planeGroupOperations } from './planeGroups.js';
9
+ import { EPSILON } from '../tolerances.js';
10
+ function tolerance(options) {
11
+ const t = options?.tolerance ?? EPSILON;
12
+ // Modulo the lattice two coordinates differ by at most 1/2, so a tolerance of 1/2 or more says nothing.
13
+ if (!(typeof t === 'number' && t > 0 && t < 0.5)) {
14
+ throw new RangeError(`The tolerance must lie between 0 and 1/2, not ${String(t)}`);
15
+ }
16
+ return t;
17
+ }
18
+ function checkPoint(point) {
19
+ if (point.length !== 2 || !point.every(Number.isFinite)) {
20
+ throw new RangeError(`A point of the plane has two finite coordinates, not ${JSON.stringify(point)}`);
21
+ }
22
+ }
23
+ const mod1 = (v) => {
24
+ const r = v - Math.floor(v);
25
+ return r >= 1 ? 0 : r + 0;
26
+ };
27
+ function image(op, p) {
28
+ return op.matrix.map((row, i) => row[0] * p[0] + row[1] * p[1] + op.translation[i]);
29
+ }
30
+ /** True if the two points agree modulo the lattice within `tol` in each coordinate. */
31
+ function sameModLattice(p, q, tol) {
32
+ return p.every((v, i) => {
33
+ const d = v - q[i];
34
+ return Math.abs(d - Math.round(d)) < tol;
35
+ });
36
+ }
37
+ const plainCache = new Map();
38
+ function plainOperations(key) {
39
+ const k = planeGroupEntry(key).symbol;
40
+ let ops = plainCache.get(k);
41
+ if (!ops) {
42
+ ops = planeGroupOperations(k).map(toPlain);
43
+ plainCache.set(k, ops);
44
+ }
45
+ return ops;
46
+ }
47
+ /**
48
+ * The orbit of a point under a plane group: its distinct images in the conventional cell, each in
49
+ * [0, 1), in the order of the operations that first produce them. Coinciding images (within the
50
+ * tolerance) are merged.
51
+ */
52
+ export function planeOrbit(key, point, options) {
53
+ checkPoint(point);
54
+ const tol = tolerance(options);
55
+ const out = [];
56
+ for (const op of plainOperations(key)) {
57
+ const q = image(op, point).map(mod1);
58
+ if (!out.some((r) => sameModLattice(r, q, tol)))
59
+ out.push(q);
60
+ }
61
+ return out;
62
+ }
63
+ /** Indices of `set` closed under products, modulo the lattice, within the operations of the group. */
64
+ function closeWithin(key, set) {
65
+ const exact = planeGroupOperations(planeGroupEntry(key).symbol);
66
+ const out = new Set(set);
67
+ let grew = true;
68
+ while (grew) {
69
+ grew = false;
70
+ for (const a of [...out]) {
71
+ for (const b of [...out]) {
72
+ const product = compose(exact[a], exact[b]);
73
+ const k = exact.findIndex((op) => equalModLattice(op, product));
74
+ if (!out.has(k)) {
75
+ out.add(k);
76
+ grew = true;
77
+ }
78
+ }
79
+ }
80
+ }
81
+ return [...out].sort((a, b) => a - b);
82
+ }
83
+ /** The operations of `indices`, each shifted by the lattice translation that brings its image of `p` nearest to `p`. */
84
+ function fixingOperations(ops, indices, p) {
85
+ return indices.map((i) => {
86
+ const op = ops[i];
87
+ const n = image(op, p).map((v, k) => Math.round(v - p[k]));
88
+ return { matrix: op.matrix.map((r) => [...r]), translation: op.translation.map((t, k) => t - n[k]) };
89
+ });
90
+ }
91
+ /**
92
+ * The site symmetry of a point under a plane group. The operations that fix the point modulo the
93
+ * lattice within the tolerance are closed under products and the point is set onto the fixed space
94
+ * of the closure (the mean of its images), repeated until stable, as `siteSymmetry` does for the point
95
+ * groups; so the result is always a subgroup and the set point lies exactly on its elements. Throws a
96
+ * RangeError if that does not settle (a tolerance far too large).
97
+ */
98
+ export function planeSiteSymmetry(key, point, options) {
99
+ checkPoint(point);
100
+ const tol = tolerance(options);
101
+ const ops = plainOperations(key);
102
+ const fixingAt = (p) => ops.flatMap((op, i) => (sameModLattice(image(op, p), p, tol) ? [i] : []));
103
+ let p = point;
104
+ let set = closeWithin(key, fixingAt(p));
105
+ for (let pass = 0; pass < 8; pass++) {
106
+ const fixing = fixingOperations(ops, set, p);
107
+ const mean = [0, 1].map((k) => fixing.reduce((s, op) => s + image(op, p)[k], 0) / fixing.length);
108
+ const next = closeWithin(key, fixingAt(mean));
109
+ const settled = fixing.every((op) => sameModLattice(image(op, mean), mean, 1e-9));
110
+ if (settled && next.length === set.length && next.every((x, i) => x === set[i])) {
111
+ const q = mean.map(mod1);
112
+ return {
113
+ operations: set,
114
+ fixing: fixingOperations(ops, set, q),
115
+ point: q,
116
+ multiplicity: ops.length / set.length,
117
+ };
118
+ }
119
+ p = mean;
120
+ set = next;
121
+ }
122
+ throw new RangeError(`No common fixed point for the operations fixing ${JSON.stringify(point)} within ${tol} (tolerance too large?)`);
123
+ }
124
+ /**
125
+ * True if some parameters x, y make the printed coordinate expression (e.g. `x,2x`, `-x+1/2,y`) give
126
+ * the point modulo the lattice within `tol`: least squares over the nearby lattice translations.
127
+ */
128
+ function onExpression(expression, p, tol) {
129
+ const { matrix, translation } = toPlain(parseOperation(expression));
130
+ const c = translation;
131
+ const ex = [matrix[0][0], matrix[1][0]];
132
+ const ey = [matrix[0][1], matrix[1][1]];
133
+ for (let i = -2; i <= 2; i++) {
134
+ for (let j = -2; j <= 2; j++) {
135
+ const r = [p[0] - c[0] - i, p[1] - c[1] - j];
136
+ // Solve min |a·ex + b·ey − r| over the columns that are not zero.
137
+ const cols = [ex, ey].filter((v) => v[0] !== 0 || v[1] !== 0);
138
+ let fit = [0, 0];
139
+ if (cols.length === 1) {
140
+ const v = cols[0];
141
+ const t = (v[0] * r[0] + v[1] * r[1]) / (v[0] * v[0] + v[1] * v[1]);
142
+ fit = [t * v[0], t * v[1]];
143
+ }
144
+ else if (cols.length === 2) {
145
+ const det = ex[0] * ey[1] - ex[1] * ey[0];
146
+ if (Math.abs(det) < 1e-12) {
147
+ const v = ex;
148
+ const t = (v[0] * r[0] + v[1] * r[1]) / (v[0] * v[0] + v[1] * v[1]);
149
+ fit = [t * v[0], t * v[1]];
150
+ }
151
+ else {
152
+ fit = r;
153
+ }
154
+ }
155
+ if (Math.abs(fit[0] - r[0]) < tol && Math.abs(fit[1] - r[1]) < tol)
156
+ return true;
157
+ }
158
+ }
159
+ return false;
160
+ }
161
+ /**
162
+ * The Wyckoff position of a point under a plane group, as ITA prints it: the point is first set
163
+ * onto the fixed space of its site symmetry (`planeSiteSymmetry`), then found among the printed
164
+ * coordinates of the positions with its multiplicity, the centring included.
165
+ */
166
+ export function planeWyckoffPositionOf(key, point, options) {
167
+ const tol = tolerance(options);
168
+ const site = planeSiteSymmetry(key, point, options);
169
+ const entry = planeGroupEntry(key);
170
+ const centrings = [[0, 0], ...entry.centring.map((t) => toPlain(parseOperation(t)).translation)];
171
+ for (const [multiplicity, letter, siteSymmetry, coordinates] of entry.wyckoff) {
172
+ if (multiplicity !== site.multiplicity)
173
+ continue;
174
+ for (const t of centrings) {
175
+ const shifted = [site.point[0] - t[0], site.point[1] - t[1]];
176
+ if (coordinates.some((expression) => onExpression(expression, shifted, tol))) {
177
+ return { letter, multiplicity, siteSymmetry };
178
+ }
179
+ }
180
+ }
181
+ throw new RangeError(`No Wyckoff position of ${entry.symbol} holds the point ${JSON.stringify(point)}`);
182
+ }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AW,CAAC,IAAI,KAAK,CAAC,OAAO,EAAE,CAAC;QAC9E,IAAI,YAAY,KAAK,IAAI,CAAC,YAAY;YAAE,SAAS;QACjD,KAAK,MAAM,CAAC,IAAI,SAAS,EAAE,CAAC;YAC1B,MAAM,OAAO,GAAG,CAAC,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,EAAE,IAAI,CAAC,KAAK,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;YAC7D,IAAI,WAAW,CAAC,IAAI,CAAC,CAAC,UAAU,EAAE,EAAE,CAAC,YAAY,CAAC,UAAU,EAAE,OAAO,EAAE,GAAG,CAAC,CAAC,EAAE,CAAC;gBAC7E,OAAO,EAAE,MAAM,EAAE,YAAY,EAAE,YAAY,EAAE,CAAC;YAChD,CAAC;QACH,CAAC;IACH,CAAC;IACD,MAAM,IAAI,UAAU,CAAC,0BAA0B,KAAK,CAAC,MAAM,oBAAoB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC1G,CAAC"}
@@ -0,0 +1,43 @@
1
+ /**
2
+ * Exact rational numbers for the translations of space and plane groups (CLAUDE.md, "Plane groups
3
+ * (and later space groups)"). A rational is a pair [numerator, denominator] of safe integers with
4
+ * a positive denominator and no common factor, so that two equal numbers have equal pairs. Every
5
+ * intermediate product is checked: a result outside the safe integers throws instead of rounding.
6
+ */
7
+ /** A rational number n/d: d > 0, gcd(n, d) = 1, both safe integers. */
8
+ export type Rational = readonly [numerator: number, denominator: number];
9
+ /** The rational 0. */
10
+ export declare const ZERO: Rational;
11
+ /** The rational 1. */
12
+ export declare const ONE: Rational;
13
+ /** Throws unless `value` is a safe integer. */
14
+ export declare function checkSafeInteger(value: number, what: string): number;
15
+ /** The product a·b of two safe integers; throws if it leaves the safe integers. */
16
+ export declare function safeProduct(a: number, b: number): number;
17
+ /** The sum a + b of two safe integers; throws if it leaves the safe integers. */
18
+ export declare function safeSum(a: number, b: number): number;
19
+ /** The rational n/d in lowest terms; throws if d is 0 or a part is not a safe integer. */
20
+ export declare function rational(numerator: number, denominator?: number): Rational;
21
+ /** The sum a + b. */
22
+ export declare function add(a: Rational, b: Rational): Rational;
23
+ /** The difference a − b. */
24
+ export declare function subtract(a: Rational, b: Rational): Rational;
25
+ /** The product a·b. */
26
+ export declare function multiply(a: Rational, b: Rational): Rational;
27
+ /** The product of an integer k and a rational a. */
28
+ export declare function scale(k: number, a: Rational): Rational;
29
+ /** The negative −a. */
30
+ export declare function negate(a: Rational): Rational;
31
+ /** True if a and b are the same number. */
32
+ export declare function rationalsEqual(a: Rational, b: Rational): boolean;
33
+ /** True if a is an integer. */
34
+ export declare function isInteger(a: Rational): boolean;
35
+ /** The representative of a modulo 1, in [0, 1). */
36
+ export declare function mod1(a: Rational): Rational;
37
+ /** The nearest double. */
38
+ export declare function toNumber(a: Rational): number;
39
+ /** Reads a rational as ITA prints it: an integer or a fraction such as `1/2` or `-2/3`. */
40
+ export declare function parseRational(text: string): Rational;
41
+ /** Writes a rational as ITA prints it: `0`, `1`, `-1/2`, `2/3`. */
42
+ export declare function formatRational(a: Rational): string;
43
+ //# sourceMappingURL=rational.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"rational.d.ts","sourceRoot":"","sources":["../../src/spaceGroups/rational.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,uEAAuE;AACvE,MAAM,MAAM,QAAQ,GAAG,SAAS,CAAC,SAAS,EAAE,MAAM,EAAE,WAAW,EAAE,MAAM,CAAC,CAAC;AAEzE,sBAAsB;AACtB,eAAO,MAAM,IAAI,EAAE,QAAiB,CAAC;AAErC,sBAAsB;AACtB,eAAO,MAAM,GAAG,EAAE,QAAiB,CAAC;AAWpC,+CAA+C;AAC/C,wBAAgB,gBAAgB,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,EAAE,MAAM,GAAG,MAAM,CAKpE;AAED,mFAAmF;AACnF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,cAAc,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAElD"}
@@ -0,0 +1,95 @@
1
+ /**
2
+ * Exact rational numbers for the translations of space and plane groups (CLAUDE.md, "Plane groups
3
+ * (and later space groups)"). A rational is a pair [numerator, denominator] of safe integers with
4
+ * a positive denominator and no common factor, so that two equal numbers have equal pairs. Every
5
+ * intermediate product is checked: a result outside the safe integers throws instead of rounding.
6
+ */
7
+ /** The rational 0. */
8
+ export const ZERO = [0, 1];
9
+ /** The rational 1. */
10
+ export const ONE = [1, 1];
11
+ function gcd(a, b) {
12
+ let x = Math.abs(a);
13
+ let y = Math.abs(b);
14
+ while (y !== 0) {
15
+ [x, y] = [y, x % y];
16
+ }
17
+ return x;
18
+ }
19
+ /** Throws unless `value` is a safe integer. */
20
+ export function checkSafeInteger(value, what) {
21
+ if (!Number.isSafeInteger(value)) {
22
+ throw new RangeError(`${what} must be a safe integer, not ${String(value)}`);
23
+ }
24
+ return value;
25
+ }
26
+ /** The product a·b of two safe integers; throws if it leaves the safe integers. */
27
+ export function safeProduct(a, b) {
28
+ return checkSafeInteger(a * b, 'An intermediate product');
29
+ }
30
+ /** The sum a + b of two safe integers; throws if it leaves the safe integers. */
31
+ export function safeSum(a, b) {
32
+ return checkSafeInteger(a + b, 'An intermediate sum');
33
+ }
34
+ /** The rational n/d in lowest terms; throws if d is 0 or a part is not a safe integer. */
35
+ export function rational(numerator, denominator = 1) {
36
+ checkSafeInteger(numerator, 'Numerator');
37
+ checkSafeInteger(denominator, 'Denominator');
38
+ if (denominator === 0) {
39
+ throw new RangeError('Denominator must not be 0');
40
+ }
41
+ const g = gcd(numerator, denominator);
42
+ const sign = denominator < 0 ? -1 : 1;
43
+ // `+ 0` turns −0 into 0, so that equal numbers have equal pairs.
44
+ return [(sign * numerator) / g + 0, (sign * denominator) / g];
45
+ }
46
+ /** The sum a + b. */
47
+ export function add(a, b) {
48
+ return rational(safeSum(safeProduct(a[0], b[1]), safeProduct(b[0], a[1])), safeProduct(a[1], b[1]));
49
+ }
50
+ /** The difference a − b. */
51
+ export function subtract(a, b) {
52
+ return add(a, negate(b));
53
+ }
54
+ /** The product a·b. */
55
+ export function multiply(a, b) {
56
+ return rational(safeProduct(a[0], b[0]), safeProduct(a[1], b[1]));
57
+ }
58
+ /** The product of an integer k and a rational a. */
59
+ export function scale(k, a) {
60
+ return rational(safeProduct(k, a[0]), a[1]);
61
+ }
62
+ /** The negative −a. */
63
+ export function negate(a) {
64
+ return rational(-a[0], a[1]);
65
+ }
66
+ /** True if a and b are the same number. */
67
+ export function rationalsEqual(a, b) {
68
+ return a[0] === b[0] && a[1] === b[1];
69
+ }
70
+ /** True if a is an integer. */
71
+ export function isInteger(a) {
72
+ return a[1] === 1;
73
+ }
74
+ /** The representative of a modulo 1, in [0, 1). */
75
+ export function mod1(a) {
76
+ const r = ((a[0] % a[1]) + a[1]) % a[1];
77
+ return rational(r, a[1]);
78
+ }
79
+ /** The nearest double. */
80
+ export function toNumber(a) {
81
+ return a[0] / a[1];
82
+ }
83
+ /** Reads a rational as ITA prints it: an integer or a fraction such as `1/2` or `-2/3`. */
84
+ export function parseRational(text) {
85
+ const m = /^([+-]?\d+)(?:\/(\d+))?$/.exec(text.trim());
86
+ if (!m) {
87
+ throw new RangeError(`Not a rational number: "${text}"`);
88
+ }
89
+ return rational(Number(m[1]), m[2] === undefined ? 1 : Number(m[2]));
90
+ }
91
+ /** Writes a rational as ITA prints it: `0`, `1`, `-1/2`, `2/3`. */
92
+ export function formatRational(a) {
93
+ return a[1] === 1 ? String(a[0]) : `${a[0]}/${a[1]}`;
94
+ }
95
+ //# sourceMappingURL=rational.js.map