Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Two- and three-center electron repulsion integrals with owning backend workspaces.
10 : !> Currently available operators: Coulomb, Truncated Coulomb, Short Range (erfc), Overlap
11 : !> \author A. Bussy (05.2019)
12 : ! **************************************************************************************************
13 :
14 : MODULE libint_2c_3c
15 : USE ai_coulomb, ONLY: coulomb2,&
16 : coulomb3
17 : USE input_constants, ONLY: do_potential_coulomb,&
18 : do_potential_id,&
19 : do_potential_mix_cl_trunc,&
20 : do_potential_short,&
21 : do_potential_truncated
22 : USE integral_library_types, ONLY: active_integral_library,&
23 : coulomb_operator_type,&
24 : cutoff_screen_factor,&
25 : library_libint,&
26 : library_native
27 : USE kinds, ONLY: dp
28 : USE libint_wrapper, ONLY: &
29 : cp_libint_cleanup_2eri, cp_libint_cleanup_2eri1, cp_libint_cleanup_3eri, &
30 : cp_libint_cleanup_3eri1, cp_libint_get_2eri_derivs, cp_libint_get_2eris, &
31 : cp_libint_get_3eri_derivs, cp_libint_get_3eris, cp_libint_init_2eri, cp_libint_init_2eri1, &
32 : cp_libint_init_3eri, cp_libint_init_3eri1, cp_libint_set_contrdepth, &
33 : cp_libint_set_params_eri, cp_libint_set_params_eri_deriv, cp_libint_t, &
34 : eri_primitive_data_type, libint_max_am, prim_data_f_size
35 : USE mathconstants, ONLY: pi
36 : USE orbital_pointers, ONLY: nco,&
37 : ncoset
38 : USE r12_fundamentals, ONLY: compute_r12_fundamentals
39 : USE t_c_g0, ONLY: get_lmax_init
40 : #include "./base/base_uses.f90"
41 :
42 : IMPLICIT NONE
43 : PRIVATE
44 :
45 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'libint_2c_3c'
46 :
47 : PUBLIC :: compute_coulomb_2c, compute_coulomb_3c, compute_coulomb_3c_derivs, compute_coulomb_2c_derivs, &
48 : coulomb_integral_init, coulomb_integral_cleanup, coulomb_integral_max_am
49 :
50 : ! Compiled angular-momentum capability, exposed through the common Coulomb interface.
51 : INTEGER, PARAMETER :: coulomb_integral_max_am = libint_max_am
52 :
53 : TYPE, PUBLIC :: coulomb_integral_context_type
54 : PRIVATE
55 : TYPE(cp_libint_t), ALLOCATABLE :: lib_2c, lib_3c
56 : INTEGER :: library_2c = library_native, library_3c = library_native
57 : INTEGER :: derivative_order_2c = -1, derivative_order_3c = -1
58 : REAL(dp), ALLOCATABLE :: derivative_work_2c(:, :), derivative_work_3c(:, :)
59 :
60 : END TYPE coulomb_integral_context_type
61 :
62 : CONTAINS
63 :
64 : ! **************************************************************************************************
65 : !> \brief Initialize the requested per-thread tasks and record their backend and derivative order.
66 : !> \param context owning task context; pass by reference without intrinsic copying
67 : !> \param max_am_2c maximum two-center angular momentum, if requested
68 : !> \param max_am_3c maximum three-center angular momentum, if requested
69 : !> \param derivative_order zero for values or one for center derivatives
70 : !> \param library optional explicit backend for existing library-specific workflows
71 : ! **************************************************************************************************
72 17991 : SUBROUTINE coulomb_integral_init(context, max_am_2c, max_am_3c, derivative_order, library)
73 : TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
74 : INTEGER, INTENT(IN), OPTIONAL :: max_am_2c, max_am_3c, derivative_order, &
75 : library
76 :
77 : INTEGER :: order
78 :
79 17991 : order = 0
80 17991 : IF (PRESENT(derivative_order)) order = derivative_order
81 17659 : CPASSERT(order == 0 .OR. order == 1)
82 17991 : IF (PRESENT(max_am_2c)) THEN
83 2532 : CPASSERT(context%derivative_order_2c == -1)
84 2532 : context%library_2c = active_integral_library%coulomb2_library
85 2532 : IF (PRESENT(library)) context%library_2c = library
86 5060 : SELECT CASE (context%library_2c)
87 : CASE (library_libint)
88 2528 : ALLOCATE (context%lib_2c)
89 2528 : IF (order == 0) THEN
90 2116 : CALL cp_libint_init_2eri(context%lib_2c, max_am_2c)
91 : ELSE
92 412 : CALL cp_libint_init_2eri1(context%lib_2c, max_am_2c)
93 : END IF
94 2528 : CALL cp_libint_set_contrdepth(context%lib_2c, 1)
95 : CASE (library_native)
96 4 : IF (order /= 0) THEN
97 0 : CPABORT("Native two-center Coulomb derivatives are not implemented by this interface")
98 : END IF
99 : CASE DEFAULT
100 2532 : CPABORT("Requested two-center Coulomb library is not implemented")
101 : END SELECT
102 2532 : context%derivative_order_2c = order
103 : END IF
104 17991 : IF (PRESENT(max_am_3c)) THEN
105 15475 : CPASSERT(context%derivative_order_3c == -1)
106 15475 : context%library_3c = active_integral_library%coulomb3_library
107 15475 : IF (PRESENT(library)) context%library_3c = library
108 30948 : SELECT CASE (context%library_3c)
109 : CASE (library_libint)
110 15473 : ALLOCATE (context%lib_3c)
111 15473 : IF (order == 0) THEN
112 14867 : CALL cp_libint_init_3eri(context%lib_3c, max_am_3c)
113 : ELSE
114 606 : CALL cp_libint_init_3eri1(context%lib_3c, max_am_3c)
115 : END IF
116 15473 : CALL cp_libint_set_contrdepth(context%lib_3c, 1)
117 : CASE (library_native)
118 2 : IF (order /= 0) THEN
119 0 : CPABORT("Native three-center Coulomb derivatives are not implemented by this interface")
120 : END IF
121 : CASE DEFAULT
122 15475 : CPABORT("Requested three-center Coulomb library is not implemented")
123 : END SELECT
124 15475 : context%derivative_order_3c = order
125 : END IF
126 17991 : END SUBROUTINE coulomb_integral_init
127 :
128 : ! **************************************************************************************************
129 : !> \brief Release the initialized tasks and retained derivative scratch of their original owner.
130 : !> \param context owning task context
131 : ! **************************************************************************************************
132 17991 : SUBROUTINE coulomb_integral_cleanup(context)
133 : TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
134 :
135 17991 : IF (context%library_2c == library_libint) THEN
136 2528 : IF (context%derivative_order_2c == 0) CALL cp_libint_cleanup_2eri(context%lib_2c)
137 2528 : IF (context%derivative_order_2c == 1) CALL cp_libint_cleanup_2eri1(context%lib_2c)
138 : END IF
139 17991 : IF (context%library_3c == library_libint) THEN
140 15473 : IF (context%derivative_order_3c == 0) CALL cp_libint_cleanup_3eri(context%lib_3c)
141 15473 : IF (context%derivative_order_3c == 1) CALL cp_libint_cleanup_3eri1(context%lib_3c)
142 : END IF
143 17991 : IF (ALLOCATED(context%lib_2c)) DEALLOCATE (context%lib_2c)
144 17991 : IF (ALLOCATED(context%lib_3c)) DEALLOCATE (context%lib_3c)
145 17991 : IF (ALLOCATED(context%derivative_work_2c)) DEALLOCATE (context%derivative_work_2c)
146 17991 : IF (ALLOCATED(context%derivative_work_3c)) DEALLOCATE (context%derivative_work_3c)
147 17991 : context%derivative_order_2c = -1
148 17991 : context%derivative_order_3c = -1
149 17991 : END SUBROUTINE coulomb_integral_cleanup
150 :
151 : ! **************************************************************************************************
152 : !> \brief Computes the 3-center electron repulsion integrals (ab|c) for a given set of cartesian
153 : !> gaussian orbitals
154 : !> \param context owning per-thread task and derivative scratch
155 : !> \param la_min ...
156 : !> \param la_max ...
157 : !> \param lb_min ...
158 : !> \param lb_max ...
159 : !> \param lc_min ...
160 : !> \param lc_max ...
161 : !> \param npgfa ...
162 : !> \param npgfb ...
163 : !> \param npgfc ...
164 : !> \param zeta ...
165 : !> \param zetb ...
166 : !> \param zetc ...
167 : !> \param rpgfa ...
168 : !> \param rpgfb ...
169 : !> \param rpgfc ...
170 : !> \param ra ...
171 : !> \param rb ...
172 : !> \param rc ...
173 : !> \param int_abc the integrals as array of cartesian orbitals (allocated before hand)
174 : !> \param potential_parameter the info about the potential
175 : !> \param dab optional center distance for primitive screening
176 : !> \param dac optional center distance for primitive screening
177 : !> \param dbc optional center distance for primitive screening
178 : !> \param int_abc_ext the extremal value of int_abc, i.e., MAXVAL(ABS(int_abc))
179 : !> Available for the Libint backend only.
180 : !> \note Prepare shared radial tables before entering a threaded evaluation region.
181 : ! **************************************************************************************************
182 5720009 : SUBROUTINE compute_coulomb_3c(context, la_min, la_max, lb_min, lb_max, lc_min, lc_max, &
183 11440018 : npgfa, npgfb, npgfc, zeta, zetb, zetc, rpgfa, rpgfb, rpgfc, &
184 5720009 : ra, rb, rc, int_abc, potential_parameter, dab, dac, dbc, int_abc_ext)
185 :
186 : TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
187 : INTEGER, INTENT(IN) :: la_min, la_max, lb_min, lb_max, lc_min, &
188 : lc_max, npgfa, npgfb, npgfc
189 : REAL(dp), DIMENSION(:), INTENT(IN) :: zeta, zetb, zetc, rpgfa, rpgfb, rpgfc
190 : REAL(dp), DIMENSION(3), INTENT(IN) :: ra, rb, rc
191 : REAL(dp), DIMENSION(:, :, :), INTENT(INOUT) :: int_abc
192 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
193 : REAL(dp), INTENT(IN), OPTIONAL :: dab, dac, dbc
194 : REAL(dp), INTENT(INOUT), OPTIONAL :: int_abc_ext
195 :
196 : INTEGER :: a_offset, a_start, b_offset, b_start, &
197 : c_offset, c_start, i, ipgf, j, jpgf, &
198 : k, kpgf, li, lj, lk, ncoa, ncob, ncoc, &
199 : op, p1, p2, p3
200 : REAL(dp) :: distance_ab, distance_ac, distance_bc, &
201 : dr_ab, dr_ac, dr_bc, zeti, zetj, zetk
202 5720009 : REAL(dp), DIMENSION(:), POINTER :: p_work
203 : TYPE(eri_primitive_data_type) :: params
204 :
205 0 : CPASSERT(context%derivative_order_3c == 0)
206 :
207 5720009 : IF (context%library_3c == library_native) THEN
208 11340 : BLOCK
209 : INTEGER :: kpgf, nc_end, nc_start, ncoa, ncob, ncoc
210 : REAL(dp) :: rab2, rac2, rbc2
211 1620 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: f_work, gccc, rpgfa_work, rpgfb_work, &
212 1620 : rpgfc_work
213 : REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: vabc
214 : REAL(dp), ALLOCATABLE, DIMENSION(:, :, :, :) :: v_work
215 :
216 1620 : ncoa = npgfa*ncoset(la_max)
217 1620 : ncob = npgfb*ncoset(lb_max)
218 1620 : ncoc = ncoset(lc_max)
219 1620 : rab2 = (rb(1) - ra(1))**2 + (rb(2) - ra(2))**2 + (rb(3) - ra(3))**2
220 1620 : rac2 = (rc(1) - ra(1))**2 + (rc(2) - ra(2))**2 + (rc(3) - ra(3))**2
221 1620 : rbc2 = (rc(1) - rb(1))**2 + (rc(2) - rb(2))**2 + (rc(3) - rb(3))**2
222 :
223 : ! Native evaluation does not provide Libint screening extrema.
224 1620 : CPASSERT(.NOT. PRESENT(int_abc_ext))
225 4860 : ALLOCATE (f_work(0:la_max + lb_max + lc_max + 2))
226 1620 : f_work(:) = 0.0_dp
227 9720 : ALLOCATE (v_work(ncoa, ncob, ncoc, la_max + lb_max + lc_max + 1))
228 1620 : v_work(:, :, :, :) = 0.0_dp
229 :
230 : ! no screening
231 4860 : ALLOCATE (rpgfa_work(npgfa))
232 4860 : ALLOCATE (rpgfb_work(npgfb))
233 4860 : ALLOCATE (rpgfc_work(npgfc))
234 4320 : rpgfa_work(:) = 1.0E10_dp
235 4320 : rpgfb_work(:) = 1.0E10_dp
236 3240 : rpgfc_work(:) = 1.0E10_dp
237 4860 : ALLOCATE (gccc(ncoc))
238 1620 : gccc(:) = 0.0_dp
239 6480 : ALLOCATE (vabc(ncoa, ncob))
240 1620 : vabc(:, :) = 0.0_dp
241 :
242 : ! coulomb3 handles a single primitive Gaussian on center C per call.
243 16200 : DO kpgf = 1, npgfc
244 : ! Each primitive occupies an ncoc-wide block in the uncontracted array.
245 1620 : nc_start = (kpgf - 1)*ncoc + ncoset(lc_min - 1) + 1
246 1620 : nc_end = kpgf*ncoc
247 :
248 : CALL coulomb3(la_max, npgfa, zeta(:), rpgfa_work(:), la_min, &
249 : lb_max, npgfb, zetb(:), rpgfb_work(:), lb_min, &
250 : lc_max, zetc(kpgf), rpgfc_work(kpgf), lc_min, &
251 : gccc, rb - ra, rab2, rc - ra, rac2, rbc2, &
252 12960 : vabc, int_abc(:, :, nc_start:nc_end), v_work, f_work)
253 : END DO
254 : END BLOCK
255 : RETURN
256 : END IF
257 5718389 : CPASSERT(context%library_3c == library_libint)
258 :
259 5718389 : IF (PRESENT(dab)) THEN
260 5582821 : distance_ab = dab
261 : ELSE
262 135568 : distance_ab = SQRT((rb(1) - ra(1))**2 + (rb(2) - ra(2))**2 + (rb(3) - ra(3))**2)
263 : END IF
264 5718389 : IF (PRESENT(dac)) THEN
265 5582821 : distance_ac = dac
266 : ELSE
267 135568 : distance_ac = SQRT((rc(1) - ra(1))**2 + (rc(2) - ra(2))**2 + (rc(3) - ra(3))**2)
268 : END IF
269 5718389 : IF (PRESENT(dbc)) THEN
270 5582821 : distance_bc = dbc
271 : ELSE
272 135568 : distance_bc = SQRT((rc(1) - rb(1))**2 + (rc(2) - rb(2))**2 + (rc(3) - rb(3))**2)
273 : END IF
274 :
275 5718389 : NULLIFY (p_work)
276 :
277 5718389 : dr_ab = 0.0_dp
278 5718389 : dr_bc = 0.0_dp
279 5718389 : dr_ac = 0.0_dp
280 :
281 5718389 : op = potential_parameter%potential_type
282 :
283 : IF (op == do_potential_truncated .OR. op == do_potential_short &
284 5718389 : .OR. op == do_potential_mix_cl_trunc) THEN
285 4670933 : dr_bc = potential_parameter%cutoff_radius*cutoff_screen_factor
286 4670933 : dr_ac = potential_parameter%cutoff_radius*cutoff_screen_factor
287 1047456 : ELSE IF (op == do_potential_coulomb) THEN
288 222305 : dr_bc = 1000000.0_dp
289 222305 : dr_ac = 1000000.0_dp
290 : END IF
291 :
292 5718389 : IF (PRESENT(int_abc_ext)) THEN
293 5545213 : int_abc_ext = 0.0_dp
294 : END IF
295 :
296 : !Note: we want to compute all possible integrals based on the 3-centers (ab|c) before
297 : ! having to switch to (ba|c) (or the other way around) due to angular momenta in libint
298 : ! For a triplet of centers (k|ji), we can only compute integrals for which lj >= li
299 :
300 : !Looping over the pgfs
301 21318579 : DO ipgf = 1, npgfa
302 15600190 : zeti = zeta(ipgf)
303 15600190 : a_start = (ipgf - 1)*ncoset(la_max)
304 :
305 70157437 : DO jpgf = 1, npgfb
306 :
307 : ! screening
308 48838858 : IF (rpgfa(ipgf) + rpgfb(jpgf) + dr_ab < distance_ab) CYCLE
309 :
310 19373991 : zetj = zetb(jpgf)
311 19373991 : b_start = (jpgf - 1)*ncoset(lb_max)
312 :
313 67446290 : DO kpgf = 1, npgfc
314 :
315 : ! screening
316 32472109 : IF (rpgfb(jpgf) + rpgfc(kpgf) + dr_bc < distance_bc) CYCLE
317 22014993 : IF (rpgfa(ipgf) + rpgfc(kpgf) + dr_ac < distance_ac) CYCLE
318 :
319 17279370 : zetk = zetc(kpgf)
320 17279370 : c_start = (kpgf - 1)*ncoset(lc_max)
321 :
322 : !start with all the (c|ba) integrals (standard order) and keep to lb >= la
323 : CALL prepare_3c_primitive(ra, rb, rc, zeti, zetj, zetk, &
324 17279370 : la_max + lb_max + lc_max, potential_parameter, params)
325 17279370 : IF (la_min <= lb_max) THEN
326 15153278 : CALL cp_libint_set_params_eri(context%lib_3c, params, [1, 2, 3, 4], params%prepared_max_order)
327 : END IF
328 :
329 42148872 : DO li = la_min, la_max
330 24869502 : a_offset = a_start + ncoset(li - 1)
331 24869502 : ncoa = nco(li)
332 69918150 : DO lj = MAX(li, lb_min), lb_max
333 27769278 : b_offset = b_start + ncoset(lj - 1)
334 27769278 : ncob = nco(lj)
335 90041811 : DO lk = lc_min, lc_max
336 37403031 : c_offset = c_start + ncoset(lk - 1)
337 37403031 : ncoc = nco(lk)
338 :
339 37403031 : CALL cp_libint_get_3eris(li, lj, lk, context%lib_3c, p_work)
340 :
341 443240599 : IF (PRESENT(int_abc_ext)) int_abc_ext = MAX(int_abc_ext, MAXVAL(ABS(p_work)))
342 167536860 : DO k = 1, ncoc
343 102364551 : p1 = (k - 1)*ncob
344 381417981 : DO j = 1, ncob
345 241650399 : p2 = (p1 + j - 1)*ncoa
346 765194667 : DO i = 1, ncoa
347 421179717 : p3 = p2 + i
348 662830116 : int_abc(a_offset + i, b_offset + j, c_offset + k) = p_work(p3)
349 : END DO
350 : END DO
351 : END DO
352 :
353 : END DO !lk
354 : END DO !lj
355 : END DO !li
356 :
357 : !swap centers 3 and 4 to compute (c|ab) with lb < la
358 17279370 : IF (lb_min < la_max) THEN
359 8627085 : CALL cp_libint_set_params_eri(context%lib_3c, params, [1, 2, 4, 3], params%prepared_max_order)
360 : END IF
361 :
362 91005474 : DO lj = lb_min, lb_max
363 24887246 : b_offset = b_start + ncoset(lj - 1)
364 24887246 : ncob = nco(lj)
365 67080850 : DO li = MAX(lj + 1, la_min), la_max
366 9721495 : a_offset = a_start + ncoset(li - 1)
367 9721495 : ncoa = nco(li)
368 47640702 : DO lk = lc_min, lc_max
369 13031961 : c_offset = c_start + ncoset(lk - 1)
370 13031961 : ncoc = nco(lk)
371 :
372 13031961 : CALL cp_libint_get_3eris(lj, li, lk, context%lib_3c, p_work)
373 :
374 187345198 : IF (PRESENT(int_abc_ext)) int_abc_ext = MAX(int_abc_ext, MAXVAL(ABS(p_work)))
375 58124862 : DO k = 1, ncoc
376 35371406 : p1 = (k - 1)*ncoa
377 183595737 : DO i = 1, ncoa
378 135192370 : p2 = (p1 + i - 1)*ncob
379 351893626 : DO j = 1, ncob
380 181329850 : p3 = p2 + j
381 316522220 : int_abc(a_offset + i, b_offset + j, c_offset + k) = p_work(p3)
382 : END DO
383 : END DO
384 : END DO
385 :
386 : END DO !lk
387 : END DO !li
388 : END DO !lj
389 :
390 : END DO !kpgf
391 : END DO !jpgf
392 : END DO !ipgf
393 :
394 291720459 : END SUBROUTINE compute_coulomb_3c
395 :
396 : ! **************************************************************************************************
397 : !> \brief Prepare geometry and radial seeds for 3-center integrals at the requested order.
398 : !> \param ri ...
399 : !> \param rj ...
400 : !> \param rk ...
401 : !> \param zeti ...
402 : !> \param zetj ...
403 : !> \param zetk ...
404 : !> \param m_max maximum radial order, including any derivative increment
405 : !> \param potential_parameter radial operator parameters
406 : !> \param params reusable primitive parameter cache
407 : ! **************************************************************************************************
408 19175970 : SUBROUTINE prepare_3c_primitive(ri, rj, rk, zeti, zetj, zetk, m_max, potential_parameter, params)
409 : REAL(dp), INTENT(IN) :: ri(3), rj(3), rk(3), zeti, zetj, zetk
410 : INTEGER, INTENT(IN) :: m_max
411 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
412 : TYPE(eri_primitive_data_type), INTENT(INOUT) :: params
413 :
414 : REAL(dp) :: fundamentals_work(prim_data_f_size), gammaq, normalization, prefac, S1234, T
415 :
416 19175970 : CPASSERT(m_max < prim_data_f_size)
417 :
418 : ! Libint layout: (k, dummy k | j, i).
419 76703880 : params%centers(:, 1) = rk
420 76703880 : params%centers(:, 2) = rk
421 76703880 : params%centers(:, 3) = rj
422 76703880 : params%centers(:, 4) = ri
423 95879850 : params%exponents = [zetk, 0.0_dp, zetj, zeti]
424 76703880 : params%P = rk
425 :
426 19175970 : params%prepared_max_order = m_max
427 19175970 : gammaq = zeti + zetj
428 19175970 : params%ZetaInv = 1._dp/zetk; params%EtaInv = 1._dp/gammaq
429 19175970 : params%ZetapEtaInv = 1._dp/(zetk + gammaq)
430 :
431 76703880 : params%Q = (zeti*ri + zetj*rj)*params%EtaInv
432 76703880 : params%W = (zetk*rk + gammaq*params%Q)*params%ZetapEtaInv
433 19175970 : params%Rho = zetk*gammaq/(zetk + gammaq)
434 :
435 421871340 : params%Fm = 0.0_dp
436 36162027 : SELECT CASE (potential_parameter%potential_type)
437 : CASE (do_potential_coulomb, do_potential_truncated, do_potential_short, do_potential_mix_cl_trunc)
438 16986057 : IF (potential_parameter%potential_type == do_potential_truncated .OR. &
439 : potential_parameter%potential_type == do_potential_mix_cl_trunc) THEN
440 13524747 : CPASSERT(get_lmax_init() >= params%prepared_max_order)
441 : END IF
442 67944228 : T = params%Rho*SUM((params%Q - rk)**2)
443 67944228 : S1234 = EXP(-zeti*zetj*params%EtaInv*SUM((rj - ri)**2))
444 : CALL compute_r12_fundamentals(params%Fm, normalization, params%prepared_max_order, potential_parameter%potential_type, &
445 : params%Rho, T, fundamentals_work, &
446 : omega=potential_parameter%omega, &
447 : cutoff_radius=potential_parameter%cutoff_radius, &
448 : scale_coulomb=potential_parameter%scale_coulomb, &
449 : scale_longrange=potential_parameter%scale_longrange, &
450 16986057 : scale_gaussian=0.0_dp)
451 16986057 : prefac = normalization*SQRT((pi*params%ZetapEtaInv)**3)*S1234
452 373693254 : params%Fm = prefac*params%Fm
453 : CASE (do_potential_id)
454 : S1234 = EXP(-zeti*zetj*params%EtaInv*SUM((rj - ri)**2) &
455 15329391 : - gammaq*zetk*params%ZetapEtaInv*SUM((params%Q - rk)**2))
456 2189913 : prefac = SQRT((pi*params%ZetapEtaInv)**3)*S1234
457 :
458 48178086 : params%Fm(:) = prefac
459 : CASE DEFAULT
460 19175970 : CPABORT("Requested operator NYI")
461 : END SELECT
462 19175970 : END SUBROUTINE prepare_3c_primitive
463 :
464 : ! **************************************************************************************************
465 : !> \brief Computes the derivatives of the 3-center electron repulsion integrals (ab|c) for a given
466 : !> set of cartesian gaussian orbitals. Returns x,y,z derivatives for 1st and 2nd center
467 : !> \param der_abc_1 the derivatives for the 1st center (allocated before hand)
468 : !> \param der_abc_2 the derivatives for the 2nd center (allocated before hand)
469 : !> \param la_min ...
470 : !> \param la_max ...
471 : !> \param npgfa ...
472 : !> \param zeta ...
473 : !> \param rpgfa ...
474 : !> \param ra ...
475 : !> \param lb_min ...
476 : !> \param lb_max ...
477 : !> \param npgfb ...
478 : !> \param zetb ...
479 : !> \param rpgfb ...
480 : !> \param rb ...
481 : !> \param lc_min ...
482 : !> \param lc_max ...
483 : !> \param npgfc ...
484 : !> \param zetc ...
485 : !> \param rpgfc ...
486 : !> \param rc ...
487 : !> \param dab ...
488 : !> \param dac ...
489 : !> \param dbc ...
490 : !> \param context owning per-thread task and derivative scratch
491 : !> \param potential_parameter the info about the potential
492 : !> \param der_abc_1_ext the extremal value of der_abc_1, i.e., MAXVAL(ABS(der_abc_1))
493 : !> \param der_abc_2_ext ...
494 : !> \note Prepare shared radial tables before entering a threaded evaluation region.
495 : ! **************************************************************************************************
496 349697 : SUBROUTINE compute_coulomb_3c_derivs(der_abc_1, der_abc_2, &
497 349697 : la_min, la_max, npgfa, zeta, rpgfa, ra, &
498 349697 : lb_min, lb_max, npgfb, zetb, rpgfb, rb, &
499 349697 : lc_min, lc_max, npgfc, zetc, rpgfc, rc, &
500 : dab, dac, dbc, context, potential_parameter, &
501 : der_abc_1_ext, der_abc_2_ext)
502 :
503 : REAL(dp), DIMENSION(:, :, :, :), INTENT(INOUT) :: der_abc_1, der_abc_2
504 : INTEGER, INTENT(IN) :: la_min, la_max, npgfa
505 : REAL(dp), DIMENSION(:), INTENT(IN) :: zeta, rpgfa
506 : REAL(dp), DIMENSION(3), INTENT(IN) :: ra
507 : INTEGER, INTENT(IN) :: lb_min, lb_max, npgfb
508 : REAL(dp), DIMENSION(:), INTENT(IN) :: zetb, rpgfb
509 : REAL(dp), DIMENSION(3), INTENT(IN) :: rb
510 : INTEGER, INTENT(IN) :: lc_min, lc_max, npgfc
511 : REAL(dp), DIMENSION(:), INTENT(IN) :: zetc, rpgfc
512 : REAL(dp), DIMENSION(3), INTENT(IN) :: rc
513 : REAL(KIND=dp), INTENT(IN) :: dab, dac, dbc
514 : TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
515 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
516 : REAL(dp), DIMENSION(3), INTENT(OUT), OPTIONAL :: der_abc_1_ext, der_abc_2_ext
517 :
518 : INTEGER :: a_offset, a_start, b_offset, b_start, c_offset, c_start, i, i_deriv, ipgf, j, &
519 : jpgf, k, kpgf, li, lj, lk, ncart, ncoa, ncob, ncoc, op, p1, p2, p3
520 : LOGICAL :: do_ext
521 : REAL(dp) :: dr_ab, dr_ac, dr_bc, zeti, zetj, zetk
522 : REAL(dp), DIMENSION(3) :: der_abc_1_ext_prv, der_abc_2_ext_prv
523 : TYPE(eri_primitive_data_type) :: params
524 :
525 0 : CPASSERT(context%derivative_order_3c == 1)
526 349697 : CPASSERT(context%library_3c == library_libint)
527 :
528 349697 : IF (ALLOCATED(context%derivative_work_3c)) THEN
529 349303 : IF (SIZE(context%derivative_work_3c, 1) < nco(la_max)*nco(lb_max)*nco(lc_max)) DEALLOCATE (context%derivative_work_3c)
530 : END IF
531 353173 : IF (.NOT. ALLOCATED(context%derivative_work_3c)) ALLOCATE (context%derivative_work_3c(nco(la_max)*nco(lb_max)*nco(lc_max), 6))
532 :
533 349697 : dr_ab = 0.0_dp
534 349697 : dr_bc = 0.0_dp
535 349697 : dr_ac = 0.0_dp
536 :
537 349697 : op = potential_parameter%potential_type
538 :
539 : IF (op == do_potential_truncated .OR. op == do_potential_short &
540 349697 : .OR. op == do_potential_mix_cl_trunc) THEN
541 119807 : dr_bc = potential_parameter%cutoff_radius*cutoff_screen_factor
542 119807 : dr_ac = potential_parameter%cutoff_radius*cutoff_screen_factor
543 229890 : ELSE IF (op == do_potential_coulomb) THEN
544 9988 : dr_bc = 1000000.0_dp
545 9988 : dr_ac = 1000000.0_dp
546 : END IF
547 :
548 349697 : do_ext = .FALSE.
549 349697 : IF (PRESENT(der_abc_1_ext) .OR. PRESENT(der_abc_2_ext)) do_ext = .TRUE.
550 349697 : der_abc_1_ext_prv = 0.0_dp
551 349697 : der_abc_2_ext_prv = 0.0_dp
552 :
553 : !Note: we want to compute all possible integrals based on the 3-centers (ab|c) before
554 : ! having to switch to (ba|c) (or the other way around) due to angular momenta in libint
555 : ! For a triplet of centers (k|ji), we can only compute integrals for which lj >= li
556 :
557 : !Looping over the pgfs
558 1204834 : DO ipgf = 1, npgfa
559 855137 : zeti = zeta(ipgf)
560 855137 : a_start = (ipgf - 1)*ncoset(la_max)
561 :
562 4818324 : DO jpgf = 1, npgfb
563 :
564 : ! screening
565 3613490 : IF (rpgfa(ipgf) + rpgfb(jpgf) + dr_ab < dab) CYCLE
566 :
567 1149085 : zetj = zetb(jpgf)
568 1149085 : b_start = (jpgf - 1)*ncoset(lb_max)
569 :
570 8423888 : DO kpgf = 1, npgfc
571 :
572 : ! screening
573 6419666 : IF (rpgfb(jpgf) + rpgfc(kpgf) + dr_bc < dbc) CYCLE
574 2702852 : IF (rpgfa(ipgf) + rpgfc(kpgf) + dr_ac < dac) CYCLE
575 :
576 1896600 : zetk = zetc(kpgf)
577 1896600 : c_start = (kpgf - 1)*ncoset(lc_max)
578 :
579 : !start with all the (c|ba) integrals (standard order) and keep to lb >= la
580 : CALL prepare_3c_primitive(ra, rb, rc, zeti, zetj, zetk, &
581 1896600 : la_max + lb_max + lc_max + 1, potential_parameter, params)
582 1896600 : IF (la_min <= lb_max) THEN
583 1797171 : CALL cp_libint_set_params_eri_deriv(context%lib_3c, params, [1, 2, 3, 4], params%prepared_max_order)
584 : END IF
585 :
586 4359315 : DO li = la_min, la_max
587 2462715 : a_offset = a_start + ncoset(li - 1)
588 2462715 : ncoa = nco(li)
589 6983236 : DO lj = MAX(li, lb_min), lb_max
590 2623921 : b_offset = b_start + ncoset(lj - 1)
591 2623921 : ncob = nco(lj)
592 8875857 : DO lk = lc_min, lc_max
593 3789221 : c_offset = c_start + ncoset(lk - 1)
594 3789221 : ncoc = nco(lk)
595 :
596 3789221 : ncart = ncoa*ncob*ncoc
597 :
598 3789221 : CALL cp_libint_get_3eri_derivs(li, lj, lk, context%lib_3c, context%derivative_work_3c)
599 :
600 17780805 : DO i_deriv = 1, 3
601 11367663 : IF (do_ext) THEN
602 : der_abc_1_ext_prv(i_deriv) = MAX(der_abc_1_ext_prv(i_deriv), &
603 90004689 : MAXVAL(ABS(context%derivative_work_3c(1:ncart, i_deriv + 3))))
604 : der_abc_2_ext_prv(i_deriv) = MAX(der_abc_2_ext_prv(i_deriv), &
605 90004689 : MAXVAL(ABS(context%derivative_work_3c(1:ncart, i_deriv))))
606 : END IF
607 42911978 : DO k = 1, ncoc
608 27755094 : p1 = (k - 1)*ncob
609 91289793 : DO j = 1, ncob
610 52167036 : p2 = (p1 + j - 1)*ncoa
611 158559156 : DO i = 1, ncoa
612 78637026 : p3 = p2 + i
613 : der_abc_1(a_offset + i, b_offset + j, c_offset + k, i_deriv) = &
614 78637026 : context%derivative_work_3c(p3, i_deriv + 3)
615 : der_abc_2(a_offset + i, b_offset + j, c_offset + k, i_deriv) = &
616 130804062 : context%derivative_work_3c(p3, i_deriv)
617 : END DO
618 : END DO
619 : END DO
620 : END DO
621 : END DO !lk
622 : END DO !lj
623 : END DO !li
624 :
625 : !swap centers 3 and 4 to compute (c|ab) with lb < la
626 1896600 : IF (lb_min < la_max) THEN
627 655878 : CALL cp_libint_set_params_eri_deriv(context%lib_3c, params, [1, 2, 4, 3], params%prepared_max_order)
628 : END IF
629 :
630 7982008 : DO lj = lb_min, lb_max
631 2471918 : b_offset = b_start + ncoset(lj - 1)
632 2471918 : ncob = nco(lj)
633 9558980 : DO li = MAX(lj + 1, la_min), la_max
634 667396 : a_offset = a_start + ncoset(li - 1)
635 667396 : ncoa = nco(li)
636 4116117 : DO lk = lc_min, lc_max
637 976803 : c_offset = c_start + ncoset(lk - 1)
638 976803 : ncoc = nco(lk)
639 :
640 976803 : ncart = ncoa*ncob*ncoc
641 976803 : CALL cp_libint_get_3eri_derivs(lj, li, lk, context%lib_3c, context%derivative_work_3c)
642 :
643 4574608 : DO i_deriv = 1, 3
644 2930409 : IF (do_ext) THEN
645 : der_abc_1_ext_prv(i_deriv) = MAX(der_abc_1_ext_prv(i_deriv), &
646 30652893 : MAXVAL(ABS(context%derivative_work_3c(1:ncart, i_deriv))))
647 : der_abc_2_ext_prv(i_deriv) = MAX(der_abc_2_ext_prv(i_deriv), &
648 30652893 : MAXVAL(ABS(context%derivative_work_3c(1:ncart, i_deriv + 3))))
649 : END IF
650 11291154 : DO k = 1, ncoc
651 7383942 : p1 = (k - 1)*ncoa
652 34549011 : DO i = 1, ncoa
653 24234660 : p2 = (p1 + i - 1)*ncob
654 59341086 : DO j = 1, ncob
655 27722484 : p3 = p2 + j
656 : der_abc_1(a_offset + i, b_offset + j, c_offset + k, i_deriv) = &
657 27722484 : context%derivative_work_3c(p3, i_deriv)
658 : der_abc_2(a_offset + i, b_offset + j, c_offset + k, i_deriv) = &
659 51957144 : context%derivative_work_3c(p3, i_deriv + 3)
660 : END DO
661 : END DO
662 : END DO
663 : END DO
664 : END DO !lk
665 : END DO !li
666 : END DO !lj
667 :
668 : END DO !kpgf
669 : END DO !jpgf
670 : END DO !ipgf
671 :
672 349697 : IF (PRESENT(der_abc_1_ext)) der_abc_1_ext = der_abc_1_ext_prv
673 349697 : IF (PRESENT(der_abc_2_ext)) der_abc_2_ext = der_abc_2_ext_prv
674 :
675 19583032 : END SUBROUTINE compute_coulomb_3c_derivs
676 :
677 : ! **************************************************************************************************
678 : !> \brief Computes the 2-center electron repulsion integrals (a|b) for a given set of cartesian
679 : !> gaussian orbitals
680 : !> \param context owning per-thread task and derivative scratch
681 : !> \param la_min ...
682 : !> \param la_max ...
683 : !> \param lb_min ...
684 : !> \param lb_max ...
685 : !> \param npgfa ...
686 : !> \param npgfb ...
687 : !> \param zeta ...
688 : !> \param zetb ...
689 : !> \param rpgfa ...
690 : !> \param rpgfb ...
691 : !> \param ra ...
692 : !> \param rb ...
693 : !> \param int_ab the integrals as array of cartesian orbitals (allocated before hand)
694 : !> \param potential_parameter the info about the potential
695 : !> \param dab optional center distance for primitive screening
696 : !> \note Prepare shared radial tables before entering a threaded evaluation region.
697 : ! **************************************************************************************************
698 645559 : SUBROUTINE compute_coulomb_2c(context, la_min, la_max, lb_min, lb_max, npgfa, npgfb, &
699 645559 : zeta, zetb, rpgfa, rpgfb, ra, rb, int_ab, potential_parameter, dab)
700 :
701 : TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
702 : INTEGER, INTENT(IN) :: la_min, la_max, lb_min, lb_max, npgfa, &
703 : npgfb
704 : REAL(dp), DIMENSION(:), INTENT(IN) :: zeta, zetb, rpgfa, rpgfb
705 : REAL(dp), DIMENSION(3), INTENT(IN) :: ra, rb
706 : REAL(dp), DIMENSION(:, :), INTENT(INOUT) :: int_ab
707 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
708 : REAL(dp), INTENT(IN), OPTIONAL :: dab
709 :
710 : INTEGER :: a_offset, a_start, b_offset, b_start, i, &
711 : ipgf, j, jpgf, li, lj, ncoa, ncob, p1, &
712 : p2
713 : REAL(dp) :: distance_ab, dr_ab, zeti, zetj
714 645559 : REAL(dp), DIMENSION(:), POINTER :: p_work
715 : TYPE(eri_primitive_data_type) :: params
716 :
717 0 : CPASSERT(context%derivative_order_2c == 0)
718 :
719 645559 : IF (context%library_2c == library_native) THEN
720 2808 : BLOCK
721 : INTEGER :: ncoa, ncob
722 : REAL(dp) :: rab2
723 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: f_work
724 : REAL(dp), ALLOCATABLE, DIMENSION(:, :, :) :: v_work
725 :
726 1404 : ncoa = npgfa*ncoset(la_max)
727 1404 : ncob = npgfb*ncoset(lb_max)
728 1404 : rab2 = (ra(1) - rb(1))**2 + (ra(2) - rb(2))**2 + (ra(3) - rb(3))**2
729 :
730 4212 : ALLOCATE (f_work(0:la_max + lb_max + 2))
731 7020 : ALLOCATE (v_work(ncoa, ncob, la_max + lb_max + 1))
732 :
733 : CALL coulomb2(la_max, npgfa, zeta, rpgfa, la_min, lb_max, npgfb, zetb, rpgfb, lb_min, &
734 8424 : rb - ra, rab2, int_ab, v_work, f_work, screening=.FALSE.)
735 : END BLOCK
736 : RETURN
737 : END IF
738 644155 : CPASSERT(context%library_2c == library_libint)
739 :
740 644155 : IF (PRESENT(dab)) THEN
741 542263 : distance_ab = dab
742 : ELSE
743 101892 : distance_ab = SQRT((ra(1) - rb(1))**2 + (ra(2) - rb(2))**2 + (ra(3) - rb(3))**2)
744 : END IF
745 :
746 644155 : NULLIFY (p_work)
747 :
748 644155 : dr_ab = 0.0_dp
749 :
750 : IF (potential_parameter%potential_type == do_potential_truncated .OR. &
751 644155 : potential_parameter%potential_type == do_potential_short .OR. &
752 : potential_parameter%potential_type == do_potential_mix_cl_trunc) THEN
753 312255 : dr_ab = potential_parameter%cutoff_radius*cutoff_screen_factor
754 331900 : ELSE IF (potential_parameter%potential_type == do_potential_coulomb) THEN
755 154347 : dr_ab = 1000000.0_dp
756 : END IF
757 :
758 : !Looping over the pgfs
759 1856726 : DO ipgf = 1, npgfa
760 1212571 : zeti = zeta(ipgf)
761 1212571 : a_start = (ipgf - 1)*ncoset(la_max)
762 :
763 6981616 : DO jpgf = 1, npgfb
764 5124890 : zetj = zetb(jpgf)
765 5124890 : b_start = (jpgf - 1)*ncoset(lb_max)
766 :
767 : !screening
768 5124890 : IF (rpgfa(ipgf) + rpgfb(jpgf) + dr_ab < distance_ab) CYCLE
769 :
770 : CALL prepare_2c_primitive(ra, rb, zeti, zetj, la_max + lb_max, &
771 3342841 : potential_parameter, params)
772 3342841 : CALL cp_libint_set_params_eri(context%lib_2c, params, [1, 2, 3, 4], params%prepared_max_order)
773 :
774 10358259 : DO li = la_min, la_max
775 5802847 : a_offset = a_start + ncoset(li - 1)
776 5802847 : ncoa = nco(li)
777 21948007 : DO lj = lb_min, lb_max
778 11020270 : b_offset = b_start + ncoset(lj - 1)
779 11020270 : ncob = nco(lj)
780 :
781 11020270 : CALL cp_libint_get_2eris(li, lj, context%lib_2c, p_work)
782 :
783 50002261 : DO j = 1, ncob
784 33179144 : p1 = (j - 1)*ncoa
785 146912311 : DO i = 1, ncoa
786 102712897 : p2 = p1 + i
787 135892041 : int_ab(a_offset + i, b_offset + j) = p_work(p2)
788 : END DO
789 : END DO
790 :
791 : END DO
792 : END DO
793 :
794 : END DO
795 : END DO
796 :
797 32923509 : END SUBROUTINE compute_coulomb_2c
798 :
799 : ! **************************************************************************************************
800 : !> \brief Prepare geometry and radial seeds for 2-center integrals at the requested order.
801 : !> \param rj ...
802 : !> \param rk ...
803 : !> \param zetj ...
804 : !> \param zetk ...
805 : !> \param m_max maximum radial order, including any derivative increment
806 : !> \param potential_parameter radial operator parameters
807 : !> \param params reusable primitive parameter cache
808 : ! **************************************************************************************************
809 5520638 : SUBROUTINE prepare_2c_primitive(rj, rk, zetj, zetk, m_max, potential_parameter, params)
810 : REAL(dp), INTENT(IN) :: rj(3), rk(3), zetj, zetk
811 : INTEGER, INTENT(IN) :: m_max
812 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
813 : TYPE(eri_primitive_data_type), INTENT(INOUT) :: params
814 :
815 : REAL(dp) :: fundamentals_work(prim_data_f_size), normalization, prefac, T
816 :
817 5520638 : CPASSERT(m_max < prim_data_f_size)
818 :
819 : ! Libint layout: (k, dummy k | j, dummy j).
820 22082552 : params%centers(:, 1) = rk
821 22082552 : params%centers(:, 2) = rk
822 22082552 : params%centers(:, 3) = rj
823 22082552 : params%centers(:, 4) = rj
824 27603190 : params%exponents = [zetk, 0.0_dp, zetj, 0.0_dp]
825 22082552 : params%P = rk
826 22082552 : params%Q = rj
827 :
828 5520638 : params%prepared_max_order = m_max
829 5520638 : params%ZetaInv = 1._dp/zetk; params%EtaInv = 1._dp/zetj
830 5520638 : params%ZetapEtaInv = 1._dp/(zetk + zetj)
831 :
832 22082552 : params%W = (zetk*rk + zetj*rj)*params%ZetapEtaInv
833 5520638 : params%Rho = zetk*zetj/(zetk + zetj)
834 :
835 121454036 : params%Fm = 0.0_dp
836 10867862 : SELECT CASE (potential_parameter%potential_type)
837 : CASE (do_potential_coulomb, do_potential_truncated, do_potential_short, do_potential_mix_cl_trunc)
838 5347224 : IF (potential_parameter%potential_type == do_potential_truncated .OR. &
839 : potential_parameter%potential_type == do_potential_mix_cl_trunc) THEN
840 353904 : CPASSERT(get_lmax_init() >= params%prepared_max_order)
841 : END IF
842 21388896 : T = params%Rho*SUM((rj - rk)**2)
843 : CALL compute_r12_fundamentals(params%Fm, normalization, params%prepared_max_order, potential_parameter%potential_type, &
844 : params%Rho, T, fundamentals_work, &
845 : omega=potential_parameter%omega, &
846 : cutoff_radius=potential_parameter%cutoff_radius, &
847 : scale_coulomb=potential_parameter%scale_coulomb, &
848 : scale_longrange=potential_parameter%scale_longrange, &
849 5347224 : scale_gaussian=0.0_dp)
850 5347224 : prefac = normalization*SQRT((pi*params%ZetapEtaInv)**3)
851 117638928 : params%Fm = prefac*params%Fm
852 : CASE (do_potential_id)
853 :
854 693656 : prefac = SQRT((pi*params%ZetapEtaInv)**3)*EXP(-zetj*zetk*params%ZetapEtaInv*SUM((rk - rj)**2))
855 3815108 : params%Fm(:) = prefac
856 : CASE DEFAULT
857 5520638 : CPABORT("Requested operator NYI")
858 : END SELECT
859 5520638 : END SUBROUTINE prepare_2c_primitive
860 :
861 : !> \brief Computes the 2-center derivatives of the electron repulsion integrals (a|b) for a given
862 : !> set of cartesian gaussian orbitals. Returns the derivatives wrt to the first center
863 : !> \param der_ab the derivatives as array of cartesian orbitals (allocated before hand)
864 : !> \param la_min ...
865 : !> \param la_max ...
866 : !> \param npgfa ...
867 : !> \param zeta ...
868 : !> \param rpgfa ...
869 : !> \param ra ...
870 : !> \param lb_min ...
871 : !> \param lb_max ...
872 : !> \param npgfb ...
873 : !> \param zetb ...
874 : !> \param rpgfb ...
875 : !> \param rb ...
876 : !> \param dab ...
877 : !> \param context owning per-thread task and derivative scratch
878 : !> \param potential_parameter the info about the potential
879 : !> \note Prepare shared radial tables before entering a threaded evaluation region.
880 : ! **************************************************************************************************
881 290078 : SUBROUTINE compute_coulomb_2c_derivs(der_ab, la_min, la_max, npgfa, zeta, rpgfa, ra, &
882 145039 : lb_min, lb_max, npgfb, zetb, rpgfb, rb, &
883 : dab, context, potential_parameter)
884 :
885 : REAL(dp), DIMENSION(:, :, :), INTENT(INOUT) :: der_ab
886 : INTEGER, INTENT(IN) :: la_min, la_max, npgfa
887 : REAL(dp), DIMENSION(:), INTENT(IN) :: zeta, rpgfa
888 : REAL(dp), DIMENSION(3), INTENT(IN) :: ra
889 : INTEGER, INTENT(IN) :: lb_min, lb_max, npgfb
890 : REAL(dp), DIMENSION(:), INTENT(IN) :: zetb, rpgfb
891 : REAL(dp), DIMENSION(3), INTENT(IN) :: rb
892 : REAL(dp), INTENT(IN) :: dab
893 : TYPE(coulomb_integral_context_type), INTENT(INOUT) :: context
894 : TYPE(coulomb_operator_type), INTENT(IN) :: potential_parameter
895 :
896 : INTEGER :: a_offset, a_start, b_offset, b_start, i, &
897 : i_deriv, ipgf, j, jpgf, li, lj, ncoa, &
898 : ncob, p1, p2
899 : REAL(dp) :: dr_ab, zeti, zetj
900 : TYPE(eri_primitive_data_type) :: params
901 :
902 0 : CPASSERT(context%derivative_order_2c == 1)
903 145039 : CPASSERT(context%library_2c == library_libint)
904 :
905 145039 : IF (ALLOCATED(context%derivative_work_2c)) THEN
906 144627 : IF (SIZE(context%derivative_work_2c, 1) < nco(la_max)*nco(lb_max)) DEALLOCATE (context%derivative_work_2c)
907 : END IF
908 148225 : IF (.NOT. ALLOCATED(context%derivative_work_2c)) ALLOCATE (context%derivative_work_2c(nco(la_max)*nco(lb_max), 3))
909 :
910 145039 : dr_ab = 0.0_dp
911 :
912 : IF (potential_parameter%potential_type == do_potential_truncated .OR. &
913 145039 : potential_parameter%potential_type == do_potential_short .OR. &
914 : potential_parameter%potential_type == do_potential_mix_cl_trunc) THEN
915 64460 : dr_ab = potential_parameter%cutoff_radius*cutoff_screen_factor
916 80579 : ELSE IF (potential_parameter%potential_type == do_potential_coulomb) THEN
917 9831 : dr_ab = 1000000.0_dp
918 : END IF
919 :
920 : !Looping over the pgfs
921 645574 : DO ipgf = 1, npgfa
922 500535 : zeti = zeta(ipgf)
923 500535 : a_start = (ipgf - 1)*ncoset(la_max)
924 :
925 3895695 : DO jpgf = 1, npgfb
926 3250121 : zetj = zetb(jpgf)
927 3250121 : b_start = (jpgf - 1)*ncoset(lb_max)
928 :
929 : !screening
930 3250121 : IF (rpgfa(ipgf) + rpgfb(jpgf) + dr_ab < dab) CYCLE
931 :
932 : CALL prepare_2c_primitive(ra, rb, zeti, zetj, la_max + lb_max + 1, &
933 2177797 : potential_parameter, params)
934 2177797 : CALL cp_libint_set_params_eri_deriv(context%lib_2c, params, [1, 2, 3, 4], params%prepared_max_order)
935 :
936 6329166 : DO li = la_min, la_max
937 3650834 : a_offset = a_start + ncoset(li - 1)
938 3650834 : ncoa = nco(li)
939 13072219 : DO lj = lb_min, lb_max
940 6171264 : b_offset = b_start + ncoset(lj - 1)
941 6171264 : ncob = nco(lj)
942 :
943 6171264 : CALL cp_libint_get_2eri_derivs(li, lj, context%lib_2c, context%derivative_work_2c)
944 :
945 28335890 : DO i_deriv = 1, 3
946 75378423 : DO j = 1, ncob
947 50693367 : p1 = (j - 1)*ncoa
948 208489899 : DO i = 1, ncoa
949 139282740 : p2 = p1 + i
950 189976107 : der_ab(a_offset + i, b_offset + j, i_deriv) = context%derivative_work_2c(p2, i_deriv)
951 : END DO
952 : END DO
953 : END DO
954 : END DO
955 : END DO
956 :
957 : END DO
958 : END DO
959 :
960 8122184 : END SUBROUTINE compute_coulomb_2c_derivs
961 :
962 0 : END MODULE libint_2c_3c
|