Skip to content

Commit c16ff2b

Browse files
committed
flake 8 happy?
1 parent d0f9950 commit c16ff2b

File tree

8 files changed

+111
-168
lines changed

8 files changed

+111
-168
lines changed

adcc/backends/pyscf.py

Lines changed: 0 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,6 @@ def correlated_gradient(self, g1_ao, w_ao, g2_ao_1, g2_ao_2):
4848
Gradient["TEI"] = np.zeros((natoms, 3))
4949
Gradient["Total"] = np.zeros((natoms, 3))
5050

51-
# Iulia added variables; TODO: remove
52-
#ovlp_iulia = np.zeros((natoms, 3))
53-
#hcore_iulia = np.zeros((natoms, 3))
54-
#eri_iulia = np.zeros((natoms, 3))
55-
5651
# TODO: does RHF/UHF matter here?
5752
gradient = grad.RHF(self.scfres)
5853
hcore_deriv = gradient.hcore_generator()
@@ -71,13 +66,10 @@ def correlated_gradient(self, g1_ao, w_ao, g2_ao_1, g2_ao_2):
7166
Sx_a[:, k0:k1] = Sx[:, k0:k1]
7267
Sx_a += Sx_a.transpose(0, 2, 1)
7368
Gradient["S"][ia] += np.einsum("xpq,pq->x", Sx_a, w_ao)
74-
#ovlp_iulia[ia] += np.einsum("xpq,pq->x", Sx_a, w_ao)
75-
7669

7770
# derivative of the core Hamiltonian
7871
Hx_a = hcore_deriv(ia)
7972
Gradient["T+V"][ia] += np.einsum("xpq,pq->x", Hx_a, g1_ao)
80-
#hcore_iulia[ia] += np.einsum("xpq,pq->x", Hx_a, g1_ao)
8173

8274
# derivatives of the ERIs
8375
ERIx_a = np.zeros_like(ERIx)
@@ -93,23 +85,6 @@ def correlated_gradient(self, g1_ao, w_ao, g2_ao_1, g2_ao_2):
9385
Gradient["TEI"][ia] -= np.einsum(
9486
"pqrs,xpsqr->x", g2_ao_2, ERIx_a, optimize=True
9587
)
96-
#eri_iulia[ia] += (
97-
# np.einsum("pqrs,xprqs->x", g2_ao_1, ERIx_a, optimize=True)
98-
# - np.einsum("pqrs,xpsqr->x", g2_ao_2, ERIx_a, optimize=True)
99-
#)
100-
101-
102-
# Iulia print TODO:remove
103-
#print("2PDM_1 in AO:\n", g2_ao_1)
104-
#print("Hcore contribution to the gradient:")
105-
#print(hcore_iulia)
106-
#print()
107-
#print("Overlp contribution to the gradient:")
108-
#print(ovlp_iulia)
109-
#print()
110-
#print("ERI contribution to the gradient:")
111-
#print(eri_iulia)
112-
#print()
11388

11489
Gradient["N"] = gradient.grad_nuc()
11590
Gradient["OEI"] = Gradient["T+V"] + Gradient["S"]

adcc/gradients/TwoParticleDensityMatrix.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ def __init__(self, spaces):
6262
b.cccc, b.ococ, b.oooo, b.cvcv,
6363
b.ocov, b.cccv, b.cocv, b.ocoo,
6464
b.ccco, b.occv, b.ccvv, b.ocvv,
65-
b.vvvv,
65+
b.vvvv,
6666
]
6767
self._tensors = {}
6868

adcc/gradients/__init__.py

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -63,13 +63,13 @@ def nuclear_gradient(excitation_or_mp):
6363

6464
with timer.record("orbital_response"):
6565
rhs = orbital_response_rhs(hf, g1a, g2a).evaluate()
66-
l = orbital_response(hf, rhs)
66+
lam = orbital_response(hf, rhs)
6767

6868
# orbital-relaxed OPDM (without reference state)
6969
g1o = g1a.copy()
70-
g1o.ov = 0.5 * l.ov
70+
g1o.ov = 0.5 * lam.ov
7171
if hf.has_core_occupied_space:
72-
g1o.cv = 0.5 * l.cv
72+
g1o.cv = 0.5 * lam.cv
7373
# orbital-relaxed OPDM (including reference state)
7474
g1 = g1o.copy()
7575
g1 += hf.density
@@ -84,48 +84,48 @@ def nuclear_gradient(excitation_or_mp):
8484
delta_IJ = hf.density.cc
8585
g2_hf = TwoParticleDensityMatrix(hf)
8686

