From 7d699063ae7cff5f9c5e975e4707972245b9e941 Mon Sep 17 00:00:00 2001 From: guanjihuan <34735497+guanjihuan@users.noreply.github.com> Date: Mon, 19 Jul 2021 23:35:25 +0800 Subject: [PATCH] version-0.0.7 --- API_reference.md | 3 ++ PyPI/setup.cfg | 2 +- PyPI/src/guan/__init__.py | 1 + .../guan/find_vector_with_the_same_gauge.py | 41 +++++++++++++++++++ tutorial.py | 2 +- 5 files changed, 47 insertions(+), 2 deletions(-) create mode 100644 PyPI/src/guan/find_vector_with_the_same_gauge.py diff --git a/API_reference.md b/API_reference.md index 60c4023..c1bb550 100644 --- a/API_reference.md +++ b/API_reference.md @@ -64,6 +64,9 @@ eigenvalue_array = guan.calculate_eigenvalue_with_two_parameters(x, y, hamiltoni # calculate wave functions eigenvector = guan.calculate_eigenvector(hamiltonian) +# find vector with the same gauge +vector_target = 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) + # calculate Green functions green = guan.green_function(fermi_energy, hamiltonian, broadening, self_energy=0) green_nn_n = guan.green_function_nn_n(fermi_energy, h00, h01, green_nn_n_minus, broadening, self_energy=0) diff --git a/PyPI/setup.cfg b/PyPI/setup.cfg index 7138320..bec272a 100644 --- a/PyPI/setup.cfg +++ b/PyPI/setup.cfg @@ -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 diff --git a/PyPI/src/guan/__init__.py b/PyPI/src/guan/__init__.py index 36f09b8..0a762e8 100644 --- a/PyPI/src/guan/__init__.py +++ b/PyPI/src/guan/__init__.py @@ -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 * diff --git a/PyPI/src/guan/find_vector_with_the_same_gauge.py b/PyPI/src/guan/find_vector_with_the_same_gauge.py new file mode 100644 index 0000000..c35af41 --- /dev/null +++ b/PyPI/src/guan/find_vector_with_the_same_gauge.py @@ -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 \ No newline at end of file diff --git a/tutorial.py b/tutorial.py index b42b0b1..60fdd4a 100644 --- a/tutorial.py +++ b/tutorial.py @@ -1,4 +1,4 @@ -# tutorial (NOT for all functions) +# tutorial (not for all functions) import guan import functools