I cannot remember how it was before psi4 was made a python module, but right now “print” prints
to stdout (I think). I was confused trying to find my table in the redirected output where the calculation is.
My history shows print no longer being directed to the output file as happening earlier than the inversion, but certainly around that time, we became more receptive to leaving legitimate python alone, instead of intercepting it and redirecting to the output file. I think previously print went to the output file and print_stdout went to ~screen. Now, print does go to screen, as you noted, but you can send most stuff to the output file via print_out. The below collects everything to output.
molecule h2o {
O
H 1 R
H 1 R 2 A
}
Rvals=[0.9,1.0,1.1]
Avals=range(100,102,2)
table=Table(rows=["R","A"], cols=["E(SCF)","E(SCS)","E(DFMP2)"])
set basis cc-pvdz
print_out("cat in the hat") # plain string
for R in Rvals:
h2o.R = R
for A in Avals:
h2o.A = A
energy('mp2')
escf = get_variable('SCF TOTAL ENERGY')
edfmp2 = get_variable('MP2 TOTAL ENERGY')
escsmp2 = get_variable('SCS-MP2 TOTAL ENERGY')
table[R][A] = [escf, escsmp2, edfmp2]
print_out(str(table)) # object
relative=table.copy()
relative.absolute_to_relative()
print_out(str(relative))
#print_out(str(relative).decode()) # alt. object if it starts complaining about unicode
If you print a psi4.Matrix or Molecule, that’s always going to go to the output file. It’s true that the current printing scheme isn’t throughly consistent, but it’ll probably stay as is until we need to revise for, say, Jupyter notebooks.