(git:936074a)
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-2025 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! *****************************************************************************
24 USE pw_methods, ONLY: pw_transfer
25 USE pw_types, ONLY: pw_c1d_gs_type,&
32 USE qs_ks_types, ONLY: get_ks_env,&
37 USE qs_rho_types, ONLY: qs_rho_type
43#include "./base/base_uses.f90"
44
45 IMPLICIT NONE
46 PRIVATE
47
48 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
49 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_update_s_mstruct'
50
52!***
53CONTAINS
54
55! *****************************************************************************
56!> \brief updates the s_mstruct to reflect the new overlap structure,
57!> and also updates rho_core distribution.
58!> Should be called after the atoms have moved and the new overlap
59!> has been calculated.
60!> \param qs_env the environment to update
61!> \par History
62!> 07.2002 created [fawzi]
63!> \author Fawzi Mohamed
64! **************************************************************************************************
65 SUBROUTINE qs_env_update_s_mstruct(qs_env)
66 TYPE(qs_environment_type), POINTER :: qs_env
67
68 CHARACTER(len=*), PARAMETER :: routinen = 'qs_env_update_s_mstruct'
69
70 INTEGER :: handle
71 LOGICAL :: do_ppl
72 TYPE(dft_control_type), POINTER :: dft_control
73 TYPE(pw_c1d_gs_type), POINTER :: rho_core, rho_nlcc_g
74 TYPE(pw_r3d_rs_type), POINTER :: rho_nlcc, vppl
75
76 CALL timeset(routinen, handle)
77
78 cpassert(ASSOCIATED(qs_env))
79
80 NULLIFY (dft_control)
81 CALL get_qs_env(qs_env, &
82 dft_control=dft_control)
83
84 ! *** updates rho core ***
85 NULLIFY (rho_core)
86 CALL get_qs_env(qs_env, rho_core=rho_core)
87 IF (dft_control%qs_control%gapw) THEN
88 qs_env%qs_charges%total_rho_core_rspace = qs_env%local_rho_set%rhoz_tot
89 ! Initial CNEO quantum nuclear charge density is a simple Zeff sum.
90 ! Later it will be calculated from numerical integration during SCF.
91 qs_env%qs_charges%total_rho1_hard_nuc = qs_env%local_rho_set%rhoz_cneo_tot
92 IF (dft_control%qs_control%gapw_control%nopaw_as_gpw) THEN
93 cpassert(ASSOCIATED(rho_core))
94 CALL calculate_rho_core(rho_core, &
95 qs_env%qs_charges%total_rho_core_rspace, qs_env, only_nopaw=.true.)
96 ELSE
97 IF (ASSOCIATED(rho_core)) THEN
98 CALL rho_core%release()
99 DEALLOCATE (rho_core)
100 END IF
101 END IF
102 ! force analytic ppl calculation
103 dft_control%qs_control%do_ppl_method = do_ppl_analytic
104 ELSE IF (dft_control%qs_control%semi_empirical) THEN
105 !??
106 ELSE IF (dft_control%qs_control%dftb) THEN
107 !??
108 ELSE IF (dft_control%qs_control%xtb) THEN
109 !??
110 ELSE
111 cpassert(ASSOCIATED(rho_core))
112 CALL calculate_rho_core(rho_core, &
113 qs_env%qs_charges%total_rho_core_rspace, qs_env)
114 END IF
115
116 ! calculate local pseudopotential on grid
117 do_ppl = dft_control%qs_control%do_ppl_method == do_ppl_grid
118 IF (do_ppl) THEN
119 NULLIFY (vppl)
120 CALL get_qs_env(qs_env, vppl=vppl)
121 cpassert(ASSOCIATED(vppl))
122 CALL calculate_ppl_grid(vppl, qs_env)
123 END IF
124
125 ! compute the rho_nlcc
126 NULLIFY (rho_nlcc, rho_nlcc_g)
127 CALL get_qs_env(qs_env, rho_nlcc=rho_nlcc, rho_nlcc_g=rho_nlcc_g)
128 IF (ASSOCIATED(rho_nlcc)) THEN
129 CALL calculate_rho_nlcc(rho_nlcc, qs_env)
130 CALL pw_transfer(rho_nlcc, rho_nlcc_g)
131 END IF
132
133 ! allocates and creates the task_list
134 CALL qs_create_task_list(qs_env)
135
136 ! *** environment for ddapc ***
137 IF (ASSOCIATED(qs_env%cp_ddapc_env)) THEN
138 CALL cp_ddapc_release(qs_env%cp_ddapc_env)
139 DEALLOCATE (qs_env%cp_ddapc_env)
140 END IF
141 CALL cp_ddapc_init(qs_env)
142
143 ! *** tell ks_env ***
144 CALL qs_ks_did_change(qs_env%ks_env, s_mstruct_changed=.true.)
145
146 ! *** Updates rho structure ***
147 CALL qs_env_rebuild_rho(qs_env=qs_env)
148
149 ! *** tell scf_env ***
150 IF (ASSOCIATED(qs_env%scf_env)) THEN
151 CALL scf_env_did_change(qs_env%scf_env)
152 END IF
153
154 CALL timestop(handle)
155
156 END SUBROUTINE qs_env_update_s_mstruct
157
158! *****************************************************************************
159!> \brief ...
160!> \param qs_env ...
161! **************************************************************************************************
162 SUBROUTINE qs_create_task_list(qs_env)
163 TYPE(qs_environment_type), POINTER :: qs_env
164
165 CHARACTER(len=*), PARAMETER :: routinen = 'qs_create_task_list'
166
167 CHARACTER(LEN=default_string_length) :: basis_type
168 INTEGER :: handle, isub
169 LOGICAL :: skip_load_balance_distributed, soft_valid
170 TYPE(dft_control_type), POINTER :: dft_control
171 TYPE(qs_ks_env_type), POINTER :: ks_env
172 TYPE(task_list_type), POINTER :: task_list
173
174 CALL timeset(routinen, handle)
175 NULLIFY (ks_env, dft_control)
176 CALL get_qs_env(qs_env, ks_env=ks_env, dft_control=dft_control)
177
178 soft_valid = (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc)
179 skip_load_balance_distributed = dft_control%qs_control%skip_load_balance_distributed
180 IF (.NOT. (dft_control%qs_control%semi_empirical &
181 .OR. dft_control%qs_control%xtb &
182 .OR. dft_control%qs_control%dftb)) THEN
183 ! generate task lists (non-soft)
184 IF (.NOT. dft_control%qs_control%gapw) THEN
185 CALL get_ks_env(ks_env, task_list=task_list)
186 IF (.NOT. ASSOCIATED(task_list)) THEN
187 CALL allocate_task_list(task_list)
188 CALL set_ks_env(ks_env, task_list=task_list)
189 END IF
190 CALL generate_qs_task_list(ks_env, task_list, basis_type="ORB", &
191 reorder_rs_grid_ranks=.true., &
192 skip_load_balance_distributed=skip_load_balance_distributed)
193 END IF
194 ! generate the soft task list
195 IF (dft_control%qs_control%gapw .OR. dft_control%qs_control%gapw_xc) THEN
196 CALL get_ks_env(ks_env, task_list_soft=task_list)
197 IF (.NOT. ASSOCIATED(task_list)) THEN
198 CALL allocate_task_list(task_list)
199 CALL set_ks_env(ks_env, task_list_soft=task_list)
200 END IF
201 CALL generate_qs_task_list(ks_env, task_list, basis_type="ORB_SOFT", &
202 reorder_rs_grid_ranks=.true., &
203 skip_load_balance_distributed=skip_load_balance_distributed)
204 END IF
205 END IF
206
207 IF (dft_control%qs_control%do_kg) THEN
208
209 IF (qs_env%kg_env%tnadd_method == kg_tnadd_embed .OR. &
210 qs_env%kg_env%tnadd_method == kg_tnadd_embed_ri) THEN
211
212 IF (ASSOCIATED(qs_env%kg_env%subset)) THEN
213 DO isub = 1, qs_env%kg_env%nsubsets
214 IF (ASSOCIATED(qs_env%kg_env%subset(isub)%task_list)) &
215 CALL deallocate_task_list(qs_env%kg_env%subset(isub)%task_list)
216 END DO
217 ELSE
218 ALLOCATE (qs_env%kg_env%subset(qs_env%kg_env%nsubsets))
219 END IF
220
221 IF (soft_valid) THEN
222 basis_type = "ORB_SOFT"
223 ELSE
224 basis_type = "ORB"
225 END IF
226
227 DO isub = 1, qs_env%kg_env%nsubsets
228 CALL allocate_task_list(qs_env%kg_env%subset(isub)%task_list)
229 ! generate the subset task list from the neighborlist
230 CALL generate_qs_task_list(ks_env, qs_env%kg_env%subset(isub)%task_list, &
231 basis_type=basis_type, &
232 reorder_rs_grid_ranks=.false., &
233 skip_load_balance_distributed=skip_load_balance_distributed, &
234 sab_orb_external=qs_env%kg_env%subset(isub)%sab_orb)
235 END DO
236
237 END IF
238
239 END IF
240
241 CALL timestop(handle)
242
243 END SUBROUTINE qs_create_task_list
244
245! *****************************************************************************
246!> \brief rebuilds the rho structure, making sure that everything is allocated
247!> and has the right size
248!> \param qs_env the environment in which rho should be rebuilt
249!> \param rebuild_ao if it is necessary to rebuild rho_ao. Defaults to true.
250!> \param rebuild_grids if it in necessary to rebuild rho_r and rho_g.
251!> Defaults to false.
252!> \par History
253!> 10.2002 created [fawzi]
254!> \author Fawzi Mohamed
255!> \note
256!> needs updated pw pools, s_mstruct and h.
257!> The use of p to keep the structure of h (needed for the forces)
258!> is ugly and should be removed.
259!> If necessary rho is created from scratch.
260! **************************************************************************************************
261 SUBROUTINE qs_env_rebuild_rho(qs_env, rebuild_ao, rebuild_grids)
262 TYPE(qs_environment_type), POINTER :: qs_env
263 LOGICAL, INTENT(in), OPTIONAL :: rebuild_ao, rebuild_grids
264
265 CHARACTER(len=*), PARAMETER :: routinen = 'qs_env_rebuild_rho'
266
267 INTEGER :: handle
268 LOGICAL :: do_admm, gapw_xc
269 TYPE(dft_control_type), POINTER :: dft_control
270 TYPE(qs_rho_type), POINTER :: rho, rho_external, rho_xc
271
272 NULLIFY (rho)
273 CALL timeset(routinen, handle)
274
275 CALL get_qs_env(qs_env, &
276 dft_control=dft_control, &
277 rho=rho, &
278 rho_xc=rho_xc, &
279 rho_external=rho_external)
280
281 gapw_xc = dft_control%qs_control%gapw_xc
282 do_admm = dft_control%do_admm
283 CALL qs_rho_rebuild(rho, qs_env=qs_env, &
284 rebuild_ao=rebuild_ao, rebuild_grids=rebuild_grids)
285
286 IF (gapw_xc) THEN
287 CALL qs_rho_rebuild(rho_xc, qs_env=qs_env, &
288 rebuild_ao=rebuild_ao, rebuild_grids=rebuild_grids)
289 END IF
290
291! ZMP rebuilding external density
292 IF (dft_control%apply_external_density) THEN
293 CALL qs_rho_rebuild(rho_external, qs_env=qs_env, &
294 rebuild_grids=rebuild_grids)
295 dft_control%read_external_density = .true.
296 END IF
297
298 CALL timestop(handle)
299
300 END SUBROUTINE qs_env_rebuild_rho
301
302END 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 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, 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, 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 set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, 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, 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, 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, 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)
...
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...
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.