This commit is contained in:
2023-07-26 00:46:01 +08:00
parent c7cbcd09af
commit 822fa7e626
212 changed files with 5687 additions and 5687 deletions

View File

@@ -0,0 +1,69 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/408
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1): # graphene哈密顿量N是条带的宽度参数
# 初始化为零矩阵
h00 = np.zeros((4*N, 4*N), dtype=complex)
h01 = np.zeros((4*N, 4*N), dtype=complex)
# 原胞内的跃迁h00
for i in range(N):
h00[i*4+0, i*4+0] = M
h00[i*4+1, i*4+1] = -M
h00[i*4+2, i*4+2] = M
h00[i*4+3, i*4+3] = -M
# 最近邻
h00[i*4+0, i*4+1] = t1
h00[i*4+1, i*4+0] = t1
h00[i*4+1, i*4+2] = t1
h00[i*4+2, i*4+1] = t1
h00[i*4+2, i*4+3] = t1
h00[i*4+3, i*4+2] = t1
for i in range(N-1):
# 最近邻
h00[i*4+3, (i+1)*4+0] = t1
h00[(i+1)*4+0, i*4+3] = t1
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4+1, i*4+0] = t1
h01[i*4+2, i*4+3] = t1
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, N=40, M=0, t1=1)
k = np.linspace(-pi, pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,65 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/408
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k1, k2, M, t1, a=1/sqrt(3)): # graphene哈密顿量a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term),用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
matrix = h0 + h1
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, M=0, t1=1, a=1/sqrt(3)) # 使用偏函数,固定一些参数
k1 = np.linspace(-2*pi, 2*pi, 500)
k2 = np.linspace(-2*pi, 2*pi, 500)
plot_bands_two_dimension(k1, k2, hamiltonian0)
def plot_bands_two_dimension(k1, k2, hamiltonian):
from matplotlib import cm
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], rcount=200, ccount=200, cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,94 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/410
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1, t2, phi): # Haldane哈密顿量N是条带的宽度参数
# 初始化为零矩阵
h00 = np.zeros((4*N, 4*N), dtype=complex)
h01 = np.zeros((4*N, 4*N), dtype=complex)
# 原胞内的跃迁h00
for i in range(N):
h00[i*4+0, i*4+0] = M
h00[i*4+1, i*4+1] = -M
h00[i*4+2, i*4+2] = M
h00[i*4+3, i*4+3] = -M
# 最近邻
h00[i*4+0, i*4+1] = t1
h00[i*4+1, i*4+0] = t1
h00[i*4+1, i*4+2] = t1
h00[i*4+2, i*4+1] = t1
h00[i*4+2, i*4+3] = t1
h00[i*4+3, i*4+2] = t1
# 次近邻
h00[i*4+0, i*4+2] = t2*cmath.exp(-1j*phi)
h00[i*4+2, i*4+0] = h00[i*4+0, i*4+2].conj()
h00[i*4+1, i*4+3] = t2*cmath.exp(-1j*phi)
h00[i*4+3, i*4+1] = h00[i*4+1, i*4+3].conj()
for i in range(N-1):
# 最近邻
h00[i*4+3, (i+1)*4+0] = t1
h00[(i+1)*4+0, i*4+3] = t1
# 次近邻
h00[i*4+2, (i+1)*4+0] = t2*cmath.exp(1j*phi)
h00[(i+1)*4+0, i*4+2] = h00[i*4+2, (i+1)*4+0].conj()
h00[i*4+3, (i+1)*4+1] = t2*cmath.exp(1j*phi)
h00[(i+1)*4+1, i*4+3] = h00[i*4+3, (i+1)*4+1].conj()
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4+1, i*4+0] = t1
h01[i*4+2, i*4+3] = t1
# 次近邻
h01[i*4+0, i*4+0] = t2*cmath.exp(1j*phi)
h01[i*4+1, i*4+1] = t2*cmath.exp(-1j*phi)
h01[i*4+2, i*4+2] = t2*cmath.exp(1j*phi)
h01[i*4+3, i*4+3] = t2*cmath.exp(-1j*phi)
h01[i*4+1, i*4+3] = t2*cmath.exp(1j*phi)
h01[i*4+2, i*4+0] = t2*cmath.exp(-1j*phi)
if i != 0:
h01[i*4+1, (i-1)*4+3] = t2*cmath.exp(1j*phi)
for i in range(N-1):
h01[i*4+2, (i+1)*4+0] = t2*cmath.exp(-1j*phi)
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, N=40, M=2/3, t1=1, t2=1/3, phi=pi/4)
k = np.linspace(-pi, pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,70 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/410
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距不赋值的话默认为1/sqrt(3)
# 初始化为零矩阵
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term),用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
# 次近邻项
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*sqrt(3)*k1*a)+cmath.exp(-1j*sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a))
matrix = h0 + h1 + h2 + h2.transpose().conj()
return matrix
def main():
hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=1/sqrt(3))
k1 = np.linspace(-2*pi, 2*pi, 500)
k2 = np.linspace(-2*pi, 2*pi, 500)
plot_bands_two_dimension(k1, k2, hamiltonian0)
def plot_bands_two_dimension(k1, k2, hamiltonian):
from matplotlib import cm
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,84 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/2327
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入sqrt(), pi, exp等
import cmath # 要处理复数情况用到cmath.exp()
import functools # 使用偏函数functools.partial()
def get_terms(A, B, C, D, M, a):
E_s = C+M-4*(D+B)/(a**2)
E_p = C-M-4*(D-B)/(a**2)
V_ss = (D+B)/(a**2)
V_pp = (D-B)/(a**2)
V_sp = -1j*A/(2*a)
H0 = np.zeros((4, 4), dtype=complex) # 在位能 (on-site energy)
H1 = np.zeros((4, 4), dtype=complex) # x方向的跃迁 (hopping)
H2 = np.zeros((4, 4), dtype=complex) # y方向的跃迁 (hopping)
H0[0, 0] = E_s
H0[1, 1] = E_p
H0[2, 2] = E_s
H0[3, 3] = E_p
H1[0, 0] = V_ss
H1[1, 1] = V_pp
H1[2, 2] = V_ss
H1[3, 3] = V_pp
H1[0, 1] = V_sp
H1[1, 0] = -np.conj(V_sp)
H1[2, 3] = np.conj(V_sp)
H1[3, 2] = -V_sp
H2[0, 0] = V_ss
H2[1, 1] = V_pp
H2[2, 2] = V_ss
H2[3, 3] = V_pp
H2[0, 1] = 1j*V_sp
H2[1, 0] = 1j*np.conj(V_sp)
H2[2, 3] = -1j*np.conj(V_sp)
H2[3, 2] = -1j*V_sp
return H0, H1, H2
def BHZ_model(k, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1, N=100): # 这边数值是不赋值时的默认参数
H0, H1, H2 = get_terms(A, B, C, D, M, a)
H00 = np.zeros((4*N, 4*N), dtype=complex) # 元胞内条带宽度为N
H01 = np.zeros((4*N, 4*N), dtype=complex) # 条带方向元胞间的跃迁
for i in range(N):
H00[i*4+0:i*4+4, i*4+0:i*4+4] = H0 # a:b代表 a <= x < b
H01[i*4+0:i*4+4, i*4+0:i*4+4] = H1
for i in range(N-1):
H00[i*4+0:i*4+4, (i+1)*4+0:(i+1)*4+4] = H2
H00[(i+1)*4+0:(i+1)*4+4, i*4+0:i*4+4] = np.conj(np.transpose(H2))
H = H00 + H01 * cmath.exp(-1j * k) + H01.transpose().conj() * cmath.exp(1j * k)
return H
def main():
hamiltonian0 = functools.partial(BHZ_model, N=50) # 使用偏函数,固定一些参数
k = np.linspace(-pi, pi, 300) # 300
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian, filename='bands_1D'):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim)) # np.zeros()里要用tuple
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k') # -.
# plt.savefig(filename + '.jpg') # plt.savefig(filename+'.eps')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,48 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/3895
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, t): # 准一维方格子哈密顿量
# 初始化为零矩阵
h00 = np.zeros((N, N), dtype=complex)
h01 = np.zeros((N, N), dtype=complex)
for i in range(N-1): # 原胞内的跃迁h00
h00[i, i+1] = t
h00[i+1, i] = t
for i in range(N): # 原胞间的跃迁h01
h01[i, i] = t
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def main():
H_k = functools.partial(hamiltonian, N=10, t=1)
k = np.linspace(-pi, pi, 300)
plot_bands_one_dimension(k, H_k)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,69 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4322
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N):
# 初始化为零矩阵
h = np.zeros((4*N, 4*N), dtype=complex)
t=1
a=1
t0=0.2 # 层间跃迁
V=0.2 # 层间的势能差为2V
for i in range(N):
h[i*4+0, i*4+0] = V
h[i*4+1, i*4+1] = V
h[i*4+2, i*4+2] = -V
h[i*4+3, i*4+3] = -V
h[i*4+0, i*4+1] = -t*(1+cmath.exp(1j*k*a))
h[i*4+1, i*4+0] = -t*(1+cmath.exp(-1j*k*a))
h[i*4+2, i*4+3] = -t*(1+cmath.exp(1j*k*a))
h[i*4+3, i*4+2] = -t*(1+cmath.exp(-1j*k*a))
h[i*4+0, i*4+3] = -t0
h[i*4+3, i*4+0] = -t0
for i in range(N-1):
# 最近邻
h[i*4+1, (i+1)*4+0] = -t
h[(i+1)*4+0, i*4+1] = -t
h[i*4+3, (i+1)*4+2] = -t
h[(i+1)*4+2, i*4+3] = -t
return h
def main():
hamiltonian0 = functools.partial(hamiltonian, N=100)
k = np.linspace(-pi, pi, 400)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
print(k0)
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,83 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4322
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N):
# 初始化为零矩阵
h = np.zeros((4*N, 4*N), dtype=complex)
h11 = np.zeros((4*N, 4*N), dtype=complex) # 元胞内
h12 = np.zeros((4*N, 4*N), dtype=complex) # 元胞间
t=1
a=1
t0=0.2 # 层间跃迁
V=0.2 # 层间的势能差为2V
for i in range(N):
h11[i*2+0, i*2+0] = V
h11[i*2+1, i*2+1] = V
h11[N*2+i*2+0, N*2+i*2+0] = -V
h11[N*2+i*2+1, N*2+i*2+1] = -V
h11[i*2+0, i*2+1] = -t
h11[i*2+1, i*2+0] = -t
h11[N*2+i*2+0, N*2+i*2+1] = -t
h11[N*2+i*2+1, N*2+i*2+0] = -t
h11[i*2+0, N*2+i*2+1] = -t0
h11[N*2+i*2+1, i*2+0] = -t0
for i in range(N-1):
h11[i*2+1, (i+1)*2+0] = -t
h11[(i+1)*2+0, i*2+1] = -t
h11[N*2+i*2+1, N*2+(i+1)*2+0] = -t
h11[N*2+(i+1)*2+0, N*2+i*2+1] = -t
for i in range(N):
h12[i*2+0, i*2+1] = -t
h12[N*2+i*2+0, N*2+i*2+1] = -t
h= h11 + h12*cmath.exp(-1j*k*a) + h12.transpose().conj()*cmath.exp(1j*k*a)
return h
def main():
hamiltonian0 = functools.partial(hamiltonian, N=100)
k = np.linspace(-pi, pi, 400)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
print(k0)
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,101 @@
% Purpose: Plot Kane-Mele's bands
% Date: Dec 07, 2021 @HNU
% Author: Ji-Huan Guan;
% Modify by Zhong-Fu Li;
% More code can be found in https://www.guanjihuan.com/
close all
clc
clear all
tic;
k0 = linspace(0,2*pi,100);
for kk = 1:100
k = k0(kk);
H1 = HH(k);
[VV,DD] = eig(H1);
Ds(:,kk) = sort(diag(DD),'ascend'); % sort eigenvalue
end
plot(k0/2/pi,Ds,'k.');
ylim([-1 1])
set(gca,'xtick',[0:0.5:1])
set(gca,'XTickLabel',{'\bf 0','\bf \pi','\bf 2\pi'})
set(gcf,'color','w');
set(gca,'fontsize',16,'LineWidth',1.1);
ylabel('Energy(a.u.)','fontname','Arial');
toc
% define Hamiltonian
function H = HH(k)
N = 10;
M = 0;
t1 = 1;
t2 = 0.03;
phi = pi/2;
h00 = zeros(2 * 4 * N, 2 * 4 * N);
h01 = zeros(2 * 4 * N, 2 * 4 * N);
for spin = 1:2
for ii = 0:N-1
% nearest neighbor couplings
h00(ii * 4 * 2 + 0 * 2 + spin, ii * 4 * 2 + 1 * 2 + spin) = t1;
h00(ii * 4 * 2 + 1 * 2 + spin, ii * 4 * 2 + 0 * 2 + spin) = t1;
h00(ii * 4 * 2 + 1 * 2 + spin, ii * 4 * 2 + 2 * 2 + spin) = t1;
h00(ii * 4 * 2 + 2 * 2 + spin, ii * 4 * 2 + 1 * 2 + spin) = t1;
h00(ii * 4 * 2 + 2 * 2 + spin, ii * 4 * 2 + 3 * 2 + spin) = t1;
h00(ii * 4 * 2 + 3 * 2 + spin, ii * 4 * 2 + 2 * 2 + spin) = t1;
%next nearest neighbor couplings
h00(ii * 4 * 2 + 0 * 2 + spin, ii * 4 * 2 + 2 * 2 + spin) = t2 * exp(-1j * phi) * sign_spin(spin);
h00(ii * 4 * 2 + 2 * 2 + spin, ii * 4 * 2 + 0 * 2 + spin) = conj(h00(...
ii * 4 * 2 + 0 * 2 + spin, ii * 4 * 2 + 2 * 2 + spin));
h00(ii * 4 * 2 + 1 * 2 + spin, ii * 4 * 2 + 3 * 2 + spin) = t2 * exp(-1j * phi) * sign_spin(spin);
h00(ii * 4 * 2 + 3 * 2 + spin, ii * 4 * 2 + 1 * 2 + spin) = conj(h00(...
ii * 4 * 2 + 1 * 2 + spin, ii * 4 * 2 + 3 * 2 + spin));
%
end
for ii = 0:N-2
% nearest neighbor couplings
h00(ii * 4 * 2 + 3 * 2 + spin, (ii + 1) * 4 * 2 + 0 * 2 + spin) = t1;
h00((ii + 1) * 4 * 2 + 0 * 2 + spin, ii * 4 * 2 + 3 * 2 + spin) = t1;
% next nearest neighbor couplings
h00(ii * 4 * 2 + 2 * 2 + spin, (ii + 1) * 4 * 2 + 0 * 2 + spin) = t2 *exp(1j * phi) * sign_spin(spin);
h00((ii + 1) * 4 * 2 + 0 * 2 + spin, ii * 4 * 2 + 2 * 2 + spin) = conj(h00(...
ii * 4 * 2 + 2 * 2 + spin, (ii + 1) * 4 * 2 + 0 * 2 + spin));
h00(ii * 4 * 2 + 3 * 2 + spin, (ii + 1) * 4 * 2 + 1 * 2 + spin) = t2 * exp(1j * phi) * sign_spin(spin);
h00((ii + 1) * 4 * 2 + 1 * 2 + spin, ii * 4 * 2 + 3 * 2 + spin) = conj(h00(...
ii * 4 * 2 + 3 * 2 + spin, (ii + 1) * 4 * 2 + 1 * 2 + spin) );
end
% hopping of intercell h01
for ii = 0:N-1
% nearest neighbor couplings
h01(ii * 4 * 2 + 1 * 2 + spin, ii * 4 * 2 + 0 * 2 + spin) = t1;
h01(ii * 4 * 2 + 2 * 2 + spin, ii * 4 * 2 + 3 * 2 + spin) = t1;
% next nearest neighbor couplings
h01(ii * 4 * 2 + 0 * 2 + spin, ii * 4 * 2 + 0 * 2 + spin) = t2 * exp(1j * phi) * sign_spin(spin);
h01(ii * 4 * 2 + 1 * 2 + spin, ii* 4 * 2 + 1 * 2 + spin) = t2 * exp(-1j * phi) * sign_spin(spin);
h01(ii * 4 * 2 + 2 * 2 + spin, ii * 4 * 2 + 2 * 2 + spin) = t2 * exp(1j * phi) * sign_spin(spin);
h01(ii * 4 * 2 + 3 * 2 + spin, ii * 4 * 2 + 3 * 2 + spin) = t2 * exp(-1j * phi) * sign_spin(spin);
h01(ii * 4 * 2 + 1 * 2 + spin, ii * 4 * 2 + 3 * 2 + spin) = t2 * exp(1j * phi) * sign_spin(spin);
h01(ii * 4 * 2 + 2 * 2 + spin, ii * 4 * 2 + 0 * 2 + spin) = t2 * exp(-1j * phi) * sign_spin(spin);
if ii ~= 0
h01(ii * 4 * 2 + 1 * 2 + spin, (ii - 1) * 4 * 2 + 3 * 2 + spin) = t2 * exp(1j * phi) * sign_spin(spin);
end
end
for ii = 0:N-2
h01(ii * 4 * 2 + 2 * 2 + spin, (ii + 1) * 4 * 2 + 0 * 2 + spin) = t2 *exp(-1j * phi) * sign_spin(spin);
end
end
H = h00 + h01 * exp(1j * k) + h01' * exp(-1j * k);
end
function sign = sign_spin(spin)
if spin == 1
sign = 1;
else
sign = -1;
end
end

