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