RuntimeError when setting custom Ca and Cb matrices in Wavefunction
Hello Psi4 community,
I’m trying to initialize a Psi4 wavefunction with custom Ca and Cb matrices for post-SCF calculations without running an SCF cycle. My goal is to use Psi4’s post-SCF capabilities with orbital coefficients from an external program. Here’s a minimal example demonstrating the issue:
import psi4
import numpy as np
# Set up a simple hydrogen atom
molecule = psi4.geometry("""
0 2
H
symmetry c1
""")
# Set basic options
psi4.set_options({"basis": "sto-3g", "reference": "uhf"})
# Build initial wavefunction
wfn = psi4.core.Wavefunction.build(molecule, psi4.core.get_global_option("basis"))
# Get number of symmetry orbitals
nso = wfn.nso()
# Create mock Ca and Cb matrices
Ca_matrix = np.random.rand(nso, nso)
Cb_matrix = np.random.rand(nso, nso)
# Convert to psi4.core.Matrix objects
Ca = psi4.core.Matrix.from_array(Ca_matrix)
Cb = psi4.core.Matrix.from_array(Cb_matrix)
# Attempt to set Ca and Cb
wfn.Ca().copy(Ca)
wfn.Cb().copy(Cb)
When I run this code, I get the following error:
RuntimeError:
Fatal Error: Wavefunction::Ca: Unable to obtain MO coefficients.
Error occurred in file: /scratch/psilocaluser/conda-builds/psi4-multiout_1670980379431/work/psi4/src/psi4/libmints/wavefunction.cc on line: 804
The most recent 5 function calls were:
psi::Wavefunction::Ca() const
My Psi4 version information:
psi4 --version
1.7
which conda python psi4
/opt/conda/condabin/conda /opt/conda/envs/p4env2/bin/python /opt/conda/envs/p4env2/bin/psi4
My questions are:
- Why can I not set the Ca and Cb matrices directly?
- Is there a way to initialize a wavefunction with custom orbital coefficients without running an SCF cycle?
- How can I create a fully customized wavefunction object that I can then use for post-SCF calculations?
I’ve searched the forum and found some related posts:
However, these don’t fully address my use case of initializing with dummy data without running an SCF cycle. The discussions in these threads suggest that additional steps might be needed to set up a wavefunction with custom matrices properly, but I’m still unclear on the exact procedure.
I appreciate your help, and I apologize if I’ve missed an existing answer to this question!