symcrys 0.11.0 → 0.12.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/dist/coordinates.d.ts +143 -0
- package/dist/coordinates.d.ts.map +1 -0
- package/dist/coordinates.js +198 -0
- package/dist/coordinates.js.map +1 -0
- package/dist/crystalClasses.d.ts +28 -3
- package/dist/crystalClasses.d.ts.map +1 -1
- package/dist/crystalClasses.js +32 -3
- package/dist/crystalClasses.js.map +1 -1
- package/dist/index.d.ts +4 -2
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -2
- package/dist/index.js.map +1 -1
- package/dist/indices.d.ts +3 -19
- package/dist/indices.d.ts.map +1 -1
- package/dist/indices.js +3 -24
- package/dist/indices.js.map +1 -1
- package/dist/magnetic.d.ts +3 -1
- package/dist/magnetic.d.ts.map +1 -1
- package/dist/magnetic.js +3 -1
- package/dist/magnetic.js.map +1 -1
- package/dist/plane.d.ts +158 -3
- package/dist/plane.d.ts.map +1 -1
- package/dist/plane.js +166 -41
- package/dist/plane.js.map +1 -1
- package/dist/pointGroups/pointGroups.d.ts +15 -6
- package/dist/pointGroups/pointGroups.d.ts.map +1 -1
- package/dist/pointGroups/pointGroups.js +52 -5
- package/dist/pointGroups/pointGroups.js.map +1 -1
- package/dist/pointGroups/shubnikovData.d.ts +11 -0
- package/dist/pointGroups/shubnikovData.d.ts.map +1 -0
- package/dist/pointGroups/shubnikovData.js +101 -0
- package/dist/pointGroups/shubnikovData.js.map +1 -0
- package/dist/spaceGroups/describe.d.ts +3 -2
- package/dist/spaceGroups/describe.d.ts.map +1 -1
- package/dist/spaceGroups/describe.js.map +1 -1
- package/dist/spaceGroups/planeGroupData.d.ts +2 -0
- package/dist/spaceGroups/planeGroupData.d.ts.map +1 -1
- package/dist/spaceGroups/planeGroupData.js +17 -0
- package/dist/spaceGroups/planeGroupData.js.map +1 -1
- package/dist/spaceGroups/planeLattice.d.ts +78 -0
- package/dist/spaceGroups/planeLattice.d.ts.map +1 -0
- package/dist/spaceGroups/planeLattice.js +143 -0
- package/dist/spaceGroups/planeLattice.js.map +1 -0
- package/dist/spaceGroups/planePointGroups.d.ts +6 -2
- package/dist/spaceGroups/planePointGroups.d.ts.map +1 -1
- package/dist/spaceGroups/planePointGroups.js +14 -2
- package/dist/spaceGroups/planePointGroups.js.map +1 -1
- package/dist/spaceGroups/rational.d.ts +18 -0
- package/dist/spaceGroups/rational.d.ts.map +1 -1
- package/dist/spaceGroups/rational.js +58 -0
- package/dist/spaceGroups/rational.js.map +1 -1
- package/dist/tensors/voigt.d.ts +56 -0
- package/dist/tensors/voigt.d.ts.map +1 -0
- package/dist/tensors/voigt.js +188 -0
- package/dist/tensors/voigt.js.map +1 -0
- package/dist/version.d.ts +1 -1
- package/dist/version.js +1 -1
- package/package.json +1 -1
- package/src/coordinates.ts +370 -0
- package/src/crystalClasses.ts +42 -3
- package/src/index.ts +12 -2
- package/src/indices.ts +3 -33
- package/src/magnetic.ts +10 -2
- package/src/plane.ts +302 -48
- package/src/pointGroups/pointGroups.ts +58 -6
- package/src/pointGroups/shubnikovData.ts +103 -0
- package/src/spaceGroups/describe.ts +3 -2
- package/src/spaceGroups/planeGroupData.ts +19 -0
- package/src/spaceGroups/planeLattice.ts +208 -0
- package/src/spaceGroups/planePointGroups.ts +23 -3
- package/src/spaceGroups/rational.ts +59 -0
- package/src/tensors/voigt.ts +268 -0
- package/src/version.ts +1 -1
package/dist/version.js
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "symcrys",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.12.0",
|
|
4
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",
|
|
@@ -0,0 +1,370 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* The change of the coordinate system by a matrix–column pair (P, p) after ITA (6th ed., 2016)
|
|
3
|
+
* Chapter 1.5 (§§ 1.5.1.3, 1.5.2, pp. 83–85), for d = 2 and d = 3 (#120, #137 G2). Internal; the
|
|
4
|
+
* entry points wrap it with their matrix types (docs/conventions.md, "Change of the coordinate
|
|
5
|
+
* system").
|
|
6
|
+
*
|
|
7
|
+
* The linear part P, the origin shift p and the operations (W, w) are read each number as the
|
|
8
|
+
* simplest fraction within the tolerance and transformed exactly, so that W′ = P⁻¹WP is exactly
|
|
9
|
+
* integral where it is and every result, the inverse pair included, is read back exactly; points,
|
|
10
|
+
* direction and plane coefficients and the metric are floating point.
|
|
11
|
+
*/
|
|
12
|
+
|
|
13
|
+
import { checkObject, checkOptions, shown, TOLERANCE_KEYS } from './checks.js';
|
|
14
|
+
import { toleranceOf, type ToleranceOptions } from './tolerances.js';
|
|
15
|
+
import { deepFreeze } from './freeze.js';
|
|
16
|
+
import type { Mat3, Vec3 } from './linalg.js';
|
|
17
|
+
import {
|
|
18
|
+
ONE,
|
|
19
|
+
add,
|
|
20
|
+
isInteger,
|
|
21
|
+
multiply,
|
|
22
|
+
simplestFraction,
|
|
23
|
+
negate,
|
|
24
|
+
rational,
|
|
25
|
+
subtract,
|
|
26
|
+
toNumber,
|
|
27
|
+
ZERO,
|
|
28
|
+
type Rational,
|
|
29
|
+
} from './spaceGroups/rational.js';
|
|
30
|
+
|
|
31
|
+
/** A matrix as rows of numbers. */
|
|
32
|
+
type Rows = readonly (readonly number[])[];
|
|
33
|
+
type RMatrix = readonly (readonly Rational[])[];
|
|
34
|
+
|
|
35
|
+
/** The pair (P, p): the new basis (a′, b′, c′) = (a, b, c)·P and the new origin O′ = O + p. */
|
|
36
|
+
export interface GenericTransformation {
|
|
37
|
+
/** P, the linear part: its columns are the new basis vectors in the old basis (ITA eq. (1.5.1.4)). */
|
|
38
|
+
readonly linearPart: Rows;
|
|
39
|
+
/** p, the origin shift: the coordinates of the new origin in the old coordinate system; default zero. */
|
|
40
|
+
readonly originShift?: readonly number[];
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** An operation (W, w) in the lattice basis, x ↦ W·x + w. */
|
|
44
|
+
export interface GenericOperation {
|
|
45
|
+
/** The linear part W, integer entries. */
|
|
46
|
+
readonly matrix: Rows;
|
|
47
|
+
/** The translation part w; default zero (an operation of a point group). */
|
|
48
|
+
readonly translation?: readonly number[];
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
/** The quantities to transform; each is optional. */
|
|
52
|
+
export interface GenericQuantities {
|
|
53
|
+
/** Point coordinates x: x′ = P⁻¹(x − p), eq. (1.5.1.7). */
|
|
54
|
+
readonly points?: readonly (readonly number[])[];
|
|
55
|
+
/** Coefficients [uvw] of vectors (directions): [uvw]′ = P⁻¹[uvw], eq. (1.5.2.3). */
|
|
56
|
+
readonly directions?: readonly (readonly number[])[];
|
|
57
|
+
/** Miller indices (hkl) of planes, or coefficients of reciprocal vectors: (hkl)′ = (hkl)P, eq. (1.5.2.2). */
|
|
58
|
+
readonly planes?: readonly (readonly number[])[];
|
|
59
|
+
/** The metric tensor G: G′ = PᵀGP, eq. (1.5.2.4). */
|
|
60
|
+
readonly metric?: Rows;
|
|
61
|
+
/** Operations (W, w): W′ = P⁻¹WP, w′ = P⁻¹(w + (W − I)p), eqs. (1.5.2.12), (1.5.2.13). */
|
|
62
|
+
readonly operations?: readonly GenericOperation[];
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
/** The result: the inverse pair and every given quantity in the new coordinate system. */
|
|
66
|
+
export interface GenericChange {
|
|
67
|
+
/** The inverse pair (Q, q) = (P, p)⁻¹ = (P⁻¹, −P⁻¹p), eq. (1.5.1.7), which takes the new coordinates back. */
|
|
68
|
+
readonly inverse: { readonly linearPart: Rows; readonly originShift: readonly number[] };
|
|
69
|
+
readonly points?: Rows;
|
|
70
|
+
readonly directions?: Rows;
|
|
71
|
+
readonly planes?: Rows;
|
|
72
|
+
readonly metric?: Rows;
|
|
73
|
+
readonly operations?: readonly { readonly matrix: Rows; readonly translation: readonly number[] }[];
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const QUANTITY_KEYS = ['points', 'directions', 'planes', 'metric', 'operations'] as const;
|
|
77
|
+
|
|
78
|
+
function isRows(m: unknown, d: number): m is Rows {
|
|
79
|
+
return (
|
|
80
|
+
Array.isArray(m) &&
|
|
81
|
+
m.length === d &&
|
|
82
|
+
m.every((r) => Array.isArray(r) && r.length === d && r.every((x) => typeof x === 'number' && Number.isFinite(x)))
|
|
83
|
+
);
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
function isVector(v: unknown, d: number): v is readonly number[] {
|
|
87
|
+
return Array.isArray(v) && v.length === d && v.every((x) => typeof x === 'number' && Number.isFinite(x));
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
function product(a: RMatrix, b: RMatrix): RMatrix {
|
|
91
|
+
return a.map((row) => b[0].map((_, j) => row.reduce((s, x, k) => add(s, multiply(x, b[k][j])), ZERO)));
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
function apply(a: RMatrix, v: readonly Rational[]): Rational[] {
|
|
95
|
+
return a.map((row) => row.reduce((s, x, k) => add(s, multiply(x, v[k])), ZERO));
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
/** The determinant of a 2 × 2 or 3 × 3 rational matrix. */
|
|
99
|
+
function determinant(m: RMatrix): Rational {
|
|
100
|
+
const t = (i: number, j: number) => m[i][j];
|
|
101
|
+
if (m.length === 2) return subtract(multiply(t(0, 0), t(1, 1)), multiply(t(0, 1), t(1, 0)));
|
|
102
|
+
const minor = (i: number, j: number, k: number, l: number) =>
|
|
103
|
+
subtract(multiply(t(i, j), t(k, l)), multiply(t(i, l), t(k, j)));
|
|
104
|
+
return add(
|
|
105
|
+
subtract(multiply(t(0, 0), minor(1, 1, 2, 2)), multiply(t(0, 1), minor(1, 0, 2, 2))),
|
|
106
|
+
multiply(t(0, 2), minor(1, 0, 2, 1)),
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
/** The inverse of a regular 2 × 2 or 3 × 3 rational matrix, by the adjugate. */
|
|
111
|
+
function inverse(m: RMatrix): RMatrix {
|
|
112
|
+
const det = determinant(m);
|
|
113
|
+
const over = (x: Rational) => multiply(x, rational(det[1], det[0]));
|
|
114
|
+
if (m.length === 2) {
|
|
115
|
+
return [
|
|
116
|
+
[over(m[1][1]), over(negate(m[0][1]))],
|
|
117
|
+
[over(negate(m[1][0])), over(m[0][0])],
|
|
118
|
+
];
|
|
119
|
+
}
|
|
120
|
+
const c = (i: number, j: number) => {
|
|
121
|
+
const rows = [0, 1, 2].filter((r) => r !== i);
|
|
122
|
+
const cols = [0, 1, 2].filter((k) => k !== j);
|
|
123
|
+
const minor = subtract(
|
|
124
|
+
multiply(m[rows[0]][cols[0]], m[rows[1]][cols[1]]),
|
|
125
|
+
multiply(m[rows[0]][cols[1]], m[rows[1]][cols[0]]),
|
|
126
|
+
);
|
|
127
|
+
return (i + j) % 2 === 0 ? minor : negate(minor);
|
|
128
|
+
};
|
|
129
|
+
// The inverse is the transposed matrix of cofactors over the determinant.
|
|
130
|
+
return [0, 1, 2].map((i) => [0, 1, 2].map((j) => over(c(j, i))));
|
|
131
|
+
}
|
|
132
|
+
|
|
133
|
+
const numbers = (v: readonly Rational[]): number[] => v.map((x) => toNumber(x) + 0);
|
|
134
|
+
const floats = (m: RMatrix): number[][] => m.map((row) => numbers(row));
|
|
135
|
+
|
|
136
|
+
function floatProduct(a: Rows, b: Rows): number[][] {
|
|
137
|
+
return a.map((row) => b[0].map((_, j) => row.reduce((s, x, k) => s + x * b[k][j], 0) + 0));
|
|
138
|
+
}
|
|
139
|
+
|
|
140
|
+
function floatApply(a: Rows, v: readonly number[]): number[] {
|
|
141
|
+
return a.map((row) => row.reduce((s, x, k) => s + x * v[k], 0) + 0);
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* The change of the coordinate system (P, p) applied to the given quantities, in d = 2 or 3
|
|
146
|
+
* dimensions (ITA 2016 §§ 1.5.1.3, 1.5.2). `who` names the calling function in the messages.
|
|
147
|
+
*/
|
|
148
|
+
export function changeCoordinates(
|
|
149
|
+
d: 2 | 3,
|
|
150
|
+
transformation: GenericTransformation,
|
|
151
|
+
quantities: GenericQuantities,
|
|
152
|
+
options: ToleranceOptions | undefined,
|
|
153
|
+
who: string,
|
|
154
|
+
): GenericChange {
|
|
155
|
+
try {
|
|
156
|
+
return transform(d, transformation, quantities, options, who);
|
|
157
|
+
} catch (e) {
|
|
158
|
+
// Exact arithmetic that leaves the safe integers names the function too.
|
|
159
|
+
if (e instanceof RangeError && !e.message.startsWith(`${who}`))
|
|
160
|
+
throw new RangeError(`${who}: ${e.message}`, { cause: e });
|
|
161
|
+
throw e;
|
|
162
|
+
}
|
|
163
|
+
}
|
|
164
|
+
|
|
165
|
+
function transform(
|
|
166
|
+
d: 2 | 3,
|
|
167
|
+
transformation: GenericTransformation,
|
|
168
|
+
quantities: GenericQuantities,
|
|
169
|
+
options: ToleranceOptions | undefined,
|
|
170
|
+
who: string,
|
|
171
|
+
): GenericChange {
|
|
172
|
+
checkOptions(options, TOLERANCE_KEYS, who);
|
|
173
|
+
const tolerance = toleranceOf(options, 'operations');
|
|
174
|
+
checkObject(transformation, `${who} takes the transformation { linearPart, originShift }`);
|
|
175
|
+
checkObject(quantities, `${who} takes the quantities { ${QUANTITY_KEYS.join(', ')} }`);
|
|
176
|
+
for (const key of Object.keys(transformation)) {
|
|
177
|
+
if (key !== 'linearPart' && key !== 'originShift') {
|
|
178
|
+
throw new RangeError(`${who}: unknown field ${shown(key)} of the transformation (linearPart, originShift)`);
|
|
179
|
+
}
|
|
180
|
+
}
|
|
181
|
+
for (const key of Object.keys(quantities)) {
|
|
182
|
+
if (!(QUANTITY_KEYS as readonly string[]).includes(key)) {
|
|
183
|
+
throw new RangeError(`${who}: unknown quantity ${shown(key)} (${QUANTITY_KEYS.join(', ')})`);
|
|
184
|
+
}
|
|
185
|
+
}
|
|
186
|
+
const P0 = transformation.linearPart;
|
|
187
|
+
if (!isRows(P0, d)) throw new RangeError(`${who}: the linear part P must be a ${d} × ${d} matrix, not ${shown(P0)}`);
|
|
188
|
+
const fraction = (x: number, what: string): Rational => simplestFraction(x, tolerance, what);
|
|
189
|
+
const P = P0.map((row) => row.map((x) => fraction(x, 'entry of P')));
|
|
190
|
+
if (determinant(P)[0] === 0) throw new RangeError(`${who}: the linear part P is singular (det P = 0)`);
|
|
191
|
+
// Only a missing origin shift is zero; null is a wrong value, not a missing one.
|
|
192
|
+
const shift0 =
|
|
193
|
+
transformation.originShift === undefined ? Array.from({ length: d }, () => 0) : transformation.originShift;
|
|
194
|
+
if (!isVector(shift0, d))
|
|
195
|
+
throw new RangeError(`${who}: the origin shift p must be ${d} numbers, not ${shown(shift0)}`);
|
|
196
|
+
const p = shift0.map((x) => fraction(x, 'coordinate of p'));
|
|
197
|
+
const Q = inverse(P);
|
|
198
|
+
const q = apply(Q, p).map(negate);
|
|
199
|
+
const Pf = floats(P);
|
|
200
|
+
const Qf = floats(Q);
|
|
201
|
+
const pf = numbers(p);
|
|
202
|
+
|
|
203
|
+
const vectors = (name: string, list: unknown): readonly (readonly number[])[] => {
|
|
204
|
+
if (!Array.isArray(list) || !list.every((v) => isVector(v, d))) {
|
|
205
|
+
throw new RangeError(`${who}: ${name} must be a list of vectors of ${d} numbers, not ${shown(list)}`);
|
|
206
|
+
}
|
|
207
|
+
return list as readonly (readonly number[])[];
|
|
208
|
+
};
|
|
209
|
+
|
|
210
|
+
const result: Record<string, unknown> = { inverse: { linearPart: floats(Q), originShift: numbers(q) } };
|
|
211
|
+
if (quantities.points !== undefined) {
|
|
212
|
+
result.points = vectors('points', quantities.points).map((x) =>
|
|
213
|
+
floatApply(
|
|
214
|
+
Qf,
|
|
215
|
+
x.map((xi, i) => xi - pf[i]),
|
|
216
|
+
),
|
|
217
|
+
);
|
|
218
|
+
}
|
|
219
|
+
if (quantities.directions !== undefined) {
|
|
220
|
+
result.directions = vectors('directions', quantities.directions).map((u) => floatApply(Qf, u));
|
|
221
|
+
}
|
|
222
|
+
if (quantities.planes !== undefined) {
|
|
223
|
+
// A row (hkl) times P: the j-th index is Σ_i h_i P_ij.
|
|
224
|
+
result.planes = vectors('planes', quantities.planes).map((h) =>
|
|
225
|
+
Pf[0].map((_, j) => h.reduce((s, hi, i) => s + hi * Pf[i][j], 0) + 0),
|
|
226
|
+
);
|
|
227
|
+
}
|
|
228
|
+
if (quantities.metric !== undefined) {
|
|
229
|
+
const G = quantities.metric;
|
|
230
|
+
if (!isRows(G, d)) throw new RangeError(`${who}: the metric must be a ${d} × ${d} matrix, not ${shown(G)}`);
|
|
231
|
+
const Pt = Pf[0].map((_, j) => Pf.map((row) => row[j]));
|
|
232
|
+
result.metric = floatProduct(floatProduct(Pt, G), Pf);
|
|
233
|
+
}
|
|
234
|
+
if (quantities.operations !== undefined) {
|
|
235
|
+
const ops: unknown = quantities.operations;
|
|
236
|
+
if (!Array.isArray(ops)) throw new RangeError(`${who}: operations must be a list, not ${shown(ops)}`);
|
|
237
|
+
result.operations = ops.map((op: unknown, n) => {
|
|
238
|
+
checkObject(op, `${who}: operation ${n + 1} is a record { matrix, translation }`);
|
|
239
|
+
const { matrix, translation } = op as GenericOperation;
|
|
240
|
+
if (!isRows(matrix, d)) {
|
|
241
|
+
throw new RangeError(`${who}: the matrix W of operation ${n + 1} must be ${d} × ${d}, not ${shown(matrix)}`);
|
|
242
|
+
}
|
|
243
|
+
const W = matrix.map((row) =>
|
|
244
|
+
row.map((x) => {
|
|
245
|
+
if (Math.abs(x - Math.round(x)) >= tolerance) {
|
|
246
|
+
throw new RangeError(
|
|
247
|
+
`${who}: the matrix W of operation ${n + 1} has integer entries, not ${shown(matrix)}`,
|
|
248
|
+
);
|
|
249
|
+
}
|
|
250
|
+
return rational(Math.round(x));
|
|
251
|
+
}),
|
|
252
|
+
);
|
|
253
|
+
if (determinant(W)[1] !== 1 || Math.abs(determinant(W)[0]) !== 1) {
|
|
254
|
+
throw new RangeError(`${who}: the matrix W of operation ${n + 1} has det W = ±1, not ${shown(matrix)}`);
|
|
255
|
+
}
|
|
256
|
+
const t0 = translation === undefined ? Array.from({ length: d }, () => 0) : translation;
|
|
257
|
+
if (!isVector(t0, d)) {
|
|
258
|
+
throw new RangeError(`${who}: the translation of operation ${n + 1} must be ${d} numbers, not ${shown(t0)}`);
|
|
259
|
+
}
|
|
260
|
+
const w = t0.map((x) => fraction(x, 'translation'));
|
|
261
|
+
const W1 = product(product(Q, W), P);
|
|
262
|
+
if (!W1.every((row) => row.every(isInteger))) {
|
|
263
|
+
throw new RangeError(
|
|
264
|
+
`${who}: operation ${n + 1} has no integral matrix in the new basis (P⁻¹WP = ${shown(floats(W1))}): ` +
|
|
265
|
+
'the new basis does not span a lattice that the operation maps onto itself',
|
|
266
|
+
);
|
|
267
|
+
}
|
|
268
|
+
// w′ = Q(w + (W − I)p)
|
|
269
|
+
const WminusI = W.map((row, i) => row.map((x, j) => (i === j ? subtract(x, ONE) : x)));
|
|
270
|
+
const shifted = apply(WminusI, p).map((x, i) => add(w[i], x));
|
|
271
|
+
return { matrix: floats(W1), translation: numbers(apply(Q, shifted)) };
|
|
272
|
+
});
|
|
273
|
+
}
|
|
274
|
+
return result as unknown as GenericChange;
|
|
275
|
+
}
|
|
276
|
+
|
|
277
|
+
// --- the three-dimensional API (symcrys, symcrys/magnetic) -------------------------------------------
|
|
278
|
+
|
|
279
|
+
/** A change of the coordinate system (P, p) (ITA 2016 § 1.5.1.3, p. 83): (a′, b′, c′) = (a, b, c)·P, origin O′ = O + p. */
|
|
280
|
+
export interface CoordinateTransformation {
|
|
281
|
+
/** P, the linear part: its columns are the new basis vectors a′, b′, c′ in the old basis (eq. (1.5.1.4)); det P ≠ 0, also negative. */
|
|
282
|
+
readonly linearPart: Mat3;
|
|
283
|
+
/** p, the origin shift: the coordinates of the new origin in the old coordinate system; default zero. */
|
|
284
|
+
readonly originShift?: Vec3;
|
|
285
|
+
}
|
|
286
|
+
|
|
287
|
+
/** An operation (W, w) in the lattice basis, x ↦ W·x + w; a record of `operations` passes as it is. */
|
|
288
|
+
export interface AffineOperation {
|
|
289
|
+
/** The linear part W, integer entries. */
|
|
290
|
+
readonly matrix: Mat3;
|
|
291
|
+
/** The translation part w; default zero, as for the operations of a point group. */
|
|
292
|
+
readonly translation?: Vec3;
|
|
293
|
+
}
|
|
294
|
+
|
|
295
|
+
/** An operation (W′, w′) in the new coordinate system. */
|
|
296
|
+
export interface TransformedOperation {
|
|
297
|
+
/** W′ = P⁻¹WP, integer entries. */
|
|
298
|
+
readonly matrix: Mat3;
|
|
299
|
+
/** w′ = P⁻¹(w + (W − I)p), not reduced modulo the lattice. */
|
|
300
|
+
readonly translation: Vec3;
|
|
301
|
+
}
|
|
302
|
+
|
|
303
|
+
/** The quantities that `changeOfCoordinates` transforms; each is optional. */
|
|
304
|
+
export interface CoordinateQuantities {
|
|
305
|
+
/** Point coordinates x: x′ = P⁻¹(x − p) (eq. (1.5.1.7)). */
|
|
306
|
+
readonly points?: readonly Vec3[];
|
|
307
|
+
/** Coefficients [uvw] of vectors, e.g. directions: [uvw]′ = P⁻¹[uvw] (eq. (1.5.2.3)); not changed by the origin shift. */
|
|
308
|
+
readonly directions?: readonly Vec3[];
|
|
309
|
+
/** Miller indices (hkl) of planes: (hkl)′ = (hkl)P (eq. (1.5.2.2)); not changed by the origin shift. */
|
|
310
|
+
readonly planes?: readonly Vec3[];
|
|
311
|
+
/** The metric tensor G: G′ = PᵀGP (eq. (1.5.2.4)). */
|
|
312
|
+
readonly metric?: Mat3;
|
|
313
|
+
/** Operations (W, w): W′ = P⁻¹WP, w′ = P⁻¹(w + (W − I)p) (eqs. (1.5.2.12), (1.5.2.13)). */
|
|
314
|
+
readonly operations?: readonly AffineOperation[];
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
/** The inverse change of the coordinate system (Q, q) = (P, p)⁻¹. */
|
|
318
|
+
export interface InverseTransformation {
|
|
319
|
+
/** Q = P⁻¹. */
|
|
320
|
+
readonly linearPart: Mat3;
|
|
321
|
+
/** q = −P⁻¹p. */
|
|
322
|
+
readonly originShift: Vec3;
|
|
323
|
+
}
|
|
324
|
+
|
|
325
|
+
/** The result of `changeOfCoordinates`: the inverse pair and each given quantity in the new coordinate system. */
|
|
326
|
+
export interface CoordinateChange {
|
|
327
|
+
/** (Q, q) = (P⁻¹, −P⁻¹p), which takes the new coordinates back to the old (eq. (1.5.1.7)). */
|
|
328
|
+
readonly inverse: InverseTransformation;
|
|
329
|
+
/** The points, as given, in the new coordinates. */
|
|
330
|
+
readonly points?: readonly Vec3[];
|
|
331
|
+
/** The vector coefficients, as given, in the new basis. */
|
|
332
|
+
readonly directions?: readonly Vec3[];
|
|
333
|
+
/** The Miller indices, as given, in the new basis. */
|
|
334
|
+
readonly planes?: readonly Vec3[];
|
|
335
|
+
/** The metric tensor in the new basis. */
|
|
336
|
+
readonly metric?: Mat3;
|
|
337
|
+
/** The operations, as given, in the new coordinate system. */
|
|
338
|
+
readonly operations?: readonly TransformedOperation[];
|
|
339
|
+
}
|
|
340
|
+
|
|
341
|
+
/**
|
|
342
|
+
* Changes the coordinate system by the pair (P, p) of ITA (6th ed., 2016) § 1.5.1.3 (p. 83): the
|
|
343
|
+
* new basis is (a′, b′, c′) = (a, b, c)·P and the new origin lies at p. Transforms the given
|
|
344
|
+
* quantities by ITA's equations (§ 1.5.2, pp. 83–85): point coordinates x′ = P⁻¹(x − p), vector
|
|
345
|
+
* coefficients [uvw]′ = P⁻¹[uvw], Miller indices (hkl)′ = (hkl)P, the metric tensor G′ = PᵀGP, and
|
|
346
|
+
* operations W′ = P⁻¹WP, w′ = P⁻¹(w + (W − I)p); and gives the inverse pair (Q, q) = (P⁻¹, −P⁻¹p).
|
|
347
|
+
* det P may be negative (a change of handedness, which ITA allows; § 1.5.1.2, p. 76).
|
|
348
|
+
*
|
|
349
|
+
* P, p and the operations are read each number as the simplest fraction within the tolerance
|
|
350
|
+
* (default `EPSILON`; 0.3333333 is 1/3) and transformed exactly, so that every result, the inverse
|
|
351
|
+
* pair included, can be passed back; the other quantities are floating point. P is rational in a
|
|
352
|
+
* change between lattice bases, as in ITA; an irrational P (a rotation by 30°) is read as the
|
|
353
|
+
* nearby fractions, about as exact as the tolerance, and a much smaller tolerance can make the exact
|
|
354
|
+
* products leave the safe integers, a RangeError.
|
|
355
|
+
* A transformed
|
|
356
|
+
* operation is `{ matrix, translation }` alone: other fields of the record (`cartesian`, in the
|
|
357
|
+
* magnetic API `timeReversal`) are not carried over, so they are matched by index. Throws a
|
|
358
|
+
* RangeError for a singular P, a quantity of the wrong shape, an unknown quantity, an operation with
|
|
359
|
+
* det W ≠ ±1, and one whose W′ is not integral (the new basis does not span a lattice that the
|
|
360
|
+
* operation maps onto itself).
|
|
361
|
+
*/
|
|
362
|
+
export function changeOfCoordinates(
|
|
363
|
+
transformation: CoordinateTransformation,
|
|
364
|
+
quantities: CoordinateQuantities,
|
|
365
|
+
options?: ToleranceOptions,
|
|
366
|
+
): CoordinateChange {
|
|
367
|
+
return deepFreeze(
|
|
368
|
+
changeCoordinates(3, transformation, quantities, options, 'changeOfCoordinates') as unknown as CoordinateChange,
|
|
369
|
+
);
|
|
370
|
+
}
|
package/src/crystalClasses.ts
CHANGED
|
@@ -28,6 +28,7 @@ import * as site from './siteSymmetry.js';
|
|
|
28
28
|
import { TENSOR_PROPERTIES as ALL_TENSOR_PROPERTIES } from './tensors/propertyTable.js';
|
|
29
29
|
import type { TensorPropertyName as MagneticTensorPropertyName } from './tensors/propertyTable.js';
|
|
30
30
|
import * as tensors from './tensors/tensorForm.js';
|
|
31
|
+
import * as voigtNotation from './tensors/voigt.js';
|
|
31
32
|
import type { IntrinsicSymmetry, TensorForm, TensorKind, TensorRank } from './tensors/tensorForm.js';
|
|
32
33
|
import { deepFreeze } from './freeze.js';
|
|
33
34
|
import type { ToleranceOptions } from './tolerances.js';
|
|
@@ -276,9 +277,9 @@ export function pointGroups(): readonly PointGroup[] {
|
|
|
276
277
|
* settings (the option `axes` set to `'rhombohedral'` for the key `32`).
|
|
277
278
|
*
|
|
278
279
|
* Spellings: the overbar as `-`, `−`, a combining overbar or `¯` after the digit (`m3̄m`), `bar3` (also with a backslash and braces, as in LaTeX);
|
|
279
|
-
* Schoenflies subscripts also as Unicode or LaTeX subscripts (`C₃ᵥ`, `C_{3v}`). Returns undefined if nothing matches,
|
|
280
|
-
* also for
|
|
281
|
-
* symbol that names several groups
|
|
280
|
+
* Schoenflies subscripts also as Unicode or LaTeX subscripts (`C₃ᵥ`, `C_{3v}`). Returns `undefined` if nothing matches,
|
|
281
|
+
* also for the symbol of a magnetic group with time reversal; a value that is not a string, and a
|
|
282
|
+
* symbol that names several groups, are a RangeError (the latter lists the groups).
|
|
282
283
|
*/
|
|
283
284
|
export function findPointGroup(symbol: string, options?: groups.AxesOptions): PointGroupInSetting | undefined {
|
|
284
285
|
if (arguments.length > 2) groups.rejectConventionArgument(arguments.length);
|
|
@@ -644,6 +645,44 @@ export function rotateTensor(
|
|
|
644
645
|
return tensors.rotateTensor(tensor, rotation, timeEven(spec), options);
|
|
645
646
|
}
|
|
646
647
|
|
|
648
|
+
/**
|
|
649
|
+
* A tensor in Voigt's two-index notation (ITC Vol. D (2013) § 1.1.4.10, pp. 24–27): each contracted
|
|
650
|
+
* index pair ij becomes α = 1…6 for 11, 22, 33, 23, 31, 12 (eq. (1.1.4.6)), and a component with
|
|
651
|
+
* α = 4, 5, 6 is the tensor component times the factor of its pair (`factors`). A symmetric tensor of
|
|
652
|
+
* rank 2 gives 6 components, one of rank 3 symmetric in its last pair a 3 × 6 matrix (d_iα), in its
|
|
653
|
+
* first pair a 6 × 3 matrix (e_αk), one of rank 4 a 6 × 6 matrix (s_αβ, c_αβ). Throws a RangeError for a specification
|
|
654
|
+
* without a symmetric index pair, factors that are missing or not one 1 or 2 per pair, and a tensor
|
|
655
|
+
* that lacks the index symmetry of its specification (within the tolerance, relative to its largest
|
|
656
|
+
* component).
|
|
657
|
+
*
|
|
658
|
+
* @remarks The tensor is flat, 3^rank components, as `tensorForm` gives a basis tensor.
|
|
659
|
+
*/
|
|
660
|
+
export function toVoigt(
|
|
661
|
+
tensor: readonly number[],
|
|
662
|
+
spec: TensorSpecArgument | TensorPropertyName,
|
|
663
|
+
options?: voigtNotation.VoigtOptions,
|
|
664
|
+
): readonly number[] | readonly (readonly number[])[] {
|
|
665
|
+
return voigtNotation.toVoigt(tensor, timeEven(spec), options);
|
|
666
|
+
}
|
|
667
|
+
|
|
668
|
+
/**
|
|
669
|
+
* The tensor of a Voigt array (`toVoigt` in reverse): each tensor component is the Voigt component
|
|
670
|
+
* of its index pairs over the factors of the pairs, so that the tensor has the index symmetry of its
|
|
671
|
+
* specification. Throws a RangeError for a Voigt array of
|
|
672
|
+
* the wrong shape, and for one that is no tensor of the specification (for rank 4 with interchangeable
|
|
673
|
+
* pairs a 6 × 6 matrix that is not symmetric, for a totally symmetric tensor one whose
|
|
674
|
+
* components do not agree), within the tolerance relative to its largest component.
|
|
675
|
+
*
|
|
676
|
+
* @remarks The tensor is flat, 3^rank components, as `tensorForm` gives a basis tensor.
|
|
677
|
+
*/
|
|
678
|
+
export function fromVoigt(
|
|
679
|
+
voigt: readonly number[] | readonly (readonly number[])[],
|
|
680
|
+
spec: TensorSpecArgument | TensorPropertyName,
|
|
681
|
+
options?: voigtNotation.VoigtOptions,
|
|
682
|
+
): readonly number[] {
|
|
683
|
+
return voigtNotation.fromVoigt(voigt, timeEven(spec), options);
|
|
684
|
+
}
|
|
685
|
+
|
|
647
686
|
/**
|
|
648
687
|
* True if the crystal class allows the named property, e.g. `allowsProperty('-6m2',
|
|
649
688
|
* 'piezoelectric')`: the tensor that describes it (`TENSOR_PROPERTIES`) has a non-zero form under
|
package/src/index.ts
CHANGED
|
@@ -32,7 +32,6 @@ export {
|
|
|
32
32
|
type LatticeParameters,
|
|
33
33
|
} from './cell.js';
|
|
34
34
|
export {
|
|
35
|
-
changeOfAxes,
|
|
36
35
|
directionFromFourIndices,
|
|
37
36
|
directionToFourIndices,
|
|
38
37
|
planeFromFourIndices,
|
|
@@ -40,10 +39,18 @@ export {
|
|
|
40
39
|
millerIndices,
|
|
41
40
|
reduceIndices,
|
|
42
41
|
zoneAxis,
|
|
43
|
-
type AxisChange,
|
|
44
42
|
type FourIndices,
|
|
45
43
|
type MillerValues,
|
|
46
44
|
} from './indices.js';
|
|
45
|
+
export {
|
|
46
|
+
changeOfCoordinates,
|
|
47
|
+
type AffineOperation,
|
|
48
|
+
type CoordinateChange,
|
|
49
|
+
type CoordinateQuantities,
|
|
50
|
+
type CoordinateTransformation,
|
|
51
|
+
type InverseTransformation,
|
|
52
|
+
type TransformedOperation,
|
|
53
|
+
} from './coordinates.js';
|
|
47
54
|
|
|
48
55
|
export type { PointGroupKey, Setting, AxesOptions, SettingOptions, SymbolOptions } from './pointGroups/pointGroups.js';
|
|
49
56
|
export { LATTICE_SYMMETRY_DIRECTIONS, type Uvw } from './symmetryDirections.js';
|
|
@@ -87,6 +94,8 @@ export {
|
|
|
87
94
|
pointGroupOf,
|
|
88
95
|
pointGroups,
|
|
89
96
|
rotateTensor,
|
|
97
|
+
toVoigt,
|
|
98
|
+
fromVoigt,
|
|
90
99
|
settings,
|
|
91
100
|
siteSymmetry,
|
|
92
101
|
siteSymmetryOf,
|
|
@@ -106,3 +115,4 @@ export {
|
|
|
106
115
|
type TensorPropertyName,
|
|
107
116
|
type TensorSpec,
|
|
108
117
|
} from './crystalClasses.js';
|
|
118
|
+
export type { VoigtFactor, VoigtOptions } from './tensors/voigt.js';
|
package/src/indices.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Miller and Bravais–Miller indices
|
|
3
|
-
*
|
|
2
|
+
* Miller and Bravais–Miller indices and the zone law (docs/conventions.md, "Cell, metric and
|
|
3
|
+
* indices"); the change of the coordinate system is in coordinates.ts. Plain integers and matrices in and out.
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { shown } from './checks.js';
|
|
7
|
-
import {
|
|
7
|
+
import { type Vec3 } from './linalg.js';
|
|
8
8
|
import { deepFreeze } from './freeze.js';
|
|
9
9
|
|
|
10
10
|
/** A direction [UVTW] or a plane (hkil) in four indices (Bravais–Miller). */
|
|
@@ -86,36 +86,6 @@ export function zoneAxis(h1: Vec3, h2: Vec3): Vec3 | undefined {
|
|
|
86
86
|
return deepFreeze(reduceIndices(c) as unknown as Vec3);
|
|
87
87
|
}
|
|
88
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 deepFreeze({ direction: clean(inverse(P)), plane: clean(transpose(P)) });
|
|
117
|
-
}
|
|
118
|
-
|
|
119
89
|
/** The values of h, k, l substituted into printed Miller indices. */
|
|
120
90
|
export interface MillerValues {
|
|
121
91
|
/** The value of h, an integer. */
|
package/src/magnetic.ts
CHANGED
|
@@ -37,7 +37,6 @@ export {
|
|
|
37
37
|
type LatticeParameters,
|
|
38
38
|
} from './cell.js';
|
|
39
39
|
export {
|
|
40
|
-
changeOfAxes,
|
|
41
40
|
directionFromFourIndices,
|
|
42
41
|
directionToFourIndices,
|
|
43
42
|
planeFromFourIndices,
|
|
@@ -45,10 +44,18 @@ export {
|
|
|
45
44
|
millerIndices,
|
|
46
45
|
reduceIndices,
|
|
47
46
|
zoneAxis,
|
|
48
|
-
type AxisChange,
|
|
49
47
|
type FourIndices,
|
|
50
48
|
type MillerValues,
|
|
51
49
|
} from './indices.js';
|
|
50
|
+
export {
|
|
51
|
+
changeOfCoordinates,
|
|
52
|
+
type AffineOperation,
|
|
53
|
+
type CoordinateChange,
|
|
54
|
+
type CoordinateQuantities,
|
|
55
|
+
type CoordinateTransformation,
|
|
56
|
+
type InverseTransformation,
|
|
57
|
+
type TransformedOperation,
|
|
58
|
+
} from './coordinates.js';
|
|
52
59
|
|
|
53
60
|
import type {
|
|
54
61
|
PointGroupKey as ClassKey,
|
|
@@ -128,6 +135,7 @@ export {
|
|
|
128
135
|
type TimeParity,
|
|
129
136
|
} from './tensors/tensorForm.js';
|
|
130
137
|
export { TENSOR_PROPERTIES, type TensorProperty, type TensorPropertyName } from './tensors/propertyTable.js';
|
|
138
|
+
export { fromVoigt, toVoigt, type VoigtFactor, type VoigtOptions } from './tensors/voigt.js';
|
|
131
139
|
export {
|
|
132
140
|
allowedProperties,
|
|
133
141
|
allowedPropertiesOf,
|