Skip to content

Commit

Permalink
Update tdscf initialization
Browse files Browse the repository at this point in the history
  • Loading branch information
sunqm committed Oct 26, 2023
1 parent bcb724b commit c336fe9
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 54 deletions.
10 changes: 2 additions & 8 deletions pyscf/adc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,12 +61,9 @@ def UADC(mf, frozen=None, mo_coeff=None, mo_occ=None):
if not (frozen is None or frozen == 0):
raise NotImplementedError

from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if not mf.istype('UHF'):
mf = mf.to_uhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

return uadc.UADC(mf, frozen, mo_coeff, mo_occ)

Expand All @@ -78,12 +75,9 @@ def RADC(mf, frozen=None, mo_coeff=None, mo_occ=None):
if not (frozen is None or frozen == 0):
raise NotImplementedError

from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if not mf.istype('RHF'):
mf = mf.to_rhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

return radc.RADC(mf, frozen, mo_coeff, mo_occ)

Expand Down
16 changes: 4 additions & 12 deletions pyscf/cc/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ def RCCSD(mf, frozen=None, mo_coeff=None, mo_occ=None):
import numpy
from pyscf import lib
from pyscf.df.df_jk import _DFHF
from pyscf.soscf import newton_ah
from pyscf.cc import dfccsd

if mf.istype('UHF'):
Expand All @@ -105,10 +104,9 @@ def RCCSD(mf, frozen=None, mo_coeff=None, mo_occ=None):
mf = mf.to_uhf()
return UCCSD(mf, frozen, mo_coeff, mo_occ)

mf = mf.remove_soscf()
if not mf.istype('RHF'):
mf = mf.to_rhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if isinstance(mf, _DFHF) and mf.with_df:
return dfccsd.RCCSD(mf, frozen, mo_coeff, mo_occ)
Expand All @@ -123,12 +121,10 @@ def RCCSD(mf, frozen=None, mo_coeff=None, mo_occ=None):

def UCCSD(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf.df.df_jk import _DFHF
from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if not mf.istype('UHF'):
mf = mf.to_uhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if isinstance(mf, _DFHF) and mf.with_df:
# TODO: DF-UCCSD with memory-efficient particle-particle ladder,
Expand All @@ -141,12 +137,10 @@ def UCCSD(mf, frozen=None, mo_coeff=None, mo_occ=None):

def GCCSD(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf.df.df_jk import _DFHF
from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if not mf.istype('GHF'):
mf = mf.to_ghf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if isinstance(mf, _DFHF) and mf.with_df:
raise NotImplementedError('DF-GCCSD')
Expand All @@ -169,7 +163,6 @@ def QCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
def RQCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
import numpy
from pyscf import lib
from pyscf.soscf import newton_ah

if mf.istype('UHF'):
raise RuntimeError('RQCISD cannot be used with UHF method.')
Expand All @@ -178,10 +171,9 @@ def RQCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
'is converted to UHF object and UQCISD method is called.')
raise NotImplementedError

mf = mf.remove_soscf()
if not mf.istype('RHF'):
mf = mf.to_rhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

elif numpy.iscomplexobj(mo_coeff) or numpy.iscomplexobj(mf.mo_coeff):
raise NotImplementedError
Expand Down
18 changes: 4 additions & 14 deletions pyscf/ci/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@
from pyscf.cc import qcisd

def CISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf.soscf import newton_ah

if mf.istype('UHF'):
return UCISD(mf, frozen, mo_coeff, mo_occ)
elif mf.istype('ROHF'):
Expand All @@ -35,12 +33,10 @@ def CISD(mf, frozen=None, mo_coeff=None, mo_occ=None):

def RCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf.df.df_jk import _DFHF
from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if not mf.istype('RHF'):
mf = mf.to_rhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if isinstance(mf, _DFHF) and mf.with_df:
from pyscf import lib
Expand All @@ -53,12 +49,10 @@ def RCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):

def UCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf.df.df_jk import _DFHF
from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if not mf.istype('UHF'):
mf = mf.to_uhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if isinstance(mf, _DFHF) and mf.with_df:
from pyscf import lib
Expand All @@ -72,12 +66,10 @@ def UCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):

def GCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf.df.df_jk import _DFHF
from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if not mf.istype('GHF'):
mf = mf.to_ghf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if isinstance(mf, _DFHF) and mf.with_df:
raise NotImplementedError('DF-GCISD')
Expand All @@ -100,7 +92,6 @@ def QCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
def RQCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
import numpy
from pyscf import lib
from pyscf.soscf import newton_ah

if mf.istype('UHF'):
raise RuntimeError('RQCISD cannot be used with UHF method.')
Expand All @@ -109,10 +100,9 @@ def RQCISD(mf, frozen=None, mo_coeff=None, mo_occ=None):
'is converted to UHF object and UQCISD method is called.')
raise NotImplementedError

