<jupyter_start><jupyter_text>Exercises for EBT617E - 2D Band structure See Homework \2<jupyter_code>import numpy as np

%matplotlib inline
import matplotlib.pyplot as plt
# define 2d BZ for a square lattice

Nk = 128
kk, dk = np.linspace(-np.pi, np.pi, Nk, endpoint=True, retstep=True)
# reciprocal lattice 

nmax = 2

dimx = 2*nmax+1

nn = np.arange(-nmax,nmax+1)

mGx, mGy = np.meshgrid(nn,nn)
mGx, mGy
# let's enumerate states in the reciprocal state for each k: k + G

states = mGx+nmax + (mGy+nmax)*dimx
states
# k in [-pi,pi]
def ϵkG(kx,ky,Gx,Gy):
    return (kx+Gx)**2+(ky+Gy)**2
ϵkG(0,0,mGx,mGy)
ϵkG(0,0,mGx,mGy).flatten()
# Let's do V(x,y) = Vm*( cos(2πx/a)/2 + cos(2πy/a) )

Vmax = 1

dF = 1
FCoeffs = np.zeros([2*dF+1,2*dF+1])

FCoeffs[-1+dF, 0+dF] = Vmax/2 
FCoeffs[ 0+dF, 0+dF] = 0
FCoeffs[ 1+dF, 0+dF] = Vmax/2

FCoeffs[ 0+dF,-1+dF] = Vmax 
FCoeffs[ 0+dF, 0+dF] = 0
FCoeffs[ 0+dF, 1+dF] = Vmax
FCoeffs
for iFx, FCoeffx in enumerate(FCoeffs):
    for iFy, FCoeff in enumerate(FCoeffx):
        print(iFx,iFy,FCoeff)
# let's plot this potential in real space

Nx = 101
xmax = 1.5
xx = np.linspace(-xmax,xmax,Nx,endpoint=True)
mx, my = np.meshgrid(xx,xx)

nF = np.arange(-dF,dF+1)

mGFx, mGFy = np.meshgrid(nF,nF)

expkR= np.exp( 1j * 2*np.pi * ( np.outer(mx,mGFx) + np.outer(my,mGFy) ) )
Vr = expkR@FCoeffs.flatten()
plt.imshow(Vr.real.reshape(Nx,Nx))
plt.imshow(Vr.imag.reshape(Nx,Nx))
def FMat(FCoeffs, nmax):
    dimx = 2*nmax+1
    dB = dimx*dimx
    MM = np.zeros([dB,dB])
    dimF = len(FCoeffs)
    dimFx  = (dimF-1)//2
    #print(dimFx,dimF)
    for iFx, FCoeffx in enumerate(FCoeffs):
        for iFy, FCoeff in enumerate(FCoeffx):
            index_shift = iFx-dimFx + (iFy-dimFx)*dimF 
            #print(iFx-dimFx,iFy-dimFx,FCoeff,index_shift)
            MM+=np.diag([FCoeff]*(dB-np.abs(index_shift)),index_shift)
    return MM # +MM.T

plt.imshow(FMat(FCoeffs, nmax))
VFMat = FMat(FCoeffs, nmax)
def Hband(kx,ky,nmax,VFMat):
    #dimx = 2*nmax+1
    #dB = dimx*dimx
    
    nn = np.arange(-nmax,nmax+1)
    mGx, mGy = np.meshgrid(nn,nn)
    
    HH = np.diag(ϵkG(kx,ky,mGx,mGy).flatten())
    HH+= VFMat
    return HH
kx=0.
ky=0.
Hb = Hband(kx,ky,nmax,VFMat)
plt.imshow(Hb)
Ebands=[]
for ky in kk:
    Eband=[]
    for kx in kk:
        Hb = Hband(kx,ky,nmax,VFMat)
        ee, uu = np.linalg.eigh(Hb)
        Eband.append(ee)
    Ebands.append(Eband)
    
Ebands=np.array(Ebands)
Ebands.shape
plt.imshow(Ebands[:,:,0])
from mpl_toolkits import mplot3d 
# syntax for 3-D projection 
ax = plt.axes(projection ='3d') 
ax.plot_surface(kk,kk,Ebands[:,:,0])
# plot the first few bands for ky=0
for ni,n in enumerate(nn[:3]):
    plt.plot(kk,Ebands[:,len(kk)//2,ni],'-')
# plot eigenfunction in real-space<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.170899854862119, 'fraction_numerical': 0.025036284470246733, 'mean_word_length': 3.66497461928934, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 1, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '1', 'dir': 'jupyter-structured-clean-dedup', 'id': '511980', 'license': 'MIT', 'n_tokens_mistral': 1452, 'n_tokens_neox': 1376, 'n_words': 256, 'path': '2d_band_structure.ipynb', 'repo_name': 'sinansevim/EBT617E', 'size': '2756'}