Code Monkey home page Code Monkey logo

hf-tutorial's Introduction

Introduction

This is a tutorial on how to implement a simple program to solve the Hartree-Fock with SCF iterations.

Impement the SCF procedure

We will be following the algorithm described in Szabo and Ostlund, 3.4.6, p. 146 to implement the Hartree-Fock method for the hydrogen molecule. The steps are as follows:

  1. Obtain a guess at the density matrix.
  2. Calculate the exchange and coulomb matrices from the density matrix and the two-electron repulsion integrals.
  3. Add exchange and coulomb matrices to the core-Hamiltonian to obtain the Fock matrix.
  4. Diagonalize the Fock matrix.
  5. Select the occupied orbitals and calculate the new density matrix.
  6. Compute the energy.
  7. Compute the errors and check for convergence.
  • If converged, return the energy.
  • If not converged, return to second step with the new density matrix.

To start, you can implement this algorithm for the hydrogen molecule by running the following code:

    mol = "h2"
    r   = 1.0
    inp = f"{mol}-{r:.4f}"
    e = main(inp) # H2 molecule with bond length 1.0

then try some more complicated molecules, such as HeH+

    mol = "heh+"
    r   = 1.0
    inp = f"{mol}-{r:.4f}"
    e = main(inp) # HeH+ molecule with bond length 1.0

and H2O

    mol = "h2o"
    r   = 1.0
    inp = f"{mol}-{r:.4f}"
    e = main(inp) # water molecule with bond length 1.0

Potential Energy Surface

After implementing the self-consistent field (SCF) procedure, we can use it to compute the potential energy surface of the $\mathrm{H}_2$ molecule. We can do this by varying the internuclear distance and computing the energy at each point.

    for r in numpy.linspace(0.5, 3.0, 61):
        inp = f"h2-{r:.4f}"
        e = main(inp)
        print(f"H2: r={r: 6.4f}, e={e: 12.8f}")

You can also try other molecules, such as $\mathrm{HeH}^+$ and $\mathrm{H_2O}$. To visualize the potential energy surface, you can use the matplotlib package. An example of how to plot the data can be found in the file ./data/plot.ipynb.

Unrestricted Hartree-Fock

To implement the unrestricted Hartree-Fock (UHF) method, we will create a new function solve_uhf that follows the same steps as the restricted Hartree-Fock method, but with the added flexibility of allowing different spin-orbitals to have different occupation numbers.

The UHF method can be used to study molecules that have broken spin-symmetry, such as those that have a non-zero magnetic moment or unpaired electrons. In this case, the potential energy surface can be different from that obtained from the restricted Hartree-Fock method.

It's important to note that even if you have implemented the UHF method, the results may not be consistent with the reference. In order to get the correct dissociation potential energy surface, you may need to carefully break the spin symmetry.

Dependencies

  • numpy
  • scipy
  • If you wish to use ./data/gen_data.py to generate the integrals, pyscf is also required.

Reference

  • Szabo and Ostlund, Modern Quantum Chemistry: Introduction to Advanced Electronic Structure Theory, Dover Publications, New York, 1996
  • Helgaker, Jørgensen, and Olsen, Molecular Electronic-Structure Theory, Wiley, New York, 2000

hf-tutorial's People

Contributors

yangjunjie0320 avatar

Stargazers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.