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 : !> - Merged with the Quickstep MODULE method_specification (17.01.2002,MK)
11 : !> - USE statements cleaned, added
12 : !> (25.09.2002,MK)
13 : !> - Added more LSD structure (01.2003,Joost VandeVondele)
14 : !> - New molecule data types introduced (Sep. 2003,MK)
15 : !> - Cleaning; getting rid of pnode (02.10.2003,MK)
16 : !> - Sub-system setup added (08.10.2003,MK)
17 : !> \author MK (18.05.2000)
18 : ! **************************************************************************************************
19 : MODULE qs_environment
20 : USE almo_scf_env_methods, ONLY: almo_scf_env_create
21 : USE atom_kind_orbitals, ONLY: calculate_atomic_relkin
22 : USE atomic_kind_types, ONLY: atomic_kind_type
23 : USE auto_basis, ONLY: create_lri_aux_basis_set,&
24 : create_ri_aux_basis_set
25 : USE basis_set_container_types, ONLY: add_basis_set_to_container
26 : USE basis_set_types, ONLY: basis_sort_zet,&
27 : create_primitive_basis_set,&
28 : deallocate_gto_basis_set,&
29 : gto_basis_set_type
30 : USE bibliography, ONLY: Iannuzzi2006,&
31 : Iannuzzi2007,&
32 : cite_reference,&
33 : cp2kqs2020
34 : USE cell_types, ONLY: cell_type
35 : USE cp_blacs_env, ONLY: cp_blacs_env_create,&
36 : cp_blacs_env_release,&
37 : cp_blacs_env_type
38 : USE cp_control_types, ONLY: dft_control_type,&
39 : dftb_control_type,&
40 : gapw_control_type,&
41 : qs_control_type,&
42 : semi_empirical_control_type,&
43 : xtb_control_type
44 : USE cp_control_utils, ONLY: &
45 : read_ddapc_section, read_dft_control, read_mgrid_section, read_qs_section, &
46 : read_tddfpt2_control, read_tddfpt_control, write_admm_control, write_dft_control, &
47 : write_qs_control
48 : USE cp_ddapc_types, ONLY: cp_ddapc_ewald_create
49 : USE cp_log_handling, ONLY: cp_get_default_logger,&
50 : cp_logger_get_default_io_unit,&
51 : cp_logger_type
52 : USE cp_output_handling, ONLY: cp_p_file,&
53 : cp_print_key_finished_output,&
54 : cp_print_key_should_output,&
55 : cp_print_key_unit_nr
56 : USE cp_subsys_types, ONLY: cp_subsys_type
57 : USE cp_symmetry, ONLY: write_symmetry
58 : USE distribution_1d_types, ONLY: distribution_1d_release,&
59 : distribution_1d_type
60 : USE distribution_methods, ONLY: distribute_molecules_1d
61 : USE dm_ls_scf_create, ONLY: ls_scf_create
62 : USE ec_env_types, ONLY: energy_correction_type
63 : USE ec_environment, ONLY: ec_env_create,&
64 : ec_write_input
65 : USE et_coupling_types, ONLY: et_coupling_create
66 : USE ewald_environment_types, ONLY: ewald_env_create,&
67 : ewald_env_get,&
68 : ewald_env_set,&
69 : ewald_environment_type,&
70 : read_ewald_section,&
71 : read_ewald_section_tb
72 : USE ewald_pw_methods, ONLY: ewald_pw_grid_update
73 : USE ewald_pw_types, ONLY: ewald_pw_create,&
74 : ewald_pw_type
75 : USE exstates_types, ONLY: excited_energy_type,&
76 : exstate_create
77 : USE external_potential_types, ONLY: get_potential,&
78 : init_potential,&
79 : set_potential
80 : USE fist_nonbond_env_types, ONLY: fist_nonbond_env_create,&
81 : fist_nonbond_env_type
82 : USE gamma, ONLY: init_md_ftable
83 : USE global_types, ONLY: global_environment_type
84 : USE hartree_local_methods, ONLY: init_coulomb_local
85 : USE header, ONLY: dftb_header,&
86 : qs_header,&
87 : se_header,&
88 : xtb_header
89 : USE hfx_types, ONLY: compare_hfx_sections,&
90 : hfx_create
91 : USE input_constants, ONLY: &
92 : dispersion_d2, dispersion_d3, dispersion_d3bj, do_et_ddapc, do_method_am1, do_method_dftb, &
93 : do_method_gapw, do_method_gapw_xc, do_method_gpw, do_method_lrigpw, do_method_mndo, &
94 : do_method_mndod, do_method_ofgpw, do_method_pdg, do_method_pm3, do_method_pm6, &
95 : do_method_pm6fm, do_method_pnnl, do_method_rigpw, do_method_rm1, do_method_xtb, &
96 : do_qmmm_gauss, do_qmmm_swave, general_roks, hden_atomic, kg_tnadd_embed_ri, rel_none, &
97 : rel_trans_atom, vdw_pairpot_dftd2, vdw_pairpot_dftd3, vdw_pairpot_dftd3bj, &
98 : vdw_pairpot_dftd4, wfi_aspc_nr, wfi_linear_ps_method_nr, wfi_linear_wf_method_nr, &
99 : wfi_ps_method_nr, wfi_use_guess_method_nr, xc_vdw_fun_none, xc_vdw_fun_nonloc, &
100 : xc_vdw_fun_pairpot, xtb_vdw_type_d3, xtb_vdw_type_d4, xtb_vdw_type_none
101 : USE input_section_types, ONLY: section_vals_get,&
102 : section_vals_get_subs_vals,&
103 : section_vals_type,&
104 : section_vals_val_get
105 : USE kg_environment, ONLY: kg_env_create
106 : USE kinds, ONLY: default_string_length,&
107 : dp
108 : USE kpoint_methods, ONLY: kpoint_env_initialize,&
109 : kpoint_initialize,&
110 : kpoint_initialize_mos
111 : USE kpoint_types, ONLY: get_kpoint_info,&
112 : kpoint_create,&
113 : kpoint_type,&
114 : read_kpoint_section,&
115 : write_kpoint_info
116 : USE lri_environment_init, ONLY: lri_env_basis,&
117 : lri_env_init
118 : USE lri_environment_types, ONLY: lri_environment_type
119 : USE machine, ONLY: m_flush
120 : USE mathconstants, ONLY: pi
121 : USE message_passing, ONLY: mp_para_env_type
122 : USE molecule_kind_types, ONLY: molecule_kind_type,&
123 : write_molecule_kind_set
124 : USE molecule_types, ONLY: molecule_type
125 : USE mp2_setup, ONLY: read_mp2_section
126 : USE mp2_types, ONLY: mp2_env_create,&
127 : mp2_type
128 : USE multipole_types, ONLY: do_multipole_none
129 : USE orbital_pointers, ONLY: init_orbital_pointers
130 : USE orbital_transformation_matrices, ONLY: init_spherical_harmonics
131 : USE particle_methods, ONLY: write_particle_distances,&
132 : write_qs_particle_coordinates,&
133 : write_structure_data
134 : USE particle_types, ONLY: particle_type
135 : USE pw_env_types, ONLY: pw_env_type
136 : USE qmmm_types_low, ONLY: qmmm_env_qm_type
137 : USE qs_basis_rotation_methods, ONLY: qs_basis_rotation
138 : USE qs_dftb_parameters, ONLY: qs_dftb_param_init
139 : USE qs_dftb_types, ONLY: qs_dftb_pairpot_type
140 : USE qs_dispersion_nonloc, ONLY: qs_dispersion_nonloc_init
141 : USE qs_dispersion_pairpot, ONLY: qs_dispersion_pairpot_init
142 : USE qs_dispersion_types, ONLY: qs_dispersion_type
143 : USE qs_dispersion_utils, ONLY: qs_dispersion_env_set,&
144 : qs_write_dispersion
145 : USE qs_energy_types, ONLY: allocate_qs_energy,&
146 : qs_energy_type
147 : USE qs_environment_methods, ONLY: qs_env_setup
148 : USE qs_environment_types, ONLY: get_qs_env,&
149 : qs_environment_type,&
150 : set_qs_env
151 : USE qs_force_types, ONLY: qs_force_type
152 : USE qs_gcp_types, ONLY: qs_gcp_type
153 : USE qs_gcp_utils, ONLY: qs_gcp_env_set,&
154 : qs_gcp_init
155 : USE qs_harris_types, ONLY: harris_rhoin_init,&
156 : harris_type
157 : USE qs_harris_utils, ONLY: harris_env_create,&
158 : harris_write_input
159 : USE qs_interactions, ONLY: init_interaction_radii,&
160 : init_se_nlradius,&
161 : write_core_charge_radii,&
162 : write_paw_radii,&
163 : write_pgf_orb_radii,&
164 : write_ppl_radii,&
165 : write_ppnl_radii
166 : USE qs_kind_types, ONLY: &
167 : check_qs_kind_set, get_qs_kind, get_qs_kind_set, init_gapw_basis_set, init_gapw_nlcc, &
168 : init_qs_kind_set, qs_kind_type, set_qs_kind, write_gto_basis_sets, write_qs_kind_set
169 : USE qs_ks_types, ONLY: qs_ks_env_create,&
170 : qs_ks_env_type,&
171 : set_ks_env
172 : USE qs_local_rho_types, ONLY: local_rho_type
173 : USE qs_mo_types, ONLY: allocate_mo_set,&
174 : mo_set_type
175 : USE qs_rho0_ggrid, ONLY: rho0_s_grid_create
176 : USE qs_rho0_methods, ONLY: init_rho0
177 : USE qs_rho0_types, ONLY: rho0_mpole_type
178 : USE qs_rho_atom_methods, ONLY: init_rho_atom
179 : USE qs_rho_atom_types, ONLY: rho_atom_type
180 : USE qs_subsys_methods, ONLY: qs_subsys_create
181 : USE qs_subsys_types, ONLY: qs_subsys_get,&
182 : qs_subsys_set,&
183 : qs_subsys_type
184 : USE qs_wf_history_methods, ONLY: wfi_create,&
185 : wfi_create_for_kp
186 : USE qs_wf_history_types, ONLY: qs_wf_history_type,&
187 : wfi_release
188 : USE rel_control_types, ONLY: rel_c_create,&
189 : rel_c_read_parameters,&
190 : rel_control_type
191 : USE scf_control_types, ONLY: scf_c_create,&
192 : scf_c_read_parameters,&
193 : scf_c_write_parameters,&
194 : scf_control_type
195 : USE semi_empirical_expns3_methods, ONLY: semi_empirical_expns3_setup
196 : USE semi_empirical_int_arrays, ONLY: init_se_intd_array
197 : USE semi_empirical_mpole_methods, ONLY: nddo_mpole_setup
198 : USE semi_empirical_mpole_types, ONLY: nddo_mpole_type
199 : USE semi_empirical_store_int_types, ONLY: semi_empirical_si_create,&
200 : semi_empirical_si_type
201 : USE semi_empirical_types, ONLY: se_taper_create,&
202 : se_taper_type
203 : USE semi_empirical_utils, ONLY: se_cutoff_compatible
204 : USE transport, ONLY: transport_env_create
205 : USE xtb_parameters, ONLY: init_xtb_basis,&
206 : xtb_parameters_init,&
207 : xtb_parameters_set
208 : USE xtb_potentials, ONLY: xtb_pp_radius
209 : USE xtb_types, ONLY: allocate_xtb_atom_param
210 : #include "./base/base_uses.f90"
211 :
212 : IMPLICIT NONE
213 :
214 : PRIVATE
215 :
216 : ! *** Global parameters ***
217 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'qs_environment'
218 :
219 : ! *** Public subroutines ***
220 : PUBLIC :: qs_init
221 :
222 : CONTAINS
223 :
224 : ! **************************************************************************************************
225 : !> \brief Read the input and the database files for the setup of the
226 : !> QUICKSTEP environment.
227 : !> \param qs_env ...
228 : !> \param para_env ...
229 : !> \param root_section ...
230 : !> \param globenv ...
231 : !> \param cp_subsys ...
232 : !> \param kpoint_env ...
233 : !> \param cell ...
234 : !> \param cell_ref ...
235 : !> \param qmmm ...
236 : !> \param qmmm_env_qm ...
237 : !> \param force_env_section ...
238 : !> \param subsys_section ...
239 : !> \param use_motion_section ...
240 : !> \author Creation (22.05.2000,MK)
241 : ! **************************************************************************************************
242 46802 : SUBROUTINE qs_init(qs_env, para_env, root_section, globenv, cp_subsys, kpoint_env, cell, cell_ref, &
243 : qmmm, qmmm_env_qm, force_env_section, subsys_section, use_motion_section)
244 :
245 : TYPE(qs_environment_type), POINTER :: qs_env
246 : TYPE(mp_para_env_type), POINTER :: para_env
247 : TYPE(section_vals_type), OPTIONAL, POINTER :: root_section
248 : TYPE(global_environment_type), OPTIONAL, POINTER :: globenv
249 : TYPE(cp_subsys_type), OPTIONAL, POINTER :: cp_subsys
250 : TYPE(kpoint_type), OPTIONAL, POINTER :: kpoint_env
251 : TYPE(cell_type), OPTIONAL, POINTER :: cell, cell_ref
252 : LOGICAL, INTENT(IN), OPTIONAL :: qmmm
253 : TYPE(qmmm_env_qm_type), OPTIONAL, POINTER :: qmmm_env_qm
254 : TYPE(section_vals_type), POINTER :: force_env_section, subsys_section
255 : LOGICAL, INTENT(IN) :: use_motion_section
256 :
257 : CHARACTER(LEN=default_string_length) :: basis_type
258 : INTEGER :: ikind, method_id, nelectron_total, &
259 : nkind, nkp_grid(3)
260 : LOGICAL :: do_admm_rpa, do_ec_hfx, do_et, do_exx, do_hfx, do_kpoints, is_identical, is_semi, &
261 : mp2_present, my_qmmm, qmmm_decoupl, same_except_frac, silent, use_ref_cell
262 6686 : REAL(KIND=dp), DIMENSION(:, :), POINTER :: rtmat
263 6686 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
264 : TYPE(cell_type), POINTER :: my_cell, my_cell_ref
265 : TYPE(cp_blacs_env_type), POINTER :: blacs_env
266 : TYPE(dft_control_type), POINTER :: dft_control
267 : TYPE(distribution_1d_type), POINTER :: local_particles
268 : TYPE(energy_correction_type), POINTER :: ec_env
269 : TYPE(excited_energy_type), POINTER :: exstate_env
270 : TYPE(harris_type), POINTER :: harris_env
271 : TYPE(kpoint_type), POINTER :: kpoints
272 : TYPE(lri_environment_type), POINTER :: lri_env
273 6686 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
274 6686 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
275 : TYPE(qs_ks_env_type), POINTER :: ks_env
276 : TYPE(qs_subsys_type), POINTER :: subsys
277 : TYPE(qs_wf_history_type), POINTER :: wf_history
278 : TYPE(rel_control_type), POINTER :: rel_control
279 : TYPE(scf_control_type), POINTER :: scf_control
280 : TYPE(section_vals_type), POINTER :: dft_section, ec_hfx_section, ec_section, &
281 : et_coupling_section, hfx_section, kpoint_section, mp2_section, rpa_hfx_section, &
282 : transport_section
283 :
284 6686 : NULLIFY (my_cell, my_cell_ref, atomic_kind_set, particle_set, &
285 6686 : qs_kind_set, kpoint_section, dft_section, ec_section, &
286 6686 : subsys, ks_env, dft_control, blacs_env)
287 :
288 6686 : CALL set_qs_env(qs_env, input=force_env_section)
289 6686 : IF (.NOT. ASSOCIATED(subsys_section)) THEN
290 104 : subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
291 : END IF
292 :
293 : ! QMMM
294 6686 : my_qmmm = .FALSE.
295 6686 : IF (PRESENT(qmmm)) my_qmmm = qmmm
296 6686 : qmmm_decoupl = .FALSE.
297 6686 : IF (PRESENT(qmmm_env_qm)) THEN
298 394 : IF (qmmm_env_qm%qmmm_coupl_type == do_qmmm_gauss .OR. &
299 : qmmm_env_qm%qmmm_coupl_type == do_qmmm_swave) THEN
300 : ! For GAUSS/SWAVE methods there could be a DDAPC decoupling requested
301 458 : qmmm_decoupl = my_qmmm .AND. qmmm_env_qm%periodic .AND. qmmm_env_qm%multipole
302 : END IF
303 394 : qs_env%qmmm_env_qm => qmmm_env_qm
304 : END IF
305 6686 : CALL set_qs_env(qs_env=qs_env, qmmm=my_qmmm)
306 :
307 : ! Possibly initialize arrays for SE
308 6686 : CALL section_vals_val_get(force_env_section, "DFT%QS%METHOD", i_val=method_id)
309 998 : SELECT CASE (method_id)
310 : CASE (do_method_rm1, do_method_am1, do_method_mndo, do_method_pdg, &
311 : do_method_pm3, do_method_pm6, do_method_pm6fm, do_method_mndod, do_method_pnnl)
312 998 : CALL init_se_intd_array()
313 998 : is_semi = .TRUE.
314 : CASE (do_method_xtb, do_method_dftb)
315 506 : is_semi = .TRUE.
316 : CASE DEFAULT
317 6686 : is_semi = .FALSE.
318 : END SELECT
319 :
320 26744 : ALLOCATE (subsys)
321 : CALL qs_subsys_create(subsys, para_env, &
322 : force_env_section=force_env_section, &
323 : subsys_section=subsys_section, &
324 : use_motion_section=use_motion_section, &
325 : root_section=root_section, &
326 : cp_subsys=cp_subsys, cell=cell, cell_ref=cell_ref, &
327 6686 : elkind=is_semi)
328 :
329 6686 : ALLOCATE (ks_env)
330 6686 : CALL qs_ks_env_create(ks_env)
331 6686 : CALL set_ks_env(ks_env, subsys=subsys)
332 6686 : CALL set_qs_env(qs_env, ks_env=ks_env)
333 :
334 : CALL qs_subsys_get(subsys, &
335 : cell=my_cell, &
336 : cell_ref=my_cell_ref, &
337 : use_ref_cell=use_ref_cell, &
338 : atomic_kind_set=atomic_kind_set, &
339 : qs_kind_set=qs_kind_set, &
340 6686 : particle_set=particle_set)
341 :
342 6686 : CALL set_ks_env(ks_env, para_env=para_env)
343 6686 : IF (PRESENT(globenv)) THEN
344 : CALL cp_blacs_env_create(blacs_env, para_env, globenv%blacs_grid_layout, &
345 6684 : globenv%blacs_repeatable)
346 : ELSE
347 2 : CALL cp_blacs_env_create(blacs_env, para_env)
348 : END IF
349 6686 : CALL set_ks_env(ks_env, blacs_env=blacs_env)
350 6686 : CALL cp_blacs_env_release(blacs_env)
351 :
352 : ! *** Setup the grids for the G-space Interpolation if any
353 : CALL cp_ddapc_ewald_create(qs_env%cp_ddapc_ewald, qmmm_decoupl, my_cell, &
354 6686 : force_env_section, subsys_section, para_env)
355 :
356 : ! kpoints
357 6686 : IF (PRESENT(kpoint_env)) THEN
358 2 : silent = .TRUE.
359 2 : kpoints => kpoint_env
360 2 : CALL set_qs_env(qs_env=qs_env, kpoints=kpoints)
361 2 : CALL kpoint_initialize(kpoints, particle_set, my_cell)
362 : ELSE
363 6684 : silent = .FALSE.
364 6684 : NULLIFY (kpoints)
365 6684 : CALL kpoint_create(kpoints)
366 6684 : CALL set_qs_env(qs_env=qs_env, kpoints=kpoints)
367 6684 : kpoint_section => section_vals_get_subs_vals(qs_env%input, "DFT%KPOINTS")
368 6684 : CALL read_kpoint_section(kpoints, kpoint_section, my_cell%hmat)
369 6684 : CALL kpoint_initialize(kpoints, particle_set, my_cell)
370 6684 : dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
371 6684 : CALL write_kpoint_info(kpoints, dft_section)
372 : END IF
373 :
374 : CALL qs_init_subsys(qs_env, para_env, subsys, my_cell, my_cell_ref, use_ref_cell, &
375 6686 : subsys_section, silent=silent)
376 :
377 6686 : CALL get_qs_env(qs_env, dft_control=dft_control)
378 6686 : IF (method_id == do_method_lrigpw .OR. dft_control%qs_control%lri_optbas) THEN
379 46 : CALL get_qs_env(qs_env=qs_env, lri_env=lri_env)
380 46 : CALL lri_env_basis("LRI", qs_env, lri_env, qs_kind_set)
381 6640 : ELSE IF (method_id == do_method_rigpw) THEN
382 : CALL cp_warn(__LOCATION__, "Experimental code: "// &
383 0 : "RIGPW should only be used for testing.")
384 0 : CALL get_qs_env(qs_env=qs_env, lri_env=lri_env)
385 0 : CALL lri_env_basis("RI", qs_env, lri_env, qs_kind_set)
386 : END IF
387 :
388 6686 : IF (my_qmmm .AND. PRESENT(qmmm_env_qm) .AND. .NOT. dft_control%qs_control%commensurate_mgrids) THEN
389 132 : IF (qmmm_env_qm%qmmm_coupl_type == do_qmmm_gauss .OR. qmmm_env_qm%qmmm_coupl_type == do_qmmm_swave) THEN
390 : CALL cp_abort(__LOCATION__, "QM/MM with coupling GAUSS or S-WAVE requires "// &
391 0 : "keyword FORCE_EVAL/DFT/MGRID/COMMENSURATE to be enabled.")
392 : END IF
393 : END IF
394 :
395 : ! more kpoint stuff
396 6686 : CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints, blacs_env=blacs_env)
397 6686 : IF (do_kpoints) THEN
398 160 : CALL kpoint_env_initialize(kpoints, para_env, blacs_env, with_aux_fit=dft_control%do_admm)
399 160 : CALL kpoint_initialize_mos(kpoints, qs_env%mos)
400 160 : CALL get_qs_env(qs_env=qs_env, wf_history=wf_history)
401 160 : CALL wfi_create_for_kp(wf_history)
402 : END IF
403 : ! basis set symmetry rotations
404 6686 : IF (do_kpoints) THEN
405 160 : CALL qs_basis_rotation(qs_env, kpoints)
406 : END IF
407 :
408 : do_hfx = .FALSE.
409 6686 : hfx_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%HF")
410 6686 : CALL section_vals_get(hfx_section, explicit=do_hfx)
411 6686 : CALL get_qs_env(qs_env, dft_control=dft_control, scf_control=scf_control, nelectron_total=nelectron_total)
412 6686 : IF (do_hfx) THEN
413 : ! Retrieve particle_set and atomic_kind_set (needed for both kinds of initialization)
414 4736 : nkp_grid = 1
415 1184 : IF (do_kpoints) CALL get_kpoint_info(kpoints, nkp_grid=nkp_grid)
416 1184 : IF (dft_control%do_admm) THEN
417 434 : basis_type = 'AUX_FIT'
418 : ELSE
419 750 : basis_type = 'ORB'
420 : END IF
421 : CALL hfx_create(qs_env%x_data, para_env, hfx_section, atomic_kind_set, &
422 : qs_kind_set, particle_set, dft_control, my_cell, orb_basis=basis_type, &
423 1184 : nelectron_total=nelectron_total, nkp_grid=nkp_grid)
424 : END IF
425 :
426 6686 : mp2_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION")
427 6686 : CALL section_vals_get(mp2_section, explicit=mp2_present)
428 6686 : IF (mp2_present) THEN
429 466 : CPASSERT(ASSOCIATED(qs_env%mp2_env))
430 466 : CALL read_mp2_section(qs_env%input, qs_env%mp2_env)
431 : ! create the EXX section if necessary
432 : do_exx = .FALSE.
433 466 : rpa_hfx_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION%RI_RPA%HF")
434 466 : CALL section_vals_get(rpa_hfx_section, explicit=do_exx)
435 466 : IF (do_exx) THEN
436 :
437 : ! do_exx in call of hfx_create decides whether to go without ADMM (do_exx=.TRUE.) or with
438 : ! ADMM (do_exx=.FALSE.)
439 138 : CALL section_vals_val_get(mp2_section, "RI_RPA%ADMM", l_val=do_admm_rpa)
440 :
441 : ! Reuse the HFX integrals from the qs_env if applicable
442 138 : qs_env%mp2_env%ri_rpa%reuse_hfx = .TRUE.
443 138 : IF (.NOT. do_hfx) qs_env%mp2_env%ri_rpa%reuse_hfx = .FALSE.
444 138 : CALL compare_hfx_sections(hfx_section, rpa_hfx_section, is_identical, same_except_frac)
445 138 : IF (.NOT. (is_identical .OR. same_except_frac)) qs_env%mp2_env%ri_rpa%reuse_hfx = .FALSE.
446 138 : IF (dft_control%do_admm .AND. .NOT. do_admm_rpa) qs_env%mp2_env%ri_rpa%reuse_hfx = .FALSE.
447 :
448 138 : IF (.NOT. qs_env%mp2_env%ri_rpa%reuse_hfx) THEN
449 120 : IF (do_admm_rpa) THEN
450 10 : basis_type = 'AUX_FIT'
451 : ELSE
452 110 : basis_type = 'ORB'
453 : END IF
454 : CALL hfx_create(qs_env%mp2_env%ri_rpa%x_data, para_env, rpa_hfx_section, atomic_kind_set, &
455 : qs_kind_set, particle_set, dft_control, my_cell, orb_basis=basis_type, &
456 120 : nelectron_total=nelectron_total)
457 : ELSE
458 18 : qs_env%mp2_env%ri_rpa%x_data => qs_env%x_data
459 : END IF
460 : END IF
461 : END IF
462 :
463 6686 : IF (dft_control%qs_control%do_kg) THEN
464 66 : CALL cite_reference(Iannuzzi2006)
465 66 : CALL kg_env_create(qs_env, qs_env%kg_env, qs_kind_set, qs_env%input)
466 : END IF
467 :
468 6686 : dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
469 : CALL section_vals_val_get(dft_section, "EXCITED_STATES%_SECTION_PARAMETERS_", &
470 6686 : l_val=qs_env%excited_state)
471 6686 : NULLIFY (exstate_env)
472 6686 : CALL exstate_create(exstate_env, qs_env%excited_state, dft_section)
473 6686 : CALL set_qs_env(qs_env, exstate_env=exstate_env)
474 :
475 : et_coupling_section => section_vals_get_subs_vals(qs_env%input, &
476 6686 : "PROPERTIES%ET_COUPLING")
477 6686 : CALL section_vals_get(et_coupling_section, explicit=do_et)
478 6686 : IF (do_et) CALL et_coupling_create(qs_env%et_coupling)
479 :
480 6686 : transport_section => section_vals_get_subs_vals(qs_env%input, "DFT%TRANSPORT")
481 6686 : CALL section_vals_get(transport_section, explicit=qs_env%do_transport)
482 6686 : IF (qs_env%do_transport) THEN
483 0 : CALL transport_env_create(qs_env)
484 : END IF
485 :
486 6686 : IF (dft_control%qs_control%do_ls_scf) THEN
487 344 : CALL ls_scf_create(qs_env)
488 : END IF
489 :
490 6686 : CALL get_qs_env(qs_env, harris_env=harris_env)
491 6686 : IF (qs_env%harris_method) THEN
492 : ! initialize the Harris input density and potential integrals
493 6 : CALL get_qs_env(qs_env, local_particles=local_particles)
494 : CALL harris_rhoin_init(harris_env%rhoin, "RHOIN", qs_kind_set, atomic_kind_set, &
495 6 : local_particles, dft_control%nspins)
496 : ! Print information of the HARRIS section
497 6 : CALL harris_write_input(harris_env)
498 : END IF
499 :
500 6686 : NULLIFY (ec_env)
501 6686 : dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
502 : CALL section_vals_val_get(dft_section, "ENERGY_CORRECTION%_SECTION_PARAMETERS_", &
503 6686 : l_val=qs_env%energy_correction)
504 6686 : ec_section => section_vals_get_subs_vals(qs_env%input, "DFT%ENERGY_CORRECTION")
505 6686 : CALL ec_env_create(qs_env, ec_env, dft_section, ec_section)
506 6686 : CALL set_qs_env(qs_env, ec_env=ec_env)
507 :
508 6686 : IF (qs_env%energy_correction) THEN
509 : ! Energy correction with Hartree-Fock exchange
510 236 : ec_hfx_section => section_vals_get_subs_vals(ec_section, "XC%HF")
511 236 : CALL section_vals_get(ec_hfx_section, explicit=do_ec_hfx)
512 :
513 236 : IF (ec_env%do_ec_hfx) THEN
514 :
515 : ! Hybrid functionals require same basis
516 16 : IF (ec_env%basis_inconsistent) THEN
517 : CALL cp_abort(__LOCATION__, &
518 : "Energy correction methods with hybrid functionals: "// &
519 : "correction and ground state need to use the same basis. "// &
520 0 : "Checked by comparing basis set names only.")
521 : END IF
522 :
523 : ! Similar to RPA_HFX we can check if HFX integrals from the qs_env can be reused
524 16 : IF (ec_env%do_ec_admm .AND. .NOT. dft_control%do_admm) THEN
525 0 : CALL cp_abort(__LOCATION__, "Need an ADMM input section for ADMM EC to work")
526 : END IF
527 :
528 16 : ec_env%reuse_hfx = .TRUE.
529 16 : IF (.NOT. do_hfx) ec_env%reuse_hfx = .FALSE.
530 16 : CALL compare_hfx_sections(hfx_section, ec_hfx_section, is_identical, same_except_frac)
531 16 : IF (.NOT. (is_identical .OR. same_except_frac)) ec_env%reuse_hfx = .FALSE.
532 16 : IF (dft_control%do_admm .AND. .NOT. ec_env%do_ec_admm) ec_env%reuse_hfx = .FALSE.
533 :
534 16 : IF (.NOT. ec_env%reuse_hfx) THEN
535 6 : IF (ec_env%do_ec_admm) THEN
536 2 : basis_type = 'AUX_FIT'
537 : ELSE
538 4 : basis_type = 'ORB'
539 : END IF
540 : CALL hfx_create(ec_env%x_data, para_env, ec_hfx_section, atomic_kind_set, &
541 : qs_kind_set, particle_set, dft_control, my_cell, orb_basis=basis_type, &
542 6 : nelectron_total=nelectron_total)
543 : ELSE
544 10 : ec_env%x_data => qs_env%x_data
545 : END IF
546 : END IF
547 :
548 : ! Print information of the EC section
549 236 : CALL ec_write_input(ec_env)
550 :
551 : END IF
552 :
553 6686 : IF (dft_control%qs_control%do_almo_scf) THEN
554 66 : CALL almo_scf_env_create(qs_env)
555 : END IF
556 :
557 : ! see if we have atomic relativistic corrections
558 6686 : CALL get_qs_env(qs_env, rel_control=rel_control)
559 6686 : IF (rel_control%rel_method /= rel_none) THEN
560 16 : IF (rel_control%rel_transformation == rel_trans_atom) THEN
561 16 : nkind = SIZE(atomic_kind_set)
562 42 : DO ikind = 1, nkind
563 26 : NULLIFY (rtmat)
564 26 : CALL calculate_atomic_relkin(atomic_kind_set(ikind), qs_kind_set(ikind), rel_control, rtmat)
565 42 : IF (ASSOCIATED(rtmat)) CALL set_qs_kind(qs_kind_set(ikind), reltmat=rtmat)
566 : END DO
567 : END IF
568 : END IF
569 :
570 6686 : END SUBROUTINE qs_init
571 :
572 : ! **************************************************************************************************
573 : !> \brief Initialize the qs environment (subsys)
574 : !> \param qs_env ...
575 : !> \param para_env ...
576 : !> \param subsys ...
577 : !> \param cell ...
578 : !> \param cell_ref ...
579 : !> \param use_ref_cell ...
580 : !> \param subsys_section ...
581 : !> \param silent ...
582 : !> \author Creation (22.05.2000,MK)
583 : ! **************************************************************************************************
584 6686 : SUBROUTINE qs_init_subsys(qs_env, para_env, subsys, cell, cell_ref, use_ref_cell, subsys_section, &
585 : silent)
586 :
587 : TYPE(qs_environment_type), POINTER :: qs_env
588 : TYPE(mp_para_env_type), POINTER :: para_env
589 : TYPE(qs_subsys_type), POINTER :: subsys
590 : TYPE(cell_type), POINTER :: cell, cell_ref
591 : LOGICAL, INTENT(in) :: use_ref_cell
592 : TYPE(section_vals_type), POINTER :: subsys_section
593 : LOGICAL, INTENT(in), OPTIONAL :: silent
594 :
595 : CHARACTER(len=*), PARAMETER :: routineN = 'qs_init_subsys'
596 :
597 : CHARACTER(len=2) :: element_symbol
598 : INTEGER :: gfn_type, handle, ikind, ispin, iw, lmax_sphere, maxl, maxlgto, maxlgto_lri, &
599 : maxlppl, maxlppnl, method_id, multiplicity, my_ival, n_ao, n_mo_add, natom, nelectron, &
600 : ngauss, nkind, output_unit, sort_basis, tnadd_method
601 : INTEGER, DIMENSION(2) :: n_mo, nelectron_spin
602 : LOGICAL :: all_potential_present, be_silent, do_kpoints, do_ri_hfx, do_ri_mp2, do_ri_rpa, &
603 : do_ri_sos_mp2, do_rpa_ri_exx, do_wfc_im_time, e1terms, has_unit_metric, lribas, &
604 : mp2_present, orb_gradient
605 : REAL(KIND=dp) :: alpha, ccore, ewald_rcut, fxx, maxocc, &
606 : rcut, total_zeff_corr, verlet_skin, &
607 : zeff_correction
608 6686 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
609 : TYPE(cp_logger_type), POINTER :: logger
610 : TYPE(dft_control_type), POINTER :: dft_control
611 : TYPE(dftb_control_type), POINTER :: dftb_control
612 : TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
613 : TYPE(ewald_environment_type), POINTER :: ewald_env
614 : TYPE(ewald_pw_type), POINTER :: ewald_pw
615 : TYPE(fist_nonbond_env_type), POINTER :: se_nonbond_env
616 : TYPE(gapw_control_type), POINTER :: gapw_control
617 : TYPE(gto_basis_set_type), POINTER :: aux_fit_basis, lri_aux_basis, &
618 : rhoin_basis, ri_aux_basis_set, &
619 : ri_hfx_basis, ri_xas_basis, &
620 : tmp_basis_set
621 : TYPE(harris_type), POINTER :: harris_env
622 : TYPE(local_rho_type), POINTER :: local_rho_set
623 : TYPE(lri_environment_type), POINTER :: lri_env
624 6686 : TYPE(mo_set_type), DIMENSION(:), POINTER :: mos, mos_last_converged
625 6686 : TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
626 6686 : TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
627 : TYPE(mp2_type), POINTER :: mp2_env
628 : TYPE(nddo_mpole_type), POINTER :: se_nddo_mpole
629 6686 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
630 : TYPE(pw_env_type), POINTER :: pw_env
631 : TYPE(qs_control_type), POINTER :: qs_control
632 : TYPE(qs_dftb_pairpot_type), DIMENSION(:, :), &
633 6686 : POINTER :: dftb_potential
634 : TYPE(qs_dispersion_type), POINTER :: dispersion_env
635 : TYPE(qs_energy_type), POINTER :: energy
636 6686 : TYPE(qs_force_type), DIMENSION(:), POINTER :: force
637 : TYPE(qs_gcp_type), POINTER :: gcp_env
638 6686 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
639 : TYPE(qs_kind_type), POINTER :: qs_kind
640 : TYPE(qs_ks_env_type), POINTER :: ks_env
641 : TYPE(qs_wf_history_type), POINTER :: wf_history
642 : TYPE(rho0_mpole_type), POINTER :: rho0_mpole
643 6686 : TYPE(rho_atom_type), DIMENSION(:), POINTER :: rho_atom_set
644 : TYPE(scf_control_type), POINTER :: scf_control
645 : TYPE(se_taper_type), POINTER :: se_taper
646 : TYPE(section_vals_type), POINTER :: dft_section, et_coupling_section, et_ddapc_section, &
647 : ewald_section, harris_section, lri_section, mp2_section, nl_section, poisson_section, &
648 : pp_section, print_section, qs_section, se_section, tddfpt_section, xc_section
649 : TYPE(semi_empirical_control_type), POINTER :: se_control
650 : TYPE(semi_empirical_si_type), POINTER :: se_store_int_env
651 : TYPE(xtb_control_type), POINTER :: xtb_control
652 :
653 6686 : CALL timeset(routineN, handle)
654 6686 : NULLIFY (logger)
655 6686 : logger => cp_get_default_logger()
656 6686 : output_unit = cp_logger_get_default_io_unit(logger)
657 :
658 6686 : be_silent = .FALSE.
659 6686 : IF (PRESENT(silent)) be_silent = silent
660 :
661 6686 : CALL cite_reference(cp2kqs2020)
662 :
663 : ! Initialise the Quickstep environment
664 6686 : NULLIFY (mos, se_taper)
665 6686 : NULLIFY (dft_control)
666 6686 : NULLIFY (energy)
667 6686 : NULLIFY (force)
668 6686 : NULLIFY (local_molecules)
669 6686 : NULLIFY (local_particles)
670 6686 : NULLIFY (scf_control)
671 6686 : NULLIFY (dft_section)
672 6686 : NULLIFY (et_coupling_section)
673 6686 : NULLIFY (ks_env)
674 6686 : NULLIFY (mos_last_converged)
675 6686 : dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
676 6686 : qs_section => section_vals_get_subs_vals(dft_section, "QS")
677 6686 : et_coupling_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%ET_COUPLING")
678 : ! reimplemented TDDFPT
679 6686 : tddfpt_section => section_vals_get_subs_vals(qs_env%input, "PROPERTIES%TDDFPT")
680 :
681 : CALL qs_subsys_get(subsys, particle_set=particle_set, &
682 : qs_kind_set=qs_kind_set, &
683 : atomic_kind_set=atomic_kind_set, &
684 : molecule_set=molecule_set, &
685 6686 : molecule_kind_set=molecule_kind_set)
686 :
687 : ! *** Read the input section with the DFT control parameters ***
688 6686 : CALL read_dft_control(dft_control, dft_section)
689 :
690 : ! original implementation of TDDFPT
691 6686 : IF (dft_control%do_tddfpt_calculation) THEN
692 12 : CALL read_tddfpt_control(dft_control%tddfpt_control, dft_section)
693 : END IF
694 : ! set periodicity flag
695 26744 : dft_control%qs_control%periodicity = SUM(cell%perd)
696 :
697 : ! Read the input section with the Quickstep control parameters
698 6686 : CALL read_qs_section(dft_control%qs_control, qs_section)
699 :
700 : ! *** Print the Quickstep program banner (copyright and version number) ***
701 6686 : IF (.NOT. be_silent) THEN
702 6684 : iw = cp_print_key_unit_nr(logger, dft_section, "PRINT%PROGRAM_BANNER", extension=".Log")
703 6684 : CALL section_vals_val_get(qs_section, "METHOD", i_val=method_id)
704 5180 : SELECT CASE (method_id)
705 : CASE DEFAULT
706 5180 : CALL qs_header(iw)
707 : CASE (do_method_rm1, do_method_am1, do_method_mndo, do_method_pdg, &
708 : do_method_pm3, do_method_pm6, do_method_pm6fm, do_method_mndod, do_method_pnnl)
709 998 : CALL se_header(iw)
710 : CASE (do_method_dftb)
711 222 : CALL dftb_header(iw)
712 : CASE (do_method_xtb)
713 284 : gfn_type = dft_control%qs_control%xtb_control%gfn_type
714 6684 : CALL xtb_header(iw, gfn_type)
715 : END SELECT
716 : CALL cp_print_key_finished_output(iw, logger, dft_section, &
717 6684 : "PRINT%PROGRAM_BANNER")
718 : END IF
719 :
720 6686 : IF (dft_control%do_sccs .AND. dft_control%qs_control%gapw) THEN
721 0 : CPABORT("SCCS is not yet implemented with GAPW")
722 : END IF
723 6686 : CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints)
724 6686 : IF (do_kpoints) THEN
725 : ! reset some of the settings for wfn extrapolation for kpoints
726 258 : SELECT CASE (dft_control%qs_control%wf_interpolation_method_nr)
727 : CASE (wfi_linear_wf_method_nr, wfi_linear_ps_method_nr, wfi_ps_method_nr, wfi_aspc_nr)
728 160 : dft_control%qs_control%wf_interpolation_method_nr = wfi_use_guess_method_nr
729 : END SELECT
730 : END IF
731 :
732 : ! ******* check if any kind of electron transfer calculation has to be performed
733 6686 : CALL section_vals_val_get(et_coupling_section, "TYPE_OF_CONSTRAINT", i_val=my_ival)
734 6686 : dft_control%qs_control%et_coupling_calc = .FALSE.
735 6686 : IF (my_ival == do_et_ddapc) THEN
736 0 : et_ddapc_section => section_vals_get_subs_vals(et_coupling_section, "DDAPC_RESTRAINT_A")
737 0 : dft_control%qs_control%et_coupling_calc = .TRUE.
738 0 : dft_control%qs_control%ddapc_restraint = .TRUE.
739 0 : CALL read_ddapc_section(dft_control%qs_control, ddapc_restraint_section=et_ddapc_section)
740 : END IF
741 :
742 6686 : CALL read_mgrid_section(dft_control%qs_control, dft_section)
743 :
744 : ! reimplemented TDDFPT
745 6686 : CALL read_tddfpt2_control(dft_control%tddfpt2_control, tddfpt_section, dft_control%qs_control)
746 :
747 : ! Create relativistic control section
748 : BLOCK
749 : TYPE(rel_control_type), POINTER :: rel_control
750 6686 : ALLOCATE (rel_control)
751 6686 : CALL rel_c_create(rel_control)
752 6686 : CALL rel_c_read_parameters(rel_control, dft_section)
753 6686 : CALL set_qs_env(qs_env, rel_control=rel_control)
754 : END BLOCK
755 :
756 : ! *** Read DFTB parameter files ***
757 6686 : IF (dft_control%qs_control%method_id == do_method_dftb) THEN
758 222 : NULLIFY (ewald_env, ewald_pw, dftb_potential)
759 222 : dftb_control => dft_control%qs_control%dftb_control
760 : CALL qs_dftb_param_init(atomic_kind_set, qs_kind_set, dftb_control, dftb_potential, &
761 222 : subsys_section=subsys_section, para_env=para_env)
762 222 : CALL set_qs_env(qs_env, dftb_potential=dftb_potential)
763 : ! check for Ewald
764 222 : IF (dftb_control%do_ewald) THEN
765 1888 : ALLOCATE (ewald_env)
766 118 : CALL ewald_env_create(ewald_env, para_env)
767 118 : poisson_section => section_vals_get_subs_vals(dft_section, "POISSON")
768 118 : CALL ewald_env_set(ewald_env, poisson_section=poisson_section)
769 118 : ewald_section => section_vals_get_subs_vals(poisson_section, "EWALD")
770 118 : print_section => section_vals_get_subs_vals(qs_env%input, "PRINT%GRID_INFORMATION")
771 118 : CALL get_qs_kind_set(qs_kind_set, basis_rcut=ewald_rcut)
772 118 : CALL read_ewald_section_tb(ewald_env, ewald_section, cell_ref%hmat)
773 118 : ALLOCATE (ewald_pw)
774 118 : CALL ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, print_section=print_section)
775 118 : CALL set_qs_env(qs_env, ewald_env=ewald_env, ewald_pw=ewald_pw)
776 : END IF
777 6464 : ELSEIF (dft_control%qs_control%method_id == do_method_xtb) THEN
778 : ! *** Read xTB parameter file ***
779 284 : xtb_control => dft_control%qs_control%xtb_control
780 284 : NULLIFY (ewald_env, ewald_pw)
781 284 : CALL get_qs_env(qs_env, nkind=nkind)
782 976 : DO ikind = 1, nkind
783 692 : qs_kind => qs_kind_set(ikind)
784 : ! Setup proper xTB parameters
785 692 : CPASSERT(.NOT. ASSOCIATED(qs_kind%xtb_parameter))
786 692 : CALL allocate_xtb_atom_param(qs_kind%xtb_parameter)
787 : ! Set default parameters
788 692 : gfn_type = dft_control%qs_control%xtb_control%gfn_type
789 692 : CALL get_qs_kind(qs_kind, element_symbol=element_symbol)
790 : CALL xtb_parameters_init(qs_kind%xtb_parameter, gfn_type, element_symbol, &
791 : xtb_control%parameter_file_path, xtb_control%parameter_file_name, &
792 692 : para_env)
793 : ! set dependent parameters
794 692 : CALL xtb_parameters_set(qs_kind%xtb_parameter)
795 : ! Generate basis set
796 692 : NULLIFY (tmp_basis_set)
797 692 : IF (qs_kind%xtb_parameter%z == 1) THEN
798 : ! special case hydrogen
799 254 : ngauss = xtb_control%h_sto_ng
800 : ELSE
801 438 : ngauss = xtb_control%sto_ng
802 : END IF
803 692 : IF (qs_kind%xtb_parameter%defined) THEN
804 690 : CALL init_xtb_basis(qs_kind%xtb_parameter, tmp_basis_set, ngauss)
805 690 : CALL add_basis_set_to_container(qs_kind%basis_sets, tmp_basis_set, "ORB")
806 : ELSE
807 2 : CALL set_qs_kind(qs_kind, ghost=.TRUE.)
808 2 : IF (ASSOCIATED(qs_kind%all_potential)) THEN
809 2 : DEALLOCATE (qs_kind%all_potential%elec_conf)
810 2 : DEALLOCATE (qs_kind%all_potential)
811 : END IF
812 : END IF
813 : ! potential
814 976 : IF (qs_kind%xtb_parameter%defined) THEN
815 690 : zeff_correction = 0.0_dp
816 : CALL init_potential(qs_kind%all_potential, itype="BARE", &
817 690 : zeff=qs_kind%xtb_parameter%zeff, zeff_correction=zeff_correction)
818 690 : CALL get_potential(qs_kind%all_potential, alpha_core_charge=alpha)
819 690 : ccore = qs_kind%xtb_parameter%zeff*SQRT((alpha/pi)**3)
820 690 : CALL set_potential(qs_kind%all_potential, ccore_charge=ccore)
821 690 : qs_kind%xtb_parameter%zeff = qs_kind%xtb_parameter%zeff - zeff_correction
822 : END IF
823 : END DO
824 : !
825 : ! set repulsive potential range
826 : !
827 1136 : ALLOCATE (xtb_control%rcpair(nkind, nkind))
828 284 : CALL xtb_pp_radius(qs_kind_set, xtb_control%rcpair, xtb_control%eps_pair, xtb_control%kf)
829 : ! check for Ewald
830 284 : IF (xtb_control%do_ewald) THEN
831 2368 : ALLOCATE (ewald_env)
832 148 : CALL ewald_env_create(ewald_env, para_env)
833 148 : poisson_section => section_vals_get_subs_vals(dft_section, "POISSON")
834 148 : CALL ewald_env_set(ewald_env, poisson_section=poisson_section)
835 148 : ewald_section => section_vals_get_subs_vals(poisson_section, "EWALD")
836 148 : print_section => section_vals_get_subs_vals(qs_env%input, "PRINT%GRID_INFORMATION")
837 148 : IF (gfn_type == 0) THEN
838 20 : CALL read_ewald_section_tb(ewald_env, ewald_section, cell_ref%hmat, pset="EEQ")
839 : ELSE
840 128 : CALL read_ewald_section_tb(ewald_env, ewald_section, cell_ref%hmat)
841 : END IF
842 148 : ALLOCATE (ewald_pw)
843 148 : CALL ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, print_section=print_section)
844 148 : CALL set_qs_env(qs_env, ewald_env=ewald_env, ewald_pw=ewald_pw)
845 : END IF
846 : END IF
847 :
848 : ! lri or ri env initialization
849 6686 : lri_section => section_vals_get_subs_vals(qs_section, "LRIGPW")
850 : IF (dft_control%qs_control%method_id == do_method_lrigpw .OR. &
851 6686 : dft_control%qs_control%lri_optbas .OR. &
852 : dft_control%qs_control%method_id == do_method_rigpw) THEN
853 46 : CALL lri_env_init(lri_env, lri_section)
854 46 : CALL set_qs_env(qs_env, lri_env=lri_env)
855 : END IF
856 :
857 : ! *** Check basis and fill in missing parts ***
858 6686 : CALL check_qs_kind_set(qs_kind_set, dft_control, subsys_section=subsys_section)
859 :
860 : ! *** Check that no all-electron potential is present if GPW or GAPW_XC
861 6686 : CALL get_qs_kind_set(qs_kind_set, all_potential_present=all_potential_present)
862 : IF ((dft_control%qs_control%method_id == do_method_gpw) .OR. &
863 6686 : (dft_control%qs_control%method_id == do_method_gapw_xc) .OR. &
864 : (dft_control%qs_control%method_id == do_method_ofgpw)) THEN
865 4328 : IF (all_potential_present) THEN
866 0 : CPABORT("All-electron calculations with GPW, GAPW_XC, and OFGPW are not implemented")
867 : END IF
868 : END IF
869 :
870 : ! DFT+U
871 6686 : CALL get_qs_kind_set(qs_kind_set, dft_plus_u_atom_present=dft_control%dft_plus_u)
872 :
873 6686 : IF (dft_control%do_admm) THEN
874 : ! Check if ADMM basis is available
875 442 : CALL get_qs_env(qs_env, nkind=nkind)
876 1254 : DO ikind = 1, nkind
877 812 : NULLIFY (aux_fit_basis)
878 812 : qs_kind => qs_kind_set(ikind)
879 812 : CALL get_qs_kind(qs_kind, basis_set=aux_fit_basis, basis_type="AUX_FIT")
880 1254 : IF (.NOT. (ASSOCIATED(aux_fit_basis))) THEN
881 : ! AUX_FIT basis set is not available
882 0 : CPABORT("AUX_FIT basis set is not defined. ")
883 : END IF
884 : END DO
885 : END IF
886 :
887 6686 : lribas = .FALSE.
888 6686 : e1terms = .FALSE.
889 6686 : IF (dft_control%qs_control%method_id == do_method_lrigpw) THEN
890 40 : lribas = .TRUE.
891 40 : CALL get_qs_env(qs_env, lri_env=lri_env)
892 40 : e1terms = lri_env%exact_1c_terms
893 : END IF
894 6686 : IF (dft_control%qs_control%do_kg) THEN
895 66 : CALL section_vals_val_get(dft_section, "KG_METHOD%TNADD_METHOD", i_val=tnadd_method)
896 66 : IF (tnadd_method == kg_tnadd_embed_ri) lribas = .TRUE.
897 : END IF
898 6684 : IF (lribas) THEN
899 : ! Check if LRI_AUX basis is available, auto-generate if needed
900 42 : CALL get_qs_env(qs_env, nkind=nkind)
901 122 : DO ikind = 1, nkind
902 80 : NULLIFY (lri_aux_basis)
903 80 : qs_kind => qs_kind_set(ikind)
904 80 : CALL get_qs_kind(qs_kind, basis_set=lri_aux_basis, basis_type="LRI_AUX")
905 122 : IF (.NOT. (ASSOCIATED(lri_aux_basis))) THEN
906 : ! LRI_AUX basis set is not yet loaded
907 : CALL cp_warn(__LOCATION__, "Automatic Generation of LRI_AUX basis. "// &
908 18 : "This is experimental code.")
909 : ! Generate a default basis
910 18 : CALL create_lri_aux_basis_set(lri_aux_basis, qs_kind, dft_control%auto_basis_lri_aux, e1terms)
911 18 : CALL add_basis_set_to_container(qs_kind%basis_sets, lri_aux_basis, "LRI_AUX")
912 : END IF
913 : END DO
914 : END IF
915 :
916 6686 : CALL section_vals_val_get(qs_env%input, "DFT%XC%HF%RI%_SECTION_PARAMETERS_", l_val=do_ri_hfx)
917 : CALL section_vals_val_get(qs_env%input, "DFT%XC%WF_CORRELATION%RI_RPA%HF%RI%_SECTION_PARAMETERS_", &
918 6686 : l_val=do_rpa_ri_exx)
919 6686 : IF (do_ri_hfx .OR. do_rpa_ri_exx) THEN
920 100 : CALL get_qs_env(qs_env, nkind=nkind)
921 100 : CALL section_vals_val_get(qs_env%input, "DFT%SORT_BASIS", i_val=sort_basis)
922 270 : DO ikind = 1, nkind
923 170 : NULLIFY (ri_hfx_basis)
924 170 : qs_kind => qs_kind_set(ikind)
925 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=ri_hfx_basis, &
926 170 : basis_type="RI_HFX")
927 6856 : IF (.NOT. (ASSOCIATED(ri_hfx_basis))) THEN
928 166 : CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto)
929 166 : IF (dft_control%do_admm) THEN
930 : CALL create_ri_aux_basis_set(ri_hfx_basis, qs_kind, dft_control%auto_basis_ri_hfx, &
931 56 : basis_type="AUX_FIT", basis_sort=sort_basis)
932 : ELSE
933 : CALL create_ri_aux_basis_set(ri_hfx_basis, qs_kind, dft_control%auto_basis_ri_hfx, &
934 110 : basis_sort=sort_basis)
935 : END IF
936 166 : CALL add_basis_set_to_container(qs_kind%basis_sets, ri_hfx_basis, "RI_HFX")
937 : END IF
938 : END DO
939 : END IF
940 :
941 6686 : IF (dft_control%qs_control%method_id == do_method_rigpw) THEN
942 : ! Check if RI_HXC basis is available, auto-generate if needed
943 0 : CALL get_qs_env(qs_env, nkind=nkind)
944 0 : DO ikind = 1, nkind
945 0 : NULLIFY (ri_hfx_basis)
946 0 : qs_kind => qs_kind_set(ikind)
947 0 : CALL get_qs_kind(qs_kind, basis_set=ri_hfx_basis, basis_type="RI_HXC")
948 0 : IF (.NOT. (ASSOCIATED(ri_hfx_basis))) THEN
949 : ! Generate a default basis
950 0 : CALL create_ri_aux_basis_set(ri_hfx_basis, qs_kind, dft_control%auto_basis_ri_hxc)
951 0 : CALL add_basis_set_to_container(qs_kind%basis_sets, ri_hfx_basis, "RI_HXC")
952 : END IF
953 : END DO
954 : END IF
955 :
956 : ! Harris method
957 6686 : NULLIFY (harris_env)
958 : CALL section_vals_val_get(dft_section, "HARRIS_METHOD%_SECTION_PARAMETERS_", &
959 6686 : l_val=qs_env%harris_method)
960 6686 : harris_section => section_vals_get_subs_vals(dft_section, "HARRIS_METHOD")
961 6686 : CALL harris_env_create(qs_env, harris_env, harris_section)
962 6686 : CALL set_qs_env(qs_env, harris_env=harris_env)
963 : !
964 6686 : IF (qs_env%harris_method) THEN
965 6 : CALL get_qs_env(qs_env, nkind=nkind)
966 : ! Check if RI_HXC basis is available, auto-generate if needed
967 22 : DO ikind = 1, nkind
968 16 : NULLIFY (tmp_basis_set)
969 16 : qs_kind => qs_kind_set(ikind)
970 16 : CALL get_qs_kind(qs_kind, basis_set=rhoin_basis, basis_type="RHOIN")
971 22 : IF (.NOT. (ASSOCIATED(rhoin_basis))) THEN
972 : ! Generate a default basis
973 16 : CALL create_ri_aux_basis_set(tmp_basis_set, qs_kind, dft_control%auto_basis_ri_hxc)
974 16 : IF (qs_env%harris_env%density_source == hden_atomic) THEN
975 16 : CALL create_primitive_basis_set(tmp_basis_set, rhoin_basis, lmax=0)
976 16 : CALL deallocate_gto_basis_set(tmp_basis_set)
977 : ELSE
978 0 : rhoin_basis => tmp_basis_set
979 : END IF
980 16 : CALL add_basis_set_to_container(qs_kind%basis_sets, rhoin_basis, "RHOIN")
981 : END IF
982 : END DO
983 : END IF
984 :
985 6686 : mp2_section => section_vals_get_subs_vals(qs_env%input, "DFT%XC%WF_CORRELATION")
986 6686 : CALL section_vals_get(mp2_section, explicit=mp2_present)
987 6686 : IF (mp2_present) THEN
988 :
989 : ! basis should be sorted for imaginary time RPA/GW
990 466 : CALL section_vals_val_get(qs_env%input, "DFT%SORT_BASIS", i_val=sort_basis)
991 : CALL section_vals_val_get(qs_env%input, "DFT%XC%WF_CORRELATION%LOW_SCALING%_SECTION_PARAMETERS_", &
992 466 : l_val=do_wfc_im_time)
993 :
994 466 : IF (do_wfc_im_time .AND. sort_basis /= basis_sort_zet) THEN
995 : CALL cp_warn(__LOCATION__, &
996 10 : "Low-scaling RPA requires SORT_BASIS EXP keyword (in DFT input section) for good performance")
997 : END IF
998 :
999 : ! Check if RI_AUX basis (for MP2/RPA) is given, auto-generate if not
1000 466 : CALL mp2_env_create(qs_env%mp2_env)
1001 466 : CALL get_qs_env(qs_env, mp2_env=mp2_env, nkind=nkind)
1002 466 : CALL section_vals_val_get(qs_env%input, "DFT%XC%WF_CORRELATION%RI_MP2%_SECTION_PARAMETERS_", l_val=do_ri_mp2)
1003 466 : CALL section_vals_val_get(qs_env%input, "DFT%XC%WF_CORRELATION%RI_SOS_MP2%_SECTION_PARAMETERS_", l_val=do_ri_sos_mp2)
1004 466 : CALL section_vals_val_get(qs_env%input, "DFT%XC%WF_CORRELATION%RI_RPA%_SECTION_PARAMETERS_", l_val=do_ri_rpa)
1005 466 : IF (do_ri_mp2 .OR. do_ri_sos_mp2 .OR. do_ri_rpa) THEN
1006 1254 : DO ikind = 1, nkind
1007 826 : NULLIFY (ri_aux_basis_set)
1008 826 : qs_kind => qs_kind_set(ikind)
1009 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=ri_aux_basis_set, &
1010 826 : basis_type="RI_AUX")
1011 1292 : IF (.NOT. (ASSOCIATED(ri_aux_basis_set))) THEN
1012 : ! RI_AUX basis set is not yet loaded
1013 : ! Generate a default basis
1014 8 : CALL create_ri_aux_basis_set(ri_aux_basis_set, qs_kind, dft_control%auto_basis_ri_aux, basis_sort=sort_basis)
1015 8 : CALL add_basis_set_to_container(qs_kind%basis_sets, ri_aux_basis_set, "RI_AUX")
1016 : END IF
1017 : END DO
1018 : END IF
1019 :
1020 : END IF
1021 :
1022 6686 : IF (dft_control%do_xas_tdp_calculation) THEN
1023 : ! Check if RI_XAS basis is given, auto-generate if not
1024 50 : CALL get_qs_env(qs_env, nkind=nkind)
1025 128 : DO ikind = 1, nkind
1026 78 : NULLIFY (ri_xas_basis)
1027 78 : qs_kind => qs_kind_set(ikind)
1028 78 : CALL get_qs_kind(qs_kind, basis_Set=ri_xas_basis, basis_type="RI_XAS")
1029 128 : IF (.NOT. ASSOCIATED(ri_xas_basis)) THEN
1030 : ! Generate a default basis
1031 76 : CALL create_ri_aux_basis_set(ri_xas_basis, qs_kind, dft_control%auto_basis_ri_xas)
1032 76 : CALL add_basis_set_to_container(qs_kind%basis_sets, ri_xas_basis, "RI_XAS")
1033 : END IF
1034 : END DO
1035 : END IF
1036 :
1037 : ! *** Initialize the spherical harmonics and ***
1038 : ! *** the orbital transformation matrices ***
1039 6686 : CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto, maxlppl=maxlppl, maxlppnl=maxlppnl)
1040 :
1041 6686 : lmax_sphere = dft_control%qs_control%gapw_control%lmax_sphere
1042 6686 : IF (lmax_sphere .LT. 0) THEN
1043 6568 : lmax_sphere = 2*maxlgto
1044 6568 : dft_control%qs_control%gapw_control%lmax_sphere = lmax_sphere
1045 : END IF
1046 6686 : IF (dft_control%qs_control%method_id == do_method_lrigpw .OR. dft_control%qs_control%lri_optbas) THEN
1047 46 : CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto_lri, basis_type="LRI_AUX")
1048 : !take maxlgto from lri basis if larger (usually)
1049 46 : maxlgto = MAX(maxlgto, maxlgto_lri)
1050 6640 : ELSE IF (dft_control%qs_control%method_id == do_method_rigpw) THEN
1051 0 : CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto_lri, basis_type="RI_HXC")
1052 0 : maxlgto = MAX(maxlgto, maxlgto_lri)
1053 : END IF
1054 6686 : IF (dft_control%do_xas_tdp_calculation) THEN
1055 : !done as a precaution
1056 50 : CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto_lri, basis_type="RI_XAS")
1057 50 : maxlgto = MAX(maxlgto, maxlgto_lri)
1058 : END IF
1059 6686 : maxl = MAX(2*maxlgto, maxlppl, maxlppnl, lmax_sphere) + 1
1060 :
1061 6686 : CALL init_orbital_pointers(maxl)
1062 :
1063 6686 : CALL init_spherical_harmonics(maxl, 0)
1064 :
1065 : ! *** Initialise the qs_kind_set ***
1066 6686 : CALL init_qs_kind_set(qs_kind_set)
1067 :
1068 : ! *** Initialise GAPW soft basis and projectors
1069 6686 : IF (dft_control%qs_control%method_id == do_method_gapw .OR. &
1070 : dft_control%qs_control%method_id == do_method_gapw_xc) THEN
1071 920 : qs_control => dft_control%qs_control
1072 920 : CALL init_gapw_basis_set(qs_kind_set, qs_control, qs_env%input)
1073 : END IF
1074 :
1075 : ! *** Initialize the pretabulation for the calculation of the ***
1076 : ! *** incomplete Gamma function F_n(t) after McMurchie-Davidson ***
1077 6686 : CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto)
1078 6686 : maxl = MAX(3*maxlgto + 1, 0)
1079 6686 : CALL init_md_ftable(maxl)
1080 :
1081 : ! *** Initialize the atomic interaction radii ***
1082 6686 : CALL init_interaction_radii(dft_control%qs_control, qs_kind_set)
1083 : !
1084 6686 : IF (dft_control%qs_control%method_id == do_method_xtb) THEN
1085 : ! cutoff radius
1086 976 : DO ikind = 1, nkind
1087 692 : qs_kind => qs_kind_set(ikind)
1088 976 : IF (qs_kind%xtb_parameter%defined) THEN
1089 690 : CALL get_qs_kind(qs_kind, basis_set=tmp_basis_set)
1090 690 : rcut = xtb_control%coulomb_sr_cut
1091 690 : fxx = 2.0_dp*xtb_control%coulomb_sr_eps*qs_kind%xtb_parameter%eta**2
1092 690 : fxx = 0.80_dp*(1.0_dp/fxx)**0.3333_dp
1093 690 : rcut = MIN(rcut, xtb_control%coulomb_sr_cut)
1094 690 : qs_kind%xtb_parameter%rcut = MIN(rcut, fxx)
1095 : ELSE
1096 2 : qs_kind%xtb_parameter%rcut = 0.0_dp
1097 : END IF
1098 : END DO
1099 : END IF
1100 :
1101 6686 : IF (.NOT. be_silent) THEN
1102 6684 : CALL write_pgf_orb_radii("orb", atomic_kind_set, qs_kind_set, subsys_section)
1103 6684 : CALL write_pgf_orb_radii("aux", atomic_kind_set, qs_kind_set, subsys_section)
1104 6684 : CALL write_pgf_orb_radii("lri", atomic_kind_set, qs_kind_set, subsys_section)
1105 6684 : CALL write_core_charge_radii(atomic_kind_set, qs_kind_set, subsys_section)
1106 6684 : CALL write_ppl_radii(atomic_kind_set, qs_kind_set, subsys_section)
1107 6684 : CALL write_ppnl_radii(atomic_kind_set, qs_kind_set, subsys_section)
1108 6684 : CALL write_paw_radii(atomic_kind_set, qs_kind_set, subsys_section)
1109 : END IF
1110 :
1111 : ! *** Distribute molecules and atoms using the new data structures ***
1112 : CALL distribute_molecules_1d(atomic_kind_set=atomic_kind_set, &
1113 : particle_set=particle_set, &
1114 : local_particles=local_particles, &
1115 : molecule_kind_set=molecule_kind_set, &
1116 : molecule_set=molecule_set, &
1117 : local_molecules=local_molecules, &
1118 6686 : force_env_section=qs_env%input)
1119 :
1120 : ! *** SCF parameters ***
1121 193894 : ALLOCATE (scf_control)
1122 : ! set (non)-self consistency
1123 6686 : IF (dft_control%qs_control%dftb) THEN
1124 222 : scf_control%non_selfconsistent = .NOT. dft_control%qs_control%dftb_control%self_consistent
1125 : END IF
1126 6686 : IF (dft_control%qs_control%xtb) THEN
1127 284 : scf_control%non_selfconsistent = (dft_control%qs_control%xtb_control%gfn_type == 0)
1128 : END IF
1129 6686 : IF (qs_env%harris_method) THEN
1130 6 : scf_control%non_selfconsistent = .TRUE.
1131 : END IF
1132 6686 : CALL scf_c_create(scf_control)
1133 6686 : CALL scf_c_read_parameters(scf_control, dft_section)
1134 : ! *** Allocate the data structure for Quickstep energies ***
1135 6686 : CALL allocate_qs_energy(energy)
1136 :
1137 : ! check for orthogonal basis
1138 6686 : has_unit_metric = .FALSE.
1139 6686 : IF (dft_control%qs_control%semi_empirical) THEN
1140 998 : IF (dft_control%qs_control%se_control%orthogonal_basis) has_unit_metric = .TRUE.
1141 : END IF
1142 6686 : IF (dft_control%qs_control%dftb) THEN
1143 222 : IF (dft_control%qs_control%dftb_control%orthogonal_basis) has_unit_metric = .TRUE.
1144 : END IF
1145 6686 : CALL set_qs_env(qs_env, has_unit_metric=has_unit_metric)
1146 :
1147 : ! *** Activate the interpolation ***
1148 : CALL wfi_create(wf_history, &
1149 : interpolation_method_nr= &
1150 : dft_control%qs_control%wf_interpolation_method_nr, &
1151 : extrapolation_order=dft_control%qs_control%wf_extrapolation_order, &
1152 6686 : has_unit_metric=has_unit_metric)
1153 :
1154 : ! *** Set the current Quickstep environment ***
1155 : CALL set_qs_env(qs_env=qs_env, &
1156 : scf_control=scf_control, &
1157 6686 : wf_history=wf_history)
1158 :
1159 : CALL qs_subsys_set(subsys, &
1160 : cell_ref=cell_ref, &
1161 : use_ref_cell=use_ref_cell, &
1162 : energy=energy, &
1163 6686 : force=force)
1164 :
1165 6686 : CALL get_qs_env(qs_env, ks_env=ks_env)
1166 6686 : CALL set_ks_env(ks_env, dft_control=dft_control)
1167 :
1168 : CALL qs_subsys_set(subsys, local_molecules=local_molecules, &
1169 6686 : local_particles=local_particles, cell=cell)
1170 :
1171 6686 : CALL distribution_1d_release(local_particles)
1172 6686 : CALL distribution_1d_release(local_molecules)
1173 6686 : CALL wfi_release(wf_history)
1174 :
1175 : CALL get_qs_env(qs_env=qs_env, &
1176 : atomic_kind_set=atomic_kind_set, &
1177 : dft_control=dft_control, &
1178 6686 : scf_control=scf_control)
1179 :
1180 : ! decide what conditions need mo_derivs
1181 : ! right now, this only appears to be OT
1182 6686 : IF (dft_control%qs_control%do_ls_scf .OR. &
1183 : dft_control%qs_control%do_almo_scf) THEN
1184 410 : CALL set_qs_env(qs_env=qs_env, requires_mo_derivs=.FALSE.)
1185 : ELSE
1186 6276 : IF (scf_control%use_ot) THEN
1187 1996 : CALL set_qs_env(qs_env=qs_env, requires_mo_derivs=.TRUE.)
1188 : ELSE
1189 4280 : CALL set_qs_env(qs_env=qs_env, requires_mo_derivs=.FALSE.)
1190 : END IF
1191 : END IF
1192 :
1193 : ! XXXXXXX this is backwards XXXXXXXX
1194 6686 : dft_control%smear = scf_control%smear%do_smear
1195 :
1196 : ! Periodic efield needs equal occupation and orbital gradients
1197 6686 : IF (.NOT. (dft_control%qs_control%dftb .OR. dft_control%qs_control%xtb)) THEN
1198 6180 : IF (dft_control%apply_period_efield) THEN
1199 26 : CALL get_qs_env(qs_env=qs_env, requires_mo_derivs=orb_gradient)
1200 26 : IF (.NOT. orb_gradient) THEN
1201 : CALL cp_abort(__LOCATION__, "Periodic Efield needs orbital gradient and direct optimization."// &
1202 0 : " Use the OT optimization method.")
1203 : END IF
1204 26 : IF (dft_control%smear) THEN
1205 : CALL cp_abort(__LOCATION__, "Periodic Efield needs equal occupation numbers."// &
1206 0 : " Smearing option is not possible.")
1207 : END IF
1208 : END IF
1209 : END IF
1210 :
1211 : ! Initialize the GAPW local densities and potentials
1212 6686 : IF (dft_control%qs_control%method_id == do_method_gapw .OR. &
1213 : dft_control%qs_control%method_id == do_method_gapw_xc) THEN
1214 : ! *** Allocate and initialize the set of atomic densities ***
1215 920 : NULLIFY (rho_atom_set)
1216 920 : gapw_control => dft_control%qs_control%gapw_control
1217 920 : CALL init_rho_atom(rho_atom_set, atomic_kind_set, qs_kind_set, dft_control, para_env)
1218 920 : CALL set_qs_env(qs_env=qs_env, rho_atom_set=rho_atom_set)
1219 920 : IF (dft_control%qs_control%method_id /= do_method_gapw_xc) THEN
1220 814 : CALL get_qs_env(qs_env=qs_env, local_rho_set=local_rho_set, natom=natom)
1221 : ! *** Allocate and initialize the compensation density rho0 ***
1222 814 : CALL init_rho0(local_rho_set, qs_env, gapw_control)
1223 : ! *** Allocate and Initialize the local coulomb term ***
1224 814 : CALL init_coulomb_local(qs_env%hartree_local, natom)
1225 : END IF
1226 : ! NLCC
1227 920 : CALL init_gapw_nlcc(qs_kind_set)
1228 5766 : ELSE IF (dft_control%qs_control%method_id == do_method_lrigpw) THEN
1229 : ! allocate local ri environment
1230 : ! nothing to do here?
1231 5726 : ELSE IF (dft_control%qs_control%method_id == do_method_rigpw) THEN
1232 : ! allocate ri environment
1233 : ! nothing to do here?
1234 5726 : ELSE IF (dft_control%qs_control%semi_empirical) THEN
1235 998 : NULLIFY (se_store_int_env, se_nddo_mpole, se_nonbond_env)
1236 998 : natom = SIZE(particle_set)
1237 998 : se_section => section_vals_get_subs_vals(qs_section, "SE")
1238 998 : se_control => dft_control%qs_control%se_control
1239 :
1240 : ! Make the cutoff radii choice a bit smarter
1241 998 : CALL se_cutoff_compatible(se_control, se_section, cell, output_unit)
1242 :
1243 1994 : SELECT CASE (dft_control%qs_control%method_id)
1244 : CASE DEFAULT
1245 : CASE (do_method_rm1, do_method_am1, do_method_mndo, do_method_pm3, &
1246 : do_method_pm6, do_method_pm6fm, do_method_mndod, do_method_pnnl)
1247 : ! Neighbor lists have to be MAX(interaction range, orbital range)
1248 : ! set new kind radius
1249 998 : CALL init_se_nlradius(se_control, atomic_kind_set, qs_kind_set, subsys_section)
1250 : END SELECT
1251 : ! Initialize to zero the max multipole to treat in the EWALD scheme..
1252 998 : se_control%max_multipole = do_multipole_none
1253 : ! check for Ewald
1254 998 : IF (se_control%do_ewald .OR. se_control%do_ewald_gks) THEN
1255 512 : ALLOCATE (ewald_env)
1256 32 : CALL ewald_env_create(ewald_env, para_env)
1257 32 : poisson_section => section_vals_get_subs_vals(dft_section, "POISSON")
1258 32 : CALL ewald_env_set(ewald_env, poisson_section=poisson_section)
1259 32 : ewald_section => section_vals_get_subs_vals(poisson_section, "EWALD")
1260 : print_section => section_vals_get_subs_vals(qs_env%input, &
1261 32 : "PRINT%GRID_INFORMATION")
1262 32 : CALL read_ewald_section(ewald_env, ewald_section)
1263 : ! Create ewald grids
1264 32 : ALLOCATE (ewald_pw)
1265 : CALL ewald_pw_create(ewald_pw, ewald_env, cell, cell_ref, &
1266 32 : print_section=print_section)
1267 : ! Initialize ewald grids
1268 32 : CALL ewald_pw_grid_update(ewald_pw, ewald_env, cell%hmat)
1269 : ! Setup the nonbond environment (real space part of Ewald)
1270 32 : CALL ewald_env_get(ewald_env, rcut=ewald_rcut)
1271 : ! Setup the maximum level of multipoles to be treated in the periodic SE scheme
1272 32 : IF (se_control%do_ewald) THEN
1273 30 : CALL ewald_env_get(ewald_env, max_multipole=se_control%max_multipole)
1274 : END IF
1275 : CALL section_vals_val_get(se_section, "NEIGHBOR_LISTS%VERLET_SKIN", &
1276 32 : r_val=verlet_skin)
1277 32 : ALLOCATE (se_nonbond_env)
1278 : CALL fist_nonbond_env_create(se_nonbond_env, atomic_kind_set, do_nonbonded=.TRUE., &
1279 : do_electrostatics=.TRUE., verlet_skin=verlet_skin, ewald_rcut=ewald_rcut, &
1280 32 : ei_scale14=0.0_dp, vdw_scale14=0.0_dp, shift_cutoff=.FALSE.)
1281 : ! Create and Setup NDDO multipole environment
1282 32 : CALL nddo_mpole_setup(se_nddo_mpole, natom)
1283 : CALL set_qs_env(qs_env, ewald_env=ewald_env, ewald_pw=ewald_pw, &
1284 32 : se_nonbond_env=se_nonbond_env, se_nddo_mpole=se_nddo_mpole)
1285 : ! Handle the residual integral part 1/R^3
1286 : CALL semi_empirical_expns3_setup(qs_kind_set, se_control, &
1287 32 : dft_control%qs_control%method_id)
1288 : END IF
1289 : ! Taper function
1290 : CALL se_taper_create(se_taper, se_control%integral_screening, se_control%do_ewald, &
1291 : se_control%taper_cou, se_control%range_cou, &
1292 : se_control%taper_exc, se_control%range_exc, &
1293 : se_control%taper_scr, se_control%range_scr, &
1294 998 : se_control%taper_lrc, se_control%range_lrc)
1295 998 : CALL set_qs_env(qs_env, se_taper=se_taper)
1296 : ! Store integral environment
1297 998 : CALL semi_empirical_si_create(se_store_int_env, se_section)
1298 998 : CALL set_qs_env(qs_env, se_store_int_env=se_store_int_env)
1299 : END IF
1300 :
1301 : ! Initialize possible dispersion parameters
1302 : IF (dft_control%qs_control%method_id == do_method_gpw .OR. &
1303 : dft_control%qs_control%method_id == do_method_gapw .OR. &
1304 : dft_control%qs_control%method_id == do_method_gapw_xc .OR. &
1305 : dft_control%qs_control%method_id == do_method_lrigpw .OR. &
1306 6686 : dft_control%qs_control%method_id == do_method_rigpw .OR. &
1307 : dft_control%qs_control%method_id == do_method_ofgpw) THEN
1308 25910 : ALLOCATE (dispersion_env)
1309 5182 : NULLIFY (xc_section)
1310 5182 : xc_section => section_vals_get_subs_vals(dft_section, "XC")
1311 5182 : CALL qs_dispersion_env_set(dispersion_env, xc_section)
1312 5182 : IF (dispersion_env%type == xc_vdw_fun_pairpot) THEN
1313 94 : NULLIFY (pp_section)
1314 94 : pp_section => section_vals_get_subs_vals(xc_section, "VDW_POTENTIAL%PAIR_POTENTIAL")
1315 94 : CALL qs_dispersion_pairpot_init(atomic_kind_set, qs_kind_set, dispersion_env, pp_section, para_env)
1316 5088 : ELSE IF (dispersion_env%type == xc_vdw_fun_nonloc) THEN
1317 46 : NULLIFY (nl_section)
1318 46 : nl_section => section_vals_get_subs_vals(xc_section, "VDW_POTENTIAL%NON_LOCAL")
1319 46 : CALL qs_dispersion_nonloc_init(dispersion_env, para_env)
1320 : END IF
1321 5182 : CALL set_qs_env(qs_env, dispersion_env=dispersion_env)
1322 1504 : ELSE IF (dft_control%qs_control%method_id == do_method_dftb) THEN
1323 1110 : ALLOCATE (dispersion_env)
1324 : ! set general defaults
1325 : dispersion_env%doabc = .FALSE.
1326 : dispersion_env%c9cnst = .FALSE.
1327 : dispersion_env%lrc = .FALSE.
1328 : dispersion_env%srb = .FALSE.
1329 : dispersion_env%verbose = .FALSE.
1330 : NULLIFY (dispersion_env%c6ab, dispersion_env%maxci, dispersion_env%r0ab, dispersion_env%rcov, &
1331 : dispersion_env%r2r4, dispersion_env%cn, dispersion_env%cnkind, dispersion_env%cnlist, &
1332 : dispersion_env%d3_exclude_pair)
1333 : NULLIFY (dispersion_env%q_mesh, dispersion_env%kernel, dispersion_env%d2phi_dk2, &
1334 : dispersion_env%d2y_dx2, dispersion_env%dftd_section)
1335 : NULLIFY (dispersion_env%sab_vdw, dispersion_env%sab_cn)
1336 222 : IF (dftb_control%dispersion .AND. dftb_control%dispersion_type == dispersion_d3) THEN
1337 14 : dispersion_env%type = xc_vdw_fun_pairpot
1338 14 : dispersion_env%pp_type = vdw_pairpot_dftd3
1339 14 : dispersion_env%eps_cn = dftb_control%epscn
1340 14 : dispersion_env%s6 = dftb_control%sd3(1)
1341 14 : dispersion_env%sr6 = dftb_control%sd3(2)
1342 14 : dispersion_env%s8 = dftb_control%sd3(3)
1343 : dispersion_env%domol = .FALSE.
1344 14 : dispersion_env%kgc8 = 0._dp
1345 14 : dispersion_env%rc_disp = dftb_control%rcdisp
1346 14 : dispersion_env%exp_pre = 0._dp
1347 14 : dispersion_env%scaling = 0._dp
1348 14 : dispersion_env%nd3_exclude_pair = 0
1349 14 : dispersion_env%parameter_file_name = dftb_control%dispersion_parameter_file
1350 14 : CALL qs_dispersion_pairpot_init(atomic_kind_set, qs_kind_set, dispersion_env, para_env=para_env)
1351 208 : ELSEIF (dftb_control%dispersion .AND. dftb_control%dispersion_type == dispersion_d3bj) THEN
1352 2 : dispersion_env%type = xc_vdw_fun_pairpot
1353 2 : dispersion_env%pp_type = vdw_pairpot_dftd3bj
1354 2 : dispersion_env%eps_cn = dftb_control%epscn
1355 2 : dispersion_env%s6 = dftb_control%sd3bj(1)
1356 2 : dispersion_env%a1 = dftb_control%sd3bj(2)
1357 2 : dispersion_env%s8 = dftb_control%sd3bj(3)
1358 2 : dispersion_env%a2 = dftb_control%sd3bj(4)
1359 : dispersion_env%domol = .FALSE.
1360 2 : dispersion_env%kgc8 = 0._dp
1361 2 : dispersion_env%rc_disp = dftb_control%rcdisp
1362 2 : dispersion_env%exp_pre = 0._dp
1363 2 : dispersion_env%scaling = 0._dp
1364 2 : dispersion_env%nd3_exclude_pair = 0
1365 2 : dispersion_env%parameter_file_name = dftb_control%dispersion_parameter_file
1366 2 : CALL qs_dispersion_pairpot_init(atomic_kind_set, qs_kind_set, dispersion_env, para_env=para_env)
1367 206 : ELSEIF (dftb_control%dispersion .AND. dftb_control%dispersion_type == dispersion_d2) THEN
1368 2 : dispersion_env%type = xc_vdw_fun_pairpot
1369 2 : dispersion_env%pp_type = vdw_pairpot_dftd2
1370 2 : dispersion_env%exp_pre = dftb_control%exp_pre
1371 2 : dispersion_env%scaling = dftb_control%scaling
1372 2 : dispersion_env%parameter_file_name = dftb_control%dispersion_parameter_file
1373 2 : dispersion_env%rc_disp = dftb_control%rcdisp
1374 2 : CALL qs_dispersion_pairpot_init(atomic_kind_set, qs_kind_set, dispersion_env, para_env=para_env)
1375 : ELSE
1376 204 : dispersion_env%type = xc_vdw_fun_none
1377 : END IF
1378 222 : CALL set_qs_env(qs_env, dispersion_env=dispersion_env)
1379 1282 : ELSE IF (dft_control%qs_control%method_id == do_method_xtb) THEN
1380 1420 : ALLOCATE (dispersion_env)
1381 : ! set general defaults
1382 : dispersion_env%doabc = .FALSE.
1383 : dispersion_env%c9cnst = .FALSE.
1384 : dispersion_env%lrc = .FALSE.
1385 : dispersion_env%srb = .FALSE.
1386 : dispersion_env%verbose = .FALSE.
1387 : NULLIFY (dispersion_env%c6ab, dispersion_env%maxci, &
1388 : dispersion_env%r0ab, dispersion_env%rcov, &
1389 : dispersion_env%r2r4, dispersion_env%cn, &
1390 : dispersion_env%cnkind, dispersion_env%cnlist, &
1391 : dispersion_env%d3_exclude_pair)
1392 : NULLIFY (dispersion_env%q_mesh, dispersion_env%kernel, dispersion_env%d2phi_dk2, &
1393 : dispersion_env%d2y_dx2, dispersion_env%dftd_section)
1394 : NULLIFY (dispersion_env%sab_vdw, dispersion_env%sab_cn)
1395 284 : dispersion_env%type = xc_vdw_fun_pairpot
1396 284 : dispersion_env%eps_cn = xtb_control%epscn
1397 284 : dispersion_env%s6 = xtb_control%s6
1398 284 : dispersion_env%s8 = xtb_control%s8
1399 284 : dispersion_env%a1 = xtb_control%a1
1400 284 : dispersion_env%a2 = xtb_control%a2
1401 : dispersion_env%domol = .FALSE.
1402 284 : dispersion_env%kgc8 = 0._dp
1403 284 : dispersion_env%rc_disp = xtb_control%rcdisp
1404 284 : dispersion_env%rc_d4 = xtb_control%rcdisp
1405 284 : dispersion_env%exp_pre = 0._dp
1406 284 : dispersion_env%scaling = 0._dp
1407 284 : dispersion_env%nd3_exclude_pair = 0
1408 284 : dispersion_env%parameter_file_name = xtb_control%dispersion_parameter_file
1409 : !
1410 564 : SELECT CASE (xtb_control%vdw_type)
1411 : CASE (xtb_vdw_type_none, xtb_vdw_type_d3)
1412 280 : dispersion_env%pp_type = vdw_pairpot_dftd3bj
1413 280 : CALL qs_dispersion_pairpot_init(atomic_kind_set, qs_kind_set, dispersion_env, para_env=para_env)
1414 280 : IF (xtb_control%vdw_type == xtb_vdw_type_none) dispersion_env%type = xc_vdw_fun_none
1415 : CASE (xtb_vdw_type_d4)
1416 4 : dispersion_env%pp_type = vdw_pairpot_dftd4
1417 4 : dispersion_env%ref_functional = "none"
1418 : CALL qs_dispersion_pairpot_init(atomic_kind_set, qs_kind_set, &
1419 4 : dispersion_env, para_env=para_env)
1420 4 : dispersion_env%cnfun = 2
1421 : CASE DEFAULT
1422 284 : CPABORT("vdw type")
1423 : END SELECT
1424 284 : CALL set_qs_env(qs_env, dispersion_env=dispersion_env)
1425 998 : ELSE IF (dft_control%qs_control%semi_empirical) THEN
1426 4990 : ALLOCATE (dispersion_env)
1427 : ! set general defaults
1428 : dispersion_env%doabc = .FALSE.
1429 : dispersion_env%c9cnst = .FALSE.
1430 : dispersion_env%lrc = .FALSE.
1431 : dispersion_env%srb = .FALSE.
1432 : dispersion_env%verbose = .FALSE.
1433 : NULLIFY (dispersion_env%c6ab, dispersion_env%maxci, dispersion_env%r0ab, dispersion_env%rcov, &
1434 : dispersion_env%r2r4, dispersion_env%cn, dispersion_env%cnkind, dispersion_env%cnlist, &
1435 : dispersion_env%d3_exclude_pair)
1436 : NULLIFY (dispersion_env%q_mesh, dispersion_env%kernel, dispersion_env%d2phi_dk2, &
1437 : dispersion_env%d2y_dx2, dispersion_env%dftd_section)
1438 : NULLIFY (dispersion_env%sab_vdw, dispersion_env%sab_cn)
1439 998 : IF (se_control%dispersion) THEN
1440 6 : dispersion_env%type = xc_vdw_fun_pairpot
1441 6 : dispersion_env%pp_type = vdw_pairpot_dftd3
1442 6 : dispersion_env%eps_cn = se_control%epscn
1443 6 : dispersion_env%s6 = se_control%sd3(1)
1444 6 : dispersion_env%sr6 = se_control%sd3(2)
1445 6 : dispersion_env%s8 = se_control%sd3(3)
1446 : dispersion_env%domol = .FALSE.
1447 6 : dispersion_env%kgc8 = 0._dp
1448 6 : dispersion_env%rc_disp = se_control%rcdisp
1449 6 : dispersion_env%exp_pre = 0._dp
1450 6 : dispersion_env%scaling = 0._dp
1451 6 : dispersion_env%nd3_exclude_pair = 0
1452 6 : dispersion_env%parameter_file_name = se_control%dispersion_parameter_file
1453 6 : CALL qs_dispersion_pairpot_init(atomic_kind_set, qs_kind_set, dispersion_env, para_env=para_env)
1454 : ELSE
1455 992 : dispersion_env%type = xc_vdw_fun_none
1456 : END IF
1457 998 : CALL set_qs_env(qs_env, dispersion_env=dispersion_env)
1458 : END IF
1459 :
1460 : ! Initialize possible geomertical counterpoise correction potential
1461 : IF (dft_control%qs_control%method_id == do_method_gpw .OR. &
1462 : dft_control%qs_control%method_id == do_method_gapw .OR. &
1463 : dft_control%qs_control%method_id == do_method_gapw_xc .OR. &
1464 : dft_control%qs_control%method_id == do_method_lrigpw .OR. &
1465 6686 : dft_control%qs_control%method_id == do_method_rigpw .OR. &
1466 : dft_control%qs_control%method_id == do_method_ofgpw) THEN
1467 5182 : ALLOCATE (gcp_env)
1468 5182 : NULLIFY (xc_section)
1469 5182 : xc_section => section_vals_get_subs_vals(dft_section, "XC")
1470 5182 : CALL qs_gcp_env_set(gcp_env, xc_section)
1471 5182 : CALL qs_gcp_init(qs_env, gcp_env)
1472 5182 : CALL set_qs_env(qs_env, gcp_env=gcp_env)
1473 : END IF
1474 :
1475 : ! *** Allocate the MO data types ***
1476 6686 : CALL get_qs_kind_set(qs_kind_set, nsgf=n_ao, nelectron=nelectron)
1477 :
1478 : ! the total number of electrons
1479 6686 : nelectron = nelectron - dft_control%charge
1480 :
1481 6686 : IF (dft_control%multiplicity == 0) THEN
1482 6104 : IF (MODULO(nelectron, 2) == 0) THEN
1483 5629 : dft_control%multiplicity = 1
1484 : ELSE
1485 475 : dft_control%multiplicity = 2
1486 : END IF
1487 : END IF
1488 :
1489 6686 : multiplicity = dft_control%multiplicity
1490 :
1491 6686 : IF ((dft_control%nspins < 1) .OR. (dft_control%nspins > 2)) THEN
1492 0 : CPABORT("nspins should be 1 or 2 for the time being ...")
1493 : END IF
1494 :
1495 6686 : IF ((MODULO(nelectron, 2) /= 0) .AND. (dft_control%nspins == 1)) THEN
1496 12 : IF (.NOT. dft_control%qs_control%ofgpw .AND. .NOT. dft_control%smear) THEN
1497 0 : CPABORT("Use the LSD option for an odd number of electrons")
1498 : END IF
1499 : END IF
1500 :
1501 : ! The transition potential method to calculate XAS needs LSD
1502 6686 : IF (dft_control%do_xas_calculation) THEN
1503 42 : IF (dft_control%nspins == 1) THEN
1504 0 : CPABORT("Use the LSD option for XAS with transition potential")
1505 : END IF
1506 : END IF
1507 :
1508 : ! assigning the number of states per spin initial version, not yet very
1509 : ! general. Should work for an even number of electrons and a single
1510 : ! additional electron this set of options that requires full matrices,
1511 : ! however, makes things a bit ugly right now.... we try to make a
1512 : ! distinction between the number of electrons per spin and the number of
1513 : ! MOs per spin this should allow the use of fractional occupations later
1514 : ! on
1515 6686 : IF (dft_control%qs_control%ofgpw) THEN
1516 :
1517 0 : IF (dft_control%nspins == 1) THEN
1518 0 : maxocc = nelectron
1519 0 : nelectron_spin(1) = nelectron
1520 0 : nelectron_spin(2) = 0
1521 0 : n_mo(1) = 1
1522 0 : n_mo(2) = 0
1523 : ELSE
1524 0 : IF (MODULO(nelectron + multiplicity - 1, 2) /= 0) THEN
1525 0 : CPABORT("LSD: try to use a different multiplicity")
1526 : END IF
1527 0 : nelectron_spin(1) = (nelectron + multiplicity - 1)/2
1528 0 : nelectron_spin(2) = (nelectron - multiplicity + 1)/2
1529 0 : IF (nelectron_spin(1) < 0) THEN
1530 0 : CPABORT("LSD: too few electrons for this multiplicity")
1531 : END IF
1532 0 : maxocc = MAXVAL(nelectron_spin)
1533 0 : n_mo(1) = MIN(nelectron_spin(1), 1)
1534 0 : n_mo(2) = MIN(nelectron_spin(2), 1)
1535 : END IF
1536 :
1537 : ELSE
1538 :
1539 6686 : IF (dft_control%nspins == 1) THEN
1540 5203 : maxocc = 2.0_dp
1541 5203 : nelectron_spin(1) = nelectron
1542 5203 : nelectron_spin(2) = 0
1543 5203 : IF (MODULO(nelectron, 2) == 0) THEN
1544 5191 : n_mo(1) = nelectron/2
1545 : ELSE
1546 12 : n_mo(1) = INT(nelectron/2._dp) + 1
1547 : END IF
1548 5203 : n_mo(2) = 0
1549 : ELSE
1550 1483 : maxocc = 1.0_dp
1551 :
1552 : ! The simplist spin distribution is written here. Special cases will
1553 : ! need additional user input
1554 1483 : IF (MODULO(nelectron + multiplicity - 1, 2) /= 0) THEN
1555 0 : CPABORT("LSD: try to use a different multiplicity")
1556 : END IF
1557 :
1558 1483 : nelectron_spin(1) = (nelectron + multiplicity - 1)/2
1559 1483 : nelectron_spin(2) = (nelectron - multiplicity + 1)/2
1560 :
1561 1483 : IF (nelectron_spin(2) < 0) THEN
1562 0 : CPABORT("LSD: too few electrons for this multiplicity")
1563 : END IF
1564 :
1565 1483 : n_mo(1) = nelectron_spin(1)
1566 1483 : n_mo(2) = nelectron_spin(2)
1567 :
1568 : END IF
1569 :
1570 : END IF
1571 :
1572 : ! Read the total_zeff_corr here [SGh]
1573 6686 : CALL get_qs_kind_set(qs_kind_set, total_zeff_corr=total_zeff_corr)
1574 : ! store it in qs_env
1575 6686 : qs_env%total_zeff_corr = total_zeff_corr
1576 :
1577 : ! store the number of electrons once an for all
1578 : CALL qs_subsys_set(subsys, &
1579 : nelectron_total=nelectron, &
1580 6686 : nelectron_spin=nelectron_spin)
1581 :
1582 : ! Check and set number of added (unoccupied) MOs
1583 6686 : IF (dft_control%nspins == 2) THEN
1584 1483 : IF (scf_control%added_mos(2) < 0) THEN
1585 0 : n_mo_add = n_ao - n_mo(2) ! use all available MOs
1586 1483 : ELSEIF (scf_control%added_mos(2) > 0) THEN
1587 : n_mo_add = scf_control%added_mos(2)
1588 : ELSE
1589 1337 : n_mo_add = scf_control%added_mos(1)
1590 : END IF
1591 1483 : IF (n_mo_add > n_ao - n_mo(2)) THEN
1592 24 : CPWARN("More ADDED_MOs requested for beta spin than available.")
1593 : END IF
1594 1483 : scf_control%added_mos(2) = MIN(n_mo_add, n_ao - n_mo(2))
1595 1483 : n_mo(2) = n_mo(2) + scf_control%added_mos(2)
1596 : END IF
1597 :
1598 : ! proceed alpha orbitals after the beta orbitals; this is essential to avoid
1599 : ! reduction in the number of available unoccupied molecular orbitals.
1600 : ! E.g. n_ao = 10, nelectrons = 10, multiplicity = 3 implies n_mo(1) = 6, n_mo(2) = 4;
1601 : ! added_mos(1:2) = (6,undef) should increase the number of molecular orbitals as
1602 : ! n_mo(1) = min(n_ao, n_mo(1) + added_mos(1)) = 10, n_mo(2) = 10.
1603 : ! However, if we try to proceed alpha orbitals first, this leads us n_mo(1:2) = (10,8)
1604 : ! due to the following assignment instruction above:
1605 : ! IF (scf_control%added_mos(2) > 0) THEN ... ELSE; n_mo_add = scf_control%added_mos(1); END IF
1606 6686 : IF (scf_control%added_mos(1) < 0) THEN
1607 42 : scf_control%added_mos(1) = n_ao - n_mo(1) ! use all available MOs
1608 6644 : ELSEIF (scf_control%added_mos(1) > n_ao - n_mo(1)) THEN
1609 : CALL cp_warn(__LOCATION__, &
1610 : "More added MOs requested than available. "// &
1611 : "The full set of unoccupied MOs will be used. "// &
1612 : "Use 'ADDED_MOS -1' to always use all available MOs "// &
1613 108 : "and to get rid of this warning.")
1614 : END IF
1615 6686 : scf_control%added_mos(1) = MIN(scf_control%added_mos(1), n_ao - n_mo(1))
1616 6686 : n_mo(1) = n_mo(1) + scf_control%added_mos(1)
1617 :
1618 6686 : IF (dft_control%nspins == 2) THEN
1619 1483 : IF (n_mo(2) > n_mo(1)) &
1620 : CALL cp_warn(__LOCATION__, &
1621 : "More beta than alpha MOs requested. "// &
1622 0 : "The number of beta MOs will be reduced to the number alpha MOs.")
1623 1483 : n_mo(2) = MIN(n_mo(1), n_mo(2))
1624 1483 : CPASSERT(n_mo(1) >= nelectron_spin(1))
1625 1483 : CPASSERT(n_mo(2) >= nelectron_spin(2))
1626 : END IF
1627 :
1628 : ! kpoints
1629 6686 : CALL get_qs_env(qs_env=qs_env, do_kpoints=do_kpoints)
1630 6686 : IF (do_kpoints .AND. dft_control%nspins == 2) THEN
1631 : ! we need equal number of calculated states
1632 20 : IF (n_mo(2) /= n_mo(1)) &
1633 : CALL cp_warn(__LOCATION__, &
1634 : "Kpoints: Different number of MOs requested. "// &
1635 0 : "The number of beta MOs will be set to the number alpha MOs.")
1636 20 : n_mo(2) = n_mo(1)
1637 20 : CPASSERT(n_mo(1) >= nelectron_spin(1))
1638 20 : CPASSERT(n_mo(2) >= nelectron_spin(2))
1639 : END IF
1640 :
1641 : ! Compatibility checks for smearing
1642 6686 : IF (scf_control%smear%do_smear) THEN
1643 274 : IF (scf_control%added_mos(1) == 0) THEN
1644 0 : CPABORT("Extra MOs (ADDED_MOS) are required for smearing")
1645 : END IF
1646 : END IF
1647 :
1648 : ! *** Some options require that all MOs are computed ... ***
1649 : IF (BTEST(cp_print_key_should_output(logger%iter_info, dft_section, &
1650 : "PRINT%MO/CARTESIAN"), &
1651 : cp_p_file) .OR. &
1652 : (scf_control%level_shift /= 0.0_dp) .OR. &
1653 6686 : (scf_control%diagonalization%eps_jacobi /= 0.0_dp) .OR. &
1654 : (dft_control%roks .AND. (.NOT. scf_control%use_ot))) THEN
1655 6842 : n_mo(:) = n_ao
1656 : END IF
1657 :
1658 : ! Compatibility checks for ROKS
1659 6686 : IF (dft_control%roks .AND. (.NOT. scf_control%use_ot)) THEN
1660 36 : IF (scf_control%roks_scheme == general_roks) THEN
1661 0 : CPWARN("General ROKS scheme is not yet tested!")
1662 : END IF
1663 36 : IF (scf_control%smear%do_smear) THEN
1664 : CALL cp_abort(__LOCATION__, &
1665 : "The options ROKS and SMEAR are not compatible. "// &
1666 0 : "Try UKS instead of ROKS")
1667 : END IF
1668 : END IF
1669 6686 : IF (dft_control%low_spin_roks) THEN
1670 8 : SELECT CASE (dft_control%qs_control%method_id)
1671 : CASE DEFAULT
1672 : CASE (do_method_xtb, do_method_dftb)
1673 : CALL cp_abort(__LOCATION__, &
1674 0 : "xTB/DFTB methods are not compatible with low spin ROKS.")
1675 : CASE (do_method_rm1, do_method_am1, do_method_mndo, do_method_pm3, &
1676 : do_method_pm6, do_method_pm6fm, do_method_mndod, do_method_pnnl)
1677 : CALL cp_abort(__LOCATION__, &
1678 8 : "SE methods are not compatible with low spin ROKS.")
1679 : END SELECT
1680 : END IF
1681 :
1682 : ! in principle the restricted calculation could be performed
1683 : ! using just one set of MOs and special casing most of the code
1684 : ! right now we'll just take care of what is effectively an additional constraint
1685 : ! at as few places as possible, just duplicating the beta orbitals
1686 6686 : IF (dft_control%restricted .AND. (output_unit > 0)) THEN
1687 : ! it is really not yet tested till the end ! Joost
1688 23 : WRITE (output_unit, *) ""
1689 23 : WRITE (output_unit, *) " **************************************"
1690 23 : WRITE (output_unit, *) " restricted calculation cutting corners"
1691 23 : WRITE (output_unit, *) " experimental feature, check code "
1692 23 : WRITE (output_unit, *) " **************************************"
1693 : END IF
1694 :
1695 : ! no point in allocating these things here ?
1696 6686 : IF (dft_control%qs_control%do_ls_scf) THEN
1697 344 : NULLIFY (mos)
1698 : ELSE
1699 26837 : ALLOCATE (mos(dft_control%nspins))
1700 14153 : DO ispin = 1, dft_control%nspins
1701 : CALL allocate_mo_set(mo_set=mos(ispin), &
1702 : nao=n_ao, &
1703 : nmo=n_mo(ispin), &
1704 : nelectron=nelectron_spin(ispin), &
1705 : n_el_f=REAL(nelectron_spin(ispin), dp), &
1706 : maxocc=maxocc, &
1707 14153 : flexible_electron_count=dft_control%relax_multiplicity)
1708 : END DO
1709 : END IF
1710 :
1711 6686 : CALL set_qs_env(qs_env, mos=mos)
1712 :
1713 : ! allocate mos when switch_surf_dip is triggered [SGh]
1714 6686 : IF (dft_control%switch_surf_dip) THEN
1715 8 : ALLOCATE (mos_last_converged(dft_control%nspins))
1716 4 : DO ispin = 1, dft_control%nspins
1717 : CALL allocate_mo_set(mo_set=mos_last_converged(ispin), &
1718 : nao=n_ao, &
1719 : nmo=n_mo(ispin), &
1720 : nelectron=nelectron_spin(ispin), &
1721 : n_el_f=REAL(nelectron_spin(ispin), dp), &
1722 : maxocc=maxocc, &
1723 4 : flexible_electron_count=dft_control%relax_multiplicity)
1724 : END DO
1725 2 : CALL set_qs_env(qs_env, mos_last_converged=mos_last_converged)
1726 : END IF
1727 :
1728 6686 : IF (.NOT. be_silent) THEN
1729 : ! Print the DFT control parameters
1730 6684 : CALL write_dft_control(dft_control, dft_section)
1731 :
1732 : ! Print the vdW control parameters
1733 : IF (dft_control%qs_control%method_id == do_method_gpw .OR. &
1734 : dft_control%qs_control%method_id == do_method_gapw .OR. &
1735 : dft_control%qs_control%method_id == do_method_gapw_xc .OR. &
1736 : dft_control%qs_control%method_id == do_method_lrigpw .OR. &
1737 : dft_control%qs_control%method_id == do_method_rigpw .OR. &
1738 : dft_control%qs_control%method_id == do_method_dftb .OR. &
1739 6684 : dft_control%qs_control%method_id == do_method_xtb .OR. &
1740 : dft_control%qs_control%method_id == do_method_ofgpw) THEN
1741 5686 : CALL get_qs_env(qs_env, dispersion_env=dispersion_env)
1742 5686 : CALL qs_write_dispersion(qs_env, dispersion_env)
1743 : END IF
1744 :
1745 : ! Print the Quickstep control parameters
1746 6684 : CALL write_qs_control(dft_control%qs_control, dft_section)
1747 :
1748 : ! Print the ADMM control parameters
1749 6684 : IF (dft_control%do_admm) THEN
1750 442 : CALL write_admm_control(dft_control%admm_control, dft_section)
1751 : END IF
1752 :
1753 : ! Print XES/XAS control parameters
1754 6684 : IF (dft_control%do_xas_calculation) THEN
1755 42 : CALL cite_reference(Iannuzzi2007)
1756 : !CALL write_xas_control(dft_control%xas_control,dft_section)
1757 : END IF
1758 :
1759 : ! Print the unnormalized basis set information (input data)
1760 6684 : CALL write_gto_basis_sets(qs_kind_set, subsys_section)
1761 :
1762 : ! Print the atomic kind set
1763 6684 : CALL write_qs_kind_set(qs_kind_set, subsys_section)
1764 :
1765 : ! Print the molecule kind set
1766 6684 : CALL write_molecule_kind_set(molecule_kind_set, subsys_section)
1767 :
1768 : ! Print the total number of kinds, atoms, basis functions etc.
1769 6684 : CALL write_total_numbers(qs_kind_set, particle_set, qs_env%input)
1770 :
1771 : ! Print the atomic coordinates
1772 6684 : CALL write_qs_particle_coordinates(particle_set, qs_kind_set, subsys_section, label="QUICKSTEP")
1773 :
1774 : ! Print the interatomic distances
1775 6684 : CALL write_particle_distances(particle_set, cell, subsys_section)
1776 :
1777 : ! Print the requested structure data
1778 6684 : CALL write_structure_data(particle_set, cell, subsys_section)
1779 :
1780 : ! Print symmetry information
1781 6684 : CALL write_symmetry(particle_set, cell, subsys_section)
1782 :
1783 : ! Print the SCF parameters
1784 6684 : IF ((.NOT. dft_control%qs_control%do_ls_scf) .AND. &
1785 : (.NOT. dft_control%qs_control%do_almo_scf)) THEN
1786 6274 : CALL scf_c_write_parameters(scf_control, dft_section)
1787 : END IF
1788 : END IF
1789 :
1790 : ! Sets up pw_env, qs_charges, mpools ...
1791 6686 : CALL qs_env_setup(qs_env)
1792 :
1793 : ! Allocate and initialise rho0 soft on the global grid
1794 6686 : IF (dft_control%qs_control%method_id == do_method_gapw) THEN
1795 814 : CALL get_qs_env(qs_env=qs_env, pw_env=pw_env, rho0_mpole=rho0_mpole)
1796 814 : CALL rho0_s_grid_create(pw_env, rho0_mpole)
1797 : END IF
1798 :
1799 6686 : IF (output_unit > 0) CALL m_flush(output_unit)
1800 6686 : CALL timestop(handle)
1801 :
1802 66860 : END SUBROUTINE qs_init_subsys
1803 :
1804 : ! **************************************************************************************************
1805 : !> \brief Write the total number of kinds, atoms, etc. to the logical unit
1806 : !> number lunit.
1807 : !> \param qs_kind_set ...
1808 : !> \param particle_set ...
1809 : !> \param force_env_section ...
1810 : !> \author Creation (06.10.2000)
1811 : ! **************************************************************************************************
1812 6684 : SUBROUTINE write_total_numbers(qs_kind_set, particle_set, force_env_section)
1813 :
1814 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
1815 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1816 : TYPE(section_vals_type), POINTER :: force_env_section
1817 :
1818 : INTEGER :: maxlgto, maxlppl, maxlppnl, natom, ncgf, &
1819 : nkind, npgf, nset, nsgf, nshell, &
1820 : output_unit
1821 : TYPE(cp_logger_type), POINTER :: logger
1822 :
1823 6684 : NULLIFY (logger)
1824 6684 : logger => cp_get_default_logger()
1825 : output_unit = cp_print_key_unit_nr(logger, force_env_section, "PRINT%TOTAL_NUMBERS", &
1826 6684 : extension=".Log")
1827 :
1828 6684 : IF (output_unit > 0) THEN
1829 3365 : natom = SIZE(particle_set)
1830 3365 : nkind = SIZE(qs_kind_set)
1831 :
1832 : CALL get_qs_kind_set(qs_kind_set, &
1833 : maxlgto=maxlgto, &
1834 : ncgf=ncgf, &
1835 : npgf=npgf, &
1836 : nset=nset, &
1837 : nsgf=nsgf, &
1838 : nshell=nshell, &
1839 : maxlppl=maxlppl, &
1840 3365 : maxlppnl=maxlppnl)
1841 :
1842 : WRITE (UNIT=output_unit, FMT="(/,/,T2,A)") &
1843 3365 : "TOTAL NUMBERS AND MAXIMUM NUMBERS"
1844 :
1845 3365 : IF (nset + npgf + ncgf > 0) THEN
1846 : WRITE (UNIT=output_unit, FMT="(/,T3,A,(T30,A,T71,I10))") &
1847 3365 : "Total number of", &
1848 3365 : "- Atomic kinds: ", nkind, &
1849 3365 : "- Atoms: ", natom, &
1850 3365 : "- Shell sets: ", nset, &
1851 3365 : "- Shells: ", nshell, &
1852 3365 : "- Primitive Cartesian functions: ", npgf, &
1853 3365 : "- Cartesian basis functions: ", ncgf, &
1854 6730 : "- Spherical basis functions: ", nsgf
1855 0 : ELSE IF (nshell + nsgf > 0) THEN
1856 : WRITE (UNIT=output_unit, FMT="(/,T3,A,(T30,A,T71,I10))") &
1857 0 : "Total number of", &
1858 0 : "- Atomic kinds: ", nkind, &
1859 0 : "- Atoms: ", natom, &
1860 0 : "- Shells: ", nshell, &
1861 0 : "- Spherical basis functions: ", nsgf
1862 : ELSE
1863 : WRITE (UNIT=output_unit, FMT="(/,T3,A,(T30,A,T71,I10))") &
1864 0 : "Total number of", &
1865 0 : "- Atomic kinds: ", nkind, &
1866 0 : "- Atoms: ", natom
1867 : END IF
1868 :
1869 3365 : IF ((maxlppl > -1) .AND. (maxlppnl > -1)) THEN
1870 : WRITE (UNIT=output_unit, FMT="(/,T3,A,(T30,A,T75,I6))") &
1871 1878 : "Maximum angular momentum of the", &
1872 1878 : "- Orbital basis functions: ", maxlgto, &
1873 1878 : "- Local part of the GTH pseudopotential: ", maxlppl, &
1874 3756 : "- Non-local part of the GTH pseudopotential: ", maxlppnl
1875 1487 : ELSEIF (maxlppl > -1) THEN
1876 : WRITE (UNIT=output_unit, FMT="(/,T3,A,(T30,A,T75,I6))") &
1877 462 : "Maximum angular momentum of the", &
1878 462 : "- Orbital basis functions: ", maxlgto, &
1879 924 : "- Local part of the GTH pseudopotential: ", maxlppl
1880 : ELSE
1881 : WRITE (UNIT=output_unit, FMT="(/,T3,A,T75,I6)") &
1882 1025 : "Maximum angular momentum of the orbital basis functions: ", maxlgto
1883 : END IF
1884 :
1885 : ! LRI_AUX BASIS
1886 : CALL get_qs_kind_set(qs_kind_set, &
1887 : maxlgto=maxlgto, &
1888 : ncgf=ncgf, &
1889 : npgf=npgf, &
1890 : nset=nset, &
1891 : nsgf=nsgf, &
1892 : nshell=nshell, &
1893 3365 : basis_type="LRI_AUX")
1894 3365 : IF (nset + npgf + ncgf > 0) THEN
1895 : WRITE (UNIT=output_unit, FMT="(/,T3,A,/,T3,A,(T30,A,T71,I10))") &
1896 135 : "LRI_AUX Basis: ", &
1897 135 : "Total number of", &
1898 135 : "- Shell sets: ", nset, &
1899 135 : "- Shells: ", nshell, &
1900 135 : "- Primitive Cartesian functions: ", npgf, &
1901 135 : "- Cartesian basis functions: ", ncgf, &
1902 270 : "- Spherical basis functions: ", nsgf
1903 : WRITE (UNIT=output_unit, FMT="(T30,A,T75,I6)") &
1904 135 : " Maximum angular momentum ", maxlgto
1905 : END IF
1906 :
1907 : ! RI_HXC BASIS
1908 : CALL get_qs_kind_set(qs_kind_set, &
1909 : maxlgto=maxlgto, &
1910 : ncgf=ncgf, &
1911 : npgf=npgf, &
1912 : nset=nset, &
1913 : nsgf=nsgf, &
1914 : nshell=nshell, &
1915 3365 : basis_type="RI_HXC")
1916 3365 : IF (nset + npgf + ncgf > 0) THEN
1917 : WRITE (UNIT=output_unit, FMT="(/,T3,A,/,T3,A,(T30,A,T71,I10))") &
1918 111 : "RI_HXC Basis: ", &
1919 111 : "Total number of", &
1920 111 : "- Shell sets: ", nset, &
1921 111 : "- Shells: ", nshell, &
1922 111 : "- Primitive Cartesian functions: ", npgf, &
1923 111 : "- Cartesian basis functions: ", ncgf, &
1924 222 : "- Spherical basis functions: ", nsgf
1925 : WRITE (UNIT=output_unit, FMT="(T30,A,T75,I6)") &
1926 111 : " Maximum angular momentum ", maxlgto
1927 : END IF
1928 :
1929 : ! AUX_FIT BASIS
1930 : CALL get_qs_kind_set(qs_kind_set, &
1931 : maxlgto=maxlgto, &
1932 : ncgf=ncgf, &
1933 : npgf=npgf, &
1934 : nset=nset, &
1935 : nsgf=nsgf, &
1936 : nshell=nshell, &
1937 3365 : basis_type="AUX_FIT")
1938 3365 : IF (nset + npgf + ncgf > 0) THEN
1939 : WRITE (UNIT=output_unit, FMT="(/,T3,A,/,T3,A,(T30,A,T71,I10))") &
1940 332 : "AUX_FIT ADMM-Basis: ", &
1941 332 : "Total number of", &
1942 332 : "- Shell sets: ", nset, &
1943 332 : "- Shells: ", nshell, &
1944 332 : "- Primitive Cartesian functions: ", npgf, &
1945 332 : "- Cartesian basis functions: ", ncgf, &
1946 664 : "- Spherical basis functions: ", nsgf
1947 : WRITE (UNIT=output_unit, FMT="(T30,A,T75,I6)") &
1948 332 : " Maximum angular momentum ", maxlgto
1949 : END IF
1950 :
1951 : END IF
1952 : CALL cp_print_key_finished_output(output_unit, logger, force_env_section, &
1953 6684 : "PRINT%TOTAL_NUMBERS")
1954 :
1955 6684 : END SUBROUTINE write_total_numbers
1956 :
1957 : END MODULE qs_environment
|