symcrys 0.3.0 → 0.3.1
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/dist/siteSymmetry.d.ts +10 -4
- package/dist/siteSymmetry.d.ts.map +1 -1
- package/dist/siteSymmetry.js +83 -16
- package/dist/siteSymmetry.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/siteSymmetry.ts +93 -16
- package/src/version.ts +1 -1
package/dist/siteSymmetry.d.ts
CHANGED
|
@@ -14,7 +14,10 @@ export interface SiteSymmetryOptions {
|
|
|
14
14
|
}
|
|
15
15
|
/** The site symmetry of a direction. */
|
|
16
16
|
export interface SiteSymmetry {
|
|
17
|
-
/**
|
|
17
|
+
/**
|
|
18
|
+
* Indices into the given operations of those that leave the direction fixed, ascending: for a group,
|
|
19
|
+
* a subgroup (the operations fixing within the tolerance, closed under products, see `siteSymmetry`).
|
|
20
|
+
*/
|
|
18
21
|
readonly operations: readonly number[];
|
|
19
22
|
/**
|
|
20
23
|
* The unit vector of the direction, set onto the fixed space of its site symmetry (the mean of
|
|
@@ -32,9 +35,12 @@ export declare function siteTolerance(options?: SiteSymmetryOptions): number;
|
|
|
32
35
|
/**
|
|
33
36
|
* The site symmetry of `direction` (any non-zero vector, Cartesian) under `operations`, which may
|
|
34
37
|
* be any list of point operations (for instance those of a distorted crystal). Time reversal is
|
|
35
|
-
* ignored: a direction or a face normal is not changed by it.
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
+
* ignored: a direction or a face normal is not changed by it. The operations fixing the direction
|
|
39
|
+
* within the tolerance are closed under the products found in the list and the direction is set onto
|
|
40
|
+
* their fixed space, repeated until stable, so that for a group the result is a subgroup and the
|
|
41
|
+
* set direction lies exactly on its elements. For a list that is not a group, `multiplicity` may
|
|
42
|
+
* not be an integer. Throws a RangeError for a zero vector, and if the closed operations fix no
|
|
43
|
+
* common direction (a tolerance far too large, e.g. 0.5).
|
|
38
44
|
*/
|
|
39
45
|
export declare function siteSymmetry(operations: readonly Operation[], direction: Vec3, options?: SiteSymmetryOptions): SiteSymmetry;
|
|
40
46
|
//# sourceMappingURL=siteSymmetry.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siteSymmetry.d.ts","sourceRoot":"","sources":["../src/siteSymmetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,
|
|
1
|
+
{"version":3,"file":"siteSymmetry.d.ts","sourceRoot":"","sources":["../src/siteSymmetry.ts"],"names":[],"mappings":"AAAA;;;GAGG;AAEH,OAAO,EAAkC,KAAK,IAAI,EAAE,MAAM,aAAa,CAAC;AACxE,OAAO,KAAK,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAC;AAGjD,MAAM,WAAW,mBAAmB;IAClC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,CAAC,EAAE,MAAM,CAAC;CAC7B;AAED,wCAAwC;AACxC,MAAM,WAAW,YAAY;IAC3B;;;OAGG;IACH,QAAQ,CAAC,UAAU,EAAE,SAAS,MAAM,EAAE,CAAC;IACvC;;;;OAIG;IACH,QAAQ,CAAC,SAAS,EAAE,IAAI,CAAC;IACzB,2GAA2G;IAC3G,QAAQ,CAAC,YAAY,EAAE,MAAM,CAAC;IAC9B,kGAAkG;IAClG,QAAQ,CAAC,OAAO,EAAE,OAAO,CAAC;CAC3B;AAuED,6CAA6C;AAC7C,wBAAgB,aAAa,CAAC,OAAO,CAAC,EAAE,mBAAmB,GAAG,MAAM,CAInE;AAED;;;;;;;;;GASG;AACH,wBAAgB,YAAY,CAC1B,UAAU,EAAE,SAAS,SAAS,EAAE,EAChC,SAAS,EAAE,IAAI,EACf,OAAO,CAAC,EAAE,mBAAmB,GAC5B,YAAY,CAsCd"}
|
package/dist/siteSymmetry.js
CHANGED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Site symmetry of a direction under any list of point operations: which operations leave it
|
|
3
3
|
* fixed (docs/conventions.md, "Site symmetry and Wyckoff positions").
|
|
4
4
|
*/
|
|
5
|
-
import { apply } from './linalg.js';
|
|
5
|
+
import { apply, matricesEqual, multiply } from './linalg.js';
|
|
6
6
|
import { EPSILON } from './tolerances.js';
|
|
7
7
|
function unit(v) {
|
|
8
8
|
const n = Math.hypot(v[0], v[1], v[2]);
|
|
@@ -17,6 +17,55 @@ function fixes(op, v, tolerance) {
|
|
|
17
17
|
function isIdentity(op) {
|
|
18
18
|
return op.matrix.every((row, i) => row.every((v, j) => Math.abs(v - (i === j ? 1 : 0)) < EPSILON));
|
|
19
19
|
}
|
|
20
|
+
/** Products already looked up, per list of operations: `i * n + j` → index of op[i]·op[j] in the list, or -1. */
|
|
21
|
+
const productTables = new WeakMap();
|
|
22
|
+
function productIndex(operations, i, j) {
|
|
23
|
+
let table = productTables.get(operations);
|
|
24
|
+
if (!table) {
|
|
25
|
+
table = new Map();
|
|
26
|
+
productTables.set(operations, table);
|
|
27
|
+
}
|
|
28
|
+
const key = i * operations.length + j;
|
|
29
|
+
let k = table.get(key);
|
|
30
|
+
if (k === undefined) {
|
|
31
|
+
const product = multiply(operations[i].matrix, operations[j].matrix);
|
|
32
|
+
k = operations.findIndex((op) => matricesEqual(op.matrix, product));
|
|
33
|
+
table.set(key, k);
|
|
34
|
+
}
|
|
35
|
+
return k;
|
|
36
|
+
}
|
|
37
|
+
/** The indices plus those of every product of two of them that is itself in the list, until closed. */
|
|
38
|
+
function closeWithin(operations, indices) {
|
|
39
|
+
const set = [...indices];
|
|
40
|
+
const inSet = new Set(set);
|
|
41
|
+
// Each element is multiplied with every element before it once, in both orders, as it is added.
|
|
42
|
+
for (let i = 0; i < set.length; i++) {
|
|
43
|
+
for (let j = 0; j <= i; j++) {
|
|
44
|
+
for (const k of [productIndex(operations, set[i], set[j]), productIndex(operations, set[j], set[i])]) {
|
|
45
|
+
if (k >= 0 && !inSet.has(k)) {
|
|
46
|
+
inSet.add(k);
|
|
47
|
+
set.push(k);
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
}
|
|
52
|
+
return set.sort((x, y) => x - y);
|
|
53
|
+
}
|
|
54
|
+
/** The normalised mean of the images of v under the operations at `indices`; undefined if it vanishes. */
|
|
55
|
+
function meanImage(operations, indices, v) {
|
|
56
|
+
if (indices.length === 0)
|
|
57
|
+
return v;
|
|
58
|
+
const sum = [0, 0, 0];
|
|
59
|
+
for (const i of indices) {
|
|
60
|
+
const w = apply(operations[i].matrix, v);
|
|
61
|
+
sum[0] += w[0];
|
|
62
|
+
sum[1] += w[1];
|
|
63
|
+
sum[2] += w[2];
|
|
64
|
+
}
|
|
65
|
+
const n = Math.hypot(sum[0], sum[1], sum[2]);
|
|
66
|
+
return n > 1e-9 * indices.length ? [sum[0] / n, sum[1] / n, sum[2] / n] : undefined;
|
|
67
|
+
}
|
|
68
|
+
const sameIndices = (a, b) => a.length === b.length && a.every((x, i) => x === b[i]);
|
|
20
69
|
/** The tolerance of the options, checked. */
|
|
21
70
|
export function siteTolerance(options) {
|
|
22
71
|
const t = options?.tolerance ?? EPSILON;
|
|
@@ -27,26 +76,44 @@ export function siteTolerance(options) {
|
|
|
27
76
|
/**
|
|
28
77
|
* The site symmetry of `direction` (any non-zero vector, Cartesian) under `operations`, which may
|
|
29
78
|
* be any list of point operations (for instance those of a distorted crystal). Time reversal is
|
|
30
|
-
* ignored: a direction or a face normal is not changed by it.
|
|
31
|
-
*
|
|
32
|
-
*
|
|
79
|
+
* ignored: a direction or a face normal is not changed by it. The operations fixing the direction
|
|
80
|
+
* within the tolerance are closed under the products found in the list and the direction is set onto
|
|
81
|
+
* their fixed space, repeated until stable, so that for a group the result is a subgroup and the
|
|
82
|
+
* set direction lies exactly on its elements. For a list that is not a group, `multiplicity` may
|
|
83
|
+
* not be an integer. Throws a RangeError for a zero vector, and if the closed operations fix no
|
|
84
|
+
* common direction (a tolerance far too large, e.g. 0.5).
|
|
33
85
|
*/
|
|
34
86
|
export function siteSymmetry(operations, direction, options) {
|
|
35
87
|
const tolerance = siteTolerance(options);
|
|
36
88
|
const v = unit(direction);
|
|
37
|
-
const
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
89
|
+
const fixing = (w) => {
|
|
90
|
+
const out = [];
|
|
91
|
+
operations.forEach((op, i) => {
|
|
92
|
+
if (fixes(op, w, tolerance))
|
|
93
|
+
out.push(i);
|
|
94
|
+
});
|
|
95
|
+
return out;
|
|
96
|
+
};
|
|
97
|
+
// Within the tolerance the operations fixing v need not form a group (near an axis a rotation can count
|
|
98
|
+
// as fixing while its square does not). Close them under products found in the list, set v onto the
|
|
99
|
+
// fixed space of the closure (the mean of its images, the projector for a group), and repeat on the
|
|
100
|
+
// projected direction until the set is stable.
|
|
101
|
+
let indices = fixing(v);
|
|
102
|
+
let projected = v;
|
|
103
|
+
let set = closeWithin(operations, indices);
|
|
104
|
+
for (let pass = 0; pass < 8; pass++) {
|
|
105
|
+
const mean = meanImage(operations, set, v);
|
|
106
|
+
if (mean === undefined) {
|
|
107
|
+
throw new RangeError(`No common fixed direction for the operations fixing ${JSON.stringify(direction)} within ${tolerance} (tolerance too large?)`);
|
|
108
|
+
}
|
|
109
|
+
const next = closeWithin(operations, fixing(mean));
|
|
110
|
+
if (sameIndices(next, set)) {
|
|
111
|
+
indices = set;
|
|
112
|
+
projected = mean;
|
|
113
|
+
break;
|
|
114
|
+
}
|
|
115
|
+
set = next;
|
|
48
116
|
}
|
|
49
|
-
const projected = indices.length > 0 ? unit(sum) : v;
|
|
50
117
|
return Object.freeze({
|
|
51
118
|
operations: Object.freeze(indices),
|
|
52
119
|
direction: Object.freeze(projected),
|
package/dist/siteSymmetry.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"siteSymmetry.js","sourceRoot":"","sources":["../src/siteSymmetry.ts"],"names":[],"mappings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,GAAG,IAAI,CAAC;YACjB,MAAM;QACR,CAAC;QACD,GAAG,GAAG,IAAI,CAAC;IACb,CAAC;IACD,OAAO,MAAM,CAAC,MAAM,CAAC;QACnB,UAAU,EAAE,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC;QAClC,SAAS,EAAE,MAAM,CAAC,MAAM,CAAC,SAAS,CAAS;QAC3C,YAAY,EAAE,OAAO,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM,GAAG,OAAO,CAAC,MAAM,CAAC,CAAC,CAAC,UAAU,CAAC,MAAM;QACzF,OAAO,EAAE,OAAO,CAAC,KAAK,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,UAAU,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC,CAAC;KACzD,CAAC,CAAC;AACL,CAAC"}
|
package/dist/version.d.ts
CHANGED
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "symcrys",
|
|
3
|
-
"version": "0.3.
|
|
3
|
+
"version": "0.3.1",
|
|
4
4
|
"description": "Crystallographic symmetry calculations: point groups (crystallographic and magnetic), their settings, symbols and properties, and property tensors. TypeScript library without dependencies.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"crystallography",
|
package/src/siteSymmetry.ts
CHANGED
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
* fixed (docs/conventions.md, "Site symmetry and Wyckoff positions").
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
|
-
import { apply, type Vec3 } from './linalg.js';
|
|
6
|
+
import { apply, matricesEqual, multiply, type Vec3 } from './linalg.js';
|
|
7
7
|
import type { Operation } from './operations.js';
|
|
8
8
|
import { EPSILON } from './tolerances.js';
|
|
9
9
|
|
|
@@ -18,7 +18,10 @@ export interface SiteSymmetryOptions {
|
|
|
18
18
|
|
|
19
19
|
/** The site symmetry of a direction. */
|
|
20
20
|
export interface SiteSymmetry {
|
|
21
|
-
/**
|
|
21
|
+
/**
|
|
22
|
+
* Indices into the given operations of those that leave the direction fixed, ascending: for a group,
|
|
23
|
+
* a subgroup (the operations fixing within the tolerance, closed under products, see `siteSymmetry`).
|
|
24
|
+
*/
|
|
22
25
|
readonly operations: readonly number[];
|
|
23
26
|
/**
|
|
24
27
|
* The unit vector of the direction, set onto the fixed space of its site symmetry (the mean of
|
|
@@ -47,6 +50,60 @@ function isIdentity(op: Operation): boolean {
|
|
|
47
50
|
return op.matrix.every((row, i) => row.every((v, j) => Math.abs(v - (i === j ? 1 : 0)) < EPSILON));
|
|
48
51
|
}
|
|
49
52
|
|
|
53
|
+
/** Products already looked up, per list of operations: `i * n + j` → index of op[i]·op[j] in the list, or -1. */
|
|
54
|
+
const productTables = new WeakMap<readonly Operation[], Map<number, number>>();
|
|
55
|
+
|
|
56
|
+
function productIndex(operations: readonly Operation[], i: number, j: number): number {
|
|
57
|
+
let table = productTables.get(operations);
|
|
58
|
+
if (!table) {
|
|
59
|
+
table = new Map();
|
|
60
|
+
productTables.set(operations, table);
|
|
61
|
+
}
|
|
62
|
+
const key = i * operations.length + j;
|
|
63
|
+
let k = table.get(key);
|
|
64
|
+
if (k === undefined) {
|
|
65
|
+
const product = multiply(operations[i].matrix, operations[j].matrix);
|
|
66
|
+
k = operations.findIndex((op) => matricesEqual(op.matrix, product));
|
|
67
|
+
table.set(key, k);
|
|
68
|
+
}
|
|
69
|
+
return k;
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
/** The indices plus those of every product of two of them that is itself in the list, until closed. */
|
|
73
|
+
function closeWithin(operations: readonly Operation[], indices: readonly number[]): number[] {
|
|
74
|
+
const set = [...indices];
|
|
75
|
+
const inSet = new Set(set);
|
|
76
|
+
// Each element is multiplied with every element before it once, in both orders, as it is added.
|
|
77
|
+
for (let i = 0; i < set.length; i++) {
|
|
78
|
+
for (let j = 0; j <= i; j++) {
|
|
79
|
+
for (const k of [productIndex(operations, set[i], set[j]), productIndex(operations, set[j], set[i])]) {
|
|
80
|
+
if (k >= 0 && !inSet.has(k)) {
|
|
81
|
+
inSet.add(k);
|
|
82
|
+
set.push(k);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
return set.sort((x, y) => x - y);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/** The normalised mean of the images of v under the operations at `indices`; undefined if it vanishes. */
|
|
91
|
+
function meanImage(operations: readonly Operation[], indices: readonly number[], v: Vec3): Vec3 | undefined {
|
|
92
|
+
if (indices.length === 0) return v;
|
|
93
|
+
const sum: [number, number, number] = [0, 0, 0];
|
|
94
|
+
for (const i of indices) {
|
|
95
|
+
const w = apply(operations[i].matrix, v);
|
|
96
|
+
sum[0] += w[0];
|
|
97
|
+
sum[1] += w[1];
|
|
98
|
+
sum[2] += w[2];
|
|
99
|
+
}
|
|
100
|
+
const n = Math.hypot(sum[0], sum[1], sum[2]);
|
|
101
|
+
return n > 1e-9 * indices.length ? [sum[0] / n, sum[1] / n, sum[2] / n] : undefined;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const sameIndices = (a: readonly number[], b: readonly number[]): boolean =>
|
|
105
|
+
a.length === b.length && a.every((x, i) => x === b[i]);
|
|
106
|
+
|
|
50
107
|
/** The tolerance of the options, checked. */
|
|
51
108
|
export function siteTolerance(options?: SiteSymmetryOptions): number {
|
|
52
109
|
const t = options?.tolerance ?? EPSILON;
|
|
@@ -57,9 +114,12 @@ export function siteTolerance(options?: SiteSymmetryOptions): number {
|
|
|
57
114
|
/**
|
|
58
115
|
* The site symmetry of `direction` (any non-zero vector, Cartesian) under `operations`, which may
|
|
59
116
|
* be any list of point operations (for instance those of a distorted crystal). Time reversal is
|
|
60
|
-
* ignored: a direction or a face normal is not changed by it.
|
|
61
|
-
*
|
|
62
|
-
*
|
|
117
|
+
* ignored: a direction or a face normal is not changed by it. The operations fixing the direction
|
|
118
|
+
* within the tolerance are closed under the products found in the list and the direction is set onto
|
|
119
|
+
* their fixed space, repeated until stable, so that for a group the result is a subgroup and the
|
|
120
|
+
* set direction lies exactly on its elements. For a list that is not a group, `multiplicity` may
|
|
121
|
+
* not be an integer. Throws a RangeError for a zero vector, and if the closed operations fix no
|
|
122
|
+
* common direction (a tolerance far too large, e.g. 0.5).
|
|
63
123
|
*/
|
|
64
124
|
export function siteSymmetry(
|
|
65
125
|
operations: readonly Operation[],
|
|
@@ -68,18 +128,35 @@ export function siteSymmetry(
|
|
|
68
128
|
): SiteSymmetry {
|
|
69
129
|
const tolerance = siteTolerance(options);
|
|
70
130
|
const v = unit(direction);
|
|
71
|
-
const
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
131
|
+
const fixing = (w: Vec3): number[] => {
|
|
132
|
+
const out: number[] = [];
|
|
133
|
+
operations.forEach((op, i) => {
|
|
134
|
+
if (fixes(op, w, tolerance)) out.push(i);
|
|
135
|
+
});
|
|
136
|
+
return out;
|
|
137
|
+
};
|
|
138
|
+
// Within the tolerance the operations fixing v need not form a group (near an axis a rotation can count
|
|
139
|
+
// as fixing while its square does not). Close them under products found in the list, set v onto the
|
|
140
|
+
// fixed space of the closure (the mean of its images, the projector for a group), and repeat on the
|
|
141
|
+
// projected direction until the set is stable.
|
|
142
|
+
let indices = fixing(v);
|
|
143
|
+
let projected = v;
|
|
144
|
+
let set = closeWithin(operations, indices);
|
|
145
|
+
for (let pass = 0; pass < 8; pass++) {
|
|
146
|
+
const mean = meanImage(operations, set, v);
|
|
147
|
+
if (mean === undefined) {
|
|
148
|
+
throw new RangeError(
|
|
149
|
+
`No common fixed direction for the operations fixing ${JSON.stringify(direction)} within ${tolerance} (tolerance too large?)`,
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
const next = closeWithin(operations, fixing(mean));
|
|
153
|
+
if (sameIndices(next, set)) {
|
|
154
|
+
indices = set;
|
|
155
|
+
projected = mean;
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
set = next;
|
|
81
159
|
}
|
|
82
|
-
const projected = indices.length > 0 ? unit(sum) : v;
|
|
83
160
|
return Object.freeze({
|
|
84
161
|
operations: Object.freeze(indices),
|
|
85
162
|
direction: Object.freeze(projected) as Vec3,
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
1
|
/** Version of symcrys. Kept equal to `version` in package.json (checked by version.test.ts). */
|
|
2
|
-
export const VERSION = '0.3.
|
|
2
|
+
export const VERSION = '0.3.1';
|