87-
g2_hf.oooo = -0.25 * ( einsum("ik,jl->ijkl", delta_ij, delta_ij))
88-
g2_hf.cccc = -0.5 * ( einsum("IK,JL->IJKL", delta_IJ, delta_IJ))
89-
g2_hf.ococ = -1.0 * ( einsum("ik,JL->iJkL", delta_ij, delta_IJ))
87+
g2_hf.oooo = -0.25 * einsum("ik,jl->ijkl", delta_ij, delta_ij)
88+
g2_hf.cccc = -0.5 * einsum("IK,JL->IJKL", delta_IJ, delta_IJ)
89+
g2_hf.ococ = -1.0 * einsum("ik,JL->iJkL", delta_ij, delta_IJ)
9090

9191
g2_oresp = TwoParticleDensityMatrix(hf)
92-
g2_oresp.cccc = einsum("IK,JL->IJKL", delta_IJ, g1o.cc+delta_IJ)
93-
g2_oresp.ococ = (
94-
einsum("ik,JL->iJkL", delta_ij, g1o.cc+2*delta_IJ)
92+
g2_oresp.cccc = einsum("IK,JL->IJKL", delta_IJ, g1o.cc + delta_IJ)
93+
g2_oresp.ococ = (
94+
+ einsum("ik,JL->iJkL", delta_ij, g1o.cc + 2.0 * delta_IJ)
9595
+ einsum("ik,JL->iJkL", g1o.oo, delta_IJ)
9696
)
9797
g2_oresp.oooo = 0.25 * (
98-
einsum("ik,jl->ijkl", delta_ij, g1o.oo+delta_ij)
98+
einsum("ik,jl->ijkl", delta_ij, g1o.oo + delta_ij)
9999
)
100100
g2_oresp.ovov = einsum("ij,ab->iajb", delta_ij, g1o.vv)
101101
g2_oresp.cvcv = einsum("IJ,ab->IaJb", delta_IJ, g1o.vv)
102-
g2_oresp.ocov = 2*einsum("ik,Ja->iJka", delta_ij, g1o.cv)
103-
g2_oresp.cccv = 2*einsum("IK,Ja->IJKa", delta_IJ, g1o.cv)
104-
g2_oresp.ooov = 2*einsum("ik,ja->ijka", delta_ij, g1o.ov)
105-
g2_oresp.cocv = 2*einsum("IK,ja->IjKa", delta_IJ, g1o.ov)
106-
g2_oresp.ocoo = 2*einsum("ik,Jl->iJkl", delta_ij, g1o.co)
107-
g2_oresp.ccco = 2*einsum("IK,Jl->IJKl", delta_IJ, g1o.co)
102+
g2_oresp.ocov = 2 * einsum("ik,Ja->iJka", delta_ij, g1o.cv)
103+
g2_oresp.cccv = 2 * einsum("IK,Ja->IJKa", delta_IJ, g1o.cv)
104+
g2_oresp.ooov = 2 * einsum("ik,ja->ijka", delta_ij, g1o.ov)
105+
g2_oresp.cocv = 2 * einsum("IK,ja->IjKa", delta_IJ, g1o.ov)
106+
g2_oresp.ocoo = 2 * einsum("ik,Jl->iJkl", delta_ij, g1o.co)
107+
g2_oresp.ccco = 2 * einsum("IK,Jl->IJKl", delta_IJ, g1o.co)
108108

109109
# scale for contraction with integrals
110110
g2a.oovv *= 0.5
111111
g2a.ccvv *= 0.5
112112
g2a.occv *= 2.0
113-
g2a.vvvv *= 0.25 # Scaling twice!
114-
g2a.vvvv *= 0.25 # it's the only way it works...
113+
g2a.vvvv *= 0.25 # Scaling twice!
114+
g2a.vvvv *= 0.25 # it's the only way it works...
115115

116116
g2_total = evaluate(g2_hf + g2a + g2_oresp)
117117
else:
118118
delta_ij = hf.density.oo
119119
g2_hf = TwoParticleDensityMatrix(hf)
120120
g2_hf.oooo = 0.25 * (- einsum("li,jk->ijkl", delta_ij, delta_ij)
121121
+ einsum("ki,jl->ijkl", delta_ij, delta_ij))
122-
122+
123123
g2_oresp = TwoParticleDensityMatrix(hf)
124124
g2_oresp.oooo = einsum("ij,kl->kilj", delta_ij, g1o.oo)
125125
g2_oresp.ovov = einsum("ij,ab->iajb", delta_ij, g1o.vv)
126126
g2_oresp.ooov = (- einsum("kj,ia->ijka", delta_ij, g1o.ov)
127127
+ einsum("ki,ja->ijka", delta_ij, g1o.ov))
128-
128+
129129
# scale for contraction with integrals
130130
g2a.oovv *= 0.5
131131
g2_total = evaluate(g2_hf + g2a + g2_oresp)

adcc/gradients/amplitude_response.py

Lines changed: 25 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -54,17 +54,14 @@ def t2bar_oovv_adc2(exci, g1a_adc0):
5454
)
5555
return t2bar
5656

