Thank you Joe for pointing out the mistake! I defined the lead_shape function that return True for sites in the 'lat1'. I have already added the lat1(0, 0, -1) site to the system. When I replace the 'if continuous' section with the following section it will complain. if continuous: def lead_shape(site): (x, y, z) = site.pos return (x == -0.7 and y == 0.0 and z <= -a) t00=0.0 Leadham ="t00*sigma_0*k_x**2+t00*sigma_0*k_y**2-t0*sigma_0*k_z**2+(2*t0+e1)*sigma_0" template = kwant.continuum.discretize(Leadham, grid_spacing=a) dn_lead.fill(template, lead_shape, lat1(0, 0, -1)) syst.attach_lead(dn_lead) I attach the full code at the end of this message. What would be the continuous leads (in the momentum space) equivalent of two discrete leads (vertical 1D chains) attached to my system? Regards Patrik ------------------------------------------------- from mpl_toolkits.mplot3d import Axes3D from scipy.spatial import * from matplotlib import rcParams from numpy import * from numpy.linalg import * import pickle import sys import os import string import heapq import kwant import tinyarray from matplotlib import pyplot chiral=True if chiral: p = pi/5 #phi t = 0.66 #theta a = 0.34 x = 1.4 e1 = 0 e2 = 0.3 t2=0.1 t1=-x*t2 t0 = 2 lam=-0.08 t_so1 = 0.01 #spin-orbit coupling param t_so2 = x*t_so1 #spin-orbit coupling param tl=tr=0.3 N = 30 sigma_0 = tinyarray.array([[1, 0], [0, 1]]) sigma_x = tinyarray.array([[0, 1], [1, 0]]) sigma_y = tinyarray.array([[0, -1j], [1j, 0]]) sigma_z = tinyarray.array([[1, 0], [0, -1]]) no=2 #number of orbitals def sigma_v1(ap): # pauli metrix along the vertical axis value=sigma_z*cos(t)+sin(t)*(sigma_x*sin(ap)-sigma_y*cos(ap)) return value def sigma_v2(ap): # pauli metrix along the vertical axis value=sigma_z*cos(t)-sin(t)*(sigma_x*sin(ap)-sigma_y*cos(ap)) return value def family_color(sites): return 'black' #if site.family == sites def hopping_lw(site1, site2): return 0.08 class Amorphous(kwant.builder.SiteFamily): def __init__(self, coords): self.coords = coords super(Amorphous, self).__init__("amorphous", "",no) def normalize_tag(self, tag): try: tag = int(tag[0]) except: raise KeyError if 0 <= tag < len(coords): return tag else: raise KeyError def pos(self, tag): return self.coords[tag] coords=[(0.0000000000, 0.0000000000, 0.0000000000), (-0.1336881039, 0.4114496766, 0.3400000000), (-0.4836881039, 0.6657395614, 0.6800000000), (-0.9163118961, 0.6657395614, 1.0200000000), (-1.2663118961, 0.4114496766, 1.3600000000), (-1.4000000000, 0.0000000000, 1.7000000000), (-1.2663118961, -0.4114496766, 2.0400000000), (-0.9163118961, -0.6657395614, 2.3800000000), (-0.4836881039, -0.6657395614, 2.7200000000), (-0.1336881039, -0.4114496766, 3.0600000000), (0.0000000000, -0.0000000000, 3.4000000000), (-0.1336881039, 0.4114496766, 3.7400000000), (-0.4836881039, 0.6657395614, 4.0800000000), (-0.9163118961, 0.6657395614, 4.4200000000), (-1.2663118961, 0.4114496766, 4.7600000000), (-1.4000000000, 0.0000000000, 5.1000000000), (-1.2663118961, -0.4114496766, 5.4400000000), (-0.9163118961, -0.6657395614, 5.7800000000), (-0.4836881039, -0.6657395614, 6.1200000000), (-0.1336881039, -0.4114496766, 6.4600000000), (0.0000000000, -0.0000000000, 6.8000000000), (-0.1336881039, 0.4114496766, 7.1400000000), (-0.4836881039, 0.6657395614, 7.4800000000), (-0.9163118961, 0.6657395614, 7.8200000000), (-1.2663118961, 0.4114496766, 8.1600000000), (-1.4000000000, 0.0000000000, 8.5000000000), (-1.2663118961, -0.4114496766, 8.8400000000), (-0.9163118961, -0.6657395614, 9.1800000000), (-0.4836881039, -0.6657395614, 9.5200000000), (-0.1336881039, -0.4114496766, 9.8600000000), (-1.4000000000, 0.0000000000, 0.0000000000), (-1.2663118961, -0.4114496766, 0.3400000000), (-0.9163118961, -0.6657395614, 0.6800000000), (-0.4836881039, -0.6657395614, 1.0200000000), (-0.1336881039, -0.4114496766, 1.3600000000), (0.0000000000, -0.0000000000, 1.7000000000), (-0.1336881039, 0.4114496766, 2.0400000000), (-0.4836881039, 0.6657395614, 2.3800000000), (-0.9163118961, 0.6657395614, 2.7200000000), (-1.2663118961, 0.4114496766, 3.0600000000), (-1.4000000000, 0.0000000000, 3.4000000000), (-1.2663118961, -0.4114496766, 3.7400000000), (-0.9163118961, -0.6657395614, 4.0800000000), (-0.4836881039, -0.6657395614, 4.4200000000), (-0.1336881039, -0.4114496766, 4.7600000000), (0.0000000000, -0.0000000000, 5.1000000000), (-0.1336881039, 0.4114496766, 5.4400000000), (-0.4836881039, 0.6657395614, 5.7800000000), (-0.9163118961, 0.6657395614, 6.1200000000), (-1.2663118961, 0.4114496766, 6.4600000000), (-1.4000000000, 0.0000000000, 6.8000000000), (-1.2663118961, -0.4114496766, 7.1400000000), (-0.9163118961, -0.6657395614, 7.4800000000), (-0.4836881039, -0.6657395614, 7.8200000000), (-0.1336881039, -0.4114496766, 8.1600000000), (0.0000000000, -0.0000000000, 8.5000000000), (-0.1336881039, 0.4114496766, 8.8400000000), (-0.4836881039, 0.6657395614, 9.1800000000), (-0.9163118961, 0.6657395614, 9.5200000000), (-1.2663118961, 0.4114496766, 9.8600000000)] amorphous_lat = Amorphous(coords) syst = kwant.Builder() for i in range(N): syst[amorphous_lat(i)] = e1*sigma_0 syst[amorphous_lat(N+i)] = e2*sigma_0 syst[amorphous_lat(i), amorphous_lat(N+i)] = lam*sigma_0 if i > 0: syst[amorphous_lat(i), amorphous_lat(i-1)] = t1*sigma_0 + 1j*t_so1*(sigma_v1(i*p)+sigma_v1((i-1)*p)) syst[amorphous_lat(N+i),amorphous_lat(N+i-1)] = t2*sigma_0 + 1j*t_so2*(sigma_v2(i*p)+sigma_v2((i-1)*p)) prim_vecs=tinyarray.array([(a,0.,0.),(0.,a,0.),(0.,0.,a)]) offset1=tinyarray.array((-0.7, 0.0, 0.0)) lat1=kwant.lattice.Monatomic(prim_vecs, offset1, norbs=no) syst[lat1(0, 0, -1)] = e1*sigma_0 syst[amorphous_lat(0), lat1(0, 0, -1)] = tl*sigma_0 syst[amorphous_lat(N), lat1(0, 0, -1)] = tl*sigma_0 sym = kwant.TranslationalSymmetry([0, 0, -a]) dn_lead = kwant.Builder(sym, conservation_law=-sigma_z) discrete=False #discrete lead continuous=True #countinuous lead if discrete: sym = kwant.TranslationalSymmetry([0, 0, -a]) dn_lead = kwant.Builder(sym, conservation_law=-sigma_z) dn_lead[lat1(0, 0, -2)] = e1*sigma_0 dn_lead[lat1.neighbors()] = t0*sigma_0 syst.attach_lead(dn_lead) if continuous: def lead_shape(site): (x, y, z) = site.pos return (x == -0.7 and y == 0.0 and z <= -a) t00=0.0 Leadham ="t00*sigma_0*k_x**2+t00*sigma_0*k_y**2-t0*sigma_0*k_z**2+(2*t0+e1)*sigma_0" template = kwant.continuum.discretize(Leadham, grid_spacing=a) dn_lead.fill(template, lead_shape, lat1(0, 0, -1)) syst.attach_lead(dn_lead) sym1 = kwant.TranslationalSymmetry([0, 0, a]) up_lead = kwant.Builder(sym1, conservation_law=-sigma_z) syst[lat1(0, 0, N)] = e1*sigma_0 syst[amorphous_lat(N-1), lat1(0, 0, N)] = tr*sigma_0 syst[amorphous_lat(2*N-1), lat1(0, 0, N)] = tr*sigma_0 up_lead[lat1(0, 0, N+1)] = e1*sigma_0 up_lead[lat1.neighbors()] = t0*sigma_0 syst.attach_lead(up_lead) system=kwant.plot(syst, site_lw=0.1, site_color=family_color, hop_lw=hopping_lw) trans=True if trans: syst = syst.finalized() energies = [] datau = [] for ie in range(-320,520): energy = ie * 0.001 smatrix = kwant.smatrix(syst, energy=energy) energies.append(energy) Gu=smatrix.transmission((1, 0), 0) Gd=smatrix.transmission((1, 1), 0) datau.append(Gu) fig = pyplot.figure() pyplot.plot(energies, datau, 'b--') pyplot.legend(['Gu'], loc='upper left') pyplot.xlim([-0.32,0.52]) pyplot.ylim([-0.03,1.05]) pyplot.show() On 7 August 2017 at 12:27, Joseph Weston <joseph.weston08@gmail.com> wrote:
Dear Patrik,
The line that fails is
dn_lead.fill(template, lat1, lat1(0, 0, -2))
did you read the documentation for the "fill" method of builders? The documentation says that the second argument, called "shape", should be a function that takes a site and returns true or false depending on whether or not the site should be added. Instead of providing such a function, you have just provided the lattice itself.
Happy Kwanting,
Joe On 08/07/2017 11:35 AM, Patrik Arvoy wrote:
Dear Christoph,
Thank you for the reply!
The code works fine with the switch (discrete=True and continuous=False). Now if I change (discrete=False and continuous=True), I want to attach a continuous lead instead of its discrete counterpart to the system, I get the error.
Regards Patrik
Here is the code ----------------------------------- from mpl_toolkits.mplot3d import Axes3D from scipy.spatial import * from matplotlib import rcParams from numpy import * from numpy.linalg import * import pickle import sys import os import string import heapq import kwant import tinyarray from matplotlib import pyplot
chiral=True if chiral: p = pi/5 #phi t = 0.66 #theta a = 0.34 x = 1.4 e1 = 0 e2 = 0.3 t2=0.1 t1=-x*t2 t0 = 2 lam=-0.08 t_so1 = 0.01 #spin-orbit coupling param t_so2 = x*t_so1 #spin-orbit coupling param tl=tr=0.3 N = 30 sigma_0 = tinyarray.array([[1, 0], [0, 1]]) sigma_x = tinyarray.array([[0, 1], [1, 0]]) sigma_y = tinyarray.array([[0, -1j], [1j, 0]]) sigma_z = tinyarray.array([[1, 0], [0, -1]]) no=2 #number of orbitals def sigma_v1(ap): # pauli metrix along the vertical axis value=sigma_z*cos(t)+sin(t)*(sigma_x*sin(ap)-sigma_y*cos(ap)) return value
def sigma_v2(ap): # pauli metrix along the vertical axis value=sigma_z*cos(t)-sin(t)*(sigma_x*sin(ap)-sigma_y*cos(ap)) return value
def family_color(sites): return 'black' #if site.family == sites
def hopping_lw(site1, site2): return 0.08
class Amorphous(kwant.builder.SiteFamily): def __init__(self, coords): self.coords = coords super(Amorphous, self).__init__("amorphous", "",no)
def normalize_tag(self, tag): try: tag = int(tag[0]) except: raise KeyError
if 0 <= tag < len(coords): return tag else: raise KeyError
def pos(self, tag): return self.coords[tag]
coords=[(0.0000000000, 0.0000000000, 0.0000000000), (-0.1336881039, 0.4114496766, 0.3400000000), (-0.4836881039, 0.6657395614, 0.6800000000), (-0.9163118961, 0.6657395614, 1.0200000000), (-1.2663118961, 0.4114496766, 1.3600000000), (-1.4000000000, 0.0000000000, 1.7000000000), (-1.2663118961, -0.4114496766, 2.0400000000), (-0.9163118961, -0.6657395614, 2.3800000000), (-0.4836881039, -0.6657395614, 2.7200000000), (-0.1336881039, -0.4114496766, 3.0600000000), (0.0000000000, -0.0000000000, 3.4000000000), (-0.1336881039, 0.4114496766, 3.7400000000), (-0.4836881039, 0.6657395614, 4.0800000000), (-0.9163118961, 0.6657395614, 4.4200000000), (-1.2663118961, 0.4114496766, 4.7600000000), (-1.4000000000, 0.0000000000, 5.1000000000), (-1.2663118961, -0.4114496766, 5.4400000000), (-0.9163118961, -0.6657395614, 5.7800000000), (-0.4836881039, -0.6657395614, 6.1200000000), (-0.1336881039, -0.4114496766, 6.4600000000), (0.0000000000, -0.0000000000, 6.8000000000), (-0.1336881039, 0.4114496766, 7.1400000000), (-0.4836881039, 0.6657395614, 7.4800000000), (-0.9163118961, 0.6657395614, 7.8200000000), (-1.2663118961, 0.4114496766, 8.1600000000), (-1.4000000000, 0.0000000000, 8.5000000000), (-1.2663118961, -0.4114496766, 8.8400000000), (-0.9163118961, -0.6657395614, 9.1800000000), (-0.4836881039, -0.6657395614, 9.5200000000), (-0.1336881039, -0.4114496766, 9.8600000000), (-1.4000000000, 0.0000000000, 0.0000000000), (-1.2663118961, -0.4114496766, 0.3400000000), (-0.9163118961, -0.6657395614, 0.6800000000), (-0.4836881039, -0.6657395614, 1.0200000000), (-0.1336881039, -0.4114496766, 1.3600000000), (0.0000000000, -0.0000000000, 1.7000000000), (-0.1336881039, 0.4114496766, 2.0400000000), (-0.4836881039, 0.6657395614, 2.3800000000), (-0.9163118961, 0.6657395614, 2.7200000000), (-1.2663118961, 0.4114496766, 3.0600000000), (-1.4000000000, 0.0000000000, 3.4000000000), (-1.2663118961, -0.4114496766, 3.7400000000), (-0.9163118961, -0.6657395614, 4.0800000000), (-0.4836881039, -0.6657395614, 4.4200000000), (-0.1336881039, -0.4114496766, 4.7600000000), (0.0000000000, -0.0000000000, 5.1000000000), (-0.1336881039, 0.4114496766, 5.4400000000), (-0.4836881039, 0.6657395614, 5.7800000000), (-0.9163118961, 0.6657395614, 6.1200000000), (-1.2663118961, 0.4114496766, 6.4600000000), (-1.4000000000, 0.0000000000, 6.8000000000), (-1.2663118961, -0.4114496766, 7.1400000000), (-0.9163118961, -0.6657395614, 7.4800000000), (-0.4836881039, -0.6657395614, 7.8200000000), (-0.1336881039, -0.4114496766, 8.1600000000), (0.0000000000, -0.0000000000, 8.5000000000), (-0.1336881039, 0.4114496766, 8.8400000000), (-0.4836881039, 0.6657395614, 9.1800000000), (-0.9163118961, 0.6657395614, 9.5200000000), (-1.2663118961, 0.4114496766, 9.8600000000)] amorphous_lat = Amorphous(coords)
syst = kwant.Builder()
for i in range(N): syst[amorphous_lat(i)] = e1*sigma_0 syst[amorphous_lat(N+i)] = e2*sigma_0 syst[amorphous_lat(i), amorphous_lat(N+i)] = lam*sigma_0 if i > 0: syst[amorphous_lat(i), amorphous_lat(i-1)] = t1*sigma_0 + 1j*t_so1*(sigma_v1(i*p)+sigma_v1((i-1)*p)) syst[amorphous_lat(N+i),amorphous_lat(N+i-1)] = t2*sigma_0 + 1j*t_so2*(sigma_v2(i*p)+sigma_v2((i-1)*p))
prim_vecs=tinyarray.array([(a,0.,0.),(0.,a,0.),(0.,0.,a)])
offset1=tinyarray.array((-0.7, 0.0, 0.0)) lat1=kwant.lattice.Monatomic(prim_vecs, offset1, norbs=no)
syst[lat1(0, 0, -1)] = e1*sigma_0 syst[amorphous_lat(0), lat1(0, 0, -1)] = tl*sigma_0 syst[amorphous_lat(N), lat1(0, 0, -1)] = tl*sigma_0
sym = kwant.TranslationalSymmetry([0, 0, -a]) dn_lead = kwant.Builder(sym, conservation_law=-sigma_z)
discrete=True #discrete lead continuous=False #countinuous lead
if discrete: sym = kwant.TranslationalSymmetry([0, 0, -a]) dn_lead = kwant.Builder(sym, conservation_law=-sigma_z)
dn_lead[lat1(0, 0, -2)] = e1*sigma_0 dn_lead[lat1.neighbors()] = t0*sigma_0 syst.attach_lead(dn_lead)
if continuous: t00=0.0 Leadham ="t00*sigma_0*k_x**2+t00*sigma_0*k_y**2-t0*sigma_0*k_z* *2+(2*t0+e1)*sigma_0" template = kwant.continuum.discretize(Leadham, grid_spacing=a) dn_lead.fill(template, lat1, lat1(0, 0, -2)) syst.attach_lead(dn_lead)
sym1 = kwant.TranslationalSymmetry([0, 0, a]) up_lead = kwant.Builder(sym1, conservation_law=-sigma_z)
syst[lat1(0, 0, N)] = e1*sigma_0 syst[amorphous_lat(N-1), lat1(0, 0, N)] = tr*sigma_0 syst[amorphous_lat(2*N-1), lat1(0, 0, N)] = tr*sigma_0
up_lead[lat1(0, 0, N+1)] = e1*sigma_0 up_lead[lat1.neighbors()] = t0*sigma_0 syst.attach_lead(up_lead)
system=kwant.plot(syst, site_lw=0.1, site_color=family_color, hop_lw=hopping_lw)
trans=True if trans: syst = syst.finalized() energies = [] datau = []
for ie in range(-320,520): energy = ie * 0.001 smatrix = kwant.smatrix(syst, energy=energy) energies.append(energy) Gu=smatrix.transmission((1, 0), 0) Gd=smatrix.transmission((1, 1), 0) datau.append(Gu)
fig = pyplot.figure() pyplot.plot(energies, datau, 'b--') pyplot.legend(['Gu'], loc='upper left') pyplot.xlim([-0.32,0.52]) pyplot.ylim([-0.03,1.05]) pyplot.show()
On 7 August 2017 at 10:15, Christoph Groth <christoph.groth@cea.fr> wrote:
Patrik, can you please provide a complete script file that demonstrates your problem?