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 8664 : SUBROUTINE qs_ks_env_create(ks_env)
220 : TYPE(qs_ks_env_type), INTENT(OUT) :: ks_env
221 :
222 8664 : ALLOCATE (ks_env%rho)
223 8664 : CALL qs_rho_create(ks_env%rho)
224 8664 : ALLOCATE (ks_env%rho_xc)
225 8664 : CALL qs_rho_create(ks_env%rho_xc)
226 8664 : 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 13733683 : 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 13733683 : IF (.NOT. ASSOCIATED(ks_env%subsys)) CPABORT("get_ks_env: subsys not associated")
399 :
400 13733683 : IF (PRESENT(s_mstruct_changed)) s_mstruct_changed = ks_env%s_mstruct_changed
401 13733683 : IF (PRESENT(rho_changed)) rho_changed = ks_env%rho_changed
402 13733683 : IF (PRESENT(potential_changed)) potential_changed = ks_env%potential_changed
403 13733683 : IF (PRESENT(forces_up_to_date)) forces_up_to_date = ks_env%forces_up_to_date
404 13733683 : IF (PRESENT(complex_ks)) complex_ks = ks_env%complex_ks
405 13733683 : IF (PRESENT(exc_accint)) exc_accint = ks_env%exc_accint
406 13733683 : IF (PRESENT(v_hartree_rspace)) v_hartree_rspace => ks_env%v_hartree_rspace
407 :
408 13733683 : IF (PRESENT(matrix_ks)) matrix_ks => get_1d_pointer(ks_env%matrix_ks)
409 13733683 : IF (PRESENT(matrix_s)) matrix_s => get_1d_pointer(ks_env%matrix_s)
410 13733683 : IF (PRESENT(matrix_s_RI_aux)) matrix_s_RI_aux => get_1d_pointer(ks_env%matrix_s_RI_aux)
411 13733683 : IF (PRESENT(kinetic)) kinetic => get_1d_pointer(ks_env%kinetic)
412 13733683 : IF (PRESENT(matrix_h)) matrix_h => get_1d_pointer(ks_env%matrix_h)
413 13733683 : IF (PRESENT(matrix_h_im)) matrix_h_im => get_1d_pointer(ks_env%matrix_h_im)
414 13733683 : IF (PRESENT(matrix_w)) matrix_w => get_1d_pointer(ks_env%matrix_w)
415 13733683 : IF (PRESENT(matrix_vxc)) matrix_vxc => get_1d_pointer(ks_env%matrix_vxc)
416 :
417 13733683 : IF (PRESENT(matrix_ks_kp)) matrix_ks_kp => get_2d_pointer(ks_env%matrix_ks)
418 13733683 : IF (PRESENT(matrix_ks_im_kp)) matrix_ks_im_kp => get_2d_pointer(ks_env%matrix_ks_im)
419 13733683 : IF (PRESENT(matrix_s_kp)) matrix_s_kp => get_2d_pointer(ks_env%matrix_s)
420 13733683 : IF (PRESENT(matrix_s_RI_aux_kp)) matrix_s_RI_aux_kp => get_2d_pointer(ks_env%matrix_s_RI_aux)
421 13733683 : IF (PRESENT(matrix_w_kp)) matrix_w_kp => get_2d_pointer(ks_env%matrix_w)
422 13733683 : IF (PRESENT(kinetic_kp)) kinetic_kp => get_2d_pointer(ks_env%kinetic)
423 13733683 : IF (PRESENT(matrix_h_kp)) matrix_h_kp => get_2d_pointer(ks_env%matrix_h)
424 13733683 : IF (PRESENT(matrix_h_im_kp)) matrix_h_im_kp => get_2d_pointer(ks_env%matrix_h_im)
425 13733683 : IF (PRESENT(matrix_vxc_kp)) matrix_vxc_kp => get_2d_pointer(ks_env%matrix_vxc)
426 13733683 : IF (PRESENT(matrix_ks_im)) matrix_ks_im => get_1d_pointer(ks_env%matrix_ks_im)
427 :
428 13733683 : IF (PRESENT(matrix_p_mp2)) matrix_p_mp2 => ks_env%matrix_p_mp2
429 13733683 : IF (PRESENT(matrix_p_mp2_admm)) matrix_p_mp2_admm => ks_env%matrix_p_mp2_admm
430 13733683 : IF (PRESENT(rho)) rho => ks_env%rho
431 13733683 : IF (PRESENT(rho_xc)) rho_xc => ks_env%rho_xc
432 13733683 : IF (PRESENT(xcint_weights)) xcint_weights => ks_env%xcint_weights
433 13733683 : IF (PRESENT(rho_core)) rho_core => ks_env%rho_core
434 13733683 : IF (PRESENT(rho_nlcc)) rho_nlcc => ks_env%rho_nlcc
435 13733683 : IF (PRESENT(rho_nlcc_g)) rho_nlcc_g => ks_env%rho_nlcc_g
436 13733683 : IF (PRESENT(vppl)) vppl => ks_env%vppl
437 13733683 : IF (PRESENT(vee)) vee => ks_env%vee
438 :
439 13733683 : IF (PRESENT(neighbor_list_id)) neighbor_list_id = ks_env%neighbor_list_id
440 13733683 : IF (PRESENT(sab_orb)) sab_orb => ks_env%sab_orb
441 13733683 : IF (PRESENT(sab_all)) sab_all => ks_env%sab_all
442 13733683 : IF (PRESENT(sab_vdw)) sab_vdw => ks_env%sab_vdw
443 13733683 : IF (PRESENT(sab_scp)) sab_scp => ks_env%sab_scp
444 13733683 : IF (PRESENT(sac_ae)) sac_ae => ks_env%sac_ae
445 13733683 : IF (PRESENT(sac_ppl)) sac_ppl => ks_env%sac_ppl
446 13733683 : IF (PRESENT(sac_lri)) sac_lri => ks_env%sac_lri
447 13733683 : IF (PRESENT(sap_ppnl)) sap_ppnl => ks_env%sap_ppnl
448 13733683 : IF (PRESENT(sap_oce)) sap_oce => ks_env%sap_oce
449 13733683 : IF (PRESENT(sab_se)) sab_se => ks_env%sab_se
450 13733683 : IF (PRESENT(sab_lrc)) sab_lrc => ks_env%sab_lrc
451 13733683 : IF (PRESENT(sab_tbe)) sab_tbe => ks_env%sab_tbe
452 13733683 : IF (PRESENT(sab_xtbe)) sab_xtbe => ks_env%sab_xtbe
453 13733683 : IF (PRESENT(sab_core)) sab_core => ks_env%sab_core
454 13733683 : IF (PRESENT(sab_xb)) sab_xb => ks_env%sab_xb
455 13733683 : IF (PRESENT(sab_xtb_pp)) sab_xtb_pp => ks_env%sab_xtb_pp
456 13733683 : IF (PRESENT(sab_xtb_nonbond)) sab_xtb_nonbond => ks_env%sab_xtb_nonbond
457 13733683 : IF (PRESENT(sab_almo)) sab_almo => ks_env%sab_almo
458 13733683 : IF (PRESENT(sab_kp)) sab_kp => ks_env%sab_kp
459 13733683 : IF (PRESENT(sab_kp_nosym)) sab_kp_nosym => ks_env%sab_kp_nosym
460 13733683 : IF (PRESENT(sab_cneo)) sab_cneo => ks_env%sab_cneo
461 13733683 : IF (PRESENT(dft_control)) dft_control => ks_env%dft_control
462 13733683 : IF (PRESENT(dbcsr_dist)) dbcsr_dist => ks_env%dbcsr_dist
463 13733683 : IF (PRESENT(distribution_2d)) distribution_2d => ks_env%distribution_2d
464 13733683 : IF (PRESENT(pw_env)) pw_env => ks_env%pw_env
465 13733683 : IF (PRESENT(para_env)) para_env => ks_env%para_env
466 13733683 : IF (PRESENT(blacs_env)) blacs_env => ks_env%blacs_env
467 :
468 13733683 : IF (PRESENT(task_list)) task_list => ks_env%task_list
469 13733683 : IF (PRESENT(task_list_soft)) task_list_soft => ks_env%task_list_soft
470 :
471 13733683 : IF (PRESENT(kpoints)) kpoints => ks_env%kpoints
472 13733683 : IF (PRESENT(do_kpoints)) THEN
473 1052306 : do_kpoints = (ks_env%kpoints%nkp > 0)
474 : END IF
475 :
476 13733683 : 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 13733683 : nelectron_spin=nelectron_spin)
498 :
499 13733683 : 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 873015 : 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 873015 : IF (PRESENT(s_mstruct_changed)) ks_env%s_mstruct_changed = s_mstruct_changed
620 873015 : IF (PRESENT(rho_changed)) ks_env%rho_changed = rho_changed
621 873015 : IF (PRESENT(potential_changed)) ks_env%potential_changed = potential_changed
622 873015 : IF (PRESENT(forces_up_to_date)) ks_env%forces_up_to_date = forces_up_to_date
623 873015 : IF (PRESENT(complex_ks)) ks_env%complex_ks = complex_ks
624 873015 : IF (ks_env%s_mstruct_changed .OR. ks_env%potential_changed .OR. ks_env%rho_changed) THEN
625 479687 : ks_env%forces_up_to_date = .FALSE.
626 : END IF
627 873015 : IF (PRESENT(exc_accint)) ks_env%exc_accint = exc_accint
628 873015 : IF (PRESENT(v_hartree_rspace)) ks_env%v_hartree_rspace => v_hartree_rspace
629 :
630 873015 : IF (PRESENT(matrix_h)) CALL set_1d_pointer(ks_env%matrix_h, matrix_h)
631 873015 : IF (PRESENT(matrix_h_kp)) CALL set_2d_pointer(ks_env%matrix_h, matrix_h_kp)
632 :
633 873015 : IF (PRESENT(matrix_h_im)) CALL set_1d_pointer(ks_env%matrix_h_im, matrix_h_im)
634 873015 : IF (PRESENT(matrix_h_im_kp)) CALL set_2d_pointer(ks_env%matrix_h_im, matrix_h_im_kp)
635 :
636 873015 : IF (PRESENT(matrix_ks)) CALL set_1d_pointer(ks_env%matrix_ks, matrix_ks)
637 873015 : IF (PRESENT(matrix_ks_kp)) CALL set_2d_pointer(ks_env%matrix_ks, matrix_ks_kp)
638 :
639 873015 : IF (PRESENT(matrix_vxc)) CALL set_1d_pointer(ks_env%matrix_vxc, matrix_vxc)
640 873015 : IF (PRESENT(matrix_vxc_kp)) CALL set_2d_pointer(ks_env%matrix_vxc, matrix_vxc_kp)
641 :
642 873015 : IF (PRESENT(matrix_s)) CALL set_1d_pointer(ks_env%matrix_s, matrix_s)
643 873015 : IF (PRESENT(matrix_s_kp)) CALL set_2d_pointer(ks_env%matrix_s, matrix_s_kp)
644 :
645 873015 : IF (PRESENT(kinetic)) CALL set_1d_pointer(ks_env%kinetic, kinetic)
646 873015 : IF (PRESENT(kinetic_kp)) CALL set_2d_pointer(ks_env%kinetic, kinetic_kp)
647 :
648 873015 : IF (PRESENT(matrix_w)) CALL set_1d_pointer(ks_env%matrix_w, matrix_w)
649 873015 : IF (PRESENT(matrix_w_kp)) CALL set_2d_pointer(ks_env%matrix_w, matrix_w_kp)
650 :
651 873015 : IF (PRESENT(matrix_s_RI_aux)) CALL set_1d_pointer(ks_env%matrix_s_RI_aux, matrix_s_RI_aux)
652 873015 : IF (PRESENT(matrix_s_RI_aux_kp)) CALL set_2d_pointer(ks_env%matrix_s_RI_aux, matrix_s_RI_aux_kp)
653 :
654 873015 : IF (PRESENT(matrix_ks_im)) CALL set_1d_pointer(ks_env%matrix_ks_im, matrix_ks_im)
655 873015 : IF (PRESENT(matrix_ks_im_kp)) CALL set_2d_pointer(ks_env%matrix_ks_im, matrix_ks_im_kp)
656 :
657 873015 : IF (PRESENT(matrix_p_mp2)) ks_env%matrix_p_mp2 => matrix_p_mp2
658 873015 : IF (PRESENT(matrix_p_mp2_admm)) ks_env%matrix_p_mp2_admm => matrix_p_mp2_admm
659 873015 : IF (PRESENT(xcint_weights)) ks_env%xcint_weights => xcint_weights
660 873015 : IF (PRESENT(rho_core)) ks_env%rho_core => rho_core
661 873015 : IF (PRESENT(rho_nlcc)) ks_env%rho_nlcc => rho_nlcc
662 873015 : IF (PRESENT(rho_nlcc_g)) ks_env%rho_nlcc_g => rho_nlcc_g
663 873015 : IF (PRESENT(vppl)) ks_env%vppl => vppl
664 873015 : IF (PRESENT(vee)) ks_env%vee => vee
665 :
666 873015 : IF (PRESENT(neighbor_list_id)) ks_env%neighbor_list_id = neighbor_list_id
667 873015 : IF (PRESENT(kpoints)) ks_env%kpoints => kpoints
668 873015 : IF (PRESENT(sab_orb)) ks_env%sab_orb => sab_orb
669 873015 : IF (PRESENT(sab_vdw)) ks_env%sab_vdw => sab_vdw
670 873015 : IF (PRESENT(sab_scp)) ks_env%sab_scp => sab_scp
671 873015 : IF (PRESENT(sab_all)) ks_env%sab_all => sab_all
672 873015 : IF (PRESENT(sac_ae)) ks_env%sac_ae => sac_ae
673 873015 : IF (PRESENT(sac_ppl)) ks_env%sac_ppl => sac_ppl
674 873015 : IF (PRESENT(sac_lri)) ks_env%sac_lri => sac_lri
675 873015 : IF (PRESENT(sap_ppnl)) ks_env%sap_ppnl => sap_ppnl
676 873015 : IF (PRESENT(sap_oce)) ks_env%sap_oce => sap_oce
677 873015 : IF (PRESENT(sab_se)) ks_env%sab_se => sab_se
678 873015 : IF (PRESENT(sab_lrc)) ks_env%sab_lrc => sab_lrc
679 873015 : IF (PRESENT(sab_tbe)) ks_env%sab_tbe => sab_tbe
680 873015 : IF (PRESENT(sab_xtbe)) ks_env%sab_xtbe => sab_xtbe
681 873015 : IF (PRESENT(sab_core)) ks_env%sab_core => sab_core
682 873015 : IF (PRESENT(sab_xb)) ks_env%sab_xb => sab_xb
683 873015 : IF (PRESENT(sab_xtb_pp)) ks_env%sab_xtb_pp => sab_xtb_pp
684 873015 : IF (PRESENT(sab_xtb_nonbond)) ks_env%sab_xtb_nonbond => sab_xtb_nonbond
685 873015 : IF (PRESENT(sab_almo)) ks_env%sab_almo => sab_almo
686 873015 : IF (PRESENT(sab_kp)) ks_env%sab_kp => sab_kp
687 873015 : IF (PRESENT(sab_kp_nosym)) ks_env%sab_kp_nosym => sab_kp_nosym
688 873015 : IF (PRESENT(sab_cneo)) ks_env%sab_cneo => sab_cneo
689 :
690 873015 : IF (PRESENT(task_list)) ks_env%task_list => task_list
691 873015 : IF (PRESENT(task_list_soft)) ks_env%task_list_soft => task_list_soft
692 :
693 873015 : IF (PRESENT(subsys)) THEN
694 8664 : IF (ASSOCIATED(ks_env%subsys)) THEN
695 0 : IF (ASSOCIATED(ks_env%subsys, subsys)) THEN
696 0 : CALL qs_subsys_release(ks_env%subsys)
697 0 : DEALLOCATE (ks_env%subsys)
698 : END IF
699 : END IF
700 8664 : ks_env%subsys => subsys
701 : END IF
702 873015 : IF (PRESENT(dft_control)) THEN
703 8664 : IF (ASSOCIATED(ks_env%dft_control)) THEN
704 0 : IF (.NOT. ASSOCIATED(ks_env%dft_control, dft_control)) THEN
705 0 : CALL dft_control_release(ks_env%dft_control)
706 0 : DEALLOCATE (ks_env%dft_control)
707 : END IF
708 : END IF
709 8664 : ks_env%dft_control => dft_control
710 : END IF
711 873015 : IF (PRESENT(dbcsr_dist)) THEN
712 8664 : IF (ASSOCIATED(ks_env%dbcsr_dist)) THEN
713 0 : IF (.NOT. ASSOCIATED(ks_env%dbcsr_dist, dbcsr_dist)) THEN
714 0 : CALL dbcsr_distribution_release(ks_env%dbcsr_dist)
715 0 : DEALLOCATE (ks_env%dbcsr_dist)
716 : END IF
717 : END IF
718 8664 : ks_env%dbcsr_dist => dbcsr_dist
719 : END IF
720 873015 : IF (PRESENT(distribution_2d)) THEN
721 8664 : CALL distribution_2d_retain(distribution_2d)
722 8664 : CALL distribution_2d_release(ks_env%distribution_2d)
723 8664 : ks_env%distribution_2d => distribution_2d
724 : END IF
725 873015 : IF (PRESENT(pw_env)) THEN
726 8664 : CALL pw_env_retain(pw_env)
727 8664 : CALL pw_env_release(ks_env%pw_env)
728 8664 : ks_env%pw_env => pw_env
729 : END IF
730 873015 : IF (PRESENT(para_env)) THEN
731 8664 : CALL para_env%retain()
732 8664 : CALL mp_para_env_release(ks_env%para_env)
733 8664 : ks_env%para_env => para_env
734 : END IF
735 873015 : IF (PRESENT(blacs_env)) THEN
736 8664 : CALL blacs_env%retain()
737 8664 : CALL cp_blacs_env_release(ks_env%blacs_env)
738 8664 : ks_env%blacs_env => blacs_env
739 : END IF
740 873015 : END SUBROUTINE set_ks_env
741 :
742 : ! **************************************************************************************************
743 : !> \brief releases the ks_env (see doc/ReferenceCounting.html)
744 : !> \param ks_env the ks_env to be released
745 : !> \par History
746 : !> 05.2002 created [fawzi]
747 : !> \author Fawzi Mohamed
748 : ! **************************************************************************************************
749 8664 : SUBROUTINE qs_ks_release(ks_env)
750 : TYPE(qs_ks_env_type), INTENT(INOUT) :: ks_env
751 :
752 8664 : IF (ASSOCIATED(ks_env%v_hartree_rspace)) THEN
753 8655 : CALL ks_env%v_hartree_rspace%release()
754 8655 : DEALLOCATE (ks_env%v_hartree_rspace)
755 : END IF
756 :
757 8664 : CALL kpoint_transitional_release(ks_env%matrix_ks)
758 8664 : CALL kpoint_transitional_release(ks_env%matrix_ks_im)
759 8664 : CALL kpoint_transitional_release(ks_env%matrix_h)
760 8664 : CALL kpoint_transitional_release(ks_env%matrix_h_im)
761 8664 : CALL kpoint_transitional_release(ks_env%matrix_vxc)
762 8664 : CALL kpoint_transitional_release(ks_env%matrix_s)
763 8664 : CALL kpoint_transitional_release(ks_env%matrix_w)
764 8664 : CALL kpoint_transitional_release(ks_env%kinetic)
765 8664 : CALL kpoint_transitional_release(ks_env%matrix_s_RI_aux)
766 :
767 8664 : IF (ASSOCIATED(ks_env%matrix_p_mp2)) THEN
768 194 : CALL dbcsr_deallocate_matrix_set(ks_env%matrix_p_mp2)
769 : END IF
770 8664 : IF (ASSOCIATED(ks_env%matrix_p_mp2_admm)) THEN
771 36 : CALL dbcsr_deallocate_matrix_set(ks_env%matrix_p_mp2_admm)
772 : END IF
773 8664 : IF (ASSOCIATED(ks_env%rho)) THEN
774 8655 : CALL qs_rho_release(ks_env%rho)
775 8655 : DEALLOCATE (ks_env%rho)
776 : END IF
777 8664 : IF (ASSOCIATED(ks_env%rho_xc)) THEN
778 8655 : CALL qs_rho_release(ks_env%rho_xc)
779 8655 : DEALLOCATE (ks_env%rho_xc)
780 : END IF
781 8664 : IF (ASSOCIATED(ks_env%distribution_2d)) THEN
782 8664 : CALL distribution_2d_release(ks_env%distribution_2d)
783 : END IF
784 8664 : IF (ASSOCIATED(ks_env%task_list)) THEN
785 4991 : CALL deallocate_task_list(ks_env%task_list)
786 : END IF
787 8664 : IF (ASSOCIATED(ks_env%task_list_soft)) THEN
788 1356 : CALL deallocate_task_list(ks_env%task_list_soft)
789 : END IF
790 :
791 8664 : IF (ASSOCIATED(ks_env%xcint_weights)) THEN
792 266 : CALL ks_env%xcint_weights%release()
793 266 : DEALLOCATE (ks_env%xcint_weights)
794 : END IF
795 8664 : IF (ASSOCIATED(ks_env%rho_nlcc_g)) THEN
796 20 : CALL ks_env%rho_nlcc_g%release()
797 20 : DEALLOCATE (ks_env%rho_nlcc_g)
798 : END IF
799 8664 : IF (ASSOCIATED(ks_env%rho_nlcc)) THEN
800 20 : CALL ks_env%rho_nlcc%release()
801 20 : DEALLOCATE (ks_env%rho_nlcc)
802 : END IF
803 8664 : IF (ASSOCIATED(ks_env%rho_core)) THEN
804 5355 : CALL ks_env%rho_core%release()
805 5355 : DEALLOCATE (ks_env%rho_core)
806 : END IF
807 8664 : IF (ASSOCIATED(ks_env%vppl)) THEN
808 8 : CALL ks_env%vppl%release()
809 8 : DEALLOCATE (ks_env%vppl)
810 : END IF
811 8664 : IF (ASSOCIATED(ks_env%vee)) THEN
812 16 : CALL ks_env%vee%release()
813 16 : DEALLOCATE (ks_env%vee)
814 : END IF
815 8664 : IF (ASSOCIATED(ks_env%dbcsr_dist)) THEN
816 8664 : CALL dbcsr_distribution_release(ks_env%dbcsr_dist)
817 8664 : DEALLOCATE (ks_env%dbcsr_dist)
818 : END IF
819 :
820 8664 : CALL release_neighbor_list_sets(ks_env%sab_orb)
821 8664 : CALL release_neighbor_list_sets(ks_env%sac_ae)
822 8664 : CALL release_neighbor_list_sets(ks_env%sac_ppl)
823 8664 : CALL release_neighbor_list_sets(ks_env%sac_lri)
824 8664 : CALL release_neighbor_list_sets(ks_env%sap_ppnl)
825 8664 : CALL release_neighbor_list_sets(ks_env%sap_oce)
826 8664 : CALL release_neighbor_list_sets(ks_env%sab_se)
827 8664 : CALL release_neighbor_list_sets(ks_env%sab_vdw)
828 8664 : CALL release_neighbor_list_sets(ks_env%sab_scp)
829 8664 : CALL release_neighbor_list_sets(ks_env%sab_tbe)
830 8664 : CALL release_neighbor_list_sets(ks_env%sab_xtbe)
831 8664 : CALL release_neighbor_list_sets(ks_env%sab_core)
832 8664 : CALL release_neighbor_list_sets(ks_env%sab_xb)
833 8664 : CALL release_neighbor_list_sets(ks_env%sab_xtb_pp)
834 8664 : CALL release_neighbor_list_sets(ks_env%sab_xtb_nonbond)
835 8664 : CALL release_neighbor_list_sets(ks_env%sab_all)
836 8664 : CALL release_neighbor_list_sets(ks_env%sab_lrc)
837 8664 : CALL release_neighbor_list_sets(ks_env%sab_almo)
838 8664 : CALL release_neighbor_list_sets(ks_env%sab_kp)
839 8664 : CALL release_neighbor_list_sets(ks_env%sab_kp_nosym)
840 8664 : CALL release_neighbor_list_sets(ks_env%sab_cneo)
841 8664 : IF (ASSOCIATED(ks_env%dft_control)) THEN
842 8664 : CALL dft_control_release(ks_env%dft_control)
843 8664 : DEALLOCATE (ks_env%dft_control)
844 : END IF
845 8664 : CALL kpoint_release(ks_env%kpoints)
846 8664 : IF (ASSOCIATED(ks_env%subsys)) THEN
847 8664 : CALL qs_subsys_release(ks_env%subsys)
848 8664 : DEALLOCATE (ks_env%subsys)
849 : END IF
850 8664 : CALL pw_env_release(ks_env%pw_env)
851 8664 : CALL mp_para_env_release(ks_env%para_env)
852 8664 : CALL cp_blacs_env_release(ks_env%blacs_env)
853 :
854 8664 : END SUBROUTINE qs_ks_release
855 :
856 : ! **************************************************************************************************
857 : !> \brief releases part of the ks_env
858 : !> \param ks_env the ks_env to be released
859 : !> \par History
860 : !> 04.2022 created [JGH]
861 : ! **************************************************************************************************
862 9 : SUBROUTINE qs_ks_part_release(ks_env)
863 : TYPE(qs_ks_env_type), INTENT(INOUT) :: ks_env
864 :
865 9 : IF (ASSOCIATED(ks_env%v_hartree_rspace)) THEN
866 9 : CALL ks_env%v_hartree_rspace%release()
867 9 : DEALLOCATE (ks_env%v_hartree_rspace)
868 : END IF
869 :
870 9 : CALL kpoint_transitional_release(ks_env%matrix_h)
871 9 : CALL kpoint_transitional_release(ks_env%matrix_h_im)
872 9 : CALL kpoint_transitional_release(ks_env%matrix_ks_im)
873 9 : CALL kpoint_transitional_release(ks_env%matrix_vxc)
874 9 : CALL kpoint_transitional_release(ks_env%matrix_w)
875 9 : CALL kpoint_transitional_release(ks_env%kinetic)
876 9 : CALL kpoint_transitional_release(ks_env%matrix_s_RI_aux)
877 :
878 9 : IF (ASSOCIATED(ks_env%matrix_p_mp2)) THEN
879 0 : CALL dbcsr_deallocate_matrix_set(ks_env%matrix_p_mp2)
880 : END IF
881 9 : IF (ASSOCIATED(ks_env%matrix_p_mp2_admm)) THEN
882 0 : CALL dbcsr_deallocate_matrix_set(ks_env%matrix_p_mp2_admm)
883 : END IF
884 9 : IF (ASSOCIATED(ks_env%rho)) THEN
885 9 : CALL qs_rho_release(ks_env%rho)
886 9 : DEALLOCATE (ks_env%rho)
887 : END IF
888 9 : IF (ASSOCIATED(ks_env%rho_xc)) THEN
889 9 : CALL qs_rho_release(ks_env%rho_xc)
890 9 : DEALLOCATE (ks_env%rho_xc)
891 : END IF
892 9 : IF (ASSOCIATED(ks_env%task_list)) THEN
893 9 : CALL deallocate_task_list(ks_env%task_list)
894 : END IF
895 9 : IF (ASSOCIATED(ks_env%task_list_soft)) THEN
896 0 : CALL deallocate_task_list(ks_env%task_list_soft)
897 : END IF
898 :
899 9 : IF (ASSOCIATED(ks_env%xcint_weights)) THEN
900 0 : CALL ks_env%xcint_weights%release()
901 0 : DEALLOCATE (ks_env%xcint_weights)
902 : END IF
903 9 : IF (ASSOCIATED(ks_env%rho_nlcc_g)) THEN
904 0 : CALL ks_env%rho_nlcc_g%release()
905 0 : DEALLOCATE (ks_env%rho_nlcc_g)
906 : END IF
907 9 : IF (ASSOCIATED(ks_env%rho_nlcc)) THEN
908 0 : CALL ks_env%rho_nlcc%release()
909 0 : DEALLOCATE (ks_env%rho_nlcc)
910 : END IF
911 9 : IF (ASSOCIATED(ks_env%rho_core)) THEN
912 9 : CALL ks_env%rho_core%release()
913 9 : DEALLOCATE (ks_env%rho_core)
914 : END IF
915 9 : IF (ASSOCIATED(ks_env%vppl)) THEN
916 0 : CALL ks_env%vppl%release()
917 0 : DEALLOCATE (ks_env%vppl)
918 : END IF
919 9 : IF (ASSOCIATED(ks_env%vee)) THEN
920 0 : CALL ks_env%vee%release()
921 0 : DEALLOCATE (ks_env%vee)
922 : END IF
923 :
924 9 : CALL release_neighbor_list_sets(ks_env%sac_ae)
925 9 : CALL release_neighbor_list_sets(ks_env%sac_ppl)
926 9 : CALL release_neighbor_list_sets(ks_env%sac_lri)
927 9 : CALL release_neighbor_list_sets(ks_env%sap_ppnl)
928 9 : CALL release_neighbor_list_sets(ks_env%sap_oce)
929 9 : CALL release_neighbor_list_sets(ks_env%sab_se)
930 9 : CALL release_neighbor_list_sets(ks_env%sab_vdw)
931 9 : CALL release_neighbor_list_sets(ks_env%sab_scp)
932 9 : CALL release_neighbor_list_sets(ks_env%sab_tbe)
933 9 : CALL release_neighbor_list_sets(ks_env%sab_xtbe)
934 9 : CALL release_neighbor_list_sets(ks_env%sab_core)
935 9 : CALL release_neighbor_list_sets(ks_env%sab_xb)
936 9 : CALL release_neighbor_list_sets(ks_env%sab_xtb_pp)
937 9 : CALL release_neighbor_list_sets(ks_env%sab_xtb_nonbond)
938 9 : CALL release_neighbor_list_sets(ks_env%sab_all)
939 9 : CALL release_neighbor_list_sets(ks_env%sab_lrc)
940 9 : CALL release_neighbor_list_sets(ks_env%sab_almo)
941 9 : CALL release_neighbor_list_sets(ks_env%sab_kp)
942 9 : CALL release_neighbor_list_sets(ks_env%sab_kp_nosym)
943 9 : CALL release_neighbor_list_sets(ks_env%sab_cneo)
944 9 : CALL kpoint_release(ks_env%kpoints)
945 9 : CALL pw_env_release(ks_env%pw_env, ks_env%para_env)
946 9 : END SUBROUTINE qs_ks_part_release
947 :
948 : ! **************************************************************************************************
949 : !> \brief tells that some of the things relevant to the ks calculation
950 : !> did change. has to be called when changes happen otherwise
951 : !> the calculation will give wrong results.
952 : !> \param ks_env the environment that is informed about the changes
953 : !> \param s_mstruct_changed if true it means that the structure of the
954 : !> overlap matrix has changed
955 : !> (atoms have moved)
956 : !> \param rho_changed if true it means that the density has changed
957 : !> \param potential_changed ...
958 : !> \param full_reset if true everything has changed
959 : !> \par History
960 : !> 4.2002 created [fawzi]
961 : !> 12.2014 moved from qs_ks_methods, added deallocation of KS-matrices [Ole Schuett]
962 : !> \author Fawzi Mohamed
963 : ! **************************************************************************************************
964 293619 : SUBROUTINE qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, &
965 : potential_changed, full_reset)
966 : TYPE(qs_ks_env_type), INTENT(INOUT) :: ks_env
967 : LOGICAL, INTENT(in), OPTIONAL :: s_mstruct_changed, rho_changed, &
968 : potential_changed, full_reset
969 :
970 : CHARACTER(len=*), PARAMETER :: routineN = 'qs_ks_did_change'
971 :
972 : INTEGER :: handle
973 : LOGICAL :: my_mstruct_chg
974 :
975 293619 : CALL timeset(routineN, handle)
976 293619 : my_mstruct_chg = .FALSE.
977 :
978 293619 : IF (PRESENT(rho_changed)) THEN
979 264121 : IF (rho_changed) ks_env%rho_changed = .TRUE.
980 : END IF
981 :
982 293619 : IF (PRESENT(potential_changed)) THEN
983 4094 : IF (potential_changed) ks_env%potential_changed = .TRUE.
984 : END IF
985 :
986 293619 : IF (PRESENT(s_mstruct_changed)) THEN
987 28234 : IF (s_mstruct_changed) my_mstruct_chg = .TRUE.
988 : END IF
989 :
990 293619 : IF (PRESENT(full_reset)) THEN
991 0 : IF (full_reset) THEN
992 0 : ks_env%potential_changed = .TRUE.
993 : my_mstruct_chg = .TRUE.
994 : END IF
995 : END IF
996 :
997 293619 : IF (my_mstruct_chg) THEN
998 28234 : ks_env%s_mstruct_changed = .TRUE.
999 : ! *** deallocate matrices that will have the wrong structure ***
1000 28234 : CALL kpoint_transitional_release(ks_env%matrix_ks)
1001 : !TODO: deallocate imaginary parts as well
1002 28234 : IF (ks_env%complex_ks) THEN
1003 102 : CALL kpoint_transitional_release(ks_env%matrix_ks_im)
1004 : END IF
1005 : !CALL dbcsr_deallocate_matrix_set(ks_env%matrix_ks_im)
1006 : !CALL dbcsr_deallocate_matrix_set(ks_env%matrix_ks_aux_fit_im)
1007 : END IF
1008 :
1009 293619 : CALL timestop(handle)
1010 :
1011 293619 : END SUBROUTINE qs_ks_did_change
1012 :
1013 0 : END MODULE qs_ks_types
|