How to use the abipy.abilab.abiopen function in abipy

To help you get started, we’ve selected a few abipy examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github abinit / abipy / abipy / integration_tests / itest_gw.py View on Github external
scf_task = flow[0][0]
    nscf_task = flow[0][1]
    scr_task = flow[0][2]
    sig_task = flow[0][3]

    # Test garbage_collector
    # The WFK|SCR file should have been removed because we call set_garbage_collector
    assert not scf_task.outdir.has_abiext("WFK")
    assert not nscf_task.outdir.has_abiext("WFK")
    assert not scr_task.outdir.has_abiext("SCR")
    assert not scr_task.outdir.has_abiext("SUS")

    # The sigma task should produce a SIGRES file.
    sigfile = sig_task.outdir.list_filepaths(wildcard="*SIGRES.nc")[0]
    assert sigfile
    with abilab.abiopen(sigfile) as sigres:
        sigres.to_string(verbose=2)
        assert sigres.nsppol == 1

    # Test SigmaTask inspect method
    #if has_matplotlib():
        #sig_task.inspect(show=False)

    # Test get_results for Sigma and Scr
    scr_task.get_results()
    sig_task.get_results()

    # Test SCR.nc file (this is optional)
    if scr_task.scr_path:
        with scr_task.open_scr() as scr:
            scr.to_string(verbose=2)
            assert len(scr.wpts) == 2
github abinit / abipy / abipy / examples / plot / plot_phonons_lo_to.py View on Github external
#!/usr/bin/env python
r"""
Phonon Bands with LO-TO
=======================

This example shows how to plot the phonon band structure of AlAs
including the LO-TO splitting. See tutorial/lesson_rf2.html
"""
from abipy.abilab import abiopen
import abipy.data as abidata

# Open PHBST file produced by anaddb and extract the phonon bands object.
# (alternatively one can use the shell and `abiopen.py OUT_PHBST.nc -nb`
# to open the file in a jupyter notebook.
with abiopen(abidata.ref_file("ZnSe_hex_886.out_PHBST.nc")) as ncfile:
    phbands = ncfile.phbands

# Phonon frequencies with non analytical contributions, if calculated, are saved
# in the anaddb.nc file produced by anaddb. The results should be fetched from there
# and added to the phonon bands.
phbands.read_non_anal_from_file(abidata.ref_file("ZnSe_hex_886.anaddb.nc"))

# Notice that all the directions starting from or arriving at gamma that are used
# in the path should explicitely calculated, even if the values are the same.

# Plot the phonon frequencies. Note that the labels for the q-points
# are found automatically by searching in an internal database.
phbands.plot(title="ZnSe with LO-TO splitting")
github abinit / abipy / abipy / examples / plot / plot_ddb_asr.py View on Github external
#!/usr/bin/env python
r"""
Phonon Bands with/without ASR
=============================

This example shows how to plot a phonon band structure
with and without imposing the acoustic sum rule at the Gamma point.
"""
from abipy import abilab
import abipy.data as abidata

# Open DDB file
filepath = abidata.ref_file("mp-1009129-9x9x10q_ebecs_DDB")
ddb = abilab.abiopen(filepath)

# This method computes the phonon bands and DOS by calling anaddb
# with different values of asr and returns a PhononBandsPlotter object.
plotter = ddb.anacompare_asr(asr_list=(0, 2))
plotter.combiplot()

# Set nqsmall to 0 to disable DOS computation.
plotter = ddb.anacompare_asr(asr_list=(0, 2), nqsmall=0, ndivsm=10)
plotter.gridplot()

ddb.close()
github abinit / abipy / _downloads / fa79d68983a6301d8b9e44a5618934b8 / plot_ejdos.py View on Github external
#!/usr/bin/env python
r"""
Joint Density of States
=======================

This example shows how plot the different contributions
to the electronic joint density of states of Silicon
"""
import abipy.data as abidata
from abipy.abilab import abiopen

# Extract the bands computed with the SCF cycle on a Monkhorst-Pack mesh.
with abiopen(abidata.ref_file("si_scf_WFK.nc")) as wfk_file:
    ebands = wfk_file.ebands

# Select the valence and conduction bands to include in the JDOS
# Here we include valence bands from 0 to 3 and the first conduction band (4).
vrange = range(0, 4)
crange = range(4, 5)

# Plot joint-DOS.
ebands.plot_ejdosvc(vrange, crange)

# Plot decomposition of joint-DOS in terms of v --> c transitions
ebands.plot_ejdosvc(vrange, crange, cumulative=False)

# Show optical (vertical) transitions of energy 2.8 eV
with abiopen(abidata.ref_file("si_nscf_GSR.nc")) as gsr_file:
    gsr_file.ebands.plot_transitions(2.8)