View File

@@ -0,0 +1,104 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/4829
"""
import numpy as np
import matplotlib.pyplot as plt
from math import *
import cmath
import functools
def hamiltonian(k, N, M, t1, t2, phi): # Kane-Mele model
# 初始化为零矩阵
h00 = np.zeros((2*4*N, 2*4*N), dtype=complex) # 因为自旋有上有下所以整个维度要乘2。这里4是元胞内部重复单位的大小规定元胞大小以4来倍增。
h01 = np.zeros((2*4*N, 2*4*N), dtype=complex)
for spin in range(2):
# 原胞内的跃迁h00
for i in range(N):
# 最近邻
h00[i*4*2+0*2+spin, i*4*2+1*2+spin] = t1
h00[i*4*2+1*2+spin, i*4*2+0*2+spin] = t1
h00[i*4*2+1*2+spin, i*4*2+2*2+spin] = t1
h00[i*4*2+2*2+spin, i*4*2+1*2+spin] = t1
h00[i*4*2+2*2+spin, i*4*2+3*2+spin] = t1
h00[i*4*2+3*2+spin, i*4*2+2*2+spin] = t1
# 次近邻
h00[i*4*2+0*2+spin, i*4*2+2*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h00[i*4*2+2*2+spin, i*4*2+0*2+spin] = h00[i*4*2+0*2+spin, i*4*2+2*2+spin].conj()
h00[i*4*2+1*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h00[i*4*2+3*2+spin, i*4*2+1*2+spin] = h00[i*4*2+1*2+spin, i*4*2+3*2+spin].conj()
for i in range(N-1):
# 最近邻
h00[i*4*2+3*2+spin, (i+1)*4*2+0*2+spin] = t1
h00[(i+1)*4*2+0*2+spin, i*4*2+3*2+spin] = t1
# 次近邻
h00[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h00[(i+1)*4*2+0*2+spin, i*4*2+2*2+spin] = h00[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin].conj()
h00[i*4*2+3*2+spin, (i+1)*4*2+1*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h00[(i+1)*4*2+1*2+spin, i*4*2+3*2+spin] = h00[i*4*2+3*2+spin, (i+1)*4*2+1*2+spin].conj()
# 原胞间的跃迁h01
for i in range(N):
# 最近邻
h01[i*4*2+1*2+spin, i*4*2+0*2+spin] = t1
h01[i*4*2+2*2+spin, i*4*2+3*2+spin] = t1
# 次近邻
h01[i*4*2+0*2+spin, i*4*2+0*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+1*2+spin, i*4*2+1*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h01[i*4*2+2*2+spin, i*4*2+2*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+3*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
h01[i*4*2+1*2+spin, i*4*2+3*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
h01[i*4*2+2*2+spin, i*4*2+0*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
if i != 0:
h01[i*4*2+1*2+spin, (i-1)*4*2+3*2+spin] = t2*cmath.exp(1j*phi)*sign_spin(spin)
for i in range(N-1):
h01[i*4*2+2*2+spin, (i+1)*4*2+0*2+spin] = t2*cmath.exp(-1j*phi)*sign_spin(spin)
matrix = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
return matrix
def sign_spin(spin):
if spin==0:
sign=1
else:
sign=-1
return sign
def main():
hamiltonian0 = functools.partial(hamiltonian, N=20, M=0, t1=1, t2=0.03, phi=pi/2)
k = np.linspace(0, 2*pi, 300)
plot_bands_one_dimension(k, hamiltonian0)
def plot_bands_one_dimension(k, hamiltonian):
dim = hamiltonian(0).shape[0]
dim_k = k.shape[0]
eigenvalue_k = np.zeros((dim_k, dim))
i0 = 0
for k0 in k:
matrix0 = hamiltonian(k0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(k, eigenvalue_k[:, dim0], '-k')
plt.ylim(-1, 1)
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,23 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5375
"""
import numpy as np
def hamiltonian(width=3, length=3): # 方格子哈密顿量
h = np.zeros((width*length, width*length))
# y方向的跃迁
for x in range(length):
for y in range(width-1):
h[x*width+y, x*width+y+1] = 1
h[x*width+y+1, x*width+y] = 1
# x方向的跃迁
for x in range(length-1):
for y in range(width):
h[x*width+y, (x+1)*width+y] = 1
h[(x+1)*width+y, x*width+y] = 1
return h
h = hamiltonian()
print(h)

