Back to Projects

Hartree-Fock Quantum Chemistry Solver

Project Overview

The Hartree-Fock Quantum Chemistry Solver is a computational quantum chemistry program that implements the self-consistent field (SCF) method for solving the electronic Schrödinger equation. This implementation includes both Restricted Hartree-Fock (RHF) and Unrestricted Hartree-Fock (UHF) algorithms, capable of handling closed-shell and open-shell molecular systems.

The solver is designed with a modular architecture that separates core quantum chemical algorithms from input/output processing, making it extensible for future enhancements and additional quantum chemistry methods.

Hartree-Fock Solver

Project Structure

The Hartree-Fock solver is built with a modular library structure that separates different aspects of quantum chemistry calculations into distinct components:

Library Components

  • libscf - Self-consistent field implementations for both RHF and UHF methods
  • libmol - Molecule class and basis set loader to handle molecular geometries
  • libmath - Linear algebra utilities and mathematical helper functions
  • libgf - Gaussian function definitions and normalizations
  • libint - One- and two-electron integral evaluations

Program Flow

  • Input file parsing and molecular system setup
  • Basis set initialization and integral evaluation
  • Self-consistent field iterations (RHF or UHF)
  • Convergence acceleration using DIIS or fixed-point iteration
  • Population analysis and property calculation
  • Results output and visualization

Input Format

<Number of atoms> <charge> <multiplicity>
<Z1> <x1> <y1> <z1>
<Z2> <x2> <y2> <z2>
...
<Basis Set Name>

Example for water molecule (H₂O):

3 0 1
8  0.0000000000  0.0000000000  0.21981483259
1  0.0000000000  1.4194772274 -0.87926122007
1  0.0000000000 -1.4194772274 -0.87926122007
STO-3G

Project Structure

Modular Architecture

main/hartree-fock.cpp

Central driver program and command-line interface

libscf/

Self-consistent field implementations:

  • scfrhf.cpp - RHF method
  • scfuhf.cpp - UHF method
  • scfgen.cpp - Common utilities
libmol/

Molecular structure handling:

  • Molecular geometry
  • Basis set loading
  • Atomic properties
libgf/

Gaussian functions:

  • Primitive Gaussians
  • Contracted basis functions
  • Normalization routines
libmath/

Mathematical utilities:

  • linalg.cpp - Matrix operations
  • miscmath.cpp - Special functions
  • Linear algebra solvers
libint/

Integral evaluations:

  • 1e.cpp - One-electron integrals
  • 2e.cpp - Two-electron integrals
  • Recursion relations
Input Processing

main/sample_inputs/ - Molecule definition files

Output Generation

main/sample_outputs/ - Calculation results

Theoretical Background

The Hartree-Fock method is a fundamental quantum mechanical approach to approximately solve the electronic Schrödinger equation for molecular systems. It forms the foundation of more advanced computational chemistry methods and provides essential insights into electronic structure.

Key Theoretical Concepts

  • Mean-Field Approximation - Each electron moves in the average field of all other electrons
  • Slater Determinants - Mathematical representation of many-electron wavefunctions that satisfy the Pauli principle
  • Self-Consistent Field (SCF) - Iterative procedure to find optimal molecular orbitals
  • Basis Set Expansion - Representation of molecular orbitals using predefined basis functions
  • Roothaan-Hall Equations - Matrix formulation of the HF equations for practical computation

Mathematical Formulation

The Hartree-Fock equation in operator form:

F̂ψᵢ = εᵢψᵢ

Where:

  • F̂ is the Fock operator
  • ψᵢ are the molecular orbital wavefunctions
  • εᵢ are the orbital energies

The Fock operator includes:

  • Kinetic energy operator
  • Nuclear-electron attraction
  • Electron-electron repulsion (Coulomb and exchange)

RHF vs. UHF Methods

Restricted Hartree-Fock (RHF)
  • For closed-shell systems (paired electrons)
  • Same spatial orbitals for alpha and beta electrons
  • More computationally efficient
  • Cannot describe bond breaking properly
