Line data Source code
1 : !--------------------------------------------------------------------------------------------------!
2 : ! CP2K: A general program to perform molecular dynamics simulations !
3 : ! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4 : ! !
5 : ! SPDX-License-Identifier: GPL-2.0-or-later !
6 : !--------------------------------------------------------------------------------------------------!
7 :
8 : ! **************************************************************************************************
9 : !> \par History
10 : !> - mo_set_p_type added to qs_env (23.04.02,MK)
11 : !> - qs_force_type added to qs_env (05.06.02,MK)
12 : !> \author MK (23.01.2002)
13 : ! **************************************************************************************************
14 : MODULE qs_environment_types
15 : USE admm_types, ONLY: admm_env_release,&
16 : admm_type
17 : USE almo_scf_types, ONLY: almo_scf_env_release,&
18 : almo_scf_env_type
19 : USE atomic_kind_types, ONLY: atomic_kind_type
20 : USE atprop_types, ONLY: atprop_type
21 : USE cell_types, ONLY: cell_release,&
22 : cell_retain,&
23 : cell_type
24 : USE cp_blacs_env, ONLY: cp_blacs_env_type
25 : USE cp_control_types, ONLY: dft_control_type
26 : USE cp_dbcsr_api, ONLY: dbcsr_distribution_type,&
27 : dbcsr_p_type,&
28 : dbcsr_release_p
29 : USE cp_ddapc_types, ONLY: cp_ddapc_ewald_release,&
30 : cp_ddapc_ewald_type,&
31 : cp_ddapc_release,&
32 : cp_ddapc_type
33 : USE cp_fm_types, ONLY: cp_fm_release,&
34 : cp_fm_type
35 : USE cp_result_types, ONLY: cp_result_type
36 : USE cp_subsys_types, ONLY: cp_subsys_type
37 : USE distribution_1d_types, ONLY: distribution_1d_type
38 : USE distribution_2d_types, ONLY: distribution_2d_type
39 : USE dm_ls_scf_types, ONLY: ls_scf_env_type,&
40 : ls_scf_release
41 : USE ec_env_types, ONLY: ec_env_release,&
42 : energy_correction_type
43 : USE et_coupling_types, ONLY: et_coupling_release,&
44 : et_coupling_type
45 : USE ewald_environment_types, ONLY: ewald_env_release,&
46 : ewald_environment_type
47 : USE ewald_pw_types, ONLY: ewald_pw_release,&
48 : ewald_pw_type
49 : USE exstates_types, ONLY: excited_energy_type,&
50 : exstate_release
51 : USE fist_nonbond_env_types, ONLY: fist_nonbond_env_release,&
52 : fist_nonbond_env_type
53 : USE global_types, ONLY: global_environment_type
54 : USE hartree_local_types, ONLY: ecoul_1center_type,&
55 : get_hartree_local,&
56 : hartree_local_create,&
57 : hartree_local_release,&
58 : hartree_local_type,&
59 : set_hartree_local
60 : USE hfx_types, ONLY: hfx_release,&
61 : hfx_type
62 : USE input_constants, ONLY: energy_force_run,&
63 : energy_run
64 : USE input_section_types, ONLY: section_vals_release,&
65 : section_vals_retain,&
66 : section_vals_type
67 : USE kg_environment_types, ONLY: kg_env_release,&
68 : kg_environment_type
69 : USE kinds, ONLY: dp
70 : USE kpoint_types, ONLY: kpoint_type
71 : USE lri_environment_types, ONLY: lri_density_release,&
72 : lri_density_type,&
73 : lri_env_release,&
74 : lri_environment_type
75 : USE message_passing, ONLY: mp_para_env_type
76 : USE molecule_kind_types, ONLY: molecule_kind_type
77 : USE molecule_types, ONLY: molecule_type
78 : USE mp2_types, ONLY: mp2_env_release,&
79 : mp2_type
80 : USE mscfg_types, ONLY: molecular_scf_guess_env_destroy,&
81 : molecular_scf_guess_env_type
82 : USE particle_types, ONLY: particle_type
83 : USE post_scf_bandstructure_types, ONLY: bs_env_release,&
84 : post_scf_bandstructure_type
85 : USE pw_env_types, ONLY: pw_env_type
86 : USE pw_types, ONLY: pw_c1d_gs_type,&
87 : pw_r3d_rs_type
88 : USE qmmm_types_low, ONLY: qmmm_env_qm_type
89 : USE qs_active_space_types, ONLY: active_space_type,&
90 : release_active_space_type
91 : USE qs_charges_types, ONLY: qs_charges_release,&
92 : qs_charges_type
93 : USE qs_cneo_types, ONLY: rhoz_cneo_type
94 : USE qs_dftb_types, ONLY: qs_dftb_pairpot_release,&
95 : qs_dftb_pairpot_type
96 : USE qs_dispersion_types, ONLY: qs_dispersion_release,&
97 : qs_dispersion_type
98 : USE qs_energy_types, ONLY: qs_energy_type
99 : USE qs_force_types, ONLY: qs_force_type
100 : USE qs_gcp_types, ONLY: qs_gcp_release,&
101 : qs_gcp_type
102 : USE qs_harris_types, ONLY: harris_env_release,&
103 : harris_type
104 : USE qs_kind_types, ONLY: qs_kind_type
105 : USE qs_ks_qmmm_types, ONLY: qs_ks_qmmm_env_type,&
106 : qs_ks_qmmm_release
107 : USE qs_ks_types, ONLY: get_ks_env,&
108 : qs_ks_env_type,&
109 : qs_ks_part_release,&
110 : qs_ks_release,&
111 : set_ks_env
112 : USE qs_linres_types, ONLY: linres_control_release,&
113 : linres_control_type,&
114 : polar_env_release,&
115 : polar_env_type
116 : USE qs_local_rho_types, ONLY: get_local_rho,&
117 : local_rho_set_create,&
118 : local_rho_set_release,&
119 : local_rho_type,&
120 : rhoz_type,&
121 : set_local_rho
122 : USE qs_matrix_pools, ONLY: mpools_release,&
123 : mpools_retain,&
124 : qs_matrix_pools_type
125 : USE qs_mo_types, ONLY: deallocate_mo_set,&
126 : mo_set_type
127 : USE qs_neighbor_list_types, ONLY: neighbor_list_set_p_type
128 : USE qs_oce_types, ONLY: deallocate_oce_set,&
129 : oce_matrix_type
130 : USE qs_period_efield_types, ONLY: efield_berry_release,&
131 : efield_berry_type
132 : USE qs_rho0_types, ONLY: rho0_atom_type,&
133 : rho0_mpole_type
134 : USE qs_rho_atom_types, ONLY: rho_atom_type
135 : USE qs_rho_types, ONLY: qs_rho_p_type,&
136 : qs_rho_release,&
137 : qs_rho_type
138 : USE qs_scf_types, ONLY: qs_scf_env_type,&
139 : scf_env_release
140 : USE qs_subsys_types, ONLY: qs_subsys_set,&
141 : qs_subsys_type
142 : USE qs_wf_history_types, ONLY: qs_wf_history_type,&
143 : wfi_release,&
144 : wfi_retain
145 : USE rel_control_types, ONLY: rel_c_release,&
146 : rel_control_type
147 : USE rt_propagation_types, ONLY: rt_prop_release,&
148 : rt_prop_type
149 : USE scf_control_types, ONLY: scf_c_release,&
150 : scf_control_type
151 : USE semi_empirical_mpole_types, ONLY: nddo_mpole_release,&
152 : nddo_mpole_type
153 : USE semi_empirical_store_int_types, ONLY: semi_empirical_si_release,&
154 : semi_empirical_si_type
155 : USE semi_empirical_types, ONLY: se_taper_release,&
156 : se_taper_type
157 : USE task_list_types, ONLY: task_list_type
158 : USE tblite_types, ONLY: deallocate_tblite_type,&
159 : tblite_type
160 : USE transport_env_types, ONLY: transport_env_release,&
161 : transport_env_type
162 : USE virial_types, ONLY: virial_type
163 : USE wannier_states_types, ONLY: wannier_centres_type
164 : USE xas_env_types, ONLY: xas_env_release,&
165 : xas_environment_type
166 : #include "./base/base_uses.f90"
167 :
168 : IMPLICIT NONE
169 :
170 : PRIVATE
171 :
172 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_environment_types'
173 :
174 : ! *** Public data types ***
175 :
176 : PUBLIC :: qs_environment_type
177 :
178 : ! *** Public subroutines ***
179 :
180 : PUBLIC :: get_qs_env, &
181 : qs_env_create, &
182 : qs_env_release, &
183 : qs_env_part_release, &
184 : set_qs_env
185 :
186 : ! **************************************************************************************************
187 : !> \param local_rho_set contains the atomic, compensations and core densities
188 : !> and the local parts of the xc terms
189 : !> \param hartree_local contains the 1, 2 and 3 centers coulomb terms
190 : !> \param requires_mo_derivs logical, true if dE/dC is required (e.g. OT)
191 : !> \param has_unit_metric logical, true if the S matrix is considered unity for the SCF
192 : !> \param mo_derivs the actual derivatives of the total energy wrt to MO coeffs (divided by 2*f_i)
193 : !> \param xas_env temporary information for xas calculation
194 : !> \param dftb_potential pair potentials for use with DFTB
195 : !> \param dispersion_env environment for use with QS dispersion
196 : !>
197 : !> compatibility get (things that you should get from the subsys):
198 : !> \param atomic_kind_set array with infos about the species (atomic_kinds)
199 : !> present in the system
200 : !> \param particle_set info on the atoms you simulate, pos,...
201 : !> \param local_particles which particles ar local to this processor
202 : !> new:
203 : !> \param local_molecules which molecules are local to this processor
204 : !> \param molecule_kind_set description of the molecule kinds
205 : !> \param molecule_set all the molecule description
206 : !> \param rtp all data needed for real time propagation
207 : !> \param x contains data used in Hartree-Fock-Exchange calculations
208 : !> \param task_list the list of tasks used in collocate and integrate
209 : !> \param task_list_soft the list of tasks used in collocate and integrate in case of soft basis functions
210 : !> \param mo_loc_history if a history of localized wfn is kept, they are stored here.
211 : !> \param molecular_scf_guess_env contains inforamation about and results of claculations
212 : !> on separate molecules
213 : !> \par History
214 : !> 11.2002 added doc and attribute description [fawzi]
215 : !> 08.2004 renamed some of the very short names (s,c,k,h) for easier grepping
216 : !> 06.2018 polar_env added (MK)
217 : !> \author Matthias Krack & fawzi
218 : ! **************************************************************************************************
219 :
220 : TYPE qs_environment_type
221 : LOGICAL :: qmmm = .FALSE., qmmm_periodic = .FALSE.
222 : LOGICAL :: mimic = .FALSE.
223 : LOGICAL :: requires_mo_derivs = .FALSE.
224 : LOGICAL :: requires_matrix_vxc = .FALSE.
225 : LOGICAL :: has_unit_metric = .FALSE.
226 : LOGICAL :: run_rtp = .FALSE.
227 : LOGICAL :: linres_run = .FALSE.
228 : LOGICAL :: calc_image_preconditioner = .FALSE.
229 : LOGICAL :: do_transport = .FALSE.
230 : LOGICAL :: single_point_run = .FALSE.
231 : LOGICAL :: given_embed_pot = .FALSE.
232 : LOGICAL :: energy_correction = .FALSE.
233 : LOGICAL :: harris_method = .FALSE.
234 : LOGICAL :: do_rixs = .FALSE.
235 : REAL(KIND=dp) :: sim_time = -1.0_dp
236 : REAL(KIND=dp) :: start_time = -1.0_dp, target_time = -1.0_dp
237 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: image_matrix => NULL()
238 : REAL(KIND=dp), DIMENSION(:), POINTER :: image_coeff => NULL()
239 : INTEGER, DIMENSION(:), POINTER :: ipiv => NULL()
240 : INTEGER :: sim_step = -1
241 : TYPE(ls_scf_env_type), POINTER :: ls_scf_env => NULL()
242 : TYPE(almo_scf_env_type), POINTER :: almo_scf_env => NULL()
243 : TYPE(transport_env_type), POINTER :: transport_env => NULL()
244 : TYPE(cell_type), POINTER :: super_cell => NULL()
245 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos => NULL()
246 : TYPE(cp_fm_type), DIMENSION(:), POINTER :: mo_loc_history => NULL()
247 : TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: mo_derivs => NULL()
248 : TYPE(scf_control_type), POINTER :: scf_control => NULL()
249 : TYPE(rel_control_type), POINTER :: rel_control => NULL()
250 : ! ZMP adding variables
251 : TYPE(qs_rho_type), POINTER :: rho_external => NULL()
252 : TYPE(pw_r3d_rs_type), POINTER :: external_vxc => NULL()
253 : TYPE(pw_r3d_rs_type), POINTER :: mask => NULL()
254 : TYPE(qs_charges_type), POINTER :: qs_charges => NULL()
255 : TYPE(qs_ks_env_type), POINTER :: ks_env => NULL()
256 : TYPE(qs_ks_qmmm_env_type), POINTER :: ks_qmmm_env => NULL()
257 : TYPE(qmmm_env_qm_type), POINTER :: qmmm_env_qm => NULL()
258 : TYPE(qs_wf_history_type), POINTER :: wf_history => NULL()
259 : TYPE(qs_scf_env_type), POINTER :: scf_env => NULL()
260 : TYPE(qs_matrix_pools_type), POINTER :: mpools => NULL()
261 : TYPE(oce_matrix_type), POINTER :: oce => NULL()
262 : TYPE(local_rho_type), POINTER :: local_rho_set => NULL()
263 : TYPE(hartree_local_type), POINTER :: hartree_local => NULL()
264 : TYPE(section_vals_type), POINTER :: input => NULL()
265 : TYPE(linres_control_type), POINTER :: linres_control => NULL()
266 : TYPE(xas_environment_type), POINTER :: xas_env => NULL()
267 : TYPE(cp_ddapc_type), POINTER :: cp_ddapc_env => NULL()
268 : TYPE(cp_ddapc_ewald_type), POINTER :: cp_ddapc_ewald => NULL()
269 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: outer_scf_history => NULL()
270 : INTEGER :: outer_scf_ihistory = -1
271 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: gradient_history => NULL(), &
272 : variable_history => NULL()
273 : TYPE(hfx_type), DIMENSION(:, :), POINTER :: x_data => NULL()
274 : TYPE(et_coupling_type), POINTER :: et_coupling => NULL()
275 : TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), POINTER :: dftb_potential => NULL()
276 : TYPE(admm_type), POINTER :: admm_env => NULL()
277 : TYPE(active_space_type), POINTER :: active_space => NULL()
278 : ! LRI
279 : TYPE(lri_environment_type), POINTER :: lri_env => NULL()
280 : TYPE(lri_density_type), POINTER :: lri_density => NULL()
281 : ! Harris model
282 : TYPE(harris_type), POINTER :: harris_env => NULL()
283 : ! Energy correction
284 : TYPE(energy_correction_type), POINTER :: ec_env => NULL()
285 : ! Excited States
286 : LOGICAL :: excited_state = .FALSE.
287 : TYPE(excited_energy_type), POINTER :: exstate_env => NULL()
288 : ! Empirical dispersion
289 : TYPE(qs_dispersion_type), POINTER :: dispersion_env => NULL()
290 : ! Empirical geometrical BSSE correction
291 : TYPE(qs_gcp_type), POINTER :: gcp_env => NULL()
292 : ! Semi-empirical and DFTB types
293 : TYPE(ewald_environment_type), POINTER :: ewald_env => NULL()
294 : TYPE(ewald_pw_type), POINTER :: ewald_pw => NULL()
295 : ! Semi-empirical types
296 : TYPE(se_taper_type), POINTER :: se_taper => NULL()
297 : TYPE(semi_empirical_si_type), POINTER :: se_store_int_env => NULL()
298 : TYPE(nddo_mpole_type), POINTER :: se_nddo_mpole => NULL()
299 : TYPE(fist_nonbond_env_type), POINTER :: se_nonbond_env => NULL()
300 : TYPE(rt_prop_type), POINTER :: rtp => NULL()
301 : TYPE(efield_berry_type), POINTER :: efield => NULL()
302 : ! a history for the broyden ot
303 : REAL(KIND=dp) :: broyden_adaptive_sigma = -1.0_dp
304 : TYPE(mp2_type), POINTER :: mp2_env => NULL()
305 : TYPE(post_scf_bandstructure_type), POINTER :: bs_env => NULL()
306 : TYPE(kg_environment_type), POINTER :: kg_env => NULL()
307 : TYPE(wannier_centres_type), POINTER, DIMENSION(:) :: WannierCentres => NULL()
308 : TYPE(molecular_scf_guess_env_type), POINTER :: molecular_scf_guess_env => NULL()
309 : ! Subsystem densities
310 : TYPE(qs_rho_p_type), DIMENSION(:), POINTER :: subsys_dens => NULL()
311 : ! Embedding potential
312 : TYPE(pw_r3d_rs_type), POINTER :: embed_pot => NULL()
313 : TYPE(pw_r3d_rs_type), POINTER :: spin_embed_pot => NULL()
314 : ! Polarizability tensor
315 : TYPE(polar_env_type), POINTER :: polar_env => NULL()
316 : ! EEQ charges
317 : REAL(KIND=dp), DIMENSION(:), POINTER :: eeq => NULL()
318 : ! Resp charges
319 : REAL(KIND=dp), DIMENSION(:), POINTER :: rhs => NULL()
320 : REAL(KIND=dp) :: total_zeff_corr = -1.0_dp, surface_dipole_moment = -1.0_dp
321 : LOGICAL :: surface_dipole_switch_off = .FALSE.
322 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos_last_converged => NULL()
323 : ! tblite
324 : TYPE(tblite_type), POINTER :: tb_tblite => Null()
325 : END TYPE qs_environment_type
326 :
327 : CONTAINS
328 :
329 : ! **************************************************************************************************
330 : !> \brief Get the QUICKSTEP environment.
331 : !> \param qs_env ...
332 : !> \param atomic_kind_set ...
333 : !> \param qs_kind_set ...
334 : !> \param cell ...
335 : !> \param super_cell ...
336 : !> \param cell_ref ...
337 : !> \param use_ref_cell ...
338 : !> \param kpoints ...
339 : !> \param dft_control ...
340 : !> \param mos ...
341 : !> \param sab_orb ...
342 : !> \param sab_all ...
343 : !> \param qmmm ...
344 : !> \param qmmm_periodic ...
345 : !> \param mimic ...
346 : !> \param sac_ae ...
347 : !> \param sac_ppl ...
348 : !> \param sac_lri ...
349 : !> \param sap_ppnl ...
350 : !> \param sab_vdw ...
351 : !> \param sab_scp ...
352 : !> \param sap_oce ...
353 : !> \param sab_lrc ...
354 : !> \param sab_se ...
355 : !> \param sab_xtbe ...
356 : !> \param sab_tbe ...
357 : !> \param sab_core ...
358 : !> \param sab_xb ...
359 : !> \param sab_xtb_pp ...
360 : !> \param sab_xtb_nonbond ...
361 : !> \param sab_almo ...
362 : !> \param sab_kp ...
363 : !> \param sab_kp_nosym ...
364 : !> \param sab_cneo ...
365 : !> \param particle_set ...
366 : !> \param energy ...
367 : !> \param force ...
368 : !> \param matrix_h ...
369 : !> \param matrix_h_im ...
370 : !> \param matrix_ks ...
371 : !> \param matrix_ks_im ...
372 : !> \param matrix_vxc ...
373 : !> \param run_rtp ...
374 : !> \param rtp ...
375 : !> \param matrix_h_kp ...
376 : !> \param matrix_h_im_kp ...
377 : !> \param matrix_ks_kp ...
378 : !> \param matrix_ks_im_kp ...
379 : !> \param matrix_vxc_kp ...
380 : !> \param kinetic_kp ...
381 : !> \param matrix_s_kp ...
382 : !> \param matrix_w_kp ...
383 : !> \param matrix_s_RI_aux_kp ...
384 : !> \param matrix_s ...
385 : !> \param matrix_s_RI_aux ...
386 : !> \param matrix_w ...
387 : !> \param matrix_p_mp2 ...
388 : !> \param matrix_p_mp2_admm ...
389 : !> \param rho ...
390 : !> \param rho_xc ...
391 : !> \param pw_env ...
392 : !> \param ewald_env ...
393 : !> \param ewald_pw ...
394 : !> \param active_space ...
395 : !> \param mpools ...
396 : !> \param input ...
397 : !> \param para_env ...
398 : !> \param blacs_env ...
399 : !> \param scf_control ...
400 : !> \param rel_control ...
401 : !> \param kinetic ...
402 : !> \param qs_charges ...
403 : !> \param vppl ...
404 : !> \param rho_core ...
405 : !> \param rho_nlcc ...
406 : !> \param rho_nlcc_g ...
407 : !> \param ks_env ...
408 : !> \param ks_qmmm_env ...
409 : !> \param wf_history ...
410 : !> \param scf_env ...
411 : !> \param local_particles ...
412 : !> \param local_molecules ...
413 : !> \param distribution_2d ...
414 : !> \param dbcsr_dist ...
415 : !> \param molecule_kind_set ...
416 : !> \param molecule_set ...
417 : !> \param subsys ...
418 : !> \param cp_subsys ...
419 : !> \param oce ...
420 : !> \param local_rho_set ...
421 : !> \param rho_atom_set ...
422 : !> \param task_list ...
423 : !> \param task_list_soft ...
424 : !> \param rho0_atom_set ...
425 : !> \param rho0_mpole ...
426 : !> \param rhoz_set ...
427 : !> \param rhoz_cneo_set ...
428 : !> \param ecoul_1c ...
429 : !> \param rho0_s_rs ...
430 : !> \param rho0_s_gs ...
431 : !> \param rhoz_cneo_s_rs ...
432 : !> \param rhoz_cneo_s_gs ...
433 : !> \param do_kpoints ...
434 : !> \param has_unit_metric ...
435 : !> \param requires_mo_derivs ...
436 : !> \param mo_derivs ...
437 : !> \param mo_loc_history ...
438 : !> \param nkind ...
439 : !> \param natom ...
440 : !> \param nelectron_total ...
441 : !> \param nelectron_spin ...
442 : !> \param efield ...
443 : !> \param neighbor_list_id ...
444 : !> \param linres_control ...
445 : !> \param xas_env ...
446 : !> \param virial ...
447 : !> \param cp_ddapc_env ...
448 : !> \param cp_ddapc_ewald ...
449 : !> \param outer_scf_history ...
450 : !> \param outer_scf_ihistory ...
451 : !> \param x_data ...
452 : !> \param et_coupling ...
453 : !> \param dftb_potential ...
454 : !> \param results ...
455 : !> \param se_taper ...
456 : !> \param se_store_int_env ...
457 : !> \param se_nddo_mpole ...
458 : !> \param se_nonbond_env ...
459 : !> \param admm_env ...
460 : !> \param lri_env ...
461 : !> \param lri_density ...
462 : !> \param exstate_env ...
463 : !> \param ec_env ...
464 : !> \param harris_env ...
465 : !> \param dispersion_env ...
466 : !> \param gcp_env ...
467 : !> \param vee ...
468 : !> \param rho_external ...
469 : !> \param external_vxc ...
470 : !> \param mask ...
471 : !> \param mp2_env ...
472 : !> \param bs_env ...
473 : !> \param kg_env ...
474 : !> \param WannierCentres ...
475 : !> \param atprop ...
476 : !> \param ls_scf_env ...
477 : !> \param do_transport ...
478 : !> \param transport_env ...
479 : !> \param v_hartree_rspace ...
480 : !> \param s_mstruct_changed ...
481 : !> \param rho_changed ...
482 : !> \param potential_changed ...
483 : !> \param forces_up_to_date ...
484 : !> \param mscfg_env ...
485 : !> \param almo_scf_env ...
486 : !> \param gradient_history ...
487 : !> \param variable_history ...
488 : !> \param embed_pot ...
489 : !> \param spin_embed_pot ...
490 : !> \param polar_env ...
491 : !> \param mos_last_converged ... [SGh]
492 : !> \param eeq ...
493 : !> \param rhs ...
494 : !> \param do_rixs ...
495 : !> \param tb_tblite ...
496 : !> \date 23.01.2002
497 : !> \author MK
498 : !> \version 1.0
499 : ! **************************************************************************************************
500 9653828 : SUBROUTINE get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, &
501 : dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, &
502 : sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, &
503 : sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, &
504 : sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, &
505 : matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, &
506 : matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, &
507 : matrix_w_kp, matrix_s_RI_aux_kp, matrix_s, matrix_s_RI_aux, matrix_w, &
508 : matrix_p_mp2, matrix_p_mp2_admm, rho, &
509 : rho_xc, pw_env, ewald_env, ewald_pw, active_space, &
510 : mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, &
511 : vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, &
512 : local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, &
513 : molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, &
514 : task_list, task_list_soft, &
515 : rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, &
516 : rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, &
517 : do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, &
518 : mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, &
519 : neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, &
520 : outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, &
521 : se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, &
522 : lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, &
523 : rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, &
524 : WannierCentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, &
525 : s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, &
526 : gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, &
527 : eeq, rhs, do_rixs, tb_tblite)
528 :
529 : TYPE(qs_environment_type), INTENT(IN) :: qs_env
530 : TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
531 : POINTER :: atomic_kind_set
532 : TYPE(qs_kind_type), DIMENSION(:), OPTIONAL, &
533 : POINTER :: qs_kind_set
534 : TYPE(cell_type), OPTIONAL, POINTER :: cell, super_cell, cell_ref
535 : LOGICAL, OPTIONAL :: use_ref_cell
536 : TYPE(kpoint_type), OPTIONAL, POINTER :: kpoints
537 : TYPE(dft_control_type), OPTIONAL, POINTER :: dft_control
538 : TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos
539 : TYPE(neighbor_list_set_p_type), DIMENSION(:), &
540 : OPTIONAL, POINTER :: sab_orb, sab_all
541 : LOGICAL, OPTIONAL :: qmmm, qmmm_periodic, mimic
542 : TYPE(neighbor_list_set_p_type), DIMENSION(:), OPTIONAL, POINTER :: sac_ae, sac_ppl, sac_lri, &
543 : sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, &
544 : sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo
545 : TYPE(particle_type), DIMENSION(:), OPTIONAL, &
546 : POINTER :: particle_set
547 : TYPE(qs_energy_type), OPTIONAL, POINTER :: energy
548 : TYPE(qs_force_type), DIMENSION(:), OPTIONAL, &
549 : POINTER :: force
550 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
551 : POINTER :: matrix_h, matrix_h_im, matrix_ks, &
552 : matrix_ks_im, matrix_vxc
553 : LOGICAL, OPTIONAL :: run_rtp
554 : TYPE(rt_prop_type), OPTIONAL, POINTER :: rtp
555 : TYPE(dbcsr_p_type), DIMENSION(:, :), OPTIONAL, POINTER :: matrix_h_kp, matrix_h_im_kp, &
556 : matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, &
557 : matrix_s_RI_aux_kp
558 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
559 : POINTER :: matrix_s, matrix_s_RI_aux, matrix_w, &
560 : matrix_p_mp2, matrix_p_mp2_admm
561 : TYPE(qs_rho_type), OPTIONAL, POINTER :: rho, rho_xc
562 : TYPE(pw_env_type), OPTIONAL, POINTER :: pw_env
563 : TYPE(ewald_environment_type), OPTIONAL, POINTER :: ewald_env
564 : TYPE(ewald_pw_type), OPTIONAL, POINTER :: ewald_pw
565 : TYPE(active_space_type), OPTIONAL, POINTER :: active_space
566 : TYPE(qs_matrix_pools_type), OPTIONAL, POINTER :: mpools
567 : TYPE(section_vals_type), OPTIONAL, POINTER :: input
568 : TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
569 : TYPE(cp_blacs_env_type), OPTIONAL, POINTER :: blacs_env
570 : TYPE(scf_control_type), OPTIONAL, POINTER :: scf_control
571 : TYPE(rel_control_type), OPTIONAL, POINTER :: rel_control
572 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
573 : POINTER :: kinetic
574 : TYPE(qs_charges_type), OPTIONAL, POINTER :: qs_charges
575 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: vppl
576 : TYPE(pw_c1d_gs_type), OPTIONAL, POINTER :: rho_core
577 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: rho_nlcc
578 : TYPE(pw_c1d_gs_type), OPTIONAL, POINTER :: rho_nlcc_g
579 : TYPE(qs_ks_env_type), OPTIONAL, POINTER :: ks_env
580 : TYPE(qs_ks_qmmm_env_type), OPTIONAL, POINTER :: ks_qmmm_env
581 : TYPE(qs_wf_history_type), OPTIONAL, POINTER :: wf_history
582 : TYPE(qs_scf_env_type), OPTIONAL, POINTER :: scf_env
583 : TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles, local_molecules
584 : TYPE(distribution_2d_type), OPTIONAL, POINTER :: distribution_2d
585 : TYPE(dbcsr_distribution_type), OPTIONAL, POINTER :: dbcsr_dist
586 : TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
587 : POINTER :: molecule_kind_set
588 : TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
589 : POINTER :: molecule_set
590 : TYPE(qs_subsys_type), OPTIONAL, POINTER :: subsys
591 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: cp_subsys
592 : TYPE(oce_matrix_type), OPTIONAL, POINTER :: oce
593 : TYPE(local_rho_type), OPTIONAL, POINTER :: local_rho_set
594 : TYPE(rho_atom_type), DIMENSION(:), OPTIONAL, &
595 : POINTER :: rho_atom_set
596 : TYPE(task_list_type), OPTIONAL, POINTER :: task_list, task_list_soft
597 : TYPE(rho0_atom_type), DIMENSION(:), OPTIONAL, &
598 : POINTER :: rho0_atom_set
599 : TYPE(rho0_mpole_type), OPTIONAL, POINTER :: rho0_mpole
600 : TYPE(rhoz_type), DIMENSION(:), OPTIONAL, POINTER :: rhoz_set
601 : TYPE(rhoz_cneo_type), DIMENSION(:), OPTIONAL, &
602 : POINTER :: rhoz_cneo_set
603 : TYPE(ecoul_1center_type), DIMENSION(:), OPTIONAL, &
604 : POINTER :: ecoul_1c
605 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: rho0_s_rs
606 : TYPE(pw_c1d_gs_type), OPTIONAL, POINTER :: rho0_s_gs
607 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: rhoz_cneo_s_rs
608 : TYPE(pw_c1d_gs_type), OPTIONAL, POINTER :: rhoz_cneo_s_gs
609 : LOGICAL, OPTIONAL :: do_kpoints, has_unit_metric, &
610 : requires_mo_derivs
611 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
612 : POINTER :: mo_derivs
613 : TYPE(cp_fm_type), DIMENSION(:), OPTIONAL, POINTER :: mo_loc_history
614 : INTEGER, OPTIONAL :: nkind, natom, nelectron_total
615 : INTEGER, DIMENSION(2), OPTIONAL :: nelectron_spin
616 : TYPE(efield_berry_type), OPTIONAL, POINTER :: efield
617 : INTEGER, OPTIONAL :: neighbor_list_id
618 : TYPE(linres_control_type), OPTIONAL, POINTER :: linres_control
619 : TYPE(xas_environment_type), OPTIONAL, POINTER :: xas_env
620 : TYPE(virial_type), OPTIONAL, POINTER :: virial
621 : TYPE(cp_ddapc_type), OPTIONAL, POINTER :: cp_ddapc_env
622 : TYPE(cp_ddapc_ewald_type), OPTIONAL, POINTER :: cp_ddapc_ewald
623 : REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER :: outer_scf_history
624 : INTEGER, INTENT(out), OPTIONAL :: outer_scf_ihistory
625 : TYPE(hfx_type), DIMENSION(:, :), OPTIONAL, POINTER :: x_data
626 : TYPE(et_coupling_type), OPTIONAL, POINTER :: et_coupling
627 : TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
628 : OPTIONAL, POINTER :: dftb_potential
629 : TYPE(cp_result_type), OPTIONAL, POINTER :: results
630 : TYPE(se_taper_type), OPTIONAL, POINTER :: se_taper
631 : TYPE(semi_empirical_si_type), OPTIONAL, POINTER :: se_store_int_env
632 : TYPE(nddo_mpole_type), OPTIONAL, POINTER :: se_nddo_mpole
633 : TYPE(fist_nonbond_env_type), OPTIONAL, POINTER :: se_nonbond_env
634 : TYPE(admm_type), OPTIONAL, POINTER :: admm_env
635 : TYPE(lri_environment_type), OPTIONAL, POINTER :: lri_env
636 : TYPE(lri_density_type), OPTIONAL, POINTER :: lri_density
637 : TYPE(excited_energy_type), OPTIONAL, POINTER :: exstate_env
638 : TYPE(energy_correction_type), OPTIONAL, POINTER :: ec_env
639 : TYPE(harris_type), OPTIONAL, POINTER :: harris_env
640 : TYPE(qs_dispersion_type), OPTIONAL, POINTER :: dispersion_env
641 : TYPE(qs_gcp_type), OPTIONAL, POINTER :: gcp_env
642 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: vee
643 : TYPE(qs_rho_type), OPTIONAL, POINTER :: rho_external
644 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: external_vxc, mask
645 : TYPE(mp2_type), OPTIONAL, POINTER :: mp2_env
646 : TYPE(post_scf_bandstructure_type), OPTIONAL, &
647 : POINTER :: bs_env
648 : TYPE(kg_environment_type), OPTIONAL, POINTER :: kg_env
649 : TYPE(wannier_centres_type), DIMENSION(:), &
650 : OPTIONAL, POINTER :: WannierCentres
651 : TYPE(atprop_type), OPTIONAL, POINTER :: atprop
652 : TYPE(ls_scf_env_type), OPTIONAL, POINTER :: ls_scf_env
653 : LOGICAL, OPTIONAL :: do_transport
654 : TYPE(transport_env_type), OPTIONAL, POINTER :: transport_env
655 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: v_hartree_rspace
656 : LOGICAL, OPTIONAL :: s_mstruct_changed, rho_changed, &
657 : potential_changed, forces_up_to_date
658 : TYPE(molecular_scf_guess_env_type), OPTIONAL, &
659 : POINTER :: mscfg_env
660 : TYPE(almo_scf_env_type), OPTIONAL, POINTER :: almo_scf_env
661 : REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER :: gradient_history, variable_history
662 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: embed_pot, spin_embed_pot
663 : TYPE(polar_env_type), OPTIONAL, POINTER :: polar_env
664 : TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos_last_converged
665 : REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER :: eeq, rhs
666 : LOGICAL, OPTIONAL :: do_rixs
667 : TYPE(tblite_type), OPTIONAL, POINTER :: tb_tblite
668 :
669 : TYPE(rho0_mpole_type), POINTER :: rho0_m
670 :
671 9653828 : NULLIFY (rho0_m)
672 9653828 : CPASSERT(ASSOCIATED(qs_env%ks_env))
673 :
674 9653828 : IF (PRESENT(outer_scf_history)) outer_scf_history => qs_env%outer_scf_history
675 9653828 : IF (PRESENT(outer_scf_ihistory)) outer_scf_ihistory = qs_env%outer_scf_ihistory
676 9653828 : IF (PRESENT(gradient_history)) gradient_history => qs_env%gradient_history
677 9653828 : IF (PRESENT(variable_history)) variable_history => qs_env%variable_history
678 9653828 : IF (PRESENT(mp2_env)) mp2_env => qs_env%mp2_env
679 9653828 : IF (PRESENT(bs_env)) bs_env => qs_env%bs_env
680 9653828 : IF (PRESENT(kg_env)) kg_env => qs_env%kg_env
681 9653828 : IF (PRESENT(super_cell)) super_cell => qs_env%super_cell
682 9653828 : IF (PRESENT(qmmm)) qmmm = qs_env%qmmm
683 9653828 : IF (PRESENT(qmmm_periodic)) qmmm_periodic = qs_env%qmmm_periodic
684 9653828 : IF (PRESENT(mimic)) mimic = qs_env%mimic
685 9653828 : IF (PRESENT(mos)) mos => qs_env%mos
686 9653828 : IF (PRESENT(mos_last_converged)) mos_last_converged => qs_env%mos_last_converged
687 9653828 : IF (PRESENT(ewald_env)) ewald_env => qs_env%ewald_env
688 9653828 : IF (PRESENT(ewald_pw)) ewald_pw => qs_env%ewald_pw
689 9653828 : IF (PRESENT(mpools)) mpools => qs_env%mpools
690 9653828 : IF (PRESENT(scf_control)) scf_control => qs_env%scf_control
691 9653828 : IF (PRESENT(rel_control)) rel_control => qs_env%rel_control
692 : ! ZMP pointing vectors
693 9653828 : IF (PRESENT(rho_external)) rho_external => qs_env%rho_external
694 9653828 : IF (PRESENT(external_vxc)) external_vxc => qs_env%external_vxc
695 9653828 : IF (PRESENT(mask)) mask => qs_env%mask
696 9653828 : IF (PRESENT(qs_charges)) qs_charges => qs_env%qs_charges
697 9653828 : IF (PRESENT(ks_env)) ks_env => qs_env%ks_env
698 9653828 : IF (PRESENT(ks_qmmm_env)) ks_qmmm_env => qs_env%ks_qmmm_env
699 9653828 : IF (PRESENT(wf_history)) wf_history => qs_env%wf_history
700 9653828 : IF (PRESENT(scf_env)) scf_env => qs_env%scf_env
701 9653828 : IF (PRESENT(oce)) oce => qs_env%oce
702 9653828 : IF (PRESENT(requires_mo_derivs)) requires_mo_derivs = qs_env%requires_mo_derivs
703 9653828 : IF (PRESENT(has_unit_metric)) has_unit_metric = qs_env%has_unit_metric
704 9653828 : IF (PRESENT(mo_derivs)) mo_derivs => qs_env%mo_derivs
705 9653828 : IF (PRESENT(mo_loc_history)) mo_loc_history => qs_env%mo_loc_history
706 9653828 : IF (PRESENT(linres_control)) linres_control => qs_env%linres_control
707 9653828 : IF (PRESENT(se_taper)) se_taper => qs_env%se_taper
708 9653828 : IF (PRESENT(se_store_int_env)) se_store_int_env => qs_env%se_store_int_env
709 9653828 : IF (PRESENT(se_nddo_mpole)) se_nddo_mpole => qs_env%se_nddo_mpole
710 9653828 : IF (PRESENT(se_nonbond_env)) se_nonbond_env => qs_env%se_nonbond_env
711 9653828 : IF (PRESENT(lri_env)) lri_env => qs_env%lri_env
712 9653828 : IF (PRESENT(lri_density)) lri_density => qs_env%lri_density
713 9653828 : IF (PRESENT(harris_env)) harris_env => qs_env%harris_env
714 9653828 : IF (PRESENT(ec_env)) ec_env => qs_env%ec_env
715 9653828 : IF (PRESENT(exstate_env)) exstate_env => qs_env%exstate_env
716 9653828 : IF (PRESENT(dispersion_env)) dispersion_env => qs_env%dispersion_env
717 9653828 : IF (PRESENT(gcp_env)) gcp_env => qs_env%gcp_env
718 9653828 : IF (PRESENT(run_rtp)) run_rtp = qs_env%run_rtp
719 9653828 : IF (PRESENT(rtp)) rtp => qs_env%rtp
720 9653828 : IF (PRESENT(ls_scf_env)) ls_scf_env => qs_env%ls_scf_env
721 9653828 : IF (PRESENT(almo_scf_env)) almo_scf_env => qs_env%almo_scf_env
722 9653828 : IF (PRESENT(do_transport)) do_transport = qs_env%do_transport
723 9653828 : IF (PRESENT(transport_env)) transport_env => qs_env%transport_env
724 9653828 : IF (PRESENT(mscfg_env)) mscfg_env => qs_env%molecular_scf_guess_env
725 9653828 : IF (PRESENT(active_space)) active_space => qs_env%active_space
726 9653828 : IF (PRESENT(admm_env)) admm_env => qs_env%admm_env
727 9653828 : IF (PRESENT(do_rixs)) do_rixs = qs_env%do_rixs
728 :
729 : ! Embedding potential
730 9653828 : IF (PRESENT(embed_pot)) embed_pot => qs_env%embed_pot
731 9653828 : IF (PRESENT(spin_embed_pot)) spin_embed_pot => qs_env%spin_embed_pot
732 :
733 : ! Polarisability tensor
734 9653828 : IF (PRESENT(polar_env)) polar_env => qs_env%polar_env
735 :
736 : ! EEQ charges
737 9653828 : IF (PRESENT(eeq)) eeq => qs_env%eeq
738 :
739 : ! Resp charges
740 9653828 : IF (PRESENT(rhs)) rhs => qs_env%rhs
741 :
742 9653828 : IF (PRESENT(local_rho_set)) &
743 15516 : local_rho_set => qs_env%local_rho_set
744 9653828 : IF (PRESENT(rho_atom_set)) &
745 114986 : CALL get_local_rho(qs_env%local_rho_set, rho_atom_set=rho_atom_set)
746 9653828 : IF (PRESENT(rho0_atom_set)) &
747 26886 : CALL get_local_rho(qs_env%local_rho_set, rho0_atom_set=rho0_atom_set)
748 9653828 : IF (PRESENT(rho0_mpole)) &
749 47452 : CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_mpole)
750 9653828 : IF (PRESENT(rhoz_set)) &
751 14 : CALL get_local_rho(qs_env%local_rho_set, rhoz_set=rhoz_set)
752 9653828 : IF (PRESENT(rhoz_cneo_set)) &
753 60643 : CALL get_local_rho(qs_env%local_rho_set, rhoz_cneo_set=rhoz_cneo_set)
754 9653828 : IF (PRESENT(ecoul_1c)) &
755 14650 : CALL get_hartree_local(qs_env%hartree_local, ecoul_1c=ecoul_1c)
756 9653828 : IF (PRESENT(rho0_s_rs)) THEN
757 1488 : CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_m)
758 1488 : IF (ASSOCIATED(rho0_m)) THEN
759 1488 : rho0_s_rs => rho0_m%rho0_s_rs
760 : END IF
761 : END IF
762 9653828 : IF (PRESENT(rho0_s_gs)) THEN
763 20544 : CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_m)
764 20544 : IF (ASSOCIATED(rho0_m)) THEN
765 14998 : rho0_s_gs => rho0_m%rho0_s_gs
766 : END IF
767 : END IF
768 9653828 : IF (PRESENT(rhoz_cneo_s_rs)) THEN
769 1488 : CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_m)
770 1488 : IF (ASSOCIATED(rho0_m)) THEN
771 1488 : rhoz_cneo_s_rs => rho0_m%rhoz_cneo_s_rs
772 : END IF
773 : END IF
774 9653828 : IF (PRESENT(rhoz_cneo_s_gs)) THEN
775 20544 : CALL get_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_m)
776 20544 : IF (ASSOCIATED(rho0_m)) THEN
777 14998 : rhoz_cneo_s_gs => rho0_m%rhoz_cneo_s_gs
778 : END IF
779 : END IF
780 :
781 9653828 : IF (PRESENT(xas_env)) xas_env => qs_env%xas_env
782 9653828 : IF (PRESENT(input)) input => qs_env%input
783 9653828 : IF (PRESENT(cp_ddapc_env)) cp_ddapc_env => qs_env%cp_ddapc_env
784 9653828 : IF (PRESENT(cp_ddapc_ewald)) cp_ddapc_ewald => qs_env%cp_ddapc_ewald
785 9653828 : IF (PRESENT(x_data)) x_data => qs_env%x_data
786 9653828 : IF (PRESENT(et_coupling)) et_coupling => qs_env%et_coupling
787 9653828 : IF (PRESENT(dftb_potential)) dftb_potential => qs_env%dftb_potential
788 9653828 : IF (PRESENT(efield)) efield => qs_env%efield
789 9653828 : IF (PRESENT(WannierCentres)) WannierCentres => qs_env%WannierCentres
790 :
791 : CALL get_ks_env(qs_env%ks_env, &
792 : v_hartree_rspace=v_hartree_rspace, &
793 : s_mstruct_changed=s_mstruct_changed, &
794 : rho_changed=rho_changed, &
795 : potential_changed=potential_changed, &
796 : forces_up_to_date=forces_up_to_date, &
797 : matrix_h=matrix_h, &
798 : matrix_h_im=matrix_h_im, &
799 : matrix_ks=matrix_ks, &
800 : matrix_ks_im=matrix_ks_im, &
801 : matrix_vxc=matrix_vxc, &
802 : kinetic=kinetic, &
803 : matrix_s=matrix_s, &
804 : matrix_s_RI_aux=matrix_s_RI_aux, &
805 : matrix_ks_im_kp=matrix_ks_im_kp, &
806 : matrix_w=matrix_w, &
807 : matrix_p_mp2=matrix_p_mp2, &
808 : matrix_p_mp2_admm=matrix_p_mp2_admm, &
809 : matrix_h_kp=matrix_h_kp, &
810 : matrix_h_im_kp=matrix_h_im_kp, &
811 : matrix_ks_kp=matrix_ks_kp, &
812 : matrix_vxc_kp=matrix_vxc_kp, &
813 : kinetic_kp=kinetic_kp, &
814 : matrix_s_kp=matrix_s_kp, &
815 : matrix_w_kp=matrix_w_kp, &
816 : matrix_s_RI_aux_kp=matrix_s_RI_aux_kp, &
817 : rho=rho, &
818 : rho_xc=rho_xc, &
819 : rho_core=rho_core, &
820 : rho_nlcc=rho_nlcc, &
821 : rho_nlcc_g=rho_nlcc_g, &
822 : vppl=vppl, &
823 : vee=vee, &
824 : neighbor_list_id=neighbor_list_id, &
825 : sab_orb=sab_orb, &
826 : sab_all=sab_all, &
827 : sab_scp=sab_scp, &
828 : sab_vdw=sab_vdw, &
829 : sac_ae=sac_ae, &
830 : sac_ppl=sac_ppl, &
831 : sac_lri=sac_lri, &
832 : sap_ppnl=sap_ppnl, &
833 : sap_oce=sap_oce, &
834 : sab_se=sab_se, &
835 : sab_lrc=sab_lrc, &
836 : sab_tbe=sab_tbe, &
837 : sab_xtbe=sab_xtbe, &
838 : sab_core=sab_core, &
839 : sab_xb=sab_xb, &
840 : sab_xtb_pp=sab_xtb_pp, &
841 : sab_xtb_nonbond=sab_xtb_nonbond, &
842 : sab_almo=sab_almo, &
843 : sab_kp=sab_kp, &
844 : sab_kp_nosym=sab_kp_nosym, &
845 : sab_cneo=sab_cneo, &
846 : task_list=task_list, &
847 : task_list_soft=task_list_soft, &
848 : kpoints=kpoints, &
849 : do_kpoints=do_kpoints, &
850 : local_molecules=local_molecules, &
851 : local_particles=local_particles, &
852 : atprop=atprop, &
853 : virial=virial, &
854 : results=results, &
855 : cell=cell, &
856 : cell_ref=cell_ref, &
857 : use_ref_cell=use_ref_cell, &
858 : energy=energy, &
859 : force=force, &
860 : qs_kind_set=qs_kind_set, &
861 : subsys=subsys, &
862 : cp_subsys=cp_subsys, &
863 : atomic_kind_set=atomic_kind_set, &
864 : particle_set=particle_set, &
865 : molecule_kind_set=molecule_kind_set, &
866 : molecule_set=molecule_set, &
867 : natom=natom, &
868 : nkind=nkind, &
869 : dft_control=dft_control, &
870 : dbcsr_dist=dbcsr_dist, &
871 : distribution_2d=distribution_2d, &
872 : pw_env=pw_env, &
873 : para_env=para_env, &
874 : blacs_env=blacs_env, &
875 : nelectron_total=nelectron_total, &
876 9653828 : nelectron_spin=nelectron_spin)
877 :
878 9653828 : IF (PRESENT(tb_tblite)) tb_tblite => qs_env%tb_tblite
879 :
880 9653828 : END SUBROUTINE get_qs_env
881 :
882 : ! **************************************************************************************************
883 : !> \brief Initialise the QUICKSTEP environment.
884 : !> \param qs_env ...
885 : !> \param globenv ...
886 : !> \date 25.01.2002
887 : !> \author MK
888 : !> \version 1.0
889 : ! **************************************************************************************************
890 7452 : SUBROUTINE init_qs_env(qs_env, globenv)
891 :
892 : TYPE(qs_environment_type), INTENT(INOUT) :: qs_env
893 : TYPE(global_environment_type), OPTIONAL, POINTER :: globenv
894 :
895 7452 : NULLIFY (qs_env%ls_scf_env)
896 7452 : NULLIFY (qs_env%almo_scf_env)
897 7452 : NULLIFY (qs_env%transport_env)
898 7452 : NULLIFY (qs_env%image_matrix)
899 7452 : NULLIFY (qs_env%ipiv)
900 7452 : NULLIFY (qs_env%image_coeff)
901 7452 : NULLIFY (qs_env%super_cell)
902 7452 : NULLIFY (qs_env%mos)
903 7452 : NULLIFY (qs_env%mos_last_converged)
904 7452 : NULLIFY (qs_env%mpools)
905 7452 : NULLIFY (qs_env%ewald_env)
906 7452 : NULLIFY (qs_env%ewald_pw)
907 7452 : NULLIFY (qs_env%scf_control)
908 7452 : NULLIFY (qs_env%rel_control)
909 7452 : NULLIFY (qs_env%qs_charges)
910 : ! ZMP initializing arrays
911 7452 : NULLIFY (qs_env%rho_external)
912 7452 : NULLIFY (qs_env%external_vxc)
913 7452 : NULLIFY (qs_env%mask)
914 : ! Embedding potential
915 7452 : NULLIFY (qs_env%embed_pot)
916 7452 : NULLIFY (qs_env%spin_embed_pot)
917 :
918 : ! Polarisability tensor
919 7452 : NULLIFY (qs_env%polar_env)
920 :
921 7452 : NULLIFY (qs_env%ks_env)
922 7452 : NULLIFY (qs_env%ks_qmmm_env)
923 7452 : NULLIFY (qs_env%wf_history)
924 7452 : NULLIFY (qs_env%scf_env)
925 7452 : NULLIFY (qs_env%oce)
926 7452 : NULLIFY (qs_env%local_rho_set)
927 7452 : NULLIFY (qs_env%hartree_local)
928 7452 : NULLIFY (qs_env%input)
929 7452 : NULLIFY (qs_env%linres_control)
930 7452 : NULLIFY (qs_env%xas_env)
931 7452 : NULLIFY (qs_env%cp_ddapc_env)
932 7452 : NULLIFY (qs_env%cp_ddapc_ewald)
933 7452 : NULLIFY (qs_env%outer_scf_history)
934 7452 : NULLIFY (qs_env%gradient_history)
935 7452 : NULLIFY (qs_env%variable_history)
936 7452 : NULLIFY (qs_env%x_data)
937 7452 : NULLIFY (qs_env%et_coupling)
938 7452 : NULLIFY (qs_env%dftb_potential)
939 7452 : NULLIFY (qs_env%active_space)
940 :
941 7452 : NULLIFY (qs_env%se_taper)
942 7452 : NULLIFY (qs_env%se_store_int_env)
943 7452 : NULLIFY (qs_env%se_nddo_mpole)
944 7452 : NULLIFY (qs_env%se_nonbond_env)
945 7452 : NULLIFY (qs_env%admm_env)
946 7452 : NULLIFY (qs_env%efield)
947 7452 : NULLIFY (qs_env%lri_env)
948 7452 : NULLIFY (qs_env%harris_env)
949 7452 : NULLIFY (qs_env%ec_env)
950 7452 : NULLIFY (qs_env%exstate_env)
951 7452 : NULLIFY (qs_env%lri_density)
952 7452 : NULLIFY (qs_env%gcp_env)
953 7452 : NULLIFY (qs_env%rtp)
954 7452 : NULLIFY (qs_env%mp2_env)
955 7452 : NULLIFY (qs_env%bs_env)
956 7452 : NULLIFY (qs_env%kg_env)
957 7452 : NULLIFY (qs_env%WannierCentres)
958 :
959 7452 : qs_env%outer_scf_ihistory = 0
960 7452 : qs_env%broyden_adaptive_sigma = -1.0_dp
961 :
962 7452 : CALL local_rho_set_create(qs_env%local_rho_set)
963 7452 : CALL hartree_local_create(qs_env%hartree_local)
964 7452 : qs_env%run_rtp = .FALSE.
965 7452 : qs_env%linres_run = .FALSE.
966 7452 : qs_env%single_point_run = .FALSE.
967 7452 : qs_env%qmmm = .FALSE.
968 7452 : qs_env%qmmm_periodic = .FALSE.
969 7452 : qs_env%mimic = .FALSE.
970 7452 : qs_env%requires_mo_derivs = .FALSE.
971 7452 : qs_env%requires_matrix_vxc = .FALSE.
972 7452 : qs_env%has_unit_metric = .FALSE.
973 7452 : qs_env%calc_image_preconditioner = .TRUE.
974 7452 : qs_env%do_transport = .FALSE.
975 7452 : qs_env%given_embed_pot = .FALSE.
976 7452 : qs_env%do_rixs = .FALSE.
977 7452 : IF (PRESENT(globenv)) THEN
978 7446 : qs_env%target_time = globenv%cp2k_target_time
979 7446 : qs_env%start_time = globenv%cp2k_start_time
980 : qs_env%single_point_run = (globenv%run_type_id == energy_run .OR. &
981 7446 : globenv%run_type_id == energy_force_run)
982 : ELSE
983 6 : qs_env%target_time = 0.0_dp
984 6 : qs_env%start_time = 0.0_dp
985 : END IF
986 :
987 7452 : qs_env%sim_time = 0._dp
988 7452 : qs_env%sim_step = 0
989 :
990 7452 : qs_env%total_zeff_corr = 0.0_dp
991 7452 : qs_env%surface_dipole_moment = 0.0_dp
992 7452 : qs_env%surface_dipole_switch_off = .FALSE.
993 :
994 : ! Zero all variables containing results
995 7452 : NULLIFY (qs_env%mo_derivs)
996 7452 : NULLIFY (qs_env%mo_loc_history)
997 :
998 7452 : IF (.NOT. ASSOCIATED(qs_env%molecular_scf_guess_env)) ALLOCATE (qs_env%molecular_scf_guess_env)
999 :
1000 7452 : NULLIFY (qs_env%tb_tblite)
1001 :
1002 7452 : END SUBROUTINE init_qs_env
1003 :
1004 : ! **************************************************************************************************
1005 : !> \brief Set the QUICKSTEP environment.
1006 : !> \param qs_env ...
1007 : !> \param super_cell ...
1008 : !> \param mos ...
1009 : !> \param qmmm ...
1010 : !> \param qmmm_periodic ...
1011 : !> \param mimic ...
1012 : !> \param ewald_env ...
1013 : !> \param ewald_pw ...
1014 : !> \param mpools ...
1015 : !> \param rho_external ...
1016 : !> \param external_vxc ...
1017 : !> \param mask ...
1018 : !> \param scf_control ...
1019 : !> \param rel_control ...
1020 : !> \param qs_charges ...
1021 : !> \param ks_env ...
1022 : !> \param ks_qmmm_env ...
1023 : !> \param wf_history ...
1024 : !> \param scf_env ...
1025 : !> \param active_space ...
1026 : !> \param input ...
1027 : !> \param oce ...
1028 : !> \param rho_atom_set ...
1029 : !> \param rho0_atom_set ...
1030 : !> \param rho0_mpole ...
1031 : !> \param run_rtp ...
1032 : !> \param rtp ...
1033 : !> \param rhoz_set ...
1034 : !> \param rhoz_tot ...
1035 : !> \param ecoul_1c ...
1036 : !> \param has_unit_metric ...
1037 : !> \param requires_mo_derivs ...
1038 : !> \param mo_derivs ...
1039 : !> \param mo_loc_history ...
1040 : !> \param efield ...
1041 : !> \param rhoz_cneo_set ...
1042 : !> \param linres_control ...
1043 : !> \param xas_env ...
1044 : !> \param cp_ddapc_env ...
1045 : !> \param cp_ddapc_ewald ...
1046 : !> \param outer_scf_history ...
1047 : !> \param outer_scf_ihistory ...
1048 : !> \param x_data ...
1049 : !> \param et_coupling ...
1050 : !> \param dftb_potential ...
1051 : !> \param se_taper ...
1052 : !> \param se_store_int_env ...
1053 : !> \param se_nddo_mpole ...
1054 : !> \param se_nonbond_env ...
1055 : !> \param admm_env ...
1056 : !> \param ls_scf_env ...
1057 : !> \param do_transport ...
1058 : !> \param transport_env ...
1059 : !> \param lri_env ...
1060 : !> \param lri_density ...
1061 : !> \param exstate_env ...
1062 : !> \param ec_env ...
1063 : !> \param dispersion_env ...
1064 : !> \param harris_env ...
1065 : !> \param gcp_env ...
1066 : !> \param mp2_env ...
1067 : !> \param bs_env ...
1068 : !> \param kg_env ...
1069 : !> \param force ...
1070 : !> \param kpoints ...
1071 : !> \param WannierCentres ...
1072 : !> \param almo_scf_env ...
1073 : !> \param gradient_history ...
1074 : !> \param variable_history ...
1075 : !> \param embed_pot ...
1076 : !> \param spin_embed_pot ...
1077 : !> \param polar_env ...
1078 : !> \param mos_last_converged ... [SGh]
1079 : !> \param eeq ...
1080 : !> \param rhs ...
1081 : !> \param do_rixs ...
1082 : !> \param tb_tblite ...
1083 : !> \date 23.01.2002
1084 : !> \author MK
1085 : !> \version 1.0
1086 : ! **************************************************************************************************
1087 154922 : SUBROUTINE set_qs_env(qs_env, super_cell, &
1088 : mos, qmmm, qmmm_periodic, mimic, &
1089 : ewald_env, ewald_pw, mpools, &
1090 : rho_external, external_vxc, mask, &
1091 : scf_control, rel_control, qs_charges, ks_env, &
1092 : ks_qmmm_env, wf_history, scf_env, active_space, &
1093 : input, oce, rho_atom_set, rho0_atom_set, rho0_mpole, run_rtp, rtp, &
1094 : rhoz_set, rhoz_tot, ecoul_1c, has_unit_metric, requires_mo_derivs, mo_derivs, &
1095 : mo_loc_history, efield, rhoz_cneo_set, &
1096 : linres_control, xas_env, cp_ddapc_env, cp_ddapc_ewald, &
1097 : outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, &
1098 : se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, ls_scf_env, &
1099 : do_transport, transport_env, lri_env, lri_density, exstate_env, ec_env, dispersion_env, &
1100 : harris_env, gcp_env, mp2_env, bs_env, kg_env, force, &
1101 : kpoints, WannierCentres, almo_scf_env, gradient_history, variable_history, embed_pot, &
1102 : spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
1103 :
1104 : TYPE(qs_environment_type), INTENT(INOUT) :: qs_env
1105 : TYPE(cell_type), OPTIONAL, POINTER :: super_cell
1106 : TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos
1107 : LOGICAL, OPTIONAL :: qmmm, qmmm_periodic, mimic
1108 : TYPE(ewald_environment_type), OPTIONAL, POINTER :: ewald_env
1109 : TYPE(ewald_pw_type), OPTIONAL, POINTER :: ewald_pw
1110 : TYPE(qs_matrix_pools_type), OPTIONAL, POINTER :: mpools
1111 : TYPE(qs_rho_type), OPTIONAL, POINTER :: rho_external
1112 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: external_vxc, mask
1113 : TYPE(scf_control_type), OPTIONAL, POINTER :: scf_control
1114 : TYPE(rel_control_type), OPTIONAL, POINTER :: rel_control
1115 : TYPE(qs_charges_type), OPTIONAL, POINTER :: qs_charges
1116 : TYPE(qs_ks_env_type), OPTIONAL, POINTER :: ks_env
1117 : TYPE(qs_ks_qmmm_env_type), OPTIONAL, POINTER :: ks_qmmm_env
1118 : TYPE(qs_wf_history_type), OPTIONAL, POINTER :: wf_history
1119 : TYPE(qs_scf_env_type), OPTIONAL, POINTER :: scf_env
1120 : TYPE(active_space_type), OPTIONAL, POINTER :: active_space
1121 : TYPE(section_vals_type), OPTIONAL, POINTER :: input
1122 : TYPE(oce_matrix_type), OPTIONAL, POINTER :: oce
1123 : TYPE(rho_atom_type), DIMENSION(:), OPTIONAL, &
1124 : POINTER :: rho_atom_set
1125 : TYPE(rho0_atom_type), DIMENSION(:), OPTIONAL, &
1126 : POINTER :: rho0_atom_set
1127 : TYPE(rho0_mpole_type), OPTIONAL, POINTER :: rho0_mpole
1128 : LOGICAL, OPTIONAL :: run_rtp
1129 : TYPE(rt_prop_type), OPTIONAL, POINTER :: rtp
1130 : TYPE(rhoz_type), DIMENSION(:), OPTIONAL, POINTER :: rhoz_set
1131 : REAL(dp), OPTIONAL :: rhoz_tot
1132 : TYPE(ecoul_1center_type), DIMENSION(:), OPTIONAL, &
1133 : POINTER :: ecoul_1c
1134 : LOGICAL, OPTIONAL :: has_unit_metric, requires_mo_derivs
1135 : TYPE(dbcsr_p_type), DIMENSION(:), OPTIONAL, &
1136 : POINTER :: mo_derivs
1137 : TYPE(cp_fm_type), DIMENSION(:), OPTIONAL, POINTER :: mo_loc_history
1138 : TYPE(efield_berry_type), OPTIONAL, POINTER :: efield
1139 : TYPE(rhoz_cneo_type), DIMENSION(:), OPTIONAL, &
1140 : POINTER :: rhoz_cneo_set
1141 : TYPE(linres_control_type), OPTIONAL, POINTER :: linres_control
1142 : TYPE(xas_environment_type), OPTIONAL, POINTER :: xas_env
1143 : TYPE(cp_ddapc_type), OPTIONAL, POINTER :: cp_ddapc_env
1144 : TYPE(cp_ddapc_ewald_type), OPTIONAL, POINTER :: cp_ddapc_ewald
1145 : REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER :: outer_scf_history
1146 : INTEGER, INTENT(IN), OPTIONAL :: outer_scf_ihistory
1147 : TYPE(hfx_type), DIMENSION(:, :), OPTIONAL, POINTER :: x_data
1148 : TYPE(et_coupling_type), OPTIONAL, POINTER :: et_coupling
1149 : TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
1150 : OPTIONAL, POINTER :: dftb_potential
1151 : TYPE(se_taper_type), OPTIONAL, POINTER :: se_taper
1152 : TYPE(semi_empirical_si_type), OPTIONAL, POINTER :: se_store_int_env
1153 : TYPE(nddo_mpole_type), OPTIONAL, POINTER :: se_nddo_mpole
1154 : TYPE(fist_nonbond_env_type), OPTIONAL, POINTER :: se_nonbond_env
1155 : TYPE(admm_type), OPTIONAL, POINTER :: admm_env
1156 : TYPE(ls_scf_env_type), OPTIONAL, POINTER :: ls_scf_env
1157 : LOGICAL, OPTIONAL :: do_transport
1158 : TYPE(transport_env_type), OPTIONAL, POINTER :: transport_env
1159 : TYPE(lri_environment_type), OPTIONAL, POINTER :: lri_env
1160 : TYPE(lri_density_type), OPTIONAL, POINTER :: lri_density
1161 : TYPE(excited_energy_type), OPTIONAL, POINTER :: exstate_env
1162 : TYPE(energy_correction_type), OPTIONAL, POINTER :: ec_env
1163 : TYPE(qs_dispersion_type), OPTIONAL, POINTER :: dispersion_env
1164 : TYPE(harris_type), OPTIONAL, POINTER :: harris_env
1165 : TYPE(qs_gcp_type), OPTIONAL, POINTER :: gcp_env
1166 : TYPE(mp2_type), OPTIONAL, POINTER :: mp2_env
1167 : TYPE(post_scf_bandstructure_type), OPTIONAL, &
1168 : POINTER :: bs_env
1169 : TYPE(kg_environment_type), OPTIONAL, POINTER :: kg_env
1170 : TYPE(qs_force_type), DIMENSION(:), OPTIONAL, &
1171 : POINTER :: force
1172 : TYPE(kpoint_type), OPTIONAL, POINTER :: kpoints
1173 : TYPE(wannier_centres_type), DIMENSION(:), &
1174 : OPTIONAL, POINTER :: WannierCentres
1175 : TYPE(almo_scf_env_type), OPTIONAL, POINTER :: almo_scf_env
1176 : REAL(KIND=dp), DIMENSION(:, :), OPTIONAL, POINTER :: gradient_history, variable_history
1177 : TYPE(pw_r3d_rs_type), OPTIONAL, POINTER :: embed_pot, spin_embed_pot
1178 : TYPE(polar_env_type), OPTIONAL, POINTER :: polar_env
1179 : TYPE(mo_set_type), DIMENSION(:), OPTIONAL, POINTER :: mos_last_converged
1180 : REAL(KIND=dp), DIMENSION(:), OPTIONAL, POINTER :: eeq, rhs
1181 : LOGICAL, OPTIONAL :: do_rixs
1182 : TYPE(tblite_type), OPTIONAL, POINTER :: tb_tblite
1183 :
1184 : TYPE(qs_subsys_type), POINTER :: subsys
1185 :
1186 154922 : IF (PRESENT(mp2_env)) qs_env%mp2_env => mp2_env
1187 154922 : IF (PRESENT(bs_env)) qs_env%bs_env => bs_env
1188 154922 : IF (PRESENT(kg_env)) qs_env%kg_env => kg_env
1189 154922 : IF (PRESENT(super_cell)) THEN
1190 46 : CALL cell_retain(super_cell)
1191 46 : CALL cell_release(qs_env%super_cell)
1192 46 : qs_env%super_cell => super_cell
1193 : END IF
1194 : !
1195 154922 : IF (PRESENT(qmmm)) qs_env%qmmm = qmmm
1196 154922 : IF (PRESENT(qmmm_periodic)) qs_env%qmmm_periodic = qmmm_periodic
1197 154922 : IF (PRESENT(mimic)) qs_env%mimic = mimic
1198 154922 : IF (PRESENT(mos)) qs_env%mos => mos
1199 154922 : IF (PRESENT(mos_last_converged)) qs_env%mos_last_converged => mos_last_converged
1200 154922 : IF (PRESENT(ls_scf_env)) qs_env%ls_scf_env => ls_scf_env
1201 154922 : IF (PRESENT(almo_scf_env)) qs_env%almo_scf_env => almo_scf_env
1202 154922 : IF (PRESENT(do_transport)) qs_env%do_transport = do_transport
1203 154922 : IF (PRESENT(transport_env)) qs_env%transport_env => transport_env
1204 : ! if intels checking (-C) complains here, you have rediscovered a bug in the intel
1205 : ! compiler (present in at least 10.0.025). A testcase has been submitted to intel.
1206 154922 : IF (PRESENT(oce)) qs_env%oce => oce
1207 154922 : IF (PRESENT(outer_scf_history)) qs_env%outer_scf_history => outer_scf_history
1208 154922 : IF (PRESENT(gradient_history)) qs_env%gradient_history => gradient_history
1209 154922 : IF (PRESENT(variable_history)) qs_env%variable_history => variable_history
1210 154922 : IF (PRESENT(outer_scf_ihistory)) qs_env%outer_scf_ihistory = outer_scf_ihistory
1211 154922 : IF (PRESENT(requires_mo_derivs)) qs_env%requires_mo_derivs = requires_mo_derivs
1212 154922 : IF (PRESENT(has_unit_metric)) qs_env%has_unit_metric = has_unit_metric
1213 154922 : IF (PRESENT(mo_derivs)) qs_env%mo_derivs => mo_derivs
1214 154922 : IF (PRESENT(mo_loc_history)) qs_env%mo_loc_history => mo_loc_history
1215 154922 : IF (PRESENT(run_rtp)) qs_env%run_rtp = run_rtp
1216 154922 : IF (PRESENT(rtp)) qs_env%rtp => rtp
1217 154922 : IF (PRESENT(efield)) qs_env%efield => efield
1218 154922 : IF (PRESENT(active_space)) qs_env%active_space => active_space
1219 154922 : IF (PRESENT(do_rixs)) do_rixs = qs_env%do_rixs
1220 :
1221 154922 : IF (PRESENT(ewald_env)) THEN ! accept also null pointers?
1222 328 : IF (ASSOCIATED(qs_env%ewald_env)) THEN
1223 0 : IF (.NOT. ASSOCIATED(qs_env%ewald_env, ewald_env)) THEN
1224 0 : CALL ewald_env_release(qs_env%ewald_env)
1225 0 : DEALLOCATE (qs_env%ewald_env)
1226 : END IF
1227 : END IF
1228 328 : qs_env%ewald_env => ewald_env
1229 : END IF
1230 154922 : IF (PRESENT(ewald_pw)) THEN ! accept also null pointers?
1231 328 : IF (ASSOCIATED(qs_env%ewald_pw)) THEN
1232 0 : IF (.NOT. ASSOCIATED(ewald_pw, qs_env%ewald_pw)) THEN
1233 0 : CALL ewald_pw_release(qs_env%ewald_pw)
1234 0 : DEALLOCATE (qs_env%ewald_pw)
1235 : END IF
1236 : END IF
1237 328 : qs_env%ewald_pw => ewald_pw
1238 : END IF
1239 154922 : IF (PRESENT(scf_control)) THEN ! accept also null pointers?
1240 7452 : IF (ASSOCIATED(qs_env%scf_control)) THEN
1241 0 : IF (.NOT. ASSOCIATED(qs_env%scf_control, scf_control)) THEN
1242 0 : CALL scf_c_release(qs_env%scf_control)
1243 0 : DEALLOCATE (qs_env%scf_control)
1244 : END IF
1245 : END IF
1246 7452 : qs_env%scf_control => scf_control
1247 : END IF
1248 154922 : IF (PRESENT(rel_control)) THEN ! accept also null pointers?
1249 7452 : IF (ASSOCIATED(qs_env%rel_control)) THEN
1250 0 : IF (.NOT. ASSOCIATED(qs_env%rel_control, rel_control)) THEN
1251 0 : CALL rel_c_release(qs_env%rel_control)
1252 0 : DEALLOCATE (qs_env%rel_control)
1253 : END IF
1254 : END IF
1255 7452 : qs_env%rel_control => rel_control
1256 : END IF
1257 154922 : IF (PRESENT(linres_control)) THEN ! accept also null pointers?
1258 1688 : IF (ASSOCIATED(qs_env%linres_control)) THEN
1259 624 : IF (.NOT. ASSOCIATED(qs_env%linres_control, linres_control)) THEN
1260 624 : CALL linres_control_release(qs_env%linres_control)
1261 624 : DEALLOCATE (qs_env%linres_control)
1262 : END IF
1263 : END IF
1264 1688 : qs_env%linres_control => linres_control
1265 : END IF
1266 : ! ZMP associating variables
1267 154922 : IF (PRESENT(rho_external)) THEN
1268 0 : IF (ASSOCIATED(qs_env%rho_external)) THEN
1269 0 : IF (.NOT. ASSOCIATED(qs_env%rho_external, rho_external)) THEN
1270 0 : CALL qs_rho_release(qs_env%rho_external)
1271 0 : DEALLOCATE (qs_env%rho_external)
1272 : END IF
1273 : END IF
1274 0 : qs_env%rho_external => rho_external
1275 : END IF
1276 154922 : IF (PRESENT(external_vxc)) qs_env%external_vxc => external_vxc
1277 154922 : IF (PRESENT(mask)) qs_env%mask => mask
1278 : ! Embedding potential
1279 154922 : IF (PRESENT(embed_pot)) qs_env%embed_pot => embed_pot
1280 154922 : IF (PRESENT(spin_embed_pot)) qs_env%spin_embed_pot => spin_embed_pot
1281 :
1282 : ! Polarisability tensor
1283 154922 : IF (PRESENT(polar_env)) qs_env%polar_env => polar_env
1284 :
1285 154922 : IF (PRESENT(qs_charges)) THEN
1286 7452 : IF (ASSOCIATED(qs_env%qs_charges)) THEN
1287 0 : IF (.NOT. ASSOCIATED(qs_env%qs_charges, qs_charges)) THEN
1288 0 : CALL qs_charges_release(qs_env%qs_charges)
1289 0 : DEALLOCATE (qs_env%qs_charges)
1290 : END IF
1291 : END IF
1292 7452 : qs_env%qs_charges => qs_charges
1293 : END IF
1294 154922 : IF (PRESENT(ks_qmmm_env)) THEN
1295 378 : IF (ASSOCIATED(qs_env%ks_qmmm_env)) THEN
1296 0 : IF (.NOT. ASSOCIATED(qs_env%ks_qmmm_env, ks_qmmm_env)) THEN
1297 0 : CALL qs_ks_qmmm_release(qs_env%ks_qmmm_env)
1298 0 : DEALLOCATE (qs_env%ks_qmmm_env)
1299 : END IF
1300 : END IF
1301 378 : qs_env%ks_qmmm_env => ks_qmmm_env
1302 : END IF
1303 154922 : IF (PRESENT(ks_env)) THEN ! accept also null pointers?
1304 7452 : IF (ASSOCIATED(qs_env%ks_env)) THEN
1305 0 : IF (.NOT. ASSOCIATED(qs_env%ks_env, ks_env)) THEN
1306 0 : CALL qs_ks_release(qs_env%ks_env)
1307 0 : DEALLOCATE (qs_env%ks_env)
1308 : END IF
1309 : END IF
1310 7452 : qs_env%ks_env => ks_env
1311 : END IF
1312 154922 : IF (PRESENT(wf_history)) THEN ! accept also null pointers ?
1313 7824 : CALL wfi_retain(wf_history)
1314 7824 : CALL wfi_release(qs_env%wf_history)
1315 7824 : qs_env%wf_history => wf_history
1316 : END IF
1317 154922 : IF (PRESENT(scf_env)) THEN ! accept also null pointers ?
1318 6411 : IF (ASSOCIATED(qs_env%scf_env)) THEN
1319 50 : IF (.NOT. ASSOCIATED(qs_env%scf_env, scf_env)) THEN
1320 50 : CALL scf_env_release(qs_env%scf_env)
1321 50 : DEALLOCATE (qs_env%scf_env)
1322 : END IF
1323 : END IF
1324 6411 : qs_env%scf_env => scf_env
1325 : END IF
1326 154922 : IF (PRESENT(xas_env)) THEN ! accept also null pointers?
1327 42 : IF (ASSOCIATED(qs_env%xas_env)) THEN
1328 0 : IF (.NOT. ASSOCIATED(qs_env%xas_env, xas_env)) THEN
1329 0 : CALL xas_env_release(qs_env%xas_env)
1330 0 : DEALLOCATE (qs_env%xas_env)
1331 : END IF
1332 : END IF
1333 42 : qs_env%xas_env => xas_env
1334 : END IF
1335 154922 : IF (PRESENT(mpools)) THEN
1336 0 : CALL mpools_retain(mpools)
1337 0 : CALL mpools_release(qs_env%mpools)
1338 0 : qs_env%mpools => mpools
1339 : END IF
1340 154922 : IF (PRESENT(rho_atom_set)) THEN
1341 998 : CALL set_local_rho(qs_env%local_rho_set, rho_atom_set=rho_atom_set)
1342 : END IF
1343 154922 : IF (PRESENT(rho0_atom_set)) THEN
1344 0 : CALL set_local_rho(qs_env%local_rho_set, rho0_atom_set=rho0_atom_set)
1345 : END IF
1346 154922 : IF (PRESENT(rho0_mpole)) THEN
1347 0 : CALL set_local_rho(qs_env%local_rho_set, rho0_mpole=rho0_mpole)
1348 : END IF
1349 154922 : IF (PRESENT(rhoz_set)) THEN
1350 0 : CALL set_local_rho(qs_env%local_rho_set, rhoz_set=rhoz_set)
1351 : END IF
1352 154922 : IF (PRESENT(rhoz_cneo_set)) THEN
1353 0 : CALL set_local_rho(qs_env%local_rho_set, rhoz_cneo_set=rhoz_cneo_set)
1354 : END IF
1355 154922 : IF (PRESENT(rhoz_tot)) qs_env%local_rho_set%rhoz_tot = rhoz_tot
1356 154922 : IF (PRESENT(ecoul_1c)) THEN
1357 0 : CALL set_hartree_local(qs_env%hartree_local, ecoul_1c=ecoul_1c)
1358 : END IF
1359 154922 : IF (PRESENT(input)) THEN
1360 7452 : CALL section_vals_retain(input)
1361 7452 : CALL section_vals_release(qs_env%input)
1362 7452 : qs_env%input => input
1363 : END IF
1364 154922 : IF (PRESENT(cp_ddapc_env)) THEN
1365 0 : IF (ASSOCIATED(qs_env%cp_ddapc_env)) THEN
1366 0 : IF (.NOT. ASSOCIATED(qs_env%cp_ddapc_env, cp_ddapc_env)) THEN
1367 0 : CALL cp_ddapc_release(qs_env%cp_ddapc_env)
1368 0 : DEALLOCATE (qs_env%cp_ddapc_env)
1369 : END IF
1370 : END IF
1371 0 : qs_env%cp_ddapc_env => cp_ddapc_env
1372 : END IF
1373 154922 : IF (PRESENT(cp_ddapc_ewald)) THEN
1374 0 : qs_env%cp_ddapc_ewald => cp_ddapc_ewald
1375 : END IF
1376 154922 : IF (PRESENT(x_data)) qs_env%x_data => x_data
1377 154922 : IF (PRESENT(et_coupling)) qs_env%et_coupling => et_coupling
1378 154922 : IF (PRESENT(dftb_potential)) qs_env%dftb_potential => dftb_potential
1379 154922 : IF (PRESENT(se_taper)) THEN
1380 998 : CALL se_taper_release(qs_env%se_taper)
1381 998 : qs_env%se_taper => se_taper
1382 : END IF
1383 154922 : IF (PRESENT(se_store_int_env)) THEN
1384 998 : CALL semi_empirical_si_release(qs_env%se_store_int_env)
1385 998 : qs_env%se_store_int_env => se_store_int_env
1386 : END IF
1387 154922 : IF (PRESENT(se_nddo_mpole)) THEN
1388 32 : CALL nddo_mpole_release(qs_env%se_nddo_mpole)
1389 32 : qs_env%se_nddo_mpole => se_nddo_mpole
1390 : END IF
1391 154922 : IF (PRESENT(se_nonbond_env)) THEN
1392 32 : IF (ASSOCIATED(qs_env%se_nonbond_env)) THEN
1393 0 : IF (.NOT. ASSOCIATED(qs_env%se_nonbond_env, se_nonbond_env)) THEN
1394 0 : CALL fist_nonbond_env_release(qs_env%se_nonbond_env)
1395 0 : DEALLOCATE (qs_env%se_nonbond_env)
1396 : END IF
1397 : END IF
1398 32 : qs_env%se_nonbond_env => se_nonbond_env
1399 : END IF
1400 154922 : IF (PRESENT(admm_env)) qs_env%admm_env => admm_env
1401 154922 : IF (PRESENT(lri_env)) qs_env%lri_env => lri_env
1402 154922 : IF (PRESENT(lri_density)) qs_env%lri_density => lri_density
1403 154922 : IF (PRESENT(harris_env)) qs_env%harris_env => harris_env
1404 154922 : IF (PRESENT(ec_env)) qs_env%ec_env => ec_env
1405 154922 : IF (PRESENT(exstate_env)) qs_env%exstate_env => exstate_env
1406 154922 : IF (PRESENT(dispersion_env)) qs_env%dispersion_env => dispersion_env
1407 154922 : IF (PRESENT(gcp_env)) qs_env%gcp_env => gcp_env
1408 154922 : IF (PRESENT(WannierCentres)) qs_env%WannierCentres => WannierCentres
1409 154922 : IF (PRESENT(kpoints)) CALL set_ks_env(qs_env%ks_env, kpoints=kpoints)
1410 :
1411 : ! EEQ charges
1412 154922 : IF (PRESENT(eeq)) qs_env%eeq => eeq
1413 :
1414 : ! Resp charges
1415 154922 : IF (PRESENT(rhs)) qs_env%rhs => rhs
1416 :
1417 154922 : IF (PRESENT(force)) THEN
1418 2304 : CALL get_qs_env(qs_env, subsys=subsys)
1419 2304 : CALL qs_subsys_set(subsys, force=force)
1420 : END IF
1421 :
1422 154922 : IF (PRESENT(tb_tblite)) qs_env%tb_tblite => tb_tblite
1423 :
1424 154922 : END SUBROUTINE set_qs_env
1425 :
1426 : ! **************************************************************************************************
1427 : !> \brief allocates and intitializes a qs_env
1428 : !> \param qs_env the object to create
1429 : !> \param globenv ...
1430 : !> \par History
1431 : !> 12.2002 created [fawzi]
1432 : !> \author Fawzi Mohamed
1433 : ! **************************************************************************************************
1434 7452 : SUBROUTINE qs_env_create(qs_env, globenv)
1435 : TYPE(qs_environment_type), INTENT(OUT) :: qs_env
1436 : TYPE(global_environment_type), OPTIONAL, POINTER :: globenv
1437 :
1438 7452 : CALL init_qs_env(qs_env, globenv=globenv)
1439 7452 : END SUBROUTINE qs_env_create
1440 :
1441 : ! **************************************************************************************************
1442 : !> \brief releases the given qs_env (see doc/ReferenceCounting.html)
1443 : !> \param qs_env the object to release
1444 : !> \par History
1445 : !> 12.2002 created [fawzi]
1446 : !> 06.2018 polar_env added (MK)
1447 : !> \author Fawzi Mohamed
1448 : ! **************************************************************************************************
1449 7452 : SUBROUTINE qs_env_release(qs_env)
1450 : TYPE(qs_environment_type), INTENT(INOUT) :: qs_env
1451 :
1452 : INTEGER :: i
1453 :
1454 7452 : CALL cell_release(qs_env%super_cell)
1455 7452 : IF (ASSOCIATED(qs_env%mos)) THEN
1456 15843 : DO i = 1, SIZE(qs_env%mos)
1457 15843 : CALL deallocate_mo_set(qs_env%mos(i))
1458 : END DO
1459 7114 : DEALLOCATE (qs_env%mos)
1460 : END IF
1461 7452 : IF (ASSOCIATED(qs_env%mos_last_converged)) THEN
1462 4 : DO i = 1, SIZE(qs_env%mos_last_converged)
1463 4 : CALL deallocate_mo_set(qs_env%mos_last_converged(i))
1464 : END DO
1465 2 : DEALLOCATE (qs_env%mos_last_converged)
1466 : END IF
1467 :
1468 7452 : IF (ASSOCIATED(qs_env%mo_derivs)) THEN
1469 4609 : DO I = 1, SIZE(qs_env%mo_derivs)
1470 4609 : CALL dbcsr_release_p(qs_env%mo_derivs(I)%matrix)
1471 : END DO
1472 2007 : DEALLOCATE (qs_env%mo_derivs)
1473 : END IF
1474 :
1475 7452 : CALL cp_fm_release(qs_env%mo_loc_history)
1476 :
1477 7452 : IF (ASSOCIATED(qs_env%rtp)) THEN
1478 198 : CALL rt_prop_release(qs_env%rtp)
1479 198 : DEALLOCATE (qs_env%rtp)
1480 : END IF
1481 7452 : IF (ASSOCIATED(qs_env%outer_scf_history)) THEN
1482 1329 : DEALLOCATE (qs_env%outer_scf_history)
1483 1329 : qs_env%outer_scf_ihistory = 0
1484 : END IF
1485 7452 : IF (ASSOCIATED(qs_env%gradient_history)) &
1486 1329 : DEALLOCATE (qs_env%gradient_history)
1487 7452 : IF (ASSOCIATED(qs_env%variable_history)) &
1488 1329 : DEALLOCATE (qs_env%variable_history)
1489 7452 : IF (ASSOCIATED(qs_env%oce)) CALL deallocate_oce_set(qs_env%oce)
1490 7452 : IF (ASSOCIATED(qs_env%local_rho_set)) THEN
1491 7443 : CALL local_rho_set_release(qs_env%local_rho_set)
1492 : END IF
1493 7452 : IF (ASSOCIATED(qs_env%hartree_local)) THEN
1494 7443 : CALL hartree_local_release(qs_env%hartree_local)
1495 : END IF
1496 7452 : IF (ASSOCIATED(qs_env%scf_control)) THEN
1497 7443 : CALL scf_c_release(qs_env%scf_control)
1498 7443 : DEALLOCATE (qs_env%scf_control)
1499 : END IF
1500 7452 : IF (ASSOCIATED(qs_env%rel_control)) THEN
1501 7443 : CALL rel_c_release(qs_env%rel_control)
1502 7443 : DEALLOCATE (qs_env%rel_control)
1503 : END IF
1504 :
1505 7452 : IF (ASSOCIATED(qs_env%linres_control)) THEN
1506 1064 : CALL linres_control_release(qs_env%linres_control)
1507 1064 : DEALLOCATE (qs_env%linres_control)
1508 : END IF
1509 :
1510 7452 : IF (ASSOCIATED(qs_env%almo_scf_env)) THEN
1511 66 : CALL almo_scf_env_release(qs_env%almo_scf_env)
1512 : END IF
1513 :
1514 7452 : IF (ASSOCIATED(qs_env%ls_scf_env)) THEN
1515 336 : CALL ls_scf_release(qs_env%ls_scf_env)
1516 : END IF
1517 7452 : IF (ASSOCIATED(qs_env%molecular_scf_guess_env)) THEN
1518 7443 : CALL molecular_scf_guess_env_destroy(qs_env%molecular_scf_guess_env)
1519 7443 : DEALLOCATE (qs_env%molecular_scf_guess_env)
1520 : END IF
1521 :
1522 7452 : IF (ASSOCIATED(qs_env%transport_env)) THEN
1523 0 : CALL transport_env_release(qs_env%transport_env)
1524 : END IF
1525 :
1526 : !Only if do_xas_calculation
1527 7452 : IF (ASSOCIATED(qs_env%xas_env)) THEN
1528 0 : CALL xas_env_release(qs_env%xas_env)
1529 0 : DEALLOCATE (qs_env%xas_env)
1530 : END IF
1531 7452 : IF (ASSOCIATED(qs_env%ewald_env)) THEN
1532 328 : CALL ewald_env_release(qs_env%ewald_env)
1533 328 : DEALLOCATE (qs_env%ewald_env)
1534 : END IF
1535 7452 : IF (ASSOCIATED(qs_env%ewald_pw)) THEN
1536 328 : CALL ewald_pw_release(qs_env%ewald_pw)
1537 328 : DEALLOCATE (qs_env%ewald_pw)
1538 : END IF
1539 7452 : IF (ASSOCIATED(qs_env%image_matrix)) THEN
1540 10 : DEALLOCATE (qs_env%image_matrix)
1541 : END IF
1542 7452 : IF (ASSOCIATED(qs_env%ipiv)) THEN
1543 8 : DEALLOCATE (qs_env%ipiv)
1544 : END IF
1545 7452 : IF (ASSOCIATED(qs_env%image_coeff)) THEN
1546 10 : DEALLOCATE (qs_env%image_coeff)
1547 : END IF
1548 : ! ZMP
1549 7452 : IF (ASSOCIATED(qs_env%rho_external)) THEN
1550 0 : CALL qs_rho_release(qs_env%rho_external)
1551 0 : DEALLOCATE (qs_env%rho_external)
1552 : END IF
1553 7452 : IF (ASSOCIATED(qs_env%external_vxc)) THEN
1554 0 : CALL qs_env%external_vxc%release()
1555 0 : DEALLOCATE (qs_env%external_vxc)
1556 : END IF
1557 7452 : IF (ASSOCIATED(qs_env%mask)) THEN
1558 0 : CALL qs_env%mask%release()
1559 0 : DEALLOCATE (qs_env%mask)
1560 : END IF
1561 7452 : IF (ASSOCIATED(qs_env%active_space)) THEN
1562 66 : CALL release_active_space_type(qs_env%active_space)
1563 : END IF
1564 : ! Embedding potentials if provided as input
1565 7452 : IF (qs_env%given_embed_pot) THEN
1566 2 : CALL qs_env%embed_pot%release()
1567 2 : DEALLOCATE (qs_env%embed_pot)
1568 2 : IF (ASSOCIATED(qs_env%spin_embed_pot)) THEN
1569 2 : CALL qs_env%spin_embed_pot%release()
1570 2 : DEALLOCATE (qs_env%spin_embed_pot)
1571 : END IF
1572 : END IF
1573 :
1574 : ! Polarisability tensor
1575 7452 : CALL polar_env_release(qs_env%polar_env)
1576 :
1577 7452 : IF (ASSOCIATED(qs_env%qs_charges)) THEN
1578 7443 : CALL qs_charges_release(qs_env%qs_charges)
1579 7443 : DEALLOCATE (qs_env%qs_charges)
1580 : END IF
1581 7452 : IF (ASSOCIATED(qs_env%ks_env)) THEN
1582 7452 : CALL qs_ks_release(qs_env%ks_env)
1583 7452 : DEALLOCATE (qs_env%ks_env)
1584 : END IF
1585 7452 : IF (ASSOCIATED(qs_env%ks_qmmm_env)) THEN
1586 378 : CALL qs_ks_qmmm_release(qs_env%ks_qmmm_env)
1587 378 : DEALLOCATE (qs_env%ks_qmmm_env)
1588 : END IF
1589 7452 : CALL wfi_release(qs_env%wf_history)
1590 7452 : IF (ASSOCIATED(qs_env%scf_env)) THEN
1591 6361 : CALL scf_env_release(qs_env%scf_env)
1592 6361 : DEALLOCATE (qs_env%scf_env)
1593 : END IF
1594 7452 : CALL mpools_release(qs_env%mpools)
1595 7452 : CALL section_vals_release(qs_env%input)
1596 7452 : IF (ASSOCIATED(qs_env%cp_ddapc_env)) THEN
1597 120 : CALL cp_ddapc_release(qs_env%cp_ddapc_env)
1598 120 : DEALLOCATE (qs_env%cp_ddapc_env)
1599 : END IF
1600 7452 : CALL cp_ddapc_ewald_release(qs_env%cp_ddapc_ewald)
1601 7452 : CALL efield_berry_release(qs_env%efield)
1602 7452 : IF (ASSOCIATED(qs_env%x_data)) THEN
1603 1198 : CALL hfx_release(qs_env%x_data)
1604 : END IF
1605 7452 : IF (ASSOCIATED(qs_env%et_coupling)) THEN
1606 10 : CALL et_coupling_release(qs_env%et_coupling)
1607 : END IF
1608 7452 : IF (ASSOCIATED(qs_env%dftb_potential)) THEN
1609 222 : CALL qs_dftb_pairpot_release(qs_env%dftb_potential)
1610 : END IF
1611 7452 : IF (ASSOCIATED(qs_env%se_taper)) THEN
1612 998 : CALL se_taper_release(qs_env%se_taper)
1613 : END IF
1614 7452 : IF (ASSOCIATED(qs_env%se_store_int_env)) THEN
1615 998 : CALL semi_empirical_si_release(qs_env%se_store_int_env)
1616 : END IF
1617 7452 : IF (ASSOCIATED(qs_env%se_nddo_mpole)) THEN
1618 32 : CALL nddo_mpole_release(qs_env%se_nddo_mpole)
1619 : END IF
1620 7452 : IF (ASSOCIATED(qs_env%se_nonbond_env)) THEN
1621 32 : CALL fist_nonbond_env_release(qs_env%se_nonbond_env)
1622 32 : DEALLOCATE (qs_env%se_nonbond_env)
1623 : END IF
1624 7452 : IF (ASSOCIATED(qs_env%admm_env)) THEN
1625 464 : CALL admm_env_release(qs_env%admm_env)
1626 : END IF
1627 7452 : IF (ASSOCIATED(qs_env%lri_env)) THEN
1628 46 : CALL lri_env_release(qs_env%lri_env)
1629 46 : DEALLOCATE (qs_env%lri_env)
1630 : END IF
1631 7452 : IF (ASSOCIATED(qs_env%lri_density)) THEN
1632 46 : CALL lri_density_release(qs_env%lri_density)
1633 46 : DEALLOCATE (qs_env%lri_density)
1634 : END IF
1635 7452 : IF (ASSOCIATED(qs_env%harris_env)) THEN
1636 7443 : CALL harris_env_release(qs_env%harris_env)
1637 : END IF
1638 7452 : IF (ASSOCIATED(qs_env%ec_env)) THEN
1639 7443 : CALL ec_env_release(qs_env%ec_env)
1640 : END IF
1641 7452 : IF (ASSOCIATED(qs_env%exstate_env)) THEN
1642 7443 : CALL exstate_release(qs_env%exstate_env)
1643 : END IF
1644 7452 : IF (ASSOCIATED(qs_env%mp2_env)) THEN
1645 470 : CALL mp2_env_release(qs_env%mp2_env)
1646 6110 : DEALLOCATE (qs_env%mp2_env)
1647 : NULLIFY (qs_env%mp2_env)
1648 : END IF
1649 7452 : IF (ASSOCIATED(qs_env%bs_env)) THEN
1650 28 : CALL bs_env_release(qs_env%bs_env)
1651 : END IF
1652 7452 : IF (ASSOCIATED(qs_env%kg_env)) THEN
1653 66 : CALL kg_env_release(qs_env%kg_env)
1654 : END IF
1655 :
1656 : ! dispersion
1657 7452 : CALL qs_dispersion_release(qs_env%dispersion_env)
1658 : ! gCP
1659 7452 : IF (ASSOCIATED(qs_env%gcp_env)) THEN
1660 5279 : CALL qs_gcp_release(qs_env%gcp_env)
1661 : END IF
1662 :
1663 7452 : IF (ASSOCIATED(qs_env%WannierCentres)) THEN
1664 12 : DO i = 1, SIZE(qs_env%WannierCentres)
1665 6 : DEALLOCATE (qs_env%WannierCentres(i)%WannierHamDiag)
1666 12 : DEALLOCATE (qs_env%WannierCentres(i)%centres)
1667 : END DO
1668 6 : DEALLOCATE (qs_env%WannierCentres)
1669 : END IF
1670 : ! EEQ charges
1671 7452 : IF (ASSOCIATED(qs_env%eeq)) DEALLOCATE (qs_env%eeq)
1672 : ! Resp charges
1673 7452 : IF (ASSOCIATED(qs_env%rhs)) DEALLOCATE (qs_env%rhs)
1674 :
1675 : ! tblite
1676 7452 : IF (ASSOCIATED(qs_env%tb_tblite)) THEN
1677 0 : CALL deallocate_tblite_type(qs_env%tb_tblite)
1678 : END IF
1679 :
1680 7452 : END SUBROUTINE qs_env_release
1681 :
1682 : ! **************************************************************************************************
1683 : !> \brief releases part of the given qs_env in order to save memory
1684 : !> \param qs_env the object to release
1685 : !> \par History
1686 : !> 04.2022 created [JGH]
1687 : ! **************************************************************************************************
1688 9 : SUBROUTINE qs_env_part_release(qs_env)
1689 : TYPE(qs_environment_type), INTENT(INOUT) :: qs_env
1690 :
1691 : INTEGER :: i
1692 :
1693 9 : IF (ASSOCIATED(qs_env%mos_last_converged)) THEN
1694 0 : DO i = 1, SIZE(qs_env%mos_last_converged)
1695 0 : CALL deallocate_mo_set(qs_env%mos_last_converged(i))
1696 : END DO
1697 0 : DEALLOCATE (qs_env%mos_last_converged)
1698 : END IF
1699 :
1700 9 : IF (ASSOCIATED(qs_env%mo_derivs)) THEN
1701 0 : DO I = 1, SIZE(qs_env%mo_derivs)
1702 0 : CALL dbcsr_release_p(qs_env%mo_derivs(I)%matrix)
1703 : END DO
1704 0 : DEALLOCATE (qs_env%mo_derivs)
1705 : END IF
1706 :
1707 9 : CALL cp_fm_release(qs_env%mo_loc_history)
1708 :
1709 9 : IF (ASSOCIATED(qs_env%rtp)) THEN
1710 0 : CALL rt_prop_release(qs_env%rtp)
1711 0 : DEALLOCATE (qs_env%rtp)
1712 : END IF
1713 9 : IF (ASSOCIATED(qs_env%outer_scf_history)) THEN
1714 0 : DEALLOCATE (qs_env%outer_scf_history)
1715 0 : qs_env%outer_scf_ihistory = 0
1716 : END IF
1717 9 : IF (ASSOCIATED(qs_env%gradient_history)) &
1718 0 : DEALLOCATE (qs_env%gradient_history)
1719 9 : IF (ASSOCIATED(qs_env%variable_history)) &
1720 0 : DEALLOCATE (qs_env%variable_history)
1721 9 : IF (ASSOCIATED(qs_env%oce)) CALL deallocate_oce_set(qs_env%oce)
1722 9 : IF (ASSOCIATED(qs_env%local_rho_set)) THEN
1723 9 : CALL local_rho_set_release(qs_env%local_rho_set)
1724 : END IF
1725 9 : IF (ASSOCIATED(qs_env%hartree_local)) THEN
1726 9 : CALL hartree_local_release(qs_env%hartree_local)
1727 : END IF
1728 9 : IF (ASSOCIATED(qs_env%scf_control)) THEN
1729 9 : CALL scf_c_release(qs_env%scf_control)
1730 9 : DEALLOCATE (qs_env%scf_control)
1731 : END IF
1732 9 : IF (ASSOCIATED(qs_env%rel_control)) THEN
1733 9 : CALL rel_c_release(qs_env%rel_control)
1734 9 : DEALLOCATE (qs_env%rel_control)
1735 : END IF
1736 :
1737 9 : IF (ASSOCIATED(qs_env%linres_control)) THEN
1738 0 : CALL linres_control_release(qs_env%linres_control)
1739 0 : DEALLOCATE (qs_env%linres_control)
1740 : END IF
1741 :
1742 9 : IF (ASSOCIATED(qs_env%almo_scf_env)) THEN
1743 0 : CALL almo_scf_env_release(qs_env%almo_scf_env)
1744 : END IF
1745 :
1746 9 : IF (ASSOCIATED(qs_env%ls_scf_env)) THEN
1747 0 : CALL ls_scf_release(qs_env%ls_scf_env)
1748 : END IF
1749 9 : IF (ASSOCIATED(qs_env%molecular_scf_guess_env)) THEN
1750 9 : CALL molecular_scf_guess_env_destroy(qs_env%molecular_scf_guess_env)
1751 9 : DEALLOCATE (qs_env%molecular_scf_guess_env)
1752 : END IF
1753 :
1754 9 : IF (ASSOCIATED(qs_env%transport_env)) THEN
1755 0 : CALL transport_env_release(qs_env%transport_env)
1756 : END IF
1757 :
1758 : !Only if do_xas_calculation
1759 9 : IF (ASSOCIATED(qs_env%xas_env)) THEN
1760 0 : CALL xas_env_release(qs_env%xas_env)
1761 0 : DEALLOCATE (qs_env%xas_env)
1762 : END IF
1763 9 : IF (ASSOCIATED(qs_env%ewald_env)) THEN
1764 0 : CALL ewald_env_release(qs_env%ewald_env)
1765 0 : DEALLOCATE (qs_env%ewald_env)
1766 : END IF
1767 9 : IF (ASSOCIATED(qs_env%ewald_pw)) THEN
1768 0 : CALL ewald_pw_release(qs_env%ewald_pw)
1769 0 : DEALLOCATE (qs_env%ewald_pw)
1770 : END IF
1771 9 : IF (ASSOCIATED(qs_env%image_matrix)) THEN
1772 0 : DEALLOCATE (qs_env%image_matrix)
1773 : END IF
1774 9 : IF (ASSOCIATED(qs_env%ipiv)) THEN
1775 0 : DEALLOCATE (qs_env%ipiv)
1776 : END IF
1777 9 : IF (ASSOCIATED(qs_env%image_coeff)) THEN
1778 0 : DEALLOCATE (qs_env%image_coeff)
1779 : END IF
1780 : ! ZMP
1781 9 : IF (ASSOCIATED(qs_env%rho_external)) THEN
1782 0 : CALL qs_rho_release(qs_env%rho_external)
1783 0 : DEALLOCATE (qs_env%rho_external)
1784 : END IF
1785 9 : IF (ASSOCIATED(qs_env%external_vxc)) THEN
1786 0 : CALL qs_env%external_vxc%release()
1787 0 : DEALLOCATE (qs_env%external_vxc)
1788 : END IF
1789 9 : IF (ASSOCIATED(qs_env%mask)) THEN
1790 0 : CALL qs_env%mask%release()
1791 0 : DEALLOCATE (qs_env%mask)
1792 : END IF
1793 9 : IF (ASSOCIATED(qs_env%active_space)) THEN
1794 0 : CALL release_active_space_type(qs_env%active_space)
1795 : END IF
1796 : ! Embedding potentials if provided as input
1797 9 : IF (qs_env%given_embed_pot) THEN
1798 0 : CALL qs_env%embed_pot%release()
1799 0 : DEALLOCATE (qs_env%embed_pot)
1800 0 : IF (ASSOCIATED(qs_env%spin_embed_pot)) THEN
1801 0 : CALL qs_env%spin_embed_pot%release()
1802 0 : DEALLOCATE (qs_env%spin_embed_pot)
1803 : END IF
1804 : END IF
1805 :
1806 : ! Polarisability tensor
1807 9 : CALL polar_env_release(qs_env%polar_env)
1808 :
1809 9 : IF (ASSOCIATED(qs_env%qs_charges)) THEN
1810 9 : CALL qs_charges_release(qs_env%qs_charges)
1811 9 : DEALLOCATE (qs_env%qs_charges)
1812 : END IF
1813 9 : CALL qs_ks_part_release(qs_env%ks_env)
1814 9 : IF (ASSOCIATED(qs_env%ks_qmmm_env)) THEN
1815 0 : CALL qs_ks_qmmm_release(qs_env%ks_qmmm_env)
1816 0 : DEALLOCATE (qs_env%ks_qmmm_env)
1817 : END IF
1818 9 : CALL wfi_release(qs_env%wf_history)
1819 9 : IF (ASSOCIATED(qs_env%scf_env)) THEN
1820 0 : CALL scf_env_release(qs_env%scf_env)
1821 0 : DEALLOCATE (qs_env%scf_env)
1822 : END IF
1823 9 : IF (ASSOCIATED(qs_env%cp_ddapc_env)) THEN
1824 0 : CALL cp_ddapc_release(qs_env%cp_ddapc_env)
1825 0 : DEALLOCATE (qs_env%cp_ddapc_env)
1826 : END IF
1827 9 : CALL cp_ddapc_ewald_release(qs_env%cp_ddapc_ewald)
1828 9 : CALL efield_berry_release(qs_env%efield)
1829 9 : IF (ASSOCIATED(qs_env%x_data)) THEN
1830 0 : CALL hfx_release(qs_env%x_data)
1831 : END IF
1832 9 : IF (ASSOCIATED(qs_env%et_coupling)) THEN
1833 0 : CALL et_coupling_release(qs_env%et_coupling)
1834 : END IF
1835 9 : IF (ASSOCIATED(qs_env%dftb_potential)) THEN
1836 0 : CALL qs_dftb_pairpot_release(qs_env%dftb_potential)
1837 : END IF
1838 9 : IF (ASSOCIATED(qs_env%se_taper)) THEN
1839 0 : CALL se_taper_release(qs_env%se_taper)
1840 : END IF
1841 9 : IF (ASSOCIATED(qs_env%se_store_int_env)) THEN
1842 0 : CALL semi_empirical_si_release(qs_env%se_store_int_env)
1843 : END IF
1844 9 : IF (ASSOCIATED(qs_env%se_nddo_mpole)) THEN
1845 0 : CALL nddo_mpole_release(qs_env%se_nddo_mpole)
1846 : END IF
1847 9 : IF (ASSOCIATED(qs_env%se_nonbond_env)) THEN
1848 0 : CALL fist_nonbond_env_release(qs_env%se_nonbond_env)
1849 0 : DEALLOCATE (qs_env%se_nonbond_env)
1850 : END IF
1851 9 : IF (ASSOCIATED(qs_env%admm_env)) THEN
1852 0 : CALL admm_env_release(qs_env%admm_env)
1853 : END IF
1854 9 : IF (ASSOCIATED(qs_env%lri_env)) THEN
1855 0 : CALL lri_env_release(qs_env%lri_env)
1856 0 : DEALLOCATE (qs_env%lri_env)
1857 : END IF
1858 9 : IF (ASSOCIATED(qs_env%lri_density)) THEN
1859 0 : CALL lri_density_release(qs_env%lri_density)
1860 0 : DEALLOCATE (qs_env%lri_density)
1861 : END IF
1862 9 : IF (ASSOCIATED(qs_env%harris_env)) THEN
1863 9 : CALL harris_env_release(qs_env%harris_env)
1864 : END IF
1865 9 : IF (ASSOCIATED(qs_env%ec_env)) THEN
1866 9 : CALL ec_env_release(qs_env%ec_env)
1867 : END IF
1868 9 : IF (ASSOCIATED(qs_env%exstate_env)) THEN
1869 9 : CALL exstate_release(qs_env%exstate_env)
1870 : END IF
1871 9 : IF (ASSOCIATED(qs_env%mp2_env)) THEN
1872 0 : CALL mp2_env_release(qs_env%mp2_env)
1873 0 : DEALLOCATE (qs_env%mp2_env)
1874 : NULLIFY (qs_env%mp2_env)
1875 : END IF
1876 9 : IF (ASSOCIATED(qs_env%kg_env)) THEN
1877 0 : CALL kg_env_release(qs_env%kg_env)
1878 : END IF
1879 :
1880 : ! dispersion
1881 9 : CALL qs_dispersion_release(qs_env%dispersion_env)
1882 : ! gCP
1883 9 : IF (ASSOCIATED(qs_env%gcp_env)) THEN
1884 9 : CALL qs_gcp_release(qs_env%gcp_env)
1885 : END IF
1886 :
1887 9 : IF (ASSOCIATED(qs_env%WannierCentres)) THEN
1888 0 : DO i = 1, SIZE(qs_env%WannierCentres)
1889 0 : DEALLOCATE (qs_env%WannierCentres(i)%WannierHamDiag)
1890 0 : DEALLOCATE (qs_env%WannierCentres(i)%centres)
1891 : END DO
1892 0 : DEALLOCATE (qs_env%WannierCentres)
1893 : END IF
1894 : ! EEQ charges
1895 9 : IF (ASSOCIATED(qs_env%eeq)) DEALLOCATE (qs_env%eeq)
1896 : ! Resp charges
1897 9 : IF (ASSOCIATED(qs_env%rhs)) DEALLOCATE (qs_env%rhs)
1898 :
1899 : ! tblite
1900 9 : IF (ASSOCIATED(qs_env%tb_tblite)) THEN
1901 0 : CALL deallocate_tblite_type(qs_env%tb_tblite)
1902 : END IF
1903 :
1904 9 : END SUBROUTINE qs_env_part_release
1905 :
1906 0 : END MODULE qs_environment_types
|