Skip to content

Commit

Permalink
Merge pull request #129 from giovanni-br/PariserParr
Browse files Browse the repository at this point in the history
Pariser parr
  • Loading branch information
RichRick1 authored Jul 22, 2024
2 parents bd293f4 + 5c26051 commit 1e594f9
Show file tree
Hide file tree
Showing 11 changed files with 725 additions and 25 deletions.
6 changes: 3 additions & 3 deletions examples/Demonstration.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@
},
{
"cell_type": "code",
"execution_count": 5,
"execution_count": 1,
"id": "36ebc326",
"metadata": {},
"outputs": [],
Expand Down Expand Up @@ -106,7 +106,7 @@
},
{
"cell_type": "code",
"execution_count": 4,
"execution_count": 2,
"id": "21b6dc5e",
"metadata": {},
"outputs": [
Expand Down Expand Up @@ -417,7 +417,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.11"
}
},
"nbformat": 4,
Expand Down
2 changes: 1 addition & 1 deletion examples/Ising.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -453,7 +453,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.11.5"
"version": "3.10.11"
}
},
"nbformat": 4,
Expand Down
224 changes: 224 additions & 0 deletions examples/TJUV.ipynb
Original file line number Diff line number Diff line change
@@ -0,0 +1,224 @@
{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# TJUV model"
]
},
{
"cell_type": "code",
"execution_count": 6,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Zero energy: 1.5\n",
"One body integrals in spatial basis: \n",
" [[-0.5 -1. 0. 0. 0. -1. ]\n",
" [-1. -0.5 -1. 0. 0. 0. ]\n",
" [ 0. -1. -0.5 -1. 0. 0. ]\n",
" [ 0. 0. -1. -0.5 -1. 0. ]\n",
" [ 0. 0. 0. -1. -0.5 -1. ]\n",
" [-1. 0. 0. 0. -1. -0.5]]\n",
"Shape of two body integral in spatial basis: (6, 6, 6, 6)\n"
]
}
],
"source": [
"import sys \n",
"sys.path.insert(0, '../')\n",
"import numpy as np\n",
"\n",
"# Now import the modules from the local moha package\n",
"from moha import HamTJUV\n",
"# Example parameters for the TJUV Hamiltonian\n",
"connectivity= np.array([[0, 1, 0, 0, 0, 1],\n",
" [1, 0, 1, 0, 0, 0],\n",
" [0, 1, 0, 1, 0, 0],\n",
" [0, 0, 1, 0, 1, 0],\n",
" [0, 0, 0, 1, 0, 1],\n",
" [1, 0, 0, 0, 1, 0]])\n",
"\n",
"\n",
"\n",
"\n",
"alpha = 0.0\n",
"beta = -1.0\n",
"u_onsite = np.array([1, 1, 1, 1, 1, 1])\n",
"gamma = None\n",
"charges = 1\n",
"sym = 8\n",
"J_eq = 1\n",
"J_ax = 1\n",
"\n",
"# Initialize the HamTJUV object\n",
"tjuv_hamiltonian = HamTJUV(connectivity=connectivity,\n",
" alpha=alpha,\n",
" beta=beta,\n",
" u_onsite=u_onsite,\n",
" gamma=gamma,\n",
" charges=charges,\n",
" sym=sym,\n",
" J_eq=J_eq,\n",
" J_ax=J_ax)\n",
"\n",
"# Generate integrals\n",
"e0 = tjuv_hamiltonian.generate_zero_body_integral()\n",
"h1 = tjuv_hamiltonian.generate_one_body_integral(dense=True, basis='spatial basis') \n",
"h2 = tjuv_hamiltonian.generate_two_body_integral(dense=True, basis='spatial basis', sym=8)\n",
"\n",
"print(\"Zero energy: \", e0)\n",
"print(\"One body integrals in spatial basis: \\n\", h1)\n",
"print(\"Shape of two body integral in spatial basis: \", h2.shape)"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Numerical energies: [-1. -1. -1. -1.]\n",
"Analytical energies: [-2.0000000e+00 -1.2246468e-16 3.6739404e-16 2.0000000e+00]\n"
]
}
],
"source": [
"import numpy as np\n",
"\n",
"def test_tjuv_energy_spectrum():\n",
" # Define parameters for a simple 1D chain\n",
" N = 4\n",
" t = 1.0\n",
" alpha = -t\n",
" beta = 0.0\n",
" u_onsite = np.zeros(N)\n",
" gamma = None\n",
" charges = None\n",
" sym = None\n",
" J_eq = 0.0\n",
" J_ax = 0.0\n",
"\n",
" # Connectivity matrix for a 1D chain with periodic boundary conditions\n",
" connectivity = np.zeros((N, N))\n",
" for i in range(N):\n",
" connectivity[i, (i + 1) % N] = 1\n",
" connectivity[(i + 1) % N, i] = 1\n",
"\n",
" # Initialize the HamTJUV object\n",
" tjuv_hamiltonian = HamTJUV(connectivity=connectivity,\n",
" alpha=alpha,\n",
" beta=beta,\n",
" u_onsite=u_onsite,\n",
" gamma=gamma,\n",
" charges=charges,\n",
" sym=sym,\n",
" J_eq=J_eq,\n",
" J_ax=J_ax)\n",
"\n",
" # Generate the one-body integral (Hamiltonian matrix)\n",
" tjuv_one_body = tjuv_hamiltonian.generate_one_body_integral(basis='spatial basis', dense=True)\n",
"\n",
" # Calculate the eigenvalues (energy spectrum)\n",
" energies, _ = np.linalg.eigh(tjuv_one_body)\n",
"\n",
" # Analytical energy levels for comparison\n",
" k_vals = np.arange(N)\n",
" analytical_energies = -2 * t * np.cos(2 * np.pi * k_vals / N)\n",
"\n",
" # Sort the energies for comparison\n",
" energies_sorted = np.sort(energies)\n",
" analytical_energies_sorted = np.sort(analytical_energies)\n",
"\n",
" # Print the energy spectrum and analytical values\n",
" print(\"Numerical energies:\", energies_sorted)\n",
" print(\"Analytical energies:\", analytical_energies_sorted)\n",
"\n",
"# Outside of the function, call the test function\n",
"test_tjuv_energy_spectrum()\n"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"One body integrals in spin basis: \n",
" [[-0.25 -1. 0. 0. 0. -1. 0. 0. 0. 0. 0. 0. ]\n",
" [-1. -0.25 -1. 0. 0. 0. 0. 0. 0. 0. 0. 0. ]\n",
" [ 0. -1. -0.25 -1. 0. 0. 0. 0. 0. 0. 0. 0. ]\n",
" [ 0. 0. -1. -0.25 -1. 0. 0. 0. 0. 0. 0. 0. ]\n",
" [ 0. 0. 0. -1. -0.25 -1. 0. 0. 0. 0. 0. 0. ]\n",
" [-1. 0. 0. 0. -1. -0.25 0. 0. 0. 0. 0. 0. ]\n",
" [ 0. 0. 0. 0. 0. 0. -0.25 -1. 0. 0. 0. -1. ]\n",
" [ 0. 0. 0. 0. 0. 0. -1. -0.25 -1. 0. 0. 0. ]\n",
" [ 0. 0. 0. 0. 0. 0. 0. -1. -0.25 -1. 0. 0. ]\n",
" [ 0. 0. 0. 0. 0. 0. 0. 0. -1. -0.25 -1. 0. ]\n",
" [ 0. 0. 0. 0. 0. 0. 0. 0. 0. -1. -0.25 -1. ]\n",
" [ 0. 0. 0. 0. 0. 0. -1. 0. 0. 0. -1. -0.25]]\n",
"Shape of two body integral in spinorbital basis: (12, 12, 12, 12)\n"
]
}
],
"source": [
"alpha = 0.0\n",
"beta = -1.0\n",
"u_onsite = np.array([1, 1, 1, 1, 1, 1])\n",
"gamma = None\n",
"charges = 1\n",
"sym = 8\n",
"J_eq = 0.5 \n",
"J_ax = 0.5 \n",
"\n",
"# Initialize the HamTJUV object\n",
"tjuv_hamiltonian = HamTJUV(connectivity=connectivity,\n",
" alpha=alpha,\n",
" beta=beta,\n",
" u_onsite=u_onsite,\n",
" gamma=gamma,\n",
" charges=charges,\n",
" sym=sym,\n",
" J_eq=J_eq,\n",
" J_ax=J_ax)\n",
"\n",
"h1_spin = tjuv_hamiltonian.generate_one_body_integral(dense=True, basis='spinorbital basis')\n",
"h2_spin = tjuv_hamiltonian.generate_two_body_integral(dense=True, basis='spinorbital basis', sym=4)\n",
"\n",
"print(\"One body integrals in spin basis: \\n\", h1_spin)\n",
"print(\"Shape of two body integral in spinorbital basis: \", h2_spin.shape)"
]
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"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.10.11"
}
},
"nbformat": 4,
"nbformat_minor": 2
}
6 changes: 3 additions & 3 deletions examples/rauk.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -174,10 +174,10 @@
"name": "stdout",
"output_type": "stream",
"text": [
"[[1. 0. 0. 0.]\n",
"[[1. 0. 0. 3.]\n",
" [0. 2. 1. 0.]\n",
" [0. 0. 3. 2.]\n",
" [3. 0. 0. 4.]]\n"
" [0. 1. 3. 2.]\n",
" [3. 0. 2. 4.]]\n"
]
}
],
Expand Down
15 changes: 11 additions & 4 deletions moha/__init__.py
Original file line number Diff line number Diff line change
@@ -1,15 +1,22 @@
r"""Model Hamiltonian module."""


from .hamiltonians import HamPPP, HamHub, HamHuck, \
HamHeisenberg, HamIsing, HamRG

from .hamiltonians import (
HamPPP,
HamHub,
HamHuck,
HamHeisenberg,
HamIsing,
HamRG,
HamTJUV,
)

__all__ = [
"HamPPP",
"HamHub",
"HamHuck",
"HamHeisenberg",
"HamIsing",
"HamRG"
"HamRG",
"HamTJUV",
]
Loading

0 comments on commit 1e594f9

Please sign in to comment.