2.2. The Hydrogen Atom#

You will learn how to use Psi4 by putting your hands on a simple example: The total energy of the hydrogen atom in Hartree-Fock theory. This is a tutorial - you are not only invited to type the commands that are being introduced, you are obliged to.

2.2.1. Electronic Structure Software#

Ab initio electronic structure software packages make it possible to calculate numerically a variety of properties of a given system, based only on physical constants and the system’s Hamiltonian. The only approximations that need to be made are in the method and basis set that have to be chosen, in order to allow for a reasonable computational time. (The stronger your workstation, the more approximations you may drop, and the more elaborate your approach can be.) There are plenty of ab initio quantum chemical packages on the market; they differ in their capabilities, license policy and pricing. Widley used packages include GAMESS US, turbomole, DALTON, CP2K, CPMD and the Gaussian set of programs.

Psi4 is a free and open-source ab initio electronic structure program providing implementations of Hartree–Fock, density functional theory, many-body perturbation theory, configuration interaction, density cumulant theory, symmetry-adapted perturbation theory, and coupled-cluster theory. Most of the methods are quite efficient, thanks to density fitting and multi-core parallelism. The program is a hybrid of C++ and Python, and calculations may be run with very simple text files or using the Python API, facilitating post-processing and complex workflows. [Reference: Smith DG, et al. PSI4 1.4: Open-source software for high-throughput quantum chemistry. The Journal of chemical physics (2020) DOI: https://doi.org/10.1063/5.0006002 ]

The current version of Psi4 that you will be using on noto.epfl is v1.5.

! Always remember to select the Computational Chemistry kernel to have psi4 and other useful packages available.

2.2.2. Preliminary steps#

Before starting to work with Psi4 we need to set up the environment, importing the required modules:

import psi4
import pandas as pd
import numpy as np
import matplotlib.pyplot as plt
import sys
sys.path.append("..")
from helpers import *

plt.style.use(['seaborn-poster', 'seaborn-ticks'])

then we can also set the maximum resources that can be used, specifying the available memory for Psi4 to use with the psi4.set_memory() function, and the number of threads to use in SMP parallel computations with the psi4.set_num_threads() function

psi4.set_memory('2 GB')
psi4.set_num_threads(2)
  Memory set to   1.863 GiB by Python driver.
  Threads set to 2 by Python driver.

2.2.3. Writing An Input For Psi4 and Invoking the Program#

The geomety of the \(H\) atom can now be defined, passing it as a string into the psi4.geometry() function in either Z-matrix (see note below) or Cartesian format, where the triple-quote """string""" syntax is used to allow the string to break over multiple lines.

h = psi4.geometry("""
0 2
H 0.0 0.0 0.0
""")

Where the first line contains the total charge of the system (0), followed by the spin multiplicity (2), and the following lines contain all the atoms of your system, one atom per line. In this case our moleule is composed of a single hydrogen atom, so we have a single line.

You can visualize a 3D representation of your molecule using the drawXYZ function imported from the helpers we provide. In this case you will not see something particularly exciting, but it is always a good practice to have a visual look at your structures, to check that everythin is as expected.

drawXYZ(h)

You appear to be running in JupyterLab (or JavaScript failed to load for some other reason). You need to install the 3dmol extension:
jupyter labextension install jupyterlab_3dmol

We can compute the energy of the system the function psi4.energy(), passing as first argument a string with the desired method and the basis set ('METHOD/BASIS'), and the target molecule as second argument. The ouput is the total electronic energy in Hartree. For this exercise we will use the unrestricted Hartree Fock method. You will see that in detail during next lectures and exercises and you will get familiar with it (for now it is sufficient to know we are using a method, with a particular basis set).

Calling psi4.energy() will perform a so called single point calculation and will not change the geometry. During the calculation the program will perform a wavefunction optimization to find the lowest energy combination of wavefunction coefficients.

We will save in separate log files the output of the calculations and we will store the energy value and print it in the next cell.

basissets = ['STO-3G', '6-31G', '6-311G'] # these are the basis sets we are going to use

psi4.set_options({'reference':'UHF'}) # We are using Unrestriced Hartee Fock method

for basis in basissets:
    psi4.core.set_output_file(f'{basis}-h-output.log', False) # save in seperate log files
    E = psi4.energy(f'hf/{basis}', molecule=h)  # we do the single point energy calculation once per basis set

    print(basis, E)

To verify the number of basis sets used, navigate to the appropriate output log file located in your file directory (lefthand side of page). You can use the CTRL+F search function to look for the phrase “Number of basis functions” and read under the section called “Primary Basis.”

Exercise 7

Include a table of the the calculated energies using the three different basis sets, specifying for each of them the number of basis functions used. Compare the energies with the analytical value for the H atom, given by the analytical expression:

\[ E = \frac{1}{2} m_e c^2\alpha^2, \]

where \(\alpha\) is the fine structure constant.

\[\begin{split}\begin{align} m_e = 0.910953\cdot10^{-30} kg\\ c = 2.99792458\cdot10^8 m s^{-1}\\ \alpha = 7.2973525376\cdot10^{-3}\\ N_A = 6.0221367\cdot10^{23}mol^{-1} \end{align}\end{split}\]

Pay attention to the units - use atomic units or kcal\(\cdot\)mol\(^{-1}\) throughout!

Exercise 8

What is the influence of the basis set size on the accuracy of the result? How do the split-valence bases compare to STO-3G?