mirror of https://github.com/abinit/abipy.git
Ignore deprecation warnings issued by pmg if py2.7
This commit is contained in:
parent
ebbf4a9c44
commit
8f7a36e6f7
|
@ -428,12 +428,15 @@ class Robot(object):
|
|||
Return list of (label, ncfile, param) tuples where param is obtained via `func_or_string`.
|
||||
|
||||
Args:
|
||||
func_or_string: Either string or callable defining the quantity to be used for sorting.
|
||||
func_or_string: Either None, string, callable defining the quantity to be used for sorting.
|
||||
If string, it's assumed that the ncfile has an attribute with the same name and getattr is invoked.
|
||||
If callable, the output of callable(ncfile) is used.
|
||||
If None, no sorting is performed.
|
||||
reverse: If set to True, then the list elements are sorted as if each comparison were reversed.
|
||||
"""
|
||||
if callable(func_or_string):
|
||||
if func_or_string is None:
|
||||
return [(label, ncfile, label) for (label, ncfile) in self]
|
||||
elif callable(func_or_string):
|
||||
items = [(label, ncfile, func_or_string(ncfile)) for (label, ncfile) in self]
|
||||
else:
|
||||
# Assume string and attribute with the same name.
|
||||
|
|
|
@ -523,7 +523,8 @@ class OpticRobot(Robot, RobotWithEbands, NotebookWriter):
|
|||
"all" if all components available on file should be plotted on the same ax.
|
||||
what_list: List of quantities to plot. "re" for real part, "im" for imaginary.
|
||||
Accepts also "abs", "angle".
|
||||
sortby: Define the convergence parameter, sort files and produce plot labels. Can be string or function.
|
||||
sortby: Define the convergence parameter, sort files and produce plot labels. Can be None, string or function.
|
||||
If None, no sorting is performed.
|
||||
If string, it's assumed that the ncfile has an attribute with the same name and getattr is invoked.
|
||||
If callable, the output of callable(ncfile) is used.
|
||||
itemp: Temperature index.
|
||||
|
@ -584,7 +585,8 @@ class OpticRobot(Robot, RobotWithEbands, NotebookWriter):
|
|||
itemp: Temperature index.
|
||||
what_list: List of quantities to plot. "re" for real part, "im" for imaginary.
|
||||
Accepts also "abs", "angle".
|
||||
sortby: Define the convergence parameter, sort files and produce plot labels. Can be string or function.
|
||||
sortby: Define the convergence parameter, sort files and produce plot labels. Can be None, string or function.
|
||||
If None, no sorting is performed.
|
||||
If string, it's assumed that the ncfile has an attribute with the same name and getattr is invoked.
|
||||
If callable, the output of callable(ncfile) is used.
|
||||
decompose: True to plot individual contributions.
|
||||
|
|
|
@ -63,7 +63,7 @@ class A2F(object):
|
|||
# """Computes the momenta of a2F(w)"""
|
||||
# raise NotImplementedError()
|
||||
|
||||
#def get_mcmillan_Tc(self, mustar):
|
||||
#def get_mcmillan_tc(self, mustar):
|
||||
# """
|
||||
# Computes the critical temperature with the McMillan equation and the input mustar.
|
||||
# """
|
||||
|
@ -203,15 +203,16 @@ class EphFile(AbinitNcFile, Has_Structure, Has_ElectronBands, NotebookWriter):
|
|||
self.reader.close()
|
||||
|
||||
@add_fig_kwargs
|
||||
def plot_eph_strength(self, what="lambda", ylims=None, ax=None, **kwargs):
|
||||
def plot_eph_strength(self, what="lambda", ylims=None, ax=None, label=None, **kwargs):
|
||||
"""
|
||||
Plot phonon bands with eph coupling strenght lambda(q, nu)
|
||||
|
||||
Args:
|
||||
what: `lambda` for eph strength, gamma for ph linewidth.
|
||||
what: `lambda` for eph strength, gamma for phonon linewidths.
|
||||
ylims: Set the data limits for the y-axis. Accept tuple e.g. `(left, right)`
|
||||
or scalar e.g. `left`. If left (right) is None, default values are used
|
||||
ax: matplotlib :class:`Axes` or None if a new figure should be created.
|
||||
label: String used to label the plot in the legend.
|
||||
|
||||
Returns:
|
||||
`matplotlib` figure
|
||||
|
@ -242,15 +243,15 @@ class EphFile(AbinitNcFile, Has_Structure, Has_ElectronBands, NotebookWriter):
|
|||
|
||||
xvals = np.arange(len(self.phbands.qpoints))
|
||||
for nu in self.phbands.branches:
|
||||
ax.plot(xvals, yvals[:, nu])
|
||||
ax.plot(xvals, yvals[:, nu],
|
||||
label=label if (nu == 0 and label) else None)
|
||||
|
||||
#if "color" not in kwargs and not match_bands:
|
||||
# kwargs["color"] = "black"
|
||||
#if "linewidth" not in kwargs:
|
||||
# kwargs["linewidth"] = 2.0
|
||||
#if "color" not in kwargs and not match_bands: kwargs["color"] = "black"
|
||||
#if "linewidth" not in kwargs: kwargs["linewidth"] = 2.0
|
||||
#ax.plot(xvals, yvals.T)
|
||||
|
||||
#set_axlims(ax, ylims, "y")
|
||||
set_axlims(ax, ylims, "y")
|
||||
if label: ax.legend(loc="best")
|
||||
return fig
|
||||
|
||||
@add_fig_kwargs
|
||||
|
@ -425,13 +426,39 @@ class EphRobot(Robot, RobotWithEbands, RobotWithPhbands, NotebookWriter):
|
|||
"""
|
||||
EXT = "EPH"
|
||||
|
||||
@add_fig_kwargs
|
||||
def plot_lambda_convergence(self, what="lambda", sortby="nkpt", ylims=None, ax=None, **kwargs):
|
||||
"""
|
||||
Plot the convergence of the lambda(q, nu) parameters wrt to `sortby` parameter.
|
||||
|
||||
Args:
|
||||
what: `lambda` for eph strength, gamma for phonon linewidths.
|
||||
sortby: Define the convergence parameter, sort files and produce plot labels. Can be None, string or function.
|
||||
If None, no sorting is performed.
|
||||
If string, it's assumed that the ncfile has an attribute with the same name and getattr is invoked.
|
||||
If callable, the output of callable(ncfile) is used.
|
||||
ylims: Set the data limits for the y-axis. Accept tuple e.g. `(left, right)`
|
||||
or scalar e.g. `left`. If left (right) is None, default values are used
|
||||
ax: matplotlib :class:`Axes` or None if a new figure should be created.
|
||||
|
||||
Returns:
|
||||
`matplotlib` figure
|
||||
"""
|
||||
ax, fig, plt = get_ax_fig_plt(ax=ax)
|
||||
for label, ncfile, param in self.sortby(sortby):
|
||||
ncfile.plot_eph_strength(what=what, ax=ax, ylims=ylims,
|
||||
label="%s %s" % (sortby, param) if not callable(sortby) else str(param),
|
||||
show=False)
|
||||
return fig
|
||||
|
||||
@add_fig_kwargs
|
||||
def plot_a2f_convergence(self, sortby="nkpt", ax=None, xlims=None, **kwargs):
|
||||
"""
|
||||
Plot the convergence of the Eliashberg function wrt to `sortby` parameter.
|
||||
|
||||
Args:
|
||||
sortby: Define the convergence parameter, sort files and produce plot labels. Can be string or function.
|
||||
sortby: Define the convergence parameter, sort files and produce plot labels. Can be None, string or function.
|
||||
If None, no sorting is performed.
|
||||
If string, it's assumed that the ncfile has an attribute with the same name and getattr is invoked.
|
||||
If callable, the output of callable(ncfile) is used.
|
||||
ax: matplotlib :class:`Axes` or None if a new figure should be created.
|
||||
|
@ -462,7 +489,9 @@ class EphRobot(Robot, RobotWithEbands, RobotWithPhbands, NotebookWriter):
|
|||
nb.cells.extend([
|
||||
#nbv.new_markdown_cell("# This is a markdown cell"),
|
||||
nbv.new_code_cell("robot = abilab.EphRobot(*%s)\nrobot.trim_paths()\nrobot" % str(args)),
|
||||
nbv.new_code_cell("robot.plot_lambda_convergence();"),
|
||||
nbv.new_code_cell("robot.plot_a2f_convergence();"),
|
||||
#nbv.new_code_cell("robot.plot_a2ftr_convergence();"),
|
||||
])
|
||||
|
||||
return self._write_nb_nbpath(nb, nbpath)
|
||||
|
|
|
@ -28,7 +28,7 @@ class SigEPhFile(AbinitNcFile, Has_Structure, Has_ElectronBands, NotebookWriter)
|
|||
|
||||
.. code-block:: python
|
||||
|
||||
with SigEPhFile("out_SIGMAPH.nc") as ncfile:
|
||||
with SigEPhFile("out_SIGEPH.nc") as ncfile:
|
||||
print(ncfile)
|
||||
ncfile.ebands.plot()
|
||||
"""
|
||||
|
@ -158,7 +158,6 @@ class SigEPhFile(AbinitNcFile, Has_Structure, Has_ElectronBands, NotebookWriter)
|
|||
"""
|
||||
Reads data from file and constructs objects.
|
||||
"""
|
||||
|
||||
def read_phbands_qpath(self):
|
||||
"""Read and return PhononBands."""
|
||||
structure = self.read_structure()
|
||||
|
|
|
@ -62,7 +62,8 @@ class EphRobotTest(AbipyTest):
|
|||
#assert [t[2] for t in robot.sortby("nkpt")] == [10, 60, 182]
|
||||
|
||||
# Test plot methods
|
||||
#if self.has_matplotlib():
|
||||
if self.has_matplotlib():
|
||||
assert robot.plot_lambda_convergence(show=False)
|
||||
#assert robot.plot_a2f_convergence(show=False)
|
||||
|
||||
if self.has_nbformat():
|
||||
|
|
|
@ -3,38 +3,36 @@
|
|||
This example shows how to plot the optical properties computed by optic within
|
||||
the independent-particle approximation, no local-field effects and no excitonic effects.
|
||||
"""
|
||||
from abipy.abilab import abiopen
|
||||
from abipy import abilab
|
||||
import abipy.data as abidata
|
||||
|
||||
# Here we use one of the OPTIC.nc files shipped with abipy.
|
||||
# Replace filename with the path to your OPTIC.nc file.
|
||||
filename = abidata.ref_file("gaas_121212_OPTIC.nc")
|
||||
|
||||
ncfile = abiopen(filename)
|
||||
ncfile = abilab.abiopen(filename)
|
||||
|
||||
# Optic files have a Structure and an ElectronBands object.
|
||||
#ncfile.ebands.plot()
|
||||
|
||||
# To plot linear dielectric tensor for all
|
||||
# tensor components available in the file:
|
||||
# To plot linear dielectric tensor and other optical
|
||||
# properties for all tensor components available in the file:
|
||||
ncfile.plot_linopt(title="Linear dielectric function")
|
||||
|
||||
# To plot linear dielectric tensor:
|
||||
# To plot the second Harmonic tensor
|
||||
ncfile.plot_shg(title="Second Harmonic Generation")
|
||||
|
||||
# Remember to close the file.
|
||||
ncfile.close()
|
||||
|
||||
# Use OpticRobot to analyze multiple file e.g convergence studies.
|
||||
from abipy.electrons.optic import OpticRobot
|
||||
|
||||
filenames = [
|
||||
abidata.ref_file("gaas_444_OPTIC.nc"),
|
||||
abidata.ref_file("gaas_888_OPTIC.nc"),
|
||||
abidata.ref_file("gaas_121212_OPTIC.nc"),
|
||||
]
|
||||
|
||||
robot = OpticRobot.from_files(filenames)
|
||||
robot = abilab.OpticRobot.from_files(filenames)
|
||||
|
||||
robot.plot_linopt_convergence(title="Convergence of $\epsilon$ wrt nkpt")
|
||||
|
||||
|
|
|
@ -36,8 +36,8 @@ class ScriptTest(AbipyTest):
|
|||
verbose = "-vv"
|
||||
|
||||
# Don’t raise an exception if anything is printed to stderr
|
||||
#if sys.version_info[0] <= 2 else str(s)
|
||||
expect_stderr = True # else tests fail due to warnings and deprecation messages
|
||||
# else tests fail due to deprecation warnings issued by pymatgen if oy2.7
|
||||
expect_stderr = sys.version_info[0] <= 2
|
||||
|
||||
def get_env(self, check_help_version=True):
|
||||
#import tempfile
|
||||
|
@ -51,7 +51,7 @@ class ScriptTest(AbipyTest):
|
|||
|
||||
if check_help_version:
|
||||
# Start with --help. If this does not work...
|
||||
r = env.run(self.script, "--help")
|
||||
r = env.run(self.script, "--help", expect_stderr=self.expect_stderr)
|
||||
assert r.returncode == 0
|
||||
|
||||
# Script must provide a version option
|
||||
|
@ -297,9 +297,11 @@ class TestAbicomp(ScriptTest):
|
|||
|
||||
#args = abidata.ref_files()
|
||||
#r = env.run(self.script, "dfpt2_scf", *args, self.loglevel, self.verbose,
|
||||
# expect_stderr=self.expect_stderr)
|
||||
|
||||
#args = abidata.ref_files()
|
||||
#r = env.run(self.script, "time", *args, self.loglevel, self.verbose,
|
||||
# expect_stderr=self.expect_stderr)
|
||||
|
||||
|
||||
class TestAbirun(ScriptTest):
|
||||
|
|
Loading…
Reference in New Issue