The FATBANDS.nc file#
The FATBANDS.nc
file contains the projection of the KS wavefunctions onto atom-centered
functions with given angular momentum \(l\).
The file is generated by using the prtdos
variable either in a SCF or NSCF run.
One can use the abiopen
function provided by abilab
to open the file and generate an instance of FatbandsFile
.
Alternatively, use the abiopen.py
script to open the file inside the shell with the syntax:
abiopen.py out_FATBANDS.nc
This command will start the ipython interpreter so that one can interact directly
with the FatbandFile
object (named abifile
inside ipython).
To generate a jupyter notebook use:
abiopen.py out_FATBANDS.nc -nb
For a quick visualization of the data, use:
abiopen.py out_FATBANDS.nc -e
Note
AbiPy provides two different APIs to produce figures either with matplotlib or with plotly.
In this tutorial, we will use the plotly API as much as possible although it should be noted
that not all the plotting methods have been yet ported to plotly.
AbiPy uses a relatively simple rule to differentiate between the two plotting libraries:
if an object provides an obj.plot
method producing a matplotlib plot, the corresponding
plotly version (if any) is named obj.plotly
.
Note that plotly requires a web browser hence the matplotlib version is still valuable if you need to
visualize results on machines in which only the X-server is available.
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
# This fatbands file has been produced on a k-path so it is not suitable for DOS calculations.
fbnc_kpath = abilab.abiopen(abidata.ref_file("mgb2_kpath_FATBANDS.nc"))
To print file info i.e., dimensions, variables, etc. (note that prtdos = 3, so LM decomposition is not available)
print(fbnc_kpath)
================================= File Info =================================
Name: mgb2_kpath_FATBANDS.nc
Directory: /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/abipy/data/refs/mgb2_fatbands
Size: 149.01 kB
Access Time: Sun Oct 27 17:41:50 2024
Modification Time: Sun Oct 27 17:40:35 2024
Change Time: Sun Oct 27 17:40:35 2024
================================= Structure =================================
Full Formula (Mg1 B2)
Reduced Formula: MgB2
abc : 3.086000 3.086000 3.523000
angles: 90.000000 90.000000 120.000000
pbc : True True True
Sites (3)
# SP a b c
--- ---- -------- -------- ---
0 Mg 0 0 0
1 B 0.333333 0.666667 0.5
2 B 0.666667 0.333333 0.5
Abinit Spacegroup: spgid: 191, num_spatial_symmetries: 24, has_timerev: True, symmorphic: False
============================== Electronic Bands ==============================
================================= Structure =================================
Full Formula (Mg1 B2)
Reduced Formula: MgB2
abc : 3.086000 3.086000 3.523000
angles: 90.000000 90.000000 120.000000
pbc : True True True
Sites (3)
# SP a b c
--- ---- -------- -------- ---
0 Mg 0 0 0
1 B 0.333333 0.666667 0.5
2 B 0.666667 0.333333 0.5
Abinit Spacegroup: spgid: 191, num_spatial_symmetries: 24, has_timerev: True, symmorphic: False
Number of electrons: 8.0, Fermi level: 8.700 (eV)
nsppol: 1, nkpt: 78, mband: 8, nspinor: 1, nspden: 1
smearing scheme: none (occopt 1), tsmear_eV: 0.272, tsmear Kelvin: 3157.7
Direct gap:
Energy: 0.595 (eV)
Initial state: spin: 0, kpt: [+0.350, +0.300, +0.000], band: 3, eig: 8.402, occ: 2.000
Final state: spin: 0, kpt: [+0.350, +0.300, +0.000], band: 4, eig: 8.997, occ: 0.000
Fundamental gap:
Energy: 0.058 (eV)
Initial state: spin: 0, kpt: K [+0.333, +0.333, +0.000], band: 4, eig: 8.700, occ: 0.000
Final state: spin: 0, kpt: [+0.147, +0.000, +0.000], band: 4, eig: 8.758, occ: 0.000
Bandwidth: 14.314 (eV)
Valence maximum located at kpt index 27:
spin: 0, kpt: K [+0.333, +0.333, +0.000], band: 4, eig: 8.700, occ: 0.000
Conduction minimum located at kpt index 5:
spin: 0, kpt: [+0.147, +0.000, +0.000], band: 4, eig: 8.758, occ: 0.000
TIP: Use `--verbose` to print k-point coordinates with more digits
=============================== Fatbands Info ===============================
prtdos: 3, prtdosm: 0, mbesslang: 5, pawprtdos: 0, usepaw: 0
nsppol: 1, nkpt: 78, mband: 8
Idx Symbol Reduced_Coords Lmax Ratsph [Bohr] Has_Atom
----- -------- ----------------------- ------ --------------- ----------
0 Mg 0.00000 0.00000 0.00000 4 2 Yes
1 B 0.33333 0.66667 0.50000 4 2 Yes
2 B 0.66667 0.33333 0.50000 4 2 Yes
fbnc_kpath.structure.plot();
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/IPython/core/formatters.py:343, in BaseFormatter.__call__(self, obj)
341 pass
342 else:
--> 343 return printer(obj)
344 # Finally look for special method names
345 method = get_real_method(obj, self.print_method)
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/IPython/core/pylabtools.py:170, in print_figure(fig, fmt, bbox_inches, base64, **kwargs)
167 from matplotlib.backend_bases import FigureCanvasBase
168 FigureCanvasBase(fig)
--> 170 fig.canvas.print_figure(bytes_io, **kw)
171 data = bytes_io.getvalue()
172 if fmt == 'svg':
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/matplotlib/backend_bases.py:2175, in FigureCanvasBase.print_figure(self, filename, dpi, facecolor, edgecolor, orientation, format, bbox_inches, pad_inches, bbox_extra_artists, backend, **kwargs)
2172 # we do this instead of `self.figure.draw_without_rendering`
2173 # so that we can inject the orientation
2174 with getattr(renderer, "_draw_disabled", nullcontext)():
-> 2175 self.figure.draw(renderer)
2176 if bbox_inches:
2177 if bbox_inches == "tight":
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/matplotlib/artist.py:95, in _finalize_rasterization.<locals>.draw_wrapper(artist, renderer, *args, **kwargs)
93 @wraps(draw)
94 def draw_wrapper(artist, renderer, *args, **kwargs):
---> 95 result = draw(artist, renderer, *args, **kwargs)
96 if renderer._rasterizing:
97 renderer.stop_rasterizing()
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/matplotlib/figure.py:3162, in Figure.draw(self, renderer)
3159 # ValueError can occur when resizing a window.
3161 self.patch.draw(renderer)
-> 3162 mimage._draw_list_compositing_images(
3163 renderer, self, artists, self.suppressComposite)
3165 renderer.close_group('figure')
3166 finally:
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/matplotlib/image.py:132, in _draw_list_compositing_images(renderer, parent, artists, suppress_composite)
130 if not_composite or not has_images:
131 for a in artists:
--> 132 a.draw(renderer)
133 else:
134 # Composite any adjacent images together
135 image_group = []
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/matplotlib/artist.py:72, in allow_rasterization.<locals>.draw_wrapper(artist, renderer)
69 if artist.get_agg_filter() is not None:
70 renderer.start_filter()
---> 72 return draw(artist, renderer)
73 finally:
74 if artist.get_agg_filter() is not None:
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/mpl_toolkits/mplot3d/axes3d.py:441, in Axes3D.draw(self, renderer)
437 zorder_offset = max(axis.get_zorder()
438 for axis in self._axis_map.values()) + 1
439 collection_zorder = patch_zorder = zorder_offset
--> 441 for artist in sorted(collections_and_patches,
442 key=lambda artist: artist.do_3d_projection(),
443 reverse=True):
444 if isinstance(artist, mcoll.Collection):
445 artist.zorder = collection_zorder
File /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/mpl_toolkits/mplot3d/axes3d.py:442, in Axes3D.draw.<locals>.<lambda>(artist)
437 zorder_offset = max(axis.get_zorder()
438 for axis in self._axis_map.values()) + 1
439 collection_zorder = patch_zorder = zorder_offset
441 for artist in sorted(collections_and_patches,
--> 442 key=lambda artist: artist.do_3d_projection(),
443 reverse=True):
444 if isinstance(artist, mcoll.Collection):
445 artist.zorder = collection_zorder
AttributeError: 'Arrow3D' object has no attribute 'do_3d_projection'
<Figure size 640x480 with 1 Axes>
To plot the k-points belonging to the path:
fbnc_kpath.ebands.kpoints.plotly();
To plot the electronic fatbands grouped by atomic type:
fbnc_kpath.plot_fatbands_typeview(tight_layout=True);
fbnc_kpath.plotly_fatbands_typeview();
To plot the electronic fatbands grouped by \(l\):
fbnc_kpath.plot_fatbands_lview(tight_layout=True);
fbnc_kpath.plotly_fatbands_lview();
Now we read another FATBANDS.nc file produced on 18x18x18 k-mesh
fbnc_kmesh = abilab.abiopen(abidata.ref_file("mgb2_kmesh181818_FATBANDS.nc"))
print(fbnc_kpath)
================================= File Info =================================
Name: mgb2_kpath_FATBANDS.nc
Directory: /usr/share/miniconda/envs/abipy/lib/python3.12/site-packages/abipy/data/refs/mgb2_fatbands
Size: 149.01 kB
Access Time: Sun Oct 27 17:41:50 2024
Modification Time: Sun Oct 27 17:40:35 2024
Change Time: Sun Oct 27 17:40:35 2024
================================= Structure =================================
Full Formula (Mg1 B2)
Reduced Formula: MgB2
abc : 3.086000 3.086000 3.523000
angles: 90.000000 90.000000 120.000000
pbc : True True True
Sites (3)
# SP a b c
--- ---- -------- -------- ---
0 Mg 0 0 0
1 B 0.333333 0.666667 0.5
2 B 0.666667 0.333333 0.5
Abinit Spacegroup: spgid: 191, num_spatial_symmetries: 24, has_timerev: True, symmorphic: False
============================== Electronic Bands ==============================
================================= Structure =================================
Full Formula (Mg1 B2)
Reduced Formula: MgB2
abc : 3.086000 3.086000 3.523000
angles: 90.000000 90.000000 120.000000
pbc : True True True
Sites (3)
# SP a b c
--- ---- -------- -------- ---
0 Mg 0 0 0
1 B 0.333333 0.666667 0.5
2 B 0.666667 0.333333 0.5
Abinit Spacegroup: spgid: 191, num_spatial_symmetries: 24, has_timerev: True, symmorphic: False
Number of electrons: 8.0, Fermi level: 8.700 (eV)
nsppol: 1, nkpt: 78, mband: 8, nspinor: 1, nspden: 1
smearing scheme: none (occopt 1), tsmear_eV: 0.272, tsmear Kelvin: 3157.7
Direct gap:
Energy: 0.595 (eV)
Initial state: spin: 0, kpt: [+0.350, +0.300, +0.000], band: 3, eig: 8.402, occ: 2.000
Final state: spin: 0, kpt: [+0.350, +0.300, +0.000], band: 4, eig: 8.997, occ: 0.000
Fundamental gap:
Energy: 0.058 (eV)
Initial state: spin: 0, kpt: K [+0.333, +0.333, +0.000], band: 4, eig: 8.700, occ: 0.000
Final state: spin: 0, kpt: [+0.147, +0.000, +0.000], band: 4, eig: 8.758, occ: 0.000
Bandwidth: 14.314 (eV)
Valence maximum located at kpt index 27:
spin: 0, kpt: K [+0.333, +0.333, +0.000], band: 4, eig: 8.700, occ: 0.000
Conduction minimum located at kpt index 5:
spin: 0, kpt: [+0.147, +0.000, +0.000], band: 4, eig: 8.758, occ: 0.000
TIP: Use `--verbose` to print k-point coordinates with more digits
=============================== Fatbands Info ===============================
prtdos: 3, prtdosm: 0, mbesslang: 5, pawprtdos: 0, usepaw: 0
nsppol: 1, nkpt: 78, mband: 8
Idx Symbol Reduced_Coords Lmax Ratsph [Bohr] Has_Atom
----- -------- ----------------------- ------ --------------- ----------
0 Mg 0.00000 0.00000 0.00000 4 2 Yes
1 B 0.33333 0.66667 0.50000 4 2 Yes
2 B 0.66667 0.33333 0.50000 4 2 Yes
and plot the \(l\)-PJDOS grouped by atomic type:
fbnc_kmesh.plot_pjdos_typeview(tight_layout=True);
fbnc_kmesh.plotly_pjdos_typeview();
Plot the L-PJDOS grouped by L:
fbnc_kmesh.plot_pjdos_lview(tight_layout=True);
fbnc_kmesh.plotly_pjdos_lview();
Now we use the two netcdf files to produce plots with fatbands + PJDOSEs. The data for the DOS is taken from pjdosfile.
fbnc_kpath.plot_fatbands_with_pjdos(pjdosfile=fbnc_kmesh, view="type", tight_layout=True);
fbnc_kpath.plotly_fatbands_with_pjdos(pjdosfile=fbnc_kmesh, view="type");
fatbands + PJDOS grouped by L:
fbnc_kpath.plot_fatbands_with_pjdos(pjdosfile=fbnc_kmesh, view="lview", tight_layout=True);
fbnc_kpath.plotly_fatbands_with_pjdos(pjdosfile=fbnc_kmesh, view="lview");
Warning
Remember to close the files with:
fbnc_kpath.close()
fbnc_kmesh.close()