Recently my question: Why does CCSD work, but not CCSD(T), after reading an FCIDUMP in PySCF? lead to a bug fix that allows users to do CCSD(T) calculations from an FCIDUMP file in PySCF. That was with the FCIDUMP file being in ASCII format though!
When the FCIDUMP file is in ASCII format, it's easy to create an "SCF object" from the dump file:
mf = pyscf.tools.fcidump.to_scf(name+'.fcidump', molpro_orbsym=False, mf=None)
mf.run()
That object is what's required to do CCSD calculations:
mcc = cc.CCSD(mf)
e = mcc.kernel()
However the function that "loads" an FCIDUMP file in HDF5 format gives an eri
object instead of an scf
object:
eri = ao2mo.load(name+'.fcidump.h5',dataname='dummy_label')
Attempting to do CCSD from only the ERI object
If I were just to replace the above mf
with eri
as in the line below:
mcc = cc.CCSD(eri)
then it will trigger the convert_to_rhf
function in pyscf/scf/addons.py
which will crash at assert (isinstance(mf, hf.SCF))
presumably because eri
is not an instance of an hf.SCF
object.
By simply doing:
mcc = cc.CCSD()
there will be a complaint about the required mf
input being missing. If we do:
mcc = pyscf.cc.ccsd.kernel(eris=eri, callback=None)
there will be an error because cc.ccsd.kernel()
requries a mycc
object as an input argument. The following gets us closer:
mcc = pyscf.cc.ccsd.kernel(0,eris=eri, verbose=9,callback=None)
but ends in pyscf/cc/ccsd.py
at mycc.get_init_guess(eris)
presumably because the integer 0
doesn't contain information about the initial guess for the CCSD calculation:
AttributeError: 'int' object has no attribute 'get_init_guess'
In most programs, asking for a CCSD calculation automatically triggers an MP2 calculation so that there's a decent initial guess for the CCSD, and I'm sure that's also happening in PySCF if I do cc.CCSD(mf)
, but it seems that if we run pyscf.cc.ccsd.kernel()
instead (due to not having an mf
object), then we need to do explicitly tell the program to do an MP2 calcualtion first. The brings us to the question:
Attempting to do MP2 from only the ERI object
Running mf.MP2().run()
requires an mf
object. The following:
eri.MP2().run(verbose=9)
won't work because eri
is a load
object and doesn't have an mp2
attribute:
AttributeError: 'load' object has no attribute 'MP2'
In fact pyscf.ci.cisd.CISD()
would also complain about not having an mf
object.
Attempting to get an SCF object from an ERI object
As long as we can get an mf
object from the eri
, we can do CISD, MP2, CCSD and much more. Attempting to create the mf
object from the FCIDUMP in the way that we did when the FCIDUMP was in ASCII format:
mf = pyscf.tools.fcidump.to_scf(name+'.fcidump.h5', molpro_orbsym=False, mf=None)
just leads to a complaint which seems to be about the FCIDUMP file not being in ASCII format:
python3.8/codecs.py", line 322, in decode
(result, consumed) = self._buffer_decode(data, self.errors, final)
UnicodeDecodeError: 'utf-8' codec can't decode byte 0x89 in position 0: invalid start byte
There's not much documentation for pyscf.tools.fcidump.to_scf()
but the source code suggests that it will only work if the FCIDUMP file is in ASCII format. Perhaps it can be hacked to go into the HDF5 file and fetch the integrals, but I would think that since PySCF has the capability to load
the integrals with ao2mo.load()
, it would have the ability to use loaded integrals, meaning that there's already a way to get the mf
object from an eri
object.
I've also looked at pyscf.tools.fcidump.scf_from_fcidump()
but it seems to require the user to already have an mf
object. Also in pyscf/tools/fcidump.py
there are the from_mo()
and from_integrals()
, but they are for writing FCIDUMP files, not loading them.
Question
My question was how to do CCSD from an FCIDUMP file in HDF5 format. Based on the above troubleshooting, I've discovered that it boils down to converting the eri
object obtained from the FCIDUMP.h5 file into an scf
object, which I don't know how to do!
The following script will create the FCIDUMP.h5
file (only about 11 kB since I used a STO-3G basis set) and then will load the FCIDUMP.h5 file into an eri
object which is classified as a "load" object:
#!/usr/bin/env python
# Author: Nike Dattani, [email protected]
import pyscf
from pyscf import gto, scf, ao2mo, cc
mol = gto.Mole()
mol.atom = ''' O
H 1 0.9576257
H 1 0.9576257 2 104.51 '''
mol.unit = 'angstrom'
mol.basis = 'STO-3G'
mol.charge = 0
mol.spin = 0
mol.verbose = 9
mol.symmetry = True
mol.symmetry_subgroup = 'C2v'
name = 'out'
#mol.output = name+'.txt' # only worked up to end of SCF (CC output went to stdout)
mol.build()
#####################
## Hartree-Fock:
#####################
mf = mol.RHF().set(chkfile = name + '.chk')
mf.kernel()
pyscf.ao2mo.kernel(mol, mf.mo_coeff, name+'.fcidump.h5', dataname='hdf5_group_name')
eri = ao2mo.load(name+'.fcidump.h5',dataname='dummy_label')
Running the above script will also give you an mf
object, but the question is how to continue to post-HF calculations without using it at all.