mf = mf.remove_soscf()
if not mf.istype('RHF'):
mf = mf.to_rhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

elif numpy.iscomplexobj(mo_coeff) or numpy.iscomplexobj(mf.mo_coeff):
raise NotImplementedError
Expand Down
14 changes: 3 additions & 11 deletions pyscf/mp/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,6 @@ def MP2(mf, frozen=None, mo_coeff=None, mo_occ=None):

def RMP2(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf import lib
from pyscf.soscf import newton_ah

if mf.istype('UHF'):
raise RuntimeError('RMP2 cannot be used with UHF method.')
Expand All @@ -43,10 +42,9 @@ def RMP2(mf, frozen=None, mo_coeff=None, mo_occ=None):
'is converted to UHF object and UMP2 method is called.')
return UMP2(mf, frozen, mo_coeff, mo_occ)

mf = mf.remove_soscf()
if not mf.istype('RHF'):
mf = mf.to_rhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if getattr(mf, 'with_df', None):
return dfmp2.DFMP2(mf, frozen, mo_coeff, mo_occ)
Expand All @@ -55,12 +53,9 @@ def RMP2(mf, frozen=None, mo_coeff=None, mo_occ=None):
RMP2.__doc__ = mp2.RMP2.__doc__

def UMP2(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if mf.istype('UHF'):
mf = mf.to_uhf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if getattr(mf, 'with_df', None):
#raise NotImplementedError('DF-UMP2')
Expand All @@ -70,12 +65,9 @@ def UMP2(mf, frozen=None, mo_coeff=None, mo_occ=None):
UMP2.__doc__ = ump2.UMP2.__doc__

def GMP2(mf, frozen=None, mo_coeff=None, mo_occ=None):
from pyscf.soscf import newton_ah

mf = mf.remove_soscf()
if not mf.istype('GHF'):
mf = mf.to_ghf()
if isinstance(mf, newton_ah._CIAH_SOSCF):
mf = mf.undo_soscf()

if getattr(mf, 'with_df', None):
return dfgmp2.DFGMP2(mf, frozen, mo_coeff, mo_occ)
Expand Down
15 changes: 6 additions & 9 deletions pyscf/pbc/tdscf/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,22 +31,20 @@
pass

def TDHF(mf):
import numpy
if isinstance(mf, scf.khf.KSCF):
return KTDHF(mf)
if isinstance(mf, scf.hf.KohnShamDFT):
raise RuntimeError('TDHF does not support DFT object %s' % mf)
#TODO: mf = mf.remove_soscf()
mf = mf.remove_soscf()
if isinstance(mf, scf.rohf.ROHF):
# Is it correct to call TDUHF for ROHF?
mf = mf.to_uhf()
return mf.TDHF()

def TDA(mf):
import numpy
if isinstance(mf, scf.khf.KSCF):
return KTDA(mf)
#TODO: mf = mf.remove_soscf()
mf = mf.remove_soscf()
if isinstance(mf, scf.rohf.ROHF):
if isinstance(mf, scf.hf.KohnShamDFT):
mf = mf.to_uks()
Expand All @@ -55,11 +53,10 @@ def TDA(mf):
return mf.TDA()

def TDDFT(mf):
import numpy
if isinstance(mf, scf.khf.KSCF):
return KTDDFT(mf)
if isinstance(mf, scf.hf.KohnShamDFT):
#TODO: mf = mf.remove_soscf()
mf = mf.remove_soscf()
if isinstance(mf, scf.rohf.ROHF):
mf = mf.to_uks()
return mf.TDDFT()
Expand All @@ -69,13 +66,13 @@ def TDDFT(mf):
def KTDHF(mf):
if isinstance(mf, scf.hf.KohnShamDFT):
raise RuntimeError('TDHF does not support DFT object %s' % mf)
#TODO: mf = mf.remove_soscf()
mf = mf.remove_soscf()
if isinstance(mf, scf.rohf.ROHF):
mf = mf.to_uhf()
return mf.TDHF()

def KTDA(mf):
#TODO: mf = mf.remove_soscf()
mf = mf.remove_soscf()
if isinstance(mf, scf.rohf.ROHF):
if isinstance(mf, scf.hf.KohnShamDFT):
mf = mf.to_uks()
Expand All @@ -85,7 +82,7 @@ def KTDA(mf):

def KTDDFT(mf):
if isinstance(mf, scf.hf.KohnShamDFT):
#TODO: mf = mf.remove_soscf()
mf = mf.remove_soscf()
if isinstance(mf, scf.rohf.ROHF):
mf = mf.to_uks()
return mf.TDDFT()
Expand Down

0 comments on commit c336fe9

Please sign in to comment.