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