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