Hi Kwant Users !

I was trying to plot the band structure of the ssh model with linearly
varying chemical potential (\mu*x). But it is showing error that "*Expecting
an arraylike object or a scalar*" while adding this potential term. Can
anyone please tell where I am making mistake  and how to rectify it ?
_____________________________________
Code is attached below :-

import kwant
import numpy as np
import math
##
import matplotlib
#matplotlib.use('Agg')
##

# For plotting
from matplotlib import pyplot as plt

# For matrix support
import tinyarray

I2 = tinyarray.array([[1,0], [0,1]])
Sx = tinyarray.array([[0,1], [1,0]])
Sy = tinyarray.array([[0,-1j], [1j,0]])
Sz = tinyarray.array([[1,0], [0,-1]])

Sp = tinyarray.array([[0,2], [0,0]])
Sm = tinyarray.array([[0,0], [2,0]])

def create_system(length=10):

    t1 = 0.5 ; t2 = 1.0 ;

    def Onsite(site):
        (x, ) = site.pos
        potential = x
        return x

    # system building
    lat = kwant.lattice.square(a=1, norbs=2)
    syst = kwant.Builder()

    # central scattering region
    syst[(lat(x, 0) for x in range(length))] = t1*Sx
    syst[lat.neighbors()] = (t2*Sx - 1j*t2*Sy)/2

    # add leads
    sym = kwant.TranslationalSymmetry((-1, 0))
    lead_left = kwant.Builder(sym)

    lead_left[lat(0, 0)] = t1*Sx + Onsite*I2
    lead_left[lat.neighbors()] = (t2*Sx - 1j*t2*Sy)/2

    syst.attach_lead(lead_left)
    syst.attach_lead(lead_left.reversed())

    return syst


def main():

    # parameters


    # create system
    syst = create_system(length=10).finalized()

    # plot the system and dispersion

    kwant.plot(syst)
    kwant.plotter.bands(syst.leads[0], show=False)
    plt.plot([-np.pi, np.pi], [chemical_potential, chemical_potential],
'k--')
    plt.show()

    lead = syst.leads[0]
    bands = kwant.physics.Bands(lead)
    momenta = np.linspace(-2*np.pi, 2*np.pi, 401)
    energies = [bands(k) for k in momenta]

    plt.plot(momenta, energies,linestyle='--')

    plt.xlim(-2*np.pi, 2*np.pi)
    #pyplot.ylim(-5, 5)
    plt.xlabel("$k$")
    plt.ylabel("Energy")
    #pyplot.axhline(y=0.0, color='k', linestyle='-')
    plt.tight_layout()
    plt.grid()

    plt.show()

    plt.close()



if __name__ == '__main__':
    main()

________________________________________________
Thanks in advance,
*_________________________________*
*Subhadeep Chakraborty*

*_________________________________*
import kwant
import numpy as np
import math
##
import matplotlib
#matplotlib.use('Agg')
##

# For plotting
from matplotlib import pyplot as plt 

# For matrix support
import tinyarray

I2 = tinyarray.array([[1,0], [0,1]])
Sx = tinyarray.array([[0,1], [1,0]])
Sy = tinyarray.array([[0,-1j], [1j,0]])
Sz = tinyarray.array([[1,0], [0,-1]])

Sp = tinyarray.array([[0,2], [0,0]])
Sm = tinyarray.array([[0,0], [2,0]])





def create_system(length=10):

    t1 = 0.5 ; t2 = 1.0 ;
    
    def Onsite(site):
        (x, ) = site.pos
        potential = x
        return x

    # system building
    lat = kwant.lattice.square(a=1, norbs=2)
    syst = kwant.Builder()

    # central scattering region
    syst[(lat(x, 0) for x in range(length))] = t1*Sx
    syst[lat.neighbors()] = (t2*Sx - 1j*t2*Sy)/2
    
    # add leads
    sym = kwant.TranslationalSymmetry((-1, 0))
    lead_left = kwant.Builder(sym)
    
    lead_left[lat(0, 0)] = t1*Sx + Onsite*I2
    lead_left[lat.neighbors()] = (t2*Sx - 1j*t2*Sy)/2
    
    syst.attach_lead(lead_left)
    syst.attach_lead(lead_left.reversed())

    return syst


def main():

    # parameters
    

    # create system
    syst = create_system(length=10).finalized()

    # plot the system and dispersion
   
    kwant.plot(syst)
    kwant.plotter.bands(syst.leads[0], show=False)
    plt.plot([-np.pi, np.pi], [chemical_potential, chemical_potential], 'k--')
    plt.show()
    
    lead = syst.leads[0]
    bands = kwant.physics.Bands(lead)
    momenta = np.linspace(-2*np.pi, 2*np.pi, 401)
    energies = [bands(k) for k in momenta]
    
    plt.plot(momenta, energies,linestyle='--')

    plt.xlim(-2*np.pi, 2*np.pi)
    #pyplot.ylim(-5, 5)
    plt.xlabel("$k$")
    plt.ylabel("Energy")
    #pyplot.axhline(y=0.0, color='k', linestyle='-')
    plt.tight_layout()
    plt.grid()
    
    plt.show()
    
    plt.close()

    

if __name__ == '__main__':
    main()
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    
    

Reply via email to