(git:9a40378)
Loading...
Searching...
No Matches
qs_update_s_mstruct.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! *****************************************************************************
9!> \brief qs_environment methods that use many other modules
10!> \par History
11!> 09.2002 created [fawzi]
12!> - local atom distribution (25.06.2003,MK)
13!> \author Fawzi Mohamed
14! *****************************************************************************
23 USE kinds, ONLY: default_string_length,&
24 dp
25 USE pw_methods, ONLY: pw_transfer
26 USE pw_types, ONLY: pw_c1d_gs_type,&
33 USE qs_ks_types, ONLY: get_ks_env,&
38 USE qs_rho_types, ONLY: qs_rho_type
44#include "./base/base_uses.f90"
45
46 IMPLICIT NONE
47 PRIVATE
48
49 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
50 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_update_s_mstruct'
51
53!***
54CONTAINS
55
56! *****************************************************************************
57!> \brief updates the s_mstruct to reflect the new overlap structure,
58!> and also updates rho_core distribution.
59!> Should be called after the atoms have moved and the new overlap
60!> has been calculated.
61!> \param qs_env the environment to update
62!> \par History
63!> 07.2002 created [fawzi]
64!> \author Fawzi Mohamed
65! **************************************************************************************************
66 SUBROUTINE qs_env_update_s_mstruct(qs_env)
67 TYPE(qs_environment_type), POINTER :: qs_env
68
69 CHARACTER(len=*), PARAMETER :: routinen = 'qs_env_update_s_mstruct'
70
71 INTEGER :: handle, nk
72 LOGICAL :: do_ppl
73 REAL(kind=dp) :: wtot
74 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: cw
75 TYPE(dft_control_type), POINTER :: dft_control
76 TYPE(pw_c1d_gs_type), POINTER :: rho_core, rho_nlcc_g
77 TYPE(pw_r3d_rs_type), POINTER :: rho_nlcc, vppl, xcint_weights
78
79 CALL timeset(routinen, handle)
80
81 cpassert(ASSOCIATED(qs_env))
82
83 NULLIFY (dft_control)
84 CALL get_qs_env(qs_env, &
85 dft_control=dft_control)
86
87 ! *** updates rho core ***
88 NULLIFY (rho_core)
89 CALL get_qs_env(qs_env, rho_core=rho_core)
90 IF (dft_control%qs_control%gapw) THEN
91 qs_env%qs_charges%total_rho_core_rspace = qs_env%local_rho_set%rhoz_tot
92 ! Initial CNEO quantum nuclear charge density is a simple Zeff sum.
93 ! Later it will be calculated from numerical integration during SCF.
94 qs_env%qs_charges%total_rho1_hard_nuc = qs_env%local_rho_set%rhoz_cneo_tot
95 IF (dft_control%qs_control%gapw_control%nopaw_as_gpw) THEN
96 cpassert(ASSOCIATED(rho_core))
97 CALL calculate_rho_core(rho_core, &
98 qs_env%qs_charges%total_rho_core_rspace, qs_env, only_nopaw=.true.)
99 ELSE
100 IF (ASSOCIATED(rho_core)) THEN
101 CALL rho_core%release()
102 DEALLOCATE (rho_core)
103 END IF
104 END IF
105 ! force analytic ppl calculation
106 dft_control%qs_control%do_ppl_method = do_ppl_analytic
107 ELSE IF (dft_control%qs_control%semi_empirical) THEN
108 !??
109 ELSE IF (dft_control%qs_control%dftb) THEN
110 !??
111 ELSE IF (dft_control%qs_control%xtb) THEN
112 !??
113 ELSE
114 cpassert(ASSOCIATED(rho_core))
115 CALL calculate_rho_core(rho_core, &
116 qs_env%qs_charges%total_rho_core_rspace, qs_env)
117 END IF
118
119 ! calculate local pseudopotential on grid
120 do_ppl = dft_control%qs_control%do_ppl_method == do_ppl_grid
121 IF (do_ppl) THEN
122 NULLIFY (vppl)
123 CALL get_qs_env(qs_env, vppl=vppl)
124 cpassert(ASSOCIATED(vppl))
125 CALL calculate_ppl_grid(vppl, qs_env)
126 END IF
127
128 ! compute the rho_nlcc
129 NULLIFY (rho_nlcc, rho_nlcc_g)
130 CALL get_qs_env(qs_env, rho_nlcc=rho_nlcc, rho_nlcc_g=rho_nlcc_g)
131 IF (ASSOCIATED(rho_nlcc)) THEN
132 CALL calculate_rho_nlcc(rho_nlcc, qs_env)
133 CALL pw_transfer(rho_nlcc, rho_nlcc_g)
134 END IF
135
136 ! compute the xcint_weights
137 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
138 IF (dft_control%qs_control%gapw_control%accurate_xcint) THEN
139 CALL get_qs_env(qs_env, xcint_weights=xcint_weights, nkind=nk)
140 ALLOCATE (cw(nk))
141 cw = 1.0_dp
142 CALL calculate_rho_core(xcint_weights, wtot, qs_env, &
143 dft_control%qs_control%gapw_control%aw, cw)
144 xcint_weights%array = 1.0_dp + xcint_weights%array
145 DEALLOCATE (cw)
146 END IF
147 END IF
148
149 ! allocates and creates the task_list
150 CALL qs_create_task_list(qs_env)
151
152 ! *** environment for ddapc ***
153 IF (ASSOCIATED(qs_env%cp_ddapc_env)) THEN
154 CALL cp_ddapc_release(qs_env%cp_ddapc_env)
155 DEALLOCATE (qs_env%cp_ddapc_env)
156 END IF
157 CALL cp_ddapc_init(qs_env)
158
159 ! *** tell ks_env ***
160 CALL qs_ks_did_change(qs_env%ks_env, s_mstruct_changed=.true.)
161
162 ! *** Updates rho structure ***
163 CALL qs_env_rebuild_rho(qs_env=qs_env)
164
165 ! *** tell scf_env ***
166 IF (ASSOCIATED(qs_env%scf_env)) THEN
167 CALL scf_env_did_change(qs_env%scf_env)
168 END IF
169
170 CALL timestop(handle)
171
172 END SUBROUTINE qs_env_update_s_mstruct
173
174! *****************************************************************************
175!> \brief ...
176!> \param qs_env ...
177! **************************************************************************************************
178 SUBROUTINE qs_create_task_list(qs_env)
179 TYPE(qs_environment_type), POINTER :: qs_env
180
181 CHARACTER(len=*), PARAMETER :: routinen = 'qs_create_task_list'
182
183 CHARACTER(LEN=default_string_length) :: basis_type
184 INTEGER :: handle, isub
185 LOGICAL :: skip_load_balance_distributed, soft_valid
186 TYPE(dft_control_type), POINTER :: dft_control
187 TYPE(qs_ks_env_type), POINTER :: ks_env
188 TYPE(task_list_type), POINTER :: task_list
189
190 CALL timeset(routinen, handle)
191 NULLIFY (ks_env, dft_control)
192 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
193
194 soft_valid = (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
195 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
196 IF (.NOT. (dft_control%qs_control%semi_empirical &
197 .OR. dft_control%qs_control%xtb &
198 .OR. dft_control%qs_control%dftb)) THEN
199 ! generate task lists (non-soft)
200 IF (.NOT. dft_control%qs_control%gapw) THEN
201 CALL get_ks_env(ks_env, task_list=task_list)
202 IF (.NOT. ASSOCIATED(task_list)) THEN
203 CALL allocate_task_list(task_list)
204 CALL set_ks_env(ks_env, task_list=task_list)
205 END IF
206 CALL generate_qs_task_list(ks_env, task_list, basis_type="ORB", &
207 reorder_rs_grid_ranks=.true., &
208 skip_load_balance_distributed=skip_load_balance_distributed)
209 END IF
210 ! generate the soft task list
211 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
212 CALL get_ks_env(ks_env, task_list_soft=task_list)
213 IF (.NOT. ASSOCIATED(task_list)) THEN
214 CALL allocate_task_list(task_list)
215 CALL set_ks_env(ks_env, task_list_soft=task_list)
216 END IF
217 CALL generate_qs_task_list(ks_env, task_list, basis_type="ORB_SOFT", &
218 reorder_rs_grid_ranks=.true., &
219 skip_load_balance_distributed=skip_load_balance_distributed)
220 END IF
221 END IF
222
223 IF (dft_control%qs_control%do_kg) THEN
224
225 IF (qs_env%kg_env%tnadd_method == kg_tnadd_embed .OR. &
226 qs_env%kg_env%tnadd_method == kg_tnadd_embed_ri) THEN
227
228 IF (ASSOCIATED(qs_env%kg_env%subset)) THEN
229 DO isub = 1, qs_env%kg_env%nsubsets
230 IF (ASSOCIATED(qs_env%kg_env%subset(isub)%task_list)) &
231 CALL deallocate_task_list(qs_env%kg_env%subset(isub)%task_list)
232 END DO
233 ELSE
234 ALLOCATE (qs_env%kg_env%subset(qs_env%kg_env%nsubsets))
235 END IF
236
237 IF (soft_valid) THEN
238 basis_type = "ORB_SOFT"
239 ELSE
240 basis_type = "ORB"
241 END IF
242
243 DO isub = 1, qs_env%kg_env%nsubsets
244 CALL allocate_task_list(qs_env%kg_env%subset(isub)%task_list)
245 ! generate the subset task list from the neighborlist
246 CALL generate_qs_task_list(ks_env, qs_env%kg_env%subset(isub)%task_list, &
247 basis_type=basis_type, &
248 reorder_rs_grid_ranks=.false., &
249 skip_load_balance_distributed=skip_load_balance_distributed, &
250 sab_orb_external=qs_env%kg_env%subset(isub)%sab_orb)
251 END DO
252
253 END IF
254
255 END IF
256
257 CALL timestop(handle)
258
259 END SUBROUTINE qs_create_task_list
260
261! *****************************************************************************
262!> \brief rebuilds the rho structure, making sure that everything is allocated
263!> and has the right size
264!> \param qs_env the environment in which rho should be rebuilt
265!> \param rebuild_ao if it is necessary to rebuild rho_ao. Defaults to true.
266!> \param rebuild_grids if it in necessary to rebuild rho_r and rho_g.
267!> Defaults to false.
268!> \par History
269!> 10.2002 created [fawzi]
270!> \author Fawzi Mohamed
271!> \note
272!> needs updated pw pools, s_mstruct and h.
273!> The use of p to keep the structure of h (needed for the forces)
274!> is ugly and should be removed.
275!> If necessary rho is created from scratch.
276! **************************************************************************************************
277 SUBROUTINE qs_env_rebuild_rho(qs_env, rebuild_ao, rebuild_grids)
278 TYPE(qs_environment_type), POINTER :: qs_env
279 LOGICAL, INTENT(in), OPTIONAL :: rebuild_ao, rebuild_grids
280
281 CHARACTER(len=*), PARAMETER :: routinen = 'qs_env_rebuild_rho'
282
283 INTEGER :: handle
284 LOGICAL :: do_admm, gapw_xc
285 TYPE(dft_control_type), POINTER :: dft_control
286 TYPE(qs_rho_type), POINTER :: rho, rho_external, rho_xc
287
288 NULLIFY (rho)
289 CALL timeset(routinen, handle)
290
291 CALL get_qs_env(qs_env, &
292 dft_control=dft_control, &
293 rho=rho, &
294 rho_xc=rho_xc, &
295 rho_external=rho_external)
296
297 gapw_xc = dft_control%qs_control%gapw_xc
298 do_admm = dft_control%do_admm
299 CALL qs_rho_rebuild(rho, qs_env=qs_env, &
300 rebuild_ao=rebuild_ao, rebuild_grids=rebuild_grids)
301
302 IF (gapw_xc) THEN
303 CALL qs_rho_rebuild(rho_xc, qs_env=qs_env, &
304 rebuild_ao=rebuild_ao, rebuild_grids=rebuild_grids)
305 END IF
306
307! ZMP rebuilding external density
308 IF (dft_control%apply_external_density) THEN
309 CALL qs_rho_rebuild(rho_external, qs_env=qs_env, &
310 rebuild_grids=rebuild_grids)
311 dft_control%read_external_density = .true.
312 END IF
313
314 CALL timestop(handle)
315
316 END SUBROUTINE qs_env_rebuild_rho
317
318END MODULE qs_update_s_mstruct
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
contains information regarding the decoupling/recoupling method of Bloechl
subroutine, public cp_ddapc_release(cp_ddapc_env)
...
Density Derived atomic point charges from a QM calculation (see Bloechl, J. Chem. Phys....
subroutine, public cp_ddapc_init(qs_env)
Initialize the cp_ddapc_environment.
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public kg_tnadd_embed_ri
integer, parameter, public kg_tnadd_embed
integer, parameter, public do_ppl_grid
integer, parameter, public do_ppl_analytic
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
Calculate the plane wave density by collocating the primitive Gaussian functions (pgf).
subroutine, public calculate_rho_nlcc(rho_nlcc, qs_env)
computes the density of the non-linear core correction on the grid
subroutine, public calculate_ppl_grid(vppl, qs_env)
computes the local pseudopotential (without erf term) on the grid
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 qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_rebuild(rho, qs_env, rebuild_ao, rebuild_grids, admm, pw_env_external)
rebuilds rho (if necessary allocating and initializing it)
superstucture that hold various representations of the density and keeps track of which ones are vali...
module that contains the definitions of the scf types
subroutine, public scf_env_did_change(scf_env)
function to be called to inform the scf_env about changes
qs_environment methods that use many other modules
subroutine, public qs_env_update_s_mstruct(qs_env)
updates the s_mstruct to reflect the new overlap structure, and also updates rho_core distribution....
generate the tasks lists used by collocate and integrate routines
subroutine, public generate_qs_task_list(ks_env, task_list, basis_type, reorder_rs_grid_ranks, skip_load_balance_distributed, pw_env_external, sab_orb_external)
...
types for task lists
subroutine, public deallocate_task_list(task_list)
deallocates the components and the object itself
subroutine, public allocate_task_list(task_list)
allocates and initialised the components of the task_list_type
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.