Fock Matrix in Original Basis

Following SCF calculations I am trying to output the Fock matrix in the original (AO) basis - without success. I have tried using the method Fa_subset( , ) but this is not recognised by the computation, despite many different attempts with different syntax. Any help appreciated. Thanks.

Something like this?

e,wfn =energy('hf',return_wfn=True)
F_ao = wfn.Fa_subset("AO").to_array() # psi4 object to numpy array; see core.Vector class

Many thanks for your reply - still having problems. See input and error message below (testing optimizer).

memory 600 mb

molecule ch4 {
C 0 0 0
H 1 0 0.1
H -0.5 0.1 0.5
H -0.5 0.5 -0.6
H -0.6 -0.5 -0.5
}

set basis cc-pVDZ
optimize(“scf”)
E,wfn=energy(“scf”,return_wfn=True)
F_ao=wfn.Fa_subset(“AO”)

Optimizer: Optimization complete!
Traceback (most recent call last):
File “/home/donald/psi4conda/bin/psi4”, line 269, in
exec(content)
File “”, line 34, in

AttributeError: ‘psi4.core.RHF’ object has no attribute ‘Fa_subset’

What am I missing? Thanks in anticipation.

What version of Psi4 do you have?

Output files show Psi4 1.2.1

You may need Psi4 1.3+ to use this feature.

Hi again. Further to this subject - can you advise? I am using psi4 in psithon mode. I have the statements:

Fock=wfn.Fa_subset(“AO”)
core.Matrix.save(Fock,“h2o.Fock”,append=True,saveLowerTriangle=True,saveSubBlocks=False)

I have a problem understanding some of the arguments in core.Matrix.save - “append=True”. Append what? This is a general problem for me with psi4; I find it difficult to find detailed information on function arguments and what they mean in the psi4 manual (I am a real novice with ab initio calculations). Is there a repository of detailed information that I am missing maybe? Please don’t misunderstand me - I think psi4 is awesome !!

I use the lower triangular Fock matrix with Multiwfn to derive localized orbitals. However, for some simple molecules and basis sets I find that core.Matrix.save only returns the non-zero entries. Is that what you would expect?

Hope you can help. Many thanks.

You are right about the missing documentation. Active developers are facing the same problems.
The C++ source code has strings for documentation( doxygen ), but they are not picked up by the documentation mechanism with sphinx. And the manual transfer (or some other solution) has not happened.

The C++ Matrix class is “documented” here: psi4/psi4/src/psi4/libmints/matrix.h at master · psi4/psi4 · GitHub
The available python bindings are here (which you probably already use, but just for completeness): PSI4 API: Linking C++ and Python

append=True would mean that the file is not overwritten but the next matrix is appended.

Not sure about that. Is does not print the full triangle?

Many thanks for the very useful response (hokru - I note you are one of the main responders on the forum. Many thanks for taking the time; you are such a good guy!).

Fock matrix return - I attach an “in” file with corresponding “out” and “Fock” files. The Fock file contains only the non-zero values. Can you advise if my “in” file contains errors? Many thanks.h2o.out.dat (150.7 KB) h2o.in.dat (469 Bytes) h2o.Fock.dat (1.9 KB)

From what I gather, the original plan was that developers would fill in the documentation as they needed it themselves. …And that never really happened, so you have the current state of affairs. One of the other developers (Lori) says she plans to do a documentation pass, so I’m hopeful for some improvements soon. In the meantime, I’m adding documentation that I find I need.

For your case, you’re misinterpreting what the third keyword to “save” does. saveLowerTriangle does not mean save the lower triangle also but save the lower triangle only. To get the entire matrix, just set that keyword to False.

I think you should stay away from this particular save function.
It only writes values >1e-12, which makes it ill-suited for data exchange where small values might occur.

Going via the numpy route is saver:

Fock=wfn.Fa_subset("AO").to_array()
np.savetxt('h2o.Fock',Fock) 

This will print the full matrix and you can modify the print out (https://numpy.org/doc/stable/reference/generated/numpy.savetxt.html)

There surely are also smart ways to get only the upper/lower part if you need it.
(https://stackoverflow.com/questions/8905501/extract-upper-or-lower-triangular-part-of-a-numpy-matrix)