Restarting a SCF with another reference SCF wavefunction

Hi,

I am looking for a way to restart a SCF calculation from a reference wavefunction, without the file 180 (or maybe I need to generate a 180 file with my scf_wfn but I don’t know how to proceed).

Context: I first do a scf calculation like

psi4.core.set_output_file(molecule.filename + ".out", False)
psi4.set_options({'basis': 'STO-3G',
                  'reference': 'rfh',
                  'e_convergence': '12',
                  'scf_type': 'direct',
                  'puream':False})
scf_e, scf_wfn = psi4.energy('scf', return_wfn=True)

Then, I transform the MO coefficient matrices and I set them back to the wavefunction objet as follows:

scf_wfn.Ca().np[:] = alpha_new_coeff
scf_wfn.epsilon_a().np[:] = alpha_new_energies

Similarly for beta if needed.

Finally, I tried

psi4.energy('scf', ref_wfn=scf_wfn)

but I got the following error:

ValidationError("Cannot seed an SCF calculation with a reference wavefunction ('ref_wfn' kwarg).")

Why cannot we seed a SCF calculation with a reference SCF wavefunction, if the basis is the same but only coefficients are different ? It can be useful to check that the transformation of the occupied orbitals span the same space as the canonical ones, among other things.

Otherwise, how can I bypass this issue ? Can I create a 180 file with my new scf_wfn object and set “guess read” ? If yes, how should I proceed?

Thank you

I honestly don’t know why the psi4.energy('scf', ref_wfn=scf_wfn) syntax works that way. The behavior you outlined is what happens for every other orbital optimized method in Psi4. I need to make some improvements to the orbital reading system in 1.5 anyways, so I’ll look into this then.

In the meantime, the best you can do is indeed to create a new 180 file and set guess read. The magic command to generate the 180 file should be scf_wfn.to_file(scf_wfn.get_scratch_filename(180)). Let me know whether that works.

Our manual about restarting an SCF is rather outdated it seems.
I am also not sure what PSI4 can and cannot do at this point.
However, one options is that after you modified your wavefunction object, you can write it to file
and restart your scf with it. Something like this.

scf_e, scf_wfn = energy('scf', return_wfn=True)
my_file=scf_wfn.get_scratch_filename(180) + '.npy'
scf_wfn.to_file(my_file)
set guess read
energy('scf', restart_file=my_file)

Thank you for your answers.

For now, get_scratct_filename(180) is indeed what I was looking for.

However, I still have trouble to set it properly. Here is my code:

my_file=scf_wfn.get_scratch_filename(180)
scf_wfn.to_file(my_file)
print(my_file)
psi4.core.set_output_file("anyname_restart.out", False)
psi4.set_options({'basis': 'STO-3G-decon',
              'reference': 'rohf',
              'e_convergence': '12',
              'scf_type': 'direct',
              'guess':'read',
              'puream':False})

psi4.energy(‘scf’,restart_file=my_file)

the print of “my_file” reads:

 /Users/bsenjean/psi4_scratch_dir//H4-C2_STO-3G_singlet.default.61097.180

(Note that my .bashrc contains: export PSI_SCRATCH=/Users/bsenjean/psi4_scratch_dir/)

And I got the following error:

FileNotFoundError: [Errno 2] No such file or directory: '/users/bsenjean/psi4_scratch_dir//h4-c2_sto-3g_singlet.default.61097.180'

And indeed, I have no file in my scratch directory.

Any idea what is going on ?

The instructions Holger and I gave aren’t for restart_file. Don’t supply that keyword.

If you’re still having problems after that, what Psi4 version are you using? I see the expected behavior when I try a simplified input file,

molecule quickexample {
    O   
    H 1 1.0 
    H 1 1.0 2 104.5
}

set basis sto-3g
scf_wfn = energy('scf', return_wfn=True)[1]
my_file=scf_wfn.get_scratch_filename(180)
scf_wfn.to_file(my_file)
set guess read
energy('scf')

Your example works fine also on my laptop :slight_smile:
But I still don’t get why it doesn’t work with my script and with the restart_file option. The thing is that I don’t want to execute psi4 directly, I prefer to run it with python and import psi4 for the sake of my interface with psi4.

I don’t follow. The reason why my example worked and your most recent example doesn’t is because your example supplied the restart_file keyword. Whether you run Psi with Python is a non-issue. For example, this modification of my example to a Python script also reads in the orbitals:

import psi4

mol = psi4.geometry("""
    O
    H 1 1.0
    H 1 1.0 2 104.5
""")
psi4.set_options({"basis": "STO-3G"})
scf_wfn = psi4.energy("scf", return_wfn=True)[1]
my_file = scf_wfn.get_scratch_filename(180)
scf_wfn.to_file(my_file)
psi4.set_options({"guess": "read"})
psi4.energy("scf")

The example with restart_file uses a much older interface to pass data, which is not recommended for orbital passing. We need to update the manual about this…

1 Like

It works. Though, I tried also without the restart_file at some point and it didn’t work, but I guess I just introduced another silly mistake. Anyway, it’s solved now, thank you !

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