From ca1bb0b8df12ec8e84975e781d46897883b8b719 Mon Sep 17 00:00:00 2001 From: guanjihuan Date: Tue, 2 Apr 2024 13:53:11 +0800 Subject: [PATCH] update --- .../GUAN_package_learning.ipynb | 238 ------------------ .../example_of_array_division.py | 9 + .../example_of_band_structure.py | 14 ++ ...example_of_chern_number_and_wilson_loop.py | 9 + ...le_of_conductance_and_scattering_matrix.py | 12 + .../example_of_dos_calculation.py | 34 +++ .../example_of_gauge_fixing.py | 22 ++ .../example_of_hamiltonian_in_real_space.py | 5 + .../pauli_matrix.py | 4 + 2024.01.16_GUAN_package_learning/test.py | 3 + 2024.01.16_GUAN_package_learning/timer.py | 11 + 11 files changed, 123 insertions(+), 238 deletions(-) delete mode 100644 2024.01.16_GUAN_package_learning/GUAN_package_learning.ipynb create mode 100644 2024.01.16_GUAN_package_learning/example_of_array_division.py create mode 100644 2024.01.16_GUAN_package_learning/example_of_band_structure.py create mode 100644 2024.01.16_GUAN_package_learning/example_of_chern_number_and_wilson_loop.py create mode 100644 2024.01.16_GUAN_package_learning/example_of_conductance_and_scattering_matrix.py create mode 100644 2024.01.16_GUAN_package_learning/example_of_dos_calculation.py create mode 100644 2024.01.16_GUAN_package_learning/example_of_gauge_fixing.py create mode 100644 2024.01.16_GUAN_package_learning/example_of_hamiltonian_in_real_space.py create mode 100644 2024.01.16_GUAN_package_learning/pauli_matrix.py create mode 100644 2024.01.16_GUAN_package_learning/test.py create mode 100644 2024.01.16_GUAN_package_learning/timer.py diff --git a/2024.01.16_GUAN_package_learning/GUAN_package_learning.ipynb b/2024.01.16_GUAN_package_learning/GUAN_package_learning.ipynb deleted file mode 100644 index 3a9a291..0000000 --- a/2024.01.16_GUAN_package_learning/GUAN_package_learning.ipynb +++ /dev/null @@ -1,238 +0,0 @@ -{ - "cells": [ - { - "cell_type": "code", - "execution_count": null, - "id": "4f66c596-dc32-4b03-bf34-726a206eaff5", - "metadata": {}, - "outputs": [], - "source": [ - "# GUAN软件包官网: https://py.guanjihuan.com\n", - "import guan\n", - "guan.test()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "214d56d6-1626-4fce-bc7d-9084c74cf4fc", - "metadata": {}, - "outputs": [], - "source": [ - "# 泡利矩阵\n", - "import guan\n", - "sigma_x = guan.sigma_x()\n", - "print(sigma_x)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "f8727100-fab6-487c-9d50-a9390aabe623", - "metadata": {}, - "outputs": [], - "source": [ - "# 函数的计时器\n", - "import guan\n", - "\n", - "@guan.timer_decorator\n", - "def my_function():\n", - " import time\n", - " time.sleep(2)\n", - " print('Run finished!')\n", - "\n", - "for _ in range(3):\n", - " my_function()" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "2778f460-f8c9-496e-a003-59394379bb20", - "metadata": {}, - "outputs": [], - "source": [ - "# 实空间哈密顿量的示例\n", - "import guan\n", - "print('\\n', guan.hamiltonian_of_finite_size_system_along_one_direction(3), '\\n')\n", - "print(guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(2, 2), '\\n')\n", - "print(guan.hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(2, 2, 2), '\\n')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "a08fb5f1-724c-43b1-ad4a-daa94b9f1605", - "metadata": {}, - "outputs": [], - "source": [ - "# 能带图计算示例\n", - "import guan\n", - "import numpy as np\n", - "k_array = np.linspace(-np.pi, np.pi, 100)\n", - " # one dimensional chain\n", - "hamiltonian_function = guan.one_dimensional_fourier_transform_with_k(unit_cell=0, hopping=1)\n", - "eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(k_array, hamiltonian_function)\n", - "guan.plot(k_array, eigenvalue_array, xlabel='k', ylabel='E', style='-k', fontfamily=None)\n", - "# square lattice ribbon\n", - "eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(k_array, guan.hamiltonian_of_square_lattice_in_quasi_one_dimension)\n", - "guan.plot(k_array, eigenvalue_array, xlabel='k', ylabel='E', style='-k', fontfamily=None)\n", - "# graphene ribbon\n", - "eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(k_array, guan.hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension)\n", - "guan.plot(k_array, eigenvalue_array, xlabel='k', ylabel='E', style='-k', fontfamily=None)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "adc6a47a-8b4f-416f-8bca-65ee2b068fb9", - "metadata": {}, - "outputs": [], - "source": [ - "# 陈数和Wilson loop计算示例\n", - "import guan\n", - "import numpy as np\n", - "chern_number = guan.calculate_chern_number_for_square_lattice_with_efficient_method(guan.hamiltonian_of_one_QAH_model, precision=100)\n", - "print('\\nChern number=', chern_number, '\\n')\n", - "wilson_loop_array = guan.calculate_wilson_loop(guan.hamiltonian_of_ssh_model)\n", - "print('Wilson loop =', wilson_loop_array)\n", - "p = np.log(wilson_loop_array)/2/np.pi/1j\n", - "print('\\np =', p, '\\n')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "44aa1ca5-ca8b-4afc-a719-d40736edeee5", - "metadata": {}, - "outputs": [], - "source": [ - "# 使用格林函数计算态密度示例\n", - "import guan\n", - "import numpy as np\n", - "\n", - "hamiltonian = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(2,2)\n", - "fermi_energy_array = np.linspace(-4, 4, 400)\n", - "total_dos_array = guan.total_density_of_states_with_fermi_energy_array(fermi_energy_array, hamiltonian, broadening=0.1)\n", - "guan.plot(fermi_energy_array, total_dos_array, xlabel='E', ylabel='Total DOS', style='-', fontfamily=None)\n", - "\n", - "fermi_energy = 0\n", - "N1 = 3\n", - "N2 = 4\n", - "hamiltonian = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1,N2)\n", - "LDOS = guan.local_density_of_states_for_square_lattice(fermi_energy, hamiltonian, N1=N1, N2=N2)\n", - "print('square lattice:\\n', LDOS, '\\n')\n", - "h00 = guan.hamiltonian_of_finite_size_system_along_one_direction(N2)\n", - "h01 = np.identity(N2)\n", - "LDOS = guan.local_density_of_states_for_square_lattice_using_dyson_equation(fermi_energy, h00=h00, h01=h01, N2=N2, N1=N1)\n", - "print(LDOS, '\\n\\n')\n", - "LDOS2 = guan.local_density_of_states_for_square_lattice_using_dyson_equation_with_second_method(fermi_energy, h00, h01, N2, N1, internal_degree=1, broadening=0.01)\n", - "print(LDOS2, '\\n\\n')\n", - "guan.plot_contour(range(N1), range(N2), LDOS, fontfamily=None)\n", - "guan.plot_contour(range(N1), range(N2), LDOS2, fontfamily=None)\n", - "\n", - "N1 = 3\n", - "N2 = 4\n", - "N3 = 5\n", - "hamiltonian = guan.hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(N1, N2, N3)\n", - "LDOS = guan.local_density_of_states_for_cubic_lattice(fermi_energy, hamiltonian, N1=N1, N2=N2, N3=N3)\n", - "print('cubic lattice:\\n', LDOS, '\\n')\n", - "h00 = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N2, N3)\n", - "h01 = np.identity(N2*N3)\n", - "LDOS = guan.local_density_of_states_for_cubic_lattice_using_dyson_equation(fermi_energy, h00, h01, N3=N3, N2=N2, N1=N1)\n", - "print(LDOS)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "cdfd4123-dcb2-4dc5-9e48-a35728fd7168", - "metadata": {}, - "outputs": [], - "source": [ - "# 电导和散射矩阵的计算示例\n", - "import guan\n", - "import numpy as np\n", - "\n", - "fermi_energy_array = np.linspace(-4, 4, 400)\n", - "h00 = guan.hamiltonian_of_finite_size_system_along_one_direction(4)\n", - "h01 = np.identity(4)\n", - "conductance_array = guan.calculate_conductance_with_fermi_energy_array(fermi_energy_array, h00, h01)\n", - "guan.plot(fermi_energy_array, conductance_array, xlabel='E', ylabel='Conductance', style='-', fontfamily=None)\n", - "\n", - "fermi_energy = 0\n", - "guan.print_or_write_scattering_matrix(fermi_energy, h00, h01)" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "fd0f2bcc-82cd-4951-8b4b-e6913d767008", - "metadata": {}, - "outputs": [], - "source": [ - "# 波函数规范的选取示例\n", - "import numpy as np\n", - "import cmath\n", - "import guan\n", - "\n", - "# Fixed gauge example 1\n", - "vector = np.array([np.sqrt(0.5), np.sqrt(0.5)])*cmath.exp(np.random.uniform(0, 1)*1j)\n", - "print('\\nExample 1\\n', vector)\n", - "print(np.dot(vector.transpose().conj(), vector), '\\n')\n", - "\n", - "vector = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector)\n", - "print(vector)\n", - "print(np.dot(vector.transpose().conj(), vector), '\\n')\n", - "\n", - "# Fixed gauge example 2\n", - "vector = np.array([1, 0])*cmath.exp(np.random.uniform(0, 1)*1j)\n", - "print('\\nExample 2\\n', vector)\n", - "print(np.dot(vector.transpose().conj(), vector), '\\n')\n", - "\n", - "vector = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector)\n", - "print(vector)\n", - "print(np.dot(vector.transpose().conj(), vector), '\\n')" - ] - }, - { - "cell_type": "code", - "execution_count": null, - "id": "444c5848-c50d-4fb3-b71c-056b5005620b", - "metadata": {}, - "outputs": [], - "source": [ - "# 数组分割示例\n", - "import numpy as np\n", - "import guan\n", - "cpus = 4\n", - "parameter_array_all = np.arange(0, 17, 1) \n", - "for task_index in range(cpus):\n", - " parameter_array = guan.preprocess_for_parallel_calculations(parameter_array_all, cpus, task_index)\n", - " print(parameter_array)\n", - " print()" - ] - } - ], - "metadata": { - "kernelspec": { - "display_name": "Python 3 (ipykernel)", - "language": "python", - "name": "python3" - }, - "language_info": { - "codemirror_mode": { - "name": "ipython", - "version": 3 - }, - "file_extension": ".py", - "mimetype": "text/x-python", - "name": "python", - "nbconvert_exporter": "python", - "pygments_lexer": "ipython3", - "version": "3.11.7" - } - }, - "nbformat": 4, - "nbformat_minor": 5 -} diff --git a/2024.01.16_GUAN_package_learning/example_of_array_division.py b/2024.01.16_GUAN_package_learning/example_of_array_division.py new file mode 100644 index 0000000..6c81c05 --- /dev/null +++ b/2024.01.16_GUAN_package_learning/example_of_array_division.py @@ -0,0 +1,9 @@ +# 数组分割示例 +import numpy as np +import guan +cpus = 4 +parameter_array_all = np.arange(0, 17, 1) +for task_index in range(cpus): + parameter_array = guan.preprocess_for_parallel_calculations(parameter_array_all, cpus, task_index) + print(parameter_array) + print() \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/example_of_band_structure.py b/2024.01.16_GUAN_package_learning/example_of_band_structure.py new file mode 100644 index 0000000..ab9a95d --- /dev/null +++ b/2024.01.16_GUAN_package_learning/example_of_band_structure.py @@ -0,0 +1,14 @@ +# 能带图计算示例 +import guan +import numpy as np +k_array = np.linspace(-np.pi, np.pi, 100) + # one dimensional chain +hamiltonian_function = guan.one_dimensional_fourier_transform_with_k(unit_cell=0, hopping=1) +eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(k_array, hamiltonian_function) +guan.plot(k_array, eigenvalue_array, xlabel='k', ylabel='E', style='-k', fontfamily=None) +# square lattice ribbon +eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(k_array, guan.hamiltonian_of_square_lattice_in_quasi_one_dimension) +guan.plot(k_array, eigenvalue_array, xlabel='k', ylabel='E', style='-k', fontfamily=None) +# graphene ribbon +eigenvalue_array = guan.calculate_eigenvalue_with_one_parameter(k_array, guan.hamiltonian_of_graphene_with_zigzag_in_quasi_one_dimension) +guan.plot(k_array, eigenvalue_array, xlabel='k', ylabel='E', style='-k', fontfamily=None) \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/example_of_chern_number_and_wilson_loop.py b/2024.01.16_GUAN_package_learning/example_of_chern_number_and_wilson_loop.py new file mode 100644 index 0000000..476af8e --- /dev/null +++ b/2024.01.16_GUAN_package_learning/example_of_chern_number_and_wilson_loop.py @@ -0,0 +1,9 @@ +# 陈数和Wilson loop计算示例 +import guan +import numpy as np +chern_number = guan.calculate_chern_number_for_square_lattice_with_efficient_method(guan.hamiltonian_of_one_QAH_model, precision=100) +print('\nChern number=', chern_number, '\n') +wilson_loop_array = guan.calculate_wilson_loop(guan.hamiltonian_of_ssh_model) +print('Wilson loop =', wilson_loop_array) +p = np.log(wilson_loop_array)/2/np.pi/1j +print('\np =', p, '\n') \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/example_of_conductance_and_scattering_matrix.py b/2024.01.16_GUAN_package_learning/example_of_conductance_and_scattering_matrix.py new file mode 100644 index 0000000..f4de06e --- /dev/null +++ b/2024.01.16_GUAN_package_learning/example_of_conductance_and_scattering_matrix.py @@ -0,0 +1,12 @@ +# 电导和散射矩阵的计算示例 +import guan +import numpy as np + +fermi_energy_array = np.linspace(-4, 4, 400) +h00 = guan.hamiltonian_of_finite_size_system_along_one_direction(4) +h01 = np.identity(4) +conductance_array = guan.calculate_conductance_with_fermi_energy_array(fermi_energy_array, h00, h01) +guan.plot(fermi_energy_array, conductance_array, xlabel='E', ylabel='Conductance', style='-', fontfamily=None) + +fermi_energy = 0 +guan.print_or_write_scattering_matrix(fermi_energy, h00, h01) \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/example_of_dos_calculation.py b/2024.01.16_GUAN_package_learning/example_of_dos_calculation.py new file mode 100644 index 0000000..b5acc22 --- /dev/null +++ b/2024.01.16_GUAN_package_learning/example_of_dos_calculation.py @@ -0,0 +1,34 @@ +# 使用格林函数计算态密度示例 +import guan +import numpy as np + +hamiltonian = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(2,2) +fermi_energy_array = np.linspace(-4, 4, 400) +total_dos_array = guan.total_density_of_states_with_fermi_energy_array(fermi_energy_array, hamiltonian, broadening=0.1) +guan.plot(fermi_energy_array, total_dos_array, xlabel='E', ylabel='Total DOS', style='-', fontfamily=None) + +fermi_energy = 0 +N1 = 3 +N2 = 4 +hamiltonian = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N1,N2) +LDOS = guan.local_density_of_states_for_square_lattice(fermi_energy, hamiltonian, N1=N1, N2=N2) +print('square lattice:\n', LDOS, '\n') +h00 = guan.hamiltonian_of_finite_size_system_along_one_direction(N2) +h01 = np.identity(N2) +LDOS = guan.local_density_of_states_for_square_lattice_using_dyson_equation(fermi_energy, h00=h00, h01=h01, N2=N2, N1=N1) +print(LDOS, '\n\n') +LDOS2 = guan.local_density_of_states_for_square_lattice_using_dyson_equation_with_second_method(fermi_energy, h00, h01, N2, N1, internal_degree=1, broadening=0.01) +print(LDOS2, '\n\n') +guan.plot_contour(range(N1), range(N2), LDOS, fontfamily=None) +guan.plot_contour(range(N1), range(N2), LDOS2, fontfamily=None) + +N1 = 3 +N2 = 4 +N3 = 5 +hamiltonian = guan.hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(N1, N2, N3) +LDOS = guan.local_density_of_states_for_cubic_lattice(fermi_energy, hamiltonian, N1=N1, N2=N2, N3=N3) +print('cubic lattice:\n', LDOS, '\n') +h00 = guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(N2, N3) +h01 = np.identity(N2*N3) +LDOS = guan.local_density_of_states_for_cubic_lattice_using_dyson_equation(fermi_energy, h00, h01, N3=N3, N2=N2, N1=N1) +print(LDOS) \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/example_of_gauge_fixing.py b/2024.01.16_GUAN_package_learning/example_of_gauge_fixing.py new file mode 100644 index 0000000..93a3342 --- /dev/null +++ b/2024.01.16_GUAN_package_learning/example_of_gauge_fixing.py @@ -0,0 +1,22 @@ +# 波函数规范的选取示例 +import numpy as np +import cmath +import guan + +# Fixed gauge example 1 +vector = np.array([np.sqrt(0.5), np.sqrt(0.5)])*cmath.exp(np.random.uniform(0, 1)*1j) +print('\nExample 1\n', vector) +print(np.dot(vector.transpose().conj(), vector), '\n') + +vector = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector) +print(vector) +print(np.dot(vector.transpose().conj(), vector), '\n') + +# Fixed gauge example 2 +vector = np.array([1, 0])*cmath.exp(np.random.uniform(0, 1)*1j) +print('\nExample 2\n', vector) +print(np.dot(vector.transpose().conj(), vector), '\n') + +vector = guan.find_vector_with_fixed_gauge_by_making_one_component_real(vector) +print(vector) +print(np.dot(vector.transpose().conj(), vector), '\n') \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/example_of_hamiltonian_in_real_space.py b/2024.01.16_GUAN_package_learning/example_of_hamiltonian_in_real_space.py new file mode 100644 index 0000000..0746a51 --- /dev/null +++ b/2024.01.16_GUAN_package_learning/example_of_hamiltonian_in_real_space.py @@ -0,0 +1,5 @@ +# 实空间哈密顿量的示例 +import guan +print('\n', guan.hamiltonian_of_finite_size_system_along_one_direction(3), '\n') +print(guan.hamiltonian_of_finite_size_system_along_two_directions_for_square_lattice(2, 2), '\n') +print(guan.hamiltonian_of_finite_size_system_along_three_directions_for_cubic_lattice(2, 2, 2), '\n') \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/pauli_matrix.py b/2024.01.16_GUAN_package_learning/pauli_matrix.py new file mode 100644 index 0000000..ded764d --- /dev/null +++ b/2024.01.16_GUAN_package_learning/pauli_matrix.py @@ -0,0 +1,4 @@ +# 泡利矩阵 +import guan +sigma_x = guan.sigma_x() +print(sigma_x) \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/test.py b/2024.01.16_GUAN_package_learning/test.py new file mode 100644 index 0000000..ea3a0e5 --- /dev/null +++ b/2024.01.16_GUAN_package_learning/test.py @@ -0,0 +1,3 @@ +# GUAN软件包官网: https://py.guanjihuan.com +import guan +guan.test() \ No newline at end of file diff --git a/2024.01.16_GUAN_package_learning/timer.py b/2024.01.16_GUAN_package_learning/timer.py new file mode 100644 index 0000000..e4daebc --- /dev/null +++ b/2024.01.16_GUAN_package_learning/timer.py @@ -0,0 +1,11 @@ +# 函数的计时器 +import guan + +@guan.timer_decorator +def my_function(): + import time + time.sleep(2) + print('Run finished!') + +for _ in range(3): + my_function() \ No newline at end of file