|
4 | 4 |
|
5 | 5 | from collections.abc import Sequence |
6 | 6 | from typing import Any, get_args |
| 7 | +from warnings import warn |
7 | 8 |
|
8 | 9 | from ase import Atoms |
9 | 10 | from numpy import ndarray |
@@ -107,6 +108,8 @@ class Phonons(BaseCalculation): |
107 | 108 | End temperature for thermal properties calculations, in K. Default is 1000.0. |
108 | 109 | temp_step |
109 | 110 | Temperature step for thermal properties calculations, in K. Default is 50.0. |
| 111 | + force_consts_to_hdf5 |
| 112 | + Deprecated. Please use `hdf5`. |
110 | 113 | hdf5 |
111 | 114 | Whether to write force constants and bands in hdf5 or not. Default is True. |
112 | 115 | plot_to_file |
@@ -159,6 +162,7 @@ def __init__( |
159 | 162 | temp_min: float = 0.0, |
160 | 163 | temp_max: float = 1000.0, |
161 | 164 | temp_step: float = 50.0, |
| 165 | + force_consts_to_hdf5: None = None, |
162 | 166 | hdf5: bool = True, |
163 | 167 | plot_to_file: bool = False, |
164 | 168 | write_results: bool = True, |
@@ -237,6 +241,8 @@ def __init__( |
237 | 241 | End temperature for thermal calculations, in K. Default is 1000.0. |
238 | 242 | temp_step |
239 | 243 | Temperature step for thermal calculations, in K. Default is 50.0. |
| 244 | + force_consts_to_hdf5 |
| 245 | + Deprecated. Please use `hdf5`. |
240 | 246 | hdf5 |
241 | 247 | Whether to write force constants and bands in hdf5 or not. Default is True. |
242 | 248 | plot_to_file |
@@ -277,12 +283,28 @@ def __init__( |
277 | 283 | self.temp_min = temp_min |
278 | 284 | self.temp_max = temp_max |
279 | 285 | self.temp_step = temp_step |
| 286 | + self.force_consts_to_hdf5 = force_consts_to_hdf5 |
280 | 287 | self.hdf5 = hdf5 |
281 | 288 | self.plot_to_file = plot_to_file |
282 | 289 | self.write_results = write_results |
283 | 290 | self.write_full = write_full |
284 | 291 | self.enable_progress_bar = enable_progress_bar |
285 | 292 |
|
| 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 | + |
286 | 308 | # Ensure supercell is a valid list |
287 | 309 | self.supercell = [supercell] * 3 if isinstance(supercell, int) else supercell |
288 | 310 | if len(self.supercell) not in [3, 9]: |
@@ -340,17 +362,12 @@ def __init__( |
340 | 362 | # Output files |
341 | 363 | self.phonopy_file = self._build_filename("phonopy.yml") |
342 | 364 | 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 | + |
354 | 371 | self.dos_file = self._build_filename("dos.dat") |
355 | 372 | self.dos_plot_file = self._build_filename("dos.svg") |
356 | 373 | self.bands_dos_plot_file = self._build_filename("bs-dos.svg") |
@@ -571,7 +588,7 @@ def write_force_constants( |
571 | 588 | Whether to save the force constants separately to an hdf5 file. Default is |
572 | 589 | self.hdf5. |
573 | 590 | 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` |
575 | 592 | is False. Default is inferred from `file_prefix`. |
576 | 593 | """ |
577 | 594 | if "phonon" not in self.results: |
|
0 commit comments