{ "nbformat": 4, "nbformat_minor": 0, "metadata": { "colab": { "provenance": [] }, "kernelspec": { "name": "python3", "display_name": "Python 3" }, "language_info": { "name": "python" } }, "cells": [ { "cell_type": "markdown", "source": [ "#**Computational Chemistry - Practical Class 4**\n", "\n", "**The variational method**\n", "\n", "\\\\\n", "\n", "---\n", "Supporting Bibliography:\n", "\n", "Attila Szabo and Neil S. Ostlund, Modern Quantum Chemistry: Introduction to Advanced Electronic Structure Theory, Dover Publications Inc., New York, 1996, **Chapter 1, Section 1.3**\n", "\n", "---\n", "\n", "\\\\\n", "\n", "**1. The variational method**\n", "\n", "We discovered in the theoretical class that the Schrödinger equation (in au) of an electron moving **in one dimension** under the influence of potential, $-\\delta(x)$ is given by\n", "\n", "$(-\\frac{1}{2}\\frac{d}{dx²}-\\delta(x))\\left|{ϕ_T}\\right\\rangle = \\mathcal{E}\\left|{ϕ_T}\\right\\rangle$\n", "\n", "we also found that $\\left|{ϕ_T}\\right\\rangle = Ne^{-\\alpha x^{2}}$ test wave function can be used.\n", "\n", "**Exercise 1**\n", "\n", "Verify that $\\left|{ϕ_T}\\right\\rangle$ is normalized if $N = \\pm (\\frac{2\\alpha}{π})^{1/4}$\n", "\n", "You will need the integral\n", "\n", "$\\int_{-\\infty}^{\\infty} x^{2m} e^{-\\alpha x^2} \\,dx = \\frac{(2m)! \\, \\pi^{1/2}}{2^{2m} \\, m! \\, \\alpha^{m+1/2}}$\n", "\n", "**Exercise 2**\n", "\n", "Plot $\\left|{ϕ_T}\\right\\rangle$ in terms of $x$. Initially consider the value of $\\alpha$ = 1.\n", "\n", "Note1: to represent functions, among several libraries, we can use the Matplotlib library. To import this library we do `import matplotlib.pyplot as plt`\n", "\n", "Note2: The basic syntax to represent a function is as follows:\n", "\n", "```\n", "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "# Create a set of 100 values ​​of x from 0 to 10 (we can define the range)\n", "x = np.linspace(0, 10, 100)\n", "\n", "# define the function\n", "f = 2*x**2 + 3\n", "\n", "# Represent the function f in order to x\n", "plt.plot(x, f)\n", "# Add a caption\n", "plt.legend(['function f'])\n", "# Caption the x-axis\n", "plt.xlabel('x')\n", "# Caption the y-axis\n", "plt.ylabel('my functionf(x)')\n", "# Limits of the xxx axis\n", "plt.xlim(0, 10)\n", "# show the graph\n", "plt.show()\n", "```\n", "\n", "Note3: the constant $\\pi$ is defined in the Numpy library via `np.pi`\n", "\n", "Note4: the exponential function $e^x$ is defined in the Numpy library through `np.exp(x)`" ], "metadata": { "id": "KqADZfYeHzHd" } }, { "cell_type": "code", "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n" ], "metadata": { "id": "rCW6VLw-D9E3" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "**Exercise 3**\n", "\n", "We also found that the expected value of energy was given by\n", "$\\left\\langle {ϕ_T}\\right| \\mathcal{H}\\left|{ϕ_T}\\right\\rangle = E_0 = \\frac{\\alpha}{2}- (\\frac{\\pi}{2\\alpha})^{-\\frac{1}{2}} \\geq \\mathcal{E}_0$\n", "\n", "Find the minimum value of energy $E_0$\n", "\n", "Note1: we can obtain the minimum of a function by calculating $\\frac{dE_0}{d\\alpha} = 0$ and $\\frac{d^2E_0}{d\\alpha^2}$. If $\\frac{dE_0}{d\\alpha}$ exists and $\\frac{d^2E_0}{d\\alpha^2} > 0$, the function has a minimum.\n", "\n", "**Exercise 4**\n", "\n", "It is not always easy for us to be able to explicitly differentiate the energy value depending on the variational parameter. However, there are numerical methods that allow us to try to find the minimum number of functions. Some of these methods are found implemented in the `minimize` function of the Scipy library. The minimum syntax is as follows:\n", "\n", "```\n", "import numpy as np\n", "from scipy.optimize import minimize\n", "\n", "# Define the function to minimize using the parameter x\n", "def min(x):\n", "# Function\n", "E = x*2 + 7/x\n", "# Print the value of x and the function at each cycle\n", "print(\"x = {:.6f}, E = {:.16f}\".format(x[0], E[0]))\n", "# return the value of E\n", "return E\n", "\n", "# Initial estimate of x\n", "x = 1\n", "\n", "# we can define bounds e.g. x can only vary between [0, ∞)\n", "bounds = [(0, None)]\n", "\n", "# Optimize the min function by varying the parameter x with a tolerance of 1e-6\n", "E_min = minimize(min, x, bounds=bounds, tol=1e-6)\n", "```\n", "\n", "Calculate the value of $\\alpha$ for which the energy $E_0$ is minimal writing a program in python." ], "metadata": { "id": "7tBy_ns4snKN" } }, { "cell_type": "code", "source": [ "import numpy as np\n", "from scipy.optimize import minimize\n" ], "metadata": { "id": "6GqipPHh3zXx" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "Now consider the test function $\\left|{ϕ_T}\\right\\rangle = Ne^{-\\alpha x}$. Graph $\\left|{ϕ_T}\\right\\rangle$ in terms of $x$. Initially consider the value of $\\alpha$ = 1." ], "metadata": { "id": "GpkOwOk8bB7z" } }, { "cell_type": "code", "source": [ "import matplotlib.pyplot as plt\n", "import numpy as np\n", "\n", "#" ], "metadata": { "id": "pVEiATD0LOTX" }, "execution_count": null, "outputs": [] }, { "cell_type": "markdown", "source": [ "**Exercise 6**\n", "\n", "For the hydrogen atom, the Hamiltonian operator $H$ (in atomic units) is given by\n", "\n", "$$\n", "H = -\\overbrace{\\frac{1}{2}\\nabla^2}^{T} - \\overbrace{\\frac{1}{r}}^{V}\n", "$$\n", "\n", "Using a test function $\\left|{ϕ_T}\\right\\rangle = Ne^{-\\alpha x}$, it is possible to demonstrate that the expected value of the energy $E_0$ is given by\n", "\n", "$$\n", "E_0 = \\frac{\\alpha^2}{2}-\\alpha\n", "$$\n", "\n", "Calculate the minimum value and $E_0$\n", "\n", "**Exercise 7**\n", "\n", "Calculate the value of $\\alpha$ for which the energy $E_0$ is minimum by writing a program in Python. Compare the value with the exact energy for the hydrogen atom (-0.5 Hartree)\n" ], "metadata": { "id": "2S6f7n_2MAeU" } }, { "cell_type": "code", "source": [ "import numpy as np\n", "from scipy.optimize import minimize" ], "metadata": { "id": "vYDlnJsPQWme" }, "execution_count": null, "outputs": [] } ] }