Skip to content

Commit

Permalink
Made constrCASSCF optional
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Hermes committed Jun 11, 2018
1 parent d8e2c5f commit 46fb1cf
Show file tree
Hide file tree
Showing 4 changed files with 13 additions and 12 deletions.
1 change: 0 additions & 1 deletion my_dmet/fragments.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,6 @@ def do_Schmidt_ofc_embedding (self, oneRDM_loc, all_frags):
# Reorder impurity orbitals so that fragments are at the top, as much as possible
proj = np.dot (loc2imp[self.frag_orb_list,:].conjugate ().T, loc2imp[self.frag_orb_list,:])
evals, u_imp = matrix_eigen_control_options (proj, sort_vecs=-1, only_nonzero_vals=False)
assert (np.logical_and (np.allclose (evals[:self.norbs_frag], 1), np.allclose (evals[self.norbs_frag:], 0))), evals
loc2imp = np.dot (loc2imp, u_imp)
self.loc2emb = get_complete_basis (loc2imp)

Expand Down
6 changes: 4 additions & 2 deletions my_dmet/main_object.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ class dmet:

def __init__( self, theInts, fragments, isTranslationInvariant=False, SCmethod='BFGS', incl_bath_errvec=True, use_constrained_opt=False,
doDET=False, doDET_NO=False, CC_E_TYPE='LAMBDA', minFunc='FOCK_INIT', wma_options=False, print_u=True,
print_rdm=True, ofc_embedding=False, debug_energy=False, noselfconsistent=False):
print_rdm=True, ofc_embedding=False, debug_energy=False, noselfconsistent=False, do_constrCASSCF=False):

if isTranslationInvariant:
raise RuntimeError ("The translational invariance option doesn't work! It needs to be completely rebuilt!")
Expand Down Expand Up @@ -63,6 +63,7 @@ def __init__( self, theInts, fragments, isTranslationInvariant=False, SCmethod='
self.ofc_embedding = ofc_embedding
self.debug_energy = debug_energy
self.noselfconsistent = noselfconsistent
self.do_constrCASSCF = do_constrCASSCF
if self.noselfconsistent:
SCmethod = 'NONE'
for frag in self.fragments:
Expand Down Expand Up @@ -520,7 +521,8 @@ def doselfconsistent_orbs (self, iters):
else:
self.mu_imp = optimize.newton( self.numeleccostfunction, self.mu_imp, tol=1e-6 )
print (" Chemical potential =", self.mu_imp)
self.doexact (self.mu_imp, frag_constrained_casscf=True)
if self.do_constrCASSCF:
self.doexact (self.mu_imp, frag_constrained_casscf=True)

loc2wmas_new = np.concatenate ([frag.loc2amo for frag in self.fragments], axis=1)
try:
Expand Down
4 changes: 2 additions & 2 deletions my_drudge/PartActvHoleDrudge.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,8 @@ def _subst_actv_vec_rdm (term: Term, rdm: IndexedBase, actv_range, op_parser, re
actv_parsed = [p for r, p in zip (ranges, parsed) if r==actv_range]
amp = term.amp
if len (actv_parsed) > 0:
actv_cr_idxs = sum([list(p[2]) for p in actv_parsed if p[1]==CR], [])
actv_an_idxs = sum([list(p[2]) for p in reversed (actv_parsed) if p[1]==AN], [])
actv_cr_idxs = sum([[p[2][0]] for p in actv_parsed if p[1]==CR], [])
actv_an_idxs = sum([[p[2][0]] for p in reversed (actv_parsed) if p[1]==AN], [])
actv_idxs = actv_cr_idxs + actv_an_idxs
amp = amp * rdm[actv_idxs]
return Term (term.sums, amp, inac_vecs)
Expand Down
14 changes: 7 additions & 7 deletions my_pyscf/mcscf/mc1step_constrained.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,13 +300,13 @@ def uniq_var_indices (self):
mask[ncas:ncasrot,:ncas] = True
# Can I add others to get occ-vir rotation without spoiling it?
# Yes I can, but this ~slows it down~ somehow! (At least it doesn't break it, but I'm not sure it's doing anything?)
idx_unocc1 = np.isclose (self._crocc, 0)
idx_occ1 = ~idx_unocc1
idx_occ2, idx_unocc2 = np.copy (idx_occ1), np.copy (idx_unocc1)
idx_occ1[ncasrot:] = idx_unocc1[ncasrot:] = False
idx_occ2[:ncasrot] = idx_unocc2[:ncasrot] = False
mask[np.ix_(idx_occ1,idx_unocc1)] = True
mask[np.ix_(idx_occ2,idx_unocc2)] = True
#idx_unocc1 = np.isclose (self._crocc, 0)
#idx_occ1 = ~idx_unocc1
#idx_occ2, idx_unocc2 = np.copy (idx_occ1), np.copy (idx_unocc1)
#idx_occ1[ncasrot:] = idx_unocc1[ncasrot:] = False
#idx_occ2[:ncasrot] = idx_unocc2[:ncasrot] = False
#mask[np.ix_(idx_occ1,idx_unocc1)] = True
#mask[np.ix_(idx_occ2,idx_unocc2)] = True
return mask

def pack_uniq_var (self, rot):
Expand Down

0 comments on commit 46fb1cf

Please sign in to comment.