In [1]:
import sys

sys.path.append("../../code")
from init_mooc_nb import *

init_notebook()
from matplotlib import cm
from matplotlib.colors import hsv_to_rgb

pi_ticks = [(-np.pi, r"$-\pi$"), (0, "$0$"), (np.pi, r"$\pi$")]


def d_wave(w=None, direction=None):
    """Creates a d-wave system.
    
    Parameters:
    -----------
    w : int
        Width of the system, if None the system is infinite
    direction : str
        Direction of translation symmetry, if None it's an infinite
        system in x and y.
    """

    def hopx(site1, site2, p):
        return -p.t * pauli.sz - p.delta * pauli.sx

    def hopy(site1, site2, p):
        return -p.t * pauli.sz + p.delta * pauli.sx

    def onsite(site, p):
        return (4 * p.t - p.mu) * pauli.sz

    lat = kwant.lattice.square()

    if not w:

        def ribbon_shape(pos):
            (x, y) = pos
            return True

        sym = kwant.TranslationalSymmetry(*lat.prim_vecs)
    else:
        if direction == "topo":

            def ribbon_shape(pos):
                (x, y) = pos
                return 0 <= y - x < w

            sym = kwant.TranslationalSymmetry((1, 1))
        elif direction == "triv":

            def ribbon_shape(pos):
                (x, y) = pos
                return 0 <= y < w

            sym = kwant.TranslationalSymmetry((1, 0))

    syst = kwant.Builder(sym)

    syst[lat.shape(ribbon_shape, (0, 0))] = onsite
    syst[kwant.HoppingKind((1, 0), lat)] = hopx
    syst[kwant.HoppingKind((0, 1), lat)] = hopy

    return syst


def graphene_infinite():
    lat = kwant.lattice.honeycomb()
    a, b = lat.sublattices
    syst = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))
    syst[lat.shape(lambda pos: True, (0, 0))] = 0
    syst[kwant.builder.HoppingKind((0, 0), a, b)] = lambda site1, site2, p: p.t_1
    syst[kwant.builder.HoppingKind((0, 1), a, b)] = lambda site1, site2, p: p.t_23
    syst[kwant.builder.HoppingKind((-1, 1), a, b)] = lambda site1, site2, p: p.t_23
    return syst


def plot_dets(syst, p, ks, chiral=False):
    B = np.array(syst.symmetry.periods).T
    A = B @ np.linalg.inv(B.T @ B)

    def momentum_to_lattice(k):
        k, residuals = np.linalg.lstsq(A, k, rcond=-1)[:2]
        return list(k)

    syst = kwant.wraparound.wraparound(syst).finalized()
    kys, kxs = np.meshgrid(ks, ks)
    dets = np.zeros_like(kxs, dtype=complex)
    for i, kx in enumerate(ks):
        for j, ky in enumerate(ks):
            kx, ky = momentum_to_lattice([kx, ky])
            ham = syst.hamiltonian_submatrix(params=dict(p=p, k_x=kx, k_y=ky))
            if chiral:
                # Bring the chiral symmetric Hamiltonian in offdiagonal form
                U = (pauli.s0 + 1j * pauli.sx) / np.sqrt(2)
                ham = U @ ham @ U.T.conjugate()
            dets[i, j] = ham[1, 0]
    H = np.angle(dets) / (2 * np.pi)
    V = np.abs(dets)
    H = np.mod(H, 1)
    V /= np.max(V)
    V = 1 - V ** 2
    S = np.ones_like(H)
    HSV = np.dstack((H, S, V))
    RGB = hsv_to_rgb(HSV)
    bounds = (ks.min(), ks.min(), ks.max(), ks.max())
    pl = holoviews.RGB(RGB, bounds=bounds, label=r"$\det(h)$", kdims=["$k_x$", "$k_y$"])
    return pl.opts(plot={"xticks": pi_ticks, "yticks": pi_ticks}).opts(
        style={"interpolation": None}
    )


def Weyl_slab(w=5):
    def hopx(site1, site2, p):
        return 0.5j * p.t * pauli.sx - p.t * pauli.sz

    def hopy(site1, site2, p):
        return -p.t * pauli.sz

    def hopz(site1, site2, p):
        return 0.5j * p.t * pauli.sy - p.t * pauli.sz

    def onsite(site, p):
        return 6 * p.t * pauli.sz - p.mu * pauli.sz

    lat = kwant.lattice.general(np.eye(3))
    syst = kwant.Builder(kwant.TranslationalSymmetry([1, 0, 0], [0, 1, 0]))

    def shape(pos):
        (x, y, z) = pos
        return 0 <= z < w

    syst[lat.shape(shape, (0, 0, 0))] = onsite
    syst[kwant.HoppingKind((1, 0, 0), lat)] = hopx
    syst[kwant.HoppingKind((0, 1, 0), lat)] = hopy
    syst[kwant.HoppingKind((0, 0, 1), lat)] = hopz

    return syst
Populated the namespace with:
np, matplotlib, kwant, holoviews, init_notebook, SimpleNamespace, pprint_matrix, scientific_number, pretty_fmt_complex, plt, pf, display_html
from code/edx_components:
MoocVideo, MoocDiscussion, MoocCheckboxesAssessment, MoocMultipleChoiceAssessment, MoocSelfAssessment
from code/functions:
spectrum, hamiltonian_array, h_k, pauli
Using kwant 1.4.2 and holoviews 1.13.2
Executed on 2020-06-07 at 08:22:34.889793.