Ejemplo n.º 1
0
def main():
    # Define the system:
    hamiltonian_up = gasb.hamiltonian_97_up()
    hamiltonian_dn = gasb.hamiltonian_97_up_y_inv()
    lead_ham = gasb.hamiltonian_97_up(-100)
    centralShape = shapes.Rect()
    syst_up = gasb.system_builder(hamiltonian_up, lead_ham, centralShape)
    syst_dn = gasb.system_builder(hamiltonian_dn, lead_ham, centralShape)

    # Calculate the wave_function:
    energia = 442
    parametros = gasb.params_97
    parametros['eF'] = 60
    # parametros = dict(GammaLead = parametros["GammaC"], V = 100, **parametros )
    wf_up = kwant.wave_function(syst_up, energy=energia, params=parametros)
    wf_dn = kwant.wave_function(syst_dn, energy=energia, params=parametros)
    modes_up = wf_up(0)  # from left lead
    modes_dn = wf_dn(0)  # from left lead

    # Calculate the density:
    rho_up = kwant.operator.Density(syst_up)
    rho_dn = kwant.operator.Density(syst_dn)
    psi_up = sum(rho_up(p) for p in modes_up)
    psi_dn = sum(rho_dn(p) for p in modes_dn)

    # Calculate dos in a line
    dos_in_line_up, y_values_up = density_in_line(syst_up, modes_up)
    dos_in_line_dn, y_values_dn = density_in_line(syst_dn, modes_dn)

    # Plot the results:
    fig, ax = plt.subplots(2, 2, figsize=(14, 6))
    y_values_up = y_values_up * (shapes.A0 / 10)  # conversion to nm^{-1}
    y_values_dn = y_values_dn * (shapes.A0 / 10)  # conversion to nm^{-1}
    min_line, max_line = -0.7 * shapes.L_STD, 0.7 * shapes.L_STD

    map_density(ax[0][0], syst_up, psi_up, colormap="Reds")
    ax[0][0].vlines(0, min_line, max_line, linestyle="--")
    ax[0][0].set_title("spin up")
    map_density(ax[1][0], syst_dn, psi_dn, colormap="Blues")
    ax[1][0].vlines(0, min_line, max_line, linestyle="--")
    ax[1][0].set_title("spin up inv.")

    ax[0][1].plot(y_values_up,
                  normalize(dos_in_line_up),
                  marker=".",
                  markersize=2.5,
                  linestyle="-",
                  color="red")
    ax[1][1].plot(y_values_dn,
                  normalize(dos_in_line_dn),
                  marker=".",
                  markersize=2.5,
                  linestyle="-")
    plt.tight_layout()
    plt.show()
Ejemplo n.º 2
0
def test_density_interpolation():
    ## Passing a Builder will raise an error
    pytest.raises(TypeError, plotter.interpolate_density, syst_2d(), None)

    # Test that the density is always identically zero at the box boundaries
    # as the bump function has finite support and we add a padding
    _test_border_0(kwant.plotter.interpolate_density)

    def R(theta):
        return ta.array([[cos(theta), -sin(theta)], [sin(theta), cos(theta)]])

    # Make lattice with lattice vectors perturbed from x and y directions
    def make_lattice(a, salt='0'):
        theta_x = kwant.digest.uniform('x', salt=salt) * np.pi / 6
        theta_y = kwant.digest.uniform('y', salt=salt) * np.pi / 6
        x = ta.dot(R(theta_x), (a, 0))
        y = ta.dot(R(theta_y), (0, a))
        return kwant.lattice.general([x, y], norbs=1)

    # Check that integrating the interpolated density gives the same result
    # as summing the densities on all sites. We check this for several lattice
    # widths, lattice orientations and bump widths.
    for a, width in itertools.product((1, 2), (1, 0.5)):
        lat = make_lattice(a)
        syst = syst_rect(lat, salt='0').finalized()

        psi = kwant.wave_function(syst, energy=3)(0)[0]
        density = kwant.operator.Density(syst)(psi)
        exact_charge = sum(density)
        # We verify that the result is good by interpolating for
        # various numbers of points-per-bump and verifying that
        # the error falls of as 1/n.
        data = []
        for n in [4, 6, 8, 11, 16]:
            rho, box = plotter.interpolate_density(syst,
                                                   density,
                                                   n=n,
                                                   abswidth=width)
            (xmin, xmax), (ymin, ymax) = box
            area = xmax - xmin * (ymax - ymin)
            N = rho.shape[0] * rho.shape[1]
            charge = np.sum(rho) * area / N
            data.append((n, abs(charge - exact_charge)))
        _, _, rvalue, *_ = scipy.stats.linregress(np.log(data))
        # Gradient of -1 on log-log plot means error falls off as 1/n
        # TODO: review this value once #280 has been dealt with.
        assert rvalue < -0.7

    # Test that the interpolation is linear in the input.
    rng = ensure_rng(1)
    lat = make_lattice(1, '1')
    syst = syst_rect(lat, salt='1').finalized()
    rho_0 = rng.rand(len(syst.sites))
    rho_1 = rng.rand(len(syst.sites))

    irho_0, _ = plotter.interpolate_density(syst, rho_0)
    irho_1, _ = plotter.interpolate_density(syst, rho_1)

    rho_tot, _ = plotter.interpolate_density(syst, rho_0 + 2 * rho_1)
    assert np.allclose(rho_tot, irho_0 + 2 * irho_1)
