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