From 1559318d1e02a6cd6be9126a95919d21a3d7214e Mon Sep 17 00:00:00 2001 From: naik-aakash Date: Tue, 17 Sep 2024 17:55:32 +0200 Subject: [PATCH 1/6] bump phonopy version --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 1213d4b8be..ad3b724546 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -96,7 +96,7 @@ strict = [ "monty==2024.7.30", "mp-api==0.42.2", "numpy", - "phonopy==2.27.0", + "phonopy==2.28.0", "pydantic-settings==2.5.2", "pydantic==2.9.1", "pymatgen-analysis-defects==2024.7.19", From 7c95613bcd045c785c6c22fbc46f730ba7722714 Mon Sep 17 00:00:00 2001 From: Aakash Ashok Naik <91958822+naik-aakash@users.noreply.github.com> Date: Mon, 18 Nov 2024 16:48:30 +0100 Subject: [PATCH 2/6] Update pyproject.toml --- pyproject.toml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyproject.toml b/pyproject.toml index 25f8bc031a..07853f2510 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -108,7 +108,7 @@ strict = [ "numpy", "openmm-mdanalysis-reporter==0.1.0", "openmm==8.1.1", - "phonopy==2.28.0", + "phonopy==2.30.1", "pydantic-settings==2.6.1", "pydantic==2.9.2", "pymatgen-analysis-defects==2024.10.22", From f71249865423b4b1ee4734caf4bccfca01a384fb Mon Sep 17 00:00:00 2001 From: naik-aakash Date: Tue, 19 Nov 2024 17:45:04 +0100 Subject: [PATCH 3/6] replace bs plotter with pymatgen implementation > reduce code repetition --- src/atomate2/common/schemas/gruneisen.py | 90 ++---------------------- 1 file changed, 7 insertions(+), 83 deletions(-) diff --git a/src/atomate2/common/schemas/gruneisen.py b/src/atomate2/common/schemas/gruneisen.py index b12f9c78a9..5394ffe197 100644 --- a/src/atomate2/common/schemas/gruneisen.py +++ b/src/atomate2/common/schemas/gruneisen.py @@ -228,11 +228,14 @@ def from_phonon_yamls( labels_dict=kpath_dict, ) gp_bs_plot = GruneisenPhononBSPlotter(bs=gruneisen_band_structure) - GruneisenParameterDocument.get_gruneisen_weighted_bandstructure( - gruneisen_band_symline_plotter=gp_bs_plot, - save_fig=True, - **compute_gruneisen_param_kwargs, + + gruneisen_bs_plot = compute_gruneisen_param_kwargs.get( + "gruneisen_bs", "gruneisen_band.pdf" ) + gp_bs_plot.save_plot_gs(filename=gruneisen_bs_plot, + plot_ph_bs_with_gruneisen=True, + img_format=compute_gruneisen_param_kwargs.get("img_format", "pdf"), + **compute_gruneisen_param_kwargs) gruneisen_parameter_inputs = { "ground": phonopy_yaml_paths_dict["ground"], "plus": phonopy_yaml_paths_dict["plus"], @@ -261,82 +264,3 @@ def from_phonon_yamls( gruneisen_band_structure=gruneisen_band_structure, derived_properties=derived_properties, ) - - @staticmethod - def get_gruneisen_weighted_bandstructure( - gruneisen_band_symline_plotter: GruneisenPhononBSPlotter, - save_fig: bool = True, - **kwargs, - ) -> None: - """Save a phonon band structure weighted with Grueneisen parameters. - - Parameters - ---------- - gruneisen_band_symline_plotter: GruneisenPhononBSPlotter - pymatgen GruneisenPhononBSPlotter obj - save_fig: bool - bool to save plots - kwargs: dict - keyword arguments to adjust plotter - - Returns - ------- - None - """ - u = freq_units(kwargs.get("units", "THz")) - ax = pretty_plot(12, 8) - gruneisen_band_symline_plotter._make_ticks(ax) # noqa: SLF001 - - # plot y=0 line - ax.axhline(0, linewidth=1, color="black") - - # Create custom colormap (default is red to blue) - cmap = LinearSegmentedColormap.from_list( - "mycmap", kwargs.get("mycmap", ["red", "blue"]) - ) - - data = gruneisen_band_symline_plotter.bs_plot_data() - - # extract min and max Grüneisen parameter values - max_gruneisen = np.array(data["gruneisen"]).max() - min_gruneisen = np.array(data["gruneisen"]).min() - - # LogNormalize colormap based on the min and max Grüneisen parameter values - norm = colors.SymLogNorm( - vmin=min_gruneisen, - vmax=max_gruneisen, - linthresh=1e-2, - linscale=1, - ) - - for (dists_inx, dists), (_, freqs) in zip( - enumerate(data["distances"]), enumerate(data["frequency"]), strict=True - ): - for band_idx in range(gruneisen_band_symline_plotter.n_bands): - ys = [freqs[band_idx][j] * u.factor for j in range(len(dists))] - ys_gru = [ - data["gruneisen"][dists_inx][band_idx][idx] - for idx in range(len(data["distances"][dists_inx])) - ] - sc = ax.scatter( - dists, ys, c=ys_gru, cmap=cmap, norm=norm, marker="o", s=1 - ) - - # Main X and Y Labels - ax.set_xlabel(r"$\mathrm{Wave\ Vector}$", fontsize=30) - units = kwargs.get("units", "THz") - ax.set_ylabel(f"Frequencies ({units})", fontsize=30) - # X range (K) - # last distance point - x_max = data["distances"][-1][-1] - ax.set_xlim(0, x_max) - - cbar = plt.colorbar(sc, ax=ax) - cbar.set_label(r"$\gamma \ \mathrm{(logarithmized)}$", fontsize=30) - plt.tight_layout() - gruneisen_band_plot = kwargs.get("gruneisen_bs", "gruneisen_band.pdf") - if save_fig: - plt.savefig(fname=gruneisen_band_plot) - plt.close() - else: - plt.close() From 10721879bf267d333a716dfb9e7e917dc211eda6 Mon Sep 17 00:00:00 2001 From: naik-aakash Date: Tue, 19 Nov 2024 17:46:29 +0100 Subject: [PATCH 4/6] replace bs plotter with pymatgen implementation > reduce code repetition --- src/atomate2/common/schemas/gruneisen.py | 21 +++++++-------------- 1 file changed, 7 insertions(+), 14 deletions(-) diff --git a/src/atomate2/common/schemas/gruneisen.py b/src/atomate2/common/schemas/gruneisen.py index 5394ffe197..e6193c3967 100644 --- a/src/atomate2/common/schemas/gruneisen.py +++ b/src/atomate2/common/schemas/gruneisen.py @@ -4,12 +4,8 @@ from pathlib import Path from typing import Optional, Union -import matplotlib.pyplot as plt -import numpy as np import phonopy from emmet.core.structure import StructureMetadata -from matplotlib import colors -from matplotlib.colors import LinearSegmentedColormap from phonopy.api_gruneisen import PhonopyGruneisen from phonopy.phonon.band_structure import get_band_qpoints_and_path_connections from pydantic import BaseModel, Field @@ -24,12 +20,7 @@ GruneisenParameter, GruneisenPhononBandStructureSymmLine, ) -from pymatgen.phonon.plotter import ( - GruneisenPhononBSPlotter, - GruneisenPlotter, - freq_units, -) -from pymatgen.util.plotting import pretty_plot +from pymatgen.phonon.plotter import GruneisenPhononBSPlotter, GruneisenPlotter from typing_extensions import Self from atomate2.common.schemas.phonons import PhononBSDOSDoc @@ -232,10 +223,12 @@ def from_phonon_yamls( gruneisen_bs_plot = compute_gruneisen_param_kwargs.get( "gruneisen_bs", "gruneisen_band.pdf" ) - gp_bs_plot.save_plot_gs(filename=gruneisen_bs_plot, - plot_ph_bs_with_gruneisen=True, - img_format=compute_gruneisen_param_kwargs.get("img_format", "pdf"), - **compute_gruneisen_param_kwargs) + gp_bs_plot.save_plot_gs( + filename=gruneisen_bs_plot, + plot_ph_bs_with_gruneisen=True, + img_format=compute_gruneisen_param_kwargs.get("img_format", "pdf"), + **compute_gruneisen_param_kwargs, + ) gruneisen_parameter_inputs = { "ground": phonopy_yaml_paths_dict["ground"], "plus": phonopy_yaml_paths_dict["plus"], From cb645a100a20bafa3017e72e4f3458fdb48e025c Mon Sep 17 00:00:00 2001 From: naik-aakash Date: Mon, 25 Nov 2024 11:06:22 +0100 Subject: [PATCH 5/6] switch off grunesien computation at gamma (unstable) --- src/atomate2/common/schemas/gruneisen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/atomate2/common/schemas/gruneisen.py b/src/atomate2/common/schemas/gruneisen.py index e6193c3967..379dc173c2 100644 --- a/src/atomate2/common/schemas/gruneisen.py +++ b/src/atomate2/common/schemas/gruneisen.py @@ -155,7 +155,7 @@ def from_phonon_yamls( mesh=mesh, shift=compute_gruneisen_param_kwargs.get("shift"), is_gamma_center=compute_gruneisen_param_kwargs.get( - "is_gamma_center", True + "is_gamma_center", False ), is_time_reversal=compute_gruneisen_param_kwargs.get( "is_time_reversal", True @@ -175,7 +175,7 @@ def from_phonon_yamls( mesh=kpoint.kpts[0], shift=compute_gruneisen_param_kwargs.get("shift"), is_gamma_center=compute_gruneisen_param_kwargs.get( - "is_gamma_center", True + "is_gamma_center", False ), is_time_reversal=compute_gruneisen_param_kwargs.get( "is_time_reversal", True From 79dd12580201ac376757779821c007aaaf53fbb6 Mon Sep 17 00:00:00 2001 From: naik-aakash Date: Mon, 25 Nov 2024 11:07:18 +0100 Subject: [PATCH 6/6] fix assertions to correct expected derived properties --- tests/common/jobs/test_gruneisen.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/common/jobs/test_gruneisen.py b/tests/common/jobs/test_gruneisen.py index b93169968c..a4cbd95247 100644 --- a/tests/common/jobs/test_gruneisen.py +++ b/tests/common/jobs/test_gruneisen.py @@ -53,8 +53,8 @@ def test_compute_gruneisen_param(tmp_dir, test_dir): "minus": False, } assert gp_doc.derived_properties.average_gruneisen == pytest.approx( - 1.1882292157682082 + 1.1203420586842452, abs=1e-2 ) assert gp_doc.derived_properties.thermal_conductivity_slack == pytest.approx( - 38.861289530152796 + 44.078885068152346, abs=1e-2 )