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 input file:

    mpirun -n 16 safire --filenames afqmc.json
    

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

  3. Analyze the results: Use the scalar_stats command-line tool from afqmctools to analyze the energy output:

    $ scalar_stats qmc.s000.scalar.dat -s time -t -e 15.0
    

    This computes the average AFQMC energy and stochastic uncertainty, using an equilibration time of 15.0 \(Ha^{-1}\). The -t flag generates a plot of the energy as a function of imaginary time if running locally. If running remotely, you can save the plot of the energy vs imaginary time to a file using the –savefig [name].png option. In either case, you should see output similar to the following if you used the same settings as in the provided afqmc.json file and above.

    ====== [analyze_scalar_data Settings] ======
    
    [+] fname            = qmc.s000.scalar.dat
    [+] mark_header      = #
    [+] series_column    = time
    [+] nequil           = 15.0
    [+] estimate_equil   = False
    [+] column           = LocalEnergy
    [+] reblock          = 1
    [+] ndiscard         = None
    [+] list             = False
    [+] trace            = True
    [+] append           = None
    [+] dump             = False
    [+] dump_fname       = trace.dat
    [+] verbose          = True
    [+] autocorr         = None
    [+] savefig          = None
    [+] dump_avail_columns = False
    
    AFQMC Energy   -14.901069 +/-   0.000386 15.93 15.0/70.0
    

    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 afqmctools.utils.pyscf_utils import load_from_pyscf_chk_mol
from afqmctools.hamiltonian.mol import write_hamil_mol
from afqmctools.wavefunction.mol import write_wfn_mol


# 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)
mf.chkfile = 'rhf.chk'
E_HF = mf.kernel()

wfn_chk = 'rhf.chk'
chol_tol = 1e-6

fout = 'afqmc.h5'


scf_data = load_from_pyscf_chk_mol(wfn_chk)

# specify the active space similarly to CAS methods,
# `cas =(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
write_hamil_mol(
    scf_data = scf_data,
    hamil_file = fout,
    chol_cut = chol_tol,
    cas = (ne,no),
    walker_type="closed"
)

# write the frozen core trial wavefunction
wfn = write_wfn_mol(
    scf_data = scf_data,
    filename = fout,
    cas = (ne,no)
)

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 cas=(ne, no) notation: 2 valence electrons in all remaining orbitals (no=-1)

  • Applies frozen-core transformation via write_hamil_mol with the cas parameter

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

  • Generates the trial wavefunction via write_wfn_mol and the cas parameter

AFQMC Input File (afqmc.json):

{
  "afqmc": {
    "project": {
      "id": "qmc",
      "series": 0
    },
    "execute": {
      "walker_set": {
        "walker_type": "CLOSED"
      },
      "wavefunction": {
        "filename": "afqmc.h5"
      },
      "timestep": 0.01,
      "steps": 7000,
      "n_walkers_per_mpi_task": 100,
      "population_control_interval": 10,
      "seed": 42
    }
  }
}

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