Skip to content

Commit

Permalink
Add test_qha_general_stress.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Dec 12, 2024
1 parent 3275f0a commit 8aedb34
Show file tree
Hide file tree
Showing 10 changed files with 385 additions and 369 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/gh-pages.yml
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,16 @@ jobs:
mkdir -p $HOME/.abinit/abipy/
cp abipy/data/managers/gh_manager.yml $HOME/.abinit/abipy/manager.yml
cp abipy/data/managers/gh_scheduler.yml $HOME/.abinit/abipy/scheduler.yml
# FIXME TEMPORARY HACK
#pip install git+https://github.com/gmatteo/pymatgen.git@master -U
# TEMPORARY HACK THAT MIGHT BE NEEDED IF THE PYMATGEN GUYS BREAK STUFF
pip install git+https://github.com/gmatteo/pymatgen.git@master -U
- name: Build docs with Sphinx
run: |
conda activate abipy
cd docs
source install.sh
make
make -j
- name: Upload artifact
uses: actions/upload-pages-artifact@v2
Expand Down
2 changes: 2 additions & 0 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ jobs:
mkdir -p $HOME/.abinit/abipy/
cp abipy/data/managers/gh_manager.yml $HOME/.abinit/abipy/manager.yml
cp abipy/data/managers/gh_scheduler.yml $HOME/.abinit/abipy/scheduler.yml
# TEMPORARY HACK THAT MIGHT BE NEEDED IF THE PYMATGEN GUYS BREAK STUFF
pip install git+https://github.com/gmatteo/pymatgen.git@master -U
- name: pytest
run: |
Expand Down
28 changes: 17 additions & 11 deletions abipy/dfpt/qha_2D.py
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
"""
Added to compute ZSISA-QHA for systems with two degrees of freedom (2DOF).
Capable of calculating anisotropic thermal expansion and lattice constants for uniaxial configurations.
Requires PHDOS.nc and DDB files for GSR calculations or _GSR.nc files.
If PHDOS.nc is available for all structures, normal interpolation for QHA will be applied.
Supports the use of six PHDOS.nc files for specific structures to employ the E_infVib2 approximation.
"""

import os
import abc
import numpy as np
import abipy.core.abinit_units as abu

#from scipy.interpolate import UnivariateSpline
#from monty.collections import dict2namedtuple
#from monty.functools import lazy_property
from abipy.tools.plotting import add_fig_kwargs, get_ax_fig_plt, get_axarray_fig_plt
from abipy.tools.typing import Figure
from abipy.electrons.gsr import GsrFile
from abipy.dfpt.ddb import DdbFile
from abipy.dfpt.phonons import PhdosFile # PhononBandsPlotter, PhononDos,
Expand Down Expand Up @@ -52,7 +60,7 @@ def __init__(self, structures, doses, energies, structures_from_phdos, eos_name=
self.min_energy_idx = np.unravel_index(np.nanargmin(self.energies), self.energies.shape)

@add_fig_kwargs
def plot_energies(self, ax=None, **kwargs):
def plot_energies(self, ax=None, **kwargs) -> Figure:
"""
Plot energy surface and visualize minima in a 3D plot.
Expand Down Expand Up @@ -127,14 +135,13 @@ def find_minimum(self, f_interp, xy_init, tol=1e-6, max_iter=1000, step_size=0.0
return xy[0], xy[1], min_energy

@add_fig_kwargs
def plot_free_energies(self, tstart=800 , tstop=0 ,num=5, ax=None, **kwargs):
def plot_free_energies(self, tstart=800 , tstop=0 ,num=5, ax=None, **kwargs) -> Figure:
"""
Plot free energy as a function of temperature in a 3D plot.
Args:
ax: Matplotlib axis for the plot.
"""

ax, fig, plt = get_ax_fig_plt(ax, figsize=(10, 8))
ax = fig.add_subplot(111, projection='3d') # Create a 3D subplot

Expand Down Expand Up @@ -222,7 +229,7 @@ def plot_free_energies(self, tstart=800 , tstop=0 ,num=5, ax=None, **kwargs):
return fig

@add_fig_kwargs
def plot_thermal_expansion(self, tstart=800, tstop=0, num=81, ax=None, **kwargs):
def plot_thermal_expansion(self, tstart=800, tstop=0, num=81, ax=None, **kwargs) -> Figure:
"""
Plots thermal expansion coefficients along the a-axis, c-axis, and volumetric alpha.
Uses both QHA and a 9-point stencil for comparison.
Expand All @@ -234,7 +241,6 @@ def plot_thermal_expansion(self, tstart=800, tstop=0, num=81, ax=None, **kwargs)
ax: Matplotlib axis object for plotting.
**kwargs: Additional arguments for customization.
"""

tmesh = np.linspace(tstart, tstop, num)
ph_energies = self.get_vib_free_energies(tstart, tstop, num)
ax, fig, plt = get_ax_fig_plt(ax, figsize=(10, 8)) # Ensure a valid plot axis
Expand Down Expand Up @@ -321,15 +327,15 @@ def plot_thermal_expansion(self, tstart=800, tstop=0, num=81, ax=None, **kwargs)
np.savetxt(file_path, data_to_save, fmt='%4.6e', delimiter='\t\t', header='\t\t\t'.join(columns), comments='')

ax.grid(True)
ax.legend()
ax.legend(loc="best", shadow=True)
ax.set_xlabel('Temperature (K)')
ax.set_ylabel(r'Thermal Expansion Coefficients ($\alpha$)')
plt.savefig("thermal_expansion.pdf", format="pdf", bbox_inches="tight")

return fig

@add_fig_kwargs
def plot_lattice(self, tstart=800, tstop=0, num=81, ax=None, **kwargs):
def plot_lattice(self, tstart=800, tstop=0, num=81, ax=None, **kwargs) -> Figure:
"""
Plots thermal expansion coefficients along the a-axis, c-axis, and volumetric alpha.
Uses both QHA and a 9-point stencil for comparison.
Expand Down Expand Up @@ -416,16 +422,16 @@ def plot_lattice(self, tstart=800, tstop=0, num=81, ax=None, **kwargs):


axs[0].set_ylabel("a")
axs[0].legend()
axs[0].legend(loc="best", shadow=True)
axs[0].grid(True)
axs[0].set_xlabel("Temperature (T)")
axs[1].set_ylabel("c")
axs[1].legend()
axs[1].legend(loc="best", shadow=True)
axs[1].grid(True)
axs[1].set_xlabel("Temperature (T)")
axs[2].set_xlabel("Temperature (T)")
axs[2].set_ylabel("Volume")
axs[2].legend()
axs[2].legend(loc="best", shadow=True)
axs[2].grid(True)

# Adjust layout and show the figure
Expand Down
Loading

0 comments on commit 8aedb34

Please sign in to comment.