.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "api/gallery/tight_binding/plot_visualizing_a_model.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_api_gallery_tight_binding_plot_visualizing_a_model.py: Visualizing a Model: tbkit.plot.Plot ========================================= Every other example in this gallery reaches straight for matplotlib to plot a spectrum or a band structure by hand. :class:`tbkit.plot.Plot` instead wraps the handful of plots that come up for *any* real-space model, directly from a :class:`~tbkit.system.System` instance: the lattice itself (with or without its hoppings drawn on), the spectrum (optionally colored by sublattice polarization), the density of states, and an eigenstate's spatial intensity. .. GENERATED FROM PYTHON SOURCE LINES 13-21 .. code-block:: Python import numpy as np from tbkit.graphene import GrapheneLattice from tbkit.system import System from tbkit.plot import Plot from tbkit.dos import density_of_states .. GENERATED FROM PYTHON SOURCE LINES 22-26 A small graphene flake ------------------------------ A zigzag hexagonal flake, small enough that the lattice and hopping plots below stay legible. .. GENERATED FROM PYTHON SOURCE LINES 26-44 .. code-block:: Python glat = GrapheneLattice() glat.hexagon_zigzag(n=4) sys = System(glat) sys.set_onsite({'a': 0., 'b': 0.}) sys.set_hopping([{'n': 1, 't': 1.}]) sys.get_ham() sys.get_eig(eigenvec=True) plot = Plot(sys) print('Flake: {} sites.'.format(glat.sites)) # Sanity check that holds for any bipartite lattice, field or not (see # also the magnetic-field examples): the spectrum is exactly symmetric # under E -> -E. en = np.sort(sys.en.real) assert np.allclose(en, -en[::-1], atol=1e-8) print('Particle-hole symmetry E -> -E: exact to machine precision.') .. rst-class:: sphx-glr-script-out .. code-block:: none Flake: 96 sites. Particle-hole symmetry E -> -E: exact to machine precision. .. GENERATED FROM PYTHON SOURCE LINES 45-47 The lattice, with hoppings drawn on ------------------------------------------ .. GENERATED FROM PYTHON SOURCE LINES 47-50 .. code-block:: Python fig1 = plot.lattice(plt_hop=True) .. image-sg:: /api/gallery/tight_binding/images/sphx_glr_plot_visualizing_a_model_001.png :alt: plot visualizing a model :srcset: /api/gallery/tight_binding/images/sphx_glr_plot_visualizing_a_model_001.png :class: sphx-glr-single-img .. GENERATED FROM PYTHON SOURCE LINES 51-58 Spectrum and sublattice polarization ------------------------------------------ ``tag_pola='a'`` colors each eigenstate by how much of its weight sits on sublattice ``a`` -- 1 for a state fully on ``a``, 0 for fully on ``b``. Every state's ``a`` + ``b`` weight sums to exactly 1 (a normalized eigenvector split across the two sublattices), regardless of how it is distributed between them. .. GENERATED FROM PYTHON SOURCE LINES 58-65 .. code-block:: Python fig2 = plot.spectrum(tag_pola='a') pola_sum = sys.pola.sum(axis=1) print('Sublattice weights sum to 1 for every state: {} (min={:.6f}, max={:.6f}).' .format(np.allclose(pola_sum, 1.), pola_sum.min(), pola_sum.max())) assert np.allclose(pola_sum, 1.) .. image-sg:: /api/gallery/tight_binding/images/sphx_glr_plot_visualizing_a_model_002.png :alt: Spectrum :srcset: /api/gallery/tight_binding/images/sphx_glr_plot_visualizing_a_model_002.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none Sublattice weights sum to 1 for every state: True (min=1.000000, max=1.000000). .. GENERATED FROM PYTHON SOURCE LINES 66-68 Density of states --------------------- .. GENERATED FROM PYTHON SOURCE LINES 68-77 .. code-block:: Python fig3 = plot.dos(broadening=0.1) # The broadened DOS integrates back to the total number of states, # regardless of the broadening kernel's width. e_grid, rho = density_of_states(sys.en, broadening=0.1) integral = np.trapezoid(rho, e_grid) print('DOS integrates to {:.3f} states (flake has {}).'.format(integral, glat.sites)) assert abs(integral - glat.sites) < 0.5 .. image-sg:: /api/gallery/tight_binding/images/sphx_glr_plot_visualizing_a_model_003.png :alt: Density of states :srcset: /api/gallery/tight_binding/images/sphx_glr_plot_visualizing_a_model_003.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none DOS integrates to 95.997 states (flake has 96). .. GENERATED FROM PYTHON SOURCE LINES 78-83 An eigenstate's spatial intensity ------------------------------------------ :meth:`~tbkit.plot.Plot.intensity_area` draws :math:`|\psi_i|^2` as a disk at each site, sized by the local weight -- here, for the state closest to zero energy. .. GENERATED FROM PYTHON SOURCE LINES 83-88 .. code-block:: Python i0 = np.argmin(np.abs(sys.en.real)) print('State closest to E=0: E={:.4f} (index {}).'.format(sys.en.real[i0], i0)) fig4 = plot.intensity_area(sys.intensity[:, i0], plt_hop=True, title=r'$|\psi|^2$ nearest $E=0$') .. image-sg:: /api/gallery/tight_binding/images/sphx_glr_plot_visualizing_a_model_004.png :alt: $|\psi|^2$ nearest $E=0$ :srcset: /api/gallery/tight_binding/images/sphx_glr_plot_visualizing_a_model_004.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none State closest to E=0: E=0.2294 (index 48). .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.186 seconds) .. _sphx_glr_download_api_gallery_tight_binding_plot_visualizing_a_model.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: plot_visualizing_a_model.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: plot_visualizing_a_model.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: plot_visualizing_a_model.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_