In [1]:
import sys

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

init_notebook()

%output size=150
dims = SimpleNamespace(
    E_t=r"$E/t$",
    mu_t=r"$\mu/t$",
    lambda_=r"$\lambda$",
    x=r"$x$",
    k=r"$k$",
    amplitude=r"$|u|^2 + |v|^2$",
)

holoviews.core.dimension.title = ""


def kitaev_chain(L=None, periodic=False):
    lat = kwant.lattice.chain()

    if L is None:
        syst = kwant.Builder(kwant.TranslationalSymmetry((-1,)))
        L = 1
    else:
        syst = kwant.Builder()

    # transformation to antisymmetric basis
    U = np.array([[1.0, 1.0], [1.0j, -1.0j]]) / np.sqrt(2)

    def onsite(onsite, p):
        return -p.mu * U @ pauli.sz @ U.T.conj()

    for x in range(L):
        syst[lat(x)] = onsite

    def hop(site1, site2, p):
        return U @ (-p.t * pauli.sz - 1j * p.delta * pauli.sy) @ U.T.conj()

    syst[kwant.HoppingKind((1,), lat)] = hop

    if periodic:

        def last_hop(site1, site2, p):
            return hop(site1, site2, p) * (1 - 2 * p.lambda_)

        syst[lat(0), lat(L - 1)] = last_hop
    return syst


def bandstructure(mu, delta=1, t=1, Dirac_cone="Hide", show_pf=False):
    syst = kitaev_chain(None)
    p = SimpleNamespace(t=t, delta=delta, mu=mu)
    plot = holoviews.Overlay([spectrum(syst, p, ydim="$E/T$", xdim="$k$")][-4:4])
    h_1 = h_k(syst, p, 0)
    h_2 = h_k(syst, p, np.pi)
    pfaffians = [find_pfaffian(h_1), find_pfaffian(h_2)]

    if show_pf:
        signs = [(">" if pf > 0 else "<") for pf in pfaffians]
        title = (
            "$\mu = {mu} t$, Pf$(iH_{{k=0}}) {sign1} 0$, Pf$(iH_{{k=\pi}}) {sign2} 0$"
        )
        title = title.format(mu=mu, sign1=signs[0], sign2=signs[1])
        plot *= holoviews.VLine(0) * holoviews.VLine(-np.pi)
    else:
        if pfaffians[0] * pfaffians[1] < 0:
            title = "$\mu = {mu} t$, topological ".format(mu=mu)
        else:
            title = "$\mu = {mu} t$, trivial ".format(mu=mu)

    if Dirac_cone == "Show":
        ks = np.linspace(-np.pi, np.pi)
        ec = np.sqrt((mu + 2 * t) ** 2 + 4.0 * (delta * ks) ** 2)
        plot *= holoviews.Path((ks, ec), kdims=[dims.k, dims.E_t]).opts(
            style={"linestyle": "--", "color": "r"}
        )
        plot *= holoviews.Path((ks, -ec), kdims=[dims.k, dims.E_t]).opts(
            style={"linestyle": "--", "color": "r"}
        )
    return plot.relabel(title)


def find_pfaffian(H):
    return np.sign(np.real(pf.pfaffian(1j * H)))
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 2021-03-06 at 14:56:56.894319.