Unrestricted Hartree-Fock (UHF)
  • For open-shell systems (unpaired electrons)
  • Different spatial orbitals for alpha and beta electrons
  • More computationally demanding
  • Can describe spin polarization effects

SCF Convergence Methods

The Self-Consistent Field procedure can be challenging to converge for some systems. This implementation includes two key acceleration techniques:

  • Fixed-Point Iteration - Simple method that directly uses the output of one cycle as input to the next
  • Direct Inversion of Iterative Subspace (DIIS) - Advanced technique that uses information from multiple previous iterations to predict an improved Fock matrix

Technical Components

Core SCF Library

The fundamental quantum chemistry algorithms that include:

  • Restricted Hartree-Fock (RHF) implementation
  • Unrestricted Hartree-Fock (UHF) implementation
  • Integral evaluation routines
  • SCF convergence acceleration methods
Implementation: C++

Basis Set Library

Gaussian basis set implementation with:

  • STO-nG minimal basis sets
  • Primitive Gaussian integral evaluation
  • Contracted Gaussian functions
  • Extensible basis set framework
Implementation: C++

Input/Output System

User interface and I/O components:

  • Molecular geometry parser
  • Calculation parameter configuration
  • Formatted output generation
  • Results analysis and visualization
Implementation: C++

Key Algorithms

Self-Consistent Field (SCF) Method

The iterative procedure for solving the Hartree-Fock equations:

  1. Initialize density matrix from guess orbitals
  2. Compute Fock matrix from density matrix
  3. Diagonalize Fock matrix to get new orbital coefficients
  4. Form new density matrix from orbital coefficients
  5. Check for convergence (energy change, density change)
  6. If not converged, return to step 2
Implementation Highlights:
  • Direct inversion of iterative subspace (DIIS) acceleration
  • Damping for difficult convergence cases
  • Level shifting for open-shell systems

Integral Evaluation

Efficient computation of molecular integrals:

  • Overlap integrals: ⟨χᵢ|χⱼ⟩
  • Kinetic energy integrals: ⟨χᵢ|-½∇²|χⱼ⟩
  • Nuclear attraction integrals: ⟨χᵢ|-Σₐ Zₐ/r₁ₐ|χⱼ⟩
  • Two-electron integrals: ⟨χᵢχⱼ|1/r₁₂|χₖχₗ⟩
Optimization Techniques:
  • Screening based on integral bounds
  • Symmetry exploitation
  • Pre-computed Gaussian product rules
  • Efficient recursion relations

Code Sample: SCF Loop

// Main SCF iteration loop for RHF method
bool scf_rhf(const BasisSet& basis, Molecule& mol, double convergence_threshold) {
    int maxiter = 100;
    int iter = 0;
    double energy = 0.0;
    double energy_prev = 0.0;
    double delta_e = 0.0;
    
    // Initialize density matrix from core Hamiltonian
    Matrix D = Matrix::Zero(basis.nbf(), basis.nbf());
    
    // Compute and store one-electron integrals
    Matrix S = overlap(basis);
    Matrix T = kinetic(basis);
    Matrix V = nuclear(basis, mol);
    Matrix H = T + V;
    
    // Compute orthogonalization matrix X
    Matrix X = compute_orthogonalization_matrix(S);
    
    // Start SCF iterations
    while (iter < maxiter) {
        // Form Fock matrix
        Matrix F = H;
        for (int mu = 0; mu < basis.nbf(); ++mu) {
            for (int nu = 0; nu < basis.nbf(); ++nu) {
                for (int lambda = 0; lambda < basis.nbf(); ++lambda) {
                    for (int sigma = 0; sigma < basis.nbf(); ++sigma) {
                        double eri = two_electron_integral(basis, mu, nu, lambda, sigma);
                        F(mu, nu) += D(lambda, sigma) * (2.0 * eri - eri_exchange(basis, mu, lambda, nu, sigma));
                    }
                }
            }
        }
        
        // Transform Fock matrix to orthogonal basis
        Matrix F_prime = X.transpose() * F * X;
        
        // Solve eigenvalue problem
        Eigen::SelfAdjointEigenSolver solver(F_prime);
        Matrix C_prime = solver.eigenvectors();
        Matrix C = X * C_prime;
        
        // Form new density matrix
        Matrix D_new = Matrix::Zero(basis.nbf(), basis.nbf());
        int n_occ = mol.n_electrons() / 2;
        for (int mu = 0; mu < basis.nbf(); ++mu) {
            for (int nu = 0; nu < basis.nbf(); ++nu) {
                for (int i = 0; i < n_occ; ++i) {
                    D_new(mu, nu) += 2.0 * C(mu, i) * C(nu, i);
                }
            }
        }
        
        // Calculate electronic energy
        energy = 0.0;
        for (int mu = 0; mu < basis.nbf(); ++mu) {
            for (int nu = 0; nu < basis.nbf(); ++nu) {
                energy += 0.5 * D_new(mu, nu) * (H(mu, nu) + F(mu, nu));
            }
        }
        
        // Add nuclear repulsion energy
        energy += nuclear_repulsion_energy(mol);
        
        // Check convergence
        delta_e = std::abs(energy - energy_prev);
        if (delta_e < convergence_threshold) {
            return true;  // Converged
        }
        
        // Update for next iteration
        D = D_new;
        energy_prev = energy;
        iter++;
    }
    
    return false;  // Not converged within max iterations
}

