symcrys 0.5.0 → 0.6.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/README.md +15 -3
- package/dist/crystalClasses.d.ts +222 -0
- package/dist/crystalClasses.d.ts.map +1 -0
- package/dist/crystalClasses.js +295 -0
- package/dist/crystalClasses.js.map +1 -0
- package/dist/index.d.ts +11 -9
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +6 -8
- package/dist/index.js.map +1 -1
- package/dist/lattice.d.ts +5 -1
- package/dist/lattice.d.ts.map +1 -1
- package/dist/lattice.js +3 -1
- package/dist/lattice.js.map +1 -1
- package/dist/magnetic.d.ts +36 -0
- package/dist/magnetic.d.ts.map +1 -0
- package/dist/magnetic.js +22 -0
- package/dist/magnetic.js.map +1 -0
- package/dist/operations.d.ts +10 -0
- package/dist/operations.d.ts.map +1 -1
- package/dist/operations.js +25 -0
- package/dist/operations.js.map +1 -1
- package/dist/pointGroups/data.d.ts +36 -1
- package/dist/pointGroups/data.d.ts.map +1 -1
- package/dist/pointGroups/data.js +29 -21
- package/dist/pointGroups/data.js.map +1 -1
- package/dist/pointGroups/elements.d.ts +16 -6
- package/dist/pointGroups/elements.d.ts.map +1 -1
- package/dist/pointGroups/elements.js +7 -2
- package/dist/pointGroups/elements.js.map +1 -1
- package/dist/pointGroups/magneticData.d.ts +66 -0
- package/dist/pointGroups/magneticData.d.ts.map +1 -0
- package/dist/pointGroups/magneticData.js +184 -0
- package/dist/pointGroups/magneticData.js.map +1 -0
- package/dist/pointGroups/magneticSymbols.d.ts +22 -0
- package/dist/pointGroups/magneticSymbols.d.ts.map +1 -0
- package/dist/pointGroups/magneticSymbols.js +103 -0
- package/dist/pointGroups/magneticSymbols.js.map +1 -0
- package/dist/pointGroups/pointGroups.d.ts +102 -24
- package/dist/pointGroups/pointGroups.d.ts.map +1 -1
- package/dist/pointGroups/pointGroups.js +293 -47
- package/dist/pointGroups/pointGroups.js.map +1 -1
- package/dist/pointGroups/properties.d.ts +25 -16
- package/dist/pointGroups/properties.d.ts.map +1 -1
- package/dist/pointGroups/properties.js +46 -56
- package/dist/pointGroups/properties.js.map +1 -1
- package/dist/pointGroups/wyckoff.d.ts +4 -1
- package/dist/pointGroups/wyckoff.d.ts.map +1 -1
- package/dist/pointGroups/wyckoff.js +6 -2
- package/dist/pointGroups/wyckoff.js.map +1 -1
- package/dist/siteSymmetry.d.ts +2 -1
- package/dist/siteSymmetry.d.ts.map +1 -1
- package/dist/siteSymmetry.js.map +1 -1
- package/dist/tensors/propertyTable.d.ts +45 -0
- package/dist/tensors/propertyTable.d.ts.map +1 -0
- package/dist/tensors/propertyTable.js +41 -0
- package/dist/tensors/propertyTable.js.map +1 -0
- package/dist/tensors/tensorForm.d.ts +21 -10
- package/dist/tensors/tensorForm.d.ts.map +1 -1
- package/dist/tensors/tensorForm.js +23 -24
- package/dist/tensors/tensorForm.js.map +1 -1
- package/dist/tensors/tensorProperties.d.ts +30 -0
- package/dist/tensors/tensorProperties.d.ts.map +1 -0
- package/dist/tensors/tensorProperties.js +44 -0
- package/dist/tensors/tensorProperties.js.map +1 -0
- package/dist/version.d.ts +6 -2
- package/dist/version.d.ts.map +1 -1
- package/dist/version.js +6 -2
- package/dist/version.js.map +1 -1
- package/package.json +6 -2
- package/src/crystalClasses.ts +451 -0
- package/src/index.ts +32 -38
- package/src/lattice.ts +5 -1
- package/src/magnetic.ts +88 -0
- package/src/operations.ts +31 -0
- package/src/pointGroups/data.ts +33 -22
- package/src/pointGroups/elements.ts +27 -8
- package/src/pointGroups/magneticData.ts +328 -0
- package/src/pointGroups/magneticSymbols.ts +110 -0
- package/src/pointGroups/pointGroups.ts +388 -65
- package/src/pointGroups/properties.ts +47 -56
- package/src/pointGroups/wyckoff.ts +17 -2
- package/src/siteSymmetry.ts +2 -1
- package/src/tensors/propertyTable.ts +89 -0
- package/src/tensors/tensorForm.ts +39 -28
- package/src/tensors/tensorProperties.ts +50 -0
- package/src/version.ts +6 -2
|
@@ -1,73 +1,64 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Properties
|
|
3
|
-
*
|
|
4
|
-
*
|
|
2
|
+
* Properties that follow from operations, for a list of operations of a caller, and the holohedry
|
|
3
|
+
* of a crystal system. The properties of a point group given by its key are fields of
|
|
4
|
+
* `pointGroup(key)` (pointGroups.ts). Properties that are the question whether a tensor is allowed
|
|
5
|
+
* (polar, piezoelectric, ferroaxial, ferromagnetic, …) are named tensor properties
|
|
6
|
+
* (tensors/tensorProperties.ts).
|
|
5
7
|
*/
|
|
6
8
|
|
|
9
|
+
import type { CrystalSystem } from '../lattice.js';
|
|
7
10
|
import { INVERSION, det, matricesEqual } from '../linalg.js';
|
|
8
|
-
import {
|
|
9
|
-
import {
|
|
10
|
-
import { POINT_GROUP_KEYS, type PointGroupKey } from './data.js';
|
|
11
|
-
import { operations } from './pointGroups.js';
|
|
12
|
-
import { tensorForm } from '../tensors/tensorForm.js';
|
|
13
|
-
|
|
14
|
-
/** Operations in setting 1, the frame all stored data share. */
|
|
15
|
-
const stored = (key: PointGroupKey): readonly Operation[] => operations(key, { setting: 1 });
|
|
16
|
-
|
|
17
|
-
/** Contains the inversion. */
|
|
18
|
-
export function isCentrosymmetric(key: PointGroupKey): boolean {
|
|
19
|
-
return stored(key).some((op) => !op.timeReversal && matricesEqual(op.matrix, INVERSION));
|
|
20
|
-
}
|
|
11
|
+
import { checkOrthogonal, checkTimeReversal, closeGroup, type Operation } from '../operations.js';
|
|
12
|
+
import type { PointGroupKey } from './data.js';
|
|
21
13
|
|
|
22
14
|
/**
|
|
23
|
-
*
|
|
24
|
-
*
|
|
15
|
+
* What every function for a list of operations asks of the list: Cartesian (orthogonal) matrices,
|
|
16
|
+
* and of every operation whether it is combined with time reversal, as `tensorFormOf` does.
|
|
25
17
|
*/
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
for (let j = 0; j < 3; j++) {
|
|
30
|
-
let sum = 0;
|
|
31
|
-
for (const op of ops) sum += op.matrix[i][j];
|
|
32
|
-
if (Math.abs(sum / ops.length) > EPSILON) return true;
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
|
-
return false;
|
|
18
|
+
function check(operations: readonly Operation[]): void {
|
|
19
|
+
operations.forEach((op, i) => checkOrthogonal(op.matrix, `Operation ${i}`));
|
|
20
|
+
checkTimeReversal(operations);
|
|
36
21
|
}
|
|
37
22
|
|
|
38
|
-
/**
|
|
39
|
-
|
|
40
|
-
|
|
23
|
+
/**
|
|
24
|
+
* True if the group generated by `operations` contains the inversion, not combined with time
|
|
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`.
|
|
27
|
+
*/
|
|
28
|
+
export function isCentrosymmetricOf(operations: readonly Operation[]): boolean {
|
|
29
|
+
check(operations);
|
|
30
|
+
return closeGroup(operations).some((op) => !op.timeReversal && matricesEqual(op.matrix, INVERSION));
|
|
41
31
|
}
|
|
42
32
|
|
|
43
|
-
|
|
44
|
-
|
|
33
|
+
/**
|
|
34
|
+
* True if the group generated by `operations` is chiral: proper rotations only, with or without
|
|
35
|
+
* 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`.
|
|
37
|
+
*/
|
|
38
|
+
export function isChiralOf(operations: readonly Operation[]): boolean {
|
|
39
|
+
check(operations);
|
|
40
|
+
return operations.every((op) => det(op.matrix) > 0);
|
|
45
41
|
}
|
|
46
42
|
|
|
47
|
-
const
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
const product = compose(operation(INVERSION), op);
|
|
57
|
-
if (!withInversion.some((x) => operationsEqual(x, product))) withInversion.push(product);
|
|
58
|
-
}
|
|
59
|
-
const laue = POINT_GROUP_KEYS.find((k) => isCentrosymmetric(k) && sameSet(withInversion, stored(k)));
|
|
60
|
-
if (!laue) throw new Error(`laueClass: no centrosymmetric class matches ${key}`);
|
|
61
|
-
laueCache.set(key, laue);
|
|
62
|
-
return laue;
|
|
63
|
-
}
|
|
43
|
+
const HOLOHEDRY: Readonly<Record<CrystalSystem, PointGroupKey>> = Object.freeze({
|
|
44
|
+
triclinic: '-1',
|
|
45
|
+
monoclinic: '2/m',
|
|
46
|
+
orthorhombic: 'mmm',
|
|
47
|
+
tetragonal: '4/mmm',
|
|
48
|
+
trigonal: '-3m',
|
|
49
|
+
hexagonal: '6/mmm',
|
|
50
|
+
cubic: 'm-3m',
|
|
51
|
+
});
|
|
64
52
|
|
|
65
53
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
54
|
+
* The holohedry of a crystal system: the crystal class that is the point symmetry of a lattice of
|
|
55
|
+
* the system (ITA Table 2.1.1.1, the Laue groups in full boxes). For the trigonal system it is
|
|
56
|
+
* `-3m`, the symmetry of the rhombohedral lattice. The trigonal classes also occur with the
|
|
57
|
+
* hexagonal lattice, whose symmetry is `6/mmm`: the holohedry of the crystal family is
|
|
58
|
+
* `holohedry(crystalFamily(system))`, which is what the lattice basis of this library
|
|
59
|
+
* (`latticeBasis`, hexagonal axes for both systems) has.
|
|
68
60
|
*/
|
|
69
|
-
export function
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
);
|
|
61
|
+
export function holohedry(system: CrystalSystem): PointGroupKey {
|
|
62
|
+
if (!Object.hasOwn(HOLOHEDRY, system)) throw new RangeError(`Unknown crystal system: ${JSON.stringify(system)}`);
|
|
63
|
+
return HOLOHEDRY[system];
|
|
73
64
|
}
|
|
@@ -7,7 +7,14 @@
|
|
|
7
7
|
import { apply, inverse, transpose, type Mat3, type Vec3 } from '../linalg.js';
|
|
8
8
|
import { crystalFamily, latticeBasis } from '../lattice.js';
|
|
9
9
|
import { POINT_GROUP_DATA } from './data.js';
|
|
10
|
-
import {
|
|
10
|
+
import {
|
|
11
|
+
isMagneticPointGroupKey,
|
|
12
|
+
isPointGroupKey,
|
|
13
|
+
operations,
|
|
14
|
+
settings,
|
|
15
|
+
type PointGroupKey,
|
|
16
|
+
type SettingOptions,
|
|
17
|
+
} from './pointGroups.js';
|
|
11
18
|
import { siteSymmetry, siteTolerance, type SiteSymmetryOptions } from '../siteSymmetry.js';
|
|
12
19
|
import { ITA_WYCKOFF, type WyckoffRow } from './wyckoffData.js';
|
|
13
20
|
|
|
@@ -31,6 +38,7 @@ export interface WyckoffPosition {
|
|
|
31
38
|
readonly millerIndices: string;
|
|
32
39
|
/** A representative face with numbers: `millerIndices` with h = 3, k = 2, l = 1. */
|
|
33
40
|
readonly representative: {
|
|
41
|
+
/** The Miller indices (hkl) of the face. */
|
|
34
42
|
readonly hkl: Hkl;
|
|
35
43
|
/**
|
|
36
44
|
* Its face normal, a Cartesian unit vector. Monoclinic and triclinic: the normal for a, b, c along
|
|
@@ -42,6 +50,7 @@ export interface WyckoffPosition {
|
|
|
42
50
|
readonly siteSymmetryOperations: readonly number[];
|
|
43
51
|
}
|
|
44
52
|
|
|
53
|
+
/** Convention and setting (`SettingOptions`) and the tolerance of `siteSymmetry` (`SiteSymmetryOptions`). */
|
|
45
54
|
export type WyckoffOptions = SettingOptions & SiteSymmetryOptions;
|
|
46
55
|
|
|
47
56
|
/** The values substituted into ITA's Miller indices for the numeric representative. */
|
|
@@ -150,6 +159,11 @@ function printedRows(key: PointGroupKey, setting: number): readonly WyckoffRow[]
|
|
|
150
159
|
const cache = new Map<string, readonly WyckoffPosition[]>();
|
|
151
160
|
|
|
152
161
|
function itcSetting(key: PointGroupKey, options?: SettingOptions): number {
|
|
162
|
+
if (isMagneticPointGroupKey(key) && !isPointGroupKey(key)) {
|
|
163
|
+
throw new RangeError(
|
|
164
|
+
`Wyckoff positions are given for the 32 crystal classes only; ${JSON.stringify(key)} is a magnetic point group`,
|
|
165
|
+
);
|
|
166
|
+
}
|
|
153
167
|
if ((options?.convention ?? 'itc') !== 'itc') {
|
|
154
168
|
throw new RangeError("Wyckoff positions exist in the ITC convention only (convention 'itc')");
|
|
155
169
|
}
|
|
@@ -161,7 +175,8 @@ function itcSetting(key: PointGroupKey, options?: SettingOptions): number {
|
|
|
161
175
|
|
|
162
176
|
/**
|
|
163
177
|
* The Wyckoff positions of a point group for directions, in ITA's printed order (general position
|
|
164
|
-
* first), in the ITC convention only (throws a RangeError for
|
|
178
|
+
* first), for the 32 crystal classes and in the ITC convention only (throws a RangeError for a
|
|
179
|
+
* magnetic point group with time reversal and for `'birss'`). The point at the origin
|
|
165
180
|
* (letter o) is not a direction and is left out. For `mm2` settings 2 and 3 (`2mm`, `m2m`), which
|
|
166
181
|
* ITA does not print, the positions of setting 1 carried into their frame.
|
|
167
182
|
*/
|
package/src/siteSymmetry.ts
CHANGED
|
@@ -7,10 +7,11 @@ 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
|
|
|
10
|
+
/** Options of `siteSymmetry` and `wyckoffPositionOf`. */
|
|
10
11
|
export interface SiteSymmetryOptions {
|
|
11
12
|
/**
|
|
12
13
|
* A direction counts as fixed by an operation if the operation moves its unit vector by less
|
|
13
|
-
* than this (Euclidean distance). Default
|
|
14
|
+
* than this (Euclidean distance). Default 10⁻⁶; a caller whose directions carry
|
|
14
15
|
* rounding errors (e.g. read from a rounded link) passes a larger value.
|
|
15
16
|
*/
|
|
16
17
|
readonly tolerance?: number;
|
|
@@ -0,0 +1,89 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Named tensor properties: physical properties of a crystal that a point group allows if and only
|
|
3
|
+
* if it allows a non-zero tensor of a given kind. The table is data: a name, the kind of tensor
|
|
4
|
+
* (`TensorSpec`) and the print source of that definition. `allowsProperty` and `tensorForm` look a
|
|
5
|
+
* name up here (docs/conventions.md, "Named tensor properties").
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import type { TensorSpec } from './tensorForm.js';
|
|
9
|
+
|
|
10
|
+
/** A named property: the tensor that describes it, what it is and where it is defined. */
|
|
11
|
+
export interface TensorProperty {
|
|
12
|
+
/** The kind of tensor whose non-zero form means that the property is allowed. */
|
|
13
|
+
readonly spec: TensorSpec;
|
|
14
|
+
/** The physical quantity the tensor relates. */
|
|
15
|
+
readonly description: string;
|
|
16
|
+
/** Print source of the definition, with printed page. */
|
|
17
|
+
readonly source: string;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const property = (spec: TensorSpec, description: string, source: string): TensorProperty =>
|
|
21
|
+
Object.freeze({ spec: Object.freeze(spec), description, source });
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* The named tensor properties. For each name, the tensor that describes the property, what it is,
|
|
25
|
+
* and its print source. `'gyrotropic'` is optical activity.
|
|
26
|
+
*
|
|
27
|
+
* @remarks Names are adjectives, one lower-case word each (maintainer, 2026-11-19, #41).
|
|
28
|
+
*/
|
|
29
|
+
export const TENSOR_PROPERTIES = Object.freeze({
|
|
30
|
+
/** Spontaneous polarization: a time-even polar vector. */
|
|
31
|
+
pyroelectric: property(
|
|
32
|
+
{ rank: 1, parity: 'polar', timeParity: 'i', intrinsic: 'none' },
|
|
33
|
+
'Spontaneous electric polarization, which changes with temperature: a polar vector p_i.',
|
|
34
|
+
'ITC Vol. D (2013), § 1.1.4.4.2, p. 12; classes: ITA (2016) Table 3.2.2.1, p. 738',
|
|
35
|
+
),
|
|
36
|
+
/** Ferroaxial order: a time-even axial vector. */
|
|
37
|
+
ferroaxial: property(
|
|
38
|
+
{ rank: 1, parity: 'axial', timeParity: 'i', intrinsic: 'none' },
|
|
39
|
+
'Ferroaxial (ferro-rotational) order, e.g. a net rotation of structural units about an axis: an axial vector A_i.',
|
|
40
|
+
'Hlinka, Privratska, Ondrejkovic & Janovec, Phys. Rev. Lett. 116, 177602 (2016); classes: Birss (1966), Tables 4a and 4c, pp. 56–58',
|
|
41
|
+
),
|
|
42
|
+
/** The piezoelectric effect (and second-harmonic generation, which has the same tensor): polar, rank 3, symmetric in j, k. */
|
|
43
|
+
piezoelectric: property(
|
|
44
|
+
{ rank: 3, parity: 'polar', timeParity: 'i', intrinsic: 'jk' },
|
|
45
|
+
'Electric polarization linear in stress, P_i = d_ijk T_jk: a polar tensor of rank 3, symmetric in j, k.',
|
|
46
|
+
'ITC Vol. D (2013), § 1.1.4.4.3, p. 12; classes: ITA (2016) Table 3.2.2.1, p. 738',
|
|
47
|
+
),
|
|
48
|
+
/** Optical activity: the symmetric axial tensor of rank 2. */
|
|
49
|
+
gyrotropic: property(
|
|
50
|
+
{ rank: 2, parity: 'axial', timeParity: 'i', intrinsic: 'ij' },
|
|
51
|
+
'Optical activity (optical rotation), G = g_ij α_i α_j: the symmetric part of the axial gyration tensor of rank 2.',
|
|
52
|
+
'ITC Vol. D (2013), § 1.1.4.10.7.2, p. 30; classes: ITA (2016) Table 3.2.2.1, p. 738',
|
|
53
|
+
),
|
|
54
|
+
/** Spontaneous magnetization: a time-odd axial vector (magnetic API only). */
|
|
55
|
+
ferromagnetic: property(
|
|
56
|
+
{ rank: 1, parity: 'axial', timeParity: 'c', intrinsic: 'none' },
|
|
57
|
+
'Spontaneous magnetization M_s (ferromagnets, ferrimagnets, weak ferromagnets): an axial vector that changes sign under time reversal.',
|
|
58
|
+
'ITC Vol. D (2013), § 1.5.2.1 with Table 1.5.2.4, p. 113',
|
|
59
|
+
),
|
|
60
|
+
/** The linear magnetoelectric effect: a time-odd axial tensor of rank 2 (magnetic API only). */
|
|
61
|
+
magnetoelectric: property(
|
|
62
|
+
{ rank: 2, parity: 'axial', timeParity: 'c', intrinsic: 'none' },
|
|
63
|
+
'Linear magnetoelectric effect, P_i = α_ij H_j: an axial tensor of rank 2 that changes sign under time reversal.',
|
|
64
|
+
'ITC Vol. D (2013), § 1.5.8.1 with eqs. (1.5.8.2), (1.5.8.3) and Table 1.5.8.1, pp. 139–140',
|
|
65
|
+
),
|
|
66
|
+
/** The piezomagnetic effect: a time-odd axial tensor of rank 3, symmetric in j, k (magnetic API only). */
|
|
67
|
+
piezomagnetic: property(
|
|
68
|
+
{ rank: 3, parity: 'axial', timeParity: 'c', intrinsic: 'jk' },
|
|
69
|
+
'Magnetization linear in stress, M_i = Λ_ijk T_jk: an axial tensor of rank 3, symmetric in j, k, that changes sign under time reversal.',
|
|
70
|
+
'ITC Vol. D (2013), § 1.5.7.1 with eq. (1.5.7.2) and Table 1.5.7.1, pp. 134–135',
|
|
71
|
+
),
|
|
72
|
+
} satisfies Record<string, TensorProperty>);
|
|
73
|
+
|
|
74
|
+
/** Name of a tensor property in `TENSOR_PROPERTIES`. */
|
|
75
|
+
export type TensorPropertyName = keyof typeof TENSOR_PROPERTIES;
|
|
76
|
+
|
|
77
|
+
/** The names of the tensor properties, in the order of `TENSOR_PROPERTIES`. */
|
|
78
|
+
export const TENSOR_PROPERTY_NAMES = Object.freeze(Object.keys(TENSOR_PROPERTIES)) as readonly TensorPropertyName[];
|
|
79
|
+
|
|
80
|
+
/** The specification behind a property name; a specification is returned as it is. */
|
|
81
|
+
export function specOf(specOrName: TensorSpec | TensorPropertyName): TensorSpec {
|
|
82
|
+
if (typeof specOrName !== 'string') return specOrName;
|
|
83
|
+
if (!Object.hasOwn(TENSOR_PROPERTIES, specOrName)) {
|
|
84
|
+
throw new RangeError(
|
|
85
|
+
`Unknown tensor property: ${JSON.stringify(specOrName)} (known: ${TENSOR_PROPERTY_NAMES.join(', ')})`,
|
|
86
|
+
);
|
|
87
|
+
}
|
|
88
|
+
return TENSOR_PROPERTIES[specOrName].spec;
|
|
89
|
+
}
|
|
@@ -11,8 +11,9 @@
|
|
|
11
11
|
*/
|
|
12
12
|
|
|
13
13
|
import { det, type Mat3 } from '../linalg.js';
|
|
14
|
-
import { closeGroup, type Operation } from '../operations.js';
|
|
15
|
-
import { operations, settings, type
|
|
14
|
+
import { checkOrthogonal, checkTimeReversal, closeGroup, type Operation } from '../operations.js';
|
|
15
|
+
import { operations, settings, type MagneticPointGroupKey, type SettingOptions } from '../pointGroups/pointGroups.js';
|
|
16
|
+
import { specOf, type TensorPropertyName } from './propertyTable.js';
|
|
16
17
|
import { EPSILON, SNAP_EPSILON } from '../tolerances.js';
|
|
17
18
|
import { reducedRowEchelon } from './rowEchelon.js';
|
|
18
19
|
|
|
@@ -37,9 +38,13 @@ export type IntrinsicSymmetry = 'none' | 'ij' | 'jk' | 'ij_kl' | 'voigt';
|
|
|
37
38
|
|
|
38
39
|
/** The kind of tensor, as in birss-app. */
|
|
39
40
|
export interface TensorSpec {
|
|
41
|
+
/** Number of indices, 0 to 4. */
|
|
40
42
|
readonly rank: TensorRank;
|
|
43
|
+
/** `'polar'` or `'axial'`: whether an improper operation changes the sign (factor det R). */
|
|
41
44
|
readonly parity: TensorParity;
|
|
45
|
+
/** `'i'` (time-even) or `'c'` (time-odd): whether time reversal changes the sign. */
|
|
42
46
|
readonly timeParity: TimeParity;
|
|
47
|
+
/** The index symmetry of the tensor. */
|
|
43
48
|
readonly intrinsic: IntrinsicSymmetry;
|
|
44
49
|
}
|
|
45
50
|
|
|
@@ -49,6 +54,7 @@ export interface TensorSpec {
|
|
|
49
54
|
* components has length 3^rank (flat index, see the module documentation).
|
|
50
55
|
*/
|
|
51
56
|
export interface TensorForm {
|
|
57
|
+
/** The rank of the tensor. */
|
|
52
58
|
readonly rank: TensorRank;
|
|
53
59
|
/**
|
|
54
60
|
* A basis of the allowed tensors in reduced row echelon form: one row per free parameter, with 1
|
|
@@ -101,18 +107,6 @@ function checkSpec(spec: TensorSpec): number[][] {
|
|
|
101
107
|
}
|
|
102
108
|
}
|
|
103
109
|
|
|
104
|
-
/** Throws unless `m` is orthogonal (mᵀm = 1 within `EPSILON`): the code assumes Cartesian matrices. */
|
|
105
|
-
function checkOrthogonal(m: Mat3, what: string): void {
|
|
106
|
-
for (let i = 0; i < 3; i++) {
|
|
107
|
-
for (let j = 0; j < 3; j++) {
|
|
108
|
-
const dot = m[0][i] * m[0][j] + m[1][i] * m[1][j] + m[2][i] * m[2][j];
|
|
109
|
-
if (Math.abs(dot - (i === j ? 1 : 0)) > EPSILON) {
|
|
110
|
-
throw new RangeError(`${what} is not an orthogonal (Cartesian) matrix: ${JSON.stringify(m)}`);
|
|
111
|
-
}
|
|
112
|
-
}
|
|
113
|
-
}
|
|
114
|
-
}
|
|
115
|
-
|
|
116
110
|
/** The indices (x, y, z = 0, 1, 2) of every flat index at a rank, first index first. */
|
|
117
111
|
const digitTables = new Map<number, readonly (readonly number[])[]>();
|
|
118
112
|
function digits(rank: number): readonly (readonly number[])[] {
|
|
@@ -223,18 +217,25 @@ function specKey(spec: TensorSpec): string {
|
|
|
223
217
|
const formCache = new Map<string, TensorForm>();
|
|
224
218
|
|
|
225
219
|
/**
|
|
226
|
-
* The form of a tensor under a point group
|
|
227
|
-
* of the convention, `'itc'` unless given). The
|
|
228
|
-
*
|
|
220
|
+
* The form of a tensor under a point group, a crystal class or a magnetic point group, in the
|
|
221
|
+
* requested setting (default: the default setting of the convention, `'itc'` unless given). The
|
|
222
|
+
* tensor is given by its specification or by the name of a property in `TENSOR_PROPERTIES`
|
|
223
|
+
* (`'piezoelectric'`). The convention matters only through the setting: the same setting index
|
|
224
|
+
* gives the same form in both conventions (docs/conventions.md, "Tensors").
|
|
229
225
|
*/
|
|
230
|
-
export function tensorForm(
|
|
231
|
-
|
|
226
|
+
export function tensorForm(
|
|
227
|
+
key: MagneticPointGroupKey,
|
|
228
|
+
spec: TensorSpec | TensorPropertyName,
|
|
229
|
+
options?: SettingOptions,
|
|
230
|
+
): TensorForm {
|
|
231
|
+
const resolved = specOf(spec);
|
|
232
|
+
const perms = checkSpec(resolved);
|
|
232
233
|
const ops = operations(key, options); // checks key, convention and setting
|
|
233
234
|
const index = options?.setting ?? settings(key, options?.convention).find((s) => s.isDefault)!.index;
|
|
234
|
-
const cacheKey = `${key}#${index}#${specKey(
|
|
235
|
+
const cacheKey = `${key}#${index}#${specKey(resolved)}`;
|
|
235
236
|
let form = formCache.get(cacheKey);
|
|
236
237
|
if (!form) {
|
|
237
|
-
form = project(ops,
|
|
238
|
+
form = project(ops, resolved, perms);
|
|
238
239
|
formCache.set(cacheKey, form);
|
|
239
240
|
}
|
|
240
241
|
return form;
|
|
@@ -242,22 +243,32 @@ export function tensorForm(key: PointGroupKey, spec: TensorSpec, options?: Setti
|
|
|
242
243
|
|
|
243
244
|
/**
|
|
244
245
|
* The form of a tensor under the group generated by `operations`, e.g. the site symmetry of a
|
|
245
|
-
* surface normal (`siteSymmetry`) or the operations of a distorted crystal. The
|
|
246
|
-
*
|
|
246
|
+
* surface normal (`siteSymmetry`) or the operations of a distorted crystal. The tensor is given by
|
|
247
|
+
* its specification or by the name of a property in `TENSOR_PROPERTIES`. The operations are
|
|
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.
|
|
247
250
|
*/
|
|
248
|
-
export function tensorFormOf(operations: readonly Operation[], spec: TensorSpec): TensorForm {
|
|
249
|
-
const
|
|
251
|
+
export function tensorFormOf(operations: readonly Operation[], spec: TensorSpec | TensorPropertyName): TensorForm {
|
|
252
|
+
const resolved = specOf(spec);
|
|
253
|
+
const perms = checkSpec(resolved);
|
|
250
254
|
operations.forEach((op, i) => checkOrthogonal(op.matrix, `Operation ${i}`));
|
|
251
|
-
|
|
255
|
+
checkTimeReversal(operations);
|
|
256
|
+
return project(closeGroup(operations), resolved, perms);
|
|
252
257
|
}
|
|
253
258
|
|
|
254
259
|
/**
|
|
255
260
|
* The components of `tensor` (length 3^rank, flat index) in a frame rotated by the orthogonal
|
|
256
261
|
* matrix `rotation`: t′_{i…} = f·Σ R_{ia}…R_{…}·t_{a…}, with f = det(R) for an axial tensor and 1
|
|
257
262
|
* for a polar one. To express a tensor in the frame of a surface, pass the matrix whose rows are
|
|
258
|
-
* the new axes in the old frame. Time parity plays no part.
|
|
263
|
+
* the new axes in the old frame. Time parity plays no part. The kind of tensor is given by its
|
|
264
|
+
* specification or by the name of a property in `TENSOR_PROPERTIES`.
|
|
259
265
|
*/
|
|
260
|
-
export function rotateTensor(
|
|
266
|
+
export function rotateTensor(
|
|
267
|
+
tensor: readonly number[],
|
|
268
|
+
rotation: Mat3,
|
|
269
|
+
specOrName: TensorSpec | TensorPropertyName,
|
|
270
|
+
): number[] {
|
|
271
|
+
const spec = specOf(specOrName);
|
|
261
272
|
checkSpec(spec);
|
|
262
273
|
checkOrthogonal(rotation, 'The rotation');
|
|
263
274
|
const { rank } = spec;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Which named tensor properties a point group allows: the property is allowed if the tensor that
|
|
3
|
+
* describes it (`TENSOR_PROPERTIES`) has a non-zero form under the group. Symmetry only allows a
|
|
4
|
+
* property; whether a crystal shows it is a question of the material.
|
|
5
|
+
*
|
|
6
|
+
* These functions serve the magnetic API (`magnetic.ts`), where a key of type `'I'` (`'432'`) is the
|
|
7
|
+
* white group: the symmetry of a magnetically ordered crystal in which time reversal does not occur
|
|
8
|
+
* at all (`'432'` is magnetoelectric). A crystal without magnetic order has the grey group of its
|
|
9
|
+
* class (`"4321'"`), which allows no time-odd property; for the time-even properties the two agree.
|
|
10
|
+
* The crystallographic API (`crystalClasses.ts`) knows the time-even properties only
|
|
11
|
+
* (docs/conventions.md, "Two entry points").
|
|
12
|
+
*/
|
|
13
|
+
|
|
14
|
+
import type { Operation } from '../operations.js';
|
|
15
|
+
import type { MagneticPointGroupKey } from '../pointGroups/pointGroups.js';
|
|
16
|
+
import { TENSOR_PROPERTY_NAMES, specOf, type TensorPropertyName } from './propertyTable.js';
|
|
17
|
+
import { tensorForm, tensorFormOf } from './tensorForm.js';
|
|
18
|
+
|
|
19
|
+
/** A name of the table; anything else, a specification included, is an error here. */
|
|
20
|
+
function named(name: TensorPropertyName): TensorPropertyName {
|
|
21
|
+
if (typeof name !== 'string') throw new RangeError(`Unknown tensor property: ${JSON.stringify(name)}`);
|
|
22
|
+
specOf(name);
|
|
23
|
+
return name;
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* True if the point group allows the named property, e.g. `allowsProperty('-6m2', 'piezoelectric')`.
|
|
28
|
+
* It does not depend on setting or convention. Throws a RangeError for an unknown key or name.
|
|
29
|
+
*/
|
|
30
|
+
export function allowsProperty(key: MagneticPointGroupKey, name: TensorPropertyName): boolean {
|
|
31
|
+
return tensorForm(key, named(name), { setting: 1 }).basis.length > 0;
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
/** The named properties the point group allows, in the order of `TENSOR_PROPERTIES`. */
|
|
35
|
+
export function allowedProperties(key: MagneticPointGroupKey): TensorPropertyName[] {
|
|
36
|
+
return TENSOR_PROPERTY_NAMES.filter((name) => allowsProperty(key, name));
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
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.
|
|
42
|
+
*/
|
|
43
|
+
export function allowsPropertyOf(operations: readonly Operation[], name: TensorPropertyName): boolean {
|
|
44
|
+
return tensorFormOf(operations, named(name)).basis.length > 0;
|
|
45
|
+
}
|
|
46
|
+
|
|
47
|
+
/** The named properties the group generated by `operations` allows. */
|
|
48
|
+
export function allowedPropertiesOf(operations: readonly Operation[]): TensorPropertyName[] {
|
|
49
|
+
return TENSOR_PROPERTY_NAMES.filter((name) => allowsPropertyOf(operations, name));
|
|
50
|
+
}
|
package/src/version.ts
CHANGED
|
@@ -1,2 +1,6 @@
|
|
|
1
|
-
/**
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* The version of symcrys, the same for the TypeScript and the Python package.
|
|
3
|
+
*
|
|
4
|
+
* @remarks Kept equal to `version` in package.json (checked by version.test.ts).
|
|
5
|
+
*/
|
|
6
|
+
export const VERSION = '0.6.1';
|