diff --git a/academic_codes/2021.01.07_Hofstadter_butterfly_in_square_lattice/Hofstadter_butterfly_in_square_lattice.py b/academic_codes/Landau_levels/2021.01.07_Hofstadter_butterfly_in_square_lattice/Hofstadter_butterfly_in_square_lattice.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2021.01.07_Hofstadter_butterfly_in_square_lattice/Hofstadter_butterfly_in_square_lattice.py rename to academic_codes/Landau_levels/2021.01.07_Hofstadter_butterfly_in_square_lattice/Hofstadter_butterfly_in_square_lattice.py index 8636517..1fba687 --- a/academic_codes/2021.01.07_Hofstadter_butterfly_in_square_lattice/Hofstadter_butterfly_in_square_lattice.py +++ b/academic_codes/Landau_levels/2021.01.07_Hofstadter_butterfly_in_square_lattice/Hofstadter_butterfly_in_square_lattice.py @@ -1,50 +1,50 @@ -""" -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/8491 -""" - -import numpy as np -import cmath -import matplotlib.pyplot as plt - - -def main(): - for n in np.arange(1, 11): - print('n=', n) - width = n - length = n - B_array = np.arange(0, 1, 0.001) - eigenvalue_all = np.zeros((B_array.shape[0], width*length)) - i0 = 0 - for B in B_array: - # print(B) - h = hamiltonian(width, length, B) - eigenvalue, eigenvector = np.linalg.eig(h) - eigenvalue_all[i0, :] = np.real(eigenvalue) - i0 += 1 - plt.plot(B_array, eigenvalue_all, '.r', markersize=0.5) - plt.title('width=length='+str(n)) - plt.xlabel('B*a^2/phi_0') - plt.ylabel('E') - plt.savefig('width=length='+str(n)+'.jpg', dpi=300) - plt.close('all') # 关闭所有plt,防止循环画图时占用内存 - # plt.show() - - -def hamiltonian(width, length, B): # 方格子哈密顿量 - h = np.zeros((width*length, width*length), dtype=complex) - # 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*cmath.exp(-2*np.pi*1j*B*y) - h[(x+1)*width+y, x*width+y] = 1*cmath.exp(2*np.pi*1j*B*y) - return h - - -if __name__ == "__main__": - main() +""" +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/8491 +""" + +import numpy as np +import cmath +import matplotlib.pyplot as plt + + +def main(): + for n in np.arange(1, 11): + print('n=', n) + width = n + length = n + B_array = np.arange(0, 1, 0.001) + eigenvalue_all = np.zeros((B_array.shape[0], width*length)) + i0 = 0 + for B in B_array: + # print(B) + h = hamiltonian(width, length, B) + eigenvalue, eigenvector = np.linalg.eig(h) + eigenvalue_all[i0, :] = np.real(eigenvalue) + i0 += 1 + plt.plot(B_array, eigenvalue_all, '.r', markersize=0.5) + plt.title('width=length='+str(n)) + plt.xlabel('B*a^2/phi_0') + plt.ylabel('E') + plt.savefig('width=length='+str(n)+'.jpg', dpi=300) + plt.close('all') # 关闭所有plt,防止循环画图时占用内存 + # plt.show() + + +def hamiltonian(width, length, B): # 方格子哈密顿量 + h = np.zeros((width*length, width*length), dtype=complex) + # 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*cmath.exp(-2*np.pi*1j*B*y) + h[(x+1)*width+y, x*width+y] = 1*cmath.exp(2*np.pi*1j*B*y) + return h + + +if __name__ == "__main__": + main() diff --git a/academic_codes/2021.04.24_Hofstadter_butterfly_of_graphene_ribbon/Hofstadter_butterfly_of_graphene_ribbon.py b/academic_codes/Landau_levels/2021.04.24_Hofstadter_butterfly_of_graphene_ribbon/Hofstadter_butterfly_of_graphene_ribbon.py similarity index 100% rename from academic_codes/2021.04.24_Hofstadter_butterfly_of_graphene_ribbon/Hofstadter_butterfly_of_graphene_ribbon.py rename to academic_codes/Landau_levels/2021.04.24_Hofstadter_butterfly_of_graphene_ribbon/Hofstadter_butterfly_of_graphene_ribbon.py diff --git a/academic_codes/2022.08.03_Landau_levels_of_honeycomb_lattice/Landau_levels_of_honeycomb_lattice.py b/academic_codes/Landau_levels/2022.08.03_Landau_levels_of_honeycomb_lattice/Landau_levels_of_honeycomb_lattice.py similarity index 100% rename from academic_codes/2022.08.03_Landau_levels_of_honeycomb_lattice/Landau_levels_of_honeycomb_lattice.py rename to academic_codes/Landau_levels/2022.08.03_Landau_levels_of_honeycomb_lattice/Landau_levels_of_honeycomb_lattice.py diff --git a/academic_codes/2019.11.02_numerically_verify_the_relation_between_eigenstates_and_DOS/numerically_verify_the_relation_between_eigenstates_and_DOS.py b/academic_codes/density_of_states/2019.11.02_numerically_verify_the_relation_between_eigenstates_and_DOS/numerically_verify_the_relation_between_eigenstates_and_DOS.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.02_numerically_verify_the_relation_between_eigenstates_and_DOS/numerically_verify_the_relation_between_eigenstates_and_DOS.py rename to academic_codes/density_of_states/2019.11.02_numerically_verify_the_relation_between_eigenstates_and_DOS/numerically_verify_the_relation_between_eigenstates_and_DOS.py index fc48384..1e13839 --- a/academic_codes/2019.11.02_numerically_verify_the_relation_between_eigenstates_and_DOS/numerically_verify_the_relation_between_eigenstates_and_DOS.py +++ b/academic_codes/density_of_states/2019.11.02_numerically_verify_the_relation_between_eigenstates_and_DOS/numerically_verify_the_relation_between_eigenstates_and_DOS.py @@ -1,43 +1,43 @@ -""" -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/962 -""" - -import numpy as np - - -def hamiltonian(width=2, length=4): # 有一定宽度和长度的方格子 - h00 = np.zeros((width*length, width*length)) - for i0 in range(length): - for j0 in range(width-1): - h00[i0*width+j0, i0*width+j0+1] = 1 - h00[i0*width+j0+1, i0*width+j0] = 1 - for i0 in range(length-1): - for j0 in range(width): - h00[i0*width+j0, (i0+1)*width+j0] = 1 - h00[(i0+1)*width+j0, i0*width+j0] = 1 - return h00 - - -def main(): - h0 = hamiltonian() - dim = h0.shape[0] - n = 4 # 选取第n个能级 - eigenvalue, eigenvector = np.linalg.eig(h0) # 本征值、本征矢 - # print(h0) - # print('哈密顿量的维度:', dim) # 哈密顿量的维度 - # print('本征矢的维度:', eigenvector.shape) # 本征矢的维度 - # print('能级(未排序):', eigenvalue) # 输出本征值。因为体系是受限的,所以是离散的能级 - # print('选取第', n, '个能级,为', eigenvalue[n-1]) # 从1开始算,查看第n个能级是什么(这里本征值未排序) - # print('第', n, '个能级对应的波函数:', eigenvector[:, n-1]) # 查看第n个能级对应的波函数 - print('\n波函数模的平方:\n', np.square(np.abs(eigenvector[:, n-1]))) # 查看第n个能级对应的波函数模的平方 - green = np.linalg.inv((eigenvalue[n-1]+1e-15j)*np.eye(dim)-h0) # 第n个能级对应的格林函数 - total = np.trace(np.imag(green)) # 求该能级格林函数的迹,对应的是总态密度(忽略符号和系数) - print('归一化后的态密度分布:') - for i in range(dim): - print(np.imag(green)[i, i]/total) # 第n个能级单位化后的态密度分布 - print('观察以上两个分布的数值情况,可以发现两者完全相同。') - - -if __name__ == '__main__': - main() +""" +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/962 +""" + +import numpy as np + + +def hamiltonian(width=2, length=4): # 有一定宽度和长度的方格子 + h00 = np.zeros((width*length, width*length)) + for i0 in range(length): + for j0 in range(width-1): + h00[i0*width+j0, i0*width+j0+1] = 1 + h00[i0*width+j0+1, i0*width+j0] = 1 + for i0 in range(length-1): + for j0 in range(width): + h00[i0*width+j0, (i0+1)*width+j0] = 1 + h00[(i0+1)*width+j0, i0*width+j0] = 1 + return h00 + + +def main(): + h0 = hamiltonian() + dim = h0.shape[0] + n = 4 # 选取第n个能级 + eigenvalue, eigenvector = np.linalg.eig(h0) # 本征值、本征矢 + # print(h0) + # print('哈密顿量的维度:', dim) # 哈密顿量的维度 + # print('本征矢的维度:', eigenvector.shape) # 本征矢的维度 + # print('能级(未排序):', eigenvalue) # 输出本征值。因为体系是受限的,所以是离散的能级 + # print('选取第', n, '个能级,为', eigenvalue[n-1]) # 从1开始算,查看第n个能级是什么(这里本征值未排序) + # print('第', n, '个能级对应的波函数:', eigenvector[:, n-1]) # 查看第n个能级对应的波函数 + print('\n波函数模的平方:\n', np.square(np.abs(eigenvector[:, n-1]))) # 查看第n个能级对应的波函数模的平方 + green = np.linalg.inv((eigenvalue[n-1]+1e-15j)*np.eye(dim)-h0) # 第n个能级对应的格林函数 + total = np.trace(np.imag(green)) # 求该能级格林函数的迹,对应的是总态密度(忽略符号和系数) + print('归一化后的态密度分布:') + for i in range(dim): + print(np.imag(green)[i, i]/total) # 第n个能级单位化后的态密度分布 + print('观察以上两个分布的数值情况,可以发现两者完全相同。') + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2019.12.30_calculation_of_spectral_function_and_QPI/calculation of spectral function and QPI.f90 b/academic_codes/density_of_states/2019.12.30_calculation_of_spectral_function_and_QPI/calculation of spectral function and QPI.f90 similarity index 100% rename from academic_codes/2019.12.30_calculation_of_spectral_function_and_QPI/calculation of spectral function and QPI.f90 rename to academic_codes/density_of_states/2019.12.30_calculation_of_spectral_function_and_QPI/calculation of spectral function and QPI.f90 diff --git a/academic_codes/2019.12.30_calculation_of_spectral_function_and_QPI/calculation of spectral function and QPI.py b/academic_codes/density_of_states/2019.12.30_calculation_of_spectral_function_and_QPI/calculation of spectral function and QPI.py similarity index 100% rename from academic_codes/2019.12.30_calculation_of_spectral_function_and_QPI/calculation of spectral function and QPI.py rename to academic_codes/density_of_states/2019.12.30_calculation_of_spectral_function_and_QPI/calculation of spectral function and QPI.py diff --git a/academic_codes/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_graphene.py b/academic_codes/density_of_states/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_graphene.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_graphene.py rename to academic_codes/density_of_states/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_graphene.py index 6686dcc..83f8627 --- a/academic_codes/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_graphene.py +++ b/academic_codes/density_of_states/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_graphene.py @@ -1,56 +1,56 @@ -""" -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/4622 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * -plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 -plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 - - -def hamiltonian(width=8, length=8): # 石墨烯格子的哈密顿量。这里width要求为4的倍数 - 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): - if np.mod(y, 4)==0: - h[x*width+y+1, (x+1)*width+y] = 1 - h[(x+1)*width+y, x*width+y+1] = 1 - - h[x*width+y+2, (x+1)*width+y+3] = 1 - h[(x+1)*width+y+3, x*width+y+2] = 1 - - return h - - -def main(): - plot_precision = 0.01 # 画图的精度 - Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组 - dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数 - total_DOS_array = np.zeros((dim_energy)) # 计算结果(总态密度total_DOS)放入该数组中 - h = hamiltonian() # 体系的哈密顿量 - dim = h.shape[0] # 哈密顿量的维度 - i0 = 0 - for Fermi_energy in Fermi_energy_array: - print(Fermi_energy) # 查看计算的进展情况 - green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数 - total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度 - total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度 - i0 += 1 - sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化 - plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像 - plt.xlabel('费米能') - plt.ylabel('总态密度') - plt.show() - - -if __name__ == '__main__': - main() +""" +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/4622 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * +plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 +plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 + + +def hamiltonian(width=8, length=8): # 石墨烯格子的哈密顿量。这里width要求为4的倍数 + 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): + if np.mod(y, 4)==0: + h[x*width+y+1, (x+1)*width+y] = 1 + h[(x+1)*width+y, x*width+y+1] = 1 + + h[x*width+y+2, (x+1)*width+y+3] = 1 + h[(x+1)*width+y+3, x*width+y+2] = 1 + + return h + + +def main(): + plot_precision = 0.01 # 画图的精度 + Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组 + dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数 + total_DOS_array = np.zeros((dim_energy)) # 计算结果(总态密度total_DOS)放入该数组中 + h = hamiltonian() # 体系的哈密顿量 + dim = h.shape[0] # 哈密顿量的维度 + i0 = 0 + for Fermi_energy in Fermi_energy_array: + print(Fermi_energy) # 查看计算的进展情况 + green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数 + total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度 + total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度 + i0 += 1 + sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化 + plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像 + plt.xlabel('费米能') + plt.ylabel('总态密度') + plt.show() + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_square_lattice.py b/academic_codes/density_of_states/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_square_lattice.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_square_lattice.py rename to academic_codes/density_of_states/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_square_lattice.py index 911a50b..03a5517 --- a/academic_codes/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_square_lattice.py +++ b/academic_codes/density_of_states/2020.06.16_total_DOS_as_a_function_of_Fermi_energy_in_square_lattice_and_graphene/total_DOS_as_a_function_of_Fermi_energy_in_square_lattice.py @@ -1,52 +1,52 @@ -""" -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/4622 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * -plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 -plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 - - -def hamiltonian(width=10, length=10): # 方格子哈密顿量 - 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 - - -def main(): - plot_precision = 0.01 # 画图的精度 - Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组 - dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数 - total_DOS_array = np.zeros((dim_energy)) # 计算结果(总态密度total_DOS)放入该数组中 - h = hamiltonian() # 体系的哈密顿量 - dim = h.shape[0] # 哈密顿量的维度 - i0 = 0 - for Fermi_energy in Fermi_energy_array: - print(Fermi_energy) # 查看计算的进展情况 - green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数 - total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度 - total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度 - i0 += 1 - sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化 - plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像 - plt.xlabel('费米能') - plt.ylabel('总态密度') - plt.show() - - -if __name__ == '__main__': - main() +""" +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/4622 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * +plt.rcParams['font.sans-serif']=['SimHei'] #用来正常显示中文标签 +plt.rcParams['axes.unicode_minus']=False #用来正常显示负号 + + +def hamiltonian(width=10, length=10): # 方格子哈密顿量 + 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 + + +def main(): + plot_precision = 0.01 # 画图的精度 + Fermi_energy_array = np.arange(-5, 5, plot_precision) # 计算中取的费米能Fermi_energy组成的数组 + dim_energy = Fermi_energy_array.shape[0] # 需要计算的费米能的个数 + total_DOS_array = np.zeros((dim_energy)) # 计算结果(总态密度total_DOS)放入该数组中 + h = hamiltonian() # 体系的哈密顿量 + dim = h.shape[0] # 哈密顿量的维度 + i0 = 0 + for Fermi_energy in Fermi_energy_array: + print(Fermi_energy) # 查看计算的进展情况 + green = np.linalg.inv((Fermi_energy+0.1j)*np.eye(dim)-h) # 体系的格林函数 + total_DOS = -np.trace(np.imag(green))/pi # 通过格林函数求得总态密度 + total_DOS_array[i0] = total_DOS # 记录每个Fermi_energy对应的总态密度 + i0 += 1 + sum_up = np.sum(total_DOS_array)*plot_precision # 用于图像归一化 + plt.plot(Fermi_energy_array, total_DOS_array/sum_up, '-') # 画DOS(E)图像 + plt.xlabel('费米能') + plt.ylabel('总态密度') + plt.show() + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.06.25_numerically_verify_Green_functions_in_Dyson_equations/numerically_verify_Green_functions_in_Dyson_equations.py b/academic_codes/density_of_states/2020.06.25_numerically_verify_Green_functions_in_Dyson_equations/numerically_verify_Green_functions_in_Dyson_equations.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.06.25_numerically_verify_Green_functions_in_Dyson_equations/numerically_verify_Green_functions_in_Dyson_equations.py rename to academic_codes/density_of_states/2020.06.25_numerically_verify_Green_functions_in_Dyson_equations/numerically_verify_Green_functions_in_Dyson_equations.py index 4121853..78bdf7d --- a/academic_codes/2020.06.25_numerically_verify_Green_functions_in_Dyson_equations/numerically_verify_Green_functions_in_Dyson_equations.py +++ b/academic_codes/density_of_states/2020.06.25_numerically_verify_Green_functions_in_Dyson_equations/numerically_verify_Green_functions_in_Dyson_equations.py @@ -1,84 +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/4396 -""" - -import numpy as np -import matplotlib.pyplot as plt -import copy -import time - - -def matrix_00(width): # 一个切片(slide)内的哈密顿量 - h00 = np.zeros((width, width)) - for width0 in range(width-1): - h00[width0, width0+1] = 1 - h00[width0+1, width0] = 1 - return h00 - - -def matrix_01(width): # 切片之间的跃迁项(hopping) - h01 = np.identity(width) - return h01 - - -def matrix_whole(width, length): # 方格子整体的哈密顿量,宽度为width,长度为length - hamiltonian = np.zeros((width*length, width*length)) - for x in range(length): - for y in range(width-1): - hamiltonian[x*width+y, x*width+y+1] = 1 - hamiltonian[x*width+y+1, x*width+y] = 1 - for x in range(length-1): - for y in range(width): - hamiltonian[x*width+y, (x+1)*width+y] = 1 - hamiltonian[(x+1)*width+y, x*width+y] = 1 - return hamiltonian - - -def main(): - width =4 # 方格子的宽度 - length = 200 # 方格子的长度 - h00 = matrix_00(width) # 一个切片(slide)内的哈密顿量 - h01 = matrix_01(width) # 切片之间的跃迁项(hopping) - hamiltonian = matrix_whole(width, length) # 方格子整体的哈密顿量,宽度为width,长度为length - fermi_energy = 0.1 # 费米能取为0.1为例。按理来说计算格林函数时,这里需要加上一个无穷小的虚数,但Python中好像不加也不会有什么问题。 - - start_1= time.perf_counter() - green = General_way(fermi_energy, hamiltonian) # 利用通常直接求逆的方法得到整体的格林函数green - end_1 = time.perf_counter() - start_2= time.perf_counter() - green_0n_n = Dyson_way(fermi_energy, h00, h01, length) # 利用Dyson方程得到的格林函数green_0n - end_2 = time.perf_counter() - - # print(green) - print('\n整体格林函数中的一个分块矩阵green_0n:\n', green[0:width, (length-1)*width+0:(length-1)*width+width]) # a:b代表 a <= x < b,左闭右开 - print('Dyson方程得到的格林函数green_0n:\n', green_0n_n) - print('观察以上两个矩阵,可以直接看出两个矩阵完全相同。\n') - - print('General_way执行时间=', end_1-start_1) - print('Dyson_way执行时间=', end_2-start_2) - - -def General_way(fermi_energy, hamiltonian): - dim_hamiltonian = hamiltonian.shape[0] - green = np.linalg.inv((fermi_energy)*np.eye(dim_hamiltonian)-hamiltonian) - return green - - -def Dyson_way(fermi_energy, h00, h01, length): - dim = h00.shape[0] - for ix in range(length): - if ix == 0: - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00) # 如果有左电极,还需要减去左电极的自能left_self_energy - green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于,两个变量会指向相同的id,改变一个值,另外一个值可能会发生改变,容易出错,所以要用上这个COPY - elif ix != length-1: - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) - green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) - else: # 这里和(elif ix != length-1)中的内容完全一样,但如果有右电极,这里是还需要减去右电极的自能right_self_energy - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) - green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) - return green_0n_n - - -if __name__ == '__main__': - main() +""" +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/4396 +""" + +import numpy as np +import matplotlib.pyplot as plt +import copy +import time + + +def matrix_00(width): # 一个切片(slide)内的哈密顿量 + h00 = np.zeros((width, width)) + for width0 in range(width-1): + h00[width0, width0+1] = 1 + h00[width0+1, width0] = 1 + return h00 + + +def matrix_01(width): # 切片之间的跃迁项(hopping) + h01 = np.identity(width) + return h01 + + +def matrix_whole(width, length): # 方格子整体的哈密顿量,宽度为width,长度为length + hamiltonian = np.zeros((width*length, width*length)) + for x in range(length): + for y in range(width-1): + hamiltonian[x*width+y, x*width+y+1] = 1 + hamiltonian[x*width+y+1, x*width+y] = 1 + for x in range(length-1): + for y in range(width): + hamiltonian[x*width+y, (x+1)*width+y] = 1 + hamiltonian[(x+1)*width+y, x*width+y] = 1 + return hamiltonian + + +def main(): + width =4 # 方格子的宽度 + length = 200 # 方格子的长度 + h00 = matrix_00(width) # 一个切片(slide)内的哈密顿量 + h01 = matrix_01(width) # 切片之间的跃迁项(hopping) + hamiltonian = matrix_whole(width, length) # 方格子整体的哈密顿量,宽度为width,长度为length + fermi_energy = 0.1 # 费米能取为0.1为例。按理来说计算格林函数时,这里需要加上一个无穷小的虚数,但Python中好像不加也不会有什么问题。 + + start_1= time.perf_counter() + green = General_way(fermi_energy, hamiltonian) # 利用通常直接求逆的方法得到整体的格林函数green + end_1 = time.perf_counter() + start_2= time.perf_counter() + green_0n_n = Dyson_way(fermi_energy, h00, h01, length) # 利用Dyson方程得到的格林函数green_0n + end_2 = time.perf_counter() + + # print(green) + print('\n整体格林函数中的一个分块矩阵green_0n:\n', green[0:width, (length-1)*width+0:(length-1)*width+width]) # a:b代表 a <= x < b,左闭右开 + print('Dyson方程得到的格林函数green_0n:\n', green_0n_n) + print('观察以上两个矩阵,可以直接看出两个矩阵完全相同。\n') + + print('General_way执行时间=', end_1-start_1) + print('Dyson_way执行时间=', end_2-start_2) + + +def General_way(fermi_energy, hamiltonian): + dim_hamiltonian = hamiltonian.shape[0] + green = np.linalg.inv((fermi_energy)*np.eye(dim_hamiltonian)-hamiltonian) + return green + + +def Dyson_way(fermi_energy, h00, h01, length): + dim = h00.shape[0] + for ix in range(length): + if ix == 0: + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00) # 如果有左电极,还需要减去左电极的自能left_self_energy + green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于,两个变量会指向相同的id,改变一个值,另外一个值可能会发生改变,容易出错,所以要用上这个COPY + elif ix != length-1: + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) + green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) + else: # 这里和(elif ix != length-1)中的内容完全一样,但如果有右电极,这里是还需要减去右电极的自能right_self_energy + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) + green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) + return green_0n_n + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice.py b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice.py rename to academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice.py index dfcdc87..6ea382e --- a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice.py +++ b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice.py @@ -1,102 +1,102 @@ -""" -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/7650 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * - - -def matrix_00(width, length): - h00 = np.zeros((width*length, width*length)) - for x in range(length): - for y in range(width-1): - h00[x*width+y, x*width+y+1] = 1 - h00[x*width+y+1, x*width+y] = 1 - for x in range(length-1): - for y in range(width): - h00[x*width+y, (x+1)*width+y] = 1 - h00[(x+1)*width+y, x*width+y] = 1 - return h00 - - -def matrix_01(width, length): - h01 = np.identity(width*length) - return h01 - - -def main(): - height = 2 # z - width = 3 # y - length = 4 # x - eta = 1e-2 - E = 0 - h00 = matrix_00(width, length) - h01 = matrix_01(width, length) - G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01) - for i0 in range(height): - print('z=', i0+1, ':') - for j0 in range(width): - print(' y=', j0+1, ':') - for k0 in range(length): - print(' x=', k0+1, ' ', -np.imag(G_ii_n_array[i0, k0*width+j0, k0*width+j0])/pi) # 态密度 - - -def G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01): - dim = length*width - G_ii_n_array = np.zeros((height, dim, dim), dtype=complex) - G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00) - for i in range(height): # i为格林函数的右下指标 - # 初始化开始 - G_nn_n_minus = G_11_1 - G_in_n_minus = G_11_1 - G_ni_n_minus = G_11_1 - G_ii_n_minus = G_11_1 - for i0 in range(i): - G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) - G_nn_n_minus = G_nn_n - if i!=0: - G_in_n_minus = G_nn_n - G_ni_n_minus = G_nn_n - G_ii_n_minus = G_nn_n - # 初始化结束 - for j0 in range(height-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)} - G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) - G_nn_n_minus = G_nn_n - - G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵 - G_ii_n_minus = G_ii_n - - G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n) - G_in_n_minus = G_in_n - - G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus) - G_ni_n_minus = G_ni_n - G_ii_n_array[i, :, :] = G_ii_n_minus - return G_ii_n_array - - -def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2 - dim = H00.shape[0] - G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V)) - return G_nn_n - - -def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2 - G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n) - return G_in_n - - -def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2 - G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus) - return G_ni_n - - -def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i - G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus) - return G_ii_n - - -if __name__ == '__main__': +""" +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/7650 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * + + +def matrix_00(width, length): + h00 = np.zeros((width*length, width*length)) + for x in range(length): + for y in range(width-1): + h00[x*width+y, x*width+y+1] = 1 + h00[x*width+y+1, x*width+y] = 1 + for x in range(length-1): + for y in range(width): + h00[x*width+y, (x+1)*width+y] = 1 + h00[(x+1)*width+y, x*width+y] = 1 + return h00 + + +def matrix_01(width, length): + h01 = np.identity(width*length) + return h01 + + +def main(): + height = 2 # z + width = 3 # y + length = 4 # x + eta = 1e-2 + E = 0 + h00 = matrix_00(width, length) + h01 = matrix_01(width, length) + G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01) + for i0 in range(height): + print('z=', i0+1, ':') + for j0 in range(width): + print(' y=', j0+1, ':') + for k0 in range(length): + print(' x=', k0+1, ' ', -np.imag(G_ii_n_array[i0, k0*width+j0, k0*width+j0])/pi) # 态密度 + + +def G_ii_n_with_Dyson_equation(width, length, height, E, eta, h00, h01): + dim = length*width + G_ii_n_array = np.zeros((height, dim, dim), dtype=complex) + G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00) + for i in range(height): # i为格林函数的右下指标 + # 初始化开始 + G_nn_n_minus = G_11_1 + G_in_n_minus = G_11_1 + G_ni_n_minus = G_11_1 + G_ii_n_minus = G_11_1 + for i0 in range(i): + G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) + G_nn_n_minus = G_nn_n + if i!=0: + G_in_n_minus = G_nn_n + G_ni_n_minus = G_nn_n + G_ii_n_minus = G_nn_n + # 初始化结束 + for j0 in range(height-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)} + G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) + G_nn_n_minus = G_nn_n + + G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵 + G_ii_n_minus = G_ii_n + + G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n) + G_in_n_minus = G_in_n + + G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus) + G_ni_n_minus = G_ni_n + G_ii_n_array[i, :, :] = G_ii_n_minus + return G_ii_n_array + + +def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2 + dim = H00.shape[0] + G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V)) + return G_nn_n + + +def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2 + G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n) + return G_in_n + + +def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2 + G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus) + return G_ni_n + + +def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i + G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus) + return G_ii_n + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice_version_II.py b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice_version_II.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice_version_II.py rename to academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice_version_II.py index 964cb75..dc451ef --- a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice_version_II.py +++ b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/DOS_calculation_using_Dyson_equations_in_cubic_lattice_version_II.py @@ -1,99 +1,99 @@ -""" -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/7650 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * - - -def matrix_00(width, length): - h00 = np.zeros((width*length, width*length)) - for x in range(length): - for y in range(width-1): - h00[x*width+y, x*width+y+1] = 1 - h00[x*width+y+1, x*width+y] = 1 - for x in range(length-1): - for y in range(width): - h00[x*width+y, (x+1)*width+y] = 1 - h00[(x+1)*width+y, x*width+y] = 1 - return h00 - - -def matrix_01(width, length): - h01 = np.identity(width*length) - return h01 - - -def main(): - height = 2 # z - width = 3 # y - length = 4 # x - eta = 1e-2 - E = 0 - h00 = matrix_00(width, length) - h01 = matrix_01(width, length) - G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01) - - -def G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01): - dim = length*width - G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00) - for i in range(height): # i为格林函数的右下指标 - # 初始化开始 - G_nn_n_minus = G_11_1 - G_in_n_minus = G_11_1 - G_ni_n_minus = G_11_1 - G_ii_n_minus = G_11_1 - for i0 in range(i): - G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) - G_nn_n_minus = G_nn_n - if i!=0: - G_in_n_minus = G_nn_n - G_ni_n_minus = G_nn_n - G_ii_n_minus = G_nn_n - # 初始化结束 - for j0 in range(height-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)} - G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) - G_nn_n_minus = G_nn_n - - G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵 - G_ii_n_minus = G_ii_n - - G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n) - G_in_n_minus = G_in_n - - G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus) - G_ni_n_minus = G_ni_n - # 输出 - print('z=', i+1, ':') - for j0 in range(width): - print(' y=', j0+1, ':') - for k0 in range(length): - print(' x=', k0+1, ' ', -np.imag(G_ii_n_minus[k0*width+j0, k0*width+j0])/pi) # 态密度 - - -def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2 - dim = H00.shape[0] - G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V)) - return G_nn_n - - -def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2 - G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n) - return G_in_n - - -def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2 - G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus) - return G_ni_n - - -def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i - G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus) - return G_ii_n - - -if __name__ == '__main__': +""" +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/7650 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * + + +def matrix_00(width, length): + h00 = np.zeros((width*length, width*length)) + for x in range(length): + for y in range(width-1): + h00[x*width+y, x*width+y+1] = 1 + h00[x*width+y+1, x*width+y] = 1 + for x in range(length-1): + for y in range(width): + h00[x*width+y, (x+1)*width+y] = 1 + h00[(x+1)*width+y, x*width+y] = 1 + return h00 + + +def matrix_01(width, length): + h01 = np.identity(width*length) + return h01 + + +def main(): + height = 2 # z + width = 3 # y + length = 4 # x + eta = 1e-2 + E = 0 + h00 = matrix_00(width, length) + h01 = matrix_01(width, length) + G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01) + + +def G_ii_n_with_Dyson_equation_version_II(width, length, height, E, eta, h00, h01): + dim = length*width + G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(dim)-h00) + for i in range(height): # i为格林函数的右下指标 + # 初始化开始 + G_nn_n_minus = G_11_1 + G_in_n_minus = G_11_1 + G_ni_n_minus = G_11_1 + G_ii_n_minus = G_11_1 + for i0 in range(i): + G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) + G_nn_n_minus = G_nn_n + if i!=0: + G_in_n_minus = G_nn_n + G_ni_n_minus = G_nn_n + G_ii_n_minus = G_nn_n + # 初始化结束 + for j0 in range(height-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)} + G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) + G_nn_n_minus = G_nn_n + + G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵 + G_ii_n_minus = G_ii_n + + G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n) + G_in_n_minus = G_in_n + + G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus) + G_ni_n_minus = G_ni_n + # 输出 + print('z=', i+1, ':') + for j0 in range(width): + print(' y=', j0+1, ':') + for k0 in range(length): + print(' x=', k0+1, ' ', -np.imag(G_ii_n_minus[k0*width+j0, k0*width+j0])/pi) # 态密度 + + +def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2 + dim = H00.shape[0] + G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V)) + return G_nn_n + + +def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2 + G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n) + return G_in_n + + +def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2 + G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus) + return G_ni_n + + +def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i + G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus) + return G_ii_n + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_cubic_lattice.py b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_cubic_lattice.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_cubic_lattice.py rename to academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_cubic_lattice.py index 25acba5..652ee6e --- a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_cubic_lattice.py +++ b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/cubic_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_cubic_lattice.py @@ -1,49 +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/7650 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * - - -def hamiltonian(width, length, height): - h = np.zeros((width*length*height, width*length*height)) - for i0 in range(length): - for j0 in range(width): - for k0 in range(height-1): - h[k0*width*length+i0*width+j0, (k0+1)*width*length+i0*width+j0] = 1 - h[(k0+1)*width*length+i0*width+j0, k0*width*length+i0*width+j0] = 1 - for i0 in range(length): - for j0 in range(width-1): - for k0 in range(height): - h[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0+1] = 1 - h[k0*width*length+i0*width+j0+1, k0*width*length+i0*width+j0] = 1 - for i0 in range(length-1): - for j0 in range(width): - for k0 in range(height): - h[k0*width*length+i0*width+j0, k0*width*length+(i0+1)*width+j0] = 1 - h[k0*width*length+(i0+1)*width+j0, k0*width*length+i0*width+j0] = 1 - return h - - -def main(): - height = 2 # z - width = 3 # y - length = 4 # x - h = hamiltonian(width, length, height) - E = 0 - green = np.linalg.inv((E+1e-2j)*np.eye(width*length*height)-h) - for k0 in range(height): - print('z=', k0+1, ':') - for j0 in range(width): - print(' y=', j0+1, ':') - for i0 in range(length): - print(' x=', i0+1, ' ', -np.imag(green[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0])/pi) # 态密度 - - -if __name__ == "__main__": - main() - +""" +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/7650 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * + + +def hamiltonian(width, length, height): + h = np.zeros((width*length*height, width*length*height)) + for i0 in range(length): + for j0 in range(width): + for k0 in range(height-1): + h[k0*width*length+i0*width+j0, (k0+1)*width*length+i0*width+j0] = 1 + h[(k0+1)*width*length+i0*width+j0, k0*width*length+i0*width+j0] = 1 + for i0 in range(length): + for j0 in range(width-1): + for k0 in range(height): + h[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0+1] = 1 + h[k0*width*length+i0*width+j0+1, k0*width*length+i0*width+j0] = 1 + for i0 in range(length-1): + for j0 in range(width): + for k0 in range(height): + h[k0*width*length+i0*width+j0, k0*width*length+(i0+1)*width+j0] = 1 + h[k0*width*length+(i0+1)*width+j0, k0*width*length+i0*width+j0] = 1 + return h + + +def main(): + height = 2 # z + width = 3 # y + length = 4 # x + h = hamiltonian(width, length, height) + E = 0 + green = np.linalg.inv((E+1e-2j)*np.eye(width*length*height)-h) + for k0 in range(height): + print('z=', k0+1, ':') + for j0 in range(width): + print(' y=', j0+1, ':') + for i0 in range(length): + print(' x=', i0+1, ' ', -np.imag(green[k0*width*length+i0*width+j0, k0*width*length+i0*width+j0])/pi) # 态密度 + + +if __name__ == "__main__": + main() + \ No newline at end of file diff --git a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/DOS_calculation_using_Dyson_equations_in_square_lattice.py b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/DOS_calculation_using_Dyson_equations_in_square_lattice.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/DOS_calculation_using_Dyson_equations_in_square_lattice.py rename to academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/DOS_calculation_using_Dyson_equations_in_square_lattice.py index 9eeee35..03dbc45 --- a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/DOS_calculation_using_Dyson_equations_in_square_lattice.py +++ b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/DOS_calculation_using_Dyson_equations_in_square_lattice.py @@ -1,95 +1,95 @@ -""" -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/7650 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * - - -def matrix_00(width): - h00 = np.zeros((width, width)) - for width0 in range(width-1): - h00[width0, width0+1] = 1 - h00[width0+1, width0] = 1 - return h00 - - -def matrix_01(width): - h01 = np.identity(width) - return h01 - - -def main(): - width = 2 - length = 3 - eta = 1e-2 - E = 0 - h00 = matrix_00(width) - h01 = matrix_01(width) - G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01) - for i0 in range(length): - # print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:') - # print(G_ii_n_array[i0, :, :],'\n') - print('x=', i0+1, ':') - for j0 in range(width): - print(' y=', j0+1, ' ', -np.imag(G_ii_n_array[i0, j0, j0])/pi) # 态密度 - - -def G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01): - G_ii_n_array = np.zeros((length, width, width), complex) - G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(width)-h00) - for i in range(length): # i为格林函数的右下指标 - # 初始化开始 - G_nn_n_minus = G_11_1 - G_in_n_minus = G_11_1 - G_ni_n_minus = G_11_1 - G_ii_n_minus = G_11_1 - for i0 in range(i): - G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) - G_nn_n_minus = G_nn_n - if i!=0: - G_in_n_minus = G_nn_n - G_ni_n_minus = G_nn_n - G_ii_n_minus = G_nn_n - # 初始化结束 - for j0 in range(length-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)} - G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) - G_nn_n_minus = G_nn_n - - G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵 - G_ii_n_minus = G_ii_n - - G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n) - G_in_n_minus = G_in_n - - G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus) - G_ni_n_minus = G_ni_n - G_ii_n_array[i, :, :] = G_ii_n_minus - return G_ii_n_array - - -def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2 - dim = H00.shape[0] - G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V)) - return G_nn_n - - -def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2 - G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n) - return G_in_n - - -def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2 - G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus) - return G_ni_n - - -def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i - G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus) - return G_ii_n - - -if __name__ == '__main__': - main() +""" +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/7650 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * + + +def matrix_00(width): + h00 = np.zeros((width, width)) + for width0 in range(width-1): + h00[width0, width0+1] = 1 + h00[width0+1, width0] = 1 + return h00 + + +def matrix_01(width): + h01 = np.identity(width) + return h01 + + +def main(): + width = 2 + length = 3 + eta = 1e-2 + E = 0 + h00 = matrix_00(width) + h01 = matrix_01(width) + G_ii_n_array = G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01) + for i0 in range(length): + # print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:') + # print(G_ii_n_array[i0, :, :],'\n') + print('x=', i0+1, ':') + for j0 in range(width): + print(' y=', j0+1, ' ', -np.imag(G_ii_n_array[i0, j0, j0])/pi) # 态密度 + + +def G_ii_n_with_Dyson_equation(width, length, E, eta, h00, h01): + G_ii_n_array = np.zeros((length, width, width), complex) + G_11_1 = np.linalg.inv((E+eta*1j)*np.identity(width)-h00) + for i in range(length): # i为格林函数的右下指标 + # 初始化开始 + G_nn_n_minus = G_11_1 + G_in_n_minus = G_11_1 + G_ni_n_minus = G_11_1 + G_ii_n_minus = G_11_1 + for i0 in range(i): + G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) + G_nn_n_minus = G_nn_n + if i!=0: + G_in_n_minus = G_nn_n + G_ni_n_minus = G_nn_n + G_ii_n_minus = G_nn_n + # 初始化结束 + for j0 in range(length-1-i): # j0为格林函数的右上指标,表示当前体系大小,即G^{(j0)} + G_nn_n = Green_nn_n(E, eta, h00, h01, G_nn_n_minus) + G_nn_n_minus = G_nn_n + + G_ii_n = Green_ii_n(G_ii_n_minus, G_in_n_minus, h01, G_nn_n, G_ni_n_minus) # 需要求的对角分块矩阵 + G_ii_n_minus = G_ii_n + + G_in_n = Green_in_n(G_in_n_minus, h01, G_nn_n) + G_in_n_minus = G_in_n + + G_ni_n = Green_ni_n(G_nn_n, h01, G_ni_n_minus) + G_ni_n_minus = G_ni_n + G_ii_n_array[i, :, :] = G_ii_n_minus + return G_ii_n_array + + +def Green_nn_n(E, eta, H00, V, G_nn_n_minus): # n>=2 + dim = H00.shape[0] + G_nn_n = np.linalg.inv((E+eta*1j)*np.identity(dim)-H00-np.dot(np.dot(V.transpose().conj(), G_nn_n_minus), V)) + return G_nn_n + + +def Green_in_n(G_in_n_minus, V, G_nn_n): # n>=2 + G_in_n = np.dot(np.dot(G_in_n_minus, V), G_nn_n) + return G_in_n + + +def Green_ni_n(G_nn_n, V, G_ni_n_minus): # n>=2 + G_ni_n = np.dot(np.dot(G_nn_n, V.transpose().conj()), G_ni_n_minus) + return G_ni_n + + +def Green_ii_n(G_ii_n_minus, G_in_n_minus, V, G_nn_n, G_ni_n_minus): # n>=i + G_ii_n = G_ii_n_minus+np.dot(np.dot(np.dot(np.dot(G_in_n_minus, V), G_nn_n), V.transpose().conj()),G_ni_n_minus) + return G_ii_n + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_square_lattice.py b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_square_lattice.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_square_lattice.py rename to academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_square_lattice.py index 185bc4a..b14e74c --- a/academic_codes/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_square_lattice.py +++ b/academic_codes/density_of_states/2020.12.31_DOS_calculation_using_Dyson_equations/square_lattice/get_DOS_by_direct_inverseion_of_Hamiltonian_of_square_lattice.py @@ -1,41 +1,41 @@ -""" -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/7650 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * - - -def hamiltonian(width, length): - h = np.zeros((width*length, width*length)) - for i0 in range(length): - for j0 in range(width-1): - h[i0*width+j0, i0*width+j0+1] = 1 - h[i0*width+j0+1, i0*width+j0] = 1 - for i0 in range(length-1): - for j0 in range(width): - h[i0*width+j0, (i0+1)*width+j0] = 1 - h[(i0+1)*width+j0, i0*width+j0] = 1 - return h - - -def main(): - width = 2 - length = 3 - h = hamiltonian(width, length) - E = 0 - green = np.linalg.inv((E+1e-2j)*np.eye(width*length)-h) - for i0 in range(length): - # print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:') - # print(green[i0*width+0: i0*width+width, i0*width+0: i0*width+width], '\n') - print('x=', i0+1, ':') - for j0 in range(width): - print(' y=', j0+1, ' ', -np.imag(green[i0*width+j0, i0*width+j0])/pi) - - -if __name__ == "__main__": - main() - +""" +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/7650 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * + + +def hamiltonian(width, length): + h = np.zeros((width*length, width*length)) + for i0 in range(length): + for j0 in range(width-1): + h[i0*width+j0, i0*width+j0+1] = 1 + h[i0*width+j0+1, i0*width+j0] = 1 + for i0 in range(length-1): + for j0 in range(width): + h[i0*width+j0, (i0+1)*width+j0] = 1 + h[(i0+1)*width+j0, i0*width+j0] = 1 + return h + + +def main(): + width = 2 + length = 3 + h = hamiltonian(width, length) + E = 0 + green = np.linalg.inv((E+1e-2j)*np.eye(width*length)-h) + for i0 in range(length): + # print('G_{'+str(i0+1)+','+str(i0+1)+'}^{('+str(length)+')}:') + # print(green[i0*width+0: i0*width+width, i0*width+0: i0*width+width], '\n') + print('x=', i0+1, ':') + for j0 in range(width): + print(' y=', j0+1, ' ', -np.imag(green[i0*width+j0, i0*width+j0])/pi) + + +if __name__ == "__main__": + main() + \ No newline at end of file diff --git a/academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/1D_graphene.py b/academic_codes/models_and_bands/2019.10.23_Hamiltonian_and_bands_of_graphene/1D_graphene.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/1D_graphene.py rename to academic_codes/models_and_bands/2019.10.23_Hamiltonian_and_bands_of_graphene/1D_graphene.py index 2faafb8..31f2e52 --- a/academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/1D_graphene.py +++ b/academic_codes/models_and_bands/2019.10.23_Hamiltonian_and_bands_of_graphene/1D_graphene.py @@ -1,69 +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() +""" +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() diff --git a/academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/2D_graphene.py b/academic_codes/models_and_bands/2019.10.23_Hamiltonian_and_bands_of_graphene/2D_graphene.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/2D_graphene.py rename to academic_codes/models_and_bands/2019.10.23_Hamiltonian_and_bands_of_graphene/2D_graphene.py index a68736a..570d7fc --- a/academic_codes/2019.10.23_Hamiltonian_and_bands_of_graphene/2D_graphene.py +++ b/academic_codes/models_and_bands/2019.10.23_Hamiltonian_and_bands_of_graphene/2D_graphene.py @@ -1,65 +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() +""" +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() diff --git a/academic_codes/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/1D_Haldane_model.py b/academic_codes/models_and_bands/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/1D_Haldane_model.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/1D_Haldane_model.py rename to academic_codes/models_and_bands/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/1D_Haldane_model.py index a75a020..2e8cf3e --- a/academic_codes/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/1D_Haldane_model.py +++ b/academic_codes/models_and_bands/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/1D_Haldane_model.py @@ -1,94 +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() +""" +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() diff --git a/academic_codes/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/2D_Haldane_model.py b/academic_codes/models_and_bands/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/2D_Haldane_model.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/2D_Haldane_model.py rename to academic_codes/models_and_bands/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/2D_Haldane_model.py index 632278c..755ffa2 --- a/academic_codes/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/2D_Haldane_model.py +++ b/academic_codes/models_and_bands/2019.10.24_Halmiltonian_and_bands_of_Haldane_model/2D_Haldane_model.py @@ -1,70 +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() +""" +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() diff --git a/academic_codes/2019.11.27_Hamiltonian_of_BHZ_model_and_bands_in_quasi_1D_systems/bands_in_quasi_1D_BHZ_systems.py b/academic_codes/models_and_bands/2019.11.27_Hamiltonian_of_BHZ_model_and_bands_in_quasi_1D_systems/bands_in_quasi_1D_BHZ_systems.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.27_Hamiltonian_of_BHZ_model_and_bands_in_quasi_1D_systems/bands_in_quasi_1D_BHZ_systems.py rename to academic_codes/models_and_bands/2019.11.27_Hamiltonian_of_BHZ_model_and_bands_in_quasi_1D_systems/bands_in_quasi_1D_BHZ_systems.py index 720b51d..9cae6bf --- a/academic_codes/2019.11.27_Hamiltonian_of_BHZ_model_and_bands_in_quasi_1D_systems/bands_in_quasi_1D_BHZ_systems.py +++ b/academic_codes/models_and_bands/2019.11.27_Hamiltonian_of_BHZ_model_and_bands_in_quasi_1D_systems/bands_in_quasi_1D_BHZ_systems.py @@ -1,84 +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() +""" +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() diff --git a/academic_codes/2020.01.03_bands_of_qusi_1D_square_lattice/bands_of_qusi_1D_square_lattice.py b/academic_codes/models_and_bands/2020.01.03_bands_of_qusi_1D_square_lattice/bands_of_qusi_1D_square_lattice.py similarity index 100% rename from academic_codes/2020.01.03_bands_of_qusi_1D_square_lattice/bands_of_qusi_1D_square_lattice.py rename to academic_codes/models_and_bands/2020.01.03_bands_of_qusi_1D_square_lattice/bands_of_qusi_1D_square_lattice.py diff --git a/academic_codes/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_1.py b/academic_codes/models_and_bands/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_1.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_1.py rename to academic_codes/models_and_bands/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_1.py index a655c58..a10c630 --- a/academic_codes/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_1.py +++ b/academic_codes/models_and_bands/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_1.py @@ -1,69 +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() +""" +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() diff --git a/academic_codes/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_2.py b/academic_codes/models_and_bands/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_2.py old mode 100755 new mode 100644 similarity index 95% rename from academic_codes/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_2.py rename to academic_codes/models_and_bands/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_2.py index c9f1b71..f0ff69e --- a/academic_codes/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_2.py +++ b/academic_codes/models_and_bands/2020.03.25_Hamiltonian_and_bands_of_bilayer_graphene/bands_of_bilayer_graphene_with_label_sequence_2.py @@ -1,83 +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() +""" +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() diff --git a/academic_codes/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/Kane_Mele_model.m b/academic_codes/models_and_bands/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/Kane_Mele_model.m similarity index 100% rename from academic_codes/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/Kane_Mele_model.m rename to academic_codes/models_and_bands/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/Kane_Mele_model.m diff --git a/academic_codes/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/bands_of_quasi_1D_Kane_Mele_model_without considering_Rashba_SOC.py b/academic_codes/models_and_bands/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/bands_of_quasi_1D_Kane_Mele_model_without considering_Rashba_SOC.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/bands_of_quasi_1D_Kane_Mele_model_without considering_Rashba_SOC.py rename to academic_codes/models_and_bands/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/bands_of_quasi_1D_Kane_Mele_model_without considering_Rashba_SOC.py index 062e399..1db3edd --- a/academic_codes/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/bands_of_quasi_1D_Kane_Mele_model_without considering_Rashba_SOC.py +++ b/academic_codes/models_and_bands/2020.06.26_Hamiltonian_and_bands_of_Kane_Mele_model_without considering_Rashba_SOC/bands_of_quasi_1D_Kane_Mele_model_without considering_Rashba_SOC.py @@ -1,104 +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() +""" +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() diff --git a/academic_codes/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_direct_assigning.py b/academic_codes/models_and_bands/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_direct_assigning.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_direct_assigning.py rename to academic_codes/models_and_bands/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_direct_assigning.py index 88ce253..8b5b3e2 --- a/academic_codes/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_direct_assigning.py +++ b/academic_codes/models_and_bands/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_direct_assigning.py @@ -1,23 +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() +""" +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) \ No newline at end of file diff --git a/academic_codes/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_tensor_product.py b/academic_codes/models_and_bands/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_tensor_product.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_tensor_product.py rename to academic_codes/models_and_bands/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_tensor_product.py index 43b72cd..5780f4a --- a/academic_codes/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_tensor_product.py +++ b/academic_codes/models_and_bands/2020.08.10_Hamiltonian_form_of_square_lattice_in_real_space/form_of_tensor_product.py @@ -1,21 +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() +""" +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) \ No newline at end of file diff --git a/academic_codes/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/Fermi_arc_in_Weyl_semimetals.py b/academic_codes/models_and_bands/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/Fermi_arc_in_Weyl_semimetals.py old mode 100755 new mode 100644 similarity index 95% rename from academic_codes/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/Fermi_arc_in_Weyl_semimetals.py rename to academic_codes/models_and_bands/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/Fermi_arc_in_Weyl_semimetals.py index 8ee5b9e..08327a3 --- a/academic_codes/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/Fermi_arc_in_Weyl_semimetals.py +++ b/academic_codes/models_and_bands/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/Fermi_arc_in_Weyl_semimetals.py @@ -1,64 +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__': +""" +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() \ No newline at end of file diff --git a/academic_codes/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/bands_of_Weyl_semimetals.py b/academic_codes/models_and_bands/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/bands_of_Weyl_semimetals.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/bands_of_Weyl_semimetals.py rename to academic_codes/models_and_bands/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/bands_of_Weyl_semimetals.py index 8ac9553..a30a4f7 --- a/academic_codes/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/bands_of_Weyl_semimetals.py +++ b/academic_codes/models_and_bands/2020.09.29_Halmiltonian_and_Fermi_arc_in_Weyl_semimetals/bands_of_Weyl_semimetals.py @@ -1,67 +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__': +""" +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() \ No newline at end of file diff --git a/academic_codes/2020.09.30_bandstructure_of_graphene_on_high_symmetric_axes/bandstructure_of_graphene_on_high_symmetric_axes.py b/academic_codes/models_and_bands/2020.09.30_bandstructure_of_graphene_on_high_symmetric_axes/bandstructure_of_graphene_on_high_symmetric_axes.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.09.30_bandstructure_of_graphene_on_high_symmetric_axes/bandstructure_of_graphene_on_high_symmetric_axes.py rename to academic_codes/models_and_bands/2020.09.30_bandstructure_of_graphene_on_high_symmetric_axes/bandstructure_of_graphene_on_high_symmetric_axes.py index ee20732..a7c20c4 --- a/academic_codes/2020.09.30_bandstructure_of_graphene_on_high_symmetric_axes/bandstructure_of_graphene_on_high_symmetric_axes.py +++ b/academic_codes/models_and_bands/2020.09.30_bandstructure_of_graphene_on_high_symmetric_axes/bandstructure_of_graphene_on_high_symmetric_axes.py @@ -1,77 +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-Gamma,Gamma-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() +""" +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-Gamma,Gamma-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() diff --git a/academic_codes/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator.py b/academic_codes/models_and_bands/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator.py rename to academic_codes/models_and_bands/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator.py index daa5742..c048b7c --- a/academic_codes/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator.py +++ b/academic_codes/models_and_bands/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator.py @@ -1,100 +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__': +""" +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() \ No newline at end of file diff --git a/academic_codes/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator_plotting_3D_surface.py b/academic_codes/models_and_bands/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator_plotting_3D_surface.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator_plotting_3D_surface.py rename to academic_codes/models_and_bands/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator_plotting_3D_surface.py index f49b51a..b7f378c --- a/academic_codes/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator_plotting_3D_surface.py +++ b/academic_codes/models_and_bands/2021.01.23_BBH_model_of_high_order_topological_insulator/BBH_model_of_high_order_topological_insulator_plotting_3D_surface.py @@ -1,100 +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__': +""" +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() \ No newline at end of file diff --git a/academic_codes/2021.03.08_eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices/eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices.nb b/academic_codes/models_and_bands/2021.03.08_eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices/eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices.nb old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2021.03.08_eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices/eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices.nb rename to academic_codes/models_and_bands/2021.03.08_eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices/eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices.nb index 05acd1b..fc18a1d --- a/academic_codes/2021.03.08_eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices/eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices.nb +++ b/academic_codes/models_and_bands/2021.03.08_eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices/eigenvalues_of_the_Hamiltonian_composed_of_Pauli_matrices.nb @@ -1,81 +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 *) - +(* 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 *) + diff --git a/academic_codes/2021.03.10_bands_of_type_II_Weyl_semimetals/bands_of_type_II_Weyl_semimetals.py b/academic_codes/models_and_bands/2021.03.10_bands_of_type_II_Weyl_semimetals/bands_of_type_II_Weyl_semimetals.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.10_bands_of_type_II_Weyl_semimetals/bands_of_type_II_Weyl_semimetals.py rename to academic_codes/models_and_bands/2021.03.10_bands_of_type_II_Weyl_semimetals/bands_of_type_II_Weyl_semimetals.py index a114181..1c4e115 --- a/academic_codes/2021.03.10_bands_of_type_II_Weyl_semimetals/bands_of_type_II_Weyl_semimetals.py +++ b/academic_codes/models_and_bands/2021.03.10_bands_of_type_II_Weyl_semimetals/bands_of_type_II_Weyl_semimetals.py @@ -1,89 +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__': +""" +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() \ No newline at end of file diff --git a/academic_codes/2021.03.19_plot_twist_graphene_with_python/graphene.py b/academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/graphene.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.19_plot_twist_graphene_with_python/graphene.py rename to academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/graphene.py index f6b6b3e..18a62e3 --- a/academic_codes/2021.03.19_plot_twist_graphene_with_python/graphene.py +++ b/academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/graphene.py @@ -1,40 +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__': +""" +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() \ No newline at end of file diff --git a/academic_codes/2021.03.19_plot_twist_graphene_with_python/square.py b/academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/square.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.19_plot_twist_graphene_with_python/square.py rename to academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/square.py index 828c6e9..d781e8b --- a/academic_codes/2021.03.19_plot_twist_graphene_with_python/square.py +++ b/academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/square.py @@ -1,35 +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__': +""" +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() \ No newline at end of file diff --git a/academic_codes/2021.03.19_plot_twist_graphene_with_python/twist_graphene.py b/academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/twist_graphene.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.19_plot_twist_graphene_with_python/twist_graphene.py rename to academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/twist_graphene.py index 318f4f6..664d630 --- a/academic_codes/2021.03.19_plot_twist_graphene_with_python/twist_graphene.py +++ b/academic_codes/models_and_bands/2021.03.19_plot_twist_graphene_with_python/twist_graphene.py @@ -1,72 +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__': +""" +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() \ No newline at end of file diff --git a/academic_codes/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/eigenvalue_of_Kronecker_product_of_Pauli_matrices.py b/academic_codes/models_and_bands/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/eigenvalue_of_Kronecker_product_of_Pauli_matrices.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/eigenvalue_of_Kronecker_product_of_Pauli_matrices.py rename to academic_codes/models_and_bands/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/eigenvalue_of_Kronecker_product_of_Pauli_matrices.py index a62150e..600a184 --- a/academic_codes/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/eigenvalue_of_Kronecker_product_of_Pauli_matrices.py +++ b/academic_codes/models_and_bands/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/eigenvalue_of_Kronecker_product_of_Pauli_matrices.py @@ -1,53 +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) +""" +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) \ No newline at end of file diff --git a/academic_codes/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/test2_eigenvalue_of_Kronecker_product_of_Pauli_matrices.py b/academic_codes/models_and_bands/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/test2_eigenvalue_of_Kronecker_product_of_Pauli_matrices.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/test2_eigenvalue_of_Kronecker_product_of_Pauli_matrices.py rename to academic_codes/models_and_bands/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/test2_eigenvalue_of_Kronecker_product_of_Pauli_matrices.py index 7e882f4..e7111eb --- a/academic_codes/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/test2_eigenvalue_of_Kronecker_product_of_Pauli_matrices.py +++ b/academic_codes/models_and_bands/2021.05.21_eigenvalue_of_Kronecker_product_of_Pauli_matrices/test2_eigenvalue_of_Kronecker_product_of_Pauli_matrices.py @@ -1,49 +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) +""" +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() \ No newline at end of file diff --git a/academic_codes/2021.07.28_bands_of_SSH_model_with_two_kinds_of_fourier_transform/bands_of_SSH_model_with_two_kinds_of_fourier_transform.py b/academic_codes/models_and_bands/2021.07.28_bands_of_SSH_model_with_two_kinds_of_fourier_transform/bands_of_SSH_model_with_two_kinds_of_fourier_transform.py similarity index 100% rename from academic_codes/2021.07.28_bands_of_SSH_model_with_two_kinds_of_fourier_transform/bands_of_SSH_model_with_two_kinds_of_fourier_transform.py rename to academic_codes/models_and_bands/2021.07.28_bands_of_SSH_model_with_two_kinds_of_fourier_transform/bands_of_SSH_model_with_two_kinds_of_fourier_transform.py diff --git a/academic_codes/2021.08.09_flat_bands_of_Kagome lattice/flat_bands_of_Kagome lattice.nb b/academic_codes/models_and_bands/2021.08.09_flat_bands_of_Kagome lattice/flat_bands_of_Kagome lattice.nb similarity index 100% rename from academic_codes/2021.08.09_flat_bands_of_Kagome lattice/flat_bands_of_Kagome lattice.nb rename to academic_codes/models_and_bands/2021.08.09_flat_bands_of_Kagome lattice/flat_bands_of_Kagome lattice.nb diff --git a/academic_codes/2021.08.09_flat_bands_of_kagome lattice/flat_bands_of_kagome lattice.py b/academic_codes/models_and_bands/2021.08.09_flat_bands_of_Kagome lattice/flat_bands_of_Kagome lattice.py similarity index 100% rename from academic_codes/2021.08.09_flat_bands_of_kagome lattice/flat_bands_of_kagome lattice.py rename to academic_codes/models_and_bands/2021.08.09_flat_bands_of_Kagome lattice/flat_bands_of_Kagome lattice.py diff --git a/academic_codes/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/Haldane_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py b/academic_codes/models_and_bands/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/Haldane_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py similarity index 100% rename from academic_codes/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/Haldane_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py rename to academic_codes/models_and_bands/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/Haldane_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py diff --git a/academic_codes/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/graphene_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py b/academic_codes/models_and_bands/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/graphene_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py similarity index 100% rename from academic_codes/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/graphene_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py rename to academic_codes/models_and_bands/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/graphene_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py diff --git a/academic_codes/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/square_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py b/academic_codes/models_and_bands/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/square_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py similarity index 100% rename from academic_codes/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/square_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py rename to academic_codes/models_and_bands/2022.07.14_relation_of_2D_discrete_ky_and_ribbon_with_Ny/square_relation_of_2D_discrete_ky_and_ribbon_with_Ny.py diff --git a/academic_codes/2022.11.06_band_folding/band_folding.py b/academic_codes/models_and_bands/2022.11.06_band_folding/band_folding.py similarity index 100% rename from academic_codes/2022.11.06_band_folding/band_folding.py rename to academic_codes/models_and_bands/2022.11.06_band_folding/band_folding.py diff --git a/academic_codes/2022.11.07_band_folding_correspondence/band_folding_correspondence_1.py b/academic_codes/models_and_bands/2022.11.07_band_folding_correspondence/band_folding_correspondence_1.py similarity index 100% rename from academic_codes/2022.11.07_band_folding_correspondence/band_folding_correspondence_1.py rename to academic_codes/models_and_bands/2022.11.07_band_folding_correspondence/band_folding_correspondence_1.py diff --git a/academic_codes/2022.11.07_band_folding_correspondence/band_folding_correspondence_2.py b/academic_codes/models_and_bands/2022.11.07_band_folding_correspondence/band_folding_correspondence_2.py similarity index 100% rename from academic_codes/2022.11.07_band_folding_correspondence/band_folding_correspondence_2.py rename to academic_codes/models_and_bands/2022.11.07_band_folding_correspondence/band_folding_correspondence_2.py diff --git a/academic_codes/2019.11.03_three_body_moving_on_2D_space/big_mass_in_one_body/step_0.1.py b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/big_mass_in_one_body/step_0.1.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.03_three_body_moving_on_2D_space/big_mass_in_one_body/step_0.1.py rename to academic_codes/others/2019.11.03_three_body_moving_on_2D_space/big_mass_in_one_body/step_0.1.py index a715bf4..8a73f3e --- a/academic_codes/2019.11.03_three_body_moving_on_2D_space/big_mass_in_one_body/step_0.1.py +++ b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/big_mass_in_one_body/step_0.1.py @@ -1,114 +1,114 @@ -import numpy as np -import matplotlib.pyplot as plt -import os -# os.chdir('E:/data') # 设置路径 - -# 万有引力常数 -G = 1 - -# 三体的质量 -m1 = 10 # 绿色 -m2 = 1000 # 红色 -m3 = 10 # 蓝色 - -# 三体的初始位置 -x1 = 0 # 绿色 -y1 = 500 -x2 = 0 # 红色 -y2 = 0 -x3 = 0 # 蓝色 -y3 = 1000 - -# 三体的初始速度 -v1_x = 1.5 # 绿色 -v1_y = 0 -v2_x = 0 # 红色 -v2_y = 0 -v3_x = 0.8 # 蓝色 -v3_y = 0 - -# 步长 -t = 0.1 - -plt.ion() # 开启交互模式 -observation_max = 100 # 视线范围初始值 -x1_all = [x1] # 轨迹初始值 -y1_all = [y1] -x2_all = [x2] -y2_all = [y2] -x3_all = [x3] -y3_all = [y3] - -i0 = 0 -for i in range(1000000): - distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 - distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 - distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 - - # 对物体1的计算 - a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) - a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 - a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 - a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 - v1_x = v1_x + a1_x*t # 物体1的速度 - v1_y = v1_y + a1_y*t # 物体1的速度 - x1 = x1 + v1_x*t # 物体1的水平位置 - y1 = y1 + v1_y*t # 物体1的垂直位置 - x1_all = np.append(x1_all, x1) # 记录轨迹 - y1_all = np.append(y1_all, y1) # 记录轨迹 - - # 对物体2的计算 - a2_1 = G*m1/(distance12**2) - a2_3 = G*m3/(distance23**2) - a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 - a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 - v2_x = v2_x + a2_x*t - v2_y = v2_y + a2_y*t - x2 = x2 + v2_x*t - y2 = y2 + v2_y*t - x2_all = np.append(x2_all, x2) - y2_all = np.append(y2_all, y2) - - # 对物体3的计算 - a3_1 = G*m1/(distance13**2) - a3_2 = G*m2/(distance23**2) - a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 - a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 - v3_x = v3_x + a3_x*t - v3_y = v3_y + a3_y*t - x3 = x3 + v3_x*t - y3 = y3 + v3_y*t - x3_all = np.append(x3_all, x3) - y3_all = np.append(y3_all, y3) - - # 选择观测坐标 - axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 - axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 - while True: - if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ - np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: - observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 - elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ - np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: - observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 - else: - break - - plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) - - plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。 - plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) - plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) - plt.plot(x1_all, y1_all, '-g') # 画轨迹 - plt.plot(x2_all, y2_all, '-r') - plt.plot(x3_all, y3_all, '-b') - - - # plt.show() # 显示图像 - # plt.pause(0.00001) # 暂停0.00001,防止画图过快 - - if np.mod(i, 100) == 0: # 当运动明显时,把图画出来 - print(i0) - plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 - i0 += 1 - plt.clf() # 清空 +import numpy as np +import matplotlib.pyplot as plt +import os +# os.chdir('E:/data') # 设置路径 + +# 万有引力常数 +G = 1 + +# 三体的质量 +m1 = 10 # 绿色 +m2 = 1000 # 红色 +m3 = 10 # 蓝色 + +# 三体的初始位置 +x1 = 0 # 绿色 +y1 = 500 +x2 = 0 # 红色 +y2 = 0 +x3 = 0 # 蓝色 +y3 = 1000 + +# 三体的初始速度 +v1_x = 1.5 # 绿色 +v1_y = 0 +v2_x = 0 # 红色 +v2_y = 0 +v3_x = 0.8 # 蓝色 +v3_y = 0 + +# 步长 +t = 0.1 + +plt.ion() # 开启交互模式 +observation_max = 100 # 视线范围初始值 +x1_all = [x1] # 轨迹初始值 +y1_all = [y1] +x2_all = [x2] +y2_all = [y2] +x3_all = [x3] +y3_all = [y3] + +i0 = 0 +for i in range(1000000): + distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 + distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 + distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 + + # 对物体1的计算 + a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) + a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 + a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 + a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 + v1_x = v1_x + a1_x*t # 物体1的速度 + v1_y = v1_y + a1_y*t # 物体1的速度 + x1 = x1 + v1_x*t # 物体1的水平位置 + y1 = y1 + v1_y*t # 物体1的垂直位置 + x1_all = np.append(x1_all, x1) # 记录轨迹 + y1_all = np.append(y1_all, y1) # 记录轨迹 + + # 对物体2的计算 + a2_1 = G*m1/(distance12**2) + a2_3 = G*m3/(distance23**2) + a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 + a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 + v2_x = v2_x + a2_x*t + v2_y = v2_y + a2_y*t + x2 = x2 + v2_x*t + y2 = y2 + v2_y*t + x2_all = np.append(x2_all, x2) + y2_all = np.append(y2_all, y2) + + # 对物体3的计算 + a3_1 = G*m1/(distance13**2) + a3_2 = G*m2/(distance23**2) + a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 + a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 + v3_x = v3_x + a3_x*t + v3_y = v3_y + a3_y*t + x3 = x3 + v3_x*t + y3 = y3 + v3_y*t + x3_all = np.append(x3_all, x3) + y3_all = np.append(y3_all, y3) + + # 选择观测坐标 + axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 + axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 + while True: + if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ + np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: + observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 + elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ + np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: + observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 + else: + break + + plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) + + plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。 + plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) + plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) + plt.plot(x1_all, y1_all, '-g') # 画轨迹 + plt.plot(x2_all, y2_all, '-r') + plt.plot(x3_all, y3_all, '-b') + + + # plt.show() # 显示图像 + # plt.pause(0.00001) # 暂停0.00001,防止画图过快 + + if np.mod(i, 100) == 0: # 当运动明显时,把图画出来 + print(i0) + plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 + i0 += 1 + plt.clf() # 清空 diff --git a/academic_codes/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.05.py b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.05.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.05.py rename to academic_codes/others/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.05.py index 0a63032..f5a7873 --- a/academic_codes/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.05.py +++ b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.05.py @@ -1,110 +1,110 @@ -import numpy as np -import matplotlib.pyplot as plt -import os -# os.chdir('E:/data') # 设置路径 - -# 万有引力常数 -G = 1 - -# 三体的质量 -m1 = 3 # 绿色 -m2 = 100 # 红色 -m3 = 10 # 蓝色 - -# 三体的初始位置 -x1 = 0 # 绿色 -y1 = -100 -x2 = 0 # 红色 -y2 = 0 -x3 = 0 # 蓝色 -y3 = 50 - -# 三体的初始速度 -v1_x = 1 # 绿色 -v1_y = 0 -v2_x = 0 # 红色 -v2_y = 0 -v3_x = 2 # 蓝色 -v3_y = 0 - -# 步长 -t = 0.05 - -plt.ion() # 开启交互模式 -observation_max = 100 # 观测坐标范围初始值 -x1_all = [x1] # 轨迹初始值 -y1_all = [y1] -x2_all = [x2] -y2_all = [y2] -x3_all = [x3] -y3_all = [y3] - -i0 = 0 -for i in range(100000000000): - distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 - distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 - distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 - # 对物体1的计算 - a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) - a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 - a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 - a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 - v1_x = v1_x + a1_x*t # 物体1的速度 - v1_y = v1_y + a1_y*t # 物体1的速度 - x1 = x1 + v1_x*t # 物体1的水平位置 - y1 = y1 + v1_y*t # 物体1的垂直位置 - x1_all = np.append(x1_all, x1) # 记录轨迹 - y1_all = np.append(y1_all, y1) # 记录轨迹 - # 对物体2的计算 - a2_1 = G*m1/(distance12**2) - a2_3 = G*m3/(distance23**2) - a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 - a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 - v2_x = v2_x + a2_x*t - v2_y = v2_y + a2_y*t - x2 = x2 + v2_x*t - y2 = y2 + v2_y*t - x2_all = np.append(x2_all, x2) - y2_all = np.append(y2_all, y2) - # 对物体3的计算 - a3_1 = G*m1/(distance13**2) - a3_2 = G*m2/(distance23**2) - a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 - a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 - v3_x = v3_x + a3_x*t - v3_y = v3_y + a3_y*t - x3 = x3 + v3_x*t - y3 = y3 + v3_y*t - x3_all = np.append(x3_all, x3) - y3_all = np.append(y3_all, y3) - - # 选择观测坐标 - axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 - axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 - while True: - if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ - np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: - observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 - elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ - np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: - observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 - else: - break - - plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) - - plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。 - plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) - plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) - plt.plot(x1_all, y1_all, '-g') # 画轨迹 - plt.plot(x2_all, y2_all, '-r') - plt.plot(x3_all, y3_all, '-b') - - # plt.show() # 显示图像 - # plt.pause(0.00001) # 暂停0.00001,防止画图过快 - - if np.mod(i, 200) == 0: - print(i0) - plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 - i0 += 1 +import numpy as np +import matplotlib.pyplot as plt +import os +# os.chdir('E:/data') # 设置路径 + +# 万有引力常数 +G = 1 + +# 三体的质量 +m1 = 3 # 绿色 +m2 = 100 # 红色 +m3 = 10 # 蓝色 + +# 三体的初始位置 +x1 = 0 # 绿色 +y1 = -100 +x2 = 0 # 红色 +y2 = 0 +x3 = 0 # 蓝色 +y3 = 50 + +# 三体的初始速度 +v1_x = 1 # 绿色 +v1_y = 0 +v2_x = 0 # 红色 +v2_y = 0 +v3_x = 2 # 蓝色 +v3_y = 0 + +# 步长 +t = 0.05 + +plt.ion() # 开启交互模式 +observation_max = 100 # 观测坐标范围初始值 +x1_all = [x1] # 轨迹初始值 +y1_all = [y1] +x2_all = [x2] +y2_all = [y2] +x3_all = [x3] +y3_all = [y3] + +i0 = 0 +for i in range(100000000000): + distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 + distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 + distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 + # 对物体1的计算 + a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) + a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 + a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 + a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 + v1_x = v1_x + a1_x*t # 物体1的速度 + v1_y = v1_y + a1_y*t # 物体1的速度 + x1 = x1 + v1_x*t # 物体1的水平位置 + y1 = y1 + v1_y*t # 物体1的垂直位置 + x1_all = np.append(x1_all, x1) # 记录轨迹 + y1_all = np.append(y1_all, y1) # 记录轨迹 + # 对物体2的计算 + a2_1 = G*m1/(distance12**2) + a2_3 = G*m3/(distance23**2) + a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 + a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 + v2_x = v2_x + a2_x*t + v2_y = v2_y + a2_y*t + x2 = x2 + v2_x*t + y2 = y2 + v2_y*t + x2_all = np.append(x2_all, x2) + y2_all = np.append(y2_all, y2) + # 对物体3的计算 + a3_1 = G*m1/(distance13**2) + a3_2 = G*m2/(distance23**2) + a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 + a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 + v3_x = v3_x + a3_x*t + v3_y = v3_y + a3_y*t + x3 = x3 + v3_x*t + y3 = y3 + v3_y*t + x3_all = np.append(x3_all, x3) + y3_all = np.append(y3_all, y3) + + # 选择观测坐标 + axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 + axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 + while True: + if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ + np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: + observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 + elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ + np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: + observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 + else: + break + + plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) + + plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。 + plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) + plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) + plt.plot(x1_all, y1_all, '-g') # 画轨迹 + plt.plot(x2_all, y2_all, '-r') + plt.plot(x3_all, y3_all, '-b') + + # plt.show() # 显示图像 + # plt.pause(0.00001) # 暂停0.00001,防止画图过快 + + if np.mod(i, 200) == 0: + print(i0) + plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 + i0 += 1 plt.clf() # 清空 \ No newline at end of file diff --git a/academic_codes/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.1.py b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.1.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.1.py rename to academic_codes/others/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.1.py index 3b23a24..0544ef6 --- a/academic_codes/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.1.py +++ b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/relatively_big_mass_in_one_body/step_0.1.py @@ -1,110 +1,110 @@ -import numpy as np -import matplotlib.pyplot as plt -import os -# os.chdir('E:/data') # 设置路径 - -# 万有引力常数 -G = 1 - -# 三体的质量 -m1 = 3 # 绿色 -m2 = 100 # 红色 -m3 = 10 # 蓝色 - -# 三体的初始位置 -x1 = 0 # 绿色 -y1 = -100 -x2 = 0 # 红色 -y2 = 0 -x3 = 0 # 蓝色 -y3 = 50 - -# 三体的初始速度 -v1_x = 1 # 绿色 -v1_y = 0 -v2_x = 0 # 红色 -v2_y = 0 -v3_x = 2 # 蓝色 -v3_y = 0 - -# 步长 -t = 0.1 - -plt.ion() # 开启交互模式 -observation_max = 100 # 观测坐标范围初始值 -x1_all = [x1] # 轨迹初始值 -y1_all = [y1] -x2_all = [x2] -y2_all = [y2] -x3_all = [x3] -y3_all = [y3] - -i0 = 0 -for i in range(100000000000): - distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 - distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 - distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 - # 对物体1的计算 - a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) - a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 - a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 - a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 - v1_x = v1_x + a1_x*t # 物体1的速度 - v1_y = v1_y + a1_y*t # 物体1的速度 - x1 = x1 + v1_x*t # 物体1的水平位置 - y1 = y1 + v1_y*t # 物体1的垂直位置 - x1_all = np.append(x1_all, x1) # 记录轨迹 - y1_all = np.append(y1_all, y1) # 记录轨迹 - # 对物体2的计算 - a2_1 = G*m1/(distance12**2) - a2_3 = G*m3/(distance23**2) - a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 - a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 - v2_x = v2_x + a2_x*t - v2_y = v2_y + a2_y*t - x2 = x2 + v2_x*t - y2 = y2 + v2_y*t - x2_all = np.append(x2_all, x2) - y2_all = np.append(y2_all, y2) - # 对物体3的计算 - a3_1 = G*m1/(distance13**2) - a3_2 = G*m2/(distance23**2) - a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 - a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 - v3_x = v3_x + a3_x*t - v3_y = v3_y + a3_y*t - x3 = x3 + v3_x*t - y3 = y3 + v3_y*t - x3_all = np.append(x3_all, x3) - y3_all = np.append(y3_all, y3) - - # 选择观测坐标 - axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 - axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 - while True: - if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ - np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: - observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 - elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ - np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: - observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 - else: - break - - plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) - - plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。 - plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) - plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) - plt.plot(x1_all, y1_all, '-g') # 画轨迹 - plt.plot(x2_all, y2_all, '-r') - plt.plot(x3_all, y3_all, '-b') - - # plt.show() # 显示图像 - # plt.pause(0.00001) # 暂停0.00001,防止画图过快 - - if np.mod(i, 100) == 0: - print(i0) - plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 - i0 += 1 +import numpy as np +import matplotlib.pyplot as plt +import os +# os.chdir('E:/data') # 设置路径 + +# 万有引力常数 +G = 1 + +# 三体的质量 +m1 = 3 # 绿色 +m2 = 100 # 红色 +m3 = 10 # 蓝色 + +# 三体的初始位置 +x1 = 0 # 绿色 +y1 = -100 +x2 = 0 # 红色 +y2 = 0 +x3 = 0 # 蓝色 +y3 = 50 + +# 三体的初始速度 +v1_x = 1 # 绿色 +v1_y = 0 +v2_x = 0 # 红色 +v2_y = 0 +v3_x = 2 # 蓝色 +v3_y = 0 + +# 步长 +t = 0.1 + +plt.ion() # 开启交互模式 +observation_max = 100 # 观测坐标范围初始值 +x1_all = [x1] # 轨迹初始值 +y1_all = [y1] +x2_all = [x2] +y2_all = [y2] +x3_all = [x3] +y3_all = [y3] + +i0 = 0 +for i in range(100000000000): + distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 + distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 + distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 + # 对物体1的计算 + a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) + a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 + a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 + a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 + v1_x = v1_x + a1_x*t # 物体1的速度 + v1_y = v1_y + a1_y*t # 物体1的速度 + x1 = x1 + v1_x*t # 物体1的水平位置 + y1 = y1 + v1_y*t # 物体1的垂直位置 + x1_all = np.append(x1_all, x1) # 记录轨迹 + y1_all = np.append(y1_all, y1) # 记录轨迹 + # 对物体2的计算 + a2_1 = G*m1/(distance12**2) + a2_3 = G*m3/(distance23**2) + a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 + a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 + v2_x = v2_x + a2_x*t + v2_y = v2_y + a2_y*t + x2 = x2 + v2_x*t + y2 = y2 + v2_y*t + x2_all = np.append(x2_all, x2) + y2_all = np.append(y2_all, y2) + # 对物体3的计算 + a3_1 = G*m1/(distance13**2) + a3_2 = G*m2/(distance23**2) + a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 + a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 + v3_x = v3_x + a3_x*t + v3_y = v3_y + a3_y*t + x3 = x3 + v3_x*t + y3 = y3 + v3_y*t + x3_all = np.append(x3_all, x3) + y3_all = np.append(y3_all, y3) + + # 选择观测坐标 + axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 + axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 + while True: + if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ + np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: + observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 + elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ + np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: + observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 + else: + break + + plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) + + plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,画出来的面积越大。视线范围越宽,球看起来越小。 + plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) + plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) + plt.plot(x1_all, y1_all, '-g') # 画轨迹 + plt.plot(x2_all, y2_all, '-r') + plt.plot(x3_all, y3_all, '-b') + + # plt.show() # 显示图像 + # plt.pause(0.00001) # 暂停0.00001,防止画图过快 + + if np.mod(i, 100) == 0: + print(i0) + plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 + i0 += 1 plt.clf() # 清空 \ No newline at end of file diff --git a/academic_codes/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.05.py b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.05.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.05.py rename to academic_codes/others/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.05.py index a2f84f6..cd4e41f --- a/academic_codes/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.05.py +++ b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.05.py @@ -1,113 +1,113 @@ -import numpy as np -import matplotlib.pyplot as plt -import os -# os.chdir('E:/data') # 设置路径 - -# 万有引力常数 -G = 1 - -# 三体的质量 -m1 = 15 # 绿色 -m2 = 12 # 红色 -m3 = 8 # 蓝色 - -# 三体的初始位置 -x1 = 300 # 绿色 -y1 = 50 -x2 = -100 # 红色 -y2 = -200 -x3 = -100 # 蓝色 -y3 = 150 - -# 三体的初始速度 -v1_x = 0 # 绿色 -v1_y = 0 -v2_x = 0 # 红色 -v2_y = 0 -v3_x = 0 # 蓝色 -v3_y = 0 - -# 步长 -t = 0.05 - -plt.ion() # 开启交互模式 -observation_max = 100 # 视线范围初始值 -x1_all = [x1] # 轨迹初始值 -y1_all = [y1] -x2_all = [x2] -y2_all = [y2] -x3_all = [x3] -y3_all = [y3] - -i0 = 0 -for i in range(1000000): - distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 - distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 - distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 - - # 对物体1的计算 - a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) - a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 - a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 - a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 - v1_x = v1_x + a1_x*t # 物体1的速度 - v1_y = v1_y + a1_y*t # 物体1的速度 - x1 = x1 + v1_x*t # 物体1的水平位置 - y1 = y1 + v1_y*t # 物体1的垂直位置 - x1_all = np.append(x1_all, x1) # 记录轨迹 - y1_all = np.append(y1_all, y1) # 记录轨迹 - - # 对物体2的计算 - a2_1 = G*m1/(distance12**2) - a2_3 = G*m3/(distance23**2) - a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 - a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 - v2_x = v2_x + a2_x*t - v2_y = v2_y + a2_y*t - x2 = x2 + v2_x*t - y2 = y2 + v2_y*t - x2_all = np.append(x2_all, x2) - y2_all = np.append(y2_all, y2) - - # 对物体3的计算 - a3_1 = G*m1/(distance13**2) - a3_2 = G*m2/(distance23**2) - a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 - a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 - v3_x = v3_x + a3_x*t - v3_y = v3_y + a3_y*t - x3 = x3 + v3_x*t - y3 = y3 + v3_y*t - x3_all = np.append(x3_all, x3) - y3_all = np.append(y3_all, y3) - - # 选择观测坐标 - axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 - axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 - while True: - if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ - np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: - observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 - elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ - np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: - observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 - else: - break - - plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) - - plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。 - plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) - plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) - plt.plot(x1_all, y1_all, '-g') # 画轨迹 - plt.plot(x2_all, y2_all, '-r') - plt.plot(x3_all, y3_all, '-b') - - # plt.show() # 显示图像 - # plt.pause(0.00001) # 暂停0.00001,防止画图过快 - - if np.mod(i, 1000) == 0: # 当运动明显时,把图画出来 - print(i0) - plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 - i0 += 1 - plt.clf() # 清空 +import numpy as np +import matplotlib.pyplot as plt +import os +# os.chdir('E:/data') # 设置路径 + +# 万有引力常数 +G = 1 + +# 三体的质量 +m1 = 15 # 绿色 +m2 = 12 # 红色 +m3 = 8 # 蓝色 + +# 三体的初始位置 +x1 = 300 # 绿色 +y1 = 50 +x2 = -100 # 红色 +y2 = -200 +x3 = -100 # 蓝色 +y3 = 150 + +# 三体的初始速度 +v1_x = 0 # 绿色 +v1_y = 0 +v2_x = 0 # 红色 +v2_y = 0 +v3_x = 0 # 蓝色 +v3_y = 0 + +# 步长 +t = 0.05 + +plt.ion() # 开启交互模式 +observation_max = 100 # 视线范围初始值 +x1_all = [x1] # 轨迹初始值 +y1_all = [y1] +x2_all = [x2] +y2_all = [y2] +x3_all = [x3] +y3_all = [y3] + +i0 = 0 +for i in range(1000000): + distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 + distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 + distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 + + # 对物体1的计算 + a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) + a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 + a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 + a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 + v1_x = v1_x + a1_x*t # 物体1的速度 + v1_y = v1_y + a1_y*t # 物体1的速度 + x1 = x1 + v1_x*t # 物体1的水平位置 + y1 = y1 + v1_y*t # 物体1的垂直位置 + x1_all = np.append(x1_all, x1) # 记录轨迹 + y1_all = np.append(y1_all, y1) # 记录轨迹 + + # 对物体2的计算 + a2_1 = G*m1/(distance12**2) + a2_3 = G*m3/(distance23**2) + a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 + a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 + v2_x = v2_x + a2_x*t + v2_y = v2_y + a2_y*t + x2 = x2 + v2_x*t + y2 = y2 + v2_y*t + x2_all = np.append(x2_all, x2) + y2_all = np.append(y2_all, y2) + + # 对物体3的计算 + a3_1 = G*m1/(distance13**2) + a3_2 = G*m2/(distance23**2) + a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 + a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 + v3_x = v3_x + a3_x*t + v3_y = v3_y + a3_y*t + x3 = x3 + v3_x*t + y3 = y3 + v3_y*t + x3_all = np.append(x3_all, x3) + y3_all = np.append(y3_all, y3) + + # 选择观测坐标 + axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 + axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 + while True: + if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ + np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: + observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 + elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ + np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: + observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 + else: + break + + plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) + + plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。 + plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) + plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) + plt.plot(x1_all, y1_all, '-g') # 画轨迹 + plt.plot(x2_all, y2_all, '-r') + plt.plot(x3_all, y3_all, '-b') + + # plt.show() # 显示图像 + # plt.pause(0.00001) # 暂停0.00001,防止画图过快 + + if np.mod(i, 1000) == 0: # 当运动明显时,把图画出来 + print(i0) + plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 + i0 += 1 + plt.clf() # 清空 diff --git a/academic_codes/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.1.py b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.1.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.1.py rename to academic_codes/others/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.1.py index 2a37f99..c579920 --- a/academic_codes/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.1.py +++ b/academic_codes/others/2019.11.03_three_body_moving_on_2D_space/three_body_mass_with_little_difference/step_0.1.py @@ -1,113 +1,113 @@ -import numpy as np -import matplotlib.pyplot as plt -import os -# os.chdir('E:/data') # 设置路径 - -# 万有引力常数 -G = 1 - -# 三体的质量 -m1 = 15 # 绿色 -m2 = 12 # 红色 -m3 = 8 # 蓝色 - -# 三体的初始位置 -x1 = 300 # 绿色 -y1 = 50 -x2 = -100 # 红色 -y2 = -200 -x3 = -100 # 蓝色 -y3 = 150 - -# 三体的初始速度 -v1_x = 0 # 绿色 -v1_y = 0 -v2_x = 0 # 红色 -v2_y = 0 -v3_x = 0 # 蓝色 -v3_y = 0 - -# 步长 -t = 0.1 - -plt.ion() # 开启交互模式 -observation_max = 100 # 视线范围初始值 -x1_all = [x1] # 轨迹初始值 -y1_all = [y1] -x2_all = [x2] -y2_all = [y2] -x3_all = [x3] -y3_all = [y3] - -i0 = 0 -for i in range(1000000): - distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 - distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 - distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 - - # 对物体1的计算 - a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) - a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 - a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 - a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 - v1_x = v1_x + a1_x*t # 物体1的速度 - v1_y = v1_y + a1_y*t # 物体1的速度 - x1 = x1 + v1_x*t # 物体1的水平位置 - y1 = y1 + v1_y*t # 物体1的垂直位置 - x1_all = np.append(x1_all, x1) # 记录轨迹 - y1_all = np.append(y1_all, y1) # 记录轨迹 - - # 对物体2的计算 - a2_1 = G*m1/(distance12**2) - a2_3 = G*m3/(distance23**2) - a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 - a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 - v2_x = v2_x + a2_x*t - v2_y = v2_y + a2_y*t - x2 = x2 + v2_x*t - y2 = y2 + v2_y*t - x2_all = np.append(x2_all, x2) - y2_all = np.append(y2_all, y2) - - # 对物体3的计算 - a3_1 = G*m1/(distance13**2) - a3_2 = G*m2/(distance23**2) - a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 - a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 - v3_x = v3_x + a3_x*t - v3_y = v3_y + a3_y*t - x3 = x3 + v3_x*t - y3 = y3 + v3_y*t - x3_all = np.append(x3_all, x3) - y3_all = np.append(y3_all, y3) - - # 选择观测坐标 - axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 - axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 - while True: - if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ - np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: - observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 - elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ - np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: - observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 - else: - break - - plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) - - plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。 - plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) - plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) - plt.plot(x1_all, y1_all, '-g') # 画轨迹 - plt.plot(x2_all, y2_all, '-r') - plt.plot(x3_all, y3_all, '-b') - - # plt.show() # 显示图像 - # plt.pause(0.00001) # 暂停0.00001,防止画图过快 - - if np.mod(i, 500) == 0: # 当运动明显时,把图画出来 - print(i0) - plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 - i0 += 1 - plt.clf() # 清空 +import numpy as np +import matplotlib.pyplot as plt +import os +# os.chdir('E:/data') # 设置路径 + +# 万有引力常数 +G = 1 + +# 三体的质量 +m1 = 15 # 绿色 +m2 = 12 # 红色 +m3 = 8 # 蓝色 + +# 三体的初始位置 +x1 = 300 # 绿色 +y1 = 50 +x2 = -100 # 红色 +y2 = -200 +x3 = -100 # 蓝色 +y3 = 150 + +# 三体的初始速度 +v1_x = 0 # 绿色 +v1_y = 0 +v2_x = 0 # 红色 +v2_y = 0 +v3_x = 0 # 蓝色 +v3_y = 0 + +# 步长 +t = 0.1 + +plt.ion() # 开启交互模式 +observation_max = 100 # 视线范围初始值 +x1_all = [x1] # 轨迹初始值 +y1_all = [y1] +x2_all = [x2] +y2_all = [y2] +x3_all = [x3] +y3_all = [y3] + +i0 = 0 +for i in range(1000000): + distance12 = np.sqrt((x1-x2)**2+(y1-y2)**2) # 物体1和物体2之间的距离 + distance13 = np.sqrt((x1-x3)**2+(y1-y3)**2) # 物体1和物体3之间的距离 + distance23 = np.sqrt((x2-x3)**2+(y2-y3)**2) # 物体2和物体3之间的距离 + + # 对物体1的计算 + a1_2 = G*m2/(distance12**2) # 物体2对物体1的加速度(用上万有引力公式) + a1_3 = G*m3/(distance13**2) # 物体3对物体1的加速度 + a1_x = a1_2*(x2-x1)/distance12 + a1_3*(x3-x1)/distance13 # 物体1受到的水平加速度 + a1_y = a1_2*(y2-y1)/distance12 + a1_3*(y3-y1)/distance13 # 物体1受到的垂直加速度 + v1_x = v1_x + a1_x*t # 物体1的速度 + v1_y = v1_y + a1_y*t # 物体1的速度 + x1 = x1 + v1_x*t # 物体1的水平位置 + y1 = y1 + v1_y*t # 物体1的垂直位置 + x1_all = np.append(x1_all, x1) # 记录轨迹 + y1_all = np.append(y1_all, y1) # 记录轨迹 + + # 对物体2的计算 + a2_1 = G*m1/(distance12**2) + a2_3 = G*m3/(distance23**2) + a2_x = a2_1*(x1-x2)/distance12 + a2_3*(x3-x2)/distance23 + a2_y = a2_1*(y1-y2)/distance12 + a2_3*(y3-y2)/distance23 + v2_x = v2_x + a2_x*t + v2_y = v2_y + a2_y*t + x2 = x2 + v2_x*t + y2 = y2 + v2_y*t + x2_all = np.append(x2_all, x2) + y2_all = np.append(y2_all, y2) + + # 对物体3的计算 + a3_1 = G*m1/(distance13**2) + a3_2 = G*m2/(distance23**2) + a3_x = a3_1*(x1-x3)/distance13 + a3_2*(x2-x3)/distance23 + a3_y = a3_1*(y1-y3)/distance13 + a3_2*(y2-y3)/distance23 + v3_x = v3_x + a3_x*t + v3_y = v3_y + a3_y*t + x3 = x3 + v3_x*t + y3 = y3 + v3_y*t + x3_all = np.append(x3_all, x3) + y3_all = np.append(y3_all, y3) + + # 选择观测坐标 + axis_x = np.mean([x1, x2, x3]) # 观测坐标中心固定在平均值的地方 + axis_y = np.mean([y1, y2, y3]) # 观测坐标中心固定在平均值的地方 + while True: + if np.abs(x1-axis_x) > observation_max or np.abs(x2-axis_x) > observation_max or np.abs(x3-axis_x) > observation_max or\ + np.abs(y1-axis_y) > observation_max or np.abs(y2-axis_y) > observation_max or np.abs(y3-axis_y) > observation_max: + observation_max = observation_max * 2 # 有一个物体超出视线时,视线范围翻倍 + elif np.abs(x1-axis_x) < observation_max/10 and np.abs(x2-axis_x) < observation_max/10 and np.abs(x3-axis_x) < observation_max/10 and\ + np.abs(y1-axis_y) < observation_max/10 and np.abs(y2-axis_y) < observation_max/10 and np.abs(y3-axis_y) < observation_max/10: + observation_max = observation_max / 2 # 所有物体都在的视线的10分之一内,视线范围减半 + else: + break + + plt.axis([axis_x-observation_max, axis_x+observation_max, axis_y-observation_max, axis_y+observation_max]) + + plt.plot(x1, y1, 'og', markersize=m1*100/observation_max) # 默认密度相同,质量越大的,球面积越大。视线范围越宽,球看起来越小。 + plt.plot(x2, y2, 'or', markersize=m2*100/observation_max) + plt.plot(x3, y3, 'ob', markersize=m3*100/observation_max) + plt.plot(x1_all, y1_all, '-g') # 画轨迹 + plt.plot(x2_all, y2_all, '-r') + plt.plot(x3_all, y3_all, '-b') + + # plt.show() # 显示图像 + # plt.pause(0.00001) # 暂停0.00001,防止画图过快 + + if np.mod(i, 500) == 0: # 当运动明显时,把图画出来 + print(i0) + plt.savefig(str(i0)+'.jpg') # 保存为图片可以用来做动画 + i0 += 1 + plt.clf() # 清空 diff --git a/academic_codes/2019.11.07_definite_integration_with_Monte_Carlo_method/definite_integration_with_Monte_Carlo_method.py b/academic_codes/others/2019.11.07_definite_integration_with_Monte_Carlo_method/definite_integration_with_Monte_Carlo_method.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2019.11.07_definite_integration_with_Monte_Carlo_method/definite_integration_with_Monte_Carlo_method.py rename to academic_codes/others/2019.11.07_definite_integration_with_Monte_Carlo_method/definite_integration_with_Monte_Carlo_method.py index 3c01139..686fecb --- a/academic_codes/2019.11.07_definite_integration_with_Monte_Carlo_method/definite_integration_with_Monte_Carlo_method.py +++ b/academic_codes/others/2019.11.07_definite_integration_with_Monte_Carlo_method/definite_integration_with_Monte_Carlo_method.py @@ -1,73 +1,73 @@ -""" -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/1145 -""" - -import numpy as np -import random -import time - - -def integral(): # 直接数值积分 - integral_value = 0 - for x in np.arange(0, 1, 1/10**7): - integral_value = integral_value + x**2*(1/10**7) # 对x^2在0和1之间积分 - return integral_value - - -def MC_1(): # 蒙特卡洛求定积分1:投点法 - n = 10**7 - x_min, x_max = 0.0, 1.0 - y_min, y_max = 0.0, 1.0 - count = 0 - for i in range(0, n): - x = random.uniform(x_min, x_max) - y = random.uniform(y_min, y_max) - # x*x > y,表示该点位于曲线的下面。所求的积分值即为曲线下方的面积与正方形面积的比。 - if x * x > y: - count += 1 - integral_value = count / n - return integral_value - - -def MC_2(): # 蒙特卡洛求定积分2:期望法 - n = 10**7 - x_min, x_max = 0.0, 1.0 - integral_value = 0 - for i in range(n): - x = random.uniform(x_min, x_max) - integral_value = integral_value + (1-0)*x**2 - integral_value = integral_value/n - return integral_value - - -print('【计算时间】') -start_clock = time.perf_counter() # 或者用time.clock() -a00 = 1/3 # 理论值 -end_clock = time.perf_counter() -print('理论值(解析):', end_clock-start_clock) -start_clock = time.perf_counter() -a0 = integral() # 直接数值积分 -end_clock = time.perf_counter() -print('直接数值积分:', end_clock-start_clock) -start_clock = time.perf_counter() -a1 = MC_1() # 用蒙特卡洛求积分投点法 -end_clock = time.perf_counter() -print('用蒙特卡洛求积分_投点法:', end_clock-start_clock) -start_clock = time.perf_counter() -a2 = MC_2() -end_clock = time.perf_counter() -print('用蒙特卡洛求积分_期望法:', end_clock-start_clock, '\n') - -print('【计算结果】') -print('理论值(解析):', a00) -print('直接数值积分:', a0) -print('用蒙特卡洛求积分_投点法:', a1) -print('用蒙特卡洛求积分_期望法:', a2, '\n') - -print('【计算误差】') -print('理论值(解析):', 0) -print('直接数值积分:', abs(a0-1/3)) -print('用蒙特卡洛求积分_投点法:', abs(a1-1/3)) -print('用蒙特卡洛求积分_期望法:', abs(a2-1/3)) - +""" +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/1145 +""" + +import numpy as np +import random +import time + + +def integral(): # 直接数值积分 + integral_value = 0 + for x in np.arange(0, 1, 1/10**7): + integral_value = integral_value + x**2*(1/10**7) # 对x^2在0和1之间积分 + return integral_value + + +def MC_1(): # 蒙特卡洛求定积分1:投点法 + n = 10**7 + x_min, x_max = 0.0, 1.0 + y_min, y_max = 0.0, 1.0 + count = 0 + for i in range(0, n): + x = random.uniform(x_min, x_max) + y = random.uniform(y_min, y_max) + # x*x > y,表示该点位于曲线的下面。所求的积分值即为曲线下方的面积与正方形面积的比。 + if x * x > y: + count += 1 + integral_value = count / n + return integral_value + + +def MC_2(): # 蒙特卡洛求定积分2:期望法 + n = 10**7 + x_min, x_max = 0.0, 1.0 + integral_value = 0 + for i in range(n): + x = random.uniform(x_min, x_max) + integral_value = integral_value + (1-0)*x**2 + integral_value = integral_value/n + return integral_value + + +print('【计算时间】') +start_clock = time.perf_counter() # 或者用time.clock() +a00 = 1/3 # 理论值 +end_clock = time.perf_counter() +print('理论值(解析):', end_clock-start_clock) +start_clock = time.perf_counter() +a0 = integral() # 直接数值积分 +end_clock = time.perf_counter() +print('直接数值积分:', end_clock-start_clock) +start_clock = time.perf_counter() +a1 = MC_1() # 用蒙特卡洛求积分投点法 +end_clock = time.perf_counter() +print('用蒙特卡洛求积分_投点法:', end_clock-start_clock) +start_clock = time.perf_counter() +a2 = MC_2() +end_clock = time.perf_counter() +print('用蒙特卡洛求积分_期望法:', end_clock-start_clock, '\n') + +print('【计算结果】') +print('理论值(解析):', a00) +print('直接数值积分:', a0) +print('用蒙特卡洛求积分_投点法:', a1) +print('用蒙特卡洛求积分_期望法:', a2, '\n') + +print('【计算误差】') +print('理论值(解析):', 0) +print('直接数值积分:', abs(a0-1/3)) +print('用蒙特卡洛求积分_投点法:', abs(a1-1/3)) +print('用蒙特卡洛求积分_期望法:', abs(a2-1/3)) + diff --git a/academic_codes/2019.12.01_Metropolis_sampling/Metropolis_sampling_example_1.py b/academic_codes/others/2019.12.01_Metropolis_sampling/Metropolis_sampling_example_1.py similarity index 100% rename from academic_codes/2019.12.01_Metropolis_sampling/Metropolis_sampling_example_1.py rename to academic_codes/others/2019.12.01_Metropolis_sampling/Metropolis_sampling_example_1.py diff --git a/academic_codes/2019.12.01_Metropolis_sampling/Metropolis_sampling_example_2.m b/academic_codes/others/2019.12.01_Metropolis_sampling/Metropolis_sampling_example_2.m similarity index 100% rename from academic_codes/2019.12.01_Metropolis_sampling/Metropolis_sampling_example_2.m rename to academic_codes/others/2019.12.01_Metropolis_sampling/Metropolis_sampling_example_2.m diff --git a/academic_codes/2019.12.01_simulation_of_Ising_model_with_Monte_Carlo_method/Ising_model.py b/academic_codes/others/2019.12.01_simulation_of_Ising_model_with_Monte_Carlo_method/Ising_model.py similarity index 100% rename from academic_codes/2019.12.01_simulation_of_Ising_model_with_Monte_Carlo_method/Ising_model.py rename to academic_codes/others/2019.12.01_simulation_of_Ising_model_with_Monte_Carlo_method/Ising_model.py diff --git a/academic_codes/2019.12.01_simulation_of_Ising_model_with_Monte_Carlo_method/get_the_transition_temperature_by_calculating_magnetic_moments_in_Ising_model.py b/academic_codes/others/2019.12.01_simulation_of_Ising_model_with_Monte_Carlo_method/get_the_transition_temperature_by_calculating_magnetic_moments_in_Ising_model.py similarity index 100% rename from academic_codes/2019.12.01_simulation_of_Ising_model_with_Monte_Carlo_method/get_the_transition_temperature_by_calculating_magnetic_moments_in_Ising_model.py rename to academic_codes/others/2019.12.01_simulation_of_Ising_model_with_Monte_Carlo_method/get_the_transition_temperature_by_calculating_magnetic_moments_in_Ising_model.py diff --git a/academic_codes/2020.10.30_time_complexity_dealing_with_matrix/time_complexity_dealing_with_matrix.py b/academic_codes/others/2020.10.30_time_complexity_dealing_with_matrix/time_complexity_dealing_with_matrix.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.10.30_time_complexity_dealing_with_matrix/time_complexity_dealing_with_matrix.py rename to academic_codes/others/2020.10.30_time_complexity_dealing_with_matrix/time_complexity_dealing_with_matrix.py index 5412639..a93ea23 --- a/academic_codes/2020.10.30_time_complexity_dealing_with_matrix/time_complexity_dealing_with_matrix.py +++ b/academic_codes/others/2020.10.30_time_complexity_dealing_with_matrix/time_complexity_dealing_with_matrix.py @@ -1,61 +1,61 @@ -import numpy as np -import matplotlib.pyplot as plt -import time - - - -time_1 = np.array([]) -time_2 = np.array([]) -time_3 = np.array([]) -n_all = np.arange(2,5000,200) # 测试的范围 -start_all = time.process_time() -for n in n_all: - print(n) - matrix_1 = np.zeros((n,n)) - matrix_2 = np.zeros((n,n)) - for i0 in range(n): - for j0 in range(n): - matrix_1[i0,j0] = np.random.uniform(-10, 10) - for i0 in range(n): - for j0 in range(n): - matrix_2[i0,j0] = np.random.uniform(-10, 10) - - start = time.process_time() - matrix_3 = np.dot(matrix_1, matrix_2) # 矩阵乘积 - end = time.process_time() - time_1 = np.append(time_1, [end-start], axis=0) - - start = time.process_time() - matrix_4 = np.linalg.inv(matrix_1) # 矩阵求逆 - end = time.process_time() - time_2 = np.append(time_2, [end-start], axis=0) - - start = time.process_time() - eigenvalue, eigenvector = np.linalg.eig(matrix_1) # 求矩阵本征值 - end = time.process_time() - time_3 = np.append(time_3, [end-start], axis=0) - - - -end_all = time.process_time() -print('总共运行时间:', (end_all-start_all)/60, '分') - -plt.subplot(131) -plt.xlabel('n^3/10^9') -plt.ylabel('时间(秒)') -plt.title('矩阵乘积') -plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_1, 'o-') - -plt.subplot(132) -plt.xlabel('n^3/10^9') -plt.title('矩阵求逆') -plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_2, 'o-') - -plt.subplot(133) -plt.xlabel('n^3/10^9') -plt.title('求矩阵本征值') -plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_3, 'o-') - -plt.rcParams['font.sans-serif'] = ['SimHei'] # 在画图中正常显示中文 -plt.rcParams['axes.unicode_minus'] = False # 中文化后,加上这个使正常显示负号 +import numpy as np +import matplotlib.pyplot as plt +import time + + + +time_1 = np.array([]) +time_2 = np.array([]) +time_3 = np.array([]) +n_all = np.arange(2,5000,200) # 测试的范围 +start_all = time.process_time() +for n in n_all: + print(n) + matrix_1 = np.zeros((n,n)) + matrix_2 = np.zeros((n,n)) + for i0 in range(n): + for j0 in range(n): + matrix_1[i0,j0] = np.random.uniform(-10, 10) + for i0 in range(n): + for j0 in range(n): + matrix_2[i0,j0] = np.random.uniform(-10, 10) + + start = time.process_time() + matrix_3 = np.dot(matrix_1, matrix_2) # 矩阵乘积 + end = time.process_time() + time_1 = np.append(time_1, [end-start], axis=0) + + start = time.process_time() + matrix_4 = np.linalg.inv(matrix_1) # 矩阵求逆 + end = time.process_time() + time_2 = np.append(time_2, [end-start], axis=0) + + start = time.process_time() + eigenvalue, eigenvector = np.linalg.eig(matrix_1) # 求矩阵本征值 + end = time.process_time() + time_3 = np.append(time_3, [end-start], axis=0) + + + +end_all = time.process_time() +print('总共运行时间:', (end_all-start_all)/60, '分') + +plt.subplot(131) +plt.xlabel('n^3/10^9') +plt.ylabel('时间(秒)') +plt.title('矩阵乘积') +plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_1, 'o-') + +plt.subplot(132) +plt.xlabel('n^3/10^9') +plt.title('矩阵求逆') +plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_2, 'o-') + +plt.subplot(133) +plt.xlabel('n^3/10^9') +plt.title('求矩阵本征值') +plt.plot((n_all/10**3)*(n_all/10**3)*(n_all/10**3), time_3, 'o-') + +plt.rcParams['font.sans-serif'] = ['SimHei'] # 在画图中正常显示中文 +plt.rcParams['axes.unicode_minus'] = False # 中文化后,加上这个使正常显示负号 plt.show() \ No newline at end of file diff --git a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_Eigenvectors.nb b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_Eigenvectors.nb old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_Eigenvectors.nb rename to academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_Eigenvectors.nb index e654c98..fedd8ff --- a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_Eigenvectors.nb +++ b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_Eigenvectors.nb @@ -1,73 +1,73 @@ -(* 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[ 2028, 65] -NotebookOptionsPosition[ 1687, 50] -NotebookOutlinePosition[ 2075, 67] -CellTagsIndexPosition[ 2032, 64] -WindowFrame->Normal*) - -(* Beginning of Notebook Content *) -Notebook[{ -Cell[BoxData[ - RowBox[{"\[IndentingNewLine]", - RowBox[{ - RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\[IndentingNewLine]", - RowBox[{ - RowBox[{"A", "=", - RowBox[{"{", - RowBox[{ - RowBox[{"{", - RowBox[{"3", ",", "2", ",", - RowBox[{"-", "1"}]}], "}"}], ",", - RowBox[{"{", - RowBox[{ - RowBox[{"-", "2"}], ",", - RowBox[{"-", "2"}], ",", "2"}], "}"}], ",", " ", - RowBox[{"{", - RowBox[{"3", ",", "6", ",", - RowBox[{"-", "1"}]}], "}"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", - RowBox[{"MatrixForm", "[", "A", "]"}], "\n", - RowBox[{"eigenvalue", "=", - RowBox[{"MatrixForm", "[", - RowBox[{"Eigenvalues", "[", "A", "]"}], "]"}]}], "\n", - RowBox[{"eigenvector", "=", - RowBox[{"MatrixForm", "[", - RowBox[{"Eigenvectors", "[", "A", "]"}], "]"}]}]}]}]], "Input", - CellChangeTimes->{{3.8249089321894894`*^9, 3.8249090194456663`*^9}, { - 3.8249090545199647`*^9, 3.824909158471919*^9}, {3.8249092372038407`*^9, - 3.824909243121014*^9}}, - CellLabel->"In[24]:=",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"] -}, -WindowSize->{1128, 568}, -WindowMargins->{{Automatic, 375}, {Automatic, 189}}, -Magnification:>1.2 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, 1125, 28, 238, "Input",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"] -} -] -*) - +(* 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[ 2028, 65] +NotebookOptionsPosition[ 1687, 50] +NotebookOutlinePosition[ 2075, 67] +CellTagsIndexPosition[ 2032, 64] +WindowFrame->Normal*) + +(* Beginning of Notebook Content *) +Notebook[{ +Cell[BoxData[ + RowBox[{"\[IndentingNewLine]", + RowBox[{ + RowBox[{"Clear", "[", "\"\<`*\>\"", "]"}], "\[IndentingNewLine]", + RowBox[{ + RowBox[{"A", "=", + RowBox[{"{", + RowBox[{ + RowBox[{"{", + RowBox[{"3", ",", "2", ",", + RowBox[{"-", "1"}]}], "}"}], ",", + RowBox[{"{", + RowBox[{ + RowBox[{"-", "2"}], ",", + RowBox[{"-", "2"}], ",", "2"}], "}"}], ",", " ", + RowBox[{"{", + RowBox[{"3", ",", "6", ",", + RowBox[{"-", "1"}]}], "}"}]}], "}"}]}], ";"}], "\[IndentingNewLine]", + RowBox[{"MatrixForm", "[", "A", "]"}], "\n", + RowBox[{"eigenvalue", "=", + RowBox[{"MatrixForm", "[", + RowBox[{"Eigenvalues", "[", "A", "]"}], "]"}]}], "\n", + RowBox[{"eigenvector", "=", + RowBox[{"MatrixForm", "[", + RowBox[{"Eigenvectors", "[", "A", "]"}], "]"}]}]}]}]], "Input", + CellChangeTimes->{{3.8249089321894894`*^9, 3.8249090194456663`*^9}, { + 3.8249090545199647`*^9, 3.824909158471919*^9}, {3.8249092372038407`*^9, + 3.824909243121014*^9}}, + CellLabel->"In[24]:=",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"] +}, +WindowSize->{1128, 568}, +WindowMargins->{{Automatic, 375}, {Automatic, 189}}, +Magnification:>1.2 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, 1125, 28, 238, "Input",ExpressionUUID->"54dc89aa-0cf7-4c91-9e21-ea7b96cf97e8"] +} +] +*) + diff --git a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_eig.m b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_eig.m old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_eig.m rename to academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_eig.m index 1439f2f..4a3ae9d --- a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_eig.m +++ b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_eig.m @@ -1,3 +1,3 @@ -clc;clear all; -A = [3, 2, -1; -2, -2, 2; 3, 6, -1] +clc;clear all; +A = [3, 2, -1; -2, -2, 2; 3, 6, -1] [V,D] = eig(A) \ No newline at end of file diff --git a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_geev.f90 b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_geev.f90 old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_geev.f90 rename to academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_geev.f90 index 55b5d7f..a3f02f9 --- a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_geev.f90 +++ b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_geev.f90 @@ -1,40 +1,40 @@ -program main - use lapack95 - implicit none - integer i,j,info - complex*16 A(3,3), eigenvalues(3), eigenvectors(3,3) - - A(1,1)=(3.d0, 0.d0) - A(1,2)=(2.d0, 0.d0) - A(1,3)=(-1.d0, 0.d0) - A(2,1)=(-2.d0, 0.d0) - A(2,2)=(-2.d0, 0.d0) - A(2,3)=(2.d0, 0.d0) - A(3,1)=(3.d0, 0.d0) - A(3,2)=(6.d0, 0.d0) - A(3,3)=(-1.d0, 0.d0) - - write(*,*) 'matrix:' - do i=1,3 - do j=1,3 - write(*,"(f10.4, '+1i*',f7.4)",advance='no') A(i,j) ! ѭΪеָ - enddo - write(*,*) '' - enddo - - call geev(A=A, W=eigenvalues, VR=eigenvectors, INFO=info) - - write(*,*) 'eigenvectors:' - do i=1,3 - do j=1,3 - write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvectors(i,j) ! ѭΪеָꡣΪ - enddo - write(*,*) '' - enddo - write(*,*) 'eigenvalues:' - do i=1,3 - write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvalues(i) - enddo - write(*,*) '' - write(*,*) '' +program main + use lapack95 + implicit none + integer i,j,info + complex*16 A(3,3), eigenvalues(3), eigenvectors(3,3) + + A(1,1)=(3.d0, 0.d0) + A(1,2)=(2.d0, 0.d0) + A(1,3)=(-1.d0, 0.d0) + A(2,1)=(-2.d0, 0.d0) + A(2,2)=(-2.d0, 0.d0) + A(2,3)=(2.d0, 0.d0) + A(3,1)=(3.d0, 0.d0) + A(3,2)=(6.d0, 0.d0) + A(3,3)=(-1.d0, 0.d0) + + write(*,*) 'matrix:' + do i=1,3 + do j=1,3 + write(*,"(f10.4, '+1i*',f7.4)",advance='no') A(i,j) ! ѭΪеָ + enddo + write(*,*) '' + enddo + + call geev(A=A, W=eigenvalues, VR=eigenvectors, INFO=info) + + write(*,*) 'eigenvectors:' + do i=1,3 + do j=1,3 + write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvectors(i,j) ! ѭΪеָꡣΪ + enddo + write(*,*) '' + enddo + write(*,*) 'eigenvalues:' + do i=1,3 + write(*,"(f10.4, '+1i*',f7.4)",advance='no') eigenvalues(i) + enddo + write(*,*) '' + write(*,*) '' end program \ No newline at end of file diff --git a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_hermitian_matrix.py b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_hermitian_matrix.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_hermitian_matrix.py rename to academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_hermitian_matrix.py index 8815fd0..ff43857 --- a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_hermitian_matrix.py +++ b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_hermitian_matrix.py @@ -1,21 +1,21 @@ -import numpy as np - -A = np.array([[3, 2+1j, -1], [2-1j, -2, 6], [-1, 6, 1]]) -eigenvalue, eigenvector = np.linalg.eig(A) -print('矩阵:\n', A) -print('特征值:\n', eigenvalue) -print('特征向量:\n', eigenvector) - -print('\n判断是否正交:\n', np.dot(eigenvector.transpose().conj(), eigenvector)) -print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose().conj())) - -print('特征向量矩阵的列向量模方和:') -for i in range(3): - print(np.abs(eigenvector[0, i])**2+np.abs(eigenvector[1, i])**2+np.abs(eigenvector[2, i])**2) -print('特征向量矩阵的行向量模方和:') -for i in range(3): - print(np.abs(eigenvector[i, 0])**2+np.abs(eigenvector[i, 1])**2+np.abs(eigenvector[i, 2])**2) - -print('\n对角化验证:') -print(np.dot(np.dot(eigenvector.transpose().conj(), A), eigenvector)) +import numpy as np + +A = np.array([[3, 2+1j, -1], [2-1j, -2, 6], [-1, 6, 1]]) +eigenvalue, eigenvector = np.linalg.eig(A) +print('矩阵:\n', A) +print('特征值:\n', eigenvalue) +print('特征向量:\n', eigenvector) + +print('\n判断是否正交:\n', np.dot(eigenvector.transpose().conj(), eigenvector)) +print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose().conj())) + +print('特征向量矩阵的列向量模方和:') +for i in range(3): + print(np.abs(eigenvector[0, i])**2+np.abs(eigenvector[1, i])**2+np.abs(eigenvector[2, i])**2) +print('特征向量矩阵的行向量模方和:') +for i in range(3): + print(np.abs(eigenvector[i, 0])**2+np.abs(eigenvector[i, 1])**2+np.abs(eigenvector[i, 2])**2) + +print('\n对角化验证:') +print(np.dot(np.dot(eigenvector.transpose().conj(), A), eigenvector)) print(np.dot(np.dot(eigenvector, A), eigenvector.transpose().conj())) \ No newline at end of file diff --git a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_numpy.linalg.eig.py b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_numpy.linalg.eig.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_numpy.linalg.eig.py rename to academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_numpy.linalg.eig.py index 62e5d19..0a113bf --- a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_numpy.linalg.eig.py +++ b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_numpy.linalg.eig.py @@ -1,18 +1,18 @@ -import numpy as np - -A = np.array([[3, 2, -1], [-2, -2, 2], [3, 6, -1]]) -eigenvalue, eigenvector = np.linalg.eig(A) -print('矩阵:\n', A) -print('特征值:\n', eigenvalue) -print('特征向量:\n', eigenvector) -print('特征值为-4对应的特征向量理论值:\n', np.array([1/3, -2/3, 1])/np.sqrt((1/3)**2+(-2/3)**2+1**2)) - -print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) -print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) - -print('特征向量矩阵的列向量模方和:') -for i in range(3): - print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2) -print('特征向量矩阵的行向量模方和:') -for i in range(3): +import numpy as np + +A = np.array([[3, 2, -1], [-2, -2, 2], [3, 6, -1]]) +eigenvalue, eigenvector = np.linalg.eig(A) +print('矩阵:\n', A) +print('特征值:\n', eigenvalue) +print('特征向量:\n', eigenvector) +print('特征值为-4对应的特征向量理论值:\n', np.array([1/3, -2/3, 1])/np.sqrt((1/3)**2+(-2/3)**2+1**2)) + +print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) +print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) + +print('特征向量矩阵的列向量模方和:') +for i in range(3): + print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2) +print('特征向量矩阵的行向量模方和:') +for i in range(3): print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2) \ No newline at end of file diff --git a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix.py b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix.py rename to academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix.py index 99f34e5..b98f737 --- a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix.py +++ b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix.py @@ -1,21 +1,21 @@ -import numpy as np - -A = np.array([[3, 2, -1], [2, -2, 6], [-1, 6, 1]]) -eigenvalue, eigenvector = np.linalg.eig(A) -print('矩阵:\n', A) -print('特征值:\n', eigenvalue) -print('特征向量:\n', eigenvector) - -print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) -print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) - -print('特征向量矩阵的列向量模方和:') -for i in range(3): - print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2) -print('特征向量矩阵的行向量模方和:') -for i in range(3): - print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2) - -print('\n对角化验证:') -print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector)) +import numpy as np + +A = np.array([[3, 2, -1], [2, -2, 6], [-1, 6, 1]]) +eigenvalue, eigenvector = np.linalg.eig(A) +print('矩阵:\n', A) +print('特征值:\n', eigenvalue) +print('特征向量:\n', eigenvector) + +print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) +print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) + +print('特征向量矩阵的列向量模方和:') +for i in range(3): + print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2) +print('特征向量矩阵的行向量模方和:') +for i in range(3): + print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2) + +print('\n对角化验证:') +print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector)) print(np.dot(np.dot(eigenvector, A), eigenvector.transpose())) \ No newline at end of file diff --git a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix2.py b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix2.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix2.py rename to academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix2.py index c7d9d97..dd07a26 --- a/academic_codes/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix2.py +++ b/academic_codes/others/2021.03.17_verify_the_orientation_of_eigenvector_in_matrix/example_real_symmetric_matrix2.py @@ -1,32 +1,32 @@ -import numpy as np - -A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]]) -eigenvalue, eigenvector = np.linalg.eig(A) -print('矩阵:\n', A) -print('特征值:\n', eigenvalue) -print('特征向量:\n', eigenvector) - -print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) -print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) - -print('特征向量矩阵的列向量模方和:') -for i in range(4): - print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2+eigenvector[3, i]**2) -print('特征向量矩阵的行向量模方和:') -for i in range(4): - print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2+eigenvector[i, 3]**2) - -print('\n对角化验证:') -print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector)) -print(np.dot(np.dot(eigenvector, A), eigenvector.transpose())) - -print('\n特征向量理论值:') -T = np.array([[1/np.sqrt(2), 1/np.sqrt(6), -1/np.sqrt(12), 1/2], [1/np.sqrt(2), -1/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 2/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 0, 3/np.sqrt(12), 1/2]]) -print(T) - -print('\n判断是否正交:\n', np.dot(T.transpose(), T)) -print('判断是否正交:\n', np.dot(T, T.transpose())) - -print('\n对角化验证:') -print(np.dot(np.dot(T.transpose(), A), T)) +import numpy as np + +A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]]) +eigenvalue, eigenvector = np.linalg.eig(A) +print('矩阵:\n', A) +print('特征值:\n', eigenvalue) +print('特征向量:\n', eigenvector) + +print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) +print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) + +print('特征向量矩阵的列向量模方和:') +for i in range(4): + print(eigenvector[0, i]**2+eigenvector[1, i]**2+eigenvector[2, i]**2+eigenvector[3, i]**2) +print('特征向量矩阵的行向量模方和:') +for i in range(4): + print(eigenvector[i, 0]**2+eigenvector[i, 1]**2+eigenvector[i, 2]**2+eigenvector[i, 3]**2) + +print('\n对角化验证:') +print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector)) +print(np.dot(np.dot(eigenvector, A), eigenvector.transpose())) + +print('\n特征向量理论值:') +T = np.array([[1/np.sqrt(2), 1/np.sqrt(6), -1/np.sqrt(12), 1/2], [1/np.sqrt(2), -1/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 2/np.sqrt(6), 1/np.sqrt(12), -1/2], [0, 0, 3/np.sqrt(12), 1/2]]) +print(T) + +print('\n判断是否正交:\n', np.dot(T.transpose(), T)) +print('判断是否正交:\n', np.dot(T, T.transpose())) + +print('\n对角化验证:') +print(np.dot(np.dot(T.transpose(), A), T)) print(np.dot(np.dot(T, A), T.transpose())) \ No newline at end of file diff --git a/academic_codes/2021.03.19_Schmidt_orthogonalization/Schmidt_orthogonalization.py b/academic_codes/others/2021.03.19_Schmidt_orthogonalization/Schmidt_orthogonalization.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.03.19_Schmidt_orthogonalization/Schmidt_orthogonalization.py rename to academic_codes/others/2021.03.19_Schmidt_orthogonalization/Schmidt_orthogonalization.py index a19fde6..8e916a4 --- a/academic_codes/2021.03.19_Schmidt_orthogonalization/Schmidt_orthogonalization.py +++ b/academic_codes/others/2021.03.19_Schmidt_orthogonalization/Schmidt_orthogonalization.py @@ -1,44 +1,44 @@ -""" -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/10890 -""" - -import numpy as np - - -def main(): - A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]]) - eigenvalue, eigenvector = np.linalg.eig(A) - print('矩阵:\n', A) - print('特征值:\n', eigenvalue) - print('特征向量:\n', eigenvector) - - print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) - print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) - - print('对角化验证:') - print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector)) - - # 施密斯正交化 - eigenvector = Schmidt_orthogonalization(eigenvector) - - print('\n施密斯正交化后,特征向量:\n', eigenvector) - - print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) - print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) - - print('施密斯正交化后,对角化验证:') - print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector)) - - -def Schmidt_orthogonalization(eigenvector): - num = eigenvector.shape[1] - for i in range(num): - for i0 in range(i): - eigenvector[:, i] = eigenvector[:, i] - eigenvector[:, i0]*np.dot(eigenvector[:, i].transpose().conj(), eigenvector[:, i0])/(np.dot(eigenvector[:, i0].transpose().conj(),eigenvector[:, i0])) - eigenvector[:, i] = eigenvector[:, i]/np.linalg.norm(eigenvector[:, i]) - return eigenvector - - -if __name__ == '__main__': +""" +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/10890 +""" + +import numpy as np + + +def main(): + A = np.array([[0, 1, 1, -1], [1, 0, -1, 1], [1, -1, 0, 1], [-1, 1, 1, 0]]) + eigenvalue, eigenvector = np.linalg.eig(A) + print('矩阵:\n', A) + print('特征值:\n', eigenvalue) + print('特征向量:\n', eigenvector) + + print('\n判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) + print('判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) + + print('对角化验证:') + print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector)) + + # 施密斯正交化 + eigenvector = Schmidt_orthogonalization(eigenvector) + + print('\n施密斯正交化后,特征向量:\n', eigenvector) + + print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector.transpose(), eigenvector)) + print('施密斯正交化后,判断是否正交:\n', np.dot(eigenvector, eigenvector.transpose())) + + print('施密斯正交化后,对角化验证:') + print(np.dot(np.dot(eigenvector.transpose(), A), eigenvector)) + + +def Schmidt_orthogonalization(eigenvector): + num = eigenvector.shape[1] + for i in range(num): + for i0 in range(i): + eigenvector[:, i] = eigenvector[:, i] - eigenvector[:, i0]*np.dot(eigenvector[:, i].transpose().conj(), eigenvector[:, i0])/(np.dot(eigenvector[:, i0].transpose().conj(),eigenvector[:, i0])) + eigenvector[:, i] = eigenvector[:, i]/np.linalg.norm(eigenvector[:, i]) + return eigenvector + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors.py b/academic_codes/others/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors.py similarity index 100% rename from academic_codes/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors.py rename to academic_codes/others/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors.py diff --git a/academic_codes/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors_with_guan.py b/academic_codes/others/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors_with_guan.py similarity index 100% rename from academic_codes/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors_with_guan.py rename to academic_codes/others/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors_with_guan.py diff --git a/academic_codes/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors_with_sympy.py b/academic_codes/others/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors_with_sympy.py similarity index 100% rename from academic_codes/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors_with_sympy.py rename to academic_codes/others/2021.07.19_calculate_reciprocal_lattice_vectors/calculate_reciprocal_lattice_vectors_with_sympy.py diff --git a/academic_codes/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_using_Green_functions.py b/academic_codes/quantum_transport/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_using_Green_functions.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_using_Green_functions.py rename to academic_codes/quantum_transport/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_using_Green_functions.py index 94aad57..12a8040 --- a/academic_codes/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_using_Green_functions.py +++ b/academic_codes/quantum_transport/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_using_Green_functions.py @@ -1,101 +1,101 @@ -""" -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/948 -""" - -import numpy as np -import matplotlib.pyplot as plt -import copy -import time - - -def matrix_00(width=10): # 不赋值时默认为10 - h00 = np.zeros((width, width)) - for width0 in range(width-1): - h00[width0, width0+1] = 1 - h00[width0+1, width0] = 1 - return h00 - - -def matrix_01(width=10): # 不赋值时默认为10 - h01 = np.identity(width) - return h01 - - -def main(): - start_time = time.time() - h00 = matrix_00(width=5) - h01 = matrix_01(width=5) - fermi_energy_array = np.arange(-4, 4, .01) - plot_conductance_energy(fermi_energy_array, h00, h01) - end_time = time.time() - print('运行时间=', end_time-start_time) - - -def plot_conductance_energy(fermi_energy_array, h00, h01): # 画电导与费米能关系图 - dim = fermi_energy_array.shape[0] - cond = np.zeros(dim) - i0 = 0 - for fermi_energy0 in fermi_energy_array: - cond0 = np.real(conductance(fermi_energy0 + 1e-12j, h00, h01)) - cond[i0] = cond0 - i0 += 1 - plt.plot(fermi_energy_array, cond, '-k') - plt.show() - - -def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T。dim是传递矩阵h00和h01的维度 - transfer = np.zeros((2*dim, 2*dim), dtype=complex) - transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) # np.dot()等效于np.matmul() - transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj()) - transfer[dim:2*dim, 0:dim] = np.identity(dim) - transfer[dim:2*dim, dim:2*dim] = 0 # a:b代表 a <= x < b,左闭右开 - return transfer # 返回转移矩阵 - - -def green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数 - transfer = transfer_matrix(fermi_energy, h00, h01, dim) - eigenvalue, eigenvector = np.linalg.eig(transfer) - ind = np.argsort(np.abs(eigenvalue)) - temp = np.zeros((2*dim, 2*dim), dtype=complex) - i0 = 0 - for ind0 in ind: - temp[:, i0] = eigenvector[:, ind0] - i0 += 1 - s1 = temp[dim:2*dim, 0:dim] - s2 = temp[0:dim, 0:dim] - s3 = temp[dim:2*dim, dim:2*dim] - s4 = temp[0:dim, dim:2*dim] - right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1))) - left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4))) - return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数 - - -def self_energy_lead(fermi_energy, h00, h01, dim): # 电极的自能 - right_lead_surface, left_lead_surface = green_function_lead(fermi_energy, h00, h01, dim) - right_self_energy = np.dot(np.dot(h01, right_lead_surface), h01.transpose().conj()) - left_self_energy = np.dot(np.dot(h01.transpose().conj(), left_lead_surface), h01) - return right_self_energy, left_self_energy # 返回右边电极自能和左边电极自能 - - -def conductance(fermi_energy, h00, h01, nx=300): # 计算电导 - dim = h00.shape[0] - right_self_energy, left_self_energy = self_energy_lead(fermi_energy, h00, h01, dim) - for ix in range(nx): - if ix == 0: - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy) - green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于,两个变量会指向相同的id,改变一个值,另外一个值可能会发生改变,容易出错,所以要用上这个COPY - elif ix != nx-1: - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) - green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) - else: - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)-right_self_energy) - green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) - gamma_right = (right_self_energy - right_self_energy.transpose().conj())*(0+1j) - gamma_left = (left_self_energy - left_self_energy.transpose().conj())*(0+1j) - transmission = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj())) - return transmission # 返回电导值 - - -if __name__ == '__main__': - main() +""" +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/948 +""" + +import numpy as np +import matplotlib.pyplot as plt +import copy +import time + + +def matrix_00(width=10): # 不赋值时默认为10 + h00 = np.zeros((width, width)) + for width0 in range(width-1): + h00[width0, width0+1] = 1 + h00[width0+1, width0] = 1 + return h00 + + +def matrix_01(width=10): # 不赋值时默认为10 + h01 = np.identity(width) + return h01 + + +def main(): + start_time = time.time() + h00 = matrix_00(width=5) + h01 = matrix_01(width=5) + fermi_energy_array = np.arange(-4, 4, .01) + plot_conductance_energy(fermi_energy_array, h00, h01) + end_time = time.time() + print('运行时间=', end_time-start_time) + + +def plot_conductance_energy(fermi_energy_array, h00, h01): # 画电导与费米能关系图 + dim = fermi_energy_array.shape[0] + cond = np.zeros(dim) + i0 = 0 + for fermi_energy0 in fermi_energy_array: + cond0 = np.real(conductance(fermi_energy0 + 1e-12j, h00, h01)) + cond[i0] = cond0 + i0 += 1 + plt.plot(fermi_energy_array, cond, '-k') + plt.show() + + +def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T。dim是传递矩阵h00和h01的维度 + transfer = np.zeros((2*dim, 2*dim), dtype=complex) + transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) # np.dot()等效于np.matmul() + transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj()) + transfer[dim:2*dim, 0:dim] = np.identity(dim) + transfer[dim:2*dim, dim:2*dim] = 0 # a:b代表 a <= x < b,左闭右开 + return transfer # 返回转移矩阵 + + +def green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数 + transfer = transfer_matrix(fermi_energy, h00, h01, dim) + eigenvalue, eigenvector = np.linalg.eig(transfer) + ind = np.argsort(np.abs(eigenvalue)) + temp = np.zeros((2*dim, 2*dim), dtype=complex) + i0 = 0 + for ind0 in ind: + temp[:, i0] = eigenvector[:, ind0] + i0 += 1 + s1 = temp[dim:2*dim, 0:dim] + s2 = temp[0:dim, 0:dim] + s3 = temp[dim:2*dim, dim:2*dim] + s4 = temp[0:dim, dim:2*dim] + right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1))) + left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4))) + return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数 + + +def self_energy_lead(fermi_energy, h00, h01, dim): # 电极的自能 + right_lead_surface, left_lead_surface = green_function_lead(fermi_energy, h00, h01, dim) + right_self_energy = np.dot(np.dot(h01, right_lead_surface), h01.transpose().conj()) + left_self_energy = np.dot(np.dot(h01.transpose().conj(), left_lead_surface), h01) + return right_self_energy, left_self_energy # 返回右边电极自能和左边电极自能 + + +def conductance(fermi_energy, h00, h01, nx=300): # 计算电导 + dim = h00.shape[0] + right_self_energy, left_self_energy = self_energy_lead(fermi_energy, h00, h01, dim) + for ix in range(nx): + if ix == 0: + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy) + green_0n_n = copy.deepcopy(green_nn_n) # 如果直接用等于,两个变量会指向相同的id,改变一个值,另外一个值可能会发生改变,容易出错,所以要用上这个COPY + elif ix != nx-1: + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) + green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) + else: + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)-right_self_energy) + green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) + gamma_right = (right_self_energy - right_self_energy.transpose().conj())*(0+1j) + gamma_left = (left_self_energy - left_self_energy.transpose().conj())*(0+1j) + transmission = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj())) + return transmission # 返回电导值 + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_with_guan.py.py b/academic_codes/quantum_transport/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_with_guan.py.py similarity index 100% rename from academic_codes/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_with_guan.py.py rename to academic_codes/quantum_transport/2019.11.01_conductance_calculation_using_Green_functions/conductance_calculation_with_guan.py.py diff --git a/academic_codes/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/Hamiltonian_of_square_lattice_in_kwant.py b/academic_codes/quantum_transport/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/Hamiltonian_of_square_lattice_in_kwant.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/Hamiltonian_of_square_lattice_in_kwant.py rename to academic_codes/quantum_transport/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/Hamiltonian_of_square_lattice_in_kwant.py index 9331db0..b9e35f4 --- a/academic_codes/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/Hamiltonian_of_square_lattice_in_kwant.py +++ b/academic_codes/quantum_transport/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/Hamiltonian_of_square_lattice_in_kwant.py @@ -1,56 +1,56 @@ -""" -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/2033 -""" - -import kwant -import matplotlib.pyplot as plt - - -def main(): - L = 3 - W = 2 - - lat = kwant.lattice.square(a=1, norbs=1) # 定义lattice - print('\nlat:\n', lat) - - syst = kwant.Builder() # 定义中心区的Builder - print('\nsyst:\n', syst) - - syst_finalized = syst.finalized() - hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量 - print('\nhamiltonian_1(定义):\n', hamiltonian) - - syst[(lat(x, y) for x in range(L) for y in range(W))] = 0 # 晶格初始化为0 - - kwant.plot(syst) # 画出syst的示意图 - - syst_finalized = syst.finalized() - hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量 - print('\nhamiltonian_2(初始化):\n', hamiltonian) - - syst[lat.neighbors()] = 1 # 添加最近邻跃迁 - - kwant.plot(syst) # 画出syst的示意图 - - syst_finalized = syst.finalized() - hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量 - print('\nhamiltonian_3(最近邻赋值):\n', hamiltonian) - - lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) # 定义电极的Builder - lead[(lat(0, j) for j in range(W))] = 0 # 电极晶格初始化 - lead[lat.neighbors()] = 1 # 添加最近邻跃迁 - syst.attach_lead(lead) # 中心区加上左电极 - syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极 - - # 画出syst的示意图 - kwant.plot(syst) - - # 查看哈密顿量(加了电极后,并不影响syst哈密顿量) - syst_finalized = syst.finalized() - hamiltonian = syst_finalized.hamiltonian_submatrix() - print('\nhamiltonian_4(加了电极后):\n', hamiltonian) - - -if __name__ == '__main__': +""" +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/2033 +""" + +import kwant +import matplotlib.pyplot as plt + + +def main(): + L = 3 + W = 2 + + lat = kwant.lattice.square(a=1, norbs=1) # 定义lattice + print('\nlat:\n', lat) + + syst = kwant.Builder() # 定义中心区的Builder + print('\nsyst:\n', syst) + + syst_finalized = syst.finalized() + hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量 + print('\nhamiltonian_1(定义):\n', hamiltonian) + + syst[(lat(x, y) for x in range(L) for y in range(W))] = 0 # 晶格初始化为0 + + kwant.plot(syst) # 画出syst的示意图 + + syst_finalized = syst.finalized() + hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量 + print('\nhamiltonian_2(初始化):\n', hamiltonian) + + syst[lat.neighbors()] = 1 # 添加最近邻跃迁 + + kwant.plot(syst) # 画出syst的示意图 + + syst_finalized = syst.finalized() + hamiltonian = syst_finalized.hamiltonian_submatrix() # 查看哈密顿量 + print('\nhamiltonian_3(最近邻赋值):\n', hamiltonian) + + lead = kwant.Builder(kwant.TranslationalSymmetry((-1, 0))) # 定义电极的Builder + lead[(lat(0, j) for j in range(W))] = 0 # 电极晶格初始化 + lead[lat.neighbors()] = 1 # 添加最近邻跃迁 + syst.attach_lead(lead) # 中心区加上左电极 + syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极 + + # 画出syst的示意图 + kwant.plot(syst) + + # 查看哈密顿量(加了电极后,并不影响syst哈密顿量) + syst_finalized = syst.finalized() + hamiltonian = syst_finalized.hamiltonian_submatrix() + print('\nhamiltonian_4(加了电极后):\n', hamiltonian) + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/kwant_example.py b/academic_codes/quantum_transport/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/kwant_example.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/kwant_example.py rename to academic_codes/quantum_transport/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/kwant_example.py index 072cf5f..db66d0f --- a/academic_codes/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/kwant_example.py +++ b/academic_codes/quantum_transport/2019.11.19_kwant_a_package_of_calculations_in_quantum_transport/kwant_example.py @@ -1,94 +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/2033 -""" - -import kwant -import numpy as np -from matplotlib import pyplot - - -def make_system(): - a = 1 # 晶格常数 - lat = kwant.lattice.square(a) # 创建晶格,方格子 - - syst = kwant.Builder() # 建立中心体系 - t = 1.0 # hopping值 - W = 5 # 中心体系宽度 - L = 40 # 中心体系长度 - - # 给中心体系赋值 - for i in range(L): - for j in range(W): - syst[lat(i, j)] = 0 - if j > 0: - syst[lat(i, j), lat(i, j-1)] = -t # hopping in y-direction - if i > 0: - syst[lat(i, j), lat(i-1, j)] = -t # hopping in x-direction - - sym_left_lead = kwant.TranslationalSymmetry((-a, 0)) # 电极的平移对称性,(-a, 0)代表远离中心区的方向,向左 - left_lead = kwant.Builder(sym_left_lead) # 建立左电极体系 - # 给电极体系赋值 - for j in range(W): - left_lead[lat(0, j)] = 0 - if j > 0: - left_lead[lat(0, j), lat(0, j - 1)] = -t - left_lead[lat(1, j), lat(0, j)] = -t # 这里写一个即可,因为平移对称性已经声明了 - syst.attach_lead(left_lead) # 把左电极接在中心区 - - sym_right_lead = kwant.TranslationalSymmetry((a, 0)) - right_lead = kwant.Builder(sym_right_lead) - for j in range(W): - right_lead[lat(0, j)] = 0 - if j > 0: - right_lead[lat(0, j), lat(0, j - 1)] = -t - right_lead[lat(1, j), lat(0, j)] = -t - syst.attach_lead(right_lead) # 把右电极接在中心区 - - kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错 - syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。 - return syst - - -def make_system_with_less_code(): - a = 1 # 晶格常数 - lat = kwant.lattice.square(a) # 创建晶格,方格子 - - syst = kwant.Builder() # 建立中心体系 - t = 1.0 # hopping值 - W = 5 # 中心体系宽度 - L = 40 # 中心体系长度 - - # 中心区 - syst[(lat(x, y) for x in range(L) for y in range(W))] = 0 - syst[lat.neighbors()] = -t # 用neighbors()方法 - - # 电极 - lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0))) - lead[(lat(0, j) for j in range(W))] = 0 - lead[lat.neighbors()] = -t # 用neighbors()方法 - syst.attach_lead(lead) # 左电极 - syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极 - - kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错 - syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。 - return syst - - -def main(): - syst = make_system() - # syst = make_system_with_less_code() # 和上面的一样,只是用更少的代码写 - energies = np.linspace(-4, 4, 200) - data = [] - for energy in energies: - smatrix = kwant.smatrix(syst, energy) # compute the transmission probability from lead 0 to lead 1 - data.append(smatrix.transmission(1, 0)) - pyplot.plot(energies, data) - pyplot.xlabel("energy [t]") - pyplot.ylabel("conductance [e^2/h]") - pyplot.show() - # pyplot.savefig('conductance' + '.eps') - - -if __name__ == '__main__': - main() +""" +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/2033 +""" + +import kwant +import numpy as np +from matplotlib import pyplot + + +def make_system(): + a = 1 # 晶格常数 + lat = kwant.lattice.square(a) # 创建晶格,方格子 + + syst = kwant.Builder() # 建立中心体系 + t = 1.0 # hopping值 + W = 5 # 中心体系宽度 + L = 40 # 中心体系长度 + + # 给中心体系赋值 + for i in range(L): + for j in range(W): + syst[lat(i, j)] = 0 + if j > 0: + syst[lat(i, j), lat(i, j-1)] = -t # hopping in y-direction + if i > 0: + syst[lat(i, j), lat(i-1, j)] = -t # hopping in x-direction + + sym_left_lead = kwant.TranslationalSymmetry((-a, 0)) # 电极的平移对称性,(-a, 0)代表远离中心区的方向,向左 + left_lead = kwant.Builder(sym_left_lead) # 建立左电极体系 + # 给电极体系赋值 + for j in range(W): + left_lead[lat(0, j)] = 0 + if j > 0: + left_lead[lat(0, j), lat(0, j - 1)] = -t + left_lead[lat(1, j), lat(0, j)] = -t # 这里写一个即可,因为平移对称性已经声明了 + syst.attach_lead(left_lead) # 把左电极接在中心区 + + sym_right_lead = kwant.TranslationalSymmetry((a, 0)) + right_lead = kwant.Builder(sym_right_lead) + for j in range(W): + right_lead[lat(0, j)] = 0 + if j > 0: + right_lead[lat(0, j), lat(0, j - 1)] = -t + right_lead[lat(1, j), lat(0, j)] = -t + syst.attach_lead(right_lead) # 把右电极接在中心区 + + kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错 + syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。 + return syst + + +def make_system_with_less_code(): + a = 1 # 晶格常数 + lat = kwant.lattice.square(a) # 创建晶格,方格子 + + syst = kwant.Builder() # 建立中心体系 + t = 1.0 # hopping值 + W = 5 # 中心体系宽度 + L = 40 # 中心体系长度 + + # 中心区 + syst[(lat(x, y) for x in range(L) for y in range(W))] = 0 + syst[lat.neighbors()] = -t # 用neighbors()方法 + + # 电极 + lead = kwant.Builder(kwant.TranslationalSymmetry((-a, 0))) + lead[(lat(0, j) for j in range(W))] = 0 + lead[lat.neighbors()] = -t # 用neighbors()方法 + syst.attach_lead(lead) # 左电极 + syst.attach_lead(lead.reversed()) # 用reversed()方法得到右电极 + + kwant.plot(syst) # 把电极-中心区-电极图画出来,通过图像可以看出有没有写错 + syst = syst.finalized() # 结束体系的制作。这个语句不可以省。这个语句是把Builder对象转换成可计算的对象。 + return syst + + +def main(): + syst = make_system() + # syst = make_system_with_less_code() # 和上面的一样,只是用更少的代码写 + energies = np.linspace(-4, 4, 200) + data = [] + for energy in energies: + smatrix = kwant.smatrix(syst, energy) # compute the transmission probability from lead 0 to lead 1 + data.append(smatrix.transmission(1, 0)) + pyplot.plot(energies, data) + pyplot.xlabel("energy [t]") + pyplot.ylabel("conductance [e^2/h]") + pyplot.show() + # pyplot.savefig('conductance' + '.eps') + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.01.03_calculation_of_local_currents/calculation_of_local_currents.py b/academic_codes/quantum_transport/2020.01.03_calculation_of_local_currents/calculation_of_local_currents.py similarity index 100% rename from academic_codes/2020.01.03_calculation_of_local_currents/calculation_of_local_currents.py rename to academic_codes/quantum_transport/2020.01.03_calculation_of_local_currents/calculation_of_local_currents.py diff --git a/academic_codes/2020.01.03_calculation_of_local_currents/calculation_of_local_currents_with_Kwant.py b/academic_codes/quantum_transport/2020.01.03_calculation_of_local_currents/calculation_of_local_currents_with_Kwant.py similarity index 100% rename from academic_codes/2020.01.03_calculation_of_local_currents/calculation_of_local_currents_with_Kwant.py rename to academic_codes/quantum_transport/2020.01.03_calculation_of_local_currents/calculation_of_local_currents_with_Kwant.py diff --git a/academic_codes/2020.01.03_calculation_of_local_currents/calculation_of_local_currents_with_guan.py b/academic_codes/quantum_transport/2020.01.03_calculation_of_local_currents/calculation_of_local_currents_with_guan.py similarity index 100% rename from academic_codes/2020.01.03_calculation_of_local_currents/calculation_of_local_currents_with_guan.py rename to academic_codes/quantum_transport/2020.01.03_calculation_of_local_currents/calculation_of_local_currents_with_guan.py diff --git a/academic_codes/2020.10.02_calculate_scattering_matrix_by_mode_matching_method/calculate_scattering_matrix_by_mode_matching_method.py b/academic_codes/quantum_transport/2020.10.02_calculate_scattering_matrix_by_mode_matching_method/calculate_scattering_matrix_by_mode_matching_method.py old mode 100755 new mode 100644 similarity index 98% rename from academic_codes/2020.10.02_calculate_scattering_matrix_by_mode_matching_method/calculate_scattering_matrix_by_mode_matching_method.py rename to academic_codes/quantum_transport/2020.10.02_calculate_scattering_matrix_by_mode_matching_method/calculate_scattering_matrix_by_mode_matching_method.py index 0002c57..4f5bafc --- a/academic_codes/2020.10.02_calculate_scattering_matrix_by_mode_matching_method/calculate_scattering_matrix_by_mode_matching_method.py +++ b/academic_codes/quantum_transport/2020.10.02_calculate_scattering_matrix_by_mode_matching_method/calculate_scattering_matrix_by_mode_matching_method.py @@ -1,240 +1,240 @@ -""" -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/6352 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * -import copy -import time -# import os -# os.chdir('D:/data') - - -def main(): - start_time = time.time() - h00 = matrix_00() # 方格子模型 - h01 = matrix_01() # 方格子模型 - fermi_energy = 0.1 - write_transmission_matrix(fermi_energy, h00, h01) # 输出无散射的散射矩阵 - end_time = time.time() - print('运行时间=', end_time - start_time, '秒') - - -def matrix_00(width=4): - h00 = np.zeros((width, width)) - for width0 in range(width-1): - h00[width0, width0+1] = 1 - h00[width0+1, width0] = 1 - return h00 - - -def matrix_01(width=4): - h01 = np.identity(width) - return h01 - - -def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵 - transfer = np.zeros((2*dim, 2*dim))*(0+0j) - transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) - transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj()) - transfer[dim:2*dim, 0:dim] = np.identity(dim) - transfer[dim:2*dim, dim:2*dim] = 0 - return transfer - - -def complex_wave_vector(fermi_energy, h00, h01, dim): # 获取通道的复数波矢,并按照波矢的实部Re(k)排序 - transfer = transfer_matrix(fermi_energy, h00, h01, dim) - eigenvalue, eigenvector = np.linalg.eig(transfer) - k_channel = np.log(eigenvalue)/1j - ind = np.argsort(np.real(k_channel)) - k_channel = np.sort(k_channel) - temp = np.zeros((2*dim, 2*dim))*(1+0j) - temp2 = np.zeros((2*dim))*(1+0j) - i0 = 0 - for ind0 in ind: - temp[:, i0] = eigenvector[:, ind0] - temp2[i0] = eigenvalue[ind0] - i0 += 1 - eigenvalue = copy.deepcopy(temp2) - temp = normalization_of_eigenvector(temp[0:dim, :], dim) - velocity = np.zeros((2*dim))*(1+0j) - for dim0 in range(2*dim): - velocity[dim0] = eigenvalue[dim0]*np.dot(np.dot(temp[0:dim, :].transpose().conj(), h01),temp[0:dim, :])[dim0, dim0] - velocity = -2*np.imag(velocity) - eigenvector = copy.deepcopy(temp) - return k_channel, velocity, eigenvalue, eigenvector # 返回通道的对应的波矢、费米速度、本征值、本征态 - - -def normalization_of_eigenvector(eigenvector, dim): # 波函数归一化 - factor = np.zeros(2*dim)*(1+0j) - for dim0 in range(dim): - factor = factor+np.square(np.abs(eigenvector[dim0, :])) - for dim0 in range(2*dim): - eigenvector[:, dim0] = eigenvector[:, dim0]/np.sqrt(factor[dim0]) - return eigenvector - - -def calculation_of_lambda_u_f(fermi_energy, h00, h01, dim): # 对所有通道(包括active和evanescent)进行分类,并计算F - k_channel, velocity, eigenvalue, eigenvector = complex_wave_vector(fermi_energy, h00, h01, dim) - ind_right_active = 0; ind_right_evanescent = 0; ind_left_active = 0; ind_left_evanescent = 0 - k_right = np.zeros(dim)*(1+0j); k_left = np.zeros(dim)*(1+0j) - velocity_right = np.zeros(dim)*(1+0j); velocity_left = np.zeros(dim)*(1+0j) - lambda_right = np.zeros(dim)*(1+0j); lambda_left = np.zeros(dim)*(1+0j) - u_right = np.zeros((dim, dim))*(1+0j); u_left = np.zeros((dim, dim))*(1+0j) - for dim0 in range(2*dim): - if_active = if_active_channel(k_channel[dim0]) - direction = direction_of_channel(velocity[dim0], k_channel[dim0]) - if direction == 1: # 向右运动的通道 - if if_active == 1: # 可传播通道(active channel) - k_right[ind_right_active] = k_channel[dim0] - velocity_right[ind_right_active] = velocity[dim0] - lambda_right[ind_right_active] = eigenvalue[dim0] - u_right[:, ind_right_active] = eigenvector[:, dim0] - ind_right_active += 1 - else: # 衰减通道(evanescent channel) - k_right[dim-1-ind_right_evanescent] = k_channel[dim0] - velocity_right[dim-1-ind_right_evanescent] = velocity[dim0] - lambda_right[dim-1-ind_right_evanescent] = eigenvalue[dim0] - u_right[:, dim-1-ind_right_evanescent] = eigenvector[:, dim0] - ind_right_evanescent += 1 - else: # 向左运动的通道 - if if_active == 1: # 可传播通道(active channel) - k_left[ind_left_active] = k_channel[dim0] - velocity_left[ind_left_active] = velocity[dim0] - lambda_left[ind_left_active] = eigenvalue[dim0] - u_left[:, ind_left_active] = eigenvector[:, dim0] - ind_left_active += 1 - else: # 衰减通道(evanescent channel) - k_left[dim-1-ind_left_evanescent] = k_channel[dim0] - velocity_left[dim-1-ind_left_evanescent] = velocity[dim0] - lambda_left[dim-1-ind_left_evanescent] = eigenvalue[dim0] - u_left[:, dim-1-ind_left_evanescent] = eigenvector[:, dim0] - ind_left_evanescent += 1 - lambda_matrix_right = np.diag(lambda_right) - lambda_matrix_left = np.diag(lambda_left) - f_right = np.dot(np.dot(u_right, lambda_matrix_right), np.linalg.inv(u_right)) - f_left = np.dot(np.dot(u_left, lambda_matrix_left), np.linalg.inv(u_left)) - return k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active - # 分别返回向右和向左的运动的波矢k、费米速度velocity、F值、U值、可向右传播的通道数 - - -def if_active_channel(k_channel): # 判断是可传播通道还是衰减通道 - if np.abs(np.imag(k_channel)) < 1e-7: - if_active = 1 - else: - if_active = 0 - return if_active - - -def direction_of_channel(velocity, k_channel): # 判断通道对应的费米速度方向 - if if_active_channel(k_channel) == 1: - direction = np.sign(velocity) - else: - direction = np.sign(np.imag(k_channel)) - return direction - - -def calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算格林函数 - k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_lambda_u_f(fermi_energy, h00, h01, dim) - right_self_energy = np.dot(h01, f_right) - left_self_energy = np.dot(h01.transpose().conj(), np.linalg.inv(f_left)) - nx = 300 - for nx0 in range(nx): - if nx0 == 0: - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy) - green_00_n = copy.deepcopy(green_nn_n) - green_0n_n = copy.deepcopy(green_nn_n) - green_n0_n = copy.deepcopy(green_nn_n) - elif nx0 != nx-1: - if scatter_type == 0: # 无散射 - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) - elif scatter_type == 1: # 势垒散射 - h00_scatter = h00 + scatter_intensity * np.identity(dim) - if int(nx/2)-int(scatter_length/2) <= nx0 < int(nx/2)+int((scatter_length+1)/2): - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00_scatter - np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) - else: - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) - else: - green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-right_self_energy-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) - - green_00_n = green_00_n+np.dot(np.dot(np.dot(np.dot(green_0n_n, h01), green_nn_n), h01.transpose().conj()), green_n0_n) - green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) - green_n0_n = np.dot(np.dot(green_nn_n, h01.transpose().conj()), green_n0_n) - return green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active - - -def transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算散射矩阵 - dim = h00.shape[0] - green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type, scatter_intensity, scatter_length) - temp = np.dot(h01.transpose().conj(), np.linalg.inv(f_right)-np.linalg.inv(f_left)) - transmission_matrix = np.dot(np.dot(np.linalg.inv(u_right), np.dot(green_n0_n, temp)), u_right) - reflection_matrix = np.dot(np.dot(np.linalg.inv(u_left), np.dot(green_00_n, temp)-np.identity(dim)), u_right) - for dim0 in range(dim): - for dim1 in range(dim): - if_active = if_active_channel(k_right[dim0])*if_active_channel(k_right[dim1]) - if if_active == 1: - transmission_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_right[dim0]/velocity_right[dim1])) * transmission_matrix[dim0, dim1] - reflection_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_left[dim0] / velocity_right[dim1]))*reflection_matrix[dim0, dim1] - else: - transmission_matrix[dim0, dim1] = 0 - reflection_matrix[dim0, dim1] = 0 - sum_of_tran_refl_array = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)+np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) - for sum_of_tran_refl in sum_of_tran_refl_array: - if sum_of_tran_refl > 1.001: - print('错误警告:散射矩阵的计算结果不归一! Error Alert: scattering matrix is not normalized!') - return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active - - -def write_transmission_matrix(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 输出 - transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active, \ - = transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type, scatter_intensity, scatter_length) - dim = h00.shape[0] - np.set_printoptions(suppress=True) # 取消科学计数法输出 - print('\n可传播的通道数(向右)active_channel (right) = ', ind_right_active) - print('衰减的通道数(向右) evanescent_channel (right) = ', dim-ind_right_active, '\n') - print('向右可传播的通道数对应的波矢 k_right:\n', np.real(k_right[0:ind_right_active])) - print('向左可传播的通道数对应的波矢 k_left:\n', np.real(k_left[0:ind_right_active]), '\n') - print('向右可传播的通道数对应的费米速度 velocity_right:\n', np.real(velocity_right[0:ind_right_active])) - print('向左可传播的通道数对应的费米速度 velocity_left:\n', np.real(velocity_left[0:ind_right_active]), '\n') - print('透射矩阵 transmission_matrix:\n', np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))) - print('反射矩阵 reflection_matrix:\n', np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), '\n') - print('透射矩阵列求和 total transmission of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)) - print('反射矩阵列求和 total reflection of channels =\n',np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)) - print('透射以及反射矩阵列求和 sum of transmission and reflection of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) + np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)) - print('总电导 total conductance = ', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))), '\n') - - # 下面把以上信息写入文件中 - with open('a.txt', 'w') as f: - f.write('Active_channel (right or left) = ' + str(ind_right_active) + '\n') - f.write('Evanescent_channel (right or left) = ' + str(dim - ind_right_active) + '\n\n') - f.write('Channel K Velocity\n') - for ind0 in range(ind_right_active): - f.write(' '+str(ind0 + 1) + ' | '+str(np.real(k_right[ind0]))+' ' + str(np.real(velocity_right[ind0]))+'\n') - f.write('\n') - for ind0 in range(ind_right_active): - f.write(' -' + str(ind0 + 1) + ' | ' + str(np.real(k_left[ind0])) + ' ' + str(np.real(velocity_left[ind0])) + '\n') - f.write('\n\nScattering_matrix:\n ') - for ind0 in range(ind_right_active): - f.write(str(ind0+1)+' ') - f.write('\n') - for ind1 in range(ind_right_active): - f.write(' '+str(ind1+1)+' ') - for ind2 in range(ind_right_active): - f.write('%f' % np.square(np.abs(transmission_matrix[ind1, ind2]))+' ') - f.write('\n') - f.write('\n') - for ind1 in range(ind_right_active): - f.write(' -'+str(ind1+1)+' ') - for ind2 in range(ind_right_active): - f.write('%f' % np.square(np.abs(reflection_matrix[ind1, ind2]))+' ') - f.write('\n') - f.write('\n') - f.write('Total transmission of channels:\n'+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))+'\n') - f.write('Total conductance = '+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))))+'\n') - - - -if __name__ == '__main__': - main() +""" +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/6352 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * +import copy +import time +# import os +# os.chdir('D:/data') + + +def main(): + start_time = time.time() + h00 = matrix_00() # 方格子模型 + h01 = matrix_01() # 方格子模型 + fermi_energy = 0.1 + write_transmission_matrix(fermi_energy, h00, h01) # 输出无散射的散射矩阵 + end_time = time.time() + print('运行时间=', end_time - start_time, '秒') + + +def matrix_00(width=4): + h00 = np.zeros((width, width)) + for width0 in range(width-1): + h00[width0, width0+1] = 1 + h00[width0+1, width0] = 1 + return h00 + + +def matrix_01(width=4): + h01 = np.identity(width) + return h01 + + +def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵 + transfer = np.zeros((2*dim, 2*dim))*(0+0j) + transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) + transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj()) + transfer[dim:2*dim, 0:dim] = np.identity(dim) + transfer[dim:2*dim, dim:2*dim] = 0 + return transfer + + +def complex_wave_vector(fermi_energy, h00, h01, dim): # 获取通道的复数波矢,并按照波矢的实部Re(k)排序 + transfer = transfer_matrix(fermi_energy, h00, h01, dim) + eigenvalue, eigenvector = np.linalg.eig(transfer) + k_channel = np.log(eigenvalue)/1j + ind = np.argsort(np.real(k_channel)) + k_channel = np.sort(k_channel) + temp = np.zeros((2*dim, 2*dim))*(1+0j) + temp2 = np.zeros((2*dim))*(1+0j) + i0 = 0 + for ind0 in ind: + temp[:, i0] = eigenvector[:, ind0] + temp2[i0] = eigenvalue[ind0] + i0 += 1 + eigenvalue = copy.deepcopy(temp2) + temp = normalization_of_eigenvector(temp[0:dim, :], dim) + velocity = np.zeros((2*dim))*(1+0j) + for dim0 in range(2*dim): + velocity[dim0] = eigenvalue[dim0]*np.dot(np.dot(temp[0:dim, :].transpose().conj(), h01),temp[0:dim, :])[dim0, dim0] + velocity = -2*np.imag(velocity) + eigenvector = copy.deepcopy(temp) + return k_channel, velocity, eigenvalue, eigenvector # 返回通道的对应的波矢、费米速度、本征值、本征态 + + +def normalization_of_eigenvector(eigenvector, dim): # 波函数归一化 + factor = np.zeros(2*dim)*(1+0j) + for dim0 in range(dim): + factor = factor+np.square(np.abs(eigenvector[dim0, :])) + for dim0 in range(2*dim): + eigenvector[:, dim0] = eigenvector[:, dim0]/np.sqrt(factor[dim0]) + return eigenvector + + +def calculation_of_lambda_u_f(fermi_energy, h00, h01, dim): # 对所有通道(包括active和evanescent)进行分类,并计算F + k_channel, velocity, eigenvalue, eigenvector = complex_wave_vector(fermi_energy, h00, h01, dim) + ind_right_active = 0; ind_right_evanescent = 0; ind_left_active = 0; ind_left_evanescent = 0 + k_right = np.zeros(dim)*(1+0j); k_left = np.zeros(dim)*(1+0j) + velocity_right = np.zeros(dim)*(1+0j); velocity_left = np.zeros(dim)*(1+0j) + lambda_right = np.zeros(dim)*(1+0j); lambda_left = np.zeros(dim)*(1+0j) + u_right = np.zeros((dim, dim))*(1+0j); u_left = np.zeros((dim, dim))*(1+0j) + for dim0 in range(2*dim): + if_active = if_active_channel(k_channel[dim0]) + direction = direction_of_channel(velocity[dim0], k_channel[dim0]) + if direction == 1: # 向右运动的通道 + if if_active == 1: # 可传播通道(active channel) + k_right[ind_right_active] = k_channel[dim0] + velocity_right[ind_right_active] = velocity[dim0] + lambda_right[ind_right_active] = eigenvalue[dim0] + u_right[:, ind_right_active] = eigenvector[:, dim0] + ind_right_active += 1 + else: # 衰减通道(evanescent channel) + k_right[dim-1-ind_right_evanescent] = k_channel[dim0] + velocity_right[dim-1-ind_right_evanescent] = velocity[dim0] + lambda_right[dim-1-ind_right_evanescent] = eigenvalue[dim0] + u_right[:, dim-1-ind_right_evanescent] = eigenvector[:, dim0] + ind_right_evanescent += 1 + else: # 向左运动的通道 + if if_active == 1: # 可传播通道(active channel) + k_left[ind_left_active] = k_channel[dim0] + velocity_left[ind_left_active] = velocity[dim0] + lambda_left[ind_left_active] = eigenvalue[dim0] + u_left[:, ind_left_active] = eigenvector[:, dim0] + ind_left_active += 1 + else: # 衰减通道(evanescent channel) + k_left[dim-1-ind_left_evanescent] = k_channel[dim0] + velocity_left[dim-1-ind_left_evanescent] = velocity[dim0] + lambda_left[dim-1-ind_left_evanescent] = eigenvalue[dim0] + u_left[:, dim-1-ind_left_evanescent] = eigenvector[:, dim0] + ind_left_evanescent += 1 + lambda_matrix_right = np.diag(lambda_right) + lambda_matrix_left = np.diag(lambda_left) + f_right = np.dot(np.dot(u_right, lambda_matrix_right), np.linalg.inv(u_right)) + f_left = np.dot(np.dot(u_left, lambda_matrix_left), np.linalg.inv(u_left)) + return k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active + # 分别返回向右和向左的运动的波矢k、费米速度velocity、F值、U值、可向右传播的通道数 + + +def if_active_channel(k_channel): # 判断是可传播通道还是衰减通道 + if np.abs(np.imag(k_channel)) < 1e-7: + if_active = 1 + else: + if_active = 0 + return if_active + + +def direction_of_channel(velocity, k_channel): # 判断通道对应的费米速度方向 + if if_active_channel(k_channel) == 1: + direction = np.sign(velocity) + else: + direction = np.sign(np.imag(k_channel)) + return direction + + +def calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算格林函数 + k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_lambda_u_f(fermi_energy, h00, h01, dim) + right_self_energy = np.dot(h01, f_right) + left_self_energy = np.dot(h01.transpose().conj(), np.linalg.inv(f_left)) + nx = 300 + for nx0 in range(nx): + if nx0 == 0: + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-left_self_energy) + green_00_n = copy.deepcopy(green_nn_n) + green_0n_n = copy.deepcopy(green_nn_n) + green_n0_n = copy.deepcopy(green_nn_n) + elif nx0 != nx-1: + if scatter_type == 0: # 无散射 + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) + elif scatter_type == 1: # 势垒散射 + h00_scatter = h00 + scatter_intensity * np.identity(dim) + if int(nx/2)-int(scatter_length/2) <= nx0 < int(nx/2)+int((scatter_length+1)/2): + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00_scatter - np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) + else: + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) + else: + green_nn_n = np.linalg.inv(fermi_energy*np.identity(dim)-h00-right_self_energy-np.dot(np.dot(h01.transpose().conj(), green_nn_n), h01)) + + green_00_n = green_00_n+np.dot(np.dot(np.dot(np.dot(green_0n_n, h01), green_nn_n), h01.transpose().conj()), green_n0_n) + green_0n_n = np.dot(np.dot(green_0n_n, h01), green_nn_n) + green_n0_n = np.dot(np.dot(green_nn_n, h01.transpose().conj()), green_n0_n) + return green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active + + +def transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 计算散射矩阵 + dim = h00.shape[0] + green_00_n, green_n0_n, k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active = calculation_of_green_function(fermi_energy, h00, h01, dim, scatter_type, scatter_intensity, scatter_length) + temp = np.dot(h01.transpose().conj(), np.linalg.inv(f_right)-np.linalg.inv(f_left)) + transmission_matrix = np.dot(np.dot(np.linalg.inv(u_right), np.dot(green_n0_n, temp)), u_right) + reflection_matrix = np.dot(np.dot(np.linalg.inv(u_left), np.dot(green_00_n, temp)-np.identity(dim)), u_right) + for dim0 in range(dim): + for dim1 in range(dim): + if_active = if_active_channel(k_right[dim0])*if_active_channel(k_right[dim1]) + if if_active == 1: + transmission_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_right[dim0]/velocity_right[dim1])) * transmission_matrix[dim0, dim1] + reflection_matrix[dim0, dim1] = np.sqrt(np.abs(velocity_left[dim0] / velocity_right[dim1]))*reflection_matrix[dim0, dim1] + else: + transmission_matrix[dim0, dim1] = 0 + reflection_matrix[dim0, dim1] = 0 + sum_of_tran_refl_array = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)+np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) + for sum_of_tran_refl in sum_of_tran_refl_array: + if sum_of_tran_refl > 1.001: + print('错误警告:散射矩阵的计算结果不归一! Error Alert: scattering matrix is not normalized!') + return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active + + +def write_transmission_matrix(fermi_energy, h00, h01, scatter_type=0, scatter_intensity=0.2, scatter_length=20): # 输出 + transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active, \ + = transmission_with_detailed_modes(fermi_energy, h00, h01, scatter_type, scatter_intensity, scatter_length) + dim = h00.shape[0] + np.set_printoptions(suppress=True) # 取消科学计数法输出 + print('\n可传播的通道数(向右)active_channel (right) = ', ind_right_active) + print('衰减的通道数(向右) evanescent_channel (right) = ', dim-ind_right_active, '\n') + print('向右可传播的通道数对应的波矢 k_right:\n', np.real(k_right[0:ind_right_active])) + print('向左可传播的通道数对应的波矢 k_left:\n', np.real(k_left[0:ind_right_active]), '\n') + print('向右可传播的通道数对应的费米速度 velocity_right:\n', np.real(velocity_right[0:ind_right_active])) + print('向左可传播的通道数对应的费米速度 velocity_left:\n', np.real(velocity_left[0:ind_right_active]), '\n') + print('透射矩阵 transmission_matrix:\n', np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))) + print('反射矩阵 reflection_matrix:\n', np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), '\n') + print('透射矩阵列求和 total transmission of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)) + print('反射矩阵列求和 total reflection of channels =\n',np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)) + print('透射以及反射矩阵列求和 sum of transmission and reflection of channels =\n', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) + np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)) + print('总电导 total conductance = ', np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))), '\n') + + # 下面把以上信息写入文件中 + with open('a.txt', 'w') as f: + f.write('Active_channel (right or left) = ' + str(ind_right_active) + '\n') + f.write('Evanescent_channel (right or left) = ' + str(dim - ind_right_active) + '\n\n') + f.write('Channel K Velocity\n') + for ind0 in range(ind_right_active): + f.write(' '+str(ind0 + 1) + ' | '+str(np.real(k_right[ind0]))+' ' + str(np.real(velocity_right[ind0]))+'\n') + f.write('\n') + for ind0 in range(ind_right_active): + f.write(' -' + str(ind0 + 1) + ' | ' + str(np.real(k_left[ind0])) + ' ' + str(np.real(velocity_left[ind0])) + '\n') + f.write('\n\nScattering_matrix:\n ') + for ind0 in range(ind_right_active): + f.write(str(ind0+1)+' ') + f.write('\n') + for ind1 in range(ind_right_active): + f.write(' '+str(ind1+1)+' ') + for ind2 in range(ind_right_active): + f.write('%f' % np.square(np.abs(transmission_matrix[ind1, ind2]))+' ') + f.write('\n') + f.write('\n') + for ind1 in range(ind_right_active): + f.write(' -'+str(ind1+1)+' ') + for ind2 in range(ind_right_active): + f.write('%f' % np.square(np.abs(reflection_matrix[ind1, ind2]))+' ') + f.write('\n') + f.write('\n') + f.write('Total transmission of channels:\n'+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0))+'\n') + f.write('Total conductance = '+str(np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active]))))+'\n') + + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems.py b/academic_codes/quantum_transport/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems.py rename to academic_codes/quantum_transport/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems.py index bdd7b0d..247edca --- a/academic_codes/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems.py +++ b/academic_codes/quantum_transport/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems.py @@ -1,180 +1,180 @@ -""" -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/6075 -""" - -import numpy as np -import matplotlib.pyplot as plt -import copy -import time - - -def get_lead_h00(width): - h00 = np.zeros((width, width)) - for i0 in range(width-1): - h00[i0, i0+1] = 1 - h00[i0+1, i0] = 1 - return h00 - - -def get_lead_h01(width): - h01 = np.identity(width) - return h01 - - -def get_center_hamiltonian(Nx, Ny): - h = np.zeros((Nx*Ny, Nx*Ny)) - for x0 in range(Nx-1): - for y0 in range(Ny): - h[x0*Ny+y0, (x0+1)*Ny+y0] = 1 # x方向的跃迁 - h[(x0+1)*Ny+y0, x0*Ny+y0] = 1 - for x0 in range(Nx): - for y0 in range(Ny-1): - h[x0*Ny+y0, x0*Ny+y0+1] = 1 # y方向的跃迁 - h[x0*Ny+y0+1, x0*Ny+y0] = 1 - return h - - -def main(): - start_time = time.time() - width = 5 - length = 50 - fermi_energy_array = np.arange(-4, 4, .01) - - # 中心区的哈密顿量 - H_center = get_center_hamiltonian(Nx=length, Ny=width) - - # 电极的h00和h01 - lead_h00 = get_lead_h00(width) - lead_h01 = get_lead_h01(width) - - transmission_12_array = [] - transmission_13_array = [] - transmission_14_array = [] - transmission_15_array = [] - transmission_16_array = [] - transmission_1_all_array = [] - - for fermi_energy in fermi_energy_array: - print(fermi_energy) - # 表面格林函数 - right_lead_surface, left_lead_surface = surface_green_function_lead(fermi_energy + 1e-9j, lead_h00, lead_h01, dim=width) - - # 由于镜面对称以及xy各项同性,因此这里六个电极的表面格林函数具有相同的形式 - lead_1 = copy.deepcopy(right_lead_surface) # 镜面对称使得lead_1=lead_4 - lead_2 = copy.deepcopy(right_lead_surface) # xy各向同性使得lead_2=lead_4 - lead_3 = copy.deepcopy(right_lead_surface) - lead_4 = copy.deepcopy(right_lead_surface) - lead_5 = copy.deepcopy(right_lead_surface) - lead_6 = copy.deepcopy(right_lead_surface) - - # 几何形状如下所示: - # lead2 lead3 - # lead1(L) lead4(R) - # lead6 lead5 - - # 电极到中心区的跃迁矩阵 - H_lead_1_to_center = np.zeros((width, width*length), dtype=complex) - H_lead_2_to_center = np.zeros((width, width*length), dtype=complex) - H_lead_3_to_center = np.zeros((width, width*length), dtype=complex) - H_lead_4_to_center = np.zeros((width, width*length), dtype=complex) - H_lead_5_to_center = np.zeros((width, width*length), dtype=complex) - H_lead_6_to_center = np.zeros((width, width*length), dtype=complex) - move = 0 # the step of leads 2,3,6,5 moving to center - for i0 in range(width): - H_lead_1_to_center[i0, i0] = 1 - H_lead_2_to_center[i0, width*(move+i0)+(width-1)] = 1 - H_lead_3_to_center[i0, width*(length-move-1-i0)+(width-1)] = 1 - H_lead_4_to_center[i0, width*(length-1)+i0] = 1 - H_lead_5_to_center[i0, width*(length-move-1-i0)+0] = 1 - H_lead_6_to_center[i0, width*(move+i0)+0] = 1 - - # 自能 - self_energy_1 = np.dot(np.dot(H_lead_1_to_center.transpose().conj(), lead_1), H_lead_1_to_center) - self_energy_2 = np.dot(np.dot(H_lead_2_to_center.transpose().conj(), lead_2), H_lead_2_to_center) - self_energy_3 = np.dot(np.dot(H_lead_3_to_center.transpose().conj(), lead_3), H_lead_3_to_center) - self_energy_4 = np.dot(np.dot(H_lead_4_to_center.transpose().conj(), lead_4), H_lead_4_to_center) - self_energy_5 = np.dot(np.dot(H_lead_5_to_center.transpose().conj(), lead_5), H_lead_5_to_center) - self_energy_6 = np.dot(np.dot(H_lead_6_to_center.transpose().conj(), lead_6), H_lead_6_to_center) - - # 整体格林函数 - green = np.linalg.inv(fermi_energy*np.eye(width*length)-H_center-self_energy_1-self_energy_2-self_energy_3-self_energy_4-self_energy_5-self_energy_6) - - # Gamma矩阵 - gamma_1 = 1j*(self_energy_1-self_energy_1.transpose().conj()) - gamma_2 = 1j*(self_energy_2-self_energy_2.transpose().conj()) - gamma_3 = 1j*(self_energy_3-self_energy_3.transpose().conj()) - gamma_4 = 1j*(self_energy_4-self_energy_4.transpose().conj()) - gamma_5 = 1j*(self_energy_5-self_energy_5.transpose().conj()) - gamma_6 = 1j*(self_energy_6-self_energy_6.transpose().conj()) - - # Transmission - transmission_12 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_2), green.transpose().conj())) - transmission_13 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_3), green.transpose().conj())) - transmission_14 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_4), green.transpose().conj())) - transmission_15 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_5), green.transpose().conj())) - transmission_16 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_6), green.transpose().conj())) - - transmission_12_array.append(np.real(transmission_12)) - transmission_13_array.append(np.real(transmission_13)) - transmission_14_array.append(np.real(transmission_14)) - transmission_15_array.append(np.real(transmission_15)) - transmission_16_array.append(np.real(transmission_16)) - transmission_1_all_array.append(np.real(transmission_12+transmission_13+transmission_14+transmission_15+transmission_16)) - - Plot_Line(fermi_energy_array, transmission_12_array, xlabel='Fermi energy', ylabel='Transmission_12', title='', filename='a') - Plot_Line(fermi_energy_array, transmission_13_array, xlabel='Fermi energy', ylabel='Transmission_13', title='', filename='a') - Plot_Line(fermi_energy_array, transmission_14_array, xlabel='Fermi energy', ylabel='Transmission_14', title='', filename='a') - Plot_Line(fermi_energy_array, transmission_15_array, xlabel='Fermi energy', ylabel='Transmission_15', title='', filename='a') - Plot_Line(fermi_energy_array, transmission_16_array, xlabel='Fermi energy', ylabel='Transmission_16', title='', filename='a') - Plot_Line(fermi_energy_array, transmission_1_all_array, xlabel='Fermi energy', ylabel='Transmission_1_all', title='', filename='a') - end_time = time.time() - print('运行时间=', end_time-start_time) - - - -def Plot_Line(x, y, xlabel='x', ylabel='y', title='', filename='a'): - import matplotlib.pyplot as plt - fig, ax = plt.subplots() - plt.subplots_adjust(bottom=0.20, left=0.18) - ax.plot(x, y, '-') - ax.grid() - 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=20) - 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') - -def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T - transfer = np.zeros((2*dim, 2*dim))*(0+0j) - transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) - transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj()) - transfer[dim:2*dim, 0:dim] = np.identity(dim) - transfer[dim:2*dim, dim:2*dim] = 0 - return transfer # 返回转移矩阵 - - -def surface_green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数 - transfer = transfer_matrix(fermi_energy, h00, h01, dim) - eigenvalue, eigenvector = np.linalg.eig(transfer) - ind = np.argsort(np.abs(eigenvalue)) - temp = np.zeros((2*dim, 2*dim))*(1+0j) - i0 = 0 - for ind0 in ind: - temp[:, i0] = eigenvector[:, ind0] - i0 += 1 - s1 = temp[dim:2*dim, 0:dim] - s2 = temp[0:dim, 0:dim] - s3 = temp[dim:2*dim, dim:2*dim] - s4 = temp[0:dim, dim:2*dim] - right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1))) - left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4))) - return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数 - - -if __name__ == '__main__': +""" +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/6075 +""" + +import numpy as np +import matplotlib.pyplot as plt +import copy +import time + + +def get_lead_h00(width): + h00 = np.zeros((width, width)) + for i0 in range(width-1): + h00[i0, i0+1] = 1 + h00[i0+1, i0] = 1 + return h00 + + +def get_lead_h01(width): + h01 = np.identity(width) + return h01 + + +def get_center_hamiltonian(Nx, Ny): + h = np.zeros((Nx*Ny, Nx*Ny)) + for x0 in range(Nx-1): + for y0 in range(Ny): + h[x0*Ny+y0, (x0+1)*Ny+y0] = 1 # x方向的跃迁 + h[(x0+1)*Ny+y0, x0*Ny+y0] = 1 + for x0 in range(Nx): + for y0 in range(Ny-1): + h[x0*Ny+y0, x0*Ny+y0+1] = 1 # y方向的跃迁 + h[x0*Ny+y0+1, x0*Ny+y0] = 1 + return h + + +def main(): + start_time = time.time() + width = 5 + length = 50 + fermi_energy_array = np.arange(-4, 4, .01) + + # 中心区的哈密顿量 + H_center = get_center_hamiltonian(Nx=length, Ny=width) + + # 电极的h00和h01 + lead_h00 = get_lead_h00(width) + lead_h01 = get_lead_h01(width) + + transmission_12_array = [] + transmission_13_array = [] + transmission_14_array = [] + transmission_15_array = [] + transmission_16_array = [] + transmission_1_all_array = [] + + for fermi_energy in fermi_energy_array: + print(fermi_energy) + # 表面格林函数 + right_lead_surface, left_lead_surface = surface_green_function_lead(fermi_energy + 1e-9j, lead_h00, lead_h01, dim=width) + + # 由于镜面对称以及xy各项同性,因此这里六个电极的表面格林函数具有相同的形式 + lead_1 = copy.deepcopy(right_lead_surface) # 镜面对称使得lead_1=lead_4 + lead_2 = copy.deepcopy(right_lead_surface) # xy各向同性使得lead_2=lead_4 + lead_3 = copy.deepcopy(right_lead_surface) + lead_4 = copy.deepcopy(right_lead_surface) + lead_5 = copy.deepcopy(right_lead_surface) + lead_6 = copy.deepcopy(right_lead_surface) + + # 几何形状如下所示: + # lead2 lead3 + # lead1(L) lead4(R) + # lead6 lead5 + + # 电极到中心区的跃迁矩阵 + H_lead_1_to_center = np.zeros((width, width*length), dtype=complex) + H_lead_2_to_center = np.zeros((width, width*length), dtype=complex) + H_lead_3_to_center = np.zeros((width, width*length), dtype=complex) + H_lead_4_to_center = np.zeros((width, width*length), dtype=complex) + H_lead_5_to_center = np.zeros((width, width*length), dtype=complex) + H_lead_6_to_center = np.zeros((width, width*length), dtype=complex) + move = 0 # the step of leads 2,3,6,5 moving to center + for i0 in range(width): + H_lead_1_to_center[i0, i0] = 1 + H_lead_2_to_center[i0, width*(move+i0)+(width-1)] = 1 + H_lead_3_to_center[i0, width*(length-move-1-i0)+(width-1)] = 1 + H_lead_4_to_center[i0, width*(length-1)+i0] = 1 + H_lead_5_to_center[i0, width*(length-move-1-i0)+0] = 1 + H_lead_6_to_center[i0, width*(move+i0)+0] = 1 + + # 自能 + self_energy_1 = np.dot(np.dot(H_lead_1_to_center.transpose().conj(), lead_1), H_lead_1_to_center) + self_energy_2 = np.dot(np.dot(H_lead_2_to_center.transpose().conj(), lead_2), H_lead_2_to_center) + self_energy_3 = np.dot(np.dot(H_lead_3_to_center.transpose().conj(), lead_3), H_lead_3_to_center) + self_energy_4 = np.dot(np.dot(H_lead_4_to_center.transpose().conj(), lead_4), H_lead_4_to_center) + self_energy_5 = np.dot(np.dot(H_lead_5_to_center.transpose().conj(), lead_5), H_lead_5_to_center) + self_energy_6 = np.dot(np.dot(H_lead_6_to_center.transpose().conj(), lead_6), H_lead_6_to_center) + + # 整体格林函数 + green = np.linalg.inv(fermi_energy*np.eye(width*length)-H_center-self_energy_1-self_energy_2-self_energy_3-self_energy_4-self_energy_5-self_energy_6) + + # Gamma矩阵 + gamma_1 = 1j*(self_energy_1-self_energy_1.transpose().conj()) + gamma_2 = 1j*(self_energy_2-self_energy_2.transpose().conj()) + gamma_3 = 1j*(self_energy_3-self_energy_3.transpose().conj()) + gamma_4 = 1j*(self_energy_4-self_energy_4.transpose().conj()) + gamma_5 = 1j*(self_energy_5-self_energy_5.transpose().conj()) + gamma_6 = 1j*(self_energy_6-self_energy_6.transpose().conj()) + + # Transmission + transmission_12 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_2), green.transpose().conj())) + transmission_13 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_3), green.transpose().conj())) + transmission_14 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_4), green.transpose().conj())) + transmission_15 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_5), green.transpose().conj())) + transmission_16 = np.trace(np.dot(np.dot(np.dot(gamma_1, green), gamma_6), green.transpose().conj())) + + transmission_12_array.append(np.real(transmission_12)) + transmission_13_array.append(np.real(transmission_13)) + transmission_14_array.append(np.real(transmission_14)) + transmission_15_array.append(np.real(transmission_15)) + transmission_16_array.append(np.real(transmission_16)) + transmission_1_all_array.append(np.real(transmission_12+transmission_13+transmission_14+transmission_15+transmission_16)) + + Plot_Line(fermi_energy_array, transmission_12_array, xlabel='Fermi energy', ylabel='Transmission_12', title='', filename='a') + Plot_Line(fermi_energy_array, transmission_13_array, xlabel='Fermi energy', ylabel='Transmission_13', title='', filename='a') + Plot_Line(fermi_energy_array, transmission_14_array, xlabel='Fermi energy', ylabel='Transmission_14', title='', filename='a') + Plot_Line(fermi_energy_array, transmission_15_array, xlabel='Fermi energy', ylabel='Transmission_15', title='', filename='a') + Plot_Line(fermi_energy_array, transmission_16_array, xlabel='Fermi energy', ylabel='Transmission_16', title='', filename='a') + Plot_Line(fermi_energy_array, transmission_1_all_array, xlabel='Fermi energy', ylabel='Transmission_1_all', title='', filename='a') + end_time = time.time() + print('运行时间=', end_time-start_time) + + + +def Plot_Line(x, y, xlabel='x', ylabel='y', title='', filename='a'): + import matplotlib.pyplot as plt + fig, ax = plt.subplots() + plt.subplots_adjust(bottom=0.20, left=0.18) + ax.plot(x, y, '-') + ax.grid() + 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=20) + 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') + +def transfer_matrix(fermi_energy, h00, h01, dim): # 转移矩阵T + transfer = np.zeros((2*dim, 2*dim))*(0+0j) + transfer[0:dim, 0:dim] = np.dot(np.linalg.inv(h01), fermi_energy*np.identity(dim)-h00) + transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj()) + transfer[dim:2*dim, 0:dim] = np.identity(dim) + transfer[dim:2*dim, dim:2*dim] = 0 + return transfer # 返回转移矩阵 + + +def surface_green_function_lead(fermi_energy, h00, h01, dim): # 电极的表面格林函数 + transfer = transfer_matrix(fermi_energy, h00, h01, dim) + eigenvalue, eigenvector = np.linalg.eig(transfer) + ind = np.argsort(np.abs(eigenvalue)) + temp = np.zeros((2*dim, 2*dim))*(1+0j) + i0 = 0 + for ind0 in ind: + temp[:, i0] = eigenvector[:, ind0] + i0 += 1 + s1 = temp[dim:2*dim, 0:dim] + s2 = temp[0:dim, 0:dim] + s3 = temp[dim:2*dim, dim:2*dim] + s4 = temp[0:dim, dim:2*dim] + right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1))) + left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4))) + return right_lead_surface, left_lead_surface # 返回右电极的表面格林函数和左电极的表面格林函数 + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems_with_guan.py b/academic_codes/quantum_transport/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems_with_guan.py similarity index 100% rename from academic_codes/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems_with_guan.py rename to academic_codes/quantum_transport/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems_with_guan.py diff --git a/academic_codes/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems_with_kwant.py b/academic_codes/quantum_transport/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems_with_kwant.py similarity index 100% rename from academic_codes/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems_with_kwant.py rename to academic_codes/quantum_transport/2021.02.08_quantum_transport_in_multi_lead_systems/quantum_transport_in_multi_lead_systems_with_kwant.py diff --git a/academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.m b/academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.m old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.m rename to academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.m index 8e6a02f..48d3a89 --- a/academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.m +++ b/academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.m @@ -1,50 +1,50 @@ -% 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/3932 - -% 陈数定义法 -clear;clc; -n=100; % 积分密度 -delta=1e-9; % 求导的偏离量 -C=0; -for kx=-pi:(1/n):pi - for ky=-pi:(1/n):pi - VV=get_vector(HH(kx,ky)); - Vkx=get_vector(HH(kx+delta,ky)); % 略偏离kx的波函数 - Vky=get_vector(HH(kx,ky+delta)); % 略偏离ky的波函数 - Vkxky=get_vector(HH(kx+delta,ky+delta)); % 略偏离kx,ky的波函数 - if sum((abs(Vkx-VV)))>0.01 % 为了波函数的连续性(这里的不连续只遇到符号问题,所以可以直接这么处理) - Vkx=-Vkx; - end - - if sum((abs(Vky-VV)))>0.01 - Vky=-Vky; - end - - if sum(abs(Vkxky-VV))>0.01 - Vkxky=-Vkxky; - end - % 价带的波函数的berry connection,求导后内积 - Ax=VV'*(Vkx-VV)/delta; % Berry connection Ax - Ay=VV'*(Vky-VV)/delta; % Berry connection Ay - Ax_delta_ky=Vky'*(Vkxky-Vky)/delta; % 略偏离ky的berry connection Ax - Ay_delta_kx=Vkx'*(Vkxky-Vkx)/delta; % 略偏离kx的berry connection Ay - % berry curvature - F=((Ay_delta_kx-Ay)-(Ax_delta_ky-Ax))/delta; - % chern number - C=C+F*(1/n)^2; - end -end -C=C/(2*pi*1i) - -function vector_new = get_vector(H) -[vector,eigenvalue] = eig(H); -[eigenvalue, index]=sort(diag(eigenvalue), 'descend'); -vector_new = vector(:, index(2)); -end - -function H=HH(kx,ky) -H(1,2)=2*cos(kx)-1i*2*cos(ky); -H(2,1)=2*cos(kx)+1i*2*cos(ky); -H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky); -H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky)); +% 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/3932 + +% 陈数定义法 +clear;clc; +n=100; % 积分密度 +delta=1e-9; % 求导的偏离量 +C=0; +for kx=-pi:(1/n):pi + for ky=-pi:(1/n):pi + VV=get_vector(HH(kx,ky)); + Vkx=get_vector(HH(kx+delta,ky)); % 略偏离kx的波函数 + Vky=get_vector(HH(kx,ky+delta)); % 略偏离ky的波函数 + Vkxky=get_vector(HH(kx+delta,ky+delta)); % 略偏离kx,ky的波函数 + if sum((abs(Vkx-VV)))>0.01 % 为了波函数的连续性(这里的不连续只遇到符号问题,所以可以直接这么处理) + Vkx=-Vkx; + end + + if sum((abs(Vky-VV)))>0.01 + Vky=-Vky; + end + + if sum(abs(Vkxky-VV))>0.01 + Vkxky=-Vkxky; + end + % 价带的波函数的berry connection,求导后内积 + Ax=VV'*(Vkx-VV)/delta; % Berry connection Ax + Ay=VV'*(Vky-VV)/delta; % Berry connection Ay + Ax_delta_ky=Vky'*(Vkxky-Vky)/delta; % 略偏离ky的berry connection Ax + Ay_delta_kx=Vkx'*(Vkxky-Vkx)/delta; % 略偏离kx的berry connection Ay + % berry curvature + F=((Ay_delta_kx-Ay)-(Ax_delta_ky-Ax))/delta; + % chern number + C=C+F*(1/n)^2; + end +end +C=C/(2*pi*1i) + +function vector_new = get_vector(H) +[vector,eigenvalue] = eig(H); +[eigenvalue, index]=sort(diag(eigenvalue), 'descend'); +vector_new = vector(:, index(2)); +end + +function H=HH(kx,ky) +H(1,2)=2*cos(kx)-1i*2*cos(ky); +H(2,1)=2*cos(kx)+1i*2*cos(ky); +H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky); +H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky)); end \ No newline at end of file diff --git a/academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.py b/academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.py rename to academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.py index 3ca0785..73167ad --- a/academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.py +++ b/academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/calculation_of_Chern_number_by_definition_method.py @@ -1,69 +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/3932 -""" - -import numpy as np -from math import * -import time - - -def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2) - t1 = 1.0 - t2 = 1.0 - t3 = 0.5 - m = -1.0 - matrix = np.zeros((2, 2), dtype=complex) - matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky) - matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky) - matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky) - matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)) - return matrix - - -def main(): - start_time = time.time() - n = 100 # 积分密度 - delta = 1e-9 # 求导的偏离量 - chern_number = 0 # 陈数初始化 - for kx in np.arange(-pi, pi, 2*pi/n): - for ky in np.arange(-pi, pi, 2*pi/n): - H = hamiltonian(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 - # print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大) - # print(eigenvalue) # 排序前的本征值 - # print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大) - - H_delta_kx = hamiltonian(kx+delta, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 - - H_delta_ky = hamiltonian(kx, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 - - H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 - - # 价带的波函数的贝里联络(berry connection) # 求导后内积 - A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量) - A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量) - - A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax - A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay - - # 贝里曲率(berry curvature) - F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta - - # 陈数(chern number) - chern_number = chern_number + F*(2*pi/n)**2 - chern_number = chern_number/(2*pi*1j) - print('Chern number = ', chern_number) - end_time = time.time() - print('运行时间(min)=', (end_time-start_time)/60) - - -if __name__ == '__main__': - main() +""" +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/3932 +""" + +import numpy as np +from math import * +import time + + +def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2) + t1 = 1.0 + t2 = 1.0 + t3 = 0.5 + m = -1.0 + matrix = np.zeros((2, 2), dtype=complex) + matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky) + matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky) + matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky) + matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)) + return matrix + + +def main(): + start_time = time.time() + n = 100 # 积分密度 + delta = 1e-9 # 求导的偏离量 + chern_number = 0 # 陈数初始化 + for kx in np.arange(-pi, pi, 2*pi/n): + for ky in np.arange(-pi, pi, 2*pi/n): + H = hamiltonian(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 + # print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大) + # print(eigenvalue) # 排序前的本征值 + # print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大) + + H_delta_kx = hamiltonian(kx+delta, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 + + H_delta_ky = hamiltonian(kx, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 + + H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 + + # 价带的波函数的贝里联络(berry connection) # 求导后内积 + A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量) + A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量) + + A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax + A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay + + # 贝里曲率(berry curvature) + F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta + + # 陈数(chern number) + chern_number = chern_number + F*(2*pi/n)**2 + chern_number = chern_number/(2*pi*1j) + print('Chern number = ', chern_number) + end_time = time.time() + print('运行时间(min)=', (end_time-start_time)/60) + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/find_smooth_gauge_and_calculate_Chern_number.py b/academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/find_smooth_gauge_and_calculate_Chern_number.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/find_smooth_gauge_and_calculate_Chern_number.py rename to academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/find_smooth_gauge_and_calculate_Chern_number.py index 6701ca2..1ed9c38 --- a/academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/find_smooth_gauge_and_calculate_Chern_number.py +++ b/academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/find_smooth_gauge_and_calculate_Chern_number.py @@ -1,107 +1,107 @@ -""" -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/3932 -""" - -import numpy as np -from math import * -import time -import cmath - - -def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2) - t1 = 1.0 - t2 = 1.0 - t3 = 0.5 - m = -1.0 - matrix = np.zeros((2, 2), dtype=complex) - matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky) - matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky) - matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky) - matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)) - return matrix - - -def main(): - start_time = time.time() - n = 20 # 积分密度 - delta = 1e-9 # 求导的偏离量 - chern_number = 0 # 陈数初始化 - for kx in np.arange(-pi, pi, 2*pi/n): - for ky in np.arange(-pi, pi, 2*pi/n): - H = hamiltonian(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 - - H_delta_kx = hamiltonian(kx+delta, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 - - H_delta_ky = hamiltonian(kx, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 - - H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 - - vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector) - vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector) - vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector) - - # 价带的波函数的贝里联络(berry connection) # 求导后内积 - A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量) - A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量) - - A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax - A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay - - # 贝里曲率(berry curvature) - F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta - - # 陈数(chern number) - chern_number = chern_number + F*(2*pi/n)**2 - chern_number = chern_number/(2*pi*1j) - print('Chern number = ', chern_number) - end_time = time.time() - print('运行时间(min)=', (end_time-start_time)/60) - - -def find_vector_with_the_same_gauge(vector_1, vector_0): - # 寻找近似的同一的规范 - phase_1_pre = 0 - phase_2_pre = pi - n_test = 10001 - for i0 in range(n_test): - test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0)) - test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0)) - if test_1 < 1e-8: - phase = phase_1_pre - # print('Done with i0=', i0) - break - if i0 == n_test-1: - phase = phase_1_pre - print('Gauge Not Found with i0=', i0) - if test_1 < test_2: - if i0 == 0: - phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2 - phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 - else: - phase_1 = phase_1_pre - phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 - else: - if i0 == 0: - phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 - phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2 - else: - phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 - phase_2 = phase_2_pre - phase_1_pre = phase_1 - phase_2_pre = phase_2 - vector_1 = vector_1*cmath.exp(1j*phase) - # print('二分查找找到的规范=', phase) - return vector_1 - - -if __name__ == '__main__': - main() +""" +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/3932 +""" + +import numpy as np +from math import * +import time +import cmath + + +def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2) + t1 = 1.0 + t2 = 1.0 + t3 = 0.5 + m = -1.0 + matrix = np.zeros((2, 2), dtype=complex) + matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky) + matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky) + matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky) + matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)) + return matrix + + +def main(): + start_time = time.time() + n = 20 # 积分密度 + delta = 1e-9 # 求导的偏离量 + chern_number = 0 # 陈数初始化 + for kx in np.arange(-pi, pi, 2*pi/n): + for ky in np.arange(-pi, pi, 2*pi/n): + H = hamiltonian(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 + + H_delta_kx = hamiltonian(kx+delta, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 + + H_delta_ky = hamiltonian(kx, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 + + H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 + + vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector) + vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector) + vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector) + + # 价带的波函数的贝里联络(berry connection) # 求导后内积 + A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量) + A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量) + + A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax + A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay + + # 贝里曲率(berry curvature) + F = (A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta + + # 陈数(chern number) + chern_number = chern_number + F*(2*pi/n)**2 + chern_number = chern_number/(2*pi*1j) + print('Chern number = ', chern_number) + end_time = time.time() + print('运行时间(min)=', (end_time-start_time)/60) + + +def find_vector_with_the_same_gauge(vector_1, vector_0): + # 寻找近似的同一的规范 + phase_1_pre = 0 + phase_2_pre = pi + n_test = 10001 + for i0 in range(n_test): + test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0)) + test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0)) + if test_1 < 1e-8: + phase = phase_1_pre + # print('Done with i0=', i0) + break + if i0 == n_test-1: + phase = phase_1_pre + print('Gauge Not Found with i0=', i0) + if test_1 < test_2: + if i0 == 0: + phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2 + phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 + else: + phase_1 = phase_1_pre + phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 + else: + if i0 == 0: + phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 + phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2 + else: + phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 + phase_2 = phase_2_pre + phase_1_pre = phase_1 + phase_2_pre = phase_2 + vector_1 = vector_1*cmath.exp(1j*phase) + # print('二分查找找到的规范=', phase) + return vector_1 + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/fix_gauge_and_calculate_Chern_number.py b/academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/fix_gauge_and_calculate_Chern_number.py similarity index 100% rename from academic_codes/2020.01.05_calculation_of_Chern_number_by_definition_method/fix_gauge_and_calculate_Chern_number.py rename to academic_codes/topological_invariant/2020.01.05_calculation_of_Chern_number_by_definition_method/fix_gauge_and_calculate_Chern_number.py diff --git a/academic_codes/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.m b/academic_codes/topological_invariant/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.m old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.m rename to academic_codes/topological_invariant/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.m index 83815b9..9c230aa --- a/academic_codes/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.m +++ b/academic_codes/topological_invariant/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.m @@ -1,40 +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/4179 - -% 陈数高效法 -clear;clc; -n=1000 % 积分密度 -delta=2*pi/n; -C=0; -for kx=-pi:(2*pi/n):pi - for ky=-pi:(2*pi/n):pi - VV=get_vector(HH(kx,ky)); - Vkx=get_vector(HH(kx+delta,ky)); % 略偏离kx的波函数 - Vky=get_vector(HH(kx,ky+delta)); % 略偏离ky的波函数 - Vkxky=get_vector(HH(kx+delta,ky+delta)); % 略偏离kx,ky的波函数 - - Ux = VV'*Vkx/abs(VV'*Vkx); - Uy = VV'*Vky/abs(VV'*Vky); - Ux_y = Vky'*Vkxky/abs(Vky'*Vkxky); - Uy_x = Vkx'*Vkxky/abs(Vkx'*Vkxky); - - % berry curvature - F=log(Ux*Uy_x*(1/Ux_y)*(1/Uy)); - % chern number - C=C+F; - end -end -C=C/(2*pi*1i) - -function vector_new = get_vector(H) -[vector,eigenvalue] = eig(H); -[eigenvalue, index]=sort(diag(eigenvalue), 'descend'); -vector_new = vector(:, index(2)); -end - -function H=HH(kx,ky) -H(1,2)=2*cos(kx)-1i*2*cos(ky); -H(2,1)=2*cos(kx)+1i*2*cos(ky); -H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky); -H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky)); +% 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/4179 + +% 陈数高效法 +clear;clc; +n=1000 % 积分密度 +delta=2*pi/n; +C=0; +for kx=-pi:(2*pi/n):pi + for ky=-pi:(2*pi/n):pi + VV=get_vector(HH(kx,ky)); + Vkx=get_vector(HH(kx+delta,ky)); % 略偏离kx的波函数 + Vky=get_vector(HH(kx,ky+delta)); % 略偏离ky的波函数 + Vkxky=get_vector(HH(kx+delta,ky+delta)); % 略偏离kx,ky的波函数 + + Ux = VV'*Vkx/abs(VV'*Vkx); + Uy = VV'*Vky/abs(VV'*Vky); + Ux_y = Vky'*Vkxky/abs(Vky'*Vkxky); + Uy_x = Vkx'*Vkxky/abs(Vkx'*Vkxky); + + % berry curvature + F=log(Ux*Uy_x*(1/Ux_y)*(1/Uy)); + % chern number + C=C+F; + end +end +C=C/(2*pi*1i) + +function vector_new = get_vector(H) +[vector,eigenvalue] = eig(H); +[eigenvalue, index]=sort(diag(eigenvalue), 'descend'); +vector_new = vector(:, index(2)); +end + +function H=HH(kx,ky) +H(1,2)=2*cos(kx)-1i*2*cos(ky); +H(2,1)=2*cos(kx)+1i*2*cos(ky); +H(1,1)=-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky); +H(2,2)=-(-1+2*0.5*sin(kx)+2*0.5*sin(ky)+2*cos(kx+ky)); end \ No newline at end of file diff --git a/academic_codes/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.py b/academic_codes/topological_invariant/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.py rename to academic_codes/topological_invariant/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.py index fe31f16..b2f61a5 --- a/academic_codes/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.py +++ b/academic_codes/topological_invariant/2020.02.26_calculation_of_Chern_number_by_efficient_method/calculation_of_Chern_number_by_efficient_method.py @@ -1,65 +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/4179 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * # 引入pi, cos等 -import cmath -import time - - -def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2) - t1 = 1.0 - t2 = 1.0 - t3 = 0.5 - m = -1.0 - matrix = np.zeros((2, 2))*(1+0j) - matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky) - matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky) - matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky) - matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)) - return matrix - - -def main(): - start_time = time.time() - n = 100 - delta = 2*pi/n - chern_number = 0 # 陈数初始化 - for kx in np.arange(-pi, pi, 2*pi/n): - for ky in np.arange(-pi, pi, 2*pi/n): - H = hamiltonian(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 - - H_delta_kx = hamiltonian(kx+delta, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 - - H_delta_ky = hamiltonian(kx, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 - - H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 - - Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) - Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) - Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) - Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) - - F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) - - # 陈数(chern number) - chern_number = chern_number + F - chern_number = chern_number/(2*pi*1j) - print('Chern number = ', chern_number) - end_time = time.time() - print('运行时间(min)=', (end_time-start_time)/60) - - -if __name__ == '__main__': - main() +""" +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/4179 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * # 引入pi, cos等 +import cmath +import time + + +def hamiltonian(kx, ky): # 量子反常霍尔QAH模型(该参数对应的陈数为2) + t1 = 1.0 + t2 = 1.0 + t3 = 0.5 + m = -1.0 + matrix = np.zeros((2, 2))*(1+0j) + matrix[0, 1] = 2*t1*cos(kx)-1j*2*t1*cos(ky) + matrix[1, 0] = 2*t1*cos(kx)+1j*2*t1*cos(ky) + matrix[0, 0] = m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky) + matrix[1, 1] = -(m+2*t3*sin(kx)+2*t3*sin(ky)+2*t2*cos(kx+ky)) + return matrix + + +def main(): + start_time = time.time() + n = 100 + delta = 2*pi/n + chern_number = 0 # 陈数初始化 + for kx in np.arange(-pi, pi, 2*pi/n): + for ky in np.arange(-pi, pi, 2*pi/n): + H = hamiltonian(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 + + H_delta_kx = hamiltonian(kx+delta, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 + + H_delta_ky = hamiltonian(kx, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 + + H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 + + Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) + Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) + Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) + Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) + + F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) + + # 陈数(chern number) + chern_number = chern_number + F + chern_number = chern_number/(2*pi*1j) + print('Chern number = ', chern_number) + end_time = time.time() + print('运行时间(min)=', (end_time-start_time)/60) + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model.py b/academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model.py rename to academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model.py index d6c8e66..3c9c4b5 --- a/academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model.py +++ b/academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model.py @@ -1,94 +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/5133 -""" - -import numpy as np -from math import * # 引入pi, cos等 -import cmath -import time -import functools # 使用偏函数functools.partial() - - -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() - - #次近邻项 # 对应陈数为-1 - 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)) - - # # 次近邻项 # 对应陈数为1 - # 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(): - start_clock = time.perf_counter() - delta = 0.005 - chern_number = 0 # 陈数初始化 - - # 几个坐标中常出现的项 - a = 1/sqrt(3) - aa1 = 4*sqrt(3)*pi/9/a - aa2 = 2*sqrt(3)*pi/9/a - bb1 = 2*pi/3/a - - hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数 - - for kx in np.arange(-aa1, aa1, delta): - print(kx) - for ky in np.arange(-bb1, bb1, delta): - if (-aa2<=kx<=aa2) or (kx>aa2 and -(aa1-kx)*tan(pi/3)<=ky<=(aa1-kx)*tan(pi/3)) or (kx<-aa2 and -(kx-(-aa1))*tan(pi/3)<=ky<=(kx-(-aa1))*tan(pi/3)): # 限制在六角格子布里渊区内 - - H = hamiltonian0(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 - - H_delta_kx = hamiltonian0(kx+delta, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 - - H_delta_ky = hamiltonian0(kx, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 - - H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 - - Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) - Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) - Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) - Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) - - F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) - - # 陈数(chern number) - chern_number = chern_number + F - - chern_number = chern_number/(2*pi*1j) - print('Chern number = ', chern_number) - end_clock = time.perf_counter() - print('CPU执行时间(min)=', (end_clock-start_clock)/60) - - -if __name__ == '__main__': +""" +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/5133 +""" + +import numpy as np +from math import * # 引入pi, cos等 +import cmath +import time +import functools # 使用偏函数functools.partial() + + +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() + + #次近邻项 # 对应陈数为-1 + 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)) + + # # 次近邻项 # 对应陈数为1 + # 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(): + start_clock = time.perf_counter() + delta = 0.005 + chern_number = 0 # 陈数初始化 + + # 几个坐标中常出现的项 + a = 1/sqrt(3) + aa1 = 4*sqrt(3)*pi/9/a + aa2 = 2*sqrt(3)*pi/9/a + bb1 = 2*pi/3/a + + hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数 + + for kx in np.arange(-aa1, aa1, delta): + print(kx) + for ky in np.arange(-bb1, bb1, delta): + if (-aa2<=kx<=aa2) or (kx>aa2 and -(aa1-kx)*tan(pi/3)<=ky<=(aa1-kx)*tan(pi/3)) or (kx<-aa2 and -(kx-(-aa1))*tan(pi/3)<=ky<=(kx-(-aa1))*tan(pi/3)): # 限制在六角格子布里渊区内 + + H = hamiltonian0(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 + + H_delta_kx = hamiltonian0(kx+delta, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 + + H_delta_ky = hamiltonian0(kx, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 + + H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 + + Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) + Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) + Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) + Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) + + F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) + + # 陈数(chern number) + chern_number = chern_number + F + + chern_number = chern_number/(2*pi*1j) + print('Chern number = ', chern_number) + end_clock = time.perf_counter() + print('CPU执行时间(min)=', (end_clock-start_clock)/60) + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_2.py b/academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_2.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_2.py rename to academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_2.py index d4a3cc2..b91bf0b --- a/academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_2.py +++ b/academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_2.py @@ -1,91 +1,91 @@ -""" -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/5133 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * # 引入pi, cos等 -import cmath -import time -import functools # 使用偏函数functools.partial() - - -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() - - #次近邻项 # 对应陈数为-1 - 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)) - - # # 次近邻项 # 对应陈数为1 - # 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(): - start_clock = time.perf_counter() - delta = 0.005 - chern_number = 0 # 陈数初始化 - - # 常出现的项 - a = 1/sqrt(3) - bb1 = 2*sqrt(3)*pi/3/a - bb2 = 2*pi/3/a - - hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数 - - for kx in np.arange(0 , bb1, delta): - print(kx) - for ky in np.arange(0, 2*bb2, delta): - H = hamiltonian0(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 - - H_delta_kx = hamiltonian0(kx+delta, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 - - H_delta_ky = hamiltonian0(kx, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 - - H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 - - Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) - Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) - Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) - Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) - - F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) - # 陈数(chern number) - chern_number = chern_number + F - - chern_number = chern_number/(2*pi*1j) - print('Chern number = ', chern_number) - end_clock = time.perf_counter() - print('CPU执行时间(min)=', (end_clock-start_clock)/60) - - -if __name__ == '__main__': +""" +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/5133 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * # 引入pi, cos等 +import cmath +import time +import functools # 使用偏函数functools.partial() + + +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() + + #次近邻项 # 对应陈数为-1 + 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)) + + # # 次近邻项 # 对应陈数为1 + # 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(): + start_clock = time.perf_counter() + delta = 0.005 + chern_number = 0 # 陈数初始化 + + # 常出现的项 + a = 1/sqrt(3) + bb1 = 2*sqrt(3)*pi/3/a + bb2 = 2*pi/3/a + + hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数 + + for kx in np.arange(0 , bb1, delta): + print(kx) + for ky in np.arange(0, 2*bb2, delta): + H = hamiltonian0(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 + + H_delta_kx = hamiltonian0(kx+delta, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 + + H_delta_ky = hamiltonian0(kx, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 + + H_delta_kx_ky = hamiltonian0(kx+delta, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 + + Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) + Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) + Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) + Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) + + F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) + # 陈数(chern number) + chern_number = chern_number + F + + chern_number = chern_number/(2*pi*1j) + print('Chern number = ', chern_number) + end_clock = time.perf_counter() + print('CPU执行时间(min)=', (end_clock-start_clock)/60) + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_3.py b/academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_3.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_3.py rename to academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_3.py index 09e3d9f..8b4c986 --- a/academic_codes/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_3.py +++ b/academic_codes/topological_invariant/2020.07.13_calculation_of_Chern_number_in_Haldane_model/Chern_number_in_Haldane_model_by_integration_method_3.py @@ -1,99 +1,99 @@ -""" -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/5133 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * # 引入pi, cos等 -import cmath -import time -import functools # 使用偏函数functools.partial() - - -def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量# 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() - - #次近邻项 # 对应陈数为-1 - 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)) - - # # 次近邻项 # 对应陈数为1 - # 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(): - start_clock = time.perf_counter() - delta = 0.005 - chern_number = 0 # 陈数初始化 - - # 常出现的项 - a = 1/sqrt(3) - bb1 = 2*sqrt(3)*pi/3/a - bb2 = 2*pi/3/a - - hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数 - - for k1 in np.arange(0 , 1, delta): - print(k1) - for k2 in np.arange(0, 1, delta): - # 坐标变换 - kx = (k1-k2)*bb1 - ky = (k1+k2)*bb2 - - # 这里乘2或除以2是为了保证“步长与积分个数的乘积刚好为布里渊区面积” - delta_x = delta*bb1*2 - delta_y = delta*bb2*2/2 - - H = hamiltonian0(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 - - H_delta_kx = hamiltonian0(kx+delta_x, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 - - H_delta_ky = hamiltonian0(kx, ky+delta_y) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 - - H_delta_kx_ky = hamiltonian0(kx+delta_x, ky+delta_y) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 - - Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) - Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) - Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) - Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) - - F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) - # 陈数(chern number) - chern_number = chern_number + F - - chern_number = chern_number/(2*pi*1j) - print('Chern number = ', chern_number) - end_clock = time.perf_counter() - print('CPU执行时间(min)=', (end_clock-start_clock)/60) - - -if __name__ == '__main__': +""" +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/5133 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * # 引入pi, cos等 +import cmath +import time +import functools # 使用偏函数functools.partial() + + +def hamiltonian(k1, k2, M, t1, t2, phi, a=1/sqrt(3)): # Haldane哈密顿量# 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() + + #次近邻项 # 对应陈数为-1 + 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)) + + # # 次近邻项 # 对应陈数为1 + # 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(): + start_clock = time.perf_counter() + delta = 0.005 + chern_number = 0 # 陈数初始化 + + # 常出现的项 + a = 1/sqrt(3) + bb1 = 2*sqrt(3)*pi/3/a + bb2 = 2*pi/3/a + + hamiltonian0 = functools.partial(hamiltonian, M=2/3, t1=1, t2=1/3, phi=pi/4, a=a) # 使用偏函数,固定一些参数 + + for k1 in np.arange(0 , 1, delta): + print(k1) + for k2 in np.arange(0, 1, delta): + # 坐标变换 + kx = (k1-k2)*bb1 + ky = (k1+k2)*bb2 + + # 这里乘2或除以2是为了保证“步长与积分个数的乘积刚好为布里渊区面积” + delta_x = delta*bb1*2 + delta_y = delta*bb2*2/2 + + H = hamiltonian0(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 + + H_delta_kx = hamiltonian0(kx+delta_x, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 + + H_delta_ky = hamiltonian0(kx, ky+delta_y) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 + + H_delta_kx_ky = hamiltonian0(kx+delta_x, ky+delta_y) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 + + Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) + Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) + Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) + Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) + + F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) + # 陈数(chern number) + chern_number = chern_number + F + + chern_number = chern_number/(2*pi*1j) + print('Chern number = ', chern_number) + end_clock = time.perf_counter() + print('CPU执行时间(min)=', (end_clock-start_clock)/60) + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/Winding_number_in_SSH_model.py b/academic_codes/topological_invariant/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/Winding_number_in_SSH_model.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/Winding_number_in_SSH_model.py rename to academic_codes/topological_invariant/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/Winding_number_in_SSH_model.py index 93c5da1..130baff --- a/academic_codes/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/Winding_number_in_SSH_model.py +++ b/academic_codes/topological_invariant/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/Winding_number_in_SSH_model.py @@ -1,41 +1,41 @@ -""" -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/5025 -""" - - -import numpy as np -import matplotlib.pyplot as plt -from math import * -import cmath -import time - -def hamiltonian(k): # SSH模型 - 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 main(): - start_clock = time.perf_counter() - delta_1 = 1e-9 # 求导的步长(求导的步长可以尽可能短) - delta_2 = 1e-5 # 积分的步长(积分步长和计算时间相关,因此取一个合理值即可) - W = 0 # Winding number初始化 - for k in np.arange(-pi, pi, delta_2): - H = hamiltonian(k) - log0 = cmath.log(H[0, 1]) - - H_delta = hamiltonian(k+delta_1) - log1 = cmath.log(H_delta[0, 1]) - - W = W + (log1-log0)/delta_1*delta_2 # Winding number - print('Winding number = ', W/2/pi/1j) - end_clock = time.perf_counter() - print('CPU执行时间(min)=', (end_clock-start_clock)/60) - - -if __name__ == '__main__': - main() +""" +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/5025 +""" + + +import numpy as np +import matplotlib.pyplot as plt +from math import * +import cmath +import time + +def hamiltonian(k): # SSH模型 + 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 main(): + start_clock = time.perf_counter() + delta_1 = 1e-9 # 求导的步长(求导的步长可以尽可能短) + delta_2 = 1e-5 # 积分的步长(积分步长和计算时间相关,因此取一个合理值即可) + W = 0 # Winding number初始化 + for k in np.arange(-pi, pi, delta_2): + H = hamiltonian(k) + log0 = cmath.log(H[0, 1]) + + H_delta = hamiltonian(k+delta_1) + log1 = cmath.log(H_delta[0, 1]) + + W = W + (log1-log0)/delta_1*delta_2 # Winding number + print('Winding number = ', W/2/pi/1j) + end_clock = time.perf_counter() + print('CPU执行时间(min)=', (end_clock-start_clock)/60) + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/bands_of_SSH_model.py b/academic_codes/topological_invariant/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/bands_of_SSH_model.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/bands_of_SSH_model.py rename to academic_codes/topological_invariant/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/bands_of_SSH_model.py index 6e669c6..3ebfd19 --- a/academic_codes/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/bands_of_SSH_model.py +++ b/academic_codes/topological_invariant/2020.07.26_Hamiltonian_bands_and_Winding_number_in_SSH_model/bands_of_SSH_model.py @@ -1,42 +1,42 @@ -""" -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/5025 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * -import cmath - - -def hamiltonian(k): # SSH模型 - 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 main(): - k = np.linspace(-pi, pi, 100) - plot_bands_one_dimension(k, hamiltonian) - - -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() +""" +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/5025 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * +import cmath + + +def hamiltonian(k): # SSH模型 + 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 main(): + k = np.linspace(-pi, pi, 100) + plot_bands_one_dimension(k, hamiltonian) + + +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() diff --git a/academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.m b/academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.m old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.m rename to academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.m index 4ae71f4..b3b663d --- a/academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.m +++ b/academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.m @@ -1,68 +1,68 @@ -% 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/5778 - -clear;clc; -delta=0.1; -Z2=0; -for kx=-pi:0.1:0 - for ky=-pi:0.1:pi - [V1,V2]=get_vector(Hamiltonian(kx,ky)); - [Vkx1,Vkx2]=get_vector(Hamiltonian(kx+delta,ky)); % 略偏离kx的波函数 - [Vky1,Vky2]=get_vector(Hamiltonian(kx,ky+delta)); % 略偏离ky的波函数 - [Vkxky1,Vkxky2]=get_vector(Hamiltonian(kx+delta,ky+delta)); % 略偏离kx,ky的波函数 - - Ux = dot_and_det(V1, Vkx1, V2, Vkx2); - Uy = dot_and_det(V1, Vky1, V2, Vky2); - Ux_y = dot_and_det(Vky1, Vkxky1, Vky2, Vkxky2); - Uy_x = dot_and_det(Vkx1, Vkxky1, Vkx2, Vkxky2); - - F=imag(log(Ux*Uy_x*(conj(Ux_y))*(conj(Uy)))); - A=imag(log(Ux))+imag(log(Uy_x))+imag(log(conj(Ux_y)))+imag(log(conj(Uy))); - - Z2 = Z2+(A-F)/(2*pi); - end -end -Z2= mod(Z2, 2) - - -function dd = dot_and_det(a1,b1,a2,b2) % 内积组成的矩阵对应的行列式 -x1=a1'*b1; -x2=a2'*b2; -x3=a1'*b2; -x4=a2'*b1; -dd =x1*x2-x3*x4; -end - - -function [vector_new_1, vector_new_2] = get_vector(H) -[vector,eigenvalue] = eig(H); -[eigenvalue, index]=sort(diag(eigenvalue), 'ascend'); -vector_new_2 = vector(:, index(2)); -vector_new_1 = vector(:, index(1)); -end - - -function H=Hamiltonian(kx,ky) % BHZ模型 -A=0.3645/5; -B=-0.686/25; -C=0; -D=-0.512/25; -M=-0.01; - -H=zeros(4,4); -varepsilon = C-2*D*(2-cos(kx)-cos(ky)); -d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky)); -d1_d2 = A*(sin(kx)+1j*sin(ky)); -H(1, 1) = varepsilon+d3; -H(2, 2) = varepsilon-d3; -H(1, 2) = conj(d1_d2); -H(2, 1) = d1_d2 ; - -varepsilon = C-2*D*(2-cos(-kx)-cos(-ky)); -d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky)); -d1_d2 = A*(sin(-kx)+1j*sin(-ky)); -H(3, 3) = varepsilon+d3; -H(4, 4) = varepsilon-d3; -H(3, 4) = d1_d2 ; -H(4, 3) = conj(d1_d2); +% 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/5778 + +clear;clc; +delta=0.1; +Z2=0; +for kx=-pi:0.1:0 + for ky=-pi:0.1:pi + [V1,V2]=get_vector(Hamiltonian(kx,ky)); + [Vkx1,Vkx2]=get_vector(Hamiltonian(kx+delta,ky)); % 略偏离kx的波函数 + [Vky1,Vky2]=get_vector(Hamiltonian(kx,ky+delta)); % 略偏离ky的波函数 + [Vkxky1,Vkxky2]=get_vector(Hamiltonian(kx+delta,ky+delta)); % 略偏离kx,ky的波函数 + + Ux = dot_and_det(V1, Vkx1, V2, Vkx2); + Uy = dot_and_det(V1, Vky1, V2, Vky2); + Ux_y = dot_and_det(Vky1, Vkxky1, Vky2, Vkxky2); + Uy_x = dot_and_det(Vkx1, Vkxky1, Vkx2, Vkxky2); + + F=imag(log(Ux*Uy_x*(conj(Ux_y))*(conj(Uy)))); + A=imag(log(Ux))+imag(log(Uy_x))+imag(log(conj(Ux_y)))+imag(log(conj(Uy))); + + Z2 = Z2+(A-F)/(2*pi); + end +end +Z2= mod(Z2, 2) + + +function dd = dot_and_det(a1,b1,a2,b2) % 内积组成的矩阵对应的行列式 +x1=a1'*b1; +x2=a2'*b2; +x3=a1'*b2; +x4=a2'*b1; +dd =x1*x2-x3*x4; +end + + +function [vector_new_1, vector_new_2] = get_vector(H) +[vector,eigenvalue] = eig(H); +[eigenvalue, index]=sort(diag(eigenvalue), 'ascend'); +vector_new_2 = vector(:, index(2)); +vector_new_1 = vector(:, index(1)); +end + + +function H=Hamiltonian(kx,ky) % BHZ模型 +A=0.3645/5; +B=-0.686/25; +C=0; +D=-0.512/25; +M=-0.01; + +H=zeros(4,4); +varepsilon = C-2*D*(2-cos(kx)-cos(ky)); +d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky)); +d1_d2 = A*(sin(kx)+1j*sin(ky)); +H(1, 1) = varepsilon+d3; +H(2, 2) = varepsilon-d3; +H(1, 2) = conj(d1_d2); +H(2, 1) = d1_d2 ; + +varepsilon = C-2*D*(2-cos(-kx)-cos(-ky)); +d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky)); +d1_d2 = A*(sin(-kx)+1j*sin(-ky)); +H(3, 3) = varepsilon+d3; +H(4, 4) = varepsilon-d3; +H(3, 4) = d1_d2 ; +H(4, 3) = conj(d1_d2); end \ No newline at end of file diff --git a/academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.py b/academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.py rename to academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.py index 160bf5b..eb3e472 --- a/academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.py +++ b/academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/Z2_invariant_in_BHZ_model.py @@ -1,88 +1,88 @@ -""" -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/5778 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * # 引入pi, cos等 -import cmath -import time - - -def hamiltonian(kx, ky): # BHZ模型 - A=0.3645/5 - B=-0.686/25 - C=0 - D=-0.512/25 - M=-0.01 - matrix = np.zeros((4, 4))*(1+0j) - - varepsilon = C-2*D*(2-cos(kx)-cos(ky)) - d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky)) - d1_d2 = A*(sin(kx)+1j*sin(ky)) - matrix[0, 0] = varepsilon+d3 - matrix[1, 1] = varepsilon-d3 - matrix[0, 1] = np.conj(d1_d2) - matrix[1, 0] = d1_d2 - - varepsilon = C-2*D*(2-cos(-kx)-cos(-ky)) - d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky)) - d1_d2 = A*(sin(-kx)+1j*sin(-ky)) - matrix[2, 2] = varepsilon+d3 - matrix[3, 3] = varepsilon-d3 - matrix[2, 3] = d1_d2 - matrix[3, 2] = np.conj(d1_d2) - return matrix - - -def main(): - start_clock = time.perf_counter() - delta = 0.1 - Z2 = 0 # Z2数 - for kx in np.arange(-pi, 0, delta): - print(kx) - for ky in np.arange(-pi, pi, delta): - H = hamiltonian(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数1 - vector2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 价带波函数2 - - H_delta_kx = hamiltonian(kx+delta, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数1 - vector_delta_kx2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx的波函数2 - - H_delta_ky = hamiltonian(kx, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数1 - vector_delta_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离ky的波函数2 - - H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数1 - vector_delta_kx_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx和ky的波函数2 - - Ux = dot_and_det(vector, vector_delta_kx, vector2, vector_delta_kx2) - Uy = dot_and_det(vector, vector_delta_ky, vector2, vector_delta_ky2) - Ux_y = dot_and_det(vector_delta_ky, vector_delta_kx_ky, vector_delta_ky2, vector_delta_kx_ky2) - Uy_x = dot_and_det(vector_delta_kx, vector_delta_kx_ky, vector_delta_kx2, vector_delta_kx_ky2) - - F = np.imag(cmath.log(Ux*Uy_x*np.conj(Ux_y)*np.conj(Uy))) - A = np.imag(cmath.log(Ux))+np.imag(cmath.log(Uy_x))+np.imag(cmath.log(np.conj(Ux_y)))+np.imag(cmath.log(np.conj(Uy))) - Z2 = Z2 + (A-F)/(2*pi) - print('Z2 = ', Z2) # Z2数 - end_clock = time.perf_counter() - print('CPU执行时间(min)=', (end_clock-start_clock)/60) - - -def dot_and_det(a1, b1, a2, b2): # 内积组成的矩阵对应的行列式 - x1 = np.dot(np.conj(a1), b1) - x2 = np.dot(np.conj(a2), b2) - x3 = np.dot(np.conj(a1), b2) - x4 = np.dot(np.conj(a2), b1) - return x1*x2-x3*x4 - - -if __name__ == '__main__': - main() +""" +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/5778 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * # 引入pi, cos等 +import cmath +import time + + +def hamiltonian(kx, ky): # BHZ模型 + A=0.3645/5 + B=-0.686/25 + C=0 + D=-0.512/25 + M=-0.01 + matrix = np.zeros((4, 4))*(1+0j) + + varepsilon = C-2*D*(2-cos(kx)-cos(ky)) + d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky)) + d1_d2 = A*(sin(kx)+1j*sin(ky)) + matrix[0, 0] = varepsilon+d3 + matrix[1, 1] = varepsilon-d3 + matrix[0, 1] = np.conj(d1_d2) + matrix[1, 0] = d1_d2 + + varepsilon = C-2*D*(2-cos(-kx)-cos(-ky)) + d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky)) + d1_d2 = A*(sin(-kx)+1j*sin(-ky)) + matrix[2, 2] = varepsilon+d3 + matrix[3, 3] = varepsilon-d3 + matrix[2, 3] = d1_d2 + matrix[3, 2] = np.conj(d1_d2) + return matrix + + +def main(): + start_clock = time.perf_counter() + delta = 0.1 + Z2 = 0 # Z2数 + for kx in np.arange(-pi, 0, delta): + print(kx) + for ky in np.arange(-pi, pi, delta): + H = hamiltonian(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数1 + vector2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 价带波函数2 + + H_delta_kx = hamiltonian(kx+delta, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数1 + vector_delta_kx2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx的波函数2 + + H_delta_ky = hamiltonian(kx, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数1 + vector_delta_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离ky的波函数2 + + H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数1 + vector_delta_kx_ky2 = eigenvector[:, np.argsort(np.real(eigenvalue))[1]] # 略偏离kx和ky的波函数2 + + Ux = dot_and_det(vector, vector_delta_kx, vector2, vector_delta_kx2) + Uy = dot_and_det(vector, vector_delta_ky, vector2, vector_delta_ky2) + Ux_y = dot_and_det(vector_delta_ky, vector_delta_kx_ky, vector_delta_ky2, vector_delta_kx_ky2) + Uy_x = dot_and_det(vector_delta_kx, vector_delta_kx_ky, vector_delta_kx2, vector_delta_kx_ky2) + + F = np.imag(cmath.log(Ux*Uy_x*np.conj(Ux_y)*np.conj(Uy))) + A = np.imag(cmath.log(Ux))+np.imag(cmath.log(Uy_x))+np.imag(cmath.log(np.conj(Ux_y)))+np.imag(cmath.log(np.conj(Uy))) + Z2 = Z2 + (A-F)/(2*pi) + print('Z2 = ', Z2) # Z2数 + end_clock = time.perf_counter() + print('CPU执行时间(min)=', (end_clock-start_clock)/60) + + +def dot_and_det(a1, b1, a2, b2): # 内积组成的矩阵对应的行列式 + x1 = np.dot(np.conj(a1), b1) + x2 = np.dot(np.conj(a2), b2) + x3 = np.dot(np.conj(a1), b2) + x4 = np.dot(np.conj(a2), b1) + return x1*x2-x3*x4 + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/spin_Chern_number_in_BHZ_model.py b/academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/spin_Chern_number_in_BHZ_model.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/spin_Chern_number_in_BHZ_model.py rename to academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/spin_Chern_number_in_BHZ_model.py index a79aa3a..ab46a24 --- a/academic_codes/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/spin_Chern_number_in_BHZ_model.py +++ b/academic_codes/topological_invariant/2020.09.05_spin_Chern_number_and_Z2_invariant_in_BHZ_model/spin_Chern_number_in_BHZ_model.py @@ -1,98 +1,98 @@ -""" -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/5778 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * # 引入pi, cos等 -import cmath -import time - - -def hamiltonian1(kx, ky): # Half BHZ for spin up - A=0.3645/5 - B=-0.686/25 - C=0 - D=-0.512/25 - M=-0.01 - matrix = np.zeros((2, 2))*(1+0j) - varepsilon = C-2*D*(2-cos(kx)-cos(ky)) - d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky)) - d1_d2 = A*(sin(kx)+1j*sin(ky)) - - matrix[0, 0] = varepsilon+d3 - matrix[1, 1] = varepsilon-d3 - matrix[0, 1] = np.conj(d1_d2) - matrix[1, 0] = d1_d2 - return matrix - -def hamiltonian2(kx, ky): # Half BHZ for spin down - A=0.3645/5 - B=-0.686/25 - C=0 - D=-0.512/25 - M=-0.01 - matrix = np.zeros((2, 2))*(1+0j) - varepsilon = C-2*D*(2-cos(-kx)-cos(-ky)) - d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky)) - d1_d2 = A*(sin(-kx)+1j*sin(-ky)) - - matrix[0, 0] = varepsilon+d3 - matrix[1, 1] = varepsilon-d3 - matrix[0, 1] = d1_d2 - matrix[1, 0] = np.conj(d1_d2) - return matrix - - -def main(): - start_clock = time.perf_counter() - delta = 0.1 - for i0 in range(2): - if i0 == 0: - hamiltonian = hamiltonian1 - else: - hamiltonian = hamiltonian2 - chern_number = 0 # 陈数初始化 - for kx in np.arange(-pi, pi, delta): - print(kx) - for ky in np.arange(-pi, pi, delta): - H = hamiltonian(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 - - H_delta_kx = hamiltonian(kx+delta, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 - - H_delta_ky = hamiltonian(kx, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 - - H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 - - Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) - Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) - Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) - Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) - - F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) - # 陈数(chern number) - chern_number = chern_number + F - chern_number = chern_number/(2*pi*1j) - if i0 == 0: - chern_number_up = chern_number - else: - chern_number_down = chern_number - spin_chern_number = (chern_number_up-chern_number_down)/2 - print('Chern number for spin up = ', chern_number_up) - print('Chern number for spin down = ', chern_number_down) - print('Spin chern number = ', spin_chern_number) - end_clock = time.perf_counter() - print('CPU执行时间(min)=', (end_clock-start_clock)/60) - - -if __name__ == '__main__': - main() +""" +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/5778 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * # 引入pi, cos等 +import cmath +import time + + +def hamiltonian1(kx, ky): # Half BHZ for spin up + A=0.3645/5 + B=-0.686/25 + C=0 + D=-0.512/25 + M=-0.01 + matrix = np.zeros((2, 2))*(1+0j) + varepsilon = C-2*D*(2-cos(kx)-cos(ky)) + d3 = -2*B*(2-(M/2/B)-cos(kx)-cos(ky)) + d1_d2 = A*(sin(kx)+1j*sin(ky)) + + matrix[0, 0] = varepsilon+d3 + matrix[1, 1] = varepsilon-d3 + matrix[0, 1] = np.conj(d1_d2) + matrix[1, 0] = d1_d2 + return matrix + +def hamiltonian2(kx, ky): # Half BHZ for spin down + A=0.3645/5 + B=-0.686/25 + C=0 + D=-0.512/25 + M=-0.01 + matrix = np.zeros((2, 2))*(1+0j) + varepsilon = C-2*D*(2-cos(-kx)-cos(-ky)) + d3 = -2*B*(2-(M/2/B)-cos(-kx)-cos(-ky)) + d1_d2 = A*(sin(-kx)+1j*sin(-ky)) + + matrix[0, 0] = varepsilon+d3 + matrix[1, 1] = varepsilon-d3 + matrix[0, 1] = d1_d2 + matrix[1, 0] = np.conj(d1_d2) + return matrix + + +def main(): + start_clock = time.perf_counter() + delta = 0.1 + for i0 in range(2): + if i0 == 0: + hamiltonian = hamiltonian1 + else: + hamiltonian = hamiltonian2 + chern_number = 0 # 陈数初始化 + for kx in np.arange(-pi, pi, delta): + print(kx) + for ky in np.arange(-pi, pi, delta): + H = hamiltonian(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 + + H_delta_kx = hamiltonian(kx+delta, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 + + H_delta_ky = hamiltonian(kx, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 + + H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 + + Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) + Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) + Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) + Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) + + F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) + # 陈数(chern number) + chern_number = chern_number + F + chern_number = chern_number/(2*pi*1j) + if i0 == 0: + chern_number_up = chern_number + else: + chern_number_down = chern_number + spin_chern_number = (chern_number_up-chern_number_down)/2 + print('Chern number for spin up = ', chern_number_up) + print('Chern number for spin down = ', chern_number_down) + print('Spin chern number = ', spin_chern_number) + end_clock = time.perf_counter() + print('CPU执行时间(min)=', (end_clock-start_clock)/60) + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals.py b/academic_codes/topological_invariant/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals.py old mode 100755 new mode 100644 similarity index 97% rename from academic_codes/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals.py rename to academic_codes/topological_invariant/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals.py index 20e470a..69786d3 --- a/academic_codes/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals.py +++ b/academic_codes/topological_invariant/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals.py @@ -1,83 +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/6896 -""" - -import numpy as np -from math import * -import matplotlib.pyplot as plt -import time -import cmath - - -def hamiltonian(kx,ky,kz): # Weyl semimetal - A = 1 - M0 = 1 - M1 = 1 - H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*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 main(): - start_time = time.time() - n = 50 - delta = 2*pi/n - kz_array = np.arange(-pi, pi, 0.1) - chern_number_array = np.zeros(kz_array.shape[0]) - i0 = 0 - for kz in kz_array: - print('kz=', kz) - chern_number = 0 # 陈数初始化 - for kx in np.arange(-pi, pi, 2*pi/n): - for ky in np.arange(-pi, pi, 2*pi/n): - H = hamiltonian(kx, ky, kz) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 - - H_delta_kx = hamiltonian(kx+delta, ky, kz) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 - - H_delta_ky = hamiltonian(kx, ky+delta, kz) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 - - H_delta_kx_ky = hamiltonian(kx+delta, ky+delta, kz) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 - - Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) - Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) - Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) - Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) - - F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) - - # 陈数(chern number) - chern_number = chern_number + F - chern_number = chern_number/(2*pi*1j) - print('Chern number = ', chern_number, '\n') - chern_number_array[i0] = np.real(chern_number) - i0 += 1 - end_time = time.time() - print('运行时间(min)=', (end_time-start_time)/60) - plt.plot(kz_array, chern_number_array, 'o-') - plt.xlabel('kz') - plt.ylabel('Chern number') - plt.show() - - -if __name__ == '__main__': +""" +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/6896 +""" + +import numpy as np +from math import * +import matplotlib.pyplot as plt +import time +import cmath + + +def hamiltonian(kx,ky,kz): # Weyl semimetal + A = 1 + M0 = 1 + M1 = 1 + H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*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 main(): + start_time = time.time() + n = 50 + delta = 2*pi/n + kz_array = np.arange(-pi, pi, 0.1) + chern_number_array = np.zeros(kz_array.shape[0]) + i0 = 0 + for kz in kz_array: + print('kz=', kz) + chern_number = 0 # 陈数初始化 + for kx in np.arange(-pi, pi, 2*pi/n): + for ky in np.arange(-pi, pi, 2*pi/n): + H = hamiltonian(kx, ky, kz) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 价带波函数 + + H_delta_kx = hamiltonian(kx+delta, ky, kz) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx的波函数 + + H_delta_ky = hamiltonian(kx, ky+delta, kz) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离ky的波函数 + + H_delta_kx_ky = hamiltonian(kx+delta, ky+delta, kz) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] # 略偏离kx和ky的波函数 + + Ux = np.dot(np.conj(vector), vector_delta_kx)/abs(np.dot(np.conj(vector), vector_delta_kx)) + Uy = np.dot(np.conj(vector), vector_delta_ky)/abs(np.dot(np.conj(vector), vector_delta_ky)) + Ux_y = np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_ky), vector_delta_kx_ky)) + Uy_x = np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)/abs(np.dot(np.conj(vector_delta_kx), vector_delta_kx_ky)) + + F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy)) + + # 陈数(chern number) + chern_number = chern_number + F + chern_number = chern_number/(2*pi*1j) + print('Chern number = ', chern_number, '\n') + chern_number_array[i0] = np.real(chern_number) + i0 += 1 + end_time = time.time() + print('运行时间(min)=', (end_time-start_time)/60) + plt.plot(kz_array, chern_number_array, 'o-') + plt.xlabel('kz') + plt.ylabel('Chern number') + plt.show() + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals_with_guan_package.py b/academic_codes/topological_invariant/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals_with_guan_package.py similarity index 100% rename from academic_codes/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals_with_guan_package.py rename to academic_codes/topological_invariant/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/Chern_number_of_the_cross_section_plane_in_Weyl_semimetals_with_guan_package.py diff --git a/academic_codes/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/bands_of_Weyl_semimetal_after_discretization.py b/academic_codes/topological_invariant/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/bands_of_Weyl_semimetal_after_discretization.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/bands_of_Weyl_semimetal_after_discretization.py rename to academic_codes/topological_invariant/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/bands_of_Weyl_semimetal_after_discretization.py index ddd31bf..bee7569 --- a/academic_codes/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/bands_of_Weyl_semimetal_after_discretization.py +++ b/academic_codes/topological_invariant/2020.11.04_Chern_number_of_the_cross_section_plane_in_Weyl_semimetals/bands_of_Weyl_semimetal_after_discretization.py @@ -1,66 +1,66 @@ -""" -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/6896 -""" - -import numpy as np -from math import * -import matplotlib.pyplot as plt - - -def main(): - k1 = np.arange(-pi, pi, 0.05) - k2 = np.arange(-pi, pi, 0.05) - plot_bands_two_dimension(k1, k2, hamiltonian) - - -def hamiltonian(kx,kz,ky=0): # Weyl semimetal - A = 1 - M0 = 1 - M1 = 1 - H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*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__': +""" +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/6896 +""" + +import numpy as np +from math import * +import matplotlib.pyplot as plt + + +def main(): + k1 = np.arange(-pi, pi, 0.05) + k2 = np.arange(-pi, pi, 0.05) + plot_bands_two_dimension(k1, k2, hamiltonian) + + +def hamiltonian(kx,kz,ky=0): # Weyl semimetal + A = 1 + M0 = 1 + M1 = 1 + H = A*(sin(kx)*sigma_x()+sin(ky)*sigma_y())+(M0-M1*(2*(1-cos(kx))+2*(1-cos(ky))+2*(1-cos(kz))))*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() \ No newline at end of file diff --git a/academic_codes/2020.11.27_find_the_same_gauge_numerically_with_binary_search/find_the_same_gauge_numerically_with_binary_search.py b/academic_codes/topological_invariant/2020.11.27_find_the_same_gauge_numerically_with_binary_search/find_the_same_gauge_numerically_with_binary_search.py similarity index 100% rename from academic_codes/2020.11.27_find_the_same_gauge_numerically_with_binary_search/find_the_same_gauge_numerically_with_binary_search.py rename to academic_codes/topological_invariant/2020.11.27_find_the_same_gauge_numerically_with_binary_search/find_the_same_gauge_numerically_with_binary_search.py diff --git a/academic_codes/2020.11.27_find_the_same_gauge_numerically_with_binary_search/find_the_same_gauge_numerically_with_guan.py b/academic_codes/topological_invariant/2020.11.27_find_the_same_gauge_numerically_with_binary_search/find_the_same_gauge_numerically_with_guan.py similarity index 100% rename from academic_codes/2020.11.27_find_the_same_gauge_numerically_with_binary_search/find_the_same_gauge_numerically_with_guan.py rename to academic_codes/topological_invariant/2020.11.27_find_the_same_gauge_numerically_with_binary_search/find_the_same_gauge_numerically_with_guan.py diff --git a/academic_codes/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery.py b/academic_codes/topological_invariant/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery.py old mode 100755 new mode 100644 similarity index 98% rename from academic_codes/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery.py rename to academic_codes/topological_invariant/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery.py index 7c8ac2a..b80179b --- a/academic_codes/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery.py +++ b/academic_codes/topological_invariant/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery.py @@ -1,159 +1,159 @@ -""" -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/8536 -""" - -import numpy as np -import matplotlib.pyplot as plt -from math import * -import cmath -import time - - -def hamiltonian(k1, k2, t1=2.82, a=1/sqrt(3)): # 石墨烯哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3)) - h = np.zeros((2, 2), dtype=complex) - h[0, 0] = 0.28/2 - h[1, 1] = -0.28/2 - h[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)) - h[0, 1] = h[1, 0].conj() - return h - - -def main(): - start_time = time.time() - n = 400 # 取点密度 - delta = 1e-10 # 求导的偏离量 - kx_array = np.linspace(-2*pi, 2*pi, n) - ky_array = np.linspace(-2*pi, 2*pi, n) - for band in range(2): - F_all = np.zeros((ky_array.shape[0], ky_array.shape[0])) # 贝里曲率 - j0 = 0 - for kx in kx_array: - print(kx) - i0 = 0 - for ky in ky_array: - H = hamiltonian(kx, ky) - eigenvalue, eigenvector = np.linalg.eig(H) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 价带波函数 - # print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大) - # print(eigenvalue) # 排序前的本征值 - # print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大) - - H_delta_kx = hamiltonian(kx+delta, ky) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) - vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx的波函数 - # vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector) # 如果波函数不连续需要使用这个 - - H_delta_ky = hamiltonian(kx, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) - vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离ky的波函数 - # vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector) # 如果波函数不连续需要使用这个 - - H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) - eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) - vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx和ky的波函数 - # vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector) # 如果波函数不连续需要使用这个 - - # 价带的波函数的贝里联络(berry connection) # 求导后内积 - A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量) - A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量) - - A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax - A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay - - # 贝里曲率(berry curvature) - F = ((A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta)*1j - # print(F) - F_all[i0, j0] = np.real(F) - i0 += 1 - j0 += 1 - - if band==0: - plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='k_x (pi)', ylabel='k_y (pi)', zlabel='Berry curvature', title='Valence Band', rcount=300, ccount=300) - else: - plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='k_x (pi)', ylabel='k_y (pi)', zlabel='Berry curvature', title='Conductance Band', rcount=300, ccount=300) - # import guan - # if band==0: - # guan.plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='kx', ylabel='ky', zlabel='Berry curvature', title='Valence Band', rcount=300, ccount=300) - # else: - # guan.plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='kx', ylabel='ky', zlabel='Berry curvature', title='Conductance Band', rcount=300, ccount=300) - end_time = time.time() - print('运行时间(min)=', (end_time-start_time)/60) - -def find_vector_with_the_same_gauge(vector_1, vector_0): - # 寻找近似的同一的规范 - phase_1_pre = 0 - phase_2_pre = pi - n_test = 10001 - for i0 in range(n_test): - test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0)) - test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0)) - if test_1 < 1e-9: - phase = phase_1_pre - # print('Done with i0=', i0) - break - if i0 == n_test-1: - phase = phase_1_pre - print('Gauge Not Found with i0=', i0) - if test_1 < test_2: - if i0 == 0: - phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2 - phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 - else: - phase_1 = phase_1_pre - phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 - else: - if i0 == 0: - phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 - phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2 - else: - phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 - phase_2 = phase_2_pre - phase_1_pre = phase_1 - phase_2_pre = phase_2 - - vector_1 = vector_1*cmath.exp(1j*phase) - # print('二分查找找到的规范=', phase) - return vector_1 - -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__': +""" +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/8536 +""" + +import numpy as np +import matplotlib.pyplot as plt +from math import * +import cmath +import time + + +def hamiltonian(k1, k2, t1=2.82, a=1/sqrt(3)): # 石墨烯哈密顿量(a为原子间距,不赋值的话默认为1/sqrt(3)) + h = np.zeros((2, 2), dtype=complex) + h[0, 0] = 0.28/2 + h[1, 1] = -0.28/2 + h[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)) + h[0, 1] = h[1, 0].conj() + return h + + +def main(): + start_time = time.time() + n = 400 # 取点密度 + delta = 1e-10 # 求导的偏离量 + kx_array = np.linspace(-2*pi, 2*pi, n) + ky_array = np.linspace(-2*pi, 2*pi, n) + for band in range(2): + F_all = np.zeros((ky_array.shape[0], ky_array.shape[0])) # 贝里曲率 + j0 = 0 + for kx in kx_array: + print(kx) + i0 = 0 + for ky in ky_array: + H = hamiltonian(kx, ky) + eigenvalue, eigenvector = np.linalg.eig(H) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 价带波函数 + # print(np.argsort(np.real(eigenvalue))[0]) # 排序索引(从小到大) + # print(eigenvalue) # 排序前的本征值 + # print(np.sort(np.real(eigenvalue))) # 排序后的本征值(从小到大) + + H_delta_kx = hamiltonian(kx+delta, ky) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx) + vector_delta_kx = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx的波函数 + # vector_delta_kx = find_vector_with_the_same_gauge(vector_delta_kx, vector) # 如果波函数不连续需要使用这个 + + H_delta_ky = hamiltonian(kx, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_ky) + vector_delta_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离ky的波函数 + # vector_delta_ky = find_vector_with_the_same_gauge(vector_delta_ky, vector) # 如果波函数不连续需要使用这个 + + H_delta_kx_ky = hamiltonian(kx+delta, ky+delta) + eigenvalue, eigenvector = np.linalg.eig(H_delta_kx_ky) + vector_delta_kx_ky = eigenvector[:, np.argsort(np.real(eigenvalue))[band]] # 略偏离kx和ky的波函数 + # vector_delta_kx_ky = find_vector_with_the_same_gauge(vector_delta_kx_ky, vector) # 如果波函数不连续需要使用这个 + + # 价带的波函数的贝里联络(berry connection) # 求导后内积 + A_x = np.dot(vector.transpose().conj(), (vector_delta_kx-vector)/delta) # 贝里联络Ax(x分量) + A_y = np.dot(vector.transpose().conj(), (vector_delta_ky-vector)/delta) # 贝里联络Ay(y分量) + + A_x_delta_ky = np.dot(vector_delta_ky.transpose().conj(), (vector_delta_kx_ky-vector_delta_ky)/delta) # 略偏离ky的贝里联络Ax + A_y_delta_kx = np.dot(vector_delta_kx.transpose().conj(), (vector_delta_kx_ky-vector_delta_kx)/delta) # 略偏离kx的贝里联络Ay + + # 贝里曲率(berry curvature) + F = ((A_y_delta_kx-A_y)/delta-(A_x_delta_ky-A_x)/delta)*1j + # print(F) + F_all[i0, j0] = np.real(F) + i0 += 1 + j0 += 1 + + if band==0: + plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='k_x (pi)', ylabel='k_y (pi)', zlabel='Berry curvature', title='Valence Band', rcount=300, ccount=300) + else: + plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='k_x (pi)', ylabel='k_y (pi)', zlabel='Berry curvature', title='Conductance Band', rcount=300, ccount=300) + # import guan + # if band==0: + # guan.plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='kx', ylabel='ky', zlabel='Berry curvature', title='Valence Band', rcount=300, ccount=300) + # else: + # guan.plot_3d_surface(kx_array/pi, ky_array/pi, F_all, xlabel='kx', ylabel='ky', zlabel='Berry curvature', title='Conductance Band', rcount=300, ccount=300) + end_time = time.time() + print('运行时间(min)=', (end_time-start_time)/60) + +def find_vector_with_the_same_gauge(vector_1, vector_0): + # 寻找近似的同一的规范 + phase_1_pre = 0 + phase_2_pre = pi + n_test = 10001 + for i0 in range(n_test): + test_1 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_1_pre) - vector_0)) + test_2 = np.sum(np.abs(vector_1*cmath.exp(1j*phase_2_pre) - vector_0)) + if test_1 < 1e-9: + phase = phase_1_pre + # print('Done with i0=', i0) + break + if i0 == n_test-1: + phase = phase_1_pre + print('Gauge Not Found with i0=', i0) + if test_1 < test_2: + if i0 == 0: + phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2 + phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 + else: + phase_1 = phase_1_pre + phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 + else: + if i0 == 0: + phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 + phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2 + else: + phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 + phase_2 = phase_2_pre + phase_1_pre = phase_1 + phase_2_pre = phase_2 + + vector_1 = vector_1*cmath.exp(1j*phase) + # print('二分查找找到的规范=', phase) + return vector_1 + +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() \ No newline at end of file diff --git a/academic_codes/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_with_ky=0.py b/academic_codes/topological_invariant/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_with_ky=0.py similarity index 100% rename from academic_codes/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_with_ky=0.py rename to academic_codes/topological_invariant/2021.01.10_Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery/Berry_curvature_distribution_with_ky=0.py diff --git a/academic_codes/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model.py b/academic_codes/topological_invariant/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model.py rename to academic_codes/topological_invariant/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model.py index 0177fbc..64afdc6 --- a/academic_codes/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model.py +++ b/academic_codes/topological_invariant/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model.py @@ -1,77 +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/10064 -""" - -import numpy as np -import cmath -from math import * - - -def hamiltonian(k): # SSH模型哈密顿量 - gamma = 0.5 - lambda0 = 1 - h = np.zeros((2, 2), dtype=complex) - h[0,0] = 0 - h[1,1] = 0 - h[0,1] = gamma+lambda0*cmath.exp(-1j*k) - h[1,0] = gamma+lambda0*cmath.exp(1j*k) - return h - - -def main(): - Num_k = 100 - k_array = np.linspace(-pi, pi, Num_k) - vector_array = [] - for k in k_array: - vector = get_occupied_bands_vectors(k, hamiltonian) - vector_array.append(vector) - # vector_array.append(vector*cmath.exp(1j*np.random.uniform(0, pi))) # 随机相位测试 - - # 波函数固定一个规范 - vector_sum = 0 - for i0 in range(Num_k): - vector_sum += np.abs(vector_array[i0]) - index = np.argmax(np.abs(vector_sum)) - for i0 in range(Num_k): - vector_array[i0] = find_vector_with_fixed_gauge_by_making_one_component_real(vector_array[i0], index=index) - - # # 波函数固定一个规范 - # import guan - # vector_array = guan.find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array, precision=0.005) - - # 计算Wilson loop - W_k = 1 - for i0 in range(Num_k-1): - F = np.dot(vector_array[i0+1].transpose().conj(), vector_array[i0]) - W_k = np.dot(F, W_k) - nu = np.log(W_k)/2/pi/1j - # if np.real(nu) < 0: - # nu += 1 - print('p=', nu, '\n') - - -def get_occupied_bands_vectors(x, matrix): - matrix0 = matrix(x) - eigenvalue, eigenvector = np.linalg.eig(matrix0) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] - return vector - - -def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None): - if index == None: - index = np.argmax(np.abs(vector)) - sign_pre = np.sign(np.imag(vector[index])) - for phase in np.arange(0, 2*np.pi, precision): - sign = np.sign(np.imag(vector[index]*cmath.exp(1j*phase))) - if np.abs(np.imag(vector[index]*cmath.exp(1j*phase))) < 1e-9 or sign == -sign_pre: - break - sign_pre = sign - vector = vector*cmath.exp(1j*phase) - if np.real(vector[index]) < 0: - vector = -vector - return vector - - -if __name__ == '__main__': +""" +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/10064 +""" + +import numpy as np +import cmath +from math import * + + +def hamiltonian(k): # SSH模型哈密顿量 + gamma = 0.5 + lambda0 = 1 + h = np.zeros((2, 2), dtype=complex) + h[0,0] = 0 + h[1,1] = 0 + h[0,1] = gamma+lambda0*cmath.exp(-1j*k) + h[1,0] = gamma+lambda0*cmath.exp(1j*k) + return h + + +def main(): + Num_k = 100 + k_array = np.linspace(-pi, pi, Num_k) + vector_array = [] + for k in k_array: + vector = get_occupied_bands_vectors(k, hamiltonian) + vector_array.append(vector) + # vector_array.append(vector*cmath.exp(1j*np.random.uniform(0, pi))) # 随机相位测试 + + # 波函数固定一个规范 + vector_sum = 0 + for i0 in range(Num_k): + vector_sum += np.abs(vector_array[i0]) + index = np.argmax(np.abs(vector_sum)) + for i0 in range(Num_k): + vector_array[i0] = find_vector_with_fixed_gauge_by_making_one_component_real(vector_array[i0], index=index) + + # # 波函数固定一个规范 + # import guan + # vector_array = guan.find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array, precision=0.005) + + # 计算Wilson loop + W_k = 1 + for i0 in range(Num_k-1): + F = np.dot(vector_array[i0+1].transpose().conj(), vector_array[i0]) + W_k = np.dot(F, W_k) + nu = np.log(W_k)/2/pi/1j + # if np.real(nu) < 0: + # nu += 1 + print('p=', nu, '\n') + + +def get_occupied_bands_vectors(x, matrix): + matrix0 = matrix(x) + eigenvalue, eigenvector = np.linalg.eig(matrix0) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] + return vector + + +def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None): + if index == None: + index = np.argmax(np.abs(vector)) + sign_pre = np.sign(np.imag(vector[index])) + for phase in np.arange(0, 2*np.pi, precision): + sign = np.sign(np.imag(vector[index]*cmath.exp(1j*phase))) + if np.abs(np.imag(vector[index]*cmath.exp(1j*phase))) < 1e-9 or sign == -sign_pre: + break + sign_pre = sign + vector = vector*cmath.exp(1j*phase) + if np.real(vector[index]) < 0: + vector = -vector + return vector + + +if __name__ == '__main__': main() \ No newline at end of file diff --git a/academic_codes/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model_with_better_code.py b/academic_codes/topological_invariant/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model_with_better_code.py old mode 100755 new mode 100644 similarity index 96% rename from academic_codes/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model_with_better_code.py rename to academic_codes/topological_invariant/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model_with_better_code.py index adfc149..c840f01 --- a/academic_codes/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model_with_better_code.py +++ b/academic_codes/topological_invariant/2021.03.01_Wilson_loop_in_SSH_model/Wilson_loop_in_SSH_model_with_better_code.py @@ -1,53 +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/10064 -""" - -import numpy as np -import cmath -from math import * - - -def hamiltonian(k): - gamma = 0.5 - lambda0 = 1 - delta = 0 - h = np.zeros((2, 2), dtype=complex) - h[0,0] = delta - h[1,1] = -delta - h[0,1] = gamma+lambda0*cmath.exp(-1j*k) - h[1,0] = gamma+lambda0*cmath.exp(1j*k) - return h - - -def main(): - Num_k = 100 - k_array = np.linspace(-pi, pi, Num_k) - vector_array = [] - for k in k_array: - vector = get_occupied_bands_vectors(k, hamiltonian) - if k != pi: - vector_array.append(vector) - else: - vector_array.append(vector_array[0]) - - # 计算Wilson loop - W_k = 1 - for i0 in range(Num_k-1): - F = np.dot(vector_array[i0+1].transpose().conj(), vector_array[i0]) - W_k = np.dot(F, W_k) - nu = np.log(W_k)/2/pi/1j - # if np.real(nu) < 0: - # nu += 1 - print('p=', nu, '\n') - - -def get_occupied_bands_vectors(x, matrix): - matrix0 = matrix(x) - eigenvalue, eigenvector = np.linalg.eig(matrix0) - vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] - return vector - - -if __name__ == '__main__': - main() +""" +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/10064 +""" + +import numpy as np +import cmath +from math import * + + +def hamiltonian(k): + gamma = 0.5 + lambda0 = 1 + delta = 0 + h = np.zeros((2, 2), dtype=complex) + h[0,0] = delta + h[1,1] = -delta + h[0,1] = gamma+lambda0*cmath.exp(-1j*k) + h[1,0] = gamma+lambda0*cmath.exp(1j*k) + return h + + +def main(): + Num_k = 100 + k_array = np.linspace(-pi, pi, Num_k) + vector_array = [] + for k in k_array: + vector = get_occupied_bands_vectors(k, hamiltonian) + if k != pi: + vector_array.append(vector) + else: + vector_array.append(vector_array[0]) + + # 计算Wilson loop + W_k = 1 + for i0 in range(Num_k-1): + F = np.dot(vector_array[i0+1].transpose().conj(), vector_array[i0]) + W_k = np.dot(F, W_k) + nu = np.log(W_k)/2/pi/1j + # if np.real(nu) < 0: + # nu += 1 + print('p=', nu, '\n') + + +def get_occupied_bands_vectors(x, matrix): + matrix0 = matrix(x) + eigenvalue, eigenvector = np.linalg.eig(matrix0) + vector = eigenvector[:, np.argsort(np.real(eigenvalue))[0]] + return vector + + +if __name__ == '__main__': + main() diff --git a/academic_codes/2021.07.26_calculation_of_chern_number_with_kubo_formula/calculation_of_chern_number_with_kubo_formula.py b/academic_codes/topological_invariant/2021.07.26_calculation_of_chern_number_with_kubo_formula/calculation_of_chern_number_with_kubo_formula.py similarity index 100% rename from academic_codes/2021.07.26_calculation_of_chern_number_with_kubo_formula/calculation_of_chern_number_with_kubo_formula.py rename to academic_codes/topological_invariant/2021.07.26_calculation_of_chern_number_with_kubo_formula/calculation_of_chern_number_with_kubo_formula.py diff --git a/academic_codes/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_Wilson_loop.py b/academic_codes/topological_invariant/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_Wilson_loop.py similarity index 100% rename from academic_codes/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_Wilson_loop.py rename to academic_codes/topological_invariant/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_Wilson_loop.py diff --git a/academic_codes/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_bands.py b/academic_codes/topological_invariant/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_bands.py similarity index 100% rename from academic_codes/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_bands.py rename to academic_codes/topological_invariant/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_bands.py diff --git a/academic_codes/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_nested_Wilson_loop.py b/academic_codes/topological_invariant/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_nested_Wilson_loop.py similarity index 100% rename from academic_codes/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_nested_Wilson_loop.py rename to academic_codes/topological_invariant/2021.12.09_nested_Wilson_loop_of_BBH_model/BBH_nested_Wilson_loop.py diff --git a/academic_codes/2021.12.09_nested_Wilson_loop_of_BBH_model/simple_method_for_degenerate_bands.py b/academic_codes/topological_invariant/2021.12.09_nested_Wilson_loop_of_BBH_model/simple_method_for_degenerate_bands.py similarity index 100% rename from academic_codes/2021.12.09_nested_Wilson_loop_of_BBH_model/simple_method_for_degenerate_bands.py rename to academic_codes/topological_invariant/2021.12.09_nested_Wilson_loop_of_BBH_model/simple_method_for_degenerate_bands.py diff --git a/academic_codes/2021.12.27_Chern_numbers_of_Landau_levels/Chern_numbers_of_Landau_levels_in_square_lattice.py b/academic_codes/topological_invariant/2021.12.27_Chern_numbers_of_Landau_levels/Chern_numbers_of_Landau_levels_in_square_lattice.py similarity index 100% rename from academic_codes/2021.12.27_Chern_numbers_of_Landau_levels/Chern_numbers_of_Landau_levels_in_square_lattice.py rename to academic_codes/topological_invariant/2021.12.27_Chern_numbers_of_Landau_levels/Chern_numbers_of_Landau_levels_in_square_lattice.py diff --git a/academic_codes/2021.12.27_Chern_numbers_of_Landau_levels/quantum_transport_of_square_lattice_under_magnetic_fields_in_multi_lead_systems_with_guan.py b/academic_codes/topological_invariant/2021.12.27_Chern_numbers_of_Landau_levels/quantum_transport_of_square_lattice_under_magnetic_fields_in_multi_lead_systems_with_guan.py similarity index 100% rename from academic_codes/2021.12.27_Chern_numbers_of_Landau_levels/quantum_transport_of_square_lattice_under_magnetic_fields_in_multi_lead_systems_with_guan.py rename to academic_codes/topological_invariant/2021.12.27_Chern_numbers_of_Landau_levels/quantum_transport_of_square_lattice_under_magnetic_fields_in_multi_lead_systems_with_guan.py diff --git a/academic_codes/2021.12.28_calculation_of_Chern_number_by_Wilson_loop/calculation_of_Chern_number_by_Wilson_loop.py b/academic_codes/topological_invariant/2021.12.28_calculation_of_Chern_number_by_Wilson_loop/calculation_of_Chern_number_by_Wilson_loop.py similarity index 100% rename from academic_codes/2021.12.28_calculation_of_Chern_number_by_Wilson_loop/calculation_of_Chern_number_by_Wilson_loop.py rename to academic_codes/topological_invariant/2021.12.28_calculation_of_Chern_number_by_Wilson_loop/calculation_of_Chern_number_by_Wilson_loop.py diff --git a/academic_codes/2021.12.28_calculation_of_Chern_number_by_Wilson_loop/calculation_of_Chern_number_by_Wilson_loop_(wrong).py b/academic_codes/topological_invariant/2021.12.28_calculation_of_Chern_number_by_Wilson_loop/calculation_of_Chern_number_by_Wilson_loop_(wrong).py similarity index 100% rename from academic_codes/2021.12.28_calculation_of_Chern_number_by_Wilson_loop/calculation_of_Chern_number_by_Wilson_loop_(wrong).py rename to academic_codes/topological_invariant/2021.12.28_calculation_of_Chern_number_by_Wilson_loop/calculation_of_Chern_number_by_Wilson_loop_(wrong).py diff --git a/academic_codes/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_Kubo_formula.py b/academic_codes/topological_invariant/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_Kubo_formula.py similarity index 100% rename from academic_codes/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_Kubo_formula.py rename to academic_codes/topological_invariant/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_Kubo_formula.py diff --git a/academic_codes/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_Wilson_loop.py b/academic_codes/topological_invariant/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_Wilson_loop.py similarity index 100% rename from academic_codes/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_Wilson_loop.py rename to academic_codes/topological_invariant/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_Wilson_loop.py diff --git a/academic_codes/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_the_efficient_method.py b/academic_codes/topological_invariant/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_the_efficient_method.py similarity index 100% rename from academic_codes/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_the_efficient_method.py rename to academic_codes/topological_invariant/2022.04.21_Berry_curvature/Berry_curvature_distribution_of_graphene_under_broken_inversion_symmery_with_the_efficient_method.py diff --git a/academic_codes/2022.07.12_gauge_fixing/example_find_vector_with_fixed_gauge_by_making_one_component_real.py b/academic_codes/topological_invariant/2022.07.12_gauge_fixing/example_find_vector_with_fixed_gauge_by_making_one_component_real.py similarity index 100% rename from academic_codes/2022.07.12_gauge_fixing/example_find_vector_with_fixed_gauge_by_making_one_component_real.py rename to academic_codes/topological_invariant/2022.07.12_gauge_fixing/example_find_vector_with_fixed_gauge_by_making_one_component_real.py diff --git a/academic_codes/2022.07.12_gauge_fixing/example_rotation_of_degenerate_vectors.py b/academic_codes/topological_invariant/2022.07.12_gauge_fixing/example_rotation_of_degenerate_vectors.py similarity index 100% rename from academic_codes/2022.07.12_gauge_fixing/example_rotation_of_degenerate_vectors.py rename to academic_codes/topological_invariant/2022.07.12_gauge_fixing/example_rotation_of_degenerate_vectors.py diff --git a/academic_codes/2022.08.12_calculation_of_Chern_number_by_Wilson_loop_for_degenerate_case/calculation_of_Chern_number_by_Wilson_loop_for_degenerate_case.py b/academic_codes/topological_invariant/2022.08.12_calculation_of_Chern_number_by_Wilson_loop_for_degenerate_case/calculation_of_Chern_number_by_Wilson_loop_for_degenerate_case.py similarity index 100% rename from academic_codes/2022.08.12_calculation_of_Chern_number_by_Wilson_loop_for_degenerate_case/calculation_of_Chern_number_by_Wilson_loop_for_degenerate_case.py rename to academic_codes/topological_invariant/2022.08.12_calculation_of_Chern_number_by_Wilson_loop_for_degenerate_case/calculation_of_Chern_number_by_Wilson_loop_for_degenerate_case.py diff --git a/academic_codes/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_Wilson_loop_(function_form).py b/academic_codes/topological_invariant/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_Wilson_loop_(function_form).py similarity index 100% rename from academic_codes/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_Wilson_loop_(function_form).py rename to academic_codes/topological_invariant/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_Wilson_loop_(function_form).py diff --git a/academic_codes/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_Wilson_loop_for_degenerate_case_(function_form).py b/academic_codes/topological_invariant/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_Wilson_loop_for_degenerate_case_(function_form).py similarity index 100% rename from academic_codes/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_Wilson_loop_for_degenerate_case_(function_form).py rename to academic_codes/topological_invariant/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_Wilson_loop_for_degenerate_case_(function_form).py diff --git a/academic_codes/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_the_efficient_method_(function_form).py b/academic_codes/topological_invariant/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_the_efficient_method_(function_form).py similarity index 100% rename from academic_codes/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_the_efficient_method_(function_form).py rename to academic_codes/topological_invariant/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_the_efficient_method_(function_form).py diff --git a/academic_codes/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_the_efficient_method_for_degenerate_case_(function_form).py b/academic_codes/topological_invariant/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_the_efficient_method_for_degenerate_case_(function_form).py similarity index 100% rename from academic_codes/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_the_efficient_method_for_degenerate_case_(function_form).py rename to academic_codes/topological_invariant/2022.08.13_Berry_curvature_distribution_in_function_form/Berry_curvature_distribution_with_the_efficient_method_for_degenerate_case_(function_form).py diff --git a/academic_codes/2022.08.28_calculation_of_Chern_number_by_efficient_method_for_degenerate_case/calculation_of_Chern_number_by_efficient_method_for_degenerate_case.py b/academic_codes/topological_invariant/2022.08.28_calculation_of_Chern_number_by_efficient_method_for_degenerate_case/calculation_of_Chern_number_by_efficient_method_for_degenerate_case.py similarity index 100% rename from academic_codes/2022.08.28_calculation_of_Chern_number_by_efficient_method_for_degenerate_case/calculation_of_Chern_number_by_efficient_method_for_degenerate_case.py rename to academic_codes/topological_invariant/2022.08.28_calculation_of_Chern_number_by_efficient_method_for_degenerate_case/calculation_of_Chern_number_by_efficient_method_for_degenerate_case.py diff --git a/language_learning/2019.10.31_fortran_example/Console1.f90 b/language_learning/fortran/2019.10.31_fortran_example/Console1.f90 similarity index 100% rename from language_learning/2019.10.31_fortran_example/Console1.f90 rename to language_learning/fortran/2019.10.31_fortran_example/Console1.f90 diff --git a/language_learning/2019.10.31_parallel_calculations_with_OpenMP/Console1.f90 b/language_learning/fortran/2019.10.31_parallel_calculations_with_OpenMP/Console1.f90 similarity index 100% rename from language_learning/2019.10.31_parallel_calculations_with_OpenMP/Console1.f90 rename to language_learning/fortran/2019.10.31_parallel_calculations_with_OpenMP/Console1.f90 diff --git a/language_learning/2023.07.19_include_and_use_in_fortran/example.f90 b/language_learning/fortran/2023.07.19_include_and_use_in_fortran/example.f90 similarity index 100% rename from language_learning/2023.07.19_include_and_use_in_fortran/example.f90 rename to language_learning/fortran/2023.07.19_include_and_use_in_fortran/example.f90 diff --git a/language_learning/2023.07.19_include_and_use_in_fortran/example_include_1.f90 b/language_learning/fortran/2023.07.19_include_and_use_in_fortran/example_include_1.f90 similarity index 100% rename from language_learning/2023.07.19_include_and_use_in_fortran/example_include_1.f90 rename to language_learning/fortran/2023.07.19_include_and_use_in_fortran/example_include_1.f90 diff --git a/language_learning/2023.07.19_include_and_use_in_fortran/example_include_2.f90 b/language_learning/fortran/2023.07.19_include_and_use_in_fortran/example_include_2.f90 similarity index 100% rename from language_learning/2023.07.19_include_and_use_in_fortran/example_include_2.f90 rename to language_learning/fortran/2023.07.19_include_and_use_in_fortran/example_include_2.f90 diff --git a/language_learning/2019.12.04_latex_example/basic_structure.tex b/language_learning/latex/2019.12.04_latex_example/basic_structure.tex old mode 100755 new mode 100644 similarity index 97% rename from language_learning/2019.12.04_latex_example/basic_structure.tex rename to language_learning/latex/2019.12.04_latex_example/basic_structure.tex index ab06ec9..632c65c --- a/language_learning/2019.12.04_latex_example/basic_structure.tex +++ b/language_learning/latex/2019.12.04_latex_example/basic_structure.tex @@ -1,5 +1,5 @@ -\documentclass{article} %文档类声明 -%导言区(文档类声明和正文间的是导言区) -\begin{document} %正文开始 - Hello, world! %正文 -\end{document} %正文结束 +\documentclass{article} %文档类声明 +%导言区(文档类声明和正文间的是导言区) +\begin{document} %正文开始 + Hello, world! %正文 +\end{document} %正文结束 diff --git a/language_learning/2019.12.04_latex_example/simple_example.tex b/language_learning/latex/2019.12.04_latex_example/simple_example.tex old mode 100755 new mode 100644 similarity index 97% rename from language_learning/2019.12.04_latex_example/simple_example.tex rename to language_learning/latex/2019.12.04_latex_example/simple_example.tex index 5e1f4cd..107054d --- a/language_learning/2019.12.04_latex_example/simple_example.tex +++ b/language_learning/latex/2019.12.04_latex_example/simple_example.tex @@ -1,18 +1,18 @@ -\documentclass{article} %文档类声明 -\usepackage{ctex} %一个支持中文宏包,如果不用中文无法显示 - - -\begin{document} %正文 - \title{这是一个标题} %标题 - \author{作者名字} %作者 - \date{} %\maketitle默认会加上当前时间,用\date{},空着内容可以取消时间的显示 - \maketitle %加了这个,标题、作者等信息才会显示 - \section{节} - \subsection{小节} - \subsubsection{子小节} - Hello, world! %下面空一行代表换行 - \textbf{用\textbackslash textbf\{\}可以加粗文本} %\textbf{}可以加粗文本 - \section{节} - \part{} - \part{} +\documentclass{article} %文档类声明 +\usepackage{ctex} %一个支持中文宏包,如果不用中文无法显示 + + +\begin{document} %正文 + \title{这是一个标题} %标题 + \author{作者名字} %作者 + \date{} %\maketitle默认会加上当前时间,用\date{},空着内容可以取消时间的显示 + \maketitle %加了这个,标题、作者等信息才会显示 + \section{节} + \subsection{小节} + \subsubsection{子小节} + Hello, world! %下面空一行代表换行 + \textbf{用\textbackslash textbf\{\}可以加粗文本} %\textbf{}可以加粗文本 + \section{节} + \part{} + \part{} \end{document} \ No newline at end of file diff --git a/language_learning/2019.12.05_beamer_as_slides/1.jpg b/language_learning/latex/2019.12.05_beamer_as_slides/1.jpg old mode 100755 new mode 100644 similarity index 100% rename from language_learning/2019.12.05_beamer_as_slides/1.jpg rename to language_learning/latex/2019.12.05_beamer_as_slides/1.jpg diff --git a/language_learning/2019.12.05_beamer_as_slides/beamer.tex b/language_learning/latex/2019.12.05_beamer_as_slides/beamer.tex old mode 100755 new mode 100644 similarity index 97% rename from language_learning/2019.12.05_beamer_as_slides/beamer.tex rename to language_learning/latex/2019.12.05_beamer_as_slides/beamer.tex index eeda189..7e2169e --- a/language_learning/2019.12.05_beamer_as_slides/beamer.tex +++ b/language_learning/latex/2019.12.05_beamer_as_slides/beamer.tex @@ -1,50 +1,50 @@ -\documentclass{beamer} -\usepackage{ctex} %一个支持中文宏包,如果不用中文无法显示 -\usepackage{graphicx} %这个包提供\includegraphics命令来插入图片 - -\usetheme{Boadilla} %主题 -\usecolortheme{default} %主题的颜色 - -\title{这是PPT标题} %标题 -\author{作者名字\inst{1},作者名字\inst{2}} %作者 -\institute{\inst{1}第一个单位\and\inst{2}第二个单位} %这里的\and有换行的效果 -\date{\today} %时间(默认也会显示) -\logo{\includegraphics[height=1.0cm]{1.jpg}} %右下角的小log - -\begin{document} %正文开始 - \begin{frame} %相当于ppt里的一页 - \titlepage %标题页 - \end{frame} - \begin{frame} - \frametitle{目录} %当前页的标题 - \tableofcontents %制作目录,需要\section{}配合 - \end{frame} - - \section{第一节} %用来做目录 - \begin{frame} - \frametitle{当前页的标题1} - 这是第一节第一页的内容。This is a text in the first frame. This is a text in the first frame. This is a text in the first frame. - \end{frame} - - \section{第二节} - \begin{frame} - \frametitle{当前页的标题2} - 这是第二节第一页的内容。这里使用了\textbackslash pause。\pause This is a text in the second frame. This is a text in the second frame. This is a text in the second frame. %\pause是暂停,前后会分成两页。 - \end{frame} - \begin{frame} - \frametitle{当前页的标题3:Two-column slide} - \begin{columns} %分成列 - \column{0.5\textwidth} %占用一半 - This is a text in first column. - $$E=mc^2$$ - \begin{itemize} %制作列表 - \item First item - \item Second item - \end{itemize} - \column{0.5\textwidth} %占用一半 - This text will be in the second column - and on a second tought this is a nice looking - layout in some cases. - \end{columns} - \end{frame} +\documentclass{beamer} +\usepackage{ctex} %一个支持中文宏包,如果不用中文无法显示 +\usepackage{graphicx} %这个包提供\includegraphics命令来插入图片 + +\usetheme{Boadilla} %主题 +\usecolortheme{default} %主题的颜色 + +\title{这是PPT标题} %标题 +\author{作者名字\inst{1},作者名字\inst{2}} %作者 +\institute{\inst{1}第一个单位\and\inst{2}第二个单位} %这里的\and有换行的效果 +\date{\today} %时间(默认也会显示) +\logo{\includegraphics[height=1.0cm]{1.jpg}} %右下角的小log + +\begin{document} %正文开始 + \begin{frame} %相当于ppt里的一页 + \titlepage %标题页 + \end{frame} + \begin{frame} + \frametitle{目录} %当前页的标题 + \tableofcontents %制作目录,需要\section{}配合 + \end{frame} + + \section{第一节} %用来做目录 + \begin{frame} + \frametitle{当前页的标题1} + 这是第一节第一页的内容。This is a text in the first frame. This is a text in the first frame. This is a text in the first frame. + \end{frame} + + \section{第二节} + \begin{frame} + \frametitle{当前页的标题2} + 这是第二节第一页的内容。这里使用了\textbackslash pause。\pause This is a text in the second frame. This is a text in the second frame. This is a text in the second frame. %\pause是暂停,前后会分成两页。 + \end{frame} + \begin{frame} + \frametitle{当前页的标题3:Two-column slide} + \begin{columns} %分成列 + \column{0.5\textwidth} %占用一半 + This is a text in first column. + $$E=mc^2$$ + \begin{itemize} %制作列表 + \item First item + \item Second item + \end{itemize} + \column{0.5\textwidth} %占用一半 + This text will be in the second column + and on a second tought this is a nice looking + layout in some cases. + \end{columns} + \end{frame} \end{document} \ No newline at end of file diff --git a/language_learning/2023.07.25_S1_in_Eq_and_Fig/S1_in_Eq_and_Fig.tex b/language_learning/latex/2023.07.25_S1_in_Eq_and_Fig/S1_in_Eq_and_Fig.tex similarity index 100% rename from language_learning/2023.07.25_S1_in_Eq_and_Fig/S1_in_Eq_and_Fig.tex rename to language_learning/latex/2023.07.25_S1_in_Eq_and_Fig/S1_in_Eq_and_Fig.tex diff --git a/language_learning/2019.10.29_matlab_example/matlab_example.m b/language_learning/others/2019.10.29_matlab_example/matlab_example.m old mode 100755 new mode 100644 similarity index 97% rename from language_learning/2019.10.29_matlab_example/matlab_example.m rename to language_learning/others/2019.10.29_matlab_example/matlab_example.m index 9d4d173..6dfd5da --- a/language_learning/2019.10.29_matlab_example/matlab_example.m +++ b/language_learning/others/2019.10.29_matlab_example/matlab_example.m @@ -1,41 +1,41 @@ -% 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/766 - - -%在matlab里加上百分号“%”是注释。 -%快捷键:选中按ctrl+R为注释,选中按ctrl+T为取消注释, -clc; %clc有窗口清空的效果,一般都用上 -clear all; %clear all可以清空所有变量,一般都用上 -clf; %clf为清空输出的图片内容,在画图的时候最好添加上 - -aa=1 %没加分号“;”,默认打印输出 -bb=2; %加了分号“;”,即不打印输出 -cc1=zeros(2,3) %零矩阵用zeros() -cc2=eye(3,3) %单位矩阵 - -%矩阵乘积 -matrix1=[3,3;3,3] %里面分号代表矩阵换一行。下标是从1开始记。 -matrix2=[2,0;0,2] -matrix_product_1=matrix1*matrix2 % *是正常的矩阵乘积 -matrix_product_2=matrix1.*matrix2 % .*是矩阵每个元素对应相乘 - -%循环 -for i0=1:0.5:2 %循环内容为for到end。a:b:c代表最小为a,最大为c,步长为b - for_result=i0+1i %i在matlab中代表虚数,所以起变量名最好不要用i。要输出内容,后面不加分号即可 -end - -%判断 -if aa~=1 %在matlab中,~=代表不等于,==代表等于 - dd=100 -else - dd=300 -end - -matrix=[2,3;5,7] -%求本征矢和本征值 -[V,D]=eig(matrix) %在matlab中,V的列向量是本征矢,注意是列。D的对角上是对应本征值。 -%求逆 -inv1=inv(matrix) %求逆 -inv2=matrix^-1 %求逆也可以这样写 -%画图 +% 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/766 + + +%在matlab里加上百分号“%”是注释。 +%快捷键:选中按ctrl+R为注释,选中按ctrl+T为取消注释, +clc; %clc有窗口清空的效果,一般都用上 +clear all; %clear all可以清空所有变量,一般都用上 +clf; %clf为清空输出的图片内容,在画图的时候最好添加上 + +aa=1 %没加分号“;”,默认打印输出 +bb=2; %加了分号“;”,即不打印输出 +cc1=zeros(2,3) %零矩阵用zeros() +cc2=eye(3,3) %单位矩阵 + +%矩阵乘积 +matrix1=[3,3;3,3] %里面分号代表矩阵换一行。下标是从1开始记。 +matrix2=[2,0;0,2] +matrix_product_1=matrix1*matrix2 % *是正常的矩阵乘积 +matrix_product_2=matrix1.*matrix2 % .*是矩阵每个元素对应相乘 + +%循环 +for i0=1:0.5:2 %循环内容为for到end。a:b:c代表最小为a,最大为c,步长为b + for_result=i0+1i %i在matlab中代表虚数,所以起变量名最好不要用i。要输出内容,后面不加分号即可 +end + +%判断 +if aa~=1 %在matlab中,~=代表不等于,==代表等于 + dd=100 +else + dd=300 +end + +matrix=[2,3;5,7] +%求本征矢和本征值 +[V,D]=eig(matrix) %在matlab中,V的列向量是本征矢,注意是列。D的对角上是对应本征值。 +%求逆 +inv1=inv(matrix) %求逆 +inv2=matrix^-1 %求逆也可以这样写 +%画图 plot([0:20],[10:-1:-10],'-o') %更多画图技巧可参考官方文档或网上资料 \ No newline at end of file diff --git a/language_learning/2019.11.16_markdown_example/markdown_example.md b/language_learning/others/2019.11.16_markdown_example/markdown_example.md old mode 100755 new mode 100644 similarity index 96% rename from language_learning/2019.11.16_markdown_example/markdown_example.md rename to language_learning/others/2019.11.16_markdown_example/markdown_example.md index 114b040..b6f65bb --- a/language_learning/2019.11.16_markdown_example/markdown_example.md +++ b/language_learning/others/2019.11.16_markdown_example/markdown_example.md @@ -1,47 +1,47 @@ -# 一级标题 -## 二级标题 -### 三级标题 -#### 四级标题 - -有序列表:数字加一个点 - -1. 列表内容 -2. 列表内容 -3. 列表内容 - -无序列表:用 + - * 任何一种都可以。为了不和其他记号重复,个人倾向于用 + 。 - -+ 列表内容 - + 嵌套前面加几个空格。为了保险起见,个人倾向于用四个空格或一个Tab。 -+ 列表内容 - + 列表嵌套 - + 列表嵌套 - + 列表嵌套 - -*倾斜:前后一个星号* - -**加粗:前后两个星号** - -***斜体加粗:前后三个星号*** - -代码:用三个反引号。如下所示。 - -``` -print('hello world') -``` - -分割线:三个或者三个以上的 - 或 * 。为了不和其他记号重复,个人倾向于用 --- 。 - ---- - -在Markdown中空一行可采用以下符号。该符号为HTML中的符号,在Markdown中也是支持的。 - -
- -以下是表格的书写形式。其中,第二行用一个横杆也是可以。为了保险起见,个人倾向于用三个横杆。 - -| 右对齐 | 居中对齐 | 左对齐 | -| ---: | :---: | :--- | -| 单元格 123 | 单元格 456 | 单元格 759 | -| 单元格 | 单元格 | 单元格 | +# 一级标题 +## 二级标题 +### 三级标题 +#### 四级标题 + +有序列表:数字加一个点 + +1. 列表内容 +2. 列表内容 +3. 列表内容 + +无序列表:用 + - * 任何一种都可以。为了不和其他记号重复,个人倾向于用 + 。 + ++ 列表内容 + + 嵌套前面加几个空格。为了保险起见,个人倾向于用四个空格或一个Tab。 ++ 列表内容 + + 列表嵌套 + + 列表嵌套 + + 列表嵌套 + +*倾斜:前后一个星号* + +**加粗:前后两个星号** + +***斜体加粗:前后三个星号*** + +代码:用三个反引号。如下所示。 + +``` +print('hello world') +``` + +分割线:三个或者三个以上的 - 或 * 。为了不和其他记号重复,个人倾向于用 --- 。 + +--- + +在Markdown中空一行可采用以下符号。该符号为HTML中的符号,在Markdown中也是支持的。 + +
+ +以下是表格的书写形式。其中,第二行用一个横杆也是可以。为了保险起见,个人倾向于用三个横杆。 + +| 右对齐 | 居中对齐 | 左对齐 | +| ---: | :---: | :--- | +| 单元格 123 | 单元格 456 | 单元格 759 | +| 单元格 | 单元格 | 单元格 | | 单元格 | 单元格 | 单元格 | \ No newline at end of file diff --git a/language_learning/2022.04.24_html_learning/html_learning.html b/language_learning/others/2022.04.24_html_learning/html_learning.html similarity index 100% rename from language_learning/2022.04.24_html_learning/html_learning.html rename to language_learning/others/2022.04.24_html_learning/html_learning.html diff --git a/language_learning/2019.10.10_python_example/python_example.py b/language_learning/python/2019.10.10_python_example/python_example.py old mode 100755 new mode 100644 similarity index 97% rename from language_learning/2019.10.10_python_example/python_example.py rename to language_learning/python/2019.10.10_python_example/python_example.py index 0c1b49e..323ff38 --- a/language_learning/2019.10.10_python_example/python_example.py +++ b/language_learning/python/2019.10.10_python_example/python_example.py @@ -1,118 +1,118 @@ -""" -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/417 -""" - - -# 第一部分:Python基本操作(循环,判断,函数,文件写入) -print('\n第一部分:Python基本操作(循环,判断,函数,文件写入)\n') # \n代表换行 - -for i in range(5): # 循环(这里只举例for循环,还有其他循环) - print('我是循环产生的数:', i) # Python中没有end,因此每个语句的缩进很重要 - if i == 2: # 判断 - print('判断:我是第三个数 2') - else: - pass # pass代表不执行任何语句,用于占位,可以之后再补充,不然空着会报错 -print() # 输出空一行 - -def fun0(arg): # 定义函数 - print('我是函数中的内容,参数值为:', arg) - return arg*2 # 返回值 - -print('函数返回值:', fun0(5)) # 调用函数 -print() - -def main(): # “主函数”,其实也是一个普通的函数,也可以起其他名字 - print('我是主函数中的内容。') - print() - -if __name__ == '__main__': # 如果直接运行本文件,那么执行以下内容。如果是import本文件,那么不执行。 - main() - -# 关于类class,这里不举例了。科学计算中主要还是面向过程,面向对象用的比较少。 - -# 文件写入 -# 第一种方式 -with open('test1.txt', 'w') as f1: # 其中'w'为重新写入,改为'a'是补充内容 - f1.write(str(100)+'\n这是第一种方式写入文件') # str()为转换成字符串 -# 第二种方式 -f2 = open('test2.txt', 'w') # 打开文件 -f2.write(str(200)+'\n这是第二种方式写入文件') # 写入文件 -f2.close() # 关闭文件 -print('已写入文件!') -print() - - - - -# 第二部分:Numpy库中常用的语句 -print('\n\n\n第二部分:Numpy库中常用的语句\n') -import numpy as np - -print('零矩阵:\n', np.zeros((2, 3))) # 注意np.zeros()里需要填元组,因此显示的是两个括号 -print('单位矩阵:\n', np.identity(3)) # 3行3列的单位矩阵,或者可以用np.eye() -print('把一维数组按对角矩阵排列:\n', np.diag([1, 3, 5])) -print() - -print('指定步长的等差数列:\n', np.arange(1, 5, .5)) # 区间是左闭右开[1, 5),步长为0.5 -print('指定个数的等差数列:\n', np.linspace(-2, 2, 5)) # 区间是左闭右闭[-2, 2], 数量是5 -print() - -print('随机数:\n', np.random.uniform(-2, 2)) # 随机浮点数 -print('随机整数:\n', np.random.randint(-10, 10)) # 区间是左闭右开[-10, 10) -print() - -# 随机数除了使用numpy库,也使用random生成 -import random -print('使用random库的随机数:\n', random.uniform(-2,2)) # 随机浮点数 -print('使用random库的随机整数:\n', random.randint(-10, 10)) # 区间是左闭右闭[-10, 10] -print() - -print('数组从小到大排列:\n', np.sort([1, 7, 0, 3])) -print('数组从小到大排列对应的索引:\n', np.argsort([1, 7, 0, 3])) # 注意Python中下标是从0开始的 -print() - -matrix0 = np.array([[1, 2+9j, 3], [2, 5, 7]]) # numpy数组 -print('矩阵0:\n', matrix0) -print('矩阵的维度:\n', matrix0.shape) # 查看矩阵的维度 -print('矩阵的行数:\n', matrix0.shape[0]) # 查看矩阵的行数 -print('矩阵的列数:\n', matrix0.shape[1]) # 查看矩阵的列数 -print('矩阵转置:\n', matrix0.transpose()) # 矩阵转置 -print('矩阵转置共轭:\n', matrix0.transpose().conj()) # 矩阵转置共轭 -print() - -matrix1 = np.array([[3, 5], [2, 7]]) -eigenvalue, eigenvector = np.linalg.eig(matrix1) # 求本征值,本征向量 -print('矩阵1:\n', matrix1) -print('本征值:\n', eigenvalue) -print('本征向量:\n', eigenvector) # 列向量为本征向量 -print('逆矩阵:\n', np.linalg.inv(matrix1)) # 求逆 -print('计算行列式:\n', np.linalg.det(matrix1)) # 行列式 -print() - -matrix2 = np.array([[1, 2], [3, 4]]) -print('矩阵2:\n', matrix2) -print('矩阵1和矩阵2相乘:\n', np.matmul(matrix1, matrix2)) # 矩阵乘积,或者可以用np.dot() -print() - -a = np.array([1, 2]) -print('numpy数组a=', a) -b = np.array([3, 4]) -print('numpy数组b=', b) -c = np.append(a, b, axis=0) # 增加元素 -print('numpy数组增加元素:\n', c) -d = np.append([a], [b], axis=0) # 增加行(列数要相同),或者用np.row_stack(([a], [b])) -print('numpy数组增加行:\n', d) -e = np.append([a], [b], axis=1) # 增加列(行数要相同),或者用np.column_stack(([a], [b])) -print('numpy数组增加列:\n', e) -print('重新观察:a=', a) -print('重新观察:b=', b) -print() - - -# 如果不是numpy数组,原python数组可以直接用以下方法增加元素 -c = [100, 200] -print('python数组c=', c) -c.append(300) -print('增加元素后,c=', c) +""" +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/417 +""" + + +# 第一部分:Python基本操作(循环,判断,函数,文件写入) +print('\n第一部分:Python基本操作(循环,判断,函数,文件写入)\n') # \n代表换行 + +for i in range(5): # 循环(这里只举例for循环,还有其他循环) + print('我是循环产生的数:', i) # Python中没有end,因此每个语句的缩进很重要 + if i == 2: # 判断 + print('判断:我是第三个数 2') + else: + pass # pass代表不执行任何语句,用于占位,可以之后再补充,不然空着会报错 +print() # 输出空一行 + +def fun0(arg): # 定义函数 + print('我是函数中的内容,参数值为:', arg) + return arg*2 # 返回值 + +print('函数返回值:', fun0(5)) # 调用函数 +print() + +def main(): # “主函数”,其实也是一个普通的函数,也可以起其他名字 + print('我是主函数中的内容。') + print() + +if __name__ == '__main__': # 如果直接运行本文件,那么执行以下内容。如果是import本文件,那么不执行。 + main() + +# 关于类class,这里不举例了。科学计算中主要还是面向过程,面向对象用的比较少。 + +# 文件写入 +# 第一种方式 +with open('test1.txt', 'w') as f1: # 其中'w'为重新写入,改为'a'是补充内容 + f1.write(str(100)+'\n这是第一种方式写入文件') # str()为转换成字符串 +# 第二种方式 +f2 = open('test2.txt', 'w') # 打开文件 +f2.write(str(200)+'\n这是第二种方式写入文件') # 写入文件 +f2.close() # 关闭文件 +print('已写入文件!') +print() + + + + +# 第二部分:Numpy库中常用的语句 +print('\n\n\n第二部分:Numpy库中常用的语句\n') +import numpy as np + +print('零矩阵:\n', np.zeros((2, 3))) # 注意np.zeros()里需要填元组,因此显示的是两个括号 +print('单位矩阵:\n', np.identity(3)) # 3行3列的单位矩阵,或者可以用np.eye() +print('把一维数组按对角矩阵排列:\n', np.diag([1, 3, 5])) +print() + +print('指定步长的等差数列:\n', np.arange(1, 5, .5)) # 区间是左闭右开[1, 5),步长为0.5 +print('指定个数的等差数列:\n', np.linspace(-2, 2, 5)) # 区间是左闭右闭[-2, 2], 数量是5 +print() + +print('随机数:\n', np.random.uniform(-2, 2)) # 随机浮点数 +print('随机整数:\n', np.random.randint(-10, 10)) # 区间是左闭右开[-10, 10) +print() + +# 随机数除了使用numpy库,也使用random生成 +import random +print('使用random库的随机数:\n', random.uniform(-2,2)) # 随机浮点数 +print('使用random库的随机整数:\n', random.randint(-10, 10)) # 区间是左闭右闭[-10, 10] +print() + +print('数组从小到大排列:\n', np.sort([1, 7, 0, 3])) +print('数组从小到大排列对应的索引:\n', np.argsort([1, 7, 0, 3])) # 注意Python中下标是从0开始的 +print() + +matrix0 = np.array([[1, 2+9j, 3], [2, 5, 7]]) # numpy数组 +print('矩阵0:\n', matrix0) +print('矩阵的维度:\n', matrix0.shape) # 查看矩阵的维度 +print('矩阵的行数:\n', matrix0.shape[0]) # 查看矩阵的行数 +print('矩阵的列数:\n', matrix0.shape[1]) # 查看矩阵的列数 +print('矩阵转置:\n', matrix0.transpose()) # 矩阵转置 +print('矩阵转置共轭:\n', matrix0.transpose().conj()) # 矩阵转置共轭 +print() + +matrix1 = np.array([[3, 5], [2, 7]]) +eigenvalue, eigenvector = np.linalg.eig(matrix1) # 求本征值,本征向量 +print('矩阵1:\n', matrix1) +print('本征值:\n', eigenvalue) +print('本征向量:\n', eigenvector) # 列向量为本征向量 +print('逆矩阵:\n', np.linalg.inv(matrix1)) # 求逆 +print('计算行列式:\n', np.linalg.det(matrix1)) # 行列式 +print() + +matrix2 = np.array([[1, 2], [3, 4]]) +print('矩阵2:\n', matrix2) +print('矩阵1和矩阵2相乘:\n', np.matmul(matrix1, matrix2)) # 矩阵乘积,或者可以用np.dot() +print() + +a = np.array([1, 2]) +print('numpy数组a=', a) +b = np.array([3, 4]) +print('numpy数组b=', b) +c = np.append(a, b, axis=0) # 增加元素 +print('numpy数组增加元素:\n', c) +d = np.append([a], [b], axis=0) # 增加行(列数要相同),或者用np.row_stack(([a], [b])) +print('numpy数组增加行:\n', d) +e = np.append([a], [b], axis=1) # 增加列(行数要相同),或者用np.column_stack(([a], [b])) +print('numpy数组增加列:\n', e) +print('重新观察:a=', a) +print('重新观察:b=', b) +print() + + +# 如果不是numpy数组,原python数组可以直接用以下方法增加元素 +c = [100, 200] +print('python数组c=', c) +c.append(300) +print('增加元素后,c=', c) print() \ No newline at end of file diff --git a/language_learning/2019.10.11_neutral_network_with_tensorflow/neutral_network_with_tensorflow.py b/language_learning/python/2019.10.11_neutral_network_with_tensorflow/neutral_network_with_tensorflow.py similarity index 100% rename from language_learning/2019.10.11_neutral_network_with_tensorflow/neutral_network_with_tensorflow.py rename to language_learning/python/2019.10.11_neutral_network_with_tensorflow/neutral_network_with_tensorflow.py diff --git a/language_learning/2019.10.11_tensorflow_example/tensorflow.py b/language_learning/python/2019.10.11_tensorflow_example/tensorflow.py similarity index 100% rename from language_learning/2019.10.11_tensorflow_example/tensorflow.py rename to language_learning/python/2019.10.11_tensorflow_example/tensorflow.py diff --git a/language_learning/2019.10.27_ball_games_with_pygame/ball_games_with_pygame.py b/language_learning/python/2019.10.27_ball_games_with_pygame/ball_games_with_pygame.py similarity index 100% rename from language_learning/2019.10.27_ball_games_with_pygame/ball_games_with_pygame.py rename to language_learning/python/2019.10.27_ball_games_with_pygame/ball_games_with_pygame.py diff --git a/language_learning/2019.10.27_stock_date_from_tushare/stock_date_from_tushare.py b/language_learning/python/2019.10.27_stock_date_from_tushare/stock_date_from_tushare.py similarity index 100% rename from language_learning/2019.10.27_stock_date_from_tushare/stock_date_from_tushare.py rename to language_learning/python/2019.10.27_stock_date_from_tushare/stock_date_from_tushare.py diff --git a/language_learning/2019.12.03_create_GIF_with_python/create_GIF_with_python.py b/language_learning/python/2019.12.03_create_GIF_with_python/create_GIF_with_python.py similarity index 100% rename from language_learning/2019.12.03_create_GIF_with_python/create_GIF_with_python.py rename to language_learning/python/2019.12.03_create_GIF_with_python/create_GIF_with_python.py diff --git a/language_learning/2020.06.01_parallel_calculations_with_python/application_of_parallel_calculations_with_python.py b/language_learning/python/2020.06.01_parallel_calculations_with_python/application_of_parallel_calculations_with_python.py similarity index 100% rename from language_learning/2020.06.01_parallel_calculations_with_python/application_of_parallel_calculations_with_python.py rename to language_learning/python/2020.06.01_parallel_calculations_with_python/application_of_parallel_calculations_with_python.py diff --git a/language_learning/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python.py b/language_learning/python/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python.py old mode 100755 new mode 100644 similarity index 96% rename from language_learning/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python.py rename to language_learning/python/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python.py index c37e6a7..15ee46b --- a/language_learning/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python.py +++ b/language_learning/python/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python.py @@ -1,42 +1,42 @@ -from multiprocessing import Process -import os -import time - -def run_proc(name): # 要执行的代码 - start_time = time.perf_counter() - time.sleep(2) - end_time = time.perf_counter() - print ('Process id running on %s = %s' % (name, os.getpid()), '; running time = %s' % (end_time-start_time)) - - -if __name__ == '__main__': - - # 串行 - print('串行程序') - print('Process id = %s.' % os.getpid()) - start_time = time.perf_counter() - run_proc('job1') - run_proc('job2') - run_proc('job3') - run_proc('job4') - end_time = time.perf_counter() - print('CPU执行时间(s)=', (end_time-start_time), '\n') - - # 并行 - print('并行程序') - print('Process id = %s.' % os.getpid()) - start_time = time.perf_counter() - p1 = Process(target=run_proc, args=('job1',)) - p2 = Process(target=run_proc, args=('job2',)) - p3 = Process(target=run_proc, args=('job3',)) - p4 = Process(target=run_proc, args=('job4',)) - p1.start() - p2.start() - p3.start() - p4.start() - p1.join() # join()方法可以等待子进程结束后再继续往下运行 - p2.join() - p3.join() - p4.join() - end_time = time.perf_counter() +from multiprocessing import Process +import os +import time + +def run_proc(name): # 要执行的代码 + start_time = time.perf_counter() + time.sleep(2) + end_time = time.perf_counter() + print ('Process id running on %s = %s' % (name, os.getpid()), '; running time = %s' % (end_time-start_time)) + + +if __name__ == '__main__': + + # 串行 + print('串行程序') + print('Process id = %s.' % os.getpid()) + start_time = time.perf_counter() + run_proc('job1') + run_proc('job2') + run_proc('job3') + run_proc('job4') + end_time = time.perf_counter() + print('CPU执行时间(s)=', (end_time-start_time), '\n') + + # 并行 + print('并行程序') + print('Process id = %s.' % os.getpid()) + start_time = time.perf_counter() + p1 = Process(target=run_proc, args=('job1',)) + p2 = Process(target=run_proc, args=('job2',)) + p3 = Process(target=run_proc, args=('job3',)) + p4 = Process(target=run_proc, args=('job4',)) + p1.start() + p2.start() + p3.start() + p4.start() + p1.join() # join()方法可以等待子进程结束后再继续往下运行 + p2.join() + p3.join() + p4.join() + end_time = time.perf_counter() print('运行时间(s)=', (end_time-start_time)) \ No newline at end of file diff --git a/language_learning/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python_using_Value.py b/language_learning/python/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python_using_Value.py similarity index 100% rename from language_learning/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python_using_Value.py rename to language_learning/python/2020.06.01_parallel_calculations_with_python/parallel_calculations_with_python_using_Value.py diff --git a/language_learning/2020.08.29_several_python_functions/2D_data_plot_and_write/plot_with_2D_data.py b/language_learning/python/2020.08.29_several_python_functions/2D_data_plot_and_write/plot_with_2D_data.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/2D_data_plot_and_write/plot_with_2D_data.py rename to language_learning/python/2020.08.29_several_python_functions/2D_data_plot_and_write/plot_with_2D_data.py diff --git a/language_learning/2020.08.29_several_python_functions/2D_data_plot_and_write/write_2D_data_into_txt_file.py b/language_learning/python/2020.08.29_several_python_functions/2D_data_plot_and_write/write_2D_data_into_txt_file.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/2D_data_plot_and_write/write_2D_data_into_txt_file.py rename to language_learning/python/2020.08.29_several_python_functions/2D_data_plot_and_write/write_2D_data_into_txt_file.py diff --git a/language_learning/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_plot_1D_bands.py b/language_learning/python/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_plot_1D_bands.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_plot_1D_bands.py rename to language_learning/python/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_plot_1D_bands.py diff --git a/language_learning/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_plot_2D_bands.py b/language_learning/python/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_plot_2D_bands.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_plot_2D_bands.py rename to language_learning/python/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_plot_2D_bands.py diff --git a/language_learning/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_write_1D_data_into_txt_file.py b/language_learning/python/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_write_1D_data_into_txt_file.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_write_1D_data_into_txt_file.py rename to language_learning/python/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_write_1D_data_into_txt_file.py diff --git a/language_learning/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_write_2D_data_into_txt_file.py b/language_learning/python/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_write_2D_data_into_txt_file.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_write_2D_data_into_txt_file.py rename to language_learning/python/2020.08.29_several_python_functions/get_eigenvalues_plot_and_write/get_eigenvalues_and_write_2D_data_into_txt_file.py diff --git a/language_learning/2020.08.29_several_python_functions/python_structure.py b/language_learning/python/2020.08.29_several_python_functions/python_structure.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/python_structure.py rename to language_learning/python/2020.08.29_several_python_functions/python_structure.py diff --git a/language_learning/2020.08.29_several_python_functions/read_txt_file/1D_data.txt b/language_learning/python/2020.08.29_several_python_functions/read_txt_file/1D_data.txt similarity index 100% rename from language_learning/2020.08.29_several_python_functions/read_txt_file/1D_data.txt rename to language_learning/python/2020.08.29_several_python_functions/read_txt_file/1D_data.txt diff --git a/language_learning/2020.08.29_several_python_functions/read_txt_file/2D_data.txt b/language_learning/python/2020.08.29_several_python_functions/read_txt_file/2D_data.txt similarity index 100% rename from language_learning/2020.08.29_several_python_functions/read_txt_file/2D_data.txt rename to language_learning/python/2020.08.29_several_python_functions/read_txt_file/2D_data.txt diff --git a/language_learning/2020.08.29_several_python_functions/read_txt_file/read_1D_data.py b/language_learning/python/2020.08.29_several_python_functions/read_txt_file/read_1D_data.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/read_txt_file/read_1D_data.py rename to language_learning/python/2020.08.29_several_python_functions/read_txt_file/read_1D_data.py diff --git a/language_learning/2020.08.29_several_python_functions/read_txt_file/read_2D_data.py b/language_learning/python/2020.08.29_several_python_functions/read_txt_file/read_2D_data.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/read_txt_file/read_2D_data.py rename to language_learning/python/2020.08.29_several_python_functions/read_txt_file/read_2D_data.py diff --git a/language_learning/2020.08.29_several_python_functions/running_and_write_2D_data_into_txt_file.py b/language_learning/python/2020.08.29_several_python_functions/running_and_write_2D_data_into_txt_file.py similarity index 100% rename from language_learning/2020.08.29_several_python_functions/running_and_write_2D_data_into_txt_file.py rename to language_learning/python/2020.08.29_several_python_functions/running_and_write_2D_data_into_txt_file.py diff --git a/language_learning/2020.10.17_web_scraping_with_BeautifulSoup/BeautifulSoup.py b/language_learning/python/2020.10.17_web_scraping_with_BeautifulSoup/BeautifulSoup.py similarity index 100% rename from language_learning/2020.10.17_web_scraping_with_BeautifulSoup/BeautifulSoup.py rename to language_learning/python/2020.10.17_web_scraping_with_BeautifulSoup/BeautifulSoup.py diff --git a/language_learning/2020.10.31_download_references_in_a_pdf_file_with_python/download_references_in_a_pdf_file_with_python.py b/language_learning/python/2020.10.31_download_references_in_a_pdf_file_with_python/download_references_in_a_pdf_file_with_python.py similarity index 100% rename from language_learning/2020.10.31_download_references_in_a_pdf_file_with_python/download_references_in_a_pdf_file_with_python.py rename to language_learning/python/2020.10.31_download_references_in_a_pdf_file_with_python/download_references_in_a_pdf_file_with_python.py diff --git a/language_learning/2020.10.31_download_references_in_a_pdf_file_with_python/get_links_from_a_pdf_file.py b/language_learning/python/2020.10.31_download_references_in_a_pdf_file_with_python/get_links_from_a_pdf_file.py similarity index 100% rename from language_learning/2020.10.31_download_references_in_a_pdf_file_with_python/get_links_from_a_pdf_file.py rename to language_learning/python/2020.10.31_download_references_in_a_pdf_file_with_python/get_links_from_a_pdf_file.py diff --git a/language_learning/2020.11.25_academic_words/download_academic_word_mp3.py b/language_learning/python/2020.11.25_academic_words/download_academic_word_mp3.py similarity index 100% rename from language_learning/2020.11.25_academic_words/download_academic_word_mp3.py rename to language_learning/python/2020.11.25_academic_words/download_academic_word_mp3.py diff --git a/language_learning/2020.11.25_academic_words/play_academic_words_with_guan.py b/language_learning/python/2020.11.25_academic_words/play_academic_words_with_guan.py similarity index 100% rename from language_learning/2020.11.25_academic_words/play_academic_words_with_guan.py rename to language_learning/python/2020.11.25_academic_words/play_academic_words_with_guan.py diff --git a/language_learning/2020.12.23_plot_with_matplotlib/plot_2D_scatter.py b/language_learning/python/2020.12.23_plot_with_matplotlib/plot_2D_scatter.py similarity index 100% rename from language_learning/2020.12.23_plot_with_matplotlib/plot_2D_scatter.py rename to language_learning/python/2020.12.23_plot_with_matplotlib/plot_2D_scatter.py diff --git a/language_learning/2020.12.23_plot_with_matplotlib/plot_3D_scatter.py b/language_learning/python/2020.12.23_plot_with_matplotlib/plot_3D_scatter.py similarity index 100% rename from language_learning/2020.12.23_plot_with_matplotlib/plot_3D_scatter.py rename to language_learning/python/2020.12.23_plot_with_matplotlib/plot_3D_scatter.py diff --git a/language_learning/2020.12.23_plot_with_matplotlib/plot_3D_surface.py b/language_learning/python/2020.12.23_plot_with_matplotlib/plot_3D_surface.py similarity index 100% rename from language_learning/2020.12.23_plot_with_matplotlib/plot_3D_surface.py rename to language_learning/python/2020.12.23_plot_with_matplotlib/plot_3D_surface.py diff --git a/language_learning/2020.12.23_plot_with_matplotlib/plot_contour.py b/language_learning/python/2020.12.23_plot_with_matplotlib/plot_contour.py similarity index 100% rename from language_learning/2020.12.23_plot_with_matplotlib/plot_contour.py rename to language_learning/python/2020.12.23_plot_with_matplotlib/plot_contour.py diff --git a/language_learning/2020.12.23_plot_with_matplotlib/plot_line.py b/language_learning/python/2020.12.23_plot_with_matplotlib/plot_line.py similarity index 100% rename from language_learning/2020.12.23_plot_with_matplotlib/plot_line.py rename to language_learning/python/2020.12.23_plot_with_matplotlib/plot_line.py diff --git a/language_learning/2021.01.13_python_code_for_data_processing/python_code_for_data_processing.py b/language_learning/python/2021.01.13_python_code_for_data_processing/python_code_for_data_processing.py similarity index 100% rename from language_learning/2021.01.13_python_code_for_data_processing/python_code_for_data_processing.py rename to language_learning/python/2021.01.13_python_code_for_data_processing/python_code_for_data_processing.py diff --git a/language_learning/2021.01.18_run_programs_sequentially/run_programs_sequentially.py b/language_learning/python/2021.01.18_run_programs_sequentially/run_programs_sequentially.py old mode 100755 new mode 100644 similarity index 96% rename from language_learning/2021.01.18_run_programs_sequentially/run_programs_sequentially.py rename to language_learning/python/2021.01.18_run_programs_sequentially/run_programs_sequentially.py index f00514d..ae2f566 --- a/language_learning/2021.01.18_run_programs_sequentially/run_programs_sequentially.py +++ b/language_learning/python/2021.01.18_run_programs_sequentially/run_programs_sequentially.py @@ -1,21 +1,21 @@ -import os -import time - -start = time.time() - -print('程序1开始的时间:', time.ctime()) -start1 = time.time() -os.chdir('D:') # 代码位置 -os.system('python a.py') # 运行a.py -end1 = time.time() -print('程序1运行时间(min)=', (end1-start1)/60,'\n') - -print('程序2开始的时间:', time.ctime()) -start2 = time.time() -os.chdir('E:') # 代码位置 -os.system('python b.py') # 运行b.py -end2 = time.time() -print('程序2运行时间(min)=', (end2-start2)/60, '\n') - -end = time.time() +import os +import time + +start = time.time() + +print('程序1开始的时间:', time.ctime()) +start1 = time.time() +os.chdir('D:') # 代码位置 +os.system('python a.py') # 运行a.py +end1 = time.time() +print('程序1运行时间(min)=', (end1-start1)/60,'\n') + +print('程序2开始的时间:', time.ctime()) +start2 = time.time() +os.chdir('E:') # 代码位置 +os.system('python b.py') # 运行b.py +end2 = time.time() +print('程序2运行时间(min)=', (end2-start2)/60, '\n') + +end = time.time() print('总运行时间(min)=', (end-start)/60) \ No newline at end of file diff --git a/language_learning/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/find_key_words_in_pdf_files.py b/language_learning/python/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/find_key_words_in_pdf_files.py old mode 100755 new mode 100644 similarity index 97% rename from language_learning/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/find_key_words_in_pdf_files.py rename to language_learning/python/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/find_key_words_in_pdf_files.py index 4018d44..affae8f --- a/language_learning/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/find_key_words_in_pdf_files.py +++ b/language_learning/python/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/find_key_words_in_pdf_files.py @@ -1,137 +1,137 @@ -""" -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/9129 -""" - -import os -import re -import time -import logging -logging.Logger.propagate = False -logging.getLogger().setLevel(logging.ERROR) # 只显示error级别的通知 - - -def main(): - # 参数 - key_word_array = ['photonic', 'Berry phase'] - original_path = 'D:\\文献' - - # 查找所有的PDF文件路径 - pdf_file_all = find_files_pdf(original_path) - print('\n该文件夹下总共有', len(pdf_file_all), '个PDF文件。\n') - - f = open('error.txt','w',encoding='utf-8') - f.close() - for key_word in key_word_array: - f = open(str(key_word)+'.txt','w',encoding='utf-8') - f.write('该文件夹下总共有'+str(len(pdf_file_all))+'个PDF文件。\n') - f.close() - - # 查找包含关键词的PDF文件 - i0 = 1 - begin = time.time() - for pdf_file in pdf_file_all: - print('查找第', i0, '个文件,', end='') - begin0 = time.time() - try: - content = get_text_from_pdf(pdf_file) - for key_word in key_word_array: - if re.search(re.compile(key_word),content): - print('发现文件!关键词', key_word, '对应的文件位置在:\n\n', pdf_file, '\n') - with open(str(key_word)+'.txt','a',encoding='utf-8') as f: - f.write('\n查找第'+str(i0)+'个文件时发现文件!位置在:\n'+pdf_file+'\n') - except: - print('出现异常!位置在:\n\n', pdf_file, '\n') - with open('error.txt','a',encoding='utf-8') as f: - f.write('\n解析第'+str(i0)+'个文件时出现异常!位置在:\n'+pdf_file+'\n') - end0 = time.time() - print('用时', end0-begin0, '秒') - i0 += 1 - print('\n全部搜索结束!') - end = time.time() - print('\n总共用时:', (end-begin)/60, '分') - - -def find_files_pdf(path): # 查找所有PDF文件 - file_all = find_files(path) - pdf_file_all = [] - for file0 in file_all: - if re.search(re.compile('^fdp.'),file0[::-1]): # 如果文件是以.pdf结尾 - pdf_file_all.append(file0) - return pdf_file_all - - -def find_files(path): # 查找所有文件 - file_all = [] - path_next_loop = [path] - for i in range(10000): # i为文件在文件夹中的深度 - file_all_in_one_loop, path_next_loop = find_files_loop_module(path_next_loop) - for file_in_one_loop in file_all_in_one_loop: - file_all.append(file_in_one_loop) - if path_next_loop == []: - break - return file_all - - -def find_files_loop_module(path_all): # 查找文件的一个循环模块 - file_all_in_one_loop = [] - path_next_loop = [] - for path in path_all: - filenames = os.listdir(path) - for filename in filenames: - filename = os.path.join(path,filename) - if os.path.isfile(filename): # 如果是文件 - file_all_in_one_loop.append(filename) - else: # 如果是文件夹 - path_next_loop.append(filename) - return file_all_in_one_loop, path_next_loop - - -def get_text_from_pdf(file_path): # 从PDF中获取文本 - from pdfminer.pdfparser import PDFParser, PDFDocument - from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter - from pdfminer.converter import PDFPageAggregator - from pdfminer.layout import LAParams, LTTextBox - from pdfminer.pdfinterp import PDFTextExtractionNotAllowed - - # 用文件对象来创建一个pdf文档分析器 - praser = PDFParser(open(file_path, 'rb')) - # 创建一个PDF文档 - doc = PDFDocument() - # 连接分析器 与文档对象 - praser.set_document(doc) - doc.set_parser(praser) - - # 提供初始化密码 - # 如果没有密码 就创建一个空的字符串 - doc.initialize() - - # 检测文档是否提供txt转换,不提供就忽略 - if not doc.is_extractable: - raise PDFTextExtractionNotAllowed - else: - # 创建PDf 资源管理器 来管理共享资源 - rsrcmgr = PDFResourceManager() - # 创建一个PDF设备对象 - laparams = LAParams() - device = PDFPageAggregator(rsrcmgr, laparams=laparams) - # 创建一个PDF解释器对象 - interpreter = PDFPageInterpreter(rsrcmgr, device) - - # 循环遍历列表,每次处理一个page的内容 - content = '' - for page in doc.get_pages(): - interpreter.process_page(page) - # 接受该页面的LTPage对象 - layout = device.get_result() - # 这里layout是一个LTPage对象,里面存放着这个 page 解析出的各种对象 - # 包括 LTTextBox, LTFigure, LTImage, LTTextBoxHorizontal 等 - for x in layout: - if isinstance(x, LTTextBox): - # print(x.get_text().strip()) - content = content + x.get_text().strip() - return content - - -if __name__ == "__main__": +""" +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/9129 +""" + +import os +import re +import time +import logging +logging.Logger.propagate = False +logging.getLogger().setLevel(logging.ERROR) # 只显示error级别的通知 + + +def main(): + # 参数 + key_word_array = ['photonic', 'Berry phase'] + original_path = 'D:\\文献' + + # 查找所有的PDF文件路径 + pdf_file_all = find_files_pdf(original_path) + print('\n该文件夹下总共有', len(pdf_file_all), '个PDF文件。\n') + + f = open('error.txt','w',encoding='utf-8') + f.close() + for key_word in key_word_array: + f = open(str(key_word)+'.txt','w',encoding='utf-8') + f.write('该文件夹下总共有'+str(len(pdf_file_all))+'个PDF文件。\n') + f.close() + + # 查找包含关键词的PDF文件 + i0 = 1 + begin = time.time() + for pdf_file in pdf_file_all: + print('查找第', i0, '个文件,', end='') + begin0 = time.time() + try: + content = get_text_from_pdf(pdf_file) + for key_word in key_word_array: + if re.search(re.compile(key_word),content): + print('发现文件!关键词', key_word, '对应的文件位置在:\n\n', pdf_file, '\n') + with open(str(key_word)+'.txt','a',encoding='utf-8') as f: + f.write('\n查找第'+str(i0)+'个文件时发现文件!位置在:\n'+pdf_file+'\n') + except: + print('出现异常!位置在:\n\n', pdf_file, '\n') + with open('error.txt','a',encoding='utf-8') as f: + f.write('\n解析第'+str(i0)+'个文件时出现异常!位置在:\n'+pdf_file+'\n') + end0 = time.time() + print('用时', end0-begin0, '秒') + i0 += 1 + print('\n全部搜索结束!') + end = time.time() + print('\n总共用时:', (end-begin)/60, '分') + + +def find_files_pdf(path): # 查找所有PDF文件 + file_all = find_files(path) + pdf_file_all = [] + for file0 in file_all: + if re.search(re.compile('^fdp.'),file0[::-1]): # 如果文件是以.pdf结尾 + pdf_file_all.append(file0) + return pdf_file_all + + +def find_files(path): # 查找所有文件 + file_all = [] + path_next_loop = [path] + for i in range(10000): # i为文件在文件夹中的深度 + file_all_in_one_loop, path_next_loop = find_files_loop_module(path_next_loop) + for file_in_one_loop in file_all_in_one_loop: + file_all.append(file_in_one_loop) + if path_next_loop == []: + break + return file_all + + +def find_files_loop_module(path_all): # 查找文件的一个循环模块 + file_all_in_one_loop = [] + path_next_loop = [] + for path in path_all: + filenames = os.listdir(path) + for filename in filenames: + filename = os.path.join(path,filename) + if os.path.isfile(filename): # 如果是文件 + file_all_in_one_loop.append(filename) + else: # 如果是文件夹 + path_next_loop.append(filename) + return file_all_in_one_loop, path_next_loop + + +def get_text_from_pdf(file_path): # 从PDF中获取文本 + from pdfminer.pdfparser import PDFParser, PDFDocument + from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter + from pdfminer.converter import PDFPageAggregator + from pdfminer.layout import LAParams, LTTextBox + from pdfminer.pdfinterp import PDFTextExtractionNotAllowed + + # 用文件对象来创建一个pdf文档分析器 + praser = PDFParser(open(file_path, 'rb')) + # 创建一个PDF文档 + doc = PDFDocument() + # 连接分析器 与文档对象 + praser.set_document(doc) + doc.set_parser(praser) + + # 提供初始化密码 + # 如果没有密码 就创建一个空的字符串 + doc.initialize() + + # 检测文档是否提供txt转换,不提供就忽略 + if not doc.is_extractable: + raise PDFTextExtractionNotAllowed + else: + # 创建PDf 资源管理器 来管理共享资源 + rsrcmgr = PDFResourceManager() + # 创建一个PDF设备对象 + laparams = LAParams() + device = PDFPageAggregator(rsrcmgr, laparams=laparams) + # 创建一个PDF解释器对象 + interpreter = PDFPageInterpreter(rsrcmgr, device) + + # 循环遍历列表,每次处理一个page的内容 + content = '' + for page in doc.get_pages(): + interpreter.process_page(page) + # 接受该页面的LTPage对象 + layout = device.get_result() + # 这里layout是一个LTPage对象,里面存放着这个 page 解析出的各种对象 + # 包括 LTTextBox, LTFigure, LTImage, LTTextBoxHorizontal 等 + for x in layout: + if isinstance(x, LTTextBox): + # print(x.get_text().strip()) + content = content + x.get_text().strip() + return content + + +if __name__ == "__main__": main() \ No newline at end of file diff --git a/language_learning/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/get_content_in_a_pdf_file.py b/language_learning/python/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/get_content_in_a_pdf_file.py old mode 100755 new mode 100644 similarity index 97% rename from language_learning/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/get_content_in_a_pdf_file.py rename to language_learning/python/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/get_content_in_a_pdf_file.py index 9508c55..5ff8ad4 --- a/language_learning/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/get_content_in_a_pdf_file.py +++ b/language_learning/python/2021.01.23_find_key_words_in_pdf_files_with_pdfminer/get_content_in_a_pdf_file.py @@ -1,63 +1,63 @@ -import os -os.chdir('D:/') # PDF文件存放的位置 -import logging -logging.Logger.propagate = False -logging.getLogger().setLevel(logging.ERROR) # 只显示error级别的通知 - - -def main(): - content = get_text_from_pdf('a') - with open('a.txt', 'w', encoding='utf-8') as f: - f.write(content) - - -def get_text_from_pdf(filename): - from pdfminer.pdfparser import PDFParser, PDFDocument - from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter - from pdfminer.converter import PDFPageAggregator - from pdfminer.layout import LAParams, LTTextBox - from pdfminer.pdfinterp import PDFTextExtractionNotAllowed - - path = filename+".pdf" - - # 用文件对象来创建一个pdf文档分析器 - praser = PDFParser(open(path, 'rb')) - # 创建一个PDF文档 - doc = PDFDocument() - # 连接分析器 与文档对象 - praser.set_document(doc) - doc.set_parser(praser) - - # 提供初始化密码 - # 如果没有密码 就创建一个空的字符串 - doc.initialize() - - # 检测文档是否提供txt转换,不提供就忽略 - if not doc.is_extractable: - raise PDFTextExtractionNotAllowed - else: - # 创建PDf 资源管理器 来管理共享资源 - rsrcmgr = PDFResourceManager() - # 创建一个PDF设备对象 - laparams = LAParams() - device = PDFPageAggregator(rsrcmgr, laparams=laparams) - # 创建一个PDF解释器对象 - interpreter = PDFPageInterpreter(rsrcmgr, device) - - # 循环遍历列表,每次处理一个page的内容 - content = '' - for page in doc.get_pages(): - interpreter.process_page(page) - # 接受该页面的LTPage对象 - layout = device.get_result() - # 这里layout是一个LTPage对象,里面存放着这个 page 解析出的各种对象 - # 包括 LTTextBox, LTFigure, LTImage, LTTextBoxHorizontal 等 - for x in layout: - if isinstance(x, LTTextBox): - # print(x.get_text().strip()) - content = content + x.get_text().strip() - return content - - -if __name__ == "__main__": +import os +os.chdir('D:/') # PDF文件存放的位置 +import logging +logging.Logger.propagate = False +logging.getLogger().setLevel(logging.ERROR) # 只显示error级别的通知 + + +def main(): + content = get_text_from_pdf('a') + with open('a.txt', 'w', encoding='utf-8') as f: + f.write(content) + + +def get_text_from_pdf(filename): + from pdfminer.pdfparser import PDFParser, PDFDocument + from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter + from pdfminer.converter import PDFPageAggregator + from pdfminer.layout import LAParams, LTTextBox + from pdfminer.pdfinterp import PDFTextExtractionNotAllowed + + path = filename+".pdf" + + # 用文件对象来创建一个pdf文档分析器 + praser = PDFParser(open(path, 'rb')) + # 创建一个PDF文档 + doc = PDFDocument() + # 连接分析器 与文档对象 + praser.set_document(doc) + doc.set_parser(praser) + + # 提供初始化密码 + # 如果没有密码 就创建一个空的字符串 + doc.initialize() + + # 检测文档是否提供txt转换,不提供就忽略 + if not doc.is_extractable: + raise PDFTextExtractionNotAllowed + else: + # 创建PDf 资源管理器 来管理共享资源 + rsrcmgr = PDFResourceManager() + # 创建一个PDF设备对象 + laparams = LAParams() + device = PDFPageAggregator(rsrcmgr, laparams=laparams) + # 创建一个PDF解释器对象 + interpreter = PDFPageInterpreter(rsrcmgr, device) + + # 循环遍历列表,每次处理一个page的内容 + content = '' + for page in doc.get_pages(): + interpreter.process_page(page) + # 接受该页面的LTPage对象 + layout = device.get_result() + # 这里layout是一个LTPage对象,里面存放着这个 page 解析出的各种对象 + # 包括 LTTextBox, LTFigure, LTImage, LTTextBoxHorizontal 等 + for x in layout: + if isinstance(x, LTTextBox): + # print(x.get_text().strip()) + content = content + x.get_text().strip() + return content + + +if __name__ == "__main__": main() \ No newline at end of file diff --git a/language_learning/2021.03.18_element_words/download_element_word_mp3.py b/language_learning/python/2021.03.18_element_words/download_element_word_mp3.py similarity index 100% rename from language_learning/2021.03.18_element_words/download_element_word_mp3.py rename to language_learning/python/2021.03.18_element_words/download_element_word_mp3.py diff --git a/language_learning/2021.03.18_element_words/play_element_words_with_guan.py b/language_learning/python/2021.03.18_element_words/play_element_words_with_guan.py similarity index 100% rename from language_learning/2021.03.18_element_words/play_element_words_with_guan.py rename to language_learning/python/2021.03.18_element_words/play_element_words_with_guan.py diff --git a/language_learning/2021.05.10_parallel_calculations_using_sh_files/a.py b/language_learning/python/2021.05.10_parallel_calculations_using_sh_files/a.py old mode 100755 new mode 100644 similarity index 100% rename from language_learning/2021.05.10_parallel_calculations_using_sh_files/a.py rename to language_learning/python/2021.05.10_parallel_calculations_using_sh_files/a.py diff --git a/language_learning/2021.05.10_parallel_calculations_using_sh_files/a.sh b/language_learning/python/2021.05.10_parallel_calculations_using_sh_files/a.sh old mode 100755 new mode 100644 similarity index 100% rename from language_learning/2021.05.10_parallel_calculations_using_sh_files/a.sh rename to language_learning/python/2021.05.10_parallel_calculations_using_sh_files/a.sh diff --git a/language_learning/2021.05.10_parallel_calculations_using_sh_files/combine.py b/language_learning/python/2021.05.10_parallel_calculations_using_sh_files/combine.py old mode 100755 new mode 100644 similarity index 96% rename from language_learning/2021.05.10_parallel_calculations_using_sh_files/combine.py rename to language_learning/python/2021.05.10_parallel_calculations_using_sh_files/combine.py index 75a185c..bce8497 --- a/language_learning/2021.05.10_parallel_calculations_using_sh_files/combine.py +++ b/language_learning/python/2021.05.10_parallel_calculations_using_sh_files/combine.py @@ -1,6 +1,6 @@ -f = open('combine.txt', 'w') -for job_index in range(7): - with open('a'+str(job_index)+'.txt', 'r') as f0: - text = f0.read() - f.write(text) +f = open('combine.txt', 'w') +for job_index in range(7): + with open('a'+str(job_index)+'.txt', 'r') as f0: + text = f0.read() + f.write(text) f.close() \ No newline at end of file diff --git a/language_learning/2021.05.10_parallel_calculations_using_sh_files/task.sh b/language_learning/python/2021.05.10_parallel_calculations_using_sh_files/task.sh old mode 100755 new mode 100644 similarity index 100% rename from language_learning/2021.05.10_parallel_calculations_using_sh_files/task.sh rename to language_learning/python/2021.05.10_parallel_calculations_using_sh_files/task.sh diff --git a/language_learning/2021.06.07_find_common_words_in_APS_abstracts/collect_prb_abstracts.py b/language_learning/python/2021.06.07_find_common_words_in_APS_abstracts/collect_prb_abstracts.py similarity index 100% rename from language_learning/2021.06.07_find_common_words_in_APS_abstracts/collect_prb_abstracts.py rename to language_learning/python/2021.06.07_find_common_words_in_APS_abstracts/collect_prb_abstracts.py diff --git a/language_learning/2021.06.07_find_common_words_in_APS_abstracts/collect_prl_abstracts.py b/language_learning/python/2021.06.07_find_common_words_in_APS_abstracts/collect_prl_abstracts.py similarity index 100% rename from language_learning/2021.06.07_find_common_words_in_APS_abstracts/collect_prl_abstracts.py rename to language_learning/python/2021.06.07_find_common_words_in_APS_abstracts/collect_prl_abstracts.py diff --git a/language_learning/2021.06.07_find_common_words_in_APS_abstracts/count_words.py b/language_learning/python/2021.06.07_find_common_words_in_APS_abstracts/count_words.py similarity index 100% rename from language_learning/2021.06.07_find_common_words_in_APS_abstracts/count_words.py rename to language_learning/python/2021.06.07_find_common_words_in_APS_abstracts/count_words.py diff --git a/language_learning/2021.06.24_sympy_example/sympy_example.py b/language_learning/python/2021.06.24_sympy_example/sympy_example.py similarity index 100% rename from language_learning/2021.06.24_sympy_example/sympy_example.py rename to language_learning/python/2021.06.24_sympy_example/sympy_example.py diff --git a/language_learning/2021.10.26_eig_and_eigh/eig_and_eigh.py b/language_learning/python/2021.10.26_eig_and_eigh/eig_and_eigh.py similarity index 100% rename from language_learning/2021.10.26_eig_and_eigh/eig_and_eigh.py rename to language_learning/python/2021.10.26_eig_and_eigh/eig_and_eigh.py diff --git a/language_learning/2021.11.17_zhihu/nature_physics.py b/language_learning/python/2021.11.17_zhihu/nature_physics.py similarity index 100% rename from language_learning/2021.11.17_zhihu/nature_physics.py rename to language_learning/python/2021.11.17_zhihu/nature_physics.py diff --git a/language_learning/2021.11.17_zhihu/physics_magazine.py b/language_learning/python/2021.11.17_zhihu/physics_magazine.py similarity index 100% rename from language_learning/2021.11.17_zhihu/physics_magazine.py rename to language_learning/python/2021.11.17_zhihu/physics_magazine.py diff --git a/language_learning/2021.11.17_zhihu/prb.py b/language_learning/python/2021.11.17_zhihu/prb.py similarity index 100% rename from language_learning/2021.11.17_zhihu/prb.py rename to language_learning/python/2021.11.17_zhihu/prb.py diff --git a/language_learning/2021.11.17_zhihu/prl.py b/language_learning/python/2021.11.17_zhihu/prl.py similarity index 100% rename from language_learning/2021.11.17_zhihu/prl.py rename to language_learning/python/2021.11.17_zhihu/prl.py diff --git a/language_learning/2021.11.17_zhihu/zhihu.py b/language_learning/python/2021.11.17_zhihu/zhihu.py similarity index 100% rename from language_learning/2021.11.17_zhihu/zhihu.py rename to language_learning/python/2021.11.17_zhihu/zhihu.py diff --git a/language_learning/2022.02.16_change_directory_by_replacement/change_directory_by_replacement _with_guan.py b/language_learning/python/2022.02.16_change_directory_by_replacement/change_directory_by_replacement _with_guan.py similarity index 100% rename from language_learning/2022.02.16_change_directory_by_replacement/change_directory_by_replacement _with_guan.py rename to language_learning/python/2022.02.16_change_directory_by_replacement/change_directory_by_replacement _with_guan.py diff --git a/language_learning/2022.02.16_change_directory_by_replacement/change_directory_by_replacement _with_guan_2.py b/language_learning/python/2022.02.16_change_directory_by_replacement/change_directory_by_replacement _with_guan_2.py similarity index 100% rename from language_learning/2022.02.16_change_directory_by_replacement/change_directory_by_replacement _with_guan_2.py rename to language_learning/python/2022.02.16_change_directory_by_replacement/change_directory_by_replacement _with_guan_2.py diff --git a/language_learning/2022.02.16_change_directory_by_replacement/change_directory_by_replacement.py b/language_learning/python/2022.02.16_change_directory_by_replacement/change_directory_by_replacement.py similarity index 100% rename from language_learning/2022.02.16_change_directory_by_replacement/change_directory_by_replacement.py rename to language_learning/python/2022.02.16_change_directory_by_replacement/change_directory_by_replacement.py diff --git a/language_learning/2022.03.06_numba_time/numba_time.py b/language_learning/python/2022.03.06_numba_time/numba_time.py similarity index 100% rename from language_learning/2022.03.06_numba_time/numba_time.py rename to language_learning/python/2022.03.06_numba_time/numba_time.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/cmath_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/cmath_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/cmath_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/cmath_example.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/copy_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/copy_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/copy_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/copy_example.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/functools_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/functools_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/functools_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/functools_example.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/math_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/math_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/math_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/math_example.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/matplotlib_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/matplotlib_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/matplotlib_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/matplotlib_example.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/multiprocessing_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/multiprocessing_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/multiprocessing_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/multiprocessing_example.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/numpy_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/numpy_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/numpy_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/numpy_example.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/os_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/os_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/os_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/os_example.py diff --git a/language_learning/2022.03.16_frequently_used_python_package/time_example.py b/language_learning/python/2022.03.16_frequently_used_python_package/time_example.py similarity index 100% rename from language_learning/2022.03.16_frequently_used_python_package/time_example.py rename to language_learning/python/2022.03.16_frequently_used_python_package/time_example.py diff --git a/language_learning/2022.07.15_encoding_methods/encoding_methods.py b/language_learning/python/2022.07.15_encoding_methods/encoding_methods.py similarity index 100% rename from language_learning/2022.07.15_encoding_methods/encoding_methods.py rename to language_learning/python/2022.07.15_encoding_methods/encoding_methods.py diff --git a/language_learning/2022.08.31_batch_modify_file_name/batch_modify_file_name.py b/language_learning/python/2022.08.31_batch_modify_file_name/batch_modify_file_name.py similarity index 100% rename from language_learning/2022.08.31_batch_modify_file_name/batch_modify_file_name.py rename to language_learning/python/2022.08.31_batch_modify_file_name/batch_modify_file_name.py diff --git a/language_learning/2022.09.07_move_all_files_to_root_directory/move_all_files_to_root_directory.py b/language_learning/python/2022.09.07_move_all_files_to_root_directory/move_all_files_to_root_directory.py similarity index 100% rename from language_learning/2022.09.07_move_all_files_to_root_directory/move_all_files_to_root_directory.py rename to language_learning/python/2022.09.07_move_all_files_to_root_directory/move_all_files_to_root_directory.py diff --git a/language_learning/2022.09.08_get_file_list_and_write_in_markdown/get_file_list_and_write_in_markdown.py b/language_learning/python/2022.09.08_get_file_list_and_write_in_markdown/get_file_list_and_write_in_markdown.py similarity index 100% rename from language_learning/2022.09.08_get_file_list_and_write_in_markdown/get_file_list_and_write_in_markdown.py rename to language_learning/python/2022.09.08_get_file_list_and_write_in_markdown/get_file_list_and_write_in_markdown.py diff --git a/language_learning/2022.09.12_creat_necessary_file_or_delete_file_with_specific_name/creat_necessary_file_or_delete_file_with_specific_name.py b/language_learning/python/2022.09.12_creat_necessary_file_or_delete_file_with_specific_name/creat_necessary_file_or_delete_file_with_specific_name.py similarity index 100% rename from language_learning/2022.09.12_creat_necessary_file_or_delete_file_with_specific_name/creat_necessary_file_or_delete_file_with_specific_name.py rename to language_learning/python/2022.09.12_creat_necessary_file_or_delete_file_with_specific_name/creat_necessary_file_or_delete_file_with_specific_name.py diff --git a/language_learning/2022.09.14_find_repeated_file_with_same_filename/find_repeated_file_with_same_filename.py b/language_learning/python/2022.09.14_find_repeated_file_with_same_filename/find_repeated_file_with_same_filename.py similarity index 100% rename from language_learning/2022.09.14_find_repeated_file_with_same_filename/find_repeated_file_with_same_filename.py rename to language_learning/python/2022.09.14_find_repeated_file_with_same_filename/find_repeated_file_with_same_filename.py diff --git a/language_learning/2022.09.30_count_file_in_sub_directory/count_file_in_sub_directory.py b/language_learning/python/2022.09.30_count_file_in_sub_directory/count_file_in_sub_directory.py similarity index 100% rename from language_learning/2022.09.30_count_file_in_sub_directory/count_file_in_sub_directory.py rename to language_learning/python/2022.09.30_count_file_in_sub_directory/count_file_in_sub_directory.py diff --git a/language_learning/2023.02.18_plot_contour_for_fixed_value/plot_contour_for_fixed_value.py b/language_learning/python/2023.02.18_plot_contour_for_fixed_value/plot_contour_for_fixed_value.py similarity index 100% rename from language_learning/2023.02.18_plot_contour_for_fixed_value/plot_contour_for_fixed_value.py rename to language_learning/python/2023.02.18_plot_contour_for_fixed_value/plot_contour_for_fixed_value.py diff --git a/language_learning/2023.02.21_parallel_python_manually/a.py b/language_learning/python/2023.02.21_parallel_python_manually/a.py similarity index 100% rename from language_learning/2023.02.21_parallel_python_manually/a.py rename to language_learning/python/2023.02.21_parallel_python_manually/a.py diff --git a/language_learning/2023.02.21_parallel_python_manually/a.sh b/language_learning/python/2023.02.21_parallel_python_manually/a.sh similarity index 100% rename from language_learning/2023.02.21_parallel_python_manually/a.sh rename to language_learning/python/2023.02.21_parallel_python_manually/a.sh diff --git a/language_learning/2023.02.21_parallel_python_manually/parallel.py b/language_learning/python/2023.02.21_parallel_python_manually/parallel.py similarity index 100% rename from language_learning/2023.02.21_parallel_python_manually/parallel.py rename to language_learning/python/2023.02.21_parallel_python_manually/parallel.py diff --git a/language_learning/2023.06.28_combine_two_pdf_files/combine_two_pdf_files.py b/language_learning/python/2023.06.28_combine_two_pdf_files/combine_two_pdf_files.py similarity index 100% rename from language_learning/2023.06.28_combine_two_pdf_files/combine_two_pdf_files.py rename to language_learning/python/2023.06.28_combine_two_pdf_files/combine_two_pdf_files.py