Skip to content

Commit

Permalink
LASSI chkfile (needs unittests)
Browse files Browse the repository at this point in the history
  • Loading branch information
MatthewRHermes committed Oct 6, 2023
1 parent fea3c9c commit aba0c43
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 8 deletions.
2 changes: 2 additions & 0 deletions my_pyscf/lassi/excitations.py
Original file line number Diff line number Diff line change
Expand Up @@ -589,6 +589,7 @@ def kernel (self, h1e, h2e, norb, nelec, ecore=0, ci0=None, orbsym=None, **kwarg
ci1 = ci0
self.denom_q = e0 - self.e_q
log.debug ("Self-energy singularities in VRVSolver: {}".format (self.e_q))
log.debug ("Denominators in VRVSolver: {}".format (self.denom_q))
self.test_locmin (e0, ci1, warntag='Saddle-point initial guess')
warn_swap = False # annoying loud warning not necessary
#print (lib.fp (ci0), self.denom_q)
Expand All @@ -607,6 +608,7 @@ def kernel (self, h1e, h2e, norb, nelec, ecore=0, ci0=None, orbsym=None, **kwarg
ket, e0 = ci1, e
e0 = self.solve_e0 (ecore, h1e, h2e, norb, nelec, ket)
self.denom_q = e0 - self.e_q
log.debug ("Denominators in VRVSolver: {}".format (self.denom_q))
#hket = self.contract_2e (self.absorb_h1e (h1e, h2e, norb, nelec, 0.5), ket, norb, nelec)
#brahket = np.dot (ket.ravel (), hket.ravel ())
#e0_test = ecore + brahket
Expand Down
28 changes: 20 additions & 8 deletions my_pyscf/mcscf/chkfile.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,18 @@
from pyscf.lib.chkfile import load
from pyscf.lib.chkfile import load_mol, save_mol

keys_config = ['ncas', 'nelecas', 'ncore', 'ncas_sub', 'nelecas_sub']
keys_saconstr = ['weights', 'charges', 'spins', 'smults', 'wfnsyms']
keys_results = ['e_states', 'states_converged', 'e_tot', 'mo_coeff']
KEYS_CONFIG_LASSCF = ['ncas', 'nelecas', 'ncore', 'ncas_sub', 'nelecas_sub']
KEYS_SACONSTR_LASSCF = ['weights', 'charges', 'spins', 'smults', 'wfnsyms']
KEYS_RESULTS_LASSCF = ['e_states', 'states_converged', 'e_tot', 'mo_coeff']

def load_las_(mc, chkfile=None):
def load_las_(mc, chkfile=None, method_key='las',
keys_config=KEYS_CONFIG_LASSCF,
keys_saconstr=KEYS_SACONSTR_LASSCF,
keys_results=KEYS_RESULTS_LASSCF):
if chkfile is None: chkfile = mc.chkfile
if chkfile is None: raise RuntimeError ('chkfile not specified')
data = load (chkfile, 'las')
if data is None: raise KeyError ('LAS record not in chkfile')
data = load (chkfile, method_key)
if data is None: raise KeyError ('{} record not in chkfile'.format (method_key.upper()))

# conditionals for backwards compatibility with older chkfiles that
# only stored mo_coeff and ci
Expand All @@ -20,7 +23,13 @@ def load_las_(mc, chkfile=None):
# this needs to happen before some of the results attributes
if all ([key in data for key in keys_saconstr]):
sakwargs = {key: data[key] for key in keys_saconstr}
mc.state_average_(**sakwargs)
try:
mc.state_average_(**sakwargs)
except AttributeError as err:
las = mc._las.state_average (**sakwargs)
mc.fciboxes = las.fciboxes
mc.nroots=las.nroots
mc.weights=las.weights
for key in keys_results:
if key in data:
setattr (mc, key, data[key])
Expand All @@ -47,7 +56,10 @@ def load_las_(mc, chkfile=None):
return mc

def dump_las (mc, chkfile=None, method_key='las', mo_coeff=None, ci=None,
overwrite_mol=True, **kwargs):
overwrite_mol=True, keys_config=KEYS_CONFIG_LASSCF,
keys_saconstr=KEYS_SACONSTR_LASSCF,
keys_results=KEYS_RESULTS_LASSCF,
**kwargs):
if chkfile is None: chkfile = mc.chkfile
if not chkfile: return mc
if mo_coeff is None: mo_coeff = mc.mo_coeff
Expand Down
1 change: 1 addition & 0 deletions my_pyscf/mcscf/productstate.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ def kernel (self, h1, h2, norb_f, nelec_f, ecore=0, ci0=None, orbsym=None,
grad_max = np.amax (np.abs (grad))
log.info ('Cycle %d: max grad = %e ; sigma = %e', it, grad_max,
e_sigma)
log.debug ('e vector = {}'.format (e))
solvers_converged = [np.all (np.asarray (s.converged)) for s in self.fcisolvers]
if ((grad_max < conv_tol_grad) and (e_sigma < conv_tol_self)
and all ([solvers_converged])):
Expand Down

0 comments on commit aba0c43

Please sign in to comment.