Getting binary file with MO and basis informations from psi4

Hello psi4 community !

I am looking for a binary file that contains all the MO coefficients and the AO basis information (exponents, coordinates of GTOs, …) in double precision.

For now, I am using the fchk extension file generated by psi4. The problem is that it gives values in single precision. Maybe there is a better way to extract those informations, that I didn’t find ?

FYI, I need this to interface a new localization scheme I am working on (written in FORTRAN) with psi4. I already interfaced the scheme with another code in double precision, and I’d like to have the same using psi4.

Thank you very much,
Best,
Bruno

You may want to explore the Wavefunction object directly via the python interface to extract quantities. There’s a little background here at Psi4NumPy. When it’s clear what quantities you’re after, you can use at present the serialization of the Wfn use and contents. The present wfn serialization is a step toward MolSSI Wfn Schema which is in place in master branch of Psi4 but is only about a month old. Glad to work with you on a concrete use case if it suits.

Thanks a lot for your answer, it helps. Indeed I can see some of the features I want, like the MO coefficients and the MO energies that I can write in double precision, nalpha and nbeta…

But I have trouble to get informations from the basis set. How do you do to print the total number of shells, and also the exponent, orbital momentum, and coordinates of each GTO?
Actually I’m interested by almost all the informations that were written in the .fchk file.

According to your answer, I guess there are no common file in psi4 that stores all these informations (appart from the fchk file in single precision). The point is that if someone wants to use my localization scheme (or any other code that works in double precision), he should be able to use his old generated files containing all the MO and basis set informations, and not have to do the SCF calculation again and print all informations using the Psi4Numpy interface.

Would it be a nice feature to have an option in psi4 that generates such a file (maybe an hdf5 file), to be re-used by other codes ? And similarly (actually that’s part of another question I posted few days ago), psi4 could also read and restart an scf calculation from this file.

Just out of curiosity, what kind of localization scheme is this? You might be interested in my recent papers
https://pubs.acs.org/doi/10.1021/ct400793q unitary optimization
https://pubs.acs.org/doi/10.1021/ct401016x generalized Pipek-Mezey orbitals
https://pubs.acs.org/doi/10.1021/acs.jctc.6b00809 generalized Pipek-Mezey Wannier functions

Let me answer you privately on this if you don’t mind, to not deviate from my question :slight_smile:

The wfn in ene, wfn = energy('mtd/bas', return_wfn=True) has a wfn.basisset() object (http://psicode.org/psi4manual/master/psi4api.html#psi4.core.BasisSet) that you can access through a number of mtds. The fchk writer could probably
be rewritten in python https://github.com/psi4/psi4/blob/master/psi4/src/psi4/libmints/writer.cc#L692 .

Other files available are molden, nbo, and fcidump.

What you want, I think, going forward is the schema file, which can be in json or messagepack binary. https://github.com/psi4/psi4/blob/master/tests/pytests/test_qcschema.py#L125-L142 . The BasisSet schema is here, implementation is here.

Thanks to your guidance, I managed to get all the informations I need to write a FCHK file on my own.
I enclose the code at the end of this message for the ones that are also interested about extracting the FCHK file informations. I did not code a fchk writer though but that is not difficult.

I will need some more time to look at the generation of this schema file.

import psi4
import numpy as np

psi4.set_options({'basis': 'aug-cc-pvdz',
                  'reference': 'rohf',
                  'puream':'true'})

h2o = psi4.geometry("""
O
H 1 0.96
H 1 0.96 2 104.5
symmetry c1
""")

# Get the SCF wavefunction & energies for H2O
scf_e, scf_wfn = psi4.energy('scf', return_wfn=True)

# MO coefficients
nalpha = scf_wfn.nalpha()
nbeta  = scf_wfn.nbeta()
eps_a  = scf_wfn.epsilon_a().np
eps_b  = scf_wfn.epsilon_b().np
coeff_a = scf_wfn.Ca().np
coeff_b = scf_wfn.Ca().np

# Basis set informations
basis = scf_wfn.basisset()
print("Basis set:",basis.name())
print("Spherical ? -->",scf_wfn.basisset().has_puream())
nshell = basis.nshell()
nao = basis.nao()
nbf = basis.nbf()
nprim = basis.nprimitive()
# some more information to be written in the fchk:
mol = scf_wfn.molecule()
charge = mol.molecular_charge()
multiplicity = mol.multiplicity()
natom = mol.natom()

for ishell in range(nshell):
    shell = basis.shell(ishell)
    am = shell.AMCHAR
    center = shell.ncenter
    Z = mol.fZ(center)
    xyz = mol.xyz(center)
    print("For shell number {} center on atom {} (Z = {}, xyz = {}) with angular momentum {}".format(ishell,center,Z,xyz,am))
    nprimitive = shell.nprimitive
    print("   {:>20} {:>20}".format("exponent","coefficient"))
    for iprim in range(nprimitive):
        exp = shell.exp(iprim)
        coef= shell.coef(iprim)
        print("   {:20.12f} {:20.12f}".format(exp,coef))
1 Like