diff --git a/2024.01.16_GUAN_package_learning/GUAN_package_learning.ipynb b/2024.01.16_GUAN_package_learning/GUAN_package_learning.ipynb new file mode 100644 index 0000000..71a9822 --- /dev/null +++ b/2024.01.16_GUAN_package_learning/GUAN_package_learning.ipynb @@ -0,0 +1,236 @@ +{ + "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", + "guan.plot_contour(range(N1), range(N2), LDOS, 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, precision=0.001)\n", + "print(vector)\n", + "print(np.dot(vector.transpose().conj(), vector), '\\n')\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, precision=0.001)\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 +}