Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[WIP] Fix bump phonopy #1006

Draft
wants to merge 12 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ strict = [
"numpy",
"openmm-mdanalysis-reporter==0.1.0",
"openmm==8.1.1",
"phonopy==2.27.0",
"phonopy==2.30.1",
"pydantic-settings==2.6.1",
"pydantic==2.9.2",
"pymatgen-analysis-defects==2024.10.22",
Expand Down
105 changes: 11 additions & 94 deletions src/atomate2/common/schemas/gruneisen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -164,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
Expand All @@ -184,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
Expand Down Expand Up @@ -228,9 +219,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,

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 = {
Expand Down Expand Up @@ -261,82 +257,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()
4 changes: 2 additions & 2 deletions tests/common/jobs/test_gruneisen.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Loading