version 0.0.21
This commit is contained in:
		| @@ -1,9 +1,7 @@ | |||||||
| import guan | import guan | ||||||
|  |  | ||||||
| # test    # Source code: https://py.guanjihuan.com/test |  | ||||||
| guan.test() |  | ||||||
|  |  | ||||||
| # basic functions    # Source code: https://py.guanjihuan.com/basic_functions | # basic functions    # Source code: https://py.guanjihuan.com/basic_functions | ||||||
|  | guan.test() | ||||||
| sigma_0 = guan.sigma_0() | sigma_0 = guan.sigma_0() | ||||||
| sigma_x = guan.sigma_x() | sigma_x = guan.sigma_x() | ||||||
| sigma_y = guan.sigma_y() | sigma_y = guan.sigma_y() | ||||||
| @@ -24,8 +22,6 @@ sigma_z0 = guan.sigma_z0() | |||||||
| sigma_zx = guan.sigma_zx() | sigma_zx = guan.sigma_zx() | ||||||
| sigma_zy = guan.sigma_zy() | sigma_zy = guan.sigma_zy() | ||||||
| sigma_zz = guan.sigma_zz() | sigma_zz = guan.sigma_zz() | ||||||
|  |  | ||||||
| # calculate reciprocal lattice vectors    # Source code: https://py.guanjihuan.com/calculate_reciprocal_lattice_vectors |  | ||||||
| b1 = guan.calculate_one_dimensional_reciprocal_lattice_vector(a1) | b1 = guan.calculate_one_dimensional_reciprocal_lattice_vector(a1) | ||||||
| b1, b2 = guan.calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2) | b1, b2 = guan.calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2) | ||||||
| b1, b2, b3 = guan.calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3) | b1, b2, b3 = guan.calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3) | ||||||
| @@ -56,15 +52,11 @@ hamiltonian = guan.hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension(k, | |||||||
| hamiltonian = guan.hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi=pi/4, a=1/sqrt(3)) | hamiltonian = guan.hamiltonian_of_haldane_model(k1, k2, M=2/3, t1=1, t2=1/3, phi=pi/4, a=1/sqrt(3)) | ||||||
| hamiltonian = guan.hamiltonian_of_haldane_model_in_quasi_one_dimension(k, N=10, M=2/3, t1=1, t2=1/3, phi=pi/4) | hamiltonian = guan.hamiltonian_of_haldane_model_in_quasi_one_dimension(k, N=10, M=2/3, t1=1, t2=1/3, phi=pi/4) | ||||||
|  |  | ||||||
| # calculate band structures  # Source code: https://py.guanjihuan.com/calculate_band_structures | # calculate band structures  # Source code: https://py.guanjihuan.com/source-code/calculate_band_structures_and_wave_functions | ||||||
| eigenvalue = guan.calculate_eigenvalue(hamiltonian) | eigenvalue = guan.calculate_eigenvalue(hamiltonian) | ||||||
| eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function) | eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function) | ||||||
| eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function) | eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function) | ||||||
|  |  | ||||||
| # calculate wave functions    # Source code: https://py.guanjihuan.com/calculate_wave_functions |  | ||||||
| eigenvector = guan.calculate_eigenvector(hamiltonian) | eigenvector = guan.calculate_eigenvector(hamiltonian) | ||||||
|  |  | ||||||
| # find vector with the same gauge    # Source code: https://py.guanjihuan.com/find_vector_with_the_same_gauge |  | ||||||
| vector_target = guan.find_vector_with_the_same_gauge_with_binary_search(vector_target, vector_ref, show_error=1, show_times=0, show_phase=0, n_test=10001, precision=1e-6) | vector_target = guan.find_vector_with_the_same_gauge_with_binary_search(vector_target, vector_ref, show_error=1, show_times=0, show_phase=0, n_test=10001, precision=1e-6) | ||||||
| vector = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None) | vector = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None) | ||||||
|  |  | ||||||
| @@ -114,10 +106,8 @@ guan.plot(x_array, y_array, xlabel='x', ylabel='y', title='', filename='a', show | |||||||
| guan.plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, z_min=None, z_max=None) | guan.plot_3d_surface(x_array, y_array, matrix, xlabel='x', ylabel='y', zlabel='z', title='', filename='a', show=1, save=0, z_min=None, z_max=None) | ||||||
| guan.plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0) | guan.plot_contour(x_array, y_array, matrix, xlabel='x', ylabel='y', title='', filename='a', show=1, save=0) | ||||||
|  |  | ||||||
| # download    # Source code: https://py.guanjihuan.com/download | # download    # Source code: https://py.guanjihuan.com/source-code/others | ||||||
| guan.download_with_scihub(address=None, num=1) | guan.download_with_scihub(address=None, num=1) | ||||||
|  |  | ||||||
| # audio    # Source code: https://py.guanjihuan.com/audio |  | ||||||
| guan.str_to_audio(str='hello world', rate=125, voice=1, read=1, save=0, print_text=0) | guan.str_to_audio(str='hello world', rate=125, voice=1, read=1, save=0, print_text=0) | ||||||
| guan.txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, print_text=0) | guan.txt_to_audio(txt_path, rate=125, voice=1, read=1, save=0, print_text=0) | ||||||
| content = guan.pdf_to_text(pdf_path) | content = guan.pdf_to_text(pdf_path) | ||||||
|   | |||||||
| @@ -1,2 +1 @@ | |||||||
| Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. | Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. | ||||||
|  |  | ||||||
|   | |||||||
| @@ -1,7 +1,7 @@ | |||||||
| [metadata] | [metadata] | ||||||
| # replace with your username: | # replace with your username: | ||||||
| name = guan | name = guan | ||||||
| version = 0.0.19 | version = 0.0.21 | ||||||
| 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 | ||||||
|   | |||||||
| @@ -2,15 +2,11 @@ | |||||||
|  |  | ||||||
| # import modules | # import modules | ||||||
|  |  | ||||||
| from .test import * |  | ||||||
| from .basic_functions import * | from .basic_functions import * | ||||||
| from .calculate_reciprocal_lattice_vectors import * |  | ||||||
| from .Fourier_transform import * | from .Fourier_transform import * | ||||||
| from .Hamiltonian_of_finite_size import * | from .Hamiltonian_of_finite_size import * | ||||||
| from .Hamiltonian_of_models_in_the_reciprocal_space import * | from .Hamiltonian_of_models_in_the_reciprocal_space import * | ||||||
| from .calculate_band_structures import * | from .calculate_band_structures_and_wave_functions import * | ||||||
| from .calculate_wave_functions import * |  | ||||||
| from .find_vector_with_the_same_gauge import * |  | ||||||
| from .calculate_Green_functions import * | from .calculate_Green_functions import * | ||||||
| from .calculate_density_of_states import * | from .calculate_density_of_states import * | ||||||
| from .calculate_conductance import * | from .calculate_conductance import * | ||||||
| @@ -19,5 +15,4 @@ from .calculate_Chern_number import * | |||||||
| from .calculate_Wilson_loop import * | from .calculate_Wilson_loop import * | ||||||
| from .read_and_write import * | from .read_and_write import * | ||||||
| from .plot_figures import * | from .plot_figures import * | ||||||
| from .download import * | from .others import * | ||||||
| from .audio import * |  | ||||||
| @@ -4,6 +4,11 @@ | |||||||
|  |  | ||||||
| import numpy as np | import numpy as np | ||||||
|  |  | ||||||
|  | ## test | ||||||
|  |  | ||||||
|  | def test(): | ||||||
|  |     print('\nSuccess in the installation of Guan package!\n') | ||||||
|  |  | ||||||
| ## Pauli matrices | ## Pauli matrices | ||||||
|  |  | ||||||
| def sigma_0(): | def sigma_0(): | ||||||
| @@ -67,3 +72,58 @@ def sigma_zy(): | |||||||
|  |  | ||||||
| def sigma_zz(): | def sigma_zz(): | ||||||
|     return np.kron(sigma_z(), sigma_z()) |     return np.kron(sigma_z(), sigma_z()) | ||||||
|  |  | ||||||
|  | ## calculate reciprocal lattice vectors | ||||||
|  |  | ||||||
|  | def calculate_one_dimensional_reciprocal_lattice_vector(a1): | ||||||
|  |     b1 = 2*np.pi/a1 | ||||||
|  |     return b1 | ||||||
|  |  | ||||||
|  | def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2): | ||||||
|  |     a1 = np.array(a1) | ||||||
|  |     a2 = np.array(a2) | ||||||
|  |     a1 = np.append(a1, 0) | ||||||
|  |     a2 = np.append(a2, 0) | ||||||
|  |     a3 = np.array([0, 0, 1]) | ||||||
|  |     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)) | ||||||
|  |     b1 = np.delete(b1, 2) | ||||||
|  |     b2 = np.delete(b2, 2) | ||||||
|  |     return b1, b2 | ||||||
|  |  | ||||||
|  | def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3): | ||||||
|  |     a1 = np.array(a1) | ||||||
|  |     a2 = np.array(a2) | ||||||
|  |     a3 = np.array(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)) | ||||||
|  |     b3 = 2*np.pi*np.cross(a1, a2)/np.dot(a1, np.cross(a2, a3)) | ||||||
|  |     return b1, b2, b3 | ||||||
|  |  | ||||||
|  | def calculate_one_dimensional_reciprocal_lattice_vector_with_sympy(a1): | ||||||
|  |     import sympy | ||||||
|  |     b1 = 2*sympy.pi/a1 | ||||||
|  |     return b1 | ||||||
|  |  | ||||||
|  | def calculate_two_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2): | ||||||
|  |     import sympy | ||||||
|  |     a1 = sympy.Matrix(1, 3, [a1[0], a1[1], 0]) | ||||||
|  |     a2 = sympy.Matrix(1, 3, [a2[0], a2[1], 0]) | ||||||
|  |     a3 = sympy.Matrix(1, 3, [0, 0, 1]) | ||||||
|  |     cross_a2_a3 = a2.cross(a3) | ||||||
|  |     cross_a3_a1 = a3.cross(a1) | ||||||
|  |     b1 = 2*sympy.pi*cross_a2_a3/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]]) | ||||||
|  |     b2 = sympy.Matrix(1, 2, [b2[0], b2[1]]) | ||||||
|  |     return b1, b2 | ||||||
|  |  | ||||||
|  | def calculate_three_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2, a3): | ||||||
|  |     import sympy | ||||||
|  |     cross_a2_a3 = a2.cross(a3) | ||||||
|  |     cross_a3_a1 = a3.cross(a1) | ||||||
|  |     cross_a1_a2 = a1.cross(a2) | ||||||
|  |     b1 = 2*sympy.pi*cross_a2_a3/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) | ||||||
|  |     return b1, b2, b3 | ||||||
| @@ -1,59 +0,0 @@ | |||||||
| # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. |  | ||||||
|  |  | ||||||
| # calculate band structures |  | ||||||
|  |  | ||||||
| import numpy as np |  | ||||||
|  |  | ||||||
| def calculate_eigenvalue(hamiltonian): |  | ||||||
|     if np.array(hamiltonian).shape==(): |  | ||||||
|         eigenvalue = np.real(hamiltonian) |  | ||||||
|     else: |  | ||||||
|         eigenvalue, eigenvector = np.linalg.eig(hamiltonian) |  | ||||||
|         eigenvalue = np.sort(np.real(eigenvalue)) |  | ||||||
|     return eigenvalue |  | ||||||
|  |  | ||||||
| def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function): |  | ||||||
|     dim_x = np.array(x_array).shape[0] |  | ||||||
|     i0 = 0 |  | ||||||
|     if np.array(hamiltonian_function(0)).shape==(): |  | ||||||
|         eigenvalue_array = np.zeros((dim_x, 1)) |  | ||||||
|         for x0 in x_array: |  | ||||||
|             hamiltonian = hamiltonian_function(x0) |  | ||||||
|             eigenvalue_array[i0, 0] = np.real(hamiltonian) |  | ||||||
|             i0 += 1 |  | ||||||
|     else: |  | ||||||
|         dim = np.array(hamiltonian_function(0)).shape[0] |  | ||||||
|         eigenvalue_array = np.zeros((dim_x, dim)) |  | ||||||
|         for x0 in x_array: |  | ||||||
|             hamiltonian = hamiltonian_function(x0) |  | ||||||
|             eigenvalue, eigenvector = np.linalg.eig(hamiltonian) |  | ||||||
|             eigenvalue_array[i0, :] = np.sort(np.real(eigenvalue[:])) |  | ||||||
|             i0 += 1 |  | ||||||
|     return eigenvalue_array |  | ||||||
|  |  | ||||||
| def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function):   |  | ||||||
|     dim_x = np.array(x_array).shape[0] |  | ||||||
|     dim_y = np.array(y_array).shape[0] |  | ||||||
|     if np.array(hamiltonian_function(0,0)).shape==(): |  | ||||||
|         eigenvalue_array = np.zeros((dim_y, dim_x, 1)) |  | ||||||
|         i0 = 0 |  | ||||||
|         for y0 in y_array: |  | ||||||
|             j0 = 0 |  | ||||||
|             for x0 in x_array: |  | ||||||
|                 hamiltonian = hamiltonian_function(x0, y0) |  | ||||||
|                 eigenvalue_array[i0, j0, 0] = np.real(hamiltonian) |  | ||||||
|                 j0 += 1 |  | ||||||
|             i0 += 1 |  | ||||||
|     else: |  | ||||||
|         dim = np.array(hamiltonian_function(0, 0)).shape[0] |  | ||||||
|         eigenvalue_array = np.zeros((dim_y, dim_x, dim)) |  | ||||||
|         i0 = 0 |  | ||||||
|         for y0 in y_array: |  | ||||||
|             j0 = 0 |  | ||||||
|             for x0 in x_array: |  | ||||||
|                 hamiltonian = hamiltonian_function(x0, y0) |  | ||||||
|                 eigenvalue, eigenvector = np.linalg.eig(hamiltonian) |  | ||||||
|                 eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:])) |  | ||||||
|                 j0 += 1 |  | ||||||
|             i0 += 1 |  | ||||||
|     return eigenvalue_array |  | ||||||
							
								
								
									
										121
									
								
								PyPI/src/guan/calculate_band_structures_and_wave_functions.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										121
									
								
								PyPI/src/guan/calculate_band_structures_and_wave_functions.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,121 @@ | |||||||
