diff --git a/pyscf/pbc/tdscf/krhf.py b/pyscf/pbc/tdscf/krhf.py index b41978f5c2..1abe6bcbf7 100644 --- a/pyscf/pbc/tdscf/krhf.py +++ b/pyscf/pbc/tdscf/krhf.py @@ -26,7 +26,7 @@ from pyscf.lib import linalg_helper from pyscf.lib import logger from pyscf.tdscf import rhf -from pyscf.tdscf._lr_eig import eig as lr_eig +from pyscf.tdscf._lr_eig import eigh as lr_eigh, eig as lr_eig from pyscf.pbc import scf from pyscf.pbc.tdscf.rhf import TDBase from pyscf.pbc.scf import _response_functions # noqa @@ -155,6 +155,8 @@ def add_hf_(a, b, hyb=1): return a, b class KTDBase(TDBase): + conv_tol = getattr(__config__, 'pbc_tdscf_rhf_TDA_conv_tol', 1e-4) + _keys = {'kconserv', 'kshift_lst'} def __init__(self, mf, kshift_lst=None): @@ -184,7 +186,6 @@ def dump_flags(self, verbose=None): log.info('conv_tol = %g', self.conv_tol) log.info('eigh lindep = %g', self.lindep) log.info('eigh level_shift = %g', self.level_shift) - log.info('eigh max_space = %d', self.max_space) log.info('eigh max_cycle = %d', self.max_cycle) log.info('chkfile = %s', self.chkfile) log.info('max_memory %d MB (current use %d MB)', @@ -215,7 +216,6 @@ def _finalize(self): get_nto = lib.invalid_method('get_nto') class TDA(KTDBase): - conv_tol = getattr(__config__, 'pbc_tdscf_rhf_TDA_conv_tol', 1e-6) @lib.with_doc(get_ab.__doc__) def get_ab(self, mf=None, kshift=0): @@ -325,13 +325,10 @@ def pickeig(w, v, nroots, envs): else: x0k = x0[i] - converged, e, x1 = \ - lib.davidson1(vind, x0k, precond, - tol=self.conv_tol, - max_cycle=self.max_cycle, - nroots=self.nstates, lindep=self.lindep, - max_space=self.max_space, pick=pickeig, - verbose=self.verbose) + converged, e, x1 = lr_eigh( + vind, x0k, precond, tol_residual=self.conv_tol, lindep=self.lindep, + nroots=self.nstates, pick=pickeig, max_cycle=self.max_cycle, + max_memory=self.max_memory, verbose=log) self.converged.append( converged ) self.e.append( e ) # 1/sqrt(2) because self.x is for alpha excitation amplitude and 2(X^+*X) = 1 @@ -345,8 +342,6 @@ def pickeig(w, v, nroots, envs): class TDHF(KTDBase): - conv_tol = 1e-5 - @lib.with_doc(get_ab.__doc__) def get_ab(self, mf=None, kshift=0): if mf is None: mf = self._scf @@ -483,9 +478,9 @@ def norm_xy(z, kconserv): x0k = x0[i] converged, e, x1 = lr_eig( - vind, x0k, precond, tol_residual=self.conv_tol, nroots=self.nstates, - lindep=self.lindep, max_cycle=self.max_cycle, - max_space=self.max_space, pick=pickeig, verbose=log) + vind, x0k, precond, tol_residual=self.conv_tol, lindep=self.lindep, + nroots=self.nstates, pick=pickeig, max_cycle=self.max_cycle, + max_memory=self.max_memory, verbose=log) self.converged.append( converged ) self.e.append( e ) self.xy.append( [norm_xy(z, kconserv) for z in x1] ) diff --git a/pyscf/pbc/tdscf/kuhf.py b/pyscf/pbc/tdscf/kuhf.py index e8e0986a33..86eb31c2d6 100644 --- a/pyscf/pbc/tdscf/kuhf.py +++ b/pyscf/pbc/tdscf/kuhf.py @@ -21,7 +21,7 @@ from pyscf import lib from pyscf.lib import logger from pyscf.tdscf import uhf -from pyscf.tdscf._lr_eig import eig as lr_eig +from pyscf.tdscf._lr_eig import eigh as lr_eigh, eig as lr_eig from pyscf.pbc import scf from pyscf.pbc.tdscf.krhf import KTDBase, _get_e_ia from pyscf.pbc.lib.kpts_helper import is_gamma_point @@ -146,14 +146,10 @@ def pickeig(w, v, nroots, envs): else: x0k = x0[i] - converged, e, x1 = \ - lib.davidson1(vind, x0k, precond, - tol=self.conv_tol, - max_cycle=self.max_cycle, - nroots=self.nstates, - lindep=self.lindep, - max_space=self.max_space, pick=pickeig, - verbose=self.verbose) + converged, e, x1 = lr_eigh( + vind, x0k, precond, tol_residual=self.conv_tol, lindep=self.lindep, + nroots=self.nstates, pick=pickeig, max_cycle=self.max_cycle, + max_memory=self.max_memory, verbose=log) self.converged.append( converged ) self.e.append( e ) self.xy.append( [(_unpack(xi, mo_occ, kconserv), # (X_alpha, X_beta) @@ -296,9 +292,9 @@ def pickeig(w, v, nroots, envs): x0k = x0[i] converged, w, x1 = lr_eig( - vind, x0k, precond, tol_residual=self.conv_tol, nroots=self.nstates, - lindep=self.lindep, max_cycle=self.max_cycle, - max_space=self.max_space, pick=pickeig, verbose=log) + vind, x0k, precond, tol_residual=self.conv_tol, lindep=self.lindep, + nroots=self.nstates, pick=pickeig, max_cycle=self.max_cycle, + max_memory=self.max_memory, verbose=log) self.converged.append( converged ) e = [] diff --git a/pyscf/tdscf/dhf.py b/pyscf/tdscf/dhf.py index 6e93d11135..00cf71a06a 100644 --- a/pyscf/tdscf/dhf.py +++ b/pyscf/tdscf/dhf.py @@ -525,7 +525,6 @@ def vind(xys): class TDHF(TDBase): - conv_tol = 1e-4 singlet = None @lib.with_doc(gen_tdhf_operation.__doc__) diff --git a/pyscf/tdscf/ghf.py b/pyscf/tdscf/ghf.py index 52071f7468..9bd02b74ec 100644 --- a/pyscf/tdscf/ghf.py +++ b/pyscf/tdscf/ghf.py @@ -544,7 +544,6 @@ def vind(xys): class TDHF(TDBase): - conv_tol = 1e-4 singlet = None @lib.with_doc(gen_tdhf_operation.__doc__) diff --git a/pyscf/tdscf/rhf.py b/pyscf/tdscf/rhf.py index 8dd0bf9fee..aa5f1f8fcc 100644 --- a/pyscf/tdscf/rhf.py +++ b/pyscf/tdscf/rhf.py @@ -660,7 +660,6 @@ class TDBase(lib.StreamObject): singlet = getattr(__config__, 'tdscf_rhf_TDA_singlet', True) lindep = getattr(__config__, 'tdscf_rhf_TDA_lindep', 1e-12) level_shift = getattr(__config__, 'tdscf_rhf_TDA_level_shift', 0) - max_space = getattr(__config__, 'tdscf_rhf_TDA_max_space', 50) max_cycle = getattr(__config__, 'tdscf_rhf_TDA_max_cycle', 100) # Low excitation filter to avoid numerical instability positive_eig_threshold = getattr(__config__, 'tdscf_rhf_TDDFT_positive_eig_threshold', 1e-3) @@ -668,7 +667,7 @@ class TDBase(lib.StreamObject): deg_eia_thresh = getattr(__config__, 'tdscf_rhf_TDDFT_deg_eia_thresh', 1e-3) _keys = { - 'conv_tol', 'nstates', 'singlet', 'lindep', 'level_shift', 'max_space', + 'conv_tol', 'nstates', 'singlet', 'lindep', 'level_shift', 'max_cycle', 'mol', 'chkfile', 'wfnsym', 'converged', 'e', 'xy', } @@ -716,7 +715,6 @@ def dump_flags(self, verbose=None): log.info('conv_tol = %g', self.conv_tol) log.info('eigh lindep = %g', self.lindep) log.info('eigh level_shift = %g', self.level_shift) - log.info('eigh max_space = %d', self.max_space) log.info('eigh max_cycle = %d', self.max_cycle) log.info('chkfile = %s', self.chkfile) log.info('max_memory %d MB (current use %d MB)', @@ -1007,8 +1005,6 @@ class TDHF(TDBase): normalized to 1 for UHF/UKS methods. In the TDA calculation, Y = 0. ''' - conv_tol = 1e-4 - @lib.with_doc(gen_tdhf_operation.__doc__) def gen_vind(self, mf=None): if mf is None: diff --git a/pyscf/tdscf/test/test_tddks.py b/pyscf/tdscf/test/test_tddks.py index 7b8b093330..e548377def 100644 --- a/pyscf/tdscf/test/test_tddks.py +++ b/pyscf/tdscf/test/test_tddks.py @@ -114,13 +114,15 @@ def test_mcol_mgga_ab_ks(self): mcol_m06l = dft.UDKS(mol).set(xc='m06l', collinear='mcol') mcol_m06l._numint.spin_samples = 6 mcol_m06l.__dict__.update(scf.chkfile.load(mf_lda.chkfile, 'scf')) - self._check_against_ab_ks(mcol_m06l.TDDFT(), 14.934345395514491, 9.539340104227188) + self._check_against_ab_ks(mcol_m06l.TDDFT()) - def _check_against_ab_ks(self, td, refa, refb): + def _check_against_ab_ks(self, td, refa=None, refb=None): mf = td._scf a, b = td.get_ab() - self.assertAlmostEqual(lib.fp(abs(a)), refa, 4) - self.assertAlmostEqual(lib.fp(abs(b)), refb, 4) + if refa is not None: + self.assertAlmostEqual(lib.fp(abs(a)), refa, 4) + if refb is not None: + self.assertAlmostEqual(lib.fp(abs(b)), refb, 4) ftda = mf.TDA().gen_vind()[0] ftdhf = td.gen_vind()[0] n2c = mf.mo_occ.size // 2 diff --git a/pyscf/tdscf/uhf.py b/pyscf/tdscf/uhf.py index abdad81c31..39ddb137f6 100644 --- a/pyscf/tdscf/uhf.py +++ b/pyscf/tdscf/uhf.py @@ -813,7 +813,6 @@ def vind(xys): class TDHF(TDBase): - conv_tol = 1e-4 singlet = None @lib.with_doc(gen_tdhf_operation.__doc__)