@mat3ra/made 2026.6.15-0 → 2026.6.29-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/.pre-commit-config.yaml +1 -1
- package/.prettierignore +1 -0
- package/AGENTS.md +133 -0
- package/MANIFEST.in +1 -0
- package/data/constants.json +13 -0
- package/data/reciprocal_paths.json +111 -0
- package/dist/js/data/reciprocal_paths.json +111 -0
- package/dist/js/lattice/reciprocal/paths.js +8 -113
- package/dist/js/made.d.ts +1 -1
- package/dist/js/made.js +1 -1
- package/package.json +1 -1
- package/pyproject.toml +1 -1
- package/src/js/constants/molecule.ts +1 -1
- package/src/js/lattice/reciprocal/paths.ts +10 -118
- package/src/js/made.ts +1 -1
- package/src/py/mat3ra/made/data_helper.py +5 -0
- package/src/py/mat3ra/made/lattice.py +34 -0
- package/src/py/mat3ra/made/material.py +1 -2
- package/src/py/mat3ra/made/reciprocal/__init__.py +5 -0
- package/src/py/mat3ra/made/reciprocal/lattice_reciprocal.py +147 -0
- package/src/py/mat3ra/made/reciprocal/paths.py +30 -0
- package/src/py/mat3ra/made/reciprocal/symmetry_points.py +385 -0
- package/src/py/mat3ra/made/tools/analyze/fingerprint/__init__.py +1 -1
- package/src/py/mat3ra/made/tools/analyze/fingerprint/layers/layered_fingerprint_along_axis.py +2 -3
- package/src/py/mat3ra/made/tools/analyze/interface/__init__.py +1 -1
- package/src/py/mat3ra/made/tools/analyze/lattice/analyzer.py +7 -5
- package/src/py/mat3ra/made/tools/analyze/lattice_planes.py +10 -9
- package/src/py/mat3ra/made/tools/analyze/lattice_swap_analyzer.py +3 -3
- package/src/py/mat3ra/made/tools/build/compound_pristine_structures/two_dimensional/heterostructure/helpers.py +0 -1
- package/src/py/mat3ra/made/tools/build/compound_pristine_structures/two_dimensional/heterostructure/utils.py +10 -11
- package/src/py/mat3ra/made/tools/build_components/operations/core/combinations/stack/builder.py +26 -13
- package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/perturb/helpers.py +2 -2
- package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/strain/builder.py +1 -1
- package/src/py/mat3ra/made/tools/convert/__init__.py +8 -11
- package/src/py/mat3ra/made/tools/convert/utils.py +9 -5
- package/src/py/mat3ra/made/tools/operations/reusable/unary.py +2 -2
- package/tests/js/parsers/poscar.ts +9 -9
- package/tests/py/unit/fixtures/thrid_party/ase_atoms.py +0 -1
- package/tests/py/unit/test_data_files.py +68 -0
- package/tests/py/unit/test_lattice.py +3 -4
- package/tests/py/unit/test_lattice_type_extended.py +53 -0
- package/tests/py/unit/test_reciprocal_lattice.py +86 -0
- package/tests/py/unit/test_reciprocal_paths.py +64 -0
- package/tests/py/unit/test_symmetry_points.py +151 -0
- package/tests/py/unit/test_tools_analyze.py +7 -1
- package/tests/py/unit/test_tools_analyze_basis.py +1 -1
- package/tests/py/unit/test_tools_analyze_lattice.py +9 -4
- package/tests/py/unit/test_tools_analyze_swap.py +15 -9
- package/tests/py/unit/test_tools_build_defect/test_point_defect.py +24 -3
- package/tests/py/unit/test_tools_build_interface.py +1 -2
- package/tests/py/unit/test_tools_build_interface_zsl.py +72 -4
- package/tests/py/unit/test_tools_build_metadata.py +0 -1
- package/tests/py/unit/test_tools_calculate.py +1 -0
- package/tests/py/unit/test_tools_convert.py +1 -4
- package/tests/py/unit/utils.py +29 -0
- package/constants.json +0 -13
- package/src/py/mat3ra/made/constants.py +0 -11
package/src/py/mat3ra/made/tools/build_components/operations/core/combinations/stack/builder.py
CHANGED
|
@@ -42,6 +42,11 @@ class StackNComponentsBuilder(BaseSingleBuilder):
|
|
|
42
42
|
configuration: StackConfiguration,
|
|
43
43
|
stack_component_build_parameters: Any = None,
|
|
44
44
|
) -> Optional[MaterialWithBuildMetadata]:
|
|
45
|
+
cache = getattr(self, "_stack_component_cache", None)
|
|
46
|
+
cache_key = id(stack_component_configuration_or_material)
|
|
47
|
+
if cache is not None and cache_key in cache:
|
|
48
|
+
return cache[cache_key]
|
|
49
|
+
|
|
45
50
|
builder = self.stack_component_types_conversion_map.get(type(stack_component_configuration_or_material))
|
|
46
51
|
pre_process_function = self.stack_component_types_conversion_pre_process_map.get(
|
|
47
52
|
type(stack_component_configuration_or_material), lambda x, y: x
|
|
@@ -50,21 +55,29 @@ class StackNComponentsBuilder(BaseSingleBuilder):
|
|
|
50
55
|
stack_component_configuration_or_material = pre_process_function(
|
|
51
56
|
stack_component_configuration_or_material, configuration
|
|
52
57
|
)
|
|
53
|
-
|
|
58
|
+
result = builder(build_parameters=stack_component_build_parameters).get_material(
|
|
54
59
|
stack_component_configuration_or_material
|
|
55
60
|
)
|
|
56
61
|
else:
|
|
57
|
-
|
|
62
|
+
result = stack_component_configuration_or_material
|
|
63
|
+
|
|
64
|
+
if cache is not None:
|
|
65
|
+
cache[cache_key] = result
|
|
66
|
+
return result
|
|
58
67
|
|
|
59
68
|
def _generate(self, configuration: TypeConfiguration) -> Material:
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
69
|
+
self._stack_component_cache: Optional[dict] = {}
|
|
70
|
+
try:
|
|
71
|
+
materials = []
|
|
72
|
+
for index, stack_component_config in enumerate(configuration.stack_components):
|
|
73
|
+
material = self._stack_component_to_material(stack_component_config, configuration)
|
|
74
|
+
gap = configuration.get_gap_by_id(index)
|
|
75
|
+
if gap is not None:
|
|
76
|
+
material = adjust_material_cell_to_set_gap_along_direction(material, gap, configuration.direction)
|
|
77
|
+
materials.append(material)
|
|
78
|
+
# Filter out None values in case some stack components are V
|
|
79
|
+
materials = [m for m in materials if m is not None]
|
|
80
|
+
stacked_material = stack(materials, configuration.direction or AxisEnum.z)
|
|
81
|
+
return stacked_material
|
|
82
|
+
finally:
|
|
83
|
+
self._stack_component_cache = None
|
package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/perturb/helpers.py
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
from typing import Optional, Union
|
|
2
2
|
|
|
3
3
|
import sympy as sp
|
|
4
|
-
|
|
5
4
|
from mat3ra.made.material import Material
|
|
5
|
+
|
|
6
|
+
from ..... import MaterialWithBuildMetadata
|
|
6
7
|
from .builders.base import PerturbationBuilder
|
|
7
8
|
from .builders.isometric import IsometricPerturbationBuilder
|
|
8
9
|
from .configuration import PerturbationConfiguration
|
|
9
10
|
from .functions import PerturbationFunctionHolder
|
|
10
11
|
from .functions.maxwell_boltzmann import MaxwellBoltzmannDisplacementHolder
|
|
11
|
-
from ..... import MaterialWithBuildMetadata
|
|
12
12
|
|
|
13
13
|
|
|
14
14
|
def create_perturbation(
|
package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/strain/builder.py
CHANGED
|
@@ -2,8 +2,8 @@ from typing import Type
|
|
|
2
2
|
|
|
3
3
|
from mat3ra.made.tools.build_components.entities.reusable.base_builder import BaseBuilderParameters, BaseSingleBuilder
|
|
4
4
|
|
|
5
|
-
from ..... import MaterialWithBuildMetadata
|
|
6
5
|
from ......operations.core.unary import strain
|
|
6
|
+
from ..... import MaterialWithBuildMetadata
|
|
7
7
|
from .configuration import StrainConfiguration
|
|
8
8
|
|
|
9
9
|
|
|
@@ -2,20 +2,11 @@ import inspect
|
|
|
2
2
|
from functools import wraps
|
|
3
3
|
from typing import Any, Callable, Dict, Union
|
|
4
4
|
|
|
5
|
+
from mat3ra.made.material import Material
|
|
6
|
+
from mat3ra.made.utils import map_array_to_array_with_id_value, map_array_with_id_value_to_array
|
|
5
7
|
from mat3ra.utils import remove_comments_from_source_code
|
|
6
8
|
from mat3ra.utils.mixins import RoundNumericValuesMixin
|
|
7
9
|
|
|
8
|
-
from mat3ra.made.material import Material
|
|
9
|
-
from mat3ra.made.utils import (
|
|
10
|
-
map_array_to_array_with_id_value,
|
|
11
|
-
map_array_with_id_value_to_array,
|
|
12
|
-
)
|
|
13
|
-
from .utils import (
|
|
14
|
-
extract_labels_from_pymatgen_structure,
|
|
15
|
-
extract_metadata_from_pymatgen_structure,
|
|
16
|
-
extract_tags_from_ase_atoms,
|
|
17
|
-
calculate_padded_cell_simple_cubic,
|
|
18
|
-
)
|
|
19
10
|
from ..third_party import (
|
|
20
11
|
ASEAtoms,
|
|
21
12
|
PymatgenAseAtomsAdaptor,
|
|
@@ -24,6 +15,12 @@ from ..third_party import (
|
|
|
24
15
|
PymatgenPoscar,
|
|
25
16
|
PymatgenStructure,
|
|
26
17
|
)
|
|
18
|
+
from .utils import (
|
|
19
|
+
calculate_padded_cell_simple_cubic,
|
|
20
|
+
extract_labels_from_pymatgen_structure,
|
|
21
|
+
extract_metadata_from_pymatgen_structure,
|
|
22
|
+
extract_tags_from_ase_atoms,
|
|
23
|
+
)
|
|
27
24
|
|
|
28
25
|
|
|
29
26
|
def to_pymatgen(material_or_material_data: Union[Material, Dict[str, Any]]) -> PymatgenStructure:
|
|
@@ -2,11 +2,7 @@ import json
|
|
|
2
2
|
from typing import Any, Dict, List, Union
|
|
3
3
|
|
|
4
4
|
import numpy as np
|
|
5
|
-
from mat3ra.made.
|
|
6
|
-
DEFAULT_NON_PERIODIC_MIN_LATTICE_SIZE,
|
|
7
|
-
DIATOMIC_LATTICE_PADDING_FACTOR,
|
|
8
|
-
MOLECULAR_LATTICE_PADDING_FACTOR,
|
|
9
|
-
)
|
|
5
|
+
from mat3ra.made.data_helper import DATA_DIR
|
|
10
6
|
from mat3ra.made.utils import get_center_of_coordinates, map_array_to_array_with_id_value
|
|
11
7
|
from mat3ra.utils.object import NumpyNDArrayRoundEncoder
|
|
12
8
|
from scipy.spatial.distance import pdist
|
|
@@ -14,6 +10,14 @@ from scipy.spatial.distance import pdist
|
|
|
14
10
|
from ..third_party import ASEAtoms, PymatgenInterface, PymatgenStructure
|
|
15
11
|
from .interface_parts_enum import INTERFACE_LABELS_MAP
|
|
16
12
|
|
|
13
|
+
_CONSTANTS_FILE = DATA_DIR / "constants.json"
|
|
14
|
+
with open(_CONSTANTS_FILE) as _f:
|
|
15
|
+
_CONSTANTS = json.load(_f)
|
|
16
|
+
|
|
17
|
+
DEFAULT_NON_PERIODIC_MIN_LATTICE_SIZE = _CONSTANTS["molecule"]["nonPeriodicMinimumLatticeSize"]
|
|
18
|
+
DIATOMIC_LATTICE_PADDING_FACTOR = _CONSTANTS["molecule"]["diatomicLatticePaddingFactor"]
|
|
19
|
+
MOLECULAR_LATTICE_PADDING_FACTOR = _CONSTANTS["molecule"]["molecularLatticePaddingFactor"]
|
|
20
|
+
|
|
17
21
|
|
|
18
22
|
def _get_non_periodic_lattice_padding_factor(max_distance: float, min_distance: float) -> float:
|
|
19
23
|
if max_distance <= 0:
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import numpy as np
|
|
2
2
|
from mat3ra.esse.models.core.abstract.matrix_3x3 import Matrix3x3Schema
|
|
3
|
-
|
|
4
3
|
from mat3ra.made.material import Material
|
|
5
|
-
|
|
4
|
+
|
|
6
5
|
from ...modify import wrap_to_unit_cell
|
|
6
|
+
from ..core.unary import strain
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
def transform_material_by_matrix(material: Material, matrix: np.ndarray) -> Material:
|
|
@@ -4,6 +4,15 @@ import { AtomicConstraints } from "../../../src/js/constraints/constraints";
|
|
|
4
4
|
import { Material } from "../../../src/js/material";
|
|
5
5
|
import parsers from "../../../src/js/parsers/parsers";
|
|
6
6
|
import { atomsCount } from "../../../src/js/parsers/poscar";
|
|
7
|
+
import {
|
|
8
|
+
atomicConstraints,
|
|
9
|
+
H2OPoscar,
|
|
10
|
+
Na4Cl4,
|
|
11
|
+
Na4Cl4Poscar,
|
|
12
|
+
Silicon,
|
|
13
|
+
Zr1H23Zr1H1,
|
|
14
|
+
Zr1H23Zr1H1Poscar,
|
|
15
|
+
} from "../fixtures";
|
|
7
16
|
|
|
8
17
|
const O2_POSCAR_WITH_COMMENTS = `O2 molecule in a box
|
|
9
18
|
1.0 ! universal scaling parameters
|
|
@@ -16,15 +25,6 @@ cart ! positions in cartesian coordinates
|
|
|
16
25
|
0 0 0 O
|
|
17
26
|
0 0 1.21 O
|
|
18
27
|
`;
|
|
19
|
-
import {
|
|
20
|
-
atomicConstraints,
|
|
21
|
-
H2OPoscar,
|
|
22
|
-
Na4Cl4,
|
|
23
|
-
Na4Cl4Poscar,
|
|
24
|
-
Silicon,
|
|
25
|
-
Zr1H23Zr1H1,
|
|
26
|
-
Zr1H23Zr1H1Poscar,
|
|
27
|
-
} from "../fixtures";
|
|
28
28
|
|
|
29
29
|
describe("Parsers.POSCAR", () => {
|
|
30
30
|
it("should return a valid poscar", () => {
|
|
@@ -0,0 +1,68 @@
|
|
|
1
|
+
"""Tests that shared data files in data/ are accessible after package installation.
|
|
2
|
+
|
|
3
|
+
These tests verify that the JSON files can be found and loaded via the
|
|
4
|
+
path resolution logic used in production code. If they fail, the data
|
|
5
|
+
files are likely missing from the installed package distribution.
|
|
6
|
+
"""
|
|
7
|
+
|
|
8
|
+
import json
|
|
9
|
+
from pathlib import Path
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
def _get_data_dir():
|
|
13
|
+
"""Resolve data/ directory the same way production code does.
|
|
14
|
+
|
|
15
|
+
Production code uses Path(__file__).parents[N] to reach the repo root.
|
|
16
|
+
This test uses the same approach from its own location to verify the
|
|
17
|
+
path resolution works in the installed environment.
|
|
18
|
+
"""
|
|
19
|
+
# tests/py/unit/test_data_files.py -> parents[3] -> repo root
|
|
20
|
+
return Path(__file__).parents[3] / "data"
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
def test_data_dir_exists():
|
|
24
|
+
data_dir = _get_data_dir()
|
|
25
|
+
assert data_dir.exists(), f"data/ directory not found at {data_dir}"
|
|
26
|
+
assert data_dir.is_dir(), f"{data_dir} is not a directory"
|
|
27
|
+
|
|
28
|
+
|
|
29
|
+
def test_data_constants_json_loadable():
|
|
30
|
+
path = _get_data_dir() / "constants.json"
|
|
31
|
+
assert path.exists(), f"constants.json not found at {path}"
|
|
32
|
+
with open(path) as f:
|
|
33
|
+
data = json.load(f)
|
|
34
|
+
assert "molecule" in data, "constants.json missing 'molecule' key"
|
|
35
|
+
assert "precision" in data, "constants.json missing 'precision' key"
|
|
36
|
+
assert data["molecule"]["nonPeriodicMinimumLatticeSize"] == 3.0
|
|
37
|
+
|
|
38
|
+
|
|
39
|
+
def test_data_reciprocal_paths_json_loadable():
|
|
40
|
+
path = _get_data_dir() / "reciprocal_paths.json"
|
|
41
|
+
assert path.exists(), f"reciprocal_paths.json not found at {path}"
|
|
42
|
+
with open(path) as f:
|
|
43
|
+
data = json.load(f)
|
|
44
|
+
assert len(data) == 22, f"Expected 22 path keys, got {len(data)}"
|
|
45
|
+
assert "CUB" in data
|
|
46
|
+
assert "FCC" in data
|
|
47
|
+
assert "TRI" in data
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def test_data_constants_importable_from_production_code():
|
|
51
|
+
"""Verify the actual production import path works."""
|
|
52
|
+
from mat3ra.made.tools.convert.utils import (
|
|
53
|
+
DEFAULT_NON_PERIODIC_MIN_LATTICE_SIZE,
|
|
54
|
+
DIATOMIC_LATTICE_PADDING_FACTOR,
|
|
55
|
+
MOLECULAR_LATTICE_PADDING_FACTOR,
|
|
56
|
+
)
|
|
57
|
+
|
|
58
|
+
assert DEFAULT_NON_PERIODIC_MIN_LATTICE_SIZE == 3.0
|
|
59
|
+
assert DIATOMIC_LATTICE_PADDING_FACTOR == 3.0
|
|
60
|
+
assert MOLECULAR_LATTICE_PADDING_FACTOR == 2.0
|
|
61
|
+
|
|
62
|
+
|
|
63
|
+
def test_data_reciprocal_paths_importable_from_production_code():
|
|
64
|
+
"""Verify the actual production import path works."""
|
|
65
|
+
from mat3ra.made.reciprocal import RECIPROCAL_PATHS
|
|
66
|
+
|
|
67
|
+
assert len(RECIPROCAL_PATHS) == 22
|
|
68
|
+
assert "CUB" in RECIPROCAL_PATHS
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import pytest
|
|
2
|
-
|
|
3
2
|
from mat3ra.code.vector import RoundedVector3D
|
|
4
3
|
from mat3ra.made.lattice import Lattice
|
|
5
4
|
from mat3ra.utils import assertion as assertion_utils
|
|
@@ -69,9 +68,9 @@ def test_lattice_get_scaled_by_matrix():
|
|
|
69
68
|
assert lattice.a == 3.0
|
|
70
69
|
assert lattice.b == 4.5
|
|
71
70
|
assert lattice.c == 2.0
|
|
72
|
-
assert lattice.alpha == 90.0
|
|
73
|
-
assert lattice.beta == 90.0
|
|
74
|
-
assert lattice.gamma == 90.0
|
|
71
|
+
assert lattice.alpha == pytest.approx(90.0)
|
|
72
|
+
assert lattice.beta == pytest.approx(90.0)
|
|
73
|
+
assert lattice.gamma == pytest.approx(90.0)
|
|
75
74
|
assert lattice.units == DEFAULT_UNITS
|
|
76
75
|
assert lattice.type.value == DEFAULT_TYPE
|
|
77
76
|
assertion_utils.assert_deep_almost_equal(lattice.vector_arrays, expected_vector_values)
|
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
"""Tests for Lattice.type_extended property."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from mat3ra.made.lattice import Lattice
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
@pytest.mark.parametrize(
|
|
8
|
+
"lattice_params, expected_type",
|
|
9
|
+
[
|
|
10
|
+
# Simple types return base type
|
|
11
|
+
({"a": 1.0, "b": 1.0, "c": 1.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "CUB"}, "CUB"),
|
|
12
|
+
({"a": 1.0, "b": 1.0, "c": 1.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "FCC"}, "FCC"),
|
|
13
|
+
({"a": 1.0, "b": 1.0, "c": 1.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "BCC"}, "BCC"),
|
|
14
|
+
({"a": 1.0, "b": 1.0, "c": 2.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "TET"}, "TET"),
|
|
15
|
+
({"a": 2.0, "b": 3.0, "c": 4.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "ORC"}, "ORC"),
|
|
16
|
+
({"a": 1.0, "b": 1.0, "c": 2.0, "alpha": 90, "beta": 90, "gamma": 120, "type": "HEX"}, "HEX"),
|
|
17
|
+
# BCT subtypes
|
|
18
|
+
({"a": 2.0, "b": 2.0, "c": 1.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "BCT"}, "BCT-1"), # c < a
|
|
19
|
+
({"a": 1.0, "b": 1.0, "c": 2.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "BCT"}, "BCT-2"), # c >= a
|
|
20
|
+
# ORCF subtypes
|
|
21
|
+
(
|
|
22
|
+
{"a": 3.0, "b": 4.0, "c": 5.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "ORCF"},
|
|
23
|
+
"ORCF-1",
|
|
24
|
+
), # 1/a^2 >= 1/b^2 + 1/c^2 for a=3,b=4,c=5: 1/9≈0.111 vs 1/16+1/25≈0.1025
|
|
25
|
+
(
|
|
26
|
+
{"a": 4.0, "b": 2.0, "c": 3.0, "alpha": 90, "beta": 90, "gamma": 90, "type": "ORCF"},
|
|
27
|
+
"ORCF-2",
|
|
28
|
+
), # 1/a^2 < 1/b^2 + 1/c^2: 1/16=0.0625 < 1/4+1/9=0.361
|
|
29
|
+
# RHL subtypes
|
|
30
|
+
({"a": 1.0, "b": 1.0, "c": 1.0, "alpha": 60, "beta": 60, "gamma": 60, "type": "RHL"}, "RHL-1"), # cos(60)>0
|
|
31
|
+
(
|
|
32
|
+
{"a": 1.0, "b": 1.0, "c": 1.0, "alpha": 120, "beta": 120, "gamma": 120, "type": "RHL"},
|
|
33
|
+
"RHL-2",
|
|
34
|
+
), # cos(120)<0
|
|
35
|
+
# MCLC subtypes
|
|
36
|
+
(
|
|
37
|
+
{"a": 1.0, "b": 2.0, "c": 3.0, "alpha": 80, "beta": 90, "gamma": 95, "type": "MCLC"},
|
|
38
|
+
"MCLC-1",
|
|
39
|
+
), # gamma >= 90
|
|
40
|
+
# TRI subtypes
|
|
41
|
+
(
|
|
42
|
+
{"a": 1.0, "b": 2.0, "c": 3.0, "alpha": 95, "beta": 100, "gamma": 110, "type": "TRI"},
|
|
43
|
+
"TRI_1a",
|
|
44
|
+
), # all > 90
|
|
45
|
+
(
|
|
46
|
+
{"a": 1.0, "b": 2.0, "c": 3.0, "alpha": 80, "beta": 85, "gamma": 75, "type": "TRI"},
|
|
47
|
+
"TRI_1b",
|
|
48
|
+
), # not all > 90
|
|
49
|
+
],
|
|
50
|
+
)
|
|
51
|
+
def test_type_extended(lattice_params, expected_type):
|
|
52
|
+
lattice = Lattice(**lattice_params)
|
|
53
|
+
assert lattice.type_extended == expected_type
|
|
@@ -0,0 +1,86 @@
|
|
|
1
|
+
"""Tests for the ReciprocalLattice class."""
|
|
2
|
+
|
|
3
|
+
from mat3ra.made.reciprocal import ReciprocalLattice
|
|
4
|
+
from mat3ra.utils import assertion as assertion_utils
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def test_reciprocal_lattice_symmetry_points_cub():
|
|
8
|
+
"""CUB lattice should have Г, R, X, M symmetry points."""
|
|
9
|
+
lattice = ReciprocalLattice(a=5.64, b=5.64, c=5.64, type="CUB")
|
|
10
|
+
points = lattice.symmetry_points
|
|
11
|
+
labels = [p["point"] for p in points]
|
|
12
|
+
assert labels == ["Г", "R", "X", "M"]
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
def test_reciprocal_lattice_default_kpoint_path_cub():
|
|
16
|
+
lattice = ReciprocalLattice(a=5.64, b=5.64, c=5.64, type="CUB")
|
|
17
|
+
path = lattice.default_kpoint_path
|
|
18
|
+
labels = [p["point"] for p in path]
|
|
19
|
+
assert labels == ["Г", "X", "M", "Г", "R", "X", "M", "R"]
|
|
20
|
+
|
|
21
|
+
|
|
22
|
+
def test_reciprocal_lattice_default_kpoint_path_bct():
|
|
23
|
+
"""BCT with c < a should use BCT-1 path."""
|
|
24
|
+
lattice = ReciprocalLattice(a=4.0, b=4.0, c=2.0, type="BCT")
|
|
25
|
+
path = lattice.default_kpoint_path
|
|
26
|
+
labels = [p["point"] for p in path]
|
|
27
|
+
assert "Z1" in labels # BCT-1 specific
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
def test_reciprocal_lattice_extract_kpoint_path():
|
|
31
|
+
lattice = ReciprocalLattice(a=5.64, b=5.64, c=5.64, type="CUB")
|
|
32
|
+
data_points = [[0, 0, 0], [0.5, 0.5, 0.5]]
|
|
33
|
+
result = lattice.extract_kpoint_path(data_points)
|
|
34
|
+
assert len(result) == 2
|
|
35
|
+
assert result[0]["point"] == "Г"
|
|
36
|
+
assert result[0]["steps"] == 0
|
|
37
|
+
assert result[1]["point"] == "R"
|
|
38
|
+
assert result[1]["steps"] == 1
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
def test_reciprocal_lattice_extract_kpoint_path_empty():
|
|
42
|
+
lattice = ReciprocalLattice(a=5.64, b=5.64, c=5.64, type="CUB")
|
|
43
|
+
result = lattice.extract_kpoint_path([])
|
|
44
|
+
assert result == []
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
def test_reciprocal_lattice_cartesian_coordinates():
|
|
48
|
+
lattice = ReciprocalLattice(a=5.64, b=5.64, c=5.64, type="CUB")
|
|
49
|
+
cart = lattice.cartesian_coordinates([0.5, 0.5, 0.5])
|
|
50
|
+
assert len(cart) == 3
|
|
51
|
+
assert all(isinstance(c, float) for c in cart)
|
|
52
|
+
|
|
53
|
+
|
|
54
|
+
def test_reciprocal_lattice_dimensions_from_points_count():
|
|
55
|
+
"""Test grid dimension calculation from total k-point count."""
|
|
56
|
+
lattice = ReciprocalLattice(a=2.0, b=3.0, c=4.0, type="ORC")
|
|
57
|
+
dims = lattice.get_dimensions_from_points_count(500)
|
|
58
|
+
assert len(dims) == 3
|
|
59
|
+
assert all(d >= 1 for d in dims)
|
|
60
|
+
# Product should be close to 500
|
|
61
|
+
product = dims[0] * dims[1] * dims[2]
|
|
62
|
+
assert product >= 500 # Should be at least 500 due to ceiling
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
def test_reciprocal_lattice_dimensions_from_spacing():
|
|
66
|
+
lattice = ReciprocalLattice(a=2.0, b=3.0, c=4.0, type="ORC")
|
|
67
|
+
dims = lattice.get_dimensions_from_spacing(0.1)
|
|
68
|
+
assert len(dims) == 3
|
|
69
|
+
assert all(d >= 1 for d in dims)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
def test_reciprocal_lattice_spacing_from_dimensions():
|
|
73
|
+
lattice = ReciprocalLattice(a=2.0, b=3.0, c=4.0, type="ORC")
|
|
74
|
+
dims = [10, 7, 5]
|
|
75
|
+
spacing = lattice.get_spacing_from_dimensions(dims)
|
|
76
|
+
assert isinstance(spacing, float)
|
|
77
|
+
assert spacing > 0
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
def test_reciprocal_lattice_reciprocal_vectors_inherited():
|
|
81
|
+
"""ReciprocalLattice should inherit reciprocal_vectors from Lattice."""
|
|
82
|
+
lattice = ReciprocalLattice(a=2.0, b=3.0, c=4.0, type="ORC")
|
|
83
|
+
vecs = lattice.reciprocal_vectors
|
|
84
|
+
assert len(vecs) == 3
|
|
85
|
+
expected = [[0.5, 0.0, 0.0], [0.0, 1 / 3, 0.0], [0.0, 0.0, 0.25]]
|
|
86
|
+
assertion_utils.assert_deep_almost_equal(vecs, expected)
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"""Tests for reciprocal paths data."""
|
|
2
|
+
|
|
3
|
+
from mat3ra.made.reciprocal import RECIPROCAL_PATHS
|
|
4
|
+
|
|
5
|
+
EXPECTED_KEYS = [
|
|
6
|
+
"CUB",
|
|
7
|
+
"BCC",
|
|
8
|
+
"FCC",
|
|
9
|
+
"TET",
|
|
10
|
+
"BCT-1",
|
|
11
|
+
"BCT-2",
|
|
12
|
+
"ORC",
|
|
13
|
+
"ORCF-1",
|
|
14
|
+
"ORCF-2",
|
|
15
|
+
"ORCF-3",
|
|
16
|
+
"ORCI",
|
|
17
|
+
"ORCC",
|
|
18
|
+
"HEX",
|
|
19
|
+
"RHL-1",
|
|
20
|
+
"RHL-2",
|
|
21
|
+
"MCL",
|
|
22
|
+
"MCLC-1",
|
|
23
|
+
"MCLC-2",
|
|
24
|
+
"MCLC-3",
|
|
25
|
+
"MCLC-4",
|
|
26
|
+
"MCLC-5",
|
|
27
|
+
"TRI",
|
|
28
|
+
]
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_reciprocal_paths_all_keys_present():
|
|
32
|
+
for key in EXPECTED_KEYS:
|
|
33
|
+
assert key in RECIPROCAL_PATHS, f"Missing path key: {key}"
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
def test_reciprocal_paths_count():
|
|
37
|
+
assert len(RECIPROCAL_PATHS) == len(EXPECTED_KEYS)
|
|
38
|
+
|
|
39
|
+
|
|
40
|
+
def test_reciprocal_paths_entry_structure():
|
|
41
|
+
for key, path in RECIPROCAL_PATHS.items():
|
|
42
|
+
assert isinstance(path, list), f"Path {key} should be a list"
|
|
43
|
+
for entry in path:
|
|
44
|
+
assert "point" in entry, f"Entry in {key} missing 'point'"
|
|
45
|
+
assert "steps" in entry, f"Entry in {key} missing 'steps'"
|
|
46
|
+
assert entry["steps"] == 10, f"Entry in {key} should have steps=10"
|
|
47
|
+
|
|
48
|
+
|
|
49
|
+
def test_reciprocal_paths_cub():
|
|
50
|
+
path = RECIPROCAL_PATHS["CUB"]
|
|
51
|
+
labels = [p["point"] for p in path]
|
|
52
|
+
assert labels == ["Г", "X", "M", "Г", "R", "X", "M", "R"]
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def test_reciprocal_paths_fcc():
|
|
56
|
+
path = RECIPROCAL_PATHS["FCC"]
|
|
57
|
+
labels = [p["point"] for p in path]
|
|
58
|
+
assert labels == ["Г", "X", "W", "K", "Г", "L", "U", "W", "L", "U", "X"]
|
|
59
|
+
|
|
60
|
+
|
|
61
|
+
def test_reciprocal_paths_hex():
|
|
62
|
+
path = RECIPROCAL_PATHS["HEX"]
|
|
63
|
+
labels = [p["point"] for p in path]
|
|
64
|
+
assert labels == ["Г", "M", "K", "Г", "A", "L", "H", "A", "L", "M", "K", "H"]
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
"""Tests for Brillouin zone symmetry points."""
|
|
2
|
+
|
|
3
|
+
import pytest
|
|
4
|
+
from mat3ra.made.lattice import Lattice
|
|
5
|
+
from mat3ra.made.reciprocal.symmetry_points import get_symmetry_points
|
|
6
|
+
from mat3ra.utils import assertion as assertion_utils
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def test_symmetry_points_gamma_always_first():
|
|
10
|
+
"""Gamma point should always be the first symmetry point."""
|
|
11
|
+
lattice = Lattice(a=1.0, b=1.0, c=1.0, type="CUB")
|
|
12
|
+
points = get_symmetry_points(lattice)
|
|
13
|
+
assert points[0]["point"] == "Г"
|
|
14
|
+
assert points[0]["coordinates"] == [0.0, 0.0, 0.0]
|
|
15
|
+
|
|
16
|
+
|
|
17
|
+
def test_symmetry_points_cub():
|
|
18
|
+
lattice = Lattice(a=5.64, b=5.64, c=5.64, type="CUB")
|
|
19
|
+
points = get_symmetry_points(lattice)
|
|
20
|
+
labels = [p["point"] for p in points]
|
|
21
|
+
assert labels == ["Г", "R", "X", "M"]
|
|
22
|
+
# Verify specific coordinates
|
|
23
|
+
r_point = next(p for p in points if p["point"] == "R")
|
|
24
|
+
assertion_utils.assert_deep_almost_equal(r_point["coordinates"], [0.5, 0.5, 0.5])
|
|
25
|
+
x_point = next(p for p in points if p["point"] == "X")
|
|
26
|
+
assertion_utils.assert_deep_almost_equal(x_point["coordinates"], [0.0, 0.5, 0.0])
|
|
27
|
+
m_point = next(p for p in points if p["point"] == "M")
|
|
28
|
+
assertion_utils.assert_deep_almost_equal(m_point["coordinates"], [0.5, 0.5, 0.0])
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
def test_symmetry_points_fcc():
|
|
32
|
+
lattice = Lattice(a=5.43, b=5.43, c=5.43, type="FCC")
|
|
33
|
+
points = get_symmetry_points(lattice)
|
|
34
|
+
labels = [p["point"] for p in points]
|
|
35
|
+
assert "K" in labels
|
|
36
|
+
assert "L" in labels
|
|
37
|
+
assert "U" in labels
|
|
38
|
+
assert "W" in labels
|
|
39
|
+
assert "X" in labels
|
|
40
|
+
k_point = next(p for p in points if p["point"] == "K")
|
|
41
|
+
assertion_utils.assert_deep_almost_equal(k_point["coordinates"], [3 / 8, 3 / 8, 3 / 4])
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
def test_symmetry_points_bcc():
|
|
45
|
+
lattice = Lattice(a=3.0, b=3.0, c=3.0, type="BCC")
|
|
46
|
+
points = get_symmetry_points(lattice)
|
|
47
|
+
labels = [p["point"] for p in points]
|
|
48
|
+
assert labels == ["Г", "H", "P", "N"]
|
|
49
|
+
h_point = next(p for p in points if p["point"] == "H")
|
|
50
|
+
assertion_utils.assert_deep_almost_equal(h_point["coordinates"], [0.5, -0.5, 0.5])
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def test_symmetry_points_hex():
|
|
54
|
+
lattice = Lattice(a=2.46, b=2.46, c=6.71, type="HEX")
|
|
55
|
+
points = get_symmetry_points(lattice)
|
|
56
|
+
labels = [p["point"] for p in points]
|
|
57
|
+
assert set(labels) == {"Г", "A", "H", "K", "L", "M"}
|
|
58
|
+
k_point = next(p for p in points if p["point"] == "K")
|
|
59
|
+
assertion_utils.assert_deep_almost_equal(k_point["coordinates"], [1 / 3, 1 / 3, 0.0])
|
|
60
|
+
|
|
61
|
+
|
|
62
|
+
def test_symmetry_points_bct1():
|
|
63
|
+
"""BCT with c < a should give BCT-1 points."""
|
|
64
|
+
lattice = Lattice(a=4.0, b=4.0, c=2.0, type="BCT")
|
|
65
|
+
points = get_symmetry_points(lattice)
|
|
66
|
+
labels = [p["point"] for p in points]
|
|
67
|
+
assert "Z" in labels
|
|
68
|
+
assert "Z1" in labels
|
|
69
|
+
# BCT-1: n = (1 + c²/a²) / 4 = (1 + 4/16) / 4 = 1.25/4 = 0.3125
|
|
70
|
+
z_point = next(p for p in points if p["point"] == "Z")
|
|
71
|
+
n = (1 + 4.0 / 16.0) / 4
|
|
72
|
+
assertion_utils.assert_deep_almost_equal(z_point["coordinates"], [n, n, -n])
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def test_symmetry_points_bct2():
|
|
76
|
+
"""BCT with c >= a should give BCT-2 points."""
|
|
77
|
+
lattice = Lattice(a=2.0, b=2.0, c=4.0, type="BCT")
|
|
78
|
+
points = get_symmetry_points(lattice)
|
|
79
|
+
labels = [p["point"] for p in points]
|
|
80
|
+
assert "∑" in labels
|
|
81
|
+
assert "Y" in labels
|
|
82
|
+
assert "Z" not in [p["point"] for p in points if p["point"] == "Z1"]
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
def test_symmetry_points_tet():
|
|
86
|
+
lattice = Lattice(a=3.0, b=3.0, c=5.0, type="TET")
|
|
87
|
+
points = get_symmetry_points(lattice)
|
|
88
|
+
labels = [p["point"] for p in points]
|
|
89
|
+
assert set(labels) == {"Г", "A", "M", "R", "X", "Z"}
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def test_symmetry_points_orc():
|
|
93
|
+
lattice = Lattice(a=2.0, b=3.0, c=4.0, type="ORC")
|
|
94
|
+
points = get_symmetry_points(lattice)
|
|
95
|
+
labels = [p["point"] for p in points]
|
|
96
|
+
assert set(labels) == {"Г", "R", "S", "T", "U", "X", "Y", "Z"}
|
|
97
|
+
|
|
98
|
+
|
|
99
|
+
def test_symmetry_points_rhl1():
|
|
100
|
+
"""RHL with cos(alpha) > 0 should give RHL-1 points."""
|
|
101
|
+
lattice = Lattice(a=3.0, b=3.0, c=3.0, alpha=60.0, beta=60.0, gamma=60.0, type="RHL")
|
|
102
|
+
points = get_symmetry_points(lattice)
|
|
103
|
+
labels = [p["point"] for p in points]
|
|
104
|
+
assert "B" in labels
|
|
105
|
+
assert "B1" in labels
|
|
106
|
+
assert "F" in labels
|
|
107
|
+
|
|
108
|
+
|
|
109
|
+
def test_symmetry_points_rhl2():
|
|
110
|
+
"""RHL with cos(alpha) < 0 should give RHL-2 points."""
|
|
111
|
+
lattice = Lattice(a=3.0, b=3.0, c=3.0, alpha=120.0, beta=120.0, gamma=120.0, type="RHL")
|
|
112
|
+
points = get_symmetry_points(lattice)
|
|
113
|
+
labels = [p["point"] for p in points]
|
|
114
|
+
assert "Q" in labels
|
|
115
|
+
assert "Q1" in labels
|
|
116
|
+
# RHL-2 should NOT have B, B1 points
|
|
117
|
+
assert "B" not in labels
|
|
118
|
+
|
|
119
|
+
|
|
120
|
+
def test_symmetry_points_tri_1a():
|
|
121
|
+
"""TRI with alpha, beta > 90 and gamma >= 90."""
|
|
122
|
+
lattice = Lattice(a=1.0, b=2.0, c=3.0, alpha=95.0, beta=100.0, gamma=110.0, type="TRI")
|
|
123
|
+
points = get_symmetry_points(lattice)
|
|
124
|
+
# TRI-1a,2a: L at [1/2, 1/2, 0]
|
|
125
|
+
l_point = next(p for p in points if p["point"] == "L")
|
|
126
|
+
assertion_utils.assert_deep_almost_equal(l_point["coordinates"], [0.5, 0.5, 0.0])
|
|
127
|
+
|
|
128
|
+
|
|
129
|
+
def test_symmetry_points_tri_1b():
|
|
130
|
+
"""TRI without all angles > 90."""
|
|
131
|
+
lattice = Lattice(a=1.0, b=2.0, c=3.0, alpha=80.0, beta=85.0, gamma=75.0, type="TRI")
|
|
132
|
+
points = get_symmetry_points(lattice)
|
|
133
|
+
# TRI-1b,2b: L at [1/2, -1/2, 0]
|
|
134
|
+
l_point = next(p for p in points if p["point"] == "L")
|
|
135
|
+
assertion_utils.assert_deep_almost_equal(l_point["coordinates"], [0.5, -0.5, 0.0])
|
|
136
|
+
|
|
137
|
+
|
|
138
|
+
@pytest.mark.parametrize(
|
|
139
|
+
"lattice_type",
|
|
140
|
+
["CUB", "FCC", "BCC", "TET", "BCT", "ORC", "ORCF", "ORCI", "ORCC", "HEX", "RHL", "MCL", "MCLC", "TRI"],
|
|
141
|
+
)
|
|
142
|
+
def test_symmetry_points_all_lattice_types(lattice_type):
|
|
143
|
+
"""Every supported lattice type should return at least the Gamma point."""
|
|
144
|
+
lattice = Lattice(a=3.0, b=4.0, c=5.0, alpha=80.0, beta=85.0, gamma=75.0, type=lattice_type)
|
|
145
|
+
points = get_symmetry_points(lattice)
|
|
146
|
+
assert len(points) >= 1
|
|
147
|
+
assert points[0]["point"] == "Г"
|
|
148
|
+
# All coordinates should be lists of 3 floats
|
|
149
|
+
for p in points:
|
|
150
|
+
assert len(p["coordinates"]) == 3
|
|
151
|
+
assert all(isinstance(c, (int, float)) for c in p["coordinates"])
|
|
@@ -117,7 +117,13 @@ def test_crystal_site_analyzer(placement_method, coordinate, expected_coordinate
|
|
|
117
117
|
else:
|
|
118
118
|
raise ValueError(f"Unknown method: {placement_method}")
|
|
119
119
|
|
|
120
|
-
|
|
120
|
+
if placement_method == AtomPlacementMethodEnum.VORONOI_SITE:
|
|
121
|
+
allowed_coords = [[0.625, 0.625, 0.125], [0.625, 0.625, 0.625], [0.5, 0.5, 0.5]]
|
|
122
|
+
assert any(
|
|
123
|
+
np.allclose(final_coordinate, allowed, atol=COMPARISON_PRECISION) for allowed in allowed_coords
|
|
124
|
+
), f"Voronoi coordinate {final_coordinate} not in allowed list"
|
|
125
|
+
else:
|
|
126
|
+
assert np.allclose(final_coordinate, expected_coordinate, atol=COMPARISON_PRECISION)
|
|
121
127
|
|
|
122
128
|
|
|
123
129
|
@pytest.mark.parametrize(
|