@mat3ra/made 2026.3.3-0 → 2026.4.1-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/package.json +1 -1
- package/src/py/mat3ra/made/material.py +3 -1
- package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/strain/__init__.py +5 -0
- package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/strain/builder.py +17 -0
- package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/strain/configuration.py +13 -0
- package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/strain/helpers.py +30 -0
- package/tests/py/unit/test_tools_build_strain.py +26 -0
- package/src/py/mat3ra/made/tools/build_components/entities/reusable/three_dimensional/strained_non_uniform.py +0 -0
- package/src/py/mat3ra/made/tools/build_components/entities/reusable/three_dimensional/strained_uniform.py +0 -0
package/package.json
CHANGED
|
@@ -4,7 +4,7 @@ from typing import Any, List, Optional, Union
|
|
|
4
4
|
from mat3ra.code.constants import AtomicCoordinateUnits, Units
|
|
5
5
|
from mat3ra.code.entity import HasDescriptionHasMetadataNamedDefaultableInMemoryEntityPydantic
|
|
6
6
|
from mat3ra.esse.models.material import MaterialSchema
|
|
7
|
-
from pydantic import SkipValidation
|
|
7
|
+
from pydantic import ConfigDict, SkipValidation
|
|
8
8
|
|
|
9
9
|
from .basis import Basis
|
|
10
10
|
from .lattice import Lattice
|
|
@@ -54,6 +54,8 @@ defaultMaterialConfig = {
|
|
|
54
54
|
|
|
55
55
|
# TODO: replace `-Pydantic` with actual class in the next PR
|
|
56
56
|
class Material(MaterialSchema, HasDescriptionHasMetadataNamedDefaultableInMemoryEntityPydantic):
|
|
57
|
+
model_config = ConfigDict(arbitrary_types_allowed=True, populate_by_name=True)
|
|
58
|
+
|
|
57
59
|
__default_config__ = defaultMaterialConfig
|
|
58
60
|
__schema__ = MaterialSchema
|
|
59
61
|
|
package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/strain/builder.py
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
from typing import Type
|
|
2
|
+
|
|
3
|
+
from mat3ra.made.tools.build_components.entities.reusable.base_builder import BaseBuilderParameters, BaseSingleBuilder
|
|
4
|
+
|
|
5
|
+
from ..... import MaterialWithBuildMetadata
|
|
6
|
+
from ......operations.core.unary import strain
|
|
7
|
+
from .configuration import StrainConfiguration
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class StrainBuilder(BaseSingleBuilder):
|
|
11
|
+
_ConfigurationType: Type[StrainConfiguration] = StrainConfiguration
|
|
12
|
+
_BuildParametersType: Type[BaseBuilderParameters] = BaseBuilderParameters
|
|
13
|
+
_DefaultBuildParameters: BaseBuilderParameters = BaseBuilderParameters()
|
|
14
|
+
|
|
15
|
+
def _generate(self, configuration: StrainConfiguration) -> MaterialWithBuildMetadata:
|
|
16
|
+
strained_material = strain(configuration.material, configuration.strain_matrix)
|
|
17
|
+
return MaterialWithBuildMetadata.create(strained_material.to_dict())
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from mat3ra.esse.models.core.abstract.matrix_3x3 import Matrix3x3Schema
|
|
4
|
+
from mat3ra.made.material import Material
|
|
5
|
+
from mat3ra.made.tools.build_components.entities.reusable.base_builder import BaseConfigurationPydantic
|
|
6
|
+
|
|
7
|
+
from ..... import MaterialWithBuildMetadata
|
|
8
|
+
|
|
9
|
+
|
|
10
|
+
class StrainConfiguration(BaseConfigurationPydantic):
|
|
11
|
+
type: str = "StrainConfiguration"
|
|
12
|
+
material: Union[Material, MaterialWithBuildMetadata]
|
|
13
|
+
strain_matrix: Matrix3x3Schema
|
package/src/py/mat3ra/made/tools/build_components/operations/core/modifications/strain/helpers.py
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
from typing import Union
|
|
2
|
+
|
|
3
|
+
from mat3ra.esse.models.core.abstract.matrix_3x3 import Matrix3x3Schema
|
|
4
|
+
from mat3ra.made.material import Material
|
|
5
|
+
|
|
6
|
+
from ..... import MaterialWithBuildMetadata
|
|
7
|
+
from .builder import StrainBuilder
|
|
8
|
+
from .configuration import StrainConfiguration
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
def get_isotropic_strain_matrix(scale_factor: float) -> Matrix3x3Schema:
|
|
12
|
+
"""
|
|
13
|
+
Returns a 3x3 isotropic strain matrix for uniform lattice scaling.
|
|
14
|
+
"""
|
|
15
|
+
return Matrix3x3Schema(
|
|
16
|
+
root=[
|
|
17
|
+
[scale_factor, 0.0, 0.0],
|
|
18
|
+
[0.0, scale_factor, 0.0],
|
|
19
|
+
[0.0, 0.0, scale_factor],
|
|
20
|
+
]
|
|
21
|
+
)
|
|
22
|
+
|
|
23
|
+
|
|
24
|
+
def create_strain(
|
|
25
|
+
material: Union[Material, MaterialWithBuildMetadata],
|
|
26
|
+
strain_matrix: Matrix3x3Schema,
|
|
27
|
+
) -> MaterialWithBuildMetadata:
|
|
28
|
+
configuration = StrainConfiguration(material=material, strain_matrix=strain_matrix)
|
|
29
|
+
builder = StrainBuilder()
|
|
30
|
+
return builder.get_material(configuration)
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import pytest
|
|
2
|
+
from mat3ra.esse.models.core.abstract.matrix_3x3 import Matrix3x3Schema
|
|
3
|
+
from mat3ra.made.material import Material
|
|
4
|
+
from mat3ra.made.tools.build_components.operations.core.modifications.strain.helpers import create_strain
|
|
5
|
+
from unit.fixtures.strain import BULK_Si_CONVENTIONAL_STRAINED
|
|
6
|
+
from unit.utils import assert_two_entities_deep_almost_equal
|
|
7
|
+
|
|
8
|
+
from .fixtures.bulk import BULK_Si_CONVENTIONAL
|
|
9
|
+
|
|
10
|
+
|
|
11
|
+
@pytest.mark.parametrize(
|
|
12
|
+
"material_config, strain_matrix, expected_material_config",
|
|
13
|
+
[
|
|
14
|
+
(BULK_Si_CONVENTIONAL, [[1.1, 0, 0], [0, 1.1, 0], [0, 0, 1.0]], BULK_Si_CONVENTIONAL_STRAINED),
|
|
15
|
+
],
|
|
16
|
+
)
|
|
17
|
+
def test_create_strain(material_config, strain_matrix, expected_material_config):
|
|
18
|
+
material = Material.create(material_config)
|
|
19
|
+
strained_material = create_strain(material, Matrix3x3Schema(root=strain_matrix))
|
|
20
|
+
|
|
21
|
+
assert_two_entities_deep_almost_equal(strained_material, expected_material_config)
|
|
22
|
+
|
|
23
|
+
build_step = strained_material.metadata.build[-1]
|
|
24
|
+
assert build_step.configuration["type"] == "StrainConfiguration"
|
|
25
|
+
assert build_step.configuration["strain_matrix"] == strain_matrix
|
|
26
|
+
assert build_step.build_parameters == {}
|
|
File without changes
|
|
File without changes
|