@mat3ra/made 2026.6.29-0 → 2026.7.4-0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/js/cell/conventional_cell.js +2 -2
- package/dist/js/cell/primitive_cell.js +1 -2
- package/dist/js/lattice/lattice.js +17 -7
- package/dist/js/lattice/lattice_types.js +1 -1
- package/dist/js/lattice/reciprocal/symmetry_points.js +1 -2
- package/dist/js/material.d.ts +15 -15
- package/dist/js/parsers/poscar.js +1 -2
- package/dist/js/parsers/xyz.js +2 -2
- package/dist/js/parsers/xyz_combinatorial_basis.d.ts +2 -1
- package/dist/js/parsers/xyz_combinatorial_basis.js +17 -7
- package/package.json +40 -40
- package/pyproject.toml +6 -7
- package/src/py/mat3ra/made/cell/primitive_cell.py +156 -0
- package/tests/py/conftest.py +1 -1
- package/tests/py/unit/test_primitive_cell.py +118 -0
- /package/src/py/mat3ra/made/{cell.py → cell/__init__.py} +0 -0
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.PRIMITIVE_TO_CONVENTIONAL_CELL_LATTICE_TYPES = exports.PRIMITIVE_TO_CONVENTIONAL_CELL_MULTIPLIERS = void 0;
|
|
4
|
+
exports.isConventionalCellSameAsPrimitiveForLatticeType = isConventionalCellSameAsPrimitiveForLatticeType;
|
|
4
5
|
/**
|
|
5
6
|
* Routines for calculating conventional cell vectors from primitive cell Bravais parameters.
|
|
6
7
|
* Following Setyawan, W., & Curtarolo, S. (2010). doi:10.1016/j.commatsci.2010.05.010
|
|
@@ -77,4 +78,3 @@ function isConventionalCellSameAsPrimitiveForLatticeType(latticeType) {
|
|
|
77
78
|
const multiplier = exports.PRIMITIVE_TO_CONVENTIONAL_CELL_MULTIPLIERS[latticeType || "TRI"];
|
|
78
79
|
return multiplier === unitMatrix;
|
|
79
80
|
}
|
|
80
|
-
exports.isConventionalCellSameAsPrimitiveForLatticeType = isConventionalCellSameAsPrimitiveForLatticeType;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getPrimitiveLatticeVectorsFromConfig =
|
|
3
|
+
exports.getPrimitiveLatticeVectorsFromConfig = getPrimitiveLatticeVectorsFromConfig;
|
|
4
4
|
const math_1 = require("@mat3ra/code/dist/js/math");
|
|
5
5
|
/**
|
|
6
6
|
* Routines for calculating primitive cell vectors from conventional cell Bravais parameters.
|
|
@@ -143,4 +143,3 @@ function getPrimitiveLatticeVectorsFromConfig(latticeConfig) {
|
|
|
143
143
|
const [vectorA, vectorB, vectorC] = primitiveCellGenerator(latticeConfig);
|
|
144
144
|
return [vectorA, vectorB, vectorC];
|
|
145
145
|
}
|
|
146
|
-
exports.getPrimitiveLatticeVectorsFromConfig = getPrimitiveLatticeVectorsFromConfig;
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.Lattice = exports.LatticeVectors = exports.molecularLatticePaddingFactor = exports.diatomicLatticePaddingFactor = exports.defaultNonPeriodicMinimumLatticeSize = void 0;
|
|
27
37
|
const constants_1 = require("@mat3ra/code/dist/js/constants");
|
|
@@ -27,7 +27,7 @@ var LatticeTypeExtended;
|
|
|
27
27
|
LatticeTypeExtended["TRI_1a"] = "TRI_1a";
|
|
28
28
|
LatticeTypeExtended["TRI_2a"] = "TRI_2a";
|
|
29
29
|
LatticeTypeExtended["TRI_1b"] = "TRI_1b";
|
|
30
|
-
})(LatticeTypeExtended
|
|
30
|
+
})(LatticeTypeExtended || (exports.LatticeTypeExtended = LatticeTypeExtended = {}));
|
|
31
31
|
exports.DEFAULT_LATTICE_UNITS = {
|
|
32
32
|
// by default lattice vectors shall be measured in angstrom, angles - in degrees
|
|
33
33
|
length: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.symmetryPoints =
|
|
3
|
+
exports.symmetryPoints = symmetryPoints;
|
|
4
4
|
const POINTS = {
|
|
5
5
|
CUB: () => {
|
|
6
6
|
return [
|
|
@@ -863,4 +863,3 @@ function symmetryPoints(lattice) {
|
|
|
863
863
|
},
|
|
864
864
|
].concat(POINTS[lattice.type](lattice) || []);
|
|
865
865
|
}
|
|
866
|
-
exports.symmetryPoints = symmetryPoints;
|
package/dist/js/material.d.ts
CHANGED
|
@@ -37,34 +37,34 @@ declare class Material extends InMemoryEntity implements Schema {
|
|
|
37
37
|
* @summary Returns the specific derived property (as specified by name) for a material.
|
|
38
38
|
*/
|
|
39
39
|
getDerivedPropertyByName(name: string): {
|
|
40
|
-
name?: "volume"
|
|
41
|
-
units?: "angstrom^3"
|
|
40
|
+
name?: "volume";
|
|
41
|
+
units?: "angstrom^3";
|
|
42
42
|
value: number;
|
|
43
43
|
} | {
|
|
44
|
-
name?: "density"
|
|
45
|
-
units?: "g/cm^3"
|
|
44
|
+
name?: "density";
|
|
45
|
+
units?: "g/cm^3";
|
|
46
46
|
value: number;
|
|
47
47
|
} | {
|
|
48
|
-
pointGroupSymbol?: string
|
|
49
|
-
spaceGroupSymbol?: string
|
|
48
|
+
pointGroupSymbol?: string;
|
|
49
|
+
spaceGroupSymbol?: string;
|
|
50
50
|
tolerance?: {
|
|
51
|
-
units?: "angstrom"
|
|
51
|
+
units?: "angstrom";
|
|
52
52
|
value: number;
|
|
53
|
-
}
|
|
54
|
-
name?: "symmetry"
|
|
53
|
+
};
|
|
54
|
+
name?: "symmetry";
|
|
55
55
|
} | {
|
|
56
|
-
name?: "elemental_ratio"
|
|
56
|
+
name?: "elemental_ratio";
|
|
57
57
|
value: number;
|
|
58
|
-
element?: string
|
|
58
|
+
element?: string;
|
|
59
59
|
} | {
|
|
60
|
-
name?: "p-norm"
|
|
61
|
-
degree?: number
|
|
60
|
+
name?: "p-norm";
|
|
61
|
+
degree?: number;
|
|
62
62
|
value: number;
|
|
63
63
|
} | {
|
|
64
|
-
name?: "inchi"
|
|
64
|
+
name?: "inchi";
|
|
65
65
|
value: string;
|
|
66
66
|
} | {
|
|
67
|
-
name?: "inchi_key"
|
|
67
|
+
name?: "inchi_key";
|
|
68
68
|
value: string;
|
|
69
69
|
} | undefined;
|
|
70
70
|
/**
|
|
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.atomsCount =
|
|
6
|
+
exports.atomsCount = atomsCount;
|
|
7
7
|
const math_1 = require("@mat3ra/code/dist/js/math");
|
|
8
8
|
const utils_1 = require("@mat3ra/utils");
|
|
9
9
|
const underscore_string_1 = __importDefault(require("underscore.string"));
|
|
@@ -63,7 +63,6 @@ function atomsCount(poscarFileContent) {
|
|
|
63
63
|
const atomsLine = lines[6].split(/\s+/);
|
|
64
64
|
return atomsLine.map((x) => parseInt(x, 10)).reduce((a, b) => a + b);
|
|
65
65
|
}
|
|
66
|
-
exports.atomsCount = atomsCount;
|
|
67
66
|
/**
|
|
68
67
|
* Parses POSCAR file into a Material config object.
|
|
69
68
|
* @param fileContent - POSCAR file content.
|
package/dist/js/parsers/xyz.js
CHANGED
|
@@ -3,7 +3,8 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
|
3
3
|
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
4
4
|
};
|
|
5
5
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
6
|
-
exports.
|
|
6
|
+
exports.XYZ_COORDINATE_PRECISION = void 0;
|
|
7
|
+
exports.validate = validate;
|
|
7
8
|
const lodash_1 = require("lodash");
|
|
8
9
|
const underscore_string_1 = __importDefault(require("underscore.string"));
|
|
9
10
|
const constrained_basis_1 = require("../basis/constrained_basis");
|
|
@@ -43,7 +44,6 @@ function validate(xyzTxt) {
|
|
|
43
44
|
.filter((x) => x.trim() !== "")
|
|
44
45
|
.forEach(validateLine);
|
|
45
46
|
}
|
|
46
|
-
exports.validate = validate;
|
|
47
47
|
/**
|
|
48
48
|
* Parses XYZ line and returns an object.
|
|
49
49
|
* @param line - line of text
|
|
@@ -1,3 +1,4 @@
|
|
|
1
|
+
import { BasisSchema } from "@mat3ra/esse/dist/js/types";
|
|
1
2
|
import { ElementsAndCoordinatesConfig } from "../basis/basis";
|
|
2
3
|
import { AtomicCoordinateValue } from "../basis/coordinates";
|
|
3
4
|
import { AtomicElementValue } from "../basis/elements";
|
|
@@ -37,7 +38,7 @@ export declare class CombinatorialBasis {
|
|
|
37
38
|
* @return {String[]}
|
|
38
39
|
*/
|
|
39
40
|
get uniqueElements(): any[];
|
|
40
|
-
static toBasisConfigForElementsAndCoordinates(array: ElementWithCoordinate[], units?: "
|
|
41
|
+
static toBasisConfigForElementsAndCoordinates(array: ElementWithCoordinate[], units?: BasisSchema["units"], cell?: Cell): ElementsAndCoordinatesConfig;
|
|
41
42
|
/**
|
|
42
43
|
* Returns array of regular bases extracted from current combinatorial basis.
|
|
43
44
|
* @return {Basis[]|Object[]}
|
|
@@ -15,13 +15,23 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
36
|
exports.CombinatorialBasis = exports.WrongBasisFormat = void 0;
|
|
27
37
|
const math_1 = require("@mat3ra/code/dist/js/math");
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@mat3ra/made",
|
|
3
|
-
"version": "2026.
|
|
3
|
+
"version": "2026.7.4-0",
|
|
4
4
|
"description": "MAterials DEsign library",
|
|
5
5
|
"scripts": {
|
|
6
6
|
"lint": "eslint --cache src/js tests/js && prettier --write src/js tests/js",
|
|
@@ -14,68 +14,68 @@
|
|
|
14
14
|
},
|
|
15
15
|
"repository": {
|
|
16
16
|
"type": "git",
|
|
17
|
-
"url": "https://github.com/
|
|
17
|
+
"url": "https://github.com/mat3ra/made.git"
|
|
18
18
|
},
|
|
19
19
|
"main": "dist/js/made.js",
|
|
20
20
|
"author": "Exabyte Inc.",
|
|
21
21
|
"bugs": {
|
|
22
|
-
"url": "https://github.com/
|
|
22
|
+
"url": "https://github.com/mat3ra/made/issues"
|
|
23
23
|
},
|
|
24
24
|
"license": "Apache-2.0",
|
|
25
|
-
"homepage": "https://github.com/
|
|
25
|
+
"homepage": "https://github.com/mat3ra/made",
|
|
26
26
|
"engines": {
|
|
27
27
|
"node": ">=0.14"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"@babel/eslint-parser": "^7.
|
|
31
|
-
"@babel/plugin-proposal-class-properties": "^7.
|
|
32
|
-
"@babel/preset-env": "^7.
|
|
33
|
-
"@babel/preset-react": "^7.
|
|
34
|
-
"@babel/register": "^7.
|
|
35
|
-
"@babel/runtime-corejs3": "^7.
|
|
36
|
-
"@exabyte-io/eslint-config": "
|
|
37
|
-
"@mat3ra/code": "2026.5.27-0",
|
|
38
|
-
"@mat3ra/esse": "2026.
|
|
39
|
-
"@mat3ra/tsconfig": "2024.6.3-0",
|
|
40
|
-
"@mat3ra/utils": "^2026.
|
|
30
|
+
"@babel/eslint-parser": "^7.29.7",
|
|
31
|
+
"@babel/plugin-proposal-class-properties": "^7.18.6",
|
|
32
|
+
"@babel/preset-env": "^7.29.7",
|
|
33
|
+
"@babel/preset-react": "^7.29.7",
|
|
34
|
+
"@babel/register": "^7.29.7",
|
|
35
|
+
"@babel/runtime-corejs3": "^7.29.7",
|
|
36
|
+
"@exabyte-io/eslint-config": "^2026.7.3-0",
|
|
37
|
+
"@mat3ra/code": "^2026.5.27-0",
|
|
38
|
+
"@mat3ra/esse": "^2026.6.30-0",
|
|
39
|
+
"@mat3ra/tsconfig": "^2024.6.3-0",
|
|
40
|
+
"@mat3ra/utils": "^2026.7.3-0",
|
|
41
41
|
"@types/crypto-js": "^4.2.2",
|
|
42
|
-
"@typescript-eslint/eslint-plugin": "^5.
|
|
43
|
-
"@typescript-eslint/parser": "^5.
|
|
44
|
-
"chai": "^4.
|
|
42
|
+
"@typescript-eslint/eslint-plugin": "^5.62.0",
|
|
43
|
+
"@typescript-eslint/parser": "^5.62.0",
|
|
44
|
+
"chai": "^4.5.0",
|
|
45
45
|
"chai-almost": "^1.0.1",
|
|
46
46
|
"eslint": "^7.32.0",
|
|
47
|
-
"eslint-config-airbnb": "^19.0.
|
|
48
|
-
"eslint-config-prettier": "^8.
|
|
47
|
+
"eslint-config-airbnb": "^19.0.4",
|
|
48
|
+
"eslint-config-prettier": "^8.10.2",
|
|
49
49
|
"eslint-import-resolver-exports": "^1.0.0-beta.5",
|
|
50
50
|
"eslint-import-resolver-meteor": "^0.4.0",
|
|
51
|
-
"eslint-import-resolver-node": "^0.3.
|
|
52
|
-
"eslint-plugin-import": "^2.
|
|
53
|
-
"eslint-plugin-jsdoc": "^37.
|
|
54
|
-
"eslint-plugin-jsx-a11y": "^6.
|
|
51
|
+
"eslint-import-resolver-node": "^0.3.10",
|
|
52
|
+
"eslint-plugin-import": "^2.32.0",
|
|
53
|
+
"eslint-plugin-jsdoc": "^37.9.7",
|
|
54
|
+
"eslint-plugin-jsx-a11y": "^6.10.2",
|
|
55
55
|
"eslint-plugin-mui-path-imports": "0.0.15",
|
|
56
|
-
"eslint-plugin-prettier": "^4.2.
|
|
57
|
-
"eslint-plugin-react": "^7.
|
|
56
|
+
"eslint-plugin-prettier": "^4.2.5",
|
|
57
|
+
"eslint-plugin-react": "^7.37.5",
|
|
58
58
|
"eslint-plugin-simple-import-sort": "^7.0.0",
|
|
59
59
|
"husky": "^7.0.4",
|
|
60
|
-
"lint-staged": "^12.
|
|
61
|
-
"mocha": "10.
|
|
62
|
-
"prettier": "^2.
|
|
60
|
+
"lint-staged": "^12.5.0",
|
|
61
|
+
"mocha": "10.8.2",
|
|
62
|
+
"prettier": "^2.8.8",
|
|
63
63
|
"nyc": "^15.1.0"
|
|
64
64
|
},
|
|
65
65
|
"dependencies": {
|
|
66
|
-
"@babel/core": "7.
|
|
67
|
-
"@exabyte-io/periodic-table.js": "
|
|
68
|
-
"@types/chai": "^4.3.
|
|
66
|
+
"@babel/core": "^7.29.7",
|
|
67
|
+
"@exabyte-io/periodic-table.js": "^2023.12.23-3",
|
|
68
|
+
"@types/chai": "^4.3.20",
|
|
69
69
|
"@types/chai-almost": "^1.0.3",
|
|
70
|
-
"@types/mocha": "^10.0.
|
|
71
|
-
"@types/node": "^20.
|
|
72
|
-
"@types/underscore.string": "^0.0.
|
|
70
|
+
"@types/mocha": "^10.0.10",
|
|
71
|
+
"@types/node": "^20.19.43",
|
|
72
|
+
"@types/underscore.string": "^0.0.42",
|
|
73
73
|
"array-almost-equal": "^1.0.0",
|
|
74
|
-
"crypto-js": "4.2.0",
|
|
75
|
-
"lodash": "^4.
|
|
76
|
-
"ts-node": "^10.9.
|
|
77
|
-
"typescript": "^
|
|
78
|
-
"underscore.string": "^3.3.
|
|
74
|
+
"crypto-js": "^4.2.0",
|
|
75
|
+
"lodash": "^4.18.*",
|
|
76
|
+
"ts-node": "^10.9.2",
|
|
77
|
+
"typescript": "^5.9.3",
|
|
78
|
+
"underscore.string": "^3.3.6"
|
|
79
79
|
},
|
|
80
80
|
"peerDependencies": {
|
|
81
81
|
"@mat3ra/code": "*",
|
package/pyproject.toml
CHANGED
|
@@ -3,7 +3,7 @@ name = "mat3ra-made"
|
|
|
3
3
|
dynamic = ["version"]
|
|
4
4
|
description = "MAterials DEfinitions and/or MAterials DEsign library."
|
|
5
5
|
readme = "README.md"
|
|
6
|
-
requires-python = ">=3.
|
|
6
|
+
requires-python = ">=3.10"
|
|
7
7
|
license = {file = "LICENSE.md"}
|
|
8
8
|
authors = [
|
|
9
9
|
{ name = "Exabyte Inc.", email = "info@mat3ra.com" }
|
|
@@ -15,12 +15,11 @@ classifiers = [
|
|
|
15
15
|
"Topic :: Software Development",
|
|
16
16
|
]
|
|
17
17
|
dependencies = [
|
|
18
|
-
|
|
18
|
+
"mat3ra-code",
|
|
19
|
+
"mat3ra-esse>=2026.6.30.post0",
|
|
20
|
+
"mat3ra-utils>=2026.7.3.post0",
|
|
19
21
|
# new verison of numpy==2.0.0 is not handled by pymatgen yet
|
|
20
22
|
"numpy<=1.26.4",
|
|
21
|
-
"mat3ra-utils",
|
|
22
|
-
"mat3ra-esse",
|
|
23
|
-
"mat3ra-code"
|
|
24
23
|
]
|
|
25
24
|
|
|
26
25
|
[project.optional-dependencies]
|
|
@@ -81,7 +80,7 @@ where = ["src/py"]
|
|
|
81
80
|
|
|
82
81
|
[tool.black]
|
|
83
82
|
line-length = 120
|
|
84
|
-
target-version = ['
|
|
83
|
+
target-version = ['py310']
|
|
85
84
|
# 'extend-exclude' excludes files or directories in addition to the defaults
|
|
86
85
|
extend-exclude = '''
|
|
87
86
|
(
|
|
@@ -99,7 +98,7 @@ extend-exclude = [
|
|
|
99
98
|
"tests/py/unit/fixtures"
|
|
100
99
|
]
|
|
101
100
|
line-length = 120
|
|
102
|
-
target-version = "
|
|
101
|
+
target-version = "py310"
|
|
103
102
|
|
|
104
103
|
[tool.ruff.per-file-ignores]
|
|
105
104
|
"__init__.py" = ["F401"]
|
|
@@ -0,0 +1,156 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Routines for calculating primitive cell vectors from conventional cell Bravais parameters.
|
|
3
|
+
Python equivalent of src/js/cell/primitive_cell.ts.
|
|
4
|
+
|
|
5
|
+
Following Setyawan, W., & Curtarolo, S. (2010). doi:10.1016/j.commatsci.2010.05.010
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import math
|
|
9
|
+
from typing import List
|
|
10
|
+
|
|
11
|
+
from mat3ra.esse.models.properties_directory.structural.lattice import LatticeSchema
|
|
12
|
+
from mat3ra.made.cell import Cell
|
|
13
|
+
|
|
14
|
+
Matrix3x3 = List[List[float]]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def _rhl(p: LatticeSchema) -> Matrix3x3:
|
|
18
|
+
a = p.a
|
|
19
|
+
alpha_rad = math.radians(p.alpha)
|
|
20
|
+
|
|
21
|
+
cos_alpha = math.cos(alpha_rad)
|
|
22
|
+
cos_half_alpha = math.cos(alpha_rad / 2.0)
|
|
23
|
+
sin_half_alpha = math.sin(alpha_rad / 2.0)
|
|
24
|
+
|
|
25
|
+
z_comp = a * math.sqrt(1.0 - (cos_alpha / cos_half_alpha) ** 2)
|
|
26
|
+
|
|
27
|
+
return [
|
|
28
|
+
[a * cos_half_alpha, -a * sin_half_alpha, 0.0],
|
|
29
|
+
[a * cos_half_alpha, a * sin_half_alpha, 0.0],
|
|
30
|
+
[(a * cos_alpha) / cos_half_alpha, 0.0, z_comp],
|
|
31
|
+
]
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
def _tri(p: LatticeSchema) -> Matrix3x3:
|
|
35
|
+
"""
|
|
36
|
+
Algorithm from pymatgen (from_params).
|
|
37
|
+
Mirrors the TRI case in primitive_cell.ts exactly.
|
|
38
|
+
"""
|
|
39
|
+
alpha = math.radians(p.alpha)
|
|
40
|
+
beta = math.radians(p.beta)
|
|
41
|
+
gamma = math.radians(p.gamma)
|
|
42
|
+
|
|
43
|
+
cos_alpha = math.cos(alpha)
|
|
44
|
+
cos_beta = math.cos(beta)
|
|
45
|
+
cos_gamma = math.cos(gamma)
|
|
46
|
+
sin_alpha = math.sin(alpha)
|
|
47
|
+
sin_beta = math.sin(beta)
|
|
48
|
+
|
|
49
|
+
acos_arg = (cos_alpha * cos_beta - cos_gamma) / (sin_alpha * sin_beta)
|
|
50
|
+
# Clamp to [-1, 1] to guard against floating-point drift
|
|
51
|
+
acos_arg = max(-1.0, min(1.0, acos_arg))
|
|
52
|
+
|
|
53
|
+
gamma_star = math.acos(acos_arg)
|
|
54
|
+
cos_gamma_star = math.cos(gamma_star)
|
|
55
|
+
sin_gamma_star = math.sin(gamma_star)
|
|
56
|
+
|
|
57
|
+
a, b, c = p.a, p.b, p.c
|
|
58
|
+
return [
|
|
59
|
+
[a * sin_beta, 0.0, a * cos_beta],
|
|
60
|
+
[-b * sin_alpha * cos_gamma_star, b * sin_alpha * sin_gamma_star, b * cos_alpha],
|
|
61
|
+
[0.0, 0.0, c],
|
|
62
|
+
]
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
PRIMITIVE_CELLS = {
|
|
66
|
+
"CUB": lambda p: [
|
|
67
|
+
[p.a, 0, 0],
|
|
68
|
+
[0, p.a, 0],
|
|
69
|
+
[0, 0, p.a],
|
|
70
|
+
],
|
|
71
|
+
"FCC": lambda p: [
|
|
72
|
+
[0.0, p.a / 2, p.a / 2],
|
|
73
|
+
[p.a / 2, 0.0, p.a / 2],
|
|
74
|
+
[p.a / 2, p.a / 2, 0.0],
|
|
75
|
+
],
|
|
76
|
+
"BCC": lambda p: [
|
|
77
|
+
[-p.a / 2, p.a / 2, p.a / 2],
|
|
78
|
+
[p.a / 2, -p.a / 2, p.a / 2],
|
|
79
|
+
[p.a / 2, p.a / 2, -p.a / 2],
|
|
80
|
+
],
|
|
81
|
+
"TET": lambda p: [
|
|
82
|
+
[p.a, 0, 0],
|
|
83
|
+
[0, p.a, 0],
|
|
84
|
+
[0, 0, p.c],
|
|
85
|
+
],
|
|
86
|
+
"BCT": lambda p: [
|
|
87
|
+
[-p.a / 2, p.a / 2, p.c / 2],
|
|
88
|
+
[p.a / 2, -p.a / 2, p.c / 2],
|
|
89
|
+
[p.a / 2, p.a / 2, -p.c / 2],
|
|
90
|
+
],
|
|
91
|
+
"ORC": lambda p: [
|
|
92
|
+
[p.a, 0, 0],
|
|
93
|
+
[0, p.b, 0],
|
|
94
|
+
[0, 0, p.c],
|
|
95
|
+
],
|
|
96
|
+
"ORCF": lambda p: [
|
|
97
|
+
[0, p.b / 2, p.c / 2],
|
|
98
|
+
[p.a / 2, 0, p.c / 2],
|
|
99
|
+
[p.a / 2, p.b / 2, 0],
|
|
100
|
+
],
|
|
101
|
+
"ORCI": lambda p: [
|
|
102
|
+
[-p.a / 2, p.b / 2, p.c / 2],
|
|
103
|
+
[p.a / 2, -p.b / 2, p.c / 2],
|
|
104
|
+
[p.a / 2, p.b / 2, -p.c / 2],
|
|
105
|
+
],
|
|
106
|
+
"ORCC": lambda p: [
|
|
107
|
+
[p.a / 2, p.b / 2, 0],
|
|
108
|
+
[-p.a / 2, p.b / 2, 0],
|
|
109
|
+
[0, 0, p.c],
|
|
110
|
+
],
|
|
111
|
+
"HEX": lambda p: [
|
|
112
|
+
[p.a / 2, -(p.a * math.sqrt(3)) / 2, 0],
|
|
113
|
+
[p.a / 2, (p.a * math.sqrt(3)) / 2, 0],
|
|
114
|
+
[0, 0, p.c],
|
|
115
|
+
],
|
|
116
|
+
"RHL": _rhl,
|
|
117
|
+
"MCL": lambda p: [
|
|
118
|
+
[p.a, 0, 0],
|
|
119
|
+
[0, p.b, 0],
|
|
120
|
+
[0, p.c * math.cos(math.radians(p.alpha)), p.c * math.sin(math.radians(p.alpha))],
|
|
121
|
+
],
|
|
122
|
+
"MCLC": lambda p: [
|
|
123
|
+
[p.a / 2, p.b / 2, 0],
|
|
124
|
+
[-p.a / 2, p.b / 2, 0],
|
|
125
|
+
[0, p.c * math.cos(math.radians(p.alpha)), p.c * math.sin(math.radians(p.alpha))],
|
|
126
|
+
],
|
|
127
|
+
"TRI": _tri,
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
|
|
131
|
+
def get_primitive_lattice_vectors_from_config(lattice_config: LatticeSchema) -> Matrix3x3:
|
|
132
|
+
"""
|
|
133
|
+
Returns lattice vectors for a primitive cell for a given lattice config.
|
|
134
|
+
Python equivalent of getPrimitiveLatticeVectorsFromConfig() in primitive_cell.ts.
|
|
135
|
+
|
|
136
|
+
Args:
|
|
137
|
+
lattice_config: LatticeSchema instance with fields:
|
|
138
|
+
type, a, b, c, alpha, beta, gamma.
|
|
139
|
+
|
|
140
|
+
Returns:
|
|
141
|
+
3x3 list of lists (rows = vectors a, b, c) in the same units as the
|
|
142
|
+
input lattice parameters (typically Angstroms).
|
|
143
|
+
"""
|
|
144
|
+
lattice_type = lattice_config.type.value if lattice_config.type else "TRI"
|
|
145
|
+
generator = PRIMITIVE_CELLS.get(lattice_type)
|
|
146
|
+
if generator is None:
|
|
147
|
+
raise ValueError(
|
|
148
|
+
f"Unsupported lattice type '{lattice_type}'. " f"Must be one of: {list(PRIMITIVE_CELLS.keys())}"
|
|
149
|
+
)
|
|
150
|
+
return generator(lattice_config)
|
|
151
|
+
|
|
152
|
+
|
|
153
|
+
def get_primitive_cell_from_config(lattice_config: LatticeSchema) -> Cell:
|
|
154
|
+
"""Returns a full Cell object instantiated with the primitive lattice vectors."""
|
|
155
|
+
vectors = get_primitive_lattice_vectors_from_config(lattice_config)
|
|
156
|
+
return Cell.from_vectors_array(vectors)
|
package/tests/py/conftest.py
CHANGED
|
@@ -26,7 +26,7 @@ def custom_warn(message, category=None, *args, **kwargs):
|
|
|
26
26
|
# These warnings always appear to come from inside spglib itself.
|
|
27
27
|
# This patch intercepts `warnings.warn` to ignore only those specific messages.
|
|
28
28
|
|
|
29
|
-
if isinstance(message, str) and "SpglibDataset" in message and category
|
|
29
|
+
if isinstance(message, str) and "SpglibDataset" in message and category is DeprecationWarning:
|
|
30
30
|
return # suppress
|
|
31
31
|
return _orig_warn(message, category, *args, **kwargs)
|
|
32
32
|
|
|
@@ -0,0 +1,118 @@
|
|
|
1
|
+
import math
|
|
2
|
+
import pytest
|
|
3
|
+
|
|
4
|
+
from mat3ra.made.cell.primitive_cell import get_primitive_lattice_vectors_from_config
|
|
5
|
+
from mat3ra.made.lattice import Lattice, LatticeTypeEnum
|
|
6
|
+
from tests.py.unit.utils import assert_two_entities_deep_almost_equal
|
|
7
|
+
|
|
8
|
+
EXPECTED_PRIMITIVE_CELL_NA4CL4 = [
|
|
9
|
+
[5.691694, 0.0, 0.0],
|
|
10
|
+
[0.0, 5.691694, 0.0],
|
|
11
|
+
[0.0, 0.0, 5.691694],
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_primitive_lattice_vectors_na4cl4():
|
|
16
|
+
"""
|
|
17
|
+
Replicates the TypeScript test for Na4Cl4 (CUB cell).
|
|
18
|
+
Translates from: tests/js/cell/primitive_cell.ts
|
|
19
|
+
"""
|
|
20
|
+
lattice = Lattice(type=LatticeTypeEnum.CUB, a=5.691694)
|
|
21
|
+
actual_primitive_cell = get_primitive_lattice_vectors_from_config(lattice)
|
|
22
|
+
|
|
23
|
+
assert_two_entities_deep_almost_equal(EXPECTED_PRIMITIVE_CELL_NA4CL4, actual_primitive_cell)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@pytest.mark.parametrize(
|
|
27
|
+
"l_type, kwargs, expected",
|
|
28
|
+
[
|
|
29
|
+
(LatticeTypeEnum.CUB, {"a": 2.0}, [[2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0]]),
|
|
30
|
+
(LatticeTypeEnum.FCC, {"a": 2.0}, [[0.0, 1.0, 1.0], [1.0, 0.0, 1.0], [1.0, 1.0, 0.0]]),
|
|
31
|
+
(LatticeTypeEnum.BCC, {"a": 2.0}, [[-1.0, 1.0, 1.0], [1.0, -1.0, 1.0], [1.0, 1.0, -1.0]]),
|
|
32
|
+
(LatticeTypeEnum.TET, {"a": 2.0, "c": 3.0}, [[2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 3.0]]),
|
|
33
|
+
(LatticeTypeEnum.BCT, {"a": 2.0, "c": 3.0}, [[-1.0, 1.0, 1.5], [1.0, -1.0, 1.5], [1.0, 1.0, -1.5]]),
|
|
34
|
+
(LatticeTypeEnum.ORC, {"a": 2.0, "b": 3.0, "c": 4.0}, [[2.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 4.0]]),
|
|
35
|
+
(
|
|
36
|
+
LatticeTypeEnum.ORCF,
|
|
37
|
+
{"a": 2.0, "b": 3.0, "c": 4.0},
|
|
38
|
+
[[0.0, 1.5, 2.0], [1.0, 0.0, 2.0], [1.0, 1.5, 0.0]],
|
|
39
|
+
),
|
|
40
|
+
(
|
|
41
|
+
LatticeTypeEnum.ORCI,
|
|
42
|
+
{"a": 2.0, "b": 3.0, "c": 4.0},
|
|
43
|
+
[[-1.0, 1.5, 2.0], [1.0, -1.5, 2.0], [1.0, 1.5, -2.0]],
|
|
44
|
+
),
|
|
45
|
+
(
|
|
46
|
+
LatticeTypeEnum.ORCC,
|
|
47
|
+
{"a": 2.0, "b": 3.0, "c": 4.0},
|
|
48
|
+
[[1.0, 1.5, 0.0], [-1.0, 1.5, 0.0], [0.0, 0.0, 4.0]],
|
|
49
|
+
),
|
|
50
|
+
(
|
|
51
|
+
LatticeTypeEnum.HEX,
|
|
52
|
+
{"a": 2.0, "c": 3.0},
|
|
53
|
+
[[1.0, -math.sqrt(3), 0.0], [1.0, math.sqrt(3), 0.0], [0.0, 0.0, 3.0]],
|
|
54
|
+
),
|
|
55
|
+
(
|
|
56
|
+
LatticeTypeEnum.RHL,
|
|
57
|
+
{"a": 2.0, "alpha": 60.0},
|
|
58
|
+
[[1.7320508, -1.0, 0.0], [1.7320508, 1.0, 0.0], [1.1547005, 0.0, 1.6329931]],
|
|
59
|
+
),
|
|
60
|
+
(
|
|
61
|
+
LatticeTypeEnum.MCL,
|
|
62
|
+
{"a": 2.0, "b": 3.0, "c": 4.0, "alpha": 60.0},
|
|
63
|
+
[[2.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 2.0, 3.4641016]],
|
|
64
|
+
),
|
|
65
|
+
(
|
|
66
|
+
LatticeTypeEnum.MCLC,
|
|
67
|
+
{"a": 2.0, "b": 3.0, "c": 4.0, "alpha": 60.0},
|
|
68
|
+
[[1.0, 1.5, 0.0], [-1.0, 1.5, 0.0], [0.0, 2.0, 3.4641016]],
|
|
69
|
+
),
|
|
70
|
+
(
|
|
71
|
+
LatticeTypeEnum.TRI,
|
|
72
|
+
{"a": 2.0, "b": 3.0, "c": 4.0, "alpha": 90.0, "beta": 90.0, "gamma": 90.0},
|
|
73
|
+
[[2.0, 0.0, 0.0], [0.0, 3.0, 0.0], [0.0, 0.0, 4.0]],
|
|
74
|
+
),
|
|
75
|
+
],
|
|
76
|
+
)
|
|
77
|
+
def test_primitive_lattice_generators(l_type, kwargs, expected):
|
|
78
|
+
"""Validates the math generators for all 14 Bravais lattice scenarios."""
|
|
79
|
+
lattice = Lattice(type=l_type, **kwargs)
|
|
80
|
+
result = get_primitive_lattice_vectors_from_config(lattice)
|
|
81
|
+
assert_two_entities_deep_almost_equal(expected, result)
|
|
82
|
+
|
|
83
|
+
|
|
84
|
+
def test_fallback_to_tri_when_type_is_none():
|
|
85
|
+
"""Tests default fallback to 'TRI' when lattice_config.type is None."""
|
|
86
|
+
# Use a simple dummy class to bypass Pydantic's strict validation
|
|
87
|
+
# and simulate a malformed or incomplete Lattice config.
|
|
88
|
+
class MockLattice:
|
|
89
|
+
type = None
|
|
90
|
+
a, b, c = 2.0, 2.0, 2.0
|
|
91
|
+
alpha, beta, gamma = 90.0, 90.0, 90.0
|
|
92
|
+
|
|
93
|
+
lattice = MockLattice()
|
|
94
|
+
result = get_primitive_lattice_vectors_from_config(lattice)
|
|
95
|
+
expected = [[2.0, 0.0, 0.0], [0.0, 2.0, 0.0], [0.0, 0.0, 2.0]]
|
|
96
|
+
|
|
97
|
+
assert_two_entities_deep_almost_equal(expected, result)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
def test_unsupported_lattice_type_raises_value_error():
|
|
101
|
+
"""Ensures a ValueError is raised for an unknown lattice type mapping."""
|
|
102
|
+
# Using a MagicMock specifically here to force an invalid type value
|
|
103
|
+
# since LatticeTypeEnum won't allow arbitrary strings
|
|
104
|
+
class MockType:
|
|
105
|
+
value = "INVALID_TYPE"
|
|
106
|
+
|
|
107
|
+
class MockLattice:
|
|
108
|
+
type = MockType()
|
|
109
|
+
# Provide dummy parameters just in case
|
|
110
|
+
a, b, c = 2.0, 2.0, 2.0
|
|
111
|
+
alpha, beta, gamma = 90.0, 90.0, 90.0
|
|
112
|
+
|
|
113
|
+
lattice = MockLattice()
|
|
114
|
+
|
|
115
|
+
with pytest.raises(ValueError) as exc_info:
|
|
116
|
+
get_primitive_lattice_vectors_from_config(lattice)
|
|
117
|
+
|
|
118
|
+
assert "Unsupported lattice type 'INVALID_TYPE'" in str(exc_info.value)
|
|
File without changes
|