Dear all,
please help
I get a different conductance plot every time by executing the same program. i didnot change anything in the program. Whats the problem? Please help me
import kwant
import numpy as np
from matplotlib import pyplot
import matplotlib.pyplot as plt
import numpy as np
import numpy.linalg as npl
import scipy.sparse.linalg as sla
import os
output_directory="output"
def saveoutput(fname, datatuple, header=""):
fname2 = os.path.join(output_directory, fname)
np.savetxt(
fname2, np.column_stack(datatuple), fmt="%.6e", delimiter="\t", header=header
)
def set_pub():
plt.rcParams.update({
"font.weight": "bold", # bold fonts
"font.size":18,
#"tick.labelsize": 15, # large tick labels
"lines.linewidth": 2, # thick lines
"lines.color": "k", # black lines
"grid.color": "0.5", # gray gridlines
"grid.linestyle": "-", # solid gridlines
"grid.linewidth": 0.5, # thin gridlines
"xtick.major.size":10,
"xtick.minor.size":5,
"ytick.major.size":10,
"ytick.minor.size":5,
"savefig.dpi": 600, # higher resolution output.
})
Wnr=99
lnr=60
a=2.46
lat=kwant.lattice.honeycomb(a,norbs=1)
a,b=lat.sublattices
def rect(pos):
x,y=pos
return 0<=x<=lnr and 0<=y<=Wnr
def delet(pos):
x, y = pos
return 0<=x<=39 and 20<=y<=80 # for 20 atoms x is 35 ,
#for 17 atoms x is 39
# for 23 atoms x is 31,
#41 for 15 atoms
#for 14 atoms ===42
def onsite(site, voltage):
x, y = site.pos
return voltage
model1 = kwant.Builder()
model1[lat.shape(rect,(1,1))] = 0
model1[lat.neighbors()] =2.64
del model1[lat.shape(delet, (11,25))]
model1.eradicate_dangling()
###########lead 1#############
def lead1_shape(pos):
x, y = pos
return 0<y <=20
def lead2_shape(pos):
x, y = pos
return 80<=y<=Wnr
sym = kwant.TranslationalSymmetry(lat.vec((-1,0))) #from the left
sym.add_site_family(lat.sublattices[0], other_vectors=[(-1, 2)])
sym.add_site_family(lat.sublattices[1], other_vectors=[(-1, 2)])
lead = kwant.Builder(sym)
lead[lat.shape(lead1_shape, (1,2))]=onsite
lead[lat.neighbors()] =2.64
model1.attach_lead(lead)
########### lead 2 #################
sym1 = kwant.TranslationalSymmetry(lat.vec((-1,0))) #from the left
sym1.add_site_family(lat.sublattices[0], other_vectors=[(-1, 2)])
sym1.add_site_family(lat.sublattices[1], other_vectors=[(-1, 2)])
lead2 = kwant.Builder(sym1)
lead2[lat.shape(lead2_shape, (2,82))]=0
lead2[lat.neighbors()] = 2.64
model1.attach_lead(lead)
model1.attach_lead(lead2)
model1=model1.finalized()
kwant.plot(model1,dpi=300)
set_pub()
plt.rc('axes', linewidth=2.0)
plt.savefig('output\\Ushape.tif',bbox_inches='tight',dpi=300)
##################calculations###################
###functions for calculations
params = dict(voltage_lead=0,voltage=0)
kwant.plotter.bands(model1.leads[0], params=params) #bandstructure of lead
set_pub()
plt.rc('axes', linewidth=2.0)
pyplot.xlabel("K",fontweight='bold')
pyplot.ylabel("Energy",fontweight='bold')
plt.show()
plt.savefig('output\\Ushape_1st_lead.png',bbox_inches='tight',dpi=300)
def plot_conductance(sys, energies, params=params):
# Compute transmission as a function of energy
data = []
for energy in energies:
smatrix = kwant.smatrix(sys, energy, params=params)
data.append(smatrix.transmission(0, 1))
pyplot.figure()
pyplot.plot(energies, data)
pyplot.xlim([-3,3])
pyplot.grid(which='major', color='#DDDDDD', linewidth=1.2)
pyplot.grid(which='minor', color='#EEEEEE', linestyle=':', linewidth=1)
pyplot.minorticks_on()
#pyplot.grid(which='minor')
pyplot.ylim([0,4])
pyplot.xlabel("Energy (eV)",fontweight='bold')
pyplot.ylabel("Conductance $(e^2/h)$",fontweight='bold')
set_pub()
plt.rc('axes', linewidth=2.0)
pyplot.show()
plt.savefig('output\\Ushape_cond.tif',bbox_inches='tight',dpi=300)
return data
#plot_conductance(model1,eng)
################DOS KPM##################################
rho = kwant.kpm.SpectralDensity(model1, params=params)
energies, densities = rho.energies, rho.densities
plt.figure()
plt.plot(energies, densities)
plt.savefig('output\\Ushape_DOS.png',bbox_inches='tight',dpi=300)
#########################################
data=plot_conductance(model1,energies, params=params)
saveoutput('c_shape.dat',(energies,data))
Thanking You