Add method to convert Fortran DEN to NC, disable tests requiring new Abinit version

This commit is contained in:
Matteo Giantomassi 2017-07-12 14:12:34 +02:00
parent e3a0044a3f
commit cee2448fbb
13 changed files with 120 additions and 58 deletions

View File

@ -113,7 +113,7 @@ abiext2ncfile = collections.OrderedDict([
("MDF.nc", MdfFile),
("FATBANDS.nc", FatBandsFile),
("FOLD2BLOCH.nc", Fold2BlochNcfile),
("CUT3D_DENPOT.nc", Cut3dDenPotNcFile),
("CUT3DDENPOT.nc", Cut3dDenPotNcFile),
])

View File

@ -2830,6 +2830,10 @@ class OpticInput(AbstractInput, MSONable):
class Cut3DInput(MSONable, object):
"""
This object stores the options to run a single cut3d analysis.
.. warning::
Converters with nspden > 1 won't work since cut3d asks for the ispden index.
"""
def __init__(self, infile_path=None, output_filepath=None, options=None):
"""

View File

@ -156,7 +156,7 @@ class TestStructure(AbipyTest):
mgb2.abi_sanitize(primitive_standard=True)
mgb2.get_conventional_standard_structure()
assert len(mgb2.abi_string)
assert len(mgb2.spglib_summary(verbose=10))
assert len(mgb2.spget_summary(verbose=10))
#print(structure.__repr_html__())
self.serialize_with_pickle(mgb2)

View File

@ -11,6 +11,10 @@
Flow for computing the band structure of silicon.
``run_gruneisen_abinit``:
Phonon band structure of AlAs.
``run_gruneisen_phonopy_si``:
Compute phonon frequencies with phonopy (supercells and finite-difference method).
@ -39,13 +43,17 @@
Band structure and the electron DOS of MgB2 with different k-point samplings.
``run_nonlinear``:
Flow to compute non-linear optical properties with optic.
``run_optic``:
Optical spectra with Optic.
``run_phfrozen_bands``:
``run_phfrozen_ebands``:
Band structure of silicon in a distorted geometry (frozen phonon at q=0)
Electronic band structure of silicon in a distorted geometry (frozen phonon at q=0)
``run_phonons``:

View File

@ -53,6 +53,7 @@ def build_flow(options):
scf_input = make_scf_input(ecut=10, ngkpt=(6, 6, 6))
flow = flowtk.NonLinearCoeffFlow.from_scf_input(workdir, scf_input)
flow.minimum_abinit_version = "8.5.2"
return flow

View File

@ -5,6 +5,7 @@ from __future__ import print_function, division, unicode_literals, absolute_impo
import os
import tempfile
import warnings
from subprocess import call
from abipy.core.testing import AbipyTest
@ -37,10 +38,20 @@ class TestScripts(AbipyTest):
options = parser.parse_args(["--workdir", workdir])
# Instantiate the manager.
options.manager = flowtk.TaskManager.as_manager(options.manager)
try:
flow = module.build_flow(options)
assert flow is not None
# Some flows enforce requirements on the Abinit version.
can_run = True
if hasattr(flow, "minimum_abinit_version"):
if not flow.manager.abinit_build.version_ge(flow.minimum_abinit_version):
can_run = False
warnings.warn("%s requires %s but Abinit version: %s" %
(s, flow.minimum_abinit_version, flow.manager.abinit_build.version))
if can_run:
flow.build_and_pickle_dump()
except Exception:
errors.append("file %s\n %s" % (s, self.straceback()))

View File

@ -138,7 +138,7 @@ class DdbTest(AbipyTest):
# Get emacro and becs
emacro, becs = ddb.anaget_emacro_and_becs(chneut=1, verbose=1)
assert np.all(becs.values == 0)
assert np.all(becs.becs == 0)
assert np.all(becs.values == 0)
repr(becs); str(becs)
assert becs.to_string(verbose=1)

View File

@ -2,6 +2,8 @@
"""Density/potential files in netcdf/fortran format."""
from __future__ import print_function, division, unicode_literals, absolute_import
import os
import tempfile
import numpy as np
from monty.string import marquee
@ -9,13 +11,10 @@ from monty.termcolor import cprint
from monty.functools import lazy_property
from abipy.core.mixins import (AbinitNcFile, Has_Structure, Has_ElectronBands, NotebookWriter,
AbinitFortranFile, CubeFile)
from abipy.flowtk import Cut3D
from abipy.core.fields import FieldReader
from abipy.abio.inputs import Cut3DInput
from abipy.electrons.ebands import ElectronsReader
#from abipy.tools import duck
#from abipy.tools.plotting import add_fig_kwargs, get_ax_fig_plt, set_axlims
import logging
logger = logging.getLogger(__name__)
__all__ = [
@ -34,14 +33,14 @@ class Cut3dDenPotNcFile(AbinitNcFile, Has_Structure):
and it's mainly used to convert from Fortran DEN/POT to netcdf.
"""
def __init__(self, filepath):
super(_Cut3dDenPotNcFileWithField, self).__init__(filepath)
self.reader = _FieldReader(filepath)
super(Cut3dDenPotNcFile, self).__init__(filepath)
self.reader = FieldReader(filepath)
self.field = self.reader.read_field()
@property
def structure(self):
""":class:`Structure` object."""
return self.field.structure()
return self.field.structure
def close(self):
self.reader.close()
@ -244,9 +243,6 @@ class DensityFortranFile(AbinitFortranFile):
Internal function to run a conversion using cut3d.
"""
workdir = tempfile.mkdtemp() if workdir is None else workdir
# local import to avoid circular references
from abipy.flowtk import Cut3D
outfile, converted_file = Cut3D().cut3d(cut3d_input, workdir)
return converted_file
@ -264,7 +260,6 @@ class DensityFortranFile(AbinitFortranFile):
Returns:
(CubeFile) the converted file as a CubeFile object.
"""
from abipy.abio.inputs import Cut3DInput
return CubeFile(self._convert(cut3d_input=Cut3DInput.den_to_cube(self.filepath, out_filepath),
workdir=workdir))
@ -282,9 +277,8 @@ class DensityFortranFile(AbinitFortranFile):
Returns:
(string) path to the converted file.
"""
from abipy.abio.inputs import Cut3DInput
return self._convert(cut3d_input=Cut3DInput.den_to_xsf(self.filepath, output_filepath=out_filepath, shift=shift),
workdir=workdir)
return self._convert(cut3d_input=Cut3DInput.den_to_xsf(self.filepath,
output_filepath=out_filepath, shift=shift), workdir=workdir)
def get_tecplot(self, out_filepath, workdir=None):
"""
@ -299,8 +293,8 @@ class DensityFortranFile(AbinitFortranFile):
Returns:
(string) path to the converted file.
"""
from abipy.abio.inputs import Cut3DInput
return self._convert(cut3d_input=Cut3DInput.den_to_tecplot(self.filepath, out_filepath), workdir=workdir)
return self._convert(cut3d_input=Cut3DInput.den_to_tecplot(self.filepath, out_filepath),
workdir=workdir)
def get_molekel(self, out_filepath, workdir=None):
"""
@ -315,8 +309,8 @@ class DensityFortranFile(AbinitFortranFile):
Returns:
(string) path to the converted file.
"""
from abipy.abio.inputs import Cut3DInput
return self._convert(cut3d_input=Cut3DInput.den_to_molekel(self.filepath, out_filepath), workdir=workdir)
return self._convert(cut3d_input=Cut3DInput.den_to_molekel(self.filepath, out_filepath),
workdir=workdir)
def get_3d_indexed(self, out_filepath, workdir=None):
"""
@ -331,8 +325,8 @@ class DensityFortranFile(AbinitFortranFile):
Returns:
(string) path to the converted file.
"""
from abipy.abio.inputs import Cut3DInput
return self._convert(cut3d_input=Cut3DInput.den_to_3d_indexed(self.filepath, out_filepath), workdir=workdir)
return self._convert(cut3d_input=Cut3DInput.den_to_3d_indexed(self.filepath, out_filepath),
workdir=workdir)
def get_3d_formatted(self, out_filepath, workdir=None):
"""
@ -347,8 +341,8 @@ class DensityFortranFile(AbinitFortranFile):
Returns:
(string) path to the converted file.
"""
from abipy.abio.inputs import Cut3DInput
return self._convert(cut3d_input=Cut3DInput.den_to_3d_indexed(self.filepath, out_filepath), workdir=workdir)
return self._convert(cut3d_input=Cut3DInput.den_to_3d_indexed(self.filepath, out_filepath),
workdir=workdir)
def get_hirshfeld(self, structure, all_el_dens_paths=None, fhi_all_el_path=None, workdir=None):
"""
@ -371,10 +365,6 @@ class DensityFortranFile(AbinitFortranFile):
if all_el_dens_paths is not None and fhi_all_el_path is not None:
raise ValueError("all_el_dens_paths and fhi_all_el_path are mutually exclusive.")
# local import to avoid circular references
from abipy.flowtk import Cut3D
from abipy.abio.inputs import Cut3DInput
if all_el_dens_paths is not None:
cut3d_input = Cut3DInput.hirshfeld(self.filepath, all_el_dens_paths)
else:
@ -388,20 +378,19 @@ class DensityFortranFile(AbinitFortranFile):
from abipy.electrons.charges import HirshfeldCharges
return HirshfeldCharges.from_cut3d_outfile(structure=structure, filepath=cut3d.stdout_fname)
#def cut3d_get_density(self, workdir=None):
# """
# Invoke cut3d to produce a netcdf file with the density, read the file and return Density object.
def get_density(self, workdir=None):
"""
Invoke cut3d to produce a netcdf file with the density, read the file and return Density object.
# Args:
# workdir: directory where cut3d is executed.
# """
# # local import to avoid circular references
# from abipy.flowtk import Cut3D
# from abipy.abio.inputs import Cut3DInput
# #cut3d_input = Cut3DInput.hirshfeld(self.filepath, all_el_dens_paths)
# workdir = tempfile.mkdtemp() if workdir is None else workdir
# cut3d = Cut3D()
# #outfile, converted_file = cut3d.cut3d(cut3d_input, workdir)
# with Cut3dDenPotNcFile() as nc:
# assert nc.field.is_density_like and nc.field.netcdf_name == "density"
# return nc.field
Args:
workdir: directory in which cut3d is executed.
"""
workdir = tempfile.mkdtemp() if workdir is None else workdir
output_filepath = os.path.join(workdir, "field_CUT3DDENPOT.nc")
# FIXME Converters with nspden > 1 won't work since cut3d asks for the ispden index.
cut3d_input = Cut3DInput(infile_path=self.filepath, output_filepath=output_filepath,
options=["17", "0", "0"])
outfile, _ = Cut3D().cut3d(cut3d_input, workdir)
with Cut3dDenPotNcFile(output_filepath) as nc:
assert nc.field.is_density_like and nc.field.netcdf_name == "density"
return nc.field

View File

@ -162,7 +162,7 @@ class Fold2BlochNcfile(AbinitNcFile, Has_Structure, Has_ElectronBands, NotebookW
@add_fig_kwargs
def plot_unfolded(self, kbounds, klabels, ylims=None, dist_tol=1e-12, verbose=0,
colormap="afmhot", facecolor="black", ax=None, **kwargs):
"""
r"""
Plot unfolded band structure with spectral weights.
Args:
@ -230,9 +230,9 @@ class Fold2BlochNcfile(AbinitNcFile, Has_Structure, Has_ElectronBands, NotebookW
nbv.new_code_cell("print(f2b)"),
nbv.new_code_cell("fig = f2b.ebands.plot()"),
nbv.new_code_cell("# fig = f2b.unfolded_kpoints.plot()"),
nbv.new_code_cell("""\
nbv.new_code_cell(r"""\
# kbounds = [0, 1/2, 0, 0, 0, 0, 0, 0, 1/2]
# klabels = ["Y", "$\Gamma$", "X"]
# klabels = ["Y", "$Gamma$", "X"]
# fig = f2b.plot_unfolded(kbounds, klabels)"""),
])

