0.1.48 增加装饰器
This commit is contained in:
parent
206fcda152
commit
7a9b86f791
@ -1,7 +1,7 @@
|
|||||||
[metadata]
|
[metadata]
|
||||||
# replace with your username:
|
# replace with your username:
|
||||||
name = guan
|
name = guan
|
||||||
version = 0.1.47
|
version = 0.1.48
|
||||||
author = guanjihuan
|
author = guanjihuan
|
||||||
author_email = guanjihuan@163.com
|
author_email = guanjihuan@163.com
|
||||||
description = An open source python package
|
description = An open source python package
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
Metadata-Version: 2.1
|
Metadata-Version: 2.1
|
||||||
Name: guan
|
Name: guan
|
||||||
Version: 0.1.47
|
Version: 0.1.48
|
||||||
Summary: An open source python package
|
Summary: An open source python package
|
||||||
Home-page: https://py.guanjihuan.com
|
Home-page: https://py.guanjihuan.com
|
||||||
Author: guanjihuan
|
Author: guanjihuan
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
# Module: Fourier_transform
|
# Module: Fourier_transform
|
||||||
|
import guan
|
||||||
|
|
||||||
# 通过元胞和跃迁项得到一维的哈密顿量(需要输入k值)
|
# 通过元胞和跃迁项得到一维的哈密顿量(需要输入k值)
|
||||||
|
@guan.function_decorator
|
||||||
def one_dimensional_fourier_transform(k, unit_cell, hopping):
|
def one_dimensional_fourier_transform(k, unit_cell, hopping):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
unit_cell = np.array(unit_cell)
|
unit_cell = np.array(unit_cell)
|
||||||
hopping = np.array(hopping)
|
hopping = np.array(hopping)
|
||||||
hamiltonian = unit_cell+hopping*cmath.exp(1j*k)+hopping.transpose().conj()*cmath.exp(-1j*k)
|
hamiltonian = unit_cell+hopping*cmath.exp(1j*k)+hopping.transpose().conj()*cmath.exp(-1j*k)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 通过元胞和跃迁项得到二维方格子的哈密顿量(需要输入k值)
|
# 通过元胞和跃迁项得到二维方格子的哈密顿量(需要输入k值)
|
||||||
|
@guan.function_decorator
|
||||||
def two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell, hopping_1, hopping_2):
|
def two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell, hopping_1, hopping_2):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -19,11 +20,10 @@ def two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell, hopp
|
|||||||
hopping_1 = np.array(hopping_1)
|
hopping_1 = np.array(hopping_1)
|
||||||
hopping_2 = np.array(hopping_2)
|
hopping_2 = np.array(hopping_2)
|
||||||
hamiltonian = unit_cell+hopping_1*cmath.exp(1j*k1)+hopping_1.transpose().conj()*cmath.exp(-1j*k1)+hopping_2*cmath.exp(1j*k2)+hopping_2.transpose().conj()*cmath.exp(-1j*k2)
|
hamiltonian = unit_cell+hopping_1*cmath.exp(1j*k1)+hopping_1.transpose().conj()*cmath.exp(-1j*k1)+hopping_2*cmath.exp(1j*k2)+hopping_2.transpose().conj()*cmath.exp(-1j*k2)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 通过元胞和跃迁项得到三维立方格子的哈密顿量(需要输入k值)
|
# 通过元胞和跃迁项得到三维立方格子的哈密顿量(需要输入k值)
|
||||||
|
@guan.function_decorator
|
||||||
def three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell, hopping_1, hopping_2, hopping_3):
|
def three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell, hopping_1, hopping_2, hopping_3):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -32,43 +32,41 @@ def three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell,
|
|||||||
hopping_2 = np.array(hopping_2)
|
hopping_2 = np.array(hopping_2)
|
||||||
hopping_3 = np.array(hopping_3)
|
hopping_3 = np.array(hopping_3)
|
||||||
hamiltonian = unit_cell+hopping_1*cmath.exp(1j*k1)+hopping_1.transpose().conj()*cmath.exp(-1j*k1)+hopping_2*cmath.exp(1j*k2)+hopping_2.transpose().conj()*cmath.exp(-1j*k2)+hopping_3*cmath.exp(1j*k3)+hopping_3.transpose().conj()*cmath.exp(-1j*k3)
|
hamiltonian = unit_cell+hopping_1*cmath.exp(1j*k1)+hopping_1.transpose().conj()*cmath.exp(-1j*k1)+hopping_2*cmath.exp(1j*k2)+hopping_2.transpose().conj()*cmath.exp(-1j*k2)+hopping_3*cmath.exp(1j*k3)+hopping_3.transpose().conj()*cmath.exp(-1j*k3)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 通过元胞和跃迁项得到一维的哈密顿量(返回的哈密顿量为携带k的函数)
|
# 通过元胞和跃迁项得到一维的哈密顿量(返回的哈密顿量为携带k的函数)
|
||||||
|
@guan.function_decorator
|
||||||
def one_dimensional_fourier_transform_with_k(unit_cell, hopping):
|
def one_dimensional_fourier_transform_with_k(unit_cell, hopping):
|
||||||
import functools
|
import functools
|
||||||
import guan
|
import guan
|
||||||
hamiltonian_function = functools.partial(guan.one_dimensional_fourier_transform, unit_cell=unit_cell, hopping=hopping)
|
hamiltonian_function = functools.partial(guan.one_dimensional_fourier_transform, unit_cell=unit_cell, hopping=hopping)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian_function
|
return hamiltonian_function
|
||||||
|
|
||||||
# 通过元胞和跃迁项得到二维方格子的哈密顿量(返回的哈密顿量为携带k的函数)
|
# 通过元胞和跃迁项得到二维方格子的哈密顿量(返回的哈密顿量为携带k的函数)
|
||||||
|
@guan.function_decorator
|
||||||
def two_dimensional_fourier_transform_for_square_lattice_with_k1_k2(unit_cell, hopping_1, hopping_2):
|
def two_dimensional_fourier_transform_for_square_lattice_with_k1_k2(unit_cell, hopping_1, hopping_2):
|
||||||
import functools
|
import functools
|
||||||
import guan
|
import guan
|
||||||
hamiltonian_function = functools.partial(guan.two_dimensional_fourier_transform_for_square_lattice, unit_cell=unit_cell, hopping_1=hopping_1, hopping_2=hopping_2)
|
hamiltonian_function = functools.partial(guan.two_dimensional_fourier_transform_for_square_lattice, unit_cell=unit_cell, hopping_1=hopping_1, hopping_2=hopping_2)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian_function
|
return hamiltonian_function
|
||||||
|
|
||||||
# 通过元胞和跃迁项得到三维立方格子的哈密顿量(返回的哈密顿量为携带k的函数)
|
# 通过元胞和跃迁项得到三维立方格子的哈密顿量(返回的哈密顿量为携带k的函数)
|
||||||
|
@guan.function_decorator
|
||||||
def three_dimensional_fourier_transform_for_cubic_lattice_with_k1_k2_k3(unit_cell, hopping_1, hopping_2, hopping_3):
|
def three_dimensional_fourier_transform_for_cubic_lattice_with_k1_k2_k3(unit_cell, hopping_1, hopping_2, hopping_3):
|
||||||
import functools
|
import functools
|
||||||
import guan
|
import guan
|
||||||
hamiltonian_function = functools.partial(guan.three_dimensional_fourier_transform_for_cubic_lattice, unit_cell=unit_cell, hopping_1=hopping_1, hopping_2=hopping_2, hopping_3=hopping_3)
|
hamiltonian_function = functools.partial(guan.three_dimensional_fourier_transform_for_cubic_lattice, unit_cell=unit_cell, hopping_1=hopping_1, hopping_2=hopping_2, hopping_3=hopping_3)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian_function
|
return hamiltonian_function
|
||||||
|
|
||||||
# 由实空间格矢得到倒空间格矢(一维)
|
# 由实空间格矢得到倒空间格矢(一维)
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_one_dimensional_reciprocal_lattice_vector(a1):
|
def calculate_one_dimensional_reciprocal_lattice_vector(a1):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
b1 = 2*np.pi/a1
|
b1 = 2*np.pi/a1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return b1
|
return b1
|
||||||
|
|
||||||
# 由实空间格矢得到倒空间格矢(二维)
|
# 由实空间格矢得到倒空间格矢(二维)
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2):
|
def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
a1 = np.array(a1)
|
a1 = np.array(a1)
|
||||||
@ -80,11 +78,10 @@ def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2):
|
|||||||
b2 = 2*np.pi*np.cross(a3, a1)/np.dot(a1, np.cross(a2, a3))
|
b2 = 2*np.pi*np.cross(a3, a1)/np.dot(a1, np.cross(a2, a3))
|
||||||
b1 = np.delete(b1, 2)
|
b1 = np.delete(b1, 2)
|
||||||
b2 = np.delete(b2, 2)
|
b2 = np.delete(b2, 2)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return b1, b2
|
return b1, b2
|
||||||
|
|
||||||
# 由实空间格矢得到倒空间格矢(三维)
|
# 由实空间格矢得到倒空间格矢(三维)
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3):
|
def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
a1 = np.array(a1)
|
a1 = np.array(a1)
|
||||||
@ -93,19 +90,17 @@ def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3):
|
|||||||
b1 = 2*np.pi*np.cross(a2, a3)/np.dot(a1, np.cross(a2, a3))
|
b1 = 2*np.pi*np.cross(a2, a3)/np.dot(a1, np.cross(a2, a3))
|
||||||
b2 = 2*np.pi*np.cross(a3, a1)/np.dot(a1, np.cross(a2, a3))
|
b2 = 2*np.pi*np.cross(a3, a1)/np.dot(a1, np.cross(a2, a3))
|
||||||
b3 = 2*np.pi*np.cross(a1, a2)/np.dot(a1, np.cross(a2, a3))
|
b3 = 2*np.pi*np.cross(a1, a2)/np.dot(a1, np.cross(a2, a3))
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return b1, b2, b3
|
return b1, b2, b3
|
||||||
|
|
||||||
# 由实空间格矢得到倒空间格矢(一维),这里为符号运算
|
# 由实空间格矢得到倒空间格矢(一维),这里为符号运算
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_one_dimensional_reciprocal_lattice_vector_with_sympy(a1):
|
def calculate_one_dimensional_reciprocal_lattice_vector_with_sympy(a1):
|
||||||
import sympy
|
import sympy
|
||||||
b1 = 2*sympy.pi/a1
|
b1 = 2*sympy.pi/a1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return b1
|
return b1
|
||||||
|
|
||||||
# 由实空间格矢得到倒空间格矢(二维),这里为符号运算
|
# 由实空间格矢得到倒空间格矢(二维),这里为符号运算
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_two_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2):
|
def calculate_two_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2):
|
||||||
import sympy
|
import sympy
|
||||||
a1 = sympy.Matrix(1, 3, [a1[0], a1[1], 0])
|
a1 = sympy.Matrix(1, 3, [a1[0], a1[1], 0])
|
||||||
@ -117,11 +112,10 @@ def calculate_two_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2):
|
|||||||
b2 = 2*sympy.pi*cross_a3_a1/a1.dot(cross_a2_a3)
|
b2 = 2*sympy.pi*cross_a3_a1/a1.dot(cross_a2_a3)
|
||||||
b1 = sympy.Matrix(1, 2, [b1[0], b1[1]])
|
b1 = sympy.Matrix(1, 2, [b1[0], b1[1]])
|
||||||
b2 = sympy.Matrix(1, 2, [b2[0], b2[1]])
|
b2 = sympy.Matrix(1, 2, [b2[0], b2[1]])
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return b1, b2
|
return b1, b2
|
||||||
|
|
||||||
# 由实空间格矢得到倒空间格矢(三维),这里为符号运算
|
# 由实空间格矢得到倒空间格矢(三维),这里为符号运算
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_three_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2, a3):
|
def calculate_three_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2, a3):
|
||||||
import sympy
|
import sympy
|
||||||
cross_a2_a3 = a2.cross(a3)
|
cross_a2_a3 = a2.cross(a3)
|
||||||
@ -130,6 +124,4 @@ def calculate_three_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2, a3
|
|||||||
b1 = 2*sympy.pi*cross_a2_a3/a1.dot(cross_a2_a3)
|
b1 = 2*sympy.pi*cross_a2_a3/a1.dot(cross_a2_a3)
|
||||||
b2 = 2*sympy.pi*cross_a3_a1/a1.dot(cross_a2_a3)
|
b2 = 2*sympy.pi*cross_a3_a1/a1.dot(cross_a2_a3)
|
||||||
b3 = 2*sympy.pi*cross_a1_a2/a1.dot(cross_a2_a3)
|
b3 = 2*sympy.pi*cross_a1_a2/a1.dot(cross_a2_a3)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return b1, b2, b3
|
return b1, b2, b3
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# Module: Green_functions
|
# Module: Green_functions
|
||||||
|
import guan
|
||||||
|
|
||||||
# 输入哈密顿量,得到格林函数
|
# 输入哈密顿量,得到格林函数
|
||||||
|
@guan.function_decorator
|
||||||
def green_function(fermi_energy, hamiltonian, broadening, self_energy=0):
|
def green_function(fermi_energy, hamiltonian, broadening, self_energy=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
if np.array(hamiltonian).shape==():
|
if np.array(hamiltonian).shape==():
|
||||||
@ -8,11 +10,10 @@ def green_function(fermi_energy, hamiltonian, broadening, self_energy=0):
|
|||||||
else:
|
else:
|
||||||
dim = np.array(hamiltonian).shape[0]
|
dim = np.array(hamiltonian).shape[0]
|
||||||
green = np.linalg.inv((fermi_energy+broadening*1j)*np.eye(dim)-hamiltonian-self_energy)
|
green = np.linalg.inv((fermi_energy+broadening*1j)*np.eye(dim)-hamiltonian-self_energy)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return green
|
return green
|
||||||
|
|
||||||
# 在Dyson方程中的一个中间格林函数G_{nn}^{n}
|
# 在Dyson方程中的一个中间格林函数G_{nn}^{n}
|
||||||
|
@guan.function_decorator
|
||||||
def green_function_nn_n(fermi_energy, h00, h01, green_nn_n_minus, broadening, self_energy=0):
|
def green_function_nn_n(fermi_energy, h00, h01, green_nn_n_minus, broadening, self_energy=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
h01 = np.array(h01)
|
h01 = np.array(h01)
|
||||||
@ -21,36 +22,32 @@ def green_function_nn_n(fermi_energy, h00, h01, green_nn_n_minus, broadening, se
|
|||||||
else:
|
else:
|
||||||
dim = np.array(h00).shape[0]
|
dim = np.array(h00).shape[0]
|
||||||
green_nn_n = np.linalg.inv((fermi_energy+broadening*1j)*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n_minus), h01)-self_energy)
|
green_nn_n = np.linalg.inv((fermi_energy+broadening*1j)*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), green_nn_n_minus), h01)-self_energy)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return green_nn_n
|
return green_nn_n
|
||||||
|
|
||||||
# 在Dyson方程中的一个中间格林函数G_{in}^{n}
|
# 在Dyson方程中的一个中间格林函数G_{in}^{n}
|
||||||
|
@guan.function_decorator
|
||||||
def green_function_in_n(green_in_n_minus, h01, green_nn_n):
|
def green_function_in_n(green_in_n_minus, h01, green_nn_n):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
green_in_n = np.dot(np.dot(green_in_n_minus, h01), green_nn_n)
|
green_in_n = np.dot(np.dot(green_in_n_minus, h01), green_nn_n)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return green_in_n
|
return green_in_n
|
||||||
|
|
||||||
# 在Dyson方程中的一个中间格林函数G_{ni}^{n}
|
# 在Dyson方程中的一个中间格林函数G_{ni}^{n}
|
||||||
|
@guan.function_decorator
|
||||||
def green_function_ni_n(green_nn_n, h01, green_ni_n_minus):
|
def green_function_ni_n(green_nn_n, h01, green_ni_n_minus):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
h01 = np.array(h01)
|
h01 = np.array(h01)
|
||||||
green_ni_n = np.dot(np.dot(green_nn_n, h01.transpose().conj()), green_ni_n_minus)
|
green_ni_n = np.dot(np.dot(green_nn_n, h01.transpose().conj()), green_ni_n_minus)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return green_ni_n
|
return green_ni_n
|
||||||
|
|
||||||
# 在Dyson方程中的一个中间格林函数G_{ii}^{n}
|
# 在Dyson方程中的一个中间格林函数G_{ii}^{n}
|
||||||
|
@guan.function_decorator
|
||||||
def green_function_ii_n(green_ii_n_minus, green_in_n_minus, h01, green_nn_n, green_ni_n_minus):
|
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
|
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)
|
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)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return green_ii_n
|
return green_ii_n
|
||||||
|
|
||||||
# 计算转移矩阵(该矩阵可以用来计算表面格林函数)
|
# 计算转移矩阵(该矩阵可以用来计算表面格林函数)
|
||||||
|
@guan.function_decorator
|
||||||
def transfer_matrix(fermi_energy, h00, h01):
|
def transfer_matrix(fermi_energy, h00, h01):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
h01 = np.array(h01)
|
h01 = np.array(h01)
|
||||||
@ -63,11 +60,10 @@ def transfer_matrix(fermi_energy, h00, h01):
|
|||||||
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
|
transfer[0:dim, dim:2*dim] = np.dot(-1*np.linalg.inv(h01), h01.transpose().conj())
|
||||||
transfer[dim:2*dim, 0:dim] = np.identity(dim)
|
transfer[dim:2*dim, 0:dim] = np.identity(dim)
|
||||||
transfer[dim:2*dim, dim:2*dim] = 0
|
transfer[dim:2*dim, dim:2*dim] = 0
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return transfer
|
return transfer
|
||||||
|
|
||||||
# 计算电极的表面格林函数
|
# 计算电极的表面格林函数
|
||||||
|
@guan.function_decorator
|
||||||
def surface_green_function_of_lead(fermi_energy, h00, h01):
|
def surface_green_function_of_lead(fermi_energy, h00, h01):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
h01 = np.array(h01)
|
h01 = np.array(h01)
|
||||||
@ -90,11 +86,10 @@ def surface_green_function_of_lead(fermi_energy, h00, h01):
|
|||||||
s4 = temp[0:dim, dim:2*dim]
|
s4 = temp[0:dim, dim:2*dim]
|
||||||
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
|
right_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01, s2), np.linalg.inv(s1)))
|
||||||
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
|
left_lead_surface = np.linalg.inv(fermi_energy*np.identity(dim)-h00-np.dot(np.dot(h01.transpose().conj(), s3), np.linalg.inv(s4)))
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return right_lead_surface, left_lead_surface
|
return right_lead_surface, left_lead_surface
|
||||||
|
|
||||||
# 计算电极的自能(基于Dyson方程的小矩阵形式)
|
# 计算电极的自能(基于Dyson方程的小矩阵形式)
|
||||||
|
@guan.function_decorator
|
||||||
def self_energy_of_lead(fermi_energy, h00, h01):
|
def self_energy_of_lead(fermi_energy, h00, h01):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -104,10 +99,10 @@ def self_energy_of_lead(fermi_energy, h00, h01):
|
|||||||
left_self_energy = np.dot(np.dot(h01.transpose().conj(), left_lead_surface), h01)
|
left_self_energy = np.dot(np.dot(h01.transpose().conj(), left_lead_surface), h01)
|
||||||
gamma_right = (right_self_energy - right_self_energy.transpose().conj())*1j
|
gamma_right = (right_self_energy - right_self_energy.transpose().conj())*1j
|
||||||
gamma_left = (left_self_energy - left_self_energy.transpose().conj())*1j
|
gamma_left = (left_self_energy - left_self_energy.transpose().conj())*1j
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return right_self_energy, left_self_energy, gamma_right, gamma_left
|
return right_self_energy, left_self_energy, gamma_right, gamma_left
|
||||||
|
|
||||||
# 计算电极的自能(基于中心区整体的大矩阵形式)
|
# 计算电极的自能(基于中心区整体的大矩阵形式)
|
||||||
|
@guan.function_decorator
|
||||||
def self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR):
|
def self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -118,10 +113,10 @@ def self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR):
|
|||||||
left_self_energy = np.dot(np.dot(h_LC.transpose().conj(), left_lead_surface), h_LC)
|
left_self_energy = np.dot(np.dot(h_LC.transpose().conj(), left_lead_surface), h_LC)
|
||||||
gamma_right = (right_self_energy - right_self_energy.transpose().conj())*1j
|
gamma_right = (right_self_energy - right_self_energy.transpose().conj())*1j
|
||||||
gamma_left = (left_self_energy - left_self_energy.transpose().conj())*1j
|
gamma_left = (left_self_energy - left_self_energy.transpose().conj())*1j
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return right_self_energy, left_self_energy, gamma_right, gamma_left
|
return right_self_energy, left_self_energy, gamma_right, gamma_left
|
||||||
|
|
||||||
# 计算电极的自能(基于中心区整体的大矩阵形式,可适用于多端电导的计算)
|
# 计算电极的自能(基于中心区整体的大矩阵形式,可适用于多端电导的计算)
|
||||||
|
@guan.function_decorator
|
||||||
def self_energy_of_lead_with_h_lead_to_center(fermi_energy, h00, h01, h_lead_to_center):
|
def self_energy_of_lead_with_h_lead_to_center(fermi_energy, h00, h01, h_lead_to_center):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -129,25 +124,24 @@ def self_energy_of_lead_with_h_lead_to_center(fermi_energy, h00, h01, h_lead_to_
|
|||||||
right_lead_surface, left_lead_surface = guan.surface_green_function_of_lead(fermi_energy, h00, h01)
|
right_lead_surface, left_lead_surface = guan.surface_green_function_of_lead(fermi_energy, h00, h01)
|
||||||
self_energy = np.dot(np.dot(h_lead_to_center.transpose().conj(), right_lead_surface), h_lead_to_center)
|
self_energy = np.dot(np.dot(h_lead_to_center.transpose().conj(), right_lead_surface), h_lead_to_center)
|
||||||
gamma = (self_energy - self_energy.transpose().conj())*1j
|
gamma = (self_energy - self_energy.transpose().conj())*1j
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return self_energy, gamma
|
return self_energy, gamma
|
||||||
|
|
||||||
# 计算考虑电极自能后的中心区的格林函数
|
# 计算考虑电极自能后的中心区的格林函数
|
||||||
|
@guan.function_decorator
|
||||||
def green_function_with_leads(fermi_energy, h00, h01, h_LC, h_CR, center_hamiltonian):
|
def green_function_with_leads(fermi_energy, h00, h01, h_LC, h_CR, center_hamiltonian):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
dim = np.array(center_hamiltonian).shape[0]
|
dim = np.array(center_hamiltonian).shape[0]
|
||||||
right_self_energy, left_self_energy, gamma_right, gamma_left = guan.self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR)
|
right_self_energy, left_self_energy, gamma_right, gamma_left = guan.self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR)
|
||||||
green = np.linalg.inv(fermi_energy*np.identity(dim)-center_hamiltonian-left_self_energy-right_self_energy)
|
green = np.linalg.inv(fermi_energy*np.identity(dim)-center_hamiltonian-left_self_energy-right_self_energy)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return green, gamma_right, gamma_left
|
return green, gamma_right, gamma_left
|
||||||
|
|
||||||
# 计算用于计算局域电流的格林函数G_n
|
# 计算用于计算局域电流的格林函数G_n
|
||||||
|
@guan.function_decorator
|
||||||
def electron_correlation_function_green_n_for_local_current(fermi_energy, h00, h01, h_LC, h_CR, center_hamiltonian):
|
def electron_correlation_function_green_n_for_local_current(fermi_energy, h00, h01, h_LC, h_CR, center_hamiltonian):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
right_self_energy, left_self_energy, gamma_right, gamma_left = guan.self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR)
|
right_self_energy, left_self_energy, gamma_right, gamma_left = guan.self_energy_of_lead_with_h_LC_and_h_CR(fermi_energy, h00, h01, h_LC, h_CR)
|
||||||
green = guan.green_function(fermi_energy, center_hamiltonian, broadening=0, self_energy=left_self_energy+right_self_energy)
|
green = guan.green_function(fermi_energy, center_hamiltonian, broadening=0, self_energy=left_self_energy+right_self_energy)
|
||||||
G_n = np.imag(np.dot(np.dot(green, gamma_left), green.transpose().conj()))
|
G_n = np.imag(np.dot(np.dot(green, gamma_left), green.transpose().conj()))
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return G_n
|
return G_n
|
@ -1,6 +1,8 @@
|
|||||||
# Module: Hamiltonian_of_examples
|
# Module: Hamiltonian_of_examples
|
||||||
|
import guan
|
||||||
|
|
||||||
# 构建一维的有限尺寸体系哈密顿量(可设置是否为周期边界条件)
|
# 构建一维的有限尺寸体系哈密顿量(可设置是否为周期边界条件)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_finite_size_system_along_one_direction(N, on_site=0, hopping=1, period=0):
|
def hamiltonian_of_finite_size_system_along_one_direction(N, on_site=0, hopping=1, period=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
on_site = np.array(on_site)
|
on_site = np.array(on_site)
|
||||||
@ -18,11 +20,10 @@ def hamiltonian_of_finite_size_system_along_one_direction(N, on_site=0, hopping=
|
|||||||
if period == 1:
|
if period == 1:
|
||||||
hamiltonian[(N-1)*dim+0:(N-1)*dim+dim, 0:dim] = hopping
|
hamiltonian[(N-1)*dim+0:(N-1)*dim+dim, 0:dim] = hopping
|
||||||
hamiltonian[0:dim, (N-1)*dim+0:(N-1)*dim+dim] = hopping.transpose().conj()
|
hamiltonian[0:dim, (N-1)*dim+0:(N-1)*dim+dim] = hopping.transpose().conj()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 构建二维的方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
|
# 构建二维的方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
|
||||||
|
@guan.function_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):
|
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
|
import numpy as np
|
||||||
on_site = np.array(on_site)
|
on_site = np.array(on_site)
|
||||||
@ -52,11 +53,10 @@ def hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1
|
|||||||
for i1 in range(N1):
|
for i1 in range(N1):
|
||||||
hamiltonian[i1*N2*dim+(N2-1)*dim+0:i1*N2*dim+(N2-1)*dim+dim, i1*N2*dim+0:i1*N2*dim+dim] = hopping_2
|
hamiltonian[i1*N2*dim+(N2-1)*dim+0:i1*N2*dim+(N2-1)*dim+dim, i1*N2*dim+0:i1*N2*dim+dim] = hopping_2
|
||||||
hamiltonian[i1*N2*dim+0:i1*N2*dim+dim, i1*N2*dim+(N2-1)*dim+0:i1*N2*dim+(N2-1)*dim+dim] = hopping_2.transpose().conj()
|
hamiltonian[i1*N2*dim+0:i1*N2*dim+dim, i1*N2*dim+(N2-1)*dim+0:i1*N2*dim+(N2-1)*dim+dim] = hopping_2.transpose().conj()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 构建三维的立方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
|
# 构建三维的立方格子有限尺寸体系哈密顿量(可设置是否为周期边界条件)
|
||||||
|
@guan.function_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):
|
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
|
import numpy as np
|
||||||
on_site = np.array(on_site)
|
on_site = np.array(on_site)
|
||||||
@ -102,11 +102,10 @@ def hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(N
|
|||||||
for i2 in range(N2):
|
for i2 in range(N2):
|
||||||
hamiltonian[i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+dim, i1*N2*N3*dim+i2*N3*dim+0:i1*N2*N3*dim+i2*N3*dim+dim] = hopping_3
|
hamiltonian[i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+dim, i1*N2*N3*dim+i2*N3*dim+0:i1*N2*N3*dim+i2*N3*dim+dim] = hopping_3
|
||||||
hamiltonian[i1*N2*N3*dim+i2*N3*dim+0:i1*N2*N3*dim+i2*N3*dim+dim, i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+dim] = hopping_3.transpose().conj()
|
hamiltonian[i1*N2*N3*dim+i2*N3*dim+0:i1*N2*N3*dim+i2*N3*dim+dim, i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+0:i1*N2*N3*dim+i2*N3*dim+(N3-1)*dim+dim] = hopping_3.transpose().conj()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 构建有限尺寸的SSH模型哈密顿量
|
# 构建有限尺寸的SSH模型哈密顿量
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_finite_size_ssh_model(N, v=0.6, w=1, onsite_1=0, onsite_2=0, period=1):
|
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
|
import numpy as np
|
||||||
hamiltonian = np.zeros((2*N, 2*N))
|
hamiltonian = np.zeros((2*N, 2*N))
|
||||||
@ -121,11 +120,10 @@ def hamiltonian_of_finite_size_ssh_model(N, v=0.6, w=1, onsite_1=0, onsite_2=0,
|
|||||||
if period==1:
|
if period==1:
|
||||||
hamiltonian[0, 2*N-1] = w
|
hamiltonian[0, 2*N-1] = w
|
||||||
hamiltonian[2*N-1, 0] = w
|
hamiltonian[2*N-1, 0] = w
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 获取Zigzag边的石墨烯条带的元胞间跃迁
|
# 获取Zigzag边的石墨烯条带的元胞间跃迁
|
||||||
|
@guan.function_decorator
|
||||||
def get_hopping_term_of_graphene_ribbon_along_zigzag_direction(N, eta=0):
|
def get_hopping_term_of_graphene_ribbon_along_zigzag_direction(N, eta=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
hopping = np.zeros((4*N, 4*N), dtype=complex)
|
hopping = np.zeros((4*N, 4*N), dtype=complex)
|
||||||
@ -136,11 +134,10 @@ def get_hopping_term_of_graphene_ribbon_along_zigzag_direction(N, eta=0):
|
|||||||
hopping[4*i0+3, 4*i0+3] = eta
|
hopping[4*i0+3, 4*i0+3] = eta
|
||||||
hopping[4*i0+1, 4*i0+0] = 1
|
hopping[4*i0+1, 4*i0+0] = 1
|
||||||
hopping[4*i0+2, 4*i0+3] = 1
|
hopping[4*i0+2, 4*i0+3] = 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hopping
|
return hopping
|
||||||
|
|
||||||
# 构建有限尺寸的石墨烯哈密顿量(可设置是否为周期边界条件)
|
# 构建有限尺寸的石墨烯哈密顿量(可设置是否为周期边界条件)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_finite_size_system_along_two_directions_for_graphene(N1, N2, period_1=0, period_2=0):
|
def hamiltonian_of_finite_size_system_along_two_directions_for_graphene(N1, N2, period_1=0, period_2=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -149,10 +146,10 @@ def hamiltonian_of_finite_size_system_along_two_directions_for_graphene(N1, N2,
|
|||||||
hopping_2 = np.zeros((4, 4), dtype=complex)
|
hopping_2 = np.zeros((4, 4), dtype=complex)
|
||||||
hopping_2[3, 0] = 1
|
hopping_2[3, 0] = 1
|
||||||
hamiltonian = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1, N2, on_site, hopping_1, hopping_2, period_1, period_2)
|
hamiltonian = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1, N2, on_site, hopping_1, hopping_2, period_1, period_2)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 获取石墨烯有效模型沿着x方向的在位能和跃迁项(其中,动量qy为参数)
|
# 获取石墨烯有效模型沿着x方向的在位能和跃迁项(其中,动量qy为参数)
|
||||||
|
@guan.function_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):
|
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
|
import numpy as np
|
||||||
constant = -np.sqrt(3)/2
|
constant = -np.sqrt(3)/2
|
||||||
@ -170,11 +167,10 @@ def get_onsite_and_hopping_terms_of_2d_effective_graphene_along_one_direction(qy
|
|||||||
else:
|
else:
|
||||||
h01[0, 1] = constant*t*(1j/2)
|
h01[0, 1] = constant*t*(1j/2)
|
||||||
h01[1, 0] = constant*t*(1j/2)
|
h01[1, 0] = constant*t*(1j/2)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return h00, h01
|
return h00, h01
|
||||||
|
|
||||||
# 获取BHZ模型的在位能和跃迁项
|
# 获取BHZ模型的在位能和跃迁项
|
||||||
|
@guan.function_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):
|
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
|
import numpy as np
|
||||||
E_s = C+M-4*(D+B)/(a**2)
|
E_s = C+M-4*(D+B)/(a**2)
|
||||||
@ -205,11 +201,10 @@ def get_onsite_and_hopping_terms_of_bhz_model(A=0.3645/5, B=-0.686/25, C=0, D=-0
|
|||||||
H2[1, 0] = 1j*np.conj(V_sp)
|
H2[1, 0] = 1j*np.conj(V_sp)
|
||||||
H2[2, 3] = -1j*np.conj(V_sp)
|
H2[2, 3] = -1j*np.conj(V_sp)
|
||||||
H2[3, 2] = -1j*V_sp
|
H2[3, 2] = -1j*V_sp
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return H0, H1, H2
|
return H0, H1, H2
|
||||||
|
|
||||||
# 获取半个BHZ模型的在位能和跃迁项(自旋向上)
|
# 获取半个BHZ模型的在位能和跃迁项(自旋向上)
|
||||||
|
@guan.function_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):
|
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
|
import numpy as np
|
||||||
E_s = C+M-4*(D+B)/(a**2)
|
E_s = C+M-4*(D+B)/(a**2)
|
||||||
@ -230,11 +225,10 @@ def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_up(A=0.3645/5, B=-0.
|
|||||||
H2[1, 1] = V_pp
|
H2[1, 1] = V_pp
|
||||||
H2[0, 1] = 1j*V_sp
|
H2[0, 1] = 1j*V_sp
|
||||||
H2[1, 0] = 1j*np.conj(V_sp)
|
H2[1, 0] = 1j*np.conj(V_sp)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return H0, H1, H2
|
return H0, H1, H2
|
||||||
|
|
||||||
# 获取半个BHZ模型的在位能和跃迁项(自旋向下)
|
# 获取半个BHZ模型的在位能和跃迁项(自旋向下)
|
||||||
|
@guan.function_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):
|
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
|
import numpy as np
|
||||||
E_s = C+M-4*(D+B)/(a**2)
|
E_s = C+M-4*(D+B)/(a**2)
|
||||||
@ -255,25 +249,24 @@ def get_onsite_and_hopping_terms_of_half_bhz_model_for_spin_down(A=0.3645/5, B=-
|
|||||||
H2[1, 1] = V_pp
|
H2[1, 1] = V_pp
|
||||||
H2[0, 1] = -1j*np.conj(V_sp)
|
H2[0, 1] = -1j*np.conj(V_sp)
|
||||||
H2[1, 0] = -1j*V_sp
|
H2[1, 0] = -1j*V_sp
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return H0, H1, H2
|
return H0, H1, H2
|
||||||
|
|
||||||
# 一维链的哈密顿量(倒空间)
|
# 一维链的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_simple_chain(k):
|
def hamiltonian_of_simple_chain(k):
|
||||||
import guan
|
import guan
|
||||||
hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=0, hopping=1)
|
hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=0, hopping=1)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 二维方格子的哈密顿量(倒空间)
|
# 二维方格子的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_square_lattice(k1, k2):
|
def hamiltonian_of_square_lattice(k1, k2):
|
||||||
import guan
|
import guan
|
||||||
hamiltonian = guan.two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell=0, hopping_1=1, hopping_2=1)
|
hamiltonian = guan.two_dimensional_fourier_transform_for_square_lattice(k1, k2, unit_cell=0, hopping_1=1, hopping_2=1)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 准一维方格子条带的哈密顿量(倒空间)
|
# 准一维方格子条带的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0):
|
def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -288,28 +281,27 @@ def hamiltonian_of_square_lattice_in_quasi_one_dimension(k, N=10, period=0):
|
|||||||
for i in range(N):
|
for i in range(N):
|
||||||
h01[i, i] = 1
|
h01[i, i] = 1
|
||||||
hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=h00, hopping=h01)
|
hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=h00, hopping=h01)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 三维立方格子的哈密顿量(倒空间)
|
# 三维立方格子的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_cubic_lattice(k1, k2, k3):
|
def hamiltonian_of_cubic_lattice(k1, k2, k3):
|
||||||
import guan
|
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)
|
hamiltonian = guan.three_dimensional_fourier_transform_for_cubic_lattice(k1, k2, k3, unit_cell=0, hopping_1=1, hopping_2=1, hopping_3=1)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# SSH模型的哈密顿量(倒空间)
|
# SSH模型的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_ssh_model(k, v=0.6, w=1):
|
def hamiltonian_of_ssh_model(k, v=0.6, w=1):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
hamiltonian = np.zeros((2, 2), dtype=complex)
|
hamiltonian = np.zeros((2, 2), dtype=complex)
|
||||||
hamiltonian[0,1] = v+w*cmath.exp(-1j*k)
|
hamiltonian[0,1] = v+w*cmath.exp(-1j*k)
|
||||||
hamiltonian[1,0] = v+w*cmath.exp(1j*k)
|
hamiltonian[1,0] = v+w*cmath.exp(1j*k)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 石墨烯的哈密顿量(倒空间)
|
# 石墨烯的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'):
|
def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -323,11 +315,10 @@ def hamiltonian_of_graphene(k1, k2, staggered_potential=0, t=1, a='default'):
|
|||||||
h1[1, 0] = t*(cmath.exp(1j*k2*a)+cmath.exp(1j*math.sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j/2*k2*a))
|
h1[1, 0] = t*(cmath.exp(1j*k2*a)+cmath.exp(1j*math.sqrt(3)/2*k1*a-1j/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j/2*k2*a))
|
||||||
h1[0, 1] = h1[1, 0].conj()
|
h1[0, 1] = h1[1, 0].conj()
|
||||||
hamiltonian = h0 + h1
|
hamiltonian = h0 + h1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 石墨烯有效模型的哈密顿量(倒空间)
|
# 石墨烯有效模型的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def effective_hamiltonian_of_graphene(qx, qy, t=1, staggered_potential=0, valley_index=0):
|
def effective_hamiltonian_of_graphene(qx, qy, t=1, staggered_potential=0, valley_index=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
hamiltonian = np.zeros((2, 2), dtype=complex)
|
hamiltonian = np.zeros((2, 2), dtype=complex)
|
||||||
@ -340,11 +331,10 @@ def effective_hamiltonian_of_graphene(qx, qy, t=1, staggered_potential=0, valley
|
|||||||
else:
|
else:
|
||||||
hamiltonian[0, 1] = constant*t*(-qx-1j*qy)
|
hamiltonian[0, 1] = constant*t*(-qx-1j*qy)
|
||||||
hamiltonian[1, 0] = constant*t*(-qx+1j*qy)
|
hamiltonian[1, 0] = constant*t*(-qx+1j*qy)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 石墨烯有效模型离散化后的哈密顿量(倒空间)
|
# 石墨烯有效模型离散化后的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def effective_hamiltonian_of_graphene_after_discretization(qx, qy, t=1, staggered_potential=0, valley_index=0):
|
def effective_hamiltonian_of_graphene_after_discretization(qx, qy, t=1, staggered_potential=0, valley_index=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
hamiltonian = np.zeros((2, 2), dtype=complex)
|
hamiltonian = np.zeros((2, 2), dtype=complex)
|
||||||
@ -357,11 +347,10 @@ def effective_hamiltonian_of_graphene_after_discretization(qx, qy, t=1, staggere
|
|||||||
else:
|
else:
|
||||||
hamiltonian[0, 1] = constant*t*(-np.sin(qx)-1j*np.sin(qy))
|
hamiltonian[0, 1] = constant*t*(-np.sin(qx)-1j*np.sin(qy))
|
||||||
hamiltonian[1, 0] = constant*t*(-np.sin(qx)+1j*np.sin(qy))
|
hamiltonian[1, 0] = constant*t*(-np.sin(qx)+1j*np.sin(qy))
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 准一维Zigzag边石墨烯条带的哈密顿量(倒空间)
|
# 准一维Zigzag边石墨烯条带的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension(k, N=10, M=0, t=1, period=0):
|
def hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension(k, N=10, M=0, t=1, period=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -388,10 +377,10 @@ def hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension(k, N=10, M=0, t=1
|
|||||||
h01[i*4+1, i*4+0] = t
|
h01[i*4+1, i*4+0] = t
|
||||||
h01[i*4+2, i*4+3] = t
|
h01[i*4+2, i*4+3] = t
|
||||||
hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=h00, hopping=h01)
|
hamiltonian = guan.one_dimensional_fourier_transform(k, unit_cell=h00, hopping=h01)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# Haldane模型的哈密顿量(倒空间)
|
# Haldane模型的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi='default', a='default'):
|
def hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi='default', a='default'):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -410,11 +399,10 @@ def hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi='default', a='
|
|||||||
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*math.sqrt(3)*k1*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
h2[0, 0] = t2*cmath.exp(-1j*phi)*(cmath.exp(1j*math.sqrt(3)*k1*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*math.sqrt(3)*k1*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
h2[1, 1] = t2*cmath.exp(1j*phi)*(cmath.exp(1j*math.sqrt(3)*k1*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a+1j*3/2*k2*a)+cmath.exp(-1j*math.sqrt(3)/2*k1*a-1j*3/2*k2*a))
|
||||||
hamiltonian = h0 + h1 + h2 + h2.transpose().conj()
|
hamiltonian = h0 + h1 + h2 + h2.transpose().conj()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 准一维Haldane模型条带的哈密顿量(倒空间)
|
# 准一维Haldane模型条带的哈密顿量(倒空间)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -466,11 +454,10 @@ def hamiltonian_of_haldane_model_in_quasi_one_dimension(k, N=10, M=2/3, t1=1, t2
|
|||||||
for i in range(N-1):
|
for i in range(N-1):
|
||||||
h01[i*4+2, (i+1)*4+0] = t2*cmath.exp(-1j*phi)
|
h01[i*4+2, (i+1)*4+0] = t2*cmath.exp(-1j*phi)
|
||||||
hamiltonian = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
|
hamiltonian = h00 + h01*cmath.exp(1j*k) + h01.transpose().conj()*cmath.exp(-1j*k)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 一个量子反常霍尔效应的哈密顿量(倒空间)
|
# 一个量子反常霍尔效应的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_one_QAH_model(k1, k2, t1=1, t2=1, t3=0.5, m=-1):
|
def hamiltonian_of_one_QAH_model(k1, k2, t1=1, t2=1, t3=0.5, m=-1):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
@ -479,11 +466,10 @@ def hamiltonian_of_one_QAH_model(k1, k2, t1=1, t2=1, t3=0.5, m=-1):
|
|||||||
hamiltonian[1, 0] = 2*t1*math.cos(k1)+1j*2*t1*math.cos(k2)
|
hamiltonian[1, 0] = 2*t1*math.cos(k1)+1j*2*t1*math.cos(k2)
|
||||||
hamiltonian[0, 0] = m+2*t3*math.sin(k1)+2*t3*math.sin(k2)+2*t2*math.cos(k1+k2)
|
hamiltonian[0, 0] = m+2*t3*math.sin(k1)+2*t3*math.sin(k2)+2*t2*math.cos(k1+k2)
|
||||||
hamiltonian[1, 1] = -(m+2*t3*math.sin(k1)+2*t3*math.sin(k2)+2*t2*math.cos(k1+k2))
|
hamiltonian[1, 1] = -(m+2*t3*math.sin(k1)+2*t3*math.sin(k2)+2*t2*math.cos(k1+k2))
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# BHZ模型的哈密顿量(倒空间)
|
# BHZ模型的哈密顿量(倒空间)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -499,11 +485,10 @@ def hamiltonian_of_bhz_model(kx, ky, A=0.3645/5, B=-0.686/25, C=0, D=-0.512/25,
|
|||||||
hamiltonian[3, 3] = varepsilon-d3
|
hamiltonian[3, 3] = varepsilon-d3
|
||||||
hamiltonian[2, 3] = -d1_d2
|
hamiltonian[2, 3] = -d1_d2
|
||||||
hamiltonian[3, 2] = -np.conj(d1_d2)
|
hamiltonian[3, 2] = -np.conj(d1_d2)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 半BHZ模型的哈密顿量(自旋向上)(倒空间)
|
# 半BHZ模型的哈密顿量(自旋向上)(倒空间)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -515,11 +500,10 @@ def hamiltonian_of_half_bhz_model_for_spin_up(kx, ky, A=0.3645/5, B=-0.686/25, C
|
|||||||
hamiltonian[1, 1] = varepsilon-d3
|
hamiltonian[1, 1] = varepsilon-d3
|
||||||
hamiltonian[0, 1] = np.conj(d1_d2)
|
hamiltonian[0, 1] = np.conj(d1_d2)
|
||||||
hamiltonian[1, 0] = d1_d2
|
hamiltonian[1, 0] = d1_d2
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# 半BHZ模型的哈密顿量(自旋向下)(倒空间)
|
# 半BHZ模型的哈密顿量(自旋向下)(倒空间)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -531,11 +515,10 @@ def hamiltonian_of_half_bhz_model_for_spin_down(kx, ky, A=0.3645/5, B=-0.686/25,
|
|||||||
hamiltonian[1, 1] = varepsilon-d3
|
hamiltonian[1, 1] = varepsilon-d3
|
||||||
hamiltonian[0, 1] = -d1_d2
|
hamiltonian[0, 1] = -d1_d2
|
||||||
hamiltonian[1, 0] = -np.conj(d1_d2)
|
hamiltonian[1, 0] = -np.conj(d1_d2)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# BBH模型的哈密顿量(倒空间)
|
# BBH模型的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_bbh_model(kx, ky, gamma_x=0.5, gamma_y=0.5, lambda_x=1, lambda_y=1):
|
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 numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -552,11 +535,10 @@ def hamiltonian_of_bbh_model(kx, ky, gamma_x=0.5, gamma_y=0.5, lambda_x=1, lambd
|
|||||||
hamiltonian[3, 1] = np.conj(hamiltonian[1, 3])
|
hamiltonian[3, 1] = np.conj(hamiltonian[1, 3])
|
||||||
hamiltonian[3, 0] = np.conj(hamiltonian[0, 3])
|
hamiltonian[3, 0] = np.conj(hamiltonian[0, 3])
|
||||||
hamiltonian[2, 1] = np.conj(hamiltonian[1, 2])
|
hamiltonian[2, 1] = np.conj(hamiltonian[1, 2])
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
||||||
|
|
||||||
# Kagome模型的哈密顿量(倒空间)
|
# Kagome模型的哈密顿量(倒空间)
|
||||||
|
@guan.function_decorator
|
||||||
def hamiltonian_of_kagome_lattice(kx, ky, t=1):
|
def hamiltonian_of_kagome_lattice(kx, ky, t=1):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
@ -569,6 +551,4 @@ def hamiltonian_of_kagome_lattice(kx, ky, t=1):
|
|||||||
hamiltonian[1, 2] = 2*math.cos(k3_dot_a3)
|
hamiltonian[1, 2] = 2*math.cos(k3_dot_a3)
|
||||||
hamiltonian = hamiltonian + hamiltonian.transpose().conj()
|
hamiltonian = hamiltonian + hamiltonian.transpose().conj()
|
||||||
hamiltonian = -t*hamiltonian
|
hamiltonian = -t*hamiltonian
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hamiltonian
|
return hamiltonian
|
@ -1,5 +1,13 @@
|
|||||||
# 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.
|
# 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 wrapper():
|
||||||
|
func()
|
||||||
|
import guan
|
||||||
|
guan.statistics_of_guan_package(func.__name__)
|
||||||
|
return wrapper
|
||||||
|
|
||||||
from .basic_functions import *
|
from .basic_functions import *
|
||||||
from .Fourier_transform import *
|
from .Fourier_transform import *
|
||||||
from .Hamiltonian_of_examples import *
|
from .Hamiltonian_of_examples import *
|
||||||
|
@ -1,17 +1,18 @@
|
|||||||
# Module: band_structures_and_wave_functions
|
# Module: band_structures_and_wave_functions
|
||||||
|
import guan
|
||||||
|
|
||||||
# 计算哈密顿量的本征值
|
# 计算哈密顿量的本征值
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_eigenvalue(hamiltonian):
|
def calculate_eigenvalue(hamiltonian):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
if np.array(hamiltonian).shape==():
|
if np.array(hamiltonian).shape==():
|
||||||
eigenvalue = np.real(hamiltonian)
|
eigenvalue = np.real(hamiltonian)
|
||||||
else:
|
else:
|
||||||
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
|
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return eigenvalue
|
return eigenvalue
|
||||||
|
|
||||||
# 输入哈密顿量函数(带一组参数),计算一组参数下的本征值,返回本征值向量组
|
# 输入哈密顿量函数(带一组参数),计算一组参数下的本征值,返回本征值向量组
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function, print_show=0):
|
def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function, print_show=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
dim_x = np.array(x_array).shape[0]
|
dim_x = np.array(x_array).shape[0]
|
||||||
@ -32,11 +33,10 @@ def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function, print
|
|||||||
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
|
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
|
||||||
eigenvalue_array[i0, :] = eigenvalue
|
eigenvalue_array[i0, :] = eigenvalue
|
||||||
i0 += 1
|
i0 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return eigenvalue_array
|
return eigenvalue_array
|
||||||
|
|
||||||
# 输入哈密顿量函数(带两组参数),计算两组参数下的本征值,返回本征值向量组
|
# 输入哈密顿量函数(带两组参数),计算两组参数下的本征值,返回本征值向量组
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function, print_show=0, print_show_more=0):
|
def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function, print_show=0, print_show_more=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
dim_x = np.array(x_array).shape[0]
|
dim_x = np.array(x_array).shape[0]
|
||||||
@ -67,19 +67,17 @@ def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_funct
|
|||||||
eigenvalue_array[i0, j0, :] = eigenvalue
|
eigenvalue_array[i0, j0, :] = eigenvalue
|
||||||
j0 += 1
|
j0 += 1
|
||||||
i0 += 1
|
i0 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return eigenvalue_array
|
return eigenvalue_array
|
||||||
|
|
||||||
# 计算哈密顿量的本征矢
|
# 计算哈密顿量的本征矢
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_eigenvector(hamiltonian):
|
def calculate_eigenvector(hamiltonian):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
|
eigenvalue, eigenvector = np.linalg.eigh(hamiltonian)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return eigenvector
|
return eigenvector
|
||||||
|
|
||||||
# 通过二分查找的方法获取和相邻波函数一样规范的波函数
|
# 通过二分查找的方法获取和相邻波函数一样规范的波函数
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -116,11 +114,10 @@ def find_vector_with_the_same_gauge_with_binary_search(vector_target, vector_ref
|
|||||||
vector_target = vector_target*cmath.exp(1j*phase)
|
vector_target = vector_target*cmath.exp(1j*phase)
|
||||||
if show_phase==1:
|
if show_phase==1:
|
||||||
print('Phase=', phase)
|
print('Phase=', phase)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return vector_target
|
return vector_target
|
||||||
|
|
||||||
# 通过使得波函数的一个非零分量为实数,得到固定规范的波函数
|
# 通过使得波函数的一个非零分量为实数,得到固定规范的波函数
|
||||||
|
@guan.function_decorator
|
||||||
def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None):
|
def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -136,11 +133,10 @@ def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=
|
|||||||
vector = vector*cmath.exp(1j*phase)
|
vector = vector*cmath.exp(1j*phase)
|
||||||
if np.real(vector[index]) < 0:
|
if np.real(vector[index]) < 0:
|
||||||
vector = -vector
|
vector = -vector
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return vector
|
return vector
|
||||||
|
|
||||||
# 通过使得波函数的一个非零分量为实数,得到固定规范的波函数(在一组波函数中选取最大的那个分量)
|
# 通过使得波函数的一个非零分量为实数,得到固定规范的波函数(在一组波函数中选取最大的那个分量)
|
||||||
|
@guan.function_decorator
|
||||||
def find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array, precision=0.005):
|
def find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array, precision=0.005):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -151,10 +147,10 @@ def find_vector_array_with_fixed_gauge_by_making_one_component_real(vector_array
|
|||||||
index = np.argmax(np.abs(vector_sum))
|
index = np.argmax(np.abs(vector_sum))
|
||||||
for i0 in range(Num_k):
|
for i0 in range(Num_k):
|
||||||
vector_array[i0] = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector_array[i0], precision=precision, index=index)
|
vector_array[i0] = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector_array[i0], precision=precision, index=index)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return vector_array
|
return vector_array
|
||||||
|
|
||||||
# 旋转两个简并的波函数(说明:参数比较多,算法效率不高)
|
# 旋转两个简并的波函数(说明:参数比较多,算法效率不高)
|
||||||
|
@guan.function_decorator
|
||||||
def rotation_of_degenerate_vectors(vector1, vector2, index1=None, index2=None, precision=0.01, criterion=0.01, show_theta=0):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -181,11 +177,10 @@ def rotation_of_degenerate_vectors(vector1, vector2, index1=None, index2=None, p
|
|||||||
break
|
break
|
||||||
if np.abs(vector1_test[index2])<criterion and np.abs(vector2_test[index1])<criterion:
|
if np.abs(vector1_test[index2])<criterion and np.abs(vector2_test[index1])<criterion:
|
||||||
break
|
break
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return vector1, vector2
|
return vector1, vector2
|
||||||
|
|
||||||
# 旋转两个简并的波函数向量组(说明:参数比较多,算法效率不高)
|
# 旋转两个简并的波函数向量组(说明:参数比较多,算法效率不高)
|
||||||
|
@guan.function_decorator
|
||||||
def rotation_of_degenerate_vectors_array(vector1_array, vector2_array, precision=0.01, criterion=0.01, show_theta=0):
|
def rotation_of_degenerate_vectors_array(vector1_array, vector2_array, precision=0.01, criterion=0.01, show_theta=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -200,10 +195,10 @@ def rotation_of_degenerate_vectors_array(vector1_array, vector2_array, precision
|
|||||||
index2 = np.argmax(np.abs(vector2_sum))
|
index2 = np.argmax(np.abs(vector2_sum))
|
||||||
for i0 in range(Num_k):
|
for i0 in range(Num_k):
|
||||||
vector1_array[i0], vector2_array[i0] = guan.rotation_of_degenerate_vectors(vector1=vector1_array[i0], vector2=vector2_array[i0], index1=index1, index2=index2, precision=precision, criterion=criterion, show_theta=show_theta)
|
vector1_array[i0], vector2_array[i0] = guan.rotation_of_degenerate_vectors(vector1=vector1_array[i0], vector2=vector2_array[i0], index1=index1, index2=index2, precision=precision, criterion=criterion, show_theta=show_theta)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return vector1_array, vector2_array
|
return vector1_array, vector2_array
|
||||||
|
|
||||||
# 在一组数据中找到数值相近的数
|
# 在一组数据中找到数值相近的数
|
||||||
|
@guan.function_decorator
|
||||||
def find_close_values_in_one_array(array, precision=1e-2):
|
def find_close_values_in_one_array(array, precision=1e-2):
|
||||||
new_array = []
|
new_array = []
|
||||||
i0 = 0
|
i0 = 0
|
||||||
@ -214,11 +209,10 @@ def find_close_values_in_one_array(array, precision=1e-2):
|
|||||||
new_array.append([a1, a2])
|
new_array.append([a1, a2])
|
||||||
j0 +=1
|
j0 +=1
|
||||||
i0 += 1
|
i0 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return new_array
|
return new_array
|
||||||
|
|
||||||
# 寻找能带的简并点
|
# 寻找能带的简并点
|
||||||
|
@guan.function_decorator
|
||||||
def find_degenerate_points(k_array, eigenvalue_array, precision=1e-2):
|
def find_degenerate_points(k_array, eigenvalue_array, precision=1e-2):
|
||||||
import guan
|
import guan
|
||||||
degenerate_k_array = []
|
degenerate_k_array = []
|
||||||
@ -230,6 +224,4 @@ def find_degenerate_points(k_array, eigenvalue_array, precision=1e-2):
|
|||||||
degenerate_k_array.append(k)
|
degenerate_k_array.append(k)
|
||||||
degenerate_eigenvalue_array.append(degenerate_points)
|
degenerate_eigenvalue_array.append(degenerate_points)
|
||||||
i0 += 1
|
i0 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return degenerate_k_array, degenerate_eigenvalue_array
|
return degenerate_k_array, degenerate_eigenvalue_array
|
@ -1,129 +1,125 @@
|
|||||||
# Module: basic_functions
|
# Module: basic_functions
|
||||||
|
import guan
|
||||||
|
|
||||||
# 测试
|
# 测试
|
||||||
|
@guan.function_decorator
|
||||||
def test():
|
def test():
|
||||||
print('\nSuccess in the installation of Guan package!\n')
|
print('\nSuccess in the installation of Guan package!\n')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 泡利矩阵
|
# 泡利矩阵
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_0():
|
def sigma_0():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.eye(2)
|
return np.eye(2)
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_x():
|
def sigma_x():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.array([[0, 1],[1, 0]])
|
return np.array([[0, 1],[1, 0]])
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_y():
|
def sigma_y():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.array([[0, -1j],[1j, 0]])
|
return np.array([[0, -1j],[1j, 0]])
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_z():
|
def sigma_z():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.array([[1, 0],[0, -1]])
|
return np.array([[1, 0],[0, -1]])
|
||||||
|
|
||||||
# 泡利矩阵的张量积
|
# 泡利矩阵的张量积
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_00():
|
def sigma_00():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_0(), guan.sigma_0())
|
return np.kron(guan.sigma_0(), guan.sigma_0())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_0x():
|
def sigma_0x():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_0(), guan.sigma_x())
|
return np.kron(guan.sigma_0(), guan.sigma_x())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_0y():
|
def sigma_0y():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_0(), guan.sigma_y())
|
return np.kron(guan.sigma_0(), guan.sigma_y())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_0z():
|
def sigma_0z():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_0(), guan.sigma_z())
|
return np.kron(guan.sigma_0(), guan.sigma_z())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_x0():
|
def sigma_x0():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_x(), guan.sigma_0())
|
return np.kron(guan.sigma_x(), guan.sigma_0())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_xx():
|
def sigma_xx():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_x(), guan.sigma_x())
|
return np.kron(guan.sigma_x(), guan.sigma_x())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_xy():
|
def sigma_xy():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_x(), guan.sigma_y())
|
return np.kron(guan.sigma_x(), guan.sigma_y())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_xz():
|
def sigma_xz():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_x(), guan.sigma_z())
|
return np.kron(guan.sigma_x(), guan.sigma_z())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_y0():
|
def sigma_y0():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_y(), guan.sigma_0())
|
return np.kron(guan.sigma_y(), guan.sigma_0())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_yx():
|
def sigma_yx():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_y(), guan.sigma_x())
|
return np.kron(guan.sigma_y(), guan.sigma_x())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_yy():
|
def sigma_yy():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_y(), guan.sigma_y())
|
return np.kron(guan.sigma_y(), guan.sigma_y())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_yz():
|
def sigma_yz():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_y(), guan.sigma_z())
|
return np.kron(guan.sigma_y(), guan.sigma_z())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_z0():
|
def sigma_z0():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_z(), guan.sigma_0())
|
return np.kron(guan.sigma_z(), guan.sigma_0())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_zx():
|
def sigma_zx():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_z(), guan.sigma_x())
|
return np.kron(guan.sigma_z(), guan.sigma_x())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_zy():
|
def sigma_zy():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_z(), guan.sigma_y())
|
return np.kron(guan.sigma_z(), guan.sigma_y())
|
||||||
|
|
||||||
|
@guan.function_decorator
|
||||||
def sigma_zz():
|
def sigma_zz():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return np.kron(guan.sigma_z(), guan.sigma_z())
|
return np.kron(guan.sigma_z(), guan.sigma_z())
|
@ -1,6 +1,8 @@
|
|||||||
# Module: data_processing (including figure-plotting and file-reading/writing)
|
# Module: data_processing (including figure-plotting and file-reading/writing)
|
||||||
|
import guan
|
||||||
|
|
||||||
# 导入plt, fig, ax
|
# 导入plt, fig, ax
|
||||||
|
@guan.function_decorator
|
||||||
def import_plt_and_start_fig_ax(adjust_bottom=0.2, adjust_left=0.2, labelsize=20):
|
def import_plt_and_start_fig_ax(adjust_bottom=0.2, adjust_left=0.2, labelsize=20):
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
fig, ax = plt.subplots()
|
fig, ax = plt.subplots()
|
||||||
@ -9,11 +11,10 @@ def import_plt_and_start_fig_ax(adjust_bottom=0.2, adjust_left=0.2, labelsize=20
|
|||||||
ax.tick_params(labelsize=labelsize)
|
ax.tick_params(labelsize=labelsize)
|
||||||
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
labels = ax.get_xticklabels() + ax.get_yticklabels()
|
||||||
[label.set_fontname('Times New Roman') for label in labels]
|
[label.set_fontname('Times New Roman') for label in labels]
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return plt, fig, ax
|
return plt, fig, ax
|
||||||
|
|
||||||
# 基于plt, fig, ax画图
|
# 基于plt, fig, ax画图
|
||||||
|
@guan.function_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):
|
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:
|
if color==None:
|
||||||
ax.plot(x_array, y_array, style, linewidth=linewidth, markersize=markersize)
|
ax.plot(x_array, y_array, style, linewidth=linewidth, markersize=markersize)
|
||||||
@ -28,10 +29,9 @@ def plot_without_starting_fig(plt, fig, ax, x_array, y_array, xlabel='x', ylabel
|
|||||||
if y_max==None:
|
if y_max==None:
|
||||||
y_max=max(y_array)
|
y_max=max(y_array)
|
||||||
ax.set_ylim(y_min, y_max)
|
ax.set_ylim(y_min, y_max)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 画图
|
# 画图
|
||||||
|
@guan.function_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):
|
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
|
import guan
|
||||||
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
||||||
@ -50,9 +50,9 @@ def plot(x_array, y_array, xlabel='x', ylabel='y', title='', fontsize=20, labels
|
|||||||
if show == 1:
|
if show == 1:
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 一组横坐标数据,两组纵坐标数据画图
|
# 一组横坐标数据,两组纵坐标数据画图
|
||||||
|
@guan.function_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):
|
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
|
import guan
|
||||||
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
||||||
@ -76,9 +76,9 @@ def plot_two_array(x_array, y1_array, y2_array, xlabel='x', ylabel='y', title=''
|
|||||||
if show == 1:
|
if show == 1:
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 两组横坐标数据,两组纵坐标数据画图
|
# 两组横坐标数据,两组纵坐标数据画图
|
||||||
|
@guan.function_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):
|
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
|
import guan
|
||||||
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
||||||
@ -102,9 +102,9 @@ def plot_two_array_with_two_horizontal_array(x1_array, x2_array, y1_array, y2_ar
|
|||||||
if show == 1:
|
if show == 1:
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 一组横坐标数据,三组纵坐标数据画图
|
# 一组横坐标数据,三组纵坐标数据画图
|
||||||
|
@guan.function_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):
|
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
|
import guan
|
||||||
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
||||||
@ -131,9 +131,9 @@ def plot_three_array(x_array, y1_array, y2_array, y3_array, xlabel='x', ylabel='
|
|||||||
if show == 1:
|
if show == 1:
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 三组横坐标数据,三组纵坐标数据画图
|
# 三组横坐标数据,三组纵坐标数据画图
|
||||||
|
@guan.function_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):
|
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
|
import guan
|
||||||
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
plt, fig, ax = guan.import_plt_and_start_fig_ax(adjust_bottom=adjust_bottom, adjust_left=adjust_left, labelsize=labelsize)
|
||||||
@ -160,9 +160,9 @@ def plot_three_array_with_three_horizontal_array(x1_array, x2_array, x3_array, y
|
|||||||
if show == 1:
|
if show == 1:
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 画三维图
|
# 画三维图
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -202,10 +202,9 @@ def plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z'
|
|||||||
if show == 1:
|
if show == 1:
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 画Contour图
|
# 画Contour图
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -229,10 +228,9 @@ def plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', fon
|
|||||||
if show == 1:
|
if show == 1:
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 画棋盘图/伪彩色图
|
# 画棋盘图/伪彩色图
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -256,10 +254,9 @@ def plot_pcolor(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', font
|
|||||||
if show == 1:
|
if show == 1:
|
||||||
plt.show()
|
plt.show()
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 通过坐标画点和线
|
# 通过坐标画点和线
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import matplotlib.pyplot as plt
|
import matplotlib.pyplot as plt
|
||||||
@ -285,10 +282,9 @@ def draw_dots_and_lines(coordinate_array, draw_dots=1, draw_lines=1, max_distanc
|
|||||||
plt.savefig(filename+file_format)
|
plt.savefig(filename+file_format)
|
||||||
else:
|
else:
|
||||||
plt.savefig(filename+file_format, dpi=dpi)
|
plt.savefig(filename+file_format, dpi=dpi)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 合并两个图片
|
# 合并两个图片
|
||||||
|
@guan.function_decorator
|
||||||
def combine_two_images(image_path_array, figsize=(16,8), show=0, save=1, filename='a', file_format='.jpg', dpi=300):
|
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
|
import numpy as np
|
||||||
num = np.array(image_path_array).shape[0]
|
num = np.array(image_path_array).shape[0]
|
||||||
@ -312,10 +308,9 @@ def combine_two_images(image_path_array, figsize=(16,8), show=0, save=1, filenam
|
|||||||
if save == 1:
|
if save == 1:
|
||||||
plt.savefig(filename+file_format, dpi=dpi)
|
plt.savefig(filename+file_format, dpi=dpi)
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 合并三个图片
|
# 合并三个图片
|
||||||
|
@guan.function_decorator
|
||||||
def combine_three_images(image_path_array, figsize=(16,5), show=0, save=1, filename='a', file_format='.jpg', dpi=300):
|
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
|
import numpy as np
|
||||||
num = np.array(image_path_array).shape[0]
|
num = np.array(image_path_array).shape[0]
|
||||||
@ -343,10 +338,9 @@ def combine_three_images(image_path_array, figsize=(16,5), show=0, save=1, filen
|
|||||||
if save == 1:
|
if save == 1:
|
||||||
plt.savefig(filename+file_format, dpi=dpi)
|
plt.savefig(filename+file_format, dpi=dpi)
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 合并四个图片
|
# 合并四个图片
|
||||||
|
@guan.function_decorator
|
||||||
def combine_four_images(image_path_array, figsize=(16,16), show=0, save=1, filename='a', file_format='.jpg', dpi=300):
|
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
|
import numpy as np
|
||||||
num = np.array(image_path_array).shape[0]
|
num = np.array(image_path_array).shape[0]
|
||||||
@ -378,10 +372,9 @@ def combine_four_images(image_path_array, figsize=(16,16), show=0, save=1, filen
|
|||||||
if save == 1:
|
if save == 1:
|
||||||
plt.savefig(filename+file_format, dpi=dpi)
|
plt.savefig(filename+file_format, dpi=dpi)
|
||||||
plt.close('all')
|
plt.close('all')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 对某个目录中的txt文件批量读取和画图
|
# 对某个目录中的txt文件批量读取和画图
|
||||||
|
@guan.function_decorator
|
||||||
def batch_reading_and_plotting(directory, xlabel='x', ylabel='y'):
|
def batch_reading_and_plotting(directory, xlabel='x', ylabel='y'):
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
@ -392,9 +385,9 @@ def batch_reading_and_plotting(directory, xlabel='x', ylabel='y'):
|
|||||||
filename = file[:-4]
|
filename = file[:-4]
|
||||||
x_array, y_array = guan.read_one_dimensional_data(filename=filename)
|
x_array, y_array = guan.read_one_dimensional_data(filename=filename)
|
||||||
guan.plot(x_array, y_array, xlabel=xlabel, ylabel=ylabel, title=filename, show=0, save=1, filename=filename)
|
guan.plot(x_array, y_array, xlabel=xlabel, ylabel=ylabel, title=filename, show=0, save=1, filename=filename)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 将图片制作GIF动画
|
# 将图片制作GIF动画
|
||||||
|
@guan.function_decorator
|
||||||
def make_gif(image_path_array, filename='a', duration=0.1):
|
def make_gif(image_path_array, filename='a', duration=0.1):
|
||||||
import imageio
|
import imageio
|
||||||
images = []
|
images = []
|
||||||
@ -402,34 +395,30 @@ def make_gif(image_path_array, filename='a', duration=0.1):
|
|||||||
im = imageio.imread(image_path)
|
im = imageio.imread(image_path)
|
||||||
images.append(im)
|
images.append(im)
|
||||||
imageio.mimsave(filename+'.gif', images, 'GIF', duration=duration)
|
imageio.mimsave(filename+'.gif', images, 'GIF', duration=duration)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 选取Matplotlib颜色
|
# 选取Matplotlib颜色
|
||||||
|
@guan.function_decorator
|
||||||
def color_matplotlib():
|
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']
|
color_array = ['tab:blue', 'tab:orange', 'tab:green', 'tab:red', 'tab:purple', 'tab:brown', 'tab:pink', 'tab:gray', 'tab:olive', 'tab:cyan']
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return color_array
|
return color_array
|
||||||
|
|
||||||
# 将变量存到文件
|
# 将变量存到文件
|
||||||
|
@guan.function_decorator
|
||||||
def dump_data(data, filename, file_format='.txt'):
|
def dump_data(data, filename, file_format='.txt'):
|
||||||
import pickle
|
import pickle
|
||||||
with open(filename+file_format, 'wb') as f:
|
with open(filename+file_format, 'wb') as f:
|
||||||
pickle.dump(data, f)
|
pickle.dump(data, f)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 从文件中恢复数据到变量
|
# 从文件中恢复数据到变量
|
||||||
|
@guan.function_decorator
|
||||||
def load_data(filename, file_format='.txt'):
|
def load_data(filename, file_format='.txt'):
|
||||||
import pickle
|
import pickle
|
||||||
with open(filename+file_format, 'rb') as f:
|
with open(filename+file_format, 'rb') as f:
|
||||||
data = pickle.load(f)
|
data = pickle.load(f)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return data
|
return data
|
||||||
|
|
||||||
# 读取文件中的一维数据(一行一组x和y)
|
# 读取文件中的一维数据(一行一组x和y)
|
||||||
|
@guan.function_decorator
|
||||||
def read_one_dimensional_data(filename='a', file_format='.txt'):
|
def read_one_dimensional_data(filename='a', file_format='.txt'):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
f = open(filename+file_format, 'r')
|
f = open(filename+file_format, 'r')
|
||||||
@ -450,11 +439,10 @@ def read_one_dimensional_data(filename='a', file_format='.txt'):
|
|||||||
y_array = [y_row]
|
y_array = [y_row]
|
||||||
else:
|
else:
|
||||||
y_array = np.append(y_array, [y_row], axis=0)
|
y_array = np.append(y_array, [y_row], axis=0)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return x_array, y_array
|
return x_array, y_array
|
||||||
|
|
||||||
# 读取文件中的一维数据(一行一组x和y)(支持复数形式)
|
# 读取文件中的一维数据(一行一组x和y)(支持复数形式)
|
||||||
|
@guan.function_decorator
|
||||||
def read_one_dimensional_complex_data(filename='a', file_format='.txt'):
|
def read_one_dimensional_complex_data(filename='a', file_format='.txt'):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
f = open(filename+file_format, 'r')
|
f = open(filename+file_format, 'r')
|
||||||
@ -475,11 +463,10 @@ def read_one_dimensional_complex_data(filename='a', file_format='.txt'):
|
|||||||
y_array = [y_row]
|
y_array = [y_row]
|
||||||
else:
|
else:
|
||||||
y_array = np.append(y_array, [y_row], axis=0)
|
y_array = np.append(y_array, [y_row], axis=0)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return x_array, y_array
|
return x_array, y_array
|
||||||
|
|
||||||
# 读取文件中的二维数据(第一行和第一列分别为横纵坐标)
|
# 读取文件中的二维数据(第一行和第一列分别为横纵坐标)
|
||||||
|
@guan.function_decorator
|
||||||
def read_two_dimensional_data(filename='a', file_format='.txt'):
|
def read_two_dimensional_data(filename='a', file_format='.txt'):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
f = open(filename+file_format, 'r')
|
f = open(filename+file_format, 'r')
|
||||||
@ -506,11 +493,10 @@ def read_two_dimensional_data(filename='a', file_format='.txt'):
|
|||||||
matrix = [matrix_row]
|
matrix = [matrix_row]
|
||||||
else:
|
else:
|
||||||
matrix = np.append(matrix, [matrix_row], axis=0)
|
matrix = np.append(matrix, [matrix_row], axis=0)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return x_array, y_array, matrix
|
return x_array, y_array, matrix
|
||||||
|
|
||||||
# 读取文件中的二维数据(第一行和第一列分别为横纵坐标)(支持复数形式)
|
# 读取文件中的二维数据(第一行和第一列分别为横纵坐标)(支持复数形式)
|
||||||
|
@guan.function_decorator
|
||||||
def read_two_dimensional_complex_data(filename='a', file_format='.txt'):
|
def read_two_dimensional_complex_data(filename='a', file_format='.txt'):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
f = open(filename+file_format, 'r')
|
f = open(filename+file_format, 'r')
|
||||||
@ -537,34 +523,30 @@ def read_two_dimensional_complex_data(filename='a', file_format='.txt'):
|
|||||||
matrix = [matrix_row]
|
matrix = [matrix_row]
|
||||||
else:
|
else:
|
||||||
matrix = np.append(matrix, [matrix_row], axis=0)
|
matrix = np.append(matrix, [matrix_row], axis=0)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return x_array, y_array, matrix
|
return x_array, y_array, matrix
|
||||||
|
|
||||||
# 读取文件中的二维数据(不包括x和y)
|
# 读取文件中的二维数据(不包括x和y)
|
||||||
|
@guan.function_decorator
|
||||||
def read_two_dimensional_data_without_xy_array(filename='a', file_format='.txt'):
|
def read_two_dimensional_data_without_xy_array(filename='a', file_format='.txt'):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
matrix = np.loadtxt(filename+file_format)
|
matrix = np.loadtxt(filename+file_format)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return matrix
|
return matrix
|
||||||
|
|
||||||
# 打开文件用于新增内容
|
# 打开文件用于新增内容
|
||||||
|
@guan.function_decorator
|
||||||
def open_file(filename='a', file_format='.txt'):
|
def open_file(filename='a', file_format='.txt'):
|
||||||
f = open(filename+file_format, 'a', encoding='UTF-8')
|
f = open(filename+file_format, 'a', encoding='UTF-8')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return f
|
return f
|
||||||
|
|
||||||
# 在文件中写入一维数据(一行一组x和y)
|
# 在文件中写入一维数据(一行一组x和y)
|
||||||
|
@guan.function_decorator
|
||||||
def write_one_dimensional_data(x_array, y_array, filename='a', file_format='.txt'):
|
def write_one_dimensional_data(x_array, y_array, filename='a', file_format='.txt'):
|
||||||
import guan
|
import guan
|
||||||
with open(filename+file_format, 'w', encoding='UTF-8') as f:
|
with open(filename+file_format, 'w', encoding='UTF-8') as f:
|
||||||
guan.write_one_dimensional_data_without_opening_file(x_array, y_array, f)
|
guan.write_one_dimensional_data_without_opening_file(x_array, y_array, f)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 在文件中写入一维数据(一行一组x和y)(需要输入已打开的文件)
|
# 在文件中写入一维数据(一行一组x和y)(需要输入已打开的文件)
|
||||||
|
@guan.function_decorator
|
||||||
def write_one_dimensional_data_without_opening_file(x_array, y_array, f):
|
def write_one_dimensional_data_without_opening_file(x_array, y_array, f):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
x_array = np.array(x_array)
|
x_array = np.array(x_array)
|
||||||
@ -579,17 +561,16 @@ def write_one_dimensional_data_without_opening_file(x_array, y_array, f):
|
|||||||
f.write(str(y_array[i0, j0])+' ')
|
f.write(str(y_array[i0, j0])+' ')
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
i0 += 1
|
i0 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 在文件中写入二维数据(第一行和第一列分别为横纵坐标)
|
# 在文件中写入二维数据(第一行和第一列分别为横纵坐标)
|
||||||
|
@guan.function_decorator
|
||||||
def write_two_dimensional_data(x_array, y_array, matrix, filename='a', file_format='.txt'):
|
def write_two_dimensional_data(x_array, y_array, matrix, filename='a', file_format='.txt'):
|
||||||
import guan
|
import guan
|
||||||
with open(filename+file_format, 'w', encoding='UTF-8') as f:
|
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.write_two_dimensional_data_without_opening_file(x_array, y_array, matrix, f)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 在文件中写入二维数据(第一行和第一列分别为横纵坐标)(需要输入已打开的文件)
|
# 在文件中写入二维数据(第一行和第一列分别为横纵坐标)(需要输入已打开的文件)
|
||||||
|
@guan.function_decorator
|
||||||
def write_two_dimensional_data_without_opening_file(x_array, y_array, matrix, f):
|
def write_two_dimensional_data_without_opening_file(x_array, y_array, matrix, f):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
x_array = np.array(x_array)
|
x_array = np.array(x_array)
|
||||||
@ -608,26 +589,25 @@ def write_two_dimensional_data_without_opening_file(x_array, y_array, matrix, f)
|
|||||||
j0 += 1
|
j0 += 1
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
i0 += 1
|
i0 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 在文件中写入二维数据(不包括x和y)
|
# 在文件中写入二维数据(不包括x和y)
|
||||||
|
@guan.function_decorator
|
||||||
def write_two_dimensional_data_without_xy_array(matrix, filename='a', file_format='.txt'):
|
def write_two_dimensional_data_without_xy_array(matrix, filename='a', file_format='.txt'):
|
||||||
import guan
|
import guan
|
||||||
with open(filename+file_format, 'w', encoding='UTF-8') as f:
|
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)
|
guan.write_two_dimensional_data_without_xy_array_and_without_opening_file(matrix, f)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 在文件中写入二维数据(不包括x和y)(需要输入已打开的文件)
|
# 在文件中写入二维数据(不包括x和y)(需要输入已打开的文件)
|
||||||
|
@guan.function_decorator
|
||||||
def write_two_dimensional_data_without_xy_array_and_without_opening_file(matrix, f):
|
def write_two_dimensional_data_without_xy_array_and_without_opening_file(matrix, f):
|
||||||
for row in matrix:
|
for row in matrix:
|
||||||
for element in row:
|
for element in row:
|
||||||
f.write(str(element)+' ')
|
f.write(str(element)+' ')
|
||||||
f.write('\n')
|
f.write('\n')
|
||||||
import guan
|
import guan
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 以显示编号的样式,打印数组
|
# 以显示编号的样式,打印数组
|
||||||
|
@guan.function_decorator
|
||||||
def print_array_with_index(array, show_index=1, index_type=0):
|
def print_array_with_index(array, show_index=1, index_type=0):
|
||||||
if show_index==0:
|
if show_index==0:
|
||||||
for i0 in array:
|
for i0 in array:
|
||||||
@ -643,10 +623,9 @@ def print_array_with_index(array, show_index=1, index_type=0):
|
|||||||
for i0 in array:
|
for i0 in array:
|
||||||
index += 1
|
index += 1
|
||||||
print(index, i0)
|
print(index, i0)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 获取目录中的所有文件名
|
# 获取目录中的所有文件名
|
||||||
|
@guan.function_decorator
|
||||||
def get_all_filenames_in_directory(directory='./', file_format=None):
|
def get_all_filenames_in_directory(directory='./', file_format=None):
|
||||||
import os
|
import os
|
||||||
file_list = []
|
file_list = []
|
||||||
@ -660,6 +639,7 @@ def get_all_filenames_in_directory(directory='./', file_format=None):
|
|||||||
return file_list
|
return file_list
|
||||||
|
|
||||||
# 读取文件夹中某种文本文件类型的文件路径和内容
|
# 读取文件夹中某种文本文件类型的文件路径和内容
|
||||||
|
@guan.function_decorator
|
||||||
def read_text_files_in_directory(directory='./', file_format='.md'):
|
def read_text_files_in_directory(directory='./', file_format='.md'):
|
||||||
import os
|
import os
|
||||||
file_list = []
|
file_list = []
|
||||||
@ -671,11 +651,10 @@ def read_text_files_in_directory(directory='./', file_format='.md'):
|
|||||||
for file in file_list:
|
for file in file_list:
|
||||||
with open(file, 'r') as f:
|
with open(file, 'r') as f:
|
||||||
content_array.append(f.read())
|
content_array.append(f.read())
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return file_list, content_array
|
return file_list, content_array
|
||||||
|
|
||||||
# 在多个文本文件中查找关键词
|
# 在多个文本文件中查找关键词
|
||||||
|
@guan.function_decorator
|
||||||
def find_words_in_multiple_files(words, directory='./', file_format='.md'):
|
def find_words_in_multiple_files(words, directory='./', file_format='.md'):
|
||||||
import guan
|
import guan
|
||||||
file_list, content_array = guan.read_text_files_in_directory(directory=directory, file_format=file_format)
|
file_list, content_array = guan.read_text_files_in_directory(directory=directory, file_format=file_format)
|
||||||
@ -684,10 +663,10 @@ def find_words_in_multiple_files(words, directory='./', file_format='.md'):
|
|||||||
for i0 in range(num_files):
|
for i0 in range(num_files):
|
||||||
if words in content_array[i0]:
|
if words in content_array[i0]:
|
||||||
file_list_with_words.append(file_list[i0])
|
file_list_with_words.append(file_list[i0])
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return file_list_with_words
|
return file_list_with_words
|
||||||
|
|
||||||
# 并行计算前的预处理,把参数分成多份
|
# 并行计算前的预处理,把参数分成多份
|
||||||
|
@guan.function_decorator
|
||||||
def preprocess_for_parallel_calculations(parameter_array_all, cpus=1, task_index=0):
|
def preprocess_for_parallel_calculations(parameter_array_all, cpus=1, task_index=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
num_all = np.array(parameter_array_all).shape[0]
|
num_all = np.array(parameter_array_all).shape[0]
|
||||||
@ -700,36 +679,32 @@ def preprocess_for_parallel_calculations(parameter_array_all, cpus=1, task_index
|
|||||||
parameter_array = parameter_array_all[task_index*num_parameter:(task_index+1)*num_parameter]
|
parameter_array = parameter_array_all[task_index*num_parameter:(task_index+1)*num_parameter]
|
||||||
else:
|
else:
|
||||||
parameter_array = parameter_array_all[task_index*num_parameter:num_all]
|
parameter_array = parameter_array_all[task_index*num_parameter:num_all]
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return parameter_array
|
return parameter_array
|
||||||
|
|
||||||
# 随机获得一个整数,左闭右闭
|
# 随机获得一个整数,左闭右闭
|
||||||
|
@guan.function_decorator
|
||||||
def get_random_number(start=0, end=1):
|
def get_random_number(start=0, end=1):
|
||||||
import random
|
import random
|
||||||
rand_number = random.randint(start, end) # 左闭右闭 [start, end]
|
rand_number = random.randint(start, end) # 左闭右闭 [start, end]
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return rand_number
|
return rand_number
|
||||||
|
|
||||||
# 选取一个种子生成固定的随机整数
|
# 选取一个种子生成固定的随机整数
|
||||||
|
@guan.function_decorator
|
||||||
def generate_random_int_number_for_a_specific_seed(seed=0, x_min=0, x_max=10):
|
def generate_random_int_number_for_a_specific_seed(seed=0, x_min=0, x_max=10):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
np.random.seed(seed)
|
np.random.seed(seed)
|
||||||
rand_num = np.random.randint(x_min, x_max) # 左闭右开[x_min, x_max)
|
rand_num = np.random.randint(x_min, x_max) # 左闭右开[x_min, x_max)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return rand_num
|
return rand_num
|
||||||
|
|
||||||
# 使用jieba软件包进行分词
|
# 使用jieba软件包进行分词
|
||||||
|
@guan.function_decorator
|
||||||
def divide_text_into_words(text):
|
def divide_text_into_words(text):
|
||||||
import jieba
|
import jieba
|
||||||
words = jieba.lcut(text)
|
words = jieba.lcut(text)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return words
|
return words
|
||||||
|
|
||||||
# 判断某个字符是中文还是英文或其他
|
# 判断某个字符是中文还是英文或其他
|
||||||
|
@guan.function_decorator
|
||||||
def check_Chinese_or_English(a):
|
def check_Chinese_or_English(a):
|
||||||
if '\u4e00' <= a <= '\u9fff' :
|
if '\u4e00' <= a <= '\u9fff' :
|
||||||
word_type = 'Chinese'
|
word_type = 'Chinese'
|
||||||
@ -740,6 +715,7 @@ def check_Chinese_or_English(a):
|
|||||||
return word_type
|
return word_type
|
||||||
|
|
||||||
# 统计中英文文本的字数,默认不包括空格
|
# 统计中英文文本的字数,默认不包括空格
|
||||||
|
@guan.function_decorator
|
||||||
def count_words(text, include_space=0, show_words=0):
|
def count_words(text, include_space=0, show_words=0):
|
||||||
import jieba
|
import jieba
|
||||||
import guan
|
import guan
|
||||||
@ -764,46 +740,41 @@ def count_words(text, include_space=0, show_words=0):
|
|||||||
new_words_2.append(word)
|
new_words_2.append(word)
|
||||||
if show_words == 1:
|
if show_words == 1:
|
||||||
print(new_words_2)
|
print(new_words_2)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return num_words
|
return num_words
|
||||||
|
|
||||||
# 将RGB转成HEX
|
# 将RGB转成HEX
|
||||||
|
@guan.function_decorator
|
||||||
def rgb_to_hex(rgb, pound=1):
|
def rgb_to_hex(rgb, pound=1):
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
if pound==0:
|
if pound==0:
|
||||||
return '%02x%02x%02x' % rgb
|
return '%02x%02x%02x' % rgb
|
||||||
else:
|
else:
|
||||||
return '#%02x%02x%02x' % rgb
|
return '#%02x%02x%02x' % rgb
|
||||||
|
|
||||||
# 将HEX转成RGB
|
# 将HEX转成RGB
|
||||||
|
@guan.function_decorator
|
||||||
def hex_to_rgb(hex):
|
def hex_to_rgb(hex):
|
||||||
hex = hex.lstrip('#')
|
hex = hex.lstrip('#')
|
||||||
length = len(hex)
|
length = len(hex)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return tuple(int(hex[i:i+length//3], 16) for i in range(0, length, length//3))
|
return tuple(int(hex[i:i+length//3], 16) for i in range(0, length, length//3))
|
||||||
|
|
||||||
# 使用MD5进行散列加密
|
# 使用MD5进行散列加密
|
||||||
|
@guan.function_decorator
|
||||||
def encryption_MD5(password, salt=''):
|
def encryption_MD5(password, salt=''):
|
||||||
import hashlib
|
import hashlib
|
||||||
password = salt+password
|
password = salt+password
|
||||||
hashed_password = hashlib.md5(password.encode()).hexdigest()
|
hashed_password = hashlib.md5(password.encode()).hexdigest()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hashed_password
|
return hashed_password
|
||||||
|
|
||||||
# 使用SHA-256进行散列加密
|
# 使用SHA-256进行散列加密
|
||||||
|
@guan.function_decorator
|
||||||
def encryption_SHA_256(password, salt=''):
|
def encryption_SHA_256(password, salt=''):
|
||||||
import hashlib
|
import hashlib
|
||||||
password = salt+password
|
password = salt+password
|
||||||
hashed_password = hashlib.sha256(password.encode()).hexdigest()
|
hashed_password = hashlib.sha256(password.encode()).hexdigest()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return hashed_password
|
return hashed_password
|
||||||
|
|
||||||
# 自动先后运行程序
|
# 自动先后运行程序
|
||||||
|
@guan.function_decorator
|
||||||
def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='python ', show_time=0):
|
def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='python ', show_time=0):
|
||||||
import os
|
import os
|
||||||
import time
|
import time
|
||||||
@ -821,25 +792,22 @@ def run_programs_sequentially(program_files=['./a.py', './b.py'], execute='pytho
|
|||||||
if show_time == 1:
|
if show_time == 1:
|
||||||
end = time.time()
|
end = time.time()
|
||||||
print('Total running time = '+str((end-start)/60)+' min')
|
print('Total running time = '+str((end-start)/60)+' min')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 如果不存在文件夹,则新建文件夹
|
# 如果不存在文件夹,则新建文件夹
|
||||||
|
@guan.function_decorator
|
||||||
def make_directory(directory='./test'):
|
def make_directory(directory='./test'):
|
||||||
import os
|
import os
|
||||||
if not os.path.exists(directory):
|
if not os.path.exists(directory):
|
||||||
os.makedirs(directory)
|
os.makedirs(directory)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 复制一份文件
|
# 复制一份文件
|
||||||
|
@guan.function_decorator
|
||||||
def copy_file(file1='./a.txt', file2='./b.txt'):
|
def copy_file(file1='./a.txt', file2='./b.txt'):
|
||||||
import shutil
|
import shutil
|
||||||
shutil.copy(file1, file2)
|
shutil.copy(file1, file2)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 拼接两个PDF文件
|
# 拼接两个PDF文件
|
||||||
|
@guan.function_decorator
|
||||||
def combine_two_pdf_files(input_file_1='a.pdf', input_file_2='b.pdf', output_file='combined_file.pdf'):
|
def combine_two_pdf_files(input_file_1='a.pdf', input_file_2='b.pdf', output_file='combined_file.pdf'):
|
||||||
import PyPDF2
|
import PyPDF2
|
||||||
output_pdf = PyPDF2.PdfWriter()
|
output_pdf = PyPDF2.PdfWriter()
|
||||||
@ -853,5 +821,3 @@ def combine_two_pdf_files(input_file_1='a.pdf', input_file_2='b.pdf', output_fil
|
|||||||
output_pdf.add_page(pdf2.pages[page])
|
output_pdf.add_page(pdf2.pages[page])
|
||||||
with open(output_file, 'wb') as combined_file:
|
with open(output_file, 'wb') as combined_file:
|
||||||
output_pdf.write(combined_file)
|
output_pdf.write(combined_file)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
@ -1,16 +1,18 @@
|
|||||||
# Module: density_of_states
|
# Module: density_of_states
|
||||||
|
import guan
|
||||||
|
|
||||||
# 计算体系的总态密度
|
# 计算体系的总态密度
|
||||||
|
@guan.function_decorator
|
||||||
def total_density_of_states(fermi_energy, hamiltonian, broadening=0.01):
|
def total_density_of_states(fermi_energy, hamiltonian, broadening=0.01):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
import guan
|
import guan
|
||||||
green = guan.green_function(fermi_energy, hamiltonian, broadening)
|
green = guan.green_function(fermi_energy, hamiltonian, broadening)
|
||||||
total_dos = -np.trace(np.imag(green))/math.pi
|
total_dos = -np.trace(np.imag(green))/math.pi
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return total_dos
|
return total_dos
|
||||||
|
|
||||||
# 对于不同费米能,计算体系的总态密度
|
# 对于不同费米能,计算体系的总态密度
|
||||||
|
@guan.function_decorator
|
||||||
def total_density_of_states_with_fermi_energy_array(fermi_energy_array, hamiltonian, broadening=0.01, print_show=0):
|
def total_density_of_states_with_fermi_energy_array(fermi_energy_array, hamiltonian, broadening=0.01, print_show=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -22,10 +24,10 @@ def total_density_of_states_with_fermi_energy_array(fermi_energy_array, hamilton
|
|||||||
print(fermi_energy)
|
print(fermi_energy)
|
||||||
total_dos_array[i0] = guan.total_density_of_states(fermi_energy, hamiltonian, broadening)
|
total_dos_array[i0] = guan.total_density_of_states(fermi_energy, hamiltonian, broadening)
|
||||||
i0 += 1
|
i0 += 1
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return total_dos_array
|
return total_dos_array
|
||||||
|
|
||||||
# 计算方格子的局域态密度(其中,哈密顿量的维度为:dim_hamiltonian = N1*N2*internal_degree)
|
# 计算方格子的局域态密度(其中,哈密顿量的维度为:dim_hamiltonian = N1*N2*internal_degree)
|
||||||
|
@guan.function_decorator
|
||||||
def local_density_of_states_for_square_lattice(fermi_energy, hamiltonian, N1, N2, internal_degree=1, broadening=0.01):
|
def local_density_of_states_for_square_lattice(fermi_energy, hamiltonian, N1, N2, internal_degree=1, broadening=0.01):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
@ -36,10 +38,10 @@ def local_density_of_states_for_square_lattice(fermi_energy, hamiltonian, N1, N2
|
|||||||
for i2 in range(N2):
|
for i2 in range(N2):
|
||||||
for i in range(internal_degree):
|
for i in range(internal_degree):
|
||||||
local_dos[i2, i1] = local_dos[i2, i1]-np.imag(green[i1*N2*internal_degree+i2*internal_degree+i, i1*N2*internal_degree+i2*internal_degree+i])/math.pi
|
local_dos[i2, i1] = local_dos[i2, i1]-np.imag(green[i1*N2*internal_degree+i2*internal_degree+i, i1*N2*internal_degree+i2*internal_degree+i])/math.pi
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return local_dos
|
return local_dos
|
||||||
|
|
||||||
# 计算立方格子的局域态密度(其中,哈密顿量的维度为:dim_hamiltonian = N1*N2*N3*internal_degree)
|
# 计算立方格子的局域态密度(其中,哈密顿量的维度为:dim_hamiltonian = N1*N2*N3*internal_degree)
|
||||||
|
@guan.function_decorator
|
||||||
def local_density_of_states_for_cubic_lattice(fermi_energy, hamiltonian, N1, N2, N3, internal_degree=1, broadening=0.01):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -51,10 +53,10 @@ def local_density_of_states_for_cubic_lattice(fermi_energy, hamiltonian, N1, N2,
|
|||||||
for i3 in range(N3):
|
for i3 in range(N3):
|
||||||
for i in range(internal_degree):
|
for i in range(internal_degree):
|
||||||
local_dos[i3, i2, i1] = local_dos[i3, i2, i1]-np.imag(green[i1*N2*N3*internal_degree+i2*N3*internal_degree+i3*internal_degree+i, i1*N2*N3*internal_degree+i2*N3*internal_degree+i3*internal_degree+i])/math.pi
|
local_dos[i3, i2, i1] = local_dos[i3, i2, i1]-np.imag(green[i1*N2*N3*internal_degree+i2*N3*internal_degree+i3*internal_degree+i, i1*N2*N3*internal_degree+i2*N3*internal_degree+i3*internal_degree+i])/math.pi
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return local_dos
|
return local_dos
|
||||||
|
|
||||||
# 利用Dyson方程,计算方格子的局域态密度(其中,h00的维度为:dim_h00 = N2*internal_degree)
|
# 利用Dyson方程,计算方格子的局域态密度(其中,h00的维度为:dim_h00 = N2*internal_degree)
|
||||||
|
@guan.function_decorator
|
||||||
def local_density_of_states_for_square_lattice_using_dyson_equation(fermi_energy, h00, h01, N2, N1, internal_degree=1, broadening=0.01):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -85,10 +87,10 @@ def local_density_of_states_for_square_lattice_using_dyson_equation(fermi_energy
|
|||||||
for i2 in range(N2):
|
for i2 in range(N2):
|
||||||
for i in range(internal_degree):
|
for i in range(internal_degree):
|
||||||
local_dos[i2, i1] = local_dos[i2, i1] - np.imag(green_ii_n_minus[i2*internal_degree+i, i2*internal_degree+i])/math.pi
|
local_dos[i2, i1] = local_dos[i2, i1] - np.imag(green_ii_n_minus[i2*internal_degree+i, i2*internal_degree+i])/math.pi
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return local_dos
|
return local_dos
|
||||||
|
|
||||||
# 利用Dyson方程,计算立方格子的局域态密度(其中,h00的维度为:dim_h00 = N2*N3*internal_degree)
|
# 利用Dyson方程,计算立方格子的局域态密度(其中,h00的维度为:dim_h00 = N2*N3*internal_degree)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -120,10 +122,10 @@ def local_density_of_states_for_cubic_lattice_using_dyson_equation(fermi_energy,
|
|||||||
for i3 in range(N3):
|
for i3 in range(N3):
|
||||||
for i in range(internal_degree):
|
for i in range(internal_degree):
|
||||||
local_dos[i3, i2, i1] = local_dos[i3, i2, i1] -np.imag(green_ii_n_minus[i2*N3*internal_degree+i3*internal_degree+i, i2*N3*internal_degree+i3*internal_degree+i])/math.pi
|
local_dos[i3, i2, i1] = local_dos[i3, i2, i1] -np.imag(green_ii_n_minus[i2*N3*internal_degree+i3*internal_degree+i, i2*N3*internal_degree+i3*internal_degree+i])/math.pi
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return local_dos
|
return local_dos
|
||||||
|
|
||||||
# 利用Dyson方程,计算方格子条带(考虑了电极自能)的局域态密度(其中,h00的维度为:dim_h00 = N2*internal_degree)
|
# 利用Dyson方程,计算方格子条带(考虑了电极自能)的局域态密度(其中,h00的维度为:dim_h00 = N2*internal_degree)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -160,5 +162,4 @@ def local_density_of_states_for_square_lattice_with_self_energy_using_dyson_equa
|
|||||||
for i2 in range(N2):
|
for i2 in range(N2):
|
||||||
for i in range(internal_degree):
|
for i in range(internal_degree):
|
||||||
local_dos[i2, i1] = local_dos[i2, i1] - np.imag(green_ii_n_minus[i2*internal_degree+i, i2*internal_degree+i])/math.pi
|
local_dos[i2, i1] = local_dos[i2, i1] - np.imag(green_ii_n_minus[i2*internal_degree+i, i2*internal_degree+i])/math.pi
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return local_dos
|
return local_dos
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# Module: others
|
# Module: others
|
||||||
|
import guan
|
||||||
|
|
||||||
# 获取运行的日期和时间并写入文件
|
# 获取运行的日期和时间并写入文件
|
||||||
|
@guan.function_decorator
|
||||||
def statistics_with_day_and_time(content='', filename='a', file_format='.txt'):
|
def statistics_with_day_and_time(content='', filename='a', file_format='.txt'):
|
||||||
import datetime
|
import datetime
|
||||||
datetime_today = str(datetime.date.today())
|
datetime_today = str(datetime.date.today())
|
||||||
@ -10,10 +12,9 @@ def statistics_with_day_and_time(content='', filename='a', file_format='.txt'):
|
|||||||
f2.write(datetime_today+' '+datetime_time+'\n')
|
f2.write(datetime_today+' '+datetime_time+'\n')
|
||||||
else:
|
else:
|
||||||
f2.write(datetime_today+' '+datetime_time+' '+content+'\n')
|
f2.write(datetime_today+' '+datetime_time+' '+content+'\n')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 统计Python文件中import的数量并排序
|
# 统计Python文件中import的数量并排序
|
||||||
|
@guan.function_decorator
|
||||||
def count_number_of_import_statements(filename, file_format='.py', num=1000):
|
def count_number_of_import_statements(filename, file_format='.py', num=1000):
|
||||||
with open(filename+file_format, 'r') as file:
|
with open(filename+file_format, 'r') as file:
|
||||||
lines = file.readlines()
|
lines = file.readlines()
|
||||||
@ -24,27 +25,24 @@ def count_number_of_import_statements(filename, file_format='.py', num=1000):
|
|||||||
import_array.append(line)
|
import_array.append(line)
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
import_statement_counter = Counter(import_array).most_common(num)
|
import_statement_counter = Counter(import_array).most_common(num)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return import_statement_counter
|
return import_statement_counter
|
||||||
|
|
||||||
# 根据一定的字符长度来分割文本
|
# 根据一定的字符长度来分割文本
|
||||||
|
@guan.function_decorator
|
||||||
def split_text(text, wrap_width=3000):
|
def split_text(text, wrap_width=3000):
|
||||||
import textwrap
|
import textwrap
|
||||||
split_text_list = textwrap.wrap(text, wrap_width)
|
split_text_list = textwrap.wrap(text, wrap_width)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return split_text_list
|
return split_text_list
|
||||||
|
|
||||||
# 获取CPU使用率
|
# 获取CPU使用率
|
||||||
|
@guan.function_decorator
|
||||||
def get_cpu_usage(interval=1):
|
def get_cpu_usage(interval=1):
|
||||||
import psutil
|
import psutil
|
||||||
cpu_usage = psutil.cpu_percent(interval=interval)
|
cpu_usage = psutil.cpu_percent(interval=interval)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return cpu_usage
|
return cpu_usage
|
||||||
|
|
||||||
# 获取内存信息
|
# 获取内存信息
|
||||||
|
@guan.function_decorator
|
||||||
def get_memory_info():
|
def get_memory_info():
|
||||||
import psutil
|
import psutil
|
||||||
memory_info = psutil.virtual_memory()
|
memory_info = psutil.virtual_memory()
|
||||||
@ -55,6 +53,7 @@ def get_memory_info():
|
|||||||
return total_memory, used_memory, available_memory, used_memory_percent
|
return total_memory, used_memory, available_memory, used_memory_percent
|
||||||
|
|
||||||
# 获取本月的所有日期
|
# 获取本月的所有日期
|
||||||
|
@guan.function_decorator
|
||||||
def get_days_of_the_current_month(str_or_datetime='str'):
|
def get_days_of_the_current_month(str_or_datetime='str'):
|
||||||
import datetime
|
import datetime
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
@ -71,11 +70,10 @@ def get_days_of_the_current_month(str_or_datetime='str'):
|
|||||||
elif str_or_datetime=='datetime':
|
elif str_or_datetime=='datetime':
|
||||||
day_array.append(current_date)
|
day_array.append(current_date)
|
||||||
current_date += datetime.timedelta(days=1)
|
current_date += datetime.timedelta(days=1)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return day_array
|
return day_array
|
||||||
|
|
||||||
# 获取上个月份
|
# 获取上个月份
|
||||||
|
@guan.function_decorator
|
||||||
def get_last_month():
|
def get_last_month():
|
||||||
import datetime
|
import datetime
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
@ -85,11 +83,10 @@ def get_last_month():
|
|||||||
year_of_last_month = today.year - 1
|
year_of_last_month = today.year - 1
|
||||||
else:
|
else:
|
||||||
year_of_last_month = today.year
|
year_of_last_month = today.year
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return year_of_last_month, last_month
|
return year_of_last_month, last_month
|
||||||
|
|
||||||
# 获取上上个月份
|
# 获取上上个月份
|
||||||
|
@guan.function_decorator
|
||||||
def get_the_month_before_last():
|
def get_the_month_before_last():
|
||||||
import datetime
|
import datetime
|
||||||
today = datetime.date.today()
|
today = datetime.date.today()
|
||||||
@ -104,11 +101,10 @@ def get_the_month_before_last():
|
|||||||
year_of_the_month_before_last = today.year - 1
|
year_of_the_month_before_last = today.year - 1
|
||||||
else:
|
else:
|
||||||
year_of_the_month_before_last = today.year
|
year_of_the_month_before_last = today.year
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return year_of_the_month_before_last, the_month_before_last
|
return year_of_the_month_before_last, the_month_before_last
|
||||||
|
|
||||||
# 获取上个月的所有日期
|
# 获取上个月的所有日期
|
||||||
|
@guan.function_decorator
|
||||||
def get_days_of_the_last_month(str_or_datetime='str'):
|
def get_days_of_the_last_month(str_or_datetime='str'):
|
||||||
import datetime
|
import datetime
|
||||||
import guan
|
import guan
|
||||||
@ -127,10 +123,10 @@ def get_days_of_the_last_month(str_or_datetime='str'):
|
|||||||
elif str_or_datetime=='datetime':
|
elif str_or_datetime=='datetime':
|
||||||
day_array.append(current_date)
|
day_array.append(current_date)
|
||||||
current_date += datetime.timedelta(days=1)
|
current_date += datetime.timedelta(days=1)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return day_array
|
return day_array
|
||||||
|
|
||||||
# 获取上上个月的所有日期
|
# 获取上上个月的所有日期
|
||||||
|
@guan.function_decorator
|
||||||
def get_days_of_the_month_before_last(str_or_datetime='str'):
|
def get_days_of_the_month_before_last(str_or_datetime='str'):
|
||||||
import datetime
|
import datetime
|
||||||
import guan
|
import guan
|
||||||
@ -149,39 +145,38 @@ def get_days_of_the_month_before_last(str_or_datetime='str'):
|
|||||||
elif str_or_datetime=='datetime':
|
elif str_or_datetime=='datetime':
|
||||||
day_array.append(current_date)
|
day_array.append(current_date)
|
||||||
current_date += datetime.timedelta(days=1)
|
current_date += datetime.timedelta(days=1)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return day_array
|
return day_array
|
||||||
|
|
||||||
# 获取所有股票
|
# 获取所有股票
|
||||||
|
@guan.function_decorator
|
||||||
def all_stocks():
|
def all_stocks():
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import akshare as ak
|
import akshare as ak
|
||||||
stocks = ak.stock_zh_a_spot_em()
|
stocks = ak.stock_zh_a_spot_em()
|
||||||
title = np.array(stocks.columns)
|
title = np.array(stocks.columns)
|
||||||
stock_data = stocks.values
|
stock_data = stocks.values
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return title, stock_data
|
return title, stock_data
|
||||||
|
|
||||||
# 获取所有股票的代码
|
# 获取所有股票的代码
|
||||||
|
@guan.function_decorator
|
||||||
def all_stock_symbols():
|
def all_stock_symbols():
|
||||||
import guan
|
import guan
|
||||||
title, stock_data = guan.all_stocks()
|
title, stock_data = guan.all_stocks()
|
||||||
stock_symbols = stock_data[:, 1]
|
stock_symbols = stock_data[:, 1]
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return stock_symbols
|
return stock_symbols
|
||||||
|
|
||||||
# 从股票代码获取股票名称
|
# 从股票代码获取股票名称
|
||||||
|
@guan.function_decorator
|
||||||
def find_stock_name_from_symbol(symbol='000002'):
|
def find_stock_name_from_symbol(symbol='000002'):
|
||||||
import guan
|
import guan
|
||||||
title, stock_data = guan.all_stocks()
|
title, stock_data = guan.all_stocks()
|
||||||
for stock in stock_data:
|
for stock in stock_data:
|
||||||
if symbol in stock:
|
if symbol in stock:
|
||||||
stock_name = stock[2]
|
stock_name = stock[2]
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return stock_name
|
return stock_name
|
||||||
|
|
||||||
# 获取单个股票的历史数据
|
# 获取单个股票的历史数据
|
||||||
|
@guan.function_decorator
|
||||||
def history_data_of_one_stock(symbol='000002', period='daily', start_date="19000101", end_date='21000101'):
|
def history_data_of_one_stock(symbol='000002', period='daily', start_date="19000101", end_date='21000101'):
|
||||||
# period = 'daily'
|
# period = 'daily'
|
||||||
# period = 'weekly'
|
# period = 'weekly'
|
||||||
@ -191,20 +186,18 @@ def history_data_of_one_stock(symbol='000002', period='daily', start_date="19000
|
|||||||
stock = ak.stock_zh_a_hist(symbol=symbol, period=period, start_date=start_date, end_date=end_date)
|
stock = ak.stock_zh_a_hist(symbol=symbol, period=period, start_date=start_date, end_date=end_date)
|
||||||
title = np.array(stock.columns)
|
title = np.array(stock.columns)
|
||||||
stock_data = stock.values[::-1]
|
stock_data = stock.values[::-1]
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return title, stock_data
|
return title, stock_data
|
||||||
|
|
||||||
# 获取软件包中的所有模块名
|
# 获取软件包中的所有模块名
|
||||||
|
@guan.function_decorator
|
||||||
def get_all_modules_in_one_package(package_name='guan'):
|
def get_all_modules_in_one_package(package_name='guan'):
|
||||||
import pkgutil
|
import pkgutil
|
||||||
package = __import__(package_name)
|
package = __import__(package_name)
|
||||||
module_names = [name for _, name, _ in pkgutil.iter_modules(package.__path__)]
|
module_names = [name for _, name, _ in pkgutil.iter_modules(package.__path__)]
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return module_names
|
return module_names
|
||||||
|
|
||||||
# 获取软件包中一个模块的所有函数名
|
# 获取软件包中一个模块的所有函数名
|
||||||
|
@guan.function_decorator
|
||||||
def get_all_functions_in_one_module(module_name, package_name='guan'):
|
def get_all_functions_in_one_module(module_name, package_name='guan'):
|
||||||
import inspect
|
import inspect
|
||||||
function_names = []
|
function_names = []
|
||||||
@ -212,11 +205,10 @@ def get_all_functions_in_one_module(module_name, package_name='guan'):
|
|||||||
for name, obj in inspect.getmembers(module):
|
for name, obj in inspect.getmembers(module):
|
||||||
if inspect.isfunction(obj):
|
if inspect.isfunction(obj):
|
||||||
function_names.append(name)
|
function_names.append(name)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return function_names
|
return function_names
|
||||||
|
|
||||||
# 获取软件包中的所有函数名
|
# 获取软件包中的所有函数名
|
||||||
|
@guan.function_decorator
|
||||||
def get_all_functions_in_one_package(package_name='guan', print_show=1):
|
def get_all_functions_in_one_package(package_name='guan', print_show=1):
|
||||||
import guan
|
import guan
|
||||||
module_names = guan.get_all_modules_in_one_package(package_name=package_name)
|
module_names = guan.get_all_modules_in_one_package(package_name=package_name)
|
||||||
@ -231,10 +223,10 @@ def get_all_functions_in_one_package(package_name='guan', print_show=1):
|
|||||||
print('function:', name)
|
print('function:', name)
|
||||||
if print_show == 1:
|
if print_show == 1:
|
||||||
print()
|
print()
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return all_function_names
|
return all_function_names
|
||||||
|
|
||||||
# 获取包含某个字符的进程PID值
|
# 获取包含某个字符的进程PID值
|
||||||
|
@guan.function_decorator
|
||||||
def get_PID(name):
|
def get_PID(name):
|
||||||
import subprocess
|
import subprocess
|
||||||
command = "ps -ef | grep "+name
|
command = "ps -ef | grep "+name
|
||||||
@ -244,11 +236,17 @@ def get_PID(name):
|
|||||||
import re
|
import re
|
||||||
ps_ef = re.split(r'\s+', ps_ef)
|
ps_ef = re.split(r'\s+', ps_ef)
|
||||||
id_running = ps_ef[1]
|
id_running = ps_ef[1]
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return id_running
|
return id_running
|
||||||
|
|
||||||
|
# 获取函数的源码
|
||||||
|
@guan.function_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):
|
def run(function_name, args=(), return_show=0, get_print=1):
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
@ -283,10 +281,10 @@ def run(function_name, args=(), return_show=0, get_print=1):
|
|||||||
except:
|
except:
|
||||||
break
|
break
|
||||||
client_socket.close()
|
client_socket.close()
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return return_data
|
return return_data
|
||||||
|
|
||||||
# 在服务器上运行大语言模型,通过Python函数调用(说明:接口服务可能为关闭状态,如果无法使用请联系管理员)
|
# 在服务器上运行大语言模型,通过Python函数调用(说明:接口服务可能为关闭状态,如果无法使用请联系管理员)
|
||||||
|
@guan.function_decorator
|
||||||
def chat(prompt='你好', stream_show=1, top_p=0.8, temperature=0.8):
|
def chat(prompt='你好', stream_show=1, top_p=0.8, temperature=0.8):
|
||||||
import socket
|
import socket
|
||||||
import json
|
import json
|
||||||
@ -321,11 +319,10 @@ def chat(prompt='你好', stream_show=1, top_p=0.8, temperature=0.8):
|
|||||||
except:
|
except:
|
||||||
break
|
break
|
||||||
client_socket.close()
|
client_socket.close()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return response
|
return response
|
||||||
|
|
||||||
# 查找文件名相同的文件
|
# 查找文件名相同的文件
|
||||||
|
@guan.function_decorator
|
||||||
def find_repeated_file_with_same_filename(directory='./', ignored_directory_with_words=[], ignored_file_with_words=[], num=1000):
|
def find_repeated_file_with_same_filename(directory='./', ignored_directory_with_words=[], ignored_file_with_words=[], num=1000):
|
||||||
import os
|
import os
|
||||||
from collections import Counter
|
from collections import Counter
|
||||||
@ -347,11 +344,10 @@ def find_repeated_file_with_same_filename(directory='./', ignored_directory_with
|
|||||||
for item in count_file:
|
for item in count_file:
|
||||||
if item[1]>1:
|
if item[1]>1:
|
||||||
repeated_file.append(item)
|
repeated_file.append(item)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return repeated_file
|
return repeated_file
|
||||||
|
|
||||||
# 统计各个子文件夹中的文件数量
|
# 统计各个子文件夹中的文件数量
|
||||||
|
@guan.function_decorator
|
||||||
def count_file_in_sub_directory(directory='./', sort=0, reverse=1, print_show=1, smaller_than_num=None):
|
def count_file_in_sub_directory(directory='./', sort=0, reverse=1, print_show=1, smaller_than_num=None):
|
||||||
import os
|
import os
|
||||||
import numpy as np
|
import numpy as np
|
||||||
@ -402,12 +398,10 @@ def count_file_in_sub_directory(directory='./', sort=0, reverse=1, print_show=1,
|
|||||||
print(dirs_list[i0])
|
print(dirs_list[i0])
|
||||||
print(count_file_array[i0])
|
print(count_file_array[i0])
|
||||||
print()
|
print()
|
||||||
|
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return sub_directory, num_in_sub_directory
|
return sub_directory, num_in_sub_directory
|
||||||
|
|
||||||
# 改变当前的目录位置
|
# 改变当前的目录位置
|
||||||
|
@guan.function_decorator
|
||||||
def change_directory_by_replacement(current_key_word='code', new_key_word='data'):
|
def change_directory_by_replacement(current_key_word='code', new_key_word='data'):
|
||||||
import os
|
import os
|
||||||
code_path = os.getcwd()
|
code_path = os.getcwd()
|
||||||
@ -416,10 +410,9 @@ def change_directory_by_replacement(current_key_word='code', new_key_word='data'
|
|||||||
if os.path.exists(data_path) == False:
|
if os.path.exists(data_path) == False:
|
||||||
os.makedirs(data_path)
|
os.makedirs(data_path)
|
||||||
os.chdir(data_path)
|
os.chdir(data_path)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 在多个子文件夹中产生必要的文件,例如 readme.md
|
# 在多个子文件夹中产生必要的文件,例如 readme.md
|
||||||
|
@guan.function_decorator
|
||||||
def creat_necessary_file(directory, filename='readme', file_format='.md', content='', overwrite=None, ignored_directory_with_words=[]):
|
def creat_necessary_file(directory, filename='readme', file_format='.md', content='', overwrite=None, ignored_directory_with_words=[]):
|
||||||
import os
|
import os
|
||||||
directory_with_file = []
|
directory_with_file = []
|
||||||
@ -447,20 +440,18 @@ def creat_necessary_file(directory, filename='readme', file_format='.md', conten
|
|||||||
f = open(filename+file_format, 'w', encoding="utf-8")
|
f = open(filename+file_format, 'w', encoding="utf-8")
|
||||||
f.write(content)
|
f.write(content)
|
||||||
f.close()
|
f.close()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 删除特定文件名的文件(慎用)
|
# 删除特定文件名的文件(慎用)
|
||||||
|
@guan.function_decorator
|
||||||
def delete_file_with_specific_name(directory, filename='readme', file_format='.md'):
|
def delete_file_with_specific_name(directory, filename='readme', file_format='.md'):
|
||||||
import os
|
import os
|
||||||
for root, dirs, files in os.walk(directory):
|
for root, dirs, files in os.walk(directory):
|
||||||
for i0 in range(len(files)):
|
for i0 in range(len(files)):
|
||||||
if files[i0] == filename+file_format:
|
if files[i0] == filename+file_format:
|
||||||
os.remove(root+'/'+files[i0])
|
os.remove(root+'/'+files[i0])
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 将所有文件移到根目录(慎用)
|
# 将所有文件移到根目录(慎用)
|
||||||
|
@guan.function_decorator
|
||||||
def move_all_files_to_root_directory(directory):
|
def move_all_files_to_root_directory(directory):
|
||||||
import os
|
import os
|
||||||
import shutil
|
import shutil
|
||||||
@ -473,10 +464,9 @@ def move_all_files_to_root_directory(directory):
|
|||||||
os.rmdir(root)
|
os.rmdir(root)
|
||||||
except:
|
except:
|
||||||
pass
|
pass
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 将文件目录结构写入Markdown文件
|
# 将文件目录结构写入Markdown文件
|
||||||
|
@guan.function_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):
|
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
|
import os
|
||||||
f = open(filename+'.md', 'w', encoding="utf-8")
|
f = open(filename+'.md', 'w', encoding="utf-8")
|
||||||
@ -578,10 +568,9 @@ def write_file_list_in_markdown(directory='./', filename='a', reverse_positive_o
|
|||||||
f.write('#')
|
f.write('#')
|
||||||
f.write('###### '+str(filename6)+'\n\n')
|
f.write('###### '+str(filename6)+'\n\n')
|
||||||
f.close()
|
f.close()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 从网页的标签中获取内容
|
# 从网页的标签中获取内容
|
||||||
|
@guan.function_decorator
|
||||||
def get_html_from_tags(link, tags=['title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'a']):
|
def get_html_from_tags(link, tags=['title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6', 'p', 'li', 'a']):
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import urllib.request
|
import urllib.request
|
||||||
@ -597,19 +586,17 @@ def get_html_from_tags(link, tags=['title', 'h1', 'h2', 'h3', 'h4', 'h5', 'h6',
|
|||||||
content = text
|
content = text
|
||||||
else:
|
else:
|
||||||
content = content + '\n\n' + text
|
content = content + '\n\n' + text
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
# 生成二维码
|
# 生成二维码
|
||||||
|
@guan.function_decorator
|
||||||
def creat_qrcode(data="https://www.guanjihuan.com", filename='a', file_format='.png'):
|
def creat_qrcode(data="https://www.guanjihuan.com", filename='a', file_format='.png'):
|
||||||
import qrcode
|
import qrcode
|
||||||
img = qrcode.make(data)
|
img = qrcode.make(data)
|
||||||
img.save(filename+file_format)
|
img.save(filename+file_format)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 将PDF文件转成文本
|
# 将PDF文件转成文本
|
||||||
|
@guan.function_decorator
|
||||||
def pdf_to_text(pdf_path):
|
def pdf_to_text(pdf_path):
|
||||||
from pdfminer.pdfparser import PDFParser, PDFDocument
|
from pdfminer.pdfparser import PDFParser, PDFDocument
|
||||||
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
|
from pdfminer.pdfinterp import PDFResourceManager, PDFPageInterpreter
|
||||||
@ -638,21 +625,19 @@ def pdf_to_text(pdf_path):
|
|||||||
for x in layout:
|
for x in layout:
|
||||||
if isinstance(x, LTTextBox):
|
if isinstance(x, LTTextBox):
|
||||||
content = content + x.get_text().strip()
|
content = content + x.get_text().strip()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return content
|
return content
|
||||||
|
|
||||||
# 获取PDF文件页数
|
# 获取PDF文件页数
|
||||||
|
@guan.function_decorator
|
||||||
def get_pdf_page_number(pdf_path):
|
def get_pdf_page_number(pdf_path):
|
||||||
import PyPDF2
|
import PyPDF2
|
||||||
pdf_file = open(pdf_path, 'rb')
|
pdf_file = open(pdf_path, 'rb')
|
||||||
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
pdf_reader = PyPDF2.PdfReader(pdf_file)
|
||||||
num_pages = len(pdf_reader.pages)
|
num_pages = len(pdf_reader.pages)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return num_pages
|
return num_pages
|
||||||
|
|
||||||
# 获取PDF文件指定页面的内容
|
# 获取PDF文件指定页面的内容
|
||||||
|
@guan.function_decorator
|
||||||
def pdf_to_txt_for_a_specific_page(pdf_path, page_num=1):
|
def pdf_to_txt_for_a_specific_page(pdf_path, page_num=1):
|
||||||
import PyPDF2
|
import PyPDF2
|
||||||
pdf_file = open(pdf_path, 'rb')
|
pdf_file = open(pdf_path, 'rb')
|
||||||
@ -663,11 +648,10 @@ def pdf_to_txt_for_a_specific_page(pdf_path, page_num=1):
|
|||||||
page = pdf_reader.pages[page_num0]
|
page = pdf_reader.pages[page_num0]
|
||||||
page_text = page.extract_text()
|
page_text = page.extract_text()
|
||||||
pdf_file.close()
|
pdf_file.close()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return page_text
|
return page_text
|
||||||
|
|
||||||
# 获取PDF文献中的链接。例如: link_starting_form='https://doi.org'
|
# 获取PDF文献中的链接。例如: link_starting_form='https://doi.org'
|
||||||
|
@guan.function_decorator
|
||||||
def get_links_from_pdf(pdf_path, link_starting_form=''):
|
def get_links_from_pdf(pdf_path, link_starting_form=''):
|
||||||
import PyPDF2
|
import PyPDF2
|
||||||
import re
|
import re
|
||||||
@ -689,11 +673,10 @@ def get_links_from_pdf(pdf_path, link_starting_form=''):
|
|||||||
links.append(u['/A']['/URI'])
|
links.append(u['/A']['/URI'])
|
||||||
i0 += 1
|
i0 += 1
|
||||||
old = u['/A']['/URI']
|
old = u['/A']['/URI']
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return links
|
return links
|
||||||
|
|
||||||
# 通过Sci-Hub网站下载文献
|
# 通过Sci-Hub网站下载文献
|
||||||
|
@guan.function_decorator
|
||||||
def download_with_scihub(address=None, num=1):
|
def download_with_scihub(address=None, num=1):
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import re
|
import re
|
||||||
@ -729,10 +712,9 @@ def download_with_scihub(address=None, num=1):
|
|||||||
print('Completed!\n')
|
print('Completed!\n')
|
||||||
if num != 1:
|
if num != 1:
|
||||||
print('All completed!\n')
|
print('All completed!\n')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 将字符串转成音频
|
# 将字符串转成音频
|
||||||
|
@guan.function_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):
|
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 pyttsx3
|
||||||
import guan
|
import guan
|
||||||
@ -754,9 +736,9 @@ def str_to_audio(str='hello world', filename='str', rate=125, voice=1, read=1, s
|
|||||||
if read==1:
|
if read==1:
|
||||||
engine.say(str)
|
engine.say(str)
|
||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 将txt文件转成音频
|
# 将txt文件转成音频
|
||||||
|
@guan.function_decorator
|
||||||
def txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, compress=0, bitrate='16k', print_text=0):
|
def txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, compress=0, bitrate='16k', print_text=0):
|
||||||
import pyttsx3
|
import pyttsx3
|
||||||
import guan
|
import guan
|
||||||
@ -782,9 +764,9 @@ def txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, compress=0, bitrat
|
|||||||
if read==1:
|
if read==1:
|
||||||
engine.say(text)
|
engine.say(text)
|
||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 将PDF文件转成音频
|
# 将PDF文件转成音频
|
||||||
|
@guan.function_decorator
|
||||||
def pdf_to_audio(pdf_path, rate=125, voice=1, read=1, save=0, compress=0, bitrate='16k', print_text=0):
|
def pdf_to_audio(pdf_path, rate=125, voice=1, read=1, save=0, compress=0, bitrate='16k', print_text=0):
|
||||||
import pyttsx3
|
import pyttsx3
|
||||||
import guan
|
import guan
|
||||||
@ -810,18 +792,17 @@ def pdf_to_audio(pdf_path, rate=125, voice=1, read=1, save=0, compress=0, bitrat
|
|||||||
if read==1:
|
if read==1:
|
||||||
engine.say(text)
|
engine.say(text)
|
||||||
engine.runAndWait()
|
engine.runAndWait()
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 将wav音频文件压缩成MP3音频文件
|
# 将wav音频文件压缩成MP3音频文件
|
||||||
|
@guan.function_decorator
|
||||||
def compress_wav_to_mp3(wav_path, output_filename='a.mp3', bitrate='16k'):
|
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.
|
# 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
|
from pydub import AudioSegment
|
||||||
sound = AudioSegment.from_mp3(wav_path)
|
sound = AudioSegment.from_mp3(wav_path)
|
||||||
sound.export(output_filename,format="mp3",bitrate=bitrate)
|
sound.export(output_filename,format="mp3",bitrate=bitrate)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 播放学术单词
|
# 播放学术单词
|
||||||
|
@guan.function_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):
|
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
|
from bs4 import BeautifulSoup
|
||||||
import re
|
import re
|
||||||
@ -880,10 +861,9 @@ def play_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_translati
|
|||||||
time.sleep(rest_time)
|
time.sleep(rest_time)
|
||||||
pygame.mixer.music.stop()
|
pygame.mixer.music.stop()
|
||||||
print()
|
print()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 播放挑选过后的学术单词
|
# 播放挑选过后的学术单词
|
||||||
|
@guan.function_decorator
|
||||||
def play_selected_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_link=1, rest_time=3):
|
def play_selected_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_link=1, rest_time=3):
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import re
|
import re
|
||||||
@ -938,10 +918,9 @@ def play_selected_academic_words(reverse=0, random_on=0, bre_or_ame='ame', show_
|
|||||||
time.sleep(rest_time)
|
time.sleep(rest_time)
|
||||||
pygame.mixer.music.stop()
|
pygame.mixer.music.stop()
|
||||||
print()
|
print()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 播放元素周期表上的单词
|
# 播放元素周期表上的单词
|
||||||
|
@guan.function_decorator
|
||||||
def play_element_words(random_on=0, show_translation=1, show_link=1, translation_time=2, rest_time=1):
|
def play_element_words(random_on=0, show_translation=1, show_link=1, translation_time=2, rest_time=1):
|
||||||
from bs4 import BeautifulSoup
|
from bs4 import BeautifulSoup
|
||||||
import re
|
import re
|
||||||
@ -995,19 +974,18 @@ def play_element_words(random_on=0, show_translation=1, show_link=1, translation
|
|||||||
time.sleep(rest_time)
|
time.sleep(rest_time)
|
||||||
pygame.mixer.music.stop()
|
pygame.mixer.music.stop()
|
||||||
print()
|
print()
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# Guan软件包的使用统计(不涉及到用户的个人数据)
|
# Guan软件包的使用统计(不涉及到用户的个人数据)
|
||||||
global_variable_of_first_guan_package_calling = []
|
global_variable_of_first_guan_package_calling = []
|
||||||
def statistics_of_guan_package():
|
def statistics_of_guan_package(function_name=None):
|
||||||
import guan
|
import guan
|
||||||
|
if function_name == None:
|
||||||
function_name = guan.get_calling_function_name(layer=2)
|
function_name = guan.get_calling_function_name(layer=2)
|
||||||
|
else:
|
||||||
|
pass
|
||||||
global global_variable_of_first_guan_package_calling
|
global global_variable_of_first_guan_package_calling
|
||||||
if function_name not in 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)
|
global_variable_of_first_guan_package_calling.append(function_name)
|
||||||
function_calling_name = guan.get_calling_function_name(layer=3)
|
|
||||||
if function_calling_name == '<module>':
|
|
||||||
try:
|
try:
|
||||||
import socket
|
import socket
|
||||||
datetime_date = guan.get_date()
|
datetime_date = guan.get_date()
|
||||||
@ -1055,12 +1033,6 @@ def get_mac_address():
|
|||||||
mac_address = '-'.join([mac_address[i:i+2] for i in range(0, 11, 2)])
|
mac_address = '-'.join([mac_address[i:i+2] for i in range(0, 11, 2)])
|
||||||
return mac_address
|
return mac_address
|
||||||
|
|
||||||
# 获取函数的源码
|
|
||||||
def get_function_source(function_name):
|
|
||||||
import inspect
|
|
||||||
function_source = inspect.getsource(function_name)
|
|
||||||
return function_source
|
|
||||||
|
|
||||||
# 获取调用本函数的函数名
|
# 获取调用本函数的函数名
|
||||||
def get_calling_function_name(layer=1):
|
def get_calling_function_name(layer=1):
|
||||||
import inspect
|
import inspect
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
# Module: quantum_transport
|
# Module: quantum_transport
|
||||||
|
import guan
|
||||||
|
|
||||||
# 计算电导
|
# 计算电导
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_conductance(fermi_energy, h00, h01, length=100):
|
def calculate_conductance(fermi_energy, h00, h01, length=100):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import copy
|
import copy
|
||||||
@ -17,10 +19,10 @@ def calculate_conductance(fermi_energy, h00, h01, length=100):
|
|||||||
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
||||||
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
||||||
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance
|
return conductance
|
||||||
|
|
||||||
# 计算不同费米能下的电导
|
# 计算不同费米能下的电导
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_conductance_with_fermi_energy_array(fermi_energy_array, h00, h01, length=100, print_show=0):
|
def calculate_conductance_with_fermi_energy_array(fermi_energy_array, h00, h01, length=100, print_show=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -32,10 +34,10 @@ def calculate_conductance_with_fermi_energy_array(fermi_energy_array, h00, h01,
|
|||||||
if print_show == 1:
|
if print_show == 1:
|
||||||
print(fermi_energy, conductance_array[i0])
|
print(fermi_energy, conductance_array[i0])
|
||||||
i0 += 1
|
i0 += 1
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance_array
|
return conductance_array
|
||||||
|
|
||||||
# 计算在势垒散射下的电导
|
# 计算在势垒散射下的电导
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_conductance_with_barrier(fermi_energy, h00, h01, length=100, barrier_length=20, barrier_potential=1):
|
def calculate_conductance_with_barrier(fermi_energy, h00, h01, length=100, barrier_length=20, barrier_potential=1):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import copy
|
import copy
|
||||||
@ -56,10 +58,10 @@ def calculate_conductance_with_barrier(fermi_energy, h00, h01, length=100, barri
|
|||||||
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
||||||
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
||||||
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance
|
return conductance
|
||||||
|
|
||||||
# 计算在无序散射下的电导
|
# 计算在无序散射下的电导
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_conductance_with_disorder(fermi_energy, h00, h01, disorder_intensity=2.0, disorder_concentration=1.0, length=100, calculation_times=1):
|
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 numpy as np
|
||||||
import copy
|
import copy
|
||||||
@ -85,10 +87,10 @@ def calculate_conductance_with_disorder(fermi_energy, h00, h01, disorder_intensi
|
|||||||
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
||||||
conductance_averaged += conductance
|
conductance_averaged += conductance
|
||||||
conductance_averaged = conductance_averaged/calculation_times
|
conductance_averaged = conductance_averaged/calculation_times
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance_averaged
|
return conductance_averaged
|
||||||
|
|
||||||
# 计算在无序垂直切片的散射下的电导
|
# 计算在无序垂直切片的散射下的电导
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_conductance_with_slice_disorder(fermi_energy, h00, h01, disorder_intensity=2.0, disorder_concentration=1.0, length=100):
|
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 numpy as np
|
||||||
import copy
|
import copy
|
||||||
@ -109,10 +111,10 @@ def calculate_conductance_with_slice_disorder(fermi_energy, h00, h01, disorder_i
|
|||||||
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
||||||
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
||||||
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance
|
return conductance
|
||||||
|
|
||||||
# 计算在无序水平切片的散射下的电导
|
# 计算在无序水平切片的散射下的电导
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import copy
|
import copy
|
||||||
@ -134,10 +136,10 @@ def calculate_conductance_with_disorder_inside_unit_cell_which_keeps_translation
|
|||||||
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
||||||
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
||||||
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance
|
return conductance
|
||||||
|
|
||||||
# 计算在随机空位的散射下的电导
|
# 计算在随机空位的散射下的电导
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_conductance_with_random_vacancy(fermi_energy, h00, h01, vacancy_concentration=0.5, vacancy_potential=1e9, length=100):
|
def calculate_conductance_with_random_vacancy(fermi_energy, h00, h01, vacancy_concentration=0.5, vacancy_potential=1e9, length=100):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import copy
|
import copy
|
||||||
@ -159,10 +161,10 @@ def calculate_conductance_with_random_vacancy(fermi_energy, h00, h01, vacancy_co
|
|||||||
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n, broadening=0, self_energy=right_self_energy)
|
||||||
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
green_0n_n = guan.green_function_in_n(green_0n_n, h01, green_nn_n)
|
||||||
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
conductance = np.trace(np.dot(np.dot(np.dot(gamma_left, green_0n_n), gamma_right), green_0n_n.transpose().conj()))
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance
|
return conductance
|
||||||
|
|
||||||
# 计算在不同无序散射强度下的电导
|
# 计算在不同无序散射强度下的电导
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -176,10 +178,10 @@ def calculate_conductance_with_disorder_intensity_array(fermi_energy, h00, h01,
|
|||||||
print(disorder_intensity, conductance_array[i0]/calculation_times)
|
print(disorder_intensity, conductance_array[i0]/calculation_times)
|
||||||
i0 += 1
|
i0 += 1
|
||||||
conductance_array = conductance_array/calculation_times
|
conductance_array = conductance_array/calculation_times
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance_array
|
return conductance_array
|
||||||
|
|
||||||
# 计算在不同无序浓度下的电导
|
# 计算在不同无序浓度下的电导
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -193,10 +195,10 @@ def calculate_conductance_with_disorder_concentration_array(fermi_energy, h00, h
|
|||||||
print(disorder_concentration, conductance_array[i0]/calculation_times)
|
print(disorder_concentration, conductance_array[i0]/calculation_times)
|
||||||
i0 += 1
|
i0 += 1
|
||||||
conductance_array = conductance_array/calculation_times
|
conductance_array = conductance_array/calculation_times
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance_array
|
return conductance_array
|
||||||
|
|
||||||
# 计算在不同无序散射长度下的电导
|
# 计算在不同无序散射长度下的电导
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -210,10 +212,10 @@ def calculate_conductance_with_scattering_length_array(fermi_energy, h00, h01, l
|
|||||||
print(length, conductance_array[i0]/calculation_times)
|
print(length, conductance_array[i0]/calculation_times)
|
||||||
i0 += 1
|
i0 += 1
|
||||||
conductance_array = conductance_array/calculation_times
|
conductance_array = conductance_array/calculation_times
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return conductance_array
|
return conductance_array
|
||||||
|
|
||||||
# 计算得到Gamma矩阵和格林函数,用于计算六端口的量子输运
|
# 计算得到Gamma矩阵和格林函数,用于计算六端口的量子输运
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -257,10 +259,10 @@ def get_gamma_array_and_green_for_six_terminal_transmission(fermi_energy, h00_fo
|
|||||||
self_energy6, gamma6 = guan.self_energy_of_lead_with_h_lead_to_center(fermi_energy, h00_for_lead_6, h01_for_lead_1, h_lead6_to_center)
|
self_energy6, gamma6 = guan.self_energy_of_lead_with_h_lead_to_center(fermi_energy, h00_for_lead_6, h01_for_lead_1, h_lead6_to_center)
|
||||||
gamma_array = [gamma1, gamma2, gamma3, gamma4, gamma5, gamma6]
|
gamma_array = [gamma1, gamma2, gamma3, gamma4, gamma5, gamma6]
|
||||||
green = np.linalg.inv(fermi_energy*np.eye(internal_degree*width*length)-center_hamiltonian-self_energy1-self_energy2-self_energy3-self_energy4-self_energy5-self_energy6)
|
green = np.linalg.inv(fermi_energy*np.eye(internal_degree*width*length)-center_hamiltonian-self_energy1-self_energy2-self_energy3-self_energy4-self_energy5-self_energy6)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return gamma_array, green
|
return gamma_array, green
|
||||||
|
|
||||||
# 计算六端口的透射矩阵
|
# 计算六端口的透射矩阵
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -282,10 +284,10 @@ def calculate_six_terminal_transmission_matrix(fermi_energy, h00_for_lead_4, h01
|
|||||||
if j0!=i0:
|
if j0!=i0:
|
||||||
transmission_matrix[i0, i0] = transmission_matrix[i0, i0]-transmission_matrix[i0, j0]
|
transmission_matrix[i0, i0] = transmission_matrix[i0, i0]-transmission_matrix[i0, j0]
|
||||||
transmission_matrix = np.real(transmission_matrix)
|
transmission_matrix = np.real(transmission_matrix)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return transmission_matrix
|
return transmission_matrix
|
||||||
|
|
||||||
# 计算从电极1出发的透射系数
|
# 计算从电极1出发的透射系数
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -295,21 +297,20 @@ def calculate_six_terminal_transmissions_from_lead_1(fermi_energy, h00_for_lead_
|
|||||||
transmission_14 = np.real(np.trace(np.dot(np.dot(np.dot(gamma_array[0], green), gamma_array[3]), green.transpose().conj())))
|
transmission_14 = np.real(np.trace(np.dot(np.dot(np.dot(gamma_array[0], green), gamma_array[3]), green.transpose().conj())))
|
||||||
transmission_15 = np.real(np.trace(np.dot(np.dot(np.dot(gamma_array[0], green), gamma_array[4]), green.transpose().conj())))
|
transmission_15 = np.real(np.trace(np.dot(np.dot(np.dot(gamma_array[0], green), gamma_array[4]), green.transpose().conj())))
|
||||||
transmission_16 = np.real(np.trace(np.dot(np.dot(np.dot(gamma_array[0], green), gamma_array[5]), green.transpose().conj())))
|
transmission_16 = np.real(np.trace(np.dot(np.dot(np.dot(gamma_array[0], green), gamma_array[5]), green.transpose().conj())))
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return transmission_12, transmission_13, transmission_14, transmission_15, transmission_16
|
return transmission_12, transmission_13, transmission_14, transmission_15, transmission_16
|
||||||
|
|
||||||
# 通过动量k的虚部,判断通道为传播通道还是衰减通道
|
# 通过动量k的虚部,判断通道为传播通道还是衰减通道
|
||||||
|
@guan.function_decorator
|
||||||
def if_active_channel(k_of_channel):
|
def if_active_channel(k_of_channel):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
if np.abs(np.imag(k_of_channel))<1e-6:
|
if np.abs(np.imag(k_of_channel))<1e-6:
|
||||||
if_active = 1
|
if_active = 1
|
||||||
else:
|
else:
|
||||||
if_active = 0
|
if_active = 0
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return if_active
|
return if_active
|
||||||
|
|
||||||
# 获取通道的动量和速度,用于计算散射矩阵
|
# 获取通道的动量和速度,用于计算散射矩阵
|
||||||
|
@guan.function_decorator
|
||||||
def get_k_and_velocity_of_channel(fermi_energy, h00, h01):
|
def get_k_and_velocity_of_channel(fermi_energy, h00, h01):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
@ -343,10 +344,10 @@ def get_k_and_velocity_of_channel(fermi_energy, h00, h01):
|
|||||||
velocity_of_channel[dim0] = eigenvalue[dim0]*np.dot(np.dot(temp[0:dim, :].transpose().conj(), h01),temp[0:dim, :])[dim0, dim0]
|
velocity_of_channel[dim0] = eigenvalue[dim0]*np.dot(np.dot(temp[0:dim, :].transpose().conj(), h01),temp[0:dim, :])[dim0, dim0]
|
||||||
velocity_of_channel = -2*np.imag(velocity_of_channel)
|
velocity_of_channel = -2*np.imag(velocity_of_channel)
|
||||||
eigenvector = copy.deepcopy(temp)
|
eigenvector = copy.deepcopy(temp)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return k_of_channel, velocity_of_channel, eigenvalue, eigenvector
|
return k_of_channel, velocity_of_channel, eigenvalue, eigenvector
|
||||||
|
|
||||||
# 获取分类后的动量和速度,以及U和F,用于计算散射矩阵
|
# 获取分类后的动量和速度,以及U和F,用于计算散射矩阵
|
||||||
|
@guan.function_decorator
|
||||||
def get_classified_k_velocity_u_and_f(fermi_energy, h00, h01):
|
def get_classified_k_velocity_u_and_f(fermi_energy, h00, h01):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -396,10 +397,10 @@ def get_classified_k_velocity_u_and_f(fermi_energy, h00, h01):
|
|||||||
lambda_matrix_left = np.diag(lambda_left)
|
lambda_matrix_left = np.diag(lambda_left)
|
||||||
f_right = np.dot(np.dot(u_right, lambda_matrix_right), np.linalg.inv(u_right))
|
f_right = np.dot(np.dot(u_right, lambda_matrix_right), np.linalg.inv(u_right))
|
||||||
f_left = np.dot(np.dot(u_left, lambda_matrix_left), np.linalg.inv(u_left))
|
f_left = np.dot(np.dot(u_left, lambda_matrix_left), np.linalg.inv(u_left))
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
|
return k_right, k_left, velocity_right, velocity_left, f_right, f_left, u_right, u_left, ind_right_active
|
||||||
|
|
||||||
# 计算散射矩阵
|
# 计算散射矩阵
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_scattering_matrix(fermi_energy, h00, h01, length=100):
|
def calculate_scattering_matrix(fermi_energy, h00, h01, length=100):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
@ -442,10 +443,10 @@ def calculate_scattering_matrix(fermi_energy, h00, h01, length=100):
|
|||||||
for sum_of_tran_refl in sum_of_tran_refl_array:
|
for sum_of_tran_refl in sum_of_tran_refl_array:
|
||||||
if sum_of_tran_refl > 1.001:
|
if sum_of_tran_refl > 1.001:
|
||||||
print('Error Alert: scattering matrix is not normalized!')
|
print('Error Alert: scattering matrix is not normalized!')
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
|
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
|
||||||
|
|
||||||
# 从散射矩阵中,获取散射矩阵的信息
|
# 从散射矩阵中,获取散射矩阵的信息
|
||||||
|
@guan.function_decorator
|
||||||
def information_of_scattering_matrix(transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active):
|
def information_of_scattering_matrix(transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
if np.array(transmission_matrix).shape==():
|
if np.array(transmission_matrix).shape==():
|
||||||
@ -464,22 +465,20 @@ def information_of_scattering_matrix(transmission_matrix, reflection_matrix, k_r
|
|||||||
total_conductance = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])))
|
total_conductance = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])))
|
||||||
total_reflection_of_channels = np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)
|
total_reflection_of_channels = np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)
|
||||||
sum_of_transmission_and_reflection_of_channels = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) + np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)
|
sum_of_transmission_and_reflection_of_channels = np.sum(np.square(np.abs(transmission_matrix[0:ind_right_active, 0:ind_right_active])), axis=0) + np.sum(np.square(np.abs(reflection_matrix[0:ind_right_active, 0:ind_right_active])), axis=0)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
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
|
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,计算散射矩阵并获得散射矩阵的信息
|
# 已知h00和h01,计算散射矩阵并获得散射矩阵的信息
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_scattering_matrix_and_get_information(fermi_energy, h00, h01, length=100):
|
def calculate_scattering_matrix_and_get_information(fermi_energy, h00, h01, length=100):
|
||||||
import guan
|
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)
|
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)
|
||||||
|
|
||||||
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.information_of_scattering_matrix(transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active)
|
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.information_of_scattering_matrix(transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active)
|
||||||
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
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
|
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
|
||||||
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'):
|
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:
|
if print_show == 1:
|
||||||
print('\nActive channel (left or right) = ', number_of_active_channels)
|
print('\nActive channel (left or right) = ', number_of_active_channels)
|
||||||
@ -522,10 +521,9 @@ def print_or_write_scattering_matrix_with_information_of_scattering_matrix(numbe
|
|||||||
f.write('\n')
|
f.write('\n')
|
||||||
f.write('Total transmission of channels:\n'+str(total_transmission_of_channels)+'\n')
|
f.write('Total transmission of channels:\n'+str(total_transmission_of_channels)+'\n')
|
||||||
f.write('Total conductance = '+str(total_conductance)+'\n')
|
f.write('Total conductance = '+str(total_conductance)+'\n')
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
|
|
||||||
# 已知h00和h01,计算散射矩阵并打印出散射矩阵的信息
|
# 已知h00和h01,计算散射矩阵并打印出散射矩阵的信息
|
||||||
|
@guan.function_decorator
|
||||||
def print_or_write_scattering_matrix(fermi_energy, h00, h01, length=100, print_show=1, write_file=0, filename='a', file_format='.txt'):
|
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
|
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)
|
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)
|
||||||
@ -534,9 +532,8 @@ 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.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_of_guan_package()
|
|
||||||
|
|
||||||
# 在无序下,计算散射矩阵
|
# 在无序下,计算散射矩阵
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_scattering_matrix_with_disorder(fermi_energy, h00, h01, length=100, disorder_intensity=2.0, disorder_concentration=1.0):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -583,10 +580,10 @@ def calculate_scattering_matrix_with_disorder(fermi_energy, h00, h01, length=100
|
|||||||
for sum_of_tran_refl in sum_of_tran_refl_array:
|
for sum_of_tran_refl in sum_of_tran_refl_array:
|
||||||
if sum_of_tran_refl > 1.001:
|
if sum_of_tran_refl > 1.001:
|
||||||
print('Error Alert: scattering matrix is not normalized!')
|
print('Error Alert: scattering matrix is not normalized!')
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
|
return transmission_matrix, reflection_matrix, k_right, k_left, velocity_right, velocity_left, ind_right_active
|
||||||
|
|
||||||
# 在无序下,计算散射矩阵,并获取散射矩阵多次计算的平均信息
|
# 在无序下,计算散射矩阵,并获取散射矩阵多次计算的平均信息
|
||||||
|
@guan.function_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):
|
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
|
import guan
|
||||||
transmission_matrix_for_active_channels_averaged = 0
|
transmission_matrix_for_active_channels_averaged = 0
|
||||||
@ -600,5 +597,4 @@ def calculate_scattering_matrix_with_disorder_and_get_averaged_information(fermi
|
|||||||
reflection_matrix_for_active_channels_averaged += reflection_matrix_for_active_channels
|
reflection_matrix_for_active_channels_averaged += reflection_matrix_for_active_channels
|
||||||
transmission_matrix_for_active_channels_averaged = transmission_matrix_for_active_channels_averaged/calculation_times
|
transmission_matrix_for_active_channels_averaged = transmission_matrix_for_active_channels_averaged/calculation_times
|
||||||
reflection_matrix_for_active_channels_averaged = reflection_matrix_for_active_channels_averaged/calculation_times
|
reflection_matrix_for_active_channels_averaged = reflection_matrix_for_active_channels_averaged/calculation_times
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return transmission_matrix_for_active_channels_averaged, reflection_matrix_for_active_channels_averaged
|
return transmission_matrix_for_active_channels_averaged, reflection_matrix_for_active_channels_averaged
|
@ -1,6 +1,8 @@
|
|||||||
# Module: topological_invariant
|
# Module: topological_invariant
|
||||||
|
import guan
|
||||||
|
|
||||||
# 通过高效法计算方格子的陈数
|
# 通过高效法计算方格子的陈数
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_chern_number_for_square_lattice_with_efficient_method(hamiltonian_function, precision=100, print_show=0):
|
def calculate_chern_number_for_square_lattice_with_efficient_method(hamiltonian_function, precision=100, print_show=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
@ -36,10 +38,10 @@ def calculate_chern_number_for_square_lattice_with_efficient_method(hamiltonian_
|
|||||||
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
||||||
chern_number[i] = chern_number[i] + F
|
chern_number[i] = chern_number[i] + F
|
||||||
chern_number = chern_number/(2*math.pi*1j)
|
chern_number = chern_number/(2*math.pi*1j)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return chern_number
|
return chern_number
|
||||||
|
|
||||||
# 通过高效法计算方格子的陈数(可计算简并的情况)
|
# 通过高效法计算方格子的陈数(可计算简并的情况)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -106,11 +108,10 @@ def calculate_chern_number_for_square_lattice_with_efficient_method_for_degenera
|
|||||||
det_value= det_value*dot_matrix
|
det_value= det_value*dot_matrix
|
||||||
chern_number += cmath.log(det_value)
|
chern_number += cmath.log(det_value)
|
||||||
chern_number = chern_number/(2*math.pi*1j)
|
chern_number = chern_number/(2*math.pi*1j)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return chern_number
|
return chern_number
|
||||||
|
|
||||||
# 通过Wilson loop方法计算方格子的陈数
|
# 通过Wilson loop方法计算方格子的陈数
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -152,11 +153,10 @@ def calculate_chern_number_for_square_lattice_with_wilson_loop(hamiltonian_funct
|
|||||||
arg = np.log(np.diagonal(wilson_loop))/1j
|
arg = np.log(np.diagonal(wilson_loop))/1j
|
||||||
chern_number = chern_number + arg
|
chern_number = chern_number + arg
|
||||||
chern_number = chern_number/(2*math.pi)
|
chern_number = chern_number/(2*math.pi)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return chern_number
|
return chern_number
|
||||||
|
|
||||||
# 通过Wilson loop方法计算方格子的陈数(可计算简并的情况)
|
# 通过Wilson loop方法计算方格子的陈数(可计算简并的情况)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -217,11 +217,10 @@ def calculate_chern_number_for_square_lattice_with_wilson_loop_for_degenerate_ca
|
|||||||
arg = np.log(wilson_loop)/1j
|
arg = np.log(wilson_loop)/1j
|
||||||
chern_number = chern_number + arg
|
chern_number = chern_number + arg
|
||||||
chern_number = chern_number/(2*math.pi)
|
chern_number = chern_number/(2*math.pi)
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return chern_number
|
return chern_number
|
||||||
|
|
||||||
# 通过高效法计算贝利曲率
|
# 通过高效法计算贝利曲率
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_berry_curvature_with_efficient_method(hamiltonian_function, k_min='default', k_max='default', precision=100, print_show=0):
|
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 numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -265,10 +264,10 @@ def calculate_berry_curvature_with_efficient_method(hamiltonian_function, k_min=
|
|||||||
berry_curvature_array[j0, i0, i] = berry_curvature
|
berry_curvature_array[j0, i0, i] = berry_curvature
|
||||||
j0 += 1
|
j0 += 1
|
||||||
i0 += 1
|
i0 += 1
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return k_array, berry_curvature_array
|
return k_array, berry_curvature_array
|
||||||
|
|
||||||
# 通过高效法计算贝利曲率(可计算简并的情况)
|
# 通过高效法计算贝利曲率(可计算简并的情况)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import cmath
|
import cmath
|
||||||
@ -344,11 +343,10 @@ def calculate_berry_curvature_with_efficient_method_for_degenerate_case(hamilton
|
|||||||
berry_curvature_array[j00, i00] = berry_curvature
|
berry_curvature_array[j00, i00] = berry_curvature
|
||||||
j00 += 1
|
j00 += 1
|
||||||
i00 += 1
|
i00 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return k_array, berry_curvature_array
|
return k_array, berry_curvature_array
|
||||||
|
|
||||||
# 通过Wilson loop方法计算贝里曲率
|
# 通过Wilson loop方法计算贝里曲率
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -402,11 +400,10 @@ def calculate_berry_curvature_with_wilson_loop(hamiltonian_function, k_min='defa
|
|||||||
berry_curvature_array[j00, i00, :]=berry_curvature
|
berry_curvature_array[j00, i00, :]=berry_curvature
|
||||||
j00 += 1
|
j00 += 1
|
||||||
i00 += 1
|
i00 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return k_array, berry_curvature_array
|
return k_array, berry_curvature_array
|
||||||
|
|
||||||
# 通过Wilson loop方法计算贝里曲率(可计算简并的情况)
|
# 通过Wilson loop方法计算贝里曲率(可计算简并的情况)
|
||||||
|
@guan.function_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):
|
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 numpy as np
|
||||||
import math
|
import math
|
||||||
@ -475,11 +472,10 @@ def calculate_berry_curvature_with_wilson_loop_for_degenerate_case(hamiltonian_f
|
|||||||
berry_curvature_array[j000, i000]=berry_curvature
|
berry_curvature_array[j000, i000]=berry_curvature
|
||||||
j000 += 1
|
j000 += 1
|
||||||
i000 += 1
|
i000 += 1
|
||||||
import guan
|
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return k_array, berry_curvature_array
|
return k_array, berry_curvature_array
|
||||||
|
|
||||||
# 计算蜂窝格子的陈数(高效法)
|
# 计算蜂窝格子的陈数(高效法)
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_chern_number_for_honeycomb_lattice(hamiltonian_function, a=1, precision=300, print_show=0):
|
def calculate_chern_number_for_honeycomb_lattice(hamiltonian_function, a=1, precision=300, print_show=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import math
|
import math
|
||||||
@ -520,10 +516,10 @@ def calculate_chern_number_for_honeycomb_lattice(hamiltonian_function, a=1, prec
|
|||||||
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
F = cmath.log(Ux*Uy_x*(1/Ux_y)*(1/Uy))
|
||||||
chern_number[i] = chern_number[i] + F
|
chern_number[i] = chern_number[i] + F
|
||||||
chern_number = chern_number/(2*math.pi*1j)
|
chern_number = chern_number/(2*math.pi*1j)
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return chern_number
|
return chern_number
|
||||||
|
|
||||||
# 计算Wilson loop
|
# 计算Wilson loop
|
||||||
|
@guan.function_decorator
|
||||||
def calculate_wilson_loop(hamiltonian_function, k_min='default', k_max='default', precision=100, print_show=0):
|
def calculate_wilson_loop(hamiltonian_function, k_min='default', k_max='default', precision=100, print_show=0):
|
||||||
import numpy as np
|
import numpy as np
|
||||||
import guan
|
import guan
|
||||||
@ -548,5 +544,4 @@ def calculate_wilson_loop(hamiltonian_function, k_min='default', k_max='default'
|
|||||||
for i0 in range(precision-1):
|
for i0 in range(precision-1):
|
||||||
F = np.dot(eigenvector_array[i0+1].transpose().conj(), eigenvector_array[i0])
|
F = np.dot(eigenvector_array[i0+1].transpose().conj(), eigenvector_array[i0])
|
||||||
wilson_loop_array[i] = np.dot(F, wilson_loop_array[i])
|
wilson_loop_array[i] = np.dot(F, wilson_loop_array[i])
|
||||||
guan.statistics_of_guan_package()
|
|
||||||
return wilson_loop_array
|
return wilson_loop_array
|
Loading…
x
Reference in New Issue
Block a user