You want to study the numpy interface in the manual (see also psi4numpy on github)
The nph
is just a view into the Matrix, it doesn’t give you access to the underlying C structure.
The syntax you want is
wfn.Ca().copy(newC)
However, here newC
is a psi4.core.Matrix
. For a given numpy array you can convert it with
newC=psi4.core.Matrix.from_array(np_array)
(see Matrix and Wavefunction class here http://psicode.org/psi4manual/master/psi4api.html#classes)
Be careful about symmetry and Matrices that contain irreps! Easy to get a segmentation fault doing it wrong.
Everything psi4 (and most of it’s plugins) are open-sourced. The C++ side of the wavefunction class is here https://github.com/psi4/psi4/blob/master/psi4/src/psi4/libmints/wavefunction.cc
This core scf function for any scf might also be interesting for you: https://github.com/psi4/psi4/blob/master/psi4/driver/procrouting/proc.py#L1231