Skip to content

Commit

Permalink
Fix bump phonopy (#1006)
Browse files Browse the repository at this point in the history
* bump phonopy version

* Update pyproject.toml

* replace bs plotter with pymatgen implementation > reduce code repetition

* replace bs plotter with pymatgen implementation > reduce code repetition

* switch off grunesien computation at gamma (unstable)

* fix assertions to correct expected derived properties

* fix failing test (use correct reference data)

* remove non used test_data, rename Si_phonons_4 > Si_phonons_3

* point to renamed ref test_data

---------

Co-authored-by: J. George <[email protected]>
  • Loading branch information
naik-aakash and JaGeo authored Nov 30, 2024
1 parent 6349766 commit 4bcf127
Show file tree
Hide file tree
Showing 94 changed files with 42 additions and 146 deletions.
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
)
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/inputs/INCAR.gz
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/inputs/POSCAR.gz
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/outputs/CONTCAR.gz
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/outputs/INCAR.gz
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/outputs/INCAR.orig.gz
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/outputs/OUTCAR.gz
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/outputs/POSCAR.gz
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/outputs/POSCAR.orig.gz
Binary file not shown.
Binary file not shown.
Binary file modified tests/test_data/vasp/Si_phonons_3/static/outputs/vasprun.xml.gz
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
77 changes: 28 additions & 49 deletions tests/vasp/flows/test_phonons.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ def test_phonon_wf_vasp_only_displacements_no_structural_transformation(
):
# mapping from job name to directory containing test files
ref_paths = {
"phonon static 1/1": "Si_phonons_3/phonon_static_1_1",
"static": "Si_phonons_3/static",
"phonon static 1/1": "Si_phonons_2/phonon_static_1_1",
"static": "Si_phonons_2/static",
}

# settings passed to fake_run_vasp; adjust these to check for certain INCAR settings
Expand All @@ -145,33 +145,27 @@ def test_phonon_wf_vasp_only_displacements_no_structural_transformation(
store_force_constants=False,
prefer_90_degrees=False,
generate_frequencies_eigenvectors_kwargs={"tstep": 100},
).make(si_structure)
).make(si_structure.to_conventional())

# run the flow or job and ensure that it finished running successfully
responses = run_locally(job, create_folders=True, ensure_success=True)

# validate the outputs
assert isinstance(responses[job.jobs[-1].uuid][1].output, PhononBSDOSDoc)

