Dear Subhadeep, I think it is better to do it without continuous hamiltonians. Defining a function for the hopping will be enough. If you still want to do it with the discretization of a continuous hamiltonian, you can proceed this way:
Define a hamiltonian: "k_x*A(x)* k_x". #check docomentation This will induce a hopping equal to A(x+1/2) but at the same time, you will have an onsite potential A(x+1/2)+A(x-1/2). What you have to do in this case is to cancel this latter with a potential V(x)= -A(x+1/2)-A(x-1/2) So the hamiltonian becomes "k_x*A(x)* k_x+V(x)". The function A(x)=x-1/2 (in order to have t=x). The following program summarizes all this. I hope this helps, Adel #################################################################### import kwant import kwant.continuum import scipy.sparse.linalg import scipy.linalg import numpy as np # For plotting import matplotlib as mpl from matplotlib import pyplot as plt L=30 def Line(site): x=site.pos[0] return abs(x)<L def Hopping(x): return x-0.5 hamiltonian= "k_x*A(x)*k_x-A(x+0.5)-A(x-0.5)" template=kwant.continuum.discretize(hamiltonian) print(template) syst=kwant.Builder() syst.fill(template,Line,(0,)) syst=syst.finalized() ham=syst.hamiltonian_submatrix(params=dict(A=Hopping),sparse=True) vals,evecs=scipy.sparse.linalg.eigsh(ham,k=36,which='SM') plt.plot(vals,'-o') On Thu, Jun 9, 2022 at 4:43 PM Subhadeep Chakraborty < sc20rs...@iiserkol.ac.in> wrote: > Hi Kwant Users ! > > I was trying to plot the band structure of the SSH model using > kwant.continuum. I could do it when the hopping terms are constant. Now let > say the hoppings are linearly varying along x direction (t*x) or say I want > to add a chemical potential like (\mu*x). In that case, how should I > introduce this potential in the code ? > > I have attached my code below. It will be a great help if anyone kindly > tells me where I need to modify the code and how to insert this (\mu*x > term) in the code. > > The code is attached herewith. > _______________________________________ > import kwant > import kwant.continuum > import scipy.sparse.linalg > import scipy.linalg > import numpy as np > > # For plotting > import matplotlib as mpl > from matplotlib import pyplot as plt > > > def ssh(): > hamiltonian = "m*sigma_x + alpha * k_x * sigma_y" > > > > > def plot(ax, a=1): > > params = dict(m=.5, alpha=.5) > > h_k = kwant.continuum.lambdify(hamiltonian, locals=params) > k_cont = np.linspace(-1, 1, 201) > e_cont = [scipy.linalg.eigvalsh(h_k(k_x=ki)) for ki in k_cont] > > template = kwant.continuum.discretize(hamiltonian, grid=a) > syst = kwant.wraparound.wraparound(template).finalized() > > def h_k(k_x): > p = dict(k_x=k_x, **params) > return syst.hamiltonian_submatrix(params=p) > > > > > ax.plot(k_cont, e_cont, 'r-') > > ax.plot([], [], 'r-', label='continuum') > > > ax.set_xlim(-1, 1) > ax.set_ylim(-2, 2) > ax.set_title('a={}'.format(a)) > > ax.set_xlabel('Momentum k_x') > ax.set_ylabel('energy E') > ax.grid() > ax.legend() > > _, (ax1, ax2) = plt.subplots(1, 2, sharey=True, figsize=(12, 4)) > > plot(ax1, a=1) > plot(ax2, a=.25) > plt.show() > > > > > def main(): > ssh() > > > if __name__ == '__main__': > main() > _______________________________________________________ > > > > > *_Thanks in advance,* > > > -- Abbout Adel