Skip to content

Commit

Permalink
Add possibility of select list of l-values in plot_fatbands_typeview
Browse files Browse the repository at this point in the history
  • Loading branch information
gmatteo committed Nov 15, 2024
1 parent 7331b76 commit d7c0fab
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 7 deletions.
9 changes: 7 additions & 2 deletions abipy/electrons/fatbands.py
Original file line number Diff line number Diff line change
Expand Up @@ -762,7 +762,7 @@ def plot_fatbands_mview(self, iatom, e0="fermie", fact=1.0, lmax=None,
return fig

@add_fig_kwargs
def plot_fatbands_typeview(self, e0="fermie", fact=1.0, lmax=None, ax_mat=None, ylims=None,
def plot_fatbands_typeview(self, e0="fermie", fact=1.0, lmax=None, l_list=None, ax_mat=None, ylims=None,
blist=None, fontsize=8, **kwargs) -> Figure:
"""
Plot the electronic fatbands grouped by atomic type with matplotlib.
Expand All @@ -774,6 +774,7 @@ def plot_fatbands_typeview(self, e0="fermie", fact=1.0, lmax=None, ax_mat=None,
- None: Don't shift energies, equivalent to ``e0 = 0``
fact: float used to scale the stripe size.
lmax: Maximum L included in plot. None means full set available on file.
l_list: List of L values to plot. None to plot all L up to lmax.
ax_mat: Matrix of axis. None if a new figure should be created.
ylims: Set the data limits for the y-axis. Accept tuple e.g. ``(left, right)``
or scalar e.g. ``left``. If left (right) is None, default values are used
Expand Down Expand Up @@ -812,6 +813,7 @@ def plot_fatbands_typeview(self, e0="fermie", fact=1.0, lmax=None, ax_mat=None,
yup = ebands.eigens[spin, :, band] - e0
ydown = yup
for l in range(min(self.lmax_symbol[symbol] + 1, mylsize)):
if l_list is not None and l not in l_list: continue
# Add width around each band.
w = wl_sbk[l, spin, band]
y1, y2 = yup + w, ydown - w
Expand Down Expand Up @@ -1451,7 +1453,7 @@ def plotly_pjdos_lview(self, e0="fermie", lmax=None, method="gaussian", step=0.1
return fig

@add_fig_kwargs
def plot_pjdos_typeview(self, e0="fermie", lmax=None, method="gaussian", step=0.1, width=0.2,
def plot_pjdos_typeview(self, e0="fermie", lmax=None, l_list=None, method="gaussian", step=0.1, width=0.2,
stacked=True, combined_spins=True, ax_mat=None, exchange_xy=False,
with_info=True, with_spin_sign=True, xlims=None, ylims=None, fontsize=8, **kwargs) -> Figure:
"""
Expand All @@ -1463,6 +1465,7 @@ def plot_pjdos_typeview(self, e0="fermie", lmax=None, method="gaussian", step=0.
- Number e.g ``e0 = 0.5``: shift all eigenvalues to have zero energy at 0.5 eV
- None: Don't shift energies, equivalent to ``e0 = 0``
lmax: Maximum L included in plot. None means full set available on file.
l_list: List of L values to plot. None to plot all L up to lmax.
method: String defining the method for the computation of the DOS.
step: Energy step (eV) of the linear mesh.
width: Standard deviation (eV) of the gaussian.
Expand Down Expand Up @@ -1529,6 +1532,7 @@ def plot_pjdos_typeview(self, e0="fermie", lmax=None, method="gaussian", step=0.
ax.plot(x, y, color="k", label=label if with_info else None)

for l in range(min(self.lmax_symbol[symbol] + 1, mylsize)):
if l_list is not None and l not in l_list: continue
# Plot PJ-DOS(l, spin)
x, y = mesh, spin_sign * symbols_lso[symbol][l, spin]
if exchange_xy: x, y = y, x
Expand Down Expand Up @@ -1558,6 +1562,7 @@ def plot_pjdos_typeview(self, e0="fermie", lmax=None, method="gaussian", step=0.
# Plot cumulative PJ-DOS(l, spin)
stack = intg.get_lstack_symbol(symbol, spin) * spin_sign
for l in range(min(self.lmax_symbol[symbol] + 1, mylsize)):
if l_list is not None and l not in l_list: continue
yup = stack[l]
ydown = stack[l-1] if l != 0 else zerodos
label = "%s (stacked)" % self.l2tex[l] if (isymb, spin) == (0, 0) else None
Expand Down
15 changes: 10 additions & 5 deletions abipy/examples/plot/plot_efatbands.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,10 @@

fbnc_kpath = abilab.abiopen(abidata.ref_file("mgb2_kpath_FATBANDS.nc"))

# To customize the matplotlib marker and its size, use:
fbnc_kpath.marker_spin = {0: "o", 1: "v"}
fbnc_kpath.marker_size = 2

#%%
# Print file info (dimensions, variables ...)
# Note that prtdos = 3, so LM decomposition is not available.
Expand All @@ -26,7 +30,7 @@

#%%
# Plot the k-points belonging to the path.
fbnc_kpath.ebands.kpoints.plotly()
#fbnc_kpath.ebands.kpoints.plotly()

#%%
# NC files have contributions up to L=4 (g channel)
Expand All @@ -36,23 +40,24 @@

#%%
# Plot the electronic fatbands grouped by atomic type.
# Can use l_list to select only particular l-values

fbnc_kpath.plot_fatbands_typeview(lmax=lmax, tight_layout=True)
fbnc_kpath.plot_fatbands_typeview(lmax=lmax, tight_layout=True, l_list=None)

#%%
# For the plotly version use:

fbnc_kpath.plotly_fatbands_typeview(lmax=lmax)
#fbnc_kpath.plotly_fatbands_typeview(lmax=lmax)

#%%
# Plot the electronic fatbands grouped by L.

fbnc_kpath.plot_fatbands_lview(lmax=lmax, tight_layout=True)
#fbnc_kpath.plot_fatbands_lview(lmax=lmax, tight_layout=True)

#%%
# For the plotly version use:

fbnc_kpath.plotly_fatbands_lview(lmax=lmax)
#fbnc_kpath.plotly_fatbands_lview(lmax=lmax)

#%%
# Now we read another FATBANDS file produced on a 18x18x18 k-mesh
Expand Down

0 comments on commit d7c0fab

Please sign in to comment.