Line data Source code
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 : !> \par History
10 : !> 11.2002 created [fawzi]
11 : !> 10.2014 Moved many components from qs_env to here [Ole Schuett]
12 : !> 11.2014 unified k-point and gamma-point code [Ole Schuett]
13 : !> \author Fawzi Mohamed
14 : ! **************************************************************************************************
15 : MODULE qs_ks_types
16 : USE atomic_kind_types, ONLY: atomic_kind_type
17 : USE atprop_types, ONLY: atprop_type
18 : USE cell_types, ONLY: cell_type
19 : USE cp_blacs_env, ONLY: cp_blacs_env_release,&
20 : cp_blacs_env_type
21 : USE cp_control_types, ONLY: dft_control_release,&
22 : dft_control_type
23 : USE cp_dbcsr_api, ONLY: dbcsr_distribution_release,&
24 : dbcsr_distribution_type,&
25 : dbcsr_p_type
26 : USE cp_dbcsr_operations, ONLY: dbcsr_deallocate_matrix_set
27 : USE cp_result_types, ONLY: cp_result_type
28 : USE cp_subsys_types, ONLY: cp_subsys_type
29 : USE distribution_1d_types, ONLY: distribution_1d_type
30 : USE distribution_2d_types, ONLY: distribution_2d_release,&
31 : distribution_2d_retain,&
32 : distribution_2d_type
33 : USE kpoint_transitional, ONLY: get_1d_pointer,&
34 : get_2d_pointer,&
35 : kpoint_transitional_release,&
36 : kpoint_transitional_type,&
37 : set_1d_pointer,&
38 : set_2d_pointer
39 : USE kpoint_types, ONLY: kpoint_release,&
40 : kpoint_type
41 : USE message_passing, ONLY: mp_para_env_release,&
42 : mp_para_env_type
43 : USE molecule_kind_types, ONLY: molecule_kind_type
44 : USE molecule_types, ONLY: molecule_type
45 : USE particle_types, ONLY: particle_type
46 : USE pw_env_types, ONLY: pw_env_release,&
47 : pw_env_retain,&
48 : pw_env_type
49 : USE pw_types, ONLY: pw_c1d_gs_type,&
50 : pw_r3d_rs_type
51 : USE qs_energy_types, ONLY: qs_energy_type
52 : USE qs_force_types, ONLY: qs_force_type
53 : USE qs_kind_types, ONLY: qs_kind_type
54 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type,&
55 : release_neighbor_list_sets
56 : USE qs_rho_types, ONLY: qs_rho_create,&
57 : qs_rho_release,&
58 : qs_rho_type
59 : USE qs_subsys_types, ONLY: qs_subsys_get,&
60 : qs_subsys_release,&
61 : qs_subsys_type
62 : USE task_list_types, ONLY: deallocate_task_list,&
63 : task_list_type
64 : USE virial_types, ONLY: virial_type
65 : #include "./base/base_uses.f90"
66 :
67 : IMPLICIT NONE
68 : PRIVATE
69 :
70 : LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .TRUE.
71 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_ks_types'
72 :
73 : PUBLIC :: qs_ks_env_type, qs_ks_env_create, qs_ks_did_change
74 : PUBLIC :: qs_ks_release, qs_ks_part_release, get_ks_env, set_ks_env
75 :
76 : ! **************************************************************************************************
77 : !> \brief calculation environment to calculate the ks matrix,
78 : !> holds all the needed vars.
79 : !> assumes that the core hamiltonian and energy are up to date.
80 : !> \param s_mstruct_changed if the sparsity structure of s in qs_env where this
81 : !> ks_env lives has changed
82 : !> \param rho_changed if the rho stored in the qs_env has changed
83 : !> \param forces_up_to_date if the forces are up to date
84 : !> \param potential_changed if some external potential changed (such as due to the constraint)
85 : !>
86 : !> \param matrix_h core hamiltonian (matrix_h(1)), if needed by the calculation also
87 : !> its derivatives wrt. x,y, and z (matrix_h(2:4))
88 : !> \param matrix_ks Khon-Sham matrix (filtered by the structure of S).
89 : !> with LSD an array with the different orbitals
90 : !> \param matrix_s the overlap matrix (matrix_s(1)), if needed by the calculation also
91 : !> its derivatives wrt. x,y, and z (matrix_s(2:4))
92 : !> \param kinetic kinetic part of h
93 : !>
94 : !> \param rho the (old) density, in various representations (ao+grid)
95 : !> \param rho_xc the (old) soft density, used for the GAPW_XC method only
96 : !> \param rho_core a grid with the charges of the cores of the atoms in the
97 : !> reciprocal (g) space
98 : !> \param vppl a realspace grid with the local pseudopotential
99 : !> \param vee a realspace grid with the external electrostatic potential
100 : !>
101 : !> \param neighbor_list_id the current version of the neighbor_list
102 : !> \param sab_orb ,sac_ae, sac_ppl, sac_lri, sap_ppnl:
103 : !> neighbor lists for the calculation of the core Hamiltonian matrix
104 : !> \param sap_oce: neighbor lists for the calculation of the expansion
105 : !> coefficients of the local atomic densities rho1_hard and rho1_soft
106 : !> \param sab_se: neighbor lists for the calculation of the 2 centers
107 : !> hartree term in semi-empirical methods
108 : !> \param sac_tbe: neighbor lists for the calculation of the tight binding
109 : !> Ewald terms (DFTB)
110 : !> \param sab_core neighbor lists for the calculation of the core interactions
111 : !> \param sab_xb neighbor lists for the calculation of the XB interactions in xTB
112 : !> \param sab_xtb_nonbond neighbor lists for the calculation of the nonbonded interactions in xTB
113 : !> \param sab_all neighbor lists for the calculation of the matrix element of
114 : !> non-symmetric operators
115 : !> \param sab_vdw: neighbor lists for the calculation of dispersion interactions
116 : !> \param sab_scp: neighbor lists for the calculation of self-consistent polarization
117 : !> \param sab_almo: neighbor lists to create ALMO delocalization template
118 : !> \param sab_kp: neighbor lists to create kp image cell lists
119 : !> \param sab_kp_nosym: neighbor lists to create kp image cell lists, non-symmetric
120 : !>
121 : !> \param kpoints information on the kpoints used
122 : !> \param subsys the particles, molecules,... of this environment
123 : !> \param dft_control object that contains the values of various parameters
124 : !> relevant to a dft calculation
125 : !> \param distribution_2d: distribution of the atom pairs between the processors
126 : !>
127 : !> \par History
128 : !> 04.2002 created [fawzi]
129 : !> 10.2002 introduced pools, uses updated rho as input,
130 : !> removed most temporary variables, renamed may vars,
131 : !> began conversion to LSD [fawzi]
132 : !> 10.2014 Moved many components from qs_env here [Ole Schuett]
133 : !> \author Fawzi Mohamed
134 : ! **************************************************************************************************
135 : TYPE qs_ks_env_type
136 : PRIVATE
137 : LOGICAL :: s_mstruct_changed = .TRUE., &
138 : rho_changed = .TRUE., &
139 : potential_changed = .TRUE., &
140 : forces_up_to_date = .FALSE., &
141 : complex_ks = .FALSE.
142 : INTEGER :: n_evals = 0
143 :
144 : ! hartree is supposed to contain the hartree potential (for cube output)
145 : ! ugly to keep it always around only for a cube output...
146 : TYPE(pw_r3d_rs_type), POINTER :: v_hartree_rspace => Null()
147 :
148 : TYPE(kpoint_transitional_type) :: matrix_ks, &
149 : matrix_s, &
150 : kinetic, &
151 : matrix_h, &
152 : matrix_w, &
153 : matrix_vxc, &
154 : matrix_s_RI_aux, &
155 : matrix_ks_im, &
156 : matrix_h_im
157 :
158 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_p_mp2 => Null(), &
159 : matrix_p_mp2_admm => Null()
160 :
161 : TYPE(qs_rho_type), POINTER :: rho => Null(), &
162 : rho_xc => Null()
163 :
164 : TYPE(pw_r3d_rs_type), POINTER :: vppl => Null(), &
165 : rho_nlcc => Null()
166 : TYPE(pw_c1d_gs_type), POINTER :: rho_nlcc_g => Null()
167 :
168 : TYPE(pw_c1d_gs_type), POINTER :: rho_core => NULL()
169 : TYPE(pw_r3d_rs_type), POINTER :: vee => NULL()
170 :
171 : INTEGER :: neighbor_list_id = -1
172 : TYPE(neighbor_list_set_p_type), DIMENSION(:), POINTER :: sab_orb => Null(), &
173 : sac_ae => Null(), &
174 : sac_ppl => Null(), &
175 : sac_lri => Null(), &
176 : sap_ppnl => Null(), &
177 : sap_oce => Null(), &
178 : sab_se => Null(), &
179 : sab_vdw => Null(), &
180 : sab_scp => Null(), &
181 : sab_tbe => Null(), &
182 : sab_xtbe => Null(), &
183 : sab_core => Null(), &
184 : sab_xb => Null(), &
185 : sab_xtb_nonbond => Null(), &
186 : sab_all => Null(), &
187 : sab_lrc => Null(), &
188 : sab_almo => Null(), &
189 : sab_kp => Null(), &
190 : sab_kp_nosym => Null()
191 :
192 : TYPE(task_list_type), POINTER :: task_list => Null()
193 : TYPE(task_list_type), POINTER :: task_list_soft => Null()
194 :
195 : TYPE(kpoint_type), POINTER :: kpoints => Null()
196 : TYPE(qs_subsys_type), POINTER :: subsys => Null()
197 : TYPE(dft_control_type), POINTER :: dft_control => Null()
198 : TYPE(dbcsr_distribution_type), POINTER :: dbcsr_dist => Null()
199 : TYPE(distribution_2d_type), POINTER :: distribution_2d => Null()
200 : TYPE(pw_env_type), POINTER :: pw_env => Null()
201 : TYPE(mp_para_env_type), POINTER :: para_env => Null()
202 : TYPE(cp_blacs_env_type), POINTER :: blacs_env => Null()
203 : END TYPE qs_ks_env_type
204 :
205 : CONTAINS
206 :
207 : ! **************************************************************************************************
208 : !> \brief Allocates a new instance of ks_env.
209 : !> \param ks_env ...
210 : !> \author Ole Schuett
211 : ! **************************************************************************************************
212 6586 : SUBROUTINE qs_ks_env_create(ks_env)
213 : TYPE(qs_ks_env_type), INTENT(OUT) :: ks_env
214 :
215 6586 : ALLOCATE (ks_env%rho)
216 6586 : CALL qs_rho_create(ks_env%rho)
217 6586 : ALLOCATE (ks_env%rho_xc)
218 6586 : CALL qs_rho_create(ks_env%rho_xc)
219 6586 : END SUBROUTINE qs_ks_env_create
220 :
221 : ! **************************************************************************************************
222 : !> \brief ...
223 : !> \param ks_env ...
224 : !> \param v_hartree_rspace ...
225 : !> \param s_mstruct_changed ...
226 : !> \param rho_changed ...
227 : !> \param potential_changed ...
228 : !> \param forces_up_to_date ...
229 : !> \param complex_ks ...
230 : !> \param matrix_h ...
231 : !> \param matrix_h_im ...
232 : !> \param matrix_ks ...
233 : !> \param matrix_ks_im ...
234 : !> \param matrix_vxc ...
235 : !> \param kinetic ...
236 : !> \param matrix_s ...
237 : !> \param matrix_s_RI_aux ...
238 : !> \param matrix_w ...
239 : !> \param matrix_p_mp2 ...
240 : !> \param matrix_p_mp2_admm ...
241 : !> \param matrix_h_kp ...
242 : !> \param matrix_h_im_kp ...
243 : !> \param matrix_ks_kp ...
244 : !> \param matrix_vxc_kp ...
245 : !> \param kinetic_kp ...
246 : !> \param matrix_s_kp ...
247 : !> \param matrix_w_kp ...
248 : !> \param matrix_s_RI_aux_kp ...
249 : !> \param matrix_ks_im_kp ...
250 : !> \param rho ...
251 : !> \param rho_xc ...
252 : !> \param vppl ...
253 : !> \param rho_core ...
254 : !> \param rho_nlcc ...
255 : !> \param rho_nlcc_g ...
256 : !> \param vee ...
257 : !> \param neighbor_list_id ...
258 : !> \param sab_orb ...
259 : !> \param sab_all ...
260 : !> \param sac_ae ...
261 : !> \param sac_ppl ...
262 : !> \param sac_lri ...
263 : !> \param sap_ppnl ...
264 : !> \param sap_oce ...
265 : !> \param sab_lrc ...
266 : !> \param sab_se ...
267 : !> \param sab_xtbe ...
268 : !> \param sab_tbe ...
269 : !> \param sab_core ...
270 : !> \param sab_xb ...
271 : !> \param sab_xtb_nonbond ...
272 : !> \param sab_vdw ...
273 : !> \param sab_scp ...
274 : !> \param sab_almo ...
275 : !> \param sab_kp ...
276 : !> \param sab_kp_nosym ...
277 : !> \param task_list ...
278 : !> \param task_list_soft ...
279 : !> \param kpoints ...
280 : !> \param do_kpoints ...
281 : !> \param atomic_kind_set ...
282 : !> \param qs_kind_set ...
283 : !> \param cell ...
284 : !> \param cell_ref ...
285 : !> \param use_ref_cell ...
286 : !> \param particle_set ...
287 : !> \param energy ...
288 : !> \param force ...
289 : !> \param local_particles ...
290 : !> \param local_molecules ...
291 : !> \param molecule_kind_set ...
292 : !> \param molecule_set ...
293 : !> \param subsys ...
294 : !> \param cp_subsys ...
295 : !> \param virial ...
296 : !> \param results ...
297 : !> \param atprop ...
298 : !> \param nkind ...
299 : !> \param natom ...
300 : !> \param dft_control ...
301 : !> \param dbcsr_dist ...
302 : !> \param distribution_2d ...
303 : !> \param pw_env ...
304 : !> \param para_env ...
305 : !> \param blacs_env ...
306 : !> \param nelectron_total ...
307 : !> \param nelectron_spin ...
308 : ! **************************************************************************************************
309 9191742 : SUBROUTINE get_ks_env(ks_env, v_hartree_rspace, &
310 : s_mstruct_changed, rho_changed, &
311 : potential_changed, forces_up_to_date, complex_ks, &
312 : matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, &
313 : kinetic, matrix_s, &
314 : matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, &
315 : matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, &
316 : matrix_s_RI_aux_kp, matrix_ks_im_kp, &
317 : rho, rho_xc, &
318 : vppl, rho_core, rho_nlcc, rho_nlcc_g, vee, &
319 : neighbor_list_id, &
320 : sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, &
321 : sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_vdw, sab_scp, &
322 : sab_almo, sab_kp, sab_kp_nosym, &
323 : task_list, task_list_soft, &
324 : kpoints, do_kpoints, &
325 : atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, &
326 : particle_set, energy, force, local_particles, local_molecules, &
327 : molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, &
328 : nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, &
329 : para_env, blacs_env, nelectron_total, nelectron_spin)
330 :
331 : TYPE(qs_ks_env_type), INTENT(IN) :: ks_env
332 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: v_hartree_rspace
333 : LOGICAL, OPTIONAL :: s_mstruct_changed, rho_changed, &
334 : potential_changed, forces_up_to_date, &
335 : complex_ks
336 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, POINTER :: matrix_h, matrix_h_im, matrix_ks, &
337 : matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, &
338 : matrix_p_mp2_admm
339 : TYPE(dbcsr_p_type), DIMENSION(:, :), OPTIONAL, POINTER :: matrix_h_kp, matrix_h_im_kp, &
340 : matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, &
341 : matrix_ks_im_kp
342 : TYPE(qs_rho_type), OPTIONAL, POINTER :: rho, rho_xc
343 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: vppl
344 : TYPE(pw_c1d_gs_type), OPTIONAL, POINTER :: rho_core
345 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: rho_nlcc
346 : TYPE(pw_c1d_gs_type), OPTIONAL, POINTER :: rho_nlcc_g
347 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: vee
348 : INTEGER, OPTIONAL :: neighbor_list_id
349 : TYPE(neighbor_list_set_p_type), DIMENSION(:), OPTIONAL, POINTER :: sab_orb, sab_all, sac_ae, &
350 : sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, &
351 : sab_xb, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym
352 : TYPE(task_list_type), OPTIONAL, POINTER :: task_list, task_list_soft
353 : TYPE(kpoint_type), OPTIONAL, POINTER :: kpoints
354 : LOGICAL, OPTIONAL :: do_kpoints
355 : TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
356 : POINTER :: atomic_kind_set
357 : TYPE(qs_kind_type), DIMENSION(:), OPTIONAL, &
358 : POINTER :: qs_kind_set
359 : TYPE(cell_type), OPTIONAL, POINTER :: cell, cell_ref
360 : LOGICAL, OPTIONAL :: use_ref_cell
361 : TYPE(particle_type), DIMENSION(:), OPTIONAL, &
362 : POINTER :: particle_set
363 : TYPE(qs_energy_type), OPTIONAL, POINTER :: energy
364 : TYPE(qs_force_type), DIMENSION(:), OPTIONAL, &
365 : POINTER :: force
366 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles, local_molecules
367 : TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
368 : POINTER :: molecule_kind_set
369 : TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
370 : POINTER :: molecule_set
371 : TYPE(qs_subsys_type), OPTIONAL, POINTER :: subsys
372 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: cp_subsys
373 : TYPE(virial_type), OPTIONAL, POINTER :: virial
374 : TYPE(cp_result_type), OPTIONAL, POINTER :: results
375 : TYPE(atprop_type), OPTIONAL, POINTER :: atprop
376 : INTEGER, OPTIONAL :: nkind, natom
377 : TYPE(dft_control_type), OPTIONAL, POINTER :: dft_control
378 : TYPE(dbcsr_distribution_type), OPTIONAL, POINTER :: dbcsr_dist
379 : TYPE(distribution_2d_type), OPTIONAL, POINTER :: distribution_2d
380 : TYPE(pw_env_type), OPTIONAL, POINTER :: pw_env
381 : TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
382 : TYPE(cp_blacs_env_type), OPTIONAL, POINTER :: blacs_env
383 : INTEGER, OPTIONAL :: nelectron_total
384 : INTEGER, DIMENSION(2), OPTIONAL :: nelectron_spin
385 :
386 9191742 : IF (.NOT. ASSOCIATED(ks_env%subsys)) CPABORT("get_ks_env: subsys not associated")
387 :
388 9191742 : IF (PRESENT(s_mstruct_changed)) s_mstruct_changed = ks_env%s_mstruct_changed
389 9191742 : IF (PRESENT(rho_changed)) rho_changed = ks_env%rho_changed
390 9191742 : IF (PRESENT(potential_changed)) potential_changed = ks_env%potential_changed
391 9191742 : IF (PRESENT(forces_up_to_date)) forces_up_to_date = ks_env%forces_up_to_date
392 9191742 : IF (PRESENT(complex_ks)) complex_ks = ks_env%complex_ks
393 9191742 : IF (PRESENT(v_hartree_rspace)) v_hartree_rspace => ks_env%v_hartree_rspace
394 :
395 9191742 : IF (PRESENT(matrix_ks)) matrix_ks => get_1d_pointer(ks_env%matrix_ks)
396 9191742 : IF (PRESENT(matrix_s)) matrix_s => get_1d_pointer(ks_env%matrix_s)
397 9191742 : IF (PRESENT(matrix_s_RI_aux)) matrix_s_RI_aux => get_1d_pointer(ks_env%matrix_s_RI_aux)
398 9191742 : IF (PRESENT(kinetic)) kinetic => get_1d_pointer(ks_env%kinetic)
399 9191742 : IF (PRESENT(matrix_h)) matrix_h => get_1d_pointer(ks_env%matrix_h)
400 9191742 : IF (PRESENT(matrix_h_im)) matrix_h_im => get_1d_pointer(ks_env%matrix_h_im)
401 9191742 : IF (PRESENT(matrix_w)) matrix_w => get_1d_pointer(ks_env%matrix_w)
402 9191742 : IF (PRESENT(matrix_vxc)) matrix_vxc => get_1d_pointer(ks_env%matrix_vxc)
403 :
404 9191742 : IF (PRESENT(matrix_ks_kp)) matrix_ks_kp => get_2d_pointer(ks_env%matrix_ks)
405 9191742 : IF (PRESENT(matrix_ks_im_kp)) matrix_ks_im_kp => get_2d_pointer(ks_env%matrix_ks_im)
406 9191742 : IF (PRESENT(matrix_s_kp)) matrix_s_kp => get_2d_pointer(ks_env%matrix_s)
407 9191742 : IF (PRESENT(matrix_s_RI_aux_kp)) matrix_s_RI_aux_kp => get_2d_pointer(ks_env%matrix_s_RI_aux)
408 9191742 : IF (PRESENT(matrix_w_kp)) matrix_w_kp => get_2d_pointer(ks_env%matrix_w)
409 9191742 : IF (PRESENT(kinetic_kp)) kinetic_kp => get_2d_pointer(ks_env%kinetic)
410 9191742 : IF (PRESENT(matrix_h_kp)) matrix_h_kp => get_2d_pointer(ks_env%matrix_h)
411 9191742 : IF (PRESENT(matrix_h_im_kp)) matrix_h_im_kp => get_2d_pointer(ks_env%matrix_h_im)
412 9191742 : IF (PRESENT(matrix_vxc_kp)) matrix_vxc_kp => get_2d_pointer(ks_env%matrix_vxc)
413 9191742 : IF (PRESENT(matrix_ks_im)) matrix_ks_im => get_1d_pointer(ks_env%matrix_ks_im)
414 :
415 9191742 : IF (PRESENT(matrix_p_mp2)) matrix_p_mp2 => ks_env%matrix_p_mp2
416 9191742 : IF (PRESENT(matrix_p_mp2_admm)) matrix_p_mp2_admm => ks_env%matrix_p_mp2_admm
417 9191742 : IF (PRESENT(rho)) rho => ks_env%rho
418 9191742 : IF (PRESENT(rho_xc)) rho_xc => ks_env%rho_xc
419 9191742 : IF (PRESENT(rho_core)) rho_core => ks_env%rho_core
420 9191742 : IF (PRESENT(rho_nlcc)) rho_nlcc => ks_env%rho_nlcc
421 9191742 : IF (PRESENT(rho_nlcc_g)) rho_nlcc_g => ks_env%rho_nlcc_g
422 9191742 : IF (PRESENT(vppl)) vppl => ks_env%vppl
423 9191742 : IF (PRESENT(vee)) vee => ks_env%vee
424 :
425 9191742 : IF (PRESENT(neighbor_list_id)) neighbor_list_id = ks_env%neighbor_list_id
426 9191742 : IF (PRESENT(sab_orb)) sab_orb => ks_env%sab_orb
427 9191742 : IF (PRESENT(sab_all)) sab_all => ks_env%sab_all
428 9191742 : IF (PRESENT(sab_vdw)) sab_vdw => ks_env%sab_vdw
429 9191742 : IF (PRESENT(sab_scp)) sab_scp => ks_env%sab_scp
430 9191742 : IF (PRESENT(sac_ae)) sac_ae => ks_env%sac_ae
431 9191742 : IF (PRESENT(sac_ppl)) sac_ppl => ks_env%sac_ppl
432 9191742 : IF (PRESENT(sac_lri)) sac_lri => ks_env%sac_lri
433 9191742 : IF (PRESENT(sap_ppnl)) sap_ppnl => ks_env%sap_ppnl
434 9191742 : IF (PRESENT(sap_oce)) sap_oce => ks_env%sap_oce
435 9191742 : IF (PRESENT(sab_se)) sab_se => ks_env%sab_se
436 9191742 : IF (PRESENT(sab_lrc)) sab_lrc => ks_env%sab_lrc
437 9191742 : IF (PRESENT(sab_tbe)) sab_tbe => ks_env%sab_tbe
438 9191742 : IF (PRESENT(sab_xtbe)) sab_xtbe => ks_env%sab_xtbe
439 9191742 : IF (PRESENT(sab_core)) sab_core => ks_env%sab_core
440 9191742 : IF (PRESENT(sab_xb)) sab_xb => ks_env%sab_xb
441 9191742 : IF (PRESENT(sab_xtb_nonbond)) sab_xtb_nonbond => ks_env%sab_xtb_nonbond
442 9191742 : IF (PRESENT(sab_almo)) sab_almo => ks_env%sab_almo
443 9191742 : IF (PRESENT(sab_kp)) sab_kp => ks_env%sab_kp
444 9191742 : IF (PRESENT(sab_kp_nosym)) sab_kp_nosym => ks_env%sab_kp_nosym
445 9191742 : IF (PRESENT(dft_control)) dft_control => ks_env%dft_control
446 9191742 : IF (PRESENT(dbcsr_dist)) dbcsr_dist => ks_env%dbcsr_dist
447 9191742 : IF (PRESENT(distribution_2d)) distribution_2d => ks_env%distribution_2d
448 9191742 : IF (PRESENT(pw_env)) pw_env => ks_env%pw_env
449 9191742 : IF (PRESENT(para_env)) para_env => ks_env%para_env
450 9191742 : IF (PRESENT(blacs_env)) blacs_env => ks_env%blacs_env
451 :
452 9191742 : IF (PRESENT(task_list)) task_list => ks_env%task_list
453 9191742 : IF (PRESENT(task_list_soft)) task_list_soft => ks_env%task_list_soft
454 :
455 9191742 : IF (PRESENT(kpoints)) kpoints => ks_env%kpoints
456 9191742 : IF (PRESENT(do_kpoints)) THEN
457 630323 : do_kpoints = (ks_env%kpoints%nkp > 0)
458 : END IF
459 :
460 9191742 : IF (PRESENT(subsys)) subsys => ks_env%subsys
461 : CALL qs_subsys_get(ks_env%subsys, &
462 : local_molecules=local_molecules, &
463 : local_particles=local_particles, &
464 : atprop=atprop, &
465 : virial=virial, &
466 : results=results, &
467 : cell=cell, &
468 : cell_ref=cell_ref, &
469 : use_ref_cell=use_ref_cell, &
470 : energy=energy, &
471 : force=force, &
472 : qs_kind_set=qs_kind_set, &
473 : cp_subsys=cp_subsys, &
474 : atomic_kind_set=atomic_kind_set, &
475 : particle_set=particle_set, &
476 : molecule_kind_set=molecule_kind_set, &
477 : molecule_set=molecule_set, &
478 : natom=natom, &
479 : nkind=nkind, &
480 : nelectron_total=nelectron_total, &
481 9191742 : nelectron_spin=nelectron_spin)
482 :
483 9191742 : END SUBROUTINE get_ks_env
484 :
485 : ! **************************************************************************************************
486 : !> \brief ...
487 : !> \param ks_env ...
488 : !> \param v_hartree_rspace ...
489 : !> \param s_mstruct_changed ...
490 : !> \param rho_changed ...
491 : !> \param potential_changed ...
492 : !> \param forces_up_to_date ...
493 : !> \param complex_ks ...
494 : !> \param matrix_h ...
495 : !> \param matrix_h_im ...
496 : !> \param matrix_ks ...
497 : !> \param matrix_ks_im ...
498 : !> \param matrix_vxc ...
499 : !> \param kinetic ...
500 : !> \param matrix_s ...
501 : !> \param matrix_s_RI_aux ...
502 : !> \param matrix_w ...
503 : !> \param matrix_p_mp2 ...
504 : !> \param matrix_p_mp2_admm ...
505 : !> \param matrix_h_kp ...
506 : !> \param matrix_h_im_kp ...
507 : !> \param matrix_ks_kp ...
508 : !> \param matrix_vxc_kp ...
509 : !> \param kinetic_kp ...
510 : !> \param matrix_s_kp ...
511 : !> \param matrix_w_kp ...
512 : !> \param matrix_s_RI_aux_kp ...
513 : !> \param matrix_ks_im_kp ...
514 : !> \param vppl ...
515 : !> \param rho_core ...
516 : !> \param rho_nlcc ...
517 : !> \param rho_nlcc_g ...
518 : !> \param vee ...
519 : !> \param neighbor_list_id ...
520 : !> \param kpoints ...
521 : !> \param sab_orb ...
522 : !> \param sab_all ...
523 : !> \param sac_ae ...
524 : !> \param sac_ppl ...
525 : !> \param sac_lri ...
526 : !> \param sap_ppnl ...
527 : !> \param sap_oce ...
528 : !> \param sab_lrc ...
529 : !> \param sab_se ...
530 : !> \param sab_xtbe ...
531 : !> \param sab_tbe ...
532 : !> \param sab_core ...
533 : !> \param sab_xb ...
534 : !> \param sab_xtb_nonbond ...
535 : !> \param sab_vdw ...
536 : !> \param sab_scp ...
537 : !> \param sab_almo ...
538 : !> \param sab_kp ...
539 : !> \param sab_kp_nosym ...
540 : !> \param task_list ...
541 : !> \param task_list_soft ...
542 : !> \param subsys ...
543 : !> \param dft_control ...
544 : !> \param dbcsr_dist ...
545 : !> \param distribution_2d ...
546 : !> \param pw_env ...
547 : !> \param para_env ...
548 : !> \param blacs_env ...
549 : ! **************************************************************************************************
550 608402 : SUBROUTINE set_ks_env(ks_env, v_hartree_rspace, &
551 : s_mstruct_changed, rho_changed, &
552 : potential_changed, forces_up_to_date, complex_ks, &
553 : matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, &
554 : kinetic, matrix_s, &
555 : matrix_s_RI_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, &
556 : matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, &
557 : matrix_s_RI_aux_kp, matrix_ks_im_kp, &
558 : vppl, rho_core, rho_nlcc, rho_nlcc_g, vee, &
559 : neighbor_list_id, &
560 : kpoints, &
561 : sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, &
562 : sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_nonbond, sab_vdw, sab_scp, &
563 : sab_almo, sab_kp, sab_kp_nosym, &
564 : task_list, task_list_soft, &
565 : subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, &
566 : para_env, blacs_env)
567 :
568 : TYPE(qs_ks_env_type), INTENT(INOUT) :: ks_env
569 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: v_hartree_rspace
570 : LOGICAL, OPTIONAL :: s_mstruct_changed, rho_changed, &
571 : potential_changed, forces_up_to_date, &
572 : complex_ks
573 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, POINTER :: matrix_h, matrix_h_im, matrix_ks, &
574 : matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_RI_aux, matrix_w, matrix_p_mp2, &
575 : matrix_p_mp2_admm
576 : TYPE(dbcsr_p_type), DIMENSION(:, :), OPTIONAL, POINTER :: matrix_h_kp, matrix_h_im_kp, &
577 : matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_RI_aux_kp, &
578 : matrix_ks_im_kp
579 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: vppl
580 : TYPE(pw_c1d_gs_type), OPTIONAL, POINTER :: rho_core
581 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: rho_nlcc
582 : TYPE(pw_c1d_gs_type), OPTIONAL, POINTER :: rho_nlcc_g
583 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: vee
584 : INTEGER, OPTIONAL :: neighbor_list_id
585 : TYPE(kpoint_type), OPTIONAL, POINTER :: kpoints
586 : TYPE(neighbor_list_set_p_type), DIMENSION(:), OPTIONAL, POINTER :: sab_orb, sab_all, sac_ae, &
587 : sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, &
588 : sab_xb, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym
589 : TYPE(task_list_type), OPTIONAL, POINTER :: task_list, task_list_soft
590 : TYPE(qs_subsys_type), OPTIONAL, POINTER :: subsys
591 : TYPE(dft_control_type), OPTIONAL, POINTER :: dft_control
592 : TYPE(dbcsr_distribution_type), OPTIONAL, POINTER :: dbcsr_dist
593 : TYPE(distribution_2d_type), OPTIONAL, POINTER :: distribution_2d
594 : TYPE(pw_env_type), OPTIONAL, POINTER :: pw_env
595 : TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
596 : TYPE(cp_blacs_env_type), OPTIONAL, POINTER :: blacs_env
597 :
598 608402 : IF (PRESENT(s_mstruct_changed)) ks_env%s_mstruct_changed = s_mstruct_changed
599 608402 : IF (PRESENT(rho_changed)) ks_env%rho_changed = rho_changed
600 608402 : IF (PRESENT(potential_changed)) ks_env%potential_changed = potential_changed
601 608402 : IF (PRESENT(forces_up_to_date)) ks_env%forces_up_to_date = forces_up_to_date
602 608402 : IF (PRESENT(complex_ks)) ks_env%complex_ks = complex_ks
603 608402 : IF (ks_env%s_mstruct_changed .OR. ks_env%potential_changed .OR. ks_env%rho_changed) &
604 343569 : ks_env%forces_up_to_date = .FALSE.
605 608402 : IF (PRESENT(v_hartree_rspace)) ks_env%v_hartree_rspace => v_hartree_rspace
606 :
607 608402 : IF (PRESENT(matrix_h)) CALL set_1d_pointer(ks_env%matrix_h, matrix_h)
608 608402 : IF (PRESENT(matrix_h_kp)) CALL set_2d_pointer(ks_env%matrix_h, matrix_h_kp)
609 :
610 608402 : IF (PRESENT(matrix_h_im)) CALL set_1d_pointer(ks_env%matrix_h_im, matrix_h_im)
611 608402 : IF (PRESENT(matrix_h_im_kp)) CALL set_2d_pointer(ks_env%matrix_h_im, matrix_h_im_kp)
612 :
613 608402 : IF (PRESENT(matrix_ks)) CALL set_1d_pointer(ks_env%matrix_ks, matrix_ks)
614 608402 : IF (PRESENT(matrix_ks_kp)) CALL set_2d_pointer(ks_env%matrix_ks, matrix_ks_kp)
615 :
616 608402 : IF (PRESENT(matrix_vxc)) CALL set_1d_pointer(ks_env%matrix_vxc, matrix_vxc)
617 608402 : IF (PRESENT(matrix_vxc_kp)) CALL set_2d_pointer(ks_env%matrix_vxc, matrix_vxc_kp)
618 :
619 608402 : IF (PRESENT(matrix_s)) CALL set_1d_pointer(ks_env%matrix_s, matrix_s)
620 608402 : IF (PRESENT(matrix_s_kp)) CALL set_2d_pointer(ks_env%matrix_s, matrix_s_kp)
621 :
622 608402 : IF (PRESENT(kinetic)) CALL set_1d_pointer(ks_env%kinetic, kinetic)
623 608402 : IF (PRESENT(kinetic_kp)) CALL set_2d_pointer(ks_env%kinetic, kinetic_kp)
624 :
625 608402 : IF (PRESENT(matrix_w)) CALL set_1d_pointer(ks_env%matrix_w, matrix_w)
626 608402 : IF (PRESENT(matrix_w_kp)) CALL set_2d_pointer(ks_env%matrix_w, matrix_w_kp)
627 :
628 608402 : IF (PRESENT(matrix_s_RI_aux)) CALL set_1d_pointer(ks_env%matrix_s_RI_aux, matrix_s_RI_aux)
629 608402 : IF (PRESENT(matrix_s_RI_aux_kp)) CALL set_2d_pointer(ks_env%matrix_s_RI_aux, matrix_s_RI_aux_kp)
630 :
631 608402 : IF (PRESENT(matrix_ks_im)) CALL set_1d_pointer(ks_env%matrix_ks_im, matrix_ks_im)
632 608402 : IF (PRESENT(matrix_ks_im_kp)) CALL set_2d_pointer(ks_env%matrix_ks_im, matrix_ks_im_kp)
633 :
634 608402 : IF (PRESENT(matrix_p_mp2)) ks_env%matrix_p_mp2 => matrix_p_mp2
635 608402 : IF (PRESENT(matrix_p_mp2_admm)) ks_env%matrix_p_mp2_admm => matrix_p_mp2_admm
636 608402 : IF (PRESENT(rho_core)) ks_env%rho_core => rho_core
637 608402 : IF (PRESENT(rho_nlcc)) ks_env%rho_nlcc => rho_nlcc
638 608402 : IF (PRESENT(rho_nlcc_g)) ks_env%rho_nlcc_g => rho_nlcc_g
639 608402 : IF (PRESENT(vppl)) ks_env%vppl => vppl
640 608402 : IF (PRESENT(vee)) ks_env%vee => vee
641 :
642 608402 : IF (PRESENT(neighbor_list_id)) ks_env%neighbor_list_id = neighbor_list_id
643 608402 : IF (PRESENT(kpoints)) ks_env%kpoints => kpoints
644 608402 : IF (PRESENT(sab_orb)) ks_env%sab_orb => sab_orb
645 608402 : IF (PRESENT(sab_vdw)) ks_env%sab_vdw => sab_vdw
646 608402 : IF (PRESENT(sab_scp)) ks_env%sab_scp => sab_scp
647 608402 : IF (PRESENT(sab_all)) ks_env%sab_all => sab_all
648 608402 : IF (PRESENT(sac_ae)) ks_env%sac_ae => sac_ae
649 608402 : IF (PRESENT(sac_ppl)) ks_env%sac_ppl => sac_ppl
650 608402 : IF (PRESENT(sac_lri)) ks_env%sac_lri => sac_lri
651 608402 : IF (PRESENT(sap_ppnl)) ks_env%sap_ppnl => sap_ppnl
652 608402 : IF (PRESENT(sap_oce)) ks_env%sap_oce => sap_oce
653 608402 : IF (PRESENT(sab_se)) ks_env%sab_se => sab_se
654 608402 : IF (PRESENT(sab_lrc)) ks_env%sab_lrc => sab_lrc
655 608402 : IF (PRESENT(sab_tbe)) ks_env%sab_tbe => sab_tbe
656 608402 : IF (PRESENT(sab_xtbe)) ks_env%sab_xtbe => sab_xtbe
657 608402 : IF (PRESENT(sab_core)) ks_env%sab_core => sab_core
658 608402 : IF (PRESENT(sab_xb)) ks_env%sab_xb => sab_xb
659 608402 : IF (PRESENT(sab_xtb_nonbond)) ks_env%sab_xtb_nonbond => sab_xtb_nonbond
660 608402 : IF (PRESENT(sab_almo)) ks_env%sab_almo => sab_almo
661 608402 : IF (PRESENT(sab_kp)) ks_env%sab_kp => sab_kp
662 608402 : IF (PRESENT(sab_kp_nosym)) ks_env%sab_kp_nosym => sab_kp_nosym
663 :
664 608402 : IF (PRESENT(task_list)) ks_env%task_list => task_list
665 608402 : IF (PRESENT(task_list_soft)) ks_env%task_list_soft => task_list_soft
666 :
667 608402 : IF (PRESENT(subsys)) THEN
668 6586 : IF (ASSOCIATED(ks_env%subsys)) THEN
669 0 : IF (ASSOCIATED(ks_env%subsys, subsys)) THEN
670 0 : CALL qs_subsys_release(ks_env%subsys)
671 0 : DEALLOCATE (ks_env%subsys)
672 : END IF
673 : END IF
674 6586 : ks_env%subsys => subsys
675 : END IF
676 608402 : IF (PRESENT(dft_control)) THEN
677 6586 : IF (ASSOCIATED(ks_env%dft_control)) THEN
678 0 : IF (.NOT. ASSOCIATED(ks_env%dft_control, dft_control)) THEN
679 0 : CALL dft_control_release(ks_env%dft_control)
680 0 : DEALLOCATE (ks_env%dft_control)
681 : END IF
682 : END IF
683 6586 : ks_env%dft_control => dft_control
684 : END IF
685 608402 : IF (PRESENT(dbcsr_dist)) THEN
686 6586 : IF (ASSOCIATED(ks_env%dbcsr_dist)) THEN
687 0 : IF (.NOT. ASSOCIATED(ks_env%dbcsr_dist, dbcsr_dist)) THEN
688 0 : CALL dbcsr_distribution_release(ks_env%dbcsr_dist)
689 0 : DEALLOCATE (ks_env%dbcsr_dist)
690 : END IF
691 : END IF
692 6586 : ks_env%dbcsr_dist => dbcsr_dist
693 : END IF
694 608402 : IF (PRESENT(distribution_2d)) THEN
695 6586 : CALL distribution_2d_retain(distribution_2d)
696 6586 : CALL distribution_2d_release(ks_env%distribution_2d)
697 6586 : ks_env%distribution_2d => distribution_2d
698 : END IF
699 608402 : IF (PRESENT(pw_env)) THEN
700 6586 : CALL pw_env_retain(pw_env)
701 6586 : CALL pw_env_release(ks_env%pw_env)
702 6586 : ks_env%pw_env => pw_env
703 : END IF
704 608402 : IF (PRESENT(para_env)) THEN
705 6586 : CALL para_env%retain()
706 6586 : CALL mp_para_env_release(ks_env%para_env)
707 6586 : ks_env%para_env => para_env
708 : END IF
709 608402 : IF (PRESENT(blacs_env)) THEN
710 6586 : CALL blacs_env%retain()
711 6586 : CALL cp_blacs_env_release(ks_env%blacs_env)
712 6586 : ks_env%blacs_env => blacs_env
713 : END IF
714 608402 : END SUBROUTINE set_ks_env
715 :
716 : ! **************************************************************************************************
717 : !> \brief releases the ks_env (see doc/ReferenceCounting.html)
718 : !> \param ks_env the ks_env to be released
719 : !> \par History
720 : !> 05.2002 created [fawzi]
721 : !> \author Fawzi Mohamed
722 : ! **************************************************************************************************
723 6586 : SUBROUTINE qs_ks_release(ks_env)
724 : TYPE(qs_ks_env_type), INTENT(INOUT) :: ks_env
725 :
726 6586 : IF (ASSOCIATED(ks_env%v_hartree_rspace)) THEN
727 6559 : CALL ks_env%v_hartree_rspace%release()
728 6559 : DEALLOCATE (ks_env%v_hartree_rspace)
729 : END IF
730 :
731 6586 : CALL kpoint_transitional_release(ks_env%matrix_ks)
732 6586 : CALL kpoint_transitional_release(ks_env%matrix_ks_im)
733 6586 : CALL kpoint_transitional_release(ks_env%matrix_h)
734 6586 : CALL kpoint_transitional_release(ks_env%matrix_h_im)
735 6586 : CALL kpoint_transitional_release(ks_env%matrix_vxc)
736 6586 : CALL kpoint_transitional_release(ks_env%matrix_s)
737 6586 : CALL kpoint_transitional_release(ks_env%matrix_w)
738 6586 : CALL kpoint_transitional_release(ks_env%kinetic)
739 6586 : CALL kpoint_transitional_release(ks_env%matrix_s_RI_aux)
740 :
741 6586 : IF (ASSOCIATED(ks_env%matrix_p_mp2)) &
742 186 : CALL dbcsr_deallocate_matrix_set(ks_env%matrix_p_mp2)
743 6586 : IF (ASSOCIATED(ks_env%matrix_p_mp2_admm)) &
744 36 : CALL dbcsr_deallocate_matrix_set(ks_env%matrix_p_mp2_admm)
745 6586 : IF (ASSOCIATED(ks_env%rho)) THEN
746 6559 : CALL qs_rho_release(ks_env%rho)
747 6559 : DEALLOCATE (ks_env%rho)
748 : END IF
749 6586 : IF (ASSOCIATED(ks_env%rho_xc)) THEN
750 6559 : CALL qs_rho_release(ks_env%rho_xc)
751 6559 : DEALLOCATE (ks_env%rho_xc)
752 : END IF
753 6586 : IF (ASSOCIATED(ks_env%distribution_2d)) &
754 6586 : CALL distribution_2d_release(ks_env%distribution_2d)
755 6586 : IF (ASSOCIATED(ks_env%task_list)) &
756 4247 : CALL deallocate_task_list(ks_env%task_list)
757 6586 : IF (ASSOCIATED(ks_env%task_list_soft)) &
758 914 : CALL deallocate_task_list(ks_env%task_list_soft)
759 :
760 6586 : IF (ASSOCIATED(ks_env%rho_nlcc_g)) THEN
761 12 : CALL ks_env%rho_nlcc_g%release()
762 12 : DEALLOCATE (ks_env%rho_nlcc_g)
763 : END IF
764 6586 : IF (ASSOCIATED(ks_env%rho_nlcc)) THEN
765 12 : CALL ks_env%rho_nlcc%release()
766 12 : DEALLOCATE (ks_env%rho_nlcc)
767 : END IF
768 6586 : IF (ASSOCIATED(ks_env%rho_core)) THEN
769 4411 : CALL ks_env%rho_core%release()
770 4411 : DEALLOCATE (ks_env%rho_core)
771 : END IF
772 6586 : IF (ASSOCIATED(ks_env%vppl)) THEN
773 8 : CALL ks_env%vppl%release()
774 8 : DEALLOCATE (ks_env%vppl)
775 : END IF
776 6586 : IF (ASSOCIATED(ks_env%vee)) THEN
777 16 : CALL ks_env%vee%release()
778 16 : DEALLOCATE (ks_env%vee)
779 : END IF
780 6586 : IF (ASSOCIATED(ks_env%dbcsr_dist)) THEN
781 6586 : CALL dbcsr_distribution_release(ks_env%dbcsr_dist)
782 6586 : DEALLOCATE (ks_env%dbcsr_dist)
783 : END IF
784 :
785 6586 : CALL release_neighbor_list_sets(ks_env%sab_orb)
786 6586 : CALL release_neighbor_list_sets(ks_env%sac_ae)
787 6586 : CALL release_neighbor_list_sets(ks_env%sac_ppl)
788 6586 : CALL release_neighbor_list_sets(ks_env%sac_lri)
789 6586 : CALL release_neighbor_list_sets(ks_env%sap_ppnl)
790 6586 : CALL release_neighbor_list_sets(ks_env%sap_oce)
791 6586 : CALL release_neighbor_list_sets(ks_env%sab_se)
792 6586 : CALL release_neighbor_list_sets(ks_env%sab_vdw)
793 6586 : CALL release_neighbor_list_sets(ks_env%sab_scp)
794 6586 : CALL release_neighbor_list_sets(ks_env%sab_tbe)
795 6586 : CALL release_neighbor_list_sets(ks_env%sab_xtbe)
796 6586 : CALL release_neighbor_list_sets(ks_env%sab_core)
797 6586 : CALL release_neighbor_list_sets(ks_env%sab_xb)
798 6586 : CALL release_neighbor_list_sets(ks_env%sab_xtb_nonbond)
799 6586 : CALL release_neighbor_list_sets(ks_env%sab_all)
800 6586 : CALL release_neighbor_list_sets(ks_env%sab_lrc)
801 6586 : CALL release_neighbor_list_sets(ks_env%sab_almo)
802 6586 : CALL release_neighbor_list_sets(ks_env%sab_kp)
803 6586 : CALL release_neighbor_list_sets(ks_env%sab_kp_nosym)
804 6586 : IF (ASSOCIATED(ks_env%dft_control)) THEN
805 6586 : CALL dft_control_release(ks_env%dft_control)
806 6586 : DEALLOCATE (ks_env%dft_control)
807 : END IF
808 6586 : CALL kpoint_release(ks_env%kpoints)
809 6586 : IF (ASSOCIATED(ks_env%subsys)) THEN
810 6586 : CALL qs_subsys_release(ks_env%subsys)
811 6586 : DEALLOCATE (ks_env%subsys)
812 : END IF
813 6586 : CALL pw_env_release(ks_env%pw_env)
814 6586 : CALL mp_para_env_release(ks_env%para_env)
815 6586 : CALL cp_blacs_env_release(ks_env%blacs_env)
816 :
817 6586 : END SUBROUTINE qs_ks_release
818 :
819 : ! **************************************************************************************************
820 : !> \brief releases part of the ks_env
821 : !> \param ks_env the ks_env to be released
822 : !> \par History
823 : !> 04.2022 created [JGH]
824 : ! **************************************************************************************************
825 27 : SUBROUTINE qs_ks_part_release(ks_env)
826 : TYPE(qs_ks_env_type), INTENT(INOUT) :: ks_env
827 :
828 27 : IF (ASSOCIATED(ks_env%v_hartree_rspace)) THEN
829 27 : CALL ks_env%v_hartree_rspace%release()
830 27 : DEALLOCATE (ks_env%v_hartree_rspace)
831 : END IF
832 :
833 27 : CALL kpoint_transitional_release(ks_env%matrix_h)
834 27 : CALL kpoint_transitional_release(ks_env%matrix_h_im)
835 27 : CALL kpoint_transitional_release(ks_env%matrix_ks_im)
836 27 : CALL kpoint_transitional_release(ks_env%matrix_vxc)
837 27 : CALL kpoint_transitional_release(ks_env%matrix_w)
838 27 : CALL kpoint_transitional_release(ks_env%kinetic)
839 27 : CALL kpoint_transitional_release(ks_env%matrix_s_RI_aux)
840 :
841 27 : IF (ASSOCIATED(ks_env%matrix_p_mp2)) &
842 0 : CALL dbcsr_deallocate_matrix_set(ks_env%matrix_p_mp2)
843 27 : IF (ASSOCIATED(ks_env%matrix_p_mp2_admm)) &
844 0 : CALL dbcsr_deallocate_matrix_set(ks_env%matrix_p_mp2_admm)
845 27 : IF (ASSOCIATED(ks_env%rho)) THEN
846 27 : CALL qs_rho_release(ks_env%rho)
847 27 : DEALLOCATE (ks_env%rho)
848 : END IF
849 27 : IF (ASSOCIATED(ks_env%rho_xc)) THEN
850 27 : CALL qs_rho_release(ks_env%rho_xc)
851 27 : DEALLOCATE (ks_env%rho_xc)
852 : END IF
853 27 : IF (ASSOCIATED(ks_env%task_list)) &
854 27 : CALL deallocate_task_list(ks_env%task_list)
855 27 : IF (ASSOCIATED(ks_env%task_list_soft)) &
856 0 : CALL deallocate_task_list(ks_env%task_list_soft)
857 :
858 27 : IF (ASSOCIATED(ks_env%rho_nlcc_g)) THEN
859 0 : CALL ks_env%rho_nlcc_g%release()
860 0 : DEALLOCATE (ks_env%rho_nlcc_g)
861 : END IF
862 27 : IF (ASSOCIATED(ks_env%rho_nlcc)) THEN
863 0 : CALL ks_env%rho_nlcc%release()
864 0 : DEALLOCATE (ks_env%rho_nlcc)
865 : END IF
866 27 : IF (ASSOCIATED(ks_env%rho_core)) THEN
867 27 : CALL ks_env%rho_core%release()
868 27 : DEALLOCATE (ks_env%rho_core)
869 : END IF
870 27 : IF (ASSOCIATED(ks_env%vppl)) THEN
871 0 : CALL ks_env%vppl%release()
872 0 : DEALLOCATE (ks_env%vppl)
873 : END IF
874 27 : IF (ASSOCIATED(ks_env%vee)) THEN
875 0 : CALL ks_env%vee%release()
876 0 : DEALLOCATE (ks_env%vee)
877 : END IF
878 :
879 27 : CALL release_neighbor_list_sets(ks_env%sac_ae)
880 27 : CALL release_neighbor_list_sets(ks_env%sac_ppl)
881 27 : CALL release_neighbor_list_sets(ks_env%sac_lri)
882 27 : CALL release_neighbor_list_sets(ks_env%sap_ppnl)
883 27 : CALL release_neighbor_list_sets(ks_env%sap_oce)
884 27 : CALL release_neighbor_list_sets(ks_env%sab_se)
885 27 : CALL release_neighbor_list_sets(ks_env%sab_vdw)
886 27 : CALL release_neighbor_list_sets(ks_env%sab_scp)
887 27 : CALL release_neighbor_list_sets(ks_env%sab_tbe)
888 27 : CALL release_neighbor_list_sets(ks_env%sab_xtbe)
889 27 : CALL release_neighbor_list_sets(ks_env%sab_core)
890 27 : CALL release_neighbor_list_sets(ks_env%sab_xb)
891 27 : CALL release_neighbor_list_sets(ks_env%sab_xtb_nonbond)
892 27 : CALL release_neighbor_list_sets(ks_env%sab_all)
893 27 : CALL release_neighbor_list_sets(ks_env%sab_lrc)
894 27 : CALL release_neighbor_list_sets(ks_env%sab_almo)
895 27 : CALL release_neighbor_list_sets(ks_env%sab_kp)
896 27 : CALL release_neighbor_list_sets(ks_env%sab_kp_nosym)
897 27 : CALL kpoint_release(ks_env%kpoints)
898 27 : CALL pw_env_release(ks_env%pw_env, ks_env%para_env)
899 27 : END SUBROUTINE qs_ks_part_release
900 :
901 : ! **************************************************************************************************
902 : !> \brief tells that some of the things relevant to the ks calculation
903 : !> did change. has to be called when changes happen otherwise
904 : !> the calculation will give wrong results.
905 : !> \param ks_env the environment that is informed about the changes
906 : !> \param s_mstruct_changed if true it means that the structure of the
907 : !> overlap matrix has changed
908 : !> (atoms have moved)
909 : !> \param rho_changed if true it means that the density has changed
910 : !> \param potential_changed ...
911 : !> \param full_reset if true everything has changed
912 : !> \par History
913 : !> 4.2002 created [fawzi]
914 : !> 12.2014 moved from qs_ks_methods, added deallocation of KS-matrices [Ole Schuett]
915 : !> \author Fawzi Mohamed
916 : ! **************************************************************************************************
917 198408 : SUBROUTINE qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, &
918 : potential_changed, full_reset)
919 : TYPE(qs_ks_env_type), INTENT(INOUT) :: ks_env
920 : LOGICAL, INTENT(in), OPTIONAL :: s_mstruct_changed, rho_changed, &
921 : potential_changed, full_reset
922 :
923 : CHARACTER(len=*), PARAMETER :: routineN = 'qs_ks_did_change'
924 :
925 : INTEGER :: handle
926 : LOGICAL :: my_mstruct_chg
927 :
928 198408 : CALL timeset(routineN, handle)
929 198408 : my_mstruct_chg = .FALSE.
930 :
931 198408 : IF (PRESENT(rho_changed)) THEN
932 177657 : IF (rho_changed) ks_env%rho_changed = .TRUE.
933 : END IF
934 :
935 198408 : IF (PRESENT(potential_changed)) THEN
936 1779 : IF (potential_changed) ks_env%potential_changed = .TRUE.
937 : END IF
938 :
939 198408 : IF (PRESENT(s_mstruct_changed)) THEN
940 19548 : IF (s_mstruct_changed) my_mstruct_chg = .TRUE.
941 : END IF
942 :
943 198408 : IF (PRESENT(full_reset)) THEN
944 0 : IF (full_reset) THEN
945 0 : ks_env%potential_changed = .TRUE.
946 : my_mstruct_chg = .TRUE.
947 : END IF
948 : END IF
949 :
950 198408 : IF (my_mstruct_chg) THEN
951 19548 : ks_env%s_mstruct_changed = .TRUE.
952 : ! *** deallocate matrices that will have the wrong structure ***
953 19548 : CALL kpoint_transitional_release(ks_env%matrix_ks)
954 : !TODO: deallocate imaginary parts as well
955 19548 : IF (ks_env%complex_ks) THEN
956 98 : CALL kpoint_transitional_release(ks_env%matrix_ks_im)
957 : END IF
958 : !CALL dbcsr_deallocate_matrix_set(ks_env%matrix_ks_im)
959 : !CALL dbcsr_deallocate_matrix_set(ks_env%matrix_ks_aux_fit_im)
960 : END IF
961 :
962 198408 : CALL timestop(handle)
963 :
964 198408 : END SUBROUTINE qs_ks_did_change
965 :
966 0 : END MODULE qs_ks_types
|