From d7c0fab1d1d3dcfa6d5b77a0e889221faf8c610a Mon Sep 17 00:00:00 2001 From: Matteo Giantomassi Date: Fri, 15 Nov 2024 16:53:22 +0100 Subject: [PATCH] Add possibility of select list of l-values in plot_fatbands_typeview --- abipy/electrons/fatbands.py | 9 +++++++-- abipy/examples/plot/plot_efatbands.py | 15 ++++++++++----- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/abipy/electrons/fatbands.py b/abipy/electrons/fatbands.py index 0ec2300d0..1098b8c7d 100644 --- a/abipy/electrons/fatbands.py +++ b/abipy/electrons/fatbands.py @@ -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. @@ -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 @@ -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 @@ -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: """ @@ -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. @@ -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 @@ -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 diff --git a/abipy/examples/plot/plot_efatbands.py b/abipy/examples/plot/plot_efatbands.py index f9bd7e14f..df5798b7d 100755 --- a/abipy/examples/plot/plot_efatbands.py +++ b/abipy/examples/plot/plot_efatbands.py @@ -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. @@ -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) @@ -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