assert_allclose(
responses[job.jobs[-1].uuid][1].output.free_energies,
[5927.157337, 5905.309813, 5439.530414, 4207.379685, 2297.576147],
)
assert_allclose(
responses[job.jobs[-1].uuid][1].output.entropies,
[0.0, 1.256496, 8.511348, 15.928285, 22.063785],
atol=1e-6,
)
assert_allclose(
responses[job.jobs[-1].uuid][1].output.heat_capacities,
[0.0, 4.958763, 15.893881, 20.311967, 22.196143],
# validate settings
assert responses[job.jobs[-1].uuid][1].output.code == "vasp"
assert isinstance(
responses[job.jobs[-1].uuid][1].output.phonopy_settings,
PhononComputationalSettings,
)

assert_allclose(
responses[job.jobs[-1].uuid][1].output.internal_energies,
[5927.157337, 6030.959432, 7141.800004, 8985.865319, 11123.090225],
assert responses[job.jobs[-1].uuid][1].output.phonopy_settings.npoints_band == 101
assert (
responses[job.jobs[-1].uuid][1].output.phonopy_settings.kpath_scheme
== "seekpath"
)
phonopy_settings = responses[job.jobs[-1].uuid][1].output.phonopy_settings
assert phonopy_settings.kpoint_density_dos == 7_000

# validate the outputs
assert isinstance(responses[job.jobs[-1].uuid][1].output, PhononBSDOSDoc)
assert isinstance(
responses[job.jobs[-1].uuid][1].output.phonon_bandstructure,
PhononBandStructureSymmLine,
Expand All @@ -187,7 +181,7 @@ def test_phonon_wf_vasp_only_displacements_no_structural_transformation(
assert isinstance(responses[job.jobs[-1].uuid][1].output.jobdirs, PhononJobDirs)
assert isinstance(responses[job.jobs[-1].uuid][1].output.uuids, PhononUUIDs)
assert_allclose(
responses[job.jobs[-1].uuid][1].output.total_dft_energy, -5.74525804
responses[job.jobs[-1].uuid][1].output.total_dft_energy, -5.74555232
)
assert responses[job.jobs[-1].uuid][1].output.born is None
assert responses[job.jobs[-1].uuid][1].output.epsilon_static is None
Expand All @@ -196,40 +190,25 @@ def test_phonon_wf_vasp_only_displacements_no_structural_transformation(
)
assert_allclose(
responses[job.jobs[-1].uuid][1].output.primitive_matrix,
((0, 1, 0), (0, 0, 1), (1, 0, 0)),
((0, 0.5, 0.5), (0.5, 0, 0.5), (0.5, 0.5, 0)),
atol=1e-8,
)
assert_allclose(
responses[job.jobs[-1].uuid][1].output.primitive_matrix,
((0, 1, 0), (0, 0, 1), (1, 0, 0)),
)
assert responses[job.jobs[-1].uuid][1].output.code == "vasp"
assert isinstance(
responses[job.jobs[-1].uuid][1].output.phonopy_settings,
PhononComputationalSettings,
)
assert responses[job.jobs[-1].uuid][1].output.phonopy_settings.npoints_band == 101
assert (
responses[job.jobs[-1].uuid][1].output.phonopy_settings.kpath_scheme
== "seekpath"
responses[job.jobs[-1].uuid][1].output.free_energies,
[6115.980051, 6059.749756, 5490.929122, 4173.234384, 2194.164562],
)
phonopy_settings = responses[job.jobs[-1].uuid][1].output.phonopy_settings
assert phonopy_settings.kpoint_density_dos == 7_000
assert_allclose(
responses[job.jobs[-1].uuid][1].output.entropies,
[0.0, 1.256496, 8.511348, 15.928285, 22.063785],
[0.0, 2.194216, 9.478603, 16.687079, 22.702177],
atol=1e-6,
)
assert_allclose(
responses[job.jobs[-1].uuid][1].output.heat_capacities,
[0.0, 4.958763, 15.893881, 20.311967, 22.196143],
atol=1e-6,
[0.0, 5.750113, 15.408866, 19.832123, 21.842104],
)

assert_allclose(
responses[job.jobs[-1].uuid][1].output.internal_energies,
[5927.157337, 6030.959432, 7141.800004, 8985.865319, 11123.090225],
atol=1e-6,
[6115.980051, 6279.17132, 7386.649622, 9179.358187, 11275.035523],
)


Expand Down Expand Up @@ -542,11 +521,11 @@ def test_phonon_wf_vasp_only_displacements_optional_settings(
def test_phonon_wf_vasp_all_steps(mock_vasp, clean_dir, si_structure: Structure):
# mapping from job name to directory containing test files
ref_paths = {
"phonon static 1/1": "Si_phonons_4/phonon_static_1_1",
"static": "Si_phonons_4/static",
"tight relax 1": "Si_phonons_4/tight_relax_1",
"tight relax 2": "Si_phonons_4/tight_relax_2",
"dielectric": "Si_phonons_4/dielectric",
"phonon static 1/1": "Si_phonons_3/phonon_static_1_1",
"static": "Si_phonons_3/static",
"tight relax 1": "Si_phonons_3/tight_relax_1",
"tight relax 2": "Si_phonons_3/tight_relax_2",
"dielectric": "Si_phonons_3/dielectric",
}

# settings passed to fake_run_vasp; adjust these to check for certain INCAR settings
Expand Down

0 comments on commit 4bcf127

Please sign in to comment.