@mat3ra/made 2024.3.22-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.
Files changed (176) hide show
  1. package/.babelrc +10 -0
  2. package/.eslintrc.json +11 -0
  3. package/.mocharc.json +5 -0
  4. package/.prettierignore +1 -0
  5. package/.prettierrc +6 -0
  6. package/LICENSE.md +15 -0
  7. package/README.md +167 -0
  8. package/dist/abstract/array_with_ids.d.ts +43 -0
  9. package/dist/abstract/array_with_ids.js +88 -0
  10. package/dist/abstract/scalar_with_id.d.ts +25 -0
  11. package/dist/abstract/scalar_with_id.js +44 -0
  12. package/dist/basis/basis.d.ts +269 -0
  13. package/dist/basis/basis.js +499 -0
  14. package/dist/basis/constrained_basis.d.ts +56 -0
  15. package/dist/basis/constrained_basis.js +90 -0
  16. package/dist/basis/types.d.ts +1 -0
  17. package/dist/basis/types.js +2 -0
  18. package/dist/cell/cell.d.ts +45 -0
  19. package/dist/cell/cell.js +88 -0
  20. package/dist/cell/conventional_cell.d.ts +22 -0
  21. package/dist/cell/conventional_cell.js +83 -0
  22. package/dist/cell/primitive_cell.d.ts +9 -0
  23. package/dist/cell/primitive_cell.js +166 -0
  24. package/dist/constants.d.ts +2 -0
  25. package/dist/constants.js +25 -0
  26. package/dist/constraints/constraints.d.ts +45 -0
  27. package/dist/constraints/constraints.js +49 -0
  28. package/dist/lattice/lattice.d.ts +104 -0
  29. package/dist/lattice/lattice.js +208 -0
  30. package/dist/lattice/lattice_bravais.d.ts +59 -0
  31. package/dist/lattice/lattice_bravais.js +120 -0
  32. package/dist/lattice/lattice_vectors.d.ts +46 -0
  33. package/dist/lattice/lattice_vectors.js +98 -0
  34. package/dist/lattice/reciprocal/lattice_reciprocal.d.ts +75 -0
  35. package/dist/lattice/reciprocal/lattice_reciprocal.js +148 -0
  36. package/dist/lattice/reciprocal/paths.d.ts +24 -0
  37. package/dist/lattice/reciprocal/paths.js +136 -0
  38. package/dist/lattice/reciprocal/symmetry_points.d.ts +8 -0
  39. package/dist/lattice/reciprocal/symmetry_points.js +866 -0
  40. package/dist/lattice/types.d.ts +49 -0
  41. package/dist/lattice/types.js +127 -0
  42. package/dist/lattice/unit_cell.d.ts +30 -0
  43. package/dist/lattice/unit_cell.js +31 -0
  44. package/dist/made.d.ts +40 -0
  45. package/dist/made.js +39 -0
  46. package/dist/material.d.ts +1562 -0
  47. package/dist/material.js +317 -0
  48. package/dist/math.d.ts +395 -0
  49. package/dist/math.js +7 -0
  50. package/dist/parsers/cif.d.ts +10 -0
  51. package/dist/parsers/cif.js +21 -0
  52. package/dist/parsers/errors.d.ts +5 -0
  53. package/dist/parsers/errors.js +11 -0
  54. package/dist/parsers/espresso.d.ts +10 -0
  55. package/dist/parsers/espresso.js +24 -0
  56. package/dist/parsers/native_format_parsers.d.ts +26 -0
  57. package/dist/parsers/native_format_parsers.js +52 -0
  58. package/dist/parsers/parsers.d.ts +13 -0
  59. package/dist/parsers/parsers.js +17 -0
  60. package/dist/parsers/poscar.d.ts +31 -0
  61. package/dist/parsers/poscar.js +180 -0
  62. package/dist/parsers/xyz.d.ts +62 -0
  63. package/dist/parsers/xyz.js +167 -0
  64. package/dist/parsers/xyz_combinatorial_basis.d.ts +64 -0
  65. package/dist/parsers/xyz_combinatorial_basis.js +241 -0
  66. package/dist/tools/basis.d.ts +22 -0
  67. package/dist/tools/basis.js +100 -0
  68. package/dist/tools/cell.d.ts +9 -0
  69. package/dist/tools/cell.js +39 -0
  70. package/dist/tools/index.d.ts +11 -0
  71. package/dist/tools/index.js +15 -0
  72. package/dist/tools/material.d.ts +25 -0
  73. package/dist/tools/material.js +54 -0
  74. package/dist/tools/supercell.d.ts +22 -0
  75. package/dist/tools/supercell.js +62 -0
  76. package/dist/tools/surface.d.ts +10 -0
  77. package/dist/tools/surface.js +147 -0
  78. package/dist/types.d.ts +3 -0
  79. package/dist/types.js +2 -0
  80. package/package.json +89 -0
  81. package/pyproject.toml +77 -0
  82. package/src/js/abstract/array_with_ids.ts +100 -0
  83. package/src/js/abstract/scalar_with_id.ts +53 -0
  84. package/src/js/basis/basis.ts +607 -0
  85. package/src/js/basis/constrained_basis.ts +107 -0
  86. package/src/js/basis/types.ts +1 -0
  87. package/src/js/cell/cell.ts +109 -0
  88. package/src/js/cell/conventional_cell.ts +89 -0
  89. package/src/js/cell/primitive_cell.ts +189 -0
  90. package/src/js/constants.js +4 -0
  91. package/src/js/constraints/constraints.ts +63 -0
  92. package/src/js/lattice/lattice.ts +229 -0
  93. package/src/js/lattice/lattice_bravais.ts +170 -0
  94. package/src/js/lattice/lattice_vectors.ts +126 -0
  95. package/src/js/lattice/reciprocal/lattice_reciprocal.js +155 -0
  96. package/src/js/lattice/reciprocal/paths.js +134 -0
  97. package/src/js/lattice/reciprocal/symmetry_points.ts +886 -0
  98. package/src/js/lattice/types.ts +142 -0
  99. package/src/js/lattice/unit_cell.ts +66 -0
  100. package/src/js/made.js +36 -0
  101. package/src/js/material.ts +398 -0
  102. package/src/js/math.js +6 -0
  103. package/src/js/parsers/cif.js +22 -0
  104. package/src/js/parsers/errors.js +7 -0
  105. package/src/js/parsers/espresso.ts +30 -0
  106. package/src/js/parsers/native_format_parsers.js +51 -0
  107. package/src/js/parsers/parsers.js +13 -0
  108. package/src/js/parsers/poscar.ts +201 -0
  109. package/src/js/parsers/xyz.ts +216 -0
  110. package/src/js/parsers/xyz_combinatorial_basis.js +243 -0
  111. package/src/js/tools/basis.js +116 -0
  112. package/src/js/tools/cell.js +36 -0
  113. package/src/js/tools/index.js +11 -0
  114. package/src/js/tools/material.js +60 -0
  115. package/src/js/tools/supercell.ts +80 -0
  116. package/src/js/tools/surface.js +176 -0
  117. package/src/js/types.ts +4 -0
  118. package/src/py/__init__.py +0 -0
  119. package/src/py/mat3ra/__init__.py +0 -0
  120. package/src/py/mat3ra/made/__init__.py +5 -0
  121. package/tests/.gitattributes +1 -0
  122. package/tests/fixtures/AsGe-basis.json +3 -0
  123. package/tests/fixtures/C2H4-translated.json +3 -0
  124. package/tests/fixtures/C2H4.json +3 -0
  125. package/tests/fixtures/FeLiSi-basis.json +3 -0
  126. package/tests/fixtures/FeO.json +3 -0
  127. package/tests/fixtures/Ge2-basis.json +3 -0
  128. package/tests/fixtures/Graphene.json +3 -0
  129. package/tests/fixtures/Graphene.poscar +3 -0
  130. package/tests/fixtures/H2+H-final.json +3 -0
  131. package/tests/fixtures/H2+H-image.json +3 -0
  132. package/tests/fixtures/H2+H-initial.json +3 -0
  133. package/tests/fixtures/H2O.poscar +3 -0
  134. package/tests/fixtures/LiFeSi-basis.json +3 -0
  135. package/tests/fixtures/Na.json +3 -0
  136. package/tests/fixtures/Na4Cl4-cartesian.json +3 -0
  137. package/tests/fixtures/Na4Cl4.json +3 -0
  138. package/tests/fixtures/Na4Cl4.poscar +3 -0
  139. package/tests/fixtures/Ni-hex.json +3 -0
  140. package/tests/fixtures/Ni-hex.poscar +3 -0
  141. package/tests/fixtures/OSi-basis.json +3 -0
  142. package/tests/fixtures/Si-hex.json +3 -0
  143. package/tests/fixtures/Si-hex.poscar +3 -0
  144. package/tests/fixtures/Si-pwscf.in +3 -0
  145. package/tests/fixtures/Si-slab.json +3 -0
  146. package/tests/fixtures/Si-supercell.json +3 -0
  147. package/tests/fixtures/Si.json +3 -0
  148. package/tests/fixtures/Si2-basis-repeated.json +3 -0
  149. package/tests/fixtures/Si2-basis.json +3 -0
  150. package/tests/fixtures/Zr1H23Zr1H1.json +3 -0
  151. package/tests/fixtures/Zr1H23Zr1H1.poscar +3 -0
  152. package/tests/fixtures/atomic-constraints.json +3 -0
  153. package/tests/js/basis/basis.js +221 -0
  154. package/tests/js/cell/cell.js +21 -0
  155. package/tests/js/cell/primitive_cell.js +17 -0
  156. package/tests/js/constraints/constraints.js +27 -0
  157. package/tests/js/enums.js +40 -0
  158. package/tests/js/lattice/lattice.js +31 -0
  159. package/tests/js/lattice/lattice_bravais.js +17 -0
  160. package/tests/js/lattice/lattice_reciprocal.js +99 -0
  161. package/tests/js/lattice/lattice_vectors.js +10 -0
  162. package/tests/js/material.test.js +11 -0
  163. package/tests/js/parsers/espresso.js +12 -0
  164. package/tests/js/parsers/native_formats.js +30 -0
  165. package/tests/js/parsers/poscar.js +21 -0
  166. package/tests/js/parsers/xyz.js +25 -0
  167. package/tests/js/parsers/xyz_combinatorial_basis.js +153 -0
  168. package/tests/js/setup.js +6 -0
  169. package/tests/js/tools/basis.js +18 -0
  170. package/tests/js/tools/supercell.js +23 -0
  171. package/tests/js/tools/surface.js +12 -0
  172. package/tests/js/utils.js +17 -0
  173. package/tests/py/__init__.py +0 -0
  174. package/tests/py/unit/__init__.py +0 -0
  175. package/tests/py/unit/test_sample.py +10 -0
  176. package/tsconfig.json +3 -0
