Dear everyone:
      we know that enegy gap in Landau levels is hw, then we can know the 
magnitude of magnatic field by claculating the gap between landau levels, in 
this code, the magnitude of magnetic field I set is way different by 
calculating the energy gap in Landau levels in this code, Ihave no idea what 
went wrong, so I'll be thankful if you can konw what is wrong in this code.

Thank you 

Following is my code—-————————————————-
### Import modules ###

import kwant
import numpy as np
from math import pi
from matplotlib import pyplot as plt
import csv
import scipy.sparse.linalg as sla

a = 1                                                                 
  # Lattice constant, in nm
h = 4.14e-15                                                   
         # Plank's constnt in unit of eV*s
hbar = 6.58e-16                                                       
  # In unit of eV*s
m = 9.11e-31                                                        
    # Mass of electron in kg
q = 1.6e-19                                                          
   # Charge of an electron in coulomb
t = hbar*hbar/(2*m*a*a)                                              
   # t = hbar^2/(2m(a^2))
B = 3                                                                 
  # Magnitude of external magnetic field, in unit of Tesla
phi0 = 4.14e-15                                                       
  # Magnetic quantum 
def setup_system(W=100, L=100):

    ### Define a function about hopping ###
    def hopping(hop):                                                   
        
        x1, y1 = hop[0].pos                                           
  # Get the position imformation of site_1
        x2, y2 = hop[1].pos                                        
     # Get the position imformation of site_2
        delta_x = (x2 - x1) * 1e-9                               
       # Differance of x coordinate in nanometer
        y_bar = (y1 + y2) / 2 * 1e-9                           
         # Averge of y coordinate in nanometer
        
        return delta_x, y_bar                                           
    
    ### Define the shape of the system ###

    def rectangle(pos):                                                 
        x, y = pos
        return x > -W and x < W and y > -L and y < L
    
    ### Define the shape of the lead ###
    
    def lead_shape(pos):                                                
        x, y = pos
        return (-L < y < L)


    ### Set up the system ###
    
    sys = kwant.Builder()                                          
     # Builde up the system 
    lat = kwant.lattice.square(a, norbs = 1)                            # Set 
up the lattice in shape of square
    sys[lat.shape(rectangle, (0, 0))] = 4 * t                           # 
Define the on-site energy
    
    
    for hopx in kwant.builder.HoppingKind((1, 0), lat)(sys):            # 
Define the hopping in x-direction
        
        delta_x, y_bar = hopping(hopx)  
        phase = 2* pi /phi0 *B *delta_x *y_bar                          # Phase 
differnce due to magnetic field
        sys[hopx] = -t * np.exp( phase*1j)

    for hopy in kwant.builder.HoppingKind((0, 1), lat)(sys):            # 
Define the hopping in y-direction
            
        sys[hopy] = -t 

    ### Set up the left lead ###

    lead0 = kwant.Builder(kwant.TranslationalSymmetry((-1, 0)))         # The 
current goes from the left lead
    lead0[lat.shape(lead_shape, (0, 0))] = 4 * t                        # 
Define the on-site energy
    
    for hopx in kwant.builder.HoppingKind((1, 0), lat)(lead0):          
# Define the hopping in x-direction

        delta_x, y_bar = hopping(hopx)
        phase = 2* pi /phi0 *B *delta_x *y_bar                          # Phase 
differnce due to magnetic field
        lead0[hopx] = -t * np.exp( phase*1j)

    for hopy in kwant.builder.HoppingKind((0, 1), lat)(lead0):          # 
Define the hopping in y-direction
            
        lead0[hopy] = -t 

    ### Set up the right lead ###

    lead1 = kwant.Builder(kwant.TranslationalSymmetry((1, 0)))          # The 
current goes from the left lead
    lead1[lat.shape(lead_shape, (0, 0))] = 4 * t                        # 
Define the on-site energy
    
    for hopx in kwant.builder.HoppingKind((1, 0), lat)(lead1):          # 
Define the hopping in x-direction
        
        delta_x, y_bar = hopping(hopx)
        phase = 2* pi /phi0 *B *delta_x *y_bar                          # Phase 
differnce due to magnetic field
        lead1[hopx] = -t * np.exp( phase*1j)

    for hopy in kwant.builder.HoppingKind((0, 1), lat)(lead1):          # 
Define the hopping in y-direction
            
        lead1[hopy] = -t 
    
    ### Attach the left lead and the right lead ###

    sys.attach_lead(lead0)
    sys.attach_lead(lead1)

    ### Finalize the system ###

    sys = sys.finalized()

    ### Finally, return the system ###
    
    return sys

sys = setup_system()
### Compute, plot and store the bandstructure ###

def plot_bandstructure(flead, momenta):
    bands = kwant.physics.Bands(flead)
    energies = [bands(k)[0: 10] for k in momenta]
    bandenergy = []
    
    '''np.savetxt("Momentatest_l.csv", momenta, delimiter = ",")
    for i in range(1000):
        bandenergy.append(energies[i])
    np.savetxt("Band_energytest1_l.csv", bandenergy, delimiter = ",")'''    
            
    plt.figure(figsize=(6, 8))
    plt.plot(momenta, energies,  color='k')
    plt.xlabel("momentum [a^-1]")
    plt.ylabel("energy [eV]")
    plt.ylim(0, 0.03)
    plt.xlim(-1, 1)
    plt.show()
    #kwant.plotter.bands(sys.leads[0])
    
momenta = np.linspace(-1, 1, 1000)
plot_bandstructure(sys.leads[0], momenta)
plot_bandstructure(sys.leads[1], momenta)

Reply via email to