diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 34d76577e9..b6d223b319 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -41,7 +41,7 @@ repos: rev: v2.3.0 hooks: - id: codespell - stages: [commit, commit-msg] + stages: [pre-commit, commit-msg] args: [--ignore-words-list, 'titel,statics,ba,nd,te,atomate'] types_or: [python, rst, markdown] - repo: https://github.com/kynan/nbstripout diff --git a/src/atomate2/common/flows/phonons.py b/src/atomate2/common/flows/phonons.py index 887885bdaa..2c3e57778c 100644 --- a/src/atomate2/common/flows/phonons.py +++ b/src/atomate2/common/flows/phonons.py @@ -107,6 +107,12 @@ class BasePhononMaker(Maker, ABC): Maker used to compute the forces for a supercell. generate_frequencies_eigenvectors_kwargs : dict Keyword arguments passed to :obj:`generate_frequencies_eigenvectors`. + - create_force_constants_file: bool + If True, a force constants file will be created + - force_constants_filename: str + If store_force_constants is True, the file name to store the force constants + - calculate_pdos: bool + If True, the projected phonon density of states will be calculated create_thermal_displacements: bool Bool that determines if thermal_displacement_matrices are computed kpath_scheme: str @@ -146,7 +152,14 @@ class BasePhononMaker(Maker, ABC): None ) create_thermal_displacements: bool = True - generate_frequencies_eigenvectors_kwargs: dict = field(default_factory=dict) + generate_frequencies_eigenvectors_kwargs: dict = field( + default_factory=lambda: { + "create_force_constants_file": False, + "force_constants_filename": "FORCE_CONSTANTS", + "calculate_pdos": False, + } + ) + kpath_scheme: str = "seekpath" code: str = None store_force_constants: bool = True diff --git a/src/atomate2/common/schemas/phonons.py b/src/atomate2/common/schemas/phonons.py index 539917fc03..73b53c9e26 100644 --- a/src/atomate2/common/schemas/phonons.py +++ b/src/atomate2/common/schemas/phonons.py @@ -346,11 +346,28 @@ def from_forces_born( phonon.produce_force_constants(forces=set_of_forces) filename_phonopy_yaml = kwargs.get("filename_phonopy_yaml", "phonopy.yaml") + create_force_constants_file = kwargs.get("create_force_constants_file", False) + force_constants_filename = kwargs.get( + "force_constants_filename", "FORCE_CONSTANTS" + ) # if kwargs.get("filename_phonopy_yaml") is None: # kwargs["filename_phonopy_yaml"] = "phonopy.yaml" # with phonopy.load("phonopy.yaml") the phonopy API can be used - phonon.save(filename_phonopy_yaml) + phonon.save( + filename_phonopy_yaml, + settings={ + "force_constants": kwargs.get( + "store_force_constants", not create_force_constants_file + ) + }, + ) + if create_force_constants_file: + from phonopy.file_IO import write_FORCE_CONSTANTS + + write_FORCE_CONSTANTS( # save force_constants to text file + phonon.force_constants, filename=force_constants_filename + ) # get phonon band structure kpath_dict, kpath_concrete = PhononBSDOSDoc.get_kpath( @@ -361,7 +378,7 @@ def from_forces_born( npoints_band = kwargs.get("npoints_band", 101) qpoints, connections = get_band_qpoints_and_path_connections( - kpath_concrete, npoints=kwargs.get("npoints_band", 101) + kpath_concrete, npoints=npoints_band ) # phonon band structures will always be computed @@ -406,6 +423,20 @@ def from_forces_born( kppa=kpoint_density_dos, force_gamma=True, ) + + # projected dos + if kwargs.get("calculate_pdos", False): + phonon.run_mesh( + kpoint.kpts[0], with_eigenvectors=True, is_mesh_symmetry=False + ) + phonon_dos_sigma = kwargs.get("phonon_dos_sigma") + dos_use_tetrahedron_method = kwargs.get("dos_use_tetrahedron_method", True) + phonon.run_projected_dos( + sigma=phonon_dos_sigma, + use_tetrahedron_method=dos_use_tetrahedron_method, + ) + phonon.write_projected_dos() + phonon.run_mesh(kpoint.kpts[0]) phonon_dos_sigma = kwargs.get("phonon_dos_sigma") dos_use_tetrahedron_method = kwargs.get("dos_use_tetrahedron_method", True)