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