Hi Adel,

Yes, I can. Below I am sending the complete code with the error:
---------------------------------------------------------------------------------------------------------------------------------------------------
from matplotlib import pyplot as plt
from matplotlib import backends
import numpy as np
from numpy import matrix,round,sqrt,conj,exp,imag,real
import cmath
import kwant

# Parametro de hopping medido em eV:
gamma_L = 0.14
gamma_C = 0.12
gamma_R = 0.08

# Energia dos sitios de impurezas:
E = 0

# Numero de repeticoes da celula primitiva:
L = 20 # Tag: (L-1)(2) + 1

# Potenciais quimicos medidos em eV:
mu_L = 0.5
mu_R = - 0.8

par = dict(gamma_L=gamma_L, gamma_C=gamma_C, gamma_R=gamma_R, E=E, mu_L=mu_L, 
mu_R=mu_R)

# Vamos definir o lattice de uma rede diatomica em 1D:
def make_system(L, gamma_L, gamma_C, gamma_R, E):
    
    lat = kwant.lattice.general([(2,0),(0,1)],[(0,0),(1,0)], norbs=1)
    a, b = lat.sublattices
    syst = kwant.Builder()
    
    # Regiao de Espalhamento
    for i in range(L):
        syst[a(i, 0)] = E
        syst[b(i, 0)] = E
    
    syst[kwant.builder.HoppingKind((0, 0), a, b)] = -gamma_C
    syst[kwant.builder.HoppingKind((1, 0), a, b)] = -gamma_C
    
    # Adicionando 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)] = -gamma_L

    syst[lat_lead1(2 * L,0)] = 0
    syst[lat_lead1(2 * L,0),b(L - 1,0)] = -gamma_R

    lead1 = kwant.Builder(sym_lead1)

    lead1[lat_lead1(0,0)] = 0
    lead1[lat_lead1.neighbors()] = -1

    syst.attach_lead(lead1)
    syst.attach_lead(lead1.reversed())
    
    return syst, lat

syst, lat = make_system(L, gamma_L, gamma_C, gamma_R, E)

def mount_vlead(syst, vlead_interface, norb):
    dim = norb*len(vlead_interface)
    print(dim)
    zero_array = np.zeros((dim, dim), dtype=float)
    def selfenergy_func(energy, args=()):
        return zero_array

    vlead = kwant.builder.SelfEnergyLead(selfenergy_func, vlead_interface,())
    syst.leads.append(vlead)

lead2 = mount_vlead(syst,[lat.sublattices[0](2, 0)], 1)
lead3 = mount_vlead(syst,[lat.sublattices[1](3, 0)], 1)

fsyst = syst.finalized()
---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~\anaconda3\lib\site-packages\kwant\builder.py in __init__(self, builder)
   2060             try:
-> 2061                 interface = [id_by_site[isite] for isite in 
lead.interface]
   2062             except KeyError as e:

~\anaconda3\lib\site-packages\kwant\builder.py in <listcomp>(.0)
   2060             try:
-> 2061                 interface = [id_by_site[isite] for isite in 
lead.interface]
   2062             except KeyError as e:

KeyError: Site(kwant.lattice.Monatomic([[2.0, 0.0], [0.0, 1.0]], [1.0, 0.0], 
'1', 1), array([20, 0]))

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
<ipython-input-15-99c1026e5465> in <module>
     12 lead3 = mount_vlead(syst,[lat.sublattices[1](3, 0)], 1)
     13 
---> 14 fsyst = syst.finalized()

~\anaconda3\lib\site-packages\kwant\builder.py in finalized(self)
   1808         """
   1809         if self.symmetry.num_directions == 0:
-> 1810             return FiniteSystem(self)
   1811         elif self.symmetry.num_directions == 1:
   1812             return InfiniteSystem(self)

~\anaconda3\lib\site-packages\kwant\builder.py in __init__(self, builder)
   2063                 msg = ("Lead {0} is attached to a site that does not "
   2064                        "belong to the scattering region:\n {1}")
-> 2065                 raise ValueError(msg.format(lead_nr, e.args[0]))
   2066 
   2067             lead_interfaces.append(np.array(interface))

ValueError: Lead 3 is attached to a site that does not belong to the scattering 
region:
 <Site [20 0] of 1>

Reply via email to