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)
Creating temporary file: /tmp/tmpelq6r2o7GaAs_COHPCAR.lobster

COHP: Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set 0 (was 2.298)
has_partial_projections: True, nsppol: 1
Number of pairs: 2
[0] Ga@0 --> As@1
[1] As@1 --> Ga@0

To plot the COHP averaged over all atom pairs specified:

cohp_file.plot(title="GaAs COHP");
_images/ae3353cd7fa8f2e692643a795e186307338ef6ff53d30daa57767253fc553c02.png

To plot the integrated COHP averaged over all atom pairs:

cohp_file.plot(what="i", title="GaAs integrated COHP");
_images/6ff6d0381f240cf880a82ba3dfcbac5dad8f8ac86bea6535e12f63b6e4aca280.png

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");
_images/489fd5135ecef0f8fb029ff7f6758521e560cb6553066ceee927e97bc4d12792.png

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);
_images/9666ac455376c150ee950d35e19dcafaabcc02481c9e0663c2853bb3cab8d746.png
#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)
Creating temporary file: /tmp/tmp3s88dnreGaAs_ICOHPLIST.lobster
Number of pairs: 2
 index0  index1 type0 type1  spin  average distance n_bonds   pair
      0       1    Ga    As     0 -4.36062  2.49546    None (0, 1)
      1       0    As    Ga     0 -4.36062  2.49546    None (1, 0)

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)
Creating temporary file: /tmp/tmpxt9w0c4dGaAs_DOSCAR.lobster
Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set to 0 (was 2.298)
nsppol: 1
Number of sites in projected DOS: 2
0 --> {4s, 4p_y, 4p_z, 4p_x}
1 --> {4s, 4p_y, 4p_z, 4p_x}
doscar.plot();
_images/6e296f7223fd189cbebafe38d5da636f5705ef7c465ff411190e053f06fe95a2.png
doscar.plot_pdos_site(site_index=[0, 1]);
_images/58d668e34d6b06b107f75cdaddc33afb9ecbe09fff31eb4388a9b8ea1e579635.png

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))
================================= COOP File =================================
Name: GaAs_COOPCAR.lobster.gz
Directory: /home/runner/work/abipy_book/abipy_book/abipy/abipy/data/refs/lobster_gaas
Size: 23.04 kB
Access Time: Wed May 28 11:53:17 2025
Modification Time: Wed May 28 11:48:25 2025
Change Time: Wed May 28 11:48:25 2025

COOP: Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set 0 (was 2.298)
has_partial_projections: True, nsppol: 1
Number of pairs: 2
[0] Ga@0 --> As@1
[1] As@1 --> Ga@0

================================= COHP File =================================
Name: GaAs_COHPCAR.lobster.gz
Directory: /home/runner/work/abipy_book/abipy_book/abipy/abipy/data/refs/lobster_gaas
Size: 24.06 kB
Access Time: Wed May 28 11:53:16 2025
Modification Time: Wed May 28 11:48:25 2025
Change Time: Wed May 28 11:48:25 2025

COHP: Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set 0 (was 2.298)
has_partial_projections: True, nsppol: 1
Number of pairs: 2
[0] Ga@0 --> As@1
[1] As@1 --> Ga@0

============================== ICHOHPLIST File ==============================
Number of pairs: 2
 index0  index1 type0 type1  spin  average distance n_bonds   pair
      0       1    Ga    As     0 -4.36062  2.49546    None (0, 1)
      1       0    As    Ga     0 -4.36062  2.49546    None (1, 0)

=============================== Lobster DOSCAR ===============================
Number of energies: 401, from -14.035 to 6.015 (eV) with E_fermi set to 0 (was 2.298)
nsppol: 1
Number of sites in projected DOS: 2
0 --> {4s, 4p_y, 4p_z, 4p_x}
1 --> {4s, 4p_y, 4p_z, 4p_x}

To plot COOP + COHP + DOS, use:

lobana.plot(title="COOP + COHP + DOS");
_images/d68ad60f8b5a72abd33822198bec1829fa31a88e5d23ee214a369059e76a9225.png

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

lobana.plot_coxp_with_dos(from_site_index=[0, 1]);
_images/05a5f2c046abf2d82f587ef7985b5031a4e10b3513f244f251ae3949c9c059b8.png
# Plot orbital projections.
lobana.plot_coxp_with_dos(from_site_index=[0], with_orbitals=True);
_images/96d62967ab7162122485eadc1bf5c413738c5a40ef49d697c2dd1cf0efab69fe.png
#lobana.plot_with_ebands(ebands="out_GSR.nc")