github abinit / abipy / abipy / tools / notebooks.py View on Github external
def on_value_change(change):
        """Callback"""
        clear_output()
        path = change["new"]
        #print(change)
        with abilab.abiopen(path) as abifile:
            print(abifile)
            #display(abifile)
github abinit / abipy / abipy / scripts / abirun.py View on Github external
return 0

        import IPython
        # Use embed because I don't know how to show a header with start_ipython.
        IPython.embed(header="The Abinit file is associated to the `abifile` variable.\nTry `print(abifile)`")

    else:
        # Call specialized method if the object is a NotebookWriter
        # else generate simple notebook by calling `make_and_open_notebook`
        cls = abilab.abifile_subclass_from_filename(filepath)
        if hasattr(cls, "make_and_open_notebook"):
            if hasattr(cls, "__exit__"):
                with abilab.abiopen(filepath) as abifile:
                    return abifile.make_and_open_notebook(foreground=options.foreground)
            else:
                abifile = abilab.abiopen(filepath)
                return abifile.make_and_open_notebook(foreground=options.foreground)
        else:
            raise TypeError("Object ot type `%s` does not provide make_and_open_notebook method" % str(cls))
            #return make_and_open_notebook(options)
github abinit / abipy / abipy / dfpt / phonons.py View on Github external
- instances of cls
            - files (string) that can be open with abiopen and that provide a `phbands` attribute.
            - objects providing a `phbands` attribute.
        """
        if isinstance(obj, cls):
            return obj

        elif is_string(obj):
            # path?
            if obj.endswith(".pickle"):
                with open(obj, "rb") as fh:
                    return cls.as_phbands(pickle.load(fh))

            from abipy.abilab import abiopen
            with abiopen(obj) as abifile:
                return abifile.phbands

        elif hasattr(obj, "phbands"):
            # object with phbands
            return obj.phbands

        raise TypeError("Don't know how to extract a PhononBands from type %s" % type(obj))
github abinit / abipy / abipy / dfpt / phonons.py View on Github external
def add_phbands_from_file(self, filepath, label=None):
        """
        Adds a band structure for plotting. Reads data from a Netcdfile
        """
        from abipy.abilab import abiopen
        with abiopen(filepath) as ncfile:
            if label is None: label = ncfile.filepath
            self.add_phbands(label, ncfile.phbands)
github abinit / abipy / abipy / examples / plot / plot_lobster_cohp.py View on Github external
This example shows how to analyze the COHPCAR file
produced by Lobster code 

Use `abiopen.py FILE` with --expose or --print for a command line interface
and --notebook to generate a jupyter notebook.
"""
import os
import abipy.data as abidata

from abipy.abilab import abiopen

dirpath = os.path.join(abidata.dirpath, "refs", "lobster_gaas")
filename = os.path.join(dirpath, "GaAs_COHPCAR.lobster.gz")

# Open the COHPCAR.lobster file (same API for COOPCAR.lobster)
cohp_file = abiopen(filename)
print(cohp_file)

# Plot COHP.
cohp_file.plot(title="GaAs COHP")

# Plot integrated COHP.
cohp_file.plot(what="i", title="GaAs integrated COHP")

# Plot total overlap for all sites listed in `from_site_index`
cohp_file.plot_site_pairs_total(from_site_index=[0], title="COHP total overlap for site index 0")

# Plot partial crystal orbital projections for all sites listed in `from_site_index`
cohp_file.plot_site_pairs_partial(from_site_index=[0], title="COHP with orbital projections from site index 0")
github abinit / abipy / abipy / examples / plot / plot_ebands_edos.py View on Github external
#!/usr/bin/env python
r"""
Bands + DOS
===========

This example shows how to compute the DOS and plot a
band structure with DOS using two GSR files.
"""
from abipy.abilab import abiopen
import abipy.data as abidata

# Open the file with energies computed on a k-path in the BZ
# and extract the band structure object.
with abiopen(abidata.ref_file("si_nscf_GSR.nc")) as nscf_file:
    nscf_ebands = nscf_file.ebands

# Open the file with energies computed with a homogeneous sampling of the BZ
# and extract the band structure object.
with abiopen(abidata.ref_file("si_scf_GSR.nc")) as gs_file:
    gs_ebands = gs_file.ebands

# Compute the DOS with the Gaussian method (use default values for
# the broadening and the step of the linear mesh.
edos = gs_ebands.get_edos()

# Plot bands and DOS.
nscf_ebands.plot_with_edos(edos, e0=None, with_gaps=True)

print("nscf_ebands.efermi", nscf_ebands.fermie)
print("gs_ebands.efermi", gs_ebands.fermie)