version-0.0.7
This commit is contained in:
		| @@ -1,7 +1,7 @@ | ||||
| [metadata] | ||||
| # replace with your username: | ||||
| name = guan | ||||
| version = 0.0.6 | ||||
| version = 0.0.7 | ||||
| author = guanjihuan | ||||
| author_email = guanjihuan@163.com | ||||
| description = An open source python package | ||||
|   | ||||
| @@ -8,6 +8,7 @@ from .Hamiltonian_of_finite_size import * | ||||
| from .Hamiltonian_of_models_in_the_reciprocal_space import * | ||||
| from .calculate_band_structures import * | ||||
| from .calculate_wave_functions import * | ||||
| from .find_vector_with_the_same_gauge import * | ||||
| from .calculate_Green_functions import * | ||||
| from .calculate_density_of_states import * | ||||
| from .calculate_conductance import * | ||||
|   | ||||
							
								
								
									
										41
									
								
								PyPI/src/guan/find_vector_with_the_same_gauge.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										41
									
								
								PyPI/src/guan/find_vector_with_the_same_gauge.py
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,41 @@ | ||||
| # 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 | ||||
		Reference in New Issue
	
	Block a user
	 guanjihuan
					guanjihuan