@@ -0,0 +1,88 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.Cell = void 0;
7
+ const math_1 = require("@exabyte-io/code.js/dist/math");
8
+ const constants_1 = __importDefault(require("../constants"));
9
+ const MATRIX = math_1.math.matrix;
10
+ const MULT = math_1.math.multiply;
11
+ const INV = math_1.math.inv;
12
+ // @ts-ignore
13
+ const MATRIX_MULT = (...args) => MULT(...args.map((x) => MATRIX(x))).toArray();
14
+ /*
15
+ * Cell represents a unit cell in geometrical form: 3x3 matrix where rows are cell vectors.
16
+ * Example: [[1, 0, 0], [0, 1, 0], [0, 0, 1]].
17
+ */
18
+ class Cell {
19
+ /**
20
+ * Create a cell.
21
+ * @param nestedArray {Number[][]} is an array of cell vectors in cartesian Angstrom units.
22
+ */
23
+ constructor(nestedArray) {
24
+ this.tolerance = 1;
25
+ [this.vector1, this.vector2, this.vector3] = nestedArray;
26
+ }
27
+ /**
28
+ * Get cell vectors as (a nested) array.
29
+ * @example [[1, 0, 0], [0, 1, 0], [0, 0, 1]]
30
+ */
31
+ get vectorsAsArray() {
32
+ return [
33
+ this.vector1,
34
+ this.vector2,
35
+ this.vector3,
36
+ // assert that no near-zero artifacts are present (ie. 1.6 x 10^-16) before attempting inversion
37
+ // @param tolerance {Number} Maximum tolerance to small numbers, used to avoid artifacts on matrix inversion
38
+ ].map((v) => v.map((c) => (math_1.math.abs(c) < constants_1.default.tolerance.lengthAngstrom ? 0 : c)));
39
+ }
40
+ clone() {
41
+ return new this.constructor(this.vectorsAsArray);
42
+ }
43
+ cloneAndScaleByMatrix(matrix) {
44
+ const newCell = this.clone();
45
+ newCell.scaleByMatrix(matrix);
46
+ return newCell;
47
+ }
48
+ /**
49
+ * Convert a point (in crystal coordinates) to cartesian.
50
+ */
51
+ convertPointToCartesian(point) {
52
+ return MULT(point, this.vectorsAsArray);
53
+ }
54
+ /**
55
+ * Convert a point (in cartesian coordinates) to crystal (fractional).
56
+ */
57
+ convertPointToFractional(point) {
58
+ return MULT(point, INV(this.vectorsAsArray));
59
+ }
60
+ /**
61
+ * Check whether a point is inside the cell.
62
+ * @param point - the point to conduct the check for.
63
+ * @param tolerance - numerical tolerance.
64
+ */
65
+ isPointInsideCell(point, tolerance = constants_1.default.tolerance.length) {
66
+ return (this.convertPointToFractional(point)
67
+ .map((c) => math_1.math.isBetweenZeroInclusiveAndOne(c, tolerance))
68
+ // @ts-ignore
69
+ .reduce((a, b) => a && b));
70
+ }
71
+ /**
72
+ * Returns the index of the cell vector, most collinear with the testVector.
73
+ * @param testVector
74
+ */
75
+ getMostCollinearVectorIndex(testVector) {
76
+ // @ts-ignore
77
+ const angles = this.vectorsAsArray.map((v) => math_1.math.angleUpTo90(v, testVector));
78
+ return angles.findIndex((el) => el === math_1.math.min(angles));
79
+ }
80
+ /**
81
+ * Scale this cell by right-multiplying it to a matrix (nested array)
82
+ */
83
+ scaleByMatrix(matrix) {
84
+ // @ts-ignore
85
+ [this.vector1, this.vector2, this.vector3] = MATRIX_MULT(matrix, this.vectorsAsArray);
86
+ }
87
+ }
88
+ exports.Cell = Cell;
@@ -0,0 +1,22 @@
1
+ import { LatticeTypeSchema } from "@mat3ra/esse/lib/js/types";
2
+ export declare const PRIMITIVE_TO_CONVENTIONAL_CELL_MULTIPLIERS: {
3
+ CUB: number[][];
4
+ FCC: number[][];
5
+ BCC: number[][];
6
+ TET: number[][];
7
+ BCT: number[][];
8
+ ORC: number[][];
9
+ ORCF: number[][];
10
+ ORCI: number[][];
11
+ ORCC: number[][];
12
+ HEX: number[][];
13
+ RHL: number[][];
14
+ MCL: number[][];
15
+ MCLC: number[][];
16
+ TRI: number[][];
17
+ TRIalt: number[][];
18
+ };
19
+ export declare const PRIMITIVE_TO_CONVENTIONAL_CELL_LATTICE_TYPES: {
20
+ [key in LatticeTypeSchema | "TRIalt"]: LatticeTypeSchema;
21
+ };
22
+ export declare function isConventionalCellSameAsPrimitiveForLatticeType(latticeType: LatticeTypeSchema): boolean;
@@ -0,0 +1,83 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isConventionalCellSameAsPrimitiveForLatticeType = exports.PRIMITIVE_TO_CONVENTIONAL_CELL_LATTICE_TYPES = exports.PRIMITIVE_TO_CONVENTIONAL_CELL_MULTIPLIERS = void 0;
4
+ /**
5
+ * Routines for calculating conventional cell vectors from primitive cell Bravais parameters.
6
+ * Following Setyawan, W., & Curtarolo, S. (2010). doi:10.1016/j.commatsci.2010.05.010
7
+ */
8
+ const unitMatrix = [
9
+ [1, 0, 0],
10
+ [0, 1, 0],
11
+ [0, 0, 1],
12
+ ];
13
+ // (Conventional cellVectors) = (Primitive cellVectors) * (PRIMITIVE_TO_CONVENTIONAL_CELL_MULTIPLIER matrix)
14
+ exports.PRIMITIVE_TO_CONVENTIONAL_CELL_MULTIPLIERS = {
15
+ // PRIMITIVE => CONVENTIONAL
16
+ CUB: unitMatrix,
17
+ FCC: [
18
+ [-1, 1, 1],
19
+ [1, -1, 1],
20
+ [1, 1, -1],
21
+ ],
22
+ BCC: [
23
+ [0, 1, 1],
24
+ [1, 0, 1],
25
+ [1, 1, 0],
26
+ ],
27
+ TET: unitMatrix,
28
+ BCT: [
29
+ [0, 1, 1],
30
+ [1, 0, 1],
31
+ [1, 1, 0],
32
+ ],
33
+ ORC: unitMatrix,
34
+ ORCF: [
35
+ [-1, 1, 1],
36
+ [1, -1, 1],
37
+ [1, 1, -1],
38
+ ],
39
+ ORCI: [
40
+ [0, 1, 1],
41
+ [1, 0, 1],
42
+ [1, 1, 0],
43
+ ],
44
+ ORCC: [
45
+ [1, -1, 0],
46
+ [1, 1, 0],
47
+ [0, 0, 1],
48
+ ],
49
+ HEX: unitMatrix,
50
+ RHL: unitMatrix,
51
+ MCL: unitMatrix,
52
+ MCLC: [
53
+ [1, -1, 0],
54
+ [1, 1, 0],
55
+ [0, 0, 1],
56
+ ],
57
+ TRI: unitMatrix,
58
+ TRIalt: unitMatrix,
59
+ };
60
+ exports.PRIMITIVE_TO_CONVENTIONAL_CELL_LATTICE_TYPES = {
61
+ // PRIMITIVE => CONVENTIONAL
62
+ CUB: "CUB",
63
+ FCC: "CUB",
64
+ BCC: "CUB",
65
+ TET: "TET",
66
+ BCT: "TET",
67
+ ORC: "ORC",
68
+ ORCF: "ORC",
69
+ ORCI: "ORC",
70
+ ORCC: "ORC",
71
+ HEX: "HEX",
72
+ RHL: "RHL",
73
+ MCL: "MCL",
74
+ MCLC: "MCL",
75
+ TRI: "TRI",
76
+ // TODO: Legacy `TRI_alt` type, assert not used and remove
77
+ TRIalt: "TRI",
78
+ };
79
+ function isConventionalCellSameAsPrimitiveForLatticeType(latticeType) {
80
+ const multiplier = exports.PRIMITIVE_TO_CONVENTIONAL_CELL_MULTIPLIERS[latticeType || "TRI"];
81
+ return multiplier === unitMatrix;
82
+ }
83
+ exports.isConventionalCellSameAsPrimitiveForLatticeType = isConventionalCellSameAsPrimitiveForLatticeType;
@@ -0,0 +1,9 @@
1
+ import { LatticeImplicitSchema } from "@mat3ra/esse/lib/js/types";
2
+ import { VectorsAsArray } from "../lattice/types";
3
+ /**
4
+ * Returns lattice vectors for a primitive cell for a lattice.
5
+ * @param lattice - Lattice instance.
6
+ * @param skipRounding - whether to skip rounding the lattice vectors.
7
+ * @return Cell.vectorsAsArray
8
+ */
9
+ export declare function primitiveCell(lattice: LatticeImplicitSchema, skipRounding?: boolean): VectorsAsArray;
@@ -0,0 +1,166 @@
1
+ "use strict";
2
+ var __importDefault = (this && this.__importDefault) || function (mod) {
3
+ return (mod && mod.__esModule) ? mod : { "default": mod };
4
+ };
5
+ Object.defineProperty(exports, "__esModule", { value: true });
6
+ exports.primitiveCell = void 0;
7
+ const math_1 = __importDefault(require("../math"));
8
+ /**
9
+ * Routines for calculating primitive cell vectors from conventional cell Bravais parameters.
10
+ * Following Setyawan, W., & Curtarolo, S. (2010). doi:10.1016/j.commatsci.2010.05.010
11
+ */
12
+ const PRIMITIVE_CELLS = {
13
+ CUB: ({ a }) => {
14
+ return [
15
+ [a, 0, 0],
16
+ [0, a, 0],
17
+ [0, 0, a],
18
+ ];
19
+ },
20
+ FCC: ({ a }) => {
21
+ return [
22
+ [0.0, a / 2, a / 2],
23
+ [a / 2, 0.0, a / 2],
24
+ [a / 2, a / 2, 0.0],
25
+ ];
26
+ },
27
+ BCC: ({ a }) => {
28
+ return [
29
+ [-a / 2, a / 2, a / 2],
30
+ [a / 2, -a / 2, a / 2],
31
+ [a / 2, a / 2, -a / 2],
32
+ ];
33
+ },
34
+ TET: ({ a, c }) => {
35
+ return [
36
+ [a, 0, 0],
37
+ [0, a, 0],
38
+ [0, 0, c],
39
+ ];
40
+ },
41
+ BCT: ({ a, c }) => {
42
+ return [
43
+ [-a / 2, a / 2, c / 2],
44
+ [a / 2, -a / 2, c / 2],
45
+ [a / 2, a / 2, -c / 2],
46
+ ];
47
+ },
48
+ ORC: ({ a, b, c }) => {
49
+ return [
50
+ [a, 0, 0],
51
+ [0, b, 0],
52
+ [0, 0, c],
53
+ ];
54
+ },
55
+ ORCF: ({ a, b, c }) => {
56
+ return [
57
+ [0, b / 2, c / 2],
58
+ [a / 2, 0, c / 2],
59
+ [a / 2, b / 2, 0],
60
+ ];
61
+ },
62
+ ORCI: ({ a, b, c }) => {
63
+ return [
64
+ [-a / 2, b / 2, c / 2],
65
+ [a / 2, -b / 2, c / 2],
66
+ [a / 2, b / 2, -c / 2],
67
+ ];
68
+ },
69
+ ORCC: ({ a, b, c }) => {
70
+ return [
71
+ [a / 2, b / 2, 0],
72
+ [-a / 2, b / 2, 0],
73
+ [0, 0, c],
74
+ ];
75
+ },
76
+ HEX: ({ a, c }) => {
77
+ return [
78
+ [a / 2, (-a * math_1.default.sqrt(3)) / 2, 0],
79
+ [a / 2, (a * math_1.default.sqrt(3)) / 2, 0],
80
+ [0, 0, c],
81
+ ];
82
+ },
83
+ RHL: ({ a, alpha }) => {
84
+ const cosAlpha = math_1.default.cos((alpha / 180) * math_1.default.PI);
85
+ const cosHalfAlpha = math_1.default.sqrt((1 / 2) * (1 + cosAlpha));
86
+ const sinHalfAlpha = math_1.default.sqrt((1 / 2) * (1 - cosAlpha));
87
+ return [
88
+ [a * cosHalfAlpha, -a * sinHalfAlpha, 0.0],
89
+ [a * cosHalfAlpha, a * sinHalfAlpha, 0.0],
90
+ [
91
+ (a * cosAlpha) / cosHalfAlpha,
92
+ 0.0,
93
+ a * math_1.default.sqrt(1 - (cosAlpha * cosAlpha) / (cosHalfAlpha * cosHalfAlpha)),
94
+ ],
95
+ ];
96
+ },
97
+ MCL: ({ a, b, c, alpha }) => {
98
+ const cosAlpha = math_1.default.cos((alpha / 180) * math_1.default.PI);
99
+ return [
100
+ [a, 0, 0],
101
+ [0, b, 0],
102
+ [0, c * cosAlpha, c * math_1.default.sqrt(1 - cosAlpha * cosAlpha)],
103
+ ];
104
+ },
105
+ MCLC: ({ a, b, c, alpha }) => {
106
+ const cosAlpha = math_1.default.cos((alpha / 180) * math_1.default.PI);
107
+ return [
108
+ [a / 2, b / 2, 0],
109
+ [-a / 2, b / 2, 0],
110
+ [0, c * cosAlpha, c * math_1.default.sqrt(1 - cosAlpha * cosAlpha)],
111
+ ];
112
+ },
113
+ // Algorithm from http://pymatgen.org/_modules/pymatgen/core/lattice.html (from_params)
114
+ TRI: ({ a, b, c, alpha, beta, gamma }) => {
115
+ // convert angles to Radians
116
+ // eslint-disable-next-line no-param-reassign
117
+ [alpha, beta, gamma] = [alpha, beta, gamma].map(
118
+ // @ts-ignore
119
+ (x) => math_1.default.unit(x, "degree").to("rad").value);
120
+ const [cosAlpha, cosBeta, cosGamma] = [alpha, beta, gamma].map((x) => math_1.default.cos(x));
121
+ const [sinAlpha, sinBeta] = [alpha, beta].map((x) => math_1.default.sin(x));
122
+ const gammaStar = math_1.default.acos((cosAlpha * cosBeta - cosGamma) / (sinAlpha * sinBeta));
123
+ const cosGammaStar = math_1.default.cos(gammaStar);
124
+ const sinGammaStar = math_1.default.sin(gammaStar);
125
+ return [
126
+ [a * sinBeta, 0.0, a * cosBeta],
127
+ [-b * sinAlpha * cosGammaStar, b * sinAlpha * sinGammaStar, b * cosAlpha],
128
+ [0.0, 0.0, c],
129
+ ];
130
+ },
131
+ // alternative implementation
132
+ TRIalt: ({ a, b, c, alpha, beta, gamma }) => {
133
+ const cosAlpha = math_1.default.cos((alpha / 180) * math_1.default.PI);
134
+ const cosBeta = math_1.default.cos((beta / 180) * math_1.default.PI);
135
+ const cosGamma = math_1.default.cos((gamma / 180) * math_1.default.PI);
136
+ const sinGamma = math_1.default.sqrt(1 - cosGamma * cosGamma);
137
+ return [
138
+ [a, 0.0, 0.0],
139
+ [b * cosGamma, b * sinGamma, 0.0],
140
+ [
141
+ c * cosBeta,
142
+ (c / sinGamma) * (cosAlpha - cosBeta * cosGamma),
143
+ (c / sinGamma) *
144
+ math_1.default.sqrt(sinGamma * sinGamma -
145
+ cosAlpha * cosAlpha -
146
+ cosBeta * cosBeta +
147
+ 2 * cosAlpha * cosBeta * cosGamma),
148
+ ],
149
+ ];
150
+ },
151
+ };
152
+ /**
153
+ * Returns lattice vectors for a primitive cell for a lattice.
154
+ * @param lattice - Lattice instance.
155
+ * @param skipRounding - whether to skip rounding the lattice vectors.
156
+ * @return Cell.vectorsAsArray
157
+ */
158
+ function primitiveCell(lattice, skipRounding = false) {
159
+ const [vectorA, vectorB, vectorC] = PRIMITIVE_CELLS[lattice.type || "TRI"](lattice);
160
+ // set precision and remove JS floating point artifacts
161
+ if (!skipRounding) {
162
+ [vectorA, vectorB, vectorC].map((vec) => vec.map((c) => math_1.default.precise(c)).map(math_1.default.roundToZero));
163
+ }
164
+ return [vectorA, vectorB, vectorC];
165
+ }
166
+ exports.primitiveCell = primitiveCell;
@@ -0,0 +1,2 @@
1
+ export * from "@exabyte-io/code.js/dist/constants";
2
+ export { default } from "@exabyte-io/code.js/dist/constants";
@@ -0,0 +1,25 @@
1
+ "use strict";
2
+ var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
3
+ if (k2 === undefined) k2 = k;
4
+ var desc = Object.getOwnPropertyDescriptor(m, k);
5
+ if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
6
+ desc = { enumerable: true, get: function() { return m[k]; } };
7
+ }
8
+ Object.defineProperty(o, k2, desc);
9
+ }) : (function(o, m, k, k2) {
10
+ if (k2 === undefined) k2 = k;
11
+ o[k2] = m[k];
12
+ }));
13
+ var __exportStar = (this && this.__exportStar) || function(m, exports) {
14
+ for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
15
+ };
16
+ var __importDefault = (this && this.__importDefault) || function (mod) {
17
+ return (mod && mod.__esModule) ? mod : { "default": mod };
18
+ };
19
+ Object.defineProperty(exports, "__esModule", { value: true });
20
+ exports.default = void 0;
21
+ // TODO: adjust the imports and remove the need for re-exporting
22
+ __exportStar(require("@exabyte-io/code.js/dist/constants"), exports);
23
+ // eslint-disable-next-line no-restricted-exports
24
+ var constants_1 = require("@exabyte-io/code.js/dist/constants");
25
+ Object.defineProperty(exports, "default", { enumerable: true, get: function () { return __importDefault(constants_1).default; } });
@@ -0,0 +1,45 @@
1
+ import { ArrayWithIds } from "../abstract/array_with_ids";
2
+ import { ObjectWithIdAndValue } from "../abstract/scalar_with_id";
3
+ export interface ConstraintValue extends Array<boolean> {
4
+ 0: boolean;
5
+ 1: boolean;
6
+ 2: boolean;
7
+ }
8
+ export type Constraint = ObjectWithIdAndValue<ConstraintValue>;
9
+ export declare class AtomicConstraints {
10
+ name: string;
11
+ values: ArrayWithIds<ConstraintValue>;
12
+ static fromArray(array: ConstraintValue[]): AtomicConstraints;
13
+ /**
14
+ * Create atomic constraints.
15
+ * @param {Object} config
16
+ * @param {ArrayWithIds|Array} config.values
17
+ */
18
+ constructor({ values }: {
19
+ values?: ConstraintValue[];
20
+ });
21
+ /**
22
+ * @example As below:
23
+ [
24
+ {
25
+ "id" : 0,
26
+ "value" : [
27
+ 1,
28
+ 1,
29
+ 1
30
+ ]
31
+ }
32
+ ]
33
+ */
34
+ toJSON(): {
35
+ name: string;
36
+ values: ObjectWithIdAndValue<ConstraintValue>[];
37
+ };
38
+ getByIndex(idx: number): ConstraintValue;
39
+ /**
40
+ * Get constraints for an atom with index as string.
41
+ * @param idx - atom index.
42
+ * @param mapFn (OPTIONAL) - a function to be applied to each constraint. By default 0 or 1 is returned.
43
+ */
44
+ getAsStringByIndex(idx: number, mapFn?: (val: boolean) => string): string;
45
+ }
@@ -0,0 +1,49 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.AtomicConstraints = void 0;
4
+ const array_with_ids_1 = require("../abstract/array_with_ids");
5
+ class AtomicConstraints {
6
+ static fromArray(array) {
7
+ return new AtomicConstraints({ values: array });
8
+ }
9
+ /**
10
+ * Create atomic constraints.
11
+ * @param {Object} config
12
+ * @param {ArrayWithIds|Array} config.values
13
+ */
14
+ constructor({ values }) {
15
+ this.name = "atomic_constraints";
16
+ this.values = new array_with_ids_1.ArrayWithIds(values || []);
17
+ }
18
+ /**
19
+ * @example As below:
20
+ [
21
+ {
22
+ "id" : 0,
23
+ "value" : [
24
+ 1,
25
+ 1,
26
+ 1
27
+ ]
28
+ }
29
+ ]
30
+ */
31
+ toJSON() {
32
+ return {
33
+ name: this.name,
34
+ values: this.values.toJSON(),
35
+ };
36
+ }
37
+ getByIndex(idx) {
38
+ return this.values.getArrayElementByIndex(idx) || [];
39
+ }
40
+ /**
41
+ * Get constraints for an atom with index as string.
42
+ * @param idx - atom index.
43
+ * @param mapFn (OPTIONAL) - a function to be applied to each constraint. By default 0 or 1 is returned.
44
+ */
45
+ getAsStringByIndex(idx, mapFn = (val) => (val ? "1" : "0")) {
46
+ return this.getByIndex(idx).map(mapFn).join(" ");
47
+ }
48
+ }
49
+ exports.AtomicConstraints = AtomicConstraints;
@@ -0,0 +1,104 @@
1
+ import { LatticeImplicitSchema, LatticeSchema, LatticeTypeExtendedSchema } from "@mat3ra/esse/lib/js/types";
2
+ import { Cell } from "../cell/cell";
3
+ import { FromVectorsProps, LatticeBravais } from "./lattice_bravais";
4
+ import { BravaisConfigProps, LatticeVectors } from "./lattice_vectors";
5
+ import { UnitCell } from "./unit_cell";
6
+ /**
7
+ * Scaling factor used to calculate the new lattice size for non-periodic systems.
8
+ * The scaling factor ensures that a non-periodic structure will have have a lattice greater than the structures size.
9
+ */
10
+ export declare const nonPeriodicLatticeScalingFactor = 2;
11
+ export declare class Lattice extends LatticeBravais implements LatticeSchema {
12
+ vectors: LatticeVectors;
13
+ /**
14
+ * Create a Lattice class from a config object.
15
+ * @param {Object} config - Config object. See LatticeVectors.fromBravais.
16
+ */
17
+ constructor(config?: Partial<LatticeImplicitSchema>);
18
+ /**
19
+ * Create a Lattice class from a list of vectors.
20
+ * @param {Object} config - Config object. See LatticeBravais.fromVectors.
21
+ */
22
+ static fromVectors(config: FromVectorsProps): Lattice;
23
+ /**
24
+ * Serialize class instance to JSON.
25
+ * @example As below:
26
+ {
27
+ "a" : 3.867,
28
+ "b" : 3.867,
29
+ "c" : 3.867,
30
+ "alpha" : 60,
31
+ "beta" : 60,
32
+ "gamma" : 60,
33
+ "units" : {
34
+ "length" : "angstrom",
35
+ "angle" : "degree"
36
+ },
37
+ "type" : "FCC",
38
+ "vectors" : {
39
+ "a" : [
40
+ 3.34892,
41
+ 0,
42
+ 1.9335
43
+ ],
44
+ "b" : [
45
+ 1.116307,
46
+ 3.157392,
47
+ 1.9335
48
+ ],
49
+ "c" : [
50
+ 0,
51
+ 0,
52
+ 3.867
53
+ ],
54
+ "alat" : 1,
55
+ "units" : "angstrom"
56
+ }
57
+ }
58
+ */
59
+ toJSON(skipRounding?: boolean): LatticeSchema;
60
+ clone(extraContext: BravaisConfigProps): Lattice;
61
+ /**
62
+ * Get lattice vectors as a nested array
63
+ */
64
+ get vectorArrays(): [import("@mat3ra/esse/lib/js/types").ArrayOf3NumberElementsSchema, import("@mat3ra/esse/lib/js/types").ArrayOf3NumberElementsSchema, import("@mat3ra/esse/lib/js/types").ArrayOf3NumberElementsSchema];
65
+ get Cell(): Cell;
66
+ /**
67
+ * Get a short label for the type of the lattice, eg. "MCLC".
68
+ */
69
+ get typeLabel(): string;
70
+ /**
71
+ * Get a short label for the extended type of the lattice, eg. "MCLC-5".
72
+ */
73
+ get typeExtended(): LatticeTypeExtendedSchema;
74
+ /**
75
+ * Calculate the volume of the lattice cell.
76
+ */
77
+ get volume(): number;
78
+ static getDefaultPrimitiveLatticeConfigByType(latticeConfig: LatticeImplicitSchema): {
79
+ a: number;
80
+ b: number;
81
+ c: number;
82
+ alpha: number;
83
+ beta: number;
84
+ gamma: number;
85
+ units: {
86
+ length?: "bohr" | "angstrom" | undefined;
87
+ angle?: "degree" | "radian" | undefined;
88
+ };
89
+ type: "CUB" | "BCC" | "FCC" | "TET" | "MCL" | "ORC" | "ORCC" | "ORCF" | "ORCI" | "HEX" | "BCT" | "TRI" | "MCLC" | "RHL";
90
+ } & {
91
+ a: number;
92
+ b: number;
93
+ c: number;
94
+ alpha: number;
95
+ beta: number;
96
+ gamma: number;
97
+ };
98
+ get unitCell(): UnitCell;
99
+ /**
100
+ * Returns a string further used for the calculation of an unique hash.
101
+ * @param isScaled - Whether to scale the vectors by the length of the first vector initially.
102
+ */
103
+ getHashString(isScaled?: boolean): string;
104
+ }