Skip to content

Commit

Permalink
Guardrail against combine_pair misuse
Browse files Browse the repository at this point in the history
Raise an exception if trying to combine two keyframes that are
responsible for the same fragment
  • Loading branch information
MatthewRHermes committed Jul 18, 2024
1 parent 25b117d commit 71cb238
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
4 changes: 4 additions & 0 deletions my_pyscf/mcscf/lasscf_async/combine.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,6 +208,10 @@ def combine_pair (las, kf1, kf2, kf_ref=None):
'''Combine two keyframes and relax one specific block of active-active orbital rotations
between the fragments assigned to each with the inactive and virtual orbitals frozen.'''
if kf_ref is None: kf_ref=kf1
if len (kf1.frags.intersection (kf2.frags)):
errstr = ("Cannot combine keyframes that are responsible for the same fragments "
"({} {})").format (kf1.frags, kf2.frags)
raise RuntimeError (errstr)
kf3 = orth_orb (las, [kf1, kf2], kf_ref=kf_ref)
i, j = select_aa_block (las, kf1.frags, kf2.frags, kf3.fock1)
kf3 = relax (las, kf3, freeze_inactive=True, unfrozen_frags=(i,j))
Expand Down
19 changes: 19 additions & 0 deletions my_pyscf/mcscf/lasscf_async/keyframe.py
Original file line number Diff line number Diff line change
Expand Up @@ -349,5 +349,24 @@ def democratic_matrix (las, mat, frags, mo_coeff):

return u @ mat @ u.conj ().T

# Thought I might need this; realize I don't. Might still be useful later.
def fock_cycle (las, kf1):
'''For the inactive-virtual orbital rotations only, build and diagonalize the fock
matrix once'''
nao, nmo = kf1.mo_coeff.shape
ncore, ncas = las.ncore, las.ncas
nocc = ncore + ncas
nvirt = nmo - nocc
mo = np.append (kf1.mo_coeff[:,:ncore], kf1.mo_coeff[:,nocc:])
if not mo.shape[1]: return kf1
kf2 = kf1.copy ()
fock = las.get_hcore ()[None,:,:] + kf1.veff
fock = get_roothaan_fock (fock, kf1.dm1s, las._scf.get_ovlp())
orbsym = None # TODO: symmetry
fock = mo.conj ().T @ fock @ mo
ene, umat = las._eig (fock, 0, 0, orbsym)
if ncore: kf2.mo_coeff[:,:ncore] = mo @ umat[:,:ncore]
if nvirt: kf2.mo_coeff[:,nocc:] = mo @ umat[:,ncore:]
return kf2


0 comments on commit 71cb238

Please sign in to comment.