@mat3ra/made 2026.5.21-2 → 2026.6.11-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 (70) hide show
  1. package/constants.json +13 -0
  2. package/dist/js/basis/basis.d.ts +7 -4
  3. package/dist/js/basis/basis.js +37 -23
  4. package/dist/js/basis/coordinates.js +2 -5
  5. package/dist/js/cell/primitive_cell.js +17 -20
  6. package/dist/js/constants/molecule.d.ts +16 -0
  7. package/dist/js/constants/molecule.js +19 -0
  8. package/dist/js/lattice/lattice.d.ts +1 -1
  9. package/dist/js/lattice/lattice.js +27 -27
  10. package/dist/js/lattice/reciprocal/lattice_reciprocal.d.ts +5 -8
  11. package/dist/js/lattice/reciprocal/lattice_reciprocal.js +17 -20
  12. package/dist/js/made.d.ts +5 -463
  13. package/dist/js/made.js +7 -5
  14. package/dist/js/material.d.ts +165 -9
  15. package/dist/js/material.js +355 -8
  16. package/dist/js/parsers/parsers.d.ts +0 -1
  17. package/dist/js/parsers/poscar.d.ts +0 -1
  18. package/dist/js/parsers/poscar.js +8 -6
  19. package/dist/js/parsers/xyz_combinatorial_basis.js +2 -5
  20. package/dist/js/tools/basis.js +3 -6
  21. package/dist/js/tools/cell.js +3 -6
  22. package/dist/js/tools/supercell.js +3 -3
  23. package/dist/js/tools/surface.js +13 -12
  24. package/package.json +6 -5
  25. package/src/js/basis/basis.ts +39 -15
  26. package/src/js/basis/coordinates.ts +1 -2
  27. package/src/js/cell/primitive_cell.ts +1 -2
  28. package/src/js/constants/molecule.ts +18 -0
  29. package/src/js/lattice/lattice.ts +6 -2
  30. package/src/js/lattice/reciprocal/lattice_reciprocal.ts +11 -17
  31. package/src/js/made.ts +12 -7
  32. package/src/js/material.ts +446 -20
  33. package/src/js/parsers/poscar.ts +7 -5
  34. package/src/js/parsers/xyz_combinatorial_basis.ts +1 -1
  35. package/src/js/tools/basis.ts +1 -1
  36. package/src/js/tools/cell.ts +1 -1
  37. package/src/js/tools/supercell.ts +1 -1
  38. package/src/js/tools/surface.ts +2 -1
  39. package/src/py/mat3ra/made/constants.py +11 -0
  40. package/src/py/mat3ra/made/tools/convert/__init__.py +18 -1
  41. package/src/py/mat3ra/made/tools/convert/utils.py +33 -6
  42. package/src/py/mat3ra/made/tools/operations/core/unary.py +2 -2
  43. package/tests/js/basis/basis.ts +1 -1
  44. package/tests/js/parsers/poscar.ts +27 -0
  45. package/tests/py/unit/test_tools_calculate.py +2 -1
  46. package/tests/py/unit/test_tools_convert.py +36 -4
  47. package/dist/js/abstract/array_with_ids.d.ts +0 -43
  48. package/dist/js/abstract/array_with_ids.js +0 -88
  49. package/dist/js/abstract/scalar_with_id.d.ts +0 -25
  50. package/dist/js/abstract/scalar_with_id.js +0 -44
  51. package/dist/js/basis/types.d.ts +0 -1
  52. package/dist/js/basis/types.js +0 -2
  53. package/dist/js/lattice/lattice_bravais.d.ts +0 -59
  54. package/dist/js/lattice/lattice_bravais.js +0 -118
  55. package/dist/js/lattice/lattice_vectors.d.ts +0 -46
  56. package/dist/js/lattice/lattice_vectors.js +0 -98
  57. package/dist/js/lattice/types.d.ts +0 -49
  58. package/dist/js/lattice/types.js +0 -127
  59. package/dist/js/materialMixin.d.ts +0 -171
  60. package/dist/js/materialMixin.js +0 -363
  61. package/dist/js/math.d.ts +0 -459
  62. package/dist/js/math.js +0 -7
  63. package/dist/js/types/index.d.ts +0 -1
  64. package/dist/js/types/index.js +0 -17
  65. package/dist/js/types/material.d.ts +0 -18
  66. package/dist/js/types/material.js +0 -2
  67. package/dist/js/types.d.ts +0 -1
  68. package/dist/js/types.js +0 -2
  69. package/src/js/materialMixin.ts +0 -453
  70. package/src/js/math.ts +0 -6