|  | # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. | ||||||
|  |  | ||||||
|  | # calculate_band_structures_and_wave_functions | ||||||
|  |  | ||||||
|  | ## calculate band structures | ||||||
|  |  | ||||||
|  | import numpy as np | ||||||
|  | import cmath | ||||||
|  |  | ||||||
|  | def calculate_eigenvalue(hamiltonian): | ||||||
|  |     if np.array(hamiltonian).shape==(): | ||||||
|  |         eigenvalue = np.real(hamiltonian) | ||||||
|  |     else: | ||||||
|  |         eigenvalue, eigenvector = np.linalg.eig(hamiltonian) | ||||||
|  |         eigenvalue = np.sort(np.real(eigenvalue)) | ||||||
|  |     return eigenvalue | ||||||
|  |  | ||||||
|  | def calculate_eigenvalue_with_one_parameter(x_array, hamiltonian_function): | ||||||
|  |     dim_x = np.array(x_array).shape[0] | ||||||
|  |     i0 = 0 | ||||||
|  |     if np.array(hamiltonian_function(0)).shape==(): | ||||||
|  |         eigenvalue_array = np.zeros((dim_x, 1)) | ||||||
|  |         for x0 in x_array: | ||||||
|  |             hamiltonian = hamiltonian_function(x0) | ||||||
|  |             eigenvalue_array[i0, 0] = np.real(hamiltonian) | ||||||
|  |             i0 += 1 | ||||||
|  |     else: | ||||||
|  |         dim = np.array(hamiltonian_function(0)).shape[0] | ||||||
|  |         eigenvalue_array = np.zeros((dim_x, dim)) | ||||||
|  |         for x0 in x_array: | ||||||
|  |             hamiltonian = hamiltonian_function(x0) | ||||||
|  |             eigenvalue, eigenvector = np.linalg.eig(hamiltonian) | ||||||
|  |             eigenvalue_array[i0, :] = np.sort(np.real(eigenvalue[:])) | ||||||
|  |             i0 += 1 | ||||||
|  |     return eigenvalue_array | ||||||
|  |  | ||||||
|  | def calculate_eigenvalue_with_two_parameters(x_array, y_array, hamiltonian_function):   | ||||||
|  |     dim_x = np.array(x_array).shape[0] | ||||||
|  |     dim_y = np.array(y_array).shape[0] | ||||||
|  |     if np.array(hamiltonian_function(0,0)).shape==(): | ||||||
|  |         eigenvalue_array = np.zeros((dim_y, dim_x, 1)) | ||||||
|  |         i0 = 0 | ||||||
|  |         for y0 in y_array: | ||||||
|  |             j0 = 0 | ||||||
|  |             for x0 in x_array: | ||||||
|  |                 hamiltonian = hamiltonian_function(x0, y0) | ||||||
|  |                 eigenvalue_array[i0, j0, 0] = np.real(hamiltonian) | ||||||
|  |                 j0 += 1 | ||||||
|  |             i0 += 1 | ||||||
|  |     else: | ||||||
|  |         dim = np.array(hamiltonian_function(0, 0)).shape[0] | ||||||
|  |         eigenvalue_array = np.zeros((dim_y, dim_x, dim)) | ||||||
|  |         i0 = 0 | ||||||
|  |         for y0 in y_array: | ||||||
|  |             j0 = 0 | ||||||
|  |             for x0 in x_array: | ||||||
|  |                 hamiltonian = hamiltonian_function(x0, y0) | ||||||
|  |                 eigenvalue, eigenvector = np.linalg.eig(hamiltonian) | ||||||
|  |                 eigenvalue_array[i0, j0, :] = np.sort(np.real(eigenvalue[:])) | ||||||
|  |                 j0 += 1 | ||||||
|  |             i0 += 1 | ||||||
|  |     return eigenvalue_array | ||||||
|  |  | ||||||
|  | ## calculate wave functions | ||||||
|  |  | ||||||
|  | def calculate_eigenvector(hamiltonian): | ||||||
|  |     eigenvalue, eigenvector = np.linalg.eig(hamiltonian)  | ||||||
|  |     eigenvector = eigenvector[:, np.argsort(np.real(eigenvalue))]  | ||||||
|  |     return eigenvector | ||||||
|  |  | ||||||
|  | ## find vector with the same gauge | ||||||
|  |  | ||||||
|  | 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=10001, precision=1e-6): | ||||||
|  |     phase_1_pre = 0 | ||||||
|  |     phase_2_pre = np.pi | ||||||
|  |     for i0 in range(n_test): | ||||||
|  |         test_1 = np.sum(np.abs(vector_target*cmath.exp(1j*phase_1_pre) - vector_ref)) | ||||||
|  |         test_2 = np.sum(np.abs(vector_target*cmath.exp(1j*phase_2_pre) - vector_ref)) | ||||||
|  |         if test_1 < precision: | ||||||
|  |             phase = phase_1_pre | ||||||
|  |             if show_times==1: | ||||||
|  |                 print('Binary search times=', i0) | ||||||
|  |             break | ||||||
|  |         if i0 == n_test-1: | ||||||
|  |             phase = phase_1_pre | ||||||
|  |             if show_error==1: | ||||||
|  |                 print('Gauge not found with binary search times=', i0) | ||||||
|  |         if test_1 < test_2: | ||||||
|  |             if i0 == 0: | ||||||
|  |                 phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2 | ||||||
|  |                 phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 | ||||||
|  |             else: | ||||||
|  |                 phase_1 = phase_1_pre | ||||||
|  |                 phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 | ||||||
|  |         else: | ||||||
|  |             if i0 == 0: | ||||||
|  |                 phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 | ||||||
|  |                 phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2 | ||||||
|  |             else: | ||||||
|  |                 phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 | ||||||
|  |                 phase_2 = phase_2_pre  | ||||||
|  |         phase_1_pre = phase_1 | ||||||
|  |         phase_2_pre = phase_2 | ||||||
|  |     vector_target = vector_target*cmath.exp(1j*phase) | ||||||
|  |     if show_phase==1: | ||||||
|  |         print('Phase=', phase)    | ||||||
|  |     return vector_target | ||||||
|  |  | ||||||
|  | def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None): | ||||||
|  |     if index == None: | ||||||
|  |         index = np.argmax(np.abs(vector)) | ||||||
|  |     sign_pre = np.sign(np.imag(vector[index])) | ||||||
|  |     for phase in np.arange(0, 2*np.pi, precision): | ||||||
|  |         sign =  np.sign(np.imag(vector[index]*cmath.exp(1j*phase))) | ||||||
|  |         if np.abs(np.imag(vector[index]*cmath.exp(1j*phase))) < 1e-9 or sign == -sign_pre: | ||||||
|  |             break | ||||||
|  |         sign_pre = sign | ||||||
|  |     vector = vector*cmath.exp(1j*phase) | ||||||
|  |     if np.real(vector[index]) < 0: | ||||||
|  |         vector = -vector | ||||||
|  |     return vector  | ||||||
| @@ -1,59 +0,0 @@ | |||||||
| # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. |  | ||||||
|  |  | ||||||
| # calculate reciprocal lattice vectors |  | ||||||
|  |  | ||||||
| import numpy as np |  | ||||||
| from math import * |  | ||||||
|  |  | ||||||
| def calculate_one_dimensional_reciprocal_lattice_vector(a1): |  | ||||||
|     b1 = 2*pi/a1 |  | ||||||
|     return b1 |  | ||||||
|  |  | ||||||
| def calculate_two_dimensional_reciprocal_lattice_vectors(a1, a2): |  | ||||||
|     a1 = np.array(a1) |  | ||||||
|     a2 = np.array(a2) |  | ||||||
|     a1 = np.append(a1, 0) |  | ||||||
|     a2 = np.append(a2, 0) |  | ||||||
|     a3 = np.array([0, 0, 1]) |  | ||||||
|     b1 = 2*pi*np.cross(a2, a3)/np.dot(a1, np.cross(a2, a3)) |  | ||||||
|     b2 = 2*pi*np.cross(a3, a1)/np.dot(a1, np.cross(a2, a3)) |  | ||||||
|     b1 = np.delete(b1, 2) |  | ||||||
|     b2 = np.delete(b2, 2) |  | ||||||
|     return b1, b2 |  | ||||||
|  |  | ||||||
| def calculate_three_dimensional_reciprocal_lattice_vectors(a1, a2, a3): |  | ||||||
|     a1 = np.array(a1) |  | ||||||
|     a2 = np.array(a2) |  | ||||||
|     a3 = np.array(a3) |  | ||||||
|     b1 = 2*pi*np.cross(a2, a3)/np.dot(a1, np.cross(a2, a3)) |  | ||||||
|     b2 = 2*pi*np.cross(a3, a1)/np.dot(a1, np.cross(a2, a3)) |  | ||||||
|     b3 = 2*pi*np.cross(a1, a2)/np.dot(a1, np.cross(a2, a3)) |  | ||||||
|     return b1, b2, b3 |  | ||||||
|  |  | ||||||
| def calculate_one_dimensional_reciprocal_lattice_vector_with_sympy(a1): |  | ||||||
|     import sympy |  | ||||||
|     b1 = 2*sympy.pi/a1 |  | ||||||
|     return b1 |  | ||||||
|  |  | ||||||
| def calculate_two_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2): |  | ||||||
|     import sympy |  | ||||||
|     a1 = sympy.Matrix(1, 3, [a1[0], a1[1], 0]) |  | ||||||
|     a2 = sympy.Matrix(1, 3, [a2[0], a2[1], 0]) |  | ||||||
|     a3 = sympy.Matrix(1, 3, [0, 0, 1]) |  | ||||||
|     cross_a2_a3 = a2.cross(a3) |  | ||||||
|     cross_a3_a1 = a3.cross(a1) |  | ||||||
|     b1 = 2*sympy.pi*cross_a2_a3/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]]) |  | ||||||
|     b2 = sympy.Matrix(1, 2, [b2[0], b2[1]]) |  | ||||||
|     return b1, b2 |  | ||||||
|  |  | ||||||
| def calculate_three_dimensional_reciprocal_lattice_vectors_with_sympy(a1, a2, a3): |  | ||||||
|     import sympy |  | ||||||
|     cross_a2_a3 = a2.cross(a3) |  | ||||||
|     cross_a3_a1 = a3.cross(a1) |  | ||||||
|     cross_a1_a2 = a1.cross(a2) |  | ||||||
|     b1 = 2*sympy.pi*cross_a2_a3/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) |  | ||||||
|     return b1, b2, b3 |  | ||||||
| @@ -1,10 +0,0 @@ | |||||||
| # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. |  | ||||||
|  |  | ||||||
| # calculate wave functions |  | ||||||
|  |  | ||||||
| import numpy as np |  | ||||||
|  |  | ||||||
| def calculate_eigenvector(hamiltonian): |  | ||||||
|     eigenvalue, eigenvector = np.linalg.eig(hamiltonian)  |  | ||||||
|     eigenvector = eigenvector[:, np.argsort(np.real(eigenvalue))]  |  | ||||||
|     return eigenvector |  | ||||||
| @@ -1,38 +0,0 @@ | |||||||
| # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. |  | ||||||
|  |  | ||||||
| # download |  | ||||||
|  |  | ||||||
| def download_with_scihub(address=None, num=1): |  | ||||||
|     from bs4 import BeautifulSoup |  | ||||||
|     import re |  | ||||||
|     import requests |  | ||||||
|     import os |  | ||||||
|     if num==1 and address!=None: |  | ||||||
|         address_array = [address] |  | ||||||
|     else: |  | ||||||
|         address_array = [] |  | ||||||
|         for i in range(num): |  | ||||||
|             address = input('\nInput:') |  | ||||||
|             address_array.append(address) |  | ||||||
|     for address in address_array: |  | ||||||
|         r = requests.post('https://sci-hub.st/', data={'request': address}) |  | ||||||
|         print('\nResponse:', r) |  | ||||||
|         print('Address:', r.url) |  | ||||||
|         soup = BeautifulSoup(r.text, features='lxml') |  | ||||||
|         pdf_URL = soup.iframe['src'] |  | ||||||
|         if re.search(re.compile('^https:'), pdf_URL): |  | ||||||
|             pass |  | ||||||
|         else: |  | ||||||
|             pdf_URL = 'https:'+pdf_URL |  | ||||||
|         print('PDF address:', pdf_URL) |  | ||||||
|         name = re.search(re.compile('fdp.*?/'),pdf_URL[::-1]).group()[::-1][1::] |  | ||||||
|         print('PDF name:', name) |  | ||||||
|         print('Directory:', os.getcwd()) |  | ||||||
|         print('\nDownloading...') |  | ||||||
|         r = requests.get(pdf_URL, stream=True) |  | ||||||
|         with open(name, 'wb') as f: |  | ||||||
|             for chunk in r.iter_content(chunk_size=32): |  | ||||||
|                 f.write(chunk) |  | ||||||
|         print('Completed!\n') |  | ||||||
|     if num != 1: |  | ||||||
|         print('All completed!\n') |  | ||||||
| @@ -1,57 +0,0 @@ | |||||||
| # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. |  | ||||||
|  |  | ||||||
| # find vector with the same gauge |  | ||||||
|  |  | ||||||
| import numpy as np |  | ||||||
| import cmath |  | ||||||
| from math import * |  | ||||||
|  |  | ||||||
| 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=10001, precision=1e-6): |  | ||||||
|     phase_1_pre = 0 |  | ||||||
|     phase_2_pre = pi |  | ||||||
|     for i0 in range(n_test): |  | ||||||
|         test_1 = np.sum(np.abs(vector_target*cmath.exp(1j*phase_1_pre) - vector_ref)) |  | ||||||
|         test_2 = np.sum(np.abs(vector_target*cmath.exp(1j*phase_2_pre) - vector_ref)) |  | ||||||
|         if test_1 < precision: |  | ||||||
|             phase = phase_1_pre |  | ||||||
|             if show_times==1: |  | ||||||
|                 print('Binary search times=', i0) |  | ||||||
|             break |  | ||||||
|         if i0 == n_test-1: |  | ||||||
|             phase = phase_1_pre |  | ||||||
|             if show_error==1: |  | ||||||
|                 print('Gauge not found with binary search times=', i0) |  | ||||||
|         if test_1 < test_2: |  | ||||||
|             if i0 == 0: |  | ||||||
|                 phase_1 = phase_1_pre-(phase_2_pre-phase_1_pre)/2 |  | ||||||
|                 phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 |  | ||||||
|             else: |  | ||||||
|                 phase_1 = phase_1_pre |  | ||||||
|                 phase_2 = phase_1_pre+(phase_2_pre-phase_1_pre)/2 |  | ||||||
|         else: |  | ||||||
|             if i0 == 0: |  | ||||||
|                 phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 |  | ||||||
|                 phase_2 = phase_2_pre+(phase_2_pre-phase_1_pre)/2 |  | ||||||
|             else: |  | ||||||
|                 phase_1 = phase_2_pre-(phase_2_pre-phase_1_pre)/2 |  | ||||||
|                 phase_2 = phase_2_pre  |  | ||||||
|         phase_1_pre = phase_1 |  | ||||||
|         phase_2_pre = phase_2 |  | ||||||
|     vector_target = vector_target*cmath.exp(1j*phase) |  | ||||||
|     if show_phase==1: |  | ||||||
|         print('Phase=', phase)    |  | ||||||
|     return vector_target |  | ||||||
|  |  | ||||||
| def find_vector_with_fixed_gauge_by_making_one_component_real(vector, precision=0.005, index=None): |  | ||||||
|     if index == None: |  | ||||||
|         index = np.argmax(np.abs(vector)) |  | ||||||
|     sign_pre = np.sign(np.imag(vector[index])) |  | ||||||
|     for phase in np.arange(0, 2*pi, precision): |  | ||||||
|         sign =  np.sign(np.imag(vector[index]*cmath.exp(1j*phase))) |  | ||||||
|         if np.abs(np.imag(vector[index]*cmath.exp(1j*phase))) < 1e-9 or sign == -sign_pre: |  | ||||||
|             break |  | ||||||
|         sign_pre = sign |  | ||||||
|     vector = vector*cmath.exp(1j*phase) |  | ||||||
|     if np.real(vector[index]) < 0: |  | ||||||
|         vector = -vector |  | ||||||
|     return vector  |  | ||||||
| @@ -1,6 +1,45 @@ | |||||||
| # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. | # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. | ||||||
| 
 | 
 | ||||||