def test_opservables_spin():
    def onsite(site, B):
        return 2 * np.eye(2) + B * sigmaz

    L = 20
    lat = kwant.lattice.chain(norbs=2)
    syst = kwant.Builder()
    syst[(lat(i) for i in range(L))] = onsite
    syst[lat.neighbors()] = -1 * np.eye(2)
    lead = kwant.Builder(kwant.TranslationalSymmetry((-1, )))
    lead[lat(0)] = onsite
    lead[lat.neighbors()] = -1 * np.eye(2)
    syst.attach_lead(lead)
    syst.attach_lead(lead.reversed())
    fsyst = syst.finalized()
    args = (0.1, )
    down, up = kwant.wave_function(fsyst, energy=1., args=args)(0)

    x_hoppings = kwant.builder.HoppingKind((1, ), lat)
    spin_current_z = ops.Current(fsyst, sigmaz, where=x_hoppings(syst))
    _test(spin_current_z, up, args=args, per_el_val=1)
    _test(spin_current_z, down, args=args, per_el_val=-1)

    # calculate spin_x torque
    spin_torque_x = ops.Source(fsyst, sigmax, where=[lat(L // 2)])
    i = fsyst.id_by_site[lat(L // 2)]
    psi = up[2 * i:2 * (i + 1)] + down[2 * i:2 * (i + 1)]
    H_ii = onsite(None, *args)
    K = np.dot(H_ii, sigmax) - np.dot(sigmax, H_ii)
    expect = 1j * ft.reduce(np.dot, (psi.conj(), K, psi))
    _test(spin_torque_x, up + down, args=args, reduced_val=expect)
Ejemplo n.º 4
0
def dwell(cishu):
    e1=ens[cishu]

    tt = dg.t_gf(sys,e1,df)
    wf=kwant.wave_function(sys,e1)(0)[0]
    wf_integral=sum(abs(wf)**2)/2/np.pi
    return [tt,wf_integral]
Ejemplo n.º 5
0
def wf_integral_all(sys, e1):
    wf = kwant.wave_function(sys, e1)
    wf0 = wf(0)[0]
    wf1 = wf(1)[0]
    return np.array(
        [sum(abs(wf0)**2) / 2 / np.pi,
         sum(abs(wf1)**2) / 2 / np.pi])
Ejemplo n.º 6
0
def main():

    for i in [150,300,400,500,600,800,1000,1500]:
        print('----------------------------------------')
        sys_size=i
        start_time = time.time()
        syst = make_system(sys_size).finalized()
        print("------- system creation: %s seconds ---" % (time.time() - start_time))

        params = dict(r0=20, delta=10, J=1)
        start_time = time.time()
        wf = kwant.wave_function(syst, energy=-1, params=params)
        print("------- wave functions calculation: %s seconds ---" % (time.time() - start_time))
        psi = wf(0)[0]
        size = (syst.cell_size if isinstance(syst, kwant.system.InfiniteSystem) else syst.graph.num_nodes)
#        print(size*2, " ", (time.time() - start_time), file=open("sys_creat-times-OpStrings.dat", "a"))
        psi = np.zeros(size*2, dtype=complex)
        start_time = time.time()
        offECurr = generalOperator.offEnergyCurrentLead(syst, where=[None,None])
#        offECurr = generalOperatorStringsNotCalledNoPrints.offEnergyCurrentLead(syst, where=[None,None])
        print("------- operator initialisation: %s seconds ---" % (time.time() - start_time))
#        print(size*2, " ", (time.time() - start_time), file=open("init-times-OpStrings.dat", "a"))

#        # calculate the expectation values of the operators with 'psi'
        start_time = time.time()
        ecurr = offECurr(psi)
        print("------- operator calculation: %s seconds ---" % (time.time() - start_time))
#        print(size*2, " ", (time.time() - start_time), file=open("call-times-OpStrings.dat", "a"))
        print(ecurr)
Ejemplo n.º 7
0
def test_opservables_scattering():
    # Disordered system with two ordered strips on the left/right.  We check
    # that the current on the right of the disorder due to incoming mode `m` is
    # equal to Σ_n |t_nm|^2. Similarly the current on the left of the disorder
    # is checked against 1 - Σ_n |r_nm|^2

    N = 10
    lat, syst = _random_square_system(N)
    # add extra sites so we can calculate the current in a region
    # where there is no backscattering
    syst[(lat(i, j) for i in [-1, N] for j in range(N))] = 2
    syst[((lat(-1, j), lat(0, j)) for j in range(N))] = -1
    syst[((lat(N-1, j), lat(N, j)) for j in range(N))] = -1

    lat, lead = _perfect_lead(3)
    syst.attach_lead(lead)
    syst.attach_lead(lead.reversed())
    fsyst = syst.finalized()

    # currents on the left and right of the disordered region
    J_right = ops.Current(fsyst, where=[(lat(N, j), lat(N-1, j))
                                        for j in range(3)])
    J_left = ops.Current(fsyst, where=[(lat(0, j), lat(-1, j))
                                       for j in range(3)])

    smatrix = kwant.smatrix(fsyst, energy=1.0)
    t = smatrix.submatrix(1, 0).T  # want to iterate over the columns
    r = smatrix.submatrix(0, 0).T  # want to iterate over the columns
    wfs = kwant.wave_function(fsyst, energy=1.0)(0)
    for rv, tv, wf in zip(r, t, wfs):
        _test(J_right, wf, reduced_val=np.sum(np.abs(tv)**2))
        _test(J_left, wf, reduced_val=(1 - np.sum(np.abs(rv)**2)))
Ejemplo n.º 8
0
def test_opservables_spin():

    def onsite(site, B):
        return 2 * np.eye(2) + B * sigmaz

    L = 20
    lat = kwant.lattice.chain(norbs=2)
    syst = kwant.Builder()
    syst[(lat(i) for i in range(L))] = onsite
    syst[lat.neighbors()] = -1 * np.eye(2)
    lead = kwant.Builder(kwant.TranslationalSymmetry((-1,)))
    lead[lat(0)] = onsite
    lead[lat.neighbors()] = -1 * np.eye(2)
    syst.attach_lead(lead)
    syst.attach_lead(lead.reversed())
    fsyst = syst.finalized()
    args = (0.1,)
    down, up = kwant.wave_function(fsyst, energy=1., args=args)(0)

    x_hoppings = kwant.builder.HoppingKind((1,), lat)
    spin_current_z = ops.Current(fsyst, sigmaz, where=x_hoppings(syst))
    _test(spin_current_z, up, args=args, per_el_val=1)
    _test(spin_current_z, down, args=args, per_el_val=-1)

    # calculate spin_x torque
    spin_torque_x = ops.Source(fsyst, sigmax, where=[lat(L//2)])
    i = fsyst.id_by_site[lat(L//2)]
    psi = up[2*i:2*(i+1)] + down[2*i:2*(i+1)]
    H_ii = onsite(None, *args)
    K = np.dot(H_ii, sigmax) - np.dot(sigmax, H_ii)
    expect = 1j * ft.reduce(np.dot, (psi.conj(), K, psi))
    _test(spin_torque_x, up+down, args=args, reduced_val=expect)
Ejemplo n.º 9
0
def wf_01(cishu):
    en=en_wf[cishu]
    wf=kwant.wave_function(sys,en)(0)[0]
#    gf=kwant.greens_function(sys,en).submatrix(1,0)[:,0]
    myDict = {'wf':wf}
    completeName = os.path.join('E:/dwell3/786/', str(cishu)+".mat")
    sio.savemat(completeName,myDict,oned_as='row') 
Ejemplo n.º 10
0
def current_density(axis,
                    syst,
                    parameters,
                    eF_value=0,
                    energy=428,
                    lead_index=0,
                    colormap="Reds"):
    parameters["eF"] = eF_value

    wf = kwant.wave_function(syst, energy=energy, params=parameters)
    J_spin = kwant.operator.Current(syst)

    current_spin = sum(
        J_spin(psi, params=parameters) for psi in wf(lead_index))
    # kwant.plotter.current(syst, current_spin, cmap = colormap, colorbar = False, show = False, ax=axis, density=1/9)
    kwant.plotter.current(syst,
                          current_spin,
                          cmap=colormap,
                          colorbar=False,
                          show=False,
                          ax=axis)
    edit_axis(axis, "none")  # change units to nm
    axis.set_title(" ")

    return 0
Ejemplo n.º 11
0
def test_opservables_gauged():
    # Test that we get the same answer when we apply a random
    # gauge (unitary) transformation to each site. We also
    # adjust our definition of the current to match

    # this is to get round a bug in test_mask_interpolate (?!) that fails when
    # the random number state is altered.
    @contextmanager
    def save_random_state():
        old_state = np.random.get_state()
        yield
        np.random.set_state(old_state)

    L = 20
    with save_random_state():
        Us = deque([kwant.rmt.circular(2) for i in range(L)])
    # need these to get the coupling to the leads right
    Us.append(np.eye(2))
    Us.appendleft(np.eye(2))

    H0 = 2 * np.eye(2) + 0.1 * sigmaz  # onsite
    V0 = -1 * np.eye(2)  # hopping

    lat = kwant.lattice.chain(norbs=2)
    syst = kwant.Builder()

    for i, U in enumerate(Us):
        syst[lat(i)] = ft.reduce(np.dot, (U, H0, U.conjugate().transpose()))

    for a, b in kwant.builder.HoppingKind((1, ), lat)(syst):
        i, j = a.tag[0], b.tag[0]
        syst[(a, b)] = ft.reduce(np.dot,
                                 (Us[i], V0, Us[j].conjugate().transpose()))

    lead = kwant.Builder(kwant.TranslationalSymmetry((-1, )))
    lead[lat(0)] = H0
    lead[lat.neighbors()] = V0
    syst.attach_lead(lead)
    syst.attach_lead(lead.reversed())
    fsyst = syst.finalized()
    down, up = kwant.wave_function(fsyst, energy=1.0)(0)

    def M_a(site):
        i = site.tag[0]
        return ft.reduce(np.dot,
                         (Us[i], sigmaz, Us[i].conjugate().transpose()))

    x_hoppings = kwant.builder.HoppingKind((1, ), lat)
    spin_current_gauge = ops.Current(fsyst, M_a, where=list(x_hoppings(syst)))
    _test(spin_current_gauge, up, per_el_val=1)
    _test(spin_current_gauge, down, per_el_val=-1)
    # check the reverse is also true
    minus_x_hoppings = kwant.builder.HoppingKind((-1, ), lat)
    spin_current_gauge = ops.Current(fsyst,
                                     M_a,
                                     where=list(minus_x_hoppings(syst)))
    _test(spin_current_gauge, up, per_el_val=-1)
    _test(spin_current_gauge, down, per_el_val=1)
Ejemplo n.º 12
0
def wf_stat(salt):
    syst = dnlr.make_system_all(length, width, dis, str(salt), width_left,
                                width_right)
    sys = syst.finalized()
    t_s = dnlr.tranmission_DIY(sys, en)
    wf = kwant.wave_function(sys, en)(0)
    myDict = {'TM': t_s, 'wf': wf}
    completeName = os.path.join('E:/pt/20/', str(salt) + ".mat")
    sio.savemat(completeName, myDict, oned_as='row')
Ejemplo n.º 13
0
def test_opservables_gauged():
    # Test that we get the same answer when we apply a random
    # gauge (unitary) transformation to each site. We also
    # adjust our definition of the current to match

    # this is to get round a bug in test_mask_interpolate (?!) that fails when
    # the random number state is altered.
    @contextmanager
    def save_random_state():
        old_state = np.random.get_state()
        yield
        np.random.set_state(old_state)

    L = 20
    with save_random_state():
        Us = deque([kwant.rmt.circular(2) for i in range(L)])
    # need these to get the coupling to the leads right
    Us.append(np.eye(2))
    Us.appendleft(np.eye(2))

    H0 = 2 * np.eye(2) + 0.1 * sigmaz  # onsite
    V0 = -1 * np.eye(2)  # hopping

    lat = kwant.lattice.chain(norbs=2)
    syst = kwant.Builder()

    for i, U in enumerate(Us):
        syst[lat(i)] = ft.reduce(np.dot, (U, H0, U.conjugate().transpose()))

    for a, b in kwant.builder.HoppingKind((1,), lat)(syst):
        i, j = a.tag[0], b.tag[0]
        syst[(a, b)] = ft.reduce(np.dot,
                                 (Us[i], V0, Us[j].conjugate().transpose()))

    lead = kwant.Builder(kwant.TranslationalSymmetry((-1,)))
    lead[lat(0)] = H0
    lead[lat.neighbors()] = V0
    syst.attach_lead(lead)
    syst.attach_lead(lead.reversed())
    fsyst = syst.finalized()
    down, up = kwant.wave_function(fsyst, energy=1.0)(0)

    def M_a(site):
        i = site.tag[0]
        return ft.reduce(np.dot,
                         (Us[i], sigmaz, Us[i].conjugate().transpose()))

    x_hoppings = kwant.builder.HoppingKind((1,), lat)
    spin_current_gauge = ops.Current(fsyst, M_a, where=x_hoppings(syst))
    _test(spin_current_gauge, up, per_el_val=1)
    _test(spin_current_gauge, down, per_el_val=-1)
    # check the reverse is also true
    minus_x_hoppings = kwant.builder.HoppingKind((-1,), lat)
    spin_current_gauge = ops.Current(fsyst, M_a, where=minus_x_hoppings(syst))
    _test(spin_current_gauge, up, per_el_val=-1)
    _test(spin_current_gauge, down, per_el_val=1)
Ejemplo n.º 14
0
 def oscle(ene, lead_nr):
     wfs = kwant.wave_function(syst, ene,
                               check_hermiticity=True)(lead_nr)
     spin_current_z = 0
     for psi in wfs:
         psi_start = psi[0:2]
         psi_end = psi[2 * 61:2 * 61 + 2]
         #spin_current_z += -2 *imag(psi_end.conjugate().dot(sigma_z).dot(psi_start))
         spin_current_z += abs(
             imag(psi_end.conjugate().dot(sigma_z).dot(psi_start)))
     return spin_current_z
Ejemplo n.º 15
0
def stat_wf(salt):
    wf_spec=np.zeros((f_num,length),dtype=complex)
    t_spec=[]
    sys=od.make_system(length,dis,str(salt))
    sys=sys.finalized()
    for i in range(f_num):
        wf_spec[i,]=kwant.wave_function(sys,ens[i])(0)
        t_spec.append(kwant.smatrix(sys,ens[i]).transmission(1,0))
    myDict = {'wf':wf_spec,'t':t_spec} 
    completeName = os.path.join('E:/pt/5/',str(salt)+'.mat')
    sio.savemat(completeName,myDict,oned_as='row') 
def dwell(cishu):
    salt = cishu  #+random.random()*100

    #    width=49.6
    syst = make_system(width, length, str(salt))
    attach_lead(syst)
    #    kwant.plot(syst,fig_size=(25, 30))
    sys = syst.finalized()
    tt = t_gf(sys)
    wf = kwant.wave_function(sys, e1)(0)
    t_wf = sum(abs(wf[0])**2) / 2 / np.pi
    return [tt, t_wf]
Ejemplo n.º 17
0
def test_current():
    syst = syst_2d().finalized()
    J = kwant.operator.Current(syst)
    current = J(kwant.wave_function(syst, energy=1)(1)[0])

    # Test good codepath
    with tempfile.NamedTemporaryFile('w+b') as out:
        plotter.current(syst, current, file=out)

        fig = pyplot.Figure()
        ax = fig.add_subplot(1, 1, 1)
        plotter.current(syst, current, ax=ax, file=out)
def lni(cishu):
    en = 0.5
    salt = cishu + random.random() * 100
    sys = make_system(width, length, str(salt))
    wff = kwant.wave_function(sys, en)(0)
    w = np.abs(wff.T)
    coord = np.array([sys.pos(i) for i in range(w.shape[0] // 2)])
    up = np.concatenate((coord, w[0::2, ]), axis=1)
    down = np.concatenate((coord, w[1::2, ]), axis=1)
    myDict = {'u': up, 'd': down}
    completeName = os.path.join('E:/dwell2/5/', str(cishu) + ".mat")
    sio.savemat(completeName, myDict, oned_as='row')
Ejemplo n.º 19
0
def current_spin(syst,
                 parameters,
                 eF_value=0,
                 energy=428,
                 lead_index=0,
                 spin="up",
                 colormap="Reds",
                 axis=None):
    """
    Gera mapa da densidade de corrente para elétrons incidentes
    da lead esquerda. Se o axis é dado a função gera uma figura
    caso contrário somente a array resultante é retornada. Para
    se gerar uma figura posterioriormente, o systema deve ser
    construído de modo identico àquele usado para calcular a
    corrente (syst).

    "syst": Note que o sistema é TOTAL com a matriz Hamiltoniana 6x6;
    "parameters": dicionario -> define const. para a Hamiltoniana;
    "eF_value" : valor da magnitude do campo elétrico em meV;
    "energy": potencial eletroquímico dos eletrons incidentes;
    "lead_index": "0" para elétrons incidentes da esquerda e "1" para elétrons da direita;
    "spin": projeção do pseudo spin
    "colormap" = mapa de cores usado para 'plotting'
    "axis" = eixo usado para plot, caso seja 'None' a função retorna a array com os valores de corrente mas não gera figura

    """

    parameters["eF"] = eF_value
    if spin.lower() == "total": up, down = 1, 1
    elif spin.lower() == "up": up, down = 1, 0
    elif spin.lower() == "down": up, down = 0, 1

    sz_sub_matrix = np.array([[up, 0], [0, down]])
    Sz_total_matrix = np.kron(sz_sub_matrix, np.eye(3))
    wf = kwant.wave_function(syst, energy=energy, params=parameters)
    J_spin = kwant.operator.Current(syst, Sz_total_matrix)

    current_spin = sum(
        J_spin(psi, params=parameters) for psi in wf(lead_index))
    # kwant.plotter.current(syst, current_spin, cmap = colormap, colorbar = False, show = False, ax=axis, density=1/9)

    if axis != None:
        kwant.plotter.current(syst,
                              current_spin,
                              cmap=colormap,
                              colorbar=False,
                              show=False,
                              ax=axis)
        edit_axis(axis, spin)  # change units to nm

    return current_spin
Ejemplo n.º 20
0
def lnt_x1(cishu):
    salt = cishu + random()
    sys = make_system(length, width, str(salt))

    #    gf_mode=kwant.smatrix(sys,en).submatrix(1,0)
    #    t=kwant.smatrix(sys,en).transmission(1,0)
    wff = kwant.wave_function(sys, en)(0)
    w = np.abs(wff.T)
    coord = np.array([sys.pos(i) for i in range(w.shape[0])])
    u = np.concatenate((coord, w), axis=1)

    myDict = {'u': u}
    completeName = os.path.join('E:/dwell2/14/', str(cishu) + ".mat")
    sio.savemat(completeName, myDict, oned_as='row')
def lnt_x1(cishu):
    en = 0.4
    salt = cishu + random()
    sys = make_system(length, width, lead_width, str(salt))
    sm = kwant.smatrix(sys, en)
    gf_mode = sm.submatrix(1, 0)
    t = sm.transmission(1, 0)
    wff = kwant.wave_function(sys, en)(0)
    w = np.abs(wff.T)
    coord = np.array([sys.pos(i) for i in range(w.shape[0])])
    u = np.concatenate((coord, w), axis=1)

    myDict = {'u': u, 't': t, 'g': gf_mode}
    completeName = os.path.join('E:/narrowlead/11/', str(cishu) + ".mat")
    sio.savemat(completeName, myDict, oned_as='row')
Ejemplo n.º 22
0
def tau_n(cishu):
    en = 0.4
    salt = cishu + random.random() * 1000
    sys = make_system(length, width, str(salt))
    gf_mode = kwant.smatrix(sys, en).submatrix(1, 0)
    #    s=np.linalg.svd(gf_mode, full_matrices=False, compute_uv=False) #u, s, vh

    wf = kwant.wave_function(sys, en)(0)
    #    kwant.plotter.map(sys, (abs(wf[14])**2),num_lead_cells=5,fig_size=(15, 10),colorbar=False)

    ldos = kwant.ldos(sys, en)
    if cishu == 0:
        coord = np.array([sys.pos(i) for i in range(ldos.shape[0])])
        sio.savemat('E:/dwell3/167/coord.mat', {'coord': coord}, oned_as='row')
    myDict = {'gf_mode': gf_mode, 'wf': wf, 'ld': ldos}
    completeName = os.path.join('E:/dwell3/167/', str(cishu) + ".mat")
    sio.savemat(completeName, myDict, oned_as='row')
def TM(cishu):
    en = 0.4
    salt = cishu + random.random() * 100
    syst = make_system(width, length, str(salt))
    attach_lead(syst)
    sys = syst.finalized()
    wf = kwant.wave_function(sys, en)(0)

    gf_mode = kwant.smatrix(sys, en).submatrix(1, 0)
    #    s=np.linalg.svd(gf_mode, full_matrices=False, compute_uv=False) #u, s, vh
    ldos = kwant.ldos(sys, en)
    if cishu == 0:
        coord = np.array([sys.pos(i) for i in range(ldos.shape[0])])
        sio.savemat('E:/dwell3/703/coord.mat', {'coord': coord}, oned_as='row')
    myDict = {'gf_mode': gf_mode, 'wf': wf, 'ld': ldos}  #'s':s,
    completeName = os.path.join('E:/dwell3/703/', str(cishu) + ".mat")
    sio.savemat(completeName, myDict, oned_as='row')
Ejemplo n.º 24
0
def analyze_bhz(pot=0, L_barrier=100, shift=0, lead_index=0):
    def potential_barrier(x, y):
        if abs(x) < L_barrier / 2:
            return -(pot - shift)
        else:
            return 0

    params = dict(A=364.5,
                  B=-686.0,
                  D=-512.0,
                  M=-10.0,
                  C=potential_barrier,
                  C_const=-shift)

    syst = qsh_system()

    # get scattering wave functions at E=0
    wf = kwant.wave_function(syst, energy=-10, params=params)

    # prepare density operators
    # sigma_z = np.array([[1, 0], [0, -1]])
    prob_density = kwant.operator.Density(syst, np.kron(sigma_z, np.eye(2)))
    # J_0 = kwant.operator.Current(syst)

    # calculate expectation values and plot them
    wf_sqr = sum(prob_density(psi) for psi in wf(lead_index))
    print(max(wf_sqr))
    # current = sum(J_0(psi,params=params) for psi in wf(lead_index))
    fig, (ax1) = plt.subplots(1, 1, figsize=(16, 4))
    ax1 = plt.gca()
    ax1.set_title(r'$\Psi_{\uparrow}$')
    ax1.set_xlabel(r'$x$ [nm]')
    ax1.set_ylabel(r'$y$ [nm]')
    kwant.plotter.map(syst, (1 / max(wf_sqr)) * wf_sqr,
                      fig_size=(9, 2),
                      ax=ax1,
                      cmap='seismic')
    ax = ax1
    im = [
        obj for obj in ax.get_children()
        if isinstance(obj, mpl.image.AxesImage)
    ][0]
    fig.colorbar(im, ax=ax)
    plt.tight_layout()
    plt.show()
def lnt_x(cishu):
    salt = cishu + random()
    sys = make_system(width, length, str(salt))

    #    gf_mode=kwant.smatrix(sys,en).submatrix(1,0)
    #    t=kwant.smatrix(sys,en).transmission(1,0)
    wff = kwant.wave_function(sys, en)
    wf = wff(0)
    for num_channel in range(wf.shape[0]):
        wf1 = wf[num_channel, ]
        ans = []
        for k in range(len(wf1)):
            ans.append(np.append(sys.pos(k), wf1[k]))
        myDict = {'ans': ans}
        completeName = os.path.join(
            'E:/yuhao/65/',
            str(cishu * wf.shape[0] + num_channel) + ".mat")
        sio.savemat(completeName, myDict, oned_as='row')
Ejemplo n.º 26
0
def get_current_with_lead(sys,sysvx,sysvy,hop_sites,pars):
    wf = kwant.wave_function(sys, pars.EF, args=[pars])
    eva = wf(0)
    T = calculate.calculate_conductance(sys, pars.EF, 1, 0, pars)
    print T, eva.shape[0]

    xs, ys, sites_index, vx_coomatrix, vy_coomatrix = get_core_matrix(sysvx, sysvy, hop_sites, pars)

    vx0 = 0;
    ev0 = 0;
    vy0 = 0;
    for i in range(eva.shape[0]):
        ev = eva[i, :]
        vx, vy = get_current(ev, sites_index, vx_coomatrix, vy_coomatrix)

        vx0 = vx + vx0
        vy0 = vy + vy0
        ev0 = ev0 + np.abs(ev) ** 2
    return xs, ys, ev0, vx0, vy0
def TM(cishu):
    salt = cishu + random.random() * 100
    syst = make_system(width, length, str(salt))
    attach_lead(syst)
    sys = syst.finalized()
    #kwant.plot(sys, fig_size=(10, 3))
    wf = kwant.wave_function(sys, 0.4)(0)
    #    kwant.plotter.map(sys, (abs(wf[14])**2),num_lead_cells=5,fig_size=(15, 10),colorbar=False)
    #
    #    t=kwant.smatrix(sys,.35).transmission(1,0)

    gf_mode = kwant.smatrix(sys, 0.4).submatrix(1, 0)
    #    s=np.linalg.svd(gf_mode, full_matrices=False, compute_uv=False) #u, s, vh
    ldos = kwant.ldos(sys, 0.4)
    if cishu == 0:
        coord = np.array([sys.pos(i) for i in range(ldos.shape[0])])
        sio.savemat('E:/dwell3/327/coord.mat', {'coord': coord}, oned_as='row')
    myDict = {'gf_mode': gf_mode, 'wf': wf, 'ld': ldos}  #'s':s,
    completeName = os.path.join('E:/dwell3/327/', str(cishu) + ".mat")
    sio.savemat(completeName, myDict, oned_as='row')
Ejemplo n.º 28
0
def get_current_with_lead(sys, sysvx, sysvy, hop_sites, pars):
    wf = kwant.wave_function(sys, pars.EF, args=[pars])
    eva = wf(0)
    T = calculate.calculate_conductance(sys, pars.EF, 1, 0, pars)
    print T, eva.shape[0]

    xs, ys, sites_index, vx_coomatrix, vy_coomatrix = get_core_matrix(
        sysvx, sysvy, hop_sites, pars)

    vx0 = 0
    ev0 = 0
    vy0 = 0
    for i in range(eva.shape[0]):
        ev = eva[i, :]
        vx, vy = get_current(ev, sites_index, vx_coomatrix, vy_coomatrix)

        vx0 = vx + vx0
        vy0 = vy + vy0
        ev0 = ev0 + np.abs(ev)**2
    return xs, ys, ev0, vx0, vy0
Ejemplo n.º 29
0
def main():
    """
    This code is for generate maps of current, without bands structures and
    with custom operators. This will allow a better exploratory process.
    """
    # Define the system
    hamiltonian = gasb.hamiltonian_97_k_plus()
    lead_ham = gasb.free_ham(norbs = 6)
    centralShape = shapes.Rect()
    syst = gasb.system_builder(hamiltonian, lead_ham, centralShape)

    # Calculate the wave function:
    energia = 442
    parametros = gasb.params_97
    parametros['eF'] = 60
    parametros['Eta2'] = 0
    parametros['Eta3'] = 0
    parametros = dict(GammaLead = parametros["GammaC"], V = 100, **parametros)
    wf = kwant.wave_function(syst, energy=energia, params=parametros)
    # modes = wf_dn(0) # from left lead

    # Define the operator
    σz = tinyarray.array([[1,0],[0,-1]])
    Mz = np.kron(σz, np.eye(3))

    # Current
    colormap = "Reds"
    J_spin = kwant.operator.Current(syst, Mz)
    current_spin = sum(J_spin(psi, params = parametros) for psi in wf(0))


    # Plot and/or save the data
    fig, axis =  plt.subplots(1,1, figsize=(8,8))
    kwant.plotter.current(syst, current_spin,
                            cmap = colormap,
                            colorbar = False,
                            show = False,
                            ax = axis)
    edit_axis(axis)
    plt.show()
Ejemplo n.º 30
0
def plot_psi(sys, energy, dx, W, L, args):
	wave_f=kwant.wave_function(sys,energy,args)
	density_lead_up=(abs(wave_f(0))**2).sum(axis=0)
	density_lead_down=(abs(wave_f(1))**2).sum(axis=0)
	sites= sys.sites

	psi_lead_up= dict(zip(sites, density_lead_up))
	psi_lead_down= dict(zip(sites, density_lead_down))

	lat_u = kwant.lattice.square(dx, name='up')
	lat_d = kwant.lattice.square(dx, name='down')

	f=open('psi'+str(energy/f_eV2au)+'.dat','w')

	for i in range(0,L):
		for j in range(-W+1,W):
			f_up=psi_lead_up[lat_u(i,j)]+psi_lead_down[lat_u(i,j)]
			f_down=psi_lead_up[lat_d(i,j)]+psi_lead_down[lat_d(i,j)]
			f_updown=f_up+f_down
			f.write("%e %e %e %e %e\n"%(i*dx/f_nm2au,j*dx/f_nm2au,f_up,f_down,f_updown))
		f.write("\n")

	f.close()
def test_opservables_scattering():
    # Disordered system with two ordered strips on the left/right.  We check
    # that the current on the right of the disorder due to incoming mode `m` is
    # equal to Σ_n |t_nm|^2. Similarly the current on the left of the disorder
    # is checked against 1 - Σ_n |r_nm|^2

    N = 10
    lat, syst = _random_square_system(N)
    # add extra sites so we can calculate the current in a region
    # where there is no backscattering
    syst[(lat(i, j) for i in [-1, N] for j in range(N))] = 2
    syst[((lat(-1, j), lat(0, j)) for j in range(N))] = -1
    syst[((lat(N - 1, j), lat(N, j)) for j in range(N))] = -1

    lat, lead = _perfect_lead(3)
    syst.attach_lead(lead)
    syst.attach_lead(lead.reversed())
    fsyst = syst.finalized()

    # currents on the left and right of the disordered region
    right_interface = [(lat(N, j), lat(N - 1, j)) for j in range(3)]
    left_interface = [(lat(0, j), lat(-1, j)) for j in range(3)]
    J_right = ops.Current(fsyst, where=right_interface)
    J_right_tot = ops.Current(fsyst, where=right_interface, sum=True)
    J_left = ops.Current(fsyst, where=left_interface)
    J_left_tot = ops.Current(fsyst, where=left_interface, sum=True)

    smatrix = kwant.smatrix(fsyst, energy=1.0)
    t = smatrix.submatrix(1, 0).T  # want to iterate over the columns
    r = smatrix.submatrix(0, 0).T  # want to iterate over the columns
    wfs = kwant.wave_function(fsyst, energy=1.0)(0)
    for rv, tv, wf in zip(r, t, wfs):
        _test(J_right, wf, reduced_val=np.sum(np.abs(tv)**2))
        _test(J_right_tot, wf, per_el_val=np.sum(np.abs(tv)**2))
        _test(J_left, wf, reduced_val=(1 - np.sum(np.abs(rv)**2)))
        _test(J_left_tot, wf, per_el_val=(1 - np.sum(np.abs(rv)**2)))
Ejemplo n.º 32
0
def test_phase_sign(system_and_gauge):
    syst, gauge = system_and_gauge

    peierls, peierls_left, peierls_right = gauge(0.1, 0.1, 0.1)

    params = dict(peierls=peierls, peierls_left=peierls_left,
                  peierls_right=peierls_right)

    cut = [(square_lattice(1, j), square_lattice(0, j))
            for j in range(10)]
    J = kwant.operator.Current(syst, where=cut)
    J = J.bind(params=params)

    psi = kwant.wave_function(syst, energy=0.6, params=params)(0)[0]

    # Electrons incident from the left travel along the *top*
    # edge of the Hall bar in the presence of a magnetic field
    # out of the plane
    j = J(psi)
    j_bottom = sum(j[0:5])
    j_top = sum(j[5:10])

    assert np.isclose(j_top + j_bottom, 1)  # sanity check
    assert j_top > 0.9
Ejemplo n.º 33
0
def wave_density(sys,  pars, lead_nr=0):
    wf = kwant.wave_function(sys, pars.EF, args=[pars])
    return (abs(wf(lead_nr))**2).sum(axis=0)
Ejemplo n.º 34
0
def wave_density(sys, pars, lead_nr=0):
    wf = kwant.wave_function(sys, pars.EF, args=[pars])
    return (abs(wf(lead_nr))**2).sum(axis=0)
Ejemplo n.º 35
0
        x, y = pos
        return abs(y) < width

    sym = kwant.TranslationalSymmetry((-1, 0))
    sym.add_site_family(graphene.sublattices[0], other_vectors=[(-1, 2)])
    sym.add_site_family(graphene.sublattices[1], other_vectors=[(-1, 2)])

    lead = kwant.Builder(sym)  #,conservation_law=-sz

    lead[graphene.shape(lead_shape, (0, width - 1))] = 0
    lead[graphene.neighbors()] = 1
    #    lead[[kwant.builder.HoppingKind(*hopping) for hopping in nnn_hoppings]]=1j *m2

    sys.attach_lead(lead)
    sys.attach_lead(lead.reversed())


#def gf_virtual(cishu):

syst = make_system(width, length, str(8900))
attach_lead(syst)
sys = syst.finalized()
#kwant.plot(sys, fig_size=(10, 3))
wff = kwant.wave_function(sys, .4)
wf = wff(0)
kwant.plotter.map(sys, (abs(wf[16])),
                  num_lead_cells=5,
                  fig_size=(15, 10),
                  colorbar=False)  #

elapsed = time() - t_ini
Ejemplo n.º 36
0
    sys = kwant.Builder()
    sys[graphene.shape(disk, (0, 0))] = onsite
    sys[graphene.neighbors()] = -1
    lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))
    lead[graphene.shape(edge, (0, 0))] = onsite_lead
    lead[graphene.neighbors()] = -1
    sys.attach_lead(lead)
    sys.attach_lead(lead.reversed())
    return sys.finalized()


#pyplot.rcParams["figure.figsize"] = [20,10]
#kwant.plot(sys)

sys = make_system()
wf = kwant.wave_function(sys, en)(0)
#wavef1=[]
#for i in range(wf.shape[1]):
#    wavef1.append(wf[0,i])
#kwant.plotter.map(sys,(abs(np.array(wavef1))**2), fig_size=(20, 12))

tpp = (abs(wf)**2)[0, ]
kwant.plotter.map(sys, tpp, fig_size=(20, 12))

gf = kwant.greens_function(sys, en).submatrix(1, 0)
t1 = kwant.greens_function(sys, en).transmission(1, 0)
sg = np.linalg.svd(gf, compute_uv=False)
taug1 = sg**2

#gf_measure=np.zeros([14,14],dtype=complex)
#for j in range(14):
Ejemplo n.º 37
0
def plot_spin(sys, energy, dx, W, L, args):
	wave_f=kwant.wave_function(sys, energy, args)
	Sxup=[[0 for i in range(-W+1,W)] for j in range(L)]
	Syup=[[0 for i in range(-W+1,W)] for j in range(L)]
	Szup=[[0 for i in range(-W+1,W)] for j in range(L)]

	sites=sys.sites
	lat_u = kwant.lattice.square(dx, name='up')
	lat_d = kwant.lattice.square(dx, name='down')

	#####wpuszczamy spin up
	for k in range(len(wave_f(0))):
		wf=dict(zip(sites,wave_f(0)[k]))
		for i in range(0,L):
			for j in range(-W+1,W):
				Sxup[i][j]+=wf[lat_u(i,j)].conjugate()*wf[lat_d(i,j)]+wf[lat_d(i,j)].conjugate()*wf[lat_u(i,j)]
				Syup[i][j]+=-1j*wf[lat_u(i,j)].conjugate()*wf[lat_d(i,j)]+1j*wf[lat_d(i,j)].conjugate()*wf[lat_u(i,j)]
				Szup[i][j]+=wf[lat_u(i,j)].conjugate()*wf[lat_u(i,j)]-wf[lat_d(i,j)].conjugate()*wf[lat_d(i,j)]

		del wf

	f1=open('spin_up'+str(energy/f_eV2au)+'.dat',"w")
	for i in range(0,L):
		for j in range(-W+1,W):
			f1.write("%e %e %e %e %e %e %e %e\n" % (i*dx/f_nm2au,j*dx/f_nm2au, Sxup[i][j].real, Syup[i][j].real, Szup[i][j].real, Sxup[i][j].imag, Syup[i][j].imag, Szup[i][j].imag))
		f1.write("\n")
	f1.close()


	Sxdn=[[0 for i in range(-W+1,W)] for j in range(L)]
	Sydn=[[0 for i in range(-W+1,W)] for j in range(L)]
	Szdn=[[0 for i in range(-W+1,W)] for j in range(L)]


	#####wpuszczamy spin down
	for k in range(len(wave_f(1))):
		wf=dict(zip(sites,wave_f(1)[k]))
		for i in range(0,L):
			for j in range(-W+1,W):
				Sxdn[i][j]+=wf[lat_u(i,j)].conjugate()*wf[lat_d(i,j)]+wf[lat_d(i,j)].conjugate()*wf[lat_u(i,j)]
				Sydn[i][j]+=-1j*wf[lat_u(i,j)].conjugate()*wf[lat_d(i,j)]+1j*wf[lat_d(i,j)].conjugate()*wf[lat_u(i,j)]
				Szdn[i][j]+=wf[lat_u(i,j)].conjugate()*wf[lat_u(i,j)]-wf[lat_d(i,j)].conjugate()*wf[lat_d(i,j)]

		del wf

	f1=open('spin_down'+str(energy/f_eV2au)+'.dat',"w")
	for i in range(0,L):
		for j in range(-W+1,W):
			f1.write("%e %e %e %e %e %e %e %e\n" % (i*dx/f_nm2au,j*dx/f_nm2au, Sxdn[i][j].real, Sydn[i][j].real, Szdn[i][j].real, Sxdn[i][j].imag, Sydn[i][j].imag, Szdn[i][j].imag))
		f1.write("\n")
	f1.close()


	Sx=[[0 for i in range(-W+1,W)] for j in range(L)]
	Sy=[[0 for i in range(-W+1,W)] for j in range(L)]
	Sz=[[0 for i in range(-W+1,W)] for j in range(L)]
	for i in range(0,L):
	  for j in range(-W+1,W):
	    Sx[i][j]=Sxup[i][j]+Sxdn[i][j]
	    Sy[i][j]=Syup[i][j]+Sydn[i][j]
	    Sz[i][j]=Szup[i][j]+Szdn[i][j]

	f1=open('spin'+str(energy/f_eV2au)+'.dat',"w")
	for i in range(0,L):
		for j in range(-W+1,W):
			f1.write("%e %e %e %e %e %e %e %e\n" % (i*dx/f_nm2au,j*dx/f_nm2au, Sx[i][j].real, Sy[i][j].real, Sz[i][j].real, Sx[i][j].imag, Sy[i][j].imag, Sz[i][j].imag))
		f1.write("\n")
	f1.close()