Skip to content

Commit 7e1d215

Browse files
committed
add deprecation
1 parent 1ad865f commit 7e1d215

File tree

2 files changed

+34
-17
lines changed

2 files changed

+34
-17
lines changed

docs/source/tutorials/python/phonons.ipynb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -140,7 +140,7 @@
140140
" temp_min=0.0,\n",
141141
" temp_max=1000.0,\n",
142142
" minimize=False,\n",
143-
" force_consts_to_hdf5=True,\n",
143+
" hdf5=True,\n",
144144
" plot_to_file=True,\n",
145145
" symmetrize=False,\n",
146146
" write_full=True,\n",
@@ -249,7 +249,7 @@
249249
" temp_min=0.0,\n",
250250
" temp_max=1000.0,\n",
251251
" minimize=True,\n",
252-
" force_consts_to_hdf5=True,\n",
252+
" hdf5=True,\n",
253253
" plot_to_file=True,\n",
254254
" symmetrize=False,\n",
255255
" write_full=True,\n",
@@ -317,7 +317,7 @@
317317
" temp_min=0.0,\n",
318318
" temp_max=1000.0,\n",
319319
" minimize=True,\n",
320-
" force_consts_to_hdf5=True,\n",
320+
" hdf5=True,\n",
321321
" plot_to_file=True,\n",
322322
" symmetrize=False,\n",
323323
" write_full=True,\n",
@@ -399,7 +399,7 @@
399399
" temp_min=0.0,\n",
400400
" temp_max=1000.0,\n",
401401
" minimize=True,\n",
402-
" force_consts_to_hdf5=True,\n",
402+
" hdf5=True,\n",
403403
" plot_to_file=True,\n",
404404
" symmetrize=False,\n",
405405
" write_full=True,\n",
@@ -440,7 +440,7 @@
440440
" temp_min=0.0,\n",
441441
" temp_max=1000.0,\n",
442442
" minimize=True,\n",
443-
" force_consts_to_hdf5=True,\n",
443+
" hdf5=True,\n",
444444
" plot_to_file=True,\n",
445445
" symmetrize=False,\n",
446446
" write_full=True,\n",

janus_core/calculations/phonons.py

Lines changed: 29 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
from collections.abc import Sequence
66
from typing import Any, get_args
7+
from warnings import warn
78

89
from ase import Atoms
910
from numpy import ndarray
@@ -107,6 +108,8 @@ class Phonons(BaseCalculation):
107108
End temperature for thermal properties calculations, in K. Default is 1000.0.
108109
temp_step
109110
Temperature step for thermal properties calculations, in K. Default is 50.0.
111+
force_consts_to_hdf5
112+
Deprecated. Please use `hdf5`.
110113
hdf5
111114
Whether to write force constants and bands in hdf5 or not. Default is True.
112115
plot_to_file
@@ -159,6 +162,7 @@ def __init__(
159162
temp_min: float = 0.0,
160163
temp_max: float = 1000.0,
161164
temp_step: float = 50.0,
165+
force_consts_to_hdf5: None = None,
162166
hdf5: bool = True,
163167
plot_to_file: bool = False,
164168
write_results: bool = True,
@@ -237,6 +241,8 @@ def __init__(
237241
End temperature for thermal calculations, in K. Default is 1000.0.
238242
temp_step
239243
Temperature step for thermal calculations, in K. Default is 50.0.
244+
force_consts_to_hdf5
245+
Deprecated. Please use `hdf5`.
240246
hdf5
241247
Whether to write force constants and bands in hdf5 or not. Default is True.
242248
plot_to_file
@@ -277,12 +283,28 @@ def __init__(
277283
self.temp_min = temp_min
278284
self.temp_max = temp_max
279285
self.temp_step = temp_step
286+
self.force_consts_to_hdf5 = force_consts_to_hdf5
280287
self.hdf5 = hdf5
281288
self.plot_to_file = plot_to_file
282289
self.write_results = write_results
283290
self.write_full = write_full
284291
self.enable_progress_bar = enable_progress_bar
285292

293+
# Handle deprecation
294+
if force_consts_to_hdf5:
295+
if hdf5:
296+
raise ValueError(
297+
"""`force_consts_to_hdf5`: has replaced `hdf5`.
298+
Please only use `hdf5`"""
299+
)
300+
self.hdf5 = force_consts_to_hdf5
301+
warn(
302+
"""`force_consts_to_hdf5` has been deprecated.
303+
Please use `hdf5`.""",
304+
FutureWarning,
305+
stacklevel=2,
306+
)
307+
286308
# Ensure supercell is a valid list
287309
self.supercell = [supercell] * 3 if isinstance(supercell, int) else supercell
288310
if len(self.supercell) not in [3, 9]:
@@ -340,17 +362,12 @@ def __init__(
340362
# Output files
341363
self.phonopy_file = self._build_filename("phonopy.yml")
342364
self.force_consts_file = self._build_filename("force_constants.hdf5")
343-
if self.qpoint_file:
344-
if hdf5:
345-
self.bands_file = self._build_filename("bands.hdf5")
346-
else:
347-
self.bands_file = self._build_filename("bands.yml")
348-
else:
349-
if hdf5:
350-
self.bands_file = self._build_filename("auto_bands.hdf5")
351-
else:
352-
self.bands_file = self._build_filename("auto_bands.yml")
353-
self.bands_plot_file = self._build_filename("bands.svg")
365+
366+
filename = "bands" + (".hdf5" if hdf5 else ".yml")
367+
if not self.qpoint_file:
368+
filename = f"auto_{filename}"
369+
self.bands_file = self._build_filename(filename)
370+
354371
self.dos_file = self._build_filename("dos.dat")
355372
self.dos_plot_file = self._build_filename("dos.svg")
356373
self.bands_dos_plot_file = self._build_filename("bs-dos.svg")
@@ -571,7 +588,7 @@ def write_force_constants(
571588
Whether to save the force constants separately to an hdf5 file. Default is
572589
self.hdf5.
573590
force_consts_file
574-
Name of hdf5 file to save force constants. Unused if `force_consts_to_hdf5`
591+
Name of hdf5 file to save force constants. Unused if `hdf5`
575592
is False. Default is inferred from `file_prefix`.
576593
"""
577594
if "phonon" not in self.results:

0 commit comments

Comments
 (0)