Skip to content

Commit 01adce9

Browse files
committed
Add helium atom
1 parent 88e5023 commit 01adce9

File tree

1 file changed

+139
-0
lines changed

1 file changed

+139
-0
lines changed

docs/notebooks/helium_atom.ipynb

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
{
2+
"cells": [
3+
{
4+
"attachments": {},
5+
"cell_type": "markdown",
6+
"metadata": {},
7+
"source": [
8+
"# Helium atom\n",
9+
"\n",
10+
"Once we have a solver for the Hydrogen Atom (1 atom), the next level off difficulty is the Helium atom (2 atoms). Here we'll show how\n",
11+
"to make and SCF for the Helium atom within the framework of Hartree–Fock."
12+
]
13+
},
14+
{
15+
"cell_type": "code",
16+
"execution_count": null,
17+
"metadata": {},
18+
"outputs": [],
19+
"source": [
20+
"from vampyr import vampyr3d as vp\n",
21+
"import numpy as np\n",
22+
"\n",
23+
"def laplace_operator(D, f_tree):\n",
24+
" return D(D(f_tree, 0), 0) + D(D(f_tree, 1), 1) + D(D(f_tree, 2), 2)\n",
25+
"\n",
26+
"def calculate_energy(phi_tree, V_tree):\n",
27+
" mra = phi_tree.MRA()\n",
28+
" d_oper = vp.ABGVDerivative(mra, 0.5, 0.5)\n",
29+
" return -0.5*vp.dot(laplace_operator(d_oper, phi_tree), phi_tree) + vp.dot(phi_tree, V_tree*phi_tree)\n",
30+
"\n",
31+
"def couloumb_potential(prec, phi_tree):\n",
32+
" mra = phi_tree.MRA()\n",
33+
" P = vp.PoissonOperator(mra, prec)\n",
34+
" return P(4.0*np.pi*phi_tree*phi_tree)\n",
35+
"\n",
36+
"# Analytic nuclear potential: f_nuc(r) = Z/|r|\n",
37+
"def f_nuc(r):\n",
38+
" Z = 2.0 # Nuclear charge\n",
39+
" R = np.sqrt(r[0]**2 + r[1]**2 + r[2]**2)\n",
40+
" return -Z / R\n",
41+
"\n",
42+
"# Analytic guess for wavefunction: f_phi(r) = exp(-r^2)\n",
43+
"def f_phi(r):\n",
44+
" R2 = r[0]**2 + r[1]**2 + r[2]**2\n",
45+
" return np.exp(-R2)\n",
46+
"\n",
47+
"# Set target precision\n",
48+
"precision = 1.0e-5\n",
49+
"\n",
50+
"# Define MRA basis and computational domain\n",
51+
"k = 5 # Polynomial order of MRA basis\n",
52+
"world = [-20, 20] # Computational domain [-L,L]^3 (a.u.)\n",
53+
"MRA = vp.MultiResolutionAnalysis(order=k, box=world)\n",
54+
"\n",
55+
"# Define projector onto the MRA basis\n",
56+
"P_mra = vp.ScalingProjector(mra=MRA, prec=precision)\n",
57+
"\n",
58+
"# Initialize the calculation\n",
59+
"phi_n = P_mra(f_phi) # Project analytic guess for wavefunction onto MRA\n",
60+
"phi_n.normalize() # Normalize the wavefunction guess\n",
61+
"V_n = P_mra(f_nuc) # Project analytic nuclear potential onto MRA\n",
62+
"J = couloumb_potential(precision, phi_n)\n",
63+
"E_n = calculate_energy(phi_n, V_n + J)"
64+
]
65+
},
66+
{
67+
"cell_type": "code",
68+
"execution_count": null,
69+
"metadata": {},
70+
"outputs": [],
71+
"source": [
72+
"# Loop parameters\n",
73+
"iteration = 0 # Iteration counter\n",
74+
"max_iter = 30 # Maximum iterations \n",
75+
"thrs = precision # -1 # Convergence requirement. Set to -1 if you wish to limit using max_iter\n",
76+
"update = 1.0 # Initialize error measure (norm of wavefunction update)\n",
77+
"# Minimization loop\n",
78+
"while (update > thrs):\n",
79+
" if iteration > max_iter-1:\n",
80+
" break\n",
81+
" # Build Helmholtz operator from current energy\n",
82+
" mu = np.sqrt(-2*E_n)\n",
83+
" G = vp.HelmholtzOperator(mra=MRA, exp=mu, prec=precision)\n",
84+
" \n",
85+
" # Apply Helmholtz operator\n",
86+
" phi_np1 = -2*G((V_n + J)*phi_n)\n",
87+
" \n",
88+
" # Compute wavefunction and energy update\n",
89+
" d_phi_n = phi_np1 - phi_n\n",
90+
" update = d_phi_n.norm()\n",
91+
"\n",
92+
" # Prepare for next iteration\n",
93+
" phi_n = phi_np1\n",
94+
" phi_n.normalize()\n",
95+
" J = couloumb_potential(precision, phi_n)\n",
96+
" E_n = calculate_energy(phi_n, V_n + J)\n",
97+
"\n",
98+
" # Collect output\n",
99+
" print(iteration, \" | E:\", E_n, \" | d_phi:\", update)\n",
100+
" iteration += 1\n",
101+
"E_tot = 2.0*E_n - vp.dot(phi_n*phi_n, couloumb_potential(precision, phi_n))"
102+
]
103+
},
104+
{
105+
"cell_type": "code",
106+
"execution_count": null,
107+
"metadata": {},
108+
"outputs": [],
109+
"source": []
110+
}
111+
],
112+
"metadata": {
113+
"kernelspec": {
114+
"display_name": "documentation",
115+
"language": "python",
116+
"name": "python3"
117+
},
118+
"language_info": {
119+
"codemirror_mode": {
120+
"name": "ipython",
121+
"version": 3
122+
},
123+
"file_extension": ".py",
124+
"mimetype": "text/x-python",
125+
"name": "python",
126+
"nbconvert_exporter": "python",
127+
"pygments_lexer": "ipython3",
128+
"version": "3.10.8"
129+
},
130+
"orig_nbformat": 4,
131+
"vscode": {
132+
"interpreter": {
133+
"hash": "a875265825dca88dc0cdca05b35ae15709f7b78b2bf941fac513dcdaf1078523"
134+
}
135+
}
136+
},
137+
"nbformat": 4,
138+
"nbformat_minor": 2
139+
}

0 commit comments

Comments
 (0)