diff --git a/PyPI/dist/guan-0.1.83-py3-none-any.whl b/PyPI/dist/guan-0.1.83-py3-none-any.whl new file mode 100644 index 0000000..c2c1241 Binary files /dev/null and b/PyPI/dist/guan-0.1.83-py3-none-any.whl differ diff --git a/PyPI/dist/guan-0.1.83.tar.gz b/PyPI/dist/guan-0.1.83.tar.gz new file mode 100644 index 0000000..db872de Binary files /dev/null and b/PyPI/dist/guan-0.1.83.tar.gz differ diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index f517163..57707b0 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -1,7 +1,7 @@ [metadata] # replace with your username: name = guan -version = 0.1.82 +version = 0.1.83 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 e8b2088..f5e59fe 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.82 +Version: 0.1.83 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 188ccab..18ff90e 100644 --- a/PyPI/src/guan.egg-info/SOURCES.txt +++ b/PyPI/src/guan.egg-info/SOURCES.txt @@ -9,7 +9,7 @@ src/guan/__init__.py src/guan/band_structures_and_wave_functions.py src/guan/basic_functions.py src/guan/data_processing.py -src/guan/decorator.py +src/guan/decorators.py src/guan/density_of_states.py src/guan/figure_plotting.py src/guan/file_reading_and_writing.py diff --git a/PyPI/src/guan/Fourier_transform.py b/PyPI/src/guan/Fourier_transform.py index a38a4f9..c5b759f 100644 --- a/PyPI/src/guan/Fourier_transform.py +++ b/PyPI/src/guan/Fourier_transform.py @@ -1,8 +1,6 @@ # Module: Fourier_transform -import guan # 通过元胞和跃迁项得到一维的哈密顿量(需要输入k值) -@guan.statistics_decorator def one_dimensional_fourier_transform(k, unit_cell, hopping): import numpy as np import cmath @@ -12,7 +10,6 @@ def one_dimensional_fourier_transform(k, unit_cell, hopping): return hamiltonian # 通过元胞和跃迁项得到二维方格子的哈密顿量(需要输入k值) -@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 +20,6 @@ def two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell, hopp return hamiltonian # 通过元胞和跃迁项得到三维立方格子的哈密顿量(需要输入k值) -@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 +31,6 @@ def three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell, return hamiltonian # 通过元胞和跃迁项得到一维的哈密顿量(返回的哈密顿量为携带k的函数) -@guan.statistics_decorator def one_dimensional_fourier_transform_with_k(unit_cell, hopping): import functools import guan @@ -43,7 +38,6 @@ def one_dimensional_fourier_transform_with_k(unit_cell, hopping): return hamiltonian_function # 通过元胞和跃迁项得到二维方格子的哈密顿量(返回的哈密顿量为携带k的函数) -@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 +45,6 @@ def two_dimensional_fourier_transform_for_square_lattice_with_k1_k2(unit_cell, h return hamiltonian_function # 通过元胞和跃迁项得到三维立方格子的哈密顿量(返回的哈密顿量为携带k的函数) -@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 +52,12 @@ def three_dimensional_fourier_transform_for_cubic_lattice_with_k1_k2_k3(unit_cel return hamiltonian_function # 由实空间格矢得到倒空间格矢(一维) -@guan.statistics_decorator def calculate_one_dimensional_reciprocal_lattice_vector(a1): import numpy as np b1 = 2*np.pi/a1 return b1 # 由实空间格矢得到倒空间格矢(二维) -@guan.statistics_decorator def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2): import numpy as np a1 = np.array(a1) @@ -81,7 +72,6 @@ def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2): return b1, b2 # 由实空间格矢得到倒空间格矢(三维) -@guan.statistics_decorator def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3): import numpy as np a1 = np.array(a1) @@ -93,14 +83,12 @@ def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3): return b1, b2, b3 # 由实空间格矢得到倒空间格矢(一维),这里为符号运算 -@guan.statistics_decorator def calculate_one_dimensional_reciprocal_lattice_vector_with_sympy(a1): import sympy b1 = 2*sympy.pi/a1 return b1 # 由实空间格矢得到倒空间格矢(二维),这里为符号运算 -@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 +103,6 @@ def calculate_two_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2): return b1, b2 # 由实空间格矢得到倒空间格矢(三维),这里为符号运算 -@guan.statistics_decorator def calculate_three_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2, a3): import sympy cross_a2_a3 = a2.cross(a3) diff --git a/PyPI/src/guan/Green_functions.py b/PyPI/src/guan/Green_functions.py index c7e54b0..d0988a8 100644 --- a/PyPI/src/guan/Green_functions.py +++ b/PyPI/src/guan/Green_functions.py @@ -1,8 +1,6 @@ # Module: Green_functions -import guan # 输入哈密顿量,得到格林函数 -@guan.statistics_decorator def green_function(fermi_energy, hamiltonian, broadening, self_energy=0): import numpy as np if np.array(hamiltonian).shape==(): @@ -13,7 +11,6 @@ def green_function(fermi_energy, hamiltonian, broadening, self_energy=0): return green # 在Dyson方程中的一个中间格林函数G_{nn}^{n} -@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 +22,12 @@ def green_function_nn_n(fermi_energy, h00, h01, green_nn_n_minus, broadening, se return green_nn_n # 在Dyson方程中的一个中间格林函数G_{in}^{n} -@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.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 +35,12 @@ def green_function_ni_n(green_nn_n, h01, green_ni_n_minus): return green_ni_n # 在Dyson方程中的一个中间格林函数G_{ii}^{n} -@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.statistics_decorator def transfer_matrix(fermi_energy, h00, h01): import numpy as np h01 = np.array(h01) @@ -63,7 +56,6 @@ def transfer_matrix(fermi_energy, h00, h01): return transfer # 计算电极的表面格林函数 -@guan.statistics_decorator def surface_green_function_of_lead(fermi_energy, h00, h01): import numpy as np h01 = np.array(h01) @@ -89,7 +81,6 @@ def surface_green_function_of_lead(fermi_energy, h00, h01): return right_lead_surface, left_lead_surface # 计算电极的自能(基于Dyson方程的小矩阵形式) -@guan.statistics_decorator def self_energy_of_lead(fermi_energy, h00, h01): import numpy as np import guan @@ -102,7 +93,6 @@ def self_energy_of_lead(fermi_energy, h00, h01): return right_self_energy, left_self_energy, gamma_right, gamma_left # 计算电极的自能(基于中心区整体的大矩阵形式) -@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 +106,6 @@ 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.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 +116,6 @@ def self_energy_of_lead_with_h_lead_to_center(fermi_energy, h00, h01, h_lead_to_ return self_energy, gamma # 计算考虑电极自能后的中心区的格林函数 -@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 +125,6 @@ def green_function_with_leads(fermi_energy, h00, h01, h_LC, h_CR, center_hamilto return green, gamma_right, gamma_left # 计算用于计算局域电流的格林函数G_n -@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 diff --git a/PyPI/src/guan/Hamiltonian_of_examples.py b/PyPI/src/guan/Hamiltonian_of_examples.py index 3bb3414..81d8660 100644 --- a/PyPI/src/guan/Hamiltonian_of_examples.py +++ b/PyPI/src/guan/Hamiltonian_of_examples.py @@ -1,8 +1,6 @@ # Module: Hamiltonian_of_examples -import guan # 构建一维的有限尺寸体系哈密顿量(可设置是否为周期边界条件) -@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 +21,6 @@ def hamiltonian_of_finite_size_system_along_one_direction(N, on_site=0, hopping= return hamiltonian # 构建二维的方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件) -@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 +53,6 @@ def hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1 return hamiltonian # 构建三维的立方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件) -@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 +101,6 @@ def hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(N return hamiltonian # 构建有限尺寸的SSH模型哈密顿量 -@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 +118,6 @@ def hamiltonian_of_finite_size_ssh_model(N, v=0.6, w=1, onsite_1=0, onsite_2=0, return hamiltonian # 获取Zigzag边的石墨烯条带的元胞间跃迁 -@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 +131,6 @@ def get_hopping_term_of_graphene_ribbon_along_zigzag_direction(N, eta=0): return hopping # 构建有限尺寸的石墨烯哈密顿量(可设置是否为周期边界条件) -@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 +142,6 @@ def hamiltonian_of_finite_size_system_along_two_directions_for_graphene(N1, N2, return hamiltonian # 获取石墨烯有效模型沿着x方向的在位能和跃迁项(其中,动量qy为参数) -@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 +162,6 @@ def get_onsite_and_hopping_terms_of_2d_effective_graphene_along_one_direction(qy return h00, h01 # 获取BHZ模型的在位能和跃迁项 -@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 +195,6 @@ 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.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 +218,6 @@ 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.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 +241,18 @@ def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_down(A=0.3645/5, B=- return H0, H1, H2 # 一维链的哈密顿量(倒空间) -@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.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.statistics_decorator def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0): import numpy as np import guan @@ -284,14 +270,12 @@ def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0): return hamiltonian # 三维立方格子的哈密顿量(倒空间) -@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.statistics_decorator def hamiltonian_of_ssh_model(k, v=0.6, w=1): import numpy as np import cmath @@ -301,7 +285,6 @@ def hamiltonian_of_ssh_model(k, v=0.6, w=1): return hamiltonian # 石墨烯的哈密顿量(倒空间) -@guan.statistics_decorator def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'): import numpy as np import cmath @@ -318,7 +301,6 @@ def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'): return hamiltonian # 石墨烯有效模型的哈密顿量(倒空间) -@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 +316,6 @@ def effective_hamiltonian_of_graphene(qx, qy, t=1, staggered_potential=0, valley return hamiltonian # 石墨烯有效模型离散化后的哈密顿量(倒空间) -@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 +331,6 @@ def effective_hamiltonian_of_graphene_after_discretization(qx, qy, t=1, staggere return hamiltonian # 准一维Zigzag边石墨烯条带的哈密顿量(倒空间) -@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 +360,6 @@ def hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension(k, N=10, M=0, t=1 return hamiltonian # Haldane模型的哈密顿量(倒空间) -@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 +381,6 @@ def hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi='default', a=' return hamiltonian # 准一维Haldane模型条带的哈密顿量(倒空间) -@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 +435,6 @@ def hamiltonian_of_haldane_model_in_quasi_one_dimension(k, N=10, M=2/3, t1=1, t2 return hamiltonian # 一个量子反常霍尔效应的哈密顿量(倒空间) -@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 +446,6 @@ def hamiltonian_of_one_QAH_model(k1, k2, t1=1, t2=1, t3=0.5, m=-1): return hamiltonian # BHZ模型的哈密顿量(倒空间) -@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 +464,6 @@ 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.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 +478,6 @@ def hamiltonian_of_half_bhz_model_for_spin_up(kx, ky, A=0.3645/5, B=-0.686/25, C return hamiltonian # 半BHZ模型的哈密顿量(自旋向下)(倒空间) -@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 +492,6 @@ def hamiltonian_of_half_bhz_model_for_spin_down(kx, ky, A=0.3645/5, B=-0.686/25, return hamiltonian # BBH模型的哈密顿量(倒空间) -@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 +511,6 @@ def hamiltonian_of_bbh_model(kx, ky, gamma_x=0.5, gamma_y=0.5, lambda_x=1, lambd return hamiltonian # Kagome模型的哈密顿量(倒空间) -@guan.statistics_decorator def hamiltonian_of_kagome_lattice(kx, ky, t=1): import numpy as np import math @@ -554,7 +526,6 @@ def hamiltonian_of_kagome_lattice(kx, ky, t=1): return hamiltonian # 超蜂窝晶格的哈密顿量(倒空间) -@guan.statistics_decorator def hamiltonian_of_hyperhoneycomb_lattice(kx, ky, kz, t=1, a=1): import cmath import numpy as np diff --git a/PyPI/src/guan/__init__.py b/PyPI/src/guan/__init__.py index cb84d55..dc91f86 100644 --- a/PyPI/src/guan/__init__.py +++ b/PyPI/src/guan/__init__.py @@ -1,6 +1,5 @@ # 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. -from .decorator import * from .basic_functions import * from .Fourier_transform import * from .Hamiltonian_of_examples import * @@ -13,4 +12,5 @@ from .machine_learning import * from .file_reading_and_writing import * from .figure_plotting import * from .data_processing import * -from .others import * \ No newline at end of file +from .others import * +from .decorators 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 3051560..4607dd5 100644 --- a/PyPI/src/guan/band_structures_and_wave_functions.py +++ b/PyPI/src/guan/band_structures_and_wave_functions.py @@ -1,8 +1,6 @@ # Module: band_structures_and_wave_functions -import guan # 计算哈密顿量的本征值 -@guan.statistics_decorator def calculate_eigenvalue(hamiltonian): import numpy as np if np.array(hamiltonian).shape==(): @@ -12,7 +10,6 @@ def calculate_eigenvalue(hamiltonian): return eigenvalue # 输入哈密顿量函数(带一组参数),计算一组参数下的本征值,返回本征值向量组 -@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 +33,6 @@ def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function, print return eigenvalue_array # 输入哈密顿量函数(带两组参数),计算两组参数下的本征值,返回本征值向量组 -@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 +66,12 @@ def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_funct return eigenvalue_array # 计算哈密顿量的本征矢 -@guan.statistics_decorator def calculate_eigenvector(hamiltonian): import numpy as np eigenvalue, eigenvector = np.linalg.eigh(hamiltonian) return eigenvector # 通过二分查找的方法获取和相邻波函数一样规范的波函数 -@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 +111,6 @@ def find_vector_with_the_same_gauge_with_binary_search(vector_target, vector_ref return vector_target # 通过乘一个相反的相位角,实现波函数的一个非零分量为实数,从而得到固定规范的波函数 -@guan.statistics_decorator def find_vector_with_fixed_gauge_by_making_one_component_real(vector, index=None): import numpy as np import cmath @@ -129,7 +122,6 @@ def find_vector_with_fixed_gauge_by_making_one_component_real(vector, index=None return vector # 通过乘一个相反的相位角,实现波函数的一个非零分量为实数,从而得到固定规范的波函数(在一组波函数中选取最大的那个分量) -@guan.statistics_decorator def find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array): import numpy as np import guan @@ -143,7 +135,6 @@ def find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array return vector_array # 循环查找规范使得波函数的一个非零分量为实数,得到固定规范的波函数 -@guan.statistics_decorator def loop_find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None): import numpy as np import cmath @@ -162,7 +153,6 @@ def loop_find_vector_with_fixed_gauge_by_making_one_component_real(vector, preci return vector # 循环查找规范使得波函数的一个非零分量为实数,得到固定规范的波函数(在一组波函数中选取最大的那个分量) -@guan.statistics_decorator def loop_find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array, precision=0.005): import numpy as np import guan @@ -176,7 +166,6 @@ def loop_find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_ return vector_array # 旋转两个简并的波函数(说明:参数比较多,算法效率不高) -@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 @@ -206,7 +195,6 @@ def rotation_of_degenerate_vectors(vector1, vector2, index1=None, index2=None, p return vector1, vector2 # 旋转两个简并的波函数向量组(说明:参数比较多,算法效率不高) -@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 @@ -224,7 +212,6 @@ def rotation_of_degenerate_vectors_array(vector1_array, vector2_array, precision return vector1_array, vector2_array # 在一组数据中找到数值相近的数 -@guan.statistics_decorator def find_close_values_in_one_array(array, precision=1e-2): new_array = [] i0 = 0 @@ -238,7 +225,6 @@ def find_close_values_in_one_array(array, precision=1e-2): return new_array # 寻找能带的简并点 -@guan.statistics_decorator def find_degenerate_points(k_array, eigenvalue_array, precision=1e-2): import guan degenerate_k_array = [] diff --git a/PyPI/src/guan/basic_functions.py b/PyPI/src/guan/basic_functions.py index aff7813..ce5e404 100644 --- a/PyPI/src/guan/basic_functions.py +++ b/PyPI/src/guan/basic_functions.py @@ -1,126 +1,104 @@ # Module: basic_functions -import guan # 测试 -@guan.statistics_decorator def test(): import guan current_version = guan.get_current_version('guan') print(f'Congratulations on successfully installing Guan package! The installed version is guan-{current_version}.') # 泡利矩阵 -@guan.statistics_decorator def sigma_0(): import numpy as np return np.eye(2) -@guan.statistics_decorator def sigma_x(): import numpy as np return np.array([[0, 1],[1, 0]]) -@guan.statistics_decorator def sigma_y(): import numpy as np return np.array([[0, -1j],[1j, 0]]) -@guan.statistics_decorator def sigma_z(): import numpy as np return np.array([[1, 0],[0, -1]]) # 泡利矩阵的张量积 -@guan.statistics_decorator def sigma_00(): import numpy as np import guan return np.kron(guan.sigma_0(), guan.sigma_0()) -@guan.statistics_decorator def sigma_0x(): import numpy as np import guan return np.kron(guan.sigma_0(), guan.sigma_x()) -@guan.statistics_decorator def sigma_0y(): import numpy as np import guan return np.kron(guan.sigma_0(), guan.sigma_y()) -@guan.statistics_decorator def sigma_0z(): import numpy as np import guan return np.kron(guan.sigma_0(), guan.sigma_z()) -@guan.statistics_decorator def sigma_x0(): import numpy as np import guan return np.kron(guan.sigma_x(), guan.sigma_0()) -@guan.statistics_decorator def sigma_xx(): import numpy as np import guan return np.kron(guan.sigma_x(), guan.sigma_x()) -@guan.statistics_decorator def sigma_xy(): import numpy as np import guan return np.kron(guan.sigma_x(), guan.sigma_y()) -@guan.statistics_decorator def sigma_xz(): import numpy as np import guan return np.kron(guan.sigma_x(), guan.sigma_z()) -@guan.statistics_decorator def sigma_y0(): import numpy as np import guan return np.kron(guan.sigma_y(), guan.sigma_0()) -@guan.statistics_decorator def sigma_yx(): import numpy as np import guan return np.kron(guan.sigma_y(), guan.sigma_x()) -@guan.statistics_decorator def sigma_yy(): import numpy as np import guan return np.kron(guan.sigma_y(), guan.sigma_y()) -@guan.statistics_decorator def sigma_yz(): import numpy as np import guan return np.kron(guan.sigma_y(), guan.sigma_z()) -@guan.statistics_decorator def sigma_z0(): import numpy as np import guan return np.kron(guan.sigma_z(), guan.sigma_0()) -@guan.statistics_decorator def sigma_zx(): import numpy as np import guan return np.kron(guan.sigma_z(), guan.sigma_x()) -@guan.statistics_decorator def sigma_zy(): import numpy as np import guan return np.kron(guan.sigma_z(), guan.sigma_y()) -@guan.statistics_decorator def sigma_zz(): import numpy as np import guan diff --git a/PyPI/src/guan/data_processing.py b/PyPI/src/guan/data_processing.py index 5a07732..14048a4 100644 --- a/PyPI/src/guan/data_processing.py +++ b/PyPI/src/guan/data_processing.py @@ -1,8 +1,6 @@ # Module: data_processing -import guan # 并行计算前的预处理,把参数分成多份 -@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] @@ -18,20 +16,17 @@ def preprocess_for_parallel_calculations(parameter_array_all, cpus=1, task_index return parameter_array # 根据子数组的第index个元素对子数组进行排序(index从0开始) -@guan.statistics_decorator def sort_array_by_index_element(original_array, index): sorted_array = sorted(original_array, key=lambda x: x[index]) return sorted_array # 随机获得一个整数,左闭右闭 -@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.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) @@ -39,7 +34,6 @@ def generate_random_int_number_for_a_specific_seed(seed=0, x_min=0, x_max=10): return rand_num # 以显示编号的样式,打印数组 -@guan.statistics_decorator def print_array_with_index(array, show_index=1, index_type=0): if show_index==0: for i0 in array: @@ -57,21 +51,18 @@ def print_array_with_index(array, show_index=1, index_type=0): print(index, i0) # 使用jieba软件包进行分词 -@guan.statistics_decorator def divide_text_into_words(text): import jieba words = jieba.lcut(text) return words # 根据一定的字符长度来分割文本 -@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.statistics_decorator def check_Chinese_or_English(a): if '\u4e00' <= a <= '\u9fff' : word_type = 'Chinese' @@ -82,7 +73,6 @@ def check_Chinese_or_English(a): return word_type # 统计中英文文本的字数,默认不包括空格 -@guan.statistics_decorator def count_words(text, include_space=0, show_words=0): import jieba import guan @@ -110,7 +100,6 @@ def count_words(text, include_space=0, show_words=0): return num_words # 将RGB转成HEX -@guan.statistics_decorator def rgb_to_hex(rgb, pound=1): if pound==0: return '%02x%02x%02x' % rgb @@ -118,14 +107,12 @@ def rgb_to_hex(rgb, pound=1): return '#%02x%02x%02x' % rgb # 将HEX转成RGB -@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.statistics_decorator def encryption_MD5(password, salt=''): import hashlib password = salt+password @@ -133,7 +120,6 @@ def encryption_MD5(password, salt=''): return hashed_password # 使用SHA-256进行散列加密 -@guan.statistics_decorator def encryption_SHA_256(password, salt=''): import hashlib password = salt+password diff --git a/PyPI/src/guan/decorator.py b/PyPI/src/guan/decorators.py similarity index 93% rename from PyPI/src/guan/decorator.py rename to PyPI/src/guan/decorators.py index e53e8f1..bd53c6e 100644 --- a/PyPI/src/guan/decorator.py +++ b/PyPI/src/guan/decorators.py @@ -1,3 +1,5 @@ +# Module: decorators + # 函数的装饰器,用于获取计算时间(秒) def timer_decorator(func): import time @@ -31,7 +33,7 @@ def timer_decorator_hours(func): return result return wrapper -# 函数的装饰器,用于GUAN软件包的统计 +# 函数的装饰器,用于GUAN软件包函数的使用统计 def statistics_decorator(func): def wrapper(*args, **kwargs): result = func(*args, **kwargs) diff --git a/PyPI/src/guan/density_of_states.py b/PyPI/src/guan/density_of_states.py index 04690e3..cba70ca 100644 --- a/PyPI/src/guan/density_of_states.py +++ b/PyPI/src/guan/density_of_states.py @@ -1,8 +1,6 @@ # Module: density_of_states -import guan # 计算体系的总态密度 -@guan.statistics_decorator def total_density_of_states(fermi_energy, hamiltonian, broadening=0.01): import numpy as np import math @@ -12,7 +10,6 @@ def total_density_of_states(fermi_energy, hamiltonian, broadening=0.01): return total_dos # 对于不同费米能,计算体系的总态密度 -@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 +24,6 @@ def total_density_of_states_with_fermi_energy_array(fermi_energy_array, hamilton return total_dos_array # 计算方格子的局域态密度(其中,哈密顿量的维度为:dim_hamiltonian = N1*N2*internal_degree) -@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 +37,6 @@ def local_density_of_states_for_square_lattice(fermi_energy, hamiltonian, N1, N2 return local_dos # 计算立方格子的局域态密度(其中,哈密顿量的维度为:dim_hamiltonian = N1*N2*N3*internal_degree) -@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 +51,6 @@ def local_density_of_states_for_cubic_lattice(fermi_energy, hamiltonian, N1, N2, return local_dos # 使用Dyson方程,计算方格子的局域态密度(其中,h00的维度为:dim_h00 = N2*internal_degree) -@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 +84,6 @@ def local_density_of_states_for_square_lattice_using_dyson_equation(fermi_energy return local_dos # 使用Dyson方程,计算方格子的局域态密度,方法二(其中,h00的维度为:dim_h00 = N2*internal_degree) -@guan.statistics_decorator def local_density_of_states_for_square_lattice_using_dyson_equation_with_second_method(fermi_energy, h00, h01, N2, N1, internal_degree=1, broadening=0.01): import numpy as np import math @@ -125,7 +118,6 @@ def local_density_of_states_for_square_lattice_using_dyson_equation_with_second_ return local_dos # 使用Dyson方程,计算立方格子的局域态密度(其中,h00的维度为:dim_h00 = N2*N3*internal_degree) -@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 @@ -160,7 +152,6 @@ def local_density_of_states_for_cubic_lattice_using_dyson_equation(fermi_energy, return local_dos # 使用Dyson方程,计算方格子条带(考虑了电极自能)的局域态密度(其中,h00的维度为:dim_h00 = N2*internal_degree) -@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 diff --git a/PyPI/src/guan/figure_plotting.py b/PyPI/src/guan/figure_plotting.py index e3cf17d..08fc628 100644 --- a/PyPI/src/guan/figure_plotting.py +++ b/PyPI/src/guan/figure_plotting.py @@ -1,8 +1,6 @@ # Module: figure_plotting -import guan # 导入plt, fig, ax -@guan.statistics_decorator def import_plt_and_start_fig_ax(adjust_bottom=0.2, adjust_left=0.2, labelsize=20, fontfamily='Times New Roman'): import matplotlib.pyplot as plt fig, ax = plt.subplots() @@ -15,7 +13,6 @@ 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.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, fontfamily='Times New Roman'): if color==None: ax.plot(x_array, y_array, style, linewidth=linewidth, markersize=markersize) @@ -37,7 +34,6 @@ def plot_without_starting_fig(plt, fig, ax, x_array, y_array, xlabel='x', ylabel ax.set_ylim(y_min, y_max) # 画图 -@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, fontfamily='Times New Roman'): import guan plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize, fontfamily=fontfamily) @@ -63,7 +59,6 @@ def plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labels plt.close('all') # 一组横坐标数据,两组纵坐标数据画图 -@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, fontfamily='Times New Roman'): import guan plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize, fontfamily=fontfamily) @@ -94,7 +89,6 @@ def plot_two_array(x_array, y1_array, y2_array, xlabel='x', ylabel='y', title='' plt.close('all') # 两组横坐标数据,两组纵坐标数据画图 -@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, fontfamily='Times New Roman'): import guan plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize, fontfamily=fontfamily) @@ -125,7 +119,6 @@ def plot_two_array_with_two_horizontal_array(x1_array, x2_array, y1_array, y2_ar plt.close('all') # 一组横坐标数据,三组纵坐标数据画图 -@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, fontfamily='Times New Roman'): import guan plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize, fontfamily=fontfamily) @@ -159,7 +152,6 @@ def plot_three_array(x_array, y1_array, y2_array, y3_array, xlabel='x', ylabel=' plt.close('all') # 三组横坐标数据,三组纵坐标数据画图 -@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, fontfamily='Times New Roman'): import guan plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize, fontfamily=fontfamily) @@ -193,7 +185,6 @@ def plot_three_array_with_three_horizontal_array(x1_array, x2_array, x3_array, y plt.close('all') # 画三维图 -@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, fontfamily='Times New Roman'): import numpy as np import matplotlib.pyplot as plt @@ -243,7 +234,6 @@ def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z' plt.close('all') # 画Contour图 -@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, fontfamily='Times New Roman'): import numpy as np import matplotlib.pyplot as plt @@ -276,7 +266,6 @@ def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', fon plt.close('all') # 画棋盘图/伪彩色图 -@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, fontfamily='Times New Roman'): import numpy as np import matplotlib.pyplot as plt @@ -309,7 +298,6 @@ def plot_pcolor(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', font plt.close('all') # 通过坐标画点和线 -@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 @@ -337,7 +325,6 @@ def draw_dots_and_lines(coordinate_array, draw_dots=1, draw_lines=1, max_distanc plt.savefig(filename+file_format, dpi=dpi) # 合并两个图片 -@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] @@ -363,7 +350,6 @@ def combine_two_images(image_path_array, figsize=(16,8), show=0, save=1, filenam plt.close('all') # 合并三个图片 -@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] @@ -393,7 +379,6 @@ def combine_three_images(image_path_array, figsize=(16,5), show=0, save=1, filen plt.close('all') # 合并四个图片 -@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] @@ -427,7 +412,6 @@ def combine_four_images(image_path_array, figsize=(16,16), show=0, save=1, filen plt.close('all') # 对某个目录中的txt文件批量读取和画图 -@guan.statistics_decorator def batch_reading_and_plotting(directory, xlabel='x', ylabel='y'): import re import os @@ -440,7 +424,6 @@ 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.statistics_decorator def make_gif(image_path_array, filename='a', duration=0.1): import imageio images = [] @@ -450,7 +433,6 @@ def make_gif(image_path_array, filename='a', duration=0.1): imageio.mimsave(filename+'.gif', images, 'GIF', duration=duration) # 选取Matplotlib颜色 -@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 \ No newline at end of file diff --git a/PyPI/src/guan/file_reading_and_writing.py b/PyPI/src/guan/file_reading_and_writing.py index cfd2ce9..9b8f42a 100644 --- a/PyPI/src/guan/file_reading_and_writing.py +++ b/PyPI/src/guan/file_reading_and_writing.py @@ -1,15 +1,12 @@ # Module: file_reading_and_writing -import guan # 使用pickle将变量保存到文件(支持几乎所有对象类型) -@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) # 使用pickle从文件中恢复数据到变量(支持几乎所有对象类型) -@guan.statistics_decorator def load_data(filename, file_format='.txt'): import pickle with open(filename+file_format, 'rb') as f: @@ -17,40 +14,34 @@ def load_data(filename, file_format='.txt'): return data # 使用NumPy保存数组变量到npy文件(二进制文件) -@guan.statistics_decorator def save_npy_data(data, filename): import numpy as np np.save(filename+'.npy', data) # 使用NumPy从npy文件恢复数据到数组变量(二进制文件) -@guan.statistics_decorator def load_npy_data(filename): import numpy as np data = np.load(filename+'.npy') return data # 使用NumPy保存数组变量到TXT文件(文本文件) -@guan.statistics_decorator def save_txt_data(data, filename): import numpy as np np.savetxt(filename+'.txt', data) # 使用NumPy从TXT文件恢复数据到数组变量(文本文件) -@guan.statistics_decorator def load_txt_data(filename): import numpy as np data = np.loadtxt(filename+'.txt') return data # 如果不存在文件夹,则新建文件夹 -@guan.statistics_decorator def make_directory(directory='./test'): import os if not os.path.exists(directory): os.makedirs(directory) # 如果不存在文件,则新建空文件 -@guan.statistics_decorator def make_file(file_path='./a.txt'): import os if not os.path.exists(file_path): @@ -58,7 +49,6 @@ def make_file(file_path='./a.txt'): pass # 打开文件用于写入,默认为新增内容 -@guan.statistics_decorator def open_file(filename='a', file_format='.txt', mode='add'): if mode == 'add': f = open(filename+file_format, 'a', encoding='UTF-8') @@ -67,7 +57,6 @@ def open_file(filename='a', file_format='.txt', mode='add'): return f # 读取文本文件内容,如果不存在,则新建空文件,并返回空字符串 -@guan.statistics_decorator def read_text_file(file_path='./a.txt'): import os if not os.path.exists(file_path): @@ -80,7 +69,6 @@ def read_text_file(file_path='./a.txt'): return content # 获取目录中的所有文件名 -@guan.statistics_decorator def get_all_filenames_in_directory(directory='./', file_format=None): import os file_list = [] @@ -94,7 +82,6 @@ def get_all_filenames_in_directory(directory='./', file_format=None): return file_list # 获取目录中的所有文件名(不包括子目录) -@guan.statistics_decorator def get_all_filenames_in_directory_without_subdirectory(directory='./', file_format=None): import os file_list = [] @@ -109,7 +96,6 @@ def get_all_filenames_in_directory_without_subdirectory(directory='./', file_for return file_list # 获取文件夹中某种文本类型的文件以及读取所有内容 -@guan.statistics_decorator def read_text_files_in_directory(directory='./', file_format='.md'): import os file_list = [] @@ -124,7 +110,6 @@ def read_text_files_in_directory(directory='./', file_format='.md'): return file_list, content_array # 在多个文本文件中查找关键词 -@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) @@ -136,13 +121,11 @@ def find_words_in_multiple_files(words, directory='./', file_format='.md'): return file_list_with_words # 复制一份文件 -@guan.statistics_decorator def copy_file(file1='./a.txt', file2='./b.txt'): import shutil shutil.copy(file1, file2) # 打开文件,替代某字符串 -@guan.statistics_decorator def open_file_and_replace_str(file_path='./a.txt', old_str='', new_str=''): import guan content = guan.read_text_file(file_path=file_path) @@ -152,7 +135,6 @@ def open_file_and_replace_str(file_path='./a.txt', old_str='', new_str=''): f.close() # 复制一份文件,然后再替代某字符串 -@guan.statistics_decorator def copy_file_and_replace_str(old_file='./a.txt', new_file='./b.txt', old_str='', new_str=''): import guan guan.copy_file(file1=old_file, file2=new_file) @@ -163,7 +145,6 @@ def copy_file_and_replace_str(old_file='./a.txt', new_file='./b.txt', old_str='' f.close() # 拼接两个PDF文件 -@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() @@ -179,7 +160,6 @@ def combine_two_pdf_files(input_file_1='a.pdf', input_file_2='b.pdf', output_fil output_pdf.write(combined_file) # 读取文件中的一维数据(一行一组x和y) -@guan.statistics_decorator def read_one_dimensional_data(filename='a', file_format='.txt'): import numpy as np f = open(filename+file_format, 'r') @@ -203,7 +183,6 @@ def read_one_dimensional_data(filename='a', file_format='.txt'): return x_array, y_array # 读取文件中的一维数据(一行一组x和y)(支持复数形式) -@guan.statistics_decorator def read_one_dimensional_complex_data(filename='a', file_format='.txt'): import numpy as np f = open(filename+file_format, 'r') @@ -227,7 +206,6 @@ def read_one_dimensional_complex_data(filename='a', file_format='.txt'): return x_array, y_array # 读取文件中的二维数据(第一行和第一列分别为横纵坐标) -@guan.statistics_decorator def read_two_dimensional_data(filename='a', file_format='.txt'): import numpy as np f = open(filename+file_format, 'r') @@ -257,7 +235,6 @@ def read_two_dimensional_data(filename='a', file_format='.txt'): return x_array, y_array, matrix # 读取文件中的二维数据(第一行和第一列分别为横纵坐标)(支持复数形式) -@guan.statistics_decorator def read_two_dimensional_complex_data(filename='a', file_format='.txt'): import numpy as np f = open(filename+file_format, 'r') @@ -287,21 +264,18 @@ def read_two_dimensional_complex_data(filename='a', file_format='.txt'): return x_array, y_array, matrix # 读取文件中的二维数据(不包括x和y) -@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 # 在文件中写入一维数据(一行一组x和y) -@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.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) @@ -318,14 +292,12 @@ def write_one_dimensional_data_without_opening_file(x_array, y_array, f): i0 += 1 # 在文件中写入二维数据(第一行和第一列分别为横纵坐标) -@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.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) @@ -346,14 +318,12 @@ def write_two_dimensional_data_without_opening_file(x_array, y_array, matrix, f) i0 += 1 # 在文件中写入二维数据(不包括x和y) -@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.statistics_decorator def write_two_dimensional_data_without_xy_array_and_without_opening_file(matrix, f): for row in matrix: for element in row: diff --git a/PyPI/src/guan/machine_learning.py b/PyPI/src/guan/machine_learning.py index 8f77803..96c94d3 100644 --- a/PyPI/src/guan/machine_learning.py +++ b/PyPI/src/guan/machine_learning.py @@ -1,8 +1,6 @@ # Module: machine_learning -import guan # 全连接神经网络模型(包含一个隐藏层)(模型的类定义成全局的) -@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 +26,6 @@ def fully_connected_neural_network_with_one_hidden_layer(input_size=1, hidden_si return model # 全连接神经网络模型(包含两个隐藏层)(模型的类定义成全局的) -@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 +64,6 @@ def fully_connected_neural_network_with_two_hidden_layers(input_size=1, hidden_s return model # 全连接神经网络模型(包含三个隐藏层)(模型的类定义成全局的) -@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 +114,6 @@ def fully_connected_neural_network_with_three_hidden_layers(input_size=1, hidden return model # 使用优化器训练模型 -@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': @@ -144,7 +139,6 @@ def train_model(model, x_data, y_data, optimizer='Adam', learning_rate=0.001, cr return model, losses # 使用优化器批量训练模型 -@guan.statistics_decorator def batch_train_model(model, train_loader, optimizer='Adam', learning_rate=0.001, criterion='MSELoss', num_epochs=1000, print_show=1): import torch if optimizer == 'Adam': @@ -171,33 +165,28 @@ def batch_train_model(model, train_loader, optimizer='Adam', learning_rate=0.001 return model, losses # 保存模型参数到文件 -@guan.statistics_decorator def save_model_parameters(model, filename='./model_parameters.pth'): import torch torch.save(model.state_dict(), filename) # 保存完整模型到文件(保存时需要模型的类可访问) -@guan.statistics_decorator def save_model(model, filename='./model.pth'): import torch torch.save(model, filename) # 加载模型参数(需要输入模型,加载后,原输入的模型参数也会改变) -@guan.statistics_decorator def load_model_parameters(model, filename='./model_parameters.pth'): import torch model.load_state_dict(torch.load(filename)) return model # 加载完整模型(不需要输入模型,但加载时需要原定义的模型的类可访问) -@guan.statistics_decorator def load_model(filename='./model.pth'): import torch model = torch.load(filename) return model # 加载训练数据,用于批量加载训练 -@guan.statistics_decorator def load_train_data(x_train, y_train, batch_size=32): from torch.utils.data import DataLoader, TensorDataset train_dataset = TensorDataset(x_train, y_train) diff --git a/PyPI/src/guan/others.py b/PyPI/src/guan/others.py index c18d916..da7109d 100644 --- a/PyPI/src/guan/others.py +++ b/PyPI/src/guan/others.py @@ -1,5 +1,4 @@ # Module: others -import guan # 获取当前日期字符串 def get_date(bar=True): @@ -18,7 +17,6 @@ def get_time(colon=True): return datetime_time # 自动先后运行程序 -@guan.statistics_decorator def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='python ', show_time=0): import os import time @@ -38,14 +36,12 @@ def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='pytho print('Total running time = '+str((end-start)/60)+' min') # 获取CPU使用率 -@guan.statistics_decorator def get_cpu_usage(interval=1): import psutil cpu_usage = psutil.cpu_percent(interval=interval) return cpu_usage # 获取内存信息 -@guan.statistics_decorator def get_memory_info(): import psutil memory_info = psutil.virtual_memory() @@ -56,7 +52,6 @@ def get_memory_info(): return total_memory, used_memory, available_memory, used_memory_percent # 将WordPress导出的XML格式文件转换成多个MarkDown格式的文件 -@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 @@ -94,7 +89,6 @@ def convert_wordpress_xml_to_markdown(xml_file='./a.xml', convert_content=1, rep md_file.write(markdown_content) # 获取运行的日期和时间并写入文件 -@guan.statistics_decorator def statistics_with_day_and_time(content='', filename='a', file_format='.txt'): import datetime datetime_today = str(datetime.date.today()) @@ -106,7 +100,6 @@ def statistics_with_day_and_time(content='', filename='a', file_format='.txt'): f2.write(datetime_today+' '+datetime_time+' '+content+'\n') # 统计Python文件中import的数量并排序 -@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() @@ -120,7 +113,6 @@ def count_number_of_import_statements(filename, file_format='.py', num=1000): return import_statement_counter # 获取本月的所有日期 -@guan.statistics_decorator def get_days_of_the_current_month(str_or_datetime='str'): import datetime today = datetime.date.today() @@ -140,7 +132,6 @@ def get_days_of_the_current_month(str_or_datetime='str'): return day_array # 获取上个月份 -@guan.statistics_decorator def get_last_month(): import datetime today = datetime.date.today() @@ -153,7 +144,6 @@ def get_last_month(): return year_of_last_month, last_month # 获取上上个月份 -@guan.statistics_decorator def get_the_month_before_last(): import datetime today = datetime.date.today() @@ -171,7 +161,6 @@ def get_the_month_before_last(): return year_of_the_month_before_last, the_month_before_last # 获取上个月的所有日期 -@guan.statistics_decorator def get_days_of_the_last_month(str_or_datetime='str'): import datetime import guan @@ -193,7 +182,6 @@ def get_days_of_the_last_month(str_or_datetime='str'): return day_array # 获取上上个月的所有日期 -@guan.statistics_decorator def get_days_of_the_month_before_last(str_or_datetime='str'): import datetime import guan @@ -215,7 +203,6 @@ def get_days_of_the_month_before_last(str_or_datetime='str'): return day_array # 获取所有股票 -@guan.statistics_decorator def all_stocks(): import numpy as np import akshare as ak @@ -225,7 +212,6 @@ def all_stocks(): return title, stock_data # 获取所有股票的代码 -@guan.statistics_decorator def all_stock_symbols(): import guan title, stock_data = guan.all_stocks() @@ -233,7 +219,6 @@ def all_stock_symbols(): return stock_symbols # 股票代码的分类 -@guan.statistics_decorator def stock_symbols_classification(): import guan import re @@ -290,7 +275,6 @@ def stock_symbols_classification(): return stock_symbols_60, stock_symbols_00, stock_symbols_30, stock_symbols_68, stock_symbols_8_4, stock_symbols_others # 股票代码各个分类的数量 -@guan.statistics_decorator def statistics_of_stock_symbols_classification(): import guan stock_symbols_60, stock_symbols_00, stock_symbols_30, stock_symbols_68, stock_symbols_8_4, stock_symbols_others = guan.stock_symbols_classification() @@ -303,7 +287,6 @@ def statistics_of_stock_symbols_classification(): return num_stocks_60, num_stocks_00, num_stocks_30, num_stocks_68, num_stocks_8_4, num_stocks_others # 从股票代码获取股票名称 -@guan.statistics_decorator def find_stock_name_from_symbol(symbol='000002'): import guan title, stock_data = guan.all_stocks() @@ -313,7 +296,6 @@ def find_stock_name_from_symbol(symbol='000002'): return stock_name # 市值排序 -@guan.statistics_decorator def sorted_market_capitalization(num=10): import numpy as np import guan @@ -338,7 +320,6 @@ def sorted_market_capitalization(num=10): return sorted_array # 美股市值排序 -@guan.statistics_decorator def sorted_market_capitalization_us(num=10): import akshare as ak import numpy as np @@ -364,7 +345,6 @@ def sorted_market_capitalization_us(num=10): return sorted_array # 获取单个股票的历史数据 -@guan.statistics_decorator def history_data_of_one_stock(symbol='000002', period='daily', start_date="19000101", end_date='21000101'): # period = 'daily' # period = 'weekly' @@ -377,7 +357,6 @@ def history_data_of_one_stock(symbol='000002', period='daily', start_date="19000 return title, stock_data # 绘制股票图 -@guan.statistics_decorator def plot_stock_line(date_array, opening_array, closing_array, high_array, low_array, lw_open_close=6, lw_high_low=2, xlabel='date', ylabel='price', title='', fontsize=20, labelsize=20, 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) @@ -395,7 +374,6 @@ def plot_stock_line(date_array, opening_array, closing_array, high_array, low_ar plt.close('all') # 获取软件包中的所有模块名 -@guan.statistics_decorator def get_all_modules_in_one_package(package_name='guan'): import pkgutil package = __import__(package_name) @@ -403,7 +381,6 @@ def get_all_modules_in_one_package(package_name='guan'): return module_names # 获取软件包中一个模块的所有函数名 -@guan.statistics_decorator def get_all_functions_in_one_module(module_name, package_name='guan'): import inspect function_names = [] @@ -414,7 +391,6 @@ def get_all_functions_in_one_module(module_name, package_name='guan'): return function_names # 获取软件包中的所有函数名 -@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) @@ -432,7 +408,6 @@ def get_all_functions_in_one_package(package_name='guan', print_show=1): return all_function_names # 获取包含某个字符的进程PID值 -@guan.statistics_decorator def get_PID(name): import subprocess command = "ps -ef | grep "+name @@ -445,14 +420,12 @@ def get_PID(name): return id_running # 获取函数的源码 -@guan.statistics_decorator def get_function_source(function_name): import inspect function_source = inspect.getsource(function_name) return function_source # 查找文件名相同的文件 -@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 @@ -477,7 +450,6 @@ def find_repeated_file_with_same_filename(directory='./', ignored_directory_with return repeated_file # 统计各个子文件夹中的文件数量 -@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 @@ -531,7 +503,6 @@ def count_file_in_sub_directory(directory='./', sort=0, reverse=1, print_show=1, return sub_directory, num_in_sub_directory # 改变当前的目录位置 -@guan.statistics_decorator def change_directory_by_replacement(current_key_word='code', new_key_word='data'): import os code_path = os.getcwd() @@ -542,7 +513,6 @@ def change_directory_by_replacement(current_key_word='code', new_key_word='data' os.chdir(data_path) # 在多个子文件夹中产生必要的文件,例如 readme.md -@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 = [] @@ -571,8 +541,7 @@ def creat_necessary_file(directory, filename='readme', file_format='.md', conten f.write(content) f.close() -# 删除特定文件名的文件(慎用) -@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): @@ -580,8 +549,7 @@ def delete_file_with_specific_name(directory, filename='readme', file_format='.m if files[i0] == filename+file_format: os.remove(root+'/'+files[i0]) -# 将所有文件移到根目录(慎用) -@guan.statistics_decorator +# 将所有文件移到根目录(谨慎使用) def move_all_files_to_root_directory(directory): import os import shutil @@ -596,7 +564,6 @@ def move_all_files_to_root_directory(directory): pass # 将文件目录结构写入Markdown文件 -@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") @@ -700,7 +667,6 @@ def write_file_list_in_markdown(directory='./', filename='a', reverse_positive_o f.close() # 从网页的标签中获取内容 -@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 @@ -719,14 +685,12 @@ def get_html_from_tags(link, tags=['title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', return content # 生成二维码 -@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.statistics_decorator def pdf_to_text(pdf_path): from pdfminer.pdfparser import PDFParser, PDFDocument from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter @@ -758,7 +722,6 @@ def pdf_to_text(pdf_path): return content # 获取PDF文件页数 -@guan.statistics_decorator def get_pdf_page_number(pdf_path): import PyPDF2 pdf_file = open(pdf_path, 'rb') @@ -767,7 +730,6 @@ def get_pdf_page_number(pdf_path): return num_pages # 获取PDF文件指定页面的内容 -@guan.statistics_decorator def pdf_to_txt_for_a_specific_page(pdf_path, page_num=1): import PyPDF2 pdf_file = open(pdf_path, 'rb') @@ -781,7 +743,6 @@ def pdf_to_txt_for_a_specific_page(pdf_path, page_num=1): return page_text # 获取PDF文献中的链接。例如: link_starting_form='https://doi.org' -@guan.statistics_decorator def get_links_from_pdf(pdf_path, link_starting_form=''): import PyPDF2 import re @@ -806,7 +767,6 @@ def get_links_from_pdf(pdf_path, link_starting_form=''): return links # 通过Sci-Hub网站下载文献 -@guan.statistics_decorator def download_with_scihub(address=None, num=1): from bs4 import BeautifulSoup import re @@ -844,7 +804,6 @@ def download_with_scihub(address=None, num=1): print('All completed!\n') # 将字符串转成音频 -@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 @@ -868,7 +827,6 @@ def str_to_audio(str='hello world', filename='str', rate=125, voice=1, read=1, s engine.runAndWait() # 将txt文件转成音频 -@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 @@ -896,7 +854,6 @@ def txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, compress=0, bitrat engine.runAndWait() # 将PDF文件转成音频 -@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 @@ -924,7 +881,6 @@ def pdf_to_audio(pdf_path, rate=125, voice=1, read=1, save=0, compress=0, bitrat engine.runAndWait() # 将wav音频文件压缩成MP3音频文件 -@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 @@ -946,7 +902,6 @@ def get_calling_function_name(layer=1): return calling_function_name # 获取Python软件包的最新版本 -@guan.statistics_decorator def get_latest_version(package_name='guan', timeout=5): import requests url = f"https://pypi.org/pypi/{package_name}/json" @@ -971,7 +926,6 @@ def get_current_version(package_name='guan'): return None # Guan软件包升级检查和提示 -@guan.statistics_decorator def notification_of_upgrade(timeout=5): try: import guan @@ -983,26 +937,27 @@ def notification_of_upgrade(timeout=5): except: pass -# Guan软件包的使用统计(不涉及到用户的个人数据) -global_variable_of_first_guan_package_calling = [] +# Guan软件包的使用统计 def statistics_of_guan_package(function_name=None): import guan - if function_name == None: - function_name = guan.get_calling_function_name(layer=2) - else: - pass - 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) - try: - import socket - datetime_date = guan.get_date() - datetime_time = guan.get_time() - current_version = guan.get_current_version('guan') - client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) - client_socket.settimeout(0.5) - client_socket.connect(('socket.guanjihuan.com', 12345)) - mac_address = guan.get_mac_address() + try: + import socket + datetime_date = guan.get_date() + datetime_time = guan.get_time() + current_version = guan.get_current_version('guan') + client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) + client_socket.settimeout(0.5) + client_socket.connect(('socket.guanjihuan.com', 12345)) + mac_address = guan.get_mac_address() + if function_name == None: + message = { + 'server': 'py.guanjihuan.com', + 'date': datetime_date, + 'time': datetime_time, + 'version': current_version, + 'MAC_address': mac_address, + } + else: message = { 'server': 'py.guanjihuan.com', 'date': datetime_date, @@ -1011,9 +966,11 @@ def statistics_of_guan_package(function_name=None): 'MAC_address': mac_address, 'function_name': function_name } - import json - send_message = json.dumps(message) - client_socket.send(send_message.encode()) - client_socket.close() - except: - pass + import json + send_message = json.dumps(message) + client_socket.send(send_message.encode()) + client_socket.close() + except: + pass + +statistics_of_guan_package(function_name=None) \ No newline at end of file diff --git a/PyPI/src/guan/quantum_transport.py b/PyPI/src/guan/quantum_transport.py index d147e21..4cb9f40 100644 --- a/PyPI/src/guan/quantum_transport.py +++ b/PyPI/src/guan/quantum_transport.py @@ -1,8 +1,6 @@ # Module: quantum_transport -import guan # 计算电导 -@guan.statistics_decorator def calculate_conductance(fermi_energy, h00, h01, length=100): import numpy as np import copy @@ -22,7 +20,6 @@ def calculate_conductance(fermi_energy, h00, h01, length=100): return conductance # 计算不同费米能下的电导 -@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 +34,6 @@ def calculate_conductance_with_fermi_energy_array(fermi_energy_array, h00, h01, return conductance_array # 计算在势垒散射下的电导 -@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 +57,6 @@ def calculate_conductance_with_barrier(fermi_energy, h00, h01, length=100, barri return conductance # 计算在无序散射下的电导 -@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 +85,6 @@ def calculate_conductance_with_disorder(fermi_energy, h00, h01, disorder_intensi return conductance_averaged # 计算在无序散射下的电导(需要输入无序数组) -@guan.statistics_decorator def calculate_conductance_with_disorder_array(fermi_energy, h00, h01, disorder_array, length=100): import numpy as np import copy @@ -114,7 +108,6 @@ def calculate_conductance_with_disorder_array(fermi_energy, h00, h01, disorder_a return conductance # 计算在无序垂直切片的散射下的电导 -@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 @@ -138,7 +131,6 @@ def calculate_conductance_with_slice_disorder(fermi_energy, h00, h01, disorder_i return conductance # 计算在无序水平切片的散射下的电导 -@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 @@ -163,7 +155,6 @@ def calculate_conductance_with_disorder_inside_unit_cell_which_keeps_translation return conductance # 计算在随机空位的散射下的电导 -@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 @@ -188,7 +179,6 @@ def calculate_conductance_with_random_vacancy(fermi_energy, h00, h01, vacancy_co return conductance # 计算在不同无序散射强度下的电导 -@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 @@ -205,7 +195,6 @@ def calculate_conductance_with_disorder_intensity_array(fermi_energy, h00, h01, return conductance_array # 计算在不同无序浓度下的电导 -@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 @@ -222,7 +211,6 @@ def calculate_conductance_with_disorder_concentration_array(fermi_energy, h00, h return conductance_array # 计算在不同无序散射长度下的电导 -@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 @@ -239,7 +227,6 @@ def calculate_conductance_with_scattering_length_array(fermi_energy, h00, h01, l return conductance_array # 计算得到Gamma矩阵和格林函数,用于计算六端口的量子输运 -@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 @@ -286,7 +273,6 @@ def get_gamma_array_and_green_for_six_terminal_transmission(fermi_energy, h00_fo return gamma_array, green # 计算六端口的透射矩阵 -@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 @@ -311,7 +297,6 @@ def calculate_six_terminal_transmission_matrix(fermi_energy, h00_for_lead_4, h01 return transmission_matrix # 计算从电极1出发的透射系数 -@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 @@ -324,7 +309,6 @@ 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.statistics_decorator def if_active_channel(k_of_channel): import numpy as np if np.abs(np.imag(k_of_channel))<1e-6: @@ -334,7 +318,6 @@ def if_active_channel(k_of_channel): return if_active # 获取通道的动量和速度,用于计算散射矩阵 -@guan.statistics_decorator def get_k_and_velocity_of_channel(fermi_energy, h00, h01): import numpy as np import math @@ -371,7 +354,6 @@ def get_k_and_velocity_of_channel(fermi_energy, h00, h01): return k_of_channel, velocity_of_channel, eigenvalue, eigenvector # 获取分类后的动量和速度,以及U和F,用于计算散射矩阵 -@guan.statistics_decorator def get_classified_k_velocity_u_and_f(fermi_energy, h00, h01): import numpy as np import guan @@ -424,7 +406,6 @@ 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.statistics_decorator def calculate_scattering_matrix(fermi_energy, h00, h01, length=100): import numpy as np import math @@ -470,7 +451,6 @@ 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.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==(): @@ -492,7 +472,6 @@ 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.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) @@ -502,7 +481,6 @@ 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.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) @@ -547,7 +525,6 @@ def print_or_write_scattering_matrix_with_information_of_scattering_matrix(numbe f.write('Total conductance = '+str(total_conductance)+'\n') # 已知h00和h01,计算散射矩阵并打印出散射矩阵的信息 -@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) @@ -557,7 +534,6 @@ 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.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 @@ -607,7 +583,6 @@ 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.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 diff --git a/PyPI/src/guan/topological_invariant.py b/PyPI/src/guan/topological_invariant.py index ade4304..0449475 100644 --- a/PyPI/src/guan/topological_invariant.py +++ b/PyPI/src/guan/topological_invariant.py @@ -1,8 +1,6 @@ # Module: topological_invariant -import guan # 通过高效法计算方格子的陈数 -@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 +39,6 @@ def calculate_chern_number_for_square_lattice_with_efficient_method(hamiltonian_ return chern_number # 通过高效法计算方格子的陈数(可计算简并的情况) -@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 +108,6 @@ def calculate_chern_number_for_square_lattice_with_efficient_method_for_degenera return chern_number # 通过Wilson loop方法计算方格子的陈数 -@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 +152,6 @@ def calculate_chern_number_for_square_lattice_with_wilson_loop(hamiltonian_funct return chern_number # 通过Wilson loop方法计算方格子的陈数(可计算简并的情况) -@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 +215,6 @@ def calculate_chern_number_for_square_lattice_with_wilson_loop_for_degenerate_ca return chern_number # 通过高效法计算贝利曲率 -@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 +261,6 @@ def calculate_berry_curvature_with_efficient_method(hamiltonian_function, k_min= return k_array, berry_curvature_array # 通过高效法计算贝利曲率(可计算简并的情况) -@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 +339,6 @@ def calculate_berry_curvature_with_efficient_method_for_degenerate_case(hamilton return k_array, berry_curvature_array # 通过Wilson loop方法计算贝里曲率 -@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 +395,6 @@ def calculate_berry_curvature_with_wilson_loop(hamiltonian_function, k_min='defa return k_array, berry_curvature_array # 通过Wilson loop方法计算贝里曲率(可计算简并的情况) -@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 +466,6 @@ def calculate_berry_curvature_with_wilson_loop_for_degenerate_case(hamiltonian_f return k_array, berry_curvature_array # 计算蜂窝格子的陈数(高效法) -@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 +509,6 @@ def calculate_chern_number_for_honeycomb_lattice(hamiltonian_function, a=1, prec return chern_number # 计算Wilson loop -@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 diff --git a/README.md b/README.md index 962136c..2201a45 100755 --- a/README.md +++ b/README.md @@ -14,7 +14,6 @@ import guan ## Summary of API Reference -+ decorator + basic functions + Fourier transform + Hamiltonian of examples @@ -28,6 +27,7 @@ import guan + figure plotting + data processing + others ++ decorators ## About this package