Skip to content

Commit 3ba5b89

Browse files
authored
Merge branch 'main' into phonon_dis
2 parents 7d546ee + 053d0f2 commit 3ba5b89

File tree

15 files changed

+416
-316
lines changed

15 files changed

+416
-316
lines changed

atomistics/workflows/elastic/elastic_moduli.py

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -12,27 +12,27 @@ def get_bulkmodul_voigt(elastic_matrix: np.ndarray) -> float:
1212
) / 9
1313

1414

15-
def get_shearmodul_voigt(elastic_matrix):
15+
def get_shearmodul_voigt(elastic_matrix: np.ndarray) -> float:
1616
return (
1717
(elastic_matrix[0, 0] + elastic_matrix[1, 1] + elastic_matrix[2, 2])
1818
- (elastic_matrix[0, 1] + elastic_matrix[0, 2] + elastic_matrix[1, 2])
1919
+ 3 * (elastic_matrix[3, 3] + elastic_matrix[4, 4] + elastic_matrix[5, 5])
2020
) / 15
2121

2222

23-
def get_youngsmodul_voigt(bulkmodul_voigt, shearmodul_voigt):
23+
def get_youngsmodul_voigt(bulkmodul_voigt: float, shearmodul_voigt: float) -> float:
2424
return (9 * bulkmodul_voigt * shearmodul_voigt) / (
2525
3 * bulkmodul_voigt + shearmodul_voigt
2626
)
2727

2828

29-
def get_poissonsratio_voigt(bulkmodul_voigt, shearmodul_voigt):
29+
def get_poissonsratio_voigt(bulkmodul_voigt: float, shearmodul_voigt: float) -> float:
3030
return (1.5 * bulkmodul_voigt - shearmodul_voigt) / (
3131
3 * bulkmodul_voigt + shearmodul_voigt
3232
)
3333

3434

35-
def get_bulkmodul_reuss(elastic_matrix_inverse):
35+
def get_bulkmodul_reuss(elastic_matrix_inverse: np.ndarray) -> float:
3636
return 1 / (
3737
elastic_matrix_inverse[0, 0]
3838
+ elastic_matrix_inverse[1, 1]
@@ -46,7 +46,7 @@ def get_bulkmodul_reuss(elastic_matrix_inverse):
4646
)
4747

4848

