Dear KWANT community, Recently I have used KWANT to simulate electronic transport in T-junction with the perpendicular magnetic field applied to the nanostructure. As well known, the inclusion of the orbital effects in this case (by the peierls substitution) is not easy due to appropriate gauge which should be applied for the vertical leads. So I decided to use the newest functionality of KWANT included in kwant.physics.magnetic_gauge.
I started testing this function from a simple nanowire (NW) with two leads applied on both sides of NW and the magnetic field perpendicular to NW. When calling ham=sys.hamiltonian_submatrix(params=params), similarly as in documentation, everything works OK. The problem appears when I am trying to calculate transport and call the function smatrix = kwant.smatrix(sys, energy=energy, params=params). Then, an following error occurs
i = syst.id_by_site[a] j = syst.id_by_site[b]# We only store *either* (i, j) *or* (j, i). If not presentKeyError: Site(kwant.lattice.Monatomic([[75.58904535685008, 0.0], [0.0, 75.58904535685008]], [0.0, 0.0], '', None), array([-1, -9])) The above exception was the direct cause of the following exception:
And I don't know how is the reason of this error.
Below I paste my code
nw = SimpleNamespace(\ W = 10, L = 100, dx = nm2au(4), m = 0.015, B = T2au(.5), )
def make_system_transport_gauge(nw): W=nw.W L=nw.L dx=nw.dx m=nw.m B=nw.B
def onsite(sitei,peierls): x,y=sitei.pos t=1.0/(2.0*nw.m*nw.dx*nw.dx) return 4*t
def hopping(sitei, sitej, peierls): xi,yi=sitei.pos xj,yj=sitej.pos t=1.0/(2.0*nw.m*nw.dx*nw.dx) return -t*peierls(sitei,sitej)
lat=kwant.lattice.square(dx) sys = kwant.Builder() sys[(lat(i,j) for i in range(L) for j in range(-W+1,W))]=onsite sys[lat.neighbors()] = hopping
syml = kwant.TranslationalSymmetry((-dx, 0)) l_lead=kwant.Builder(syml) l_lead[(lat(0,y) for y in range(-W+1,W))]=onsite l_lead[lat.neighbors()]=hopping l_lead.substituted(peierls='peierls_llead') sys.attach_lead(l_lead)
symr = kwant.TranslationalSymmetry((dx, 0)) r_lead=kwant.Builder(symr) r_lead[(lat(0,y) for y in range(-W+1,W))]=onsite r_lead[lat.neighbors()]=hopping r_lead.substituted(peierls='peierls_rlead') sys.attach_lead(r_lead)
sys = sys.finalized()
def B_syst(pos): return nw.B
sys=make_system_transport_gauge(nw) gauge = kwant.physics.magnetic_gauge(sys) peierls_sys, peierls_llead, peierls_rlead = gauge(B_syst, B_syst, B_syst) params = dict(t=1, peierls=peierls_sys, peierls_llead=peierls_llead, peierls_rlead=peierls_rlead) ham=sys.hamiltonian_submatrix(params=params) #this works
#I tried to calculate transport energy=eV2au(3e-3) smatrix = kwant.smatrix(sys, energy=energy, params=params) #this generates an error
I would be grateful for any help or hint what is wrong. Best regards, Pawel Wojcik
I can confirm that from your code, doing
``` lead0 = sys.leads lead0.inter_cell_hopping(params=params) ``` raises the same error.
Please, consider opening an issue in the Kwant gitlab repository.
Best regards, Pablo
The issue lies within the `lead.substituted` part. Until that bit is fixed, you can go ahead and define the leads' functions and Peierl's phase functions with different names for each lead.
I have checked that the below example works, it will be easy to adapt it to your case.
Best regards, Pablo
``` import numpy as np import kwant
def hopping(a, b, t, peierls): return -t * peierls(a, b)
def hopping_lead_1(a, b, t, peierls_lead_1): return -t * peierls_lead_1(a, b)
def hopping_lead_2(a, b, t, peierls_lead_2): return -t * peierls_lead_2(a, b)
size = 30 def make_system(hopping): lat = kwant.lattice.square(norbs=1) syst = kwant.Builder() syst[(lat(i, j) for i in range(size) for j in range(size))] = 0 syst[lat.neighbors()] = hopping return syst
def make_lead(hopping_lead, lattice_direction=(-1, 0)): symmetry = kwant.TranslationalSymmetry(lattice_direction) lat = kwant.lattice.square(norbs=1) lead = kwant.Builder(symmetry=symmetry) lead[(lat(i, j) for j in range(size) for i in range(abs(lattice_direction)))] = 0 lead[lat.neighbors()] = hopping_lead return lead
syst = make_system(hopping)
lead_1 = make_lead(hopping_lead_1, lattice_direction=(1, 0)) lead_2 = make_lead(hopping_lead_2, lattice_direction=(-1, 0))
syst = syst.finalized()
gauge = kwant.physics.magnetic_gauge(syst)
def B_syst(pos): return np.pi / 10
peierls_syst, peierls_lead_1, peierls_lead_2 = gauge(B_syst, B_syst, B_syst)
params = dict(t=1, peierls=peierls_syst, peierls_lead_1=peierls_lead_1, peierls_lead_2=peierls_lead_2)
smatrix = kwant.smatrix(syst, params=params, energy=1)
print(smatrix.transmission(0, 1)) ```
Hi again Paweł,
I realized that `substutited` *returns* a new builder, and does not change it in-place. The docs of `magnetic_gauge` were misleading there.
You can simply replace ``` l_lead = l_lead.substituted(peierls='peierls_llead') ... r_lead = r_lead.substituted(peierls='peierls_llead') ```
in your code, and should work.