2020 PathLike ,
2121 PhononCalcs ,
2222)
23- from janus_core .helpers .utils import none_to_dict , write_table
23+ from janus_core .helpers .utils import none_to_dict , track_progress , write_table
2424
2525
2626class Phonons (BaseCalculation ):
@@ -60,6 +60,8 @@ class Phonons(BaseCalculation):
6060 Size of supercell for calculation. Default is 2.
6161 displacement : float
6262 Displacement for force constants calculation, in A. Default is 0.01.
63+ mesh : tuple[int, int, int]
64+ Mesh for sampling. Default is (10, 10, 10).
6365 symmetrize : bool
6466 Whether to symmetrize force constants after calculation.
6567 Default is False.
@@ -88,6 +90,8 @@ class Phonons(BaseCalculation):
8890 file_prefix : Optional[PathLike]
8991 Prefix for output filenames. Default is inferred from chemical formula of the
9092 structure.
93+ enable_progress_bar : bool
94+ Whether to show a progress bar during phonon calculations. Default is False.
9195
9296 Attributes
9397 ----------
@@ -106,7 +110,7 @@ class Phonons(BaseCalculation):
106110 Calculate band structure and optionally write and plot results.
107111 write_bands(bands_file, save_plots, plot_file)
108112 Write results of band structure calculations.
109- calc_thermal_props(write_thermal)
113+ calc_thermal_props(mesh, write_thermal)
110114 Calculate thermal properties and optionally write results.
111115 write_thermal_props(thermal_file)
112116 Write results of thermal properties calculations.
@@ -138,6 +142,7 @@ def __init__(
138142 calcs : MaybeSequence [PhononCalcs ] = (),
139143 supercell : MaybeList [int ] = 2 ,
140144 displacement : float = 0.01 ,
145+ mesh : tuple [int , int , int ] = (10 , 10 , 10 ),
141146 symmetrize : bool = False ,
142147 minimize : bool = False ,
143148 minimize_kwargs : Optional [dict [str , Any ]] = None ,
@@ -149,6 +154,7 @@ def __init__(
149154 write_results : bool = True ,
150155 write_full : bool = True ,
151156 file_prefix : Optional [PathLike ] = None ,
157+ enable_progress_bar : bool = False ,
152158 ) -> None :
153159 """
154160 Initialise Phonons class.
@@ -186,6 +192,8 @@ def __init__(
186192 Size of supercell for calculation. Default is 2.
187193 displacement : float
188194 Displacement for force constants calculation, in A. Default is 0.01.
195+ mesh : tuple[int, int, int]
196+ Mesh for sampling. Default is (10, 10, 10).
189197 symmetrize : bool
190198 Whether to symmetrize force constants after calculations.
191199 Default is False.
@@ -214,11 +222,14 @@ def __init__(
214222 file_prefix : Optional[PathLike]
215223 Prefix for output filenames. Default is inferred from structure name, or
216224 chemical formula of the structure.
225+ enable_progress_bar : bool
226+ Whether to show a progress bar during phonon calculations. Default is False.
217227 """
218228 (read_kwargs , minimize_kwargs ) = none_to_dict ((read_kwargs , minimize_kwargs ))
219229
220230 self .calcs = calcs
221231 self .displacement = displacement
232+ self .mesh = mesh
222233 self .symmetrize = symmetrize
223234 self .minimize = minimize
224235 self .minimize_kwargs = minimize_kwargs
@@ -229,6 +240,7 @@ def __init__(
229240 self .plot_to_file = plot_to_file
230241 self .write_results = write_results
231242 self .write_full = write_full
243+ self .enable_progress_bar = enable_progress_bar
232244
233245 # Ensure supercell is a valid list
234246 self .supercell = [supercell ] * 3 if isinstance (supercell , int ) else supercell
@@ -357,6 +369,11 @@ def calc_force_constants(
357369 phonon .generate_displacements (distance = self .displacement )
358370 disp_supercells = phonon .supercells_with_displacements
359371
372+ if self .enable_progress_bar :
373+ disp_supercells = track_progress (
374+ disp_supercells , "Computing displacements..."
375+ )
376+
360377 phonon .forces = [
361378 self ._calc_forces (supercell )
362379 for supercell in disp_supercells
@@ -490,13 +507,18 @@ def write_bands(
490507 bplt .savefig (plot_file )
491508
492509 def calc_thermal_props (
493- self , write_thermal : Optional [bool ] = None , ** kwargs
510+ self ,
511+ mesh : Optional [tuple [int , int , int ]] = None ,
512+ write_thermal : Optional [bool ] = None ,
513+ ** kwargs ,
494514 ) -> None :
495515 """
496516 Calculate thermal properties and optionally write results.
497517
498518 Parameters
499519 ----------
520+ mesh : Optional[tuple[int, int, int]]
521+ Mesh for sampling. Default is self.mesh.
500522 write_thermal : Optional[bool]
501523 Whether to write out thermal properties to file. Default is
502524 self.write_results.
@@ -506,6 +528,9 @@ def calc_thermal_props(
506528 if write_thermal is None :
507529 write_thermal = self .write_results
508530
531+ if mesh is None :
532+ mesh = self .mesh
533+
509534 # Calculate phonons if not already in results
510535 if "phonon" not in self .results :
511536 # Use general (self.write_results) setting for writing force constants
@@ -515,7 +540,7 @@ def calc_thermal_props(
515540 self .logger .info ("Starting thermal properties calculation" )
516541 self .tracker .start_task ("Thermal calculation" )
517542
518- self .results ["phonon" ].run_mesh ()
543+ self .results ["phonon" ].run_mesh (mesh )
519544 self .results ["phonon" ].run_thermal_properties (
520545 t_step = self .temp_step , t_max = self .temp_max , t_min = self .temp_min
521546 )
@@ -563,7 +588,7 @@ def write_thermal_props(self, thermal_file: Optional[PathLike] = None) -> None:
563588 def calc_dos (
564589 self ,
565590 * ,
566- mesh : MaybeList [ float ] = ( 10 , 10 , 10 ) ,
591+ mesh : Optional [ tuple [ int , int , int ]] = None ,
567592 write_dos : Optional [bool ] = None ,
568593 ** kwargs ,
569594 ) -> None :
@@ -572,8 +597,8 @@ def calc_dos(
572597
573598 Parameters
574599 ----------
575- mesh : MaybeList[float ]
576- Mesh for sampling. Default is (10, 10, 10) .
600+ mesh : Optional[tuple[int, int, int] ]
601+ Mesh for sampling. Default is self.mesh .
577602 write_dos : Optional[bool]
578603 Whether to write out results to file. Default is True.
579604 **kwargs
@@ -582,6 +607,9 @@ def calc_dos(
582607 if write_dos is None :
583608 write_dos = self .write_results
584609
610+ if mesh is None :
611+ mesh = self .mesh
612+
585613 # Calculate phonons if not already in results
586614 if "phonon" not in self .results :
587615 # Use general (self.write_results) setting for writing force constants
@@ -665,7 +693,7 @@ def write_dos(
665693 def calc_pdos (
666694 self ,
667695 * ,
668- mesh : MaybeList [ float ] = ( 10 , 10 , 10 ) ,
696+ mesh : Optional [ tuple [ int , int , int ]] = None ,
669697 write_pdos : Optional [bool ] = None ,
670698 ** kwargs ,
671699 ) -> None :
@@ -674,8 +702,8 @@ def calc_pdos(
674702
675703 Parameters
676704 ----------
677- mesh : MaybeList[float ]
678- Mesh for sampling. Default is (10, 10, 10) .
705+ mesh : Optional[tuple[int, int, int] ]
706+ Mesh for sampling. Default is self.mesh .
679707 write_pdos : Optional[bool]
680708 Whether to write out results to file. Default is self.write_results.
681709 **kwargs
@@ -684,6 +712,9 @@ def calc_pdos(
684712 if write_pdos is None :
685713 write_pdos = self .write_results
686714
715+ if mesh is None :
716+ mesh = self .mesh
717+
687718 # Calculate phonons if not already in results
688719 if "phonon" not in self .results :
689720 # Use general (self.write_results) setting for writing force constants
0 commit comments