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