View File

@@ -0,0 +1,21 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/5375
"""
import numpy as np
def hamiltonian(width=3, length=3): # 方格子哈密顿量
hopping_x = np.zeros((length, length))
hopping_y = np.zeros((width, width))
for i in range(length-1):
hopping_x[i, i+1] = 1
hopping_x[i+1, i] = 1
for i in range(width-1):
hopping_y[i, i+1] = 1
hopping_y[i+1, i] = 1
h = np.kron(hopping_x, np.eye(width))+np.kron(np.eye(length), hopping_y)
return h
h = hamiltonian()
print(h)

View File

@@ -0,0 +1,64 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6077
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
def main():
n = 0.5
k1 = np.arange(-n*pi, n*pi, n/50)
k2 = np.arange(-n*pi, n*pi, n/50)
plot_bands_two_dimension_direct(k1, k2, hamiltonian)
def hamiltonian(kx,kz,ky=0): # surface states of Weyl semimetal
A = 1
H = A*kx
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def plot_bands_two_dimension_direct(k1, k2, hamiltonian):
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
fig = plt.figure()
ax = fig.gca(projection='3d')
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
if (k10**2+k20**2 <= 1):
eigenvalue_k[j0, i0] = hamiltonian(k10, k20)
else:
eigenvalue_k[j0, i0] = 'nan'
j0 += 1
i0 += 1
k1, k2 = np.meshgrid(k1, k2)
ax.scatter(k1, k2, eigenvalue_k)
plt.xlabel('kx')
plt.ylabel('kz')
ax.set_zlabel('E')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,67 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6077
"""
import numpy as np
from math import *
import matplotlib.pyplot as plt
def main():
n = 0.5
k1 = np.arange(-n*pi, n*pi, n/20)
k2 = np.arange(-n*pi, n*pi, n/20)
plot_bands_two_dimension(k1, k2, hamiltonian)
def hamiltonian(kx,kz,ky=0): # Weyl semimetal
A = 1
M0 = 1
M1 = 1
H = A*(kx*sigma_x()+ky*sigma_y())+(M0-M1*(kx**2+ky**2+kz**2))*sigma_z()
return H
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def plot_bands_two_dimension(k1, k2, hamiltonian):
from mpl_toolkits.mplot3d import Axes3D
from matplotlib import cm
from matplotlib.ticker import LinearLocator, FormatStrFormatter
dim = hamiltonian(0, 0).shape[0]
dim1 = k1.shape[0]
dim2 = k2.shape[0]
eigenvalue_k = np.zeros((dim2, dim1, dim))
i0 = 0
for k10 in k1:
j0 = 0
for k20 in k2:
matrix0 = hamiltonian(k10, k20)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_k[j0, i0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
fig = plt.figure()
ax = fig.gca(projection='3d')
k1, k2 = np.meshgrid(k1, k2)
for dim0 in range(dim):
ax.plot_surface(k1, k2, eigenvalue_k[:, :, dim0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
plt.xlabel('kx')
plt.ylabel('kz')
ax.set_zlabel('E')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,77 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/6260
"""
import numpy as np
import matplotlib.pyplot as plt
from math import * # 引入sqrt(), pi, exp等
import cmath # 要处理复数情况用到cmath.exp()
def hamiltonian(k1, k2, M=0, t1=1, a=1/sqrt(3)): # Haldane哈密顿量(a为原子间距不赋值的话默认为1/sqrt(3)
h0 = np.zeros((2, 2), dtype=complex)
h1 = np.zeros((2, 2), dtype=complex)
h2 = np.zeros((2, 2), dtype=complex)
# 质量项(mass term), 用于打开带隙
h0[0, 0] = M
h0[1, 1] = -M
# 最近邻项
h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*sqrt(3)/2*k1*a-1j/2*k2*a))
h1[0, 1] = h1[1, 0].conj()
# # 最近邻项也可写成这种形式
# h1[1, 0] = t1+t1*cmath.exp(1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)+t1*cmath.exp(-1j*sqrt(3)/2*k1*a-1j*3/2*k2*a)
# h1[0, 1] = h1[1, 0].conj()
matrix = h0 + h1
return matrix
def main():
a = 1/sqrt(3)
Gamma0 = np.array([0, 0])
M0 = np.array([0, 2*pi/3/a])
K0 = np.array([2*np.sqrt(3)*pi/9/a, 2*pi/3/a])
kn = 100 # 每个区域的取点数
n = 3 # n个区域K-GammaGamma-M, M-K
k1_array = np.zeros(kn*n)
k2_array = np.zeros(kn*n)
# K-Gamma轴
k1_array[0:kn] = np.linspace(0, K0[0], kn)[::-1] # [::-1]表示反转数组
k2_array[0:kn] = np.linspace(0, K0[1], kn)[::-1]
# Gamma-M轴
k1_array[kn:2*kn] = np.zeros(kn)
k2_array[kn:2*kn] = np.linspace(0, M0[1], kn)
# M-K轴
k1_array[2*kn:3*kn] = np.linspace(0, K0[0], kn)
k2_array[2*kn:3*kn] = np.ones(kn)*M0[1]
i0 = 0
dim = hamiltonian(0, 0).shape[0]
eigenvalue_k = np.zeros((kn*n, dim))
fig, ax = plt.subplots()
for kn0 in range(kn*n):
k1 = k1_array[kn0]
k2 = k2_array[kn0]
eigenvalue, eigenvector = np.linalg.eig(hamiltonian(k1, k2))
eigenvalue_k[i0, :] = np.sort(np.real(eigenvalue[:]))
i0 += 1
for dim0 in range(dim):
plt.plot(range(kn*n), eigenvalue_k[:, dim0], '-k')
plt.ylabel('E')
ax.set_xticks([0, kn, 2*kn, 3*kn])
ax.set_xticklabels(['K', 'Gamma', 'M', 'K'])
plt.xlim(0, n*kn)
plt.grid(axis='x',c='r',linestyle='--')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,100 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8557
"""
import numpy as np
from math import *
def hamiltonian(Nx, Ny):
delta = 1e-3
gamma = 1e-3
lambda0 = 1
h = np.zeros((4*Nx*Ny, 4*Nx*Ny))
# 元胞内部跃迁
for x in range(Nx):
for y in range(Ny):
h[x*Ny*4+y*4+0, x*Ny*4+y*4+0] = delta
h[x*Ny*4+y*4+1, x*Ny*4+y*4+1] = delta
h[x*Ny*4+y*4+2, x*Ny*4+y*4+2] = -delta
h[x*Ny*4+y*4+3, x*Ny*4+y*4+3] = -delta
h[x*Ny*4+y*4+0, x*Ny*4+y*4+2] = gamma
h[x*Ny*4+y*4+0, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+2] = -gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+1] = -gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+1] = gamma
# y方向上的元胞间跃迁
for x in range(Nx):
for y in range(Ny-1):
h[x*Ny*4+y*4+0, x*Ny*4+(y+1)*4+3] = lambda0
h[x*Ny*4+(y+1)*4+1, x*Ny*4+y*4+2] = -lambda0
h[x*Ny*4+y*4+2, x*Ny*4+(y+1)*4+1] = -lambda0
h[x*Ny*4+(y+1)*4+3, x*Ny*4+y*4+0] = lambda0
# x方向上的元胞间跃迁
for x in range(Nx-1):
for y in range(Ny):
h[x*Ny*4+y*4+0, (x+1)*Ny*4+y*4+2] = lambda0
h[(x+1)*Ny*4+y*4+1, x*Ny*4+y*4+3] = lambda0
h[(x+1)*Ny*4+y*4+2, x*Ny*4+y*4+0] = lambda0
h[x*Ny*4+y*4+3, (x+1)*Ny*4+y*4+1] = lambda0
return h
def main():
Nx = 10
Ny = 10
fermi_energy = 0
h = hamiltonian(Nx, Ny)
green = np.linalg.inv((fermi_energy+1e-6j)*np.eye(h.shape[0])-h)
x_array = []
y_array = []
DOS = []
for x in range(Nx):
for y in range(Ny):
x_array.append(x*2+2)
y_array.append(y*2+2)
DOS.append(-np.imag(green[x*Ny*4+y*4+0, x*Ny*4+y*4+0])/pi)
x_array.append(x*2+1)
y_array.append(y*2+1)
DOS.append(-np.imag(green[x*Ny*4+y*4+1, x*Ny*4+y*4+1])/pi)
x_array.append(x*2+1)
y_array.append(y*2+2)
DOS.append(-np.imag(green[x*Ny*4+y*4+2, x*Ny*4+y*4+2])/pi)
x_array.append(x*2+2)
y_array.append(y*2+1)
DOS.append(-np.imag(green[x*Ny*4+y*4+3, x*Ny*4+y*4+3])/pi)
DOS = DOS/np.sum(DOS)
Plot_2D_Scatter(x_array, y_array, DOS, xlabel='x', ylabel='y', title='BBH Model', filename='BBH Model')
def Plot_2D_Scatter(x, y, value, xlabel='x', ylabel='y', title='title', filename='a'):
import matplotlib.pyplot as plt
fig = plt.figure()
ax = fig.add_subplot(111)
plt.subplots_adjust(bottom=0.2, right=0.8, left=0.2)
for i in range(np.array(x).shape[0]):
ax.scatter(x[i], y[i], marker='o', s=1000*value[i], c=[(1,0,0)])
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,100 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/8557
"""
import numpy as np
from math import *
def hamiltonian(Nx, Ny):
delta = 1e-3
gamma = 1e-3
lambda0 = 1
h = np.zeros((4*Nx*Ny, 4*Nx*Ny))
# 元胞内部跃迁
for x in range(Nx):
for y in range(Ny):
h[x*Ny*4+y*4+0, x*Ny*4+y*4+0] = delta
h[x*Ny*4+y*4+1, x*Ny*4+y*4+1] = delta
h[x*Ny*4+y*4+2, x*Ny*4+y*4+2] = -delta
h[x*Ny*4+y*4+3, x*Ny*4+y*4+3] = -delta
h[x*Ny*4+y*4+0, x*Ny*4+y*4+2] = gamma
h[x*Ny*4+y*4+0, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+2] = -gamma
h[x*Ny*4+y*4+1, x*Ny*4+y*4+3] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+2, x*Ny*4+y*4+1] = -gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+0] = gamma
h[x*Ny*4+y*4+3, x*Ny*4+y*4+1] = gamma
# y方向上的元胞间跃迁
for x in range(Nx):
for y in range(Ny-1):
h[x*Ny*4+y*4+0, x*Ny*4+(y+1)*4+3] = lambda0
h[x*Ny*4+(y+1)*4+1, x*Ny*4+y*4+2] = -lambda0
h[x*Ny*4+y*4+2, x*Ny*4+(y+1)*4+1] = -lambda0
h[x*Ny*4+(y+1)*4+3, x*Ny*4+y*4+0] = lambda0
# x方向上的元胞间跃迁
for x in range(Nx-1):
for y in range(Ny):
h[x*Ny*4+y*4+0, (x+1)*Ny*4+y*4+2] = lambda0
h[(x+1)*Ny*4+y*4+1, x*Ny*4+y*4+3] = lambda0
h[(x+1)*Ny*4+y*4+2, x*Ny*4+y*4+0] = lambda0
h[x*Ny*4+y*4+3, (x+1)*Ny*4+y*4+1] = lambda0
return h
def main():
Nx = 10
Ny = 10
fermi_energy = 0
h = hamiltonian(Nx, Ny)
green = np.linalg.inv((fermi_energy+1e-6j)*np.eye(h.shape[0])-h)
DOS = np.zeros((Ny*2, Nx*2))
for x in range(Nx):
for y in range(Ny):
DOS[y*2+1, x*2+1] = -np.imag(green[x*Ny*4+y*4+0, x*Ny*4+y*4+0])/pi
DOS[y*2+0, x*2+0] = -np.imag(green[x*Ny*4+y*4+1, x*Ny*4+y*4+1])/pi
DOS[y*2+1, x*2+0] = -np.imag(green[x*Ny*4+y*4+2, x*Ny*4+y*4+2])/pi
DOS[y*2+0, x*2+1] = -np.imag(green[x*Ny*4+y*4+3, x*Ny*4+y*4+3])/pi
DOS = DOS/np.sum(DOS)
Plot_3D_Surface(np.arange(1, 2*Nx+0.001), np.arange(1, 2*Ny+0.001), DOS, xlabel='x', ylabel='y', zlabel='DOS', title='BBH Model', filename='BBH Model')
def Plot_3D_Surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='title', filename='a'):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65)
x, y = np.meshgrid(x, y)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
# ax.set_zlim(-1, 1) # 设置z轴的范围
ax.zaxis.set_major_locator(LinearLocator(2)) # 设置z轴主刻度的个数
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
cax = plt.axes([0.80, 0.15, 0.05, 0.75]) # color bar的位置 [左,下,宽度, 高度]
cbar = fig.colorbar(surf, cax=cax) # color bar
cbar.ax.tick_params(labelsize=15) # 设置color bar刻度的字体大小
for l in cbar.ax.yaxis.get_ticklabels():
l.set_family('Times New Roman')
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,81 @@
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 12.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 158, 7]
NotebookDataLength[ 2039, 71]
NotebookOptionsPosition[ 1730, 57]
NotebookOutlinePosition[ 2086, 73]
CellTagsIndexPosition[ 2043, 70]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\n",
RowBox[{
RowBox[{"H", "=",
RowBox[{
RowBox[{"(",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"a0", ",", "0"}], "}"}], ",",
RowBox[{"{",
RowBox[{"0", ",", "a0"}], "}"}]}], "}"}], ")"}], "+",
RowBox[{"(",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"a3", ",",
RowBox[{"a1", "-",
RowBox[{"I", "*", "a2"}]}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"a1", "+",
RowBox[{"I", "*", "a2"}]}], ",",
RowBox[{"-", "a3"}]}], "}"}]}], "}"}], ")"}]}]}], ";"}], "\n",
RowBox[{"MatrixForm", "[", "H", "]"}], "\n",
RowBox[{"eigenvalue", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Simplify", "[",
RowBox[{"Eigenvalues", "[", "H", "]"}], "]"}], "]"}]}], "\n",
RowBox[{"eigenvector", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Simplify", "[",
RowBox[{"Eigenvectors", "[", "H", "]"}], "]"}], "]"}]}]}], "Input",
CellChangeTimes->{{3.830338636045154*^9,
3.830338636046383*^9}},ExpressionUUID->"6b5e0acb-1938-4b1e-bd73-\
d3f6bb8905fc"]
},
WindowSize->{759, 670},
WindowMargins->{{Automatic, 572}, {64, Automatic}},
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 1168, 35, 193, "Input",ExpressionUUID->"6b5e0acb-1938-4b1e-bd73-d3f6bb8905fc"]
}
]
*)
(* End of internal cache information *)

View File

@@ -0,0 +1,89 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10385
"""
import numpy as np
from math import *
def main():
k1 = np.linspace(-pi, pi, 100)
k2 = np.linspace(-pi, pi, 100)
eigenvalue_array = Calculate_Eigenvalue_with_Two_Parameters(k1, k2, hamiltonian)
Plot_3D_Surface(k1, k2, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', title='', filename='a')
def hamiltonian(kx,ky,kz=0):
w0x = 2
w0y = 0
w0z = 0
vx = 1
vy = 1
vz = 1
H = (w0x*kx+w0y*ky+w0z*kz)*sigma_0() + vx*kx*sigma_x()+vy*ky*sigma_y()+vz*kz*sigma_z()
return H
def sigma_0():
return np.eye(2)
def sigma_x():
return np.array([[0, 1],[1, 0]])
def sigma_y():
return np.array([[0, -1j],[1j, 0]])
def sigma_z():
return np.array([[1, 0],[0, -1]])
def Calculate_Eigenvalue_with_Two_Parameters(x, y, matrix):
dim = np.array(matrix(0, 0)).shape[0]
dim_x = np.array(x).shape[0]
dim_y = np.array(y).shape[0]
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
i0 = 0
for y0 in y:
j0 = 0
for x0 in x:
matrix0 = matrix(x0, y0)
eigenvalue, eigenvector = np.linalg.eig(matrix0)
eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:]))
j0 += 1
i0 += 1
return eigenvalue_array
def Plot_3D_Surface(x, y, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a'):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.8)
x, y = np.meshgrid(x, y)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x, y, matrix, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x, y, matrix[:,:,i0], cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=20, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=20, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=20, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=20, fontfamily='Times New Roman')
# ax.set_zlim(-1, 1) # 设置z轴的范围
ax.zaxis.set_major_locator(LinearLocator(5)) # 设置z轴主刻度的个数
ax.zaxis.set_major_formatter('{x:.2f}') # 设置z轴主刻度的格式
ax.tick_params(labelsize=15) # 设置刻度值字体大小
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels] # 设置刻度值字体
# plt.savefig(filename+'.jpg', dpi=300)
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,40 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
def main():
x_array = np.arange(-5, 5.1)
y_array = np.arange(-5, 5.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([0+x*3, 0+y*np.sqrt(3)])
coordinates.append([1+x*3, 0+y*np.sqrt(3)])
coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
plot_dots(coordinates)
def plot_dots(coordinates):
import matplotlib.pyplot as plt
x_range = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
y_range = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=8)
# plt.savefig('graphene.eps')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,35 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
def main():
x_array = np.arange(-5, 5.1)
y_array = np.arange(-5, 5.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([x, y])
plot_dots(coordinates)
def plot_dots(coordinates):
import matplotlib.pyplot as plt
fig, ax = plt.subplots(figsize=(9,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=1)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=10)
# plt.savefig('square.eps')
plt.show()
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,72 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/10909
"""
import numpy as np
import copy
import matplotlib.pyplot as plt
from math import *
def main():
x_array = np.arange(-20, 20.1)
y_array = np.arange(-20, 20.1)
coordinates = []
for x in x_array:
for y in y_array:
coordinates.append([0+x*3, 0+y*np.sqrt(3)])
coordinates.append([1+x*3, 0+y*np.sqrt(3)])
coordinates.append([-1/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
coordinates.append([-3/2+x*3, np.sqrt(3)/2+y*np.sqrt(3)])
x_range1 = max(np.array(coordinates)[:, 0])-min(np.array(coordinates)[:, 0])
y_range1 = max(np.array(coordinates)[:, 1])-min(np.array(coordinates)[:, 1])
theta = -1.1/180*pi
rotation_matrix = np.zeros((2, 2))
rotation_matrix[0, 0] = np.cos(theta)
rotation_matrix[1, 1] = np.cos(theta)
rotation_matrix[0, 1] = -np.sin(theta)
rotation_matrix[1, 0] = np.sin(theta)
coordinates2 = copy.deepcopy(coordinates)
for i in range(len(coordinates)):
coordinates2[i] = np.dot(rotation_matrix, coordinates[i])
x_range2 = max(np.array(coordinates2)[:, 0])-min(np.array(coordinates2)[:, 0])
y_range2 = max(np.array(coordinates2)[:, 1])-min(np.array(coordinates2)[:, 1])
x_range = max([x_range1, x_range2])
y_range = max([y_range1, y_range2])
fig, ax = plt.subplots(figsize=(9*x_range/y_range,9))
plt.subplots_adjust(left=0.05, bottom=0.05, right=0.95, top=0.95)
plt.axis('off')
plot_dots_1(ax, coordinates)
plot_dots_2(ax, coordinates2)
plot_dots_0(ax, [[0, 0]])
plt.savefig('twist_graphene.eps')
plt.show()
def plot_dots_0(ax, coordinates):
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ko', markersize=0.5)
def plot_dots_1(ax, coordinates):
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '-k', linewidth=0.2)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'ro', markersize=0.5)
def plot_dots_2(ax, coordinates):
for i1 in range(len(coordinates)):
for i2 in range(len(coordinates)):
if np.sqrt((coordinates[i1][0] - coordinates[i2][0])**2+(coordinates[i1][1] - coordinates[i2][1])**2) < 1.1:
ax.plot([coordinates[i1][0], coordinates[i2][0]], [coordinates[i1][1], coordinates[i2][1]], '--k', linewidth=0.2)
for i in range(len(coordinates)):
ax.plot(coordinates[i][0], coordinates[i][1], 'bo', markersize=0.5)
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,53 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/12731
"""
import numpy as np
import guan
a_00 = np.random.uniform(-1, 1)
a_0x = np.random.uniform(-1, 1)
a_0y = np.random.uniform(-1, 1)
a_0z = np.random.uniform(-1, 1)
a_x0 = np.random.uniform(-1, 1)
a_xx = np.random.uniform(-1, 1)
a_xy = np.random.uniform(-1, 1)
a_xz = np.random.uniform(-1, 1)
a_y0 = np.random.uniform(-1, 1)
a_yx = np.random.uniform(-1, 1)
a_yy = np.random.uniform(-1, 1)
a_yz = np.random.uniform(-1, 1)
a_z0 = np.random.uniform(-1, 1)
a_zx = np.random.uniform(-1, 1)
a_zy = np.random.uniform(-1, 1)
a_zz = np.random.uniform(-1, 1)
hamiltonian_1 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_0x()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_1 = guan.calculate_eigenvalue(hamiltonian_1)
hamiltonian_2 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_x0()+a_0y*guan.sigma_y0()+a_0z*guan.sigma_z0()+ \
a_x0*guan.sigma_0x()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_yx()+a_xz*guan.sigma_zx()+ \
a_y0*guan.sigma_0y()+a_yx*guan.sigma_xy()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_zy()+ \
a_z0*guan.sigma_0z()+a_zx*guan.sigma_xz()+a_zy*guan.sigma_yz()+a_zz*guan.sigma_zz()
eigenvalue_2 = guan.calculate_eigenvalue(hamiltonian_2)
print()
print('Eigenvalue:')
print(eigenvalue_1)
print(eigenvalue_2)
print()
print('Difference of matrices:')
print(hamiltonian_1-hamiltonian_2)
print()
# print(hamiltonian_1)
# print(hamiltonian_2)

View File

@@ -0,0 +1,49 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/12731
"""
import numpy as np
import guan
a_00 = np.random.uniform(-1, 1)
a_0x = np.random.uniform(-1, 1)
a_0y = np.random.uniform(-1, 1)
a_0z = np.random.uniform(-1, 1)
a_x0 = np.random.uniform(-1, 1)
a_xx = np.random.uniform(-1, 1)
a_xy = np.random.uniform(-1, 1)
a_xz = np.random.uniform(-1, 1)
a_y0 = np.random.uniform(-1, 1)
a_yx = np.random.uniform(-1, 1)
a_yy = np.random.uniform(-1, 1)
a_yz = np.random.uniform(-1, 1)
a_z0 = np.random.uniform(-1, 1)
a_zx = np.random.uniform(-1, 1)
a_zy = np.random.uniform(-1, 1)
a_zz = np.random.uniform(-1, 1)
hamiltonian_1 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_0x()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_1 = guan.calculate_eigenvalue(hamiltonian_1)
# only guan.sigma_0x() is changed to guan.sigma_x0()
hamiltonian_3 = \
a_00*guan.sigma_00()+a_0x*guan.sigma_x0()+a_0y*guan.sigma_0y()+a_0z*guan.sigma_0z()+ \
a_x0*guan.sigma_x0()+a_xx*guan.sigma_xx()+a_xy*guan.sigma_xy()+a_xz*guan.sigma_xz()+ \
a_y0*guan.sigma_y0()+a_yx*guan.sigma_yx()+a_yy*guan.sigma_yy()+a_yz*guan.sigma_yz()+ \
a_z0*guan.sigma_z0()+a_zx*guan.sigma_zx()+a_zy*guan.sigma_zy()+a_zz*guan.sigma_zz()
eigenvalue_3 = guan.calculate_eigenvalue(hamiltonian_3)
print()
print('Eigenvalue:')
print(eigenvalue_1)
print(eigenvalue_3)
print()

View File

@@ -0,0 +1,81 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/16199
"""
import numpy as np
from math import *
import cmath
def hamiltonian_1(k, v=0.6, w=1):
matrix = np.zeros((2, 2), dtype=complex)
matrix[0,1] = v+w*cmath.exp(-1j*k)
matrix[1,0] = v+w*cmath.exp(1j*k)
return matrix
def hamiltonian_2(k, v=0.6, w=1):
matrix = np.zeros((2, 2), dtype=complex)
matrix[0,1] = v*cmath.exp(1j*k/2)+w*cmath.exp(-1j*k/2)
matrix[1,0] = v*cmath.exp(-1j*k/2)+w*cmath.exp(1j*k/2)
return matrix
def main():
k_array = np.linspace(-pi ,pi, 100)
E_1_array = calculate_eigenvalue_with_one_parameter(k_array, hamiltonian_1)
plot(k_array, E_1_array, xlabel='k', ylabel='E_1')
E_2_array = calculate_eigenvalue_with_one_parameter(k_array, hamiltonian_2)
plot(k_array, E_2_array, xlabel='k', ylabel='E_2')
# import guan
# E_1_array = guan.calculate_eigenvalue_with_one_parameter(k_array, hamiltonian_1)
# guan.plot(k_array, E_1_array, xlabel='k', ylabel='E_1')
# E_2_array = guan.calculate_eigenvalue_with_one_parameter(k_array, hamiltonian_2)
# guan.plot(k_array, E_2_array, xlabel='k', ylabel='E_2')
def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function, print_show=0):
dim_x = np.array(x_array).shape[0]
i0 = 0
if np.array(hamiltonian_function(0)).shape==():
eigenvalue_array = np.zeros((dim_x, 1))
for x0 in x_array:
hamiltonian = hamiltonian_function(x0)
eigenvalue_array[i0, 0] = np.real(hamiltonian)
i0 += 1
else:
dim = np.array(hamiltonian_function(0)).shape[0]
eigenvalue_array = np.zeros((dim_x, dim))
for x0 in x_array:
if print_show==1:
print(x0)
hamiltonian = hamiltonian_function(x0)
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
eigenvalue_array[i0, :] = eigenvalue
i0 += 1
return eigenvalue_array
def plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', file_format='.jpg', dpi=300, style='', y_min=None, y_max=None, linewidth=None, markersize=None, adjust_bottom=0.2, adjust_left=0.2):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
plt.subplots_adjust(bottom=adjust_bottom, left=adjust_left)
ax.plot(x_array, y_array, style, linewidth=linewidth, markersize=markersize)
ax.grid()
ax.set_title(title, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=fontsize, fontfamily='Times New Roman')
if y_min!=None or y_max!=None:
if y_min==None:
y_min=min(y_array)
if y_max==None:
y_max=max(y_array)
ax.set_ylim(y_min, y_max)
ax.tick_params(labelsize=labelsize)
labels = ax.get_xticklabels() + ax.get_yticklabels()
[label.set_fontname('Times New Roman') for label in labels]
if save == 1:
plt.savefig(filename+file_format, dpi=dpi)
if show == 1:
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,90 @@
(* Content-type: application/vnd.wolfram.mathematica *)
(*** Wolfram Notebook File ***)
(* http://www.wolfram.com/nb *)
(* CreatedBy='Mathematica 12.0' *)
(*CacheID: 234*)
(* Internal cache information:
NotebookFileLineBreakTest
NotebookFileLineBreakTest
NotebookDataPosition[ 158, 7]
NotebookDataLength[ 2422, 82]
NotebookOptionsPosition[ 2082, 67]
NotebookOutlinePosition[ 2469, 84]
CellTagsIndexPosition[ 2426, 81]
WindowFrame->Normal*)
(* Beginning of Notebook Content *)
Notebook[{
Cell[BoxData[{
RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\n",
RowBox[{
RowBox[{"k1a1", "=", "kx"}], ";"}], "\n",
RowBox[{
RowBox[{"k2a2", "=",
RowBox[{
RowBox[{"kx", "/", "2"}], "+",
RowBox[{"ky", "*",
RowBox[{
RowBox[{"Sqrt", "[", "3", "]"}], "/", "2"}]}]}]}], ";"}], "\n",
RowBox[{
RowBox[{"k3a3", "=",
RowBox[{
RowBox[{
RowBox[{"-", "kx"}], "/", "2"}], "+",
RowBox[{"ky", "*",
RowBox[{
RowBox[{"Sqrt", "[", "3", "]"}], "/", "2"}]}]}]}], ";"}], "\n",
RowBox[{
RowBox[{"H", "=",
RowBox[{
RowBox[{"-", "2"}], "*", "t", "*",
RowBox[{"(",
RowBox[{"{",
RowBox[{
RowBox[{"{",
RowBox[{"0", ",",
RowBox[{"Cos", "[", "k1a1", "]"}], ",",
RowBox[{"Cos", "[", "k2a2", "]"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"Cos", "[", "k1a1", "]"}], ",", "0", ",",
RowBox[{"Cos", "[", "k3a3", "]"}]}], "}"}], ",",
RowBox[{"{",
RowBox[{
RowBox[{"Cos", "[", "k2a2", "]"}], ",",
RowBox[{"Cos", "[", "k3a3", "]"}], ",", "0"}], "}"}]}], "}"}],
")"}]}]}], ";"}], "\n",
RowBox[{"MatrixForm", "[", "H", "]"}], "\n",
RowBox[{"eigenvalue", "=",
RowBox[{"MatrixForm", "[",
RowBox[{"Eigenvalues", "[", "H", "]"}], "]"}]}]}], "Input",
CellChangeTimes->{{3.837485198864452*^9, 3.837485198867505*^9}, {
3.837497369979506*^9, 3.8374974574378343`*^9}},
CellLabel->"",ExpressionUUID->"a7abdb4e-e7ef-4556-9d32-d94836d031ca"]
},
WindowSize->{1147, 812},
WindowMargins->{{Automatic, 228}, {22, Automatic}},
Magnification:>1.7 Inherited,
FrontEndVersion->"12.0 for Microsoft Windows (64-bit) (2019\:5e744\:67088\
\:65e5)",
StyleDefinitions->"Default.nb"
]
(* End of Notebook Content *)
(* Internal cache information *)
(*CellTagsOutline
CellTagsIndex->{}
*)
(*CellTagsIndex
CellTagsIndex->{}
*)
(*NotebookFileOutline
Notebook[{
Cell[558, 20, 1520, 45, 514, "Input",ExpressionUUID->"a7abdb4e-e7ef-4556-9d32-d94836d031ca"]
}
]
*)

View File

@@ -0,0 +1,103 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/16730
"""
import numpy as np
from math import *
def hamiltonian(kx, ky): # kagome lattice
k1_dot_a1 = kx
k2_dot_a2 = kx/2+ky*sqrt(3)/2
k3_dot_a3 = -kx/2+ky*sqrt(3)/2
h = np.zeros((3, 3), dtype=complex)
h[0, 1] = 2*cos(k1_dot_a1)
h[0, 2] = 2*cos(k2_dot_a2)
h[1, 2] = 2*cos(k3_dot_a3)
h = h + h.transpose().conj()
t = 1
h = -t*h
return h
def main():
kx_array = np.linspace(-pi ,pi, 500)
ky_array = np.linspace(-pi ,pi, 500)
eigenvalue_array = calculate_eigenvalue_with_two_parameters(kx_array, ky_array, hamiltonian)
plot_3d_surface(kx_array, ky_array, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', rcount=200, ccount=200)
# import guan
# eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(kx_array, ky_array, hamiltonian)
# guan.plot_3d_surface(kx_array, ky_array, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', rcount=200, ccount=200)
def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function, print_show=0, print_show_more=0):
dim_x = np.array(x_array).shape[0]
dim_y = np.array(y_array).shape[0]
if np.array(hamiltonian_function(0,0)).shape==():
eigenvalue_array = np.zeros((dim_y, dim_x, 1))
i0 = 0
for y0 in y_array:
j0 = 0
for x0 in x_array:
hamiltonian = hamiltonian_function(x0, y0)
eigenvalue_array[i0, j0, 0] = np.real(hamiltonian)
j0 += 1
i0 += 1
else:
dim = np.array(hamiltonian_function(0, 0)).shape[0]
eigenvalue_array = np.zeros((dim_y, dim_x, dim))
i0 = 0
for y0 in y_array:
j0 = 0
if print_show==1:
print(y0)
for x0 in x_array:
if print_show_more==1:
print(x0)
hamiltonian = hamiltonian_function(x0, y0)
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
eigenvalue_array[i0, j0, :] = eigenvalue
j0 += 1
i0 += 1
return eigenvalue_array
def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', fontsize=20, labelsize=15, show=1, save=0, filename='a', file_format='.jpg', dpi=300, z_min=None, z_max=None, rcount=100, ccount=100):
import matplotlib.pyplot as plt
from matplotlib import cm
from matplotlib.ticker import LinearLocator
matrix = np.array(matrix)
fig, ax = plt.subplots(subplot_kw={"projection": "3d"})
plt.subplots_adjust(bottom=0.1, right=0.65)
x_array, y_array = np.meshgrid(x_array, y_array)
if len(matrix.shape) == 2:
surf = ax.plot_surface(x_array, y_array, matrix, rcount=rcount, ccount=ccount, cmap=cm.coolwarm, linewidth=0, antialiased=False)
elif len(matrix.shape) == 3:
for i0 in range(matrix.shape[2]):
surf = ax.plot_surface(x_array, y_array, matrix[:,:,i0], rcount=rcount, ccount=ccount, cmap=cm.coolwarm, linewidth=0, antialiased=False)
ax.set_title(title, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_xlabel(xlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_ylabel(ylabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.set_zlabel(zlabel, fontsize=fontsize, fontfamily='Times New Roman')
ax.zaxis.set_major_locator(LinearLocator(5))
ax.zaxis.set_major_formatter('{x:.2f}')
if z_min!=None or z_max!=None:
if z_min==None:
z_min=matrix.min()
if z_max==None:
z_max=matrix.max()
ax.set_zlim(z_min, z_max)
ax.tick_params(labelsize=labelsize)
labels = ax.get_xticklabels() + ax.get_yticklabels() + ax.get_zticklabels()
[label.set_fontname('Times New Roman') for label in labels]
cax = plt.axes([0.8, 0.1, 0.05, 0.8])
cbar = fig.colorbar(surf, cax=cax)
cbar.ax.tick_params(labelsize=labelsize)
for l in cbar.ax.yaxis.get_ticklabels():
l.set_family('Times New Roman')
if save == 1:
plt.savefig(filename+file_format, dpi=dpi)
if show == 1:
plt.show()
plt.close('all')
if __name__ == '__main__':
main()

View File

@@ -0,0 +1,47 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/22691
"""
import guan
import numpy as np
import functools
# 2D Haldane lattice
k1_array = np.linspace(-2*np.pi, 2*np.pi, 100)
k2_array = np.linspace(-2*np.pi, 2*np.pi, 100)
eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(k1_array, k2_array, guan.hamiltonian_of_haldane_model)
guan.plot_3d_surface(k1_array, k2_array, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E')
# 2D Haldane lattice for discrete ky array
Ny = 5
ky_array = np.linspace(-np.pi, np.pi, Ny*4) # important
print(ky_array)
kx_array = np.linspace(-np.pi, np.pi, 100)
i0 = 0
for ky in ky_array:
hamiltonian_function = functools.partial(guan.hamiltonian_of_haldane_model, k2=ky)
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(-kx_array, hamiltonian_function)
if i0 == 0:
eigenvalue_array_for_discrete_ky = eigenvalue_array
else:
eigenvalue_array_for_discrete_ky = np.append(eigenvalue_array_for_discrete_ky, eigenvalue_array, axis=1)
i0 += 1
# 1D Haldane ribbon
hamiltonian_function = functools.partial(guan.hamiltonian_of_haldane_model_in_quasi_one_dimension, N=Ny)
eigenvalue_array_2 = guan.calculate_eigenvalue_with_one_parameter(kx_array, hamiltonian_function)
# 1D Haldane ribbon with periodic boundary condition in y direction
hamiltonian_function = functools.partial(guan.hamiltonian_of_haldane_model_in_quasi_one_dimension, N=Ny, period=1)
eigenvalue_array_3 = guan.calculate_eigenvalue_with_one_parameter(kx_array, hamiltonian_function)
# Plot figures
guan.plot_three_array(kx_array, eigenvalue_array_for_discrete_ky, eigenvalue_array_2, eigenvalue_array_3, xlabel='kx', ylabel='E', style_1='-k', style_2='--r', style_3='.y', linewidth_1=3, markersize_2=3, markersize_3=3)

View File

@@ -0,0 +1,46 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/22691
"""
import guan
import numpy as np
import functools
# 2D graphene lattice
k1_array = np.linspace(-2*np.pi, 2*np.pi, 300)
k2_array = np.linspace(-2*np.pi, 2*np.pi, 300)
eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(k1_array, k2_array, guan.hamiltonian_of_graphene)
guan.plot_3d_surface(k1_array, k2_array, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E', rcount=300, ccount=300)
# 2D graphene lattice for discrete ky array
Ny = 5
ky_array = np.linspace(-np.pi, np.pi, Ny*4) # important
print(ky_array)
kx_array = np.linspace(-np.pi, np.pi, 100)
i0 = 0
for ky in ky_array:
hamiltonian_function = functools.partial(guan.hamiltonian_of_graphene, k2=ky)
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(kx_array, hamiltonian_function)
if i0 == 0:
eigenvalue_array_for_discrete_ky = eigenvalue_array
else:
eigenvalue_array_for_discrete_ky = np.append(eigenvalue_array_for_discrete_ky, eigenvalue_array, axis=1)
i0 += 1
# 1D graphene ribbon
hamiltonian_function = functools.partial(guan.hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension, N=Ny)
eigenvalue_array_2 = guan.calculate_eigenvalue_with_one_parameter(kx_array, hamiltonian_function)
# 1D graphene ribbon with periodic boundary condition in y direction
hamiltonian_function = functools.partial(guan.hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension, N=Ny, period=1)
eigenvalue_array_3 = guan.calculate_eigenvalue_with_one_parameter(kx_array, hamiltonian_function)
# Plot figures
guan.plot_three_array(kx_array, eigenvalue_array_for_discrete_ky, eigenvalue_array_2, eigenvalue_array_3, xlabel='kx', ylabel='E', style_1='-k', style_2='--r', style_3='.y', linewidth_1=3, markersize_2=3, markersize_3=3)

View File

@@ -0,0 +1,47 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/22691
"""
import guan
import numpy as np
import functools
# 2D square lattice
k1_array = np.linspace(-np.pi, np.pi, 100)
k2_array = np.linspace(-np.pi, np.pi, 100)
eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(k1_array, k2_array, guan.hamiltonian_of_square_lattice)
guan.plot_3d_surface(k1_array, k2_array, eigenvalue_array, xlabel='kx', ylabel='ky', zlabel='E')
# 2D square lattice for discrete ky array
Ny = 10
ky_array = np.linspace(-np.pi, np.pi, Ny) # important
print(ky_array)
kx_array = np.linspace(-np.pi, np.pi, 100)
i0 = 0
for ky in ky_array:
hamiltonian_function = functools.partial(guan.hamiltonian_of_square_lattice, k2=ky)
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(kx_array, hamiltonian_function)
if i0 == 0:
eigenvalue_array_for_discrete_ky = eigenvalue_array
else:
eigenvalue_array_for_discrete_ky = np.append(eigenvalue_array_for_discrete_ky, eigenvalue_array, axis=1)
i0 += 1
# 1D square ribbon
hamiltonian_function = functools.partial(guan.hamiltonian_of_square_lattice_in_quasi_one_dimension, N=Ny)
eigenvalue_array_2 = guan.calculate_eigenvalue_with_one_parameter(kx_array, hamiltonian_function)
# 1D square ribbon with periodic boundary condition in y direction
hamiltonian_function = functools.partial(guan.hamiltonian_of_square_lattice_in_quasi_one_dimension, N=Ny, period=1)
eigenvalue_array_3 = guan.calculate_eigenvalue_with_one_parameter(kx_array, hamiltonian_function)
# Plot figures
guan.plot_three_array(kx_array, eigenvalue_array_for_discrete_ky, eigenvalue_array_2, eigenvalue_array_3, xlabel='kx', ylabel='E', style_1='-k', style_2='--r', style_3='.y', linewidth_1=3, markersize_2=1, markersize_3=1)

View File

@@ -0,0 +1,30 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/27656
"""
import guan
import numpy as np
# one dimensional chain model
unit_cell = 0
hopping = 1
hamiltonian_function = guan.one_dimensional_fourier_transform_with_k(unit_cell, hopping)
k_array = np.linspace(-np.pi, np.pi, 100)
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(k_array, hamiltonian_function)
guan.plot(k_array, eigenvalue_array, xlabel='k', ylabel='E', style='k', title='one dimensional chain model')
# n times band folding
max_n = 10
for n in np.arange(2, max_n+1):
unit_cell = np.zeros((n, n))
for i0 in range(int(n)):
for j0 in range(int(n)):
if abs(i0-j0)==1:
unit_cell[i0, j0] = 1
hopping = np.zeros((n, n))
hopping[0, n-1] = 1
hamiltonian_function = guan.one_dimensional_fourier_transform_with_k(unit_cell, hopping)
k_array = np.linspace(-np.pi, np.pi, 100)
eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(k_array, hamiltonian_function)
guan.plot(k_array, eigenvalue_array, xlabel='k', ylabel='E', style='k', title='%i times band folding'%n)

View File

@@ -0,0 +1,89 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/27605
"""
import guan
import numpy as np
# one dimensional chain model
unit_cell = 0
hopping = 1
hamiltonian_function_1 = guan.one_dimensional_fourier_transform_with_k(unit_cell, hopping)
k_array_1 = np.linspace(-np.pi, np.pi, 520)
eigenvalue_array_1 = guan.calculate_eigenvalue_with_one_parameter(k_array_1, hamiltonian_function_1)
# guan.plot(k_array_1, eigenvalue_array_1, xlabel='k', ylabel='E', style='k', title='one dimensional chain model')
# n times band folding
n = 7
unit_cell = np.zeros((n, n))
for i0 in range(int(n)):
for j0 in range(int(n)):
if abs(i0-j0)==1:
unit_cell[i0, j0] = 1
hopping = np.zeros((n, n))
hopping[0, n-1] = 1
k_array_2 = np.linspace(-np.pi, np.pi, 500)
hamiltonian_function_2 = guan.one_dimensional_fourier_transform_with_k(unit_cell, hopping)
eigenvalue_array_2 = guan.calculate_eigenvalue_with_one_parameter(k_array_2, hamiltonian_function_2)
# guan.plot(k_array_2, eigenvalue_array_2, xlabel='k', ylabel='E', style='k', title='%i times band folding'%n)
### 以下通过速度和能量查找能带折叠前后的对应关系
# 获取速度
velocity_array_1 = []
for i0 in range(k_array_1.shape[0]-1):
velocity_1 = (eigenvalue_array_1[i0+1]-eigenvalue_array_1[i0])/(k_array_1[i0+1]-k_array_1[i0])
velocity_array_1.append(velocity_1)
# 获取速度
velocity_array_2 = []
for i0 in range(k_array_2.shape[0]-1):
velocity_2 = (eigenvalue_array_2[i0+1]-eigenvalue_array_2[i0])/(k_array_2[i0+1]-k_array_2[i0])
velocity_array_2.append(velocity_2*n)
plt_1, fig_1, ax_1 = guan.import_plt_and_start_fig_ax()
plt_2, fig_2, ax_2 = guan.import_plt_and_start_fig_ax()
for i00 in range(n):
k_array_new_2 = []
k_array_new_1 = []
index_array_new_2 = []
index_array_new_1 = []
for i0 in range(k_array_2.shape[0]-1):
for j0 in range(k_array_1.shape[0]-1):
if abs(eigenvalue_array_2[i0][i00]-eigenvalue_array_1[j0])<1e-2 and abs(velocity_array_2[i0][i00]-velocity_array_1[j0])<1e-2:
k_array_new_2.append(k_array_2[i0])
k_array_new_1.append(k_array_1[j0])
index_array_new_2.append(i0)
index_array_new_1.append(j0)
if i00 == 0:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1], style='*r')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*r')
elif i00 == 1:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1], style='*b')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*b')
elif i00 == 2:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1], style='*g')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*g')
elif i00 == 3:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1], style='*c')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*c')
elif i00 == 4:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1], style='*m')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*m')
elif i00 == 5:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1], style='*y')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*y')
else:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1], style='*k')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*k')
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, [], [], xlabel='k', ylabel='E', title='one dimensional chain model')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, [], [], xlabel='k', ylabel='E', title='%i times band folding'%n)
plt_1.show()
plt_2.show()

View File

@@ -0,0 +1,96 @@
"""
This code is supported by the website: https://www.guanjihuan.com
The newest version of this code is on the web page: https://www.guanjihuan.com/archives/27605
"""
import guan
import numpy as np
# double chains model with different potentials
unit_cell = np.array([[0, 0], [0, 0.5]])
hopping = np.eye(2)
hamiltonian_function_1 = guan.one_dimensional_fourier_transform_with_k(unit_cell, hopping)
k_array_1 = np.linspace(-np.pi, np.pi, 600)
eigenvalue_array_1 = guan.calculate_eigenvalue_with_one_parameter(k_array_1, hamiltonian_function_1)
# guan.plot(k_array_1, eigenvalue_array_1, xlabel='k', ylabel='E', style='k', title='double chains model with different potentials')
# n times band folding
n = 2
unit_cell = np.zeros((2*n, 2*n))
for i0 in range(int(n)):
for j0 in range(int(n)):
if abs(i0-j0)==1:
unit_cell[i0, j0] = 1
for i0 in range(int(n)):
unit_cell[n+i0, n+i0] = 0.5
for j0 in range(int(n)):
if abs(i0-j0)==1:
unit_cell[n+i0, n+j0] = 1
hopping = np.zeros((2*n, 2*n))
hopping[0, n-1] = 1
hopping[n, 2*n-1] = 1
hamiltonian_function_2 = guan.one_dimensional_fourier_transform_with_k(unit_cell, hopping)
k_array_2 = np.linspace(-np.pi, np.pi, 620)
eigenvalue_array_2 = guan.calculate_eigenvalue_with_one_parameter(k_array_2, hamiltonian_function_2)
# guan.plot(k_array_2, eigenvalue_array_2, xlabel='k', ylabel='E', style='k', title='%i times band folding'%n)
### 以下通过速度和能量查找能带折叠前后的对应关系
# 获取速度
velocity_array_1 = []
for i0 in range(k_array_1.shape[0]-1):
velocity_1 = (eigenvalue_array_1[i0+1]-eigenvalue_array_1[i0])/(k_array_1[i0+1]-k_array_1[i0])
velocity_array_1.append(velocity_1)
# 获取速度
velocity_array_2 = []
for i0 in range(k_array_2.shape[0]-1):
velocity_2 = (eigenvalue_array_2[i0+1]-eigenvalue_array_2[i0])/(k_array_2[i0+1]-k_array_2[i0])
velocity_array_2.append(velocity_2*n)
dim = 2 # 维度为两倍
plt_1, fig_1, ax_1 = guan.import_plt_and_start_fig_ax()
plt_2, fig_2, ax_2 = guan.import_plt_and_start_fig_ax()
for j00 in range(dim):
for i00 in range(n*dim):
k_array_new_2 = []
k_array_new_1 = []
index_array_new_2 = []
index_array_new_1 = []
for i0 in range(k_array_2.shape[0]-1):
for j0 in range(k_array_1.shape[0]-1):
if abs(eigenvalue_array_2[i0][i00]-eigenvalue_array_1[j0][j00])<1e-2 and abs(velocity_array_2[i0][i00]-velocity_array_1[j0][j00])<1e-2:
k_array_new_2.append(k_array_2[i0])
k_array_new_1.append(k_array_1[j0])
index_array_new_2.append(i0)
index_array_new_1.append(j0)
if i00 == 0 and j00 == 0:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1, j00], style='*r')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*r')
elif i00 == 0 and j00 == 1:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1, j00], style='*b')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*b')
elif i00 == 1 and j00 == 0:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1, j00], style='*g')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*g')
elif i00 == 1 and j00 == 1:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1, j00], style='*c')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*c')
elif i00 == 2 and j00 == 0:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1, j00], style='*m')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*m')
elif i00 == 2 and j00 == 1:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1, j00], style='*y')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*y')
else:
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, k_array_new_1, eigenvalue_array_1[index_array_new_1, j00], style='*k')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, k_array_new_2, eigenvalue_array_2[index_array_new_2, i00], style='*k')
guan.plot_without_starting_fig(plt_1, fig_1, ax_1, [], [], xlabel='k', ylabel='E', title='double chains model with different potentials')
guan.plot_without_starting_fig(plt_2, fig_2, ax_2, [], [], xlabel='k', ylabel='E', title='%i times band folding'%n)
plt_1.show()
plt_2.show()