1. Oxygen Atom (UHF Trial Wavefunction)#

This example demonstrates an AFQMC calculation of an isolated oxygen atom using an unrestricted Hartree-Fock (UHF) trial wavefunction. The Oxygen atom has a ground state with \(S=2\) (quartet state)

1.1. Running the Example#

The workflow includes the following steps:

  1. Create AFQMC input files: Execute ham/ham.py. It runs the ROHF and UHF calculations with PySCF, then generates the Hamiltonian in Cholesky-decomposed form and formats the trial wavefunction. Note that we used the ROHF orbitals as a basis, since they are spin-independent. The UHF wavefunction will be used as the trial wavefunction for AFQMC. Wavefunction.from_pyscf() directly handles the change of basis as demonstrated in this example. This produces afqmc.h5 containing the Hamiltonian and trial wavefunction.

  2. Run SAFIRE: Run SAFIRE using the provided JSON job file (see below):

    $ mpirun -n 16 safire afqmc.json
    

    The AFQMC calculation will perform sampling and output energy estimates and other observables.

  3. Analyze the results: Use safiretools to analyze the energy in the results file qmc.results.h5:

    from safiretools import Results, vis
    
    results = Results("qmc.results.h5")
    vis.plot_timeseries(results)
    

    This prints the average AFQMC energy and its stochastic uncertainty and plots the energy as a function of imaginary time. The first 500 steps (an imaginary time of 5.0 \(\mathrm{Ha}^{-1}\)) are discarded as equilibration, as set by equilibration_steps in the provided afqmc.json. If you used the same settings, you should get an output compatible with

    Energy = -74.90960 ± 0.00033
    

1.2. Files#

SCF, Hamiltonian and Wavefunction Generation (ham/ham.py):

# This file is distributed under the Apache License, Version 2.0 License.
# See LICENSE file in top directory for details.
#
# Copyright (c) 2021-2025 The Simons Foundation, Inc.
#
# You may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#      http://www.apache.org/licenses/LICENSE-2.0

from pyscf import gto, scf

from safiretools import MolecularHamiltonian, Wavefunction


def main():
    """
    AFQMC inputs for the oxygen atom: a Hamiltonian in the ROHF orbital basis
    and a UHF trial wavefunction.
    """

    #####################################
    #                                   #
    #       Run the SCF calculations    #
    #                                   #
    #####################################

    mol = gto.M(
        atom='O 0. 0. 0.',
        basis='ccpvdz',
        spin=2,
        verbose=4
    )

    # the orbital basis
    rohf = scf.ROHF(mol).newton()
    rohf.kernel()

    # the trial wavefunction
    uhf = scf.UHF(mol).newton()
    uhf.kernel()

    chol_tol = 1e-5

    # output
    fout = 'afqmc.h5'

    #####################################
    #                                   #
    #  Write Hamiltonian in ROHF basis  #
    #                                   #
    #####################################

    MolecularHamiltonian.from_pyscf(
        rohf,
        chol_cut=chol_tol,
        verbose=True
    ).to_hdf5(fout)

    #####################################
    #                                   #
    #      Write Trial Wavefunction     #
    #                                   #
    #####################################

    Wavefunction.from_pyscf(
        uhf,
        basis=rohf
    ).to_hdf5(fout)


if __name__ == '__main__':
    main()

AFQMC Input File (afqmc.json):

{
  "output_name": "qmc",
  "seed": 42,
  "execute": {
    "wavefunction": {
      "filename": "../ham/afqmc.h5"
    },
    "hamiltonian": {
      "filename": "../ham/afqmc.h5"
    },
    "timestep": 0.01,
    "steps": 6000,
    "equilibration_steps": 500,
    "population_control_interval": 10,
    "measure_interval": 10,
    "num_walkers": 1600
  }
}