Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
75 changes: 30 additions & 45 deletions src/quemb/molbe/mbe.py
Original file line number Diff line number Diff line change
Expand Up @@ -1353,6 +1353,28 @@ def read_heff(self, heff_file="bepotfile.h5"):
for fobj in self.Fobjs:
fobj.heff = filepot.get(fobj.dname)

def _get_noncore_W(self, W, P_core, pop_thr=0.7):
"""Construct an orthonormal working basis with core orbitals removed."""

# Project out columns of W with core character
P_noncore = eye(W.shape[0]) - P_core @ self.S
C = P_noncore @ W

# Decide which columns of W to retain
# NOTE: PYSCF has basis in 1s2s3s2p2p2p3p3p3p format
# fix no_core_idx - use population for now
Cpop = multi_dot((C.T, self.S, C))
no_core_idx = where(diag(Cpop) > pop_thr)[0]
C = C[:, no_core_idx]

# Perform symmetric (Lowdin) othogonalization
S_ = multi_dot((C.T, self.S, C))
es_, vs_ = eigh(S_)
s_ = diag(1.0 / sqrt(es_))
W_ = multi_dot((vs_, s_, vs_.T))

return C @ W_

def localize(
self,
lo_method: LocMethods,
Expand Down Expand Up @@ -1399,48 +1421,22 @@ def localize(
self.W = vs_[:, edx] / sqrt(es_[edx]) @ vs_[:, edx].T
if self.frozen_core:
if self.unrestricted:
P_core = [
eye(self.W.shape[0]) - (self.P_core[s] @ self.S) for s in [0, 1]
]
C_ = P_core @ self.W
unr_Cpop = [multi_dot((C_[s].T, self.S, C_[s])) for s in [0, 1]]
unr_Cpop = [diag(unr_Cpop[s]) for s in [0, 1]]
unr_no_core_idx = [where(unr_Cpop[s] > 0.7)[0] for s in [0, 1]]
C_ = [C_[s][:, unr_no_core_idx[s]] for s in [0, 1]]
S_ = [multi_dot((C_[s].T, self.S, C_[s])) for s in [0, 1]]
unr_W_ = []
for s in [0, 1]:
es_, vs_ = eigh(S_[s])
s_ = sqrt(es_)
s_ = diag(1.0 / s_)
unr_W_.append(multi_dot((vs_, s_, vs_.T)))
self.W = [C_[s] @ unr_W_[s] for s in [0, 1]]
self.W_a = self._get_noncore_W(self.W, self.P_core[0], pop_thr=0.7)
self.W_b = self._get_noncore_W(self.W, self.P_core[1], pop_thr=0.7)
else:
P_core = eye(self.W.shape[0]) - self.P_core @ self.S
C_ = P_core @ self.W
# NOTE: PYSCF has basis in 1s2s3s2p2p2p3p3p3p format
# fix no_core_idx - use population for now
Cpop = multi_dot((C_.T, self.S, C_))
no_core_idx = where(diag(Cpop) > 0.7)[0]
C_ = C_[:, no_core_idx]
S_ = multi_dot((C_.T, self.S, C_)) # type: ignore[assignment]
es_, vs_ = eigh(S_)
s_ = sqrt(es_)
s_ = diag(1.0 / s_)
W_ = multi_dot((vs_, s_, vs_.T))
self.W = C_ @ W_
self.W = self._get_noncore_W(self.W, self.P_core, pop_thr=0.7)

if self.unrestricted:
if self.frozen_core:
self.lmo_coeff_a = multi_dot(
(self.W[0].T, self.S, self.C_a[:, self.ncore :]) # type: ignore[attr-defined]
(self.W_a.T, self.S, self.C_a[:, self.ncore :]) # type: ignore[attr-defined]
)
self.lmo_coeff_b = multi_dot(
(self.W[1].T, self.S, self.C_b[:, self.ncore :]) # type: ignore[attr-defined]
(self.W_b.T, self.S, self.C_b[:, self.ncore :]) # type: ignore[attr-defined]
)
else:
self.lmo_coeff_a = multi_dot((self.W.T, self.S, self.C_a)) # type: ignore[attr-defined]
self.lmo_coeff_b = multi_dot((self.W.T, self.S, self.C_b)) # type: ignore[attr-defined]
self.lmo_coeff_a = multi_dot((self.W_unr.T, self.S, self.C_a)) # type: ignore[attr-defined]
self.lmo_coeff_b = multi_dot((self.W_unr.T, self.S, self.C_b)) # type: ignore[attr-defined]
else:
if self.frozen_core:
self.lmo_coeff = multi_dot(
Expand All @@ -1454,18 +1450,7 @@ def localize(
edx = es_ > 1.0e-15
W_ = vs_[:, edx] / sqrt(es_[edx]) @ vs_[:, edx].T
if self.frozen_core:
P_core = eye(W_.shape[0]) - self.P_core @ self.S
C_ = P_core @ W_
Cpop = multi_dot((C_.T, self.S, C_))
Cpop = diag(Cpop)
no_core_idx = where(Cpop > 0.55)[0]
C_ = C_[:, no_core_idx]
S_ = multi_dot((C_.T, self.S, C_)) # type: ignore[assignment]
es_, vs_ = eigh(S_)
s_ = sqrt(es_)
s_ = diag(1.0 / s_)
W_ = multi_dot((vs_, s_, vs_.T))
W_ = C_ @ W_
W_ = self._get_noncore_W(W_, self.P_core, pop_thr=0.55)

self.W = get_loc(
self.mf.mol,
Expand Down
Loading