How to use the abipy.data.ref_file 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 / examples / plot / plot_qpbands_with_interpolation.py View on Github external
values to correct the KS band structure computed on a high symmetry k-path and
the KS energies of a k-mesh. Finally, the KS and the GW results are plotted with matplotlib.
"""
import abipy.data as abidata
from abipy.abilab import abiopen, ElectronBandsPlotter

# Get quasiparticle results from the SIGRES.nc database.
sigres = abiopen(abidata.ref_file("si_g0w0ppm_nband30_SIGRES.nc"))

# Read the KS band energies computed on the k-path
with abiopen(abidata.ref_file("si_nscf_GSR.nc")) as gsr_nscf:
    ks_ebands_kpath = gsr_nscf.ebands

# Read the KS band energies computed on the Monkhorst-Pack (MP) mesh
# and compute the DOS with the Gaussian method
with abiopen(abidata.ref_file("si_scf_GSR.nc")) as gsr_scf:
    ks_ebands_kmesh = gsr_scf.ebands

ks_edos = ks_ebands_kmesh.get_edos()

# Interpolate the QP corrections and use the interpolated values to correct
# the KS energies stored in `ks_ebands_kpath` and `ks_ebands_kmesh`.
#
# The QP energies are returned in r.qp_ebands_kpath and r.qp_ebands_kmesh.
# Note that the KS energies are optional but this is the recommended approach
# because the code will interpolate the corrections instead of the QP energies.

r = sigres.interpolate(lpratio=5,
                       ks_ebands_kpath=ks_ebands_kpath,
                       ks_ebands_kmesh=ks_ebands_kmesh
                       )
qp_edos = r.qp_ebands_kmesh.get_edos()
github abinit / abipy / _downloads / plot_qpbands_with_scissor.py View on Github external
# because we need the absolute values for the fit.
# The qpeme0(e0) curve consists of two branches:
#   the one in the [-6, 5.7] eV interval associated to valence states
#   and the one in the [6.1, 15] eV interval associated to conduction bands.
# We will fit these results with 2 functions defined in these two domains.
sigma_file.plot_qps_vs_e0(e0=None)
sigma_file.plot_qps_vs_e0()

qplist_spin = sigma_file.qplist_spin

# Define the two domains and construct the scissors operator
domains = [[-10, 6.1], [6.1, 18]]
scissors = qplist_spin[0].build_scissors(domains, bounds=None)

# Read the KS band energies computed on the k-path
ks_bands = abiopen(abidata.ref_file("si_nscf_GSR.nc")).ebands

# Read the KS band energies computed on the Monkhorst-Pack (MP) mesh
# and compute the DOS with the Gaussian method
ks_mpbands = abiopen(abidata.ref_file("si_scf_GSR.nc")).ebands
ks_edos = ks_mpbands.get_edos()

# Apply the scissors operator first on the KS band structure
# along the k-path then on the energies computed with the MP mesh.
qp_bands = ks_bands.apply_scissors(scissors)

qp_mpbands = ks_mpbands.apply_scissors(scissors)

# Compute the DOS with the modified QPState energies.
qp_edos = qp_mpbands.get_edos()

# Plot the LDA and the QPState band structure with matplotlib.
github abinit / abipy / _downloads / 04203741dbec64028afec63c72684d0f / plot_scr.py View on Github external
#!/usr/bin/env python
r"""
Dielectric function with LFE
============================

This examples shows how to plot the macroscopic dielectric function
computed in the GW code (optdriver 3)
"""
import abipy.data as abidata
from abipy.abilab import abiopen

with abiopen(abidata.ref_file("sio2_SCR.nc")) as ncfile:
    # The SCR file contains a structure and electron bands in the IBZ.
    # We can thus use the ebands object to plot bands + DOS.
    print(ncfile)

    edos = ncfile.ebands.get_edos()
    ncfile.ebands.plot_with_edos(edos, title="KS energies used to compute the SCR file.")

    # sphinx_gallery_thumbnail_number = 2
    ncfile.plot_emacro(title="Macroscopic dielectric function of $SiO_2$ with local-field effects.")

    ncfile.plot_eelf(title="Electron Energy Loss Function of $SiO_2$")
github abinit / abipy / abipy / gui / demo / demo_sigresviewer.py View on Github external
#!/usr/bin/env python
import abipy
import abipy.data

from abipy.gui.wxapps import wxapp_sigresviewer

app = wxapp_sigresviewer(abipy.data.ref_file("tgw1_9o_DS4_SIGRES.nc"))
app.MainLoop()
github abinit / abipy / _downloads / plot_ebands_grid.py View on Github external
ElectronBandsPlotter
====================

This example shows how to plot several band structures on a grid

We use two GSR files:

    si_scf_GSR.n: energies on a homogeneous sampling of the BZ (can be used to compute DOS)
    si_nscf_GSR.nc: energies on a k-path in the BZ (used to plot the band dispersion)
"""
from abipy.abilab import ElectronBandsPlotter
from abipy.data import ref_file

