Skip to content

Commit

Permalink
qha_aproximation.py --> vzsisa.py
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Dec 19, 2024
1 parent d782893 commit b46b593
Show file tree
Hide file tree
Showing 11 changed files with 97 additions and 103 deletions.
7 changes: 5 additions & 2 deletions abipy/dfpt/deformation_utils.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
# deformation_utils.py
from __future__ import annotations

import numpy as np
from pymatgen.core import Structure, Lattice, Element
import re

from pymatgen.core import Lattice, Element
#from abipy.core.structure import Structure
from abipy.core.symmetries import AbinitSpaceGroup
from pymatgen.symmetry.analyzer import SpacegroupAnalyzer
from abipy.abio.inputs import AbinitInput
import re


def generate_deformations_volumic(structure, eps_V=0.02, scales=None):
Expand Down
File renamed without changes.
40 changes: 28 additions & 12 deletions abipy/dfpt/qha_aproximation.py → abipy/dfpt/vzsisa.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# coding: utf-8
"""
Classes for V-ZSISA approximation.
Classes for post-processing QHA results obtained with the V-ZSISA approximation.
See PHYSICAL REVIEW B 110, 014103 (2024)
"""
from __future__ import annotations
Expand All @@ -19,7 +19,7 @@
from abipy.dfpt.phonons import PhdosFile, PhononDosPlotter