Example Results

Water Molecule (H₂O)

Calculation parameters:

  • Method: RHF
  • Basis Set: STO-3G
  • Geometry: Experimental

Results:

  • Total Energy: -74.9659 Hartrees
  • HOMO-LUMO Gap: 0.6834 Hartrees
  • Dipole Moment: 1.8546 Debye
  • Convergence: 12 iterations
View Output

Methane (CH₄)

Calculation parameters:

  • Method: RHF
  • Basis Set: STO-3G
  • Geometry: Optimized

Results:

  • Total Energy: -39.7268 Hartrees
  • HOMO-LUMO Gap: 0.9104 Hartrees
  • Dipole Moment: 0.0000 Debye
  • Convergence: 9 iterations
View Output

Ammonia (NH₃)

Calculation parameters:

  • Method: RHF
  • Basis Set: STO-3G

Results:

  • Total Energy: -54.0445 Hartrees
  • Population Analysis: N (-0.754), H (+0.251 each)
View Output

Oxygen Molecule (O₂)

Calculation parameters:

  • Method: UHF
  • Basis Set: STO-3G
  • Multiplicity: 3 (triplet)

Results:

  • Total Energy: -144.0911 Hartrees
  • UHF <S²>: 2.0008 (vs. exact 2.0000)
View Output

Hydrazine (N₂H₄)

Calculation parameters:

  • Method: RHF
  • Basis Set: STO-3G

Results:

  • Total Energy: -107.8792 Hartrees
  • N-N Bond: Demonstrates single bond electron distribution
View Output

Benzene (C₆H₆)

Calculation parameters:

  • Method: RHF
  • Basis Set: STO-3G
  • Structure: Aromatic ring with D6h symmetry

Results:

  • Total Energy: Demonstrates ability to handle larger molecular systems
  • Aromaticity: Shows delocalized π-electron system
  • Computational Challenge: Higher demand due to increased electron count and basis functions
View Output

Key Features

  • Ab initio quantum chemistry calculations
  • Support for closed-shell and open-shell systems
  • STO-nG basis set implementation
  • Self-consistent field convergence acceleration
  • Wavefunction analysis tools
  • Modular, extensible architecture
  • Detailed calculation output and visualization

Future Enhancements

  • Density Functional Theory (DFT) implementation
  • Advanced correlation methods (MP2, CCSD)
  • Expanded basis set library
  • Geometry optimization capabilities
  • Frequency calculations and thermochemistry
  • Parallel computation for large systems
  • Interactive graphical user interface

Note: This project is officially registered as part of my academic coursework at BITS Pilani. It reflects significant original effort, research, and development, and is protected under institutional intellectual property policies. Unauthorized copying, reproduction, or derivative use—whether in part or in full—is strictly discouraged and may lead to academic or legal consequences. If you find this work inspiring or would like to collaborate or learn more, feel free to reach out!!

Play Game