5. Li₂ Molecule with Frozen Core#

This example demonstrates the frozen-core approximation in AFQMC, where the energetic core orbitals are excluded from the correlated calculation. This significantly reduces the computational cost while maintaining high accuracy in relative energies for many systems. For the Li₂ molecule, we freeze the 1s core orbitals of each lithium atom, treating only the 2s valence electrons explicitly in AFQMC. The computational savings become more significant for larger atoms with more core electrons. We reproduce results from Purwanto, Zhang, and Krakauer (J. Chem. Theory Comput. 2013, 9, 4825–4833). In a cc-pVDZ basis, the FCI energy is -14.9005 Ha and the AFQMC energy is -14.9017(1) Ha.

5.1. Running the Example#

The workflow includes the following steps:

  1. Generate all AFQMC inputs: Execute the single Python script:

    $ python 05_Li2_frozen_core.py
    

    This creates afqmc.h5 containing the frozen-core Hamiltonian and trial wavefunction. You should see that the RHF energy of the full system is -14.8694988585082 Ha,

  2. Run SAFIRE: Execute the AFQMC calculation using the provided JSON job file:

    mpirun -n 16 safire afqmc.json
    

    The calculation runs only in the valence space with the core electrons frozen, significantly reducing computational cost.

  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 1500 steps (an imaginary time of 15.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 = -14.90107 ± 0.00039
    

    We note that the AFQMC energy of -14.9011(4) Ha is in excellent agreement with the reference AFQMC energy of -14.9017(1) Ha from the literature.

5.2. Files#

Frozen-Core Preparation (05_Li2_frozen_core.py):

r"""
Example 6: Frozen core/orbital tranformation.

From:

W. Purwanto, S. Zhang, H. Krakauer. Frozen-Orbital and Downfolding Calculations with 
Auxiliary-Field Quantum Monte Carlo. J. Chem. Theory Comput. 2013, 9, 11, 4825–4833
https://pubs.acs.org/doi/10.1021/ct4006486

Computing the AFQMC ground state energy of the Li_2 molecule in the cc-pVDZ
using the frozen core approximation to freeze the Li 1s orbitals.

ncore: 2	
trial wavefunction: RHF
refrence AFQMC energy: -14.9017(1)
FCI energy:	       -14.9005
"""
from pyscf import gto,scf

from safiretools import MolecularHamiltonian, Wavefunction


# run PySCF calculation to generate RHF wavefunction
equil_bond=2.673

atoms = f"""
Li 0.0 0.0 {equil_bond/2}
Li 0.0 0.0 {-equil_bond/2}
"""

mol = gto.M(
    atom = atoms,
    basis = "ccpvdz",
    verbose = 5
)

mf = scf.RHF(mol)
E_HF = mf.kernel()

chol_tol = 1e-6

fout = 'afqmc.h5'


# specify the active space similarly to CAS methods,
# `active_space=(ne,no)` where `ne`/`no` is the number of active electrrons / orbitals
# use `no=-1` to include all remaining orbitlas in the CAS space
ne = 2 # [He] 2s^1 for each Li
no = -1 # use all remaining orbitals in CAS space
MolecularHamiltonian.from_pyscf(
    mf,
    chol_cut = chol_tol,
    active_space = (ne,no),
).to_hdf5(fout)

# write the frozen core trial wavefunction
wfn = Wavefunction.from_pyscf(
    mf,
    active_space = (ne,no)
)
wfn.to_hdf5(fout)

This all-in-one script:

  • Sets up the Li₂ molecule with PySCF at equilibrium bond length

  • Performs RHF calculation to generate molecular orbitals

  • Specifies active space using active_space=(ne, no) notation: 2 valence electrons in all remaining orbitals (no=-1)

  • Applies frozen-core transformation via MolecularHamiltonian.from_pyscf with the active_space parameter

  • Writes Hamiltonian in the active space representation (including the constant core energy) to afqmc.h5

  • Generates the trial wavefunction via Wavefunction.from_pyscf and the active_space parameter

AFQMC Input File (afqmc.json):

{
  "output_name": "qmc",
  "seed": 42,
  "execute": {
    "wavefunction": {
      "filename": "afqmc.h5"
    },
    "hamiltonian": {
      "filename": "afqmc.h5"
    },
    "timestep": 0.01,
    "steps": 7000,
    "equilibration_steps": 1500,
    "num_walkers": 1600,
    "population_control_interval": 10
  }
}

This JSON job file configures the AFQMC calculation parameters, including time step, number of walkers, and measurement settings.