67#include "./base/base_uses.f90"
73 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'rpa_rse'
90 SUBROUTINE rse_energy(qs_env, mp2_env, para_env, dft_control, &
91 mo_coeff, homo, Eigenval)
93 TYPE(
mp2_type),
INTENT(INOUT) :: mp2_env
96 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: mo_coeff
97 INTEGER,
DIMENSION(:),
INTENT(IN) :: homo
98 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: eigenval
100 CHARACTER(LEN=*),
PARAMETER :: routinen =
'rse_energy'
102 INTEGER :: handle, i_global, iib, ispin, j_global, &
103 jjb, n_rep_hf, nao, ncol_local, nmo, &
105 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
106 LOGICAL :: do_hfx, hfx_treat_lsd_in_core
107 REAL(kind=
dp) :: coeff, corr, rse_corr
108 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: diag_diff
112 TYPE(
cp_fm_type),
ALLOCATABLE,
DIMENSION(:) :: fm_p_mu_nu, fm_x_mo, fm_xc_mo
113 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: mat_mu_nu, matrix_s, rho_ao
120 CALL timeset(routinen, handle)
122 nspins = dft_control%nspins
126 nrow_local=nrow_local, &
127 ncol_local=ncol_local, &
128 row_indices=row_indices, &
129 col_indices=col_indices, &
134 NULLIFY (input, matrix_s, blacs_env, rho, energy, sab_orb)
138 blacs_env=blacs_env, &
146 NULLIFY (hfx_sections)
158 ALLOCATE (mat_mu_nu(ispin)%matrix)
159 CALL dbcsr_create(matrix=mat_mu_nu(ispin)%matrix, template=matrix_s(1)%matrix, name=
"T_mu_nu", &
160 matrix_type=dbcsr_type_symmetric)
162 CALL dbcsr_set(mat_mu_nu(ispin)%matrix, 0.0_dp)
166 ALLOCATE (fm_p_mu_nu(nspins))
167 NULLIFY (fm_struct_tmp)
169 nrow_global=nao, ncol_global=nao)
171 CALL cp_fm_create(fm_p_mu_nu(ispin), fm_struct_tmp, name=
"P_mu_nu")
179 NULLIFY (fm_struct_tmp)
181 nrow_global=nmo, ncol_global=nmo)
182 ALLOCATE (fm_x_mo(nspins), fm_xc_mo(nspins))
184 CALL cp_fm_create(fm_x_mo(ispin), fm_struct_tmp, name=
"f_X_mo")
185 CALL cp_fm_create(fm_xc_mo(ispin), fm_struct_tmp, name=
"f_XC_mo")
192 nrow_global=nmo, ncol_global=nao)
193 CALL cp_fm_create(fm_ao_mo, fm_struct_tmp, name=
"f_ao_mo")
204 IF (nspins == 1) coeff = 2.0_dp
206 CALL parallel_gemm(transa=
'N', transb=
'T', m=nao, n=nao, k=homo(ispin), alpha=coeff, &
207 matrix_a=mo_coeff(ispin), matrix_b=mo_coeff(ispin), &
208 beta=0.0_dp, matrix_c=fm_p_mu_nu(ispin))
212 CALL exchange_contribution(qs_env, para_env, mo_coeff, &
213 hfx_sections, n_rep_hf, &
214 rho, mat_mu_nu, fm_p_mu_nu, &
215 fm_ao, fm_x_mo, fm_ao_mo)
218 CALL xc_contribution(qs_env, fm_ao, fm_ao_mo, fm_xc_mo, mo_coeff)
220 ALLOCATE (diag_diff(nmo))
232 nrow_local=nrow_local, &
233 ncol_local=ncol_local, &
234 row_indices=row_indices, &
235 col_indices=col_indices)
242 DO jjb = 1, ncol_local
243 j_global = col_indices(jjb)
244 DO iib = 1, nrow_local
245 i_global = row_indices(iib)
246 IF ((i_global .LE. homo(ispin)) .AND. (j_global .GT. homo(ispin)))
THEN
247 corr = corr + fm_x_mo(ispin)%local_data(iib, jjb)**2.0_dp/ &
248 (eigenval(i_global, ispin) - eigenval(j_global, ispin) - diag_diff(i_global) + diag_diff(j_global))
254 rse_corr = rse_corr + corr
257 CALL para_env%sum(rse_corr)
259 IF (nspins == 1) rse_corr = rse_corr*2.0_dp
261 mp2_env%ri_rpa%rse_corr_diag = rse_corr
263 CALL non_diag_rse(fm_x_mo, eigenval, homo, para_env, blacs_env, rse_corr)
265 IF (nspins == 1) rse_corr = rse_corr*2.0_dp
267 mp2_env%ri_rpa%rse_corr = rse_corr
270 DEALLOCATE (diag_diff)
278 DEALLOCATE (mat_mu_nu(ispin)%matrix)
280 DEALLOCATE (mat_mu_nu)
282 CALL timestop(handle)
300 SUBROUTINE exchange_contribution(qs_env, para_env, mo_coeff, &
301 hfx_sections, n_rep_hf, &
302 rho_work, mat_mu_nu, fm_P_mu_nu, &
303 fm_X_ao, fm_X_mo, fm_X_ao_mo)
306 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: mo_coeff
308 INTEGER,
INTENT(IN) :: n_rep_hf
312 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: fm_p_mu_nu
314 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: fm_x_mo
317 CHARACTER(LEN=*),
PARAMETER :: routinen =
'exchange_contribution'
319 INTEGER :: handle, irep, is, nao, nmo, ns
320 LOGICAL :: my_recalc_hfx_integrals
321 REAL(kind=
dp) :: ehfx
322 TYPE(
dbcsr_p_type),
DIMENSION(:),
POINTER :: p_mu_nu, rho_work_ao
323 TYPE(
dbcsr_p_type),
DIMENSION(:, :),
POINTER :: mat_2d, rho_ao_2d
325 CALL timeset(routinen, handle)
327 CALL cp_fm_get_info(mo_coeff(1), nrow_global=nao, ncol_global=nmo)
330 ns =
SIZE(rho_work_ao)
335 CALL dbcsr_create(p_mu_nu(is)%matrix, template=rho_work_ao(1)%matrix)
336 CALL dbcsr_copy(p_mu_nu(is)%matrix, rho_work_ao(1)%matrix)
337 CALL dbcsr_set(p_mu_nu(is)%matrix, 0.0_dp)
340 my_recalc_hfx_integrals = .true.
342 CALL exx_pre_hfx(hfx_sections, qs_env%mp2_env%ri_rpa%x_data, qs_env%mp2_env%ri_rpa%reuse_hfx)
344 CALL copy_fm_to_dbcsr(fm_p_mu_nu(is), p_mu_nu(1)%matrix, keep_sparsity=.true.)
346 CALL dbcsr_set(mat_mu_nu(1)%matrix, 0.0_dp)
348 IF (qs_env%mp2_env%ri_rpa%x_data(1, 1)%do_hfx_ri)
THEN
350 DO irep = 1, n_rep_hf
351 rho_ao_2d(1:ns, 1:1) => p_mu_nu(1:ns)
352 mat_2d(1:ns, 1:1) => mat_mu_nu(1:ns)
353 CALL hfx_ri_update_ks(qs_env, qs_env%mp2_env%ri_rpa%x_data(irep, 1)%ri_data, mat_2d, ehfx, &
354 rho_ao=rho_ao_2d, geometry_did_change=my_recalc_hfx_integrals, nspins=1, &
355 hf_fraction=qs_env%mp2_env%ri_rpa%x_data(irep, 1)%general_parameter%fraction)
357 IF (ns == 2)
CALL dbcsr_scale(mat_mu_nu(1)%matrix, 2.0_dp)
358 my_recalc_hfx_integrals = .false.
363 DO irep = 1, n_rep_hf
364 rho_ao_2d(1:ns, 1:1) => p_mu_nu(1:ns)
365 mat_2d(1:ns, 1:1) => mat_mu_nu(1:ns)
366 CALL integrate_four_center(qs_env, qs_env%mp2_env%ri_rpa%x_data, mat_2d, ehfx, rho_ao_2d, hfx_sections, &
367 para_env, my_recalc_hfx_integrals, irep, .true., &
370 my_recalc_hfx_integrals = .false.
381 mo_coeff(is), fm_x_ao, 0.0_dp, fm_x_ao_mo)
385 fm_x_ao_mo, mo_coeff(is), 1.0_dp, fm_x_mo(is))
388 CALL exx_post_hfx(qs_env, qs_env%mp2_env%ri_rpa%x_data, qs_env%mp2_env%ri_rpa%reuse_hfx)
391 DO is = 1,
SIZE(p_mu_nu)
393 DEALLOCATE (p_mu_nu(is)%matrix)
397 CALL timestop(handle)
399 END SUBROUTINE exchange_contribution
409 SUBROUTINE xc_contribution(qs_env, fm_XC_ao, fm_XC_ao_mo, fm_XC_mo, mo_coeff)
413 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: fm_xc_mo, mo_coeff
415 CHARACTER(LEN=*),
PARAMETER :: routinen =
'xc_contribution'
417 INTEGER :: handle, i, nao, nmo
420 TYPE(
pw_r3d_rs_type),
DIMENSION(:),
POINTER :: tau_rspace, v_rspace
425 CALL timeset(routinen, handle)
427 NULLIFY (matrix_vxc, v_rspace, tau_rspace, input, xc_section, ks_env, &
429 CALL get_qs_env(qs_env, matrix_vxc=matrix_vxc, input=input, ks_env=ks_env, rho=rho)
433 CALL qs_vxc_create(ks_env=ks_env, rho_struct=rho, xc_section=xc_section, &
434 vxc_rho=v_rspace, vxc_tau=tau_rspace, exc=exc)
436 IF (
ASSOCIATED(v_rspace))
THEN
439 DO i = 1,
SIZE(v_rspace)
440 CALL v_rspace(i)%release()
442 DEALLOCATE (v_rspace)
444 CALL cp_fm_get_info(mo_coeff(1), nrow_global=nao, ncol_global=nmo)
446 DO i = 1,
SIZE(matrix_vxc)
453 mo_coeff(i), fm_xc_ao, 0.0_dp, fm_xc_ao_mo)
457 fm_xc_ao_mo, mo_coeff(i), 1.0_dp, fm_xc_mo(i))
461 DO i = 1,
SIZE(matrix_vxc)
463 DEALLOCATE (matrix_vxc(i)%matrix)
465 DEALLOCATE (matrix_vxc)
468 CALL timestop(handle)
470 END SUBROUTINE xc_contribution
481 SUBROUTINE non_diag_rse(fm_F_mo, eigenval, homo, para_env, &
483 TYPE(
cp_fm_type),
DIMENSION(:),
INTENT(IN) :: fm_f_mo
484 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN) :: eigenval
485 INTEGER,
DIMENSION(:),
INTENT(IN) :: homo
488 REAL(kind=
dp),
INTENT(OUT) :: rse_corr
490 CHARACTER(LEN=*),
PARAMETER :: routinen =
'non_diag_rse'
492 INTEGER :: handle, i_global, iib, ispin, j_global, &
493 jjb, ncol_local, nmo, nrow_local, &
495 INTEGER,
DIMENSION(:),
POINTER :: col_indices, row_indices
496 REAL(kind=
dp) :: corr
497 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: eig_o, eig_semi_can, eig_v
499 TYPE(
cp_fm_type) :: fm_f_oo, fm_f_ov, fm_f_vv, fm_o, fm_tmp, &
502 CALL timeset(routinen, handle)
504 nmo =
SIZE(eigenval, 1)
505 nspins =
SIZE(fm_f_mo)
510 nrow_local=nrow_local, &
511 ncol_local=ncol_local, &
512 row_indices=row_indices, &
513 col_indices=col_indices)
517 DO jjb = 1, ncol_local
518 j_global = col_indices(jjb)
519 DO iib = 1, nrow_local
520 i_global = row_indices(iib)
521 IF (i_global .EQ. j_global) fm_f_mo(ispin)%local_data(iib, jjb) = &
522 fm_f_mo(ispin)%local_data(iib, jjb) + eigenval(i_global, ispin)
531 IF (homo(ispin) <= 0 .OR. homo(ispin) >= nmo) cycle
533 NULLIFY (fm_struct_tmp)
535 nrow_global=homo(ispin), ncol_global=homo(ispin))
543 nrow=homo(ispin), ncol=homo(ispin), &
544 s_firstrow=1, s_firstcol=1, &
545 t_firstrow=1, t_firstcol=1)
546 virtual = nmo - homo(ispin)
547 NULLIFY (fm_struct_tmp)
549 nrow_global=virtual, ncol_global=virtual)
557 nrow=virtual, ncol=virtual, &
558 s_firstrow=homo(ispin) + 1, s_firstcol=homo(ispin) + 1, &
559 t_firstrow=1, t_firstcol=1)
562 ALLOCATE (eig_o(homo(ispin)))
563 ALLOCATE (eig_v(virtual))
570 ALLOCATE (eig_semi_can(nmo))
571 eig_semi_can = 0.0_dp
572 eig_semi_can(1:homo(ispin)) = eig_o(:)
573 eig_semi_can(homo(ispin) + 1:nmo) = eig_v(:)
576 NULLIFY (fm_struct_tmp)
578 nrow_global=homo(ispin), ncol_global=virtual)
586 nrow=homo(ispin), ncol=virtual, &
587 s_firstrow=1, s_firstcol=homo(ispin) + 1, &
588 t_firstrow=1, t_firstcol=1)
590 CALL parallel_gemm(transa=
'T', transb=
'N', m=homo(ispin), n=virtual, k=homo(ispin), alpha=1.0_dp, &
591 matrix_a=fm_o, matrix_b=fm_f_ov, beta=0.0_dp, matrix_c=fm_tmp)
593 CALL parallel_gemm(transa=
'N', transb=
'N', m=homo(ispin), n=virtual, k=virtual, alpha=1.0_dp, &
594 matrix_a=fm_tmp, matrix_b=fm_u, beta=0.0_dp, matrix_c=fm_f_ov)
598 nrow_local=nrow_local, &
599 ncol_local=ncol_local, &
600 row_indices=row_indices, &
601 col_indices=col_indices)
606 DO jjb = 1, ncol_local
607 j_global = col_indices(jjb)
608 DO iib = 1, nrow_local
609 i_global = row_indices(iib)
610 corr = corr + fm_f_ov%local_data(iib, jjb)**2.0_dp/ &
611 (eig_semi_can(i_global) - eig_semi_can(j_global + homo(ispin)))
616 rse_corr = rse_corr + corr
619 DEALLOCATE (eig_semi_can)
632 CALL para_env%sum(rse_corr)
634 CALL timestop(handle)
636 END SUBROUTINE non_diag_rse
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_scale(matrix, alpha_scalar)
...
subroutine, public dbcsr_copy(matrix_b, matrix_a, name, keep_sparsity, keep_imaginary)
...
subroutine, public dbcsr_init_p(matrix)
...
subroutine, public dbcsr_set(matrix, alpha)
...
subroutine, public dbcsr_release(matrix)
...
Routines that link DBCSR and CP2K concepts together.
subroutine, public cp_dbcsr_alloc_block_from_nbl(matrix, sab_orb, desymmetrize)
allocate the blocks of a dbcsr based on the neighbor list
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm)
Copy a DBCSR matrix to a BLACS matrix.
subroutine, public copy_fm_to_dbcsr(fm, matrix, keep_sparsity)
Copy a BLACS matrix to a dbcsr matrix.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_scale_and_add(alpha, matrix_a, beta, matrix_b)
calc A <- alpha*A + beta*B optimized for alpha == 1.0 (just add beta*B) and beta == 0....
used for collecting some of the diagonalization schemes available for cp_fm_type. cp_fm_power also mo...
subroutine, public choose_eigv_solver(matrix, eigenvectors, eigenvalues, info)
Choose the Eigensolver depending on which library is available ELPA seems to be unstable for small sy...
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
subroutine, public cp_fm_get_diag(matrix, diag)
returns the diagonal elements of a fm
subroutine, public cp_fm_get_info(matrix, name, nrow_global, ncol_global, nrow_block, ncol_block, nrow_local, ncol_local, row_indices, col_indices, local_data, context, nrow_locals, ncol_locals, matrix_struct, para_env)
returns all kind of information about the full matrix
subroutine, public cp_fm_to_fm_submat(msource, mtarget, nrow, ncol, s_firstrow, s_firstcol, t_firstrow, t_firstcol)
copy just a part ot the matrix
subroutine, public cp_fm_set_all(matrix, alpha, beta)
set all elements of a matrix to the same value, and optionally the diagonal to a different one
subroutine, public cp_fm_create(matrix, matrix_struct, name, use_sp)
creates a new full matrix with the given structure
Routines to calculate HFX energy and potential.
subroutine, public integrate_four_center(qs_env, x_data, ks_matrix, ehfx, rho_ao, hfx_section, para_env, geometry_did_change, irep, distribute_fock_matrix, ispin)
computes four center integrals for a full basis set and updates the Kohn-Sham-Matrix and energy....
Routines to calculate EXX in RPA and energy correction methods.
subroutine, public exx_pre_hfx(ext_hfx_section, x_data, reuse_hfx)
Prepare the external x_data for integration. Simply change the HFX fraction in case the qs_envx_data ...
subroutine, public exx_post_hfx(qs_env, x_data, reuse_hfx)
Revert back to the proper HFX fraction in case qs_envx_data is reused.
subroutine, public hfx_ri_update_ks(qs_env, ri_data, ks_matrix, ehfx, mos, rho_ao, geometry_did_change, nspins, hf_fraction)
...
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
Types needed for MP2 calculations.
basic linear algebra operations for full matrixes
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, tb_tblite)
Get the QUICKSTEP environment.
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public compute_matrix_vxc(qs_env, v_rspace, matrix_vxc)
compute matrix_vxc, defined via the potential created by qs_vxc_create ignores things like tau functi...
Define the neighbor list data types and the corresponding functionality.
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
subroutine, public qs_vxc_create(ks_env, rho_struct, xc_section, vxc_rho, vxc_tau, exc, just_energy, edisp, dispersion_env, adiabatic_rescale_factor, pw_env_external)
calculates and allocates the xc potential, already reducing it to the dependence on rho and the one o...
Routines to compute singles correction to RPA (RSE)
subroutine, public rse_energy(qs_env, mp2_env, para_env, dft_control, mo_coeff, homo, eigenval)
Single excitations energy corrections for RPA.
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
stores all the informations relevant to an mpi environment
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...
keeps the density in various representations, keeping track of which ones are valid.