def OPDM(L, R, flavor): display( Markdown( rf""" Computing OPDM for {flavor} (skipping summation for dummy variables)""" )) i, j = symbols('i,j', below_fermi=True) a, b = symbols('a,b', above_fermi=True) PermutList = [PermutationOperator(i, j), PermutationOperator(a, b)] oo = Fd(i) * F(j) cc = BCH.level(oo, "SD") g_oo = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) g_oo = simplify_index_permutations(g_oo, PermutList) index_rule = {'below': 'klmno', 'above': 'abcde'} g_oo = substitute_dummies(g_oo, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{ij}') final_eq = Eq(gamma, g_oo) display(final_eq) ov = Fd(i) * F(a) cc = BCH.level(ov, "SD") g_ov = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) g_ov = simplify_index_permutations(g_ov, PermutList) index_rule = {'below': 'jklmn', 'above': 'bcdef'} g_ov = substitute_dummies(g_ov, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{ia}') final_eq = Eq(gamma, g_ov) display(final_eq) vo = Fd(a) * F(i) cc = BCH.level(vo, "SD") g_vo = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) g_vo = simplify_index_permutations(g_vo, PermutList) index_rule = {'below': 'jklmn', 'above': 'bcdef'} g_vo = substitute_dummies(g_vo, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{ai}') final_eq = Eq(gamma, g_vo) display(final_eq) vv = Fd(a) * F(b) cc = BCH.level(vv, "SD") g_vv = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) g_vv = simplify_index_permutations(g_vv, PermutList) index_rule = {'below': 'ijklm', 'above': 'cdefg'} g_vv = substitute_dummies(g_vv, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{ab}') final_eq = Eq(gamma, g_vv) display(final_eq)
def OPTDM(Lf1, Rf1, Lf2, Rf2, flavor1, flavor2): display( Markdown( rf""" Computing Dyson OPTDM between {flavor1} $\rightarrow$ {flavor2} (skipping summation for dummy variables)""" )) i = symbols('i', below_fermi=True) a = symbols('a', above_fermi=True) index_rule = {'below': 'jklmn', 'above': 'bcde'} oo = Fd(i) cc = BCH.level(oo, "SD") g_oo = evaluate_deltas( wicks(Lf2 * cc * Rf1, keep_only_fully_contracted=True)) g_oo = substitute_dummies(g_oo, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_i^{R}') final_eq = Eq(gamma, g_oo) display(final_eq) ov = Fd(a) cc = BCH.level(ov, "SD") g_ov = evaluate_deltas( wicks(Lf2 * cc * Rf1, keep_only_fully_contracted=True)) index_rule = {'below': 'jklmn', 'above': 'bcdef'} g_ov = substitute_dummies(g_ov, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_a^{R}') final_eq = Eq(gamma, g_ov) display(final_eq) vo = F(i) cc = BCH.level(vo, "SD") g_vo = evaluate_deltas( wicks(Lf1 * cc * Rf2, keep_only_fully_contracted=True)) index_rule = {'below': 'jklmn', 'above': 'bcdef'} g_vo = substitute_dummies(g_vo, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_i^{L}') final_eq = Eq(gamma, g_vo) display(final_eq) vv = F(a) cc = BCH.level(vv, "SD") g_vv = evaluate_deltas( wicks(Lf1 * cc * Rf2, keep_only_fully_contracted=True)) index_rule = {'below': 'ijklm', 'above': 'cdefg'} g_vv = substitute_dummies(g_vv, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_a^{L}') final_eq = Eq(gamma, g_vv) display(final_eq)
def test_contraction(): i, j, k, l = symbols("i,j,k,l", below_fermi=True) a, b, c, d = symbols("a,b,c,d", above_fermi=True) p, q, r, s = symbols("p,q,r,s") assert contraction(Fd(i), F(j)) == KroneckerDelta(i, j) assert contraction(F(a), Fd(b)) == KroneckerDelta(a, b) assert contraction(F(a), Fd(i)) == 0 assert contraction(Fd(a), F(i)) == 0 assert contraction(F(i), Fd(a)) == 0 assert contraction(Fd(i), F(a)) == 0 assert contraction(Fd(i), F(p)) == KroneckerDelta(i, p) restr = evaluate_deltas(contraction(Fd(p), F(q))) assert restr.is_only_below_fermi restr = evaluate_deltas(contraction(F(p), Fd(q))) assert restr.is_only_above_fermi
def test_contraction(): i,j,k,l = symbols('ijkl',below_fermi=True) a,b,c,d = symbols('abcd',above_fermi=True) p,q,r,s = symbols('pqrs') assert contraction(Fd(i),F(j)) == KroneckerDelta(i,j) assert contraction(F(a),Fd(b)) == KroneckerDelta(a,b) assert contraction(F(a),Fd(i)) == 0 assert contraction(Fd(a),F(i)) == 0 assert contraction(F(i),Fd(a)) == 0 assert contraction(Fd(i),F(a)) == 0 assert contraction(Fd(i),F(p)) == KroneckerDelta(p,i) restr = evaluate_deltas(contraction(Fd(p),F(q))) assert restr.is_only_below_fermi restr = evaluate_deltas(contraction(F(p),Fd(q))) assert restr.is_only_above_fermi
def test_contraction(): i, j, k, l = symbols('i,j,k,l', below_fermi=True) a, b, c, d = symbols('a,b,c,d', above_fermi=True) p, q, r, s = symbols('p,q,r,s') assert contraction(Fd(i), F(j)) == KroneckerDelta(i, j) assert contraction(F(a), Fd(b)) == KroneckerDelta(a, b) assert contraction(F(a), Fd(i)) == 0 assert contraction(Fd(a), F(i)) == 0 assert contraction(F(i), Fd(a)) == 0 assert contraction(Fd(i), F(a)) == 0 assert contraction(Fd(i), F(p)) == KroneckerDelta(i, p) restr = evaluate_deltas(contraction(Fd(p), F(q))) assert restr.is_only_below_fermi restr = evaluate_deltas(contraction(F(p), Fd(q))) assert restr.is_only_above_fermi
def test_contraction(): i, j, k, l = symbols("i,j,k,l", below_fermi=True) a, b, c, d = symbols("a,b,c,d", above_fermi=True) p, q, r, s = symbols("p,q,r,s") assert contraction(Fd(i), F(j)) == KroneckerDelta(i, j) assert contraction(F(a), Fd(b)) == KroneckerDelta(a, b) assert contraction(F(a), Fd(i)) == 0 assert contraction(Fd(a), F(i)) == 0 assert contraction(F(i), Fd(a)) == 0 assert contraction(Fd(i), F(a)) == 0 assert contraction(Fd(i), F(p)) == KroneckerDelta(i, p) restr = evaluate_deltas(contraction(Fd(p), F(q))) assert restr.is_only_below_fermi restr = evaluate_deltas(contraction(F(p), Fd(q))) assert restr.is_only_above_fermi raises(ContractionAppliesOnlyToFermions, lambda: contraction(B(a), Fd(b)))
def test_contraction(): i, j, k, l = symbols('i,j,k,l', below_fermi=True) a, b, c, d = symbols('a,b,c,d', above_fermi=True) p, q, r, s = symbols('p,q,r,s') assert contraction(Fd(i), F(j)) == KroneckerDelta(i, j) assert contraction(F(a), Fd(b)) == KroneckerDelta(a, b) assert contraction(F(a), Fd(i)) == 0 assert contraction(Fd(a), F(i)) == 0 assert contraction(F(i), Fd(a)) == 0 assert contraction(Fd(i), F(a)) == 0 assert contraction(Fd(i), F(p)) == KroneckerDelta(i, p) restr = evaluate_deltas(contraction(Fd(p), F(q))) assert restr.is_only_below_fermi restr = evaluate_deltas(contraction(F(p), Fd(q))) assert restr.is_only_above_fermi raises(ContractionAppliesOnlyToFermions, lambda: contraction(B(a), Fd(b)))
def level(H, expr): pretty_dummies_dict = { 'above': 'defg', 'below': 'lmno', 'general': 'pqrst' } #display(Markdown # (rf"""Calculating 4 nested commutators""")) C = Commutator T1, T2 = get_CC_operators() T = T1 + T2 comm1 = wicks(C(H, T)) comm1 = evaluate_deltas(comm1) comm1 = substitute_dummies(comm1) T1, T2 = get_CC_operators() T = T1 + T2 comm2 = wicks(C(comm1, T)) comm2 = evaluate_deltas(comm2) comm2 = substitute_dummies(comm2) T1, T2 = get_CC_operators() T = T1 + T2 comm3 = wicks(C(comm2, T)) comm3 = evaluate_deltas(comm3) comm3 = substitute_dummies(comm3) T1, T2 = get_CC_operators() T = T1 + T2 comm4 = wicks(C(comm3, T)) comm4 = evaluate_deltas(comm4) comm4 = substitute_dummies(comm4) eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24 eq = eq.expand() eq = evaluate_deltas(eq) eq = substitute_dummies(eq, new_indices=True, pretty_indices=pretty_dummies_dict) return eq
def computeHausdorff(H): print("Calculating 4 nested commutators") C = Commutator T1, T2 = get_T_operators() T = T2 print("commutator 1...") comm1 = wicks(C(H, T)) comm1 = evaluate_deltas(comm1) comm1 = substitute_dummies(comm1) T1, T2 = get_T_operators() T = T2 print("commutator 2...") comm2 = wicks(C(comm1, T)) comm2 = evaluate_deltas(comm2) comm2 = substitute_dummies(comm2) T1, T2 = get_T_operators() T = T2 print("commutator 3...") comm3 = wicks(C(comm2, T)) comm3 = evaluate_deltas(comm3) comm3 = substitute_dummies(comm3) T1, T2 = get_T_operators() T = T2 print("commutator 4...") comm4 = wicks(C(comm3, T)) comm4 = evaluate_deltas(comm4) comm4 = substitute_dummies(comm4) print("construct Hausdorff expansion...") eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24 eq = eq.expand() eq = evaluate_deltas(eq) eq = substitute_dummies(eq, new_indices=True, pretty_indices=pretty_dummies_dict) print("*********************") print() return eq
def compute_hausdorff(h, cluster_func, num_terms=4): commutator = Commutator comm_term = h equation = comm_term for i in range(num_terms): t = sum(cluster_func()) comm_term = wicks(commutator(comm_term, t)) comm_term = substitute_dummies(evaluate_deltas(comm_term)) equation += comm_term / factorial(i + 1) equation = equation.expand() equation = evaluate_deltas(equation) equation = substitute_dummies(equation, new_indices=True, pretty_indices=pretty_dummies) return equation
def test_evaluate_deltas(): i, j, k = symbols("i,j,k") r = KroneckerDelta(i, j) * KroneckerDelta(j, k) assert evaluate_deltas(r) == KroneckerDelta(i, k) r = KroneckerDelta(i, 0) * KroneckerDelta(j, k) assert evaluate_deltas(r) == KroneckerDelta(i, 0) * KroneckerDelta(j, k) r = KroneckerDelta(1, j) * KroneckerDelta(j, k) assert evaluate_deltas(r) == KroneckerDelta(1, k) r = KroneckerDelta(j, 2) * KroneckerDelta(k, j) assert evaluate_deltas(r) == KroneckerDelta(2, k) r = KroneckerDelta(i, 0) * KroneckerDelta(i, j) * KroneckerDelta(j, 1) assert evaluate_deltas(r) == 0 r = ( KroneckerDelta(0, i) * KroneckerDelta(0, j) * KroneckerDelta(1, j) * KroneckerDelta(1, j) ) assert evaluate_deltas(r) == 0
def test_evaluate_deltas(): i, j, k = symbols('i,j,k') r = KroneckerDelta(i, j) * KroneckerDelta(j, k) assert evaluate_deltas(r) == KroneckerDelta(i, k) r = KroneckerDelta(i, 0) * KroneckerDelta(j, k) assert evaluate_deltas(r) == KroneckerDelta(i, 0) * KroneckerDelta(j, k) r = KroneckerDelta(1, j) * KroneckerDelta(j, k) assert evaluate_deltas(r) == KroneckerDelta(1, k) r = KroneckerDelta(j, 2) * KroneckerDelta(k, j) assert evaluate_deltas(r) == KroneckerDelta(2, k) r = KroneckerDelta(i, 0) * KroneckerDelta(i, j) * KroneckerDelta(j, 1) assert evaluate_deltas(r) == 0 r = (KroneckerDelta(0, i) * KroneckerDelta(0, j) * KroneckerDelta(1, j) * KroneckerDelta(1, j)) assert evaluate_deltas(r) == 0
#Link to Second quant documentation: https://docs.sympy.org/latest/modules/physics/secondquant.html pretty_dummies_dict = { 'above': 'abcdefgh', 'below': 'ijklmno', 'general': 'pqrstu' } p, q, r, s = symbols('p,q,r,s', cls=Dummy) #Setup creation and annihilation operators ap_dagger = Fd(p) aq = F(q) #Perform a contraction contr = evaluate_deltas(contraction(ap_dagger, aq)) print("Example outputs") print() print("contraction(a_p^\dagger a_q): ", latex(contr)) print() #Setup Hamiltonian, not on normal order form h = AntiSymmetricTensor('h', (p, ), (q, )) pq = ap_dagger * aq V = AntiSymmetricTensor('V', (p, q), (r, s)) pqsr = Fd(p) * Fd(q) * F(s) * F(r) H0 = h * pq HI = Rational(1, 4) * V * pqsr
eqT2 = wicks(NO(Fd(i) * Fd(j) * F(b) * F(a)) * HN, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True) P = PermutationOperator eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)]) print("<Phi|HN|Phi_ij^ab = ", latex(eqT2)) print() C = Commutator T1, T2 = get_CC_operators() T = T2 print("[HN,T]-term") comm1 = wicks(C(HN, T)) comm1 = evaluate_deltas(comm1) comm1 = substitute_dummies(comm1, new_indices=True, pretty_indices=pretty_dummies_dict) print( "<Phi|[HN,T]|Phi> = ", latex(wicks(comm1, simplify_dummies=True, keep_only_fully_contracted=True))) eqT2 = wicks(NO(Fd(i) * Fd(j) * F(b) * F(a)) * comm1, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True) P = PermutationOperator eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)]) print("<Phi|[HN,T]|Phi_ij^ab = ", latex(eqT2)) print()
def main(): print() print("Calculates the Coupled-Cluster energy- and amplitude equations") print("See 'An Introduction to Coupled Cluster Theory' by") print("T. Daniel Crawford and Henry F. Schaefer III") print("http://www.ccc.uga.edu/lec_top/cc/html/review.html") print() # setup hamiltonian p, q, r, s = symbols('p,q,r,s', cls=Dummy) f = AntiSymmetricTensor('f', (p,), (q,)) pr = NO((Fd(p)*F(q))) v = AntiSymmetricTensor('v', (p, q), (r, s)) pqsr = NO(Fd(p)*Fd(q)*F(s)*F(r)) H = f*pr + Rational(1, 4)*v*pqsr print("Using the hamiltonian:", latex(H)) print("Calculating 4 nested commutators") C = Commutator T1, T2 = get_CC_operators() T = T1 + T2 print("commutator 1...") comm1 = wicks(C(H, T)) comm1 = evaluate_deltas(comm1) comm1 = substitute_dummies(comm1) T1, T2 = get_CC_operators() T = T1 + T2 print("commutator 2...") comm2 = wicks(C(comm1, T)) comm2 = evaluate_deltas(comm2) comm2 = substitute_dummies(comm2) T1, T2 = get_CC_operators() T = T1 + T2 print("commutator 3...") comm3 = wicks(C(comm2, T)) comm3 = evaluate_deltas(comm3) comm3 = substitute_dummies(comm3) T1, T2 = get_CC_operators() T = T1 + T2 print("commutator 4...") comm4 = wicks(C(comm3, T)) comm4 = evaluate_deltas(comm4) comm4 = substitute_dummies(comm4) print("construct Hausdoff expansion...") eq = H + comm1 + comm2/2 + comm3/6 + comm4/24 eq = eq.expand() eq = evaluate_deltas(eq) eq = substitute_dummies(eq, new_indices=True, pretty_indices=pretty_dummies_dict) print("*********************") print() print("extracting CC equations from full Hbar") i, j, k, l = symbols('i,j,k,l', below_fermi=True) a, b, c, d = symbols('a,b,c,d', above_fermi=True) print() print("CC Energy:") print(latex(wicks(eq, simplify_dummies=True, keep_only_fully_contracted=True))) print() print("CC T1:") eqT1 = wicks(NO(Fd(i)*F(a))*eq, simplify_kronecker_deltas=True, keep_only_fully_contracted=True) eqT1 = substitute_dummies(eqT1) print(latex(eqT1)) print() print("CC T2:") eqT2 = wicks(NO(Fd(i)*Fd(j)*F(b)*F(a))*eq, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True) P = PermutationOperator eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)]) print(latex(eqT2))
comm2 = wicks(C(comm1,T),simplify_dummies=True, simplify_kronecker_deltas=True) T1,T2 = get_CC_operators() T = T1+ T2 print "comm3..." comm3 = wicks(C(comm2,T),simplify_dummies=True, simplify_kronecker_deltas=True) T1,T2 = get_CC_operators() T = T1+ T2 print "comm4..." comm4 = wicks(C(comm3,T),simplify_dummies=True, simplify_kronecker_deltas=True) print "construct Hausdoff expansion..." eq = H + comm1+comm2/2+comm3/6+comm4/24 eq = eq.expand() eq = evaluate_deltas(eq) eq = substitute_dummies(eq, new_indices=True, reverse_order=False) print "*********************" print print "extracting CC equations from full Hbar" i,j,k,l = symbols('ijkl',below_fermi=True) a,b,c,d = symbols('abcd',above_fermi=True) print print "CC Energy:" print latex(wicks(eq, simplify_dummies=True, keep_only_fully_contracted=True)) print print "CC T1:" eqT1 = wicks(NO(Fd(i)*F(a))*eq, simplify_kronecker_deltas=True, keep_only_fully_contracted=True) eqT1 = substitute_dummies(eqT1,reverse_order=False)
def main(): print print "Calculates the Coupled-Cluster energy- and amplitude equations" print "See 'An Introduction to Coupled Cluster Theory' by" print "T. Daniel Crawford and Henry F. Schaefer III" print "http://www.ccc.uga.edu/lec_top/cc/html/review.html" print # setup hamiltonian p, q, r, s = symbols("pqrs", dummy=True) f = AntiSymmetricTensor("f", (p,), (q,)) pr = NO((Fd(p) * F(q))) v = AntiSymmetricTensor("v", (p, q), (r, s)) pqsr = NO(Fd(p) * Fd(q) * F(s) * F(r)) H = f * pr # Uncomment the next line to use a 2-body hamiltonian: # H=f*pr + Number(1,4)*v*pqsr print "Using the hamiltonian:", latex(H) print "Calculating nested commutators" C = Commutator T1, T2 = get_CC_operators() T = T1 + T2 print "comm1..." comm1 = wicks(C(H, T), simplify_dummies=True, simplify_kronecker_deltas=True) T1, T2 = get_CC_operators() T = T1 + T2 print "comm2..." comm2 = wicks(C(comm1, T), simplify_dummies=True, simplify_kronecker_deltas=True) T1, T2 = get_CC_operators() T = T1 + T2 print "comm3..." comm3 = wicks(C(comm2, T), simplify_dummies=True, simplify_kronecker_deltas=True) T1, T2 = get_CC_operators() T = T1 + T2 print "comm4..." comm4 = wicks(C(comm3, T), simplify_dummies=True, simplify_kronecker_deltas=True) print "construct Hausdoff expansion..." eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24 eq = eq.expand() eq = evaluate_deltas(eq) eq = substitute_dummies(eq, new_indices=True, reverse_order=False, pretty_indices=pretty_dummies_dict) print "*********************" print print "extracting CC equations from full Hbar" i, j, k, l = symbols("ijkl", below_fermi=True) a, b, c, d = symbols("abcd", above_fermi=True) print print "CC Energy:" print latex(wicks(eq, simplify_dummies=True, keep_only_fully_contracted=True)) print print "CC T1:" eqT1 = wicks(NO(Fd(i) * F(a)) * eq, simplify_kronecker_deltas=True, keep_only_fully_contracted=True) eqT1 = substitute_dummies(eqT1, reverse_order=False) print latex(eqT1) print print "CC T2:" eqT2 = wicks( NO(Fd(i) * Fd(j) * F(b) * F(a)) * eq, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True, ) P = PermutationOperator eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)]) print latex(eqT2)
def main(): print() print("Calculates the Coupled-Cluster energy- and amplitude equations") print("See 'An Introduction to Coupled Cluster Theory' by") print("T. Daniel Crawford and Henry F. Schaefer III") print( "Reference to a Lecture Series: http://vergil.chemistry.gatech.edu/notes/sahan-cc-2010.pdf" ) print() # setup hamiltonian p, q, r, s = symbols('p,q,r,s', cls=Dummy) f = AntiSymmetricTensor('f', (p, ), (q, )) pr = NO(Fd(p) * F(q)) v = AntiSymmetricTensor('v', (p, q), (r, s)) pqsr = NO(Fd(p) * Fd(q) * F(s) * F(r)) H = f * pr + Rational(1, 4) * v * pqsr print("Using the hamiltonian:", latex(H)) print("Calculating 4 nested commutators") C = Commutator T1, T2 = get_CC_operators() T = T1 + T2 print("commutator 1...") comm1 = wicks(C(H, T)) comm1 = evaluate_deltas(comm1) comm1 = substitute_dummies(comm1) T1, T2 = get_CC_operators() T = T1 + T2 print("commutator 2...") comm2 = wicks(C(comm1, T)) comm2 = evaluate_deltas(comm2) comm2 = substitute_dummies(comm2) T1, T2 = get_CC_operators() T = T1 + T2 print("commutator 3...") comm3 = wicks(C(comm2, T)) comm3 = evaluate_deltas(comm3) comm3 = substitute_dummies(comm3) T1, T2 = get_CC_operators() T = T1 + T2 print("commutator 4...") comm4 = wicks(C(comm3, T)) comm4 = evaluate_deltas(comm4) comm4 = substitute_dummies(comm4) print("construct Hausdorff expansion...") eq = H + comm1 + comm2 / 2 + comm3 / 6 + comm4 / 24 eq = eq.expand() eq = evaluate_deltas(eq) eq = substitute_dummies(eq, new_indices=True, pretty_indices=pretty_dummies_dict) print("*********************") print() print("extracting CC equations from full Hbar") i, j, k, l = symbols('i,j,k,l', below_fermi=True) a, b, c, d = symbols('a,b,c,d', above_fermi=True) print() print("CC Energy:") print( latex(wicks(eq, simplify_dummies=True, keep_only_fully_contracted=True))) # print("HERE") # print("HERE") # print("HERE") # print(pycode(wicks(eq, simplify_dummies=True, # keep_only_fully_contracted=True))) # with open("cc_energy.py", "w") as f: # f. with open("ccsd.jl", "w") as f: eq_energy = wicks(eq, simplify_dummies=True, keep_only_fully_contracted=True) f.write(julia_code(eq_energy)) print() print("CC T1:") eqT1 = wicks(NO(Fd(i) * F(a)) * eq, simplify_kronecker_deltas=True, keep_only_fully_contracted=True) eqT1 = substitute_dummies(eqT1) print(latex(eqT1)) print() print("CC T2:") eqT2 = wicks(NO(Fd(i) * Fd(j) * F(b) * F(a)) * eq, simplify_dummies=True, keep_only_fully_contracted=True, simplify_kronecker_deltas=True) # P = PermutationOperator # eqT2 = simplify_index_permutations(eqT2, [P(a, b), P(i, j)]) print(latex(eqT2)) print(latex(simplify(eqT2)))
def LVECTORS(L0, L1, L2, flavor): display( Markdown( rf""" Computing left sigma amplitudes for {flavor} (skipping summation for dummy variables)""" )) p, q, r, s = symbols('p,q,r,s', cls=Dummy) f = AntiSymmetricTensor('f', (p, ), (q, )) pr = NO((Fd(p) * F(q))) v = AntiSymmetricTensor('v', (p, q), (r, s)) pqsr = NO(Fd(p) * Fd(q) * F(s) * F(r)) ham = f * pr + Rational(1, 4) * v * pqsr cc = BCH.level(ham, "SD") E_cc = evaluate_deltas(wicks(cc, keep_only_fully_contracted=True)) i, j, k = symbols('i,j,k', below_fermi=True) a, b, c = symbols('a,b,c', above_fermi=True) if flavor == "IP": sig11 = evaluate_deltas( wicks(L1 * (cc - E_cc) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'jklmno', 'above': 'abcdefg'} sig11 = substitute_dummies(sig11, new_indices=True, pretty_indices=index_rule) if flavor == "EA": sig11 = evaluate_deltas( wicks(L1 * (cc - E_cc) * Fd(a), keep_only_fully_contracted=True)) index_rule = {'below': 'ijklmno', 'above': 'bcdefg'} sig11 = substitute_dummies(sig11, new_indices=True, pretty_indices=index_rule) if flavor == "DIP": PermutList = [PermutationOperator(i, j)] sig11 = evaluate_deltas( wicks(L1 * (cc - E_cc) * F(j) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'klmno', 'above': 'abcdefg'} sig11 = substitute_dummies(sig11, new_indices=True, pretty_indices=index_rule) sig11 = simplify_index_permutations(sig11, PermutList) if flavor == "DEA": PermutList = [PermutationOperator(a, b)] sig11 = evaluate_deltas( wicks(L1 * (cc - E_cc) * Fd(a) * Fd(b), keep_only_fully_contracted=True)) index_rule = {'below': 'ijklmno', 'above': 'cdefg'} sig11 = substitute_dummies(sig11, new_indices=True, pretty_indices=index_rule) sig11 = simplify_index_permutations(sig11, PermutList) sigma_11 = Symbol('(L_{1}(\overline{H}_{SS}-E_{cc}))') final_eq = Eq(sigma_11, sig11) display(final_eq) if flavor == "IP": PermutList = [PermutationOperator(i, j)] sig12 = evaluate_deltas( wicks((L2 * cc) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'jklmno', 'above': 'abcdefg'} sig12 = substitute_dummies(sig12, new_indices=True, pretty_indices=index_rule) sig12 = simplify_index_permutations(sig12, PermutList) if flavor == "EA": PermutList = [PermutationOperator(a, b)] sig12 = evaluate_deltas( wicks((L2 * cc) * Fd(a), keep_only_fully_contracted=True)) index_rule = {'below': 'ijklmno', 'above': 'bcdefg'} sig12 = substitute_dummies(sig12, new_indices=True, pretty_indices=index_rule) sig12 = simplify_index_permutations(sig12, PermutList) if flavor == "DIP": PermutList = [ PermutationOperator(i, j), PermutationOperator(j, k), PermutationOperator(i, k) ] sig12 = evaluate_deltas( wicks(L2 * cc * F(j) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'klmno', 'above': 'abcdefg'} sig12 = substitute_dummies(sig12, new_indices=True, pretty_indices=index_rule) sig12 = simplify_index_permutations(sig12, PermutList) if flavor == "DEA": PermutList = [ PermutationOperator(a, b), PermutationOperator(b, c), PermutationOperator(a, c) ] sig12 = evaluate_deltas( wicks((L2 * cc) * Fd(a) * Fd(b), keep_only_fully_contracted=True)) index_rule = {'below': 'ijklmno', 'above': 'cdefg'} sig12 = substitute_dummies(sig12, new_indices=True, pretty_indices=index_rule) sig12 = simplify_index_permutations(sig12, PermutList) sigma_12 = Symbol('(L_{2}\overline{H}_{DS})') final_eq = Eq(sigma_12, sig12) display(final_eq) if flavor == "IP": sig21 = evaluate_deltas( wicks((L1 * cc) * Fd(a) * F(j) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'klmno', 'above': 'bcdefgh'} sig21 = substitute_dummies(sig21, new_indices=True, pretty_indices=index_rule) if flavor == "EA": sig21 = evaluate_deltas( wicks((L1 * cc) * Fd(a) * Fd(b) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'jklmno', 'above': 'cdefgh'} sig21 = substitute_dummies(sig21, new_indices=True, pretty_indices=index_rule) if flavor == "DIP": PermutList = [PermutationOperator(i, j)] sig21 = evaluate_deltas( wicks(L1 * cc * Fd(a) * F(k) * F(j) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'lmno', 'above': 'bcdefgh'} sig21 = substitute_dummies(sig21, new_indices=True, pretty_indices=index_rule) sig21 = simplify_index_permutations(sig21, PermutList) if flavor == "DEA": PermutList = [PermutationOperator(a, b)] sig21 = evaluate_deltas( wicks((L1 * cc) * Fd(a) * Fd(b) * Fd(c) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'jklmno', 'above': 'defgh'} sig21 = substitute_dummies(sig21, new_indices=True, pretty_indices=index_rule) sig21 = simplify_index_permutations(sig21, PermutList) sigma_21 = Symbol('(L_{1}\overline{H}_{SD})') final_eq = Eq(sigma_21, sig21) display(final_eq) if flavor == "IP": PermutList = [PermutationOperator(i, j)] sig22 = evaluate_deltas( wicks(L2 * (cc - E_cc) * Fd(a) * F(j) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'klmno', 'above': 'bcdefgh'} sig22 = substitute_dummies(sig22, new_indices=True, pretty_indices=index_rule) sig22 = simplify_index_permutations(sig22, PermutList) if flavor == "EA": PermutList = [PermutationOperator(a, b)] sig22 = evaluate_deltas( wicks(L2 * (cc - E_cc) * Fd(a) * Fd(b) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'jklmno', 'above': 'cdefgh'} sig22 = substitute_dummies(sig22, new_indices=True, pretty_indices=index_rule) sig22 = simplify_index_permutations(sig22, PermutList) if flavor == "DIP": PermutList = [ PermutationOperator(i, j), PermutationOperator(j, k), PermutationOperator(i, k) ] sig22 = evaluate_deltas( wicks(L2 * (cc - E_cc) * Fd(a) * F(k) * F(j) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'lmno', 'above': 'bcdefgh'} sig22 = substitute_dummies(sig22, new_indices=True, pretty_indices=index_rule) sig22 = simplify_index_permutations(sig22, PermutList) if flavor == "DEA": PermutList = [ PermutationOperator(a, b), PermutationOperator(b, c), PermutationOperator(a, c) ] sig22 = evaluate_deltas( wicks(L2 * (cc - E_cc) * Fd(a) * Fd(b) * Fd(c) * F(i), keep_only_fully_contracted=True)) index_rule = {'below': 'jklmno', 'above': 'defgh'} sig22 = substitute_dummies(sig22, new_indices=True, pretty_indices=index_rule) sig22 = simplify_index_permutations(sig22, PermutList) sigma_22 = Symbol('(L_{2}(\overline{H}_{DD}-E_{cc}))') final_eq = Eq(sigma_22, sig22) display(final_eq)
T = sum(get_ccsd_t_operators()) T_2 = sum(get_ccsd_t_operators()) T_t = sum(get_ccsd_t_operators(ast_symb="t(t)")) T_t_2 = sum(get_ccsd_t_operators(ast_symb="t(t)")) L = sum(get_ccsd_lambda_operators()) L_t = sum(get_ccsd_lambda_operators(ast_symb="l(t)")) tilde_t_eq = Rational(1, 1) tilde_t_eq += eval_equation(-L_t * T_t) tilde_t_eq += eval_equation(L_t * T) tilde_t_eq += eval_equation(-L_t * T_t * T) tilde_t_eq += eval_equation(Rational(1, 2) * L_t * T_t * T_t_2) tilde_t_eq += eval_equation(Rational(1, 2) * L_t * T * T_2) tilde_t_eq = tilde_t_eq.expand() tilde_t_eq = evaluate_deltas(tilde_t_eq) tilde_t_eq = substitute_dummies(tilde_t_eq, **sub_kwargs) tilde_eq = Rational(1, 1) tilde_eq += eval_equation(-L * T) tilde_eq += eval_equation(L * T_t) tilde_eq += eval_equation(-L * T * T_t) tilde_eq += eval_equation(Rational(1, 2) * L * T * T_2) tilde_eq += eval_equation(Rational(1, 2) * L * T_t * T_t_2) tilde_eq = tilde_eq.expand() tilde_eq = evaluate_deltas(tilde_eq) tilde_eq = substitute_dummies(tilde_eq, **sub_kwargs) print(latex(tilde_t_eq)) print(latex(tilde_eq))
( "rho^{a}_{i} = ", ( symbols("p", below_fermi=True, cls=Dummy), symbols("q", above_fermi=True, cls=Dummy), ), ), ("rho^{j}_{i} = ", symbols("p, q", below_fermi=True, cls=Dummy)), ] for label, (p, q) in symbol_list: c_pq = Fd(p) * F(q) T = sum(get_ccsd_t_operators()) L = sum(get_ccsd_lambda_operators()) # Only keep non-zero terms rho_eq = eval_equation(c_pq) rho_eq += eval_equation(Commutator(c_pq, T)) rho_eq += eval_equation(L * c_pq) comm = Commutator(c_pq, T) rho_eq += eval_equation(L * comm) comm = Commutator(comm, sum(get_ccsd_t_operators())) rho_eq += Rational(1, 2) * eval_equation(L * comm) rho = rho_eq.expand() rho = evaluate_deltas(rho) rho = substitute_dummies(rho, **sub_kwargs) print(label + latex(rho))
def TPDM(L, R, flavor): display( Markdown( rf""" Computing TPDM for {flavor} (skipping summation for dummy variables)""" )) i, j, k, l = symbols('i,j,k,l', below_fermi=True) a, b, c, d = symbols('a,b,c,d', above_fermi=True) oooo = Fd(i) * Fd(j) * F(l) * F(k) cc = BCH.level(oooo, "SD") g_oooo = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) PermutList = [PermutationOperator(i,j),PermutationOperator(i,k), \ PermutationOperator(i,l),PermutationOperator(j,k), \ PermutationOperator(j,l),PermutationOperator(k,l)] g_oooo = simplify_index_permutations(g_oooo, PermutList) index_rule = {'below': 'mnop', 'above': 'abcde'} g_oooo = substitute_dummies(g_oooo, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{ijkl}') final_eq = Eq(gamma, g_oooo) display(final_eq) ooov = Fd(i) * Fd(j) * F(a) * F(k) cc = BCH.level(ooov, "SD") g_ooov = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) PermutList = [PermutationOperator(i,j),PermutationOperator(i,k), \ PermutationOperator(j,k)] g_ooov = simplify_index_permutations(g_ooov, PermutList) index_rule = {'below': 'lmnop', 'above': 'bcdef'} g_ooov = substitute_dummies(g_ooov, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{ijka}') final_eq = Eq(gamma, g_oo) display(final_eq) ooov = Fd(i) * Fd(a) * F(k) * F(j) cc = BCH.level(ooov, "SD") g_ovoo = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) PermutList = [PermutationOperator(i,j),PermutationOperator(i,k), \ PermutationOperator(j,k)] g_ovoo = simplify_index_permutations(g_ovoo, PermutList) index_rule = {'below': 'lmnop', 'above': 'bcdef'} g_ovoo = substitute_dummies(g_ovoo, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{iajk}') final_eq = Eq(gamma, g_ovoo) display(final_eq) ovov = Fd(i) * Fd(a) * F(b) * F(j) cc = BCH.level(ovov, "SD") g_ovov = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) PermutList = [PermutationOperator(i, j), PermutationOperator(a, b)] g_ovov = simplify_index_permutations(g_ovov, PermutList) index_rule = {'below': 'klmno', 'above': 'cdef'} g_ovov = substitute_dummies(g_ovov, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{iajb}') final_eq = Eq(gamma, g_ovov) display(final_eq) ovvv = Fd(i) * Fd(a) * F(c) * F(b) cc = BCH.level(ovvv, "SD") g_ovvv = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) PermutList = [PermutationOperator(a,b),PermutationOperator(a,c), \ PermutationOperator(b,c)] g_ovvv = simplify_index_permutations(g_ovvv, PermutList) index_rule = {'below': 'jklmn', 'above': 'defg'} g_ovvv = substitute_dummies(g_ovvv, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{iabc}') final_eq = Eq(gamma, g_ovvv) display(final_eq) oovv = Fd(i) * Fd(j) * F(b) * F(a) cc = BCH.level(oovv, "SD") g_oovv = evaluate_deltas(wicks(L * cc * R, keep_only_fully_contracted=True)) PermutList = [PermutationOperator(i, j), PermutationOperator(a, b)] g_oovv = simplify_index_permutations(g_oovv, PermutList) index_rule = {'below': 'klmn', 'above': 'cdefg'} g_oovv = substitute_dummies(g_oovv, new_indices=True, pretty_indices=index_rule) gamma = Symbol('\gamma_{ijab}') final_eq = Eq(gamma, g_oovv) display(final_eq)
def eval_equation(eq): eq = wicks(eq, **wicks_kwargs) eq = evaluate_deltas(eq.expand()) eq = substitute_dummies(eq, **sub_kwargs) return eq