MPQC  3.0.0-alpha
sr_r12intermediates_VXB_diag.h
1 //
2 // sr_r12intermediates_VXB_diag.h
3 //
4 // Copyright (C) 2013 Edward Valeev
5 //
6 // Author: Edward Valeev <evaleev@vt.edu>
7 // Maintainer: EV
8 //
9 // This file is part of the SC Toolkit.
10 //
11 // The SC Toolkit is free software; you can redistribute it and/or modify
12 // it under the terms of the GNU Library General Public License as published by
13 // the Free Software Foundation; either version 2, or (at your option)
14 // any later version.
15 //
16 // The SC Toolkit is distributed in the hope that it will be useful,
17 // but WITHOUT ANY WARRANTY; without even the implied warranty of
18 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 // GNU Library General Public License for more details.
20 //
21 // You should have received a copy of the GNU Library General Public License
22 // along with the SC Toolkit; see the file COPYING.LIB. If not, write to
23 // the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
24 //
25 // The U.S. Government is granted a limited license as per AL 91-7.
26 //
27 
28 #ifndef _mpqc_src_lib_chemistry_qc_mbptr12_srr12intermediatesVXBdiag_h
29 #define _mpqc_src_lib_chemistry_qc_mbptr12_srr12intermediatesVXBdiag_h
30 
31 #include <tiledarray.h>
32 #include <cmath>
33 
34 namespace sc {
35  inline double get_element(const TA::TArrayD& array, const std::vector<std::size_t>& ele_idx)
36  {
37  const std::vector<std::size_t> tile_idx = array.trange().element_to_tile(ele_idx);
38  return (array.find(tile_idx).get()[ele_idx]);
39  }
40 
41  template <typename T>
43  SingleReference_R12Intermediates<T>::XaiAddToXam(const TA::Array<double, 2 >& Xam,
44  const TA::Array<double, 2 >& Xai) {
45 // MPQC_ASSERT(Xam.size() == 1);
46 //
47 // typename TArray2::value_type tile_X =
48 // static_cast<const typename TArray2::value_type&>(Xam.find(0)).clone();
49 // typename TArray2::value_type tile_Xai = Xai.find(0);
50 // const std::size_t zero_cols = tile_X.range().extent()[1] - tile_Xai.range().extent()[1];
51 //
52 // std::array<std::size_t, 2> i = {{0, 0}};
53 // std::size_t ix = 0;
54 // for(i[0] = tile_X.range().lobound()[0];
55 // i[0] < tile_X.range().upbound()[0]; ++i[0]) {
56 // for(i[1] = zero_cols + tile_X.range().lobound()[1];
57 // i[1] < tile_X.range().upbound()[1]; ++i[1], ++ix) {
58 // tile_X[i] += tile_Xai[ix];
59 // }
60 // }
61 //
62 // TArray2 X(Xam.world(), Xam.trange());
63 // X.set(0, tile_X);
64  TArray2 X;
65  X("a,m") = Xam("a,m") + Xai("a,i") * _2("<i|I|m>");
66  return X;
67  }
68 
69  // compute F^A'_C' R^Pk_A'B' R^Qk_C'B' (P & Q in alpha or beta space)
70  template <typename T>
72  SingleReference_R12Intermediates<T>::BPk_Qk(const char* p, const char* q,
73  const double C_0, const double C_1) {
74 
75  const double B_C1 = 0.5 * C_0 * C_0 + 1.5 * C_1 * C_1;
76  const double B_C2 = 0.5 * C_0 * C_0 - 1.5 * C_1 * C_1;
77 
78  std::string rTr_pkql = std::string("<") + p + " k|rTr|" + q + " l>";
79  std::string rTr_kpql = std::string("<k ") + p + "|rTr|" + q + " l>";
80 
81  std::string r2_phJk_ql = std::string("<") + p + "_hJ(p') k|r2|" + q + " l>";
82  std::string r2_pkhJ_ql = std::string("<") + p + " k_hJ(p')|r2|" + q + " l>";
83  //
84  std::string r2_kphJ_ql = std::string("<k ") + p + "_hJ(p')|r2|" + q + " l>";
85  std::string r2_khJp_ql = std::string("<k_hJ(p') ") + p + "|r2|" + q + " l>";
86  //
87  std::string r2_pk_qhJl = std::string("<") + p + " k|r2|" + q + "_hJ(p') l>";
88  std::string r2_pk_qlhJ = std::string("<") + p + " k|r2|" + q + " l_hJ(p')>";
89  //
90  std::string r2_pk_lqhJ = std::string("<") + p + " k|r2|l " + q + "_hJ(p')>";
91  std::string r2_pk_lhJq = std::string("<") + p + " k|r2|l_hJ(p') " + q + ">";
92 
93  std::string pk_PQ = std::string("<") + p + " k|r|p' q'>";
94  std::string kp_PQ = std::string("<k ") + p + "|r|p' q'>";
95  std::string qk_PKQ = std::string("<") + q + " k|r|p'_K(r') q'>";
96  std::string kq_PKQ = std::string("<k ") + q + "|r|p'_K(r') q'>";
97 
98  std::string pk_Pn = std::string("<") + p + " k|r|p' n>";
99  std::string kp_Pn = std::string("<k ") + p + "|r|p' n>";
100  std::string qk_PFn = std::string("<") + q + " k|r|p'_F(r') n>";
101  std::string kq_PFn = std::string("<k ") + q + "|r|p'_F(r') n>";
102 
103  std::string pk_mA = std::string("<") + p + " k|r|m a'>";
104  std::string kp_mA = std::string("<k ") + p + "|r|m a'>";
105  std::string qk_mFA = std::string("<") + q + " k|r|m_F(n) a'>";
106  std::string kq_mFA = std::string("<k ") + q + "|r|m_F(n) a'>";
107 
108  std::string pk_pq = std::string("<") + p + " k|r|p b>";
109  std::string kp_pq = std::string("<k ") + p + "|r|p b>";
110  std::string qk_pFb = std::string("<") + q + " k|r|p_F(r) b>";
111  std::string kq_pFb = std::string("<k ") + q + "|r|p_F(r) b>";
112 
113  std::string qk_mFPA = std::string("<") + q + " k|r|m_F(p') a'>";
114  std::string kq_mFPA = std::string("<k ") + q + "|r|m_F(p') a'>";
115  //
116  std::string qk_mA = std::string("<") + q + " k|r|m a'>";
117  std::string kq_mA = std::string("<k ") + q + "|r|m a'>";
118  std::string pk_mFPA = std::string("<") + p + " k|r|m_F(p') a'>";
119  std::string kp_mFPA = std::string("<k ") + p + "|r|m_F(p') a'>";
120 
121  std::string pk_Ab = std::string("<") + p + " k|r|a' b>";
122  std::string kp_Ab = std::string("<k ") + p + "|r|a' b>";
123  std::string qk_AFb = std::string("<") + q + " k|r|a'_F(q) b>";
124  std::string kq_AFb = std::string("<k ") + q + "|r|a'_F(q) b>";
125  //
126  std::string qk_Ab = std::string("<") + q + " k|r|a' b>";
127  std::string kq_Ab = std::string("<k ") + q + "|r|a' b>";
128  std::string pk_AFb = std::string("<") + p + " k|r|a'_F(q) b>";
129  std::string kp_AFb = std::string("<k ") + p + "|r|a'_F(q) b>";
130 
131  std::string pq = p + std::string(",") + q;
132 
133  TArray2 B_pq;
134  B_pq(pq.c_str()) =
135  // diag
136  ( B_C1 * _4(rTr_pkql.c_str()) + B_C2 * _4(rTr_kpql.c_str())
137  // Q
138  + 0.5 * (
139  B_C1 * (_4(r2_phJk_ql.c_str()) + _4(r2_pkhJ_ql.c_str()))
140  + B_C2 * (_4(r2_kphJ_ql.c_str()) + _4(r2_khJp_ql.c_str()))
141 
142  + B_C1 * (_4(r2_pk_qhJl.c_str()) + _4(r2_pk_qlhJ.c_str()))
143  + B_C2 * (_4(r2_pk_lqhJ.c_str()) + _4(r2_pk_lhJq.c_str()))
144  )
145  ) * _2("<k|I|l>")
146  // rKr_p'q'
147  - ( B_C1 * (_4(pk_PQ.c_str()) * _4(qk_PKQ.c_str())
148  + _4(kp_PQ.c_str()) * _4(kq_PKQ.c_str()))
149  + B_C2 * (_4(kp_PQ.c_str()) * _4(qk_PKQ.c_str())
150  + _4(pk_PQ.c_str()) * _4(kq_PKQ.c_str()))
151  )
152  // rFr_p'n
153  - ( B_C1 * (_4(pk_Pn.c_str()) * _4(qk_PFn.c_str())
154  + _4(kp_Pn.c_str()) * _4(kq_PFn.c_str()))
155  + B_C2 * (_4(kp_Pn.c_str()) * _4(qk_PFn.c_str())
156  + _4(pk_Pn.c_str()) * _4(kq_PFn.c_str()))
157  )
158  // rFr_mA
159  + ( B_C1 * (_4(pk_mA.c_str()) * _4(qk_mFA.c_str())
160  + _4(kp_mA.c_str()) * _4(kq_mFA.c_str()))
161  + B_C2 * (_4(kp_mA.c_str()) * _4(qk_mFA.c_str())
162  + _4(pk_mA.c_str()) * _4(kq_mFA.c_str()))
163  )
164  // rFr_pb
165  - ( B_C1 * (_4(pk_pq.c_str()) * _4(qk_pFb.c_str())
166  + _4(kp_pq.c_str()) * _4(kq_pFb.c_str()))
167  + B_C2 * (_4(kp_pq.c_str()) * _4(qk_pFb.c_str())
168  + _4(pk_pq.c_str()) * _4(kq_pFb.c_str()))
169  )
170  //
171  - ( B_C1 * (_4(pk_mA.c_str()) * _4(qk_mFPA.c_str())
172  + _4(kp_mA.c_str()) * _4(kq_mFPA.c_str()))
173  + B_C2 * (_4(kp_mA.c_str()) * _4(qk_mFPA.c_str())
174  + _4(pk_mA.c_str()) * _4(kq_mFPA.c_str()))
175 
176  + B_C1 * (_4(qk_mA.c_str()) * _4(pk_mFPA.c_str())
177  + _4(kq_mA.c_str()) * _4(kp_mFPA.c_str()))
178  + B_C2 * (_4(kq_mA.c_str()) * _4(pk_mFPA.c_str())
179  + _4(qk_mA.c_str()) * _4(kp_mFPA.c_str()))
180  )
181  //
182  - ( B_C1 * (_4(pk_Ab.c_str()) * _4(qk_AFb.c_str())
183  + _4(kp_Ab.c_str()) * _4(kq_AFb.c_str()))
184  + B_C2 * (_4(kp_Ab.c_str()) * _4(qk_AFb.c_str())
185  + _4(pk_Ab.c_str()) * _4(kq_AFb.c_str()))
186 
187  + B_C1 * (_4(qk_Ab.c_str()) * _4(pk_AFb.c_str())
188  + _4(kq_Ab.c_str()) * _4(kp_AFb.c_str()))
189  + B_C2 * (_4(kq_Ab.c_str()) * _4(pk_AFb.c_str())
190  + _4(qk_Ab.c_str()) * _4(kp_AFb.c_str()))
191  );
192  return B_pq;
193  }
194 
195  template <typename T>
197  SingleReference_R12Intermediates<T>::Bpr_qs(const char* p, const char* q)
198  {
199 
200  const double C_0 = 0.5;
201  const double C_1 = 0.25;
202  const double B_C1 = 0.5 * C_0 * C_0 + 1.5 * C_1 * C_1;
203  const double B_C2 = 0.5 * C_0 * C_0 - 1.5 * C_1 * C_1;
204 
205  std::string rTr_pkql = std::string("<") + p + " k|rTr|" + q + " l>";
206  std::string rTr_kpql = std::string("<k ") + p + "|rTr|" + q + " l>";
207 
208  std::string r2_phJk_ql = std::string("<") + p + "_hJ(p') k|r2|" + q + " l>";
209  std::string r2_pkhJ_ql = std::string("<") + p + " k_hJ(p')|r2|" + q + " l>";
210  //
211  std::string r2_kphJ_ql = std::string("<k ") + p + "_hJ(p')|r2|" + q + " l>";
212  std::string r2_khJp_ql = std::string("<k_hJ(p') ") + p + "|r2|" + q + " l>";
213  //
214  std::string r2_pk_qhJl = std::string("<") + p + " k|r2|" + q + "_hJ(p') l>";
215  std::string r2_pk_qlhJ = std::string("<") + p + " k|r2|" + q + " l_hJ(p')>";
216  //
217  std::string r2_pk_lqhJ = std::string("<") + p + " k|r2|l " + q + "_hJ(p')>";
218  std::string r2_pk_lhJq = std::string("<") + p + " k|r2|l_hJ(p') " + q + ">";
219 
220  std::string pk_PQ = std::string("<") + p + " k|r|p' q'>";
221  std::string kp_PQ = std::string("<k ") + p + "|r|p' q'>";
222  std::string ql_PKQ = std::string("<") + q + " l|r|p'_K(r') q'>";
223  std::string lq_PKQ = std::string("<l ") + q + "|r|p'_K(r') q'>";
224 
225  std::string pk_Pn = std::string("<") + p + " k|r|p' n>";
226  std::string kp_Pn = std::string("<k ") + p + "|r|p' n>";
227  std::string ql_PFn = std::string("<") + q + " l|r|p'_F(r') n>";
228  std::string lq_PFn = std::string("<l ") + q + "|r|p'_F(r') n>";
229 
230  std::string pk_mA = std::string("<") + p + " k|r|m a'>";
231  std::string kp_mA = std::string("<k ") + p + "|r|m a'>";
232  std::string ql_mFA = std::string("<") + q + " l|r|m_F(n) a'>";
233  std::string lq_mFA = std::string("<l ") + q + "|r|m_F(n) a'>";
234 
235  std::string pk_pq = std::string("<") + p + " k|r|p b>";
236  std::string kp_pq = std::string("<k ") + p + "|r|p b>";
237  std::string ql_pFb = std::string("<") + q + " l|r|p_F(r) b>";
238  std::string lq_pFb = std::string("<l ") + q + "|r|p_F(r) b>";
239 
240  std::string ql_mFPA = std::string("<") + q + " l|r|m_F(p') a'>";
241  std::string lq_mFPA = std::string("<l ") + q + "|r|m_F(p') a'>";
242  //
243  std::string ql_mA = std::string("<") + q + " l|r|m a'>";
244  std::string lq_mA = std::string("<l ") + q + "|r|m a'>";
245  std::string pk_mFPA = std::string("<") + p + " k|r|m_F(p') a'>";
246  std::string kp_mFPA = std::string("<k ") + p + "|r|m_F(p') a'>";
247 
248  std::string pk_Ab = std::string("<") + p + " k|r|a' b>";
249  std::string kp_Ab = std::string("<k ") + p + "|r|a' b>";
250  std::string ql_AFb = std::string("<") + q + " l|r|a'_F(q) b>";
251  std::string lq_AFb = std::string("<l ") + q + "|r|a'_F(q) b>";
252  //
253  std::string ql_Ab = std::string("<") + q + " l|r|a' b>";
254  std::string lq_Ab = std::string("<l ") + q + "|r|a' b>";
255  std::string pk_AFb = std::string("<") + p + " k|r|a'_F(q) b>";
256  std::string kp_AFb = std::string("<k ") + p + "|r|a'_F(q) b>";
257 
258  TArray4 Bpr_qs;
259  Bpr_qs("p,r,q,s") =
260  // diag
261  B_C1 * _4(rTr_pkql.c_str()) + B_C2 * _4(rTr_kpql.c_str())
262  // Q
263  + 0.5 * (
264  B_C1 * (_4(r2_phJk_ql.c_str()) + _4(r2_pkhJ_ql.c_str()))
265  + B_C2 * (_4(r2_kphJ_ql.c_str()) + _4(r2_khJp_ql.c_str()))
266 
267  + B_C1 * (_4(r2_pk_qhJl.c_str()) + _4(r2_pk_qlhJ.c_str()))
268  + B_C2 * (_4(r2_pk_lqhJ.c_str()) + _4(r2_pk_lhJq.c_str()))
269  )
270  // rKr_p'q'
271  - ( B_C1 * (_4(pk_PQ.c_str()) * _4(ql_PKQ.c_str())
272  + _4(kp_PQ.c_str()) * _4(lq_PKQ.c_str()))
273  + B_C2 * (_4(kp_PQ.c_str()) * _4(ql_PKQ.c_str())
274  + _4(pk_PQ.c_str()) * _4(lq_PKQ.c_str()))
275  )
276  // rFr_p'n
277  - ( B_C1 * (_4(pk_Pn.c_str()) * _4(ql_PFn.c_str())
278  + _4(kp_Pn.c_str()) * _4(lq_PFn.c_str()))
279  + B_C2 * (_4(kp_Pn.c_str()) * _4(ql_PFn.c_str())
280  + _4(pk_Pn.c_str()) * _4(lq_PFn.c_str()))
281  )
282  // rFr_mA
283  + ( B_C1 * (_4(pk_mA.c_str()) * _4(ql_mFA.c_str())
284  + _4(kp_mA.c_str()) * _4(lq_mFA.c_str()))
285  + B_C2 * (_4(kp_mA.c_str()) * _4(ql_mFA.c_str())
286  + _4(pk_mA.c_str()) * _4(lq_mFA.c_str()))
287  )
288  // rFr_pb
289  - ( B_C1 * (_4(pk_pq.c_str()) * _4(ql_pFb.c_str())
290  + _4(kp_pq.c_str()) * _4(lq_pFb.c_str()))
291  + B_C2 * (_4(kp_pq.c_str()) * _4(ql_pFb.c_str())
292  + _4(pk_pq.c_str()) * _4(lq_pFb.c_str()))
293  )
294  //
295  - ( B_C1 * (_4(pk_mA.c_str()) * _4(ql_mFPA.c_str())
296  + _4(kp_mA.c_str()) * _4(lq_mFPA.c_str()))
297  + B_C2 * (_4(kp_mA.c_str()) * _4(ql_mFPA.c_str())
298  + _4(pk_mA.c_str()) * _4(lq_mFPA.c_str()))
299 
300  + B_C1 * (_4(ql_mA.c_str()) * _4(pk_mFPA.c_str())
301  + _4(lq_mA.c_str()) * _4(kp_mFPA.c_str()))
302  + B_C2 * (_4(lq_mA.c_str()) * _4(pk_mFPA.c_str())
303  + _4(ql_mA.c_str()) * _4(kp_mFPA.c_str()))
304  )
305  //
306  - ( B_C1 * (_4(pk_Ab.c_str()) * _4(ql_AFb.c_str())
307  + _4(kp_Ab.c_str()) * _4(lq_AFb.c_str()))
308  + B_C2 * (_4(kp_Ab.c_str()) * _4(ql_AFb.c_str())
309  + _4(pk_Ab.c_str()) * _4(lq_AFb.c_str()))
310 
311  + B_C1 * (_4(ql_Ab.c_str()) * _4(pk_AFb.c_str())
312  + _4(lq_Ab.c_str()) * _4(kp_AFb.c_str()))
313  + B_C2 * (_4(lq_Ab.c_str()) * _4(pk_AFb.c_str())
314  + _4(ql_Ab.c_str()) * _4(kp_AFb.c_str()))
315  );
316  return Bpr_qs;
317  }
318 
319  // compute V^PQ_RS = 1/2 R^PQ_A'B' g^A'B'_RS (all indices in alpha or beta space)
320  // do not use p1, q1, a1', or n1 as argument
321  template <typename T>
323  SingleReference_R12Intermediates<T>::VPQ_RS(const char* p, const char* q,
324  const char* r, const char* s)
325  {
326 
327  std::string gr_pqrs = std::string("<") + p + " " + q + "|gr|" + r + " " + s + ">";
328 
329  std::string rpq_pq = std::string("<") + p + " " + q + "|r|p1 q1>";
330  std::string grs_pq = std::string("<p1 q1|g|") + r + " " + s + ">";
331 
332  std::string rpq_apn = std::string("<") + p + " " + q + "|r|a1' n1>";
333  std::string grs_apn = std::string("<a1' n1|g|") + r + " " + s + ">";
334 
335  std::string rpq_nap = std::string("<") + p + " " + q + "|r|n1 a1'>";
336  std::string grs_nap = std::string("<n1 a1'|g|") + r + " " + s + ">";
337 
338  std::string pqrs = p + std::string(",") + q + std::string(",")
339  + r + std::string(",") + s;
340 
341  TArray4 Vpq_rs;
342  Vpq_rs(pqrs.c_str()) = _4(gr_pqrs.c_str())
343  - _4(rpq_pq.c_str()) * _4(grs_pq.c_str())
344  - _4(rpq_apn.c_str()) * _4(grs_apn.c_str())
345  - _4(rpq_nap.c_str()) * _4(grs_nap.c_str())
346  ;
347  return Vpq_rs;
348  }
349 
350  // compute V^Pq_Rs = 1/2 bar{R}^Pq_A'B' bar{g}^A'B'_Rs (P, R in alpha or beta space)
351  // do not use p1, q1, a1', or n1 as argument
352  template <typename T>
354  SingleReference_R12Intermediates<T>::VPq_Rs(const char* p, const char* q,
355  const char* r, const char* s,
356  const double C_0, const double C_1)
357  {
358  const double V_C1 = (0.5 * C_0 + 1.5 * C_1);
359  const double V_C2 = (0.5 * C_0 - 1.5 * C_1);
360 
361  std::string gr_pqrs = std::string("<") + p + " " + q + "|gr|" + r + " " + s + ">";
362  std::string gr_qprs = std::string("<") + q + " " + p + "|gr|" + r + " " + s + ">";
363 
364  std::string rpq_pq = std::string("<") + p + " " + q + "|r|p1 q1>";
365  std::string rqp_pq = std::string("<") + q + " " + p + "|r|p1 q1>";
366  std::string grs_pq = std::string("<p1 q1|g|") + r + " " + s + ">";
367 
368  std::string rpq_apn = std::string("<") + p + " " + q + "|r|a1' n1>";
369  std::string rqp_apn = std::string("<") + q + " " + p + "|r|a1' n1>";
370  std::string grs_apn = std::string("<a1' n1|g|") + r + " " + s + ">";
371 
372  std::string rpq_nap = std::string("<") + p + " " + q + "|r|n1 a1'>";
373  std::string rqp_nap = std::string("<") + q + " " + p + "|r|n1 a1'>";
374  std::string grs_nap = std::string("<n1 a1'|g|") + r + " " + s + ">";
375 
376  std::string pqrs = p + std::string(",") + q + std::string(",")
377  + r + std::string(",") + s;
378 
379  TArray4 Vpq_rs;
380  Vpq_rs(pqrs.c_str()) = V_C1 * _4(gr_pqrs.c_str()) + V_C2 * _4(gr_qprs.c_str())
381  - (V_C1 * _4(rpq_pq.c_str()) + V_C2 * _4(rqp_pq.c_str()))
382  * _4(grs_pq.c_str())
383  - (V_C1 * _4(rpq_apn.c_str()) + V_C2 * _4(rqp_apn.c_str()))
384  * _4(grs_apn.c_str())
385  - (V_C1 * _4(rpq_nap.c_str()) + V_C2 * _4(rqp_nap.c_str()))
386  * _4(grs_nap.c_str())
387  ;
388  return Vpq_rs;
389  }
390 
391  // compute V^Rk_Sk = 1/2 bar{R}^Rk_A'B' bar{g}^A'B'_Sk
392  // can not use k1 l2 n1 a1' for arguments
393  template <typename T>
395  SingleReference_R12Intermediates<T>::VRk_Sk(const char* r, const char* s,
396  const double C_0, const double C_1)
397  {
398  const double V_C1 = (0.5 * C_0 + 1.5 * C_1);
399  const double V_C2 = (0.5 * C_0 - 1.5 * C_1);
400 
401  std::string gr_rksk = std::string("<") + r + " k1|gr|" + s + " l1>";
402  std::string gr_krsk = std::string("<k1 ") + r + "|gr|" + s + " l1>";
403 
404  std::string r_rkpq = std::string("<") + r + " k1|r|p1 q1>";
405  std::string r_krpq = std::string("<k1 ") + r + "|r|p1 q1>";
406  std::string g_skpq = std::string("<p1 q1|g|") + s + " k1>";
407 
408  std::string r_rkapn = std::string("<") + r + " k1|r|a1' n1>";
409  std::string r_krapn = std::string("<k1 ") + r + "|r|a1' n1>";
410  std::string g_skapn = std::string("<a1' n1|g|") + s + " k1>";
411 
412  std::string r_rknap = std::string("<") + r + " k1|r|n1 a1'>";
413  std::string r_krnap = std::string("<k1 ") + r + "|r|n1 a1'>";
414  std::string g_sknap = std::string("<n1 a1'|g|") + s + " k1>";
415 
416  std::string rs = r + std::string(",") + s;
417  TArray2 Vrk_sk;
418  Vrk_sk(rs.c_str()) = (V_C1 * _4(gr_rksk.c_str()) + V_C2 * _4(gr_krsk.c_str()))
419  * _2("<l1|I|k1")
420  - (V_C1 * _4(r_rkpq.c_str()) + V_C2 * _4(r_krpq.c_str()))
421  * _4(g_skpq.c_str())
422  - (V_C1 * _4(r_rkapn.c_str()) + V_C2 * _4(r_krapn.c_str()))
423  * _4(g_skapn.c_str())
424  - (V_C1 * _4(r_rknap.c_str()) + V_C2 * _4(r_krnap.c_str()))
425  * _4(g_sknap.c_str())
426  ;
427  return Vrk_sk;
428  }
429 
430  template <typename T>
431  std::pair<typename SingleReference_R12Intermediates<T>::TArray2,
434 
435  TArray2 V_ij_ij_cabs; V_ij_ij_cabs("i,j") = dotket(ij_xy("<i j|g|m a'>"), ij_xy("<i j|r|m a'>"));
436  // don't need this in closed shell!
437  //TArray2 V_ij_ij_cabs1 = dotket(ij_xy("<i j|g|a' m>"), ij_xy("<i j|r|a' m>"));
438 
439  TArray2 V_ij_ij; V_ij_ij("i,j") = take(ij_xy("<i j|gr|p q>"), ij) - dotket(ij_xy("<i j|g|p q>"), ij_xy("<i j|r|p q>"))
440  - V_ij_ij_cabs("i,j") - V_ij_ij_cabs("j,i");
441 
442  TArray2 V_ij_ji_cabs = dotket(ij_xy("<i j|g|m a'>"), ij_xy("<i j|r|m a'>"), true);
443  TArray2 V_ij_ji = take(ij_xy("<i j|gr|p q>"), ji) - dotket(ij_xy("<i j|g|p q>"), ij_xy("<i j|r|p q>"), true)
444  - V_ij_ji_cabs("i,j") - V_ij_ji_cabs("j,i");
445 
446  return std::make_pair(V_ij_ij,V_ij_ji);
447 
448  }
449 
450  template <typename T>
451  std::pair<typename SingleReference_R12Intermediates<T>::TArray2,
454 
455  TArray2 X_ij_ij_cabs = dotket(ij_xy("<i j|r|m a'>"), ij_xy("<i j|r|m a'>"));
456  // don't need this in closed shell!
457  //TArray2 X_ij_ij_cabs1 = dotket(ij_xy("<i j|r|a' m>"), ij_xy("<i j|r|a' m>"));
458 
459  TArray2 X_ij_ij = take(ij_xy("<i j|r2|p q>"), ij) - dotket(ij_xy("<i j|r|p q>"), ij_xy("<i j|r|p q>"))
460  - X_ij_ij_cabs("i,j") - X_ij_ij_cabs("j,i");
461 
462  TArray2 X_ij_ji_cabs = dotket(ij_xy("<i j|r|m a'>"), ij_xy("<i j|r|m a'>"), true);
463  TArray2 X_ij_ji = take(ij_xy("<i j|r2|p q>"), ji) - dotket(ij_xy("<i j|r|p q>"), ij_xy("<i j|r|p q>"), true)
464  - X_ij_ji_cabs("i,j") - X_ij_ji_cabs("j,i");
465 
466  return std::make_pair(X_ij_ij,X_ij_ji);
467 
468  }
469 
470  template <typename T>
471  std::pair<typename SingleReference_R12Intermediates<T>::TArray2,
474 
476  TArray2 B_ij_ij = take(ij_xy("<i j|rTr|p q>"), ij) + take(ij_xy("<i_hJ(p') j|r2|p q>"), ij)
477  - dotket(ij_xy("<i j|r|p' q'>"), ij_xy("<i j|r|p' q'_K(r')>"));
478 
479  TArray2 B_ij_ji = take(ij_xy("<i j|rTr|p q>"), ji) + take(ij_xy("<i_hJ(p') j|r2|p q>"), ji);
480 
481  return std::make_pair(B_ij_ij,B_ij_ji);
482 
483  }
484 
485  namespace detail {
486 
490  template<typename T>
492  typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> EigenMatrixX;
493  selfenergy_denom(const T& E,
494  const EigenMatrixX& Y_mat,
495  const EigenMatrixX& X1_mat,
496  const EigenMatrixX& X2_mat) :
497  E_(E), Y_mat_(Y_mat), X1_mat_(X1_mat), X2_mat_(X2_mat) {
498  }
499  template<typename Index> T operator()(const Index& i) {
500  return 1.0 / ( E_ + Y_mat_(i[1], i[1]) - X1_mat_(i[2], i[2]) - X2_mat_(i[3], i[3]) );
501  }
502 
503  private:
504  T E_;
505  EigenMatrixX Y_mat_;
506  EigenMatrixX X1_mat_;
507  EigenMatrixX X2_mat_;
508  };
509  }; // namespace sc::detail
510 
511  template <typename T>
512  void
514 
515  enum CalcType {
516  IP, EA
517  };
518 
519  MPQC_ASSERT(orbital != 0);
520  const CalcType type = (orbital < 0) ? IP : EA;
521 
522  const std::string X_label = (type == IP) ? "i1" : "a1"; // active orbital label
523  const Ref<OrbitalSpace>& X_space = (type == IP) ? this->r12world()->refwfn()->occ_act()
524  : this->r12world()->refwfn()->uocc_act();
525 
526  TArray2 fij = xy("<j|F|j>");
527  TArray2 fab = xy("<a|F|b>");
528 
529  // use the diagonal element of the Fock matrix as the guess (only HOMO/LUMO supported);
530  const double E = (type == IP) ? X_space->evals()(X_space->rank() + orbital) : X_space->evals()(orbital - 1);
531 
532  // compute Delta_ijaE = 1 / (- E - <a|F|a> + <i|F|i> + <j|F|j>)
533  typedef detail::selfenergy_denom<double> sedenom_eval_type;
534  sedenom_eval_type Delta_jab_gen(E,
535  TA::array_to_eigen(fij),
536  TA::array_to_eigen(fab),
537  TA::array_to_eigen(fab) );
538  sedenom_eval_type Delta_ajk_gen(E,
539  TA::array_to_eigen(fab),
540  TA::array_to_eigen(fij),
541  TA::array_to_eigen(fij) );
542 
543  std::ostringstream Xjab; Xjab << "<" << X_label << " j|g|a b>";
544  TArray4d g_Xjab = ijxy(Xjab.str());
545  typedef TA::Array<T, 4, LazyTensor<T, 4, sedenom_eval_type > > TArray4dLazy;
546  TArray4dLazy Delta_Xjab(g_Xjab.world(), g_Xjab.trange());
547 
548  // construct local tiles
549  for(auto t = Delta_Xjab.trange().tiles_range().begin();
550  t != Delta_Xjab.trange().tiles_range().end(); ++t)
551  if (Delta_Xjab.is_local(*t)) {
552  std::array<std::size_t, 4> index;
553  std::copy(t->begin(), t->end(), index.begin());
554  madness::Future < typename TArray4dLazy::value_type >
555  tile((LazyTensor<T, 4, sedenom_eval_type >(&Delta_Xjab, index, &Delta_jab_gen)
556  ));
557 
558  // Insert the tile into the array
559  Delta_Xjab.set(*t, tile);
560  }
561 
562  std::ostringstream Xajk; Xajk << "<" << X_label << " a|g|j k>";
563  TArray4d g_Xajk = ijxy(Xajk.str());
564  typedef TA::Array<T, 4, LazyTensor<T, 4, sedenom_eval_type > > TArray4dLazy;
565  TArray4dLazy Delta_Xajk(g_Xajk.world(), g_Xajk.trange());
566 
567  // construct local tiles
568  for(auto t = Delta_Xajk.trange().tiles_range().begin();
569  t != Delta_Xajk.trange().tiles_range().end(); ++t)
570  if (Delta_Xajk.is_local(*t)) {
571  std::array<std::size_t, 4> index;
572  std::copy(t->begin(), t->end(), index.begin());
573  madness::Future < typename TArray4dLazy::value_type >
574  tile((LazyTensor<T, 4, sedenom_eval_type >(&Delta_Xajk, index, &Delta_ajk_gen)
575  ));
576 
577  // Insert the tile into the array
578  Delta_Xajk.set(*t, tile);
579  }
580 
581  TArray4 dg_Xjab; dg_Xjab("Y,j,a,b") = Delta_Xjab("Y,j,a,b") * (4 * g_Xjab("Y,j,a,b") - 2 * g_Xjab("Y,j,b,a"));
582  TArray4 dg_Xajk; dg_Xajk("Y,a,j,m") = Delta_Xajk("Y,a,j,m") * (4 * g_Xajk("Y,a,j,m") - 2 * g_Xajk("Y,a,m,j"));
583 
584  // second-order self-energy, Eq. 11.16 in Dickoff-VanNeck, with spin integrated out
585  // \sigma_{X}^{Y} =
586 // TArray2 sigma2; sigma2("X,Y") = (1./2) * ( g_Xjab("X,j,a,b") * dg_Xjab("Y,j,a,b") +
587 // g_Xajk("X,a,j,m") * dg_Xajk("Y,a,j,m") );
588  TArray2 sigma2_hpp; sigma2_hpp("X,Y") = (1./2) * g_Xjab("X,j,a,b") * dg_Xjab("Y,j,a,b");
589  TArray2 sigma2_phh; sigma2_phh("X,Y") = (1./2) * g_Xajk("X,a,j,m") * dg_Xajk("Y,a,j,m");
590 
591  ExEnv::out0() << "Fock:" << std::endl << fij << std::endl;
592  ExEnv::out0() << "SE2_hpp(e=" << E << "):" << std::endl << sigma2_hpp << std::endl;
593  ExEnv::out0() << "SE2_phh(e=" << E << "):" << std::endl << sigma2_phh << std::endl;
594  }
595 
596  namespace detail {
599  template<typename T>
601 
602  typedef TiledArray::Array<T, 2> Array;
603 
608  _CABS_singles_h0t1(const Array& h0_AB, const Array& h0_ij) :
609  H0_AB(h0_AB), H0_IJ(h0_ij) {
610  }
611 
612  const Array& H0_AB;
613  const Array& H0_IJ;
614 
619  void operator()(const Array& T1, Array& R1) {
620  R1 = T1("i,b") * H0_AB("b,a") - H0_IJ("i,j") * T1("j,a");
621  }
622  };
623 
626  template<typename T>
627  struct _OrbResponse {
628 
629  typedef TiledArray::Array<T, 2> Array2;
630  typedef TiledArray::Array<T, 4> Array4;
631 
638  _OrbResponse(const Array2& f_AB, const Array2& f_ij,
639  const Array4& g_ij_ab, const Array4& g_ia_jb) :
640  F_AB(f_AB), F_IJ(f_ij), G_IJ_AB(g_ij_ab), G_IA_JB(g_ia_jb) {
641  }
642 
643  const Array2& F_AB;
644  const Array2& F_IJ;
645  const Array4& G_IJ_AB;
646  const Array4& G_IA_JB;
647 
652  void operator()(const Array2& kappa, Array2& residual) {
653  residual = kappa("i,b") * F_AB("b,a") - F_IJ("i,j") * kappa("j,a")
654  + 4.0 * G_IJ_AB("i,j,a,b") * kappa("j,b")
655  - G_IJ_AB("i,j,b,a") * kappa("j,b")
656  - G_IA_JB("i,a,j,b") * kappa("j,b");
657  }
658  };
659 
661  template <typename T>
662  struct diag_precond2 {
663  typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> EigenMatrixX;
664  diag_precond2(const EigenMatrixX& O1_mat,
665  const EigenMatrixX& O2_mat) :
666  O1_mat_(O1_mat), O2_mat_(O2_mat) {
667  }
668  template <typename Index> T operator()(const Index& i) {
669  return 1.0 / (- O1_mat_(i[0], i[0]) + O2_mat_(i[1], i[1]));
670  }
671 
672  private:
673  EigenMatrixX O1_mat_;
674  EigenMatrixX O2_mat_;
675  };
676 
678  template <typename T>
679  struct diag_precond4 {
680  typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> EigenMatrixX;
681  diag_precond4(const EigenMatrixX& O1_mat,
682  const EigenMatrixX& O2_mat,
683  const EigenMatrixX& O3_mat,
684  const EigenMatrixX& O4_mat) :
685  O1_mat_(O1_mat), O2_mat_(O2_mat),
686  O3_mat_(O3_mat), O4_mat_(O4_mat) {
687  }
688  template <typename Index> T operator()(const Index& i) {
689  return 1.0 / (- O1_mat_(i[0], i[0]) - O2_mat_(i[1], i[1]) + O3_mat_(i[2], i[2]) + O4_mat_(i[3], i[3]));
690  }
691 
692  private:
693  EigenMatrixX O1_mat_;
694  EigenMatrixX O2_mat_;
695  EigenMatrixX O3_mat_;
696  EigenMatrixX O4_mat_;
697  };
698 
699  template<typename T>
701 
702  typedef TiledArray::Array<T, 2> Array2;
703  typedef TiledArray::Array<T, 4> Array4;
704 
708  Orbital_relaxation_Abjai(const Array4& a_bjai) :
709  A_bjai(a_bjai) {
710  }
711 
712  const Array4& A_bjai;
713 
718  void operator()(const Array2& K_bj, Array2& R1) {
719  R1("a,i") = K_bj("b,j") * A_bjai("b,j,a,i");
720  }
721  };
722 
723  // e_ij = (e_i + e_j)
724  template <typename T>
725  struct e_ij {
726  typedef Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic, Eigen::RowMajor> EigenMatrixX;
727  e_ij(const EigenMatrixX& O1_mat, const EigenMatrixX& O2_mat):
728  O1_mat_(O1_mat), O2_mat_(O2_mat) {}
729 
730  template <typename Index> T operator()(const Index& i) {
731  return (O1_mat_(i[0], i[0]) + O2_mat_(i[1], i[1]));
732  }
733 
734  private:
735  EigenMatrixX O1_mat_;
736  EigenMatrixX O2_mat_;
737  };
738 
739  } // namespace sc::detail
740 
741  // Xam contribution from CABS Singles
742  template <typename T>
745  const TArray2& Tma) {
746  // density from CABS Singles contribution
747  TArray2 D_e2_mn, D_e2_AB;
748  // D^m_n = t^m_A' * t^A'_n
749  D_e2_mn("m,n")= TmA("m,A'") * TmA("n,A'");
750  // D^A'_B' = t^A'_m * t^m_B'
751  D_e2_AB("A',B'") = TmA("m,A'") * TmA("m,B'");
752 
753  // compute intermediate to reduce memory consumption
754  TArray4 g_aAmB;
755  g_aAmB("a,A',m,B'") = 2.0 * _4("<a A'|g|m B'>") - _4("<a A'|g|B' m>");
756  TArray4::wait_for_lazy_cleanup(g_aAmB.world());
757 
758  TArray4d g_aAmn = ijxy("<a A'|g|m n>");
759  TArray4d g_ammn = ijxy("<a m|g|m1 n>");
760 
761  TArray2 Xam_E2;
762  Xam_E2("a,m") = 2.0 * (
763  - _2("<A'|F|a>") * TmA("m,A'")
764  + Tma("n,a") * _2("<m|F|n>")
765  + (TmA("n,A'") * Tma("n,a")) * _2("<m|F|A'>")
766  //
767  - ( 2.0 * _4("<a n|g|m A'>") - _4("<a n|g|A' m>")
768  + 2.0 * g_aAmn("a,A',m,n") - g_aAmn("a,A',n,m")
769  ) * TmA("n,A'")
770  //
771  - g_aAmB("a,A',m,B'") * D_e2_AB("A',B'")
772  //
773  + (2.0 * g_ammn("a,n1,m,n2") - g_ammn("a,n1,n2,m"))
774  * D_e2_mn("n1,n2")
775  );
776  return Xam_E2;
777  }
778 
779  // Xam contribution from MP2 correlation
780  template <typename T>
782  SingleReference_R12Intermediates<T>::Xam_mp2(const TArray4& T2_ijab,
783  const TArray2& Dij,
784  const TArray2& Dab) {
785  TArray2 Xai_mp2, Xam_mp2;
786  Xai_mp2("a,i") = 2.0 * (
787  // derivatives of 1/4 g^kl_cd T^cd_kl
788  // g^al_cd T^cd_il
789  - _4("<a l|g|c d>")
790  * (2.0 * T2_ijab("i,l,c,d") - T2_ijab("l,i,c,d"))
791  );
792  Xam_mp2("a,m") = 2.0 * (
793  // derivatives of 1/4 g^kl_cd T^cd_kl
794  // g_mc^kl T^ac_kl
795  (2.0 * T2_ijab("k,l,a,c") - T2_ijab("k,l,c,a"))
796  * _4("<m c|g|k l>")
797 
798  // derivatives of 1/2 F^c_d D^d_c - 1/2 F^l_k D^k_l
799  // g^ac_md D^d_c
800  - (2.0 * _4("<a c|g|m d>") - _4("<a c|g|d m>"))
801  * Dab("d,c")
802  // g^al_mk D^k_l
803  + (2.0 * _4("<a l|g|m k>") - _4("<a l|g|k m>"))
804  * Dij("k,l")
805  );
806 
807  // test code: print out I intermediates
808 // TArray2 Iam, Iia, Ima;
809 // Iam("a,m") = - (2.0 * T2_ijab("k,l,a,c") - T2_ijab("k,l,c,a"))
810 // * _4("<m c|g|k l>")
811 // ;
812 // Iia("a,i") = _4("<a l|g|c d>")
813 // * (2.0 * T2_ijab("i,l,c,d") - T2_ijab("l,i,c,d"));
814 // Ima("a,m") = (2.0 * _4("<a c|g|m d>") - _4("<a c|g|d m>"))
815 // * Dab("d,c")
816 // - (2.0 * _4("<a l|g|m k>") - _4("<a l|g|k m>"))
817 // * Dij("k,l")
818 // ;
819 // TArray2 Iima = XaiAddToXam(Ima, Iia);
820 // std::cout << "MP2 Iam: " << std::endl << Iam << std::endl;
821 // std::cout << "MP2 Ima: " << std::endl << Iima << std::endl;
822 
823  return XaiAddToXam(Xam_mp2, Xai_mp2);
824  }
825 
826  // Xai contribution from MP2 F12 coupling part
827  template <typename T>
829  SingleReference_R12Intermediates<T>::Xam_Cmp2f12(const double C_0, const double C_1,
830  const TArray4& T2_ijab, const TArray4& A_ijab,
831  const TArray2& Dij, const TArray2& Dab,
832  const TArray2& RT_apb) {
833  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
834  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
835  const double RR_C1 = 0.5 * C_0 * C_0 + 1.5 * C_1 * C_1;
836  const double RR_C2 = 0.5 * C_0 * C_0 - 1.5 * C_1 * C_1;
837 
838  TArray4 T2pA_temp;
839  T2pA_temp("i,j,a,b") = R_C1 * T2_ijab("i,j,a,b") + R_C2 * T2_ijab("j,i,a,b")
840  + RR_C1 * A_ijab("i,j,a,b") + RR_C2 * A_ijab("j,i,a,b");
841 
842  TArray2 Xai_mp2f12, Xam_mp2f12;
843  // Xai
844  Xai_mp2f12("a,i") = // derivatives of 1/4 g^kl_cd \tilde{T}^cd_kl
845  // g^al_cd \tilde{T}^cd_il
846  - _4("<a l|g|c d>")
847  * (R_C1 * A_ijab("i,l,c,d") + R_C2 * A_ijab("l,i,c,d"));
848  Xai_mp2f12("a,i") = Xai_mp2f12("a,i")
849  // F^a'_b R^al_a'c \tilde{T}^bc_il
850  // 1st part
851  - _4("<a l|r|b_F(a') c>") * T2pA_temp("i,l,b,c");
852  Xai_mp2f12("a,i") = Xai_mp2f12("a,i")
853  // 2nd part
854  - _4("<a l|r|c b_F(a')>") * T2pA_temp("i,l,c,b");
855 
856  // Xam
857  Xam_mp2f12("a,m") = // derivatives of 1/4 g^kl_cd \tilde{T}^cd_kl
858  // g_ic^kl \tilde{T}^Ac_kl
859  (R_C1 * A_ijab("k,l,a,c") + R_C2 * A_ijab("k,l,c,a"))
860  * _4("<m c|g|k l>")
861 
862  // derivatives of 1/2 F^c_d D^d_c - 1/2 F^l_k D^k_l
863  // g^ac_md D^d_c
864  - (2.0 * _4("<a c|g|m d>") - _4("<a c|g|d m>"))
865  * Dab("d,c")
866  // g^al_mk D^k_l
867  + (2.0 * _4("<a l|g|m k>") - _4("<a l|g|k m>"))
868  * Dij("k,l");
869  Xam_mp2f12("a,m") = Xam_mp2f12("a,m")
870  // derivatives of 1/2 F^a'_b R^kl_a'c \tilde{T}^bc_kl
871  // 1/2 F^a'_m R^kl_a'b \tilde{T}^ab_kl
872  // & 1/2 F^a'_b R^kl_ma' \tilde{T}^ab_kl
873  + T2pA_temp("k,l,a,b")
874  * (_4("<k l|r|m_F(a') b>") + _4("<k l|r|m b_F(a')>"));
875  TArray4 g_temp;
876  {
877  TArray4d gab_map = ijxy("<a b|g|m a'>");
878  g_temp("a,a',m,b") = 2.0 * _4("<a a'|g|m b>") - _4("<a a'|g|b m>")
879  + 2.0 * gab_map("a,b,m,a'") - gab_map("b,a,m,a'");
880  }
881  Xam_mp2f12("a,m") = Xam_mp2f12("a,m")
882  // g^aa'_mb 1/2 R^kl_a'c \tilde{T}^bc_kl
883  // & g^ab_ma' 1/2 R^kl_a'c \tilde{T}^bc_kl
884  - g_temp("a,a',m,b") * RT_apb("a',b");
885 
886  return XaiAddToXam(Xam_mp2f12, Xai_mp2f12);
887  }
888 
889  // compute F12 density from X and B terms
890  template <typename T>
891  void SingleReference_R12Intermediates<T>::compute_Df12_XB(const double C_0, const double C_1,
892  TArray2& D_f12_ij, TArray2& D_f12_ab,
893  TArray2& D_f12_apbp, TArray2& D_f12_apb) {
894 
895  const double RR_C1 = 0.5 * C_0 * C_0 + 1.5 * C_1 * C_1;
896  const double RR_C2 = 0.5 * C_0 * C_0 - 1.5 * C_1 * C_1;
897 
898  // Dij = 1/2 R^ik_A'B' R^A'B'_kl (A': all virtual)
899  {
900  TArray4d r2_ijkl = ijxy("<i j|r2|k l>");
901  TArray4d r_ijpq = ijxy("<i j|r|p q>");
902  TArray4d r_ijapn = ijxy("<i j|r|a' n>");
903  D_f12_ij("i,j") = (RR_C1 * r2_ijkl("i,k,j,l") + RR_C2 * r2_ijkl("k,i,j,l"))
904  * _2("<k|I|l>")
905  - (RR_C1 * r_ijpq("i,k,p,q") + RR_C2 * r_ijpq("k,i,p,q"))
906  * r_ijpq("j,k,p,q")
907  - (RR_C1 * r_ijapn("i,k,a',n") + RR_C2 * r_ijapn("k,i,a',n"))
908  * r_ijapn("j,k,a',n")
909  - (RR_C1 * r_ijapn("k,i,a',n") + RR_C2 * r_ijapn("i,k,a',n"))
910  * r_ijapn("k,j,a',n");
911  }
912  TArray4d::wait_for_lazy_cleanup(D_f12_ij.world());
913 
914  // DA'B' = 1/2 R^A'C'_kl R^kl_B'C' (A': all virtual)
915  TArray4d r_acpkl = ijxy("<a c'|r|k l>");
916  {
917  TArray4d r_apcpkl = ijxy("<a' c'|r|k l>");
918  D_f12_apb("a',b") = (RR_C1 * r_apcpkl("a',c',k,l") + RR_C2 * r_apcpkl("a',c',l,k"))
919  * r_acpkl("b,c',k,l");
920 
921  D_f12_apbp("a',b'") = (RR_C1 * r_acpkl("c,a',l,k") + RR_C2 * r_acpkl("c,a',k,l"))
922  * r_acpkl("c,b',l,k")
923  + (RR_C1 * r_apcpkl("a',c',k,l") + RR_C2 * r_apcpkl("a',c',l,k"))
924  * r_apcpkl("b',c',k,l");
925 // D_f12_apbp("a',b'") = (RR_C1 * _4("<a' p'|r|k l>") + RR_C2 * _4("<a' p'|r|l k>"))
926 // * _4("<b' p'|r|k l>")
927 // - (RR_C1 * _4("<a' m|r|k l>") + RR_C2 * _4("<a' m|r|l k>"))
928 // * _4("<b' m|r|k l>");
929  }
930  TArray4d::wait_for_lazy_cleanup(D_f12_ij.world());
931 
932  D_f12_ab("a,b") = (RR_C1 * r_acpkl("a,c',k,l") + RR_C2 * r_acpkl("a,c',l,k"))
933  * r_acpkl("b,c',k,l");
934  }
935 
936  // compute X and B density contribution to Xam
937  template <typename T>
939  SingleReference_R12Intermediates<T>::Xam_Df12_XB(const double C_0, const double C_1,
940  const TArray2& Df12_ij, const TArray2& Df12_ab,
941  const TArray2& Df12_apbp, const TArray2& Df12_apb) {
942  TArray2 gdf12_am;
943  gdf12_am("a,m") = // X related contribution
944  (2.0 * _4("<a k|g|m l>") - _4("<a k|g|l m>"))
945  * Df12_ij("k,l");
946 
947  TArray4d g_abmc = ijxy("<a b|g|m c>");
948  gdf12_am("a,m") = gdf12_am("a,m")
949  // B related contribution
950  // 1st part
951  - (2.0 * g_abmc("a,b,m,c") - g_abmc("b,a,m,c"))
952  * Df12_ab("b,c");
953  {
954  TArray4 g_temp;
955  g_temp("a,b',m,c'") = 2.0 * _4("<a b'|g|m c'>") - _4("<a b'|g|c' m>");
956  TArray4d::wait_for_lazy_cleanup(g_temp.world());
957 
958  gdf12_am("a,m") = gdf12_am("a,m")
959  // 2nd part
960  - g_temp("a,b',m,c'") * Df12_apbp("b',c'");
961  }
962  {
963  TArray4 g_temp;
964  g_temp("a,b',m,c") = 2.0 * _4("<a b'|g|m c>") - _4("<a b'|g|c m>");
965  gdf12_am("a,m") = gdf12_am("a,m")
966  // 3rd part
967  - g_temp("a,b',m,c") * Df12_apb("b',c");
968  }
969  TArray4d g_abmcp = ijxy("<a b|g|m c'>");
970  gdf12_am("a,m") = gdf12_am("a,m")
971  // 4th part
972  - (2.0 * g_abmcp("a,b,m,c'") - g_abmcp("b,a,m,c'"))
973  * Df12_apb("c',b");
974  return gdf12_am;
975  }
976 
977  // Xam contribution from F12 V part
978  template <typename T>
980  SingleReference_R12Intermediates<T>::Xam_V(const double C_0, const double C_1) {
981 
982  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
983  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
984 
985  TArray2 Xai_V, Xam_V;
986  {
987  TArray4d gr_ak_ij = ijxy("<a k|gr|i j>");
988  TArray4d rpq_kl = ijxy("<p q|r|k l>");
989  TArray4d rapn_kl = ijxy("<a' n|r|k l>");
990  TArray4d rpq_ak = ijxy("<p q|r|a k>");
991 
992  TArray4d gij_apm = ijxy("<i j|g|a' m>");
993  TArray4d rapn_ak = ijxy("<a' n|r|a k>");
994  TArray4d rapn_ka = ijxy("<a' n|r|k a>");
995 
996  TArray2 Ikl = xy("<k|I|l>");
997 
998  Xai_V("a,i") = // 1/2 R^ik_AC g^AC_ak
999  - ( (R_C1 * gr_ak_ij("a,k,i,l") + R_C2 * gr_ak_ij("a,k,l,i"))
1000  * Ikl("k,l")
1001  - _4("<a k|g|p q>")
1002  * ( R_C1 * rpq_kl("p,q,i,k") + R_C2 * rpq_kl("p,q,k,i") )
1003  - _4("<a k|g|a' n>")
1004  * ( R_C1 * rapn_kl("a',n,i,k") + R_C2 * rapn_kl("a',n,k,i"))
1005  - _4("<k a|g|a' n>")
1006  * ( R_C1 * rapn_kl("a',n,k,i") + R_C2 * rapn_kl("a',n,i,k"))
1007  )
1008  // 1/2 R^ak_AC g^AC_ik
1009  - ( (R_C1 * gr_ak_ij("a,l,i,k") + R_C2 * gr_ak_ij("a,l,k,i"))
1010  * Ikl("k,l")
1011  - _4("<i k|g|p q>")
1012  * ( R_C1 * rpq_ak("p,q,a,k") + R_C2 * rpq_ak("q,p,a,k"))
1013  - gij_apm("i,k,a',n")
1014  * ( R_C1 * rapn_ak("a',n,a,k") + R_C2 * rapn_ka("a',n,k,a"))
1015  - gij_apm("k,i,a',n")
1016  * ( R_C1 * rapn_ka("a',n,k,a") + R_C2 * rapn_ak("a',n,a,k"))
1017  );
1018  }
1019  TArray4d::wait_for_lazy_cleanup(Xai_V.world());
1020 
1021  TArray4d raap_kl = ijxy("<a a'|r|k l>");
1022  TArray4d rmap_kl = ijxy("<m a'|r|k l>");
1023 
1024  Xam_V("a,m") = // 1/2 R^kl_ac' g^mc'_kl
1025  ( R_C1 * raap_kl("a,a',k,l") + R_C2 * raap_kl("a,a',l,k"))
1026  * _4("<k l|g|m a'>")
1027  // 1/2 R^kl_mc' g^ac'_kl
1028  + ( R_C1 * rmap_kl("m,a',k,l") + R_C2 * rmap_kl("m,a',l,k"))
1029  * _4("<k l|g|a a'>");
1030 
1031  return XaiAddToXam(Xam_V, Xai_V);
1032  }
1033 
1034  // Xam contribution from F12 X part
1035  template <typename T>
1037  SingleReference_R12Intermediates<T>::Xam_X(const double C_0, const double C_1) {
1038 
1039  const double RR_C1 = 0.5 * C_0 * C_0 + 1.5 * C_1 * C_1;
1040  const double RR_C2 = 0.5 * C_0 * C_0 - 1.5 * C_1 * C_1;
1041 
1042  TArray4d r2_akjl = ijxy("<a k|r2|j l>");
1043  TArray4d r2_kajl = ijxy("<k a|r2|j l>");
1044  TArray2 F_ij = xy("<i|F|j>");
1045 
1046  TArray4d r_pqjk = ijxy("<p q|r|j k>");
1047  TArray4d r_apnjk = ijxy("<a' n|r|j k>");
1048  TArray4d r_napjk = ijxy("<n a'|r|j k>");
1049 
1050  TArray2 X_ai, X_am;
1051 
1052  // - 1/2 (F^i_i + F^k_k) R^ak_alpha beta R_ik^alpha beta
1053  X_ai("a,i") = - (RR_C1 * r2_akjl("a,k,j,l") + RR_C2 * r2_kajl("k,a,j,l"))
1054  * _2("<l|I|k>") * F_ij("j,i")
1055 
1056  - (RR_C1 * r2_akjl("a,k,i,l") + RR_C2 * r2_kajl("k,a,i,l"))
1057  * F_ij("l,k")
1058 
1059  + (RR_C1 * _4("<a k|r|p q>") + RR_C2 * _4("<k a|r|p q>"))
1060  * ( r_pqjk("p,q,j,k") * F_ij("j,i")
1061  + r_pqjk("p,q,i,l") * F_ij("l,k"))
1062 
1063  + (RR_C1 * _4("<a k|r|a' n>") + RR_C2 * _4("<k a|r|a' n>"))
1064  * ( r_apnjk("a',n,j,k") * F_ij("j,i")
1065  + r_apnjk("a',n,i,l") * F_ij("l,k"))
1066 
1067  + (RR_C1 * _4("<a k|r|n a'>") + RR_C2 * _4("<k a|r|n a'>"))
1068  * ( r_napjk("n,a',j,k") * F_ij("j,i")
1069  + r_napjk("n,a',i,l") * F_ij("l,k"));
1070 
1071  // 1/2 (F^k_k + F^l_l) R^ab'_kl R_mb'^kl
1072  TArray4d r_aapkl = ijxy("<a a'|r|k l>");
1073  TArray4d r_klmap = ijxy("<k l|r|m a'>");
1074  X_am("a,m") = (RR_C1 * r_aapkl("a,b',k,l") + RR_C2 * r_aapkl("a,b',l,k"))
1075  * ( r_klmap("j,l,m,b'") * F_ij("j,k")
1076  + r_klmap("k,j,m,b'") * F_ij("j,l"));
1077 
1078  return XaiAddToXam(X_am, X_ai);
1079  }
1080 
1081  // Xam contribution from F12 B part
1082  template <typename T>
1084  SingleReference_R12Intermediates<T>::Xam_B(const double C_0, const double C_1) {
1085 
1086  const double B_C1 = 0.5 * C_0 * C_0 + 1.5 * C_1 * C_1;
1087  const double B_C2 = 0.5 * C_0 * C_0 - 1.5 * C_1 * C_1;
1088 
1089  TArray2 B_ai, B_am;
1090 
1091  // 1st parts of B_am:
1092  // - R^ak_A'B' F^A'_C' R^ik_C'B' (A': all virtual orbital index)
1093  TArray4d r_akPQ = ijxy("<a k|r|p' q'>");
1094  TArray4d r_kaPQ = ijxy("<k a|r|p' q'>");
1095  TArray4d rik_PKQ = ijxy("<i k|r|p'_K(r') q'>");
1096 
1097  TArray4d r_akPn = ijxy("<a k|r|p' n>");
1098  TArray4d r_kaPn = ijxy("<k a|r|p' n>");
1099  TArray4d rik_PFn = ijxy("<i k|r|p'_F(r') n>");
1100 
1101  TArray4d r_akmA = ijxy("<a k|r|m a'>");
1102  TArray4d r_kamA = ijxy("<k a|r|m a'>");
1103  TArray4d rik_mFA = ijxy("<i k|r|m_F(n) a'>");
1104 
1105  TArray4d r_akpq = ijxy("<a k|r|p b>");
1106  TArray4d r_kapq = ijxy("<k a|r|p b>");
1107  TArray4d rik_pFb = ijxy("<i k|r|p_F(r) b>");
1108 
1109  TArray4d rik_nFA = ijxy("<i k|r|n_F(p') a'>");
1110  //
1111  TArray4d r_ikmA = ijxy("<i k|r|m a'>");
1112  TArray4d rak_nFA = ijxy("<a k|r|n_F(p') a'>");
1113  TArray4d rka_nFA = ijxy("<k a|r|n_F(p') a'>");
1114  TArray4d r_akAb = ijxy("<a k|r|a' b>");
1115  TArray4d r_kaAb = ijxy("<k a|r|a' b>");
1116  TArray4d rik_AFb = ijxy("<i k|r|a'_F(q) b>");
1117  //
1118  TArray4d r_ikAb = ijxy("<i k|r|a' b>");
1119  TArray4d rak_AFb = ijxy("<a k|r|a'_F(q) b>");
1120  TArray4d rka_AFb = ijxy("<k a|r|a'_F(q) b>");
1121 
1122  B_ai("a,i") = // diag
1123  - ( B_C1 * _4("<a k|rTr|i l>") + B_C2 * _4("<k a|rTr|i l>")
1124  // Q
1125  + ( B_C1 * (_4("<a_hJ(p') l|r2|i k>") + _4("<a l_hJ(p')|r2|i k>")
1126  + _4("<a l|r2|i_hJ(p') k>") + _4("<a l|r2|i k_hJ(p')>"))
1127 
1128  + B_C2 * (_4("<l a_hJ(p')|r2|i k>") + _4("<l_hJ(p') a|r2|i k>")
1129  + _4("<l a|r2|i_hJ(p') k>") + _4("<l a|r2|i k_hJ(p')>"))
1130  ) * 0.5
1131  ) * _2("<k|I|l>")
1132  // rKr_p'q'
1133  + ( B_C1 * (r_akPQ("a,k,p',q'") * rik_PKQ("i,k,p',q'")
1134  + r_kaPQ("k,a,p',q'") * rik_PKQ("k,i,p',q'"))
1135 
1136  + B_C2 * (r_kaPQ("k,a,p',q'") * rik_PKQ("i,k,p',q'")
1137  + r_akPQ("a,k,p',q'") * rik_PKQ("k,i,p',q'"))
1138  )
1139  // rFr_p'n
1140  + ( B_C1 * (r_akPn("a,k,p',n") * rik_PFn("i,k,p',n")
1141  + r_kaPn("k,a,p',n") * rik_PFn("k,i,p',n"))
1142 
1143  + B_C2 * (r_kaPn("k,a,p',n") * rik_PFn("i,k,p',n")
1144  + r_akPn("a,k,p',n") * rik_PFn("k,i,p',n"))
1145  )
1146  // rFr_mA
1147  - ( B_C1 * (r_akmA("a,k,m,a'") * rik_mFA("i,k,m,a'")
1148  + r_kamA("k,a,m,a'") * rik_mFA("k,i,m,a'"))
1149 
1150  + B_C2 * (r_kamA("k,a,m,a'") * rik_mFA("i,k,m,a'")
1151  + r_akmA("a,k,m,a'") * rik_mFA("k,i,m,a'"))
1152  )
1153  // rFr_pb
1154  + ( B_C1 * (r_akpq("a,k,p,b") * rik_pFb("i,k,p,b")
1155  + r_kapq("k,a,p,b") * rik_pFb("k,i,p,b"))
1156 
1157  + B_C2 * (r_kapq("k,a,p,b") * rik_pFb("i,k,p,b")
1158  + r_akpq("a,k,p,b") * rik_pFb("k,i,p,b"))
1159  )
1160  //
1161  + ( B_C1 * (r_akmA("a,k,n,a'") * rik_nFA("i,k,n,a'")
1162  + r_kamA("k,a,n,a'") * rik_nFA("k,i,n,a'"))
1163 
1164  + B_C2 * (r_kamA("k,a,n,a'") * rik_nFA("i,k,n,a'")
1165  + r_akmA("a,k,n,a'") * rik_nFA("k,i,n,a'"))
1166 
1167  + B_C1 * (r_ikmA("i,k,n,a'") * rak_nFA("a,k,n,a'")
1168  + r_ikmA("k,i,n,a'") * rka_nFA("k,a,n,a'"))
1169 
1170  + B_C2 * (r_ikmA("k,i,n,a'") * rak_nFA("a,k,n,a'")
1171  + r_ikmA("i,k,n,a'") * rka_nFA("k,a,n,a'"))
1172  )
1173  //
1174  + ( B_C1 * (r_akAb("a,k,a',b") * rik_AFb("i,k,a',b")
1175  + r_kaAb("k,a,a',b") * rik_AFb("k,i,a',b"))
1176 
1177  + B_C2 * (r_kaAb("k,a,a',b") * rik_AFb("i,k,a',b")
1178  + r_akAb("a,k,a',b") * rik_AFb("k,i,a',b"))
1179 
1180  + B_C1 * (r_ikAb("i,k,a',b") * rak_AFb("a,k,a',b")
1181  + r_ikAb("k,i,a',b") * rka_AFb("k,a,a',b"))
1182 
1183  + B_C2 * (r_ikAb("k,i,a',b") * rak_AFb("a,k,a',b")
1184  + r_ikAb("i,k,a',b") * rka_AFb("k,a,a',b"))
1185  );
1186 
1187 // // test codes for computing B_ai for H2O molecule
1188 // const char* a = "a";
1189 // const char* i = "i";
1190 // TArray2 B_ia = Bpk_qk(i,a);
1191 // TArray2 B_ai = Bpk_qk(a,i);
1192 // TArray2 B_ai2 = B_ai("a,i") + B_ia("i,a");
1193 //
1194 // TArray4 B_akil = Bpr_qs(a,i);
1195 // TArray2 B_ai2 = B_akil("a,k,i,l") * _2("<k|I|l");
1196 //
1197 // const char* i = "i";
1198 // const char* j = "j";
1199 // TArray4 B_ijkl = Bpr_qs(i,j);
1200 //
1201 // double sum_Bijij = 0;
1202 // std::cout << "B_ijkl" << std::endl;
1203 // for (std::size_t i = 0; i < 5; ++i) {
1204 // for (std::size_t j = 0; j < 5; ++j) {
1205 // std::vector<std::size_t> indices(4);
1206 // indices[0] = indices[2] = i;
1207 // indices[1] = indices[3] = j;
1208 // sum_Bijij += get_element(B_ijkl, indices);
1209 // }
1210 // }
1211 // std::cout << "Bijkl sum: " << sum_Bijij << std::endl;
1212 
1213  // 2nd parts of B_am:
1214  // 1/2 R^ab'_kl F^c'_m R^c'b'_kl
1215  // + (1/2 R^mb'_kl F^C'_a R^C'b'_kl + 1/2 R^mb'_kl F^c'_b' R^ab'_kl)
1216  TArray4d r_abpkl = ijxy("<a b'|r|k l>");
1217  TArray4d raFpbp_kl = ijxy("<a_F(c') b'|r|k l>");
1218  TArray4d raFbp_kl = ijxy("<a_F(c) b'|r|k l>");
1219  TArray4d rabpFp_kl = ijxy("<a b'_F(c')|r|k l>") ;
1220 
1221  B_am("a,m") = (B_C1 * r_abpkl("a,b',k,l") + B_C2 * r_abpkl("a,b',l,k"))
1222  * _4("<k l|r|m_F(c') b'>")
1223  //
1224  //+ (B_C1 * _4("<a_F(C') b'|r|k l>") + B_C2 *_4("<b' a_F(C')|r|k l>"))
1225  // * _4("<k l|r|i b'>") // do not work for CCR12
1226  + ( B_C1 * raFpbp_kl("a,b',k,l") + B_C2 * raFpbp_kl("a,b',l,k")
1227  + B_C1 * raFbp_kl("a,b',k,l") + B_C2 * raFbp_kl("a,b',l,k"))
1228  * _4("<k l|r|m b'>")
1229  //
1230  + (B_C1 * rabpFp_kl("a,b',k,l") + B_C2 * rabpFp_kl("a,b',l,k"))
1231  * _4("<k l|r|m b'>")
1232  ;
1233 
1234  return XaiAddToXam(B_am, B_ai);
1235  }
1236 
1237  // frozen-core F12 Xii' contribution
1238  template <typename T>
1240  SingleReference_R12Intermediates<T>::Xiip_VBX(const double C_0, const double C_1) {
1241 
1242  const double RR_C1 = 0.5 * C_0 * C_0 + 1.5 * C_1 * C_1;
1243  const double RR_C2 = 0.5 * C_0 * C_0 - 1.5 * C_1 * C_1;
1244 
1245  TArray2 Xiip_V;
1246  const char* ip = "i'";
1247  const char* i = "i";
1248  TArray2 V_ipi = VRk_Sk(ip,i,C_0, C_1);
1249  TArray2 V_iip = VRk_Sk(i,ip,C_0, C_1);
1250  Xiip_V("i,i'") = // 2 * (1/2 R^i'k_A'C' g^A'C'_ik + 1/2 R^ik_A'C' g^A'C'_i'k)
1251  2.0 * (V_ipi("i',i") + V_iip("i,i'"));
1252  // test
1253 // TArray4d gr_ipk_ij = ijxy("<i' k|gr|i j>");
1254 // TArray4d rpq_kl = ijxy("<p q|r|k l>");
1255 // TArray4d rapn_kl = ijxy("<a' n|r|k l>");
1256 // TArray4d rnap_kl = ijxy("<n a'|r|k l>");
1257 // TArray4d rpq_ipk = ijxy("<p q|r|i' k>");
1258 // TArray2 Ikl = xy("<k|I|l>");
1259 // Xiip_V("i,i'") = // 1/2 R^ik_AC g^AC_i'k
1260 // ( (R_C1 * gr_ipk_ij("i',k,i,l") + R_C2 * gr_ipk_ij("i',k,l,i"))
1261 // * Ikl("k,l")
1262 // - _4("<i' k|g|p q>")
1263 // * ( R_C1 * rpq_kl("p,q,i,k") + R_C2 * rpq_kl("p,q,k,i") )
1264 // - _4("<i' k|g|a' n>")
1265 // * ( R_C1 * rapn_kl("a',n,i,k") + R_C2 * rapn_kl("a',n,k,i"))
1266 // - _4("<i' k|g|n a'>")
1267 // * ( R_C1 * rnap_kl("n,a',i,k") + R_C2 * rnap_kl("n,a',k,i"))
1268 // ) * 2.0
1269 // // 1/2 R^i'k_AC g^AC_ik
1270 // + ( (R_C1 * gr_ipk_ij("i',l,i,k") + R_C2 * gr_ipk_ij("i',l,k,i"))
1271 // * Ikl("k,l")
1272 // - _4("<i k|g|p q>")
1273 // * ( R_C1 * rpq_ipk("p,q,i',k") + R_C2 * rpq_ipk("q,p,i',k"))
1274 // - _4("<i k|g|a' n>")
1275 // * ( R_C1 * _4("<a' n|r|i' k>") + R_C2 * _4("<a' n|r|k i'>"))
1276 // - _4("<i k|g|n a'>")
1277 // * ( R_C1 * _4("<n a'|r|i' k>") + R_C2 * _4("<n a'|r|k i'>"))
1278 // ) * 2.0;
1279 
1280  TArray2 Xiip_X;
1281  TArray2 F_ij = xy("<i|F|j>");
1282  TArray4d r2_ipk_jl = ijxy("<i' k|r2|j l>");
1283  TArray4d r_ipk_pq = ijxy("<i' k|r|p q>");
1284  TArray4d r_pqkl = ijxy("<p q|r|k l>");
1285  TArray4d r_ipk_apn = ijxy("<i' k|r|a' n>");
1286  TArray4d r_apn_kl = ijxy("<a' n|r|k l>");
1287  TArray4d r_kip_apn = ijxy("<k i'|r|a' n>");
1288  Xiip_X("i,i'") = // 2 * (F^i_i + F^k_k) 1/2 R^i'k_A'B' R_ik^A'B'
1289  2.0 * ( (RR_C1 * r2_ipk_jl("i',k,j,l") + RR_C2 * r2_ipk_jl("i',k,l,j"))
1290  * _2("<l|I|k>") * F_ij("j,i")
1291  + (RR_C1 * r2_ipk_jl("i',k,i,l") + RR_C2 * r2_ipk_jl("i',k,l,i"))
1292  * F_ij("l,k")
1293 
1294  - (RR_C1 * r_ipk_pq("i',k,p,q") + RR_C2 * r_ipk_pq("i',k,q,p"))
1295  * ( r_pqkl("p,q,j,k") * F_ij("j,i")
1296  + r_pqkl("p,q,i,l") * F_ij("l,k"))
1297 
1298  - (RR_C1 * r_ipk_apn("i',k,a',n") + RR_C2 * r_kip_apn("k,i',a',n"))
1299  * ( r_apn_kl("a',n,j,k") * F_ij("j,i")
1300  + r_apn_kl("a',n,i,l") * F_ij("l,k"))
1301 
1302  - (RR_C1 * r_kip_apn("k,i',a',n") + RR_C2 * r_ipk_apn("i',k,a',n"))
1303  * ( r_apn_kl("a',n,k,j") * F_ij("j,i")
1304  + r_apn_kl("a',n,l,i") * F_ij("l,k"))
1305  );
1306 
1307  TArray2 Xiip_B;
1308  TArray2 B_ipi = BPk_Qk(ip,i,C_0,C_1);
1309  Xiip_B("i,i'") = // 2 R^i'k_A'B' F^A'_C' R^ik_C'B'
1310  2.0 * B_ipi("i',i");
1311 
1312  TArray2 Xiip_f12;
1313  Xiip_f12("i,i'") = Xiip_V("i,i'") - Xiip_X("i,i'") + Xiip_B("i,i'");
1314  return Xiip_f12;
1315  }
1316 
1317  // frozen-core Xii' contribution from CCSD F12 coupling
1318  template <typename T>
1320  SingleReference_R12Intermediates<T>::Xiip_CVT(const double C_0, const double C_1,
1321  const TArray2& T1, const TArray4& T2){
1322 
1323  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
1324  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
1325 
1326  TArray2 Xiip_CT2;
1327  Xiip_CT2("i,i'") = // 2 F^a'_b R^i'l_a'c T2^bc_il
1328  2.0 * ( _4("<i' l|r|b_F(a') c>")
1329  * (R_C1 * T2("b,c,i,l") + R_C2 * T2("b,c,l,i"))
1330  + _4("<i' l|r|c b_F(a')>")
1331  * (R_C1 * T2("c,b,i,l") + R_C2 * T2("c,b,l,i"))
1332  );
1333 
1334  TArray2 Xiip_VT2;
1335  const char* ip = "i'";
1336  const char* i = "i";
1337  const char* l = "l";
1338  const char* c = "c";
1339  const char* d = "d";
1340  TArray4 V_ipl_cd = VPq_Rs(ip,l,c,d,C_0, C_1);
1341  Xiip_VT2("i,i'") = // 2 * 1/4 R^i'l_A'B' g^A'B'_cd T^cd_il
1342  2.0 * V_ipl_cd("i',l,c,d") * T2("c,d,i,l");
1343 
1344  TArray2 Xiip_VT1;
1345  TArray4 V_ipl_ic = VPq_Rs(ip,l,i,c, C_0, C_1);
1346  TArray4 V_il_ipc = VPq_Rs(i,l,ip,c,C_0, C_1);
1347  TArray2 V_ipc = VRk_Sk(ip,c,C_0, C_1);
1348  Xiip_VT1("i,i'") = // 2 *
1349  2.0 * ( // 1/2 R^i'l_A'B' g^A'B'_ic t1^c_l
1350  // 1/2 R^il_A'B' g^A'B'_i'c t1^c_l
1351  (V_ipl_ic("i',l,i,c") + V_il_ipc("i,l,i',c")) * T1("c,l")
1352 
1353  // 1/2 R^i'k_A'B' g^A'B'_ck t1^c_i
1354  + V_ipc("i',c") * T1("c,i")
1355  );
1356 
1357  TArray2 Xiip_C;
1358  Xiip_C("i,i'") = Xiip_CT2("i,i'") + Xiip_VT2("i,i'") + Xiip_VT1("i,i'");
1359  return Xiip_C;
1360  }
1361 
1362  // Xam contribution of CT2 part resulted from CCSD F12 coupling
1363  template <typename T>
1365  SingleReference_R12Intermediates<T>::Xam_CT2_ccsd(const double C_0, const double C_1,
1366  const TArray4& T2, const TArray2& RT2_aPb) {
1367  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
1368  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
1369 
1370  TArray4d g_abmaP = ijxy("<a b|g|m a'>");
1371  TArray2 Xam_CT2, Xai_CT2;
1372  Xam_CT2("a,m") = 2.0 * ( // + 1/2 F^a'_m R^kl_a'b T2^ab_kl
1373  // + 1/2 F^a'_b R^kl_ma' T2^ab_kl
1374  (R_C1 * T2("a,b,k,l") + R_C2 * T2("b,a,k,l"))
1375  * (_4("<k l|r|m_F(a') b>") + _4("<k l|r|m b_F(a')>"))
1376  //RT2_aPb("a',a") * _2("<a'|F|m>")
1377 
1378  // - g^aa'_mb 1/2 R^kl_a'c T2^bc_kl
1379  // - g^ab_ma' 1/2 R^kl_a'c T2^bc_kl
1380  - ( 2.0 * _4("<a a'|g|m b>") - _4("<a a'|g|b m>")
1381  + 2.0 * g_abmaP("a,b,m,a'") - g_abmaP("b,a,m,a'")
1382  ) * RT2_aPb("a',b")
1383  );
1384  Xai_CT2("a,i") = 2.0 * ( // - F^a'_b R^al_a'c T2^bc_il
1385  - _4("<a l|r|b_F(a') c>")
1386  * (R_C1 * T2("b,c,i,l") + R_C2 * T2("b,c,l,i"))
1387  - _4("<a l|r|c b_F(a')>")
1388  * (R_C1 * T2("c,b,i,l") + R_C2 * T2("c,b,l,i"))
1389  );
1390 
1391  return XaiAddToXam(Xam_CT2, Xai_CT2);
1392  }
1393 
1394  // Xam contribution of VT(T1&T2) part resulted from CCSD F12 coupling
1395  template <typename T>
1397  SingleReference_R12Intermediates<T>::Xam_VT_ccsd(const double C_0, const double C_1,
1398  const TArray2& T1, const TArray4& T2) {
1399 
1400  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
1401  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
1402 
1403  const char* i = "i";
1404  const char* j = "j";
1405  const char* k = "k";
1406  const char* l = "l";
1407  const char* m = "m";
1408 
1409  const char* a = "a";
1410  const char* c = "c";
1411  const char* d = "d";
1412 
1413  TArray4 V_alic = VPq_Rs(a,l,i,c, C_0, C_1);
1414  TArray4 V_ilac = VPq_Rs(i,l,a,c,C_0, C_1);
1415  TArray2 V_ac = VRk_Sk(a,c,C_0, C_1);
1416  TArray2 V_jm = VRk_Sk(j,m,C_0, C_1);
1417  TArray4d r_klmaP = ijxy("<k l|r|m a'>");
1418  TArray4d r_abPkl = ijxy("<a b'|r|k l>");
1419  TArray2 Xam_VT1, Xai_VT1;
1420  Xam_VT1("a,m") = 2.0 * ( // + 1/2 R^jk_A'B' g^A'B'_mk t1^a_j
1421  T1("a,j") * V_jm("j,m")
1422 // // test
1423 // ( (R_C1 * _4("<j k|gr|m l>") + R_C2 * _4("<k j|gr|m l>"))
1424 // * _2("<k|I|l>")
1425 // - (R_C1 * _4("<j k|r|p q>") + R_C2 * _4("<k j|r|p q>"))
1426 // * _4("<p q|g|m k>")
1427 // - (R_C1 * _4("<j k|r|a' n>") + R_C2 * _4("<k j|r|a' n>"))
1428 // * _4("<a' n|g|m k>")
1429 // - (R_C1 * _4("<j k|r|n a'>") + R_C2 * _4("<k j|r|n a'>"))
1430 // * _4("<n a'|g|m k>")
1431 // )
1432 
1433  + ( // + R^kl_mb' g^ab'_kc t1^c_l
1434  _4("<a b'|g|k c>")
1435  * (R_C1 * r_klmaP("k,l,m,b'") + R_C2 * r_klmaP("l,k,m,b'"))
1436  + _4("<a b'|g|c k>")
1437  * (R_C1 * r_klmaP("l,k,m,b'") + R_C2 * r_klmaP("k,l,m,b'"))
1438  // + R^kl_ab' g^mb'_kc t1^c_l
1439  + (R_C1 * r_abPkl("a,b',k,l") + R_C2 * r_abPkl("a,b',l,k"))
1440  * _4("<k c|g|m b'>")
1441  + (R_C1 * r_abPkl("a,b',l,k") + R_C2 * r_abPkl("a,b',k,l"))
1442  * _4("<c k|g|m b'>")
1443  ) * T1("c,l")
1444  );
1445  Xai_VT1("a,i") = 2.0 * ( // - 1/2 R^al_A'B' g^A'B'_ic t1^c_l
1446  // - 1/2 R^il_A'B' g^A'B'_ac t1^c_l
1447  - (V_alic("a,l,i,c") + V_ilac("i,l,a,c")) * T1("c,l")
1448 
1449  // - 1/2 R^ak_A'B' g^A'B'_ck t1^c_i
1450  - V_ac("a,c") * T1("c,i")
1451 // // test
1452 // ( (R_C1 * _4("<a k|gr|c l>") + R_C2 * _4("<k a|gr|c l>"))
1453 // * _2("<k|I|l>")
1454 // - (R_C1 * _4("<a k|r|p q>") + R_C2 * _4("<k a|r|p q>"))
1455 // * _4("<p q|g|c k>")
1456 // - (R_C1 * _4("<a k|r|a' n>") + R_C2 * _4("<k a|r|a' n>"))
1457 // * _4("<a' n|g|c k>")
1458 // - (R_C1 * _4("<a k|r|n a'>") + R_C2 * _4("<k a|r|n a'>"))
1459 // * _4("<n a'|g|c k>")
1460 // )
1461  );
1462  TArray2 Xam_VT1_tot = XaiAddToXam(Xam_VT1, Xai_VT1);
1463 
1464  TArray4 V_alcd = VPq_Rs(a,l,c,d,C_0, C_1);
1465  TArray4 V_klmd = VPq_Rs(k,l,m,d,C_0, C_1);
1466  TArray2 Xam_VT2, Xai_VT2;
1467  Xam_VT2("a,m") = 2.0 * ( // 1/4 R^kl_A'B' g^A'B'_md T^ad_kl
1468  T2("a,d,k,l") * V_klmd("k,l,m,d")
1469 
1470  + ( // + 1/4 R^kl_ab' g^mb'_cd T^cd_kl
1471  (R_C1 * r_abPkl("a,b',k,l") + R_C2 * r_abPkl("a,b',l,k"))
1472  * _4("<c d|g|m b'>")
1473  // + 1/4 R^kl_mb' g^ab'_cd T^cd_kl
1474  + _4("<a b'|g|c d>")
1475  * (R_C1 * r_klmaP("k,l,m,b'") + R_C2 * r_klmaP("l,k,m,b'"))
1476  ) * T2("c,d,k,l")
1477  );
1478  Xai_VT2("a,i") = 2.0 * ( // - 1/4 R^al_A'B' g^A'B'_cd T^cd_il
1479  - V_alcd("a,l,c,d") * T2("c,d,i,l")
1480  );
1481  TArray2 Xam_VT2_tot = XaiAddToXam(Xam_VT2, Xai_VT2);
1482 
1483  TArray2 Xam_VT_tot;
1484  Xam_VT_tot("a,m") = Xam_VT1_tot("a,m") + Xam_VT2_tot("a,m");
1485  return Xam_VT_tot;
1486  }
1487 
1488  // compute T1 & T2 amplitudes of CC2
1489  template <typename T>
1490  void SingleReference_R12Intermediates<T>::compute_T_cc2(TArray2& t1, TArray4& t2) {
1491 
1492  TArray2 fij = xy("<j|F|j>");
1493  TArray2 fab = xy("<a|F|b>");
1494  TArray2 fai = xy("<a|F|i>");
1495 
1496  // compute Delta_ai = 1 / (- <a|F|a> + <i|F|i>)
1497  typedef detail::diag_precond2<double> pceval_type;
1498  pceval_type Delta_ai_gen(TA::array_to_eigen(fab), TA::array_to_eigen(fij));
1499 
1500  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2dLazy;
1501  TArray2dLazy Delta_ai(fai.world(), fai.trange());
1502 
1503  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
1504  // construct local tiles
1505  for(auto t = Delta_ai.trange().tiles_range().begin();
1506  t != Delta_ai.trange().tiles_range().end(); ++t)
1507  if (Delta_ai.is_local(*t)) {
1508  std::array<std::size_t, 2> index;
1509  std::copy(t->begin(), t->end(), index.begin());
1510  madness::Future < typename TArray2dLazy::value_type >
1511  tile((LazyTensor<T, 2, pceval_type >(&Delta_ai, index, &Delta_ai_gen)
1512  ));
1513 
1514  // Insert the tile into the array
1515  Delta_ai.set(*t, tile);
1516  }
1517 
1518  // compute Delta_ijab = 1 / (- <a|F|a> - <b|F|b> + <i|F|i> + <j|F|j>)
1519  typedef detail::diag_precond4<double> pc4eval_type;
1520  pc4eval_type Delta_abij_gen(TA::array_to_eigen(fab), TA::array_to_eigen(fab),
1521  TA::array_to_eigen(fij),TA::array_to_eigen(fij));
1522 
1523  TArray4d g_abij = ijxy("<a b|g|i j>");
1524  typedef TA::Array<T, 4, LazyTensor<T, 4, pc4eval_type > > TArray4dLazy;
1525  TArray4dLazy Delta_abij(g_abij.world(), g_abij.trange());
1526 
1527  // construct local tiles
1528  for(auto t = Delta_abij.trange().tiles_range().begin();
1529  t != Delta_abij.trange().tiles_range().end(); ++t)
1530  if (Delta_abij.is_local(*t)) {
1531  std::array<std::size_t, 4> index;
1532  std::copy(t->begin(), t->end(), index.begin());
1533  madness::Future < typename TArray4dLazy::value_type >
1534  tile((LazyTensor<T, 4, pc4eval_type >(&Delta_abij, index, &Delta_abij_gen)
1535  ));
1536 
1537  // Insert the tile into the array
1538  Delta_abij.set(*t, tile);
1539  }
1540 
1541  // compute initial T1 & T2 amplitudes and energy
1542  t1("a,i") = fai("a,i") * Delta_ai("a,i");
1543  t2("a,b,i,j") = g_abij("a,b,i,j") * Delta_abij("a,b,i,j");
1544  TArray4 tau;
1545  tau("a,b,i,j") = t2("a,b,i,j") + t1("a,i") * t1("b,j");
1546 
1547  double E_0 = 0.0;
1548  double E_1 = 2.0 * dot(fai("a,i"), t1("a,i"))
1549  + dot((2.0 * g_abij("a,b,i,j") - g_abij("b,a,i,j")), tau("a,b,i,j") );
1550  double Delta_E = std::abs(E_0 - E_1);
1551 
1552  TArray2 Iij = xy("<i|I|j>");
1553  TArray2 Iab = xy("<a|I|b>");
1554 
1555  TArray4d g_iabj = ijxy("<i a|g|b j>");
1556  TArray4d g_iajb = ijxy("<i a|g|j b>");
1557  TArray4d g_iacd = ijxy("<i a|g|c d>");
1558  TArray4d g_aicd = ijxy("<a i|g|c d>");
1559  TArray4d g_klai = ijxy("<k l|g|a i>");
1560  TArray4d g_klia = ijxy("<k l|g|i a>");
1561  TArray4d g_ijkl = ijxy("<i j|g|k l>");
1562  TArray4d g_abcd = ijxy("<a b|g|c d>");
1563 
1564  TArray2 hac, hki, hck;
1565  TArray4 a_klij, b_abcd;
1566 
1567  double iter = 0;
1568  std::cout << indent << scprintf("%-5s", "Iter") << scprintf("%-20s", "Delta_E")
1569  << scprintf("%-20s", "E(CC2)") << std::endl;
1570  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-20.10f", Delta_E)
1571  << scprintf("%-15.10f", E_1) << std::endl;
1572 
1573  while (Delta_E >= 1.0e-12) {
1574 
1575  // recompute T1 and T2 amplitudes
1576  hac("a,c") = //- fab("a,c") * (Iab("a,c") - 1.0)
1577  - (2.0 * g_abij("c,d,k,l") - g_abij("c,d,l,k")) * tau("a,d,k,l");
1578  hki("k,i") = //fij("k,i") * (1.0 - Iab("k,i"))
1579  //+
1580  (2.0 * g_abij("c,d,k,l") - g_abij("d,c,k,l")) * tau("c,d,i,l");
1581  hck("c,k") = fai("c,k")
1582  + (2.0 * g_abij("c,d,k,l") - g_abij("d,c,k,l")) * t1("d,l");
1583 
1584  t1("a,i") = Delta_ai("a,i") * (
1585  //
1586  fai("a,i") - 2.0 * fai("c,k") * t1("a,k") * t1("c,i")
1587  //
1588  + t1("c,i") * hac("a,c") - t1("a,k") * hki("k,i")
1589  //
1590  + hck("c,k")
1591  * (2.0 * t2("c,a,k,i") - t2("c,a,i,k") + t1("c,i") * t1("a,k"))
1592  //
1593  + (2.0 * g_iabj("k,a,c,i") - g_iajb("k,a,i,c")) * t1("c,k")
1594  //
1595  + (2.0 * g_iacd("k,a,c,d") - g_iacd("k,a,d,c")) * tau("c,d,k,i")
1596  //
1597  - (2.0 * g_klai("k,l,c,i") - g_klai("l,k,c,i")) * tau("c,a,k,l")
1598  );
1599 
1600  a_klij("k,l,i,j") = g_ijkl("k,l,i,j")
1601  + g_klia("k,l,i,c") * t1("c,j") + g_klai("k,l,c,j") * t1("c,i")
1602  + g_abij("c,d,k,l") * t1("c,i") * t1("d,j");
1603  b_abcd("a,b,c,d") = g_abcd("a,b,c,d")
1604  - g_aicd("a,k,c,d") * t1("b,k") - g_iacd("k,b,c,d") * t1("a,k");
1605 
1606  t2("a,b,i,j") = Delta_abij("a,b,i,j") * (
1607  //
1608  g_abij("a,b,i,j")
1609  //
1610  + a_klij("k,l,i,j") * t1("a,k") * t1("b,l")
1611  //
1612  + b_abcd("a,b,c,d") * t1("c,i") * t1("d,j")
1613  //
1614  //+ (fab("a,c") * t2("c,b,i,j") + fab("b,c") * t2("a,c,i,j"))
1615  // * (1.0 - Iab("a,c"))
1616  //+ (fij("k,i") * t2("a,b,k,j") + fij("k,j") * t2("a,c,i,k"))
1617  // * (1 - Iij("k,i"))
1618  //
1619  + (g_iacd("i,c,a,b") - g_iajb("k,b,i,c") * t1("a,k")) * t1("c,j")
1620  + (g_iacd("j,c,b,a") - g_iajb("k,a,j,c") * t1("b,k")) * t1("c,i")
1621  //
1622  - (g_klai("i,j,a,k") + g_iabj("i,c,a,k") * t1("c,j")) * t1("b,k")
1623  - (g_klai("j,i,b,k") + g_iabj("j,c,b,k") * t1("c,i")) * t1("a,k")
1624  );
1625  tau("a,b,i,j") = t2("a,b,i,j") + t1("a,i") * t1("b,j");
1626 
1627  // recompute energy
1628  E_0 = E_1;
1629  E_1 = 2.0 * dot(fai("a,i"), t1("a,i"))
1630  + dot((2.0 * g_abij("a,b,i,j") - g_abij("b,a,i,j")), tau("a,b,i,j") );
1631  Delta_E = std::abs(E_0 - E_1);
1632  iter += 1;
1633  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-20.10f", Delta_E)
1634  << scprintf("%-15.10f", E_1) << std::endl;
1635  }
1636  //std::cout << "CC2 T1 amplitudes: " << std::endl << t1 << std::endl;
1637 
1638  }
1639 
1640  // compute lambda amplitudes of CC2
1641  // using formula from JCP 87, 5361 (1987)
1642  template <typename T>
1643  void SingleReference_R12Intermediates<T>::compute_lambda_cc2(const TArray2& t1, const TArray4& t2,
1644  TArray2& L1, TArray4& L2) {
1645 
1646  TArray2 fij = xy("<j|F|j>");
1647  TArray2 fab = xy("<a|F|b>");
1648  TArray2 fai = xy("<a|F|i>");
1649 
1650  // compute Delta_ai = 1 / (- <a|F|a> + <i|F|i>)
1651  typedef detail::diag_precond2<double> pceval_type;
1652  pceval_type Delta_ai_gen(TA::array_to_eigen(fab), TA::array_to_eigen(fij));
1653 
1654  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2dLazy;
1655  TArray2dLazy Delta_ai(fai.world(), fai.trange());
1656 
1657  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
1658  // construct local tiles
1659  for(auto t = Delta_ai.trange().tiles_range().begin();
1660  t != Delta_ai.trange().tiles_range().end(); ++t)
1661  if (Delta_ai.is_local(*t)) {
1662  std::array<std::size_t, 2> index;
1663  std::copy(t->begin(), t->end(), index.begin());
1664  madness::Future < typename TArray2dLazy::value_type >
1665  tile((LazyTensor<T, 2, pceval_type >(&Delta_ai, index, &Delta_ai_gen)
1666  ));
1667 
1668  // Insert the tile into the array
1669  Delta_ai.set(*t, tile);
1670  }
1671 
1672  // compute Delta_ijab = 1 / (- <a|F|a> - <b|F|b> + <i|F|i> + <j|F|j>)
1673  typedef detail::diag_precond4<double> pc4eval_type;
1674  pc4eval_type Delta_abij_gen(TA::array_to_eigen(fab), TA::array_to_eigen(fab),
1675  TA::array_to_eigen(fij),TA::array_to_eigen(fij));
1676 
1677  TArray4d g_abij = ijxy("<a b|g|i j>");
1678  typedef TA::Array<T, 4, LazyTensor<T, 4, pc4eval_type > > TArray4dLazy;
1679  TArray4dLazy Delta_abij(g_abij.world(), g_abij.trange());
1680 
1681  // construct local tiles
1682  for(auto t = Delta_abij.trange().tiles_range().begin();
1683  t != Delta_abij.trange().tiles_range().end(); ++t)
1684  if (Delta_abij.is_local(*t)) {
1685  std::array<std::size_t, 4> index;
1686  std::copy(t->begin(), t->end(), index.begin());
1687  madness::Future < typename TArray4dLazy::value_type >
1688  tile((LazyTensor<T, 4, pc4eval_type >(&Delta_abij, index, &Delta_abij_gen)
1689  ));
1690 
1691  // Insert the tile into the array
1692  Delta_abij.set(*t, tile);
1693  }
1694 
1695  L1("a,i") = t1("a,i");
1696  L2("a,b,i,j") = t2("a,b,i,j");
1697 
1698  TArray4 tau;
1699  tau("a,b,i,j") = t2("a,b,i,j") + t1("a,i") * t1("b,j");
1700 
1701  // pseudo energy
1702  double E_0_L = 0.0;
1703  double E_1_L = dot((2.0 * g_abij("a,b,i,j") - g_abij("b,a,i,j")), L2("a,b,i,j") );
1704  double Delta_E_L = std::abs(E_0_L - E_1_L);
1705 
1706 
1707  TArray4d g_abci = ijxy("<a b|g|c i>"); // g_aicd = ijxy("<a i|g|c d>");
1708  TArray4d g_aikl = ijxy("<a i|g|k l>"); // g_klia = ijxy("<k l|g|i a>");
1709  TArray4d g_aibj = ijxy("<a i|g|b j>"); // g_iajb = ijxy("<i a|g|j b>");
1710  TArray4d g_aijb = ijxy("<a i|g|j b>"); // g_iabj = ijxy("<i a|g|b j>");
1711  TArray4d g_ijkl = ijxy("<i j|g|k l>");
1712  TArray4d g_abcd = ijxy("<a b|g|c d>");
1713 
1714  double iter = 0;
1715  std::cout << indent << scprintf("%-5s", "Iter") << scprintf("%-20s", "Delta_E_L")
1716  << scprintf("%-20s", "E_L(CC2)") << std::endl;
1717  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-20.10f", Delta_E_L)
1718  << scprintf("%-15.10f", E_1_L) << std::endl;
1719 
1720  // intermediates for L1 & L2
1721  TArray2 Iai, Gac, Kki, Iai_L2;
1722  TArray4 R_akic, Q_akic, A_klim, E_klic, B_aecd, F_akcd;
1723  TArray4 H_abcj, J_kbij;
1724 
1725  Iai("a,i") = fai("a,i")
1726  + (2.0 * g_abij("a,c,i,k") - g_abij("a,c,k,i")) * t1("c,k");
1727  //TArray4 I_abij; I_abij("a,b,i,j") = g_abij("a,b,i,j");
1728 
1729  Gac("a,c") = //- fab("a,c") * (1.0 - Iab("a,c")) +
1730  // fai("a,k") * t1("c,k")
1731  - (2.0 * g_abci("a,d,c,k") - g_abci("d,a,c,k")) * t1("d,k")
1732  + (2.0 * g_abij("a,d,k,l") - g_abij("a,d,l,k")) * tau("c,d,k,l");
1733 
1734  Kki("k,i") = //fij("k,i") * (1.0 - Iij("k,i")) +
1735  fai("c,i") * t1("c,k")
1736  + (2.0 * g_aikl("c,k,l,i") - g_aikl("c,k,i,l")) * t1("c,l")
1737  + (2.0 * g_abij("c,d,i,l") - g_abij("c,d,l,i")) * tau("c,d,k,l");
1738 
1739  R_akic("a,k,i,c") = g_aibj("a,k,c,i") + g_abci("a,d,c,i") * t1("d,k")
1740  - g_aikl("a,k,l,i") * t1("c,l")
1741  - g_abij("a,d,l,i") * tau("c,d,l,k")
1742  ;
1743 
1744  Q_akic("a,k,i,c") = g_aijb("a,k,i,c") + g_abci("d,a,c,i") * t1("d,k")
1745  - g_aikl("a,k,i,l") * t1("c,l")
1746  - g_abij("a,d,l,i") * t2("c,d,k,l")
1747  + g_abij("a,d,i,l") * (2.0 * t2("c,d,k,l") - tau("c,d,l,k"))
1748  ;
1749 
1750  A_klim("k,l,i,m") = - (2.0 * g_ijkl("k,l,i,m") - g_ijkl("k,l,m,i"))
1751  - (2.0 * g_abij("c,d,i,m") - g_abij("c,d,m,i")) * t1("c,k") * t1("d,l")
1752  - (2.0 * g_aikl("c,l,i,m") - g_aikl("c,l,m,i")) * t1("c,k")
1753  - (2.0 * g_aikl("c,k,m,i") - g_aikl("c,k,i,m")) * t1("c,l");
1754 
1755  E_klic("k,l,i,c") = 2.0 * g_aikl("c,i,l,k") - g_aikl("c,i,k,l")
1756  // a^kl_im tcm
1757  + A_klim("k,l,i,m") * t1("c,m")
1758  //
1759  + (2.0 * g_abci("e,d,c,i") - g_abci("d,e,c,i")) * t1("d,k") * t1("e,l")
1760  //
1761  + (2.0 * g_aijb("d,l,i,c") - g_aibj("d,l,c,i")) * t1("d,k")
1762  + (2.0 * g_aibj("d,k,c,i") - g_aijb("d,k,i,c")) * t1("d,l")
1763  ;
1764 
1765  B_aecd("a,e,c,d") = - (2.0 * g_abcd("a,e,c,d") - g_abcd("e,a,c,d"))
1766  - (2.0 * g_abij("a,e,k,l") - g_abij("e,a,k,l")) * t1("c,k") * t1("d,l")
1767  + (2.0 * g_abci("e,a,d,k") - g_abci("a,e,d,k")) * t1("c,k")
1768  + (2.0 * g_abci("a,e,c,k") - g_abci("e,a,c,k")) * t1("d,k");
1769 
1770  F_akcd("a,k,c,d") = - (2.0 * g_abci("c,d,a,k") - g_abci("d,c,a,k"))
1771  // b^ae_cd tek
1772  + B_aecd("a,e,c,d") * t1("e,k")
1773  //
1774  - (2.0 * g_aikl("a,k,m,l") - g_aikl("a,k,l,m")) * t1("d,l") * t1("c,m")
1775  //
1776  + (2.0 * g_aibj("a,k,c,l") - g_aijb("a,k,l,c")) * t1("d,l")
1777  + (2.0 * g_aijb("a,k,l,d") - g_aibj("a,k,d,l")) * t1("c,l")
1778  ;
1779 
1780  H_abcj("a,b,c,j") = - g_abci("a,b,c,j")
1781  + g_abij("a,b,k,j") * t1("c,k");
1782 
1783  J_kbij("k,b,i,j") = g_aikl("b,k,j,i")
1784  + g_abij("b,c,j,i") * t1("c,k");
1785 
1786  while (Delta_E_L >= 1.0e-12) {
1787 
1788  // close-shell L^a_i & alpha-beta case L^ab_ij
1789  L1("a,i") = Delta_ai("a,i") * (
1790  // Iai
1791  Iai("a,i")
1792  // Gac Lci
1793  - Gac("a,c") * L1("c,i")
1794  // Kki Lak
1795  - Kki("k,i") * L1("a,k")
1796  // (R - 2Q)ak_ic Lck
1797  - (R_akic("a,k,i,c") - 2.0 * Q_akic("a,k,i,c")) * L1("c,k")
1798  // E^kl_ic L2^ac_kl
1799  - E_klic("k,l,i,c") * L2("a,c,k,l")
1800  // F^ak_cd L2^cd_ik
1801  - F_akcd("a,k,c,d") * L2("c,d,i,k")
1802  );
1803 
1804  L2("a,b,i,j") = Delta_abij("a,b,i,j") * (
1805  // I^ab_ij
1806  g_abij("a,b,i,j")
1807 
1808  // Ibi Laj + Iaj Lbi
1809  //- L1("a,j") * Iai("b,i")
1810  //- L1("b,i") * Iai("a,j")
1811 
1812  // Ibj Lai + Iai Lbj
1813  + L1("a,i") * Iai("b,j")
1814  + L1("b,j") * Iai("a,i")
1815 
1816  // Gbc L^ac_ij + Gac L^bc_ji
1817  // CC2: Gbc = - fbc (1 - delta_bc) = 0
1818  //+ fab("b,c") * (1.0 - Iab("b,c")) * L2("a,c,i,j")
1819  //+ fab("a,c") * (1.0 - Iab("a,c")) * L2("b,c,j,i")
1820 
1821  // Kkj L^ab_ik + Kki L^ba_jk
1822  // CC2: Kkj = fkj (1 - delta_kj) = 0
1823  //- fij("k,j") * (1.0 - Iij("k,j")) * L2("a,b,i,k")
1824  //- fij("k,i") * (1.0 - Iij("k,i")) * L2("b,a,j,k")
1825 
1826  // H^ab_cj Lci + H^ba_ci Lcj
1827  - H_abcj("a,b,c,j") * L1("c,i")
1828  - H_abcj("b,a,c,i") * L1("c,j")
1829 
1830  // J^kb_ij Lak - j^ka_ji Lbk
1831  - J_kbij("k,b,i,j") * L1("a,k")
1832  - J_kbij("k,a,j,i") * L1("b,k")
1833  );
1834 
1835 #if 0 // close-shell L^a_i & alpha-beta case L^ab_ij in explicit form
1836 
1837  L1("a,i") = Delta_ai("a,i") * (
1838  // Iai
1839  fai("a,i")
1840  + (2.0 * g_abij("a,b,i,j") - g_abij("a,b,j,i")) * t1("b,j")
1841 
1842  // Gac Lci
1843  - ( fai("a,j") * t1("c,j")
1844  - (2.0 * g_abci("a,b,c,j") - g_abci("b,a,c,j")) * t1("b,j")
1845  + (2.0 * g_abij("a,d,k,l") - g_abij("a,d,l,k")) * tau("c,d,k,l"))
1846  * L1("c,i")
1847 
1848  // Kki Lak
1849  - ( fai("c,i") * t1("c,k")
1850  + (2.0 * g_aikl("b,k,j,i") - g_aikl("b,k,i,j")) * t1("b,j")
1851  + (2.0 * g_abij("c,d,i,l") - g_abij("c,d,l,i")) * tau("c,d,k,l"))
1852  * L1("a,k")
1853 
1854  // (R - 2Q)ak_ic Lck
1855  + ( 2.0 * g_aijb("a,k,i,c") - g_aibj("a,k,c,i")
1856  + (2.0 * g_abci("b,a,c,i") - g_abci("a,b,c,i")) * t1("b,k")
1857  - (2.0 * g_aikl("a,k,i,l") - g_aikl("a,k,l,i")) * t1("c,l")
1858  - (2.0 * g_abij("a,b,i,j") - g_abij("a,b,j,i")) * t1("c,j") * t1("b,k")
1859  + (2.0 * g_abij("a,b,i,j") - g_abij("a,b,j,i"))
1860  * (2.0 * t2("c,b,k,j") - t2("c,b,j,k"))
1861  ) * L1("c,k")
1862 
1863  // E^kl_ic L2^ac_kl
1864  - ( 2.0 * g_aikl("b,i,l,k") - g_aikl("b,i,k,l")
1865  // a^kl_im tcm
1866  + ( - (2.0 * g_ijkl("k,l,i,j") - g_ijkl("k,l,j,i"))
1867  - (2.0 * g_abij("c,d,i,j") - g_abij("c,d,j,i")) * t1("c,k") * t1("d,l")
1868 
1869  - (2.0 * g_aikl("c,l,i,j") - g_aikl("c,l,j,i")) * t1("c,k")
1870  - (2.0 * g_aikl("c,k,j,i") - g_aikl("c,k,i,j")) * t1("c,l")
1871  ) * t1("b,j")
1872  //
1873  + (2.0 * g_abci("d,c,b,i") - g_abci("c,d,b,i")) * t1("d,l") * t1("c,k")
1874  //
1875  + (2.0 * g_aijb("c,l,i,b") - g_aibj("c,l,b,i")) * t1("c,k")
1876  + (2.0 * g_aibj("c,k,b,i") - g_aijb("c,k,i,b")) * t1("c,l")
1877  ) * L2("a,b,k,l")
1878 
1879  // F^ak_cd L2^cd_ik
1880  - ( - 2.0 * g_abci("c,d,a,j") - g_abci("d,c,a,j")
1881  // b^ae_cd tek
1882  + ( - (2.0 * g_abcd("a,b,c,d") - g_abcd("b,a,c,d"))
1883  - (2.0 * g_abij("a,b,k,l") - g_abij("b,a,k,l")) * t1("c,k") * t1("d,l")
1884 
1885  + (2.0 * g_abci("b,a,d,k") - g_abci("a,b,d,k")) * t1("c,k")
1886  + (2.0 * g_abci("a,b,c,k") - g_abci("b,a,c,k")) * t1("d,k")
1887  ) * t1("b,j")
1888  //
1889  - (2.0 * g_aikl("a,j,k,l") - g_aikl("a,j,l,k")) * t1("d,l") * t1("c,k")
1890  //
1891  + (2.0 * g_aibj("a,j,c,k") - g_aijb("a,j,k,c")) * t1("d,k")
1892  + (2.0 * g_aijb("a,j,k,d") - g_aibj("a,j,d,k")) * t1("c,k")
1893  ) * L2("c,d,i,j")
1894  );
1895 
1896  L2("a,b,i,j") = Delta_abij("a,b,i,j") * (
1897  // I^ab_ij
1898  g_abij("a,b,i,j")
1899 
1900  // Ibi Laj + Iaj Lbi
1901  // Ibj Lai + Iai Lbj
1902 
1903  + ( fai("a,i")
1904  + (2.0 * g_abij("a,f,i,n") - g_abij("a,f,n,i")) * t1("f,n"))
1905  * L1("b,j")
1906 
1907  + ( fai("b,j")
1908  + (2.0 * g_abij("b,f,j,n") - g_abij("b,f,n,j")) * t1("f,n"))
1909  * L1("a,i")
1910 
1911  // H^ab_cj Lci + H^ba_ci Lcj
1912  - (- g_abci("a,b,e,j")
1913  + g_abij("a,b,n,j") * t1("e,n")) * L1("e,i")
1914  - (- g_abci("b,a,e,i")
1915  + g_abij("b,a,n,i") * t1("e,n")) * L1("e,j")
1916 
1917  // J^kb_ij Lak - j^ka_ji Lbk
1918  - ( g_aikl("b,m,j,i")
1919  + g_abij("b,f,j,i") * t1("f,m")) * L1("a,m")
1920  - ( g_aikl("a,m,i,j")
1921  + g_abij("a,f,i,j") * t1("f,m")) * L1("b,m")
1922  );
1923 #endif
1924 
1925  E_0_L = E_1_L;
1926  E_1_L = dot((2.0 * g_abij("a,b,i,j") - g_abij("b,a,i,j")), L2("a,b,i,j") );
1927  Delta_E_L = std::abs(E_0_L - E_1_L);
1928 
1929  iter += 1;
1930  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-20.10f", Delta_E_L)
1931  << scprintf("%-15.10f", E_1_L) << std::endl;
1932  }
1933  //std::cout << "CC2 L1 amplitudes: " << std::endl << L1 << std::endl;
1934  }
1935 
1936  // compute lambda amplitudes of CC2
1937  // use formula from Gauss and Stanton, JCP, 103 (1995)
1938  template <typename T>
1939  void SingleReference_R12Intermediates<T>::compute_lambda_cc2_2(const TArray2& t1, const TArray4& t2,
1940  TArray2& L1, TArray4& L2) {
1941 
1942  TArray2 fij = xy("<j|F|j>");
1943  TArray2 fab = xy("<a|F|b>");
1944  TArray2 fai = xy("<a|F|i>");
1945 
1946  // compute Delta_ai = 1 / (- <a|F|a> + <i|F|i>)
1947  typedef detail::diag_precond2<double> pceval_type;
1948  pceval_type Delta_ai_gen(TA::array_to_eigen(fab), TA::array_to_eigen(fij));
1949 
1950  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2dLazy;
1951  TArray2dLazy Delta_ai(fai.world(), fai.trange());
1952 
1953  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
1954  // construct local tiles
1955  for(auto t = Delta_ai.trange().tiles_range().begin();
1956  t != Delta_ai.trange().tiles_range().end(); ++t)
1957  if (Delta_ai.is_local(*t)) {
1958  std::array<std::size_t, 2> index;
1959  std::copy(t->begin(), t->end(), index.begin());
1960  madness::Future < typename TArray2dLazy::value_type >
1961  tile((LazyTensor<T, 2, pceval_type >(&Delta_ai, index, &Delta_ai_gen)
1962  ));
1963 
1964  // Insert the tile into the array
1965  Delta_ai.set(*t, tile);
1966  }
1967 
1968  // compute Delta_ijab = 1 / (- <a|F|a> - <b|F|b> + <i|F|i> + <j|F|j>)
1969  typedef detail::diag_precond4<double> pc4eval_type;
1970  pc4eval_type Delta_abij_gen(TA::array_to_eigen(fab), TA::array_to_eigen(fab),
1971  TA::array_to_eigen(fij),TA::array_to_eigen(fij));
1972 
1973  TArray4d g_abij = ijxy("<a b|g|i j>");
1974  typedef TA::Array<T, 4, LazyTensor<T, 4, pc4eval_type > > TArray4dLazy;
1975  TArray4dLazy Delta_abij(g_abij.world(), g_abij.trange());
1976 
1977  // construct local tiles
1978  for(auto t = Delta_abij.trange().tiles_range().begin();
1979  t != Delta_abij.trange().tiles_range().end(); ++t)
1980  if (Delta_abij.is_local(*t)) {
1981  std::array<std::size_t, 4> index;
1982  std::copy(t->begin(), t->end(), index.begin());
1983  madness::Future < typename TArray4dLazy::value_type >
1984  tile((LazyTensor<T, 4, pc4eval_type >(&Delta_abij, index, &Delta_abij_gen)
1985  ));
1986 
1987  // Insert the tile into the array
1988  Delta_abij.set(*t, tile);
1989  }
1990 
1991  // pseudo energy
1992  L1("a,i") = t1("a,i");
1993  L2("a,b,i,j") = t2("a,b,i,j");
1994 
1995  double E_0_L = 0.0;
1996  double E_1_L = dot((2.0 * g_abij("a,b,i,j") - g_abij("b,a,i,j")), L2("a,b,i,j") );
1997  double Delta_E_L = std::abs(E_0_L - E_1_L);
1998 
1999  double iter = 0;
2000  std::cout << indent << scprintf("%-5s", "Iter") << scprintf("%-20s", "Delta_E_L")
2001  << scprintf("%-20s", "E_L(CC2)") << std::endl;
2002  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-20.10f", Delta_E_L)
2003  << scprintf("%-15.10f", E_1_L) << std::endl;
2004 
2005  // intermediates for computing L1 & L2
2006  TArray4d g_abci = ijxy("<a b|g|c i>");
2007  TArray4d g_aikl = ijxy("<a i|g|k l>");
2008  TArray4d g_aibj = ijxy("<a i|g|b j>");
2009  TArray4d g_aijb = ijxy("<a i|g|j b>");
2010  TArray4d g_ijkl = ijxy("<i j|g|k l>");
2011  TArray4d g_abcd = ijxy("<a b|g|c d>");
2012 
2013  TArray4 tau2_aa, tau2_ab, Ttau_aa, Ttau_ab;
2014  tau2_aa("a,b,i,j") = t2("a,b,i,j") - t2("b,a,i,j")
2015  + (t1("a,i") * t1("b,j") - t1("b,i") * t1("a,j"));
2016  tau2_ab("a,b,i,j") = t2("a,b,i,j")
2017  + (t1("a,i") * t1("b,j"));
2018 
2019  Ttau_aa("a,b,i,j") = t2("a,b,i,j") - t2("b,a,i,j")
2020  + 0.5 * (t1("a,i") * t1("b,j") - t1("b,i") * t1("a,j"));
2021  Ttau_ab("a,b,i,j") = t2("a,b,i,j")
2022  + 0.5 * t1("a,i") * t1("b,j");
2023 
2024  TArray4 tau2t1_aa, tau2t1_ab, Ttaut1_aa, Ttaut1_ab;
2025  tau2t1_aa("a,b,i,j") = t1("a,i") * t1("b,j") - t1("b,i") * t1("a,j");
2026  tau2t1_ab("a,b,i,j") = t1("a,i") * t1("b,j");
2027  Ttaut1_aa("a,b,i,j") = 0.5 * t1("a,i") * t1("b,j") - t1("b,i") * t1("a,j");
2028  Ttaut1_ab("a,b,i,j") = 0.5 * t1("a,i") * t1("b,j");
2029 
2030  TArray2 TFme, TFae, TFmi;
2031  TFme("m,e") = // fme
2032  // + t^f_n g^mn_ef
2033  (2.0 * g_abij("e,f,m,n") - g_abij("e,f,n,m")) * t1("f,n");
2034  TFae("a,e") = // fae - 1/2 fme t^a_m
2035  // + t^f_m g^am_ef
2036  t1("f,m") * (2.0 * g_abci("e,f,a,m") - g_abci("f,e,a,m"))
2037  // - 1/2 Ttau^af_mn g^mn_ef
2038  - 0.5 * Ttau_aa("a,f,m,n") * (g_abij("e,f,m,n") - g_abij("f,e,m,n"))
2039  - Ttau_ab("a,f,m,n") * g_abij("e,f,m,n")
2040  ;
2041  TFmi("m,i") = // fmi + 1/2 fme t^e_i
2042  // + t^e_n g^mn_ie
2043  t1("e,n") * (2.0 * g_aikl("e,i,n,m") - g_aikl("e,i,m,n"))
2044  // + 1/2 Ttau^ef_in g^mn_ef
2045  + 0.5 * Ttau_aa("e,f,i,n") * (g_abij("e,f,m,n") - g_abij("e,f,n,m"))
2046  + Ttau_ab("e,f,i,n") * g_abij("e,f,m,n")
2047  ;
2048 
2049  TArray2 CFme, CFae, CFmi;
2050  CFme("m,e") = TFme("m,e");
2051  CFae("a,e") = TFae("a,e") - 0.5 * t1("a,m") * TFme("m,e");
2052  CFmi("m,i") = TFmi("m,i") + 0.5 * t1("e,i") * TFme("m,e");
2053 
2054  // compute \cal{W}mbej
2055  TArray4 TW_MBEJ_aa, TW_MbEj_ab,CW_MBEJ_aa, CW_MbEj_ab;
2056 
2057  // \tilde{W}mbej:
2058  // alpha-alpha case
2059  TW_MBEJ_aa("m,b,e,j") = // g^mb_ej
2060  g_aijb("e,j,m,b") - g_aibj("e,j,b,m")
2061 
2062  // + t^f_j g^mb_ef
2063  + t1("f,j") * (g_abci("f,e,b,m") - g_abci("e,f,b,m"))
2064 
2065  // - t^b_n g^mn_ej
2066  - t1("b,n") * (g_aikl("e,j,m,n") - g_aikl("e,j,n,m"))
2067 
2068  // - 1/2 (t^fb_jn + 2 t^f_j t^b_n) g^mn_ef:
2069  // + 1/2 t^bf_jn g^mn_ef
2070  + 0.5 * ( (2.0 * t2("b,f,j,n") - t2("f,b,j,n"))
2071  * g_abij("e,f,m,n")
2072  - (t2("b,f,j,n") - t2("f,b,j,n"))
2073  * g_abij("f,e,m,n")
2074  )
2075  // - t^f_j t^b_n g^mn_ef
2076  - t1("f,j") * t1("b,n")
2077  * (g_abij("e,f,m,n") - g_abij("f,e,m,n"))
2078  ;
2079  // alpha-beta case
2080  TW_MbEj_ab("m,b,e,j") = // g^mb_ej
2081  g_aijb("e,j,m,b")
2082  // + t^f_j g^mb_ef
2083  + t1("f,j") * g_abci("f,e,b,m")
2084  // - t^b_n g^mn_ej
2085  - t1("b,n") * g_aikl("e,j,m,n")
2086 
2087  // - 1/2 (t^fb_jn + 2 t^f_j t^b_n) g^mn_ef:
2088  // + 1/2 t^bf_jn g^mn_ef
2089  + 0.5 * ( (2.0 * t2("b,f,j,n") - t2("f,b,j,n"))
2090  * g_abij("e,f,m,n")
2091  - t2("b,f,j,n") * g_abij("f,e,m,n")
2092  )
2093  // - t^f_j t^b_n g^mn_ef
2094  - t1("f,j") * t1("b,n") * g_abij("e,f,m,n")
2095  ;
2096 
2097  // \cal{W}mbej
2098  CW_MBEJ_aa("m,b,e,j") = // \tilde{W}mbej
2099  TW_MBEJ_aa("m,b,e,j")
2100 
2101  // - 1/2 t^fb_jn g^mn_ef = + 1/2 t^fb_nj g^mn_ef
2102  + 0.5 * (t2("f,b,n,j") - t2("b,f,n,j"))
2103  * (g_abij("e,f,m,n") - g_abij("f,e,m,n"))
2104  + 0.5 * t2("f,b,n,j") * g_abij("e,f,m,n")
2105  ;
2106  CW_MbEj_ab("m,b,e,j") = // \tilde{W}mbej
2107  TW_MbEj_ab("m,b,e,j")
2108 
2109  // - 1/2 t^fb_jn g^mn_ef = + 1/2 t^fb_nj g^mn_ef
2110  + 0.5 * (t2("f,b,n,j") - t2("b,f,n,j"))
2111  * g_abij("e,f,m,n")
2112  + 0.5 * t2("f,b,n,j")
2113  * (g_abij("e,f,m,n") - g_abij("f,e,m,n"))
2114  ;
2115 
2116 
2117  // compute \cal{W}abei
2118  TArray4 TW_ABEF_aa, TW_AbEf_ab, CW_ABEF_aa, CW_AbEf_ab, CW_ABEI_aa, CW_AbEi_ab;
2119 
2120  // \tilde{W}abef
2121  TW_ABEF_aa("a,b,e,f") = // g^ab_ef
2122  g_abcd("a,b,e,f") - g_abcd("b,a,e,f")
2123 
2124  // - P(ab) t^b_m g^am_ef:
2125  // - t^b_m g^am_ef
2126  - t1("b,m") * (g_abci("e,f,a,m") - g_abci("f,e,a,m"))
2127  // + t^a_m g^bm_ef
2128  + t1("a,m") * (g_abci("e,f,b,m") - g_abci("f,e,b,m"))
2129 
2130  // + 1/4 tau^ab_mn g^mn_ef
2131  + 0.25 * tau2t1_aa("a,b,m,n") * (g_abij("e,f,m,n") - g_abij("f,e,m,n"))
2132  ;
2133 
2134  TW_AbEf_ab("a,b,e,f") = // g^ab_ef
2135  g_abcd("a,b,e,f")
2136 
2137  // - P(ab) t^b_m g^am_ef:
2138  // - t^b_m g^am_ef
2139  - t1("b,m") * g_abci("e,f,a,m")
2140  // - t^a_m g^mb_ef
2141  - t1("a,m") * g_abci("f,e,b,m")
2142 
2143  // + 1/4 tau^ab_mn g^mn_ef
2144  + 0.5 * tau2t1_ab("a,b,m,n") * g_abij("e,f,m,n")
2145  ;
2146 
2147  // \cal{W}abef
2148  CW_ABEF_aa("a,b,e,f") = // \tilde{W}abef
2149  TW_ABEF_aa("a,b,e,f")
2150  // + 1/4 tau^ab_mn g^mn_ef
2151  + 0.25 * tau2t1_aa("a,b,m,n") * (g_abij("e,f,m,n") - g_abij("f,e,m,n"));
2152 
2153  CW_AbEf_ab("a,b,e,f") = // \tilde{W}abef
2154  TW_AbEf_ab("a,b,e,f")
2155  // + 1/4 tau^ab_mn g^mn_ef
2156  + 0.5 * tau2t1_ab("a,b,m,n") * g_abij("e,f,m,n");
2157 
2158  // \cal{W}abei
2159  CW_ABEI_aa("a,b,e,i") = // g^ab_ei
2160  g_abci("a,b,e,i") - g_abci("b,a,e,i")
2161 
2162  // - \cal{F}me t^ab_mi
2163  //- CFme("m,e") * (t2("a,b,m,i") - t2("b,a,m,i"))
2164 
2165  // + t^f_i \cal{W}abef
2166  + t1("f,i") * CW_ABEF_aa("a,b,e,f")
2167 
2168  // + 1/2 g^mn_ei tau^ab_mn
2169  + 0.5 * (g_aikl("e,i,m,n") - g_aikl("e,i,n,m")) * tau2t1_aa("a,b,m,n")
2170 
2171  // - P(ab) g^mb_ef t^af_mi (=> 0 for cc2):
2172  // - g^mb_ef t^af_mi = - g^bm_ef t^fa_mi
2173  //- (g_abci("f,e,b,m") - g_abci("e,f,b,m")) * (t2("a,f,m,i") - t2("f,a,m,i")) // m,f in alpha space
2174  //- g_abci("e,f,b,m") * t2("f,a,m,i") // m,f in beta space
2175  // + g^ma_ef t^bf_mi = + g^am_ef t^fb_mi
2176  //+ g_abci("f,e,a,m") * t2("b,f,m,i") - g_abci("e,f,a,m") * t2("b,f,m,i")
2177  //- g_abci("f,e,a,m") * t2("f,b,m,i") + 2.0 * g_abci("e,f,a,m") * t2("f,b,m,i")
2178 
2179  // - P(ab) t^a_m (g^mb_ei - t^bf_ni g^mn_ef):
2180  // - t^a_m (g^mb_ei - t^bf_ni g^mn_ef) = - t^a_m (g^mb_ei + t^fb_ni g^mn_ef)
2181  - t1("a,m")
2182  * ( g_aijb("b,m,i,e") - g_aibj("b,m,e,i")
2183  //- ( t2("b,f,n,i") * g_abij("e,f,m,n") - 2.0 * t2("f,b,n,i") * g_abij("e,f,m,n")
2184  // - t2("b,f,n,i") * g_abij("f,e,m,n") + t2("f,b,n,i") * g_abij("f,e,m,n"))
2185  )
2186  // + t^b_m (g^ma_ei - t^af_ni g^mn_ef) = + t^b_m (- g^am_ei + t^af_in g^mn_ef)
2187  + t1("b,m")
2188  * (- g_aibj("a,m,e,i") + g_aijb("a,m,i,e")
2189  //+ ( 2.0 * t2("f,a,n,i") * g_abij("e,f,m,n") - t2("a,f,n,i") * g_abij("e,f,m,n")
2190  // - t2("f,a,n,i") * g_abij("f,e,m,n") + t2("a,f,n,i") * g_abij("f,e,m,n")
2191  // )
2192  )
2193  ;
2194 
2195  CW_AbEi_ab("a,b,e,i") = // g^ab_ei
2196  g_abci("a,b,e,i")
2197 
2198  // - \cal{F}me t^ab_mi
2199  //- CFme("m,e") * t2("a,b,m,i")
2200 
2201  // + t^f_i \cal{W}abef
2202  + t1("f,i") * CW_AbEf_ab("a,b,e,f")
2203 
2204  // + 1/2 g^mn_ei tau^ab_mn
2205  + g_aikl("e,i,m,n") * tau2t1_ab("a,b,m,n")
2206 
2207  // - P(ab) g^mb_ef t^af_mi (=> 0 for cc2):
2208  // - g^mb_ef t^af_mi
2209  //- g_abci("f,e,b,m") * t2("a,f,m,i")
2210  // + g^ma_ef t^bf_mi = + g^am_ef t^fb_mi
2211  //+ (g_abci("e,f,a,m") - g_abci("f,e,a,m")) * t2("f,b,m,i")
2212  //+ g_abci("e,f,a,m") * (t2("f,b,m,i") - t2("b,f,m,i"))
2213 
2214  // - P(ab) t^a_m (g^mb_ei - t^bf_ni g^mn_ef):
2215  // - t^a_m (g^mb_ei - t^bf_ni g^mn_ef) = - t^a_m (g^mb_ei + t^fb_ni g^mn_ef)
2216  - t1("a,m")
2217  * ( g_aijb("b,m,i,e")
2218  //+ t2("f,b,n,i") * (g_abij("e,f,m,n") - g_abij("f,e,m,n"))
2219  //+ (t2("f,b,n,i") - t2("b,f,n,i")) * g_abij("e,f,m,n")
2220  )
2221  // + t^b_m (g^ma_ei - t^af_ni g^mn_ef) = + t^b_m (- g^am_ei + t^af_ni g^nm_ef)
2222  + t1("b,m")
2223  * (- g_aibj("a,m,e,i")
2224  //+ t2("a,f,n,i") * g_abij("e,f,n,m")
2225  )
2226  ;
2227 
2228  // compute \cal{W}mbij
2229  TArray4 TW_MNIJ_aa, TW_MnIj_ab, CW_MNIJ_aa, CW_MnIj_ab, CW_MBIJ_aa, CW_MbIj_ab;
2230 
2231  // \tilde{W}mnij
2232  TW_MNIJ_aa("m,n,i,j") = // g^mn_ij
2233  g_ijkl("m,n,i,j") - g_ijkl("n,m,i,j")
2234 
2235  // + P(ij) t^e_j g^mn_ie:
2236  // + t^e_j g^mn_ie
2237  + t1("e,j") * (g_aikl("e,i,n,m") - g_aikl("e,i,m,n"))
2238  // + t^e_i g^mn_ej
2239  + t1("e,i") * (g_aikl("e,j,m,n") - g_aikl("e,j,n,m"))
2240 
2241  // + 0.25 * tau^ef_ij * g^mn_ef
2242  + 0.25 * tau2t1_aa("e,f,i,j") * (g_abij("e,f,m,n") - g_abij("e,f,n,m"))
2243  ;
2244  TW_MnIj_ab("m,n,i,j") = // g^mn_ij
2245  g_ijkl("m,n,i,j")
2246 
2247  // + P(ij) t^e_j g^mn_ie:
2248  // + t^e_j g^mn_ie
2249  + t1("e,j") * g_aikl("e,i,n,m")
2250  // + t^e_i g^mn_ej
2251  + t1("e,i") * g_aikl("e,j,m,n")
2252 
2253  // + 0.25 * tau^ef_ij * g^mn_ef
2254  + 0.5 * tau2t1_ab("e,f,i,j") * g_abij("e,f,m,n")
2255  ;
2256 
2257  // \cal{W}mnij
2258  CW_MNIJ_aa("m,n,i,j") = // \tilde{W}mnij
2259  TW_MNIJ_aa("m,n,i,j")
2260  // + 1/4 tau^ef_ij g^mn_ef
2261  + 0.25 * tau2t1_aa("e,f,i,j") * (g_abij("e,f,m,n") - g_abij("e,f,n,m"))
2262  ;
2263  CW_MnIj_ab("m,n,i,j") = // \tilde{W}mnij
2264  TW_MnIj_ab("m,n,i,j")
2265  // + 1/4 tau^ef_ij g^mn_ef
2266  + 0.5 * tau2t1_ab("e,f,i,j") * g_abij("e,f,m,n")
2267  ;
2268 
2269  // \cal{W}mbij
2270  CW_MBIJ_aa("m,b,i,j") = // g^mb_ij
2271  g_aikl("b,m,j,i") - g_aikl("b,m,i,j")
2272 
2273  // - \cal{F}me t^be_ij = + CFme t^eb_ij
2274  //+ CFme("m,e") * (t2("e,b,i,j") - t2("b,e,i,j"))
2275 
2276  // - t^b_n \cal{W}mnij
2277  - t1("b,n") * CW_MNIJ_aa("m,n,i,j")
2278 
2279  // + 0.5 g^mb_ef tau^ef_ij
2280  + 0.5 * (g_abci("f,e,b,m") - g_abci("e,f,b,m")) * tau2t1_aa("e,f,i,j")
2281 
2282  // + P(ij) g^mn_ie t^be_jn (=> 0 for cc2):
2283  // + g^mn_ie t^be_jn
2284  //+ 2.0 * g_aikl("e,i,n,m") * t2("b,e,j,n") - g_aikl("e,i,m,n") * t2("b,e,j,n")
2285  //- g_aikl("e,i,n,m") * t2("b,e,n,j") + g_aikl("e,i,m,n") * t2("b,e,n,j")
2286  // - g^mn_je t^be_in
2287  //+ 2.0 * g_aikl("e,j,n,m") * t2("b,e,i,n") - g_aikl("e,j,m,n") * t2("b,e,i,n")
2288  //- g_aikl("e,j,n,m") * t2("e,b,i,n") + g_aikl("e,j,m,n") * t2("e,b,i,n")
2289 
2290  // + P(IJ) t^e_i (g^mb_ej - t^bf_nj g^mn_ef)
2291  // + t^e_i (g^mb_ej - t^bf_nj g^mn_ef) = + t^e_i (g^mb_ej + t^bf_jn g^mn_ef)
2292  + t1("e,i")
2293  * ( g_aijb("e,j,m,b") - g_aibj("e,j,b,m")
2294 
2295  //+ 2.0 * t2("b,f,j,n") * g_abij("e,f,m,n") - t2("f,b,j,n") * g_abij("e,f,m,n")
2296  //- t2("b,f,j,n") * g_abij("f,e,m,n") + t2("f,b,j,n") * g_abij("f,e,m,n")
2297  )
2298  // - t^e_j (g^mb_ei - t^bf_ni g^mn_ef) = - t^e_j (g^mb_ei + t^bf_in g^mn_ef)
2299  - t1("e,j")
2300  * ( g_aijb("e,i,m,b") - g_aibj("e,i,b,m")
2301 
2302  //+ 2.0 * t2("b,f,i,n") * g_abij("e,f,m,n") - t2("f,b,i,n") * g_abij("e,f,m,n")
2303  //- t2("b,f,i,n") * g_abij("f,e,m,n") + t2("f,b,i,n") * g_abij("f,e,m,n")
2304  )
2305  ;
2306 
2307  CW_MbIj_ab("m,b,i,j") = // g^mb_ij
2308  g_aikl("b,m,j,i")
2309 
2310  // - \cal{F}me t^be_ij = + CFme t^eb_ij
2311  //+ CFme("m,e") * t2("e,b,i,j")
2312 
2313  // - t^b_n \cal{W}mnij
2314  - t1("b,n") * CW_MnIj_ab("m,n,i,j")
2315 
2316  // + 0.5 g^mb_ef tau^ef_ij
2317  + g_abci("f,e,b,m") * tau2t1_ab("e,f,i,j")
2318 
2319  // + P(ij) g^mn_ie t^be_jn (=> 0 for cc2):
2320  // + g^mn_ie t^be_jn
2321  //+ 2.0 * g_aikl("e,i,n,m") * t2("b,e,j,n") - g_aikl("e,i,n,m") * t2("b,e,n,j")
2322  //- g_aikl("e,i,m,n") * t2("b,e,j,n")
2323  // - g^mn_je t^be_in = - g^nm_je t^eb_in
2324  //+ g_aikl("e,j,m,n") * t2("e,b,i,n")
2325 
2326  // + P(IJ) t^e_i (g^mb_ej - t^bf_nj g^mn_ef)
2327  // + t^e_i (g^mb_ej - t^bf_nj g^mn_ef) = + t^e_i (g^mb_ej + t^bf_jn g^mn_ef)
2328  + t1("e,i")
2329  * ( g_aijb("e,j,m,b")
2330 
2331  //+ 2.0 * t2("b,f,j,n") * g_abij("e,f,m,n") - t2("f,b,j,n") * g_abij("e,f,m,n")
2332  //- t2("b,f,j,n") * g_abij("f,e,m,n")
2333  )
2334  // - t^e_j (g^mb_ei - t^bf_ni g^mn_ef) = - t^e_j (- g^mb_ie + t^bf_ni g^mn_fe)
2335  - t1("e,j")
2336  * (- g_aibj("e,i,b,m")
2337  //+ t2("b,f,n,i") * g_abij("f,e,m,n")
2338  )
2339  ;
2340 
2341  // intermediates for L2
2342  TArray4 CW_MnIe_ab, CW_MniE_ab, CW_AmEf_ab, CW_aMEf_ab;
2343 
2344  CW_MnIe_ab("m,n,i,e") = // g^mn_ie
2345  g_aikl("e,i,n,m")
2346  // + t^f_i g^mn_fe
2347  + t1("f,i") * g_abij("f,e,m,n")
2348  ;
2349  CW_MniE_ab("m,n,i,e") = // g^mn_ie
2350  - g_aikl("e,i,m,n")
2351  // + t^f_i g^mn_fe
2352  - t1("f,i") * g_abij("f,e,n,m")
2353  ;
2354 
2355  CW_AmEf_ab("a,m,e,f") = // g^am_ef
2356  g_abci("e,f,a,m")
2357  // - t^a_n g^nm_ef
2358  - t1("a,n") * g_abij("e,f,n,m")
2359  ;
2360  CW_aMEf_ab("a,m,e,f") = // g^am_ef
2361  - g_abci("f,e,a,m")
2362  // - t^a_n g^nm_ef
2363  + t1("a,n") * g_abij("f,e,n,m")
2364  ;
2365 
2366  while (Delta_E_L >= 1.0e-9) {
2367 
2368  L1("a,i") = Delta_ai("a,i") * (
2369  // \cal{F}ia
2370  CFme("i,a")
2371  // + \lambda^i_e \cal{F}ea
2372  + L1("e,i") * CFae("e,a")
2373  // - \lambda^m_a \cal{F}im
2374  - L1("a,m") * CFmi("i,m")
2375  // + \lambda^m_e \cal{W}ieam
2376  + L1("e,m") * (CW_MBEJ_aa("i,e,a,m") + CW_MbEj_ab("i,e,a,m"))
2377  // + 1/2 \lambda^im_ef \cal{W}efam
2378  + 0.5 * (L2("e,f,i,m") - L2("e,f,m,i") ) * CW_ABEI_aa("e,f,a,m")
2379  + L2("e,f,i,m") * CW_AbEi_ab("e,f,a,m")
2380  // - 1/2 \lambda^mn_ae \cal{W}iemn
2381  - 0.5 * (L2("a,e,m,n") - L2("e,a,m,n") ) * CW_MBIJ_aa("i,e,m,n")
2382  - L2("a,e,m,n") * CW_MbIj_ab("i,e,m,n")
2383  );
2384 
2385  L2("a,b,i,j") = Delta_abij("a,b,i,j") * (
2386  // g^ij_ab
2387  g_abij("a,b,i,j")
2388 
2389  // + P(ab) \lambda^ij_ae \cal{F}eb
2390  //+ L2("a,e,i,j") * CFae("e,b")
2391  //+ L2("e,b,i,j") * CFae("e,a")
2392 
2393  // - P(ij) \lambda^im_ab \cal{F}jm
2394  //- L2("a,b,i,m") * CFmi("j,m")
2395  //- L2("a,b,m,j") * CFmi("i,m")
2396 
2397  // + P(ij) \lambda^i_e \cal{W}ejab
2398  + L1("e,i") * CW_AmEf_ab("e,j,a,b")
2399  - L1("e,j") * CW_aMEf_ab("e,i,a,b")
2400 
2401  // - P(ab) \lambda^m_a \cal{W}ijmb
2402  - L1("a,m") * CW_MnIe_ab("i,j,m,b")
2403  + L1("b,m") * CW_MniE_ab("i,j,m,a")
2404 
2405  // + P(ij) P(ab) \lambda^i_a \cal{F}jb
2406  + L1("a,i") * CFme("j,b")
2407  //- L1("b,i") * CFme("j,a")
2408  //- L1("a,j") * CFme("i,b")
2409  + L1("b,j") * CFme("i,a")
2410  );
2411 
2412  E_0_L = E_1_L;
2413  E_1_L = dot((2.0 * g_abij("a,b,i,j") - g_abij("b,a,i,j")), L2("a,b,i,j") );
2414  Delta_E_L = std::abs(E_0_L - E_1_L);
2415 
2416  iter += 1;
2417  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-20.10f", Delta_E_L)
2418  << scprintf("%-15.10f", E_1_L) << std::endl;
2419  }
2420  //std::cout << "CC2 L1 amplitudes: " << std::endl << L1 << std::endl;
2421  }
2422 
2423  // compute CC2 one-electron density from amplitudes
2424  template <typename T>
2425  void SingleReference_R12Intermediates<T>::compute_cc2_1rdm_amp(
2426  const TArray2& T1_cc2, const TArray4& T2_cc2,
2427  const TArray2& L1_cc2, const TArray4& L2_cc2,
2428  TArray2& Dij_cc2, TArray2& Dab_cc2,
2429  TArray2& Dia_cc2, TArray2& Dai_cc2) {
2430 
2431  Dij_cc2("i,j") = // - 1/4 P+(ij) t^ef_im lambda^jm_ef
2432  - 0.5 * ( (2.0 * T2_cc2("c,d,i,k") - T2_cc2("c,d,k,i"))
2433  * L2_cc2("c,d,j,k")
2434  + (2.0 * T2_cc2("c,d,j,k") - T2_cc2("c,d,k,j"))
2435  * L2_cc2("c,d,i,k")
2436  )
2437  // - 1/2 P+(ij) t^e_i lambda^j_e
2438  - 0.5 * ( T1_cc2("c,i") * L1_cc2("c,j")
2439  + T1_cc2("c,j") * L1_cc2("c,i")
2440  )
2441  ;
2442  //std::cout << "Dij_cc2: " << std::endl << Dij_cc2 << std::endl;
2443 
2444  Dab_cc2("a,b") = // 1/4 P+(ab) t^mn_ae lambda^be_mn
2445  0.5 * ( (2.0 * T2_cc2("a,c,k,l") - T2_cc2("c,a,k,l"))
2446  * L2_cc2("b,c,k,l")
2447  + (2.0 * T2_cc2("b,c,k,l") - T2_cc2("c,b,k,l"))
2448  * L2_cc2("a,c,k,l")
2449  )
2450  // + 1/2 P+(ab) lambda^m_a t^b_m
2451  + 0.5 * ( L1_cc2("a,k") * T1_cc2("b,k")
2452  + L1_cc2("b,k") * T1_cc2("a,k")
2453  )
2454  ;
2455 
2456  Dia_cc2("i,a") = // t^a_i
2457  T1_cc2("a,i")
2458  // + (t^ae_im - t^e_i t^a_m) \lambda^m_e
2459  + (2.0 * T2_cc2("a,c,i,k") - T2_cc2("a,c,k,i")
2460  - T1_cc2("c,i") * T1_cc2("a,k"))
2461  * L1_cc2("c,k")
2462  // CCSD term
2463  // - 1/2 lambda^mn_ef (t^ef_in t^a_m + t^e_i t^af_mn)
2464 // - (2.0 * L2_cc2("c,d,k,l") - L2_cc2("d,c,k,l"))
2465 // * ( T2_cc2("c,d,i,l") * T1_cc2("a,k")
2466 // + T2_cc2("a,d,k,l") * T1_cc2("c,i")
2467 // )
2468  ;
2469 
2470  Dai_cc2("a,i") = // lambda^i_a
2471  L1_cc2("a,i");
2472  }
2473 
2474  // compute lambda amplitudes of CCSD
2475  // use formula from Gauss and Stanton, JCP, 103 (1995)
2476  // compute Delta_ai = 1 / (- <a|F|a> + <i|F|i>)
2477  // & Delta_ijab = 1 / (- <a|F|a> - <b|F|b> + <i|F|i> + <j|F|j>)
2478  template <typename T>
2479  void SingleReference_R12Intermediates<T>::compute_Delta_cc(const TA::TiledRange& TR_ai,
2480  const TA::TiledRange& TR_abij,
2481  TArray2& D_ai, TArray4& D_abij) {
2482  TArray2 fij = xy("<j|F|j>");
2483  TArray2 fab = xy("<a|F|b>");
2484 
2485  // compute Delta_ai = 1 / (- <a|F|a> + <i|F|i>)
2486  typedef detail::diag_precond2<double> pceval_type;
2487  pceval_type Delta_ai_gen(TA::array_to_eigen(fab), TA::array_to_eigen(fij));
2488 
2489  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2dLazy;
2490  TArray2dLazy Delta_ai(fij.world(), TR_ai);
2491 
2492  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
2493  // construct local tiles
2494  for(auto t = Delta_ai.trange().tiles_range().begin();
2495  t != Delta_ai.trange().tiles_range().end(); ++t)
2496  if (Delta_ai.is_local(*t)) {
2497  std::array<std::size_t, 2> index;
2498  std::copy(t->begin(), t->end(), index.begin());
2499  madness::Future < typename TArray2dLazy::value_type >
2500  tile((LazyTensor<T, 2, pceval_type >(&Delta_ai, index, &Delta_ai_gen)
2501  ));
2502 
2503  // Insert the tile into the array
2504  Delta_ai.set(*t, tile);
2505  }
2506  D_ai("a,i") = Delta_ai("a,i");
2507 
2508  // compute Delta_ijab = 1 / (- <a|F|a> - <b|F|b> + <i|F|i> + <j|F|j>)
2509  typedef detail::diag_precond4<double> pc4eval_type;
2510  pc4eval_type Delta_abij_gen(TA::array_to_eigen(fab), TA::array_to_eigen(fab),
2511  TA::array_to_eigen(fij),TA::array_to_eigen(fij));
2512 
2513  typedef TA::Array<T, 4, LazyTensor<T, 4, pc4eval_type > > TArray4dLazy;
2514  TArray4dLazy Delta_abij(fij.world(), TR_abij);
2515 
2516  // construct local tiles
2517  for(auto t = Delta_abij.trange().tiles_range().begin();
2518  t != Delta_abij.trange().tiles_range().end(); ++t)
2519  if (Delta_abij.is_local(*t)) {
2520  std::array<std::size_t, 4> index;
2521  std::copy(t->begin(), t->end(), index.begin());
2522  madness::Future < typename TArray4dLazy::value_type >
2523  tile((LazyTensor<T, 4, pc4eval_type >(&Delta_abij, index, &Delta_abij_gen)
2524  ));
2525 
2526  // Insert the tile into the array
2527  Delta_abij.set(*t, tile);
2528  }
2529  D_abij("a,b,i,j") = Delta_abij("a,b,i,j");
2530  fij.world().gop.fence();
2531  }
2532 
2533  // compute intermediates needed for T amplitudes
2534  template <typename T>
2535  void SingleReference_R12Intermediates<T>::compute_intermediates_TFW_ccsd(
2536  const TArray2& t1, const TArray4& t2,
2537  const TArray4d& g_abij, const TArray4d& g_aikl,
2538  const TArray4d& g_aibj, const TArray4d& g_aijb,
2539  const TArray4d& g_abci,
2540  const TArray4d& g_ijkl, const TArray4d& g_abcd,
2541  TArray2& TFkc, TArray2& TFac, TArray2& TFki,
2542  TArray4& TW_KbCj_ab,TArray4& TW_KbcJ_ba,
2543  TArray4& TW_AbCd_ab, TArray4& TW_KlIj_ab) {
2544  TArray4 tau_ab, Ttau_ab;
2545  tau_ab("a,b,i,j") = t2("a,b,i,j") + (t1("a,i") * t1("b,j"));
2546  Ttau_ab("a,b,i,j") = t2("a,b,i,j") + 0.5 * t1("a,i") * t1("b,j");
2547 
2548  TArray4 gabij_temp;
2549  gabij_temp("a,b,i,j") = 2.0 * g_abij("a,b,i,j") - g_abij("a,b,j,i");
2550 
2551  TFkc("k,c") = // fkc
2552  // + t^d_l g^kl_cd
2553  gabij_temp("c,d,k,l") * t1("d,l");
2554  TFac("a,c") = // fac (1 - delta_ac) - 1/2 fkc t^a_k
2555  // + t^d_k g^ak_cd
2556  t1("d,k") * (2.0 * g_abci("c,d,a,k") - g_abci("d,c,a,k"))
2557  // - 1/2 Ttau^ad_kl g^kl_cd
2558  - Ttau_ab("a,d,k,l") * gabij_temp("c,d,k,l")
2559  ;
2560  TFki("k,i") = // fki (1 - delta_ki) + 1/2 fkc t^c_i
2561  // + t^c_l g^kl_ic
2562  t1("c,l") * (2.0 * g_aikl("c,i,l,k") - g_aikl("c,i,k,l"))
2563  // + 1/2 Ttau^cd_il g^kl_cd
2564  + Ttau_ab("c,d,i,l") * gabij_temp("c,d,k,l")
2565  ;
2566 
2567  // \tilde{W}mbej:
2568  // alpha-beta case
2569  TW_KbCj_ab("k,b,c,j") = // g^kb_cj
2570  g_aijb("c,j,k,b")
2571  // + t^d_j g^kb_cd
2572  + t1("d,j") * g_abci("d,c,b,k")
2573  // - t^b_l g^kl_cj
2574  - t1("b,l") * g_aikl("c,j,k,l")
2575 
2576  // - 1/2 (t^db_jl + 2 t^d_j t^b_l) g^kl_cd:
2577  // + 1/2 t^bd_jl g^kl_cd
2578  + 0.5 * ( t2("b,d,j,l") * gabij_temp("c,d,k,l")
2579  - t2("d,b,j,l") * g_abij("c,d,k,l")
2580  )
2581  // - t^d_j t^b_l g^kl_cd
2582  - t1("d,j") * (t1("b,l") * g_abij("c,d,k,l"))
2583  ;
2584 
2586  TW_KbcJ_ba("k,b,c,j") = // g^kb_cj
2587  - g_aibj("c,j,b,k")
2588  // + t^d_j g^kb_cd
2589  - t1("d,j") * g_abci("c,d,b,k")
2590  // - t^b_l g^kl_cj
2591  + t1("b,l") * g_aikl("c,j,l,k")
2592 
2593  // - 1/2 (t^db_jl + 2 t^d_j t^b_l) g^kl_cd:
2594  // + 1/2 t^bd_jl g^kl_cd
2595  + 0.5 * t2("d,b,j,l") * g_abij("d,c,k,l")
2596  // - t^d_j t^b_l g^kl_cd
2597  + t1("d,j") * (t1("b,l") * g_abij("d,c,k,l"))
2598  ;
2599 
2600  // \tilde{W}abef
2601  TW_AbCd_ab("a,b,c,d") = // g^ab_cd
2602  g_abcd("a,b,c,d")
2603 
2604  // - P(ab) t^b_k g^ak_cd:
2605  // - t^b_k g^ak_cd
2606  - t1("b,k") * g_abci("c,d,a,k")
2607  // - t^a_k g^kb_cd
2608  - t1("a,k") * g_abci("d,c,b,k")
2609 
2610 
2611  // + 1/4 tau^ab_kl g^kl_cd
2612  + 0.5 * tau_ab("a,b,k,l") * g_abij("c,d,k,l")
2613  ;
2614 
2615  // \tilde{W}mnij
2616  TW_KlIj_ab("k,l,i,j") = // g^kl_ij
2617  g_ijkl("k,l,i,j")
2618 
2619  // + P(ij) t^c_j g^kl_ic:
2620  // + t^c_j g^kl_ic
2621  + t1("c,j") * g_aikl("c,i,l,k")
2622  // + t^e_i g^mn_ej
2623  + t1("c,i") * g_aikl("c,j,k,l")
2624 
2625 
2626  // + 0.25 * tau^cd_ij * g^kl_cd
2627  + 0.5 * tau_ab("c,d,i,j") * g_abij("c,d,k,l")
2628  ;
2629  }
2630 
2631  // compute intermediates for lambda amplitudes
2632  template <typename T>
2633  void SingleReference_R12Intermediates<T>::compute_intermediates_CW_ccsd(
2634  const TArray2& t1, const TArray4& t2,
2635  TArray2& CFkc, TArray2& CFac, TArray2& CFki,
2636  TArray4& CW_KbCj_ab, TArray4& CW_KbcJ_ba,
2637  TArray4& CW_AbCd_ab, TArray4& CW_AbCi_ab,
2638  TArray4& CW_KlIj_ab, TArray4& CW_KbIj_ab,
2639  TArray4& CW_KlIc_ab, TArray4& CW_KliC_ab,
2640  TArray4& CW_AkCd_ab) {
2641 
2642  TArray4 tau_ab, Ttau_ab;
2643  tau_ab("a,b,i,j") = t2("a,b,i,j") + (t1("a,i") * t1("b,j"));
2644 
2645  Ttau_ab("a,b,i,j") = t2("a,b,i,j") + 0.5 * t1("a,i") * t1("b,j");
2646 
2647  TArray4d g_abij = ijxy("<a b|g|i j>");
2648  TArray4d g_abci = ijxy("<a b|g|c i>");
2649  TArray4d g_aikl = ijxy("<a i|g|k l>");
2650  TArray4d g_aibj = ijxy("<a i|g|b j>");
2651  TArray4d g_aijb = ijxy("<a i|g|j b>");
2652  TArray4d g_ijkl = ijxy("<i j|g|k l>");
2653  TArray4d g_abcd = ijxy("<a b|g|c d>");
2654 
2655  // compute intermediates
2656  TArray2 TFkc, TFac, TFki;
2657  TArray4 TW_KbCj_ab,
2659  TW_KbcJ_ba,
2660  TW_AbCd_ab, TW_KlIj_ab;
2661 
2662  compute_intermediates_TFW_ccsd(t1, t2,
2663  g_abij, g_aikl,
2664  g_aibj, g_aijb, g_abci,
2665  g_ijkl, g_abcd,
2666  TFkc, TFac, TFki,
2667  TW_KbCj_ab, TW_KbcJ_ba,
2668  TW_AbCd_ab, TW_KlIj_ab);
2669 
2670  // \cal{F}
2671  CFkc("k,c") = TFkc("k,c");
2672  CFac("a,c") = TFac("a,c") - 0.5 * t1("a,k") * TFkc("k,c");
2673  CFki("k,i") = TFki("k,i") + 0.5 * t1("c,i") * TFkc("k,c");
2674 
2675  // \cal{W}mbej
2676  CW_KbCj_ab("k,b,c,j") = // \tilde{W}kbcj
2677  TW_KbCj_ab("k,b,c,j")
2678 
2679  // - 1/2 t^db_jl g^kn_cd = + 1/2 t^db_lj g^kl_cd
2680  + 0.5 * (t2("d,b,l,j") - t2("b,d,l,j"))
2681  * g_abij("c,d,k,l")
2682  + 0.5 * t2("d,b,l,j")
2683  * (g_abij("c,d,k,l") - g_abij("d,c,k,l"))
2684  ;
2685 
2686  CW_KbcJ_ba("k,b,c,j") = // \tilde{W}kbcj
2687  TW_KbcJ_ba("k,b,c,j")
2688 
2689  // - 1/2 t^db_jl g^kn_cd = + 1/2 t^db_lj g^kl_cd
2690  + 0.5 * t2("b,d,l,j") * g_abij("d,c,k,l")
2691  ;
2692 
2693  // \cal{W}abef
2694  CW_AbCd_ab("a,b,c,d") = // \tilde{W}abcd
2695  TW_AbCd_ab("a,b,c,d")
2696 
2697 
2698  // + 1/4 tau^ab_kl g^kl_cd
2699  + 0.5 * tau_ab("a,b,k,l") * g_abij("c,d,k,l");
2700 
2701  TArray4 t2_temp;
2702  t2_temp("a,b,i,j") = 2.0 * t2("a,b,i,j") - t2("a,b,j,i");
2703  // \cal{W}abei
2704  CW_AbCi_ab("a,b,c,i") = // g^ab_ci
2705  g_abci("a,b,c,i")
2706 
2707  // - \cal{F}kc t^ab_ki
2708  - CFkc("k,c") * t2("a,b,k,i")
2709 
2710  // + t^d_i \cal{W}abcd
2711  + t1("d,i") * CW_AbCd_ab("a,b,c,d")
2712 
2713 
2714  // + 1/2 g^kl_ci tau^ab_kl
2715  + g_aikl("c,i,k,l") * tau_ab("a,b,k,l")
2716 
2717 
2718  // - P(ab) g^kb_cd t^ad_ki:
2719  // - g^kb_cd t^ad_ki
2720  - g_abci("d,c,b,k") * t2("a,d,k,i")
2721  // + g^ka_cd t^bd_ki = + g^ak_cd t^db_ki
2722  + ( g_abci("c,d,a,k") * t2_temp("b,d,i,k")
2723  - g_abci("d,c,a,k") * t2("b,d,i,k"))
2724 
2725  // - P(ab) t^a_k (g^kb_ci - t^bd_li g^kl_cd):
2726  // - t^a_k (g^kb_ci - t^bd_li g^kl_cd) = - t^a_k (g^kb_ci + t^db_li g^kl_cd)
2727  - t1("a,k")
2728  * ( g_aijb("b,k,i,c")
2730  + ( t2_temp("d,b,l,i") * g_abij("c,d,k,l")
2731  - t2("d,b,l,i") * g_abij("d,c,k,l"))
2732  )
2733  // + t^b_k (g^ka_ci - t^ad_li g^kl_cd) = + t^b_k (- g^ak_ci + t^ad_li g^lk_cd)
2734  + t1("b,k")
2735  * (- g_aibj("a,k,c,i")
2737  + t2("a,d,l,i") * g_abij("c,d,l,k")
2738  )
2739  ;
2740 
2741  // \cal{W}mnij
2742  CW_KlIj_ab("k,l,i,j") = // \tilde{W}klij
2743  TW_KlIj_ab("k,l,i,j")
2745  // + 1/4 tau^cd_ij g^kl_cd
2746  + 0.5 * tau_ab("c,d,i,j") * g_abij("c,d,k,l")
2747  ;
2748 
2749  // \cal{W}mbij
2750  CW_KbIj_ab("k,b,i,j") = // g^kb_ij
2751  g_aikl("b,k,j,i")
2752 
2753  // - \cal{F}kc t^bc_ij = + CFkc t^cb_ij
2754  + CFkc("k,c") * t2("c,b,i,j")
2755 
2756  // - t^b_l \cal{W}klij
2757  - t1("b,l") * CW_KlIj_ab("k,l,i,j")
2758 
2759 
2760  // + 0.5 g^kb_cd tau^cd_ij
2761  + g_abci("d,c,b,k") * tau_ab("c,d,i,j")
2762 
2763 
2764  // + P(ij) g^kl_ic t^bc_jl
2765  // + g^kl_ic t^bc_jl
2766  + g_aikl("c,i,l,k") * t2_temp("b,c,j,l")
2767  - g_aikl("c,i,k,l") * t2("b,c,j,l")
2768  // - g^kl_jc t^bc_il = - g^lk_jc t^cb_il
2769  - g_aikl("c,j,k,l") * t2("c,b,i,l")
2770 
2771  // + P(IJ) t^c_i (g^kb_cj - t^bd_lj g^kl_cd)
2772  // + t^c_i (g^kb_cj - t^bd_lj g^kl_cd) = + t^c_i (g^kb_cj + t^bd_jl g^kl_cd)
2773  + t1("c,i")
2774  * ( g_aijb("c,j,k,b")
2776  + t2_temp("b,d,j,l") * g_abij("c,d,k,l")
2777  - t2("b,d,j,l") * g_abij("d,c,k,l")
2778  )
2779  // - t^c_j (g^kb_ci - t^bd_li g^kl_cd) = - t^c_j (- g^kb_ic + t^bd_li g^kl_dc)
2780  - t1("c,j")
2781  * (- g_aibj("c,i,b,k")
2783  + t2("b,d,l,i") * g_abij("d,c,k,l")
2784  )
2785  ;
2786 
2787  // CCSD only term: CW_MNIE_ab
2788  CW_KlIc_ab("k,l,i,c") = // g^kl_ic
2789  g_aikl("c,i,l,k")
2790  // + t^d_i g^kl_dc
2791  + t1("d,i") * g_abij("d,c,k,l")
2792  ;
2793  CW_KliC_ab("k,l,i,c") = // g^kl_ic
2794  - g_aikl("c,i,k,l")
2795  // + t^d_i g^kl_dc
2796  - t1("d,i") * g_abij("d,c,l,k")
2797  ;
2798 
2799  // CCSD only term: CW_AMEF_aa
2800  CW_AkCd_ab("a,k,c,d") = // g^ak_cd
2801  g_abci("c,d,a,k")
2802  // - t^a_l g^lk_cd
2803  - t1("a,l") * g_abij("c,d,l,k")
2804  ;
2805 
2806  }
2807 
2808  // compute T1 & T2 amplitudes of CCSD
2809  template <typename T>
2810  void SingleReference_R12Intermediates<T>::compute_T_ccsd(TArray2& t1, TArray4& t2,
2811  const std::string method) {
2812 
2813  // compute Delta_ai = 1 / (- <a|F|a> + <i|F|i>)
2814  // & Delta_ijab = 1 / (- <a|F|a> - <b|F|b> + <i|F|i> + <j|F|j>)
2815  TArray2 fai = xy("<a|F|i>");
2816  TArray4d g_abij = ijxy("<a b|g|i j>");
2817 
2818  TArray2 Delta_ai;
2819  TArray4 Delta_abij;
2820  compute_Delta_cc(fai.trange(), g_abij.trange(), Delta_ai, Delta_abij);
2821 
2822  // compute initial T1 & T2 amplitudes and energy
2823  t1("a,i") = fai("a,i") * Delta_ai("a,i");
2824  t2("a,b,i,j") = g_abij("a,b,i,j") * Delta_abij("a,b,i,j");
2825 
2826  TArray2 T1_f12contri;
2827  TArray4 T2_f12contri,
2828  T2_f12contri_T1, V_KLAJ_temp, V_IJKL_temp; // F12 contributions involing T1
2829  if (method == "f12b" || method == "F12b") {
2830  const double C_0 = 1.0 / 2.0;
2831  const double C_1 = 1.0 / 4.0;
2832  const double RC1 = 0.5 * (C_0 + C_1);
2833  const double RC2 = 0.5 * (C_0 - C_1);
2834 
2835  const char* i = "i";
2836  const char* j = "j";
2837  const char* k = "k";
2838  const char* l = "l";
2839  const char* a = "a";
2840  const char* b = "b";
2841 
2842  // F12 contributions to amplitude equations
2843  //
2844  // contributions to T1 equation
2845  TArray2 Via = VRk_Sk(i, a, C_0, C_1);
2846  T1_f12contri("a,i") = Delta_ai("a,i") * Via("i,a"); // 1/2 R^ik_AB g^AB_ak
2847  t1("a,i") = t1("a,i") + T1_f12contri("a,i");
2848 
2849  // contributions to T2 equation
2850  TArray4d r_ijaFb = ijxy("<i j|r|a_F(c') b>");
2851  TArray4 V_IJAB = VPQ_RS(i, j, a, b);
2852  T2_f12contri("a,b,i,j") = Delta_abij("a,b,i,j") * (
2853  // F^a'_a R^ij_a'b + F^a'_b R^ij_aa'
2854  RC1 * r_ijaFb("i,j,a,b") + RC2 * r_ijaFb("j,i,a,b")
2855  + RC1 * r_ijaFb("j,i,b,a") + RC2 * r_ijaFb("i,j,b,a")
2856  // + 1/2 R^ij_AB g^AB_ab
2857  + RC1 * V_IJAB("i,j,a,b") + RC2 * V_IJAB("j,i,a,b")
2858  );
2859  // compute terms needed for constructing contributions that depends on T amplitudes
2860  // - 1/2 R^ij_AB g^AB_ak t^k_b - 1/2 R^ij_AB g^AB_kb t^k_a
2861  // + 1/2 R^ij_AB g^AB_kl t^k_a t^l_b
2862  TArray4 V_KLAJ = VPQ_RS(k, l, a, j);
2863  TArray4 V_IJKL = VPQ_RS(i, j, k, l);
2864  V_KLAJ_temp("i,j,a,k") = RC1 * V_KLAJ("i,j,a,k") + RC2 * V_KLAJ("j,i,a,k");
2865  V_IJKL_temp("i,j,k,l") = RC1 * V_IJKL("i,j,k,l") + RC2 * V_IJKL("j,i,k,l");
2866 
2867  t2("a,b,i,j") = t2("a,b,i,j")
2868  + T2_f12contri("a,b,i,j")
2869  ;
2870  }
2871 
2872  TArray4 tau_ab;
2873  tau_ab("a,b,i,j") = t2("a,b,i,j") + t1("a,i") * t1("b,j");
2874 
2875  TArray4 gabij_temp;
2876  gabij_temp("a,b,i,j") = 2.0 * g_abij("a,b,i,j") - g_abij("b,a,i,j");
2877 
2878  double E_0 = 0.0;
2879  double E_1 = //2.0 * dot(fai("a,i"), t1("a,i")) +
2880  dot(gabij_temp("a,b,i,j"), tau_ab("a,b,i,j") );
2881  double Delta_E = std::abs(E_0 - E_1);
2882 
2883  double iter = 0;
2884  std::cout << indent << scprintf("%-5s", "Iter") << scprintf("%-20s", "Delta_E")
2885  << scprintf("%-20s", "E(CCSD)") << std::endl;
2886  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-15.12f", Delta_E)
2887  << scprintf("%-15.12f", E_1) << std::endl;
2888 
2889  TArray2 TFkc, TFac, TFki;
2890  TArray4 TW_KbCj_ab,
2892  TW_KbcJ_ba,
2893  TW_AbCd_ab, TW_KlIj_ab;
2894 
2895  TArray4d g_aikl = ijxy("<a i|g|k l>");
2896  TArray4d g_aibj = ijxy("<a i|g|b j>");
2897  TArray4d g_aijb = ijxy("<a i|g|j b>");
2898  TArray4d g_abci = ijxy("<a b|g|c i>");
2899  TArray4d g_ijkl = ijxy("<i j|g|k l>");
2900  TArray4d g_abcd = ijxy("<a b|g|c d>");
2901 
2902  TArray4 t2_unsymm, t2_interim;
2903 
2904  while (Delta_E >= 1.0e-12) {
2905  // compute intermediates
2906  compute_intermediates_TFW_ccsd(t1, t2,
2907  g_abij, g_aikl,
2908  g_aibj, g_aijb, g_abci,
2909  g_ijkl, g_abcd,
2910  TFkc, TFac, TFki,
2911  TW_KbCj_ab, TW_KbcJ_ba,
2912  TW_AbCd_ab, TW_KlIj_ab);
2913 
2914  t2_interim("a,b,i,j") = 2.0 * t2("a,b,i,j") - t2("b,a,i,j");
2915 
2916  auto t1_temp = Delta_ai("a,i") * (
2917  // fai
2918  //fai("a,i")
2919  // + TFac t^c_i
2920  TFac("a,c") * t1("c,i")
2921  // - TFki t^a_k
2922  - TFki("k,i") * t1("a,k")
2923  // + TFkc t^ac_ik
2924  + TFkc("k,c") * t2_interim("a,c,i,k")
2925  // + t^c_k g^ak_ic
2926  + t1("c,k") * (2.0 * g_aijb("a,k,i,c") - g_aibj("a,k,c,i"))
2927  // - 1/2 t^ac_kl g^kl_ic
2928  - t2_interim("c,a,k,l") * g_aikl("c,i,k,l")
2929  // + 1/2 t^cd_ik g^ak_cd
2930  + t2_interim("c,d,i,k") * g_abci("c,d,a,k")
2931  );
2932 
2933  auto t2_temp = Delta_abij("a,b,i,j") * (
2934  // g^ab_ij
2935  g_abij("a,b,i,j")
2936 
2937  // + P_(ab) t^ac_ij (TFbc - 1/2 t^b_k TFkc)
2938  + t2("a,c,i,j") * (TFac("b,c") - 0.5 * t1("b,k") * TFkc("k,c"))
2939  + t2("c,b,i,j") * (TFac("a,c") - 0.5 * t1("a,k") * TFkc("k,c"))
2940 
2941  // - P_(ij) T^ab_ik (TFkj + 1/2 t^c_j TFkc)
2942  - t2("a,b,i,k") * (TFki("k,j") + 0.5 * t1("c,j") * TFkc("k,c"))
2943  - t2("a,b,k,j") * (TFki("k,i") + 0.5 * t1("c,i") * TFkc("k,c"))
2944 
2945  // + 1/2 tau^ab_kl TW_klij
2946  + tau_ab("a,b,k,l") * TW_KlIj_ab("k,l,i,j")
2947 
2948  // + 1/2 tau^cd_ij TW_abcd
2949  + tau_ab("c,d,i,j") * TW_AbCd_ab("a,b,c,d")
2950 
2951  // + P_(ij) P_(ab) (t^ac_ik TW_kbcj - t^c_i t^a_k g^kb_cj)
2952  + ( t2("a,c,i,k") * TW_KbcJ_ba("k,b,c,j")
2953  + t2_interim("a,c,i,k") * TW_KbCj_ab("k,b,c,j")
2954  //
2955  - t1("c,i") * (t1("a,k") * g_aijb("b,k,j,c"))
2956  )
2957  // - P(ab)
2958  - (- t2("c,b,i,k") * TW_KbcJ_ba("k,a,c,j") // TW_kBCj_ba => TW_KbcJ_ba
2959  + t1("c,i") * (t1("b,k") * g_aibj("a,k,c,j"))
2960  )
2961  // - P(ij)
2962  - (- t2("a,c,k,j") * TW_KbcJ_ba("k,b,c,i")
2963  + t1("c,j") * (t1("a,k") * g_aibj("b,k,c,i"))
2964  )
2965  // + P_(ij) P_(ab)
2966  + ( t2("b,c,j,k") * TW_KbcJ_ba("k,a,c,i")
2967  + t2_interim("b,c,j,k") * TW_KbCj_ab("k,a,c,i")
2968  //
2969  - t1("c,j") * (t1("b,k") * g_aijb("a,k,i,c"))
2970  )
2971 
2972  // + P(ij) t^c_i g^ab_cj
2973  + t1("c,i") * g_abci("a,b,c,j")
2974  + t1("c,j") * g_abci("b,a,c,i")
2975 
2976  // - P(ab) t^a_k g^kb_ij
2977  - t1("a,k") * g_aikl("b,k,j,i")
2978  - t1("b,k") * g_aikl("a,k,i,j")
2979  );
2980 
2981  if (method == "f12b" || method == "F12b") {
2982  t1("a,i") = t1_temp
2983  + T1_f12contri("a,i")
2984  ;
2985 
2986  // recompute F12 contributions to T2 which depend on T amplitudes
2987  T2_f12contri_T1("a,b,i,j") = Delta_abij("a,b,i,j") * (
2988  // - 1/2 R^ij_AB g^AB_ak t^k_b - 1/2 R^ij_AB g^AB_kb t^k_a
2989  - V_KLAJ_temp("i,j,a,k") * t1("b,k")
2990  - V_KLAJ_temp("j,i,b,k") * t1("a,k")
2991  // + 1/2 R^ij_AB g^AB_kl t^k_a t^l_b
2992  + V_IJKL_temp("i,j,k,l") * t1("a,k") * t1("b,l")
2993  );
2994 
2995  t2_unsymm("a,b,i,j") = t2_temp
2996  + T2_f12contri("a,b,i,j")
2997  + T2_f12contri_T1("a,b,i,j")
2998  ;
2999  } else {
3000  t1("a,i") = t1_temp;
3001  t2_unsymm("a,b,i,j") = t2_temp;
3002  }
3003 
3004  t2("a,b,i,j") = 0.5 * (t2_unsymm("a,b,i,j") + t2_unsymm("b,a,j,i"));
3005  tau_ab("a,b,i,j") = t2("a,b,i,j") + t1("a,i") * t1("b,j");
3006 
3007  // recompute energy
3008  E_0 = E_1;
3009  E_1 = //2.0 * dot(fai("a,i"), t1("a,i")) +
3010  dot(gabij_temp("a,b,i,j"), tau_ab("a,b,i,j") );
3011  Delta_E = std::abs(E_0 - E_1);
3012  iter += 1;
3013  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-15.12f", Delta_E)
3014  << scprintf("%-15.12f", E_1) << std::endl;
3015  }
3016  //std::cout << "CCSD T1 amplitudes: " << std::endl << t1 << std::endl;
3017 
3018  }
3019 
3020  template <typename T>
3021  void SingleReference_R12Intermediates<T>::compute_lambda_ccsd(const TArray2& t1, const TArray4& t2,
3022  TArray2& L1, TArray4& L2,
3023  const std::string method) {
3024 
3025  TArray4d g_abij = ijxy("<a b|g|i j>");
3026  TArray4d g_abci = ijxy("<a b|g|c i>");
3027  TArray2 fai = xy("<a|F|i>");
3028 
3029  // compute Delta_ai = 1 / (- <a|F|a> + <i|F|i>)
3030  // & Delta_ijab = 1 / (- <a|F|a> - <b|F|b> + <i|F|i> + <j|F|j>)
3031  TArray2 Delta_ai;
3032  TArray4 Delta_abij;
3033  compute_Delta_cc(fai.trange(), g_abij.trange(), Delta_ai, Delta_abij);
3034 
3035  // initial guess for L1 and L2
3036  TArray2 L1_f12contri, L1_f12b, L1_f12b_L2;
3037  TArray4 L2_f12contri, Vijab, Vklib, Vklij;
3038  if (method == "ccsd" || method == "CCSD") {
3039  L1("a,i") = t1("a,i");
3040  L2("a,b,i,j") = t2("a,b,i,j");
3041 
3042  } else {
3043  const double C_0 = 1.0 / 2.0;
3044  const double C_1 = 1.0 / 4.0;
3045  const double RC1 = 0.5 * (C_0 + C_1);
3046  const double RC2 = 0.5 * (C_0 - C_1);
3047 
3048  TArray2 V_ia;
3049  const char* i = "i";
3050  const char* a = "a";
3051  V_ia = VRk_Sk(i,a, C_0, C_1);
3052 
3053  L1_f12contri("a,i") = Delta_ai("a,i") * V_ia("i,a");
3054 
3055  TArray4 rg_ijab;
3056  TArray4d r_ijaPn = ijxy("<i j|r|a' n>");
3057  TArray4d g_aPnab = ijxy("<a' n|g|a b>");
3058  rg_ijab("i,j,a,b") = _4("<i j|gr|a b>")
3059  - _4("<i j|r|p q>") * _4("<p q|g|a b>")
3060  - r_ijaPn("i,j,a',n") * g_aPnab("a',n,a,b")
3061  - r_ijaPn("j,i,a',n") * g_aPnab("a',n,b,a");
3062 
3063  TArray4d r_ijaFb = ijxy("<i j|r|a_F(c') b>");
3064 
3065  L2_f12contri("a,b,i,j") = Delta_abij("a,b,i,j")
3066  * ( RC1 * r_ijaFb("i,j,a,b") + RC2 * r_ijaFb("j,i,a,b")
3067  + RC1 * r_ijaFb("j,i,b,a") + RC2 * r_ijaFb("i,j,b,a")
3068  + RC1 * rg_ijab("i,j,a,b") + RC2 * rg_ijab("j,i,a,b")
3069  );
3070 
3071  if (method == "f12" || method == "F12") {
3072  L1("a,i") = t1("a,i") + L1_f12contri("a,i") * 2.0;
3073  L2("a,b,i,j") = t2("a,b,i,j") + L2_f12contri("a,b,i,j") * 2.0;
3074 
3075  } else if (method == "f12b" || method == "F12b") {
3076 
3077  // contributions to L1 equation
3078  const char* j = "j";
3079  const char* k = "k";
3080  const char* l = "l";
3081  const char* b = "b";
3082 
3083  // 1st contribution
3084  Vijab = VPq_Rs(i, j, a, b, C_0, C_1);
3085  L1_f12b("a,i") = Delta_ai("a,i")
3086  * (Vijab("i,j,a,b") * t1("b,j")); // 1/2 R_ij^AB g_AB^ab t^j_b
3087 
3088  // 2nd contribution that depends on L2 amplitudes
3089  Vklib = VPq_Rs(k, l, i, b, C_0, C_1);
3090  Vklij = VPq_Rs(k, l, i, j, C_0, C_1);
3091  //TArray4 V_KLAJ = VPQ_RS(k, l, a, j);
3092  //TArray4 V_IJKL = VPQ_RS(i, j, k, l);
3093 // L1_f12b_L2("a,i") = Delta_ai("a,i") * (
3094 // // - 1/4 l^ab_kl R^kl_AB g^AB_ib
3095 // - Vklib("k,l,i,b") * L2("a,b,k,l")
3096 //
3097 // // + 1/4 l^ab_kl R^kl_AB g^AB_ij t^j_b
3098 // + Vklij("k,l,i,j") * L2("a,b,k,l") * t1("b,j")
3099 // );
3100 
3101  L1("a,i") = t1("a,i")
3102  + L1_f12contri("a,i")
3103  + L1_f12b("a,i")// + L1_f12b_L2("a,i")
3104  ;
3105  L2("a,b,i,j") = t2("a,b,i,j")
3106  + L2_f12contri("a,b,i,j")
3107  ;
3108  }
3109  }
3110 
3111  TArray4 gabij_temp;
3112  gabij_temp("a,b,i,j") = 2.0 * g_abij("a,b,i,j") - g_abij("b,a,i,j");
3113 
3114  // pseudo energy
3115  double E_0_L = 0.0;
3116  double E_1_L = dot(gabij_temp("a,b,i,j"), L2("a,b,i,j") );
3117  double Delta_E_L = std::abs(E_0_L - E_1_L);
3118 
3119  double iter = 0;
3120  std::cout << indent << scprintf("%-5s", "Iter") << scprintf("%-20s", "Delta_E_L")
3121  << scprintf("%-20s", "E_L(CCSD)") << std::endl;
3122  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-15.12f", Delta_E_L)
3123  << scprintf("%-15.12f", E_1_L) << std::endl;
3124 
3125  // compute intermediates
3126  TArray2 CFkc, CFac, CFki;
3127  // \cal{W}mbej
3128  TArray4 CW_KbCj_ab,
3130  CW_KbcJ_ba,
3131  // \cal{W}abei
3132  CW_AbCd_ab, CW_AbCi_ab,
3133  // \cal{W}mbij
3134  CW_KlIj_ab, CW_KbIj_ab,
3135  // intermediates for L2
3136  CW_KlIc_ab, CW_KliC_ab, CW_AkCd_ab;
3137 
3138  compute_intermediates_CW_ccsd(t1, t2, CFkc, CFac, CFki,
3139  CW_KbCj_ab, CW_KbcJ_ba,
3140  CW_AbCd_ab, CW_AbCi_ab,
3141  CW_KlIj_ab, CW_KbIj_ab,
3142  CW_KlIc_ab, CW_KliC_ab, CW_AkCd_ab);
3143 
3144  TArray2 CGac, CGki;
3145 
3146  TArray4 L2_unsymm, L2abij_temp;
3147 
3148  while (Delta_E_L >= 1.0e-12) {
3149 
3150  L2abij_temp("a,b,i,j") = 2.0 * L2("a,b,i,j") - L2("b,a,i,j");
3151 
3152  CGac("a,c") = // - 1/2 t^cd_kl lambda^kl_ad
3153  - t2("c,d,k,l") * L2abij_temp("a,d,k,l");
3154  CGki("k,i") = // 1/2 t^cd_kl lambda^il_cd
3155  t2("c,d,k,l") * L2abij_temp("c,d,i,l");
3156 
3157  auto L1_temp = Delta_ai("a,i") * (
3158  // \cal{F}ia
3159  CFkc("i,a")
3160  // + \lambda^i_c \cal{F}ca
3161  + L1("c,i") * CFac("c,a")
3162  // - \lambda^k_a \cal{F}ik
3163  - L1("a,k") * CFki("i,k")
3164  // + \lambda^k_c \cal{W}icak
3165  + L1("c,k") * (2.0 * CW_KbCj_ab("i,c,a,k") + CW_KbcJ_ba("i,c,a,k"))
3166  // + 1/2 \lambda^ik_cd \cal{W}cdak
3167  + L2abij_temp("c,d,i,k") * CW_AbCi_ab("c,d,a,k")
3168  // - 1/2 \lambda^kl_ac \cal{W}ickl
3169  - L2abij_temp("a,c,k,l") * CW_KbIj_ab("i,c,k,l")
3170 
3171  // CCSD only terms:
3172  // - cal{G}cd cal{W}cida
3173  - CGac("c,d") * (2.0 * CW_AkCd_ab("c,i,d,a") - CW_AkCd_ab("c,i,a,d")) // CW_aKcD => CW_AkCd_ab
3174  // - cal{G}kl cal{W}kila
3175  - CGki("k,l") * (2.0 * CW_KlIc_ab("k,i,l,a") + CW_KliC_ab("k,i,l,a"))
3176  );
3177 
3178  auto L2_temp = Delta_abij("a,b,i,j") * (
3179  // g^ij_ab
3180  g_abij("a,b,i,j")
3181 
3182  // + P(ij) \lambda^i_c \cal{W}cjab
3183  + L1("c,i") * CW_AkCd_ab("c,j,a,b")
3184  + L1("c,j") * CW_AkCd_ab("c,i,b,a")
3185 
3186  // - P(ab) \lambda^k_a \cal{W}ijkb
3187  - L1("a,k") * CW_KlIc_ab("i,j,k,b")
3188  + L1("b,k") * CW_KliC_ab("i,j,k,a")
3189 
3190  // + P(ij) P(ab) \lambda^i_a \cal{F}jb
3191  + L1("a,i") * CFkc("j,b")
3192  //- L1("b,i") * CFkc("j,a")
3193  //- L1("a,j") * CFkc("i,b")
3194  + L1("b,j") * CFkc("i,a")
3195 
3196  // CCSD term
3197  // + P(ab) \lambda^ij_ac \cal{F}cb
3198  + L2("a,c,i,j") * CFac("c,b")
3199  + L2("c,b,i,j") * CFac("c,a")
3200 
3201  // CCSD term
3202  // - P(ij) \lambda^ik_ab \cal{F}jk
3203  - L2("a,b,i,k") * CFki("j,k")
3204  - L2("a,b,k,j") * CFki("i,k")
3205 
3206 
3207  // + 1/2 \lambda^kl_ab \cal{W}ijkl
3208  + L2("a,b,k,l") * CW_KlIj_ab("i,j,k,l")
3209 
3210  // + 1/2 \lambda^ij_cd \cal{W}cdab
3211  + L2("c,d,i,j") * CW_AbCd_ab("c,d,a,b")
3212 
3213  // + P(ij) P(ab) \lambda^ik_ac \cal{W}jcbk
3214  + ( L2abij_temp("a,c,i,k") * CW_KbCj_ab("j,c,b,k")
3215  + L2("a,c,i,k") * CW_KbcJ_ba("j,c,b,k")) // CW_kbcj => CW_KBCJ_aa
3216  // P(ab)
3217  + L2("c,b,i,k") * CW_KbcJ_ba("j,c,a,k") // CW_kBCj => CW_KbcJ_ab
3218  // P(ij)
3219  + L2("a,c,k,j") * CW_KbcJ_ba("i,c,b,k")
3220  // P(ij) P(ab)
3221  + ( L2abij_temp("b,c,j,k") * CW_KbCj_ab("i,c,a,k")
3222  + L2("b,c,j,k") * CW_KbcJ_ba("i,c,a,k"))
3223 
3224  // + P(ab) g^ij_ac Gbc
3225  + g_abij("a,c,i,j") * CGac("b,c")
3226  + g_abij("c,b,i,j") * CGac("a,c")
3227 
3228  // - P(ij) g^ik_ab Gkj
3229  - g_abij("a,b,i,k") * CGki("k,j")
3230  - g_abij("a,b,k,j") * CGki("k,i")
3231  );
3232 
3233  if (method == "ccsd" || method == "CCSD") {
3234  L1("a,i") = L1_temp;
3235  L2_unsymm("a,b,i,j") = L2_temp;
3236 
3237  } else if (method == "f12" || method == "F12") {
3238  L1("a,i") = L1_temp + L1_f12contri("a,i") * 2.0;
3239  L2_unsymm("a,b,i,j") = L2_temp + L2_f12contri("a,b,i,j") * 2.0;
3240 
3241  } else if (method == "f12b" || method == "F12b") {
3242 
3243  L1_f12b_L2("a,i") = Delta_ai("a,i") * (
3244  // - 1/4 l^ab_kl R^kl_AB g^AB_ib
3245  - Vklib("k,l,i,b") * L2("a,b,k,l")
3246 
3247  // + 1/4 l^ab_kl R^kl_AB g^AB_ij t^j_b
3248  + Vklij("k,l,i,j") * L2("a,b,k,l") * t1("b,j")
3249  );
3250 
3251  L1("a,i") = L1_temp
3252  + L1_f12contri("a,i")
3253  + L1_f12b("a,i") + L1_f12b_L2("a,i")
3254  ;
3255  L2_unsymm("a,b,i,j") = L2_temp
3256  + L2_f12contri("a,b,i,j")
3257  ;
3258 
3259  }
3260 
3261  L2("a,b,i,j") = 0.5 * (L2_unsymm("a,b,i,j") + L2_unsymm("b,a,j,i"));
3262 
3263  E_0_L = E_1_L;
3264  E_1_L = dot(gabij_temp("a,b,i,j"), L2("a,b,i,j") );
3265  Delta_E_L = std::abs(E_0_L - E_1_L);
3266 
3267  iter += 1;
3268  std::cout << indent << scprintf("%-5.0f", iter) << scprintf("%-15.12f", Delta_E_L)
3269  << scprintf("%-15.12f", E_1_L) << std::endl;
3270  }
3271  //std::cout << "CC2 L1 amplitudes: " << std::endl << L1 << std::endl;
3272  }
3273 
3274  // compute intermediates for CCSD Xam (Xai)
3275  template <typename T>
3276  void SingleReference_R12Intermediates<T>::compute_Gamma_ijab_ccsd(const TArray2& T1, const TArray4& T2,
3277  const TArray4& tau_ab,
3278  const TArray2& L1, const TArray4& L2,
3279  TArray4& Gamma_IjAb_ab) {
3280 // // i,j,a,b in alpha or beta space
3281 // Gamma_IJAB_aa("i,j,a,b") = // 1/4 tau^ab_ij
3282 // 0.25 * tau_aa("a,b,i,j")
3283 //
3284 // // CCSD modified term
3285 // // + 1/16 tau^cd_ij lambda^kl_cd tau^ab_kl
3286 // + 0.0625 * tau_aa("c,d,i,j")
3287 // * (L2("c,d,k,l") - L2("c,d,l,k"))
3288 // * tau_aa("a,b,k,l")
3289 //
3290 // // CCSD terms only
3291 // // - 1/8 P-(ij) t^cd_il lambda^kl_cd tau^ab_kj
3292 // - 0.125 * (T2("c,d,i,l") - T2("c,d,l,i"))
3293 // * (L2("c,d,k,l") - L2("c,d,l,k")) * tau_aa("a,b,k,j")
3294 // - 0.25 * T2("c,d,i,l") * L2("c,d,k,l") * tau_aa("a,b,k,j")
3295 // // - P(ij)
3296 // + 0.125 * (T2("c,d,j,l") - T2("c,d,l,j"))
3297 // * (L2("c,d,k,l") - L2("c,d,l,k")) * tau_aa("a,b,k,i")
3298 // + 0.25 * T2("c,d,j,l") * L2("c,d,k,l") * tau_aa("a,b,k,i")
3299 //
3300 //
3301 // // - 1/4 P-(ij) t^c_i lambda^k_c tau^ab_kj
3302 // - 0.25 * ( T1("c,i") * tau_aa("a,b,k,j")
3303 // - T1("c,j") * tau_aa("a,b,k,i")
3304 // ) * L1("c,k")
3305 //
3306 // // CCSD only term
3307 // // - 1/8 P-(ab) t^ad_kl lambda^kl_cd tau^cb_ij
3308 // - 0.125 * (T2("a,d,k,l") - T2("d,a,k,l"))
3309 // * (L2("c,d,k,l") - L2("c,d,l,k")) * tau_aa("c,b,i,j")
3310 // - 0.25 * T2("a,d,k,l") * L2("c,d,k,l") * tau_aa("c,b,i,j")
3311 // // - P(ab)
3312 // + 0.125 * (T2("b,d,k,l") - T2("d,b,k,l"))
3313 // * (L2("c,d,k,l") - L2("c,d,l,k")) * tau_aa("c,a,i,j")
3314 // + 0.25 * T2("b,d,k,l") * L2("c,d,k,l") * tau_aa("c,a,i,j")
3315 //
3316 // // - 1/4 P-(ab) t^a_k lambda^k_c tau^cb_ij
3317 // - 0.25 * ( T1("a,k") * tau_aa("c,b,i,j")
3318 // - T1("b,k") * tau_aa("c,a,i,j")
3319 // ) * L1("c,k")
3320 //
3321 // // CCSD only term
3322 // // - 1/8 P-(ij) P-(ab) (t^ac_ki + 2 t^c_i t^a_k) lambda^kl_cd t^bd_jl
3323 // // + 1/8 P-(ij) P-(ab) t^ac_ik lambda^kl_cd t^bd_jl
3324 // + 0.125 * ( (T2("a,c,i,k") - T2("c,a,i,k"))
3325 // * (L2("c,d,k,l") - L2("d,c,k,l"))
3326 // * (T2("b,d,j,l") - T2("d,b,j,l"))
3327 // + (T2("a,c,i,k") - T2("c,a,i,k")) * L2("c,d,k,l") * T2("b,d,j,l")
3328 // + T2("a,c,i,k") * (L2("c,d,k,l") - L2("d,c,k,l")) * T2("b,d,j,l")
3329 // + T2("a,c,i,k") * L2("c,d,k,l") * (T2("b,d,j,l") - T2("d,b,j,l"))
3330 //
3331 // // P(ab)
3332 // - (T2("b,c,i,k") - T2("c,b,i,k"))
3333 // * (L2("c,d,k,l") - L2("d,c,k,l"))
3334 // * (T2("a,d,j,l") - T2("d,a,j,l"))
3335 // - (T2("b,c,i,k") - T2("c,b,i,k")) * L2("c,d,k,l") * T2("a,d,j,l")
3336 // - T2("b,c,i,k") * (L2("c,d,k,l") - L2("d,c,k,l")) * T2("a,d,j,l")
3337 // - T2("b,c,i,k") * L2("c,d,k,l") * (T2("a,d,j,l") - T2("d,a,j,l"))
3338 //
3339 // // P(ij)
3340 // - (T2("a,c,j,k") - T2("c,a,j,k"))
3341 // * (L2("c,d,k,l") - L2("d,c,k,l"))
3342 // * (T2("b,d,i,l") - T2("d,b,i,l"))
3343 // - (T2("a,c,j,k") - T2("c,a,j,k")) * L2("c,d,k,l") * T2("b,d,i,l")
3344 // - T2("a,c,j,k") * (L2("c,d,k,l") - L2("d,c,k,l")) * T2("b,d,i,l")
3345 // - T2("a,c,j,k") * L2("c,d,k,l") * (T2("b,d,i,l") - T2("d,b,i,l"))
3346 //
3347 // // P(ij)P(ab)
3348 // + (T2("b,c,j,k") - T2("c,b,j,k"))
3349 // * (L2("c,d,k,l") - L2("d,c,k,l"))
3350 // * (T2("a,d,i,l") - T2("d,a,i,l"))
3351 // + (T2("b,c,j,k") - T2("c,b,j,k")) * L2("c,d,k,l") * T2("a,d,i,l")
3352 // + T2("b,c,j,k") * (L2("c,d,k,l") - L2("d,c,k,l")) * T2("a,d,i,l")
3353 // + T2("b,c,j,k") * L2("c,d,k,l") * (T2("a,d,i,l") - T2("d,a,i,l"))
3354 // )
3355 // // - 1/4 P-(ij) P-(ab) t^c_i t^a_k lambda^kl_cd t^bd_jl
3356 // - 0.25 * ( ( T1("c,i") * T1("a,k") * (T2("b,d,j,l") - T2("d,b,j,l"))
3357 // - T1("c,i") * T1("b,k") * (T2("a,d,j,l") - T2("d,a,j,l"))
3358 // - T1("c,j") * T1("a,k") * (T2("b,d,i,l") - T2("d,b,i,l"))
3359 // + T1("c,j") * T1("b,k") * (T2("a,d,i,l") - T2("d,a,i,l"))
3360 // ) * (L2("c,d,k,l") - L2("d,c,k,l"))
3361 //
3362 // + ( T1("c,i") * T1("a,k") * T2("b,d,j,l")
3363 // - T1("c,i") * T1("b,k") * T2("a,d,j,l")
3364 // - T1("c,j") * T1("a,k") * T2("b,d,i,l")
3365 // + T1("c,j") * T1("b,k") * T2("a,d,i,l")
3366 // ) * L2("c,d,k,l")
3367 // )
3368 //
3369 // // - 1/4 P-(ij) P-(ab) (t^ac_ki + 2 t^c_i t^a_k) lambda^k_c t^b_j
3370 // // => - 1/4 P-(ij) P-(ab) (- t^ac_ik + 2 t^c_i t^a_k) t^b_j
3371 // - 0.25 * ( (- 2.0 * T2("a,c,i,k") + T2("c,a,i,k")
3372 // + 2.0 * T1("c,i") * T1("a,k")
3373 // ) * T1("b,j")
3374 // // P(ab)
3375 // - (- 2.0 * T2("b,c,i,k") + T2("c,b,i,k")
3376 // + 2.0 * T1("c,i") * T1("b,k")
3377 // ) * T1("a,j")
3378 // // P(ij)
3379 // - (- 2.0 * T2("a,c,j,k") + T2("c,a,j,k")
3380 // + 2.0 * T1("c,j") * T1("a,k")
3381 // ) * T1("b,i")
3382 // // P(ij) P(ab)
3383 // + (- 2.0 * T2("b,c,j,k") + T2("c,b,j,k")
3384 // + 2.0 * T1("c,j") * T1("b,k")
3385 // ) * T1("a,i")
3386 // ) * L1("c,k")
3387 //
3388 // // + 3/4 P-(ij) P-(ab) t^a_i t^c_j lambda^k_c t^b_k
3389 // + 0.75 * ( T1("a,i") * T1("c,j") * T1("b,k")
3390 // - T1("b,i") * T1("c,j") * T1("a,k")
3391 // - T1("a,j") * T1("c,i") * T1("b,k")
3392 // + T1("b,j") * T1("c,i") * T1("a,k")
3393 // ) * L1("c,k")
3394 //
3395 // ;
3396 
3397  // a,i in alpha space, b,j in beta space
3398  Gamma_IjAb_ab("i,j,a,b") = // 1/4 tau^ab_ij
3399  0.25 * tau_ab("a,b,i,j")
3400 
3401  // CCSD modified term
3402  // + 1/16 tau^cd_ij lambda^kl_cd tau^ab_kl
3403  + 0.25 * tau_ab("c,d,i,j") * L2("c,d,k,l")
3404  * tau_ab("a,b,k,l")
3405 
3406  // CCSD terms only
3407  // - 1/8 P-(ij) t^cd_il lambda^kl_cd tau^ab_kj
3408  - 0.125 * (T2("c,d,i,l") - T2("c,d,l,i"))
3409  * (L2("c,d,k,l") - L2("c,d,l,k")) * tau_ab("a,b,k,j")
3410  - 0.25 * T2("c,d,i,l") * L2("c,d,k,l") * tau_ab("a,b,k,j")
3411  // - P(ij)
3412  - 0.125 * (T2("c,d,j,l") - T2("c,d,l,j"))
3413  * (L2("c,d,k,l") - L2("c,d,l,k")) * tau_ab("a,b,i,k")
3414  - 0.25 * T2("c,d,j,l") * L2("c,d,k,l") * tau_ab("a,b,i,k")
3415 
3416  // - 1/4 P-(ij) t^c_i lambda^k_c tau^ab_kj
3417  - 0.25 * ( T1("c,i") * tau_ab("a,b,k,j")
3418  + T1("c,j") * tau_ab("a,b,i,k")
3419  ) * L1("c,k")
3420 
3421  // CCSD only term
3422  // - 1/8 P-(ab) t^ad_kl lambda^kl_cd tau^cb_ij
3423  - 0.125 * (T2("a,d,k,l") - T2("d,a,k,l"))
3424  * (L2("c,d,k,l") - L2("c,d,l,k")) * tau_ab("c,b,i,j")
3425  - 0.25 * T2("a,d,k,l") * L2("c,d,k,l") * tau_ab("c,b,i,j")
3426  // - P(ab)
3427  - 0.125 * (T2("b,d,k,l") - T2("d,b,k,l"))
3428  * (L2("c,d,k,l") - L2("c,d,l,k")) * tau_ab("a,c,i,j")
3429  - 0.25 * T2("b,d,k,l") * L2("c,d,k,l") * tau_ab("a,c,i,j")
3430 
3431  // - 1/4 P-(ab) t^a_k lambda^k_c tau^cb_ij
3432  - 0.25 * ( T1("a,k") * tau_ab("c,b,i,j")
3433  + T1("b,k") * tau_ab("a,c,i,j")
3434  ) * L1("c,k")
3435 
3436  // - 1/8 P-(ij) P-(ab) (t^ac_ki + 2 t^c_i t^a_k) lambda^kl_cd t^bd_jl
3437  // + 1/8 P-(ij) P-(ab) t^ac_ik lambda^kl_cd t^bd_jl
3438  + 0.125 * ( (T2("a,c,i,k") - T2("c,a,i,k"))
3439  * (L2("c,d,k,l") - L2("d,c,k,l")) * T2("b,d,j,l")
3440  + (T2("a,c,i,k") - T2("c,a,i,k"))
3441  * L2("c,d,k,l") * (T2("b,d,j,l") - T2("d,b,j,l"))
3442  + T2("a,c,i,k") * (L2("c,d,k,l") - L2("d,c,k,l"))
3443  * (T2("b,d,j,l") - T2("d,b,j,l"))
3444  + T2("a,c,i,k") * L2("c,d,k,l") * T2("b,d,j,l")
3445 
3446  // P(ab)
3447  + T2("c,b,i,k") * L2("c,d,l,k") * T2("a,d,l,j")
3448 
3449  // P(ij)
3450  + T2("a,c,k,j") * L2("d,c,k,l") * T2("d,b,i,l")
3451 
3452  //P(ij)P(ab)
3453  + T2("b,c,j,k") * (L2("c,d,k,l") - L2("d,c,k,l"))
3454  * (T2("a,d,i,l") - T2("d,a,i,l"))
3455  + T2("b,c,j,k") * L2("c,d,k,l") * T2("a,d,i,l")
3456  + (T2("b,c,j,k") - T2("c,b,j,k"))
3457  * L2("c,d,k,l") * (T2("a,d,i,l") - T2("d,a,i,l"))
3458  + (T2("b,c,j,k") - T2("c,b,j,k"))
3459  * (L2("c,d,k,l") - L2("d,c,k,l"))
3460  * T2("a,d,i,l")
3461  )
3462  // - 1/4 P-(ij) P-(ab) t^c_i t^a_k lambda^kl_cd t^bd_jl
3463  - 0.25 * ( T1("c,i") * T1("a,k")
3464  * ( (L2("c,d,k,l") - L2("d,c,k,l")) * T2("b,d,j,l")
3465  + L2("c,d,k,l") * (T2("b,d,j,l") - T2("d,b,j,l"))
3466  )
3467  // P(ab)
3468  - T1("c,i") * T1("b,k") * L2("c,d,l,k") * T2("a,d,l,j")
3469  // P(ij)
3470  - T1("c,j") * T1("a,k") * L2("d,c,k,l") * T2("d,b,i,l")
3471  // P(ij) P(ab)
3472  + T1("c,j") * T1("b,k")
3473  * ( (L2("c,d,k,l") - L2("d,c,k,l")) * T2("a,d,i,l")
3474  + L2("c,d,k,l") * (T2("a,d,i,l") - T2("d,a,i,l"))
3475  )
3476  )
3477 
3478  // - 1/4 P-(ij) P-(ab) (t^ac_ki + 2 t^c_i t^a_k) lambda^k_c t^b_j
3479  - 0.25 * ( (- 2.0 * T2("a,c,i,k") + T2("c,a,i,k")
3480  + 2.0 * T1("c,i") * T1("a,k")
3481  ) * T1("b,j")
3482  //
3483  + (- 2.0 * T2("b,c,j,k") + T2("c,b,j,k")
3484  + 2.0 * T1("c,j") * T1("b,k")
3485  ) * T1("a,i")
3486  ) * L1("c,k")
3487 
3488  // + 3/4 P-(ij) P-(ab) t^a_i t^c_j lambda^k_c t^b_k
3489  + 0.75 * ( T1("a,i") * T1("c,j") * T1("b,k")
3490  + T1("b,j") * T1("c,i") * T1("a,k")
3491  ) * L1("c,k")
3492  ;
3493 
3494  }
3495 
3496  // compute Gamma intermediates following JCP, 95, 2623(1991)
3497  template <typename T>
3498  void SingleReference_R12Intermediates<T>::compute_Gamma2_ccsd(const TArray2& T1, const TArray4& T2,
3499  const TArray2& L1, const TArray4& L2,
3500  const TArray4& tau_aa, const TArray4& tau_ab,
3501  TArray4& Gamma_IjKa_ab,
3502  TArray4& Gamma_AbCi_ab,
3503  TArray4& Gamma_iBjA_ab, TArray4& Gamma_iBJa_ba,
3504  TArray4& Gamma_AbCd_ab, TArray4& Gamma_IjKl_ab,
3505  TArray4& Gamma_IjAb_ab) {
3506 
3507  TArray2 CGac, CGki;
3508  CGac("a,c") = - 0.5 * (T2("c,d,k,l") - T2("d,c,k,l"))
3509  * (L2("a,d,k,l") - L2("d,a,k,l"))
3510  - T2("c,d,k,l") * L2("a,d,k,l");
3511 
3512  CGki("k,i") = 0.5 * (T2("c,d,k,l") - T2("c,d,l,k"))
3513  * (L2("c,d,i,l") - L2("c,d,l,i"))
3514  + T2("c,d,k,l") * L2("c,d,i,l");
3515 
3516  TArray4 VKlIj_ab, VIBJA_aa, VIbJa_ab, ViBJa_ba, VAbCd_ab;
3517 
3518  VKlIj_ab("k,l,i,j") = tau_ab("c,d,k,l") * L2("c,d,i,j");
3519 
3520  VIBJA_aa("i,b,j,a") = 0.5 * (T2("a,c,i,k") - T2("a,c,k,i"))
3521  * (L2("b,c,j,k") - L2("b,c,k,j"))
3522  + 0.5 * T2("a,c,i,k") * L2("b,c,j,k");
3523  VIbJa_ab("i,b,j,a") = 0.5 * T2("c,a,i,k") * L2("c,b,j,k");
3524  ViBJa_ba("i,b,j,a") = 0.5 * (T2("a,c,i,k") - T2("a,c,k,i")) * L2("b,c,j,k")
3525  + 0.5 * T2("a,c,i,k") * (L2("b,c,j,k") - L2("b,c,k,j"));
3526  // VIbjA_ba("i,b,j,a") = ViBJa_ba("i,b,j,a")
3527  // ViBjA_ab("i,b,j,a") = VIbJa_ab("i,b,j,a")
3528  // ViBjA_ab("i,b,j,a") = 0.5 * T2("a,c,k,i") * L2("b,c,k,j");
3529  // VIBja_ba("i,b,j,a") = VIbJa_ab("i,b,j,a")
3530  //VIBja_ba("i,b,j,a") = 0.5 * T2("c,a,i,k") * L2("b,c,k,j");
3531 
3532  VAbCd_ab("a,b,c,d") = tau_ab("c,d,k,l") * L2("a,b,k,l");
3533  // V_aBCd = - tau_ab("d,c,k,l") * L2("a,b,k,l")
3534 
3535  Gamma_IjKa_ab("i,j,k,a") = // - 1/8 tau^Ca_Ij lambda^K_C
3536  - 0.125 * tau_ab("c,a,i,j") * L1("c,k")
3537 
3538  // - 1/8 lambda^Ca_Ij t^K_C
3539  - 0.125 * L2("c,a,i,j") * T1("c,k")
3540 
3541  // + 1/8 V_IjKl t^a_l
3542  + 0.125 * VKlIj_ab("i,j,k,l") * T1("a,l")
3543 
3544  //*** + 1/4 P-(ij) V_kcia (V_icka ???) t^c_j
3545  // + 1/4 V_IcKa t^c_j
3546  + 0.25 * VIbJa_ab("i,c,k,a") * T1("c,j")
3547  // - 1/4 V_jCKa t^C_I
3548  - 0.25 * ViBJa_ba("j,c,k,a") * T1("c,i")
3549 
3550  // - 1/8 P-(ij) CG_IK t^a_j
3551  - 0.125 * CGki("i,k") * T1("a,j")
3552  ;
3553 
3554 // Gamma_iJkA_ab("i,j,k,a") = // - 1/8 tau^cA_iJ lambda^k_c
3555 // - 0.125 * tau_ab("c,a,i,j") * L1("c,k")
3556 //
3557 // // - 1/8 lambda^cA_iJ t^k_c
3558 // - 0.125 * L2("c,a,i,j") * T1("c,k")
3559 //
3560 // // + 1/8 V_iJkL t^A_L
3561 // + 0.125 * VKlIj_ab("i,j,k,l") * T1("a,l")
3562 //
3565 //
3566 // // - 1/8 P-(ij) CG_ik t^A_J
3567 // - 0.125 * CGki("i,k") * T1("a,j")
3568 // ;
3569 
3570  Gamma_AbCi_ab("a,b,c,i") = // 1/8 tau^ab_ki lambda^k_c
3571  0.125 * tau_ab("a,b,k,i") * L1("c,k")
3572 
3573  // 1/8 lambda^Ki_Ab t^C_K
3574  + 0.125 * L2("a,b,k,i") * T1("c,k")
3575 
3576  // - 1/8 t^d_i V_CdAb
3577  - 0.125 * T1("d,i") * VAbCd_ab("c,d,a,b")
3578 
3579  //*** + 1/4 P-(ab) V_kcib (V_ickb ???) t^a_k
3580  // + 1/4 V_iCKb t^A_K
3581  + 0.25 * ViBJa_ba("i,c,k,b") * T1("a,k")
3582  // - 1/4 V_iCkA t^b_k
3583  - 0.25 * VIbJa_ab("i,c,k,a") * T1("b,k")
3584 
3585  // - 1/8 P-(ab) t^b_i CG_ca
3586  // - 1/8 t^b_i CG_CA
3587  - 0.125 * CGac("c,a") * T1("b,i")
3588  ;
3589 
3590  // Gamma_AbcI_ab("a,b,c,i") = - Gamma_AbcI_ab("b,a,c,i")
3591 // Gamma_AbcI_ab("a,b,c,i") = // 1/8 tau^Ab_kI lambda^k_c
3592 // - 0.125 * tau_ab("a,b,i,k") * L1("c,k") // tau_ab("b,a,k,i")
3593 //
3594 // // 1/8 lambda^kI_Ab t^c_k
3595 // - 0.125 * L2("b,a,k,i") * T1("c,k")
3596 //
3597 // // - 1/8 t^D_I V_cDAb (- V_DcAb or - V_cDbA)
3598 // + 0.125 * T1("d,i") * VAbCd_ab("c,d,b,a")
3599 //
3600 // // + 1/4 P-(ab) V_kcib t^a_k
3601 // // + 1/4 V_KCib t^A_K
3602 // // - 1/4 V_kCiA t^b_k
3603 //
3604 // // - 1/8 P-(ab) t^b_i CG_ca
3605 // // + 1/8 t^A_I CG_cb
3606 // + 0.125 * CGac("c,b") * T1("a,i")
3607 // ;
3608 
3609  // Gamma_IBJA_aa = Gamma_IbJa_ab + Gamma_iBJa_ab
3610 
3611  Gamma_iBJa_ba("i,b,j,a") = // -?? 1/4 P+(ia,jb) Vibja
3612  // - 1/4 ViBJa
3613  - 0.25 * ViBJa_ba("i,b,j,a")
3614  // 1/4 VJaiB (ViBJa)
3615  - 0.25 * ViBJa_ba("j,a,i,b")
3616 
3617  // + 1/8 P+(ia,jb) t^c_i t^a_k lambda^jk_bc
3618  // + 1/8 t^c_i t^a_k lambda^Jk_Bc
3619  + 0.125 * T1("c,i") * T1("a,k") * L2("b,c,j,k")
3620  // + 1/8 t^C_J t^B_K lambda^iK_aC
3621  + 0.125 * T1("c,j") * T1("b,k") * L2("a,c,i,k")
3622 
3623  // - 1/8 P+(ia,jb) t^a_i lambda^j_b
3624  // - 1/8 t^a_i lambda^J_B
3625  - 0.125 * L1("b,j") * T1("a,i")
3626  // - 1/8 t^B_J lambda^i_a
3627  - 0.125 * L1("a,i") * T1("b,j")
3628  ;
3629 
3630  // Gamma_iBjA_ab = Gamma_IbJa_ab
3631  Gamma_iBjA_ab("i,b,j,a") = // - ?? 1/4 P+(ia,jb) Vibja
3632  // - 1/4 ViBjA (VIbJa)
3633  - 0.25 * VIbJa_ab("i,b,j,a")
3634  // - 1/4 VjAiB
3635  - 0.25 * VIbJa_ab("j,a,i,b")
3636 
3637  // + 1/8 P+(ia,jb) t^c_i t^a_k lambda^jk_bc
3638  // + 1/8 t^c_i t^A_K lambda^jK_Bc
3639  - 0.125 * T1("c,i") * T1("a,k") * L2("c,b,j,k")
3640  // + 1/8 t^c_j t^B_K lambda^iK_Ac
3641  - 0.125 * T1("c,j") * T1("b,k") * L2("c,a,i,k")
3642 
3643  // - 1/8 P+(ia,jb) t^a_i lambda^j_b
3644  ;
3645 
3646  // Gamma_IJKL_aa("i,j,k,l") = Gamma_IjKl_ab("i,j,k,l") - Gamma_IjKl_ab("j,i,k,l")
3647  Gamma_IjKl_ab("i,j,k,l") = // 1/8 P+(ij,kl) Vijkl
3648  0.125 * VKlIj_ab("k,l,i,j")
3649  + 0.125 * VKlIj_ab("i,j,k,l");
3650 
3651  // Gamma_ABCD_ab("a,b,c,d") = Gamma_AbCd_ab("a,b,c,d") - Gamma_AbCd_ab("b,a,c,d")
3652  Gamma_AbCd_ab("a,b,c,d") = // 1/8 P+(ij,kl) Vabcd
3653  0.125 * VAbCd_ab("a,b,c,d")
3654  + 0.125 * VAbCd_ab("c,d,a,b");
3655 
3656  Gamma_IjAb_ab("i,j,a,b") = // 1/8 tau^Ab_Ij
3657  0.125 * tau_ab("a,b,i,j")
3658 
3659  // 1/8 lambda^Ab_Ij
3660  + 0.125 * L2("a,b,i,j")
3661 
3662  // + 1/16 VIjkl tau^Ab_kl
3663  + 0.125 * VKlIj_ab("i,j,k,l") * tau_ab("a,b,k,l")
3664 
3665  // - 1/8 P-(ij) (Gik + t^c_i lambda^k_c) tau^ab_kj
3666  // - 1/8 (GIk + t^c_i lambda^k_c) tau^Ab_kj
3667  - 0.125 * (CGki("i,k") + T1("c,i") * L1("c,k")) * tau_ab("a,b,k,j")
3668  // + 1/8 (Gjk + t^c_j lambda^k_c) tau^Ab_kI
3669  - 0.125 * (CGki("j,k") + T1("c,j") * L1("c,k")) * tau_ab("a,b,i,k")
3670 
3671  // + 1/8 P-(ab) (Gca - t^a_k lambda^k_c) tau^cb_ij
3672  // + 1/8 (GCA - t^A_K lambda^K_C) tau^Cb_Ij
3673  + 0.125 * (CGac("c,a") - T1("a,k") * L1("c,k")) * tau_ab("c,b,i,j")
3674  // - 1/8 (Gcb - t^b_k lambda^k_c) tau^cA_Ij
3675  + 0.125 * (CGac("c,b") - T1("b,k") * L1("c,k")) * tau_ab("a,c,i,j")
3676 
3677  //*** - 1/8 P-(ij) P-(ab) (t^ac_ki + 2 t^c_i t^a_k) Vjckb
3678  // - 1/8 t^Ac_kI Vjkcb = + 1/8 t^AC_IK VjCKb + 1/8 t^Ac_Ik Vjckb
3679  + 0.125 * (T2("a,c,i,k") - T2("c,a,i,k")) * ViBJa_ba("j,c,k,b")
3680  + 0.125 * T2("a,c,i,k") * VIBJA_aa("j,c,k,b")
3681  // + 1/8 t^bC_kI VjCkA
3682  + 0.125 * T2("b,c,k,i") * VIbJa_ab("j,c,k,a")
3683  // + 1/8 t^Ac_Kj VIcKb
3684  + 0.125 * T2("a,c,k,j") * VIbJa_ab("i,c,k,b")
3685  // - 1/8 t^bc_kj VIkcA = + 1/8 t^bC_jK VICKA + 1/8 t^bc_jk VIckA
3686  + 0.125 * T2("b,c,j,k") * VIBJA_aa("i,c,k,a")
3687  + 0.125 * (T2("b,c,j,k") - T2("c,b,j,k")) * ViBJa_ba("i,c,k,a")
3688 
3689  //*** - 1/4 t^C_I t^A_K VjCKb
3690  - 0.25 * T1("c,i") * T1("a,k") * ViBJa_ba("j,c,k,b")
3691  // + 1/4 t^C_I t^b_k VjCkA
3692  + 0.25 * T1("c,i") * T1("b,k") * VIbJa_ab("j,c,k,a")
3693  // + 1/4 t^c_j t^A_K VIcKb
3694  + 0.25 * T1("c,j") * T1("a,k") * VIbJa_ab("i,c,k,b")
3695  // - 1/4 t^c_j t^b_k VIckA
3696  - 0.25 * T1("c,j") * T1("b,k") * ViBJa_ba("i,c,k,a")
3697 
3698 
3699  // - 1/8 P-(ij) P-(ab) (t^ac_ki + 2 t^c_i t^a_k) lambda^k_c t^b_j
3700  - 0.125 * (
3701  // (t^Ac_kI + 2 t^c_I t^A_k) lambda^k_c t^b_j
3702  (- 2.0 * T2("a,c,i,k") + T2("c,a,i,k")
3703  + 2.0 * T1("c,i") * T1("a,k")
3704  ) * T1("b,j")
3705  // (t^bc_kj + 2 t^c_j t^b_k) lambda^k_c t^A_I
3706  + (- 2.0 * T2("b,c,j,k") + T2("c,b,j,k")
3707  + 2.0 * T1("c,j") * T1("b,k")
3708  ) * T1("a,i")
3709  ) * L1("c,k")
3710 
3711  // *** + 3/2 (3/8 ???) P-(ij) P-(ab) t^a_i t^c_j lambda^k_c t^b_k
3712  + 0.375 * ( // t^A_I t^c_j lambda^k_c t^b_k
3713  T1("a,i") * T1("c,j") * T1("b,k")
3714  // t^b_j t^C_I lambda^K_C t^A_K
3715  + T1("b,j") * T1("c,i") * T1("a,k")
3716  ) * L1("c,k")
3717  ;
3718 
3719 
3720  }
3721 
3722  // compute CCSD one-electron density from amplitudes
3723  template <typename T>
3724  void SingleReference_R12Intermediates<T>::compute_ccsd_1rdm_amp(const TArray2& T1, const TArray4& T2,
3725  const TArray2& L1, const TArray4& L2,
3726  TArray2& Dij, TArray2& Dab,
3727  TArray2& Dia, TArray2& Dai) {
3728 
3729  TArray4 T2_temp;
3730  T2_temp("a,b,i,j") = 2.0 * T2("a,b,i,j") - T2("a,b,j,i");
3731 
3732  Dij("i,j") = // - 1/4 P+(ij) t^cd_ik lambda^jk_cd
3733  - 0.5 * ( T2_temp("c,d,i,k") * L2("c,d,j,k")
3734  + T2_temp("c,d,j,k") * L2("c,d,i,k")
3735  )
3736  // - 1/2 P+(ij) t^c_i lambda^j_c
3737  - 0.5 * ( T1("c,i") * L1("c,j")
3738  + T1("c,j") * L1("c,i")
3739  )
3740  ;
3741 
3742  Dab("a,b") = // 1/4 P+(ab) t^kl_ac lambda^bc_kl
3743  0.5 * ( T2_temp("a,c,k,l") * L2("b,c,k,l")
3744  + T2_temp("b,c,k,l") * L2("a,c,k,l")
3745  )
3746  // + 1/2 P+(ab) lambda^k_a t^b_k
3747  + 0.5 * ( L1("a,k") * T1("b,k")
3748  + L1("b,k") * T1("a,k")
3749  )
3750  ;
3751 
3752  Dia("i,a") = // t^a_i
3753  T1("a,i")
3754  // + (t^ac_ik - t^c_i t^a_k) \lambda^k_c
3755  + (T2_temp("a,c,i,k") - T1("c,i") * T1("a,k")) * L1("c,k")
3756  // CCSD term
3757  // - 1/2 lambda^kl_cd (t^cd_il t^a_k + t^c_i t^ad_kl)
3758  - (2.0 * L2("c,d,k,l") - L2("d,c,k,l"))
3759  * ( T2("c,d,i,l") * T1("a,k")
3760  + T2("a,d,k,l") * T1("c,i")
3761  )
3762  ;
3763 
3764  Dai("a,i") = // lambda^i_a
3765  L1("a,i");
3766  }
3767 
3768  // compute CCSD Xam (the right-hand side of Z-vector equations)
3769  // following formula from JCP, 103, 3561 (1995)
3770  template <typename T>
3771  void SingleReference_R12Intermediates<T>::compute_Xam_ccsd(const TArray2& T1, const TArray4& T2,
3772  const TArray2& L1, const TArray4& L2,
3773  TArray2& Xam_tot, TArray2& Xiip) {
3774 
3775  TArray4 tau_ab;
3776  tau_ab("a,b,i,j") = T2("a,b,i,j") + (T1("a,i") * T1("b,j"));
3777 
3778  // compute \Gamma(pq,rs) intermediates
3779 
3780  TArray4 Gamma_IjAb_ab;
3781  compute_Gamma_ijab_ccsd(T1, T2, tau_ab, L1, L2,
3782  Gamma_IjAb_ab);
3783 
3784  TArray4 Gamma_AbIj_ab;
3785  Gamma_AbIj_ab("a,b,i,j") = // 1/4 lambda^ij_ab
3786  0.25 * L2("a,b,i,j");
3787 // TArray4 Gamma_ABIJ_aa;
3788 // Gamma_ABIJ_aa("a,b,i,j") = // 1/4 lambda^ij_ab
3789 // 0.25 * (L2("a,b,i,j") - L2("b,a,i,j"));
3790 // TArray4 Gamma_aa_1, diff_1;
3791 // Gamma_aa_1("a,b,i,j") = Gamma_AbIj_ab("a,b,i,j") - Gamma_AbIj_ab("a,b,j,i");
3792 // diff_1("a,b,i,j") = Gamma_ABIJ_aa("a,b,i,j") - Gamma_aa_1("a,b,i,j");
3793 // std::cout << std::endl << "Diff 1: " << std::endl
3794 // << "norm = " << static_cast<double>(diff_1("a,b,i,j").norm())
3795 // << " max = " << static_cast<double>(diff_1("a,b,i,j").max())
3796 // << " min = " << static_cast<double>(diff_1("a,b,i,j").min()) << std::endl;
3797 
3798  TArray4 Gamma_AbCd_ab;
3799  Gamma_AbCd_ab("a,b,c,d") = // 1/8 lambda^kl_ab tau^cd_kl (CCSD modified term)
3800  0.25 * L2("a,b,k,l") * tau_ab("c,d,k,l");
3801 
3802  TArray4 Gamma_IjKl_ab;
3803  Gamma_IjKl_ab("i,j,k,l") = // 1/8 tau^cd_ij lambda^kl_cd
3804  0.25 * tau_ab("c,d,i,j") * L2("c,d,k,l");
3805 // TArray4 Gamma_IJKL_aa;
3806 // Gamma_IJKL_aa("i,j,k,l") = // 1/8 tau^cd_ij lambda^kl_cd
3807 // 0.125 * tau_aa("c,d,i,j") * (L2("c,d,k,l") - L2("c,d,l,k"));
3808 // TArray4 Gamma_aa_1, diff_1, Gamma_aa_2, diff_2;
3809 // Gamma_aa_1("i,j,k,l") = Gamma_IjKl_ab("i,j,k,l") - Gamma_IjKl_ab("j,i,k,l");
3810 // diff_1("i,j,k,l") = Gamma_IJKL_aa("i,j,k,l") - Gamma_aa_1("i,j,k,l");
3811 // std::cout << std::endl << "Diff 1: " << std::endl
3812 // << "norm = " << static_cast<double>(diff_1("i,j,k,l").norm())
3813 // << " max = " << static_cast<double>(diff_1("i,j,k,l").max())
3814 // << " min = " << static_cast<double>(diff_1("i,j,k,l").min()) << std::endl;
3815 //
3816 // Gamma_aa_2("i,j,k,l") = Gamma_IjKl_ab("i,j,k,l") - Gamma_IjKl_ab("i,j,l,k");
3817 // diff_2("i,j,k,l") = Gamma_IJKL_aa("i,j,k,l") - Gamma_aa_2("i,j,k,l");
3818 // std::cout << std::endl << "Diff 2: " << std::endl
3819 // << "norm = " << static_cast<double>(diff_2("i,j,k,l").norm())
3820 // << " max = " << static_cast<double>(diff_2("i,j,k,l").max())
3821 // << " min = " << static_cast<double>(diff_2("i,j,k,l").min()) << std::endl;
3822 
3823  TArray4 Gamma_IjKa_ab;
3824  Gamma_IjKa_ab("i,j,k,a") = // - 1/4 tau^ca_ij lambda^k_c
3825  - 0.25 * tau_ab("c,a,i,j") * L1("c,k")
3826 
3827  // + 1/8 tau^cd_ij lambda^kl_cd t^a_l
3828  + 0.25 * tau_ab("c,d,i,j") * L2("c,d,k,l") * T1("a,l")
3829 
3830  // + 1/4 P-(ij) t^ac_il lambda^lk_cd t^d_j
3831  + 0.25 * T2("a,c,l,i") * L2("c,d,k,l") * T1("d,j")
3832  //
3833  - 0.25 * ( (T2("a,c,j,l") - T2("a,c,l,j")) * L2("c,d,l,k")
3834  + T2("a,c,j,l") * (L2("c,d,l,k") - L2("c,d,k,l"))
3835  ) * T1("d,i")
3836 
3837  // - 1/8 P-(ij) t^cd_il lambda^kl_cd t^a_j
3838  - 0.125 * ( (T2("c,d,i,l") - T2("c,d,l,i")) * (L2("c,d,k,l") - L2("c,d,l,k"))
3839  + 2.0 * T2("c,d,i,l") * L2("c,d,k,l")
3840  ) * T1("a,j")
3841  ;
3842 
3843  TArray4 Gamma_AKIJ_aa, Gamma_AkIj_ab;
3844  Gamma_AkIj_ab("a,k,i,j") = // -1/4 t^c_k lambda^Ij_Ac
3845  - 0.25 * T1("c,k") * L2("a,c,i,j");
3846 
3847  TArray4 Gamma_CiAb_ab;
3848  Gamma_CiAb_ab("c,i,a,b") = // 1/4 tau^ab_ki lambda^k_c
3849  0.25 * tau_ab("a,b,k,i") * L1("c,k")
3850 
3851  // - 1/8 t^d_i lambda^kl_cd tau^ab_kl
3852  - 0.25 * T1("d,i") * L2("c,d,k,l") * tau_ab("a,b,k,l")
3853 
3854  // - 1/4 P-(ab) t^ad_il lambda^kl_cd t^b_k
3855  - 0.25 * T2("a,d,l,i") * L2("c,d,l,k") * T1("b,k")
3856  //
3857  + 0.25 * ( (T2("b,d,i,l") - T2("b,d,l,i")) * L2("c,d,k,l")
3858  + T2("b,d,i,l") * (L2("c,d,k,l") - L2("c,d,l,k"))
3859  ) * T1("a,k")
3860 
3861  // + 1/8 P-(ab) t^b_i t^ad_kl lambda^kl_cd
3862  + 0.125 * T1("b,i") * (T2("a,d,k,l") - T2("d,a,k,l"))
3863  * (L2("c,d,k,l") - L2("c,d,l,k"))
3864  + 0.25 * T1("b,i") * T2("a,d,k,l") * L2("c,d,k,l")
3865  ;
3866 
3867  TArray4 Gamma_AbCi_ab;
3868  Gamma_AbCi_ab("a,b,c,i") = // 1/4 lambda^ki_ab t^c_k
3869  0.25 * L2("a,b,k,i") * T1("c,k");
3870 
3871  TArray4 Gamma_aJiB_ab, Gamma_AjiB_ba;
3872  Gamma_aJiB_ab("a,j,i,b") = // 1/4 lambda^ik_ac t^c_j t^cb_kj
3873  0.25 * (L2("a,c,i,k") - L2("c,a,i,k")) * T2("c,b,k,j")
3874  + 0.25 * L2("a,c,i,k") * (T2("c,b,k,j") - T2("b,c,k,j"))
3875 
3876  // - 1/4 lambda^ik_ac t^c_j t^b_k
3877  - 0.25 * L2("a,c,i,k") * T1("c,j") * T1("b,k")
3878  // + 1/4 lambda^i_a t^b_j
3879  + 0.25 * L1("a,i") * T1("b,j")
3880  ;
3881 
3882  Gamma_AjiB_ba("a,j,i,b") = // 1/4 lambda^ik_ac t^c_j t^cb_kj
3883  0.25 * L2("c,a,i,k") * T2("b,c,k,j")
3884 
3885  // - 1/4 lambda^ik_ac t^c_j t^b_k
3886  + 0.25 * L2("a,c,k,i") * T1("c,j") * T1("b,k")
3887  // + 1/4 lambda^i_a t^b_j
3888  ;
3889 
3890  // compute CCSD density from amplitudes
3891  TArray2 Dij, Dab, Dia, Dai;
3892  compute_ccsd_1rdm_amp(T1, T2, L1, L2, Dij, Dab, Dia, Dai);
3893 
3894  TArray4d g_ijma = ijxy("<i j|g|m a>");
3895  TArray4d g_mabc = ijxy("<m a|g|b c>");
3896  TArray4d g_mabi = ijxy("<m a|g|b i>");
3897  TArray4d g_maib = ijxy("<m a|g|i b>");
3898 
3899  TArray4d g_imkl = ijxy("<i m|g|k l>");
3900  TArray4d g_miab = ijxy("<m i|g|a b>");
3901  TArray4d g_imbj = ijxy("<i m|g|b j>");
3902  TArray4d g_imjb = ijxy("<i m|g|j b>");
3903 
3904  TArray4d g_ijak = ijxy("<i j|g|a k>");
3905  TArray4d g_abci = ijxy("<a b|g|c i>");
3906  TArray4d g_aibj = ijxy("<a i|g|b j>");
3907  TArray4d g_iabj = ijxy("<i a|g|b j>");
3908 
3909  TArray4d g_ijab = ijxy("<i j|g|a b>");
3910  TArray4d g_abcd = ijxy("<a b|g|c d>");
3911 
3912  TArray2 Xam, Xai;
3913  Xam("a,m") = (Dai("a,j") + Dia("j,a")) * _2("<j|F|m>")
3914  + (Dab("a,c") + Dab("c,a")) * _2("<c|F|m>")
3915 
3916  - (2.0 * g_mabc("m,c,a,d") - g_mabc("m,c,d,a"))
3917  * (Dab("c,d") + Dab("d,c"))
3918  - (2.0 * g_imjb("l,m,k,a") - g_imbj("l,m,a,k"))
3919  * (Dij("k,l") + Dij("l,k"))
3920  - ( 2.0 * g_miab("m,j,a,b") - g_miab("m,j,b,a")
3921  + 2.0 * g_mabi("m,b,a,j") - g_maib("m,b,j,a")
3922  ) * (Dia("j,b") + Dai("b,j"))
3923 
3924  + 4.0 * (
3925  //
3926  // (Gamma(kl,ab) + Gamma(ab,kl)) g^kl_mb
3927  (Gamma_IjAb_ab("k,l,a,b") + Gamma_AbIj_ab("a,b,k,l"))
3928  * (g_ijma("k,l,m,b") * 2.0 - g_ijma("l,k,m,b"))
3929 
3930  // (Gamma(cd,ab) + Gamma(ab, cd)) g^cd_mb
3931  + (Gamma_AbCd_ab("c,d,a,b") + Gamma_AbCd_ab("a,b,c,d"))
3932  * (g_mabc("m,b,c,d") * 2.0 - g_mabc("m,b,d,c"))
3933 
3934  // 2 (Gamma(ck,ab) - Gamma(ba,ck)) g^ck_mb
3935  + ( Gamma_CiAb_ab("c,k,a,b") - Gamma_CiAb_ab("c,k,b,a")
3936  - Gamma_AbCi_ab("b,a,c,k") + Gamma_AbCi_ab("a,b,c,k"))
3937  * (g_mabi("m,b,c,k") - g_maib("m,b,k,c"))
3938  + (Gamma_CiAb_ab("c,k,a,b") + Gamma_AbCi_ab("a,b,c,k"))
3939  * g_mabi("m,b,c,k")
3940  - (- Gamma_CiAb_ab("c,k,b,a") - Gamma_AbCi_ab("b,a,c,k"))
3941  * g_maib("m,b,k,c")
3942 
3943  //
3944  // (Gamma(lk, ja) + Gamma(aj, kl)) g^kl_mj
3945  + (Gamma_IjKa_ab("l,k,j,a") + Gamma_AkIj_ab("a,j,k,l"))
3946  * (g_imkl("j,m,l,k") * 2.0 - g_imkl("j,m,k,l"))
3947 
3948  // (Gamma(cd, aj) + Gamma(aj, cd) g^mj_cd) g^cd_mj
3949  + (Gamma_AbCi_ab("c,d,a,j") + Gamma_CiAb_ab("a,j,c,d"))
3950  * (g_miab("m,j,c,d") * 2.0 - g_miab("m,j,d,c"))
3951 
3952  // * (Gamma(ck, ja) + Gamma(aj,kc)) g^kc_mj
3953  + ( Gamma_aJiB_ab("c,k,j,a") + Gamma_AjiB_ba("c,k,j,a")
3954  + Gamma_aJiB_ab("a,j,k,c") + Gamma_AjiB_ba("a,j,k,c"))
3955  * (g_imbj("j,m,c,k") - g_imjb("j,m,k,c"))
3956  + (Gamma_aJiB_ab("c,k,j,a") + Gamma_aJiB_ab("a,j,k,c"))
3957  * g_imbj("j,m,c,k")
3958  - (Gamma_AjiB_ba("c,k,j,a") + Gamma_AjiB_ba("a,j,k,c"))
3959  * g_imjb("j,m,k,c")
3960  )
3961  ;
3962 
3963  Xai("a,i") = - _2("<a|F|b>") * (Dai("b,i") + Dia("i,b"))
3964  - _2("<a|F|l>") * (Dij("l,i") + Dij("i,l"))
3965 
3966  - 4.0 * (
3967  //
3968  // (Gamma(kl,ij) + Gamma(ij, kl)) g^kl_aj
3969  (Gamma_IjKl_ab("k,l,i,j") + Gamma_IjKl_ab("i,j,k,l"))
3970  * (g_ijak("k,l,a,j") * 2.0 - g_ijak("l,k,a,j"))
3971 
3972  // (Gamma(cd,ij) + Gamma(ij, cd)) g^cd_aj
3973  + (Gamma_AbIj_ab("c,d,i,j") + Gamma_IjAb_ab("i,j,c,d"))
3974  * (g_abci("c,d,a,j") * 2.0 - g_abci("d,c,a,j"))
3975 
3976  // (- Gamma(ck,ij) + Gamma(ij,kc)) g^kc_aj
3977  + (- (Gamma_AkIj_ab("c,k,i,j") - Gamma_AkIj_ab("c,k,j,i"))
3978  + Gamma_IjKa_ab("i,j,k,c") - Gamma_IjKa_ab("j,i,k,c"))
3979  * (g_iabj("j,a,c,k") - g_aibj("a,j,c,k"))
3980  // - Gamma_aKIj_ba("c,k,i,j") = Gamma_AkIj_ab("c,k,j,i")
3981  + ( Gamma_AkIj_ab("c,k,j,i") + Gamma_IjKa_ab("i,j,k,c"))
3982  * g_iabj("j,a,c,k")
3983  - ( - Gamma_AkIj_ab("c,k,i,j") - Gamma_IjKa_ab("j,i,k,c"))
3984  * g_aibj("a,j,c,k")
3985 
3986  //
3987  // (Gamma(kl,ib) - Gamma(bi,kl)) g^kl_ab
3988  + (Gamma_IjKa_ab("k,l,i,b") + Gamma_AkIj_ab("b,i,l,k"))
3989  * (g_ijab("k,l,a,b") * 2.0 - g_ijab("l,k,a,b"))
3990 
3991  // (- Gamma(cd,bi) + Gamma(bi,dc)) g^cd_ab
3992  + (Gamma_AbCi_ab("d,c,b,i") + Gamma_CiAb_ab("b,i,d,c"))
3993  * (g_abcd("c,d,a,b") * 2.0 - g_abcd("d,c,a,b"))
3994 
3995  // (Gamma(ck,ib) + Gamma(bi,kc)) g^ck_ab
3996  + ( Gamma_aJiB_ab("c,k,i,b") + Gamma_AjiB_ba("c,k,i,b")
3997  + Gamma_aJiB_ab("b,i,k,c") + Gamma_AjiB_ba("b,i,k,c"))
3998  * (g_abci("a,b,c,k") - g_abci("b,a,c,k"))
3999  + (Gamma_aJiB_ab("c,k,i,b") + Gamma_aJiB_ab("b,i,k,c"))
4000  * g_abci("a,b,c,k")
4001  - (Gamma_AjiB_ba("c,k,i,b") + Gamma_AjiB_ba("b,i,k,c"))
4002  * g_abci("b,a,c,k")
4003 
4004  )
4005  ;
4006  Xam_tot = XaiAddToXam(Xam, Xai);
4007 
4008  // *** test code: print out Iam & Ima ***
4009 // TArray4d g_iabc = ijxy("<i a|g|b c>");
4010 // TArray4d g_ikbj = ijxy("<i k|g|b j>");
4011 // TArray4d g_ikjb = ijxy("<i k|g|j b>");
4012 // TArray4d g_kabi = ijxy("<k a|g|b i>");
4013 // TArray4d g_kaib = ijxy("<k a|g|i b>");
4014 // TArray4d g_ijkl = ijxy("<i j|g|k l>");
4015 //
4016 // TArray2 Iam;
4017 // Iam("a,m") = 2.0 * (
4018 // //
4019 // // (Gamma(kl,ab) + Gamma(ab,kl)) g^kl_mb
4020 // (Gamma_IjAb_ab("k,l,a,b") + Gamma_AbIj_ab("a,b,k,l"))
4021 // * (g_ijma("k,l,m,b") * 2.0 - g_ijma("l,k,m,b"))
4022 //
4023 // // (Gamma(cd,ab) + Gamma(ab, cd)) g^cd_mb
4024 // + (Gamma_AbCd_ab("c,d,a,b") + Gamma_AbCd_ab("a,b,c,d"))
4025 // * (g_mabc("m,b,c,d") * 2.0 - g_mabc("m,b,d,c"))
4026 //
4027 // // 2 (Gamma(ck,ab) - Gamma(ba,ck)) g^ck_mb
4028 // + ( Gamma_CiAb_ab("c,k,a,b") - Gamma_CiAb_ab("c,k,b,a")
4029 // - Gamma_AbCi_ab("b,a,c,k") + Gamma_AbCi_ab("a,b,c,k"))
4030 // * (g_mabi("m,b,c,k") - g_maib("m,b,k,c"))
4031 // + (Gamma_CiAb_ab("c,k,a,b") + Gamma_AbCi_ab("a,b,c,k"))
4032 // * g_mabi("m,b,c,k")
4033 // - (- Gamma_CiAb_ab("c,k,b,a") - Gamma_AbCi_ab("b,a,c,k"))
4034 // * g_maib("m,b,k,c")
4035 //
4036 // //
4037 // // (Gamma(lk, ja) + Gamma(aj, kl)) g^kl_mj
4038 // + (Gamma_IjKa_ab("l,k,j,a") + Gamma_AkIj_ab("a,j,k,l"))
4039 // * (g_imkl("j,m,l,k") * 2.0 - g_imkl("j,m,k,l"))
4040 //
4041 // // (Gamma(cd, aj) + Gamma(aj, cd) g^mj_cd) g^cd_mj
4042 // + (Gamma_AbCi_ab("c,d,a,j") + Gamma_CiAb_ab("a,j,c,d"))
4043 // * (g_miab("m,j,c,d") * 2.0 - g_miab("m,j,d,c"))
4044 //
4045 // // * (Gamma(ck, ja) + Gamma(aj,kc)) g^kc_mj
4046 // + ( Gamma_aJiB_ab("c,k,j,a") + Gamma_AjiB_ba("c,k,j,a")
4047 // + Gamma_aJiB_ab("a,j,k,c") + Gamma_AjiB_ba("a,j,k,c"))
4048 // * (g_imbj("j,m,c,k") - g_imjb("j,m,k,c"))
4049 // + (Gamma_aJiB_ab("c,k,j,a") + Gamma_aJiB_ab("a,j,k,c"))
4050 // * g_imbj("j,m,c,k")
4051 // - (Gamma_AjiB_ba("c,k,j,a") + Gamma_AjiB_ba("a,j,k,c"))
4052 // * g_imjb("j,m,k,c")
4053 // )
4054 // ;
4055 //
4056 // TArray2 Ima, Iia;
4057 // Ima("a,m") = - (2.0 * g_mabc("m,c,a,d") - g_mabc("m,c,d,a"))
4058 // * (Dab("c,d") + Dab("d,c")) * 0.5
4059 // - (2.0 * g_imjb("l,m,k,a") - g_imbj("l,m,a,k"))
4060 // * (Dij("k,l") + Dij("l,k")) * 0.5
4061 // ;
4062 // Iia("a,i") = - 2.0 * (
4063 // //
4064 // // (Gamma(kl,ij) + Gamma(ij, kl)) g^kl_aj
4065 // (Gamma_IjKl_ab("k,l,i,j") + Gamma_IjKl_ab("i,j,k,l"))
4066 // * (g_ijak("k,l,a,j") * 2.0 - g_ijak("l,k,a,j"))
4067 //
4068 // // (Gamma(cd,ij) + Gamma(ij, cd)) g^cd_aj
4069 // + (Gamma_AbIj_ab("c,d,i,j") + Gamma_IjAb_ab("i,j,c,d"))
4070 // * (g_abci("c,d,a,j") * 2.0 - g_abci("d,c,a,j"))
4071 //
4072 // // (- Gamma(ck,ij) + Gamma(ij,kc)) g^kc_aj
4073 // + (- (Gamma_AkIj_ab("c,k,i,j") - Gamma_AkIj_ab("c,k,j,i"))
4074 // + Gamma_IjKa_ab("i,j,k,c") - Gamma_IjKa_ab("j,i,k,c"))
4075 // * (g_iabj("j,a,c,k") - g_aibj("a,j,c,k"))
4076 // // - Gamma_aKIj_ba("c,k,i,j") = Gamma_AkIj_ab("c,k,j,i")
4077 // + ( Gamma_AkIj_ab("c,k,j,i") + Gamma_IjKa_ab("i,j,k,c"))
4078 // * g_iabj("j,a,c,k")
4079 // - ( - Gamma_AkIj_ab("c,k,i,j") - Gamma_IjKa_ab("j,i,k,c"))
4080 // * g_aibj("a,j,c,k")
4081 //
4082 // //
4083 // // (Gamma(kl,ib) - Gamma(bi,kl)) g^kl_ab
4084 // + (Gamma_IjKa_ab("k,l,i,b") + Gamma_AkIj_ab("b,i,l,k"))
4085 // * (g_ijab("k,l,a,b") * 2.0 - g_ijab("l,k,a,b"))
4086 //
4087 // // (- Gamma(cd,bi) + Gamma(bi,dc)) g^cd_ab
4088 // + (Gamma_AbCi_ab("d,c,b,i") + Gamma_CiAb_ab("b,i,d,c"))
4089 // * (g_abcd("c,d,a,b") * 2.0 - g_abcd("d,c,a,b"))
4090 //
4091 // // (Gamma(ck,ib) + Gamma(bi,kc)) g^ck_ab
4092 // + ( Gamma_aJiB_ab("c,k,i,b") + Gamma_AjiB_ba("c,k,i,b")
4093 // + Gamma_aJiB_ab("b,i,k,c") + Gamma_AjiB_ba("b,i,k,c"))
4094 // * (g_abci("a,b,c,k") - g_abci("b,a,c,k"))
4095 // + (Gamma_aJiB_ab("c,k,i,b") + Gamma_aJiB_ab("b,i,k,c"))
4096 // * g_abci("a,b,c,k")
4097 // - (Gamma_AjiB_ba("c,k,i,b") + Gamma_AjiB_ba("b,i,k,c"))
4098 // * g_abci("b,a,c,k")
4099 //
4100 // )
4101 // ;
4102 // TArray2 I_ima = XaiAddToXam(Ima, Iia);
4103 //
4104 // std::cout << "Ii/m a : " << std::endl << I_ima << std::endl;
4105 // std::cout << "Iam : " << std::endl << Iam << std::endl;
4106 
4107  // frozen-core contribution
4108  const std::size_t nocc = Xam.trange().elements_range().extent()[1];
4109  const std::size_t naocc = Xai.trange().elements_range().extent()[1];
4110  if (nocc != naocc) {
4111  TArray4d g_ijipk = ijxy("<i j|g|i' k>");
4112  TArray4d g_abipi = ijxy("<a b|g|i' i>");
4113  TArray4d g_ipibj = ijxy("<i' i|g|b j>");
4114  TArray4d g_iipbj = ijxy("<i i'|g|b j>");
4115  TArray4d g_ijipb = ijxy("<i j|g|i' b>");
4116  TArray4d g_abipd = ijxy("<a b|g|i' d>");
4117  TArray4d g_aipbi = ijxy("<a i'|g|b i>");
4118 
4119  Xiip("i,i'") = - 4.0 * (
4120  //
4121  // (Gamma(kl,ij) + Gamma(ij, kl)) g^kl_i'j
4122  (Gamma_IjKl_ab("k,l,i,j") + Gamma_IjKl_ab("i,j,k,l"))
4123  * (g_ijipk("k,l,i',j") * 2.0 - g_ijipk("l,k,i',j"))
4124 
4125  // (Gamma(cd,ij) + Gamma(ij, cd)) g^cd_i'j
4126  + (Gamma_AbIj_ab("c,d,i,j") + Gamma_IjAb_ab("i,j,c,d"))
4127  * (g_abipi("c,d,i',j") * 2.0 - g_abipi("d,c,i',j"))
4128 
4129  // (- Gamma(ck,ij) + Gamma(ij,kc)) g^kc_i'j
4130  + (- (Gamma_AkIj_ab("c,k,i,j") - Gamma_AkIj_ab("c,k,j,i"))
4131  + Gamma_IjKa_ab("i,j,k,c") - Gamma_IjKa_ab("j,i,k,c"))
4132  * (g_iipbj("j,i',c,k") - g_ipibj("i',j,c,k"))
4133  + ( Gamma_AkIj_ab("c,k,j,i") + Gamma_IjKa_ab("i,j,k,c"))
4134  * g_iipbj("j,i',c,k")
4135  - ( - Gamma_AkIj_ab("c,k,i,j") - Gamma_IjKa_ab("j,i,k,c"))
4136  * g_ipibj("i',j,c,k")
4137 
4138  //
4139  // (Gamma(kl,ib) - Gamma(bi,kl)) g^kl_i'b
4140  + (Gamma_IjKa_ab("k,l,i,b") + Gamma_AkIj_ab("b,i,l,k"))
4141  * (g_ijipb("k,l,i',b") * 2.0 - g_ijipb("l,k,i',b"))
4142 
4143  // (- Gamma(cd,bi) + Gamma(bi,dc)) g^cd_i'b
4144  + (Gamma_AbCi_ab("d,c,b,i") + Gamma_CiAb_ab("b,i,d,c"))
4145  * (g_abipd("c,d,i',b") * 2.0 - g_abipd("d,c,i',b"))
4146 
4147  // (Gamma(ck,ib) + Gamma(bi,kc)) g^ck_i'b
4148  + ( Gamma_aJiB_ab("c,k,i,b") + Gamma_AjiB_ba("c,k,i,b")
4149  + Gamma_aJiB_ab("b,i,k,c") + Gamma_AjiB_ba("b,i,k,c"))
4150  * (g_abipi("c,b,i',k") - g_aipbi("b,i',c,k"))
4151  + (Gamma_aJiB_ab("c,k,i,b") + Gamma_aJiB_ab("b,i,k,c"))
4152  * g_abipi("c,b,i',k")
4153  - (Gamma_AjiB_ba("c,k,i,b") + Gamma_AjiB_ba("b,i,k,c"))
4154  * g_aipbi("b,i',c,k")
4155  )
4156  ;
4157 
4158  }
4159 
4160  }
4161 
4162  template <typename T>
4164 
4165  ExEnv::out0() << std::endl << indent
4166  << "Compute dipole and quadrupole moments" << std::endl;
4167 
4168  bool compute_dipole = true;
4169  bool compute_quadrupole = true;
4170  bool compute_EFG = false;
4171 
4172  #define INCLUDE_CABS_Singles_CONTRI 1
4173  #define INCLUDE_MP2_CONTRI 1
4174  #define INCLUDE_MP2F12C_CONTRI 1
4175  #define INCLUDE_F12_CONTRI 1
4176 
4177  #define INCLUDE_CCSD_CONTRI 1
4178  #define INCLUDE_CCSDF12C_CONTRI 1
4179 
4180  double conv_target = 1e-10;
4181 
4182  // Obtain property integrals which is needed in multiple places
4183 
4184  // dipole integrals
4185  TArray2 mu_z_mn, mu_z_am;
4186  if (compute_dipole) {
4187  mu_z_mn = xy("<m|mu_z|n>");
4188  mu_z_am = xy("<a|mu_z|m>");
4189  }
4190 
4191  // quadrupole integrals
4192  TArray2 q_xx_mn, q_yy_mn, q_zz_mn;
4193  TArray2 Qxx_mn, Qyy_mn, Qzz_mn, Qxz_mn, Qxy_mn, Qyz_mn;
4194  TArray2 q_xx_am, q_yy_am, q_zz_am;
4195  TArray2 Qxx_am, Qyy_am, Qzz_am, Qxy_am, Qxz_am, Qyz_am;
4196  if (compute_quadrupole) {
4197  q_xx_mn = xy("<m|q_xx|n>");
4198  q_yy_mn = xy("<m|q_yy|n>");
4199  q_zz_mn = xy("<m|q_zz|n>");
4200  Qxx_mn("m,n") = q_xx_mn("m,n") - (q_zz_mn("m,n") + q_yy_mn("m,n")) * 0.5;
4201  Qyy_mn("m,n") = q_yy_mn("m,n") - (q_zz_mn("m,n") + q_xx_mn("m,n")) * 0.5;
4202  Qzz_mn("m,n") = q_zz_mn("m,n") - (q_xx_mn("m,n") + q_yy_mn("m,n")) * 0.5;
4203  Qxz_mn("m,n") = _2("<m|q_xz|n>") * 1.5;
4204  Qxy_mn("m,n") = _2("<m|q_xy|n>") * 1.5;
4205  Qyz_mn("m,n") = _2("<m|q_yz|n>") * 1.5;
4206 
4207  q_xx_am = xy("<a|q_xx|m>");
4208  q_yy_am = xy("<a|q_yy|m>");
4209  q_zz_am = xy("<a|q_zz|m>");
4210  Qxx_am("a,m") = q_xx_am("a,m") - (q_zz_am("a,m") + q_yy_am("a,m")) * 0.5;
4211  Qyy_am("a,m") = q_yy_am("a,m") - (q_zz_am("a,m") + q_xx_am("a,m")) * 0.5;
4212  Qzz_am("a,m") = q_zz_am("a,m") - (q_xx_am("a,m") + q_yy_am("a,m")) * 0.5;
4213  Qxy_am("a,m") = _2("<a|q_xy|m>") * 1.5;
4214  Qxz_am("a,m") = _2("<a|q_xz|m>") * 1.5;
4215  Qyz_am("a,m") = _2("<a|q_yz|m>") * 1.5;
4216  }
4217 
4218  // electric field gradient integrals
4219  TArray2 v_xx_mn, v_yy_mn, v_zz_mn, v_xy_mn, v_xz_mn, v_yz_mn;
4220  TArray2 v_xx_am, v_yy_am, v_zz_am, v_xy_am, v_xz_am, v_yz_am;
4221  if (compute_EFG) {
4222  v_xx_mn = xy("<m|ddphi_xx|n>");
4223  v_yy_mn = xy("<m|ddphi_yy|n>");
4224  v_zz_mn = xy("<m|ddphi_zz|n>");
4225  v_xy_mn = xy("<m|ddphi_xy|n>");
4226  v_xz_mn = xy("<m|ddphi_xz|n>");
4227  v_yz_mn = xy("<m|ddphi_yz|n>");
4228 
4229  v_xx_am = xy("<a|ddphi_xx|m>");
4230  v_yy_am = xy("<a|ddphi_yy|m>");
4231  v_zz_am = xy("<a|ddphi_zz|m>");
4232  v_xy_am = xy("<a|ddphi_xy|m>");
4233  v_xz_am = xy("<a|ddphi_xz|m>");
4234  v_yz_am = xy("<a|ddphi_yz|m>");
4235  }
4236 
4237  // compute HF contribution
4238  Ref<Molecule> mol = r12world_->basis()->molecule();
4239  const int natom = mol->natom();
4240 
4241  TArray2 Imn = xy("<m|I|n>");
4242 
4243  // HF eletric dipole
4244  double mu_z_n = 0.0, mu_z_scf = 0.0;
4245  if (compute_dipole) {
4246  // Nuclear contribution to dipole
4247  for(int a = 0; a < natom; ++a) {
4248  const double x = mol->r(a, 0);
4249  const double y = mol->r(a, 1);
4250  const double z = mol->r(a, 2);
4251  const double Z = mol->Z(a);
4252  mu_z_n += Z * z;
4253  }
4254 
4255  // SCF contribution to electronic electric dipole
4256  mu_z_scf = dot(mu_z_mn("m,n"), Imn("m,n"));
4257  }
4258 
4259  // HF eletric quadrupole
4260  double q_xx_n = 0.0, q_yy_n = 0.0, q_zz_n = 0.0;
4261  double q_xy_n = 0.0, q_xz_n = 0.0, q_yz_n = 0.0;
4262  double q_xx_scf = 0.0, q_yy_scf = 0.0, q_zz_scf = 0.0,
4263  q_xy_scf = 0.0, q_xz_scf = 0.0, q_yz_scf = 0.0;
4264  if (compute_quadrupole) {
4265  // Nuclear electric quadrupole (traceless)
4266  for(int a = 0; a < natom; ++a) {
4267  const double x = mol->r(a, 0);
4268  const double y = mol->r(a, 1);
4269  const double z = mol->r(a, 2);
4270  const double Z = mol->Z(a);
4271 
4272  q_xx_n += Z * (x * x - (z * z + y * y) * 0.5); // traceless form of the quadrupole
4273  q_yy_n += Z * (y * y - (z * z + x * x) * 0.5); // traceless form of the quadrupole
4274  q_zz_n += Z * (z * z - (x * x + y * y) * 0.5); // traceless form of the quadrupole
4275  q_xy_n += Z * (x * y * 1.5); // traceless form of the quadrupole
4276  q_xz_n += Z * (x * z * 1.5); // traceless form of the quadrupole
4277  q_yz_n += Z * (y * z * 1.5); // traceless form of the quadrupole
4278  }
4279 
4280  // SCF contribution to electronic electric quadrupoles
4281  q_xx_scf = dot(Qxx_mn("m,n"), Imn("m,n"));
4282  q_yy_scf = dot(Qyy_mn("m,n"), Imn("m,n"));
4283  q_zz_scf = dot(Qzz_mn("m,n"), Imn("m,n"));
4284  q_xy_scf = dot(Qxy_mn("m,n"), Imn("m,n"));
4285  q_xz_scf = dot(Qxz_mn("m,n"), Imn("m,n"));
4286  q_yz_scf = dot(Qyz_mn("m,n"), Imn("m,n"));
4287  }
4288 
4289  // HF electric field gradient near the 1st nucleus
4290  if (compute_EFG) {
4291  // Nuclear contribution to electric field gradient near the 1st nucleus
4292  double v_xx_n = 0.0, v_yy_n = 0.0, v_zz_n = 0.0;
4293  double v_xy_n = 0.0, v_xz_n = 0.0, v_yz_n = 0.0;
4294  for(int i = 1; i < natom; i++) {
4295  const double x = mol->r(0, 0) - mol->r(i, 0);
4296  const double y = mol->r(0, 1) - mol->r(i, 1);
4297  const double z = mol->r(0, 2) - mol->r(i, 2);
4298  const double r2 = x * x + y * y + z * z;
4299  const double r = pow(r2, 0.5);
4300  const double Z = mol->Z(i);
4301 
4302  v_xx_n += - Z * (3.0 * x * x - r2) / (r * r2 * r2);
4303  v_yy_n += - Z * (3.0 * y * y - r2) / (r * r2 * r2);
4304  v_zz_n += - Z * (3.0 * z * z - r2) / (r * r2 * r2);
4305 
4306  v_xy_n += - Z * (3.0 * x * y) / (r * r2 * r2);
4307  v_xz_n += - Z * (3.0 * x * z) / (r * r2 * r2);
4308  v_yz_n += - Z * (3.0 * y * z) / (r * r2 * r2);
4309  }
4310 
4311  // Electric field gradient near the 1st nucleus
4312  const double v_xx_scf = dot(v_xx_mn("m,n"), Imn("m,n"));
4313  const double v_yy_scf = dot(v_yy_mn("m,n"), Imn("m,n"));
4314  const double v_zz_scf = dot(v_zz_mn("m,n"), Imn("m,n"));
4315  const double v_xy_scf = dot(v_xy_mn("m,n"), Imn("m,n"));
4316  const double v_xz_scf = dot(v_xz_mn("m,n"), Imn("m,n"));
4317  const double v_yz_scf = dot(v_yz_mn("m,n"), Imn("m,n"));
4318 
4319  std::cout << std::endl << indent
4320  << "electric gradient (HF=SCF+N)" << std::endl
4321  << indent << "v_xx (HF) = " << scprintf("%12.10f", v_xx_n + v_xx_scf * 2.0)
4322  << indent << " v_yy (HF) = " << scprintf("%12.10f", v_yy_n + v_yy_scf * 2.0)
4323  << indent << " v_zz (HF) = " << scprintf("%12.10f", v_zz_n + v_zz_scf * 2.0)
4324  << std::endl
4325  << indent << "v_xy (HF) = " << scprintf("%12.10f", v_xy_n + v_xy_scf * 2.0)
4326  << indent << " v_xz (HF) = " << scprintf("%12.10f", v_xz_n + v_xz_scf * 2.0)
4327  << indent << " v_yz (HF) = " << scprintf("%12.10f", v_yz_n + v_yz_scf * 2.0)
4328  << std::endl;
4329  }
4330 
4331  // compute integrals needed for orbital relaxation
4332  // i.e. solve Abnam Dbn = Xam (close-shell formula)
4333  TArray4d g_mnab = ijxy("<m n|g|a b>");
4334  TArray4 A_bnam;
4335  A_bnam("b,n,a,m") = - _4("<b n|g|a m>") - g_mnab("m,n,b,a") + 4.0 * g_mnab("n,m,b,a")
4336  + _2("<b|F|a>") * Imn("m,n") - _2("<a|I|b>") * _2("<m|F|n>");
4337 
4338  // Make preconditioner: Delta_am = 1 / (<a|F|a> - <m|F|m>) for
4339  // solving k_bn A_bnam = X_am
4340  TArray2 mFmn, mFab;
4341  mFmn("m,n") = - _2("<m|F|n>");
4342  mFab("a,b") = - _2("<a|F|b>");
4343  typedef detail::diag_precond2<double> pceval_type;
4344  pceval_type Delta_am_gen(TA::array_to_eigen(mFab), TA::array_to_eigen(mFmn));
4345 
4346  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
4347  TArray2 Iam = xy("<a|I|m>");
4348  TArray2d Delta_am(Iam.world(), Iam.trange());
4349 
4350  // construct local tiles
4351  for(auto t = Delta_am.trange().tiles_range().begin();
4352  t != Delta_am.trange().tiles_range().end(); ++t)
4353  if (Delta_am.is_local(*t)) {
4354  std::array<std::size_t, 2> index;
4355  std::copy(t->begin(), t->end(), index.begin());
4356  madness::Future < typename TArray2d::value_type >
4357  tile((LazyTensor<T, 2, pceval_type >(&Delta_am, index, &Delta_am_gen)
4358  ));
4359 
4360  // Insert the tile into the array
4361  Delta_am.set(*t, tile);
4362  }
4363  TArray2 preconditioner;
4364  preconditioner("a,m") = Delta_am("a,m");
4365 
4366  detail::Orbital_relaxation_Abjai<double> Orbital_relaxation_Abnam(A_bnam);
4367  TA::ConjugateGradientSolver<TiledArray::Array<T,2>,
4369 
4370  // compute CABS singles contribution
4371  double mu_z_e2 = 0.0, mu_z_e2or = 0.0;
4372  double q_xx_e2 = 0.0, q_yy_e2 = 0.0, q_zz_e2 = 0.0;
4373  double q_xx_e2or = 0.0, q_yy_e2or = 0.0, q_zz_e2or = 0.0;
4374 #if INCLUDE_CABS_Singles_CONTRI
4375  {
4376  ExEnv::out0() << std::endl << indent
4377  << "Compute CABS_singles contributions" << std::endl;
4378  TArray2 TmA = xy("<m|T1|A'>");
4379  TArray2 Tma = xy("<m|T1|a>");
4380 
4381  // density from CABS Singles contribution
4382  // D^m_n = t^m_A' * t^A'_n
4383  // D^A'_B' = t^A'_m * t^m_B'
4384  // D^A'_m = t^A'_m
4385  ExEnv::out0() << indent
4386  << "Compute CABS_singles D" << std::endl;
4387  TArray2 D_e2_mn, D_e2_AB;
4388  D_e2_mn("m,n") = TmA("m,A'") * TmA("n,A'");
4389  D_e2_AB("A',B'") = TmA("m,A'") * TmA("m,B'");
4390 
4391  // CABS singles orbital response
4392  ExEnv::out0() << indent
4393  << "Compute CABS_singles Xam" << std::endl;
4394  TArray2 Xam_E2 = Xam_CabsSingles(TmA, Tma);
4395  TArray2 Dbn_E2(Xam_E2.world(), Xam_E2.trange());
4396  // solve k_bn A_bnam = X_am
4397  auto resnorm_E2 = cg_solver2(Orbital_relaxation_Abnam,
4398  Xam_E2,
4399  Dbn_E2,
4400  preconditioner,
4401  conv_target);
4402 
4403  // compute CABS singles contribution to dipole
4404  if (compute_dipole) {
4405  TArray2 mu_z_AB = xy("<A'|mu_z|B'>");
4406  TArray2 mu_z_mA = xy("<m|mu_z|A'>");
4407 
4408  mu_z_e2 = - dot(mu_z_mn("m,n"), D_e2_mn("m,n"))
4409  + dot(mu_z_AB("A',B'"), D_e2_AB("A',B'"))
4410  + dot(mu_z_mA("m,A'"), TmA("m,A'")) * 2.0;
4411 
4412  // CABS singles orbital response contribution to dipole
4413  mu_z_e2or = dot(mu_z_am("a,m"), Dbn_E2("a,m"));
4414  }
4415 
4416  // CABS singles contribution to quadrupoles
4417  if (compute_quadrupole) {
4418  TArray2 q_xx_AB = xy("<A'|q_xx|B'>");
4419  TArray2 q_yy_AB = xy("<A'|q_yy|B'>");
4420  TArray2 q_zz_AB = xy("<A'|q_zz|B'>");
4421  TArray2 Qxx_AB, Qyy_AB, Qzz_AB;
4422  Qxx_AB("A',B'") = q_xx_AB("A',B'") - (q_zz_AB("A',B'") + q_yy_AB("A',B'")) * 0.5;
4423  Qyy_AB("A',B'") = q_yy_AB("A',B'") - (q_xx_AB("A',B'") + q_zz_AB("A',B'")) * 0.5;
4424  Qzz_AB("A',B'") = q_zz_AB("A',B'") - (q_xx_AB("A',B'") + q_yy_AB("A',B'")) * 0.5;
4425 
4426  TArray2 q_xx_mA = xy("<m|q_xx|A'>");
4427  TArray2 q_yy_mA = xy("<m|q_yy|A'>");
4428  TArray2 q_zz_mA = xy("<m|q_zz|A'>");
4429  TArray2 Qxx_mA, Qyy_mA, Qzz_mA;
4430  Qxx_mA("m,A'") = q_xx_mA("m,A'") - (q_zz_mA("m,A'") + q_yy_mA("m,A'") ) * 0.5;
4431  Qyy_mA("m,A'") = q_yy_mA("m,A'") - (q_xx_mA("m,A'") + q_zz_mA("m,A'") ) * 0.5;
4432  Qzz_mA("m,A'") = q_zz_mA("m,A'") - (q_xx_mA("m,A'") + q_yy_mA("m,A'") ) * 0.5;
4433 
4434  q_xx_e2 = - dot(Qxx_mn("m,n"), D_e2_mn("m,n"))
4435  + dot(Qxx_AB("A',B'"), D_e2_AB("A',B'"))
4436  + dot(Qxx_mA("m,A'"), TmA("m,A'")) * 2.0;
4437  q_yy_e2 = - dot(Qyy_mn("m,n"), D_e2_mn("m,n"))
4438  + dot(Qyy_AB("A',B'"), D_e2_AB("A',B'"))
4439  + dot(Qyy_mA("m,A'"), TmA("m,A'")) * 2.0;
4440  q_zz_e2 = - dot(Qzz_mn("m,n"), D_e2_mn("m,n"))
4441  + dot(Qzz_AB("A',B'"), D_e2_AB("A',B'"))
4442  + dot(Qzz_mA("m,A'"), TmA("m,A'")) * 2.0;
4443 
4444  q_xx_e2or = dot(Qxx_am("a,m"), Dbn_E2("a,m"));
4445  q_yy_e2or = dot(Qyy_am("a,m"), Dbn_E2("a,m"));
4446  q_zz_e2or = dot(Qzz_am("a,m"), Dbn_E2("a,m"));
4447  }
4448 
4449  // CABS singles contribution to
4450  // electric field gradient near the 1st nucleus
4451  if (compute_EFG) {
4452  TArray2 v_xx_mA = xy("<m|ddphi_xx|A'>");
4453  TArray2 v_yy_mA = xy("<m|ddphi_yy|A'>");
4454  TArray2 v_zz_mA = xy("<m|ddphi_zz|A'>");
4455  TArray2 v_xy_mA = xy("<m|ddphi_xy|A'>");
4456  TArray2 v_xz_mA = xy("<m|ddphi_xz|A'>");
4457  TArray2 v_yz_mA = xy("<m|ddphi_yz|A'>");
4458 
4459  TArray2 v_xx_AB = xy("<A'|ddphi_xx|B'>");
4460  TArray2 v_yy_AB = xy("<A'|ddphi_yy|B'>");
4461  TArray2 v_zz_AB = xy("<A'|ddphi_zz|B'>");
4462  TArray2 v_xy_AB = xy("<A'|ddphi_xy|B'>");
4463  TArray2 v_xz_AB = xy("<A'|ddphi_xz|B'>");
4464  TArray2 v_yz_AB = xy("<A'|ddphi_yz|B'>");
4465 
4466  const double v_xx_e2 = - dot(v_xx_mn("m,n"), D_e2_mn("m,n"))
4467  + dot(v_xx_AB("A',B'"), D_e2_AB("A',B'"))
4468  + dot(v_xx_mA("m,A'"), TmA("m,A'")) * 2.0;
4469  const double v_yy_e2 = - dot(v_yy_mn("m,n"), D_e2_mn("m,n"))
4470  + dot(v_yy_AB("A',B'"), D_e2_AB("A',B'"))
4471  + dot(v_yy_mA("m,A'"), TmA("m,A'")) * 2.0;
4472  const double v_zz_e2 = - dot(v_zz_mn("m,n"), D_e2_mn("m,n"))
4473  + dot(v_zz_AB("A',B'"), D_e2_AB("A',B'"))
4474  + dot(v_zz_mA("m,A'"), TmA("m,A'")) * 2.0;
4475  const double v_xy_e2 = - dot(v_xy_mn("m,n"), D_e2_mn("m,n"))
4476  + dot(v_xy_AB("A',B'"), D_e2_AB("A',B'"))
4477  + dot(v_xy_mA("m,A'"), TmA("m,A'")) * 2.0;
4478  const double v_xz_e2 = - dot(v_xz_mn("m,n"), D_e2_mn("m,n"))
4479  + dot(v_xz_AB("A',B'"), D_e2_AB("A',B'"))
4480  + dot(v_xz_mA("m,A'"), TmA("m,A'")) * 2.0;
4481  const double v_yz_e2 = - dot(v_yz_mn("m,n"), D_e2_mn("m,n"))
4482  + dot(v_yz_AB("A',B'"), D_e2_AB("A',B'"))
4483  + dot(v_yz_mA("m,A'"), TmA("m,A'")) * 2.0;
4484 
4485  const double v_xx_e2or = dot(v_xx_am("a,m"), Dbn_E2("a,m"));
4486  const double v_yy_e2or = dot(v_yy_am("a,m"), Dbn_E2("a,m"));
4487  const double v_zz_e2or = dot(v_zz_am("a,m"), Dbn_E2("a,m"));
4488  const double v_xy_e2or = dot(v_xy_am("a,m"), Dbn_E2("a,m"));
4489  const double v_xz_e2or = dot(v_xz_am("a,m"), Dbn_E2("a,m"));
4490  const double v_yz_e2or = dot(v_yz_am("a,m"), Dbn_E2("a,m"));
4491 
4492  std::cout << std::endl << indent
4493  << "electric gradient (E2)" << std::endl
4494  << indent << "v_xx (E2) = " << scprintf("%12.10f", v_xx_e2 * 2.0)
4495  << indent << " v_yy (E2) = " << scprintf("%12.10f", v_yy_e2 * 2.0)
4496  << indent << " v_zz (E2) = " << scprintf("%12.10f", v_zz_e2 * 2.0)
4497  << std::endl
4498  << indent << "v_xy (E2) = " << scprintf("%12.10f", v_xy_e2 * 2.0)
4499  << indent << " v_xz (E2) = " << scprintf("%12.10f", v_xz_e2 * 2.0)
4500  << indent << " v_yz (E2) = " << scprintf("%12.10f", v_yz_e2 * 2.0)
4501  << std::endl;
4502  std::cout << std::endl << indent
4503  << "electric gradient (E2 orbital response)" << std::endl
4504  << indent << "v_xx (E2 or) = " << scprintf("%12.10f", v_xx_e2or * 2.0)
4505  << indent << " v_yy (E2 or) = " << scprintf("%12.10f", v_yy_e2or * 2.0)
4506  << indent << " v_zz (E2 or) = " << scprintf("%12.10f", v_zz_e2or * 2.0)
4507  << std::endl
4508  << indent << "v_xy (E2 or) = " << scprintf("%12.10f", v_xy_e2or * 2.0)
4509  << indent << " v_xz (E2 or) = " << scprintf("%12.10f", v_xz_e2or * 2.0)
4510  << indent << " v_yz (E2 or) = " << scprintf("%12.10f", v_yz_e2or * 2.0)
4511  << std::endl << std::endl;
4512  }
4513 
4514  }
4515  world_.gop.fence(); // clear memory
4516 #endif
4517 
4518  // determine if it is frozen-core
4519  TArray2 Fij = xy("<i|F|j>");
4520  const std::size_t nocc = mFmn.trange().elements_range().extent()[0];
4521  const std::size_t naocc = Fij.trange().elements_range().extent()[0];
4522 
4523  // compute integrals needed for MP2 and following calculations of properties
4524  // dipole integrals
4525  TArray2 mu_z_ij, mu_z_ab, mu_z_ijp;
4526  if (compute_dipole) {
4527  mu_z_ij = xy("<i|mu_z|j>");
4528  mu_z_ab = xy("<a|mu_z|b>");
4529 
4530  if (nocc != naocc) {
4531  mu_z_ijp = xy("<i|mu_z|j'>");
4532  }
4533  }
4534 
4535  // quadrupole integrals
4536  TArray2 q_xx_ij, q_yy_ij, q_zz_ij, Qxx_ij, Qyy_ij, Qzz_ij;
4537  TArray2 q_xx_ab, q_yy_ab, q_zz_ab, Qxx_ab, Qyy_ab, Qzz_ab;
4538  // integrals for frozen-core
4539  TArray2 Qxx_ijp, Qyy_ijp, Qzz_ijp;
4540  if (compute_quadrupole){
4541  q_xx_ij = xy("<i|q_xx|j>");
4542  q_yy_ij = xy("<i|q_yy|j>");
4543  q_zz_ij = xy("<i|q_zz|j>");
4544  Qxx_ij("i,j") = q_xx_ij("i,j") - (q_zz_ij("i,j") + q_yy_ij("i,j")) * 0.5;
4545  Qyy_ij("i,j") = q_yy_ij("i,j") - (q_zz_ij("i,j") + q_xx_ij("i,j")) * 0.5;
4546  Qzz_ij("i,j") = q_zz_ij("i,j") - (q_xx_ij("i,j") + q_yy_ij("i,j")) * 0.5;
4547 
4548  q_xx_ab = xy("<a|q_xx|b>");
4549  q_yy_ab = xy("<a|q_yy|b>");
4550  q_zz_ab = xy("<a|q_zz|b>");
4551  Qxx_ab("a,b") = q_xx_ab("a,b") - (q_zz_ab("a,b") + q_yy_ab("a,b")) * 0.5;
4552  Qyy_ab("a,b") = q_yy_ab("a,b") - (q_zz_ab("a,b") + q_xx_ab("a,b")) * 0.5;
4553  Qzz_ab("a,b") = q_zz_ab("a,b") - (q_xx_ab("a,b") + q_yy_ab("a,b")) * 0.5;
4554 
4555  if (nocc != naocc) {
4556  TArray2 q_xx_ijp = xy("<i|q_xx|j'>");
4557  TArray2 q_yy_ijp = xy("<i|q_yy|j'>");
4558  TArray2 q_zz_ijp = xy("<i|q_zz|j'>");
4559  Qxx_ijp("i,j'") = q_xx_ijp("i,j'") - (q_zz_ijp("i,j'") + q_yy_ijp("i,j'")) * 0.5;
4560  Qyy_ijp("i,j'") = q_yy_ijp("i,j'") - (q_zz_ijp("i,j'") + q_xx_ijp("i,j'")) * 0.5;
4561  Qzz_ijp("i,j'") = q_zz_ijp("i,j'") - (q_xx_ijp("i,j'") + q_yy_ijp("i,j'")) * 0.5;
4562  }
4563  }
4564 
4565  // electric field gradient integrals
4566  TArray2 v_xx_ij, v_yy_ij, v_zz_ij, v_xy_ij, v_xz_ij, v_yz_ij;
4567  TArray2 v_xx_ab, v_yy_ab, v_zz_ab, v_xy_ab, v_xz_ab, v_yz_ab;
4568  if (compute_EFG) {
4569  v_xx_ij = xy("<i|ddphi_xx|j>");
4570  v_yy_ij = xy("<i|ddphi_yy|j>");
4571  v_zz_ij = xy("<i|ddphi_zz|j>");
4572  v_xy_ij = xy("<i|ddphi_xy|j>");
4573  v_xz_ij = xy("<i|ddphi_xz|j>");
4574  v_yz_ij = xy("<i|ddphi_yz|j>");
4575 
4576  v_xx_ab = xy("<a|ddphi_xx|b>");
4577  v_yy_ab = xy("<a|ddphi_yy|b>");
4578  v_zz_ab = xy("<a|ddphi_zz|b>");
4579  v_xy_ab = xy("<a|ddphi_xy|b>");
4580  v_xz_ab = xy("<a|ddphi_xz|b>");
4581  v_yz_ab = xy("<a|ddphi_yz|b>");
4582  }
4583 
4584  // compute terms needed for frozen-core
4585  TArray2 Delta_ijp_F;
4586  TArray4 A_ijpam;
4587  if (nocc != naocc) {
4588  // compute 1 / (Fi'i' - Fjj)
4589  TArray2 Fipjp = xy("<i'|F|j'>");
4590  pceval_type Delta_ijp_gen(TA::array_to_eigen(Fij), TA::array_to_eigen(Fipjp));
4591 
4592  TArray2 Fijp = xy("<i|F|j'>");
4593  TArray2d Delta_ijp(Fijp.world(), Fijp.trange());
4594  // construct local tiles
4595  for(auto t = Delta_ijp.trange().tiles_range().begin();
4596  t != Delta_ijp.trange().tiles_range().end(); ++t)
4597  if (Delta_ijp.is_local(*t)) {
4598  std::array<std::size_t, 2> index;
4599  std::copy(t->begin(), t->end(), index.begin());
4600  madness::Future < typename TArray2d::value_type >
4601  tile((LazyTensor<T, 2, pceval_type >(&Delta_ijp, index, &Delta_ijp_gen)
4602  ));
4603 
4604  // Insert the tile into the array
4605  Delta_ijp.set(*t, tile);
4606  }
4607  Delta_ijp_F("i,j'") = Delta_ijp("i,j'");
4608 
4609  A_ijpam("i,j',a,m") = 4.0 * _4("<i a|g|j' m>") - _4("<i a|g|m j'>") - _4("<i m|g|a j'>");
4610  }
4611 
4612  // compute MP2 and its orbital response contribution
4613  // compute Delta_ijab = - 1 / (- <i|F|i> - <j|F|j> + <a|F|a> + <b|F|b>)
4614  // which is needed for MP2 amplitudes & MP2 F12 coupling
4615  TArray2 mFij;
4616  mFij("i,j") = - _2("<i|F|j>");
4617  TArray4d g_ijab = ijxy("<i j|g|a b>");
4618 
4619  typedef detail::diag_precond4<double> pc4eval_type;
4620  typedef TA::Array<T, 4, LazyTensor<T, 4, pc4eval_type > > TArray4dLazy;
4621  TArray4dLazy Delta_ijab(g_ijab.world(), g_ijab.trange());
4622  pc4eval_type Delta_ijab_gen(TA::array_to_eigen(mFij), TA::array_to_eigen(mFij),
4623  TA::array_to_eigen(mFab),TA::array_to_eigen(mFab));
4624  // construct local tiles
4625  for(auto t = Delta_ijab.trange().tiles_range().begin();
4626  t != Delta_ijab.trange().tiles_range().end(); ++t)
4627  if (Delta_ijab.is_local(*t)) {
4628  std::array<std::size_t, 4> index;
4629  std::copy(t->begin(), t->end(), index.begin());
4630  madness::Future < typename TArray4dLazy::value_type >
4631  tile((LazyTensor<T, 4, pc4eval_type >(&Delta_ijab, index, &Delta_ijab_gen)
4632  ));
4633 
4634  // Insert the tile into the array
4635  Delta_ijab.set(*t, tile);
4636  }
4637 
4638  // MP2 amplitues which are needed for MP2 and coupling contibutions
4639  TArray4 T2_ijab;
4640  T2_ijab("i,j,a,b") = g_ijab("i,j,a,b") * Delta_ijab("i,j,a,b");
4641 
4642  double mu_z_mp2 = 0.0, mu_z_mp2or = 0.0;
4643  double q_xx_mp2 = 0.0, q_yy_mp2 = 0.0, q_zz_mp2 = 0.0;
4644  double q_xx_mp2or = 0.0, q_yy_mp2or = 0.0, q_zz_mp2or = 0.0;
4645 #if INCLUDE_MP2_CONTRI
4646  {
4647  ExEnv::out0() << std::endl << indent
4648  << "Compute MP2 contributions" << std::endl;
4649  // MP2 density
4650  TArray2 D_mp2_ij, D_mp2_ab;
4651  D_mp2_ij("i,j") = (2.0 * T2_ijab("i,k,a,b") - T2_ijab("k,i,a,b"))
4652  * T2_ijab("j,k,a,b");
4653  D_mp2_ab("a,b") = (2.0 * T2_ijab("i,j,a,c") - T2_ijab("i,j,c,a"))
4654  * T2_ijab("i,j,b,c");
4655 
4656  // MP2 orbital response
4657  TArray2 X_mp2_nfzc = Xam_mp2(T2_ijab, D_mp2_ij, D_mp2_ab);
4658 
4659  TArray2 X_mp2;
4660  // frozen-core contribution
4661  TArray2 Dijp_or_mp2;
4662  if (nocc != naocc) {
4663  ExEnv::out0() << std::endl << indent
4664  << "Include frozen-core MP2 contributions" << std::endl;
4665  Dijp_or_mp2("i,j'") = - ( _4("<j' l|g|c d>")
4666  * (2.0 * T2_ijab("i,l,c,d") - T2_ijab("l,i,c,d"))
4667  ) * Delta_ijp_F("i,j'") * 2.0;
4668  TArray2 Xam_Dijp_or;
4669  Xam_Dijp_or("a,m") = A_ijpam("i,j',a,m") * Dijp_or_mp2("i,j'");
4670  X_mp2("a,m") = X_mp2_nfzc("a,m") - Xam_Dijp_or("a,m");
4671 
4672  // test code: print out Ima in frozen-core case
4673 // TArray2 Iia, Ima;
4674 // Iia("a,i") = _4("<a l|g|c d>")
4675 // * (2.0 * T2_ijab("i,l,c,d") - T2_ijab("l,i,c,d"));
4676 // Ima("a,m") = (2.0 * _4("<a c|g|m d>") - _4("<a c|g|d m>"))
4677 // * D_mp2_ab("d,c")
4678 // - (2.0 * _4("<a l|g|m k>") - _4("<a l|g|k m>"))
4679 // * D_mp2_ij("k,l")
4680 // ;
4681 // TArray2 Iima = XaiAddToXam(Ima, Iia);
4682 // TArray2 Iima_fzc;
4683 // Iima_fzc("a,m") = Iima("a,m") + Xam_Dijp_or("a,m") * 0.5;
4684 // ExEnv::out0() << std::endl << "FZC Ima : " << std::endl << Iima_fzc << std::endl;
4685  } else {
4686  X_mp2("a,m") = X_mp2_nfzc("a,m");
4687  }
4688  // *** end of frozen-core ***
4689 
4690  TArray2 Dbn_mp2(X_mp2.world(), X_mp2.trange());
4691  auto resnorm_mp2 = cg_solver2(Orbital_relaxation_Abnam,
4692  X_mp2,
4693  Dbn_mp2,
4694  preconditioner,
4695  conv_target);
4696 
4697  // MP2 dipole
4698  if (compute_dipole) {
4699  // MP2 density contribution to dipole
4700  mu_z_mp2 = - dot(mu_z_ij("i,j"), D_mp2_ij("i,j"))
4701  + dot(mu_z_ab("a,b"), D_mp2_ab("a,b"));
4702 
4703  // MP2 orbital response contribution to dipole
4704  mu_z_mp2or = dot(mu_z_am("a,m"), Dbn_mp2("a,m"));
4705 
4706  if (nocc != naocc) {
4707  mu_z_mp2or += dot(mu_z_ijp("i,j'"), Dijp_or_mp2("i,j'"));
4708  }
4709  }
4710 
4711  // MP2 contribution to quadrupoles
4712  if (compute_quadrupole) {
4713  q_xx_mp2 = - dot(Qxx_ij("i,j"), D_mp2_ij("i,j"))
4714  + dot(Qxx_ab("a,b"), D_mp2_ab("a,b"));
4715  q_yy_mp2 = - dot(Qyy_ij("i,j"), D_mp2_ij("i,j"))
4716  + dot(Qyy_ab("a,b"), D_mp2_ab("a,b"));
4717  q_zz_mp2 = - dot(Qzz_ij("i,j"), D_mp2_ij("i,j"))
4718  + dot(Qzz_ab("a,b"), D_mp2_ab("a,b"));
4719 // // x2, y2, z2 components to quadrupole moment
4720 // q_xx_mp2 = - dot(q_xx_ij("i,j"), D_mp2_ij("i,j"))
4721 // + dot(q_xx_ab("a,b"), D_mp2_ab("a,b"));
4722 // q_yy_mp2 = - dot(q_yy_ij("i,j"), D_mp2_ij("i,j"))
4723 // + dot(q_yy_ab("a,b"), D_mp2_ab("a,b"));
4724 // q_zz_mp2 = - dot(q_zz_ij("i,j"), D_mp2_ij("i,j"))
4725 // + dot(q_zz_ab("a,b"), D_mp2_ab("a,b"));
4726 
4727  q_xx_mp2or = dot(Qxx_am("a,m"), Dbn_mp2("a,m"));
4728  q_yy_mp2or = dot(Qyy_am("a,m"), Dbn_mp2("a,m"));
4729  q_zz_mp2or = dot(Qzz_am("a,m"), Dbn_mp2("a,m"));
4730 // // x2, y2, z2 components to quadrupole moment
4731 // q_xx_mp2or = dot(q_xx_am("a,m"), Dbn_mp2("a,m"));
4732 // q_yy_mp2or = dot(q_yy_am("a,m"), Dbn_mp2("a,m"));
4733 // q_zz_mp2or = dot(q_zz_am("a,m"), Dbn_mp2("a,m"));
4734 
4735  if (nocc != naocc) {
4736  q_xx_mp2or += dot(Qxx_ijp("i,j'"), Dijp_or_mp2("i,j'"));
4737  q_yy_mp2or += dot(Qyy_ijp("i,j'"), Dijp_or_mp2("i,j'"));
4738  q_zz_mp2or += dot(Qzz_ijp("i,j'"), Dijp_or_mp2("i,j'"));
4739  }
4740  }
4741 
4742  // Electric field gradient near the 1st nucleus
4743  if (compute_EFG) {
4744  const double v_xx_mp2 = - dot(v_xx_ij("i,j"), D_mp2_ij("i,j"))
4745  + dot(v_xx_ab("a,b"), D_mp2_ab("a,b"));
4746  const double v_yy_mp2 = - dot(v_yy_ij("i,j"), D_mp2_ij("i,j"))
4747  + dot(v_yy_ab("a,b"), D_mp2_ab("a,b"));
4748  const double v_zz_mp2 = - dot(v_zz_ij("i,j"), D_mp2_ij("i,j"))
4749  + dot(v_zz_ab("a,b"), D_mp2_ab("a,b"));
4750  const double v_xy_mp2 = - dot(v_xy_ij("i,j"), D_mp2_ij("i,j"))
4751  + dot(v_xy_ab("a,b"), D_mp2_ab("a,b"));
4752  const double v_xz_mp2 = - dot(v_xz_ij("i,j"), D_mp2_ij("i,j"))
4753  + dot(v_xz_ab("a,b"), D_mp2_ab("a,b"));
4754  const double v_yz_mp2 = - dot(v_yz_ij("i,j"), D_mp2_ij("i,j"))
4755  + dot(v_yz_ab("a,b"), D_mp2_ab("a,b"));
4756 
4757  const double v_xx_mp2or = dot(v_xx_am("a,m"), Dbn_mp2("a,m"));
4758  const double v_yy_mp2or = dot(v_yy_am("a,m"), Dbn_mp2("a,m"));
4759  const double v_zz_mp2or = dot(v_zz_am("a,m"), Dbn_mp2("a,m"));
4760  const double v_xy_mp2or = dot(v_xy_am("a,m"), Dbn_mp2("a,m"));
4761  const double v_xz_mp2or = dot(v_xz_am("a,m"), Dbn_mp2("a,m"));
4762  const double v_yz_mp2or = dot(v_yz_am("a,m"), Dbn_mp2("a,m"));
4763 
4764  std::cout << std::endl << indent
4765  << "electric gradient (MP2)" << std::endl
4766  << indent << "v_xx (MP2) = " << scprintf("%12.10f", - v_xx_mp2 * 2.0)
4767  << indent << " v_yy (MP2) = " << scprintf("%12.10f", - v_yy_mp2 * 2.0)
4768  << indent << " v_zz (MP2) = " << scprintf("%12.10f", - v_zz_mp2 * 2.0)
4769  << std::endl
4770  << indent << "v_xy (MP2) = " << scprintf("%12.10f", - v_xy_mp2 * 2.0)
4771  << indent << " v_xz (MP2) = " << scprintf("%12.10f", - v_xz_mp2 * 2.0)
4772  << indent << " v_yz (MP2) = " << scprintf("%12.10f", - v_yz_mp2 * 2.0)
4773  << std::endl;
4774  std::cout << std::endl << indent
4775  << "electric gradient (MP2 orbital response)" << std::endl
4776  << indent << "v_xx (MP2 or) = " << scprintf("%12.10f", - v_xx_mp2or * 2.0)
4777  << indent << " v_yy (MP2 or) = " << scprintf("%12.10f", - v_yy_mp2or * 2.0)
4778  << indent << " v_zz (MP2 or) = " << scprintf("%12.10f", - v_zz_mp2or * 2.0)
4779  << std::endl
4780  << indent << "v_xy (MP2 or) = " << scprintf("%12.10f", - v_xy_mp2or * 2.0)
4781  << indent << " v_xz (MP2 or) = " << scprintf("%12.10f", - v_xz_mp2or * 2.0)
4782  << indent << " v_yz (MP2 or) = " << scprintf("%12.10f", - v_yz_mp2or * 2.0)
4783  << std::endl << std::endl;
4784  }
4785 
4786  }
4787  world_.gop.fence();
4788 #endif
4789 
4790  // compute integrals needed for F12 related calculations of properties
4791  TArray2 mu_z_apb;
4792  if (compute_dipole) {
4793  mu_z_apb = xy("<a'|mu_z|b>");
4794  }
4795 
4796  TArray2 q_xx_apb, q_yy_apb, q_zz_apb;
4797  TArray2 Qxx_apb, Qyy_apb, Qzz_apb, Qxy_apb, Qxz_apb, Qyz_apb;
4798  if (compute_quadrupole) {
4799  q_xx_apb = xy("<a'|q_xx|b>");
4800  q_yy_apb = xy("<a'|q_yy|b>");
4801  q_zz_apb = xy("<a'|q_zz|b>");
4802 
4803  Qxx_apb("a',b") = q_xx_apb("a',b") - (q_zz_apb("a',b") + q_yy_apb("a',b")) * 0.5;
4804  Qyy_apb("a',b") = q_yy_apb("a',b") - (q_zz_apb("a',b") + q_xx_apb("a',b")) * 0.5 ;
4805  Qzz_apb("a',b") = q_zz_apb("a',b") - (q_xx_apb("a',b") + q_yy_apb("a',b")) * 0.5;
4806  Qxy_apb("a',b") = _2("<a'|q_xy|b>") * 1.5;
4807  Qxz_apb("a',b") = _2("<a'|q_xz|b>") * 1.5;
4808  Qyz_apb("a',b") = _2("<a'|q_yz|b>") * 1.5;
4809  }
4810 
4811  TArray2 v_xx_apb, v_yy_apb, v_zz_apb, v_xy_apb, v_xz_apb, v_yz_apb;
4812  if (compute_EFG) {
4813  v_xx_apb = xy("<a'|ddphi_xx|b>");
4814  v_yy_apb = xy("<a'|ddphi_yy|b>");
4815  v_zz_apb = xy("<a'|ddphi_zz|b>");
4816  v_xy_apb = xy("<a'|ddphi_xy|b>");
4817  v_xz_apb = xy("<a'|ddphi_xz|b>");
4818  v_yz_apb = xy("<a'|ddphi_yz|b>");
4819  }
4820 
4821  // singlet and triplet coefficients for F12 and coupling terms
4822  const double C_0 = 1.0 / 2.0;
4823  const double C_1 = 1.0 / 4.0;
4824  // compute coefficients needed in the F12 and coupling calculations
4825  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
4826  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
4827  const double RR_C1 = 0.5 * C_0 * C_0 + 1.5 * C_1 * C_1;
4828  const double RR_C2 = 0.5 * C_0 * C_0 - 1.5 * C_1 * C_1;
4829 
4830  // MP2 F12 coupling part
4831  double mu_z_mp2f12C = 0.0, mu_z_mp2f12Cor = 0.0;
4832  double q_xx_mp2f12C = 0.0, q_yy_mp2f12C = 0.0, q_zz_mp2f12C = 0.0;
4833  double q_xx_mp2f12Cor = 0.0, q_yy_mp2f12Cor = 0.0, q_zz_mp2f12Cor = 0.0;
4834 #if INCLUDE_MP2F12C_CONTRI
4835  {
4836  ExEnv::out0() << std::endl << indent
4837  << "Compute MP2 F12 coupling contributions" << std::endl;
4838  TArray4 C_ijab, A_ijab;
4839  C_ijab("i,j,a,b") = _4("<i j|r|a_F(a') b>") + _4("<i j|r|a b_F(a')>");
4840  A_ijab("i,j,a,b") = C_ijab("i,j,a,b") * Delta_ijab("i,j,a,b");
4841 
4842  // Coupling and F12 part of MP2F12 density
4843  ExEnv::out0() << indent
4844  << "Compute density from coupling contribution" << std::endl;
4845  TArray2 D_mp2f12_ij, D_mp2f12_ab;
4846  D_mp2f12_ij("i,j") = (R_C1 * A_ijab("i,k,a,b") + R_C2 * A_ijab("k,i,a,b"))
4847  * T2_ijab("j,k,a,b")
4848  // A_jk^ab T_ab^ik
4849  + (R_C1 * A_ijab("j,k,a,b") + R_C2 * A_ijab("k,j,a,b"))
4850  * T2_ijab("i,k,a,b")
4851  // A^ik_ab A^ab_jk
4852  + (RR_C1 * A_ijab("i,k,a,b") + RR_C2 * A_ijab("k,i,a,b"))
4853  * A_ijab("j,k,a,b");
4854  D_mp2f12_ab("a,b") = (R_C1 * T2_ijab("i,j,a,c") + R_C2 * T2_ijab("i,j,c,a"))
4855  * A_ijab("i,j,b,c")
4856  // A^ac_ij T^ij_bc
4857  + (R_C1 * T2_ijab("i,j,b,c") + R_C2 * T2_ijab("i,j,c,b"))
4858  * A_ijab("i,j,a,c")
4859  // A_ac^ij A_ij^bc
4860  + (RR_C1 * A_ijab("i,j,a,c") + RR_C2 * A_ijab("i,j,c,a"))
4861  * A_ijab("i,j,b,c");
4862 
4863  // 1/2 R^kl_a'c \tilde{T}^bc_kl
4864  TArray2 RT_apb;
4865  RT_apb("a',b") = _4("<a' c|r|k l>")
4866  * ( R_C1 * T2_ijab("k,l,b,c") + R_C2 * T2_ijab("k,l,c,b")
4867  + RR_C1 * A_ijab("k,l,b,c") + RR_C2 * A_ijab("k,l,c,b")
4868  );
4869 
4870  // MP2 F12 coupling contribution to orbital response
4871  ExEnv::out0() << indent
4872  << "Compute orbital response from coupling contribution" << std::endl;
4873  TArray2 Xmp2f12_contri_nfzc = Xam_Cmp2f12(C_0, C_1,T2_ijab, A_ijab,
4874  D_mp2f12_ij, D_mp2f12_ab, RT_apb);
4875 
4876  TArray2 Xmp2f12_contri;
4877  // frozen-core contribution
4878  TArray2 Diip_Cmp2;
4879  if (nocc != naocc) {
4880  ExEnv::out0() << std::endl << indent
4881  << "Include frozen-core contributions for MP2 F12 coupling" << std::endl;
4882  TArray2 Xiip_CT2_mp2;
4883  Xiip_CT2_mp2("i,i'") = // F^a'_b R^i'l_a'c \tilde{T}^bc_il
4884  _4("<i' l|r|b_F(a') c>")
4885  * ( R_C1 * T2_ijab("i,l,b,c") + R_C2 * T2_ijab("l,i,b,c")
4886  + RR_C1 * A_ijab("i,l,b,c") + RR_C2 * A_ijab("l,i,b,c")
4887  )
4888  + _4("<i' l|r|c b_F(a')>")
4889  * ( R_C1 * T2_ijab("i,l,c,b") + R_C2 * T2_ijab("l,i,c,b")
4890  + RR_C1 * A_ijab("i,l,c,b") + RR_C2 * A_ijab("l,i,c,b")
4891  )
4892  // g^i'l_cd A^cd_il
4893  + _4("<i' l|g|c d>")
4894  * (R_C1 * A_ijab("i,l,c,d") + R_C2 * A_ijab("l,i,c,d"))
4895  ; // 2.0 is not multiplied as 4.0 is multiplied in the end
4896 
4897  Diip_Cmp2("i,i'") = - Xiip_CT2_mp2("i,i'") * Delta_ijp_F("i,i'");
4898 
4899  Xmp2f12_contri("a,m") = Xmp2f12_contri_nfzc("a,m") - A_ijpam("i,j',a,m") * Diip_Cmp2("i,j'");
4900 
4901  } else {
4902  Xmp2f12_contri("a,m") = Xmp2f12_contri_nfzc("a,m");
4903  }
4904 
4905  TArray2 Dbn_mp2f12(Xmp2f12_contri.world(), Xmp2f12_contri.trange());
4906  auto resnorm_mp2f12 = cg_solver2(Orbital_relaxation_Abnam,
4907  Xmp2f12_contri,
4908  Dbn_mp2f12,
4909  preconditioner,
4910  conv_target);
4911 
4912  // MP2-F12 coupling contribution to dipole
4913  if (compute_dipole) {
4914  // MP2 F12 coupling density contribution to dipole
4915  mu_z_mp2f12C = - dot(mu_z_ij("i,j"), D_mp2f12_ij("i,j"))
4916  + dot(mu_z_ab("a,b"), D_mp2f12_ab("a,b"))
4917  + dot(mu_z_apb("a',b"), RT_apb("a',b")) * 2.0;
4918 
4919  // MP2-F12 coupling orbital response contribution to dipole
4920  mu_z_mp2f12Cor = dot(mu_z_am("a,m"), Dbn_mp2f12("a,m"));
4921 
4922  if (nocc != naocc) {
4923  mu_z_mp2f12Cor += dot(mu_z_ijp("i,j'"), Diip_Cmp2("i,j'"));
4924  }
4925  }
4926 
4927  // MP2-F12 coupling contribution to quadrupoles
4928  if (compute_quadrupole) {
4929  q_xx_mp2f12C = - dot(Qxx_ij("i,j"), D_mp2f12_ij("i,j"))
4930  + dot(Qxx_ab("a,b"), D_mp2f12_ab("a,b"))
4931  + dot(Qxx_apb("a',b"), RT_apb("a',b")) * 2.0;
4932  q_yy_mp2f12C = - dot(Qyy_ij("i,j"), D_mp2f12_ij("i,j"))
4933  + dot(Qyy_ab("a,b"), D_mp2f12_ab("a,b"))
4934  + dot(Qyy_apb("a',b"), RT_apb("a',b")) * 2.0;
4935  q_zz_mp2f12C = - dot(Qzz_ij("i,j"), D_mp2f12_ij("i,j"))
4936  + dot(Qzz_ab("a,b"), D_mp2f12_ab("a,b"))
4937  + dot(Qzz_apb("a',b"), RT_apb("a',b")) * 2.0;
4938 // // x2, y2, z2 components to quadrupole moment
4939 // q_xx_mp2f12C = - dot(q_xx_ij("i,j"), D_mp2f12_ij("i,j"))
4940 // + dot(q_xx_ab("a,b"), D_mp2f12_ab("a,b"))
4941 // + dot(q_xx_apb("a',b"), RT_apb("a',b")) * 2.0;
4942 // q_yy_mp2f12C = - dot(q_yy_ij("i,j"), D_mp2f12_ij("i,j"))
4943 // + dot(q_yy_ab("a,b"), D_mp2f12_ab("a,b"))
4944 // + dot(q_yy_apb("a',b"), RT_apb("a',b")) * 2.0;
4945 // q_zz_mp2f12C = - dot(q_zz_ij("i,j"), D_mp2f12_ij("i,j"))
4946 // + dot(q_zz_ab("a,b"), D_mp2f12_ab("a,b"))
4947 // + dot(q_zz_apb("a',b"), RT_apb("a',b")) * 2.0;
4948 
4949  q_xx_mp2f12Cor = dot(Qxx_am("a,m"), Dbn_mp2f12("a,m"));
4950  q_yy_mp2f12Cor = dot(Qyy_am("a,m"), Dbn_mp2f12("a,m"));
4951  q_zz_mp2f12Cor = dot(Qzz_am("a,m"), Dbn_mp2f12("a,m"));
4952 // // x2, y2, z2 components to quadrupole moment
4953 // q_xx_mp2f12Cor = dot(q_xx_am("a,m"), Dbn_mp2f12("a,m"));
4954 // q_yy_mp2f12Cor = dot(q_yy_am("a,m"), Dbn_mp2f12("a,m"));
4955 // q_zz_mp2f12Cor = dot(q_zz_am("a,m"), Dbn_mp2f12("a,m"));
4956 
4957  if (nocc != naocc) {
4958  q_xx_mp2f12Cor += dot(Qxx_ijp("i,j'"), Diip_Cmp2("i,j'"));
4959  q_yy_mp2f12Cor += dot(Qyy_ijp("i,j'"), Diip_Cmp2("i,j'"));
4960  q_zz_mp2f12Cor += dot(Qzz_ijp("i,j'"), Diip_Cmp2("i,j'"));
4961  }
4962  }
4963 
4964  // MP2-F12 coupling contribution to electric field gradient on 1st nucleus
4965  if (compute_EFG) {
4966  const double v_xx_mp2f12C = - dot(v_xx_ij("i,j"), D_mp2f12_ij("i,j"))
4967  + dot(v_xx_ab("a,b"), D_mp2f12_ab("a,b"))
4968  + dot(v_xx_apb("a',b"), RT_apb("a',b")) * 2.0;
4969  const double v_yy_mp2f12C = - dot(v_yy_ij("i,j"), D_mp2f12_ij("i,j"))
4970  + dot(v_yy_ab("a,b"), D_mp2f12_ab("a,b"))
4971  + dot(v_yy_apb("a',b"), RT_apb("a',b")) * 2.0;
4972  const double v_zz_mp2f12C = - dot(v_zz_ij("i,j"), D_mp2f12_ij("i,j"))
4973  + dot(v_zz_ab("a,b"), D_mp2f12_ab("a,b"))
4974  + dot(v_zz_apb("a',b"), RT_apb("a',b")) * 2.0;
4975  const double v_xy_mp2f12C = - dot(v_xy_ij("i,j"), D_mp2f12_ij("i,j"))
4976  + dot(v_xy_ab("a,b"), D_mp2f12_ab("a,b"))
4977  + dot(v_xy_apb("a',b"), RT_apb("a',b")) * 2.0;
4978  const double v_xz_mp2f12C = - dot(v_xz_ij("i,j"), D_mp2f12_ij("i,j"))
4979  + dot(v_xz_ab("a,b"), D_mp2f12_ab("a,b"))
4980  + dot(v_xz_apb("a',b"), RT_apb("a',b")) * 2.0;
4981  const double v_yz_mp2f12C = - dot(v_yz_ij("i,j"), D_mp2f12_ij("i,j"))
4982  + dot(v_yz_ab("a,b"), D_mp2f12_ab("a,b"))
4983  + dot(v_yz_apb("a',b"), RT_apb("a',b")) * 2.0;
4984 
4985  const double v_xx_mp2f12Cor = dot(v_xx_am("a,m"), Dbn_mp2f12("a,m"));
4986  const double v_yy_mp2f12Cor = dot(v_yy_am("a,m"), Dbn_mp2f12("a,m"));
4987  const double v_zz_mp2f12Cor = dot(v_zz_am("a,m"), Dbn_mp2f12("a,m"));
4988  const double v_xy_mp2f12Cor = dot(v_xy_am("a,m"), Dbn_mp2f12("a,m"));
4989  const double v_xz_mp2f12Cor = dot(v_xz_am("a,m"), Dbn_mp2f12("a,m"));
4990  const double v_yz_mp2f12Cor = dot(v_yz_am("a,m"), Dbn_mp2f12("a,m"));
4991 
4992  std::cout << std::endl << indent
4993  << "electric gradient (MP2F12 coupling)" << std::endl
4994  << indent << "v_xx (MP2F12 C) = " << scprintf("%12.10f", v_xx_mp2f12C * 2.0)
4995  << indent << " v_yy (MP2F12 C) = " << scprintf("%12.10f", v_yy_mp2f12C * 2.0)
4996  << indent << " v_zz (MP2F12 C) = " << scprintf("%12.10f", v_zz_mp2f12C * 2.0)
4997  << std::endl
4998  << indent << "v_xy (MP2F12 C) = " << scprintf("%12.10f", v_xy_mp2f12C * 2.0)
4999  << indent << " v_xz (MP2F12 C) = " << scprintf("%12.10f", v_xz_mp2f12C * 2.0)
5000  << indent << " v_yz (MP2F12 C) = " << scprintf("%12.10f", v_yz_mp2f12C * 2.0)
5001  << std::endl;
5002  std::cout << std::endl << indent
5003  << "electric gradient (MP2F12 coupling orbital response)" << std::endl
5004  << indent << "v_xx (MP2F12 C or) = " << scprintf("%12.10f", v_xx_mp2f12Cor * 2.0)
5005  << indent << " v_yy (MP2F12 C or) = " << scprintf("%12.10f", v_yy_mp2f12Cor * 2.0)
5006  << indent << " v_zz (MP2F12 C or) = " << scprintf("%12.10f", v_zz_mp2f12Cor * 2.0)
5007  << std::endl
5008  << indent << "v_xy (MP2F12 C or) = " << scprintf("%12.10f", v_xy_mp2f12Cor * 2.0)
5009  << indent << " v_xz (MP2F12 C or) = " << scprintf("%12.10f", v_xz_mp2f12Cor * 2.0)
5010  << indent << " v_yz (MP2F12 C or) = " << scprintf("%12.10f", v_yz_mp2f12Cor * 2.0)
5011  << std::endl << std::endl;
5012  }
5013 
5014  }
5015  world_.gop.fence();
5016 #endif
5017 
5018  // F12 contribution
5019  double mu_z_f12 = 0.0, mu_z_f12or = 0.0;
5020  double q_xx_f12 = 0.0, q_yy_f12 = 0.0, q_zz_f12 = 0.0;
5021  double q_xx_f12or = 0.0, q_yy_f12or = 0.0, q_zz_f12or = 0.0;
5022 #if INCLUDE_F12_CONTRI
5023  {
5024  ExEnv::out0() << std::endl << indent
5025  << "Compute F12 contributions" << std::endl;
5026 
5027  ExEnv::out0() << std::endl << indent << "Compute D_f12" << std::endl;
5028  // F12 density from X and B terms
5029  TArray2 D_f12_ij, D_f12_ab, D_f12_apbp, D_f12_apb;
5030  compute_Df12_XB(C_0, C_1, D_f12_ij, D_f12_ab, D_f12_apbp, D_f12_apb);
5031 
5032 
5033  // F12 orbital response contribution
5034 
5035  ExEnv::out0() << std::endl << indent << "Compute X and B density contribution to Xam" << std::endl;
5036  // X and B density contribution to Xam
5037  TArray2 gdf12_am = Xam_Df12_XB(C_0, C_1, D_f12_ij,D_f12_ab,
5038  D_f12_apbp, D_f12_apb);
5039 
5040  // Xam from F12 (V, X, and B) contributions
5041  ExEnv::out0() << std::endl << indent << "Compute V Xam" << std::endl;
5042  TArray2 Xam_Vcontri = Xam_V(C_0, C_1);
5043  ExEnv::out0() << std::endl << indent << "Compute X Xam" << std::endl;
5044  TArray2 Xam_Xcontri = Xam_X(C_0, C_1);
5045  ExEnv::out0() << std::endl << indent << "Compute B Xam" << std::endl;
5046  TArray2 Xam_Bcontri = Xam_B(C_0, C_1);
5047 
5048  // F12 contribution to orbital response
5049  TArray2 Xam_f12_nfzc;
5050  Xam_f12_nfzc("a,m") = 2.0 * ( Xam_Vcontri("a,m")
5051  - Xam_Xcontri("a,m")
5052  + Xam_Bcontri("a,m")
5053  + gdf12_am("a,m") // F12 density terms
5054  );
5055  TArray2 Xam_f12;
5056  // frozen-core contribution of F12 part: Xii'
5057  TArray2 Diip_f12;
5058  if (nocc != naocc) {
5059  ExEnv::out0() << std::endl << indent
5060  << "Include frozen-core F12 contributions" << std::endl;
5061  TArray2 Xiip_f12 = Xiip_VBX(C_0, C_1);
5062  Diip_f12("i,i'") = - Xiip_f12("i,i'") * Delta_ijp_F("i,i'");
5063 
5064  Xam_f12("a,m") = Xam_f12_nfzc("a,m") - A_ijpam("i,j',a,m") * Diip_f12("i,j'");
5065  } else {
5066  Xam_f12("a,m") = Xam_f12_nfzc("a,m");
5067  }
5068 
5069  TArray2 Dbn_f12(Xam_f12.world(), Xam_f12.trange());
5070  auto resnorm_f12 = cg_solver2(Orbital_relaxation_Abnam,
5071  Xam_f12,
5072  Dbn_f12,
5073  preconditioner,
5074  conv_target);
5075 
5076  // print out each contribution in F12 contribution
5077 #if 0
5078  TArray2 gdf12_X_am;
5079  gdf12_X_am("a,m") = // X related contribution
5080  (2.0 * _4("<a k|g|m l>") - _4("<a k|g|l m>"))
5081  * D_f12_ij("k,l");
5082  TArray2 gdf12_B_am;
5083  gdf12_B_am("a,m") = // B related contribution
5084  - (2.0 * g_abmc("a,b,m,c") - g_abmc("b,a,m,c"))
5085  * D_f12_ab("b,c")
5086  - (2.0 * _4("<a b'|g|m c'>") - _4("<a b'|g|c' m>"))
5087  * D_f12_apbp("b',c'")
5088  - (2.0 * _4("<a b'|g|m c>") - _4("<a b'|g|c m>"))
5089  * D_f12_apb("b',c")
5090  - (2.0 * _4("<a b|g|m c'>") - _4("<a b|g|c' m>"))
5091  * D_f12_apb("c',b");
5092 
5093  TArray2 Xam_V_nfzc;
5094  Xam_V_nfzc("a,m") = 2.0 * Xam_Vcontri("a,m");
5095  TArray2 Xam_X_nfzc;
5096  Xam_X_nfzc("a,m") = 2.0 * (- Xam_Xcontri("a,m") + gdf12_X_am("a,m"));
5097  TArray2 Xam_B_nfzc;
5098  Xam_B_nfzc("a,m") = 2.0 * (Xam_Bcontri("a,m")+ gdf12_B_am("a,m"));
5099 
5100  TArray2 Xam_V, Xam_X, Xam_B;
5101  // frozen-core contribution of F12 part: Xii'
5102  TArray2 D_iip_V, D_iip_X, D_iip_B;
5103  if (nocc != naocc) {
5104  ExEnv::out0() << std::endl << indent
5105  << "Include frozen-core V, X, and B contributions" << std::endl;
5106  TArray2 Xiip_V;
5107  const char* ip = "i'";
5108  const char* i = "i";
5109  TArray2 V_ipi = VRk_Sk(ip,i,C_0, C_1);
5110  TArray2 V_iip = VRk_Sk(i,ip,C_0, C_1);
5111  Xiip_V("i,i'") = // 2 * (1/2 R^i'k_A'C' g^A'C'_ik + 1/2 R^ik_A'C' g^A'C'_i'k)
5112  2.0 * (V_ipi("i',i") + V_iip("i,i'"));
5113  D_iip_V("i,i'") = - Xiip_V("i,i'") * Delta_ijp_F("i,i'");
5114  Xam_V("a,m") = Xam_V_nfzc("a,m") - A_ijpam("i,j',a,m") * D_iip_V("i,j'");
5115 
5116  TArray2 Xiip_X;
5117  TArray2 F_ij = xy("<i|F|j>");
5118  TArray4d r2_ipk_jl = ijxy("<i' k|r2|j l>");
5119  TArray4d r_ipk_pq = ijxy("<i' k|r|p q>");
5120  TArray4d r_pqkl = ijxy("<p q|r|k l>");
5121  TArray4d r_ipk_apn = ijxy("<i' k|r|a' n>");
5122  TArray4d r_apn_kl = ijxy("<a' n|r|k l>");
5123  TArray4d r_kip_apn = ijxy("<k i'|r|a' n>");
5124  Xiip_X("i,i'") = // 2 * (F^i_i + F^k_k) 1/2 R^i'k_A'B' R_ik^A'B'
5125  - 2.0 * ( (RR_C1 * r2_ipk_jl("i',k,j,l") + RR_C2 * r2_ipk_jl("i',k,l,j"))
5126  * _2("<l|I|k>") * F_ij("j,i")
5127  + (RR_C1 * r2_ipk_jl("i',k,i,l") + RR_C2 * r2_ipk_jl("i',k,l,i"))
5128  * F_ij("l,k")
5129 
5130  - (RR_C1 * r_ipk_pq("i',k,p,q") + RR_C2 * r_ipk_pq("i',k,q,p"))
5131  * ( r_pqkl("p,q,j,k") * F_ij("j,i")
5132  + r_pqkl("p,q,i,l") * F_ij("l,k"))
5133 
5134  - (RR_C1 * r_ipk_apn("i',k,a',n") + RR_C2 * r_kip_apn("k,i',a',n"))
5135  * ( r_apn_kl("a',n,j,k") * F_ij("j,i")
5136  + r_apn_kl("a',n,i,l") * F_ij("l,k"))
5137 
5138  - (RR_C1 * r_kip_apn("k,i',a',n") + RR_C2 * r_ipk_apn("i',k,a',n"))
5139  * ( r_apn_kl("a',n,k,j") * F_ij("j,i")
5140  + r_apn_kl("a',n,l,i") * F_ij("l,k"))
5141  );
5142  D_iip_X("i,i'") = - Xiip_X("i,i'") * Delta_ijp_F("i,i'");
5143  Xam_X("a,m") = Xam_X_nfzc("a,m") - A_ijpam("i,j',a,m") * D_iip_X("i,j'");
5144 
5145  TArray2 Xiip_B;
5146  TArray2 B_ipi = BPk_Qk(ip,i,C_0,C_1);
5147  Xiip_B("i,i'") = // 2 R^i'k_A'B' F^A'_C' R^ik_C'B'
5148  2.0 * B_ipi("i',i");
5149  D_iip_B("i,i'") = - Xiip_B("i,i'") * Delta_ijp_F("i,i'");
5150  Xam_B("a,m") = Xam_B_nfzc("a,m") - A_ijpam("i,j',a,m") * D_iip_B("i,j'");
5151  } else {
5152  Xam_V("a,m") = Xam_V_nfzc("a,m");
5153  Xam_X("a,m") = Xam_X_nfzc("a,m");
5154  Xam_B("a,m") = Xam_B_nfzc("a,m");
5155  }
5156 
5157  TArray2 Dbn_V(Xam_V.world(), Xam_V.trange());
5158  auto resnorm_V = cg_solver2(Orbital_relaxation_Abnam,
5159  Xam_V,
5160  Dbn_V,
5161  preconditioner,
5162  conv_target);
5163  TArray2 Dbn_X(Xam_X.world(), Xam_X.trange());
5164  auto resnorm_X = cg_solver2(Orbital_relaxation_Abnam,
5165  Xam_X,
5166  Dbn_X,
5167  preconditioner,
5168  conv_target);
5169  TArray2 Dbn_B(Xam_B.world(), Xam_B.trange());
5170  auto resnorm_B = cg_solver2(Orbital_relaxation_Abnam,
5171  Xam_B,
5172  Dbn_B,
5173  preconditioner,
5174  conv_target);
5175 
5176  if (compute_dipole) {
5177  double mu_z_X, mu_z_B, mu_z_Vor, mu_z_Xor, mu_z_Bor;
5178  // F12 density contribution to dipole
5179  mu_z_X = // X related contribution
5180  - dot(mu_z_ij("i,j"), D_f12_ij("i,j"));
5181  TArray2 mu_z_apbp = xy("<a'|mu_z|b'>");
5182  mu_z_B = // B related contribution
5183  dot(mu_z_ab("a,b"), D_f12_ab("a,b"))
5184  + dot(mu_z_apbp("a',b'"), D_f12_apbp("a',b'"))
5185  + dot(mu_z_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5186 
5187  mu_z_Vor = dot(mu_z_am("a,m"), Dbn_V("a,m"));
5188  mu_z_Xor = dot(mu_z_am("a,m"), Dbn_X("a,m"));
5189  mu_z_Bor = dot(mu_z_am("a,m"), Dbn_B("a,m"));
5190  if (nocc != naocc) {
5191  mu_z_Vor += dot(mu_z_ijp("i,j'"), D_iip_V("i,j'"));
5192  mu_z_Xor += dot(mu_z_ijp("i,j'"), D_iip_X("i,j'"));
5193  mu_z_Bor += dot(mu_z_ijp("i,j'"), D_iip_B("i,j'"));
5194  }
5195 
5196  std::cout << std::endl << indent
5197  << "mu_z (V orbital response) = " << scprintf("%15.12f", - mu_z_Vor * 2.0)
5198  << std::endl << indent
5199  << "mu_z (X) = " << scprintf("%15.12f",- mu_z_X * 2.0)
5200  << std::endl << indent
5201  << "mu_z (X orbital response) = " << scprintf("%15.12f", - mu_z_Xor * 2.0)
5202  << std::endl << indent
5203  << "mu_z (B) = " << scprintf("%15.12f",- mu_z_B * 2.0)
5204  << std::endl << indent
5205  << "mu_z (B orbital response) = " << scprintf("%15.12f", - mu_z_Bor * 2.0)
5206  << std::endl;
5207  }
5208 #endif
5209 
5210  if (compute_dipole) {
5211  TArray2 mu_z_apbp = xy("<a'|mu_z|b'>");
5212  // F12 density contribution to dipole
5213  mu_z_f12 = // X related contribution
5214  - dot(mu_z_ij("i,j"), D_f12_ij("i,j"))
5215  // B related contribution
5216  + dot(mu_z_ab("a,b"), D_f12_ab("a,b"))
5217  + dot(mu_z_apbp("a',b'"), D_f12_apbp("a',b'"))
5218  + dot(mu_z_apb("a',b"), D_f12_apb("a',b")) * 2.0
5219  ;
5220  mu_z_f12or = dot(mu_z_am("a,m"), Dbn_f12("a,m"));
5221  if (nocc != naocc) {
5222  mu_z_f12or += dot(mu_z_ijp("i,j'"), Diip_f12("i,j'"));
5223  }
5224  }
5225 
5226  // F12 contribution to quadrupoles
5227  if (compute_quadrupole) {
5228  TArray2 q_xx_apbp = xy("<a'|q_xx|b'>");
5229  TArray2 q_yy_apbp = xy("<a'|q_yy|b'>");
5230  TArray2 q_zz_apbp = xy("<a'|q_zz|b'>");
5231 
5232  TArray2 Qxx_apbp, Qyy_apbp, Qzz_apbp;
5233  Qxx_apbp("a',b'") = q_xx_apbp("a',b'") - (q_zz_apbp("a',b'") + q_yy_apbp("a',b'")) * 0.5;
5234  Qyy_apbp("a',b'") = q_yy_apbp("a',b'") - (q_zz_apbp("a',b'") + q_xx_apbp("a',b'")) * 0.5;
5235  Qzz_apbp("a',b'") = q_zz_apbp("a',b'") - (q_xx_apbp("a',b'") + q_yy_apbp("a',b'")) * 0.5;
5236 
5237  q_xx_f12 = - dot(Qxx_ij("i,j"), D_f12_ij("i,j"))
5238  + dot(Qxx_ab("a,b"), D_f12_ab("a,b"))
5239  + dot(Qxx_apbp("a',b'"), D_f12_apbp("a',b'"))
5240  + dot(Qxx_apb("a',b"), D_f12_apb("a',b")) * 2.0
5241  ;
5242  q_yy_f12 = - dot(Qyy_ij("i,j"), D_f12_ij("i,j"))
5243  + dot(Qyy_ab("a,b"), D_f12_ab("a,b"))
5244  + dot(Qyy_apbp("a',b'"), D_f12_apbp("a',b'"))
5245  + dot(Qyy_apb("a',b"), D_f12_apb("a',b")) * 2.0
5246  ;
5247  q_zz_f12 = - dot(Qzz_ij("i,j"), D_f12_ij("i,j"))
5248  + dot(Qzz_ab("a,b"), D_f12_ab("a,b"))
5249  + dot(Qzz_apbp("a',b'"), D_f12_apbp("a',b'"))
5250  + dot(Qzz_apb("a',b"), D_f12_apb("a',b")) * 2.0
5251  ;
5252 // // x2, y2, z2 components to quadrupole moment
5253 // q_xx_f12 = - dot(q_xx_ij("i,j"), D_f12_ij("i,j"))
5254 // + dot(q_xx_ab("a,b"), D_f12_ab("a,b"))
5255 // + dot(q_xx_apbp("a',b'"), D_f12_apbp("a',b'"))
5256 // + dot(q_xx_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5257 // q_yy_f12 = - dot(q_yy_ij("i,j"), D_f12_ij("i,j"))
5258 // + dot(q_yy_ab("a,b"), D_f12_ab("a,b"))
5259 // + dot(q_yy_apbp("a',b'"), D_f12_apbp("a',b'"))
5260 // + dot(q_yy_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5261 // q_zz_f12 = - dot(q_zz_ij("i,j"), D_f12_ij("i,j"))
5262 // + dot(q_zz_ab("a,b"), D_f12_ab("a,b"))
5263 // + dot(q_zz_apbp("a',b'"), D_f12_apbp("a',b'"))
5264 // + dot(q_zz_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5265 
5266  q_xx_f12or = dot(Qxx_am("a,m"), Dbn_f12("a,m"));
5267  q_yy_f12or = dot(Qyy_am("a,m"), Dbn_f12("a,m"));
5268  q_zz_f12or = dot(Qzz_am("a,m"), Dbn_f12("a,m"));
5269 // // x2, y2, z2 components to quadrupole moment
5270 // q_xx_f12or = dot(q_xx_am("a,m"), Dbn_f12("a,m"));
5271 // q_yy_f12or = dot(q_yy_am("a,m"), Dbn_f12("a,m"));
5272 // q_zz_f12or = dot(q_zz_am("a,m"), Dbn_f12("a,m"));
5273 
5274  if (nocc != naocc) {
5275  q_xx_f12or += dot(Qxx_ijp("i,j'"), Diip_f12("i,j'"));
5276  q_yy_f12or += dot(Qyy_ijp("i,j'"), Diip_f12("i,j'"));
5277  q_zz_f12or += dot(Qzz_ijp("i,j'"), Diip_f12("i,j'"));
5278  }
5279  }
5280 
5281  if (compute_EFG) {
5282  TArray2 v_xx_apbp = xy("<a'|ddphi_xx|b'>");
5283  TArray2 v_yy_apbp = xy("<a'|ddphi_yy|b'>");
5284  TArray2 v_zz_apbp = xy("<a'|ddphi_zz|b'>");
5285  TArray2 v_xy_apbp = xy("<a'|ddphi_xy|b'>");
5286  TArray2 v_xz_apbp = xy("<a'|ddphi_xz|b'>");
5287  TArray2 v_yz_apbp = xy("<a'|ddphi_yz|b'>");
5288 
5289  // F12 contribution to electric gradient
5290  const double v_xx_f12 = - dot(v_xx_ij("i,j"), D_f12_ij("i,j"))
5291  + dot(v_xx_ab("a,b"), D_f12_ab("a,b"))
5292  + dot(v_xx_apbp("a',b'"), D_f12_apbp("a',b'"))
5293  + dot(v_xx_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5294  const double v_yy_f12 = - dot(v_yy_ij("i,j"), D_f12_ij("i,j"))
5295  + dot(v_yy_ab("a,b"), D_f12_ab("a,b"))
5296  + dot(v_yy_apbp("a',b'"), D_f12_apbp("a',b'"))
5297  + dot(v_yy_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5298  const double v_zz_f12 = - dot(v_zz_ij("i,j"), D_f12_ij("i,j"))
5299  + dot(v_zz_ab("a,b"), D_f12_ab("a,b"))
5300  + dot(v_zz_apbp("a',b'"), D_f12_apbp("a',b'"))
5301  + dot(v_zz_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5302  const double v_xy_f12 = - dot(v_xy_ij("i,j"), D_f12_ij("i,j"))
5303  + dot(v_xy_ab("a,b"), D_f12_ab("a,b"))
5304  + dot(v_xy_apbp("a',b'"), D_f12_apbp("a',b'"))
5305  + dot(v_xy_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5306  const double v_xz_f12 = - dot(v_xz_ij("i,j"), D_f12_ij("i,j"))
5307  + dot(v_xz_ab("a,b"), D_f12_ab("a,b"))
5308  + dot(v_xz_apbp("a',b'"), D_f12_apbp("a',b'"))
5309  + dot(v_xz_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5310  const double v_yz_f12 = - dot(v_yz_ij("i,j"), D_f12_ij("i,j"))
5311  + dot(v_yz_ab("a,b"), D_f12_ab("a,b"))
5312  + dot(v_yz_apbp("a',b'"), D_f12_apbp("a',b'"))
5313  + dot(v_yz_apb("a',b"), D_f12_apb("a',b")) * 2.0;
5314 
5315  const double v_xx_f12or = dot(v_xx_am("a,m"), Dbn_f12("a,m"));
5316  const double v_yy_f12or = dot(v_yy_am("a,m"), Dbn_f12("a,m"));
5317  const double v_zz_f12or = dot(v_zz_am("a,m"), Dbn_f12("a,m"));
5318  const double v_xy_f12or = dot(v_xy_am("a,m"), Dbn_f12("a,m"));
5319  const double v_xz_f12or = dot(v_xz_am("a,m"), Dbn_f12("a,m"));
5320  const double v_yz_f12or = dot(v_yz_am("a,m"), Dbn_f12("a,m"));
5321 
5322  std::cout << indent << "electric gradient (F12)" << std::endl
5323  << indent << "v_xx (F12) = " << scprintf("%12.10f", v_xx_f12 * 2.0)
5324  << indent << " v_yy (F12) = " << scprintf("%12.10f", v_yy_f12 * 2.0)
5325  << indent << " v_zz (F12) = " << scprintf("%12.10f", v_zz_f12 * 2.0)
5326  << std::endl
5327  << indent << "v_xy (F12) = " << scprintf("%12.10f", v_xy_f12 * 2.0)
5328  << indent << " v_xz (F12) = " << scprintf("%12.10f", v_xz_f12 * 2.0)
5329  << indent << " v_yz (F12) = " << scprintf("%12.10f", v_yz_f12 * 2.0)
5330  << std::endl;
5331  std::cout << indent << "electric gradient (F12 orbital response)" << std::endl
5332  << indent << "v_xx (F12 or) = " << scprintf("%12.10f", v_xx_f12or * 2.0)
5333  << indent << " v_yy (F12 or) = " << scprintf("%12.10f", v_yy_f12or * 2.0)
5334  << indent << " v_zz (F12 or) = " << scprintf("%12.10f", v_zz_f12or * 2.0)
5335  << std::endl
5336  << indent << "v_xy (F12 or) = " << scprintf("%12.10f", v_xy_f12or * 2.0)
5337  << indent << " v_xz (F12 or) = " << scprintf("%12.10f", v_xz_f12or * 2.0)
5338  << indent << " v_yz (F12 or) = " << scprintf("%12.10f", v_yz_f12or * 2.0)
5339  << std::endl << std::endl;
5340  }
5341  }
5342 #endif
5343 
5344  ExEnv::out0() << std::endl << indent << "Start CCSD computation" << std::endl;
5345  double mu_z_ccsd = 0.0, mu_z_ccsdor = 0.0;
5346  double q_xx_ccsd = 0.0, q_yy_ccsd = 0.0, q_zz_ccsd = 0.0;
5347  double q_xx_ccsdor = 0.0, q_yy_ccsdor = 0.0, q_zz_ccsdor = 0.0;
5348 
5349  TArray2 mu_z_ai;
5350  TArray2 Qxx_ai, Qyy_ai, Qzz_ai, Qxy_ai, Qxz_ai, Qyz_ai;
5351 #if 0
5352  // compute CC2 amplitudes using Schaefer's formula
5353  TArray2 T1_cc2, L1_cc2;
5354  TArray4 T2_cc2, L2_cc2;
5355 
5356  ExEnv::out0() << std::endl << indent << "Compute CC2 T amplitudes " << std::endl;
5357  compute_T_cc2(T1_cc2,T2_cc2);
5358 
5359  ExEnv::out0() << std::endl << indent << "Compute CC2 lambda amplitudes " << std::endl;
5360  compute_lambda_cc2(T1_cc2, T2_cc2, L1_cc2, L2_cc2);
5361 
5362  // compute CC2 density from amplitudes
5363  TArray2 Dij_cc2, Dab_cc2, Dia_cc2, Dai_cc2;
5364  ExEnv::out0() << indent << "Compute CC2 density from amplitudes" << std::endl;
5365  compute_cc2_1rdm_amp(T1_cc2, T2_cc2, L1_cc2, L2_cc2,
5366  Dij_cc2, Dab_cc2, Dia_cc2, Dai_cc2);
5367 #endif
5368 
5369 #if 0
5370  // compute CC2 lambda amplitudes using Gauss's formula
5371  TArray2 L1_cc2_2;
5372  TArray4 L2_cc2_2;
5373  ExEnv::out0() << indent << "Using Gauss's formula" << std::endl;
5374  compute_lambda_cc2_2(T1_cc2, T2_cc2, L1_cc2_2, L2_cc2_2);
5375 #endif
5376 
5377  ExEnv::out0() << indent << "Compute CCSD T amplitudes " << std::endl;
5378  TArray2 T1;
5379  TArray4 T2;
5380  compute_T_ccsd(T1, T2, "CCSD");
5381 
5382  ExEnv::out0() << std::endl << indent << "Compute CCSD L amplitudes " << std::endl;
5383  TArray2 L1;
5384  TArray4 L2;
5385  compute_lambda_ccsd(T1, T2, L1, L2, "CCSD"); // do not include F12 contributions
5386 
5387 #if INCLUDE_CCSD_CONTRI
5388  {
5389  // compute CCSD density from amplitudes
5390  TArray2 Dij_ccsd, Dab_ccsd, Dia_ccsd, Dai_ccsd;
5391  ExEnv::out0() << std::endl << indent
5392  << "Compute CCSD density from amplitudes" << std::endl;
5393  compute_ccsd_1rdm_amp(T1, T2, L1, L2,
5394  Dij_ccsd, Dab_ccsd, Dia_ccsd, Dai_ccsd);
5395 
5396  ExEnv::out0() << std::endl << indent << "Compute CCSD Xam and Xai" << std::endl;
5397  TArray2 Xam_ccsd_nfzc, Xiip_ccsd;
5398  compute_Xam_ccsd(T1, T2, L1, L2, Xam_ccsd_nfzc, Xiip_ccsd);
5399 
5400  TArray2 Diip_or_ccsd, Xam_ccsd;
5401  if (nocc != naocc) {
5402  ExEnv::out0() << std::endl << indent
5403  << "Include frozen-core CCSD contributions" << std::endl;
5404  Diip_or_ccsd("i,i'") = Xiip_ccsd("i,i'") * Delta_ijp_F("i,i'");
5405 
5406  TArray2 Xam_Diip_ccsd;
5407  Xam_Diip_ccsd("a,m") = A_ijpam("i,i',a,m") * Diip_or_ccsd("i,i'");
5408  Xam_ccsd("a,m") = Xam_ccsd_nfzc("a,m") - Xam_Diip_ccsd("a,m");
5409 
5410  // test code: print out frozen-core contribution to Ima
5411 // TArray2 I_ma_fzc;
5412 // I_ma_fzc("a,m") = - Xam_Diip_ccsd("a,m") * 0.5;
5413 // std::cout << "Ima frozen-core part: " << std::endl << I_ma_fzc << std::endl;
5414  } else {
5415  Xam_ccsd("a,m") = Xam_ccsd_nfzc("a,m");
5416  }
5417 
5418  // solve the Z-vector equation for CCSD
5419  TArray2 Dbn_ccsd(Xam_ccsd.world(), Xam_ccsd.trange());
5420  auto resnorm_ccsd = cg_solver2(Orbital_relaxation_Abnam,
5421  Xam_ccsd,
5422  Dbn_ccsd,
5423  preconditioner,
5424  conv_target);
5425 
5426  if (compute_dipole) {
5427  mu_z_ai = xy("<a|mu_z|i>");
5428  mu_z_ccsd = dot(mu_z_ij("i,j"), Dij_ccsd("i,j"))
5429  + dot(mu_z_ab("a,b"), Dab_ccsd("a,b"))
5430  + dot(mu_z_ai("a,i"), Dai_ccsd("a,i"))
5431  + dot(mu_z_ai("a,i"), Dia_ccsd("i,a"))
5432  ;
5433 
5434  mu_z_ccsdor = dot(mu_z_am("a,m"), Dbn_ccsd("a,m"));
5435  if (nocc != naocc) {
5436  mu_z_ccsdor += dot(mu_z_ijp("i,i'"), Diip_or_ccsd("i,i'"));
5437  }
5438 
5439 // std::cout << std::endl << indent
5440 // << "mu_z (CCSD) = " << scprintf("%15.12f", - mu_z_ccsd * 2.0)
5441 // << std::endl << indent
5442 // << "mu_z (CCSD orbital response) = " << scprintf("%15.12f", - mu_z_ccsdor * 2.0)
5443 // << std::endl;
5444  }
5445 
5446  if (compute_quadrupole) {
5447  TArray2 q_xx_ai = xy("<a|q_xx|i>");
5448  TArray2 q_yy_ai = xy("<a|q_yy|i>");
5449  TArray2 q_zz_ai = xy("<a|q_zz|i>");
5450  Qxx_ai("a,i") = q_xx_ai("a,i") - (q_zz_ai("a,i") + q_yy_ai("a,i")) * 0.5;
5451  Qyy_ai("a,i") = q_yy_ai("a,i") - (q_zz_ai("a,i") + q_xx_ai("a,i")) * 0.5;
5452  Qzz_ai("a,i") = q_zz_ai("a,i") - (q_xx_ai("a,i") + q_yy_ai("a,i")) * 0.5;
5453 
5454  q_xx_ccsd = dot(Qxx_ij("i,j"), Dij_ccsd("i,j"))
5455  + dot(Qxx_ab("a,b"), Dab_ccsd("a,b"))
5456  + dot(Qxx_ai("a,i"), Dai_ccsd("a,i"))
5457  + dot(Qxx_ai("a,i"), Dia_ccsd("i,a"))
5458  ;
5459  q_yy_ccsd = dot(Qyy_ij("i,j"), Dij_ccsd("i,j"))
5460  + dot(Qyy_ab("a,b"), Dab_ccsd("a,b"))
5461  + dot(Qyy_ai("a,i"), Dai_ccsd("a,i"))
5462  + dot(Qyy_ai("a,i"), Dia_ccsd("i,a"))
5463  ;
5464  q_zz_ccsd = dot(Qzz_ij("i,j"), Dij_ccsd("i,j"))
5465  + dot(Qzz_ab("a,b"), Dab_ccsd("a,b"))
5466  + dot(Qzz_ai("a,i"), Dai_ccsd("a,i"))
5467  + dot(Qzz_ai("a,i"), Dia_ccsd("i,a"))
5468  ;
5469 
5470  q_xx_ccsdor = dot(Qxx_am("a,m"), Dbn_ccsd("a,m"));
5471  q_yy_ccsdor = dot(Qyy_am("a,m"), Dbn_ccsd("a,m"));
5472  q_zz_ccsdor = dot(Qzz_am("a,m"), Dbn_ccsd("a,m"));
5473 
5474  if (nocc != naocc) {
5475  q_xx_ccsdor += dot(Qxx_ijp("i,j'"), Diip_or_ccsd("i,j'"));
5476  q_yy_ccsdor += dot(Qyy_ijp("i,j'"), Diip_or_ccsd("i,j'"));
5477  q_zz_ccsdor += dot(Qzz_ijp("i,j'"), Diip_or_ccsd("i,j'"));
5478  }
5479  }
5480  }
5481 #endif
5482 
5483  // CC F12 coupling contribution to Xam
5484  double mu_z_Cccsdf12 = 0.0, mu_z_Cccsdf12or = 0.0;
5485  double q_xx_Cccsdf12 = 0.0, q_yy_Cccsdf12 = 0.0, q_zz_Cccsdf12 = 0.0;
5486  double q_xx_Cccsdf12or = 0.0, q_yy_Cccsdf12or = 0.0, q_zz_Cccsdf12or = 0.0;
5487 #if INCLUDE_CCSDF12C_CONTRI
5488  {
5489  // resolve CCSD lambda amplitudes, density, and Xam in the framework of CCSD(2)_F12
5490  ExEnv::out0() << std::endl << indent << "Compute CCSD(2)_F12 L amplitudes " << std::endl;
5491  TArray2 L1_f12;
5492  TArray4 L2_f12;
5493  compute_lambda_ccsd(T1, T2, L1_f12, L2_f12, "F12");
5494 
5495  // compute CCSD density from amplitudes
5496  TArray2 Dij_ccsd_f12, Dab_ccsd_f12, Dia_ccsd_f12, Dai_ccsd_f12;
5497  ExEnv::out0() << std::endl << indent
5498  << "Compute CCSD density from amplitudes in CCSD(2)_F12" << std::endl;
5499  compute_ccsd_1rdm_amp(T1, T2, L1_f12, L2_f12,
5500  Dij_ccsd_f12, Dab_ccsd_f12, Dia_ccsd_f12, Dai_ccsd_f12);
5501 
5502  ExEnv::out0() << std::endl << indent
5503  << "Compute CCSD Xam and Xai in CCSD(2)_F12" << std::endl;
5504  TArray2 Xam_ccsd_f12_nfzc, Xiip_ccsd_f12;
5505  compute_Xam_ccsd(T1, T2, L1_f12, L2_f12, Xam_ccsd_f12_nfzc, Xiip_ccsd_f12);
5506  //compute_Xam_ccsd(T1, T2, L1, L2_f12, Xam_ccsd_f12_nfzc, Xiip_ccsd_f12);
5507 
5508  TArray2 Diip_ccsd_f12, Xam_ccsd_f12;
5509  if (nocc != naocc) {
5510  Diip_ccsd_f12("i,i'") = Xiip_ccsd_f12("i,i'") * Delta_ijp_F("i,i'");
5511  Xam_ccsd_f12("a,m") = Xam_ccsd_f12_nfzc("a,m") - A_ijpam("i,i',a,m") * Diip_ccsd_f12("i,i'");
5512  } else {
5513  Xam_ccsd_f12("a,m") = Xam_ccsd_f12_nfzc("a,m");
5514  }
5515 
5516  TArray2 Dbn_ccsd_f12(Xam_ccsd_f12.world(), Xam_ccsd_f12.trange());
5517  auto resnorm_ccsd_f12 = cg_solver2(Orbital_relaxation_Abnam,
5518  Xam_ccsd_f12,
5519  Dbn_ccsd_f12,
5520  preconditioner,
5521  1e-12);
5522 
5523  ExEnv::out0() << std::endl << indent
5524  << "Compute CCSD F12 coupling contributions" << std::endl;
5525  // CC CT2
5526  // 1/2 R^kl_a'c T2^bc_kl
5527  TArray2 RT2_aPb;
5528  RT2_aPb("a',b") = _4("<a' c|r|k l>")
5529  * (R_C1 * T2("b,c,k,l") + R_C2 * T2("c,b,k,l"));
5530 
5531  TArray2 Xam_CT2_cc = Xam_CT2_ccsd(C_0, C_1, T2, RT2_aPb);
5532  // VT1 & VT2 coupling contribution to F12 Xam
5533  TArray2 Xam_VT_cc = Xam_VT_ccsd(C_0, C_1, T1, T2);
5534  TArray2 Xam_CVT_cc_nfzc;
5535  Xam_CVT_cc_nfzc("a,m") = Xam_CT2_cc("a,m") + Xam_VT_cc("a,m");
5536 
5537  // frozen-core contribution
5538  TArray2 Diip_CVT_cc, Xam_CVT_cc;
5539  if (nocc != naocc) {
5540  ExEnv::out0() << std::endl << indent
5541  << "Include frozen-core contributions for CCSD F12 coupling" << std::endl;
5542  TArray2 Xiip_couling = Xiip_CVT(C_0, C_1, T1, T2);
5543  Diip_CVT_cc("i,i'") = - Xiip_couling("i,i'") * Delta_ijp_F("i,i'");
5544 
5545  TArray2 Xam_Diip_CVT;
5546  Xam_Diip_CVT("a,m") = - A_ijpam("i,j',a,m") * Diip_CVT_cc("i,j'");
5547 
5548  Xam_CVT_cc("a,m") = Xam_CVT_cc_nfzc("a,m") + Xam_Diip_CVT("a,m");
5549  } else {
5550  Xam_CVT_cc("a,m") = Xam_CVT_cc_nfzc("a,m");
5551  }
5552 
5553  TArray2 Dbn_CVT_cc(Xam_CVT_cc.world(), Xam_CVT_cc.trange());
5554  auto resnorm_CVT_cc = cg_solver2(Orbital_relaxation_Abnam,
5555  Xam_CVT_cc,
5556  Dbn_CVT_cc,
5557  preconditioner,
5558  conv_target);
5559 
5560  if (compute_dipole) {
5561  double mu_z_ccsd_f12 = dot(mu_z_ij("i,j"), Dij_ccsd_f12("i,j"))
5562  + dot(mu_z_ab("a,b"), Dab_ccsd_f12("a,b"))
5563  + dot(mu_z_ai("a,i"), Dai_ccsd_f12("a,i"))
5564  + dot(mu_z_ai("a,i"), Dia_ccsd_f12("i,a"))
5565  // F12 coupling density contribution
5566  + dot(mu_z_apb("a',b"), RT2_aPb("a',b")) * 2.0
5567  ;
5568 
5569  double mu_z_ccsdor_f12 = dot(mu_z_am("a,m"), Dbn_ccsd_f12("a,m"))
5570  + dot(mu_z_am("a,m"), Dbn_CVT_cc("a,m"));
5571 
5572  if (nocc != naocc) {
5573  mu_z_ccsdor_f12 += dot(mu_z_ijp("i,j'"), Diip_ccsd_f12("i,j'"))
5574  + dot(mu_z_ijp("i,j'"), Diip_CVT_cc("i,j'"));
5575  }
5576 
5577  mu_z_Cccsdf12 = mu_z_ccsd_f12 - mu_z_ccsd;
5578  mu_z_Cccsdf12or = mu_z_ccsdor_f12 - mu_z_ccsdor;
5579  }
5580 
5581  if (compute_quadrupole) {
5582  double q_xx_ccsd_f12 = dot(Qxx_ij("i,j"), Dij_ccsd_f12("i,j"))
5583  + dot(Qxx_ab("a,b"), Dab_ccsd_f12("a,b"))
5584  + dot(Qxx_ai("a,i"), Dai_ccsd_f12("a,i"))
5585  + dot(Qxx_ai("a,i"), Dia_ccsd_f12("i,a"))
5586  + dot(Qxx_apb("a',b"), RT2_aPb("a',b")) * 2.0
5587  ;
5588  double q_yy_ccsd_f12 = dot(Qyy_ij("i,j"), Dij_ccsd_f12("i,j"))
5589  + dot(Qyy_ab("a,b"), Dab_ccsd_f12("a,b"))
5590  + dot(Qyy_ai("a,i"), Dai_ccsd_f12("a,i"))
5591  + dot(Qyy_ai("a,i"), Dia_ccsd_f12("i,a"))
5592  + dot(Qyy_apb("a',b"), RT2_aPb("a',b")) * 2.0
5593  ;
5594  double q_zz_ccsd_f12 = dot(Qzz_ij("i,j"), Dij_ccsd_f12("i,j"))
5595  + dot(Qzz_ab("a,b"), Dab_ccsd_f12("a,b"))
5596  + dot(Qzz_ai("a,i"), Dai_ccsd_f12("a,i"))
5597  + dot(Qzz_ai("a,i"), Dia_ccsd_f12("i,a"))
5598  + dot(Qzz_apb("a',b"), RT2_aPb("a',b")) * 2.0
5599  ;
5600 
5601  double q_xx_ccsdor_f12 = dot(Qxx_am("a,m"), Dbn_ccsd_f12("a,m"))
5602  + dot(Qxx_am("a,m"), Dbn_CVT_cc("a,m"));
5603  double q_yy_ccsdor_f12 = dot(Qyy_am("a,m"), Dbn_ccsd_f12("a,m"))
5604  + dot(Qyy_am("a,m"), Dbn_CVT_cc("a,m"));
5605  double q_zz_ccsdor_f12 = dot(Qzz_am("a,m"), Dbn_ccsd_f12("a,m"))
5606  + dot(Qzz_am("a,m"), Dbn_CVT_cc("a,m"));
5607 
5608  if (nocc != naocc) {
5609  q_xx_ccsdor_f12 += dot(Qxx_ijp("i,j'"), Diip_ccsd_f12("i,j'"))
5610  + dot(Qxx_ijp("i,j'"), Diip_CVT_cc("i,j'"));
5611  q_yy_ccsdor_f12 += dot(Qyy_ijp("i,j'"), Diip_ccsd_f12("i,j'"))
5612  + dot(Qyy_ijp("i,j'"), Diip_CVT_cc("i,j'"));
5613  q_zz_ccsdor_f12 += dot(Qzz_ijp("i,j'"), Diip_ccsd_f12("i,j'"))
5614  + dot(Qzz_ijp("i,j'"), Diip_CVT_cc("i,j'"));
5615  }
5616 
5617  q_xx_Cccsdf12 = q_xx_ccsd_f12 - q_xx_ccsd;
5618  q_yy_Cccsdf12 = q_yy_ccsd_f12 - q_yy_ccsd;
5619  q_zz_Cccsdf12 = q_zz_ccsd_f12 - q_zz_ccsd;
5620  q_xx_Cccsdf12or = q_xx_ccsdor_f12 - q_xx_ccsdor;
5621  q_yy_Cccsdf12or = q_yy_ccsdor_f12 - q_yy_ccsdor;
5622  q_zz_Cccsdf12or = q_zz_ccsdor_f12 - q_zz_ccsdor;
5623  }
5624 
5625  }
5626 #endif
5627 
5628  // print results
5629  if (compute_dipole) {
5630  std::cout << std::endl << indent << "Dipole moment "
5631  << std::endl << indent
5632  << "mu_z (HF=SCF+N) = " << scprintf("%15.12f", mu_z_n - mu_z_scf * 2.0)
5633  //electron charge = -1, hence the minus
5634  << std::endl << std::endl << indent
5635  << "mu_z (E2) = " << scprintf("%15.12f", - mu_z_e2 * 2.0)
5636  << std::endl << indent
5637  << "mu_z (E2 orbital response) = " << scprintf("%15.12f", - mu_z_e2or * 2.0)
5638  << std::endl << std::endl << indent
5639  << "mu_z (MP2) = " << scprintf("%15.12f", - mu_z_mp2 * 2.0)
5640  << std::endl << indent
5641  << "mu_z (MP2 orbital response) = "<< scprintf("%15.12f", - mu_z_mp2or * 2.0)
5642  << std::endl << std::endl << indent
5643  << "mu_z (MP2F12 coupling) = " << scprintf("%15.12f", - mu_z_mp2f12C * 2.0)
5644  << std::endl << indent
5645  << "mu_z (MP2-F12 coupling orbital response) = " << scprintf("%15.12f", - mu_z_mp2f12Cor * 4.0)
5646  << std::endl << std::endl << indent
5647  << "mu_z (F12) = " << scprintf("%15.12f",- mu_z_f12 * 2.0)
5648  << std::endl << indent
5649  << "mu_z (F12 orbital response) = " << scprintf("%15.12f", - mu_z_f12or * 2.0)
5650  << std::endl << std::endl << indent
5651  << "mu_z (CCSD) = " << scprintf("%15.12f", - mu_z_ccsd * 2.0)
5652  << std::endl << indent
5653  << "mu_z (CCSD orbital response) = " << scprintf("%15.12f", - mu_z_ccsdor * 2.0)
5654  << std::endl << std::endl << indent
5655  << "mu_z (CCSDF12 coupling) = " << scprintf("%15.12f", - mu_z_Cccsdf12 * 2.0)
5656  << std::endl << indent
5657  << "mu_z (CCSDF12 coupling orbital response) = " << scprintf("%15.12f", - mu_z_Cccsdf12or * 2.0)
5658  << std::endl;
5659  }
5660 
5661  if (compute_quadrupole) {
5662  std::cout << std::endl << indent
5663  << "Traceless quadrupole moment"
5664  << std::endl << indent
5665  << "q_xx (HF) = " << scprintf("%12.10f", q_xx_n - q_xx_scf * 2.0)
5666  << " q_yy (HF) = " << scprintf("%12.10f", q_yy_n - q_yy_scf * 2.0)
5667  << " q_zz (HF) = " << scprintf("%12.10f", q_zz_n - q_zz_scf * 2.0)
5668  << std::endl << indent
5669  << "q_xy (HF) = " << scprintf("%12.10f", q_xy_n - q_xy_scf * 2.0)
5670  << " q_xz (HF) = " << scprintf("%12.10f", q_xz_n - q_xz_scf * 2.0)
5671  << " q_yz (HF) = " << scprintf("%12.10f", q_yz_n - q_yz_scf * 2.0)
5672  << std::endl;
5673 
5674  std::cout << std::endl << indent
5675  << "q_xx (E2) = " << scprintf("%12.10f", - q_xx_e2 * 2.0)
5676  << " q_yy (E2) = " << scprintf("%12.10f", - q_yy_e2 * 2.0)
5677  << " q_zz (E2) = " << scprintf("%12.10f", - q_zz_e2 * 2.0)
5678  << std::endl << indent
5679  << "q_xx (E2 or) = " << scprintf("%12.10f", - q_xx_e2or * 2.0)
5680  << " q_yy (E2 or) = " << scprintf("%12.10f", - q_yy_e2or * 2.0)
5681  << " q_zz (E2 or) = " << scprintf("%12.10f", - q_zz_e2or * 2.0)
5682  << std::endl;
5683 
5684  std::cout << std::endl << indent
5685  << "q_xx (MP2) = " << scprintf("%12.10f", - q_xx_mp2 * 2.0)
5686  << " q_yy (MP2) = " << scprintf("%12.10f", - q_yy_mp2 * 2.0)
5687  << " q_zz (MP2) = " << scprintf("%12.10f", - q_zz_mp2 * 2.0)
5688  << std::endl << indent
5689  << "q_xx (MP2 or) = " << scprintf("%12.10f", - q_xx_mp2or * 2.0)
5690  << " q_yy (MP2 or) = " << scprintf("%12.10f", - q_yy_mp2or * 2.0)
5691  << " q_zz (MP2 or) = " << scprintf("%12.10f", - q_zz_mp2or * 2.0)
5692  << std::endl;
5693 
5694  std::cout << std::endl << indent
5695  << "q_xx (MP2F12 C) = " << scprintf("%12.10f", - q_xx_mp2f12C * 2.0)
5696  << " q_yy (MP2F12 C) = " << scprintf("%12.10f", - q_yy_mp2f12C * 2.0)
5697  << " q_zz (MP2F12 C) = " << scprintf("%12.10f", - q_zz_mp2f12C * 2.0)
5698  << std::endl << indent
5699  << "q_xx (MP2F12 C or) = " << scprintf("%12.10f", - q_xx_mp2f12Cor * 2.0)
5700  << " q_yy (MP2F12 C or) = " << scprintf("%12.10f", - q_yy_mp2f12Cor * 2.0)
5701  << " q_zz (MP2F12 C or) = " << scprintf("%12.10f", - q_zz_mp2f12Cor * 2.0)
5702  << std::endl;
5703 
5704  std::cout << std::endl << indent
5705  << "q_xx (F12) = " << scprintf("%12.10f", - q_xx_f12 * 2.0)
5706  << " q_yy (F12) = " << scprintf("%12.10f", - q_yy_f12 * 2.0)
5707  << " q_zz (F12) = " << scprintf("%12.10f", - q_zz_f12 * 2.0)
5708  << std::endl << indent
5709  << "q_xx (F12 or) = " << scprintf("%12.10f", - q_xx_f12or * 2.0)
5710  << " q_yy (F12 or) = " << scprintf("%12.10f", - q_yy_f12or * 2.0)
5711  << " q_zz (F12 or) = " << scprintf("%12.10f", - q_zz_f12or * 2.0)
5712  << std::endl;
5713 
5714  std::cout << std::endl << indent
5715  << "q_xx (CCSD) = " << scprintf("%12.10f", - q_xx_ccsd * 2.0)
5716  << " q_yy (CCSD) = " << scprintf("%12.10f", - q_yy_ccsd * 2.0)
5717  << " q_zz (CCSD) = " << scprintf("%12.10f", - q_zz_ccsd * 2.0)
5718  << std::endl << indent
5719  << "q_xx (CCSD or) = " << scprintf("%12.10f", - q_xx_ccsdor * 2.0)
5720  << " q_yy (CCSD or) = " << scprintf("%12.10f", - q_yy_ccsdor * 2.0)
5721  << " q_zz (CCSD or) = " << scprintf("%12.10f", - q_zz_ccsdor * 2.0)
5722  << std::endl;
5723 
5724  std::cout << std::endl << indent
5725  << "q_xx (CCSDF12 C) = " << scprintf("%12.10f", - q_xx_Cccsdf12 * 2.0)
5726  << " q_yy (CCSDF12 C) = " << scprintf("%12.10f", - q_yy_Cccsdf12 * 2.0)
5727  << " q_zz (CCSDF12 C) = " << scprintf("%12.10f", - q_zz_Cccsdf12 * 2.0)
5728  << std::endl << indent
5729  << "q_xx (CCSDF12 C or) = " << scprintf("%12.10f", - q_xx_Cccsdf12or * 2.0)
5730  << " q_yy (CCSDF12 C or) = " << scprintf("%12.10f", - q_yy_Cccsdf12or * 2.0)
5731  << " q_zz (CCSDF12 C or) = " << scprintf("%12.10f", - q_zz_Cccsdf12or * 2.0)
5732  << std::endl << std::endl;
5733  }
5734  }
5735 
5736  // F12b method
5737  // Xam contribution of CT2 part resulted from CCSD F12 coupling
5738  template <typename T>
5740  SingleReference_R12Intermediates<T>::Xam_CT2L2_f12b(const double C_0, const double C_1,
5741  const TArray4& T2, const TArray2& RT2_aPb,
5742  const TArray4& L2, const TArray2& RL2_aPb) {
5743  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
5744  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
5745 
5746  TArray4d g_abmaP = ijxy("<a b|g|m a'>");
5747  TArray2 Xam_CT2, Xai_CT2;
5748  Xam_CT2("a,m") = // + 1/2 F^a'_m R^kl_a'b (T2^ab_kl + L2^ab_kl)
5749  // + 1/2 F^a'_b R^kl_ma' (T2^ab_kl + L2^ab_kl)
5750  ( R_C1 * T2("a,b,k,l") + R_C2 * T2("b,a,k,l")
5751  + R_C1 * L2("a,b,k,l") + R_C2 * L2("b,a,k,l")
5752  ) * (_4("<k l|r|m_F(a') b>") + _4("<k l|r|m b_F(a')>"))
5753 
5754  // - g^aa'_mb 1/2 R^kl_a'c (T2^bc_kl + L2^bc_kl)
5755  // - g^ab_ma' 1/2 R^kl_a'c (T2^bc_kl + L2^bc_kl)
5756  - ( 2.0 * _4("<a a'|g|m b>") - _4("<a a'|g|b m>")
5757  + 2.0 * g_abmaP("a,b,m,a'") - g_abmaP("b,a,m,a'")
5758  ) * (RT2_aPb("a',b") + RL2_aPb("a',b")
5759  )
5760  ;
5761  Xai_CT2("a,i") = // - F^a'_b R^al_a'c (T2^bc_il + L2^bc_il)
5762  - _4("<a l|r|b_F(a') c>")
5763  * ( R_C1 * T2("b,c,i,l") + R_C2 * T2("b,c,l,i")
5764  + R_C1 * L2("b,c,i,l") + R_C2 * L2("b,c,l,i")
5765  )
5766  - _4("<a l|r|c b_F(a')>")
5767  * ( R_C1 * T2("c,b,i,l") + R_C2 * T2("c,b,l,i")
5768  + R_C1 * L2("c,b,i,l") + R_C2 * L2("c,b,l,i")
5769  )
5770  ;
5771 
5772  return XaiAddToXam(Xam_CT2, Xai_CT2);
5773  }
5774 
5775  // F12b method
5776  // Xam contribution of VT(T1&T2) part resulted from CCSD F12 coupling
5777  template <typename T>
5779  SingleReference_R12Intermediates<T>::Xam_VTL_f12b(const double C_0, const double C_1,
5780  const TArray2& T1, const TArray4& T2,
5781  const TArray2& L1, const TArray4& L2) {
5782 
5783  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
5784  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
5785 
5786  const char* i = "i";
5787  const char* j = "j";
5788  const char* k = "k";
5789  const char* l = "l";
5790  const char* m = "m";
5791 
5792  const char* a = "a";
5793  const char* c = "c";
5794  const char* d = "d";
5795 
5796  TArray4 V_alic = VPq_Rs(a,l,i,c, C_0, C_1);
5797  TArray4 V_ilac = VPq_Rs(i,l,a,c,C_0, C_1);
5798  TArray2 V_ac = VRk_Sk(a,c,C_0, C_1);
5799  TArray2 V_jm = VRk_Sk(j,m,C_0, C_1);
5800  TArray4d r_klmaP = ijxy("<k l|r|m a'>");
5801  TArray4d r_abPkl = ijxy("<a b'|r|k l>");
5802  TArray2 Xam_VT1L1, Xai_VT1L1;
5803  Xam_VT1L1("a,m") = // + 1/2 R^jk_A'B' g^A'B'_mk (t1^a_j + l1^a_j)
5804  (T1("a,j") + L1("a,j")) * V_jm("j,m")
5805 
5806  + ( // + R^kl_mb' g^ab'_kc (t1^c_l + l1^c_l)
5807  _4("<a b'|g|k c>")
5808  * (R_C1 * r_klmaP("k,l,m,b'") + R_C2 * r_klmaP("l,k,m,b'"))
5809  + _4("<a b'|g|c k>")
5810  * (R_C1 * r_klmaP("l,k,m,b'") + R_C2 * r_klmaP("k,l,m,b'"))
5811  // + R^kl_ab' g^mb'_kc (t1^c_l + l1^c_l)
5812  + (R_C1 * r_abPkl("a,b',k,l") + R_C2 * r_abPkl("a,b',l,k"))
5813  * _4("<k c|g|m b'>")
5814  + (R_C1 * r_abPkl("a,b',l,k") + R_C2 * r_abPkl("a,b',k,l"))
5815  * _4("<c k|g|m b'>")
5816  ) * (T1("c,l") + L1("c,l"))
5817  ;
5818  Xai_VT1L1("a,i") = // - 1/2 R^al_A'B' g^A'B'_ic (t1^c_l + l1^c_l)
5819  // - 1/2 R^il_A'B' g^A'B'_ac (t1^c_l + l1^c_l)
5820  - (V_alic("a,l,i,c") + V_ilac("i,l,a,c"))
5821  * (T1("c,l") + L1("c,l"))
5822 
5823  // - 1/2 R^ak_A'B' g^A'B'_ck (t1^c_i + l1^c_i)
5824  - V_ac("a,c") * (T1("c,i") + L1("c,i"))
5825  ;
5826  TArray2 Xam_VT1L1_tot = XaiAddToXam(Xam_VT1L1, Xai_VT1L1);
5827 
5828  TArray4 V_alcd = VPq_Rs(a,l,c,d,C_0, C_1);
5829  TArray4 V_klmd = VPq_Rs(k,l,m,d,C_0, C_1);
5830  TArray2 Xam_VT2L2, Xai_VT2L2;
5831  Xam_VT2L2("a,m") = // 1/4 R^kl_A'B' g^A'B'_md (T^ad_kl + L^ad_kl)
5832  (T2("a,d,k,l") + L2("a,d,k,l")) * V_klmd("k,l,m,d")
5833 
5834  + ( // + 1/4 R^kl_ab' g^mb'_cd (T^cd_kl + L^cd_kl)
5835  (R_C1 * r_abPkl("a,b',k,l") + R_C2 * r_abPkl("a,b',l,k"))
5836  * _4("<c d|g|m b'>")
5837  // + 1/4 R^kl_mb' g^ab'_cd (T^cd_kl + L^cd_kl)
5838  + _4("<a b'|g|c d>")
5839  * (R_C1 * r_klmaP("k,l,m,b'") + R_C2 * r_klmaP("l,k,m,b'"))
5840  ) * (T2("c,d,k,l") + L2("c,d,k,l"))
5841  ;
5842  Xai_VT2L2("a,i") = // - 1/4 R^al_A'B' g^A'B'_cd (T^cd_il + L^cd_il)
5843  - V_alcd("a,l,c,d") * (T2("c,d,i,l") + L2("c,d,i,l"))
5844  ;
5845  TArray2 Xam_VT2L2_tot = XaiAddToXam(Xam_VT2L2, Xai_VT2L2);
5846 
5847  TArray2 Xam_VTL_tot;
5848  Xam_VTL_tot("a,m") = Xam_VT1L1_tot("a,m") + Xam_VT2L2_tot("a,m");
5849  return Xam_VTL_tot;
5850  }
5851 
5852  // F12b method
5853  // Xam contribution of VT1T1 part resulted from CCSD F12 coupling
5854  // VT1T1: 1/2 [V^dagger]^cd_kl t^k_c t^l_d
5855  // (1/4 R^AB_kl g^cd_AB t^k_c t^l_d)
5856  template <typename T>
5858  SingleReference_R12Intermediates<T>::Xam_VT1T1_f12b(const double C_0, const double C_1,
5859  const TArray2& T1) {
5860  const char* k = "k";
5861  const char* l = "l";
5862  const char* m = "m";
5863 
5864  const char* a = "a";
5865  const char* c = "c";
5866  const char* d = "d";
5867 
5868  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
5869  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
5870 
5871  TArray4 Vklmd = VPq_Rs(k, l, m, d, C_0, C_1); // V^Rk_Sk = 1/2 bar{R}^Rk_A'B' bar{g}^A'B'_Sk
5872  TArray4 Valcd = VPq_Rs(a, l, c, d, C_0, C_1);
5873 
5874  // test for VPQ_RS
5875  //TArray4 V_KLMD = VPQ_RS(k, l, m, d);
5876 
5877  TArray4d rmbp_kl = ijxy("<m b'|r|k l>");
5878  TArray4d rabp_kl = ijxy("<a b'|r|k l>");
5879 
5880  TArray2 Xam_VT1T1;
5881  Xam_VT1T1("a,m") = // 1/2 R^AB_kl g^md_AB t^k_a t^l_d
5882  Vklmd("k,l,m,d")
5883  //(R_C1 * V_KLMD("k,l,m,d") + R_C2 * V_KLMD("l,k,m,d"))
5884  * T1("a,k") * T1("d,l")
5885 
5886  // 1/2 R^mb'_kl g^cd_ab' t^k_c t^l_d
5887  // 1/2 R^ab'_kl g^cd_mb' t^k_c t^l_d
5888  + ( (R_C1 * rmbp_kl("m,b',k,l") + R_C2 * rmbp_kl("m,b',l,k"))
5889  * _4("<a b'|g|c d>")
5890  + (R_C1 * rabp_kl("a,b',k,l") + R_C2 * rabp_kl("a,b',l,k"))
5891  * _4("<m b'|g|c d>")
5892  ) * T1("c,k") * T1("d,l")
5893  ;
5894  TArray2 Xai_VT1T1;
5895  Xai_VT1T1("a,i") = // - 1/2 R^AB_al g^cd_AB t^i_c t^l_d
5896  - Valcd("a,l,c,d") * T1("c,i") * T1("d,l")
5897  ;
5898 
5899  return XaiAddToXam(Xam_VT1T1, Xai_VT1T1);
5900  }
5901 
5902  template <typename T>
5904  SingleReference_R12Intermediates<T>::Xam_VT1T1_f12b_test(const double C_0, const double C_1,
5905  const TArray4& tauT1_ab) {
5906 
5907  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
5908  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
5909 
5910  const char* k = "k";
5911  const char* l = "l";
5912  const char* m = "m";
5913 
5914  const char* a = "a";
5915  const char* c = "c";
5916  const char* d = "d";
5917 
5918  TArray4d r_klmaP = ijxy("<k l|r|m a'>");
5919  TArray4d r_abPkl = ijxy("<a b'|r|k l>");
5920 
5921 
5922  TArray4 V_alcd = VPq_Rs(a,l,c,d,C_0, C_1);
5923  TArray4 V_klmd = VPq_Rs(k,l,m,d,C_0, C_1);
5924  TArray2 Xam, Xai;
5925  Xam("a,m") = //
5926  tauT1_ab("a,d,k,l") * V_klmd("k,l,m,d")
5927 
5928  + ( //
5929  (R_C1 * r_abPkl("a,b',k,l") + R_C2 * r_abPkl("a,b',l,k"))
5930  * _4("<c d|g|m b'>")
5931  //
5932  + _4("<a b'|g|c d>")
5933  * (R_C1 * r_klmaP("k,l,m,b'") + R_C2 * r_klmaP("l,k,m,b'"))
5934  ) * tauT1_ab("c,d,k,l")
5935  ;
5936  Xai("a,i") = //
5937  - V_alcd("a,l,c,d") * tauT1_ab("c,d,i,l")
5938  ;
5939 
5940  return XaiAddToXam(Xam, Xai);
5941  }
5942 
5943  // F12b method
5944  // Xam contribution of VL2T1 part resulted from CCSD F12 coupling
5945  // VL2T1: 1/2 L^cd_kl V^cd_jc t^j_d
5946  // (- 1/4 L^cd_kl R^kl_AB g^AB_cj t^j_d)
5947  template <typename T>
5949  SingleReference_R12Intermediates<T>::Xam_VL2T1_f12b(const double C_0, const double C_1,
5950  const TArray2& T1, const TArray4& L2) {
5951 
5952  const char* k = "k";
5953  const char* l = "l";
5954  const char* j = "j";
5955  const char* m = "m";
5956  const char* a = "a";
5957  const char* c = "c";
5958 
5959  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
5960  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
5961 
5962  TArray4d rmbp_kl = ijxy("<m b'|r|k l>");
5963  TArray4d rabp_kl = ijxy("<a b'|r|k l>");
5964 
5965  TArray4 V_ALCJ = VPQ_RS(a, l, c, j);
5966  TArray4 V_LACJ = VPQ_RS(l, a, c, j);
5967  TArray4 V_KLCA = VPQ_RS(k, l, c, a);
5968  TArray4 V_KLMJ = VPQ_RS(k, l, m, j);
5969 
5970  TArray2 Xam_VL2T1;
5971  Xam_VL2T1("a,m") = // - 1/2 l^ad_kl R^kl_AB g^AB_mj t^j_d
5972  - (R_C1 * V_KLMJ("k,l,m,j") + R_C2 * V_KLMJ("l,k,m,j"))
5973  * L2("a,d,k,l") * T1("d,j")
5974 
5975  // - 1/2 l^cd_kl R^kl_mb' g^ab'_cj t^j_d
5976  // - 1/2 l^cd_kl R^kl_ab' g^mb'_cj t^j_d
5977  - ( (R_C1 * rmbp_kl("m,b',k,l") + R_C2 * rmbp_kl("m,b',l,k"))
5978  * _4("<a b'|g|c j>")
5979  + (R_C1 * rmbp_kl("m,b',l,k") + R_C2 * rmbp_kl("m,b',k,l"))
5980  * _4("<a b'|g|j c>")
5981  //
5982  + (R_C1 * rabp_kl("a,b',k,l") + R_C2 * rabp_kl("a,b',l,k"))
5983  * _4("<m b'|g|c j>")
5984  + (R_C1 * rabp_kl("a,b',l,k") + R_C2 * rabp_kl("a,b',k,l"))
5985  * _4("<m b'|g|j c>")
5986  ) * L2("c,d,k,l") * T1("d,j")
5987  ;
5988  TArray2 Xai_VL2T1;
5989  Xai_VL2T1("a,i") = // + 1/2 l^cd_il R^al_AB g^AB_cj t^j_d
5990  ( R_C1 * ( V_ALCJ("a,l,c,j") * L2("c,d,i,l")
5991  + V_LACJ("l,a,c,j") * L2("c,d,l,i"))
5992  + R_C2 * ( V_ALCJ("a,l,c,j") * L2("c,d,l,i")
5993  + V_LACJ("l,a,c,j") * L2("c,d,i,l"))
5994  ) * T1("d,j")
5995 
5996  // + 1/2 l^cd_kl R^kl_AB g^AB_ca t^i_d
5997  + (R_C1 * V_KLCA("k,l,c,a") + R_C2 * V_KLCA("l,k,c,a"))
5998  * L2("c,d,k,l") * T1("d,i")
5999  ;
6000 
6001  return XaiAddToXam(Xam_VL2T1, Xai_VL2T1);
6002 
6003  }
6004 
6005  template <typename T>
6007  SingleReference_R12Intermediates<T>::Xam_VL2T1_f12b_test(const double C_0, const double C_1,
6008  const TArray2& T1, const TArray4& L2) {
6009 
6010  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
6011  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
6012 
6013  const char* j = "j";
6014  const char* k = "k";
6015  const char* l = "l";
6016  const char* m = "m";
6017 
6018  const char* a = "a";
6019  const char* c = "c";
6020 
6021  TArray4d r_klmaP = ijxy("<k l|r|m a'>");
6022  TArray4d r_abPkl = ijxy("<a b'|r|k l>");
6023 
6024  TArray4 V_alcj = VPq_Rs(a,l,c,j,C_0, C_1);
6025  TArray4 V_lacj = VPq_Rs(l,a,c,j,C_0, C_1);
6026  TArray4 V_klca = VPq_Rs(k,l,c,a,C_0, C_1);
6027  TArray4 V_klmj = VPq_Rs(k,l,m,j,C_0, C_1);
6028  TArray2 Xam, Xai;
6029  Xam("a,m") = //
6030  - L2("a,d,k,l") * V_klmj("k,l,m,j") * T1("d,j")
6031 
6032  - ( //
6033  (R_C1 * r_abPkl("a,b',k,l") + R_C2 * r_abPkl("a,b',l,k"))
6034  * _4("<c j|g|m b'>")
6035  + (R_C1 * r_abPkl("a,b',l,k") + R_C2 * r_abPkl("a,b',k,l"))
6036  * _4("<j c|g|m b'>")
6037  //
6038  + _4("<a b'|g|c j>")
6039  * (R_C1 * r_klmaP("k,l,m,b'") + R_C2 * r_klmaP("l,k,m,b'"))
6040  + _4("<a b'|g|j c>")
6041  * (R_C1 * r_klmaP("l,k,m,b'") + R_C2 * r_klmaP("k,l,m,b'"))
6042  ) * L2("c,d,k,l") * T1("d,j")
6043  ;
6044  Xai("a,i") = //
6045  (V_alcj("a,l,c,j") * L2("c,d,i,l") + V_lacj("l,a,c,j") * L2("c,d,l,i"))
6046  * T1("d,j")
6047  //
6048  + L2("c,d,k,l") * V_klca("k,l,c,a") * T1("d,i")
6049  ;
6050 
6051  return XaiAddToXam(Xam, Xai);
6052  }
6053 
6054  // F12b method
6055  // Xam contribution of VL2T1T1 part resulted from CCSD F12 coupling
6056  template <typename T>
6058  SingleReference_R12Intermediates<T>::Xam_VL2T1T1_f12b(const double C_0, const double C_1,
6059  const TArray2& T1, const TArray4& L2) {
6060 
6061  const char* k = "k";
6062  const char* l = "l";
6063  const char* j = "j";
6064  const char* a = "a";
6065 
6066  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
6067  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
6068 
6069  TArray4d rmbp_kl = ijxy("<m b'|r|k l>");
6070  TArray4d rabp_kl = ijxy("<a b'|r|k l>");
6071 
6072  TArray4 V_AJKL = VPQ_RS(a, j, k, l);
6073  TArray4 V_KLAJ = VPQ_RS(k, l, a, j);
6074 
6075  // compute Xam from 1/4 L^cd_kl V^cd_k1l1 t^k1_c t^l1_d
6076  // (1/8 L^cd_kl R^kl_AB g^AB_k1l1 t^k1_c t^l1_d)
6077  TArray2 Xam_VL2T1T1;
6078  Xam_VL2T1T1("a,m") = // 1/4 l^cd_kl R^kl_mb' g^ab'_k1l1 t^k1_c t^l1_d
6079  // 1/4 l^cd_kl R^kl_ab' g^mb'_k1l1 t^k1_c t^l1_d
6080  ( (R_C1 * rmbp_kl("m,b',k,l") + R_C2 * rmbp_kl("m,b',l,k"))
6081  * _4("<a b'|g|i j>")
6082  //
6083  + (R_C1 * rabp_kl("a,b',k,l") + R_C2 * rabp_kl("a,b',l,k"))
6084  * _4("<m b'|g|i j>")
6085  ) * L2("c,d,k,l") * T1("c,i") * T1("d,j")
6086  ;
6087  TArray2 Xai_VL2T1T1;
6088  Xai_VL2T1T1("a,i") = // - 1/4 l^cd_il R^al_AB g^AB_k1l1 t^k1_c t^l1_d
6089  - (R_C1 * V_AJKL("a,j,k,l") + R_C2 * V_AJKL("a,j,l,k"))
6090  * L2("c,d,i,j") * T1("c,k") * T1("d,l")
6091 
6092  // - 1/4 l^cd_kl R^kl_AB g^AB_al1 t^i_c t^l1_d
6093  - (R_C1 * V_KLAJ("k,l,a,j") + R_C2 * V_KLAJ("l,k,a,j"))
6094  * L2("c,d,k,l") * T1("c,i") * T1("d,j")
6095  ;
6096 
6097  return XaiAddToXam(Xam_VL2T1T1, Xai_VL2T1T1);
6098  }
6099 
6100  template <typename T>
6102  SingleReference_R12Intermediates<T>::Xam_VL2T1T1_f12b_test(const double C_0, const double C_1,
6103  const TArray2& T1, const TArray4& L2) {
6104 
6105  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
6106  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
6107 
6108  const char* j = "j";
6109  const char* k = "k";
6110  const char* l = "l";
6111  const char* a = "a";
6112 
6113  TArray4d r_klmaP = ijxy("<k l|r|m a'>");
6114  TArray4d r_abPkl = ijxy("<a b'|r|k l>");
6115 
6116  TArray4 V_ajkl = VPq_Rs(a,j,k,l,C_0, C_1);
6117  TArray4 V_klaj = VPq_Rs(k,l,a,j,C_0, C_1);
6118  TArray2 Xam, Xai;
6119  Xam("a,m") = ( //
6120  (R_C1 * r_abPkl("a,b',k,l") + R_C2 * r_abPkl("a,b',l,k"))
6121  * _4("<i j|g|m b'>")
6122  //
6123  + _4("<a b'|g|i j>")
6124  * (R_C1 * r_klmaP("k,l,m,b'") + R_C2 * r_klmaP("l,k,m,b'"))
6125  ) * L2("c,d,k,l") * T1("c,i") * T1("d,j")
6126  ;
6127  Xai("a,i") = //
6128  - L2("c,d,k,l") * V_klaj("k,l,a,j") * T1("c,i") * T1("d,j")
6129  //
6130  - V_ajkl("a,j,k,l") * T1("c,k") * T1("d,l") * L2("c,d,i,j")
6131  ;
6132 
6133  return XaiAddToXam(Xam, Xai);
6134  }
6135 
6136  // frozen-core Xii' contribution resulting from CT2, VT2, and VT1 in F12b
6137  template <typename T>
6139  SingleReference_R12Intermediates<T>::Xiip_CVT_f12b(const double C_0, const double C_1,
6140  const TArray2& T1, const TArray4& T2,
6141  const TArray2& L1, const TArray4& L2){
6142 
6143  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
6144  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
6145 
6146  const char* ip = "i'";
6147  const char* i = "i";
6148  const char* l = "l";
6149  const char* c = "c";
6150  const char* d = "d";
6151 
6152  TArray2 Xiip_CTL;
6153  Xiip_CTL("i,i'") = // F^a'_b R^i'l_a'c (T2^bc_il + L2^bc_il)
6154  _4("<i' l|r|b_F(a') c>")
6155  * ( R_C1 * T2("b,c,i,l") + R_C2 * T2("b,c,l,i")
6156  + R_C1 * L2("b,c,i,l") + R_C2 * L2("b,c,l,i"))
6157  + _4("<i' l|r|c b_F(a')>")
6158  * ( R_C1 * T2("c,b,i,l") + R_C2 * T2("c,b,l,i")
6159  + R_C1 * L2("c,b,i,l") + R_C2 * L2("c,b,l,i"))
6160  ;
6161 
6162  TArray2 Xiip_VT2L2;
6163  TArray4 V_ipl_cd = VPq_Rs(ip,l,c,d,C_0, C_1);
6164  Xiip_VT2L2("i,i'") = // 1/4 R^i'l_A'B' g^A'B'_cd (T^cd_il +L^cd_il)
6165  V_ipl_cd("i',l,c,d") * (T2("c,d,i,l") + L2("c,d,i,l"));
6166 
6167  TArray2 Xiip_VT1L1;
6168  TArray4 V_ipl_ic = VPq_Rs(ip,l,i,c, C_0, C_1);
6169  TArray4 V_il_ipc = VPq_Rs(i,l,ip,c,C_0, C_1);
6170  TArray2 V_ipc = VRk_Sk(ip,c,C_0, C_1);
6171  Xiip_VT1L1("i,i'") = // 1/2 R^i'l_A'B' g^A'B'_ic (T^c_l + L^c_l)
6172  // 1/2 R^il_A'B' g^A'B'_i'c (T^c_l + L^c_l)
6173  (V_ipl_ic("i',l,i,c") + V_il_ipc("i,l,i',c"))
6174  * (T1("c,l") + L1("c,l"))
6175 
6176  // 1/2 R^i'k_A'B' g^A'B'_ck (T^c_i + L^c_i)
6177  + V_ipc("i',c") * (T1("c,i") + L1("c,i"))
6178  ;
6179 
6180  TArray2 Xiip_C1;
6181  Xiip_C1("i,i'") = Xiip_CTL("i,i'") + Xiip_VT2L2("i,i'") + Xiip_VT1L1("i,i'");
6182  return Xiip_C1;
6183  }
6184 
6185  // frozen-core Xii' contribution resulting from VT1T1 in F12b
6186  template <typename T>
6188  SingleReference_R12Intermediates<T>::Xiip_VT1T1_f12b(const double C_0, const double C_1,
6189  const TArray2& T1, const TArray4& T2,
6190  const TArray4& L2) {
6191  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
6192  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
6193 
6194  const char* ip = "i'";
6195  const char* i = "i";
6196  const char* j = "j";
6197  const char* k = "k";
6198  const char* l = "l";
6199  const char* c = "c";
6200  const char* d = "d";
6201 
6202  TArray4 V_ipl_cd = VPq_Rs(ip,l,c,d,C_0, C_1);
6203  TArray2 Xiip_VT1T1;
6204  Xiip_VT1T1("i,i'") = // 1/2 R^i'l_A'B' g^A'B'_cd T^i_c t^l_d
6205  V_ipl_cd("i',l,c,d") * T1("c,i") * T1("d,l");
6206 
6207 
6208  TArray4 V_IPL_CJ = VPQ_RS(ip, l, c, j);
6209  TArray4 V_LIP_CJ = VPQ_RS(l, ip, c, j);
6210  TArray4 V_KL_CIP = VPQ_RS(k, l, c, ip);
6211  TArray2 Xai_VL2T1;
6212  Xai_VL2T1("i,i'") = // - 1/2 l^cd_il R^i'l_AB g^AB_cj t^j_d
6213  ( R_C1 * ( V_IPL_CJ("i',l,c,j") * L2("c,d,i,l")
6214  + V_LIP_CJ("l,i',c,j") * L2("c,d,l,i"))
6215  + R_C2 * ( V_IPL_CJ("i',l,c,j") * L2("c,d,l,i")
6216  + V_LIP_CJ("l,i',c,j") * L2("c,d,i,l"))
6217  ) * T1("d,j")
6218 
6219  // - 1/2 l^cd_kl R^kl_AB g^AB_ci' t^i_d
6220  + (R_C1 * V_KL_CIP("k,l,c,i'") + R_C2 * V_KL_CIP("l,k,c,i'"))
6221  * L2("c,d,k,l") * T1("d,i")
6222  ;
6223 
6224  TArray4 V_IPJ_KL = VPQ_RS(ip, j, k, l);
6225  TArray4 V_KL_IPJ = VPQ_RS(k, l, ip, j);
6226  TArray2 Xai_VL2T1T1;
6227  Xai_VL2T1T1("i,i'") = // 1/4 l^cd_il R^i'l_AB g^AB_k1l1 t^k1_c t^l1_d
6228  (R_C1 * V_IPJ_KL("i',j,k,l") + R_C2 * V_IPJ_KL("i',j,l,k"))
6229  * L2("c,d,i,j") * T1("c,k") * T1("d,l")
6230 
6231  // + 1/4 l^cd_kl R^kl_AB g^AB_i'l1 t^i_c t^l1_d
6232  + (R_C1 * V_KL_IPJ("k,l,i',j") + R_C2 * V_KL_IPJ("l,k,i',j"))
6233  * L2("c,d,k,l") * T1("c,i") * T1("d,j")
6234  ;
6235 
6236  TArray2 Xiip_C2;
6237  Xiip_C2("i,i'") = Xiip_VT1T1("i,i'") + Xai_VL2T1("i,i'") + Xai_VL2T1T1("i,i'");
6238  return Xiip_C2;
6239  }
6240 
6241  template <typename T>
6243 
6244  ExEnv::out0() << std::endl << indent
6245  << "Compute CCSD-F12b coupling contri. to dipole and quadrupole moments" << std::endl;
6246 
6247  bool compute_dipole = true;
6248  bool compute_quadrupole = true;
6249 
6250  double conv_target = 1e-10;
6251 
6252  // singlet and triplet coefficients for F12 and coupling terms
6253  const double C_0 = 1.0 / 2.0;
6254  const double C_1 = 1.0 / 4.0;
6255  const double RC1 = 0.5 * (C_0 + C_1);
6256  const double RC2 = 0.5 * (C_0 - C_1);
6257  // compute coefficients needed in the F12 and coupling calculations
6258  const double R_C1 = (0.5 * C_0 + 1.5 * C_1);
6259  const double R_C2 = (0.5 * C_0 - 1.5 * C_1);
6260 
6261  const char* i = "i";
6262  const char* j = "j";
6263  const char* k = "k";
6264  const char* l = "l";
6265  const char* m = "m";
6266 
6267  const char* a = "a";
6268  const char* b = "b";
6269  const char* c = "c";
6270  const char* d = "d";
6271 
6272  // compute integrals needed for orbital relaxation
6273  // i.e. solve Abnam Dbn = Xam (close-shell formula)
6274  TArray4d g_mnab = ijxy("<m n|g|a b>");
6275  TArray4 A_bnam;
6276  A_bnam("b,n,a,m") = - _4("<b n|g|a m>") - g_mnab("m,n,b,a") + 4.0 * g_mnab("n,m,b,a")
6277  + _2("<b|F|a>") * _2("<m|I|n>") - _2("<a|I|b>") * _2("<m|F|n>");
6278 
6279  // Make preconditioner: Delta_am = 1 / (<a|F|a> - <m|F|m>) for
6280  // solving k_bn A_bnam = X_am
6281  TArray2 mFmn, mFab;
6282  mFmn("m,n") = - _2("<m|F|n>");
6283  mFab("a,b") = - _2("<a|F|b>");
6284  typedef detail::diag_precond2<double> pceval_type;
6285  pceval_type Delta_am_gen(TA::array_to_eigen(mFab), TA::array_to_eigen(mFmn));
6286 
6287  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
6288  TArray2 Iam = xy("<a|I|m>");
6289  TArray2d Delta_am(Iam.world(), Iam.trange());
6290 
6291  // construct local tiles
6292  for(auto t = Delta_am.trange().tiles_range().begin();
6293  t != Delta_am.trange().tiles_range().end(); ++t)
6294  if (Delta_am.is_local(*t)) {
6295  std::array<std::size_t, 2> index;
6296  std::copy(t->begin(), t->end(), index.begin());
6297  madness::Future < typename TArray2d::value_type >
6298  tile((LazyTensor<T, 2, pceval_type >(&Delta_am, index, &Delta_am_gen)
6299  ));
6300 
6301  // Insert the tile into the array
6302  Delta_am.set(*t, tile);
6303  }
6304  TArray2 preconditioner;
6305  preconditioner("a,m") = Delta_am("a,m");
6306 
6307  detail::Orbital_relaxation_Abjai<double> Orbital_relaxation_Abnam(A_bnam);
6308  TA::ConjugateGradientSolver<TiledArray::Array<T,2>,
6310 
6311 
6312  // determine if it is frozen-core
6313  TArray2 Fij = xy("<i|F|j>");
6314  const std::size_t nocc = mFmn.trange().elements_range().extent()[0];
6315  const std::size_t naocc = Fij.trange().elements_range().extent()[0];
6316 
6317  // compute terms needed for frozen-core
6318  TArray2 Delta_ijp_F;
6319  TArray4 A_ijpam;
6320  if (nocc != naocc) {
6321  // compute 1 / (Fi'i' - Fjj)
6322  TArray2 Fipjp = xy("<i'|F|j'>");
6323  pceval_type Delta_ijp_gen(TA::array_to_eigen(Fij), TA::array_to_eigen(Fipjp));
6324 
6325  TArray2 Fijp = xy("<i|F|j'>");
6326  TArray2d Delta_ijp(Fijp.world(), Fijp.trange());
6327  // construct local tiles
6328  for(auto t = Delta_ijp.trange().tiles_range().begin();
6329  t != Delta_ijp.trange().tiles_range().end(); ++t)
6330  if (Delta_ijp.is_local(*t)) {
6331  std::array<std::size_t, 2> index;
6332  std::copy(t->begin(), t->end(), index.begin());
6333  madness::Future < typename TArray2d::value_type >
6334  tile((LazyTensor<T, 2, pceval_type >(&Delta_ijp, index, &Delta_ijp_gen)
6335  ));
6336 
6337  // Insert the tile into the array
6338  Delta_ijp.set(*t, tile);
6339  }
6340  Delta_ijp_F("i,j'") = Delta_ijp("i,j'");
6341 
6342  A_ijpam("i,j',a,m") = 4.0 * _4("<i a|g|j' m>") - _4("<i a|g|m j'>") - _4("<i m|g|a j'>");
6343  }
6344 
6345  TArray2 mu_z_ij, mu_z_ijp, mu_z_ab, mu_z_ai, mu_z_am;
6346  if (compute_dipole) {
6347  mu_z_ij = xy("<i|mu_z|j>");
6348  mu_z_ab = xy("<a|mu_z|b>");
6349  mu_z_ai = xy("<a|mu_z|i>");
6350  mu_z_am = xy("<a|mu_z|m>");
6351 
6352  if (nocc != naocc)
6353  mu_z_ijp = xy("<i|mu_z|j'>");
6354  }
6355 
6356  // quadrupole integrals
6357  TArray2 Qxx_ij, Qyy_ij, Qzz_ij, Qxx_ab, Qyy_ab, Qzz_ab,
6358  Qxx_ai, Qyy_ai, Qzz_ai, Qxx_am, Qyy_am, Qzz_am,
6359  Qxx_apb, Qyy_apb, Qzz_apb,
6360  // integrals for frozen-core
6361  Qxx_ijp, Qyy_ijp, Qzz_ijp;
6362 
6363  if (compute_quadrupole){
6364 
6365  TArray2 q_xx_ij = xy("<i|q_xx|j>");
6366  TArray2 q_yy_ij = xy("<i|q_yy|j>");
6367  TArray2 q_zz_ij = xy("<i|q_zz|j>");
6368  Qxx_ij("i,j") = q_xx_ij("i,j") - (q_zz_ij("i,j") + q_yy_ij("i,j")) * 0.5;
6369  Qyy_ij("i,j") = q_yy_ij("i,j") - (q_zz_ij("i,j") + q_xx_ij("i,j")) * 0.5;
6370  Qzz_ij("i,j") = q_zz_ij("i,j") - (q_xx_ij("i,j") + q_yy_ij("i,j")) * 0.5;
6371 
6372  TArray2 q_xx_ab = xy("<a|q_xx|b>");
6373  TArray2 q_yy_ab = xy("<a|q_yy|b>");
6374  TArray2 q_zz_ab = xy("<a|q_zz|b>");
6375  Qxx_ab("a,b") = q_xx_ab("a,b") - (q_zz_ab("a,b") + q_yy_ab("a,b")) * 0.5;
6376  Qyy_ab("a,b") = q_yy_ab("a,b") - (q_zz_ab("a,b") + q_xx_ab("a,b")) * 0.5;
6377  Qzz_ab("a,b") = q_zz_ab("a,b") - (q_xx_ab("a,b") + q_yy_ab("a,b")) * 0.5;
6378 
6379  TArray2 q_xx_ai = xy("<a|q_xx|i>");
6380  TArray2 q_yy_ai = xy("<a|q_yy|i>");
6381  TArray2 q_zz_ai = xy("<a|q_zz|i>");
6382  Qxx_ai("a,i") = q_xx_ai("a,i") - (q_zz_ai("a,i") + q_yy_ai("a,i")) * 0.5;
6383  Qyy_ai("a,i") = q_yy_ai("a,i") - (q_zz_ai("a,i") + q_xx_ai("a,i")) * 0.5;
6384  Qzz_ai("a,i") = q_zz_ai("a,i") - (q_xx_ai("a,i") + q_yy_ai("a,i")) * 0.5;
6385 
6386  TArray2 q_xx_am = xy("<a|q_xx|m>");
6387  TArray2 q_yy_am = xy("<a|q_yy|m>");
6388  TArray2 q_zz_am = xy("<a|q_zz|m>");
6389  Qxx_am("a,m") = q_xx_am("a,m") - (q_zz_am("a,m") + q_yy_am("a,m")) * 0.5;
6390  Qyy_am("a,m") = q_yy_am("a,m") - (q_zz_am("a,m") + q_xx_am("a,m")) * 0.5;
6391  Qzz_am("a,m") = q_zz_am("a,m") - (q_xx_am("a,m") + q_yy_am("a,m")) * 0.5;
6392 
6393  TArray2 q_xx_apb = xy("<a'|q_xx|b>");
6394  TArray2 q_yy_apb = xy("<a'|q_yy|b>");
6395  TArray2 q_zz_apb = xy("<a'|q_zz|b>");
6396  Qxx_apb("a',b") = q_xx_apb("a',b") - (q_zz_apb("a',b") + q_yy_apb("a',b")) * 0.5;
6397  Qyy_apb("a',b") = q_yy_apb("a',b") - (q_zz_apb("a',b") + q_xx_apb("a',b")) * 0.5 ;
6398  Qzz_apb("a',b") = q_zz_apb("a',b") - (q_xx_apb("a',b") + q_yy_apb("a',b")) * 0.5;
6399 
6400  if (nocc != naocc) {
6401  TArray2 q_xx_ijp = xy("<i|q_xx|j'>");
6402  TArray2 q_yy_ijp = xy("<i|q_yy|j'>");
6403  TArray2 q_zz_ijp = xy("<i|q_zz|j'>");
6404  Qxx_ijp("i,j'") = q_xx_ijp("i,j'") - (q_zz_ijp("i,j'") + q_yy_ijp("i,j'")) * 0.5;
6405  Qyy_ijp("i,j'") = q_yy_ijp("i,j'") - (q_zz_ijp("i,j'") + q_xx_ijp("i,j'")) * 0.5;
6406  Qzz_ijp("i,j'") = q_zz_ijp("i,j'") - (q_xx_ijp("i,j'") + q_yy_ijp("i,j'")) * 0.5;
6407  }
6408  }
6409 
6410  double muz_ccsd = 0.0, muz_ccsdor = 0.0;
6411  double q_xx_ccsd = 0.0, q_yy_ccsd = 0.0, q_zz_ccsd = 0.0;
6412  double q_xx_ccsdor = 0.0, q_yy_ccsdor = 0.0, q_zz_ccsdor = 0.0;
6413 #if 1 // CCSD
6414  ExEnv::out0() << indent << "Compute CCSD T amplitudes " << std::endl;
6415  TArray2 T1_ccsd;
6416  TArray4 T2_ccsd;
6417  compute_T_ccsd(T1_ccsd, T2_ccsd, "CCSD");
6418 
6419  ExEnv::out0() << indent << "Compute CCSD L amplitudes " << std::endl;
6420  TArray2 L1_ccsd;
6421  TArray4 L2_ccsd;
6422  compute_lambda_ccsd(T1_ccsd, T2_ccsd, L1_ccsd, L2_ccsd, "CCSD");
6423 
6424  // compute CCSD density from amplitudes
6425  TArray2 Dij_ccsd, Dab_ccsd, Dia_ccsd, Dai_ccsd;
6426  ExEnv::out0() << std::endl << indent
6427  << "Compute CCSD density from amplitudes" << std::endl;
6428  compute_ccsd_1rdm_amp(T1_ccsd, T2_ccsd, L1_ccsd, L2_ccsd,
6429  Dij_ccsd, Dab_ccsd, Dia_ccsd, Dai_ccsd);
6430 
6431  ExEnv::out0() << std::endl << indent << "Compute CCSD Xam and Xai" << std::endl;
6432  TArray2 Xam_ccsd_nfzc, Xiip_ccsd;
6433  compute_Xam_ccsd(T1_ccsd, T2_ccsd, L1_ccsd, L2_ccsd,
6434  Xam_ccsd_nfzc, Xiip_ccsd);
6435 
6436  TArray2 Diip_or_ccsd, Xam_ccsd;
6437  if (nocc != naocc) {
6438  ExEnv::out0() << std::endl << indent
6439  << "Include frozen-core CCSD contributions" << std::endl;
6440  Diip_or_ccsd("i,i'") = Xiip_ccsd("i,i'") * Delta_ijp_F("i,i'");
6441 
6442  TArray2 Xam_Diip_ccsd;
6443  Xam_Diip_ccsd("a,m") = A_ijpam("i,i',a,m") * Diip_or_ccsd("i,i'");
6444  Xam_ccsd("a,m") = Xam_ccsd_nfzc("a,m") - Xam_Diip_ccsd("a,m");
6445  } else {
6446  Xam_ccsd("a,m") = Xam_ccsd_nfzc("a,m");
6447  }
6448 
6449  // solve the Z-vector equation for CCSD
6450  TArray2 Dbn_ccsd(Xam_ccsd.world(), Xam_ccsd.trange());
6451  auto resnorm_ccsd = cg_solver2(Orbital_relaxation_Abnam,
6452  Xam_ccsd,
6453  Dbn_ccsd,
6454  preconditioner,
6455  conv_target);
6456 
6457  if (compute_dipole) {
6458  muz_ccsd = dot(mu_z_ij("i,j"), Dij_ccsd("i,j"))
6459  + dot(mu_z_ab("a,b"), Dab_ccsd("a,b"))
6460  + dot(mu_z_ai("a,i"), Dai_ccsd("a,i"))
6461  + dot(mu_z_ai("a,i"), Dia_ccsd("i,a"))
6462  ;
6463 
6464  muz_ccsdor = dot(mu_z_am("a,m"), Dbn_ccsd("a,m"));
6465  if (nocc != naocc) {
6466  muz_ccsdor += dot(mu_z_ijp("i,i'"), Diip_or_ccsd("i,i'"));
6467  }
6468 
6469 // std::cout << std::endl << indent
6470 // << "muz_CCSD = " << scprintf("%15.12f", - muz_ccsd * 2.0)
6471 // << std::endl << indent
6472 // << "muz_CCSDor = " << scprintf("%15.12f", - muz_ccsdor * 2.0)
6473 // << std::endl;
6474  }
6475 
6476  if (compute_quadrupole) {
6477  q_xx_ccsd = dot(Qxx_ij("i,j"), Dij_ccsd("i,j"))
6478  + dot(Qxx_ab("a,b"), Dab_ccsd("a,b"))
6479  + dot(Qxx_ai("a,i"), Dai_ccsd("a,i"))
6480  + dot(Qxx_ai("a,i"), Dia_ccsd("i,a"))
6481  ;
6482  q_yy_ccsd = dot(Qyy_ij("i,j"), Dij_ccsd("i,j"))
6483  + dot(Qyy_ab("a,b"), Dab_ccsd("a,b"))
6484  + dot(Qyy_ai("a,i"), Dai_ccsd("a,i"))
6485  + dot(Qyy_ai("a,i"), Dia_ccsd("i,a"))
6486  ;
6487  q_zz_ccsd = dot(Qzz_ij("i,j"), Dij_ccsd("i,j"))
6488  + dot(Qzz_ab("a,b"), Dab_ccsd("a,b"))
6489  + dot(Qzz_ai("a,i"), Dai_ccsd("a,i"))
6490  + dot(Qzz_ai("a,i"), Dia_ccsd("i,a"))
6491  ;
6492 
6493  q_xx_ccsdor = dot(Qxx_am("a,m"), Dbn_ccsd("a,m"));
6494  q_yy_ccsdor = dot(Qyy_am("a,m"), Dbn_ccsd("a,m"));
6495  q_zz_ccsdor = dot(Qzz_am("a,m"), Dbn_ccsd("a,m"));
6496 
6497  if (nocc != naocc) {
6498  q_xx_ccsdor += dot(Qxx_ijp("i,j'"), Diip_or_ccsd("i,j'"));
6499  q_yy_ccsdor += dot(Qyy_ijp("i,j'"), Diip_or_ccsd("i,j'"));
6500  q_zz_ccsdor += dot(Qzz_ijp("i,j'"), Diip_or_ccsd("i,j'"));
6501  }
6502 
6503 // std::cout << std::endl << indent
6504 // << "qxx_ccsd = " << scprintf("%12.10f", - q_xx_ccsd * 2.0)
6505 // << " qyy_ccsd = " << scprintf("%12.10f", - q_yy_ccsd * 2.0)
6506 // << " qzz_ccsd = " << scprintf("%12.10f", - q_zz_ccsd * 2.0)
6507 // << std::endl << indent
6508 // << "qxx_ccsdor = " << scprintf("%12.10f", - q_xx_ccsdor * 2.0)
6509 // << " qyy_ccsdor = " << scprintf("%12.10f", - q_yy_ccsdor * 2.0)
6510 // << " qzz_ccsdor = " << scprintf("%12.10f", - q_zz_ccsdor * 2.0)
6511 // << std::endl;
6512  }
6513 #endif
6514 
6515  // resolve CCSD T amplitudes in the framework of CCSD-F12b
6516  ExEnv::out0() << indent << "Compute CCSD-F12b T amplitudes " << std::endl;
6517  TArray2 T1_f12b;
6518  TArray4 T2_f12b;
6519  compute_T_ccsd(T1_f12b, T2_f12b, "F12b");
6520 
6521  // resolve CCSD lambda amplitudes in the framework of CCSD-F12b
6522  ExEnv::out0() << std::endl << indent << "Compute CCSD-F12b L amplitudes " << std::endl;
6523  TArray2 L1_f12b;
6524  TArray4 L2_f12b;
6525  compute_lambda_ccsd(T1_f12b, T2_f12b, L1_f12b, L2_f12b, "F12b");
6526 
6527  // compute energy from coupling in F12b
6528 #if 0
6529  // CT2 energy
6530  // F^a'_a R^ij_a'b + F^a'_b R^ij_aa'
6531  TArray4 Cijab;
6532  TArray4d r_ijaFb = ijxy("<i j|r|a_F(c') b>");
6533  Cijab("i,j,a,b") = R_C1 * r_ijaFb("i,j,a,b") + R_C2 * r_ijaFb("j,i,a,b")
6534  + R_C1 * r_ijaFb("j,i,b,a") + R_C2 * r_ijaFb("i,j,b,a");
6535  TArray2 CT2;
6536  CT2("i,j") = Cijab("i,k,a,b") * T2_f12b("a,b,j,k");
6537  double E_CT2 = dot(CT2("i,j"), _2("<j|I|i>"));
6538  std::cout << std::endl
6539  << indent << "E_CT2 = " << scprintf("%15.12f", E_CT2)
6540  << std::endl;
6541 
6542  // VT1 + VT2 energy
6543  TArray2 V_ia;
6544  V_ia = VRk_Sk(i,a, C_0, C_1);
6545 
6546  TArray4 Vijab = VPq_Rs(i, j, a, b, C_0, C_1);
6547  TArray2 VT2;
6548  VT2("i,j") = Vijab("i,k,a,b") * T2_f12b("a,b,j,k");
6549 
6550  double E_VT = dot(V_ia("i,a"), T1_f12b("a,i")) * 2.0
6551  + dot(VT2("i,j"), _2("<j|I|i>"));
6552  std::cout << indent << "E_VT = " << scprintf("%15.12f", E_VT)
6553  << std::endl;
6554 
6555  // VT1T1 energy
6556  double E_VT1T1 = dot(Vijab("i,j,a,b"), T1_f12b("a,i") * T1_f12b("b,j"));
6557  std::cout << indent << "E_VT1T1 = " << scprintf("%15.12f", E_VT1T1)
6558  << std::endl;
6559 
6560  std::cout << indent << "E (Coupling in F12b) = "
6561  << scprintf("%15.12f", (E_CT2+E_VT+E_VT1T1))
6562  << std::endl;
6563 #endif
6564 
6565  // CC F12b coupling contribution to Xam
6566  TArray2 mu_z_apb;
6567 #if 1
6568  // compute CCSD-F12b density from amplitudes
6569  TArray2 Dij_f12b, Dab_f12b, Dia_f12b, Dai_f12b;
6570  ExEnv::out0() << std::endl << indent
6571  << "Compute CCSD density from amplitudes in CCSD-F12b" << std::endl;
6572  compute_ccsd_1rdm_amp(T1_f12b, T2_f12b, L1_f12b, L2_f12b,
6573  Dij_f12b, Dab_f12b, Dia_f12b, Dai_f12b);
6574 
6575  ExEnv::out0() << std::endl << indent
6576  << "Compute CCSD Xam and Xai in CCSD-F12b" << std::endl;
6577  TArray2 Xam_f12b_nfzc, Xiip_f12b;
6578  compute_Xam_ccsd(T1_f12b, T2_f12b, L1_f12b, L2_f12b, Xam_f12b_nfzc, Xiip_f12b);
6579 
6580  TArray2 Diip_f12b, Xam_f12b;
6581  if (nocc != naocc) {
6582  Diip_f12b("i,i'") = Xiip_f12b("i,i'") * Delta_ijp_F("i,i'");
6583  Xam_f12b("a,m") = Xam_f12b_nfzc("a,m") - A_ijpam("i,i',a,m") * Diip_f12b("i,i'");
6584  } else {
6585  Xam_f12b("a,m") = Xam_f12b_nfzc("a,m");
6586  }
6587 
6588  TArray2 Dbn_f12b(Xam_f12b.world(), Xam_f12b.trange());
6589  auto resnorm_f12b = cg_solver2(Orbital_relaxation_Abnam,
6590  Xam_f12b,
6591  Dbn_f12b,
6592  preconditioner,
6593  conv_target);
6594 
6595 
6596  ExEnv::out0() << std::endl << indent
6597  << "Compute CCSD F12b coupling contributions" << std::endl;
6598  // CC CT2
6599  TArray2 RT2_aPb, RL2_aPb;
6600  // 1/2 R^kl_a'c T2^bc_kl
6601  RT2_aPb("a',b") = _4("<a' c|r|k l>")
6602  * (R_C1 * T2_f12b("b,c,k,l") + R_C2 * T2_f12b("c,b,k,l"));
6603  // 1/2 R^kl_a'c L2^bc_kl
6604  RL2_aPb("a',b") = _4("<a' c|r|k l>")
6605  * (R_C1 * L2_f12b("b,c,k,l") + R_C2 * L2_f12b("c,b,k,l"));
6606 
6607  TArray2 Xam_CT2L2 = Xam_CT2L2_f12b(C_0, C_1, T2_f12b, RT2_aPb, L2_f12b, RL2_aPb);
6608 
6609  // VT1 & VT2 coupling contribution to F12 Xam
6610  TArray2 Xam_VTL = Xam_VTL_f12b(C_0, C_1, T1_f12b, T2_f12b, L1_f12b, L2_f12b);
6611 
6612  // VT1T1
6613  TArray2 X_VT1T1 = Xam_VT1T1_f12b(C_0, C_1, T1_f12b);
6614 // // *** test
6615 // TArray4 tauT1_ab;
6616 // tauT1_ab("a,b,i,j") = T1_f12b("a,i") * T1_f12b("b,j");
6617 // TArray2 X_VT1T1 = Xam_VT1T1_f12b_test(C_0, C_1, tauT1_ab);
6618 
6619  // VL2T1
6620  TArray2 X_VL2T1 = Xam_VL2T1_f12b(C_0, C_1, T1_f12b, L2_f12b);
6621 // // *** test
6622 // TArray2 X_VL2T1 = Xam_VL2T1_f12b_test(C_0, C_1, T1_f12b, L2_f12b);
6623 
6624  // VL2T1T1
6625  TArray2 X_VL2T1T1 = Xam_VL2T1T1_f12b(C_0, C_1, T1_f12b, L2_f12b);
6626 // // *** test
6627 // TArray2 X_VL2T1T1 = Xam_VL2T1T1_f12b_test(C_0, C_1, T1_f12b, L2_f12b);
6628 
6629  TArray2 Xam_C_nfzc;
6630  Xam_C_nfzc("a,m") = Xam_CT2L2("a,m")
6631  + Xam_VTL("a,m")
6632  + X_VT1T1("a,m")
6633  + X_VL2T1("a,m")
6634  + X_VL2T1T1("a,m")
6635  ;
6636 
6637  // frozen-core contribution
6638  TArray2 Diip_C, Xam_C;
6639  if (nocc != naocc) {
6640  ExEnv::out0() << std::endl << indent
6641  << "Include frozen-core contributions for CCSD F12 coupling" << std::endl;
6642  TArray2 Xiip_couling1 = Xiip_CVT_f12b(C_0, C_1, T1_f12b, T2_f12b, L1_f12b, L2_f12b);
6643  TArray2 Xiip_couling2 = Xiip_VT1T1_f12b(C_0, C_1, T1_f12b, T2_f12b, L2_f12b);
6644  Diip_C("i,i'") = - (Xiip_couling1("i,i'") + Xiip_couling2("i,i'"))
6645  * Delta_ijp_F("i,i'");
6646 
6647  TArray2 Xam_Diip_C;
6648  Xam_Diip_C("a,m") = - A_ijpam("i,j',a,m") * Diip_C("i,j'");
6649 
6650  Xam_C("a,m") = Xam_C_nfzc("a,m") + Xam_Diip_C("a,m");
6651  } else {
6652  Xam_C("a,m") = Xam_C_nfzc("a,m");
6653  }
6654 
6655  TArray2 Dbn_C(Xam_C.world(), Xam_C.trange());
6656  auto resnorm_C = cg_solver2(Orbital_relaxation_Abnam,
6657  Xam_C,
6658  Dbn_C,
6659  preconditioner,
6660  conv_target);
6661 
6662 // TArray2 Dbn_CT2L2(Xam_CT2L2.world(), Xam_CT2L2.trange());
6663 // auto resnorm_CT2L2 = cg_solver2(Orbital_relaxation_Abnam,
6664 // Xam_CT2L2,
6665 // Dbn_CT2L2,
6666 // preconditioner,
6667 // conv_target);
6668 //
6669 // TArray2 Dbn_VTL(Xam_VTL.world(), Xam_VTL.trange());
6670 // auto resnorm_VTL = cg_solver2(Orbital_relaxation_Abnam,
6671 // Xam_VTL,
6672 // Dbn_VTL,
6673 // preconditioner,
6674 // conv_target);
6675 
6676  if (compute_dipole) {
6677  mu_z_apb = xy("<a'|mu_z|b>");
6678  double muz_f12b = dot(mu_z_ij("i,j"), Dij_f12b("i,j"))
6679  + dot(mu_z_ab("a,b"), Dab_f12b("a,b"))
6680  + dot(mu_z_ai("a,i"), Dai_f12b("a,i"))
6681  + dot(mu_z_ai("a,i"), Dia_f12b("i,a"))
6682  // F12 coupling density contribution
6683  + dot(mu_z_apb("a',b"), RT2_aPb("a',b"))
6684  + dot(mu_z_apb("a',b"), RL2_aPb("a',b"))
6685  ;
6686 
6687  double muz_f12bor = dot(mu_z_am("a,m"), Dbn_f12b("a,m"))
6688  + dot(mu_z_am("a,m"), Dbn_C("a,m"))
6689  ;
6690 
6691  if (nocc != naocc) {
6692  muz_f12b += dot(mu_z_ijp("i,j'"), Diip_f12b("i,j'"))
6693  + dot(mu_z_ijp("i,j'"), Diip_C("i,j'"));
6694  }
6695 
6696 // std::cout << std::endl << indent
6697 // << "muz_ccsd (F12b) = " << scprintf("%15.12f", - muz_f12b * 2.0)
6698 // << std::endl << indent
6699 // << "muz_ccsdor (F12b) = " << scprintf("%15.12f", - muz_f12bor * 2.0)
6700 // << std::endl;
6701 
6702  double muz_Cf12b = muz_f12b - muz_ccsd;
6703  double muz_Cf12bor = muz_f12bor - muz_ccsdor;
6704 
6705  std::cout << std::endl << indent
6706  << "mu_z (F12b C) = " << scprintf("%15.12f", - muz_Cf12b * 2.0)
6707  << std::endl << indent
6708  << "mu_z (F12b C or) = " << scprintf("%15.12f", - muz_Cf12bor * 2.0)
6709  << std::endl << std::endl;
6710  }
6711 
6712  if (compute_quadrupole) {
6713  double q_xx_f12b = dot(Qxx_ij("i,j"), Dij_f12b("i,j"))
6714  + dot(Qxx_ab("a,b"), Dab_f12b("a,b"))
6715  + dot(Qxx_ai("a,i"), Dai_f12b("a,i"))
6716  + dot(Qxx_ai("a,i"), Dia_f12b("i,a"))
6717  + dot(Qxx_apb("a',b"), RT2_aPb("a',b"))
6718  + dot(Qxx_apb("a',b"), RL2_aPb("a',b"))
6719  ;
6720  double q_yy_f12b = dot(Qyy_ij("i,j"), Dij_f12b("i,j"))
6721  + dot(Qyy_ab("a,b"), Dab_f12b("a,b"))
6722  + dot(Qyy_ai("a,i"), Dai_f12b("a,i"))
6723  + dot(Qyy_ai("a,i"), Dia_f12b("i,a"))
6724  + dot(Qyy_apb("a',b"), RT2_aPb("a',b"))
6725  + dot(Qyy_apb("a',b"), RL2_aPb("a',b"))
6726  ;
6727  double q_zz_f12b = dot(Qzz_ij("i,j"), Dij_f12b("i,j"))
6728  + dot(Qzz_ab("a,b"), Dab_f12b("a,b"))
6729  + dot(Qzz_ai("a,i"), Dai_f12b("a,i"))
6730  + dot(Qzz_ai("a,i"), Dia_f12b("i,a"))
6731  + dot(Qzz_apb("a',b"), RT2_aPb("a',b"))
6732  + dot(Qzz_apb("a',b"), RL2_aPb("a',b"))
6733  ;
6734 
6735  double q_xx_f12bor = dot(Qxx_am("a,m"), Dbn_f12b("a,m"))
6736  + dot(Qxx_am("a,m"), Dbn_C("a,m"));
6737  double q_yy_f12bor = dot(Qyy_am("a,m"), Dbn_f12b("a,m"))
6738  + dot(Qyy_am("a,m"), Dbn_C("a,m"));
6739  double q_zz_f12bor = dot(Qzz_am("a,m"), Dbn_f12b("a,m"))
6740  + dot(Qzz_am("a,m"), Dbn_C("a,m"));
6741 
6742  if (nocc != naocc) {
6743  q_xx_f12bor += dot(Qxx_ijp("i,j'"), Diip_f12b("i,j'"))
6744  + dot(Qxx_ijp("i,j'"), Diip_C("i,j'"));
6745  q_yy_f12bor += dot(Qyy_ijp("i,j'"), Diip_f12b("i,j'"))
6746  + dot(Qyy_ijp("i,j'"), Diip_C("i,j'"));
6747  q_zz_f12bor += dot(Qzz_ijp("i,j'"), Diip_f12b("i,j'"))
6748  + dot(Qzz_ijp("i,j'"), Diip_C("i,j'"));
6749  }
6750 
6751 // std::cout << std::endl << indent
6752 // << "q_xx (F12b) = " << scprintf("%12.10f", - q_xx_f12b * 2.0)
6753 // << " q_yy (F12b) = " << scprintf("%12.10f", - q_yy_f12b * 2.0)
6754 // << " q_zz (F12b) = " << scprintf("%12.10f", - q_zz_f12b * 2.0)
6755 // << std::endl << indent
6756 // << "q_xx (F12b or) = " << scprintf("%12.10f", - q_xx_f12bor * 2.0)
6757 // << " q_yy (F12b or) = " << scprintf("%12.10f", - q_yy_f12bor * 2.0)
6758 // << " q_zz (F12b or) = " << scprintf("%12.10f", - q_zz_f12bor * 2.0)
6759 // << std::endl << std::endl;
6760 
6761  double q_xx_f12b_C = q_xx_f12b - q_xx_ccsd;
6762  double q_yy_f12b_C = q_yy_f12b - q_yy_ccsd;
6763  double q_zz_f12b_C = q_zz_f12b - q_zz_ccsd;
6764  double q_xx_f12bor_C = q_xx_f12bor - q_xx_ccsdor;
6765  double q_yy_f12bor_C = q_yy_f12bor - q_yy_ccsdor;
6766  double q_zz_f12bor_C = q_zz_f12bor - q_zz_ccsdor;
6767  std::cout << std::endl << indent
6768  << "q_xx (F12b C) = " << scprintf("%12.10f", - q_xx_f12b_C * 2.0)
6769  << " q_yy (F12b C) = " << scprintf("%12.10f", - q_yy_f12b_C * 2.0)
6770  << " q_zz (F12b C) = " << scprintf("%12.10f", - q_zz_f12b_C * 2.0)
6771  << std::endl << indent
6772  << "q_xx (F12b C or) = " << scprintf("%12.10f", - q_xx_f12bor_C * 2.0)
6773  << " q_yy (F12b C or) = " << scprintf("%12.10f", - q_yy_f12bor_C * 2.0)
6774  << " q_zz (F12b C or) = " << scprintf("%12.10f", - q_zz_f12bor_C * 2.0)
6775  << std::endl << std::endl;
6776  }
6777 #endif
6778 
6779  }
6780 
6781  template <typename T>
6784 
6785 #define ENABLE_SRR12_RDM1 1
6786 
6787 #if ENABLE_SRR12_RDM1
6788 // if (0) {
6789 // {
6790 // typedef TiledArray::Array<T,2> Array;
6791 // Array FiA = _2("<i|F|A'>");
6792 // Array FAi = _2("<A'|F|i>");
6793 // std::cout << "<i|F|A'>:" << std::endl << FiA << std::endl;
6794 // std::cout << "<A'|F|i>:" << std::endl << FAi << std::endl;
6795 // Array FiA_2(FiA.world(), FiA.trange());
6796 // FiA_2("i,A'") = FAi("A',i");
6797 // std::cout << "<i|F|A'>=Perm(<A'|F|i>):" << std::endl << FiA_2 << std::endl;
6798 // }
6799 // {
6800 // typedef TiledArray::Array<T,4> Array;
6801 // Array g_ij_ab = _4("<i j|g|a b>");
6802 // Array g_ab_ij = _4("<a b|g|i j>");
6803 // std::cout << "<i j|g|a b>:" << std::endl << g_ij_ab << std::endl;
6804 // std::cout << "<a b|g|i j>:" << std::endl << g_ab_ij << std::endl;
6805 // Array g_ij_ab_2(g_ij_ab.world(), g_ij_ab.trange());
6806 // g_ij_ab_2("i,j,a,b") = g_ab_ij("a,b,i,j");
6807 // std::cout << "<i j|g|a b>=Perm(<a b|g|i j>):" << std::endl << g_ij_ab_2 << std::endl;
6808 // Array should_be_zero = g_ij_ab("i,j,a,b") - g_ab_ij("a,b,i,j");
6809 // std::cout << "<i j|g|a b> - Perm(<a b|g|i j>):" << std::endl << should_be_zero << std::endl;
6810 // const double max_nonzero = norminf(should_be_zero("i,j,a,b"));
6811 // std::cout << "|| <i j|g|a b> - Perm(<a b|g|i j>) ||_\infty = " << max_nonzero << std::endl;
6812 // }
6813 // {
6814 // typedef TiledArray::Array<T,2> Array;
6815 // Array mu_z_ij = _2("<i|mu_z|j>");
6816 // Array gamma_ij = _2("<i|gamma|j>");
6817 // const double mu_z_e = dot(mu_z_ij("i,j"), gamma_ij("i,j"));
6818 // double mu_z_n = 0.0;
6819 // Ref<Molecule> mol = r12world_->basis()->molecule();
6820 // for(int a=0; a<mol->natom(); ++a) {
6821 // mu_z_n += mol->Z(a) * mol->r(a, 2);
6822 // }
6823 // std::cout << "mu_z = " << -mu_z_e+mu_z_n << std::endl;
6824 // }
6825 // }
6826 
6827  // can only ask for T1 with i in bra!
6828  // since we computed T1 CABS, they are expressed in terms of all virtuals = A'
6829  // if you turn off vir-CABS coupling, use a' (i.e. CABS only)
6830 // TArray2 T1iA = _2("<i|T1|A'>");
6831 // //t1_cabs_.print("T1(RefSCMatrix)");
6832 // //std::cout << "T1(cabs)\n" << T1iA << std::endl;
6833 // TArray2 T1ia = _2("<i|T1|a>");
6834 // //std::cout << "T1(cabs) => i by a block\n" << T1ia << std::endl;
6835 //
6836 // // recompute E2(CABS) = T1_cabs . H1
6837 // const double E2_cabs = 2.0 * dot(T1iA("i,A'"), _2("<i|F|A'>"));
6838 // std::cout << "E2_cabs (recomputed) = " << E2_cabs << std::endl;
6839 
6840 #if 0
6841  // recompute T1_cabs and re-recompute E2_cabs
6842  {
6843  typedef TiledArray::Array<T,2> Array;
6844  Array Fii = _2("<i|F|j>");
6845  Array FAA = _2("<A'|F|B'>");
6846  // this computes Z_i^A' = T_i^B' F_B'^A' - F_i^j T_j^A'
6847  detail::_CABS_singles_h0t1<double> cabs_singles_rhs_eval(FAA, Fii);
6848 
6849  TA::ConjugateGradientSolver<Array, detail::_CABS_singles_h0t1<double> > cg_solver;
6850  Array FiA = _2("<i|F|A'>");
6851  Array minus_FiA = -1.0 * FiA("i,A'");
6852  Array T1_recomp = FiA;
6853 
6854  // make preconditioner: Delta_iA = <i|F|i> - <A'|F|A'>
6855  typedef detail::diag_precond2<double> pceval_type;
6856  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
6857  TArray2d Delta_iA(FiA.world(), FiA.trange());
6858  pceval_type Delta_iA_gen(TA::array_to_eigen(Fii),
6859  TA::array_to_eigen(FAA));
6860 
6861  // construct local tiles
6862  for(auto t=Delta_iA.trange().tiles_range().begin();
6863  t!=Delta_iA.trange().tiles_range().end();
6864  ++t)
6865  if (Delta_iA.is_local(*t)) {
6866  std::array<std::size_t, 2> index; std::copy(t->begin(), t->end(), index.begin());
6867  madness::Future < typename TArray2d::value_type >
6868  tile((LazyTensor<T, 2, pceval_type >(&Delta_iA, index, &Delta_iA_gen)
6869  ));
6870 
6871  // Insert the tile into the array
6872  Delta_iA.set(*t, tile);
6873  }
6874  Array preconditioner = Delta_iA("i,A'");
6875 
6876 #if 0
6877  std::cout << "FiA:\n" << FiA << std::endl;
6878  std::cout << "Fii:\n" << Fii << std::endl;
6879  std::cout << "FAA:\n" << FAA << std::endl;
6880  std::cout << "preconditioner:\n" << preconditioner << std::endl;
6881 #endif
6882 
6883  // solves CABS singles equations T_i^B' F_B'^A' - F_i^j T_j^A' = -F_i^A' using CG
6884  auto resnorm = cg_solver(cabs_singles_rhs_eval,
6885  minus_FiA,
6886  T1_recomp,
6887  preconditioner,
6888  1e-10);
6889  std::cout << "Converged CG to " << resnorm << std::endl;
6890  const double E2_cabs = 2.0 * dot(T1_recomp("i,A'"), _2("<i|F|A'>")); // 2 accounts for spin
6891  std::cout << "E2_cabs (re-recomputed) = " << E2_cabs << std::endl;
6892 
6893  // compute the (2)_S dipole moment
6894  {
6895  const double mu_z_e = 2*dot(_2("<i|mu_z|A'>"), T1_recomp("i,A'"))
6896  - dot(_2("<i|mu_z|j>"), T1_recomp("i,A'") * T1_recomp("j,A'") )
6897  + dot(_2("<A'|mu_z|B'>"), T1_recomp("i,A'") * T1_recomp("i,B'") );
6898  std::cout << "Mu_z (2)_S = " << 2*mu_z_e << std::endl; // 2 accounts for spin degeneracy
6899  std::cout << "Mu_z ref = " << (dot(_2("<i|mu_z|j>"),_2("<i|gamma|j>")))
6900  << std::endl; // 2 is included in gamma!
6901  }
6902 
6903  // compute the (2)_S quadrupole moment
6904  {
6905  const double q_zz_e = 2*dot(_2("<i|q_zz|A'>"), T1_recomp("i,A'"))
6906  - dot(_2("<i|q_zz|j>"), T1_recomp("i,A'") * T1_recomp("j,A'") )
6907  + dot(_2("<A'|q_zz|B'>"), T1_recomp("i,A'") * T1_recomp("i,B'") );
6908  std::cout << "Q_zz (2)_S = " << 2*q_zz_e << std::endl; // 2 accounts for spin degeneracy
6909  std::cout << "Q_zz ref = " << (dot(_2("<i|q_zz|j>"),_2("<i|gamma|j>")))
6910  << std::endl; // 2 is included in gamma!
6911  }
6912 
6913  // compute orbital rotation multipliers in the (2)_S Lagrangian
6914  if (1) {
6915  TArray2 Tia = T1_recomp("j,A'") * _2("<A'|I|a>");
6916  TArray2 Xia_1 = 2* (_2("<i|F|j>") * Tia("j,a") - T1_recomp("i,B'") * _2("<B'|F|a>"))
6917  + 2 * _2("<i|F|C'>") * T1_recomp("j,C'") * Tia("j,a")
6918  - 2 * (2 * _4("<j i|g|B' a>") - _4("<j i|g|a B'>") + 2 * _4("<j a|g|B' i>") - _4("<j a|g|i B'>")) * T1_recomp("j,B'")
6919  - 2 * (2 * _4("<B' i|g|C' a>") - _4("<B' i|g|a C'>")) * T1_recomp("j,B'") * T1_recomp("j,C'")
6920  + 2 * (2 * _4("<j i|g|k a>") - _4("<j i|g|a k>")) * T1_recomp("j,B'") * T1_recomp("k,B'");
6921  std::cout << "Xia_1, should not be 0:\n" << Xia_1 << std::endl;
6922 
6923  TArray2 Faa = _2("<a|F|b>");
6924  TArray4 G_ij_ab = _4("<i j|g|a b>");
6925  TArray4 G_ia_jb = _4("<i a|g|j b>");
6926  detail::_OrbResponse<double> response_lhs_eval(Faa, Fii, G_ij_ab, G_ia_jb);
6927 
6928  TA::ConjugateGradientSolver<Array, detail::_OrbResponse<double> > cg_solver;
6929  Array kappa = Xia_1;
6930 
6931  // make preconditioner: Delta_ia = <i|F|i> - <a|F|a>
6932  typedef detail::diag_precond2<double> pceval_type;
6933  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
6934  TArray2d Delta_ia(Xia_1.world(), Xia_1.trange());
6935  pceval_type Delta_ia_gen(TA::array_to_eigen(Fii),
6936  TA::array_to_eigen(Faa));
6937 
6938  // construct local tiles
6939  for(auto t=Delta_ia.trange().tiles_range().begin();
6940  t!=Delta_ia.trange().tiles_range().end();
6941  ++t)
6942  if (Delta_ia.is_local(*t)) {
6943  std::array<std::size_t, 2> index; std::copy(t->begin(), t->end(), index.begin());
6944  madness::Future < typename TArray2d::value_type >
6945  tile((LazyTensor<T, 2, pceval_type >(&Delta_ia, index, &Delta_ia_gen)
6946  ));
6947 
6948  // Insert the tile into the array
6949  Delta_ia.set(*t, tile);
6950  }
6951  Array preconditioner = Delta_ia("i,a");
6952 
6953  // solves orbital response using CG
6954  auto resnorm = cg_solver(response_lhs_eval,
6955  Xia_1,
6956  kappa,
6957  preconditioner,
6958  1e-10);
6959  std::cout << "Converged CG to " << resnorm << std::endl;
6960 
6961  // verify the solution:
6962  {
6963  TArray2 res = Xia_1;
6964  response_lhs_eval(kappa, res);
6965  std::cout << "should be zero = " << TA::expressions::norm2(res("i,a") - Xia_1("i,a"));
6966  }
6967 
6968  const double mu_z_e = dot(kappa("i,a"), _2("<i|mu_z|a>"));
6969  std::cout << "mu_z_e (orb response) = " << 2*mu_z_e << std::endl;
6970 
6971  }
6972  }
6973 
6974  // now recompute T1_cabs and E2_cabs using only CABS for perturbation!
6975  {
6976  std::cout << "computing E2_cabs due to CABS only as the first-order space\n";
6977  typedef TiledArray::Array<T,2> Array;
6978  Array Fii = _2("<i|F|j>");
6979  Array FAA = _2("<a'|F|b'>");
6980  // this computes Z_i^a' = T_i^b' F_b'^a' - F_i^j T_j^a'
6981  detail::_CABS_singles_h0t1<double> cabs_singles_rhs_eval(FAA, Fii);
6982 
6983  TA::ConjugateGradientSolver<Array, detail::_CABS_singles_h0t1<double> > cg_solver;
6984  Array FiA = _2("<i|F|a'>");
6985  Array minus_FiA = -1.0 * FiA("i,a'");
6986  Array T1_recomp = FiA;
6987 
6988  // make preconditioner: Delta_iA = <i|F|i> - <a'|F|a'>
6989  typedef detail::diag_precond2<double> pceval_type;
6990  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
6991  TArray2d Delta_iA(FiA.world(), FiA.trange());
6992  pceval_type Delta_iA_gen(TA::array_to_eigen(Fii),
6993  TA::array_to_eigen(FAA));
6994 
6995  // construct local tiles
6996  for(auto t=Delta_iA.trange().tiles_range().begin();
6997  t!=Delta_iA.trange().tiles_range().end();
6998  ++t)
6999  if (Delta_iA.is_local(*t)) {
7000  std::array<std::size_t, 2> index; std::copy(t->begin(), t->end(), index.begin());
7001  madness::Future < typename TArray2d::value_type >
7002  tile((LazyTensor<T, 2, pceval_type >(&Delta_iA, index, &Delta_iA_gen)
7003  ));
7004 
7005  // Insert the tile into the array
7006  Delta_iA.set(*t, tile);
7007  }
7008  Array preconditioner = Delta_iA("i,a'");
7009 
7010 #if 0
7011  std::cout << "FiA:\n" << FiA << std::endl;
7012  std::cout << "Fii:\n" << Fii << std::endl;
7013  std::cout << "FAA:\n" << FAA << std::endl;
7014  std::cout << "preconditioner:\n" << preconditioner << std::endl;
7015 #endif
7016 
7017  // solves CABS singles equations T_i^B' F_B'^A' - F_i^j T_j^A' = -F_i^A' using CG
7018  auto resnorm = cg_solver(cabs_singles_rhs_eval,
7019  minus_FiA,
7020  T1_recomp,
7021  preconditioner,
7022  1e-10);
7023  std::cout << "Converged CG to " << resnorm << std::endl;
7024  const double E2_cabs = 2.0 * dot(T1_recomp("i,a'"), _2("<i|F|a'>")); // 2 accounts for spin
7025  std::cout << "E2_cabs (re-recomputed) = " << E2_cabs << std::endl;
7026 
7027  // compute the (2)_S dipole moment
7028  {
7029  const double mu_z_e = 2*dot(_2("<i|mu_z|a'>"), T1_recomp("i,a'"))
7030  - dot(_2("<i|mu_z|j>"), T1_recomp("i,a'") * T1_recomp("j,a'") )
7031  + dot(_2("<a'|mu_z|b'>"), T1_recomp("i,a'") * T1_recomp("i,b'") );
7032  std::cout << "Mu_z (2)_S = " << 2*mu_z_e << std::endl; // 2 accounts for spin degeneracy
7033  }
7034 
7035  // compute orbital rotation multipliers in the (2)_S Lagrangian
7036  if (1) {
7037  // only include the first-order terms in the Lagrangian derivative
7038  TArray2 Xia_1 = - 2 * T1_recomp("i,b'") * _2("<b'|F|a>")
7039  - 2 * (2 * _4("<j i|g|b' a>") - _4("<j i|g|a b'>") + 2 * _4("<j a|g|b' i>") - _4("<j a|g|i b'>")) * T1_recomp("j,b'")
7040  - 2 * (2 * _4("<b' i|g|c' a>") - _4("<b' i|g|a c'>")) * T1_recomp("j,b'") * T1_recomp("j,c'")
7041  + 2 * (2 * _4("<j i|g|k a>") - _4("<j i|g|a k>")) * T1_recomp("j,b'") * T1_recomp("k,b'");
7042  std::cout << "Xia_1, should not be 0:\n" << Xia_1 << std::endl;
7043 
7044  TArray2 Faa = _2("<a|F|b>");
7045  TArray4 G_ij_ab = _4("<i j|g|a b>");
7046  TArray4 G_ia_jb = _4("<i a|g|j b>");
7047  detail::_OrbResponse<double> response_lhs_eval(Faa, Fii, G_ij_ab, G_ia_jb);
7048 
7049  TA::ConjugateGradientSolver<Array, detail::_OrbResponse<double> > cg_solver;
7050  Array kappa = Xia_1;
7051 
7052  // make preconditioner: Delta_ia = <i|F|i> - <a|F|a>
7053  typedef detail::diag_precond2<double> pceval_type;
7054  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
7055  TArray2d Delta_ia(Xia_1.world(), Xia_1.trange());
7056  pceval_type Delta_ia_gen(TA::array_to_eigen(Fii),
7057  TA::array_to_eigen(Faa));
7058 
7059  // construct local tiles
7060  for(auto t=Delta_ia.trange().tiles_range().begin();
7061  t!=Delta_ia.trange().tiles_range().end();
7062  ++t)
7063  if (Delta_ia.is_local(*t)) {
7064  std::array<std::size_t, 2> index; std::copy(t->begin(), t->end(), index.begin());
7065  madness::Future < typename TArray2d::value_type >
7066  tile((LazyTensor<T, 2, pceval_type >(&Delta_ia, index, &Delta_ia_gen)
7067  ));
7068 
7069  // Insert the tile into the array
7070  Delta_ia.set(*t, tile);
7071  }
7072  Array preconditioner = Delta_ia("i,a");
7073 
7074  // solves orbital response using CG
7075  auto resnorm = cg_solver(response_lhs_eval,
7076  Xia_1,
7077  kappa,
7078  preconditioner,
7079  1e-10);
7080  std::cout << "Converged CG to " << resnorm << std::endl;
7081  const double mu_z_e = dot(kappa("i,a"), _2("<i|mu_z|a>"));
7082  std::cout << "mu_z_e (orb reponse) = " << 2*mu_z_e << std::endl;
7083 
7084  }
7085  }
7086 
7087  // compute T1_obs and E2_obs
7088  {
7089  std::cout << "computing E2_obs (virtuals is the first-order space)\n";
7090  typedef TiledArray::Array<T,2> Array;
7091  Array Fii = _2("<i|F|j>");
7092  Array FAA = _2("<a|F|b>");
7093  // this computes Z_i^a = T_i^b F_b^a - F_i^j T_j^a
7094  detail::_CABS_singles_h0t1<double> cabs_singles_rhs_eval(FAA, Fii);
7095 
7096  TA::ConjugateGradientSolver<Array, detail::_CABS_singles_h0t1<double> > cg_solver;
7097  Array FiA = _2("<i|F|a>");
7098  Array minus_FiA = -1.0 * FiA("i,a");
7099  Array T1_obs = FiA;
7100 
7101  // make preconditioner: Delta_iA = <i|F|i> - <a|F|a>
7102  typedef detail::diag_precond2<double> pceval_type;
7103  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
7104  TArray2d Delta_iA(FiA.world(), FiA.trange());
7105  pceval_type Delta_iA_gen(TA::array_to_eigen(Fii),
7106  TA::array_to_eigen(FAA));
7107 
7108  // construct local tiles
7109  for(auto t=Delta_iA.trange().tiles_range().begin();
7110  t!=Delta_iA.trange().tiles_range().end();
7111  ++t)
7112  if (Delta_iA.is_local(*t)) {
7113  std::array<std::size_t, 2> index; std::copy(t->begin(), t->end(), index.begin());
7114  madness::Future < typename TArray2d::value_type >
7115  tile((LazyTensor<T, 2, pceval_type >(&Delta_iA, index, &Delta_iA_gen)
7116  ));
7117 
7118  // Insert the tile into the array
7119  Delta_iA.set(*t, tile);
7120  }
7121  Array preconditioner = Delta_iA("i,a");
7122 
7123 #if 0
7124  std::cout << "FiA:\n" << FiA << std::endl;
7125  std::cout << "Fii:\n" << Fii << std::endl;
7126  std::cout << "FAA:\n" << FAA << std::endl;
7127  std::cout << "preconditioner:\n" << preconditioner << std::endl;
7128 #endif
7129 
7130  // solves CABS singles equations T_i^B' F_B'^A' - F_i^j T_j^A' = -F_i^A' using CG
7131  auto resnorm = cg_solver(cabs_singles_rhs_eval,
7132  minus_FiA,
7133  T1_obs,
7134  preconditioner,
7135  1e-10);
7136  std::cout << "Converged CG to " << resnorm << std::endl;
7137  // same as the lagrangian since solved for T1 exactly
7138  const double E2_obs = 2.0 * dot(T1_obs("i,a"), _2("<i|F|a>")); // 2 accounts for spin
7139  std::cout << "E2_obs = " << E2_obs << std::endl;
7140  const double E0_obs = dot(_2("<i|F|j>"), _2("<i|gamma|j>")); // 2 included in gamma
7141  std::cout << "E0_obs = " << scprintf("%15.10lf",E0_obs) << std::endl;
7142 
7143  // compute the (2)_S dipole moment
7144  {
7145  const double mu_z_e = 2*dot(_2("<i|mu_z|a>"), T1_obs("i,a"))
7146  - dot(_2("<i|mu_z|j>"), T1_obs("i,a") * T1_obs("j,a") )
7147  + dot(_2("<a|mu_z|b>"), T1_obs("i,a") * T1_obs("i,b") );
7148  std::cout << scprintf("Mu_z (2)_S OBS = %25.15lf", 2*mu_z_e) << std::endl; // 2 accounts for spin degeneracy
7149  std::cout << scprintf("Mu_z ref = %25.15lf", (dot(_2("<i|mu_z|j>"),_2("<i|gamma|j>")))) << std::endl;
7150  }
7151 
7152  // compute orbital rotation multipliers in the (2)_S OBS Lagrangian
7153  if (1) {
7154  // only include the first-order terms in the Lagrangian derivative
7155  TArray2 Xia_1 = _2("<i|F|j>") * T1_obs("j,a") - T1_obs("i,b") * _2("<b|F|a>")
7156  + 2 * _2("<i|F|c>") * T1_obs("j,c") * T1_obs("j,a")
7157  + 2 * T1_obs("i,c") * T1_obs("j,c") * _2("<j|F|a>")
7158  ;
7159  std::cout << "Xia_1, should not be 0:\n" << Xia_1 << std::endl;
7160  TArray2 Fia = _2("<i|F|a>");
7161  std::cout << "Fia, should be close to Xia_1:\n" << Fia << std::endl;
7162 
7163  TArray2 Faa = _2("<a|F|b>");
7164  TArray4 G_ij_ab = _4("<i j|g|a b>");
7165  TArray4 G_ia_jb = _4("<i a|g|j b>");
7166  detail::_OrbResponse<double> response_lhs_eval(Faa, Fii, G_ij_ab, G_ia_jb);
7167 
7168  TA::ConjugateGradientSolver<Array, detail::_OrbResponse<double> > cg_solver;
7169  Array kappa = Xia_1;
7170 
7171  // make preconditioner: Delta_ia = <i|F|i> - <a|F|a>
7172  typedef detail::diag_precond2<double> pceval_type;
7173  typedef TA::Array<T, 2, LazyTensor<T, 2, pceval_type > > TArray2d;
7174  TArray2d Delta_ia(Xia_1.world(), Xia_1.trange());
7175  pceval_type Delta_ia_gen(TA::array_to_eigen(Fii),
7176  TA::array_to_eigen(Faa));
7177 
7178  // construct local tiles
7179  for(auto t=Delta_ia.trange().tiles_range().begin();
7180  t!=Delta_ia.trange().tiles_range().end();
7181  ++t)
7182  if (Delta_ia.is_local(*t)) {
7183  std::array<std::size_t, 2> index; std::copy(t->begin(), t->end(), index.begin());
7184  madness::Future < typename TArray2d::value_type >
7185  tile((LazyTensor<T, 2, pceval_type >(&Delta_ia, index, &Delta_ia_gen)
7186  ));
7187 
7188  // Insert the tile into the array
7189  Delta_ia.set(*t, tile);
7190  }
7191  Array preconditioner = Delta_ia("i,a");
7192 
7193  // solves orbital response using CG
7194  auto resnorm = cg_solver(response_lhs_eval,
7195  Xia_1,
7196  kappa,
7197  preconditioner,
7198  1e-10);
7199  std::cout << "Converged CG to " << resnorm << std::endl;
7200  std::cout << scprintf("E_2 (orb reponse) = %25.15lf", 2*dot(kappa("i,a"), _2("<i|F|a>"))) << std::endl;
7201  const double mu_z_e = dot(kappa("i,a"), _2("<i|mu_z|a>"));
7202  std::cout << scprintf("mu_z_e (orb reponse) = %25.15lf", 2*mu_z_e) << std::endl;
7203 
7204  }
7205  }
7206 
7207  if (1) {
7208  for(int i=0; i<10; ++i) {
7209  TArray4 should_be_zero = _4("<b j|g|a i>") - _4("<b i|g|a j>");
7210  std::cout << "should be 0: " << TA::expressions::norminf(should_be_zero("b,j,a,i")) << std::endl;
7211  }
7212  }
7213 #endif
7214 
7216  TArray2 r2_i_j;
7217  //r2_i_j("i,j") = _4("<i j|r|p q>") * _4("<k_F(p) j|r|p q>");
7218 
7219  return r2_i_j;
7220 #else // ENABLE_SRR12_RDM1
7221  MPQC_ASSERT(false); // not converted yet to the TiledArray expressions branch
7222  return TArray2();
7223 #endif
7224  }
7225 
7226  template <typename T>
7229 
7230  TArray4 V_ij_mn;
7231  V_ij_mn("i1,i2,m1,m2") = _4("<i1 i2|gr|m1 m2>") - _4("<i1 i2|r|p1 p2>") * _4("<m1 m2|g|p1 p2>")
7232  - _4("<i1 i2|r|m3_gamma(m) a'>") * _4("<m1 m2|g|m3 a'>");
7233 
7234  if (symmetrize_p1_p2)
7235  V_ij_mn("i1,i2,m1,m2") = 0.5 * (V_ij_mn("i1,i2,m1,m2") + V_ij_mn("i2,i1,m2,m1"));
7236 
7237  return V_ij_mn;
7238  }
7239 
7240  template <typename T>
7243 
7244  TArray4 X_ij_kl;
7245  X_ij_kl("i1,i2,j1,j2") = _4("<i1 i2|r2|j1 j2>") - _4("<i1 i2|r|p1 p2>") * _4("<j1 j2|r|p1 p2>")
7246  - _4("<i1 i2|r|m3_gamma(m) a'>") * _4("<j1 j2|r|m3 a'>");
7247 
7248  if (symmetrize_p1_p2)
7249  X_ij_kl("i1,i2,j1,j2") = 0.5 * (X_ij_kl("i1,i2,j1,j2") + X_ij_kl("i2,i1,j2,j1"));
7250 
7251  return X_ij_kl;
7252  }
7253 
7254  template <typename T>
7257 
7258  TArray4 B_ij_kl;
7259  B_ij_kl("i1,i2,j1,j2") =
7260 
7261  // everything seems scaled up by factor of 2 relative to Eq.(12) in J. Chem. Phys. 135, 214105 (2011),
7262  // due to including particle 1 and particle 2 contributions?
7263 
7264  // diag Q
7265  _4("<i1 i2|rTr|j1 j2>") + 2.0 * _4("<i1 i2|r2|j1 j2_hJ(p')>")
7266 
7267  // rKr
7268  - 2.0 * _4("<i1 i2|r|r' s'>") * _4("<j1 j2|r|r' s'_K(p')>")
7269 
7270  // rFr
7271  - 2.0 * _4("<i1 i2|r|r s>") * _4("<j1 j2|r|r s_F(p)>")
7272 
7273  // rFr_2, extra 2 due to bra-ket symmetrization
7274  - 4.0 * _4("<i1 i2|r|r s>") * _4("<j1 j2|r|r s_F(a')>")
7275 
7276  // rFGr
7277  - _4("<i1 i2|r|n_gamma(m) b'>") * _4("<j1 j2|r|n b'_F(a')>")
7278 
7279  // rFGr_2
7280  - _4("<i1 i2|r|n_gamma(m) a'>") * _4("<j1 j2|r|n_F(p') a'>");
7281 
7282  B_ij_kl("i1,i2,j1,j2") = 0.5
7283  * (B_ij_kl("i1,i2,j1,j2") + B_ij_kl("i2,i1,j2,j1"));
7284  B_ij_kl("i1,i2,j1,j2") = 0.5
7285  * (B_ij_kl("i1,i2,j1,j2") + B_ij_kl("j1,j2,i1,i2"));
7286 
7287  if (symmetrize_p1_p2)
7288  B_ij_kl("i1,i2,j1,j2") = 0.5
7289  * (B_ij_kl("i1,i2,j1,j2") + B_ij_kl("i2,i1,j2,j1"));
7290 
7291  return B_ij_kl;
7292  }
7293 
7294 
7295 }; // end of namespace sc
7296 
7297 #endif // end of header guard
7298 
7299 
7300 // Local Variables:
7301 // mode: c++
7302 // c-file-style: "CLJ-CONDENSED"
7303 // End:
sc::SingleReference_R12Intermediates::V_diag
std::pair< TArray2, TArray2 > V_diag()
computes diagonal (spin-restricted, for now) V intermediate
Definition: sr_r12intermediates_VXB_diag.h:433
sc::OrbitalSpace::evals
const RefDiagSCMatrix & evals() const
Returns the "eigenvalues" matrix.
sc::detail::Orbital_relaxation_Abjai::Orbital_relaxation_Abjai
Orbital_relaxation_Abjai(const Array4 &a_bjai)
Definition: sr_r12intermediates_VXB_diag.h:708
sc::detail::diag_precond4
makes a diagonal 4-index preconditioner: pc_xy^zw = -1/ ( <x|O1|x> + <y|O2|y> - <z|O3|z> - <w|O4|w> )
Definition: sr_r12intermediates_VXB_diag.h:679
sc::detail::Orbital_relaxation_Abjai
Definition: sr_r12intermediates_VXB_diag.h:700
sc::detail::_OrbResponse::_OrbResponse
_OrbResponse(const Array2 &f_AB, const Array2 &f_ij, const Array4 &g_ij_ab, const Array4 &g_ia_jb)
Definition: sr_r12intermediates_VXB_diag.h:638
sc::SingleReference_R12Intermediates::compute_multipole
void compute_multipole()
Definition: sr_r12intermediates_VXB_diag.h:4163
sc::SingleReference_R12Intermediates::X_diag
std::pair< TArray2, TArray2 > X_diag()
computes diagonal (spin-restricted, for now) X intermediate
Definition: sr_r12intermediates_VXB_diag.h:453
sc::Ref
A template class that maintains references counts.
Definition: ref.h:361
sc::detail::_CABS_singles_h0t1
this functor helps to implement conjugate gradient CABS singles solver
Definition: sr_r12intermediates_VXB_diag.h:600
sc::SingleReference_R12Intermediates::gf2_r12
void gf2_r12(int orbital)
Computes second-order Green's function IPs and EAs \parame orbital the index of the orbital,...
Definition: sr_r12intermediates_VXB_diag.h:513
sc::SingleReference_R12Intermediates::TArray4d
TA::Array< T, 4, DA4_Tile< T > > TArray4d
4-index tensor with lazy tiles
Definition: sr_r12intermediates.h:224
sc::SingleReference_R12Intermediates::compute_multipole_F12b_coupling
void compute_multipole_F12b_coupling()
Definition: sr_r12intermediates_VXB_diag.h:6242
sc::SingleReference_R12Intermediates::TArray2
TA::Array< T, 2 > TArray2
standard 2-index tensor
Definition: sr_r12intermediates.h:226
sc::detail::Orbital_relaxation_Abjai::operator()
void operator()(const Array2 &K_bj, Array2 &R1)
Definition: sr_r12intermediates_VXB_diag.h:718
sc::OrbitalSpace::rank
unsigned int rank() const
Returns the rank of the space.
sc::SingleReference_R12Intermediates::B_diag
std::pair< TArray2, TArray2 > B_diag()
computes diagonal (spin-restricted, for now) B intermediate
Definition: sr_r12intermediates_VXB_diag.h:473
sc::SingleReference_R12Intermediates
SingleReference_R12Intermediates computes R12/F12 intermediates using MPQC3 runtime.
Definition: sr_r12intermediates.h:218
sc::SingleReference_R12Intermediates::TArray2d
TA::Array< T, 2, DA4_Tile< T > > TArray2d
2-index tensor with lazy tiles
Definition: sr_r12intermediates.h:228
sc::detail::selfenergy_denom
makes a pseudo-3-index (4-index, but first index is dummy) self-energy denominator: (se_den)_{xyz} = ...
Definition: sr_r12intermediates_VXB_diag.h:491
sc::detail::diag_precond2
makes a diagonal 2-index preconditioner: pc_x^y = -1/ ( <x|O1|x> - <y|O2|y> )
Definition: sr_r12intermediates_VXB_diag.h:662
sc::detail::_OrbResponse
this functor helps to implement orbital response
Definition: sr_r12intermediates_VXB_diag.h:627
sc::LazyTensor
Tile of a DIM-order tensor that's "evaluated" when needed by calling ElementGenerator({i0,...
Definition: sr_r12intermediates.h:125
sc::detail::_CABS_singles_h0t1::_CABS_singles_h0t1
_CABS_singles_h0t1(const Array &h0_AB, const Array &h0_ij)
Definition: sr_r12intermediates_VXB_diag.h:608
sc::SingleReference_R12Intermediates::TArray4
TA::Array< T, 4 > TArray4
standard 4-index tensor
Definition: sr_r12intermediates.h:222
sc::SingleReference_R12Intermediates::B_spinfree
TArray4 B_spinfree(bool symmetrize_p1_p2=false)
computes spin-free B intermediate
Definition: sr_r12intermediates_VXB_diag.h:7256
sc::SingleReference_R12Intermediates::X_spinfree
TArray4 X_spinfree(bool symmetrize_p1_p2=false)
computes spin-free X intermediate
Definition: sr_r12intermediates_VXB_diag.h:7242
sc::ExEnv::out0
static std::ostream & out0()
Return an ostream that writes from node 0.
sc::Molecule::natom
size_t natom() const
Returns the number of atoms in the molecule.
Definition: molecule.h:327
sc::detail::_OrbResponse::operator()
void operator()(const Array2 &kappa, Array2 &residual)
Definition: sr_r12intermediates_VXB_diag.h:652
sc::detail::_CABS_singles_h0t1::operator()
void operator()(const Array &T1, Array &R1)
Definition: sr_r12intermediates_VXB_diag.h:619
sc::scprintf
This class allows printf-like output to be sent to an ostream.
Definition: formio.h:97
sc
Contains all MPQC code up to version 3.
Definition: mpqcin.h:14
sc::detail::e_ij
Definition: sr_r12intermediates_VXB_diag.h:725
sc::SingleReference_R12Intermediates::V_spinfree
TArray4 V_spinfree(bool symmetrize_p1_p2=false)
computes spin-free V intermediate
Definition: sr_r12intermediates_VXB_diag.h:7228
sc::SingleReference_R12Intermediates::rdm1
TArray2 rdm1()
returns the 1-particle reduced density matrix
Definition: sr_r12intermediates_VXB_diag.h:6783

Generated at Sun Jan 26 2020 23:23:59 for MPQC 3.0.0-alpha using the documentation package Doxygen 1.8.16.