About kwant.greens_function
Hi devs, I have been studying Kwant, specifically, Green’s functions. I am trying to obtain the electron density from the definition of the correlation function. The code follows below, ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- data3 = [] energies2 = [] Es = np.linspace(0, 30, 100) for ie in Es: E = ie * 0.01 G = kwant.greens_function(fsyst, E) # Funcoes de Green retardada indo da lead0 para lead1 G_r = G.submatrix(1,0) # Funcao de Green avancada G_a = conj((G_r).T) # Self-energy da lead 0 SigmaL_r = lead_0.selfenergy(E) # Retardada SigmaL_a = conj((SigmaL_r).T) # Avancada # Self-energy da lead 1 SigmaR_r = lead_1.selfenergy(E) # Retardada SigmaR_a = conj((SigmaR_r).T) # Avancada # Matriz de Alargamento Gamma_L = 1j*(SigmaL_r-SigmaL_a) # referente a lead_0 Gamma_R = 1j*(SigmaR_r-SigmaR_a) # referente a lead_1 # Funcao de distribuicao de Fermi-Dirac em T=0 f_L = np.heaviside(mu_L - E, 1) f_R = np.heaviside(mu_R - E, 1) # Funcao inscattering Sigma_in = (f_L)*(Gamma_L) + (f_R)*(Gamma_R) # Funcao de correlacao G_n = np.dot(np.dot(G_r, Sigma_in), G_a) data3.append(imag(np.trace(G_n))) energies2.append(E) plt.figure() plt.plot(energies2, data3) plt.xlabel("energy [eV]") plt.ylabel("electron density") plt.show() ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- From this definition, is it possible to obtain this electron density as a function of the sites position? How can I do that? Best, Gabriel
Dear Gabriel, These matrix elements do not give you access to the density of states inside the system. All what you might have access to is the Transmission via the Fisher-Lee formula or the density of states at the interface. I hope this helps, Adel On Mon, Oct 2, 2023 at 8:58 PM Gabriel Garcia <gqgarcia99@gmail.com> wrote:
Hi devs,
I have been studying Kwant, specifically, Green’s functions. I am trying to obtain the electron density from the definition of the correlation function. The code follows below,
------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- data3 = [] energies2 = []
Es = np.linspace(0, 30, 100)
for ie in Es: E = ie * 0.01 G = kwant.greens_function(fsyst, E)
# Funcoes de Green retardada indo da lead0 para lead1 G_r = G.submatrix(1,0)
# Funcao de Green avancada G_a = conj((G_r).T)
# Self-energy da lead 0 SigmaL_r = lead_0.selfenergy(E) # Retardada SigmaL_a = conj((SigmaL_r).T) # Avancada
# Self-energy da lead 1 SigmaR_r = lead_1.selfenergy(E) # Retardada SigmaR_a = conj((SigmaR_r).T) # Avancada
# Matriz de Alargamento Gamma_L = 1j*(SigmaL_r-SigmaL_a) # referente a lead_0 Gamma_R = 1j*(SigmaR_r-SigmaR_a) # referente a lead_1
# Funcao de distribuicao de Fermi-Dirac em T=0 f_L = np.heaviside(mu_L - E, 1) f_R = np.heaviside(mu_R - E, 1)
# Funcao inscattering Sigma_in = (f_L)*(Gamma_L) + (f_R)*(Gamma_R)
# Funcao de correlacao G_n = np.dot(np.dot(G_r, Sigma_in), G_a)
data3.append(imag(np.trace(G_n))) energies2.append(E)
plt.figure() plt.plot(energies2, data3) plt.xlabel("energy [eV]") plt.ylabel("electron density") plt.show()
-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------
From this definition, is it possible to obtain this electron density as a function of the sites position? How can I do that?
Best, Gabriel
-- Abbout Adel
Hi Adel, Thank you again for responding to me! I tried this matrix method because I had calculated the transmission function and it matched what was calculated by smatrix.transmission. So I thought it was possible to use it this way. I tried to escape from the method of virtual leads, but it is not possible. Best, Gabriel
Hi devs, * I am trying to get the Green functions between two neighboring sites, through the method of virtual leads. However, the following error is occurring: ```python 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> * Where 'syst' is a diatomic network with two sublattices attached with two leads. How to correctly use the tags for the sites of the two sublattices?
Dear Gabriel, Could you provide the part of the code that reproduces this error? Adel On Tue, Oct 17, 2023 at 2:49 AM Gabriel Garcia <gqgarcia99@gmail.com> wrote:
Hi devs,
* I am trying to get the Green functions between two neighboring sites, through the method of virtual leads. However, the following error is occurring:
```python 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>
* Where 'syst' is a diatomic network with two sublattices attached with two leads. How to correctly use the tags for the sites of the two sublattices?
-- Abbout Adel
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>
participants (2)
-
Abbout Adel -
Gabriel Garcia