| # audio | # others | ||||||
|  | 
 | ||||||
|  | ## download | ||||||
|  | 
 | ||||||
|  | def download_with_scihub(address=None, num=1): | ||||||
|  |     from bs4 import BeautifulSoup | ||||||
|  |     import re | ||||||
|  |     import requests | ||||||
|  |     import os | ||||||
|  |     if num==1 and address!=None: | ||||||
|  |         address_array = [address] | ||||||
|  |     else: | ||||||
|  |         address_array = [] | ||||||
|  |         for i in range(num): | ||||||
|  |             address = input('\nInput:') | ||||||
|  |             address_array.append(address) | ||||||
|  |     for address in address_array: | ||||||
|  |         r = requests.post('https://sci-hub.st/', data={'request': address}) | ||||||
|  |         print('\nResponse:', r) | ||||||
|  |         print('Address:', r.url) | ||||||
|  |         soup = BeautifulSoup(r.text, features='lxml') | ||||||
|  |         pdf_URL = soup.iframe['src'] | ||||||
|  |         if re.search(re.compile('^https:'), pdf_URL): | ||||||
|  |             pass | ||||||
|  |         else: | ||||||
|  |             pdf_URL = 'https:'+pdf_URL | ||||||
|  |         print('PDF address:', pdf_URL) | ||||||
|  |         name = re.search(re.compile('fdp.*?/'),pdf_URL[::-1]).group()[::-1][1::] | ||||||
|  |         print('PDF name:', name) | ||||||
|  |         print('Directory:', os.getcwd()) | ||||||
|  |         print('\nDownloading...') | ||||||
|  |         r = requests.get(pdf_URL, stream=True) | ||||||
|  |         with open(name, 'wb') as f: | ||||||
|  |             for chunk in r.iter_content(chunk_size=32): | ||||||
|  |                 f.write(chunk) | ||||||
|  |         print('Completed!\n') | ||||||
|  |     if num != 1: | ||||||
|  |         print('All completed!\n') | ||||||
|  | 
 | ||||||
|  | ## audio | ||||||
| 
 | 
 | ||||||
| def str_to_audio(str='hello world', rate=125, voice=1, read=1, save=0, print_text=0): | def str_to_audio(str='hello world', rate=125, voice=1, read=1, save=0, print_text=0): | ||||||
|     import pyttsx3 |     import pyttsx3 | ||||||
| @@ -1,6 +0,0 @@ | |||||||
| # Guan is an open-source python package developed and maintained by https://www.guanjihuan.com. The primary location of this package is on website https://py.guanjihuan.com. |  | ||||||
|  |  | ||||||
| # test |  | ||||||
|  |  | ||||||
| def test(): |  | ||||||
|     print('\nSuccess in the installation of Guan package!\n') |  | ||||||
		Reference in New Issue
	
	Block a user
	 guanjihuan
					guanjihuan