class QHA_App:
class Vzsisa:
"""
Class for the approximations on QHA analysis.
Provides some basic methods and plotting utils.
Expand All @@ -31,7 +31,7 @@ def from_gsr_ddb_files(cls,
gsr_paths: list[PathLike],
ddb_paths: list[PathLike],
verbose: int = 0,
**extra_kwargs) -> QHA_App:
**extra_kwargs) -> Vzsisa:
"""
Creates an instance from a list of GSR files and a list of DDB files.
This is a simplified interface that computes the PHDOS.nc files automatically
Expand Down Expand Up @@ -71,7 +71,7 @@ def from_gsr_ddb_files(cls,
return cls.from_gsr_phdos_files(gsr_paths, phdos_paths)

@classmethod
def from_gsr_phdos_files(cls, gsr_paths: list[str], phdos_paths: list[str]) -> QHA_App:
def from_gsr_phdos_files(cls, gsr_paths: list[str], phdos_paths: list[str]) -> Vzsisa:
"""
Creates an instance from a list of GSR files and a list of PHDOS.nc files.
Expand Down Expand Up @@ -112,11 +112,8 @@ def from_gsr_phdos_files(cls, gsr_paths: list[str], phdos_paths: list[str]) -> Q

return cls(structures, structures_from_phdos, index_list, phdoses, energies, pressures)

# FIXME: This to maintain previous interface. It should be removed
from_files_app = from_gsr_phdos_files

@classmethod
def from_ddb_phdos_files(cls, ddb_paths: list[str], phdos_paths: list[str]) -> QHA_App:
def from_ddb_phdos_files(cls, ddb_paths: list[str], phdos_paths: list[str]) -> Vzsisa:
"""
Creates an instance from a list of DDB files and a list of PHDOS.nc files.
Expand Down Expand Up @@ -158,9 +155,6 @@ def from_ddb_phdos_files(cls, ddb_paths: list[str], phdos_paths: list[str]) -> Q

return cls(structures, structures_from_phdos, index_list, phdoses, energies, pressures)

# FIXME: This to maintain previous interface. It should be removed
from_files_app_ddb = from_ddb_phdos_files

def __init__(self, structures, structures_from_phdos, index_list, phdoses, energies, pressures,
eos_name: str = 'vinet', pressure: float = 0.0):
"""
Expand Down Expand Up @@ -529,6 +523,8 @@ def plot_energies(self, tstart=0, tstop=1000, num=1, ax=None, fontsize=10, **kwa
ax.plot(f.min_vol, f.min_en - self.energies[self.iv0], color='r', linestyle='dashed' , lw=1, marker='o', ms=5)
set_grid_legend(ax, fontsize, xlabel=r'V (${\AA}^3$)', ylabel='E (eV)', legend=False)

fig.suptitle("Energies as a function of volume for different T")

return fig

def get_phdos_plotter(self) -> PhononDosPlotter:
Expand Down Expand Up @@ -605,6 +601,8 @@ def plot_vol_vs_t(self, tstart=0, tstop=1000, num=101, fontsize=10, ax=None, **k
set_grid_legend(ax, fontsize, xlabel='T (K)', ylabel=r'V (${\AA}^3$)')
ax.set_xlim(tstart, tstop)

fig.suptitle("Volume as a function of T")

return fig

def get_thermal_expansion_coeff(self, tstart=0, tstop=1000, num=101, tref=None) -> Function1D:
Expand Down Expand Up @@ -775,6 +773,8 @@ def plot_thermal_expansion_coeff(self, tstart=0, tstop=1000, num=101, tref=None,
ax.set_xlim(tstart, tstop)
ax.get_yaxis().get_major_formatter().set_powerlimits((0, 0))

fig.suptitle("Volumetric thermal expansion coefficient as a function of T")

return fig

def get_abc(self, volumes, num=101) -> tuple:
Expand Down Expand Up @@ -924,6 +924,8 @@ def plot_thermal_expansion_coeff_abc(self, tstart=0, tstop=1000, num=101, tref=N
ax.set_xlim(tstart, tstop)
ax.get_yaxis().get_major_formatter().set_powerlimits((0, 0))

fig.suptitle("Thermal expansion coefficient as a function of T")

return fig

@add_fig_kwargs
Expand Down Expand Up @@ -1107,6 +1109,8 @@ def plot_abc_vs_t(self, tstart=0, tstop=1000, num=101, lattice=None, tref=None,
ax.set_xlim(tstart, tstop)
ax.get_yaxis().get_major_formatter().set_powerlimits((0, 0))

fig.suptitle("Lattice as a function of T")

return fig

@add_fig_kwargs
Expand Down Expand Up @@ -1181,6 +1185,8 @@ def plot_angles_vs_t(self, tstart=0, tstop=1000, num=101, angle=None, tref=None,
ax.set_xlim(tstart, tstop)
ax.get_yaxis().get_major_formatter().set_powerlimits((0, 0))

fig.suptitle("Angles as a function of T")

return fig

def fit_forth(self, tstart=0, tstop=1000, num=1, energy="energy", volumes="volumes"):
Expand Down Expand Up @@ -1434,6 +1440,8 @@ def plot_vol_vs_t_4th(self, tstart=0, tstop=1000, num=101, ax=None, fontsize=10,
set_grid_legend(ax, fontsize, xlabel='T (K)', ylabel=r'V (${\AA}^3$)')
ax.set_xlim(tstart, tstop)

fig.suptitle("Volume as a function of T")

return fig

def get_thermal_expansion_coeff_4th(self, tstart=0, tstop=1000, num=101, tref=None) -> np.ndarray:
Expand Down Expand Up @@ -1558,7 +1566,7 @@ def plot_thermal_expansion_coeff_4th(self, tstart=0, tstop=1000, num=101, tref=N
ds_dv = ds_dv + (df_t[:,iv0+2]-2*df_t[:,iv0+1]+df_t[:,iv0])/dV**2 * (vol3_4th[:]-volumes[iv0+1])
if tref is None:
alpha_3 = - 1/vol3_4th[:] * ds_dv / (E2D_V[:]+dfe_dV2[:])
else :
else:
vol3_4th_ref = self.vol_Einf_Vib2_forth(num=1, tstop=tref, tstart=tref)
alpha_3 = - 1/vol3_4th_ref * ds_dv / (E2D_V[:]+dfe_dV2[:])

Expand Down Expand Up @@ -1602,6 +1610,8 @@ def plot_thermal_expansion_coeff_4th(self, tstart=0, tstop=1000, num=101, tref=N
ax.set_xlim(tstart, tstop)
ax.get_yaxis().get_major_formatter().set_powerlimits((0, 0))

fig.suptitle("Volumetric thermal expansion coefficient as a function of T")

return fig

@add_fig_kwargs
Expand Down Expand Up @@ -1676,6 +1686,8 @@ def plot_abc_vs_t_4th(self, tstart=0, tstop=1000, num=101, lattice=None, tref=No
ax.set_xlim(tstart, tstop)
ax.get_yaxis().get_major_formatter().set_powerlimits((0, 0))

fig.suptitle("Lattice as a function of T")

return fig

@add_fig_kwargs
Expand Down Expand Up @@ -1750,6 +1762,8 @@ def plot_angles_vs_t_4th(self, tstart=0, tstop=1000, num=101, angle=None, tref=N
ax.set_xlim(tstart, tstop)
ax.get_yaxis().get_major_formatter().set_powerlimits((0, 0))

fig.suptitle("Angles as a function of T")

return fig

@add_fig_kwargs
Expand Down Expand Up @@ -1858,6 +1872,8 @@ def plot_thermal_expansion_coeff_abc_4th(self, tstart=0, tstop=1000, num=101, tr
ax.set_xlim(tstart, tstop)
ax.get_yaxis().get_major_formatter().set_powerlimits((0, 0))

fig.suptitle("Thermal expansion coefficient as a function of T")

return fig

@add_fig_kwargs
Expand Down
2 changes: 1 addition & 1 deletion abipy/examples/flows/run_qha_vzsisa.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import abipy.data as abidata

from abipy import flowtk
from abipy.flowtk.qha import VzsisaFlow
from abipy.flowtk.vzsisa import VzsisaFlow


def build_flow(options):
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import os
import abipy.data as abidata

from abipy.dfpt.qha_aproximation import QHA_App
from abipy.dfpt.vzsisa import Vzsisa

# Root points to the directory in the git submodule with the output results.
root = os.path.join(abidata.dirpath, "data_v-ZSISA-QHA.git", "Si_v_ZSISA_approximation")
Expand All @@ -23,64 +23,64 @@
ddb_paths = [os.path.join(root, "scale_{:d}_GSR_DDB".format(s)) for s in strains]
dos_paths = [os.path.join(root, "scale_{:d}_PHDOS.nc".format(s)) for s in strains2]

qha = QHA_App.from_files_app_ddb(ddb_paths, dos_paths)
qha = Vzsisa.from_files_app_ddb(ddb_paths, dos_paths)
tstart, tstop = 0, 800

#%%
qha.plot_energies(tstop=tstop, tstart=tstart, num=11,
title="Energies as a function of volume for different T")
# Plot Energies as a function of volume for different T
qha.plot_energies(tstop=tstop, tstart=tstart, num=11)

#%%
qha.plot_vol_vs_t(tstop=tstop, tstart=tstart, num=101,
title="Volume as a function of T")
# Plot Volume as a function of T
qha.plot_vol_vs_t(tstop=tstop, tstart=tstart, num=101)

#%%
qha.plot_abc_vs_t(tstop=tstop, tstart=tstart, num=101,
title="Lattice as a function of T")

# Plot Lattice as a function of T
qha.plot_abc_vs_t(tstop=tstop, tstart=tstart, num=101)

#%%
qha.plot_abc_vs_t(tstop=tstop, tstart=tstart, num=101, lattice="b",
title="Lattice as a function of T")
# Plot Lattice as a function of T")
qha.plot_abc_vs_t(tstop=tstop, tstart=tstart, num=101, lattice="b")

#%%
qha.plot_thermal_expansion_coeff(tstop=tstop, tstart=tstart ,num=101,
title="Volumetric thermal expansion coefficient as a function of T")
# Plot Volumetric thermal expansion coefficient as a function of T
qha.plot_thermal_expansion_coeff(tstop=tstop, tstart=tstart ,num=101)

#%%
qha.plot_thermal_expansion_coeff_abc(tstop=tstop, tstart=tstart ,num=101,
title="Thermal expansion coefficient as a function of T")
# Plot Thermal expansion coefficient as a function of T
qha.plot_thermal_expansion_coeff_abc(tstop=tstop, tstart=tstart ,num=101)

#%%
qha.plot_angles_vs_t(tstop=tstop, tstart=tstart, num=101,
title="Angles as a function of T")
# Plot Angles as a function of T
qha.plot_angles_vs_t(tstop=tstop, tstart=tstart, num=101)

#%%
# 4th order polinomial
qha.plot_vol_vs_t_4th(tstop=tstop, tstart=tstart, num=101,
title="Volume as a function of T")
#
# Plot Volume as a function of T. 4th order polinomial
qha.plot_vol_vs_t_4th(tstop=tstop, tstart=tstart, num=101)

#%%
qha.plot_abc_vs_t_4th(tstop=tstop, tstart=tstart, num=101, lattice="a",
title="Lattice as a function of T")
# Plot Lattice as a function of T. 4th order polinomial
qha.plot_abc_vs_t_4th(tstop=tstop, tstart=tstart, num=101, lattice="a")

#%%
qha.plot_abc_vs_t_4th(tstop=tstop, tstart=tstart,
title="Lattice as a function of T")
# Plot Lattice as a function of T. 4th order polinomial
qha.plot_abc_vs_t_4th(tstop=tstop, tstart=tstart)

#%%
qha.plot_thermal_expansion_coeff_4th(tref=293,
title="Volumetric thermal expansion coefficient as a function of T")
# Plot Volumetric thermal expansion coefficient as a function of T
qha.plot_thermal_expansion_coeff_4th(tref=293)

#%%
qha.plot_thermal_expansion_coeff_abc_4th(tstop=tstop, tstart=tstart ,num=101, tref=293,
title="Thermal expansion coefficient as a function of T")
# Plot Thermal expansion coefficient as a function of T
qha.plot_thermal_expansion_coeff_abc_4th(tstop=tstop, tstart=tstart ,num=101, tref=293)

#%%
qha.plot_angles_vs_t_4th(tstop=tstop, tstart=tstart, num=101, angle=3,
title="Angles as a function of T")
# Plot Angles as a function of T.
qha.plot_angles_vs_t_4th(tstop=tstop, tstart=tstart, num=101, angle=3)


#%%
# Create plotter to plot all the phonon DOS.
phdos_plotter = qha.get_phdos_plotter()
phdos_plotter.combiplot()
8 changes: 7 additions & 1 deletion abipy/flowtk/psrepos.py
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,13 @@ def get_oncvpsp_pseudos(xc_name: str, version: str, relativity_type: str = "SR",
ps_generator, project_name = OncvpspRepo.ps_generator, OncvpspRepo.project_name
repo_name = f"{ps_generator}-{xc_name}-{relativity_type}-{project_name}v{version}"

return get_repo_from_name(repo_name).get_pseudos(accuracy)
repo = get_repo_from_name(repo_name)

# Istall it at runtime if needed.
if not repo.is_installed():
repo.install()

return repo.get_pseudos(accuracy)


# Installation directory.
Expand Down
File renamed without changes.
Loading

0 comments on commit b46b593

Please sign in to comment.