This commit is contained in:
guanjihuan 2023-12-13 00:30:08 +08:00
parent 0ea6a97c82
commit 150d169681
14 changed files with 241 additions and 301 deletions

View File

@ -1,7 +1,7 @@
[metadata]
# replace with your username:
name = guan
version = 0.1.62
version = 0.1.63
author = guanjihuan
author_email = guanjihuan@163.com
description = An open source python package

View File

@ -1,6 +1,6 @@
Metadata-Version: 2.1
Name: guan
Version: 0.1.62
Version: 0.1.63
Summary: An open source python package
Home-page: https://py.guanjihuan.com
Author: guanjihuan

View File

@ -2,7 +2,7 @@
import guan
# 通过元胞和跃迁项得到一维的哈密顿量需要输入k值
@guan.function_decorator
@guan.statistics_decorator
def one_dimensional_fourier_transform(k, unit_cell, hopping):
import numpy as np
import cmath
@ -12,7 +12,7 @@ def one_dimensional_fourier_transform(k, unit_cell, hopping):
return hamiltonian
# 通过元胞和跃迁项得到二维方格子的哈密顿量需要输入k值
@guan.function_decorator
@guan.statistics_decorator
def two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell, hopping_1, hopping_2):
import numpy as np
import cmath
@ -23,7 +23,7 @@ def two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell, hopp
return hamiltonian
# 通过元胞和跃迁项得到三维立方格子的哈密顿量需要输入k值
@guan.function_decorator
@guan.statistics_decorator
def three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell, hopping_1, hopping_2, hopping_3):
import numpy as np
import cmath
@ -35,7 +35,7 @@ def three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell,
return hamiltonian
# 通过元胞和跃迁项得到一维的哈密顿量返回的哈密顿量为携带k的函数
@guan.function_decorator
@guan.statistics_decorator
def one_dimensional_fourier_transform_with_k(unit_cell, hopping):
import functools
import guan
@ -43,7 +43,7 @@ def one_dimensional_fourier_transform_with_k(unit_cell, hopping):
return hamiltonian_function
# 通过元胞和跃迁项得到二维方格子的哈密顿量返回的哈密顿量为携带k的函数
@guan.function_decorator
@guan.statistics_decorator
def two_dimensional_fourier_transform_for_square_lattice_with_k1_k2(unit_cell, hopping_1, hopping_2):
import functools
import guan
@ -51,7 +51,7 @@ def two_dimensional_fourier_transform_for_square_lattice_with_k1_k2(unit_cell, h
return hamiltonian_function
# 通过元胞和跃迁项得到三维立方格子的哈密顿量返回的哈密顿量为携带k的函数
@guan.function_decorator
@guan.statistics_decorator
def three_dimensional_fourier_transform_for_cubic_lattice_with_k1_k2_k3(unit_cell, hopping_1, hopping_2, hopping_3):
import functools
import guan
@ -59,14 +59,14 @@ def three_dimensional_fourier_transform_for_cubic_lattice_with_k1_k2_k3(unit_cel
return hamiltonian_function
# 由实空间格矢得到倒空间格矢(一维)
@guan.function_decorator
@guan.statistics_decorator
def calculate_one_dimensional_reciprocal_lattice_vector(a1):
import numpy as np
b1 = 2*np.pi/a1
return b1
# 由实空间格矢得到倒空间格矢(二维)
@guan.function_decorator
@guan.statistics_decorator
def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2):
import numpy as np
a1 = np.array(a1)
@ -81,7 +81,7 @@ def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2):
return b1, b2
# 由实空间格矢得到倒空间格矢(三维)
@guan.function_decorator
@guan.statistics_decorator
def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3):
import numpy as np
a1 = np.array(a1)
@ -93,14 +93,14 @@ def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3):
return b1, b2, b3
# 由实空间格矢得到倒空间格矢(一维),这里为符号运算
@guan.function_decorator
@guan.statistics_decorator
def calculate_one_dimensional_reciprocal_lattice_vector_with_sympy(a1):
import sympy
b1 = 2*sympy.pi/a1
return b1
# 由实空间格矢得到倒空间格矢(二维),这里为符号运算
@guan.function_decorator
@guan.statistics_decorator
def calculate_two_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2):
import sympy
a1 = sympy.Matrix(1, 3, [a1[0], a1[1], 0])
@ -115,7 +115,7 @@ def calculate_two_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2):
return b1, b2
# 由实空间格矢得到倒空间格矢(三维),这里为符号运算
@guan.function_decorator
@guan.statistics_decorator
def calculate_three_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2, a3):
import sympy
cross_a2_a3 = a2.cross(a3)

View File

