From f08ce91afcc2375206baefba2248dda59332f592 Mon Sep 17 00:00:00 2001 From: Matteo Giantomassi Date: Tue, 30 Jul 2024 20:11:41 +0200 Subject: [PATCH] abiml.py ph now computes phdos automatically and abiopen supports phonopy_params.yaml files --- abipy/abilab.py | 5 +++++ abipy/ml/ml_phonopy.py | 23 ++++++++++------------- 2 files changed, 15 insertions(+), 13 deletions(-) diff --git a/abipy/abilab.py b/abipy/abilab.py index e258d03bb..60d8e958b 100644 --- a/abipy/abilab.py +++ b/abipy/abilab.py @@ -323,6 +323,11 @@ def abiopen(filepath: str): # Assume Abinit log file. return AbinitLogFile.from_file(filepath) + if os.path.basename(filepath) == "phonopy_params.yaml": + # Handle phonopy object. + import phonopy + return phonopy.load(filepath) + cls = abifile_subclass_from_filename(filepath) return cls.from_file(filepath) diff --git a/abipy/ml/ml_phonopy.py b/abipy/ml/ml_phonopy.py index 269f58558..d36c61c70 100644 --- a/abipy/ml/ml_phonopy.py +++ b/abipy/ml/ml_phonopy.py @@ -439,7 +439,6 @@ def _run_nn_name(self, nn_name: str) -> None: #from phonopy.file_IO import write_FORCE_CONSTANTS #write_FORCE_CONSTANTS(force_constants, filename=str(self.workdir / f"{nn_name}_FORCE_CONSTANTS")) - show = False #from abipy.dfpt.phonons import PhononBands, PhononBandsPlotter #with Timer(header="Starting phonopy ph-bands computation...", footer=""): # phonon.run_band_structure(self.py_qpoints, with_eigenvectors=True) @@ -458,22 +457,20 @@ def _run_nn_name(self, nn_name: str) -> None: filename=workdir / f"{nn_name}_band.yml", ) plt.savefig(workdir / f"phonopy_{nn_name}_phbands.png") - if show: plt.show() plt.close() + # Save phonopy object in Yaml format. phonon.save(filename=workdir / f"phonopy_params.yaml", settings={'force_constants': True}) - #mesh = [20, 20, 20] - #phonon.run_mesh(mesh) - #mesh_dict = phonon.get_mesh_dict() - #qpoints = mesh_dict['qpoints'] - #weights = mesh_dict['weights'] - #frequencies = mesh_dict['frequencies'] - #eigenvectors = mesh_dict['eigenvectors'] - #group_velocities = mesh_dict['group_velocities'] - - #phonon.auto_total_dos(plot=True).show() - #phonon.auto_projected_dos(plot=True).show() + # Compute phonon DOS and generate file with figure. + phonon.auto_total_dos(plot=True) + plt.savefig(workdir / f"phonopy_{nn_name}_phdos.png") + plt.close() + + # Compute site-project phonon DOS and generate file with figure. + #phonon.auto_projected_dos(plot=True) + #plt.savefig(workdir / f"phonopy_{nn_name}_pjdos.png") + #plt.close() #phon#on.run_mesh([20, 20, 20]) #phonon.run_thermal_properties(t_step=10, t_max=1000, t_min=0)