2
2
3
3
from copy import deepcopy
4
4
from enum import Enum
5
- from typing import Optional
6
5
7
6
import numpy as np
8
7
from emmet .core .math import Matrix3D , MatrixVoigt
21
20
from typing_extensions import Self
22
21
23
22
from atomate2 import SETTINGS
23
+ from atomate2 .common .utils import _recursive_to_list
24
24
25
25
26
26
class DerivedProperties (BaseModel ):
27
27
"""Properties derived from an elastic tensor."""
28
28
29
- k_voigt : Optional [ float ] = Field (
29
+ k_voigt : float | None = Field (
30
30
None , description = "Voigt average of the bulk modulus."
31
31
)
32
- k_reuss : Optional [ float ] = Field (
32
+ k_reuss : float | None = Field (
33
33
None , description = "Reuss average of the bulk modulus."
34
34
)
35
- k_vrh : Optional [ float ] = Field (
35
+ k_vrh : float | None = Field (
36
36
None , description = "Voigt-Reuss-Hill average of the bulk modulus."
37
37
)
38
- g_voigt : Optional [ float ] = Field (
38
+ g_voigt : float | None = Field (
39
39
None , description = "Voigt average of the shear modulus."
40
40
)
41
- g_reuss : Optional [ float ] = Field (
41
+ g_reuss : float | None = Field (
42
42
None , description = "Reuss average of the shear modulus."
43
43
)
44
- g_vrh : Optional [ float ] = Field (
44
+ g_vrh : float | None = Field (
45
45
None , description = "Voigt-Reuss-Hill average of the shear modulus."
46
46
)
47
- universal_anisotropy : Optional [ float ] = Field (
47
+ universal_anisotropy : float | None = Field (
48
48
None , description = "Universal elastic anisotropy."
49
49
)
50
- homogeneous_poisson : Optional [ float ] = Field (
50
+ homogeneous_poisson : float | None = Field (
51
51
None , description = "Homogeneous poisson ratio."
52
52
)
53
- y_mod : Optional [ float ] = Field (
53
+ y_mod : float | None = Field (
54
54
None ,
55
55
description = "Young's modulus (SI units) from the Voight-Reuss-Hill averages of "
56
56
"the bulk and shear moduli." ,
57
57
)
58
- trans_v : Optional [ float ] = Field (
58
+ trans_v : float | None = Field (
59
59
None ,
60
60
description = "Transverse sound velocity (SI units) obtained from the "
61
61
"Voigt-Reuss-Hill average bulk modulus." ,
62
62
)
63
- long_v : Optional [ float ] = Field (
63
+ long_v : float | None = Field (
64
64
None ,
65
65
description = "Longitudinal sound velocity (SI units) obtained from the "
66
66
"Voigt-Reuss-Hill average bulk modulus." ,
67
67
)
68
- snyder_ac : Optional [ float ] = Field (
68
+ snyder_ac : float | None = Field (
69
69
None , description = "Synder's acoustic sound velocity (SI units)."
70
70
)
71
- snyder_opt : Optional [ float ] = Field (
71
+ snyder_opt : float | None = Field (
72
72
None , description = "Synder's optical sound velocity (SI units)."
73
73
)
74
- snyder_total : Optional [ float ] = Field (
74
+ snyder_total : float | None = Field (
75
75
None , description = "Synder's total sound velocity (SI units)."
76
76
)
77
- clark_thermalcond : Optional [ float ] = Field (
77
+ clark_thermalcond : float | None = Field (
78
78
None , description = "Clarke's thermal conductivity (SI units)."
79
79
)
80
- cahill_thermalcond : Optional [ float ] = Field (
80
+ cahill_thermalcond : float | None = Field (
81
81
None , description = "Cahill's thermal conductivity (SI units)."
82
82
)
83
- debye_temperature : Optional [ float ] = Field (
83
+ debye_temperature : float | None = Field (
84
84
None ,
85
85
description = "Debye temperature from longitudinal and transverse sound "
86
86
"velocities (SI units)." ,
@@ -90,34 +90,34 @@ class DerivedProperties(BaseModel):
90
90
class FittingData (BaseModel ):
91
91
"""Data used to fit elastic tensors."""
92
92
93
- cauchy_stresses : Optional [ list [Matrix3D ]] = Field (
93
+ cauchy_stresses : list [Matrix3D ] | None = Field (
94
94
None , description = "The Cauchy stresses used to fit the elastic tensor."
95
95
)
96
- strains : Optional [ list [Matrix3D ]] = Field (
96
+ strains : list [Matrix3D ] | None = Field (
97
97
None , description = "The strains used to fit the elastic tensor."
98
98
)
99
- pk_stresses : Optional [ list [Matrix3D ]] = Field (
99
+ pk_stresses : list [Matrix3D ] | None = Field (
100
100
None , description = "The Piola-Kirchoff stresses used to fit the elastic tensor."
101
101
)
102
- deformations : Optional [ list [Matrix3D ]] = Field (
102
+ deformations : list [Matrix3D ] | None = Field (
103
103
None , description = "The deformations corresponding to each strain state."
104
104
)
105
- uuids : Optional [ list [str ]] = Field (
105
+ uuids : list [str ] | None = Field (
106
106
None , description = "The uuids of the deformation jobs."
107
107
)
108
- job_dirs : Optional [ list [Optional [ str ]]] = Field (
108
+ job_dirs : list [str | None ] | None = Field (
109
109
None , description = "The directories where the deformation jobs were run."
110
110
)
111
- failed_uuids : Optional [ list [str ]] = Field (
111
+ failed_uuids : list [str ] | None = Field (
112
112
None , description = "The uuids of perturbations that were not completed"
113
113
)
114
114
115
115
116
116
class ElasticTensorDocument (BaseModel ):
117
117
"""Raw and standardized elastic tensors."""
118
118
119
- raw : Optional [ MatrixVoigt ] = Field (None , description = "Raw elastic tensor." )
120
- ieee_format : Optional [ MatrixVoigt ] = Field (
119
+ raw : MatrixVoigt | list | None = Field (None , description = "Raw elastic tensor." )
120
+ ieee_format : MatrixVoigt | list | None = Field (
121
121
None , description = "Elastic tensor in IEEE format."
122
122
)
123
123
@@ -131,28 +131,28 @@ class ElasticWarnings(Enum):
131
131
class ElasticDocument (StructureMetadata ):
132
132
"""Document containing elastic tensor information and related properties."""
133
133
134
- structure : Optional [ Structure ] = Field (
134
+ structure : Structure | None = Field (
135
135
None , description = "The structure for which the elastic data is calculated."
136
136
)
137
- elastic_tensor : Optional [ ElasticTensorDocument ] = Field (
137
+ elastic_tensor : ElasticTensorDocument | None = Field (
138
138
None , description = "Fitted elastic tensor."
139
139
)
140
- eq_stress : Optional [ Matrix3D ] = Field (
140
+ eq_stress : Matrix3D | None = Field (
141
141
None , description = "The equilibrium stress of the structure."
142
142
)
143
- derived_properties : Optional [ DerivedProperties ] = Field (
143
+ derived_properties : DerivedProperties | None = Field (
144
144
None , description = "Properties derived from the elastic tensor."
145
145
)
146
- fitting_data : Optional [ FittingData ] = Field (
146
+ fitting_data : FittingData | None = Field (
147
147
None , description = "Data used to fit the elastic tensor."
148
148
)
149
- fitting_method : Optional [ str ] = Field (
149
+ fitting_method : str | None = Field (
150
150
None , description = "Method used to fit the elastic tensor."
151
151
)
152
- order : Optional [ int ] = Field (
152
+ order : int | None = Field (
153
153
None , description = "Order of the expansion of the elastic tensor."
154
154
)
155
- warnings : Optional [ list [str ]] = Field (None , description = "Warnings." )
155
+ warnings : list [str ] | None = Field (None , description = "Warnings." )
156
156
157
157
@classmethod
158
158
def from_stresses (
@@ -163,8 +163,8 @@ def from_stresses(
163
163
uuids : list [str ],
164
164
job_dirs : list [str ],
165
165
fitting_method : str = SETTINGS .ELASTIC_FITTING_METHOD ,
166
- order : Optional [ int ] = None ,
167
- equilibrium_stress : Optional [ Matrix3D ] = None ,
166
+ order : int | None = None ,
167
+ equilibrium_stress : Matrix3D | None = None ,
168
168
symprec : float = SETTINGS .SYMPREC ,
169
169
allow_elastically_unstable_structs : bool = True ,
170
170
failed_uuids : list [str ] = None ,
@@ -264,7 +264,8 @@ def from_stresses(
264
264
fitting_method = fitting_method ,
265
265
order = order ,
266
266
elastic_tensor = ElasticTensorDocument (
267
- raw = result .voigt .tolist (), ieee_format = ieee .voigt .tolist ()
267
+ raw = _recursive_to_list (result .voigt ),
268
+ ieee_format = _recursive_to_list (ieee .voigt ),
268
269
),
269
270
fitting_data = FittingData (
270
271
cauchy_stresses = [s .tolist () for s in stresses ],
0 commit comments