symcrys 0.2.0 → 0.3.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 -1
- package/dist/index.d.ts +2 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/pointGroups/wyckoff.d.ts +53 -0
- package/dist/pointGroups/wyckoff.d.ts.map +1 -0
- package/dist/pointGroups/wyckoff.js +189 -0
- package/dist/pointGroups/wyckoff.js.map +1 -0
- package/dist/pointGroups/wyckoffData.d.ts +24 -0
- package/dist/pointGroups/wyckoffData.d.ts.map +1 -0
- package/dist/pointGroups/wyckoffData.js +423 -0
- package/dist/pointGroups/wyckoffData.js.map +1 -0
- package/dist/siteSymmetry.d.ts +40 -0
- package/dist/siteSymmetry.d.ts.map +1 -0
- package/dist/siteSymmetry.js +57 -0
- package/dist/siteSymmetry.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +3 -2
- package/src/index.ts +8 -0
- package/src/pointGroups/wyckoff.ts +233 -0
- package/src/pointGroups/wyckoffData.ts +437 -0
- package/src/siteSymmetry.ts +89 -0
- package/src/version.ts +1 -1
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Site symmetry of a direction under any list of point operations: which operations leave it
|
|
3
|
+
* fixed (docs/conventions.md, "Site symmetry and Wyckoff positions").
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { apply, type Vec3 } from './linalg.js';
|
|
7
|
+
import type { Operation } from './operations.js';
|
|
8
|
+
import { EPSILON } from './tolerances.js';
|
|
9
|
+
|
|
10
|
+
export interface SiteSymmetryOptions {
|
|
11
|
+
/**
|
|
12
|
+
* A direction counts as fixed by an operation if the operation moves its unit vector by less
|
|
13
|
+
* than this (Euclidean distance). Default `EPSILON` (10⁻⁶); a caller whose directions carry
|
|
14
|
+
* rounding errors (e.g. read from a rounded link) passes a larger value.
|
|
15
|
+
*/
|
|
16
|
+
readonly tolerance?: number;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
/** The site symmetry of a direction. */
|
|
20
|
+
export interface SiteSymmetry {
|
|
21
|
+
/** Indices into the given operations of those that leave the direction fixed, ascending. */
|
|
22
|
+
readonly operations: readonly number[];
|
|
23
|
+
/**
|
|
24
|
+
* The unit vector of the direction, set onto the fixed space of its site symmetry (the mean of
|
|
25
|
+
* its images under the site symmetry, normalised), which removes rounding errors within the
|
|
26
|
+
* tolerance.
|
|
27
|
+
*/
|
|
28
|
+
readonly direction: Vec3;
|
|
29
|
+
/** Number of operations divided by the order of the site symmetry: the number of equivalent directions. */
|
|
30
|
+
readonly multiplicity: number;
|
|
31
|
+
/** True if no operation other than the identity leaves the direction fixed (general position). */
|
|
32
|
+
readonly general: boolean;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function unit(v: Vec3): Vec3 {
|
|
36
|
+
const n = Math.hypot(v[0], v[1], v[2]);
|
|
37
|
+
if (!(n > 0) || !Number.isFinite(n)) throw new RangeError(`Not a direction: ${JSON.stringify(v)}`);
|
|
38
|
+
return [v[0] / n, v[1] / n, v[2] / n];
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function fixes(op: Operation, v: Vec3, tolerance: number): boolean {
|
|
42
|
+
const w = apply(op.matrix, v);
|
|
43
|
+
return Math.hypot(w[0] - v[0], w[1] - v[1], w[2] - v[2]) < tolerance;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
function isIdentity(op: Operation): boolean {
|
|
47
|
+
return op.matrix.every((row, i) => row.every((v, j) => Math.abs(v - (i === j ? 1 : 0)) < EPSILON));
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/** The tolerance of the options, checked. */
|
|
51
|
+
export function siteTolerance(options?: SiteSymmetryOptions): number {
|
|
52
|
+
const t = options?.tolerance ?? EPSILON;
|
|
53
|
+
if (!(typeof t === 'number' && t > 0 && t < 1)) throw new RangeError(`Invalid tolerance: ${String(t)}`);
|
|
54
|
+
return t;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
/**
|
|
58
|
+
* The site symmetry of `direction` (any non-zero vector, Cartesian) under `operations`, which may
|
|
59
|
+
* 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. `direction` and `multiplicity` are
|
|
61
|
+
* meaningful when the operations form a group (then the fixing ones do too); for another list
|
|
62
|
+
* `multiplicity` may not be an integer. Throws a RangeError for a zero vector.
|
|
63
|
+
*/
|
|
64
|
+
export function siteSymmetry(
|
|
65
|
+
operations: readonly Operation[],
|
|
66
|
+
direction: Vec3,
|
|
67
|
+
options?: SiteSymmetryOptions,
|
|
68
|
+
): SiteSymmetry {
|
|
69
|
+
const tolerance = siteTolerance(options);
|
|
70
|
+
const v = unit(direction);
|
|
71
|
+
const indices: number[] = [];
|
|
72
|
+
operations.forEach((op, i) => {
|
|
73
|
+
if (fixes(op, v, tolerance)) indices.push(i);
|
|
74
|
+
});
|
|
75
|
+
const sum: [number, number, number] = [0, 0, 0];
|
|
76
|
+
for (const i of indices) {
|
|
77
|
+
const w = apply(operations[i].matrix, v);
|
|
78
|
+
sum[0] += w[0];
|
|
79
|
+
sum[1] += w[1];
|
|
80
|
+
sum[2] += w[2];
|
|
81
|
+
}
|
|
82
|
+
const projected = indices.length > 0 ? unit(sum) : v;
|
|
83
|
+
return Object.freeze({
|
|
84
|
+
operations: Object.freeze(indices),
|
|
85
|
+
direction: Object.freeze(projected) as Vec3,
|
|
86
|
+
multiplicity: indices.length > 0 ? operations.length / indices.length : operations.length,
|
|
87
|
+
general: indices.every((i) => isIdentity(operations[i])),
|
|
88
|
+
});
|
|
89
|
+
}
|
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.
|
|
2
|
+
export const VERSION = '0.3.0';
|