human
I am working on the file "1D.ipynb".
The first task is:
Now let us write a small class implementing 1D semi-infinite leads. The class below is just a simple collection of the analytic formilae for spectrum, groupvelocity and the surface Green's function. Most functions have some meaningfull standard parameters (e.g.: hopping $\gamma=-1$, on-site potential $\varepsilon_0=0$). The functions are written keeping in mind that for a generic scattering problem energy is the important variable and not the wavenumber.
Can you write Python code for it?
assistant
#Here is the Python code you requested.

class lead1D:
    'A class for simple 1D leads'
    def __init__(self,eps0=0,gamma=-1,**kwargs):
        'We assume real hopping \gamma and onsite \epsilon_0 parameters!'
        self.eps0=eps0
        self.gamma=gamma
        return
    
    def Ek(self,k):
        'Spectrum as a function of k'
        return self.eps0+2*self.gamma*cos(k)
    
    def kE(self,E,**kwargs):
        '''
        Spectrum as a function of E.
        If keyword a=True is given than 
        it gives back two k values, 
        one positive and one negative.
        '''
        a = kwargs.get('a',False)
        k=arccos((E-self.eps0)/(2*self.gamma))
        if a:
            return array([-k,k])
        else:
            return k
        
    def vE(self,E=0,**kwargs):
        '''
        Group velocity as a function of E.
        If keyword a=True is given than 
        it gives back two v values, 
        one positive and one negative.
        '''
        a = kwargs.get('a',False)
        k=self.kE(E)
        v= -2*self.gamma*sin(k)
        if a:
            return array([-v,v])
        else:
            return v
    
    
    def sgf(self,E=0):
        '''
        Surgace Green's function of a seminfinite 1D lead.
        '''
        return exp(1.0j *self.kE(E))/self.gamma
    
    def sgfk(self,k=pi/2):
        '''
        Surgace Green's function of a seminfinite 1D lead in terms of k.
        '''
        return exp(1.0j*k)/self.gamma
    
    def vk(self,k=pi/2):
        '''
        Group velocity in terms of k
        '''
        return -2*self.gamma*sin(k)