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:
Generate the trial wavefunction and orbital basis: Execute
scf/scf.pyto run PySCF calculations generating both ROHF and UHF checkpoint files.Create AFQMC input files: Execute
ham/ham.pyto generate the Hamiltonian in Cholesky-decomposed form and format 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. The write_wfn_mol () function directly handles the change of basis as demonstrated in this example. This producesafqmc.h5containing the Hamiltonian and trial wavefunction.Run SAFIRE: Run SAFIRE using the provided json input file (see below):
$ mpirun -n 16 safire afqmc.json
The AFQMC calculation will perform sampling and output energy estimates and other observables.
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 -e 5.0 -t
This will compute the average AFQMC energy and stochastic uncertainty, using an equilibration time of 5.0 \(Ha^{-1}\). The -t flag will generate 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 the following output 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 = 5.0 [+] estimate_equil = False [+] column = LocalEnergy [+] reblock = 1 [+] ndiscard = None [+] list = False [+] trace = False [+] append = None [+] dump = False [+] dump_fname = trace.dat [+] verbose = True [+] autocorr = None [+] savefig = None [+] dump_avail_columns = False AFQMC Energy -74.909596 +/- 0.000328 4.22 5.0/60.0
1.2. Files#
SCF Calculation (scf/scf.py):
#!/usr/bin/env python3
# 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
def main():
"""
Computing the energy of ferro-magnetically coupled
Vandium atoms.
"""
mol = gto.M(
atom='O 0. 0. 0.',
basis='ccpvdz',
spin=2,
verbose=4
)
mf = scf.ROHF(mol).newton()
mf.chkfile = 'rohf.chk'
mf.kernel()
mf = scf.UHF(mol).newton()
mf.chkfile = 'uhf.chk'
mf.kernel()
if __name__ == '__main__':
main()
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 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
def main():
# inputs
orbital_basis_chk = '../scf/rohf.chk'
wavefunction_chk = '../scf/uhf.chk'
chol_tol = 1e-5
# output
fout = 'afqmc.h5'
#####################################
# #
# Write Hamiltonian in ROHF basis #
# #
#####################################
scf_data = load_from_pyscf_chk_mol(
orbital_basis_chk,
'scf'
)
write_hamil_mol(
scf_data=scf_data,
hamil_file=fout,
chol_cut=chol_tol,
real_chol=True,
verbose=True
)
#####################################
# #
# Write Trial Wavefunction #
# #
#####################################
write_wfn_mol(
scf_data=load_from_pyscf_chk_mol(
wavefunction_chk,
'scf'
),
basis_scf_data=scf_data,
filename=fout
)
if __name__ == '__main__':
main()
AFQMC Input File (afqmc.json):
{
"afqmc" :{
"project": {
"id": "qmc",
"series": 0
},
"execute": {
"walker_set": {
"walker_type": "COLLINEAR"
},
"wavefunction": {
"filename": "../ham/afqmc.h5"
},
"timestep": "0.01",
"steps": "6000",
"population_control_interval": "10",
"measure_interval_multiplier": "1",
"n_walkers_per_mpi_task": "100",
"seed": "42"
}
}
}