Lobster output files#

This example shows how to analyze the output files produced by Lobster

Use

abiopen.py FILE

with the --expose or --print for a command line interface and --notebook to generate a jupyter notebook from a lobster FILE.

Note: The code in this notebook requires abipy >= 0.6

Let’s start by importing the basic modules needed for this tutorial.

import warnings
warnings.filterwarnings("ignore")  # Ignore warnings

from abipy import abilab
abilab.enable_notebook() # This line tells AbiPy we are running inside a notebook
import abipy.data as abidata

# This line configures matplotlib to show figures embedded in the notebook.
# Replace `inline` with `notebook` in classic notebook
%matplotlib inline

# Option available in jupyterlab. See https://github.com/matplotlib/jupyter-matplotlib
#%matplotlib widget

How to analyze the COHPCAR file#

# Path to one of the reference file shipped with AbiPy
import os
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 = abilab.abiopen(filename)
print(cohp_file)
---------------------------------------------------------------------------
FileNotFoundError                         Traceback (most recent call last)
Cell In[2], line 7
      4 filename = os.path.join(dirpath, "GaAs_COHPCAR.lobster.gz")
      6 # Open the COHPCAR.lobster file (same API for COOPCAR.lobster)
----> 7 cohp_file = abilab.abiopen(filename)
      8 print(cohp_file)

File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/abipy/abilab.py:304, in abiopen(filepath)
    302 if ext in (".bz2", ".gz", ".z"):
    303     from monty.io import zopen
--> 304     with zopen(filepath, "rt") as f:
    305         import tempfile
    306         _, tmp_path = tempfile.mkstemp(suffix=os.path.basename(root), text=True)

File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/monty/io.py:47, in zopen(filename, *args, **kwargs)
     45     return bz2.open(filename, *args, **kwargs)
     46 if ext in {".GZ", ".Z"}:
---> 47     return gzip.open(filename, *args, **kwargs)
     48 if ext in {".XZ", ".LZMA"}:
     49     return lzma.open(filename, *args, **kwargs)

File /usr/share/miniconda/envs/abipy/lib/python3.12/gzip.py:61, in open(filename, mode, compresslevel, encoding, errors, newline)
     59 gz_mode = mode.replace("t", "")
     60 if isinstance(filename, (str, bytes, os.PathLike)):
---> 61     binary_file = GzipFile(filename, gz_mode, compresslevel)
     62 elif hasattr(filename, "read") or hasattr(filename, "write"):
     63     binary_file = GzipFile(None, gz_mode, compresslevel, filename)

File /usr/share/miniconda/envs/abipy/lib/python3.12/gzip.py:192, in GzipFile.__init__(self, filename, mode, compresslevel, fileobj, mtime)
    190     mode += 'b'
    191 if fileobj is None:
--> 192     fileobj = self.myfileobj = builtins.open(filename, mode or 'rb')
    193 if filename is None:
    194     filename = getattr(fileobj, 'name', '')

FileNotFoundError: [Errno 2] No such file or directory: '/usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/abipy/data/refs/lobster_gaas/GaAs_COHPCAR.lobster.gz'

To plot the COHP averaged over all atom pairs specified:

cohp_file.plot(title="GaAs COHP");

To plot the integrated COHP averaged over all atom pairs:

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

To plot the total overlap for all sites listed in from_site_index

cohp_file.plot_site_pairs_total(from_site_index=[0, 1], title="COHP total overlap for site index 0");

To plot partial crystal orbital projections for all sites listed in from_site_index:

cohp_file.plot_site_pairs_partial(from_site_index=[0, 1],
                                  title="COHP with orbital projections from site index 0",
                                  fontsize=6, tight_layout=True);
#cohp_file.plot_average_pairs(with_site_index=[0]);

Use abiopen to open the MDF:

How to analyze the ICOHPLIST file#

# Path to one of the AbiPy file
dirpath = os.path.join(abidata.dirpath, "refs", "lobster_gaas")
filename = os.path.join(dirpath, "GaAs_ICOHPLIST.lobster.gz")

# Open the ICOHPCAR.lobster file.
icohp_file = abilab.abiopen(filename)
print(icohp_file)

How to analyze the DOSCAR file#

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

# Open the ICOHPCAR.lobster file.
doscar = abilab.abiopen(filename)
print(doscar)
doscar.plot();
doscar.plot_pdos_site(site_index=[0, 1]);

Analyzing all Lobster output files with LobsterAnalyzer#

Let’s assume we have a directory with lobster output files for COOP, COHP, DOS and we need to produce plots showing all these results altogether. In this case, one can use the LobsterAnalyzer object and initialize it from the directory containing the output files.

dirpath = os.path.join(abidata.dirpath, "refs", "lobster_gaas")

# Open the all the lobster files produced in directory dirpath
# with the (optional) prefix GaAs_
lobana = abilab.LobsterAnalyzer.from_dir(dirpath, prefix="GaAs_")
print(lobana.to_string(verbose=1))

To plot COOP + COHP + DOS, use:

lobana.plot(title="COOP + COHP + DOS");

To plot COHP for all sites in from_site_index and Lobster DOS:

lobana.plot_coxp_with_dos(from_site_index=[0, 1]);
# Plot orbital projections.
lobana.plot_coxp_with_dos(from_site_index=[0], with_orbitals=True);
#lobana.plot_with_ebands(ebands="out_GSR.nc")