@mat3ra/made 2026.7.4-0 → 2026.7.13-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/js/basis/basis.js +8 -8
- package/dist/js/basis/coordinates.js +2 -2
- package/dist/js/cell/cell.js +11 -10
- package/dist/js/cell/primitive_cell.js +18 -19
- package/dist/js/lattice/lattice.js +25 -23
- package/dist/js/lattice/reciprocal/lattice_reciprocal.js +16 -16
- package/dist/js/parsers/poscar.js +1 -2
- package/dist/js/parsers/xyz_combinatorial_basis.js +2 -2
- package/dist/js/tools/basis.js +3 -3
- package/dist/js/tools/cell.js +3 -3
- package/dist/js/tools/material.js +3 -3
- package/dist/js/tools/supercell.js +3 -3
- package/dist/js/tools/surface.js +14 -12
- package/package.json +3 -2
- package/pyproject.toml +1 -1
- package/src/js/basis/basis.ts +9 -8
- package/src/js/basis/coordinates.ts +3 -2
- package/src/js/cell/cell.ts +12 -10
- package/src/js/cell/primitive_cell.ts +23 -19
- package/src/js/lattice/lattice.ts +25 -23
- package/src/js/lattice/reciprocal/lattice_reciprocal.ts +19 -18
- package/src/js/parsers/poscar.ts +2 -2
- package/src/js/parsers/xyz_combinatorial_basis.ts +3 -2
- package/src/js/tools/basis.ts +4 -3
- package/src/js/tools/cell.ts +4 -3
- package/src/js/tools/material.ts +5 -4
- package/src/js/tools/supercell.ts +4 -3
- package/src/js/tools/surface.ts +18 -12
- package/src/py/mat3ra/made/basis/__init__.py +6 -3
- package/src/py/mat3ra/made/tools/analyze/solid_solution_analyzer.py +171 -0
- package/src/py/mat3ra/made/tools/analyze/utils.py +25 -0
- package/src/py/mat3ra/made/tools/build/defective_structures/three_dimensional/__init__.py +1 -0
- package/src/py/mat3ra/made/tools/build/defective_structures/three_dimensional/solid_solution/__init__.py +9 -0
- package/src/py/mat3ra/made/tools/build/defective_structures/three_dimensional/solid_solution/builder.py +37 -0
- package/src/py/mat3ra/made/tools/build/defective_structures/three_dimensional/solid_solution/configuration.py +30 -0
- package/src/py/mat3ra/made/tools/build/defective_structures/three_dimensional/solid_solution/enums.py +8 -0
- package/src/py/mat3ra/made/tools/build/defective_structures/three_dimensional/solid_solution/helpers.py +76 -0
- package/src/py/mat3ra/made/tools/build_components/entities/auxiliary/zero_dimensional/crystal_site/crystal_site.py +3 -2
- package/src/py/mat3ra/made/tools/build_components/entities/auxiliary/zero_dimensional/point_defect_site/builder.py +11 -10
- package/src/py/mat3ra/made/tools/build_components/operations/core/combinations/merge/builder.py +9 -0
- package/src/py/mat3ra/made/tools/helpers.py +2 -0
- package/tests/fixtures/hashes.json +3 -0
- package/tests/js/cell/cell.ts +1 -1
- package/tests/js/fixtures.ts +7 -1
- package/tests/js/material.test.ts +8 -1
- package/tests/py/unit/test_material.py +10 -0
- package/tests/py/unit/test_tools_build_defect/test_solid_solution.py +90 -0
package/pyproject.toml
CHANGED
package/src/js/basis/basis.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
// @ts-ignore
|
|
2
2
|
import { getElectronegativity, getElementAtomicRadius } from "@exabyte-io/periodic-table.js";
|
|
3
3
|
import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
4
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
5
4
|
import { BasisSchema, Coordinate3DSchema, Vector3DSchema } from "@mat3ra/esse/dist/js/types";
|
|
5
|
+
import { Utils } from "@mat3ra/utils";
|
|
6
6
|
import { chain, toPairs, uniq, values } from "lodash";
|
|
7
7
|
|
|
8
8
|
import { Cell } from "../cell/cell";
|
|
9
9
|
import { ATOMIC_COORD_UNITS, HASH_TOLERANCE } from "../constants";
|
|
10
|
+
|
|
10
11
|
import {
|
|
11
12
|
defaultNonPeriodicMinimumLatticeSize,
|
|
12
13
|
diatomicLatticePaddingFactor,
|
|
@@ -247,7 +248,7 @@ export class Basis extends InMemoryEntity implements BasisSchema {
|
|
|
247
248
|
toStandardRepresentation() {
|
|
248
249
|
this.toCrystal();
|
|
249
250
|
this._coordinates.mapArrayInPlace(
|
|
250
|
-
(point) => point.map((x) => math.mod(x)) as Coordinate3DSchema,
|
|
251
|
+
(point) => point.map((x) => Utils.math.mod(x)) as Coordinate3DSchema,
|
|
251
252
|
);
|
|
252
253
|
}
|
|
253
254
|
|
|
@@ -330,7 +331,7 @@ export class Basis extends InMemoryEntity implements BasisSchema {
|
|
|
330
331
|
get formula(): string {
|
|
331
332
|
const counts = this.uniqueElementCountsSortedByElectronegativity;
|
|
332
333
|
const countsValues = values(counts);
|
|
333
|
-
const gcd = countsValues.length > 1 ? math.gcd(...countsValues) : countsValues[0];
|
|
334
|
+
const gcd = countsValues.length > 1 ? Utils.math.gcd(...countsValues) : countsValues[0];
|
|
334
335
|
|
|
335
336
|
return toPairs(counts)
|
|
336
337
|
.map(([element, count]) => element + (count / gcd === 1 ? "" : count / gcd))
|
|
@@ -392,7 +393,7 @@ export class Basis extends InMemoryEntity implements BasisSchema {
|
|
|
392
393
|
const element = entry[0];
|
|
393
394
|
const coordinate = entry[1];
|
|
394
395
|
const atomicLabel = entry[2];
|
|
395
|
-
const toleratedCoordinate = coordinate.map((x) => math.
|
|
396
|
+
const toleratedCoordinate = coordinate.map((x) => Utils.math.roundCustom(x, HASH_TOLERANCE));
|
|
396
397
|
return `${element}${atomicLabel} ${toleratedCoordinate.join()}`;
|
|
397
398
|
});
|
|
398
399
|
return `${standardRep.sort().join(";")};`;
|
|
@@ -471,7 +472,7 @@ export class Basis extends InMemoryEntity implements BasisSchema {
|
|
|
471
472
|
hasEquivalentCellTo(anotherBasisClsInstance: Basis): boolean {
|
|
472
473
|
return !this.cell.vectorArrays
|
|
473
474
|
.map((vector, idx) => {
|
|
474
|
-
return math.vEqualWithTolerance(
|
|
475
|
+
return Utils.math.vEqualWithTolerance(
|
|
475
476
|
vector,
|
|
476
477
|
anotherBasisClsInstance.cell.vectorArrays[idx],
|
|
477
478
|
);
|
|
@@ -496,7 +497,7 @@ export class Basis extends InMemoryEntity implements BasisSchema {
|
|
|
496
497
|
const maxDistance = this.maxPairwiseDistance;
|
|
497
498
|
const minDistance = this.minPairwiseDistance;
|
|
498
499
|
const widthRatio = maxDistance > 0 ? minDistance / maxDistance : 1;
|
|
499
|
-
const latticeScalingFactor = math.almostEqual(widthRatio, 1)
|
|
500
|
+
const latticeScalingFactor = Utils.math.almostEqual(widthRatio, 1)
|
|
500
501
|
? diatomicLatticePaddingFactor
|
|
501
502
|
: molecularLatticePaddingFactor;
|
|
502
503
|
const moleculeLatticeSize = maxDistance * latticeScalingFactor;
|
|
@@ -525,7 +526,7 @@ export class Basis extends InMemoryEntity implements BasisSchema {
|
|
|
525
526
|
(getElementAtomicRadius(el1) + getElementAtomicRadius(el2)); // in angstroms
|
|
526
527
|
|
|
527
528
|
// @ts-ignore
|
|
528
|
-
const distance = math.vDist(entry1.value, entry2.value) as number;
|
|
529
|
+
const distance = Utils.math.vDist(entry1.value, entry2.value) as number;
|
|
529
530
|
if (distance < tolerance) {
|
|
530
531
|
overlaps.push({
|
|
531
532
|
id1: i,
|
|
@@ -571,7 +572,7 @@ export class Basis extends InMemoryEntity implements BasisSchema {
|
|
|
571
572
|
if (this._elements.values.length >= 2) {
|
|
572
573
|
for (let i = 0; i < this._elements.values.length; i++) {
|
|
573
574
|
for (let j = i + 1; j < this._elements.values.length; j++) {
|
|
574
|
-
const distance = math.vDist(
|
|
575
|
+
const distance = Utils.math.vDist(
|
|
575
576
|
this._coordinates.getElementValueByIndex(i) as Coordinate3DSchema,
|
|
576
577
|
this._coordinates.getElementValueByIndex(j) as Coordinate3DSchema,
|
|
577
578
|
);
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
import { RoundedArrayWithIds, RoundedValueWithId, RoundedVector3D, Vector3D } from "@mat3ra/code";
|
|
2
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
3
2
|
import {
|
|
4
3
|
AtomicCoordinateSchema,
|
|
5
4
|
Coordinate3DSchema,
|
|
6
5
|
Matrix3X3Schema,
|
|
7
6
|
Vector3DSchema,
|
|
8
7
|
} from "@mat3ra/esse/dist/js/types";
|
|
8
|
+
import { Utils } from "@mat3ra/utils";
|
|
9
9
|
import { sprintf } from "underscore.string";
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
export type AtomicCoordinateValue = AtomicCoordinateSchema["value"];
|
|
12
13
|
|
|
13
14
|
type AxisType = "x" | "y" | "z";
|
|
@@ -78,7 +79,7 @@ export class Coordinates extends RoundedArrayWithIds<Coordinate3DSchema> {
|
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
getCenterPoint(): Vector3DSchema {
|
|
81
|
-
const transposed = math.transpose(this.values) as Matrix3X3Schema;
|
|
82
|
+
const transposed = Utils.math.transpose(this.values) as Matrix3X3Schema;
|
|
82
83
|
const center: Vector3DSchema = [0, 0, 0];
|
|
83
84
|
|
|
84
85
|
for (let i = 0; i < 3; i++) {
|
package/src/js/cell/cell.ts
CHANGED
|
@@ -1,17 +1,18 @@
|
|
|
1
1
|
import { RoundedVector3D } from "@mat3ra/code";
|
|
2
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
3
2
|
import {
|
|
4
3
|
Coordinate3DSchema,
|
|
5
4
|
LatticeVectorsSchema as CellSchema,
|
|
6
5
|
Matrix3X3Schema,
|
|
7
6
|
Vector3DSchema,
|
|
8
7
|
} from "@mat3ra/esse/dist/js/types";
|
|
8
|
+
import { Utils } from "@mat3ra/utils";
|
|
9
9
|
|
|
10
10
|
import constants from "../constants";
|
|
11
11
|
|
|
12
|
-
|
|
13
|
-
const
|
|
14
|
-
const
|
|
12
|
+
|
|
13
|
+
const MATRIX = Utils.math.matrix;
|
|
14
|
+
const MULT = Utils.math.multiply;
|
|
15
|
+
const INV = Utils.math.inv;
|
|
15
16
|
// @ts-ignore
|
|
16
17
|
const MATRIX_MULT = (...args) => MULT(...args.map((x) => MATRIX(x))).toArray();
|
|
17
18
|
|
|
@@ -74,11 +75,11 @@ export class Cell implements CellSchema {
|
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
get volume(): number {
|
|
77
|
-
return math.det(this.vectorArrays);
|
|
78
|
+
return Utils.math.det(this.vectorArrays);
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
get volumeRounded(): number {
|
|
81
|
-
return math.roundArrayOrNumber(this.volume, Cell.roundPrecision) as number;
|
|
82
|
+
return Utils.math.roundArrayOrNumber(this.volume, Cell.roundPrecision) as number;
|
|
82
83
|
}
|
|
83
84
|
|
|
84
85
|
clone(): Cell {
|
|
@@ -103,7 +104,7 @@ export class Cell implements CellSchema {
|
|
|
103
104
|
const { tolerance } = this.constructor as typeof Cell;
|
|
104
105
|
return (
|
|
105
106
|
this.convertPointToCrystal(point)
|
|
106
|
-
.map((c: number) => math.isBetweenZeroInclusiveAndOne(c, tolerance))
|
|
107
|
+
.map((c: number) => Utils.math.isBetweenZeroInclusiveAndOne(c, tolerance))
|
|
107
108
|
// @ts-ignore
|
|
108
109
|
.reduce((a: boolean, b: boolean): boolean => a && b)
|
|
109
110
|
);
|
|
@@ -114,7 +115,7 @@ export class Cell implements CellSchema {
|
|
|
114
115
|
const { tolerance } = this.constructor as typeof Cell;
|
|
115
116
|
return (
|
|
116
117
|
point
|
|
117
|
-
.map((c: number) => math.isBetweenZeroInclusiveAndOne(c, tolerance))
|
|
118
|
+
.map((c: number) => Utils.math.isBetweenZeroInclusiveAndOne(c, tolerance))
|
|
118
119
|
// @ts-ignore
|
|
119
120
|
.reduce((a: boolean, b: boolean): boolean => a && b)
|
|
120
121
|
);
|
|
@@ -128,11 +129,12 @@ export class Cell implements CellSchema {
|
|
|
128
129
|
}
|
|
129
130
|
|
|
130
131
|
getMostCollinearVectorIndex(testVector: Vector3DSchema): number {
|
|
131
|
-
const angles = this.vectorArrays.map((v) => math.angleUpTo90(v, testVector, "deg"));
|
|
132
|
-
return angles.findIndex((el: number) => el === math.min(angles));
|
|
132
|
+
const angles = this.vectorArrays.map((v) => Utils.math.angleUpTo90(v, testVector, "deg"));
|
|
133
|
+
return angles.findIndex((el: number) => el === Utils.math.min(angles));
|
|
133
134
|
}
|
|
134
135
|
|
|
135
136
|
scaleByMatrix(matrix: number[][]) {
|
|
137
|
+
// @ts-ignore - mathjs v12 multiply return type is broader than runtime
|
|
136
138
|
[this.a, this.b, this.c] = MATRIX_MULT(matrix, this.vectorArrays);
|
|
137
139
|
}
|
|
138
140
|
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
2
1
|
import { LatticeSchema, Matrix3X3Schema } from "@mat3ra/esse/dist/js/types";
|
|
2
|
+
import { Utils } from "@mat3ra/utils";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Routines for calculating primitive cell vectors from conventional cell Bravais parameters.
|
|
@@ -80,42 +80,45 @@ const PRIMITIVE_CELLS = {
|
|
|
80
80
|
|
|
81
81
|
HEX: ({ a, c }: LatticeSchema): Matrix3X3Schema => {
|
|
82
82
|
return [
|
|
83
|
-
[a / 2, (-a * math.sqrt(3)) / 2, 0],
|
|
84
|
-
[a / 2, (a * math.sqrt(3)) / 2, 0],
|
|
83
|
+
[a / 2, (-a * Number(Utils.math.sqrt(3))) / 2, 0],
|
|
84
|
+
[a / 2, (a * Number(Utils.math.sqrt(3))) / 2, 0],
|
|
85
85
|
[0, 0, c],
|
|
86
86
|
];
|
|
87
87
|
},
|
|
88
88
|
|
|
89
89
|
RHL: ({ a, alpha }: LatticeSchema): Matrix3X3Schema => {
|
|
90
|
-
const cosAlpha = math.cos((alpha / 180) * math.PI);
|
|
91
|
-
const cosHalfAlpha = math.sqrt((1 / 2) * (1 + cosAlpha));
|
|
92
|
-
const sinHalfAlpha = math.sqrt((1 / 2) * (1 - cosAlpha));
|
|
90
|
+
const cosAlpha = Number(Utils.math.cos((alpha / 180) * Number(Utils.math.PI)));
|
|
91
|
+
const cosHalfAlpha = Number(Utils.math.sqrt((1 / 2) * (1 + cosAlpha)));
|
|
92
|
+
const sinHalfAlpha = Number(Utils.math.sqrt((1 / 2) * (1 - cosAlpha)));
|
|
93
93
|
return [
|
|
94
94
|
[a * cosHalfAlpha, -a * sinHalfAlpha, 0.0],
|
|
95
95
|
[a * cosHalfAlpha, a * sinHalfAlpha, 0.0],
|
|
96
96
|
[
|
|
97
97
|
(a * cosAlpha) / cosHalfAlpha,
|
|
98
98
|
0.0,
|
|
99
|
-
a *
|
|
99
|
+
a *
|
|
100
|
+
Number(
|
|
101
|
+
Utils.math.sqrt(1 - (cosAlpha * cosAlpha) / (cosHalfAlpha * cosHalfAlpha)),
|
|
102
|
+
),
|
|
100
103
|
],
|
|
101
104
|
];
|
|
102
105
|
},
|
|
103
106
|
|
|
104
107
|
MCL: ({ a, b, c, alpha }: LatticeSchema): Matrix3X3Schema => {
|
|
105
|
-
const cosAlpha = math.cos((alpha / 180) * math.PI);
|
|
108
|
+
const cosAlpha = Number(Utils.math.cos((alpha / 180) * Number(Utils.math.PI)));
|
|
106
109
|
return [
|
|
107
110
|
[a, 0, 0],
|
|
108
111
|
[0, b, 0],
|
|
109
|
-
[0, c * cosAlpha, c * math.sqrt(1 - cosAlpha * cosAlpha)],
|
|
112
|
+
[0, c * cosAlpha, c * Number(Utils.math.sqrt(1 - cosAlpha * cosAlpha))],
|
|
110
113
|
];
|
|
111
114
|
},
|
|
112
115
|
|
|
113
116
|
MCLC: ({ a, b, c, alpha }: LatticeSchema): Matrix3X3Schema => {
|
|
114
|
-
const cosAlpha = math.cos((alpha / 180) * math.PI);
|
|
117
|
+
const cosAlpha = Number(Utils.math.cos((alpha / 180) * Number(Utils.math.PI)));
|
|
115
118
|
return [
|
|
116
119
|
[a / 2, b / 2, 0],
|
|
117
120
|
[-a / 2, b / 2, 0],
|
|
118
|
-
[0, c * cosAlpha, c * math.sqrt(1 - cosAlpha * cosAlpha)],
|
|
121
|
+
[0, c * cosAlpha, c * Number(Utils.math.sqrt(1 - cosAlpha * cosAlpha))],
|
|
119
122
|
];
|
|
120
123
|
},
|
|
121
124
|
|
|
@@ -123,22 +126,23 @@ const PRIMITIVE_CELLS = {
|
|
|
123
126
|
TRI: ({ a, b, c, alpha, beta, gamma }: LatticeSchema): Matrix3X3Schema => {
|
|
124
127
|
// convert angles to Radians
|
|
125
128
|
// eslint-disable-next-line no-param-reassign
|
|
126
|
-
[alpha, beta, gamma] = [alpha, beta, gamma].map(
|
|
127
|
-
|
|
128
|
-
(x) => math.unit(x, "degree").to("rad").value,
|
|
129
|
+
[alpha, beta, gamma] = [alpha, beta, gamma].map((x) =>
|
|
130
|
+
Number(Utils.math.unit(x, "degree").to("rad").value),
|
|
129
131
|
);
|
|
130
132
|
|
|
131
|
-
const [cosAlpha, cosBeta, cosGamma] = [alpha, beta, gamma].map((x) =>
|
|
132
|
-
|
|
133
|
+
const [cosAlpha, cosBeta, cosGamma] = [alpha, beta, gamma].map((x) =>
|
|
134
|
+
Number(Utils.math.cos(x)),
|
|
135
|
+
);
|
|
136
|
+
const [sinAlpha, sinBeta] = [alpha, beta].map((x) => Number(Utils.math.sin(x)));
|
|
133
137
|
let acosArg = (cosAlpha * cosBeta - cosGamma) / (sinAlpha * sinBeta);
|
|
134
138
|
if (acosArg < -1) {
|
|
135
139
|
acosArg = -1;
|
|
136
140
|
} else if (acosArg > 1) {
|
|
137
141
|
acosArg = 1;
|
|
138
142
|
}
|
|
139
|
-
const gammaStar = math.acos(acosArg);
|
|
140
|
-
const cosGammaStar = math.cos(gammaStar);
|
|
141
|
-
const sinGammaStar = math.sin(gammaStar);
|
|
143
|
+
const gammaStar = Number(Utils.math.acos(acosArg));
|
|
144
|
+
const cosGammaStar = Number(Utils.math.cos(gammaStar));
|
|
145
|
+
const sinGammaStar = Number(Utils.math.sin(gammaStar));
|
|
142
146
|
|
|
143
147
|
return [
|
|
144
148
|
[a * sinBeta, 0.0, a * cosBeta],
|
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
import { HASH_TOLERANCE } from "@mat3ra/code/dist/js/constants";
|
|
2
1
|
import { InMemoryEntity } from "@mat3ra/code/dist/js/entity";
|
|
3
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
4
2
|
import {
|
|
5
3
|
Coordinate3DSchema,
|
|
6
4
|
LatticeSchema,
|
|
@@ -9,6 +7,7 @@ import {
|
|
|
9
7
|
LatticeVectorsSchema,
|
|
10
8
|
Matrix3X3Schema,
|
|
11
9
|
} from "@mat3ra/esse/dist/js/types";
|
|
10
|
+
import { Utils } from "@mat3ra/utils";
|
|
12
11
|
import * as lodash from "lodash";
|
|
13
12
|
|
|
14
13
|
import { Cell } from "../cell/cell";
|
|
@@ -16,6 +15,7 @@ import { getPrimitiveLatticeVectorsFromConfig } from "../cell/primitive_cell";
|
|
|
16
15
|
import { LATTICE_TYPE_CONFIGS } from "./lattice_types";
|
|
17
16
|
import { UnitCell, UnitCellProps } from "./unit_cell";
|
|
18
17
|
|
|
18
|
+
const { HASH_TOLERANCE } = Utils.constants;
|
|
19
19
|
/**
|
|
20
20
|
* Scaling factor used to calculate the new lattice size for non-periodic systems.
|
|
21
21
|
* The scaling factor ensures that a non-periodic structure will have have a lattice greater than the structures size.
|
|
@@ -86,19 +86,21 @@ export class Lattice extends InMemoryEntity implements LatticeSchema {
|
|
|
86
86
|
const { b } = this;
|
|
87
87
|
const { c } = this;
|
|
88
88
|
|
|
89
|
-
const alphaRad = math.unit(this.alpha, "deg").toNumber("rad");
|
|
90
|
-
const betaRad = math.unit(this.beta, "deg").toNumber("rad");
|
|
91
|
-
const gammaRad = math.unit(this.gamma, "deg").toNumber("rad");
|
|
89
|
+
const alphaRad = Utils.math.unit(this.alpha, "deg").toNumber("rad");
|
|
90
|
+
const betaRad = Utils.math.unit(this.beta, "deg").toNumber("rad");
|
|
91
|
+
const gammaRad = Utils.math.unit(this.gamma, "deg").toNumber("rad");
|
|
92
92
|
|
|
93
|
-
const cosAlpha = math.cos(alphaRad);
|
|
94
|
-
const cosBeta = math.cos(betaRad);
|
|
95
|
-
const cosGamma = math.cos(gammaRad);
|
|
96
|
-
const sinAlpha = math.sin(alphaRad);
|
|
97
|
-
const sinBeta = math.sin(betaRad);
|
|
93
|
+
const cosAlpha = Utils.math.cos(alphaRad);
|
|
94
|
+
const cosBeta = Utils.math.cos(betaRad);
|
|
95
|
+
const cosGamma = Utils.math.cos(gammaRad);
|
|
96
|
+
const sinAlpha = Utils.math.sin(alphaRad);
|
|
97
|
+
const sinBeta = Utils.math.sin(betaRad);
|
|
98
98
|
|
|
99
|
-
const gammaStar = math.acos((cosAlpha * cosBeta - cosGamma) / (sinAlpha * sinBeta));
|
|
100
|
-
|
|
101
|
-
const
|
|
99
|
+
const gammaStar = Utils.math.acos((cosAlpha * cosBeta - cosGamma) / (sinAlpha * sinBeta));
|
|
100
|
+
// @ts-ignore - mathjs v12 acos return type includes Complex, but inputs are always real
|
|
101
|
+
const cosGammaStar = Utils.math.cos(gammaStar);
|
|
102
|
+
// @ts-ignore
|
|
103
|
+
const sinGammaStar = Utils.math.sin(gammaStar);
|
|
102
104
|
|
|
103
105
|
const vectorA: Coordinate3DSchema = [a * sinBeta, 0.0, a * cosBeta];
|
|
104
106
|
const vectorB: Coordinate3DSchema = [
|
|
@@ -121,12 +123,12 @@ export class Lattice extends InMemoryEntity implements LatticeSchema {
|
|
|
121
123
|
type: LatticeTypeEnum = "TRI",
|
|
122
124
|
): Lattice {
|
|
123
125
|
const [aVec, bVec, cVec] = vectors;
|
|
124
|
-
const a = math.vlen(aVec);
|
|
125
|
-
const b = math.vlen(bVec);
|
|
126
|
-
const c = math.vlen(cVec);
|
|
127
|
-
const alpha = math.angle(bVec, cVec, "deg");
|
|
128
|
-
const beta = math.angle(aVec, cVec, "deg");
|
|
129
|
-
const gamma = math.angle(aVec, bVec, "deg");
|
|
126
|
+
const a = Utils.math.vlen(aVec);
|
|
127
|
+
const b = Utils.math.vlen(bVec);
|
|
128
|
+
const c = Utils.math.vlen(cVec);
|
|
129
|
+
const alpha = Utils.math.angle(bVec, cVec, "deg");
|
|
130
|
+
const beta = Utils.math.angle(aVec, cVec, "deg");
|
|
131
|
+
const gamma = Utils.math.angle(aVec, bVec, "deg");
|
|
130
132
|
|
|
131
133
|
return new Lattice({
|
|
132
134
|
a,
|
|
@@ -183,7 +185,7 @@ export class Lattice extends InMemoryEntity implements LatticeSchema {
|
|
|
183
185
|
*/
|
|
184
186
|
get typeExtended(): LatticeTypeExtendedEnum {
|
|
185
187
|
const { a, b, c, alpha, beta, gamma, type } = this;
|
|
186
|
-
const cosAlpha = math.cos((alpha / 180) * math.PI);
|
|
188
|
+
const cosAlpha = Utils.math.cos((alpha / 180) * Utils.math.PI);
|
|
187
189
|
|
|
188
190
|
switch (type) {
|
|
189
191
|
case "BCT":
|
|
@@ -220,7 +222,7 @@ export class Lattice extends InMemoryEntity implements LatticeSchema {
|
|
|
220
222
|
* Calculate the volume of the lattice cell.
|
|
221
223
|
*/
|
|
222
224
|
get volume(): number {
|
|
223
|
-
return math.abs(math.det(this.vectorArrays));
|
|
225
|
+
return Utils.math.abs(Utils.math.det(this.vectorArrays));
|
|
224
226
|
}
|
|
225
227
|
|
|
226
228
|
/*
|
|
@@ -228,7 +230,7 @@ export class Lattice extends InMemoryEntity implements LatticeSchema {
|
|
|
228
230
|
* @param latticeConfig {Object} LatticeBravais config (see constructor)
|
|
229
231
|
*/
|
|
230
232
|
static getDefaultPrimitiveLatticeConfigByType(latticeConfig: LatticeSchema) {
|
|
231
|
-
const f_ = math.roundArrayOrNumber;
|
|
233
|
+
const f_ = Utils.math.roundArrayOrNumber;
|
|
232
234
|
// construct new primitive cell using lattice parameters and skip rounding the vectors
|
|
233
235
|
const vectors = getPrimitiveLatticeVectorsFromConfig(latticeConfig);
|
|
234
236
|
// create new lattice from primitive cell
|
|
@@ -268,7 +270,7 @@ export class Lattice extends InMemoryEntity implements LatticeSchema {
|
|
|
268
270
|
scaledLattice.beta,
|
|
269
271
|
scaledLattice.gamma,
|
|
270
272
|
]
|
|
271
|
-
.map((x) => math.
|
|
273
|
+
.map((x) => Utils.math.roundCustom(x, HASH_TOLERANCE))
|
|
272
274
|
.join(";")};`;
|
|
273
275
|
}
|
|
274
276
|
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { ATOMIC_COORD_UNITS, units as UNITS } from "@mat3ra/code/dist/js/constants";
|
|
2
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
3
2
|
import { Vector3DSchema } from "@mat3ra/esse/dist/js/types";
|
|
3
|
+
import { Utils } from "@mat3ra/utils";
|
|
4
4
|
import lodash from "lodash";
|
|
5
5
|
|
|
6
6
|
import { Lattice } from "../lattice";
|
|
7
7
|
import { paths } from "./paths";
|
|
8
8
|
import { symmetryPoints } from "./symmetry_points";
|
|
9
9
|
|
|
10
|
+
|
|
10
11
|
export type KPointCoordinates = number[];
|
|
11
12
|
export type KPointPath = Array<{
|
|
12
13
|
point: string;
|
|
@@ -39,16 +40,16 @@ export class ReciprocalLattice extends Lattice {
|
|
|
39
40
|
*/
|
|
40
41
|
get reciprocalVectors(): Vector3DSchema[] {
|
|
41
42
|
const vectors_: Vector3DSchema[] = this.vectors.vectorArrays as Vector3DSchema[];
|
|
42
|
-
const a: number = math.vlen(vectors_[0]);
|
|
43
|
+
const a: number = Utils.math.vlen(vectors_[0]);
|
|
43
44
|
const divider: number =
|
|
44
|
-
(math.multiply(
|
|
45
|
+
(Utils.math.multiply(
|
|
45
46
|
vectors_[0],
|
|
46
|
-
math.cross(vectors_[1], vectors_[2]),
|
|
47
|
+
Utils.math.cross(vectors_[1], vectors_[2]),
|
|
47
48
|
) as unknown as number) / a;
|
|
48
49
|
return [
|
|
49
|
-
math.multiply(math.cross(vectors_[1], vectors_[2]), 1 / divider) as Vector3DSchema,
|
|
50
|
-
math.multiply(math.cross(vectors_[2], vectors_[0]), 1 / divider) as Vector3DSchema,
|
|
51
|
-
math.multiply(math.cross(vectors_[0], vectors_[1]), 1 / divider) as Vector3DSchema,
|
|
50
|
+
Utils.math.multiply(Utils.math.cross(vectors_[1], vectors_[2]), 1 / divider) as Vector3DSchema,
|
|
51
|
+
Utils.math.multiply(Utils.math.cross(vectors_[2], vectors_[0]), 1 / divider) as Vector3DSchema,
|
|
52
|
+
Utils.math.multiply(Utils.math.cross(vectors_[0], vectors_[1]), 1 / divider) as Vector3DSchema,
|
|
52
53
|
];
|
|
53
54
|
}
|
|
54
55
|
|
|
@@ -56,7 +57,7 @@ export class ReciprocalLattice extends Lattice {
|
|
|
56
57
|
* Norms of reciprocal vectors.
|
|
57
58
|
*/
|
|
58
59
|
get reciprocalVectorNorms(): Vector3DSchema {
|
|
59
|
-
return this.reciprocalVectors.map((vec) => math.norm(vec) as number) as Vector3DSchema;
|
|
60
|
+
return this.reciprocalVectors.map((vec) => Utils.math.norm(vec) as number) as Vector3DSchema;
|
|
60
61
|
}
|
|
61
62
|
|
|
62
63
|
/**
|
|
@@ -64,7 +65,7 @@ export class ReciprocalLattice extends Lattice {
|
|
|
64
65
|
*/
|
|
65
66
|
get reciprocalVectorRatios(): Vector3DSchema {
|
|
66
67
|
const norms: number[] = this.reciprocalVectorNorms;
|
|
67
|
-
const maxNorm: number = math.max(...norms) as number;
|
|
68
|
+
const maxNorm: number = Utils.math.max(...norms) as number;
|
|
68
69
|
return norms.map((n: number) => n / maxNorm) as Vector3DSchema;
|
|
69
70
|
}
|
|
70
71
|
|
|
@@ -74,7 +75,7 @@ export class ReciprocalLattice extends Lattice {
|
|
|
74
75
|
* @return {KPointCoordinates}
|
|
75
76
|
*/
|
|
76
77
|
getCartesianCoordinates(point: KPointCoordinates): KPointCoordinates {
|
|
77
|
-
return math.multiply(point, this.reciprocalVectors) as KPointCoordinates;
|
|
78
|
+
return Utils.math.multiply(point, this.reciprocalVectors) as KPointCoordinates;
|
|
78
79
|
}
|
|
79
80
|
|
|
80
81
|
/**
|
|
@@ -105,7 +106,7 @@ export class ReciprocalLattice extends Lattice {
|
|
|
105
106
|
|
|
106
107
|
dataPoints.forEach((point: KPointCoordinates, index: number) => {
|
|
107
108
|
const symmPoint: SymmetryPoint | undefined = symmPoints.find((x) => {
|
|
108
|
-
return math.vEqualWithTolerance(x.coordinates, point, 1e-4);
|
|
109
|
+
return Utils.math.vEqualWithTolerance(x.coordinates, point, 1e-4);
|
|
109
110
|
});
|
|
110
111
|
if (symmPoint) {
|
|
111
112
|
kpointPath.push({
|
|
@@ -128,10 +129,10 @@ export class ReciprocalLattice extends Lattice {
|
|
|
128
129
|
calculateDimension(nPoints: number, index: number): number {
|
|
129
130
|
const norms: number[] = this.reciprocalVectorNorms;
|
|
130
131
|
const [j, k] = [0, 1, 2].filter((i) => i !== index); // get indices of other two dimensions
|
|
131
|
-
const N: number = math.cbrt(
|
|
132
|
+
const N: number = Utils.math.cbrt(
|
|
132
133
|
(nPoints * norms[index] ** 2) / (norms[j] * norms[k]),
|
|
133
134
|
) as number;
|
|
134
|
-
return math.max(1, math.ceil(N)) as number;
|
|
135
|
+
return Utils.math.max(1, Utils.math.ceil(N)) as number;
|
|
135
136
|
}
|
|
136
137
|
|
|
137
138
|
/**
|
|
@@ -148,10 +149,10 @@ export class ReciprocalLattice extends Lattice {
|
|
|
148
149
|
const { a } = this;
|
|
149
150
|
return {
|
|
150
151
|
[ATOMIC_COORD_UNITS.cartesian]: {
|
|
151
|
-
[UNITS.angstrom]: (2 * math.PI) / a,
|
|
152
|
+
[UNITS.angstrom]: (2 * Utils.math.PI) / a,
|
|
152
153
|
},
|
|
153
154
|
[UNITS.angstrom]: {
|
|
154
|
-
[ATOMIC_COORD_UNITS.cartesian]: a / (2 * math.PI),
|
|
155
|
+
[ATOMIC_COORD_UNITS.cartesian]: a / (2 * Utils.math.PI),
|
|
155
156
|
},
|
|
156
157
|
};
|
|
157
158
|
}
|
|
@@ -166,7 +167,7 @@ export class ReciprocalLattice extends Lattice {
|
|
|
166
167
|
getDimensionsFromSpacing(spacing: number, units: string = ATOMIC_COORD_UNITS.cartesian) {
|
|
167
168
|
const factor: number = this.conversionTable[units][ATOMIC_COORD_UNITS.cartesian] || 1;
|
|
168
169
|
return this.reciprocalVectorNorms.map((norm: number) => {
|
|
169
|
-
return math.max(1, math.ceil(lodash.round(norm / (spacing * factor), 4))) as number;
|
|
170
|
+
return Utils.math.max(1, Utils.math.ceil(lodash.round(norm / (spacing * factor), 4))) as number;
|
|
170
171
|
}) as Vector3DSchema;
|
|
171
172
|
}
|
|
172
173
|
|
|
@@ -184,8 +185,8 @@ export class ReciprocalLattice extends Lattice {
|
|
|
184
185
|
const norms: number[] = this.reciprocalVectorNorms;
|
|
185
186
|
return (
|
|
186
187
|
factor *
|
|
187
|
-
(math.mean(
|
|
188
|
-
dimensions.map((dim: number, i: number) => norms[i] / math.max(1, dim)),
|
|
188
|
+
(Utils.math.mean(
|
|
189
|
+
dimensions.map((dim: number, i: number) => norms[i] / Utils.math.max(1, dim)),
|
|
189
190
|
) as number)
|
|
190
191
|
);
|
|
191
192
|
}
|
package/src/js/parsers/poscar.ts
CHANGED
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
2
1
|
import {
|
|
3
2
|
BasisSchema,
|
|
4
3
|
Coordinate3DSchema,
|
|
@@ -16,7 +15,8 @@ import { ATOMIC_COORD_UNITS } from "../constants";
|
|
|
16
15
|
import { AtomicConstraintValue } from "../constraints/constraints";
|
|
17
16
|
import { Lattice } from "../lattice/lattice";
|
|
18
17
|
|
|
19
|
-
|
|
18
|
+
|
|
19
|
+
const _print = (x: number, printFormat = "%14.9f") => s.sprintf(printFormat, Utils.math.precise(x));
|
|
20
20
|
const _latticeVectorsToString = (vectors: Vector3DSchema[]) =>
|
|
21
21
|
vectors.map((v) => v.map((c) => _print(c)).join("\t")).join("\n");
|
|
22
22
|
const atomicConstraintsCharFromBool = (bool: boolean): string => (bool ? "T" : "F");
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
2
1
|
import { BasisSchema } from "@mat3ra/esse/dist/js/types";
|
|
2
|
+
import { Utils } from "@mat3ra/utils";
|
|
3
3
|
import { chain, last, map } from "lodash";
|
|
4
4
|
import * as s from "underscore.string";
|
|
5
5
|
|
|
@@ -8,6 +8,7 @@ import { AtomicCoordinateValue } from "../basis/coordinates";
|
|
|
8
8
|
import { AtomicElementValue } from "../basis/elements";
|
|
9
9
|
import { Cell } from "../cell/cell";
|
|
10
10
|
|
|
11
|
+
|
|
11
12
|
/**
|
|
12
13
|
* @summary Combinatorial XYZ basis class and related. Create and get all information about basis and elements in it.
|
|
13
14
|
* Constructor accepts string in extended XYZ format. Extended XYZ format is as follows:
|
|
@@ -224,7 +225,7 @@ export class CombinatorialBasis {
|
|
|
224
225
|
dimensions.push(itemsSet);
|
|
225
226
|
});
|
|
226
227
|
// @ts-ignore // We're multiplying objects with math, not numbers. No type casting will help.
|
|
227
|
-
const basisSet = math.cartesianProduct.apply(null, dimensions) as ElementWithCoordinate[][];
|
|
228
|
+
const basisSet = Utils.math.cartesianProduct.apply(null, dimensions) as ElementWithCoordinate[][];
|
|
228
229
|
return basisSet.map((basis: ElementWithCoordinate[]) =>
|
|
229
230
|
basis.filter((entry) => entry.element !== VACANCY_CHARACTER),
|
|
230
231
|
);
|
package/src/js/tools/basis.ts
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
2
1
|
import { Coordinate3DSchema } from "@mat3ra/esse/dist/js/types";
|
|
2
|
+
import { Utils } from "@mat3ra/utils";
|
|
3
3
|
import { chunk, flatten } from "lodash";
|
|
4
4
|
|
|
5
5
|
import { Basis } from "../basis/basis";
|
|
6
6
|
import { AtomicCoordinateValue, Coordinate } from "../basis/coordinates";
|
|
7
7
|
|
|
8
|
-
|
|
9
|
-
const
|
|
8
|
+
|
|
9
|
+
const ADD = Utils.math.add;
|
|
10
|
+
const MULT = Utils.math.multiply;
|
|
10
11
|
|
|
11
12
|
/**
|
|
12
13
|
* Returns a repeated basis of a crystal.
|
package/src/js/tools/cell.ts
CHANGED
|
@@ -1,8 +1,9 @@
|
|
|
1
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
2
1
|
import { Coordinate3DSchema, Matrix3X3Schema } from "@mat3ra/esse/dist/js/types";
|
|
2
|
+
import { Utils } from "@mat3ra/utils";
|
|
3
3
|
|
|
4
4
|
import { Cell } from "../cell/cell";
|
|
5
5
|
|
|
6
|
+
|
|
6
7
|
/**
|
|
7
8
|
* Returns the list of points on the original lattice contained in the supercell in fractional coordinates.
|
|
8
9
|
* Source: https://pymatgen.org/_modules/pymatgen/util/coord.html
|
|
@@ -22,8 +23,8 @@ function latticePointsInSupercell(supercellMatrix: Matrix3X3Schema) {
|
|
|
22
23
|
const d_points = diagonals.map((point) =>
|
|
23
24
|
supercell.convertPointToCartesian(point as Coordinate3DSchema),
|
|
24
25
|
);
|
|
25
|
-
const mins = [0, 1, 2].map((i) => math.min(...d_points.map((p) => p[i])));
|
|
26
|
-
const maxes = [0, 1, 2].map((i) => math.max(...d_points.map((p) => p[i])) + 1);
|
|
26
|
+
const mins = [0, 1, 2].map((i) => Utils.math.min(...d_points.map((p) => p[i])));
|
|
27
|
+
const maxes = [0, 1, 2].map((i) => Utils.math.max(...d_points.map((p) => p[i])) + 1);
|
|
27
28
|
const points = [];
|
|
28
29
|
for (let i = mins[0]; i <= maxes[0]; i++) {
|
|
29
30
|
for (let j = mins[1]; j <= maxes[1]; j++) {
|
package/src/js/tools/material.ts
CHANGED
|
@@ -1,10 +1,11 @@
|
|
|
1
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
2
1
|
import { LatticeSchema, Vector3DSchema } from "@mat3ra/esse/dist/js/types";
|
|
2
|
+
import { Utils } from "@mat3ra/utils";
|
|
3
3
|
|
|
4
4
|
import { ATOMIC_COORD_UNITS } from "../constants";
|
|
5
5
|
import { Lattice } from "../lattice/lattice";
|
|
6
6
|
import { Material } from "../material";
|
|
7
7
|
|
|
8
|
+
|
|
8
9
|
/**
|
|
9
10
|
* Scales one lattice vector for the given material
|
|
10
11
|
* @param material {Material} The material acted upon.
|
|
@@ -44,11 +45,11 @@ function translateAtomsToCenter(material: Material) {
|
|
|
44
45
|
material.toCartesian();
|
|
45
46
|
const updatedBasis = material.Basis;
|
|
46
47
|
const centerOfCoordinates = updatedBasis.centerOfCoordinatesPoint;
|
|
47
|
-
const centerOfLattice = math.multiply(
|
|
48
|
+
const centerOfLattice = Utils.math.multiply(
|
|
48
49
|
0.5,
|
|
49
|
-
material.Lattice.vectorArrays.reduce((a, b) => math.add(a, b) as Vector3DSchema),
|
|
50
|
+
material.Lattice.vectorArrays.reduce((a, b) => Utils.math.add(a, b) as Vector3DSchema),
|
|
50
51
|
);
|
|
51
|
-
const translationVector = math.subtract(centerOfLattice, centerOfCoordinates);
|
|
52
|
+
const translationVector = Utils.math.subtract(centerOfLattice, centerOfCoordinates);
|
|
52
53
|
updatedBasis.translateByVector(translationVector as Vector3DSchema);
|
|
53
54
|
material.setBasis(updatedBasis.toJSON());
|
|
54
55
|
if (originalUnits !== ATOMIC_COORD_UNITS.cartesian) material.toCrystal();
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { math } from "@mat3ra/code/dist/js/math";
|
|
2
1
|
import { Coordinate3DSchema, Matrix3X3Schema } from "@mat3ra/esse/dist/js/types";
|
|
2
|
+
import { Utils } from "@mat3ra/utils";
|
|
3
3
|
|
|
4
4
|
import { Basis } from "../basis/basis";
|
|
5
5
|
import { ConstrainedBasis } from "../basis/constrained_basis";
|
|
@@ -8,7 +8,8 @@ import { Lattice } from "../lattice/lattice";
|
|
|
8
8
|
import type { Material } from "../material";
|
|
9
9
|
import cellTools from "./cell";
|
|
10
10
|
|
|
11
|
-
|
|
11
|
+
|
|
12
|
+
const ADD = Utils.math.add;
|
|
12
13
|
|
|
13
14
|
/**
|
|
14
15
|
* @summary Generates new basis for a supercell. For each site from basis generates shifts that are within supercell.
|
|
@@ -56,7 +57,7 @@ function generateNewBasisWithinSupercell(
|
|
|
56
57
|
* @param supercellMatrix {Number[][]}
|
|
57
58
|
*/
|
|
58
59
|
function generateConfig(material: Material, supercellMatrix: Matrix3X3Schema) {
|
|
59
|
-
const det = math.det(supercellMatrix);
|
|
60
|
+
const det = Utils.math.det(supercellMatrix);
|
|
60
61
|
if (det === 0) {
|
|
61
62
|
throw new Error("Scaling matrix is degenerate.");
|
|
62
63
|
}
|