Download IPython notebook here. Binder badge.

GitHub issues by-label

WavefunctionPlot

The WavefunctionPlot class will help you very easily generate and display wavefunctions from a Hamiltonian or any other source. If you already have your wavefunction in a grid, you can use GridPlot.

Note

WavefunctionPlot is just an extension of GridPlot, so everything in the GridPlot notebook applies and this notebook will only display the additional features.

[1]:
import sisl
import sisl.viz.plotly

Generating wavefunctions from a hamiltonian

We will create a toy graphene tight binding hamiltonian, but you could have read the Hamiltonian from any source. Note that your hamiltonian needs to contain the corresponding geometry with the right orbitals, otherwise we have no idea what’s the shape of the wavefunction.

[2]:
import sisl
import numpy as np

r = np.linspace(0, 3.5, 50)
f = np.exp(-r)

orb = sisl.AtomicOrbital('2pzZ', (r, f))
geom = sisl.geom.graphene(orthogonal=True, atoms=sisl.Atom(6, orb))
geom = geom.move([0, 0, 5])
H = sisl.Hamiltonian(geom)
H.construct([(0.1, 1.44), (0, -2.7)], )

Now that we have our hamiltonian, plotting a wavefunction is as simple as:

[3]:
H.plot.wavefunction()

That truly is an ugly wavefunction.

Selecting the wavefunction

By default, WavefunctionPlot gives you the first wavefunction at the gamma point. You can control this behavior by tuning the i and k settings.

For example, to get the second wavefunction at the gamma point:

[4]:
plot = H.plot.wavefunction(i=2, k=(0, 0, 0))
plot

You can also select the spin with the spin setting (if you have, of course, a spin polarized Hamiltonian).

Note

If you update the number of the wavefunction, the eigenstates are already calculated, so there’s no need to recalculate them. However, changing the k point or the spin component will trigger a recalculation of the eigenstates.

Grid precision

The wavefunction is projected in a grid, and how fine that grid is will determine the resolution. You can control this with the grid_prec setting, which accepts the grid precision in Angstrom. Let’s check the difference in 2D, where it will be best appreciated:

[5]:
plot.update_settings(axes=[0,1], k=(0,0,0), transforms=["square"]) # by default grid_prec is 0.2 Ang
[6]:
plot.update_settings(grid_prec=0.05)

Much better, isn’t it? Notice how it didn’t look that bad in 3d, because the grid is smooth, so it’s values are nicely interpolated. You can also appreciate this by setting zsmooth to "best" in 2D, which does an “OK job” at guessing the values.

[7]:
plot.update_settings(grid_prec=0.2, zsmooth="best")

Warning

Keep in mind that a finer grid will occupy more memory and take more time to generate and render, and sometimes it might be unnecessary to make your grid very fine, specially if it’s smooth.

GridPlot settings

As stated at the beggining of this notebook, you have all the power of GridPlot available to you. Therefore you can, for example, display supercells of the resulting wavefunctions (please don’t tile the hamiltonian! :)).

[8]:
plot.update_settings(axes=[0,1,2], nsc=[2,2,1], grid_prec=0.1, transforms=[],
    isos=[
        {"frac": 0.3, "opacity": 1, "color": "salmon"},
        {"frac": 0.7, "opacity": 0.7, "color": "blue"}
    ],
    geom_kwargs={"atoms_color": ["orange", "red", "green", "pink"]},

)

We hope you enjoyed what you learned!


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

[9]:
thumbnail_plot = plot

if thumbnail_plot:
    thumbnail_plot.show("png")
---------------------------------------------------------------------------
ValueError                                Traceback (most recent call last)
/tmp/ipykernel_4847/1954004590.py in <module>
      2
      3 if thumbnail_plot:
----> 4     thumbnail_plot.show("png")

~/checkouts/readthedocs.org/user_builds/sisl/checkouts/v0.11.0/sisl/viz/plotly/plot.py in show(self, listen, return_figWidget, *args, **kwargs)
   1187                 warn(e)
   1188
-> 1189         return self.figure.show(*args, **kwargs)
   1190
   1191     def _ipython_display_(self, return_figWidget=False, **kwargs):

~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/basedatatypes.py in show(self, *args, **kwargs)
   3396         import plotly.io as pio
   3397
-> 3398         return pio.show(self, *args, **kwargs)
   3399
   3400     def to_json(self, *args, **kwargs):

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

~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/io/_renderers.py in _build_mime_bundle(self, fig_dict, renderers_string, **kwargs)
    295                         setattr(renderer, k, v)
    296
--> 297                 bundle.update(renderer.to_mimebundle(fig_dict))
    298
    299         return bundle

~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/io/_base_renderers.py in to_mimebundle(self, fig_dict)
    126
    127     def to_mimebundle(self, fig_dict):
--> 128         image_bytes = to_image(
    129             fig_dict,
    130             format=self.format,

~/checkouts/readthedocs.org/user_builds/sisl/conda/v0.11.0/lib/python3.8/site-packages/plotly/io/_kaleido.py 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,

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