symcrys 0.7.0 → 0.8.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/cell.d.ts +112 -0
- package/dist/cell.d.ts.map +1 -0
- package/dist/cell.js +193 -0
- package/dist/cell.js.map +1 -0
- package/dist/crystalClasses.d.ts +22 -8
- package/dist/crystalClasses.d.ts.map +1 -1
- package/dist/crystalClasses.js +25 -8
- package/dist/crystalClasses.js.map +1 -1
- package/dist/index.d.ts +3 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -1
- package/dist/index.js.map +1 -1
- package/dist/indices.d.ts +42 -0
- package/dist/indices.d.ts.map +1 -0
- package/dist/indices.js +101 -0
- package/dist/indices.js.map +1 -0
- package/dist/linalg.d.ts +7 -1
- package/dist/linalg.d.ts.map +1 -1
- package/dist/linalg.js +20 -3
- package/dist/linalg.js.map +1 -1
- package/dist/magnetic.d.ts +3 -0
- package/dist/magnetic.d.ts.map +1 -1
- package/dist/magnetic.js +3 -0
- package/dist/magnetic.js.map +1 -1
- package/dist/operations.d.ts +6 -0
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +19 -0
- package/dist/operations.js.map +1 -1
- package/dist/pointGroups/identify.d.ts +4 -2
- package/dist/pointGroups/identify.d.ts.map +1 -1
- package/dist/pointGroups/identify.js +5 -18
- package/dist/pointGroups/identify.js.map +1 -1
- package/dist/pointGroups/orbits.d.ts +1 -1
- package/dist/pointGroups/orbits.d.ts.map +1 -1
- package/dist/pointGroups/orbits.js +3 -3
- package/dist/pointGroups/orbits.js.map +1 -1
- package/dist/pointGroups/properties.d.ts +6 -2
- package/dist/pointGroups/properties.d.ts.map +1 -1
- package/dist/pointGroups/properties.js +6 -2
- package/dist/pointGroups/properties.js.map +1 -1
- package/dist/siteSymmetry.d.ts +5 -3
- package/dist/siteSymmetry.d.ts.map +1 -1
- package/dist/siteSymmetry.js +6 -2
- package/dist/siteSymmetry.js.map +1 -1
- package/dist/tensors/tensorForm.d.ts +3 -1
- package/dist/tensors/tensorForm.d.ts.map +1 -1
- package/dist/tensors/tensorForm.js +3 -1
- package/dist/tensors/tensorForm.js.map +1 -1
- package/dist/tensors/tensorProperties.d.ts +4 -2
- package/dist/tensors/tensorProperties.d.ts.map +1 -1
- package/dist/tensors/tensorProperties.js +4 -2
- package/dist/tensors/tensorProperties.js.map +1 -1
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/cell.ts +272 -0
- package/src/crystalClasses.ts +30 -8
- package/src/index.ts +26 -0
- package/src/indices.ts +117 -0
- package/src/linalg.ts +21 -2
- package/src/magnetic.ts +26 -0
- package/src/operations.ts +20 -0
- package/src/pointGroups/identify.ts +5 -19
- package/src/pointGroups/orbits.ts +3 -3
- package/src/pointGroups/properties.ts +6 -2
- package/src/siteSymmetry.ts +6 -3
- package/src/tensors/tensorForm.ts +3 -1
- package/src/tensors/tensorProperties.ts +4 -2
- package/src/version.ts +1 -1
package/src/crystalClasses.ts
CHANGED
|
@@ -23,6 +23,7 @@ import * as identify from './pointGroups/identify.js';
|
|
|
23
23
|
import * as orbits from './pointGroups/orbits.js';
|
|
24
24
|
import * as wyckoff from './pointGroups/wyckoff.js';
|
|
25
25
|
import type { Hkl } from './pointGroups/wyckoff.js';
|
|
26
|
+
import * as cell from './cell.js';
|
|
26
27
|
import * as site from './siteSymmetry.js';
|
|
27
28
|
import type { Uvw } from './symmetryDirections.js';
|
|
28
29
|
import { TENSOR_PROPERTIES as ALL_TENSOR_PROPERTIES } from './tensors/propertyTable.js';
|
|
@@ -285,7 +286,7 @@ export { holohedry } from './pointGroups/properties.js';
|
|
|
285
286
|
/**
|
|
286
287
|
* True if the group generated by `operations` contains the inversion, e.g. for the operations of a
|
|
287
288
|
* distorted crystal. A list that is not closed is closed first. For a crystal class, read
|
|
288
|
-
* `pointGroup(key).centrosymmetric`.
|
|
289
|
+
* `pointGroup(key).centrosymmetric`. Throws a RangeError for a matrix that is not orthogonal.
|
|
289
290
|
*/
|
|
290
291
|
export function isCentrosymmetricOf(operations: readonly OperationArgument[]): boolean {
|
|
291
292
|
return properties.isCentrosymmetricOf(unitary(operations));
|
|
@@ -294,7 +295,7 @@ export function isCentrosymmetricOf(operations: readonly OperationArgument[]): b
|
|
|
294
295
|
/**
|
|
295
296
|
* True if the group generated by `operations` is chiral: proper rotations only. For a crystal
|
|
296
297
|
* class, read `pointGroup(key).chiral`. Polar is the named property `'pyroelectric'`:
|
|
297
|
-
* `allowsPropertyOf(operations, 'pyroelectric')`.
|
|
298
|
+
* `allowsPropertyOf(operations, 'pyroelectric')`. Throws a RangeError for a matrix that is not orthogonal.
|
|
298
299
|
*/
|
|
299
300
|
export function isChiralOf(operations: readonly OperationArgument[]): boolean {
|
|
300
301
|
return properties.isChiralOf(unitary(operations));
|
|
@@ -400,8 +401,10 @@ export function symmetryDirections(
|
|
|
400
401
|
* fixing the direction within the tolerance are closed under the products found in the list and
|
|
401
402
|
* the direction is set onto their fixed space, repeated until stable, so that for a group the
|
|
402
403
|
* result is a subgroup and the set direction lies exactly on its elements. For a list that is not a
|
|
403
|
-
* group, `multiplicity` may not be an integer.
|
|
404
|
-
*
|
|
404
|
+
* group, `multiplicity` may not be an integer. The matrices must be Cartesian and orthogonal (not
|
|
405
|
+
* those of `latticeOperations`). Throws a RangeError for a matrix that is not orthogonal (within
|
|
406
|
+
* `tolerance`, at least `EPSILON`), for a zero vector, and if the closed operations fix no common
|
|
407
|
+
* direction (a tolerance far too large, e.g. 0.5).
|
|
405
408
|
*/
|
|
406
409
|
export function siteSymmetry(
|
|
407
410
|
operations: readonly OperationArgument[],
|
|
@@ -437,6 +440,22 @@ export function wyckoffPositionOf(
|
|
|
437
440
|
|
|
438
441
|
// --- lattice basis and orbits ---------------------------------------------------------------------
|
|
439
442
|
|
|
443
|
+
/**
|
|
444
|
+
* The operations of a list that keep the metric of a cell: W with WᵀGW = G, G the metric tensor
|
|
445
|
+
* of `basis`. The operations are integer matrices on lattice coordinates, as `latticeOperations`
|
|
446
|
+
* gives them; the list is taken as it is and the kept operations are the ones of the list, in its
|
|
447
|
+
* order. The deviation counts relative to the largest entry of G (`tolerance`, default
|
|
448
|
+
* `EPSILON`). An operation combined with time reversal belongs to the magnetic API.
|
|
449
|
+
*/
|
|
450
|
+
export function residualOperations<T extends OperationArgument>(
|
|
451
|
+
operations: readonly T[],
|
|
452
|
+
basis: Mat3,
|
|
453
|
+
options?: cell.ResidualOperationsOptions,
|
|
454
|
+
): T[] {
|
|
455
|
+
checkUnitary(operations);
|
|
456
|
+
return cell.residualOperations(operations, basis, options);
|
|
457
|
+
}
|
|
458
|
+
|
|
440
459
|
/**
|
|
441
460
|
* The operations of the crystal class in the conventional lattice basis (a, b, c; for the trigonal
|
|
442
461
|
* classes the hexagonal axes), in the order of `operations` for the same setting and convention:
|
|
@@ -490,7 +509,8 @@ export function orbit(
|
|
|
490
509
|
* operation, coinciding images merged (closer than `tolerance`, default `EPSILON`, as for
|
|
491
510
|
* `siteSymmetry`), in the order in which the operations reach them, each with the indices of the
|
|
492
511
|
* operations that map the direction there. The list is taken as it is, not closed into a group.
|
|
493
|
-
* Throws a RangeError for a zero vector and for a matrix that is not orthogonal
|
|
512
|
+
* Throws a RangeError for a zero vector and for a matrix that is not orthogonal (within
|
|
513
|
+
* `tolerance`, at least `EPSILON`).
|
|
494
514
|
*/
|
|
495
515
|
export function orbitOf(
|
|
496
516
|
operations: readonly OperationArgument[],
|
|
@@ -542,7 +562,8 @@ export function tensorForm(
|
|
|
542
562
|
* The form of a tensor under the group generated by `operations`, e.g. the site symmetry of a
|
|
543
563
|
* surface normal (`siteSymmetry`) or the operations of a distorted crystal. The tensor is given by
|
|
544
564
|
* its specification or by the name of a property in `TENSOR_PROPERTIES`. The operations are
|
|
545
|
-
* Cartesian and orthogonal; a list that is not closed is closed first.
|
|
565
|
+
* Cartesian and orthogonal; a list that is not closed is closed first. Throws a RangeError for a
|
|
566
|
+
* matrix that is not orthogonal.
|
|
546
567
|
*/
|
|
547
568
|
export function tensorFormOf(
|
|
548
569
|
operations: readonly OperationArgument[],
|
|
@@ -584,13 +605,14 @@ export function allowedProperties(key: PointGroupKey): TensorPropertyName[] {
|
|
|
584
605
|
|
|
585
606
|
/**
|
|
586
607
|
* True if the group generated by `operations` allows the named property, e.g. for the site
|
|
587
|
-
* symmetry of a surface normal or the operations of a distorted crystal.
|
|
608
|
+
* symmetry of a surface normal or the operations of a distorted crystal. The matrices must be
|
|
609
|
+
* Cartesian and orthogonal; a list that is not closed is closed first. Throws a RangeError for a matrix that is not orthogonal.
|
|
588
610
|
*/
|
|
589
611
|
export function allowsPropertyOf(operations: readonly OperationArgument[], name: TensorPropertyName): boolean {
|
|
590
612
|
return tensors.tensorFormOf(unitary(operations), propertyName(name)).basis.length > 0;
|
|
591
613
|
}
|
|
592
614
|
|
|
593
|
-
/** The named properties the group generated by `operations` allows. */
|
|
615
|
+
/** The named properties the group generated by `operations` allows. Checks the operations as `allowsPropertyOf`. */
|
|
594
616
|
export function allowedPropertiesOf(operations: readonly OperationArgument[]): TensorPropertyName[] {
|
|
595
617
|
const ops = unitary(operations);
|
|
596
618
|
return TENSOR_PROPERTY_NAMES.filter((name) => tensors.tensorFormOf(ops, name).basis.length > 0);
|
package/src/index.ts
CHANGED
|
@@ -15,6 +15,31 @@ export {
|
|
|
15
15
|
type CrystalSystem,
|
|
16
16
|
type FixedAngleFamily,
|
|
17
17
|
} from './lattice.js';
|
|
18
|
+
export {
|
|
19
|
+
angleBetweenDirections,
|
|
20
|
+
angleBetweenPlanes,
|
|
21
|
+
isValidCell,
|
|
22
|
+
latticeFromParameters,
|
|
23
|
+
latticeParameters,
|
|
24
|
+
metricTensor,
|
|
25
|
+
reciprocalBasis,
|
|
26
|
+
type CellAngles,
|
|
27
|
+
type CellOperation,
|
|
28
|
+
type IsValidCellOptions,
|
|
29
|
+
type LatticeParameters,
|
|
30
|
+
type ResidualOperationsOptions,
|
|
31
|
+
} from './cell.js';
|
|
32
|
+
export {
|
|
33
|
+
changeOfAxes,
|
|
34
|
+
directionFromFourIndices,
|
|
35
|
+
directionToFourIndices,
|
|
36
|
+
planeFromFourIndices,
|
|
37
|
+
planeToFourIndices,
|
|
38
|
+
reduceIndices,
|
|
39
|
+
zoneAxis,
|
|
40
|
+
type AxisChange,
|
|
41
|
+
type FourIndices,
|
|
42
|
+
} from './indices.js';
|
|
18
43
|
|
|
19
44
|
export type { Convention, PointGroupKey, Setting, SettingOptions, SymbolOptions } from './pointGroups/pointGroups.js';
|
|
20
45
|
export { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from './symmetryDirections.js';
|
|
@@ -44,6 +69,7 @@ export {
|
|
|
44
69
|
isChiralOf,
|
|
45
70
|
isPointGroupKey,
|
|
46
71
|
latticeOperations,
|
|
72
|
+
residualOperations,
|
|
47
73
|
operations,
|
|
48
74
|
orbit,
|
|
49
75
|
orbitOf,
|
package/src/indices.ts
ADDED
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Miller and Miller–Bravais indices, the zone law and the change of axes
|
|
3
|
+
* (docs/conventions.md, "Cell, metric and indices"). Plain integers and matrices in and out.
|
|
4
|
+
*/
|
|
5
|
+
|
|
6
|
+
import { det, inverse, isSingular, transpose, type Mat3, type Vec3 } from './linalg.js';
|
|
7
|
+
|
|
8
|
+
/** A direction [UVTW] or a plane (hkil) in four indices (Miller–Bravais). */
|
|
9
|
+
export type FourIndices = readonly [number, number, number, number];
|
|
10
|
+
|
|
11
|
+
function gcd(a: number, b: number): number {
|
|
12
|
+
a = Math.abs(a);
|
|
13
|
+
b = Math.abs(b);
|
|
14
|
+
while (b) [a, b] = [b, a % b];
|
|
15
|
+
return a;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
function integers(v: readonly number[], who: string, length?: number): void {
|
|
19
|
+
if (
|
|
20
|
+
!Array.isArray(v) ||
|
|
21
|
+
(length !== undefined && v.length !== length) ||
|
|
22
|
+
v.length === 0 ||
|
|
23
|
+
!v.every((x) => Number.isSafeInteger(x))
|
|
24
|
+
) {
|
|
25
|
+
throw new RangeError(
|
|
26
|
+
`${who}: ${length === undefined ? 'a list of' : length} integers expected, not ${JSON.stringify(v)}`,
|
|
27
|
+
);
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
/** The indices divided by their greatest common divisor, signs kept. Throws a RangeError for non-integers and for all zeros. */
|
|
32
|
+
export function reduceIndices(indices: readonly number[]): number[] {
|
|
33
|
+
integers(indices, 'reduceIndices');
|
|
34
|
+
const g = indices.reduce(gcd, 0);
|
|
35
|
+
if (g === 0) throw new RangeError('reduceIndices: all indices are zero');
|
|
36
|
+
return indices.map((x) => x / g + 0);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/** The plane (hkl) of hexagonal axes as (hkil) with i = −(h + k). */
|
|
40
|
+
export function planeToFourIndices(hkl: Vec3): FourIndices {
|
|
41
|
+
integers(hkl, 'planeToFourIndices', 3);
|
|
42
|
+
if (hkl.every((x) => x === 0)) throw new RangeError('planeToFourIndices: zero vector');
|
|
43
|
+
return [hkl[0] + 0, hkl[1] + 0, -(hkl[0] + hkl[1]) + 0, hkl[2] + 0];
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/** The plane (hkil) as (hkl); throws a RangeError unless i = −(h + k). */
|
|
47
|
+
export function planeFromFourIndices(hkil: FourIndices): Vec3 {
|
|
48
|
+
integers(hkil, 'planeFromFourIndices', 4);
|
|
49
|
+
if (hkil[2] !== -(hkil[0] + hkil[1]))
|
|
50
|
+
throw new RangeError(`planeFromFourIndices: i must be −(h + k) in ${JSON.stringify(hkil)}`);
|
|
51
|
+
return [hkil[0] + 0, hkil[1] + 0, hkil[3] + 0];
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
/**
|
|
55
|
+
* The direction [uvw] of hexagonal axes as [UVTW], reduced: U = (2u − v)/3, V = (2v − u)/3,
|
|
56
|
+
* T = −(U + V), W = w, scaled to the smallest integers.
|
|
57
|
+
*/
|
|
58
|
+
export function directionToFourIndices(uvw: Vec3): FourIndices {
|
|
59
|
+
integers(uvw, 'directionToFourIndices', 3);
|
|
60
|
+
const [u, v, w] = uvw;
|
|
61
|
+
if (u === 0 && v === 0 && w === 0) throw new RangeError('directionToFourIndices: zero vector');
|
|
62
|
+
return reduceIndices([2 * u - v, 2 * v - u, -(u + v), 3 * w]) as unknown as FourIndices;
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The direction [UVTW] as [uvw], reduced: u = U − T, v = V − T, w = W; throws a RangeError unless T = −(U + V). */
|
|
66
|
+
export function directionFromFourIndices(uvtw: FourIndices): Vec3 {
|
|
67
|
+
integers(uvtw, 'directionFromFourIndices', 4);
|
|
68
|
+
if (uvtw.every((x) => x === 0)) throw new RangeError('directionFromFourIndices: zero vector');
|
|
69
|
+
const [U, V, T, W] = uvtw;
|
|
70
|
+
if (T !== -(U + V)) throw new RangeError(`directionFromFourIndices: T must be −(U + V) in ${JSON.stringify(uvtw)}`);
|
|
71
|
+
return reduceIndices([U - T, V - T, W]) as unknown as Vec3;
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
/**
|
|
75
|
+
* The zone axis [uvw] of two planes (hkl), which must not be zero vectors: the solution of the zone law hu + kv + lw = 0, the
|
|
76
|
+
* cross product h₁ × h₂ reduced (so its sign follows the order of the planes), or `null` for parallel planes.
|
|
77
|
+
*/
|
|
78
|
+
export function zoneAxis(h1: Vec3, h2: Vec3): Vec3 | null {
|
|
79
|
+
integers(h1, 'zoneAxis', 3);
|
|
80
|
+
integers(h2, 'zoneAxis', 3);
|
|
81
|
+
if (h1.every((x) => x === 0) || h2.every((x) => x === 0)) throw new RangeError('zoneAxis: zero vector');
|
|
82
|
+
const c = [h1[1] * h2[2] - h1[2] * h2[1], h1[2] * h2[0] - h1[0] * h2[2], h1[0] * h2[1] - h1[1] * h2[0]];
|
|
83
|
+
if (!c.every((x) => Number.isSafeInteger(x)))
|
|
84
|
+
throw new RangeError('zoneAxis: the cross product exceeds the safe integers');
|
|
85
|
+
if (c.every((x) => x === 0)) return null;
|
|
86
|
+
return reduceIndices(c) as unknown as Vec3;
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
/** The matrices that carry coordinates of a direction and indices of a plane to a new basis. */
|
|
90
|
+
export interface AxisChange {
|
|
91
|
+
/** Q = P⁻¹: the coordinates [uvw]′ = Q·[uvw] of a direction in the new basis. */
|
|
92
|
+
readonly direction: Mat3;
|
|
93
|
+
/** Pᵀ: the indices (hkl)′ = Pᵀ·(hkl) of a plane, i.e. (h′ k′ l′) = (h k l)·P. */
|
|
94
|
+
readonly plane: Mat3;
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
/**
|
|
98
|
+
* The transformation of indices for a change of basis (a′, b′, c′) = (a, b, c)·P (ITA Vol. A, 2006,
|
|
99
|
+
* Section 5.1.3): the columns of `P` are the new basis vectors in the old one. The coordinates of a
|
|
100
|
+
* direction transform with Q = P⁻¹, the indices of a plane with Pᵀ, so that hu + kv + lw is the same in
|
|
101
|
+
* both bases. Throws a RangeError unless det P > 0 (a right-handed basis), and for a P that is
|
|
102
|
+
* singular within rounding (the absolute value of det P at most 10⁻⁹ times the product of its
|
|
103
|
+
* column lengths).
|
|
104
|
+
*/
|
|
105
|
+
export function changeOfAxes(P: Mat3): AxisChange {
|
|
106
|
+
if (
|
|
107
|
+
!Array.isArray(P) ||
|
|
108
|
+
P.length !== 3 ||
|
|
109
|
+
!P.every((r) => Array.isArray(r) && r.length === 3 && r.every((x) => Number.isFinite(x)))
|
|
110
|
+
) {
|
|
111
|
+
throw new RangeError('changeOfAxes: P must be a 3×3 matrix of finite numbers');
|
|
112
|
+
}
|
|
113
|
+
if (!(det(P) > 0)) throw new RangeError('changeOfAxes: det P must be positive (a right-handed basis)');
|
|
114
|
+
if (isSingular(P)) throw new RangeError('changeOfAxes: P is singular within rounding');
|
|
115
|
+
const clean = (m: Mat3): Mat3 => m.map((r) => r.map((x) => x + 0)) as unknown as Mat3; // no −0
|
|
116
|
+
return { direction: clean(inverse(P)), plane: clean(transpose(P)) };
|
|
117
|
+
}
|
package/src/linalg.ts
CHANGED
|
@@ -120,10 +120,29 @@ export function matricesEqual(a: Mat3, b: Mat3): boolean {
|
|
|
120
120
|
return true;
|
|
121
121
|
}
|
|
122
122
|
|
|
123
|
-
/**
|
|
123
|
+
/**
|
|
124
|
+
* Below this ratio of |det| to the product of the column lengths (Hadamard's bound, the largest
|
|
125
|
+
* |det| columns of these lengths can have) a matrix counts as singular. The ratio depends neither
|
|
126
|
+
* on the unit of the entries nor on the lengths of the columns relative to each other; for a cell
|
|
127
|
+
* it is V/(abc).
|
|
128
|
+
*/
|
|
129
|
+
const SINGULAR_RATIO = 1e-9;
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* True if `a` is singular within rounding: |det a| at most `SINGULAR_RATIO` times the product of
|
|
133
|
+
* its column lengths. The one criterion for `inverse` and for the bases of the cell functions. Also
|
|
134
|
+
* true for a zero column and for a matrix with NaN or an infinite entry.
|
|
135
|
+
*/
|
|
136
|
+
export function isSingular(a: Mat3): boolean {
|
|
137
|
+
const bound = [0, 1, 2].reduce((p, j) => p * Math.hypot(a[0][j], a[1][j], a[2][j]), 1);
|
|
138
|
+
// A comparison that is false for NaN, so a matrix with NaN counts as singular.
|
|
139
|
+
return !(Number.isFinite(bound) && Math.abs(det(a)) > SINGULAR_RATIO * bound);
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
/** The inverse of a regular matrix (by the adjugate); throws for a singular one (`isSingular`), whatever the scale of its entries. */
|
|
124
143
|
export function inverse(a: Mat3): Mat3 {
|
|
144
|
+
if (isSingular(a)) throw new RangeError('inverse: singular matrix');
|
|
125
145
|
const d = det(a);
|
|
126
|
-
if (Math.abs(d) < EPSILON) throw new RangeError('inverse: singular matrix');
|
|
127
146
|
const c = (i: number, j: number): number => {
|
|
128
147
|
const [r0, r1] = [0, 1, 2].filter((k) => k !== i);
|
|
129
148
|
const [s0, s1] = [0, 1, 2].filter((k) => k !== j);
|
package/src/magnetic.ts
CHANGED
|
@@ -20,6 +20,31 @@ export {
|
|
|
20
20
|
type CrystalSystem,
|
|
21
21
|
type FixedAngleFamily,
|
|
22
22
|
} from './lattice.js';
|
|
23
|
+
export {
|
|
24
|
+
angleBetweenDirections,
|
|
25
|
+
angleBetweenPlanes,
|
|
26
|
+
isValidCell,
|
|
27
|
+
latticeFromParameters,
|
|
28
|
+
latticeParameters,
|
|
29
|
+
metricTensor,
|
|
30
|
+
reciprocalBasis,
|
|
31
|
+
type CellAngles,
|
|
32
|
+
type CellOperation,
|
|
33
|
+
type IsValidCellOptions,
|
|
34
|
+
type LatticeParameters,
|
|
35
|
+
type ResidualOperationsOptions,
|
|
36
|
+
} from './cell.js';
|
|
37
|
+
export {
|
|
38
|
+
changeOfAxes,
|
|
39
|
+
directionFromFourIndices,
|
|
40
|
+
directionToFourIndices,
|
|
41
|
+
planeFromFourIndices,
|
|
42
|
+
planeToFourIndices,
|
|
43
|
+
reduceIndices,
|
|
44
|
+
zoneAxis,
|
|
45
|
+
type AxisChange,
|
|
46
|
+
type FourIndices,
|
|
47
|
+
} from './indices.js';
|
|
23
48
|
|
|
24
49
|
import type {
|
|
25
50
|
PointGroupKey as ClassKey,
|
|
@@ -67,6 +92,7 @@ export {
|
|
|
67
92
|
type OperationKind,
|
|
68
93
|
type SymmetryDirection,
|
|
69
94
|
} from './pointGroups/elements.js';
|
|
95
|
+
export { residualMagneticOperations as residualOperations, type MagneticCellOperation } from './cell.js';
|
|
70
96
|
export { siteSymmetry, type SiteSymmetry, type SiteSymmetryOptions } from './siteSymmetry.js';
|
|
71
97
|
export {
|
|
72
98
|
describeOperationsOf,
|
package/src/operations.ts
CHANGED
|
@@ -40,6 +40,26 @@ export function checkOrthogonal(m: Mat3, what: string): void {
|
|
|
40
40
|
}
|
|
41
41
|
}
|
|
42
42
|
|
|
43
|
+
/**
|
|
44
|
+
* Throws unless mᵀm = 1 within the tolerance: the check of `checkOrthogonal` for a function with a
|
|
45
|
+
* `tolerance` option, so that a matrix with rounding errors (e.g. rounded to 4 decimals) passes
|
|
46
|
+
* with a larger one. Never stricter than `checkOrthogonal`.
|
|
47
|
+
*/
|
|
48
|
+
export function checkOrthogonalWithin(m: Mat3, what: string, tolerance: number): void {
|
|
49
|
+
if (tolerance <= EPSILON) {
|
|
50
|
+
checkOrthogonal(m, what);
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
for (let i = 0; i < 3; i++) {
|
|
54
|
+
for (let j = 0; j < 3; j++) {
|
|
55
|
+
const d = m[0][i] * m[0][j] + m[1][i] * m[1][j] + m[2][i] * m[2][j];
|
|
56
|
+
if (!(Math.abs(d - (i === j ? 1 : 0)) < tolerance)) {
|
|
57
|
+
throw new RangeError(`${what} is not an orthogonal (Cartesian) matrix: ${JSON.stringify(m)}`);
|
|
58
|
+
}
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
}
|
|
62
|
+
|
|
43
63
|
/**
|
|
44
64
|
* Checks operations that a caller passes in: each must say whether it is combined with time
|
|
45
65
|
* reversal. Without this, an operation that lacks `timeReversal` (as the crystallographic API
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
*/
|
|
6
6
|
|
|
7
7
|
import { det, multiply, trace, type Mat3, type Vec3 } from '../linalg.js';
|
|
8
|
-
import {
|
|
8
|
+
import { checkOrthogonalWithin, checkTimeReversal, type Operation } from '../operations.js';
|
|
9
9
|
import { EPSILON } from '../tolerances.js';
|
|
10
10
|
import { axialVector, rotationAxis, type OperationKind } from './elements.js';
|
|
11
11
|
import {
|
|
@@ -62,22 +62,6 @@ export interface CartesianOperationDescription {
|
|
|
62
62
|
readonly timeReversal: boolean;
|
|
63
63
|
}
|
|
64
64
|
|
|
65
|
-
/** Throws unless mᵀm = 1 within the tolerance (a matrix with rounding errors passes with a larger one). */
|
|
66
|
-
function checkOrthogonalWithin(m: Mat3, what: string, tolerance: number): void {
|
|
67
|
-
if (tolerance <= EPSILON) {
|
|
68
|
-
checkOrthogonal(m, what);
|
|
69
|
-
return;
|
|
70
|
-
}
|
|
71
|
-
for (let i = 0; i < 3; i++) {
|
|
72
|
-
for (let j = 0; j < 3; j++) {
|
|
73
|
-
const d = m[0][i] * m[0][j] + m[1][i] * m[1][j] + m[2][i] * m[2][j];
|
|
74
|
-
if (!(Math.abs(d - (i === j ? 1 : 0)) < tolerance)) {
|
|
75
|
-
throw new RangeError(`${what} is not an orthogonal (Cartesian) matrix: ${JSON.stringify(m)}`);
|
|
76
|
-
}
|
|
77
|
-
}
|
|
78
|
-
}
|
|
79
|
-
}
|
|
80
|
-
|
|
81
65
|
/** No point group has more than 96 operations (m-3m1'). */
|
|
82
66
|
const MAX_ORDER = 96;
|
|
83
67
|
|
|
@@ -181,7 +165,8 @@ function keyOfSignature(s: string): MagneticPointGroupKey | undefined {
|
|
|
181
165
|
* Time reversal counts: a list with time reversal gives a magnetic point group. Returns undefined
|
|
182
166
|
* if the operations generate no point group (an operation of order 5, a group larger than 96).
|
|
183
167
|
* Throws a RangeError for a matrix that is not orthogonal (within `tolerance`, at least
|
|
184
|
-
* `EPSILON`)
|
|
168
|
+
* `EPSILON`) and for an operation that does not say whether it is combined with time reversal.
|
|
169
|
+
* The classes `1` and `-1` have one setting and no orientation, so they always have
|
|
185
170
|
* setting 1.
|
|
186
171
|
*/
|
|
187
172
|
export function pointGroupOf(
|
|
@@ -243,7 +228,8 @@ function describe(op: Operation, i: number, tolerance: number): CartesianOperati
|
|
|
243
228
|
* by lattice directions, since the list need not belong to a setting; for a point group given by its
|
|
244
229
|
* key, `describeOperations` names them. Throws a RangeError for a matrix that is not orthogonal or
|
|
245
230
|
* not a crystallographic operation (a rotation part by an angle other than 360°/n, n = 1, 2, 3, 4,
|
|
246
|
-
* 6), both within `tolerance` (default `EPSILON`, as for `pointGroupOf`)
|
|
231
|
+
* 6), both within `tolerance` (default `EPSILON`, as for `pointGroupOf`), and for an operation that
|
|
232
|
+
* does not say whether it is combined with time reversal.
|
|
247
233
|
*/
|
|
248
234
|
export function describeOperationsOf(
|
|
249
235
|
operations: readonly Operation[],
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
|
|
6
6
|
import { crystalFamily, latticeBasis } from '../lattice.js';
|
|
7
7
|
import { apply, inverse, multiply, type Mat3, type Vec3 } from '../linalg.js';
|
|
8
|
-
import {
|
|
8
|
+
import { checkOrthogonalWithin, type Operation } from '../operations.js';
|
|
9
9
|
import { siteTolerance } from '../siteSymmetry.js';
|
|
10
10
|
import type { Uvw } from '../symmetryDirections.js';
|
|
11
11
|
import {
|
|
@@ -196,7 +196,7 @@ export interface OrbitPole {
|
|
|
196
196
|
* `siteSymmetry`), in the order in which the operations reach them, each with the indices of the
|
|
197
197
|
* operations that map the direction there. The list is taken as it is, not closed into a group.
|
|
198
198
|
* Time reversal is ignored. Throws a RangeError for a zero vector and for a matrix that is not
|
|
199
|
-
* orthogonal (Cartesian
|
|
199
|
+
* orthogonal (Cartesian, not one of `latticeOperations`; within `tolerance`, at least `EPSILON`).
|
|
200
200
|
*/
|
|
201
201
|
export function orbitOf(
|
|
202
202
|
operations: readonly { readonly matrix: Mat3 }[],
|
|
@@ -204,7 +204,7 @@ export function orbitOf(
|
|
|
204
204
|
options?: OrbitOptions,
|
|
205
205
|
): readonly OrbitPole[] {
|
|
206
206
|
const tolerance = siteTolerance(options);
|
|
207
|
-
operations.forEach((op, i) =>
|
|
207
|
+
operations.forEach((op, i) => checkOrthogonalWithin(op.matrix, `Operation ${i}`, tolerance));
|
|
208
208
|
const n = Math.hypot(direction[0], direction[1], direction[2]);
|
|
209
209
|
if (!(n > 0) || !Number.isFinite(n)) throw new RangeError(`Not a direction: ${JSON.stringify(direction)}`);
|
|
210
210
|
const u: Vec3 = [direction[0] / n, direction[1] / n, direction[2] / n];
|
|
@@ -23,7 +23,9 @@ function check(operations: readonly Operation[]): void {
|
|
|
23
23
|
/**
|
|
24
24
|
* True if the group generated by `operations` contains the inversion, not combined with time
|
|
25
25
|
* reversal: e.g. for the operations of a distorted crystal. A list that is not closed is closed
|
|
26
|
-
* first. For a point group given by its key, read `pointGroup(key).centrosymmetric`.
|
|
26
|
+
* first. For a point group given by its key, read `pointGroup(key).centrosymmetric`. Throws a
|
|
27
|
+
* RangeError for a matrix that is not orthogonal and for an operation that does not say whether it
|
|
28
|
+
* is combined with time reversal.
|
|
27
29
|
*/
|
|
28
30
|
export function isCentrosymmetricOf(operations: readonly Operation[]): boolean {
|
|
29
31
|
check(operations);
|
|
@@ -33,7 +35,9 @@ export function isCentrosymmetricOf(operations: readonly Operation[]): boolean {
|
|
|
33
35
|
/**
|
|
34
36
|
* True if the group generated by `operations` is chiral: proper rotations only, with or without
|
|
35
37
|
* time reversal (products of proper rotations are proper, so the list need not be closed). For a
|
|
36
|
-
* point group given by its key, read `pointGroup(key).chiral`.
|
|
38
|
+
* point group given by its key, read `pointGroup(key).chiral`. Throws a RangeError for a matrix that
|
|
39
|
+
* is not orthogonal and for an operation that does not say whether it is combined with time
|
|
40
|
+
* reversal.
|
|
37
41
|
*/
|
|
38
42
|
export function isChiralOf(operations: readonly Operation[]): boolean {
|
|
39
43
|
check(operations);
|
package/src/siteSymmetry.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { apply, matricesEqual, multiply, type Vec3 } from './linalg.js';
|
|
7
|
-
import type
|
|
7
|
+
import { checkOrthogonalWithin, type Operation } from './operations.js';
|
|
8
8
|
import { EPSILON } from './tolerances.js';
|
|
9
9
|
|
|
10
10
|
/** Options of `siteSymmetry` and `wyckoffPositionOf`. */
|
|
@@ -119,8 +119,10 @@ export function siteTolerance(options?: SiteSymmetryOptions): number {
|
|
|
119
119
|
* within the tolerance are closed under the products found in the list and the direction is set onto
|
|
120
120
|
* their fixed space, repeated until stable, so that for a group the result is a subgroup and the
|
|
121
121
|
* set direction lies exactly on its elements. For a list that is not a group, `multiplicity` may
|
|
122
|
-
* not be an integer.
|
|
123
|
-
*
|
|
122
|
+
* not be an integer. The matrices must be Cartesian and orthogonal (not those of
|
|
123
|
+
* `latticeOperations`). Throws a RangeError for a matrix that is not orthogonal (within
|
|
124
|
+
* `tolerance`, at least `EPSILON`), for a zero vector, and if the closed operations fix no common
|
|
125
|
+
* direction (a tolerance far too large, e.g. 0.5).
|
|
124
126
|
*/
|
|
125
127
|
export function siteSymmetry(
|
|
126
128
|
operations: readonly Operation[],
|
|
@@ -128,6 +130,7 @@ export function siteSymmetry(
|
|
|
128
130
|
options?: SiteSymmetryOptions,
|
|
129
131
|
): SiteSymmetry {
|
|
130
132
|
const tolerance = siteTolerance(options);
|
|
133
|
+
operations.forEach((op, i) => checkOrthogonalWithin(op.matrix, `Operation ${i}`, tolerance));
|
|
131
134
|
const v = unit(direction);
|
|
132
135
|
const fixing = (w: Vec3): number[] => {
|
|
133
136
|
const out: number[] = [];
|
|
@@ -246,7 +246,9 @@ export function tensorForm(
|
|
|
246
246
|
* surface normal (`siteSymmetry`) or the operations of a distorted crystal. The tensor is given by
|
|
247
247
|
* its specification or by the name of a property in `TENSOR_PROPERTIES`. The operations are
|
|
248
248
|
* Cartesian and orthogonal, and each says whether it is combined with time reversal
|
|
249
|
-
* (`timeReversal`, `true` or `false`); a list that is not closed is closed first.
|
|
249
|
+
* (`timeReversal`, `true` or `false`); a list that is not closed is closed first. Throws a
|
|
250
|
+
* RangeError for a matrix that is not orthogonal and for an operation that does not say whether it
|
|
251
|
+
* is combined with time reversal.
|
|
250
252
|
*/
|
|
251
253
|
export function tensorFormOf(operations: readonly Operation[], spec: TensorSpec | TensorPropertyName): TensorForm {
|
|
252
254
|
const resolved = specOf(spec);
|
|
@@ -38,13 +38,15 @@ export function allowedProperties(key: MagneticPointGroupKey): TensorPropertyNam
|
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
40
|
* True if the group generated by `operations` allows the named property, e.g. for the site
|
|
41
|
-
* symmetry of a surface normal or the operations of a distorted crystal.
|
|
41
|
+
* symmetry of a surface normal or the operations of a distorted crystal. The matrices must be
|
|
42
|
+
* Cartesian and orthogonal; a list that is not closed is closed first. Throws a RangeError for a matrix that is not
|
|
43
|
+
* orthogonal and for an operation that does not say whether it is combined with time reversal.
|
|
42
44
|
*/
|
|
43
45
|
export function allowsPropertyOf(operations: readonly Operation[], name: TensorPropertyName): boolean {
|
|
44
46
|
return tensorFormOf(operations, named(name)).basis.length > 0;
|
|
45
47
|
}
|
|
46
48
|
|
|
47
|
-
/** The named properties the group generated by `operations` allows. */
|
|
49
|
+
/** The named properties the group generated by `operations` allows. Checks the operations as `allowsPropertyOf`. */
|
|
48
50
|
export function allowedPropertiesOf(operations: readonly Operation[]): TensorPropertyName[] {
|
|
49
51
|
return TENSOR_PROPERTY_NAMES.filter((name) => allowsPropertyOf(operations, name));
|
|
50
52
|
}
|
package/src/version.ts
CHANGED