(git:71c3ab0)
Loading...
Searching...
No Matches
qs_gapw_densities.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
15 USE kinds, ONLY: dp
17 USE pw_env_types, ONLY: pw_env_get,&
25 USE qs_kind_types, ONLY: get_qs_kind,&
30 USE qs_rho0_types, ONLY: rho0_atom_type,&
36#include "./base/base_uses.f90"
37
38 IMPLICIT NONE
39
40 PRIVATE
41
42 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_gapw_densities'
43
44 PUBLIC :: prepare_gapw_den
45
46CONTAINS
47
48! **************************************************************************************************
49!> \brief ...
50!> \param qs_env ...
51!> \param local_rho_set ...
52!> \param do_rho0 ...
53!> \param kind_set_external can be provided to use different projectors/grids/basis than the default
54!> \param pw_env_sub ...
55! **************************************************************************************************
56 SUBROUTINE prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
57
58 TYPE(qs_environment_type), POINTER :: qs_env
59 TYPE(local_rho_type), OPTIONAL, POINTER :: local_rho_set
60 LOGICAL, INTENT(IN), OPTIONAL :: do_rho0
61 TYPE(qs_kind_type), DIMENSION(:), OPTIONAL, &
62 POINTER :: kind_set_external
63 TYPE(pw_env_type), OPTIONAL :: pw_env_sub
64
65 CHARACTER(len=*), PARAMETER :: routinen = 'prepare_gapw_den'
66
67 INTEGER :: handle, ikind, ispin, natom, nspins, &
68 output_unit
69 INTEGER, DIMENSION(:), POINTER :: atom_list
70 LOGICAL :: extern, my_do_rho0, paw_atom
71 REAL(dp) :: rho0_h_tot, rho1_h_aspin, rho1_h_spin, &
72 rho1_s_aspin, rho1_s_spin, tot_rs_int
73 REAL(dp), DIMENSION(:), POINTER :: rho1_h_tot, rho1_s_tot
74 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
75 TYPE(dft_control_type), POINTER :: dft_control
76 TYPE(gapw_control_type), POINTER :: gapw_control
77 TYPE(mp_para_env_type), POINTER :: para_env
78 TYPE(pw_pool_p_type), DIMENSION(:), POINTER :: my_pools
79 TYPE(qs_charges_type), POINTER :: qs_charges
80 TYPE(qs_kind_type), DIMENSION(:), POINTER :: my_kind_set
81 TYPE(realspace_grid_desc_p_type), DIMENSION(:), &
82 POINTER :: my_rs_descs
83 TYPE(realspace_grid_type), DIMENSION(:), POINTER :: my_rs_grids
84 TYPE(rho0_atom_type), DIMENSION(:), POINTER :: rho0_atom_set
85 TYPE(rho0_mpole_type), POINTER :: rho0_mpole
86 TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
87 TYPE(rhoz_cneo_type), DIMENSION(:), POINTER :: rhoz_cneo_set
88
89 CALL timeset(routinen, handle)
90
91 NULLIFY (atomic_kind_set)
92 NULLIFY (my_kind_set)
93 NULLIFY (dft_control)
94 NULLIFY (gapw_control)
95 NULLIFY (para_env)
96 NULLIFY (atom_list)
97 NULLIFY (rho0_mpole)
98 NULLIFY (qs_charges)
99 NULLIFY (rho1_h_tot, rho1_s_tot)
100 NULLIFY (rho_atom_set)
101 NULLIFY (rho0_atom_set)
102
103 my_do_rho0 = .true.
104 IF (PRESENT(do_rho0)) my_do_rho0 = do_rho0
105
106 output_unit = cp_logger_get_default_io_unit()
107
108 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, &
109 para_env=para_env, &
110 qs_charges=qs_charges, &
111 qs_kind_set=my_kind_set, &
112 atomic_kind_set=atomic_kind_set, &
113 rho0_mpole=rho0_mpole, &
114 rho_atom_set=rho_atom_set, &
115 rho0_atom_set=rho0_atom_set, &
116 rhoz_cneo_set=rhoz_cneo_set)
117
118 gapw_control => dft_control%qs_control%gapw_control
119
120 ! If TDDFPT%MGRID is defined, overwrite QS grid info accordingly
121 IF (PRESENT(local_rho_set)) THEN
122 rho_atom_set => local_rho_set%rho_atom_set
123 rhoz_cneo_set => local_rho_set%rhoz_cneo_set
124 IF (my_do_rho0) THEN
125 rho0_mpole => local_rho_set%rho0_mpole
126 rho0_atom_set => local_rho_set%rho0_atom_set
127 END IF
128 END IF
129
130 extern = .false.
131 IF (PRESENT(kind_set_external)) THEN
132 cpassert(ASSOCIATED(kind_set_external))
133 my_kind_set => kind_set_external
134 extern = .true.
135 END IF
136
137 nspins = dft_control%nspins
138
139 rho0_h_tot = 0.0_dp
140 ALLOCATE (rho1_h_tot(1:nspins), rho1_s_tot(1:nspins))
141 rho1_h_tot = 0.0_dp
142 rho1_s_tot = 0.0_dp
143
144 rho1_h_spin = 0.0_dp
145 rho1_s_spin = 0.0_dp
146 rho1_h_aspin = 0.0_dp
147 rho1_s_aspin = 0.0_dp
148
149 DO ikind = 1, SIZE(atomic_kind_set)
150 CALL get_atomic_kind(atomic_kind_set(ikind), atom_list=atom_list, natom=natom)
151 CALL get_qs_kind(my_kind_set(ikind), paw_atom=paw_atom)
152
153 !Calculate rho1_h and rho1_s on the radial grids centered on the atomic position
154 IF (paw_atom) THEN
155 CALL calculate_rho_atom(para_env, rho_atom_set, my_kind_set(ikind), &
156 atom_list, natom, nspins, rho1_h_tot, rho1_s_tot, &
157 rho1_h_spin, rho1_s_spin, rho1_h_aspin, rho1_s_aspin)
158 END IF
159
160 !Calculate rho0_h and rho0_s on the radial grids centered on the atomic position
161 IF (my_do_rho0) THEN
162 CALL calculate_rho0_atom(gapw_control, rho_atom_set, rhoz_cneo_set, rho0_atom_set, &
163 rho0_mpole, atom_list, natom, ikind, my_kind_set(ikind), &
164 rho0_h_tot)
165 END IF
166 END DO
167
168 !Do not mess with charges if using a non-default kind_set
169 IF (.NOT. extern) THEN
170 CALL para_env%sum(rho1_h_tot)
171 CALL para_env%sum(rho1_s_tot)
172 DO ispin = 1, nspins
173 qs_charges%total_rho1_hard(ispin) = -rho1_h_tot(ispin)
174 qs_charges%total_rho1_soft(ispin) = -rho1_s_tot(ispin)
175 END DO
176 !spin
177 CALL para_env%sum(rho1_h_spin)
178 CALL para_env%sum(rho1_s_spin)
179 CALL para_env%sum(rho1_h_aspin)
180 CALL para_env%sum(rho1_s_aspin)
181 qs_charges%total_rho_hard_spin = rho1_h_spin
182 qs_charges%total_rho_soft_spin = rho1_s_spin
183 qs_charges%total_rho_hard_abs_spin = rho1_h_aspin
184 qs_charges%total_rho_soft_abs_spin = rho1_s_aspin
185
186 IF (my_do_rho0) THEN
187 rho0_mpole%total_rho0_h = -rho0_h_tot
188
189 ! When MGRID is defined within TDDFPT
190 IF (PRESENT(pw_env_sub)) THEN
191 ! Find pool
192 NULLIFY (my_pools, my_rs_grids, my_rs_descs)
193 CALL pw_env_get(pw_env=pw_env_sub, rs_grids=my_rs_grids, &
194 rs_descs=my_rs_descs, pw_pools=my_pools)
195 ! Put the rho0_soft on the global grid
196 CALL put_rho0_on_grid(qs_env, rho0_mpole, tot_rs_int, my_pools=my_pools, &
197 my_rs_grids=my_rs_grids, my_rs_descs=my_rs_descs)
198 ELSE
199 ! Put the rho0_soft on the global grid
200 CALL put_rho0_on_grid(qs_env, rho0_mpole, tot_rs_int)
201 END IF
202
203 IF (abs(rho0_h_tot) >= 1.0e-5_dp) THEN
204 IF (abs(1.0_dp - abs(tot_rs_int/rho0_h_tot)) > 1.0e-3_dp) THEN
205 IF (output_unit > 0) THEN
206 WRITE (output_unit, '(/,72("*"))')
207 WRITE (output_unit, '(T2,A,T66,1E20.8)') &
208 "WARNING: rho0 calculated on the local grid is :", -rho0_h_tot, &
209 " rho0 calculated on the global grid is :", tot_rs_int
210 WRITE (output_unit, '(T2,A)') &
211 " bad integration"
212 WRITE (output_unit, '(72("*"),/)')
213 END IF
214 END IF
215 END IF
216 qs_charges%total_rho0_soft_rspace = tot_rs_int
217 qs_charges%total_rho0_hard_lebedev = rho0_h_tot
218 IF (rho0_mpole%do_cneo) THEN
219 ! put soft tails of quantum nuclear charge densities on the global grid
220 CALL put_rhoz_cneo_s_on_grid(qs_env, rho0_mpole, rhoz_cneo_set, tot_rs_int)
221 IF (abs(rho0_mpole%tot_rhoz_cneo_s) >= 1.0e-5_dp) THEN
222 IF (abs(1.0_dp - abs(tot_rs_int/rho0_mpole%tot_rhoz_cneo_s)) > 1.0e-3_dp) THEN
223 IF (output_unit > 0) THEN
224 WRITE (output_unit, '(/,72("*"))')
225 WRITE (output_unit, '(T2,A,T66,1E20.8)') &
226 "WARNING: rhoz_cneo_s calculated on the local grid is :", &
227 rho0_mpole%tot_rhoz_cneo_s, &
228 " rhoz_cneo_s calculated on the global grid is :", tot_rs_int
229 WRITE (output_unit, '(T2,A)') &
230 " bad integration"
231 WRITE (output_unit, '(72("*"),/)')
232 END IF
233 END IF
234 END IF
235 qs_charges%total_rho1_soft_nuc_rspace = tot_rs_int
236 qs_charges%total_rho1_soft_nuc_lebedev = rho0_mpole%tot_rhoz_cneo_s
237 ELSE
238 qs_charges%total_rho1_soft_nuc_rspace = 0.0_dp
239 END IF
240 ELSE
241 qs_charges%total_rho0_hard_lebedev = 0.0_dp
242 END IF
243 END IF
244
245 DEALLOCATE (rho1_h_tot, rho1_s_tot)
246
247 CALL timestop(handle)
248
249 END SUBROUTINE prepare_gapw_den
250
251END MODULE qs_gapw_densities
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
Interface to the message passing library MPI.
container for various plainwaves related things
subroutine, public pw_env_get(pw_env, pw_pools, cube_info, gridlevel_info, auxbas_pw_pool, auxbas_grid, auxbas_rs_desc, auxbas_rs_grid, rs_descs, rs_grids, xc_pw_pool, vdw_pw_pool, poisson_env, interp_section)
returns the various attributes of the pw env
Manages a pool of grids (to be used for example as tmp objects), but can also be used to instantiate ...
container for information about total charges on the grids
CNEO soft nuclear densities on the global grid (see J. Chem. Theory Comput. 2025, 21,...
subroutine, public put_rhoz_cneo_s_on_grid(qs_env, rho0, rhoz_cneo_set, tot_rs_int)
...
Types used by CNEO-DFT (see J. Chem. Theory Comput. 2025, 21, 16, 7865–7877)
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, mimic, 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, sab_cneo, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public prepare_gapw_den(qs_env, local_rho_set, do_rho0, kind_set_external, pw_env_sub)
...
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind(qs_kind, basis_set, basis_type, ncgf, nsgf, all_potential, tnadd_potential, gth_potential, sgp_potential, upf_potential, cneo_potential, se_parameter, dftb_parameter, xtb_parameter, dftb3_param, zatom, zeff, elec_conf, mao, lmax_dftb, alpha_core_charge, ccore_charge, core_charge, core_charge_radius, paw_proj_set, paw_atom, hard_radius, hard0_radius, max_rad_local, covalent_radius, vdw_radius, gpw_type_forced, harmonics, max_iso_not0, max_s_harm, grid_atom, ngrid_ang, ngrid_rad, lmax_rho0, dft_plus_u_atom, l_of_dft_plus_u, n_of_dft_plus_u, u_minus_j, u_of_dft_plus_u, j_of_dft_plus_u, alpha_of_dft_plus_u, beta_of_dft_plus_u, j0_of_dft_plus_u, occupation_of_dft_plus_u, dispersion, bs_occupation, magnetization, no_optimize, addel, laddel, naddel, orbitals, max_scf, eps_scf, smear, u_ramping, u_minus_j_target, eps_u_ramping, init_u_ramping_each_scf, reltmat, ghost, monovalent, floating, name, element_symbol, pao_basis_size, pao_model_file, pao_potentials, pao_descriptors, nelec)
Get attributes of an atomic kind.
subroutine, public put_rho0_on_grid(qs_env, rho0, tot_rs_int, my_pools, my_rs_grids, my_rs_descs)
...
subroutine, public calculate_rho0_atom(gapw_control, rho_atom_set, rhoz_cneo_set, rho0_atom_set, rho0_mp, a_list, natom, ikind, qs_kind, rho0_h_tot)
...
subroutine, public calculate_rho_atom(para_env, rho_atom_set, qs_kind, atom_list, natom, nspins, tot_rho1_h, tot_rho1_s, rho1_h_spin, rho1_s_spin, rho1_h_aspin, rho1_s_aspin)
...
Provides all information about an atomic kind.
stores all the informations relevant to an mpi environment
contained for different pw related things
to create arrays of pools
Container for information about total charges on the grids.
Provides all information about a quickstep kind.