Scattering region and lead with different kind of lattice
Hi devs, I am learning kwant alone, but i have doubts. I am trying to construct a system with a diatomic chain as scattering region and the leads as a monoatomic chain. But i am doing something wrong. Someone else can help me? Bellow i will show the code: ##################################################################################################################### from matplotlib import pyplot as plt from matplotlib import backends import kwant # Defining the parameters L = 5 # range of scattering region C = 2 # primitive vector # Definindo o parametro de Hopping t = 5 # hopping parameter lat = kwant.lattice.general([(C,0),(0,1)],[(0,0),(1,0)], norbs=1) a, b = lat.sublattices syst = kwant.Builder() # Scattering region for i in range(L): syst[a(i, 0)] = 0 syst[b(i, 0)] = 0 syst[kwant.builder.HoppingKind((0, 0), a, b)] = -t syst[kwant.builder.HoppingKind((1, 0), b, a)] = -t kwant.plot(syst) plt.show() # leaft lead (lead 1) lat_lead1 = kwant.lattice.chain(C, norbs=1) sym_lead1 = kwant.TranslationalSymmetry((-C, 0)) lead1 = kwant.Builder(sym_lead1) lead1[lat_lead(0,0)] = 4*t lead1[lat_lead1.neighbors()] = -t syst[(lat_lead1(-C, 0), a(0, 0))] = -t syst.attach_lead(lead1) kwant.plot(syst) --------------------------------------------------------------------------- ValueError Traceback (most recent call last) ~\anaconda3\lib\site-packages\kwant\builder.py in __new__(cls, family, tag, _i_know_what_i_do) 75 try: ---> 76 tag = family.normalize_tag(tag) 77 except (TypeError, ValueError) as e: ~\anaconda3\lib\site-packages\kwant\lattice.py in normalize_tag(self, tag) 475 if len(tag) != self.lattice_dim: --> 476 raise ValueError("Dimensionality mismatch.") 477 return tag ValueError: Dimensionality mismatch. During handling of the above exception, another exception occurred: ValueError Traceback (most recent call last) <ipython-input-46-3d36b05d2870> in <module> 8 lead1[lat_lead1.neighbors()] = -t 9 ---> 10 syst[(lat_lead1(-C, 0), a(0, 0))] = -t 11 12 syst.attach_lead(lead1) ~\anaconda3\lib\site-packages\kwant\builder.py in __call__(self, *tag) 195 raise ValueError('Use site_family(1, 2) instead of ' 196 'site_family((1, 2))!') --> 197 return Site(self, tag) 198 199 ~\anaconda3\lib\site-packages\kwant\builder.py in __new__(cls, family, tag, _i_know_what_i_do) 77 except (TypeError, ValueError) as e: 78 msg = 'Tag {0} is not allowed for site family {1}: {2}' ---> 79 raise type(e)(msg.format(repr(tag), repr(family), e.args[0])) 80 return tuple.__new__(cls, (family, tag)) 81 ValueError: Tag (-2, 0) is not allowed for site family kwant.lattice.Monatomic([[2.0]], [0.0], '', 1): Dimensionality mismatch. ############################################################################################# Thanks! Gabriel Garcia
Dear Gabriel, You have a "Dimensionality mismatch": Use the same dimension for the two lattices. If you are still using two different lattices, then go and check the FAQ [1] where you have a nice example about combining graphene with a square lattice. I hope this helps, Adel [1] https://kwant-project.org/doc/1/tutorial/faq On Tue, Jun 6, 2023 at 5:55 PM Gabriel Garcia <gqgarcia99@gmail.com> wrote:
Hi devs,
I am learning kwant alone, but i have doubts. I am trying to construct a system with a diatomic chain as scattering region and the leads as a monoatomic chain. But i am doing something wrong. Someone else can help me? Bellow i will show the code:
##################################################################################################################### from matplotlib import pyplot as plt from matplotlib import backends import kwant
# Defining the parameters L = 5 # range of scattering region C = 2 # primitive vector # Definindo o parametro de Hopping
t = 5 # hopping parameter
lat = kwant.lattice.general([(C,0),(0,1)],[(0,0),(1,0)], norbs=1) a, b = lat.sublattices
syst = kwant.Builder()
# Scattering region for i in range(L): syst[a(i, 0)] = 0 syst[b(i, 0)] = 0
syst[kwant.builder.HoppingKind((0, 0), a, b)] = -t syst[kwant.builder.HoppingKind((1, 0), b, a)] = -t
kwant.plot(syst) plt.show()
# leaft lead (lead 1) lat_lead1 = kwant.lattice.chain(C, norbs=1) sym_lead1 = kwant.TranslationalSymmetry((-C, 0))
lead1 = kwant.Builder(sym_lead1)
lead1[lat_lead(0,0)] = 4*t lead1[lat_lead1.neighbors()] = -t
syst[(lat_lead1(-C, 0), a(0, 0))] = -t
syst.attach_lead(lead1)
kwant.plot(syst)
--------------------------------------------------------------------------- ValueError Traceback (most recent call last) ~\anaconda3\lib\site-packages\kwant\builder.py in __new__(cls, family, tag, _i_know_what_i_do) 75 try: ---> 76 tag = family.normalize_tag(tag) 77 except (TypeError, ValueError) as e:
~\anaconda3\lib\site-packages\kwant\lattice.py in normalize_tag(self, tag) 475 if len(tag) != self.lattice_dim: --> 476 raise ValueError("Dimensionality mismatch.") 477 return tag
ValueError: Dimensionality mismatch.
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last) <ipython-input-46-3d36b05d2870> in <module> 8 lead1[lat_lead1.neighbors()] = -t 9 ---> 10 syst[(lat_lead1(-C, 0), a(0, 0))] = -t 11 12 syst.attach_lead(lead1)
~\anaconda3\lib\site-packages\kwant\builder.py in __call__(self, *tag) 195 raise ValueError('Use site_family(1, 2) instead of ' 196 'site_family((1, 2))!') --> 197 return Site(self, tag) 198 199
~\anaconda3\lib\site-packages\kwant\builder.py in __new__(cls, family, tag, _i_know_what_i_do) 77 except (TypeError, ValueError) as e: 78 msg = 'Tag {0} is not allowed for site family {1}: {2}' ---> 79 raise type(e)(msg.format(repr(tag), repr(family), e.args[0])) 80 return tuple.__new__(cls, (family, tag)) 81
ValueError: Tag (-2, 0) is not allowed for site family kwant.lattice.Monatomic([[2.0]], [0.0], '', 1): Dimensionality mismatch.
############################################################################################# Thanks! Gabriel Garcia
-- Abbout Adel
Dear Adel, Thanks for answering me. I saw the FAQ and I try to reproduce for my case, but unfortunately didn't work. I changed the lead command: # Lead a direita (lead 1) lat_lead1 = kwant.lattice.square(C) sym_lead1 = kwant.TranslationalSymmetry((-C, 0)) lead1 = kwant.Builder(sym_lead1) lead1[(lat_lead1(0, 0))] = 0 lead1[lat_lead1(0,0), lat_lead1(1,0)] = -t syst[(a(0,0), lat_lead1(-1,0))] = -1 syst.attach_lead(lead1) kwant.plot(syst) plt.show() --------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-8-df1e018f6b56> in <module> 8 lead1[lat_lead1(0,0), lat_lead1(1,0)] = -t 9 ---> 10 syst[(a(0,0), lat_lead1(-1,0))] = -1 11 12 syst.attach_lead(lead1) ~\anaconda3\lib\site-packages\kwant\builder.py in __setitem__(self, key, value) 1160 func = (self._set_site if isinstance(sh, Site) 1161 else self._set_hopping) -> 1162 func(sh, value) 1163 1164 def _del_site(self, site): ~\anaconda3\lib\site-packages\kwant\builder.py in _set_hopping(self, hopping, value) 1136 # of identical sites. 1137 a2 = a = self.H[a][0] -> 1138 b2 = b = self.H[b][0] 1139 else: 1140 b2, a2 = sym.to_fd(b, a) KeyError: Site(kwant.lattice.Monatomic([[2.0, 0.0], [0.0, 2.0]], [0.0, 0.0], '', None), array([-1, 0])) If anyone can help me, i appreciate. Thaks. Gabriel Garcia
Dear Gabriel, Try this: from matplotlib import pyplot as plt from matplotlib import backends import kwant t = 1 # hopping parameter L=5 lat = kwant.lattice.general([(1,0),(0,1)],[(0,0),(.5,0)], norbs=1) a, b = lat.sublattices syst = kwant.Builder() # Scattering region for i in range(L): syst[a(i, 0)] = 0 syst[b(i, 0)] = 0 syst[kwant.builder.HoppingKind((0, 0), a, b)] = -t syst[kwant.builder.HoppingKind((1, 0), a, b)] = -t #syst[lat.neighbors()]=-t kwant.plot(syst) plt.show() # leaft lead (lead 1) lat_lead1 = kwant.lattice.general([(1,0),(0,1)],[(0,0)], norbs=1).sublattices[0] sym_lead1 = kwant.TranslationalSymmetry((-1, 0)) syst[lat_lead1(-1,0)] = 0 syst[lat_lead1(-1,0),lat_lead1(0,0)] = -t syst[lat_lead1(5,0)] = 0 syst[lat_lead1(5,0),b(4,0)] = -t lead1 = kwant.Builder(sym_lead1) lead1[lat_lead1(0,0)] = 0 lead1[lat_lead1.neighbors()] = -t syst.attach_lead(lead1) syst.attach_lead(lead1.reversed()) kwant.plot(syst) # In[77]: import numpy as np sysf=syst.finalized() # In[78]: Trans=[] energies=np.linspace(-1.99,1.99,100) for energy in energies: SM=kwant.smatrix(sysf,energy) T=SM.transmission(0,1) Trans.append(T) # In[79]: from matplotlib import pyplot pyplot.plot(energies,Trans) pyplot.show() Regards, On Wed, Jun 7, 2023 at 10:41 PM Gabriel Garcia <gqgarcia99@gmail.com> wrote:
Dear Adel,
Thanks for answering me. I saw the FAQ and I try to reproduce for my case, but unfortunately didn't work. I changed the lead command:
# Lead a direita (lead 1) lat_lead1 = kwant.lattice.square(C) sym_lead1 = kwant.TranslationalSymmetry((-C, 0))
lead1 = kwant.Builder(sym_lead1)
lead1[(lat_lead1(0, 0))] = 0 lead1[lat_lead1(0,0), lat_lead1(1,0)] = -t
syst[(a(0,0), lat_lead1(-1,0))] = -1
syst.attach_lead(lead1)
kwant.plot(syst) plt.show()
--------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-8-df1e018f6b56> in <module> 8 lead1[lat_lead1(0,0), lat_lead1(1,0)] = -t 9 ---> 10 syst[(a(0,0), lat_lead1(-1,0))] = -1 11 12 syst.attach_lead(lead1)
~\anaconda3\lib\site-packages\kwant\builder.py in __setitem__(self, key, value) 1160 func = (self._set_site if isinstance(sh, Site) 1161 else self._set_hopping) -> 1162 func(sh, value) 1163 1164 def _del_site(self, site):
~\anaconda3\lib\site-packages\kwant\builder.py in _set_hopping(self, hopping, value) 1136 # of identical sites. 1137 a2 = a = self.H[a][0] -> 1138 b2 = b = self.H[b][0] 1139 else: 1140 b2, a2 = sym.to_fd(b, a)
KeyError: Site(kwant.lattice.Monatomic([[2.0, 0.0], [0.0, 2.0]], [0.0, 0.0], '', None), array([-1, 0]))
If anyone can help me, i appreciate. Thaks.
Gabriel Garcia
-- Abbout Adel
Hi Adel and others devs, I'm trying to replicate your example above with float lattice parameter, but i couldn't do it. Can someone explain to me how to work the TAG to define the hopping between sites? best, Gabriel Garcia
Dear Gabriel, Try to see the documentation and the FAQ. Usually, you can find your request faster. *tag* : a hashable python object The unique identifier of the site within the site family, typically a *vector of integers*. I hope this helps, Adel On Mon, Jul 3, 2023 at 9:19 PM Gabriel Garcia <gqgarcia99@gmail.com> wrote:
Hi Adel and others devs,
I'm trying to replicate your example above with float lattice parameter, but i couldn't do it. Can someone explain to me how to work the TAG to define the hopping between sites?
best, Gabriel Garcia
-- Abbout Adel
Hi Adel, Thanks for answering me. I already read the FAQ, but unfortunately it's not working for me. I tried to replicate your example above with different lattice parameters, where the primitive vector is (2,0) and the atoms are located at (0,0) and (1,0). So that, from matplotlib import pyplot as plt from matplotlib import backends import kwant t = 10 # em eV (hopping parameter) L = 5 lat = kwant.lattice.general([(2,0),(0,1)],[(0,0),(1,0)], norbs=1) a, b = lat.sublattices syst = kwant.Builder() # Scattering region for i in range(L): syst[a(i, 0)] = 0 syst[b(i, 0)] = 0 syst[kwant.builder.HoppingKind((0, 0), a, b)] = -t syst[kwant.builder.HoppingKind((1, 0), a, b)] = -t kwant.plot(syst) plt.show() # Anexando as leads lat_lead1 = kwant.lattice.general([(1,0),(0,1)],[(0,0)], norbs=1).sublattices[0] sym_lead1 = kwant.TranslationalSymmetry((-1, 0)) syst[lat_lead1(-1,0)] = 0 syst[lat_lead1(-1,0),a(0,0)] = -t syst[lat_lead1(10,0)] = 0 syst[lat_lead1(10,0),b(9,0)] = -t lead1 = kwant.Builder(sym_lead1) lead1[lat_lead1(0,0)] = 0 lead1[lat_lead1.neighbors()] = -t syst.attach_lead(lead1) syst.attach_lead(lead1.reversed()) kwant.plot(syst) plt.show() --------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-17-d6f28d521172> in <module> 8 9 syst[lat_lead1(10,0)] = 0 ---> 10 syst[lat_lead1(10,0),b(9,0)] = -t 11 12 lead1 = kwant.Builder(sym_lead1) ~\anaconda3\lib\site-packages\kwant\builder.py in __setitem__(self, key, value) 1160 func = (self._set_site if isinstance(sh, Site) 1161 else self._set_hopping) -> 1162 func(sh, value) 1163 1164 def _del_site(self, site): ~\anaconda3\lib\site-packages\kwant\builder.py in _set_hopping(self, hopping, value) 1136 # of identical sites. 1137 a2 = a = self.H[a][0] -> 1138 b2 = b = self.H[b][0] 1139 else: 1140 b2, a2 = sym.to_fd(b, a) KeyError: Site(kwant.lattice.Monatomic([[2.0, 0.0], [0.0, 1.0]], [1.0, 0.0], '1', 1), array([9, 0])) --------------------------------------------------------------------------------------------------------------------------------------- Every time I change the lattice parameters, the code gives me an error. The erro is exactly in hopping with leads. Can someone can explain to me what i did wrong?
Dear Gabriel, I went back to your original message. You want a system with a di-atomic chain and leads with a monoatomic lattice. You can achieve that with one unique monoatomic lattice for the whole system and put a staggered potential in the middle. This will make your life easier. Check the code below I hope this helps, Adel ############################################## lat=kwant.lattice.square() sys=kwant.Builder() L=10 t=1 def pot(site,v1,v2): x,_=site.pos if x%2==0: return v1 else: return v2 sys[(lat(x,0) for x in range(L))]=pot sys[lat.neighbors()]=-t sym=kwant.TranslationalSymmetry((-1,0)) lead=kwant.Builder(sym) lead[lat(0,0)]=0 lead[lat.neighbors()]=-t sys.attach_lead(lead) sys.attach_lead(lead.reversed()) kwant.plot(sys) sysf=sys.finalized() sm=kwant.smatrix(sysf,energy=-1.8,params=dict(v1=0.1,v2=-0.1)) T=sm.transmission(0,1) On Mon, Jul 10, 2023 at 7:25 PM Gabriel Garcia <gqgarcia99@gmail.com> wrote:
Hi Adel,
Thanks for answering me. I already read the FAQ, but unfortunately it's not working for me. I tried to replicate your example above with different lattice parameters, where the primitive vector is (2,0) and the atoms are located at (0,0) and (1,0). So that,
from matplotlib import pyplot as plt from matplotlib import backends import kwant
t = 10 # em eV (hopping parameter) L = 5
lat = kwant.lattice.general([(2,0),(0,1)],[(0,0),(1,0)], norbs=1) a, b = lat.sublattices
syst = kwant.Builder()
# Scattering region for i in range(L): syst[a(i, 0)] = 0 syst[b(i, 0)] = 0
syst[kwant.builder.HoppingKind((0, 0), a, b)] = -t syst[kwant.builder.HoppingKind((1, 0), a, b)] = -t
kwant.plot(syst) plt.show()
# Anexando as leads
lat_lead1 = kwant.lattice.general([(1,0),(0,1)],[(0,0)], norbs=1).sublattices[0] sym_lead1 = kwant.TranslationalSymmetry((-1, 0))
syst[lat_lead1(-1,0)] = 0 syst[lat_lead1(-1,0),a(0,0)] = -t
syst[lat_lead1(10,0)] = 0 syst[lat_lead1(10,0),b(9,0)] = -t
lead1 = kwant.Builder(sym_lead1)
lead1[lat_lead1(0,0)] = 0 lead1[lat_lead1.neighbors()] = -t
syst.attach_lead(lead1) syst.attach_lead(lead1.reversed()) kwant.plot(syst) plt.show() --------------------------------------------------------------------------- KeyError Traceback (most recent call last) <ipython-input-17-d6f28d521172> in <module> 8 9 syst[lat_lead1(10,0)] = 0 ---> 10 syst[lat_lead1(10,0),b(9,0)] = -t 11 12 lead1 = kwant.Builder(sym_lead1)
~\anaconda3\lib\site-packages\kwant\builder.py in __setitem__(self, key, value) 1160 func = (self._set_site if isinstance(sh, Site) 1161 else self._set_hopping) -> 1162 func(sh, value) 1163 1164 def _del_site(self, site):
~\anaconda3\lib\site-packages\kwant\builder.py in _set_hopping(self, hopping, value) 1136 # of identical sites. 1137 a2 = a = self.H[a][0] -> 1138 b2 = b = self.H[b][0] 1139 else: 1140 b2, a2 = sym.to_fd(b, a)
KeyError: Site(kwant.lattice.Monatomic([[2.0, 0.0], [0.0, 1.0]], [1.0, 0.0], '1', 1), array([9, 0]))
---------------------------------------------------------------------------------------------------------------------------------------
Every time I change the lattice parameters, the code gives me an error. The erro is exactly in hopping with leads. Can someone can explain to me what i did wrong?
-- Abbout Adel
participants (2)
-
Abbout Adel
-
Gabriel Garcia