From 81a77155b2bfdc14af38405851758eb9152caca3 Mon Sep 17 00:00:00 2001 From: George Booth Date: Thu, 3 Nov 2022 22:17:52 +0000 Subject: [PATCH 01/66] Added to_cisdtq functionality to RFCI wave function types for extraction of C1 -> C4 info --- vayesta/core/types/wf/cisdtq.py | 5 +- vayesta/core/types/wf/fci.py | 217 +++++++++++++++++++++++++++++--- vayesta/core/util.py | 30 ++++- 3 files changed, 229 insertions(+), 23 deletions(-) diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 362caec6d..e157d6882 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -14,13 +14,14 @@ def CISDTQ_WaveFunction(mo, *args, **kwargs): class RCISDTQ_WaveFunction(wf_types.WaveFunction): - def __init__(self, mo, c0, c1, c2, c3, c4): + def __init__(self, mo, c0, c1, c2, c3, c4_abab, c4_abaa): super().__init__(mo) self.c0 = c0 self.c1 = c1 self.c2 = c2 self.c3 = c3 - self.c4 = c4 + self.c4_abab = c4_abab + self.c4_abaa = c4_abaa def as_ccsdtq(self): t1 = self.c1/self.c0 diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 445356401..6d8f00366 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -5,7 +5,6 @@ from vayesta.core.util import * from vayesta.core.types import wf as wf_types - def FCI_WaveFunction(mo, ci, **kwargs): if mo.nspin == 1: cls = RFCI_WaveFunction @@ -85,25 +84,202 @@ def as_cisdtq(self, c0=None): if self.projector is not None: raise NotImplementedError norb, nocc, nvir = self.norb, self.nocc, self.nvir - t1addr, t1sign = pyscf.ci.cisd.t1strs(norb, nocc) + # For packed 2D arrays + ij_pairs = int(nocc * (nocc - 1) / 2) + ab_pairs = int(nvir * (nvir - 1) / 2) + ooidx = np.tril_indices(nocc, -1) # second index lower than first + vvidx = np.tril_indices(nvir, -1) # second index lower than first + # For packed 3D arrays + oooidx = tril_indices_ndim(nocc, 3) # i > j > k + vvvidx = tril_indices_ndim(nvir, 3) # a > b > c + ijk_pairs = int(nocc * (nocc - 1) * (nocc - 2) / 6) + abc_pairs = int(nvir * (nvir - 1) * (nvir - 2) / 6) + + # === C1 amplitudes === + # These functions extract out the indicies and signs of + # the *same spin* excitations of a given rank from the FCI vector + t1addr, t1sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 1) + # C1 are taken to be the beta -> beta excitations (which should be + # the same as alpha -> alpha), by taking the first (alpha) index to be doubly occupied. + c1 = self.ci[0,t1addr] * t1sign + c1 = c1.reshape((nocc, nvir)) + + # Longhand check (to be put into a test) + c1_ = np.zeros(t1addr.shape[0]) + c1_full = np.zeros_like(c1) + for s_cnt, sing_ind in enumerate(t1addr): + c1_[s_cnt] = self.ci[0, sing_ind] * t1sign[s_cnt] + i = int(s_cnt / nvir) + a = s_cnt % nvir + c1_full[i,a] = c1_[s_cnt] + assert(np.allclose(c1, c1_full)) + + # === C2 amplitudes === + # For RHF, we want the (alpha, beta) -> (alpha, beta) excitation amplitudes. + # Therefore, we can just take single excitations of alpha and + # combine with the single excitations of beta. + c2 = np.einsum('i,j,ij->ij', t1sign, t1sign, self.ci[t1addr[:,None],t1addr]) + # Reorder occupied indices to the front + c2 = c2.reshape((nocc, nvir, nocc, nvir)).transpose(0,2,1,3) + + # === C3 amplitudes === + # For the C3 amplitudes, we want to find the ijk -> abc amplitudes of + # spin signature (alpha, beta, alpha) -> (alpha, beta, alpha) + + # t2addr, t2sign is the index and sign of the packed (alpha, alpha) -> (alpha, alpha) + # excitations in the FCI array. To get the orbital indices that they correspond to, + # use ooidx and vvidx t2addr, t2sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 2) + assert(t2addr.shape[0] == ij_pairs * ab_pairs) + + # First find the ijk -> abc excitations, where ijab are alpha, and kc are beta + c3_comp = np.zeros((ij_pairs * ab_pairs, nocc * nvir)) + c3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir)) + for d_cnt, doub_ind in enumerate(t2addr): + ij = int(d_cnt / ab_pairs) + ab = d_cnt % ab_pairs + i, j = ooidx[0][ij], ooidx[1][ij] # j ind < i ind + a, b = vvidx[0][ab], vvidx[1][ab] # b ind < a ind + for s_cnt, sing_ind in enumerate(t1addr): + # First index of c3_comp is a compound index of ijab (alpha, alpha) excitations, + # with the second index being the kc (beta, beta) single excitation. + c3_comp[d_cnt, s_cnt] = self.ci[doub_ind, sing_ind] * t2sign[d_cnt] * t1sign[s_cnt] + + k = int(s_cnt / nvir) + c = s_cnt % nvir + # Note, we want aba -> aba spin signature, not aab -> aab, which is what we have. + # We can therefore swap (jk) and (bc). This does not cause an overall sign change. + # We then also want to fill up the contributions between permutations + # amongst the alpha electrons and alpha holes. + # If only one is permuted, then this will indeed cause a sign change. + assert(i != j) + assert(a != b) + c3[i,k,j,a,c,b] = c3_comp[d_cnt, s_cnt] + c3[j,k,i,a,c,b] = -c3_comp[d_cnt, s_cnt] + c3[i,k,j,b,c,a] = -c3_comp[d_cnt, s_cnt] + c3[j,k,i,b,c,a] = c3_comp[d_cnt, s_cnt] + assert(np.allclose(c3_comp, np.einsum('i,j,ij->ij', \ + t2sign, t1sign, self.ci[t2addr[:,None], t1addr]))) + del c3_comp + + # === C4 amplitudes === + # For the C4 amplitudes, ijkl -> abcd, we are going to store two different spin + # signatures: + # (alpha, beta, alpha, beta) -> (alpha, beta, alpha, beta) and + # (alpha, beta, alpha, alpha) -> (alpha, beta, alpha, alpha) + # TODO: Can we store the information as a single combined spatial orbital representation? + + # Start with abab. We will first get this as aabb -> aabb, via a product of + # alpha-alpha double excitations and beta-beta double excitations and then reorder. + c4_abab = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir)) + c4_comp = np.zeros((ij_pairs * ab_pairs, ij_pairs * ab_pairs)) + for d_cnt_a, doub_ind_a in enumerate(t2addr): + ij_alpha = int(d_cnt_a / ab_pairs) + ab_alpha = d_cnt_a % ab_pairs + i, j = ooidx[0][ij_alpha], ooidx[1][ij_alpha] + a, b = vvidx[0][ab_alpha], vvidx[1][ab_alpha] + for d_cnt_b, doub_ind_b in enumerate(t2addr): + ij_beta = int(d_cnt_b / ab_pairs) + ab_beta = d_cnt_b % ab_pairs + I, J = ooidx[0][ij_beta], ooidx[1][ij_beta] + A, B = vvidx[0][ab_beta], vvidx[1][ab_beta] + + # Swap aabb -> abab spin signature. No sign change required. + c4_comp[d_cnt_a, d_cnt_b] = self.ci[doub_ind_a, doub_ind_b] \ + * t2sign[d_cnt_a] * t2sign[d_cnt_b] + # Consider all possible (antisymmetric) permutations of (i_alpha, j_alpha), + # (i_beta, j_beta), (a_alpha, b_alpha), (a_beta, b_beta). 16 options. + c4_abab[i, I, j, J, a, A, b, B] = c4_comp[d_cnt_a, d_cnt_b] + c4_abab[i, I, j, J, a, B, b, A] = -c4_comp[d_cnt_a, d_cnt_b] + c4_abab[i, I, j, J, b, A, a, B] = -c4_comp[d_cnt_a, d_cnt_b] + c4_abab[i, I, j, J, b, B, a, A] = c4_comp[d_cnt_a, d_cnt_b] + c4_abab[i, J, j, I, a, A, b, B] = -c4_comp[d_cnt_a, d_cnt_b] + c4_abab[i, J, j, I, a, B, b, A] = c4_comp[d_cnt_a, d_cnt_b] + c4_abab[i, J, j, I, b, A, a, B] = c4_comp[d_cnt_a, d_cnt_b] + c4_abab[i, J, j, I, b, B, a, A] = -c4_comp[d_cnt_a, d_cnt_b] + c4_abab[j, I, i, J, a, A, b, B] = -c4_comp[d_cnt_a, d_cnt_b] + c4_abab[j, I, i, J, a, B, b, A] = c4_comp[d_cnt_a, d_cnt_b] + c4_abab[j, I, i, J, b, A, a, B] = c4_comp[d_cnt_a, d_cnt_b] + c4_abab[j, I, i, J, b, B, a, A] = -c4_comp[d_cnt_a, d_cnt_b] + c4_abab[j, J, i, I, a, A, b, B] = c4_comp[d_cnt_a, d_cnt_b] + c4_abab[j, J, i, I, a, B, b, A] = -c4_comp[d_cnt_a, d_cnt_b] + c4_abab[j, J, i, I, b, A, a, B] = -c4_comp[d_cnt_a, d_cnt_b] + c4_abab[j, J, i, I, b, B, a, A] = c4_comp[d_cnt_a, d_cnt_b] + assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t2sign, t2sign, \ + self.ci[t2addr[:,None], t2addr]))) + del c4_comp + + # abaa spin signature. Get this from the aaab->aaab excitations. + # This requires the index of the (alpha, alpha, alpha) -> (alpha, alpha, alpha) excits. t3addr, t3sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 3) - t4addr, t4sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 4) - # C1 & C2 (from CISD code) - c1 = self.ci[0,t1addr] * t1sign - c2 = einsum('i,j,ij->ij', t1sign, t1sign, self.ci[t1addr[:,None],t1addr]) - # C3 & C4 (TODO) - # Check also UCISD code to understand what is going on? - # (for example, t2addr are not needed for RCISD, but are in UCISD) - raise NotImplementedError - #c3 = ... - #c4 = ... - # Sort occupied indices to the front: - nov = (nocc, nvir) - c1 = c1.reshape(nov) - c2 = c2.reshape(2*nov).transpose(0,2,1,3) - c3 = c3.reshape(3*nov).transpose(0,2,4,1,3,5) - c4 = c4.reshape(4*nov).transpose(0,2,4,6,1,3,5,7) + assert(t3addr.shape[0] == ijk_pairs * abc_pairs) + + c4_abaa = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir)) + c4_comp = np.zeros((ijk_pairs * abc_pairs, nocc * nvir)) + for t_cnt_a, trip_ind_a in enumerate(t3addr): + # Find alpha i,j,k -> a,b,c indices + ijk_alpha = int(t_cnt_a / abc_pairs) + abc_alpha = t_cnt_a % abc_pairs + i, j, k = oooidx[0][ijk_alpha], oooidx[1][ijk_alpha], oooidx[2][ijk_alpha] + a, b, c = vvvidx[0][abc_alpha], vvvidx[1][abc_alpha], vvvidx[2][abc_alpha] + for s_cnt_b, sing_ind_b in enumerate(t1addr): + c4_comp[t_cnt_a, s_cnt_b] = self.ci[trip_ind_a, sing_ind_b] * \ + t3sign[t_cnt_a] * t1sign[s_cnt_b] + + # Beta singles values + I = int(s_cnt / nvir) + A = s_cnt % nvir + + # Swap aaab -> abaa spin signature. No sign change required. + c4_abaa[i, I, j, k, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] + # All antisym permutations of (ijk) x (abc) amongst alpha orbitals. + # Six permutations each, making 36 overall + # just rearrange occupied + c4_abaa[i, I, j, k, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[i, I, k, j, a, A, b, c] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, j, i, a, A, b, c] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, i, k, a, A, b, c] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, k, i, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, i, j, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] + # swap ac + c4_abaa[i, I, j, k, c, A, b, a] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[i, I, k, j, c, A, b, a] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, j, i, c, A, b, a] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, i, k, c, A, b, a] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, k, i, c, A, b, a] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, i, j, c, A, b, a] = -c4_comp[t_cnt_a, s_cnt_b] + # swap ab + c4_abaa[i, I, j, k, b, A, a, c] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[i, I, k, j, b, A, a, c] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, j, i, b, A, a, c] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, i, k, b, A, a, c] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, k, i, b, A, a, c] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, i, j, b, A, a, c] = -c4_comp[t_cnt_a, s_cnt_b] + # swap bc + c4_abaa[i, I, j, k, a, A, c, b] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[i, I, k, j, a, A, c, b] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, j, i, a, A, c, b] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, i, k, a, A, c, b] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, k, i, a, A, c, b] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, i, j, a, A, c, b] = -c4_comp[t_cnt_a, s_cnt_b] + # swap abc -> cab + c4_abaa[i, I, j, k, c, A, a, b] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[i, I, k, j, c, A, a, b] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, j, i, c, A, a, b] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, i, k, c, A, a, b] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, k, i, c, A, a, b] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, i, j, c, A, a, b] = c4_comp[t_cnt_a, s_cnt_b] + # swap abc -> bca + c4_abaa[i, I, j, k, b, A, c, a] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[i, I, k, j, b, A, c, a] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, j, i, b, A, c, a] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, i, k, b, A, c, a] = -c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[j, I, k, i, b, A, c, a] = c4_comp[t_cnt_a, s_cnt_b] + c4_abaa[k, I, i, j, b, A, c, a] = c4_comp[t_cnt_a, s_cnt_b] + + assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t3sign, t1sign, \ + self.ci[t3addr[:,None], t1addr]))) + del c4_comp if c0 is None: c0 = self.c0 @@ -111,8 +287,9 @@ def as_cisdtq(self, c0=None): c1 *= c0/self.c0 c2 *= c0/self.c0 c3 *= c0/self.c0 - c4 *= c0/self.c0 - return wf_types.RCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4) + c4_abab *= c0/self.c0 + c4_abaa *= c0/self.c0 + return wf_types.RCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4_abab, c4_abaa) def as_ccsd(self): return self.as_cisd().as_ccsd() diff --git a/vayesta/core/util.py b/vayesta/core/util.py index a706e339d..dab9600c9 100644 --- a/vayesta/core/util.py +++ b/vayesta/core/util.py @@ -28,7 +28,7 @@ # General 'Object', 'OptionsBase', 'brange', 'deprecated', 'cache', 'call_once', 'with_doc', # NumPy replacements - 'dot', 'einsum', 'hstack', + 'dot', 'tril_indices_ndim', 'einsum', 'hstack', # Exceptions 'AbstractMethodError', 'ConvergenceError', 'OrthonormalityError', 'ImaginaryPartError', 'NotCalculatedError', @@ -107,6 +107,34 @@ def func_with_doc(func): # --- NumPy +def tril_indices_ndim(n, dims, include_diagonal=False): + """Return lower triangular indices for a multidimensional array.""" + + ranges = [np.arange(n)] * dims + + if dims == 0: + return tuple() + elif dims == 1: + return (ranges[0],) + + if include_diagonal: + func = np.greater_equal + else: + func = np.greater + + slices = [ + tuple(slice(None) if i == j else np.newaxis for i in range(dims)) for j in range(dims) + ] + + casted = [rng[ind] for rng, ind in zip(ranges, slices)] + mask = functools.reduce(np.logical_and, [func(a, b) for a, b in zip(casted[:-1], casted[1:])]) + + tril = tuple( + np.broadcast_to(inds, mask.shape)[mask] for inds in np.indices(mask.shape, sparse=True) + ) + + return tril + def dot(*args, out=None, ignore_none=False): """Like NumPy's multi_dot, but variadic""" if ignore_none: From 5080b65970f97c6728ad0f1fb49eacc9f9596aef Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 4 Nov 2022 10:33:50 +0000 Subject: [PATCH 02/66] Added cisdtq -> ccsdtq functionality for restricted wave functions --- vayesta/core/types/wf/ccsdtq.py | 5 +- vayesta/core/types/wf/cisdtq.py | 166 +++++++++++++++++++++++++++++++- 2 files changed, 164 insertions(+), 7 deletions(-) diff --git a/vayesta/core/types/wf/ccsdtq.py b/vayesta/core/types/wf/ccsdtq.py index 503b8d7f6..7b552cd47 100644 --- a/vayesta/core/types/wf/ccsdtq.py +++ b/vayesta/core/types/wf/ccsdtq.py @@ -14,12 +14,13 @@ def CCSDTQ_WaveFunction(mo, *args, **kwargs): class RCCSDTQ_WaveFunction(wf_types.WaveFunction): - def __init__(self, mo, t1, t2, t3, t4): + def __init__(self, mo, t1, t2, t3, t4_abab, t4_abaa): super().__init__(mo) self.t1 = t1 self.t2 = t2 self.t3 = t3 - self.t4 = t4 + self.t4_abab = t4_abab + self.t4_abaa = t4_abaa def as_ccsdtq(self): return self diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index e157d6882..160ce02ae 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -26,13 +26,169 @@ def __init__(self, mo, c0, c1, c2, c3, c4_abab, c4_abaa): def as_ccsdtq(self): t1 = self.c1/self.c0 t2 = self.c2/self.c0 - einsum('ia,jb->ijab', t1, t1) - raise NotImplementedError - # TODO: # see also THE JOURNAL OF CHEMICAL PHYSICS 147, 154105 (2017) - t3 = self.c3/self.c0 # - C1*C2 - (C1^3)/3 - t4 = self.c4/self.c0 # - C1*C3 - (C2^2)/2 - C1^2*C2 - (C1^4)/4 - return wf_types.RCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) + # === t3 === + t3 = self.c3/self.c0 + # As a useful intermediate, compute t2_aa from t2 (_ab), which is + # just the antisymmetric permutation. + t2aa = t2 - t2.transpose(1,0,2,3) + + t1t2 = einsum('ia, jkbc -> ijkabc', t1, t2) + t1t1t1 = einsum('ia,jb,kc -> ijkabc', t1, t1, t1) + + t3 -= t1t2 + t3 += t1t2.transpose(0,1,2,5,4,3) + t3 += t1t2.transpose(2,1,0,3,4,5) + t3 -= t1t2.transpose(2,1,0,5,4,3) + t3 -= einsum('jb,ikac -> ijkabc', t1, t2aa) + t3 -= t1t1t1 + t3 += t1t1t1.transpose(0,1,2,5,4,3) + + # === t4_abaa === (Note that we construct both the abaa and abab spin signatures) + # Construct the abaa first + t4_abaa = self.c4_abaa/self.c0 + + # A useful intermediate is the t3_aaa. Construct this from t3 (_aba) mixed spin. + t3_aaa = t3 - t3.transpose(0,2,1,3,4,5) - t3.transpose(1,0,2,3,4,5) + + # (t1 t3) terms + permutations + t1t3a = einsum('ia,kjlcbd -> ijklabcd', t1, t3) + t1t3b = np.einsum('kd,ijlabc -> ijklabcd', t1, t3) + + t4_abaa -= t1t3a + t4_abaa += t1t3b + t4_abaa += t1t3a.transpose(0,1,2,3,6,5,4,7) + t4_abaa -= t1t3a.transpose(0,1,3,2,7,5,6,4) + t4_abaa -= einsum('jb, iklacd -> ijklabcd', t1, t3_aaa) + t4_abaa += t1t3a.transpose(2,1,0,3,4,5,6,7) + t4_abaa -= t1t3a.transpose(2,1,0,3,6,5,4,7) + t4_abaa -= t1t3a.transpose(3,1,2,0,4,5,7,6) + t4_abaa += t1t3b.transpose(0,1,3,2,4,5,7,6) + t4_abaa -= t1t3b.transpose(0,1,3,2,4,5,6,7) + + # (t2 t2) terms + permutations + t2t2a = einsum('ijab, klcd -> ijklabcd', t2, t2aa) + t2t2b = einsum('ljcb, kida -> ijklabcd', t2, t2aa) + + t4_abaa -= t2t2a + t4_abaa += t2t2b + t4_abaa += t2t2a.transpose(0,1,2,3,6,5,4,7) + t4_abaa -= t2t2a.transpose(0,1,3,2,7,5,6,4) + t4_abaa -= t2t2a.transpose(3,1,2,0,7,5,6,4) + t4_abaa -= t2t2a.transpose(3,1,2,0,4,5,7,6) + t4_abaa += t2t2b.transpose(0,1,3,2,4,5,7,6) + t4_abaa -= t2t2a.transpose(2,1,0,3,6,5,4,7) + t4_abaa += t2t2a.transpose(2,1,0,3,4,5,6,7) + + # (t1 t1 t2) terms + permutations + t1t1t2a = einsum('ia, jb, klcd -> ijklabcd', t1, t1, t2aa) + t1t1t2b = einsum('kd, jb, ilac -> ijklabcd', t1, t1, t2aa) + t1t1t2c = einsum('ia, kc, ljdb -> ijklabcd', t1, t1, t2) + t1t1t2d = einsum('ic, ld, kjab -> ijklabcd', t1, t1, t2) + + t4_abaa -= t1t1t2a + t4_abaa += t1t1t2a.transpose(0,1,2,3,6,5,4,7) + t4_abaa -= t1t1t2a.transpose(0,1,3,2,7,5,6,4) + t4_abaa += t1t1t2a.transpose(2,1,0,3,4,5,6,7) + t4_abaa -= t1t1t2a.transpose(2,1,0,3,6,5,4,7) + t4_abaa += t1t1t2b + t4_abaa -= t1t1t2a.transpose(3,1,2,0,4,5,7,6) + t4_abaa += t1t1t2b.transpose(0,1,3,2,4,5,7,6) + t4_abaa -= t1t1t2b.transpose(0,1,3,2,4,5,6,7) + t4_abaa -= t1t1t2c + t4_abaa += t1t1t2c.transpose(0,1,2,3,4,5,7,6) + t4_abaa += t1t1t2c.transpose(0,1,3,2,4,5,6,7) + t4_abaa -= t1t1t2c.transpose(0,1,3,2,4,5,7,6) + t4_abaa += t1t1t2c.transpose(0,1,2,3,6,5,4,7) + t4_abaa -= t1t1t2c.transpose(2,1,0,3,7,5,6,4) + t4_abaa -= t1t1t2c.transpose(0,1,3,2,6,5,4,7) + t4_abaa += t1t1t2d + t4_abaa -= t1t1t2c.transpose(2,1,0,3,4,5,7,6) + t4_abaa += t1t1t2c.transpose(0,1,2,3,7,5,6,4) + t4_abaa += t1t1t2d.transpose(3,1,2,0,6,5,4,7) + t4_abaa -= t1t1t2d.transpose(0,1,2,3,4,5,7,6) + t4_abaa -= t1t1t2c.transpose(3,1,2,0,6,5,4,7) + t4_abaa += t1t1t2d.transpose(2,1,0,3,6,5,4,7) + t4_abaa += t1t1t2c.transpose(3,1,2,0,4,5,6,7) + t4_abaa -= t1t1t2d.transpose(2,1,0,3,4,5,6,7) + t4_abaa -= t1t1t2c.transpose(3,1,2,0,4,5,7,6) + t4_abaa += t1t1t2d.transpose(2,1,0,3,4,5,7,6) + + # (t1 t1 t1 t1) terms + permutations + t1t1t1t1 = einsum('ia, jb, kc, ld -> ijklabcd', t1, t1, t1, t1) + + t4_abaa -= t1t1t1t1 + t4_abaa += t1t1t1t1.transpose(0,1,2,3,4,5,7,6) + t4_abaa += t1t1t1t1.transpose(0,1,2,3,6,5,4,7) + t4_abaa -= t1t1t1t1.transpose(0,1,3,2,6,5,4,7) + t4_abaa -= t1t1t1t1.transpose(0,1,3,2,7,5,6,4) + t4_abaa += t1t1t1t1.transpose(0,1,2,3,7,5,6,4) + + # Now construct t4 with spin signature (abab -> abab) + t4_abab = self.c4_abab/self.c0 + + # (t1 t3) terms + permutations + t1t3a = einsum('ia, jklbcd -> ijklabcd', t1, t3) + t1t3b = einsum('jd, ilkabc -> ijklabcd', t1, t3) + + t4_abab -= t1t3a + t4_abab += t1t3a.transpose(0,1,2,3,6,5,4,7) + t4_abab -= t1t3a.transpose(1,0,3,2,5,4,7,6) + t4_abab += t1t3b + t4_abab += t1t3a.transpose(2,1,0,3,4,5,6,7) + t4_abab -= t1t3a.transpose(2,1,0,3,6,5,4,7) + t4_abab += t1t3b.transpose(0,3,2,1,4,7,6,5) + t4_abab -= t1t3b.transpose(0,3,2,1,4,5,6,7) + + # (t2 t2) terms + permutations + t2t2 = einsum('ijab, klcd -> ijklabcd', t2, t2) + + t4_abab -= t2t2 + t4_abab += t2t2.transpose(0,1,2,3,4,7,6,5) + t4_abab += t2t2.transpose(0,1,2,3,6,5,4,7) + t4_abab -= t2t2.transpose(0,1,2,3,6,7,4,5) + t4_abab += t2t2.transpose(0,3,2,1,4,5,6,7) + t4_abab -= t2t2.transpose(0,3,2,1,6,5,4,7) + t4_abab += t2t2.transpose(0,3,2,1,6,7,4,5) + t4_abab -= einsum('ilad, jkbc -> ijklabcd', t2, t2) + t4_abab -= einsum('ikac, jlbd -> ijklabcd', t2aa, t2aa) + + # (t1 t1 t2) terms + permutations + t1t1t2a = einsum('ia,jb,klcd -> ijklabcd', t1, t1, t2) + t1t1t2b = einsum('jb,ka,ilcd -> ijklabcd', t1, t1, t2) + + t4_abab -= t1t1t2a + t4_abab += t1t1t2a.transpose(0,1,2,3,4,7,6,5) + t4_abab += t1t1t2a.transpose(0,3,2,1,4,5,6,7) + t4_abab += t1t1t2a.transpose(0,1,2,3,6,5,4,7) + t4_abab -= t1t1t2a.transpose(0,1,2,3,6,7,4,5) + t4_abab -= t1t1t2a.transpose(0,3,2,1,6,5,4,7) + t4_abab += t1t1t2a.transpose(0,3,2,1,6,7,4,5) + t4_abab -= t1t1t2a.transpose(2,3,0,1,4,5,6,7) + t4_abab += t1t1t2a.transpose(2,3,0,1,4,7,6,5) + t4_abab += t1t1t2a.transpose(2,3,0,1,6,5,4,7) + t4_abab -= t1t1t2a.transpose(2,3,0,1,6,7,4,5) + t4_abab += t1t1t2b + t4_abab -= t1t1t2b.transpose(0,1,2,3,6,5,4,7) + t4_abab -= t1t1t2b.transpose(0,1,2,3,4,7,6,5) + t4_abab += t1t1t2b.transpose(0,1,2,3,6,7,4,5) + t4_abab -= t1t1t2b.transpose(2,3,0,1,4,7,6,5) + t4_abab -= einsum('ia,kc,jlbd -> ijklabcd', t1, t1, t2aa) + t4_abab += einsum('ic,ka,jlbd -> ijklabcd', t1, t1, t2aa) + t4_abab -= einsum('jb,ld,ikac -> ijklabcd', t1, t1, t2aa) + t4_abab += einsum('jd,lb,ikac -> ijklabcd', t1, t1, t2aa) + + # (t1 t1 t1 t1) terms + permutations + t1t1t1t1 = einsum('ia,jb,kc,ld -> ijklabcd', t1, t1, t1, t1) + + t4_abab -= t1t1t1t1 + t4_abab += t1t1t1t1.transpose(0,1,2,3,4,7,6,5) + t4_abab += t1t1t1t1.transpose(0,1,2,3,6,5,4,7) + t4_abab -= t1t1t1t1.transpose(0,1,2,3,6,7,4,5) + + return wf_types.RCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, \ + t4_abab=t4_abab, t4_abaa=t4_abaa) class UCISDTQ_WaveFunction(RCISDTQ_WaveFunction): From 9e306b9645f37f9ea29283a586ccd74fd2d0cd70 Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 4 Nov 2022 14:27:43 +0000 Subject: [PATCH 03/66] pass in tuple for t4 and c4 arguments rather than individual spin signatures --- vayesta/core/types/wf/ccsdtq.py | 8 +++++--- vayesta/core/types/wf/cisdtq.py | 20 +++++++++++++------- vayesta/core/types/wf/fci.py | 4 ++-- 3 files changed, 20 insertions(+), 12 deletions(-) diff --git a/vayesta/core/types/wf/ccsdtq.py b/vayesta/core/types/wf/ccsdtq.py index 7b552cd47..fa1c08982 100644 --- a/vayesta/core/types/wf/ccsdtq.py +++ b/vayesta/core/types/wf/ccsdtq.py @@ -14,13 +14,15 @@ def CCSDTQ_WaveFunction(mo, *args, **kwargs): class RCCSDTQ_WaveFunction(wf_types.WaveFunction): - def __init__(self, mo, t1, t2, t3, t4_abab, t4_abaa): + def __init__(self, mo, t1, t2, t3, t4): super().__init__(mo) self.t1 = t1 self.t2 = t2 self.t3 = t3 - self.t4_abab = t4_abab - self.t4_abaa = t4_abaa + self.t4 = t4 + if not (isinstance(t4, tuple) and len(t4) == 2): + raise ValueError('''t4 definition in RCCSDTQ wfn requires + tuple of (abaa, abab) spin signatures''') def as_ccsdtq(self): return self diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 160ce02ae..42a8628b6 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -14,14 +14,16 @@ def CISDTQ_WaveFunction(mo, *args, **kwargs): class RCISDTQ_WaveFunction(wf_types.WaveFunction): - def __init__(self, mo, c0, c1, c2, c3, c4_abab, c4_abaa): + def __init__(self, mo, c0, c1, c2, c3, c4): super().__init__(mo) self.c0 = c0 self.c1 = c1 self.c2 = c2 self.c3 = c3 - self.c4_abab = c4_abab - self.c4_abaa = c4_abaa + self.c4 = c4 + if not (isinstance(c4, tuple) and len(c4)==2): + raise ValueError('''c4 definition in RCISDTQ wfn requires + tuple of (abaa, abab) spin signatures''') def as_ccsdtq(self): t1 = self.c1/self.c0 @@ -46,8 +48,10 @@ def as_ccsdtq(self): t3 += t1t1t1.transpose(0,1,2,5,4,3) # === t4_abaa === (Note that we construct both the abaa and abab spin signatures) + # Unpack c4 array into spin signatures + c4_abaa, c4_abab = self.c4 # Construct the abaa first - t4_abaa = self.c4_abaa/self.c0 + t4_abaa = c4_abaa/self.c0 # A useful intermediate is the t3_aaa. Construct this from t3 (_aba) mixed spin. t3_aaa = t3 - t3.transpose(0,2,1,3,4,5) - t3.transpose(1,0,2,3,4,5) @@ -126,7 +130,7 @@ def as_ccsdtq(self): t4_abaa += t1t1t1t1.transpose(0,1,2,3,7,5,6,4) # Now construct t4 with spin signature (abab -> abab) - t4_abab = self.c4_abab/self.c0 + t4_abab = c4_abab/self.c0 # (t1 t3) terms + permutations t1t3a = einsum('ia, jklbcd -> ijklabcd', t1, t3) @@ -186,9 +190,11 @@ def as_ccsdtq(self): t4_abab += t1t1t1t1.transpose(0,1,2,3,4,7,6,5) t4_abab += t1t1t1t1.transpose(0,1,2,3,6,5,4,7) t4_abab -= t1t1t1t1.transpose(0,1,2,3,6,7,4,5) + + # Pack two spin signatures into single tuple + t4 = (t4_abaa, t4_abab) - return wf_types.RCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, \ - t4_abab=t4_abab, t4_abaa=t4_abaa) + return wf_types.RCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) class UCISDTQ_WaveFunction(RCISDTQ_WaveFunction): diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 6d8f00366..2c5c49ad3 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -279,7 +279,6 @@ def as_cisdtq(self, c0=None): assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t3sign, t1sign, \ self.ci[t3addr[:,None], t1addr]))) - del c4_comp if c0 is None: c0 = self.c0 @@ -289,7 +288,8 @@ def as_cisdtq(self, c0=None): c3 *= c0/self.c0 c4_abab *= c0/self.c0 c4_abaa *= c0/self.c0 - return wf_types.RCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4_abab, c4_abaa) + + return wf_types.RCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, (c4_abaa, c4_abab)) def as_ccsd(self): return self.as_cisd().as_ccsd() From 847f0f562f8f41653df3ba1d4f0067ec24e117ac Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 4 Nov 2022 14:58:33 +0000 Subject: [PATCH 04/66] Fix string format --- vayesta/core/types/wf/ccsdtq.py | 3 +-- vayesta/core/types/wf/cisdtq.py | 3 +-- 2 files changed, 2 insertions(+), 4 deletions(-) diff --git a/vayesta/core/types/wf/ccsdtq.py b/vayesta/core/types/wf/ccsdtq.py index fa1c08982..1fbb28a51 100644 --- a/vayesta/core/types/wf/ccsdtq.py +++ b/vayesta/core/types/wf/ccsdtq.py @@ -21,8 +21,7 @@ def __init__(self, mo, t1, t2, t3, t4): self.t3 = t3 self.t4 = t4 if not (isinstance(t4, tuple) and len(t4) == 2): - raise ValueError('''t4 definition in RCCSDTQ wfn requires - tuple of (abaa, abab) spin signatures''') + raise ValueError("t4 definition in RCCSDTQ wfn requires tuple of (abaa, abab) spin signatures") def as_ccsdtq(self): return self diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 42a8628b6..30ca39aa1 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -22,8 +22,7 @@ def __init__(self, mo, c0, c1, c2, c3, c4): self.c3 = c3 self.c4 = c4 if not (isinstance(c4, tuple) and len(c4)==2): - raise ValueError('''c4 definition in RCISDTQ wfn requires - tuple of (abaa, abab) spin signatures''') + raise ValueError("c4 definition in RCISDTQ wfn requires tuple of (abaa, abab) spin signatures") def as_ccsdtq(self): t1 = self.c1/self.c0 From 5105d8a8c014e99d7f15ba113b19f6b49ec1562d Mon Sep 17 00:00:00 2001 From: George Booth Date: Sat, 12 Nov 2022 11:40:39 +0000 Subject: [PATCH 05/66] Update example to non-deprecated practices --- examples/ewf/molecules/11-fragmentation.py | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/examples/ewf/molecules/11-fragmentation.py b/examples/ewf/molecules/11-fragmentation.py index c990a6f3b..cef26754a 100644 --- a/examples/ewf/molecules/11-fragmentation.py +++ b/examples/ewf/molecules/11-fragmentation.py @@ -21,19 +21,21 @@ mf.kernel() # Embedded CCSD -emb_iao = vayesta.ewf.EWF(mf, bno_threshold=1e-6) +emb_iao = vayesta.ewf.EWF(mf, bath_options=dict(threshold=1e-6)) # If calling the kernel without initializing the fragmentation, -# IAO fragmentation is used automatically: -# It can be initialized manually by calling emb.iao_fragmentation() +# IAO fragmentation is used automatically. +# It can be initialized manually by calling: +with emb_iao.iao_fragmentation() as f: + f.add_all_atomic_fragments() emb_iao.kernel() -emb_iaopao = vayesta.ewf.EWF(mf, bno_threshold=1e-6) +emb_iaopao = vayesta.ewf.EWF(mf, bath_options=dict(threshold=1e-6)) # To use IAO+PAOs, call emb.iaopao_fragmentation() before the kernel: with emb_iaopao.iaopao_fragmentation() as f: f.add_all_atomic_fragments() emb_iaopao.kernel() -emb_sao = vayesta.ewf.EWF(mf, bno_threshold=1e-6) +emb_sao = vayesta.ewf.EWF(mf, bath_options=dict(threshold=1e-6)) # To use Lowdin AOs (SAOs), call emb.sao_fragmentation() before the kernel: with emb_sao.sao_fragmentation() as f: f.add_all_atomic_fragments() From 410a3208795b697c236cfbbd5522bf650c843003 Mon Sep 17 00:00:00 2001 From: George Booth Date: Sat, 12 Nov 2022 11:41:27 +0000 Subject: [PATCH 06/66] Add OBC 1D chain of atoms constructor --- vayesta/misc/molecules/molecules.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/vayesta/misc/molecules/molecules.py b/vayesta/misc/molecules/molecules.py index 42d5c9737..64e64130d 100644 --- a/vayesta/misc/molecules/molecules.py +++ b/vayesta/misc/molecules/molecules.py @@ -150,6 +150,18 @@ def ring(atom, natom, bond_length=None, radius=None, z=0.0, numbering=None): atoms.append([atom_i, np.asarray([r*np.cos(theta), r*np.sin(theta), z])]) return atoms +def chain(atom, natom, bond_length=None, numbering=None): + '''Open boundary condition version of 1D ring''' + atoms = [] + if isinstance(atom, str): + atom = [atom] + for i in range(natom): + atom_i = atom[i%len(atom)] + if numbering is not None: + atom_i += str(int(numbering) + i) + atoms.append([atom_i, np.asarray([i*bond_length, 0.0, 0.0])]) + return atoms + # --- From datafiles: def acetic_acid(): From 14de2a2cfafd85068a8591230a0d5c9d02b7ebf5 Mon Sep 17 00:00:00 2001 From: George Booth Date: Sat, 12 Nov 2022 21:37:39 +0000 Subject: [PATCH 07/66] WIP --- vayesta/solver/coupling.py | 36 ++++++++++++++++++++++++++++++++---- 1 file changed, 32 insertions(+), 4 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 7dc8b0b11..5101da846 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -266,7 +266,7 @@ def _integrals_for_extcorr(fragment, fock): if emb.spinsym == 'restricted': occ = np.s_[:cluster.nocc_active] vir = np.s_[cluster.nocc_active:] - govov = eris[occ,vir,occ,vir] + govov = eris[occ,vir,occ,vir] # chemical notation fov = dot(cluster.c_active_occ.T, fock, cluster.c_active_vir) if emb.spinsym == 'unrestricted': oa = np.s_[:cluster.nocc_active[0]] @@ -291,9 +291,10 @@ def _get_delta_t_for_extcorr(fragment, fock): # to avoid storing all wf = fragment.results.wf.as_ccsdtq() - t1, t2, t3, t4 = wf.t1, wf.t2, wf.t3, wf.t4 + t1, t2, t3 = wf.t1, wf.t2, wf.t3 + t4_abaa, t4_abab = wf.t4 - # Get ERIs and Fock matrix + # Get ERIs and Fock matrix for the given fragment fov, govov = _integrals_for_extcorr(fragment, fock) # --- Make correction to T1 and T2 amplitudes # J. Chem. Theory Comput. 2021, 17, 182−190 @@ -301,13 +302,39 @@ def _get_delta_t_for_extcorr(fragment, fock): dt1 = spinalg.zeros_like(t1) dt2 = spinalg.zeros_like(t2) - raise NotImplementedError if emb.spinsym == 'restricted': + # TODO: o Are the f_ov blocks just ignored? Only (ov) block contributes - check if it is zero or not. + # o If not, will need to integrate it from the spin-orbital expressions. + # o Compare to equations in literature?? + + # o Some terms want to be contracted with the integrals in the parent cluster. Don't pass back delta_T2, + # but quantities to contract with in parent cluster. This is option to max_coul_coup. + # o When do we want to project terms. Presumably not after contraction with integrals if we can help it? + # o For just testing of correctness, we can just do it naievely to start, as it should still be exact. + + # TO TEST: + # o Exact cf FCI for four electron systems and full CCSD and FCI fragments + # o Exact cf FCI for four electron systems and full bath CCSD and FCI fragments? Or just one? (only if zero projectors?) + # o Rotate (ov) space and ensure invariant + # o Extensivity checks for separated fragments? (Two LiH clusters separated should be exact, then check approximate systems) # --- T1 # T3 * V + # V are antisymmetrized integrals of V[i,j,a,b] = 2 - + # Vint are the + dt1 += einsum('ijab, jiupab -> up', 2.*govov - govov.transpose(0,3,2,1), self.T3) #dt1 += einsum('imnaef,menf->ia', t3, govov) # --- T2 + self.T3onT2 = 0.5*np.einsum('bmef, jimeaf -> ijab', (self.Vint - self.Vint.swapaxes(2,3))[v,o,v,v], self.T3) \ + + np.einsum('bmef, ijmaef -> ijab', self.Vint[v,o,v,v], self.T3) \ + -0.5*np.einsum('mnje, minbae -> ijab', (self.Vint - self.Vint.swapaxes(2,3))[o,o,o,v], self.T3) \ + - np.einsum('mnje, imnabe -> ijab', self.Vint[o,o,o,v], self.T3) + + self.T3onT2 = self.T3onT2 + np.einsum('ijab -> jiba', self.T3onT2) + + + # F * T3 + #dt2 += einsum('me,ijmabe->ijab', fov, t3) # T1 * T3 * V #dt2 += einsum('me,ijnabf,menf->ijab', t1, t3, govov) @@ -319,6 +346,7 @@ def _get_delta_t_for_extcorr(fragment, fock): # T4 * V pass elif emb.spinsym == 'unrestricted': + raise NotImplementedError # TODO pass else: From bf6d8d8f687257a6bb3af057d3aa4141bedb9cc5 Mon Sep 17 00:00:00 2001 From: George Booth Date: Mon, 14 Nov 2022 15:10:29 +0000 Subject: [PATCH 08/66] Complete code for ec-cc with all hamiltonian terms from child cluster. --- vayesta/solver/coupling.py | 154 ++++++++++++++++++++++++------------- 1 file changed, 100 insertions(+), 54 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 5101da846..16ce1f3b2 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -267,6 +267,9 @@ def _integrals_for_extcorr(fragment, fock): occ = np.s_[:cluster.nocc_active] vir = np.s_[cluster.nocc_active:] govov = eris[occ,vir,occ,vir] # chemical notation + gvvov = eris[vir,vir,occ,vir] + gooov = eris[occ,occ,occ,vir] + govoo = eris[occ,vir,occ,occ] fov = dot(cluster.c_active_occ.T, fock, cluster.c_active_vir) if emb.spinsym == 'unrestricted': oa = np.s_[:cluster.nocc_active[0]] @@ -280,72 +283,102 @@ def _integrals_for_extcorr(fragment, fock): govovbb = eris[ob,vb,ob,vb] fov = (fova, fovb) govov = (govovaa, govovab, govovbb) - return fov, govov + gvvov = None + gooov = None + govoo = None + raise NotImplementedError + return fov, govov, gvvov, gooov, govoo -def _get_delta_t_for_extcorr(fragment, fock): - emb = fragment.base +def _get_delta_t_for_extcorr(fragment, fock, include_t3v=True): + ''' Make T3 and T4 correction to CCSD wave function for given fragment. + If include_t3v, then these terms are included. If not, they are left out + (to be contracted later with cluster y integrals). + + TODO: Option: Contract T4's down at original solver point to save memory. - # Make CCSDTQ wave function from cluster y - # TODO: Future improvement - make option to directly store these amplitudes precontracted, - # to avoid storing all + TO TEST: Exact for 4-e systems for full CCSD and FCI fragments. + Exact for 4-e systems for full CCSD and FCI baths (depending on projectors) + Rotate (ov) space to check invariance? + Extensivity checks for separated fragments''' wf = fragment.results.wf.as_ccsdtq() t1, t2, t3 = wf.t1, wf.t2, wf.t3 t4_abaa, t4_abab = wf.t4 # Get ERIs and Fock matrix for the given fragment - fov, govov = _integrals_for_extcorr(fragment, fock) + # govov is (ia|jb) + fov, govov, gvvov, gooov, govoo = _integrals_for_extcorr(fragment, fock) # --- Make correction to T1 and T2 amplitudes # J. Chem. Theory Comput. 2021, 17, 182−190 - # [what is v_ef^mn? (em|fn) ?] + # also with reference to git@github.com:gustavojra/Methods.git dt1 = spinalg.zeros_like(t1) dt2 = spinalg.zeros_like(t2) - if emb.spinsym == 'restricted': - # TODO: o Are the f_ov blocks just ignored? Only (ov) block contributes - check if it is zero or not. - # o If not, will need to integrate it from the spin-orbital expressions. - # o Compare to equations in literature?? - - # o Some terms want to be contracted with the integrals in the parent cluster. Don't pass back delta_T2, - # but quantities to contract with in parent cluster. This is option to max_coul_coup. - # o When do we want to project terms. Presumably not after contraction with integrals if we can help it? - # o For just testing of correctness, we can just do it naievely to start, as it should still be exact. - - # TO TEST: - # o Exact cf FCI for four electron systems and full CCSD and FCI fragments - # o Exact cf FCI for four electron systems and full bath CCSD and FCI fragments? Or just one? (only if zero projectors?) - # o Rotate (ov) space and ensure invariant - # o Extensivity checks for separated fragments? (Two LiH clusters separated should be exact, then check approximate systems) - # --- T1 - # T3 * V - # V are antisymmetrized integrals of V[i,j,a,b] = 2 - - # Vint are the - dt1 += einsum('ijab, jiupab -> up', 2.*govov - govov.transpose(0,3,2,1), self.T3) - #dt1 += einsum('imnaef,menf->ia', t3, govov) - # --- T2 - self.T3onT2 = 0.5*np.einsum('bmef, jimeaf -> ijab', (self.Vint - self.Vint.swapaxes(2,3))[v,o,v,v], self.T3) \ - + np.einsum('bmef, ijmaef -> ijab', self.Vint[v,o,v,v], self.T3) \ - -0.5*np.einsum('mnje, minbae -> ijab', (self.Vint - self.Vint.swapaxes(2,3))[o,o,o,v], self.T3) \ - - np.einsum('mnje, imnabe -> ijab', self.Vint[o,o,o,v], self.T3) - - self.T3onT2 = self.T3onT2 + np.einsum('ijab -> jiba', self.T3onT2) - - - - # F * T3 - - #dt2 += einsum('me,ijmabe->ijab', fov, t3) - # T1 * T3 * V - #dt2 += einsum('me,ijnabf,menf->ijab', t1, t3, govov) - # TODO: - # P(ab) T3 * V - # P(ij) T3 * V - # P(ij) T1 * T3 * V - # P(ab) T1 * T3 * V - # T4 * V - pass - elif emb.spinsym == 'unrestricted': + if fragment.base.spinsym == 'restricted': + # Construct physical antisymmetrized integrals for some contractions + # Note that some contractions are with physical and some chemical integrals (govov) + antiphys_g = (govov - govov.transpose(0,3,2,1)).transpose(0,2,1,3) + spinned_antiphys_g = (2.0*govov - govov.transpose(0,3,2,1)).transpose(0,2,1,3) + + # --- T1 update + # --- T3 * V + dt1 += einsum('ijab, jiupab -> up', spinned_antiphys_g, t3) + + # --- T2 update + # --- T3 * F + if np.allclose(fov, np.zeros_like(fov)): + solver.log.info("fov block zero: No T3 * f contribution.") + # (Fa) (Taba) contraction + dt2 += einsum('em, ijmabe -> ijab', fov, t3) + # (Fb) (Tabb) contraction + dt2 += einsum('em, jimbae -> ijab', fov, t3) + solver.log.info("(T3 * F) -> T2 update norm from fragment {}: {}".format(fragment.id, np.linalg.norm(dt2))) + + # --- T4 * V + # (Vaa) (Tabaa) contraction + t4v = 0.25 * einsum('mnef, ijmnabef -> ijab', antiphys_g, t4_abaa) + dt2 += t4v + dt2 += t4v.transpose(1,0,3,2) + # (Vab) (Tabab) contraction + dt2 += einsum('menf, ijmnabef -> ijab', govov, t4_abab) + + # --- (T1 T3) * V + # Note: Approximate T1 by the CCSDTQ T1 amplitudes of this fragment. + # TODO: Relax this approximation? + t1t3v = np.zeros_like(dt2) + X_ = einsum('mnef, me -> nf', spinned_antiphys_g, t1) + t1t3v += einsum('nf, nijfab -> ijab', X_, t3) + + X_ = 0.5*einsum('mnef, njiebf -> ijmb', antiphys_g, t3) + X_ += einsum('menf, jinfeb -> ijmb', govov, t3) + t1t3v += einsum('ijmb, ma -> ijab', X_, t1) + + X_ = 0.5*einsum('mnef, mjnfba -> ejab', antiphys_g, t3) + X_ += einsum('menf, nmjbaf -> ejab', govov, t3) + t1t3v += einsum('ejab, ie -> ijab', X_, t1) + # apply permutation + dt2 += t1t3v + t1t3v.transpose(1,0,3,2) + + # --- T3 * V + if include_t3v: + # Option to leave out this term, and instead perform T3 * V with the + # integrals in the parent cluster later. + # This will give a different result since the V operators + # will span a different space. Instead, here we just contract T3 with integrals + # in cluster y (FCI), rather than cluster x (CCSD) + + # Note that this requires (vv|ov) [first term], (oo|ov) and (ov|oo) [second term] + t3v = np.zeros_like(dt2) + # First term: 1/2 P_ab [t_ijmaef v_efbm] + t3v += 0.5*einsum('bemf, jimeaf -> ijab', gvvov - gvvov.transpose(0,3,2,1), t3) + t3v += einsum('bemf, ijmaef -> ijab', gvvov, t3) + # Second term: -1/2 P_ij [t_imnabe v_jemn] + t3v -= 0.5*einsum('mjne, minbae -> ijab', gooov - govoo.transpose(0,3,2,1), t3) + t3v -= einsum('mjne, imnabe -> ijab', gooov, t3) + dt2 += t3v + t3v.transpose(1,0,3,2) + + elif fragment.base.spinsym == 'unrestricted': raise NotImplementedError # TODO pass @@ -354,6 +387,9 @@ def _get_delta_t_for_extcorr(fragment, fock): return dt1, dt2 +def _get_delta_t2_from_t3v() + pass + def _get_delta_t_for_delta_tailor(fragment, fock): wf = fragment.results.wf.as_ccsd() t1, t2 = wf.t1, wf.t2 @@ -427,13 +463,17 @@ def externally_correct(solver, external_corrections): # CCSD uses exxdiv-uncorrected Fock matrix: fock = emb.get_fock(with_exxdiv=False) + + for y, corrtype, projectors in external_corrections: fy = frag_dir[y] # Get fragment y object from its index assert (y != fx.id) - if corrtype == 'external': - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock) + if corrtype == 'external' or 'external-fciv': + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, include_t3v=True) + elif corrtype == 'external-ccsdv': + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, include_t3v=False) elif corrtype == 'delta-tailor': dt1y, dt2y = _get_delta_t_for_delta_tailor(fy, fock) else: @@ -455,6 +495,12 @@ def externally_correct(solver, external_corrections): dt2y = transform_amplitude(dt2y, rxy_occ, rxy_vir, inverse=True) dt1 = spinalg.add(dt1, dt1y) dt2 = spinalg.add(dt2, dt2y) + + if corrtype == 'external-ccsdv': + # Include the t3v term, contracting with the integrals from the x cluster + dt2y_t3v = _get_delta_t2_from_t3v() + dt2 = spinalg.add(dt2, dt2y_t3v) + solver.log.info("External correction from fragment %3d (%s): dT1= %.3e dT2= %.3e", fy.id, fy.solver, *get_amplitude_norm(dt1y, dt2y)) From da0453555a928a89689606fddd0e0adba2611c0b Mon Sep 17 00:00:00 2001 From: George Booth Date: Tue, 15 Nov 2022 09:21:02 +0000 Subject: [PATCH 09/66] Local external correction implemented and running. Now to debug...! --- vayesta/core/types/wf/fci.py | 19 +++++--- vayesta/ewf/fragment.py | 4 +- vayesta/solver/ccsd.py | 2 +- vayesta/solver/coupling.py | 95 +++++++++++++++++++++++++++++++----- 4 files changed, 99 insertions(+), 21 deletions(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 2c5c49ad3..88afb633c 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -158,8 +158,10 @@ def as_cisdtq(self, c0=None): c3[j,k,i,a,c,b] = -c3_comp[d_cnt, s_cnt] c3[i,k,j,b,c,a] = -c3_comp[d_cnt, s_cnt] c3[j,k,i,b,c,a] = c3_comp[d_cnt, s_cnt] - assert(np.allclose(c3_comp, np.einsum('i,j,ij->ij', \ - t2sign, t1sign, self.ci[t2addr[:,None], t1addr]))) + + if len(t2addr) > 0: + assert(np.allclose(c3_comp, np.einsum('i,j,ij->ij', \ + t2sign, t1sign, self.ci[t2addr[:,None], t1addr]))) del c3_comp # === C4 amplitudes === @@ -205,14 +207,16 @@ def as_cisdtq(self, c0=None): c4_abab[j, J, i, I, a, B, b, A] = -c4_comp[d_cnt_a, d_cnt_b] c4_abab[j, J, i, I, b, A, a, B] = -c4_comp[d_cnt_a, d_cnt_b] c4_abab[j, J, i, I, b, B, a, A] = c4_comp[d_cnt_a, d_cnt_b] - assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t2sign, t2sign, \ - self.ci[t2addr[:,None], t2addr]))) + + if len(t2addr) > 0: + assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t2sign, t2sign, \ + self.ci[t2addr[:,None], t2addr]))) del c4_comp # abaa spin signature. Get this from the aaab->aaab excitations. # This requires the index of the (alpha, alpha, alpha) -> (alpha, alpha, alpha) excits. t3addr, t3sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 3) - assert(t3addr.shape[0] == ijk_pairs * abc_pairs) + assert(len(t3addr) == ijk_pairs * abc_pairs) c4_abaa = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir)) c4_comp = np.zeros((ijk_pairs * abc_pairs, nocc * nvir)) @@ -277,8 +281,9 @@ def as_cisdtq(self, c0=None): c4_abaa[j, I, k, i, b, A, c, a] = c4_comp[t_cnt_a, s_cnt_b] c4_abaa[k, I, i, j, b, A, c, a] = c4_comp[t_cnt_a, s_cnt_b] - assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t3sign, t1sign, \ - self.ci[t3addr[:,None], t1addr]))) + if len(t3addr) > 0: + assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t3sign, t1sign, \ + self.ci[t3addr[:,None], t1addr]))) if c0 is None: c0 = self.c0 diff --git a/vayesta/ewf/fragment.py b/vayesta/ewf/fragment.py index bd5f17576..760d7d382 100644 --- a/vayesta/ewf/fragment.py +++ b/vayesta/ewf/fragment.py @@ -143,12 +143,14 @@ def add_external_corrections(self, fragments, correction_type='tailor', projecto 'tailor': replace CCSD T1 and T2 amplitudes with FCI amplitudes. 'delta-tailor': Add the difference of FCI and CCSD T1 and T2 amplitudes 'external': externally correct CCSD T1 and T2 amplitudes from FCI T3 and T4 amplitudes. + 'external-fciv': externally correct CCSD T1 and T2 amplitudes from FCI T3 and T4 amplitudes (note T3V term contracted with integrals from the cluster providing the constraints). 'external' is the same as this. + 'external-ccsdv': externally correct CCSD T1 and T2 amplitudes from FCI T3 and T4 amplitudes (note T3V term contracted with integrals from the cluster being constrained). Should be more accurate? Default: 'tailor'. projectors: int, optional Maximum number of projections applied to the occupied dimensions of the amplitude corrections. Default: 1. """ - if correction_type not in ('tailor', 'delta-tailor', 'external'): + if correction_type not in ('tailor', 'delta-tailor', 'external', 'external-fciv', 'external-ccsdv'): raise ValueError if self.solver != 'CCSD': raise RuntimeError diff --git a/vayesta/solver/ccsd.py b/vayesta/solver/ccsd.py index 72dd581d1..10e06aaa5 100644 --- a/vayesta/solver/ccsd.py +++ b/vayesta/solver/ccsd.py @@ -165,7 +165,7 @@ def kernel(self, t1=None, t2=None, eris=None, l1=None, l2=None, seris_ov=None, c elif self.opts.external_corrections: # Tailoring of T1 and T2 tailors = [ec for ec in self.opts.external_corrections if (ec[1] == 'tailor')] - externals = [ec for ec in self.opts.external_corrections if (ec[1] in ('external', 'delta-tailor'))] + externals = [ec for ec in self.opts.external_corrections if (ec[1] in ('external', 'delta-tailor', 'external-fciv', 'external-ccsdv'))] if tailors and externals: raise NotImplementedError if tailors: diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 16ce1f3b2..bd5572156 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -289,16 +289,14 @@ def _integrals_for_extcorr(fragment, fock): raise NotImplementedError return fov, govov, gvvov, gooov, govoo - -def _get_delta_t_for_extcorr(fragment, fock, include_t3v=True): +def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): ''' Make T3 and T4 correction to CCSD wave function for given fragment. If include_t3v, then these terms are included. If not, they are left out (to be contracted later with cluster y integrals). TODO: Option: Contract T4's down at original solver point to save memory. - TO TEST: Exact for 4-e systems for full CCSD and FCI fragments. - Exact for 4-e systems for full CCSD and FCI baths (depending on projectors) + TO TEST: Exact for 4-e systems for all IAO CCSD and FCI fragments and full bath. Rotate (ov) space to check invariance? Extensivity checks for separated fragments''' @@ -330,9 +328,9 @@ def _get_delta_t_for_extcorr(fragment, fock, include_t3v=True): if np.allclose(fov, np.zeros_like(fov)): solver.log.info("fov block zero: No T3 * f contribution.") # (Fa) (Taba) contraction - dt2 += einsum('em, ijmabe -> ijab', fov, t3) + dt2 += einsum('me, ijmabe -> ijab', fov, t3) # (Fb) (Tabb) contraction - dt2 += einsum('em, jimbae -> ijab', fov, t3) + dt2 += einsum('me, jimbae -> ijab', fov, t3) solver.log.info("(T3 * F) -> T2 update norm from fragment {}: {}".format(fragment.id, np.linalg.norm(dt2))) # --- T4 * V @@ -387,8 +385,75 @@ def _get_delta_t_for_extcorr(fragment, fock, include_t3v=True): return dt1, dt2 -def _get_delta_t2_from_t3v() - pass +def _get_delta_t2_from_t3v(gvvov_x, gooov_x, govoo_x, frag_child, rxy_occ, rxy_vir, cxs_occ, projectors): + """Perform the (T3 * V) contraction for the external correction, with the V integrals + in the parent basis (x). This will change the results as the V retains one open index + in the resulting T2 contributions. + + Parameters + ---------- + gvvov_x, gooov_x, govoo_x: ndarray + Integrals over various occ, vir slices in the parent (x) cluster + frag_child: fragment type + Fragment of the child cluster (y) + rxy_occ, rxy_vir: ndarray + Projection operator from x cluster to y cluster in the occ (vir) space + cxs_occ: ndarray + Cluster orbitals of cluster x contracted with overlap + projectors: int + Number of projectors onto the fragment space of y + + Returns + ------- + dt2: ndarray + Update to T2 amplitudes in the parent (x) basis + """ + + wf = frag_child.results.wf.as_ccsdtq() + t3 = wf.t3 + + if frag_child.base.spinsym == 'restricted': + + # First term, using (vv|ov): 1/2 P_ab [t_ijmaef v_efbm] + # Three-quarter transform of passed-in integrals from parent (x) to child (y) basis + # Keep first index of vvov integrals in x basis. Transform rest to y basis. + gvvov_ = einsum('abic,bB,iI,cC -> aBIC', gvvov_x, rxy_vir, rxy_occ, rxy_vir) + + # Contract with T3 amplitudes in the y basis + t3v_ = 0.5*einsum('bemf, jimeaf -> ijab', gvvov_ - gvvov_.transpose(0,3,2,1), t3) + t3v_ += einsum('bemf, ijmaef -> ijab', gvvov_, t3) + # Final is in a mixed basis form, with last index in t3v here in the x basis + # Rotate remaining indices into x basis: another three-quarter transform + t3v_x = einsum('IJAb,iI,jJ,aA -> ijab', t3v_, rxy_occ, rxy_occ, rxy_vir) + + # Second term: -1/2 P_ij [t_imnabe v_jemn] + # ooov three-quarter transform, to IjKA (capital is y (child) basis) + gooov_ = einsum('ijka,iI,kK,aA -> IjKA', gooov_x, rxy_occ, rxy_occ, rxy_vir) + # ovoo three-quarter transform, to IAJk (capital is y (child) basis) + govoo_ = einsum('iajk,iI,aA,jJ -> IAJk', govoo_x, rxy_occ, rxy_vir, rxy_occ) + + # Second index of t3v_ in the parent (x) basis + t3v_ = -0.5*einsum('mjne, minbae -> ijab', gooov_ - govoo_.transpose(0,3,2,1), t3) + t3v_ -= einsum('mjne, imnabe -> ijab', gooov_, t3) + # Rotate remaining indices into x basis: another three-quarter transform + t3v_x += einsum('IjAB,iI,aA,bB -> ijab', t3v_, rxy_occ, rxy_vir, rxy_vir) + + # Include permutation + dt2 = t3v_x + t3v_x.transpose(1,0,3,2) + + # Find the fragment projector of cluster y (child) in the basis of cluster x (parent) + c_frag_xocc = spinalg.dot(spinalg.T(frag_child.c_frag), spinalg.T(cxs_occ)) + proj_y_in_x = spinalg.dot(spinalg.T(c_frag_xocc), c_frag_xocc) + + # Project (t3 v) contribution onto fragment of cluster y + dt2 = project_t2(dt2, proj_y_in_x, projectors=projectors) + + elif frag_child.base.spinsym == 'unrestricted': + raise NotImplementedError + else: + raise ValueError + + return dt2 def _get_delta_t_for_delta_tailor(fragment, fock): wf = fragment.results.wf.as_ccsd() @@ -463,7 +528,11 @@ def externally_correct(solver, external_corrections): # CCSD uses exxdiv-uncorrected Fock matrix: fock = emb.get_fock(with_exxdiv=False) - + if any([corr[1] == 'external-ccsdv' for corr in external_corrections]): + # At least one fragment is externally corrected, *and* contracted with + # integrals in the parent cluster. Form the required integrals + # for this parent cluster. Note that not all of these are needed. + fov_x, govov_x, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) for y, corrtype, projectors in external_corrections: @@ -471,9 +540,9 @@ def externally_correct(solver, external_corrections): assert (y != fx.id) if corrtype == 'external' or 'external-fciv': - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, include_t3v=True) + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=True) elif corrtype == 'external-ccsdv': - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, include_t3v=False) + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=False) elif corrtype == 'delta-tailor': dt1y, dt2y = _get_delta_t_for_delta_tailor(fy, fock) else: @@ -498,7 +567,9 @@ def externally_correct(solver, external_corrections): if corrtype == 'external-ccsdv': # Include the t3v term, contracting with the integrals from the x cluster - dt2y_t3v = _get_delta_t2_from_t3v() + # These have already been fragment projected, and rotated into the x cluster + # in this function. + dt2y_t3v = _get_delta_t2_from_t3v(gvvov_x, gooov_x, govoo_x, fy, rxy_occ, rxy_vir, cxs_occ, projectors) dt2 = spinalg.add(dt2, dt2y_t3v) solver.log.info("External correction from fragment %3d (%s): dT1= %.3e dT2= %.3e", From 6d187cef0094b99a77a2aa1d0a7c57999f1dd562 Mon Sep 17 00:00:00 2001 From: George Booth Date: Tue, 15 Nov 2022 09:44:24 +0000 Subject: [PATCH 10/66] fix for 2e systems --- vayesta/core/types/wf/fci.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 88afb633c..2ceb7dd93 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -130,7 +130,7 @@ def as_cisdtq(self, c0=None): # excitations in the FCI array. To get the orbital indices that they correspond to, # use ooidx and vvidx t2addr, t2sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 2) - assert(t2addr.shape[0] == ij_pairs * ab_pairs) + assert(len(t2addr) == ij_pairs * ab_pairs) # First find the ijk -> abc excitations, where ijab are alpha, and kc are beta c3_comp = np.zeros((ij_pairs * ab_pairs, nocc * nvir)) From b8262a839020c09a46bf18965a85a96bf2a8cdf9 Mon Sep 17 00:00:00 2001 From: George Booth Date: Tue, 15 Nov 2022 17:08:23 +0000 Subject: [PATCH 11/66] ec-cc now exact for 4-electron systems and full FCI space. Seems to be working, but more tests needed. --- vayesta/solver/coupling.py | 42 ++++++++++++++++++++++++++++---------- 1 file changed, 31 insertions(+), 11 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index bd5572156..0ec3a1f03 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -296,7 +296,7 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): TODO: Option: Contract T4's down at original solver point to save memory. - TO TEST: Exact for 4-e systems for all IAO CCSD and FCI fragments and full bath. + TO TEST: Rotate (ov) space to check invariance? Extensivity checks for separated fragments''' @@ -312,7 +312,7 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # also with reference to git@github.com:gustavojra/Methods.git dt1 = spinalg.zeros_like(t1) dt2 = spinalg.zeros_like(t2) - + if fragment.base.spinsym == 'restricted': # Construct physical antisymmetrized integrals for some contractions # Note that some contractions are with physical and some chemical integrals (govov) @@ -321,7 +321,7 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # --- T1 update # --- T3 * V - dt1 += einsum('ijab, jiupab -> up', spinned_antiphys_g, t3) + dt1 -= einsum('ijab, jiupab -> up', spinned_antiphys_g, t3) # --- T2 update # --- T3 * F @@ -336,14 +336,14 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # --- T4 * V # (Vaa) (Tabaa) contraction t4v = 0.25 * einsum('mnef, ijmnabef -> ijab', antiphys_g, t4_abaa) - dt2 += t4v - dt2 += t4v.transpose(1,0,3,2) + t4v += t4v.transpose(1,0,3,2) # (Vab) (Tabab) contraction - dt2 += einsum('menf, ijmnabef -> ijab', govov, t4_abab) + t4v += einsum('menf, ijmnabef -> ijab', govov, t4_abab) + dt2 += t4v # --- (T1 T3) * V # Note: Approximate T1 by the CCSDTQ T1 amplitudes of this fragment. - # TODO: Relax this approximation? + # TODO: Relax this approximation via the callback? t1t3v = np.zeros_like(dt2) X_ = einsum('mnef, me -> nf', spinned_antiphys_g, t1) t1t3v += einsum('nf, nijfab -> ijab', X_, t3) @@ -356,7 +356,8 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): X_ += einsum('menf, nmjbaf -> ejab', govov, t3) t1t3v += einsum('ejab, ie -> ijab', X_, t1) # apply permutation - dt2 += t1t3v + t1t3v.transpose(1,0,3,2) + t1t3v += t1t3v.transpose(1,0,3,2) + dt2 += t1t3v # --- T3 * V if include_t3v: @@ -374,7 +375,9 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # Second term: -1/2 P_ij [t_imnabe v_jemn] t3v -= 0.5*einsum('mjne, minbae -> ijab', gooov - govoo.transpose(0,3,2,1), t3) t3v -= einsum('mjne, imnabe -> ijab', gooov, t3) - dt2 += t3v + t3v.transpose(1,0,3,2) + # Permutation + t3v += t3v.transpose(1,0,3,2) + dt2 += t3v elif fragment.base.spinsym == 'unrestricted': raise NotImplementedError @@ -487,6 +490,8 @@ def externally_correct(solver, external_corrections): """Build callback function for CCSD, to add external correction from other fragments. TODO: combine with `tailor_with_fragments`? + TODO: Improve efficiency of callback, by contracting update with energy denominators once. + (Need to make sure use correct MO energies here...) Parameters ---------- @@ -572,16 +577,31 @@ def externally_correct(solver, external_corrections): dt2y_t3v = _get_delta_t2_from_t3v(gvvov_x, gooov_x, govoo_x, fy, rxy_occ, rxy_vir, cxs_occ, projectors) dt2 = spinalg.add(dt2, dt2y_t3v) + # Note that the lines below don't actually give the norm of the T updates, since they are missing the + # energy denominators solver.log.info("External correction from fragment %3d (%s): dT1= %.3e dT2= %.3e", fy.id, fy.solver, *get_amplitude_norm(dt1y, dt2y)) + solver.log.info("Total external correction from all fragments: dT1= %.3e dT2= %.3e",*get_amplitude_norm(dt1, dt2)) if solver.spinsym == 'restricted': def callback(kwargs): """Add external correction to T1 and T2 amplitudes.""" t1, t2 = kwargs['t1new'], kwargs['t2new'] - t1[:] += dt1 - t2[:] += dt2 + + # Note that this will not work with a level shift + # TODO: Do this properly, using the correct MO energies, and precontracting + # outside the callback function. + eris = kwargs['eris'] + mo_energy = eris.mo_energy + nocc = t1.shape[0] + eia = mo_energy[:nocc,None] - mo_energy[None,nocc:] + eijab = mo_energy[:nocc,None,None,None] + mo_energy[None,:nocc,None,None] \ + - mo_energy[None,None,nocc:,None] - mo_energy[None,None,None,nocc:] + + # Divide by energy denominators + t1[:] += (dt1 / eia) + t2[:] += (dt2 / eijab) elif solver.spinsym == 'unrestricted': From 4d7381f4eb0190fa6efb5c7ff981745ec0e718d0 Mon Sep 17 00:00:00 2001 From: George Booth Date: Thu, 17 Nov 2022 13:53:49 +0000 Subject: [PATCH 12/66] Energy denominators now dealt with effectively outside the callback --- vayesta/solver/ccsd.py | 2 +- vayesta/solver/coupling.py | 85 ++++++++++++++++++++++++-------------- 2 files changed, 54 insertions(+), 33 deletions(-) diff --git a/vayesta/solver/ccsd.py b/vayesta/solver/ccsd.py index 10e06aaa5..9b9713811 100644 --- a/vayesta/solver/ccsd.py +++ b/vayesta/solver/ccsd.py @@ -178,7 +178,7 @@ def kernel(self, t1=None, t2=None, eris=None, l1=None, l2=None, seris_ov=None, c # External correction of T1 and T2 if externals: self.log.info("Externally correct CCSD from %d fragments", len(externals)) - self.set_callback(coupling.externally_correct(self, externals)) + self.set_callback(coupling.externally_correct(self, externals, eris=eris)) elif self.opts.sc_mode and self.base.iteration > 1: raise NotImplementedError diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 0ec3a1f03..c38e0f549 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -1,4 +1,5 @@ import numpy as np +from vayesta.core.ao2mo import helper as ao2mo_helper from vayesta.core.util import * from vayesta.core import spinalg from vayesta.mpi import mpi, RMA_Dict @@ -486,12 +487,10 @@ def _get_delta_t_for_delta_tailor(fragment, fock): return dt1, dt2 -def externally_correct(solver, external_corrections): +def externally_correct(solver, external_corrections, eris=None): """Build callback function for CCSD, to add external correction from other fragments. TODO: combine with `tailor_with_fragments`? - TODO: Improve efficiency of callback, by contracting update with energy denominators once. - (Need to make sure use correct MO energies here...) Parameters ---------- @@ -500,6 +499,12 @@ def externally_correct(solver, external_corrections): external_corrections: list[tuple(int, str, int)] List of external corrections. Each tuple contains the fragment ID, type of correction, and number of projectors for the given external correction. + eris: _ChemistsERIs + ERIs for parent CCSD fragment. Used for MO energies in residual contraction, and for + type of correction == 'external-ccsdv', where the parent Coulomb integral is contracted. + If not passed in, MO energy if needed will be constructed from the diagonal of + get_fock() of embedding base class, and the eris will be also be obtained from the + embedding base class. Optional. Returns ------- @@ -517,7 +522,32 @@ def externally_correct(solver, external_corrections): cx_vir = cluster.c_active_vir # Virtual active orbitals of current cluster cxs_occ = spinalg.dot(spinalg.T(cx_occ), ovlp) cxs_vir = spinalg.dot(spinalg.T(cx_vir), ovlp) + # CCSD uses exxdiv-uncorrected Fock matrix for residuals + fock = emb.get_fock(with_exxdiv=False) + if eris is None: + # Note that if no MO energies are passed in, we construct them from the + # get_fock function without with_exxdiv=False. For PBC CCSD, this may be different + # behaviour. + mo_energy = einsum('ai,ab,bi->i', cluster.c_active, emb.get_fock(), cluster.c_active) + else: + mo_energy = eris.mo_energy + if any([corr[1] == 'external-ccsdv' for corr in external_corrections]): + # At least one fragment is externally corrected, *and* contracted with + # integrals in the parent cluster. We can take the integrals from eris + # if passed in. Otherwise, form the required integrals + # for this parent cluster. Note that not all of these are needed. + if eris is None: + _, _, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) + else: + if emb.spinsym == 'restricted': + print(vars(eris)) + gvvov_x = ao2mo_helper.get_ovvv(eris).transpose(2,3,0,1) + gooov_x = eris.ovoo.transpose(2,3,0,1) + govoo_x = eris.ovoo + elif emb.spinsym == 'unrestricted': + raise NotImplementedError + # delta-T1 and delta-T2 amplitudes, to be added to the CCSD amplitudes if solver.spinsym == 'restricted': dt1 = np.zeros((nocc, nvir)) @@ -530,15 +560,6 @@ def externally_correct(solver, external_corrections): np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]))) frag_dir = {f.id: f for f in emb.fragments} - # CCSD uses exxdiv-uncorrected Fock matrix: - fock = emb.get_fock(with_exxdiv=False) - - if any([corr[1] == 'external-ccsdv' for corr in external_corrections]): - # At least one fragment is externally corrected, *and* contracted with - # integrals in the parent cluster. Form the required integrals - # for this parent cluster. Note that not all of these are needed. - fov_x, govov_x, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) - for y, corrtype, projectors in external_corrections: fy = frag_dir[y] # Get fragment y object from its index @@ -562,7 +583,7 @@ def externally_correct(solver, external_corrections): dt1y = spinalg.dot(proj, dt1y) dt2y = project_t2(dt2y, proj, projectors=projectors) - # Transform back to fragment x space and add: + # Transform back to fragment x space rxy_occ = spinalg.dot(cxs_occ, fy.cluster.c_active_occ) rxy_vir = spinalg.dot(cxs_vir, fy.cluster.c_active_vir) dt1y = transform_amplitude(dt1y, rxy_occ, rxy_vir, inverse=True) @@ -577,33 +598,33 @@ def externally_correct(solver, external_corrections): dt2y_t3v = _get_delta_t2_from_t3v(gvvov_x, gooov_x, govoo_x, fy, rxy_occ, rxy_vir, cxs_occ, projectors) dt2 = spinalg.add(dt2, dt2y_t3v) - # Note that the lines below don't actually give the norm of the T updates, since they are missing the - # energy denominators - solver.log.info("External correction from fragment %3d (%s): dT1= %.3e dT2= %.3e", + solver.log.info("External correction residuals from fragment %3d (%s): dT1= %.3e dT2= %.3e", fy.id, fy.solver, *get_amplitude_norm(dt1y, dt2y)) - solver.log.info("Total external correction from all fragments: dT1= %.3e dT2= %.3e",*get_amplitude_norm(dt1, dt2)) - + if solver.spinsym == 'restricted': + + if corrtype in ['external', 'external-fciv', 'external-ccsdv']: + # Contract with fragment x (CCSD) energy denominators + # Note that this will not work correctly if a level shift used + eia = mo_energy[:nocc, None] - mo_energy[None, nocc:] + # TODO: Not the most memory efficient way to contract with + # energy denominators here. Improve to reduce N^4 memory cost? + eijab = mo_energy[:nocc, None, None, None] + mo_energy[None, :nocc, None, None] \ + - mo_energy[None, None, nocc:, None] - mo_energy[None, None, None, nocc:] + dt1 /= eia + dt2 /= eijab + + solver.log.info("Total external correction amplitudes from all fragments: dT1= %.3e dT2= %.3e", \ + *get_amplitude_norm(dt1, dt2)) def callback(kwargs): """Add external correction to T1 and T2 amplitudes.""" t1, t2 = kwargs['t1new'], kwargs['t2new'] - - # Note that this will not work with a level shift - # TODO: Do this properly, using the correct MO energies, and precontracting - # outside the callback function. - eris = kwargs['eris'] - mo_energy = eris.mo_energy - nocc = t1.shape[0] - eia = mo_energy[:nocc,None] - mo_energy[None,nocc:] - eijab = mo_energy[:nocc,None,None,None] + mo_energy[None,:nocc,None,None] \ - - mo_energy[None,None,nocc:,None] - mo_energy[None,None,None,nocc:] - - # Divide by energy denominators - t1[:] += (dt1 / eia) - t2[:] += (dt2 / eijab) + t1[:] += dt1 + t2[:] += dt2 elif solver.spinsym == 'unrestricted': + # TODO: Not working - need to contract properly with energy denominators def callback(kwargs): """Add external correction to T1 and T2 amplitudes.""" From ab487aa208569e8cbf010101ada75e7b2641947a Mon Sep 17 00:00:00 2001 From: George Booth Date: Thu, 17 Nov 2022 15:02:27 +0000 Subject: [PATCH 13/66] Address Max comments on code style. Fix bug in external-ccsdv --- vayesta/core/types/wf/fci.py | 2 +- vayesta/misc/molecules/molecules.py | 2 +- vayesta/solver/coupling.py | 19 ++++++++++--------- 3 files changed, 12 insertions(+), 11 deletions(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 2ceb7dd93..a0971dbc3 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -222,7 +222,7 @@ def as_cisdtq(self, c0=None): c4_comp = np.zeros((ijk_pairs * abc_pairs, nocc * nvir)) for t_cnt_a, trip_ind_a in enumerate(t3addr): # Find alpha i,j,k -> a,b,c indices - ijk_alpha = int(t_cnt_a / abc_pairs) + ijk_alpha = t_cnt_a // abc_pairs abc_alpha = t_cnt_a % abc_pairs i, j, k = oooidx[0][ijk_alpha], oooidx[1][ijk_alpha], oooidx[2][ijk_alpha] a, b, c = vvvidx[0][abc_alpha], vvvidx[1][abc_alpha], vvvidx[2][abc_alpha] diff --git a/vayesta/misc/molecules/molecules.py b/vayesta/misc/molecules/molecules.py index 64e64130d..aca216044 100644 --- a/vayesta/misc/molecules/molecules.py +++ b/vayesta/misc/molecules/molecules.py @@ -150,7 +150,7 @@ def ring(atom, natom, bond_length=None, radius=None, z=0.0, numbering=None): atoms.append([atom_i, np.asarray([r*np.cos(theta), r*np.sin(theta), z])]) return atoms -def chain(atom, natom, bond_length=None, numbering=None): +def chain(atom, natom, bond_length, numbering=None): '''Open boundary condition version of 1D ring''' atoms = [] if isinstance(atom, str): diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index c38e0f549..d457cb0c4 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -279,6 +279,7 @@ def _integrals_for_extcorr(fragment, fock): vb = np.s_[cluster.nocc_active[1]:] fova = dot(cluster.c_active_occ[0].T, fock[0], cluster.c_active_vir[0]) fovb = dot(cluster.c_active_occ[1].T, fock[1], cluster.c_active_vir[1]) + # TODO: Sort out the code below: Should be referring to eris[0], eris[1] and eris[2] govovaa = eris[oa,va,oa,va] govovab = eris[oa,va,ob,vb] govovbb = eris[ob,vb,ob,vb] @@ -291,7 +292,7 @@ def _integrals_for_extcorr(fragment, fock): return fov, govov, gvvov, gooov, govoo def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): - ''' Make T3 and T4 correction to CCSD wave function for given fragment. + """Make T3 and T4 correction to CCSD wave function for given fragment. If include_t3v, then these terms are included. If not, they are left out (to be contracted later with cluster y integrals). @@ -299,7 +300,8 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): TO TEST: Rotate (ov) space to check invariance? - Extensivity checks for separated fragments''' + Extensivity checks for separated fragments + """ wf = fragment.results.wf.as_ccsdtq() t1, t2, t3 = wf.t1, wf.t2, wf.t3 @@ -336,7 +338,7 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # --- T4 * V # (Vaa) (Tabaa) contraction - t4v = 0.25 * einsum('mnef, ijmnabef -> ijab', antiphys_g, t4_abaa) + t4v = einsum('mnef, ijmnabef -> ijab', antiphys_g, t4_abaa) / 4 t4v += t4v.transpose(1,0,3,2) # (Vab) (Tabab) contraction t4v += einsum('menf, ijmnabef -> ijab', govov, t4_abab) @@ -349,11 +351,11 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): X_ = einsum('mnef, me -> nf', spinned_antiphys_g, t1) t1t3v += einsum('nf, nijfab -> ijab', X_, t3) - X_ = 0.5*einsum('mnef, njiebf -> ijmb', antiphys_g, t3) + X_ = einsum('mnef, njiebf -> ijmb', antiphys_g, t3) / 2 X_ += einsum('menf, jinfeb -> ijmb', govov, t3) t1t3v += einsum('ijmb, ma -> ijab', X_, t1) - X_ = 0.5*einsum('mnef, mjnfba -> ejab', antiphys_g, t3) + X_ = einsum('mnef, mjnfba -> ejab', antiphys_g, t3) / 2 X_ += einsum('menf, nmjbaf -> ejab', govov, t3) t1t3v += einsum('ejab, ie -> ijab', X_, t1) # apply permutation @@ -371,10 +373,10 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # Note that this requires (vv|ov) [first term], (oo|ov) and (ov|oo) [second term] t3v = np.zeros_like(dt2) # First term: 1/2 P_ab [t_ijmaef v_efbm] - t3v += 0.5*einsum('bemf, jimeaf -> ijab', gvvov - gvvov.transpose(0,3,2,1), t3) + t3v += einsum('bemf, jimeaf -> ijab', gvvov - gvvov.transpose(0,3,2,1), t3) / 2 t3v += einsum('bemf, ijmaef -> ijab', gvvov, t3) # Second term: -1/2 P_ij [t_imnabe v_jemn] - t3v -= 0.5*einsum('mjne, minbae -> ijab', gooov - govoo.transpose(0,3,2,1), t3) + t3v -= einsum('mjne, minbae -> ijab', gooov - govoo.transpose(0,3,2,1), t3) / 2 t3v -= einsum('mjne, imnabe -> ijab', gooov, t3) # Permutation t3v += t3v.transpose(1,0,3,2) @@ -541,7 +543,6 @@ def externally_correct(solver, external_corrections, eris=None): _, _, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) else: if emb.spinsym == 'restricted': - print(vars(eris)) gvvov_x = ao2mo_helper.get_ovvv(eris).transpose(2,3,0,1) gooov_x = eris.ovoo.transpose(2,3,0,1) govoo_x = eris.ovoo @@ -565,7 +566,7 @@ def externally_correct(solver, external_corrections, eris=None): fy = frag_dir[y] # Get fragment y object from its index assert (y != fx.id) - if corrtype == 'external' or 'external-fciv': + if corrtype in ['external', 'external-fciv']: dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=True) elif corrtype == 'external-ccsdv': dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=False) From b8fd264f25cf0cc1531a0f258f49953417c67d3a Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 18 Nov 2022 11:48:55 +0000 Subject: [PATCH 14/66] Added alternate equations to check consistency of EC implementation. All seems to be working correctly. Tests and examples to come. --- vayesta/core/types/wf/ccsdtq.py | 8 +++ vayesta/ewf/fragment.py | 15 +++++- vayesta/solver/ccsd.py | 4 +- vayesta/solver/coupling.py | 92 ++++++++++++++++++++++++++++----- 4 files changed, 103 insertions(+), 16 deletions(-) diff --git a/vayesta/core/types/wf/ccsdtq.py b/vayesta/core/types/wf/ccsdtq.py index 1fbb28a51..5f7c4f0ad 100644 --- a/vayesta/core/types/wf/ccsdtq.py +++ b/vayesta/core/types/wf/ccsdtq.py @@ -13,6 +13,7 @@ def CCSDTQ_WaveFunction(mo, *args, **kwargs): class RCCSDTQ_WaveFunction(wf_types.WaveFunction): + # TODO: Contract T4's down to intermediates to reduce EC-CC memory overheads. def __init__(self, mo, t1, t2, t3, t4): super().__init__(mo) @@ -26,6 +27,13 @@ def __init__(self, mo, t1, t2, t3, t4): def as_ccsdtq(self): return self + def as_ccsd(self): + if self.projector is not None: + raise NotImplementedError + return wf_types.RCCSD_WaveFunction(self.mo, self.t1, self.t2) + + def as_cisd(self, c0=1.0): + return self.as_ccsd().as_cisd() class UCCSDTQ_WaveFunction(RCCSDTQ_WaveFunction): pass diff --git a/vayesta/ewf/fragment.py b/vayesta/ewf/fragment.py index 760d7d382..7d87a96f3 100644 --- a/vayesta/ewf/fragment.py +++ b/vayesta/ewf/fragment.py @@ -18,7 +18,7 @@ from vayesta.core.qemb import Fragment as BaseFragment from vayesta.solver import get_solver_class from vayesta.core.fragmentation import IAO_Fragmentation -from vayesta.core.types import RFCI_WaveFunction +from vayesta.core.types import RFCI_WaveFunction, RCCSDTQ_WaveFunction from vayesta.core.bath import BNO_Threshold from vayesta.core.bath import DMET_Bath @@ -69,6 +69,9 @@ class Fragment(BaseFragment): class Flags(BaseFragment.Flags): # Tailoring and external correction of CCSD external_corrections: Optional[List[typing.Any]] = dataclasses.field(default_factory=list) + # Whether to perform additional checks on external corrections + test_extcorr: bool = False + @dataclasses.dataclass class Results(BaseFragment.Results): @@ -131,7 +134,7 @@ def set_cas(self, iaos=None, c_occ=None, c_vir=None, minao='auto', dmet_threshol def tailor_with_fragments(self, fragments, projectors=1): return self.add_external_corrections(fragments, projectors=projectors) - def add_external_corrections(self, fragments, correction_type='tailor', projectors=1): + def add_external_corrections(self, fragments, correction_type='tailor', projectors=1, test_extcorr=False): """Add tailoring or external correction from other fragment solutions to CCSD solver. Parameters @@ -149,6 +152,8 @@ def add_external_corrections(self, fragments, correction_type='tailor', projecto projectors: int, optional Maximum number of projections applied to the occupied dimensions of the amplitude corrections. Default: 1. + test_extcorr: bool, optional + Whether to perform additional checks on the external corrections. """ if correction_type not in ('tailor', 'delta-tailor', 'external', 'external-fciv', 'external-ccsdv'): raise ValueError @@ -156,10 +161,12 @@ def add_external_corrections(self, fragments, correction_type='tailor', projecto raise RuntimeError self.flags.external_corrections.extend( [(f.id, correction_type, projectors) for f in fragments]) + self.flags.test_extcorr = test_extcorr def clear_external_corrections(self): """Remove all tailoring or external correction which were added via add_external_corrections.""" self.flags.external_corrections = [] + self.flags.test_extcorr = False def get_init_guess(self, init_guess, solver, cluster): # FIXME @@ -304,6 +311,9 @@ def kernel(self, solver=None, init_guess=None, eris=None): # Projection of FCI wave function is not implemented - convert to CISD if isinstance(wf, RFCI_WaveFunction): pwf = wf.as_cisd() + # Projection of CCSDTQ wave function is not implemented - convert to CCSD + elif isinstance(wf, RCCSDTQ_WaveFunction): + pwf = wf.as_ccsd() proj = self.get_overlap('frag|cluster-occ') pwf = pwf.project(proj, inplace=False) @@ -356,6 +366,7 @@ def get_solver_options(self, solver): elif solver.upper() == 'DUMP': solver_opts['filename'] = self.opts.solver_options['dumpfile'] solver_opts['external_corrections'] = self.flags.external_corrections + solver_opts['test_extcorr'] = self.flags.test_extcorr return solver_opts # --- Expectation values diff --git a/vayesta/solver/ccsd.py b/vayesta/solver/ccsd.py index 9b9713811..bd68316f3 100644 --- a/vayesta/solver/ccsd.py +++ b/vayesta/solver/ccsd.py @@ -47,6 +47,8 @@ class Options(ClusterSolver.Options): external_corrections: Optional[List[typing.Any]] = dataclasses.field(default_factory=list) # Lambda equations solve_lambda: bool = True + # Whether to perform additional checks on external corrections + test_extcorr: bool = False def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -178,7 +180,7 @@ def kernel(self, t1=None, t2=None, eris=None, l1=None, l2=None, seris_ov=None, c # External correction of T1 and T2 if externals: self.log.info("Externally correct CCSD from %d fragments", len(externals)) - self.set_callback(coupling.externally_correct(self, externals, eris=eris)) + self.set_callback(coupling.externally_correct(self, externals, eris=eris, test_extcorr=self.opts.test_extcorr)) elif self.opts.sc_mode and self.base.iteration > 1: raise NotImplementedError diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index d457cb0c4..1655b8a20 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -1,4 +1,6 @@ import numpy as np +import pyscf +from pyscf.lib import direct_sum from vayesta.core.ao2mo import helper as ao2mo_helper from vayesta.core.util import * from vayesta.core import spinalg @@ -291,16 +293,36 @@ def _integrals_for_extcorr(fragment, fock): raise NotImplementedError return fov, govov, gvvov, gooov, govoo -def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): - """Make T3 and T4 correction to CCSD wave function for given fragment. - If include_t3v, then these terms are included. If not, they are left out - (to be contracted later with cluster y integrals). +def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extcorr=False): + """Make T3 and T4 residual correction to CCSD wave function for given fragment. + Expressions consistent with J. Chem. Phys. 86, 2881 (1987): G. E. Scuseria et al. + and verified same behaviour as implementation in git@github.com:gustavojra/Methods.git + TODO + ---- + o Add Option: Contract T4's down at original solver point to save memory. + o UHF implementation - TODO: Option: Contract T4's down at original solver point to save memory. + Parameters + ---------- + fragment: Fragment class + FCI fragment with FCI, CISDTQ or CCSDTQ wave function object in results + fock: ndarray + Full system for matrix used for CCSD residuals + solver: Solver class + Used for logging options + include_t3v: Bool + If include_t3v, then these terms are included. If not, they are left out + (to be contracted later with cluster y integrals). + test_extcorr: Bool + Perform additional tests on expressions, comparing to the EC-CC implementation + with fully UHF T3 and T4 of Seunghoon Lee (https://github.com/seunghoonlee89/excc). - TO TEST: - Rotate (ov) space to check invariance? - Extensivity checks for separated fragments + Returns + ------- + dt1, dt2: ndarray + T1 and T2 expressions. + NOTE: These expressions still need to be contracted with energy denominators + for full amplitude updates. """ wf = fragment.results.wf.as_ccsdtq() @@ -326,6 +348,17 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # --- T3 * V dt1 -= einsum('ijab, jiupab -> up', spinned_antiphys_g, t3) + if test_extcorr: + # A useful intermediate is the t3_aaa. Construct this from t3 (_aba) mixed spin. + t3_aaa = t3 - t3.transpose(0,2,1,3,4,5) - t3.transpose(1,0,2,3,4,5) + t3_aab = t3.transpose(0,2,1,3,5,4) + dt1_test = einsum('kcld,iklacd->ia', govov, t3_aaa) + dt1_test += einsum('kcld,iklacd->ia', govov, t3_aab) + dt1_test += einsum('kcld,ilkadc->ia', govov, t3_aab) + dt1_test += einsum('kcld,klicda->ia', govov, t3_aab) + dt1_test *= 0.5 + assert(np.allclose(dt1_test, dt1)) + # --- T2 update # --- T3 * F if np.allclose(fov, np.zeros_like(fov)): @@ -335,6 +368,10 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # (Fb) (Tabb) contraction dt2 += einsum('me, jimbae -> ijab', fov, t3) solver.log.info("(T3 * F) -> T2 update norm from fragment {}: {}".format(fragment.id, np.linalg.norm(dt2))) + if test_extcorr: + t3tmp = t3_aab + t3_aab.transpose(0,2,1,3,5,4) + dt2_test = np.einsum('kc,kijcab->ijab', fov, t3tmp) + assert(np.allclose(dt2, dt2_test)) # --- T4 * V # (Vaa) (Tabaa) contraction @@ -343,6 +380,13 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # (Vab) (Tabab) contraction t4v += einsum('menf, ijmnabef -> ijab', govov, t4_abab) dt2 += t4v + if test_extcorr: + t4aaab = t4_abaa.transpose(0,2,3,1,4,6,7,5) + t4aabb = t4_abab.transpose(0,2,1,3,4,6,5,7) + tmp1 = t4aaab + t4aaab.transpose(0,1,3,2,4,5,7,6) + tmp1 += t4aabb.transpose(0,2,1,3,4,6,5,7) + tmp1 += t4aabb.transpose(1,2,0,3,5,6,4,7) + t4v_test = 0.5 * einsum('kcld,klijcdab->ijab', govov, tmp1) # --- (T1 T3) * V # Note: Approximate T1 by the CCSDTQ T1 amplitudes of this fragment. @@ -361,6 +405,19 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # apply permutation t1t3v += t1t3v.transpose(1,0,3,2) dt2 += t1t3v + if test_extcorr: + tmp2 = einsum('kdlc,id->kilc', govov, t1) + t1t3v_test = -einsum('kilc,lkjcab->ijab', tmp2, t3tmp) + tmp2 = einsum('kdlc,jd->kjlc', govov, t1) + t1t3v_test -= einsum('kjlc,likcab->ijab', tmp2, t3tmp) + tmp2 = -einsum('kcld,lb->kcbd', govov, t1) + t1t3v_test += einsum('kcbd,kijcad->ijab', tmp2, t3tmp) + tmp2 = -einsum('kcld,la->kcad', govov, t1) + t1t3v_test += einsum('kcad,kijcdb->ijab', tmp2, t3tmp) + tmp2 = 2*einsum('kcld,ld->kc', govov, t1) + tmp2 += -einsum('kdlc,ld->kc', govov, t1) + t1t3v_test += einsum('kc,kijcab->ijab', tmp2, t3tmp) + assert(np.allclose(t1t3v_test, t1t3v)) # --- T3 * V if include_t3v: @@ -381,6 +438,13 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): # Permutation t3v += t3v.transpose(1,0,3,2) dt2 += t3v + if test_extcorr: + govvv = gvvov.transpose(2,3,0,1) + t3v_test = -einsum('kilc,lkjcab->ijab', gooov, t3tmp) + t3v_test -= einsum('kjlc,likcab->ijab', gooov, t3tmp) + t3v_test += einsum('kcbd,kijcad->ijab', govvv, t3tmp) + t3v_test += einsum('kcad,kijcdb->ijab', govvv, t3tmp) + assert(np.allclose(t3v_test, t3v)) elif fragment.base.spinsym == 'unrestricted': raise NotImplementedError @@ -489,7 +553,7 @@ def _get_delta_t_for_delta_tailor(fragment, fock): return dt1, dt2 -def externally_correct(solver, external_corrections, eris=None): +def externally_correct(solver, external_corrections, eris=None, test_extcorr=False): """Build callback function for CCSD, to add external correction from other fragments. TODO: combine with `tailor_with_fragments`? @@ -507,6 +571,9 @@ def externally_correct(solver, external_corrections, eris=None): If not passed in, MO energy if needed will be constructed from the diagonal of get_fock() of embedding base class, and the eris will be also be obtained from the embedding base class. Optional. + test_extcorr: Bool + Perform additional tests on correctness of contractions, comparing to an alternative + implementation. Optional. Returns ------- @@ -567,9 +634,9 @@ def externally_correct(solver, external_corrections, eris=None): assert (y != fx.id) if corrtype in ['external', 'external-fciv']: - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=True) + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=True, test_extcorr=test_extcorr) elif corrtype == 'external-ccsdv': - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=False) + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=False, test_extcorr=test_extcorr) elif corrtype == 'delta-tailor': dt1y, dt2y = _get_delta_t_for_delta_tailor(fy, fock) else: @@ -610,8 +677,7 @@ def externally_correct(solver, external_corrections, eris=None): eia = mo_energy[:nocc, None] - mo_energy[None, nocc:] # TODO: Not the most memory efficient way to contract with # energy denominators here. Improve to reduce N^4 memory cost? - eijab = mo_energy[:nocc, None, None, None] + mo_energy[None, :nocc, None, None] \ - - mo_energy[None, None, nocc:, None] - mo_energy[None, None, None, nocc:] + eijab = pyscf.lib.direct_sum('ia,jb->ijab',eia,eia) dt1 /= eia dt2 /= eijab From 15d4fbf9f08e5f962677bc70744cde1cc31a0615 Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 18 Nov 2022 15:45:29 +0000 Subject: [PATCH 15/66] Passed in ERIs sometimes fails, as they are stored as HDF5 file, rather than ndarray. Rather than get from HDF5 file, just use try/except block for the time being, and fix properly later...(presume whether it stores as ndarray or hdf5 will depend on what it thinks is available memory). --- vayesta/solver/coupling.py | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 1655b8a20..490788ce1 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -610,9 +610,13 @@ def externally_correct(solver, external_corrections, eris=None, test_extcorr=Fal _, _, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) else: if emb.spinsym == 'restricted': - gvvov_x = ao2mo_helper.get_ovvv(eris).transpose(2,3,0,1) - gooov_x = eris.ovoo.transpose(2,3,0,1) - govoo_x = eris.ovoo + try: + # TODO: Sort this out for when integrals are stored in HDF5 files + gvvov_x = ao2mo_helper.get_ovvv(eris).transpose(2,3,0,1) + gooov_x = eris.ovoo.transpose(2,3,0,1) + govoo_x = eris.ovoo + except: + _, _, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) elif emb.spinsym == 'unrestricted': raise NotImplementedError @@ -666,8 +670,8 @@ def externally_correct(solver, external_corrections, eris=None, test_extcorr=Fal dt2y_t3v = _get_delta_t2_from_t3v(gvvov_x, gooov_x, govoo_x, fy, rxy_occ, rxy_vir, cxs_occ, projectors) dt2 = spinalg.add(dt2, dt2y_t3v) - solver.log.info("External correction residuals from fragment %3d (%s): dT1= %.3e dT2= %.3e", - fy.id, fy.solver, *get_amplitude_norm(dt1y, dt2y)) + solver.log.info("External correction residuals from fragment %3d (%s via %s): dT1= %.3e dT2= %.3e", + fy.id, fy.solver, corrtype, *get_amplitude_norm(dt1y, dt2y)) if solver.spinsym == 'restricted': From 31f5b79ae39c858128d33860a5f5ca40b6cfb7c2 Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 18 Nov 2022 15:46:40 +0000 Subject: [PATCH 16/66] Add tests for external correction, including Hubbard model and LiH (where results should be exact due to complete FCI fragment), and regression tests on water. --- vayesta/tests/ewf/test_extcorr.py | 199 ++++++++++++++++++++++++++++++ 1 file changed, 199 insertions(+) create mode 100644 vayesta/tests/ewf/test_extcorr.py diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py new file mode 100644 index 000000000..39adfd1eb --- /dev/null +++ b/vayesta/tests/ewf/test_extcorr.py @@ -0,0 +1,199 @@ +import pytest +import unittest +import numpy as np + +import pyscf +import pyscf.cc + +import vayesta +import vayesta.ewf + +from vayesta.tests.common import TestCase +from vayesta.tests import testsystems + + +@pytest.mark.fast +class TestSolvers(TestCase): + + def _test(self, key, proj=0, mode='external-fciv', store_wf_ccsdtq=True): + mf = getattr(getattr(testsystems, key[0]), key[1])() + + emb = vayesta.ewf.EWF(mf) + with emb.iao_fragmentation() as f: + if store_wf_ccsdtq: + fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full'), store_wf_type='CCSDTQ') + else: + fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full')) + ccsd = f.add_atomic_fragment([0], solver='CCSD', bath_options=dict(bathtype='full'), active=False) + ccsd2 = f.add_atomic_fragment([1], solver='CCSD', bath_options=dict(bathtype='full'), active=False) + emb.kernel() + fci_frag_ecorr = emb.e_corr + fci_frag_etot = emb.e_tot + + fci_frag.active = False + ccsd.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) + ccsd.active=True + ccsd2.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) + ccsd2.active=True + emb.kernel() + + fci = pyscf.fci.FCI(mf) + fci.threads = 1 + fci.conv_tol = 1e-12 + fci.davidson_only = True + fci.kernel() + + self.assertAlmostEqual(fci_frag_ecorr, fci.e_tot - mf.e_tot) + self.assertAlmostEqual(fci_frag_etot, fci.e_tot) + self.assertAlmostEqual(emb.e_corr, fci_frag_ecorr) + self.assertAlmostEqual(emb.e_tot, fci_frag_etot) + + # Test all combinations of options + def test_r_exact_ec_lih_proj0_fciv_store(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=True) + def test_r_exact_ec_lih_proj1_fciv_store(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=True) + def test_r_exact_ec_lih_proj2_fciv_store(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=True) + def test_r_exact_ec_lih_proj0_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=False) + def test_r_exact_ec_lih_proj1_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=False) + def test_r_exact_ec_lih_proj2_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=False) + def test_r_exact_ec_lih_proj0_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_r_exact_ec_lih_proj1_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_r_exact_ec_lih_proj2_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_r_exact_ec_lih_proj0_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=False) + def test_r_exact_ec_lih_proj1_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=False) + def test_r_exact_ec_lih_proj2_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=False) + + def _test_10_u4_2imp(self, mode, proj): + """Tests for N=10 U=4 Hubbard model with double site CCSD impurities + and complete FCI fragment + """ + + mf = testsystems.hubb_10_u4.rhf() + + emb = vayesta.ewf.EWF(mf) + with emb.site_fragmentation() as f: + fci_frag = f.add_atomic_fragment(list(range(10)), solver='FCI', store_wf_type='CCSDTQ') + ccsd_frag = f.add_atomic_fragment([0, 1], solver='CCSD', bath_options=dict(bathtype='full'), active=False) + ccsd_frag.add_tsymmetric_fragments(tvecs=[5, 1, 1]) + emb.kernel() + fci_frag_ecorr = emb.e_corr + fci_frag_etot = emb.e_tot + + fci_frag.active = False + ccsd_frag.active = True + ccsd_frag.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) + emb.kernel() + + fci = pyscf.fci.FCI(mf) + fci.threads = 1 + fci.conv_tol = 1e-12 + fci.davidson_only = True + fci.kernel() + + self.assertAlmostEqual(fci_frag_ecorr, fci.e_tot - mf.e_tot) + self.assertAlmostEqual(fci_frag_etot, fci.e_tot) + self.assertAlmostEqual(emb.e_corr, fci_frag_ecorr) + self.assertAlmostEqual(emb.e_tot, fci_frag_etot) + + def test_hub_ec_2imp_proj0_ccsdv(self): + return self._test_10_u4_2imp(mode='external-ccsdv', proj=0) + def test_hub_ec_2imp_proj1_ccsdv(self): + return self._test_10_u4_2imp(mode='external-ccsdv', proj=1) + def test_hub_ec_2imp_proj2_ccsdv(self): + return self._test_10_u4_2imp(mode='external-ccsdv', proj=2) + def test_hub_ec_2imp_proj0_fciv(self): + return self._test_10_u4_2imp(mode='external-fciv', proj=0) + def test_hub_ec_2imp_proj1_fciv(self): + return self._test_10_u4_2imp(mode='external-fciv', proj=1) + def test_hub_ec_2imp_proj2_fciv(self): + return self._test_10_u4_2imp(mode='external-fciv', proj=2) + + def _test_10_u4_2impfci(self, mode): + """Tests for N=10 U=4 Hubbard model with double site CCSD impurities + and 2-site FCI fragment (but complete bath). With no projectors on + external correction, should still be exact. + """ + + mf = testsystems.hubb_10_u2.rhf() + + emb = vayesta.ewf.EWF(mf) + with emb.site_fragmentation() as f: + fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full'), store_wf_type='CCSDTQ') + ccsd_frag = f.add_atomic_fragment([0, 1], solver='CCSD', bath_options=dict(bathtype='full'), active=False) + ccsd_frag.add_tsymmetric_fragments(tvecs=[5, 1, 1]) + emb.kernel() + + fci_frag.active = False + ccsd_frag.active = True + # Given the complete bath of the FCI fragment, should still be exact + ccsd_frag.add_external_corrections([fci_frag], correction_type=mode, projectors=0, test_extcorr=True) + emb.kernel() + + fci = pyscf.fci.FCI(mf) + fci.threads = 1 + fci.conv_tol = 1e-12 + fci.davidson_only = True + fci.kernel() + + self.assertAlmostEqual(emb.e_corr, fci.e_tot - mf.e_tot) + self.assertAlmostEqual(emb.e_tot, fci.e_tot) + + def test_hub_ec_2impfci_proj0_fciv(self): + return self._test_10_u4_2impfci(mode='external-fciv') + def test_hub_ec_2impfci_proj0_ccsdv(self): + return self._test_10_u4_2impfci(mode='external-ccsdv') + + def _test_water_ec_regression(self, mode=None, projectors=None): + + mf = testsystems.water_ccpvdz_df.rhf() + + emb = vayesta.ewf.EWF(mf) + fci_frags = [] + with emb.iao_fragmentation() as f: + fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ') + ccsd_frags = f.add_all_atomic_fragments(solver='CCSD', bath_options=dict(bathtype='full'), active=False) + emb.kernel() + + for fci_frag in fci_frags: + fci_frag.active = False + + for ccsd_frag in ccsd_frags: + ccsd_frag.active = True + ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors, test_extcorr=True) + + emb.kernel() + return emb.e_tot + + def test_water_ec_regression_proj0_fciv(self): + e_tot = self._test_water_ec_regression(mode='external-fciv', projectors=0) + self.assertAlmostEqual(e_tot, -76.2402530047042) + def test_water_ec_regression_proj0_ccsdv(self): + e_tot = self._test_water_ec_regression(mode='external-ccsdv', projectors=0) + self.assertAlmostEqual(e_tot, -76.24018922136538) + def test_water_ec_regression_proj1_fciv(self): + e_tot = self._test_water_ec_regression(mode='external-fciv', projectors=1) + self.assertAlmostEqual(e_tot, -76.24022612405739) + def test_water_ec_regression_proj1_ccsdv(self): + e_tot = self._test_water_ec_regression(mode='external-ccsdv', projectors=1) + self.assertAlmostEqual(e_tot, -76.24017967220551) + def test_water_ec_regression_proj2_fciv(self): + e_tot = self._test_water_ec_regression(mode='external-fciv', projectors=2) + self.assertAlmostEqual(e_tot, -76.24020498388937) + def test_water_ec_regression_proj2_ccsdv(self): + e_tot = self._test_water_ec_regression(mode='external-ccsdv', projectors=2) + self.assertAlmostEqual(e_tot, -76.24017093290053) + +if __name__ == '__main__': + print('Running %s' % __file__) + unittest.main() From befe789c0f54c3f2a7d0207ac2078f368df5dc3d Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 18 Nov 2022 16:24:50 +0000 Subject: [PATCH 17/66] Add example of EC-CCSD via local FCI clusters, both for a full system CCSD calculation, and a fragmented CCSD calculation. --- .../ewf/molecules/25-externally-correct.py | 68 +++++++++++++++++++ 1 file changed, 68 insertions(+) create mode 100644 examples/ewf/molecules/25-externally-correct.py diff --git a/examples/ewf/molecules/25-externally-correct.py b/examples/ewf/molecules/25-externally-correct.py new file mode 100644 index 000000000..7cc120ecf --- /dev/null +++ b/examples/ewf/molecules/25-externally-correct.py @@ -0,0 +1,68 @@ +import numpy as np +import pyscf +import pyscf.gto +import pyscf.scf +import pyscf.cc +import pyscf.fci +import vayesta +import vayesta.ewf +from vayesta.misc import molecules + +mol = pyscf.gto.Mole() +mol.atom = """ +Se 0.0000 0.0000 0.2807 +O 0.0000 1.3464 -0.5965 +O 0.0000 -1.3464 -0.5965 +""" +mol.basis = 'cc-pVDZ' +mol.output = 'pyscf.out' +mol.build() + +# Hartree-Fock +mf = pyscf.scf.RHF(mol) +mf.kernel() + +# Reference full system CCSD: +cc = pyscf.cc.CCSD(mf) +cc.kernel() + +# 1) Consider setup where you have a complete CCSD, externally corrected by local atomic fragment+DMET FCI clusters +emb = vayesta.ewf.EWF(mf) +with emb.iao_fragmentation() as f: + # Add all atomic FCI fragments with DMET bath + # Store the FCI wave functions as CCSDTQ types, so they can be used for correction later. + fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ') + # Add single 'complete' CCSD fragment covering all IAOs, but set as inactive + ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), active=False) +emb.kernel() +# Switch active <-> inactive fragments, and run the full system CCSD fragment, applying external correction +for fci_frag in fci_frags: + fci_frag.active = False +ccsd_frag.active = True +# Setup the external correction from the FCI fragments. +# Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the +# T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is +# larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). +# The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). +# The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less +# 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) +# Run kernel again +emb.kernel() +print('Total energy from full system CCSD tailored (CCSD Coulomb interaction) by atomic FCI fragments (projectors=1): {}'.format(emb.e_tot)) + +# 2) Now, we also fragment the CCSD spaces, and use BNOs. These CCSD fragments are individually externally corrected from the FCI clusters. +# Similar set up, but we now have multiple CCSD clusters. +emb = vayesta.ewf.EWF(mf) +with emb.iao_fragmentation() as f: + fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ') + ccsd_frags = f.add_all_atomic_fragments(solver='CCSD', bath_options=dict(bathtype='mp2', threshold=1.e-5), active=False) +emb.kernel() +for fci_frag in fci_frags: + fci_frag.active = False +for ccsd_frag in ccsd_frags: + ccsd_frag.active = True + # Now add external corrections to all CCSD clusters, and use 'external-fciv' correction, with 2 projectors + ccsd_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=2) +emb.kernel() +print('Total energy from embedded CCSD tailored (FCI Coulomb interaction) by atomic FCI fragments (projectors=2): {}'.format(emb.e_tot)) From 4b45e160188a6633013d4267385f02bdc2b36fd1 Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 18 Nov 2022 18:04:02 +0000 Subject: [PATCH 18/66] Add example of various external corrections on the Hubbard model. Will tidy it up, as a little long and should be modularized. Also little confused as to why TCC != Emb. FCI, as we saw previously - needs a little more investigation. Finally, need to check on translational symmetry of FCI clusters, which will also improve this example --- examples/ewf/molecules/04-bath-options.py | 1 - .../ewf/molecules/25-externally-correct.py | 2 +- examples/ewf/other/61-ext-corr-hubbard-1D.py | 134 ++++++++++++++++++ vayesta/tests/ewf/test_extcorr.py | 2 + 4 files changed, 137 insertions(+), 2 deletions(-) create mode 100644 examples/ewf/other/61-ext-corr-hubbard-1D.py diff --git a/examples/ewf/molecules/04-bath-options.py b/examples/ewf/molecules/04-bath-options.py index 2f2433a6d..25a37f332 100644 --- a/examples/ewf/molecules/04-bath-options.py +++ b/examples/ewf/molecules/04-bath-options.py @@ -48,7 +48,6 @@ emb_mp2_projdmet = vayesta.ewf.EWF(mf, bath_options=dict(bathtype='mp2', threshold=1e-4, \ project_dmet_order=2, project_dmet_mode='squared-entropy')) emb_mp2_projdmet.kernel() -1./0 # Use maximally R^2-localized bath orbitals: # rcut is the cutoff distance in Angstrom diff --git a/examples/ewf/molecules/25-externally-correct.py b/examples/ewf/molecules/25-externally-correct.py index 7cc120ecf..e23680f1f 100644 --- a/examples/ewf/molecules/25-externally-correct.py +++ b/examples/ewf/molecules/25-externally-correct.py @@ -39,7 +39,7 @@ for fci_frag in fci_frags: fci_frag.active = False ccsd_frag.active = True -# Setup the external correction from the FCI fragments. +# Setup the external correction from the CCSD fragments. # Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the # T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is # larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). diff --git a/examples/ewf/other/61-ext-corr-hubbard-1D.py b/examples/ewf/other/61-ext-corr-hubbard-1D.py new file mode 100644 index 000000000..30b371dc0 --- /dev/null +++ b/examples/ewf/other/61-ext-corr-hubbard-1D.py @@ -0,0 +1,134 @@ +import pyscf +import pyscf.cc +import pyscf.fci +import vayesta +import vayesta.ewf +import vayesta.lattmod + +nsite = 10 +nelectron = nsite + 4 +hubbard_u = 4.0 +mol = vayesta.lattmod.Hubbard1D(nsite, nelectron=nelectron, hubbard_u=hubbard_u) +mf = vayesta.lattmod.LatticeMF(mol) +mf.kernel() +assert(mf.converged) + +# Reference full system CCSD and FCI +cc = pyscf.cc.CCSD(mf) +cc.kernel() +fci = pyscf.fci.FCI(mf) +fci.threads = 1 +fci.conv_tol = 1e-12 +fci.davidson_only = True +fci.kernel() + +# Perform embedded FCI with two sites +emb_simp = vayesta.ewf.EWF(mf, solver='FCI', bath_options=dict(bathtype='dmet')) +with emb_simp.site_fragmentation() as f: + f.add_atomic_fragment([0, 1], sym_factor=nsite/2, nelectron_target=2*nelectron/nsite) +emb_simp.kernel() + +# Perform full system CCSD, externally corrected by two-site+DMET bath FCI level clusters +emb = vayesta.ewf.EWF(mf) +fci_frags = [] +with emb.site_fragmentation() as f: + # Set up a two-site FCI fragmentation of full system + # Ensure the right number of electrons on each fragment space of the FCI calculation. + fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) + fci_frags.append(f.add_atomic_fragment([2, 3], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) + fci_frags.append(f.add_atomic_fragment([4, 5], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) + fci_frags.append(f.add_atomic_fragment([6, 7], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) + fci_frags.append(f.add_atomic_fragment([8, 9], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) + # Add single 'complete' CCSD fragment covering all sites (currently inactive) + ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), solver_options=dict(solve_lambda=False), active=False) +# FCI fragment symmetry not available for external correction +#fci_frags = fci_frags.add_tsymmetric_fragments(tvecs=[5, 1, 1]) +emb.kernel() + +for fci_frag in fci_frags: + fci_frag.active = False +ccsd_frag.active = True +# Setup the external correction from the CCSD fragments. +# Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the +# T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is +# larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). +# NOTE however that the Hubbard model only has local interactions, so these should be identical. +# The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). +# The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less +# 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=0) +# Run kernel again +emb.kernel() +e_ccsdv = [] +e_ccsdv.append(emb.e_tot) + +# Change number of projectors and/or Coulomb type, and re-run +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) +emb.kernel() +e_ccsdv.append(emb.e_tot) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=2) +emb.kernel() +e_ccsdv.append(emb.e_tot) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=0) +emb.kernel() +e_fciv = [] +e_fciv.append(emb.e_tot) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) +emb.kernel() +e_fciv.append(emb.e_tot) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=2) +emb.kernel() +e_fciv.append(emb.e_tot) + +# Compare to a simpler tailoring +e_tailor = [] +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='tailor', projectors=0) +emb.kernel() +e_tailor.append(emb.e_tot) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='tailor', projectors=1) +emb.kernel() +e_tailor.append(emb.e_tot) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='tailor', projectors=2) +emb.kernel() +e_tailor.append(emb.e_tot) + +# Compare to a delta-tailoring, where the correction is the difference between full-system +# CCSD and CCSD in the FCI cluster. +e_dtailor = [] +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='delta-tailor', projectors=0) +emb.kernel() +e_dtailor.append(emb.e_tot) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='delta-tailor', projectors=1) +emb.kernel() +e_dtailor.append(emb.e_tot) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='delta-tailor', projectors=2) +emb.kernel() +e_dtailor.append(emb.e_tot) + +print("E(MF)= %+16.8f Ha" % (mf.e_tot/nsite)) +print("E(CCSD)= %+16.8f Ha" % (cc.e_tot/nsite)) +print("E(FCI)= %+16.8f Ha" % (fci.e_tot/nsite)) +print("E(Emb. FCI, 2-site)= %+16.8f Ha" % (emb_simp.e_tot/nsite)) +print("E(EC-CCSD, 2-site FCI, 0 proj, ccsd V)= %+16.8f Ha" % (e_ccsdv[0]/nsite)) +print("E(EC-CCSD, 2-site FCI, 1 proj, ccsd V)= %+16.8f Ha" % (e_ccsdv[1]/nsite)) +print("E(EC-CCSD, 2-site FCI, 2 proj, ccsd V)= %+16.8f Ha" % (e_ccsdv[2]/nsite)) +print("E(EC-CCSD, 2-site FCI, 0 proj, fci V)= %+16.8f Ha" % (e_fciv[0]/nsite)) +print("E(EC-CCSD, 2-site FCI, 1 proj, fci V)= %+16.8f Ha" % (e_fciv[1]/nsite)) +print("E(EC-CCSD, 2-site FCI, 2 proj, fci V)= %+16.8f Ha" % (e_fciv[2]/nsite)) +print("E(T-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha" % (e_tailor[0]/nsite)) +print("E(T-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha" % (e_tailor[1]/nsite)) +print("E(T-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha" % (e_tailor[2]/nsite)) +print("E(DT-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha" % (e_dtailor[0]/nsite)) +print("E(DT-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha" % (e_dtailor[1]/nsite)) +print("E(DT-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha" % (e_dtailor[2]/nsite)) diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index 39adfd1eb..858b83da1 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -149,6 +149,8 @@ def _test_10_u4_2impfci(self, mode): self.assertAlmostEqual(emb.e_corr, fci.e_tot - mf.e_tot) self.assertAlmostEqual(emb.e_tot, fci.e_tot) + # Also check the use of symmetry here... + def test_hub_ec_2impfci_proj0_fciv(self): return self._test_10_u4_2impfci(mode='external-fciv') def test_hub_ec_2impfci_proj0_ccsdv(self): From d46d0db423a913fe23b1029dcae732a1bd119539 Mon Sep 17 00:00:00 2001 From: George Booth Date: Sun, 20 Nov 2022 10:56:26 +0000 Subject: [PATCH 19/66] Clean up ext-corr hubbard example --- examples/ewf/other/61-ext-corr-hubbard-1D.py | 107 +++++++------------ 1 file changed, 39 insertions(+), 68 deletions(-) diff --git a/examples/ewf/other/61-ext-corr-hubbard-1D.py b/examples/ewf/other/61-ext-corr-hubbard-1D.py index 30b371dc0..d9f878e15 100644 --- a/examples/ewf/other/61-ext-corr-hubbard-1D.py +++ b/examples/ewf/other/61-ext-corr-hubbard-1D.py @@ -45,87 +45,58 @@ #fci_frags = fci_frags.add_tsymmetric_fragments(tvecs=[5, 1, 1]) emb.kernel() -for fci_frag in fci_frags: - fci_frag.active = False -ccsd_frag.active = True -# Setup the external correction from the CCSD fragments. -# Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the -# T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is -# larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). -# NOTE however that the Hubbard model only has local interactions, so these should be identical. -# The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). -# The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less -# 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=0) -# Run kernel again -emb.kernel() -e_ccsdv = [] -e_ccsdv.append(emb.e_tot) +def ext_corr(emb_, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): + """Setup the external correction from the CCSD fragments. + Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the + T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is + larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). + NOTE however that the Hubbard model only has local interactions, so these should be identical. + The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). + The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less + 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. + """ -# Change number of projectors and/or Coulomb type, and re-run -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) -emb.kernel() -e_ccsdv.append(emb.e_tot) -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=2) -emb.kernel() -e_ccsdv.append(emb.e_tot) -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=0) -emb.kernel() -e_fciv = [] -e_fciv.append(emb.e_tot) -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) -emb.kernel() -e_fciv.append(emb.e_tot) -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=2) -emb.kernel() -e_fciv.append(emb.e_tot) + ccsd_frag.clear_external_corrections() # Clear any previous corrections applied + for fci_frag in fci_frags: + fci_frag.active = False + ccsd_frag.active = True + ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors) + # Run kernel again + emb_.kernel() + return emb_.e_tot + +# Change number of projectors and/or Coulomb type, and re-run to get change +e_extcorr = [] +e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0)) +e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=1)) +e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=2)) +e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=0)) +e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=1)) +e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=1)) # Compare to a simpler tailoring e_tailor = [] -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='tailor', projectors=0) -emb.kernel() -e_tailor.append(emb.e_tot) -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='tailor', projectors=1) -emb.kernel() -e_tailor.append(emb.e_tot) -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='tailor', projectors=2) -emb.kernel() -e_tailor.append(emb.e_tot) +e_tailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=0)) +e_tailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=1)) +e_tailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=2)) # Compare to a delta-tailoring, where the correction is the difference between full-system # CCSD and CCSD in the FCI cluster. e_dtailor = [] -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='delta-tailor', projectors=0) -emb.kernel() -e_dtailor.append(emb.e_tot) -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='delta-tailor', projectors=1) -emb.kernel() -e_dtailor.append(emb.e_tot) -ccsd_frag.clear_external_corrections() -ccsd_frag.add_external_corrections(fci_frags, correction_type='delta-tailor', projectors=2) -emb.kernel() -e_dtailor.append(emb.e_tot) +e_dtailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=0)) +e_dtailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=1)) +e_dtailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=2)) print("E(MF)= %+16.8f Ha" % (mf.e_tot/nsite)) print("E(CCSD)= %+16.8f Ha" % (cc.e_tot/nsite)) print("E(FCI)= %+16.8f Ha" % (fci.e_tot/nsite)) print("E(Emb. FCI, 2-site)= %+16.8f Ha" % (emb_simp.e_tot/nsite)) -print("E(EC-CCSD, 2-site FCI, 0 proj, ccsd V)= %+16.8f Ha" % (e_ccsdv[0]/nsite)) -print("E(EC-CCSD, 2-site FCI, 1 proj, ccsd V)= %+16.8f Ha" % (e_ccsdv[1]/nsite)) -print("E(EC-CCSD, 2-site FCI, 2 proj, ccsd V)= %+16.8f Ha" % (e_ccsdv[2]/nsite)) -print("E(EC-CCSD, 2-site FCI, 0 proj, fci V)= %+16.8f Ha" % (e_fciv[0]/nsite)) -print("E(EC-CCSD, 2-site FCI, 1 proj, fci V)= %+16.8f Ha" % (e_fciv[1]/nsite)) -print("E(EC-CCSD, 2-site FCI, 2 proj, fci V)= %+16.8f Ha" % (e_fciv[2]/nsite)) +print("E(EC-CCSD, 2-site FCI, 0 proj, ccsd V)= %+16.8f Ha" % (e_extcorr[0]/nsite)) +print("E(EC-CCSD, 2-site FCI, 1 proj, ccsd V)= %+16.8f Ha" % (e_extcorr[1]/nsite)) +print("E(EC-CCSD, 2-site FCI, 2 proj, ccsd V)= %+16.8f Ha" % (e_extcorr[2]/nsite)) +print("E(EC-CCSD, 2-site FCI, 0 proj, fci V)= %+16.8f Ha" % (e_extcorr[0]/nsite)) +print("E(EC-CCSD, 2-site FCI, 1 proj, fci V)= %+16.8f Ha" % (e_extcorr[1]/nsite)) +print("E(EC-CCSD, 2-site FCI, 2 proj, fci V)= %+16.8f Ha" % (e_extcorr[2]/nsite)) print("E(T-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha" % (e_tailor[0]/nsite)) print("E(T-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha" % (e_tailor[1]/nsite)) print("E(T-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha" % (e_tailor[2]/nsite)) From 87d34bdfadce508fbd080414758eb296cc27022c Mon Sep 17 00:00:00 2001 From: George Booth Date: Mon, 21 Nov 2022 10:03:55 +0000 Subject: [PATCH 20/66] Allow external correction to be used along with scmf --- examples/ewf/other/61-ext-corr-hubbard-1D.py | 6 ++-- vayesta/core/qemb/fragment.py | 31 +++++++++++--------- vayesta/core/scmf/scmf.py | 3 +- 3 files changed, 22 insertions(+), 18 deletions(-) diff --git a/examples/ewf/other/61-ext-corr-hubbard-1D.py b/examples/ewf/other/61-ext-corr-hubbard-1D.py index d9f878e15..66c59382c 100644 --- a/examples/ewf/other/61-ext-corr-hubbard-1D.py +++ b/examples/ewf/other/61-ext-corr-hubbard-1D.py @@ -45,7 +45,7 @@ #fci_frags = fci_frags.add_tsymmetric_fragments(tvecs=[5, 1, 1]) emb.kernel() -def ext_corr(emb_, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): +def ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): """Setup the external correction from the CCSD fragments. Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is @@ -62,8 +62,8 @@ def ext_corr(emb_, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): ccsd_frag.active = True ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors) # Run kernel again - emb_.kernel() - return emb_.e_tot + emb.kernel() + return emb.e_tot # Change number of projectors and/or Coulomb type, and re-run to get change e_extcorr = [] diff --git a/vayesta/core/qemb/fragment.py b/vayesta/core/qemb/fragment.py index c5eabf4d6..84482c65b 100644 --- a/vayesta/core/qemb/fragment.py +++ b/vayesta/core/qemb/fragment.py @@ -329,20 +329,23 @@ def cluster(self, value): raise RuntimeError("Cannot set attribute cluster in symmetry derived fragment.") self._cluster = value - def reset(self, reset_bath=True, reset_cluster=True, reset_eris=True): - self.log.debugv("Resetting %s (reset_bath= %r, reset_cluster= %r, reset_eris= %r)", - self, reset_bath, reset_cluster, reset_eris) - if reset_bath: - self._dmet_bath = None - self._bath_factory_occ = None - self._bath_factory_vir = None - if reset_cluster: - self._cluster = None - self.get_overlap.cache_clear() - if reset_eris: - self._eris = None - self._seris_ov = None - self._results = None + def reset(self, reset_bath=True, reset_cluster=True, reset_eris=True, reset_inactive=True): + self.log.debugv("Resetting %s (reset_bath= %r, reset_cluster= %r, reset_eris= %r, reset_inactive= %r)", + self, reset_bath, reset_cluster, reset_eris, reset_inactive) + if not reset_inactive and not self.active: + return + else: + if reset_bath: + self._dmet_bath = None + self._bath_factory_occ = None + self._bath_factory_vir = None + if reset_cluster: + self._cluster = None + self.get_overlap.cache_clear() + if reset_eris: + self._eris = None + self._seris_ov = None + self._results = None def get_fragments_with_overlap(self, tol=1e-8, **kwargs): """Get list of fragments which overlap both in occupied and virtual space.""" diff --git a/vayesta/core/scmf/scmf.py b/vayesta/core/scmf/scmf.py index d53a6f015..23f122782 100644 --- a/vayesta/core/scmf/scmf.py +++ b/vayesta/core/scmf/scmf.py @@ -85,7 +85,8 @@ def kernel(self, *args, **kwargs): self.log.info("%s==============", len(self.name)*"=") if self.iteration > 1: - self.emb.reset() + # Don't reset inactive clusters for external corrections + self.emb.reset(reset_inactive=False) # Run clusters, save results res = self.kernel_orig(*args, **kwargs) From 75103a7febaecf6d3940ea082e00d0bef996873b Mon Sep 17 00:00:00 2001 From: George Booth Date: Mon, 21 Nov 2022 15:54:25 +0000 Subject: [PATCH 21/66] Update Hubbard EC-CC example to print out whether converged. --- examples/ewf/other/61-ext-corr-hubbard-1D.py | 85 ++++++++++++-------- 1 file changed, 51 insertions(+), 34 deletions(-) diff --git a/examples/ewf/other/61-ext-corr-hubbard-1D.py b/examples/ewf/other/61-ext-corr-hubbard-1D.py index 66c59382c..2db3e5aeb 100644 --- a/examples/ewf/other/61-ext-corr-hubbard-1D.py +++ b/examples/ewf/other/61-ext-corr-hubbard-1D.py @@ -6,8 +6,8 @@ import vayesta.lattmod nsite = 10 -nelectron = nsite + 4 -hubbard_u = 4.0 +nelectron = nsite +hubbard_u = 5.0 mol = vayesta.lattmod.Hubbard1D(nsite, nelectron=nelectron, hubbard_u=hubbard_u) mf = vayesta.lattmod.LatticeMF(mol) mf.kernel() @@ -40,17 +40,17 @@ fci_frags.append(f.add_atomic_fragment([6, 7], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) fci_frags.append(f.add_atomic_fragment([8, 9], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) # Add single 'complete' CCSD fragment covering all sites (currently inactive) - ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), solver_options=dict(solve_lambda=False), active=False) + ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), solver_options=dict(solve_lambda=False, init_guess='CISD'), active=False) # FCI fragment symmetry not available for external correction #fci_frags = fci_frags.add_tsymmetric_fragments(tvecs=[5, 1, 1]) emb.kernel() +assert(emb.converged) def ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): """Setup the external correction from the CCSD fragments. Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). - NOTE however that the Hubbard model only has local interactions, so these should be identical. The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. @@ -63,43 +63,60 @@ def ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors) # Run kernel again emb.kernel() - return emb.e_tot + return emb.e_tot, emb.converged -# Change number of projectors and/or Coulomb type, and re-run to get change e_extcorr = [] -e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0)) -e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=1)) -e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=2)) -e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=0)) -e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=1)) -e_extcorr.append(ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=1)) +extcorr_conv = [] +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0) +e_extcorr.append(e); extcorr_conv.append(conv) +# Change number of projectors and/or Coulomb type, and re-run to get change +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0) +e_extcorr.append(e); extcorr_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=1) +e_extcorr.append(e); extcorr_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=2) +e_extcorr.append(e); extcorr_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=0) +e_extcorr.append(e); extcorr_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=1) +e_extcorr.append(e); extcorr_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=1) +e_extcorr.append(e); extcorr_conv.append(conv) # Compare to a simpler tailoring e_tailor = [] -e_tailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=0)) -e_tailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=1)) -e_tailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=2)) +tailor_conv = [] +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=0) +e_tailor.append(e) ; tailor_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=1) +e_tailor.append(e) ; tailor_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=2) +e_tailor.append(e) ; tailor_conv.append(conv) # Compare to a delta-tailoring, where the correction is the difference between full-system # CCSD and CCSD in the FCI cluster. e_dtailor = [] -e_dtailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=0)) -e_dtailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=1)) -e_dtailor.append(ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=2)) +dtailor_conv = [] +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=0) +e_dtailor.append(e) ; dtailor_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=1) +e_dtailor.append(e) ; dtailor_conv.append(conv) +e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=2) +e_dtailor.append(e) ; dtailor_conv.append(conv) -print("E(MF)= %+16.8f Ha" % (mf.e_tot/nsite)) -print("E(CCSD)= %+16.8f Ha" % (cc.e_tot/nsite)) -print("E(FCI)= %+16.8f Ha" % (fci.e_tot/nsite)) -print("E(Emb. FCI, 2-site)= %+16.8f Ha" % (emb_simp.e_tot/nsite)) -print("E(EC-CCSD, 2-site FCI, 0 proj, ccsd V)= %+16.8f Ha" % (e_extcorr[0]/nsite)) -print("E(EC-CCSD, 2-site FCI, 1 proj, ccsd V)= %+16.8f Ha" % (e_extcorr[1]/nsite)) -print("E(EC-CCSD, 2-site FCI, 2 proj, ccsd V)= %+16.8f Ha" % (e_extcorr[2]/nsite)) -print("E(EC-CCSD, 2-site FCI, 0 proj, fci V)= %+16.8f Ha" % (e_extcorr[0]/nsite)) -print("E(EC-CCSD, 2-site FCI, 1 proj, fci V)= %+16.8f Ha" % (e_extcorr[1]/nsite)) -print("E(EC-CCSD, 2-site FCI, 2 proj, fci V)= %+16.8f Ha" % (e_extcorr[2]/nsite)) -print("E(T-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha" % (e_tailor[0]/nsite)) -print("E(T-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha" % (e_tailor[1]/nsite)) -print("E(T-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha" % (e_tailor[2]/nsite)) -print("E(DT-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha" % (e_dtailor[0]/nsite)) -print("E(DT-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha" % (e_dtailor[1]/nsite)) -print("E(DT-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha" % (e_dtailor[2]/nsite)) +print("E(MF)= %+16.8f Ha, conv = %s" % (mf.e_tot/nsite, mf.converged)) +print("E(CCSD)= %+16.8f Ha, conv = %s" % (cc.e_tot/nsite, cc.converged)) +print("E(FCI)= %+16.8f Ha, conv = %s" % (fci.e_tot/nsite, fci.converged)) +print("E(Emb. FCI, 2-site)= %+16.8f Ha, conv = %s" % (emb_simp.e_tot/nsite, emb_simp.converged)) +print("E(EC-CCSD, 2-site FCI, 0 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[0]/nsite), extcorr_conv[0])) +print("E(EC-CCSD, 2-site FCI, 1 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[1]/nsite), extcorr_conv[1])) +print("E(EC-CCSD, 2-site FCI, 2 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[2]/nsite), extcorr_conv[2])) +print("E(EC-CCSD, 2-site FCI, 0 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[3]/nsite), extcorr_conv[3])) +print("E(EC-CCSD, 2-site FCI, 1 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[4]/nsite), extcorr_conv[4])) +print("E(EC-CCSD, 2-site FCI, 2 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[5]/nsite), extcorr_conv[5])) +print("E(T-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[0]/nsite), tailor_conv[0])) +print("E(T-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[1]/nsite), tailor_conv[1])) +print("E(T-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[2]/nsite), tailor_conv[2])) +print("E(DT-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[0]/nsite), dtailor_conv[0])) +print("E(DT-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[1]/nsite), dtailor_conv[1])) +print("E(DT-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[2]/nsite), dtailor_conv[2])) From a5dec5b0b6ec57e1e7a6ddaafadb7745a16da774 Mon Sep 17 00:00:00 2001 From: George Booth Date: Tue, 22 Nov 2022 10:24:13 +0000 Subject: [PATCH 22/66] Fix for use of delta-tailoring correction with symmetry-derived fragments --- vayesta/solver/coupling.py | 3 +++ 1 file changed, 3 insertions(+) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 490788ce1..a0e775353 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -545,6 +545,9 @@ def _get_delta_t_for_delta_tailor(fragment, fock): mo_energy = (moa, mob) eris = fragment._eris + if eris is None: + # Symmetry-derived fragments may not have eris stored + eris = fragment.base.get_eris_array(cluster.c_active) ccsd = SimpleCCSD(fock, eris, nocc, mo_energy=mo_energy) ccsd.kernel(t1=t1, t2=t2) assert ccsd.converged From d949b683b53e9919c2fc850f3babb9aadcb04794 Mon Sep 17 00:00:00 2001 From: George Booth Date: Tue, 22 Nov 2022 11:40:42 +0000 Subject: [PATCH 23/66] Update EC-CC example to use symmetry correctly. Put note in external-correction function to warn if double counting correction. --- examples/ewf/other/61-ext-corr-hubbard-1D.py | 18 +++++++----------- vayesta/solver/coupling.py | 8 ++++++++ 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/examples/ewf/other/61-ext-corr-hubbard-1D.py b/examples/ewf/other/61-ext-corr-hubbard-1D.py index 2db3e5aeb..cbe0d649d 100644 --- a/examples/ewf/other/61-ext-corr-hubbard-1D.py +++ b/examples/ewf/other/61-ext-corr-hubbard-1D.py @@ -7,7 +7,7 @@ nsite = 10 nelectron = nsite -hubbard_u = 5.0 +hubbard_u = 4.0 mol = vayesta.lattmod.Hubbard1D(nsite, nelectron=nelectron, hubbard_u=hubbard_u) mf = vayesta.lattmod.LatticeMF(mol) mf.kernel() @@ -35,14 +35,11 @@ # Set up a two-site FCI fragmentation of full system # Ensure the right number of electrons on each fragment space of the FCI calculation. fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) - fci_frags.append(f.add_atomic_fragment([2, 3], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) - fci_frags.append(f.add_atomic_fragment([4, 5], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) - fci_frags.append(f.add_atomic_fragment([6, 7], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) - fci_frags.append(f.add_atomic_fragment([8, 9], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) # Add single 'complete' CCSD fragment covering all sites (currently inactive) ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), solver_options=dict(solve_lambda=False, init_guess='CISD'), active=False) -# FCI fragment symmetry not available for external correction -#fci_frags = fci_frags.add_tsymmetric_fragments(tvecs=[5, 1, 1]) +for fci_sym_frag in fci_frags[0].add_tsymmetric_fragments(tvecs=[5, 1, 1]): + # Add symmetry-derived FCI fragments to avoid multiple calculations + fci_frags.append(fci_sym_frag) emb.kernel() assert(emb.converged) @@ -54,6 +51,9 @@ def ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. + NOTE that with multiple FCI fragments providing constraints and overlapping bath spaces, proj=0 will + overcount the correction, so do not use with multiple FCI clusters. It will not e.g. tend to the right answer as + the FCI bath space becomes complete. Only use with a single FCI fragment. """ ccsd_frag.clear_external_corrections() # Clear any previous corrections applied @@ -108,15 +108,11 @@ def ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): print("E(CCSD)= %+16.8f Ha, conv = %s" % (cc.e_tot/nsite, cc.converged)) print("E(FCI)= %+16.8f Ha, conv = %s" % (fci.e_tot/nsite, fci.converged)) print("E(Emb. FCI, 2-site)= %+16.8f Ha, conv = %s" % (emb_simp.e_tot/nsite, emb_simp.converged)) -print("E(EC-CCSD, 2-site FCI, 0 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[0]/nsite), extcorr_conv[0])) print("E(EC-CCSD, 2-site FCI, 1 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[1]/nsite), extcorr_conv[1])) print("E(EC-CCSD, 2-site FCI, 2 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[2]/nsite), extcorr_conv[2])) -print("E(EC-CCSD, 2-site FCI, 0 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[3]/nsite), extcorr_conv[3])) print("E(EC-CCSD, 2-site FCI, 1 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[4]/nsite), extcorr_conv[4])) print("E(EC-CCSD, 2-site FCI, 2 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[5]/nsite), extcorr_conv[5])) -print("E(T-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[0]/nsite), tailor_conv[0])) print("E(T-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[1]/nsite), tailor_conv[1])) print("E(T-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[2]/nsite), tailor_conv[2])) -print("E(DT-CCSD, 2-site FCI, 0 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[0]/nsite), dtailor_conv[0])) print("E(DT-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[1]/nsite), dtailor_conv[1])) print("E(DT-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[2]/nsite), dtailor_conv[2])) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index a8662022f..94326a7de 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -604,6 +604,14 @@ def externally_correct(solver, external_corrections, eris=None, test_extcorr=Fal else: mo_energy = eris.mo_energy + if (len(external_corrections) > 1) and any([corr[2] == 0 for corr in external_corrections]): + # We are externally correcting from multiple fragments, but not projecting them + # into their fragment spaces. This means we are at risk of double-counting the external + # corrections. + solver.log.warn("Multiple external correcting fragments, but not fragment-projecting the resulting correction!") + solver.log.warn("This will likely lead to double-counting of external correction.") + solver.log.warn("Are you sure you want to do this?!") + if any([corr[1] == 'external-ccsdv' for corr in external_corrections]): # At least one fragment is externally corrected, *and* contracted with # integrals in the parent cluster. We can take the integrals from eris From 2549eefa34ccebcebda168a1d221d5d1caa26361 Mon Sep 17 00:00:00 2001 From: George Booth Date: Tue, 22 Nov 2022 13:12:51 +0000 Subject: [PATCH 24/66] Tidying in response to PR comments. --- examples/ewf/molecules/04-bath-options.py | 3 ++- vayesta/core/qemb/fragment.py | 23 +++++++++++------------ vayesta/core/types/wf/cisdtq.py | 2 +- vayesta/tests/ewf/test_extcorr.py | 14 +++++++++++++- 4 files changed, 27 insertions(+), 15 deletions(-) diff --git a/examples/ewf/molecules/04-bath-options.py b/examples/ewf/molecules/04-bath-options.py index 4520561f9..f73610871 100644 --- a/examples/ewf/molecules/04-bath-options.py +++ b/examples/ewf/molecules/04-bath-options.py @@ -1,3 +1,4 @@ +import numpy as np import pyscf import pyscf.gto import pyscf.scf @@ -46,7 +47,7 @@ # Other options (not shown) include projecting out all couplings to the DMET bath space, or just projecting # one index. # The options below are default -emb_mp2_projdmet = vayesta.ewf.EWF(mf, bath_options=dict(bathtype='mp2', threshold=1e-4, \ +emb_mp2_projdmet = vayesta.ewf.EWF(mf, bath_options=dict(bathtype='mp2', threshold=1e-4, project_dmet_order=2, project_dmet_mode='squared-entropy')) emb_mp2_projdmet.kernel() assert(np.allclose(emb_mp2_projdmet.e_tot, emb_mp2.e_tot)) diff --git a/vayesta/core/qemb/fragment.py b/vayesta/core/qemb/fragment.py index c482e6d97..dc11b6875 100644 --- a/vayesta/core/qemb/fragment.py +++ b/vayesta/core/qemb/fragment.py @@ -336,18 +336,17 @@ def reset(self, reset_bath=True, reset_cluster=True, reset_eris=True, reset_inac self, reset_bath, reset_cluster, reset_eris, reset_inactive) if not reset_inactive and not self.active: return - else: - if reset_bath: - self._dmet_bath = None - self._bath_factory_occ = None - self._bath_factory_vir = None - if reset_cluster: - self._cluster = None - self.get_overlap.cache_clear() - if reset_eris: - self._eris = None - self._seris_ov = None - self._results = None + if reset_bath: + self._dmet_bath = None + self._bath_factory_occ = None + self._bath_factory_vir = None + if reset_cluster: + self._cluster = None + self.get_overlap.cache_clear() + if reset_eris: + self._eris = None + self._seris_ov = None + self._results = None def get_fragments_with_overlap(self, tol=1e-8, **kwargs): """Get list of fragments which overlap both in occupied and virtual space.""" diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 30ca39aa1..d6cbcc2e3 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -21,7 +21,7 @@ def __init__(self, mo, c0, c1, c2, c3, c4): self.c2 = c2 self.c3 = c3 self.c4 = c4 - if not (isinstance(c4, tuple) and len(c4)==2): + if not (isinstance(c4, tuple) and len(c4) == 2): raise ValueError("c4 definition in RCISDTQ wfn requires tuple of (abaa, abab) spin signatures") def as_ccsdtq(self): diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index f9c16b288..86c5f9179 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -13,7 +13,7 @@ @pytest.mark.fast -class TestSolvers(TestCase): +class TestFullEC(TestCase): def _test(self, key, proj=0, mode='external-fciv', store_wf_ccsdtq=True): mf = getattr(getattr(testsystems, key[0]), key[1])() @@ -74,6 +74,9 @@ def test_r_exact_ec_lih_proj1_ccsdv_nostore(self): def test_r_exact_ec_lih_proj2_ccsdv_nostore(self): return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=False) +@pytest.mark.fast +class TestHubCompleteEC(TestCase): + def _test_10_u4_2imp(self, mode, proj): """Tests for N=10 U=4 Hubbard model with double site CCSD impurities and complete FCI fragment @@ -119,6 +122,9 @@ def test_hub_ec_2imp_proj1_fciv(self): def test_hub_ec_2imp_proj2_fciv(self): return self._test_10_u4_2imp(mode='external-fciv', proj=2) +@pytest.mark.fast +class TestHubBathEC(TestCase): + def _test_10_u2_2impfci(self, mode): """Tests for N=10 U=2 Hubbard model with double site CCSD impurities and 2-site FCI fragment (but complete bath). With no projectors on @@ -154,6 +160,9 @@ def test_hub_ec_2impfci_proj0_fciv(self): def test_hub_ec_2impfci_proj0_ccsdv(self): return self._test_10_u2_2impfci(mode='external-ccsdv') +@pytest.mark.fast +class TestECSym(TestCase): + def _test_10_u2_eccc_sym(self, mode, proj=0): """Test symmetry in external correction via comparison to system without use of symmetry """ @@ -218,6 +227,9 @@ def test_hub_ec_sym_proj1_dtailor(self): def test_hub_ec_sym_proj1_tailor(self): return self._test_10_u2_eccc_sym(mode='tailor', proj=1) +@pytest.mark.fast +class TestRegEC_CCSD(TestCase): + def _test_water_ec_regression(self, mode=None, projectors=None): mf = testsystems.water_ccpvdz_df.rhf() From 6aaff995ce3449488bf122dc79166ca6a9bfb0a8 Mon Sep 17 00:00:00 2001 From: George Booth Date: Thu, 24 Nov 2022 17:10:43 +0000 Subject: [PATCH 25/66] Update examples and tests for (single kernel) EC --- .../ewf/molecules/25-externally-correct.py | 31 ++--- examples/ewf/other/61-ext-corr-hubbard-1D.py | 121 +++++++++--------- vayesta/core/scmf/scmf.py | 3 +- vayesta/tests/ewf/test_extcorr.py | 15 ++- 4 files changed, 85 insertions(+), 85 deletions(-) diff --git a/examples/ewf/molecules/25-externally-correct.py b/examples/ewf/molecules/25-externally-correct.py index e23680f1f..a1147685d 100644 --- a/examples/ewf/molecules/25-externally-correct.py +++ b/examples/ewf/molecules/25-externally-correct.py @@ -31,23 +31,21 @@ with emb.iao_fragmentation() as f: # Add all atomic FCI fragments with DMET bath # Store the FCI wave functions as CCSDTQ types, so they can be used for correction later. - fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ') - # Add single 'complete' CCSD fragment covering all IAOs, but set as inactive - ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), active=False) -emb.kernel() -# Switch active <-> inactive fragments, and run the full system CCSD fragment, applying external correction -for fci_frag in fci_frags: - fci_frag.active = False -ccsd_frag.active = True -# Setup the external correction from the CCSD fragments. + # These want to be flagged as 'auxiliary', as they are solved first, and then used as constraints for the + # non-auxiliary fragments. + fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', auxiliary=True) + # Add single 'complete' CCSD fragment covering all IAOs + ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full')) +# Setup the external correction from the CCSD fragment. # Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the # T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is # larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). # The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). # The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less # 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. +# For multiple constraining fragments, proj=0 will double-count the correction due to overlapping bath spaces, and +# in this case, only proj=1 will be exact in the limit of enlarging (FCI) bath spaces. ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) -# Run kernel again emb.kernel() print('Total energy from full system CCSD tailored (CCSD Coulomb interaction) by atomic FCI fragments (projectors=1): {}'.format(emb.e_tot)) @@ -55,14 +53,9 @@ # Similar set up, but we now have multiple CCSD clusters. emb = vayesta.ewf.EWF(mf) with emb.iao_fragmentation() as f: - fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ') - ccsd_frags = f.add_all_atomic_fragments(solver='CCSD', bath_options=dict(bathtype='mp2', threshold=1.e-5), active=False) -emb.kernel() -for fci_frag in fci_frags: - fci_frag.active = False -for ccsd_frag in ccsd_frags: - ccsd_frag.active = True - # Now add external corrections to all CCSD clusters, and use 'external-fciv' correction, with 2 projectors - ccsd_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=2) + fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', auxiliary=True) + ccsd_frags = f.add_all_atomic_fragments(solver='CCSD', bath_options=dict(bathtype='mp2', threshold=1.e-5)) +# Now add external corrections to all CCSD clusters, and use 'external-fciv' correction, with 2 projectors +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=2) emb.kernel() print('Total energy from embedded CCSD tailored (FCI Coulomb interaction) by atomic FCI fragments (projectors=2): {}'.format(emb.e_tot)) diff --git a/examples/ewf/other/61-ext-corr-hubbard-1D.py b/examples/ewf/other/61-ext-corr-hubbard-1D.py index cbe0d649d..7b7d47024 100644 --- a/examples/ewf/other/61-ext-corr-hubbard-1D.py +++ b/examples/ewf/other/61-ext-corr-hubbard-1D.py @@ -32,87 +32,84 @@ emb = vayesta.ewf.EWF(mf) fci_frags = [] with emb.site_fragmentation() as f: - # Set up a two-site FCI fragmentation of full system + # Set up a two-site FCI fragmentation of full system as auxiliary clusters # Ensure the right number of electrons on each fragment space of the FCI calculation. - fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite)) - # Add single 'complete' CCSD fragment covering all sites (currently inactive) - ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), solver_options=dict(solve_lambda=False, init_guess='CISD'), active=False) + fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite, auxiliary=True)) + # Add single 'complete' CCSD fragment covering all sites + ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), solver_options=dict(solve_lambda=False, init_guess='CISD')) for fci_sym_frag in fci_frags[0].add_tsymmetric_fragments(tvecs=[5, 1, 1]): # Add symmetry-derived FCI fragments to avoid multiple calculations fci_frags.append(fci_sym_frag) + +e_extcorr = [] +extcorr_conv = [] +#Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the +#T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is +#larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). +#The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). +#The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less +#'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. +#NOTE that with multiple FCI fragments providing constraints and overlapping bath spaces, proj=0 will +#overcount the correction, so do not use with multiple FCI clusters. It will not e.g. tend to the right answer as +#the FCI bath space becomes complete (for which you must have proj=1). Only use with a single FCI fragment. +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) emb.kernel() -assert(emb.converged) +e_extcorr.append(emb.e_tot); extcorr_conv.append(emb.converged) -def ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0): - """Setup the external correction from the CCSD fragments. - Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the - T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is - larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). - The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). - The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less - 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. - NOTE that with multiple FCI fragments providing constraints and overlapping bath spaces, proj=0 will - overcount the correction, so do not use with multiple FCI clusters. It will not e.g. tend to the right answer as - the FCI bath space becomes complete. Only use with a single FCI fragment. - """ +# For subsequent calculations where we have just changed the mode/projectors in the external tailoring, we want to avoid having +# to resolve the FCI fragments. Set them to inactive, so just the CCSD fragments will be resolved. +for fci_frag in fci_frags: + fci_frag.active = False - ccsd_frag.clear_external_corrections() # Clear any previous corrections applied - for fci_frag in fci_frags: - fci_frag.active = False - ccsd_frag.active = True - ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors) - # Run kernel again - emb.kernel() - return emb.e_tot, emb.converged +ccsd_frag.clear_external_corrections() # Clear any previous corrections applied +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=2) +emb.kernel() +e_extcorr.append(emb.e_tot); extcorr_conv.append(emb.converged) -e_extcorr = [] -extcorr_conv = [] -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0) -e_extcorr.append(e); extcorr_conv.append(conv) -# Change number of projectors and/or Coulomb type, and re-run to get change -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=0) -e_extcorr.append(e); extcorr_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=1) -e_extcorr.append(e); extcorr_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-ccsdv', projectors=2) -e_extcorr.append(e); extcorr_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=0) -e_extcorr.append(e); extcorr_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=1) -e_extcorr.append(e); extcorr_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='external-fciv', projectors=1) -e_extcorr.append(e); extcorr_conv.append(conv) +ccsd_frag.clear_external_corrections() # Clear any previous corrections applied +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=1) +emb.kernel() +e_extcorr.append(emb.e_tot); extcorr_conv.append(emb.converged) + +ccsd_frag.clear_external_corrections() # Clear any previous corrections applied +ccsd_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=2) +emb.kernel() +e_extcorr.append(emb.e_tot); extcorr_conv.append(emb.converged) # Compare to a simpler tailoring e_tailor = [] tailor_conv = [] -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=0) -e_tailor.append(e) ; tailor_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=1) -e_tailor.append(e) ; tailor_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='tailor', projectors=2) -e_tailor.append(e) ; tailor_conv.append(conv) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='tailor', projectors=1) +emb.kernel() +e_tailor.append(emb.e_tot); tailor_conv.append(emb.converged) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='tailor', projectors=2) +emb.kernel() +e_tailor.append(emb.e_tot); tailor_conv.append(emb.converged) # Compare to a delta-tailoring, where the correction is the difference between full-system # CCSD and CCSD in the FCI cluster. e_dtailor = [] dtailor_conv = [] -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=0) -e_dtailor.append(e) ; dtailor_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=1) -e_dtailor.append(e) ; dtailor_conv.append(conv) -e, conv = ext_corr(emb, fci_frags, ccsd_frag, mode='delta-tailor', projectors=2) -e_dtailor.append(e) ; dtailor_conv.append(conv) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='delta-tailor', projectors=1) +emb.kernel() +e_dtailor.append(emb.e_tot); dtailor_conv.append(emb.converged) +ccsd_frag.clear_external_corrections() +ccsd_frag.add_external_corrections(fci_frags, correction_type='delta-tailor', projectors=2) +emb.kernel() +e_dtailor.append(emb.e_tot); dtailor_conv.append(emb.converged) print("E(MF)= %+16.8f Ha, conv = %s" % (mf.e_tot/nsite, mf.converged)) print("E(CCSD)= %+16.8f Ha, conv = %s" % (cc.e_tot/nsite, cc.converged)) print("E(FCI)= %+16.8f Ha, conv = %s" % (fci.e_tot/nsite, fci.converged)) print("E(Emb. FCI, 2-site)= %+16.8f Ha, conv = %s" % (emb_simp.e_tot/nsite, emb_simp.converged)) -print("E(EC-CCSD, 2-site FCI, 1 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[1]/nsite), extcorr_conv[1])) -print("E(EC-CCSD, 2-site FCI, 2 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[2]/nsite), extcorr_conv[2])) -print("E(EC-CCSD, 2-site FCI, 1 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[4]/nsite), extcorr_conv[4])) -print("E(EC-CCSD, 2-site FCI, 2 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[5]/nsite), extcorr_conv[5])) -print("E(T-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[1]/nsite), tailor_conv[1])) -print("E(T-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[2]/nsite), tailor_conv[2])) -print("E(DT-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[1]/nsite), dtailor_conv[1])) -print("E(DT-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[2]/nsite), dtailor_conv[2])) +print("E(EC-CCSD, 2-site FCI, 1 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[0]/nsite), extcorr_conv[0])) +print("E(EC-CCSD, 2-site FCI, 2 proj, ccsd V)= %+16.8f Ha, conv = %s" % ((e_extcorr[1]/nsite), extcorr_conv[1])) +print("E(EC-CCSD, 2-site FCI, 1 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[2]/nsite), extcorr_conv[2])) +print("E(EC-CCSD, 2-site FCI, 2 proj, fci V)= %+16.8f Ha, conv = %s" % ((e_extcorr[3]/nsite), extcorr_conv[3])) +print("E(T-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[0]/nsite), tailor_conv[0])) +print("E(T-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha, conv = %s" % ((e_tailor[1]/nsite), tailor_conv[1])) +print("E(DT-CCSD, 2-site FCI, 1 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[0]/nsite), dtailor_conv[0])) +print("E(DT-CCSD, 2-site FCI, 2 proj)= %+16.8f Ha, conv = %s" % ((e_dtailor[1]/nsite), dtailor_conv[1])) diff --git a/vayesta/core/scmf/scmf.py b/vayesta/core/scmf/scmf.py index 23f122782..d53a6f015 100644 --- a/vayesta/core/scmf/scmf.py +++ b/vayesta/core/scmf/scmf.py @@ -85,8 +85,7 @@ def kernel(self, *args, **kwargs): self.log.info("%s==============", len(self.name)*"=") if self.iteration > 1: - # Don't reset inactive clusters for external corrections - self.emb.reset(reset_inactive=False) + self.emb.reset() # Run clusters, save results res = self.kernel_orig(*args, **kwargs) diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index 86c5f9179..e8849f702 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -32,9 +32,9 @@ def _test(self, key, proj=0, mode='external-fciv', store_wf_ccsdtq=True): fci_frag.active = False ccsd.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) - ccsd.active=True + ccsd.active = True ccsd2.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) - ccsd2.active=True + ccsd2.active = True emb.kernel() fci = pyscf.fci.FCI(mf) @@ -48,6 +48,17 @@ def _test(self, key, proj=0, mode='external-fciv', store_wf_ccsdtq=True): self.assertAlmostEqual(emb.e_corr, fci_frag_ecorr) self.assertAlmostEqual(emb.e_tot, fci_frag_etot) + # Rather than setting fragments to active and inactive, we should also be able to run the external correction + # in a single kernel call, setting the FCI fragments with auxiliary flags + fci_frag.opts.active = True + fci_frag.opts.auxiliary = True + ccsd.clear_external_corrections() + ccsd.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) + ccsd2.clear_external_corrections() + ccsd2.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) + emb.kernel() + self.assertAlmostEqual(emb.e_tot, fci_frag_etot) + # Test all combinations of options def test_r_exact_ec_lih_proj0_fciv_store(self): return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=True) From 90e73190b53179870d7857a5bd1d8d1b200d01ae Mon Sep 17 00:00:00 2001 From: George Booth Date: Thu, 26 Jan 2023 15:09:44 +0000 Subject: [PATCH 26/66] WIP to prep for UHF implementation --- vayesta/core/qemb/qemb.py | 2 +- vayesta/core/scmf/scmf.py | 7 ++++++- vayesta/core/types/wf/cisdtq.py | 14 +++++++++++++- vayesta/core/types/wf/fci.py | 9 +++++++++ vayesta/solver/coupling.py | 1 + 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/vayesta/core/qemb/qemb.py b/vayesta/core/qemb/qemb.py index 8e43dc21d..2626e05c9 100644 --- a/vayesta/core/qemb/qemb.py +++ b/vayesta/core/qemb/qemb.py @@ -1542,7 +1542,7 @@ def reset(self, *args, **kwargs): def update_mf(self, mo_coeff, mo_energy=None, veff=None): """Update underlying mean-field object.""" # Chech orthonormal MOs - if not np.allclose(dot(mo_coeff.T, self.get_ovlp(), mo_coeff) - np.eye(mo_coeff.shape[-1]), 0): + if not np.allclose(dot(mo_coeff.T, self.get_ovlp(), mo_coeff) - np.eye(mo_coeff.shape[-1]), 0.): raise ValueError("MO coefficients not orthonormal!") self.mf.mo_coeff = mo_coeff dm = self.mf.make_rdm1(mo_coeff=mo_coeff) diff --git a/vayesta/core/scmf/scmf.py b/vayesta/core/scmf/scmf.py index d53a6f015..1ba6258fc 100644 --- a/vayesta/core/scmf/scmf.py +++ b/vayesta/core/scmf/scmf.py @@ -100,7 +100,12 @@ def kernel(self, *args, **kwargs): dm1 = self.mf.make_rdm1() # Check symmetry - self.emb.check_fragment_symmetry(dm1) + try: + self.emb.check_fragment_symmetry(dm1) + except: + self.log.error("Symmetry check failed in %s", self.name) + self.converged = False + break # Check convergence conv, de, ddm = self.check_convergence(e_tot, dm1, e_last, dm1_last) diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index d6cbcc2e3..d2b5f7617 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -195,7 +195,19 @@ def as_ccsdtq(self): return wf_types.RCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) -class UCISDTQ_WaveFunction(RCISDTQ_WaveFunction): +class UCISDTQ_WaveFunction(wf_types.WaveFunction): + + def __init__(self, mo, c0, c1, c2, c3, c4): + super().__init__(mo) + self.c0 = c0 + self.c1 = c1 + self.c2 = c2 + self.c3 = c3 + self.c4 = c4 + if not (isinstance(c3, tuple) and len(c3) == 6): + raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaa, aba, abb, bab, bba, bbb) spin signatures") + if not (isinstance(c4, tuple) and len(c4) == 8): + raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaaa, aaab, aaba, abaa, abab, bbab, bbba, bbbb) spin signatures") def as_ccsdtq(self): c1a, c1b = self.c1 diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index a0971dbc3..5159b386d 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -450,3 +450,12 @@ def as_cisdtq(self, c0=None): #c3 = (c3aaa, ... #c4 = (c4aaaa, ... return wf_types.UCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4, projector=self.projector) + + def as_ccsd(self): + return self.as_cisd().as_ccsd() + + def as_ccsdtq(self): + return self.as_cisdtq().as_ccsdtq() + + def as_fci(self): + return self diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 94326a7de..5296ba8ad 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -405,6 +405,7 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc # apply permutation t1t3v += t1t3v.transpose(1,0,3,2) dt2 += t1t3v + solver.log.info("T1 norm in ext corr from fragment {}: {}".format(fragment.id, np.linalg.norm(t1))) if test_extcorr: tmp2 = einsum('kdlc,id->kilc', govov, t1) t1t3v_test = -einsum('kilc,lkjcab->ijab', tmp2, t3tmp) From c2a04c0e448806785b089c8d0f4bf308720758fb Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 27 Jan 2023 11:32:36 +0000 Subject: [PATCH 27/66] Code to create packed C1 -> C4 UHF arrays. Need to unpack. --- vayesta/core/types/wf/fci.py | 101 ++++++++++++++++++++++++++++++++--- 1 file changed, 95 insertions(+), 6 deletions(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 5159b386d..dbfb27cd5 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -398,9 +398,33 @@ def as_cisd(self, c0=None): def as_cisdtq(self, c0=None): if self.projector is not None: raise NotImplementedError + norba, norbb = self.norb nocca, noccb = self.nocc nvira, nvirb = self.nvir + + ij_pairs_a = int(nocca * (nocca - 1) / 2) + ab_pairs_a = int(nvira * (nvira - 1) / 2) + ij_pairs_b = int(noccb * (noccb - 1) / 2) + ab_pairs_b = int(nvirb * (nvirb - 1) / 2) + ooidx_a = np.tril_indices(nocca, -1) # second index lower than first + vvidx_a = np.tril_indices(nvira, -1) # second index lower than first + ooidx_b = np.tril_indices(noccb, -1) # second index lower than first + vvidx_b = np.tril_indices(nvirb, -1) # second index lower than first + # For packed 3D arrays + oooidx_a = tril_indices_ndim(nocca, 3) # i > j > k + vvvidx_a = tril_indices_ndim(nvira, 3) # a > b > c + ijk_pairs_a = int(nocca * (nocca - 1) * (nocca - 2) / 6) + abc_pairs_a = int(nvira * (nvira - 1) * (nvira - 2) / 6) + oooidx_b = tril_indices_ndim(noccb, 3) # i > j > k + vvvidx_b = tril_indices_ndim(nvirb, 3) # a > b > c + ijk_pairs_b = int(noccb * (noccb - 1) * (noccb - 2) / 6) + abc_pairs_b = int(nvirb * (nvirb - 1) * (nvirb - 2) / 6) + + ijkl_pairs_a = int(nocca * (nocca - 1) * (nocca - 2) * (nocca - 3) / 24) + abcd_pairs_a = int(nvira * (nvira - 1) * (nvira - 2) * (nvira - 3) / 24) + ijkl_pairs_b = int(noccb * (noccb - 1) * (noccb - 2) * (noccb - 3) / 24) + abcd_pairs_b = int(nvirb * (nvirb - 1) * (nvirb - 2) * (nvirb - 3) / 24) t1addra, t1signa = pyscf.ci.cisd.tn_addrs_signs(norba, nocca, 1) t1addrb, t1signb = pyscf.ci.cisd.tn_addrs_signs(norbb, noccb, 1) @@ -419,17 +443,81 @@ def as_cisdtq(self, c0=None): c1a = (self.ci[t1addra,0] * t1signa).reshape(nocca,nvira) c1b = (self.ci[0,t1addrb] * t1signb).reshape(noccb,nvirb) # C2 - nocca_comp = nocca*(nocca-1)//2 - noccb_comp = noccb*(noccb-1)//2 - nvira_comp = nvira*(nvira-1)//2 - nvirb_comp = nvirb*(nvirb-1)//2 - c2aa = (self.ci[t2addra,0] * t2signa).reshape(nocca_comp, nvira_comp) - c2bb = (self.ci[0,t2addrb] * t2signb).reshape(noccb_comp, nvirb_comp) + c2aa = (self.ci[t2addra,0] * t2signa).reshape(ij_pairs_a, ab_pairs_a) + c2bb = (self.ci[0,t2addrb] * t2signb).reshape(ij_pairs_b, ab_pairs_b) c2aa = pyscf.cc.ccsd._unpack_4fold(c2aa, nocca, nvira) c2bb = pyscf.cc.ccsd._unpack_4fold(c2bb, noccb, nvirb) c2ab = einsum('i,j,ij->ij', t1signa, t1signb, self.ci[t1addra[:,None],t1addrb]) c2ab = c2ab.reshape(nocca,nvira,noccb,nvirb).transpose(0,2,1,3) # C3 + + # Get the following spin signatures in packed form, and then Ollie will unpack later! + # T3: aaa, aba, abb, bab, bba, bbb + # aaa + c3_aaa_pack = (self.ci[t3addra,0] * t3signa).reshape(ijk_pairs_a, abc_pairs_a) + # bbb + c3_bbb_pack = (self.ci[0,t3addrb] * t3signb).reshape(ijk_pairs_b, abc_pairs_b) + # aab + c3_aab_pack = np.einsum('i,j,ij->ij', t2signa, t1signb, self.ci[t2addra[:,None], t1addrb]) + assert(c3_aab_pack.shape == (ij_pairs_a * ab_pairs_a, noccb * nvirb)) + # bba + c3_abb_pack = np.einsum('i,j,ij->ij', t1signa, t2signb, self.ci[t1addra[:,None], t2addrb]) + assert(c3_abb_pack.shape == (nocca * nvirb, ij_pairs_b * ab_pairs_b)) + + # Now, unpack... TODO + + # T4: aaaa, aaab, aaba, abaa, abab, bbab, bbba, bbbb + # aaaa + c4_aaaa_pack = (self.ci[t4addra,0] * t4signa).reshape(ijkl_pairs_a, abcd_pairs_a) + # bbbb + c4_bbbb_pack = (self.ci[0,t4addrb] * t4signb).reshape(ijkl_pairs_b, abcd_pairs_b) + # aaab + c4_aaab_pack = np.einsum('i,j,ij->ij', t3signa, t1signb, self.ci[t3addra[:,None], t1addrb]) + assert(c4_aaab_pack.shape == (ijk_pairs_a * abc_pairs_a, noccb * nvirb)) + # aabb + c4_aabb_pack = np.einsum('i,j,ij->ij', t2signa, t2signb, self.ci[t2addra[:,None], t2addrb]) + assert(c4_aabb_pack.shape == (ij_pairs_a * ab_pairs_a, ij_pairs_b * ab_pairs_b)) + # abbb + c4_abbb_pack = np.einsum('i,j,ij->ij', t1signa, t3signb, self.ci[t1addra[:,None], t3addrb]) + assert(c4_aabb_pack.shape == (nocca * nvirb, ijk_pairs_b * abc_pairs_b)) + + # Now, unpack... TODO + + # alpha, beta, alpha: Use this longhand code as a sanity check + # First find the ijk -> abc excitations, where ijab are alpha, and kc are beta + c3_comp = np.zeros((ij_pairs_a * ab_pairs_a, noccb * nvirb)) + c3_aba = np.zeros((nocca, noccb, nocca, nvira, nvirb, nvira)) + for d_cnta, doub_inda in enumerate(t2addra): + ij_a = int(d_cnta / ab_pairs_a) + ab_a = d_cnta % ab_pairs_a + i, j = ooidx_a[0][ij_a], ooidx_a[1][ij_a] # j ind < i ind + a, b = vvidx_a[0][ab_a], vvidx_a[1][ab_a] # b ind < a ind + for s_cntb, sing_indb in enumerate(t1addrb): + # First index of c3_comp is a compound index of ijab (alpha, alpha) excitations, + # with the second index being the kc (beta, beta) single excitation. + c3_comp[d_cnta, s_cntb] = self.ci[doub_inda, sing_indb] * t2signa[d_cnta] * t1signa[s_cntb] + + k = int(s_cntb / nvirb) + c = s_cntb % nvirb + # Note, we want aba -> aba spin signature, not aab -> aab, which is what we have. + # We can therefore swap (jk) and (bc). This does not cause an overall sign change. + # We then also want to fill up the contributions between permutations + # amongst the alpha electrons and alpha holes. + # If only one is permuted, then this will indeed cause a sign change. + assert(i != j) + assert(a != b) + c3_aba[i,k,j,a,c,b] = c3_comp[d_cnta, s_cntb] + c3_aba[j,k,i,a,c,b] = -c3_comp[d_cnta, s_cntb] + c3_aba[i,k,j,b,c,a] = -c3_comp[d_cnta, s_cntb] + c3_aba[j,k,i,b,c,a] = c3_comp[d_cnta, s_cntb] + + if len(t2addra) > 0: + # This is a better way of doing it, and then expand! Put rest in a test. + assert(np.allclose(c3_comp, np.einsum('i,j,ij->ij', \ + t2signa, t1signb, self.ci[t2addra[:,None], t1addrb]))) + del c3_comp + + raise NotImplementedError # C4 raise NotImplementedError @@ -449,6 +537,7 @@ def as_cisdtq(self, c0=None): # TODO #c3 = (c3aaa, ... #c4 = (c4aaaa, ... + # Are any of them 'packed'? return wf_types.UCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4, projector=self.projector) def as_ccsd(self): From 11089bdbb35d96140bf9867b969b7e4562c5940d Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 27 Jan 2023 12:50:48 +0000 Subject: [PATCH 28/66] Add unpacking for unrestricted C amplitudes via ebcc --- vayesta/core/types/wf/cisdtq.py | 58 ++++++++------- vayesta/core/types/wf/fci.py | 126 +++++++++++++++++++++++++------- 2 files changed, 129 insertions(+), 55 deletions(-) diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index d2b5f7617..2ef587760 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -204,34 +204,36 @@ def __init__(self, mo, c0, c1, c2, c3, c4): self.c2 = c2 self.c3 = c3 self.c4 = c4 - if not (isinstance(c3, tuple) and len(c3) == 6): - raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaa, aba, abb, bab, bba, bbb) spin signatures") - if not (isinstance(c4, tuple) and len(c4) == 8): - raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaaa, aaab, aaba, abaa, abab, bbab, bbba, bbbb) spin signatures") + # FIXME I've just disabled these checks for now - fix later + #if not (isinstance(c3, tuple) and len(c3) == 6): + # raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaa, aba, abb, bab, bba, bbb) spin signatures") + #if not (isinstance(c4, tuple) and len(c4) == 8): + # raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaaa, aaab, aaba, abaa, abab, bbab, bbba, bbbb) spin signatures") def as_ccsdtq(self): - c1a, c1b = self.c1 - c2aa, c2ab, c2bb = self.c2 - # TODO - #c3aaa, c3aab, ... = self.c3 - #c4aaaa, c4aaab, ... = self.c4 - - # T1 - t1a = c1a/self.c0 - t1b = c1b/self.c0 - # T2 - t2aa = c2aa/self.c0 - einsum('ia,jb->ijab', t1a, t1a) + einsum('ib,ja->ijab', t1a, t1a) - t2bb = c2bb/self.c0 - einsum('ia,jb->ijab', t1b, t1b) + einsum('ib,ja->ijab', t1b, t1b) - t2ab = c2ab/self.c0 - einsum('ia,jb->ijab', t1a, t1b) - # T3 - raise NotImplementedError - #t3aaa = c3aaa/self.c0 - einsum('ijab,kc->ijkabc', t2a, t1a) - ... - # T4 - #t4aaaa = c4aaaa/self.c0 - einsum('ijkabc,ld->ijklabcd', t3a, t1a) - ... - - t1 = (t1a, t1b) - t2 = (t2aa, t2ab, t2bb) - # TODO - #t3 = (t3aaa, t3aab, ...) - #t4 = (t4aaaa, t4aaab, ...) + #c1a, c1b = self.c1 + #c2aa, c2ab, c2bb = self.c2 + ## TODO + ##c3aaa, c3aab, ... = self.c3 + ##c4aaaa, c4aaab, ... = self.c4 + + ## T1 + #t1a = c1a/self.c0 + #t1b = c1b/self.c0 + ## T2 + #t2aa = c2aa/self.c0 - einsum('ia,jb->ijab', t1a, t1a) + einsum('ib,ja->ijab', t1a, t1a) + #t2bb = c2bb/self.c0 - einsum('ia,jb->ijab', t1b, t1b) + einsum('ib,ja->ijab', t1b, t1b) + #t2ab = c2ab/self.c0 - einsum('ia,jb->ijab', t1a, t1b) + ## T3 + #raise NotImplementedError + ##t3aaa = c3aaa/self.c0 - einsum('ijab,kc->ijkabc', t2a, t1a) - ... + ## T4 + ##t4aaaa = c4aaaa/self.c0 - einsum('ijkabc,ld->ijklabcd', t3a, t1a) - ... + + #t1 = (t1a, t1b) + #t2 = (t2aa, t2ab, t2bb) + ## TODO + ##t3 = (t3aaa, t3aab, ...) + ##t4 = (t4aaaa, t4aaab, ...) + return wf_types.UCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index dbfb27cd5..efe9423f8 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -440,15 +440,15 @@ def as_cisdtq(self, c0=None): ci = self.ci.reshape(na,nb) # C1 - c1a = (self.ci[t1addra,0] * t1signa).reshape(nocca,nvira) - c1b = (self.ci[0,t1addrb] * t1signb).reshape(noccb,nvirb) + c1_a = (self.ci[t1addra,0] * t1signa).reshape(nocca,nvira) + c1_b = (self.ci[0,t1addrb] * t1signb).reshape(noccb,nvirb) # C2 - c2aa = (self.ci[t2addra,0] * t2signa).reshape(ij_pairs_a, ab_pairs_a) - c2bb = (self.ci[0,t2addrb] * t2signb).reshape(ij_pairs_b, ab_pairs_b) - c2aa = pyscf.cc.ccsd._unpack_4fold(c2aa, nocca, nvira) - c2bb = pyscf.cc.ccsd._unpack_4fold(c2bb, noccb, nvirb) - c2ab = einsum('i,j,ij->ij', t1signa, t1signb, self.ci[t1addra[:,None],t1addrb]) - c2ab = c2ab.reshape(nocca,nvira,noccb,nvirb).transpose(0,2,1,3) + c2_aa = (self.ci[t2addra,0] * t2signa).reshape(ij_pairs_a, ab_pairs_a) + c2_bb = (self.ci[0,t2addrb] * t2signb).reshape(ij_pairs_b, ab_pairs_b) + c2_aa = pyscf.cc.ccsd._unpack_4fold(c2_aa, nocca, nvira) + c2_bb = pyscf.cc.ccsd._unpack_4fold(c2_bb, noccb, nvirb) + c2_ab = einsum('i,j,ij->ij', t1signa, t1signb, self.ci[t1addra[:,None],t1addrb]) + c2_ab = c2_ab.reshape(nocca,nvira,noccb,nvirb).transpose(0,2,1,3) # C3 # Get the following spin signatures in packed form, and then Ollie will unpack later! @@ -465,6 +465,33 @@ def as_cisdtq(self, c0=None): assert(c3_abb_pack.shape == (nocca * nvirb, ij_pairs_b * ab_pairs_b)) # Now, unpack... TODO + from ebcc.util import decompress_axes + c3_aaa = decompress_axes( + "iiiaaa", + c3_aaa_pack, + shape=(nocca, nocca, nocca, nvira, nvira, nvira), + symmetry="------", + ) + c3_bbb = decompress_axes( + "iiiaaa", + c3_bbb_pack, + shape=(noccb, noccb, noccb, nvirb, nvirb, nvirb), + symmetry="------", + ) + c3_aab = decompress_axes( + "iiaajb", + c3_aab_pack, + shape=(nocca, nocca, nvira, nvira, noccb, nvirb), + symmetry="------", + ) + c3_aab = c3_aab.transpose(0, 1, 4, 2, 3, 5) + c3_abb = decompress_axes( + "iajjbb", + c3_abb_pack, + shape=(nocca, nvirb, noccb, noccb, nvirb, nvirb), + symmetry="------", + ) + c3_abb = c3_abb.transpose(0, 2, 3, 1, 4, 5) # T4: aaaa, aaab, aaba, abaa, abab, bbab, bbba, bbbb # aaaa @@ -479,9 +506,42 @@ def as_cisdtq(self, c0=None): assert(c4_aabb_pack.shape == (ij_pairs_a * ab_pairs_a, ij_pairs_b * ab_pairs_b)) # abbb c4_abbb_pack = np.einsum('i,j,ij->ij', t1signa, t3signb, self.ci[t1addra[:,None], t3addrb]) - assert(c4_aabb_pack.shape == (nocca * nvirb, ijk_pairs_b * abc_pairs_b)) + assert(c4_abbb_pack.shape == (nocca * nvirb, ijk_pairs_b * abc_pairs_b)) # Now, unpack... TODO + c4_aaaa = decompress_axes( + "iiiiaaaa", + c4_aaaa_pack, + shape=(nocca, nocca, nocca, nocca, nvira, nvira, nvira, nvira), + symmetry="--------", + ) + c4_bbbb = decompress_axes( + "iiiiaaaa", + c4_bbbb_pack, + shape=(noccb, noccb, noccb, noccb, nvirb, nvirb, nvirb, nvirb), + symmetry="--------", + ) + c4_aaab = decompress_axes( + "iiiaaajb", + c4_aaab_pack, + shape=(nocca, nocca, nocca, nvira, nvira, nvira, noccb, nvirb), + symmetry="--------", + ) + c4_aaab = c4_aaab.transpose(0, 1, 2, 6, 3, 4, 5, 7) + c4_aabb = decompress_axes( + "iiaajjbb", + c4_aabb_pack, + shape=(nocca, nocca, nvira, nvira, noccb, noccb, nvirb, nvirb), + symmetry="--------", + ) + c4_aabb = c4_aabb.transpose(0, 1, 4, 5, 2, 3, 6, 7) + c4_abbb = decompress_axes( + "iajjjbbb", + c4_abbb_pack, + shape=(nocca, nvirb, noccb, noccb, noccb, nvirb, nvirb, nvirb), + symmetry="--------", + ) + c4_abbb = c4_abbb.transpose(0, 2, 3, 4, 1, 5, 6, 7) # alpha, beta, alpha: Use this longhand code as a sanity check # First find the ijk -> abc excitations, where ijab are alpha, and kc are beta @@ -517,28 +577,40 @@ def as_cisdtq(self, c0=None): t2signa, t1signb, self.ci[t2addra[:,None], t1addrb]))) del c3_comp - - raise NotImplementedError - # C4 - raise NotImplementedError + assert np.allclose(c3_aba, c3_aab.transpose(0, 2, 1, 3, 5, 4)) + + # TODO remove degenerate permutations + c1 = (c1_a, c1_b) + c2 = (c2_aa, c2_ab, c2_bb) + c3 = ( + c3_aaa, + c3_aab.transpose(0, 2, 1, 3, 5, 4), + c3_abb, + c3_abb.transpose(1, 0, 2, 4, 3, 5), + c3_bbb, + ) + c4 = ( + c4_aaaa, + c4_aaab, + c4_aaab.transpose(0, 1, 3, 2, 4, 5, 7, 6), + c4_aaab.transpose(0, 3, 2, 1, 4, 7, 6, 5), + c4_aabb.transpose(0, 2, 1, 3, 4, 6, 5, 7), + c4_abbb.transpose(2, 1, 0, 3, 6, 5, 4, 7), + c4_abbb.transpose(3, 1, 2, 0, 7, 5, 6, 4), + c4_bbbb, + ) if c0 is None: c0 = self.c0 else: - c1a *= c0/self.c0 - c1b *= c0/self.c0 - c2aa *= c0/self.c0 - c2ab *= c0/self.c0 - c2bb *= c0/self.c0 - # TODO - c3aaa *= c0/self.c0 - c1 = (c1a, c1b) - c2 = (c2aa, c2ab, c2bb) - # TODO - #c3 = (c3aaa, ... - #c4 = (c4aaaa, ... - # Are any of them 'packed'? - return wf_types.UCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4, projector=self.projector) + fac = c0 / self.c0 + c1 = tuple(c * fac for c in c1) + c2 = tuple(c * fac for c in c2) + c3 = tuple(c * fac for c in c3) + c4 = tuple(c * fac for c in c4) + + # FIXME unexpected keyword argument 'projector' + return wf_types.UCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4)#, projector=self.projector) def as_ccsd(self): return self.as_cisd().as_ccsd() From e847618d4b208f3962fb9aaadddeed17d04da473 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 27 Jan 2023 13:49:36 +0000 Subject: [PATCH 29/66] Implemented C to T conversion for UHF --- vayesta/core/types/wf/ccsdtq.py | 23 +- vayesta/core/types/wf/cisdtq.py | 719 ++++++++++++++++++++++++++++++-- vayesta/core/types/wf/fci.py | 1 + 3 files changed, 717 insertions(+), 26 deletions(-) diff --git a/vayesta/core/types/wf/ccsdtq.py b/vayesta/core/types/wf/ccsdtq.py index 5f7c4f0ad..486753b66 100644 --- a/vayesta/core/types/wf/ccsdtq.py +++ b/vayesta/core/types/wf/ccsdtq.py @@ -35,5 +35,24 @@ def as_ccsd(self): def as_cisd(self, c0=1.0): return self.as_ccsd().as_cisd() -class UCCSDTQ_WaveFunction(RCCSDTQ_WaveFunction): - pass +class UCCSDTQ_WaveFunction(wf_types.WaveFunction): + def __init__(self, mo, t1, t2, t3, t4): + super().__init__(mo) + self.t1 = t1 + self.t2 = t2 + self.t3 = t3 + self.t4 = t4 + # TODO + #if not (isinstance(t4, tuple) and len(t4) == 2): + # raise ValueError("t4 definition in RCCSDTQ wfn requires tuple of (abaa, abab) spin signatures") + + def as_ccsdtq(self): + return self + + def as_ccsd(self): + if self.projector is not None: + raise NotImplementedError + return wf_types.UCCSD_WaveFunction(self.mo, self.t1, self.t2) + + def as_cisd(self, c0=1.0): + return self.as_ccsd().as_cisd() diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 2ef587760..3594f4d2c 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -211,29 +211,700 @@ def __init__(self, mo, c0, c1, c2, c3, c4): # raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaaa, aaab, aaba, abaa, abab, bbab, bbba, bbbb) spin signatures") def as_ccsdtq(self): - #c1a, c1b = self.c1 - #c2aa, c2ab, c2bb = self.c2 - ## TODO - ##c3aaa, c3aab, ... = self.c3 - ##c4aaaa, c4aaab, ... = self.c4 - - ## T1 - #t1a = c1a/self.c0 - #t1b = c1b/self.c0 - ## T2 - #t2aa = c2aa/self.c0 - einsum('ia,jb->ijab', t1a, t1a) + einsum('ib,ja->ijab', t1a, t1a) - #t2bb = c2bb/self.c0 - einsum('ia,jb->ijab', t1b, t1b) + einsum('ib,ja->ijab', t1b, t1b) - #t2ab = c2ab/self.c0 - einsum('ia,jb->ijab', t1a, t1b) - ## T3 - #raise NotImplementedError - ##t3aaa = c3aaa/self.c0 - einsum('ijab,kc->ijkabc', t2a, t1a) - ... - ## T4 - ##t4aaaa = c4aaaa/self.c0 - einsum('ijkabc,ld->ijklabcd', t3a, t1a) - ... - - #t1 = (t1a, t1b) - #t2 = (t2aa, t2ab, t2bb) - ## TODO - ##t3 = (t3aaa, t3aab, ...) - ##t4 = (t4aaaa, t4aaab, ...) + # TODO optimise these contractions + # TODO remove redundant permutations + c1_aa, c1_bb = (c / self.c0 for c in self.c1) + c2_aaaa, c2_abab, c2_bbbb = (c / self.c0 for c in self.c2) + c3_aaaaaa, c3_abaaba, c3_abbabb, c3_babbab, c3_bbabba, c3_bbbbbb = (c / self.c0 for c in self.c3) + c4_aaaaaaaa, c4_aaabaaab, c4_aabaaaba, c4_abaaabaa, c4_abababab, c4_bbabbbab, c4_bbbabbba, c4_bbbbbbbb = (c / self.c0 for c in self.c4) + + nocc = self.nocc + nvir = self.nvir + + t1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + t1_aa += einsum("ia->ia", c1_aa) + + t1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + t1_bb += einsum("ia->ia", c1_bb) + + t2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + t2_aaaa += einsum("ijab->ijab", c2_aaaa) * 2.0 + t2_aaaa += einsum("ia,jb->ijab", t1_aa, t1_aa) * -1.0 + t2_aaaa += einsum("ib,ja->ijab", t1_aa, t1_aa) + + t2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) + t2_abab += einsum("ijab->ijab", c2_abab) + t2_abab += einsum("ia,jb->ijab", t1_aa, t1_bb) * -1.0 + + t2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + t2_bbbb += einsum("ijab->ijab", c2_bbbb) * 2.0 + t2_bbbb += einsum("ia,jb->ijab", t1_bb, t1_bb) * -1.0 + t2_bbbb += einsum("ib,ja->ijab", t1_bb, t1_bb) + + t3_aaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + t3_aaaaaa += einsum("ijkabc->ijkabc", c3_aaaaaa) * 6.0 + t3_aaaaaa += einsum("ia,jkbc->ijkabc", t1_aa, t2_aaaa) * -2.0 + t3_aaaaaa += einsum("ib,jkac->ijkabc", t1_aa, t2_aaaa) * 2.0 + t3_aaaaaa += einsum("ic,jkab->ijkabc", t1_aa, t2_aaaa) * -2.0 + t3_aaaaaa += einsum("ja,ikbc->ijkabc", t1_aa, t2_aaaa) * 2.0 + t3_aaaaaa += einsum("jb,ikac->ijkabc", t1_aa, t2_aaaa) * -2.0 + t3_aaaaaa += einsum("jc,ikab->ijkabc", t1_aa, t2_aaaa) * 2.0 + t3_aaaaaa += einsum("ka,ijbc->ijkabc", t1_aa, t2_aaaa) * -2.0 + t3_aaaaaa += einsum("kb,ijac->ijkabc", t1_aa, t2_aaaa) * 2.0 + t3_aaaaaa += einsum("kc,ijab->ijkabc", t1_aa, t2_aaaa) * -2.0 + t3_aaaaaa += einsum("ia,jb,kc->ijkabc", t1_aa, t1_aa, t1_aa) * -1.0 + t3_aaaaaa += einsum("ia,jc,kb->ijkabc", t1_aa, t1_aa, t1_aa) + t3_aaaaaa += einsum("ib,ja,kc->ijkabc", t1_aa, t1_aa, t1_aa) + t3_aaaaaa += einsum("ib,jc,ka->ijkabc", t1_aa, t1_aa, t1_aa) * -1.0 + t3_aaaaaa += einsum("ic,ja,kb->ijkabc", t1_aa, t1_aa, t1_aa) * -1.0 + t3_aaaaaa += einsum("ic,jb,ka->ijkabc", t1_aa, t1_aa, t1_aa) + + t3_abaaba = np.zeros((nocc[0], nocc[1], nocc[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) + t3_abaaba += einsum("ijkabc->ijkabc", c3_abaaba) * 2.0 + t3_abaaba += einsum("ia,kjcb->ijkabc", t1_aa, t2_abab) * -1.0 + t3_abaaba += einsum("ic,kjab->ijkabc", t1_aa, t2_abab) + t3_abaaba += einsum("ka,ijcb->ijkabc", t1_aa, t2_abab) + t3_abaaba += einsum("kc,ijab->ijkabc", t1_aa, t2_abab) * -1.0 + t3_abaaba += einsum("jb,ikac->ijkabc", t1_bb, t2_aaaa) * -2.0 + t3_abaaba += einsum("ia,kc,jb->ijkabc", t1_aa, t1_aa, t1_bb) * -1.0 + t3_abaaba += einsum("ic,ka,jb->ijkabc", t1_aa, t1_aa, t1_bb) + + t3_abbabb = np.zeros((nocc[0], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) + t3_abbabb += einsum("ijkabc->ijkabc", c3_abbabb) * 2.0 + t3_abbabb += einsum("ia,jkbc->ijkabc", t1_aa, t2_bbbb) * -2.0 + t3_abbabb += einsum("jb,ikac->ijkabc", t1_bb, t2_abab) * -1.0 + t3_abbabb += einsum("jc,ikab->ijkabc", t1_bb, t2_abab) + t3_abbabb += einsum("kb,ijac->ijkabc", t1_bb, t2_abab) + t3_abbabb += einsum("kc,ijab->ijkabc", t1_bb, t2_abab) * -1.0 + t3_abbabb += einsum("ia,jb,kc->ijkabc", t1_aa, t1_bb, t1_bb) * -1.0 + t3_abbabb += einsum("ia,jc,kb->ijkabc", t1_aa, t1_bb, t1_bb) + + t3_babbab = np.zeros((nocc[1], nocc[0], nocc[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t3_babbab += einsum("ijkabc->ijkabc", c3_babbab) * 2.0 + t3_babbab += einsum("jb,ikac->ijkabc", t1_aa, t2_bbbb) * -2.0 + t3_babbab += einsum("ia,jkbc->ijkabc", t1_bb, t2_abab) * -1.0 + t3_babbab += einsum("ic,jkba->ijkabc", t1_bb, t2_abab) + t3_babbab += einsum("ka,jibc->ijkabc", t1_bb, t2_abab) + t3_babbab += einsum("kc,jiba->ijkabc", t1_bb, t2_abab) * -1.0 + t3_babbab += einsum("jb,ia,kc->ijkabc", t1_aa, t1_bb, t1_bb) * -1.0 + t3_babbab += einsum("jb,ic,ka->ijkabc", t1_aa, t1_bb, t1_bb) + + t3_bbabba = np.zeros((nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) + t3_bbabba += einsum("ijkabc->ijkabc", c3_bbabba) * 2.0 + t3_bbabba += einsum("kc,ijab->ijkabc", t1_aa, t2_bbbb) * -2.0 + t3_bbabba += einsum("ia,kjcb->ijkabc", t1_bb, t2_abab) * -1.0 + t3_bbabba += einsum("ib,kjca->ijkabc", t1_bb, t2_abab) + t3_bbabba += einsum("ja,kicb->ijkabc", t1_bb, t2_abab) + t3_bbabba += einsum("jb,kica->ijkabc", t1_bb, t2_abab) * -1.0 + t3_bbabba += einsum("kc,ia,jb->ijkabc", t1_aa, t1_bb, t1_bb) * -1.0 + t3_bbabba += einsum("kc,ib,ja->ijkabc", t1_aa, t1_bb, t1_bb) + + t3_bbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t3_bbbbbb += einsum("ijkabc->ijkabc", c3_bbbbbb) * 6.0 + t3_bbbbbb += einsum("ia,jkbc->ijkabc", t1_bb, t2_bbbb) * -2.0 + t3_bbbbbb += einsum("ib,jkac->ijkabc", t1_bb, t2_bbbb) * 2.0 + t3_bbbbbb += einsum("ic,jkab->ijkabc", t1_bb, t2_bbbb) * -2.0 + t3_bbbbbb += einsum("ja,ikbc->ijkabc", t1_bb, t2_bbbb) * 2.0 + t3_bbbbbb += einsum("jb,ikac->ijkabc", t1_bb, t2_bbbb) * -2.0 + t3_bbbbbb += einsum("jc,ikab->ijkabc", t1_bb, t2_bbbb) * 2.0 + t3_bbbbbb += einsum("ka,ijbc->ijkabc", t1_bb, t2_bbbb) * -2.0 + t3_bbbbbb += einsum("kb,ijac->ijkabc", t1_bb, t2_bbbb) * 2.0 + t3_bbbbbb += einsum("kc,ijab->ijkabc", t1_bb, t2_bbbb) * -2.0 + t3_bbbbbb += einsum("ia,jb,kc->ijkabc", t1_bb, t1_bb, t1_bb) * -1.0 + t3_bbbbbb += einsum("ia,jc,kb->ijkabc", t1_bb, t1_bb, t1_bb) + t3_bbbbbb += einsum("ib,ja,kc->ijkabc", t1_bb, t1_bb, t1_bb) + t3_bbbbbb += einsum("ib,jc,ka->ijkabc", t1_bb, t1_bb, t1_bb) * -1.0 + t3_bbbbbb += einsum("ic,ja,kb->ijkabc", t1_bb, t1_bb, t1_bb) * -1.0 + t3_bbbbbb += einsum("ic,jb,ka->ijkabc", t1_bb, t1_bb, t1_bb) + + t4_aaaaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + t4_aaaaaaaa += einsum("ijklabcd->ijklabcd", c4_aaaaaaaa) * 24.0 + t4_aaaaaaaa += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 + t4_aaaaaaaa += einsum("ib,jklacd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 + t4_aaaaaaaa += einsum("ic,jklabd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 + t4_aaaaaaaa += einsum("id,jklabc->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 + t4_aaaaaaaa += einsum("ja,iklbcd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 + t4_aaaaaaaa += einsum("jb,iklacd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 + t4_aaaaaaaa += einsum("jc,iklabd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 + t4_aaaaaaaa += einsum("jd,iklabc->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 + t4_aaaaaaaa += einsum("ka,ijlbcd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 + t4_aaaaaaaa += einsum("kb,ijlacd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 + t4_aaaaaaaa += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 + t4_aaaaaaaa += einsum("kd,ijlabc->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 + t4_aaaaaaaa += einsum("la,ijkbcd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 + t4_aaaaaaaa += einsum("lb,ijkacd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 + t4_aaaaaaaa += einsum("lc,ijkabd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 + t4_aaaaaaaa += einsum("ld,ijkabc->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 + t4_aaaaaaaa += einsum("ikac,jlbd->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ikad,jlbc->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 + t4_aaaaaaaa += einsum("ikab,jlcd->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 + t4_aaaaaaaa += einsum("ikbc,jlad->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 + t4_aaaaaaaa += einsum("ikbd,jlac->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ikcd,jlab->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 + t4_aaaaaaaa += einsum("ilac,jkbd->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 + t4_aaaaaaaa += einsum("ilad,jkbc->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ilab,jkcd->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ilbc,jkad->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ilbd,jkac->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 + t4_aaaaaaaa += einsum("ilcd,jkab->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ijac,klbd->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 + t4_aaaaaaaa += einsum("ijad,klbc->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ijab,klcd->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ijbc,klad->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ijbd,klac->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 + t4_aaaaaaaa += einsum("ijcd,klab->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 + t4_aaaaaaaa += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ia,jc,klbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ia,jd,klbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ib,ja,klcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ib,jc,klad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ib,jd,klac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ic,ja,klbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ic,jb,klad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ic,jd,klab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("id,ja,klbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("id,jb,klac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("id,jc,klab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ia,kb,jlcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ia,kd,jlbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ib,ka,jlcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ib,kc,jlad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ib,kd,jlac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ic,ka,jlbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ic,kb,jlad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ic,kd,jlab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("id,ka,jlbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("id,kb,jlac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("id,kc,jlab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ia,lb,jkcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ia,lc,jkbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ia,ld,jkbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ib,la,jkcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ib,lc,jkad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ib,ld,jkac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ic,la,jkbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ic,lb,jkad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ic,ld,jkab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("id,la,jkbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("id,lb,jkac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("id,lc,jkab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ja,kb,ilcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ja,kc,ilbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ja,kd,ilbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jb,ka,ilcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jb,kc,ilad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jb,kd,ilac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jc,ka,ilbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jc,kb,ilad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jc,kd,ilab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jd,ka,ilbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jd,kb,ilac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jd,kc,ilab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ja,lb,ikcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ja,lc,ikbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ja,ld,ikbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jb,la,ikcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jb,lc,ikad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jb,ld,ikac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jc,la,ikbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jc,lb,ikad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jc,ld,ikab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jd,la,ikbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("jd,lb,ikac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("jd,lc,ikab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ka,lb,ijcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("ka,lc,ijbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ka,ld,ijbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("kb,la,ijcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("kb,lc,ijad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("kb,ld,ijac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("kc,la,ijbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("kc,lb,ijad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("kd,la,ijbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("kd,lb,ijac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 + t4_aaaaaaaa += einsum("kd,lc,ijab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 + t4_aaaaaaaa += einsum("ia,jb,kc,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ia,jb,kd,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("ia,jc,kb,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("ia,jc,kd,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ia,jd,kb,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ia,jd,kc,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("ib,ja,kc,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("ib,ja,kd,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ib,jc,ka,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ib,jc,kd,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("ib,jd,ka,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("ib,jd,kc,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ic,ja,kb,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ic,ja,kd,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("ic,jb,ka,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("ic,jb,kd,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ic,jd,ka,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("ic,jd,kb,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("id,ja,kb,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("id,ja,kc,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("id,jb,ka,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + t4_aaaaaaaa += einsum("id,jb,kc,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("id,jc,ka,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) + t4_aaaaaaaa += einsum("id,jc,kb,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 + + t4_aaabaaab = np.zeros((nocc[0], nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[0], nvir[1]), dtype=np.float64) + t4_aaabaaab += einsum("ijklabcd->ijklabcd", c4_aaabaaab) * 6.0 + t4_aaabaaab += einsum("ia,jlkbdc->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aaabaaab += einsum("ib,jlkadc->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_aaabaaab += einsum("ic,jlkadb->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aaabaaab += einsum("ja,ilkbdc->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_aaabaaab += einsum("jb,ilkadc->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aaabaaab += einsum("jc,ilkadb->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_aaabaaab += einsum("ka,iljbdc->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aaabaaab += einsum("kb,iljadc->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_aaabaaab += einsum("kc,iljadb->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aaabaaab += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_aaaaaa) * -6.0 + t4_aaabaaab += einsum("ilad,jkbc->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("ilbd,jkac->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_aaabaaab += einsum("ilcd,jkab->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("jlad,ikbc->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_aaabaaab += einsum("jlbd,ikac->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("jlcd,ikab->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_aaabaaab += einsum("klad,ijbc->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("klbd,ijac->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_aaabaaab += einsum("klcd,ijab->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("ia,jc,klbd->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("ib,ja,klcd->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("ib,jc,klad->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("ic,ja,klbd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("ic,jb,klad->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("ia,kb,jlcd->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("ib,ka,jlcd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("ib,kc,jlad->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("ic,ka,jlbd->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("ic,kb,jlad->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("ja,kb,ilcd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("ja,kc,ilbd->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("jb,ka,ilcd->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("jb,kc,ilad->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("jc,ka,ilbd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aaabaaab += einsum("jc,kb,ilad->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aaabaaab += einsum("ia,ld,jkbc->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("ib,ld,jkac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_aaabaaab += einsum("ic,ld,jkab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("ja,ld,ikbc->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_aaabaaab += einsum("jb,ld,ikac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("jc,ld,ikab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_aaabaaab += einsum("ka,ld,ijbc->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("kb,ld,ijac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_aaabaaab += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aaabaaab += einsum("ia,jb,kc,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_aaabaaab += einsum("ia,jc,kb,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + t4_aaabaaab += einsum("ib,ja,kc,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + t4_aaabaaab += einsum("ib,jc,ka,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_aaabaaab += einsum("ic,ja,kb,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_aaabaaab += einsum("ic,jb,ka,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + + t4_aabaaaba = np.zeros((nocc[0], nocc[0], nocc[1], nocc[0], nvir[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) + t4_aabaaaba += einsum("ijklabcd->ijklabcd", c4_aabaaaba) * 6.0 + t4_aabaaaba += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aabaaaba += einsum("ib,jklacd->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_aabaaaba += einsum("id,jklacb->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aabaaaba += einsum("ja,iklbcd->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_aabaaaba += einsum("jb,iklacd->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aabaaaba += einsum("jd,iklacb->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_aabaaaba += einsum("la,ikjbcd->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aabaaaba += einsum("lb,ikjacd->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_aabaaaba += einsum("ld,ikjacb->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_aabaaaba += einsum("kc,ijlabd->ijklabcd", t1_bb, t3_aaaaaa) * -6.0 + t4_aabaaaba += einsum("ikac,jlbd->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("ikbc,jlad->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_aabaaaba += einsum("ikdc,jlab->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("jkac,ilbd->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_aabaaaba += einsum("jkbc,ilad->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("jkdc,ilab->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_aabaaaba += einsum("lkac,ijbd->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("lkbc,ijad->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_aabaaaba += einsum("lkdc,ijab->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("ia,jb,lkdc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("ia,jd,lkbc->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("ib,ja,lkdc->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("ib,jd,lkac->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("id,ja,lkbc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("id,jb,lkac->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("ia,lb,jkdc->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("ia,ld,jkbc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("ib,la,jkdc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("ib,ld,jkac->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("id,la,jkbc->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("id,lb,jkac->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("ja,lb,ikdc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("ja,ld,ikbc->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("jb,la,ikdc->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("jb,ld,ikac->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("jd,la,ikbc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_aabaaaba += einsum("jd,lb,ikac->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_aabaaaba += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("ib,kc,jlad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_aabaaaba += einsum("id,kc,jlab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("ja,kc,ilbd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_aabaaaba += einsum("jb,kc,ilad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("jd,kc,ilab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_aabaaaba += einsum("la,kc,ijbd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("lb,kc,ijad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_aabaaaba += einsum("ld,kc,ijab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_aabaaaba += einsum("ia,jb,ld,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_aabaaaba += einsum("ia,jd,lb,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + t4_aabaaaba += einsum("ib,ja,ld,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + t4_aabaaaba += einsum("ib,jd,la,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_aabaaaba += einsum("id,ja,lb,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_aabaaaba += einsum("id,jb,la,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + + t4_abaaabaa = np.zeros((nocc[0], nocc[1], nocc[0], nocc[0], nvir[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) + t4_abaaabaa += einsum("ijklabcd->ijklabcd", c4_abaaabaa) * 6.0 + t4_abaaabaa += einsum("ia,kjlcbd->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_abaaabaa += einsum("ic,kjlabd->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_abaaabaa += einsum("id,kjlabc->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_abaaabaa += einsum("ka,ijlcbd->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_abaaabaa += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_abaaabaa += einsum("kd,ijlabc->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_abaaabaa += einsum("la,ijkcbd->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_abaaabaa += einsum("lc,ijkabd->ijklabcd", t1_aa, t3_abaaba) * 2.0 + t4_abaaabaa += einsum("ld,ijkabc->ijklabcd", t1_aa, t3_abaaba) * -2.0 + t4_abaaabaa += einsum("jb,iklacd->ijklabcd", t1_bb, t3_aaaaaa) * -6.0 + t4_abaaabaa += einsum("ijab,klcd->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("ijcb,klad->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_abaaabaa += einsum("ijdb,klac->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("kjab,ilcd->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_abaaabaa += einsum("kjcb,ilad->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("kjdb,ilac->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_abaaabaa += einsum("ljab,ikcd->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("ljcb,ikad->ijklabcd", t2_abab, t2_aaaa) * 2.0 + t4_abaaabaa += einsum("ljdb,ikac->ijklabcd", t2_abab, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("ia,kc,ljdb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("ia,kd,ljcb->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("ic,ka,ljdb->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("ic,kd,ljab->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("id,ka,ljcb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("id,kc,ljab->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("ia,lc,kjdb->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("ia,ld,kjcb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("ic,la,kjdb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("ic,ld,kjab->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("id,la,kjcb->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("id,lc,kjab->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("ka,lc,ijdb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("ka,ld,ijcb->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("kc,la,ijdb->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("kd,la,ijcb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 + t4_abaaabaa += einsum("kd,lc,ijab->ijklabcd", t1_aa, t1_aa, t2_abab) + t4_abaaabaa += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("ic,jb,klad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_abaaabaa += einsum("id,jb,klac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("ka,jb,ilcd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_abaaabaa += einsum("kc,jb,ilad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("kd,jb,ilac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_abaaabaa += einsum("la,jb,ikcd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("lc,jb,ikad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 + t4_abaaabaa += einsum("ld,jb,ikac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 + t4_abaaabaa += einsum("ia,kc,ld,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_abaaabaa += einsum("ia,kd,lc,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + t4_abaaabaa += einsum("ic,ka,ld,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + t4_abaaabaa += einsum("ic,kd,la,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_abaaabaa += einsum("id,ka,lc,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 + t4_abaaabaa += einsum("id,kc,la,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) + + t4_abababab = np.zeros((nocc[0], nocc[1], nocc[0], nocc[1], nvir[0], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t4_abababab += einsum("ijklabcd->ijklabcd", c4_abababab) * 4.0 + t4_abababab += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_babbab) * -2.0 + t4_abababab += einsum("ic,jklbad->ijklabcd", t1_aa, t3_babbab) * 2.0 + t4_abababab += einsum("ka,ijlcbd->ijklabcd", t1_aa, t3_abbabb) * 2.0 + t4_abababab += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_abbabb) * -2.0 + t4_abababab += einsum("jb,ilkadc->ijklabcd", t1_bb, t3_abaaba) * -2.0 + t4_abababab += einsum("jd,ilkabc->ijklabcd", t1_bb, t3_abaaba) * 2.0 + t4_abababab += einsum("lb,ijkadc->ijklabcd", t1_bb, t3_abaaba) * 2.0 + t4_abababab += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_abaaba) * -2.0 + t4_abababab += einsum("ijab,klcd->ijklabcd", t2_abab, t2_abab) * -1.0 + t4_abababab += einsum("ijad,klcb->ijklabcd", t2_abab, t2_abab) + t4_abababab += einsum("ijcb,klad->ijklabcd", t2_abab, t2_abab) + t4_abababab += einsum("ijcd,klab->ijklabcd", t2_abab, t2_abab) * -1.0 + t4_abababab += einsum("ilab,kjcd->ijklabcd", t2_abab, t2_abab) + t4_abababab += einsum("ilad,kjcb->ijklabcd", t2_abab, t2_abab) * -1.0 + t4_abababab += einsum("ilcb,kjad->ijklabcd", t2_abab, t2_abab) * -1.0 + t4_abababab += einsum("ilcd,kjab->ijklabcd", t2_abab, t2_abab) + t4_abababab += einsum("ikac,jlbd->ijklabcd", t2_aaaa, t2_bbbb) * -4.0 + t4_abababab += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_aa, t2_bbbb) * -2.0 + t4_abababab += einsum("ic,ka,jlbd->ijklabcd", t1_aa, t1_aa, t2_bbbb) * 2.0 + t4_abababab += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 + t4_abababab += einsum("ia,jd,klcb->ijklabcd", t1_aa, t1_bb, t2_abab) + t4_abababab += einsum("ic,jb,klad->ijklabcd", t1_aa, t1_bb, t2_abab) + t4_abababab += einsum("ic,jd,klab->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 + t4_abababab += einsum("ia,lb,kjcd->ijklabcd", t1_aa, t1_bb, t2_abab) + t4_abababab += einsum("ia,ld,kjcb->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 + t4_abababab += einsum("ic,lb,kjad->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 + t4_abababab += einsum("ic,ld,kjab->ijklabcd", t1_aa, t1_bb, t2_abab) + t4_abababab += einsum("ka,jb,ilcd->ijklabcd", t1_aa, t1_bb, t2_abab) + t4_abababab += einsum("ka,jd,ilcb->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 + t4_abababab += einsum("kc,jb,ilad->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 + t4_abababab += einsum("kc,jd,ilab->ijklabcd", t1_aa, t1_bb, t2_abab) + t4_abababab += einsum("ka,lb,ijcd->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 + t4_abababab += einsum("ka,ld,ijcb->ijklabcd", t1_aa, t1_bb, t2_abab) + t4_abababab += einsum("kc,lb,ijad->ijklabcd", t1_aa, t1_bb, t2_abab) + t4_abababab += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 + t4_abababab += einsum("jb,ld,ikac->ijklabcd", t1_bb, t1_bb, t2_aaaa) * -2.0 + t4_abababab += einsum("jd,lb,ikac->ijklabcd", t1_bb, t1_bb, t2_aaaa) * 2.0 + t4_abababab += einsum("ia,kc,jb,ld->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) * -1.0 + t4_abababab += einsum("ia,kc,jd,lb->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) + t4_abababab += einsum("ic,ka,jb,ld->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) + t4_abababab += einsum("ic,ka,jd,lb->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) * -1.0 + + t4_bbabbbab = np.zeros((nocc[1], nocc[1], nocc[0], nocc[1], nvir[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t4_bbabbbab += einsum("ijklabcd->ijklabcd", c4_bbabbbab) * 6.0 + t4_bbabbbab += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_bbbbbb) * -6.0 + t4_bbabbbab += einsum("ia,jklbcd->ijklabcd", t1_bb, t3_babbab) * -2.0 + t4_bbabbbab += einsum("ib,jklacd->ijklabcd", t1_bb, t3_babbab) * 2.0 + t4_bbabbbab += einsum("id,jklacb->ijklabcd", t1_bb, t3_babbab) * -2.0 + t4_bbabbbab += einsum("ja,iklbcd->ijklabcd", t1_bb, t3_babbab) * 2.0 + t4_bbabbbab += einsum("jb,iklacd->ijklabcd", t1_bb, t3_babbab) * -2.0 + t4_bbabbbab += einsum("jd,iklacb->ijklabcd", t1_bb, t3_babbab) * 2.0 + t4_bbabbbab += einsum("la,ijkbdc->ijklabcd", t1_bb, t3_bbabba) * -2.0 + t4_bbabbbab += einsum("lb,ijkadc->ijklabcd", t1_bb, t3_bbabba) * 2.0 + t4_bbabbbab += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_bbabba) * -2.0 + t4_bbabbbab += einsum("kjcb,ilad->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("kjcd,ilab->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_bbabbbab += einsum("kjca,ilbd->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_bbabbbab += einsum("klcb,ijad->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_bbabbbab += einsum("klcd,ijab->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("klca,ijbd->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("kicb,jlad->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_bbabbbab += einsum("kicd,jlab->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("kica,jlbd->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("kc,ia,jlbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("kc,ib,jlad->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_bbabbbab += einsum("kc,id,jlab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("kc,ja,ilbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_bbabbbab += einsum("kc,jb,ilad->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("kc,jd,ilab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_bbabbbab += einsum("kc,la,ijbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("kc,lb,ijad->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_bbabbbab += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbabbbab += einsum("ia,jb,klcd->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("ia,jd,klcb->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("ib,ja,klcd->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("ib,jd,klca->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("id,ja,klcb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("id,jb,klca->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("ia,lb,kjcd->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("ia,ld,kjcb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("ib,la,kjcd->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("ib,ld,kjca->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("id,la,kjcb->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("id,lb,kjca->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("ja,lb,kicd->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("ja,ld,kicb->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("jb,la,kicd->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("jb,ld,kica->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("jd,la,kicb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbabbbab += einsum("jd,lb,kica->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbabbbab += einsum("kc,ia,jb,ld->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbabbbab += einsum("kc,ia,jd,lb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + t4_bbabbbab += einsum("kc,ib,ja,ld->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + t4_bbabbbab += einsum("kc,ib,jd,la->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbabbbab += einsum("kc,id,ja,lb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbabbbab += einsum("kc,id,jb,la->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + + t4_bbbabbba = np.zeros((nocc[1], nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[1], nvir[0]), dtype=np.float64) + t4_bbbabbba += einsum("ijklabcd->ijklabcd", c4_bbbabbba) * 6.0 + t4_bbbabbba += einsum("ld,ijkabc->ijklabcd", t1_aa, t3_bbbbbb) * -6.0 + t4_bbbabbba += einsum("ia,jklbcd->ijklabcd", t1_bb, t3_bbabba) * -2.0 + t4_bbbabbba += einsum("ib,jklacd->ijklabcd", t1_bb, t3_bbabba) * 2.0 + t4_bbbabbba += einsum("ic,jklabd->ijklabcd", t1_bb, t3_bbabba) * -2.0 + t4_bbbabbba += einsum("ja,iklbcd->ijklabcd", t1_bb, t3_bbabba) * 2.0 + t4_bbbabbba += einsum("jb,iklacd->ijklabcd", t1_bb, t3_bbabba) * -2.0 + t4_bbbabbba += einsum("jc,iklabd->ijklabcd", t1_bb, t3_bbabba) * 2.0 + t4_bbbabbba += einsum("ka,ijlbcd->ijklabcd", t1_bb, t3_bbabba) * -2.0 + t4_bbbabbba += einsum("kb,ijlacd->ijklabcd", t1_bb, t3_bbabba) * 2.0 + t4_bbbabbba += einsum("kc,ijlabd->ijklabcd", t1_bb, t3_bbabba) * -2.0 + t4_bbbabbba += einsum("ljdb,ikac->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("ljdc,ikab->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_bbbabbba += einsum("ljda,ikbc->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_bbbabbba += einsum("lkdb,ijac->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_bbbabbba += einsum("lkdc,ijab->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("lkda,ijbc->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("lidb,jkac->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_bbbabbba += einsum("lidc,jkab->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("lida,jkbc->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("ld,ia,jkbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("ld,ib,jkac->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_bbbabbba += einsum("ld,ic,jkab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("ld,ja,ikbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_bbbabbba += einsum("ld,jb,ikac->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("ld,jc,ikab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_bbbabbba += einsum("ld,ka,ijbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("ld,kb,ijac->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_bbbabbba += einsum("ld,kc,ijab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_bbbabbba += einsum("ia,jb,lkdc->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("ia,jc,lkdb->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("ib,ja,lkdc->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("ib,jc,lkda->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("ic,ja,lkdb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("ic,jb,lkda->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("ia,kb,ljdc->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("ia,kc,ljdb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("ib,ka,ljdc->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("ib,kc,ljda->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("ic,ka,ljdb->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("ic,kb,ljda->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("ja,kb,lidc->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("ja,kc,lidb->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("jb,ka,lidc->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("jb,kc,lida->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("jc,ka,lidb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_bbbabbba += einsum("jc,kb,lida->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_bbbabbba += einsum("ld,ia,jb,kc->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbabbba += einsum("ld,ia,jc,kb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + t4_bbbabbba += einsum("ld,ib,ja,kc->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + t4_bbbabbba += einsum("ld,ib,jc,ka->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbabbba += einsum("ld,ic,ja,kb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbabbba += einsum("ld,ic,jb,ka->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + + t4_bbbbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t4_bbbbbbbb += einsum("ijklabcd->ijklabcd", c4_bbbbbbbb) * 24.0 + t4_bbbbbbbb += einsum("ia,jklbcd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 + t4_bbbbbbbb += einsum("ib,jklacd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 + t4_bbbbbbbb += einsum("ic,jklabd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 + t4_bbbbbbbb += einsum("id,jklabc->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 + t4_bbbbbbbb += einsum("ja,iklbcd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 + t4_bbbbbbbb += einsum("jb,iklacd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 + t4_bbbbbbbb += einsum("jc,iklabd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 + t4_bbbbbbbb += einsum("jd,iklabc->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 + t4_bbbbbbbb += einsum("ka,ijlbcd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 + t4_bbbbbbbb += einsum("kb,ijlacd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 + t4_bbbbbbbb += einsum("kc,ijlabd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 + t4_bbbbbbbb += einsum("kd,ijlabc->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 + t4_bbbbbbbb += einsum("la,ijkbcd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 + t4_bbbbbbbb += einsum("lb,ijkacd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 + t4_bbbbbbbb += einsum("lc,ijkabd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 + t4_bbbbbbbb += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 + t4_bbbbbbbb += einsum("ikac,jlbd->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ikad,jlbc->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 + t4_bbbbbbbb += einsum("ikab,jlcd->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 + t4_bbbbbbbb += einsum("ikbc,jlad->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 + t4_bbbbbbbb += einsum("ikbd,jlac->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ikcd,jlab->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 + t4_bbbbbbbb += einsum("ilac,jkbd->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 + t4_bbbbbbbb += einsum("ilad,jkbc->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ilab,jkcd->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ilbc,jkad->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ilbd,jkac->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 + t4_bbbbbbbb += einsum("ilcd,jkab->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ijac,klbd->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 + t4_bbbbbbbb += einsum("ijad,klbc->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ijab,klcd->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ijbc,klad->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ijbd,klac->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 + t4_bbbbbbbb += einsum("ijcd,klab->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 + t4_bbbbbbbb += einsum("ia,jb,klcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ia,jc,klbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ia,jd,klbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ib,ja,klcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ib,jc,klad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ib,jd,klac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ic,ja,klbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ic,jb,klad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ic,jd,klab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("id,ja,klbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("id,jb,klac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("id,jc,klab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ia,kb,jlcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ia,kc,jlbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ia,kd,jlbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ib,ka,jlcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ib,kc,jlad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ib,kd,jlac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ic,ka,jlbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ic,kb,jlad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ic,kd,jlab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("id,ka,jlbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("id,kb,jlac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("id,kc,jlab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ia,lb,jkcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ia,lc,jkbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ia,ld,jkbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ib,la,jkcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ib,lc,jkad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ib,ld,jkac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ic,la,jkbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ic,lb,jkad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ic,ld,jkab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("id,la,jkbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("id,lb,jkac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("id,lc,jkab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ja,kb,ilcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ja,kc,ilbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ja,kd,ilbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jb,ka,ilcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jb,kc,ilad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jb,kd,ilac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jc,ka,ilbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jc,kb,ilad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jc,kd,ilab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jd,ka,ilbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jd,kb,ilac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jd,kc,ilab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ja,lb,ikcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ja,lc,ikbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ja,ld,ikbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jb,la,ikcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jb,lc,ikad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jb,ld,ikac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jc,la,ikbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jc,lb,ikad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jc,ld,ikab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jd,la,ikbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("jd,lb,ikac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("jd,lc,ikab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ka,lb,ijcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("ka,lc,ijbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ka,ld,ijbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("kb,la,ijcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("kb,lc,ijad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("kb,ld,ijac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("kc,la,ijbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("kc,lb,ijad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("kc,ld,ijab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("kd,la,ijbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("kd,lb,ijac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 + t4_bbbbbbbb += einsum("kd,lc,ijab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 + t4_bbbbbbbb += einsum("ia,jb,kc,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ia,jb,kd,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("ia,jc,kb,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("ia,jc,kd,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ia,jd,kb,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ia,jd,kc,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("ib,ja,kc,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("ib,ja,kd,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ib,jc,ka,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ib,jc,kd,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("ib,jd,ka,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("ib,jd,kc,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ic,ja,kb,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ic,ja,kd,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("ic,jb,ka,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("ic,jb,kd,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ic,jd,ka,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("ic,jd,kb,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("id,ja,kb,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("id,ja,kc,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("id,jb,ka,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + t4_bbbbbbbb += einsum("id,jb,kc,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("id,jc,ka,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) + t4_bbbbbbbb += einsum("id,jc,kb,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + + t1 = (t1_aa, t1_bb) + t2 = (t2_aaaa, t2_abab, t2_bbbb) + t3 = (t3_aaaaaa, t3_abaaba, t3_abbabb, t3_babbab, t3_bbabba, t3_bbbbbb) + t4 = (t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb) return wf_types.UCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index efe9423f8..264e29342 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -587,6 +587,7 @@ def as_cisdtq(self, c0=None): c3_aab.transpose(0, 2, 1, 3, 5, 4), c3_abb, c3_abb.transpose(1, 0, 2, 4, 3, 5), + c3_abb.transpose(2, 1, 0, 5, 4, 3), c3_bbb, ) c4 = ( From 5ba49339787dde3bdc268536ffdbfe2fcc5262d3 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 27 Jan 2023 14:44:15 +0000 Subject: [PATCH 30/66] Adds routine to build external correction in UHF --- vayesta/solver/coupling.py | 149 ++++++++++++++++++++++++++++++++----- 1 file changed, 130 insertions(+), 19 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 5296ba8ad..9f47ec134 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -281,16 +281,12 @@ def _integrals_for_extcorr(fragment, fock): vb = np.s_[cluster.nocc_active[1]:] fova = dot(cluster.c_active_occ[0].T, fock[0], cluster.c_active_vir[0]) fovb = dot(cluster.c_active_occ[1].T, fock[1], cluster.c_active_vir[1]) - # TODO: Sort out the code below: Should be referring to eris[0], eris[1] and eris[2] - govovaa = eris[oa,va,oa,va] - govovab = eris[oa,va,ob,vb] - govovbb = eris[ob,vb,ob,vb] + # TODO make consistent with RHF return value fov = (fova, fovb) - govov = (govovaa, govovab, govovbb) - gvvov = None - gooov = None - govoo = None - raise NotImplementedError + gooov = (eris[0][oa, oa, oa, va], eris[1][oa, oa, ob, vb], eris[2][ob, ob, ob, vb]) + govov = (eris[0][oa, va, oa, va], eris[1][oa, va, ob, vb], eris[2][ob, vb, ob, vb]) + govvv = (eris[0][oa, va, va, va], eris[1][oa, va, vb, vb], eris[2][ob, vb, vb, vb]) + return fov, gooov, govov, govvv return fov, govov, gvvov, gooov, govoo def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extcorr=False): @@ -326,19 +322,21 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc """ wf = fragment.results.wf.as_ccsdtq() - t1, t2, t3 = wf.t1, wf.t2, wf.t3 - t4_abaa, t4_abab = wf.t4 - # Get ERIs and Fock matrix for the given fragment - # govov is (ia|jb) - fov, govov, gvvov, gooov, govoo = _integrals_for_extcorr(fragment, fock) # --- Make correction to T1 and T2 amplitudes # J. Chem. Theory Comput. 2021, 17, 182−190 # also with reference to git@github.com:gustavojra/Methods.git - dt1 = spinalg.zeros_like(t1) - dt2 = spinalg.zeros_like(t2) if fragment.base.spinsym == 'restricted': + # Get ERIs and Fock matrix for the given fragment + # govov is (ia|jb) + fov, govov, gvvov, gooov, govoo = _integrals_for_extcorr(fragment, fock) + t1, t2, t3 = wf.t1, wf.t2, wf.t3 + t4_abaa, t4_abab = wf.t4 + + dt1 = spinalg.zeros_like(t1) + dt2 = spinalg.zeros_like(t2) + # Construct physical antisymmetrized integrals for some contractions # Note that some contractions are with physical and some chemical integrals (govov) antiphys_g = (govov - govov.transpose(0,3,2,1)).transpose(0,2,1,3) @@ -448,9 +446,122 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc assert(np.allclose(t3v_test, t3v)) elif fragment.base.spinsym == 'unrestricted': - raise NotImplementedError - # TODO - pass + # Get ERIs and Fock matrix for the given fragment + (f_aa_ov, f_bb_ov), \ + (v_aaaa_ooov, v_aabb_ooov, v_bbbb_ooov), \ + (v_aaaa_ovov, v_aabb_ovov, v_bbbb_ovov), \ + (v_aaaa_ovvv, v_aabb_ovvv, v_bbbb_ovvv) = _integrals_for_extcorr(fragment, fock) + + t1_aa, t1_bb = wf.t1 + t2_aaaa, t2_abab, t2_bbbb = wf.t2 + t3_aaaaaa, t3_abaaba, t3_abbabb, t3_babbab, t3_bbabba, t3_bbbbbb = wf.t3 + t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb = wf.t4 + + dt1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + dt1_aa += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_abaaba) + dt1_aa += einsum("jbkc,ikjacb->ia", v_aabb_ovov, t3_abaaba) + dt1_aa += einsum("jbkc,ijkabc->ia", v_aaaa_ovov, t3_aaaaaa) * 3.0 + dt1_aa += einsum("jbkc,ijkabc->ia", v_bbbb_ovov, t3_abbabb) + + dt1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + dt1_bb += einsum("jbkc,jikbac->ia", v_aaaa_ovov, t3_abaaba) + dt1_bb += einsum("jbkc,ijkabc->ia", v_aabb_ovov, t3_babbab) + dt1_bb += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_bbabba) + dt1_bb += einsum("jbkc,ijkabc->ia", v_bbbb_ovov, t3_bbbbbb) * 3.0 + + dt2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + dt2_aaaa += einsum("kc,ikjacb->ijab", f_bb_ov, t3_abaaba) * 2.0 + dt2_aaaa += einsum("kc,ijkabc->ijab", f_aa_ov, t3_aaaaaa) * 6.0 + dt2_aaaa += einsum("iklc,jlkacb->ijab", v_aabb_ooov, t3_abaaba) * 2.0 + dt2_aaaa += einsum("jklc,ilkacb->ijab", v_aabb_ooov, t3_abaaba) * -2.0 + dt2_aaaa += einsum("kcad,ikjbcd->ijab", v_bbaa_ovvv, t3_abaaba) * -2.0 + dt2_aaaa += einsum("kcbd,ikjacd->ijab", v_bbaa_ovvv, t3_abaaba) * 2.0 + dt2_aaaa += einsum("iklc,jklabc->ijab", v_aaaa_ooov, t3_aaaaaa) * 6.0 + dt2_aaaa += einsum("jklc,iklabc->ijab", v_aaaa_ooov, t3_aaaaaa) * -6.0 + dt2_aaaa += einsum("kcad,ijkbcd->ijab", v_aaaa_ovvv, t3_aaaaaa) * 6.0 + dt2_aaaa += einsum("kcbd,ijkacd->ijab", v_aaaa_ovvv, t3_aaaaaa) * -6.0 + dt2_aaaa += einsum("ic,kcld,jlkadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) + dt2_aaaa += einsum("ic,kdlc,jkladb->ijab", t1_aa, v_bbaa_ovov, t3_abaaba) + dt2_aaaa += einsum("jc,kcld,ilkadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * -1.0 + dt2_aaaa += einsum("jc,kdlc,ikladb->ijab", t1_aa, v_bbaa_ovov, t3_abaaba) * -1.0 + dt2_aaaa += einsum("ka,kcld,iljbdc->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * 2.0 + dt2_aaaa += einsum("kb,kcld,iljadc->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * -2.0 + dt2_aaaa += einsum("kc,kcld,iljadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * 2.0 + dt2_aaaa += einsum("ic,kcld,jklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 3.0 + dt2_aaaa += einsum("ic,kdlc,jklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -3.0 + dt2_aaaa += einsum("jc,kcld,iklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -3.0 + dt2_aaaa += einsum("jc,kdlc,iklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 3.0 + dt2_aaaa += einsum("ka,kcld,ijlbcd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 6.0 + dt2_aaaa += einsum("kb,kcld,ijlacd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -6.0 + dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 6.0 + dt2_aaaa += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -6.0 + dt2_aaaa += einsum("kc,kcld,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) * 2.0 + dt2_aaaa += einsum("kc,kdlc,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) * -2.0 + dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_aaaaaa) * 6.0 + + dt2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + dt2_bbbb += einsum("kc,ijkabc->ijab", f_aa_ov, t3_bbabba) * 2.0 + dt2_bbbb += einsum("kc,ijkabc->ijab", f_bb_ov, t3_bbbbbb) * 6.0 + dt2_bbbb += einsum("iklc,jklabc->ijab", v_bbaa_ooov, t3_bbabba) * 2.0 + dt2_bbbb += einsum("iklc,jklabc->ijab", v_bbbb_ooov, t3_bbbbbb) * 6.0 + dt2_bbbb += einsum("jklc,iklabc->ijab", v_bbaa_ooov, t3_bbabba) * -2.0 + dt2_bbbb += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) * -6.0 + dt2_bbbb += einsum("kcad,ijkbcd->ijab", v_bbbb_ovvv, t3_bbbbbb) * 6.0 + dt2_bbbb += einsum("kcad,ijkbdc->ijab", v_aabb_ovvv, t3_bbabba) * -2.0 + dt2_bbbb += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) * -6.0 + dt2_bbbb += einsum("kcbd,ijkadc->ijab", v_aabb_ovvv, t3_bbabba) * 2.0 + dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_bbabba) * 2.0 + dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aabb_ovov, t3_bbbbbb) * 6.0 + dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_bbabba) * -2.0 + dt2_bbbb += einsum("ic,kcld,jklabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) + dt2_bbbb += einsum("ic,kcld,jklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 3.0 + dt2_bbbb += einsum("ic,kdlc,jkladb->ijab", t1_bb, v_aabb_ovov, t3_babbab) + dt2_bbbb += einsum("ic,kdlc,jklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -3.0 + dt2_bbbb += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * -1.0 + dt2_bbbb += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -3.0 + dt2_bbbb += einsum("jc,kdlc,ikladb->ijab", t1_bb, v_aabb_ovov, t3_babbab) * -1.0 + dt2_bbbb += einsum("jc,kdlc,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 3.0 + dt2_bbbb += einsum("ka,kcld,ijlbcd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * 2.0 + dt2_bbbb += einsum("ka,kcld,ijlbcd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 6.0 + dt2_bbbb += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * -2.0 + dt2_bbbb += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -6.0 + dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * 2.0 + dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 6.0 + dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -6.0 + + dt2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) + dt2_abab += einsum("kc,ijkabc->ijab", f_aa_ov, t3_abaaba) * 2.0 + dt2_abab += einsum("kc,ijkabc->ijab", f_bb_ov, t3_abbabb) * 2.0 + dt2_abab += einsum("iklc,kjlabc->ijab", v_aaaa_ooov, t3_abaaba) * -2.0 + dt2_abab += einsum("jklc,iklabc->ijab", v_bbaa_ooov, t3_abaaba) * -2.0 + dt2_abab += einsum("kcad,ijkcbd->ijab", v_aaaa_ovvv, t3_abaaba) * -2.0 + dt2_abab += einsum("kcbd,ijkadc->ijab", v_aabb_ovvv, t3_abaaba) * 2.0 + dt2_abab += einsum("iklc,jklbac->ijab", v_aabb_ooov, t3_babbab) * -2.0 + dt2_abab += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_abbabb) * -2.0 + dt2_abab += einsum("kcad,ijkdbc->ijab", v_bbaa_ovvv, t3_abbabb) * 2.0 + dt2_abab += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_abbabb) * -2.0 + dt2_abab += einsum("ic,kcld,kjlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -1.0 + dt2_abab += einsum("ic,kdlc,kjlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) + dt2_abab += einsum("ka,kcld,ijlcbd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -2.0 + dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * 2.0 + dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -2.0 + dt2_abab += einsum("ic,kcld,jklbad->ijab", t1_aa, v_aabb_ovov, t3_babbab) * -1.0 + dt2_abab += einsum("ic,kdlc,jklbda->ijab", t1_aa, v_bbaa_ovov, t3_bbabba) * -1.0 + dt2_abab += einsum("ka,kcld,ijlcbd->ijab", t1_aa, v_aabb_ovov, t3_abbabb) * -2.0 + dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aabb_ovov, t3_abbabb) * 2.0 + dt2_abab += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * -1.0 + dt2_abab += einsum("jc,kdlc,ilkabd->ijab", t1_bb, v_aabb_ovov, t3_abaaba) * -1.0 + dt2_abab += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * -2.0 + dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * 2.0 + dt2_abab += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -1.0 + dt2_abab += einsum("jc,kdlc,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) + dt2_abab += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -2.0 + dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * 2.0 + dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -2.0 + + dt1 = (dt1_aa, dt1_bb) + dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) + else: raise ValueError From 6e1b83aac280b6981e244933254b8f230732984a Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 27 Jan 2023 15:00:05 +0000 Subject: [PATCH 31/66] Enable external correction for UHF --- vayesta/solver/coupling.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 9f47ec134..a19a8efb6 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -818,7 +818,18 @@ def callback(kwargs): t2[:] += dt2 elif solver.spinsym == 'unrestricted': - # TODO: Not working - need to contract properly with energy denominators + + if corrtype in ["external", "external-fciv", "external-ccsdv"]: + ei = (mo_energy[:nocc[0]], mo_energy[:nocc[1]]) + ea = (mo_energy[nocc[0]:], mo_energy[nocc[1]:]) + e_ia = pyscf.lib.direct_sum("si-sa->sia", ei, ea) + + dt1 = (dt1[0] / e_ia[0], dt1[1] / e_ia[1]) + dt2 = ( + dt2[0] / pyscf.lib.direct_sum("ia,jb->ijab", e_ia[0], e_ia[0]), + dt2[1] / pyscf.lib.direct_sum("ia,jb->ijab", e_ia[0], e_ia[1]), + dt2[2] / pyscf.lib.direct_sum("ia,jb->ijab", e_ia[1], e_ia[1]), + ) def callback(kwargs): """Add external correction to T1 and T2 amplitudes.""" From 1835603cc4d16d2adae4c5af7a52c89525cf01cc Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 27 Jan 2023 15:18:54 +0000 Subject: [PATCH 32/66] Fixes for UHF external correction --- vayesta/ewf/fragment.py | 4 ++-- vayesta/solver/coupling.py | 26 +++++++++++++++----------- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/vayesta/ewf/fragment.py b/vayesta/ewf/fragment.py index 6d1844ebd..331f6e923 100644 --- a/vayesta/ewf/fragment.py +++ b/vayesta/ewf/fragment.py @@ -18,7 +18,7 @@ from vayesta.core.qemb import Fragment as BaseFragment from vayesta.solver import get_solver_class from vayesta.core.fragmentation import IAO_Fragmentation -from vayesta.core.types import RFCI_WaveFunction, RCCSDTQ_WaveFunction +from vayesta.core.types import RFCI_WaveFunction, RCCSDTQ_WaveFunction, UCCSDTQ_WaveFunction from vayesta.core.bath import BNO_Threshold from vayesta.core.bath import DMET_Bath @@ -314,7 +314,7 @@ def kernel(self, solver=None, init_guess=None, eris=None): if isinstance(wf, RFCI_WaveFunction): pwf = wf.as_cisd() # Projection of CCSDTQ wave function is not implemented - convert to CCSD - elif isinstance(wf, RCCSDTQ_WaveFunction): + elif isinstance(wf, (RCCSDTQ_WaveFunction, UCCSDTQ_WaveFunction)): pwf = wf.as_ccsd() proj = self.get_overlap('proj|cluster-occ') pwf = pwf.project(proj, inplace=False) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index a19a8efb6..431d403d4 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -281,11 +281,11 @@ def _integrals_for_extcorr(fragment, fock): vb = np.s_[cluster.nocc_active[1]:] fova = dot(cluster.c_active_occ[0].T, fock[0], cluster.c_active_vir[0]) fovb = dot(cluster.c_active_occ[1].T, fock[1], cluster.c_active_vir[1]) - # TODO make consistent with RHF return value + # TODO make consistent with RHF return value, remove redundancies fov = (fova, fovb) - gooov = (eris[0][oa, oa, oa, va], eris[1][oa, oa, ob, vb], eris[2][ob, ob, ob, vb]) - govov = (eris[0][oa, va, oa, va], eris[1][oa, va, ob, vb], eris[2][ob, vb, ob, vb]) - govvv = (eris[0][oa, va, va, va], eris[1][oa, va, vb, vb], eris[2][ob, vb, vb, vb]) + gooov = (eris[0][oa, oa, oa, va], eris[1][oa, oa, ob, vb], eris[1].transpose(2, 3, 0, 1)[ob, vb, oa, oa], eris[2][ob, ob, ob, vb]) + govov = (eris[0][oa, va, oa, va], eris[1][oa, va, ob, vb], eris[1].transpose(2, 3, 0, 1)[ob, vb, oa, va], eris[2][ob, vb, ob, vb]) + govvv = (eris[0][oa, va, va, va], eris[1][oa, va, vb, vb], eris[1].transpose(2, 3, 0, 1)[vb, vb, oa, va], eris[2][ob, vb, vb, vb]) return fov, gooov, govov, govvv return fov, govov, gvvov, gooov, govoo @@ -448,15 +448,18 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc elif fragment.base.spinsym == 'unrestricted': # Get ERIs and Fock matrix for the given fragment (f_aa_ov, f_bb_ov), \ - (v_aaaa_ooov, v_aabb_ooov, v_bbbb_ooov), \ - (v_aaaa_ovov, v_aabb_ovov, v_bbbb_ovov), \ - (v_aaaa_ovvv, v_aabb_ovvv, v_bbbb_ovvv) = _integrals_for_extcorr(fragment, fock) + (v_aaaa_ooov, v_aabb_ooov, v_bbaa_ooov, v_bbbb_ooov), \ + (v_aaaa_ovov, v_aabb_ovov, v_bbaa_ovov, v_bbbb_ovov), \ + (v_aaaa_ovvv, v_aabb_ovvv, v_bbaa_ovvv, v_bbbb_ovvv) = _integrals_for_extcorr(fragment, fock) t1_aa, t1_bb = wf.t1 t2_aaaa, t2_abab, t2_bbbb = wf.t2 t3_aaaaaa, t3_abaaba, t3_abbabb, t3_babbab, t3_bbabba, t3_bbbbbb = wf.t3 t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb = wf.t4 + nocc = fragment.base.nocc + nvir = fragment.base.nvir + dt1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) dt1_aa += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_abaaba) dt1_aa += einsum("jbkc,ikjacb->ia", v_aabb_ovov, t3_abaaba) @@ -741,7 +744,7 @@ def externally_correct(solver, external_corrections, eris=None, test_extcorr=Fal except: _, _, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) elif emb.spinsym == 'unrestricted': - raise NotImplementedError + pass # TODO is this only needed for external-ccsdv? # delta-T1 and delta-T2 amplitudes, to be added to the CCSD amplitudes if solver.spinsym == 'restricted': @@ -820,9 +823,10 @@ def callback(kwargs): elif solver.spinsym == 'unrestricted': if corrtype in ["external", "external-fciv", "external-ccsdv"]: - ei = (mo_energy[:nocc[0]], mo_energy[:nocc[1]]) - ea = (mo_energy[nocc[0]:], mo_energy[nocc[1]:]) - e_ia = pyscf.lib.direct_sum("si-sa->sia", ei, ea) + e_ia = ( + pyscf.lib.direct_sum("i-a->ia", mo_energy[0][:nocc[0]], mo_energy[0][nocc[0]:]), + pyscf.lib.direct_sum("i-a->ia", mo_energy[1][:nocc[1]], mo_energy[1][nocc[1]:]), + ) dt1 = (dt1[0] / e_ia[0], dt1[1] / e_ia[1]) dt2 = ( From 8ee1b3ba7420da9d51f7c082d41d88775d18b490 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 27 Jan 2023 16:28:46 +0000 Subject: [PATCH 33/66] Some fixes for UHF external corrections --- vayesta/core/types/wf/fci.py | 10 +++++----- vayesta/solver/coupling.py | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 264e29342..ec8f4eebf 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -462,7 +462,7 @@ def as_cisdtq(self, c0=None): assert(c3_aab_pack.shape == (ij_pairs_a * ab_pairs_a, noccb * nvirb)) # bba c3_abb_pack = np.einsum('i,j,ij->ij', t1signa, t2signb, self.ci[t1addra[:,None], t2addrb]) - assert(c3_abb_pack.shape == (nocca * nvirb, ij_pairs_b * ab_pairs_b)) + assert(c3_abb_pack.shape == (nocca * nvira, ij_pairs_b * ab_pairs_b)) # Now, unpack... TODO from ebcc.util import decompress_axes @@ -488,7 +488,7 @@ def as_cisdtq(self, c0=None): c3_abb = decompress_axes( "iajjbb", c3_abb_pack, - shape=(nocca, nvirb, noccb, noccb, nvirb, nvirb), + shape=(nocca, nvira, noccb, noccb, nvirb, nvirb), symmetry="------", ) c3_abb = c3_abb.transpose(0, 2, 3, 1, 4, 5) @@ -506,7 +506,7 @@ def as_cisdtq(self, c0=None): assert(c4_aabb_pack.shape == (ij_pairs_a * ab_pairs_a, ij_pairs_b * ab_pairs_b)) # abbb c4_abbb_pack = np.einsum('i,j,ij->ij', t1signa, t3signb, self.ci[t1addra[:,None], t3addrb]) - assert(c4_abbb_pack.shape == (nocca * nvirb, ijk_pairs_b * abc_pairs_b)) + assert(c4_abbb_pack.shape == (nocca * nvira, ijk_pairs_b * abc_pairs_b)) # Now, unpack... TODO c4_aaaa = decompress_axes( @@ -538,7 +538,7 @@ def as_cisdtq(self, c0=None): c4_abbb = decompress_axes( "iajjjbbb", c4_abbb_pack, - shape=(nocca, nvirb, noccb, noccb, noccb, nvirb, nvirb, nvirb), + shape=(nocca, nvira, noccb, noccb, noccb, nvirb, nvirb, nvirb), symmetry="--------", ) c4_abbb = c4_abbb.transpose(0, 2, 3, 4, 1, 5, 6, 7) @@ -571,12 +571,12 @@ def as_cisdtq(self, c0=None): c3_aba[i,k,j,b,c,a] = -c3_comp[d_cnta, s_cntb] c3_aba[j,k,i,b,c,a] = c3_comp[d_cnta, s_cntb] + # NOTE: this all fails for open shell if len(t2addra) > 0: # This is a better way of doing it, and then expand! Put rest in a test. assert(np.allclose(c3_comp, np.einsum('i,j,ij->ij', \ t2signa, t1signb, self.ci[t2addra[:,None], t1addrb]))) del c3_comp - assert np.allclose(c3_aba, c3_aab.transpose(0, 2, 1, 3, 5, 4)) # TODO remove degenerate permutations diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 431d403d4..5856dce33 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -283,9 +283,9 @@ def _integrals_for_extcorr(fragment, fock): fovb = dot(cluster.c_active_occ[1].T, fock[1], cluster.c_active_vir[1]) # TODO make consistent with RHF return value, remove redundancies fov = (fova, fovb) - gooov = (eris[0][oa, oa, oa, va], eris[1][oa, oa, ob, vb], eris[1].transpose(2, 3, 0, 1)[ob, vb, oa, oa], eris[2][ob, ob, ob, vb]) + gooov = (eris[0][oa, oa, oa, va], eris[1][oa, oa, ob, vb], eris[1].transpose(2, 3, 0, 1)[ob, ob, oa, va], eris[2][ob, ob, ob, vb]) govov = (eris[0][oa, va, oa, va], eris[1][oa, va, ob, vb], eris[1].transpose(2, 3, 0, 1)[ob, vb, oa, va], eris[2][ob, vb, ob, vb]) - govvv = (eris[0][oa, va, va, va], eris[1][oa, va, vb, vb], eris[1].transpose(2, 3, 0, 1)[vb, vb, oa, va], eris[2][ob, vb, vb, vb]) + govvv = (eris[0][oa, va, va, va], eris[1][oa, va, vb, vb], eris[1].transpose(2, 3, 0, 1)[ob, vb, va, va], eris[2][ob, vb, vb, vb]) return fov, gooov, govov, govvv return fov, govov, gvvov, gooov, govoo From d31532cb78da2b23612471de42ee64db536662c1 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 27 Jan 2023 16:54:48 +0000 Subject: [PATCH 34/66] Forgot T4 contractions --- vayesta/core/types/wf/cisdtq.py | 59 +++++++++++++++++++++++++++++++-- vayesta/core/types/wf/fci.py | 1 + vayesta/solver/coupling.py | 22 +++++++++++- 3 files changed, 79 insertions(+), 3 deletions(-) diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 3594f4d2c..38eb14b60 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -216,7 +216,7 @@ def as_ccsdtq(self): c1_aa, c1_bb = (c / self.c0 for c in self.c1) c2_aaaa, c2_abab, c2_bbbb = (c / self.c0 for c in self.c2) c3_aaaaaa, c3_abaaba, c3_abbabb, c3_babbab, c3_bbabba, c3_bbbbbb = (c / self.c0 for c in self.c3) - c4_aaaaaaaa, c4_aaabaaab, c4_aabaaaba, c4_abaaabaa, c4_abababab, c4_bbabbbab, c4_bbbabbba, c4_bbbbbbbb = (c / self.c0 for c in self.c4) + c4_aaaaaaaa, c4_aaabaaab, c4_aabaaaba, c4_abaaabaa, c4_abababab, c4_abbbabbb, c4_bbabbbab, c4_bbbabbba, c4_bbbbbbbb = (c / self.c0 for c in self.c4) nocc = self.nocc nvir = self.nvir @@ -659,6 +659,61 @@ def as_ccsdtq(self): t4_abababab += einsum("ic,ka,jb,ld->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) t4_abababab += einsum("ic,ka,jd,lb->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) * -1.0 + t4_abbbabbb = np.zeros((nocc[0], nocc[1], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t4_abbbabbb += einsum("ijklabcd->ijklabcd", c4_abbbabbb) * 6.0 + t4_abbbabbb += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_bbbbbb) * -6.0 + t4_abbbabbb += einsum("jb,iklacd->ijklabcd", t1_bb, t3_abbabb) * -2.0 + t4_abbbabbb += einsum("jc,iklabd->ijklabcd", t1_bb, t3_abbabb) * 2.0 + t4_abbbabbb += einsum("jd,iklabc->ijklabcd", t1_bb, t3_abbabb) * -2.0 + t4_abbbabbb += einsum("kb,ijlacd->ijklabcd", t1_bb, t3_abbabb) * 2.0 + t4_abbbabbb += einsum("kc,ijlabd->ijklabcd", t1_bb, t3_abbabb) * -2.0 + t4_abbbabbb += einsum("kd,ijlabc->ijklabcd", t1_bb, t3_abbabb) * 2.0 + t4_abbbabbb += einsum("lb,ijkacd->ijklabcd", t1_bb, t3_abbabb) * -2.0 + t4_abbbabbb += einsum("lc,ijkabd->ijklabcd", t1_bb, t3_abbabb) * 2.0 + t4_abbbabbb += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_abbabb) * -2.0 + t4_abbbabbb += einsum("ikac,jlbd->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ikad,jlbc->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_abbbabbb += einsum("ikab,jlcd->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_abbbabbb += einsum("ilac,jkbd->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_abbbabbb += einsum("ilad,jkbc->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ilab,jkcd->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ijac,klbd->ijklabcd", t2_abab, t2_bbbb) * 2.0 + t4_abbbabbb += einsum("ijad,klbc->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ijab,klcd->ijklabcd", t2_abab, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ia,jc,klbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_abbbabbb += einsum("ia,jd,klbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ia,kb,jlcd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_abbbabbb += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ia,kd,jlbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_abbbabbb += einsum("ia,lb,jkcd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("ia,lc,jkbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 + t4_abbbabbb += einsum("ia,ld,jkbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 + t4_abbbabbb += einsum("jb,kc,ilad->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("jb,kd,ilac->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("jc,kb,ilad->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("jc,kd,ilab->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("jd,kb,ilac->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("jd,kc,ilab->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("jb,lc,ikad->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("jb,ld,ikac->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("jc,lb,ikad->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("jc,ld,ikab->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("jd,lb,ikac->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("jd,lc,ikab->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("kb,lc,ijad->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("kb,ld,ijac->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("kc,lb,ijad->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("kc,ld,ijab->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("kd,lb,ijac->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 + t4_abbbabbb += einsum("kd,lc,ijab->ijklabcd", t1_bb, t1_bb, t2_abab) + t4_abbbabbb += einsum("ia,jb,kc,ld->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_abbbabbb += einsum("ia,jb,kd,lc->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + t4_abbbabbb += einsum("ia,jc,kb,ld->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + t4_abbbabbb += einsum("ia,jc,kd,lb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_abbbabbb += einsum("ia,jd,kb,lc->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 + t4_abbbabbb += einsum("ia,jd,kc,lb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) + t4_bbabbbab = np.zeros((nocc[1], nocc[1], nocc[0], nocc[1], nvir[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) t4_bbabbbab += einsum("ijklabcd->ijklabcd", c4_bbabbbab) * 6.0 t4_bbabbbab += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_bbbbbb) * -6.0 @@ -905,6 +960,6 @@ def as_ccsdtq(self): t1 = (t1_aa, t1_bb) t2 = (t2_aaaa, t2_abab, t2_bbbb) t3 = (t3_aaaaaa, t3_abaaba, t3_abbabb, t3_babbab, t3_bbabba, t3_bbbbbb) - t4 = (t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb) + t4 = (t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_abbbabbb, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb) return wf_types.UCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index ec8f4eebf..79854679c 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -596,6 +596,7 @@ def as_cisdtq(self, c0=None): c4_aaab.transpose(0, 1, 3, 2, 4, 5, 7, 6), c4_aaab.transpose(0, 3, 2, 1, 4, 7, 6, 5), c4_aabb.transpose(0, 2, 1, 3, 4, 6, 5, 7), + c4_abbb, c4_abbb.transpose(2, 1, 0, 3, 6, 5, 4, 7), c4_abbb.transpose(3, 1, 2, 0, 7, 5, 6, 4), c4_bbbb, diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 5856dce33..441474fdf 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -455,7 +455,7 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc t1_aa, t1_bb = wf.t1 t2_aaaa, t2_abab, t2_bbbb = wf.t2 t3_aaaaaa, t3_abaaba, t3_abbabb, t3_babbab, t3_bbabba, t3_bbbbbb = wf.t3 - t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb = wf.t4 + t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_abbbabbb, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb = wf.t4 nocc = fragment.base.nocc nvir = fragment.base.nvir @@ -502,6 +502,11 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc dt2_aaaa += einsum("kc,kdlc,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) * -2.0 dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_aaaaaa) * 6.0 + dt2_aaaa += einsum("kcld,ikjlacbd->ijab", v_bbbb_ovov, t4_abababab) * 2.0 + dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_aaaaaaaa) * 12.0 + dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_aaabaaab) * 3.0 + dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_bbaa_ovov, t4_aabaaaba) * 3.0 + dt2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) dt2_bbbb += einsum("kc,ijkabc->ijab", f_aa_ov, t3_bbabba) * 2.0 dt2_bbbb += einsum("kc,ijkabc->ijab", f_bb_ov, t3_bbbbbb) * 6.0 @@ -532,6 +537,11 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 6.0 dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -6.0 + dt2_bbbb += einsum("kcld,kiljcadb->ijab", v_aaaa_ovov, t4_abababab) * 2.0 + dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_bbabbbab) * 3.0 + dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbaa_ovov, t4_bbbabbba) * 3.0 + dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 12.0 + dt2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) dt2_abab += einsum("kc,ijkabc->ijab", f_aa_ov, t3_abaaba) * 2.0 dt2_abab += einsum("kc,ijkabc->ijab", f_bb_ov, t3_abbabb) * 2.0 @@ -562,6 +572,11 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * 2.0 dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -2.0 + dt2_abab += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_abababab) * 2.0 + dt2_abab += einsum("kcld,ijlkabdc->ijab", v_bbaa_ovov, t4_abababab) * 2.0 + dt2_abab += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_abaaabaa) * 3.0 + dt2_abab += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_abbbabbb) * 3.0 + dt1 = (dt1_aa, dt1_bb) dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) @@ -823,6 +838,7 @@ def callback(kwargs): elif solver.spinsym == 'unrestricted': if corrtype in ["external", "external-fciv", "external-ccsdv"]: + # FIXME is this done correctly? I update my T amplitudes as T = R / D - T' e_ia = ( pyscf.lib.direct_sum("i-a->ia", mo_energy[0][:nocc[0]], mo_energy[0][nocc[0]:]), pyscf.lib.direct_sum("i-a->ia", mo_energy[1][:nocc[1]], mo_energy[1][nocc[1]:]), @@ -835,9 +851,13 @@ def callback(kwargs): dt2[2] / pyscf.lib.direct_sum("ia,jb->ijab", e_ia[1], e_ia[1]), ) + solver.log.info("Total external correction amplitudes from all fragments: dT1= %.3e dT2= %.3e", \ + *get_amplitude_norm(dt1, dt2)) + def callback(kwargs): """Add external correction to T1 and T2 amplitudes.""" t1, t2 = kwargs['t1new'], kwargs['t2new'] + t1[0][:] += dt1[0] t1[1][:] += dt1[1] t2[0][:] += dt2[0] From 65289e1d146bf6f7108d065cef20ac1ec02a51a3 Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 27 Jan 2023 17:03:41 +0000 Subject: [PATCH 35/66] Comment --- vayesta/solver/coupling.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 441474fdf..7eb700990 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -460,6 +460,7 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc nocc = fragment.base.nocc nvir = fragment.base.nvir + # TODO: Use spinalg.zeros_like(t1/t2) dt1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) dt1_aa += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_abaaba) dt1_aa += einsum("jbkc,ikjacb->ia", v_aabb_ovov, t3_abaaba) @@ -572,10 +573,16 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * 2.0 dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -2.0 +<<<<<<< Updated upstream dt2_abab += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_abababab) * 2.0 dt2_abab += einsum("kcld,ijlkabdc->ijab", v_bbaa_ovov, t4_abababab) * 2.0 dt2_abab += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_abaaabaa) * 3.0 dt2_abab += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_abbbabbb) * 3.0 +======= + if not include_t3v: + # TODO + raise NotImplementedError +>>>>>>> Stashed changes dt1 = (dt1_aa, dt1_bb) dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) From 779e95d80a061f17117f46198172692777562133 Mon Sep 17 00:00:00 2001 From: George Booth Date: Tue, 7 Feb 2023 09:23:57 +0000 Subject: [PATCH 36/66] Resolve merge --- vayesta/solver/coupling.py | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 7eb700990..5b0ab2192 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -573,16 +573,14 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * 2.0 dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -2.0 -<<<<<<< Updated upstream dt2_abab += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_abababab) * 2.0 dt2_abab += einsum("kcld,ijlkabdc->ijab", v_bbaa_ovov, t4_abababab) * 2.0 dt2_abab += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_abaaabaa) * 3.0 dt2_abab += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_abbbabbb) * 3.0 -======= + if not include_t3v: # TODO raise NotImplementedError ->>>>>>> Stashed changes dt1 = (dt1_aa, dt1_bb) dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) From a6b3fbd2e6c615100d45320c47fec4c2d5fbc7b9 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Tue, 28 Feb 2023 11:12:46 +0000 Subject: [PATCH 37/66] Fix bug in array sizes --- vayesta/solver/coupling.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 441474fdf..57d4d3040 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -457,8 +457,11 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc t3_aaaaaa, t3_abaaba, t3_abbabb, t3_babbab, t3_bbabba, t3_bbbbbb = wf.t3 t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_abbbabbb, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb = wf.t4 - nocc = fragment.base.nocc - nvir = fragment.base.nvir + # FIXME pull from property + nocc_a, nvir_a = t1_aa.shape + nocc_b, nvir_b = t1_bb.shape + nocc = (nocc_a, nocc_b) + nvir = (nvir_a, nvir_b) dt1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) dt1_aa += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_abaaba) From 6c6138d1e290be211562963c324f7ea53ff9fb94 Mon Sep 17 00:00:00 2001 From: George Booth Date: Tue, 28 Feb 2023 15:40:33 +0000 Subject: [PATCH 38/66] Allow slicing for FCI vector with empty lists --- vayesta/core/types/wf/cisdtq.py | 2 +- vayesta/core/types/wf/fci.py | 10 ++++++++++ 2 files changed, 11 insertions(+), 1 deletion(-) diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 38eb14b60..ec62f51d2 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -192,7 +192,7 @@ def as_ccsdtq(self): # Pack two spin signatures into single tuple t4 = (t4_abaa, t4_abab) - + return wf_types.RCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) class UCISDTQ_WaveFunction(wf_types.WaveFunction): diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 79854679c..f4e9b7e22 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -435,6 +435,16 @@ def as_cisdtq(self, c0=None): t4addra, t4signa = pyscf.ci.cisd.tn_addrs_signs(norba, nocca, 4) t4addrb, t4signb = pyscf.ci.cisd.tn_addrs_signs(norbb, noccb, 4) + # Change to arrays, in case of empty slice + t1addra = np.asarray(t1addra, dtype=int) + t1addrb = np.asarray(t1addrb, dtype=int) + t2addra = np.asarray(t2addra, dtype=int) + t2addrb = np.asarray(t2addrb, dtype=int) + t3addra = np.asarray(t3addra, dtype=int) + t3addrb = np.asarray(t3addrb, dtype=int) + t4addra = np.asarray(t4addra, dtype=int) + t4addrb = np.asarray(t4addrb, dtype=int) + na = pyscf.fci.cistring.num_strings(norba, nocca) nb = pyscf.fci.cistring.num_strings(norbb, noccb) From 9e7f0f9947b8f98ce05f7cee8d8bb073cbeff34b Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Wed, 1 Mar 2023 16:55:11 +0000 Subject: [PATCH 39/66] Refactorises conversion UHF C->T conversion routines --- vayesta/core/types/wf/_conversion_routines.py | 1397 +++++++++++++++++ vayesta/core/types/wf/cisdtq.py | 779 +-------- 2 files changed, 1438 insertions(+), 738 deletions(-) create mode 100644 vayesta/core/types/wf/_conversion_routines.py diff --git a/vayesta/core/types/wf/_conversion_routines.py b/vayesta/core/types/wf/_conversion_routines.py new file mode 100644 index 000000000..ad525b079 --- /dev/null +++ b/vayesta/core/types/wf/_conversion_routines.py @@ -0,0 +1,1397 @@ +import numpy as np +from ebcc.util import pack_2e, einsum, Namespace + +def t1_uhf_aa(c1=None, nocc=None, nvir=None): + t1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + t1_aa += einsum(c1.aa, (0, 1), (0, 1)) + return t1_aa + +def t1_uhf_bb(c1=None, nocc=None, nvir=None): + t1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + t1_bb += einsum(c1.bb, (0, 1), (0, 1)) + return t1_bb + +def t1_rhf(c1=None, nocc=None, nvir=None): + t1 = np.zeros((nocc, nvir), dtype=np.float64) + t1 += einsum(c1, (0, 1), (0, 1)) + return t1 + +def t1_ghf(c1=None, nocc=None, nvir=None): + t1 = np.zeros((nocc, nvir), dtype=np.float64) + t1 += einsum(c1, (0, 1), (0, 1)) + return t1 + +def t2_uhf_aaaa(c2=None, t1=None, nocc=None, nvir=None): + t2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + t2_aaaa += einsum(c2.aaaa, (0, 1, 2, 3), (0, 1, 2, 3)) + t2_aaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), (0, 2, 1, 3)) * -1.0 + t2_aaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), (0, 2, 3, 1)) + return t2_aaaa + +def t2_uhf_abab(c2=None, t1=None, nocc=None, nvir=None): + t2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) + t2_abab += einsum(c2.abab, (0, 1, 2, 3), (0, 1, 2, 3)) + t2_abab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), (0, 2, 1, 3)) * -1.0 + return t2_abab + +def t2_uhf_baba(c2=None, t1=None, nocc=None, nvir=None): + t2_baba = np.zeros((nocc[1], nocc[0], nvir[1], nvir[0]), dtype=np.float64) + t2_baba += einsum(c2.abab, (0, 1, 2, 3), (1, 0, 3, 2)) + t2_baba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), (2, 0, 3, 1)) * -1.0 + return t2_baba + +def t2_uhf_bbbb(c2=None, t1=None, nocc=None, nvir=None): + t2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + t2_bbbb += einsum(c2.bbbb, (0, 1, 2, 3), (0, 1, 2, 3)) + t2_bbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), (0, 2, 1, 3)) * -1.0 + t2_bbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), (0, 2, 3, 1)) + return t2_bbbb + +def t2_rhf(c2=None, t1=None, nocc=None, nvir=None): + t2 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) + t2 += einsum(c2, (0, 1, 2, 3), (0, 1, 2, 3)) + t2 += einsum(t1, (0, 1), t1, (2, 3), (0, 2, 1, 3)) * -1.0 + return t2 + +def t2_ghf(c2=None, t1=None, nocc=None, nvir=None): + t2 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) + t2 += einsum(c2, (0, 1, 2, 3), (0, 1, 2, 3)) + t2 += einsum(t1, (0, 1), t1, (2, 3), (0, 2, 1, 3)) * -1.0 + t2 += einsum(t1, (0, 1), t1, (2, 3), (0, 2, 3, 1)) + return t2 + +def t3_uhf_aaaaaa(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_aaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + t3_aaaaaa += einsum(c3.aaaaaa, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (0, 2, 3, 4, 1, 5)) + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (0, 2, 3, 4, 5, 1)) * -1.0 + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 0, 3, 1, 4, 5)) + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 0, 3, 4, 5, 1)) + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 3, 0, 1, 4, 5)) * -1.0 + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 3, 0, 4, 1, 5)) + t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 + t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 + t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 1, 5, 3)) + t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 3, 1, 5)) + t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 5, 1, 3)) * -1.0 + t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 3, 5, 1)) * -1.0 + t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 5, 3, 1)) + return t3_aaaaaa + +def t3_uhf_aabaab(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_aabaab = np.zeros((nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[1]), dtype=np.float64) + t3_aabaab += einsum(c3.abaaba, (0, 1, 2, 3, 4, 5), (0, 2, 1, 3, 5, 4)) + t3_aabaab += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 + t3_aabaab += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (0, 2, 3, 4, 1, 5)) + t3_aabaab += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (2, 0, 3, 1, 4, 5)) + t3_aabaab += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 + t3_aabaab += einsum(t1.bb, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 + t3_aabaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 + t3_aabaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (0, 2, 4, 3, 1, 5)) + return t3_aabaab + +def t3_uhf_abaaba(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_abaaba = np.zeros((nocc[0], nocc[1], nocc[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) + t3_abaaba += einsum(c3.abaaba, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) + t3_abaaba += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (0, 3, 2, 1, 5, 4)) * -1.0 + t3_abaaba += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (0, 3, 2, 4, 5, 1)) + t3_abaaba += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (2, 3, 0, 1, 5, 4)) + t3_abaaba += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 + t3_abaaba += einsum(t1.bb, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 + t3_abaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (0, 4, 2, 1, 5, 3)) * -1.0 + t3_abaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (0, 4, 2, 3, 5, 1)) + return t3_abaaba + +def t3_uhf_abbabb(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_abbabb = np.zeros((nocc[0], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) + t3_abbabb += einsum(c3.abbabb, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) + t3_abbabb += einsum(t1.aa, (0, 1), t2.bbbb, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 + t3_abbabb += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 + t3_abbabb += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (2, 0, 3, 4, 5, 1)) + t3_abbabb += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (2, 3, 0, 4, 1, 5)) + t3_abbabb += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 + t3_abbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 + t3_abbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 5, 3)) + return t3_abbabb + +def t3_uhf_baabaa(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_baabaa = np.zeros((nocc[1], nocc[0], nocc[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) + t3_baabaa += einsum(c3.abaaba, (0, 1, 2, 3, 4, 5), (1, 0, 2, 4, 3, 5)) + t3_baabaa += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (3, 0, 2, 5, 1, 4)) * -1.0 + t3_baabaa += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (3, 0, 2, 5, 4, 1)) + t3_baabaa += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (3, 2, 0, 5, 1, 4)) + t3_baabaa += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (3, 2, 0, 5, 4, 1)) * -1.0 + t3_baabaa += einsum(t1.bb, (0, 1), t2.aaaa, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 + t3_baabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (4, 0, 2, 5, 1, 3)) * -1.0 + t3_baabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (4, 0, 2, 5, 3, 1)) + return t3_baabaa + +def t3_uhf_babbab(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_babbab = np.zeros((nocc[1], nocc[0], nocc[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t3_babbab += einsum(c3.babbab, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) + t3_babbab += einsum(t1.aa, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 + t3_babbab += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 + t3_babbab += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (0, 2, 3, 5, 4, 1)) + t3_babbab += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (3, 2, 0, 1, 4, 5)) + t3_babbab += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (3, 2, 0, 5, 4, 1)) * -1.0 + t3_babbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (2, 0, 4, 3, 1, 5)) * -1.0 + t3_babbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (2, 0, 4, 5, 1, 3)) + return t3_babbab + +def t3_uhf_bbabba(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_bbabba = np.zeros((nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) + t3_bbabba += einsum(c3.bbabba, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) + t3_bbabba += einsum(t1.aa, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 + t3_bbabba += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (0, 3, 2, 1, 5, 4)) * -1.0 + t3_bbabba += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (0, 3, 2, 5, 1, 4)) + t3_bbabba += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (3, 0, 2, 1, 5, 4)) + t3_bbabba += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (3, 0, 2, 5, 1, 4)) * -1.0 + t3_bbabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (2, 4, 0, 3, 5, 1)) * -1.0 + t3_bbabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (2, 4, 0, 5, 3, 1)) + return t3_bbabba + +def t3_uhf_bbbbbb(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_bbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t3_bbbbbb += einsum(c3.bbbbbb, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (0, 2, 3, 4, 1, 5)) + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (0, 2, 3, 4, 5, 1)) * -1.0 + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 0, 3, 1, 4, 5)) + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 0, 3, 4, 5, 1)) + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 3, 0, 1, 4, 5)) * -1.0 + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 3, 0, 4, 1, 5)) + t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 + t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 + t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 5, 3)) + t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 3, 1, 5)) + t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 5, 1, 3)) * -1.0 + t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 3, 5, 1)) * -1.0 + t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 5, 3, 1)) + return t3_bbbbbb + +def t3_rhf(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) + t3 += einsum(c3, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 3, 2, 1, 5, 4)) * -1.0 + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 3, 2, 4, 5, 1)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 5, 1, 4)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 1, 5, 4)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 + t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 + t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 5, 3, 1)) + return t3 + +def t3_ghf(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) + t3 += einsum(c3, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 2, 3, 4, 1, 5)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 2, 3, 4, 5, 1)) * -1.0 + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 1, 4, 5)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 4, 5, 1)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 1, 4, 5)) * -1.0 + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 4, 1, 5)) + t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 + t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 + t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 1, 5, 3)) + t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 3, 1, 5)) + t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 5, 1, 3)) * -1.0 + t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 3, 5, 1)) * -1.0 + t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 5, 3, 1)) + return t3 + +def t4_uhf_aaaaaaaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_aaaaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + t4_aaaaaaaa += einsum(c4.aaaaaaaa, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 5, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 5, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 3, 6, 7)) + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 7, 2, 3)) + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 3, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 7, 2, 3)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 3, 7)) + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 7, 3)) + t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 7, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 3, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 3, 1, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 1, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 3, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 3, 1, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 1, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 3, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 1, 3, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 1, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 1, 3, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 3, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 3, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 3, 1, 6, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 7, 3, 5)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 5, 7, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 1, 7, 5)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 1, 3, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 1, 3, 5)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 1, 7, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 1, 5, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 5, 1, 7)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 7, 1, 5)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 3, 1, 5)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 5, 1, 3)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 5, 7, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 7, 5, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 3, 7, 1)) * -1.0 + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 3, 5, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 7, 3, 1)) + t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 5, 3, 1)) * -1.0 + return t4_aaaaaaaa + +def t4_uhf_aaabaaab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_aaabaaab = np.zeros((nocc[0], nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[0], nvir[1]), dtype=np.float64) + t4_aaabaaab += einsum(c4.aaabaaab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 1, 5, 7, 6)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 5, 1, 7, 6)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 5, 7, 1, 6)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 1, 5, 7, 6)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 1, 7, 6)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 7, 1, 6)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 1, 5, 7, 6)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 5, 1, 7, 6)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 5, 7, 1, 6)) * -1.0 + t4_aaabaaab += einsum(t1.bb, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 7, 2, 3)) * -1.0 + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 1, 2, 6, 7, 3)) + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 1, 6, 2, 7, 3)) * -1.0 + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 1, 6, 7, 2, 3)) + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 1, 2, 6, 7, 3)) * -1.0 + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 1, 6, 2, 7, 3)) + t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 1, 6, 7, 2, 3)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 3, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 1, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 3, 1, 6, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 1, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 1, 3, 6, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 1, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 1, 3)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 7, 3)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 1, 3, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 5, 1, 7)) * -1.0 + t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) + return t4_aaabaaab + +def t4_uhf_aabaaaba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_aabaaaba = np.zeros((nocc[0], nocc[0], nocc[1], nocc[0], nvir[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) + t4_aabaaaba += einsum(c4.aabaaaba, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 7, 6, 1)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 7, 6, 1)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 1, 5, 6, 7)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 5, 1, 6, 7)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 5, 7, 6, 1)) * -1.0 + t4_aabaaaba += einsum(t1.bb, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 7, 3, 2)) * -1.0 + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 1, 5, 2, 6, 3, 7)) + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 1, 5, 6, 2, 3, 7)) * -1.0 + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 1, 5, 6, 7, 3, 2)) + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 1, 0, 2, 6, 3, 7)) * -1.0 + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 1, 0, 6, 2, 3, 7)) + t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 1, 0, 6, 7, 3, 2)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 3, 7, 6)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 6, 7, 3)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 3, 1, 7, 6)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 6, 1, 7, 3)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 3, 6, 7, 1)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 6, 3, 7, 1)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 7, 6)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 3, 1, 7, 6)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 7, 1)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 1, 3, 7, 6)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 7, 6)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 7, 1)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 3, 1)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 2, 0, 1, 6, 3, 7)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 2, 0, 6, 1, 3, 7)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 2, 0, 6, 7, 3, 1)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 1, 3, 7, 5)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 1, 5, 7, 3)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 3, 1, 7, 5)) + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 5, 1, 7, 3)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 3, 5, 7, 1)) * -1.0 + t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 5, 3, 7, 1)) + return t4_aabaaaba + +def t4_uhf_aabbaabb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_aabbaabb = np.zeros((nocc[0], nocc[0], nocc[1], nocc[1], nvir[0], nvir[0], nvir[1], nvir[1]), dtype=np.float64) + t4_aabbaabb += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 2, 1, 3, 4, 6, 5, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_aabbaabb += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 5, 7, 1, 6)) * -1.0 + t4_aabbaabb += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 5, 7, 6, 1)) + t4_aabbaabb += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 5, 7, 1, 6)) + t4_aabbaabb += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 5, 7, 6, 1)) * -1.0 + t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) + t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) + t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 7, 3)) * -1.0 + t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) + t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 + t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 3, 7)) * -1.0 + t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) + t4_aabbaabb += einsum(t2.aaaa, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 7, 3)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 3, 7)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 7, 3)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 3, 7)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_aabbaabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_aabbaabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) + t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 7, 5)) * -1.0 + return t4_aabbaabb + +def t4_uhf_abaaabaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_abaaabaa = np.zeros((nocc[0], nocc[1], nocc[0], nocc[0], nvir[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) + t4_abaaabaa += einsum(c4.abaaabaa, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 1, 6, 5, 7)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 5, 6, 1, 7)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 5, 6, 7, 1)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 6, 5, 7)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 6, 5, 7)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_abaaabaa += einsum(t1.bb, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 2, 7)) + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 7, 2)) * -1.0 + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 0, 5, 2, 3, 6, 7)) + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 0, 5, 6, 3, 2, 7)) * -1.0 + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 0, 5, 6, 3, 7, 2)) + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 5, 0, 2, 3, 6, 7)) * -1.0 + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 5, 0, 6, 3, 2, 7)) + t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 5, 0, 6, 3, 7, 2)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 3, 6)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 6, 3)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 1, 6)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 1, 3)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 6, 1)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 3, 1)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 3, 6)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 1, 6)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 1, 3)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 6, 1)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 3, 1)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 3, 6)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 6, 3)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 3, 7, 1, 6)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 3, 7, 6, 1)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 0, 5, 1, 3, 6, 7)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 0, 5, 6, 3, 1, 7)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 0, 5, 6, 3, 7, 1)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 5, 0, 1, 3, 6, 7)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 5, 0, 6, 3, 1, 7)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 5, 0, 6, 3, 7, 1)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 1, 7, 3, 5)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 1, 7, 5, 3)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 3, 7, 1, 5)) + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 5, 7, 1, 3)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 3, 7, 5, 1)) * -1.0 + t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 5, 7, 3, 1)) + return t4_abaaabaa + +def t4_uhf_abababab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_abababab = np.zeros((nocc[0], nocc[1], nocc[0], nocc[1], nvir[0], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t4_abababab += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 1, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 6, 5, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_abababab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 1, 7, 6)) * -1.0 + t4_abababab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 6, 7, 1)) + t4_abababab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 7, 6)) + t4_abababab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 4, 5, 2, 7, 6, 3)) + t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 2, 7)) + t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 + t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 1, 2, 3, 6, 7)) + t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 1, 2, 7, 6, 3)) * -1.0 + t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 1, 6, 3, 2, 7)) * -1.0 + t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 1, 6, 7, 2, 3)) + t4_abababab += einsum(t2.aaaa, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 7, 6, 3)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 3, 6, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 6, 3, 1, 7)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 1, 3)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 0, 5, 1, 3, 6, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 0, 5, 1, 7, 6, 3)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 0, 5, 6, 3, 1, 7)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 0, 5, 6, 7, 1, 3)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 6, 3)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_abababab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_abababab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) + t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 2, 6, 1, 5, 3, 7)) * -1.0 + t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 2, 6, 1, 7, 3, 5)) + t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 2, 6, 3, 5, 1, 7)) + t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 2, 6, 3, 7, 1, 5)) * -1.0 + return t4_abababab + +def t4_uhf_abbaabba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_abbaabba = np.zeros((nocc[0], nocc[1], nocc[1], nocc[0], nvir[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) + t4_abbaabba += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 3, 2, 4, 5, 7, 6)) + t4_abbaabba += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 7, 5, 6, 1)) + t4_abbaabba += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 6, 7, 5)) + t4_abbaabba += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_abbaabba += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_abbaabba += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) + t4_abbaabba += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) + t4_abbaabba += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 5, 4, 2, 3, 7, 6)) * -1.0 + t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 5, 4, 2, 7, 3, 6)) + t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 5, 4, 6, 3, 7, 2)) + t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 5, 4, 6, 7, 3, 2)) * -1.0 + t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 1, 4, 2, 3, 7, 6)) + t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 1, 4, 2, 7, 3, 6)) * -1.0 + t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 1, 4, 6, 3, 7, 2)) * -1.0 + t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 1, 4, 6, 7, 3, 2)) + t4_abbaabba += einsum(t2.aaaa, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 3, 7, 6)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 7, 3, 6)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 6, 3, 7, 1)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 6, 7, 3, 1)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 3, 7, 6)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 3, 6)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 6, 3, 7, 1)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 3, 1)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 5, 0, 1, 3, 7, 6)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 5, 0, 1, 7, 3, 6)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 5, 0, 6, 3, 7, 1)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 5, 0, 6, 7, 3, 1)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 2, 0, 1, 3, 7, 6)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 2, 0, 1, 7, 3, 6)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 2, 0, 6, 3, 7, 1)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 2, 0, 6, 7, 3, 1)) * -1.0 + t4_abbaabba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_abbaabba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 6, 2, 1, 5, 7, 3)) * -1.0 + t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 6, 2, 1, 7, 5, 3)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 6, 2, 3, 5, 7, 1)) + t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 6, 2, 3, 7, 5, 1)) * -1.0 + return t4_abbaabba + +def t4_uhf_abbbabbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_abbbabbb = np.zeros((nocc[0], nocc[1], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t4_abbbabbb += einsum(c4.abbbabbb, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_abbbabbb += einsum(t1.aa, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 7, 1)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 6, 7)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 3, 6, 7)) + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 3, 6, 7)) * -1.0 + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 3, 7)) + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 7, 3)) * -1.0 + t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 7, 3)) * -1.0 + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 6, 7)) * -1.0 + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 1, 3)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 7, 1)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 1, 7)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 3, 1)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 3, 7)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 7, 1)) * -1.0 + t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 7, 3, 5)) * -1.0 + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 7, 3)) * -1.0 + t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) + return t4_abbbabbb + +def t4_uhf_baaabaaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_baaabaaa = np.zeros((nocc[1], nocc[0], nocc[0], nocc[0], nvir[1], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + t4_baaabaaa += einsum(c4.baaabaaa, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 6, 1, 5, 7)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 6, 5, 1, 7)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 6, 5, 7, 1)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 1, 5, 7)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 5, 1, 7)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 5, 7, 1)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 6, 1, 5, 7)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 6, 5, 1, 7)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 6, 5, 7, 1)) * -1.0 + t4_baaabaaa += einsum(t1.bb, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 0, 4, 5, 3, 2, 6, 7)) * -1.0 + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 0, 4, 5, 3, 6, 2, 7)) + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 0, 4, 5, 3, 6, 7, 2)) * -1.0 + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 0, 5, 3, 2, 6, 7)) + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 0, 5, 3, 6, 2, 7)) * -1.0 + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 0, 5, 3, 6, 7, 2)) + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 5, 0, 3, 2, 6, 7)) * -1.0 + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 5, 0, 3, 6, 2, 7)) + t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 5, 0, 3, 6, 7, 2)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 1, 3, 6)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 1, 6, 3)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 3, 1, 6)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 6, 1, 3)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 3, 6, 1)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 6, 3, 1)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 1, 3, 6)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 1, 6, 3)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 3, 1, 6)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 6, 1, 3)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 3, 6, 1)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 6, 3, 1)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 1, 3, 6)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 1, 6, 3)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 3, 1, 6)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 1, 3)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 3, 6, 1)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 3, 1)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 0, 4, 5, 3, 1, 6, 7)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 0, 4, 5, 3, 6, 1, 7)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 0, 4, 5, 3, 6, 7, 1)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 0, 5, 3, 1, 6, 7)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 0, 5, 3, 6, 1, 7)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 0, 5, 3, 6, 7, 1)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 5, 0, 3, 1, 6, 7)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 5, 0, 3, 6, 1, 7)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 5, 0, 3, 6, 7, 1)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 1, 3, 5)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 1, 5, 3)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 3, 1, 5)) + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 5, 1, 3)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 3, 5, 1)) * -1.0 + t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 5, 3, 1)) + return t4_baaabaaa + +def t4_uhf_baabbaab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_baabbaab = np.zeros((nocc[1], nocc[0], nocc[0], nocc[1], nvir[1], nvir[0], nvir[0], nvir[1]), dtype=np.float64) + t4_baabbaab += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (1, 0, 2, 3, 5, 4, 6, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_baabbaab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 1, 5, 7, 6)) * -1.0 + t4_baabbaab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 6, 5, 7, 1)) + t4_baabbaab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 1, 5, 7, 6)) + t4_baabbaab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 6, 5, 7, 1)) * -1.0 + t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 4, 5, 3, 2, 6, 7)) * -1.0 + t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 4, 5, 7, 2, 6, 3)) + t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 4, 5, 3, 6, 2, 7)) + t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 4, 5, 7, 6, 2, 3)) * -1.0 + t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 1, 3, 2, 6, 7)) + t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 1, 7, 2, 6, 3)) * -1.0 + t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 1, 3, 6, 2, 7)) * -1.0 + t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 1, 7, 6, 2, 3)) + t4_baabbaab += einsum(t2.bbbb, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 4, 5, 3, 1, 6, 7)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 4, 5, 7, 1, 6, 3)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 4, 5, 3, 6, 1, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 4, 5, 7, 6, 1, 3)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 3, 1, 6, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 1, 6, 3)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 3, 6, 1, 7)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 6, 1, 3)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 0, 5, 3, 1, 6, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 0, 5, 7, 1, 6, 3)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 0, 5, 3, 6, 1, 7)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 0, 5, 7, 6, 1, 3)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 3, 1, 6, 7)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 1, 6, 3)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 3, 6, 1, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 1, 3)) * -1.0 + t4_baabbaab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_baabbaab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 2, 6, 5, 1, 3, 7)) * -1.0 + t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 2, 6, 7, 1, 3, 5)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 2, 6, 5, 3, 1, 7)) + t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 2, 6, 7, 3, 1, 5)) * -1.0 + return t4_baabbaab + +def t4_uhf_babababa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_babababa = np.zeros((nocc[1], nocc[0], nocc[1], nocc[0], nvir[1], nvir[0], nvir[1], nvir[0]), dtype=np.float64) + t4_babababa += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (1, 0, 3, 2, 5, 4, 7, 6)) + t4_babababa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 7, 6, 1)) + t4_babababa += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 7, 6)) + t4_babababa += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_babababa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_babababa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 1, 7)) + t4_babababa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 1, 5, 6, 7)) + t4_babababa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 5, 1, 7)) * -1.0 + t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 5, 4, 3, 2, 7, 6)) * -1.0 + t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 5, 4, 7, 2, 3, 6)) + t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 5, 4, 3, 6, 7, 2)) + t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 5, 4, 7, 6, 3, 2)) * -1.0 + t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 1, 4, 3, 2, 7, 6)) + t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 1, 4, 7, 2, 3, 6)) * -1.0 + t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 1, 4, 3, 6, 7, 2)) * -1.0 + t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 1, 4, 7, 6, 3, 2)) + t4_babababa += einsum(t2.bbbb, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 5, 4, 3, 1, 7, 6)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 5, 4, 7, 1, 3, 6)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 5, 4, 3, 6, 7, 1)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 5, 4, 7, 6, 3, 1)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 3, 1, 7, 6)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 1, 3, 6)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 3, 6, 7, 1)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 6, 3, 1)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 5, 0, 3, 1, 7, 6)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 5, 0, 7, 1, 3, 6)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 5, 0, 3, 6, 7, 1)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 5, 0, 7, 6, 3, 1)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 2, 0, 3, 1, 7, 6)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 2, 0, 7, 1, 3, 6)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 2, 0, 3, 6, 7, 1)) + t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 2, 0, 7, 6, 3, 1)) * -1.0 + t4_babababa += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_babababa += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) + t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 6, 2, 5, 1, 7, 3)) * -1.0 + t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 6, 2, 7, 1, 5, 3)) + t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 6, 2, 5, 3, 7, 1)) + t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 6, 2, 7, 3, 5, 1)) * -1.0 + return t4_babababa + +def t4_uhf_babbbabb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_babbbabb = np.zeros((nocc[1], nocc[0], nocc[1], nocc[1], nvir[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) + t4_babbbabb += einsum(c4.babbbabb, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_babbbabb += einsum(t1.aa, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 1, 7)) + t4_babbbabb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 7, 1)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 6, 5, 7)) + t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) + t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 6, 5, 7)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) + t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 1, 5, 6, 2, 3, 7)) * -1.0 + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 1, 5, 6, 2, 7, 3)) + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 1, 5, 3, 2, 6, 7)) + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 1, 6, 2, 3, 7)) + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 1, 6, 2, 7, 3)) * -1.0 + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 1, 3, 2, 6, 7)) * -1.0 + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 0, 4, 5, 6, 2, 3, 7)) + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 0, 4, 5, 6, 2, 7, 3)) * -1.0 + t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 0, 4, 5, 3, 2, 6, 7)) * -1.0 + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 0, 4, 5, 3, 1, 6, 7)) * -1.0 + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 0, 4, 5, 6, 1, 3, 7)) + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 0, 4, 5, 6, 1, 7, 3)) * -1.0 + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 7, 6, 1, 3)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 7, 1)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 7, 6, 3, 1)) + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 1, 7)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 7, 6, 1, 3)) + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 7, 6, 3, 1)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 1, 6, 3, 7)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 1, 6, 7, 3)) + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 3, 6, 1, 7)) + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 1, 3)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 3, 6, 7, 1)) * -1.0 + t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 3, 1)) + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 3, 1, 5, 7)) * -1.0 + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 3, 1, 7, 5)) + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 5, 1, 3, 7)) + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 7, 1, 3, 5)) * -1.0 + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 5, 1, 7, 3)) * -1.0 + t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 7, 1, 5, 3)) + return t4_babbbabb + +def t4_uhf_bbaabbaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_bbaabbaa = np.zeros((nocc[1], nocc[1], nocc[0], nocc[0], nvir[1], nvir[1], nvir[0], nvir[0]), dtype=np.float64) + t4_bbaabbaa += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (1, 3, 0, 2, 5, 7, 4, 6)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_bbaabbaa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 1, 6, 5, 7)) * -1.0 + t4_bbaabbaa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 6, 1, 5, 7)) + t4_bbaabbaa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 1, 6, 5, 7)) + t4_bbaabbaa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 6, 1, 5, 7)) * -1.0 + t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 5, 0, 4, 3, 7, 2, 6)) * -1.0 + t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 5, 0, 4, 7, 3, 2, 6)) + t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 5, 0, 4, 3, 7, 6, 2)) + t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 5, 0, 4, 7, 3, 6, 2)) * -1.0 + t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 1, 0, 4, 3, 7, 2, 6)) + t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 1, 0, 4, 7, 3, 2, 6)) * -1.0 + t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 1, 0, 4, 3, 7, 6, 2)) * -1.0 + t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 1, 0, 4, 7, 3, 6, 2)) + t4_bbaabbaa += einsum(t2.bbbb, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 0, 4, 3, 7, 1, 6)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 0, 4, 7, 3, 1, 6)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 0, 4, 3, 7, 6, 1)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 0, 4, 7, 3, 6, 1)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 0, 4, 3, 7, 1, 6)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 0, 4, 7, 3, 1, 6)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 0, 4, 3, 7, 6, 1)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 0, 4, 7, 3, 6, 1)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 4, 0, 3, 7, 1, 6)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 4, 0, 7, 3, 1, 6)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 4, 0, 3, 7, 6, 1)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 4, 0, 7, 3, 6, 1)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 4, 0, 3, 7, 1, 6)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 4, 0, 7, 3, 1, 6)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 4, 0, 3, 7, 6, 1)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 4, 0, 7, 3, 6, 1)) * -1.0 + t4_bbaabbaa += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_bbaabbaa += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 6, 0, 2, 5, 7, 1, 3)) * -1.0 + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 6, 0, 2, 7, 5, 1, 3)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 6, 0, 2, 5, 7, 3, 1)) + t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 6, 0, 2, 7, 5, 3, 1)) * -1.0 + return t4_bbaabbaa + +def t4_uhf_bbabbbab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_bbabbbab = np.zeros((nocc[1], nocc[1], nocc[0], nocc[1], nvir[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t4_bbabbbab += einsum(c4.bbabbbab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_bbabbbab += einsum(t1.aa, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 7, 6, 1)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 7, 6, 1)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 5, 7, 6)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 7, 6)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 0, 5, 6, 3, 2, 7)) * -1.0 + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 0, 5, 6, 7, 2, 3)) + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 0, 5, 3, 6, 2, 7)) + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 1, 6, 3, 2, 7)) + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 1, 6, 7, 2, 3)) * -1.0 + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 1, 3, 6, 2, 7)) * -1.0 + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 0, 5, 6, 3, 2, 7)) + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 0, 5, 6, 7, 2, 3)) * -1.0 + t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 0, 5, 3, 6, 2, 7)) * -1.0 + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 0, 5, 3, 6, 1, 7)) * -1.0 + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 0, 5, 6, 3, 1, 7)) + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 0, 5, 6, 7, 1, 3)) * -1.0 + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 0, 5, 3, 6, 1, 7)) + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 0, 5, 6, 3, 1, 7)) * -1.0 + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 0, 5, 6, 7, 1, 3)) + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 1, 7)) * -1.0 + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 7, 6, 3)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 7, 1, 6, 3)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 3, 7, 6, 1)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 7, 3, 6, 1)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 3, 6, 7)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 3, 1, 6, 7)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 7, 1, 6, 3)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 6, 1)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 7, 3, 6, 1)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 1, 3, 6, 7)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 1, 7, 6, 3)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 3, 1, 6, 7)) + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 1, 6, 3)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 3, 7, 6, 1)) * -1.0 + t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 3, 6, 1)) + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 3, 5, 1, 7)) * -1.0 + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 3, 7, 1, 5)) + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 5, 3, 1, 7)) + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 7, 3, 1, 5)) * -1.0 + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 5, 7, 1, 3)) * -1.0 + t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 7, 5, 1, 3)) + return t4_bbabbbab + +def t4_uhf_bbbabbba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_bbbabbba = np.zeros((nocc[1], nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[1], nvir[0]), dtype=np.float64) + t4_bbbabbba += einsum(c4.bbbabbba, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_bbbabbba += einsum(t1.aa, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 1, 7)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 5, 6, 7)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 5, 0, 6, 3, 7, 2)) * -1.0 + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 5, 0, 6, 7, 3, 2)) + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 5, 0, 3, 6, 7, 2)) + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 1, 0, 6, 3, 7, 2)) + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 1, 0, 6, 7, 3, 2)) * -1.0 + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 1, 0, 3, 6, 7, 2)) * -1.0 + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 5, 0, 6, 3, 7, 2)) + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 5, 0, 6, 7, 3, 2)) * -1.0 + t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 5, 0, 3, 6, 7, 2)) * -1.0 + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 5, 0, 3, 6, 7, 1)) * -1.0 + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 5, 0, 6, 3, 7, 1)) + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 5, 0, 6, 7, 3, 1)) * -1.0 + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 5, 0, 3, 6, 7, 1)) + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 5, 0, 6, 3, 7, 1)) * -1.0 + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 5, 0, 6, 7, 3, 1)) + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 2, 0, 3, 6, 7, 1)) * -1.0 + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 2, 0, 6, 3, 7, 1)) + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 2, 0, 6, 7, 3, 1)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 3, 7, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 7, 3, 6)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 3, 1, 7, 6)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 7, 1, 3, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 3, 7, 1, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 7, 3, 1, 6)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 3, 7, 6)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 3, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 3, 1, 7, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 7, 1, 3, 6)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 1, 6)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 7, 3, 1, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 1, 3, 7, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 1, 7, 3, 6)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 3, 1, 7, 6)) + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 1, 3, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 3, 7, 1, 6)) * -1.0 + t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 3, 1, 6)) + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 3, 5, 7, 1)) * -1.0 + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 3, 7, 5, 1)) + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 5, 3, 7, 1)) + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 7, 3, 5, 1)) * -1.0 + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 5, 7, 3, 1)) * -1.0 + t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 7, 5, 3, 1)) + return t4_bbbabbba + +def t4_uhf_bbbbbbbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_bbbbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t4_bbbbbbbb += einsum(c4.bbbbbbbb, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 5, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 5, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 3, 6, 7)) + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 6, 7, 2, 3)) + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 3, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 6, 7, 2, 3)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 3, 7)) + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 7, 3)) + t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 7, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 3, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 3, 1, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 1, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 3, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 3, 1, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 1, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 3, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 1, 3, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 1, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 1, 3, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 3, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 3, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 3, 1, 6, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 7, 3, 5)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 7, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 7, 5)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 1, 3, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 1, 3, 5)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 1, 7, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 1, 5, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 5, 1, 7)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 7, 1, 5)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 3, 1, 5)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 5, 1, 3)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 5, 7, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 7, 5, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 3, 7, 1)) * -1.0 + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 3, 5, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 7, 3, 1)) + t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 5, 3, 1)) * -1.0 + return t4_bbbbbbbb + +def t4_rhf(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) + t4 += einsum(c4, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 1, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 1, 7, 6)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 6, 7, 1)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 1, 5, 6, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 5, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 7, 6)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 7, 3, 6)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 3, 6, 2, 7)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 3, 7, 2, 6)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 7, 6, 3)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 2, 7)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 2, 3, 6, 7)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 2, 7, 6, 3)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 6, 3, 2, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 6, 7, 2, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 7, 6, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 7, 3, 6)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 7, 1, 6)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 1, 3, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 6, 3, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 1, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 7, 6, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 7, 1, 6, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 7, 3, 6, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 6, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 + return t4 + +def t4_ghf(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) + t4 += einsum(c4, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 7, 1)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 5, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 5, 6, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 3, 6, 7)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 7, 3)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 6, 7, 2, 3)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 2, 3, 6, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 3, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 6, 7, 2, 3)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 3, 7)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 7, 3)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 3, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 7, 3)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 7, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 7, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 3, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 1, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 1, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 7, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 3, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 3, 1, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 3, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 1, 3, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 7, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 1, 3, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 3, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 3, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 1, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 7, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 7, 3, 5)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 5, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 1, 7, 5)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 1, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 1, 3, 5)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 1, 7, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 1, 5, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 5, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 7, 1, 5)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 3, 1, 5)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 5, 1, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 5, 7, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 7, 5, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 3, 5, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 7, 3, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 5, 3, 1)) * -1.0 + return t4 + diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index ec62f51d2..42e4fccb4 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -218,744 +218,47 @@ def as_ccsdtq(self): c3_aaaaaa, c3_abaaba, c3_abbabb, c3_babbab, c3_bbabba, c3_bbbbbb = (c / self.c0 for c in self.c3) c4_aaaaaaaa, c4_aaabaaab, c4_aabaaaba, c4_abaaabaa, c4_abababab, c4_abbbabbb, c4_bbabbbab, c4_bbbabbba, c4_bbbbbbbb = (c / self.c0 for c in self.c4) - nocc = self.nocc - nvir = self.nvir - - t1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - t1_aa += einsum("ia->ia", c1_aa) - - t1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - t1_bb += einsum("ia->ia", c1_bb) - - t2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - t2_aaaa += einsum("ijab->ijab", c2_aaaa) * 2.0 - t2_aaaa += einsum("ia,jb->ijab", t1_aa, t1_aa) * -1.0 - t2_aaaa += einsum("ib,ja->ijab", t1_aa, t1_aa) - - t2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) - t2_abab += einsum("ijab->ijab", c2_abab) - t2_abab += einsum("ia,jb->ijab", t1_aa, t1_bb) * -1.0 - - t2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - t2_bbbb += einsum("ijab->ijab", c2_bbbb) * 2.0 - t2_bbbb += einsum("ia,jb->ijab", t1_bb, t1_bb) * -1.0 - t2_bbbb += einsum("ib,ja->ijab", t1_bb, t1_bb) - - t3_aaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - t3_aaaaaa += einsum("ijkabc->ijkabc", c3_aaaaaa) * 6.0 - t3_aaaaaa += einsum("ia,jkbc->ijkabc", t1_aa, t2_aaaa) * -2.0 - t3_aaaaaa += einsum("ib,jkac->ijkabc", t1_aa, t2_aaaa) * 2.0 - t3_aaaaaa += einsum("ic,jkab->ijkabc", t1_aa, t2_aaaa) * -2.0 - t3_aaaaaa += einsum("ja,ikbc->ijkabc", t1_aa, t2_aaaa) * 2.0 - t3_aaaaaa += einsum("jb,ikac->ijkabc", t1_aa, t2_aaaa) * -2.0 - t3_aaaaaa += einsum("jc,ikab->ijkabc", t1_aa, t2_aaaa) * 2.0 - t3_aaaaaa += einsum("ka,ijbc->ijkabc", t1_aa, t2_aaaa) * -2.0 - t3_aaaaaa += einsum("kb,ijac->ijkabc", t1_aa, t2_aaaa) * 2.0 - t3_aaaaaa += einsum("kc,ijab->ijkabc", t1_aa, t2_aaaa) * -2.0 - t3_aaaaaa += einsum("ia,jb,kc->ijkabc", t1_aa, t1_aa, t1_aa) * -1.0 - t3_aaaaaa += einsum("ia,jc,kb->ijkabc", t1_aa, t1_aa, t1_aa) - t3_aaaaaa += einsum("ib,ja,kc->ijkabc", t1_aa, t1_aa, t1_aa) - t3_aaaaaa += einsum("ib,jc,ka->ijkabc", t1_aa, t1_aa, t1_aa) * -1.0 - t3_aaaaaa += einsum("ic,ja,kb->ijkabc", t1_aa, t1_aa, t1_aa) * -1.0 - t3_aaaaaa += einsum("ic,jb,ka->ijkabc", t1_aa, t1_aa, t1_aa) - - t3_abaaba = np.zeros((nocc[0], nocc[1], nocc[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) - t3_abaaba += einsum("ijkabc->ijkabc", c3_abaaba) * 2.0 - t3_abaaba += einsum("ia,kjcb->ijkabc", t1_aa, t2_abab) * -1.0 - t3_abaaba += einsum("ic,kjab->ijkabc", t1_aa, t2_abab) - t3_abaaba += einsum("ka,ijcb->ijkabc", t1_aa, t2_abab) - t3_abaaba += einsum("kc,ijab->ijkabc", t1_aa, t2_abab) * -1.0 - t3_abaaba += einsum("jb,ikac->ijkabc", t1_bb, t2_aaaa) * -2.0 - t3_abaaba += einsum("ia,kc,jb->ijkabc", t1_aa, t1_aa, t1_bb) * -1.0 - t3_abaaba += einsum("ic,ka,jb->ijkabc", t1_aa, t1_aa, t1_bb) - - t3_abbabb = np.zeros((nocc[0], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) - t3_abbabb += einsum("ijkabc->ijkabc", c3_abbabb) * 2.0 - t3_abbabb += einsum("ia,jkbc->ijkabc", t1_aa, t2_bbbb) * -2.0 - t3_abbabb += einsum("jb,ikac->ijkabc", t1_bb, t2_abab) * -1.0 - t3_abbabb += einsum("jc,ikab->ijkabc", t1_bb, t2_abab) - t3_abbabb += einsum("kb,ijac->ijkabc", t1_bb, t2_abab) - t3_abbabb += einsum("kc,ijab->ijkabc", t1_bb, t2_abab) * -1.0 - t3_abbabb += einsum("ia,jb,kc->ijkabc", t1_aa, t1_bb, t1_bb) * -1.0 - t3_abbabb += einsum("ia,jc,kb->ijkabc", t1_aa, t1_bb, t1_bb) - - t3_babbab = np.zeros((nocc[1], nocc[0], nocc[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t3_babbab += einsum("ijkabc->ijkabc", c3_babbab) * 2.0 - t3_babbab += einsum("jb,ikac->ijkabc", t1_aa, t2_bbbb) * -2.0 - t3_babbab += einsum("ia,jkbc->ijkabc", t1_bb, t2_abab) * -1.0 - t3_babbab += einsum("ic,jkba->ijkabc", t1_bb, t2_abab) - t3_babbab += einsum("ka,jibc->ijkabc", t1_bb, t2_abab) - t3_babbab += einsum("kc,jiba->ijkabc", t1_bb, t2_abab) * -1.0 - t3_babbab += einsum("jb,ia,kc->ijkabc", t1_aa, t1_bb, t1_bb) * -1.0 - t3_babbab += einsum("jb,ic,ka->ijkabc", t1_aa, t1_bb, t1_bb) - - t3_bbabba = np.zeros((nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) - t3_bbabba += einsum("ijkabc->ijkabc", c3_bbabba) * 2.0 - t3_bbabba += einsum("kc,ijab->ijkabc", t1_aa, t2_bbbb) * -2.0 - t3_bbabba += einsum("ia,kjcb->ijkabc", t1_bb, t2_abab) * -1.0 - t3_bbabba += einsum("ib,kjca->ijkabc", t1_bb, t2_abab) - t3_bbabba += einsum("ja,kicb->ijkabc", t1_bb, t2_abab) - t3_bbabba += einsum("jb,kica->ijkabc", t1_bb, t2_abab) * -1.0 - t3_bbabba += einsum("kc,ia,jb->ijkabc", t1_aa, t1_bb, t1_bb) * -1.0 - t3_bbabba += einsum("kc,ib,ja->ijkabc", t1_aa, t1_bb, t1_bb) - - t3_bbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t3_bbbbbb += einsum("ijkabc->ijkabc", c3_bbbbbb) * 6.0 - t3_bbbbbb += einsum("ia,jkbc->ijkabc", t1_bb, t2_bbbb) * -2.0 - t3_bbbbbb += einsum("ib,jkac->ijkabc", t1_bb, t2_bbbb) * 2.0 - t3_bbbbbb += einsum("ic,jkab->ijkabc", t1_bb, t2_bbbb) * -2.0 - t3_bbbbbb += einsum("ja,ikbc->ijkabc", t1_bb, t2_bbbb) * 2.0 - t3_bbbbbb += einsum("jb,ikac->ijkabc", t1_bb, t2_bbbb) * -2.0 - t3_bbbbbb += einsum("jc,ikab->ijkabc", t1_bb, t2_bbbb) * 2.0 - t3_bbbbbb += einsum("ka,ijbc->ijkabc", t1_bb, t2_bbbb) * -2.0 - t3_bbbbbb += einsum("kb,ijac->ijkabc", t1_bb, t2_bbbb) * 2.0 - t3_bbbbbb += einsum("kc,ijab->ijkabc", t1_bb, t2_bbbb) * -2.0 - t3_bbbbbb += einsum("ia,jb,kc->ijkabc", t1_bb, t1_bb, t1_bb) * -1.0 - t3_bbbbbb += einsum("ia,jc,kb->ijkabc", t1_bb, t1_bb, t1_bb) - t3_bbbbbb += einsum("ib,ja,kc->ijkabc", t1_bb, t1_bb, t1_bb) - t3_bbbbbb += einsum("ib,jc,ka->ijkabc", t1_bb, t1_bb, t1_bb) * -1.0 - t3_bbbbbb += einsum("ic,ja,kb->ijkabc", t1_bb, t1_bb, t1_bb) * -1.0 - t3_bbbbbb += einsum("ic,jb,ka->ijkabc", t1_bb, t1_bb, t1_bb) - - t4_aaaaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - t4_aaaaaaaa += einsum("ijklabcd->ijklabcd", c4_aaaaaaaa) * 24.0 - t4_aaaaaaaa += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 - t4_aaaaaaaa += einsum("ib,jklacd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 - t4_aaaaaaaa += einsum("ic,jklabd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 - t4_aaaaaaaa += einsum("id,jklabc->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 - t4_aaaaaaaa += einsum("ja,iklbcd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 - t4_aaaaaaaa += einsum("jb,iklacd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 - t4_aaaaaaaa += einsum("jc,iklabd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 - t4_aaaaaaaa += einsum("jd,iklabc->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 - t4_aaaaaaaa += einsum("ka,ijlbcd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 - t4_aaaaaaaa += einsum("kb,ijlacd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 - t4_aaaaaaaa += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 - t4_aaaaaaaa += einsum("kd,ijlabc->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 - t4_aaaaaaaa += einsum("la,ijkbcd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 - t4_aaaaaaaa += einsum("lb,ijkacd->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 - t4_aaaaaaaa += einsum("lc,ijkabd->ijklabcd", t1_aa, t3_aaaaaa) * 6.0 - t4_aaaaaaaa += einsum("ld,ijkabc->ijklabcd", t1_aa, t3_aaaaaa) * -6.0 - t4_aaaaaaaa += einsum("ikac,jlbd->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ikad,jlbc->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 - t4_aaaaaaaa += einsum("ikab,jlcd->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 - t4_aaaaaaaa += einsum("ikbc,jlad->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 - t4_aaaaaaaa += einsum("ikbd,jlac->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ikcd,jlab->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 - t4_aaaaaaaa += einsum("ilac,jkbd->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 - t4_aaaaaaaa += einsum("ilad,jkbc->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ilab,jkcd->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ilbc,jkad->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ilbd,jkac->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 - t4_aaaaaaaa += einsum("ilcd,jkab->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ijac,klbd->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 - t4_aaaaaaaa += einsum("ijad,klbc->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ijab,klcd->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ijbc,klad->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ijbd,klac->ijklabcd", t2_aaaa, t2_aaaa) * 4.0 - t4_aaaaaaaa += einsum("ijcd,klab->ijklabcd", t2_aaaa, t2_aaaa) * -4.0 - t4_aaaaaaaa += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ia,jc,klbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ia,jd,klbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ib,ja,klcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ib,jc,klad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ib,jd,klac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ic,ja,klbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ic,jb,klad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ic,jd,klab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("id,ja,klbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("id,jb,klac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("id,jc,klab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ia,kb,jlcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ia,kd,jlbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ib,ka,jlcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ib,kc,jlad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ib,kd,jlac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ic,ka,jlbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ic,kb,jlad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ic,kd,jlab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("id,ka,jlbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("id,kb,jlac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("id,kc,jlab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ia,lb,jkcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ia,lc,jkbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ia,ld,jkbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ib,la,jkcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ib,lc,jkad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ib,ld,jkac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ic,la,jkbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ic,lb,jkad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ic,ld,jkab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("id,la,jkbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("id,lb,jkac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("id,lc,jkab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ja,kb,ilcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ja,kc,ilbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ja,kd,ilbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jb,ka,ilcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jb,kc,ilad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jb,kd,ilac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jc,ka,ilbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jc,kb,ilad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jc,kd,ilab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jd,ka,ilbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jd,kb,ilac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jd,kc,ilab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ja,lb,ikcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ja,lc,ikbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ja,ld,ikbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jb,la,ikcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jb,lc,ikad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jb,ld,ikac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jc,la,ikbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jc,lb,ikad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jc,ld,ikab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jd,la,ikbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("jd,lb,ikac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("jd,lc,ikab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ka,lb,ijcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("ka,lc,ijbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ka,ld,ijbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("kb,la,ijcd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("kb,lc,ijad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("kb,ld,ijac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("kc,la,ijbd->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("kc,lb,ijad->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("kd,la,ijbc->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("kd,lb,ijac->ijklabcd", t1_aa, t1_aa, t2_aaaa) * -2.0 - t4_aaaaaaaa += einsum("kd,lc,ijab->ijklabcd", t1_aa, t1_aa, t2_aaaa) * 2.0 - t4_aaaaaaaa += einsum("ia,jb,kc,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ia,jb,kd,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("ia,jc,kb,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("ia,jc,kd,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ia,jd,kb,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ia,jd,kc,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("ib,ja,kc,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("ib,ja,kd,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ib,jc,ka,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ib,jc,kd,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("ib,jd,ka,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("ib,jd,kc,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ic,ja,kb,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ic,ja,kd,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("ic,jb,ka,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("ic,jb,kd,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ic,jd,ka,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("ic,jd,kb,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("id,ja,kb,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("id,ja,kc,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("id,jb,ka,lc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - t4_aaaaaaaa += einsum("id,jb,kc,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("id,jc,ka,lb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) - t4_aaaaaaaa += einsum("id,jc,kb,la->ijklabcd", t1_aa, t1_aa, t1_aa, t1_aa) * -1.0 - - t4_aaabaaab = np.zeros((nocc[0], nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[0], nvir[1]), dtype=np.float64) - t4_aaabaaab += einsum("ijklabcd->ijklabcd", c4_aaabaaab) * 6.0 - t4_aaabaaab += einsum("ia,jlkbdc->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aaabaaab += einsum("ib,jlkadc->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_aaabaaab += einsum("ic,jlkadb->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aaabaaab += einsum("ja,ilkbdc->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_aaabaaab += einsum("jb,ilkadc->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aaabaaab += einsum("jc,ilkadb->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_aaabaaab += einsum("ka,iljbdc->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aaabaaab += einsum("kb,iljadc->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_aaabaaab += einsum("kc,iljadb->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aaabaaab += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_aaaaaa) * -6.0 - t4_aaabaaab += einsum("ilad,jkbc->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("ilbd,jkac->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_aaabaaab += einsum("ilcd,jkab->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("jlad,ikbc->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_aaabaaab += einsum("jlbd,ikac->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("jlcd,ikab->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_aaabaaab += einsum("klad,ijbc->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("klbd,ijac->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_aaabaaab += einsum("klcd,ijab->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("ia,jc,klbd->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("ib,ja,klcd->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("ib,jc,klad->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("ic,ja,klbd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("ic,jb,klad->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("ia,kb,jlcd->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("ib,ka,jlcd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("ib,kc,jlad->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("ic,ka,jlbd->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("ic,kb,jlad->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("ja,kb,ilcd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("ja,kc,ilbd->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("jb,ka,ilcd->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("jb,kc,ilad->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("jc,ka,ilbd->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aaabaaab += einsum("jc,kb,ilad->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aaabaaab += einsum("ia,ld,jkbc->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("ib,ld,jkac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_aaabaaab += einsum("ic,ld,jkab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("ja,ld,ikbc->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_aaabaaab += einsum("jb,ld,ikac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("jc,ld,ikab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_aaabaaab += einsum("ka,ld,ijbc->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("kb,ld,ijac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_aaabaaab += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aaabaaab += einsum("ia,jb,kc,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_aaabaaab += einsum("ia,jc,kb,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - t4_aaabaaab += einsum("ib,ja,kc,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - t4_aaabaaab += einsum("ib,jc,ka,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_aaabaaab += einsum("ic,ja,kb,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_aaabaaab += einsum("ic,jb,ka,ld->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - - t4_aabaaaba = np.zeros((nocc[0], nocc[0], nocc[1], nocc[0], nvir[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) - t4_aabaaaba += einsum("ijklabcd->ijklabcd", c4_aabaaaba) * 6.0 - t4_aabaaaba += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aabaaaba += einsum("ib,jklacd->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_aabaaaba += einsum("id,jklacb->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aabaaaba += einsum("ja,iklbcd->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_aabaaaba += einsum("jb,iklacd->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aabaaaba += einsum("jd,iklacb->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_aabaaaba += einsum("la,ikjbcd->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aabaaaba += einsum("lb,ikjacd->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_aabaaaba += einsum("ld,ikjacb->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_aabaaaba += einsum("kc,ijlabd->ijklabcd", t1_bb, t3_aaaaaa) * -6.0 - t4_aabaaaba += einsum("ikac,jlbd->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("ikbc,jlad->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_aabaaaba += einsum("ikdc,jlab->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("jkac,ilbd->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_aabaaaba += einsum("jkbc,ilad->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("jkdc,ilab->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_aabaaaba += einsum("lkac,ijbd->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("lkbc,ijad->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_aabaaaba += einsum("lkdc,ijab->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("ia,jb,lkdc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("ia,jd,lkbc->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("ib,ja,lkdc->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("ib,jd,lkac->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("id,ja,lkbc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("id,jb,lkac->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("ia,lb,jkdc->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("ia,ld,jkbc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("ib,la,jkdc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("ib,ld,jkac->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("id,la,jkbc->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("id,lb,jkac->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("ja,lb,ikdc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("ja,ld,ikbc->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("jb,la,ikdc->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("jb,ld,ikac->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("jd,la,ikbc->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_aabaaaba += einsum("jd,lb,ikac->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_aabaaaba += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("ib,kc,jlad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_aabaaaba += einsum("id,kc,jlab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("ja,kc,ilbd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_aabaaaba += einsum("jb,kc,ilad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("jd,kc,ilab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_aabaaaba += einsum("la,kc,ijbd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("lb,kc,ijad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_aabaaaba += einsum("ld,kc,ijab->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_aabaaaba += einsum("ia,jb,ld,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_aabaaaba += einsum("ia,jd,lb,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - t4_aabaaaba += einsum("ib,ja,ld,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - t4_aabaaaba += einsum("ib,jd,la,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_aabaaaba += einsum("id,ja,lb,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_aabaaaba += einsum("id,jb,la,kc->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - - t4_abaaabaa = np.zeros((nocc[0], nocc[1], nocc[0], nocc[0], nvir[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) - t4_abaaabaa += einsum("ijklabcd->ijklabcd", c4_abaaabaa) * 6.0 - t4_abaaabaa += einsum("ia,kjlcbd->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_abaaabaa += einsum("ic,kjlabd->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_abaaabaa += einsum("id,kjlabc->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_abaaabaa += einsum("ka,ijlcbd->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_abaaabaa += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_abaaabaa += einsum("kd,ijlabc->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_abaaabaa += einsum("la,ijkcbd->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_abaaabaa += einsum("lc,ijkabd->ijklabcd", t1_aa, t3_abaaba) * 2.0 - t4_abaaabaa += einsum("ld,ijkabc->ijklabcd", t1_aa, t3_abaaba) * -2.0 - t4_abaaabaa += einsum("jb,iklacd->ijklabcd", t1_bb, t3_aaaaaa) * -6.0 - t4_abaaabaa += einsum("ijab,klcd->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("ijcb,klad->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_abaaabaa += einsum("ijdb,klac->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("kjab,ilcd->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_abaaabaa += einsum("kjcb,ilad->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("kjdb,ilac->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_abaaabaa += einsum("ljab,ikcd->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("ljcb,ikad->ijklabcd", t2_abab, t2_aaaa) * 2.0 - t4_abaaabaa += einsum("ljdb,ikac->ijklabcd", t2_abab, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("ia,kc,ljdb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("ia,kd,ljcb->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("ic,ka,ljdb->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("ic,kd,ljab->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("id,ka,ljcb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("id,kc,ljab->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("ia,lc,kjdb->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("ia,ld,kjcb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("ic,la,kjdb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("ic,ld,kjab->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("id,la,kjcb->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("id,lc,kjab->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("ka,lc,ijdb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("ka,ld,ijcb->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("kc,la,ijdb->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("kd,la,ijcb->ijklabcd", t1_aa, t1_aa, t2_abab) * -1.0 - t4_abaaabaa += einsum("kd,lc,ijab->ijklabcd", t1_aa, t1_aa, t2_abab) - t4_abaaabaa += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("ic,jb,klad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_abaaabaa += einsum("id,jb,klac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("ka,jb,ilcd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_abaaabaa += einsum("kc,jb,ilad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("kd,jb,ilac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_abaaabaa += einsum("la,jb,ikcd->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("lc,jb,ikad->ijklabcd", t1_aa, t1_bb, t2_aaaa) * 2.0 - t4_abaaabaa += einsum("ld,jb,ikac->ijklabcd", t1_aa, t1_bb, t2_aaaa) * -2.0 - t4_abaaabaa += einsum("ia,kc,ld,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_abaaabaa += einsum("ia,kd,lc,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - t4_abaaabaa += einsum("ic,ka,ld,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - t4_abaaabaa += einsum("ic,kd,la,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_abaaabaa += einsum("id,ka,lc,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) * -1.0 - t4_abaaabaa += einsum("id,kc,la,jb->ijklabcd", t1_aa, t1_aa, t1_aa, t1_bb) - - t4_abababab = np.zeros((nocc[0], nocc[1], nocc[0], nocc[1], nvir[0], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t4_abababab += einsum("ijklabcd->ijklabcd", c4_abababab) * 4.0 - t4_abababab += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_babbab) * -2.0 - t4_abababab += einsum("ic,jklbad->ijklabcd", t1_aa, t3_babbab) * 2.0 - t4_abababab += einsum("ka,ijlcbd->ijklabcd", t1_aa, t3_abbabb) * 2.0 - t4_abababab += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_abbabb) * -2.0 - t4_abababab += einsum("jb,ilkadc->ijklabcd", t1_bb, t3_abaaba) * -2.0 - t4_abababab += einsum("jd,ilkabc->ijklabcd", t1_bb, t3_abaaba) * 2.0 - t4_abababab += einsum("lb,ijkadc->ijklabcd", t1_bb, t3_abaaba) * 2.0 - t4_abababab += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_abaaba) * -2.0 - t4_abababab += einsum("ijab,klcd->ijklabcd", t2_abab, t2_abab) * -1.0 - t4_abababab += einsum("ijad,klcb->ijklabcd", t2_abab, t2_abab) - t4_abababab += einsum("ijcb,klad->ijklabcd", t2_abab, t2_abab) - t4_abababab += einsum("ijcd,klab->ijklabcd", t2_abab, t2_abab) * -1.0 - t4_abababab += einsum("ilab,kjcd->ijklabcd", t2_abab, t2_abab) - t4_abababab += einsum("ilad,kjcb->ijklabcd", t2_abab, t2_abab) * -1.0 - t4_abababab += einsum("ilcb,kjad->ijklabcd", t2_abab, t2_abab) * -1.0 - t4_abababab += einsum("ilcd,kjab->ijklabcd", t2_abab, t2_abab) - t4_abababab += einsum("ikac,jlbd->ijklabcd", t2_aaaa, t2_bbbb) * -4.0 - t4_abababab += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_aa, t2_bbbb) * -2.0 - t4_abababab += einsum("ic,ka,jlbd->ijklabcd", t1_aa, t1_aa, t2_bbbb) * 2.0 - t4_abababab += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 - t4_abababab += einsum("ia,jd,klcb->ijklabcd", t1_aa, t1_bb, t2_abab) - t4_abababab += einsum("ic,jb,klad->ijklabcd", t1_aa, t1_bb, t2_abab) - t4_abababab += einsum("ic,jd,klab->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 - t4_abababab += einsum("ia,lb,kjcd->ijklabcd", t1_aa, t1_bb, t2_abab) - t4_abababab += einsum("ia,ld,kjcb->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 - t4_abababab += einsum("ic,lb,kjad->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 - t4_abababab += einsum("ic,ld,kjab->ijklabcd", t1_aa, t1_bb, t2_abab) - t4_abababab += einsum("ka,jb,ilcd->ijklabcd", t1_aa, t1_bb, t2_abab) - t4_abababab += einsum("ka,jd,ilcb->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 - t4_abababab += einsum("kc,jb,ilad->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 - t4_abababab += einsum("kc,jd,ilab->ijklabcd", t1_aa, t1_bb, t2_abab) - t4_abababab += einsum("ka,lb,ijcd->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 - t4_abababab += einsum("ka,ld,ijcb->ijklabcd", t1_aa, t1_bb, t2_abab) - t4_abababab += einsum("kc,lb,ijad->ijklabcd", t1_aa, t1_bb, t2_abab) - t4_abababab += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_bb, t2_abab) * -1.0 - t4_abababab += einsum("jb,ld,ikac->ijklabcd", t1_bb, t1_bb, t2_aaaa) * -2.0 - t4_abababab += einsum("jd,lb,ikac->ijklabcd", t1_bb, t1_bb, t2_aaaa) * 2.0 - t4_abababab += einsum("ia,kc,jb,ld->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) * -1.0 - t4_abababab += einsum("ia,kc,jd,lb->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) - t4_abababab += einsum("ic,ka,jb,ld->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) - t4_abababab += einsum("ic,ka,jd,lb->ijklabcd", t1_aa, t1_aa, t1_bb, t1_bb) * -1.0 - - t4_abbbabbb = np.zeros((nocc[0], nocc[1], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t4_abbbabbb += einsum("ijklabcd->ijklabcd", c4_abbbabbb) * 6.0 - t4_abbbabbb += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_bbbbbb) * -6.0 - t4_abbbabbb += einsum("jb,iklacd->ijklabcd", t1_bb, t3_abbabb) * -2.0 - t4_abbbabbb += einsum("jc,iklabd->ijklabcd", t1_bb, t3_abbabb) * 2.0 - t4_abbbabbb += einsum("jd,iklabc->ijklabcd", t1_bb, t3_abbabb) * -2.0 - t4_abbbabbb += einsum("kb,ijlacd->ijklabcd", t1_bb, t3_abbabb) * 2.0 - t4_abbbabbb += einsum("kc,ijlabd->ijklabcd", t1_bb, t3_abbabb) * -2.0 - t4_abbbabbb += einsum("kd,ijlabc->ijklabcd", t1_bb, t3_abbabb) * 2.0 - t4_abbbabbb += einsum("lb,ijkacd->ijklabcd", t1_bb, t3_abbabb) * -2.0 - t4_abbbabbb += einsum("lc,ijkabd->ijklabcd", t1_bb, t3_abbabb) * 2.0 - t4_abbbabbb += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_abbabb) * -2.0 - t4_abbbabbb += einsum("ikac,jlbd->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ikad,jlbc->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_abbbabbb += einsum("ikab,jlcd->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_abbbabbb += einsum("ilac,jkbd->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_abbbabbb += einsum("ilad,jkbc->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ilab,jkcd->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ijac,klbd->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_abbbabbb += einsum("ijad,klbc->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ijab,klcd->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ia,jb,klcd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ia,jc,klbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_abbbabbb += einsum("ia,jd,klbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ia,kb,jlcd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_abbbabbb += einsum("ia,kc,jlbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ia,kd,jlbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_abbbabbb += einsum("ia,lb,jkcd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("ia,lc,jkbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_abbbabbb += einsum("ia,ld,jkbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_abbbabbb += einsum("jb,kc,ilad->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("jb,kd,ilac->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("jc,kb,ilad->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("jc,kd,ilab->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("jd,kb,ilac->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("jd,kc,ilab->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("jb,lc,ikad->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("jb,ld,ikac->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("jc,lb,ikad->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("jc,ld,ikab->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("jd,lb,ikac->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("jd,lc,ikab->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("kb,lc,ijad->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("kb,ld,ijac->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("kc,lb,ijad->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("kc,ld,ijab->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("kd,lb,ijac->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_abbbabbb += einsum("kd,lc,ijab->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_abbbabbb += einsum("ia,jb,kc,ld->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_abbbabbb += einsum("ia,jb,kd,lc->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - t4_abbbabbb += einsum("ia,jc,kb,ld->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - t4_abbbabbb += einsum("ia,jc,kd,lb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_abbbabbb += einsum("ia,jd,kb,lc->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_abbbabbb += einsum("ia,jd,kc,lb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - - t4_bbabbbab = np.zeros((nocc[1], nocc[1], nocc[0], nocc[1], nvir[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t4_bbabbbab += einsum("ijklabcd->ijklabcd", c4_bbabbbab) * 6.0 - t4_bbabbbab += einsum("kc,ijlabd->ijklabcd", t1_aa, t3_bbbbbb) * -6.0 - t4_bbabbbab += einsum("ia,jklbcd->ijklabcd", t1_bb, t3_babbab) * -2.0 - t4_bbabbbab += einsum("ib,jklacd->ijklabcd", t1_bb, t3_babbab) * 2.0 - t4_bbabbbab += einsum("id,jklacb->ijklabcd", t1_bb, t3_babbab) * -2.0 - t4_bbabbbab += einsum("ja,iklbcd->ijklabcd", t1_bb, t3_babbab) * 2.0 - t4_bbabbbab += einsum("jb,iklacd->ijklabcd", t1_bb, t3_babbab) * -2.0 - t4_bbabbbab += einsum("jd,iklacb->ijklabcd", t1_bb, t3_babbab) * 2.0 - t4_bbabbbab += einsum("la,ijkbdc->ijklabcd", t1_bb, t3_bbabba) * -2.0 - t4_bbabbbab += einsum("lb,ijkadc->ijklabcd", t1_bb, t3_bbabba) * 2.0 - t4_bbabbbab += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_bbabba) * -2.0 - t4_bbabbbab += einsum("kjcb,ilad->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("kjcd,ilab->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_bbabbbab += einsum("kjca,ilbd->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_bbabbbab += einsum("klcb,ijad->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_bbabbbab += einsum("klcd,ijab->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("klca,ijbd->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("kicb,jlad->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_bbabbbab += einsum("kicd,jlab->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("kica,jlbd->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("kc,ia,jlbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("kc,ib,jlad->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_bbabbbab += einsum("kc,id,jlab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("kc,ja,ilbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_bbabbbab += einsum("kc,jb,ilad->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("kc,jd,ilab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_bbabbbab += einsum("kc,la,ijbd->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("kc,lb,ijad->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_bbabbbab += einsum("kc,ld,ijab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbabbbab += einsum("ia,jb,klcd->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("ia,jd,klcb->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("ib,ja,klcd->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("ib,jd,klca->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("id,ja,klcb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("id,jb,klca->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("ia,lb,kjcd->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("ia,ld,kjcb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("ib,la,kjcd->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("ib,ld,kjca->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("id,la,kjcb->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("id,lb,kjca->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("ja,lb,kicd->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("ja,ld,kicb->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("jb,la,kicd->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("jb,ld,kica->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("jd,la,kicb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbabbbab += einsum("jd,lb,kica->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbabbbab += einsum("kc,ia,jb,ld->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbabbbab += einsum("kc,ia,jd,lb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - t4_bbabbbab += einsum("kc,ib,ja,ld->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - t4_bbabbbab += einsum("kc,ib,jd,la->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbabbbab += einsum("kc,id,ja,lb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbabbbab += einsum("kc,id,jb,la->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - - t4_bbbabbba = np.zeros((nocc[1], nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[1], nvir[0]), dtype=np.float64) - t4_bbbabbba += einsum("ijklabcd->ijklabcd", c4_bbbabbba) * 6.0 - t4_bbbabbba += einsum("ld,ijkabc->ijklabcd", t1_aa, t3_bbbbbb) * -6.0 - t4_bbbabbba += einsum("ia,jklbcd->ijklabcd", t1_bb, t3_bbabba) * -2.0 - t4_bbbabbba += einsum("ib,jklacd->ijklabcd", t1_bb, t3_bbabba) * 2.0 - t4_bbbabbba += einsum("ic,jklabd->ijklabcd", t1_bb, t3_bbabba) * -2.0 - t4_bbbabbba += einsum("ja,iklbcd->ijklabcd", t1_bb, t3_bbabba) * 2.0 - t4_bbbabbba += einsum("jb,iklacd->ijklabcd", t1_bb, t3_bbabba) * -2.0 - t4_bbbabbba += einsum("jc,iklabd->ijklabcd", t1_bb, t3_bbabba) * 2.0 - t4_bbbabbba += einsum("ka,ijlbcd->ijklabcd", t1_bb, t3_bbabba) * -2.0 - t4_bbbabbba += einsum("kb,ijlacd->ijklabcd", t1_bb, t3_bbabba) * 2.0 - t4_bbbabbba += einsum("kc,ijlabd->ijklabcd", t1_bb, t3_bbabba) * -2.0 - t4_bbbabbba += einsum("ljdb,ikac->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("ljdc,ikab->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_bbbabbba += einsum("ljda,ikbc->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_bbbabbba += einsum("lkdb,ijac->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_bbbabbba += einsum("lkdc,ijab->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("lkda,ijbc->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("lidb,jkac->ijklabcd", t2_abab, t2_bbbb) * 2.0 - t4_bbbabbba += einsum("lidc,jkab->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("lida,jkbc->ijklabcd", t2_abab, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("ld,ia,jkbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("ld,ib,jkac->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_bbbabbba += einsum("ld,ic,jkab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("ld,ja,ikbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_bbbabbba += einsum("ld,jb,ikac->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("ld,jc,ikab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_bbbabbba += einsum("ld,ka,ijbc->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("ld,kb,ijac->ijklabcd", t1_aa, t1_bb, t2_bbbb) * 2.0 - t4_bbbabbba += einsum("ld,kc,ijab->ijklabcd", t1_aa, t1_bb, t2_bbbb) * -2.0 - t4_bbbabbba += einsum("ia,jb,lkdc->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("ia,jc,lkdb->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("ib,ja,lkdc->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("ib,jc,lkda->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("ic,ja,lkdb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("ic,jb,lkda->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("ia,kb,ljdc->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("ia,kc,ljdb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("ib,ka,ljdc->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("ib,kc,ljda->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("ic,ka,ljdb->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("ic,kb,ljda->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("ja,kb,lidc->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("ja,kc,lidb->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("jb,ka,lidc->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("jb,kc,lida->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("jc,ka,lidb->ijklabcd", t1_bb, t1_bb, t2_abab) * -1.0 - t4_bbbabbba += einsum("jc,kb,lida->ijklabcd", t1_bb, t1_bb, t2_abab) - t4_bbbabbba += einsum("ld,ia,jb,kc->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbabbba += einsum("ld,ia,jc,kb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - t4_bbbabbba += einsum("ld,ib,ja,kc->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - t4_bbbabbba += einsum("ld,ib,jc,ka->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbabbba += einsum("ld,ic,ja,kb->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbabbba += einsum("ld,ic,jb,ka->ijklabcd", t1_aa, t1_bb, t1_bb, t1_bb) - - t4_bbbbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t4_bbbbbbbb += einsum("ijklabcd->ijklabcd", c4_bbbbbbbb) * 24.0 - t4_bbbbbbbb += einsum("ia,jklbcd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 - t4_bbbbbbbb += einsum("ib,jklacd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 - t4_bbbbbbbb += einsum("ic,jklabd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 - t4_bbbbbbbb += einsum("id,jklabc->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 - t4_bbbbbbbb += einsum("ja,iklbcd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 - t4_bbbbbbbb += einsum("jb,iklacd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 - t4_bbbbbbbb += einsum("jc,iklabd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 - t4_bbbbbbbb += einsum("jd,iklabc->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 - t4_bbbbbbbb += einsum("ka,ijlbcd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 - t4_bbbbbbbb += einsum("kb,ijlacd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 - t4_bbbbbbbb += einsum("kc,ijlabd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 - t4_bbbbbbbb += einsum("kd,ijlabc->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 - t4_bbbbbbbb += einsum("la,ijkbcd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 - t4_bbbbbbbb += einsum("lb,ijkacd->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 - t4_bbbbbbbb += einsum("lc,ijkabd->ijklabcd", t1_bb, t3_bbbbbb) * 6.0 - t4_bbbbbbbb += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_bbbbbb) * -6.0 - t4_bbbbbbbb += einsum("ikac,jlbd->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ikad,jlbc->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 - t4_bbbbbbbb += einsum("ikab,jlcd->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 - t4_bbbbbbbb += einsum("ikbc,jlad->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 - t4_bbbbbbbb += einsum("ikbd,jlac->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ikcd,jlab->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 - t4_bbbbbbbb += einsum("ilac,jkbd->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 - t4_bbbbbbbb += einsum("ilad,jkbc->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ilab,jkcd->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ilbc,jkad->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ilbd,jkac->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 - t4_bbbbbbbb += einsum("ilcd,jkab->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ijac,klbd->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 - t4_bbbbbbbb += einsum("ijad,klbc->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ijab,klcd->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ijbc,klad->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ijbd,klac->ijklabcd", t2_bbbb, t2_bbbb) * 4.0 - t4_bbbbbbbb += einsum("ijcd,klab->ijklabcd", t2_bbbb, t2_bbbb) * -4.0 - t4_bbbbbbbb += einsum("ia,jb,klcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ia,jc,klbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ia,jd,klbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ib,ja,klcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ib,jc,klad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ib,jd,klac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ic,ja,klbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ic,jb,klad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ic,jd,klab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("id,ja,klbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("id,jb,klac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("id,jc,klab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ia,kb,jlcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ia,kc,jlbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ia,kd,jlbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ib,ka,jlcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ib,kc,jlad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ib,kd,jlac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ic,ka,jlbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ic,kb,jlad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ic,kd,jlab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("id,ka,jlbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("id,kb,jlac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("id,kc,jlab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ia,lb,jkcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ia,lc,jkbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ia,ld,jkbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ib,la,jkcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ib,lc,jkad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ib,ld,jkac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ic,la,jkbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ic,lb,jkad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ic,ld,jkab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("id,la,jkbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("id,lb,jkac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("id,lc,jkab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ja,kb,ilcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ja,kc,ilbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ja,kd,ilbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jb,ka,ilcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jb,kc,ilad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jb,kd,ilac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jc,ka,ilbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jc,kb,ilad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jc,kd,ilab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jd,ka,ilbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jd,kb,ilac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jd,kc,ilab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ja,lb,ikcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ja,lc,ikbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ja,ld,ikbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jb,la,ikcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jb,lc,ikad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jb,ld,ikac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jc,la,ikbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jc,lb,ikad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jc,ld,ikab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jd,la,ikbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("jd,lb,ikac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("jd,lc,ikab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ka,lb,ijcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("ka,lc,ijbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ka,ld,ijbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("kb,la,ijcd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("kb,lc,ijad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("kb,ld,ijac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("kc,la,ijbd->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("kc,lb,ijad->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("kc,ld,ijab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("kd,la,ijbc->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("kd,lb,ijac->ijklabcd", t1_bb, t1_bb, t2_bbbb) * -2.0 - t4_bbbbbbbb += einsum("kd,lc,ijab->ijklabcd", t1_bb, t1_bb, t2_bbbb) * 2.0 - t4_bbbbbbbb += einsum("ia,jb,kc,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ia,jb,kd,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("ia,jc,kb,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("ia,jc,kd,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ia,jd,kb,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ia,jd,kc,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("ib,ja,kc,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("ib,ja,kd,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ib,jc,ka,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ib,jc,kd,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("ib,jd,ka,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("ib,jd,kc,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ic,ja,kb,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ic,ja,kd,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("ic,jb,ka,ld->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("ic,jb,kd,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ic,jd,ka,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("ic,jd,kb,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("id,ja,kb,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("id,ja,kc,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("id,jb,ka,lc->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 - t4_bbbbbbbb += einsum("id,jb,kc,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("id,jc,ka,lb->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) - t4_bbbbbbbb += einsum("id,jc,kb,la->ijklabcd", t1_bb, t1_bb, t1_bb, t1_bb) * -1.0 + from ._conversion_routines import \ + t1_uhf_aa, t1_uhf_bb, \ + t2_uhf_aaaa, t2_uhf_abab, t2_uhf_bbbb, \ + t3_uhf_aaaaaa, t3_uhf_abaaba, t3_uhf_abbabb, t3_uhf_babbab, t3_uhf_bbabba, t3_uhf_bbbbbb, \ + t4_uhf_aaaaaaaa, t4_uhf_aaabaaab, t4_uhf_aabaaaba, t4_uhf_abaaabaa, t4_uhf_abababab, t4_uhf_abbbabbb, t4_uhf_bbabbbab, t4_uhf_bbbabbba, t4_uhf_bbbbbbbb + + from types import SimpleNamespace + c1 = SimpleNamespace(aa=c1_aa, bb=c1_bb) + c2 = SimpleNamespace(aaaa=c2_aaaa, abab=c2_abab, bbbb=c2_bbbb) + c3 = SimpleNamespace(aaaaaa=c3_aaaaaa, abaaba=c3_abaaba, abbabb=c3_abbabb, babbab=c3_babbab, bbabba=c3_bbabba, bbbbbb=c3_bbbbbb) + c4 = SimpleNamespace(aaaaaaaa=c4_aaaaaaaa, aaabaaab=c4_aaabaaab, aabaaaba=c4_aabaaaba, abaaabaa=c4_abaaabaa, abababab=c4_abababab, abbbabbb=c4_abbbabbb, bbabbbab=c4_bbabbbab, bbbabbba=c4_bbbabbba, bbbbbbbb=c4_bbbbbbbb) + + nocc = (c1.aa.shape[0], c1.bb.shape[0]) + nvir = (c1.aa.shape[1], c1.bb.shape[1]) + + t1_aa = t1_uhf_aa(c1=c1, nocc=nocc, nvir=nvir) + t1_bb = t1_uhf_bb(c1=c1, nocc=nocc, nvir=nvir) + t1 = SimpleNamespace(aa=t1_aa, bb=t1_bb) + + t2_aaaa = t2_uhf_aaaa(c2=c2, t1=t1, nocc=nocc, nvir=nvir) + t2_abab = t2_uhf_abab(c2=c2, t1=t1, nocc=nocc, nvir=nvir) + t2_bbbb = t2_uhf_bbbb(c2=c2, t1=t1, nocc=nocc, nvir=nvir) + t2 = SimpleNamespace(aaaa=t2_aaaa, abab=t2_abab, bbbb=t2_bbbb) + + t3_aaaaaa = t3_uhf_aaaaaa(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_abaaba = t3_uhf_abaaba(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_abbabb = t3_uhf_abbabb(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_babbab = t3_uhf_babbab(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_bbabba = t3_uhf_bbabba(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_bbbbbb = t3_uhf_bbbbbb(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3 = SimpleNamespace(aaaaaa=t3_aaaaaa, abaaba=t3_abaaba, abbabb=t3_abbabb, babbab=t3_babbab, bbabba=t3_bbabba, bbbbbb=t3_bbbbbb) + + t4_aaaaaaaa = t4_uhf_aaaaaaaa(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_aaabaaab = t4_uhf_aaabaaab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_aabaaaba = t4_uhf_aabaaaba(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_abaaabaa = t4_uhf_abaaabaa(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_abababab = t4_uhf_abababab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_abbbabbb = t4_uhf_abbbabbb(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_bbabbbab = t4_uhf_bbabbbab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_bbbabbba = t4_uhf_bbbabbba(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_bbbbbbbb = t4_uhf_bbbbbbbb(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) t1 = (t1_aa, t1_bb) t2 = (t2_aaaa, t2_abab, t2_bbbb) From 82622229acda7be53a21f1184ac0fd7cdc339ea3 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Thu, 2 Mar 2023 16:17:51 +0000 Subject: [PATCH 40/66] Fixes factors in ECCC contractions --- vayesta/core/types/wf/_conversion_routines.py | 79 ++++++- vayesta/solver/coupling.py | 211 +++++++++--------- 2 files changed, 182 insertions(+), 108 deletions(-) diff --git a/vayesta/core/types/wf/_conversion_routines.py b/vayesta/core/types/wf/_conversion_routines.py index ad525b079..30a342e3d 100644 --- a/vayesta/core/types/wf/_conversion_routines.py +++ b/vayesta/core/types/wf/_conversion_routines.py @@ -1207,7 +1207,7 @@ def t4_uhf_bbbbbbbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 5, 3, 1)) * -1.0 return t4_bbbbbbbb -def t4_rhf(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): +def t4_rhf_abab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) t4 += einsum(c4, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 @@ -1260,6 +1260,83 @@ def t4_rhf(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 return t4 +def t4_rhf_abaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) + t4 += einsum(c4, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 1, 6, 5, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 5, 6, 1, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 5, 6, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 6, 1, 5, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 7, 6)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 6, 5, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 6, 5, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) + t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 7, 6)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 2, 7)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 7, 3, 2, 6)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 7, 2)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 7, 3, 6, 2)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 2, 7, 6, 3)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 2, 7, 3, 6)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 6, 7, 2, 3)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 3, 7, 2, 6)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 6, 7, 3, 2)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 3, 7, 6, 2)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 2, 7, 6, 3)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 2, 7, 3, 6)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 6, 7, 2, 3)) * -1.0 + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 3, 7, 2, 6)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 6, 7, 3, 2)) + t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 3, 7, 6, 2)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 7, 6)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 7, 3, 1, 6)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 7, 3, 6, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 3, 6)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 6, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 1, 6)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 6, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 3, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 3, 6)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 1, 6)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 1, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 6, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 3, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 7, 6)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 7, 1, 3, 6)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 7, 1, 6, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 7, 6)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 7, 1, 3, 6)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 7, 1, 6, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 3, 6)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 6, 3)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 7, 1, 6)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 7, 6, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 3, 1, 5)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 7, 1)) * -1.0 + t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 3, 5, 1)) + return t4 + def t4_ghf(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) t4 += einsum(c4, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 2315f1d2f..446157642 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -465,121 +465,118 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc # TODO: Use spinalg.zeros_like(t1/t2) dt1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - dt1_aa += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_abaaba) - dt1_aa += einsum("jbkc,ikjacb->ia", v_aabb_ovov, t3_abaaba) - dt1_aa += einsum("jbkc,ijkabc->ia", v_aaaa_ovov, t3_aaaaaa) * 3.0 - dt1_aa += einsum("jbkc,ijkabc->ia", v_bbbb_ovov, t3_abbabb) + dt1_aa += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_abaaba) * 0.5 + dt1_aa += einsum("jbkc,ikjacb->ia", v_aabb_ovov, t3_abaaba) * 0.5 + dt1_aa += einsum("jbkc,ijkabc->ia", v_aaaa_ovov, t3_aaaaaa) * 0.5 + dt1_aa += einsum("jbkc,ijkabc->ia", v_bbbb_ovov, t3_abbabb) * 0.5 dt1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - dt1_bb += einsum("jbkc,jikbac->ia", v_aaaa_ovov, t3_abaaba) - dt1_bb += einsum("jbkc,ijkabc->ia", v_aabb_ovov, t3_babbab) - dt1_bb += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_bbabba) - dt1_bb += einsum("jbkc,ijkabc->ia", v_bbbb_ovov, t3_bbbbbb) * 3.0 + dt1_bb += einsum("jbkc,jikbac->ia", v_aaaa_ovov, t3_abaaba) * 0.5 + dt1_bb += einsum("jbkc,ijkabc->ia", v_aabb_ovov, t3_babbab) * 0.5 + dt1_bb += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_bbabba) * 0.5 + dt1_bb += einsum("jbkc,ijkabc->ia", v_bbbb_ovov, t3_bbbbbb) * 0.5 dt2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - dt2_aaaa += einsum("kc,ikjacb->ijab", f_bb_ov, t3_abaaba) * 2.0 - dt2_aaaa += einsum("kc,ijkabc->ijab", f_aa_ov, t3_aaaaaa) * 6.0 - dt2_aaaa += einsum("iklc,jlkacb->ijab", v_aabb_ooov, t3_abaaba) * 2.0 - dt2_aaaa += einsum("jklc,ilkacb->ijab", v_aabb_ooov, t3_abaaba) * -2.0 - dt2_aaaa += einsum("kcad,ikjbcd->ijab", v_bbaa_ovvv, t3_abaaba) * -2.0 - dt2_aaaa += einsum("kcbd,ikjacd->ijab", v_bbaa_ovvv, t3_abaaba) * 2.0 - dt2_aaaa += einsum("iklc,jklabc->ijab", v_aaaa_ooov, t3_aaaaaa) * 6.0 - dt2_aaaa += einsum("jklc,iklabc->ijab", v_aaaa_ooov, t3_aaaaaa) * -6.0 - dt2_aaaa += einsum("kcad,ijkbcd->ijab", v_aaaa_ovvv, t3_aaaaaa) * 6.0 - dt2_aaaa += einsum("kcbd,ijkacd->ijab", v_aaaa_ovvv, t3_aaaaaa) * -6.0 - dt2_aaaa += einsum("ic,kcld,jlkadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) - dt2_aaaa += einsum("ic,kdlc,jkladb->ijab", t1_aa, v_bbaa_ovov, t3_abaaba) - dt2_aaaa += einsum("jc,kcld,ilkadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * -1.0 - dt2_aaaa += einsum("jc,kdlc,ikladb->ijab", t1_aa, v_bbaa_ovov, t3_abaaba) * -1.0 - dt2_aaaa += einsum("ka,kcld,iljbdc->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * 2.0 - dt2_aaaa += einsum("kb,kcld,iljadc->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * -2.0 - dt2_aaaa += einsum("kc,kcld,iljadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * 2.0 - dt2_aaaa += einsum("ic,kcld,jklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 3.0 - dt2_aaaa += einsum("ic,kdlc,jklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -3.0 - dt2_aaaa += einsum("jc,kcld,iklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -3.0 - dt2_aaaa += einsum("jc,kdlc,iklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 3.0 - dt2_aaaa += einsum("ka,kcld,ijlbcd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 6.0 - dt2_aaaa += einsum("kb,kcld,ijlacd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -6.0 - dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 6.0 - dt2_aaaa += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -6.0 - dt2_aaaa += einsum("kc,kcld,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) * 2.0 - dt2_aaaa += einsum("kc,kdlc,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) * -2.0 - dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_aaaaaa) * 6.0 - - dt2_aaaa += einsum("kcld,ikjlacbd->ijab", v_bbbb_ovov, t4_abababab) * 2.0 - dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_aaaaaaaa) * 12.0 - dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_aaabaaab) * 3.0 - dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_bbaa_ovov, t4_aabaaaba) * 3.0 + dt2_aaaa += einsum("kc,ikjacb->ijab", f_bb_ov, t3_abaaba) + dt2_aaaa += einsum("kc,ijkabc->ijab", f_aa_ov, t3_aaaaaa) + dt2_aaaa += einsum("iklc,jlkacb->ijab", v_aabb_ooov, t3_abaaba) + dt2_aaaa += einsum("jklc,ilkacb->ijab", v_aabb_ooov, t3_abaaba) * -1.0 + dt2_aaaa += einsum("kcad,ikjbcd->ijab", v_bbaa_ovvv, t3_abaaba) * -1.0 + dt2_aaaa += einsum("kcbd,ikjacd->ijab", v_bbaa_ovvv, t3_abaaba) + dt2_aaaa += einsum("iklc,jklabc->ijab", v_aaaa_ooov, t3_aaaaaa) + dt2_aaaa += einsum("jklc,iklabc->ijab", v_aaaa_ooov, t3_aaaaaa) * -1.0 + dt2_aaaa += einsum("kcad,ijkbcd->ijab", v_aaaa_ovvv, t3_aaaaaa) + dt2_aaaa += einsum("kcbd,ijkacd->ijab", v_aaaa_ovvv, t3_aaaaaa) * -1.0 + dt2_aaaa += einsum("kcld,ikjlacbd->ijab", v_bbbb_ovov, t4_abababab) * 0.5 + dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_aaaaaaaa) * 0.5 + dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_aaabaaab) * 0.5 + dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_bbaa_ovov, t4_aabaaaba) * 0.5 + dt2_aaaa += einsum("ic,kcld,jlkadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * 0.5 + dt2_aaaa += einsum("ic,kdlc,jkladb->ijab", t1_aa, v_bbaa_ovov, t3_abaaba) * 0.5 + dt2_aaaa += einsum("jc,kcld,ilkadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * -0.5 + dt2_aaaa += einsum("jc,kdlc,ikladb->ijab", t1_aa, v_bbaa_ovov, t3_abaaba) * -0.5 + dt2_aaaa += einsum("ka,kcld,iljbdc->ijab", t1_aa, v_aabb_ovov, t3_abaaba) + dt2_aaaa += einsum("kb,kcld,iljadc->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * -1.0 + dt2_aaaa += einsum("kc,kcld,iljadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) + dt2_aaaa += einsum("ic,kcld,jklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 0.5 + dt2_aaaa += einsum("ic,kdlc,jklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -0.5 + dt2_aaaa += einsum("jc,kcld,iklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -0.5 + dt2_aaaa += einsum("jc,kdlc,iklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 0.5 + dt2_aaaa += einsum("ka,kcld,ijlbcd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) + dt2_aaaa += einsum("kb,kcld,ijlacd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -1.0 + dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) + dt2_aaaa += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -1.0 + dt2_aaaa += einsum("kc,kcld,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) + dt2_aaaa += einsum("kc,kdlc,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) * -1.0 + dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_aaaaaa) dt2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - dt2_bbbb += einsum("kc,ijkabc->ijab", f_aa_ov, t3_bbabba) * 2.0 - dt2_bbbb += einsum("kc,ijkabc->ijab", f_bb_ov, t3_bbbbbb) * 6.0 - dt2_bbbb += einsum("iklc,jklabc->ijab", v_bbaa_ooov, t3_bbabba) * 2.0 - dt2_bbbb += einsum("iklc,jklabc->ijab", v_bbbb_ooov, t3_bbbbbb) * 6.0 - dt2_bbbb += einsum("jklc,iklabc->ijab", v_bbaa_ooov, t3_bbabba) * -2.0 - dt2_bbbb += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) * -6.0 - dt2_bbbb += einsum("kcad,ijkbcd->ijab", v_bbbb_ovvv, t3_bbbbbb) * 6.0 - dt2_bbbb += einsum("kcad,ijkbdc->ijab", v_aabb_ovvv, t3_bbabba) * -2.0 - dt2_bbbb += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) * -6.0 - dt2_bbbb += einsum("kcbd,ijkadc->ijab", v_aabb_ovvv, t3_bbabba) * 2.0 - dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_bbabba) * 2.0 - dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aabb_ovov, t3_bbbbbb) * 6.0 - dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_bbabba) * -2.0 - dt2_bbbb += einsum("ic,kcld,jklabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) - dt2_bbbb += einsum("ic,kcld,jklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 3.0 - dt2_bbbb += einsum("ic,kdlc,jkladb->ijab", t1_bb, v_aabb_ovov, t3_babbab) - dt2_bbbb += einsum("ic,kdlc,jklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -3.0 - dt2_bbbb += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * -1.0 - dt2_bbbb += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -3.0 - dt2_bbbb += einsum("jc,kdlc,ikladb->ijab", t1_bb, v_aabb_ovov, t3_babbab) * -1.0 - dt2_bbbb += einsum("jc,kdlc,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 3.0 - dt2_bbbb += einsum("ka,kcld,ijlbcd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * 2.0 - dt2_bbbb += einsum("ka,kcld,ijlbcd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 6.0 - dt2_bbbb += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * -2.0 - dt2_bbbb += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -6.0 - dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * 2.0 - dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 6.0 - dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -6.0 - - dt2_bbbb += einsum("kcld,kiljcadb->ijab", v_aaaa_ovov, t4_abababab) * 2.0 - dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_bbabbbab) * 3.0 - dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbaa_ovov, t4_bbbabbba) * 3.0 - dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 12.0 + dt2_bbbb += einsum("kc,ijkabc->ijab", f_aa_ov, t3_bbabba) + dt2_bbbb += einsum("kc,ijkabc->ijab", f_bb_ov, t3_bbbbbb) + dt2_bbbb += einsum("iklc,jklabc->ijab", v_bbaa_ooov, t3_bbabba) + dt2_bbbb += einsum("iklc,jklabc->ijab", v_bbbb_ooov, t3_bbbbbb) + dt2_bbbb += einsum("jklc,iklabc->ijab", v_bbaa_ooov, t3_bbabba) * -1.0 + dt2_bbbb += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) * -1.0 + dt2_bbbb += einsum("kcad,ijkbcd->ijab", v_bbbb_ovvv, t3_bbbbbb) + dt2_bbbb += einsum("kcad,ijkbdc->ijab", v_aabb_ovvv, t3_bbabba) * -1.0 + dt2_bbbb += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) * -1.0 + dt2_bbbb += einsum("kcbd,ijkadc->ijab", v_aabb_ovvv, t3_bbabba) + dt2_bbbb += einsum("kcld,kiljcadb->ijab", v_aaaa_ovov, t4_abababab) * 0.5 + dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_bbabbbab) * 0.5 + dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbaa_ovov, t4_bbbabbba) * 0.5 + dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 0.5 + dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_bbabba) + dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aabb_ovov, t3_bbbbbb) + dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_bbabba) * -1.0 + dt2_bbbb += einsum("ic,kcld,jklabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * 0.5 + dt2_bbbb += einsum("ic,kcld,jklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 0.5 + dt2_bbbb += einsum("ic,kdlc,jklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -0.5 + dt2_bbbb += einsum("ic,kdlc,jkladb->ijab", t1_bb, v_aabb_ovov, t3_babbab) * 0.5 + dt2_bbbb += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * -0.5 + dt2_bbbb += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -0.5 + dt2_bbbb += einsum("jc,kdlc,ikladb->ijab", t1_bb, v_aabb_ovov, t3_babbab) * -0.5 + dt2_bbbb += einsum("jc,kdlc,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 0.5 + dt2_bbbb += einsum("ka,kcld,ijlbcd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) + dt2_bbbb += einsum("ka,kcld,ijlbcd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) + dt2_bbbb += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * -1.0 + dt2_bbbb += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -1.0 + dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) + dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) + dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -1.0 dt2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) - dt2_abab += einsum("kc,ijkabc->ijab", f_aa_ov, t3_abaaba) * 2.0 - dt2_abab += einsum("kc,ijkabc->ijab", f_bb_ov, t3_abbabb) * 2.0 - dt2_abab += einsum("iklc,kjlabc->ijab", v_aaaa_ooov, t3_abaaba) * -2.0 - dt2_abab += einsum("jklc,iklabc->ijab", v_bbaa_ooov, t3_abaaba) * -2.0 - dt2_abab += einsum("kcad,ijkcbd->ijab", v_aaaa_ovvv, t3_abaaba) * -2.0 - dt2_abab += einsum("kcbd,ijkadc->ijab", v_aabb_ovvv, t3_abaaba) * 2.0 - dt2_abab += einsum("iklc,jklbac->ijab", v_aabb_ooov, t3_babbab) * -2.0 - dt2_abab += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_abbabb) * -2.0 - dt2_abab += einsum("kcad,ijkdbc->ijab", v_bbaa_ovvv, t3_abbabb) * 2.0 - dt2_abab += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_abbabb) * -2.0 - dt2_abab += einsum("ic,kcld,kjlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -1.0 - dt2_abab += einsum("ic,kdlc,kjlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) - dt2_abab += einsum("ka,kcld,ijlcbd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -2.0 - dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * 2.0 - dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -2.0 - dt2_abab += einsum("ic,kcld,jklbad->ijab", t1_aa, v_aabb_ovov, t3_babbab) * -1.0 - dt2_abab += einsum("ic,kdlc,jklbda->ijab", t1_aa, v_bbaa_ovov, t3_bbabba) * -1.0 - dt2_abab += einsum("ka,kcld,ijlcbd->ijab", t1_aa, v_aabb_ovov, t3_abbabb) * -2.0 - dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aabb_ovov, t3_abbabb) * 2.0 - dt2_abab += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * -1.0 - dt2_abab += einsum("jc,kdlc,ilkabd->ijab", t1_bb, v_aabb_ovov, t3_abaaba) * -1.0 - dt2_abab += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * -2.0 - dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * 2.0 - dt2_abab += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -1.0 - dt2_abab += einsum("jc,kdlc,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) - dt2_abab += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -2.0 - dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * 2.0 - dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -2.0 - - dt2_abab += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_abababab) * 2.0 - dt2_abab += einsum("kcld,ijlkabdc->ijab", v_bbaa_ovov, t4_abababab) * 2.0 - dt2_abab += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_abaaabaa) * 3.0 - dt2_abab += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_abbbabbb) * 3.0 + dt2_abab += einsum("kc,ijkabc->ijab", f_aa_ov, t3_abaaba) + dt2_abab += einsum("kc,ijkabc->ijab", f_bb_ov, t3_abbabb) + dt2_abab += einsum("iklc,kjlabc->ijab", v_aaaa_ooov, t3_abaaba) * -1.0 + dt2_abab += einsum("jklc,iklabc->ijab", v_bbaa_ooov, t3_abaaba) * -1.0 + dt2_abab += einsum("kcad,ijkcbd->ijab", v_aaaa_ovvv, t3_abaaba) * -1.0 + dt2_abab += einsum("kcbd,ijkadc->ijab", v_aabb_ovvv, t3_abaaba) + dt2_abab += einsum("iklc,jklbac->ijab", v_aabb_ooov, t3_babbab) * -1.0 + dt2_abab += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_abbabb) * -1.0 + dt2_abab += einsum("kcad,ijkdbc->ijab", v_bbaa_ovvv, t3_abbabb) + dt2_abab += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_abbabb) * -1.0 + dt2_abab += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_abababab) * 0.5 + dt2_abab += einsum("kcld,ijlkabdc->ijab", v_bbaa_ovov, t4_abababab) * 0.5 + dt2_abab += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_abaaabaa) * 0.5 + dt2_abab += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_abbbabbb) * 0.5 + dt2_abab += einsum("ic,kcld,kjlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -0.5 + dt2_abab += einsum("ic,kdlc,kjlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * 0.5 + dt2_abab += einsum("ka,kcld,ijlcbd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -1.0 + dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) + dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -1.0 + dt2_abab += einsum("ic,kcld,jklbad->ijab", t1_aa, v_aabb_ovov, t3_babbab) * -0.5 + dt2_abab += einsum("ic,kdlc,jklbda->ijab", t1_aa, v_bbaa_ovov, t3_bbabba) * -0.5 + dt2_abab += einsum("ka,kcld,ijlcbd->ijab", t1_aa, v_aabb_ovov, t3_abbabb) * -1.0 + dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aabb_ovov, t3_abbabb) + dt2_abab += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * -0.5 + dt2_abab += einsum("jc,kdlc,ilkabd->ijab", t1_bb, v_aabb_ovov, t3_abaaba) * -0.5 + dt2_abab += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * -1.0 + dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) + dt2_abab += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -0.5 + dt2_abab += einsum("jc,kdlc,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * 0.5 + dt2_abab += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -1.0 + dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) + dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -1.0 if not include_t3v: # TODO From 701dbe3c885d403e77087b4cb02204f22b478adb Mon Sep 17 00:00:00 2001 From: George Booth Date: Thu, 2 Mar 2023 17:30:17 +0000 Subject: [PATCH 41/66] Bugfix for C_abaa amplitudes to get EC-CC (RHF) working. --- vayesta/core/types/wf/cisdtq.py | 2 +- vayesta/core/types/wf/fci.py | 4 ++-- vayesta/solver/coupling.py | 1 + 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 42e4fccb4..caddde8f4 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -69,7 +69,7 @@ def as_ccsdtq(self): t4_abaa -= t1t3a.transpose(3,1,2,0,4,5,7,6) t4_abaa += t1t3b.transpose(0,1,3,2,4,5,7,6) t4_abaa -= t1t3b.transpose(0,1,3,2,4,5,6,7) - + # (t2 t2) terms + permutations t2t2a = einsum('ijab, klcd -> ijklabcd', t2, t2aa) t2t2b = einsum('ljcb, kida -> ijklabcd', t2, t2aa) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index f4e9b7e22..531120a33 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -231,8 +231,8 @@ def as_cisdtq(self, c0=None): t3sign[t_cnt_a] * t1sign[s_cnt_b] # Beta singles values - I = int(s_cnt / nvir) - A = s_cnt % nvir + I = int(s_cnt_b / nvir) + A = s_cnt_b % nvir # Swap aaab -> abaa spin signature. No sign change required. c4_abaa[i, I, j, k, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 446157642..3d87a78ce 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -385,6 +385,7 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc tmp1 += t4aabb.transpose(0,2,1,3,4,6,5,7) tmp1 += t4aabb.transpose(1,2,0,3,5,6,4,7) t4v_test = 0.5 * einsum('kcld,klijcdab->ijab', govov, tmp1) + assert(np.allclose(t4v, t4v_test)) # --- (T1 T3) * V # Note: Approximate T1 by the CCSDTQ T1 amplitudes of this fragment. From 4645f131a0a05bfdd62fb4b9c5e266cfb52ba2e7 Mon Sep 17 00:00:00 2001 From: Abhishek Khedkar Date: Mon, 13 Mar 2023 11:00:42 +0000 Subject: [PATCH 42/66] added tests for unrestricted ec-cc --- vayesta/tests/ewf/test_extcorr.py | 71 ++++++++++++++++++++++++++++++- 1 file changed, 70 insertions(+), 1 deletion(-) diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index e8849f702..bfe59719d 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -4,6 +4,7 @@ import pyscf import pyscf.cc +from pyscf.scf import convert_to_uhf import vayesta import vayesta.ewf @@ -17,8 +18,24 @@ class TestFullEC(TestCase): def _test(self, key, proj=0, mode='external-fciv', store_wf_ccsdtq=True): mf = getattr(getattr(testsystems, key[0]), key[1])() - + + if len(key) == 3: + if key[2] == 'rhf_to_uhf': + mf = pyscf.scf.convert_to_uhf(mf) + emb = vayesta.ewf.EWF(mf) + + if len(key) == 3: + if key[1] == 'rhf': + if key[2] == 'rhf_to_uhf': + self.assertEqual(emb.is_uhf, True) + else: + self.assertEqual(emb.is_rhf, True) + if key[1] == 'rhf' and len(key) == 2: + self.assertEqual(emb.is_rhf, True) + if key[1] == 'uhf': + self.assertEqual(emb.is_uhf, True) + with emb.iao_fragmentation() as f: if store_wf_ccsdtq: fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full'), store_wf_type='CCSDTQ') @@ -60,6 +77,58 @@ def _test(self, key, proj=0, mode='external-fciv', store_wf_ccsdtq=True): self.assertAlmostEqual(emb.e_tot, fci_frag_etot) # Test all combinations of options + + def test_r_to_u_exact_ec_lih_proj0_fciv_store(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=True) + def test_r_to_u_exact_ec_lih_proj1_fciv_store(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=True) + def test_r_to_u_exact_ec_lih_proj2_fciv_store(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=True) + def test_r_to_u_exact_ec_lih_proj0_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=False) + def test_r_to_u_exact_ec_lih_proj1_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=False) + def test_r_to_u_exact_ec_lih_proj2_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=False) + def test_r_to_u_exact_ec_lih_proj0_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_r_to_u_exact_ec_lih_proj1_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_r_to_u_exact_ec_lih_proj2_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_r_to_u_exact_ec_lih_proj0_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=False) + def test_r_to_u_exact_ec_lih_proj1_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=False) + def test_r_to_u_exact_ec_lih_proj2_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=False) + + + def test_u_exact_ec_lih_proj0_fciv_store(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=True) + def test_u_exact_ec_lih_proj1_fciv_store(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=True) + def test_u_exact_ec_lih_proj2_fciv_store(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=True) + def test_u_exact_ec_lih_proj0_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=False) + def test_u_exact_ec_lih_proj1_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=False) + def test_u_exact_ec_lih_proj2_fciv_nostore(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=False) + def test_u_exact_ec_lih_proj0_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_u_exact_ec_lih_proj1_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_u_exact_ec_lih_proj2_ccsdv_store(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=True) + def test_u_exact_ec_lih_proj0_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=False) + def test_u_exact_ec_lih_proj1_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=False) + def test_u_exact_ec_lih_proj2_ccsdv_nostore(self): + return self._test(('lih_ccpvdz', 'uhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=False) + def test_r_exact_ec_lih_proj0_fciv_store(self): return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=True) def test_r_exact_ec_lih_proj1_fciv_store(self): From c24dea2a02be9c70fd1bbe38f7028dbfe4d54d5a Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Tue, 14 Mar 2023 10:44:10 +0000 Subject: [PATCH 43/66] Resolve minor comments --- vayesta/core/qemb/qemb.py | 4 ++-- vayesta/core/scmf/scmf.py | 2 +- vayesta/core/util.py | 3 +++ 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/vayesta/core/qemb/qemb.py b/vayesta/core/qemb/qemb.py index 2626e05c9..472402af7 100644 --- a/vayesta/core/qemb/qemb.py +++ b/vayesta/core/qemb/qemb.py @@ -1542,7 +1542,7 @@ def reset(self, *args, **kwargs): def update_mf(self, mo_coeff, mo_energy=None, veff=None): """Update underlying mean-field object.""" # Chech orthonormal MOs - if not np.allclose(dot(mo_coeff.T, self.get_ovlp(), mo_coeff) - np.eye(mo_coeff.shape[-1]), 0.): + if not np.allclose(dot(mo_coeff.T, self.get_ovlp(), mo_coeff) - np.eye(mo_coeff.shape[-1]), 0): raise ValueError("MO coefficients not orthonormal!") self.mf.mo_coeff = mo_coeff dm = self.mf.make_rdm1(mo_coeff=mo_coeff) @@ -1563,7 +1563,7 @@ def check_fragment_symmetry(self, dm1, symtol=1e-6): for child in children: charge_err, spin_err = parent.get_symmetry_error(child, dm1=dm1) if (max(charge_err, spin_err) > symtol): - raise RuntimeError("%s and %s not symmetric! Errors: charge= %.2e spin= %.2e" + raise SymmetryError("%s and %s not symmetric! Errors: charge= %.2e spin= %.2e" % (parent.name, child.name, charge_err, spin_err)) self.log.debugv("Symmetry between %s and %s: Errors: charge= %.2e spin= %.2e", parent.name, child.name, charge_err, spin_err) diff --git a/vayesta/core/scmf/scmf.py b/vayesta/core/scmf/scmf.py index 1ba6258fc..1cfc94c45 100644 --- a/vayesta/core/scmf/scmf.py +++ b/vayesta/core/scmf/scmf.py @@ -102,7 +102,7 @@ def kernel(self, *args, **kwargs): # Check symmetry try: self.emb.check_fragment_symmetry(dm1) - except: + except SymmetryError: self.log.error("Symmetry check failed in %s", self.name) self.converged = False break diff --git a/vayesta/core/util.py b/vayesta/core/util.py index dab9600c9..c37938dbc 100644 --- a/vayesta/core/util.py +++ b/vayesta/core/util.py @@ -305,6 +305,9 @@ class NotCalculatedError(AttributeError): """Raise if a necessary attribute has not been calculated.""" pass +class SymmetryError(RuntimeError): + pass + # --- Energy def energy_string(energy, unit='Ha'): From cc198d3d751f00fb9ff6b129cbeffe66a3f84fd3 Mon Sep 17 00:00:00 2001 From: Abhishek Khedkar Date: Thu, 16 Mar 2023 15:46:42 +0000 Subject: [PATCH 44/66] Updated ec-cc unit tests with UHF, regression --- vayesta/tests/ewf/test_extcorr.py | 474 +++++++++++++++++++++--------- 1 file changed, 341 insertions(+), 133 deletions(-) diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index bfe59719d..3c8eb3576 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -13,146 +13,343 @@ from vayesta.tests import testsystems -@pytest.mark.fast -class TestFullEC(TestCase): +#@pytest.mark.fast +class TestFullEC_tailor(TestCase): + @classmethod + def setUpClass(cls): + cls.fci = {} + cls.mf = {} + cls.mf['lih_631g'] = testsystems.lih_631g.rhf() + cls.fci['lih_631g'] = pyscf.fci.FCI( cls.mf['lih_631g']) + cls.fci['lih_631g'].threads = 1 + cls.fci['lih_631g'].conv_tol = 1.0e-12 + cls.fci['lih_631g'].davidson_only = True + cls.fci['lih_631g'].kernel() - def _test(self, key, proj=0, mode='external-fciv', store_wf_ccsdtq=True): - mf = getattr(getattr(testsystems, key[0]), key[1])() - - if len(key) == 3: - if key[2] == 'rhf_to_uhf': - mf = pyscf.scf.convert_to_uhf(mf) - - emb = vayesta.ewf.EWF(mf) - if len(key) == 3: - if key[1] == 'rhf': - if key[2] == 'rhf_to_uhf': - self.assertEqual(emb.is_uhf, True) - else: - self.assertEqual(emb.is_rhf, True) - if key[1] == 'rhf' and len(key) == 2: - self.assertEqual(emb.is_rhf, True) - if key[1] == 'uhf': - self.assertEqual(emb.is_uhf, True) + cls.mf['lih_ccpvdz'] = testsystems.lih_ccpvdz.rhf() + cls.fci['lih_ccpvdz'] = pyscf.fci.FCI( cls.mf['lih_ccpvdz']) + cls.fci['lih_ccpvdz'].threads = 1 + cls.fci['lih_ccpvdz'].conv_tol = 1.0e-12 + cls.fci['lih_ccpvdz'].davidson_only = True + cls.fci['lih_ccpvdz'].kernel() - with emb.iao_fragmentation() as f: - if store_wf_ccsdtq: - fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full'), store_wf_type='CCSDTQ') - else: - fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full')) - ccsd = f.add_atomic_fragment([0], solver='CCSD', bath_options=dict(bathtype='full'), active=False) - ccsd2 = f.add_atomic_fragment([1], solver='CCSD', bath_options=dict(bathtype='full'), active=False) - emb.kernel() - fci_frag_ecorr = emb.e_corr - fci_frag_etot = emb.e_tot + def TearDownClass(cls): + cls.fci.clear() + cls.mf.clear() + del cls.fci + del cls.mf - fci_frag.active = False - ccsd.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) - ccsd.active = True - ccsd2.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) - ccsd2.active = True - emb.kernel() - fci = pyscf.fci.FCI(mf) - fci.threads = 1 - fci.conv_tol = 1e-12 - fci.davidson_only = True - fci.kernel() + def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True): - self.assertAlmostEqual(fci_frag_ecorr, fci.e_tot - mf.e_tot) - self.assertAlmostEqual(fci_frag_etot, fci.e_tot) - self.assertAlmostEqual(emb.e_corr, fci_frag_ecorr) - self.assertAlmostEqual(emb.e_tot, fci_frag_etot) + mf = getattr(getattr(testsystems, key[0]), key[1])() + if fcifragtype == 'fullsystem': + emb = vayesta.ewf.EWF(mf, solver_options={'conv_tol':1.0e-12} ) + fci_frags = [] + with emb.iao_fragmentation() as f: + if store_wf_ccsdtq: + fci_frags.append(f.add_full_system(solver='FCI', bath_options=dict(bathtype=bathtype), store_wf_type='CCSDTQ', auxiliary=True)) + else: + fci_frags.append(f.add_full_system(solver='FCI', bath_options=dict(bathtype=bathtype), auxiliary=True)) + ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full')) + ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=proj,test_extcorr=True) + emb.kernel() - # Rather than setting fragments to active and inactive, we should also be able to run the external correction - # in a single kernel call, setting the FCI fragments with auxiliary flags - fci_frag.opts.active = True - fci_frag.opts.auxiliary = True - ccsd.clear_external_corrections() - ccsd.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) - ccsd2.clear_external_corrections() - ccsd2.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) - emb.kernel() - self.assertAlmostEqual(emb.e_tot, fci_frag_etot) - # Test all combinations of options - - def test_r_to_u_exact_ec_lih_proj0_fciv_store(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=True) - def test_r_to_u_exact_ec_lih_proj1_fciv_store(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=True) - def test_r_to_u_exact_ec_lih_proj2_fciv_store(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=True) - def test_r_to_u_exact_ec_lih_proj0_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=False) - def test_r_to_u_exact_ec_lih_proj1_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=False) - def test_r_to_u_exact_ec_lih_proj2_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=False) - def test_r_to_u_exact_ec_lih_proj0_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_r_to_u_exact_ec_lih_proj1_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_r_to_u_exact_ec_lih_proj2_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_r_to_u_exact_ec_lih_proj0_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=False) - def test_r_to_u_exact_ec_lih_proj1_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=False) - def test_r_to_u_exact_ec_lih_proj2_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf', 'rhf_to_uhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=False) - - - def test_u_exact_ec_lih_proj0_fciv_store(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=True) - def test_u_exact_ec_lih_proj1_fciv_store(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=True) - def test_u_exact_ec_lih_proj2_fciv_store(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=True) - def test_u_exact_ec_lih_proj0_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=False) - def test_u_exact_ec_lih_proj1_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=False) - def test_u_exact_ec_lih_proj2_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=False) - def test_u_exact_ec_lih_proj0_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_u_exact_ec_lih_proj1_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_u_exact_ec_lih_proj2_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_u_exact_ec_lih_proj0_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=False) - def test_u_exact_ec_lih_proj1_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=False) - def test_u_exact_ec_lih_proj2_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'uhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=False) - - def test_r_exact_ec_lih_proj0_fciv_store(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=True) - def test_r_exact_ec_lih_proj1_fciv_store(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=True) - def test_r_exact_ec_lih_proj2_fciv_store(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=True) - def test_r_exact_ec_lih_proj0_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-fciv', store_wf_ccsdtq=False) - def test_r_exact_ec_lih_proj1_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=1, mode='external-fciv', store_wf_ccsdtq=False) - def test_r_exact_ec_lih_proj2_fciv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-fciv', store_wf_ccsdtq=False) - def test_r_exact_ec_lih_proj0_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_r_exact_ec_lih_proj1_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_r_exact_ec_lih_proj2_ccsdv_store(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=True) - def test_r_exact_ec_lih_proj0_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=0, mode='external-ccsdv', store_wf_ccsdtq=False) - def test_r_exact_ec_lih_proj1_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=1, mode='external-ccsdv', store_wf_ccsdtq=False) - def test_r_exact_ec_lih_proj2_ccsdv_nostore(self): - return self._test(('lih_ccpvdz', 'rhf'), proj=2, mode='external-ccsdv', store_wf_ccsdtq=False) + if fcifragtype == 'atomic': + + emb = vayesta.ewf.EWF(mf, solver_options={'conv_tol':1.0e-12}) + with emb.iao_fragmentation() as f: + if store_wf_ccsdtq: + fci_frag = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype=bathtype), store_wf_type='CCSDTQ', auxiliary=True) + else: + fci_frag = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype=bathtype), auxiliary=True) + ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full')) + ccsd_frag.add_external_corrections(fci_frag, correction_type=mode, projectors=proj, test_extcorr=True) + + emb.kernel() + + return emb.e_tot, cls.fci[key[0]].e_tot + + +# FCI fragment bath type=full + + @pytest.mark.fast + def test_r_regression_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988952842115175) + + @pytest.mark.fast + def test_r_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.fast + def test_r_regression_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.98893732925952) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_atomicfrags_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988952842133734) + + @pytest.mark.slow + def test_r_exact_ec_lih_631g_atomicfrags_proj1_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_atomicfrags_proj2_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.98893732924287) + + + @pytest.mark.slow + def test_r_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_r_exact_ec_lih_631g_fullsystem_proj1_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_r_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_r_exact_ec_lih_631g_fullsystem_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_r_exact_ec_lih_631g_fullsystem_proj1_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_r_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + +# uhf tests + + + #@pytest.mark.slow + #def test_u_exact_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + #@pytest.mark.slow + #def test_u_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + #@pytest.mark.slow + #def test_u_exact_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_u_regression_ec_lih_631g_atomicfrags_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988952849629403) + +# A test with nostore + @pytest.mark.slow + def test_u_regression_ec_lih_631g_atomicfrags_proj0_fciv_nostore(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=False) + self.assertAlmostEqual(e_tot, -7.988952849629403) + + @pytest.mark.slow + def test_u_exact_ec_lih_631g_atomicfrags_proj1_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_u_regression_ec_lih_631g_atomicfrags_proj2_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988937336775954) + + + #@pytest.mark.fast + #def test_u_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + #@pytest.mark.slow + #def test_u_exact_ec_lih_631g_fullsystem_proj1_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + #@pytest.mark.fast + #def test_u_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_u_exact_ec_lih_631g_fullsystem_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + +# test tailoring + @pytest.mark.fast + def test_u_exact_tailor_lih_631g_fullsystem_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='tailor', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.fast + def test_u_exact_tailor_lih_631g_fullsystem_proj0_fciv_nostore(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='tailor', store_wf_ccsdtq=False) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.fast + def test_u_exact_ec_lih_631g_fullsystem_proj1_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_u_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) + + # FCI fragment bathtype = dmet + + @pytest.mark.fast + def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393747139) + + @pytest.mark.fast + def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393747468) + + @pytest.mark.fast + def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393747468) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.9889313937490956) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393746693) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.98893139374700) + + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393745471) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393747714) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.98893139374664) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393748568) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393746042) + + @pytest.mark.slow + def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393748121) + + # uhf tests + + + #@pytest.mark.slow + #def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + #@pytest.mark.slow + #def test_u_exact_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + #@pytest.mark.slow + #def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393739508) + + # test with nostore + @pytest.mark.slow + def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_nostore(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=False) + self.assertAlmostEqual(e_tot, -7.988931393739513) + + @pytest.mark.slow + def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.9889313937395015 ) + + @pytest.mark.slow + def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393739511) + + + #@pytest.mark.fast + #def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + #@pytest.mark.slow + #def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + #@pytest.mark.fast + #def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): + # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + # self.assertAlmostEqual(e_tot, fci_e_tot) + + @pytest.mark.slow + def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393739515 ) + + @pytest.mark.fast + def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.9889313937395015 ) + + @pytest.mark.slow + def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, -7.988931393739506 ) + @pytest.mark.fast class TestHubCompleteEC(TestCase): @@ -165,6 +362,8 @@ def _test_10_u4_2imp(self, mode, proj): mf = testsystems.hubb_10_u4.rhf() emb = vayesta.ewf.EWF(mf) + emb.opts.solver_options['conv_tol'] = 1.0e-12 + with emb.site_fragmentation() as f: fci_frag = f.add_atomic_fragment(list(range(10)), solver='FCI', store_wf_type='CCSDTQ') ccsd_frag = f.add_atomic_fragment([0, 1], solver='CCSD', bath_options=dict(bathtype='full'), active=False) @@ -214,6 +413,8 @@ def _test_10_u2_2impfci(self, mode): mf = testsystems.hubb_10_u2.rhf() emb = vayesta.ewf.EWF(mf) + emb.opts.solver_options['conv_tol'] = 1.0e-12 + with emb.site_fragmentation() as f: fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full'), store_wf_type='CCSDTQ') ccsd_frag = f.add_atomic_fragment([0, 1], solver='CCSD', bath_options=dict(bathtype='full'), active=False) @@ -250,6 +451,8 @@ def _test_10_u2_eccc_sym(self, mode, proj=0): mf = testsystems.hubb_10_u2.rhf() emb = vayesta.ewf.EWF(mf) + emb.opts.solver_options['conv_tol'] = 1.0e-12 + fci_frags = [] with emb.site_fragmentation() as f: # Set up a two-site FCI fragment on all symmetrically equivalent fragments @@ -272,6 +475,8 @@ def _test_10_u2_eccc_sym(self, mode, proj=0): # use symmetry of FCI clusters. emb = vayesta.ewf.EWF(mf) + emb.opts.solver_options['conv_tol'] = 1.0e-12 + fci_frags = [] with emb.site_fragmentation() as f: fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ')) @@ -315,6 +520,8 @@ def _test_water_ec_regression(self, mode=None, projectors=None): mf = testsystems.water_ccpvdz_df.rhf() emb = vayesta.ewf.EWF(mf) + emb.opts.solver_options['conv_tol'] = 1.0e-12 + fci_frags = [] with emb.iao_fragmentation() as f: fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ') @@ -349,7 +556,8 @@ def test_water_ec_regression_proj2_fciv(self): def test_water_ec_regression_proj2_ccsdv(self): e_tot = self._test_water_ec_regression(mode='external-ccsdv', projectors=2) self.assertAlmostEqual(e_tot, -76.24017093290053) - + + if __name__ == '__main__': print('Running %s' % __file__) unittest.main() From a3d53b958e52cdf98a780743b4f530a514ad5ee6 Mon Sep 17 00:00:00 2001 From: Abhishek Khedkar Date: Thu, 16 Mar 2023 15:48:22 +0000 Subject: [PATCH 45/66] added a testsytem variation lih_631g --- vayesta/tests/testsystems.py | 1 + 1 file changed, 1 insertion(+) diff --git a/vayesta/tests/testsystems.py b/vayesta/tests/testsystems.py index 8ac7d359b..55dcf00f5 100644 --- a/vayesta/tests/testsystems.py +++ b/vayesta/tests/testsystems.py @@ -340,6 +340,7 @@ def uhf(self): ethanol_ccpvdz = TestMolecule(atom=molecules.ethanol(), basis="cc-pvdz") lih_ccpvdz = TestMolecule(atom="Li 0 0 0; H 0 0 1.4", basis="cc-pvdz") +lih_631g = TestMolecule(atom="Li 0 0 0; H 0 0 1.4", basis="6-31g") h2_ccpvdz = TestMolecule(atom="H1 0 0 0; H2 0 0 1.0", basis="cc-pvdz") h2_ccpvdz_df = TestMolecule(atom="H1 0 0 0; H2 0 0 1.0", basis="cc-pvdz", auxbasis="cc-pvdz-jkfit") From 8def64f9fa5cdc02825faa32dc98a9b3a97b3d5a Mon Sep 17 00:00:00 2001 From: George Booth Date: Thu, 16 Mar 2023 16:07:45 +0000 Subject: [PATCH 46/66] Fix to example 25-externally-correct. Previously, there was an error in how the external correction was being done for multiple CCSD fragments. --- examples/ewf/molecules/25-externally-correct.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/examples/ewf/molecules/25-externally-correct.py b/examples/ewf/molecules/25-externally-correct.py index a1147685d..a27115e60 100644 --- a/examples/ewf/molecules/25-externally-correct.py +++ b/examples/ewf/molecules/25-externally-correct.py @@ -56,6 +56,7 @@ fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', auxiliary=True) ccsd_frags = f.add_all_atomic_fragments(solver='CCSD', bath_options=dict(bathtype='mp2', threshold=1.e-5)) # Now add external corrections to all CCSD clusters, and use 'external-fciv' correction, with 2 projectors -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=2) +for cc_frag in ccsd_frags: + cc_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=2) emb.kernel() print('Total energy from embedded CCSD tailored (FCI Coulomb interaction) by atomic FCI fragments (projectors=2): {}'.format(emb.e_tot)) From b5fb8a5d5461daa91d5081f18c6650662ddb891b Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 17 Mar 2023 09:54:11 +0000 Subject: [PATCH 47/66] Changes filename of conversion routines --- vayesta/core/types/wf/_conversion_routines.py | 1474 ----------------- vayesta/core/types/wf/cisdtq.py | 47 +- vayesta/core/types/wf/t_to_c.py | 993 +++++++++++ 3 files changed, 1014 insertions(+), 1500 deletions(-) delete mode 100644 vayesta/core/types/wf/_conversion_routines.py create mode 100644 vayesta/core/types/wf/t_to_c.py diff --git a/vayesta/core/types/wf/_conversion_routines.py b/vayesta/core/types/wf/_conversion_routines.py deleted file mode 100644 index 30a342e3d..000000000 --- a/vayesta/core/types/wf/_conversion_routines.py +++ /dev/null @@ -1,1474 +0,0 @@ -import numpy as np -from ebcc.util import pack_2e, einsum, Namespace - -def t1_uhf_aa(c1=None, nocc=None, nvir=None): - t1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - t1_aa += einsum(c1.aa, (0, 1), (0, 1)) - return t1_aa - -def t1_uhf_bb(c1=None, nocc=None, nvir=None): - t1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - t1_bb += einsum(c1.bb, (0, 1), (0, 1)) - return t1_bb - -def t1_rhf(c1=None, nocc=None, nvir=None): - t1 = np.zeros((nocc, nvir), dtype=np.float64) - t1 += einsum(c1, (0, 1), (0, 1)) - return t1 - -def t1_ghf(c1=None, nocc=None, nvir=None): - t1 = np.zeros((nocc, nvir), dtype=np.float64) - t1 += einsum(c1, (0, 1), (0, 1)) - return t1 - -def t2_uhf_aaaa(c2=None, t1=None, nocc=None, nvir=None): - t2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - t2_aaaa += einsum(c2.aaaa, (0, 1, 2, 3), (0, 1, 2, 3)) - t2_aaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), (0, 2, 1, 3)) * -1.0 - t2_aaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), (0, 2, 3, 1)) - return t2_aaaa - -def t2_uhf_abab(c2=None, t1=None, nocc=None, nvir=None): - t2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) - t2_abab += einsum(c2.abab, (0, 1, 2, 3), (0, 1, 2, 3)) - t2_abab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), (0, 2, 1, 3)) * -1.0 - return t2_abab - -def t2_uhf_baba(c2=None, t1=None, nocc=None, nvir=None): - t2_baba = np.zeros((nocc[1], nocc[0], nvir[1], nvir[0]), dtype=np.float64) - t2_baba += einsum(c2.abab, (0, 1, 2, 3), (1, 0, 3, 2)) - t2_baba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), (2, 0, 3, 1)) * -1.0 - return t2_baba - -def t2_uhf_bbbb(c2=None, t1=None, nocc=None, nvir=None): - t2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - t2_bbbb += einsum(c2.bbbb, (0, 1, 2, 3), (0, 1, 2, 3)) - t2_bbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), (0, 2, 1, 3)) * -1.0 - t2_bbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), (0, 2, 3, 1)) - return t2_bbbb - -def t2_rhf(c2=None, t1=None, nocc=None, nvir=None): - t2 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) - t2 += einsum(c2, (0, 1, 2, 3), (0, 1, 2, 3)) - t2 += einsum(t1, (0, 1), t1, (2, 3), (0, 2, 1, 3)) * -1.0 - return t2 - -def t2_ghf(c2=None, t1=None, nocc=None, nvir=None): - t2 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) - t2 += einsum(c2, (0, 1, 2, 3), (0, 1, 2, 3)) - t2 += einsum(t1, (0, 1), t1, (2, 3), (0, 2, 1, 3)) * -1.0 - t2 += einsum(t1, (0, 1), t1, (2, 3), (0, 2, 3, 1)) - return t2 - -def t3_uhf_aaaaaa(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_aaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - t3_aaaaaa += einsum(c3.aaaaaa, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (0, 2, 3, 4, 1, 5)) - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (0, 2, 3, 4, 5, 1)) * -1.0 - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 0, 3, 1, 4, 5)) - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 0, 3, 4, 5, 1)) - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 3, 0, 1, 4, 5)) * -1.0 - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 3, 0, 4, 1, 5)) - t3_aaaaaa += einsum(t1.aa, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 - t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 - t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 1, 5, 3)) - t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 3, 1, 5)) - t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 5, 1, 3)) * -1.0 - t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 3, 5, 1)) * -1.0 - t3_aaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), (0, 2, 4, 5, 3, 1)) - return t3_aaaaaa - -def t3_uhf_aabaab(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_aabaab = np.zeros((nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[1]), dtype=np.float64) - t3_aabaab += einsum(c3.abaaba, (0, 1, 2, 3, 4, 5), (0, 2, 1, 3, 5, 4)) - t3_aabaab += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 - t3_aabaab += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (0, 2, 3, 4, 1, 5)) - t3_aabaab += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (2, 0, 3, 1, 4, 5)) - t3_aabaab += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 - t3_aabaab += einsum(t1.bb, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 - t3_aabaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 - t3_aabaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (0, 2, 4, 3, 1, 5)) - return t3_aabaab - -def t3_uhf_abaaba(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_abaaba = np.zeros((nocc[0], nocc[1], nocc[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) - t3_abaaba += einsum(c3.abaaba, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) - t3_abaaba += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (0, 3, 2, 1, 5, 4)) * -1.0 - t3_abaaba += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (0, 3, 2, 4, 5, 1)) - t3_abaaba += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (2, 3, 0, 1, 5, 4)) - t3_abaaba += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 - t3_abaaba += einsum(t1.bb, (0, 1), t2.aaaa, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 - t3_abaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (0, 4, 2, 1, 5, 3)) * -1.0 - t3_abaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (0, 4, 2, 3, 5, 1)) - return t3_abaaba - -def t3_uhf_abbabb(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_abbabb = np.zeros((nocc[0], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) - t3_abbabb += einsum(c3.abbabb, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) - t3_abbabb += einsum(t1.aa, (0, 1), t2.bbbb, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 - t3_abbabb += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 - t3_abbabb += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (2, 0, 3, 4, 5, 1)) - t3_abbabb += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (2, 3, 0, 4, 1, 5)) - t3_abbabb += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 - t3_abbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 - t3_abbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 5, 3)) - return t3_abbabb - -def t3_uhf_baabaa(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_baabaa = np.zeros((nocc[1], nocc[0], nocc[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) - t3_baabaa += einsum(c3.abaaba, (0, 1, 2, 3, 4, 5), (1, 0, 2, 4, 3, 5)) - t3_baabaa += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (3, 0, 2, 5, 1, 4)) * -1.0 - t3_baabaa += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (3, 0, 2, 5, 4, 1)) - t3_baabaa += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (3, 2, 0, 5, 1, 4)) - t3_baabaa += einsum(t1.aa, (0, 1), t2.abab, (2, 3, 4, 5), (3, 2, 0, 5, 4, 1)) * -1.0 - t3_baabaa += einsum(t1.bb, (0, 1), t2.aaaa, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 - t3_baabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (4, 0, 2, 5, 1, 3)) * -1.0 - t3_baabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), (4, 0, 2, 5, 3, 1)) - return t3_baabaa - -def t3_uhf_babbab(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_babbab = np.zeros((nocc[1], nocc[0], nocc[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t3_babbab += einsum(c3.babbab, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) - t3_babbab += einsum(t1.aa, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 - t3_babbab += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 - t3_babbab += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (0, 2, 3, 5, 4, 1)) - t3_babbab += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (3, 2, 0, 1, 4, 5)) - t3_babbab += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (3, 2, 0, 5, 4, 1)) * -1.0 - t3_babbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (2, 0, 4, 3, 1, 5)) * -1.0 - t3_babbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (2, 0, 4, 5, 1, 3)) - return t3_babbab - -def t3_uhf_bbabba(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_bbabba = np.zeros((nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) - t3_bbabba += einsum(c3.bbabba, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) - t3_bbabba += einsum(t1.aa, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 - t3_bbabba += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (0, 3, 2, 1, 5, 4)) * -1.0 - t3_bbabba += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (0, 3, 2, 5, 1, 4)) - t3_bbabba += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (3, 0, 2, 1, 5, 4)) - t3_bbabba += einsum(t1.bb, (0, 1), t2.abab, (2, 3, 4, 5), (3, 0, 2, 5, 1, 4)) * -1.0 - t3_bbabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (2, 4, 0, 3, 5, 1)) * -1.0 - t3_bbabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (2, 4, 0, 5, 3, 1)) - return t3_bbabba - -def t3_uhf_bbbbbb(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_bbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t3_bbbbbb += einsum(c3.bbbbbb, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (0, 2, 3, 4, 1, 5)) - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (0, 2, 3, 4, 5, 1)) * -1.0 - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 0, 3, 1, 4, 5)) - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 0, 3, 4, 5, 1)) - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 3, 0, 1, 4, 5)) * -1.0 - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 3, 0, 4, 1, 5)) - t3_bbbbbb += einsum(t1.bb, (0, 1), t2.bbbb, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 - t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 - t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 1, 5, 3)) - t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 3, 1, 5)) - t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 5, 1, 3)) * -1.0 - t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 3, 5, 1)) * -1.0 - t3_bbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), (0, 2, 4, 5, 3, 1)) - return t3_bbbbbb - -def t3_rhf(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) - t3 += einsum(c3, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 3, 2, 1, 5, 4)) * -1.0 - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 3, 2, 4, 5, 1)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 5, 1, 4)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 1, 5, 4)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 - t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 - t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 5, 3, 1)) - return t3 - -def t3_ghf(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) - t3 += einsum(c3, (0, 1, 2, 3, 4, 5), (0, 1, 2, 3, 4, 5)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 2, 3, 1, 4, 5)) * -1.0 - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 2, 3, 4, 1, 5)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (0, 2, 3, 4, 5, 1)) * -1.0 - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 1, 4, 5)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 4, 1, 5)) * -1.0 - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 0, 3, 4, 5, 1)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 1, 4, 5)) * -1.0 - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 4, 1, 5)) - t3 += einsum(t1, (0, 1), t2, (2, 3, 4, 5), (2, 3, 0, 4, 5, 1)) * -1.0 - t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 1, 3, 5)) * -1.0 - t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 1, 5, 3)) - t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 3, 1, 5)) - t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 5, 1, 3)) * -1.0 - t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 3, 5, 1)) * -1.0 - t3 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), (0, 2, 4, 5, 3, 1)) - return t3 - -def t4_uhf_aaaaaaaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_aaaaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - t4_aaaaaaaa += einsum(c4.aaaaaaaa, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 5, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 5, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 3, 6, 7)) - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 7, 2, 3)) - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 3, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 7, 2, 3)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 3, 7)) - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 7, 3)) - t4_aaaaaaaa += einsum(t2.aaaa, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 7, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 3, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 3, 1, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 1, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 3, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 3, 1, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 1, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 3, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 1, 3, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 1, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 1, 3, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 3, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 3, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 3, 1, 6, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 7, 3, 5)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 5, 7, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 1, 7, 5)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 1, 3, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 1, 3, 5)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 1, 7, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 1, 5, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 5, 1, 7)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 7, 1, 5)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 3, 1, 5)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 5, 1, 3)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 5, 7, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 3, 7, 5, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 3, 7, 1)) * -1.0 - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 3, 5, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 5, 7, 3, 1)) - t4_aaaaaaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.aa, (6, 7), (0, 2, 4, 6, 7, 5, 3, 1)) * -1.0 - return t4_aaaaaaaa - -def t4_uhf_aaabaaab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_aaabaaab = np.zeros((nocc[0], nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[0], nvir[1]), dtype=np.float64) - t4_aaabaaab += einsum(c4.aaabaaab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 1, 5, 7, 6)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 5, 1, 7, 6)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 5, 7, 1, 6)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 1, 5, 7, 6)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 1, 7, 6)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 7, 1, 6)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 1, 5, 7, 6)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 5, 1, 7, 6)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 5, 7, 1, 6)) * -1.0 - t4_aaabaaab += einsum(t1.bb, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 6, 7, 2, 3)) * -1.0 - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 1, 2, 6, 7, 3)) - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 1, 6, 2, 7, 3)) * -1.0 - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 1, 6, 7, 2, 3)) - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 1, 2, 6, 7, 3)) * -1.0 - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 1, 6, 2, 7, 3)) - t4_aaabaaab += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 1, 6, 7, 2, 3)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 3, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 1, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 3, 1, 6, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 1, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 1, 3, 6, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 1, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 1, 3)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 7, 3)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 1, 3, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 5, 1, 7)) * -1.0 - t4_aaabaaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) - return t4_aaabaaab - -def t4_uhf_aabaaaba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_aabaaaba = np.zeros((nocc[0], nocc[0], nocc[1], nocc[0], nvir[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) - t4_aabaaaba += einsum(c4.aabaaaba, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 7, 6, 1)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 7, 6, 1)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 1, 5, 6, 7)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 5, 1, 6, 7)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 5, 7, 6, 1)) * -1.0 - t4_aabaaaba += einsum(t1.bb, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 6, 7, 3, 2)) * -1.0 - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 1, 5, 2, 6, 3, 7)) - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 1, 5, 6, 2, 3, 7)) * -1.0 - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 1, 5, 6, 7, 3, 2)) - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 1, 0, 2, 6, 3, 7)) * -1.0 - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 1, 0, 6, 2, 3, 7)) - t4_aabaaaba += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 1, 0, 6, 7, 3, 2)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 3, 7, 6)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 6, 7, 3)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 3, 1, 7, 6)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 6, 1, 7, 3)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 3, 6, 7, 1)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 6, 3, 7, 1)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 7, 6)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 3, 1, 7, 6)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 7, 1)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 1, 3, 7, 6)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 7, 6)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 7, 1)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 3, 1)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 2, 0, 1, 6, 3, 7)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 2, 0, 6, 1, 3, 7)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 2, 0, 6, 7, 3, 1)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 1, 3, 7, 5)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 1, 5, 7, 3)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 3, 1, 7, 5)) - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 5, 1, 7, 3)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 3, 5, 7, 1)) * -1.0 - t4_aabaaaba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 2, 6, 4, 5, 3, 7, 1)) - return t4_aabaaaba - -def t4_uhf_aabbaabb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_aabbaabb = np.zeros((nocc[0], nocc[0], nocc[1], nocc[1], nvir[0], nvir[0], nvir[1], nvir[1]), dtype=np.float64) - t4_aabbaabb += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 2, 1, 3, 4, 6, 5, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_aabbaabb += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 5, 7, 1, 6)) * -1.0 - t4_aabbaabb += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 0, 3, 5, 7, 6, 1)) - t4_aabbaabb += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 5, 7, 1, 6)) - t4_aabbaabb += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 4, 3, 0, 5, 7, 6, 1)) * -1.0 - t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) - t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) - t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 7, 3)) * -1.0 - t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) - t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 - t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 3, 7)) * -1.0 - t4_aabbaabb += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) - t4_aabbaabb += einsum(t2.aaaa, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 7, 3)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 3, 7)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 7, 3)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 3, 7)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_aabbaabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_aabbaabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) - t4_aabbaabb += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 7, 5)) * -1.0 - return t4_aabbaabb - -def t4_uhf_abaaabaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_abaaabaa = np.zeros((nocc[0], nocc[1], nocc[0], nocc[0], nvir[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) - t4_abaaabaa += einsum(c4.abaaabaa, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 1, 6, 5, 7)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 5, 6, 1, 7)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 5, 6, 7, 1)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 6, 5, 7)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 6, 5, 7)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_abaaabaa += einsum(t1.bb, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 2, 7)) - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 7, 2)) * -1.0 - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 0, 5, 2, 3, 6, 7)) - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 0, 5, 6, 3, 2, 7)) * -1.0 - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 0, 5, 6, 3, 7, 2)) - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 5, 0, 2, 3, 6, 7)) * -1.0 - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 5, 0, 6, 3, 2, 7)) - t4_abaaabaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (4, 1, 5, 0, 6, 3, 7, 2)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 3, 6)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 6, 3)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 1, 6)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 1, 3)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 6, 1)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 3, 1)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 3, 6)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 1, 6)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 1, 3)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 6, 1)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 3, 1)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 3, 6)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 6, 3)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 3, 7, 1, 6)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 3, 7, 6, 1)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 0, 5, 1, 3, 6, 7)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 0, 5, 6, 3, 1, 7)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 0, 5, 6, 3, 7, 1)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 5, 0, 1, 3, 6, 7)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 5, 0, 6, 3, 1, 7)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 2, 5, 0, 6, 3, 7, 1)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 1, 7, 3, 5)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 1, 7, 5, 3)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 3, 7, 1, 5)) - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 5, 7, 1, 3)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 3, 7, 5, 1)) * -1.0 - t4_abaaabaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (0, 6, 2, 4, 5, 7, 3, 1)) - return t4_abaaabaa - -def t4_uhf_abababab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_abababab = np.zeros((nocc[0], nocc[1], nocc[0], nocc[1], nvir[0], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t4_abababab += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 1, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 6, 5, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_abababab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 1, 7, 6)) * -1.0 - t4_abababab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 6, 7, 1)) - t4_abababab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 7, 6)) - t4_abababab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 4, 5, 2, 7, 6, 3)) - t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 2, 7)) - t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 - t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 1, 2, 3, 6, 7)) - t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 1, 2, 7, 6, 3)) * -1.0 - t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 1, 6, 3, 2, 7)) * -1.0 - t4_abababab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 1, 6, 7, 2, 3)) - t4_abababab += einsum(t2.aaaa, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 7, 6, 3)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 3, 6, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 6, 3, 1, 7)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 1, 3)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 0, 5, 1, 3, 6, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 0, 5, 1, 7, 6, 3)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 0, 5, 6, 3, 1, 7)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 0, 5, 6, 7, 1, 3)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 6, 3)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_abababab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_abababab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) - t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 2, 6, 1, 5, 3, 7)) * -1.0 - t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 2, 6, 1, 7, 3, 5)) - t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 2, 6, 3, 5, 1, 7)) - t4_abababab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 2, 6, 3, 7, 1, 5)) * -1.0 - return t4_abababab - -def t4_uhf_abbaabba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_abbaabba = np.zeros((nocc[0], nocc[1], nocc[1], nocc[0], nvir[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) - t4_abbaabba += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 3, 2, 4, 5, 7, 6)) - t4_abbaabba += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 7, 5, 6, 1)) - t4_abbaabba += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 6, 7, 5)) - t4_abbaabba += einsum(t1.aa, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_abbaabba += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_abbaabba += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) - t4_abbaabba += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) - t4_abbaabba += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 5, 4, 2, 3, 7, 6)) * -1.0 - t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 5, 4, 2, 7, 3, 6)) - t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 5, 4, 6, 3, 7, 2)) - t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 1, 5, 4, 6, 7, 3, 2)) * -1.0 - t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 1, 4, 2, 3, 7, 6)) - t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 1, 4, 2, 7, 3, 6)) * -1.0 - t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 1, 4, 6, 3, 7, 2)) * -1.0 - t4_abbaabba += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 1, 4, 6, 7, 3, 2)) - t4_abbaabba += einsum(t2.aaaa, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 3, 7, 6)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 7, 3, 6)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 6, 3, 7, 1)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 6, 7, 3, 1)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 3, 7, 6)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 3, 6)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 6, 3, 7, 1)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 3, 1)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 5, 0, 1, 3, 7, 6)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 5, 0, 1, 7, 3, 6)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 5, 0, 6, 3, 7, 1)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 2, 5, 0, 6, 7, 3, 1)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 2, 0, 1, 3, 7, 6)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 2, 0, 1, 7, 3, 6)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 2, 0, 6, 3, 7, 1)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 2, 0, 6, 7, 3, 1)) * -1.0 - t4_abbaabba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_abbaabba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 6, 2, 1, 5, 7, 3)) * -1.0 - t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 6, 2, 1, 7, 5, 3)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 6, 2, 3, 5, 7, 1)) - t4_abbaabba += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 4, 6, 2, 3, 7, 5, 1)) * -1.0 - return t4_abbaabba - -def t4_uhf_abbbabbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_abbbabbb = np.zeros((nocc[0], nocc[1], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t4_abbbabbb += einsum(c4.abbbabbb, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_abbbabbb += einsum(t1.aa, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 7, 1)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 6, 7)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 3, 6, 7)) - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 3, 6, 7)) * -1.0 - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 3, 7)) - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 7, 3)) * -1.0 - t4_abbbabbb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 7, 3)) * -1.0 - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 6, 7)) * -1.0 - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 1, 3)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 7, 1)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 1, 7)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 3, 1)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 3, 7)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 7, 1)) * -1.0 - t4_abbbabbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 7, 3, 5)) * -1.0 - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 7, 3)) * -1.0 - t4_abbbabbb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) - return t4_abbbabbb - -def t4_uhf_baaabaaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_baaabaaa = np.zeros((nocc[1], nocc[0], nocc[0], nocc[0], nvir[1], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - t4_baaabaaa += einsum(c4.baaabaaa, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 6, 1, 5, 7)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 6, 5, 1, 7)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 6, 5, 7, 1)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 1, 5, 7)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 5, 1, 7)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 5, 7, 1)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 6, 1, 5, 7)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 6, 5, 1, 7)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 6, 5, 7, 1)) * -1.0 - t4_baaabaaa += einsum(t1.bb, (0, 1), t3.aaaaaa, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 0, 4, 5, 3, 2, 6, 7)) * -1.0 - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 0, 4, 5, 3, 6, 2, 7)) - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 0, 4, 5, 3, 6, 7, 2)) * -1.0 - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 0, 5, 3, 2, 6, 7)) - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 0, 5, 3, 6, 2, 7)) * -1.0 - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 0, 5, 3, 6, 7, 2)) - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 5, 0, 3, 2, 6, 7)) * -1.0 - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 5, 0, 3, 6, 2, 7)) - t4_baaabaaa += einsum(t2.abab, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (1, 4, 5, 0, 3, 6, 7, 2)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 1, 3, 6)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 1, 6, 3)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 3, 1, 6)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 6, 1, 3)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 3, 6, 1)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 6, 3, 1)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 1, 3, 6)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 1, 6, 3)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 3, 1, 6)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 6, 1, 3)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 3, 6, 1)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 6, 3, 1)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 1, 3, 6)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 1, 6, 3)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 3, 1, 6)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 1, 3)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 3, 6, 1)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 3, 1)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 0, 4, 5, 3, 1, 6, 7)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 0, 4, 5, 3, 6, 1, 7)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 0, 4, 5, 3, 6, 7, 1)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 0, 5, 3, 1, 6, 7)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 0, 5, 3, 6, 1, 7)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 0, 5, 3, 6, 7, 1)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 5, 0, 3, 1, 6, 7)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 5, 0, 3, 6, 1, 7)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (2, 4, 5, 0, 3, 6, 7, 1)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 1, 3, 5)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 1, 5, 3)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 3, 1, 5)) - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 5, 1, 3)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 3, 5, 1)) * -1.0 - t4_baaabaaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.aa, (4, 5), t1.bb, (6, 7), (6, 0, 2, 4, 7, 5, 3, 1)) - return t4_baaabaaa - -def t4_uhf_baabbaab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_baabbaab = np.zeros((nocc[1], nocc[0], nocc[0], nocc[1], nvir[1], nvir[0], nvir[0], nvir[1]), dtype=np.float64) - t4_baabbaab += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (1, 0, 2, 3, 5, 4, 6, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_baabbaab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 1, 5, 7, 6)) * -1.0 - t4_baabbaab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 4, 3, 6, 5, 7, 1)) - t4_baabbaab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 1, 5, 7, 6)) - t4_baabbaab += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 4, 0, 6, 5, 7, 1)) * -1.0 - t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 4, 5, 3, 2, 6, 7)) * -1.0 - t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 4, 5, 7, 2, 6, 3)) - t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 4, 5, 3, 6, 2, 7)) - t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 4, 5, 7, 6, 2, 3)) * -1.0 - t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 1, 3, 2, 6, 7)) - t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 1, 7, 2, 6, 3)) * -1.0 - t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 1, 3, 6, 2, 7)) * -1.0 - t4_baabbaab += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 1, 7, 6, 2, 3)) - t4_baabbaab += einsum(t2.bbbb, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 4, 5, 3, 1, 6, 7)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 4, 5, 7, 1, 6, 3)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 4, 5, 3, 6, 1, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 4, 5, 7, 6, 1, 3)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 3, 1, 6, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 1, 6, 3)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 3, 6, 1, 7)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 6, 1, 3)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 0, 5, 3, 1, 6, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 0, 5, 7, 1, 6, 3)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 0, 5, 3, 6, 1, 7)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 0, 5, 7, 6, 1, 3)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 3, 1, 6, 7)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 1, 6, 3)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 3, 6, 1, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 1, 3)) * -1.0 - t4_baabbaab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_baabbaab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 2, 6, 5, 1, 3, 7)) * -1.0 - t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 2, 6, 7, 1, 3, 5)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 2, 6, 5, 3, 1, 7)) - t4_baabbaab += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 2, 6, 7, 3, 1, 5)) * -1.0 - return t4_baabbaab - -def t4_uhf_babababa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_babababa = np.zeros((nocc[1], nocc[0], nocc[1], nocc[0], nvir[1], nvir[0], nvir[1], nvir[0]), dtype=np.float64) - t4_babababa += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (1, 0, 3, 2, 5, 4, 7, 6)) - t4_babababa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 7, 6, 1)) - t4_babababa += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 7, 6)) - t4_babababa += einsum(t1.aa, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_babababa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_babababa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 1, 7)) - t4_babababa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 1, 5, 6, 7)) - t4_babababa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 5, 1, 7)) * -1.0 - t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 5, 4, 3, 2, 7, 6)) * -1.0 - t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 5, 4, 7, 2, 3, 6)) - t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 5, 4, 3, 6, 7, 2)) - t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 0, 5, 4, 7, 6, 3, 2)) * -1.0 - t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 1, 4, 3, 2, 7, 6)) - t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 1, 4, 7, 2, 3, 6)) * -1.0 - t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 1, 4, 3, 6, 7, 2)) * -1.0 - t4_babababa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 1, 4, 7, 6, 3, 2)) - t4_babababa += einsum(t2.bbbb, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 5, 4, 3, 1, 7, 6)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 5, 4, 7, 1, 3, 6)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 5, 4, 3, 6, 7, 1)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 0, 5, 4, 7, 6, 3, 1)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 3, 1, 7, 6)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 1, 3, 6)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 3, 6, 7, 1)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 6, 3, 1)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 5, 0, 3, 1, 7, 6)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 5, 0, 7, 1, 3, 6)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 5, 0, 3, 6, 7, 1)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 4, 5, 0, 7, 6, 3, 1)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 2, 0, 3, 1, 7, 6)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 2, 0, 7, 1, 3, 6)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 2, 0, 3, 6, 7, 1)) - t4_babababa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 2, 0, 7, 6, 3, 1)) * -1.0 - t4_babababa += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_babababa += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) - t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 6, 2, 5, 1, 7, 3)) * -1.0 - t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 6, 2, 7, 1, 5, 3)) - t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 6, 2, 5, 3, 7, 1)) - t4_babababa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 0, 6, 2, 7, 3, 5, 1)) * -1.0 - return t4_babababa - -def t4_uhf_babbbabb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_babbbabb = np.zeros((nocc[1], nocc[0], nocc[1], nocc[1], nvir[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) - t4_babbbabb += einsum(c4.babbbabb, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_babbbabb += einsum(t1.aa, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 1, 7)) - t4_babbbabb += einsum(t1.bb, (0, 1), t3.abbabb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 7, 1)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 6, 5, 7)) - t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) - t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 6, 5, 7)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) - t4_babbbabb += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 1, 5, 6, 2, 3, 7)) * -1.0 - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 1, 5, 6, 2, 7, 3)) - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 1, 5, 3, 2, 6, 7)) - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 1, 6, 2, 3, 7)) - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 1, 6, 2, 7, 3)) * -1.0 - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 1, 3, 2, 6, 7)) * -1.0 - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 0, 4, 5, 6, 2, 3, 7)) - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 0, 4, 5, 6, 2, 7, 3)) * -1.0 - t4_babbbabb += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 0, 4, 5, 3, 2, 6, 7)) * -1.0 - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 0, 4, 5, 3, 1, 6, 7)) * -1.0 - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 0, 4, 5, 6, 1, 3, 7)) - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 0, 4, 5, 6, 1, 7, 3)) * -1.0 - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 7, 6, 1, 3)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 7, 1)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 2, 5, 7, 6, 3, 1)) - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 1, 7)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 7, 6, 1, 3)) - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 4, 5, 2, 7, 6, 3, 1)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 1, 6, 3, 7)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 1, 6, 7, 3)) - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 3, 6, 1, 7)) - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 1, 3)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 3, 6, 7, 1)) * -1.0 - t4_babbbabb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 4, 0, 2, 7, 6, 3, 1)) - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 3, 1, 5, 7)) * -1.0 - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 3, 1, 7, 5)) - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 5, 1, 3, 7)) - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 7, 1, 3, 5)) * -1.0 - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 5, 1, 7, 3)) * -1.0 - t4_babbbabb += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 0, 4, 6, 7, 1, 5, 3)) - return t4_babbbabb - -def t4_uhf_bbaabbaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_bbaabbaa = np.zeros((nocc[1], nocc[1], nocc[0], nocc[0], nvir[1], nvir[1], nvir[0], nvir[0]), dtype=np.float64) - t4_bbaabbaa += einsum(c4.abababab, (0, 1, 2, 3, 4, 5, 6, 7), (1, 3, 0, 2, 5, 7, 4, 6)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_bbaabbaa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 1, 6, 5, 7)) * -1.0 - t4_bbaabbaa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 6, 1, 5, 7)) - t4_bbaabbaa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 1, 6, 5, 7)) - t4_bbaabbaa += einsum(t1.bb, (0, 1), t3.abaaba, (2, 3, 4, 5, 6, 7), (3, 0, 2, 4, 6, 1, 5, 7)) * -1.0 - t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 5, 0, 4, 3, 7, 2, 6)) * -1.0 - t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 5, 0, 4, 7, 3, 2, 6)) - t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 5, 0, 4, 3, 7, 6, 2)) - t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (1, 5, 0, 4, 7, 3, 6, 2)) * -1.0 - t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 1, 0, 4, 3, 7, 2, 6)) - t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 1, 0, 4, 7, 3, 2, 6)) * -1.0 - t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 1, 0, 4, 3, 7, 6, 2)) * -1.0 - t4_bbaabbaa += einsum(t2.abab, (0, 1, 2, 3), t2.abab, (4, 5, 6, 7), (5, 1, 0, 4, 7, 3, 6, 2)) - t4_bbaabbaa += einsum(t2.bbbb, (0, 1, 2, 3), t2.aaaa, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 0, 4, 3, 7, 1, 6)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 0, 4, 7, 3, 1, 6)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 0, 4, 3, 7, 6, 1)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 0, 4, 7, 3, 6, 1)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 0, 4, 3, 7, 1, 6)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 0, 4, 7, 3, 1, 6)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 0, 4, 3, 7, 6, 1)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 0, 4, 7, 3, 6, 1)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 4, 0, 3, 7, 1, 6)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 4, 0, 7, 3, 1, 6)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 4, 0, 3, 7, 6, 1)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (2, 5, 4, 0, 7, 3, 6, 1)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 4, 0, 3, 7, 1, 6)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 4, 0, 7, 3, 1, 6)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 4, 0, 3, 7, 6, 1)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 2, 4, 0, 7, 3, 6, 1)) * -1.0 - t4_bbaabbaa += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_bbaabbaa += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.aaaa, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 6, 0, 2, 5, 7, 1, 3)) * -1.0 - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 6, 0, 2, 7, 5, 1, 3)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 6, 0, 2, 5, 7, 3, 1)) - t4_bbaabbaa += einsum(t1.aa, (0, 1), t1.aa, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (4, 6, 0, 2, 7, 5, 3, 1)) * -1.0 - return t4_bbaabbaa - -def t4_uhf_bbabbbab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_bbabbbab = np.zeros((nocc[1], nocc[1], nocc[0], nocc[1], nvir[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t4_bbabbbab += einsum(c4.bbabbbab, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_bbabbbab += einsum(t1.aa, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 7, 6, 1)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.babbab, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 7, 6, 1)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 5, 7, 6)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 7, 6)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 0, 5, 6, 3, 2, 7)) * -1.0 - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 0, 5, 6, 7, 2, 3)) - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 0, 5, 3, 6, 2, 7)) - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 1, 6, 3, 2, 7)) - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 1, 6, 7, 2, 3)) * -1.0 - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 1, 3, 6, 2, 7)) * -1.0 - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 0, 5, 6, 3, 2, 7)) - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 0, 5, 6, 7, 2, 3)) * -1.0 - t4_bbabbbab += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 0, 5, 3, 6, 2, 7)) * -1.0 - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 0, 5, 3, 6, 1, 7)) * -1.0 - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 0, 5, 6, 3, 1, 7)) - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 0, 5, 6, 7, 1, 3)) * -1.0 - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 0, 5, 3, 6, 1, 7)) - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 0, 5, 6, 3, 1, 7)) * -1.0 - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 0, 5, 6, 7, 1, 3)) - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 1, 7)) * -1.0 - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 1, 7, 6, 3)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 7, 1, 6, 3)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 3, 7, 6, 1)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 4, 5, 7, 3, 6, 1)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 3, 6, 7)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 3, 1, 6, 7)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 7, 1, 6, 3)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 6, 1)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 4, 2, 7, 3, 6, 1)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 1, 3, 6, 7)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 1, 7, 6, 3)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 3, 1, 6, 7)) - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 1, 6, 3)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 3, 7, 6, 1)) * -1.0 - t4_bbabbbab += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 4, 2, 7, 3, 6, 1)) - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 3, 5, 1, 7)) * -1.0 - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 3, 7, 1, 5)) - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 5, 3, 1, 7)) - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 7, 3, 1, 5)) * -1.0 - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 5, 7, 1, 3)) * -1.0 - t4_bbabbbab += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 0, 6, 7, 5, 1, 3)) - return t4_bbabbbab - -def t4_uhf_bbbabbba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_bbbabbba = np.zeros((nocc[1], nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[1], nvir[0]), dtype=np.float64) - t4_bbbabbba += einsum(c4.bbbabbba, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_bbbabbba += einsum(t1.aa, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 1, 7)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 5, 6, 7)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t3.bbabba, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 5, 0, 6, 3, 7, 2)) * -1.0 - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 5, 0, 6, 7, 3, 2)) - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 1, 5, 0, 3, 6, 7, 2)) - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 1, 0, 6, 3, 7, 2)) - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 1, 0, 6, 7, 3, 2)) * -1.0 - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 1, 0, 3, 6, 7, 2)) * -1.0 - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 5, 0, 6, 3, 7, 2)) - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 5, 0, 6, 7, 3, 2)) * -1.0 - t4_bbbabbba += einsum(t2.abab, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (1, 4, 5, 0, 3, 6, 7, 2)) * -1.0 - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 5, 0, 3, 6, 7, 1)) * -1.0 - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 5, 0, 6, 3, 7, 1)) - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (2, 4, 5, 0, 6, 7, 3, 1)) * -1.0 - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 5, 0, 3, 6, 7, 1)) - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 5, 0, 6, 3, 7, 1)) * -1.0 - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 2, 5, 0, 6, 7, 3, 1)) - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 2, 0, 3, 6, 7, 1)) * -1.0 - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 2, 0, 6, 3, 7, 1)) - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 2, 0, 6, 7, 3, 1)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 3, 7, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 1, 7, 3, 6)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 3, 1, 7, 6)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 7, 1, 3, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 3, 7, 1, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 2, 5, 4, 7, 3, 1, 6)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 3, 7, 6)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 3, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 3, 1, 7, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 7, 1, 3, 6)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 1, 6)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (0, 5, 2, 4, 7, 3, 1, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 1, 3, 7, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 1, 7, 3, 6)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 3, 1, 7, 6)) - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 1, 3, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 3, 7, 1, 6)) * -1.0 - t4_bbbabbba += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.abab, (4, 5, 6, 7), (5, 0, 2, 4, 7, 3, 1, 6)) - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 3, 5, 7, 1)) * -1.0 - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 3, 7, 5, 1)) - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 5, 3, 7, 1)) - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 7, 3, 5, 1)) * -1.0 - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 5, 7, 3, 1)) * -1.0 - t4_bbbabbba += einsum(t1.aa, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (2, 4, 6, 0, 7, 5, 3, 1)) - return t4_bbbabbba - -def t4_uhf_bbbbbbbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_bbbbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t4_bbbbbbbb += einsum(c4.bbbbbbbb, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 5, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 5, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t3.bbbbbb, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 2, 3, 6, 7)) - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 1, 5, 6, 7, 2, 3)) - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 2, 3, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 1, 6, 7, 2, 3)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 3, 7)) - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 7, 3)) - t4_bbbbbbbb += einsum(t2.bbbb, (0, 1, 2, 3), t2.bbbb, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 7, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 3, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 3, 1, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 1, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 3, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 3, 1, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 1, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 3, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 1, 3, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 1, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 1, 3, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 3, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 3, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 3, 1, 6, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t2.bbbb, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 7, 3, 5)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 5, 7, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 1, 7, 5)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 1, 3, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 1, 3, 5)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 1, 7, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 1, 5, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 5, 1, 7)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 7, 1, 5)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 3, 1, 5)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 5, 1, 3)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 5, 7, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 3, 7, 5, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 3, 7, 1)) * -1.0 - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 3, 5, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 5, 7, 3, 1)) - t4_bbbbbbbb += einsum(t1.bb, (0, 1), t1.bb, (2, 3), t1.bb, (4, 5), t1.bb, (6, 7), (0, 2, 4, 6, 7, 5, 3, 1)) * -1.0 - return t4_bbbbbbbb - -def t4_rhf_abab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) - t4 += einsum(c4, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 6, 5, 1, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 1, 7, 6)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 4, 3, 5, 6, 7, 1)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 1, 5, 6, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (3, 2, 0, 4, 6, 5, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 7, 6)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 7, 3, 6)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 3, 6, 2, 7)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 3, 7, 2, 6)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 7, 6, 3)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 2, 7)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 2, 3, 6, 7)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 2, 7, 6, 3)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 6, 3, 2, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 6, 7, 2, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 7, 6, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 7, 3, 6)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 7, 1, 6)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 1, 3, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 6, 3, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 1, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 7, 6, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 7, 1, 6, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 7, 3, 6, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 6, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 - return t4 - -def t4_rhf_abaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) - t4 += einsum(c4, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 1, 6, 5, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 5, 6, 1, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 3, 2, 4, 5, 6, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 6, 1, 5, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 7, 6)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 6, 5, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 6, 5, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 7, 6)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 2, 7)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 7, 3, 2, 6)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 3, 7, 2)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 7, 3, 6, 2)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 2, 7, 6, 3)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 2, 7, 3, 6)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 6, 7, 2, 3)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 3, 7, 2, 6)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 6, 7, 3, 2)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 1, 3, 7, 6, 2)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 2, 7, 6, 3)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 2, 7, 3, 6)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 6, 7, 2, 3)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 3, 7, 2, 6)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 6, 7, 3, 2)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 5, 1, 4, 3, 7, 6, 2)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 7, 6)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 7, 3, 1, 6)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 7, 3, 6, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 3, 6)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 1, 7, 6, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 1, 6)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 3, 7, 6, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 2, 4, 6, 7, 3, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 3, 6)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 1, 7, 6, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 1, 6)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 1, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 3, 7, 6, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 5, 4, 2, 6, 7, 3, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 7, 6)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 7, 1, 3, 6)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 7, 1, 6, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 7, 6)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 7, 1, 3, 6)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 7, 1, 6, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 3, 6)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 7, 6, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 7, 1, 6)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 7, 6, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 3, 1, 5)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 3, 5, 1)) - return t4 - -def t4_ghf(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) - t4 += einsum(c4, (0, 1, 2, 3, 4, 5, 6, 7), (0, 1, 2, 3, 4, 5, 6, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 1, 5, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 1, 6, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (0, 2, 3, 4, 5, 6, 7, 1)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 1, 5, 6, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 1, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 1, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 0, 3, 4, 5, 6, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 1, 5, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 1, 6, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 0, 4, 5, 6, 7, 1)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 1, 5, 6, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 1, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 1, 7)) - t4 += einsum(t1, (0, 1), t3, (2, 3, 4, 5, 6, 7), (2, 3, 4, 0, 5, 6, 7, 1)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 3, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 6, 7, 3)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 2, 3, 6, 7)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 3, 7)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 6, 2, 7, 3)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 1, 5, 6, 7, 2, 3)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 3, 7)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 2, 6, 7, 3)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 2, 3, 6, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 3, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 6, 2, 7, 3)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 1, 6, 7, 2, 3)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 3, 7)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 6, 7, 3)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 2, 3, 6, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 3, 7)) * -1.0 - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 2, 7, 3)) - t4 += einsum(t2, (0, 1, 2, 3), t2, (4, 5, 6, 7), (0, 1, 4, 5, 6, 7, 2, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 3, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 3, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 1, 6, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 3, 1, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 1, 7, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 3, 6, 7, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 3, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 2, 4, 5, 6, 7, 3, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 3, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 1, 6, 7, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 1, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 3, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 1, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 1, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 3, 6, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 3, 7, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 2, 5, 6, 7, 3, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 1, 3, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 3, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 1, 6, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 3, 1, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 1, 7, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 3, 6, 7, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 3, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (0, 4, 5, 2, 6, 7, 3, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 1, 3, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 3, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 1, 6, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 1, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 1, 7, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 3, 6, 7, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 3, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 2, 5, 6, 7, 3, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 1, 3, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 1, 6, 7, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 1, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 3, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 1, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 1, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 3, 6, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 3, 7, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 0, 5, 2, 6, 7, 3, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 3, 6, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 3, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 1, 6, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 1, 6, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 1, 7, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 3, 6, 7, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 3, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t2, (4, 5, 6, 7), (4, 5, 0, 2, 6, 7, 3, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 5, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 3, 7, 5)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 5, 3, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 7, 3, 5)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 5, 7, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 1, 7, 5, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 1, 5, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 1, 7, 5)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 1, 3, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 1, 3, 5)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 1, 7, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 1, 5, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 5, 1, 7)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 7, 1, 5)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 1, 7)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 3, 1, 5)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 7, 1, 3)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 5, 1, 3)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 5, 7, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 3, 7, 5, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 3, 7, 1)) * -1.0 - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 3, 5, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 5, 7, 3, 1)) - t4 += einsum(t1, (0, 1), t1, (2, 3), t1, (4, 5), t1, (6, 7), (0, 2, 4, 6, 7, 5, 3, 1)) * -1.0 - return t4 - diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index caddde8f4..689eb64f9 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -2,6 +2,7 @@ import vayesta from vayesta.core.util import * from vayesta.core.types import wf as wf_types +from vayesta.core.types.wf import t_to_c def CISDTQ_WaveFunction(mo, *args, **kwargs): @@ -218,12 +219,6 @@ def as_ccsdtq(self): c3_aaaaaa, c3_abaaba, c3_abbabb, c3_babbab, c3_bbabba, c3_bbbbbb = (c / self.c0 for c in self.c3) c4_aaaaaaaa, c4_aaabaaab, c4_aabaaaba, c4_abaaabaa, c4_abababab, c4_abbbabbb, c4_bbabbbab, c4_bbbabbba, c4_bbbbbbbb = (c / self.c0 for c in self.c4) - from ._conversion_routines import \ - t1_uhf_aa, t1_uhf_bb, \ - t2_uhf_aaaa, t2_uhf_abab, t2_uhf_bbbb, \ - t3_uhf_aaaaaa, t3_uhf_abaaba, t3_uhf_abbabb, t3_uhf_babbab, t3_uhf_bbabba, t3_uhf_bbbbbb, \ - t4_uhf_aaaaaaaa, t4_uhf_aaabaaab, t4_uhf_aabaaaba, t4_uhf_abaaabaa, t4_uhf_abababab, t4_uhf_abbbabbb, t4_uhf_bbabbbab, t4_uhf_bbbabbba, t4_uhf_bbbbbbbb - from types import SimpleNamespace c1 = SimpleNamespace(aa=c1_aa, bb=c1_bb) c2 = SimpleNamespace(aaaa=c2_aaaa, abab=c2_abab, bbbb=c2_bbbb) @@ -233,32 +228,32 @@ def as_ccsdtq(self): nocc = (c1.aa.shape[0], c1.bb.shape[0]) nvir = (c1.aa.shape[1], c1.bb.shape[1]) - t1_aa = t1_uhf_aa(c1=c1, nocc=nocc, nvir=nvir) - t1_bb = t1_uhf_bb(c1=c1, nocc=nocc, nvir=nvir) + t1_aa = t_to_c.t1_uhf_aa(c1=c1, nocc=nocc, nvir=nvir) + t1_bb = t_to_c.t1_uhf_bb(c1=c1, nocc=nocc, nvir=nvir) t1 = SimpleNamespace(aa=t1_aa, bb=t1_bb) - t2_aaaa = t2_uhf_aaaa(c2=c2, t1=t1, nocc=nocc, nvir=nvir) - t2_abab = t2_uhf_abab(c2=c2, t1=t1, nocc=nocc, nvir=nvir) - t2_bbbb = t2_uhf_bbbb(c2=c2, t1=t1, nocc=nocc, nvir=nvir) + t2_aaaa = t_to_c.t2_uhf_aaaa(c2=c2, t1=t1, nocc=nocc, nvir=nvir) + t2_abab = t_to_c.t2_uhf_abab(c2=c2, t1=t1, nocc=nocc, nvir=nvir) + t2_bbbb = t_to_c.t2_uhf_bbbb(c2=c2, t1=t1, nocc=nocc, nvir=nvir) t2 = SimpleNamespace(aaaa=t2_aaaa, abab=t2_abab, bbbb=t2_bbbb) - t3_aaaaaa = t3_uhf_aaaaaa(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_abaaba = t3_uhf_abaaba(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_abbabb = t3_uhf_abbabb(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_babbab = t3_uhf_babbab(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_bbabba = t3_uhf_bbabba(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_bbbbbb = t3_uhf_bbbbbb(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_aaaaaa = t_to_c.t3_uhf_aaaaaa(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_abaaba = t_to_c.t3_uhf_abaaba(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_abbabb = t_to_c.t3_uhf_abbabb(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_babbab = t_to_c.t3_uhf_babbab(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_bbabba = t_to_c.t3_uhf_bbabba(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) + t3_bbbbbb = t_to_c.t3_uhf_bbbbbb(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) t3 = SimpleNamespace(aaaaaa=t3_aaaaaa, abaaba=t3_abaaba, abbabb=t3_abbabb, babbab=t3_babbab, bbabba=t3_bbabba, bbbbbb=t3_bbbbbb) - t4_aaaaaaaa = t4_uhf_aaaaaaaa(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_aaabaaab = t4_uhf_aaabaaab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_aabaaaba = t4_uhf_aabaaaba(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_abaaabaa = t4_uhf_abaaabaa(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_abababab = t4_uhf_abababab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_abbbabbb = t4_uhf_abbbabbb(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_bbabbbab = t4_uhf_bbabbbab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_bbbabbba = t4_uhf_bbbabbba(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_bbbbbbbb = t4_uhf_bbbbbbbb(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_aaaaaaaa = t_to_c.t4_uhf_aaaaaaaa(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_aaabaaab = t_to_c.t4_uhf_aaabaaab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_aabaaaba = t_to_c.t4_uhf_aabaaaba(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_abaaabaa = t_to_c.t4_uhf_abaaabaa(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_abababab = t_to_c.t4_uhf_abababab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_abbbabbb = t_to_c.t4_uhf_abbbabbb(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_bbabbbab = t_to_c.t4_uhf_bbabbbab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_bbbabbba = t_to_c.t4_uhf_bbbabbba(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) + t4_bbbbbbbb = t_to_c.t4_uhf_bbbbbbbb(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) t1 = (t1_aa, t1_bb) t2 = (t2_aaaa, t2_abab, t2_bbbb) diff --git a/vayesta/core/types/wf/t_to_c.py b/vayesta/core/types/wf/t_to_c.py new file mode 100644 index 000000000..8b7859f8d --- /dev/null +++ b/vayesta/core/types/wf/t_to_c.py @@ -0,0 +1,993 @@ +import numpy as np +from vayesta.core.util import einsum + +def t1_uhf_aa(c1=None, nocc=None, nvir=None): + t1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + t1_aa += einsum("ia->ia", c1.aa) + return t1_aa + +def t1_uhf_bb(c1=None, nocc=None, nvir=None): + t1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + t1_bb += einsum("ia->ia", c1.bb) + return t1_bb + +def t1_rhf(c1=None, nocc=None, nvir=None): + t1 = np.zeros((nocc, nvir), dtype=np.float64) + t1 += einsum("ia->ia", c1) + return t1 + +def t2_uhf_aaaa(c2=None, t1=None, nocc=None, nvir=None): + t2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + t2_aaaa += einsum("ijab->ijab", c2.aaaa) + t2_aaaa += einsum("ib,ja->ijab", t1.aa, t1.aa) + t2_aaaa += einsum("ia,jb->ijab", t1.aa, t1.aa) * -1.0 + return t2_aaaa + +def t2_uhf_abab(c2=None, t1=None, nocc=None, nvir=None): + t2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) + t2_abab += einsum("ijab->ijab", c2.abab) + t2_abab += einsum("ia,jb->ijab", t1.aa, t1.bb) * -1.0 + return t2_abab + +def t2_uhf_baba(c2=None, t1=None, nocc=None, nvir=None): + t2_baba = np.zeros((nocc[1], nocc[0], nvir[1], nvir[0]), dtype=np.float64) + t2_baba += einsum("jiba->ijab", c2.abab) + t2_baba += einsum("jb,ia->ijab", t1.aa, t1.bb) * -1.0 + return t2_baba + +def t2_uhf_bbbb(c2=None, t1=None, nocc=None, nvir=None): + t2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + t2_bbbb += einsum("ijab->ijab", c2.bbbb) + t2_bbbb += einsum("ib,ja->ijab", t1.bb, t1.bb) + t2_bbbb += einsum("ia,jb->ijab", t1.bb, t1.bb) * -1.0 + return t2_bbbb + +def t2_rhf(c2=None, t1=None, nocc=None, nvir=None): + t2 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) + t2 += einsum("ijab->ijab", c2) + t2 += einsum("ia,jb->ijab", t1, t1) * -1.0 + return t2 + +def t3_uhf_aaaaaa(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_aaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + t3_aaaaaa += einsum("ijkabc->ijkabc", c3.aaaaaa) + t3_aaaaaa += einsum("ia,jkbc->ijkabc", t1.aa, t2.aaaa) * -1.0 + t3_aaaaaa += einsum("ic,jkab->ijkabc", t1.aa, t2.aaaa) * -1.0 + t3_aaaaaa += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) + t3_aaaaaa += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) + t3_aaaaaa += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) * -1.0 + t3_aaaaaa += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t3_aaaaaa += einsum("ib,kjca->ijkabc", t1.aa, x0) + t3_aaaaaa += einsum("kb,jica->ijkabc", t1.aa, x0) + t3_aaaaaa += einsum("jb,kica->ijkabc", t1.aa, x0) * -1.0 + return t3_aaaaaa + +def t3_uhf_aabaab(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_aabaab = np.zeros((nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[1]), dtype=np.float64) + t3_aabaab += einsum("ikjacb->ijkabc", c3.abaaba) + t3_aabaab += einsum("ia,jkbc->ijkabc", t1.aa, t2.abab) * -1.0 + t3_aabaab += einsum("ib,jkac->ijkabc", t1.aa, t2.abab) + t3_aabaab += einsum("ja,ikbc->ijkabc", t1.aa, t2.abab) + t3_aabaab += einsum("jb,ikac->ijkabc", t1.aa, t2.abab) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t3_aabaab += einsum("kc,jiba->ijkabc", t1.bb, x0) * -1.0 + return t3_aabaab + +def t3_uhf_abaaba(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_abaaba = np.zeros((nocc[0], nocc[1], nocc[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) + t3_abaaba += einsum("ijkabc->ijkabc", c3.abaaba) + t3_abaaba += einsum("ia,kjcb->ijkabc", t1.aa, t2.abab) * -1.0 + t3_abaaba += einsum("ic,kjab->ijkabc", t1.aa, t2.abab) + t3_abaaba += einsum("ka,ijcb->ijkabc", t1.aa, t2.abab) + t3_abaaba += einsum("kc,ijab->ijkabc", t1.aa, t2.abab) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t3_abaaba += einsum("jb,kica->ijkabc", t1.bb, x0) * -1.0 + return t3_abaaba + +def t3_uhf_abbabb(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_abbabb = np.zeros((nocc[0], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) + t3_abbabb += einsum("jikbac->ijkabc", c3.babbab) + t3_abbabb += einsum("jb,ikac->ijkabc", t1.bb, t2.abab) * -1.0 + t3_abbabb += einsum("jc,ikab->ijkabc", t1.bb, t2.abab) + t3_abbabb += einsum("kb,ijac->ijkabc", t1.bb, t2.abab) + t3_abbabb += einsum("kc,ijab->ijkabc", t1.bb, t2.abab) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t3_abbabb += einsum("ia,kjcb->ijkabc", t1.aa, x0) * -1.0 + return t3_abbabb + +def t3_uhf_baabaa(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_baabaa = np.zeros((nocc[1], nocc[0], nocc[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) + t3_baabaa += einsum("jikbac->ijkabc", c3.abaaba) + t3_baabaa += einsum("jb,kica->ijkabc", t1.aa, t2.abab) * -1.0 + t3_baabaa += einsum("jc,kiba->ijkabc", t1.aa, t2.abab) + t3_baabaa += einsum("kb,jica->ijkabc", t1.aa, t2.abab) + t3_baabaa += einsum("kc,jiba->ijkabc", t1.aa, t2.abab) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t3_baabaa += einsum("ia,kjcb->ijkabc", t1.bb, x0) * -1.0 + return t3_baabaa + +def t3_uhf_babbab(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_babbab = np.zeros((nocc[1], nocc[0], nocc[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t3_babbab += einsum("ijkabc->ijkabc", c3.babbab) + t3_babbab += einsum("ia,jkbc->ijkabc", t1.bb, t2.abab) * -1.0 + t3_babbab += einsum("ic,jkba->ijkabc", t1.bb, t2.abab) + t3_babbab += einsum("ka,jibc->ijkabc", t1.bb, t2.abab) + t3_babbab += einsum("kc,jiba->ijkabc", t1.bb, t2.abab) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t3_babbab += einsum("jb,kica->ijkabc", t1.aa, x0) * -1.0 + return t3_babbab + +def t3_uhf_bbabba(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_bbabba = np.zeros((nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) + t3_bbabba += einsum("ikjacb->ijkabc", c3.babbab) + t3_bbabba += einsum("ia,kjcb->ijkabc", t1.bb, t2.abab) * -1.0 + t3_bbabba += einsum("ib,kjca->ijkabc", t1.bb, t2.abab) + t3_bbabba += einsum("ja,kicb->ijkabc", t1.bb, t2.abab) + t3_bbabba += einsum("jb,kica->ijkabc", t1.bb, t2.abab) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t3_bbabba += einsum("kc,jiba->ijkabc", t1.aa, x0) * -1.0 + return t3_bbabba + +def t3_uhf_bbbbbb(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3_bbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t3_bbbbbb += einsum("ijkabc->ijkabc", c3.bbbbbb) + t3_bbbbbb += einsum("ia,jkbc->ijkabc", t1.bb, t2.bbbb) * -1.0 + t3_bbbbbb += einsum("ic,jkab->ijkabc", t1.bb, t2.bbbb) * -1.0 + t3_bbbbbb += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) + t3_bbbbbb += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) + t3_bbbbbb += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) * -1.0 + t3_bbbbbb += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t3_bbbbbb += einsum("ib,kjca->ijkabc", t1.bb, x0) + t3_bbbbbb += einsum("kb,jica->ijkabc", t1.bb, x0) + t3_bbbbbb += einsum("jb,kica->ijkabc", t1.bb, x0) * -1.0 + return t3_bbbbbb + +def t3_rhf(c3=None, t1=None, t2=None, nocc=None, nvir=None): + t3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) + t3 += einsum("ijkabc->ijkabc", c3) + t3 += einsum("ia,kjcb->ijkabc", t1, t2) * -1.0 + t3 += einsum("ic,kjab->ijkabc", t1, t2) + t3 += einsum("ka,ijcb->ijkabc", t1, t2) + t3 += einsum("kc,ijab->ijkabc", t1, t2) * -1.0 + x0 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) + x0 += einsum("ijab->ijab", t2) * -1.0 + x0 += einsum("ijba->ijab", t2) + x0 += einsum("ib,ja->ijab", t1, t1) + x0 += einsum("ia,jb->ijab", t1, t1) * -1.0 + t3 += einsum("jb,ikca->ijkabc", t1, x0) * -1.0 + return t3 + +def t4_uhf_aaaaaaaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_aaaaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + t4_aaaaaaaa += einsum("ijklabcd->ijklabcd", c4.aaaaaaaa) + t4_aaaaaaaa += einsum("la,ijkbcd->ijklabcd", t1.aa, t3.aaaaaa) + t4_aaaaaaaa += einsum("lb,ijkacd->ijklabcd", t1.aa, t3.aaaaaa) * -1.0 + t4_aaaaaaaa += einsum("lc,ijkabd->ijklabcd", t1.aa, t3.aaaaaa) + t4_aaaaaaaa += einsum("ld,ijkabc->ijklabcd", t1.aa, t3.aaaaaa) * -1.0 + t4_aaaaaaaa += einsum("ilcd,jkab->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ilbd,jkac->ijklabcd", t2.aaaa, t2.aaaa) + t4_aaaaaaaa += einsum("ilad,jkbc->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ilbc,jkad->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ilac,jkbd->ijklabcd", t2.aaaa, t2.aaaa) + t4_aaaaaaaa += einsum("ilab,jkcd->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ikcd,jlab->ijklabcd", t2.aaaa, t2.aaaa) + t4_aaaaaaaa += einsum("ikbd,jlac->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ikad,jlbc->ijklabcd", t2.aaaa, t2.aaaa) + t4_aaaaaaaa += einsum("ikbc,jlad->ijklabcd", t2.aaaa, t2.aaaa) + t4_aaaaaaaa += einsum("ikac,jlbd->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ikab,jlcd->ijklabcd", t2.aaaa, t2.aaaa) + t4_aaaaaaaa += einsum("ijcd,klab->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ijbd,klac->ijklabcd", t2.aaaa, t2.aaaa) + t4_aaaaaaaa += einsum("ijad,klbc->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ijbc,klad->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ijac,klbd->ijklabcd", t2.aaaa, t2.aaaa) + t4_aaaaaaaa += einsum("ijab,klcd->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) + x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) + x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) + x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 + t4_aaaaaaaa += einsum("ib,ljkdac->ijklabcd", t1.aa, x1) + t4_aaaaaaaa += einsum("id,ljkcab->ijklabcd", t1.aa, x1) + t4_aaaaaaaa += einsum("ia,ljkdbc->ijklabcd", t1.aa, x1) * -1.0 + t4_aaaaaaaa += einsum("ic,ljkdab->ijklabcd", t1.aa, x1) * -1.0 + x2 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("ijkabc->ijkabc", t3.aaaaaa) + x2 += einsum("ia,jkbc->ijkabc", t1.aa, t2.aaaa) + x2 += einsum("ib,jkac->ijkabc", t1.aa, t2.aaaa) * -1.0 + x2 += einsum("ic,jkab->ijkabc", t1.aa, t2.aaaa) + x2 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) + x2 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 + x2 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) + t4_aaaaaaaa += einsum("ja,likdbc->ijklabcd", t1.aa, x2) + t4_aaaaaaaa += einsum("jc,likdab->ijklabcd", t1.aa, x2) + t4_aaaaaaaa += einsum("jb,likdac->ijklabcd", t1.aa, x2) * -1.0 + t4_aaaaaaaa += einsum("jd,likcab->ijklabcd", t1.aa, x2) * -1.0 + x3 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + x3 += einsum("ijkabc->ijkabc", t3.aaaaaa) + x3 += einsum("ia,jkbc->ijkabc", t1.aa, t2.aaaa) + x3 += einsum("ib,jkac->ijkabc", t1.aa, t2.aaaa) * -1.0 + x3 += einsum("ic,jkab->ijkabc", t1.aa, t2.aaaa) + t4_aaaaaaaa += einsum("kb,lijdac->ijklabcd", t1.aa, x3) + t4_aaaaaaaa += einsum("kd,lijcab->ijklabcd", t1.aa, x3) + t4_aaaaaaaa += einsum("ka,lijdbc->ijklabcd", t1.aa, x3) * -1.0 + t4_aaaaaaaa += einsum("kc,lijdab->ijklabcd", t1.aa, x3) * -1.0 + return t4_aaaaaaaa + +def t4_uhf_aaabaaab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_aaabaaab = np.zeros((nocc[0], nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[0], nvir[1]), dtype=np.float64) + t4_aaabaaab += einsum("ijklabcd->ijklabcd", c4.aaabaaab) + t4_aaabaaab += einsum("ia,jlkbdc->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_aaabaaab += einsum("ic,jlkadb->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_aaabaaab += einsum("ja,ilkbdc->ijklabcd", t1.aa, t3.abaaba) + t4_aaabaaab += einsum("jc,ilkadb->ijklabcd", t1.aa, t3.abaaba) + t4_aaabaaab += einsum("ka,iljbdc->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_aaabaaab += einsum("kc,iljadb->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_aaabaaab += einsum("klcd,ijab->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_aaabaaab += einsum("klad,ijbc->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_aaabaaab += einsum("jlcd,ikab->ijklabcd", t2.abab, t2.aaaa) + t4_aaabaaab += einsum("jlad,ikbc->ijklabcd", t2.abab, t2.aaaa) + t4_aaabaaab += einsum("ilcd,jkab->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_aaabaaab += einsum("ilad,jkbc->ijklabcd", t2.abab, t2.aaaa) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t4_aaabaaab += einsum("ilbd,kjca->ijklabcd", t2.abab, x0) + t4_aaabaaab += einsum("klbd,jica->ijklabcd", t2.abab, x0) + t4_aaabaaab += einsum("jlbd,kica->ijklabcd", t2.abab, x0) * -1.0 + x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) + x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) + x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) + x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 + t4_aaabaaab += einsum("ld,kijcab->ijklabcd", t1.bb, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_aaabaaab += einsum("ib,ldkjca->ijklabcd", t1.aa, x2) + t4_aaabaaab += einsum("kb,ldjica->ijklabcd", t1.aa, x2) + t4_aaabaaab += einsum("jb,ldkica->ijklabcd", t1.aa, x2) * -1.0 + return t4_aaabaaab + +def t4_uhf_aabaaaba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_aabaaaba = np.zeros((nocc[0], nocc[0], nocc[1], nocc[0], nvir[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) + t4_aabaaaba += einsum("ijlkabdc->ijklabcd", c4.aaabaaab) + t4_aabaaaba += einsum("ia,jklbcd->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_aabaaaba += einsum("id,jklacb->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_aabaaaba += einsum("ja,iklbcd->ijklabcd", t1.aa, t3.abaaba) + t4_aabaaaba += einsum("jd,iklacb->ijklabcd", t1.aa, t3.abaaba) + t4_aabaaaba += einsum("la,ikjbcd->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_aabaaaba += einsum("ld,ikjacb->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_aabaaaba += einsum("lkdc,ijab->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_aabaaaba += einsum("lkac,ijbd->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_aabaaaba += einsum("jkdc,ilab->ijklabcd", t2.abab, t2.aaaa) + t4_aabaaaba += einsum("jkac,ilbd->ijklabcd", t2.abab, t2.aaaa) + t4_aabaaaba += einsum("ikdc,jlab->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_aabaaaba += einsum("ikac,jlbd->ijklabcd", t2.abab, t2.aaaa) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t4_aabaaaba += einsum("ikbc,ljda->ijklabcd", t2.abab, x0) + t4_aabaaaba += einsum("lkbc,jida->ijklabcd", t2.abab, x0) + t4_aabaaaba += einsum("jkbc,lida->ijklabcd", t2.abab, x0) * -1.0 + x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) + x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) + x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) + x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 + t4_aabaaaba += einsum("kc,lijdab->ijklabcd", t1.bb, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_aabaaaba += einsum("ib,kcljda->ijklabcd", t1.aa, x2) + t4_aabaaaba += einsum("lb,kcjida->ijklabcd", t1.aa, x2) + t4_aabaaaba += einsum("jb,kclida->ijklabcd", t1.aa, x2) * -1.0 + return t4_aabaaaba + +def t4_uhf_aabbaabb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_aabbaabb = np.zeros((nocc[0], nocc[0], nocc[1], nocc[1], nvir[0], nvir[0], nvir[1], nvir[1]), dtype=np.float64) + t4_aabbaabb += einsum("ikjlacbd->ijklabcd", c4.abababab) + t4_aabbaabb += einsum("ia,kjlcbd->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_aabbaabb += einsum("ib,kjlcad->ijklabcd", t1.aa, t3.babbab) + t4_aabbaabb += einsum("ja,kilcbd->ijklabcd", t1.aa, t3.babbab) + t4_aabbaabb += einsum("jb,kilcad->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_aabbaabb += einsum("ilac,jkbd->ijklabcd", t2.abab, t2.abab) + t4_aabbaabb += einsum("ilbc,jkad->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_aabbaabb += einsum("ikbd,jlac->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_aabbaabb += einsum("ikad,jlbc->ijklabcd", t2.abab, t2.abab) + t4_aabbaabb += einsum("ilad,jkbc->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_aabbaabb += einsum("ilbd,jkac->ijklabcd", t2.abab, t2.abab) + t4_aabbaabb += einsum("ikbc,jlad->ijklabcd", t2.abab, t2.abab) + t4_aabbaabb += einsum("ikac,jlbd->ijklabcd", t2.abab, t2.abab) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("ijab->ijab", t2.bbbb) + x1 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x1 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t4_aabbaabb += einsum("jiba,lkdc->ijklabcd", x0, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_aabbaabb += einsum("kd,lcjiba->ijklabcd", t1.bb, x2) + t4_aabbaabb += einsum("lc,kdjiba->ijklabcd", t1.bb, x2) + t4_aabbaabb += einsum("kc,ldjiba->ijklabcd", t1.bb, x2) * -1.0 + t4_aabbaabb += einsum("ld,kcjiba->ijklabcd", t1.bb, x2) * -1.0 + return t4_aabbaabb + +def t4_uhf_abaaabaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_abaaabaa = np.zeros((nocc[0], nocc[1], nocc[0], nocc[0], nvir[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) + t4_abaaabaa += einsum("ikljacdb->ijklabcd", c4.aaabaaab) + t4_abaaabaa += einsum("ia,kjlcbd->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_abaaabaa += einsum("id,kjlabc->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_abaaabaa += einsum("ka,ijlcbd->ijklabcd", t1.aa, t3.abaaba) + t4_abaaabaa += einsum("kd,ijlabc->ijklabcd", t1.aa, t3.abaaba) + t4_abaaabaa += einsum("la,ijkcbd->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_abaaabaa += einsum("ld,ijkabc->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_abaaabaa += einsum("ljdb,ikac->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_abaaabaa += einsum("ljab,ikcd->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_abaaabaa += einsum("kjdb,ilac->ijklabcd", t2.abab, t2.aaaa) + t4_abaaabaa += einsum("kjab,ilcd->ijklabcd", t2.abab, t2.aaaa) + t4_abaaabaa += einsum("ijdb,klac->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_abaaabaa += einsum("ijab,klcd->ijklabcd", t2.abab, t2.aaaa) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t4_abaaabaa += einsum("ijcb,lkda->ijklabcd", t2.abab, x0) + t4_abaaabaa += einsum("ljcb,kida->ijklabcd", t2.abab, x0) + t4_abaaabaa += einsum("kjcb,lida->ijklabcd", t2.abab, x0) * -1.0 + x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) + x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) + x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) + x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 + t4_abaaabaa += einsum("jb,likdac->ijklabcd", t1.bb, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_abaaabaa += einsum("ic,jblkda->ijklabcd", t1.aa, x2) + t4_abaaabaa += einsum("lc,jbkida->ijklabcd", t1.aa, x2) + t4_abaaabaa += einsum("kc,jblida->ijklabcd", t1.aa, x2) * -1.0 + return t4_abaaabaa + +def t4_uhf_abababab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_abababab = np.zeros((nocc[0], nocc[1], nocc[0], nocc[1], nvir[0], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t4_abababab += einsum("ijklabcd->ijklabcd", c4.abababab) + t4_abababab += einsum("ia,jklbcd->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_abababab += einsum("ic,jklbad->ijklabcd", t1.aa, t3.babbab) + t4_abababab += einsum("ka,jilbcd->ijklabcd", t1.aa, t3.babbab) + t4_abababab += einsum("kc,jilbad->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_abababab += einsum("ilab,kjcd->ijklabcd", t2.abab, t2.abab) + t4_abababab += einsum("ilcb,kjad->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_abababab += einsum("ijcd,klab->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_abababab += einsum("ijad,klcb->ijklabcd", t2.abab, t2.abab) + t4_abababab += einsum("ilad,kjcb->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_abababab += einsum("ilcd,kjab->ijklabcd", t2.abab, t2.abab) + t4_abababab += einsum("ijcb,klad->ijklabcd", t2.abab, t2.abab) + t4_abababab += einsum("ijab,klcd->ijklabcd", t2.abab, t2.abab) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("ijab->ijab", t2.bbbb) + x1 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x1 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t4_abababab += einsum("kica,ljdb->ijklabcd", x0, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_abababab += einsum("jd,lbkica->ijklabcd", t1.bb, x2) + t4_abababab += einsum("lb,jdkica->ijklabcd", t1.bb, x2) + t4_abababab += einsum("jb,ldkica->ijklabcd", t1.bb, x2) * -1.0 + t4_abababab += einsum("ld,jbkica->ijklabcd", t1.bb, x2) * -1.0 + return t4_abababab + +def t4_uhf_abbaabba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_abbaabba = np.zeros((nocc[0], nocc[1], nocc[1], nocc[0], nvir[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) + t4_abbaabba += einsum("ijlkabdc->ijklabcd", c4.abababab) + t4_abbaabba += einsum("ia,jlkbdc->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_abbaabba += einsum("id,jlkbac->ijklabcd", t1.aa, t3.babbab) + t4_abbaabba += einsum("la,jikbdc->ijklabcd", t1.aa, t3.babbab) + t4_abbaabba += einsum("ld,jikbac->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_abbaabba += einsum("ikab,ljdc->ijklabcd", t2.abab, t2.abab) + t4_abbaabba += einsum("ikdb,ljac->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_abbaabba += einsum("ijdc,lkab->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_abbaabba += einsum("ijac,lkdb->ijklabcd", t2.abab, t2.abab) + t4_abbaabba += einsum("ikac,ljdb->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_abbaabba += einsum("ikdc,ljab->ijklabcd", t2.abab, t2.abab) + t4_abbaabba += einsum("ijdb,lkac->ijklabcd", t2.abab, t2.abab) + t4_abbaabba += einsum("ijab,lkdc->ijklabcd", t2.abab, t2.abab) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("ijab->ijab", t2.aaaa) + x1 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x1 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t4_abbaabba += einsum("kjcb,lida->ijklabcd", x0, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_abbaabba += einsum("jc,kblida->ijklabcd", t1.bb, x2) + t4_abbaabba += einsum("kb,jclida->ijklabcd", t1.bb, x2) + t4_abbaabba += einsum("jb,kclida->ijklabcd", t1.bb, x2) * -1.0 + t4_abbaabba += einsum("kc,jblida->ijklabcd", t1.bb, x2) * -1.0 + return t4_abbaabba + +def t4_uhf_abbbabbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_abbbabbb = np.zeros((nocc[0], nocc[1], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t4_abbbabbb += einsum("ijklabcd->ijklabcd", c4.abbbabbb) + t4_abbbabbb += einsum("jb,kilcad->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_abbbabbb += einsum("jd,kilbac->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_abbbabbb += einsum("kb,jilcad->ijklabcd", t1.bb, t3.babbab) + t4_abbbabbb += einsum("kd,jilbac->ijklabcd", t1.bb, t3.babbab) + t4_abbbabbb += einsum("lb,jikcad->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_abbbabbb += einsum("ld,jikbac->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_abbbabbb += einsum("ilad,jkbc->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_abbbabbb += einsum("ilab,jkcd->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_abbbabbb += einsum("ikad,jlbc->ijklabcd", t2.abab, t2.bbbb) + t4_abbbabbb += einsum("ikab,jlcd->ijklabcd", t2.abab, t2.bbbb) + t4_abbbabbb += einsum("ijad,klbc->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_abbbabbb += einsum("ijab,klcd->ijklabcd", t2.abab, t2.bbbb) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t4_abbbabbb += einsum("ilac,kjdb->ijklabcd", t2.abab, x0) + t4_abbbabbb += einsum("ijac,lkdb->ijklabcd", t2.abab, x0) + t4_abbbabbb += einsum("ikac,ljdb->ijklabcd", t2.abab, x0) * -1.0 + x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) + x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) + x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) + x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 + t4_abbbabbb += einsum("ia,ljkdbc->ijklabcd", t1.aa, x1) * -1.0 + x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1], nocc[0], nvir[0]), dtype=np.float64) + x2 += einsum("ikjacb->ijabkc", t3.babbab) + x2 += einsum("ia,kjcb->ijabkc", t1.bb, t2.abab) + x2 += einsum("ib,kjca->ijabkc", t1.bb, t2.abab) * -1.0 + x2 += einsum("ja,kicb->ijabkc", t1.bb, t2.abab) * -1.0 + x2 += einsum("jb,kica->ijabkc", t1.bb, t2.abab) + t4_abbbabbb += einsum("jc,lkdbia->ijklabcd", t1.bb, x2) + t4_abbbabbb += einsum("lc,kjdbia->ijklabcd", t1.bb, x2) + t4_abbbabbb += einsum("kc,ljdbia->ijklabcd", t1.bb, x2) * -1.0 + return t4_abbbabbb + +def t4_uhf_baaabaaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_baaabaaa = np.zeros((nocc[1], nocc[0], nocc[0], nocc[0], nvir[1], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + t4_baaabaaa += einsum("jklibcda->ijklabcd", c4.aaabaaab) + t4_baaabaaa += einsum("jb,kilcad->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_baaabaaa += einsum("jd,kilbac->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_baaabaaa += einsum("kb,jilcad->ijklabcd", t1.aa, t3.abaaba) + t4_baaabaaa += einsum("kd,jilbac->ijklabcd", t1.aa, t3.abaaba) + t4_baaabaaa += einsum("lb,jikcad->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_baaabaaa += einsum("ld,jikbac->ijklabcd", t1.aa, t3.abaaba) * -1.0 + t4_baaabaaa += einsum("lida,jkbc->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_baaabaaa += einsum("liba,jkcd->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_baaabaaa += einsum("kida,jlbc->ijklabcd", t2.abab, t2.aaaa) + t4_baaabaaa += einsum("kiba,jlcd->ijklabcd", t2.abab, t2.aaaa) + t4_baaabaaa += einsum("jida,klbc->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_baaabaaa += einsum("jiba,klcd->ijklabcd", t2.abab, t2.aaaa) * -1.0 + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t4_baaabaaa += einsum("jica,lkdb->ijklabcd", t2.abab, x0) + t4_baaabaaa += einsum("lica,kjdb->ijklabcd", t2.abab, x0) + t4_baaabaaa += einsum("kica,ljdb->ijklabcd", t2.abab, x0) * -1.0 + x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) + x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) + x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) + x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) + x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 + t4_baaabaaa += einsum("ia,ljkdbc->ijklabcd", t1.bb, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_baaabaaa += einsum("jc,ialkdb->ijklabcd", t1.aa, x2) + t4_baaabaaa += einsum("lc,iakjdb->ijklabcd", t1.aa, x2) + t4_baaabaaa += einsum("kc,ialjdb->ijklabcd", t1.aa, x2) * -1.0 + return t4_baaabaaa + +def t4_uhf_baabbaab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_baabbaab = np.zeros((nocc[1], nocc[0], nocc[0], nocc[1], nvir[1], nvir[0], nvir[0], nvir[1]), dtype=np.float64) + t4_baabbaab += einsum("jiklbacd->ijklabcd", c4.abababab) + t4_baabbaab += einsum("jb,iklacd->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_baabbaab += einsum("jc,iklabd->ijklabcd", t1.aa, t3.babbab) + t4_baabbaab += einsum("kb,ijlacd->ijklabcd", t1.aa, t3.babbab) + t4_baabbaab += einsum("kc,ijlabd->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_baabbaab += einsum("jiba,klcd->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_baabbaab += einsum("jica,klbd->ijklabcd", t2.abab, t2.abab) + t4_baabbaab += einsum("jlcd,kiba->ijklabcd", t2.abab, t2.abab) + t4_baabbaab += einsum("jlbd,kica->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_baabbaab += einsum("jibd,klca->ijklabcd", t2.abab, t2.abab) + t4_baabbaab += einsum("jicd,klba->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_baabbaab += einsum("jlca,kibd->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_baabbaab += einsum("jlba,kicd->ijklabcd", t2.abab, t2.abab) + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.aaaa) + x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("ijab->ijab", t2.bbbb) + x1 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x1 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t4_baabbaab += einsum("kjcb,lida->ijklabcd", x0, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_baabbaab += einsum("id,lakjcb->ijklabcd", t1.bb, x2) + t4_baabbaab += einsum("la,idkjcb->ijklabcd", t1.bb, x2) + t4_baabbaab += einsum("ia,ldkjcb->ijklabcd", t1.bb, x2) * -1.0 + t4_baabbaab += einsum("ld,iakjcb->ijklabcd", t1.bb, x2) * -1.0 + return t4_baabbaab + +def t4_uhf_babababa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_babababa = np.zeros((nocc[1], nocc[0], nocc[1], nocc[0], nvir[1], nvir[0], nvir[1], nvir[0]), dtype=np.float64) + t4_babababa += einsum("jilkbadc->ijklabcd", c4.abababab) + t4_babababa += einsum("jb,ilkadc->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_babababa += einsum("jd,ilkabc->ijklabcd", t1.aa, t3.babbab) + t4_babababa += einsum("lb,ijkadc->ijklabcd", t1.aa, t3.babbab) + t4_babababa += einsum("ld,ijkabc->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_babababa += einsum("jiba,lkdc->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_babababa += einsum("jida,lkbc->ijklabcd", t2.abab, t2.abab) + t4_babababa += einsum("jkdc,liba->ijklabcd", t2.abab, t2.abab) + t4_babababa += einsum("jkbc,lida->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_babababa += einsum("jibc,lkda->ijklabcd", t2.abab, t2.abab) + t4_babababa += einsum("jidc,lkba->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_babababa += einsum("jkda,libc->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_babababa += einsum("jkba,lidc->ijklabcd", t2.abab, t2.abab) + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("ijab->ijab", t2.aaaa) + x1 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x1 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t4_babababa += einsum("kica,ljdb->ijklabcd", x0, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_babababa += einsum("ic,kaljdb->ijklabcd", t1.bb, x2) + t4_babababa += einsum("ka,icljdb->ijklabcd", t1.bb, x2) + t4_babababa += einsum("ia,kcljdb->ijklabcd", t1.bb, x2) * -1.0 + t4_babababa += einsum("kc,ialjdb->ijklabcd", t1.bb, x2) * -1.0 + return t4_babababa + +def t4_uhf_babbbabb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_babbbabb = np.zeros((nocc[1], nocc[0], nocc[1], nocc[1], nvir[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) + t4_babbbabb += einsum("jiklbacd->ijklabcd", c4.abbbabbb) + t4_babbbabb += einsum("ia,kjlcbd->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_babbbabb += einsum("id,kjlabc->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_babbbabb += einsum("ka,ijlcbd->ijklabcd", t1.bb, t3.babbab) + t4_babbbabb += einsum("kd,ijlabc->ijklabcd", t1.bb, t3.babbab) + t4_babbbabb += einsum("la,ijkcbd->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_babbbabb += einsum("ld,ijkabc->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_babbbabb += einsum("jlbd,ikac->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_babbbabb += einsum("jlba,ikcd->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_babbbabb += einsum("jkbd,ilac->ijklabcd", t2.abab, t2.bbbb) + t4_babbbabb += einsum("jkba,ilcd->ijklabcd", t2.abab, t2.bbbb) + t4_babbbabb += einsum("jibd,klac->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_babbbabb += einsum("jiba,klcd->ijklabcd", t2.abab, t2.bbbb) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t4_babbbabb += einsum("jlbc,kida->ijklabcd", t2.abab, x0) + t4_babbbabb += einsum("jibc,lkda->ijklabcd", t2.abab, x0) + t4_babbbabb += einsum("jkbc,lida->ijklabcd", t2.abab, x0) * -1.0 + x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) + x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) + x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) + x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 + t4_babbbabb += einsum("jb,likdac->ijklabcd", t1.aa, x1) * -1.0 + x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1], nocc[0], nvir[0]), dtype=np.float64) + x2 += einsum("ikjacb->ijabkc", t3.babbab) + x2 += einsum("ia,kjcb->ijabkc", t1.bb, t2.abab) + x2 += einsum("ib,kjca->ijabkc", t1.bb, t2.abab) * -1.0 + x2 += einsum("ja,kicb->ijabkc", t1.bb, t2.abab) * -1.0 + x2 += einsum("jb,kica->ijabkc", t1.bb, t2.abab) + t4_babbbabb += einsum("ic,lkdajb->ijklabcd", t1.bb, x2) + t4_babbbabb += einsum("lc,kidajb->ijklabcd", t1.bb, x2) + t4_babbbabb += einsum("kc,lidajb->ijklabcd", t1.bb, x2) * -1.0 + return t4_babbbabb + +def t4_uhf_bbaabbaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_bbaabbaa = np.zeros((nocc[1], nocc[1], nocc[0], nocc[0], nvir[1], nvir[1], nvir[0], nvir[0]), dtype=np.float64) + t4_bbaabbaa += einsum("kiljcadb->ijklabcd", c4.abababab) + t4_bbaabbaa += einsum("kc,iljadb->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_bbaabbaa += einsum("kd,iljacb->ijklabcd", t1.aa, t3.babbab) + t4_bbaabbaa += einsum("lc,ikjadb->ijklabcd", t1.aa, t3.babbab) + t4_bbaabbaa += einsum("ld,ikjacb->ijklabcd", t1.aa, t3.babbab) * -1.0 + t4_bbaabbaa += einsum("kica,ljdb->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_bbaabbaa += einsum("kida,ljcb->ijklabcd", t2.abab, t2.abab) + t4_bbaabbaa += einsum("kjdb,lica->ijklabcd", t2.abab, t2.abab) + t4_bbaabbaa += einsum("kjcb,lida->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_bbaabbaa += einsum("kicb,ljda->ijklabcd", t2.abab, t2.abab) + t4_bbaabbaa += einsum("kidb,ljca->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_bbaabbaa += einsum("kjda,licb->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_bbaabbaa += einsum("kjca,lidb->ijklabcd", t2.abab, t2.abab) + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("ijab->ijab", t2.aaaa) + x1 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 + x1 += einsum("ia,jb->ijab", t1.aa, t1.aa) + t4_bbaabbaa += einsum("jiba,lkdc->ijklabcd", x0, x1) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("jikbac->iajkbc", t3.abaaba) + x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) + x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) + t4_bbaabbaa += einsum("ib,jalkdc->ijklabcd", t1.bb, x2) + t4_bbaabbaa += einsum("ja,iblkdc->ijklabcd", t1.bb, x2) + t4_bbaabbaa += einsum("ia,jblkdc->ijklabcd", t1.bb, x2) * -1.0 + t4_bbaabbaa += einsum("jb,ialkdc->ijklabcd", t1.bb, x2) * -1.0 + return t4_bbaabbaa + +def t4_uhf_bbabbbab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_bbabbbab = np.zeros((nocc[1], nocc[1], nocc[0], nocc[1], nvir[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) + t4_bbabbbab += einsum("kijlcabd->ijklabcd", c4.abbbabbb) + t4_bbabbbab += einsum("ia,jklbcd->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_bbabbbab += einsum("id,jklacb->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_bbabbbab += einsum("ja,iklbcd->ijklabcd", t1.bb, t3.babbab) + t4_bbabbbab += einsum("jd,iklacb->ijklabcd", t1.bb, t3.babbab) + t4_bbabbbab += einsum("la,ikjbcd->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_bbabbbab += einsum("ld,ikjacb->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_bbabbbab += einsum("klcd,ijab->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_bbabbbab += einsum("klca,ijbd->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_bbabbbab += einsum("kjcd,ilab->ijklabcd", t2.abab, t2.bbbb) + t4_bbabbbab += einsum("kjca,ilbd->ijklabcd", t2.abab, t2.bbbb) + t4_bbabbbab += einsum("kicd,jlab->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_bbabbbab += einsum("kica,jlbd->ijklabcd", t2.abab, t2.bbbb) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t4_bbabbbab += einsum("klcb,jida->ijklabcd", t2.abab, x0) + t4_bbabbbab += einsum("kicb,ljda->ijklabcd", t2.abab, x0) + t4_bbabbbab += einsum("kjcb,lida->ijklabcd", t2.abab, x0) * -1.0 + x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) + x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) + x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) + x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 + t4_bbabbbab += einsum("kc,lijdab->ijklabcd", t1.aa, x1) * -1.0 + x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1], nocc[0], nvir[0]), dtype=np.float64) + x2 += einsum("ikjacb->ijabkc", t3.babbab) + x2 += einsum("ia,kjcb->ijabkc", t1.bb, t2.abab) + x2 += einsum("ib,kjca->ijabkc", t1.bb, t2.abab) * -1.0 + x2 += einsum("ja,kicb->ijabkc", t1.bb, t2.abab) * -1.0 + x2 += einsum("jb,kica->ijabkc", t1.bb, t2.abab) + t4_bbabbbab += einsum("ib,ljdakc->ijklabcd", t1.bb, x2) + t4_bbabbbab += einsum("lb,jidakc->ijklabcd", t1.bb, x2) + t4_bbabbbab += einsum("jb,lidakc->ijklabcd", t1.bb, x2) * -1.0 + return t4_bbabbbab + +def t4_uhf_bbbabbba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_bbbabbba = np.zeros((nocc[1], nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[1], nvir[0]), dtype=np.float64) + t4_bbbabbba += einsum("lijkdabc->ijklabcd", c4.abbbabbb) + t4_bbbabbba += einsum("ia,jlkbdc->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_bbbabbba += einsum("ic,jlkadb->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_bbbabbba += einsum("ja,ilkbdc->ijklabcd", t1.bb, t3.babbab) + t4_bbbabbba += einsum("jc,ilkadb->ijklabcd", t1.bb, t3.babbab) + t4_bbbabbba += einsum("ka,iljbdc->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_bbbabbba += einsum("kc,iljadb->ijklabcd", t1.bb, t3.babbab) * -1.0 + t4_bbbabbba += einsum("lkdc,ijab->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_bbbabbba += einsum("lkda,ijbc->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_bbbabbba += einsum("ljdc,ikab->ijklabcd", t2.abab, t2.bbbb) + t4_bbbabbba += einsum("ljda,ikbc->ijklabcd", t2.abab, t2.bbbb) + t4_bbbabbba += einsum("lidc,jkab->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_bbbabbba += einsum("lida,jkbc->ijklabcd", t2.abab, t2.bbbb) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + t4_bbbabbba += einsum("lkdb,jica->ijklabcd", t2.abab, x0) + t4_bbbabbba += einsum("lidb,kjca->ijklabcd", t2.abab, x0) + t4_bbbabbba += einsum("ljdb,kica->ijklabcd", t2.abab, x0) * -1.0 + x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) + x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) + x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) + x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 + t4_bbbabbba += einsum("ld,kijcab->ijklabcd", t1.aa, x1) * -1.0 + x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1], nocc[0], nvir[0]), dtype=np.float64) + x2 += einsum("ikjacb->ijabkc", t3.babbab) + x2 += einsum("ia,kjcb->ijabkc", t1.bb, t2.abab) + x2 += einsum("ib,kjca->ijabkc", t1.bb, t2.abab) * -1.0 + x2 += einsum("ja,kicb->ijabkc", t1.bb, t2.abab) * -1.0 + x2 += einsum("jb,kica->ijabkc", t1.bb, t2.abab) + t4_bbbabbba += einsum("ib,kjcald->ijklabcd", t1.bb, x2) + t4_bbbabbba += einsum("kb,jicald->ijklabcd", t1.bb, x2) + t4_bbbabbba += einsum("jb,kicald->ijklabcd", t1.bb, x2) * -1.0 + return t4_bbbabbba + +def t4_uhf_bbbbbbbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4_bbbbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + t4_bbbbbbbb += einsum("ijklabcd->ijklabcd", c4.bbbbbbbb) + t4_bbbbbbbb += einsum("la,ijkbcd->ijklabcd", t1.bb, t3.bbbbbb) + t4_bbbbbbbb += einsum("lb,ijkacd->ijklabcd", t1.bb, t3.bbbbbb) * -1.0 + t4_bbbbbbbb += einsum("lc,ijkabd->ijklabcd", t1.bb, t3.bbbbbb) + t4_bbbbbbbb += einsum("ld,ijkabc->ijklabcd", t1.bb, t3.bbbbbb) * -1.0 + t4_bbbbbbbb += einsum("ilcd,jkab->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ilbd,jkac->ijklabcd", t2.bbbb, t2.bbbb) + t4_bbbbbbbb += einsum("ilad,jkbc->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ilbc,jkad->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ilac,jkbd->ijklabcd", t2.bbbb, t2.bbbb) + t4_bbbbbbbb += einsum("ilab,jkcd->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ikcd,jlab->ijklabcd", t2.bbbb, t2.bbbb) + t4_bbbbbbbb += einsum("ikbd,jlac->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ikad,jlbc->ijklabcd", t2.bbbb, t2.bbbb) + t4_bbbbbbbb += einsum("ikbc,jlad->ijklabcd", t2.bbbb, t2.bbbb) + t4_bbbbbbbb += einsum("ikac,jlbd->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ikab,jlcd->ijklabcd", t2.bbbb, t2.bbbb) + t4_bbbbbbbb += einsum("ijcd,klab->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ijbd,klac->ijklabcd", t2.bbbb, t2.bbbb) + t4_bbbbbbbb += einsum("ijad,klbc->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ijbc,klad->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ijac,klbd->ijklabcd", t2.bbbb, t2.bbbb) + t4_bbbbbbbb += einsum("ijab,klcd->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("ijab->ijab", t2.bbbb) + x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) + x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) + x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) + x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) + x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 + t4_bbbbbbbb += einsum("ib,ljkdac->ijklabcd", t1.bb, x1) + t4_bbbbbbbb += einsum("id,ljkcab->ijklabcd", t1.bb, x1) + t4_bbbbbbbb += einsum("ia,ljkdbc->ijklabcd", t1.bb, x1) * -1.0 + t4_bbbbbbbb += einsum("ic,ljkdab->ijklabcd", t1.bb, x1) * -1.0 + x2 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + x2 += einsum("ijkabc->ijkabc", t3.bbbbbb) + x2 += einsum("ia,jkbc->ijkabc", t1.bb, t2.bbbb) + x2 += einsum("ib,jkac->ijkabc", t1.bb, t2.bbbb) * -1.0 + x2 += einsum("ic,jkab->ijkabc", t1.bb, t2.bbbb) + x2 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) + x2 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 + x2 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) + t4_bbbbbbbb += einsum("ja,likdbc->ijklabcd", t1.bb, x2) + t4_bbbbbbbb += einsum("jc,likdab->ijklabcd", t1.bb, x2) + t4_bbbbbbbb += einsum("jb,likdac->ijklabcd", t1.bb, x2) * -1.0 + t4_bbbbbbbb += einsum("jd,likcab->ijklabcd", t1.bb, x2) * -1.0 + x3 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) + x3 += einsum("ijkabc->ijkabc", t3.bbbbbb) + x3 += einsum("ia,jkbc->ijkabc", t1.bb, t2.bbbb) + x3 += einsum("ib,jkac->ijkabc", t1.bb, t2.bbbb) * -1.0 + x3 += einsum("ic,jkab->ijkabc", t1.bb, t2.bbbb) + t4_bbbbbbbb += einsum("kb,lijdac->ijklabcd", t1.bb, x3) + t4_bbbbbbbb += einsum("kd,lijcab->ijklabcd", t1.bb, x3) + t4_bbbbbbbb += einsum("ka,lijdbc->ijklabcd", t1.bb, x3) * -1.0 + t4_bbbbbbbb += einsum("kc,lijdab->ijklabcd", t1.bb, x3) * -1.0 + return t4_bbbbbbbb + +def t4_rhf_abab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) + t4 += einsum("ijklabcd->ijklabcd", c4) + t4 += einsum("jb,ilkadc->ijklabcd", t1, t3) * -1.0 + t4 += einsum("jd,ilkabc->ijklabcd", t1, t3) + t4 += einsum("lb,ijkadc->ijklabcd", t1, t3) + t4 += einsum("ld,ijkabc->ijklabcd", t1, t3) * -1.0 + t4 += einsum("ijab,klcd->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ijad,klcb->ijklabcd", t2, t2) + t4 += einsum("ijcb,klad->ijklabcd", t2, t2) + t4 += einsum("ijcd,klab->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ilab,kjcd->ijklabcd", t2, t2) + t4 += einsum("ilad,kjcb->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ilcb,kjad->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ilcd,kjab->ijklabcd", t2, t2) + x0 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) + x0 += einsum("ijab->ijab", t2) * -1.0 + x0 += einsum("ijba->ijab", t2) + x0 += einsum("ib,ja->ijab", t1, t1) + x0 += einsum("ia,jb->ijab", t1, t1) * -1.0 + t4 += einsum("ikac,jldb->ijklabcd", x0, x0) + x1 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) + x1 += einsum("ijkabc->ijkabc", t3) + x1 += einsum("ia,jkbc->ijkabc", t1, t2) + x1 += einsum("ic,jkba->ijkabc", t1, t2) * -1.0 + x1 += einsum("ka,jibc->ijkabc", t1, t2) * -1.0 + x1 += einsum("kc,jiba->ijkabc", t1, t2) + t4 += einsum("ic,jklbad->ijklabcd", t1, x1) + t4 += einsum("ka,jilbcd->ijklabcd", t1, x1) + t4 += einsum("ia,jklbcd->ijklabcd", t1, x1) * -1.0 + t4 += einsum("kc,jilbad->ijklabcd", t1, x1) * -1.0 + return t4 + +def t4_rhf_abaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) + t4 += einsum("ikljacdb->ijklabcd", c4) + t4 += einsum("ia,kjlcbd->ijklabcd", t1, t3) * -1.0 + t4 += einsum("id,kjlabc->ijklabcd", t1, t3) * -1.0 + t4 += einsum("ka,ijlcbd->ijklabcd", t1, t3) + t4 += einsum("kd,ijlabc->ijklabcd", t1, t3) + t4 += einsum("la,ijkcbd->ijklabcd", t1, t3) * -1.0 + t4 += einsum("ld,ijkabc->ijklabcd", t1, t3) * -1.0 + t4 += einsum("ijab,klcd->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ijab,kldc->ijklabcd", t2, t2) + t4 += einsum("ijdb,klac->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ijdb,klca->ijklabcd", t2, t2) + t4 += einsum("ilac,kjdb->ijklabcd", t2, t2) + t4 += einsum("ilcd,kjab->ijklabcd", t2, t2) + t4 += einsum("ilca,kjdb->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ildc,kjab->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ikac,ljdb->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ikcd,ljab->ijklabcd", t2, t2) * -1.0 + t4 += einsum("ikca,ljdb->ijklabcd", t2, t2) + t4 += einsum("ikdc,ljab->ijklabcd", t2, t2) + x0 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) + x0 += einsum("ijab->ijab", t2) * -1.0 + x0 += einsum("ijba->ijab", t2) + x0 += einsum("ib,ja->ijab", t1, t1) + x0 += einsum("ia,jb->ijab", t1, t1) * -1.0 + t4 += einsum("kjcb,ilda->ijklabcd", t2, x0) * -1.0 + x1 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) + x1 += einsum("ijab->ijab", t2) + x1 += einsum("ijba->ijab", t2) * -1.0 + x1 += einsum("ib,ja->ijab", t1, t1) * -1.0 + x1 += einsum("ia,jb->ijab", t1, t1) + t4 += einsum("ijcb,klda->ijklabcd", t2, x1) * -1.0 + t4 += einsum("ljcb,ikda->ijklabcd", t2, x1) * -1.0 + x2 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) + x2 += einsum("ijkabc->ijkabc", t3) * -1.0 + x2 += einsum("ijkacb->ijkabc", t3) + x2 += einsum("ijkbac->ijkabc", t3) + x2 += einsum("ja,ikbc->ijkabc", t1, t2) + x2 += einsum("ja,ikcb->ijkabc", t1, t2) * -1.0 + x2 += einsum("jb,ikac->ijkabc", t1, t2) * -1.0 + x2 += einsum("jb,ikca->ijkabc", t1, t2) + x2 += einsum("jc,ikab->ijkabc", t1, t2) + x2 += einsum("jc,ikba->ijkabc", t1, t2) * -1.0 + x2 += einsum("ka,ijbc->ijkabc", t1, t2) * -1.0 + x2 += einsum("ka,ijcb->ijkabc", t1, t2) + x2 += einsum("kb,ijac->ijkabc", t1, t2) + x2 += einsum("kb,ijca->ijkabc", t1, t2) * -1.0 + x2 += einsum("kc,ijab->ijkabc", t1, t2) * -1.0 + x2 += einsum("kc,ijba->ijkabc", t1, t2) + x2 += einsum("ia,jkcb->ijkabc", t1, x0) * -1.0 + x2 += einsum("ib,jkca->ijkabc", t1, x1) * -1.0 + x2 += einsum("ic,jkab->ijkabc", t1, x1) * -1.0 + t4 += einsum("jb,iklacd->ijklabcd", t1, x2) + x3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) + x3 += einsum("ijkabc->ijkabc", t3) + x3 += einsum("ia,kjcb->ijkabc", t1, t2) + x3 += einsum("ic,kjab->ijkabc", t1, t2) * -1.0 + x3 += einsum("ka,ijcb->ijkabc", t1, t2) * -1.0 + x3 += einsum("kc,ijab->ijkabc", t1, t2) + t4 += einsum("ic,kjlabd->ijklabcd", t1, x3) + t4 += einsum("lc,ijkabd->ijklabcd", t1, x3) + t4 += einsum("kc,ijlabd->ijklabcd", t1, x3) * -1.0 + return t4 + From 24898b2b39b528ace9b407e77bcd5e807b9253a1 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Fri, 17 Mar 2023 13:47:33 +0000 Subject: [PATCH 48/66] Cleans up conversion routines --- vayesta/core/types/wf/cisdtq.py | 240 +----- vayesta/core/types/wf/fci.py | 6 - vayesta/core/types/wf/t_to_c.py | 1244 +++++++++---------------------- vayesta/solver/ccsdtq.py | 206 +++++ vayesta/solver/coupling.py | 150 +--- 5 files changed, 601 insertions(+), 1245 deletions(-) create mode 100644 vayesta/solver/ccsdtq.py diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 689eb64f9..42a2fc210 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -26,176 +26,19 @@ def __init__(self, mo, c0, c1, c2, c3, c4): raise ValueError("c4 definition in RCISDTQ wfn requires tuple of (abaa, abab) spin signatures") def as_ccsdtq(self): - t1 = self.c1/self.c0 - t2 = self.c2/self.c0 - einsum('ia,jb->ijab', t1, t1) - # see also THE JOURNAL OF CHEMICAL PHYSICS 147, 154105 (2017) + c1 = self.c1 / self.c0 + c2 = self.c2 / self.c0 + c3 = self.c3 / self.c0 + c4 = tuple(c / self.c0 for c in self.c4) - # === t3 === - t3 = self.c3/self.c0 - # As a useful intermediate, compute t2_aa from t2 (_ab), which is - # just the antisymmetric permutation. - t2aa = t2 - t2.transpose(1,0,2,3) - - t1t2 = einsum('ia, jkbc -> ijkabc', t1, t2) - t1t1t1 = einsum('ia,jb,kc -> ijkabc', t1, t1, t1) - - t3 -= t1t2 - t3 += t1t2.transpose(0,1,2,5,4,3) - t3 += t1t2.transpose(2,1,0,3,4,5) - t3 -= t1t2.transpose(2,1,0,5,4,3) - t3 -= einsum('jb,ikac -> ijkabc', t1, t2aa) - t3 -= t1t1t1 - t3 += t1t1t1.transpose(0,1,2,5,4,3) - - # === t4_abaa === (Note that we construct both the abaa and abab spin signatures) - # Unpack c4 array into spin signatures - c4_abaa, c4_abab = self.c4 - # Construct the abaa first - t4_abaa = c4_abaa/self.c0 - - # A useful intermediate is the t3_aaa. Construct this from t3 (_aba) mixed spin. - t3_aaa = t3 - t3.transpose(0,2,1,3,4,5) - t3.transpose(1,0,2,3,4,5) - - # (t1 t3) terms + permutations - t1t3a = einsum('ia,kjlcbd -> ijklabcd', t1, t3) - t1t3b = np.einsum('kd,ijlabc -> ijklabcd', t1, t3) - - t4_abaa -= t1t3a - t4_abaa += t1t3b - t4_abaa += t1t3a.transpose(0,1,2,3,6,5,4,7) - t4_abaa -= t1t3a.transpose(0,1,3,2,7,5,6,4) - t4_abaa -= einsum('jb, iklacd -> ijklabcd', t1, t3_aaa) - t4_abaa += t1t3a.transpose(2,1,0,3,4,5,6,7) - t4_abaa -= t1t3a.transpose(2,1,0,3,6,5,4,7) - t4_abaa -= t1t3a.transpose(3,1,2,0,4,5,7,6) - t4_abaa += t1t3b.transpose(0,1,3,2,4,5,7,6) - t4_abaa -= t1t3b.transpose(0,1,3,2,4,5,6,7) - - # (t2 t2) terms + permutations - t2t2a = einsum('ijab, klcd -> ijklabcd', t2, t2aa) - t2t2b = einsum('ljcb, kida -> ijklabcd', t2, t2aa) - - t4_abaa -= t2t2a - t4_abaa += t2t2b - t4_abaa += t2t2a.transpose(0,1,2,3,6,5,4,7) - t4_abaa -= t2t2a.transpose(0,1,3,2,7,5,6,4) - t4_abaa -= t2t2a.transpose(3,1,2,0,7,5,6,4) - t4_abaa -= t2t2a.transpose(3,1,2,0,4,5,7,6) - t4_abaa += t2t2b.transpose(0,1,3,2,4,5,7,6) - t4_abaa -= t2t2a.transpose(2,1,0,3,6,5,4,7) - t4_abaa += t2t2a.transpose(2,1,0,3,4,5,6,7) - - # (t1 t1 t2) terms + permutations - t1t1t2a = einsum('ia, jb, klcd -> ijklabcd', t1, t1, t2aa) - t1t1t2b = einsum('kd, jb, ilac -> ijklabcd', t1, t1, t2aa) - t1t1t2c = einsum('ia, kc, ljdb -> ijklabcd', t1, t1, t2) - t1t1t2d = einsum('ic, ld, kjab -> ijklabcd', t1, t1, t2) - - t4_abaa -= t1t1t2a - t4_abaa += t1t1t2a.transpose(0,1,2,3,6,5,4,7) - t4_abaa -= t1t1t2a.transpose(0,1,3,2,7,5,6,4) - t4_abaa += t1t1t2a.transpose(2,1,0,3,4,5,6,7) - t4_abaa -= t1t1t2a.transpose(2,1,0,3,6,5,4,7) - t4_abaa += t1t1t2b - t4_abaa -= t1t1t2a.transpose(3,1,2,0,4,5,7,6) - t4_abaa += t1t1t2b.transpose(0,1,3,2,4,5,7,6) - t4_abaa -= t1t1t2b.transpose(0,1,3,2,4,5,6,7) - t4_abaa -= t1t1t2c - t4_abaa += t1t1t2c.transpose(0,1,2,3,4,5,7,6) - t4_abaa += t1t1t2c.transpose(0,1,3,2,4,5,6,7) - t4_abaa -= t1t1t2c.transpose(0,1,3,2,4,5,7,6) - t4_abaa += t1t1t2c.transpose(0,1,2,3,6,5,4,7) - t4_abaa -= t1t1t2c.transpose(2,1,0,3,7,5,6,4) - t4_abaa -= t1t1t2c.transpose(0,1,3,2,6,5,4,7) - t4_abaa += t1t1t2d - t4_abaa -= t1t1t2c.transpose(2,1,0,3,4,5,7,6) - t4_abaa += t1t1t2c.transpose(0,1,2,3,7,5,6,4) - t4_abaa += t1t1t2d.transpose(3,1,2,0,6,5,4,7) - t4_abaa -= t1t1t2d.transpose(0,1,2,3,4,5,7,6) - t4_abaa -= t1t1t2c.transpose(3,1,2,0,6,5,4,7) - t4_abaa += t1t1t2d.transpose(2,1,0,3,6,5,4,7) - t4_abaa += t1t1t2c.transpose(3,1,2,0,4,5,6,7) - t4_abaa -= t1t1t2d.transpose(2,1,0,3,4,5,6,7) - t4_abaa -= t1t1t2c.transpose(3,1,2,0,4,5,7,6) - t4_abaa += t1t1t2d.transpose(2,1,0,3,4,5,7,6) - - # (t1 t1 t1 t1) terms + permutations - t1t1t1t1 = einsum('ia, jb, kc, ld -> ijklabcd', t1, t1, t1, t1) - - t4_abaa -= t1t1t1t1 - t4_abaa += t1t1t1t1.transpose(0,1,2,3,4,5,7,6) - t4_abaa += t1t1t1t1.transpose(0,1,2,3,6,5,4,7) - t4_abaa -= t1t1t1t1.transpose(0,1,3,2,6,5,4,7) - t4_abaa -= t1t1t1t1.transpose(0,1,3,2,7,5,6,4) - t4_abaa += t1t1t1t1.transpose(0,1,2,3,7,5,6,4) - - # Now construct t4 with spin signature (abab -> abab) - t4_abab = c4_abab/self.c0 - - # (t1 t3) terms + permutations - t1t3a = einsum('ia, jklbcd -> ijklabcd', t1, t3) - t1t3b = einsum('jd, ilkabc -> ijklabcd', t1, t3) - - t4_abab -= t1t3a - t4_abab += t1t3a.transpose(0,1,2,3,6,5,4,7) - t4_abab -= t1t3a.transpose(1,0,3,2,5,4,7,6) - t4_abab += t1t3b - t4_abab += t1t3a.transpose(2,1,0,3,4,5,6,7) - t4_abab -= t1t3a.transpose(2,1,0,3,6,5,4,7) - t4_abab += t1t3b.transpose(0,3,2,1,4,7,6,5) - t4_abab -= t1t3b.transpose(0,3,2,1,4,5,6,7) - - # (t2 t2) terms + permutations - t2t2 = einsum('ijab, klcd -> ijklabcd', t2, t2) - - t4_abab -= t2t2 - t4_abab += t2t2.transpose(0,1,2,3,4,7,6,5) - t4_abab += t2t2.transpose(0,1,2,3,6,5,4,7) - t4_abab -= t2t2.transpose(0,1,2,3,6,7,4,5) - t4_abab += t2t2.transpose(0,3,2,1,4,5,6,7) - t4_abab -= t2t2.transpose(0,3,2,1,6,5,4,7) - t4_abab += t2t2.transpose(0,3,2,1,6,7,4,5) - t4_abab -= einsum('ilad, jkbc -> ijklabcd', t2, t2) - t4_abab -= einsum('ikac, jlbd -> ijklabcd', t2aa, t2aa) - - # (t1 t1 t2) terms + permutations - t1t1t2a = einsum('ia,jb,klcd -> ijklabcd', t1, t1, t2) - t1t1t2b = einsum('jb,ka,ilcd -> ijklabcd', t1, t1, t2) - - t4_abab -= t1t1t2a - t4_abab += t1t1t2a.transpose(0,1,2,3,4,7,6,5) - t4_abab += t1t1t2a.transpose(0,3,2,1,4,5,6,7) - t4_abab += t1t1t2a.transpose(0,1,2,3,6,5,4,7) - t4_abab -= t1t1t2a.transpose(0,1,2,3,6,7,4,5) - t4_abab -= t1t1t2a.transpose(0,3,2,1,6,5,4,7) - t4_abab += t1t1t2a.transpose(0,3,2,1,6,7,4,5) - t4_abab -= t1t1t2a.transpose(2,3,0,1,4,5,6,7) - t4_abab += t1t1t2a.transpose(2,3,0,1,4,7,6,5) - t4_abab += t1t1t2a.transpose(2,3,0,1,6,5,4,7) - t4_abab -= t1t1t2a.transpose(2,3,0,1,6,7,4,5) - t4_abab += t1t1t2b - t4_abab -= t1t1t2b.transpose(0,1,2,3,6,5,4,7) - t4_abab -= t1t1t2b.transpose(0,1,2,3,4,7,6,5) - t4_abab += t1t1t2b.transpose(0,1,2,3,6,7,4,5) - t4_abab -= t1t1t2b.transpose(2,3,0,1,4,7,6,5) - t4_abab -= einsum('ia,kc,jlbd -> ijklabcd', t1, t1, t2aa) - t4_abab += einsum('ic,ka,jlbd -> ijklabcd', t1, t1, t2aa) - t4_abab -= einsum('jb,ld,ikac -> ijklabcd', t1, t1, t2aa) - t4_abab += einsum('jd,lb,ikac -> ijklabcd', t1, t1, t2aa) - - # (t1 t1 t1 t1) terms + permutations - t1t1t1t1 = einsum('ia,jb,kc,ld -> ijklabcd', t1, t1, t1, t1) - - t4_abab -= t1t1t1t1 - t4_abab += t1t1t1t1.transpose(0,1,2,3,4,7,6,5) - t4_abab += t1t1t1t1.transpose(0,1,2,3,6,5,4,7) - t4_abab -= t1t1t1t1.transpose(0,1,2,3,6,7,4,5) - - # Pack two spin signatures into single tuple - t4 = (t4_abaa, t4_abab) + t1 = t_to_c.t1_rhf(c1) + t2 = t_to_c.t2_rhf(t1, c2) + t3 = t_to_c.t3_rhf(t1, t2, c3) + t4 = t_to_c.t4_rhf(t1, t2, t3, c4) return wf_types.RCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) + class UCISDTQ_WaveFunction(wf_types.WaveFunction): def __init__(self, mo, c0, c1, c2, c3, c4): @@ -205,59 +48,20 @@ def __init__(self, mo, c0, c1, c2, c3, c4): self.c2 = c2 self.c3 = c3 self.c4 = c4 - # FIXME I've just disabled these checks for now - fix later - #if not (isinstance(c3, tuple) and len(c3) == 6): - # raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaa, aba, abb, bab, bba, bbb) spin signatures") - #if not (isinstance(c4, tuple) and len(c4) == 8): - # raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaaa, aaab, aaba, abaa, abab, bbab, bbba, bbbb) spin signatures") + if not (isinstance(c3, tuple) and len(c3) == 4): + raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaa, aba, bab, bbb) spin signatures") + if not (isinstance(c4, tuple) and len(c4) == 5): + raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaaa, aaab, abab, abbb, bbbb) spin signatures") def as_ccsdtq(self): - # TODO optimise these contractions - # TODO remove redundant permutations - c1_aa, c1_bb = (c / self.c0 for c in self.c1) - c2_aaaa, c2_abab, c2_bbbb = (c / self.c0 for c in self.c2) - c3_aaaaaa, c3_abaaba, c3_abbabb, c3_babbab, c3_bbabba, c3_bbbbbb = (c / self.c0 for c in self.c3) - c4_aaaaaaaa, c4_aaabaaab, c4_aabaaaba, c4_abaaabaa, c4_abababab, c4_abbbabbb, c4_bbabbbab, c4_bbbabbba, c4_bbbbbbbb = (c / self.c0 for c in self.c4) - - from types import SimpleNamespace - c1 = SimpleNamespace(aa=c1_aa, bb=c1_bb) - c2 = SimpleNamespace(aaaa=c2_aaaa, abab=c2_abab, bbbb=c2_bbbb) - c3 = SimpleNamespace(aaaaaa=c3_aaaaaa, abaaba=c3_abaaba, abbabb=c3_abbabb, babbab=c3_babbab, bbabba=c3_bbabba, bbbbbb=c3_bbbbbb) - c4 = SimpleNamespace(aaaaaaaa=c4_aaaaaaaa, aaabaaab=c4_aaabaaab, aabaaaba=c4_aabaaaba, abaaabaa=c4_abaaabaa, abababab=c4_abababab, abbbabbb=c4_abbbabbb, bbabbbab=c4_bbabbbab, bbbabbba=c4_bbbabbba, bbbbbbbb=c4_bbbbbbbb) - - nocc = (c1.aa.shape[0], c1.bb.shape[0]) - nvir = (c1.aa.shape[1], c1.bb.shape[1]) - - t1_aa = t_to_c.t1_uhf_aa(c1=c1, nocc=nocc, nvir=nvir) - t1_bb = t_to_c.t1_uhf_bb(c1=c1, nocc=nocc, nvir=nvir) - t1 = SimpleNamespace(aa=t1_aa, bb=t1_bb) - - t2_aaaa = t_to_c.t2_uhf_aaaa(c2=c2, t1=t1, nocc=nocc, nvir=nvir) - t2_abab = t_to_c.t2_uhf_abab(c2=c2, t1=t1, nocc=nocc, nvir=nvir) - t2_bbbb = t_to_c.t2_uhf_bbbb(c2=c2, t1=t1, nocc=nocc, nvir=nvir) - t2 = SimpleNamespace(aaaa=t2_aaaa, abab=t2_abab, bbbb=t2_bbbb) - - t3_aaaaaa = t_to_c.t3_uhf_aaaaaa(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_abaaba = t_to_c.t3_uhf_abaaba(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_abbabb = t_to_c.t3_uhf_abbabb(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_babbab = t_to_c.t3_uhf_babbab(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_bbabba = t_to_c.t3_uhf_bbabba(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3_bbbbbb = t_to_c.t3_uhf_bbbbbb(c3=c3, t1=t1, t2=t2, nocc=nocc, nvir=nvir) - t3 = SimpleNamespace(aaaaaa=t3_aaaaaa, abaaba=t3_abaaba, abbabb=t3_abbabb, babbab=t3_babbab, bbabba=t3_bbabba, bbbbbb=t3_bbbbbb) - - t4_aaaaaaaa = t_to_c.t4_uhf_aaaaaaaa(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_aaabaaab = t_to_c.t4_uhf_aaabaaab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_aabaaaba = t_to_c.t4_uhf_aabaaaba(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_abaaabaa = t_to_c.t4_uhf_abaaabaa(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_abababab = t_to_c.t4_uhf_abababab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_abbbabbb = t_to_c.t4_uhf_abbbabbb(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_bbabbbab = t_to_c.t4_uhf_bbabbbab(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_bbbabbba = t_to_c.t4_uhf_bbbabbba(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - t4_bbbbbbbb = t_to_c.t4_uhf_bbbbbbbb(c4=c4, t1=t1, t2=t2, t3=t3, nocc=nocc, nvir=nvir) - - t1 = (t1_aa, t1_bb) - t2 = (t2_aaaa, t2_abab, t2_bbbb) - t3 = (t3_aaaaaa, t3_abaaba, t3_abbabb, t3_babbab, t3_bbabba, t3_bbbbbb) - t4 = (t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_abbbabbb, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb) + c1 = tuple(c / self.c0 for c in self.c1) + c2 = tuple(c / self.c0 for c in self.c2) + c3 = tuple(c / self.c0 for c in self.c3) + c4 = tuple(c / self.c0 for c in self.c4) + + t1 = t_to_c.t1_uhf(c1) + t2 = t_to_c.t2_uhf(t1, c2) + t3 = t_to_c.t3_uhf(t1, t2, c3) + t4 = t_to_c.t4_uhf(t1, t2, t3, c4) return wf_types.UCCSDTQ_WaveFunction(self.mo, t1=t1, t2=t2, t3=t3, t4=t4) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 531120a33..99dc48b7f 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -595,20 +595,14 @@ def as_cisdtq(self, c0=None): c3 = ( c3_aaa, c3_aab.transpose(0, 2, 1, 3, 5, 4), - c3_abb, c3_abb.transpose(1, 0, 2, 4, 3, 5), - c3_abb.transpose(2, 1, 0, 5, 4, 3), c3_bbb, ) c4 = ( c4_aaaa, c4_aaab, - c4_aaab.transpose(0, 1, 3, 2, 4, 5, 7, 6), - c4_aaab.transpose(0, 3, 2, 1, 4, 7, 6, 5), c4_aabb.transpose(0, 2, 1, 3, 4, 6, 5, 7), c4_abbb, - c4_abbb.transpose(2, 1, 0, 3, 6, 5, 4, 7), - c4_abbb.transpose(3, 1, 2, 0, 7, 5, 6, 4), c4_bbbb, ) diff --git a/vayesta/core/types/wf/t_to_c.py b/vayesta/core/types/wf/t_to_c.py index 8b7859f8d..6f5f09391 100644 --- a/vayesta/core/types/wf/t_to_c.py +++ b/vayesta/core/types/wf/t_to_c.py @@ -1,174 +1,109 @@ import numpy as np from vayesta.core.util import einsum -def t1_uhf_aa(c1=None, nocc=None, nvir=None): +def t1_uhf(c1): + c1_aa, c1_bb = c1 + nocc = (c1_aa.shape[0], c1_bb.shape[0]) + nvir = (c1_aa.shape[1], c1_bb.shape[1]) t1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - t1_aa += einsum("ia->ia", c1.aa) - return t1_aa - -def t1_uhf_bb(c1=None, nocc=None, nvir=None): + t1_aa += einsum("ia->ia", c1_aa) t1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - t1_bb += einsum("ia->ia", c1.bb) - return t1_bb + t1_bb += einsum("ia->ia", c1_bb) + return t1_aa, t1_bb -def t1_rhf(c1=None, nocc=None, nvir=None): +def t1_rhf(c1): + nocc, nvir = c1.shape t1 = np.zeros((nocc, nvir), dtype=np.float64) t1 += einsum("ia->ia", c1) return t1 -def t2_uhf_aaaa(c2=None, t1=None, nocc=None, nvir=None): +def t2_uhf(t1, c2): + t1_aa, t1_bb = t1 + c2_aaaa, c2_abab, c2_bbbb = c2 + nocc = (t1_aa.shape[0], t1_bb.shape[0]) + nvir = (t1_aa.shape[1], t1_bb.shape[1]) t2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - t2_aaaa += einsum("ijab->ijab", c2.aaaa) - t2_aaaa += einsum("ib,ja->ijab", t1.aa, t1.aa) - t2_aaaa += einsum("ia,jb->ijab", t1.aa, t1.aa) * -1.0 - return t2_aaaa - -def t2_uhf_abab(c2=None, t1=None, nocc=None, nvir=None): + t2_aaaa += einsum("ijab->ijab", c2_aaaa) + t2_aaaa += einsum("ib,ja->ijab", t1_aa, t1_aa) + t2_aaaa += einsum("ia,jb->ijab", t1_aa, t1_aa) * -1.0 t2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) - t2_abab += einsum("ijab->ijab", c2.abab) - t2_abab += einsum("ia,jb->ijab", t1.aa, t1.bb) * -1.0 - return t2_abab - -def t2_uhf_baba(c2=None, t1=None, nocc=None, nvir=None): - t2_baba = np.zeros((nocc[1], nocc[0], nvir[1], nvir[0]), dtype=np.float64) - t2_baba += einsum("jiba->ijab", c2.abab) - t2_baba += einsum("jb,ia->ijab", t1.aa, t1.bb) * -1.0 - return t2_baba - -def t2_uhf_bbbb(c2=None, t1=None, nocc=None, nvir=None): + t2_abab += einsum("ijab->ijab", c2_abab) + t2_abab += einsum("ia,jb->ijab", t1_aa, t1_bb) * -1.0 t2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - t2_bbbb += einsum("ijab->ijab", c2.bbbb) - t2_bbbb += einsum("ib,ja->ijab", t1.bb, t1.bb) - t2_bbbb += einsum("ia,jb->ijab", t1.bb, t1.bb) * -1.0 - return t2_bbbb + t2_bbbb += einsum("ijab->ijab", c2_bbbb) + t2_bbbb += einsum("ib,ja->ijab", t1_bb, t1_bb) + t2_bbbb += einsum("ia,jb->ijab", t1_bb, t1_bb) * -1.0 + return t2_aaaa, t2_abab, t2_bbbb -def t2_rhf(c2=None, t1=None, nocc=None, nvir=None): +def t2_rhf(t1, c2): + nocc, nvir = t1.shape t2 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) t2 += einsum("ijab->ijab", c2) t2 += einsum("ia,jb->ijab", t1, t1) * -1.0 return t2 -def t3_uhf_aaaaaa(c3=None, t1=None, t2=None, nocc=None, nvir=None): +def t3_uhf(t1, t2, c3): + t1_aa, t1_bb = t1 + t2_aaaa, t2_abab, t2_bbbb = t2 + c3_aaaaaa, c3_abaaba, c3_babbab, c3_bbbbbb = c3 + nocc = (t1_aa.shape[0], t1_bb.shape[0]) + nvir = (t1_aa.shape[1], t1_bb.shape[1]) t3_aaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - t3_aaaaaa += einsum("ijkabc->ijkabc", c3.aaaaaa) - t3_aaaaaa += einsum("ia,jkbc->ijkabc", t1.aa, t2.aaaa) * -1.0 - t3_aaaaaa += einsum("ic,jkab->ijkabc", t1.aa, t2.aaaa) * -1.0 - t3_aaaaaa += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) - t3_aaaaaa += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) - t3_aaaaaa += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) * -1.0 - t3_aaaaaa += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) * -1.0 + t3_aaaaaa += einsum("ijkabc->ijkabc", c3_aaaaaa) + t3_aaaaaa += einsum("ia,jkbc->ijkabc", t1_aa, t2_aaaa) * -1.0 + t3_aaaaaa += einsum("ic,jkab->ijkabc", t1_aa, t2_aaaa) * -1.0 + t3_aaaaaa += einsum("ja,ikbc->ijkabc", t1_aa, t2_aaaa) + t3_aaaaaa += einsum("jc,ikab->ijkabc", t1_aa, t2_aaaa) + t3_aaaaaa += einsum("ka,ijbc->ijkabc", t1_aa, t2_aaaa) * -1.0 + t3_aaaaaa += einsum("kc,ijab->ijkabc", t1_aa, t2_aaaa) * -1.0 x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t3_aaaaaa += einsum("ib,kjca->ijkabc", t1.aa, x0) - t3_aaaaaa += einsum("kb,jica->ijkabc", t1.aa, x0) - t3_aaaaaa += einsum("jb,kica->ijkabc", t1.aa, x0) * -1.0 - return t3_aaaaaa - -def t3_uhf_aabaab(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_aabaab = np.zeros((nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[1]), dtype=np.float64) - t3_aabaab += einsum("ikjacb->ijkabc", c3.abaaba) - t3_aabaab += einsum("ia,jkbc->ijkabc", t1.aa, t2.abab) * -1.0 - t3_aabaab += einsum("ib,jkac->ijkabc", t1.aa, t2.abab) - t3_aabaab += einsum("ja,ikbc->ijkabc", t1.aa, t2.abab) - t3_aabaab += einsum("jb,ikac->ijkabc", t1.aa, t2.abab) * -1.0 - x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t3_aabaab += einsum("kc,jiba->ijkabc", t1.bb, x0) * -1.0 - return t3_aabaab - -def t3_uhf_abaaba(c3=None, t1=None, t2=None, nocc=None, nvir=None): + x0 += einsum("ijab->ijab", t2_aaaa) + x0 += einsum("ib,ja->ijab", t1_aa, t1_aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1_aa, t1_aa) + t3_aaaaaa += einsum("ib,kjca->ijkabc", t1_aa, x0) + t3_aaaaaa += einsum("kb,jica->ijkabc", t1_aa, x0) + t3_aaaaaa += einsum("jb,kica->ijkabc", t1_aa, x0) * -1.0 t3_abaaba = np.zeros((nocc[0], nocc[1], nocc[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) - t3_abaaba += einsum("ijkabc->ijkabc", c3.abaaba) - t3_abaaba += einsum("ia,kjcb->ijkabc", t1.aa, t2.abab) * -1.0 - t3_abaaba += einsum("ic,kjab->ijkabc", t1.aa, t2.abab) - t3_abaaba += einsum("ka,ijcb->ijkabc", t1.aa, t2.abab) - t3_abaaba += einsum("kc,ijab->ijkabc", t1.aa, t2.abab) * -1.0 - x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t3_abaaba += einsum("jb,kica->ijkabc", t1.bb, x0) * -1.0 - return t3_abaaba - -def t3_uhf_abbabb(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_abbabb = np.zeros((nocc[0], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) - t3_abbabb += einsum("jikbac->ijkabc", c3.babbab) - t3_abbabb += einsum("jb,ikac->ijkabc", t1.bb, t2.abab) * -1.0 - t3_abbabb += einsum("jc,ikab->ijkabc", t1.bb, t2.abab) - t3_abbabb += einsum("kb,ijac->ijkabc", t1.bb, t2.abab) - t3_abbabb += einsum("kc,ijab->ijkabc", t1.bb, t2.abab) * -1.0 - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t3_abbabb += einsum("ia,kjcb->ijkabc", t1.aa, x0) * -1.0 - return t3_abbabb - -def t3_uhf_baabaa(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_baabaa = np.zeros((nocc[1], nocc[0], nocc[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) - t3_baabaa += einsum("jikbac->ijkabc", c3.abaaba) - t3_baabaa += einsum("jb,kica->ijkabc", t1.aa, t2.abab) * -1.0 - t3_baabaa += einsum("jc,kiba->ijkabc", t1.aa, t2.abab) - t3_baabaa += einsum("kb,jica->ijkabc", t1.aa, t2.abab) - t3_baabaa += einsum("kc,jiba->ijkabc", t1.aa, t2.abab) * -1.0 + t3_abaaba += einsum("ijkabc->ijkabc", c3_abaaba) + t3_abaaba += einsum("ia,kjcb->ijkabc", t1_aa, t2_abab) * -1.0 + t3_abaaba += einsum("ic,kjab->ijkabc", t1_aa, t2_abab) + t3_abaaba += einsum("ka,ijcb->ijkabc", t1_aa, t2_abab) + t3_abaaba += einsum("kc,ijab->ijkabc", t1_aa, t2_abab) * -1.0 x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t3_baabaa += einsum("ia,kjcb->ijkabc", t1.bb, x0) * -1.0 - return t3_baabaa - -def t3_uhf_babbab(c3=None, t1=None, t2=None, nocc=None, nvir=None): + x0 += einsum("ijab->ijab", t2_aaaa) + x0 += einsum("ib,ja->ijab", t1_aa, t1_aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1_aa, t1_aa) + t3_abaaba += einsum("jb,kica->ijkabc", t1_bb, x0) * -1.0 t3_babbab = np.zeros((nocc[1], nocc[0], nocc[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t3_babbab += einsum("ijkabc->ijkabc", c3.babbab) - t3_babbab += einsum("ia,jkbc->ijkabc", t1.bb, t2.abab) * -1.0 - t3_babbab += einsum("ic,jkba->ijkabc", t1.bb, t2.abab) - t3_babbab += einsum("ka,jibc->ijkabc", t1.bb, t2.abab) - t3_babbab += einsum("kc,jiba->ijkabc", t1.bb, t2.abab) * -1.0 + t3_babbab += einsum("ijkabc->ijkabc", c3_babbab) + t3_babbab += einsum("ia,jkbc->ijkabc", t1_bb, t2_abab) * -1.0 + t3_babbab += einsum("ic,jkba->ijkabc", t1_bb, t2_abab) + t3_babbab += einsum("ka,jibc->ijkabc", t1_bb, t2_abab) + t3_babbab += einsum("kc,jiba->ijkabc", t1_bb, t2_abab) * -1.0 x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t3_babbab += einsum("jb,kica->ijkabc", t1.aa, x0) * -1.0 - return t3_babbab - -def t3_uhf_bbabba(c3=None, t1=None, t2=None, nocc=None, nvir=None): - t3_bbabba = np.zeros((nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) - t3_bbabba += einsum("ikjacb->ijkabc", c3.babbab) - t3_bbabba += einsum("ia,kjcb->ijkabc", t1.bb, t2.abab) * -1.0 - t3_bbabba += einsum("ib,kjca->ijkabc", t1.bb, t2.abab) - t3_bbabba += einsum("ja,kicb->ijkabc", t1.bb, t2.abab) - t3_bbabba += einsum("jb,kica->ijkabc", t1.bb, t2.abab) * -1.0 - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t3_bbabba += einsum("kc,jiba->ijkabc", t1.aa, x0) * -1.0 - return t3_bbabba - -def t3_uhf_bbbbbb(c3=None, t1=None, t2=None, nocc=None, nvir=None): + x0 += einsum("ijab->ijab", t2_bbbb) + x0 += einsum("ib,ja->ijab", t1_bb, t1_bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1_bb, t1_bb) + t3_babbab += einsum("jb,kica->ijkabc", t1_aa, x0) * -1.0 t3_bbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t3_bbbbbb += einsum("ijkabc->ijkabc", c3.bbbbbb) - t3_bbbbbb += einsum("ia,jkbc->ijkabc", t1.bb, t2.bbbb) * -1.0 - t3_bbbbbb += einsum("ic,jkab->ijkabc", t1.bb, t2.bbbb) * -1.0 - t3_bbbbbb += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) - t3_bbbbbb += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) - t3_bbbbbb += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) * -1.0 - t3_bbbbbb += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) * -1.0 + t3_bbbbbb += einsum("ijkabc->ijkabc", c3_bbbbbb) + t3_bbbbbb += einsum("ia,jkbc->ijkabc", t1_bb, t2_bbbb) * -1.0 + t3_bbbbbb += einsum("ic,jkab->ijkabc", t1_bb, t2_bbbb) * -1.0 + t3_bbbbbb += einsum("ja,ikbc->ijkabc", t1_bb, t2_bbbb) + t3_bbbbbb += einsum("jc,ikab->ijkabc", t1_bb, t2_bbbb) + t3_bbbbbb += einsum("ka,ijbc->ijkabc", t1_bb, t2_bbbb) * -1.0 + t3_bbbbbb += einsum("kc,ijab->ijkabc", t1_bb, t2_bbbb) * -1.0 x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t3_bbbbbb += einsum("ib,kjca->ijkabc", t1.bb, x0) - t3_bbbbbb += einsum("kb,jica->ijkabc", t1.bb, x0) - t3_bbbbbb += einsum("jb,kica->ijkabc", t1.bb, x0) * -1.0 - return t3_bbbbbb - -def t3_rhf(c3=None, t1=None, t2=None, nocc=None, nvir=None): + x0 += einsum("ijab->ijab", t2_bbbb) + x0 += einsum("ib,ja->ijab", t1_bb, t1_bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1_bb, t1_bb) + t3_bbbbbb += einsum("ib,kjca->ijkabc", t1_bb, x0) + t3_bbbbbb += einsum("kb,jica->ijkabc", t1_bb, x0) + t3_bbbbbb += einsum("jb,kica->ijkabc", t1_bb, x0) * -1.0 + return t3_aaaaaa, t3_abaaba, t3_babbab, t3_bbbbbb + +def t3_rhf(t1, t2, c3): + nocc, nvir = t1.shape t3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) t3 += einsum("ijkabc->ijkabc", c3) t3 += einsum("ia,kjcb->ijkabc", t1, t2) * -1.0 @@ -183,783 +118,327 @@ def t3_rhf(c3=None, t1=None, t2=None, nocc=None, nvir=None): t3 += einsum("jb,ikca->ijkabc", t1, x0) * -1.0 return t3 -def t4_uhf_aaaaaaaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): +def t4_uhf(t1, t2, t3, c4): + t1_aa, t1_bb = t1 + t2_aaaa, t2_abab, t2_bbbb = t2 + t3_aaaaaa, t3_abaaba, t3_babbab, t3_bbbbbb = t3 + c4_aaaaaaaa, c4_aaabaaab, c4_abababab, c4_abbbabbb, c4_bbbbbbbb = c4 + nocc = (t1_aa.shape[0], t1_bb.shape[0]) + nvir = (t1_aa.shape[1], t1_bb.shape[1]) t4_aaaaaaaa = np.zeros((nocc[0], nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - t4_aaaaaaaa += einsum("ijklabcd->ijklabcd", c4.aaaaaaaa) - t4_aaaaaaaa += einsum("la,ijkbcd->ijklabcd", t1.aa, t3.aaaaaa) - t4_aaaaaaaa += einsum("lb,ijkacd->ijklabcd", t1.aa, t3.aaaaaa) * -1.0 - t4_aaaaaaaa += einsum("lc,ijkabd->ijklabcd", t1.aa, t3.aaaaaa) - t4_aaaaaaaa += einsum("ld,ijkabc->ijklabcd", t1.aa, t3.aaaaaa) * -1.0 - t4_aaaaaaaa += einsum("ilcd,jkab->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ilbd,jkac->ijklabcd", t2.aaaa, t2.aaaa) - t4_aaaaaaaa += einsum("ilad,jkbc->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ilbc,jkad->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ilac,jkbd->ijklabcd", t2.aaaa, t2.aaaa) - t4_aaaaaaaa += einsum("ilab,jkcd->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ikcd,jlab->ijklabcd", t2.aaaa, t2.aaaa) - t4_aaaaaaaa += einsum("ikbd,jlac->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ikad,jlbc->ijklabcd", t2.aaaa, t2.aaaa) - t4_aaaaaaaa += einsum("ikbc,jlad->ijklabcd", t2.aaaa, t2.aaaa) - t4_aaaaaaaa += einsum("ikac,jlbd->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ikab,jlcd->ijklabcd", t2.aaaa, t2.aaaa) - t4_aaaaaaaa += einsum("ijcd,klab->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ijbd,klac->ijklabcd", t2.aaaa, t2.aaaa) - t4_aaaaaaaa += einsum("ijad,klbc->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ijbc,klad->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 - t4_aaaaaaaa += einsum("ijac,klbd->ijklabcd", t2.aaaa, t2.aaaa) - t4_aaaaaaaa += einsum("ijab,klcd->ijklabcd", t2.aaaa, t2.aaaa) * -1.0 + t4_aaaaaaaa += einsum("ijklabcd->ijklabcd", c4_aaaaaaaa) + t4_aaaaaaaa += einsum("la,ijkbcd->ijklabcd", t1_aa, t3_aaaaaa) + t4_aaaaaaaa += einsum("lb,ijkacd->ijklabcd", t1_aa, t3_aaaaaa) * -1.0 + t4_aaaaaaaa += einsum("lc,ijkabd->ijklabcd", t1_aa, t3_aaaaaa) + t4_aaaaaaaa += einsum("ld,ijkabc->ijklabcd", t1_aa, t3_aaaaaa) * -1.0 + t4_aaaaaaaa += einsum("ilcd,jkab->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ilbd,jkac->ijklabcd", t2_aaaa, t2_aaaa) + t4_aaaaaaaa += einsum("ilad,jkbc->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ilbc,jkad->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ilac,jkbd->ijklabcd", t2_aaaa, t2_aaaa) + t4_aaaaaaaa += einsum("ilab,jkcd->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ikcd,jlab->ijklabcd", t2_aaaa, t2_aaaa) + t4_aaaaaaaa += einsum("ikbd,jlac->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ikad,jlbc->ijklabcd", t2_aaaa, t2_aaaa) + t4_aaaaaaaa += einsum("ikbc,jlad->ijklabcd", t2_aaaa, t2_aaaa) + t4_aaaaaaaa += einsum("ikac,jlbd->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ikab,jlcd->ijklabcd", t2_aaaa, t2_aaaa) + t4_aaaaaaaa += einsum("ijcd,klab->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ijbd,klac->ijklabcd", t2_aaaa, t2_aaaa) + t4_aaaaaaaa += einsum("ijad,klbc->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ijbc,klad->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 + t4_aaaaaaaa += einsum("ijac,klbd->ijklabcd", t2_aaaa, t2_aaaa) + t4_aaaaaaaa += einsum("ijab,klcd->ijklabcd", t2_aaaa, t2_aaaa) * -1.0 x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + x0 += einsum("ijab->ijab", t2_aaaa) + x0 += einsum("ib,ja->ijab", t1_aa, t1_aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1_aa, t1_aa) x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) - x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) - x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) - x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 - t4_aaaaaaaa += einsum("ib,ljkdac->ijklabcd", t1.aa, x1) - t4_aaaaaaaa += einsum("id,ljkcab->ijklabcd", t1.aa, x1) - t4_aaaaaaaa += einsum("ia,ljkdbc->ijklabcd", t1.aa, x1) * -1.0 - t4_aaaaaaaa += einsum("ic,ljkdab->ijklabcd", t1.aa, x1) * -1.0 + x1 += einsum("ijkabc->ijkabc", t3_aaaaaa) + x1 += einsum("ja,ikbc->ijkabc", t1_aa, t2_aaaa) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1_aa, t2_aaaa) + x1 += einsum("jc,ikab->ijkabc", t1_aa, t2_aaaa) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1_aa, t2_aaaa) + x1 += einsum("kb,ijac->ijkabc", t1_aa, t2_aaaa) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1_aa, t2_aaaa) + x1 += einsum("ia,kjcb->ijkabc", t1_aa, x0) + x1 += einsum("ic,kjba->ijkabc", t1_aa, x0) + x1 += einsum("ib,kjca->ijkabc", t1_aa, x0) * -1.0 + t4_aaaaaaaa += einsum("ib,ljkdac->ijklabcd", t1_aa, x1) + t4_aaaaaaaa += einsum("id,ljkcab->ijklabcd", t1_aa, x1) + t4_aaaaaaaa += einsum("ia,ljkdbc->ijklabcd", t1_aa, x1) * -1.0 + t4_aaaaaaaa += einsum("ic,ljkdab->ijklabcd", t1_aa, x1) * -1.0 x2 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("ijkabc->ijkabc", t3.aaaaaa) - x2 += einsum("ia,jkbc->ijkabc", t1.aa, t2.aaaa) - x2 += einsum("ib,jkac->ijkabc", t1.aa, t2.aaaa) * -1.0 - x2 += einsum("ic,jkab->ijkabc", t1.aa, t2.aaaa) - x2 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) - x2 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 - x2 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) - t4_aaaaaaaa += einsum("ja,likdbc->ijklabcd", t1.aa, x2) - t4_aaaaaaaa += einsum("jc,likdab->ijklabcd", t1.aa, x2) - t4_aaaaaaaa += einsum("jb,likdac->ijklabcd", t1.aa, x2) * -1.0 - t4_aaaaaaaa += einsum("jd,likcab->ijklabcd", t1.aa, x2) * -1.0 + x2 += einsum("ijkabc->ijkabc", t3_aaaaaa) + x2 += einsum("ia,jkbc->ijkabc", t1_aa, t2_aaaa) + x2 += einsum("ib,jkac->ijkabc", t1_aa, t2_aaaa) * -1.0 + x2 += einsum("ic,jkab->ijkabc", t1_aa, t2_aaaa) + x2 += einsum("ka,ijbc->ijkabc", t1_aa, t2_aaaa) + x2 += einsum("kb,ijac->ijkabc", t1_aa, t2_aaaa) * -1.0 + x2 += einsum("kc,ijab->ijkabc", t1_aa, t2_aaaa) + t4_aaaaaaaa += einsum("ja,likdbc->ijklabcd", t1_aa, x2) + t4_aaaaaaaa += einsum("jc,likdab->ijklabcd", t1_aa, x2) + t4_aaaaaaaa += einsum("jb,likdac->ijklabcd", t1_aa, x2) * -1.0 + t4_aaaaaaaa += einsum("jd,likcab->ijklabcd", t1_aa, x2) * -1.0 x3 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - x3 += einsum("ijkabc->ijkabc", t3.aaaaaa) - x3 += einsum("ia,jkbc->ijkabc", t1.aa, t2.aaaa) - x3 += einsum("ib,jkac->ijkabc", t1.aa, t2.aaaa) * -1.0 - x3 += einsum("ic,jkab->ijkabc", t1.aa, t2.aaaa) - t4_aaaaaaaa += einsum("kb,lijdac->ijklabcd", t1.aa, x3) - t4_aaaaaaaa += einsum("kd,lijcab->ijklabcd", t1.aa, x3) - t4_aaaaaaaa += einsum("ka,lijdbc->ijklabcd", t1.aa, x3) * -1.0 - t4_aaaaaaaa += einsum("kc,lijdab->ijklabcd", t1.aa, x3) * -1.0 - return t4_aaaaaaaa - -def t4_uhf_aaabaaab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + x3 += einsum("ijkabc->ijkabc", t3_aaaaaa) + x3 += einsum("ia,jkbc->ijkabc", t1_aa, t2_aaaa) + x3 += einsum("ib,jkac->ijkabc", t1_aa, t2_aaaa) * -1.0 + x3 += einsum("ic,jkab->ijkabc", t1_aa, t2_aaaa) + t4_aaaaaaaa += einsum("kb,lijdac->ijklabcd", t1_aa, x3) + t4_aaaaaaaa += einsum("kd,lijcab->ijklabcd", t1_aa, x3) + t4_aaaaaaaa += einsum("ka,lijdbc->ijklabcd", t1_aa, x3) * -1.0 + t4_aaaaaaaa += einsum("kc,lijdab->ijklabcd", t1_aa, x3) * -1.0 t4_aaabaaab = np.zeros((nocc[0], nocc[0], nocc[0], nocc[1], nvir[0], nvir[0], nvir[0], nvir[1]), dtype=np.float64) - t4_aaabaaab += einsum("ijklabcd->ijklabcd", c4.aaabaaab) - t4_aaabaaab += einsum("ia,jlkbdc->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_aaabaaab += einsum("ic,jlkadb->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_aaabaaab += einsum("ja,ilkbdc->ijklabcd", t1.aa, t3.abaaba) - t4_aaabaaab += einsum("jc,ilkadb->ijklabcd", t1.aa, t3.abaaba) - t4_aaabaaab += einsum("ka,iljbdc->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_aaabaaab += einsum("kc,iljadb->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_aaabaaab += einsum("klcd,ijab->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_aaabaaab += einsum("klad,ijbc->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_aaabaaab += einsum("jlcd,ikab->ijklabcd", t2.abab, t2.aaaa) - t4_aaabaaab += einsum("jlad,ikbc->ijklabcd", t2.abab, t2.aaaa) - t4_aaabaaab += einsum("ilcd,jkab->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_aaabaaab += einsum("ilad,jkbc->ijklabcd", t2.abab, t2.aaaa) * -1.0 - x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t4_aaabaaab += einsum("ilbd,kjca->ijklabcd", t2.abab, x0) - t4_aaabaaab += einsum("klbd,jica->ijklabcd", t2.abab, x0) - t4_aaabaaab += einsum("jlbd,kica->ijklabcd", t2.abab, x0) * -1.0 - x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) - x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) - x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) - x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 - t4_aaabaaab += einsum("ld,kijcab->ijklabcd", t1.bb, x1) * -1.0 - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_aaabaaab += einsum("ib,ldkjca->ijklabcd", t1.aa, x2) - t4_aaabaaab += einsum("kb,ldjica->ijklabcd", t1.aa, x2) - t4_aaabaaab += einsum("jb,ldkica->ijklabcd", t1.aa, x2) * -1.0 - return t4_aaabaaab - -def t4_uhf_aabaaaba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_aabaaaba = np.zeros((nocc[0], nocc[0], nocc[1], nocc[0], nvir[0], nvir[0], nvir[1], nvir[0]), dtype=np.float64) - t4_aabaaaba += einsum("ijlkabdc->ijklabcd", c4.aaabaaab) - t4_aabaaaba += einsum("ia,jklbcd->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_aabaaaba += einsum("id,jklacb->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_aabaaaba += einsum("ja,iklbcd->ijklabcd", t1.aa, t3.abaaba) - t4_aabaaaba += einsum("jd,iklacb->ijklabcd", t1.aa, t3.abaaba) - t4_aabaaaba += einsum("la,ikjbcd->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_aabaaaba += einsum("ld,ikjacb->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_aabaaaba += einsum("lkdc,ijab->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_aabaaaba += einsum("lkac,ijbd->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_aabaaaba += einsum("jkdc,ilab->ijklabcd", t2.abab, t2.aaaa) - t4_aabaaaba += einsum("jkac,ilbd->ijklabcd", t2.abab, t2.aaaa) - t4_aabaaaba += einsum("ikdc,jlab->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_aabaaaba += einsum("ikac,jlbd->ijklabcd", t2.abab, t2.aaaa) * -1.0 - x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t4_aabaaaba += einsum("ikbc,ljda->ijklabcd", t2.abab, x0) - t4_aabaaaba += einsum("lkbc,jida->ijklabcd", t2.abab, x0) - t4_aabaaaba += einsum("jkbc,lida->ijklabcd", t2.abab, x0) * -1.0 - x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) - x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) - x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) - x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 - t4_aabaaaba += einsum("kc,lijdab->ijklabcd", t1.bb, x1) * -1.0 - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_aabaaaba += einsum("ib,kcljda->ijklabcd", t1.aa, x2) - t4_aabaaaba += einsum("lb,kcjida->ijklabcd", t1.aa, x2) - t4_aabaaaba += einsum("jb,kclida->ijklabcd", t1.aa, x2) * -1.0 - return t4_aabaaaba - -def t4_uhf_aabbaabb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_aabbaabb = np.zeros((nocc[0], nocc[0], nocc[1], nocc[1], nvir[0], nvir[0], nvir[1], nvir[1]), dtype=np.float64) - t4_aabbaabb += einsum("ikjlacbd->ijklabcd", c4.abababab) - t4_aabbaabb += einsum("ia,kjlcbd->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_aabbaabb += einsum("ib,kjlcad->ijklabcd", t1.aa, t3.babbab) - t4_aabbaabb += einsum("ja,kilcbd->ijklabcd", t1.aa, t3.babbab) - t4_aabbaabb += einsum("jb,kilcad->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_aabbaabb += einsum("ilac,jkbd->ijklabcd", t2.abab, t2.abab) - t4_aabbaabb += einsum("ilbc,jkad->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_aabbaabb += einsum("ikbd,jlac->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_aabbaabb += einsum("ikad,jlbc->ijklabcd", t2.abab, t2.abab) - t4_aabbaabb += einsum("ilad,jkbc->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_aabbaabb += einsum("ilbd,jkac->ijklabcd", t2.abab, t2.abab) - t4_aabbaabb += einsum("ikbc,jlad->ijklabcd", t2.abab, t2.abab) - t4_aabbaabb += einsum("ikac,jlbd->ijklabcd", t2.abab, t2.abab) * -1.0 - x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("ijab->ijab", t2.bbbb) - x1 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x1 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t4_aabbaabb += einsum("jiba,lkdc->ijklabcd", x0, x1) * -1.0 - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_aabbaabb += einsum("kd,lcjiba->ijklabcd", t1.bb, x2) - t4_aabbaabb += einsum("lc,kdjiba->ijklabcd", t1.bb, x2) - t4_aabbaabb += einsum("kc,ldjiba->ijklabcd", t1.bb, x2) * -1.0 - t4_aabbaabb += einsum("ld,kcjiba->ijklabcd", t1.bb, x2) * -1.0 - return t4_aabbaabb - -def t4_uhf_abaaabaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_abaaabaa = np.zeros((nocc[0], nocc[1], nocc[0], nocc[0], nvir[0], nvir[1], nvir[0], nvir[0]), dtype=np.float64) - t4_abaaabaa += einsum("ikljacdb->ijklabcd", c4.aaabaaab) - t4_abaaabaa += einsum("ia,kjlcbd->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_abaaabaa += einsum("id,kjlabc->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_abaaabaa += einsum("ka,ijlcbd->ijklabcd", t1.aa, t3.abaaba) - t4_abaaabaa += einsum("kd,ijlabc->ijklabcd", t1.aa, t3.abaaba) - t4_abaaabaa += einsum("la,ijkcbd->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_abaaabaa += einsum("ld,ijkabc->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_abaaabaa += einsum("ljdb,ikac->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_abaaabaa += einsum("ljab,ikcd->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_abaaabaa += einsum("kjdb,ilac->ijklabcd", t2.abab, t2.aaaa) - t4_abaaabaa += einsum("kjab,ilcd->ijklabcd", t2.abab, t2.aaaa) - t4_abaaabaa += einsum("ijdb,klac->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_abaaabaa += einsum("ijab,klcd->ijklabcd", t2.abab, t2.aaaa) * -1.0 + t4_aaabaaab += einsum("ijklabcd->ijklabcd", c4_aaabaaab) + t4_aaabaaab += einsum("ia,jlkbdc->ijklabcd", t1_aa, t3_abaaba) * -1.0 + t4_aaabaaab += einsum("ic,jlkadb->ijklabcd", t1_aa, t3_abaaba) * -1.0 + t4_aaabaaab += einsum("ja,ilkbdc->ijklabcd", t1_aa, t3_abaaba) + t4_aaabaaab += einsum("jc,ilkadb->ijklabcd", t1_aa, t3_abaaba) + t4_aaabaaab += einsum("ka,iljbdc->ijklabcd", t1_aa, t3_abaaba) * -1.0 + t4_aaabaaab += einsum("kc,iljadb->ijklabcd", t1_aa, t3_abaaba) * -1.0 + t4_aaabaaab += einsum("klcd,ijab->ijklabcd", t2_abab, t2_aaaa) * -1.0 + t4_aaabaaab += einsum("klad,ijbc->ijklabcd", t2_abab, t2_aaaa) * -1.0 + t4_aaabaaab += einsum("jlcd,ikab->ijklabcd", t2_abab, t2_aaaa) + t4_aaabaaab += einsum("jlad,ikbc->ijklabcd", t2_abab, t2_aaaa) + t4_aaabaaab += einsum("ilcd,jkab->ijklabcd", t2_abab, t2_aaaa) * -1.0 + t4_aaabaaab += einsum("ilad,jkbc->ijklabcd", t2_abab, t2_aaaa) * -1.0 x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t4_abaaabaa += einsum("ijcb,lkda->ijklabcd", t2.abab, x0) - t4_abaaabaa += einsum("ljcb,kida->ijklabcd", t2.abab, x0) - t4_abaaabaa += einsum("kjcb,lida->ijklabcd", t2.abab, x0) * -1.0 + x0 += einsum("ijab->ijab", t2_aaaa) + x0 += einsum("ib,ja->ijab", t1_aa, t1_aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1_aa, t1_aa) + t4_aaabaaab += einsum("ilbd,kjca->ijklabcd", t2_abab, x0) + t4_aaabaaab += einsum("klbd,jica->ijklabcd", t2_abab, x0) + t4_aaabaaab += einsum("jlbd,kica->ijklabcd", t2_abab, x0) * -1.0 x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) - x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) - x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) - x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 - t4_abaaabaa += einsum("jb,likdac->ijklabcd", t1.bb, x1) * -1.0 + x1 += einsum("ijkabc->ijkabc", t3_aaaaaa) + x1 += einsum("ja,ikbc->ijkabc", t1_aa, t2_aaaa) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1_aa, t2_aaaa) + x1 += einsum("jc,ikab->ijkabc", t1_aa, t2_aaaa) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1_aa, t2_aaaa) + x1 += einsum("kb,ijac->ijkabc", t1_aa, t2_aaaa) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1_aa, t2_aaaa) + x1 += einsum("ia,kjcb->ijkabc", t1_aa, x0) + x1 += einsum("ic,kjba->ijkabc", t1_aa, x0) + x1 += einsum("ib,kjca->ijkabc", t1_aa, x0) * -1.0 + t4_aaabaaab += einsum("ld,kijcab->ijklabcd", t1_bb, x1) * -1.0 x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_abaaabaa += einsum("ic,jblkda->ijklabcd", t1.aa, x2) - t4_abaaabaa += einsum("lc,jbkida->ijklabcd", t1.aa, x2) - t4_abaaabaa += einsum("kc,jblida->ijklabcd", t1.aa, x2) * -1.0 - return t4_abaaabaa - -def t4_uhf_abababab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + x2 += einsum("jikbac->iajkbc", t3_abaaba) + x2 += einsum("jb,kica->iajkbc", t1_aa, t2_abab) + x2 += einsum("jc,kiba->iajkbc", t1_aa, t2_abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1_aa, t2_abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1_aa, t2_abab) + t4_aaabaaab += einsum("ib,ldkjca->ijklabcd", t1_aa, x2) + t4_aaabaaab += einsum("kb,ldjica->ijklabcd", t1_aa, x2) + t4_aaabaaab += einsum("jb,ldkica->ijklabcd", t1_aa, x2) * -1.0 t4_abababab = np.zeros((nocc[0], nocc[1], nocc[0], nocc[1], nvir[0], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t4_abababab += einsum("ijklabcd->ijklabcd", c4.abababab) - t4_abababab += einsum("ia,jklbcd->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_abababab += einsum("ic,jklbad->ijklabcd", t1.aa, t3.babbab) - t4_abababab += einsum("ka,jilbcd->ijklabcd", t1.aa, t3.babbab) - t4_abababab += einsum("kc,jilbad->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_abababab += einsum("ilab,kjcd->ijklabcd", t2.abab, t2.abab) - t4_abababab += einsum("ilcb,kjad->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_abababab += einsum("ijcd,klab->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_abababab += einsum("ijad,klcb->ijklabcd", t2.abab, t2.abab) - t4_abababab += einsum("ilad,kjcb->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_abababab += einsum("ilcd,kjab->ijklabcd", t2.abab, t2.abab) - t4_abababab += einsum("ijcb,klad->ijklabcd", t2.abab, t2.abab) - t4_abababab += einsum("ijab,klcd->ijklabcd", t2.abab, t2.abab) * -1.0 + t4_abababab += einsum("ijklabcd->ijklabcd", c4_abababab) + t4_abababab += einsum("ia,jklbcd->ijklabcd", t1_aa, t3_babbab) * -1.0 + t4_abababab += einsum("ic,jklbad->ijklabcd", t1_aa, t3_babbab) + t4_abababab += einsum("ka,jilbcd->ijklabcd", t1_aa, t3_babbab) + t4_abababab += einsum("kc,jilbad->ijklabcd", t1_aa, t3_babbab) * -1.0 + t4_abababab += einsum("ilab,kjcd->ijklabcd", t2_abab, t2_abab) + t4_abababab += einsum("ilcb,kjad->ijklabcd", t2_abab, t2_abab) * -1.0 + t4_abababab += einsum("ijcd,klab->ijklabcd", t2_abab, t2_abab) * -1.0 + t4_abababab += einsum("ijad,klcb->ijklabcd", t2_abab, t2_abab) + t4_abababab += einsum("ilad,kjcb->ijklabcd", t2_abab, t2_abab) * -1.0 + t4_abababab += einsum("ilcd,kjab->ijklabcd", t2_abab, t2_abab) + t4_abababab += einsum("ijcb,klad->ijklabcd", t2_abab, t2_abab) + t4_abababab += einsum("ijab,klcd->ijklabcd", t2_abab, t2_abab) * -1.0 x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) + x0 += einsum("ijab->ijab", t2_aaaa) + x0 += einsum("ib,ja->ijab", t1_aa, t1_aa) * -1.0 + x0 += einsum("ia,jb->ijab", t1_aa, t1_aa) x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("ijab->ijab", t2.bbbb) - x1 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x1 += einsum("ia,jb->ijab", t1.bb, t1.bb) + x1 += einsum("ijab->ijab", t2_bbbb) + x1 += einsum("ib,ja->ijab", t1_bb, t1_bb) * -1.0 + x1 += einsum("ia,jb->ijab", t1_bb, t1_bb) t4_abababab += einsum("kica,ljdb->ijklabcd", x0, x1) * -1.0 x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_abababab += einsum("jd,lbkica->ijklabcd", t1.bb, x2) - t4_abababab += einsum("lb,jdkica->ijklabcd", t1.bb, x2) - t4_abababab += einsum("jb,ldkica->ijklabcd", t1.bb, x2) * -1.0 - t4_abababab += einsum("ld,jbkica->ijklabcd", t1.bb, x2) * -1.0 - return t4_abababab - -def t4_uhf_abbaabba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_abbaabba = np.zeros((nocc[0], nocc[1], nocc[1], nocc[0], nvir[0], nvir[1], nvir[1], nvir[0]), dtype=np.float64) - t4_abbaabba += einsum("ijlkabdc->ijklabcd", c4.abababab) - t4_abbaabba += einsum("ia,jlkbdc->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_abbaabba += einsum("id,jlkbac->ijklabcd", t1.aa, t3.babbab) - t4_abbaabba += einsum("la,jikbdc->ijklabcd", t1.aa, t3.babbab) - t4_abbaabba += einsum("ld,jikbac->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_abbaabba += einsum("ikab,ljdc->ijklabcd", t2.abab, t2.abab) - t4_abbaabba += einsum("ikdb,ljac->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_abbaabba += einsum("ijdc,lkab->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_abbaabba += einsum("ijac,lkdb->ijklabcd", t2.abab, t2.abab) - t4_abbaabba += einsum("ikac,ljdb->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_abbaabba += einsum("ikdc,ljab->ijklabcd", t2.abab, t2.abab) - t4_abbaabba += einsum("ijdb,lkac->ijklabcd", t2.abab, t2.abab) - t4_abbaabba += einsum("ijab,lkdc->ijklabcd", t2.abab, t2.abab) * -1.0 - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("ijab->ijab", t2.aaaa) - x1 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x1 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t4_abbaabba += einsum("kjcb,lida->ijklabcd", x0, x1) * -1.0 - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_abbaabba += einsum("jc,kblida->ijklabcd", t1.bb, x2) - t4_abbaabba += einsum("kb,jclida->ijklabcd", t1.bb, x2) - t4_abbaabba += einsum("jb,kclida->ijklabcd", t1.bb, x2) * -1.0 - t4_abbaabba += einsum("kc,jblida->ijklabcd", t1.bb, x2) * -1.0 - return t4_abbaabba - -def t4_uhf_abbbabbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + x2 += einsum("jikbac->iajkbc", t3_abaaba) + x2 += einsum("jb,kica->iajkbc", t1_aa, t2_abab) + x2 += einsum("jc,kiba->iajkbc", t1_aa, t2_abab) * -1.0 + x2 += einsum("kb,jica->iajkbc", t1_aa, t2_abab) * -1.0 + x2 += einsum("kc,jiba->iajkbc", t1_aa, t2_abab) + t4_abababab += einsum("jd,lbkica->ijklabcd", t1_bb, x2) + t4_abababab += einsum("lb,jdkica->ijklabcd", t1_bb, x2) + t4_abababab += einsum("jb,ldkica->ijklabcd", t1_bb, x2) * -1.0 + t4_abababab += einsum("ld,jbkica->ijklabcd", t1_bb, x2) * -1.0 t4_abbbabbb = np.zeros((nocc[0], nocc[1], nocc[1], nocc[1], nvir[0], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t4_abbbabbb += einsum("ijklabcd->ijklabcd", c4.abbbabbb) - t4_abbbabbb += einsum("jb,kilcad->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_abbbabbb += einsum("jd,kilbac->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_abbbabbb += einsum("kb,jilcad->ijklabcd", t1.bb, t3.babbab) - t4_abbbabbb += einsum("kd,jilbac->ijklabcd", t1.bb, t3.babbab) - t4_abbbabbb += einsum("lb,jikcad->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_abbbabbb += einsum("ld,jikbac->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_abbbabbb += einsum("ilad,jkbc->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_abbbabbb += einsum("ilab,jkcd->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_abbbabbb += einsum("ikad,jlbc->ijklabcd", t2.abab, t2.bbbb) - t4_abbbabbb += einsum("ikab,jlcd->ijklabcd", t2.abab, t2.bbbb) - t4_abbbabbb += einsum("ijad,klbc->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_abbbabbb += einsum("ijab,klcd->ijklabcd", t2.abab, t2.bbbb) * -1.0 - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t4_abbbabbb += einsum("ilac,kjdb->ijklabcd", t2.abab, x0) - t4_abbbabbb += einsum("ijac,lkdb->ijklabcd", t2.abab, x0) - t4_abbbabbb += einsum("ikac,ljdb->ijklabcd", t2.abab, x0) * -1.0 - x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) - x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) - x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) - x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 - t4_abbbabbb += einsum("ia,ljkdbc->ijklabcd", t1.aa, x1) * -1.0 - x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1], nocc[0], nvir[0]), dtype=np.float64) - x2 += einsum("ikjacb->ijabkc", t3.babbab) - x2 += einsum("ia,kjcb->ijabkc", t1.bb, t2.abab) - x2 += einsum("ib,kjca->ijabkc", t1.bb, t2.abab) * -1.0 - x2 += einsum("ja,kicb->ijabkc", t1.bb, t2.abab) * -1.0 - x2 += einsum("jb,kica->ijabkc", t1.bb, t2.abab) - t4_abbbabbb += einsum("jc,lkdbia->ijklabcd", t1.bb, x2) - t4_abbbabbb += einsum("lc,kjdbia->ijklabcd", t1.bb, x2) - t4_abbbabbb += einsum("kc,ljdbia->ijklabcd", t1.bb, x2) * -1.0 - return t4_abbbabbb - -def t4_uhf_baaabaaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_baaabaaa = np.zeros((nocc[1], nocc[0], nocc[0], nocc[0], nvir[1], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - t4_baaabaaa += einsum("jklibcda->ijklabcd", c4.aaabaaab) - t4_baaabaaa += einsum("jb,kilcad->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_baaabaaa += einsum("jd,kilbac->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_baaabaaa += einsum("kb,jilcad->ijklabcd", t1.aa, t3.abaaba) - t4_baaabaaa += einsum("kd,jilbac->ijklabcd", t1.aa, t3.abaaba) - t4_baaabaaa += einsum("lb,jikcad->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_baaabaaa += einsum("ld,jikbac->ijklabcd", t1.aa, t3.abaaba) * -1.0 - t4_baaabaaa += einsum("lida,jkbc->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_baaabaaa += einsum("liba,jkcd->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_baaabaaa += einsum("kida,jlbc->ijklabcd", t2.abab, t2.aaaa) - t4_baaabaaa += einsum("kiba,jlcd->ijklabcd", t2.abab, t2.aaaa) - t4_baaabaaa += einsum("jida,klbc->ijklabcd", t2.abab, t2.aaaa) * -1.0 - t4_baaabaaa += einsum("jiba,klcd->ijklabcd", t2.abab, t2.aaaa) * -1.0 - x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t4_baaabaaa += einsum("jica,lkdb->ijklabcd", t2.abab, x0) - t4_baaabaaa += einsum("lica,kjdb->ijklabcd", t2.abab, x0) - t4_baaabaaa += einsum("kica,ljdb->ijklabcd", t2.abab, x0) * -1.0 - x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.aaaaaa) - x1 += einsum("ja,ikbc->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("jc,ikab->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("kb,ijac->ijkabc", t1.aa, t2.aaaa) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.aa, t2.aaaa) - x1 += einsum("ia,kjcb->ijkabc", t1.aa, x0) - x1 += einsum("ic,kjba->ijkabc", t1.aa, x0) - x1 += einsum("ib,kjca->ijkabc", t1.aa, x0) * -1.0 - t4_baaabaaa += einsum("ia,ljkdbc->ijklabcd", t1.bb, x1) * -1.0 - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_baaabaaa += einsum("jc,ialkdb->ijklabcd", t1.aa, x2) - t4_baaabaaa += einsum("lc,iakjdb->ijklabcd", t1.aa, x2) - t4_baaabaaa += einsum("kc,ialjdb->ijklabcd", t1.aa, x2) * -1.0 - return t4_baaabaaa - -def t4_uhf_baabbaab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_baabbaab = np.zeros((nocc[1], nocc[0], nocc[0], nocc[1], nvir[1], nvir[0], nvir[0], nvir[1]), dtype=np.float64) - t4_baabbaab += einsum("jiklbacd->ijklabcd", c4.abababab) - t4_baabbaab += einsum("jb,iklacd->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_baabbaab += einsum("jc,iklabd->ijklabcd", t1.aa, t3.babbab) - t4_baabbaab += einsum("kb,ijlacd->ijklabcd", t1.aa, t3.babbab) - t4_baabbaab += einsum("kc,ijlabd->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_baabbaab += einsum("jiba,klcd->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_baabbaab += einsum("jica,klbd->ijklabcd", t2.abab, t2.abab) - t4_baabbaab += einsum("jlcd,kiba->ijklabcd", t2.abab, t2.abab) - t4_baabbaab += einsum("jlbd,kica->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_baabbaab += einsum("jibd,klca->ijklabcd", t2.abab, t2.abab) - t4_baabbaab += einsum("jicd,klba->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_baabbaab += einsum("jlca,kibd->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_baabbaab += einsum("jlba,kicd->ijklabcd", t2.abab, t2.abab) - x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.aaaa) - x0 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x0 += einsum("ia,jb->ijab", t1.aa, t1.aa) - x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("ijab->ijab", t2.bbbb) - x1 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x1 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t4_baabbaab += einsum("kjcb,lida->ijklabcd", x0, x1) * -1.0 - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_baabbaab += einsum("id,lakjcb->ijklabcd", t1.bb, x2) - t4_baabbaab += einsum("la,idkjcb->ijklabcd", t1.bb, x2) - t4_baabbaab += einsum("ia,ldkjcb->ijklabcd", t1.bb, x2) * -1.0 - t4_baabbaab += einsum("ld,iakjcb->ijklabcd", t1.bb, x2) * -1.0 - return t4_baabbaab - -def t4_uhf_babababa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_babababa = np.zeros((nocc[1], nocc[0], nocc[1], nocc[0], nvir[1], nvir[0], nvir[1], nvir[0]), dtype=np.float64) - t4_babababa += einsum("jilkbadc->ijklabcd", c4.abababab) - t4_babababa += einsum("jb,ilkadc->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_babababa += einsum("jd,ilkabc->ijklabcd", t1.aa, t3.babbab) - t4_babababa += einsum("lb,ijkadc->ijklabcd", t1.aa, t3.babbab) - t4_babababa += einsum("ld,ijkabc->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_babababa += einsum("jiba,lkdc->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_babababa += einsum("jida,lkbc->ijklabcd", t2.abab, t2.abab) - t4_babababa += einsum("jkdc,liba->ijklabcd", t2.abab, t2.abab) - t4_babababa += einsum("jkbc,lida->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_babababa += einsum("jibc,lkda->ijklabcd", t2.abab, t2.abab) - t4_babababa += einsum("jidc,lkba->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_babababa += einsum("jkda,libc->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_babababa += einsum("jkba,lidc->ijklabcd", t2.abab, t2.abab) - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("ijab->ijab", t2.aaaa) - x1 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x1 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t4_babababa += einsum("kica,ljdb->ijklabcd", x0, x1) * -1.0 - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_babababa += einsum("ic,kaljdb->ijklabcd", t1.bb, x2) - t4_babababa += einsum("ka,icljdb->ijklabcd", t1.bb, x2) - t4_babababa += einsum("ia,kcljdb->ijklabcd", t1.bb, x2) * -1.0 - t4_babababa += einsum("kc,ialjdb->ijklabcd", t1.bb, x2) * -1.0 - return t4_babababa - -def t4_uhf_babbbabb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_babbbabb = np.zeros((nocc[1], nocc[0], nocc[1], nocc[1], nvir[1], nvir[0], nvir[1], nvir[1]), dtype=np.float64) - t4_babbbabb += einsum("jiklbacd->ijklabcd", c4.abbbabbb) - t4_babbbabb += einsum("ia,kjlcbd->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_babbbabb += einsum("id,kjlabc->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_babbbabb += einsum("ka,ijlcbd->ijklabcd", t1.bb, t3.babbab) - t4_babbbabb += einsum("kd,ijlabc->ijklabcd", t1.bb, t3.babbab) - t4_babbbabb += einsum("la,ijkcbd->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_babbbabb += einsum("ld,ijkabc->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_babbbabb += einsum("jlbd,ikac->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_babbbabb += einsum("jlba,ikcd->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_babbbabb += einsum("jkbd,ilac->ijklabcd", t2.abab, t2.bbbb) - t4_babbbabb += einsum("jkba,ilcd->ijklabcd", t2.abab, t2.bbbb) - t4_babbbabb += einsum("jibd,klac->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_babbbabb += einsum("jiba,klcd->ijklabcd", t2.abab, t2.bbbb) * -1.0 - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t4_babbbabb += einsum("jlbc,kida->ijklabcd", t2.abab, x0) - t4_babbbabb += einsum("jibc,lkda->ijklabcd", t2.abab, x0) - t4_babbbabb += einsum("jkbc,lida->ijklabcd", t2.abab, x0) * -1.0 - x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) - x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) - x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) - x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 - t4_babbbabb += einsum("jb,likdac->ijklabcd", t1.aa, x1) * -1.0 - x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1], nocc[0], nvir[0]), dtype=np.float64) - x2 += einsum("ikjacb->ijabkc", t3.babbab) - x2 += einsum("ia,kjcb->ijabkc", t1.bb, t2.abab) - x2 += einsum("ib,kjca->ijabkc", t1.bb, t2.abab) * -1.0 - x2 += einsum("ja,kicb->ijabkc", t1.bb, t2.abab) * -1.0 - x2 += einsum("jb,kica->ijabkc", t1.bb, t2.abab) - t4_babbbabb += einsum("ic,lkdajb->ijklabcd", t1.bb, x2) - t4_babbbabb += einsum("lc,kidajb->ijklabcd", t1.bb, x2) - t4_babbbabb += einsum("kc,lidajb->ijklabcd", t1.bb, x2) * -1.0 - return t4_babbbabb - -def t4_uhf_bbaabbaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_bbaabbaa = np.zeros((nocc[1], nocc[1], nocc[0], nocc[0], nvir[1], nvir[1], nvir[0], nvir[0]), dtype=np.float64) - t4_bbaabbaa += einsum("kiljcadb->ijklabcd", c4.abababab) - t4_bbaabbaa += einsum("kc,iljadb->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_bbaabbaa += einsum("kd,iljacb->ijklabcd", t1.aa, t3.babbab) - t4_bbaabbaa += einsum("lc,ikjadb->ijklabcd", t1.aa, t3.babbab) - t4_bbaabbaa += einsum("ld,ikjacb->ijklabcd", t1.aa, t3.babbab) * -1.0 - t4_bbaabbaa += einsum("kica,ljdb->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_bbaabbaa += einsum("kida,ljcb->ijklabcd", t2.abab, t2.abab) - t4_bbaabbaa += einsum("kjdb,lica->ijklabcd", t2.abab, t2.abab) - t4_bbaabbaa += einsum("kjcb,lida->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_bbaabbaa += einsum("kicb,ljda->ijklabcd", t2.abab, t2.abab) - t4_bbaabbaa += einsum("kidb,ljca->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_bbaabbaa += einsum("kjda,licb->ijklabcd", t2.abab, t2.abab) * -1.0 - t4_bbaabbaa += einsum("kjca,lidb->ijklabcd", t2.abab, t2.abab) - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("ijab->ijab", t2.aaaa) - x1 += einsum("ib,ja->ijab", t1.aa, t1.aa) * -1.0 - x1 += einsum("ia,jb->ijab", t1.aa, t1.aa) - t4_bbaabbaa += einsum("jiba,lkdc->ijklabcd", x0, x1) * -1.0 - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x2 += einsum("jikbac->iajkbc", t3.abaaba) - x2 += einsum("jb,kica->iajkbc", t1.aa, t2.abab) - x2 += einsum("jc,kiba->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kb,jica->iajkbc", t1.aa, t2.abab) * -1.0 - x2 += einsum("kc,jiba->iajkbc", t1.aa, t2.abab) - t4_bbaabbaa += einsum("ib,jalkdc->ijklabcd", t1.bb, x2) - t4_bbaabbaa += einsum("ja,iblkdc->ijklabcd", t1.bb, x2) - t4_bbaabbaa += einsum("ia,jblkdc->ijklabcd", t1.bb, x2) * -1.0 - t4_bbaabbaa += einsum("jb,ialkdc->ijklabcd", t1.bb, x2) * -1.0 - return t4_bbaabbaa - -def t4_uhf_bbabbbab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_bbabbbab = np.zeros((nocc[1], nocc[1], nocc[0], nocc[1], nvir[1], nvir[1], nvir[0], nvir[1]), dtype=np.float64) - t4_bbabbbab += einsum("kijlcabd->ijklabcd", c4.abbbabbb) - t4_bbabbbab += einsum("ia,jklbcd->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_bbabbbab += einsum("id,jklacb->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_bbabbbab += einsum("ja,iklbcd->ijklabcd", t1.bb, t3.babbab) - t4_bbabbbab += einsum("jd,iklacb->ijklabcd", t1.bb, t3.babbab) - t4_bbabbbab += einsum("la,ikjbcd->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_bbabbbab += einsum("ld,ikjacb->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_bbabbbab += einsum("klcd,ijab->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_bbabbbab += einsum("klca,ijbd->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_bbabbbab += einsum("kjcd,ilab->ijklabcd", t2.abab, t2.bbbb) - t4_bbabbbab += einsum("kjca,ilbd->ijklabcd", t2.abab, t2.bbbb) - t4_bbabbbab += einsum("kicd,jlab->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_bbabbbab += einsum("kica,jlbd->ijklabcd", t2.abab, t2.bbbb) * -1.0 + t4_abbbabbb += einsum("ijklabcd->ijklabcd", c4_abbbabbb) + t4_abbbabbb += einsum("jb,kilcad->ijklabcd", t1_bb, t3_babbab) * -1.0 + t4_abbbabbb += einsum("jd,kilbac->ijklabcd", t1_bb, t3_babbab) * -1.0 + t4_abbbabbb += einsum("kb,jilcad->ijklabcd", t1_bb, t3_babbab) + t4_abbbabbb += einsum("kd,jilbac->ijklabcd", t1_bb, t3_babbab) + t4_abbbabbb += einsum("lb,jikcad->ijklabcd", t1_bb, t3_babbab) * -1.0 + t4_abbbabbb += einsum("ld,jikbac->ijklabcd", t1_bb, t3_babbab) * -1.0 + t4_abbbabbb += einsum("ilad,jkbc->ijklabcd", t2_abab, t2_bbbb) * -1.0 + t4_abbbabbb += einsum("ilab,jkcd->ijklabcd", t2_abab, t2_bbbb) * -1.0 + t4_abbbabbb += einsum("ikad,jlbc->ijklabcd", t2_abab, t2_bbbb) + t4_abbbabbb += einsum("ikab,jlcd->ijklabcd", t2_abab, t2_bbbb) + t4_abbbabbb += einsum("ijad,klbc->ijklabcd", t2_abab, t2_bbbb) * -1.0 + t4_abbbabbb += einsum("ijab,klcd->ijklabcd", t2_abab, t2_bbbb) * -1.0 x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t4_bbabbbab += einsum("klcb,jida->ijklabcd", t2.abab, x0) - t4_bbabbbab += einsum("kicb,ljda->ijklabcd", t2.abab, x0) - t4_bbabbbab += einsum("kjcb,lida->ijklabcd", t2.abab, x0) * -1.0 + x0 += einsum("ijab->ijab", t2_bbbb) + x0 += einsum("ib,ja->ijab", t1_bb, t1_bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1_bb, t1_bb) + t4_abbbabbb += einsum("ilac,kjdb->ijklabcd", t2_abab, x0) + t4_abbbabbb += einsum("ijac,lkdb->ijklabcd", t2_abab, x0) + t4_abbbabbb += einsum("ikac,ljdb->ijklabcd", t2_abab, x0) * -1.0 x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) - x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) - x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) - x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 - t4_bbabbbab += einsum("kc,lijdab->ijklabcd", t1.aa, x1) * -1.0 + x1 += einsum("ijkabc->ijkabc", t3_bbbbbb) + x1 += einsum("ja,ikbc->ijkabc", t1_bb, t2_bbbb) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1_bb, t2_bbbb) + x1 += einsum("jc,ikab->ijkabc", t1_bb, t2_bbbb) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1_bb, t2_bbbb) + x1 += einsum("kb,ijac->ijkabc", t1_bb, t2_bbbb) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1_bb, t2_bbbb) + x1 += einsum("ia,kjcb->ijkabc", t1_bb, x0) + x1 += einsum("ic,kjba->ijkabc", t1_bb, x0) + x1 += einsum("ib,kjca->ijkabc", t1_bb, x0) * -1.0 + t4_abbbabbb += einsum("ia,ljkdbc->ijklabcd", t1_aa, x1) * -1.0 x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1], nocc[0], nvir[0]), dtype=np.float64) - x2 += einsum("ikjacb->ijabkc", t3.babbab) - x2 += einsum("ia,kjcb->ijabkc", t1.bb, t2.abab) - x2 += einsum("ib,kjca->ijabkc", t1.bb, t2.abab) * -1.0 - x2 += einsum("ja,kicb->ijabkc", t1.bb, t2.abab) * -1.0 - x2 += einsum("jb,kica->ijabkc", t1.bb, t2.abab) - t4_bbabbbab += einsum("ib,ljdakc->ijklabcd", t1.bb, x2) - t4_bbabbbab += einsum("lb,jidakc->ijklabcd", t1.bb, x2) - t4_bbabbbab += einsum("jb,lidakc->ijklabcd", t1.bb, x2) * -1.0 - return t4_bbabbbab - -def t4_uhf_bbbabbba(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4_bbbabbba = np.zeros((nocc[1], nocc[1], nocc[1], nocc[0], nvir[1], nvir[1], nvir[1], nvir[0]), dtype=np.float64) - t4_bbbabbba += einsum("lijkdabc->ijklabcd", c4.abbbabbb) - t4_bbbabbba += einsum("ia,jlkbdc->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_bbbabbba += einsum("ic,jlkadb->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_bbbabbba += einsum("ja,ilkbdc->ijklabcd", t1.bb, t3.babbab) - t4_bbbabbba += einsum("jc,ilkadb->ijklabcd", t1.bb, t3.babbab) - t4_bbbabbba += einsum("ka,iljbdc->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_bbbabbba += einsum("kc,iljadb->ijklabcd", t1.bb, t3.babbab) * -1.0 - t4_bbbabbba += einsum("lkdc,ijab->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_bbbabbba += einsum("lkda,ijbc->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_bbbabbba += einsum("ljdc,ikab->ijklabcd", t2.abab, t2.bbbb) - t4_bbbabbba += einsum("ljda,ikbc->ijklabcd", t2.abab, t2.bbbb) - t4_bbbabbba += einsum("lidc,jkab->ijklabcd", t2.abab, t2.bbbb) * -1.0 - t4_bbbabbba += einsum("lida,jkbc->ijklabcd", t2.abab, t2.bbbb) * -1.0 - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) - t4_bbbabbba += einsum("lkdb,jica->ijklabcd", t2.abab, x0) - t4_bbbabbba += einsum("lidb,kjca->ijklabcd", t2.abab, x0) - t4_bbbabbba += einsum("ljdb,kica->ijklabcd", t2.abab, x0) * -1.0 - x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) - x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) - x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) - x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 - t4_bbbabbba += einsum("ld,kijcab->ijklabcd", t1.aa, x1) * -1.0 - x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1], nocc[0], nvir[0]), dtype=np.float64) - x2 += einsum("ikjacb->ijabkc", t3.babbab) - x2 += einsum("ia,kjcb->ijabkc", t1.bb, t2.abab) - x2 += einsum("ib,kjca->ijabkc", t1.bb, t2.abab) * -1.0 - x2 += einsum("ja,kicb->ijabkc", t1.bb, t2.abab) * -1.0 - x2 += einsum("jb,kica->ijabkc", t1.bb, t2.abab) - t4_bbbabbba += einsum("ib,kjcald->ijklabcd", t1.bb, x2) - t4_bbbabbba += einsum("kb,jicald->ijklabcd", t1.bb, x2) - t4_bbbabbba += einsum("jb,kicald->ijklabcd", t1.bb, x2) * -1.0 - return t4_bbbabbba - -def t4_uhf_bbbbbbbb(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): + x2 += einsum("ikjacb->ijabkc", t3_babbab) + x2 += einsum("ia,kjcb->ijabkc", t1_bb, t2_abab) + x2 += einsum("ib,kjca->ijabkc", t1_bb, t2_abab) * -1.0 + x2 += einsum("ja,kicb->ijabkc", t1_bb, t2_abab) * -1.0 + x2 += einsum("jb,kica->ijabkc", t1_bb, t2_abab) + t4_abbbabbb += einsum("jc,lkdbia->ijklabcd", t1_bb, x2) + t4_abbbabbb += einsum("lc,kjdbia->ijklabcd", t1_bb, x2) + t4_abbbabbb += einsum("kc,ljdbia->ijklabcd", t1_bb, x2) * -1.0 t4_bbbbbbbb = np.zeros((nocc[1], nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - t4_bbbbbbbb += einsum("ijklabcd->ijklabcd", c4.bbbbbbbb) - t4_bbbbbbbb += einsum("la,ijkbcd->ijklabcd", t1.bb, t3.bbbbbb) - t4_bbbbbbbb += einsum("lb,ijkacd->ijklabcd", t1.bb, t3.bbbbbb) * -1.0 - t4_bbbbbbbb += einsum("lc,ijkabd->ijklabcd", t1.bb, t3.bbbbbb) - t4_bbbbbbbb += einsum("ld,ijkabc->ijklabcd", t1.bb, t3.bbbbbb) * -1.0 - t4_bbbbbbbb += einsum("ilcd,jkab->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ilbd,jkac->ijklabcd", t2.bbbb, t2.bbbb) - t4_bbbbbbbb += einsum("ilad,jkbc->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ilbc,jkad->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ilac,jkbd->ijklabcd", t2.bbbb, t2.bbbb) - t4_bbbbbbbb += einsum("ilab,jkcd->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ikcd,jlab->ijklabcd", t2.bbbb, t2.bbbb) - t4_bbbbbbbb += einsum("ikbd,jlac->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ikad,jlbc->ijklabcd", t2.bbbb, t2.bbbb) - t4_bbbbbbbb += einsum("ikbc,jlad->ijklabcd", t2.bbbb, t2.bbbb) - t4_bbbbbbbb += einsum("ikac,jlbd->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ikab,jlcd->ijklabcd", t2.bbbb, t2.bbbb) - t4_bbbbbbbb += einsum("ijcd,klab->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ijbd,klac->ijklabcd", t2.bbbb, t2.bbbb) - t4_bbbbbbbb += einsum("ijad,klbc->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ijbc,klad->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 - t4_bbbbbbbb += einsum("ijac,klbd->ijklabcd", t2.bbbb, t2.bbbb) - t4_bbbbbbbb += einsum("ijab,klcd->ijklabcd", t2.bbbb, t2.bbbb) * -1.0 + t4_bbbbbbbb += einsum("ijklabcd->ijklabcd", c4_bbbbbbbb) + t4_bbbbbbbb += einsum("la,ijkbcd->ijklabcd", t1_bb, t3_bbbbbb) + t4_bbbbbbbb += einsum("lb,ijkacd->ijklabcd", t1_bb, t3_bbbbbb) * -1.0 + t4_bbbbbbbb += einsum("lc,ijkabd->ijklabcd", t1_bb, t3_bbbbbb) + t4_bbbbbbbb += einsum("ld,ijkabc->ijklabcd", t1_bb, t3_bbbbbb) * -1.0 + t4_bbbbbbbb += einsum("ilcd,jkab->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ilbd,jkac->ijklabcd", t2_bbbb, t2_bbbb) + t4_bbbbbbbb += einsum("ilad,jkbc->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ilbc,jkad->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ilac,jkbd->ijklabcd", t2_bbbb, t2_bbbb) + t4_bbbbbbbb += einsum("ilab,jkcd->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ikcd,jlab->ijklabcd", t2_bbbb, t2_bbbb) + t4_bbbbbbbb += einsum("ikbd,jlac->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ikad,jlbc->ijklabcd", t2_bbbb, t2_bbbb) + t4_bbbbbbbb += einsum("ikbc,jlad->ijklabcd", t2_bbbb, t2_bbbb) + t4_bbbbbbbb += einsum("ikac,jlbd->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ikab,jlcd->ijklabcd", t2_bbbb, t2_bbbb) + t4_bbbbbbbb += einsum("ijcd,klab->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ijbd,klac->ijklabcd", t2_bbbb, t2_bbbb) + t4_bbbbbbbb += einsum("ijad,klbc->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ijbc,klad->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 + t4_bbbbbbbb += einsum("ijac,klbd->ijklabcd", t2_bbbb, t2_bbbb) + t4_bbbbbbbb += einsum("ijab,klcd->ijklabcd", t2_bbbb, t2_bbbb) * -1.0 x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("ijab->ijab", t2.bbbb) - x0 += einsum("ib,ja->ijab", t1.bb, t1.bb) * -1.0 - x0 += einsum("ia,jb->ijab", t1.bb, t1.bb) + x0 += einsum("ijab->ijab", t2_bbbb) + x0 += einsum("ib,ja->ijab", t1_bb, t1_bb) * -1.0 + x0 += einsum("ia,jb->ijab", t1_bb, t1_bb) x1 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("ijkabc->ijkabc", t3.bbbbbb) - x1 += einsum("ja,ikbc->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("jb,ikac->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("jc,ikab->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 - x1 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) - x1 += einsum("ia,kjcb->ijkabc", t1.bb, x0) - x1 += einsum("ic,kjba->ijkabc", t1.bb, x0) - x1 += einsum("ib,kjca->ijkabc", t1.bb, x0) * -1.0 - t4_bbbbbbbb += einsum("ib,ljkdac->ijklabcd", t1.bb, x1) - t4_bbbbbbbb += einsum("id,ljkcab->ijklabcd", t1.bb, x1) - t4_bbbbbbbb += einsum("ia,ljkdbc->ijklabcd", t1.bb, x1) * -1.0 - t4_bbbbbbbb += einsum("ic,ljkdab->ijklabcd", t1.bb, x1) * -1.0 + x1 += einsum("ijkabc->ijkabc", t3_bbbbbb) + x1 += einsum("ja,ikbc->ijkabc", t1_bb, t2_bbbb) * -1.0 + x1 += einsum("jb,ikac->ijkabc", t1_bb, t2_bbbb) + x1 += einsum("jc,ikab->ijkabc", t1_bb, t2_bbbb) * -1.0 + x1 += einsum("ka,ijbc->ijkabc", t1_bb, t2_bbbb) + x1 += einsum("kb,ijac->ijkabc", t1_bb, t2_bbbb) * -1.0 + x1 += einsum("kc,ijab->ijkabc", t1_bb, t2_bbbb) + x1 += einsum("ia,kjcb->ijkabc", t1_bb, x0) + x1 += einsum("ic,kjba->ijkabc", t1_bb, x0) + x1 += einsum("ib,kjca->ijkabc", t1_bb, x0) * -1.0 + t4_bbbbbbbb += einsum("ib,ljkdac->ijklabcd", t1_bb, x1) + t4_bbbbbbbb += einsum("id,ljkcab->ijklabcd", t1_bb, x1) + t4_bbbbbbbb += einsum("ia,ljkdbc->ijklabcd", t1_bb, x1) * -1.0 + t4_bbbbbbbb += einsum("ic,ljkdab->ijklabcd", t1_bb, x1) * -1.0 x2 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - x2 += einsum("ijkabc->ijkabc", t3.bbbbbb) - x2 += einsum("ia,jkbc->ijkabc", t1.bb, t2.bbbb) - x2 += einsum("ib,jkac->ijkabc", t1.bb, t2.bbbb) * -1.0 - x2 += einsum("ic,jkab->ijkabc", t1.bb, t2.bbbb) - x2 += einsum("ka,ijbc->ijkabc", t1.bb, t2.bbbb) - x2 += einsum("kb,ijac->ijkabc", t1.bb, t2.bbbb) * -1.0 - x2 += einsum("kc,ijab->ijkabc", t1.bb, t2.bbbb) - t4_bbbbbbbb += einsum("ja,likdbc->ijklabcd", t1.bb, x2) - t4_bbbbbbbb += einsum("jc,likdab->ijklabcd", t1.bb, x2) - t4_bbbbbbbb += einsum("jb,likdac->ijklabcd", t1.bb, x2) * -1.0 - t4_bbbbbbbb += einsum("jd,likcab->ijklabcd", t1.bb, x2) * -1.0 + x2 += einsum("ijkabc->ijkabc", t3_bbbbbb) + x2 += einsum("ia,jkbc->ijkabc", t1_bb, t2_bbbb) + x2 += einsum("ib,jkac->ijkabc", t1_bb, t2_bbbb) * -1.0 + x2 += einsum("ic,jkab->ijkabc", t1_bb, t2_bbbb) + x2 += einsum("ka,ijbc->ijkabc", t1_bb, t2_bbbb) + x2 += einsum("kb,ijac->ijkabc", t1_bb, t2_bbbb) * -1.0 + x2 += einsum("kc,ijab->ijkabc", t1_bb, t2_bbbb) + t4_bbbbbbbb += einsum("ja,likdbc->ijklabcd", t1_bb, x2) + t4_bbbbbbbb += einsum("jc,likdab->ijklabcd", t1_bb, x2) + t4_bbbbbbbb += einsum("jb,likdac->ijklabcd", t1_bb, x2) * -1.0 + t4_bbbbbbbb += einsum("jd,likcab->ijklabcd", t1_bb, x2) * -1.0 x3 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1], nvir[1], nvir[1]), dtype=np.float64) - x3 += einsum("ijkabc->ijkabc", t3.bbbbbb) - x3 += einsum("ia,jkbc->ijkabc", t1.bb, t2.bbbb) - x3 += einsum("ib,jkac->ijkabc", t1.bb, t2.bbbb) * -1.0 - x3 += einsum("ic,jkab->ijkabc", t1.bb, t2.bbbb) - t4_bbbbbbbb += einsum("kb,lijdac->ijklabcd", t1.bb, x3) - t4_bbbbbbbb += einsum("kd,lijcab->ijklabcd", t1.bb, x3) - t4_bbbbbbbb += einsum("ka,lijdbc->ijklabcd", t1.bb, x3) * -1.0 - t4_bbbbbbbb += einsum("kc,lijdab->ijklabcd", t1.bb, x3) * -1.0 - return t4_bbbbbbbb - -def t4_rhf_abab(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) - t4 += einsum("ijklabcd->ijklabcd", c4) - t4 += einsum("jb,ilkadc->ijklabcd", t1, t3) * -1.0 - t4 += einsum("jd,ilkabc->ijklabcd", t1, t3) - t4 += einsum("lb,ijkadc->ijklabcd", t1, t3) - t4 += einsum("ld,ijkabc->ijklabcd", t1, t3) * -1.0 - t4 += einsum("ijab,klcd->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ijad,klcb->ijklabcd", t2, t2) - t4 += einsum("ijcb,klad->ijklabcd", t2, t2) - t4 += einsum("ijcd,klab->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ilab,kjcd->ijklabcd", t2, t2) - t4 += einsum("ilad,kjcb->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ilcb,kjad->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ilcd,kjab->ijklabcd", t2, t2) + x3 += einsum("ijkabc->ijkabc", t3_bbbbbb) + x3 += einsum("ia,jkbc->ijkabc", t1_bb, t2_bbbb) + x3 += einsum("ib,jkac->ijkabc", t1_bb, t2_bbbb) * -1.0 + x3 += einsum("ic,jkab->ijkabc", t1_bb, t2_bbbb) + t4_bbbbbbbb += einsum("kb,lijdac->ijklabcd", t1_bb, x3) + t4_bbbbbbbb += einsum("kd,lijcab->ijklabcd", t1_bb, x3) + t4_bbbbbbbb += einsum("ka,lijdbc->ijklabcd", t1_bb, x3) * -1.0 + t4_bbbbbbbb += einsum("kc,lijdab->ijklabcd", t1_bb, x3) * -1.0 + return t4_aaaaaaaa, t4_aaabaaab, t4_abababab, t4_abbbabbb, t4_bbbbbbbb + +def t4_rhf(t1, t2, t3, c4): + nocc, nvir = t1.shape + c4_abaaabaa, c4_abababab = c4 + t4_abababab = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) + t4_abababab += einsum("ijklabcd->ijklabcd", c4_abababab) + t4_abababab += einsum("jb,ilkadc->ijklabcd", t1, t3) * -1.0 + t4_abababab += einsum("jd,ilkabc->ijklabcd", t1, t3) + t4_abababab += einsum("lb,ijkadc->ijklabcd", t1, t3) + t4_abababab += einsum("ld,ijkabc->ijklabcd", t1, t3) * -1.0 + t4_abababab += einsum("ijab,klcd->ijklabcd", t2, t2) * -1.0 + t4_abababab += einsum("ijad,klcb->ijklabcd", t2, t2) + t4_abababab += einsum("ijcb,klad->ijklabcd", t2, t2) + t4_abababab += einsum("ijcd,klab->ijklabcd", t2, t2) * -1.0 + t4_abababab += einsum("ilab,kjcd->ijklabcd", t2, t2) + t4_abababab += einsum("ilad,kjcb->ijklabcd", t2, t2) * -1.0 + t4_abababab += einsum("ilcb,kjad->ijklabcd", t2, t2) * -1.0 + t4_abababab += einsum("ilcd,kjab->ijklabcd", t2, t2) x0 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) x0 += einsum("ijab->ijab", t2) * -1.0 x0 += einsum("ijba->ijab", t2) x0 += einsum("ib,ja->ijab", t1, t1) x0 += einsum("ia,jb->ijab", t1, t1) * -1.0 - t4 += einsum("ikac,jldb->ijklabcd", x0, x0) + t4_abababab += einsum("ikac,jldb->ijklabcd", x0, x0) x1 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) x1 += einsum("ijkabc->ijkabc", t3) x1 += einsum("ia,jkbc->ijkabc", t1, t2) x1 += einsum("ic,jkba->ijkabc", t1, t2) * -1.0 x1 += einsum("ka,jibc->ijkabc", t1, t2) * -1.0 x1 += einsum("kc,jiba->ijkabc", t1, t2) - t4 += einsum("ic,jklbad->ijklabcd", t1, x1) - t4 += einsum("ka,jilbcd->ijklabcd", t1, x1) - t4 += einsum("ia,jklbcd->ijklabcd", t1, x1) * -1.0 - t4 += einsum("kc,jilbad->ijklabcd", t1, x1) * -1.0 - return t4 - -def t4_rhf_abaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): - t4 = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) - t4 += einsum("ikljacdb->ijklabcd", c4) - t4 += einsum("ia,kjlcbd->ijklabcd", t1, t3) * -1.0 - t4 += einsum("id,kjlabc->ijklabcd", t1, t3) * -1.0 - t4 += einsum("ka,ijlcbd->ijklabcd", t1, t3) - t4 += einsum("kd,ijlabc->ijklabcd", t1, t3) - t4 += einsum("la,ijkcbd->ijklabcd", t1, t3) * -1.0 - t4 += einsum("ld,ijkabc->ijklabcd", t1, t3) * -1.0 - t4 += einsum("ijab,klcd->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ijab,kldc->ijklabcd", t2, t2) - t4 += einsum("ijdb,klac->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ijdb,klca->ijklabcd", t2, t2) - t4 += einsum("ilac,kjdb->ijklabcd", t2, t2) - t4 += einsum("ilcd,kjab->ijklabcd", t2, t2) - t4 += einsum("ilca,kjdb->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ildc,kjab->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ikac,ljdb->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ikcd,ljab->ijklabcd", t2, t2) * -1.0 - t4 += einsum("ikca,ljdb->ijklabcd", t2, t2) - t4 += einsum("ikdc,ljab->ijklabcd", t2, t2) + t4_abababab += einsum("ic,jklbad->ijklabcd", t1, x1) + t4_abababab += einsum("ka,jilbcd->ijklabcd", t1, x1) + t4_abababab += einsum("ia,jklbcd->ijklabcd", t1, x1) * -1.0 + t4_abababab += einsum("kc,jilbad->ijklabcd", t1, x1) * -1.0 + t4_abaaabaa = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir), dtype=np.float64) + #t4_abaaabaa += einsum("ikljacdb->ijklabcd", c4_abaaabaa) # NOTE incorrect in generated eqns + t4_abaaabaa += einsum("ijklabcd->ijklabcd", c4_abaaabaa) + t4_abaaabaa += einsum("ia,kjlcbd->ijklabcd", t1, t3) * -1.0 + t4_abaaabaa += einsum("id,kjlabc->ijklabcd", t1, t3) * -1.0 + t4_abaaabaa += einsum("ka,ijlcbd->ijklabcd", t1, t3) + t4_abaaabaa += einsum("kd,ijlabc->ijklabcd", t1, t3) + t4_abaaabaa += einsum("la,ijkcbd->ijklabcd", t1, t3) * -1.0 + t4_abaaabaa += einsum("ld,ijkabc->ijklabcd", t1, t3) * -1.0 + t4_abaaabaa += einsum("ijab,klcd->ijklabcd", t2, t2) * -1.0 + t4_abaaabaa += einsum("ijab,kldc->ijklabcd", t2, t2) + t4_abaaabaa += einsum("ijdb,klac->ijklabcd", t2, t2) * -1.0 + t4_abaaabaa += einsum("ijdb,klca->ijklabcd", t2, t2) + t4_abaaabaa += einsum("ilac,kjdb->ijklabcd", t2, t2) + t4_abaaabaa += einsum("ilcd,kjab->ijklabcd", t2, t2) + t4_abaaabaa += einsum("ilca,kjdb->ijklabcd", t2, t2) * -1.0 + t4_abaaabaa += einsum("ildc,kjab->ijklabcd", t2, t2) * -1.0 + t4_abaaabaa += einsum("ikac,ljdb->ijklabcd", t2, t2) * -1.0 + t4_abaaabaa += einsum("ikcd,ljab->ijklabcd", t2, t2) * -1.0 + t4_abaaabaa += einsum("ikca,ljdb->ijklabcd", t2, t2) + t4_abaaabaa += einsum("ikdc,ljab->ijklabcd", t2, t2) x0 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) x0 += einsum("ijab->ijab", t2) * -1.0 x0 += einsum("ijba->ijab", t2) x0 += einsum("ib,ja->ijab", t1, t1) x0 += einsum("ia,jb->ijab", t1, t1) * -1.0 - t4 += einsum("kjcb,ilda->ijklabcd", t2, x0) * -1.0 + t4_abaaabaa += einsum("kjcb,ilda->ijklabcd", t2, x0) * -1.0 x1 = np.zeros((nocc, nocc, nvir, nvir), dtype=np.float64) x1 += einsum("ijab->ijab", t2) x1 += einsum("ijba->ijab", t2) * -1.0 x1 += einsum("ib,ja->ijab", t1, t1) * -1.0 x1 += einsum("ia,jb->ijab", t1, t1) - t4 += einsum("ijcb,klda->ijklabcd", t2, x1) * -1.0 - t4 += einsum("ljcb,ikda->ijklabcd", t2, x1) * -1.0 + t4_abaaabaa += einsum("ijcb,klda->ijklabcd", t2, x1) * -1.0 + t4_abaaabaa += einsum("ljcb,ikda->ijklabcd", t2, x1) * -1.0 x2 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) x2 += einsum("ijkabc->ijkabc", t3) * -1.0 x2 += einsum("ijkacb->ijkabc", t3) @@ -979,15 +458,14 @@ def t4_rhf_abaa(c4=None, t1=None, t2=None, t3=None, nocc=None, nvir=None): x2 += einsum("ia,jkcb->ijkabc", t1, x0) * -1.0 x2 += einsum("ib,jkca->ijkabc", t1, x1) * -1.0 x2 += einsum("ic,jkab->ijkabc", t1, x1) * -1.0 - t4 += einsum("jb,iklacd->ijklabcd", t1, x2) + t4_abaaabaa += einsum("jb,iklacd->ijklabcd", t1, x2) x3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir), dtype=np.float64) x3 += einsum("ijkabc->ijkabc", t3) x3 += einsum("ia,kjcb->ijkabc", t1, t2) x3 += einsum("ic,kjab->ijkabc", t1, t2) * -1.0 x3 += einsum("ka,ijcb->ijkabc", t1, t2) * -1.0 x3 += einsum("kc,ijab->ijkabc", t1, t2) - t4 += einsum("ic,kjlabd->ijklabcd", t1, x3) - t4 += einsum("lc,ijkabd->ijklabcd", t1, x3) - t4 += einsum("kc,ijlabd->ijklabcd", t1, x3) * -1.0 - return t4 - + t4_abaaabaa += einsum("ic,kjlabd->ijklabcd", t1, x3) + t4_abaaabaa += einsum("lc,ijkabd->ijklabcd", t1, x3) + t4_abaaabaa += einsum("kc,ijlabd->ijklabcd", t1, x3) * -1.0 + return t4_abaaabaa, t4_abababab diff --git a/vayesta/solver/ccsdtq.py b/vayesta/solver/ccsdtq.py new file mode 100644 index 000000000..5aeca6851 --- /dev/null +++ b/vayesta/solver/ccsdtq.py @@ -0,0 +1,206 @@ +import numpy as np +from vayesta.core.util import einsum + +def t1_residual_uhf(t1, t2, t3, t4, f, v): + t1_aa, t1_bb = t1 + t2_aaaa, t2_abab, t2_bbbb = t2 + t3_aaaaaa, t3_abaaba, t3_babbab, t3_bbbbbb = t3 + t4_aaaaaaaa, t4_aaabaaab, t4_abababab, t4_abbbabbb, t4_bbbbbbbb = t4 + f_aa_ov, f_bb_ov = f + v_ooov, v_ovov, v_ovvv, v_vvov, v_ovoo = v + v_aaaa_ooov, v_aabb_ooov, v_bbbb_ooov = v_ooov + v_aaaa_ovov, v_aabb_ovov, v_bbbb_ovov = v_ovov + v_aaaa_ovvv, v_aabb_ovvv, v_bbbb_ovvv = v_ovvv + v_aaaa_vvov, v_aabb_vvov, v_bbbb_vvov = v_vvov + v_aaaa_ovoo, v_aabb_ovoo, v_bbbb_ovoo = v_ovoo + nocc = (t1_aa.shape[0], t1_bb.shape[0]) + nvir = (t1_aa.shape[1], t1_bb.shape[1]) + t1new_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + t1new_aa += einsum("jbkc,ijkabc->ia", v_aaaa_ovov, t3_aaaaaa) * 0.5 + t1new_aa += einsum("ldme,limdae->ia", v_bbbb_ovov, t3_babbab) * 0.5 + t1new_aa += einsum("jbmd,imjadb->ia", v_aabb_ovov, t3_abaaba) + t1new_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + t1new_bb += einsum("jbkc,jikbac->ia", v_aaaa_ovov, t3_abaaba) * 0.5 + t1new_bb += einsum("ldme,ilmade->ia", v_bbbb_ovov, t3_bbbbbb) * 0.5 + t1new_bb += einsum("kcmd,ikmacd->ia", v_aabb_ovov, t3_babbab) + return t1new_aa, t1new_bb + +def t2_residual_uhf(t1, t2, t3, t4, f, v): + t1_aa, t1_bb = t1 + t2_aaaa, t2_abab, t2_bbbb = t2 + t3_aaaaaa, t3_abaaba, t3_babbab, t3_bbbbbb = t3 + t4_aaaaaaaa, t4_aaabaaab, t4_abababab, t4_abbbabbb, t4_bbbbbbbb = t4 + f_aa_ov, f_bb_ov = f + v_ooov, v_ovov, v_ovvv, v_vvov, v_ovoo = v + v_aaaa_ooov, v_aabb_ooov, v_bbbb_ooov = v_ooov + v_aaaa_ovov, v_aabb_ovov, v_bbbb_ovov = v_ovov + v_aaaa_ovvv, v_aabb_ovvv, v_bbbb_ovvv = v_ovvv + v_aaaa_vvov, v_aabb_vvov, v_bbbb_vvov = v_vvov + v_aaaa_ovoo, v_aabb_ovoo, v_bbbb_ovoo = v_ovoo + nocc = (t1_aa.shape[0], t1_bb.shape[0]) + nvir = (t1_aa.shape[1], t1_bb.shape[1]) + t2new_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + t2new_aaaa += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_aaaaaaaa) * 0.5 + t2new_aaaa += einsum("menf,imjnaebf->ijab", v_bbbb_ovov, t4_abababab) * 0.5 + t2new_aaaa += einsum("lcne,ijlnabce->ijab", v_aabb_ovov, t4_aaabaaab) + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("jlkc,iklacb->ijab", v_aabb_ooov, t3_abaaba) + x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("jklc,iklabc->ijab", v_aaaa_ooov, t3_aaaaaa) + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) + x2 += einsum("jb,kbia->iajk", t1_aa, v_aabb_ovov) + x3 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x3 += einsum("kcil,jklacb->ijab", x2, t3_abaaba) + x4 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x4 += einsum("ib,jakb->ijka", t1_aa, v_aaaa_ovov) + x5 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x5 += einsum("iklc,jklabc->ijab", x4, t3_aaaaaa) * -1.0 + x6 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x6 += einsum("ijba->ijab", x0) * -1.0 + x6 += einsum("ijba->ijab", x1) * -1.0 + x6 += einsum("ijba->ijab", x3) + x6 += einsum("ijba->ijab", x5) + t2new_aaaa += einsum("ijab->ijab", x6) * -1.0 + t2new_aaaa += einsum("jiab->ijab", x6) + x7 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x7 += einsum("bdkc,ikjacd->ijab", v_aabb_vvov, t3_abaaba) + x8 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x8 += einsum("kdbc,ijkacd->ijab", v_aaaa_ovvv, t3_aaaaaa) * -1.0 + x9 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x9 += einsum("kclb,iljabc->ijka", v_aabb_ovov, t3_abaaba) + x10 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x10 += einsum("kclb,ijlabc->ijka", v_aaaa_ovov, t3_aaaaaa) * -1.0 + x11 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x11 += einsum("ijka->ijka", x9) + x11 += einsum("ijka->ijka", x10) + x12 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x12 += einsum("ka,ijkb->ijab", t1_aa, x11) + x13 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x13 += einsum("ijab->ijab", x7) + x13 += einsum("ijab->ijab", x8) * -1.0 + x13 += einsum("ijab->ijab", x12) + t2new_aaaa += einsum("ijab->ijab", x13) + t2new_aaaa += einsum("ijba->ijab", x13) * -1.0 + x14 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x14 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 + x14 += einsum("iajb->ijab", v_aaaa_ovov) + x15 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + x15 += einsum("ia->ia", f_aa_ov) + x15 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) + x15 += einsum("kc,kiac->ia", t1_aa, x14) * -1.0 + t2new_aaaa += einsum("lc,ijlabc->ijab", x15, t3_aaaaaa) + x16 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x16 += einsum("ibja->ijab", v_bbbb_ovov) + x16 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 + x17 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + x17 += einsum("ia->ia", f_bb_ov) + x17 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) + x17 += einsum("kc,kica->ia", t1_bb, x16) * -1.0 + t2new_aaaa += einsum("ne,injaeb->ijab", x17, t3_abaaba) + t2new_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + t2new_bbbb += einsum("ldkc,lijkdabc->ijab", v_aabb_ovov, t4_abbbabbb) + t2new_bbbb += einsum("ldme,limjdaeb->ijab", v_aaaa_ovov, t4_abababab) * 0.5 + t2new_bbbb += einsum("kcnf,ijknabcf->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 0.5 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) + x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("lcjk,ilkacb->ijab", v_aabb_ovoo, t3_babbab) + x2 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x2 += einsum("ib,jakb->ijka", t1_bb, v_bbbb_ovov) + x3 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x3 += einsum("ilkc,jklabc->ijab", x2, t3_bbbbbb) + x4 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) + x4 += einsum("ib,kajb->ijka", t1_bb, v_aabb_ovov) + x5 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x5 += einsum("iklc,jlkacb->ijab", x4, t3_babbab) + x6 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x6 += einsum("ijba->ijab", x0) * -1.0 + x6 += einsum("ijba->ijab", x1) * -1.0 + x6 += einsum("ijba->ijab", x3) + x6 += einsum("ijba->ijab", x5) + t2new_bbbb += einsum("ijab->ijab", x6) * -1.0 + t2new_bbbb += einsum("jiab->ijab", x6) + x7 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x7 += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) + x8 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x8 += einsum("kdbc,ikjadc->ijab", v_aabb_ovvv, t3_babbab) + x9 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x9 += einsum("kclb,ijlabc->ijka", v_bbbb_ovov, t3_bbbbbb) * -1.0 + x10 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x10 += einsum("lckb,iljacb->ijka", v_aabb_ovov, t3_babbab) + x11 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x11 += einsum("ijka->ijka", x9) + x11 += einsum("ijka->ijka", x10) + x12 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x12 += einsum("ka,ijkb->ijab", t1_bb, x11) + x13 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x13 += einsum("ijab->ijab", x7) * -1.0 + x13 += einsum("ijab->ijab", x8) + x13 += einsum("ijab->ijab", x12) + t2new_bbbb += einsum("ijab->ijab", x13) + t2new_bbbb += einsum("ijba->ijab", x13) * -1.0 + x14 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x14 += einsum("ibja->ijab", v_bbbb_ovov) + x14 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 + x15 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + x15 += einsum("ia->ia", f_bb_ov) + x15 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) + x15 += einsum("kc,kica->ia", t1_bb, x14) * -1.0 + t2new_bbbb += einsum("kc,ijkabc->ijab", x15, t3_bbbbbb) + x16 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x16 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 + x16 += einsum("iajb->ijab", v_aaaa_ovov) + x17 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + x17 += einsum("ia->ia", f_aa_ov) + x17 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) + x17 += einsum("kc,kiac->ia", t1_aa, x16) * -1.0 + t2new_bbbb += einsum("ld,iljadb->ijab", x17, t3_babbab) + t2new_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) + t2new_abab += einsum("kcld,ikljacdb->ijab", v_aaaa_ovov, t4_aaabaaab) * 0.5 + t2new_abab += einsum("kcbe,ijkaec->ijab", v_aabb_ovvv, t3_abaaba) + t2new_abab += einsum("mebf,jimeaf->ijab", v_bbbb_ovvv, t3_babbab) * -1.0 + t2new_abab += einsum("kcad,ijkcbd->ijab", v_aaaa_ovvv, t3_abaaba) * -1.0 + t2new_abab += einsum("acme,jimbce->ijab", v_aabb_vvov, t3_babbab) + t2new_abab += einsum("mfne,ijmnabef->ijab", v_bbbb_ovov, t4_abbbabbb) * -0.5 + t2new_abab += einsum("kcme,ijkmabce->ijab", v_aabb_ovov, t4_abababab) + x0 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) + x0 += einsum("jkia->iajk", v_aabb_ooov) + x0 += einsum("kb,jbia->iajk", t1_aa, v_aabb_ovov) + t2new_abab += einsum("meki,jkmbae->ijab", x0, t3_babbab) * -1.0 + x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x1 += einsum("ikja->ijka", v_aaaa_ooov) + x1 += einsum("ib,jakb->ijka", t1_aa, v_aaaa_ovov) + t2new_abab += einsum("iklc,kjlabc->ijab", x1, t3_abaaba) + x2 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x2 += einsum("ikja->ijka", v_bbbb_ooov) + x2 += einsum("ib,jakb->ijka", t1_bb, v_bbbb_ovov) + t2new_abab += einsum("jnme,minbae->ijab", x2, t3_babbab) * -1.0 + x3 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) + x3 += einsum("kaij->ijka", v_aabb_ovoo) + x3 += einsum("jb,kaib->ijka", t1_bb, v_aabb_ovov) + t2new_abab += einsum("mjkc,imkabc->ijab", x3, t3_abaaba) * -1.0 + x4 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x4 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 + x4 += einsum("iajb->ijab", v_aaaa_ovov) + x5 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + x5 += einsum("ia->ia", f_aa_ov) + x5 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) + x5 += einsum("kc,kiac->ia", t1_aa, x4) * -1.0 + t2new_abab += einsum("kc,ijkabc->ijab", x5, t3_abaaba) + x6 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x6 += einsum("ibja->ijab", v_bbbb_ovov) + x6 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 + x7 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + x7 += einsum("ia->ia", f_bb_ov) + x7 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) + x7 += einsum("kc,kica->ia", t1_bb, x6) * -1.0 + t2new_abab += einsum("me,jimbae->ijab", x7, t3_babbab) + x8 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) + x8 += einsum("kclb,ijlacb->iajk", v_aabb_ovov, t3_babbab) + x8 += einsum("kcmd,jimcad->iajk", v_aaaa_ovov, t3_abaaba) + t2new_abab += einsum("ka,jbik->ijab", t1_aa, x8) * -1.0 + x9 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) + x9 += einsum("jclb,iklbac->ijka", v_bbbb_ovov, t3_babbab) * -1.0 + x9 += einsum("mdjc,kimacd->ijka", v_aabb_ovov, t3_abaaba) + t2new_abab += einsum("mb,jmia->ijab", t1_bb, x9) * -1.0 + return t2new_aaaa, t2new_abab, t2new_bbbb diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 3d87a78ce..99d7494aa 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -6,6 +6,7 @@ from vayesta.core import spinalg from vayesta.mpi import mpi, RMA_Dict from vayesta.solver.simple import CCSD as SimpleCCSD +from vayesta.solver import ccsdtq def transform_amplitude(t, u_occ, u_vir, u_occ2=None, u_vir2=None, inverse=False): @@ -283,10 +284,12 @@ def _integrals_for_extcorr(fragment, fock): fovb = dot(cluster.c_active_occ[1].T, fock[1], cluster.c_active_vir[1]) # TODO make consistent with RHF return value, remove redundancies fov = (fova, fovb) - gooov = (eris[0][oa, oa, oa, va], eris[1][oa, oa, ob, vb], eris[1].transpose(2, 3, 0, 1)[ob, ob, oa, va], eris[2][ob, ob, ob, vb]) - govov = (eris[0][oa, va, oa, va], eris[1][oa, va, ob, vb], eris[1].transpose(2, 3, 0, 1)[ob, vb, oa, va], eris[2][ob, vb, ob, vb]) - govvv = (eris[0][oa, va, va, va], eris[1][oa, va, vb, vb], eris[1].transpose(2, 3, 0, 1)[ob, vb, va, va], eris[2][ob, vb, vb, vb]) - return fov, gooov, govov, govvv + gooov = (eris[0][oa, oa, oa, va], eris[1][oa, oa, ob, vb], eris[2][ob, ob, ob, vb]) + govov = (eris[0][oa, va, oa, va], eris[1][oa, va, ob, vb], eris[2][ob, vb, ob, vb]) + govvv = (eris[0][oa, va, va, va], eris[1][oa, va, vb, vb], eris[2][ob, vb, vb, vb]) + gvvov = (None, eris[1][va, va, ob, vb], None) + govoo = (None, eris[1][oa, va, ob, ob], None) + return fov, (gooov, govov, govvv, gvvov, govoo) return fov, govov, gvvov, gooov, govoo def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extcorr=False): @@ -448,144 +451,15 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc elif fragment.base.spinsym == 'unrestricted': # Get ERIs and Fock matrix for the given fragment - (f_aa_ov, f_bb_ov), \ - (v_aaaa_ooov, v_aabb_ooov, v_bbaa_ooov, v_bbbb_ooov), \ - (v_aaaa_ovov, v_aabb_ovov, v_bbaa_ovov, v_bbbb_ovov), \ - (v_aaaa_ovvv, v_aabb_ovvv, v_bbaa_ovvv, v_bbbb_ovvv) = _integrals_for_extcorr(fragment, fock) - - t1_aa, t1_bb = wf.t1 - t2_aaaa, t2_abab, t2_bbbb = wf.t2 - t3_aaaaaa, t3_abaaba, t3_abbabb, t3_babbab, t3_bbabba, t3_bbbbbb = wf.t3 - t4_aaaaaaaa, t4_aaabaaab, t4_aabaaaba, t4_abaaabaa, t4_abababab, t4_abbbabbb, t4_bbabbbab, t4_bbbabbba, t4_bbbbbbbb = wf.t4 - - # FIXME pull from property - nocc_a, nvir_a = t1_aa.shape - nocc_b, nvir_b = t1_bb.shape - nocc = (nocc_a, nocc_b) - nvir = (nvir_a, nvir_b) - - # TODO: Use spinalg.zeros_like(t1/t2) - dt1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - dt1_aa += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_abaaba) * 0.5 - dt1_aa += einsum("jbkc,ikjacb->ia", v_aabb_ovov, t3_abaaba) * 0.5 - dt1_aa += einsum("jbkc,ijkabc->ia", v_aaaa_ovov, t3_aaaaaa) * 0.5 - dt1_aa += einsum("jbkc,ijkabc->ia", v_bbbb_ovov, t3_abbabb) * 0.5 - - dt1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - dt1_bb += einsum("jbkc,jikbac->ia", v_aaaa_ovov, t3_abaaba) * 0.5 - dt1_bb += einsum("jbkc,ijkabc->ia", v_aabb_ovov, t3_babbab) * 0.5 - dt1_bb += einsum("jbkc,ijkabc->ia", v_bbaa_ovov, t3_bbabba) * 0.5 - dt1_bb += einsum("jbkc,ijkabc->ia", v_bbbb_ovov, t3_bbbbbb) * 0.5 - - dt2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - dt2_aaaa += einsum("kc,ikjacb->ijab", f_bb_ov, t3_abaaba) - dt2_aaaa += einsum("kc,ijkabc->ijab", f_aa_ov, t3_aaaaaa) - dt2_aaaa += einsum("iklc,jlkacb->ijab", v_aabb_ooov, t3_abaaba) - dt2_aaaa += einsum("jklc,ilkacb->ijab", v_aabb_ooov, t3_abaaba) * -1.0 - dt2_aaaa += einsum("kcad,ikjbcd->ijab", v_bbaa_ovvv, t3_abaaba) * -1.0 - dt2_aaaa += einsum("kcbd,ikjacd->ijab", v_bbaa_ovvv, t3_abaaba) - dt2_aaaa += einsum("iklc,jklabc->ijab", v_aaaa_ooov, t3_aaaaaa) - dt2_aaaa += einsum("jklc,iklabc->ijab", v_aaaa_ooov, t3_aaaaaa) * -1.0 - dt2_aaaa += einsum("kcad,ijkbcd->ijab", v_aaaa_ovvv, t3_aaaaaa) - dt2_aaaa += einsum("kcbd,ijkacd->ijab", v_aaaa_ovvv, t3_aaaaaa) * -1.0 - dt2_aaaa += einsum("kcld,ikjlacbd->ijab", v_bbbb_ovov, t4_abababab) * 0.5 - dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_aaaaaaaa) * 0.5 - dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_aaabaaab) * 0.5 - dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_bbaa_ovov, t4_aabaaaba) * 0.5 - dt2_aaaa += einsum("ic,kcld,jlkadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * 0.5 - dt2_aaaa += einsum("ic,kdlc,jkladb->ijab", t1_aa, v_bbaa_ovov, t3_abaaba) * 0.5 - dt2_aaaa += einsum("jc,kcld,ilkadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * -0.5 - dt2_aaaa += einsum("jc,kdlc,ikladb->ijab", t1_aa, v_bbaa_ovov, t3_abaaba) * -0.5 - dt2_aaaa += einsum("ka,kcld,iljbdc->ijab", t1_aa, v_aabb_ovov, t3_abaaba) - dt2_aaaa += einsum("kb,kcld,iljadc->ijab", t1_aa, v_aabb_ovov, t3_abaaba) * -1.0 - dt2_aaaa += einsum("kc,kcld,iljadb->ijab", t1_aa, v_aabb_ovov, t3_abaaba) - dt2_aaaa += einsum("ic,kcld,jklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 0.5 - dt2_aaaa += einsum("ic,kdlc,jklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -0.5 - dt2_aaaa += einsum("jc,kcld,iklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -0.5 - dt2_aaaa += einsum("jc,kdlc,iklabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * 0.5 - dt2_aaaa += einsum("ka,kcld,ijlbcd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) - dt2_aaaa += einsum("kb,kcld,ijlacd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -1.0 - dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) - dt2_aaaa += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_aaaaaa) * -1.0 - dt2_aaaa += einsum("kc,kcld,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) - dt2_aaaa += einsum("kc,kdlc,iljadb->ijab", t1_bb, v_bbbb_ovov, t3_abaaba) * -1.0 - dt2_aaaa += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_aaaaaa) - - dt2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - dt2_bbbb += einsum("kc,ijkabc->ijab", f_aa_ov, t3_bbabba) - dt2_bbbb += einsum("kc,ijkabc->ijab", f_bb_ov, t3_bbbbbb) - dt2_bbbb += einsum("iklc,jklabc->ijab", v_bbaa_ooov, t3_bbabba) - dt2_bbbb += einsum("iklc,jklabc->ijab", v_bbbb_ooov, t3_bbbbbb) - dt2_bbbb += einsum("jklc,iklabc->ijab", v_bbaa_ooov, t3_bbabba) * -1.0 - dt2_bbbb += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) * -1.0 - dt2_bbbb += einsum("kcad,ijkbcd->ijab", v_bbbb_ovvv, t3_bbbbbb) - dt2_bbbb += einsum("kcad,ijkbdc->ijab", v_aabb_ovvv, t3_bbabba) * -1.0 - dt2_bbbb += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) * -1.0 - dt2_bbbb += einsum("kcbd,ijkadc->ijab", v_aabb_ovvv, t3_bbabba) - dt2_bbbb += einsum("kcld,kiljcadb->ijab", v_aaaa_ovov, t4_abababab) * 0.5 - dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_bbabbbab) * 0.5 - dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbaa_ovov, t4_bbbabbba) * 0.5 - dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 0.5 - dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_bbabba) - dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aabb_ovov, t3_bbbbbb) - dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_bbabba) * -1.0 - dt2_bbbb += einsum("ic,kcld,jklabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * 0.5 - dt2_bbbb += einsum("ic,kcld,jklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 0.5 - dt2_bbbb += einsum("ic,kdlc,jklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -0.5 - dt2_bbbb += einsum("ic,kdlc,jkladb->ijab", t1_bb, v_aabb_ovov, t3_babbab) * 0.5 - dt2_bbbb += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * -0.5 - dt2_bbbb += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -0.5 - dt2_bbbb += einsum("jc,kdlc,ikladb->ijab", t1_bb, v_aabb_ovov, t3_babbab) * -0.5 - dt2_bbbb += einsum("jc,kdlc,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * 0.5 - dt2_bbbb += einsum("ka,kcld,ijlbcd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) - dt2_bbbb += einsum("ka,kcld,ijlbcd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) - dt2_bbbb += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) * -1.0 - dt2_bbbb += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -1.0 - dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_bbabba) - dt2_bbbb += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) - dt2_bbbb += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_bbbbbb) * -1.0 - - dt2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) - dt2_abab += einsum("kc,ijkabc->ijab", f_aa_ov, t3_abaaba) - dt2_abab += einsum("kc,ijkabc->ijab", f_bb_ov, t3_abbabb) - dt2_abab += einsum("iklc,kjlabc->ijab", v_aaaa_ooov, t3_abaaba) * -1.0 - dt2_abab += einsum("jklc,iklabc->ijab", v_bbaa_ooov, t3_abaaba) * -1.0 - dt2_abab += einsum("kcad,ijkcbd->ijab", v_aaaa_ovvv, t3_abaaba) * -1.0 - dt2_abab += einsum("kcbd,ijkadc->ijab", v_aabb_ovvv, t3_abaaba) - dt2_abab += einsum("iklc,jklbac->ijab", v_aabb_ooov, t3_babbab) * -1.0 - dt2_abab += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_abbabb) * -1.0 - dt2_abab += einsum("kcad,ijkdbc->ijab", v_bbaa_ovvv, t3_abbabb) - dt2_abab += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_abbabb) * -1.0 - dt2_abab += einsum("kcld,ijklabcd->ijab", v_aabb_ovov, t4_abababab) * 0.5 - dt2_abab += einsum("kcld,ijlkabdc->ijab", v_bbaa_ovov, t4_abababab) * 0.5 - dt2_abab += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_abaaabaa) * 0.5 - dt2_abab += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_abbbabbb) * 0.5 - dt2_abab += einsum("ic,kcld,kjlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -0.5 - dt2_abab += einsum("ic,kdlc,kjlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * 0.5 - dt2_abab += einsum("ka,kcld,ijlcbd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -1.0 - dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) - dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_aa, v_aaaa_ovov, t3_abaaba) * -1.0 - dt2_abab += einsum("ic,kcld,jklbad->ijab", t1_aa, v_aabb_ovov, t3_babbab) * -0.5 - dt2_abab += einsum("ic,kdlc,jklbda->ijab", t1_aa, v_bbaa_ovov, t3_bbabba) * -0.5 - dt2_abab += einsum("ka,kcld,ijlcbd->ijab", t1_aa, v_aabb_ovov, t3_abbabb) * -1.0 - dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_aa, v_aabb_ovov, t3_abbabb) - dt2_abab += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * -0.5 - dt2_abab += einsum("jc,kdlc,ilkabd->ijab", t1_bb, v_aabb_ovov, t3_abaaba) * -0.5 - dt2_abab += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) * -1.0 - dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbaa_ovov, t3_abaaba) - dt2_abab += einsum("jc,kcld,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -0.5 - dt2_abab += einsum("jc,kdlc,iklabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * 0.5 - dt2_abab += einsum("kb,kcld,ijlacd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -1.0 - dt2_abab += einsum("kc,kcld,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) - dt2_abab += einsum("kc,kdlc,ijlabd->ijab", t1_bb, v_bbbb_ovov, t3_abbabb) * -1.0 - + f, v = _integrals_for_extcorr(fragment, fock) + + dt1 = ccsdtq.t1_residual_uhf(wf.t1, wf.t2, wf.t3, wf.t4, f, v) + dt2 = ccsdtq.t2_residual_uhf(wf.t1, wf.t2, wf.t3, wf.t4, f, v) + if not include_t3v: # TODO raise NotImplementedError - dt1 = (dt1_aa, dt1_bb) - dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) - else: raise ValueError From 5c52285982d83165534814c9cbef0e405078cd87 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Mon, 20 Mar 2023 10:52:02 +0000 Subject: [PATCH 49/66] Refactoring and cleaning --- vayesta/core/types/wf/fci.py | 376 ++++++----------------------------- vayesta/core/util.py | 114 ++++++++++- vayesta/solver/ccsd.py | 4 +- vayesta/solver/ccsdtq.py | 191 ++++++++++++------ vayesta/solver/coupling.py | 164 +++------------ 5 files changed, 328 insertions(+), 521 deletions(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 99dc48b7f..360b3a042 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -95,195 +95,50 @@ def as_cisdtq(self, c0=None): ijk_pairs = int(nocc * (nocc - 1) * (nocc - 2) / 6) abc_pairs = int(nvir * (nvir - 1) * (nvir - 2) / 6) + t1addr, t1sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 1) + t2addr, t2sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 2) + t3addr, t3sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 3) + t4addr, t4sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 4) + + t1addr = np.asarray(t1addr, dtype=int) + t2addr = np.asarray(t2addr, dtype=int) + t3addr = np.asarray(t3addr, dtype=int) + t4addr = np.asarray(t4addr, dtype=int) + # === C1 amplitudes === # These functions extract out the indicies and signs of # the *same spin* excitations of a given rank from the FCI vector - t1addr, t1sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 1) # C1 are taken to be the beta -> beta excitations (which should be # the same as alpha -> alpha), by taking the first (alpha) index to be doubly occupied. c1 = self.ci[0,t1addr] * t1sign c1 = c1.reshape((nocc, nvir)) - # Longhand check (to be put into a test) - c1_ = np.zeros(t1addr.shape[0]) - c1_full = np.zeros_like(c1) - for s_cnt, sing_ind in enumerate(t1addr): - c1_[s_cnt] = self.ci[0, sing_ind] * t1sign[s_cnt] - i = int(s_cnt / nvir) - a = s_cnt % nvir - c1_full[i,a] = c1_[s_cnt] - assert(np.allclose(c1, c1_full)) - # === C2 amplitudes === # For RHF, we want the (alpha, beta) -> (alpha, beta) excitation amplitudes. # Therefore, we can just take single excitations of alpha and # combine with the single excitations of beta. - c2 = np.einsum('i,j,ij->ij', t1sign, t1sign, self.ci[t1addr[:,None],t1addr]) - # Reorder occupied indices to the front - c2 = c2.reshape((nocc, nvir, nocc, nvir)).transpose(0,2,1,3) + c2 = np.einsum('i,j,ij->ij', t1sign, t1sign, self.ci[t1addr[:, None], t1addr]) + c2 = c2.reshape((nocc, nvir, nocc, nvir)) + c2 = c2.transpose(0, 2, 1, 3) # === C3 amplitudes === # For the C3 amplitudes, we want to find the ijk -> abc amplitudes of # spin signature (alpha, beta, alpha) -> (alpha, beta, alpha) - - # t2addr, t2sign is the index and sign of the packed (alpha, alpha) -> (alpha, alpha) - # excitations in the FCI array. To get the orbital indices that they correspond to, - # use ooidx and vvidx - t2addr, t2sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 2) - assert(len(t2addr) == ij_pairs * ab_pairs) - - # First find the ijk -> abc excitations, where ijab are alpha, and kc are beta - c3_comp = np.zeros((ij_pairs * ab_pairs, nocc * nvir)) - c3 = np.zeros((nocc, nocc, nocc, nvir, nvir, nvir)) - for d_cnt, doub_ind in enumerate(t2addr): - ij = int(d_cnt / ab_pairs) - ab = d_cnt % ab_pairs - i, j = ooidx[0][ij], ooidx[1][ij] # j ind < i ind - a, b = vvidx[0][ab], vvidx[1][ab] # b ind < a ind - for s_cnt, sing_ind in enumerate(t1addr): - # First index of c3_comp is a compound index of ijab (alpha, alpha) excitations, - # with the second index being the kc (beta, beta) single excitation. - c3_comp[d_cnt, s_cnt] = self.ci[doub_ind, sing_ind] * t2sign[d_cnt] * t1sign[s_cnt] - - k = int(s_cnt / nvir) - c = s_cnt % nvir - # Note, we want aba -> aba spin signature, not aab -> aab, which is what we have. - # We can therefore swap (jk) and (bc). This does not cause an overall sign change. - # We then also want to fill up the contributions between permutations - # amongst the alpha electrons and alpha holes. - # If only one is permuted, then this will indeed cause a sign change. - assert(i != j) - assert(a != b) - c3[i,k,j,a,c,b] = c3_comp[d_cnt, s_cnt] - c3[j,k,i,a,c,b] = -c3_comp[d_cnt, s_cnt] - c3[i,k,j,b,c,a] = -c3_comp[d_cnt, s_cnt] - c3[j,k,i,b,c,a] = c3_comp[d_cnt, s_cnt] - - if len(t2addr) > 0: - assert(np.allclose(c3_comp, np.einsum('i,j,ij->ij', \ - t2sign, t1sign, self.ci[t2addr[:,None], t1addr]))) - del c3_comp + c3 = np.einsum('i,j,ij->ij', t2sign, t1sign, self.ci[t2addr[:, None], t1addr]) + c3 = decompress_axes("iiaajb", c3, shape=(nocc, nocc, nvir, nvir, nocc, nvir)) + c3 = c3.transpose(0, 4, 1, 2, 5, 3) # === C4 amplitudes === # For the C4 amplitudes, ijkl -> abcd, we are going to store two different spin # signatures: # (alpha, beta, alpha, beta) -> (alpha, beta, alpha, beta) and # (alpha, beta, alpha, alpha) -> (alpha, beta, alpha, alpha) - # TODO: Can we store the information as a single combined spatial orbital representation? - - # Start with abab. We will first get this as aabb -> aabb, via a product of - # alpha-alpha double excitations and beta-beta double excitations and then reorder. - c4_abab = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir)) - c4_comp = np.zeros((ij_pairs * ab_pairs, ij_pairs * ab_pairs)) - for d_cnt_a, doub_ind_a in enumerate(t2addr): - ij_alpha = int(d_cnt_a / ab_pairs) - ab_alpha = d_cnt_a % ab_pairs - i, j = ooidx[0][ij_alpha], ooidx[1][ij_alpha] - a, b = vvidx[0][ab_alpha], vvidx[1][ab_alpha] - for d_cnt_b, doub_ind_b in enumerate(t2addr): - ij_beta = int(d_cnt_b / ab_pairs) - ab_beta = d_cnt_b % ab_pairs - I, J = ooidx[0][ij_beta], ooidx[1][ij_beta] - A, B = vvidx[0][ab_beta], vvidx[1][ab_beta] - - # Swap aabb -> abab spin signature. No sign change required. - c4_comp[d_cnt_a, d_cnt_b] = self.ci[doub_ind_a, doub_ind_b] \ - * t2sign[d_cnt_a] * t2sign[d_cnt_b] - # Consider all possible (antisymmetric) permutations of (i_alpha, j_alpha), - # (i_beta, j_beta), (a_alpha, b_alpha), (a_beta, b_beta). 16 options. - c4_abab[i, I, j, J, a, A, b, B] = c4_comp[d_cnt_a, d_cnt_b] - c4_abab[i, I, j, J, a, B, b, A] = -c4_comp[d_cnt_a, d_cnt_b] - c4_abab[i, I, j, J, b, A, a, B] = -c4_comp[d_cnt_a, d_cnt_b] - c4_abab[i, I, j, J, b, B, a, A] = c4_comp[d_cnt_a, d_cnt_b] - c4_abab[i, J, j, I, a, A, b, B] = -c4_comp[d_cnt_a, d_cnt_b] - c4_abab[i, J, j, I, a, B, b, A] = c4_comp[d_cnt_a, d_cnt_b] - c4_abab[i, J, j, I, b, A, a, B] = c4_comp[d_cnt_a, d_cnt_b] - c4_abab[i, J, j, I, b, B, a, A] = -c4_comp[d_cnt_a, d_cnt_b] - c4_abab[j, I, i, J, a, A, b, B] = -c4_comp[d_cnt_a, d_cnt_b] - c4_abab[j, I, i, J, a, B, b, A] = c4_comp[d_cnt_a, d_cnt_b] - c4_abab[j, I, i, J, b, A, a, B] = c4_comp[d_cnt_a, d_cnt_b] - c4_abab[j, I, i, J, b, B, a, A] = -c4_comp[d_cnt_a, d_cnt_b] - c4_abab[j, J, i, I, a, A, b, B] = c4_comp[d_cnt_a, d_cnt_b] - c4_abab[j, J, i, I, a, B, b, A] = -c4_comp[d_cnt_a, d_cnt_b] - c4_abab[j, J, i, I, b, A, a, B] = -c4_comp[d_cnt_a, d_cnt_b] - c4_abab[j, J, i, I, b, B, a, A] = c4_comp[d_cnt_a, d_cnt_b] - - if len(t2addr) > 0: - assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t2sign, t2sign, \ - self.ci[t2addr[:,None], t2addr]))) - del c4_comp - - # abaa spin signature. Get this from the aaab->aaab excitations. - # This requires the index of the (alpha, alpha, alpha) -> (alpha, alpha, alpha) excits. - t3addr, t3sign = pyscf.ci.cisd.tn_addrs_signs(norb, nocc, 3) - assert(len(t3addr) == ijk_pairs * abc_pairs) - - c4_abaa = np.zeros((nocc, nocc, nocc, nocc, nvir, nvir, nvir, nvir)) - c4_comp = np.zeros((ijk_pairs * abc_pairs, nocc * nvir)) - for t_cnt_a, trip_ind_a in enumerate(t3addr): - # Find alpha i,j,k -> a,b,c indices - ijk_alpha = t_cnt_a // abc_pairs - abc_alpha = t_cnt_a % abc_pairs - i, j, k = oooidx[0][ijk_alpha], oooidx[1][ijk_alpha], oooidx[2][ijk_alpha] - a, b, c = vvvidx[0][abc_alpha], vvvidx[1][abc_alpha], vvvidx[2][abc_alpha] - for s_cnt_b, sing_ind_b in enumerate(t1addr): - c4_comp[t_cnt_a, s_cnt_b] = self.ci[trip_ind_a, sing_ind_b] * \ - t3sign[t_cnt_a] * t1sign[s_cnt_b] - - # Beta singles values - I = int(s_cnt_b / nvir) - A = s_cnt_b % nvir - - # Swap aaab -> abaa spin signature. No sign change required. - c4_abaa[i, I, j, k, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] - # All antisym permutations of (ijk) x (abc) amongst alpha orbitals. - # Six permutations each, making 36 overall - # just rearrange occupied - c4_abaa[i, I, j, k, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[i, I, k, j, a, A, b, c] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, j, i, a, A, b, c] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, i, k, a, A, b, c] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, k, i, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, i, j, a, A, b, c] = c4_comp[t_cnt_a, s_cnt_b] - # swap ac - c4_abaa[i, I, j, k, c, A, b, a] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[i, I, k, j, c, A, b, a] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, j, i, c, A, b, a] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, i, k, c, A, b, a] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, k, i, c, A, b, a] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, i, j, c, A, b, a] = -c4_comp[t_cnt_a, s_cnt_b] - # swap ab - c4_abaa[i, I, j, k, b, A, a, c] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[i, I, k, j, b, A, a, c] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, j, i, b, A, a, c] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, i, k, b, A, a, c] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, k, i, b, A, a, c] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, i, j, b, A, a, c] = -c4_comp[t_cnt_a, s_cnt_b] - # swap bc - c4_abaa[i, I, j, k, a, A, c, b] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[i, I, k, j, a, A, c, b] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, j, i, a, A, c, b] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, i, k, a, A, c, b] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, k, i, a, A, c, b] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, i, j, a, A, c, b] = -c4_comp[t_cnt_a, s_cnt_b] - # swap abc -> cab - c4_abaa[i, I, j, k, c, A, a, b] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[i, I, k, j, c, A, a, b] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, j, i, c, A, a, b] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, i, k, c, A, a, b] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, k, i, c, A, a, b] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, i, j, c, A, a, b] = c4_comp[t_cnt_a, s_cnt_b] - # swap abc -> bca - c4_abaa[i, I, j, k, b, A, c, a] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[i, I, k, j, b, A, c, a] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, j, i, b, A, c, a] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, i, k, b, A, c, a] = -c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[j, I, k, i, b, A, c, a] = c4_comp[t_cnt_a, s_cnt_b] - c4_abaa[k, I, i, j, b, A, c, a] = c4_comp[t_cnt_a, s_cnt_b] - - if len(t3addr) > 0: - assert(np.allclose(c4_comp, np.einsum('i,j,ij->ij', t3sign, t1sign, \ - self.ci[t3addr[:,None], t1addr]))) + c4_abaa = np.einsum('i,j,ij->ij', t3sign, t1sign, self.ci[t3addr[:, None], t1addr]) + c4_abaa = decompress_axes("iiiaaajb", c4_abaa, shape=(nocc, nocc, nocc, nvir, nvir, nvir, nocc, nvir)) + c4_abaa = c4_abaa.transpose(0, 6, 2, 1, 3, 7, 5, 4) + c4_abab = np.einsum('i,j,ij->ij', t2sign, t2sign, self.ci[t2addr[:, None], t2addr]) + c4_abab = decompress_axes("iiaajjbb", c4_abab, shape=(nocc, nocc, nvir, nvir, nocc, nocc, nvir, nvir)) + c4_abab = c4_abab.transpose(0, 4, 1, 5, 2, 6, 3, 7) if c0 is None: c0 = self.c0 @@ -420,7 +275,7 @@ def as_cisdtq(self, c0=None): vvvidx_b = tril_indices_ndim(nvirb, 3) # a > b > c ijk_pairs_b = int(noccb * (noccb - 1) * (noccb - 2) / 6) abc_pairs_b = int(nvirb * (nvirb - 1) * (nvirb - 2) / 6) - + ijkl_pairs_a = int(nocca * (nocca - 1) * (nocca - 2) * (nocca - 3) / 24) abcd_pairs_a = int(nvira * (nvira - 1) * (nvira - 2) * (nvira - 3) / 24) ijkl_pairs_b = int(noccb * (noccb - 1) * (noccb - 2) * (noccb - 3) / 24) @@ -448,163 +303,59 @@ def as_cisdtq(self, c0=None): na = pyscf.fci.cistring.num_strings(norba, nocca) nb = pyscf.fci.cistring.num_strings(norbb, noccb) - ci = self.ci.reshape(na,nb) # C1 c1_a = (self.ci[t1addra,0] * t1signa).reshape(nocca,nvira) c1_b = (self.ci[0,t1addrb] * t1signb).reshape(noccb,nvirb) + # C2 c2_aa = (self.ci[t2addra,0] * t2signa).reshape(ij_pairs_a, ab_pairs_a) - c2_bb = (self.ci[0,t2addrb] * t2signb).reshape(ij_pairs_b, ab_pairs_b) c2_aa = pyscf.cc.ccsd._unpack_4fold(c2_aa, nocca, nvira) + + c2_bb = (self.ci[0,t2addrb] * t2signb).reshape(ij_pairs_b, ab_pairs_b) c2_bb = pyscf.cc.ccsd._unpack_4fold(c2_bb, noccb, nvirb) - c2_ab = einsum('i,j,ij->ij', t1signa, t1signb, self.ci[t1addra[:,None],t1addrb]) - c2_ab = c2_ab.reshape(nocca,nvira,noccb,nvirb).transpose(0,2,1,3) + + c2_ab = einsum('i,j,ij->ij', t1signa, t1signb, self.ci[t1addra[:, None], t1addrb]) + c2_ab = c2_ab.reshape(nocca, nvira, noccb, nvirb) + c2_ab = c2_ab.transpose(0, 2, 1, 3) + # C3 + c3_aaa = (self.ci[t3addra,0] * t3signa).reshape(ijk_pairs_a, abc_pairs_a) + c3_aaa = decompress_axes("iiiaaa", c3_aaa, shape=(nocca, nocca, nocca, nvira, nvira, nvira)) + + c3_bbb = (self.ci[0,t3addrb] * t3signb).reshape(ijk_pairs_b, abc_pairs_b) + c3_bbb = decompress_axes("iiiaaa", c3_bbb, shape=(noccb, noccb, noccb, nvirb, nvirb, nvirb)) - # Get the following spin signatures in packed form, and then Ollie will unpack later! - # T3: aaa, aba, abb, bab, bba, bbb - # aaa - c3_aaa_pack = (self.ci[t3addra,0] * t3signa).reshape(ijk_pairs_a, abc_pairs_a) - # bbb - c3_bbb_pack = (self.ci[0,t3addrb] * t3signb).reshape(ijk_pairs_b, abc_pairs_b) - # aab - c3_aab_pack = np.einsum('i,j,ij->ij', t2signa, t1signb, self.ci[t2addra[:,None], t1addrb]) - assert(c3_aab_pack.shape == (ij_pairs_a * ab_pairs_a, noccb * nvirb)) - # bba - c3_abb_pack = np.einsum('i,j,ij->ij', t1signa, t2signb, self.ci[t1addra[:,None], t2addrb]) - assert(c3_abb_pack.shape == (nocca * nvira, ij_pairs_b * ab_pairs_b)) - - # Now, unpack... TODO - from ebcc.util import decompress_axes - c3_aaa = decompress_axes( - "iiiaaa", - c3_aaa_pack, - shape=(nocca, nocca, nocca, nvira, nvira, nvira), - symmetry="------", - ) - c3_bbb = decompress_axes( - "iiiaaa", - c3_bbb_pack, - shape=(noccb, noccb, noccb, nvirb, nvirb, nvirb), - symmetry="------", - ) - c3_aab = decompress_axes( - "iiaajb", - c3_aab_pack, - shape=(nocca, nocca, nvira, nvira, noccb, nvirb), - symmetry="------", - ) - c3_aab = c3_aab.transpose(0, 1, 4, 2, 3, 5) - c3_abb = decompress_axes( - "iajjbb", - c3_abb_pack, - shape=(nocca, nvira, noccb, noccb, nvirb, nvirb), - symmetry="------", - ) - c3_abb = c3_abb.transpose(0, 2, 3, 1, 4, 5) - - # T4: aaaa, aaab, aaba, abaa, abab, bbab, bbba, bbbb - # aaaa - c4_aaaa_pack = (self.ci[t4addra,0] * t4signa).reshape(ijkl_pairs_a, abcd_pairs_a) - # bbbb - c4_bbbb_pack = (self.ci[0,t4addrb] * t4signb).reshape(ijkl_pairs_b, abcd_pairs_b) - # aaab - c4_aaab_pack = np.einsum('i,j,ij->ij', t3signa, t1signb, self.ci[t3addra[:,None], t1addrb]) - assert(c4_aaab_pack.shape == (ijk_pairs_a * abc_pairs_a, noccb * nvirb)) - # aabb - c4_aabb_pack = np.einsum('i,j,ij->ij', t2signa, t2signb, self.ci[t2addra[:,None], t2addrb]) - assert(c4_aabb_pack.shape == (ij_pairs_a * ab_pairs_a, ij_pairs_b * ab_pairs_b)) - # abbb - c4_abbb_pack = np.einsum('i,j,ij->ij', t1signa, t3signb, self.ci[t1addra[:,None], t3addrb]) - assert(c4_abbb_pack.shape == (nocca * nvira, ijk_pairs_b * abc_pairs_b)) - - # Now, unpack... TODO - c4_aaaa = decompress_axes( - "iiiiaaaa", - c4_aaaa_pack, - shape=(nocca, nocca, nocca, nocca, nvira, nvira, nvira, nvira), - symmetry="--------", - ) - c4_bbbb = decompress_axes( - "iiiiaaaa", - c4_bbbb_pack, - shape=(noccb, noccb, noccb, noccb, nvirb, nvirb, nvirb, nvirb), - symmetry="--------", - ) - c4_aaab = decompress_axes( - "iiiaaajb", - c4_aaab_pack, - shape=(nocca, nocca, nocca, nvira, nvira, nvira, noccb, nvirb), - symmetry="--------", - ) + c3_aba = np.einsum('i,j,ij->ij', t2signa, t1signb, self.ci[t2addra[:, None], t1addrb]) + c3_aba = decompress_axes("iiaajb", c3_aba, shape=(nocca, nocca, nvira, nvira, noccb, nvirb)) + c3_aba = c3_aba.transpose(0, 4, 1, 2, 5, 3) + + c3_bab = np.einsum('i,j,ij->ij', t1signa, t2signb, self.ci[t1addra[:, None], t2addrb]) + c3_bab = decompress_axes("iajjbb", c3_bab, shape=(nocca, nvira, noccb, noccb, nvirb, nvirb)) + c3_bab = c3_bab.transpose(2, 0, 3, 4, 1, 5) + + # C4 + c4_aaaa = (self.ci[t4addra,0] * t4signa).reshape(ijkl_pairs_a, abcd_pairs_a) + c4_aaaa = decompress_axes("iiiiaaaa", c4_aaaa, shape=(nocca, nocca, nocca, nocca, nvira, nvira, nvira, nvira)) + + c4_bbbb = (self.ci[0,t4addrb] * t4signb).reshape(ijkl_pairs_b, abcd_pairs_b) + c4_bbbb = decompress_axes("iiiiaaaa", c4_bbbb, shape=(noccb, noccb, noccb, noccb, nvirb, nvirb, nvirb, nvirb)) + + c4_aaab = np.einsum('i,j,ij->ij', t3signa, t1signb, self.ci[t3addra[:,None], t1addrb]) + c4_aaab = decompress_axes("iiiaaajb", c4_aaab, shape=(nocca, nocca, nocca, nvira, nvira, nvira, noccb, nvirb)) c4_aaab = c4_aaab.transpose(0, 1, 2, 6, 3, 4, 5, 7) - c4_aabb = decompress_axes( - "iiaajjbb", - c4_aabb_pack, - shape=(nocca, nocca, nvira, nvira, noccb, noccb, nvirb, nvirb), - symmetry="--------", - ) - c4_aabb = c4_aabb.transpose(0, 1, 4, 5, 2, 3, 6, 7) - c4_abbb = decompress_axes( - "iajjjbbb", - c4_abbb_pack, - shape=(nocca, nvira, noccb, noccb, noccb, nvirb, nvirb, nvirb), - symmetry="--------", - ) + + c4_abab = np.einsum('i,j,ij->ij', t2signa, t2signb, self.ci[t2addra[:,None], t2addrb]) + c4_abab = decompress_axes("iiaajjbb", c4_abab, shape=(nocca, nocca, nvira, nvira, noccb, noccb, nvirb, nvirb)) + c4_abab = c4_abab.transpose(0, 4, 1, 5, 2, 6, 3, 7) + + c4_abbb = np.einsum('i,j,ij->ij', t1signa, t3signb, self.ci[t1addra[:,None], t3addrb]) + c4_abbb = decompress_axes("iajjjbbb", c4_abbb, shape=(nocca, nvira, noccb, noccb, noccb, nvirb, nvirb, nvirb)) c4_abbb = c4_abbb.transpose(0, 2, 3, 4, 1, 5, 6, 7) - # alpha, beta, alpha: Use this longhand code as a sanity check - # First find the ijk -> abc excitations, where ijab are alpha, and kc are beta - c3_comp = np.zeros((ij_pairs_a * ab_pairs_a, noccb * nvirb)) - c3_aba = np.zeros((nocca, noccb, nocca, nvira, nvirb, nvira)) - for d_cnta, doub_inda in enumerate(t2addra): - ij_a = int(d_cnta / ab_pairs_a) - ab_a = d_cnta % ab_pairs_a - i, j = ooidx_a[0][ij_a], ooidx_a[1][ij_a] # j ind < i ind - a, b = vvidx_a[0][ab_a], vvidx_a[1][ab_a] # b ind < a ind - for s_cntb, sing_indb in enumerate(t1addrb): - # First index of c3_comp is a compound index of ijab (alpha, alpha) excitations, - # with the second index being the kc (beta, beta) single excitation. - c3_comp[d_cnta, s_cntb] = self.ci[doub_inda, sing_indb] * t2signa[d_cnta] * t1signa[s_cntb] - - k = int(s_cntb / nvirb) - c = s_cntb % nvirb - # Note, we want aba -> aba spin signature, not aab -> aab, which is what we have. - # We can therefore swap (jk) and (bc). This does not cause an overall sign change. - # We then also want to fill up the contributions between permutations - # amongst the alpha electrons and alpha holes. - # If only one is permuted, then this will indeed cause a sign change. - assert(i != j) - assert(a != b) - c3_aba[i,k,j,a,c,b] = c3_comp[d_cnta, s_cntb] - c3_aba[j,k,i,a,c,b] = -c3_comp[d_cnta, s_cntb] - c3_aba[i,k,j,b,c,a] = -c3_comp[d_cnta, s_cntb] - c3_aba[j,k,i,b,c,a] = c3_comp[d_cnta, s_cntb] - - # NOTE: this all fails for open shell - if len(t2addra) > 0: - # This is a better way of doing it, and then expand! Put rest in a test. - assert(np.allclose(c3_comp, np.einsum('i,j,ij->ij', \ - t2signa, t1signb, self.ci[t2addra[:,None], t1addrb]))) - del c3_comp - assert np.allclose(c3_aba, c3_aab.transpose(0, 2, 1, 3, 5, 4)) - - # TODO remove degenerate permutations c1 = (c1_a, c1_b) c2 = (c2_aa, c2_ab, c2_bb) - c3 = ( - c3_aaa, - c3_aab.transpose(0, 2, 1, 3, 5, 4), - c3_abb.transpose(1, 0, 2, 4, 3, 5), - c3_bbb, - ) - c4 = ( - c4_aaaa, - c4_aaab, - c4_aabb.transpose(0, 2, 1, 3, 4, 6, 5, 7), - c4_abbb, - c4_bbbb, - ) + c3 = (c3_aaa, c3_aba, c3_bab, c3_bbb) + c4 = (c4_aaaa, c4_aaab, c4_abab, c4_abbb, c4_bbbb) if c0 is None: c0 = self.c0 @@ -615,8 +366,7 @@ def as_cisdtq(self, c0=None): c3 = tuple(c * fac for c in c3) c4 = tuple(c * fac for c in c4) - # FIXME unexpected keyword argument 'projector' - return wf_types.UCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4)#, projector=self.projector) + return wf_types.UCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4) def as_ccsd(self): return self.as_cisd().as_ccsd() diff --git a/vayesta/core/util.py b/vayesta/core/util.py index c37938dbc..bd0af14f3 100644 --- a/vayesta/core/util.py +++ b/vayesta/core/util.py @@ -1,5 +1,6 @@ from contextlib import contextmanager from copy import deepcopy +import itertools import dataclasses import functools import logging @@ -28,7 +29,7 @@ # General 'Object', 'OptionsBase', 'brange', 'deprecated', 'cache', 'call_once', 'with_doc', # NumPy replacements - 'dot', 'tril_indices_ndim', 'einsum', 'hstack', + 'dot', 'tril_indices_ndim', 'einsum', 'hstack', 'decompress_axes', # Exceptions 'AbstractMethodError', 'ConvergenceError', 'OrthonormalityError', 'ImaginaryPartError', 'NotCalculatedError', @@ -39,7 +40,7 @@ # Other 'getattr_recursive', 'setattr_recursive', 'replace_attr', 'break_into_lines', 'fix_orbital_sign', 'split_into_blocks', - 'getif', 'callif', + 'getif', 'callif', 'permutations_with_signs', ] class Object: @@ -108,7 +109,10 @@ def func_with_doc(func): # --- NumPy def tril_indices_ndim(n, dims, include_diagonal=False): - """Return lower triangular indices for a multidimensional array.""" + """Return lower triangular indices for a multidimensional array. + + Copied from ebcc. + """ ranges = [np.arange(n)] * dims @@ -135,6 +139,87 @@ def tril_indices_ndim(n, dims, include_diagonal=False): return tril +def decompress_axes(subscript, array_flat, shape, include_diagonal=False, symmetry=None): + """Decompress an array that has dimensions flattened according to + permutation symmetries in the signs. + + Copied from ebcc. + """ + + assert "->" not in subscript + + # Get symmetry string if needed: + if symmetry is None: + symmetry = "-" * len(subscript) + + # Initialise decompressed array + array = np.zeros(shape) + + # Substitute the input characters so that they are ordered: + subs = {} + i = 0 + for char in subscript: + if char not in subs: + subs[char] = chr(97 + i) + i += 1 + subscript = "".join([subs[s] for s in subscript]) + + # Reshape array so that all axes of the same character are adjacent: + arg = np.argsort(list(subscript)) + array = array.transpose(arg) + subscript = "".join([subscript[i] for i in arg]) + + # Reshape array so that all axes of the same character are flattened: + sizes = {} + for char, n in zip(subscript, array.shape): + if char in sizes: + assert sizes[char] == n + else: + sizes[char] = n + array = array.reshape([sizes[char] ** subscript.count(char) for char in sorted(set(subscript))]) + + # Check the symmetry string, and compress it: + n = 0 + symmetry_compressed = "" + for char in sorted(set(subscript)): + assert len(set(symmetry[n : n + subscript.count(char)])) == 1 + symmetry_compressed += symmetry[n] + n += subscript.count(char) + + # For each axis type, get the necessary lower-triangular indices: + indices = [ + tril_indices_ndim(sizes[char], subscript.count(char), include_diagonal=include_diagonal) + for char in sorted(set(subscript)) + ] + + # Iterate over permutations with signs: + for tup in itertools.product(*[permutations_with_signs(ind) for ind in indices]): + indices_perm, signs = zip(*tup) + signs = [s if symm == "-" else 1 for s, symm in zip(signs, symmetry_compressed)] + + # Apply the indices: + indices_perm = [ + np.ravel_multi_index(ind, (sizes[char],) * subscript.count(char)) + for ind, char in zip(indices_perm, sorted(set(subscript))) + ] + indices_perm = [ + ind[tuple(np.newaxis if i != j else slice(None) for i in range(len(indices_perm)))] + for j, ind in enumerate(indices_perm) + ] + shape = array[tuple(indices_perm)].shape + array[tuple(indices_perm)] = array_flat.reshape(shape) * np.prod(signs) + + # Reshape array to non-flattened format + array = array.reshape( + sum([(sizes[char],) * subscript.count(char) for char in sorted(set(subscript))], tuple()) + ) + + # Undo transpose: + arg = np.argsort(arg) + array = array.transpose(arg) + + return array + def dot(*args, out=None, ignore_none=False): """Like NumPy's multi_dot, but variadic""" if ignore_none: @@ -585,3 +670,26 @@ def callif(func, arg, cond=lambda x, **kw: x is not None, default=None, **kwargs if cond(arg, **kwargs): return func(arg, **kwargs) return default + +def permutations_with_signs(seq): + """Generate permutations of seq, yielding also a sign which is + equal to +1 for an even number of swaps, and -1 for an odd number + of swaps. + + Copied from ebcc. + """ + + def _permutations(seq): + if not seq: + return [[]] + + items = [] + for i, item in enumerate(_permutations(seq[:-1])): + inds = range(len(item) + 1) + if i % 2 == 0: + inds = reversed(inds) + items += [item[:i] + seq[-1:] + item[i:] for i in inds] + + return items + + return [(item, -1 if i % 2 else 1) for i, item in enumerate(_permutations(list(seq)))] diff --git a/vayesta/solver/ccsd.py b/vayesta/solver/ccsd.py index bd68316f3..9b9713811 100644 --- a/vayesta/solver/ccsd.py +++ b/vayesta/solver/ccsd.py @@ -47,8 +47,6 @@ class Options(ClusterSolver.Options): external_corrections: Optional[List[typing.Any]] = dataclasses.field(default_factory=list) # Lambda equations solve_lambda: bool = True - # Whether to perform additional checks on external corrections - test_extcorr: bool = False def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) @@ -180,7 +178,7 @@ def kernel(self, t1=None, t2=None, eris=None, l1=None, l2=None, seris_ov=None, c # External correction of T1 and T2 if externals: self.log.info("Externally correct CCSD from %d fragments", len(externals)) - self.set_callback(coupling.externally_correct(self, externals, eris=eris, test_extcorr=self.opts.test_extcorr)) + self.set_callback(coupling.externally_correct(self, externals, eris=eris)) elif self.opts.sc_mode and self.base.iteration > 1: raise NotImplementedError diff --git a/vayesta/solver/ccsdtq.py b/vayesta/solver/ccsdtq.py index 5aeca6851..94d5a2e03 100644 --- a/vayesta/solver/ccsdtq.py +++ b/vayesta/solver/ccsdtq.py @@ -1,31 +1,84 @@ import numpy as np from vayesta.core.util import einsum -def t1_residual_uhf(t1, t2, t3, t4, f, v): - t1_aa, t1_bb = t1 - t2_aaaa, t2_abab, t2_bbbb = t2 - t3_aaaaaa, t3_abaaba, t3_babbab, t3_bbbbbb = t3 - t4_aaaaaaaa, t4_aaabaaab, t4_abababab, t4_abbbabbb, t4_bbbbbbbb = t4 - f_aa_ov, f_bb_ov = f - v_ooov, v_ovov, v_ovvv, v_vvov, v_ovoo = v - v_aaaa_ooov, v_aabb_ooov, v_bbbb_ooov = v_ooov - v_aaaa_ovov, v_aabb_ovov, v_bbbb_ovov = v_ovov - v_aaaa_ovvv, v_aabb_ovvv, v_bbbb_ovvv = v_ovvv - v_aaaa_vvov, v_aabb_vvov, v_bbbb_vvov = v_vvov - v_aaaa_ovoo, v_aabb_ovoo, v_bbbb_ovoo = v_ovoo - nocc = (t1_aa.shape[0], t1_bb.shape[0]) - nvir = (t1_aa.shape[1], t1_bb.shape[1]) - t1new_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - t1new_aa += einsum("jbkc,ijkabc->ia", v_aaaa_ovov, t3_aaaaaa) * 0.5 - t1new_aa += einsum("ldme,limdae->ia", v_bbbb_ovov, t3_babbab) * 0.5 - t1new_aa += einsum("jbmd,imjadb->ia", v_aabb_ovov, t3_abaaba) - t1new_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - t1new_bb += einsum("jbkc,jikbac->ia", v_aaaa_ovov, t3_abaaba) * 0.5 - t1new_bb += einsum("ldme,ilmade->ia", v_bbbb_ovov, t3_bbbbbb) * 0.5 - t1new_bb += einsum("kcmd,ikmacd->ia", v_aabb_ovov, t3_babbab) - return t1new_aa, t1new_bb - -def t2_residual_uhf(t1, t2, t3, t4, f, v): +def t_residual_rhf(solver, fragment, t1, t2, t3, t4, f, v, include_t3v=False): + t4_abaa, t4_abab = t4 + fov = f + govov, gvvov, gooov, govoo = v + nocc, nvir = t1.shape + + dt1 = np.zeros_like(t1) + dt2 = np.zeros_like(t2) + + # Construct physical antisymmetrized integrals for some contractions + # Note that some contractions are with physical and some chemical integrals (govov) + antiphys_g = (govov - govov.transpose(0,3,2,1)).transpose(0,2,1,3) + spinned_antiphys_g = (2.0*govov - govov.transpose(0,3,2,1)).transpose(0,2,1,3) + + # --- T1 update + # --- T3 * V + dt1 -= einsum('ijab, jiupab -> up', spinned_antiphys_g, t3) + + # --- T2 update + # --- T3 * F + if np.allclose(fov, np.zeros_like(fov)): + solver.log.info("fov block zero: No T3 * f contribution.") + # (Fa) (Taba) contraction + dt2 += einsum('me, ijmabe -> ijab', fov, t3) + # (Fb) (Tabb) contraction + dt2 += einsum('me, jimbae -> ijab', fov, t3) + solver.log.info("(T3 * F) -> T2 update norm from fragment {}: {}".format(fragment.id, np.linalg.norm(dt2))) + + # --- T4 * V + # (Vaa) (Tabaa) contraction + t4v = einsum('mnef, ijmnabef -> ijab', antiphys_g, t4_abaa) / 4 + t4v += t4v.transpose(1,0,3,2) + # (Vab) (Tabab) contraction + t4v += einsum('menf, ijmnabef -> ijab', govov, t4_abab) + dt2 += t4v + + # --- (T1 T3) * V + # Note: Approximate T1 by the CCSDTQ T1 amplitudes of this fragment. + # TODO: Relax this approximation via the callback? + t1t3v = np.zeros_like(dt2) + X_ = einsum('mnef, me -> nf', spinned_antiphys_g, t1) + t1t3v += einsum('nf, nijfab -> ijab', X_, t3) + + X_ = einsum('mnef, njiebf -> ijmb', antiphys_g, t3) / 2 + X_ += einsum('menf, jinfeb -> ijmb', govov, t3) + t1t3v += einsum('ijmb, ma -> ijab', X_, t1) + + X_ = einsum('mnef, mjnfba -> ejab', antiphys_g, t3) / 2 + X_ += einsum('menf, nmjbaf -> ejab', govov, t3) + t1t3v += einsum('ejab, ie -> ijab', X_, t1) + # apply permutation + t1t3v += t1t3v.transpose(1,0,3,2) + dt2 += t1t3v + solver.log.info("T1 norm in ext corr from fragment {}: {}".format(fragment.id, np.linalg.norm(t1))) + + # --- T3 * V + if include_t3v: + # Option to leave out this term, and instead perform T3 * V with the + # integrals in the parent cluster later. + # This will give a different result since the V operators + # will span a different space. Instead, here we just contract T3 with integrals + # in cluster y (FCI), rather than cluster x (CCSD) + + # Note that this requires (vv|ov) [first term], (oo|ov) and (ov|oo) [second term] + t3v = np.zeros_like(dt2) + # First term: 1/2 P_ab [t_ijmaef v_efbm] + t3v += einsum('bemf, jimeaf -> ijab', gvvov - gvvov.transpose(0,3,2,1), t3) / 2 + t3v += einsum('bemf, ijmaef -> ijab', gvvov, t3) + # Second term: -1/2 P_ij [t_imnabe v_jemn] + t3v -= einsum('mjne, minbae -> ijab', gooov - govoo.transpose(0,3,2,1), t3) / 2 + t3v -= einsum('mjne, imnabe -> ijab', gooov, t3) + # Permutation + t3v += t3v.transpose(1,0,3,2) + dt2 += t3v + + return dt1, dt2 + +def t_residual_uhf(solver, fragment, t1, t2, t3, t4, f, v, include_t3v=False): t1_aa, t1_bb = t1 t2_aaaa, t2_abab, t2_bbbb = t2 t3_aaaaaa, t3_abaaba, t3_babbab, t3_bbbbbb = t3 @@ -39,10 +92,20 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): v_aaaa_ovoo, v_aabb_ovoo, v_bbbb_ovoo = v_ovoo nocc = (t1_aa.shape[0], t1_bb.shape[0]) nvir = (t1_aa.shape[1], t1_bb.shape[1]) - t2new_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - t2new_aaaa += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_aaaaaaaa) * 0.5 - t2new_aaaa += einsum("menf,imjnaebf->ijab", v_bbbb_ovov, t4_abababab) * 0.5 - t2new_aaaa += einsum("lcne,ijlnabce->ijab", v_aabb_ovov, t4_aaabaaab) + + dt1_aa = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + dt1_aa += einsum("jbkc,ijkabc->ia", v_aaaa_ovov, t3_aaaaaa) * 0.5 + dt1_aa += einsum("ldme,limdae->ia", v_bbbb_ovov, t3_babbab) * 0.5 + dt1_aa += einsum("jbmd,imjadb->ia", v_aabb_ovov, t3_abaaba) + dt1_bb = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + dt1_bb += einsum("jbkc,jikbac->ia", v_aaaa_ovov, t3_abaaba) * 0.5 + dt1_bb += einsum("ldme,ilmade->ia", v_bbbb_ovov, t3_bbbbbb) * 0.5 + dt1_bb += einsum("kcmd,ikmacd->ia", v_aabb_ovov, t3_babbab) + + dt2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_aaaaaaaa) * 0.5 + dt2_aaaa += einsum("menf,imjnaebf->ijab", v_bbbb_ovov, t4_abababab) * 0.5 + dt2_aaaa += einsum("lcne,ijlnabce->ijab", v_aabb_ovov, t4_aaabaaab) x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) x0 += einsum("jlkc,iklacb->ijab", v_aabb_ooov, t3_abaaba) x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) @@ -60,8 +123,8 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x6 += einsum("ijba->ijab", x1) * -1.0 x6 += einsum("ijba->ijab", x3) x6 += einsum("ijba->ijab", x5) - t2new_aaaa += einsum("ijab->ijab", x6) * -1.0 - t2new_aaaa += einsum("jiab->ijab", x6) + dt2_aaaa += einsum("ijab->ijab", x6) * -1.0 + dt2_aaaa += einsum("jiab->ijab", x6) x7 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) x7 += einsum("bdkc,ikjacd->ijab", v_aabb_vvov, t3_abaaba) x8 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) @@ -79,8 +142,8 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x13 += einsum("ijab->ijab", x7) x13 += einsum("ijab->ijab", x8) * -1.0 x13 += einsum("ijab->ijab", x12) - t2new_aaaa += einsum("ijab->ijab", x13) - t2new_aaaa += einsum("ijba->ijab", x13) * -1.0 + dt2_aaaa += einsum("ijab->ijab", x13) + dt2_aaaa += einsum("ijba->ijab", x13) * -1.0 x14 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) x14 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 x14 += einsum("iajb->ijab", v_aaaa_ovov) @@ -88,7 +151,7 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x15 += einsum("ia->ia", f_aa_ov) x15 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) x15 += einsum("kc,kiac->ia", t1_aa, x14) * -1.0 - t2new_aaaa += einsum("lc,ijlabc->ijab", x15, t3_aaaaaa) + dt2_aaaa += einsum("lc,ijlabc->ijab", x15, t3_aaaaaa) x16 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) x16 += einsum("ibja->ijab", v_bbbb_ovov) x16 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 @@ -96,11 +159,11 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x17 += einsum("ia->ia", f_bb_ov) x17 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) x17 += einsum("kc,kica->ia", t1_bb, x16) * -1.0 - t2new_aaaa += einsum("ne,injaeb->ijab", x17, t3_abaaba) - t2new_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - t2new_bbbb += einsum("ldkc,lijkdabc->ijab", v_aabb_ovov, t4_abbbabbb) - t2new_bbbb += einsum("ldme,limjdaeb->ijab", v_aaaa_ovov, t4_abababab) * 0.5 - t2new_bbbb += einsum("kcnf,ijknabcf->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 0.5 + dt2_aaaa += einsum("ne,injaeb->ijab", x17, t3_abaaba) + dt2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + dt2_bbbb += einsum("ldkc,lijkdabc->ijab", v_aabb_ovov, t4_abbbabbb) + dt2_bbbb += einsum("ldme,limjdaeb->ijab", v_aaaa_ovov, t4_abababab) * 0.5 + dt2_bbbb += einsum("kcnf,ijknabcf->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 0.5 x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) x0 += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) @@ -118,8 +181,8 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x6 += einsum("ijba->ijab", x1) * -1.0 x6 += einsum("ijba->ijab", x3) x6 += einsum("ijba->ijab", x5) - t2new_bbbb += einsum("ijab->ijab", x6) * -1.0 - t2new_bbbb += einsum("jiab->ijab", x6) + dt2_bbbb += einsum("ijab->ijab", x6) * -1.0 + dt2_bbbb += einsum("jiab->ijab", x6) x7 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) x7 += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) x8 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) @@ -137,8 +200,8 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x13 += einsum("ijab->ijab", x7) * -1.0 x13 += einsum("ijab->ijab", x8) x13 += einsum("ijab->ijab", x12) - t2new_bbbb += einsum("ijab->ijab", x13) - t2new_bbbb += einsum("ijba->ijab", x13) * -1.0 + dt2_bbbb += einsum("ijab->ijab", x13) + dt2_bbbb += einsum("ijba->ijab", x13) * -1.0 x14 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) x14 += einsum("ibja->ijab", v_bbbb_ovov) x14 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 @@ -146,7 +209,7 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x15 += einsum("ia->ia", f_bb_ov) x15 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) x15 += einsum("kc,kica->ia", t1_bb, x14) * -1.0 - t2new_bbbb += einsum("kc,ijkabc->ijab", x15, t3_bbbbbb) + dt2_bbbb += einsum("kc,ijkabc->ijab", x15, t3_bbbbbb) x16 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) x16 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 x16 += einsum("iajb->ijab", v_aaaa_ovov) @@ -154,31 +217,31 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x17 += einsum("ia->ia", f_aa_ov) x17 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) x17 += einsum("kc,kiac->ia", t1_aa, x16) * -1.0 - t2new_bbbb += einsum("ld,iljadb->ijab", x17, t3_babbab) - t2new_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) - t2new_abab += einsum("kcld,ikljacdb->ijab", v_aaaa_ovov, t4_aaabaaab) * 0.5 - t2new_abab += einsum("kcbe,ijkaec->ijab", v_aabb_ovvv, t3_abaaba) - t2new_abab += einsum("mebf,jimeaf->ijab", v_bbbb_ovvv, t3_babbab) * -1.0 - t2new_abab += einsum("kcad,ijkcbd->ijab", v_aaaa_ovvv, t3_abaaba) * -1.0 - t2new_abab += einsum("acme,jimbce->ijab", v_aabb_vvov, t3_babbab) - t2new_abab += einsum("mfne,ijmnabef->ijab", v_bbbb_ovov, t4_abbbabbb) * -0.5 - t2new_abab += einsum("kcme,ijkmabce->ijab", v_aabb_ovov, t4_abababab) + dt2_bbbb += einsum("ld,iljadb->ijab", x17, t3_babbab) + dt2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) + dt2_abab += einsum("kcld,ikljacdb->ijab", v_aaaa_ovov, t4_aaabaaab) * 0.5 + dt2_abab += einsum("kcbe,ijkaec->ijab", v_aabb_ovvv, t3_abaaba) + dt2_abab += einsum("mebf,jimeaf->ijab", v_bbbb_ovvv, t3_babbab) * -1.0 + dt2_abab += einsum("kcad,ijkcbd->ijab", v_aaaa_ovvv, t3_abaaba) * -1.0 + dt2_abab += einsum("acme,jimbce->ijab", v_aabb_vvov, t3_babbab) + dt2_abab += einsum("mfne,ijmnabef->ijab", v_bbbb_ovov, t4_abbbabbb) * -0.5 + dt2_abab += einsum("kcme,ijkmabce->ijab", v_aabb_ovov, t4_abababab) x0 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) x0 += einsum("jkia->iajk", v_aabb_ooov) x0 += einsum("kb,jbia->iajk", t1_aa, v_aabb_ovov) - t2new_abab += einsum("meki,jkmbae->ijab", x0, t3_babbab) * -1.0 + dt2_abab += einsum("meki,jkmbae->ijab", x0, t3_babbab) * -1.0 x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) x1 += einsum("ikja->ijka", v_aaaa_ooov) x1 += einsum("ib,jakb->ijka", t1_aa, v_aaaa_ovov) - t2new_abab += einsum("iklc,kjlabc->ijab", x1, t3_abaaba) + dt2_abab += einsum("iklc,kjlabc->ijab", x1, t3_abaaba) x2 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) x2 += einsum("ikja->ijka", v_bbbb_ooov) x2 += einsum("ib,jakb->ijka", t1_bb, v_bbbb_ovov) - t2new_abab += einsum("jnme,minbae->ijab", x2, t3_babbab) * -1.0 + dt2_abab += einsum("jnme,minbae->ijab", x2, t3_babbab) * -1.0 x3 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) x3 += einsum("kaij->ijka", v_aabb_ovoo) x3 += einsum("jb,kaib->ijka", t1_bb, v_aabb_ovov) - t2new_abab += einsum("mjkc,imkabc->ijab", x3, t3_abaaba) * -1.0 + dt2_abab += einsum("mjkc,imkabc->ijab", x3, t3_abaaba) * -1.0 x4 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) x4 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 x4 += einsum("iajb->ijab", v_aaaa_ovov) @@ -186,7 +249,7 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x5 += einsum("ia->ia", f_aa_ov) x5 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) x5 += einsum("kc,kiac->ia", t1_aa, x4) * -1.0 - t2new_abab += einsum("kc,ijkabc->ijab", x5, t3_abaaba) + dt2_abab += einsum("kc,ijkabc->ijab", x5, t3_abaaba) x6 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) x6 += einsum("ibja->ijab", v_bbbb_ovov) x6 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 @@ -194,13 +257,17 @@ def t2_residual_uhf(t1, t2, t3, t4, f, v): x7 += einsum("ia->ia", f_bb_ov) x7 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) x7 += einsum("kc,kica->ia", t1_bb, x6) * -1.0 - t2new_abab += einsum("me,jimbae->ijab", x7, t3_babbab) + dt2_abab += einsum("me,jimbae->ijab", x7, t3_babbab) x8 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) x8 += einsum("kclb,ijlacb->iajk", v_aabb_ovov, t3_babbab) x8 += einsum("kcmd,jimcad->iajk", v_aaaa_ovov, t3_abaaba) - t2new_abab += einsum("ka,jbik->ijab", t1_aa, x8) * -1.0 + dt2_abab += einsum("ka,jbik->ijab", t1_aa, x8) * -1.0 x9 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) x9 += einsum("jclb,iklbac->ijka", v_bbbb_ovov, t3_babbab) * -1.0 x9 += einsum("mdjc,kimacd->ijka", v_aabb_ovov, t3_abaaba) - t2new_abab += einsum("mb,jmia->ijab", t1_bb, x9) * -1.0 - return t2new_aaaa, t2new_abab, t2new_bbbb + dt2_abab += einsum("mb,jmia->ijab", t1_bb, x9) * -1.0 + + dt1 = (dt1_aa, dt1_bb) + dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) + + return dt1, dt2 diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 99d7494aa..c1e4b088f 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -267,6 +267,7 @@ def _integrals_for_extcorr(fragment, fock): eris = emb.get_eris_array(cluster.c_active) else: eris = emb.get_eris_array_uhf(cluster.c_active) + if emb.spinsym == 'restricted': occ = np.s_[:cluster.nocc_active] vir = np.s_[cluster.nocc_active:] @@ -275,7 +276,9 @@ def _integrals_for_extcorr(fragment, fock): gooov = eris[occ,occ,occ,vir] govoo = eris[occ,vir,occ,occ] fov = dot(cluster.c_active_occ.T, fock, cluster.c_active_vir) - if emb.spinsym == 'unrestricted': + return fov, (govov, gvvov, gooov, govoo) + + elif emb.spinsym == 'unrestricted': oa = np.s_[:cluster.nocc_active[0]] ob = np.s_[:cluster.nocc_active[1]] va = np.s_[cluster.nocc_active[0]:] @@ -290,9 +293,11 @@ def _integrals_for_extcorr(fragment, fock): gvvov = (None, eris[1][va, va, ob, vb], None) govoo = (None, eris[1][oa, va, ob, ob], None) return fov, (gooov, govov, govvv, gvvov, govoo) - return fov, govov, gvvov, gooov, govoo -def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extcorr=False): + else: + raise NotImplementedError(emb.spinsym) + +def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): """Make T3 and T4 residual correction to CCSD wave function for given fragment. Expressions consistent with J. Chem. Phys. 86, 2881 (1987): G. E. Scuseria et al. and verified same behaviour as implementation in git@github.com:gustavojra/Methods.git @@ -303,23 +308,21 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc Parameters ---------- - fragment: Fragment class + fragment : Fragment FCI fragment with FCI, CISDTQ or CCSDTQ wave function object in results - fock: ndarray + fock : numpy.ndarray Full system for matrix used for CCSD residuals - solver: Solver class + solver : Solver Used for logging options - include_t3v: Bool + include_t3v : bool If include_t3v, then these terms are included. If not, they are left out (to be contracted later with cluster y integrals). - test_extcorr: Bool - Perform additional tests on expressions, comparing to the EC-CC implementation - with fully UHF T3 and T4 of Seunghoon Lee (https://github.com/seunghoonlee89/excc). Returns ------- - dt1, dt2: ndarray + dt1, dt2 : numpy.ndarray T1 and T2 expressions. + NOTE: These expressions still need to be contracted with energy denominators for full amplitude updates. """ @@ -332,133 +335,17 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True, test_extc if fragment.base.spinsym == 'restricted': # Get ERIs and Fock matrix for the given fragment - # govov is (ia|jb) - fov, govov, gvvov, gooov, govoo = _integrals_for_extcorr(fragment, fock) + f, v = _integrals_for_extcorr(fragment, fock) t1, t2, t3 = wf.t1, wf.t2, wf.t3 t4_abaa, t4_abab = wf.t4 - dt1 = spinalg.zeros_like(t1) - dt2 = spinalg.zeros_like(t2) - - # Construct physical antisymmetrized integrals for some contractions - # Note that some contractions are with physical and some chemical integrals (govov) - antiphys_g = (govov - govov.transpose(0,3,2,1)).transpose(0,2,1,3) - spinned_antiphys_g = (2.0*govov - govov.transpose(0,3,2,1)).transpose(0,2,1,3) - - # --- T1 update - # --- T3 * V - dt1 -= einsum('ijab, jiupab -> up', spinned_antiphys_g, t3) - - if test_extcorr: - # A useful intermediate is the t3_aaa. Construct this from t3 (_aba) mixed spin. - t3_aaa = t3 - t3.transpose(0,2,1,3,4,5) - t3.transpose(1,0,2,3,4,5) - t3_aab = t3.transpose(0,2,1,3,5,4) - dt1_test = einsum('kcld,iklacd->ia', govov, t3_aaa) - dt1_test += einsum('kcld,iklacd->ia', govov, t3_aab) - dt1_test += einsum('kcld,ilkadc->ia', govov, t3_aab) - dt1_test += einsum('kcld,klicda->ia', govov, t3_aab) - dt1_test *= 0.5 - assert(np.allclose(dt1_test, dt1)) - - # --- T2 update - # --- T3 * F - if np.allclose(fov, np.zeros_like(fov)): - solver.log.info("fov block zero: No T3 * f contribution.") - # (Fa) (Taba) contraction - dt2 += einsum('me, ijmabe -> ijab', fov, t3) - # (Fb) (Tabb) contraction - dt2 += einsum('me, jimbae -> ijab', fov, t3) - solver.log.info("(T3 * F) -> T2 update norm from fragment {}: {}".format(fragment.id, np.linalg.norm(dt2))) - if test_extcorr: - t3tmp = t3_aab + t3_aab.transpose(0,2,1,3,5,4) - dt2_test = np.einsum('kc,kijcab->ijab', fov, t3tmp) - assert(np.allclose(dt2, dt2_test)) - - # --- T4 * V - # (Vaa) (Tabaa) contraction - t4v = einsum('mnef, ijmnabef -> ijab', antiphys_g, t4_abaa) / 4 - t4v += t4v.transpose(1,0,3,2) - # (Vab) (Tabab) contraction - t4v += einsum('menf, ijmnabef -> ijab', govov, t4_abab) - dt2 += t4v - if test_extcorr: - t4aaab = t4_abaa.transpose(0,2,3,1,4,6,7,5) - t4aabb = t4_abab.transpose(0,2,1,3,4,6,5,7) - tmp1 = t4aaab + t4aaab.transpose(0,1,3,2,4,5,7,6) - tmp1 += t4aabb.transpose(0,2,1,3,4,6,5,7) - tmp1 += t4aabb.transpose(1,2,0,3,5,6,4,7) - t4v_test = 0.5 * einsum('kcld,klijcdab->ijab', govov, tmp1) - assert(np.allclose(t4v, t4v_test)) - - # --- (T1 T3) * V - # Note: Approximate T1 by the CCSDTQ T1 amplitudes of this fragment. - # TODO: Relax this approximation via the callback? - t1t3v = np.zeros_like(dt2) - X_ = einsum('mnef, me -> nf', spinned_antiphys_g, t1) - t1t3v += einsum('nf, nijfab -> ijab', X_, t3) - - X_ = einsum('mnef, njiebf -> ijmb', antiphys_g, t3) / 2 - X_ += einsum('menf, jinfeb -> ijmb', govov, t3) - t1t3v += einsum('ijmb, ma -> ijab', X_, t1) - - X_ = einsum('mnef, mjnfba -> ejab', antiphys_g, t3) / 2 - X_ += einsum('menf, nmjbaf -> ejab', govov, t3) - t1t3v += einsum('ejab, ie -> ijab', X_, t1) - # apply permutation - t1t3v += t1t3v.transpose(1,0,3,2) - dt2 += t1t3v - solver.log.info("T1 norm in ext corr from fragment {}: {}".format(fragment.id, np.linalg.norm(t1))) - if test_extcorr: - tmp2 = einsum('kdlc,id->kilc', govov, t1) - t1t3v_test = -einsum('kilc,lkjcab->ijab', tmp2, t3tmp) - tmp2 = einsum('kdlc,jd->kjlc', govov, t1) - t1t3v_test -= einsum('kjlc,likcab->ijab', tmp2, t3tmp) - tmp2 = -einsum('kcld,lb->kcbd', govov, t1) - t1t3v_test += einsum('kcbd,kijcad->ijab', tmp2, t3tmp) - tmp2 = -einsum('kcld,la->kcad', govov, t1) - t1t3v_test += einsum('kcad,kijcdb->ijab', tmp2, t3tmp) - tmp2 = 2*einsum('kcld,ld->kc', govov, t1) - tmp2 += -einsum('kdlc,ld->kc', govov, t1) - t1t3v_test += einsum('kc,kijcab->ijab', tmp2, t3tmp) - assert(np.allclose(t1t3v_test, t1t3v)) - - # --- T3 * V - if include_t3v: - # Option to leave out this term, and instead perform T3 * V with the - # integrals in the parent cluster later. - # This will give a different result since the V operators - # will span a different space. Instead, here we just contract T3 with integrals - # in cluster y (FCI), rather than cluster x (CCSD) - - # Note that this requires (vv|ov) [first term], (oo|ov) and (ov|oo) [second term] - t3v = np.zeros_like(dt2) - # First term: 1/2 P_ab [t_ijmaef v_efbm] - t3v += einsum('bemf, jimeaf -> ijab', gvvov - gvvov.transpose(0,3,2,1), t3) / 2 - t3v += einsum('bemf, ijmaef -> ijab', gvvov, t3) - # Second term: -1/2 P_ij [t_imnabe v_jemn] - t3v -= einsum('mjne, minbae -> ijab', gooov - govoo.transpose(0,3,2,1), t3) / 2 - t3v -= einsum('mjne, imnabe -> ijab', gooov, t3) - # Permutation - t3v += t3v.transpose(1,0,3,2) - dt2 += t3v - if test_extcorr: - govvv = gvvov.transpose(2,3,0,1) - t3v_test = -einsum('kilc,lkjcab->ijab', gooov, t3tmp) - t3v_test -= einsum('kjlc,likcab->ijab', gooov, t3tmp) - t3v_test += einsum('kcbd,kijcad->ijab', govvv, t3tmp) - t3v_test += einsum('kcad,kijcdb->ijab', govvv, t3tmp) - assert(np.allclose(t3v_test, t3v)) + dt1, dt2 = ccsdtq.t_residual_rhf(solver, fragment, wf.t1, wf.t2, wf.t3, wf.t4, f, v, include_t3v=include_t3v) elif fragment.base.spinsym == 'unrestricted': # Get ERIs and Fock matrix for the given fragment f, v = _integrals_for_extcorr(fragment, fock) - dt1 = ccsdtq.t1_residual_uhf(wf.t1, wf.t2, wf.t3, wf.t4, f, v) - dt2 = ccsdtq.t2_residual_uhf(wf.t1, wf.t2, wf.t3, wf.t4, f, v) - - if not include_t3v: - # TODO - raise NotImplementedError + dt1, dt2 = ccsdtq.t_residual_uhf(solver, fragment, wf.t1, wf.t2, wf.t3, wf.t4, f, v, include_t3v=include_t3v) else: raise ValueError @@ -566,31 +453,28 @@ def _get_delta_t_for_delta_tailor(fragment, fock): return dt1, dt2 -def externally_correct(solver, external_corrections, eris=None, test_extcorr=False): +def externally_correct(solver, external_corrections, eris=None): """Build callback function for CCSD, to add external correction from other fragments. TODO: combine with `tailor_with_fragments`? Parameters ---------- - solver: CCSD_Solver + solver : CCSD_Solver Vayesta CCSD solver. - external_corrections: list[tuple(int, str, int)] + external_corrections : list of tuple of (int, str, int) List of external corrections. Each tuple contains the fragment ID, type of correction, and number of projectors for the given external correction. - eris: _ChemistsERIs + eris : _ChemistsERIs ERIs for parent CCSD fragment. Used for MO energies in residual contraction, and for type of correction == 'external-ccsdv', where the parent Coulomb integral is contracted. If not passed in, MO energy if needed will be constructed from the diagonal of get_fock() of embedding base class, and the eris will be also be obtained from the embedding base class. Optional. - test_extcorr: Bool - Perform additional tests on correctness of contractions, comparing to an alternative - implementation. Optional. Returns ------- - callback: callable + callback : callable Callback function for PySCF's CCSD solver. """ @@ -659,9 +543,9 @@ def externally_correct(solver, external_corrections, eris=None, test_extcorr=Fal assert (y != fx.id) if corrtype in ['external', 'external-fciv']: - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=True, test_extcorr=test_extcorr) + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=True) elif corrtype == 'external-ccsdv': - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=False, test_extcorr=test_extcorr) + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=False) elif corrtype == 'delta-tailor': dt1y, dt2y = _get_delta_t_for_delta_tailor(fy, fock) else: From cb37eeb4dd075651c5c580bbe8ade3a2ac25738a Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Mon, 20 Mar 2023 12:18:46 +0000 Subject: [PATCH 50/66] More cleanup and addressing reviews --- vayesta/core/types/wf/ccsdtq.py | 35 +++++++++++---------------------- vayesta/core/types/wf/cisdtq.py | 3 ++- vayesta/core/types/wf/fci.py | 9 --------- vayesta/solver/coupling.py | 34 +++++++++++++------------------- 4 files changed, 28 insertions(+), 53 deletions(-) diff --git a/vayesta/core/types/wf/ccsdtq.py b/vayesta/core/types/wf/ccsdtq.py index 486753b66..034cf1ecd 100644 --- a/vayesta/core/types/wf/ccsdtq.py +++ b/vayesta/core/types/wf/ccsdtq.py @@ -21,7 +21,10 @@ def __init__(self, mo, t1, t2, t3, t4): self.t2 = t2 self.t3 = t3 self.t4 = t4 - if not (isinstance(t4, tuple) and len(t4) == 2): + self._check_amps() + + def _check_amps(self): + if not (isinstance(self.t4, tuple) and len(self.t4) == 2): raise ValueError("t4 definition in RCCSDTQ wfn requires tuple of (abaa, abab) spin signatures") def as_ccsdtq(self): @@ -30,29 +33,15 @@ def as_ccsdtq(self): def as_ccsd(self): if self.projector is not None: raise NotImplementedError - return wf_types.RCCSD_WaveFunction(self.mo, self.t1, self.t2) + return wf_types.CCSD_WaveFunction(self.mo, self.t1, self.t2) def as_cisd(self, c0=1.0): return self.as_ccsd().as_cisd() -class UCCSDTQ_WaveFunction(wf_types.WaveFunction): - def __init__(self, mo, t1, t2, t3, t4): - super().__init__(mo) - self.t1 = t1 - self.t2 = t2 - self.t3 = t3 - self.t4 = t4 - # TODO - #if not (isinstance(t4, tuple) and len(t4) == 2): - # raise ValueError("t4 definition in RCCSDTQ wfn requires tuple of (abaa, abab) spin signatures") - - def as_ccsdtq(self): - return self - - def as_ccsd(self): - if self.projector is not None: - raise NotImplementedError - return wf_types.UCCSD_WaveFunction(self.mo, self.t1, self.t2) - - def as_cisd(self, c0=1.0): - return self.as_ccsd().as_cisd() +class UCCSDTQ_WaveFunction(RCCSDTQ_WaveFunction): + def _check_amps(self): + if not (isinstance(self.t3, tuple) and len(self.t3) == 4): + raise ValueError("t4 definition in UCCSDTQ wfn requires tuple of (aaa, aba, bab, bbb) spin signatures") + if not (isinstance(self.t4, tuple) and len(self.t4) == 5): + raise ValueError( + "t4 definition in UCCSDTQ wfn requires tuple of (aaaa, aaab, abab, abbb, bbbb) spin signatures") diff --git a/vayesta/core/types/wf/cisdtq.py b/vayesta/core/types/wf/cisdtq.py index 42a2fc210..fde9cae63 100644 --- a/vayesta/core/types/wf/cisdtq.py +++ b/vayesta/core/types/wf/cisdtq.py @@ -51,7 +51,8 @@ def __init__(self, mo, c0, c1, c2, c3, c4): if not (isinstance(c3, tuple) and len(c3) == 4): raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaa, aba, bab, bbb) spin signatures") if not (isinstance(c4, tuple) and len(c4) == 5): - raise ValueError("c4 definition in UCISDTQ wfn requires tuple of (aaaa, aaab, abab, abbb, bbbb) spin signatures") + raise ValueError( + "c4 definition in UCISDTQ wfn requires tuple of (aaaa, aaab, abab, abbb, bbbb) spin signatures") def as_ccsdtq(self): c1 = tuple(c / self.c0 for c in self.c1) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 360b3a042..074bf0a8e 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -367,12 +367,3 @@ def as_cisdtq(self, c0=None): c4 = tuple(c * fac for c in c4) return wf_types.UCISDTQ_WaveFunction(self.mo, c0, c1, c2, c3, c4) - - def as_ccsd(self): - return self.as_cisd().as_ccsd() - - def as_ccsdtq(self): - return self.as_cisdtq().as_ccsdtq() - - def as_fci(self): - return self diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index c1e4b088f..0f68ee7b4 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -287,11 +287,11 @@ def _integrals_for_extcorr(fragment, fock): fovb = dot(cluster.c_active_occ[1].T, fock[1], cluster.c_active_vir[1]) # TODO make consistent with RHF return value, remove redundancies fov = (fova, fovb) - gooov = (eris[0][oa, oa, oa, va], eris[1][oa, oa, ob, vb], eris[2][ob, ob, ob, vb]) - govov = (eris[0][oa, va, oa, va], eris[1][oa, va, ob, vb], eris[2][ob, vb, ob, vb]) - govvv = (eris[0][oa, va, va, va], eris[1][oa, va, vb, vb], eris[2][ob, vb, vb, vb]) - gvvov = (None, eris[1][va, va, ob, vb], None) - govoo = (None, eris[1][oa, va, ob, ob], None) + gooov = (eris[0][oa,oa,oa,va], eris[1][oa,oa,ob,vb], eris[2][ob,ob,ob,vb]) + govov = (eris[0][oa,va,oa,va], eris[1][oa,va,ob,vb], eris[2][ob,vb,ob,vb]) + govvv = (eris[0][oa,va,va,va], eris[1][oa,va,vb,vb], eris[2][ob,vb,vb,vb]) + gvvov = (None, eris[1][va,va,ob,vb], None) + govoo = (None, eris[1][oa,va,ob,ob], None) return fov, (gooov, govov, govvv, gvvov, govoo) else: @@ -584,9 +584,7 @@ def externally_correct(solver, external_corrections, eris=None): # Contract with fragment x (CCSD) energy denominators # Note that this will not work correctly if a level shift used eia = mo_energy[:nocc, None] - mo_energy[None, nocc:] - # TODO: Not the most memory efficient way to contract with - # energy denominators here. Improve to reduce N^4 memory cost? - eijab = pyscf.lib.direct_sum('ia,jb->ijab',eia,eia) + eijab = pyscf.lib.direct_sum('ia,jb->ijab', eia, eia) dt1 /= eia dt2 /= eijab @@ -602,18 +600,14 @@ def callback(kwargs): elif solver.spinsym == 'unrestricted': if corrtype in ["external", "external-fciv", "external-ccsdv"]: - # FIXME is this done correctly? I update my T amplitudes as T = R / D - T' - e_ia = ( - pyscf.lib.direct_sum("i-a->ia", mo_energy[0][:nocc[0]], mo_energy[0][nocc[0]:]), - pyscf.lib.direct_sum("i-a->ia", mo_energy[1][:nocc[1]], mo_energy[1][nocc[1]:]), - ) - - dt1 = (dt1[0] / e_ia[0], dt1[1] / e_ia[1]) - dt2 = ( - dt2[0] / pyscf.lib.direct_sum("ia,jb->ijab", e_ia[0], e_ia[0]), - dt2[1] / pyscf.lib.direct_sum("ia,jb->ijab", e_ia[0], e_ia[1]), - dt2[2] / pyscf.lib.direct_sum("ia,jb->ijab", e_ia[1], e_ia[1]), - ) + eia_a = mo_energy[0][:nocc[0], None] - mo_energy[0][None, nocc[0]:] + eia_b = mo_energy[1][:nocc[1], None] - mo_energy[1][None, nocc[1]:] + eijab_aa = pyscf.lib.direct_sum('ia,jb->ijab', eia_a, eia_a) + eijab_ab = pyscf.lib.direct_sum('ia,jb->ijab', eia_a, eia_b) + eijab_bb = pyscf.lib.direct_sum('ia,jb->ijab', eia_b, eia_b) + + dt1 = (dt1[0] / eia_a, dt1[1] / eia_b) + dt2 = (dt2[0] / eijab_aa, dt2[1] / eijab_ab, dt2[2] / eijab_bb) solver.log.info("Total external correction amplitudes from all fragments: dT1= %.3e dT2= %.3e", \ *get_amplitude_norm(dt1, dt2)) From 9d003ddfbffd452489d0c27f1eb362c6188498e8 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Mon, 20 Mar 2023 12:22:39 +0000 Subject: [PATCH 51/66] Fix bug in integral unpacking --- vayesta/solver/coupling.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 0f68ee7b4..1c58ab373 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -521,7 +521,7 @@ def externally_correct(solver, external_corrections, eris=None): gooov_x = eris.ovoo.transpose(2,3,0,1) govoo_x = eris.ovoo except: - _, _, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) + _, (_, gvvov_x, gooov_x, govoo_x) = _integrals_for_extcorr(fx, fock) elif emb.spinsym == 'unrestricted': pass # TODO is this only needed for external-ccsdv? From 9e4dc54f2439203dfd1ddcd114f9a9590458f5ae Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Mon, 20 Mar 2023 14:27:45 +0000 Subject: [PATCH 52/66] Move t3v terms into separate function --- vayesta/solver/ccsdtq.py | 358 ++++++++++++++++++++++----------------- 1 file changed, 200 insertions(+), 158 deletions(-) diff --git a/vayesta/solver/ccsdtq.py b/vayesta/solver/ccsdtq.py index 94d5a2e03..3ca0295df 100644 --- a/vayesta/solver/ccsdtq.py +++ b/vayesta/solver/ccsdtq.py @@ -1,6 +1,24 @@ import numpy as np from vayesta.core.util import einsum + +def t2_residual_rhf_t3v(solver, fragment, t3, v): + govov, gvvov, gooov, govoo = v + nocc, nvir = govov.shape[:2] + dt2 = np.zeros((nocc, nocc, nvir, nvir)) + + # First term: 1/2 P_ab [t_ijmaef v_efbm] + dt2 += einsum('bemf, jimeaf -> ijab', gvvov - gvvov.transpose(0,3,2,1), t3) / 2 + dt2 += einsum('bemf, ijmaef -> ijab', gvvov, t3) + # Second term: -1/2 P_ij [t_imnabe v_jemn] + dt2 -= einsum('mjne, minbae -> ijab', gooov - govoo.transpose(0,3,2,1), t3) / 2 + dt2 -= einsum('mjne, imnabe -> ijab', gooov, t3) + # Permutation + dt2 += dt2.transpose(1,0,3,2) + + return dt2 + + def t_residual_rhf(solver, fragment, t1, t2, t3, t4, f, v, include_t3v=False): t4_abaa, t4_abab = t4 fov = f @@ -63,21 +81,75 @@ def t_residual_rhf(solver, fragment, t1, t2, t3, t4, f, v, include_t3v=False): # This will give a different result since the V operators # will span a different space. Instead, here we just contract T3 with integrals # in cluster y (FCI), rather than cluster x (CCSD) - - # Note that this requires (vv|ov) [first term], (oo|ov) and (ov|oo) [second term] - t3v = np.zeros_like(dt2) - # First term: 1/2 P_ab [t_ijmaef v_efbm] - t3v += einsum('bemf, jimeaf -> ijab', gvvov - gvvov.transpose(0,3,2,1), t3) / 2 - t3v += einsum('bemf, ijmaef -> ijab', gvvov, t3) - # Second term: -1/2 P_ij [t_imnabe v_jemn] - t3v -= einsum('mjne, minbae -> ijab', gooov - govoo.transpose(0,3,2,1), t3) / 2 - t3v -= einsum('mjne, imnabe -> ijab', gooov, t3) - # Permutation - t3v += t3v.transpose(1,0,3,2) - dt2 += t3v + dt2 += t2_residual_rhf_t3v(solver, fragment, t3, v) return dt1, dt2 + +def t2_residual_uhf_t3v(solver, fragment, t3, v): + t3_aaaaaa, t3_abaaba, t3_babbab, t3_bbbbbb = t3 + v_ooov, v_ovov, v_ovvv, v_vvov, v_ovoo = v + v_aaaa_ooov, v_aabb_ooov, v_bbbb_ooov = v_ooov + v_aaaa_ovov, v_aabb_ovov, v_bbbb_ovov = v_ovov + v_aaaa_ovvv, v_aabb_ovvv, v_bbbb_ovvv = v_ovvv + v_aaaa_vvov, v_aabb_vvov, v_bbbb_vvov = v_vvov + v_aaaa_ovoo, v_aabb_ovoo, v_bbbb_ovoo = v_ovoo + nocc = (t3_abaaba.shape[0], t3_abaaba.shape[1]) + nvir = (t3_abaaba.shape[3], t3_abaaba.shape[4]) + + x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x0 += einsum("jlkc,iklacb->ijab", v_aabb_ooov, t3_abaaba) + x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x1 += einsum("jlkc,iklabc->ijab", v_aaaa_ooov, t3_aaaaaa) * -1.0 + x2 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x2 += einsum("ijba->ijab", x0) * -1.0 + x2 += einsum("ijba->ijab", x1) * -1.0 + dt2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + dt2_aaaa += einsum("ijab->ijab", x2) * -1.0 + dt2_aaaa += einsum("jiab->ijab", x2) + x3 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x3 += einsum("bdkc,ikjacd->ijab", v_aabb_vvov, t3_abaaba) + x4 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x4 += einsum("kcbd,ijkacd->ijab", v_aaaa_ovvv, t3_aaaaaa) + x5 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x5 += einsum("ijab->ijab", x3) + x5 += einsum("ijab->ijab", x4) * -1.0 + dt2_aaaa += einsum("ijab->ijab", x5) + dt2_aaaa += einsum("ijba->ijab", x5) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x0 += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) + x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x1 += einsum("lcjk,ilkacb->ijab", v_aabb_ovoo, t3_babbab) + x2 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x2 += einsum("ijba->ijab", x0) * -1.0 + x2 += einsum("ijba->ijab", x1) * -1.0 + dt2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + dt2_bbbb += einsum("ijab->ijab", x2) * -1.0 + dt2_bbbb += einsum("jiab->ijab", x2) + x3 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x3 += einsum("kdbc,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) * -1.0 + x4 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x4 += einsum("kdbc,ikjadc->ijab", v_aabb_ovvv, t3_babbab) + x5 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x5 += einsum("ijab->ijab", x3) + x5 += einsum("ijab->ijab", x4) * -1.0 + dt2_bbbb += einsum("ijab->ijab", x5) * -1.0 + dt2_bbbb += einsum("ijba->ijab", x5) + dt2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) + dt2_abab += einsum("ilkc,jlkbac->ijab", v_aabb_ooov, t3_babbab) * -1.0 + dt2_abab += einsum("ldjk,iklabd->ijab", v_aabb_ovoo, t3_abaaba) * -1.0 + dt2_abab += einsum("ilmd,ljmabd->ijab", v_aaaa_ooov, t3_abaaba) * -1.0 + dt2_abab += einsum("ldbc,ijlacd->ijab", v_aabb_ovvv, t3_abaaba) + dt2_abab += einsum("adkc,jikbdc->ijab", v_aabb_vvov, t3_babbab) + dt2_abab += einsum("jnkc,kinbac->ijab", v_bbbb_ooov, t3_babbab) + dt2_abab += einsum("ldae,ijldbe->ijab", v_aaaa_ovvv, t3_abaaba) * -1.0 + dt2_abab += einsum("kcbf,jikcaf->ijab", v_bbbb_ovvv, t3_babbab) * -1.0 + + dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) + + return dt2 + + def t_residual_uhf(solver, fragment, t1, t2, t3, t4, f, v, include_t3v=False): t1_aa, t1_bb = t1 t2_aaaa, t2_abab, t2_bbbb = t2 @@ -103,170 +175,140 @@ def t_residual_uhf(solver, fragment, t1, t2, t3, t4, f, v, include_t3v=False): dt1_bb += einsum("kcmd,ikmacd->ia", v_aabb_ovov, t3_babbab) dt2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - dt2_aaaa += einsum("kcld,ijklabcd->ijab", v_aaaa_ovov, t4_aaaaaaaa) * 0.5 - dt2_aaaa += einsum("menf,imjnaebf->ijab", v_bbbb_ovov, t4_abababab) * 0.5 - dt2_aaaa += einsum("lcne,ijlnabce->ijab", v_aabb_ovov, t4_aaabaaab) - x0 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x0 += einsum("jlkc,iklacb->ijab", v_aabb_ooov, t3_abaaba) + dt2_aaaa += einsum("ldkc,ijlkabdc->ijab", v_aabb_ovov, t4_aaabaaab) + dt2_aaaa += einsum("kcme,ikjmacbe->ijab", v_bbbb_ovov, t4_abababab) * 0.5 + dt2_aaaa += einsum("lfnd,ijlnabdf->ijab", v_aaaa_ovov, t4_aaaaaaaa) * -0.5 + x0 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) + x0 += einsum("jb,kbia->iajk", t1_aa, v_aabb_ovov) x1 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x1 += einsum("jklc,iklabc->ijab", v_aaaa_ooov, t3_aaaaaa) - x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) - x2 += einsum("jb,kbia->iajk", t1_aa, v_aabb_ovov) + x1 += einsum("kcil,jklacb->ijab", x0, t3_abaaba) + x2 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x2 += einsum("ib,jakb->ijka", t1_aa, v_aaaa_ovov) x3 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x3 += einsum("kcil,jklacb->ijab", x2, t3_abaaba) - x4 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) - x4 += einsum("ib,jakb->ijka", t1_aa, v_aaaa_ovov) - x5 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x5 += einsum("iklc,jklabc->ijab", x4, t3_aaaaaa) * -1.0 - x6 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x6 += einsum("ijba->ijab", x0) * -1.0 - x6 += einsum("ijba->ijab", x1) * -1.0 - x6 += einsum("ijba->ijab", x3) - x6 += einsum("ijba->ijab", x5) - dt2_aaaa += einsum("ijab->ijab", x6) * -1.0 - dt2_aaaa += einsum("jiab->ijab", x6) - x7 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x7 += einsum("bdkc,ikjacd->ijab", v_aabb_vvov, t3_abaaba) + x3 += einsum("iklc,jklabc->ijab", x2, t3_aaaaaa) * -1.0 + x4 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x4 += einsum("ijba->ijab", x1) * -1.0 + x4 += einsum("ijba->ijab", x3) * -1.0 + dt2_aaaa += einsum("ijab->ijab", x4) + dt2_aaaa += einsum("jiab->ijab", x4) * -1.0 + x5 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x5 += einsum("kclb,iljabc->ijka", v_aabb_ovov, t3_abaaba) + x6 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x6 += einsum("kclb,ijlabc->ijka", v_aaaa_ovov, t3_aaaaaa) * -1.0 + x7 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x7 += einsum("ijka->ijka", x5) + x7 += einsum("ijka->ijka", x6) x8 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x8 += einsum("kdbc,ijkacd->ijab", v_aaaa_ovvv, t3_aaaaaa) * -1.0 - x9 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) - x9 += einsum("kclb,iljabc->ijka", v_aabb_ovov, t3_abaaba) - x10 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) - x10 += einsum("kclb,ijlabc->ijka", v_aaaa_ovov, t3_aaaaaa) * -1.0 - x11 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) - x11 += einsum("ijka->ijka", x9) - x11 += einsum("ijka->ijka", x10) - x12 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x12 += einsum("ka,ijkb->ijab", t1_aa, x11) - x13 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x13 += einsum("ijab->ijab", x7) - x13 += einsum("ijab->ijab", x8) * -1.0 - x13 += einsum("ijab->ijab", x12) - dt2_aaaa += einsum("ijab->ijab", x13) - dt2_aaaa += einsum("ijba->ijab", x13) * -1.0 - x14 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x14 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 - x14 += einsum("iajb->ijab", v_aaaa_ovov) - x15 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - x15 += einsum("ia->ia", f_aa_ov) - x15 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) - x15 += einsum("kc,kiac->ia", t1_aa, x14) * -1.0 - dt2_aaaa += einsum("lc,ijlabc->ijab", x15, t3_aaaaaa) - x16 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x16 += einsum("ibja->ijab", v_bbbb_ovov) - x16 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 - x17 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - x17 += einsum("ia->ia", f_bb_ov) - x17 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) - x17 += einsum("kc,kica->ia", t1_bb, x16) * -1.0 - dt2_aaaa += einsum("ne,injaeb->ijab", x17, t3_abaaba) + x8 += einsum("ka,ijkb->ijab", t1_aa, x7) + dt2_aaaa += einsum("ijab->ijab", x8) + dt2_aaaa += einsum("ijba->ijab", x8) * -1.0 + x9 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x9 += einsum("ibja->ijab", v_aaaa_ovov) + x9 += einsum("iajb->ijab", v_aaaa_ovov) * -1.0 + x10 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + x10 += einsum("ia->ia", f_aa_ov) + x10 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) + x10 += einsum("kc,kica->ia", t1_aa, x9) * -1.0 + dt2_aaaa += einsum("ld,ijlabd->ijab", x10, t3_aaaaaa) + x11 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x11 += einsum("ibja->ijab", v_bbbb_ovov) + x11 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 + x12 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + x12 += einsum("ia->ia", f_bb_ov) + x12 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) + x12 += einsum("kc,kica->ia", t1_bb, x11) * -1.0 + dt2_aaaa += einsum("kc,ikjacb->ijab", x12, t3_abaaba) dt2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - dt2_bbbb += einsum("ldkc,lijkdabc->ijab", v_aabb_ovov, t4_abbbabbb) - dt2_bbbb += einsum("ldme,limjdaeb->ijab", v_aaaa_ovov, t4_abababab) * 0.5 - dt2_bbbb += einsum("kcnf,ijknabcf->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 0.5 - x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x0 += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) + dt2_bbbb += einsum("kcld,ijklabcd->ijab", v_bbbb_ovov, t4_bbbbbbbb) * 0.5 + dt2_bbbb += einsum("melc,mijleabc->ijab", v_aabb_ovov, t4_abbbabbb) + dt2_bbbb += einsum("menf,minjeafb->ijab", v_aaaa_ovov, t4_abababab) * 0.5 + x0 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x0 += einsum("ib,jakb->ijka", t1_bb, v_bbbb_ovov) x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x1 += einsum("lcjk,ilkacb->ijab", v_aabb_ovoo, t3_babbab) - x2 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) - x2 += einsum("ib,jakb->ijka", t1_bb, v_bbbb_ovov) + x1 += einsum("iklc,jklabc->ijab", x0, t3_bbbbbb) * -1.0 + x2 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) + x2 += einsum("ib,kajb->ijka", t1_bb, v_aabb_ovov) x3 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x3 += einsum("ilkc,jklabc->ijab", x2, t3_bbbbbb) - x4 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) - x4 += einsum("ib,kajb->ijka", t1_bb, v_aabb_ovov) - x5 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x5 += einsum("iklc,jlkacb->ijab", x4, t3_babbab) - x6 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x6 += einsum("ijba->ijab", x0) * -1.0 - x6 += einsum("ijba->ijab", x1) * -1.0 - x6 += einsum("ijba->ijab", x3) - x6 += einsum("ijba->ijab", x5) - dt2_bbbb += einsum("ijab->ijab", x6) * -1.0 - dt2_bbbb += einsum("jiab->ijab", x6) - x7 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x7 += einsum("kcbd,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) + x3 += einsum("iklc,jlkacb->ijab", x2, t3_babbab) + x4 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x4 += einsum("ijba->ijab", x1) * -1.0 + x4 += einsum("ijba->ijab", x3) * -1.0 + dt2_bbbb += einsum("ijab->ijab", x4) + dt2_bbbb += einsum("jiab->ijab", x4) * -1.0 + x5 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x5 += einsum("kclb,ijlabc->ijka", v_bbbb_ovov, t3_bbbbbb) * -1.0 + x6 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x6 += einsum("lckb,iljacb->ijka", v_aabb_ovov, t3_babbab) + x7 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x7 += einsum("ijka->ijka", x5) + x7 += einsum("ijka->ijka", x6) x8 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x8 += einsum("kdbc,ikjadc->ijab", v_aabb_ovvv, t3_babbab) - x9 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) - x9 += einsum("kclb,ijlabc->ijka", v_bbbb_ovov, t3_bbbbbb) * -1.0 - x10 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) - x10 += einsum("lckb,iljacb->ijka", v_aabb_ovov, t3_babbab) - x11 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) - x11 += einsum("ijka->ijka", x9) - x11 += einsum("ijka->ijka", x10) - x12 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x12 += einsum("ka,ijkb->ijab", t1_bb, x11) - x13 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x13 += einsum("ijab->ijab", x7) * -1.0 - x13 += einsum("ijab->ijab", x8) - x13 += einsum("ijab->ijab", x12) - dt2_bbbb += einsum("ijab->ijab", x13) - dt2_bbbb += einsum("ijba->ijab", x13) * -1.0 - x14 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x14 += einsum("ibja->ijab", v_bbbb_ovov) - x14 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 - x15 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - x15 += einsum("ia->ia", f_bb_ov) - x15 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) - x15 += einsum("kc,kica->ia", t1_bb, x14) * -1.0 - dt2_bbbb += einsum("kc,ijkabc->ijab", x15, t3_bbbbbb) - x16 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x16 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 - x16 += einsum("iajb->ijab", v_aaaa_ovov) - x17 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - x17 += einsum("ia->ia", f_aa_ov) - x17 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) - x17 += einsum("kc,kiac->ia", t1_aa, x16) * -1.0 - dt2_bbbb += einsum("ld,iljadb->ijab", x17, t3_babbab) + x8 += einsum("ka,ijkb->ijab", t1_bb, x7) + dt2_bbbb += einsum("ijab->ijab", x8) + dt2_bbbb += einsum("ijba->ijab", x8) * -1.0 + x9 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x9 += einsum("ibja->ijab", v_bbbb_ovov) + x9 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 + x10 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + x10 += einsum("ia->ia", f_bb_ov) + x10 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) + x10 += einsum("kc,kica->ia", t1_bb, x9) * -1.0 + dt2_bbbb += einsum("lc,ijlabc->ijab", x10, t3_bbbbbb) + x11 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x11 += einsum("ibja->ijab", v_aaaa_ovov) + x11 += einsum("iajb->ijab", v_aaaa_ovov) * -1.0 + x12 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + x12 += einsum("ia->ia", f_aa_ov) + x12 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) + x12 += einsum("kc,kica->ia", t1_aa, x11) * -1.0 + dt2_bbbb += einsum("me,imjaeb->ijab", x12, t3_babbab) dt2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) dt2_abab += einsum("kcld,ikljacdb->ijab", v_aaaa_ovov, t4_aaabaaab) * 0.5 - dt2_abab += einsum("kcbe,ijkaec->ijab", v_aabb_ovvv, t3_abaaba) - dt2_abab += einsum("mebf,jimeaf->ijab", v_bbbb_ovvv, t3_babbab) * -1.0 - dt2_abab += einsum("kcad,ijkcbd->ijab", v_aaaa_ovvv, t3_abaaba) * -1.0 - dt2_abab += einsum("acme,jimbce->ijab", v_aabb_vvov, t3_babbab) + dt2_abab += einsum("ldme,ijlmabde->ijab", v_aabb_ovov, t4_abababab) dt2_abab += einsum("mfne,ijmnabef->ijab", v_bbbb_ovov, t4_abbbabbb) * -0.5 - dt2_abab += einsum("kcme,ijkmabce->ijab", v_aabb_ovov, t4_abababab) - x0 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) - x0 += einsum("jkia->iajk", v_aabb_ooov) - x0 += einsum("kb,jbia->iajk", t1_aa, v_aabb_ovov) - dt2_abab += einsum("meki,jkmbae->ijab", x0, t3_babbab) * -1.0 - x1 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) - x1 += einsum("ikja->ijka", v_aaaa_ooov) - x1 += einsum("ib,jakb->ijka", t1_aa, v_aaaa_ovov) - dt2_abab += einsum("iklc,kjlabc->ijab", x1, t3_abaaba) - x2 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) - x2 += einsum("ikja->ijka", v_bbbb_ooov) - x2 += einsum("ib,jakb->ijka", t1_bb, v_bbbb_ovov) - dt2_abab += einsum("jnme,minbae->ijab", x2, t3_babbab) * -1.0 - x3 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) - x3 += einsum("kaij->ijka", v_aabb_ovoo) - x3 += einsum("jb,kaib->ijka", t1_bb, v_aabb_ovov) - dt2_abab += einsum("mjkc,imkabc->ijab", x3, t3_abaaba) * -1.0 - x4 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) - x4 += einsum("ibja->ijab", v_aaaa_ovov) * -1.0 - x4 += einsum("iajb->ijab", v_aaaa_ovov) - x5 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) - x5 += einsum("ia->ia", f_aa_ov) - x5 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) - x5 += einsum("kc,kiac->ia", t1_aa, x4) * -1.0 - dt2_abab += einsum("kc,ijkabc->ijab", x5, t3_abaaba) - x6 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) - x6 += einsum("ibja->ijab", v_bbbb_ovov) - x6 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 - x7 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) - x7 += einsum("ia->ia", f_bb_ov) - x7 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) - x7 += einsum("kc,kica->ia", t1_bb, x6) * -1.0 - dt2_abab += einsum("me,jimbae->ijab", x7, t3_babbab) + x0 = np.zeros((nocc[0], nocc[0], nocc[0], nvir[0]), dtype=np.float64) + x0 += einsum("ib,jakb->ijka", t1_aa, v_aaaa_ovov) + dt2_abab += einsum("ikld,kjlabd->ijab", x0, t3_abaaba) + x1 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) + x1 += einsum("ib,kajb->ijka", t1_bb, v_aabb_ovov) + dt2_abab += einsum("jmld,imlabd->ijab", x1, t3_abaaba) * -1.0 + x2 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) + x2 += einsum("jb,kbia->iajk", t1_aa, v_aabb_ovov) + dt2_abab += einsum("meil,jlmbae->ijab", x2, t3_babbab) * -1.0 + x3 = np.zeros((nocc[1], nocc[1], nocc[1], nvir[1]), dtype=np.float64) + x3 += einsum("ib,jakb->ijka", t1_bb, v_bbbb_ovov) + dt2_abab += einsum("jmne,minbae->ijab", x3, t3_babbab) + x4 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) + x4 += einsum("ibja->ijab", v_bbbb_ovov) + x4 += einsum("iajb->ijab", v_bbbb_ovov) * -1.0 + x5 = np.zeros((nocc[1], nvir[1]), dtype=np.float64) + x5 += einsum("ia->ia", f_bb_ov) + x5 += einsum("jb,jbia->ia", t1_aa, v_aabb_ovov) + x5 += einsum("kc,kica->ia", t1_bb, x4) * -1.0 + dt2_abab += einsum("me,jimbae->ijab", x5, t3_babbab) + x6 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) + x6 += einsum("ibja->ijab", v_aaaa_ovov) + x6 += einsum("iajb->ijab", v_aaaa_ovov) * -1.0 + x7 = np.zeros((nocc[0], nvir[0]), dtype=np.float64) + x7 += einsum("ia->ia", f_aa_ov) + x7 += einsum("jb,iajb->ia", t1_bb, v_aabb_ovov) + x7 += einsum("kc,kica->ia", t1_aa, x6) * -1.0 + dt2_abab += einsum("ld,ijlabd->ijab", x7, t3_abaaba) x8 = np.zeros((nocc[1], nvir[1], nocc[0], nocc[0]), dtype=np.float64) x8 += einsum("kclb,ijlacb->iajk", v_aabb_ovov, t3_babbab) x8 += einsum("kcmd,jimcad->iajk", v_aaaa_ovov, t3_abaaba) - dt2_abab += einsum("ka,jbik->ijab", t1_aa, x8) * -1.0 + dt2_abab += einsum("la,jbil->ijab", t1_aa, x8) * -1.0 x9 = np.zeros((nocc[1], nocc[1], nocc[0], nvir[0]), dtype=np.float64) x9 += einsum("jclb,iklbac->ijka", v_bbbb_ovov, t3_babbab) * -1.0 x9 += einsum("mdjc,kimacd->ijka", v_aabb_ovov, t3_abaaba) dt2_abab += einsum("mb,jmia->ijab", t1_bb, x9) * -1.0 + if include_t3v: + dt2_t3v = t2_residual_uhf_t3v(solver, fragment, t3, v) + dt2_aaaa += dt2_t3v[0] + dt2_abab += dt2_t3v[1] + dt2_bbbb += dt2_t3v[2] + dt1 = (dt1_aa, dt1_bb) dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) From ff11ba5333322938acb74ff25841a2a4e28a218e Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Tue, 21 Mar 2023 14:38:17 +0000 Subject: [PATCH 53/66] Starting UHF t3v (buggy) --- vayesta/solver/coupling.py | 143 ++++++++++++++++++++++++------ vayesta/tests/ewf/test_extcorr.py | 96 ++++++++++---------- 2 files changed, 164 insertions(+), 75 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 1c58ab373..cab65e149 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -285,7 +285,6 @@ def _integrals_for_extcorr(fragment, fock): vb = np.s_[cluster.nocc_active[1]:] fova = dot(cluster.c_active_occ[0].T, fock[0], cluster.c_active_vir[0]) fovb = dot(cluster.c_active_occ[1].T, fock[1], cluster.c_active_vir[1]) - # TODO make consistent with RHF return value, remove redundancies fov = (fova, fovb) gooov = (eris[0][oa,oa,oa,va], eris[1][oa,oa,ob,vb], eris[2][ob,ob,ob,vb]) govov = (eris[0][oa,va,oa,va], eris[1][oa,va,ob,vb], eris[2][ob,vb,ob,vb]) @@ -352,27 +351,28 @@ def _get_delta_t_for_extcorr(fragment, fock, solver, include_t3v=True): return dt1, dt2 -def _get_delta_t2_from_t3v(gvvov_x, gooov_x, govoo_x, frag_child, rxy_occ, rxy_vir, cxs_occ, projectors): +def _get_delta_t2_from_t3v(govvv_x, gvvov_x, gooov_x, govoo_x, frag_child, rxy_occ, rxy_vir, cxs_occ, projectors): """Perform the (T3 * V) contraction for the external correction, with the V integrals in the parent basis (x). This will change the results as the V retains one open index in the resulting T2 contributions. Parameters ---------- - gvvov_x, gooov_x, govoo_x: ndarray - Integrals over various occ, vir slices in the parent (x) cluster - frag_child: fragment type + govvv_x, gvvov_x, gooov_x, govoo_x : ndarray + Integrals over various occ, vir slices in the parent (x) cluster. + govvv_x not required for unrestricted calculations. + frag_child : Fragment Fragment of the child cluster (y) - rxy_occ, rxy_vir: ndarray + rxy_occ, rxy_vir : numpy.ndarray Projection operator from x cluster to y cluster in the occ (vir) space - cxs_occ: ndarray + cxs_occ : numpy.ndarray Cluster orbitals of cluster x contracted with overlap - projectors: int + projectors : int Number of projectors onto the fragment space of y Returns ------- - dt2: ndarray + dt2 : numpy.ndarray Update to T2 amplitudes in the parent (x) basis """ @@ -408,18 +408,90 @@ def _get_delta_t2_from_t3v(gvvov_x, gooov_x, govoo_x, frag_child, rxy_occ, rxy_v # Include permutation dt2 = t3v_x + t3v_x.transpose(1,0,3,2) - # Find the fragment projector of cluster y (child) in the basis of cluster x (parent) - c_frag_xocc = spinalg.dot(spinalg.T(frag_child.c_frag), spinalg.T(cxs_occ)) - proj_y_in_x = spinalg.dot(spinalg.T(c_frag_xocc), c_frag_xocc) - - # Project (t3 v) contribution onto fragment of cluster y - dt2 = project_t2(dt2, proj_y_in_x, projectors=projectors) - elif frag_child.base.spinsym == 'unrestricted': - raise NotImplementedError + gooov_aaaa, gooov_aabb, gooov_bbbb = gooov_x + govoo_aaaa, govoo_aabb, govoo_bbbb = govoo_x + govvv_aaaa, govvv_aabb, govvv_bbbb = govvv_x + gvvov_aaaa, gvvov_aabb, gvvov_bbbb = gvvov_x + + t3_aaa, t3_aba, t3_bab, t3_bbb = t3 + + govvv_aaaa_ = einsum('iabc,iI,aA,cC -> IAbC', govvv_aaaa, rxy_occ[0], rxy_vir[0], rxy_vir[0]) + govvv_aabb_ = einsum('iabc,iI,aA,cC -> IAbC', govvv_aabb, rxy_occ[0], rxy_vir[0], rxy_vir[1]) + govvv_bbbb_ = einsum('iabc,iI,aA,cC -> IAbC', govvv_bbbb, rxy_occ[1], rxy_vir[1], rxy_vir[1]) + + gvvov_aaaa_ = einsum('abic,bB,iI,cC -> aBIC', gvvov_aaaa, rxy_vir[0], rxy_occ[0], rxy_vir[0]) + gvvov_aabb_ = einsum('abic,bB,iI,cC -> aBIC', gvvov_aabb, rxy_vir[0], rxy_occ[1], rxy_vir[1]) + gvvov_bbbb_ = einsum('abic,bB,iI,cC -> aBIC', gvvov_bbbb, rxy_vir[1], rxy_occ[1], rxy_vir[1]) + + gooov_aaaa_ = einsum('ijka,jJ,kK,aA -> iJKA', gooov_aaaa, rxy_occ[0], rxy_occ[0], rxy_vir[0]) + gooov_aabb_ = einsum('ijka,jJ,kK,aA -> iJKA', gooov_aabb, rxy_occ[0], rxy_occ[1], rxy_vir[1]) + gooov_bbbb_ = einsum('ijka,jJ,kK,aA -> iJKA', gooov_bbbb, rxy_occ[1], rxy_occ[1], rxy_vir[1]) + + govoo_aaaa_ = einsum('iajk,iI,aA,kK -> IAjK', govoo_aaaa, rxy_occ[0], rxy_vir[0], rxy_occ[0]) + govoo_aabb_ = einsum('iajk,iI,aA,kK -> IAjK', govoo_aabb, rxy_occ[0], rxy_vir[0], rxy_occ[1]) + govoo_bbbb_ = einsum('iajk,iI,aA,kK -> IAjK', govoo_bbbb, rxy_occ[1], rxy_vir[1], rxy_occ[1]) + + x0 = einsum("Jlkc,iklacb->iJab", gooov_aabb_, t3_aba) + x1 = einsum("Jlkc,iklabc->iJab", gooov_aaaa_, t3_aaa) * -1.0 + x2 = einsum("iJba->iJab", x0) * -1.0 + x2 += einsum("iJba->iJab", x1) * -1.0 + x2 = einsum("iJab,Ii,Aa,Bb->IJAB", x2, rxy_occ[0], rxy_vir[0], rxy_vir[0]) + dt2_aaaa = einsum("ijab->ijab", x2) * -1.0 + dt2_aaaa += einsum("jiab->ijab", x2) + + x0 = einsum("Bdkc,ikjacd->ijaB", gvvov_aabb_, t3_aba) + x1 = einsum("kcBd,ijkacd->ijaB", govvv_aaaa_, t3_aaa) + x2 = einsum("ijaB->ijaB", x0) + x2 += einsum("ijaB->ijaB", x1) * -1.0 + x2 = einsum("ijaB,Ii,Jj,Aa->IJAB", x2, rxy_occ[0], rxy_occ[0], rxy_vir[0]) + dt2_aaaa += einsum("ijab->ijab", x2) + dt2_aaaa += einsum("ijba->ijab", x2) * -1.0 + + x0 = einsum("Jklc,iklabc->iJab", gooov_bbbb_, t3_bbb) + x1 = einsum("lcJk,ilkacb->iJab", govoo_aabb_, t3_bab) + x2 = einsum("iJba->iJab", x0) * -1.0 + x2 += einsum("iJba->iJab", x1) * -1.0 + x2 = einsum("iJab,Ii,Aa,Bb->IJAB", x2, rxy_occ[1], rxy_vir[1], rxy_vir[1]) + dt2_bbbb = einsum("ijab->ijab", x2) * -1.0 + dt2_bbbb += einsum("jiab->ijab", x2) + + x0 = einsum("kdBc,ijkacd->ijaB", govvv_bbbb_, t3_bbb) * -1.0 + x1 = einsum("kdBc,ikjadc->ijaB", govvv_aabb_, t3_bab) + x2 = einsum("ijaB->ijaB", x0) + x2 += einsum("ijaB->ijaB", x1) * -1.0 + x2 = einsum("ijaB,Ii,Jj,Aa->IJAB", x2, rxy_occ[1], rxy_occ[1], rxy_vir[1]) + dt2_bbbb += einsum("ijab->ijab", x2) * -1.0 + dt2_bbbb += einsum("ijba->ijab", x2) + + x0 = einsum("Ilkc,jlkbac->Ijab", gooov_aabb, t3_bab) * -1.0 + x0 += einsum("Ilmd,ljmabd->Ijab", gooov_aaaa, t3_aba) * -1.0 + dt2_abab = einsum("Ijab,Jj,Aa,Bb->IJAB", x0, rxy_occ[1], rxy_vir[0], rxy_vir[1]) + + x0 = einsum("Jnkc,kinbac->iJab", gooov_bbbb, t3_bab) + x0 += einsum("ldJk,iklabd->iJab", govoo_aabb, t3_aba) * -1.0 + dt2_abab += einsum("iJab,Ii,Aa,Bb->IJAB", x0, rxy_occ[0], rxy_vir[0], rxy_vir[1]) + + x0 = einsum("ldAe,ijldbe->ijAb", govvv_aaaa, t3_aba) * -1.0 + x0 += einsum("Adkc,jikbdc->ijAb", gvvov_aabb, t3_bab) + dt2_abab += einsum("ijAb,Ii,Jj,Bb->IJAB", x0, rxy_occ[0], rxy_occ[1], rxy_vir[1]) + + x0 = einsum("ldBc,ijlacd->ijaB", govvv_aabb, t3_aba) + x0 += einsum("kcBf,jikcaf->ijaB", govvv_bbbb, t3_bab) * -1.0 + dt2_abab = einsum("ijaB,Ii,Jj,Aa->IJAB", x0, rxy_occ[0], rxy_occ[1], rxy_vir[0]) + + dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) + else: raise ValueError + # Find the fragment projector of cluster y (child) in the basis of cluster x (parent) + c_frag_xocc = spinalg.dot(spinalg.T(frag_child.c_frag), spinalg.T(cxs_occ)) + proj_y_in_x = spinalg.dot(spinalg.T(c_frag_xocc), c_frag_xocc) + + # Project (t3 v) contribution onto fragment of cluster y + dt2 = project_t2(dt2, proj_y_in_x, projectors=projectors) + return dt2 def _get_delta_t_for_delta_tailor(fragment, fock): @@ -512,18 +584,34 @@ def externally_correct(solver, external_corrections, eris=None): # if passed in. Otherwise, form the required integrals # for this parent cluster. Note that not all of these are needed. if eris is None: - _, _, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) + _, govvv_x, gvvov_x, gooov_x, govoo_x = _integrals_for_extcorr(fx, fock) else: if emb.spinsym == 'restricted': - try: - # TODO: Sort this out for when integrals are stored in HDF5 files - gvvov_x = ao2mo_helper.get_ovvv(eris).transpose(2,3,0,1) - gooov_x = eris.ovoo.transpose(2,3,0,1) - govoo_x = eris.ovoo - except: - _, (_, gvvov_x, gooov_x, govoo_x) = _integrals_for_extcorr(fx, fock) + govvv_x = None + gvvov_x = np.array(ao2mo_helper.get_ovvv(eris)).transpose(2,3,0,1) + gooov_x = np.array(eris.ovoo).transpose(2,3,0,1) + govoo_x = np.array(eris.ovoo) elif emb.spinsym == 'unrestricted': - pass # TODO is this only needed for external-ccsdv? + govvv_x = ( + np.array(ao2mo_helper.get_ovvv(eris, block="ovvv")), + np.array(ao2mo_helper.get_ovvv(eris, block="ovVV")), + np.array(ao2mo_helper.get_ovvv(eris, block="OVVV")), + ) + gvvov_x = ( + np.array(ao2mo_helper.get_ovvv(eris, block="ovvv")).transpose(2,3,0,1), + np.array(ao2mo_helper.get_ovvv(eris, block="OVvv")).transpose(2,3,0,1), + np.array(ao2mo_helper.get_ovvv(eris, block="OVVV")).transpose(2,3,0,1), + ) + gooov_x = ( + np.array(eris.ovoo).transpose(2,3,0,1), + np.array(eris.OVoo).transpose(2,3,0,1), + np.array(eris.OVOO).transpose(2,3,0,1), + ) + govoo_x = ( + np.array(eris.ovoo), + np.array(eris.OVoo), + np.array(eris.OVOO), + ) # delta-T1 and delta-T2 amplitudes, to be added to the CCSD amplitudes if solver.spinsym == 'restricted': @@ -572,7 +660,8 @@ def externally_correct(solver, external_corrections, eris=None): # Include the t3v term, contracting with the integrals from the x cluster # These have already been fragment projected, and rotated into the x cluster # in this function. - dt2y_t3v = _get_delta_t2_from_t3v(gvvov_x, gooov_x, govoo_x, fy, rxy_occ, rxy_vir, cxs_occ, projectors) + dt2y_t3v = _get_delta_t2_from_t3v(govvv_x, gvvov_x, gooov_x, govoo_x, fy, + rxy_occ, rxy_vir, cxs_occ, projectors) dt2 = spinalg.add(dt2, dt2y_t3v) solver.log.info("External correction residuals from fragment %3d (%s via %s): dT1= %.3e dT2= %.3e", diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index 3c8eb3576..9a6662617 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -139,20 +139,20 @@ def test_r_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): # uhf tests - #@pytest.mark.slow - #def test_u_exact_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.slow + def test_u_exact_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) - #@pytest.mark.slow - #def test_u_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.slow + def test_u_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) - #@pytest.mark.slow - #def test_u_exact_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.slow + def test_u_exact_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_proj0_fciv_store(self): @@ -176,20 +176,20 @@ def test_u_regression_ec_lih_631g_atomicfrags_proj2_fciv_store(self): self.assertAlmostEqual(e_tot, -7.988937336775954) - #@pytest.mark.fast - #def test_u_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.fast + def test_u_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) - #@pytest.mark.slow - #def test_u_exact_ec_lih_631g_fullsystem_proj1_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.slow + def test_u_exact_ec_lih_631g_fullsystem_proj1_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) - #@pytest.mark.fast - #def test_u_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.fast + def test_u_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_fullsystem_proj0_fciv_store(self): @@ -283,20 +283,20 @@ def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self) # uhf tests - #@pytest.mark.slow - #def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.slow + def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) - #@pytest.mark.slow - #def test_u_exact_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.slow + def test_u_exact_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) - #@pytest.mark.slow - #def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.slow + def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_store(self): @@ -320,20 +320,20 @@ def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_fciv_store(self self.assertAlmostEqual(e_tot, -7.988931393739511) - #@pytest.mark.fast - #def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.fast + def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) - #@pytest.mark.slow - #def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.slow + def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) - #@pytest.mark.fast - #def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): - # e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - # self.assertAlmostEqual(e_tot, fci_e_tot) + @pytest.mark.fast + def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_fciv_store(self): From cabb9871655173773a90228b130c09b52a44f502 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Thu, 23 Mar 2023 11:47:59 +0000 Subject: [PATCH 54/66] Fixes bugs in UHF external-ccsdv --- vayesta/solver/ccsdtq.py | 4 +++ vayesta/solver/coupling.py | 50 ++++++++++++++++---------------------- 2 files changed, 25 insertions(+), 29 deletions(-) diff --git a/vayesta/solver/ccsdtq.py b/vayesta/solver/ccsdtq.py index 3ca0295df..91c867983 100644 --- a/vayesta/solver/ccsdtq.py +++ b/vayesta/solver/ccsdtq.py @@ -107,6 +107,7 @@ def t2_residual_uhf_t3v(solver, fragment, t3, v): dt2_aaaa = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) dt2_aaaa += einsum("ijab->ijab", x2) * -1.0 dt2_aaaa += einsum("jiab->ijab", x2) + x3 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) x3 += einsum("bdkc,ikjacd->ijab", v_aabb_vvov, t3_abaaba) x4 = np.zeros((nocc[0], nocc[0], nvir[0], nvir[0]), dtype=np.float64) @@ -116,6 +117,7 @@ def t2_residual_uhf_t3v(solver, fragment, t3, v): x5 += einsum("ijab->ijab", x4) * -1.0 dt2_aaaa += einsum("ijab->ijab", x5) dt2_aaaa += einsum("ijba->ijab", x5) * -1.0 + x0 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) x0 += einsum("jklc,iklabc->ijab", v_bbbb_ooov, t3_bbbbbb) x1 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) @@ -126,6 +128,7 @@ def t2_residual_uhf_t3v(solver, fragment, t3, v): dt2_bbbb = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) dt2_bbbb += einsum("ijab->ijab", x2) * -1.0 dt2_bbbb += einsum("jiab->ijab", x2) + x3 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) x3 += einsum("kdbc,ijkacd->ijab", v_bbbb_ovvv, t3_bbbbbb) * -1.0 x4 = np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]), dtype=np.float64) @@ -135,6 +138,7 @@ def t2_residual_uhf_t3v(solver, fragment, t3, v): x5 += einsum("ijab->ijab", x4) * -1.0 dt2_bbbb += einsum("ijab->ijab", x5) * -1.0 dt2_bbbb += einsum("ijba->ijab", x5) + dt2_abab = np.zeros((nocc[0], nocc[1], nvir[0], nvir[1]), dtype=np.float64) dt2_abab += einsum("ilkc,jlkbac->ijab", v_aabb_ooov, t3_babbab) * -1.0 dt2_abab += einsum("ldjk,iklabd->ijab", v_aabb_ovoo, t3_abaaba) * -1.0 diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index cab65e149..5fe9026da 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -464,21 +464,21 @@ def _get_delta_t2_from_t3v(govvv_x, gvvov_x, gooov_x, govoo_x, frag_child, rxy_o dt2_bbbb += einsum("ijab->ijab", x2) * -1.0 dt2_bbbb += einsum("ijba->ijab", x2) - x0 = einsum("Ilkc,jlkbac->Ijab", gooov_aabb, t3_bab) * -1.0 - x0 += einsum("Ilmd,ljmabd->Ijab", gooov_aaaa, t3_aba) * -1.0 + x0 = einsum("Ilkc,jlkbac->Ijab", gooov_aabb_, t3_bab) * -1.0 + x0 += einsum("Ilmd,ljmabd->Ijab", gooov_aaaa_, t3_aba) * -1.0 dt2_abab = einsum("Ijab,Jj,Aa,Bb->IJAB", x0, rxy_occ[1], rxy_vir[0], rxy_vir[1]) - x0 = einsum("Jnkc,kinbac->iJab", gooov_bbbb, t3_bab) - x0 += einsum("ldJk,iklabd->iJab", govoo_aabb, t3_aba) * -1.0 + x0 = einsum("Jnkc,kinbac->iJab", gooov_bbbb_, t3_bab) + x0 += einsum("ldJk,iklabd->iJab", govoo_aabb_, t3_aba) * -1.0 dt2_abab += einsum("iJab,Ii,Aa,Bb->IJAB", x0, rxy_occ[0], rxy_vir[0], rxy_vir[1]) - x0 = einsum("ldAe,ijldbe->ijAb", govvv_aaaa, t3_aba) * -1.0 - x0 += einsum("Adkc,jikbdc->ijAb", gvvov_aabb, t3_bab) + x0 = einsum("ldAe,ijldbe->ijAb", govvv_aaaa_, t3_aba) * -1.0 + x0 += einsum("Adkc,jikbdc->ijAb", gvvov_aabb_, t3_bab) dt2_abab += einsum("ijAb,Ii,Jj,Bb->IJAB", x0, rxy_occ[0], rxy_occ[1], rxy_vir[1]) - x0 = einsum("ldBc,ijlacd->ijaB", govvv_aabb, t3_aba) - x0 += einsum("kcBf,jikcaf->ijaB", govvv_bbbb, t3_bab) * -1.0 - dt2_abab = einsum("ijaB,Ii,Jj,Aa->IJAB", x0, rxy_occ[0], rxy_occ[1], rxy_vir[0]) + x0 = einsum("ldBc,ijlacd->ijaB", govvv_aabb_, t3_aba) + x0 += einsum("kcBf,jikcaf->ijaB", govvv_bbbb_, t3_bab) * -1.0 + dt2_abab += einsum("ijaB,Ii,Jj,Aa->IJAB", x0, rxy_occ[0], rxy_occ[1], rxy_vir[0]) dt2 = (dt2_aaaa, dt2_abab, dt2_bbbb) @@ -592,26 +592,18 @@ def externally_correct(solver, external_corrections, eris=None): gooov_x = np.array(eris.ovoo).transpose(2,3,0,1) govoo_x = np.array(eris.ovoo) elif emb.spinsym == 'unrestricted': - govvv_x = ( - np.array(ao2mo_helper.get_ovvv(eris, block="ovvv")), - np.array(ao2mo_helper.get_ovvv(eris, block="ovVV")), - np.array(ao2mo_helper.get_ovvv(eris, block="OVVV")), - ) - gvvov_x = ( - np.array(ao2mo_helper.get_ovvv(eris, block="ovvv")).transpose(2,3,0,1), - np.array(ao2mo_helper.get_ovvv(eris, block="OVvv")).transpose(2,3,0,1), - np.array(ao2mo_helper.get_ovvv(eris, block="OVVV")).transpose(2,3,0,1), - ) - gooov_x = ( - np.array(eris.ovoo).transpose(2,3,0,1), - np.array(eris.OVoo).transpose(2,3,0,1), - np.array(eris.OVOO).transpose(2,3,0,1), - ) - govoo_x = ( - np.array(eris.ovoo), - np.array(eris.OVoo), - np.array(eris.OVOO), - ) + govvv_x = (np.array(ao2mo_helper.get_ovvv(eris, block="ovvv")), + np.array(ao2mo_helper.get_ovvv(eris, block="ovVV")), + np.array(ao2mo_helper.get_ovvv(eris, block="OVVV"))) + gvvov_x = (np.array(ao2mo_helper.get_ovvv(eris, block="ovvv")).transpose(2,3,0,1), + np.array(ao2mo_helper.get_ovvv(eris, block="OVvv")).transpose(2,3,0,1), + np.array(ao2mo_helper.get_ovvv(eris, block="OVVV")).transpose(2,3,0,1)) + gooov_x = (np.array(eris.ovoo).transpose(2,3,0,1), + np.array(eris.OVoo).transpose(2,3,0,1), + np.array(eris.OVOO).transpose(2,3,0,1)) + govoo_x = (np.array(eris.ovoo), + np.array(eris.ovOO), + np.array(eris.OVOO)) # delta-T1 and delta-T2 amplitudes, to be added to the CCSD amplitudes if solver.spinsym == 'restricted': From c98b0c58c48becab48ca5677f334185dc0dadf82 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Thu, 23 Mar 2023 11:59:20 +0000 Subject: [PATCH 55/66] Cleans up tests --- vayesta/tests/ewf/test_extcorr.py | 210 +++++++++++++++++++----------- 1 file changed, 135 insertions(+), 75 deletions(-) diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index 9a6662617..efbe3eb3b 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -19,22 +19,23 @@ class TestFullEC_tailor(TestCase): def setUpClass(cls): cls.fci = {} cls.mf = {} + cls.mf['lih_631g'] = testsystems.lih_631g.rhf() - cls.fci['lih_631g'] = pyscf.fci.FCI( cls.mf['lih_631g']) + cls.fci['lih_631g'] = pyscf.fci.FCI(cls.mf['lih_631g']) cls.fci['lih_631g'].threads = 1 cls.fci['lih_631g'].conv_tol = 1.0e-12 cls.fci['lih_631g'].davidson_only = True cls.fci['lih_631g'].kernel() - cls.mf['lih_ccpvdz'] = testsystems.lih_ccpvdz.rhf() - cls.fci['lih_ccpvdz'] = pyscf.fci.FCI( cls.mf['lih_ccpvdz']) + cls.fci['lih_ccpvdz'] = pyscf.fci.FCI(cls.mf['lih_ccpvdz']) cls.fci['lih_ccpvdz'].threads = 1 cls.fci['lih_ccpvdz'].conv_tol = 1.0e-12 cls.fci['lih_ccpvdz'].davidson_only = True cls.fci['lih_ccpvdz'].kernel() - def TearDownClass(cls): + @classmethod + def tearDownClass(cls): cls.fci.clear() cls.mf.clear() del cls.fci @@ -42,29 +43,31 @@ def TearDownClass(cls): def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True): - mf = getattr(getattr(testsystems, key[0]), key[1])() if fcifragtype == 'fullsystem': emb = vayesta.ewf.EWF(mf, solver_options={'conv_tol':1.0e-12} ) fci_frags = [] with emb.iao_fragmentation() as f: if store_wf_ccsdtq: - fci_frags.append(f.add_full_system(solver='FCI', bath_options=dict(bathtype=bathtype), store_wf_type='CCSDTQ', auxiliary=True)) + fci_frags.append(f.add_full_system(solver='FCI', bath_options=dict(bathtype=bathtype), + store_wf_type='CCSDTQ', auxiliary=True)) else: - fci_frags.append(f.add_full_system(solver='FCI', bath_options=dict(bathtype=bathtype), auxiliary=True)) + fci_frags.append(f.add_full_system(solver='FCI', bath_options=dict(bathtype=bathtype), + auxiliary=True)) ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full')) ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=proj,test_extcorr=True) emb.kernel() if fcifragtype == 'atomic': - emb = vayesta.ewf.EWF(mf, solver_options={'conv_tol':1.0e-12}) with emb.iao_fragmentation() as f: if store_wf_ccsdtq: - fci_frag = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype=bathtype), store_wf_type='CCSDTQ', auxiliary=True) + fci_frag = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype=bathtype), + store_wf_type='CCSDTQ', auxiliary=True) else: - fci_frag = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype=bathtype), auxiliary=True) + fci_frag = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype=bathtype), + auxiliary=True) ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full')) ccsd_frag.add_external_corrections(fci_frag, correction_type=mode, projectors=proj, test_extcorr=True) @@ -77,63 +80,75 @@ def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='exter @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988952842115175) @pytest.mark.fast def test_r_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.98893732925952) @pytest.mark.slow def test_r_regression_ec_lih_631g_atomicfrags_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988952842133734) @pytest.mark.slow def test_r_exact_ec_lih_631g_atomicfrags_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_r_regression_ec_lih_631g_atomicfrags_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.98893732924287) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj1_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) # uhf tests @@ -141,143 +156,170 @@ def test_r_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): @pytest.mark.slow def test_u_exact_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988952849629403) # A test with nostore @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_proj0_fciv_nostore(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=False) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=False) self.assertAlmostEqual(e_tot, -7.988952849629403) @pytest.mark.slow def test_u_exact_ec_lih_631g_atomicfrags_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988937336775954) @pytest.mark.fast def test_u_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_fullsystem_proj1_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.fast def test_u_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_fullsystem_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) # test tailoring @pytest.mark.fast def test_u_exact_tailor_lih_631g_fullsystem_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='tailor', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', + mode='tailor', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.fast def test_u_exact_tailor_lih_631g_fullsystem_proj0_fciv_nostore(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', mode='tailor', store_wf_ccsdtq=False) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', + mode='tailor', store_wf_ccsdtq=False) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.fast def test_u_exact_ec_lih_631g_fullsystem_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) # FCI fragment bathtype = dmet @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747139) @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747468) @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747468) @pytest.mark.slow def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.9889313937490956) @pytest.mark.slow def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393746693) @pytest.mark.slow def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.98893139374700) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393745471) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747714) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.98893139374664) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393748568) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393746042) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393748121) # uhf tests @@ -285,75 +327,87 @@ def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self) @pytest.mark.slow def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739508) # test with nostore @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_nostore(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=False) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=False) self.assertAlmostEqual(e_tot, -7.988931393739513) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.9889313937395015 ) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739511) @pytest.mark.fast def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.fast def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739515 ) @pytest.mark.fast def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.9889313937395015 ) @pytest.mark.slow def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) + e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', + mode='external-fciv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739506 ) @pytest.mark.fast class TestHubCompleteEC(TestCase): - def _test_10_u4_2imp(self, mode, proj): """Tests for N=10 U=4 Hubbard model with double site CCSD impurities and complete FCI fragment @@ -403,7 +457,6 @@ def test_hub_ec_2imp_proj2_fciv(self): @pytest.mark.fast class TestHubBathEC(TestCase): - def _test_10_u2_2impfci(self, mode): """Tests for N=10 U=2 Hubbard model with double site CCSD impurities and 2-site FCI fragment (but complete bath). With no projectors on @@ -416,7 +469,8 @@ def _test_10_u2_2impfci(self, mode): emb.opts.solver_options['conv_tol'] = 1.0e-12 with emb.site_fragmentation() as f: - fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full'), store_wf_type='CCSDTQ') + fci_frag = f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='full'), + store_wf_type='CCSDTQ') ccsd_frag = f.add_atomic_fragment([0, 1], solver='CCSD', bath_options=dict(bathtype='full'), active=False) ccsd_frag.add_tsymmetric_fragments(tvecs=[5, 1, 1]) emb.kernel() @@ -443,7 +497,6 @@ def test_hub_ec_2impfci_proj0_ccsdv(self): @pytest.mark.fast class TestECSym(TestCase): - def _test_10_u2_eccc_sym(self, mode, proj=0): """Test symmetry in external correction via comparison to system without use of symmetry """ @@ -456,11 +509,16 @@ def _test_10_u2_eccc_sym(self, mode, proj=0): fci_frags = [] with emb.site_fragmentation() as f: # Set up a two-site FCI fragment on all symmetrically equivalent fragments - fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ')) - fci_frags.append(f.add_atomic_fragment([2, 3], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ')) - fci_frags.append(f.add_atomic_fragment([4, 5], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ')) - fci_frags.append(f.add_atomic_fragment([6, 7], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ')) - fci_frags.append(f.add_atomic_fragment([8, 9], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ')) + fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), + store_wf_type='CCSDTQ')) + fci_frags.append(f.add_atomic_fragment([2, 3], solver='FCI', bath_options=dict(bathtype='dmet'), + store_wf_type='CCSDTQ')) + fci_frags.append(f.add_atomic_fragment([4, 5], solver='FCI', bath_options=dict(bathtype='dmet'), + store_wf_type='CCSDTQ')) + fci_frags.append(f.add_atomic_fragment([6, 7], solver='FCI', bath_options=dict(bathtype='dmet'), + store_wf_type='CCSDTQ')) + fci_frags.append(f.add_atomic_fragment([8, 9], solver='FCI', bath_options=dict(bathtype='dmet'), + store_wf_type='CCSDTQ')) ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), active=False) emb.kernel() @@ -479,7 +537,8 @@ def _test_10_u2_eccc_sym(self, mode, proj=0): fci_frags = [] with emb.site_fragmentation() as f: - fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ')) + fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), + store_wf_type='CCSDTQ')) ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), active=False) # Add the symmetry-derived FCI fragments @@ -514,7 +573,6 @@ def test_hub_ec_sym_proj1_tailor(self): @pytest.mark.fast class TestRegEC_CCSD(TestCase): - def _test_water_ec_regression(self, mode=None, projectors=None): mf = testsystems.water_ccpvdz_df.rhf() @@ -524,7 +582,8 @@ def _test_water_ec_regression(self, mode=None, projectors=None): fci_frags = [] with emb.iao_fragmentation() as f: - fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ') + fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), + store_wf_type='CCSDTQ') ccsd_frags = f.add_all_atomic_fragments(solver='CCSD', bath_options=dict(bathtype='full'), active=False) emb.kernel() @@ -533,7 +592,8 @@ def _test_water_ec_regression(self, mode=None, projectors=None): for ccsd_frag in ccsd_frags: ccsd_frag.active = True - ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors, test_extcorr=True) + ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors, + test_extcorr=True) emb.kernel() return emb.e_tot From c1bca3597923f16d9804f2d79fd9e9fc37257658 Mon Sep 17 00:00:00 2001 From: Charles Scott Date: Fri, 24 Mar 2023 15:09:23 +0000 Subject: [PATCH 56/66] Fixed bug with single-site embedding in AFM systems. --- vayesta/core/types/wf/fci.py | 9 +++++++++ vayesta/solver/fci.py | 16 +++++++++------- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/vayesta/core/types/wf/fci.py b/vayesta/core/types/wf/fci.py index 074bf0a8e..f39207044 100644 --- a/vayesta/core/types/wf/fci.py +++ b/vayesta/core/types/wf/fci.py @@ -69,6 +69,10 @@ def as_cisd(self, c0=None): raise NotImplementedError norb, nocc, nvir = self.norb, self.nocc, self.nvir t1addr, t1sign = pyscf.ci.cisd.t1strs(norb, nocc) + + # Change to arrays, in case of empty slice + t1addr = np.asarray(t1addr, dtype=int) + c1 = self.ci[0,t1addr] * t1sign c2 = einsum('i,j,ij->ij', t1sign, t1sign, self.ci[t1addr[:,None],t1addr]) c1 = c1.reshape(nocc,nvir) @@ -221,6 +225,11 @@ def as_cisd(self, c0=None): t1addrb, t1signb = pyscf.ci.cisd.tn_addrs_signs(norbb, noccb, 1) t2addra, t2signa = pyscf.ci.cisd.tn_addrs_signs(norba, nocca, 2) t2addrb, t2signb = pyscf.ci.cisd.tn_addrs_signs(norbb, noccb, 2) + + # Change to arrays, in case of empty slice + t1addra = np.asarray(t1addra, dtype=int) + t1addrb = np.asarray(t1addrb, dtype=int) + na = pyscf.fci.cistring.num_strings(norba, nocca) nb = pyscf.fci.cistring.num_strings(norbb, noccb) diff --git a/vayesta/solver/fci.py b/vayesta/solver/fci.py index a5af0c229..4f33482de 100644 --- a/vayesta/solver/fci.py +++ b/vayesta/solver/fci.py @@ -174,16 +174,13 @@ def kernel(self, ci0=None, eris=None, seris_ov=None): mo = Orbitals(self.cluster.c_active, occ=self.cluster.nocc_active) self.wf = FCI_WaveFunction(mo, self.civec) - #def get_cisd_amps(self, civec): - # cisdvec = pyscf.ci.cisd.from_fcivec(civec, self.ncas, self.nelec) - # c0, c1, c2 = pyscf.ci.cisd.cisdvec_to_amplitudes(cisdvec, self.ncas, self.cluster.nocc_active) - # c1 = c1/c0 - # c2 = c2/c0 - # return c0, c1, c2 - def get_cisd_amps(self, civec, intermed_norm=False): nocc, nvir = self.cluster.nocc_active, self.cluster.nvir_active t1addr, t1sign = pyscf.ci.cisd.t1strs(self.ncas, nocc) + + # Change to arrays, in case of empty slice + t1addr = np.asarray(t1addr, dtype=int) + c0 = civec[0,0] c1 = civec[0,t1addr] * t1sign c2 = einsum('i,j,ij->ij', t1sign, t1sign, civec[t1addr[:,None],t1addr]) @@ -270,6 +267,11 @@ def get_cisd_amps(self, civec, intermed_norm=False): t1addrb, t1signb = pyscf.ci.cisd.tn_addrs_signs(norbb, noccb, 1) t2addra, t2signa = pyscf.ci.cisd.tn_addrs_signs(norba, nocca, 2) t2addrb, t2signb = pyscf.ci.cisd.tn_addrs_signs(norbb, noccb, 2) + + # Change to arrays, in case of empty slice + t1addra = np.asarray(t1addra, dtype=int) + t1addrb = np.asarray(t1addrb, dtype=int) + na = pyscf.fci.cistring.num_strings(norba, nocca) nb = pyscf.fci.cistring.num_strings(norbb, noccb) From b0e860d4d144171bb23e39aa590f462bdb7bbc53 Mon Sep 17 00:00:00 2001 From: Charles Scott Date: Fri, 24 Mar 2023 15:54:58 +0000 Subject: [PATCH 57/66] Added test for dissociated H2 with symmetry broken, reference, as well as mechanism to obtain stability-analysis-verified UHF solutions for tests. --- vayesta/tests/ewf/test_h2.py | 24 ++++++++++++++++++++++++ vayesta/tests/testsystems.py | 20 ++++++++++++++++++++ 2 files changed, 44 insertions(+) diff --git a/vayesta/tests/ewf/test_h2.py b/vayesta/tests/ewf/test_h2.py index e62ab29ba..1329f55ad 100644 --- a/vayesta/tests/ewf/test_h2.py +++ b/vayesta/tests/ewf/test_h2.py @@ -163,6 +163,30 @@ def setUpClass(cls): cls.mf = testsystems.h2anion_dz.uhf() cls.fci = testsystems.h2anion_dz.ufci() +class Test_UFCI_dissoc(TestCase): + + @classmethod + def setUpClass(cls): + cls.mf = testsystems.h2_sto3g_dissoc_df.uhf_stable() + cls.fci = testsystems.h2_sto3g_dissoc_df.ufci() + + @classmethod + def tearDownClass(cls): + del cls.mf + del cls.fci + cls.emb.cache_clear() + + @classmethod + @cache + def emb(cls, bno_threshold): + emb = vayesta.ewf.EWF(cls.mf, bath_options=dict(bathtype="dmet"), solver='FCI') + emb.kernel() + return emb + + def test_energy(self): + emb = self.emb(-1) + self.assertAllclose(emb.e_tot, self.fci.e_tot, rtol=0) + if __name__ == '__main__': print('Running %s' % __file__) diff --git a/vayesta/tests/testsystems.py b/vayesta/tests/testsystems.py index 55dcf00f5..21d4eb0b6 100644 --- a/vayesta/tests/testsystems.py +++ b/vayesta/tests/testsystems.py @@ -4,6 +4,7 @@ from functools import lru_cache cache = lru_cache(maxsize=None) import numpy as np +import copy import pyscf # Open boundary @@ -71,6 +72,24 @@ def uhf(self): assert uhf.converged return uhf + @cache + def uhf_stable(self): + # Get uhf solution, and copy to avoid changing attributes. + uhf = copy.copy(self.uhf()) + # Repeat this procedure a few times; it should converge pretty rapidly, but we don't want to get stuck in an + # infinite loop if it doesn't. + for i in range(5): + # Check stability of current solution. + int_c, ext_c, int_stab, ext_stab = uhf.stability(return_status=True) + # If we have a converged solution which is stable return. + if int_stab and uhf.converged: + return uhf + # Run new calculation starting from result of stability analysis. + uhf.kernel(dm0=uhf.make_rdm1(mo_coeff=int_c)) + else: + # Don't want to get stuck in an infinite loop. + raise RuntimeError("Could not obtain converged, stable UHF solution.") + # --- MP2 @cache @@ -315,6 +334,7 @@ def uhf(self): h2_dz = TestMolecule("H 0 0 0; H 0 0 0.74", basis="cc-pvdz") h2anion_dz = TestMolecule("H 0 0 0; H 0 0 0.74", basis="cc-pvdz", charge=-1, spin=1) +h2_sto3g_dissoc_df = TestMolecule("H 0 0 0; H 0 0 10.0", basis="sto3g", auxbasis=True) h6_sto6g = TestMolecule( atom=["H %f %f %f" % xyz for xyz in pyscf.tools.ring.make(6, 1.0)], From 4806b242caf895116871aa981135b5b399f4690c Mon Sep 17 00:00:00 2001 From: Abhishek Khedkar Date: Mon, 27 Mar 2023 13:37:13 +0100 Subject: [PATCH 58/66] fixed UHF external-ccsdv regression tests --- vayesta/tests/ewf/test_extcorr.py | 36 +++++++++++++++---------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index efbe3eb3b..833b99610 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -155,10 +155,10 @@ def test_r_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): @pytest.mark.slow - def test_u_exact_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): + def test_u_regression_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) + self.assertAlmostEqual(e_tot, -7.988952842052377) @pytest.mark.slow def test_u_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): @@ -167,10 +167,10 @@ def test_u_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow - def test_u_exact_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): + def test_u_regression_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) + self.assertAlmostEqual(e_tot, -7.988937329208046) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_proj0_fciv_store(self): @@ -326,22 +326,22 @@ def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self) @pytest.mark.slow - def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): + def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) + self.assertAlmostEqual(e_tot, -7.988931393739508) @pytest.mark.slow - def test_u_exact_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): + def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) + self.assertAlmostEqual(e_tot, -7.988931393739508) @pytest.mark.slow - def test_u_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): + def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) + self.assertAlmostEqual(e_tot, -7.988931393739506) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_store(self): @@ -370,34 +370,34 @@ def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_fciv_store(self @pytest.mark.fast - def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): + def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) + self.assertAlmostEqual(e_tot, -7.988931393739505) @pytest.mark.slow - def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): + def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) + self.assertAlmostEqual(e_tot, -7.9889313937395094) @pytest.mark.fast - def test_u_exact_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): + def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) + self.assertAlmostEqual(e_tot, -7.988931393739503) @pytest.mark.slow def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_fciv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393739515 ) + self.assertAlmostEqual(e_tot, -7.988931393739515) @pytest.mark.fast def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_fciv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.9889313937395015 ) + self.assertAlmostEqual(e_tot, -7.9889313937395015) @pytest.mark.slow def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self): From 6c04deec90032c4d484e2de028a7efb8eeeb5899 Mon Sep 17 00:00:00 2001 From: Abhishek Khedkar Date: Mon, 3 Apr 2023 10:26:31 +0100 Subject: [PATCH 59/66] Removed many redundant tests, external-fciv tests --- vayesta/tests/ewf/test_extcorr.py | 204 +----------------------------- 1 file changed, 3 insertions(+), 201 deletions(-) diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index 833b99610..d4960ee2d 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -78,11 +78,6 @@ def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='exter # FCI fragment bath type=full - @pytest.mark.fast - def test_r_regression_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988952842115175) @pytest.mark.fast def test_r_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): @@ -96,25 +91,6 @@ def test_r_regression_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.98893732925952) - @pytest.mark.slow - def test_r_regression_ec_lih_631g_atomicfrags_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988952842133734) - - @pytest.mark.slow - def test_r_exact_ec_lih_631g_atomicfrags_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - - @pytest.mark.slow - def test_r_regression_ec_lih_631g_atomicfrags_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.98893732924287) - - @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', @@ -133,32 +109,8 @@ def test_r_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) - @pytest.mark.slow - def test_r_exact_ec_lih_631g_fullsystem_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - @pytest.mark.slow - def test_r_exact_ec_lih_631g_fullsystem_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - - @pytest.mark.slow - def test_r_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - -# uhf tests - - - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988952842052377) + # uhf tests @pytest.mark.slow def test_u_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): @@ -172,32 +124,6 @@ def test_u_regression_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988937329208046) - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988952849629403) - -# A test with nostore - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_proj0_fciv_nostore(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=False) - self.assertAlmostEqual(e_tot, -7.988952849629403) - - @pytest.mark.slow - def test_u_exact_ec_lih_631g_atomicfrags_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988937336775954) - - @pytest.mark.fast def test_u_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', @@ -216,44 +142,8 @@ def test_u_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) - @pytest.mark.slow - def test_u_exact_ec_lih_631g_fullsystem_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - -# test tailoring - @pytest.mark.fast - def test_u_exact_tailor_lih_631g_fullsystem_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', - mode='tailor', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - - @pytest.mark.fast - def test_u_exact_tailor_lih_631g_fullsystem_proj0_fciv_nostore(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', - mode='tailor', store_wf_ccsdtq=False) - self.assertAlmostEqual(e_tot, fci_e_tot) - - @pytest.mark.fast - def test_u_exact_ec_lih_631g_fullsystem_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - - @pytest.mark.slow - def test_u_exact_ec_lih_631g_fullsystem_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, fci_e_tot) - - # FCI fragment bathtype = dmet + # FCI fragment bathtype = dmet - @pytest.mark.fast - def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393747139) @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): @@ -267,25 +157,6 @@ def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(sel mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747468) - @pytest.mark.slow - def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.9889313937490956) - - @pytest.mark.slow - def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393746693) - - @pytest.mark.slow - def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.98893139374700) - - @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', @@ -304,32 +175,7 @@ def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.98893139374664) - @pytest.mark.slow - def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393748568) - - @pytest.mark.slow - def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393746042) - - @pytest.mark.slow - def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393748121) - - # uhf tests - - - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_ccsdv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393739508) + # uhf tests @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): @@ -343,31 +189,6 @@ def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(sel mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739506) - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393739508) - - # test with nostore - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj0_fciv_nostore(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=False) - self.assertAlmostEqual(e_tot, -7.988931393739513) - - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.9889313937395015 ) - - @pytest.mark.slow - def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393739511) - @pytest.mark.fast def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): @@ -387,25 +208,6 @@ def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self mode='external-ccsdv', store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739503) - @pytest.mark.slow - def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393739515) - - @pytest.mark.fast - def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.9889313937395015) - - @pytest.mark.slow - def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_fciv_store(self): - e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-fciv', store_wf_ccsdtq=True) - self.assertAlmostEqual(e_tot, -7.988931393739506 ) - - @pytest.mark.fast class TestHubCompleteEC(TestCase): def _test_10_u4_2imp(self, mode, proj): From 859b6bf7bcb6b72af0cd31876475ce1f25400536 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Wed, 5 Apr 2023 09:35:06 +0100 Subject: [PATCH 60/66] Trigger CI build --- .github/workflows/ci.yaml | 1 - 1 file changed, 1 deletion(-) diff --git a/.github/workflows/ci.yaml b/.github/workflows/ci.yaml index a460a004d..ff6d71f18 100644 --- a/.github/workflows/ci.yaml +++ b/.github/workflows/ci.yaml @@ -4,7 +4,6 @@ on: push: branches: [master, dev] pull_request: - branches: [master, dev] schedule: - cron: '0 2 * * *' From f02001c886c1446146c7a807a6e90f2ef0a0b681 Mon Sep 17 00:00:00 2001 From: Ollie Backhouse Date: Wed, 5 Apr 2023 09:55:22 +0100 Subject: [PATCH 61/66] Address Max's comments --- examples/ewf/other/61-ext-corr-hubbard-1D.py | 5 ++--- vayesta/core/types/wf/t_to_c.py | 5 +++++ vayesta/solver/coupling.py | 7 ++++--- 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/examples/ewf/other/61-ext-corr-hubbard-1D.py b/examples/ewf/other/61-ext-corr-hubbard-1D.py index 7b7d47024..d7b9a694f 100644 --- a/examples/ewf/other/61-ext-corr-hubbard-1D.py +++ b/examples/ewf/other/61-ext-corr-hubbard-1D.py @@ -37,9 +37,8 @@ fci_frags.append(f.add_atomic_fragment([0, 1], solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', nelectron_target=2*nelectron/nsite, auxiliary=True)) # Add single 'complete' CCSD fragment covering all sites ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full'), solver_options=dict(solve_lambda=False, init_guess='CISD')) -for fci_sym_frag in fci_frags[0].add_tsymmetric_fragments(tvecs=[5, 1, 1]): - # Add symmetry-derived FCI fragments to avoid multiple calculations - fci_frags.append(fci_sym_frag) +# Add symmetry-derived FCI fragments to avoid multiple calculations +fci_frags.extend(fci_frags[0].add_tsymmetric_fragments(tvecs=[5, 1, 1]) e_extcorr = [] extcorr_conv = [] diff --git a/vayesta/core/types/wf/t_to_c.py b/vayesta/core/types/wf/t_to_c.py index 6f5f09391..b412a1d0a 100644 --- a/vayesta/core/types/wf/t_to_c.py +++ b/vayesta/core/types/wf/t_to_c.py @@ -1,3 +1,8 @@ +""" +These expressions were obtained from https://doi.org/10.1063/1.4996044 for +GHF, and then spin integrated to RHF and UHF expressions. +""" + import numpy as np from vayesta.core.util import einsum diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 5fe9026da..aec137afa 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -560,8 +560,6 @@ def externally_correct(solver, external_corrections, eris=None): cx_vir = cluster.c_active_vir # Virtual active orbitals of current cluster cxs_occ = spinalg.dot(spinalg.T(cx_occ), ovlp) cxs_vir = spinalg.dot(spinalg.T(cx_vir), ovlp) - # CCSD uses exxdiv-uncorrected Fock matrix for residuals - fock = emb.get_fock(with_exxdiv=False) if eris is None: # Note that if no MO energies are passed in, we construct them from the # get_fock function without with_exxdiv=False. For PBC CCSD, this may be different @@ -578,6 +576,9 @@ def externally_correct(solver, external_corrections, eris=None): solver.log.warn("This will likely lead to double-counting of external correction.") solver.log.warn("Are you sure you want to do this?!") + # CCSD uses exxdiv-uncorrected Fock matrix for residuals + fock = emb.get_fock(with_exxdiv=False) + if any([corr[1] == 'external-ccsdv' for corr in external_corrections]): # At least one fragment is externally corrected, *and* contracted with # integrals in the parent cluster. We can take the integrals from eris @@ -669,7 +670,7 @@ def externally_correct(solver, external_corrections, eris=None): dt1 /= eia dt2 /= eijab - solver.log.info("Total external correction amplitudes from all fragments: dT1= %.3e dT2= %.3e", \ + solver.log.info("Total external correction amplitudes from all fragments: dT1= %.3e dT2= %.3e", *get_amplitude_norm(dt1, dt2)) def callback(kwargs): From 7fe0cdfb5970cde06376a7901609b546ebab627f Mon Sep 17 00:00:00 2001 From: Charles Scott Date: Fri, 14 Apr 2023 15:28:50 +0100 Subject: [PATCH 62/66] Moved to not using density fitting for dissociated UHF test. Also ensured TestMolecule.uhf_stable uses symmetry-broken reference. --- vayesta/tests/ewf/test_h2.py | 5 +++-- vayesta/tests/testsystems.py | 9 +++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/vayesta/tests/ewf/test_h2.py b/vayesta/tests/ewf/test_h2.py index 1329f55ad..431d2c919 100644 --- a/vayesta/tests/ewf/test_h2.py +++ b/vayesta/tests/ewf/test_h2.py @@ -167,8 +167,9 @@ class Test_UFCI_dissoc(TestCase): @classmethod def setUpClass(cls): - cls.mf = testsystems.h2_sto3g_dissoc_df.uhf_stable() - cls.fci = testsystems.h2_sto3g_dissoc_df.ufci() + # TODO ensure this tests works if density fitting is used. + cls.mf = testsystems.h2_sto3g_dissoc.uhf_stable() + cls.fci = testsystems.h2_sto3g_dissoc.ufci() @classmethod def tearDownClass(cls): diff --git a/vayesta/tests/testsystems.py b/vayesta/tests/testsystems.py index 21d4eb0b6..9955d3808 100644 --- a/vayesta/tests/testsystems.py +++ b/vayesta/tests/testsystems.py @@ -76,7 +76,12 @@ def uhf(self): def uhf_stable(self): # Get uhf solution, and copy to avoid changing attributes. uhf = copy.copy(self.uhf()) - # Repeat this procedure a few times; it should converge pretty rapidly, but we don't want to get stuck in an + # Follow procedure from pyscf/examples/scf/32-break_spin_symm.py to ensure symmetry breaking in initial guess. + # Use standard calculation as initial guess. + dm0 = uhf.make_rdm1() + uhf.kernel(dm0=(dm0[0], np.zeros_like(dm0[1]))) + + # Repeat this procedure a few times; it should converge rapidly, but we don't want to get stuck in an # infinite loop if it doesn't. for i in range(5): # Check stability of current solution. @@ -334,7 +339,7 @@ def uhf(self): h2_dz = TestMolecule("H 0 0 0; H 0 0 0.74", basis="cc-pvdz") h2anion_dz = TestMolecule("H 0 0 0; H 0 0 0.74", basis="cc-pvdz", charge=-1, spin=1) -h2_sto3g_dissoc_df = TestMolecule("H 0 0 0; H 0 0 10.0", basis="sto3g", auxbasis=True) +h2_sto3g_dissoc = TestMolecule("H 0 0 0; H 0 0 10.0", basis="sto3g") h6_sto6g = TestMolecule( atom=["H %f %f %f" % xyz for xyz in pyscf.tools.ring.make(6, 1.0)], From 07f2773b1dafe23da5172772571de615752527d4 Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 14 Apr 2023 15:59:25 +0100 Subject: [PATCH 63/66] Remove separate options 'external-ccsdv' and 'external-fciv'. Now, there is just an 'external' keyword for the external correction. Instead, whether the interaction in the T3 * V term is contracted with V in the high-level (i.e. FCI) 'smaller' space, or the low-level (i.e. CCSD) 'larger' space, is controlled via an optional argument to the 'externally_correct' function. This argument is 'low_level_coul', and defaults to 'True'. This means that the default behaviour is equivalent to the 'external-ccsdv' correction previously. Tests and examples updated. --- .../ewf/molecules/25-externally-correct.py | 22 ++-- vayesta/ewf/fragment.py | 17 ++- vayesta/solver/ccsd.py | 2 +- vayesta/solver/coupling.py | 28 ++--- vayesta/tests/ewf/test_extcorr.py | 100 +++++++++--------- 5 files changed, 89 insertions(+), 80 deletions(-) diff --git a/examples/ewf/molecules/25-externally-correct.py b/examples/ewf/molecules/25-externally-correct.py index a27115e60..c909f0542 100644 --- a/examples/ewf/molecules/25-externally-correct.py +++ b/examples/ewf/molecules/25-externally-correct.py @@ -37,15 +37,15 @@ # Add single 'complete' CCSD fragment covering all IAOs ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full')) # Setup the external correction from the CCSD fragment. -# Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the -# T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is -# larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). -# The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). -# The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less -# 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. -# For multiple constraining fragments, proj=0 will double-count the correction due to overlapping bath spaces, and -# in this case, only proj=1 will be exact in the limit of enlarging (FCI) bath spaces. -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) +# Main option is 'projectors', which should be an integer between 0 and 2 (inclusive). +# The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less +# 'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. +# For multiple constraining fragments, proj=0 will double-count the correction due to overlapping bath spaces, and +# in this case, only proj=1 will be exact in the limit of enlarging (FCI) bath spaces. +# Note that there is also the option 'low_level_coul' (default True). For the important T3 * V contribution to the +# T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is +# larger, and hence this is likely to be better (and is default), as the correction is longer-ranged (though slightly more expensive). +ccsd_frag.add_external_corrections(fci_frags, correction_type='external', projectors=1) emb.kernel() print('Total energy from full system CCSD tailored (CCSD Coulomb interaction) by atomic FCI fragments (projectors=1): {}'.format(emb.e_tot)) @@ -55,8 +55,8 @@ with emb.iao_fragmentation() as f: fci_frags = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype='dmet'), store_wf_type='CCSDTQ', auxiliary=True) ccsd_frags = f.add_all_atomic_fragments(solver='CCSD', bath_options=dict(bathtype='mp2', threshold=1.e-5)) -# Now add external corrections to all CCSD clusters, and use 'external-fciv' correction, with 2 projectors +# Now add external corrections to all CCSD clusters, and use 'external' correction, with 2 projectors and only contracting with the FCI integrals for cc_frag in ccsd_frags: - cc_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=2) + cc_frag.add_external_corrections(fci_frags, correction_type='external', projectors=2, low_level_coul=False) emb.kernel() print('Total energy from embedded CCSD tailored (FCI Coulomb interaction) by atomic FCI fragments (projectors=2): {}'.format(emb.e_tot)) diff --git a/vayesta/ewf/fragment.py b/vayesta/ewf/fragment.py index 331f6e923..43546881e 100644 --- a/vayesta/ewf/fragment.py +++ b/vayesta/ewf/fragment.py @@ -134,7 +134,7 @@ def set_cas(self, iaos=None, c_occ=None, c_vir=None, minao='auto', dmet_threshol def tailor_with_fragments(self, fragments, projectors=1): return self.add_external_corrections(fragments, projectors=projectors) - def add_external_corrections(self, fragments, correction_type='tailor', projectors=1, test_extcorr=False): + def add_external_corrections(self, fragments, correction_type='tailor', projectors=1, test_extcorr=False, low_level_coul=True): """Add tailoring or external correction from other fragment solutions to CCSD solver. Parameters @@ -146,23 +146,30 @@ def add_external_corrections(self, fragments, correction_type='tailor', projecto 'tailor': replace CCSD T1 and T2 amplitudes with FCI amplitudes. 'delta-tailor': Add the difference of FCI and CCSD T1 and T2 amplitudes 'external': externally correct CCSD T1 and T2 amplitudes from FCI T3 and T4 amplitudes. - 'external-fciv': externally correct CCSD T1 and T2 amplitudes from FCI T3 and T4 amplitudes (note T3V term contracted with integrals from the cluster providing the constraints). 'external' is the same as this. - 'external-ccsdv': externally correct CCSD T1 and T2 amplitudes from FCI T3 and T4 amplitudes (note T3V term contracted with integrals from the cluster being constrained). Should be more accurate? Default: 'tailor'. projectors: int, optional Maximum number of projections applied to the occupied dimensions of the amplitude corrections. Default: 1. test_extcorr: bool, optional Whether to perform additional checks on the external corrections. + low_level_coul: bool, optional + This is an option specific to the 'external' correction. + If True, then the T3V term is contracted with integrals spanning the 'low-level' (i.e. CCSD) solver, i.e. the cluster being constrained. + If False, then the T3V term is contracted with the integrals in the 'high-level' (i.e. FCI) solver, i.e. the cluster providing the constraints. + In general, there should be a slight speed increase, and slight loss of accuracy for the low_level_coul=False option, but in practice, we find only + minor differences. + Default: True """ - if correction_type not in ('tailor', 'delta-tailor', 'external', 'external-fciv', 'external-ccsdv'): + if correction_type not in ('tailor', 'delta-tailor', 'external'): raise ValueError if self.solver != 'CCSD': raise RuntimeError + if (not low_level_coul) and correction_type != 'external': + raise ValueError("low_level_coul optional argument only meaningful with 'external' correction of fragments.") if np.any([(getattr_recursive(f, 'results.wf', None) is None and not f.opts.auxiliary) for f in fragments]): raise ValueError("Fragments for external correction need to be already solved or defined as auxiliary fragments.") self.flags.external_corrections.extend( - [(f.id, correction_type, projectors) for f in fragments]) + [(f.id, correction_type, projectors, low_level_coul) for f in fragments]) self.flags.test_extcorr = test_extcorr def clear_external_corrections(self): diff --git a/vayesta/solver/ccsd.py b/vayesta/solver/ccsd.py index 9b9713811..78a580be9 100644 --- a/vayesta/solver/ccsd.py +++ b/vayesta/solver/ccsd.py @@ -165,7 +165,7 @@ def kernel(self, t1=None, t2=None, eris=None, l1=None, l2=None, seris_ov=None, c elif self.opts.external_corrections: # Tailoring of T1 and T2 tailors = [ec for ec in self.opts.external_corrections if (ec[1] == 'tailor')] - externals = [ec for ec in self.opts.external_corrections if (ec[1] in ('external', 'delta-tailor', 'external-fciv', 'external-ccsdv'))] + externals = [ec for ec in self.opts.external_corrections if (ec[1] in ('external', 'delta-tailor'))] if tailors and externals: raise NotImplementedError if tailors: diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index aec137afa..68e5e7419 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -534,12 +534,13 @@ def externally_correct(solver, external_corrections, eris=None): ---------- solver : CCSD_Solver Vayesta CCSD solver. - external_corrections : list of tuple of (int, str, int) + external_corrections : list of tuple of (int, str, int, bool) List of external corrections. Each tuple contains the fragment ID, type of correction, - and number of projectors for the given external correction. + and number of projectors for the given external correction. Final element is boolean giving + the low_level_coul optional argument. eris : _ChemistsERIs ERIs for parent CCSD fragment. Used for MO energies in residual contraction, and for - type of correction == 'external-ccsdv', where the parent Coulomb integral is contracted. + the case of low_level_coul, where the parent Coulomb integral is contracted. If not passed in, MO energy if needed will be constructed from the diagonal of get_fock() of embedding base class, and the eris will be also be obtained from the embedding base class. Optional. @@ -579,9 +580,9 @@ def externally_correct(solver, external_corrections, eris=None): # CCSD uses exxdiv-uncorrected Fock matrix for residuals fock = emb.get_fock(with_exxdiv=False) - if any([corr[1] == 'external-ccsdv' for corr in external_corrections]): + if any([corr[3] and corr[1] == 'external' for corr in external_corrections]): # At least one fragment is externally corrected, *and* contracted with - # integrals in the parent cluster. We can take the integrals from eris + # integrals in the parent (i.e. CCSD) cluster. We can take the integrals from eris # if passed in. Otherwise, form the required integrals # for this parent cluster. Note that not all of these are needed. if eris is None: @@ -618,15 +619,16 @@ def externally_correct(solver, external_corrections, eris=None): np.zeros((nocc[1], nocc[1], nvir[1], nvir[1]))) frag_dir = {f.id: f for f in emb.fragments} - for y, corrtype, projectors in external_corrections: + for y, corrtype, projectors, low_level_coul in external_corrections: fy = frag_dir[y] # Get fragment y object from its index assert (y != fx.id) - if corrtype in ['external', 'external-fciv']: - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=True) - elif corrtype == 'external-ccsdv': - dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=False) + if corrtype == 'external': + if low_level_coul: + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=False) + else: + dt1y, dt2y = _get_delta_t_for_extcorr(fy, fock, solver, include_t3v=True) elif corrtype == 'delta-tailor': dt1y, dt2y = _get_delta_t_for_delta_tailor(fy, fock) else: @@ -649,7 +651,7 @@ def externally_correct(solver, external_corrections, eris=None): dt1 = spinalg.add(dt1, dt1y) dt2 = spinalg.add(dt2, dt2y) - if corrtype == 'external-ccsdv': + if low_level_coul: # Include the t3v term, contracting with the integrals from the x cluster # These have already been fragment projected, and rotated into the x cluster # in this function. @@ -662,7 +664,7 @@ def externally_correct(solver, external_corrections, eris=None): if solver.spinsym == 'restricted': - if corrtype in ['external', 'external-fciv', 'external-ccsdv']: + if corrtype == 'external': # Contract with fragment x (CCSD) energy denominators # Note that this will not work correctly if a level shift used eia = mo_energy[:nocc, None] - mo_energy[None, nocc:] @@ -681,7 +683,7 @@ def callback(kwargs): elif solver.spinsym == 'unrestricted': - if corrtype in ["external", "external-fciv", "external-ccsdv"]: + if corrtype == "external": eia_a = mo_energy[0][:nocc[0], None] - mo_energy[0][None, nocc[0]:] eia_b = mo_energy[1][:nocc[1], None] - mo_energy[1][None, nocc[1]:] eijab_aa = pyscf.lib.direct_sum('ia,jb->ijab', eia_a, eia_a) diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index d4960ee2d..7240553d2 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -42,7 +42,7 @@ def tearDownClass(cls): del cls.mf - def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='external-fciv', store_wf_ccsdtq=True): + def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='external', low_level_coul=False, store_wf_ccsdtq=True): mf = getattr(getattr(testsystems, key[0]), key[1])() if fcifragtype == 'fullsystem': emb = vayesta.ewf.EWF(mf, solver_options={'conv_tol':1.0e-12} ) @@ -55,7 +55,7 @@ def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='exter fci_frags.append(f.add_full_system(solver='FCI', bath_options=dict(bathtype=bathtype), auxiliary=True)) ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full')) - ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=proj,test_extcorr=True) + ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=proj, low_level_coul=low_level_coul, test_extcorr=True) emb.kernel() @@ -69,7 +69,7 @@ def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='exter fci_frag = f.add_all_atomic_fragments(solver='FCI', bath_options=dict(bathtype=bathtype), auxiliary=True) ccsd_frag = f.add_full_system(solver='CCSD', bath_options=dict(bathtype='full')) - ccsd_frag.add_external_corrections(fci_frag, correction_type=mode, projectors=proj, test_extcorr=True) + ccsd_frag.add_external_corrections(fci_frag, correction_type=mode, projectors=proj, low_level_coul=low_level_coul, test_extcorr=True) emb.kernel() @@ -82,31 +82,31 @@ def _test(cls, key, proj=0, bathtype='full', fcifragtype = 'atomic', mode='exter @pytest.mark.fast def test_r_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.98893732925952) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_r_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @@ -115,31 +115,31 @@ def test_r_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): @pytest.mark.slow def test_u_exact_ec_lih_631g_atomicfrags_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988937329208046) @pytest.mark.fast def test_u_exact_ec_lih_631g_fullsystem_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='full', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.slow def test_u_exact_ec_lih_631g_fullsystem_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='full', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) @pytest.mark.fast def test_u_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='full', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, fci_e_tot) # FCI fragment bathtype = dmet @@ -148,31 +148,31 @@ def test_u_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747468) @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747468) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393745471) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747714) @pytest.mark.slow def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.98893139374664) # uhf tests @@ -180,32 +180,32 @@ def test_r_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739508) @pytest.mark.slow def test_u_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'atomic', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739506) @pytest.mark.fast def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj0_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=0, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739505) @pytest.mark.slow def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=1, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.9889313937395094) @pytest.mark.fast def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'uhf'), proj=2, bathtype='dmet', fcifragtype = 'fullsystem', - mode='external-ccsdv', store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393739503) @pytest.mark.fast @@ -245,21 +245,21 @@ def _test_10_u4_2imp(self, mode, proj): self.assertAlmostEqual(emb.e_tot, fci_frag_etot) def test_hub_ec_2imp_proj0_ccsdv(self): - return self._test_10_u4_2imp(mode='external-ccsdv', proj=0) + return self._test_10_u4_2imp(mode='external', low_level_coul=True, proj=0) def test_hub_ec_2imp_proj1_ccsdv(self): - return self._test_10_u4_2imp(mode='external-ccsdv', proj=1) + return self._test_10_u4_2imp(mode='external', low_level_coul=True, proj=1) def test_hub_ec_2imp_proj2_ccsdv(self): - return self._test_10_u4_2imp(mode='external-ccsdv', proj=2) + return self._test_10_u4_2imp(mode='external', low_level_coul=True, proj=2) def test_hub_ec_2imp_proj0_fciv(self): - return self._test_10_u4_2imp(mode='external-fciv', proj=0) + return self._test_10_u4_2imp(mode='external', low_level_coul=False, proj=0) def test_hub_ec_2imp_proj1_fciv(self): - return self._test_10_u4_2imp(mode='external-fciv', proj=1) + return self._test_10_u4_2imp(mode='external', low_level_coul=False, proj=1) def test_hub_ec_2imp_proj2_fciv(self): - return self._test_10_u4_2imp(mode='external-fciv', proj=2) + return self._test_10_u4_2imp(mode='external', low_level_coul=False, proj=2) @pytest.mark.fast class TestHubBathEC(TestCase): - def _test_10_u2_2impfci(self, mode): + def _test_10_u2_2impfci(self, mode, low_level_coul=True): """Tests for N=10 U=2 Hubbard model with double site CCSD impurities and 2-site FCI fragment (but complete bath). With no projectors on external correction, should still be exact. @@ -280,7 +280,7 @@ def _test_10_u2_2impfci(self, mode): fci_frag.active = False ccsd_frag.active = True # Given the complete bath of the FCI fragment, should still be exact - ccsd_frag.add_external_corrections([fci_frag], correction_type=mode, projectors=0, test_extcorr=True) + ccsd_frag.add_external_corrections([fci_frag], correction_type=mode, projectors=0, low_level_coul=low_level_coul, test_extcorr=True) emb.kernel() fci = pyscf.fci.FCI(mf) @@ -293,13 +293,13 @@ def _test_10_u2_2impfci(self, mode): self.assertAlmostEqual(emb.e_tot, fci.e_tot) def test_hub_ec_2impfci_proj0_fciv(self): - return self._test_10_u2_2impfci(mode='external-fciv') + return self._test_10_u2_2impfci(mode='external', low_level_coul=False) def test_hub_ec_2impfci_proj0_ccsdv(self): - return self._test_10_u2_2impfci(mode='external-ccsdv') + return self._test_10_u2_2impfci(mode='external', low_level_coul=True) @pytest.mark.fast class TestECSym(TestCase): - def _test_10_u2_eccc_sym(self, mode, proj=0): + def _test_10_u2_eccc_sym(self, mode, low_level_coul=True, proj=0): """Test symmetry in external correction via comparison to system without use of symmetry """ @@ -329,7 +329,7 @@ def _test_10_u2_eccc_sym(self, mode, proj=0): ccsd_frag.active = True # Note that proj=0 will 'over correct' here and double-count bath-bath tailoring contributions. # However, it should still be equivalent to the non symmetry version - ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=proj, test_extcorr=True) + ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=proj, low_level_coul=low_level_coul, test_extcorr=True) emb.kernel() e_tot_nosym = emb.e_tot @@ -351,23 +351,23 @@ def _test_10_u2_eccc_sym(self, mode, proj=0): for fci_frag in fci_frags: fci_frag.active = False ccsd_frag.active = True - ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=proj, test_extcorr=True) + ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=proj, low_level_coul=low_level_coul, test_extcorr=True) emb.kernel() self.assertAlmostEqual(emb.e_tot, e_tot_nosym) def test_hub_ec_sym_proj0_fciv(self): - return self._test_10_u2_eccc_sym(mode='external-fciv', proj=0) + return self._test_10_u2_eccc_sym(mode='external', proj=0, low_level_coul=False) def test_hub_ec_sym_proj1_fciv(self): - return self._test_10_u2_eccc_sym(mode='external-fciv', proj=1) + return self._test_10_u2_eccc_sym(mode='external', proj=1, low_level_coul=False) def test_hub_ec_sym_proj2_fciv(self): - return self._test_10_u2_eccc_sym(mode='external-fciv', proj=2) + return self._test_10_u2_eccc_sym(mode='external', proj=2, low_level_coul=False) def test_hub_ec_sym_proj0_ccsdv(self): - return self._test_10_u2_eccc_sym(mode='external-ccsdv', proj=0) + return self._test_10_u2_eccc_sym(mode='external', proj=0, low_level_coul=True) def test_hub_ec_sym_proj1_ccsdv(self): - return self._test_10_u2_eccc_sym(mode='external-ccsdv', proj=1) + return self._test_10_u2_eccc_sym(mode='external', proj=1, low_level_coul=True) def test_hub_ec_sym_proj2_ccsdv(self): - return self._test_10_u2_eccc_sym(mode='external-ccsdv', proj=2) + return self._test_10_u2_eccc_sym(mode='external', proj=2, low_level_coul=True) def test_hub_ec_sym_proj1_dtailor(self): return self._test_10_u2_eccc_sym(mode='delta-tailor', proj=1) def test_hub_ec_sym_proj1_tailor(self): @@ -375,7 +375,7 @@ def test_hub_ec_sym_proj1_tailor(self): @pytest.mark.fast class TestRegEC_CCSD(TestCase): - def _test_water_ec_regression(self, mode=None, projectors=None): + def _test_water_ec_regression(self, mode=None, projectors=None, low_level_coul=True): mf = testsystems.water_ccpvdz_df.rhf() @@ -394,29 +394,29 @@ def _test_water_ec_regression(self, mode=None, projectors=None): for ccsd_frag in ccsd_frags: ccsd_frag.active = True - ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors, + ccsd_frag.add_external_corrections(fci_frags, correction_type=mode, projectors=projectors, low_level_coul=low_level_coul, test_extcorr=True) emb.kernel() return emb.e_tot def test_water_ec_regression_proj0_fciv(self): - e_tot = self._test_water_ec_regression(mode='external-fciv', projectors=0) + e_tot = self._test_water_ec_regression(mode='external', projectors=0, low_level_coul=False) self.assertAlmostEqual(e_tot, -76.2402530047042) def test_water_ec_regression_proj0_ccsdv(self): - e_tot = self._test_water_ec_regression(mode='external-ccsdv', projectors=0) + e_tot = self._test_water_ec_regression(mode='external', projectors=0, low_level_coul=True) self.assertAlmostEqual(e_tot, -76.24018922136538) def test_water_ec_regression_proj1_fciv(self): - e_tot = self._test_water_ec_regression(mode='external-fciv', projectors=1) + e_tot = self._test_water_ec_regression(mode='external', projectors=1, low_level_coul=False) self.assertAlmostEqual(e_tot, -76.24022612405739) def test_water_ec_regression_proj1_ccsdv(self): - e_tot = self._test_water_ec_regression(mode='external-ccsdv', projectors=1) + e_tot = self._test_water_ec_regression(mode='external', projectors=1, low_level_coul=True) self.assertAlmostEqual(e_tot, -76.24017967220551) def test_water_ec_regression_proj2_fciv(self): - e_tot = self._test_water_ec_regression(mode='external-fciv', projectors=2) + e_tot = self._test_water_ec_regression(mode='external', projectors=2, low_level_coul=False) self.assertAlmostEqual(e_tot, -76.24020498388937) def test_water_ec_regression_proj2_ccsdv(self): - e_tot = self._test_water_ec_regression(mode='external-ccsdv', projectors=2) + e_tot = self._test_water_ec_regression(mode='external', projectors=2, low_level_coul=True) self.assertAlmostEqual(e_tot, -76.24017093290053) From 54e0fa3d4f013b90b00de7cf3b361b3b8022d3fc Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 14 Apr 2023 16:05:06 +0100 Subject: [PATCH 64/66] Update externally corrected Hubbard model exammple too. --- examples/ewf/other/61-ext-corr-hubbard-1D.py | 13 +++++-------- 1 file changed, 5 insertions(+), 8 deletions(-) diff --git a/examples/ewf/other/61-ext-corr-hubbard-1D.py b/examples/ewf/other/61-ext-corr-hubbard-1D.py index d7b9a694f..f48d9948a 100644 --- a/examples/ewf/other/61-ext-corr-hubbard-1D.py +++ b/examples/ewf/other/61-ext-corr-hubbard-1D.py @@ -42,16 +42,13 @@ e_extcorr = [] extcorr_conv = [] -#Two main options: correction_type='external-ccsdv' and 'external-fciv'. For the important T3 * V contribution to the -#T2 amplitudes, this determines whether the V is expressed in the FCI or CCSD cluster space. The CCSD cluster is -#larger, and hence this is likely to be better, as the correction is longer-ranged (though slightly more expensive). -#The other option is 'projectors', which should be an integer between 0 and 2 (inclusive). +#Main options: 'projectors', which should be an integer between 0 and 2 (inclusive). #The larger the number, the more fragment projectors are applied to the correcting T2 contributions, and less #'bath' correlation from the FCI clusters is used as a constraint in the external correction of the CCSD clusters. #NOTE that with multiple FCI fragments providing constraints and overlapping bath spaces, proj=0 will #overcount the correction, so do not use with multiple FCI clusters. It will not e.g. tend to the right answer as #the FCI bath space becomes complete (for which you must have proj=1). Only use with a single FCI fragment. -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=1) +ccsd_frag.add_external_corrections(fci_frags, correction_type='external', projectors=1) emb.kernel() e_extcorr.append(emb.e_tot); extcorr_conv.append(emb.converged) @@ -61,17 +58,17 @@ fci_frag.active = False ccsd_frag.clear_external_corrections() # Clear any previous corrections applied -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-ccsdv', projectors=2) +ccsd_frag.add_external_corrections(fci_frags, correction_type='external', projectors=2) emb.kernel() e_extcorr.append(emb.e_tot); extcorr_conv.append(emb.converged) ccsd_frag.clear_external_corrections() # Clear any previous corrections applied -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=1) +ccsd_frag.add_external_corrections(fci_frags, correction_type='external', projectors=1, low_level_coul=False) emb.kernel() e_extcorr.append(emb.e_tot); extcorr_conv.append(emb.converged) ccsd_frag.clear_external_corrections() # Clear any previous corrections applied -ccsd_frag.add_external_corrections(fci_frags, correction_type='external-fciv', projectors=2) +ccsd_frag.add_external_corrections(fci_frags, correction_type='external', projectors=2, low_level_coul=False) emb.kernel() e_extcorr.append(emb.e_tot); extcorr_conv.append(emb.converged) From 9f60bcbce3a688f7d0b4c932708fb278fe1ff252 Mon Sep 17 00:00:00 2001 From: George Booth Date: Fri, 14 Apr 2023 16:09:45 +0100 Subject: [PATCH 65/66] TODO added to improve integral transformation for delta-tailoring with translationally equivalent fragments. --- vayesta/solver/coupling.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index 68e5e7419..a6bb81c50 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -516,6 +516,8 @@ def _get_delta_t_for_delta_tailor(fragment, fock): eris = fragment._eris if eris is None: # Symmetry-derived fragments may not have eris stored + # TODO: This may not scale well, since we are performing + # integral transformations for all fragments. Can be improved. eris = fragment.base.get_eris_array(cluster.c_active) ccsd = SimpleCCSD(fock, eris, nocc, mo_energy=mo_energy) wf = ccsd.kernel(t1=t1, t2=t2) From 18aa87acab0a0ee58c843f812522c3325b2ec92c Mon Sep 17 00:00:00 2001 From: George Booth Date: Sat, 15 Apr 2023 11:30:09 +0100 Subject: [PATCH 66/66] Fixes for tests. --- vayesta/solver/coupling.py | 2 +- vayesta/tests/ewf/test_extcorr.py | 28 ++++++++++++++-------------- 2 files changed, 15 insertions(+), 15 deletions(-) diff --git a/vayesta/solver/coupling.py b/vayesta/solver/coupling.py index a6bb81c50..e788c142c 100644 --- a/vayesta/solver/coupling.py +++ b/vayesta/solver/coupling.py @@ -653,7 +653,7 @@ def externally_correct(solver, external_corrections, eris=None): dt1 = spinalg.add(dt1, dt1y) dt2 = spinalg.add(dt2, dt2y) - if low_level_coul: + if low_level_coul and corrtype == 'external': # Include the t3v term, contracting with the integrals from the x cluster # These have already been fragment projected, and rotated into the x cluster # in this function. diff --git a/vayesta/tests/ewf/test_extcorr.py b/vayesta/tests/ewf/test_extcorr.py index 7240553d2..caa4303bf 100644 --- a/vayesta/tests/ewf/test_extcorr.py +++ b/vayesta/tests/ewf/test_extcorr.py @@ -148,7 +148,7 @@ def test_u_exact_ec_lih_631g_fullsystem_proj2_ccsdv_store(self): @pytest.mark.fast def test_r_regression_ec_lih_631g_atomicfrags_bathype_dmet_proj1_ccsdv_store(self): e_tot, fci_e_tot = self._test(('lih_631g', 'rhf'), proj=1, bathtype='dmet', fcifragtype = 'atomic', - mode='external', low_level_coul=True store_wf_ccsdtq=True) + mode='external', low_level_coul=True, store_wf_ccsdtq=True) self.assertAlmostEqual(e_tot, -7.988931393747468) @pytest.mark.fast @@ -210,7 +210,7 @@ def test_u_regression_ec_lih_631g_fullsystem_bathype_dmet_proj2_ccsdv_store(self @pytest.mark.fast class TestHubCompleteEC(TestCase): - def _test_10_u4_2imp(self, mode, proj): + def _test_10_u4_2imp(self, mode, proj, low_level_coul=True): """Tests for N=10 U=4 Hubbard model with double site CCSD impurities and complete FCI fragment """ @@ -230,7 +230,7 @@ def _test_10_u4_2imp(self, mode, proj): fci_frag.active = False ccsd_frag.active = True - ccsd_frag.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, test_extcorr=True) + ccsd_frag.add_external_corrections([fci_frag], correction_type=mode, projectors=proj, low_level_coul=low_level_coul, test_extcorr=True) emb.kernel() fci = pyscf.fci.FCI(mf) @@ -245,17 +245,17 @@ def _test_10_u4_2imp(self, mode, proj): self.assertAlmostEqual(emb.e_tot, fci_frag_etot) def test_hub_ec_2imp_proj0_ccsdv(self): - return self._test_10_u4_2imp(mode='external', low_level_coul=True, proj=0) - def test_hub_ec_2imp_proj1_ccsdv(self): - return self._test_10_u4_2imp(mode='external', low_level_coul=True, proj=1) - def test_hub_ec_2imp_proj2_ccsdv(self): - return self._test_10_u4_2imp(mode='external', low_level_coul=True, proj=2) - def test_hub_ec_2imp_proj0_fciv(self): - return self._test_10_u4_2imp(mode='external', low_level_coul=False, proj=0) - def test_hub_ec_2imp_proj1_fciv(self): - return self._test_10_u4_2imp(mode='external', low_level_coul=False, proj=1) - def test_hub_ec_2imp_proj2_fciv(self): - return self._test_10_u4_2imp(mode='external', low_level_coul=False, proj=2) + return self._test_10_u4_2imp(mode='external', proj=0, low_level_coul=True) + def test_hub_ec_2imp_proj1_ccsdv(self): + return self._test_10_u4_2imp(mode='external', proj=1, low_level_coul=True) + def test_hub_ec_2imp_proj2_ccsdv(self): + return self._test_10_u4_2imp(mode='external', proj=2, low_level_coul=True) + def test_hub_ec_2imp_proj0_fciv(self): + return self._test_10_u4_2imp(mode='external', proj=0, low_level_coul=False) + def test_hub_ec_2imp_proj1_fciv(self): + return self._test_10_u4_2imp(mode='external', proj=1, low_level_coul=False) + def test_hub_ec_2imp_proj2_fciv(self): + return self._test_10_u4_2imp(mode='external', proj=2, low_level_coul=False) @pytest.mark.fast class TestHubBathEC(TestCase):