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