Skip to content

Commit

Permalink
Adds UCISD with density-fitting (pyscf#1450)
Browse files Browse the repository at this point in the history
* Adds support for UCISD with density fitting

* Allows RCISD with df in ci.__init__

* Remove trailing whitespaces

* Removes unnecessary import
  • Loading branch information
maxnus authored Mar 17, 2023
1 parent 15920e6 commit 737ed93
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 8 deletions.
12 changes: 6 additions & 6 deletions pyscf/ci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ def RCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
mf = scf.addons.convert_to_rhf(mf)

if getattr(mf, 'with_df', None):
raise NotImplementedError('DF-RCISD')
return cisd.RCISD(mf, frozen, mo_coeff, mo_occ)
else:
return cisd.RCISD(mf, frozen, mo_coeff, mo_occ)
RCISD.__doc__ = cisd.RCISD.__doc__
Expand All @@ -52,7 +52,7 @@ def UCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
mf = scf.addons.convert_to_uhf(mf)

if getattr(mf, 'with_df', None):
raise NotImplementedError('DF-UCISD')
return ucisd.UCISD(mf, frozen, mo_coeff, mo_occ)
else:
return ucisd.UCISD(mf, frozen, mo_coeff, mo_occ)
UCISD.__doc__ = ucisd.UCISD.__doc__
Expand All @@ -73,9 +73,9 @@ def GCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):

def QCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
if isinstance(mf, scf.uhf.UHF):
raise NotImplementedError
raise NotImplementedError
elif isinstance(mf, scf.ghf.GHF):
raise NotImplementedError
raise NotImplementedError
else:
return RQCISD(mf, frozen, mo_coeff, mo_occ)
QCISD.__doc__ = qcisd.QCISD.__doc__
Expand All @@ -93,13 +93,13 @@ def RQCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
lib.logger.warn(mf, 'RQCISD method does not support ROHF method. ROHF object '
'is converted to UHF object and UQCISD method is called.')
mf = scf.addons.convert_to_uhf(mf)
raise NotImplementedError
raise NotImplementedError

if isinstance(mf, newton_ah._CIAH_SOSCF) or not isinstance(mf, scf.hf.RHF):
mf = scf.addons.convert_to_rhf(mf)

elif numpy.iscomplexobj(mo_coeff) or numpy.iscomplexobj(mf.mo_coeff):
raise NotImplementedError
raise NotImplementedError

else:
return qcisd.QCISD(mf, frozen, mo_coeff, mo_occ)
Expand Down
32 changes: 32 additions & 0 deletions pyscf/ci/test/test_ucisd.py
Original file line number Diff line number Diff line change
Expand Up @@ -305,6 +305,38 @@ def test_cisdvec_to_amplitudes_overwritten(self):
t2bb[:] = 1
self.assertAlmostEqual(abs(vec - vec_orig).max(), 0, 15)

def test_with_df_s0(self):
mol = gto.Mole()
mol.atom = [
[8 , (0. , 0. , 0.)],
[1 , (0. , -0.757 , 0.587)],
[1 , (0. , 0.757 , 0.587)]]
mol.basis = '631g'
mol.build()
rhf = scf.RHF(mol).density_fit(auxbasis='weigend')
rhf.conv_tol_grad = 1e-8
rhf.kernel()
mf = scf.addons.convert_to_uhf(rhf)
myci = ci.UCISD(mf)
myci.kernel()
self.assertAlmostEqual(myci.e_tot, -76.1131374309989, 8)

def test_with_df_s2(self):
mol = gto.Mole()
mol.atom = [
[8 , (0. , 0. , 0.)],
[1 , (0. , -0.757 , 0.587)],
[1 , (0. , 0.757 , 0.587)]]
mol.basis = '631g'
mol.spin = 2
mol.build()
mf = scf.UHF(mol).density_fit(auxbasis='weigend')
mf.conv_tol_grad = 1e-8
mf.kernel()
myci = ci.UCISD(mf)
myci.kernel()
self.assertAlmostEqual(myci.e_tot, -75.8307298990769, 8)


if __name__ == "__main__":
print("Full Tests for UCISD")
Expand Down
3 changes: 1 addition & 2 deletions pyscf/ci/ucisd.py
Original file line number Diff line number Diff line change
Expand Up @@ -944,8 +944,7 @@ def ao2mo(self, mo_coeff=None):
return uccsd._make_eris_incore(self, mo_coeff)

elif getattr(self._scf, 'with_df', None):
raise NotImplementedError

return uccsd._make_df_eris_outcore(self, mo_coeff)
else:
return uccsd._make_eris_outcore(self, mo_coeff)

Expand Down

0 comments on commit 737ed93

Please sign in to comment.