Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \brief Routines needed for cubic-scaling RPA and SOS-Laplace-MP2 forces
10 : !> \author Augustin Bussy
11 : ! **************************************************************************************************
12 : MODULE rpa_im_time_force_methods
13 : USE admm_methods, ONLY: admm_projection_derivative
14 : USE admm_types, ONLY: admm_type,&
15 : get_admm_env
16 : USE ao_util, ONLY: exp_radius_very_extended
17 : USE atomic_kind_types, ONLY: atomic_kind_type,&
18 : get_atomic_kind_set
19 : USE basis_set_types, ONLY: gto_basis_set_p_type,&
20 : gto_basis_set_type
21 : USE bibliography, ONLY: Bussy2023,&
22 : cite_reference
23 : USE cell_types, ONLY: cell_type,&
24 : pbc
25 : USE core_ae, ONLY: build_core_ae
26 : USE core_ppl, ONLY: build_core_ppl
27 : USE core_ppnl, ONLY: build_core_ppnl
28 : USE cp_blacs_env, ONLY: cp_blacs_env_type
29 : USE cp_control_types, ONLY: dft_control_type
30 : USE cp_dbcsr_api, ONLY: &
31 : dbcsr_add, dbcsr_add_on_diag, dbcsr_clear, dbcsr_complete_redistribute, dbcsr_copy, &
32 : dbcsr_create, dbcsr_distribution_new, dbcsr_distribution_release, dbcsr_distribution_type, &
33 : dbcsr_get_block_p, dbcsr_iterator_blocks_left, dbcsr_iterator_next_block, &
34 : dbcsr_iterator_start, dbcsr_iterator_stop, dbcsr_iterator_type, dbcsr_multiply, &
35 : dbcsr_p_type, dbcsr_release, dbcsr_scale, dbcsr_set, dbcsr_type, dbcsr_type_antisymmetric, &
36 : dbcsr_type_no_symmetry, dbcsr_type_symmetric
37 : USE cp_dbcsr_cholesky, ONLY: cp_dbcsr_cholesky_decompose,&
38 : cp_dbcsr_cholesky_invert
39 : USE cp_dbcsr_contrib, ONLY: dbcsr_frobenius_norm
40 : USE cp_dbcsr_diag, ONLY: cp_dbcsr_power
41 : USE cp_dbcsr_operations, ONLY: copy_dbcsr_to_fm,&
42 : copy_fm_to_dbcsr,&
43 : cp_dbcsr_dist2d_to_dist,&
44 : cp_dbcsr_sm_fm_multiply,&
45 : dbcsr_allocate_matrix_set,&
46 : dbcsr_deallocate_matrix_set
47 : USE cp_eri_mme_interface, ONLY: cp_eri_mme_update_local_counts
48 : USE cp_fm_struct, ONLY: cp_fm_struct_create,&
49 : cp_fm_struct_release,&
50 : cp_fm_struct_type
51 : USE cp_fm_types, ONLY: cp_fm_create,&
52 : cp_fm_release,&
53 : cp_fm_set_all,&
54 : cp_fm_to_fm,&
55 : cp_fm_type
56 : USE dbt_api, ONLY: &
57 : dbt_batched_contract_finalize, dbt_batched_contract_init, dbt_clear, dbt_contract, &
58 : dbt_copy, dbt_copy_matrix_to_tensor, dbt_copy_tensor_to_matrix, dbt_create, dbt_destroy, &
59 : dbt_filter, dbt_get_info, dbt_mp_environ_pgrid, dbt_pgrid_create, dbt_pgrid_destroy, &
60 : dbt_pgrid_type, dbt_scale, dbt_type
61 : USE distribution_2d_types, ONLY: distribution_2d_type
62 : USE ec_methods, ONLY: create_kernel
63 : USE gaussian_gridlevels, ONLY: gaussian_gridlevel
64 : USE hfx_admm_utils, ONLY: tddft_hfx_matrix
65 : USE hfx_derivatives, ONLY: derivatives_four_center
66 : USE hfx_exx, ONLY: add_exx_to_rhs
67 : USE hfx_ri, ONLY: get_2c_der_force,&
68 : get_force_from_3c_trace,&
69 : get_idx_to_atom,&
70 : hfx_ri_update_forces
71 : USE hfx_types, ONLY: alloc_containers,&
72 : block_ind_type,&
73 : dealloc_containers,&
74 : hfx_compression_type,&
75 : hfx_type
76 : USE input_constants, ONLY: do_admm_aux_exch_func_none,&
77 : do_eri_gpw,&
78 : do_eri_mme,&
79 : do_potential_id,&
80 : ri_rpa_method_gpw
81 : USE input_section_types, ONLY: section_vals_get,&
82 : section_vals_get_subs_vals,&
83 : section_vals_type,&
84 : section_vals_val_get
85 : USE iterate_matrix, ONLY: matrix_exponential
86 : USE kinds, ONLY: dp,&
87 : int_8
88 : USE libint_2c_3c, ONLY: libint_potential_type
89 : USE machine, ONLY: m_flush,&
90 : m_walltime
91 : USE mathconstants, ONLY: fourpi
92 : USE message_passing, ONLY: mp_cart_type,&
93 : mp_para_env_release,&
94 : mp_para_env_type
95 : USE mp2_eri, ONLY: integrate_set_2c
96 : USE mp2_eri_gpw, ONLY: calc_potential_gpw,&
97 : cleanup_gpw,&
98 : prepare_gpw,&
99 : virial_gpw_potential
100 : USE mp2_types, ONLY: mp2_type
101 : USE orbital_pointers, ONLY: ncoset
102 : USE parallel_gemm_api, ONLY: parallel_gemm
103 : USE particle_methods, ONLY: get_particle_set
104 : USE particle_types, ONLY: particle_type
105 : USE pw_env_types, ONLY: pw_env_get,&
106 : pw_env_type
107 : USE pw_methods, ONLY: pw_axpy,&
108 : pw_copy,&
109 : pw_integral_ab,&
110 : pw_scale,&
111 : pw_transfer,&
112 : pw_zero
113 : USE pw_poisson_methods, ONLY: pw_poisson_solve
114 : USE pw_poisson_types, ONLY: pw_poisson_type
115 : USE pw_pool_types, ONLY: pw_pool_type
116 : USE pw_types, ONLY: pw_c1d_gs_type,&
117 : pw_r3d_rs_type
118 : USE qs_collocate_density, ONLY: calculate_rho_elec,&
119 : collocate_function
120 : USE qs_density_matrices, ONLY: calculate_whz_matrix
121 : USE qs_environment_types, ONLY: get_qs_env,&
122 : qs_environment_type,&
123 : set_qs_env
124 : USE qs_force_types, ONLY: qs_force_type
125 : USE qs_integral_utils, ONLY: basis_set_list_setup
126 : USE qs_integrate_potential, ONLY: integrate_pgf_product,&
127 : integrate_v_core_rspace,&
128 : integrate_v_rspace
129 : USE qs_interactions, ONLY: init_interaction_radii_orb_basis
130 : USE qs_kind_types, ONLY: qs_kind_type
131 : USE qs_kinetic, ONLY: build_kinetic_matrix
132 : USE qs_ks_methods, ONLY: calc_rho_tot_gspace
133 : USE qs_ks_reference, ONLY: ks_ref_potential
134 : USE qs_ks_types, ONLY: set_ks_env
135 : USE qs_linres_types, ONLY: linres_control_type
136 : USE qs_matrix_w, ONLY: compute_matrix_w
137 : USE qs_mo_types, ONLY: get_mo_set,&
138 : mo_set_type
139 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
140 : release_neighbor_list_sets
141 : USE qs_overlap, ONLY: build_overlap_matrix
142 : USE qs_p_env_methods, ONLY: p_env_create,&
143 : p_env_psi0_changed
144 : USE qs_p_env_types, ONLY: p_env_release,&
145 : qs_p_env_type
146 : USE qs_rho_types, ONLY: qs_rho_get,&
147 : qs_rho_type
148 : USE qs_tensors, ONLY: &
149 : build_2c_derivatives, build_2c_integrals, build_2c_neighbor_lists, build_3c_derivatives, &
150 : build_3c_neighbor_lists, calc_2c_virial, calc_3c_virial, compress_tensor, &
151 : decompress_tensor, get_tensor_occupancy, neighbor_list_3c_destroy
152 : USE qs_tensors_types, ONLY: create_2c_tensor,&
153 : create_3c_tensor,&
154 : create_tensor_batches,&
155 : distribution_3d_create,&
156 : distribution_3d_type,&
157 : neighbor_list_3c_type
158 : USE realspace_grid_types, ONLY: map_gaussian_here,&
159 : realspace_grid_type
160 : USE response_solver, ONLY: response_equation_new
161 : USE rpa_im_time, ONLY: compute_mat_dm_global
162 : USE rpa_im_time_force_types, ONLY: im_time_force_type
163 : USE rs_pw_interface, ONLY: potential_pw2rs
164 : USE task_list_types, ONLY: task_list_type
165 : USE virial_types, ONLY: virial_type
166 : #include "./base/base_uses.f90"
167 :
168 : IMPLICIT NONE
169 :
170 : PRIVATE
171 :
172 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rpa_im_time_force_methods'
173 :
174 : PUBLIC :: init_im_time_forces, calc_laplace_loop_forces, calc_post_loop_forces, &
175 : keep_initial_quad, calc_rpa_loop_forces
176 :
177 : CONTAINS
178 :
179 : ! **************************************************************************************************
180 : !> \brief Initializes and pre-calculates all needed tensors for the forces
181 : !> \param force_data ...
182 : !> \param fm_matrix_PQ ...
183 : !> \param t_3c_M the 3-center M tensor to be used as a template
184 : !> \param unit_nr ...
185 : !> \param mp2_env ...
186 : !> \param qs_env ...
187 : ! **************************************************************************************************
188 50 : SUBROUTINE init_im_time_forces(force_data, fm_matrix_PQ, t_3c_M, unit_nr, mp2_env, qs_env)
189 :
190 : TYPE(im_time_force_type), INTENT(INOUT) :: force_data
191 : TYPE(cp_fm_type), INTENT(IN) :: fm_matrix_PQ
192 : TYPE(dbt_type), INTENT(INOUT) :: t_3c_M
193 : INTEGER, INTENT(IN) :: unit_nr
194 : TYPE(mp2_type) :: mp2_env
195 : TYPE(qs_environment_type), POINTER :: qs_env
196 :
197 : CHARACTER(LEN=*), PARAMETER :: routineN = 'init_im_time_forces'
198 :
199 : INTEGER :: handle, i_mem, i_xyz, ibasis, ispin, &
200 : n_dependent, n_mem, n_rep, natom, &
201 : nkind, nspins
202 : INTEGER(int_8) :: nze, nze_tot
203 50 : INTEGER, ALLOCATABLE, DIMENSION(:) :: dist1, dist2, dist_AO_1, dist_AO_2, &
204 50 : dist_RI, dummy_end, dummy_start, &
205 100 : end_blocks, sizes_AO, sizes_RI, &
206 50 : start_blocks
207 : INTEGER, DIMENSION(2) :: pdims_t2c
208 : INTEGER, DIMENSION(3) :: nblks_total, pcoord, pdims, pdims_t3c
209 100 : INTEGER, DIMENSION(:), POINTER :: col_bsize, row_bsize
210 : LOGICAL :: do_periodic, use_virial
211 : REAL(dp) :: compression_factor, eps_pgf_orb, &
212 : eps_pgf_orb_old, memory, occ
213 : TYPE(cell_type), POINTER :: cell
214 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
215 : TYPE(dbcsr_distribution_type) :: dbcsr_dist
216 100 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s, rho_ao
217 : TYPE(dbcsr_type) :: dbcsr_work, dbcsr_work2, dbcsr_work3
218 100 : TYPE(dbcsr_type), DIMENSION(1) :: t_2c_int_tmp
219 350 : TYPE(dbcsr_type), DIMENSION(1, 3) :: t_2c_der_tmp
220 250 : TYPE(dbt_pgrid_type) :: pgrid_t2c, pgrid_t3c
221 1000 : TYPE(dbt_type) :: t_2c_template, t_2c_tmp, t_3c_template
222 50 : TYPE(dbt_type), ALLOCATABLE, DIMENSION(:, :, :) :: t_3c_der_AO_prv, t_3c_der_RI_prv
223 : TYPE(dft_control_type), POINTER :: dft_control
224 : TYPE(distribution_2d_type), POINTER :: dist_2d
225 : TYPE(distribution_3d_type) :: dist_3d, dist_vir
226 : TYPE(gto_basis_set_p_type), ALLOCATABLE, &
227 50 : DIMENSION(:), TARGET :: basis_set_ao, basis_set_ri_aux
228 : TYPE(gto_basis_set_type), POINTER :: orb_basis, ri_basis
229 : TYPE(libint_potential_type) :: identity_pot
230 50 : TYPE(mp_cart_type) :: mp_comm_t3c, mp_comm_vir
231 : TYPE(mp_para_env_type), POINTER :: para_env
232 : TYPE(neighbor_list_3c_type) :: nl_3c
233 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
234 50 : POINTER :: nl_2c
235 50 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
236 50 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
237 : TYPE(qs_rho_type), POINTER :: rho
238 : TYPE(section_vals_type), POINTER :: qs_section
239 : TYPE(virial_type), POINTER :: virial
240 :
241 50 : NULLIFY (dft_control, para_env, particle_set, qs_kind_set, dist_2d, nl_2c, blacs_env, matrix_s, &
242 50 : rho, rho_ao, cell, qs_section, orb_basis, ri_basis, virial)
243 :
244 50 : CALL cite_reference(Bussy2023)
245 :
246 50 : CALL timeset(routineN, handle)
247 :
248 : CALL get_qs_env(qs_env, natom=natom, nkind=nkind, dft_control=dft_control, para_env=para_env, &
249 50 : particle_set=particle_set, qs_kind_set=qs_kind_set, cell=cell, virial=virial)
250 50 : IF (dft_control%qs_control%gapw) THEN
251 0 : CPABORT("Low-scaling RPA/SOS-MP2 forces only available with GPW")
252 : END IF
253 :
254 50 : use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
255 :
256 50 : do_periodic = .FALSE.
257 128 : IF (ANY(cell%perd == 1)) do_periodic = .TRUE.
258 50 : force_data%do_periodic = do_periodic
259 :
260 : !Dealing with the 3-center derivatives
261 50 : pdims_t3c = 0
262 50 : CALL dbt_pgrid_create(para_env, pdims_t3c, pgrid_t3c)
263 :
264 : !Make sure we use the proper QS EPS_PGF_ORB values
265 50 : qs_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS")
266 50 : CALL section_vals_val_get(qs_section, "EPS_PGF_ORB", n_rep_val=n_rep)
267 50 : IF (n_rep /= 0) THEN
268 0 : CALL section_vals_val_get(qs_section, "EPS_PGF_ORB", r_val=eps_pgf_orb)
269 : ELSE
270 50 : CALL section_vals_val_get(qs_section, "EPS_DEFAULT", r_val=eps_pgf_orb)
271 50 : eps_pgf_orb = SQRT(eps_pgf_orb)
272 : END IF
273 50 : eps_pgf_orb_old = dft_control%qs_control%eps_pgf_orb
274 :
275 200 : ALLOCATE (sizes_RI(natom), sizes_AO(natom))
276 400 : ALLOCATE (basis_set_ri_aux(nkind), basis_set_ao(nkind))
277 50 : CALL basis_set_list_setup(basis_set_ri_aux, "RI_AUX", qs_kind_set)
278 50 : CALL get_particle_set(particle_set, qs_kind_set, nsgf=sizes_RI, basis=basis_set_ri_aux)
279 50 : CALL basis_set_list_setup(basis_set_ao, "ORB", qs_kind_set)
280 50 : CALL get_particle_set(particle_set, qs_kind_set, nsgf=sizes_AO, basis=basis_set_ao)
281 :
282 150 : DO ibasis = 1, SIZE(basis_set_ao)
283 100 : orb_basis => basis_set_ao(ibasis)%gto_basis_set
284 100 : CALL init_interaction_radii_orb_basis(orb_basis, eps_pgf_orb)
285 100 : ri_basis => basis_set_ri_aux(ibasis)%gto_basis_set
286 150 : CALL init_interaction_radii_orb_basis(ri_basis, eps_pgf_orb)
287 : END DO
288 :
289 : CALL create_3c_tensor(t_3c_template, dist_RI, dist_AO_1, dist_AO_2, pgrid_t3c, &
290 50 : sizes_RI, sizes_AO, sizes_AO, map1=[1], map2=[2, 3], name="der (RI AO | AO)")
291 :
292 1550 : ALLOCATE (t_3c_der_RI_prv(1, 1, 3), t_3c_der_AO_prv(1, 1, 3))
293 200 : DO i_xyz = 1, 3
294 150 : CALL dbt_create(t_3c_template, t_3c_der_RI_prv(1, 1, i_xyz))
295 200 : CALL dbt_create(t_3c_template, t_3c_der_AO_prv(1, 1, i_xyz))
296 : END DO
297 :
298 50 : IF (use_virial) THEN
299 52 : ALLOCATE (force_data%t_3c_virial, force_data%t_3c_virial_split)
300 4 : CALL dbt_create(t_3c_template, force_data%t_3c_virial)
301 4 : CALL dbt_create(t_3c_M, force_data%t_3c_virial_split)
302 : END IF
303 50 : CALL dbt_destroy(t_3c_template)
304 :
305 50 : CALL dbt_mp_environ_pgrid(pgrid_t3c, pdims, pcoord)
306 50 : CALL mp_comm_t3c%create(pgrid_t3c%mp_comm_2d, 3, pdims)
307 : CALL distribution_3d_create(dist_3d, dist_RI, dist_AO_1, dist_AO_2, &
308 50 : nkind, particle_set, mp_comm_t3c, own_comm=.TRUE.)
309 :
310 : !In case of virial, we need to store the 3c_nl
311 50 : IF (use_virial) THEN
312 4 : ALLOCATE (force_data%nl_3c)
313 4 : CALL mp_comm_vir%create(pgrid_t3c%mp_comm_2d, 3, pdims)
314 : CALL distribution_3d_create(dist_vir, dist_RI, dist_AO_1, dist_AO_2, &
315 4 : nkind, particle_set, mp_comm_vir, own_comm=.TRUE.)
316 : CALL build_3c_neighbor_lists(force_data%nl_3c, basis_set_ri_aux, basis_set_ao, basis_set_ao, &
317 : dist_vir, mp2_env%ri_metric, "RPA_3c_nl", qs_env, op_pos=1, &
318 4 : sym_jk=.FALSE., own_dist=.TRUE.)
319 : END IF
320 :
321 : CALL build_3c_neighbor_lists(nl_3c, basis_set_ri_aux, basis_set_ao, basis_set_ao, dist_3d, &
322 : mp2_env%ri_metric, "RPA_3c_nl", qs_env, op_pos=1, sym_jk=.TRUE., &
323 50 : own_dist=.TRUE.)
324 50 : DEALLOCATE (dist_RI, dist_AO_1, dist_AO_2)
325 :
326 : !Prepare the resulting 3c tensors in the format of t_3c_M for compatible traces: (RI|AO AO), split blocks
327 50 : CALL dbt_get_info(t_3c_M, nblks_total=nblks_total)
328 250 : ALLOCATE (force_data%bsizes_RI_split(nblks_total(1)), force_data%bsizes_AO_split(nblks_total(2)))
329 50 : CALL dbt_get_info(t_3c_M, blk_size_1=force_data%bsizes_RI_split, blk_size_2=force_data%bsizes_AO_split)
330 200 : DO i_xyz = 1, 3
331 150 : CALL dbt_create(t_3c_M, force_data%t_3c_der_RI(i_xyz))
332 200 : CALL dbt_create(t_3c_M, force_data%t_3c_der_AO(i_xyz))
333 : END DO
334 :
335 : !Keep track of atom index corresponding to split blocks
336 100 : ALLOCATE (force_data%idx_to_at_RI(nblks_total(1)))
337 50 : CALL get_idx_to_atom(force_data%idx_to_at_RI, force_data%bsizes_RI_split, sizes_RI)
338 :
339 100 : ALLOCATE (force_data%idx_to_at_AO(nblks_total(2)))
340 50 : CALL get_idx_to_atom(force_data%idx_to_at_AO, force_data%bsizes_AO_split, sizes_AO)
341 :
342 50 : n_mem = mp2_env%ri_rpa_im_time%cut_memory
343 50 : CALL create_tensor_batches(sizes_RI, n_mem, dummy_start, dummy_end, start_blocks, end_blocks)
344 50 : DEALLOCATE (dummy_start, dummy_end)
345 :
346 212300 : ALLOCATE (force_data%t_3c_der_AO_comp(n_mem, 3), force_data%t_3c_der_RI_comp(n_mem, 3))
347 1100 : ALLOCATE (force_data%t_3c_der_AO_ind(n_mem, 3), force_data%t_3c_der_RI_ind(n_mem, 3))
348 :
349 50 : memory = 0.0_dp
350 50 : nze_tot = 0
351 150 : DO i_mem = 1, n_mem
352 : CALL build_3c_derivatives(t_3c_der_RI_prv, t_3c_der_AO_prv, mp2_env%ri_rpa_im_time%eps_filter, &
353 : qs_env, nl_3c, basis_set_ri_aux, basis_set_ao, basis_set_ao, &
354 : mp2_env%ri_metric, der_eps=mp2_env%ri_rpa_im_time%eps_filter, op_pos=1, &
355 300 : bounds_i=[start_blocks(i_mem), end_blocks(i_mem)])
356 :
357 450 : DO i_xyz = 1, 3
358 300 : CALL dbt_copy(t_3c_der_RI_prv(1, 1, i_xyz), force_data%t_3c_der_RI(i_xyz), move_data=.TRUE.)
359 300 : CALL dbt_filter(force_data%t_3c_der_RI(i_xyz), mp2_env%ri_rpa_im_time%eps_filter)
360 300 : CALL get_tensor_occupancy(force_data%t_3c_der_RI(i_xyz), nze, occ)
361 300 : nze_tot = nze_tot + nze
362 :
363 300 : CALL alloc_containers(force_data%t_3c_der_RI_comp(i_mem, i_xyz), 1)
364 : CALL compress_tensor(force_data%t_3c_der_RI(i_xyz), force_data%t_3c_der_RI_ind(i_mem, i_xyz)%ind, &
365 300 : force_data%t_3c_der_RI_comp(i_mem, i_xyz), mp2_env%ri_rpa_im_time%eps_compress, memory)
366 300 : CALL dbt_clear(force_data%t_3c_der_RI(i_xyz))
367 :
368 300 : CALL dbt_copy(t_3c_der_AO_prv(1, 1, i_xyz), force_data%t_3c_der_AO(i_xyz), move_data=.TRUE.)
369 300 : CALL dbt_filter(force_data%t_3c_der_AO(i_xyz), mp2_env%ri_rpa_im_time%eps_filter)
370 300 : CALL get_tensor_occupancy(force_data%t_3c_der_AO(i_xyz), nze, occ)
371 300 : nze_tot = nze_tot + nze
372 :
373 300 : CALL alloc_containers(force_data%t_3c_der_AO_comp(i_mem, i_xyz), 1)
374 : CALL compress_tensor(force_data%t_3c_der_AO(i_xyz), force_data%t_3c_der_AO_ind(i_mem, i_xyz)%ind, &
375 300 : force_data%t_3c_der_AO_comp(i_mem, i_xyz), mp2_env%ri_rpa_im_time%eps_compress, memory)
376 1000 : CALL dbt_clear(force_data%t_3c_der_AO(i_xyz))
377 : END DO
378 : END DO
379 50 : CALL neighbor_list_3c_destroy(nl_3c)
380 200 : DO i_xyz = 1, 3
381 150 : CALL dbt_destroy(t_3c_der_RI_prv(1, 1, i_xyz))
382 200 : CALL dbt_destroy(t_3c_der_AO_prv(1, 1, i_xyz))
383 : END DO
384 :
385 50 : CALL para_env%sum(memory)
386 50 : compression_factor = REAL(nze_tot, dp)*1.0E-06*8.0_dp/memory
387 50 : IF (unit_nr > 0) THEN
388 : WRITE (UNIT=unit_nr, FMT="((T3,A,T66,F11.2,A4))") &
389 25 : "MEMORY_INFO| Memory for 3-center derivatives (compressed):", memory, ' MiB'
390 :
391 : WRITE (UNIT=unit_nr, FMT="((T3,A,T60,F21.2))") &
392 25 : "MEMORY_INFO| Compression factor: ", compression_factor
393 : END IF
394 :
395 : !Dealing with the 2-center derivatives
396 50 : CALL get_qs_env(qs_env, distribution_2d=dist_2d, blacs_env=blacs_env, matrix_s=matrix_s)
397 50 : CALL cp_dbcsr_dist2d_to_dist(dist_2d, dbcsr_dist)
398 150 : ALLOCATE (row_bsize(SIZE(sizes_RI)))
399 100 : ALLOCATE (col_bsize(SIZE(sizes_RI)))
400 212 : row_bsize(:) = sizes_RI(:)
401 212 : col_bsize(:) = sizes_RI(:)
402 :
403 50 : pdims_t2c = 0
404 50 : CALL dbt_pgrid_create(para_env, pdims_t2c, pgrid_t2c)
405 : CALL create_2c_tensor(t_2c_template, dist1, dist2, pgrid_t2c, force_data%bsizes_RI_split, &
406 50 : force_data%bsizes_RI_split, name='(RI| RI)')
407 50 : DEALLOCATE (dist1, dist2)
408 :
409 50 : CALL dbcsr_create(t_2c_int_tmp(1), "(P|Q) RPA", dbcsr_dist, dbcsr_type_symmetric, row_bsize, col_bsize)
410 200 : DO i_xyz = 1, 3
411 : CALL dbcsr_create(t_2c_der_tmp(1, i_xyz), "(P|Q) RPA der", dbcsr_dist, &
412 200 : dbcsr_type_antisymmetric, row_bsize, col_bsize)
413 : END DO
414 :
415 50 : IF (use_virial) THEN
416 4 : ALLOCATE (force_data%RI_virial_pot, force_data%RI_virial_met)
417 : CALL dbcsr_create(force_data%RI_virial_pot, "RI_virial", dbcsr_dist, &
418 4 : dbcsr_type_no_symmetry, row_bsize, col_bsize)
419 : CALL dbcsr_create(force_data%RI_virial_met, "RI_virial", dbcsr_dist, &
420 4 : dbcsr_type_no_symmetry, row_bsize, col_bsize)
421 : END IF
422 :
423 : ! Main (P|Q) integrals and derivatives
424 : ! Integrals are passed as a full matrix => convert to DBCSR
425 50 : CALL dbcsr_create(dbcsr_work, template=t_2c_int_tmp(1))
426 50 : CALL copy_fm_to_dbcsr(fm_matrix_PQ, dbcsr_work)
427 :
428 : ! We need the +/- square root of (P|Q)
429 50 : CALL dbcsr_create(dbcsr_work2, template=t_2c_int_tmp(1))
430 50 : CALL dbcsr_create(dbcsr_work3, template=t_2c_int_tmp(1))
431 50 : CALL dbcsr_copy(dbcsr_work2, dbcsr_work)
432 50 : CALL cp_dbcsr_power(dbcsr_work, -0.5_dp, 1.0E-7_dp, n_dependent, para_env, blacs_env) !1.0E-7 ev qunenching thresh
433 :
434 : ! Transfer to tensor format with split blocks
435 50 : CALL dbt_create(dbcsr_work, t_2c_tmp)
436 50 : CALL dbt_copy_matrix_to_tensor(dbcsr_work, t_2c_tmp)
437 50 : CALL dbt_create(t_2c_template, force_data%t_2c_pot_msqrt)
438 50 : CALL dbt_copy(t_2c_tmp, force_data%t_2c_pot_msqrt, move_data=.TRUE.)
439 50 : CALL dbt_filter(force_data%t_2c_pot_msqrt, mp2_env%ri_rpa_im_time%eps_filter)
440 :
441 50 : CALL dbcsr_multiply('N', 'N', 1.0_dp, dbcsr_work2, dbcsr_work, 0.0_dp, dbcsr_work3)
442 50 : CALL dbt_copy_matrix_to_tensor(dbcsr_work3, t_2c_tmp)
443 50 : CALL dbt_create(t_2c_template, force_data%t_2c_pot_psqrt)
444 50 : CALL dbt_copy(t_2c_tmp, force_data%t_2c_pot_psqrt, move_data=.TRUE.)
445 50 : CALL dbt_filter(force_data%t_2c_pot_psqrt, mp2_env%ri_rpa_im_time%eps_filter)
446 50 : CALL dbt_destroy(t_2c_tmp)
447 50 : CALL dbcsr_release(dbcsr_work2)
448 50 : CALL dbcsr_release(dbcsr_work3)
449 50 : CALL dbcsr_clear(dbcsr_work)
450 :
451 : ! Deal with the 2c potential derivatives. Only precompute if not in PBCs
452 50 : IF (.NOT. do_periodic) THEN
453 : CALL build_2c_neighbor_lists(nl_2c, basis_set_ri_aux, basis_set_ri_aux, mp2_env%potential_parameter, &
454 26 : "RPA_2c_nl_pot", qs_env, sym_ij=.TRUE., dist_2d=dist_2d)
455 : CALL build_2c_derivatives(t_2c_der_tmp, mp2_env%ri_rpa_im_time%eps_filter, qs_env, nl_2c, &
456 26 : basis_set_ri_aux, basis_set_ri_aux, mp2_env%potential_parameter)
457 26 : CALL release_neighbor_list_sets(nl_2c)
458 :
459 104 : DO i_xyz = 1, 3
460 78 : CALL dbt_create(t_2c_der_tmp(1, i_xyz), t_2c_tmp)
461 78 : CALL dbt_copy_matrix_to_tensor(t_2c_der_tmp(1, i_xyz), t_2c_tmp)
462 78 : CALL dbt_create(t_2c_template, force_data%t_2c_der_pot(i_xyz))
463 78 : CALL dbt_copy(t_2c_tmp, force_data%t_2c_der_pot(i_xyz), move_data=.TRUE.)
464 78 : CALL dbt_filter(force_data%t_2c_der_pot(i_xyz), mp2_env%ri_rpa_im_time%eps_filter)
465 78 : CALL dbt_destroy(t_2c_tmp)
466 104 : CALL dbcsr_clear(t_2c_der_tmp(1, i_xyz))
467 : END DO
468 :
469 26 : IF (use_virial) THEN
470 : CALL build_2c_neighbor_lists(force_data%nl_2c_pot, basis_set_ri_aux, basis_set_ri_aux, &
471 : mp2_env%potential_parameter, "RPA_2c_nl_pot", qs_env, &
472 0 : sym_ij=.FALSE., dist_2d=dist_2d)
473 : END IF
474 : END IF
475 : ! Create a G_PQ matrix to collect the terms for the force trace in the periodic case
476 50 : CALL dbcsr_create(force_data%G_PQ, "G_PQ", dbcsr_dist, dbcsr_type_no_symmetry, row_bsize, col_bsize)
477 :
478 : ! we need the RI metric derivatives and the inverse of the integrals
479 : CALL build_2c_neighbor_lists(nl_2c, basis_set_ri_aux, basis_set_ri_aux, mp2_env%ri_metric, &
480 50 : "RPA_2c_nl_metric", qs_env, sym_ij=.TRUE., dist_2d=dist_2d)
481 : CALL build_2c_integrals(t_2c_int_tmp, mp2_env%ri_rpa_im_time%eps_filter, qs_env, nl_2c, &
482 50 : basis_set_ri_aux, basis_set_ri_aux, mp2_env%ri_metric)
483 : CALL build_2c_derivatives(t_2c_der_tmp, mp2_env%ri_rpa_im_time%eps_filter, qs_env, nl_2c, &
484 50 : basis_set_ri_aux, basis_set_ri_aux, mp2_env%ri_metric)
485 50 : CALL release_neighbor_list_sets(nl_2c)
486 :
487 50 : IF (use_virial) THEN
488 : CALL build_2c_neighbor_lists(force_data%nl_2c_met, basis_set_ri_aux, basis_set_ri_aux, &
489 : mp2_env%ri_metric, "RPA_2c_nl_metric", qs_env, sym_ij=.FALSE., &
490 4 : dist_2d=dist_2d)
491 : END IF
492 :
493 50 : CALL dbcsr_copy(dbcsr_work, t_2c_int_tmp(1))
494 50 : CALL cp_dbcsr_cholesky_decompose(dbcsr_work, para_env=para_env, blacs_env=blacs_env)
495 50 : CALL cp_dbcsr_cholesky_invert(dbcsr_work, para_env=para_env, blacs_env=blacs_env, uplo_to_full=.TRUE.)
496 :
497 50 : CALL dbt_create(dbcsr_work, t_2c_tmp)
498 50 : CALL dbt_copy_matrix_to_tensor(dbcsr_work, t_2c_tmp)
499 50 : CALL dbt_create(t_2c_template, force_data%t_2c_inv_metric)
500 50 : CALL dbt_copy(t_2c_tmp, force_data%t_2c_inv_metric, move_data=.TRUE.)
501 50 : CALL dbt_filter(force_data%t_2c_inv_metric, mp2_env%ri_rpa_im_time%eps_filter)
502 50 : CALL dbt_destroy(t_2c_tmp)
503 50 : CALL dbcsr_clear(dbcsr_work)
504 50 : CALL dbcsr_clear(t_2c_int_tmp(1))
505 :
506 200 : DO i_xyz = 1, 3
507 150 : CALL dbt_create(t_2c_der_tmp(1, i_xyz), t_2c_tmp)
508 150 : CALL dbt_copy_matrix_to_tensor(t_2c_der_tmp(1, i_xyz), t_2c_tmp)
509 150 : CALL dbt_create(t_2c_template, force_data%t_2c_der_metric(i_xyz))
510 150 : CALL dbt_copy(t_2c_tmp, force_data%t_2c_der_metric(i_xyz), move_data=.TRUE.)
511 150 : CALL dbt_filter(force_data%t_2c_der_metric(i_xyz), mp2_env%ri_rpa_im_time%eps_filter)
512 150 : CALL dbt_destroy(t_2c_tmp)
513 200 : CALL dbcsr_clear(t_2c_der_tmp(1, i_xyz))
514 : END DO
515 :
516 : !Pre-calculate matrix K = metric^-1 * V^0.5
517 50 : CALL dbt_create(t_2c_template, force_data%t_2c_K)
518 : CALL dbt_contract(1.0_dp, force_data%t_2c_inv_metric, force_data%t_2c_pot_psqrt, &
519 : 0.0_dp, force_data%t_2c_K, &
520 : contract_1=[2], notcontract_1=[1], &
521 : contract_2=[1], notcontract_2=[2], &
522 50 : map_1=[1], map_2=[2], filter_eps=mp2_env%ri_rpa_im_time%eps_filter)
523 :
524 : ! Finally, we need the overlap matrix derivative and the inverse of the integrals
525 50 : CALL dbt_destroy(t_2c_template)
526 50 : CALL dbcsr_release(dbcsr_work)
527 50 : CALL dbcsr_release(t_2c_int_tmp(1))
528 200 : DO i_xyz = 1, 3
529 200 : CALL dbcsr_release(t_2c_der_tmp(1, i_xyz))
530 : END DO
531 :
532 50 : DEALLOCATE (row_bsize, col_bsize)
533 150 : ALLOCATE (row_bsize(SIZE(sizes_AO)))
534 100 : ALLOCATE (col_bsize(SIZE(sizes_AO)))
535 212 : row_bsize(:) = sizes_AO(:)
536 212 : col_bsize(:) = sizes_AO(:)
537 :
538 : CALL create_2c_tensor(t_2c_template, dist1, dist2, pgrid_t2c, force_data%bsizes_AO_split, &
539 : force_data%bsizes_AO_split, name='(AO| AO)')
540 50 : DEALLOCATE (dist1, dist2)
541 :
542 200 : DO i_xyz = 1, 3
543 : CALL dbcsr_create(t_2c_der_tmp(1, i_xyz), "(P|Q) RPA der", dbcsr_dist, &
544 200 : dbcsr_type_antisymmetric, row_bsize, col_bsize)
545 : END DO
546 :
547 50 : identity_pot%potential_type = do_potential_id
548 : CALL build_2c_neighbor_lists(nl_2c, basis_set_ao, basis_set_ao, identity_pot, &
549 50 : "RPA_2c_nl_metric", qs_env, sym_ij=.TRUE., dist_2d=dist_2d)
550 : CALL build_2c_derivatives(t_2c_der_tmp, mp2_env%ri_rpa_im_time%eps_filter, qs_env, nl_2c, &
551 50 : basis_set_ao, basis_set_ao, identity_pot)
552 50 : CALL release_neighbor_list_sets(nl_2c)
553 :
554 50 : IF (use_virial) THEN
555 : CALL build_2c_neighbor_lists(force_data%nl_2c_ovlp, basis_set_ao, basis_set_ao, identity_pot, &
556 4 : "RPA_2c_nl_metric", qs_env, sym_ij=.FALSE., dist_2d=dist_2d)
557 : END IF
558 :
559 50 : CALL dbcsr_create(force_data%inv_ovlp, template=matrix_s(1)%matrix)
560 50 : CALL dbcsr_copy(force_data%inv_ovlp, matrix_s(1)%matrix)
561 50 : CALL cp_dbcsr_cholesky_decompose(force_data%inv_ovlp, para_env=para_env, blacs_env=blacs_env)
562 50 : CALL cp_dbcsr_cholesky_invert(force_data%inv_ovlp, para_env=para_env, blacs_env=blacs_env, uplo_to_full=.TRUE.)
563 :
564 200 : DO i_xyz = 1, 3
565 150 : CALL dbt_create(t_2c_der_tmp(1, i_xyz), t_2c_tmp)
566 150 : CALL dbt_copy_matrix_to_tensor(t_2c_der_tmp(1, i_xyz), t_2c_tmp)
567 150 : CALL dbt_create(t_2c_template, force_data%t_2c_der_ovlp(i_xyz))
568 150 : CALL dbt_copy(t_2c_tmp, force_data%t_2c_der_ovlp(i_xyz), move_data=.TRUE.)
569 150 : CALL dbt_filter(force_data%t_2c_der_ovlp(i_xyz), mp2_env%ri_rpa_im_time%eps_filter)
570 150 : CALL dbt_destroy(t_2c_tmp)
571 200 : CALL dbcsr_clear(t_2c_der_tmp(1, i_xyz))
572 : END DO
573 :
574 : !Create the rest of the 2-center AO tensors
575 50 : nspins = dft_control%nspins
576 324 : ALLOCATE (force_data%P_virt(nspins), force_data%P_occ(nspins))
577 274 : ALLOCATE (force_data%sum_YP_tau(nspins), force_data%sum_O_tau(nspins))
578 112 : DO ispin = 1, nspins
579 62 : ALLOCATE (force_data%P_virt(ispin)%matrix, force_data%P_occ(ispin)%matrix)
580 62 : ALLOCATE (force_data%sum_YP_tau(ispin)%matrix, force_data%sum_O_tau(ispin)%matrix)
581 62 : CALL dbcsr_create(force_data%P_virt(ispin)%matrix, template=matrix_s(1)%matrix)
582 62 : CALL dbcsr_create(force_data%P_occ(ispin)%matrix, template=matrix_s(1)%matrix)
583 62 : CALL dbcsr_create(force_data%sum_O_tau(ispin)%matrix, template=matrix_s(1)%matrix)
584 62 : CALL dbcsr_create(force_data%sum_YP_tau(ispin)%matrix, template=matrix_s(1)%matrix)
585 :
586 62 : CALL dbcsr_copy(force_data%sum_O_tau(ispin)%matrix, matrix_s(1)%matrix)
587 62 : CALL dbcsr_copy(force_data%sum_YP_tau(ispin)%matrix, matrix_s(1)%matrix)
588 :
589 62 : CALL dbcsr_set(force_data%sum_O_tau(ispin)%matrix, 0.0_dp)
590 112 : CALL dbcsr_set(force_data%sum_YP_tau(ispin)%matrix, 0.0_dp)
591 : END DO
592 :
593 : !Populate the density matrices: 1 = P_virt*S +P_occ*S ==> P_virt = S^-1 - P_occ
594 50 : CALL get_qs_env(qs_env, rho=rho)
595 50 : CALL qs_rho_get(rho, rho_ao=rho_ao)
596 50 : CALL dbcsr_copy(force_data%P_occ(1)%matrix, rho_ao(1)%matrix)
597 50 : IF (nspins == 1) THEN
598 38 : CALL dbcsr_scale(force_data%P_occ(1)%matrix, 0.5_dp) !because double occupency
599 : ELSE
600 12 : CALL dbcsr_copy(force_data%P_occ(2)%matrix, rho_ao(2)%matrix)
601 : END IF
602 112 : DO ispin = 1, nspins
603 62 : CALL dbcsr_copy(force_data%P_virt(ispin)%matrix, force_data%inv_ovlp)
604 112 : CALL dbcsr_add(force_data%P_virt(ispin)%matrix, force_data%P_occ(ispin)%matrix, 1.0_dp, -1.0_dp)
605 : END DO
606 :
607 150 : DO ibasis = 1, SIZE(basis_set_ao)
608 100 : orb_basis => basis_set_ao(ibasis)%gto_basis_set
609 100 : CALL init_interaction_radii_orb_basis(orb_basis, eps_pgf_orb_old)
610 100 : ri_basis => basis_set_ri_aux(ibasis)%gto_basis_set
611 150 : CALL init_interaction_radii_orb_basis(ri_basis, eps_pgf_orb_old)
612 : END DO
613 :
614 50 : CALL dbt_destroy(t_2c_template)
615 50 : CALL dbcsr_release(dbcsr_work)
616 200 : DO i_xyz = 1, 3
617 200 : CALL dbcsr_release(t_2c_der_tmp(1, i_xyz))
618 : END DO
619 50 : DEALLOCATE (row_bsize, col_bsize)
620 50 : CALL dbt_pgrid_destroy(pgrid_t3c)
621 50 : CALL dbt_pgrid_destroy(pgrid_t2c)
622 50 : CALL dbcsr_distribution_release(dbcsr_dist)
623 50 : CALL timestop(handle)
624 :
625 750 : END SUBROUTINE init_im_time_forces
626 :
627 : ! **************************************************************************************************
628 : !> \brief Updates the cubic-scaling SOS-Laplace-MP2 contribution to the forces at each quadrature point
629 : !> \param force_data ...
630 : !> \param mat_P_omega ...
631 : !> \param t_3c_M ...
632 : !> \param t_3c_O ...
633 : !> \param t_3c_O_compressed ...
634 : !> \param t_3c_O_ind ...
635 : !> \param fm_scaled_dm_occ_tau ...
636 : !> \param fm_scaled_dm_virt_tau ...
637 : !> \param fm_mo_coeff_occ ...
638 : !> \param fm_mo_coeff_virt ...
639 : !> \param fm_mo_coeff_occ_scaled ...
640 : !> \param fm_mo_coeff_virt_scaled ...
641 : !> \param starts_array_mc ...
642 : !> \param ends_array_mc ...
643 : !> \param starts_array_mc_block ...
644 : !> \param ends_array_mc_block ...
645 : !> \param num_integ_points ...
646 : !> \param nmo ...
647 : !> \param Eigenval ...
648 : !> \param tau_tj ...
649 : !> \param tau_wj ...
650 : !> \param cut_memory ...
651 : !> \param Pspin ...
652 : !> \param Qspin ...
653 : !> \param open_shell ...
654 : !> \param unit_nr ...
655 : !> \param dbcsr_time ...
656 : !> \param dbcsr_nflop ...
657 : !> \param mp2_env ...
658 : !> \param qs_env ...
659 : !> \note In open-shell, we need to take Q from one spin, and everything from the other
660 : ! **************************************************************************************************
661 130 : SUBROUTINE calc_laplace_loop_forces(force_data, mat_P_omega, t_3c_M, t_3c_O, t_3c_O_compressed, &
662 26 : t_3c_O_ind, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, &
663 26 : fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, &
664 26 : fm_mo_coeff_virt_scaled, starts_array_mc, ends_array_mc, &
665 26 : starts_array_mc_block, ends_array_mc_block, num_integ_points, &
666 52 : nmo, Eigenval, tau_tj, tau_wj, cut_memory, Pspin, Qspin, &
667 : open_shell, unit_nr, dbcsr_time, dbcsr_nflop, mp2_env, qs_env)
668 :
669 : TYPE(im_time_force_type), INTENT(INOUT) :: force_data
670 : TYPE(dbcsr_p_type), DIMENSION(:, :), INTENT(INOUT) :: mat_P_omega
671 : TYPE(dbt_type), INTENT(INOUT) :: t_3c_M, t_3c_O
672 : TYPE(hfx_compression_type), DIMENSION(:) :: t_3c_O_compressed
673 : TYPE(block_ind_type), DIMENSION(:), INTENT(INOUT) :: t_3c_O_ind
674 : TYPE(cp_fm_type), INTENT(IN) :: fm_scaled_dm_occ_tau, &
675 : fm_scaled_dm_virt_tau
676 : TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: fm_mo_coeff_occ, fm_mo_coeff_virt
677 : TYPE(cp_fm_type), INTENT(IN) :: fm_mo_coeff_occ_scaled, &
678 : fm_mo_coeff_virt_scaled
679 : INTEGER, DIMENSION(:), INTENT(IN) :: starts_array_mc, ends_array_mc, &
680 : starts_array_mc_block, &
681 : ends_array_mc_block
682 : INTEGER, INTENT(IN) :: num_integ_points, nmo
683 : REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: Eigenval
684 : REAL(KIND=dp), DIMENSION(0:num_integ_points), &
685 : INTENT(IN) :: tau_tj
686 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
687 : INTENT(IN) :: tau_wj
688 : INTEGER, INTENT(IN) :: cut_memory, Pspin, Qspin
689 : LOGICAL, INTENT(IN) :: open_shell
690 : INTEGER, INTENT(IN) :: unit_nr
691 : REAL(dp), INTENT(INOUT) :: dbcsr_time
692 : INTEGER(int_8), INTENT(INOUT) :: dbcsr_nflop
693 : TYPE(mp2_type) :: mp2_env
694 : TYPE(qs_environment_type), POINTER :: qs_env
695 :
696 : CHARACTER(LEN=*), PARAMETER :: routineN = 'calc_laplace_loop_forces'
697 :
698 : INTEGER :: dummy_int, handle, handle2, i_mem, i_xyz, ibasis, ispin, j_xyz, jquad, k_xyz, &
699 : n_mem_RI, n_rep, natom, nkind, nspins, unit_nr_dbcsr
700 : INTEGER(int_8) :: flop, nze, nze_ddint, nze_der_AO, &
701 : nze_der_RI, nze_KQK
702 26 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, batch_blk_end, &
703 26 : batch_blk_start, batch_end_RI, &
704 26 : batch_start_RI, kind_of, mc_ranges, &
705 26 : mc_ranges_RI
706 26 : INTEGER, DIMENSION(:, :), POINTER :: dummy_ptr
707 : LOGICAL :: memory_info, use_virial
708 : REAL(dp) :: eps_filter, eps_pgf_orb, &
709 : eps_pgf_orb_old, fac, occ, occ_ddint, &
710 : occ_der_AO, occ_der_RI, occ_KQK, &
711 : omega, pref, t1, t2, tau
712 : REAL(dp), DIMENSION(3, 3) :: work_virial, work_virial_ovlp
713 26 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
714 : TYPE(cell_type), POINTER :: cell
715 26 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s
716 26 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_dm_occ, mat_dm_virt
717 : TYPE(dbcsr_type) :: dbcsr_work1, dbcsr_work2, dbcsr_work3, &
718 : exp_occ, exp_virt, R_occ, R_virt, &
719 : virial_ovlp, Y_1, Y_2
720 1274 : TYPE(dbt_type) :: t_2c_AO, t_2c_RI, t_2c_RI_2, t_2c_tmp, t_3c_0, t_3c_1, t_3c_3, t_3c_4, &
721 1274 : t_3c_5, t_3c_6, t_3c_7, t_3c_8, t_3c_help_1, t_3c_help_2, t_3c_ints, t_3c_sparse, &
722 1456 : t_3c_work, t_dm_occ, t_dm_virt, t_KQKT, t_M_occ, t_M_virt, t_Q, t_R_occ, t_R_virt
723 26 : TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: t_P
724 : TYPE(dft_control_type), POINTER :: dft_control
725 : TYPE(gto_basis_set_p_type), ALLOCATABLE, &
726 26 : DIMENSION(:), TARGET :: basis_set_ao, basis_set_ri_aux
727 : TYPE(gto_basis_set_type), POINTER :: orb_basis, ri_basis
728 : TYPE(libint_potential_type) :: identity_pot
729 : TYPE(mp_para_env_type), POINTER :: para_env
730 26 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
731 26 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
732 26 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
733 : TYPE(section_vals_type), POINTER :: qs_section
734 : TYPE(virial_type), POINTER :: virial
735 :
736 26 : NULLIFY (matrix_s, dummy_ptr, atomic_kind_set, force, matrix_s, matrix_ks, mat_dm_occ, mat_dm_virt)
737 26 : NULLIFY (dft_control, virial, particle_set, cell, para_env, orb_basis, ri_basis, qs_section)
738 26 : NULLIFY (qs_kind_set)
739 :
740 26 : CALL timeset(routineN, handle)
741 :
742 : CALL get_qs_env(qs_env, matrix_s=matrix_s, natom=natom, atomic_kind_set=atomic_kind_set, &
743 : force=force, matrix_ks=matrix_ks, dft_control=dft_control, virial=virial, &
744 : particle_set=particle_set, cell=cell, para_env=para_env, nkind=nkind, &
745 26 : qs_kind_set=qs_kind_set)
746 26 : eps_filter = mp2_env%ri_rpa_im_time%eps_filter
747 26 : nspins = dft_control%nspins
748 :
749 26 : memory_info = mp2_env%ri_rpa_im_time%memory_info
750 26 : IF (memory_info) THEN
751 0 : unit_nr_dbcsr = unit_nr
752 : ELSE
753 26 : unit_nr_dbcsr = 0
754 : END IF
755 :
756 26 : use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
757 :
758 26 : IF (use_virial) virial%pv_calculate = .TRUE.
759 :
760 26 : IF (use_virial) THEN
761 2 : qs_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS")
762 2 : CALL section_vals_val_get(qs_section, "EPS_PGF_ORB", n_rep_val=n_rep)
763 2 : IF (n_rep /= 0) THEN
764 0 : CALL section_vals_val_get(qs_section, "EPS_PGF_ORB", r_val=eps_pgf_orb)
765 : ELSE
766 2 : CALL section_vals_val_get(qs_section, "EPS_DEFAULT", r_val=eps_pgf_orb)
767 2 : eps_pgf_orb = SQRT(eps_pgf_orb)
768 : END IF
769 2 : eps_pgf_orb_old = dft_control%qs_control%eps_pgf_orb
770 :
771 16 : ALLOCATE (basis_set_ri_aux(nkind), basis_set_ao(nkind))
772 2 : CALL basis_set_list_setup(basis_set_ri_aux, "RI_AUX", qs_kind_set)
773 2 : CALL basis_set_list_setup(basis_set_ao, "ORB", qs_kind_set)
774 :
775 8 : DO ibasis = 1, SIZE(basis_set_ao)
776 4 : orb_basis => basis_set_ao(ibasis)%gto_basis_set
777 4 : CALL init_interaction_radii_orb_basis(orb_basis, eps_pgf_orb)
778 4 : ri_basis => basis_set_ri_aux(ibasis)%gto_basis_set
779 6 : CALL init_interaction_radii_orb_basis(ri_basis, eps_pgf_orb)
780 : END DO
781 : END IF
782 :
783 : !We follow the general logic of the compute_mat_P_omega routine
784 268 : ALLOCATE (t_P(nspins))
785 26 : CALL dbt_create(force_data%t_2c_K, t_2c_RI)
786 26 : CALL dbt_create(force_data%t_2c_K, t_2c_RI_2)
787 26 : CALL dbt_create(force_data%t_2c_der_ovlp(1), t_2c_AO)
788 :
789 26 : CALL get_atomic_kind_set(atomic_kind_set, kind_of=kind_of, atom_of_kind=atom_of_kind)
790 :
791 : ! Always do the batching of the MO on mu and sigma, such that it is consistent between
792 : ! the occupied and the virtual quantities
793 78 : ALLOCATE (mc_ranges(cut_memory + 1))
794 78 : mc_ranges(:cut_memory) = starts_array_mc_block(:)
795 26 : mc_ranges(cut_memory + 1) = ends_array_mc_block(cut_memory) + 1
796 :
797 : ! Also need some batching on the RI, because it loses sparsity at some point
798 26 : n_mem_RI = cut_memory
799 : CALL create_tensor_batches(force_data%bsizes_RI_split, n_mem_RI, batch_start_RI, batch_end_RI, &
800 26 : batch_blk_start, batch_blk_end)
801 78 : ALLOCATE (mc_ranges_RI(n_mem_RI + 1))
802 78 : mc_ranges_RI(1:n_mem_RI) = batch_blk_start(1:n_mem_RI)
803 26 : mc_ranges_RI(n_mem_RI + 1) = batch_blk_end(n_mem_RI) + 1
804 26 : DEALLOCATE (batch_blk_start, batch_blk_end)
805 :
806 : !Pre-allocate all required tensors and matrices
807 60 : DO ispin = 1, nspins
808 60 : CALL dbt_create(t_2c_RI, t_P(ispin))
809 : END DO
810 26 : CALL dbt_create(t_2c_RI, t_Q)
811 26 : CALL dbt_create(t_2c_RI, t_KQKT)
812 26 : CALL dbt_create(t_2c_AO, t_dm_occ)
813 26 : CALL dbt_create(t_2c_AO, t_dm_virt)
814 :
815 : !note: t_3c_O and t_3c_M have different mappings (map_1d, map_2d)
816 26 : CALL dbt_create(t_3c_O, t_M_occ)
817 26 : CALL dbt_create(t_3c_O, t_M_virt)
818 26 : CALL dbt_create(t_3c_O, t_3c_0)
819 :
820 26 : CALL dbt_create(t_3c_O, t_3c_1)
821 26 : CALL dbt_create(t_3c_O, t_3c_3)
822 26 : CALL dbt_create(t_3c_O, t_3c_4)
823 26 : CALL dbt_create(t_3c_O, t_3c_5)
824 26 : CALL dbt_create(t_3c_M, t_3c_6)
825 26 : CALL dbt_create(t_3c_M, t_3c_7)
826 26 : CALL dbt_create(t_3c_M, t_3c_8)
827 26 : CALL dbt_create(t_3c_M, t_3c_sparse)
828 26 : CALL dbt_create(t_3c_O, t_3c_help_1)
829 26 : CALL dbt_create(t_3c_O, t_3c_help_2)
830 26 : CALL dbt_create(t_2c_AO, t_R_occ)
831 26 : CALL dbt_create(t_2c_AO, t_R_virt)
832 26 : CALL dbt_create(t_3c_M, t_3c_ints)
833 26 : CALL dbt_create(t_3c_M, t_3c_work)
834 :
835 : !Pre-define the sparsity of t_3c_4 as a function of the derivatives
836 26 : occ_der_AO = 0; nze_der_AO = 0
837 26 : occ_der_RI = 0; nze_der_RI = 0
838 104 : DO i_xyz = 1, 3
839 260 : DO i_mem = 1, cut_memory
840 : CALL decompress_tensor(force_data%t_3c_der_RI(i_xyz), force_data%t_3c_der_RI_ind(i_mem, i_xyz)%ind, &
841 156 : force_data%t_3c_der_RI_comp(i_mem, i_xyz), mp2_env%ri_rpa_im_time%eps_compress)
842 156 : CALL get_tensor_occupancy(force_data%t_3c_der_RI(i_xyz), nze, occ)
843 156 : occ_der_RI = occ_der_RI + occ
844 156 : nze_der_RI = nze_der_RI + nze
845 156 : CALL dbt_copy(force_data%t_3c_der_RI(i_xyz), t_3c_sparse, summation=.TRUE., move_data=.TRUE.)
846 :
847 : CALL decompress_tensor(force_data%t_3c_der_AO(i_xyz), force_data%t_3c_der_AO_ind(i_mem, i_xyz)%ind, &
848 156 : force_data%t_3c_der_AO_comp(i_mem, i_xyz), mp2_env%ri_rpa_im_time%eps_compress)
849 156 : CALL get_tensor_occupancy(force_data%t_3c_der_AO(i_xyz), nze, occ)
850 156 : occ_der_AO = occ_der_AO + occ
851 156 : nze_der_AO = nze_der_AO + nze
852 156 : CALL dbt_copy(force_data%t_3c_der_AO(i_xyz), t_3c_sparse, order=[1, 3, 2], summation=.TRUE.)
853 546 : CALL dbt_copy(force_data%t_3c_der_AO(i_xyz), t_3c_sparse, summation=.TRUE., move_data=.TRUE.)
854 : END DO
855 : END DO
856 26 : occ_der_RI = occ_der_RI/3.0_dp
857 26 : occ_der_AO = occ_der_AO/3.0_dp
858 26 : nze_der_RI = nze_der_RI/3
859 26 : nze_der_AO = nze_der_AO/3
860 :
861 26 : CALL dbcsr_create(R_occ, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
862 26 : CALL dbcsr_create(R_virt, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
863 26 : CALL dbcsr_create(dbcsr_work1, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
864 26 : CALL dbcsr_create(dbcsr_work2, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
865 26 : CALL dbcsr_create(dbcsr_work3, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
866 26 : CALL dbcsr_create(exp_occ, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
867 26 : CALL dbcsr_create(exp_virt, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
868 26 : IF (use_virial) CALL dbcsr_create(virial_ovlp, template=dbcsr_work1)
869 :
870 26 : CALL dbt_batched_contract_init(t_3c_0, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
871 26 : CALL dbt_batched_contract_init(t_3c_1, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
872 26 : CALL dbt_batched_contract_init(t_3c_3, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
873 26 : CALL dbt_batched_contract_init(t_M_occ, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
874 26 : CALL dbt_batched_contract_init(t_M_virt, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
875 :
876 26 : CALL dbt_batched_contract_init(t_3c_ints, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
877 26 : CALL dbt_batched_contract_init(t_3c_work, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
878 :
879 : CALL dbt_batched_contract_init(t_3c_4, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
880 26 : batch_range_3=mc_ranges)
881 : CALL dbt_batched_contract_init(t_3c_5, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
882 26 : batch_range_3=mc_ranges)
883 : CALL dbt_batched_contract_init(t_3c_6, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
884 26 : batch_range_3=mc_ranges)
885 : CALL dbt_batched_contract_init(t_3c_7, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
886 26 : batch_range_3=mc_ranges)
887 : CALL dbt_batched_contract_init(t_3c_8, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
888 26 : batch_range_3=mc_ranges)
889 : CALL dbt_batched_contract_init(t_3c_sparse, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
890 26 : batch_range_3=mc_ranges)
891 :
892 26 : work_virial = 0.0_dp
893 26 : work_virial_ovlp = 0.0_dp
894 104 : DO jquad = 1, num_integ_points
895 78 : tau = tau_tj(jquad)
896 78 : omega = tau_wj(jquad)
897 78 : fac = -2.0_dp*omega*mp2_env%scale_S
898 78 : IF (open_shell) fac = 0.5_dp*fac
899 78 : occ_ddint = 0; nze_ddint = 0
900 :
901 78 : CALL para_env%sync()
902 78 : t1 = m_walltime()
903 :
904 : !Deal with the force contributions where there is no explicit 3-center quantities, i.e. the
905 : !forces due to the metric and potential derivatives
906 180 : DO ispin = 1, nspins
907 102 : CALL dbt_create(mat_P_omega(jquad, ispin)%matrix, t_2c_tmp)
908 102 : CALL dbt_copy_matrix_to_tensor(mat_P_omega(jquad, ispin)%matrix, t_2c_tmp)
909 102 : CALL dbt_copy(t_2c_tmp, t_P(ispin), move_data=.TRUE.)
910 102 : CALL dbt_filter(t_P(ispin), eps_filter)
911 180 : CALL dbt_destroy(t_2c_tmp)
912 : END DO
913 :
914 : !Q = K^T*P*K, open-shell: Q is from one spin, everything else from the other
915 : CALL dbt_contract(1.0_dp, t_P(Qspin), force_data%t_2c_K, 0.0_dp, t_2c_RI, &
916 : contract_1=[2], notcontract_1=[1], &
917 : contract_2=[1], notcontract_2=[2], &
918 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
919 78 : flop=flop, unit_nr=unit_nr_dbcsr)
920 78 : dbcsr_nflop = dbcsr_nflop + flop
921 : CALL dbt_contract(1.0_dp, force_data%t_2c_K, t_2c_RI, 0.0_dp, t_Q, &
922 : contract_1=[1], notcontract_1=[2], &
923 : contract_2=[1], notcontract_2=[2], &
924 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
925 78 : flop=flop, unit_nr=unit_nr_dbcsr)
926 78 : dbcsr_nflop = dbcsr_nflop + flop
927 78 : CALL dbt_clear(t_2c_RI)
928 :
929 : CALL perform_2c_ops(force, t_KQKT, force_data, fac, t_Q, t_P(Pspin), t_2c_RI, t_2c_RI_2, &
930 78 : use_virial, atom_of_kind, kind_of, eps_filter, dbcsr_nflop, unit_nr_dbcsr)
931 78 : CALL get_tensor_occupancy(t_KQKT, nze_KQK, occ_KQK)
932 :
933 : !Calculate the pseudo-density matrix in tensor form. There are a few useless arguments for SOS-MP2
934 : CALL compute_mat_dm_global(fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, tau_tj, num_integ_points, &
935 : nmo, fm_mo_coeff_occ(Pspin), fm_mo_coeff_virt(Pspin), &
936 : fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, mat_dm_occ, mat_dm_virt, &
937 : matrix_s, Pspin, Eigenval(:, Pspin), 0.0_dp, eps_filter, &
938 : mp2_env%ri_rpa_im_time%memory_info, unit_nr, &
939 78 : jquad, .FALSE., .FALSE., qs_env, dummy_int, dummy_ptr, para_env)
940 :
941 78 : CALL dbt_create(mat_dm_occ(jquad, 1)%matrix, t_2c_tmp)
942 78 : CALL dbt_copy_matrix_to_tensor(mat_dm_occ(jquad, 1)%matrix, t_2c_tmp)
943 78 : CALL dbt_copy(t_2c_tmp, t_dm_occ, move_data=.TRUE.)
944 78 : CALL dbt_filter(t_dm_occ, eps_filter)
945 78 : CALL dbt_destroy(t_2c_tmp)
946 :
947 78 : CALL dbt_create(mat_dm_virt(jquad, 1)%matrix, t_2c_tmp)
948 78 : CALL dbt_copy_matrix_to_tensor(mat_dm_virt(jquad, 1)%matrix, t_2c_tmp)
949 78 : CALL dbt_copy(t_2c_tmp, t_dm_virt, move_data=.TRUE.)
950 78 : CALL dbt_filter(t_dm_virt, eps_filter)
951 78 : CALL dbt_destroy(t_2c_tmp)
952 :
953 : !Deal with the 3-center quantities.
954 : CALL perform_3c_ops(force, t_R_occ, t_R_virt, force_data, fac, cut_memory, n_mem_RI, &
955 : t_KQKT, t_dm_occ, t_dm_virt, t_3c_O, t_3c_M, t_M_occ, t_M_virt, t_3c_0, t_3c_1, &
956 : t_3c_3, t_3c_4, t_3c_5, t_3c_6, t_3c_7, t_3c_8, t_3c_sparse, t_3c_help_1, t_3c_help_2, &
957 : t_3c_ints, t_3c_work, starts_array_mc, ends_array_mc, batch_start_RI, &
958 : batch_end_RI, t_3c_O_compressed, t_3c_O_ind, use_virial, &
959 : atom_of_kind, kind_of, eps_filter, occ_ddint, nze_ddint, dbcsr_nflop, &
960 78 : unit_nr_dbcsr, mp2_env)
961 :
962 78 : CALL timeset(routineN//"_dbcsr", handle2)
963 : !We go back to DBCSR matrices from now on
964 : !Note: R matrices are in fact symmetric, but use a normal type for convenience
965 78 : CALL dbt_create(matrix_s(1)%matrix, t_2c_tmp)
966 78 : CALL dbt_copy(t_R_occ, t_2c_tmp, move_data=.TRUE.)
967 78 : CALL dbt_copy_tensor_to_matrix(t_2c_tmp, R_occ)
968 :
969 78 : CALL dbt_copy(t_R_virt, t_2c_tmp, move_data=.TRUE.)
970 78 : CALL dbt_copy_tensor_to_matrix(t_2c_tmp, R_virt)
971 :
972 : !Iteratively calculate the Y1 and Y2 matrices
973 : CALL dbcsr_multiply('N', 'N', tau, force_data%P_occ(Pspin)%matrix, &
974 78 : matrix_ks(Pspin)%matrix, 0.0_dp, dbcsr_work1)
975 78 : CALL build_Y_matrix(Y_1, dbcsr_work1, force_data%P_occ(Pspin)%matrix, R_virt, eps_filter)
976 78 : CALL matrix_exponential(exp_occ, dbcsr_work1, 1.0_dp, 1.0_dp, eps_filter)
977 :
978 : CALL dbcsr_multiply('N', 'N', -tau, force_data%P_virt(Pspin)%matrix, &
979 78 : matrix_ks(Pspin)%matrix, 0.0_dp, dbcsr_work1)
980 78 : CALL build_Y_matrix(Y_2, dbcsr_work1, force_data%P_virt(Pspin)%matrix, R_occ, eps_filter)
981 78 : CALL matrix_exponential(exp_virt, dbcsr_work1, 1.0_dp, 1.0_dp, eps_filter)
982 :
983 : !The force contribution coming from [-S^-1*(e^-tau*P_virt*F)^T*R_occ*S^-1
984 : ! +tau*S^-1*Y_2^T*F*S^-1] * der_S
985 78 : CALL dbcsr_multiply('N', 'N', 1.0_dp, R_occ, force_data%inv_ovlp, 0.0_dp, dbcsr_work1)
986 78 : CALL dbcsr_multiply('T', 'N', 1.0_dp, exp_virt, dbcsr_work1, 0.0_dp, dbcsr_work3)
987 78 : CALL dbcsr_multiply('N', 'N', 1.0_dp, force_data%inv_ovlp, dbcsr_work3, 0.0_dp, dbcsr_work2)
988 :
989 78 : CALL dbcsr_multiply('N', 'T', tau, force_data%inv_ovlp, Y_2, 0.0_dp, dbcsr_work3)
990 78 : CALL dbcsr_multiply('N', 'N', 1.0_dp, dbcsr_work3, matrix_ks(Pspin)%matrix, 0.0_dp, dbcsr_work1)
991 78 : CALL dbcsr_multiply('N', 'N', 1.0_dp, dbcsr_work1, force_data%inv_ovlp, 0.0_dp, dbcsr_work3)
992 :
993 78 : CALL dbcsr_add(dbcsr_work2, dbcsr_work3, 1.0_dp, -1.0_dp)
994 :
995 78 : CALL dbt_copy_matrix_to_tensor(dbcsr_work2, t_2c_tmp)
996 78 : CALL dbt_copy(t_2c_tmp, t_2c_AO, move_data=.TRUE.)
997 :
998 78 : pref = -1.0_dp*fac
999 : CALL get_2c_der_force(force, t_2c_AO, force_data%t_2c_der_ovlp, atom_of_kind, &
1000 78 : kind_of, force_data%idx_to_at_AO, pref, do_ovlp=.TRUE.)
1001 :
1002 78 : IF (use_virial) CALL dbcsr_add(virial_ovlp, dbcsr_work2, 1.0_dp, pref)
1003 :
1004 : !The final contribution from Tr[(tau*Y_1*P_occ - tau*Y_2*P_virt) * der_F]
1005 : CALL dbcsr_multiply('N', 'N', tau*fac, Y_1, force_data%P_occ(Pspin)%matrix, 1.0_dp, &
1006 78 : force_data%sum_YP_tau(Pspin)%matrix, retain_sparsity=.TRUE.)
1007 : CALL dbcsr_multiply('N', 'N', -tau*fac, Y_2, force_data%P_virt(Pspin)%matrix, 1.0_dp, &
1008 78 : force_data%sum_YP_tau(Pspin)%matrix, retain_sparsity=.TRUE.)
1009 :
1010 : !Build-up the RHS of the response equation.
1011 78 : pref = -omega*mp2_env%scale_S
1012 : CALL dbcsr_multiply('N', 'N', pref, R_virt, exp_occ, 1.0_dp, &
1013 78 : force_data%sum_O_tau(Pspin)%matrix, retain_sparsity=.TRUE.)
1014 : CALL dbcsr_multiply('N', 'N', -pref, R_occ, exp_virt, 1.0_dp, &
1015 78 : force_data%sum_O_tau(Pspin)%matrix, retain_sparsity=.TRUE.)
1016 : CALL dbcsr_multiply('N', 'N', pref*tau, matrix_ks(Pspin)%matrix, Y_1, 1.0_dp, &
1017 78 : force_data%sum_O_tau(Pspin)%matrix, retain_sparsity=.TRUE.)
1018 : CALL dbcsr_multiply('N', 'N', pref*tau, matrix_ks(Pspin)%matrix, Y_2, 1.0_dp, &
1019 78 : force_data%sum_O_tau(Pspin)%matrix, retain_sparsity=.TRUE.)
1020 :
1021 78 : CALL timestop(handle2)
1022 :
1023 : !Print some info
1024 78 : CALL para_env%sync()
1025 78 : t2 = m_walltime()
1026 78 : dbcsr_time = dbcsr_time + t2 - t1
1027 :
1028 78 : IF (unit_nr > 0) THEN
1029 : WRITE (unit_nr, '(/T3,A,1X,I3,A)') &
1030 39 : 'RPA_LOW_SCALING_INFO| Info for time point', jquad, ' (gradients)'
1031 : WRITE (unit_nr, '(T6,A,T56,F25.6)') &
1032 39 : 'Execution time (s):', t2 - t1
1033 : WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
1034 39 : 'Occupancy of 3c AO derivs:', REAL(nze_der_AO, dp), '/', occ_der_AO*100, '%'
1035 : WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
1036 39 : 'Occupancy of 3c RI derivs:', REAL(nze_der_RI, dp), '/', occ_der_RI*100, '%'
1037 : WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
1038 39 : 'Occupancy of the Docc * Dvirt * 3c-int tensor', REAL(nze_ddint, dp), '/', occ_ddint*100, '%'
1039 : WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
1040 39 : 'Occupancy of KQK^T 2c-tensor:', REAL(nze_KQK, dp), '/', occ_KQK*100, '%'
1041 39 : CALL m_flush(unit_nr)
1042 : END IF
1043 :
1044 : !intermediate clean-up
1045 78 : CALL dbcsr_release(Y_1)
1046 78 : CALL dbcsr_release(Y_2)
1047 416 : CALL dbt_destroy(t_2c_tmp)
1048 : END DO !jquad
1049 :
1050 26 : CALL dbt_batched_contract_finalize(t_3c_0)
1051 26 : CALL dbt_batched_contract_finalize(t_3c_1)
1052 26 : CALL dbt_batched_contract_finalize(t_3c_3)
1053 26 : CALL dbt_batched_contract_finalize(t_M_occ)
1054 26 : CALL dbt_batched_contract_finalize(t_M_virt)
1055 :
1056 26 : CALL dbt_batched_contract_finalize(t_3c_ints)
1057 26 : CALL dbt_batched_contract_finalize(t_3c_work)
1058 :
1059 26 : CALL dbt_batched_contract_finalize(t_3c_4)
1060 26 : CALL dbt_batched_contract_finalize(t_3c_5)
1061 26 : CALL dbt_batched_contract_finalize(t_3c_6)
1062 26 : CALL dbt_batched_contract_finalize(t_3c_7)
1063 26 : CALL dbt_batched_contract_finalize(t_3c_8)
1064 26 : CALL dbt_batched_contract_finalize(t_3c_sparse)
1065 :
1066 : !Calculate the 2c and 3c contributions to the virial
1067 26 : IF (use_virial) THEN
1068 2 : CALL dbt_copy(force_data%t_3c_virial_split, force_data%t_3c_virial, move_data=.TRUE.)
1069 : CALL calc_3c_virial(work_virial, force_data%t_3c_virial, 1.0_dp, qs_env, force_data%nl_3c, &
1070 : basis_set_ri_aux, basis_set_ao, basis_set_ao, mp2_env%ri_metric, &
1071 2 : der_eps=mp2_env%ri_rpa_im_time%eps_filter, op_pos=1)
1072 :
1073 : CALL calc_2c_virial(work_virial, force_data%RI_virial_met, 1.0_dp, qs_env, force_data%nl_2c_met, &
1074 2 : basis_set_ri_aux, basis_set_ri_aux, mp2_env%ri_metric)
1075 2 : CALL dbcsr_clear(force_data%RI_virial_met)
1076 :
1077 2 : IF (.NOT. force_data%do_periodic) THEN
1078 : CALL calc_2c_virial(work_virial, force_data%RI_virial_pot, 1.0_dp, qs_env, force_data%nl_2c_pot, &
1079 0 : basis_set_ri_aux, basis_set_ri_aux, mp2_env%potential_parameter)
1080 0 : CALL dbcsr_clear(force_data%RI_virial_pot)
1081 : END IF
1082 :
1083 2 : identity_pot%potential_type = do_potential_id
1084 : CALL calc_2c_virial(work_virial_ovlp, virial_ovlp, 1.0_dp, qs_env, force_data%nl_2c_ovlp, &
1085 2 : basis_set_ao, basis_set_ao, identity_pot)
1086 2 : CALL dbcsr_release(virial_ovlp)
1087 :
1088 8 : DO k_xyz = 1, 3
1089 26 : DO j_xyz = 1, 3
1090 78 : DO i_xyz = 1, 3
1091 : virial%pv_mp2(i_xyz, j_xyz) = virial%pv_mp2(i_xyz, j_xyz) &
1092 54 : - work_virial(i_xyz, k_xyz)*cell%hmat(j_xyz, k_xyz)
1093 : virial%pv_overlap(i_xyz, j_xyz) = virial%pv_overlap(i_xyz, j_xyz) &
1094 54 : - work_virial_ovlp(i_xyz, k_xyz)*cell%hmat(j_xyz, k_xyz)
1095 : virial%pv_virial(i_xyz, j_xyz) = virial%pv_virial(i_xyz, j_xyz) &
1096 : - work_virial(i_xyz, k_xyz)*cell%hmat(j_xyz, k_xyz) &
1097 72 : - work_virial_ovlp(i_xyz, k_xyz)*cell%hmat(j_xyz, k_xyz)
1098 : END DO
1099 : END DO
1100 : END DO
1101 : END IF
1102 :
1103 : !Calculate the periodic contributions of (P|Q) to the force and the virial
1104 26 : work_virial = 0.0_dp
1105 26 : IF (force_data%do_periodic) THEN
1106 10 : IF (mp2_env%eri_method == do_eri_gpw) THEN
1107 6 : CALL get_2c_gpw_forces(force_data%G_PQ, force, work_virial, use_virial, mp2_env, qs_env)
1108 4 : ELSE IF (mp2_env%eri_method == do_eri_mme) THEN
1109 4 : CALL get_2c_mme_forces(force_data%G_PQ, force, mp2_env, qs_env)
1110 4 : IF (use_virial) CPABORT("Stress tensor not available with MME intrgrals")
1111 : ELSE
1112 0 : CPABORT("Periodic case not possible with OS integrals")
1113 : END IF
1114 10 : CALL dbcsr_clear(force_data%G_PQ)
1115 : END IF
1116 :
1117 26 : IF (use_virial) THEN
1118 26 : virial%pv_mp2 = virial%pv_mp2 + work_virial
1119 26 : virial%pv_virial = virial%pv_virial + work_virial
1120 2 : virial%pv_calculate = .FALSE.
1121 :
1122 6 : DO ibasis = 1, SIZE(basis_set_ao)
1123 4 : orb_basis => basis_set_ao(ibasis)%gto_basis_set
1124 4 : CALL init_interaction_radii_orb_basis(orb_basis, eps_pgf_orb_old)
1125 4 : ri_basis => basis_set_ri_aux(ibasis)%gto_basis_set
1126 6 : CALL init_interaction_radii_orb_basis(ri_basis, eps_pgf_orb_old)
1127 : END DO
1128 : END IF
1129 :
1130 : !clean-up
1131 26 : IF (ASSOCIATED(dummy_ptr)) DEALLOCATE (dummy_ptr)
1132 60 : DO ispin = 1, nspins
1133 60 : CALL dbt_destroy(t_P(ispin))
1134 : END DO
1135 26 : CALL dbt_destroy(t_3c_0)
1136 26 : CALL dbt_destroy(t_3c_1)
1137 26 : CALL dbt_destroy(t_3c_3)
1138 26 : CALL dbt_destroy(t_3c_4)
1139 26 : CALL dbt_destroy(t_3c_5)
1140 26 : CALL dbt_destroy(t_3c_6)
1141 26 : CALL dbt_destroy(t_3c_7)
1142 26 : CALL dbt_destroy(t_3c_8)
1143 26 : CALL dbt_destroy(t_3c_sparse)
1144 26 : CALL dbt_destroy(t_3c_help_1)
1145 26 : CALL dbt_destroy(t_3c_help_2)
1146 26 : CALL dbt_destroy(t_3c_ints)
1147 26 : CALL dbt_destroy(t_3c_work)
1148 26 : CALL dbt_destroy(t_R_occ)
1149 26 : CALL dbt_destroy(t_R_virt)
1150 26 : CALL dbt_destroy(t_dm_occ)
1151 26 : CALL dbt_destroy(t_dm_virt)
1152 26 : CALL dbt_destroy(t_Q)
1153 26 : CALL dbt_destroy(t_KQKT)
1154 26 : CALL dbt_destroy(t_M_occ)
1155 26 : CALL dbt_destroy(t_M_virt)
1156 26 : CALL dbcsr_release(R_occ)
1157 26 : CALL dbcsr_release(R_virt)
1158 26 : CALL dbcsr_release(dbcsr_work1)
1159 26 : CALL dbcsr_release(dbcsr_work2)
1160 26 : CALL dbcsr_release(dbcsr_work3)
1161 26 : CALL dbcsr_release(exp_occ)
1162 26 : CALL dbcsr_release(exp_virt)
1163 :
1164 26 : CALL dbt_destroy(t_2c_RI)
1165 26 : CALL dbt_destroy(t_2c_RI_2)
1166 26 : CALL dbt_destroy(t_2c_AO)
1167 26 : CALL dbcsr_deallocate_matrix_set(mat_dm_occ)
1168 26 : CALL dbcsr_deallocate_matrix_set(mat_dm_virt)
1169 :
1170 26 : CALL timestop(handle)
1171 :
1172 138 : END SUBROUTINE calc_laplace_loop_forces
1173 :
1174 : ! **************************************************************************************************
1175 : !> \brief Updates the cubic-scaling RPA contribution to the forces at each quadrature point. This
1176 : !> routine is adapted from the corresponding Laplace SOS-MP2 loop force one.
1177 : !> \param force_data ...
1178 : !> \param mat_P_omega ...
1179 : !> \param t_3c_M ...
1180 : !> \param t_3c_O ...
1181 : !> \param t_3c_O_compressed ...
1182 : !> \param t_3c_O_ind ...
1183 : !> \param fm_scaled_dm_occ_tau ...
1184 : !> \param fm_scaled_dm_virt_tau ...
1185 : !> \param fm_mo_coeff_occ ...
1186 : !> \param fm_mo_coeff_virt ...
1187 : !> \param fm_mo_coeff_occ_scaled ...
1188 : !> \param fm_mo_coeff_virt_scaled ...
1189 : !> \param starts_array_mc ...
1190 : !> \param ends_array_mc ...
1191 : !> \param starts_array_mc_block ...
1192 : !> \param ends_array_mc_block ...
1193 : !> \param num_integ_points ...
1194 : !> \param nmo ...
1195 : !> \param Eigenval ...
1196 : !> \param e_fermi ...
1197 : !> \param weights_cos_tf_t_to_w ...
1198 : !> \param weights_cos_tf_w_to_t ...
1199 : !> \param tj ...
1200 : !> \param wj ...
1201 : !> \param tau_tj ...
1202 : !> \param cut_memory ...
1203 : !> \param ispin ...
1204 : !> \param open_shell ...
1205 : !> \param unit_nr ...
1206 : !> \param dbcsr_time ...
1207 : !> \param dbcsr_nflop ...
1208 : !> \param mp2_env ...
1209 : !> \param qs_env ...
1210 : ! **************************************************************************************************
1211 180 : SUBROUTINE calc_rpa_loop_forces(force_data, mat_P_omega, t_3c_M, t_3c_O, t_3c_O_compressed, &
1212 36 : t_3c_O_ind, fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, &
1213 36 : fm_mo_coeff_occ, fm_mo_coeff_virt, fm_mo_coeff_occ_scaled, &
1214 36 : fm_mo_coeff_virt_scaled, starts_array_mc, ends_array_mc, &
1215 36 : starts_array_mc_block, ends_array_mc_block, num_integ_points, &
1216 36 : nmo, Eigenval, e_fermi, weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, &
1217 36 : tj, wj, tau_tj, cut_memory, ispin, open_shell, unit_nr, dbcsr_time, &
1218 : dbcsr_nflop, mp2_env, qs_env)
1219 :
1220 : TYPE(im_time_force_type), INTENT(INOUT) :: force_data
1221 : TYPE(dbcsr_p_type), DIMENSION(:, :), INTENT(INOUT) :: mat_P_omega
1222 : TYPE(dbt_type), INTENT(INOUT) :: t_3c_M, t_3c_O
1223 : TYPE(hfx_compression_type), DIMENSION(:) :: t_3c_O_compressed
1224 : TYPE(block_ind_type), DIMENSION(:), INTENT(INOUT) :: t_3c_O_ind
1225 : TYPE(cp_fm_type), INTENT(IN) :: fm_scaled_dm_occ_tau, &
1226 : fm_scaled_dm_virt_tau
1227 : TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: fm_mo_coeff_occ, fm_mo_coeff_virt
1228 : TYPE(cp_fm_type), INTENT(IN) :: fm_mo_coeff_occ_scaled, &
1229 : fm_mo_coeff_virt_scaled
1230 : INTEGER, DIMENSION(:), INTENT(IN) :: starts_array_mc, ends_array_mc, &
1231 : starts_array_mc_block, &
1232 : ends_array_mc_block
1233 : INTEGER, INTENT(IN) :: num_integ_points, nmo
1234 : REAL(KIND=dp), DIMENSION(:, :), INTENT(IN) :: Eigenval
1235 : REAL(KIND=dp), INTENT(IN) :: e_fermi
1236 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :), &
1237 : INTENT(IN) :: weights_cos_tf_t_to_w, &
1238 : weights_cos_tf_w_to_t
1239 : REAL(KIND=dp), ALLOCATABLE, DIMENSION(:), &
1240 : INTENT(IN) :: tj, wj
1241 : REAL(KIND=dp), DIMENSION(0:num_integ_points), &
1242 : INTENT(IN) :: tau_tj
1243 : INTEGER, INTENT(IN) :: cut_memory, ispin
1244 : LOGICAL, INTENT(IN) :: open_shell
1245 : INTEGER, INTENT(IN) :: unit_nr
1246 : REAL(dp), INTENT(INOUT) :: dbcsr_time
1247 : INTEGER(int_8), INTENT(INOUT) :: dbcsr_nflop
1248 : TYPE(mp2_type) :: mp2_env
1249 : TYPE(qs_environment_type), POINTER :: qs_env
1250 :
1251 : CHARACTER(LEN=*), PARAMETER :: routineN = 'calc_rpa_loop_forces'
1252 :
1253 : INTEGER :: dummy_int, handle, handle2, i_mem, i_xyz, ibasis, iquad, j_xyz, jquad, k_xyz, &
1254 : n_mem_RI, n_rep, natom, nkind, nspins, unit_nr_dbcsr
1255 : INTEGER(int_8) :: flop, nze, nze_ddint, nze_der_AO, &
1256 : nze_der_RI, nze_KBK
1257 36 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, batch_blk_end, &
1258 36 : batch_blk_start, batch_end_RI, &
1259 36 : batch_start_RI, kind_of, mc_ranges, &
1260 36 : mc_ranges_RI
1261 36 : INTEGER, DIMENSION(:, :), POINTER :: dummy_ptr
1262 : LOGICAL :: memory_info, use_virial
1263 : REAL(dp) :: eps_filter, eps_pgf_orb, eps_pgf_orb_old, fac, occ, occ_ddint, occ_der_AO, &
1264 : occ_der_RI, occ_KBK, omega, pref, spin_fac, t1, t2, tau, weight
1265 : REAL(dp), DIMENSION(3, 3) :: work_virial, work_virial_ovlp
1266 36 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1267 : TYPE(cell_type), POINTER :: cell
1268 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
1269 36 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mat_P_tau, matrix_ks, matrix_s
1270 36 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: mat_dm_occ, mat_dm_virt
1271 : TYPE(dbcsr_type) :: dbcsr_work1, dbcsr_work2, dbcsr_work3, &
1272 : dbcsr_work_symm, exp_occ, exp_virt, &
1273 : R_occ, R_virt, virial_ovlp, Y_1, Y_2
1274 1764 : TYPE(dbt_type) :: t_2c_AO, t_2c_RI, t_2c_RI_2, t_2c_tmp, t_3c_0, t_3c_1, t_3c_3, t_3c_4, &
1275 1764 : t_3c_5, t_3c_6, t_3c_7, t_3c_8, t_3c_help_1, t_3c_help_2, t_3c_ints, t_3c_sparse, &
1276 2016 : t_3c_work, t_dm_occ, t_dm_virt, t_KBKT, t_M_occ, t_M_virt, t_P, t_R_occ, t_R_virt
1277 36 : TYPE(dbt_type), ALLOCATABLE, DIMENSION(:) :: t_B
1278 : TYPE(dft_control_type), POINTER :: dft_control
1279 : TYPE(gto_basis_set_p_type), ALLOCATABLE, &
1280 36 : DIMENSION(:), TARGET :: basis_set_ao, basis_set_ri_aux
1281 : TYPE(gto_basis_set_type), POINTER :: orb_basis, ri_basis
1282 : TYPE(libint_potential_type) :: identity_pot
1283 : TYPE(mp_para_env_type), POINTER :: para_env
1284 36 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1285 36 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
1286 36 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1287 : TYPE(section_vals_type), POINTER :: qs_section
1288 : TYPE(virial_type), POINTER :: virial
1289 :
1290 36 : NULLIFY (matrix_s, dummy_ptr, atomic_kind_set, force, matrix_s, matrix_ks, mat_dm_occ, mat_dm_virt)
1291 36 : NULLIFY (dft_control, virial, particle_set, cell, blacs_env, para_env, orb_basis, ri_basis)
1292 36 : NULLIFY (qs_kind_set)
1293 :
1294 36 : CALL timeset(routineN, handle)
1295 :
1296 : CALL get_qs_env(qs_env, matrix_s=matrix_s, natom=natom, atomic_kind_set=atomic_kind_set, &
1297 : force=force, matrix_ks=matrix_ks, dft_control=dft_control, virial=virial, &
1298 : particle_set=particle_set, cell=cell, blacs_env=blacs_env, para_env=para_env, &
1299 36 : qs_kind_set=qs_kind_set, nkind=nkind)
1300 36 : eps_filter = mp2_env%ri_rpa_im_time%eps_filter
1301 36 : nspins = dft_control%nspins
1302 :
1303 36 : memory_info = mp2_env%ri_rpa_im_time%memory_info
1304 36 : IF (memory_info) THEN
1305 0 : unit_nr_dbcsr = unit_nr
1306 : ELSE
1307 36 : unit_nr_dbcsr = 0
1308 : END IF
1309 :
1310 36 : use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
1311 :
1312 36 : IF (use_virial) virial%pv_calculate = .TRUE.
1313 :
1314 36 : IF (use_virial) THEN
1315 2 : qs_section => section_vals_get_subs_vals(qs_env%input, "DFT%QS")
1316 2 : CALL section_vals_val_get(qs_section, "EPS_PGF_ORB", n_rep_val=n_rep)
1317 2 : IF (n_rep /= 0) THEN
1318 0 : CALL section_vals_val_get(qs_section, "EPS_PGF_ORB", r_val=eps_pgf_orb)
1319 : ELSE
1320 2 : CALL section_vals_val_get(qs_section, "EPS_DEFAULT", r_val=eps_pgf_orb)
1321 2 : eps_pgf_orb = SQRT(eps_pgf_orb)
1322 : END IF
1323 2 : eps_pgf_orb_old = dft_control%qs_control%eps_pgf_orb
1324 :
1325 16 : ALLOCATE (basis_set_ri_aux(nkind), basis_set_ao(nkind))
1326 2 : CALL basis_set_list_setup(basis_set_ri_aux, "RI_AUX", qs_kind_set)
1327 2 : CALL basis_set_list_setup(basis_set_ao, "ORB", qs_kind_set)
1328 :
1329 8 : DO ibasis = 1, SIZE(basis_set_ao)
1330 4 : orb_basis => basis_set_ao(ibasis)%gto_basis_set
1331 4 : CALL init_interaction_radii_orb_basis(orb_basis, eps_pgf_orb)
1332 4 : ri_basis => basis_set_ri_aux(ibasis)%gto_basis_set
1333 6 : CALL init_interaction_radii_orb_basis(ri_basis, eps_pgf_orb)
1334 : END DO
1335 : END IF
1336 :
1337 : !We follow the general logic of the compute_mat_P_omega routine
1338 36 : CALL dbt_create(force_data%t_2c_K, t_2c_RI)
1339 36 : CALL dbt_create(force_data%t_2c_K, t_2c_RI_2)
1340 36 : CALL dbt_create(force_data%t_2c_der_ovlp(1), t_2c_AO)
1341 :
1342 36 : CALL get_atomic_kind_set(atomic_kind_set, kind_of=kind_of, atom_of_kind=atom_of_kind)
1343 :
1344 : ! Always do the batching of the MO on mu and sigma, such that it is consistent between
1345 : ! the occupied and the virtual quantities
1346 108 : ALLOCATE (mc_ranges(cut_memory + 1))
1347 108 : mc_ranges(:cut_memory) = starts_array_mc_block(:)
1348 36 : mc_ranges(cut_memory + 1) = ends_array_mc_block(cut_memory) + 1
1349 :
1350 : ! Also need some batching on the RI, because it loses sparsity at some point
1351 36 : n_mem_RI = cut_memory
1352 : CALL create_tensor_batches(force_data%bsizes_RI_split, n_mem_RI, batch_start_RI, batch_end_RI, &
1353 36 : batch_blk_start, batch_blk_end)
1354 108 : ALLOCATE (mc_ranges_RI(n_mem_RI + 1))
1355 108 : mc_ranges_RI(1:n_mem_RI) = batch_blk_start(1:n_mem_RI)
1356 36 : mc_ranges_RI(n_mem_RI + 1) = batch_blk_end(n_mem_RI) + 1
1357 36 : DEALLOCATE (batch_blk_start, batch_blk_end)
1358 :
1359 : !Pre-allocate all required tensors and matrices
1360 36 : CALL dbt_create(t_2c_RI, t_P)
1361 36 : CALL dbt_create(t_2c_RI, t_KBKT)
1362 36 : CALL dbt_create(t_2c_AO, t_dm_occ)
1363 36 : CALL dbt_create(t_2c_AO, t_dm_virt)
1364 :
1365 : !note: t_3c_O and t_3c_M have different mappings (map_1d, map_2d)
1366 36 : CALL dbt_create(t_3c_O, t_M_occ)
1367 36 : CALL dbt_create(t_3c_O, t_M_virt)
1368 36 : CALL dbt_create(t_3c_O, t_3c_0)
1369 :
1370 36 : CALL dbt_create(t_3c_O, t_3c_1)
1371 36 : CALL dbt_create(t_3c_O, t_3c_3)
1372 36 : CALL dbt_create(t_3c_O, t_3c_4)
1373 36 : CALL dbt_create(t_3c_O, t_3c_5)
1374 36 : CALL dbt_create(t_3c_M, t_3c_6)
1375 36 : CALL dbt_create(t_3c_M, t_3c_7)
1376 36 : CALL dbt_create(t_3c_M, t_3c_8)
1377 36 : CALL dbt_create(t_3c_M, t_3c_sparse)
1378 36 : CALL dbt_create(t_3c_O, t_3c_help_1)
1379 36 : CALL dbt_create(t_3c_O, t_3c_help_2)
1380 36 : CALL dbt_create(t_2c_AO, t_R_occ)
1381 36 : CALL dbt_create(t_2c_AO, t_R_virt)
1382 36 : CALL dbt_create(t_3c_M, t_3c_ints)
1383 36 : CALL dbt_create(t_3c_M, t_3c_work)
1384 :
1385 : !Before entring the loop, need to compute the 2c tensors B = (1 + Q(w))^-1 - 1, for each
1386 : !frequency grid point, before doing the transformation to the time grid
1387 416 : ALLOCATE (t_B(num_integ_points))
1388 128 : DO jquad = 1, num_integ_points
1389 128 : CALL dbt_create(t_2c_RI, t_B(jquad))
1390 : END DO
1391 :
1392 200 : ALLOCATE (mat_P_tau(num_integ_points))
1393 128 : DO jquad = 1, num_integ_points
1394 92 : ALLOCATE (mat_P_tau(jquad)%matrix)
1395 128 : CALL dbcsr_create(mat_P_tau(jquad)%matrix, template=mat_P_omega(jquad, ispin)%matrix)
1396 : END DO
1397 :
1398 36 : CALL dbcsr_create(dbcsr_work_symm, template=force_data%G_PQ, matrix_type=dbcsr_type_symmetric)
1399 36 : CALL dbt_create(dbcsr_work_symm, t_2c_tmp)
1400 :
1401 : !loop over freqeuncies
1402 128 : DO iquad = 1, num_integ_points
1403 92 : omega = tj(iquad)
1404 :
1405 : !calculate (1 + Q(w))^-1 - 1 for the given freq.
1406 : !Always take spin alpha (get 2*alpha in closed shell, and alpha+beta in open-shell)
1407 92 : CALL dbcsr_copy(dbcsr_work_symm, mat_P_omega(iquad, 1)%matrix)
1408 92 : CALL dbt_copy_matrix_to_tensor(dbcsr_work_symm, t_2c_tmp)
1409 92 : CALL dbt_copy(t_2c_tmp, t_2c_RI, move_data=.TRUE.)
1410 :
1411 : CALL dbt_contract(1.0_dp, t_2c_RI, force_data%t_2c_K, 0.0_dp, t_2c_RI_2, &
1412 : contract_1=[2], notcontract_1=[1], &
1413 : contract_2=[1], notcontract_2=[2], &
1414 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
1415 92 : flop=flop, unit_nr=unit_nr_dbcsr)
1416 92 : dbcsr_nflop = dbcsr_nflop + flop
1417 : CALL dbt_contract(1.0_dp, force_data%t_2c_K, t_2c_RI_2, 0.0_dp, t_2c_RI, &
1418 : contract_1=[1], notcontract_1=[2], &
1419 : contract_2=[1], notcontract_2=[2], &
1420 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
1421 92 : flop=flop, unit_nr=unit_nr_dbcsr)
1422 92 : CALL dbt_copy(t_2c_RI, t_2c_tmp, move_data=.TRUE.)
1423 92 : CALL dbt_copy_tensor_to_matrix(t_2c_tmp, dbcsr_work_symm)
1424 92 : CALL dbcsr_add_on_diag(dbcsr_work_symm, 1.0_dp)
1425 :
1426 92 : CALL cp_dbcsr_cholesky_decompose(dbcsr_work_symm, para_env=para_env, blacs_env=blacs_env)
1427 92 : CALL cp_dbcsr_cholesky_invert(dbcsr_work_symm, para_env=para_env, blacs_env=blacs_env, uplo_to_full=.TRUE.)
1428 :
1429 92 : CALL dbcsr_add_on_diag(dbcsr_work_symm, -1.0_dp)
1430 :
1431 372 : DO jquad = 1, num_integ_points
1432 244 : tau = tau_tj(jquad)
1433 :
1434 : !the P matrix to time.
1435 244 : weight = weights_cos_tf_w_to_t(jquad, iquad)*COS(tau*omega)
1436 244 : IF (open_shell) THEN
1437 64 : IF (ispin == 1) THEN
1438 : !mat_P_omega contains the sum of alpha and beta spin => we only want alpha
1439 32 : CALL dbcsr_add(mat_P_tau(jquad)%matrix, mat_P_omega(iquad, 1)%matrix, 1.0_dp, weight)
1440 32 : CALL dbcsr_add(mat_P_tau(jquad)%matrix, mat_P_omega(iquad, 2)%matrix, 1.0_dp, -weight)
1441 : ELSE
1442 32 : CALL dbcsr_add(mat_P_tau(jquad)%matrix, mat_P_omega(iquad, 2)%matrix, 1.0_dp, weight)
1443 : END IF
1444 : ELSE
1445 : !factor 0.5 because originam matrix Q is scaled by 2 in RPA (spin)
1446 180 : weight = 0.5_dp*weight
1447 180 : CALL dbcsr_add(mat_P_tau(jquad)%matrix, mat_P_omega(iquad, 1)%matrix, 1.0_dp, weight)
1448 : END IF
1449 :
1450 : !convert B matrix to time
1451 244 : weight = weights_cos_tf_t_to_w(iquad, jquad)*COS(tau*omega)*wj(iquad)
1452 244 : CALL dbt_copy_matrix_to_tensor(dbcsr_work_symm, t_2c_tmp)
1453 244 : CALL dbt_scale(t_2c_tmp, weight)
1454 336 : CALL dbt_copy(t_2c_tmp, t_B(jquad), summation=.TRUE., move_data=.TRUE.)
1455 : END DO
1456 : END DO
1457 36 : CALL dbt_destroy(t_2c_tmp)
1458 36 : CALL dbcsr_release(dbcsr_work_symm)
1459 36 : CALL dbt_clear(t_2c_RI)
1460 36 : CALL dbt_clear(t_2c_RI_2)
1461 :
1462 : !Pre-define the sparsity of t_3c_4 as a function of the derivatives
1463 36 : occ_der_AO = 0; nze_der_AO = 0
1464 36 : occ_der_RI = 0; nze_der_RI = 0
1465 144 : DO i_xyz = 1, 3
1466 360 : DO i_mem = 1, cut_memory
1467 : CALL decompress_tensor(force_data%t_3c_der_RI(i_xyz), force_data%t_3c_der_RI_ind(i_mem, i_xyz)%ind, &
1468 216 : force_data%t_3c_der_RI_comp(i_mem, i_xyz), mp2_env%ri_rpa_im_time%eps_compress)
1469 216 : CALL get_tensor_occupancy(force_data%t_3c_der_RI(i_xyz), nze, occ)
1470 216 : occ_der_RI = occ_der_RI + occ
1471 216 : nze_der_RI = nze_der_RI + nze
1472 216 : CALL dbt_copy(force_data%t_3c_der_RI(i_xyz), t_3c_sparse, summation=.TRUE., move_data=.TRUE.)
1473 :
1474 : CALL decompress_tensor(force_data%t_3c_der_AO(i_xyz), force_data%t_3c_der_AO_ind(i_mem, i_xyz)%ind, &
1475 216 : force_data%t_3c_der_AO_comp(i_mem, i_xyz), mp2_env%ri_rpa_im_time%eps_compress)
1476 216 : CALL get_tensor_occupancy(force_data%t_3c_der_AO(i_xyz), nze, occ)
1477 216 : occ_der_AO = occ_der_AO + occ
1478 216 : nze_der_AO = nze_der_AO + nze
1479 216 : CALL dbt_copy(force_data%t_3c_der_AO(i_xyz), t_3c_sparse, order=[1, 3, 2], summation=.TRUE.)
1480 756 : CALL dbt_copy(force_data%t_3c_der_AO(i_xyz), t_3c_sparse, summation=.TRUE., move_data=.TRUE.)
1481 : END DO
1482 : END DO
1483 36 : occ_der_RI = occ_der_RI/3.0_dp
1484 36 : occ_der_AO = occ_der_AO/3.0_dp
1485 36 : nze_der_RI = nze_der_RI/3
1486 36 : nze_der_AO = nze_der_AO/3
1487 :
1488 36 : CALL dbcsr_create(R_occ, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1489 36 : CALL dbcsr_create(R_virt, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1490 36 : CALL dbcsr_create(dbcsr_work_symm, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_symmetric)
1491 36 : CALL dbcsr_create(dbcsr_work1, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1492 36 : CALL dbcsr_create(dbcsr_work2, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1493 36 : CALL dbcsr_create(dbcsr_work3, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1494 36 : CALL dbcsr_create(exp_occ, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1495 36 : CALL dbcsr_create(exp_virt, template=matrix_s(1)%matrix, matrix_type=dbcsr_type_no_symmetry)
1496 36 : IF (use_virial) CALL dbcsr_create(virial_ovlp, template=dbcsr_work1)
1497 :
1498 36 : CALL dbt_batched_contract_init(t_3c_0, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
1499 36 : CALL dbt_batched_contract_init(t_3c_1, batch_range_2=mc_ranges, batch_range_3=mc_ranges)
1500 36 : CALL dbt_batched_contract_init(t_3c_3, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
1501 36 : CALL dbt_batched_contract_init(t_M_occ, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
1502 36 : CALL dbt_batched_contract_init(t_M_virt, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
1503 :
1504 36 : CALL dbt_batched_contract_init(t_3c_ints, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
1505 36 : CALL dbt_batched_contract_init(t_3c_work, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges)
1506 :
1507 : CALL dbt_batched_contract_init(t_3c_4, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
1508 36 : batch_range_3=mc_ranges)
1509 : CALL dbt_batched_contract_init(t_3c_5, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
1510 36 : batch_range_3=mc_ranges)
1511 : CALL dbt_batched_contract_init(t_3c_6, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
1512 36 : batch_range_3=mc_ranges)
1513 : CALL dbt_batched_contract_init(t_3c_7, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
1514 36 : batch_range_3=mc_ranges)
1515 : CALL dbt_batched_contract_init(t_3c_8, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
1516 36 : batch_range_3=mc_ranges)
1517 : CALL dbt_batched_contract_init(t_3c_sparse, batch_range_1=mc_ranges_RI, batch_range_2=mc_ranges, &
1518 36 : batch_range_3=mc_ranges)
1519 :
1520 36 : fac = 1.0_dp/fourpi*mp2_env%ri_rpa%scale_rpa
1521 36 : IF (open_shell) fac = 0.5_dp*fac
1522 :
1523 36 : work_virial = 0.0_dp
1524 36 : work_virial_ovlp = 0.0_dp
1525 128 : DO jquad = 1, num_integ_points
1526 92 : tau = tau_tj(jquad)
1527 92 : occ_ddint = 0; nze_ddint = 0
1528 :
1529 92 : CALL para_env%sync()
1530 92 : t1 = m_walltime()
1531 :
1532 : !Deal with the force contributions where there is no explicit 3-center quantities, i.e. the
1533 : !forces due to the metric and potential derivatives
1534 92 : CALL dbt_create(mat_P_tau(jquad)%matrix, t_2c_tmp)
1535 92 : CALL dbt_copy_matrix_to_tensor(mat_P_tau(jquad)%matrix, t_2c_tmp)
1536 92 : CALL dbt_copy(t_2c_tmp, t_P, move_data=.TRUE.)
1537 92 : CALL dbt_filter(t_P, eps_filter)
1538 92 : CALL dbt_destroy(t_2c_tmp)
1539 :
1540 : CALL perform_2c_ops(force, t_KBKT, force_data, fac, t_B(jquad), t_P, t_2c_RI, t_2c_RI_2, &
1541 92 : use_virial, atom_of_kind, kind_of, eps_filter, dbcsr_nflop, unit_nr_dbcsr)
1542 92 : CALL get_tensor_occupancy(t_KBKT, nze_KBK, occ_KBK)
1543 :
1544 : !Calculate the pseudo-density matrix in tensor form. There are a few useless arguments for SOS-MP2
1545 : CALL compute_mat_dm_global(fm_scaled_dm_occ_tau, fm_scaled_dm_virt_tau, tau_tj, num_integ_points, &
1546 : nmo, fm_mo_coeff_occ(ispin), fm_mo_coeff_virt(ispin), &
1547 : fm_mo_coeff_occ_scaled, fm_mo_coeff_virt_scaled, mat_dm_occ, mat_dm_virt, &
1548 : matrix_s, ispin, Eigenval(:, ispin), e_fermi, eps_filter, &
1549 : mp2_env%ri_rpa_im_time%memory_info, unit_nr, &
1550 92 : jquad, .FALSE., .FALSE., qs_env, dummy_int, dummy_ptr, para_env)
1551 :
1552 92 : CALL dbt_create(mat_dm_occ(jquad, 1)%matrix, t_2c_tmp)
1553 92 : CALL dbt_copy_matrix_to_tensor(mat_dm_occ(jquad, 1)%matrix, t_2c_tmp)
1554 92 : CALL dbt_copy(t_2c_tmp, t_dm_occ, move_data=.TRUE.)
1555 92 : CALL dbt_filter(t_dm_occ, eps_filter)
1556 92 : CALL dbt_destroy(t_2c_tmp)
1557 :
1558 92 : CALL dbt_create(mat_dm_virt(jquad, 1)%matrix, t_2c_tmp)
1559 92 : CALL dbt_copy_matrix_to_tensor(mat_dm_virt(jquad, 1)%matrix, t_2c_tmp)
1560 92 : CALL dbt_copy(t_2c_tmp, t_dm_virt, move_data=.TRUE.)
1561 92 : CALL dbt_filter(t_dm_virt, eps_filter)
1562 92 : CALL dbt_destroy(t_2c_tmp)
1563 :
1564 : !Deal with the 3-center quantities.
1565 : CALL perform_3c_ops(force, t_R_occ, t_R_virt, force_data, fac, cut_memory, n_mem_RI, &
1566 : t_KBKT, t_dm_occ, t_dm_virt, t_3c_O, t_3c_M, t_M_occ, t_M_virt, t_3c_0, t_3c_1, &
1567 : t_3c_3, t_3c_4, t_3c_5, t_3c_6, t_3c_7, t_3c_8, t_3c_sparse, t_3c_help_1, t_3c_help_2, &
1568 : t_3c_ints, t_3c_work, starts_array_mc, ends_array_mc, batch_start_RI, &
1569 : batch_end_RI, t_3c_O_compressed, t_3c_O_ind, use_virial, &
1570 : atom_of_kind, kind_of, eps_filter, occ_ddint, nze_ddint, dbcsr_nflop, &
1571 92 : unit_nr_dbcsr, mp2_env)
1572 :
1573 92 : CALL timeset(routineN//"_dbcsr", handle2)
1574 : !We go back to DBCSR matrices from now on
1575 : !Note: R matrices are in fact symmetric, but use a normal type for convenience
1576 92 : CALL dbt_create(matrix_s(1)%matrix, t_2c_tmp)
1577 92 : CALL dbt_copy(t_R_occ, t_2c_tmp, move_data=.TRUE.)
1578 92 : CALL dbt_copy_tensor_to_matrix(t_2c_tmp, R_occ)
1579 :
1580 92 : CALL dbt_copy(t_R_virt, t_2c_tmp, move_data=.TRUE.)
1581 92 : CALL dbt_copy_tensor_to_matrix(t_2c_tmp, R_virt)
1582 :
1583 : !Iteratively calculate the Y1 and Y2 matrices
1584 92 : CALL dbcsr_copy(dbcsr_work_symm, matrix_ks(ispin)%matrix)
1585 92 : CALL dbcsr_add(dbcsr_work_symm, matrix_s(1)%matrix, 1.0_dp, -e_fermi)
1586 : CALL dbcsr_multiply('N', 'N', tau, force_data%P_occ(ispin)%matrix, &
1587 92 : dbcsr_work_symm, 0.0_dp, dbcsr_work1)
1588 92 : CALL build_Y_matrix(Y_1, dbcsr_work1, force_data%P_occ(ispin)%matrix, R_virt, eps_filter)
1589 92 : CALL matrix_exponential(exp_occ, dbcsr_work1, 1.0_dp, 1.0_dp, eps_filter)
1590 :
1591 : CALL dbcsr_multiply('N', 'N', -tau, force_data%P_virt(ispin)%matrix, &
1592 92 : dbcsr_work_symm, 0.0_dp, dbcsr_work1)
1593 92 : CALL build_Y_matrix(Y_2, dbcsr_work1, force_data%P_virt(ispin)%matrix, R_occ, eps_filter)
1594 92 : CALL matrix_exponential(exp_virt, dbcsr_work1, 1.0_dp, 1.0_dp, eps_filter)
1595 :
1596 : !The force contribution coming from [-S^-1*(e^-tau*P_virt*F)^T*R_occ*S^-1
1597 : ! +tau*S^-1*Y_2^T*F*S^-1] * der_S
1598 : !as well as -tau*e_fermi*Y_1*P^occ + tau*e_fermi*Y_2*P^virt
1599 92 : CALL dbcsr_multiply('N', 'N', 1.0_dp, R_occ, force_data%inv_ovlp, 0.0_dp, dbcsr_work1)
1600 92 : CALL dbcsr_multiply('T', 'N', 1.0_dp, exp_virt, dbcsr_work1, 0.0_dp, dbcsr_work3)
1601 92 : CALL dbcsr_multiply('N', 'N', 1.0_dp, force_data%inv_ovlp, dbcsr_work3, 0.0_dp, dbcsr_work2)
1602 :
1603 92 : CALL dbcsr_multiply('N', 'T', tau, force_data%inv_ovlp, Y_2, 0.0_dp, dbcsr_work3)
1604 92 : CALL dbcsr_multiply('N', 'N', 1.0_dp, dbcsr_work3, dbcsr_work_symm, 0.0_dp, dbcsr_work1)
1605 92 : CALL dbcsr_multiply('N', 'N', -1.0_dp, dbcsr_work1, force_data%inv_ovlp, 1.0_dp, dbcsr_work2)
1606 :
1607 92 : CALL dbcsr_multiply('N', 'T', tau*e_fermi, force_data%P_occ(ispin)%matrix, Y_1, 1.0_dp, dbcsr_work2)
1608 92 : CALL dbcsr_multiply('N', 'T', -tau*e_fermi, force_data%P_virt(ispin)%matrix, Y_2, 1.0_dp, dbcsr_work2)
1609 :
1610 92 : CALL dbt_copy_matrix_to_tensor(dbcsr_work2, t_2c_tmp)
1611 92 : CALL dbt_copy(t_2c_tmp, t_2c_AO, move_data=.TRUE.)
1612 :
1613 92 : pref = -1.0_dp*fac
1614 : CALL get_2c_der_force(force, t_2c_AO, force_data%t_2c_der_ovlp, atom_of_kind, &
1615 92 : kind_of, force_data%idx_to_at_AO, pref, do_ovlp=.TRUE.)
1616 :
1617 92 : IF (use_virial) CALL dbcsr_add(virial_ovlp, dbcsr_work2, 1.0_dp, pref)
1618 :
1619 : !The final contribution from Tr[(tau*Y_1*P_occ - tau*Y_2*P_virt) * der_F]
1620 : CALL dbcsr_multiply('N', 'N', fac*tau, Y_1, force_data%P_occ(ispin)%matrix, 1.0_dp, &
1621 92 : force_data%sum_YP_tau(ispin)%matrix, retain_sparsity=.TRUE.)
1622 : CALL dbcsr_multiply('N', 'N', -fac*tau, Y_2, force_data%P_virt(ispin)%matrix, 1.0_dp, &
1623 92 : force_data%sum_YP_tau(ispin)%matrix, retain_sparsity=.TRUE.)
1624 :
1625 92 : spin_fac = 0.5_dp*fac
1626 92 : IF (open_shell) spin_fac = 2.0_dp*spin_fac
1627 : !Build-up the RHS of the response equation.
1628 : CALL dbcsr_multiply('N', 'N', 1.0_dp*spin_fac, R_virt, exp_occ, 1.0_dp, &
1629 92 : force_data%sum_O_tau(ispin)%matrix, retain_sparsity=.TRUE.)
1630 : CALL dbcsr_multiply('N', 'N', -1.0_dp*spin_fac, R_occ, exp_virt, 1.0_dp, &
1631 92 : force_data%sum_O_tau(ispin)%matrix, retain_sparsity=.TRUE.)
1632 : CALL dbcsr_multiply('N', 'N', tau*spin_fac, dbcsr_work_symm, Y_1, 1.0_dp, &
1633 92 : force_data%sum_O_tau(ispin)%matrix, retain_sparsity=.TRUE.)
1634 : CALL dbcsr_multiply('N', 'N', tau*spin_fac, dbcsr_work_symm, Y_2, 1.0_dp, &
1635 92 : force_data%sum_O_tau(ispin)%matrix, retain_sparsity=.TRUE.)
1636 :
1637 92 : CALL timestop(handle2)
1638 :
1639 : !Print some info
1640 92 : CALL para_env%sync()
1641 92 : t2 = m_walltime()
1642 92 : dbcsr_time = dbcsr_time + t2 - t1
1643 :
1644 92 : IF (unit_nr > 0) THEN
1645 : WRITE (unit_nr, '(/T3,A,1X,I3,A)') &
1646 46 : 'RPA_LOW_SCALING_INFO| Info for time point', jquad, ' (gradients)'
1647 : WRITE (unit_nr, '(T6,A,T56,F25.6)') &
1648 46 : 'Time:', t2 - t1
1649 : WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
1650 46 : 'Occupancy of 3c AO derivs:', REAL(nze_der_AO, dp), '/', occ_der_AO*100, '%'
1651 : WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
1652 46 : 'Occupancy of 3c RI derivs:', REAL(nze_der_RI, dp), '/', occ_der_RI*100, '%'
1653 : WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
1654 46 : 'Occupancy of the Docc * Dvirt * 3c-int tensor', REAL(nze_ddint, dp), '/', occ_ddint*100, '%'
1655 : WRITE (unit_nr, '(T6,A,T63,ES7.1,1X,A1,1X,F7.3,A1)') &
1656 46 : 'Occupancy of KBK^T 2c-tensor:', REAL(nze_KBK, dp), '/', occ_KBK*100, '%'
1657 46 : CALL m_flush(unit_nr)
1658 : END IF
1659 :
1660 : !intermediate clean-up
1661 92 : CALL dbcsr_release(Y_1)
1662 92 : CALL dbcsr_release(Y_2)
1663 496 : CALL dbt_destroy(t_2c_tmp)
1664 :
1665 : END DO !jquad
1666 :
1667 36 : CALL dbt_batched_contract_finalize(t_3c_0)
1668 36 : CALL dbt_batched_contract_finalize(t_3c_1)
1669 36 : CALL dbt_batched_contract_finalize(t_3c_3)
1670 36 : CALL dbt_batched_contract_finalize(t_M_occ)
1671 36 : CALL dbt_batched_contract_finalize(t_M_virt)
1672 :
1673 36 : CALL dbt_batched_contract_finalize(t_3c_ints)
1674 36 : CALL dbt_batched_contract_finalize(t_3c_work)
1675 :
1676 36 : CALL dbt_batched_contract_finalize(t_3c_4)
1677 36 : CALL dbt_batched_contract_finalize(t_3c_5)
1678 36 : CALL dbt_batched_contract_finalize(t_3c_6)
1679 36 : CALL dbt_batched_contract_finalize(t_3c_7)
1680 36 : CALL dbt_batched_contract_finalize(t_3c_8)
1681 36 : CALL dbt_batched_contract_finalize(t_3c_sparse)
1682 :
1683 : !Calculate the 2c and 3c contributions to the virial
1684 36 : IF (use_virial) THEN
1685 2 : CALL dbt_copy(force_data%t_3c_virial_split, force_data%t_3c_virial, move_data=.TRUE.)
1686 : CALL calc_3c_virial(work_virial, force_data%t_3c_virial, 1.0_dp, qs_env, force_data%nl_3c, &
1687 : basis_set_ri_aux, basis_set_ao, basis_set_ao, mp2_env%ri_metric, &
1688 2 : der_eps=mp2_env%ri_rpa_im_time%eps_filter, op_pos=1)
1689 :
1690 : CALL calc_2c_virial(work_virial, force_data%RI_virial_met, 1.0_dp, qs_env, force_data%nl_2c_met, &
1691 2 : basis_set_ri_aux, basis_set_ri_aux, mp2_env%ri_metric)
1692 2 : CALL dbcsr_clear(force_data%RI_virial_met)
1693 :
1694 2 : IF (.NOT. force_data%do_periodic) THEN
1695 : CALL calc_2c_virial(work_virial, force_data%RI_virial_pot, 1.0_dp, qs_env, force_data%nl_2c_pot, &
1696 0 : basis_set_ri_aux, basis_set_ri_aux, mp2_env%potential_parameter)
1697 0 : CALL dbcsr_clear(force_data%RI_virial_pot)
1698 : END IF
1699 :
1700 2 : identity_pot%potential_type = do_potential_id
1701 : CALL calc_2c_virial(work_virial_ovlp, virial_ovlp, 1.0_dp, qs_env, force_data%nl_2c_ovlp, &
1702 2 : basis_set_ao, basis_set_ao, identity_pot)
1703 2 : CALL dbcsr_release(virial_ovlp)
1704 :
1705 8 : DO k_xyz = 1, 3
1706 26 : DO j_xyz = 1, 3
1707 78 : DO i_xyz = 1, 3
1708 : virial%pv_mp2(i_xyz, j_xyz) = virial%pv_mp2(i_xyz, j_xyz) &
1709 54 : - work_virial(i_xyz, k_xyz)*cell%hmat(j_xyz, k_xyz)
1710 : virial%pv_overlap(i_xyz, j_xyz) = virial%pv_overlap(i_xyz, j_xyz) &
1711 54 : - work_virial_ovlp(i_xyz, k_xyz)*cell%hmat(j_xyz, k_xyz)
1712 : virial%pv_virial(i_xyz, j_xyz) = virial%pv_virial(i_xyz, j_xyz) &
1713 : - work_virial(i_xyz, k_xyz)*cell%hmat(j_xyz, k_xyz) &
1714 72 : - work_virial_ovlp(i_xyz, k_xyz)*cell%hmat(j_xyz, k_xyz)
1715 : END DO
1716 : END DO
1717 : END DO
1718 : END IF
1719 :
1720 : !Calculate the periodic contributions of (P|Q) to the force and the virial
1721 36 : work_virial = 0.0_dp
1722 36 : IF (force_data%do_periodic) THEN
1723 18 : IF (mp2_env%eri_method == do_eri_gpw) THEN
1724 6 : CALL get_2c_gpw_forces(force_data%G_PQ, force, work_virial, use_virial, mp2_env, qs_env)
1725 12 : ELSE IF (mp2_env%eri_method == do_eri_mme) THEN
1726 12 : CALL get_2c_mme_forces(force_data%G_PQ, force, mp2_env, qs_env)
1727 12 : IF (use_virial) CPABORT("Stress tensor not available with MME intrgrals")
1728 : ELSE
1729 0 : CPABORT("Periodic case not possible with OS integrals")
1730 : END IF
1731 18 : CALL dbcsr_clear(force_data%G_PQ)
1732 : END IF
1733 :
1734 36 : IF (use_virial) THEN
1735 26 : virial%pv_mp2 = virial%pv_mp2 + work_virial
1736 26 : virial%pv_virial = virial%pv_virial + work_virial
1737 2 : virial%pv_calculate = .FALSE.
1738 :
1739 6 : DO ibasis = 1, SIZE(basis_set_ao)
1740 4 : orb_basis => basis_set_ao(ibasis)%gto_basis_set
1741 4 : CALL init_interaction_radii_orb_basis(orb_basis, eps_pgf_orb_old)
1742 4 : ri_basis => basis_set_ri_aux(ibasis)%gto_basis_set
1743 6 : CALL init_interaction_radii_orb_basis(ri_basis, eps_pgf_orb_old)
1744 : END DO
1745 : END IF
1746 :
1747 : !clean-up
1748 36 : IF (ASSOCIATED(dummy_ptr)) DEALLOCATE (dummy_ptr)
1749 128 : DO jquad = 1, num_integ_points
1750 128 : CALL dbt_destroy(t_B(jquad))
1751 : END DO
1752 36 : CALL dbt_destroy(t_P)
1753 36 : CALL dbt_destroy(t_3c_0)
1754 36 : CALL dbt_destroy(t_3c_1)
1755 36 : CALL dbt_destroy(t_3c_3)
1756 36 : CALL dbt_destroy(t_3c_4)
1757 36 : CALL dbt_destroy(t_3c_5)
1758 36 : CALL dbt_destroy(t_3c_6)
1759 36 : CALL dbt_destroy(t_3c_7)
1760 36 : CALL dbt_destroy(t_3c_8)
1761 36 : CALL dbt_destroy(t_3c_sparse)
1762 36 : CALL dbt_destroy(t_3c_help_1)
1763 36 : CALL dbt_destroy(t_3c_help_2)
1764 36 : CALL dbt_destroy(t_3c_ints)
1765 36 : CALL dbt_destroy(t_3c_work)
1766 36 : CALL dbt_destroy(t_R_occ)
1767 36 : CALL dbt_destroy(t_R_virt)
1768 36 : CALL dbt_destroy(t_dm_occ)
1769 36 : CALL dbt_destroy(t_dm_virt)
1770 36 : CALL dbt_destroy(t_KBKT)
1771 36 : CALL dbt_destroy(t_M_occ)
1772 36 : CALL dbt_destroy(t_M_virt)
1773 36 : CALL dbcsr_release(R_occ)
1774 36 : CALL dbcsr_release(R_virt)
1775 36 : CALL dbcsr_release(dbcsr_work_symm)
1776 36 : CALL dbcsr_release(dbcsr_work1)
1777 36 : CALL dbcsr_release(dbcsr_work2)
1778 36 : CALL dbcsr_release(dbcsr_work3)
1779 36 : CALL dbcsr_release(exp_occ)
1780 36 : CALL dbcsr_release(exp_virt)
1781 :
1782 36 : CALL dbt_destroy(t_2c_RI)
1783 36 : CALL dbt_destroy(t_2c_RI_2)
1784 36 : CALL dbt_destroy(t_2c_AO)
1785 36 : CALL dbcsr_deallocate_matrix_set(mat_dm_occ)
1786 36 : CALL dbcsr_deallocate_matrix_set(mat_dm_virt)
1787 36 : CALL dbcsr_deallocate_matrix_set(mat_P_tau)
1788 :
1789 36 : CALL timestop(handle)
1790 :
1791 236 : END SUBROUTINE calc_rpa_loop_forces
1792 :
1793 : ! **************************************************************************************************
1794 : !> \brief This subroutines performs the 2c tensor operations that are common accros low-scaling RPA
1795 : !> and SOS-MP2, including forces and virial
1796 : !> \param force ...
1797 : !> \param t_KBKT returns the 2c tensor product of K*B*K^T
1798 : !> \param force_data ...
1799 : !> \param fac ...
1800 : !> \param t_B depending on RPA or SOS-MP2, t_B contains (1 + Q)^-1 - 1 or simply Q, respectively
1801 : !> \param t_P ...
1802 : !> \param t_2c_RI ...
1803 : !> \param t_2c_RI_2 ...
1804 : !> \param use_virial ...
1805 : !> \param atom_of_kind ...
1806 : !> \param kind_of ...
1807 : !> \param eps_filter ...
1808 : !> \param dbcsr_nflop ...
1809 : !> \param unit_nr_dbcsr ...
1810 : ! **************************************************************************************************
1811 170 : SUBROUTINE perform_2c_ops(force, t_KBKT, force_data, fac, t_B, t_P, t_2c_RI, t_2c_RI_2, use_virial, &
1812 170 : atom_of_kind, kind_of, eps_filter, dbcsr_nflop, unit_nr_dbcsr)
1813 :
1814 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
1815 : TYPE(dbt_type), INTENT(INOUT) :: t_KBKT
1816 : TYPE(im_time_force_type), INTENT(INOUT) :: force_data
1817 : REAL(dp), INTENT(IN) :: fac
1818 : TYPE(dbt_type), INTENT(INOUT) :: t_B, t_P, t_2c_RI, t_2c_RI_2
1819 : LOGICAL, INTENT(IN) :: use_virial
1820 : INTEGER, DIMENSION(:), INTENT(IN) :: atom_of_kind, kind_of
1821 : REAL(dp), INTENT(IN) :: eps_filter
1822 : INTEGER(int_8), INTENT(INOUT) :: dbcsr_nflop
1823 : INTEGER, INTENT(IN) :: unit_nr_dbcsr
1824 :
1825 : CHARACTER(LEN=*), PARAMETER :: routineN = 'perform_2c_ops'
1826 :
1827 : INTEGER :: handle
1828 : INTEGER(int_8) :: flop
1829 : REAL(dp) :: pref
1830 2890 : TYPE(dbt_type) :: t_2c_tmp, t_2c_virial
1831 :
1832 170 : CALL timeset(routineN, handle)
1833 :
1834 170 : IF (use_virial) CALL dbt_create(force_data%RI_virial_pot, t_2c_virial)
1835 :
1836 : !P^T*K*B + P*K*B^T (note we calculate and save K*B*K^T for later, and P=P^T)
1837 : CALL dbt_contract(1.0_dp, force_data%t_2c_K, t_B, 0.0_dp, t_2c_RI, &
1838 : contract_1=[2], notcontract_1=[1], &
1839 : contract_2=[1], notcontract_2=[2], &
1840 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
1841 170 : flop=flop, unit_nr=unit_nr_dbcsr)
1842 170 : dbcsr_nflop = dbcsr_nflop + flop
1843 :
1844 : CALL dbt_contract(1.0_dp, t_2c_RI, force_data%t_2c_K, 0.0_dp, t_KBKT, &
1845 : contract_1=[2], notcontract_1=[1], &
1846 : contract_2=[2], notcontract_2=[1], &
1847 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
1848 170 : flop=flop, unit_nr=unit_nr_dbcsr)
1849 170 : dbcsr_nflop = dbcsr_nflop + flop
1850 :
1851 : CALL dbt_contract(2.0_dp, t_P, t_2c_RI, 0.0_dp, t_2c_RI_2, & !t_2c_RI_2 holds P^T*K*B
1852 : contract_1=[2], notcontract_1=[1], &
1853 : contract_2=[1], notcontract_2=[2], &
1854 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
1855 170 : flop=flop, unit_nr=unit_nr_dbcsr)
1856 170 : dbcsr_nflop = dbcsr_nflop + flop
1857 170 : CALL dbt_clear(t_2c_RI)
1858 : !t_2c_RI_2 currently holds 2*P^T*K*B = P^T*K*B + P*K*B^T (because of symmetry)
1859 :
1860 : !For the metric contribution, we need S^-1*(P^T*K*B + P*K*B^T)*K^T
1861 : CALL dbt_contract(1.0_dp, force_data%t_2c_inv_metric, t_2c_RI_2, 0.0_dp, t_2c_RI, &
1862 : contract_1=[2], notcontract_1=[1], &
1863 : contract_2=[1], notcontract_2=[2], &
1864 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
1865 170 : flop=flop, unit_nr=unit_nr_dbcsr)
1866 170 : dbcsr_nflop = dbcsr_nflop + flop
1867 :
1868 : CALL dbt_contract(1.0_dp, t_2c_RI, force_data%t_2c_K, 0.0_dp, t_2c_RI_2, &
1869 : contract_1=[2], notcontract_1=[1], &
1870 : contract_2=[2], notcontract_2=[1], &
1871 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
1872 170 : flop=flop, unit_nr=unit_nr_dbcsr)
1873 170 : dbcsr_nflop = dbcsr_nflop + flop
1874 :
1875 : !Here we do the trace for the force
1876 170 : pref = -1.0_dp*fac
1877 : CALL get_2c_der_force(force, t_2c_RI_2, force_data%t_2c_der_metric, atom_of_kind, &
1878 170 : kind_of, force_data%idx_to_at_RI, pref, do_mp2=.TRUE.)
1879 170 : IF (use_virial) THEN
1880 12 : CALL dbt_copy(t_2c_RI_2, t_2c_virial)
1881 12 : CALL dbt_scale(t_2c_virial, pref)
1882 12 : CALL dbt_copy_tensor_to_matrix(t_2c_virial, force_data%RI_virial_met, summation=.TRUE.)
1883 12 : CALL dbt_clear(t_2c_virial)
1884 : END IF
1885 :
1886 : !For the potential contribution, we need S^-1*(P^T*K*B + P*K*B^T)*V^-0.5
1887 : !some of it is still in t_2c_RI: ( S^-1*(P^T*K*B + P*K*B^T) )
1888 : CALL dbt_contract(1.0_dp, t_2c_RI, force_data%t_2c_pot_msqrt, 0.0_dp, t_2c_RI_2, &
1889 : contract_1=[2], notcontract_1=[1], &
1890 : contract_2=[1], notcontract_2=[2], &
1891 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
1892 170 : flop=flop, unit_nr=unit_nr_dbcsr)
1893 170 : dbcsr_nflop = dbcsr_nflop + flop
1894 :
1895 : !Here we do the trace for the force. In the periodic case, we store the matrix in G_PQ for later
1896 170 : pref = 0.5_dp*fac
1897 170 : IF (force_data%do_periodic) THEN
1898 76 : CALL dbt_scale(t_2c_RI_2, pref)
1899 76 : CALL dbt_create(force_data%G_PQ, t_2c_tmp)
1900 76 : CALL dbt_copy(t_2c_RI_2, t_2c_tmp, move_data=.TRUE.)
1901 76 : CALL dbt_copy_tensor_to_matrix(t_2c_tmp, force_data%G_PQ, summation=.TRUE.)
1902 76 : CALL dbt_destroy(t_2c_tmp)
1903 : ELSE
1904 : CALL get_2c_der_force(force, t_2c_RI_2, force_data%t_2c_der_pot, atom_of_kind, &
1905 94 : kind_of, force_data%idx_to_at_RI, pref, do_mp2=.TRUE.)
1906 :
1907 94 : IF (use_virial) THEN
1908 0 : CALL dbt_copy(t_2c_RI_2, t_2c_virial)
1909 0 : CALL dbt_scale(t_2c_virial, pref)
1910 0 : CALL dbt_copy_tensor_to_matrix(t_2c_virial, force_data%RI_virial_pot, summation=.TRUE.)
1911 0 : CALL dbt_clear(t_2c_virial)
1912 : END IF
1913 : END IF
1914 :
1915 170 : CALL dbt_clear(t_2c_RI)
1916 170 : CALL dbt_clear(t_2c_RI_2)
1917 :
1918 170 : IF (use_virial) CALL dbt_destroy(t_2c_virial)
1919 :
1920 170 : CALL timestop(handle)
1921 :
1922 170 : END SUBROUTINE perform_2c_ops
1923 :
1924 : ! **************************************************************************************************
1925 : !> \brief This subroutines performs the 3c tensor operations that are common accros low-scaling RPA
1926 : !> and SOS-MP2, including forces and virial
1927 : !> \param force ...
1928 : !> \param t_R_occ ...
1929 : !> \param t_R_virt ...
1930 : !> \param force_data ...
1931 : !> \param fac ...
1932 : !> \param cut_memory ...
1933 : !> \param n_mem_RI ...
1934 : !> \param t_KBKT ...
1935 : !> \param t_dm_occ ...
1936 : !> \param t_dm_virt ...
1937 : !> \param t_3c_O ...
1938 : !> \param t_3c_M ...
1939 : !> \param t_M_occ ...
1940 : !> \param t_M_virt ...
1941 : !> \param t_3c_0 ...
1942 : !> \param t_3c_1 ...
1943 : !> \param t_3c_3 ...
1944 : !> \param t_3c_4 ...
1945 : !> \param t_3c_5 ...
1946 : !> \param t_3c_6 ...
1947 : !> \param t_3c_7 ...
1948 : !> \param t_3c_8 ...
1949 : !> \param t_3c_sparse ...
1950 : !> \param t_3c_help_1 ...
1951 : !> \param t_3c_help_2 ...
1952 : !> \param t_3c_ints ...
1953 : !> \param t_3c_work ...
1954 : !> \param starts_array_mc ...
1955 : !> \param ends_array_mc ...
1956 : !> \param batch_start_RI ...
1957 : !> \param batch_end_RI ...
1958 : !> \param t_3c_O_compressed ...
1959 : !> \param t_3c_O_ind ...
1960 : !> \param use_virial ...
1961 : !> \param atom_of_kind ...
1962 : !> \param kind_of ...
1963 : !> \param eps_filter ...
1964 : !> \param occ_ddint ...
1965 : !> \param nze_ddint ...
1966 : !> \param dbcsr_nflop ...
1967 : !> \param unit_nr_dbcsr ...
1968 : !> \param mp2_env ...
1969 : ! **************************************************************************************************
1970 170 : SUBROUTINE perform_3c_ops(force, t_R_occ, t_R_virt, force_data, fac, cut_memory, n_mem_RI, &
1971 : t_KBKT, t_dm_occ, t_dm_virt, t_3c_O, t_3c_M, t_M_occ, t_M_virt, t_3c_0, t_3c_1, &
1972 : t_3c_3, t_3c_4, t_3c_5, t_3c_6, t_3c_7, t_3c_8, t_3c_sparse, t_3c_help_1, t_3c_help_2, &
1973 170 : t_3c_ints, t_3c_work, starts_array_mc, ends_array_mc, batch_start_RI, &
1974 170 : batch_end_RI, t_3c_O_compressed, t_3c_O_ind, use_virial, &
1975 170 : atom_of_kind, kind_of, eps_filter, occ_ddint, nze_ddint, dbcsr_nflop, &
1976 : unit_nr_dbcsr, mp2_env)
1977 :
1978 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
1979 : TYPE(dbt_type), INTENT(INOUT) :: t_R_occ, t_R_virt
1980 : TYPE(im_time_force_type), INTENT(INOUT) :: force_data
1981 : REAL(dp), INTENT(IN) :: fac
1982 : INTEGER, INTENT(IN) :: cut_memory, n_mem_RI
1983 : TYPE(dbt_type), INTENT(INOUT) :: t_KBKT, t_dm_occ, t_dm_virt, t_3c_O, t_3c_M, t_M_occ, &
1984 : t_M_virt, t_3c_0, t_3c_1, t_3c_3, t_3c_4, t_3c_5, t_3c_6, t_3c_7, t_3c_8, t_3c_sparse, &
1985 : t_3c_help_1, t_3c_help_2, t_3c_ints, t_3c_work
1986 : INTEGER, DIMENSION(:), INTENT(IN) :: starts_array_mc, ends_array_mc, &
1987 : batch_start_RI, batch_end_RI
1988 : TYPE(hfx_compression_type), DIMENSION(:) :: t_3c_O_compressed
1989 : TYPE(block_ind_type), DIMENSION(:), INTENT(INOUT) :: t_3c_O_ind
1990 : LOGICAL, INTENT(IN) :: use_virial
1991 : INTEGER, DIMENSION(:), INTENT(IN) :: atom_of_kind, kind_of
1992 : REAL(dp), INTENT(IN) :: eps_filter
1993 : REAL(dp), INTENT(INOUT) :: occ_ddint
1994 : INTEGER(int_8), INTENT(INOUT) :: nze_ddint, dbcsr_nflop
1995 : INTEGER, INTENT(IN) :: unit_nr_dbcsr
1996 : TYPE(mp2_type) :: mp2_env
1997 :
1998 : CHARACTER(LEN=*), PARAMETER :: routineN = 'perform_3c_ops'
1999 :
2000 : INTEGER :: dummy_int, handle, handle2, i_mem, &
2001 : i_xyz, j_mem, k_mem
2002 : INTEGER(int_8) :: flop, nze
2003 : INTEGER, DIMENSION(2, 1) :: ibounds, jbounds, kbounds
2004 : INTEGER, DIMENSION(2, 2) :: bounds_2c
2005 : INTEGER, DIMENSION(2, 3) :: bounds_cpy
2006 : INTEGER, DIMENSION(3) :: bounds_3c
2007 : REAL(dp) :: memory, occ, pref
2008 170 : TYPE(block_ind_type), ALLOCATABLE, DIMENSION(:, :) :: blk_indices
2009 : TYPE(hfx_compression_type), ALLOCATABLE, &
2010 170 : DIMENSION(:, :) :: store_3c
2011 :
2012 170 : CALL timeset(routineN, handle)
2013 :
2014 170 : CALL dbt_get_info(t_3c_M, nfull_total=bounds_3c)
2015 :
2016 : !Pre-compute and compress KBK^T * (pq|R)
2017 360910 : ALLOCATE (store_3c(n_mem_RI, cut_memory))
2018 1700 : ALLOCATE (blk_indices(n_mem_RI, cut_memory))
2019 170 : memory = 0.0_dp
2020 170 : CALL timeset(routineN//"_pre_3c", handle2)
2021 : !temporarily build the full int 3c tensor
2022 170 : CALL dbt_copy(t_3c_O, t_3c_0)
2023 510 : DO i_mem = 1, cut_memory
2024 : CALL decompress_tensor(t_3c_O, t_3c_O_ind(i_mem)%ind, t_3c_O_compressed(i_mem), &
2025 340 : mp2_env%ri_rpa_im_time%eps_compress)
2026 340 : CALL dbt_copy(t_3c_O, t_3c_ints)
2027 340 : CALL dbt_copy(t_3c_O, t_3c_0, move_data=.TRUE., summation=.TRUE.)
2028 :
2029 1190 : DO k_mem = 1, n_mem_RI
2030 2040 : kbounds(:, 1) = [batch_start_RI(k_mem), batch_end_RI(k_mem)]
2031 :
2032 680 : CALL alloc_containers(store_3c(k_mem, i_mem), 1)
2033 :
2034 : !contract witht KBK^T over the RI index and store
2035 680 : CALL dbt_batched_contract_init(t_KBKT)
2036 : CALL dbt_contract(1.0_dp, t_KBKT, t_3c_ints, 0.0_dp, t_3c_work, &
2037 : contract_1=[2], notcontract_1=[1], &
2038 : contract_2=[1], notcontract_2=[2, 3], &
2039 : map_1=[1], map_2=[2, 3], filter_eps=eps_filter, &
2040 680 : bounds_2=kbounds, flop=flop, unit_nr=unit_nr_dbcsr)
2041 680 : CALL dbt_batched_contract_finalize(t_KBKT)
2042 680 : dbcsr_nflop = dbcsr_nflop + flop
2043 :
2044 680 : CALL dbt_copy(t_3c_work, t_3c_M, move_data=.TRUE.)
2045 : CALL compress_tensor(t_3c_M, blk_indices(k_mem, i_mem)%ind, store_3c(k_mem, i_mem), &
2046 1020 : mp2_env%ri_rpa_im_time%eps_compress, memory)
2047 : END DO
2048 : END DO !i_mem
2049 170 : CALL dbt_clear(t_3c_M)
2050 170 : CALL dbt_copy(t_3c_M, t_3c_ints)
2051 170 : CALL timestop(handle2)
2052 :
2053 170 : CALL dbt_batched_contract_init(t_R_occ)
2054 170 : CALL dbt_batched_contract_init(t_R_virt)
2055 510 : DO i_mem = 1, cut_memory
2056 1020 : ibounds(:, 1) = [starts_array_mc(i_mem), ends_array_mc(i_mem)]
2057 :
2058 : !Compute the matrices M (integrals in t_3c_0)
2059 340 : CALL timeset(routineN//"_3c_M", handle2)
2060 340 : CALL dbt_batched_contract_init(t_dm_occ)
2061 : CALL dbt_contract(1.0_dp, t_3c_0, t_dm_occ, 0.0_dp, t_3c_1, &
2062 : contract_1=[3], notcontract_1=[1, 2], &
2063 : contract_2=[1], notcontract_2=[2], &
2064 : map_1=[1, 2], map_2=[3], filter_eps=eps_filter, &
2065 340 : bounds_3=ibounds, flop=flop, unit_nr=unit_nr_dbcsr)
2066 340 : dbcsr_nflop = dbcsr_nflop + flop
2067 340 : CALL dbt_batched_contract_finalize(t_dm_occ)
2068 340 : CALL dbt_copy(t_3c_1, t_M_occ, order=[1, 3, 2], move_data=.TRUE.)
2069 :
2070 340 : CALL dbt_batched_contract_init(t_dm_virt)
2071 : CALL dbt_contract(1.0_dp, t_3c_0, t_dm_virt, 0.0_dp, t_3c_1, &
2072 : contract_1=[3], notcontract_1=[1, 2], &
2073 : contract_2=[1], notcontract_2=[2], &
2074 : map_1=[1, 2], map_2=[3], filter_eps=eps_filter, &
2075 340 : bounds_3=ibounds, flop=flop, unit_nr=unit_nr_dbcsr)
2076 340 : dbcsr_nflop = dbcsr_nflop + flop
2077 340 : CALL dbt_batched_contract_finalize(t_dm_virt)
2078 340 : CALL dbt_copy(t_3c_1, t_M_virt, order=[1, 3, 2], move_data=.TRUE.)
2079 340 : CALL timestop(handle2)
2080 :
2081 : !Compute the R matrices
2082 340 : CALL timeset(routineN//"_3c_R", handle2)
2083 1020 : DO k_mem = 1, n_mem_RI
2084 : CALL decompress_tensor(t_3c_M, blk_indices(k_mem, i_mem)%ind, store_3c(k_mem, i_mem), &
2085 680 : mp2_env%ri_rpa_im_time%eps_compress)
2086 680 : CALL dbt_copy(t_3c_M, t_3c_3, move_data=.TRUE.)
2087 :
2088 : CALL dbt_contract(1.0_dp, t_M_occ, t_3c_3, 1.0_dp, t_R_occ, &
2089 : contract_1=[1, 2], notcontract_1=[3], &
2090 : contract_2=[1, 2], notcontract_2=[3], &
2091 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
2092 680 : flop=flop, unit_nr=unit_nr_dbcsr)
2093 680 : dbcsr_nflop = dbcsr_nflop + flop
2094 :
2095 : CALL dbt_contract(1.0_dp, t_M_virt, t_3c_3, 1.0_dp, t_R_virt, &
2096 : contract_1=[1, 2], notcontract_1=[3], &
2097 : contract_2=[1, 2], notcontract_2=[3], &
2098 : map_1=[1], map_2=[2], filter_eps=eps_filter, &
2099 680 : flop=flop, unit_nr=unit_nr_dbcsr)
2100 1020 : dbcsr_nflop = dbcsr_nflop + flop
2101 : END DO
2102 340 : CALL dbt_copy(t_3c_M, t_3c_3)
2103 340 : CALL dbt_copy(t_3c_M, t_M_virt)
2104 340 : CALL timestop(handle2)
2105 :
2106 340 : CALL dbt_copy(t_M_occ, t_3c_4, move_data=.TRUE.)
2107 :
2108 1020 : DO j_mem = 1, cut_memory
2109 2040 : jbounds(:, 1) = [starts_array_mc(j_mem), ends_array_mc(j_mem)]
2110 :
2111 2040 : bounds_cpy(:, 1) = [1, bounds_3c(1)]
2112 2040 : bounds_cpy(:, 2) = [starts_array_mc(i_mem), ends_array_mc(i_mem)]
2113 2040 : bounds_cpy(:, 3) = [starts_array_mc(j_mem), ends_array_mc(j_mem)]
2114 680 : CALL dbt_copy(t_3c_sparse, t_3c_7, bounds=bounds_cpy)
2115 :
2116 680 : CALL dbt_batched_contract_init(t_dm_virt)
2117 2040 : DO k_mem = 1, n_mem_RI
2118 4080 : bounds_2c(:, 1) = [batch_start_RI(k_mem), batch_end_RI(k_mem)]
2119 4080 : bounds_2c(:, 2) = [starts_array_mc(i_mem), ends_array_mc(i_mem)]
2120 :
2121 1360 : CALL timeset(routineN//"_3c_dm", handle2)
2122 :
2123 : !Calculate (mu nu| P) * D_occ * D_virt
2124 : !Note: technically need M_occ*D_virt + M_virt*D_occ, but it is equivalent to 2*M_occ*D_virt
2125 : CALL dbt_contract(2.0_dp, t_3c_4, t_dm_virt, 0.0_dp, t_3c_5, &
2126 : contract_1=[3], notcontract_1=[1, 2], &
2127 : contract_2=[1], notcontract_2=[2], &
2128 : map_1=[1, 2], map_2=[3], filter_eps=eps_filter, &
2129 1360 : bounds_2=bounds_2c, bounds_3=jbounds, flop=flop, unit_nr=unit_nr_dbcsr)
2130 1360 : dbcsr_nflop = dbcsr_nflop + flop
2131 :
2132 1360 : CALL get_tensor_occupancy(t_3c_5, nze, occ)
2133 1360 : nze_ddint = nze_ddint + nze
2134 1360 : occ_ddint = occ_ddint + occ
2135 :
2136 1360 : CALL dbt_copy(t_3c_5, t_3c_6, move_data=.TRUE.)
2137 1360 : CALL timestop(handle2)
2138 :
2139 : !Calculate the contraction of the above with K*B*K^T
2140 1360 : CALL timeset(routineN//"_3c_KBK", handle2)
2141 1360 : CALL dbt_batched_contract_init(t_KBKT)
2142 : CALL dbt_contract(1.0_dp, t_KBKT, t_3c_6, 0.0_dp, t_3c_7, &
2143 : contract_1=[2], notcontract_1=[1], &
2144 : contract_2=[1], notcontract_2=[2, 3], &
2145 : map_1=[1], map_2=[2, 3], &
2146 1360 : retain_sparsity=.TRUE., flop=flop, unit_nr=unit_nr_dbcsr)
2147 1360 : dbcsr_nflop = dbcsr_nflop + flop
2148 1360 : CALL dbt_batched_contract_finalize(t_KBKT)
2149 1360 : CALL timestop(handle2)
2150 6120 : CALL dbt_copy(t_3c_7, t_3c_8, summation=.TRUE.)
2151 :
2152 : END DO !k_mem
2153 1020 : CALL dbt_batched_contract_finalize(t_dm_virt)
2154 : END DO !j_mem
2155 :
2156 340 : CALL dbt_copy(t_3c_8, t_3c_help_1, move_data=.TRUE.)
2157 :
2158 340 : pref = 1.0_dp*fac
2159 1020 : DO k_mem = 1, cut_memory
2160 2720 : DO i_xyz = 1, 3
2161 2040 : CALL dbt_clear(force_data%t_3c_der_RI(i_xyz))
2162 : CALL decompress_tensor(force_data%t_3c_der_RI(i_xyz), force_data%t_3c_der_RI_ind(k_mem, i_xyz)%ind, &
2163 2720 : force_data%t_3c_der_RI_comp(k_mem, i_xyz), mp2_env%ri_rpa_im_time%eps_compress)
2164 : END DO
2165 : CALL get_force_from_3c_trace(force, t_3c_help_1, force_data%t_3c_der_RI, atom_of_kind, kind_of, &
2166 1020 : force_data%idx_to_at_RI, pref, do_mp2=.TRUE., deriv_dim=1)
2167 : END DO
2168 :
2169 340 : IF (use_virial) THEN
2170 24 : CALL dbt_copy(t_3c_help_1, t_3c_help_2)
2171 24 : CALL dbt_scale(t_3c_help_2, pref)
2172 24 : CALL dbt_copy(t_3c_help_2, force_data%t_3c_virial_split, summation=.TRUE., move_data=.TRUE.)
2173 : END IF
2174 :
2175 340 : CALL dbt_copy(t_3c_help_1, t_3c_help_2)
2176 340 : CALL dbt_copy(t_3c_help_1, t_3c_help_2, order=[1, 3, 2], move_data=.TRUE., summation=.TRUE.)
2177 1020 : DO k_mem = 1, cut_memory
2178 2720 : DO i_xyz = 1, 3
2179 2040 : CALL dbt_clear(force_data%t_3c_der_AO(i_xyz))
2180 : CALL decompress_tensor(force_data%t_3c_der_AO(i_xyz), force_data%t_3c_der_AO_ind(k_mem, i_xyz)%ind, &
2181 2720 : force_data%t_3c_der_AO_comp(k_mem, i_xyz), mp2_env%ri_rpa_im_time%eps_compress)
2182 : END DO
2183 : CALL get_force_from_3c_trace(force, t_3c_help_2, force_data%t_3c_der_AO, atom_of_kind, kind_of, &
2184 1020 : force_data%idx_to_at_AO, pref, do_mp2=.TRUE., deriv_dim=3)
2185 : END DO
2186 :
2187 1190 : CALL dbt_clear(t_3c_help_2)
2188 : END DO !i_mem
2189 170 : CALL dbt_batched_contract_finalize(t_R_occ)
2190 170 : CALL dbt_batched_contract_finalize(t_R_virt)
2191 :
2192 510 : DO k_mem = 1, n_mem_RI
2193 1190 : DO i_mem = 1, cut_memory
2194 1020 : CALL dealloc_containers(store_3c(k_mem, i_mem), dummy_int)
2195 : END DO
2196 : END DO
2197 850 : DEALLOCATE (store_3c, blk_indices)
2198 :
2199 170 : CALL timestop(handle)
2200 :
2201 340 : END SUBROUTINE perform_3c_ops
2202 :
2203 : ! **************************************************************************************************
2204 : !> \brief All the forces that can be calculated after the loop on the Laplace quaradture, using
2205 : !> terms collected during the said loop. This inludes the z-vector equation and its reponse
2206 : !> forces, as well as the force coming from the trace with the derivative of the KS matrix
2207 : !> \param force_data ...
2208 : !> \param unit_nr ...
2209 : !> \param qs_env ...
2210 : ! **************************************************************************************************
2211 50 : SUBROUTINE calc_post_loop_forces(force_data, unit_nr, qs_env)
2212 :
2213 : TYPE(im_time_force_type), INTENT(INOUT) :: force_data
2214 : INTEGER, INTENT(IN) :: unit_nr
2215 : TYPE(qs_environment_type), POINTER :: qs_env
2216 :
2217 : CHARACTER(len=*), PARAMETER :: routineN = 'calc_post_loop_forces'
2218 :
2219 : INTEGER :: handle, ispin, nao, nao_aux, nocc, nspins
2220 : LOGICAL :: do_exx
2221 : REAL(dp) :: focc
2222 : TYPE(admm_type), POINTER :: admm_env
2223 : TYPE(cp_fm_struct_type), POINTER :: fm_struct
2224 50 : TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: cpmos, mo_occ
2225 : TYPE(cp_fm_type), POINTER :: mo_coeff
2226 50 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: dbcsr_p_work, matrix_p_mp2, &
2227 50 : matrix_p_mp2_admm, matrix_s, &
2228 50 : matrix_s_aux, work_admm, YP_admm
2229 : TYPE(dft_control_type), POINTER :: dft_control
2230 : TYPE(linres_control_type), POINTER :: linres_control
2231 50 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
2232 : TYPE(qs_p_env_type), POINTER :: p_env
2233 : TYPE(section_vals_type), POINTER :: hfx_section, lr_section
2234 :
2235 50 : NULLIFY (linres_control, p_env, dft_control, matrix_s, mos, mo_coeff, fm_struct, lr_section, &
2236 50 : dbcsr_p_work, YP_admm, matrix_p_mp2, admm_env, work_admm, matrix_s_aux, matrix_p_mp2_admm)
2237 :
2238 50 : CALL timeset(routineN, handle)
2239 :
2240 50 : CALL get_qs_env(qs_env, dft_control=dft_control, matrix_s=matrix_s, mos=mos)
2241 50 : nspins = dft_control%nspins
2242 :
2243 : ! Setting up for the z-vector equation
2244 :
2245 : ! Initialize linres_control
2246 50 : lr_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION%LOW_SCALING%CPHF")
2247 :
2248 50 : ALLOCATE (linres_control)
2249 50 : CALL section_vals_val_get(lr_section, "MAX_ITER", i_val=linres_control%max_iter)
2250 50 : CALL section_vals_val_get(lr_section, "EPS_CONV", r_val=linres_control%eps)
2251 50 : CALL section_vals_val_get(lr_section, "PRECONDITIONER", i_val=linres_control%preconditioner_type)
2252 50 : CALL section_vals_val_get(lr_section, "ENERGY_GAP", r_val=linres_control%energy_gap)
2253 :
2254 50 : linres_control%do_kernel = .TRUE.
2255 50 : linres_control%lr_triplet = .FALSE.
2256 50 : linres_control%converged = .FALSE.
2257 50 : linres_control%eps_filter = qs_env%mp2_env%ri_rpa_im_time%eps_filter
2258 :
2259 50 : CALL set_qs_env(qs_env, linres_control=linres_control)
2260 :
2261 50 : IF (unit_nr > 0) THEN
2262 25 : WRITE (unit_nr, *)
2263 25 : WRITE (unit_nr, '(T3,A)') 'MP2_CPHF| Iterative solution of Z-Vector equations'
2264 25 : WRITE (unit_nr, '(T3,A,T45,ES8.1)') 'MP2_CPHF| Convergence threshold:', linres_control%eps
2265 25 : WRITE (unit_nr, '(T3,A,T45,I8)') 'MP2_CPHF| Maximum number of iterations: ', linres_control%max_iter
2266 : END IF
2267 :
2268 350 : ALLOCATE (p_env)
2269 50 : CALL p_env_create(p_env, qs_env, orthogonal_orbitals=.TRUE., linres_control=linres_control)
2270 50 : CALL p_env_psi0_changed(p_env, qs_env)
2271 :
2272 : ! Matrix allocation
2273 50 : CALL dbcsr_allocate_matrix_set(p_env%p1, nspins)
2274 50 : CALL dbcsr_allocate_matrix_set(p_env%w1, nspins)
2275 50 : CALL dbcsr_allocate_matrix_set(dbcsr_p_work, nspins)
2276 112 : DO ispin = 1, nspins
2277 62 : ALLOCATE (p_env%p1(ispin)%matrix, p_env%w1(ispin)%matrix, dbcsr_p_work(ispin)%matrix)
2278 62 : CALL dbcsr_create(matrix=p_env%p1(ispin)%matrix, template=matrix_s(1)%matrix)
2279 62 : CALL dbcsr_create(matrix=p_env%w1(ispin)%matrix, template=matrix_s(1)%matrix)
2280 62 : CALL dbcsr_create(matrix=dbcsr_p_work(ispin)%matrix, template=matrix_s(1)%matrix)
2281 62 : CALL dbcsr_copy(p_env%p1(ispin)%matrix, matrix_s(1)%matrix)
2282 62 : CALL dbcsr_copy(p_env%w1(ispin)%matrix, matrix_s(1)%matrix)
2283 62 : CALL dbcsr_copy(dbcsr_p_work(ispin)%matrix, matrix_s(1)%matrix)
2284 62 : CALL dbcsr_set(p_env%p1(ispin)%matrix, 0.0_dp)
2285 62 : CALL dbcsr_set(p_env%w1(ispin)%matrix, 0.0_dp)
2286 112 : CALL dbcsr_set(dbcsr_p_work(ispin)%matrix, 0.0_dp)
2287 : END DO
2288 :
2289 50 : IF (dft_control%do_admm) THEN
2290 16 : CALL get_admm_env(qs_env%admm_env, matrix_s_aux_fit=matrix_s_aux)
2291 16 : CALL dbcsr_allocate_matrix_set(p_env%p1_admm, nspins)
2292 16 : CALL dbcsr_allocate_matrix_set(work_admm, nspins)
2293 36 : DO ispin = 1, nspins
2294 20 : ALLOCATE (p_env%p1_admm(ispin)%matrix, work_admm(ispin)%matrix)
2295 20 : CALL dbcsr_create(p_env%p1_admm(ispin)%matrix, template=matrix_s_aux(1)%matrix)
2296 20 : CALL dbcsr_copy(p_env%p1_admm(ispin)%matrix, matrix_s_aux(1)%matrix)
2297 20 : CALL dbcsr_set(p_env%p1_admm(ispin)%matrix, 0.0_dp)
2298 20 : CALL dbcsr_create(work_admm(ispin)%matrix, template=matrix_s_aux(1)%matrix)
2299 20 : CALL dbcsr_copy(work_admm(ispin)%matrix, matrix_s_aux(1)%matrix)
2300 36 : CALL dbcsr_set(work_admm(ispin)%matrix, 0.0_dp)
2301 : END DO
2302 : END IF
2303 :
2304 : ! Preparing the RHS of the z-vector equation
2305 50 : CALL prepare_for_response(force_data, qs_env)
2306 374 : ALLOCATE (cpmos(nspins), mo_occ(nspins))
2307 112 : DO ispin = 1, nspins
2308 62 : CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, nao=nao, homo=nocc)
2309 62 : NULLIFY (fm_struct)
2310 : CALL cp_fm_struct_create(fm_struct, ncol_global=nocc, &
2311 62 : template_fmstruct=mo_coeff%matrix_struct)
2312 62 : CALL cp_fm_create(cpmos(ispin), fm_struct)
2313 62 : CALL cp_fm_set_all(cpmos(ispin), 0.0_dp)
2314 62 : CALL cp_fm_create(mo_occ(ispin), fm_struct)
2315 62 : CALL cp_fm_to_fm(mo_coeff, mo_occ(ispin), nocc)
2316 174 : CALL cp_fm_struct_release(fm_struct)
2317 : END DO
2318 :
2319 : ! in case of EXX, need to add the HF Hamiltonian to the RHS of the Z-vector equation
2320 : ! Strategy: we take the ks_matrix, remove the current xc contribution, and then add the RPA HF one
2321 50 : do_exx = .FALSE.
2322 50 : IF (qs_env%mp2_env%method == ri_rpa_method_gpw) THEN
2323 28 : hfx_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION%RI_RPA%HF")
2324 28 : CALL section_vals_get(hfx_section, explicit=do_exx)
2325 : END IF
2326 :
2327 50 : IF (do_exx) THEN
2328 : CALL add_exx_to_rhs(rhs=force_data%sum_O_tau, &
2329 : qs_env=qs_env, &
2330 : ext_hfx_section=hfx_section, &
2331 : x_data=qs_env%mp2_env%ri_rpa%x_data, &
2332 : recalc_integrals=.FALSE., &
2333 : do_admm=qs_env%mp2_env%ri_rpa%do_admm, &
2334 : do_exx=do_exx, &
2335 18 : reuse_hfx=qs_env%mp2_env%ri_rpa%reuse_hfx)
2336 : END IF
2337 :
2338 50 : focc = 2.0_dp
2339 50 : IF (nspins == 1) focc = 4.0_dp
2340 112 : DO ispin = 1, nspins
2341 62 : CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, homo=nocc)
2342 : CALL cp_dbcsr_sm_fm_multiply(force_data%sum_O_tau(ispin)%matrix, mo_occ(ispin), &
2343 : cpmos(ispin), nocc, &
2344 112 : alpha=focc, beta=0.0_dp)
2345 : END DO
2346 :
2347 : ! The z-vector equation and associated forces
2348 50 : CALL response_equation_new(qs_env, p_env, cpmos, unit_nr)
2349 :
2350 : ! Save the mp2 density matrix
2351 50 : CALL get_qs_env(qs_env, matrix_p_mp2=matrix_p_mp2)
2352 50 : IF (ASSOCIATED(matrix_p_mp2)) CALL dbcsr_deallocate_matrix_set(matrix_p_mp2)
2353 112 : DO ispin = 1, nspins
2354 62 : CALL dbcsr_copy(dbcsr_p_work(ispin)%matrix, p_env%p1(ispin)%matrix)
2355 112 : CALL dbcsr_add(dbcsr_p_work(ispin)%matrix, force_data%sum_YP_tau(ispin)%matrix, 1.0_dp, 1.0_dp)
2356 : END DO
2357 50 : CALL set_ks_env(qs_env%ks_env, matrix_p_mp2=dbcsr_p_work)
2358 :
2359 50 : IF (dft_control%do_admm) THEN
2360 16 : CALL dbcsr_allocate_matrix_set(YP_admm, nspins)
2361 16 : CALL get_qs_env(qs_env, matrix_p_mp2_admm=matrix_p_mp2_admm, admm_env=admm_env)
2362 16 : nao = admm_env%nao_orb
2363 16 : nao_aux = admm_env%nao_aux_fit
2364 16 : IF (ASSOCIATED(matrix_p_mp2_admm)) CALL dbcsr_deallocate_matrix_set(matrix_p_mp2_admm)
2365 36 : DO ispin = 1, nspins
2366 :
2367 : !sum_YP_tau in the auxiliary basis
2368 20 : CALL copy_dbcsr_to_fm(force_data%sum_YP_tau(ispin)%matrix, admm_env%work_orb_orb)
2369 : CALL parallel_gemm('N', 'N', nao_aux, nao, nao, 1.0_dp, admm_env%A, admm_env%work_orb_orb, &
2370 20 : 0.0_dp, admm_env%work_aux_orb)
2371 : CALL parallel_gemm('N', 'T', nao_aux, nao_aux, nao, 1.0_dp, admm_env%work_aux_orb, admm_env%A, &
2372 20 : 0.0_dp, admm_env%work_aux_aux)
2373 20 : CALL copy_fm_to_dbcsr(admm_env%work_aux_aux, work_admm(ispin)%matrix, keep_sparsity=.TRUE.)
2374 :
2375 : !save the admm representation od sum_YP_tau
2376 20 : ALLOCATE (YP_admm(ispin)%matrix)
2377 20 : CALL dbcsr_create(YP_admm(ispin)%matrix, template=work_admm(ispin)%matrix)
2378 20 : CALL dbcsr_copy(YP_admm(ispin)%matrix, work_admm(ispin)%matrix)
2379 :
2380 36 : CALL dbcsr_add(work_admm(ispin)%matrix, p_env%p1_admm(ispin)%matrix, 1.0_dp, 1.0_dp)
2381 :
2382 : END DO
2383 16 : CALL set_ks_env(qs_env%ks_env, matrix_p_mp2_admm=work_admm)
2384 : END IF
2385 :
2386 : !Calculate the response force and the force from the trace with F
2387 50 : CALL update_im_time_forces(p_env, force_data%sum_O_tau, force_data%sum_YP_tau, YP_admm, qs_env)
2388 :
2389 : !clean-up
2390 50 : IF (dft_control%do_admm) CALL dbcsr_deallocate_matrix_set(YP_admm)
2391 :
2392 50 : CALL cp_fm_release(cpmos)
2393 50 : CALL cp_fm_release(mo_occ)
2394 50 : CALL p_env_release(p_env)
2395 50 : DEALLOCATE (p_env)
2396 :
2397 50 : CALL timestop(handle)
2398 :
2399 100 : END SUBROUTINE calc_post_loop_forces
2400 :
2401 : ! **************************************************************************************************
2402 : !> \brief Prepares the RHS of the z-vector equation. Apply the xc and HFX kernel on the previously
2403 : !> stored sum_YP_tau density, and add it to the final force_data%sum_O_tau quantity
2404 : !> \param force_data ...
2405 : !> \param qs_env ...
2406 : ! **************************************************************************************************
2407 50 : SUBROUTINE prepare_for_response(force_data, qs_env)
2408 :
2409 : TYPE(im_time_force_type), INTENT(INOUT) :: force_data
2410 : TYPE(qs_environment_type), POINTER :: qs_env
2411 :
2412 : CHARACTER(LEN=*), PARAMETER :: routineN = 'prepare_for_response'
2413 :
2414 : INTEGER :: handle, ispin, nao, nao_aux, nspins
2415 : LOGICAL :: do_hfx, do_tau, do_tau_admm
2416 : REAL(dp) :: ehartree
2417 : TYPE(admm_type), POINTER :: admm_env
2418 50 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: dbcsr_p_work, ker_tau_admm, matrix_s, &
2419 50 : matrix_s_aux, work_admm
2420 : TYPE(dbcsr_type) :: dbcsr_work
2421 : TYPE(dft_control_type), POINTER :: dft_control
2422 : TYPE(pw_c1d_gs_type) :: rhoz_tot_gspace, zv_hartree_gspace
2423 50 : TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rhoz_g
2424 : TYPE(pw_env_type), POINTER :: pw_env
2425 : TYPE(pw_poisson_type), POINTER :: poisson_env
2426 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
2427 : TYPE(pw_r3d_rs_type) :: zv_hartree_rspace
2428 50 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rhoz_r, tauz_r, v_xc, v_xc_tau
2429 : TYPE(qs_rho_type), POINTER :: rho, rho_aux_fit
2430 : TYPE(section_vals_type), POINTER :: hfx_section, xc_section
2431 : TYPE(task_list_type), POINTER :: task_list_aux_fit
2432 :
2433 50 : NULLIFY (pw_env, rhoz_r, rhoz_g, tauz_r, v_xc, v_xc_tau, &
2434 50 : poisson_env, auxbas_pw_pool, dft_control, admm_env, xc_section, rho, rho_aux_fit, &
2435 50 : task_list_aux_fit, ker_tau_admm, work_admm, dbcsr_p_work, matrix_s, hfx_section)
2436 :
2437 50 : CALL timeset(routineN, handle)
2438 :
2439 50 : CALL get_qs_env(qs_env, dft_control=dft_control, pw_env=pw_env, rho=rho, matrix_s=matrix_s)
2440 50 : CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, poisson_env=poisson_env)
2441 50 : nspins = dft_control%nspins
2442 :
2443 50 : CALL dbcsr_allocate_matrix_set(dbcsr_p_work, nspins)
2444 112 : DO ispin = 1, nspins
2445 62 : ALLOCATE (dbcsr_p_work(ispin)%matrix)
2446 62 : CALL dbcsr_create(matrix=dbcsr_p_work(ispin)%matrix, template=matrix_s(1)%matrix)
2447 62 : CALL dbcsr_copy(dbcsr_p_work(ispin)%matrix, matrix_s(1)%matrix)
2448 112 : CALL dbcsr_set(dbcsr_p_work(ispin)%matrix, 0.0_dp)
2449 : END DO
2450 :
2451 : !Apply the kernel on the density saved in force_data%sum_YP_tau
2452 374 : ALLOCATE (rhoz_r(nspins), rhoz_g(nspins))
2453 112 : DO ispin = 1, nspins
2454 62 : CALL auxbas_pw_pool%create_pw(rhoz_r(ispin))
2455 112 : CALL auxbas_pw_pool%create_pw(rhoz_g(ispin))
2456 : END DO
2457 50 : CALL auxbas_pw_pool%create_pw(rhoz_tot_gspace)
2458 50 : CALL auxbas_pw_pool%create_pw(zv_hartree_rspace)
2459 50 : CALL auxbas_pw_pool%create_pw(zv_hartree_gspace)
2460 :
2461 50 : CALL pw_zero(rhoz_tot_gspace)
2462 112 : DO ispin = 1, nspins
2463 : CALL calculate_rho_elec(ks_env=qs_env%ks_env, matrix_p=force_data%sum_YP_tau(ispin)%matrix, &
2464 62 : rho=rhoz_r(ispin), rho_gspace=rhoz_g(ispin))
2465 112 : CALL pw_axpy(rhoz_g(ispin), rhoz_tot_gspace)
2466 : END DO
2467 :
2468 : CALL pw_poisson_solve(poisson_env, rhoz_tot_gspace, ehartree, &
2469 50 : zv_hartree_gspace)
2470 :
2471 50 : CALL pw_transfer(zv_hartree_gspace, zv_hartree_rspace)
2472 50 : CALL pw_scale(zv_hartree_rspace, zv_hartree_rspace%pw_grid%dvol)
2473 :
2474 50 : CALL qs_rho_get(rho, tau_r_valid=do_tau)
2475 50 : IF (do_tau) THEN
2476 : BLOCK
2477 : TYPE(pw_c1d_gs_type) :: tauz_g
2478 24 : ALLOCATE (tauz_r(nspins))
2479 8 : CALL auxbas_pw_pool%create_pw(tauz_g)
2480 16 : DO ispin = 1, nspins
2481 8 : CALL auxbas_pw_pool%create_pw(tauz_r(ispin))
2482 :
2483 : CALL calculate_rho_elec(ks_env=qs_env%ks_env, matrix_p=force_data%sum_YP_tau(ispin)%matrix, &
2484 16 : rho=tauz_r(ispin), rho_gspace=tauz_g, compute_tau=.TRUE.)
2485 : END DO
2486 16 : CALL auxbas_pw_pool%give_back_pw(tauz_g)
2487 : END BLOCK
2488 : END IF
2489 :
2490 50 : IF (dft_control%do_admm) THEN
2491 16 : CALL get_qs_env(qs_env, admm_env=admm_env)
2492 16 : xc_section => admm_env%xc_section_primary
2493 : ELSE
2494 34 : xc_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC")
2495 : END IF
2496 :
2497 : !Primary XC kernel
2498 50 : CALL create_kernel(qs_env, v_xc, v_xc_tau, rho, rhoz_r, rhoz_g, tauz_r, xc_section)
2499 :
2500 112 : DO ispin = 1, nspins
2501 62 : CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2502 62 : CALL pw_axpy(zv_hartree_rspace, v_xc(ispin))
2503 : CALL integrate_v_rspace(qs_env=qs_env, &
2504 : v_rspace=v_xc(ispin), &
2505 : hmat=dbcsr_p_work(ispin), &
2506 62 : calculate_forces=.FALSE.)
2507 :
2508 112 : CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2509 : END DO
2510 50 : CALL auxbas_pw_pool%give_back_pw(rhoz_tot_gspace)
2511 50 : CALL auxbas_pw_pool%give_back_pw(zv_hartree_rspace)
2512 50 : CALL auxbas_pw_pool%give_back_pw(zv_hartree_gspace)
2513 50 : DEALLOCATE (v_xc)
2514 :
2515 50 : IF (do_tau) THEN
2516 16 : DO ispin = 1, nspins
2517 8 : CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2518 : CALL integrate_v_rspace(qs_env=qs_env, &
2519 : v_rspace=v_xc_tau(ispin), &
2520 : hmat=dbcsr_p_work(ispin), &
2521 : compute_tau=.TRUE., &
2522 8 : calculate_forces=.FALSE.)
2523 16 : CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2524 : END DO
2525 8 : DEALLOCATE (v_xc_tau)
2526 : END IF
2527 :
2528 : !Auxiliary xc kernel (admm)
2529 50 : IF (dft_control%do_admm) THEN
2530 16 : CALL get_qs_env(qs_env, admm_env=admm_env)
2531 : CALL get_admm_env(admm_env, matrix_s_aux_fit=matrix_s_aux, &
2532 16 : task_list_aux_fit=task_list_aux_fit, rho_aux_fit=rho_aux_fit)
2533 :
2534 16 : CALL qs_rho_get(rho_aux_fit, tau_r_valid=do_tau_admm)
2535 :
2536 16 : CALL dbcsr_allocate_matrix_set(work_admm, nspins)
2537 16 : CALL dbcsr_allocate_matrix_set(ker_tau_admm, nspins)
2538 36 : DO ispin = 1, nspins
2539 20 : ALLOCATE (work_admm(ispin)%matrix, ker_tau_admm(ispin)%matrix)
2540 20 : CALL dbcsr_create(work_admm(ispin)%matrix, template=matrix_s_aux(1)%matrix)
2541 20 : CALL dbcsr_copy(work_admm(ispin)%matrix, matrix_s_aux(1)%matrix)
2542 20 : CALL dbcsr_set(work_admm(ispin)%matrix, 0.0_dp)
2543 20 : CALL dbcsr_create(ker_tau_admm(ispin)%matrix, template=matrix_s_aux(1)%matrix)
2544 20 : CALL dbcsr_copy(ker_tau_admm(ispin)%matrix, matrix_s_aux(1)%matrix)
2545 36 : CALL dbcsr_set(ker_tau_admm(ispin)%matrix, 0.0_dp)
2546 : END DO
2547 :
2548 : !get the density in the auxuliary density
2549 16 : CPASSERT(ASSOCIATED(admm_env%work_orb_orb))
2550 16 : CPASSERT(ASSOCIATED(admm_env%work_aux_orb))
2551 16 : CPASSERT(ASSOCIATED(admm_env%work_aux_aux))
2552 16 : nao = admm_env%nao_orb
2553 16 : nao_aux = admm_env%nao_aux_fit
2554 36 : DO ispin = 1, nspins
2555 20 : CALL copy_dbcsr_to_fm(force_data%sum_YP_tau(ispin)%matrix, admm_env%work_orb_orb)
2556 : CALL parallel_gemm('N', 'N', nao_aux, nao, nao, 1.0_dp, admm_env%A, admm_env%work_orb_orb, &
2557 20 : 0.0_dp, admm_env%work_aux_orb)
2558 : CALL parallel_gemm('N', 'T', nao_aux, nao_aux, nao, 1.0_dp, admm_env%work_aux_orb, admm_env%A, &
2559 20 : 0.0_dp, admm_env%work_aux_aux)
2560 36 : CALL copy_fm_to_dbcsr(admm_env%work_aux_aux, ker_tau_admm(ispin)%matrix, keep_sparsity=.TRUE.)
2561 : END DO
2562 :
2563 16 : IF (.NOT. qs_env%admm_env%aux_exch_func == do_admm_aux_exch_func_none) THEN
2564 36 : DO ispin = 1, nspins
2565 20 : CALL pw_zero(rhoz_r(ispin))
2566 20 : CALL pw_zero(rhoz_g(ispin))
2567 : CALL calculate_rho_elec(ks_env=qs_env%ks_env, matrix_p=ker_tau_admm(ispin)%matrix, &
2568 : rho=rhoz_r(ispin), rho_gspace=rhoz_g(ispin), &
2569 36 : basis_type="AUX_FIT", task_list_external=task_list_aux_fit)
2570 : END DO
2571 :
2572 16 : IF (do_tau_admm) THEN
2573 : BLOCK
2574 : TYPE(pw_c1d_gs_type) :: tauz_g
2575 0 : CALL auxbas_pw_pool%create_pw(tauz_g)
2576 0 : DO ispin = 1, nspins
2577 0 : CALL pw_zero(tauz_r(ispin))
2578 : CALL calculate_rho_elec(ks_env=qs_env%ks_env, matrix_p=ker_tau_admm(ispin)%matrix, &
2579 : rho=tauz_r(ispin), rho_gspace=tauz_g, &
2580 : basis_type="AUX_FIT", task_list_external=task_list_aux_fit, &
2581 0 : compute_tau=.TRUE.)
2582 : END DO
2583 0 : CALL auxbas_pw_pool%give_back_pw(tauz_g)
2584 : END BLOCK
2585 : END IF
2586 :
2587 16 : xc_section => admm_env%xc_section_aux
2588 16 : CALL create_kernel(qs_env, v_xc, v_xc_tau, rho_aux_fit, rhoz_r, rhoz_g, tauz_r, xc_section)
2589 :
2590 36 : DO ispin = 1, nspins
2591 20 : CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
2592 : CALL integrate_v_rspace(qs_env=qs_env, &
2593 : v_rspace=v_xc(ispin), &
2594 : hmat=work_admm(ispin), &
2595 : calculate_forces=.FALSE., &
2596 : basis_type="AUX_FIT", &
2597 20 : task_list_external=task_list_aux_fit)
2598 36 : CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
2599 : END DO
2600 16 : DEALLOCATE (v_xc)
2601 :
2602 16 : IF (do_tau_admm) THEN
2603 0 : DO ispin = 1, nspins
2604 0 : CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
2605 : CALL integrate_v_rspace(qs_env=qs_env, &
2606 : v_rspace=v_xc_tau(ispin), &
2607 : hmat=work_admm(ispin), &
2608 : calculate_forces=.FALSE., &
2609 : basis_type="AUX_FIT", &
2610 : task_list_external=task_list_aux_fit, &
2611 0 : compute_tau=.TRUE.)
2612 0 : CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
2613 : END DO
2614 0 : DEALLOCATE (v_xc_tau)
2615 : END IF
2616 : END IF !admm
2617 : END IF
2618 :
2619 112 : DO ispin = 1, nspins
2620 62 : CALL auxbas_pw_pool%give_back_pw(rhoz_r(ispin))
2621 112 : CALL auxbas_pw_pool%give_back_pw(rhoz_g(ispin))
2622 : END DO
2623 50 : DEALLOCATE (rhoz_r, rhoz_g)
2624 :
2625 50 : IF (do_tau) THEN
2626 16 : DO ispin = 1, nspins
2627 16 : CALL auxbas_pw_pool%give_back_pw(tauz_r(ispin))
2628 : END DO
2629 8 : DEALLOCATE (tauz_r)
2630 : END IF
2631 :
2632 : !HFX kernel
2633 50 : hfx_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%HF")
2634 50 : CALL section_vals_get(hfx_section, explicit=do_hfx)
2635 50 : IF (do_hfx) THEN
2636 32 : IF (dft_control%do_admm) THEN
2637 16 : CALL tddft_hfx_matrix(work_admm, ker_tau_admm, qs_env, .FALSE., .FALSE.)
2638 :
2639 : !Going back to primary basis
2640 16 : CALL dbcsr_create(dbcsr_work, template=dbcsr_p_work(1)%matrix)
2641 16 : CALL dbcsr_copy(dbcsr_work, dbcsr_p_work(1)%matrix)
2642 16 : CALL dbcsr_set(dbcsr_work, 0.0_dp)
2643 36 : DO ispin = 1, nspins
2644 20 : CALL copy_dbcsr_to_fm(work_admm(ispin)%matrix, admm_env%work_aux_aux)
2645 : CALL parallel_gemm('N', 'N', nao_aux, nao, nao_aux, 1.0_dp, admm_env%work_aux_aux, admm_env%A, &
2646 20 : 0.0_dp, admm_env%work_aux_orb)
2647 : CALL parallel_gemm('T', 'N', nao, nao, nao_aux, 1.0_dp, admm_env%A, admm_env%work_aux_orb, &
2648 20 : 0.0_dp, admm_env%work_orb_orb)
2649 20 : CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, dbcsr_work, keep_sparsity=.TRUE.)
2650 36 : CALL dbcsr_add(dbcsr_p_work(ispin)%matrix, dbcsr_work, 1.0_dp, 1.0_dp)
2651 : END DO
2652 16 : CALL dbcsr_release(dbcsr_work)
2653 16 : CALL dbcsr_deallocate_matrix_set(ker_tau_admm)
2654 : ELSE
2655 16 : CALL tddft_hfx_matrix(dbcsr_p_work, force_data%sum_YP_tau, qs_env, .FALSE., .FALSE.)
2656 : END IF
2657 : END IF
2658 :
2659 112 : DO ispin = 1, nspins
2660 112 : CALL dbcsr_add(force_data%sum_O_tau(ispin)%matrix, dbcsr_p_work(ispin)%matrix, 1.0_dp, 1.0_dp)
2661 : END DO
2662 :
2663 50 : CALL dbcsr_deallocate_matrix_set(dbcsr_p_work)
2664 50 : CALL dbcsr_deallocate_matrix_set(work_admm)
2665 :
2666 50 : CALL timestop(handle)
2667 :
2668 200 : END SUBROUTINE prepare_for_response
2669 :
2670 : ! **************************************************************************************************
2671 : !> \brief Calculate the force and virial due to the (P|Q) GPW integral derivatives
2672 : !> \param G_PQ ...
2673 : !> \param force ...
2674 : !> \param h_stress ...
2675 : !> \param use_virial ...
2676 : !> \param mp2_env ...
2677 : !> \param qs_env ...
2678 : ! **************************************************************************************************
2679 12 : SUBROUTINE get_2c_gpw_forces(G_PQ, force, h_stress, use_virial, mp2_env, qs_env)
2680 :
2681 : TYPE(dbcsr_type), INTENT(INOUT) :: G_PQ
2682 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
2683 : REAL(dp), DIMENSION(3, 3), INTENT(INOUT) :: h_stress
2684 : LOGICAL, INTENT(IN) :: use_virial
2685 : TYPE(mp2_type), INTENT(INOUT) :: mp2_env
2686 : TYPE(qs_environment_type), POINTER :: qs_env
2687 :
2688 : CHARACTER(len=*), PARAMETER :: routineN = 'get_2c_gpw_forces'
2689 :
2690 : INTEGER :: atom_a, color, handle, i, i_RI, i_xyz, iatom, igrid_level, ikind, ipgf, iset, j, &
2691 : j_RI, jatom, lb_RI, n_RI, natom, ncoa, ncoms, nkind, nproc, nseta, o1, offset, pdims(2), &
2692 : sgfa, ub_RI
2693 24 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, iproc_map, kind_of, &
2694 12 : sizes_RI
2695 24 : INTEGER, DIMENSION(:), POINTER :: col_dist, la_max, la_min, npgfa, nsgfa, &
2696 12 : row_dist
2697 12 : INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, pgrid
2698 : LOGICAL :: found, one_proc_group
2699 : REAL(dp) :: cutoff_old, radius, relative_cutoff_old
2700 12 : REAL(dp), ALLOCATABLE, DIMENSION(:) :: e_cutoff_old, wf_vector
2701 : REAL(dp), DIMENSION(3) :: force_a, force_b, ra
2702 : REAL(dp), DIMENSION(3, 3) :: my_virial_a, my_virial_b
2703 12 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: h_tmp, I_ab, pab, pblock, sphi_a, zeta
2704 12 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2705 : TYPE(cell_type), POINTER :: cell
2706 : TYPE(dbcsr_distribution_type) :: dbcsr_dist
2707 : TYPE(dbcsr_type) :: tmp_G_PQ
2708 : TYPE(dft_control_type), POINTER :: dft_control
2709 : TYPE(gto_basis_set_p_type), ALLOCATABLE, &
2710 12 : DIMENSION(:), TARGET :: basis_set_ri_aux
2711 : TYPE(gto_basis_set_type), POINTER :: basis_set_a
2712 12 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
2713 : TYPE(mp_para_env_type), POINTER :: para_env, para_env_ext
2714 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
2715 12 : POINTER :: sab_orb
2716 12 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
2717 48 : TYPE(pw_c1d_gs_type) :: dvg(3), pot_g, rho_g, rho_g_copy
2718 : TYPE(pw_env_type), POINTER :: pw_env_ext
2719 : TYPE(pw_poisson_type), POINTER :: poisson_env
2720 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
2721 : TYPE(pw_r3d_rs_type) :: psi_L, rho_r
2722 12 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
2723 12 : TYPE(realspace_grid_type), DIMENSION(:), POINTER :: rs_v
2724 : TYPE(task_list_type), POINTER :: task_list_ext
2725 :
2726 12 : NULLIFY (sab_orb, task_list_ext, particle_set, qs_kind_set, dft_control, pw_env_ext, auxbas_pw_pool, &
2727 12 : poisson_env, atomic_kind_set, para_env, cell, rs_v, mos, basis_set_a)
2728 :
2729 12 : CALL timeset(routineN, handle)
2730 :
2731 : CALL get_qs_env(qs_env, dft_control=dft_control, para_env=para_env, sab_orb=sab_orb, &
2732 : natom=natom, nkind=nkind, qs_kind_set=qs_kind_set, particle_set=particle_set, &
2733 12 : mos=mos, cell=cell, atomic_kind_set=atomic_kind_set)
2734 :
2735 : !The idea is to use GPW to compute the integrals and derivatives. Because the potential needs
2736 : !to be calculated for each phi_j (column) of all AO pairs, and because that is expensive, we want
2737 : !to minimize the amount of time we do that. Therefore, we work with a special distribution, where
2738 : !each column of the resulting DBCSR matrix is mapped to a sub-communicator.
2739 :
2740 : !Try to get the optimal pdims (we want a grid that is flat: many cols, few rows)
2741 12 : IF (para_env%num_pe <= natom) THEN
2742 : pdims(1) = 1
2743 : pdims(2) = para_env%num_pe
2744 : ELSE
2745 0 : DO i = natom, 1, -1
2746 0 : IF (MODULO(para_env%num_pe, i) == 0) THEN
2747 0 : pdims(1) = para_env%num_pe/i
2748 0 : pdims(2) = i
2749 0 : EXIT
2750 : END IF
2751 : END DO
2752 : END IF
2753 :
2754 48 : ALLOCATE (row_dist(natom), col_dist(natom))
2755 48 : DO iatom = 1, natom
2756 48 : row_dist(iatom) = MODULO(iatom, pdims(1))
2757 : END DO
2758 48 : DO jatom = 1, natom
2759 48 : col_dist(jatom) = MODULO(jatom, pdims(2))
2760 : END DO
2761 :
2762 48 : ALLOCATE (pgrid(0:pdims(1) - 1, 0:pdims(2) - 1))
2763 12 : nproc = 0
2764 24 : DO i = 0, pdims(1) - 1
2765 48 : DO j = 0, pdims(2) - 1
2766 24 : pgrid(i, j) = nproc
2767 36 : nproc = nproc + 1
2768 : END DO
2769 : END DO
2770 :
2771 12 : CALL dbcsr_distribution_new(dbcsr_dist, group=para_env%get_handle(), pgrid=pgrid, row_dist=row_dist, col_dist=col_dist)
2772 :
2773 : !The temporary DBCSR integrals and derivatives matrices in this flat distribution
2774 12 : CALL dbcsr_create(tmp_G_PQ, template=G_PQ, matrix_type=dbcsr_type_no_symmetry, dist=dbcsr_dist)
2775 12 : CALL dbcsr_complete_redistribute(G_PQ, tmp_G_PQ)
2776 :
2777 84 : ALLOCATE (basis_set_ri_aux(nkind), sizes_RI(natom))
2778 12 : CALL basis_set_list_setup(basis_set_ri_aux, "RI_AUX", qs_kind_set)
2779 12 : CALL get_particle_set(particle_set, qs_kind_set, nsgf=sizes_RI, basis=basis_set_ri_aux)
2780 48 : n_RI = SUM(sizes_RI)
2781 :
2782 12 : one_proc_group = mp2_env%mp2_num_proc == 1
2783 12 : ALLOCATE (para_env_ext)
2784 12 : IF (one_proc_group) THEN
2785 : !one subgroup per proc
2786 4 : CALL para_env_ext%from_split(para_env, para_env%mepos)
2787 : ELSE
2788 : !Split the communicator accross the columns of the matrix
2789 8 : ncoms = MIN(pdims(2), para_env%num_pe/mp2_env%mp2_num_proc)
2790 16 : DO i = 0, pdims(1) - 1
2791 32 : DO j = 0, pdims(2) - 1
2792 24 : IF (pgrid(i, j) == para_env%mepos) color = MODULO(j + 1, ncoms)
2793 : END DO
2794 : END DO
2795 8 : CALL para_env_ext%from_split(para_env, color)
2796 : END IF
2797 :
2798 : !sab_orb and task_list_ext are essentially dummies
2799 : CALL prepare_gpw(qs_env, dft_control, e_cutoff_old, cutoff_old, relative_cutoff_old, para_env_ext, pw_env_ext, &
2800 12 : auxbas_pw_pool, poisson_env, task_list_ext, rho_r, rho_g, pot_g, psi_L, sab_orb)
2801 :
2802 12 : IF (use_virial) THEN
2803 4 : CALL auxbas_pw_pool%create_pw(rho_g_copy)
2804 16 : DO i_xyz = 1, 3
2805 16 : CALL auxbas_pw_pool%create_pw(dvg(i_xyz))
2806 : END DO
2807 : END IF
2808 :
2809 36 : ALLOCATE (wf_vector(n_RI))
2810 :
2811 12 : CALL get_atomic_kind_set(atomic_kind_set, kind_of=kind_of, atom_of_kind=atom_of_kind)
2812 :
2813 36 : ALLOCATE (iproc_map(natom))
2814 :
2815 : !Loop over the atomic blocks
2816 48 : DO jatom = 1, natom
2817 :
2818 : !Only calculate if on the correct sub-communicator/proc
2819 36 : IF (one_proc_group) THEN
2820 48 : iproc_map = 0
2821 48 : DO iatom = 1, natom
2822 48 : IF (pgrid(row_dist(iatom), col_dist(jatom)) == para_env%mepos) iproc_map(iatom) = 1
2823 : END DO
2824 30 : IF (.NOT. ANY(iproc_map == 1)) CYCLE
2825 : ELSE
2826 24 : IF (.NOT. MODULO(col_dist(jatom) + 1, ncoms) == color) CYCLE
2827 : END IF
2828 :
2829 60 : lb_RI = SUM(sizes_RI(1:jatom - 1))
2830 30 : ub_RI = lb_RI + sizes_RI(jatom)
2831 872 : DO j_RI = lb_RI + 1, ub_RI
2832 :
2833 69720 : wf_vector = 0.0_dp
2834 830 : wf_vector(j_RI) = 1.0_dp
2835 :
2836 : CALL collocate_function(wf_vector, psi_L, rho_g, atomic_kind_set, qs_kind_set, cell, &
2837 : particle_set, pw_env_ext, dft_control%qs_control%eps_rho_rspace, &
2838 830 : basis_type="RI_AUX")
2839 :
2840 830 : IF (use_virial) THEN
2841 166 : CALL calc_potential_gpw(rho_r, rho_g, poisson_env, pot_g, mp2_env%potential_parameter, dvg)
2842 :
2843 13944 : wf_vector = 0.0_dp
2844 664 : DO iatom = 1, natom
2845 : !only compute if i,j atom pair on correct proc
2846 498 : IF (one_proc_group) THEN
2847 498 : IF (.NOT. iproc_map(iatom) == 1) CYCLE
2848 : END IF
2849 :
2850 498 : CALL dbcsr_get_block_p(tmp_G_PQ, iatom, jatom, pblock, found)
2851 498 : IF (.NOT. found) CYCLE
2852 :
2853 996 : i_RI = SUM(sizes_RI(1:iatom - 1))
2854 14940 : wf_vector(i_RI + 1:i_RI + sizes_RI(iatom)) = pblock(:, j_RI - lb_RI)
2855 : END DO
2856 :
2857 166 : CALL pw_copy(rho_g, rho_g_copy)
2858 : CALL collocate_function(wf_vector, psi_L, rho_g, atomic_kind_set, qs_kind_set, cell, &
2859 : particle_set, pw_env_ext, dft_control%qs_control%eps_rho_rspace, &
2860 166 : basis_type="RI_AUX")
2861 :
2862 : CALL calc_potential_gpw(psi_L, rho_g, poisson_env, pot_g, mp2_env%potential_parameter, &
2863 166 : no_transfer=.TRUE.)
2864 : CALL virial_gpw_potential(rho_g_copy, pot_g, rho_g, dvg, h_stress, &
2865 166 : mp2_env%potential_parameter, para_env_ext)
2866 : ELSE
2867 664 : CALL calc_potential_gpw(rho_r, rho_g, poisson_env, pot_g, mp2_env%potential_parameter)
2868 : END IF
2869 :
2870 830 : NULLIFY (rs_v)
2871 830 : CALL pw_env_get(pw_env_ext, rs_grids=rs_v)
2872 830 : CALL potential_pw2rs(rs_v, rho_r, pw_env_ext)
2873 :
2874 3356 : DO iatom = 1, natom
2875 :
2876 : !only compute if i,j atom pair on correct proc
2877 2490 : IF (one_proc_group) THEN
2878 498 : IF (.NOT. iproc_map(iatom) == 1) CYCLE
2879 : END IF
2880 :
2881 2490 : force_a(:) = 0.0_dp
2882 2490 : force_b(:) = 0.0_dp
2883 2490 : IF (use_virial) THEN
2884 498 : my_virial_a = 0.0_dp
2885 498 : my_virial_b = 0.0_dp
2886 : END IF
2887 :
2888 2490 : ikind = kind_of(iatom)
2889 2490 : atom_a = atom_of_kind(iatom)
2890 :
2891 2490 : basis_set_a => basis_set_ri_aux(ikind)%gto_basis_set
2892 2490 : first_sgfa => basis_set_a%first_sgf
2893 2490 : la_max => basis_set_a%lmax
2894 2490 : la_min => basis_set_a%lmin
2895 2490 : nseta = basis_set_a%nset
2896 2490 : nsgfa => basis_set_a%nsgf_set
2897 2490 : sphi_a => basis_set_a%sphi
2898 2490 : zeta => basis_set_a%zet
2899 2490 : npgfa => basis_set_a%npgf
2900 :
2901 2490 : ra(:) = pbc(particle_set(iatom)%r, cell)
2902 :
2903 2490 : CALL dbcsr_get_block_p(tmp_G_PQ, iatom, jatom, pblock, found)
2904 2490 : IF (.NOT. found) CYCLE
2905 :
2906 : offset = 0
2907 15936 : DO iset = 1, nseta
2908 14442 : ncoa = npgfa(iset)*ncoset(la_max(iset))
2909 14442 : sgfa = first_sgfa(1, iset)
2910 :
2911 131472 : ALLOCATE (h_tmp(ncoa, 1)); h_tmp = 0.0_dp
2912 99102 : ALLOCATE (I_ab(nsgfa(iset), 1)); I_ab = 0.0_dp
2913 117030 : ALLOCATE (pab(ncoa, 1)); pab = 0.0_dp
2914 :
2915 97110 : I_ab(1:nsgfa(iset), 1) = 2.0_dp*pblock(offset + 1:offset + nsgfa(iset), j_RI - lb_RI)
2916 : CALL dgemm("N", "N", ncoa, 1, nsgfa(iset), 1.0_dp, sphi_a(1, sgfa), SIZE(sphi_a, 1), &
2917 14442 : I_ab(1, 1), nsgfa(iset), 0.0_dp, pab(1, 1), ncoa)
2918 :
2919 43326 : igrid_level = gaussian_gridlevel(pw_env_ext%gridlevel_info, MINVAL(zeta(:, iset)))
2920 :
2921 : ! The last three parameters are used to check whether a given function is within the own range.
2922 : ! Here, it is always the case, so let's enforce it because mod(0, 1)==0
2923 14442 : IF (map_gaussian_here(rs_v(igrid_level), cell%h_inv, ra, 0, 1, 0)) THEN
2924 28884 : DO ipgf = 1, npgfa(iset)
2925 14442 : o1 = (ipgf - 1)*ncoset(la_max(iset))
2926 14442 : igrid_level = gaussian_gridlevel(pw_env_ext%gridlevel_info, zeta(ipgf, iset))
2927 :
2928 : radius = exp_radius_very_extended(la_min=la_min(iset), la_max=la_max(iset), &
2929 : lb_min=0, lb_max=0, ra=ra, rb=ra, rp=ra, &
2930 : zetp=zeta(ipgf, iset), &
2931 : eps=dft_control%qs_control%eps_gvg_rspace, &
2932 14442 : prefactor=1.0_dp, cutoff=1.0_dp)
2933 :
2934 : CALL integrate_pgf_product( &
2935 : la_max=la_max(iset), zeta=zeta(ipgf, iset), la_min=la_min(iset), &
2936 : lb_max=0, zetb=0.0_dp, lb_min=0, &
2937 : ra=ra, rab=(/0.0_dp, 0.0_dp, 0.0_dp/), &
2938 : rsgrid=rs_v(igrid_level), &
2939 : hab=h_tmp, pab=pab, &
2940 : o1=o1, &
2941 : o2=0, &
2942 : radius=radius, &
2943 : calculate_forces=.TRUE., &
2944 : force_a=force_a, force_b=force_b, &
2945 28884 : use_virial=use_virial, my_virial_a=my_virial_a, my_virial_b=my_virial_b)
2946 :
2947 : END DO
2948 :
2949 : END IF
2950 :
2951 14442 : offset = offset + nsgfa(iset)
2952 15936 : DEALLOCATE (pab, h_tmp, I_ab)
2953 : END DO !iset
2954 :
2955 5976 : force(ikind)%mp2_non_sep(:, atom_a) = force(ikind)%mp2_non_sep(:, atom_a) + force_a + force_b
2956 10790 : IF (use_virial) h_stress = h_stress + my_virial_a + my_virial_b
2957 :
2958 : END DO !iatom
2959 : END DO !j_RI
2960 : END DO !jatom
2961 :
2962 12 : IF (use_virial) THEN
2963 4 : CALL auxbas_pw_pool%give_back_pw(rho_g_copy)
2964 16 : DO i_xyz = 1, 3
2965 16 : CALL auxbas_pw_pool%give_back_pw(dvg(i_xyz))
2966 : END DO
2967 : END IF
2968 :
2969 : CALL cleanup_gpw(qs_env, e_cutoff_old, cutoff_old, relative_cutoff_old, para_env_ext, pw_env_ext, &
2970 12 : task_list_ext, auxbas_pw_pool, rho_r, rho_g, pot_g, psi_L)
2971 :
2972 12 : CALL dbcsr_release(tmp_G_PQ)
2973 12 : CALL dbcsr_distribution_release(dbcsr_dist)
2974 12 : DEALLOCATE (col_dist, row_dist, pgrid)
2975 :
2976 12 : CALL mp_para_env_release(para_env_ext)
2977 :
2978 12 : CALL timestop(handle)
2979 :
2980 48 : END SUBROUTINE get_2c_gpw_forces
2981 :
2982 : ! **************************************************************************************************
2983 : !> \brief Calculate the forces due to the (P|Q) MME integral derivatives
2984 : !> \param G_PQ ...
2985 : !> \param force ...
2986 : !> \param mp2_env ...
2987 : !> \param qs_env ...
2988 : ! **************************************************************************************************
2989 16 : SUBROUTINE get_2c_mme_forces(G_PQ, force, mp2_env, qs_env)
2990 :
2991 : TYPE(dbcsr_type), INTENT(INOUT) :: G_PQ
2992 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
2993 : TYPE(mp2_type), INTENT(INOUT) :: mp2_env
2994 : TYPE(qs_environment_type), POINTER :: qs_env
2995 :
2996 : CHARACTER(len=*), PARAMETER :: routineN = 'get_2c_mme_forces'
2997 :
2998 : INTEGER :: atom_a, atom_b, G_count, handle, i_xyz, iatom, ikind, iset, jatom, jkind, jset, &
2999 : natom, nkind, nseta, nsetb, offset_hab_a, offset_hab_b, R_count, sgfa, sgfb
3000 16 : INTEGER, ALLOCATABLE, DIMENSION(:) :: atom_of_kind, kind_of
3001 16 : INTEGER, DIMENSION(:), POINTER :: la_max, la_min, lb_max, lb_min, npgfa, &
3002 16 : npgfb, nsgfa, nsgfb
3003 16 : INTEGER, DIMENSION(:, :), POINTER :: first_sgfa, first_sgfb
3004 : LOGICAL :: found
3005 : REAL(dp) :: new_force, pref
3006 16 : REAL(dp), ALLOCATABLE, DIMENSION(:, :) :: hab
3007 16 : REAL(dp), ALLOCATABLE, DIMENSION(:, :, :) :: hdab
3008 16 : REAL(dp), DIMENSION(:, :), POINTER :: pblock
3009 : REAL(KIND=dp), DIMENSION(3) :: ra, rb
3010 16 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: sphi_a, sphi_b, zeta, zetb
3011 16 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
3012 : TYPE(cell_type), POINTER :: cell
3013 : TYPE(dbcsr_iterator_type) :: iter
3014 : TYPE(gto_basis_set_p_type), ALLOCATABLE, &
3015 16 : DIMENSION(:), TARGET :: basis_set_ri_aux
3016 : TYPE(gto_basis_set_type), POINTER :: basis_set_a, basis_set_b
3017 : TYPE(mp_para_env_type), POINTER :: para_env
3018 16 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
3019 16 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
3020 :
3021 16 : NULLIFY (qs_kind_set, basis_set_a, basis_set_b, pblock, particle_set, &
3022 16 : cell, la_max, la_min, lb_min, npgfa, lb_max, npgfb, nsgfa, &
3023 16 : nsgfb, first_sgfa, first_sgfb, sphi_a, sphi_b, zeta, zetb, &
3024 16 : atomic_kind_set, para_env)
3025 :
3026 16 : CALL timeset(routineN, handle)
3027 :
3028 : CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, nkind=nkind, particle_set=particle_set, &
3029 16 : cell=cell, atomic_kind_set=atomic_kind_set, natom=natom, para_env=para_env)
3030 :
3031 16 : CALL get_atomic_kind_set(atomic_kind_set, kind_of=kind_of, atom_of_kind=atom_of_kind)
3032 :
3033 80 : ALLOCATE (basis_set_ri_aux(nkind))
3034 16 : CALL basis_set_list_setup(basis_set_ri_aux, "RI_AUX", qs_kind_set)
3035 :
3036 16 : G_count = 0; R_count = 0
3037 :
3038 16 : CALL dbcsr_iterator_start(iter, G_PQ)
3039 116 : DO WHILE (dbcsr_iterator_blocks_left(iter))
3040 :
3041 100 : CALL dbcsr_iterator_next_block(iter, row=iatom, column=jatom)
3042 100 : CALL dbcsr_get_block_p(G_PQ, iatom, jatom, pblock, found)
3043 100 : IF (.NOT. found) CYCLE
3044 100 : IF (iatom > jatom) CYCLE
3045 64 : pref = 2.0_dp
3046 64 : IF (iatom == jatom) pref = 1.0_dp
3047 :
3048 64 : ikind = kind_of(iatom)
3049 64 : jkind = kind_of(jatom)
3050 :
3051 64 : atom_a = atom_of_kind(iatom)
3052 64 : atom_b = atom_of_kind(jatom)
3053 :
3054 64 : basis_set_a => basis_set_ri_aux(ikind)%gto_basis_set
3055 64 : first_sgfa => basis_set_a%first_sgf
3056 64 : la_max => basis_set_a%lmax
3057 64 : la_min => basis_set_a%lmin
3058 64 : nseta = basis_set_a%nset
3059 64 : nsgfa => basis_set_a%nsgf_set
3060 64 : sphi_a => basis_set_a%sphi
3061 64 : zeta => basis_set_a%zet
3062 64 : npgfa => basis_set_a%npgf
3063 :
3064 64 : basis_set_b => basis_set_ri_aux(jkind)%gto_basis_set
3065 64 : first_sgfb => basis_set_b%first_sgf
3066 64 : lb_max => basis_set_b%lmax
3067 64 : lb_min => basis_set_b%lmin
3068 64 : nsetb = basis_set_b%nset
3069 64 : nsgfb => basis_set_b%nsgf_set
3070 64 : sphi_b => basis_set_b%sphi
3071 64 : zetb => basis_set_b%zet
3072 64 : npgfb => basis_set_b%npgf
3073 :
3074 64 : ra(:) = pbc(particle_set(iatom)%r, cell)
3075 64 : rb(:) = pbc(particle_set(jatom)%r, cell)
3076 :
3077 256 : ALLOCATE (hab(basis_set_a%nsgf, basis_set_b%nsgf))
3078 256 : ALLOCATE (hdab(3, basis_set_a%nsgf, basis_set_b%nsgf))
3079 47944 : hab(:, :) = 0.0_dp
3080 187912 : hdab(:, :, :) = 0.0_dp
3081 :
3082 64 : offset_hab_a = 0
3083 756 : DO iset = 1, nseta
3084 692 : sgfa = first_sgfa(1, iset)
3085 :
3086 692 : offset_hab_b = 0
3087 6340 : DO jset = 1, nsetb
3088 5648 : sgfb = first_sgfb(1, jset)
3089 :
3090 : CALL integrate_set_2c(mp2_env%eri_mme_param%par, mp2_env%potential_parameter, la_min(iset), &
3091 : la_max(iset), lb_min(jset), lb_max(jset), npgfa(iset), npgfb(jset), &
3092 : zeta(:, iset), zetb(:, jset), ra, rb, hab, nsgfa(iset), nsgfb(jset), &
3093 : offset_hab_a, offset_hab_b, 0, 0, sphi_a, sphi_b, sgfa, sgfb, &
3094 : nsgfa(iset), nsgfb(jset), do_eri_mme, hdab=hdab, &
3095 5648 : G_count=G_count, R_count=R_count)
3096 :
3097 6340 : offset_hab_b = offset_hab_b + nsgfb(jset)
3098 : END DO
3099 756 : offset_hab_a = offset_hab_a + nsgfa(iset)
3100 : END DO
3101 :
3102 256 : DO i_xyz = 1, 3
3103 143832 : new_force = pref*SUM(pblock(:, :)*hdab(i_xyz, :, :))
3104 192 : force(ikind)%mp2_non_sep(i_xyz, atom_a) = force(ikind)%mp2_non_sep(i_xyz, atom_a) + new_force
3105 256 : force(jkind)%mp2_non_sep(i_xyz, atom_b) = force(jkind)%mp2_non_sep(i_xyz, atom_b) - new_force
3106 : END DO
3107 :
3108 216 : DEALLOCATE (hab, hdab)
3109 : END DO
3110 16 : CALL dbcsr_iterator_stop(iter)
3111 :
3112 16 : CALL cp_eri_mme_update_local_counts(mp2_env%eri_mme_param, para_env, G_count_2c=G_count, R_count_2c=R_count)
3113 :
3114 16 : CALL timestop(handle)
3115 :
3116 48 : END SUBROUTINE get_2c_mme_forces
3117 :
3118 : ! **************************************************************************************************
3119 : !> \brief This routines gather all the force updates due to the response density and the trace with F
3120 : !> Also update the forces due to the SCF density for XC and exact exchange
3121 : !> \param p_env the p_env coming from the response calculation
3122 : !> \param matrix_hz the matrix going into the RHS of the response equation
3123 : !> \param matrix_p_F the density matrix with which we evaluate Trace[P*F]
3124 : !> \param matrix_p_F_admm ...
3125 : !> \param qs_env ...
3126 : !> \note very much inspired from the response_force routine in response_solver.F, especially for virial
3127 : ! **************************************************************************************************
3128 50 : SUBROUTINE update_im_time_forces(p_env, matrix_hz, matrix_p_F, matrix_p_F_admm, qs_env)
3129 :
3130 : TYPE(qs_p_env_type), POINTER :: p_env
3131 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_hz, matrix_p_F, matrix_p_F_admm
3132 : TYPE(qs_environment_type), POINTER :: qs_env
3133 :
3134 : CHARACTER(len=*), PARAMETER :: routineN = 'update_im_time_forces'
3135 :
3136 : INTEGER :: handle, i, idens, ispin, n_rep_hf, nao, &
3137 : nao_aux, nder, nimages, nocc, nspins
3138 50 : INTEGER, DIMENSION(:, :, :), POINTER :: cell_to_index
3139 : LOGICAL :: do_exx, do_hfx, do_tau, do_tau_admm, &
3140 : use_virial
3141 : REAL(dp) :: dummy_real1, dummy_real2, ehartree, &
3142 : eps_ppnl, exc, focc
3143 : REAL(dp), DIMENSION(3, 3) :: h_stress, pv_loc
3144 : TYPE(admm_type), POINTER :: admm_env
3145 50 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
3146 50 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: current_density, current_density_admm, &
3147 50 : current_mat_h, matrix_p_mp2, matrix_p_mp2_admm, matrix_s, matrix_s_aux_fit, matrix_w, &
3148 50 : rho_ao, rho_ao_aux, scrm, scrm_admm
3149 50 : TYPE(dbcsr_p_type), DIMENSION(:, :), POINTER :: dbcsr_work_h, dbcsr_work_p
3150 : TYPE(dbcsr_type) :: dbcsr_work
3151 : TYPE(dft_control_type), POINTER :: dft_control
3152 50 : TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data
3153 50 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
3154 : TYPE(mp_para_env_type), POINTER :: para_env
3155 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
3156 50 : POINTER :: sab_orb, sac_ae, sac_ppl, sap_ppnl
3157 50 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
3158 : TYPE(pw_c1d_gs_type) :: rho_tot_gspace, rhoz_tot_gspace, &
3159 : zv_hartree_gspace
3160 50 : TYPE(pw_c1d_gs_type), DIMENSION(:), POINTER :: rhoz_g
3161 : TYPE(pw_env_type), POINTER :: pw_env
3162 : TYPE(pw_poisson_type), POINTER :: poisson_env
3163 : TYPE(pw_pool_type), POINTER :: auxbas_pw_pool
3164 : TYPE(pw_r3d_rs_type) :: vh_rspace, vhxc_rspace, zv_hartree_rspace
3165 50 : TYPE(pw_r3d_rs_type), DIMENSION(:), POINTER :: rhoz_r, tauz_r, v_xc, v_xc_tau, &
3166 50 : vadmm_rspace, vtau_rspace, vxc_rspace
3167 50 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
3168 50 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
3169 : TYPE(qs_rho_type), POINTER :: rho, rho_aux_fit
3170 : TYPE(section_vals_type), POINTER :: hfx_section, xc_section
3171 : TYPE(task_list_type), POINTER :: task_list_aux_fit
3172 : TYPE(virial_type), POINTER :: virial
3173 :
3174 50 : NULLIFY (scrm, rho, dft_control, matrix_p_mp2, matrix_s, matrix_p_mp2_admm, admm_env, sab_orb, &
3175 50 : cell_to_index, dbcsr_work_p, dbcsr_work_h, sac_ae, sac_ppl, sap_ppnl, force, virial, &
3176 50 : qs_kind_set, atomic_kind_set, particle_set, pw_env, poisson_env, auxbas_pw_pool, &
3177 50 : task_list_aux_fit, matrix_s_aux_fit, scrm_admm, rho_aux_fit, rho_ao_aux, x_data, &
3178 50 : hfx_section, xc_section, para_env, rhoz_g, rhoz_r, tauz_r, v_xc, v_xc_tau, &
3179 50 : vxc_rspace, vtau_rspace, vadmm_rspace, rho_ao, matrix_w)
3180 :
3181 50 : CALL timeset(routineN, handle)
3182 :
3183 : CALL get_qs_env(qs_env, rho=rho, dft_control=dft_control, matrix_s=matrix_s, admm_env=admm_env, &
3184 : sab_orb=sab_orb, sac_ae=sac_ae, sac_ppl=sac_ppl, sap_ppnl=sap_ppnl, force=force, &
3185 : virial=virial, particle_set=particle_set, qs_kind_set=qs_kind_set, &
3186 50 : atomic_kind_set=atomic_kind_set, x_data=x_data, para_env=para_env)
3187 50 : nspins = dft_control%nspins
3188 :
3189 50 : use_virial = virial%pv_availability .AND. (.NOT. virial%pv_numer)
3190 50 : IF (use_virial) virial%pv_calculate = .TRUE.
3191 :
3192 : !Whether we replace the force/energy of SCF XC with HF in RPA
3193 50 : do_exx = .FALSE.
3194 50 : IF (qs_env%mp2_env%method == ri_rpa_method_gpw) THEN
3195 28 : hfx_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION%RI_RPA%HF")
3196 28 : CALL section_vals_get(hfx_section, explicit=do_exx)
3197 : END IF
3198 :
3199 : !Get the mp2 density matrix which is p_env%p1 + matrix_p_F
3200 50 : CALL get_qs_env(qs_env, matrix_p_mp2=matrix_p_mp2, matrix_p_mp2_admm=matrix_p_mp2_admm)
3201 :
3202 : !The kinetic term (only response density)
3203 50 : NULLIFY (scrm)
3204 50 : IF (nspins == 2) CALL dbcsr_add(matrix_p_mp2(1)%matrix, matrix_p_mp2(2)%matrix, 1.0_dp, 1.0_dp)
3205 : CALL build_kinetic_matrix(qs_env%ks_env, matrix_t=scrm, &
3206 : matrix_name="KINETIC ENERGY MATRIX", &
3207 : basis_type="ORB", &
3208 : sab_nl=sab_orb, calculate_forces=.TRUE., &
3209 50 : matrix_p=matrix_p_mp2(1)%matrix)
3210 50 : IF (nspins == 2) CALL dbcsr_add(matrix_p_mp2(1)%matrix, matrix_p_mp2(2)%matrix, 1.0_dp, -1.0_dp)
3211 50 : CALL dbcsr_deallocate_matrix_set(scrm)
3212 :
3213 : !The pseudo-potential terms (only reponse density)
3214 50 : CALL dbcsr_allocate_matrix_set(scrm, nspins)
3215 112 : DO ispin = 1, nspins
3216 62 : ALLOCATE (scrm(ispin)%matrix)
3217 62 : CALL dbcsr_create(scrm(ispin)%matrix, template=matrix_s(1)%matrix)
3218 62 : CALL dbcsr_copy(scrm(ispin)%matrix, matrix_s(1)%matrix)
3219 112 : CALL dbcsr_set(scrm(ispin)%matrix, 0.0_dp)
3220 : END DO
3221 :
3222 50 : nder = 1
3223 50 : nimages = 1
3224 50 : NULLIFY (cell_to_index)
3225 424 : ALLOCATE (dbcsr_work_p(nspins, 1), dbcsr_work_h(nspins, 1))
3226 112 : DO ispin = 1, nspins
3227 62 : dbcsr_work_p(ispin, 1)%matrix => matrix_p_mp2(ispin)%matrix
3228 112 : dbcsr_work_h(ispin, 1)%matrix => scrm(ispin)%matrix
3229 : END DO
3230 :
3231 50 : IF (ASSOCIATED(sac_ae)) THEN
3232 : CALL build_core_ae(dbcsr_work_h, dbcsr_work_p, force, &
3233 : virial, .TRUE., use_virial, nder, &
3234 : qs_kind_set, atomic_kind_set, particle_set, &
3235 0 : sab_orb, sac_ae, nimages, cell_to_index)
3236 : END IF
3237 :
3238 50 : IF (ASSOCIATED(sac_ppl)) THEN
3239 : CALL build_core_ppl(dbcsr_work_h, dbcsr_work_p, force, &
3240 : virial, .TRUE., use_virial, nder, &
3241 : qs_kind_set, atomic_kind_set, particle_set, &
3242 50 : sab_orb, sac_ppl, nimages, cell_to_index, "ORB")
3243 : END IF
3244 :
3245 50 : IF (ASSOCIATED(sap_ppnl)) THEN
3246 50 : eps_ppnl = dft_control%qs_control%eps_ppnl
3247 : CALL build_core_ppnl(dbcsr_work_h, dbcsr_work_p, force, &
3248 : virial, .TRUE., use_virial, nder, &
3249 : qs_kind_set, atomic_kind_set, particle_set, &
3250 50 : sab_orb, sap_ppnl, eps_ppnl, nimages, cell_to_index, "ORB")
3251 : END IF
3252 50 : DEALLOCATE (dbcsr_work_p, dbcsr_work_h)
3253 :
3254 50 : IF (use_virial) THEN
3255 4 : h_stress = 0.0_dp
3256 52 : virial%pv_xc = 0.0_dp
3257 4 : NULLIFY (vxc_rspace, vtau_rspace, vadmm_rspace)
3258 : CALL ks_ref_potential(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, &
3259 4 : dummy_real1, dummy_real2, h_stress)
3260 52 : virial%pv_ehartree = virial%pv_ehartree + h_stress/REAL(para_env%num_pe, dp)
3261 52 : virial%pv_virial = virial%pv_virial + h_stress/REAL(para_env%num_pe, dp)
3262 4 : IF (.NOT. do_exx) THEN
3263 : !if RPA EXX, then do not consider XC virial (replaced by RPA%HF virial)
3264 52 : virial%pv_exc = virial%pv_exc - virial%pv_xc
3265 52 : virial%pv_virial = virial%pv_virial - virial%pv_xc
3266 : END IF
3267 : ELSE
3268 46 : CALL ks_ref_potential(qs_env, vh_rspace, vxc_rspace, vtau_rspace, vadmm_rspace, dummy_real1, dummy_real2)
3269 : END IF
3270 50 : do_tau = ASSOCIATED(vtau_rspace)
3271 :
3272 : !Core forces from the SCF
3273 50 : CALL integrate_v_core_rspace(vh_rspace, qs_env)
3274 :
3275 : !The Hartree-xc potential term, P*dVHxc (mp2 + SCF density x deriv of the SCF potential)
3276 : !Get the total density
3277 50 : CALL qs_rho_get(rho, rho_ao=rho_ao)
3278 112 : DO ispin = 1, nspins
3279 112 : CALL dbcsr_add(rho_ao(ispin)%matrix, matrix_p_mp2(ispin)%matrix, 1.0_dp, 1.0_dp)
3280 : END DO
3281 :
3282 50 : CALL get_qs_env(qs_env, pw_env=pw_env)
3283 : CALL pw_env_get(pw_env, auxbas_pw_pool=auxbas_pw_pool, &
3284 50 : poisson_env=poisson_env)
3285 50 : CALL auxbas_pw_pool%create_pw(vhxc_rspace)
3286 :
3287 98 : IF (use_virial) pv_loc = virial%pv_virial
3288 :
3289 50 : IF (do_exx) THEN
3290 : !Only want response XC contribution, but SCF+response Hartree contribution
3291 44 : DO ispin = 1, nspins
3292 : !Hartree
3293 26 : CALL pw_transfer(vh_rspace, vhxc_rspace)
3294 : CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
3295 : hmat=scrm(ispin), pmat=rho_ao(ispin), &
3296 26 : qs_env=qs_env, calculate_forces=.TRUE.)
3297 : !XC
3298 26 : CALL pw_transfer(vxc_rspace(ispin), vhxc_rspace)
3299 : CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
3300 : hmat=scrm(ispin), pmat=matrix_p_mp2(ispin), &
3301 26 : qs_env=qs_env, calculate_forces=.TRUE.)
3302 44 : IF (do_tau) THEN
3303 : CALL integrate_v_rspace(v_rspace=vtau_rspace(ispin), &
3304 : hmat=scrm(ispin), pmat=matrix_p_mp2(ispin), &
3305 0 : qs_env=qs_env, calculate_forces=.TRUE., compute_tau=.TRUE.)
3306 : END IF
3307 : END DO
3308 : ELSE
3309 68 : DO ispin = 1, nspins
3310 36 : CALL pw_transfer(vh_rspace, vhxc_rspace)
3311 36 : CALL pw_axpy(vxc_rspace(ispin), vhxc_rspace)
3312 : CALL integrate_v_rspace(v_rspace=vhxc_rspace, &
3313 : hmat=scrm(ispin), pmat=rho_ao(ispin), &
3314 36 : qs_env=qs_env, calculate_forces=.TRUE.)
3315 68 : IF (do_tau) THEN
3316 : CALL integrate_v_rspace(v_rspace=vtau_rspace(ispin), &
3317 : hmat=scrm(ispin), pmat=rho_ao(ispin), &
3318 8 : qs_env=qs_env, calculate_forces=.TRUE., compute_tau=.TRUE.)
3319 : END IF
3320 : END DO
3321 : END IF
3322 50 : CALL auxbas_pw_pool%give_back_pw(vhxc_rspace)
3323 :
3324 98 : IF (use_virial) virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
3325 :
3326 : !The admm projection contribution (mp2 + SCF densities). If EXX, then only mp2 density
3327 50 : IF (dft_control%do_admm) THEN
3328 : CALL get_admm_env(admm_env, task_list_aux_fit=task_list_aux_fit, rho_aux_fit=rho_aux_fit, &
3329 16 : matrix_s_aux_fit=matrix_s_aux_fit)
3330 16 : CALL qs_rho_get(rho_aux_fit, rho_ao=rho_ao_aux)
3331 16 : CALL dbcsr_allocate_matrix_set(scrm_admm, nspins)
3332 36 : DO ispin = 1, nspins
3333 20 : ALLOCATE (scrm_admm(ispin)%matrix)
3334 20 : CALL dbcsr_create(scrm_admm(ispin)%matrix, template=matrix_s_aux_fit(1)%matrix)
3335 20 : CALL dbcsr_copy(scrm_admm(ispin)%matrix, matrix_s_aux_fit(1)%matrix)
3336 36 : CALL dbcsr_set(scrm_admm(ispin)%matrix, 0.0_dp)
3337 : END DO
3338 :
3339 64 : IF (use_virial) pv_loc = virial%pv_virial
3340 16 : IF (.NOT. qs_env%admm_env%aux_exch_func == do_admm_aux_exch_func_none) THEN
3341 36 : DO ispin = 1, nspins
3342 36 : IF (do_exx) THEN
3343 : CALL integrate_v_rspace(v_rspace=vadmm_rspace(ispin), &
3344 : hmat=scrm_admm(ispin), pmat=matrix_p_mp2_admm(ispin), &
3345 : qs_env=qs_env, calculate_forces=.TRUE., &
3346 8 : basis_type="AUX_FIT", task_list_external=task_list_aux_fit)
3347 : ELSE
3348 12 : CALL dbcsr_add(rho_ao_aux(ispin)%matrix, matrix_p_mp2_admm(ispin)%matrix, 1.0_dp, 1.0_dp)
3349 : CALL integrate_v_rspace(v_rspace=vadmm_rspace(ispin), &
3350 : hmat=scrm_admm(ispin), pmat=rho_ao_aux(ispin), &
3351 : qs_env=qs_env, calculate_forces=.TRUE., &
3352 12 : basis_type="AUX_FIT", task_list_external=task_list_aux_fit)
3353 12 : CALL dbcsr_add(rho_ao_aux(ispin)%matrix, matrix_p_mp2_admm(ispin)%matrix, 1.0_dp, -1.0_dp)
3354 : END IF
3355 : END DO
3356 : END IF
3357 64 : IF (use_virial) virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
3358 :
3359 16 : CALL tddft_hfx_matrix(scrm_admm, rho_ao_aux, qs_env, .FALSE., .FALSE.)
3360 :
3361 16 : IF (do_exx) THEN
3362 4 : CALL admm_projection_derivative(qs_env, scrm_admm, matrix_p_mp2)
3363 : ELSE
3364 12 : CALL admm_projection_derivative(qs_env, scrm_admm, rho_ao)
3365 : END IF
3366 : END IF
3367 :
3368 : !The exact-exchange term (mp2 + SCF densities)
3369 50 : xc_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC")
3370 50 : hfx_section => section_vals_get_subs_vals(xc_section, "HF")
3371 50 : CALL section_vals_get(hfx_section, explicit=do_hfx)
3372 :
3373 50 : IF (do_hfx) THEN
3374 32 : CALL section_vals_get(hfx_section, n_repetition=n_rep_hf)
3375 32 : CPASSERT(n_rep_hf == 1)
3376 80 : IF (use_virial) virial%pv_fock_4c = 0.0_dp
3377 :
3378 : !In case of EXX, only want to response HFX forces, as the SCF will change according to RI_RPA%HF
3379 32 : IF (do_exx) THEN
3380 8 : IF (dft_control%do_admm) THEN
3381 4 : CALL get_admm_env(admm_env, rho_aux_fit=rho_aux_fit)
3382 4 : CALL qs_rho_get(rho_aux_fit, rho_ao=rho_ao_aux, rho_ao_kp=dbcsr_work_p)
3383 4 : IF (x_data(1, 1)%do_hfx_ri) THEN
3384 :
3385 : CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
3386 : x_data(1, 1)%general_parameter%fraction, &
3387 : rho_ao=dbcsr_work_p, rho_ao_resp=matrix_p_mp2_admm, &
3388 0 : use_virial=use_virial, resp_only=.TRUE.)
3389 : ELSE
3390 : CALL derivatives_four_center(qs_env, dbcsr_work_p, matrix_p_mp2_admm, hfx_section, para_env, &
3391 4 : 1, use_virial, resp_only=.TRUE.)
3392 : END IF
3393 : ELSE
3394 8 : DO ispin = 1, nspins
3395 8 : CALL dbcsr_add(rho_ao(ispin)%matrix, matrix_p_mp2(ispin)%matrix, 1.0_dp, -1.0_dp)
3396 : END DO
3397 4 : CALL qs_rho_get(rho, rho_ao_kp=dbcsr_work_p)
3398 4 : IF (x_data(1, 1)%do_hfx_ri) THEN
3399 :
3400 : CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
3401 : x_data(1, 1)%general_parameter%fraction, &
3402 : rho_ao=dbcsr_work_p, rho_ao_resp=matrix_p_mp2, &
3403 0 : use_virial=use_virial, resp_only=.TRUE.)
3404 : ELSE
3405 : CALL derivatives_four_center(qs_env, dbcsr_work_p, matrix_p_mp2, hfx_section, para_env, &
3406 4 : 1, use_virial, resp_only=.TRUE.)
3407 : END IF
3408 8 : DO ispin = 1, nspins
3409 8 : CALL dbcsr_add(rho_ao(ispin)%matrix, matrix_p_mp2(ispin)%matrix, 1.0_dp, 1.0_dp)
3410 : END DO
3411 : END IF !admm
3412 :
3413 : ELSE !No Exx
3414 24 : IF (dft_control%do_admm) THEN
3415 12 : CALL get_admm_env(admm_env, rho_aux_fit=rho_aux_fit)
3416 12 : CALL qs_rho_get(rho_aux_fit, rho_ao=rho_ao_aux, rho_ao_kp=dbcsr_work_p)
3417 24 : DO ispin = 1, nspins
3418 24 : CALL dbcsr_add(rho_ao_aux(ispin)%matrix, matrix_p_mp2_admm(ispin)%matrix, 1.0_dp, 1.0_dp)
3419 : END DO
3420 12 : IF (x_data(1, 1)%do_hfx_ri) THEN
3421 :
3422 : CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
3423 : x_data(1, 1)%general_parameter%fraction, &
3424 : rho_ao=dbcsr_work_p, rho_ao_resp=matrix_p_mp2_admm, &
3425 0 : use_virial=use_virial, resp_only=.FALSE.)
3426 : ELSE
3427 : CALL derivatives_four_center(qs_env, dbcsr_work_p, matrix_p_mp2_admm, hfx_section, para_env, &
3428 12 : 1, use_virial, resp_only=.FALSE.)
3429 : END IF
3430 24 : DO ispin = 1, nspins
3431 24 : CALL dbcsr_add(rho_ao_aux(ispin)%matrix, matrix_p_mp2_admm(ispin)%matrix, 1.0_dp, -1.0_dp)
3432 : END DO
3433 : ELSE
3434 12 : CALL qs_rho_get(rho, rho_ao_kp=dbcsr_work_p)
3435 12 : IF (x_data(1, 1)%do_hfx_ri) THEN
3436 :
3437 : CALL hfx_ri_update_forces(qs_env, x_data(1, 1)%ri_data, nspins, &
3438 : x_data(1, 1)%general_parameter%fraction, &
3439 : rho_ao=dbcsr_work_p, rho_ao_resp=matrix_p_mp2, &
3440 0 : use_virial=use_virial, resp_only=.FALSE.)
3441 : ELSE
3442 : CALL derivatives_four_center(qs_env, dbcsr_work_p, matrix_p_mp2, hfx_section, para_env, &
3443 12 : 1, use_virial, resp_only=.FALSE.)
3444 : END IF
3445 : END IF
3446 : END IF !do_exx
3447 :
3448 32 : IF (use_virial) THEN
3449 52 : virial%pv_exx = virial%pv_exx - virial%pv_fock_4c
3450 52 : virial%pv_virial = virial%pv_virial - virial%pv_fock_4c
3451 : END IF
3452 : END IF
3453 :
3454 : !retrieve the SCF density
3455 50 : CALL qs_rho_get(rho, rho_ao=rho_ao)
3456 112 : DO ispin = 1, nspins
3457 112 : CALL dbcsr_add(rho_ao(ispin)%matrix, matrix_p_mp2(ispin)%matrix, 1.0_dp, -1.0_dp)
3458 : END DO
3459 :
3460 : !From here, we need to do everything twice. Once for the response density, and once for the
3461 : !density that is used for the trace Tr[P*F]. The reason is that the former is needed for the
3462 : !eventual overlap contribution from matrix_wz
3463 : !Only with the mp2 density
3464 :
3465 436 : ALLOCATE (current_density(nspins), current_mat_h(nspins), current_density_admm(nspins))
3466 150 : DO idens = 1, 2
3467 224 : DO ispin = 1, nspins
3468 224 : IF (idens == 1) THEN
3469 62 : current_density(ispin)%matrix => matrix_p_F(ispin)%matrix
3470 62 : current_mat_h(ispin)%matrix => scrm(ispin)%matrix
3471 62 : IF (dft_control%do_admm) current_density_admm(ispin)%matrix => matrix_p_F_admm(ispin)%matrix
3472 : ELSE
3473 62 : current_density(ispin)%matrix => p_env%p1(ispin)%matrix
3474 62 : current_mat_h(ispin)%matrix => matrix_hz(ispin)%matrix
3475 62 : IF (dft_control%do_admm) current_density_admm(ispin)%matrix => p_env%p1_admm(ispin)%matrix
3476 : END IF
3477 : END DO
3478 :
3479 : !The core-denstiy derivative
3480 748 : ALLOCATE (rhoz_r(nspins), rhoz_g(nspins))
3481 224 : DO ispin = 1, nspins
3482 124 : CALL auxbas_pw_pool%create_pw(rhoz_r(ispin))
3483 224 : CALL auxbas_pw_pool%create_pw(rhoz_g(ispin))
3484 : END DO
3485 100 : CALL auxbas_pw_pool%create_pw(rhoz_tot_gspace)
3486 100 : CALL auxbas_pw_pool%create_pw(zv_hartree_rspace)
3487 100 : CALL auxbas_pw_pool%create_pw(zv_hartree_gspace)
3488 :
3489 100 : CALL pw_zero(rhoz_tot_gspace)
3490 224 : DO ispin = 1, nspins
3491 : CALL calculate_rho_elec(ks_env=qs_env%ks_env, matrix_p=current_density(ispin)%matrix, &
3492 124 : rho=rhoz_r(ispin), rho_gspace=rhoz_g(ispin))
3493 224 : CALL pw_axpy(rhoz_g(ispin), rhoz_tot_gspace)
3494 : END DO
3495 :
3496 100 : IF (use_virial) THEN
3497 :
3498 8 : CALL get_qs_env(qs_env, rho=rho)
3499 8 : CALL auxbas_pw_pool%create_pw(rho_tot_gspace)
3500 :
3501 8 : CALL calc_rho_tot_gspace(rho_tot_gspace, qs_env, rho)
3502 :
3503 8 : h_stress(:, :) = 0.0_dp
3504 : CALL pw_poisson_solve(poisson_env, &
3505 : density=rhoz_tot_gspace, &
3506 : ehartree=ehartree, &
3507 : vhartree=zv_hartree_gspace, &
3508 : h_stress=h_stress, &
3509 8 : aux_density=rho_tot_gspace)
3510 :
3511 8 : CALL auxbas_pw_pool%give_back_pw(rho_tot_gspace)
3512 :
3513 : !Green contribution
3514 104 : virial%pv_ehartree = virial%pv_ehartree + 2.0_dp*h_stress/REAL(para_env%num_pe, dp)
3515 104 : virial%pv_virial = virial%pv_virial + 2.0_dp*h_stress/REAL(para_env%num_pe, dp)
3516 :
3517 : ELSE
3518 : CALL pw_poisson_solve(poisson_env, rhoz_tot_gspace, ehartree, &
3519 92 : zv_hartree_gspace)
3520 : END IF
3521 :
3522 100 : CALL pw_transfer(zv_hartree_gspace, zv_hartree_rspace)
3523 100 : CALL pw_scale(zv_hartree_rspace, zv_hartree_rspace%pw_grid%dvol)
3524 100 : CALL integrate_v_core_rspace(zv_hartree_rspace, qs_env)
3525 :
3526 100 : IF (do_tau) THEN
3527 : BLOCK
3528 : TYPE(pw_c1d_gs_type) :: tauz_g
3529 16 : CALL auxbas_pw_pool%create_pw(tauz_g)
3530 48 : ALLOCATE (tauz_r(nspins))
3531 32 : DO ispin = 1, nspins
3532 16 : CALL auxbas_pw_pool%create_pw(tauz_r(ispin))
3533 :
3534 : CALL calculate_rho_elec(ks_env=qs_env%ks_env, matrix_p=current_density(ispin)%matrix, &
3535 32 : rho=tauz_r(ispin), rho_gspace=tauz_g, compute_tau=.TRUE.)
3536 : END DO
3537 16 : CALL auxbas_pw_pool%give_back_pw(tauz_g)
3538 : END BLOCK
3539 : END IF
3540 :
3541 : !Volume contribution to the virial
3542 100 : IF (use_virial) THEN
3543 : !Volume contribution
3544 : exc = 0.0_dp
3545 16 : DO ispin = 1, nspins
3546 : exc = exc + pw_integral_ab(rhoz_r(ispin), vxc_rspace(ispin))/ &
3547 16 : vxc_rspace(ispin)%pw_grid%dvol
3548 : END DO
3549 8 : IF (ASSOCIATED(vtau_rspace)) THEN
3550 0 : DO ispin = 1, nspins
3551 : exc = exc + pw_integral_ab(tauz_r(ispin), vtau_rspace(ispin))/ &
3552 0 : vtau_rspace(ispin)%pw_grid%dvol
3553 : END DO
3554 : END IF
3555 32 : DO i = 1, 3
3556 24 : virial%pv_ehartree(i, i) = virial%pv_ehartree(i, i) - 4.0_dp*ehartree/REAL(para_env%num_pe, dp)
3557 24 : virial%pv_exc(i, i) = virial%pv_exc(i, i) - exc/REAL(para_env%num_pe, dp)
3558 : virial%pv_virial(i, i) = virial%pv_virial(i, i) - 4.0_dp*ehartree/REAL(para_env%num_pe, dp) &
3559 32 : - exc/REAL(para_env%num_pe, dp)
3560 : END DO
3561 : END IF
3562 :
3563 : !The xc-kernel term.
3564 100 : IF (dft_control%do_admm) THEN
3565 32 : CALL get_qs_env(qs_env, admm_env=admm_env)
3566 32 : xc_section => admm_env%xc_section_primary
3567 : ELSE
3568 68 : xc_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC")
3569 : END IF
3570 :
3571 196 : IF (use_virial) virial%pv_xc = 0.0_dp
3572 :
3573 : CALL create_kernel(qs_env, &
3574 : vxc=v_xc, &
3575 : vxc_tau=v_xc_tau, &
3576 : rho=rho, &
3577 : rho1_r=rhoz_r, &
3578 : rho1_g=rhoz_g, &
3579 : tau1_r=tauz_r, &
3580 : xc_section=xc_section, &
3581 : compute_virial=use_virial, &
3582 100 : virial_xc=virial%pv_xc)
3583 :
3584 100 : IF (use_virial) THEN
3585 104 : virial%pv_exc = virial%pv_exc + virial%pv_xc
3586 104 : virial%pv_virial = virial%pv_virial + virial%pv_xc
3587 :
3588 104 : pv_loc = virial%pv_virial
3589 : END IF
3590 :
3591 100 : CALL qs_rho_get(rho, rho_ao_kp=dbcsr_work_p)
3592 224 : DO ispin = 1, nspins
3593 124 : CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
3594 124 : CALL pw_axpy(zv_hartree_rspace, v_xc(ispin))
3595 : CALL integrate_v_rspace(qs_env=qs_env, &
3596 : v_rspace=v_xc(ispin), &
3597 : hmat=current_mat_h(ispin), &
3598 : pmat=dbcsr_work_p(ispin, 1), &
3599 124 : calculate_forces=.TRUE.)
3600 224 : CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
3601 : END DO
3602 100 : CALL auxbas_pw_pool%give_back_pw(rhoz_tot_gspace)
3603 100 : CALL auxbas_pw_pool%give_back_pw(zv_hartree_rspace)
3604 100 : CALL auxbas_pw_pool%give_back_pw(zv_hartree_gspace)
3605 100 : DEALLOCATE (v_xc)
3606 :
3607 100 : IF (do_tau) THEN
3608 32 : DO ispin = 1, nspins
3609 16 : CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
3610 : CALL integrate_v_rspace(qs_env=qs_env, &
3611 : v_rspace=v_xc_tau(ispin), &
3612 : hmat=current_mat_h(ispin), &
3613 : pmat=dbcsr_work_p(ispin, 1), &
3614 : compute_tau=.TRUE., &
3615 16 : calculate_forces=.TRUE.)
3616 32 : CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
3617 : END DO
3618 16 : DEALLOCATE (v_xc_tau)
3619 : END IF
3620 :
3621 196 : IF (use_virial) virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
3622 :
3623 100 : IF (do_hfx) THEN
3624 64 : IF (dft_control%do_admm) THEN
3625 72 : DO ispin = 1, nspins
3626 72 : CALL dbcsr_set(scrm_admm(ispin)%matrix, 0.0_dp)
3627 : END DO
3628 32 : CALL qs_rho_get(rho_aux_fit, tau_r_valid=do_tau_admm)
3629 :
3630 32 : IF (.NOT. admm_env%aux_exch_func == do_admm_aux_exch_func_none) THEN
3631 32 : CALL get_admm_env(admm_env, rho_aux_fit=rho_aux_fit)
3632 72 : DO ispin = 1, nspins
3633 40 : CALL pw_zero(rhoz_r(ispin))
3634 40 : CALL pw_zero(rhoz_g(ispin))
3635 : CALL calculate_rho_elec(ks_env=qs_env%ks_env, matrix_p=current_density_admm(ispin)%matrix, &
3636 : rho=rhoz_r(ispin), rho_gspace=rhoz_g(ispin), &
3637 72 : basis_type="AUX_FIT", task_list_external=task_list_aux_fit)
3638 : END DO
3639 :
3640 32 : IF (do_tau_admm) THEN
3641 : BLOCK
3642 : TYPE(pw_c1d_gs_type) :: tauz_g
3643 0 : CALL auxbas_pw_pool%create_pw(tauz_g)
3644 0 : DO ispin = 1, nspins
3645 0 : CALL pw_zero(tauz_r(ispin))
3646 : CALL calculate_rho_elec(ks_env=qs_env%ks_env, matrix_p=current_density(ispin)%matrix, &
3647 : rho=tauz_r(ispin), rho_gspace=tauz_g, &
3648 : basis_type="AUX_FIT", task_list_external=task_list_aux_fit, &
3649 0 : compute_tau=.TRUE.)
3650 : END DO
3651 0 : CALL auxbas_pw_pool%give_back_pw(tauz_g)
3652 : END BLOCK
3653 : END IF
3654 :
3655 : !Volume contribution to the virial
3656 32 : IF (use_virial) THEN
3657 : exc = 0.0_dp
3658 16 : DO ispin = 1, nspins
3659 : exc = exc + pw_integral_ab(rhoz_r(ispin), vadmm_rspace(ispin))/ &
3660 16 : vadmm_rspace(ispin)%pw_grid%dvol
3661 : END DO
3662 32 : DO i = 1, 3
3663 24 : virial%pv_exc(i, i) = virial%pv_exc(i, i) - exc/REAL(para_env%num_pe, dp)
3664 32 : virial%pv_virial(i, i) = virial%pv_virial(i, i) - exc/REAL(para_env%num_pe, dp)
3665 : END DO
3666 :
3667 104 : virial%pv_xc = 0.0_dp
3668 : END IF
3669 :
3670 32 : xc_section => admm_env%xc_section_aux
3671 : CALL create_kernel(qs_env, v_xc, v_xc_tau, rho_aux_fit, rhoz_r, rhoz_g, tauz_r, xc_section, &
3672 32 : compute_virial=use_virial, virial_xc=virial%pv_xc)
3673 :
3674 32 : IF (use_virial) THEN
3675 104 : virial%pv_exc = virial%pv_exc + virial%pv_xc
3676 104 : virial%pv_virial = virial%pv_virial + virial%pv_xc
3677 :
3678 104 : pv_loc = virial%pv_virial
3679 : END IF
3680 :
3681 32 : CALL qs_rho_get(rho_aux_fit, rho_ao_kp=dbcsr_work_p)
3682 72 : DO ispin = 1, nspins
3683 40 : CALL pw_scale(v_xc(ispin), v_xc(ispin)%pw_grid%dvol)
3684 : CALL integrate_v_rspace(qs_env=qs_env, &
3685 : v_rspace=v_xc(ispin), &
3686 : hmat=scrm_admm(ispin), &
3687 : pmat=dbcsr_work_p(ispin, 1), &
3688 : calculate_forces=.TRUE., &
3689 : basis_type="AUX_FIT", &
3690 40 : task_list_external=task_list_aux_fit)
3691 72 : CALL auxbas_pw_pool%give_back_pw(v_xc(ispin))
3692 : END DO
3693 32 : DEALLOCATE (v_xc)
3694 :
3695 32 : IF (do_tau_admm) THEN
3696 0 : DO ispin = 1, nspins
3697 0 : CALL pw_scale(v_xc_tau(ispin), v_xc_tau(ispin)%pw_grid%dvol)
3698 : CALL integrate_v_rspace(qs_env=qs_env, &
3699 : v_rspace=v_xc_tau(ispin), &
3700 : hmat=scrm_admm(ispin), &
3701 : pmat=dbcsr_work_p(ispin, 1), &
3702 : calculate_forces=.TRUE., &
3703 : basis_type="AUX_FIT", &
3704 : task_list_external=task_list_aux_fit, &
3705 0 : compute_tau=.TRUE.)
3706 0 : CALL auxbas_pw_pool%give_back_pw(v_xc_tau(ispin))
3707 : END DO
3708 0 : DEALLOCATE (v_xc_tau)
3709 : END IF
3710 :
3711 128 : IF (use_virial) virial%pv_ehartree = virial%pv_ehartree + (virial%pv_virial - pv_loc)
3712 : END IF
3713 :
3714 32 : CALL tddft_hfx_matrix(scrm_admm, current_density_admm, qs_env, .FALSE., .FALSE.)
3715 :
3716 32 : CALL qs_rho_get(rho, rho_ao_kp=dbcsr_work_p)
3717 32 : CALL admm_projection_derivative(qs_env, scrm_admm, dbcsr_work_p(:, 1))
3718 :
3719 : !If response density, need to get matrix_hz contribution
3720 32 : CALL dbcsr_create(dbcsr_work, template=matrix_s(1)%matrix)
3721 32 : IF (idens == 2) THEN
3722 16 : nao = admm_env%nao_orb
3723 16 : nao_aux = admm_env%nao_aux_fit
3724 36 : DO ispin = 1, nspins
3725 20 : CALL dbcsr_copy(dbcsr_work, matrix_hz(ispin)%matrix)
3726 20 : CALL dbcsr_set(dbcsr_work, 0.0_dp)
3727 :
3728 : CALL cp_dbcsr_sm_fm_multiply(scrm_admm(ispin)%matrix, admm_env%A, &
3729 20 : admm_env%work_aux_orb, nao)
3730 : CALL parallel_gemm('T', 'N', nao, nao, nao_aux, &
3731 : 1.0_dp, admm_env%A, admm_env%work_aux_orb, 0.0_dp, &
3732 20 : admm_env%work_orb_orb)
3733 20 : CALL copy_fm_to_dbcsr(admm_env%work_orb_orb, dbcsr_work, keep_sparsity=.TRUE.)
3734 36 : CALL dbcsr_add(matrix_hz(ispin)%matrix, dbcsr_work, 1.0_dp, 1.0_dp)
3735 : END DO
3736 : END IF
3737 :
3738 32 : CALL dbcsr_release(dbcsr_work)
3739 : ELSE !no admm
3740 :
3741 : !Need the contribution to matrix_hz as well
3742 32 : IF (idens == 2) THEN
3743 16 : CALL tddft_hfx_matrix(matrix_hz, current_density, qs_env, .FALSE., .FALSE.)
3744 : END IF
3745 : END IF !admm
3746 : END IF !do_hfx
3747 :
3748 224 : DO ispin = 1, nspins
3749 124 : CALL auxbas_pw_pool%give_back_pw(rhoz_r(ispin))
3750 224 : CALL auxbas_pw_pool%give_back_pw(rhoz_g(ispin))
3751 : END DO
3752 100 : DEALLOCATE (rhoz_r, rhoz_g)
3753 :
3754 150 : IF (do_tau) THEN
3755 32 : DO ispin = 1, nspins
3756 32 : CALL auxbas_pw_pool%give_back_pw(tauz_r(ispin))
3757 : END DO
3758 16 : DEALLOCATE (tauz_r)
3759 : END IF
3760 : END DO !idens
3761 50 : CALL dbcsr_deallocate_matrix_set(scrm_admm)
3762 :
3763 50 : DEALLOCATE (current_density, current_mat_h, current_density_admm)
3764 50 : CALL dbcsr_deallocate_matrix_set(scrm)
3765 :
3766 : !The energy weighted and overlap term. ONLY with the response density
3767 50 : focc = 2.0_dp
3768 50 : IF (nspins == 2) focc = 1.0_dp
3769 50 : CALL get_qs_env(qs_env, mos=mos)
3770 112 : DO ispin = 1, nspins
3771 62 : CALL get_mo_set(mo_set=mos(ispin), homo=nocc)
3772 : CALL calculate_whz_matrix(mos(ispin)%mo_coeff, matrix_hz(ispin)%matrix, &
3773 112 : p_env%w1(ispin)%matrix, focc, nocc)
3774 : END DO
3775 50 : IF (nspins == 2) CALL dbcsr_add(p_env%w1(1)%matrix, p_env%w1(2)%matrix, 1.0_dp, 1.0_dp)
3776 :
3777 : !Add to it the SCF W matrix, except if EXX (because taken care of by HF response)
3778 50 : IF (.NOT. do_exx) THEN
3779 32 : CALL compute_matrix_w(qs_env, calc_forces=.TRUE.)
3780 32 : CALL get_qs_env(qs_env, matrix_w=matrix_w)
3781 32 : CALL dbcsr_add(p_env%w1(1)%matrix, matrix_w(1)%matrix, 1.0_dp, 1.0_dp)
3782 32 : IF (nspins == 2) CALL dbcsr_add(p_env%w1(1)%matrix, matrix_w(2)%matrix, 1.0_dp, 1.0_dp)
3783 : END IF
3784 :
3785 50 : NULLIFY (scrm)
3786 : CALL build_overlap_matrix(qs_env%ks_env, matrix_s=scrm, &
3787 : matrix_name="OVERLAP MATRIX", &
3788 : basis_type_a="ORB", basis_type_b="ORB", &
3789 : sab_nl=sab_orb, calculate_forces=.TRUE., &
3790 50 : matrix_p=p_env%w1(1)%matrix)
3791 :
3792 50 : IF (.NOT. do_exx) THEN
3793 32 : CALL dbcsr_add(p_env%w1(1)%matrix, matrix_w(1)%matrix, 1.0_dp, -1.0_dp)
3794 32 : IF (nspins == 2) CALL dbcsr_add(p_env%w1(1)%matrix, matrix_w(2)%matrix, 1.0_dp, -1.0_dp)
3795 68 : DO ispin = 1, nspins
3796 68 : CALL dbcsr_set(matrix_w(ispin)%matrix, 0.0_dp)
3797 : END DO
3798 : END IF
3799 :
3800 50 : IF (nspins == 2) CALL dbcsr_add(p_env%w1(1)%matrix, p_env%w1(2)%matrix, 1.0_dp, -1.0_dp)
3801 50 : CALL dbcsr_deallocate_matrix_set(scrm)
3802 :
3803 50 : IF (use_virial) virial%pv_calculate = .FALSE.
3804 :
3805 : !clean-up
3806 50 : CALL auxbas_pw_pool%give_back_pw(vh_rspace)
3807 :
3808 112 : DO ispin = 1, nspins
3809 62 : CALL auxbas_pw_pool%give_back_pw(vxc_rspace(ispin))
3810 62 : IF (ASSOCIATED(vtau_rspace)) THEN
3811 8 : CALL auxbas_pw_pool%give_back_pw(vtau_rspace(ispin))
3812 : END IF
3813 112 : IF (ASSOCIATED(vadmm_rspace)) THEN
3814 20 : CALL auxbas_pw_pool%give_back_pw(vadmm_rspace(ispin))
3815 : END IF
3816 : END DO
3817 50 : DEALLOCATE (vxc_rspace)
3818 50 : IF (ASSOCIATED(vtau_rspace)) DEALLOCATE (vtau_rspace)
3819 50 : IF (ASSOCIATED(vadmm_rspace)) DEALLOCATE (vadmm_rspace)
3820 :
3821 50 : CALL timestop(handle)
3822 :
3823 100 : END SUBROUTINE update_im_time_forces
3824 :
3825 : ! **************************************************************************************************
3826 : !> \brief Iteratively builds the matrix Y = sum_k Y_k until convergence, where
3827 : !> Y_k = 1/k*2^n (A/2^n) Y_k-1 + 1/k!*2^n * PR(n) * (A/2^n)^(k-1)
3828 : !> n is chosen such that the norm of A is < 1 (and e^A converges fast)
3829 : !> PR(n) = e^(A/2^n)*PR(n-1) + PR(n-1)*e^(A/2^n), PR(0) = P*R^T
3830 : !> \param Y ...
3831 : !> \param A ...
3832 : !> \param P ...
3833 : !> \param R ...
3834 : !> \param filter_eps ...
3835 : ! **************************************************************************************************
3836 340 : SUBROUTINE build_Y_matrix(Y, A, P, R, filter_eps)
3837 :
3838 : TYPE(dbcsr_type), INTENT(OUT) :: Y
3839 : TYPE(dbcsr_type), INTENT(INOUT) :: A, P, R
3840 : REAL(dp), INTENT(IN) :: filter_eps
3841 :
3842 : CHARACTER(LEN=*), PARAMETER :: routineN = 'build_Y_matrix'
3843 :
3844 : INTEGER :: handle, k, n
3845 : REAL(dp) :: norm_scalar, threshold
3846 : TYPE(dbcsr_type) :: A2n, exp_A2n, PRn, work, work2, Yk
3847 :
3848 340 : CALL timeset(routineN, handle)
3849 :
3850 340 : threshold = 1.0E-16_dp
3851 :
3852 : !Find n such that norm(A) < 1 and we insure convergence of the exponential
3853 340 : norm_scalar = dbcsr_frobenius_norm(A)
3854 :
3855 : !checked: result invariant with value of n
3856 340 : n = 1
3857 466 : DO
3858 806 : IF ((norm_scalar/2.0_dp**n) < 1.0_dp) EXIT
3859 466 : n = n + 1
3860 : END DO
3861 :
3862 : !Calculate PR(n) recursively
3863 340 : CALL dbcsr_create(PRn, template=A, matrix_type=dbcsr_type_no_symmetry)
3864 340 : CALL dbcsr_create(work, template=A, matrix_type=dbcsr_type_no_symmetry)
3865 340 : CALL dbcsr_multiply('N', 'N', 1.0_dp, P, R, 0.0_dp, work, filter_eps=filter_eps)
3866 340 : CALL dbcsr_create(exp_A2n, template=A, matrix_type=dbcsr_type_no_symmetry)
3867 :
3868 1146 : DO k = 1, n
3869 806 : CALL matrix_exponential(exp_A2n, A, 1.0_dp, 0.5_dp**k, threshold)
3870 806 : CALL dbcsr_multiply('N', 'N', 1.0_dp, exp_A2n, work, 0.0_dp, PRn, filter_eps=filter_eps)
3871 806 : CALL dbcsr_multiply('N', 'N', 1.0_dp, work, exp_A2n, 1.0_dp, PRn, filter_eps=filter_eps)
3872 1146 : CALL dbcsr_copy(work, PRn)
3873 : END DO
3874 340 : CALL dbcsr_release(exp_A2n)
3875 :
3876 : !Calculate Y iteratively, until convergence
3877 340 : CALL dbcsr_create(A2n, template=A, matrix_type=dbcsr_type_no_symmetry)
3878 340 : CALL dbcsr_copy(A2n, A)
3879 340 : CALL dbcsr_scale(A2n, 0.5_dp**n)
3880 340 : CALL dbcsr_create(Y, template=A, matrix_type=dbcsr_type_no_symmetry)
3881 340 : CALL dbcsr_create(Yk, template=A, matrix_type=dbcsr_type_no_symmetry)
3882 340 : CALL dbcsr_create(work2, template=A, matrix_type=dbcsr_type_no_symmetry)
3883 :
3884 : !k=1
3885 340 : CALL dbcsr_scale(PRn, 0.5_dp**n)
3886 340 : CALL dbcsr_copy(work, PRn)
3887 340 : CALL dbcsr_copy(work2, PRn)
3888 340 : CALL dbcsr_add(Y, PRn, 1.0_dp, 1.0_dp)
3889 :
3890 340 : k = 1
3891 1908 : DO
3892 2248 : k = k + 1
3893 2248 : CALL dbcsr_multiply('N', 'N', 1.0_dp/REAL(k, dp), A2n, work, 0.0_dp, Yk, filter_eps=filter_eps)
3894 2248 : CALL dbcsr_multiply('N', 'N', 1.0_dp/REAL(k, dp), work2, A2n, 0.0_dp, PRn, filter_eps=filter_eps)
3895 :
3896 2248 : CALL dbcsr_add(Yk, PRn, 1.0_dp, 1.0_dp)
3897 2248 : CALL dbcsr_add(Y, Yk, 1.0_dp, 1.0_dp)
3898 :
3899 2248 : IF (dbcsr_frobenius_norm(Yk) < threshold) EXIT
3900 1908 : CALL dbcsr_copy(work, Yk)
3901 1908 : CALL dbcsr_copy(work2, PRn)
3902 : END DO
3903 :
3904 340 : CALL dbcsr_release(work)
3905 340 : CALL dbcsr_release(work2)
3906 340 : CALL dbcsr_release(PRn)
3907 340 : CALL dbcsr_release(A2n)
3908 340 : CALL dbcsr_release(Yk)
3909 :
3910 340 : CALL timestop(handle)
3911 :
3912 340 : END SUBROUTINE build_Y_matrix
3913 :
3914 : ! **************************************************************************************************
3915 : !> \brief Overwrites the "optimal" Laplace quadrature with that of the first step
3916 : !> \param tj ...
3917 : !> \param wj ...
3918 : !> \param tau_tj ...
3919 : !> \param tau_wj ...
3920 : !> \param weights_cos_tf_t_to_w ...
3921 : !> \param weights_cos_tf_w_to_t ...
3922 : !> \param do_laplace ...
3923 : !> \param do_im_time ...
3924 : !> \param num_integ_points ...
3925 : !> \param unit_nr ...
3926 : !> \param qs_env ...
3927 : ! **************************************************************************************************
3928 202 : SUBROUTINE keep_initial_quad(tj, wj, tau_tj, tau_wj, weights_cos_tf_t_to_w, weights_cos_tf_w_to_t, &
3929 : do_laplace, do_im_time, num_integ_points, unit_nr, qs_env)
3930 :
3931 : REAL(dp), ALLOCATABLE, DIMENSION(:), INTENT(INOUT) :: tj, wj, tau_tj, tau_wj
3932 : REAL(dp), ALLOCATABLE, DIMENSION(:, :), &
3933 : INTENT(INOUT) :: weights_cos_tf_t_to_w, &
3934 : weights_cos_tf_w_to_t
3935 : LOGICAL, INTENT(IN) :: do_laplace, do_im_time
3936 : INTEGER, INTENT(IN) :: num_integ_points, unit_nr
3937 : TYPE(qs_environment_type), POINTER :: qs_env
3938 :
3939 : INTEGER :: jquad
3940 :
3941 202 : IF (do_laplace .OR. do_im_time) THEN
3942 164 : IF (.NOT. ASSOCIATED(qs_env%mp2_env%ri_rpa_im_time%tau_tj)) THEN
3943 384 : ALLOCATE (qs_env%mp2_env%ri_rpa_im_time%tau_tj(0:num_integ_points))
3944 384 : ALLOCATE (qs_env%mp2_env%ri_rpa_im_time%tau_wj(num_integ_points))
3945 1112 : qs_env%mp2_env%ri_rpa_im_time%tau_tj(:) = tau_tj(:)
3946 984 : qs_env%mp2_env%ri_rpa_im_time%tau_wj(:) = tau_wj(:)
3947 : ELSE
3948 : !If weights already stored, we overwrite the new ones
3949 188 : tau_tj(:) = qs_env%mp2_env%ri_rpa_im_time%tau_tj(:)
3950 152 : tau_wj(:) = qs_env%mp2_env%ri_rpa_im_time%tau_wj(:)
3951 : END IF
3952 : END IF
3953 202 : IF (.NOT. do_laplace) THEN
3954 144 : IF (.NOT. ASSOCIATED(qs_env%mp2_env%ri_rpa_im_time%tj)) THEN
3955 354 : ALLOCATE (qs_env%mp2_env%ri_rpa_im_time%tj(num_integ_points))
3956 354 : ALLOCATE (qs_env%mp2_env%ri_rpa_im_time%wj(num_integ_points))
3957 976 : qs_env%mp2_env%ri_rpa_im_time%tj(:) = tj(:)
3958 976 : qs_env%mp2_env%ri_rpa_im_time%wj(:) = wj(:)
3959 118 : IF (do_im_time) THEN
3960 360 : ALLOCATE (qs_env%mp2_env%ri_rpa_im_time%weights_cos_tf_t_to_w(num_integ_points, num_integ_points))
3961 360 : ALLOCATE (qs_env%mp2_env%ri_rpa_im_time%weights_cos_tf_w_to_t(num_integ_points, num_integ_points))
3962 9746 : qs_env%mp2_env%ri_rpa_im_time%weights_cos_tf_t_to_w(:, :) = weights_cos_tf_t_to_w(:, :)
3963 9746 : qs_env%mp2_env%ri_rpa_im_time%weights_cos_tf_w_to_t(:, :) = weights_cos_tf_w_to_t(:, :)
3964 : END IF
3965 : ELSE
3966 110 : tj(:) = qs_env%mp2_env%ri_rpa_im_time%tj(:)
3967 110 : wj(:) = qs_env%mp2_env%ri_rpa_im_time%wj(:)
3968 26 : IF (do_im_time) THEN
3969 184 : weights_cos_tf_t_to_w(:, :) = qs_env%mp2_env%ri_rpa_im_time%weights_cos_tf_t_to_w(:, :)
3970 184 : weights_cos_tf_w_to_t(:, :) = qs_env%mp2_env%ri_rpa_im_time%weights_cos_tf_w_to_t(:, :)
3971 : END IF
3972 : END IF
3973 : END IF
3974 202 : IF (unit_nr > 0) THEN
3975 : !Printing order same as in mp2_grids.F for consistency
3976 101 : IF (ASSOCIATED(qs_env%mp2_env%ri_rpa_im_time%tj) .AND. (.NOT. do_laplace)) THEN
3977 : WRITE (UNIT=unit_nr, FMT="(T3,A,T75,i6)") &
3978 72 : "MINIMAX_INFO| Number of integration points:", num_integ_points
3979 : WRITE (UNIT=unit_nr, FMT="(T3,A,T54,A,T72,A)") &
3980 72 : "MINIMAX_INFO| Minimax params (freq grid, scaled):", "Weights", "Abscissas"
3981 543 : DO jquad = 1, num_integ_points
3982 543 : WRITE (UNIT=unit_nr, FMT="(T41,F20.10,F20.10)") wj(jquad), tj(jquad)
3983 : END DO
3984 72 : CALL m_flush(unit_nr)
3985 : END IF
3986 101 : IF (ASSOCIATED(qs_env%mp2_env%ri_rpa_im_time%tau_tj)) THEN
3987 : WRITE (UNIT=unit_nr, FMT="(T3,A,T75,i6)") &
3988 82 : "MINIMAX_INFO| Number of integration points:", num_integ_points
3989 : WRITE (UNIT=unit_nr, FMT="(T3,A,T54,A,T72,A)") &
3990 82 : "MINIMAX_INFO| Minimax params (time grid, scaled):", "Weights", "Abscissas"
3991 568 : DO jquad = 1, num_integ_points
3992 568 : WRITE (UNIT=unit_nr, FMT="(T41,F20.10,F20.10)") tau_wj(jquad), tau_tj(jquad)
3993 : END DO
3994 82 : CALL m_flush(unit_nr)
3995 : END IF
3996 : END IF
3997 :
3998 202 : END SUBROUTINE keep_initial_quad
3999 :
4000 : END MODULE rpa_im_time_force_methods
|