4. Vanadium Atom (Fully Polarized)#

This example demonstrates a fully polarized AFQMC calculation on an isolated vanadium atom which has a ground state with \(S=3/2\) (quartet state). We will use the frozen core approximation to freeze all electrons except for the \(3d^3\) valence electrons. In the cc-pVDZ basis set, this results in 32 active orbitals and 3 active electrons. We will use CASCI to compute the exact energy within the active space as a reference for comparison with AFQMC.

4.1. Running the Example#

The workflow follows these steps:

  1. Create AFQMC inputs: Execute inputs/setup.py. It first performs ROHF on the vanadium atom, whose orbitals we will use as a basis and from which the trial wavefunction is built. It also runs a CASCI(32o,3e) calculation to provide a reference energy.

    The ROHF energy should be around -942.884910 Ha, and the CASCI(32o,3e) energy should be around -942.902127 Ha, where the contribution from the active space is -3.535253 Ha.

    Note

    An isolated vanadium atom has other ROHF solutions, and the CASCI and AFQMC energies quoted in this example all assume the lowest one. setup.py therefore runs an internal stability analysis, re-solving from any instability it finds, and then checks the total energy against the value above.

    It then generates the SAFIRE inputs. Note that script uses an active space for AFQMC of cas_afqmc = (3,32). This treats the system as having all electrons in the spin-up channel. The script writes both the Hamiltonian and a fully polarized trial wavefunction to afqmc.h5. A trial with no beta electrons is collinear with ndown == 0, so walker_type in afqmc.json is "collinear" and the wavefunction’s beta blocks are written with zero width.

  2. Run SAFIRE: Execute SAFIRE using the provided JSON job file afqmc.json:

    First, go to the inputs directory, then run SAFIRE with the following command:

    mpirun -n 64 safire afqmc.json
    
  3. Analyze the results: Use safiretools to analyze the energy in the results file inputs/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 1000 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 = -942.90168 ± 0.00015
    
  4. compare with the reference CASCI energy: The AFQMC energy, -942.9017(2) Ha, agrees with the CASCI energy, -942.902127 Ha, which is the exact energy within the active space, to well within chemical accuracy.

inputs/run_safire_cpu.sh is a sample Slurm batch script for step 2. For an alternative way to build the trial wavefunction, using selected CI instead of a single determinant, see B Atom – Semistochastic Heat-Bath CI (SHCI) Trial Wavefunction.

4.2. Files#

SCF/CASCI Calculation and Input Generation (inputs/setup.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, mcscf

from safiretools import MolecularHamiltonian, Wavefunction

# The internally stable ROHF solution for the S=3/2 vanadium atom in cc-pVDZ.
#   An isolated V atom has other ROHF solutions, and the
#   CASCI and AFQMC reference energies quoted in this example all assume this one.
ROHF_ENERGY = -942.884909528
ROHF_ENERGY_TOL = 1e-4


def solve_stable_rohf(mol, max_rotations=5):
    """
    Solve ROHF, re-solving from the lowest instability direction until the
    solution is internally stable.

    Internal stability asks whether the solution is a genuine ROHF minimum
    rather than a saddle point; it does not consider the symmetry-breaking
    (ROHF -> UHF) rotations that external stability would.
    """
    mf = scf.ROHF(mol).newton()
    mf.kernel()

    for _ in range(max_rotations):
        mo, _, stable, _ = mf.stability(return_status=True)
        if stable:
            break
        # rotate the orbitals along the instability and re-solve from there
        mf.kernel(mo, mf.mo_occ)
    else:
        raise RuntimeError(
            f"ROHF is still internally unstable after {max_rotations} rotations"
        )

    if not mf.converged:
        raise RuntimeError("ROHF reached a stable solution but did not converge")

    return mf


def main():
    """
    AFQMC inputs for the fully polarized vanadium atom, with a CASCI(32o,3e)
    reference energy.
    """

    # 1. ROHF on the isolated vanadium atom, whose orbitals are the basis
    mol = gto.M(
        atom='V 0. 0. 0.',
        basis='ccpvdz',
        spin=3,
        verbose=5
    )

    rohf = solve_stable_rohf(mol)

    # Report ROHF energy decomposition and total energy.
    e_elec, e_coul = rohf.energy_elec()
    e_nuc = rohf.energy_nuc()
    e_one = e_elec - e_coul
    e_tot = rohf.e_tot

    print("ROHF one-electron energy: ", e_one)
    print("ROHF Coulomb/exchange energy: ", e_coul)
    print("ROHF electronic energy: ", e_elec)
    print("ROHF nuclear repulsion energy: ", e_nuc)
    print("ROHF total energy: ", e_tot)

    if abs(e_tot - ROHF_ENERGY) > ROHF_ENERGY_TOL:
        raise RuntimeError(
            f"ROHF total energy {e_tot:.9f} Ha differs from the expected stable "
            f"solution {ROHF_ENERGY:.9f} Ha by more than {ROHF_ENERGY_TOL:g} Ha. "
            "The CASCI and AFQMC reference energies in this example assume that "
            "solution, so they will not be reproduced."
        )

    # Getting a reference energy:
    mycas = mcscf.CASCI(rohf,32,3)
    E_casci =  mycas.kernel()
    print("CASCI(32,3) energy: ", E_casci[0])

    # 2. the AFQMC inputs
    chol_tol = 1e-5
    cas_afqmc = (3,32)

    # output
    fout = 'afqmc.h5'

    MolecularHamiltonian.from_pyscf(
        rohf,
        chol_cut=chol_tol,
        verbose=True,
        active_space=cas_afqmc  # provide the active space here
    ).to_hdf5(fout)

    # Freezing the 10 doubly occupied core orbitals leaves 3 alpha and 0 beta
    #   electrons in the active space, so the trial is collinear with ndown == 0
    Wavefunction.from_pyscf(
        rohf,
        active_space = cas_afqmc  # must match the Hamiltonian's active space!
    ).to_hdf5(fout)


if __name__ == '__main__':
    main()