@ -2,7 +2,7 @@
import guan
# 输入哈密顿量,得到格林函数
@guan.function_decorator
@guan.statistics_decorator
def green_function(fermi_energy, hamiltonian, broadening, self_energy=0):
import numpy as np
if np.array(hamiltonian).shape==():
@ -13,7 +13,7 @@ def green_function(fermi_energy, hamiltonian, broadening, self_energy=0):
return green
# 在Dyson方程中的一个中间格林函数G_{nn}^{n}
@guan.function_decorator
@guan.statistics_decorator
def green_function_nn_n(fermi_energy, h00, h01, green_nn_n_minus, broadening, self_energy=0):
import numpy as np
h01 = np.array(h01)
@ -25,14 +25,14 @@ def green_function_nn_n(fermi_energy, h00, h01, green_nn_n_minus, broadening, se
return green_nn_n
# 在Dyson方程中的一个中间格林函数G_{in}^{n}
@guan.function_decorator
@guan.statistics_decorator
def green_function_in_n(green_in_n_minus, h01, green_nn_n):
import numpy as np
green_in_n = np.dot(np.dot(green_in_n_minus, h01), green_nn_n)
return green_in_n
# 在Dyson方程中的一个中间格林函数G_{ni}^{n}
@guan.function_decorator
@guan.statistics_decorator
def green_function_ni_n(green_nn_n, h01, green_ni_n_minus):
import numpy as np
h01 = np.array(h01)
@ -40,14 +40,14 @@ def green_function_ni_n(green_nn_n, h01, green_ni_n_minus):
return green_ni_n
# 在Dyson方程中的一个中间格林函数G_{ii}^{n}
@guan.function_decorator
@guan.statistics_decorator
def green_function_ii_n(green_ii_n_minus, green_in_n_minus, h01, green_nn_n, green_ni_n_minus):
import numpy as np
green_ii_n = green_ii_n_minus+np.dot(np.dot(np.dot(np.dot(green_in_n_minus, h01), green_nn_n), h01.transpose().conj()),green_ni_n_minus)
return green_ii_n
# 计算转移矩阵(该矩阵可以用来计算表面格林函数)
@guan.function_decorator
@guan.statistics_decorator
def transfer_matrix(fermi_energy, h00, h01):
import numpy as np
h01 = np.array(h01)
@ -63,7 +63,7 @@ def transfer_matrix(fermi_energy, h00, h01):
return transfer
# 计算电极的表面格林函数
@guan.function_decorator
@guan.statistics_decorator
def surface_green_function_of_lead(fermi_energy, h00, h01):
import numpy as np
h01 = np.array(h01)
@ -89,7 +89,7 @@ def surface_green_function_of_lead(fermi_energy, h00, h01):
return right_lead_surface, left_lead_surface
# 计算电极的自能基于Dyson方程的小矩阵形式
@guan.function_decorator
@guan.statistics_decorator
def self_energy_of_lead(fermi_energy, h00, h01):
import numpy as np
import guan
@ -102,7 +102,7 @@ def self_energy_of_lead(fermi_energy, h00, h01):
return right_self_energy, left_self_energy, gamma_right, gamma_left
# 计算电极的自能(基于中心区整体的大矩阵形式)
@guan.function_decorator
@guan.statistics_decorator
def self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR):
import numpy as np
import guan
@ -116,7 +116,7 @@ def self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR):
return right_self_energy, left_self_energy, gamma_right, gamma_left
# 计算电极的自能(基于中心区整体的大矩阵形式,可适用于多端电导的计算)
@guan.function_decorator
@guan.statistics_decorator
def self_energy_of_lead_with_h_lead_to_center(fermi_energy, h00, h01, h_lead_to_center):
import numpy as np
import guan
@ -127,7 +127,7 @@ def self_energy_of_lead_with_h_lead_to_center(fermi_energy, h00, h01, h_lead_to_
return self_energy, gamma
# 计算考虑电极自能后的中心区的格林函数
@guan.function_decorator
@guan.statistics_decorator
def green_function_with_leads(fermi_energy, h00, h01, h_LC, h_CR, center_hamiltonian):
import numpy as np
import guan
@ -137,7 +137,7 @@ def green_function_with_leads(fermi_energy, h00, h01, h_LC, h_CR, center_hamilto
return green, gamma_right, gamma_left
# 计算用于计算局域电流的格林函数G_n
@guan.function_decorator
@guan.statistics_decorator
def electron_correlation_function_green_n_for_local_current(fermi_energy, h00, h01, h_LC, h_CR, center_hamiltonian):
import numpy as np
import guan

View File

@ -2,7 +2,7 @@
import guan
# 构建一维的有限尺寸体系哈密顿量(可设置是否为周期边界条件)
@guan.function_decorator
@guan.statistics_decorator
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)
@ -23,7 +23,7 @@ def hamiltonian_of_finite_size_system_along_one_direction(N, on_site=0, hopping=
return hamiltonian
# 构建二维的方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
@guan.function_decorator
@guan.statistics_decorator
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)
@ -56,7 +56,7 @@ def hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1
return hamiltonian
# 构建三维的立方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
@guan.function_decorator
@guan.statistics_decorator
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)
@ -105,7 +105,7 @@ def hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(N
return hamiltonian
# 构建有限尺寸的SSH模型哈密顿量
@guan.function_decorator
@guan.statistics_decorator
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))
@ -123,7 +123,7 @@ def hamiltonian_of_finite_size_ssh_model(N, v=0.6, w=1, onsite_1=0, onsite_2=0,
return hamiltonian
# 获取Zigzag边的石墨烯条带的元胞间跃迁
@guan.function_decorator
@guan.statistics_decorator
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)
@ -137,7 +137,7 @@ def get_hopping_term_of_graphene_ribbon_along_zigzag_direction(N, eta=0):
return hopping
# 构建有限尺寸的石墨烯哈密顿量(可设置是否为周期边界条件)
@guan.function_decorator
@guan.statistics_decorator
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
@ -149,7 +149,7 @@ def hamiltonian_of_finite_size_system_along_two_directions_for_graphene(N1, N2,
return hamiltonian
# 获取石墨烯有效模型沿着x方向的在位能和跃迁项其中动量qy为参数
@guan.function_decorator
@guan.statistics_decorator
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
@ -170,7 +170,7 @@ def get_onsite_and_hopping_terms_of_2d_effective_graphene_along_one_direction(qy
return h00, h01
# 获取BHZ模型的在位能和跃迁项
@guan.function_decorator
@guan.statistics_decorator
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)
@ -204,7 +204,7 @@ def get_onsite_and_hopping_terms_of_bhz_model(A=0.3645/5, B=-0.686/25, C=0, D=-0
return H0, H1, H2
# 获取半个BHZ模型的在位能和跃迁项自旋向上
@guan.function_decorator
@guan.statistics_decorator
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)
@ -228,7 +228,7 @@ def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_up(A=0.3645/5, B=-0.
return H0, H1, H2
# 获取半个BHZ模型的在位能和跃迁项自旋向下
@guan.function_decorator
@guan.statistics_decorator
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)
@ -252,21 +252,21 @@ def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_down(A=0.3645/5, B=-
return H0, H1, H2
# 一维链的哈密顿量(倒空间)
@guan.function_decorator
@guan.statistics_decorator
def hamiltonian_of_simple_chain(k):
import guan
hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=0, hopping=1)
return hamiltonian
# 二维方格子的哈密顿量(倒空间)
@guan.function_decorator
@guan.statistics_decorator
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)
return hamiltonian
# 准一维方格子条带的哈密顿量(倒空间)
@guan.function_decorator
@guan.statistics_decorator
def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0):
import numpy as np
import guan
@ -284,14 +284,14 @@ def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0):
return hamiltonian
# 三维立方格子的哈密顿量(倒空间)
@guan.function_decorator
@guan.statistics_decorator
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)
return hamiltonian
# SSH模型的哈密顿量倒空间
@guan.function_decorator
@guan.statistics_decorator
def hamiltonian_of_ssh_model(k, v=0.6, w=1):
import numpy as np
import cmath
@ -301,7 +301,7 @@ def hamiltonian_of_ssh_model(k, v=0.6, w=1):
return hamiltonian
# 石墨烯的哈密顿量(倒空间)
@guan.function_decorator
@guan.statistics_decorator
def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'):
import numpy as np
import cmath
@ -318,7 +318,7 @@ def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'):
return hamiltonian
# 石墨烯有效模型的哈密顿量(倒空间)
@guan.function_decorator
@guan.statistics_decorator
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)
@ -334,7 +334,7 @@ def effective_hamiltonian_of_graphene(qx, qy, t=1, staggered_potential=0, valley
return hamiltonian
# 石墨烯有效模型离散化后的哈密顿量(倒空间)
@guan.function_decorator
@guan.statistics_decorator
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)
@ -350,7 +350,7 @@ def effective_hamiltonian_of_graphene_after_discretization(qx, qy, t=1, staggere
return hamiltonian
# 准一维Zigzag边石墨烯条带的哈密顿量倒空间
@guan.function_decorator
@guan.statistics_decorator
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
@ -380,7 +380,7 @@ def hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension(k, N=10, M=0, t=1
return hamiltonian
# Haldane模型的哈密顿量倒空间
@guan.function_decorator
@guan.statistics_decorator
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
@ -402,7 +402,7 @@ def hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi='default', a='
return hamiltonian
# 准一维Haldane模型条带的哈密顿量倒空间
@guan.function_decorator
@guan.statistics_decorator
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
@ -457,7 +457,7 @@ def hamiltonian_of_haldane_model_in_quasi_one_dimension(k, N=10, M=2/3, t1=1, t2
return hamiltonian
# 一个量子反常霍尔效应的哈密顿量(倒空间)
@guan.function_decorator
@guan.statistics_decorator
def hamiltonian_of_one_QAH_model(k1, k2, t1=1, t2=1, t3=0.5, m=-1):
import numpy as np
import math
@ -469,7 +469,7 @@ def hamiltonian_of_one_QAH_model(k1, k2, t1=1, t2=1, t3=0.5, m=-1):
return hamiltonian
# BHZ模型的哈密顿量倒空间
@guan.function_decorator
@guan.statistics_decorator
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
@ -488,7 +488,7 @@ def hamiltonian_of_bhz_model(kx, ky, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25,
return hamiltonian
# 半BHZ模型的哈密顿量自旋向上倒空间
@guan.function_decorator
@guan.statistics_decorator
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
@ -503,7 +503,7 @@ def hamiltonian_of_half_bhz_model_for_spin_up(kx, ky, A=0.3645/5, B=-0.686/25, C
return hamiltonian
# 半BHZ模型的哈密顿量自旋向下倒空间
@guan.function_decorator
@guan.statistics_decorator
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
@ -518,7 +518,7 @@ def hamiltonian_of_half_bhz_model_for_spin_down(kx, ky, A=0.3645/5, B=-0.686/25,
return hamiltonian
# BBH模型的哈密顿量倒空间
@guan.function_decorator
@guan.statistics_decorator
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
@ -538,7 +538,7 @@ def hamiltonian_of_bbh_model(kx, ky, gamma_x=0.5, gamma_y=0.5, lambda_x=1, lambd
return hamiltonian
# Kagome模型的哈密顿量倒空间
@guan.function_decorator
@guan.statistics_decorator
def hamiltonian_of_kagome_lattice(kx, ky, t=1):
import numpy as np
import math

View File

@ -1,7 +1,23 @@
# Guan is an open-source python package developed and maintained by https://www.guanjihuan.com/about (Ji-Huan Guan, 关济寰). The primary location of this package is on website https://py.guanjihuan.com. The GitHub location of this package is on https://github.com/guanjihuan/py.guanjihuan.com.
# 函数的装饰器,用于软件包的统计
def function_decorator(func):
# 函数的装饰器,用于获取计算时间
def timer_decorator(func, time_type=0):
import time
def wrapper(*args, **kwargs):
start = time.time()
result = func(*args, **kwargs)
end = time.time()
if time_type == 0:
print(f"Running time of {func.__name__}: {end - start} seconds")
elif time_type == 1:
print(f"Running time of {func.__name__}: {(end - start)/60} minutes")
elif time_type == 2:
print(f"Running time of {func.__name__}: {(end - start)/3600} hours")
return result
return wrapper
# 函数的装饰器用于GUAN软件包的统计
def statistics_decorator(func):
def wrapper(*args, **kwargs):
result = func(*args, **kwargs)
import guan

View File

@ -2,7 +2,7 @@
import guan
# 计算哈密顿量的本征值
@guan.function_decorator
@guan.statistics_decorator
def calculate_eigenvalue(hamiltonian):
import numpy as np
if np.array(hamiltonian).shape==():
@ -12,7 +12,7 @@ def calculate_eigenvalue(hamiltonian):
return eigenvalue
# 输入哈密顿量函数(带一组参数),计算一组参数下的本征值,返回本征值向量组
@guan.function_decorator
@guan.statistics_decorator
def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function, print_show=0):
import numpy as np
dim_x = np.array(x_array).shape[0]
@ -36,7 +36,7 @@ def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function, print
return eigenvalue_array
# 输入哈密顿量函数(带两组参数),计算两组参数下的本征值,返回本征值向量组
@guan.function_decorator
@guan.statistics_decorator
def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function, print_show=0, print_show_more=0):
import numpy as np
dim_x = np.array(x_array).shape[0]
@ -70,14 +70,14 @@ def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_funct
return eigenvalue_array
# 计算哈密顿量的本征矢
@guan.function_decorator
@guan.statistics_decorator
def calculate_eigenvector(hamiltonian):
import numpy as np
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
return eigenvector
# 通过二分查找的方法获取和相邻波函数一样规范的波函数
@guan.function_decorator
@guan.statistics_decorator
def find_vector_with_the_same_gauge_with_binary_search(vector_target, vector_ref, show_error=1, show_times=0, show_phase=0, n_test=1000, precision=1e-6):
import numpy as np
import cmath
@ -117,7 +117,7 @@ def find_vector_with_the_same_gauge_with_binary_search(vector_target, vector_ref
return vector_target
# 通过使得波函数的一个非零分量为实数,得到固定规范的波函数
@guan.function_decorator
@guan.statistics_decorator
def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None):
import numpy as np
import cmath
@ -136,7 +136,7 @@ def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=
return vector
# 通过使得波函数的一个非零分量为实数,得到固定规范的波函数(在一组波函数中选取最大的那个分量)
@guan.function_decorator
@guan.statistics_decorator
def find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array, precision=0.005):
import numpy as np
import guan
@ -150,7 +150,7 @@ def find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array
return vector_array
# 旋转两个简并的波函数(说明:参数比较多,算法效率不高)
@guan.function_decorator
@guan.statistics_decorator
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
@ -180,7 +180,7 @@ def rotation_of_degenerate_vectors(vector1, vector2, index1=None, index2=None, p
return vector1, vector2
# 旋转两个简并的波函数向量组(说明:参数比较多,算法效率不高)
@guan.function_decorator
@guan.statistics_decorator
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
@ -198,7 +198,7 @@ def rotation_of_degenerate_vectors_array(vector1_array, vector2_array, precision
return vector1_array, vector2_array
# 在一组数据中找到数值相近的数
@guan.function_decorator
@guan.statistics_decorator
def find_close_values_in_one_array(array, precision=1e-2):
new_array = []
i0 = 0
@ -212,7 +212,7 @@ def find_close_values_in_one_array(array, precision=1e-2):
return new_array
# 寻找能带的简并点
@guan.function_decorator
@guan.statistics_decorator
def find_degenerate_points(k_array, eigenvalue_array, precision=1e-2):
import guan
degenerate_k_array = []

View File

@ -2,7 +2,7 @@
import guan
# 测试
@guan.function_decorator
@guan.statistics_decorator
def test():
import guan
current_version = guan.get_current_version('guan')
@ -13,118 +13,118 @@ def test():
print('\nTest completed.\n')
# 泡利矩阵
@guan.function_decorator
@guan.statistics_decorator
def sigma_0():
import numpy as np
return np.eye(2)
@guan.function_decorator
@guan.statistics_decorator
def sigma_x():
import numpy as np
return np.array([[0, 1],[1, 0]])
@guan.function_decorator
@guan.statistics_decorator
def sigma_y():
import numpy as np
return np.array([[0, -1j],[1j, 0]])
@guan.function_decorator
@guan.statistics_decorator
def sigma_z():
import numpy as np
return np.array([[1, 0],[0, -1]])
# 泡利矩阵的张量积
@guan.function_decorator
@guan.statistics_decorator
def sigma_00():
import numpy as np
import guan
return np.kron(guan.sigma_0(), guan.sigma_0())
@guan.function_decorator
@guan.statistics_decorator
def sigma_0x():
import numpy as np
import guan
return np.kron(guan.sigma_0(), guan.sigma_x())
@guan.function_decorator
@guan.statistics_decorator
def sigma_0y():
import numpy as np
import guan
return np.kron(guan.sigma_0(), guan.sigma_y())
@guan.function_decorator
@guan.statistics_decorator
def sigma_0z():
import numpy as np
import guan
return np.kron(guan.sigma_0(), guan.sigma_z())
@guan.function_decorator
@guan.statistics_decorator
def sigma_x0():
import numpy as np
import guan
return np.kron(guan.sigma_x(), guan.sigma_0())
@guan.function_decorator
@guan.statistics_decorator
def sigma_xx():
import numpy as np
import guan
return np.kron(guan.sigma_x(), guan.sigma_x())
@guan.function_decorator
@guan.statistics_decorator
def sigma_xy():
import numpy as np
import guan
return np.kron(guan.sigma_x(), guan.sigma_y())
@guan.function_decorator
@guan.statistics_decorator
def sigma_xz():
import numpy as np
import guan
return np.kron(guan.sigma_x(), guan.sigma_z())
@guan.function_decorator
@guan.statistics_decorator
def sigma_y0():
import numpy as np
import guan
return np.kron(guan.sigma_y(), guan.sigma_0())
@guan.function_decorator
@guan.statistics_decorator
def sigma_yx():
import numpy as np
import guan
return np.kron(guan.sigma_y(), guan.sigma_x())
@guan.function_decorator
@guan.statistics_decorator
def sigma_yy():
import numpy as np
import guan
return np.kron(guan.sigma_y(), guan.sigma_y())
@guan.function_decorator
@guan.statistics_decorator
def sigma_yz():
import numpy as np
import guan
return np.kron(guan.sigma_y(), guan.sigma_z())
@guan.function_decorator
@guan.statistics_decorator
def sigma_z0():
import numpy as np
import guan
return np.kron(guan.sigma_z(), guan.sigma_0())
@guan.function_decorator
@guan.statistics_decorator
def sigma_zx():
import numpy as np
import guan
return np.kron(guan.sigma_z(), guan.sigma_x())
@guan.function_decorator
@guan.statistics_decorator
def sigma_zy():
import numpy as np
import guan
return np.kron(guan.sigma_z(), guan.sigma_y())
@guan.function_decorator
@guan.statistics_decorator
def sigma_zz():
import numpy as np
import guan

View File

@ -2,7 +2,7 @@
import guan
# 导入plt, fig, ax
@guan.function_decorator
@guan.statistics_decorator
def import_plt_and_start_fig_ax(adjust_bottom=0.2, adjust_left=0.2, labelsize=20):
import matplotlib.pyplot as plt
fig, ax = plt.subplots()
@ -14,7 +14,7 @@ def import_plt_and_start_fig_ax(adjust_bottom=0.2, adjust_left=0.2, labelsize=20
return plt, fig, ax
# 基于plt, fig, ax画图
@guan.function_decorator
@guan.statistics_decorator
def plot_without_starting_fig(plt, fig, ax, x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, style='', y_min=None, y_max=None, linewidth=None, markersize=None, color=None):
if color==None:
ax.plot(x_array, y_array, style, linewidth=linewidth, markersize=markersize)
@ -31,7 +31,7 @@ def plot_without_starting_fig(plt, fig, ax, x_array, y_array, xlabel='x', ylabel
ax.set_ylim(y_min, y_max)
# 画图
@guan.function_decorator
@guan.statistics_decorator
def plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', file_format='.jpg', dpi=300, style='', y_min=None, y_max=None, linewidth=None, markersize=None, adjust_bottom=0.2, adjust_left=0.2):
import guan
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
@ -52,7 +52,7 @@ def plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labels
plt.close('all')
# 一组横坐标数据,两组纵坐标数据画图
@guan.function_decorator
@guan.statistics_decorator
def plot_two_array(x_array, y1_array, y2_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', file_format='.jpg', dpi=300, style_1='', style_2='', y_min=None, y_max=None, linewidth_1=None, linewidth_2=None, markersize_1=None, markersize_2=None, adjust_bottom=0.2, adjust_left=0.2):
import guan
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
@ -78,7 +78,7 @@ def plot_two_array(x_array, y1_array, y2_array, xlabel='x', ylabel='y', title=''
plt.close('all')
# 两组横坐标数据,两组纵坐标数据画图
@guan.function_decorator
@guan.statistics_decorator
def plot_two_array_with_two_horizontal_array(x1_array, x2_array, y1_array, y2_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', file_format='.jpg', dpi=300, style_1='', style_2='', y_min=None, y_max=None, linewidth_1=None, linewidth_2=None, markersize_1=None, markersize_2=None, adjust_bottom=0.2, adjust_left=0.2):
import guan
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
@ -104,7 +104,7 @@ def plot_two_array_with_two_horizontal_array(x1_array, x2_array, y1_array, y2_ar
plt.close('all')
# 一组横坐标数据,三组纵坐标数据画图
@guan.function_decorator
@guan.statistics_decorator
def plot_three_array(x_array, y1_array, y2_array, y3_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', file_format='.jpg', dpi=300, style_1='', style_2='', style_3='', y_min=None, y_max=None, linewidth_1=None, linewidth_2=None, linewidth_3=None,markersize_1=None, markersize_2=None, markersize_3=None, adjust_bottom=0.2, adjust_left=0.2):
import guan
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
@ -133,7 +133,7 @@ def plot_three_array(x_array, y1_array, y2_array, y3_array, xlabel='x', ylabel='
plt.close('all')
# 三组横坐标数据,三组纵坐标数据画图
@guan.function_decorator
@guan.statistics_decorator
def plot_three_array_with_three_horizontal_array(x1_array, x2_array, x3_array, y1_array, y2_array, y3_array, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=20, show=1, save=0, filename='a', file_format='.jpg', dpi=300, style_1='', style_2='', style_3='', y_min=None, y_max=None, linewidth_1=None, linewidth_2=None, linewidth_3=None,markersize_1=None, markersize_2=None, markersize_3=None, adjust_bottom=0.2, adjust_left=0.2):
import guan
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
@ -162,7 +162,7 @@ def plot_three_array_with_three_horizontal_array(x1_array, x2_array, x3_array, y
plt.close('all')
# 画三维图
@guan.function_decorator
@guan.statistics_decorator
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 numpy as np
import matplotlib.pyplot as plt
@ -204,7 +204,7 @@ def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z'
plt.close('all')
# 画Contour图
@guan.function_decorator
@guan.statistics_decorator
def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=15, cmap='jet', levels=None, show=1, save=0, filename='a', file_format='.jpg', dpi=300):
import numpy as np
import matplotlib.pyplot as plt
@ -230,7 +230,7 @@ def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', fon
plt.close('all')
# 画棋盘图/伪彩色图
@guan.function_decorator
@guan.statistics_decorator
def plot_pcolor(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', fontsize=20, labelsize=15, cmap='jet', levels=None, show=1, save=0, filename='a', file_format='.jpg', dpi=300):
import numpy as np
import matplotlib.pyplot as plt
@ -256,7 +256,7 @@ def plot_pcolor(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', font
plt.close('all')
# 通过坐标画点和线
@guan.function_decorator
@guan.statistics_decorator
def draw_dots_and_lines(coordinate_array, draw_dots=1, draw_lines=1, max_distance=1.1, line_style='-k', linewidth=1, dot_style='ro', markersize=3, show=1, save=0, filename='a', file_format='.eps', dpi=300):
import numpy as np
import matplotlib.pyplot as plt
@ -284,7 +284,7 @@ def draw_dots_and_lines(coordinate_array, draw_dots=1, draw_lines=1, max_distanc
plt.savefig(filename+file_format, dpi=dpi)
# 合并两个图片
@guan.function_decorator
@guan.statistics_decorator
def combine_two_images(image_path_array, figsize=(16,8), show=0, save=1, filename='a', file_format='.jpg', dpi=300):
import numpy as np
num = np.array(image_path_array).shape[0]
@ -310,7 +310,7 @@ def combine_two_images(image_path_array, figsize=(16,8), show=0, save=1, filenam
plt.close('all')
# 合并三个图片
@guan.function_decorator
@guan.statistics_decorator
def combine_three_images(image_path_array, figsize=(16,5), show=0, save=1, filename='a', file_format='.jpg', dpi=300):
import numpy as np
num = np.array(image_path_array).shape[0]
@ -340,7 +340,7 @@ def combine_three_images(image_path_array, figsize=(16,5), show=0, save=1, filen
plt.close('all')
# 合并四个图片
@guan.function_decorator
@guan.statistics_decorator
def combine_four_images(image_path_array, figsize=(16,16), show=0, save=1, filename='a', file_format='.jpg', dpi=300):
import numpy as np
num = np.array(image_path_array).shape[0]
@ -374,7 +374,7 @@ def combine_four_images(image_path_array, figsize=(16,16), show=0, save=1, filen
plt.close('all')
# 对某个目录中的txt文件批量读取和画图
@guan.function_decorator
@guan.statistics_decorator
def batch_reading_and_plotting(directory, xlabel='x', ylabel='y'):
import re
import os
@ -387,7 +387,7 @@ def batch_reading_and_plotting(directory, xlabel='x', ylabel='y'):
guan.plot(x_array, y_array, xlabel=xlabel, ylabel=ylabel, title=filename, show=0, save=1, filename=filename)
# 将图片制作GIF动画
@guan.function_decorator
@guan.statistics_decorator
def make_gif(image_path_array, filename='a', duration=0.1):
import imageio
images = []
@ -397,20 +397,20 @@ def make_gif(image_path_array, filename='a', duration=0.1):
imageio.mimsave(filename+'.gif', images, 'GIF', duration=duration)
# 选取Matplotlib颜色
@guan.function_decorator
@guan.statistics_decorator
def color_matplotlib():
color_array = ['tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan']
return color_array
# 将变量存到文件
@guan.function_decorator
@guan.statistics_decorator
def dump_data(data, filename, file_format='.txt'):
import pickle
with open(filename+file_format, 'wb') as f:
pickle.dump(data, f)
# 从文件中恢复数据到变量
@guan.function_decorator
@guan.statistics_decorator
def load_data(filename, file_format='.txt'):
import pickle
with open(filename+file_format, 'rb') as f:
@ -418,7 +418,7 @@ def load_data(filename, file_format='.txt'):
return data
# 读取文件中的一维数据一行一组x和y
@guan.function_decorator
@guan.statistics_decorator
def read_one_dimensional_data(filename='a', file_format='.txt'):
import numpy as np
f = open(filename+file_format, 'r')
@ -442,7 +442,7 @@ def read_one_dimensional_data(filename='a', file_format='.txt'):
return x_array, y_array
# 读取文件中的一维数据一行一组x和y支持复数形式
@guan.function_decorator
@guan.statistics_decorator
def read_one_dimensional_complex_data(filename='a', file_format='.txt'):
import numpy as np
f = open(filename+file_format, 'r')
@ -466,7 +466,7 @@ def read_one_dimensional_complex_data(filename='a', file_format='.txt'):
return x_array, y_array
# 读取文件中的二维数据(第一行和第一列分别为横纵坐标)
@guan.function_decorator
@guan.statistics_decorator
def read_two_dimensional_data(filename='a', file_format='.txt'):
import numpy as np
f = open(filename+file_format, 'r')
@ -496,7 +496,7 @@ def read_two_dimensional_data(filename='a', file_format='.txt'):
return x_array, y_array, matrix
# 读取文件中的二维数据(第一行和第一列分别为横纵坐标)(支持复数形式)
@guan.function_decorator
@guan.statistics_decorator
def read_two_dimensional_complex_data(filename='a', file_format='.txt'):
import numpy as np
f = open(filename+file_format, 'r')
@ -526,27 +526,27 @@ def read_two_dimensional_complex_data(filename='a', file_format='.txt'):
return x_array, y_array, matrix
# 读取文件中的二维数据不包括x和y
@guan.function_decorator
@guan.statistics_decorator
def read_two_dimensional_data_without_xy_array(filename='a', file_format='.txt'):
import numpy as np
matrix = np.loadtxt(filename+file_format)
return matrix
# 打开文件用于新增内容
@guan.function_decorator
@guan.statistics_decorator
def open_file(filename='a', file_format='.txt'):
f = open(filename+file_format, 'a', encoding='UTF-8')
return f
# 在文件中写入一维数据一行一组x和y
@guan.function_decorator
@guan.statistics_decorator
def write_one_dimensional_data(x_array, y_array, filename='a', file_format='.txt'):
import guan
with open(filename+file_format, 'w', encoding='UTF-8') as f:
guan.write_one_dimensional_data_without_opening_file(x_array, y_array, f)
# 在文件中写入一维数据一行一组x和y需要输入已打开的文件
@guan.function_decorator
@guan.statistics_decorator
def write_one_dimensional_data_without_opening_file(x_array, y_array, f):
import numpy as np
x_array = np.array(x_array)
@ -563,14 +563,14 @@ def write_one_dimensional_data_without_opening_file(x_array, y_array, f):
i0 += 1
# 在文件中写入二维数据(第一行和第一列分别为横纵坐标)
@guan.function_decorator
@guan.statistics_decorator
def write_two_dimensional_data(x_array, y_array, matrix, filename='a', file_format='.txt'):
import guan
with open(filename+file_format, 'w', encoding='UTF-8') as f:
guan.write_two_dimensional_data_without_opening_file(x_array, y_array, matrix, f)
# 在文件中写入二维数据(第一行和第一列分别为横纵坐标)(需要输入已打开的文件)
@guan.function_decorator
@guan.statistics_decorator
def write_two_dimensional_data_without_opening_file(x_array, y_array, matrix, f):
import numpy as np
x_array = np.array(x_array)
@ -591,14 +591,14 @@ def write_two_dimensional_data_without_opening_file(x_array, y_array, matrix, f)
i0 += 1
# 在文件中写入二维数据不包括x和y
@guan.function_decorator
@guan.statistics_decorator
def write_two_dimensional_data_without_xy_array(matrix, filename='a', file_format='.txt'):
import guan
with open(filename+file_format, 'w', encoding='UTF-8') as f:
guan.write_two_dimensional_data_without_xy_array_and_without_opening_file(matrix, f)
# 在文件中写入二维数据不包括x和y需要输入已打开的文件
@guan.function_decorator
@guan.statistics_decorator
def write_two_dimensional_data_without_xy_array_and_without_opening_file(matrix, f):
for row in matrix:
for element in row:
@ -607,7 +607,7 @@ def write_two_dimensional_data_without_xy_array_and_without_opening_file(matrix,
import guan
# 以显示编号的样式,打印数组
@guan.function_decorator
@guan.statistics_decorator
def print_array_with_index(array, show_index=1, index_type=0):
if show_index==0:
for i0 in array:
@ -625,7 +625,7 @@ def print_array_with_index(array, show_index=1, index_type=0):
print(index, i0)
# 获取目录中的所有文件名
@guan.function_decorator
@guan.statistics_decorator
def get_all_filenames_in_directory(directory='./', file_format=None):
import os
file_list = []
@ -639,7 +639,7 @@ def get_all_filenames_in_directory(directory='./', file_format=None):
return file_list
# 读取文件夹中某种文本类型的文件路径和内容
@guan.function_decorator
@guan.statistics_decorator
def read_text_files_in_directory(directory='./', file_format='.md'):
import os
file_list = []
@ -654,7 +654,7 @@ def read_text_files_in_directory(directory='./', file_format='.md'):
return file_list, content_array
# 在多个文本文件中查找关键词
@guan.function_decorator
@guan.statistics_decorator
def find_words_in_multiple_files(words, directory='./', file_format='.md'):
import guan
file_list, content_array = guan.read_text_files_in_directory(directory=directory, file_format=file_format)
@ -666,7 +666,7 @@ def find_words_in_multiple_files(words, directory='./', file_format='.md'):
return file_list_with_words
# 并行计算前的预处理,把参数分成多份
@guan.function_decorator
@guan.statistics_decorator
def preprocess_for_parallel_calculations(parameter_array_all, cpus=1, task_index=0):
import numpy as np
num_all = np.array(parameter_array_all).shape[0]
@ -682,14 +682,14 @@ def preprocess_for_parallel_calculations(parameter_array_all, cpus=1, task_index
return parameter_array
# 随机获得一个整数,左闭右闭
@guan.function_decorator
@guan.statistics_decorator
def get_random_number(start=0, end=1):
import random
rand_number = random.randint(start, end) # 左闭右闭 [start, end]
return rand_number
# 选取一个种子生成固定的随机整数
@guan.function_decorator
@guan.statistics_decorator
def generate_random_int_number_for_a_specific_seed(seed=0, x_min=0, x_max=10):
import numpy as np
np.random.seed(seed)
@ -697,14 +697,14 @@ def generate_random_int_number_for_a_specific_seed(seed=0, x_min=0, x_max=10):
return rand_num
# 使用jieba软件包进行分词
@guan.function_decorator
@guan.statistics_decorator
def divide_text_into_words(text):
import jieba
words = jieba.lcut(text)
return words
# 判断某个字符是中文还是英文或其他
@guan.function_decorator
@guan.statistics_decorator
def check_Chinese_or_English(a):
if '\u4e00' <= a <= '\u9fff' :
word_type = 'Chinese'
@ -715,7 +715,7 @@ def check_Chinese_or_English(a):
return word_type
# 统计中英文文本的字数,默认不包括空格
@guan.function_decorator
@guan.statistics_decorator
def count_words(text, include_space=0, show_words=0):
import jieba
import guan
@ -743,7 +743,7 @@ def count_words(text, include_space=0, show_words=0):
return num_words
# 将RGB转成HEX
@guan.function_decorator
@guan.statistics_decorator
def rgb_to_hex(rgb, pound=1):
if pound==0:
return '%02x%02x%02x' % rgb
@ -751,14 +751,14 @@ def rgb_to_hex(rgb, pound=1):
return '#%02x%02x%02x' % rgb
# 将HEX转成RGB
@guan.function_decorator
@guan.statistics_decorator
def hex_to_rgb(hex):
hex = hex.lstrip('#')
length = len(hex)
return tuple(int(hex[i:i+length//3], 16) for i in range(0, length, length//3))
# 使用MD5进行散列加密
@guan.function_decorator
@guan.statistics_decorator
def encryption_MD5(password, salt=''):
import hashlib
password = salt+password
@ -766,7 +766,7 @@ def encryption_MD5(password, salt=''):
return hashed_password
# 使用SHA-256进行散列加密
@guan.function_decorator
@guan.statistics_decorator
def encryption_SHA_256(password, salt=''):
import hashlib
password = salt+password
@ -774,7 +774,7 @@ def encryption_SHA_256(password, salt=''):
return hashed_password
# 自动先后运行程序
@guan.function_decorator
@guan.statistics_decorator
def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='python ', show_time=0):
import os
import time
@ -794,20 +794,20 @@ def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='pytho
print('Total running time = '+str((end-start)/60)+' min')
# 如果不存在文件夹,则新建文件夹
@guan.function_decorator
@guan.statistics_decorator
def make_directory(directory='./test'):
import os
if not os.path.exists(directory):
os.makedirs(directory)
# 复制一份文件
@guan.function_decorator
@guan.statistics_decorator
def copy_file(file1='./a.txt', file2='./b.txt'):
import shutil
shutil.copy(file1, file2)
# 拼接两个PDF文件
@guan.function_decorator
@guan.statistics_decorator
def combine_two_pdf_files(input_file_1='a.pdf', input_file_2='b.pdf', output_file='combined_file.pdf'):
import PyPDF2
output_pdf = PyPDF2.PdfWriter()

View File

@ -2,7 +2,7 @@
import guan
# 计算体系的总态密度
@guan.function_decorator
@guan.statistics_decorator
def total_density_of_states(fermi_energy, hamiltonian, broadening=0.01):
import numpy as np
import math
@ -12,7 +12,7 @@ def total_density_of_states(fermi_energy, hamiltonian, broadening=0.01):
return total_dos
# 对于不同费米能,计算体系的总态密度
@guan.function_decorator
@guan.statistics_decorator
def total_density_of_states_with_fermi_energy_array(fermi_energy_array, hamiltonian, broadening=0.01, print_show=0):
import numpy as np
import guan
@ -27,7 +27,7 @@ def total_density_of_states_with_fermi_energy_array(fermi_energy_array, hamilton
return total_dos_array
# 计算方格子的局域态密度其中哈密顿量的维度为dim_hamiltonian = N1*N2*internal_degree
@guan.function_decorator
@guan.statistics_decorator
def local_density_of_states_for_square_lattice(fermi_energy, hamiltonian, N1, N2, internal_degree=1, broadening=0.01):
import numpy as np
import math
@ -41,7 +41,7 @@ def local_density_of_states_for_square_lattice(fermi_energy, hamiltonian, N1, N2
return local_dos
# 计算立方格子的局域态密度其中哈密顿量的维度为dim_hamiltonian = N1*N2*N3*internal_degree
@guan.function_decorator
@guan.statistics_decorator
def local_density_of_states_for_cubic_lattice(fermi_energy, hamiltonian, N1, N2, N3, internal_degree=1, broadening=0.01):
import numpy as np
import math
@ -56,7 +56,7 @@ def local_density_of_states_for_cubic_lattice(fermi_energy, hamiltonian, N1, N2,
return local_dos
# 利用Dyson方程计算方格子的局域态密度其中h00的维度为dim_h00 = N2*internal_degree
@guan.function_decorator
@guan.statistics_decorator
def local_density_of_states_for_square_lattice_using_dyson_equation(fermi_energy, h00, h01, N2, N1, internal_degree=1, broadening=0.01):
import numpy as np
import math
@ -90,7 +90,7 @@ def local_density_of_states_for_square_lattice_using_dyson_equation(fermi_energy
return local_dos
# 利用Dyson方程计算立方格子的局域态密度其中h00的维度为dim_h00 = N2*N3*internal_degree
@guan.function_decorator
@guan.statistics_decorator
def local_density_of_states_for_cubic_lattice_using_dyson_equation(fermi_energy, h00, h01, N3, N2, N1, internal_degree=1, broadening=0.01):
import numpy as np
import math
@ -125,7 +125,7 @@ def local_density_of_states_for_cubic_lattice_using_dyson_equation(fermi_energy,
return local_dos
# 利用Dyson方程计算方格子条带考虑了电极自能的局域态密度其中h00的维度为dim_h00 = N2*internal_degree
@guan.function_decorator
@guan.statistics_decorator
def local_density_of_states_for_square_lattice_with_self_energy_using_dyson_equation(fermi_energy, h00, h01, N2, N1, right_self_energy, left_self_energy, internal_degree=1, broadening=0.01):
import numpy as np
import math

View File

@ -2,7 +2,7 @@
import guan
# 全连接神经网络模型(包含一个隐藏层)(模型的类定义成全局的)
@guan.function_decorator
@guan.statistics_decorator
def fully_connected_neural_network_with_one_hidden_layer(input_size=1, hidden_size=10, output_size=1, activation='relu'):
import torch
global model_class_of_fully_connected_neural_network_with_one_hidden_layer
@ -28,7 +28,7 @@ def fully_connected_neural_network_with_one_hidden_layer(input_size=1, hidden_si
return model
# 全连接神经网络模型(包含两个隐藏层)(模型的类定义成全局的)
@guan.function_decorator
@guan.statistics_decorator
def fully_connected_neural_network_with_two_hidden_layers(input_size=1, hidden_size_1=10, hidden_size_2=10, output_size=1, activation_1='relu', activation_2='relu'):
import torch
global model_class_of_fully_connected_neural_network_with_two_hidden_layers
@ -67,7 +67,7 @@ def fully_connected_neural_network_with_two_hidden_layers(input_size=1, hidden_s
return model
# 全连接神经网络模型(包含三个隐藏层)(模型的类定义成全局的)
@guan.function_decorator
@guan.statistics_decorator
def fully_connected_neural_network_with_three_hidden_layers(input_size=1, hidden_size_1=10, hidden_size_2=10, hidden_size_3=10, output_size=1, activation_1='relu', activation_2='relu', activation_3='relu'):
import torch
global model_class_of_fully_connected_neural_network_with_three_hidden_layers
@ -118,7 +118,7 @@ def fully_connected_neural_network_with_three_hidden_layers(input_size=1, hidden
return model
# 使用优化器训练模型
@guan.function_decorator
@guan.statistics_decorator
def train_model(model, x_data, y_data, optimizer='Adam', learning_rate=0.001, criterion='MSELoss', num_epochs=1000, print_show=1):
import torch
if optimizer == 'Adam':
@ -145,26 +145,26 @@ def train_model(model, x_data, y_data, optimizer='Adam', learning_rate=0.001, cr
return model, losses
# 保存模型参数到文件
@guan.function_decorator
@guan.statistics_decorator
def save_model_parameters(model, filename='./model_parameters.pth'):
import torch
torch.save(model.state_dict(), filename)
# 保存完整模型到文件(保存时需要模型的类可访问)
@guan.function_decorator
@guan.statistics_decorator
def save_model(model, filename='./model.pth'):
import torch
torch.save(model, filename)
# 加载模型参数(需要输入模型,加载后,原输入的模型参数也会改变)
@guan.function_decorator
@guan.statistics_decorator
def load_model_parameters(model, filename='./model_parameters.pth'):
import torch
model.load_state_dict(torch.load(filename))
return model
# 加载完整模型(不需要输入模型,但加载时需要原定义的模型的类可访问)
@guan.function_decorator
@guan.statistics_decorator
def load_model(filename='./model.pth'):
import torch
model = torch.load(filename)

View File

@ -2,14 +2,14 @@
import guan
# 获取CPU使用率
@guan.function_decorator
@guan.statistics_decorator
def get_cpu_usage(interval=1):
import psutil
cpu_usage = psutil.cpu_percent(interval=interval)
return cpu_usage
# 获取内存信息
@guan.function_decorator
@guan.statistics_decorator
def get_memory_info():
import psutil
memory_info = psutil.virtual_memory()
@ -20,7 +20,7 @@ def get_memory_info():
return total_memory, used_memory, available_memory, used_memory_percent
# 将WordPress导出的XML格式文件转换成多个MarkDown格式的文件
@guan.function_decorator
@guan.statistics_decorator
def convert_wordpress_xml_to_markdown(xml_file='./a.xml', convert_content=1, replace_more=[]):
import xml.etree.ElementTree as ET
import re
@ -58,7 +58,7 @@ def convert_wordpress_xml_to_markdown(xml_file='./a.xml', convert_content=1, rep
md_file.write(markdown_content)
# 获取运行的日期和时间并写入文件
@guan.function_decorator
@guan.statistics_decorator
def statistics_with_day_and_time(content='', filename='a', file_format='.txt'):
import datetime
datetime_today = str(datetime.date.today())
@ -70,7 +70,7 @@ def statistics_with_day_and_time(content='', filename='a', file_format='.txt'):
f2.write(datetime_today+' '+datetime_time+' '+content+'\n')
# 统计Python文件中import的数量并排序
@guan.function_decorator
@guan.statistics_decorator
def count_number_of_import_statements(filename, file_format='.py', num=1000):
with open(filename+file_format, 'r') as file:
lines = file.readlines()
@ -84,14 +84,14 @@ def count_number_of_import_statements(filename, file_format='.py', num=1000):
return import_statement_counter
# 根据一定的字符长度来分割文本
@guan.function_decorator
@guan.statistics_decorator
def split_text(text, wrap_width=3000):
import textwrap
split_text_list = textwrap.wrap(text, wrap_width)
return split_text_list
# 获取本月的所有日期
@guan.function_decorator
@guan.statistics_decorator
def get_days_of_the_current_month(str_or_datetime='str'):
import datetime
today = datetime.date.today()
@ -111,7 +111,7 @@ def get_days_of_the_current_month(str_or_datetime='str'):
return day_array
# 获取上个月份
@guan.function_decorator
@guan.statistics_decorator
def get_last_month():
import datetime
today = datetime.date.today()
@ -124,7 +124,7 @@ def get_last_month():
return year_of_last_month, last_month
# 获取上上个月份
@guan.function_decorator
@guan.statistics_decorator
def get_the_month_before_last():
import datetime
today = datetime.date.today()
@ -142,7 +142,7 @@ def get_the_month_before_last():
return year_of_the_month_before_last, the_month_before_last
# 获取上个月的所有日期
@guan.function_decorator
@guan.statistics_decorator
def get_days_of_the_last_month(str_or_datetime='str'):
import datetime
import guan
@ -164,7 +164,7 @@ def get_days_of_the_last_month(str_or_datetime='str'):
return day_array
# 获取上上个月的所有日期
@guan.function_decorator
@guan.statistics_decorator
def get_days_of_the_month_before_last(str_or_datetime='str'):
import datetime
import guan
@ -186,7 +186,7 @@ def get_days_of_the_month_before_last(str_or_datetime='str'):
return day_array
# 获取所有股票
@guan.function_decorator
@guan.statistics_decorator
def all_stocks():
import numpy as np
import akshare as ak
@ -196,7 +196,7 @@ def all_stocks():
return title, stock_data
# 获取所有股票的代码
@guan.function_decorator
@guan.statistics_decorator
def all_stock_symbols():
import guan
title, stock_data = guan.all_stocks()
@ -204,7 +204,7 @@ def all_stock_symbols():
return stock_symbols
# 从股票代码获取股票名称
@guan.function_decorator
@guan.statistics_decorator
def find_stock_name_from_symbol(symbol='000002'):
import guan
title, stock_data = guan.all_stocks()
@ -214,7 +214,7 @@ def find_stock_name_from_symbol(symbol='000002'):
return stock_name
# 获取单个股票的历史数据
@guan.function_decorator
@guan.statistics_decorator
def history_data_of_one_stock(symbol='000002', period='daily', start_date="19000101", end_date='21000101'):
# period = 'daily'
# period = 'weekly'
@ -227,7 +227,7 @@ def history_data_of_one_stock(symbol='000002', period='daily', start_date="19000
return title, stock_data
# 获取软件包中的所有模块名
@guan.function_decorator
@guan.statistics_decorator
def get_all_modules_in_one_package(package_name='guan'):
import pkgutil
package = __import__(package_name)
@ -235,7 +235,7 @@ def get_all_modules_in_one_package(package_name='guan'):
return module_names
# 获取软件包中一个模块的所有函数名
@guan.function_decorator
@guan.statistics_decorator
def get_all_functions_in_one_module(module_name, package_name='guan'):
import inspect
function_names = []
@ -246,7 +246,7 @@ def get_all_functions_in_one_module(module_name, package_name='guan'):
return function_names
# 获取软件包中的所有函数名
@guan.function_decorator
@guan.statistics_decorator
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)
@ -264,7 +264,7 @@ def get_all_functions_in_one_package(package_name='guan', print_show=1):
return all_function_names
# 获取包含某个字符的进程PID值
@guan.function_decorator
@guan.statistics_decorator
def get_PID(name):
import subprocess
command = "ps -ef | grep "+name
@ -277,90 +277,14 @@ def get_PID(name):
return id_running
# 获取函数的源码
@guan.function_decorator
@guan.statistics_decorator
def get_function_source(function_name):
import inspect
function_source = inspect.getsource(function_name)
return function_source
# 在服务器上运行函数(说明:接口服务可能为关闭状态,如果无法使用请联系管理员。目前仅支持长度较短的函数,此外由于服务器只获取一个函数内的代码,因此需要函数是独立的可运行的代码。需要注意的是:返回的值是字符串类型,需要自行转换成数字类型。)
@guan.function_decorator
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()
return return_data
# 在服务器上运行大语言模型通过Python函数调用说明接口服务可能为关闭状态如果无法使用请联系管理员
@guan.function_decorator
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()
return response
# 查找文件名相同的文件
@guan.function_decorator
@guan.statistics_decorator
def find_repeated_file_with_same_filename(directory='./', ignored_directory_with_words=[], ignored_file_with_words=[], num=1000):
import os
from collections import Counter
@ -385,7 +309,7 @@ def find_repeated_file_with_same_filename(directory='./', ignored_directory_with
return repeated_file
# 统计各个子文件夹中的文件数量
@guan.function_decorator
@guan.statistics_decorator
def count_file_in_sub_directory(directory='./', sort=0, reverse=1, print_show=1, smaller_than_num=None):
import os
import numpy as np
@ -439,7 +363,7 @@ def count_file_in_sub_directory(directory='./', sort=0, reverse=1, print_show=1,
return sub_directory, num_in_sub_directory
# 改变当前的目录位置
@guan.function_decorator
@guan.statistics_decorator
def change_directory_by_replacement(current_key_word='code', new_key_word='data'):
import os
code_path = os.getcwd()
@ -450,7 +374,7 @@ def change_directory_by_replacement(current_key_word='code', new_key_word='data'
os.chdir(data_path)
# 在多个子文件夹中产生必要的文件,例如 readme.md
@guan.function_decorator
@guan.statistics_decorator
def creat_necessary_file(directory, filename='readme', file_format='.md', content='', overwrite=None, ignored_directory_with_words=[]):
import os
directory_with_file = []
@ -480,7 +404,7 @@ def creat_necessary_file(directory, filename='readme', file_format='.md', conten
f.close()
# 删除特定文件名的文件(慎用)
@guan.function_decorator
@guan.statistics_decorator
def delete_file_with_specific_name(directory, filename='readme', file_format='.md'):
import os
for root, dirs, files in os.walk(directory):
@ -489,7 +413,7 @@ def delete_file_with_specific_name(directory, filename='readme', file_format='.m
os.remove(root+'/'+files[i0])
# 将所有文件移到根目录(慎用)
@guan.function_decorator
@guan.statistics_decorator
def move_all_files_to_root_directory(directory):
import os
import shutil
@ -504,7 +428,7 @@ def move_all_files_to_root_directory(directory):
pass
# 将文件目录结构写入Markdown文件
@guan.function_decorator
@guan.statistics_decorator
def write_file_list_in_markdown(directory='./', filename='a', reverse_positive_or_negative=1, starting_from_h1=None, banned_file_format=[], hide_file_format=None, divided_line=None, show_second_number=None, show_third_number=None):
import os
f = open(filename+'.md', 'w', encoding="utf-8")
@ -608,7 +532,7 @@ def write_file_list_in_markdown(directory='./', filename='a', reverse_positive_o
f.close()
# 从网页的标签中获取内容
@guan.function_decorator
@guan.statistics_decorator
def get_html_from_tags(link, tags=['title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'a']):
from bs4 import BeautifulSoup
import urllib.request
@ -627,14 +551,14 @@ def get_html_from_tags(link, tags=['title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
return content
# 生成二维码
@guan.function_decorator
@guan.statistics_decorator
def creat_qrcode(data="https://www.guanjihuan.com", filename='a', file_format='.png'):
import qrcode
img = qrcode.make(data)
img.save(filename+file_format)
# 将PDF文件转成文本
@guan.function_decorator
@guan.statistics_decorator
def pdf_to_text(pdf_path):
from pdfminer.pdfparser import PDFParser, PDFDocument
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
@ -666,7 +590,7 @@ def pdf_to_text(pdf_path):
return content
# 获取PDF文件页数
@guan.function_decorator
@guan.statistics_decorator
def get_pdf_page_number(pdf_path):
import PyPDF2
pdf_file = open(pdf_path, 'rb')
@ -675,7 +599,7 @@ def get_pdf_page_number(pdf_path):
return num_pages
# 获取PDF文件指定页面的内容
@guan.function_decorator
@guan.statistics_decorator
def pdf_to_txt_for_a_specific_page(pdf_path, page_num=1):
import PyPDF2
pdf_file = open(pdf_path, 'rb')
@ -689,7 +613,7 @@ def pdf_to_txt_for_a_specific_page(pdf_path, page_num=1):
return page_text
# 获取PDF文献中的链接。例如: link_starting_form='https://doi.org'
@guan.function_decorator
@guan.statistics_decorator
def get_links_from_pdf(pdf_path, link_starting_form=''):
import PyPDF2
import re
@ -714,7 +638,7 @@ def get_links_from_pdf(pdf_path, link_starting_form=''):
return links
# 通过Sci-Hub网站下载文献
@guan.function_decorator
@guan.statistics_decorator
def download_with_scihub(address=None, num=1):
from bs4 import BeautifulSoup
import re
@ -752,7 +676,7 @@ def download_with_scihub(address=None, num=1):
print('All completed!\n')
# 将字符串转成音频
@guan.function_decorator
@guan.statistics_decorator
def str_to_audio(str='hello world', filename='str', rate=125, voice=1, read=1, save=0, compress=0, bitrate='16k', print_text=0):
import pyttsx3
import guan
@ -776,7 +700,7 @@ def str_to_audio(str='hello world', filename='str', rate=125, voice=1, read=1, s
engine.runAndWait()
# 将txt文件转成音频
@guan.function_decorator
@guan.statistics_decorator
def txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, compress=0, bitrate='16k', print_text=0):
import pyttsx3
import guan
@ -804,7 +728,7 @@ def txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, compress=0, bitrat
engine.runAndWait()
# 将PDF文件转成音频
@guan.function_decorator
@guan.statistics_decorator
def pdf_to_audio(pdf_path, rate=125, voice=1, read=1, save=0, compress=0, bitrate='16k', print_text=0):
import pyttsx3
import guan
@ -832,7 +756,7 @@ def pdf_to_audio(pdf_path, rate=125, voice=1, read=1, save=0, compress=0, bitrat
engine.runAndWait()
# 将wav音频文件压缩成MP3音频文件
@guan.function_decorator
@guan.statistics_decorator
def compress_wav_to_mp3(wav_path, output_filename='a.mp3', bitrate='16k'):
# Note: Beside the installation of pydub, you may also need download FFmpeg on http://www.ffmpeg.org/download.html and add the bin path to the environment variable.
from pydub import AudioSegment
@ -840,7 +764,7 @@ def compress_wav_to_mp3(wav_path, output_filename='a.mp3', bitrate='16k'):
sound.export(output_filename,format="mp3",bitrate=bitrate)
# 播放学术单词
@guan.function_decorator
@guan.statistics_decorator
def play_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_translation=1, show_link=1, translation_time=2, rest_time=1):
from bs4 import BeautifulSoup
import re
@ -901,7 +825,7 @@ def play_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_translati
print()
# 播放挑选过后的学术单词
@guan.function_decorator
@guan.statistics_decorator
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
@ -958,7 +882,7 @@ def play_selected_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_
print()
# 播放元素周期表上的单词
@guan.function_decorator
@guan.statistics_decorator
def play_element_words(random_on=0, show_translation=1, show_link=1, translation_time=2, rest_time=1):
from bs4 import BeautifulSoup
import re

View File

@ -2,7 +2,7 @@
import guan
# 计算电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance(fermi_energy, h00, h01, length=100):
import numpy as np
import copy
@ -22,7 +22,7 @@ def calculate_conductance(fermi_energy, h00, h01, length=100):
return conductance
# 计算不同费米能下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_fermi_energy_array(fermi_energy_array, h00, h01, length=100, print_show=0):
import numpy as np
import guan
@ -37,7 +37,7 @@ def calculate_conductance_with_fermi_energy_array(fermi_energy_array, h00, h01,
return conductance_array
# 计算在势垒散射下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_barrier(fermi_energy, h00, h01, length=100, barrier_length=20, barrier_potential=1):
import numpy as np
import copy
@ -61,7 +61,7 @@ def calculate_conductance_with_barrier(fermi_energy, h00, h01, length=100, barri
return conductance
# 计算在无序散射下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_disorder(fermi_energy, h00, h01, disorder_intensity=2.0, disorder_concentration=1.0, length=100, calculation_times=1):
import numpy as np
import copy
@ -90,7 +90,7 @@ def calculate_conductance_with_disorder(fermi_energy, h00, h01, disorder_intensi
return conductance_averaged
# 计算在无序垂直切片的散射下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_slice_disorder(fermi_energy, h00, h01, disorder_intensity=2.0, disorder_concentration=1.0, length=100):
import numpy as np
import copy
@ -114,7 +114,7 @@ def calculate_conductance_with_slice_disorder(fermi_energy, h00, h01, disorder_i
return conductance
# 计算在无序水平切片的散射下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_disorder_inside_unit_cell_which_keeps_translational_symmetry(fermi_energy, h00, h01, disorder_intensity=2.0, disorder_concentration=1.0, length=100):
import numpy as np
import copy
@ -139,7 +139,7 @@ def calculate_conductance_with_disorder_inside_unit_cell_which_keeps_translation
return conductance
# 计算在随机空位的散射下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_random_vacancy(fermi_energy, h00, h01, vacancy_concentration=0.5, vacancy_potential=1e9, length=100):
import numpy as np
import copy
@ -164,7 +164,7 @@ def calculate_conductance_with_random_vacancy(fermi_energy, h00, h01, vacancy_co
return conductance
# 计算在不同无序散射强度下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_disorder_intensity_array(fermi_energy, h00, h01, disorder_intensity_array, disorder_concentration=1.0, length=100, calculation_times=1, print_show=0):
import numpy as np
import guan
@ -181,7 +181,7 @@ def calculate_conductance_with_disorder_intensity_array(fermi_energy, h00, h01,
return conductance_array
# 计算在不同无序浓度下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_disorder_concentration_array(fermi_energy, h00, h01, disorder_concentration_array, disorder_intensity=2.0, length=100, calculation_times=1, print_show=0):
import numpy as np
import guan
@ -198,7 +198,7 @@ def calculate_conductance_with_disorder_concentration_array(fermi_energy, h00, h
return conductance_array
# 计算在不同无序散射长度下的电导
@guan.function_decorator
@guan.statistics_decorator
def calculate_conductance_with_scattering_length_array(fermi_energy, h00, h01, length_array, disorder_intensity=2.0, disorder_concentration=1.0, calculation_times=1, print_show=0):
import numpy as np
import guan
@ -215,7 +215,7 @@ def calculate_conductance_with_scattering_length_array(fermi_energy, h00, h01, l
return conductance_array
# 计算得到Gamma矩阵和格林函数用于计算六端口的量子输运
@guan.function_decorator
@guan.statistics_decorator
def get_gamma_array_and_green_for_six_terminal_transmission(fermi_energy, h00_for_lead_4, h01_for_lead_4, h00_for_lead_2, h01_for_lead_2, center_hamiltonian, width=10, length=50, internal_degree=1, moving_step_of_leads=10):
import numpy as np
import guan
@ -262,7 +262,7 @@ def get_gamma_array_and_green_for_six_terminal_transmission(fermi_energy, h00_fo
return gamma_array, green
# 计算六端口的透射矩阵
@guan.function_decorator
@guan.statistics_decorator
def calculate_six_terminal_transmission_matrix(fermi_energy, h00_for_lead_4, h01_for_lead_4, h00_for_lead_2, h01_for_lead_2, center_hamiltonian, width=10, length=50, internal_degree=1, moving_step_of_leads=10):
import numpy as np
import guan
@ -287,7 +287,7 @@ def calculate_six_terminal_transmission_matrix(fermi_energy, h00_for_lead_4, h01
return transmission_matrix
# 计算从电极1出发的透射系数
@guan.function_decorator
@guan.statistics_decorator
def calculate_six_terminal_transmissions_from_lead_1(fermi_energy, h00_for_lead_4, h01_for_lead_4, h00_for_lead_2, h01_for_lead_2, center_hamiltonian, width=10, length=50, internal_degree=1, moving_step_of_leads=10):
import numpy as np
import guan
@ -300,7 +300,7 @@ def calculate_six_terminal_transmissions_from_lead_1(fermi_energy, h00_for_lead_
return transmission_12, transmission_13, transmission_14, transmission_15, transmission_16
# 通过动量k的虚部判断通道为传播通道还是衰减通道
@guan.function_decorator
@guan.statistics_decorator
def if_active_channel(k_of_channel):
import numpy as np
if np.abs(np.imag(k_of_channel))<1e-6:
@ -310,7 +310,7 @@ def if_active_channel(k_of_channel):
return if_active
# 获取通道的动量和速度,用于计算散射矩阵
@guan.function_decorator
@guan.statistics_decorator
def get_k_and_velocity_of_channel(fermi_energy, h00, h01):
import numpy as np
import math
@ -347,7 +347,7 @@ def get_k_and_velocity_of_channel(fermi_energy, h00, h01):
return k_of_channel, velocity_of_channel, eigenvalue, eigenvector
# 获取分类后的动量和速度以及U和F用于计算散射矩阵
@guan.function_decorator
@guan.statistics_decorator
def get_classified_k_velocity_u_and_f(fermi_energy, h00, h01):
import numpy as np
import guan
@ -400,7 +400,7 @@ def get_classified_k_velocity_u_and_f(fermi_energy, h00, h01):
return k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
# 计算散射矩阵
@guan.function_decorator
@guan.statistics_decorator
def calculate_scattering_matrix(fermi_energy, h00, h01, length=100):
import numpy as np
import math
@ -446,7 +446,7 @@ def calculate_scattering_matrix(fermi_energy, h00, h01, length=100):
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
# 从散射矩阵中,获取散射矩阵的信息
@guan.function_decorator
@guan.statistics_decorator
def information_of_scattering_matrix(transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active):
import numpy as np
if np.array(transmission_matrix).shape==():
@ -468,7 +468,7 @@ def information_of_scattering_matrix(transmission_matrix, reflection_matrix, k_r
return number_of_active_channels, number_of_evanescent_channels, k_of_right_moving_active_channels, k_of_left_moving_active_channels, velocity_of_right_moving_active_channels, velocity_of_left_moving_active_channels, transmission_matrix_for_active_channels, reflection_matrix_for_active_channels, total_transmission_of_channels, total_conductance, total_reflection_of_channels, sum_of_transmission_and_reflection_of_channels
# 已知h00和h01计算散射矩阵并获得散射矩阵的信息
@guan.function_decorator
@guan.statistics_decorator
def calculate_scattering_matrix_and_get_information(fermi_energy, h00, h01, length=100):
import guan
transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active = guan.calculate_scattering_matrix(fermi_energy, h00, h01, length=length)
@ -478,7 +478,7 @@ def calculate_scattering_matrix_and_get_information(fermi_energy, h00, h01, leng
return number_of_active_channels, number_of_evanescent_channels, k_of_right_moving_active_channels, k_of_left_moving_active_channels, velocity_of_right_moving_active_channels, velocity_of_left_moving_active_channels, transmission_matrix_for_active_channels, reflection_matrix_for_active_channels, total_transmission_of_channels, total_conductance, total_reflection_of_channels, sum_of_transmission_and_reflection_of_channels
# 从散射矩阵中打印出散射矩阵的信息
@guan.function_decorator
@guan.statistics_decorator
def print_or_write_scattering_matrix_with_information_of_scattering_matrix(number_of_active_channels, number_of_evanescent_channels, k_of_right_moving_active_channels, k_of_left_moving_active_channels, velocity_of_right_moving_active_channels, velocity_of_left_moving_active_channels, transmission_matrix_for_active_channels, reflection_matrix_for_active_channels, total_transmission_of_channels, total_conductance, total_reflection_of_channels, sum_of_transmission_and_reflection_of_channels, print_show=1, write_file=0, filename='a', file_format='.txt'):
if print_show == 1:
print('\nActive channel (left or right) = ', number_of_active_channels)
@ -523,7 +523,7 @@ def print_or_write_scattering_matrix_with_information_of_scattering_matrix(numbe
f.write('Total conductance = '+str(total_conductance)+'\n')
# 已知h00和h01计算散射矩阵并打印出散射矩阵的信息
@guan.function_decorator
@guan.statistics_decorator
def print_or_write_scattering_matrix(fermi_energy, h00, h01, length=100, print_show=1, write_file=0, filename='a', file_format='.txt'):
import guan
transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active = guan.calculate_scattering_matrix(fermi_energy, h00, h01, length=length)
@ -533,7 +533,7 @@ def print_or_write_scattering_matrix(fermi_energy, h00, h01, length=100, print_s
guan.print_or_write_scattering_matrix_with_information_of_scattering_matrix(number_of_active_channels, number_of_evanescent_channels, k_of_right_moving_active_channels, k_of_left_moving_active_channels, velocity_of_right_moving_active_channels, velocity_of_left_moving_active_channels, transmission_matrix_for_active_channels, reflection_matrix_for_active_channels, total_transmission_of_channels, total_conductance, total_reflection_of_channels, sum_of_transmission_and_reflection_of_channels, print_show=print_show, write_file=write_file, filename=filename, file_format=file_format)
# 在无序下,计算散射矩阵
@guan.function_decorator
@guan.statistics_decorator
def calculate_scattering_matrix_with_disorder(fermi_energy, h00, h01, length=100, disorder_intensity=2.0, disorder_concentration=1.0):
import numpy as np
import math
@ -583,7 +583,7 @@ def calculate_scattering_matrix_with_disorder(fermi_energy, h00, h01, length=100
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
# 在无序下,计算散射矩阵,并获取散射矩阵多次计算的平均信息
@guan.function_decorator
@guan.statistics_decorator
def calculate_scattering_matrix_with_disorder_and_get_averaged_information(fermi_energy, h00, h01, length=100, disorder_intensity=2.0, disorder_concentration=1.0, calculation_times=1):
import guan
transmission_matrix_for_active_channels_averaged = 0

View File

@ -2,7 +2,7 @@
import guan
# 通过高效法计算方格子的陈数
@guan.function_decorator
@guan.statistics_decorator
def calculate_chern_number_for_square_lattice_with_efficient_method(hamiltonian_function, precision=100, print_show=0):
import numpy as np
import math
@ -41,7 +41,7 @@ def calculate_chern_number_for_square_lattice_with_efficient_method(hamiltonian_
return chern_number
# 通过高效法计算方格子的陈数(可计算简并的情况)
@guan.function_decorator
@guan.statistics_decorator
def calculate_chern_number_for_square_lattice_with_efficient_method_for_degenerate_case(hamiltonian_function, index_of_bands=[0, 1], precision=100, print_show=0):
import numpy as np
import math
@ -111,7 +111,7 @@ def calculate_chern_number_for_square_lattice_with_efficient_method_for_degenera
return chern_number
# 通过Wilson loop方法计算方格子的陈数
@guan.function_decorator
@guan.statistics_decorator
def calculate_chern_number_for_square_lattice_with_wilson_loop(hamiltonian_function, precision_of_plaquettes=20, precision_of_wilson_loop=5, print_show=0):
import numpy as np
import math
@ -156,7 +156,7 @@ def calculate_chern_number_for_square_lattice_with_wilson_loop(hamiltonian_funct
return chern_number
# 通过Wilson loop方法计算方格子的陈数可计算简并的情况
@guan.function_decorator
@guan.statistics_decorator
def calculate_chern_number_for_square_lattice_with_wilson_loop_for_degenerate_case(hamiltonian_function, index_of_bands=[0, 1], precision_of_plaquettes=20, precision_of_wilson_loop=5, print_show=0):
import numpy as np
import math
@ -220,7 +220,7 @@ def calculate_chern_number_for_square_lattice_with_wilson_loop_for_degenerate_ca
return chern_number
# 通过高效法计算贝利曲率
@guan.function_decorator
@guan.statistics_decorator
def calculate_berry_curvature_with_efficient_method(hamiltonian_function, k_min='default', k_max='default', precision=100, print_show=0):
import numpy as np
import cmath
@ -267,7 +267,7 @@ def calculate_berry_curvature_with_efficient_method(hamiltonian_function, k_min=
return k_array, berry_curvature_array
# 通过高效法计算贝利曲率(可计算简并的情况)
@guan.function_decorator
@guan.statistics_decorator
def calculate_berry_curvature_with_efficient_method_for_degenerate_case(hamiltonian_function, index_of_bands=[0, 1], k_min='default', k_max='default', precision=100, print_show=0):
import numpy as np
import cmath
@ -346,7 +346,7 @@ def calculate_berry_curvature_with_efficient_method_for_degenerate_case(hamilton
return k_array, berry_curvature_array
# 通过Wilson loop方法计算贝里曲率
@guan.function_decorator
@guan.statistics_decorator
def calculate_berry_curvature_with_wilson_loop(hamiltonian_function, k_min='default', k_max='default', precision_of_plaquettes=20, precision_of_wilson_loop=5, print_show=0):
import numpy as np
import math
@ -403,7 +403,7 @@ def calculate_berry_curvature_with_wilson_loop(hamiltonian_function, k_min='defa
return k_array, berry_curvature_array
# 通过Wilson loop方法计算贝里曲率可计算简并的情况
@guan.function_decorator
@guan.statistics_decorator
def calculate_berry_curvature_with_wilson_loop_for_degenerate_case(hamiltonian_function, index_of_bands=[0, 1], k_min='default', k_max='default', precision_of_plaquettes=20, precision_of_wilson_loop=5, print_show=0):
import numpy as np
import math
@ -475,7 +475,7 @@ def calculate_berry_curvature_with_wilson_loop_for_degenerate_case(hamiltonian_f
return k_array, berry_curvature_array
# 计算蜂窝格子的陈数(高效法)
@guan.function_decorator
@guan.statistics_decorator
def calculate_chern_number_for_honeycomb_lattice(hamiltonian_function, a=1, precision=300, print_show=0):
import numpy as np
import math
@ -519,7 +519,7 @@ def calculate_chern_number_for_honeycomb_lattice(hamiltonian_function, a=1, prec
return chern_number
# 计算Wilson loop
@guan.function_decorator
@guan.statistics_decorator
def calculate_wilson_loop(hamiltonian_function, k_min='default', k_max='default', precision=100, print_show=0):
import numpy as np
import guan