7
$\begingroup$

I am trying to perform a CISD calculation in PySCF using the starting orbitals from an old DFT result.

The DFT result was saved on a chkfile, mf.hdf5. The code that generate this file is the following:

import pyscf.gto, pyscf.dft

bz_geom="""\
C    -1.21225309     0.69989455     0.00000000;
C    -1.21225309    -0.69989455     0.00000000;
C    -0.00000000    -1.39978909     0.00000000;
C     1.21225309    -0.69989455     0.00000000;
C     1.21225309     0.69989455     0.00000000;
C     0.00000000     1.39978909     0.00000000;
H    -2.15365863     1.24341536     0.00000000;
H    -2.15365863    -1.24341536     0.00000000;
H    -0.00000000    -2.48683071     0.00000000;
H     2.15365863    -1.24341536     0.00000000;
H     2.15365863     1.24341536     0.00000000;
H     0.00000000     2.48683071     0.00000000"""

mol = pyscf.gto.M(atom=bz_geom, basis='bfd_vtz', ecp='bfd')
mf  = pyscf.dft.RKS(mol)
mf.xc='b3lyp'
mf.chkfile="mf.hdf5"
mf.kernel()

It was very difficult to me finding documentation about how to load information from a chkfile. I came across with the function pyscf.scf.chkfile.load_scf. However, when I try to use it to perform the CI calculation, I get an error:

import pyscf.gto, pyscf.dft, pyscf.ci, pyscf.scf

mf = pyscf.scf.chkfile.load_scf('mf.hdf5')

# CISD calculation
cisolver = pyscf.ci.CISD(mf)
cisolver.kernel()

The full error message is:

---------------------------------------------------------------------------
AssertionError                            Traceback (most recent call last)
/tmp/ipykernel_20980/4228492657.py in <module>
     22 
     23 # CISD calculation
---> 24 cisolver = pyscf.ci.CISD(mf)
     25 cisolver.kernel()
     26 

~/.local/lib/python3.10/site-packages/pyscf/ci/__init__.py in CISD(mf, frozen, mo_coeff, mo_occ)
     31         return UCISD(mf, frozen, mo_coeff, mo_occ)
     32     else:
---> 33         return RCISD(mf, frozen, mo_coeff, mo_occ)
     34 CISD.__doc__ = cisd.CISD.__doc__
     35 

~/.local/lib/python3.10/site-packages/pyscf/ci/__init__.py in RCISD(mf, frozen, mo_coeff, mo_occ)
     38 
     39     if isinstance(mf, newton_ah._CIAH_SOSCF) or not isinstance(mf, scf.hf.RHF):
---> 40         mf = scf.addons.convert_to_rhf(mf)
     41 
     42     if getattr(mf, 'with_df', None):

~/.local/lib/python3.10/site-packages/pyscf/scf/addons.py in convert_to_rhf(mf, out, remove_df)
    692     from pyscf import scf
    693     from pyscf import dft
--> 694     assert (isinstance(mf, hf.SCF))
    695 
    696     logger.debug(mf, 'Converting %s to RHF', mf.__class__)

AssertionError: 

It seems to me that the error is because the mf object is from a DFT calculation and not from a HF calculation. I get a similar error before (if I try to start the CI calculation directly from the DFT mf object, instead of with the chkfile). In that case, I got a helpful error message:

RuntimeError: CISD Warning: The first argument mf is a DFT object. CISD calculation should be initialized with HF object.
DFT object can be converted to HF object with the code below:
    mf_hf = scf.RHF(mol)
    if getattr(mf_dft, "with_x2c", False):
        mf_hf = mf_hf.x2c()
    mf_hf.__dict__.update(mf_dft.__dict__)

So I should try to do something similar with the mf object obtained from pyscf.scf.chkfile.load_scf. The problem is I do not have the mol object in that case.

I probably am doing something wrong. What is the correct procedure to start a CI calculation from a previous chkfile from a DFT or HF calculation?

$\endgroup$
13
  • $\begingroup$ These two questions and their answers could provide direction for you. restarting-an-fci-calculation-in-pyscf and why-is-my-cisd-restart-failing-in-pyscf $\endgroup$ Apr 29, 2023 at 9:12
  • 2
    $\begingroup$ @VandanRevanur I read those questions before writing mine. They are not related to my problem. $\endgroup$ Apr 29, 2023 at 12:37
  • $\begingroup$ +1 and welcome to our new community! Thank you for contributing your question here and we hope to see much more of you in the future !!! Have you seen this: mattermodeling.stackexchange.com/q/10277/5 and this: mattermodeling.stackexchange.com/q/10349/5? Less relevant but perhaps also interesting to you is this: mattermodeling.stackexchange.com/q/10444/5. I was saving my HF information as a .chk file instead of a .h5 or .hdf5 file. Also, please show your input and full output. The fact that you deleted everything after " AssertionError:" is surprising to me. $\endgroup$ Apr 29, 2023 at 15:07
  • $\begingroup$ @NikeDattani I edited the question to include more info. I think none of those questions you linked are directly related to my issue, since they are about the chkfile from a CISD calculation, and not using a SCF chkfile to start a CISD calculation. Sometimes I find PySCF very confusing. $\endgroup$ Apr 29, 2023 at 16:03
  • $\begingroup$ @DavidSousa Please take a more careful look at the questions that I provided in my last comment. Also, is there nothing that comes after Assertion Error:? It would be helpful if you could provide the whole output file. Questions can have up to 30,000 characters and if you exceed that limit, there's a GitHub repository for input/output files related to MMSE posts: mattermodeling.meta.stackexchange.com/q/393/5 $\endgroup$ Apr 29, 2023 at 16:57

1 Answer 1

3
$\begingroup$

I got an answer to this question at PySCF GitHub page from James E.T. Smith. I will post here in case someone has the same issue.

It can be done both ways:

import pyscf.scf, pyscf.ci

mol = pyscf.scf.chkfile.load_mol('mf.hdf5')
mf = pyscf.scf.RHF(mol) 
mf.__dict__.update(pyscf.scf.chkfile.load('mf.hdf5', 'scf')) 

cisolver = pyscf.ci.CISD(mf)
cisolver.kernel()

or

import pyscf.scf, pyscf.ci

mol, mf_dict = pyscf.scf.chkfile.load_scf('mf.hdf5')
mf = pyscf.scf.RHF(mol) 
mf.__dict__.update(mf_dict) 
cisolver = pyscf.ci.CISD(mf)
cisolver.kernel()
$\endgroup$

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .