Convert molden to wfn (180, npy) file

Dear users and developers,

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:

wfn = psi4.core.Wavefunction.build(molecule, basis_set)

But I am stuck at how I can set values for MO coefficients and occupations. Any help will be appreciated!

Best,
Chenru

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.

This might be interesting for you:

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.

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

1 Like

Thanks! This is exactly what I needed!

Dear Chenru,
if you have any working code that can import Molden files, I would be grateful if you could share it.

Thanks,
Tibor Győri

Hi I am still working on it to make it more general and readable. I will post a script here once done

@TiborGY, just FYI that the script is at the open-source package of our group: https://github.com/hjkgrp/molSimplify/blob/master/molSimplify/Scripts/molden2psi4wfn.py. You many need to adjust slightly about the function (noted in the comments in the script) depending on what basis set you will use. Please feel free to let me know if you have any questions.

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