49-
def get_shearmodul_reuss(elastic_matrix_inverse):
49+
def get_shearmodul_reuss(elastic_matrix_inverse: np.ndarray) -> float:
5050
return 15 / (
5151
4
5252
* (
@@ -69,143 +69,143 @@ def get_shearmodul_reuss(elastic_matrix_inverse):
6969
)
7070

7171

72-
def get_youngsmodul_reuss(bulkmodul_reuss, shearmodul_reuss):
72+
def get_youngsmodul_reuss(bulkmodul_reuss: float, shearmodul_reuss: float) -> float:
7373
return (9 * bulkmodul_reuss * shearmodul_reuss) / (
7474
3 * bulkmodul_reuss + shearmodul_reuss
7575
)
7676

7777

78-
def get_poissonsratio_reuss(bulkmodul_reuss, shearmodul_reuss):
78+
def get_poissonsratio_reuss(bulkmodul_reuss: float, shearmodul_reuss: float) -> float:
7979
return (1.5 * bulkmodul_reuss - shearmodul_reuss) / (
8080
3 * bulkmodul_reuss + shearmodul_reuss
8181
)
8282

8383

84-
def get_bulkmodul_hill(bulkmodul_voigt, bulkmodul_reuss):
84+
def get_bulkmodul_hill(bulkmodul_voigt: float, bulkmodul_reuss: float) -> float:
8585
return _hill_approximation(voigt=bulkmodul_voigt, reuss=bulkmodul_reuss)
8686

8787

88-
def get_shearmodul_hill(shearmodul_voigt, shearmodul_reuss):
88+
def get_shearmodul_hill(shearmodul_voigt: float, shearmodul_reuss: float) -> float:
8989
return _hill_approximation(voigt=shearmodul_voigt, reuss=shearmodul_reuss)
9090

9191

92-
def get_youngsmodul_hill(bulkmodul_hill, shearmodul_hill):
92+
def get_youngsmodul_hill(bulkmodul_hill: float, shearmodul_hill: float) -> float:
9393
return (9.0 * bulkmodul_hill * shearmodul_hill) / (
9494
3.0 * bulkmodul_hill + shearmodul_hill
9595
)
9696

9797

98-
def get_poissonsratio_hill(bulkmodul_hill, shearmodul_hill):
98+
def get_poissonsratio_hill(bulkmodul_hill: float, shearmodul_hill: float) -> float:
9999
return (1.5 * bulkmodul_hill - shearmodul_hill) / (
100100
3.0 * bulkmodul_hill + shearmodul_hill
101101
)
102102

103103

104-
def get_AVR(shearmodul_voigt, shearmodul_reuss):
104+
def get_AVR(shearmodul_voigt: float, shearmodul_reuss: float) -> float:
105105
return (
106106
100.0
107107
* (shearmodul_voigt - shearmodul_reuss)
108108
/ (shearmodul_voigt + shearmodul_reuss)
109109
)
110110

111111

112-
def get_elastic_matrix_eigval(elastic_matrix):
112+
def get_elastic_matrix_eigval(elastic_matrix: np.ndarray):
113113
return np.linalg.eig(elastic_matrix)
114114

115115

116-
def get_elastic_matrix_inverse(elastic_matrix):
116+
def get_elastic_matrix_inverse(elastic_matrix: np.ndarray) -> np.ndarray:
117117
return np.linalg.inv(elastic_matrix)
118118

119119

120-
def _hill_approximation(voigt, reuss):
120+
def _hill_approximation(voigt: float, reuss: float) -> float:
121121
return 0.50 * (voigt + reuss)
122122

123123

124124
class ElasticProperties:
125125
def __init__(self, elastic_matrix):
126126
self._elastic_matrix = elastic_matrix
127127

128-
def elastic_matrix(self):
128+
def elastic_matrix(self) -> np.ndarray:
129129
return self._elastic_matrix
130130

131131
@cache
132-
def elastic_matrix_inverse(self):
132+
def elastic_matrix_inverse(self) -> np.ndarray:
133133
return get_elastic_matrix_inverse(elastic_matrix=self.elastic_matrix())
134134

135135
@cache
136-
def bulkmodul_voigt(self):
136+
def bulkmodul_voigt(self) -> float:
137137
return get_bulkmodul_voigt(elastic_matrix=self.elastic_matrix())
138138

139139
@cache
140-
def shearmodul_voigt(self):
140+
def shearmodul_voigt(self) -> float:
141141
return get_shearmodul_voigt(elastic_matrix=self.elastic_matrix())
142142

143143
@cache
144-
def bulkmodul_reuss(self):
144+
def bulkmodul_reuss(self) -> float:
145145
return get_bulkmodul_reuss(elastic_matrix_inverse=self.elastic_matrix_inverse())
146146

147147
@cache
148-
def shearmodul_reuss(self):
148+
def shearmodul_reuss(self) -> float:
149149
return get_shearmodul_reuss(
150150
elastic_matrix_inverse=self.elastic_matrix_inverse()
151151
)
152152

153153
@cache
154-
def bulkmodul_hill(self):
154+
def bulkmodul_hill(self) -> float:
155155
return get_bulkmodul_hill(
156156
bulkmodul_voigt=self.bulkmodul_voigt(),
157157
bulkmodul_reuss=self.bulkmodul_reuss(),
158158
)
159159

160160
@cache
161-
def shearmodul_hill(self):
161+
def shearmodul_hill(self) -> float:
162162
return get_shearmodul_hill(
163163
shearmodul_voigt=self.shearmodul_voigt(),
164164
shearmodul_reuss=self.shearmodul_reuss(),
165165
)
166166

167167
@cache
168-
def youngsmodul_voigt(self):
168+
def youngsmodul_voigt(self) -> float:
169169
return get_youngsmodul_voigt(
170170
bulkmodul_voigt=self.bulkmodul_voigt(),
171171
shearmodul_voigt=self.shearmodul_voigt(),
172172
)
173173

174174
@cache
175-
def poissonsratio_voigt(self):
175+
def poissonsratio_voigt(self) -> float:
176176
return get_poissonsratio_voigt(
177177
bulkmodul_voigt=self.bulkmodul_voigt(),
178178
shearmodul_voigt=self.shearmodul_voigt(),
179179
)
180180

181181
@cache
182-
def youngsmodul_reuss(self):
182+
def youngsmodul_reuss(self) -> float:
183183
return get_youngsmodul_reuss(
184184
bulkmodul_reuss=self.bulkmodul_reuss(),
185185
shearmodul_reuss=self.shearmodul_reuss(),
186186
)
187187

188188
@cache
189-
def poissonsratio_reuss(self):
189+
def poissonsratio_reuss(self) -> float:
190190
return get_poissonsratio_reuss(
191191
bulkmodul_reuss=self.bulkmodul_reuss(),
192192
shearmodul_reuss=self.shearmodul_reuss(),
193193
)
194194

195195
@cache
196-
def youngsmodul_hill(self):
196+
def youngsmodul_hill(self) -> float:
197197
return get_youngsmodul_hill(
198198
bulkmodul_hill=self.bulkmodul_hill(), shearmodul_hill=self.shearmodul_hill()
199199
)
200200

201201
@cache
202-
def poissonsratio_hill(self):
202+
def poissonsratio_hill(self) -> float:
203203
return get_poissonsratio_hill(
204204
bulkmodul_hill=self.bulkmodul_hill(), shearmodul_hill=self.shearmodul_hill()
205205
)
206206

207207
@cache
208-
def AVR(self):
208+
def AVR(self) -> float:
209209
return get_AVR(
210210
shearmodul_voigt=self.shearmodul_voigt(),
211211
shearmodul_reuss=self.shearmodul_reuss(),

atomistics/workflows/elastic/helper.py

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
from collections import OrderedDict
22

3+
import ase.atoms
34
import numpy as np
45
import scipy.constants
56

@@ -11,7 +12,11 @@
1112

1213

1314
def generate_structures_helper(
14-
structure, eps_range, num_of_point, zero_strain_job_name="s_e_0", sqrt_eta=True
15+
structure: ase.atoms.Atoms,
16+
eps_range: float,
17+
num_of_point: int,
18+
zero_strain_job_name: str = "s_e_0",
19+
sqrt_eta: bool = True,
1520
):
1621
"""
1722
@@ -84,13 +89,13 @@ def generate_structures_helper(
8489

8590

8691
def analyse_structures_helper(
87-
output_dict,
88-
Lag_strain_list,
89-
epss,
90-
v0,
91-
LC,
92-
fit_order=2,
93-
zero_strain_job_name="s_e_0",
92+
output_dict: dict,
93+
Lag_strain_list: list[float],
94+
epss: float,
95+
v0: float,
96+
LC: str,
97+
fit_order: int = 2,
98+
zero_strain_job_name: str = "s_e_0",
9499
):
95100
"""
96101
@@ -125,7 +130,7 @@ def analyse_structures_helper(
125130
return elastic_matrix, A2, strain_energy, ene0
126131

127132

128-
def _subjob_name(i, eps):
133+
def _subjob_name(i: int, eps: float):
129134
"""
130135
131136
Args:
@@ -138,7 +143,7 @@ def _subjob_name(i, eps):
138143
return ("s_%s_e_%.5f" % (i, eps)).replace(".", "_").replace("-", "m")
139144

140145

141-
def _fit_elastic_matrix(strain_ene, v0, LC, fit_order):
146+
def _fit_elastic_matrix(strain_ene: list, v0: float, LC: str, fit_order: int):
142147
"""
143148
144149
Returns:

atomistics/workflows/elastic/symmetry.py

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1+
from ase.atoms import Atoms
12
import numpy as np
23
import spglib
34

45

5-
def ase_to_spglib(structure):
6+
def ase_to_spglib(structure: Atoms) -> tuple:
67
"""
78
Translate ASE to spglib cell. The format is a tuple of
89
(basis vectors, atomic points, types). The implementation here follows
@@ -17,7 +18,7 @@ def ase_to_spglib(structure):
1718
)
1819

1920

20-
def find_symmetry_group_number(struct):
21+
def find_symmetry_group_number(struct: tuple) -> int:
2122
dataset = spglib.get_symmetry_dataset(cell=ase_to_spglib(struct))
2223
SGN = dataset["number"]
2324
return SGN
@@ -72,7 +73,7 @@ def find_symmetry_group_number(struct):
7273
}
7374

7475

75-
def get_symmetry_family_from_SGN(SGN):
76+
def get_symmetry_family_from_SGN(SGN: int) -> str:
7677
if 1 <= SGN <= 2: # Triclinic
7778
LC = "N"
7879
elif 3 <= SGN <= 15: # Monoclinic
@@ -100,7 +101,7 @@ def get_symmetry_family_from_SGN(SGN):
100101
return LC
101102

102103

103-
def get_LAG_Strain_List(LC):
104+
def get_LAG_Strain_List(LC: str) -> list[str]:
104105
if LC == "CI" or LC == "CII":
105106
Lag_strain_list = ["01", "08", "23"]
106107
elif LC == "HI" or LC == "HII":
@@ -158,7 +159,7 @@ def get_LAG_Strain_List(LC):
158159
return Lag_strain_list
159160

160161

161-
def get_C_from_A2(A2, LC):
162+
def get_C_from_A2(A2: np.ndarray, LC: str) -> np.ndarray:
162163
C = np.zeros((6, 6))
163164

164165
# %!%!%--- Cubic structures ---%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%!%
@@ -334,7 +335,7 @@ def get_C_from_A2(A2, LC):
334335
return C
335336

336337

337-
def symmetry_analysis(structure, eps_range, num_of_point):
338+
def symmetry_analysis(structure: Atoms, eps_range: float, num_of_point: int):
338339
"""
339340
340341
Returns:

atomistics/workflows/elastic/workflow.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
from ase.atoms import Atoms
12
import numpy as np
23

34
from atomistics.shared.output import OutputElastic
@@ -11,7 +12,12 @@
1112

1213
class ElasticMatrixWorkflow(Workflow):
1314
def __init__(
14-
self, structure, num_of_point=5, eps_range=0.005, sqrt_eta=True, fit_order=2
15+
self,
16+
structure: Atoms,
17+
num_of_point: int = 5,
18+
eps_range: float = 0.005,
19+
sqrt_eta: bool = True,
20+
fit_order: int = 2,
1521
):
1622
self.structure = structure.copy()
1723
self.num_of_point = num_of_point
@@ -24,7 +30,7 @@ def __init__(
2430
self.epss = np.array([])
2531
self.zero_strain_job_name = "s_e_0"
2632

27-
def generate_structures(self):
33+
def generate_structures(self) -> dict:
2834
"""
2935
3036
Returns:
@@ -39,7 +45,9 @@ def generate_structures(self):
3945
)
4046
return {"calc_energy": self._structure_dict}
4147

42-
def analyse_structures(self, output_dict, output_keys=OutputElastic.keys()):
48+
def analyse_structures(
49+
self, output_dict: dict, output_keys: tuple = OutputElastic.keys()
50+
):
4351
"""
4452
4553
Args:

0 commit comments

Comments
 (0)