(git:b977e33)
rt_hfx_utils.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief Utility functions that are needed for RTP/EMD in combination with
10 !> HF or hybrid functionals (needs to deal with imaginary KS and P
11 !> \par History
12 !> 2014 created [fschiff]
13 !> \author Florina Schiffmann
14 ! **************************************************************************************************
16  USE admm_types, ONLY: get_admm_env,&
18  USE cp_control_types, ONLY: dft_control_type
22  USE dbcsr_api, ONLY: dbcsr_create,&
23  dbcsr_p_type,&
24  dbcsr_set,&
25  dbcsr_type_antisymmetric
26  USE kinds, ONLY: dp
27  USE qs_environment_types, ONLY: get_qs_env,&
28  qs_environment_type
29  USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
30  USE qs_rho_types, ONLY: qs_rho_get,&
31  qs_rho_set,&
32  qs_rho_type
33 #include "../base/base_uses.f90"
34 
35  IMPLICIT NONE
36  PRIVATE
37 
38  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'rt_hfx_utils'
39 
40  PUBLIC :: rtp_hfx_rebuild
41 
42 !***
43 CONTAINS
44 ! **************************************************************************************************
45 !> \brief rebuilds the structures of P and KS (imaginary) in case S changed
46 !> \param qs_env ...
47 !> \author Florian Schiffmann
48 ! **************************************************************************************************
49  SUBROUTINE rtp_hfx_rebuild(qs_env)
50  TYPE(qs_environment_type), POINTER :: qs_env
51 
52  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks_aux_im, matrix_s_aux, &
53  rho_aux_ao_im
54  TYPE(dft_control_type), POINTER :: dft_control
55  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
56  POINTER :: sab_aux
57  TYPE(qs_rho_type), POINTER :: rho_aux
58 
59  NULLIFY (dft_control)
60  NULLIFY (sab_aux, rho_aux, rho_aux_ao_im, matrix_ks_aux_im, matrix_s_aux)
61 
62  CALL get_qs_env(qs_env, &
63  dft_control=dft_control)
64 
65  IF (dft_control%do_admm) THEN
66  CALL get_admm_env(qs_env%admm_env, &
67  matrix_s_aux_fit=matrix_s_aux, &
68  sab_aux_fit=sab_aux, &
69  rho_aux_fit=rho_aux, &
70  matrix_ks_aux_fit_im=matrix_ks_aux_im)
71  CALL qs_rho_get(rho_aux, rho_ao_im=rho_aux_ao_im)
72  CALL rebuild_matrices(rho_aux_ao_im, matrix_ks_aux_im, sab_aux, matrix_s_aux, &
73  dft_control%nspins)
74  CALL set_admm_env(qs_env%admm_env, matrix_ks_aux_fit_im=matrix_ks_aux_im)
75  CALL qs_rho_set(rho_aux, rho_ao_im=rho_aux_ao_im)
76  END IF
77 
78  END SUBROUTINE rtp_hfx_rebuild
79 
80 ! **************************************************************************************************
81 !> \brief does the actual rebuilding of P and KS (imaginary) in case S changed
82 !> \param matrix_p ...
83 !> \param matrix_ks ...
84 !> \param sab_orb ...
85 !> \param matrix_s ...
86 !> \param nspins ...
87 !> \author Florian Schiffmann
88 ! **************************************************************************************************
89 
90  SUBROUTINE rebuild_matrices(matrix_p, matrix_ks, sab_orb, matrix_s, nspins)
91  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p, matrix_ks
92  TYPE(neighbor_list_set_p_type), DIMENSION(:), &
93  POINTER :: sab_orb
94  TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
95  INTEGER, INTENT(in) :: nspins
96 
97  INTEGER :: i
98 
99  IF (ASSOCIATED(matrix_p)) THEN
100  CALL dbcsr_deallocate_matrix_set(matrix_p)
101  END IF
102  ! Create a new density matrix set
103  CALL dbcsr_allocate_matrix_set(matrix_p, nspins)
104  DO i = 1, nspins
105  ALLOCATE (matrix_p(i)%matrix)
106  CALL dbcsr_create(matrix=matrix_p(i)%matrix, template=matrix_s(1)%matrix, &
107  name="Imaginary density matrix", matrix_type=dbcsr_type_antisymmetric, nze=0)
108  CALL cp_dbcsr_alloc_block_from_nbl(matrix_p(i)%matrix, sab_orb)
109  CALL dbcsr_set(matrix_p(i)%matrix, 0.0_dp)
110  END DO
111 
112  IF (ASSOCIATED(matrix_ks)) THEN
113  CALL dbcsr_deallocate_matrix_set(matrix_ks)
114  END IF
115  ! Create a new density matrix set
116  CALL dbcsr_allocate_matrix_set(matrix_ks, nspins)
117  DO i = 1, nspins
118  ALLOCATE (matrix_ks(i)%matrix)
119  CALL dbcsr_create(matrix=matrix_ks(i)%matrix, template=matrix_s(1)%matrix, &
120  name="Imaginary Kohn-Sham matrix", matrix_type=dbcsr_type_antisymmetric, nze=0)
121  CALL cp_dbcsr_alloc_block_from_nbl(matrix_ks(i)%matrix, sab_orb)
122  CALL dbcsr_set(matrix_ks(i)%matrix, 0.0_dp)
123  END DO
124 
125  END SUBROUTINE rebuild_matrices
126 
127 END MODULE rt_hfx_utils
Types and set/get functions for auxiliary density matrix methods.
Definition: admm_types.F:15
subroutine, public get_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Get routine for the ADMM env.
Definition: admm_types.F:593
subroutine, public set_admm_env(admm_env, mo_derivs_aux_fit, mos_aux_fit, sab_aux_fit, sab_aux_fit_asymm, sab_aux_fit_vs_orb, matrix_s_aux_fit, matrix_s_aux_fit_kp, matrix_s_aux_fit_vs_orb, matrix_s_aux_fit_vs_orb_kp, task_list_aux_fit, matrix_ks_aux_fit, matrix_ks_aux_fit_kp, matrix_ks_aux_fit_im, matrix_ks_aux_fit_dft, matrix_ks_aux_fit_hfx, matrix_ks_aux_fit_dft_kp, matrix_ks_aux_fit_hfx_kp, rho_aux_fit, rho_aux_fit_buffer, admm_dm)
Set routine for the ADMM env.
Definition: admm_types.F:677
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
DBCSR operations in CP2K.
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
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_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, 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, rhs)
Get the QUICKSTEP environment.
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...
Definition: qs_rho_types.F:18
subroutine, public qs_rho_set(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)
...
Definition: qs_rho_types.F:308
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...
Definition: qs_rho_types.F:229
Utility functions that are needed for RTP/EMD in combination with HF or hybrid functionals (needs to ...
Definition: rt_hfx_utils.F:15
subroutine, public rtp_hfx_rebuild(qs_env)
rebuilds the structures of P and KS (imaginary) in case S changed
Definition: rt_hfx_utils.F:50