Skip to content

Commit de14be7

Browse files
committed
Add PDoS kwargs option
1 parent e6b9df1 commit de14be7

File tree

4 files changed

+54
-7
lines changed

4 files changed

+54
-7
lines changed

janus_core/calculations/phonons.py

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,8 @@ class Phonons(BaseCalculation):
8585
Default is None.
8686
dos_kwargs : Optional[dict[str, Any]]
8787
Keyword arguments to pass to run_total_dos. Default is {}.
88+
pdos_kwargs : Optional[dict[str, Any]]
89+
Keyword arguments to pass to run_projected_dos. Default is {}.
8890
temp_min : float
8991
Start temperature for thermal properties calculations, in K. Default is 0.0.
9092
temp_max : float
@@ -164,6 +166,7 @@ def __init__(
164166
n_qpoints: int = 51,
165167
paths: Optional[PathLike] = None,
166168
dos_kwargs: Optional[dict[str, Any]] = None,
169+
pdos_kwargs: Optional[dict[str, Any]] = None,
167170
temp_min: float = 0.0,
168171
temp_max: float = 1000.0,
169172
temp_step: float = 50.0,
@@ -230,6 +233,8 @@ def __init__(
230233
structure. Default is None.
231234
dos_kwargs : Optional[dict[str, Any]]
232235
Keyword arguments to pass to run_total_dos. Default is {}.
236+
pdos_kwargs : Optional[dict[str, Any]]
237+
Keyword arguments to pass to run_projected_dos. Default is {}.
233238
temp_min : float
234239
Start temperature for thermal calculations, in K. Default is 0.0.
235240
temp_max : float
@@ -252,8 +257,16 @@ def __init__(
252257
enable_progress_bar : bool
253258
Whether to show a progress bar during phonon calculations. Default is False.
254259
"""
255-
(read_kwargs, displacement_kwargs, minimize_kwargs, dos_kwargs) = none_to_dict(
256-
(read_kwargs, displacement_kwargs, minimize_kwargs, dos_kwargs)
260+
(read_kwargs, displacement_kwargs, minimize_kwargs, dos_kwargs, pdos_kwargs) = (
261+
none_to_dict(
262+
(
263+
read_kwargs,
264+
displacement_kwargs,
265+
minimize_kwargs,
266+
dos_kwargs,
267+
pdos_kwargs,
268+
)
269+
)
257270
)
258271

259272
self.calcs = calcs
@@ -266,6 +279,7 @@ def __init__(
266279
self.n_qpoints = n_qpoints
267280
self.paths = paths
268281
self.dos_kwargs = dos_kwargs
282+
self.pdos_kwargs = pdos_kwargs
269283
self.temp_min = temp_min
270284
self.temp_max = temp_max
271285
self.temp_step = temp_step
@@ -778,7 +792,7 @@ def calc_pdos(
778792
self.results["phonon"].run_mesh(
779793
mesh, with_eigenvectors=True, is_mesh_symmetry=False
780794
)
781-
self.results["phonon"].run_projected_dos()
795+
self.results["phonon"].run_projected_dos(**self.pdos_kwargs)
782796

783797
if self.logger:
784798
emissions = self.tracker.stop_task().emissions

janus_core/cli/phonons.py

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
LogPath,
1616
MinimizeKwargs,
1717
ModelPath,
18+
PDoSKwargs,
1819
ReadKwargsLast,
1920
StructPath,
2021
Summary,
@@ -63,7 +64,9 @@ def phonons(
6364
),
6465
] = None,
6566
dos: Annotated[bool, Option(help="Whether to calculate the DOS.")] = False,
67+
dos_kwargs: DoSKwargs = None,
6668
pdos: Annotated[bool, Option(help="Whether to calculate the PDOS.")] = False,
69+
pdos_kwargs: PDoSKwargs = None,
6770
thermal: Annotated[
6871
bool, Option(help="Whether to calculate thermal properties.")
6972
] = False,
@@ -89,7 +92,6 @@ def phonons(
8992
float, Option(help="Maximum force for optimization convergence.")
9093
] = 0.1,
9194
minimize_kwargs: MinimizeKwargs = None,
92-
dos_kwargs: DoSKwargs = None,
9395
hdf5: Annotated[
9496
bool, Option(help="Whether to save force constants in hdf5.")
9597
] = True,
@@ -151,8 +153,12 @@ def phonons(
151153
Default is None.
152154
dos : bool
153155
Whether to calculate and save the DOS. Default is False.
156+
dos_kwargs : Optional[dict[str, Any]]
157+
Other keyword arguments to pass to run_total_dos. Default is {}.
154158
pdos : bool
155159
Whether to calculate and save the PDOS. Default is False.
160+
pdos_kwargs : Optional[dict[str, Any]]
161+
Other keyword arguments to pass to run_projected_dos. Default is {}.
156162
thermal : bool
157163
Whether to calculate thermal properties. Default is False.
158164
temp_min : float
@@ -173,8 +179,6 @@ def phonons(
173179
Default is 0.1.
174180
minimize_kwargs : Optional[dict[str, Any]]
175181
Other keyword arguments to pass to geometry optimizer. Default is {}.
176-
dos_kwargs : Optional[dict[str, Any]]
177-
Other keyword arguments to pass to run_total_dos. Default is {}.
178182
hdf5 : bool
179183
Whether to save force constants in hdf5 format. Default is True.
180184
plot_to_file : bool
@@ -226,8 +230,16 @@ def phonons(
226230
calc_kwargs,
227231
minimize_kwargs,
228232
dos_kwargs,
233+
pdos_kwargs,
229234
) = parse_typer_dicts(
230-
[displacement_kwargs, read_kwargs, calc_kwargs, minimize_kwargs, dos_kwargs]
235+
[
236+
displacement_kwargs,
237+
read_kwargs,
238+
calc_kwargs,
239+
minimize_kwargs,
240+
dos_kwargs,
241+
pdos_kwargs,
242+
]
231243
)
232244

233245
# Read only first structure by default and ensure only one image is read
@@ -273,6 +285,7 @@ def phonons(
273285
"n_qpoints": n_qpoints,
274286
"paths": paths,
275287
"dos_kwargs": dos_kwargs,
288+
"pdos_kwargs": pdos_kwargs,
276289
"temp_min": temp_min,
277290
"temp_max": temp_max,
278291
"temp_step": temp_step,

janus_core/cli/types.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,20 @@ def __str__(self):
173173
),
174174
]
175175

176+
PDoSKwargs = Annotated[
177+
Optional[TyperDict],
178+
Option(
179+
parser=parse_dict_class,
180+
help=(
181+
"""
182+
Keyword arguments to pass to run_projected_dos. Must be passed as a
183+
dictionary wrapped in quotes, e.g. "{'key' : value}".
184+
"""
185+
),
186+
metavar="DICT",
187+
),
188+
]
189+
176190
EnsembleKwargs = Annotated[
177191
Optional[TyperDict],
178192
Option(

tests/test_phonons_cli.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,13 +208,19 @@ def test_pdos(tmp_path):
208208
"--struct",
209209
DATA_PATH / "NaCl.cif",
210210
"--pdos",
211+
"--pdos-kwargs",
212+
"{'freq_min': -1, 'freq_max': 0, 'xyz_projection': True}",
211213
"--no-hdf5",
212214
"--file-prefix",
213215
file_prefix,
214216
],
215217
)
216218
assert result.exit_code == 0
217219
assert pdos_results.exists()
220+
with open(pdos_results, encoding="utf8") as file:
221+
lines = file.readlines()
222+
assert lines[1].split()[0] == "-1.0000000000"
223+
assert lines[-1].split()[0] == "0.0000000000"
218224

219225

220226
def test_plot(tmp_path):

0 commit comments

Comments
 (0)