In [1]:
import sys

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

init_notebook()
%output size=110
from holoviews.core.options import Cycle


def nanowire_chain():
    lat = kwant.lattice.chain()
    syst = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))

    def onsite(onsite, p):
        return (2 * p.t - p.mu) * pauli.szs0 + p.B * pauli.s0sz + p.delta * pauli.sxs0

    syst[lat(0)] = onsite

    def hop(site1, site2, p):
        return -p.t * pauli.szs0 - 0.5j * p.alpha * pauli.szsx

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

    return syst


def spinful_kitaev_chain():
    lat = kwant.lattice.chain()
    syst = kwant.Builder(kwant.TranslationalSymmetry(*lat.prim_vecs))

    def onsite(site, p):
        return (2 * p.t - p.mu) * pauli.szs0 + p.B * pauli.szsz

    syst[lat(0)] = onsite

    def hop(site1, site2, p):
        return -p.t * pauli.szs0 - 1j * p.delta * pauli.sys0

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

    return syst


def find_gap(syst, p, resolution=1e-4):
    """Find gap in a system by doing a binary search in energy."""

    # This tells us if there are modes at a certain energy.
    if len(syst.modes(energy=0, params=dict(p=p))[0].momenta):
        return 0

    gap = step = min(abs(kwant.physics.Bands(syst, params=dict(p=p))(k=0))) / 2
    while step > resolution:
        step /= 2
        if len(syst.modes(gap, params=dict(p=p))[0].momenta):
            gap -= step
        else:
            gap += step

    return gap


def spinorbit_band_gap(syst, mu, t, delta, Bs):
    syst = syst.finalized()
    alphas = [0.0, 0.1, 0.2, 0.3]
    p = SimpleNamespace(mu=mu, t=t, delta=delta)

    def gap(syst, p, alpha, B):
        p.alpha = alpha
        p.B = B
        return find_gap(syst, p)

    gaps = [gap(syst, p, alpha, B) for alpha in alphas for B in Bs]
    gaps = np.reshape(gaps, (len(alphas), -1))
    dims = {"kdims": [r"$B$"], "vdims": ["Band gap"]}
    B_crit = holoviews.VLine(np.sqrt(p.delta ** 2 + p.mu ** 2))
    plot = [
        holoviews.Curve((Bs, gaps[i]), label=r"$\alpha={}$".format(alphas[i]), **dims)
        * B_crit
        for i, alpha in enumerate(alphas)
    ]
    title = r"$\Delta={:.2}$, $\mu={:.2}$".format(p.delta, p.mu)
    style = {"xticks": [0, 0.1, 0.2, 0.3], "yticks": [0, 0.05, 0.1], "fig_size": 150}
    plot = holoviews.Overlay(plot)
    return plot.opts(plot=style)


def title(p):
    try:
        title = r"$\alpha={:.2}$, $\mu={:.2}$, $B={:.2}$, $\Delta={:.2}$"
        title = title.format(p.alpha, p.mu, p.B, p.delta)
    except AttributeError:
        title = r"$\mu={:.2}$, $B={:.2}$, $\Delta={:.2}$"
        title = title.format(p.mu, p.B, p.delta)
    return title


style = {
    "k_x": np.linspace(-1, 1, 101),
    "xdim": r"$k$",
    "ydim": r"$E/t$",
    "xticks": [-1, 0, 1],
    "yticks": [-1, 0, 1],
    "xlims": [-1, 1],
    "ylims": [-1.5, 1.5],
    "title": title,
}
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:43.937124.