diff --git a/pyscf/__config__.py b/pyscf/__config__.py index d9ce17b57a..8c1779e60a 100644 --- a/pyscf/__config__.py +++ b/pyscf/__config__.py @@ -28,15 +28,10 @@ conf_file = None if conf_file is not None: - if sys.version_info < (3,0): - import imp - imp.load_source('pyscf.__config__', conf_file) - del (imp) - else: - from importlib import machinery - machinery.SourceFileLoader('pyscf.__config__', conf_file).load_module() - del (machinery) -del (os, sys) + with open(conf_file, 'r') as f: + exec(f.read()) + del f +del (os, sys, tempfile) # # All parameters initialized after loading pyscf_conf.py will be kept in the diff --git a/pyscf/df/grad/casscf.py b/pyscf/df/grad/casscf.py index a5bce4404f..56815f96b7 100644 --- a/pyscf/df/grad/casscf.py +++ b/pyscf/df/grad/casscf.py @@ -179,6 +179,8 @@ def __call__(self, mol_or_geom, **kwargs): class Gradients(casci_grad.Gradients): '''Non-relativistic restricted Hartree-Fock gradients''' + _keys = {'with_df', 'auxbasis_response'} + def __init__(self, mc): self.with_df = mc.with_df self.auxbasis_response = True diff --git a/pyscf/df/grad/rhf.py b/pyscf/df/grad/rhf.py index 39ac3ce531..8ed06362d8 100644 --- a/pyscf/df/grad/rhf.py +++ b/pyscf/df/grad/rhf.py @@ -441,6 +441,9 @@ def __call__(self, set_id, p0, p1): class Gradients(rhf_grad.Gradients): '''Restricted density-fitting Hartree-Fock gradients''' + + _keys = {'with_df', 'auxbasis_response'} + def __init__(self, mf): # Whether to include the response of DF auxiliary basis when computing # nuclear gradients of J/K matrices diff --git a/pyscf/df/grad/rks.py b/pyscf/df/grad/rks.py index 08f24e3035..adfc7b7080 100644 --- a/pyscf/df/grad/rks.py +++ b/pyscf/df/grad/rks.py @@ -103,6 +103,9 @@ def get_veff(ks_grad, mol=None, dm=None): class Gradients(rks_grad.Gradients): + + _keys = {'with_df', 'auxbasis_response'} + def __init__(self, mf): # Whether to include the response of DF auxiliary basis when computing # nuclear gradients of J/K matrices diff --git a/pyscf/df/grad/sacasscf.py b/pyscf/df/grad/sacasscf.py index 828b13febe..1d985d993c 100644 --- a/pyscf/df/grad/sacasscf.py +++ b/pyscf/df/grad/sacasscf.py @@ -351,6 +351,8 @@ def __call__(self, mol_or_geom, **kwargs): class Gradients (sacasscf_grad.Gradients): + _keys = {'with_df', 'auxbasis_response'} + def __init__(self, mc, state=None): self.auxbasis_response = True sacasscf_grad.Gradients.__init__(self, mc, state=state) diff --git a/pyscf/df/grad/uhf.py b/pyscf/df/grad/uhf.py index 2aa7e86e13..0eec773b0d 100644 --- a/pyscf/df/grad/uhf.py +++ b/pyscf/df/grad/uhf.py @@ -31,6 +31,9 @@ class Gradients(uhf_grad.Gradients): '''Unrestricted density-fitting Hartree-Fock gradients''' + + _keys = {'with_df', 'auxbasis_response'} + def __init__(self, mf): # Whether to include the response of DF auxiliary basis when computing # nuclear gradients of J/K matrices diff --git a/pyscf/df/grad/uks.py b/pyscf/df/grad/uks.py index b925de2285..e6de663a95 100644 --- a/pyscf/df/grad/uks.py +++ b/pyscf/df/grad/uks.py @@ -104,6 +104,9 @@ def get_veff(ks_grad, mol=None, dm=None): class Gradients(uks_grad.Gradients): + + _keys = {'with_df', 'auxbasis_response'} + def __init__(self, mf): # Whether to include the response of DF auxiliary basis when computing # nuclear gradients of J/K matrices diff --git a/pyscf/grad/casci.py b/pyscf/grad/casci.py index 715694e3c3..1d46856e69 100644 --- a/pyscf/grad/casci.py +++ b/pyscf/grad/casci.py @@ -256,6 +256,9 @@ def __call__(self, mol_or_geom, state=None, **kwargs): class Gradients(rhf_grad.GradientsBase): '''Non-relativistic restricted Hartree-Fock gradients''' + + _keys = {'state'} + def __init__(self, mc): if isinstance(mc, StateAverageMCSCFSolver): self.state = None # not a specific state diff --git a/pyscf/grad/lagrange.py b/pyscf/grad/lagrange.py index 4b31ed9bc7..3ce7f6c003 100644 --- a/pyscf/grad/lagrange.py +++ b/pyscf/grad/lagrange.py @@ -65,6 +65,10 @@ def get_LdotJnuc (self, Lvec, **kwargs): ####################### Child classes SHOULD overwrite the methods below ###################### + _keys = { + 'Lvec', 'nlag', 'level_shift', 'conv_atol', 'conv_rtol', 'max_cycle', + } + def __init__(self, method, nlag): self._conv = False self.Lvec = None diff --git a/pyscf/grad/rhf.py b/pyscf/grad/rhf.py index 708a23ae21..4c4bc46822 100644 --- a/pyscf/grad/rhf.py +++ b/pyscf/grad/rhf.py @@ -279,7 +279,7 @@ class GradientsBase(lib.StreamObject): Basic nuclear gradient functions for non-relativistic methods ''' - _keys = set(('mol', 'base', 'unit', 'atmlst', 'de')) + _keys = {'mol', 'base', 'unit', 'atmlst', 'de'} def __init__(self, method): self.verbose = method.verbose diff --git a/pyscf/grad/sacasscf.py b/pyscf/grad/sacasscf.py index 190fddbb83..fd5304049f 100644 --- a/pyscf/grad/sacasscf.py +++ b/pyscf/grad/sacasscf.py @@ -401,6 +401,13 @@ def converged(self, x): class Gradients (lagrange.Gradients): + _keys = { + 'ngorb', 'nroots', 'spin_states', 'na_states', 'nb_states', 'nroots', + 'nci', 'state', 'eris', 'weights', 'e_states', 'max_cycle', 'ncas', + 'e_cas', 'nelecas', 'mo_occ', 'mo_energy', 'mo_coeff', 'callback', + 'chkfile', 'nlag', 'frozen', 'level_shift', 'extrasym', 'fcisolver', + } + def __init__(self, mc, state=None): self.__dict__.update (mc.__dict__) nmo = mc.mo_coeff.shape[-1] @@ -499,14 +506,12 @@ def make_fcasscf (self, state=None, casscf_attr={}, fcisolver_attr={}): else: solver_class = self.base.fcisolver._base_class solver_obj = self.base.fcisolver - fcasscf.fcisolver = solver_class (self.base.mol) - fcasscf.fcisolver.__dict__.update (solver_obj.__dict__) + fcasscf.fcisolver = solver_obj.view(solver_class) fcasscf.fcisolver.nroots = 1 # Spin penalty method is inapplicable to response calc'ns # It must be deactivated for Lagrange multipliers to converge if isinstance (fcasscf.fcisolver, SpinPenaltyFCISolver): - fcasscf.fcisolver = fcasscf.fcisolver.copy() - fcasscf.fcisolver.ss_penalty = 0 + fcasscf.fcisolver = fcasscf.fcisolver.undo_fix_spin() fcasscf.__dict__.update (casscf_attr) fcasscf.nelecas = nelecas fcasscf.fcisolver.__dict__.update (fcisolver_attr) @@ -777,6 +782,11 @@ class SACASLagPrec (lagrange.LagPrec): Make the operand's matrix element with