package/constants.json ADDED
@@ -0,0 +1,13 @@
1
+ {
2
+ "molecule": {
3
+ "nonPeriodicMinimumLatticeSize": 3.0,
4
+ "diatomicLatticePaddingFactor": 3.0,
5
+ "molecularLatticePaddingFactor": 2.0
6
+ },
7
+ "precision": {
8
+ "coordinatesCrystal": 9,
9
+ "coordinatesCartesian": 6,
10
+ "latticeLengths": 6,
11
+ "latticeAngles": 4
12
+ }
13
+ }
@@ -147,11 +147,12 @@ export declare class Basis extends InMemoryEntity implements BasisSchema {
147
147
  */
148
148
  hasEquivalentCellTo(anotherBasisClsInstance: Basis): boolean;
149
149
  /**
150
- * @summary function returns the minimum basis lattice size for a structure.
151
- * The lattice size is based on the atomic radius of an element if the basis contains a single atom.
152
- * The lattice size is based on the maximum pairwise distance across a structure if the basis contains > 2 atoms.
150
+ * @summary Returns the minimum cubic lattice size for a non-periodic structure.
151
+ * Single-atom structures use the element atomic radius floored at defaultMinimumLatticeSize.
152
+ * Multi-atom structures scale the maximum pairwise distance by 3 when W=min/max pairwise distance
153
+ * is ~1 (diatomic), otherwise by 2.
153
154
  */
154
- getMinimumLatticeSize(latticeScalingFactor?: number): number;
155
+ getMinimumLatticeSize(defaultMinimumLatticeSize?: number): number;
155
156
  /**
156
157
  * @summary function returns an array of overlapping atoms within specified tolerance.
157
158
  */
@@ -172,6 +173,8 @@ export declare class Basis extends InMemoryEntity implements BasisSchema {
172
173
  *
173
174
  */
174
175
  get maxPairwiseDistance(): number;
176
+ get minPairwiseDistance(): number;
177
+ getPairwiseDistanceExtremum(extremum: "max" | "min"): number;
175
178
  /**
176
179
  * @summary Function takes basis coordinates and transposes them so that the values for each dimension of the
177
180
  * the basis are in their own nested array.
@@ -1,17 +1,14 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Basis = void 0;
7
4
  // @ts-ignore
8
5
  const periodic_table_js_1 = require("@exabyte-io/periodic-table.js");
9
6
  const entity_1 = require("@mat3ra/code/dist/js/entity");
7
+ const math_1 = require("@mat3ra/code/dist/js/math");
10
8
  const lodash_1 = require("lodash");
11
9
  const cell_1 = require("../cell/cell");
12
10
  const constants_1 = require("../constants");
13
11
  const lattice_1 = require("../lattice/lattice");
14
- const math_1 = __importDefault(require("../math"));
15
12
  const coordinates_1 = require("./coordinates");
16
13
  const elements_1 = require("./elements");
17
14
  const labels_1 = require("./labels");
@@ -166,7 +163,7 @@ class Basis extends entity_1.InMemoryEntity {
166
163
  }
167
164
  toStandardRepresentation() {
168
165
  this.toCrystal();
169
- this._coordinates.mapArrayInPlace((point) => point.map((x) => math_1.default.mod(x)));
166
+ this._coordinates.mapArrayInPlace((point) => point.map((x) => math_1.math.mod(x)));
170
167
  }
171
168
  /** A representation where all coordinates are within 0 and 1 in crystal units */
172
169
  get standardRepresentation() {
@@ -240,7 +237,7 @@ class Basis extends entity_1.InMemoryEntity {
240
237
  get formula() {
241
238
  const counts = this.uniqueElementCountsSortedByElectronegativity;
242
239
  const countsValues = (0, lodash_1.values)(counts);
243
- const gcd = countsValues.length > 1 ? math_1.default.gcd(...countsValues) : countsValues[0];
240
+ const gcd = countsValues.length > 1 ? math_1.math.gcd(...countsValues) : countsValues[0];
244
241
  return (0, lodash_1.toPairs)(counts)
245
242
  .map(([element, count]) => element + (count / gcd === 1 ? "" : count / gcd))
246
243
  .reduce((acc, part) => acc + part, "");
@@ -293,7 +290,7 @@ class Basis extends entity_1.InMemoryEntity {
293
290
  const element = entry[0];
294
291
  const coordinate = entry[1];
295
292
  const atomicLabel = entry[2];
296
- const toleratedCoordinate = coordinate.map((x) => math_1.default.round(x, constants_1.HASH_TOLERANCE));
293
+ const toleratedCoordinate = coordinate.map((x) => math_1.math.round(x, constants_1.HASH_TOLERANCE));
297
294
  return `${element}${atomicLabel} ${toleratedCoordinate.join()}`;
298
295
  });
299
296
  return `${standardRep.sort().join(";")};`;
@@ -364,24 +361,30 @@ class Basis extends entity_1.InMemoryEntity {
364
361
  hasEquivalentCellTo(anotherBasisClsInstance) {
365
362
  return !this.cell.vectorArrays
366
363
  .map((vector, idx) => {
367
- return math_1.default.vEqualWithTolerance(vector, anotherBasisClsInstance.cell.vectorArrays[idx]);
364
+ return math_1.math.vEqualWithTolerance(vector, anotherBasisClsInstance.cell.vectorArrays[idx]);
368
365
  })
369
366
  .some((x) => !x);
370
367
  }
371
368
  /**
372
- * @summary function returns the minimum basis lattice size for a structure.
373
- * The lattice size is based on the atomic radius of an element if the basis contains a single atom.
374
- * The lattice size is based on the maximum pairwise distance across a structure if the basis contains > 2 atoms.
369
+ * @summary Returns the minimum cubic lattice size for a non-periodic structure.
370
+ * Single-atom structures use the element atomic radius floored at defaultMinimumLatticeSize.
371
+ * Multi-atom structures scale the maximum pairwise distance by 3 when W=min/max pairwise distance
372
+ * is ~1 (diatomic), otherwise by 2.
375
373
  */
376
- getMinimumLatticeSize(latticeScalingFactor = lattice_1.nonPeriodicLatticeScalingFactor) {
377
- let latticeSizeAdditiveContribution = 0;
374
+ getMinimumLatticeSize(defaultMinimumLatticeSize = lattice_1.defaultNonPeriodicMinimumLatticeSize) {
378
375
  if (this._elements.values.length === 1) {
379
376
  const elementSymbol = this._elements.getElementValueByIndex(0);
380
- latticeSizeAdditiveContribution = (0, periodic_table_js_1.getElementAtomicRadius)(elementSymbol);
377
+ const atomicRadius = (0, periodic_table_js_1.getElementAtomicRadius)(elementSymbol);
378
+ return Math.max(defaultMinimumLatticeSize, atomicRadius);
381
379
  }
382
- const moleculeLatticeSize = this.maxPairwiseDistance * latticeScalingFactor;
383
- const latticeSize = latticeSizeAdditiveContribution + moleculeLatticeSize;
384
- return latticeSize;
380
+ const maxDistance = this.maxPairwiseDistance;
381
+ const minDistance = this.minPairwiseDistance;
382
+ const widthRatio = maxDistance > 0 ? minDistance / maxDistance : 1;
383
+ const latticeScalingFactor = math_1.math.almostEqual(widthRatio, 1)
384
+ ? lattice_1.diatomicLatticePaddingFactor
385
+ : lattice_1.molecularLatticePaddingFactor;
386
+ const moleculeLatticeSize = maxDistance * latticeScalingFactor;
387
+ return Math.max(defaultMinimumLatticeSize, moleculeLatticeSize);
385
388
  }
386
389
  /**
387
390
  * @summary function returns an array of overlapping atoms within specified tolerance.
@@ -401,7 +404,7 @@ class Basis extends entity_1.InMemoryEntity {
401
404
  const tolerance = overlapCoefficient *
402
405
  ((0, periodic_table_js_1.getElementAtomicRadius)(el1) + (0, periodic_table_js_1.getElementAtomicRadius)(el2)); // in angstroms
403
406
  // @ts-ignore
404
- const distance = math_1.default.vDist(entry1.value, entry2.value);
407
+ const distance = math_1.math.vDist(entry1.value, entry2.value);
405
408
  if (distance < tolerance) {
406
409
  overlaps.push({
407
410
  id1: i,
@@ -431,22 +434,33 @@ class Basis extends entity_1.InMemoryEntity {
431
434
  *
432
435
  */
433
436
  get maxPairwiseDistance() {
437
+ return this.getPairwiseDistanceExtremum("max");
438
+ }
439
+ get minPairwiseDistance() {
440
+ return this.getPairwiseDistanceExtremum("min");
441
+ }
442
+ getPairwiseDistanceExtremum(extremum) {
434
443
  const originalUnits = this.units;
435
444
  this.toCartesian();
436
- let maxDistance = 0;
445
+ let resultDistance = extremum === "max" ? 0 : Infinity;
437
446
  if (this._elements.values.length >= 2) {
438
447
  for (let i = 0; i < this._elements.values.length; i++) {
439
448
  for (let j = i + 1; j < this._elements.values.length; j++) {
440
- const distance = math_1.default.vDist(this._coordinates.getElementValueByIndex(i), this._coordinates.getElementValueByIndex(j));
441
- if (distance && distance > maxDistance) {
442
- maxDistance = distance;
449
+ const distance = math_1.math.vDist(this._coordinates.getElementValueByIndex(i), this._coordinates.getElementValueByIndex(j));
450
+ if (!distance)
451
+ continue;
452
+ if (extremum === "max" && distance > resultDistance) {
453
+ resultDistance = distance;
454
+ }
455
+ if (extremum === "min" && distance < resultDistance) {
456
+ resultDistance = distance;
443
457
  }
444
458
  }
445
459
  }
446
460
  }
447
461
  if (originalUnits !== constants_1.ATOMIC_COORD_UNITS.cartesian)
448
462
  this.toCrystal();
449
- return maxDistance;
463
+ return extremum === "min" && resultDistance === Infinity ? 0 : resultDistance;
450
464
  }
451
465
  /**
452
466
  * @summary Function takes basis coordinates and transposes them so that the values for each dimension of the
@@ -1,12 +1,9 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.Coordinates = exports.Coordinate = void 0;
7
4
  const code_1 = require("@mat3ra/code");
5
+ const math_1 = require("@mat3ra/code/dist/js/math");
8
6
  const underscore_string_1 = require("underscore.string");
9
- const math_1 = __importDefault(require("../math"));
10
7
  class Coordinate extends code_1.RoundedValueWithId {
11
8
  constructor({ value, id }) {
12
9
  super(id, value);
@@ -61,7 +58,7 @@ class Coordinates extends code_1.RoundedArrayWithIds {
61
58
  });
62
59
  }
63
60
  getCenterPoint() {
64
- const transposed = math_1.default.transpose(this.values);
61
+ const transposed = math_1.math.transpose(this.values);
65
62
  const center = [0, 0, 0];
66
63
  for (let i = 0; i < 3; i++) {
67
64
  const axisCoords = transposed[i];
@@ -1,10 +1,7 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
2
  Object.defineProperty(exports, "__esModule", { value: true });
6
3
  exports.getPrimitiveLatticeVectorsFromConfig = void 0;
7
- const math_1 = __importDefault(require("../math"));
4
+ const math_1 = require("@mat3ra/code/dist/js/math");
8
5
  /**
9
6
  * Routines for calculating primitive cell vectors from conventional cell Bravais parameters.
10
7
  * Following Setyawan, W., & Curtarolo, S. (2010). doi:10.1016/j.commatsci.2010.05.010
@@ -75,39 +72,39 @@ const PRIMITIVE_CELLS = {
75
72
  },
76
73
  HEX: ({ a, c }) => {
77
74
  return [
78
- [a / 2, (-a * math_1.default.sqrt(3)) / 2, 0],
79
- [a / 2, (a * math_1.default.sqrt(3)) / 2, 0],
75
+ [a / 2, (-a * math_1.math.sqrt(3)) / 2, 0],
76
+ [a / 2, (a * math_1.math.sqrt(3)) / 2, 0],
80
77
  [0, 0, c],
81
78
  ];
82
79
  },
83
80
  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));
81
+ const cosAlpha = math_1.math.cos((alpha / 180) * math_1.math.PI);
82
+ const cosHalfAlpha = math_1.math.sqrt((1 / 2) * (1 + cosAlpha));
83
+ const sinHalfAlpha = math_1.math.sqrt((1 / 2) * (1 - cosAlpha));
87
84
  return [
88
85
  [a * cosHalfAlpha, -a * sinHalfAlpha, 0.0],
89
86
  [a * cosHalfAlpha, a * sinHalfAlpha, 0.0],
90
87
  [
91
88
  (a * cosAlpha) / cosHalfAlpha,
92
89
  0.0,
93
- a * math_1.default.sqrt(1 - (cosAlpha * cosAlpha) / (cosHalfAlpha * cosHalfAlpha)),
90
+ a * math_1.math.sqrt(1 - (cosAlpha * cosAlpha) / (cosHalfAlpha * cosHalfAlpha)),
94
91
  ],
95
92
  ];
96
93
  },
97
94
  MCL: ({ a, b, c, alpha }) => {
98
- const cosAlpha = math_1.default.cos((alpha / 180) * math_1.default.PI);
95
+ const cosAlpha = math_1.math.cos((alpha / 180) * math_1.math.PI);
99
96
  return [
100
97
  [a, 0, 0],
101
98
  [0, b, 0],
102
- [0, c * cosAlpha, c * math_1.default.sqrt(1 - cosAlpha * cosAlpha)],
99
+ [0, c * cosAlpha, c * math_1.math.sqrt(1 - cosAlpha * cosAlpha)],
103
100
  ];
104
101
  },
105
102
  MCLC: ({ a, b, c, alpha }) => {
106
- const cosAlpha = math_1.default.cos((alpha / 180) * math_1.default.PI);
103
+ const cosAlpha = math_1.math.cos((alpha / 180) * math_1.math.PI);
107
104
  return [
108
105
  [a / 2, b / 2, 0],
109
106
  [-a / 2, b / 2, 0],
110
- [0, c * cosAlpha, c * math_1.default.sqrt(1 - cosAlpha * cosAlpha)],
107
+ [0, c * cosAlpha, c * math_1.math.sqrt(1 - cosAlpha * cosAlpha)],
111
108
  ];
112
109
  },
113
110
  // Algorithm from http://pymatgen.org/_modules/pymatgen/core/lattice.html (from_params)
@@ -116,9 +113,9 @@ const PRIMITIVE_CELLS = {
116
113
  // eslint-disable-next-line no-param-reassign
117
114
  [alpha, beta, gamma] = [alpha, beta, gamma].map(
118
115
  // @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));
116
+ (x) => math_1.math.unit(x, "degree").to("rad").value);
117
+ const [cosAlpha, cosBeta, cosGamma] = [alpha, beta, gamma].map((x) => math_1.math.cos(x));
118
+ const [sinAlpha, sinBeta] = [alpha, beta].map((x) => math_1.math.sin(x));
122
119
  let acosArg = (cosAlpha * cosBeta - cosGamma) / (sinAlpha * sinBeta);
123
120
  if (acosArg < -1) {
124
121
  acosArg = -1;
@@ -126,9 +123,9 @@ const PRIMITIVE_CELLS = {
126
123
  else if (acosArg > 1) {
127
124
  acosArg = 1;
128
125
  }
129
- const gammaStar = math_1.default.acos(acosArg);
130
- const cosGammaStar = math_1.default.cos(gammaStar);
131
- const sinGammaStar = math_1.default.sin(gammaStar);
126
+ const gammaStar = math_1.math.acos(acosArg);
127
+ const cosGammaStar = math_1.math.cos(gammaStar);
128
+ const sinGammaStar = math_1.math.sin(gammaStar);
132
129
  return [
133
130
  [a * sinBeta, 0.0, a * cosBeta],
134
131
  [-b * sinAlpha * cosGammaStar, b * sinAlpha * sinGammaStar, b * cosAlpha],
@@ -0,0 +1,16 @@
1
+ /**
2
+ * Constants for molecule handling and precision.
3
+ * Source of truth: /constants.json at repository root
4
+ *
5
+ * These values are duplicated here for TypeScript compilation.
6
+ * When updating these, also update constants.json.
7
+ */
8
+ export declare const defaultNonPeriodicMinimumLatticeSize = 3;
9
+ export declare const diatomicLatticePaddingFactor = 3;
10
+ export declare const molecularLatticePaddingFactor = 2;
11
+ export declare const PRECISION_MAP: {
12
+ coordinatesCrystal: number;
13
+ coordinatesCartesian: number;
14
+ latticeLengths: number;
15
+ latticeAngles: number;
16
+ };
@@ -0,0 +1,19 @@
1
+ "use strict";
2
+ /**
3
+ * Constants for molecule handling and precision.
4
+ * Source of truth: /constants.json at repository root
5
+ *
6
+ * These values are duplicated here for TypeScript compilation.
7
+ * When updating these, also update constants.json.
8
+ */
9
+ Object.defineProperty(exports, "__esModule", { value: true });
10
+ exports.PRECISION_MAP = exports.molecularLatticePaddingFactor = exports.diatomicLatticePaddingFactor = exports.defaultNonPeriodicMinimumLatticeSize = void 0;
11
+ exports.defaultNonPeriodicMinimumLatticeSize = 3.0;
12
+ exports.diatomicLatticePaddingFactor = 3.0;
13
+ exports.molecularLatticePaddingFactor = 2.0;
14
+ exports.PRECISION_MAP = {
15
+ coordinatesCrystal: 9,
16
+ coordinatesCartesian: 6,
17
+ latticeLengths: 6,
18
+ latticeAngles: 4,
19
+ };
@@ -6,7 +6,7 @@ import { UnitCell } from "./unit_cell";
6
6
  * Scaling factor used to calculate the new lattice size for non-periodic systems.
7
7
  * The scaling factor ensures that a non-periodic structure will have have a lattice greater than the structures size.
8
8
  */
9
- export declare const nonPeriodicLatticeScalingFactor = 2;
9
+ export { defaultNonPeriodicMinimumLatticeSize, diatomicLatticePaddingFactor, molecularLatticePaddingFactor, } from "../constants/molecule";
10
10
  export declare class LatticeVectors extends Cell implements LatticeVectorsSchema {
11
11
  }
12
12
  export type { LatticeVectorsSchema };
@@ -22,24 +22,24 @@ var __importStar = (this && this.__importStar) || function (mod) {
22
22
  __setModuleDefault(result, mod);
23
23
  return result;
24
24
  };
25
- var __importDefault = (this && this.__importDefault) || function (mod) {
26
- return (mod && mod.__esModule) ? mod : { "default": mod };
27
- };
28
25
  Object.defineProperty(exports, "__esModule", { value: true });
29
- exports.Lattice = exports.LatticeVectors = exports.nonPeriodicLatticeScalingFactor = void 0;
26
+ exports.Lattice = exports.LatticeVectors = exports.molecularLatticePaddingFactor = exports.diatomicLatticePaddingFactor = exports.defaultNonPeriodicMinimumLatticeSize = void 0;
30
27
  const constants_1 = require("@mat3ra/code/dist/js/constants");
31
28
  const entity_1 = require("@mat3ra/code/dist/js/entity");
29
+ const math_1 = require("@mat3ra/code/dist/js/math");
32
30
  const lodash = __importStar(require("lodash"));
33
31
  const cell_1 = require("../cell/cell");
34
32
  const primitive_cell_1 = require("../cell/primitive_cell");
35
- const math_1 = __importDefault(require("../math"));
36
33
  const lattice_types_1 = require("./lattice_types");
37
34
  const unit_cell_1 = require("./unit_cell");
38
35
  /**
39
36
  * Scaling factor used to calculate the new lattice size for non-periodic systems.
40
37
  * The scaling factor ensures that a non-periodic structure will have have a lattice greater than the structures size.
41
38
  */
42
- exports.nonPeriodicLatticeScalingFactor = 2.0;
39
+ var molecule_1 = require("../constants/molecule");
40
+ Object.defineProperty(exports, "defaultNonPeriodicMinimumLatticeSize", { enumerable: true, get: function () { return molecule_1.defaultNonPeriodicMinimumLatticeSize; } });
41
+ Object.defineProperty(exports, "diatomicLatticePaddingFactor", { enumerable: true, get: function () { return molecule_1.diatomicLatticePaddingFactor; } });
42
+ Object.defineProperty(exports, "molecularLatticePaddingFactor", { enumerable: true, get: function () { return molecule_1.molecularLatticePaddingFactor; } });
43
43
  class LatticeVectors extends cell_1.Cell {
44
44
  }
45
45
  exports.LatticeVectors = LatticeVectors;
@@ -69,17 +69,17 @@ class Lattice extends entity_1.InMemoryEntity {
69
69
  const { a } = this;
70
70
  const { b } = this;
71
71
  const { c } = this;
72
- const alphaRad = math_1.default.unit(this.alpha, "deg").toNumber("rad");
73
- const betaRad = math_1.default.unit(this.beta, "deg").toNumber("rad");
74
- const gammaRad = math_1.default.unit(this.gamma, "deg").toNumber("rad");
75
- const cosAlpha = math_1.default.cos(alphaRad);
76
- const cosBeta = math_1.default.cos(betaRad);
77
- const cosGamma = math_1.default.cos(gammaRad);
78
- const sinAlpha = math_1.default.sin(alphaRad);
79
- const sinBeta = math_1.default.sin(betaRad);
80
- const gammaStar = math_1.default.acos((cosAlpha * cosBeta - cosGamma) / (sinAlpha * sinBeta));
81
- const cosGammaStar = math_1.default.cos(gammaStar);
82
- const sinGammaStar = math_1.default.sin(gammaStar);
72
+ const alphaRad = math_1.math.unit(this.alpha, "deg").toNumber("rad");
73
+ const betaRad = math_1.math.unit(this.beta, "deg").toNumber("rad");
74
+ const gammaRad = math_1.math.unit(this.gamma, "deg").toNumber("rad");
75
+ const cosAlpha = math_1.math.cos(alphaRad);
76
+ const cosBeta = math_1.math.cos(betaRad);
77
+ const cosGamma = math_1.math.cos(gammaRad);
78
+ const sinAlpha = math_1.math.sin(alphaRad);
79
+ const sinBeta = math_1.math.sin(betaRad);
80
+ const gammaStar = math_1.math.acos((cosAlpha * cosBeta - cosGamma) / (sinAlpha * sinBeta));
81
+ const cosGammaStar = math_1.math.cos(gammaStar);
82
+ const sinGammaStar = math_1.math.sin(gammaStar);
83
83
  const vectorA = [a * sinBeta, 0.0, a * cosBeta];
84
84
  const vectorB = [
85
85
  -b * sinAlpha * cosGammaStar,
@@ -94,12 +94,12 @@ class Lattice extends entity_1.InMemoryEntity {
94
94
  }
95
95
  static fromVectorsArray(vectors, units = Lattice.defaultConfig.units, type = "TRI") {
96
96
  const [aVec, bVec, cVec] = vectors;
97
- const a = math_1.default.vlen(aVec);
98
- const b = math_1.default.vlen(bVec);
99
- const c = math_1.default.vlen(cVec);
100
- const alpha = math_1.default.angle(bVec, cVec, "deg");
101
- const beta = math_1.default.angle(aVec, cVec, "deg");
102
- const gamma = math_1.default.angle(aVec, bVec, "deg");
97
+ const a = math_1.math.vlen(aVec);
98
+ const b = math_1.math.vlen(bVec);
99
+ const c = math_1.math.vlen(cVec);
100
+ const alpha = math_1.math.angle(bVec, cVec, "deg");
101
+ const beta = math_1.math.angle(aVec, cVec, "deg");
102
+ const gamma = math_1.math.angle(aVec, bVec, "deg");
103
103
  return new Lattice({
104
104
  a,
105
105
  b,
@@ -144,7 +144,7 @@ class Lattice extends entity_1.InMemoryEntity {
144
144
  */
145
145
  get typeExtended() {
146
146
  const { a, b, c, alpha, beta, gamma, type } = this;
147
- const cosAlpha = math_1.default.cos((alpha / 180) * math_1.default.PI);
147
+ const cosAlpha = math_1.math.cos((alpha / 180) * math_1.math.PI);
148
148
  switch (type) {
149
149
  case "BCT":
150
150
  return c < a ? "BCT-1" : "BCT-2";
@@ -179,14 +179,14 @@ class Lattice extends entity_1.InMemoryEntity {
179
179
  * Calculate the volume of the lattice cell.
180
180
  */
181
181
  get volume() {
182
- return math_1.default.abs(math_1.default.det(this.vectorArrays));
182
+ return math_1.math.abs(math_1.math.det(this.vectorArrays));
183
183
  }
184
184
  /*
185
185
  * Returns a "default" primitive lattice by type, with lattice parameters scaled by the length of "a",
186
186
  * @param latticeConfig {Object} LatticeBravais config (see constructor)
187
187
  */
188
188
  static getDefaultPrimitiveLatticeConfigByType(latticeConfig) {
189
- const f_ = math_1.default.roundArrayOrNumber;
189
+ const f_ = math_1.math.roundArrayOrNumber;
190
190
  // construct new primitive cell using lattice parameters and skip rounding the vectors
191
191
  const vectors = (0, primitive_cell_1.getPrimitiveLatticeVectorsFromConfig)(latticeConfig);
192
192
  // create new lattice from primitive cell
@@ -224,7 +224,7 @@ class Lattice extends entity_1.InMemoryEntity {
224
224
  scaledLattice.beta,
225
225
  scaledLattice.gamma,
226
226
  ]
227
- .map((x) => math_1.default.round(x, constants_1.HASH_TOLERANCE))
227
+ .map((x) => math_1.math.round(x, constants_1.HASH_TOLERANCE))
228
228
  .join(";")};`;
229
229
  }
230
230
  /**
@@ -23,14 +23,12 @@ export declare class ReciprocalLattice extends Lattice {
23
23
  get reciprocalVectors(): Vector3DSchema[];
24
24
  /**
25
25
  * Norms of reciprocal vectors.
26
- * @return {number[]}
27
26
  */
28
- get reciprocalVectorNorms(): number[];
27
+ get reciprocalVectorNorms(): Vector3DSchema;
29
28
  /**
30
29
  * Ratio of reciprocal vector norms scaled by the inverse of the largest component.
31
- * @return {number[]}
32
30
  */
33
- get reciprocalVectorRatios(): number[];
31
+ get reciprocalVectorRatios(): Vector3DSchema;
34
32
  /**
35
33
  * Get point (in crystal coordinates) in cartesian coordinates.
36
34
  * @param {KPointCoordinates} point - point in 3D space
@@ -67,9 +65,9 @@ export declare class ReciprocalLattice extends Lattice {
67
65
  /**
68
66
  * Calculate grid dimensions from total number of k-points.
69
67
  * @param {number} nKpoints - Total number of k-points.
70
- * @return {number[]} - Grid dimensions
68
+ * @return Grid dimensions
71
69
  */
72
- getDimensionsFromPointsCount(nKpoints: number): number[];
70
+ getDimensionsFromPointsCount(nKpoints: number): Vector3DSchema;
73
71
  get conversionTable(): ConversionTable;
74
72
  /**
75
73
  * Calculate grid dimensions from k-point spacing, i.e.
@@ -77,9 +75,8 @@ export declare class ReciprocalLattice extends Lattice {
77
75
  * Note: just as the lattice vectors spacing is in cartesian (2pi / a) units by default
78
76
  * @param {number} spacing - maximum Spacing between k-points
79
77
  * @param {string} units - units of spacing parameter (default: 2pi / a)
80
- * @return {number[]}
81
78
  */
82
- getDimensionsFromSpacing(spacing: number, units?: string): number[];
79
+ getDimensionsFromSpacing(spacing: number, units?: string): Vector3DSchema;
83
80
  /**
84
81
  * Calculate grid spacing as average of spacing along individual reciprocal axes.
85
82
  * @param {number[]} dimensions - Array of dimensions
@@ -5,8 +5,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.ReciprocalLattice = void 0;
7
7
  const constants_1 = require("@mat3ra/code/dist/js/constants");
8
+ const math_1 = require("@mat3ra/code/dist/js/math");
8
9
  const lodash_1 = __importDefault(require("lodash"));
9
- const math_1 = __importDefault(require("../../math"));
10
10
  const lattice_1 = require("../lattice");
11
11
  const paths_1 = require("./paths");
12
12
  const symmetry_points_1 = require("./symmetry_points");
@@ -17,28 +17,26 @@ class ReciprocalLattice extends lattice_1.Lattice {
17
17
  */
18
18
  get reciprocalVectors() {
19
19
  const vectors_ = this.vectors.vectorArrays;
20
- const a = math_1.default.vlen(vectors_[0]);
21
- const divider = math_1.default.multiply(vectors_[0], math_1.default.cross(vectors_[1], vectors_[2])) / a;
20
+ const a = math_1.math.vlen(vectors_[0]);
21
+ const divider = math_1.math.multiply(vectors_[0], math_1.math.cross(vectors_[1], vectors_[2])) / a;
22
22
  return [
23
- math_1.default.multiply(math_1.default.cross(vectors_[1], vectors_[2]), 1 / divider),
24
- math_1.default.multiply(math_1.default.cross(vectors_[2], vectors_[0]), 1 / divider),
25
- math_1.default.multiply(math_1.default.cross(vectors_[0], vectors_[1]), 1 / divider),
23
+ math_1.math.multiply(math_1.math.cross(vectors_[1], vectors_[2]), 1 / divider),
24
+ math_1.math.multiply(math_1.math.cross(vectors_[2], vectors_[0]), 1 / divider),
25
+ math_1.math.multiply(math_1.math.cross(vectors_[0], vectors_[1]), 1 / divider),
26
26
  ];
27
27
  }
28
28
  /**
29
29
  * Norms of reciprocal vectors.
30
- * @return {number[]}
31
30
  */
32
31
  get reciprocalVectorNorms() {
33
- return this.reciprocalVectors.map((vec) => math_1.default.norm(vec));
32
+ return this.reciprocalVectors.map((vec) => math_1.math.norm(vec));
34
33
  }
35
34
  /**
36
35
  * Ratio of reciprocal vector norms scaled by the inverse of the largest component.
37
- * @return {number[]}
38
36
  */
39
37
  get reciprocalVectorRatios() {
40
38
  const norms = this.reciprocalVectorNorms;
41
- const maxNorm = math_1.default.max(...norms);
39
+ const maxNorm = math_1.math.max(...norms);
42
40
  return norms.map((n) => n / maxNorm);
43
41
  }
44
42
  /**
@@ -47,7 +45,7 @@ class ReciprocalLattice extends lattice_1.Lattice {
47
45
  * @return {KPointCoordinates}
48
46
  */
49
47
  getCartesianCoordinates(point) {
50
- return math_1.default.multiply(point, this.reciprocalVectors);
48
+ return math_1.math.multiply(point, this.reciprocalVectors);
51
49
  }
52
50
  /**
53
51
  * Get the list of high-symmetry points for the current lattice.
@@ -74,7 +72,7 @@ class ReciprocalLattice extends lattice_1.Lattice {
74
72
  const symmPoints = this.symmetryPoints;
75
73
  dataPoints.forEach((point, index) => {
76
74
  const symmPoint = symmPoints.find((x) => {
77
- return math_1.default.vEqualWithTolerance(x.coordinates, point, 1e-4);
75
+ return math_1.math.vEqualWithTolerance(x.coordinates, point, 1e-4);
78
76
  });
79
77
  if (symmPoint) {
80
78
  kpointPath.push({
@@ -96,13 +94,13 @@ class ReciprocalLattice extends lattice_1.Lattice {
96
94
  calculateDimension(nPoints, index) {
97
95
  const norms = this.reciprocalVectorNorms;
98
96
  const [j, k] = [0, 1, 2].filter((i) => i !== index); // get indices of other two dimensions
99
- const N = math_1.default.cbrt((nPoints * norms[index] ** 2) / (norms[j] * norms[k]));
100
- return math_1.default.max(1, math_1.default.ceil(N));
97
+ const N = math_1.math.cbrt((nPoints * norms[index] ** 2) / (norms[j] * norms[k]));
98
+ return math_1.math.max(1, math_1.math.ceil(N));
101
99
  }
102
100
  /**
103
101
  * Calculate grid dimensions from total number of k-points.
104
102
  * @param {number} nKpoints - Total number of k-points.
105
- * @return {number[]} - Grid dimensions
103
+ * @return Grid dimensions
106
104
  */
107
105
  getDimensionsFromPointsCount(nKpoints) {
108
106
  const indices = [0, 1, 2];
@@ -112,10 +110,10 @@ class ReciprocalLattice extends lattice_1.Lattice {
112
110
  const { a } = this;
113
111
  return {
114
112
  [constants_1.ATOMIC_COORD_UNITS.cartesian]: {
115
- [constants_1.units.angstrom]: (2 * math_1.default.PI) / a,
113
+ [constants_1.units.angstrom]: (2 * math_1.math.PI) / a,
116
114
  },
117
115
  [constants_1.units.angstrom]: {
118
- [constants_1.ATOMIC_COORD_UNITS.cartesian]: a / (2 * math_1.default.PI),
116
+ [constants_1.ATOMIC_COORD_UNITS.cartesian]: a / (2 * math_1.math.PI),
119
117
  },
120
118
  };
121
119
  }
@@ -125,12 +123,11 @@ class ReciprocalLattice extends lattice_1.Lattice {
125
123
  * Note: just as the lattice vectors spacing is in cartesian (2pi / a) units by default
126
124
  * @param {number} spacing - maximum Spacing between k-points
127
125
  * @param {string} units - units of spacing parameter (default: 2pi / a)
128
- * @return {number[]}
129
126
  */
130
127
  getDimensionsFromSpacing(spacing, units = constants_1.ATOMIC_COORD_UNITS.cartesian) {
131
128
  const factor = this.conversionTable[units][constants_1.ATOMIC_COORD_UNITS.cartesian] || 1;
132
129
  return this.reciprocalVectorNorms.map((norm) => {
133
- return math_1.default.max(1, math_1.default.ceil(lodash_1.default.round(norm / (spacing * factor), 4)));
130
+ return math_1.math.max(1, math_1.math.ceil(lodash_1.default.round(norm / (spacing * factor), 4)));
134
131
  });
135
132
  }
136
133
  /**
@@ -143,7 +140,7 @@ class ReciprocalLattice extends lattice_1.Lattice {
143
140
  const factor = this.conversionTable[constants_1.ATOMIC_COORD_UNITS.cartesian][units] || 1;
144
141
  const norms = this.reciprocalVectorNorms;
145
142
  return (factor *
146
- math_1.default.mean(dimensions.map((dim, i) => norms[i] / math_1.default.max(1, dim))));
143
+ math_1.math.mean(dimensions.map((dim, i) => norms[i] / math_1.math.max(1, dim))));
147
144
  }
148
145
  }
149
146
  exports.ReciprocalLattice = ReciprocalLattice;