#! Density fitted MP2 energy of H2, using density fitted reference and automatic looping over cc-pVDZ and cc-pVTZ basis sets.
#! Results are tabulated using the built in table functions by using the default options and by specifiying the format.

# This will remove the 32 file in each iteration of the for loop 
psi4_io.set_specific_retention(32,False)

memory 250 mb


molecule h2 {
   0 1
   H
   H 1 0.9
}

set {
   scf_type   df
   guess      sad
   d_convergence 12
   e_convergence 12
}

# This is a table that uses just the default parameters
table = Table(rows=("Basis"), cols=("E(DF-SCF)", "E(DF-MP2)"))

# This is the same table, but with more explicit control of column widths
longtable = Table(rows=("Basis"), cols=("E(DF-SCF)", "E(DF-MP2)"),
                  row_label_width=10,
                  row_label_precision=4,
                  width=20, precision=12)

basissets = ["cc-pVDZ", "cc-pVTZ"]


for basisset in basissets:
    set basis        $basisset
    jkbasis = basisset + "-jkfit"
    set df_basis_scf $jkbasis
    ribasis = basisset + "-ri"
    set df_basis_mp2 $ribasis
    edfmp2 = energy('df-mp2')
    edfscf = get_variable('SCF TOTAL ENERGY')
    # Store the computed values in the tables
    table[basisset]     = [edfscf, edfmp2]
    longtable[basisset] = [edfscf, edfmp2]
    # We clean out the scratch files here because the dimensions of the basis set have
    # changed, so we want to generate new files
    clean()

print_out("\nSummary of results\n")
print_out(str(table))
print_out("\nAnd again, but more precision\n")
print_out(str(longtable))
