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