@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,241 @@
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 __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
14
+ Object.defineProperty(o, "default", { enumerable: true, value: v });
15
+ }) : function(o, v) {
16
+ o["default"] = v;
17
+ });
18
+ var __importStar = (this && this.__importStar) || function (mod) {
19
+ if (mod && mod.__esModule) return mod;
20
+ var result = {};
21
+ if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
22
+ __setModuleDefault(result, mod);
23
+ return result;
24
+ };
25
+ var __importDefault = (this && this.__importDefault) || function (mod) {
26
+ return (mod && mod.__esModule) ? mod : { "default": mod };
27
+ };
28
+ Object.defineProperty(exports, "__esModule", { value: true });
29
+ exports.CombinatorialBasis = exports.WrongBasisFormat = void 0;
30
+ /* eslint-disable max-classes-per-file */
31
+ const underscore_1 = __importDefault(require("underscore"));
32
+ const s = __importStar(require("underscore.string"));
33
+ const basis_1 = require("../basis/basis");
34
+ const math_1 = __importDefault(require("../math"));
35
+ /**
36
+ * @summary Combinatorial XYZ basis class and related. Create and get all information about basis and elements in it.
37
+ * Constructor accepts string in extended XYZ format. Extended XYZ format is as follows:
38
+ *
39
+ * 1. Regular XYZ
40
+ * ```
41
+ * Si 0.0 0.0 0.0
42
+ * Li 0.5 0.5 0.5
43
+ * ```
44
+ * 2. Permutation (slash-separated)
45
+ * ```
46
+ * Si/Ge/As 0.0 0.0 0.0
47
+ * Si/Ge 0.5 0.5 0.0
48
+ * ```
49
+ * 3. Combination (comma-separated)
50
+ * ```
51
+ * Si,Ge,As 0.0 0.0 0.0
52
+ * Si,Ge 0.5 0.5 0.0
53
+ * ```
54
+ * More at: https://exabyte.atlassian.net/wiki/display/PD/Combinatorial+materials+set
55
+ */
56
+ /**
57
+ * Regular expression for basis line.
58
+ * @type {RegExp}
59
+ */
60
+ // eslint-disable-next-line max-len
61
+ const LINE_REGEX = /^([A-Z][a-z]?\/?,?)+\s+(-?\d+\.?\d*|\.\d+)\s+(-?\d+\.?\d*|\.\d+)\s+(-?\d+\.?\d*|\.\d+)\s*$/gi;
62
+ // vacancy characters will be used to create vacancies on basis generation
63
+ const VACANCY_CHARACTER = "VAC";
64
+ const COMBINATION_DELIMITER = ",";
65
+ const PERMUTATION_DELIMITER = "/";
66
+ /**
67
+ * Basis validation error codes.
68
+ * @type {{MIXING_IN_SINGLE_LINE: number, MIXING_IN_MULTI_LINES: number, REGEX_NOT_PASSED: number}}
69
+ */
70
+ const ERROR_CODES = {
71
+ MIXING_IN_SINGLE_LINE: 1,
72
+ MIXING_IN_MULTI_LINES: 2,
73
+ REGEX_NOT_PASSED: 3,
74
+ };
75
+ class WrongBasisFormat extends Error {
76
+ constructor(xyz, message, type) {
77
+ super(message, type);
78
+ this.xyz = xyz;
79
+ }
80
+ }
81
+ exports.WrongBasisFormat = WrongBasisFormat;
82
+ class CombinatorialBasis {
83
+ /**
84
+ * Creates Combinatorial basis
85
+ * @param eXYZ
86
+ */
87
+ constructor(eXYZ) {
88
+ this._xyz = eXYZ;
89
+ this._lines = s
90
+ .lines(eXYZ)
91
+ .map((x) => x.trim())
92
+ .filter((x) => x !== "")
93
+ .map(this._parseBasisLine);
94
+ this._hasPermutationLine = this._lines.reduce((mem, a) => {
95
+ return mem || a.isPermutation;
96
+ }, false);
97
+ this._hasCombinationLine = this._lines.reduce((mem, a) => {
98
+ return mem || a.isCombination;
99
+ }, false);
100
+ if (this._hasPermutationLine && this._hasCombinationLine) {
101
+ throw new WrongBasisFormat(this._xyz, "Basis contains mixed permutation and combination.", ERROR_CODES.MIXING_IN_MULTI_LINES);
102
+ }
103
+ }
104
+ /**
105
+ * Parses combinatorial basis line and returns result as Object. Throws exception if line is not valid:
106
+ * - does not meet RegExp
107
+ * - mixes permutation and combination
108
+ * @param str {String} Combinatorial basis' line
109
+ * @param index {Number} order of the
110
+ * @return {{displayName: string, isCombination: boolean, isPermutation: boolean, elements: Array, coordinates: *[]}}
111
+ * @private
112
+ */
113
+ _parseBasisLine(str, index) {
114
+ if (!str.match(LINE_REGEX)) {
115
+ throw new WrongBasisFormat(this._xyz, `Line #${index + 1}: "${str}" contains errors. ` +
116
+ 'Allowed formats: "Si 0 0 0", "Si/Li 0.5 0.5 0.5", "Si,Ge 0.7 0.7 0.8"', ERROR_CODES.REGEX_NOT_PASSED);
117
+ }
118
+ const containsPermutation = str.indexOf(PERMUTATION_DELIMITER) > -1;
119
+ const containsCombination = str.indexOf(COMBINATION_DELIMITER) > -1;
120
+ if (containsCombination && containsPermutation) {
121
+ throw new WrongBasisFormat(this._xyz, `Line #${index} contains mixed permutation and combination.`, ERROR_CODES.MIXING_IN_SINGLE_LINE);
122
+ }
123
+ let elements = [];
124
+ const words = s
125
+ .words(str)
126
+ .map((x) => x.trim())
127
+ .filter((x) => x != null);
128
+ if (containsCombination) {
129
+ elements = words[0].split(COMBINATION_DELIMITER).map((x) => x.trim());
130
+ }
131
+ else if (containsPermutation) {
132
+ elements = words[0].split(PERMUTATION_DELIMITER).map((x) => x.trim());
133
+ }
134
+ else {
135
+ elements = [words[0]];
136
+ }
137
+ const coordinates = [parseFloat(words[1]), parseFloat(words[2]), parseFloat(words[3])];
138
+ return {
139
+ displayName: `ELEMENT_${index}`,
140
+ isCombination: containsCombination,
141
+ isPermutation: containsPermutation,
142
+ elements,
143
+ coordinates,
144
+ };
145
+ }
146
+ /**
147
+ * Returns array of ALL unique elements used in basis.
148
+ * @return {String[]}
149
+ */
150
+ get uniqueElements() {
151
+ return underscore_1.default.chain(this._lines)
152
+ .map((line) => line.elements)
153
+ .flatten()
154
+ .unique()
155
+ .value()
156
+ .sort();
157
+ }
158
+ static toBasisConfig(array, units = "crystal", cell = basis_1.Basis.defaultCell) {
159
+ return {
160
+ elements: underscore_1.default.pluck(array, "element"),
161
+ coordinates: underscore_1.default.pluck(array, "coordinates"),
162
+ units,
163
+ cell,
164
+ };
165
+ }
166
+ /**
167
+ * Returns array of regular bases extracted from current combinatorial basis.
168
+ * @return {Basis[]|Object[]}
169
+ */
170
+ get allBasisConfigs() {
171
+ let result = [];
172
+ if (this._hasPermutationLine) {
173
+ result = this._permutation();
174
+ }
175
+ else if (this._hasCombinationLine) {
176
+ result = this._combination();
177
+ }
178
+ else {
179
+ const items = [];
180
+ this._lines.forEach((line) => {
181
+ items.push({
182
+ element: line.elements[0],
183
+ coordinates: line.coordinates,
184
+ });
185
+ });
186
+ result = [items];
187
+ }
188
+ return result.map((x) => CombinatorialBasis.toBasisConfig(x));
189
+ }
190
+ /**
191
+ * Returns array of regular bases extracted from current combinatorial basis with combinations.
192
+ * @private
193
+ */
194
+ _combination() {
195
+ const dimensions = [];
196
+ this._lines.forEach((line) => {
197
+ const itemsSet = [];
198
+ line.elements.forEach((element) => {
199
+ // omit vacancy characters
200
+ itemsSet.push({
201
+ element,
202
+ coordinates: line.coordinates,
203
+ });
204
+ });
205
+ dimensions.push(itemsSet);
206
+ });
207
+ const basisSet = math_1.default.cartesianProduct.apply(null, dimensions);
208
+ return basisSet.map((basis) => basis.filter((entry) => entry.element !== VACANCY_CHARACTER));
209
+ }
210
+ /**
211
+ * Returns array of regular bases extracted from current combinatorial basis with permutations.
212
+ * @return {Basis[]}
213
+ * @private
214
+ */
215
+ _permutation() {
216
+ const maxLen = Math.max(...this._lines.map((x) => x.elements.length));
217
+ const bases = [];
218
+ for (let i = 0; i < maxLen; i++) {
219
+ const items = [];
220
+ this._lines.forEach((line) => {
221
+ const element = line.elements.length <= i ? underscore_1.default.last(line.elements) : line.elements[i];
222
+ if (element !== VACANCY_CHARACTER) {
223
+ items.push({
224
+ element,
225
+ coordinates: line.coordinates,
226
+ });
227
+ }
228
+ });
229
+ bases.push(items);
230
+ }
231
+ return bases;
232
+ }
233
+ /**
234
+ * Returns true if current combinatorial basis contains more than one regular basis.
235
+ * @return {Boolean}
236
+ */
237
+ isCombinatorial() {
238
+ return this._hasCombinationLine || this._hasPermutationLine;
239
+ }
240
+ }
241
+ exports.CombinatorialBasis = CombinatorialBasis;
@@ -0,0 +1,22 @@
1
+ declare namespace _default {
2
+ export { repeat };
3
+ export { interpolate };
4
+ }
5
+ export default _default;
6
+ /**
7
+ * Returns a repeated basis of a crystal.
8
+ * @param basis {Basis} Original basis.
9
+ * @param repetitions{Number[]} Repetition vector `[x, y, z]`, in each spatial dimension.
10
+ * @return {Basis} New Basis.
11
+ */
12
+ declare function repeat(basis: Basis, repetitions: number[]): Basis;
13
+ /**
14
+ * Returns a set of Bases for a crystal interpolated from initial to final crystal.
15
+ * Can be used to generate atomic configurations along a chemical reaction path, for example.
16
+ * @param initialBasis {Basis} Original initialBasis.
17
+ * @param finalBasis {Basis} Final initialBasis.
18
+ * @param numberOfSteps{Number} Number of intermediate steps.
19
+ * @return {Basis[]} List of all bases.
20
+ */
21
+ declare function interpolate(initialBasis: Basis, finalBasis: Basis, numberOfSteps?: number): Basis[];
22
+ import { Basis } from "../basis/basis";
@@ -0,0 +1,100 @@
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
+ const underscore_1 = __importDefault(require("underscore"));
7
+ // eslint-disable-next-line no-unused-vars
8
+ const basis_1 = require("../basis/basis");
9
+ const math_1 = __importDefault(require("../math"));
10
+ const ADD = math_1.default.add;
11
+ const MULT = math_1.default.multiply;
12
+ /**
13
+ * Returns a repeated basis of a crystal.
14
+ * @param basis {Basis} Original basis.
15
+ * @param repetitions{Number[]} Repetition vector `[x, y, z]`, in each spatial dimension.
16
+ * @return {Basis} New Basis.
17
+ */
18
+ function repeat(basis, repetitions) {
19
+ let i, j, k;
20
+ let shiftI = 0;
21
+ let shiftJ = 0;
22
+ let shiftK = 0;
23
+ // clone original basis and assert it is in cartesian coordinates
24
+ const newBasis = basis.clone();
25
+ const basisCloneInCrystalCoordinates = basis.clone();
26
+ newBasis.toCrystal();
27
+ basisCloneInCrystalCoordinates.toCrystal();
28
+ for (i = 1; i <= repetitions[0]; i += 1) {
29
+ for (j = 1; j <= repetitions[1]; j += 1) {
30
+ for (k = 1; k <= repetitions[2]; k += 1) {
31
+ // for each atom in original basis add one with a repetition
32
+ // eslint-disable-next-line no-loop-func
33
+ basisCloneInCrystalCoordinates.elements.forEach((element, index) => {
34
+ const coord = basisCloneInCrystalCoordinates.getCoordinateByIndex(index);
35
+ // only add atoms if shifts are non-zero
36
+ if (shiftI || shiftJ || shiftK) {
37
+ newBasis.addAtom({
38
+ element,
39
+ coordinate: [coord[0] + shiftI, coord[1] + shiftJ, coord[2] + shiftK],
40
+ });
41
+ }
42
+ });
43
+ shiftK += 1;
44
+ }
45
+ shiftK = 0;
46
+ shiftJ += 1;
47
+ }
48
+ shiftJ = 0;
49
+ shiftI += 1;
50
+ }
51
+ if (basis.isInCartesianUnits)
52
+ newBasis.toCartesian();
53
+ return newBasis;
54
+ }
55
+ /**
56
+ * Calculates linear function `y = kx + b` for vectors. Isolated for modularity.
57
+ * @param initialCoordinates {Array} - b.
58
+ * @param delta {Array} - x.
59
+ * @param normalizedStepIndex {Number} - k.
60
+ * @return {Basis[]} List of all bases.
61
+ */
62
+ function _linearInterpolation(initialCoordinates, delta, normalizedStepIndex) {
63
+ return ADD(initialCoordinates, MULT(delta, normalizedStepIndex));
64
+ }
65
+ /**
66
+ * Returns a set of Bases for a crystal interpolated from initial to final crystal.
67
+ * Can be used to generate atomic configurations along a chemical reaction path, for example.
68
+ * @param initialBasis {Basis} Original initialBasis.
69
+ * @param finalBasis {Basis} Final initialBasis.
70
+ * @param numberOfSteps{Number} Number of intermediate steps.
71
+ * @return {Basis[]} List of all bases.
72
+ */
73
+ function interpolate(initialBasis, finalBasis, numberOfSteps = 1) {
74
+ // check that initial and final basis have the same cell
75
+ if (!initialBasis.hasEquivalentCellTo(finalBasis))
76
+ throw new Error("basis.interpolate: Basis cells are not equal");
77
+ // clone original initialBasis and assert it is in cartesian coordinates
78
+ const initialBasisCopy = initialBasis.clone();
79
+ const finalBasisCopy = finalBasis.clone();
80
+ initialBasisCopy.toCrystal();
81
+ finalBasisCopy.toCrystal();
82
+ const initialCoordinates = underscore_1.default.flatten(initialBasisCopy.coordinatesAsArray);
83
+ const finalCoordinates = underscore_1.default.flatten(finalBasisCopy.coordinatesAsArray);
84
+ const delta = ADD(finalCoordinates, MULT(initialCoordinates, -1));
85
+ const resultingListOfBases = [];
86
+ for (let i = 1; i <= numberOfSteps; i++) {
87
+ const normalizedStepIndex = i / (numberOfSteps + 1);
88
+ const intermediateCoordinates = _linearInterpolation(initialCoordinates, delta, normalizedStepIndex);
89
+ const vectorSize = 3;
90
+ const intermediateCoordinatesAsNestedArray = underscore_1.default.toArray(underscore_1.default.groupBy(intermediateCoordinates, (a, b) => Math.floor(b / vectorSize)));
91
+ const intermediateBasis = initialBasis.clone();
92
+ intermediateBasis.coordinates = intermediateCoordinatesAsNestedArray;
93
+ resultingListOfBases.push(intermediateBasis);
94
+ }
95
+ return resultingListOfBases;
96
+ }
97
+ exports.default = {
98
+ repeat,
99
+ interpolate,
100
+ };
@@ -0,0 +1,9 @@
1
+ declare namespace _default {
2
+ export { latticePointsInSupercell };
3
+ }
4
+ export default _default;
5
+ /**
6
+ * Returns the list of points on the original lattice contained in the supercell in fractional coordinates.
7
+ * Source: https://pymatgen.org/_modules/pymatgen/util/coord.html
8
+ */
9
+ declare function latticePointsInSupercell(supercellMatrix: any): import("../basis/types").Coordinate[];
@@ -0,0 +1,39 @@
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
+ const cell_1 = require("../cell/cell");
7
+ const math_1 = __importDefault(require("../math"));
8
+ /**
9
+ * Returns the list of points on the original lattice contained in the supercell in fractional coordinates.
10
+ * Source: https://pymatgen.org/_modules/pymatgen/util/coord.html
11
+ */
12
+ function latticePointsInSupercell(supercellMatrix) {
13
+ const supercell = new cell_1.Cell(supercellMatrix);
14
+ const diagonals = [
15
+ [0, 0, 0],
16
+ [0, 0, 1],
17
+ [0, 1, 0],
18
+ [0, 1, 1],
19
+ [1, 0, 0],
20
+ [1, 0, 1],
21
+ [1, 1, 0],
22
+ [1, 1, 1],
23
+ ];
24
+ const d_points = diagonals.map((p) => supercell.convertPointToCartesian(p));
25
+ const mins = [0, 1, 2].map((i) => math_1.default.min(...d_points.map((p) => p[i])));
26
+ const maxes = [0, 1, 2].map((i) => math_1.default.max(...d_points.map((p) => p[i])) + 1);
27
+ const points = [];
28
+ for (let i = mins[0]; i <= maxes[0]; i++) {
29
+ for (let j = mins[1]; j <= maxes[1]; j++) {
30
+ for (let k = mins[2]; k <= maxes[2]; k++) {
31
+ points.push(supercell.convertPointToFractional([i, j, k]));
32
+ }
33
+ }
34
+ }
35
+ return points;
36
+ }
37
+ exports.default = {
38
+ latticePointsInSupercell,
39
+ };
@@ -0,0 +1,11 @@
1
+ declare namespace _default {
2
+ export { SurfaceTools as surface };
3
+ export { SupercellTools as supercell };
4
+ export { MaterialTools as material };
5
+ export { BasisTools as basis };
6
+ }
7
+ export default _default;
8
+ import SurfaceTools from "./surface";
9
+ import SupercellTools from "./supercell";
10
+ import MaterialTools from "./material";
11
+ import BasisTools from "./basis";
@@ -0,0 +1,15 @@
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
+ const basis_1 = __importDefault(require("./basis"));
7
+ const material_1 = __importDefault(require("./material"));
8
+ const supercell_1 = __importDefault(require("./supercell"));
9
+ const surface_1 = __importDefault(require("./surface"));
10
+ exports.default = {
11
+ surface: surface_1.default,
12
+ supercell: supercell_1.default,
13
+ material: material_1.default,
14
+ basis: basis_1.default,
15
+ };
@@ -0,0 +1,25 @@
1
+ declare namespace _default {
2
+ export { scaleOneLatticeVector };
3
+ export { scaleLatticeToMakeNonPeriodic };
4
+ export { getBasisConfigTranslatedToCenter };
5
+ }
6
+ export default _default;
7
+ /**
8
+ * Scales one lattice vector for the given material
9
+ * @param material {Material} The material acted upon.
10
+ * @param key {String} Lattice vector key.
11
+ * @param factor {Number} Float scaling factor.
12
+ */
13
+ declare function scaleOneLatticeVector(material: Material, key?: string, factor?: number): void;
14
+ /**
15
+ * Updates the size of a materials lattice using the minimumLatticeSize function.
16
+ * The new size of the material is calculated based on the materials basis.
17
+ * @param material {Material}
18
+ */
19
+ declare function scaleLatticeToMakeNonPeriodic(material: Material): void;
20
+ /**
21
+ * Updates the basis of a material by translating the coordinates
22
+ * so that the center of the material and lattice are aligned.
23
+ * @param material {Material}
24
+ * */
25
+ declare function getBasisConfigTranslatedToCenter(material: Material): void;
@@ -0,0 +1,54 @@
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
+ const mathjs_1 = __importDefault(require("mathjs"));
7
+ const constants_1 = require("../constants");
8
+ const lattice_1 = require("../lattice/lattice");
9
+ /**
10
+ * Scales one lattice vector for the given material
11
+ * @param material {Material} The material acted upon.
12
+ * @param key {String} Lattice vector key.
13
+ * @param factor {Number} Float scaling factor.
14
+ */
15
+ function scaleOneLatticeVector(material, key = "a", factor = 1.0) {
16
+ material.toCartesian();
17
+ const { lattice } = material;
18
+ lattice[key] *= factor;
19
+ material.lattice = lattice;
20
+ material.toCrystal();
21
+ }
22
+ /**
23
+ * Updates the size of a materials lattice using the minimumLatticeSize function.
24
+ * The new size of the material is calculated based on the materials basis.
25
+ * @param material {Material}
26
+ */
27
+ function scaleLatticeToMakeNonPeriodic(material) {
28
+ material.lattice = new lattice_1.Lattice({
29
+ a: material.Basis.getMinimumLatticeSize(),
30
+ type: "CUB",
31
+ });
32
+ }
33
+ /**
34
+ * Updates the basis of a material by translating the coordinates
35
+ * so that the center of the material and lattice are aligned.
36
+ * @param material {Material}
37
+ * */
38
+ function getBasisConfigTranslatedToCenter(material) {
39
+ const originalUnits = material.Basis.units;
40
+ material.toCartesian();
41
+ const updatedBasis = material.Basis;
42
+ const centerOfCoordinates = updatedBasis.centerOfCoordinatesPoint;
43
+ const centerOfLattice = mathjs_1.default.multiply(0.5, material.Lattice.vectorArrays.reduce((a, b) => mathjs_1.default.add(a, b)));
44
+ const translationVector = mathjs_1.default.subtract(centerOfLattice, centerOfCoordinates);
45
+ updatedBasis.translateByVector(translationVector);
46
+ material.setBasis(updatedBasis.toJSON());
47
+ if (originalUnits !== constants_1.ATOMIC_COORD_UNITS.cartesian)
48
+ material.toCrystal();
49
+ }
50
+ exports.default = {
51
+ scaleOneLatticeVector,
52
+ scaleLatticeToMakeNonPeriodic,
53
+ getBasisConfigTranslatedToCenter,
54
+ };
@@ -0,0 +1,22 @@
1
+ import { Basis } from "../basis/basis";
2
+ import { Cell } from "../cell/cell";
3
+ import { Material } from "../material";
4
+ /**
5
+ * @summary Generates new basis for a supercell. For each site from basis generates shifts that are within supercell.
6
+ */
7
+ declare function generateNewBasisWithinSupercell(basis: Basis, cell: Cell, supercell: Cell, supercellMatrix: number[][]): Basis;
8
+ /**
9
+ * @summary Generates supercell config for the specified material.
10
+ * @param material
11
+ * @param supercellMatrix {Number[][]}
12
+ */
13
+ declare function generateConfig(material: Material, supercellMatrix: number[][]): {
14
+ name: string;
15
+ basis: import("../basis/basis").BasisSchema;
16
+ lattice: import("@mat3ra/esse/lib/js/types").LatticeImplicitSchema;
17
+ };
18
+ declare const _default: {
19
+ generateConfig: typeof generateConfig;
20
+ generateNewBasisWithinSupercell: typeof generateNewBasisWithinSupercell;
21
+ };
22
+ export default _default;
@@ -0,0 +1,62 @@
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
+ const lattice_bravais_1 = require("../lattice/lattice_bravais");
7
+ const math_1 = __importDefault(require("../math"));
8
+ const cell_1 = __importDefault(require("./cell"));
9
+ const ADD = math_1.default.add;
10
+ /**
11
+ * @summary Generates new basis for a supercell. For each site from basis generates shifts that are within supercell.
12
+ */
13
+ function generateNewBasisWithinSupercell(basis, cell, supercell, supercellMatrix) {
14
+ const oldBasis = basis.clone();
15
+ const newBasis = basis.clone({ isEmpty: true });
16
+ oldBasis.toCrystal();
17
+ newBasis.toCrystal();
18
+ oldBasis.elements.forEach((element) => {
19
+ const coordinate = oldBasis.getCoordinateByIndex(element.id);
20
+ const cartesianCoordinate = cell.convertPointToCartesian(coordinate);
21
+ const shifts = cell_1.default.latticePointsInSupercell(supercellMatrix);
22
+ shifts.forEach((comb) => {
23
+ // "combination" is effectively a point in fractional coordinates here, hence the below
24
+ const newPoint = ADD(cartesianCoordinate, supercell.convertPointToCartesian(comb));
25
+ if (supercell.isPointInsideCell(newPoint)) {
26
+ newBasis.addAtom({
27
+ element: element.value,
28
+ coordinate: supercell.convertPointToFractional(newPoint),
29
+ });
30
+ }
31
+ });
32
+ });
33
+ return newBasis;
34
+ }
35
+ /**
36
+ * @summary Generates supercell config for the specified material.
37
+ * @param material
38
+ * @param supercellMatrix {Number[][]}
39
+ */
40
+ function generateConfig(material, supercellMatrix) {
41
+ const det = math_1.default.det(supercellMatrix);
42
+ if (det === 0) {
43
+ throw new Error("Scaling matrix is degenerate.");
44
+ }
45
+ const cell = material.Lattice.Cell;
46
+ const supercell = cell.cloneAndScaleByMatrix(supercellMatrix);
47
+ const newBasis = generateNewBasisWithinSupercell(material.Basis, cell, supercell, supercellMatrix);
48
+ const newLattice = lattice_bravais_1.LatticeBravais.fromVectors({
49
+ a: supercell.vector1,
50
+ b: supercell.vector2,
51
+ c: supercell.vector3,
52
+ });
53
+ return {
54
+ name: `${material.name} - supercell ${JSON.stringify(supercellMatrix)}`,
55
+ basis: newBasis.toJSON(),
56
+ lattice: newLattice.toJSON(),
57
+ };
58
+ }
59
+ exports.default = {
60
+ generateConfig,
61
+ generateNewBasisWithinSupercell,
62
+ };
@@ -0,0 +1,10 @@
1
+ declare namespace _default {
2
+ export { generateConfig };
3
+ }
4
+ export default _default;
5
+ declare function generateConfig(material: any, millerIndices: any, numberOfLayers?: number, vx?: number, vy?: number): {
6
+ name: string;
7
+ basis: import("../basis/basis").BasisSchema;
8
+ lattice: import("@mat3ra/esse/lib/js/types").LatticeImplicitSchema;
9
+ outOfPlaneAxisIndex: any;
10
+ };