@@ -68,11 +68,19 @@ def gfock_sym(mc, mo_coeff, casdm1, casdm2, h1e, eris):
68
68
def xc_response (ot , vot , rho , Pi , weights , moval_occ , aoval , mo_occ , mo_occup , ncore , nocc , casdm2_pack , ndpi , mo_cas ):
69
69
vrho , vPi = vot
70
70
71
+
71
72
# Vpq + Vpqrs * Drs ; I'm not sure why the list comprehension down
72
73
# there doesn't break ao's stride order but I'm not complaining
73
74
vrho = _contract_eff_rho (vPi , rho .sum (0 ), add_eff_rho = vrho )
74
- tmp_dv = np .stack ([ot .get_veff_1body (rho , Pi , [ao_i , moval_occ ], weights , kern = vrho ) for ao_i in aoval ], axis = 0 )
75
- tmp_dv = (tmp_dv * mo_occ [None ,:,:] * mo_occup [None , None ,:nocc ]).sum (2 )
75
+
76
+ tmp_dv = np .stack (
77
+ [
78
+ ot .get_veff_1body (rho , Pi , [ao_i , moval_occ ], weights , kern = vrho )
79
+ for ao_i in aoval
80
+ ],
81
+ axis = 0 ,
82
+ )
83
+ tmp_dv = (tmp_dv * mo_occ [None , :, :] * mo_occup [None , None , :nocc ]).sum (2 )
76
84
77
85
# Vpuvx * Lpuvx ; remember the stupid slowest->fastest->medium
78
86
# stride order of the ao grid arrays
@@ -202,7 +210,7 @@ def mcpdft_HellmanFeynman_grad (mc, ot, veff1, veff2, mo_coeff=None, ci=None,
202
210
casdm1 , casdm2 = mc .fcisolver .make_rdm12 (ci , ncas , nelecas )
203
211
twoCDM = _dms .dm2_cumulant (casdm2 , casdm1 )
204
212
dm1 = tag_array (dm1 , mo_coeff = mo_occ , mo_occ = mo_occup [:nocc ])
205
- make_rho = ot ._numint ._gen_rho_evaluator (mol , dm1 , 1 )[0 ]
213
+ make_rho = ot ._numint ._gen_rho_evaluator (mol , dm1 , hermi = 1 , with_lapl = False )[0 ]
206
214
dvxc = np .zeros ((3 ,nao ))
207
215
idx = np .array ([[1 ,4 ,5 ,6 ],[2 ,5 ,7 ,8 ],[3 ,6 ,8 ,9 ]], dtype = np .int_ )
208
216
# For addressing particular ao derivatives
@@ -215,9 +223,13 @@ def mcpdft_HellmanFeynman_grad (mc, ot, veff1, veff2, mo_coeff=None, ci=None,
215
223
for k , ia in enumerate (atmlst ):
216
224
full_atmlst [ia ] = k
217
225
218
- ndao = (1 , 4 )[ot .dens_deriv ]
226
+ # for LDA we need 1 deriv, GGA: 2 deriv
227
+ # for mGGA with tau, we only need 2 deriv
228
+ ao_deriv = (1 , 2 , 2 )[ot .dens_deriv ]
229
+ ndao = (1 , 4 , 10 )[ao_deriv ]
230
+ ndrho = (1 , 4 , 5 )[ot .dens_deriv ]
219
231
ndpi = (1 , 4 )[ot .Pi_deriv ]
220
- ncols = 1.05 * 3 * (ndao * (nao + nocc ) + max (ndao * nao , ndpi * ncas * ncas ))
232
+ ncols = 1.05 * 3 * (ndao * (nao + nocc ) + max (ndrho * nao , ndpi * ncas * ncas ))
221
233
222
234
for ia , (coords , w0 , w1 ) in enumerate (rks_grad .grids_response_cc (
223
235
ot .grids )):
@@ -235,27 +247,39 @@ def mcpdft_HellmanFeynman_grad (mc, ot, veff1, veff2, mo_coeff=None, ci=None,
235
247
blksize = max (BLKSIZE , min (blksize , ngrids , BLKSIZE * 1200 ))
236
248
t1 = logger .timer (mc , 'PDFT HlFn quadrature atom {} mask and memory '
237
249
'setup' .format (ia ), * t1 )
238
- for ip0 in range (0 , ngrids , blksize ):
239
- ip1 = min (ngrids , ip0 + blksize )
240
- mask = gen_grid .make_mask (mol , coords [ip0 :ip1 ])
241
- logger .info (mc , ('PDFT gradient atom {} slice {}-{} of {} '
242
- 'total' ).format (ia , ip0 , ip1 , ngrids ))
243
- ao = ot ._numint .eval_ao (mol , coords [ip0 :ip1 ],
244
- deriv = ot .dens_deriv + 1 , non0tab = mask )
250
+
251
+ for ip0 in range (0 , ngrids , blksize ):
252
+ ip1 = min (ngrids , ip0 + blksize )
253
+ mask = gen_grid .make_mask (mol , coords [ip0 :ip1 ])
254
+ logger .info (
255
+ mc ,
256
+ ("PDFT gradient atom {} slice {}-{} of {} total" ).format (
257
+ ia , ip0 , ip1 , ngrids
258
+ ),
259
+ )
260
+
261
+ ao = ot ._numint .eval_ao (mol , coords [ip0 :ip1 ], deriv = ao_deriv , non0tab = mask )
262
+
245
263
# Need 1st derivs for LDA, 2nd for GGA, etc.
246
- t1 = logger .timer (mc , ('PDFT HlFn quadrature atom {} ao '
247
- 'grids' ).format (ia ), * t1 )
264
+ t1 = logger .timer (
265
+ mc , ("PDFT HlFn quadrature atom {} ao " "grids" ).format (ia ), * t1
266
+ )
248
267
# Slice down ao so as not to confuse the rho and Pi generators
249
- if ot .xctype == ' LDA' :
268
+ if ot .xctype == " LDA" :
250
269
aoval = ao [0 ]
251
- if ot .xctype == ' GGA' :
270
+ elif ot .xctype == " GGA" :
252
271
aoval = ao [:4 ]
272
+ elif ot .xctype == "MGGA" :
273
+ aoval = ao [:4 ]
274
+ else :
275
+ raise ValueError ("Unknown xctype: {}" .format (ot .xctype ))
276
+
253
277
rho = make_rho (0 , aoval , mask , ot .xctype ) / 2.0
254
278
rho = np .stack ((rho ,)* 2 , axis = 0 )
255
279
t1 = logger .timer (mc , ('PDFT HlFn quadrature atom {} rho '
256
280
'calc' ).format (ia ), * t1 )
257
281
Pi = get_ontop_pair_density (ot , rho , aoval , twoCDM , mo_cas ,
258
- ot .dens_deriv , mask )
282
+ ot .Pi_deriv , mask )
259
283
t1 = logger .timer (mc , ('PDFT HlFn quadrature atom {} Pi '
260
284
'calc' ).format (ia ), * t1 )
261
285
0 commit comments