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.
- package/README.md +11 -2
- package/dist/plane.d.ts +262 -0
- package/dist/plane.d.ts.map +1 -0
- package/dist/plane.js +300 -0
- package/dist/plane.js.map +1 -0
- package/dist/spaceGroups/affine.d.ts +81 -0
- package/dist/spaceGroups/affine.d.ts.map +1 -0
- package/dist/spaceGroups/affine.js +245 -0
- package/dist/spaceGroups/affine.js.map +1 -0
- package/dist/spaceGroups/cell.d.ts +60 -0
- package/dist/spaceGroups/cell.d.ts.map +1 -0
- package/dist/spaceGroups/cell.js +305 -0
- package/dist/spaceGroups/cell.js.map +1 -0
- package/dist/spaceGroups/describe.d.ts +51 -0
- package/dist/spaceGroups/describe.d.ts.map +1 -0
- package/dist/spaceGroups/describe.js +101 -0
- package/dist/spaceGroups/describe.js.map +1 -0
- package/dist/spaceGroups/planeGroupData.d.ts +44 -0
- package/dist/spaceGroups/planeGroupData.d.ts.map +1 -0
- package/dist/spaceGroups/planeGroupData.js +371 -0
- package/dist/spaceGroups/planeGroupData.js.map +1 -0
- package/dist/spaceGroups/planeGroups.d.ts +28 -0
- package/dist/spaceGroups/planeGroups.d.ts.map +1 -0
- package/dist/spaceGroups/planeGroups.js +61 -0
- package/dist/spaceGroups/planeGroups.js.map +1 -0
- package/dist/spaceGroups/planePointGroups.d.ts +31 -0
- package/dist/spaceGroups/planePointGroups.d.ts.map +1 -0
- package/dist/spaceGroups/planePointGroups.js +77 -0
- package/dist/spaceGroups/planePointGroups.js.map +1 -0
- package/dist/spaceGroups/positions.d.ts +65 -0
- package/dist/spaceGroups/positions.d.ts.map +1 -0
- package/dist/spaceGroups/positions.js +200 -0
- package/dist/spaceGroups/positions.js.map +1 -0
- package/dist/spaceGroups/rational.d.ts +43 -0
- package/dist/spaceGroups/rational.d.ts.map +1 -0
- package/dist/spaceGroups/rational.js +95 -0
- package/dist/spaceGroups/rational.js.map +1 -0
- package/dist/spaceGroups/snap.d.ts +20 -0
- package/dist/spaceGroups/snap.d.ts.map +1 -0
- package/dist/spaceGroups/snap.js +103 -0
- package/dist/spaceGroups/snap.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +1 -1
- package/dist/version.js.map +1 -1
- package/package.json +7 -2
- package/src/plane.ts +562 -0
- package/src/spaceGroups/affine.ts +315 -0
- package/src/spaceGroups/cell.ts +382 -0
- package/src/spaceGroups/describe.ts +149 -0
- package/src/spaceGroups/planeGroupData.ts +407 -0
- package/src/spaceGroups/planeGroups.ts +75 -0
- package/src/spaceGroups/planePointGroups.ts +90 -0
- package/src/spaceGroups/positions.ts +267 -0
- package/src/spaceGroups/rational.ts +115 -0
- package/src/spaceGroups/snap.ts +121 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,65 @@
|
|
|
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 { 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;AAkED;;;;GAIG;AACH,wBAAgB,UAAU,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,MAAM,EAAE,EAAE,CASpG;AA8BD;;;;;;GAMG;AACH,wBAAgB,iBAAiB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,EAAE,SAAS,MAAM,EAAE,EAAE,OAAO,CAAC,EAAE,YAAY,GAAG,iBAAiB,CA4BlH;AAgDD;;;;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,200 @@
|
|
|
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 groupCache = new Map();
|
|
38
|
+
function groupData(key) {
|
|
39
|
+
const k = planeGroupEntry(key).symbol;
|
|
40
|
+
let data = groupCache.get(k);
|
|
41
|
+
if (!data) {
|
|
42
|
+
const exact = planeGroupOperations(k);
|
|
43
|
+
const table = exact.map((a) => exact.map((b) => {
|
|
44
|
+
const product = compose(a, b);
|
|
45
|
+
const i = exact.findIndex((op) => equalModLattice(op, product));
|
|
46
|
+
if (i < 0)
|
|
47
|
+
throw new Error(`The operations of ${k} are not closed modulo the lattice`);
|
|
48
|
+
return i;
|
|
49
|
+
}));
|
|
50
|
+
data = { ops: exact.map(toPlain), table };
|
|
51
|
+
groupCache.set(k, data);
|
|
52
|
+
}
|
|
53
|
+
return data;
|
|
54
|
+
}
|
|
55
|
+
const plainOperations = (key) => groupData(key).ops;
|
|
56
|
+
/**
|
|
57
|
+
* The orbit of a point under a plane group: its distinct images in the conventional cell, each in
|
|
58
|
+
* [0, 1), in the order of the operations that first produce them. Coinciding images (within the
|
|
59
|
+
* tolerance) are merged.
|
|
60
|
+
*/
|
|
61
|
+
export function planeOrbit(key, point, options) {
|
|
62
|
+
checkPoint(point);
|
|
63
|
+
const tol = tolerance(options);
|
|
64
|
+
const out = [];
|
|
65
|
+
for (const op of plainOperations(key)) {
|
|
66
|
+
const q = image(op, point).map(mod1);
|
|
67
|
+
if (!out.some((r) => sameModLattice(r, q, tol)))
|
|
68
|
+
out.push(q);
|
|
69
|
+
}
|
|
70
|
+
return out;
|
|
71
|
+
}
|
|
72
|
+
/** Indices of `set` closed under products, modulo the lattice, within the operations of the group. */
|
|
73
|
+
function closeWithin(key, set) {
|
|
74
|
+
const { table } = groupData(key);
|
|
75
|
+
const out = [...new Set(set)];
|
|
76
|
+
const member = new Set(out);
|
|
77
|
+
// Every product of two members is a member once each new member has been combined with all others.
|
|
78
|
+
for (let i = 0; i < out.length; i++) {
|
|
79
|
+
for (let j = 0; j <= i; j++) {
|
|
80
|
+
for (const k of [table[out[i]][out[j]], table[out[j]][out[i]]]) {
|
|
81
|
+
if (!member.has(k)) {
|
|
82
|
+
member.add(k);
|
|
83
|
+
out.push(k);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
}
|
|
88
|
+
return out.sort((a, b) => a - b);
|
|
89
|
+
}
|
|
90
|
+
/** The operations of `indices`, each shifted by the lattice translation that brings its image of `p` nearest to `p`. */
|
|
91
|
+
function fixingOperations(ops, indices, p) {
|
|
92
|
+
return indices.map((i) => {
|
|
93
|
+
const op = ops[i];
|
|
94
|
+
const n = image(op, p).map((v, k) => Math.round(v - p[k]));
|
|
95
|
+
return { matrix: op.matrix.map((r) => [...r]), translation: op.translation.map((t, k) => t - n[k]) };
|
|
96
|
+
});
|
|
97
|
+
}
|
|
98
|
+
/**
|
|
99
|
+
* The site symmetry of a point under a plane group. The operations that fix the point modulo the
|
|
100
|
+
* lattice within the tolerance are closed under products and the point is set onto the fixed space
|
|
101
|
+
* of the closure (the mean of its images), repeated until stable, as `siteSymmetry` does for the point
|
|
102
|
+
* groups; so the result is always a subgroup and the set point lies exactly on its elements. Throws a
|
|
103
|
+
* RangeError if that does not settle (a tolerance far too large).
|
|
104
|
+
*/
|
|
105
|
+
export function planeSiteSymmetry(key, point, options) {
|
|
106
|
+
checkPoint(point);
|
|
107
|
+
const tol = tolerance(options);
|
|
108
|
+
const ops = plainOperations(key);
|
|
109
|
+
const fixingAt = (p) => ops.flatMap((op, i) => (sameModLattice(image(op, p), p, tol) ? [i] : []));
|
|
110
|
+
let p = point;
|
|
111
|
+
let set = closeWithin(key, fixingAt(p));
|
|
112
|
+
for (let pass = 0; pass < 8; pass++) {
|
|
113
|
+
const fixing = fixingOperations(ops, set, p);
|
|
114
|
+
const mean = [0, 1].map((k) => fixing.reduce((s, op) => s + image(op, p)[k], 0) / fixing.length);
|
|
115
|
+
const next = closeWithin(key, fixingAt(mean));
|
|
116
|
+
const settled = fixing.every((op) => sameModLattice(image(op, mean), mean, 1e-9));
|
|
117
|
+
if (settled && next.length === set.length && next.every((x, i) => x === set[i])) {
|
|
118
|
+
const q = mean.map(mod1);
|
|
119
|
+
return {
|
|
120
|
+
operations: set,
|
|
121
|
+
fixing: fixingOperations(ops, set, q),
|
|
122
|
+
point: q,
|
|
123
|
+
multiplicity: ops.length / set.length,
|
|
124
|
+
};
|
|
125
|
+
}
|
|
126
|
+
p = mean;
|
|
127
|
+
set = next;
|
|
128
|
+
}
|
|
129
|
+
throw new RangeError(`No common fixed point for the operations fixing ${JSON.stringify(point)} within ${tol} (tolerance too large?)`);
|
|
130
|
+
}
|
|
131
|
+
/** A printed coordinate expression, parsed once. */
|
|
132
|
+
const expressionCache = new Map();
|
|
133
|
+
function parsed(expression) {
|
|
134
|
+
let op = expressionCache.get(expression);
|
|
135
|
+
if (!op) {
|
|
136
|
+
op = toPlain(parseOperation(expression));
|
|
137
|
+
expressionCache.set(expression, op);
|
|
138
|
+
}
|
|
139
|
+
return op;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* True if some parameters x, y make the printed coordinate expression (e.g. `x,2x`, `-x+1/2,y`) give
|
|
143
|
+
* the point modulo the lattice within `tol`: least squares over the nearby lattice translations.
|
|
144
|
+
*/
|
|
145
|
+
function onExpression(expression, p, tol) {
|
|
146
|
+
const { matrix, translation } = parsed(expression);
|
|
147
|
+
const c = translation;
|
|
148
|
+
const ex = [matrix[0][0], matrix[1][0]];
|
|
149
|
+
const ey = [matrix[0][1], matrix[1][1]];
|
|
150
|
+
for (let i = -2; i <= 2; i++) {
|
|
151
|
+
for (let j = -2; j <= 2; j++) {
|
|
152
|
+
const r = [p[0] - c[0] - i, p[1] - c[1] - j];
|
|
153
|
+
// Solve min |a·ex + b·ey − r| over the columns that are not zero.
|
|
154
|
+
const cols = [ex, ey].filter((v) => v[0] !== 0 || v[1] !== 0);
|
|
155
|
+
let fit = [0, 0];
|
|
156
|
+
if (cols.length === 1) {
|
|
157
|
+
const v = cols[0];
|
|
158
|
+
const t = (v[0] * r[0] + v[1] * r[1]) / (v[0] * v[0] + v[1] * v[1]);
|
|
159
|
+
fit = [t * v[0], t * v[1]];
|
|
160
|
+
}
|
|
161
|
+
else if (cols.length === 2) {
|
|
162
|
+
const det = ex[0] * ey[1] - ex[1] * ey[0];
|
|
163
|
+
if (Math.abs(det) < 1e-12) {
|
|
164
|
+
const v = ex;
|
|
165
|
+
const t = (v[0] * r[0] + v[1] * r[1]) / (v[0] * v[0] + v[1] * v[1]);
|
|
166
|
+
fit = [t * v[0], t * v[1]];
|
|
167
|
+
}
|
|
168
|
+
else {
|
|
169
|
+
fit = r;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
if (Math.abs(fit[0] - r[0]) < tol && Math.abs(fit[1] - r[1]) < tol)
|
|
173
|
+
return true;
|
|
174
|
+
}
|
|
175
|
+
}
|
|
176
|
+
return false;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* The Wyckoff position of a point under a plane group, as ITA prints it: the point is first set
|
|
180
|
+
* onto the fixed space of its site symmetry (`planeSiteSymmetry`), then found among the printed
|
|
181
|
+
* coordinates of the positions with its multiplicity, the centring included.
|
|
182
|
+
*/
|
|
183
|
+
export function planeWyckoffPositionOf(key, point, options) {
|
|
184
|
+
const tol = tolerance(options);
|
|
185
|
+
const site = planeSiteSymmetry(key, point, options);
|
|
186
|
+
const entry = planeGroupEntry(key);
|
|
187
|
+
const centrings = [[0, 0], ...entry.centring.map((t) => parsed(t).translation)];
|
|
188
|
+
for (const [multiplicity, letter, siteSymmetry, coordinates] of entry.wyckoff) {
|
|
189
|
+
if (multiplicity !== site.multiplicity)
|
|
190
|
+
continue;
|
|
191
|
+
for (const t of centrings) {
|
|
192
|
+
const shifted = [site.point[0] - t[0], site.point[1] - t[1]];
|
|
193
|
+
if (coordinates.some((expression) => onExpression(expression, shifted, tol))) {
|
|
194
|
+
return { letter, multiplicity, siteSymmetry };
|
|
195
|
+
}
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
throw new RangeError(`No Wyckoff position of ${entry.symbol} holds the point ${JSON.stringify(point)}`);
|
|
199
|
+
}
|
|
200
|
+
//# sourceMappingURL=positions.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"positions.js","sourceRoot":"","sources":["../../src/spaceGroups/positions.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,OAAO,EAAE,eAAe,EAAE,cAAc,EAAE,OAAO,EAAuB,MAAM,aAAa,CAAC;AACrG,OAAO,EAAE,eAAe,EAAE,oBAAoB,EAAE,MAAM,kBAAkB,CAAC;AACzE,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AA0C3C,SAAS,SAAS,CAAC,OAAsB;IACvC,MAAM,CAAC,GAAG,OAAO,EAAE,SAAS,IAAI,OAAO,CAAC;IACxC,wGAAwG;IACxG,IAAI,CAAC,CAAC,OAAO,CAAC,KAAK,QAAQ,IAAI,CAAC,GAAG,CAAC,IAAI,CAAC,GAAG,GAAG,CAAC,EAAE,CAAC;QACjD,MAAM,IAAI,UAAU,CAAC,iDAAiD,MAAM,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC;IACrF,CAAC;IACD,OAAO,CAAC,CAAC;AACX,CAAC;AAED,SAAS,UAAU,CAAC,KAAwB;IAC1C,IAAI,KAAK,CAAC,MAAM,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,MAAM,CAA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EAAE,GAAG,KAAK,CAAC,QAAQ,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC;IAChF,KAAK,MAAM,CAAC,YAAY,EAAE,MAAM,EAAE,YAAY,EAAE,WAAW,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 formatR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AAED,uBAAuB;AACvB,wBAAgB,MAAM,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAE5C;AAED,2CAA2C;AAC3C,wBAAgB,cAAc,CAAC,CAAC,EAAE,QAAQ,EAAE,CAAC,EAAE,QAAQ,GAAG,OAAO,CAEhE;AAED,+BAA+B;AAC/B,wBAAgB,SAAS,CAAC,CAAC,EAAE,QAAQ,GAAG,OAAO,CAE9C;AAED,mDAAmD;AACnD,wBAAgB,IAAI,CAAC,CAAC,EAAE,QAAQ,GAAG,QAAQ,CAG1C;AAED,0BAA0B;AAC1B,wBAAgB,QAAQ,CAAC,CAAC,EAAE,QAAQ,GAAG,MAAM,CAE5C;AAED,2FAA2F;AAC3F,wBAAgB,aAAa,CAAC,IAAI,EAAE,MAAM,GAAG,QAAQ,CAMpD;AAED,mEAAmE;AACnE,wBAAgB,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
|
|
@@ -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;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,2BAA2B,IAAI,GAAG,CAAC,CAAC;IAC3D,CAAC;IACD,OAAO,QAAQ,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,CAAC,KAAK,SAAS,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;AACvE,CAAC;AAED,mEAAmE;AACnE,MAAM,UAAU,cAAc,CAAC,CAAW;IACxC,OAAO,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,EAAE,CAAC;AACvD,CAAC"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapping a point of the plane onto the nearest Wyckoff position of a plane group, by the distance
|
|
3
|
+
* of the point to the position (#85; CLAUDE.md, "Snapping onto a Wyckoff position"). Unlike the site
|
|
4
|
+
* symmetry (`positions.ts`), which asks whether the images of a point lie within a tolerance of it,
|
|
5
|
+
* this asks whether the point lies within the tolerance of the point set of a position. Internal.
|
|
6
|
+
*/
|
|
7
|
+
/** A point snapped onto a Wyckoff position: the index of the printed row and the point on it, in [0, 1). */
|
|
8
|
+
export interface SnappedPoint {
|
|
9
|
+
readonly row: number;
|
|
10
|
+
readonly point: readonly number[];
|
|
11
|
+
}
|
|
12
|
+
/**
|
|
13
|
+
* Snaps a point (lattice basis) onto the most special Wyckoff position of a plane group that lies
|
|
14
|
+
* within `tolerance` of it (per coordinate, modulo the lattice): positions without a free parameter
|
|
15
|
+
* first, then lines, then the general position, which always holds the point. Among positions with
|
|
16
|
+
* the same number of free parameters the nearest wins. Throws a RangeError for a point that is not
|
|
17
|
+
* two finite numbers or a tolerance outside (0, 1/2).
|
|
18
|
+
*/
|
|
19
|
+
export declare function planeSnapToWyckoffPosition(key: string, point: readonly number[], tolerance?: number): SnappedPoint;
|
|
20
|
+
//# sourceMappingURL=snap.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snap.d.ts","sourceRoot":"","sources":["../../src/spaceGroups/snap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AA6EH,4GAA4G;AAC5G,MAAM,WAAW,YAAY;IAC3B,QAAQ,CAAC,GAAG,EAAE,MAAM,CAAC;IACrB,QAAQ,CAAC,KAAK,EAAE,SAAS,MAAM,EAAE,CAAC;CACnC;AAED;;;;;;GAMG;AACH,wBAAgB,0BAA0B,CACxC,GAAG,EAAE,MAAM,EACX,KAAK,EAAE,SAAS,MAAM,EAAE,EACxB,SAAS,GAAE,MAAgB,GAC1B,YAAY,CAqBd"}
|
|
@@ -0,0 +1,103 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Snapping a point of the plane onto the nearest Wyckoff position of a plane group, by the distance
|
|
3
|
+
* of the point to the position (#85; CLAUDE.md, "Snapping onto a Wyckoff position"). Unlike the site
|
|
4
|
+
* symmetry (`positions.ts`), which asks whether the images of a point lie within a tolerance of it,
|
|
5
|
+
* this asks whether the point lies within the tolerance of the point set of a position. Internal.
|
|
6
|
+
*/
|
|
7
|
+
import { parseOperation, toPlain } from './affine.js';
|
|
8
|
+
import { planeGroupEntry } from './planeGroups.js';
|
|
9
|
+
import { EPSILON } from '../tolerances.js';
|
|
10
|
+
const cache = new Map();
|
|
11
|
+
function expression(op, shift) {
|
|
12
|
+
const m = op.matrix;
|
|
13
|
+
const columns = [0, 1].filter((k) => m[0][k] !== 0 || m[1][k] !== 0);
|
|
14
|
+
const det = m[0][0] * m[1][1] - m[0][1] * m[1][0];
|
|
15
|
+
return {
|
|
16
|
+
matrix: m,
|
|
17
|
+
translation: [op.translation[0] + shift[0], op.translation[1] + shift[1]],
|
|
18
|
+
freedom: columns.length === 2 && det === 0 ? 1 : columns.length,
|
|
19
|
+
};
|
|
20
|
+
}
|
|
21
|
+
/** Per printed Wyckoff row (index into `wyckoff`), its coordinate expressions with every centring. */
|
|
22
|
+
function positionsOf(symbol) {
|
|
23
|
+
let rows = cache.get(symbol);
|
|
24
|
+
if (!rows) {
|
|
25
|
+
const entry = planeGroupEntry(symbol);
|
|
26
|
+
const shifts = [[0, 0], ...entry.centring.map((t) => toPlain(parseOperation(t)).translation)];
|
|
27
|
+
rows = entry.wyckoff.map(([, , , coordinates], row) => ({
|
|
28
|
+
row,
|
|
29
|
+
expressions: coordinates.flatMap((c) => shifts.map((s) => expression(toPlain(parseOperation(c)), s))),
|
|
30
|
+
}));
|
|
31
|
+
cache.set(symbol, rows);
|
|
32
|
+
}
|
|
33
|
+
return rows;
|
|
34
|
+
}
|
|
35
|
+
/**
|
|
36
|
+
* The nearest point of the set of `e` to `p` modulo the lattice: the parameters by least squares in
|
|
37
|
+
* the lattice coordinates, over the lattice translations that can reach it. Returns the point and
|
|
38
|
+
* its distance, the larger of the two coordinate differences.
|
|
39
|
+
*/
|
|
40
|
+
function nearest(e, p) {
|
|
41
|
+
if (e.freedom === 2)
|
|
42
|
+
return { point: [...p], distance: 0 };
|
|
43
|
+
const m = e.matrix;
|
|
44
|
+
const c = e.translation;
|
|
45
|
+
let best = { point: [0, 0], distance: Infinity };
|
|
46
|
+
// c lies in [0, 2) (a printed coordinate in [0, 1) plus a centring), p in [0, 1).
|
|
47
|
+
for (let i = -2; i <= 2; i++) {
|
|
48
|
+
for (let j = -2; j <= 2; j++) {
|
|
49
|
+
const v = [p[0] - c[0] - i, p[1] - c[1] - j];
|
|
50
|
+
let r;
|
|
51
|
+
if (e.freedom === 0) {
|
|
52
|
+
r = [0, 0];
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
const k = m[0][0] !== 0 || m[1][0] !== 0 ? 0 : 1;
|
|
56
|
+
const col = [m[0][k], m[1][k]];
|
|
57
|
+
const t = (col[0] * v[0] + col[1] * v[1]) / (col[0] * col[0] + col[1] * col[1]);
|
|
58
|
+
r = [t * col[0], t * col[1]];
|
|
59
|
+
}
|
|
60
|
+
const distance = Math.max(Math.abs(r[0] - v[0]), Math.abs(r[1] - v[1]));
|
|
61
|
+
if (distance < best.distance)
|
|
62
|
+
best = { point: [r[0] + c[0] + i, r[1] + c[1] + j], distance };
|
|
63
|
+
}
|
|
64
|
+
}
|
|
65
|
+
return best;
|
|
66
|
+
}
|
|
67
|
+
const mod1 = (v) => {
|
|
68
|
+
const r = v - Math.floor(v);
|
|
69
|
+
return r >= 1 ? 0 : r + 0;
|
|
70
|
+
};
|
|
71
|
+
/**
|
|
72
|
+
* Snaps a point (lattice basis) onto the most special Wyckoff position of a plane group that lies
|
|
73
|
+
* within `tolerance` of it (per coordinate, modulo the lattice): positions without a free parameter
|
|
74
|
+
* first, then lines, then the general position, which always holds the point. Among positions with
|
|
75
|
+
* the same number of free parameters the nearest wins. Throws a RangeError for a point that is not
|
|
76
|
+
* two finite numbers or a tolerance outside (0, 1/2).
|
|
77
|
+
*/
|
|
78
|
+
export function planeSnapToWyckoffPosition(key, point, tolerance = EPSILON) {
|
|
79
|
+
if (point.length !== 2 || !point.every(Number.isFinite)) {
|
|
80
|
+
throw new RangeError(`A point of the plane has two finite coordinates, not ${JSON.stringify(point)}`);
|
|
81
|
+
}
|
|
82
|
+
if (!(typeof tolerance === 'number' && tolerance > 0 && tolerance < 0.5)) {
|
|
83
|
+
throw new RangeError(`The tolerance must lie between 0 and 1/2, not ${String(tolerance)}`);
|
|
84
|
+
}
|
|
85
|
+
const p = point.map(mod1);
|
|
86
|
+
const rows = positionsOf(planeGroupEntry(key).symbol);
|
|
87
|
+
for (const freedom of [0, 1, 2]) {
|
|
88
|
+
let best;
|
|
89
|
+
for (const { row, expressions } of rows) {
|
|
90
|
+
for (const e of expressions) {
|
|
91
|
+
if (e.freedom !== freedom)
|
|
92
|
+
continue;
|
|
93
|
+
const n = nearest(e, p);
|
|
94
|
+
if (n.distance < tolerance && (!best || n.distance < best.distance))
|
|
95
|
+
best = { row, ...n };
|
|
96
|
+
}
|
|
97
|
+
}
|
|
98
|
+
if (best)
|
|
99
|
+
return { row: best.row, point: best.point.map(mod1) };
|
|
100
|
+
}
|
|
101
|
+
throw new Error(`The general position of ${key} does not hold ${JSON.stringify(point)}`);
|
|
102
|
+
}
|
|
103
|
+
//# sourceMappingURL=snap.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"snap.js","sourceRoot":"","sources":["../../src/spaceGroups/snap.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,cAAc,EAAE,OAAO,EAAuB,MAAM,aAAa,CAAC;AAC3E,OAAO,EAAE,eAAe,EAAE,MAAM,kBAAkB,CAAC;AACnD,OAAO,EAAE,OAAO,EAAE,MAAM,kBAAkB,CAAC;AAU3C,MAAM,KAAK,GAAG,IAAI,GAAG,EAAiE,CAAC;AAEvF,SAAS,UAAU,CAAC,EAAkB,EAAE,KAAwB;IAC9D,MAAM,CAAC,GAAG,EAAE,CAAC,MAAM,CAAC;IACpB,MAAM,OAAO,GAAG,CAAC,CAAC,EAAE,CAAC,CAAC,CAAC,MAAM,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC;IACrE,MAAM,GAAG,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC,CAAC;IAClD,OAAO;QACL,MAAM,EAAE,CAAC;QACT,WAAW,EAAE,CAAC,EAAE,CAAC,WAAW,CAAC,CAAC,CAAC,GAAG,KAAK,CAAC,CAAC,CAA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EAAE,KAAK,EAAE,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,EAAE,CAAC;IAClE,CAAC;IACD,MAAM,IAAI,KAAK,CAAC,2BAA2B,GAAG,kBAAkB,IAAI,CAAC,SAAS,CAAC,KAAK,CAAC,EAAE,CAAC,CAAC;AAC3F,CAAC"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,OAAO,
|
|
1
|
+
{"version":3,"file":"version.d.ts","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,eAAO,MAAM,OAAO,WAAW,CAAC"}
|
package/dist/version.js
CHANGED
package/dist/version.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,
|
|
1
|
+
{"version":3,"file":"version.js","sourceRoot":"","sources":["../src/version.ts"],"names":[],"mappings":"AAAA;;;;GAIG;AACH,MAAM,CAAC,MAAM,OAAO,GAAG,QAAQ,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "symcrys",
|
|
3
|
-
"version": "0.
|
|
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.10.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",
|