diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg
index dadcc2e..e324de0 100644
--- a/PyPI/setup.cfg
+++ b/PyPI/setup.cfg
@@ -1,7 +1,7 @@
[metadata]
# replace with your username:
name = guan
-version = 0.1.43
+version = 0.1.44
author = guanjihuan
author_email = guanjihuan@163.com
description = An open source python package
diff --git a/PyPI/src/guan.egg-info/PKG-INFO b/PyPI/src/guan.egg-info/PKG-INFO
index d183204..21f7ca1 100644
--- a/PyPI/src/guan.egg-info/PKG-INFO
+++ b/PyPI/src/guan.egg-info/PKG-INFO
@@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: guan
-Version: 0.1.43
+Version: 0.1.44
Summary: An open source python package
Home-page: https://py.guanjihuan.com
Author: guanjihuan
diff --git a/PyPI/src/guan.egg-info/SOURCES.txt b/PyPI/src/guan.egg-info/SOURCES.txt
index f61e2af..7c3d4ec 100644
--- a/PyPI/src/guan.egg-info/SOURCES.txt
+++ b/PyPI/src/guan.egg-info/SOURCES.txt
@@ -4,18 +4,14 @@ pyproject.toml
setup.cfg
src/guan/Fourier_transform.py
src/guan/Green_functions.py
-src/guan/Hamiltonian_of_finite_size_systems.py
-src/guan/Hamiltonian_of_models_in_reciprocal_space.py
+src/guan/Hamiltonian_of_examples.py
src/guan/__init__.py
src/guan/band_structures_and_wave_functions.py
src/guan/basic_functions.py
src/guan/data_processing.py
src/guan/density_of_states.py
-src/guan/file_processing.py
src/guan/others.py
-src/guan/plot_figures.py
src/guan/quantum_transport.py
-src/guan/read_and_write.py
src/guan/topological_invariant.py
src/guan.egg-info/PKG-INFO
src/guan.egg-info/SOURCES.txt
diff --git a/PyPI/src/guan/Hamiltonian_of_examples.py b/PyPI/src/guan/Hamiltonian_of_examples.py
new file mode 100644
index 0000000..e8056b6
--- /dev/null
+++ b/PyPI/src/guan/Hamiltonian_of_examples.py
@@ -0,0 +1,574 @@
+# Module: Hamiltonian_of_examples
+
+# 构建一维的有限尺寸体系哈密顿量(可设置是否为周期边界条件)
+def hamiltonian_of_finite_size_system_along_one_direction(N, on_site=0, hopping=1, period=0):
+ import numpy as np
+ on_site = np.array(on_site)
+ hopping = np.array(hopping)
+ if on_site.shape==():
+ dim = 1
+ else:
+ dim = on_site.shape[0]
+ hamiltonian = np.zeros((N*dim, N*dim), dtype=complex)
+ for i0 in range(N):
+ hamiltonian[i0*dim+0:i0*dim+dim, i0*dim+0:i0*dim+dim] = on_site
+ for i0 in range(N-1):
+ hamiltonian[i0*dim+0:i0*dim+dim, (i0+1)*dim+0:(i0+1)*dim+dim] = hopping
+ hamiltonian[(i0+1)*dim+0:(i0+1)*dim+dim, i0*dim+0:i0*dim+dim] = hopping.transpose().conj()
+ if period == 1:
+ hamiltonian[(N-1)*dim+0:(N-1)*dim+dim, 0:dim] = hopping
+ hamiltonian[0:dim, (N-1)*dim+0:(N-1)*dim+dim] = hopping.transpose().conj()
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 构建二维的方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
+def hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1, N2, on_site=0, hopping_1=1, hopping_2=1, period_1=0, period_2=0):
+ import numpy as np
+ on_site = np.array(on_site)
+ hopping_1 = np.array(hopping_1)
+ hopping_2 = np.array(hopping_2)
+ if on_site.shape==():
+ dim = 1
+ else:
+ dim = on_site.shape[0]
+ hamiltonian = np.zeros((N1*N2*dim, N1*N2*dim), dtype=complex)
+ for i1 in range(N1):
+ for i2 in range(N2):
+ hamiltonian[i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim, i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim] = on_site
+ for i1 in range(N1-1):
+ for i2 in range(N2):
+ hamiltonian[i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim, (i1+1)*N2*dim+i2*dim+0:(i1+1)*N2*dim+i2*dim+dim] = hopping_1
+ hamiltonian[(i1+1)*N2*dim+i2*dim+0:(i1+1)*N2*dim+i2*dim+dim, i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim] = hopping_1.transpose().conj()
+ for i1 in range(N1):
+ for i2 in range(N2-1):
+ hamiltonian[i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim, i1*N2*dim+(i2+1)*dim+0:i1*N2*dim+(i2+1)*dim+dim] = hopping_2
+ hamiltonian[i1*N2*dim+(i2+1)*dim+0:i1*N2*dim+(i2+1)*dim+dim, i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim] = hopping_2.transpose().conj()
+ if period_1 == 1:
+ for i2 in range(N2):
+ hamiltonian[(N1-1)*N2*dim+i2*dim+0:(N1-1)*N2*dim+i2*dim+dim, i2*dim+0:i2*dim+dim] = hopping_1
+ hamiltonian[i2*dim+0:i2*dim+dim, (N1-1)*N2*dim+i2*dim+0:(N1-1)*N2*dim+i2*dim+dim] = hopping_1.transpose().conj()
+ if period_2 == 1:
+ for i1 in range(N1):
+ hamiltonian[i1*N2*dim+(N2-1)*dim+0:i1*N2*dim+(N2-1)*dim+dim, i1*N2*dim+0:i1*N2*dim+dim] = hopping_2
+ hamiltonian[i1*N2*dim+0:i1*N2*dim+dim, i1*N2*dim+(N2-1)*dim+0:i1*N2*dim+(N2-1)*dim+dim] = hopping_2.transpose().conj()
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 构建三维的立方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
+def hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(N1, N2, N3, on_site=0, hopping_1=1, hopping_2=1, hopping_3=1, period_1=0, period_2=0, period_3=0):
+ import numpy as np
+ on_site = np.array(on_site)
+ hopping_1 = np.array(hopping_1)
+ hopping_2 = np.array(hopping_2)
+ hopping_3 = np.array(hopping_3)
+ if on_site.shape==():
+ dim = 1
+ else:
+ dim = on_site.shape[0]
+ hamiltonian = np.zeros((N1*N2*N3*dim, N1*N2*N3*dim), dtype=complex)
+ for i1 in range(N1):
+ for i2 in range(N2):
+ for i3 in range(N3):
+ hamiltonian[i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim, i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim] = on_site
+ for i1 in range(N1-1):
+ for i2 in range(N2):
+ for i3 in range(N3):
+ hamiltonian[i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim, (i1+1)*N2*N3*dim+i2*N3*dim+i3*dim+0:(i1+1)*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_1
+ hamiltonian[(i1+1)*N2*N3*dim+i2*N3*dim+i3*dim+0:(i1+1)*N2*N3*dim+i2*N3*dim+i3*dim+dim, i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_1.transpose().conj()
+ for i1 in range(N1):
+ for i2 in range(N2-1):
+ for i3 in range(N3):
+ hamiltonian[i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim, i1*N2*N3*dim+(i2+1)*N3*dim+i3*dim+0:i1*N2*N3*dim+(i2+1)*N3*dim+i3*dim+dim] = hopping_2
+ hamiltonian[i1*N2*N3*dim+(i2+1)*N3*dim+i3*dim+0:i1*N2*N3*dim+(i2+1)*N3*dim+i3*dim+dim, i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_2.transpose().conj()
+ for i1 in range(N1):
+ for i2 in range(N2):
+ for i3 in range(N3-1):
+ hamiltonian[i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim, i1*N2*N3*dim+i2*N3*dim+(i3+1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(i3+1)*dim+dim] = hopping_3
+ hamiltonian[i1*N2*N3*dim+i2*N3*dim+(i3+1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(i3+1)*dim+dim, i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_3.transpose().conj()
+ if period_1 == 1:
+ for i2 in range(N2):
+ for i3 in range(N3):
+ hamiltonian[(N1-1)*N2*N3*dim+i2*N3*dim+i3*dim+0:(N1-1)*N2*N3*dim+i2*N3*dim+i3*dim+dim, i2*N3*dim+i3*dim+0:i2*N3*dim+i3*dim+dim] = hopping_1
+ hamiltonian[i2*N3*dim+i3*dim+0:i2*N3*dim+i3*dim+dim, (N1-1)*N2*N3*dim+i2*N3*dim+i3*dim+0:(N1-1)*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_1.transpose().conj()
+ if period_2 == 1:
+ for i1 in range(N1):
+ for i3 in range(N3):
+ hamiltonian[i1*N2*N3*dim+(N2-1)*N3*dim+i3*dim+0:i1*N2*N3*dim+(N2-1)*N3*dim+i3*dim+dim, i1*N2*N3*dim+i3*dim+0:i1*N2*N3*dim+i3*dim+dim] = hopping_2
+ hamiltonian[i1*N2*N3*dim+i3*dim+0:i1*N2*N3*dim+i3*dim+dim, i1*N2*N3*dim+(N2-1)*N3*dim+i3*dim+0:i1*N2*N3*dim+(N2-1)*N3*dim+i3*dim+dim] = hopping_2.transpose().conj()
+ if period_3 == 1:
+ for i1 in range(N1):
+ for i2 in range(N2):
+ hamiltonian[i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+dim, i1*N2*N3*dim+i2*N3*dim+0:i1*N2*N3*dim+i2*N3*dim+dim] = hopping_3
+ hamiltonian[i1*N2*N3*dim+i2*N3*dim+0:i1*N2*N3*dim+i2*N3*dim+dim, i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+dim] = hopping_3.transpose().conj()
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 构建有限尺寸的SSH模型哈密顿量
+def hamiltonian_of_finite_size_ssh_model(N, v=0.6, w=1, onsite_1=0, onsite_2=0, period=1):
+ import numpy as np
+ hamiltonian = np.zeros((2*N, 2*N))
+ for i in range(N):
+ hamiltonian[i*2+0, i*2+0] = onsite_1
+ hamiltonian[i*2+1, i*2+1] = onsite_2
+ hamiltonian[i*2+0, i*2+1] = v
+ hamiltonian[i*2+1, i*2+0] = v
+ for i in range(N-1):
+ hamiltonian[i*2+1, (i+1)*2+0] = w
+ hamiltonian[(i+1)*2+0, i*2+1] = w
+ if period==1:
+ hamiltonian[0, 2*N-1] = w
+ hamiltonian[2*N-1, 0] = w
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 获取Zigzag边的石墨烯条带的元胞间跃迁
+def get_hopping_term_of_graphene_ribbon_along_zigzag_direction(N, eta=0):
+ import numpy as np
+ hopping = np.zeros((4*N, 4*N), dtype=complex)
+ for i0 in range(N):
+ hopping[4*i0+0, 4*i0+0] = eta
+ hopping[4*i0+1, 4*i0+1] = eta
+ hopping[4*i0+2, 4*i0+2] = eta
+ hopping[4*i0+3, 4*i0+3] = eta
+ hopping[4*i0+1, 4*i0+0] = 1
+ hopping[4*i0+2, 4*i0+3] = 1
+ import guan
+ guan.statistics_of_guan_package()
+ return hopping
+
+# 构建有限尺寸的石墨烯哈密顿量(可设置是否为周期边界条件)
+def hamiltonian_of_finite_size_system_along_two_directions_for_graphene(N1, N2, period_1=0, period_2=0):
+ import numpy as np
+ import guan
+ on_site = guan.hamiltonian_of_finite_size_system_along_one_direction(4)
+ hopping_1 = guan.get_hopping_term_of_graphene_ribbon_along_zigzag_direction(1)
+ hopping_2 = np.zeros((4, 4), dtype=complex)
+ hopping_2[3, 0] = 1
+ hamiltonian = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1, N2, on_site, hopping_1, hopping_2, period_1, period_2)
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 获取石墨烯有效模型沿着x方向的在位能和跃迁项(其中,动量qy为参数)
+def get_onsite_and_hopping_terms_of_2d_effective_graphene_along_one_direction(qy, t=1, staggered_potential=0, eta=0, valley_index=0):
+ import numpy as np
+ constant = -np.sqrt(3)/2
+ h00 = np.zeros((2, 2), dtype=complex)
+ h00[0, 0] = staggered_potential
+ h00[1, 1] = -staggered_potential
+ h00[0, 1] = -1j*constant*t*np.sin(qy)
+ h00[1, 0] = 1j*constant*t*np.sin(qy)
+ h01 = np.zeros((2, 2), dtype=complex)
+ h01[0, 0] = eta
+ h01[1, 1] = eta
+ if valley_index == 0:
+ h01[0, 1] = constant*t*(-1j/2)
+ h01[1, 0] = constant*t*(-1j/2)
+ else:
+ h01[0, 1] = constant*t*(1j/2)
+ h01[1, 0] = constant*t*(1j/2)
+ import guan
+ guan.statistics_of_guan_package()
+ return h00, h01
+
+# 获取BHZ模型的在位能和跃迁项
+def get_onsite_and_hopping_terms_of_bhz_model(A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1):
+ import numpy as np
+ 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)
+ H1 = np.zeros((4, 4), dtype=complex)
+ H2 = np.zeros((4, 4), dtype=complex)
+ 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
+ import guan
+ guan.statistics_of_guan_package()
+ return H0, H1, H2
+
+# 获取半个BHZ模型的在位能和跃迁项(自旋向上)
+def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_up(A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1):
+ import numpy as np
+ 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((2, 2), dtype=complex)
+ H1 = np.zeros((2, 2), dtype=complex)
+ H2 = np.zeros((2, 2), dtype=complex)
+ H0[0, 0] = E_s
+ H0[1, 1] = E_p
+ H1[0, 0] = V_ss
+ H1[1, 1] = V_pp
+ H1[0, 1] = V_sp
+ H1[1, 0] = -np.conj(V_sp)
+ H2[0, 0] = V_ss
+ H2[1, 1] = V_pp
+ H2[0, 1] = 1j*V_sp
+ H2[1, 0] = 1j*np.conj(V_sp)
+ import guan
+ guan.statistics_of_guan_package()
+ return H0, H1, H2
+
+# 获取半个BHZ模型的在位能和跃迁项(自旋向下)
+def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_down(A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1):
+ import numpy as np
+ 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((2, 2), dtype=complex)
+ H1 = np.zeros((2, 2), dtype=complex)
+ H2 = np.zeros((2, 2), dtype=complex)
+ H0[0, 0] = E_s
+ H0[1, 1] = E_p
+ H1[0, 0] = V_ss
+ H1[1, 1] = V_pp
+ H1[0, 1] = np.conj(V_sp)
+ H1[1, 0] = -V_sp
+ H2[0, 0] = V_ss
+ H2[1, 1] = V_pp
+ H2[0, 1] = -1j*np.conj(V_sp)
+ H2[1, 0] = -1j*V_sp
+ import guan
+ guan.statistics_of_guan_package()
+ return H0, H1, H2
+
+# 一维链的哈密顿量(倒空间)
+def hamiltonian_of_simple_chain(k):
+ import guan
+ hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=0, hopping=1)
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 二维方格子的哈密顿量(倒空间)
+def hamiltonian_of_square_lattice(k1, k2):
+ import guan
+ hamiltonian = guan.two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell=0, hopping_1=1, hopping_2=1)
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 准一维方格子条带的哈密顿量(倒空间)
+def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0):
+ import numpy as np
+ import guan
+ h00 = np.zeros((N, N), dtype=complex) # hopping in a unit cell
+ h01 = np.zeros((N, N), dtype=complex) # hopping between unit cells
+ for i in range(N-1):
+ h00[i, i+1] = 1
+ h00[i+1, i] = 1
+ if period == 1:
+ h00[N-1, 0] = 1
+ h00[0, N-1] = 1
+ for i in range(N):
+ h01[i, i] = 1
+ hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=h00, hopping=h01)
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 三维立方格子的哈密顿量(倒空间)
+def hamiltonian_of_cubic_lattice(k1, k2, k3):
+ import guan
+ hamiltonian = guan.three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell=0, hopping_1=1, hopping_2=1, hopping_3=1)
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# SSH模型的哈密顿量(倒空间)
+def hamiltonian_of_ssh_model(k, v=0.6, w=1):
+ import numpy as np
+ import cmath
+ hamiltonian = np.zeros((2, 2), dtype=complex)
+ hamiltonian[0,1] = v+w*cmath.exp(-1j*k)
+ hamiltonian[1,0] = v+w*cmath.exp(1j*k)
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 石墨烯的哈密顿量(倒空间)
+def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'):
+ import numpy as np
+ import cmath
+ import math
+ if a == 'default':
+ a = 1/math.sqrt(3)
+ h0 = np.zeros((2, 2), dtype=complex) # mass term
+ h1 = np.zeros((2, 2), dtype=complex) # nearest hopping
+ h0[0, 0] = staggered_potential
+ h0[1, 1] = -staggered_potential
+ h1[1, 0] = t*(cmath.exp(1j*k2*a)+cmath.exp(1j*math.sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j/2*k2*a))
+ h1[0, 1] = h1[1, 0].conj()
+ hamiltonian = h0 + h1
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 石墨烯有效模型的哈密顿量(倒空间)
+def effective_hamiltonian_of_graphene(qx, qy, t=1, staggered_potential=0, valley_index=0):
+ import numpy as np
+ hamiltonian = np.zeros((2, 2), dtype=complex)
+ hamiltonian[0, 0] = staggered_potential
+ hamiltonian[1, 1] = -staggered_potential
+ constant = -np.sqrt(3)/2
+ if valley_index == 0:
+ hamiltonian[0, 1] = constant*t*(qx-1j*qy)
+ hamiltonian[1, 0] = constant*t*(qx+1j*qy)
+ else:
+ hamiltonian[0, 1] = constant*t*(-qx-1j*qy)
+ hamiltonian[1, 0] = constant*t*(-qx+1j*qy)
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 石墨烯有效模型离散化后的哈密顿量(倒空间)
+def effective_hamiltonian_of_graphene_after_discretization(qx, qy, t=1, staggered_potential=0, valley_index=0):
+ import numpy as np
+ hamiltonian = np.zeros((2, 2), dtype=complex)
+ hamiltonian[0, 0] = staggered_potential
+ hamiltonian[1, 1] = -staggered_potential
+ constant = -np.sqrt(3)/2
+ if valley_index == 0:
+ hamiltonian[0, 1] = constant*t*(np.sin(qx)-1j*np.sin(qy))
+ hamiltonian[1, 0] = constant*t*(np.sin(qx)+1j*np.sin(qy))
+ else:
+ hamiltonian[0, 1] = constant*t*(-np.sin(qx)-1j*np.sin(qy))
+ hamiltonian[1, 0] = constant*t*(-np.sin(qx)+1j*np.sin(qy))
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 准一维Zigzag边石墨烯条带的哈密顿量(倒空间)
+def hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension(k, N=10, M=0, t=1, period=0):
+ import numpy as np
+ import guan
+ h00 = np.zeros((4*N, 4*N), dtype=complex) # hopping in a unit cell
+ h01 = np.zeros((4*N, 4*N), dtype=complex) # hopping between unit cells
+ 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] = t
+ h00[i*4+1, i*4+0] = t
+ h00[i*4+1, i*4+2] = t
+ h00[i*4+2, i*4+1] = t
+ h00[i*4+2, i*4+3] = t
+ h00[i*4+3, i*4+2] = t
+ for i in range(N-1):
+ h00[i*4+3, (i+1)*4+0] = t
+ h00[(i+1)*4+0, i*4+3] = t
+ if period == 1:
+ h00[(N-1)*4+3, 0] = t
+ h00[0, (N-1)*4+3] = t
+ for i in range(N):
+ h01[i*4+1, i*4+0] = t
+ h01[i*4+2, i*4+3] = t
+ hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=h00, hopping=h01)
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# Haldane模型的哈密顿量(倒空间)
+def hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi='default', a='default'):
+ import numpy as np
+ import cmath
+ import math
+ if phi == 'default':
+ phi=math.pi/4
+ if a == 'default':
+ a=1/math.sqrt(3)
+ h0 = np.zeros((2, 2), dtype=complex) # mass term
+ h1 = np.zeros((2, 2), dtype=complex) # nearest hopping
+ h2 = np.zeros((2, 2), dtype=complex) # next nearest hopping
+ h0[0, 0] = M
+ h0[1, 1] = -M
+ h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*math.sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j/2*k2*a))
+ h1[0, 1] = h1[1, 0].conj()
+ h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*math.sqrt(3)*k1*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j*3/2*k2*a))
+ h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*math.sqrt(3)*k1*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j*3/2*k2*a))
+ hamiltonian = h0 + h1 + h2 + h2.transpose().conj()
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 准一维Haldane模型条带的哈密顿量(倒空间)
+def hamiltonian_of_haldane_model_in_quasi_one_dimension(k, N=10, M=2/3, t1=1, t2=1/3, phi='default', period=0):
+ import numpy as np
+ import cmath
+ import math
+ if phi == 'default':
+ phi=math.pi/4
+ h00 = np.zeros((4*N, 4*N), dtype=complex) # hopping in a unit cell
+ h01 = np.zeros((4*N, 4*N), dtype=complex) # hopping between unit cells
+ 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()
+ if period == 1:
+ h00[(N-1)*4+3, 0] = t1
+ h00[0, (N-1)*4+3] = t1
+ h00[(N-1)*4+2, 0] = t2*cmath.exp(1j*phi)
+ h00[0, (N-1)*4+2] = h00[(N-1)*4+2, 0].conj()
+ h00[(N-1)*4+3, 1] = t2*cmath.exp(1j*phi)
+ h00[1, (N-1)*4+3] = h00[(N-1)*4+3, 1].conj()
+ 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)
+ hamiltonian = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 一个量子反常霍尔效应的哈密顿量(倒空间)
+def hamiltonian_of_one_QAH_model(k1, k2, t1=1, t2=1, t3=0.5, m=-1):
+ import numpy as np
+ import math
+ hamiltonian = np.zeros((2, 2), dtype=complex)
+ hamiltonian[0, 1] = 2*t1*math.cos(k1)-1j*2*t1*math.cos(k2)
+ hamiltonian[1, 0] = 2*t1*math.cos(k1)+1j*2*t1*math.cos(k2)
+ hamiltonian[0, 0] = m+2*t3*math.sin(k1)+2*t3*math.sin(k2)+2*t2*math.cos(k1+k2)
+ hamiltonian[1, 1] = -(m+2*t3*math.sin(k1)+2*t3*math.sin(k2)+2*t2*math.cos(k1+k2))
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# BHZ模型的哈密顿量(倒空间)
+def hamiltonian_of_bhz_model(kx, ky, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01):
+ import numpy as np
+ import math
+ hamiltonian = np.zeros((4, 4), dtype=complex)
+ varepsilon = C-2*D*(2-math.cos(kx)-math.cos(ky))
+ d3 = -2*B*(2-(M/2/B)-math.cos(kx)-math.cos(ky))
+ d1_d2 = A*(math.sin(kx)+1j*math.sin(ky))
+ hamiltonian[0, 0] = varepsilon+d3
+ hamiltonian[1, 1] = varepsilon-d3
+ hamiltonian[0, 1] = np.conj(d1_d2)
+ hamiltonian[1, 0] = d1_d2
+ hamiltonian[2, 2] = varepsilon+d3
+ hamiltonian[3, 3] = varepsilon-d3
+ hamiltonian[2, 3] = -d1_d2
+ hamiltonian[3, 2] = -np.conj(d1_d2)
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 半BHZ模型的哈密顿量(自旋向上)(倒空间)
+def hamiltonian_of_half_bhz_model_for_spin_up(kx, ky, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01):
+ import numpy as np
+ import math
+ hamiltonian = np.zeros((2, 2), dtype=complex)
+ varepsilon = C-2*D*(2-math.cos(kx)-math.cos(ky))
+ d3 = -2*B*(2-(M/2/B)-math.cos(kx)-math.cos(ky))
+ d1_d2 = A*(math.sin(kx)+1j*math.sin(ky))
+ hamiltonian[0, 0] = varepsilon+d3
+ hamiltonian[1, 1] = varepsilon-d3
+ hamiltonian[0, 1] = np.conj(d1_d2)
+ hamiltonian[1, 0] = d1_d2
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# 半BHZ模型的哈密顿量(自旋向下)(倒空间)
+def hamiltonian_of_half_bhz_model_for_spin_down(kx, ky, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01):
+ import numpy as np
+ import math
+ hamiltonian = np.zeros((2, 2), dtype=complex)
+ varepsilon = C-2*D*(2-math.cos(kx)-math.cos(ky))
+ d3 = -2*B*(2-(M/2/B)-math.cos(kx)-math.cos(ky))
+ d1_d2 = A*(math.sin(kx)+1j*math.sin(ky))
+ hamiltonian[0, 0] = varepsilon+d3
+ hamiltonian[1, 1] = varepsilon-d3
+ hamiltonian[0, 1] = -d1_d2
+ hamiltonian[1, 0] = -np.conj(d1_d2)
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# BBH模型的哈密顿量(倒空间)
+def hamiltonian_of_bbh_model(kx, ky, gamma_x=0.5, gamma_y=0.5, lambda_x=1, lambda_y=1):
+ import numpy as np
+ import cmath
+ # 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])
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
+
+# Kagome模型的哈密顿量(倒空间)
+def hamiltonian_of_kagome_lattice(kx, ky, t=1):
+ import numpy as np
+ import math
+ k1_dot_a1 = kx
+ k2_dot_a2 = kx/2+ky*math.sqrt(3)/2
+ k3_dot_a3 = -kx/2+ky*math.sqrt(3)/2
+ hamiltonian = np.zeros((3, 3), dtype=complex)
+ hamiltonian[0, 1] = 2*math.cos(k1_dot_a1)
+ hamiltonian[0, 2] = 2*math.cos(k2_dot_a2)
+ hamiltonian[1, 2] = 2*math.cos(k3_dot_a3)
+ hamiltonian = hamiltonian + hamiltonian.transpose().conj()
+ hamiltonian = -t*hamiltonian
+ import guan
+ guan.statistics_of_guan_package()
+ return hamiltonian
\ No newline at end of file
diff --git a/PyPI/src/guan/Hamiltonian_of_finite_size_systems.py b/PyPI/src/guan/Hamiltonian_of_finite_size_systems.py
deleted file mode 100644
index a8ffaa8..0000000
--- a/PyPI/src/guan/Hamiltonian_of_finite_size_systems.py
+++ /dev/null
@@ -1,260 +0,0 @@
-# Module: Hamiltonian_of_finite_size_systems
-
-# 构建一维的有限尺寸体系哈密顿量(可设置是否为周期边界条件)
-def hamiltonian_of_finite_size_system_along_one_direction(N, on_site=0, hopping=1, period=0):
- import numpy as np
- on_site = np.array(on_site)
- hopping = np.array(hopping)
- if on_site.shape==():
- dim = 1
- else:
- dim = on_site.shape[0]
- hamiltonian = np.zeros((N*dim, N*dim), dtype=complex)
- for i0 in range(N):
- hamiltonian[i0*dim+0:i0*dim+dim, i0*dim+0:i0*dim+dim] = on_site
- for i0 in range(N-1):
- hamiltonian[i0*dim+0:i0*dim+dim, (i0+1)*dim+0:(i0+1)*dim+dim] = hopping
- hamiltonian[(i0+1)*dim+0:(i0+1)*dim+dim, i0*dim+0:i0*dim+dim] = hopping.transpose().conj()
- if period == 1:
- hamiltonian[(N-1)*dim+0:(N-1)*dim+dim, 0:dim] = hopping
- hamiltonian[0:dim, (N-1)*dim+0:(N-1)*dim+dim] = hopping.transpose().conj()
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 构建二维的方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
-def hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1, N2, on_site=0, hopping_1=1, hopping_2=1, period_1=0, period_2=0):
- import numpy as np
- on_site = np.array(on_site)
- hopping_1 = np.array(hopping_1)
- hopping_2 = np.array(hopping_2)
- if on_site.shape==():
- dim = 1
- else:
- dim = on_site.shape[0]
- hamiltonian = np.zeros((N1*N2*dim, N1*N2*dim), dtype=complex)
- for i1 in range(N1):
- for i2 in range(N2):
- hamiltonian[i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim, i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim] = on_site
- for i1 in range(N1-1):
- for i2 in range(N2):
- hamiltonian[i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim, (i1+1)*N2*dim+i2*dim+0:(i1+1)*N2*dim+i2*dim+dim] = hopping_1
- hamiltonian[(i1+1)*N2*dim+i2*dim+0:(i1+1)*N2*dim+i2*dim+dim, i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim] = hopping_1.transpose().conj()
- for i1 in range(N1):
- for i2 in range(N2-1):
- hamiltonian[i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim, i1*N2*dim+(i2+1)*dim+0:i1*N2*dim+(i2+1)*dim+dim] = hopping_2
- hamiltonian[i1*N2*dim+(i2+1)*dim+0:i1*N2*dim+(i2+1)*dim+dim, i1*N2*dim+i2*dim+0:i1*N2*dim+i2*dim+dim] = hopping_2.transpose().conj()
- if period_1 == 1:
- for i2 in range(N2):
- hamiltonian[(N1-1)*N2*dim+i2*dim+0:(N1-1)*N2*dim+i2*dim+dim, i2*dim+0:i2*dim+dim] = hopping_1
- hamiltonian[i2*dim+0:i2*dim+dim, (N1-1)*N2*dim+i2*dim+0:(N1-1)*N2*dim+i2*dim+dim] = hopping_1.transpose().conj()
- if period_2 == 1:
- for i1 in range(N1):
- hamiltonian[i1*N2*dim+(N2-1)*dim+0:i1*N2*dim+(N2-1)*dim+dim, i1*N2*dim+0:i1*N2*dim+dim] = hopping_2
- hamiltonian[i1*N2*dim+0:i1*N2*dim+dim, i1*N2*dim+(N2-1)*dim+0:i1*N2*dim+(N2-1)*dim+dim] = hopping_2.transpose().conj()
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 构建三维的立方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
-def hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(N1, N2, N3, on_site=0, hopping_1=1, hopping_2=1, hopping_3=1, period_1=0, period_2=0, period_3=0):
- import numpy as np
- on_site = np.array(on_site)
- hopping_1 = np.array(hopping_1)
- hopping_2 = np.array(hopping_2)
- hopping_3 = np.array(hopping_3)
- if on_site.shape==():
- dim = 1
- else:
- dim = on_site.shape[0]
- hamiltonian = np.zeros((N1*N2*N3*dim, N1*N2*N3*dim), dtype=complex)
- for i1 in range(N1):
- for i2 in range(N2):
- for i3 in range(N3):
- hamiltonian[i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim, i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim] = on_site
- for i1 in range(N1-1):
- for i2 in range(N2):
- for i3 in range(N3):
- hamiltonian[i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim, (i1+1)*N2*N3*dim+i2*N3*dim+i3*dim+0:(i1+1)*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_1
- hamiltonian[(i1+1)*N2*N3*dim+i2*N3*dim+i3*dim+0:(i1+1)*N2*N3*dim+i2*N3*dim+i3*dim+dim, i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_1.transpose().conj()
- for i1 in range(N1):
- for i2 in range(N2-1):
- for i3 in range(N3):
- hamiltonian[i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim, i1*N2*N3*dim+(i2+1)*N3*dim+i3*dim+0:i1*N2*N3*dim+(i2+1)*N3*dim+i3*dim+dim] = hopping_2
- hamiltonian[i1*N2*N3*dim+(i2+1)*N3*dim+i3*dim+0:i1*N2*N3*dim+(i2+1)*N3*dim+i3*dim+dim, i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_2.transpose().conj()
- for i1 in range(N1):
- for i2 in range(N2):
- for i3 in range(N3-1):
- hamiltonian[i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim, i1*N2*N3*dim+i2*N3*dim+(i3+1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(i3+1)*dim+dim] = hopping_3
- hamiltonian[i1*N2*N3*dim+i2*N3*dim+(i3+1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(i3+1)*dim+dim, i1*N2*N3*dim+i2*N3*dim+i3*dim+0:i1*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_3.transpose().conj()
- if period_1 == 1:
- for i2 in range(N2):
- for i3 in range(N3):
- hamiltonian[(N1-1)*N2*N3*dim+i2*N3*dim+i3*dim+0:(N1-1)*N2*N3*dim+i2*N3*dim+i3*dim+dim, i2*N3*dim+i3*dim+0:i2*N3*dim+i3*dim+dim] = hopping_1
- hamiltonian[i2*N3*dim+i3*dim+0:i2*N3*dim+i3*dim+dim, (N1-1)*N2*N3*dim+i2*N3*dim+i3*dim+0:(N1-1)*N2*N3*dim+i2*N3*dim+i3*dim+dim] = hopping_1.transpose().conj()
- if period_2 == 1:
- for i1 in range(N1):
- for i3 in range(N3):
- hamiltonian[i1*N2*N3*dim+(N2-1)*N3*dim+i3*dim+0:i1*N2*N3*dim+(N2-1)*N3*dim+i3*dim+dim, i1*N2*N3*dim+i3*dim+0:i1*N2*N3*dim+i3*dim+dim] = hopping_2
- hamiltonian[i1*N2*N3*dim+i3*dim+0:i1*N2*N3*dim+i3*dim+dim, i1*N2*N3*dim+(N2-1)*N3*dim+i3*dim+0:i1*N2*N3*dim+(N2-1)*N3*dim+i3*dim+dim] = hopping_2.transpose().conj()
- if period_3 == 1:
- for i1 in range(N1):
- for i2 in range(N2):
- hamiltonian[i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+dim, i1*N2*N3*dim+i2*N3*dim+0:i1*N2*N3*dim+i2*N3*dim+dim] = hopping_3
- hamiltonian[i1*N2*N3*dim+i2*N3*dim+0:i1*N2*N3*dim+i2*N3*dim+dim, i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+dim] = hopping_3.transpose().conj()
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 构建有限尺寸的SSH模型哈密顿量
-def hamiltonian_of_finite_size_ssh_model(N, v=0.6, w=1, onsite_1=0, onsite_2=0, period=1):
- import numpy as np
- hamiltonian = np.zeros((2*N, 2*N))
- for i in range(N):
- hamiltonian[i*2+0, i*2+0] = onsite_1
- hamiltonian[i*2+1, i*2+1] = onsite_2
- hamiltonian[i*2+0, i*2+1] = v
- hamiltonian[i*2+1, i*2+0] = v
- for i in range(N-1):
- hamiltonian[i*2+1, (i+1)*2+0] = w
- hamiltonian[(i+1)*2+0, i*2+1] = w
- if period==1:
- hamiltonian[0, 2*N-1] = w
- hamiltonian[2*N-1, 0] = w
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 获取Zigzag边的石墨烯条带的元胞间跃迁
-def get_hopping_term_of_graphene_ribbon_along_zigzag_direction(N, eta=0):
- import numpy as np
- hopping = np.zeros((4*N, 4*N), dtype=complex)
- for i0 in range(N):
- hopping[4*i0+0, 4*i0+0] = eta
- hopping[4*i0+1, 4*i0+1] = eta
- hopping[4*i0+2, 4*i0+2] = eta
- hopping[4*i0+3, 4*i0+3] = eta
- hopping[4*i0+1, 4*i0+0] = 1
- hopping[4*i0+2, 4*i0+3] = 1
- import guan
- guan.statistics_of_guan_package()
- return hopping
-
-# 构建有限尺寸的石墨烯哈密顿量(可设置是否为周期边界条件)
-def hamiltonian_of_finite_size_system_along_two_directions_for_graphene(N1, N2, period_1=0, period_2=0):
- import numpy as np
- import guan
- on_site = guan.hamiltonian_of_finite_size_system_along_one_direction(4)
- hopping_1 = guan.get_hopping_term_of_graphene_ribbon_along_zigzag_direction(1)
- hopping_2 = np.zeros((4, 4), dtype=complex)
- hopping_2[3, 0] = 1
- hamiltonian = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1, N2, on_site, hopping_1, hopping_2, period_1, period_2)
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 获取石墨烯有效模型沿着x方向的在位能和跃迁项(其中,动量qy为参数)
-def get_onsite_and_hopping_terms_of_2d_effective_graphene_along_one_direction(qy, t=1, staggered_potential=0, eta=0, valley_index=0):
- import numpy as np
- constant = -np.sqrt(3)/2
- h00 = np.zeros((2, 2), dtype=complex)
- h00[0, 0] = staggered_potential
- h00[1, 1] = -staggered_potential
- h00[0, 1] = -1j*constant*t*np.sin(qy)
- h00[1, 0] = 1j*constant*t*np.sin(qy)
- h01 = np.zeros((2, 2), dtype=complex)
- h01[0, 0] = eta
- h01[1, 1] = eta
- if valley_index == 0:
- h01[0, 1] = constant*t*(-1j/2)
- h01[1, 0] = constant*t*(-1j/2)
- else:
- h01[0, 1] = constant*t*(1j/2)
- h01[1, 0] = constant*t*(1j/2)
- import guan
- guan.statistics_of_guan_package()
- return h00, h01
-
-# 获取BHZ模型的在位能和跃迁项
-def get_onsite_and_hopping_terms_of_bhz_model(A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1):
- import numpy as np
- 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)
- H1 = np.zeros((4, 4), dtype=complex)
- H2 = np.zeros((4, 4), dtype=complex)
- 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
- import guan
- guan.statistics_of_guan_package()
- return H0, H1, H2
-
-# 获取半个BHZ模型的在位能和跃迁项(自旋向上)
-def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_up(A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1):
- import numpy as np
- 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((2, 2), dtype=complex)
- H1 = np.zeros((2, 2), dtype=complex)
- H2 = np.zeros((2, 2), dtype=complex)
- H0[0, 0] = E_s
- H0[1, 1] = E_p
- H1[0, 0] = V_ss
- H1[1, 1] = V_pp
- H1[0, 1] = V_sp
- H1[1, 0] = -np.conj(V_sp)
- H2[0, 0] = V_ss
- H2[1, 1] = V_pp
- H2[0, 1] = 1j*V_sp
- H2[1, 0] = 1j*np.conj(V_sp)
- import guan
- guan.statistics_of_guan_package()
- return H0, H1, H2
-
-# 获取半个BHZ模型的在位能和跃迁项(自旋向下)
-def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_down(A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01, a=1):
- import numpy as np
- 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((2, 2), dtype=complex)
- H1 = np.zeros((2, 2), dtype=complex)
- H2 = np.zeros((2, 2), dtype=complex)
- H0[0, 0] = E_s
- H0[1, 1] = E_p
- H1[0, 0] = V_ss
- H1[1, 1] = V_pp
- H1[0, 1] = np.conj(V_sp)
- H1[1, 0] = -V_sp
- H2[0, 0] = V_ss
- H2[1, 1] = V_pp
- H2[0, 1] = -1j*np.conj(V_sp)
- H2[1, 0] = -1j*V_sp
- import guan
- guan.statistics_of_guan_package()
- return H0, H1, H2
\ No newline at end of file
diff --git a/PyPI/src/guan/Hamiltonian_of_models_in_reciprocal_space.py b/PyPI/src/guan/Hamiltonian_of_models_in_reciprocal_space.py
deleted file mode 100644
index ffd5bbd..0000000
--- a/PyPI/src/guan/Hamiltonian_of_models_in_reciprocal_space.py
+++ /dev/null
@@ -1,315 +0,0 @@
-# Module: Hamiltonian_of_models_in_reciprocal_space
-
-# 一维链的哈密顿量
-def hamiltonian_of_simple_chain(k):
- import guan
- hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=0, hopping=1)
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 二维方格子的哈密顿量
-def hamiltonian_of_square_lattice(k1, k2):
- import guan
- hamiltonian = guan.two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell=0, hopping_1=1, hopping_2=1)
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 准一维方格子条带的哈密顿量
-def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0):
- import numpy as np
- import guan
- h00 = np.zeros((N, N), dtype=complex) # hopping in a unit cell
- h01 = np.zeros((N, N), dtype=complex) # hopping between unit cells
- for i in range(N-1):
- h00[i, i+1] = 1
- h00[i+1, i] = 1
- if period == 1:
- h00[N-1, 0] = 1
- h00[0, N-1] = 1
- for i in range(N):
- h01[i, i] = 1
- hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=h00, hopping=h01)
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 三维立方格子的哈密顿量
-def hamiltonian_of_cubic_lattice(k1, k2, k3):
- import guan
- hamiltonian = guan.three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell=0, hopping_1=1, hopping_2=1, hopping_3=1)
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# SSH模型的哈密顿量
-def hamiltonian_of_ssh_model(k, v=0.6, w=1):
- import numpy as np
- import cmath
- hamiltonian = np.zeros((2, 2), dtype=complex)
- hamiltonian[0,1] = v+w*cmath.exp(-1j*k)
- hamiltonian[1,0] = v+w*cmath.exp(1j*k)
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 石墨烯的哈密顿量
-def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'):
- import numpy as np
- import cmath
- import math
- if a == 'default':
- a = 1/math.sqrt(3)
- h0 = np.zeros((2, 2), dtype=complex) # mass term
- h1 = np.zeros((2, 2), dtype=complex) # nearest hopping
- h0[0, 0] = staggered_potential
- h0[1, 1] = -staggered_potential
- h1[1, 0] = t*(cmath.exp(1j*k2*a)+cmath.exp(1j*math.sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j/2*k2*a))
- h1[0, 1] = h1[1, 0].conj()
- hamiltonian = h0 + h1
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 石墨烯有效模型的哈密顿量
-def effective_hamiltonian_of_graphene(qx, qy, t=1, staggered_potential=0, valley_index=0):
- import numpy as np
- hamiltonian = np.zeros((2, 2), dtype=complex)
- hamiltonian[0, 0] = staggered_potential
- hamiltonian[1, 1] = -staggered_potential
- constant = -np.sqrt(3)/2
- if valley_index == 0:
- hamiltonian[0, 1] = constant*t*(qx-1j*qy)
- hamiltonian[1, 0] = constant*t*(qx+1j*qy)
- else:
- hamiltonian[0, 1] = constant*t*(-qx-1j*qy)
- hamiltonian[1, 0] = constant*t*(-qx+1j*qy)
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 石墨烯有效模型离散化后的哈密顿量
-def effective_hamiltonian_of_graphene_after_discretization(qx, qy, t=1, staggered_potential=0, valley_index=0):
- import numpy as np
- hamiltonian = np.zeros((2, 2), dtype=complex)
- hamiltonian[0, 0] = staggered_potential
- hamiltonian[1, 1] = -staggered_potential
- constant = -np.sqrt(3)/2
- if valley_index == 0:
- hamiltonian[0, 1] = constant*t*(np.sin(qx)-1j*np.sin(qy))
- hamiltonian[1, 0] = constant*t*(np.sin(qx)+1j*np.sin(qy))
- else:
- hamiltonian[0, 1] = constant*t*(-np.sin(qx)-1j*np.sin(qy))
- hamiltonian[1, 0] = constant*t*(-np.sin(qx)+1j*np.sin(qy))
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 准一维Zigzag边石墨烯条带的哈密顿量
-def hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension(k, N=10, M=0, t=1, period=0):
- import numpy as np
- import guan
- h00 = np.zeros((4*N, 4*N), dtype=complex) # hopping in a unit cell
- h01 = np.zeros((4*N, 4*N), dtype=complex) # hopping between unit cells
- 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] = t
- h00[i*4+1, i*4+0] = t
- h00[i*4+1, i*4+2] = t
- h00[i*4+2, i*4+1] = t
- h00[i*4+2, i*4+3] = t
- h00[i*4+3, i*4+2] = t
- for i in range(N-1):
- h00[i*4+3, (i+1)*4+0] = t
- h00[(i+1)*4+0, i*4+3] = t
- if period == 1:
- h00[(N-1)*4+3, 0] = t
- h00[0, (N-1)*4+3] = t
- for i in range(N):
- h01[i*4+1, i*4+0] = t
- h01[i*4+2, i*4+3] = t
- hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=h00, hopping=h01)
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# Haldane模型的哈密顿量
-def hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi='default', a='default'):
- import numpy as np
- import cmath
- import math
- if phi == 'default':
- phi=math.pi/4
- if a == 'default':
- a=1/math.sqrt(3)
- h0 = np.zeros((2, 2), dtype=complex) # mass term
- h1 = np.zeros((2, 2), dtype=complex) # nearest hopping
- h2 = np.zeros((2, 2), dtype=complex) # next nearest hopping
- h0[0, 0] = M
- h0[1, 1] = -M
- h1[1, 0] = t1*(cmath.exp(1j*k2*a)+cmath.exp(1j*math.sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j/2*k2*a))
- h1[0, 1] = h1[1, 0].conj()
- h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*math.sqrt(3)*k1*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j*3/2*k2*a))
- h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*math.sqrt(3)*k1*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j*3/2*k2*a))
- hamiltonian = h0 + h1 + h2 + h2.transpose().conj()
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 准一维Haldane模型条带的哈密顿量
-def hamiltonian_of_haldane_model_in_quasi_one_dimension(k, N=10, M=2/3, t1=1, t2=1/3, phi='default', period=0):
- import numpy as np
- import cmath
- import math
- if phi == 'default':
- phi=math.pi/4
- h00 = np.zeros((4*N, 4*N), dtype=complex) # hopping in a unit cell
- h01 = np.zeros((4*N, 4*N), dtype=complex) # hopping between unit cells
- 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()
- if period == 1:
- h00[(N-1)*4+3, 0] = t1
- h00[0, (N-1)*4+3] = t1
- h00[(N-1)*4+2, 0] = t2*cmath.exp(1j*phi)
- h00[0, (N-1)*4+2] = h00[(N-1)*4+2, 0].conj()
- h00[(N-1)*4+3, 1] = t2*cmath.exp(1j*phi)
- h00[1, (N-1)*4+3] = h00[(N-1)*4+3, 1].conj()
- 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)
- hamiltonian = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 一个量子反常霍尔效应的哈密顿量
-def hamiltonian_of_one_QAH_model(k1, k2, t1=1, t2=1, t3=0.5, m=-1):
- import numpy as np
- import math
- hamiltonian = np.zeros((2, 2), dtype=complex)
- hamiltonian[0, 1] = 2*t1*math.cos(k1)-1j*2*t1*math.cos(k2)
- hamiltonian[1, 0] = 2*t1*math.cos(k1)+1j*2*t1*math.cos(k2)
- hamiltonian[0, 0] = m+2*t3*math.sin(k1)+2*t3*math.sin(k2)+2*t2*math.cos(k1+k2)
- hamiltonian[1, 1] = -(m+2*t3*math.sin(k1)+2*t3*math.sin(k2)+2*t2*math.cos(k1+k2))
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# BHZ模型的哈密顿量
-def hamiltonian_of_bhz_model(kx, ky, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01):
- import numpy as np
- import math
- hamiltonian = np.zeros((4, 4), dtype=complex)
- varepsilon = C-2*D*(2-math.cos(kx)-math.cos(ky))
- d3 = -2*B*(2-(M/2/B)-math.cos(kx)-math.cos(ky))
- d1_d2 = A*(math.sin(kx)+1j*math.sin(ky))
- hamiltonian[0, 0] = varepsilon+d3
- hamiltonian[1, 1] = varepsilon-d3
- hamiltonian[0, 1] = np.conj(d1_d2)
- hamiltonian[1, 0] = d1_d2
- hamiltonian[2, 2] = varepsilon+d3
- hamiltonian[3, 3] = varepsilon-d3
- hamiltonian[2, 3] = -d1_d2
- hamiltonian[3, 2] = -np.conj(d1_d2)
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 半BHZ模型的哈密顿量(自旋向上)
-def hamiltonian_of_half_bhz_model_for_spin_up(kx, ky, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01):
- import numpy as np
- import math
- hamiltonian = np.zeros((2, 2), dtype=complex)
- varepsilon = C-2*D*(2-math.cos(kx)-math.cos(ky))
- d3 = -2*B*(2-(M/2/B)-math.cos(kx)-math.cos(ky))
- d1_d2 = A*(math.sin(kx)+1j*math.sin(ky))
- hamiltonian[0, 0] = varepsilon+d3
- hamiltonian[1, 1] = varepsilon-d3
- hamiltonian[0, 1] = np.conj(d1_d2)
- hamiltonian[1, 0] = d1_d2
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# 半BHZ模型的哈密顿量(自旋向下)
-def hamiltonian_of_half_bhz_model_for_spin_down(kx, ky, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25, M=-0.01):
- import numpy as np
- import math
- hamiltonian = np.zeros((2, 2), dtype=complex)
- varepsilon = C-2*D*(2-math.cos(kx)-math.cos(ky))
- d3 = -2*B*(2-(M/2/B)-math.cos(kx)-math.cos(ky))
- d1_d2 = A*(math.sin(kx)+1j*math.sin(ky))
- hamiltonian[0, 0] = varepsilon+d3
- hamiltonian[1, 1] = varepsilon-d3
- hamiltonian[0, 1] = -d1_d2
- hamiltonian[1, 0] = -np.conj(d1_d2)
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# BBH模型的哈密顿量
-def hamiltonian_of_bbh_model(kx, ky, gamma_x=0.5, gamma_y=0.5, lambda_x=1, lambda_y=1):
- import numpy as np
- import cmath
- # 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])
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
-
-# Kagome模型的哈密顿量
-def hamiltonian_of_kagome_lattice(kx, ky, t=1):
- import numpy as np
- import math
- k1_dot_a1 = kx
- k2_dot_a2 = kx/2+ky*math.sqrt(3)/2
- k3_dot_a3 = -kx/2+ky*math.sqrt(3)/2
- hamiltonian = np.zeros((3, 3), dtype=complex)
- hamiltonian[0, 1] = 2*math.cos(k1_dot_a1)
- hamiltonian[0, 2] = 2*math.cos(k2_dot_a2)
- hamiltonian[1, 2] = 2*math.cos(k3_dot_a3)
- hamiltonian = hamiltonian + hamiltonian.transpose().conj()
- hamiltonian = -t*hamiltonian
- import guan
- guan.statistics_of_guan_package()
- return hamiltonian
\ No newline at end of file
diff --git a/PyPI/src/guan/__init__.py b/PyPI/src/guan/__init__.py
index bef4501..01646fb 100644
--- a/PyPI/src/guan/__init__.py
+++ b/PyPI/src/guan/__init__.py
@@ -2,15 +2,11 @@
from .basic_functions import *
from .Fourier_transform import *
-from .Hamiltonian_of_finite_size_systems import *
-from .Hamiltonian_of_models_in_reciprocal_space import *
+from .Hamiltonian_of_examples import *
from .band_structures_and_wave_functions import *
from .Green_functions import *
from .density_of_states import *
from .quantum_transport import *
from .topological_invariant import *
-from .plot_figures import *
-from .read_and_write import *
-from .file_processing import *
from .data_processing import *
from .others import *
\ No newline at end of file
diff --git a/PyPI/src/guan/band_structures_and_wave_functions.py b/PyPI/src/guan/band_structures_and_wave_functions.py
index 7d51264..06b3f77 100644
--- a/PyPI/src/guan/band_structures_and_wave_functions.py
+++ b/PyPI/src/guan/band_structures_and_wave_functions.py
@@ -154,7 +154,7 @@ def find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array
guan.statistics_of_guan_package()
return vector_array
-# 旋转两个简并的波函数(说明:参数比较多,效率不高)
+# 旋转两个简并的波函数(说明:参数比较多,算法效率不高)
def rotation_of_degenerate_vectors(vector1, vector2, index1=None, index2=None, precision=0.01, criterion=0.01, show_theta=0):
import numpy as np
import math
@@ -185,7 +185,7 @@ def rotation_of_degenerate_vectors(vector1, vector2, index1=None, index2=None, p
guan.statistics_of_guan_package()
return vector1, vector2
-# 旋转两个简并的波函数向量组(说明:参数比较多,效率不高)
+# 旋转两个简并的波函数向量组(说明:参数比较多,算法效率不高)
def rotation_of_degenerate_vectors_array(vector1_array, vector2_array, precision=0.01, criterion=0.01, show_theta=0):
import numpy as np
import guan
@@ -201,4 +201,35 @@ def rotation_of_degenerate_vectors_array(vector1_array, vector2_array, precision
for i0 in range(Num_k):
vector1_array[i0], vector2_array[i0] = guan.rotation_of_degenerate_vectors(vector1=vector1_array[i0], vector2=vector2_array[i0], index1=index1, index2=index2, precision=precision, criterion=criterion, show_theta=show_theta)
guan.statistics_of_guan_package()
- return vector1_array, vector2_array
\ No newline at end of file
+ return vector1_array, vector2_array
+
+# 在一组数据中找到数值相近的数
+def find_close_values_in_one_array(array, precision=1e-2):
+ new_array = []
+ i0 = 0
+ for a1 in array:
+ j0 = 0
+ for a2 in array:
+ if j0>i0 and abs(a1-a2)
.*?
', content, re.S)[0][3:-4] - if show_translation==1: - time.sleep(translation_time) - print(translation) - time.sleep(rest_time) - pygame.mixer.music.stop() - print() - import guan - guan.statistics_of_guan_package() - -# 播放挑选过后的学术单词 -def play_selected_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_link=1, rest_time=3): - from bs4 import BeautifulSoup - import re - import urllib.request - import requests - import os - import pygame - import time - import ssl - import random - ssl._create_default_https_context = ssl._create_unverified_context - html = urllib.request.urlopen("https://www.guanjihuan.com/archives/24732").read().decode('utf-8') - if bre_or_ame == 'ame': - directory = 'words_mp3_ameProns/' - elif bre_or_ame == 'bre': - directory = 'words_mp3_breProns/' - exist_directory = os.path.exists(directory) - html_file = urllib.request.urlopen("https://file.guanjihuan.com/words/"+directory).read().decode('utf-8') - if exist_directory == 0: - os.makedirs(directory) - soup = BeautifulSoup(html, features='lxml') - contents = re.findall('.*?
', content, re.S)[0][3:-4] - if show_translation==1: - time.sleep(translation_time) - print(translation) - time.sleep(rest_time) - pygame.mixer.music.stop() - print() - import guan - guan.statistics_of_guan_package() \ No newline at end of file diff --git a/PyPI/src/guan/others.py b/PyPI/src/guan/others.py index 840b578..f9684a0 100644 --- a/PyPI/src/guan/others.py +++ b/PyPI/src/guan/others.py @@ -1,3 +1,1027 @@ +# Module: others + +# 获取运行的日期和时间并写入文件 +def statistics_with_day_and_time(content='', filename='a', file_format='.txt'): + import datetime + datetime_today = str(datetime.date.today()) + datetime_time = datetime.datetime.now().strftime('%H:%M:%S') + with open(filename+file_format, 'a', encoding="utf-8") as f2: + if content == '': + f2.write(datetime_today+' '+datetime_time+'\n') + else: + f2.write(datetime_today+' '+datetime_time+' '+content+'\n') + import guan + guan.statistics_of_guan_package() + +# 统计Python文件中import的数量并排序 +def count_number_of_import_statements(filename, file_format='.py', num=1000): + with open(filename+file_format, 'r') as file: + lines = file.readlines() + import_array = [] + for line in lines: + if 'import ' in line: + line = line.strip() + import_array.append(line) + from collections import Counter + import_statement_counter = Counter(import_array).most_common(num) + import guan + guan.statistics_of_guan_package() + return import_statement_counter + +# 根据一定的字符长度来分割文本 +def split_text(text, wrap_width=3000): + import textwrap + split_text_list = textwrap.wrap(text, wrap_width) + import guan + guan.statistics_of_guan_package() + return split_text_list + +# 获取CPU使用率 +def get_cpu_usage(interval=1): + import psutil + cpu_usage = psutil.cpu_percent(interval=interval) + import guan + guan.statistics_of_guan_package() + return cpu_usage + +# 获取本月的所有日期 +def get_days_of_the_current_month(str_or_datetime='str'): + import datetime + today = datetime.date.today() + first_day_of_month = today.replace(day=1) + if first_day_of_month.month == 12: + next_month = first_day_of_month.replace(year=first_day_of_month.year + 1, month=1) + else: + next_month = first_day_of_month.replace(month=first_day_of_month.month + 1) + current_date = first_day_of_month + day_array = [] + while current_date < next_month: + if str_or_datetime=='str': + day_array.append(str(current_date)) + elif str_or_datetime=='datetime': + day_array.append(current_date) + current_date += datetime.timedelta(days=1) + import guan + guan.statistics_of_guan_package() + return day_array + +# 获取上个月份 +def get_last_month(): + import datetime + today = datetime.date.today() + last_month = today.month - 1 + if last_month == 0: + last_month = 12 + year_of_last_month = today.year - 1 + else: + year_of_last_month = today.year + import guan + guan.statistics_of_guan_package() + return year_of_last_month, last_month + +# 获取上上个月份 +def get_the_month_before_last(): + import datetime + today = datetime.date.today() + the_month_before_last = today.month - 2 + if the_month_before_last == 0: + the_month_before_last = 12 + year_of_the_month_before_last = today.year - 1 + else: + year_of_the_month_before_last = today.year + if the_month_before_last == -1: + the_month_before_last = 11 + year_of_the_month_before_last = today.year - 1 + else: + year_of_the_month_before_last = today.year + import guan + guan.statistics_of_guan_package() + return year_of_the_month_before_last, the_month_before_last + +# 获取上个月的所有日期 +def get_days_of_the_last_month(str_or_datetime='str'): + import datetime + import guan + today = datetime.date.today() + year_of_last_month, last_month = guan.get_last_month() + first_day_of_month = today.replace(year=year_of_last_month, month=last_month, day=1) + if first_day_of_month.month == 12: + next_month = first_day_of_month.replace(year=first_day_of_month.year + 1, month=1) + else: + next_month = first_day_of_month.replace(month=first_day_of_month.month + 1) + current_date = first_day_of_month + day_array = [] + while current_date < next_month: + if str_or_datetime=='str': + day_array.append(str(current_date)) + elif str_or_datetime=='datetime': + day_array.append(current_date) + current_date += datetime.timedelta(days=1) + guan.statistics_of_guan_package() + return day_array + +# 获取上上个月的所有日期 +def get_days_of_the_month_before_last(str_or_datetime='str'): + import datetime + import guan + today = datetime.date.today() + year_of_last_last_month, last_last_month = guan.get_the_month_before_last() + first_day_of_month = today.replace(year=year_of_last_last_month, month=last_last_month, day=1) + if first_day_of_month.month == 12: + next_month = first_day_of_month.replace(year=first_day_of_month.year + 1, month=1) + else: + next_month = first_day_of_month.replace(month=first_day_of_month.month + 1) + current_date = first_day_of_month + day_array = [] + while current_date < next_month: + if str_or_datetime=='str': + day_array.append(str(current_date)) + elif str_or_datetime=='datetime': + day_array.append(current_date) + current_date += datetime.timedelta(days=1) + guan.statistics_of_guan_package() + return day_array + +# 获取所有股票 +def all_stocks(): + import numpy as np + import akshare as ak + stocks = ak.stock_zh_a_spot_em() + title = np.array(stocks.columns) + stock_data = stocks.values + import guan + guan.statistics_of_guan_package() + return title, stock_data + +# 获取所有股票的代码 +def all_stock_symbols(): + import guan + title, stock_data = guan.all_stocks() + stock_symbols = stock_data[:, 1] + guan.statistics_of_guan_package() + return stock_symbols + +# 从股票代码获取股票名称 +def find_stock_name_from_symbol(symbol='000002'): + import guan + title, stock_data = guan.all_stocks() + for stock in stock_data: + if symbol in stock: + stock_name = stock[2] + guan.statistics_of_guan_package() + return stock_name + +# 获取单个股票的历史数据 +def history_data_of_one_stock(symbol='000002', period='daily', start_date="19000101", end_date='21000101'): + # period = 'daily' + # period = 'weekly' + # period = 'monthly' + import numpy as np + import akshare as ak + stock = ak.stock_zh_a_hist(symbol=symbol, period=period, start_date=start_date, end_date=end_date) + title = np.array(stock.columns) + stock_data = stock.values[::-1] + import guan + guan.statistics_of_guan_package() + return title, stock_data + +# 获取软件包中的所有模块名 +def get_all_modules_in_one_package(package_name='guan'): + import pkgutil + package = __import__(package_name) + module_names = [name for _, name, _ in pkgutil.iter_modules(package.__path__)] + import guan + guan.statistics_of_guan_package() + return module_names + +# 获取软件包中一个模块的所有函数名 +def get_all_functions_in_one_module(module_name, package_name='guan'): + import inspect + function_names = [] + module = __import__(f"{package_name}.{module_name}", fromlist=[""]) + for name, obj in inspect.getmembers(module): + if inspect.isfunction(obj): + function_names.append(name) + import guan + guan.statistics_of_guan_package() + return function_names + +# 获取软件包中的所有函数名 +def get_all_functions_in_one_package(package_name='guan', print_show=1): + import guan + module_names = guan.get_all_modules_in_one_package(package_name=package_name) + all_function_names = [] + for module_name in module_names: + function_names = guan.get_all_functions_in_one_module(module_name, package_name='guan') + if print_show == 1: + print('Module:', module_name) + for name in function_names: + all_function_names.append(name) + if print_show == 1: + print('function:', name) + if print_show == 1: + print() + guan.statistics_of_guan_package() + return all_function_names + +# 获取包含某个字符的进程PID值 +def get_PID(name): + import subprocess + command = "ps -ef | grep "+name + result = subprocess.run(command, shell=True, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) + if result.returncode == 0: + ps_ef = result.stdout + import re + ps_ef = re.split(r'\s+', ps_ef) + id_running = ps_ef[1] + import guan + guan.statistics_of_guan_package() + return id_running + +# 在服务器上运行函数(说明:接口服务可能为关闭状态,如果无法使用请联系管理员。目前仅支持长度较短的函数,此外由于服务器只获取一个函数内的代码,因此需要函数是独立的可运行的代码。需要注意的是:返回的值是字符串类型,需要自行转换成数字类型。) +def run(function_name, args=(), return_show=0, get_print=1): + import socket + import json + import guan + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket: + client_socket.connect(('socket.guanjihuan.com', 12345)) + function_source = guan.get_function_source(function_name) + message = { + 'server': "python", + 'function_name': function_name.__name__, + 'function_source': function_source, + 'args': str(args), + 'get_print': get_print, + } + send_message = json.dumps(message) + client_socket.send(send_message.encode()) + return_data = None + while True: + try: + data = client_socket.recv(1024) + return_text = data.decode() + return_dict = json.loads(return_text) + return_data = return_dict['return_data'] + print_data = return_dict['print_data'] + end_message = return_dict['end_message'] + if get_print == 1: + print(print_data) + if return_show == 1: + print(return_data) + if end_message == 1 or return_text == '': + break + except: + break + client_socket.close() + guan.statistics_of_guan_package() + return return_data + +# 在服务器上运行大语言模型,通过Python函数调用(说明:接口服务可能为关闭状态,如果无法使用请联系管理员) +def chat(prompt='你好', stream_show=1, top_p=0.8, temperature=0.8): + import socket + import json + response = '' + with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as client_socket: + client_socket.settimeout(15) + client_socket.connect(('socket.guanjihuan.com', 12345)) + message = { + 'server': "chat.guanjihuan.com", + 'prompt': prompt, + 'top_p': top_p, + 'temperature': temperature, + } + send_message = json.dumps(message) + client_socket.send(send_message.encode()) + while True: + try: + data = client_socket.recv(1024) + stream_response = data.decode() + response_dict = json.loads(stream_response) + stream_response = response_dict['response'] + end_message = response_dict['end_message'] + if end_message == 1: + break + elif stream_response == '': + break + else: + if stream_show == 1: + print(stream_response) + print('\n---\n') + response = stream_response + except: + break + client_socket.close() + import guan + guan.statistics_of_guan_package() + return response + +# 查找文件名相同的文件 +def find_repeated_file_with_same_filename(directory='./', ignored_directory_with_words=[], ignored_file_with_words=[], num=1000): + import os + from collections import Counter + file_list = [] + for root, dirs, files in os.walk(directory): + for i0 in range(len(files)): + file_list.append(files[i0]) + for word in ignored_directory_with_words: + if word in root: + file_list.remove(files[i0]) + for word in ignored_file_with_words: + if word in files[i0]: + try: + file_list.remove(files[i0]) + except: + pass + count_file = Counter(file_list).most_common(num) + repeated_file = [] + for item in count_file: + if item[1]>1: + repeated_file.append(item) + import guan + guan.statistics_of_guan_package() + return repeated_file + +# 统计各个子文件夹中的文件数量 +def count_file_in_sub_directory(directory='./', sort=0, reverse=1, print_show=1, smaller_than_num=None): + import os + import numpy as np + dirs_list = [] + for root, dirs, files in os.walk(directory): + if dirs != []: + for i0 in range(len(dirs)): + dirs_list.append(root+'/'+dirs[i0]) + count_file_array = [] + for sub_dir in dirs_list: + file_list = [] + for root, dirs, files in os.walk(sub_dir): + for i0 in range(len(files)): + file_list.append(files[i0]) + count_file = len(file_list) + count_file_array.append(count_file) + if sort == 0: + if print_show == 1: + if smaller_than_num == None: + print(sub_dir) + print(count_file) + print() + else: + if count_file.*?
', content, re.S)[0][3:-4] + if show_translation==1: + time.sleep(translation_time) + print(translation) + time.sleep(rest_time) + pygame.mixer.music.stop() + print() + import guan + guan.statistics_of_guan_package() + +# 播放挑选过后的学术单词 +def play_selected_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_link=1, rest_time=3): + from bs4 import BeautifulSoup + import re + import urllib.request + import requests + import os + import pygame + import time + import ssl + import random + ssl._create_default_https_context = ssl._create_unverified_context + html = urllib.request.urlopen("https://www.guanjihuan.com/archives/24732").read().decode('utf-8') + if bre_or_ame == 'ame': + directory = 'words_mp3_ameProns/' + elif bre_or_ame == 'bre': + directory = 'words_mp3_breProns/' + exist_directory = os.path.exists(directory) + html_file = urllib.request.urlopen("https://file.guanjihuan.com/words/"+directory).read().decode('utf-8') + if exist_directory == 0: + os.makedirs(directory) + soup = BeautifulSoup(html, features='lxml') + contents = re.findall('.*?
', content, re.S)[0][3:-4] + if show_translation==1: + time.sleep(translation_time) + print(translation) + time.sleep(rest_time) + pygame.mixer.music.stop() + print() + import guan + guan.statistics_of_guan_package() + +# Guan软件包的使用统计(不涉及到用户的个人数据) +global_variable_of_first_guan_package_calling = [] +def statistics_of_guan_package(): + import guan + function_name = guan.get_calling_function_name(layer=2) + global global_variable_of_first_guan_package_calling + if function_name not in global_variable_of_first_guan_package_calling: + global_variable_of_first_guan_package_calling.append(function_name) + function_calling_name = guan.get_calling_function_name(layer=3) + if function_calling_name == '