Getting wavefunction object from file

Hi,

The question I’m going to ask is a bit similar to a previous one of mine : Restarting a SCF with another reference SCF wavefunction

But I think it is still different enough for me to make a new post.

What I would like is to be able to store a wavefunction object from psi4, that could be used anytime for other purposes. For instance, I would like to do a SCF calculation which can take hours, store the scf_wfn object into a file, and then use this file in another script to rebuild the scf_wfn object for post-HF purposes, or to change the MO coefficient of this scf_wfn object only.

For now, I did something like this:

scf_e, scf_wfn = psi4.energy('scf', return_wfn=True)
my_file=scf_wfn.get_scratch_filename(180) + '.npy'
subprocess.check_call("cp " + my_file + " scf_wfn.npy", shell = True)

And I indeed get a scf_wfn.npy which I tried to extract in another script as:

scf_wfn = numpy.load("scf_wfn.npy",allow_pickle=True)

But it doesn’t seem to work properly as the object is not really the same. For instance, I get such kind of error when playing with MO coefficients:

'numpy.ndarray' object has no attribute 'Ca'

Any idea of what is going wrong and how I can really extract this scf_wfn from a file ?

Why not just use scf_wfn.to_file(filename_here)?

I get the following error if I do that:

NameError: name 'scf_wfn' is not defined

I think that’s because this other script doesn’t start with a SCF calculation. So scf_wfn is never initialized in this script. Maybe I’m missing something pretty obvious here.

No, no, scf_wfn.to_file(filename_here) goes in the first file.

See here for an example of writing a wavefunction to a file and then reading it back from a file. The same trick should work if you move the call to read from a file into its script, as long as it can find the path you give it.

Thank you ! It works, I just didn’t find those commands before :slight_smile:

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.