Skip to content

Commit 7add7ca

Browse files
chouyoudouYaotang Zhangjanosh
authored
PhononMaker add options to calculate_pdos and save force constants to file (#1008)
* add calculate_pdos and make force constance can be save * add calculate_pdos and make force constance can be save * Update phonons.py * Apply pre-commit hooks for code formatting and linting * Fix issues found by pre-commit hooks * add force_constants2file parameter * - Renamed "force_constants2file" to "force_constants_filename" - Add "create_force_constants_file" in "generate_frequencies_eigenvectors_kwargs" - Move "force_constants_filename" and "calculate_pdos" to "generate_frequencies_eigenvectors_kwargs" * fix doc string placement * refactor from_forces_born handling create_force_constants_file --------- Co-authored-by: Yaotang Zhang <[email protected]> Co-authored-by: Janosh Riebesell <[email protected]>
1 parent 67efb7f commit 7add7ca

File tree

2 files changed

+47
-3
lines changed

2 files changed

+47
-3
lines changed

src/atomate2/common/flows/phonons.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,12 @@ class BasePhononMaker(Maker, ABC):
107107
Maker used to compute the forces for a supercell.
108108
generate_frequencies_eigenvectors_kwargs : dict
109109
Keyword arguments passed to :obj:`generate_frequencies_eigenvectors`.
110+
- create_force_constants_file: bool
111+
If True, a force constants file will be created
112+
- force_constants_filename: str
113+
If store_force_constants is True, the file name to store the force constants
114+
- calculate_pdos: bool
115+
If True, the projected phonon density of states will be calculated
110116
create_thermal_displacements: bool
111117
Bool that determines if thermal_displacement_matrices are computed
112118
kpath_scheme: str
@@ -146,7 +152,14 @@ class BasePhononMaker(Maker, ABC):
146152
None
147153
)
148154
create_thermal_displacements: bool = True
149-
generate_frequencies_eigenvectors_kwargs: dict = field(default_factory=dict)
155+
generate_frequencies_eigenvectors_kwargs: dict = field(
156+
default_factory=lambda: {
157+
"create_force_constants_file": False,
158+
"force_constants_filename": "FORCE_CONSTANTS",
159+
"calculate_pdos": False,
160+
}
161+
)
162+
150163
kpath_scheme: str = "seekpath"
151164
code: str = None
152165
store_force_constants: bool = True

src/atomate2/common/schemas/phonons.py

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -346,11 +346,28 @@ def from_forces_born(
346346
phonon.produce_force_constants(forces=set_of_forces)
347347

348348
filename_phonopy_yaml = kwargs.get("filename_phonopy_yaml", "phonopy.yaml")
349+
create_force_constants_file = kwargs.get("create_force_constants_file", False)
350+
force_constants_filename = kwargs.get(
351+
"force_constants_filename", "FORCE_CONSTANTS"
352+
)
349353
# if kwargs.get("filename_phonopy_yaml") is None:
350354
# kwargs["filename_phonopy_yaml"] = "phonopy.yaml"
351355

352356
# with phonopy.load("phonopy.yaml") the phonopy API can be used
353-
phonon.save(filename_phonopy_yaml)
357+
phonon.save(
358+
filename_phonopy_yaml,
359+
settings={
360+
"force_constants": kwargs.get(
361+
"store_force_constants", not create_force_constants_file
362+
)
363+
},
364+
)
365+
if create_force_constants_file:
366+
from phonopy.file_IO import write_FORCE_CONSTANTS
367+
368+
write_FORCE_CONSTANTS( # save force_constants to text file
369+
phonon.force_constants, filename=force_constants_filename
370+
)
354371

355372
# get phonon band structure
356373
kpath_dict, kpath_concrete = PhononBSDOSDoc.get_kpath(
@@ -361,7 +378,7 @@ def from_forces_born(
361378

362379
npoints_band = kwargs.get("npoints_band", 101)
363380
qpoints, connections = get_band_qpoints_and_path_connections(
364-
kpath_concrete, npoints=kwargs.get("npoints_band", 101)
381+
kpath_concrete, npoints=npoints_band
365382
)
366383

367384
# phonon band structures will always be computed
@@ -406,6 +423,20 @@ def from_forces_born(
406423
kppa=kpoint_density_dos,
407424
force_gamma=True,
408425
)
426+
427+
# projected dos
428+
if kwargs.get("calculate_pdos", False):
429+
phonon.run_mesh(
430+
kpoint.kpts[0], with_eigenvectors=True, is_mesh_symmetry=False
431+
)
432+
phonon_dos_sigma = kwargs.get("phonon_dos_sigma")
433+
dos_use_tetrahedron_method = kwargs.get("dos_use_tetrahedron_method", True)
434+
phonon.run_projected_dos(
435+
sigma=phonon_dos_sigma,
436+
use_tetrahedron_method=dos_use_tetrahedron_method,
437+
)
438+
phonon.write_projected_dos()
439+
409440
phonon.run_mesh(kpoint.kpts[0])
410441
phonon_dos_sigma = kwargs.get("phonon_dos_sigma")
411442
dos_use_tetrahedron_method = kwargs.get("dos_use_tetrahedron_method", True)

0 commit comments

Comments
 (0)