View File

@ -153,7 +153,8 @@ class TestSigresFile(AbipyTest):
assert r.qp_ebands_kmesh.kpoints.ksampling is not None
assert r.qp_ebands_kmesh.kpoints.is_mpmesh
qp_mpdivs, qp_shifts = r.qp_ebands_kmesh.kpoints.mpdivs_shifts
assert not ((qp_mpdivs, qp_shifts) == (None, None))
assert qp_mpdivs is not None
assert qp_shifts is not None
ks_mpdivs, ks_shifts = r.ks_ebands_kmesh.kpoints.mpdivs_shifts
self.assert_equal(qp_mpdivs, ks_mpdivs)
self.assert_equal(qp_shifts, ks_shifts)

View File

@ -10,10 +10,6 @@ import abipy.flowtk as flowtk
from abipy.core.testing import has_matplotlib
# Tests in this module require abinit >= 7.9.0
#pytestmark = pytest.mark.skipif(not has_abinit("7.9.0"), reason="Requires abinit >= 7.9.0")
def make_scf_nscf_inputs(tvars, pp_paths, nstep=50):
"""
Returns two input files: GS run and NSCF on a high symmetry k-mesh
@ -255,6 +251,7 @@ def itest_bandstructure_flow(fwp, tvars):
assert den_path
if not den_path.endswith(".nc"):
denfile = abilab.DensityFortranFile(den_path)
str(denfile)
workdir = flow.outdir.path
denfile.get_cube("den.cube", workdir=workdir)
denfile.get_xsf("den.xsf", workdir=workdir)
@ -262,6 +259,10 @@ def itest_bandstructure_flow(fwp, tvars):
denfile.get_molekel("den.molekel", workdir=workdir)
denfile.get_3d_indexed("den.data_indexed", workdir=workdir)
denfile.get_3d_formatted("den.data_formatted", workdir=workdir)
# This feature requires Abinit 8.5.2
if flow.manager.abinit_build.version_ge("8.5.2"):
den = denfile.get_density(workdir=workdir)
assert den.structure is not None and hasattr(den, "datar")
def itest_bandstructure_schedflow(fwp, tvars):

View File

@ -3,6 +3,7 @@
from __future__ import print_function, division, unicode_literals, absolute_import
import collections
import warnings
import numpy as np
@ -21,6 +22,7 @@ def is_intlike(obj):
"""
# isinstance(i, numbers.Integral)
try:
with warnings.catch_warnings():
return int(obj) == obj
except (ValueError, TypeError):
return False

45
docs/api/display_api.rst Normal file
View File

@ -0,0 +1,45 @@
tools Package
=============
:mod:`display` Module
=====================
.. automodule:: abipy.display
:members:
:undoc-members:
:show-inheritance:
:mod:`mvtk` Module
------------------
.. automodule:: abipy.display.mvtk
:members:
:undoc-members:
:show-inheritance:
:mod:`pandasw` Module
----------------------
.. automodule:: abipy.display.pandasw
:members:
:undoc-members:
:show-inheritance:
:mod:`seaborn` Module
---------------------
.. automodule:: abipy.display.seaborn
:members:
:undoc-members:
:show-inheritance:
:mod:`utils` Module
-------------------
.. automodule:: abipy.display.utils
:members:
:undoc-members:
:show-inheritance: