update
This commit is contained in:
		@@ -0,0 +1,48 @@
 | 
				
			|||||||
 | 
					"""
 | 
				
			||||||
 | 
					This code is supported by the website: https://www.guanjihuan.com
 | 
				
			||||||
 | 
					The newest version of this code is on the web page: https://www.guanjihuan.com/archives/22604
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import numpy as np
 | 
				
			||||||
 | 
					import cmath
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None):
 | 
				
			||||||
 | 
					    vector = np.array(vector)
 | 
				
			||||||
 | 
					    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 
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					vector_1 = np.array([np.sqrt(0.5), np.sqrt(0.5)])*cmath.exp(np.random.uniform(0, 1)*1j)
 | 
				
			||||||
 | 
					vector_2 = np.array([1, 0])*cmath.exp(np.random.uniform(0, 1)*1j)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print('\n随机规范的原向量:', vector_1)
 | 
				
			||||||
 | 
					vector_1 = find_vector_with_fixed_gauge_by_making_one_component_real(vector_1, precision=0.001)
 | 
				
			||||||
 | 
					print('固定规范后的向量:', vector_1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					print('\n随机规范的原向量:', vector_2)
 | 
				
			||||||
 | 
					vector_2 = find_vector_with_fixed_gauge_by_making_one_component_real(vector_2, precision=0.001)
 | 
				
			||||||
 | 
					print('固定规范后的向量:', vector_2)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# # 可直接使用Guan软件包来调用以上函数:https://py.guanjihuan.com。
 | 
				
			||||||
 | 
					# # 安装命令:pip install --upgrade guan。
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# import guan
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# print('\n随机规范的原向量:', vector_1)
 | 
				
			||||||
 | 
					# vector_1 = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector_1, precision=0.001)
 | 
				
			||||||
 | 
					# print('固定规范后的向量:', vector_1)
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# print('\n随机规范的原向量:', vector_2)
 | 
				
			||||||
 | 
					# vector_2 = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector_2, precision=0.001)
 | 
				
			||||||
 | 
					# print('固定规范后的向量:', vector_2)
 | 
				
			||||||
@@ -0,0 +1,78 @@
 | 
				
			|||||||
 | 
					"""
 | 
				
			||||||
 | 
					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/22604
 | 
				
			||||||
 | 
					"""
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					import numpy as np
 | 
				
			||||||
 | 
					import math
 | 
				
			||||||
 | 
					import cmath
 | 
				
			||||||
 | 
					# from numba import jit
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# @jit
 | 
				
			||||||
 | 
					def rotation_of_degenerate_vectors(vector1, vector2, index1=None, index2=None, precision=0.01, criterion=0.01, show_theta=0):
 | 
				
			||||||
 | 
					    vector1 = np.array(vector1)
 | 
				
			||||||
 | 
					    vector2 = np.array(vector2)
 | 
				
			||||||
 | 
					    if index1 == None:
 | 
				
			||||||
 | 
					        index1 = np.argmax(np.abs(vector1))
 | 
				
			||||||
 | 
					    if index2 == None:
 | 
				
			||||||
 | 
					        index2 = np.argmax(np.abs(vector2))
 | 
				
			||||||
 | 
					    if np.abs(vector1[index2])>criterion or np.abs(vector2[index1])>criterion:
 | 
				
			||||||
 | 
					        for theta in np.arange(0, 2*math.pi, precision):
 | 
				
			||||||
 | 
					            if show_theta==1:
 | 
				
			||||||
 | 
					                print(theta)
 | 
				
			||||||
 | 
					            for phi1 in np.arange(0, 2*math.pi, precision):
 | 
				
			||||||
 | 
					                for phi2 in np.arange(0, 2*math.pi, precision):
 | 
				
			||||||
 | 
					                    vector1_test = cmath.exp(1j*phi1)*vector1*math.cos(theta)+cmath.exp(1j*phi2)*vector2*math.sin(theta)
 | 
				
			||||||
 | 
					                    vector2_test = -cmath.exp(-1j*phi2)*vector1*math.sin(theta)+cmath.exp(-1j*phi1)*vector2*math.cos(theta)
 | 
				
			||||||
 | 
					                    if np.abs(vector1_test[index2])<criterion and np.abs(vector2_test[index1])<criterion:
 | 
				
			||||||
 | 
					                        vector1 = vector1_test
 | 
				
			||||||
 | 
					                        vector2 = vector2_test
 | 
				
			||||||
 | 
					                        break
 | 
				
			||||||
 | 
					                if np.abs(vector1_test[index2])<criterion and np.abs(vector2_test[index1])<criterion:
 | 
				
			||||||
 | 
					                    break
 | 
				
			||||||
 | 
					            if np.abs(vector1_test[index2])<criterion and np.abs(vector2_test[index1])<criterion:
 | 
				
			||||||
 | 
					                break
 | 
				
			||||||
 | 
					    return vector1, vector2
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					def hamiltonian_of_BBH_model(kx, ky, gamma_x=0.5, gamma_y=0.5, lambda_x=1, lambda_y=1):
 | 
				
			||||||
 | 
					    # label of atoms in a unit cell
 | 
				
			||||||
 | 
					    # (2) —— (0)
 | 
				
			||||||
 | 
					    #  |      |
 | 
				
			||||||
 | 
					    # (1) —— (3)   
 | 
				
			||||||
 | 
					    hamiltonian = np.zeros((4, 4), dtype=complex)
 | 
				
			||||||
 | 
					    hamiltonian[0, 2] = gamma_x+lambda_x*cmath.exp(1j*kx)
 | 
				
			||||||
 | 
					    hamiltonian[1, 3] = gamma_x+lambda_x*cmath.exp(-1j*kx)
 | 
				
			||||||
 | 
					    hamiltonian[0, 3] = gamma_y+lambda_y*cmath.exp(1j*ky)
 | 
				
			||||||
 | 
					    hamiltonian[1, 2] = -gamma_y-lambda_y*cmath.exp(-1j*ky)
 | 
				
			||||||
 | 
					    hamiltonian[2, 0] = np.conj(hamiltonian[0, 2])
 | 
				
			||||||
 | 
					    hamiltonian[3, 1] = np.conj(hamiltonian[1, 3])
 | 
				
			||||||
 | 
					    hamiltonian[3, 0] = np.conj(hamiltonian[0, 3])
 | 
				
			||||||
 | 
					    hamiltonian[2, 1] = np.conj(hamiltonian[1, 2]) 
 | 
				
			||||||
 | 
					    return hamiltonian
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# For kx=0
 | 
				
			||||||
 | 
					print('\nFor kx=0:\n')
 | 
				
			||||||
 | 
					eigenvalue, eigenvector = np.linalg.eigh(hamiltonian_of_BBH_model(kx=0, ky=0))
 | 
				
			||||||
 | 
					print(eigenvalue, '\n')
 | 
				
			||||||
 | 
					print(eigenvector[:, 0])
 | 
				
			||||||
 | 
					print(eigenvector[:, 1], '\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# For kx=0.005
 | 
				
			||||||
 | 
					print('\nFor kx=0.005:\n')
 | 
				
			||||||
 | 
					eigenvalue, eigenvector = np.linalg.eigh(hamiltonian_of_BBH_model(kx=0.005, ky=0))
 | 
				
			||||||
 | 
					print(eigenvalue, '\n')
 | 
				
			||||||
 | 
					print(eigenvector[:, 0])
 | 
				
			||||||
 | 
					print(eigenvector[:, 1], '\n\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# Rotaion
 | 
				
			||||||
 | 
					vector1, vector2 = rotation_of_degenerate_vectors(eigenvector[:, 0], eigenvector[:, 1], precision=0.01, criterion=0.01, show_theta=1)
 | 
				
			||||||
 | 
					print()
 | 
				
			||||||
 | 
					print(vector1)
 | 
				
			||||||
 | 
					print(vector2, '\n')
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					
 | 
				
			||||||
 | 
					# # 可直接使用Guan软件包来调用以上函数:https://py.guanjihuan.com。
 | 
				
			||||||
 | 
					# # 安装命令:pip install --upgrade guan。
 | 
				
			||||||
 | 
					# import guan
 | 
				
			||||||
 | 
					# vector1, vector2 = guan.rotation_of_degenerate_vectors(vector1, vector2, index1=None, index2=None, precision=0.01, criterion=0.01, show_theta=0)
 | 
				
			||||||
 | 
					# hamiltonian = guan.hamiltonian_of_BBH_model(kx, ky, gamma_x=0.5, gamma_y=0.5, lambda_x=1, lambda_y=1)
 | 
				
			||||||
		Reference in New Issue
	
	Block a user