Download IPython notebook here. Binder badge.

GitHub issues by-label

FatbandsPlot

[1]:
import sisl
import sisl.viz

For this notebook we will create a toy “Boron nitride” tight binding:

[2]:
# First, we create the geometry
BN = sisl.geom.graphene(atoms=["B", "N"])

# Create a hamiltonian with different on-site terms
H = sisl.Hamiltonian(BN)

H[0, 0] = 2
H[1, 1] = -2

H[0, 1] = -2.7
H[1, 0] = -2.7

H[0, 1, (-1, 0)] = -2.7
H[0, 1, (0, -1)] = -2.7
H[1, 0, (1, 0)] = -2.7
H[1, 0, (0, 1)] = -2.7

Note that we could have obtained this hamiltonian from any other source. Then we generate a path for the band structure:

[3]:
band = sisl.BandStructure(H, [[0., 0.], [2./3, 1./3],
                              [1./2, 1./2], [1., 1.]], 301,
                              [r'$\Gamma$', 'K', 'M', r'$\Gamma$'])

And finally we just ask for the fatbands plot:

[4]:
fatbands = band.plot.fatbands()
fatbands

We only see the bands here, but this is a fatbands plot, and it is ready to accept your requests on what to draw!

Requesting specific weights

The fatbands that the plot draws are controlled by the groups setting.

[5]:
print(fatbands.get_param("groups").help)
The different groups that are displayed in the fatbands

 Each item is a dict.

 Structure of the dict: {
        'name':
        'species':
        'atoms':

 Structure of the dict: {
        'index':

 Structure of the dict: {
        'in':
}
        'fx':
        'fy':
        'fz':
        'x':
        'y':
        'z':
        'Z':
        'neighbours':

 Structure of the dict: {
        'range':
        'R':
        'neigh_tag':
}
        'tag':
        'seq':
}
        'orbitals':
        'spin':
        'normalize':
        'color':
        'scale':
}

This setting works exactly like the requests setting in PdosPlot, which is documented here. Therefore we won’t give an extended description of it, but just quickly show that you can autogenerate the groups:

[6]:
fatbands.split_groups(on="species")

Or write them yourself if you want the maximum flexibility:

[7]:
fatbands.update_settings(groups=[
    {"species": "N", "color": "blue", "name": "Nitrogen"},
    {"species": "B", "color": "red", "name": "Boron"}
])

Scaling fatbands

The visual appeal of fatbands depends a lot on the size of your plot, therefore there’s one global scale setting that scales all fatbands at the same time:

[8]:
fatbands.update_settings(scale=2)

You can also use the scale_fatbands method, which additionally lets you choose if you want to rescale from the current size or just set the value of scale:

[9]:
fatbands.scale_fatbands(0.5, from_current=True)

Use BandsPlot settings

All settings of BandsPlot work as well for FatbandsPlot. Even spin texture!

We hope you enjoyed what you learned!


This next cell is just to create the thumbnail for the notebook in the docs

[10]:
thumbnail_plot = fatbands

if thumbnail_plot:
    thumbnail_plot.show("png")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
Input In [10], in <module>
      1 thumbnail_plot = fatbands
      3 if thumbnail_plot:
----> 4     thumbnail_plot.show("png")

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/plot.py:1180, in Plot.show(self, listen, return_figWidget, *args, **kwargs)
   1177     except Exception as e:
   1178         warn(e)
-> 1180 return self._backend.show(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.12.0/sisl/viz/backends/plotly/backend.py:42, in PlotlyBackend.show(self, *args, **kwargs)
     41 def show(self, *args, **kwargs):
---> 42     return self.figure.show(*args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/basedatatypes.py:3398, in BaseFigure.show(self, *args, **kwargs)
   3365 """
   3366 Show a figure using either the default renderer(s) or the renderer(s)
   3367 specified by the renderer argument
   (...)
   3394 None
   3395 """
   3396 import plotly.io as pio
-> 3398 return pio.show(self, *args, **kwargs)

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/io/_renderers.py:389, in show(fig, renderer, validate, **kwargs)
    386 fig_dict = validate_coerce_fig_to_dict(fig, validate)
    388 # Mimetype renderers
--> 389 bundle = renderers._build_mime_bundle(fig_dict, renderers_string=renderer, **kwargs)
    390 if bundle:
    391     if not ipython_display:

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/io/_renderers.py:297, in RenderersConfig._build_mime_bundle(self, fig_dict, renderers_string, **kwargs)
    294             if hasattr(renderer, k):
    295                 setattr(renderer, k, v)
--> 297         bundle.update(renderer.to_mimebundle(fig_dict))
    299 return bundle

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/io/_base_renderers.py:128, in ImageRenderer.to_mimebundle(self, fig_dict)
    127 def to_mimebundle(self, fig_dict):
--> 128     image_bytes = to_image(
    129         fig_dict,
    130         format=self.format,
    131         width=self.width,
    132         height=self.height,
    133         scale=self.scale,
    134         validate=False,
    135         engine=self.engine,
    136     )
    138     if self.b64_encode:
    139         image_str = base64.b64encode(image_bytes).decode("utf8")

File ~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.12.0/lib/python3.10/site-packages/plotly/io/_kaleido.py:134, in to_image(fig, format, width, height, scale, validate, engine)
    132     # Raise informative error message if Kaleido is not installed
    133     if scope is None:
--> 134         raise ValueError(
    135             """
    136 Image export using the "kaleido" engine requires the kaleido package,
    137 which can be installed using pip:
    138     $ pip install -U kaleido
    139 """
    140         )
    142     # Validate figure
    143     # ---------------
    144     fig_dict = validate_coerce_fig_to_dict(fig, validate)

ValueError:
Image export using the "kaleido" engine requires the kaleido package,
which can be installed using pip:
    $ pip install -U kaleido