57+
5758
def t2bar_oovv_cvs_adc2(exci, g1a_adc0):
5859
mp = exci.ground_state
5960
hf = mp.reference_state
60-
u = exci.excitation_vector
6161
df_ia = mp.df(b.ov)
62-
t2bar = 0.5*(
62+
t2bar = 0.5 * (
6363
- einsum("ijcb,ac->ijab", hf.oovv, g1a_adc0.vv).antisymmetrise((2, 3))
64-
) / (
65-
direct_sum("ia+jb->ijab", df_ia, df_ia).symmetrise((0, 1))
66-
)
67-
64+
) / direct_sum("ia+jb->ijab", df_ia, df_ia).symmetrise((0, 1))
6865
return t2bar
6966

7067

@@ -78,6 +75,7 @@ def ampl_relaxed_dms_adc1(exci):
7875
g2a.ovov = - 1.0 * einsum("ja,ib->iajb", u.ph, u.ph)
7976
return g1a, g2a
8077

78+
8179
def ampl_relaxed_dms_adc0(exci):
8280
hf = exci.reference_state
8381
u = exci.excitation_vector
@@ -89,6 +87,7 @@ def ampl_relaxed_dms_adc0(exci):
8987
g1a.vv = + 1.0 * einsum("ia,ib->ab", u.ph, u.ph)
9088
return g1a, g2a
9189

90+
9291
def ampl_relaxed_dms_cvs_adc0(exci):
9392
hf = exci.reference_state
9493
u = exci.excitation_vector
@@ -100,6 +99,7 @@ def ampl_relaxed_dms_cvs_adc0(exci):
10099
g1a.vv = + 1.0 * einsum("Ia,Ib->ab", u.ph, u.ph)
101100
return g1a, g2a
102101

102+
103103
def ampl_relaxed_dms_cvs_adc1(exci):
104104
hf = exci.reference_state
105105
u = exci.excitation_vector
@@ -118,6 +118,7 @@ def ampl_relaxed_dms_cvs_adc1(exci):
118118
g1a.co = - 1.0 * einsum('JbKc,ibKc->Ji', g2a.cvcv, hf.ovcv) / fco
119119
return g1a, g2a
120120

121+
121122
def ampl_relaxed_dms_cvs_adc2(exci):
122123
hf = exci.reference_state
123124
mp = exci.ground_state
@@ -139,10 +140,9 @@ def ampl_relaxed_dms_cvs_adc2(exci):
139140
- 0.5 * einsum('kIab,kJab->IJ', t2ocvv, t2ocvv)
140141
)
141142

