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