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