142-
g1a.oo = (
143+
g1a.oo = (
143144
- 1.0 * einsum("jKba,iKba->ij", u.pphh, u.pphh)
144145
- 2.0 * einsum("ikab,jkab->ij", t2bar, t2oovv).symmetrise((0, 1))
145-
#- 1.0 * einsum('jkab,ikab->ij', t2oovv, t2bar)
146146
- 0.5 * einsum('iKab,jKab->ij', t2ocvv, t2ocvv)
147147
- 0.5 * einsum('ikab,jkab->ij', t2oovv, t2oovv)
148148
)
@@ -157,7 +157,6 @@ def ampl_relaxed_dms_cvs_adc2(exci):
157157
+ 1.0 * einsum("Ia,Ib->ab", u.ph, u.ph)
158158
+ 2.0 * einsum('jIcb,jIca->ab', u.pphh, u.pphh)
159159
+ 2.0 * einsum('ijac,ijbc->ab', t2bar, t2oovv).symmetrise((0, 1))
160-
#+ 1.0 * einsum('ijbc,ijac->ab', t2bar, t2oovv)
161160
+ 0.5 * einsum('IJac,IJbc->ab', t2ccvv, t2ccvv)
162161
+ 0.5 * einsum('ijac,ijbc->ab', t2oovv, t2oovv)
163162
+ 1.0 * einsum('iJac,iJbc->ab', t2ocvv, t2ocvv)
@@ -169,32 +168,29 @@ def ampl_relaxed_dms_cvs_adc2(exci):
169168

170169
# The factor 1/sqrt(2) is needed because of the scaling used in adcc
171170
# for the ph-pphh blocks.
172-
g2a.occv = (1 / sqrt(2)) * (
173-
2.0 * einsum('Ib,kJba->kJIa', u.ph, u.pphh)
174-
#- einsum('Ib,kJab->kJIa', u.ph, u.pphh)
171+
g2a.occv = (1 / sqrt(2)) * (
172+
2.0 * einsum('Ib,kJba->kJIa', u.ph, u.pphh)
175173
)
176174

177175
g2a.oovv = (
178176
+ 1.0 * einsum('ijcb,ca->ijab', t2oovv, g1a_cvs0.vv).antisymmetrise((2, 3))
179-
#- 0.5 * einsum('ijca,cb->ijab', t2oovv, g1a_cvs0.vv)
180177
- 1.0 * t2oovv
181178
- 2.0 * t2bar
182179
)
183180

184181
# The factor 2/sqrt(2) is necessary because of the way
185182
# that the ph-pphh is scaled.
186-
g2a.ovvv = (2 / sqrt(2) ) * (
183+
g2a.ovvv = (2 / sqrt(2)) * (
187184
einsum('Ja,iJcb->iabc', u.ph, u.pphh)
188185
)
189-
190-
g2a.ccvv = -t2ccvv
191-
192-
g2a.ocvv = -t2ocvv
186+
187+
g2a.ccvv = - 1.0 * t2ccvv
188+
g2a.ocvv = - 1.0 * t2ocvv
193189

194190
# This is the OC block of the orbital response
195191
# Lagrange multipliers (lambda):
196192
g1a.co = (
197-
- 1.0 * einsum('JbKc,ibKc->Ji', g2a.cvcv, hf.ovcv)
193+
- 1.0 * einsum('JbKc,ibKc->Ji', g2a.cvcv, hf.ovcv)
198194
- 0.5 * einsum('JKab,iKab->Ji', g2a.ccvv, hf.ocvv)
199195
+ 1.0 * einsum('kJLa,ikLa->Ji', g2a.occv, hf.oocv)
200196
+ 0.5 * einsum('kJab,ikab->Ji', g2a.ocvv, hf.oovv)
@@ -205,9 +201,9 @@ def ampl_relaxed_dms_cvs_adc2(exci):
205201
+ 0.5 * einsum('iabc,Jabc->Ji', g2a.ovvv, hf.cvvv)
206202
) / fco
207203

208-
209204
return g1a, g2a
210205

206+
211207
def ampl_relaxed_dms_cvs_adc2x(exci):
212208
hf = exci.reference_state
213209
mp = exci.ground_state
@@ -229,10 +225,9 @@ def ampl_relaxed_dms_cvs_adc2x(exci):
229225
- 0.5 * einsum('kIab,kJab->IJ', t2ocvv, t2ocvv)
230226
)
231227

232-
g1a.oo = (
228+
g1a.oo = (
233229
- 1.0 * einsum("jKba,iKba->ij", u.pphh, u.pphh)
234230
- 2.0 * einsum("ikab,jkab->ij", t2bar, t2oovv).symmetrise((0, 1))
235-
#- 1.0 * einsum('jkab,ikab->ij', t2oovv, t2bar) # use symmetrize?
236231
- 0.5 * einsum('iKab,jKab->ij', t2ocvv, t2ocvv)
237232
- 0.5 * einsum('ikab,jkab->ij', t2oovv, t2oovv)
238233
)
@@ -247,7 +242,6 @@ def ampl_relaxed_dms_cvs_adc2x(exci):
247242
+ 1.0 * einsum("Ia,Ib->ab", u.ph, u.ph)
248243
+ 2.0 * einsum('jIcb,jIca->ab', u.pphh, u.pphh)
249244
+ 2.0 * einsum('ijac,ijbc->ab', t2bar, t2oovv).symmetrise((0, 1))
250-
#+ 1.0 * einsum('ijbc,ijac->ab', t2bar, t2oovv)
251245
+ 0.5 * einsum('IJac,IJbc->ab', t2ccvv, t2ccvv)
252246
+ 0.5 * einsum('ijac,ijbc->ab', t2oovv, t2oovv)
253247
+ 1.0 * einsum('iJac,iJbc->ab', t2ocvv, t2ocvv)
@@ -256,49 +250,39 @@ def ampl_relaxed_dms_cvs_adc2x(exci):
256250
g2a.cvcv = (
257251
- 1.0 * einsum("Ja,Ib->IaJb", u.ph, u.ph)
258252
- 1.0 * einsum('kIbc,kJac->IaJb', u.pphh, u.pphh)
259-
#- 0.5 * einsum('kIcb,kJca->IaJb', u.pphh, u.pphh)
260253
+ 1.0 * einsum('kIcb,kJac->IaJb', u.pphh, u.pphh)
261-
#+ 0.5 * einsum('kIbc,kJca->IaJb', u.pphh, u.pphh)
262254
)
263255

264256
# The factor 1/sqrt(2) is needed because of the scaling used in adcc
265257
# for the ph-pphh blocks.
266-
g2a.occv = (1 / sqrt(2)) * (
267-
2.0 * einsum('Ib,kJba->kJIa', u.ph, u.pphh)
268-
#- einsum('Ib,kJab->kJIa', u.ph, u.pphh)
258+
g2a.occv = (1 / sqrt(2)) * (
259+
2.0 * einsum('Ib,kJba->kJIa', u.ph, u.pphh)
269260
)
270261

271262
g2a.oovv = (
272263
+ 1.0 * einsum('ijcb,ca->ijab', t2oovv, g1a_cvs0.vv).antisymmetrise((2, 3))
273-
#- 0.5 * einsum('ijca,cb->ijab', t2oovv, g1a_cvs0.vv)
274264
- 1.0 * t2oovv
275265
- 2.0 * t2bar
276266
)
277267

278-
# The factor 2/sqrt(2) is necessary because of
268+
# The factor 2/sqrt(2) is necessary because of
279269
# the way that the ph-pphh is scaled
280270
g2a.ovvv = (2 / sqrt(2)) * (
281271
einsum('Ja,iJcb->iabc', u.ph, u.pphh)
282272
)
283273

284274
g2a.ovov = 1.0 * (
285275
- einsum("iKbc,jKac->iajb", u.pphh, u.pphh)
286-
#- einsum("iKcb,jKca->iajb", u.pphh, u.pphh)
287276
+ einsum("iKcb,jKac->iajb", u.pphh, u.pphh)
288-
#+ einsum("iKbc,jKca->iajb", u.pphh, u.pphh)
289277
)
290-
291-
g2a.ccvv = -t2ccvv
292-
293-
g2a.ocvv = -t2ocvv
294278

279+
g2a.ccvv = - 1.0 * t2ccvv
280+
g2a.ocvv = - 1.0 * t2ocvv
295281
g2a.ococ = 1.0 * einsum("iJab,kLab->iJkL", u.pphh, u.pphh)
296-
297282
g2a.vvvv = 2.0 * einsum("iJcd,iJab->abcd", u.pphh, u.pphh)
298283

299-
# These are the OC multipliers:
300284
g1a.co = (
301-
- 1.0 * einsum('JbKc,ibKc->Ji', g2a.cvcv, hf.ovcv)
285+
- 1.0 * einsum('JbKc,ibKc->Ji', g2a.cvcv, hf.ovcv)
302286
- 0.5 * einsum('JKab,iKab->Ji', g2a.ccvv, hf.ocvv)
303287
+ 1.0 * einsum('kJLa,ikLa->Ji', g2a.occv, hf.oocv)
304288
+ 0.5 * einsum('kJab,ikab->Ji', g2a.ocvv, hf.oovv)
@@ -307,7 +291,7 @@ def ampl_relaxed_dms_cvs_adc2x(exci):
307291
+ 0.5 * einsum('iKab,JKab->Ji', g2a.ocvv, hf.ccvv)
308292
- 0.5 * einsum('ikab,kJab->Ji', g2a.oovv, hf.ocvv)
309293
+ 0.5 * einsum('iabc,Jabc->Ji', g2a.ovvv, hf.cvvv)
310-
+ 1.0 * einsum('kJmL,ikmL->Ji', g2a.ococ, hf.oooc)
294+
+ 1.0 * einsum('kJmL,ikmL->Ji', g2a.ococ, hf.oooc)
311295
- 1.0 * einsum('iKlM,JKMl->Ji', g2a.ococ, hf.ccco)
312296
+ 1.0 * einsum('iakb,kbJa->Ji', g2a.ovov, hf.ovcv)
313297
) / fco
@@ -369,7 +353,7 @@ def ampl_relaxed_dms_mp2(mp):
369353
"cvs-adc0": ampl_relaxed_dms_cvs_adc0,
370354
"cvs-adc1": ampl_relaxed_dms_cvs_adc1,
371355
"cvs-adc2": ampl_relaxed_dms_cvs_adc2,
372-
"cvs-adc2x": ampl_relaxed_dms_cvs_adc2x,
356+
"cvs-adc2x": ampl_relaxed_dms_cvs_adc2x,
373357
}
374358

375359

0 commit comments

Comments
 (0)