# To plot a grid with two band structures:
plotter = ElectronBandsPlotter()
plotter.add_ebands("BZ sampling", ref_file("si_scf_GSR.nc"))
plotter.add_ebands("k-path", ref_file("si_nscf_GSR.nc"))

# Get pandas dataframe
frame = plotter.get_ebands_frame()
print(frame)

plotter.gridplot(with_gaps=True)
#plotter.animate()

# To plot a grid with band structures + DOS, use the optional argument `edos_objects`
# The first subplot gets the band dispersion from eb_objects[0] and the DOS from edos_objects[0]
# edos_kwargs is an optional dictionary passed to `get_dos` to compute the DOS.
eb_objects = 2 * [ref_file("si_nscf_GSR.nc")]
edos_objects = 2 * [ref_file("si_scf_GSR.nc")]

# sphinx_gallery_thumbnail_number = 2
github abinit / abipy / abipy / examples / plot / plot_hist.py View on Github external
#!/usr/bin/env python
r"""
Structural relaxation
=====================

This example shows how to analyze the results of a
structure relaxation run using the HIST.nc file.
"""
from abipy.abilab import abiopen
import abipy.data as abidata

# Open the HIST file.
# (alternatively one can use the shell and `abiopen.py OUT_HIST.nc -nb`
# to open the file in jupyter notebook.
hist = abiopen(abidata.ref_file("sic_relax_HIST.nc"))

# The structure at the end of the structural relaxation.
print(hist.final_structure)

# Plot the evolution of the lattice parameters, forces, etotal, ...
hist.plot(tight_layout=True)

# Plot the total energy at the different relaxation steps.
hist.plot_energies(tight_layout=True)

hist.close()
github abinit / abipy / abipy / examples / plot / plot_multiple_hist.py View on Github external
#!/usr/bin/env python
r"""
Multiple Structural relaxations
===============================

This example shows how to analyze the results of multiple
structure relaxations with the HIST robot.
"""
from abipy import abilab
import abipy.data as abidata

files = [
    abidata.ref_file("sic_relax_HIST.nc"),
    abidata.ref_file("sic_relax_HIST.nc"),
]

# Build HIST robot from paths, use user-selected labels.
robot = abilab.HistRobot.from_files(files, labels=["sic_relaxation", "same_hist"])

# Get dataframe with most important results.
print(robot.get_dataframe())

for what in robot.what_list:
    robot.gridplot(what=what, tight_layout=True)

# Use combiplot to compare the results
# (meaningless in this case as we are using the same HIST file).
robot.combiplot(tight_layout=True)
github abinit / abipy / _downloads / plot_ebands_scatter3d.py View on Github external
#!/usr/bin/env python
r"""
e-bands scatter3d
=================

This example shows how to plot a particular "band" in 3D
with matplotlib scatter3D.
The color of the point gives the energy of the state wrt to the Fermi level.
"""
from abipy import abilab
import abipy.data as abidata

# Open the GSR file and extract the band structure.
with abilab.abiopen(abidata.ref_file("ni_kpath_GSR.nc")) as ncfile:
    ncfile.ebands.plot_scatter3d(band=9, spin=0)
github abinit / abipy / abipy / examples / htc / struct_tools.py View on Github external
#!/usr/bin/env python
from __future__ import division, print_function, unicode_literals

import abipy.data as abidata
from abipy import abilab 

# One can export the crystalline structure stored in the Netcdf files
# produced by abinit with a few lines of code. 
# See also abipy/scripts/abistruct.py for a handy command line interface.

# Read the structure from a netcdf file
filepath = abidata.ref_file("si_nscf_GSR.nc")
structure = abilab.Structure.from_file(filepath)

# Call convert to get the string representation in the new format.
for format in ["cif", "POSCAR", "cssr", "json"]:
    print((" Abinit --> %s " % format).center(80, "*"))
    s = structure.convert(format=format)
    print(s)