Psi4 has a very nice function to write the wfn to a molden file by “molden(wfn, filename)”. I am wondering whether the reverse can be done (i.e., reading a molden file as a wfn)? Practically speaking, I would assume so since the molden file contains all the necessary information to build a wfn.
I found that one can construct a wfn with a molecule and basis set by doing:
The molden format isn’t well defined (or at least not implemented 100% the same way in various programs). If you know the Multiwfn code, the author had to do all sorts of tricks to account for how programs write molden files. Thus I see little hope of anyone wanting to program an interface for the backtransformation.
Hi @hokru, thanks for your speedy response! I am aware of the problem of molden format issues. But what I want to know is, if I have the MO coefficients, how can I set it to the wfn object? For example, something like
wfn_loaded.Ca().nph[:] = my_MO_coeff
I tried the above but it did not work. I also tried to search for the source code of the psi4.core.Wavefunction but it seems that part of the code is not open-sourced?
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.