Skip to content

Commit 06ee1b2

Browse files
committed
fix cvs-adc2x gradients
1 parent 0cbc490 commit 06ee1b2

File tree

6 files changed

+545
-485
lines changed

6 files changed

+545
-485
lines changed

adcc/gradients/TwoParticleDensityMatrix.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,11 +58,12 @@ def __init__(self, spaces):
5858
]
5959
if self.mospaces.has_core_occupied_space:
6060
self.blocks += [
61-
b.cccc, b.ococ, b.oooo, b.cvcv,
61+
b.cccc, b.ococ, b.cvcv,
6262
b.ocov, b.cccv, b.cocv, b.ocoo,
6363
b.ccco, b.occv, b.ccvv, b.ocvv,
64-
b.vvvv,
6564
]
65+
# make sure we didn't add any block twice!
66+
assert len(list(set(self.blocks))) == len(self.blocks)
6667
self._tensors = {}
6768

6869
@property
@@ -223,7 +224,7 @@ def to_ao_basis(self, refstate_or_coefficients=None):
223224
if not hasattr(self, "reference_state"):
224225
raise ValueError("Argument reference_state is required if no "
225226
"reference_state is stored in the "
226-
"OneParticleOperator")
227+
"TwoParticleDensityMatrix")
227228
return self.__transform_to_ao(self.reference_state)
228229
else:
229230
raise TypeError("Argument type not supported.")

adcc/gradients/__init__.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,8 @@ def nuclear_gradient(excitation_or_mp):
159159
if hf.has_core_occupied_space:
160160
delta_IJ = hf.density.cc
161161

162-
g2_hf.oooo = -0.25 * einsum("ik,jl->ijkl", delta_ij, delta_ij)
162+
g2_hf.oooo = 0.25 * (- einsum("li,jk->ijkl", delta_ij, delta_ij)
163+
+ einsum("ki,jl->ijkl", delta_ij, delta_ij))
163164
g2_hf.cccc = -0.5 * einsum("IK,JL->IJKL", delta_IJ, delta_IJ)
164165
g2_hf.ococ = -1.0 * einsum("ik,JL->iJkL", delta_ij, delta_IJ)
165166

@@ -168,9 +169,7 @@ def nuclear_gradient(excitation_or_mp):
168169
+ einsum("ik,JL->iJkL", delta_ij, g1o.cc + 2.0 * delta_IJ)
169170
+ einsum("ik,JL->iJkL", g1o.oo, delta_IJ)
170171
)
171-
g2_oresp.oooo = 0.25 * (
172-
einsum("ik,jl->ijkl", delta_ij, g1o.oo + delta_ij)
173-
)
172+
g2_oresp.oooo = einsum("ij,kl->kilj", delta_ij, g1o.oo)
174173
g2_oresp.ovov = einsum("ij,ab->iajb", delta_ij, g1o.vv)
175174
g2_oresp.cvcv = einsum("IJ,ab->IaJb", delta_IJ, g1o.vv)
176175
g2_oresp.ocov = 2 * einsum("ik,Ja->iJka", delta_ij, g1o.cv)

adcc/gradients/amplitude_response.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -642,11 +642,8 @@ def ampl_relaxed_dms_cvs_adc2x(exci):
642642
g2a.ccvv = - 1.0 * t2ccvv
643643
g2a.ocvv = - 1.0 * t2ocvv
644644
g2a.ococ = 1.0 * einsum("iJab,kLab->iJkL", u.pphh, u.pphh)
645-
g2a.vvvv = 1.0 * einsum("iJcd,iJab->abcd", u.pphh, u.pphh)
645+
g2a.vvvv = 2.0 * einsum("iJcd,iJab->abcd", u.pphh, u.pphh)
646646

647-
# TODO: remove
648-
# g2a.ococ *= 0.0
649-
# g2a.vvvv *= 0.0
650647

651648
g1a.co = (
652649
- 1.0 * einsum('JbKc,ibKc->Ji', g2a.cvcv, hf.ovcv)

adcc/gradients/orbital_response.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,6 @@ def orbital_response_rhs(hf, g1a, g2a):
3333
response given amplitude-relaxed density matrices (method-specific)
3434
"""
3535
# TODO: only add non-zero blocks to equations!
36-
3736
if hf.has_core_occupied_space:
3837
ret_ov = -1.0 * (
3938
+ 2.0 * einsum("JiKa,JK->ia", hf.cocv, g1a.cc)
@@ -78,7 +77,7 @@ def orbital_response_rhs(hf, g1a, g2a):
7877
+ 2.0 * einsum('kJIb,kJab->Ia', g2a.occv, hf.ocvv)
7978
- 1.0 * einsum('abcd,Ibcd->Ia', g2a.vvvv, hf.cvvv) # cvs-adc2x
8079
- 2.0 * einsum('jakb,jIkb->Ia', g2a.ovov, hf.ocov) # cvs-adc2x
81-
- 2.0 * einsum('jIlK,lKja->Ia', g2a.ococ, hf.ocov) # cvs-adc2x
80+
+ 2.0 * einsum('jIlK,lKja->Ia', g2a.ococ, hf.ocov) # cvs-adc2x
8281
)
8382
ret = AmplitudeVector(cv=ret_cv, ov=ret_ov)
8483
else:
@@ -112,7 +111,6 @@ def orbital_response_rhs(hf, g1a, g2a):
112111

113112
def energy_weighted_density_matrix(hf, g1o, g2a):
114113
if hf.has_core_occupied_space:
115-
# CVS-ADC0, CVS-ADC1, CVS-ADC2
116114
w = OneParticleOperator(hf)
117115
w.cc = - 0.5 * (
118116
+ einsum("JKab,IKab->IJ", g2a.ccvv, hf.ccvv)
@@ -295,13 +293,6 @@ def __matmul__(self, lam):
295293
ret = AmplitudeVector(cv=ret_cv, ov=ret_ov)
296294
else:
297295
ret = AmplitudeVector(ov=ret_ov)
298-
# TODO: generalize once other solvent methods are available
299-
if self.hf.environment == "pe":
300-
# PE contribution to the orbital Hessian
301-
ops = self.hf.operators
302-
dm = OneParticleOperator(self.hf, is_symmetric=True)
303-
dm.ov = lam.ov
304-
ret += ops.pe_induction_elec(dm).ov
305296
return evaluate(ret)
306297

307298

adcc/testdata/dump_fdiff_gradient.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,6 @@
3636

3737
prefactors_5p = np.array([1.0, -8.0, 8.0, -1.0]) / 12.0
3838
multipliers_5p = [-2, -1, 1, 2]
39-
# prefactors_9p = [1. / 280., -4. / 105., 1. / 5., -4. / 5.,
40-
# 4. / 5., -1. / 5., 4. / 105., -1. / 280.]
41-
# multipliers_9p = [-4., -3., - 2., -1., 1., 2., 3., 4.]
4239

4340

4441
@dataclass
@@ -137,7 +134,7 @@ def main():
137134
"cvs-adc0",
138135
"cvs-adc1",
139136
"cvs-adc2",
140-
# "cvs-adc2x", # TODO: broken
137+
"cvs-adc2x",
141138
]
142139
molnames = [
143140
"h2o",

0 commit comments

Comments
 (0)