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 : !> \brief Energy correction environment setup and handling
10 : !> \par History
11 : !> 2019.09 created
12 : !> \author JGH
13 : ! **************************************************************************************************
14 : MODULE ec_environment
15 : USE atomic_kind_types, ONLY: atomic_kind_type
16 : USE basis_set_container_types, ONLY: add_basis_set_to_container,&
17 : remove_basis_from_container
18 : USE basis_set_types, ONLY: copy_gto_basis_set,&
19 : create_primitive_basis_set,&
20 : gto_basis_set_type
21 : USE bibliography, ONLY: Niklasson2003,&
22 : Niklasson2014,&
23 : cite_reference
24 : USE cp_control_types, ONLY: dft_control_type
25 : USE cp_log_handling, ONLY: cp_get_default_logger,&
26 : cp_logger_get_default_unit_nr,&
27 : cp_logger_type
28 : USE dm_ls_scf_types, ONLY: ls_scf_env_type
29 : USE ec_env_types, ONLY: energy_correction_type
30 : USE input_constants, ONLY: &
31 : ec_diagonalization, ec_functional_dc, ec_functional_harris, ec_matrix_sign, ec_matrix_tc2, &
32 : ec_matrix_trs4, ec_ot_atomic, ec_ot_diag, ec_ot_gs, kg_cholesky, ls_cluster_atomic, &
33 : ls_cluster_molecular, ls_s_inversion_hotelling, ls_s_inversion_none, &
34 : ls_s_inversion_sign_sqrt, ls_s_preconditioner_atomic, ls_s_preconditioner_molecular, &
35 : ls_s_preconditioner_none, ls_s_sqrt_ns, ls_s_sqrt_proot, xc_vdw_fun_nonloc, &
36 : xc_vdw_fun_pairpot
37 : USE input_cp2k_check, ONLY: xc_functionals_expand
38 : USE input_section_types, ONLY: section_get_ival,&
39 : section_vals_get,&
40 : section_vals_get_subs_vals,&
41 : section_vals_type,&
42 : section_vals_val_get
43 : USE kinds, ONLY: dp
44 : USE message_passing, ONLY: mp_para_env_type
45 : USE molecule_types, ONLY: molecule_of_atom,&
46 : molecule_type
47 : USE orbital_pointers, ONLY: init_orbital_pointers
48 : USE particle_types, ONLY: particle_type
49 : USE qs_dispersion_nonloc, ONLY: qs_dispersion_nonloc_init
50 : USE qs_dispersion_pairpot, ONLY: qs_dispersion_pairpot_init
51 : USE qs_dispersion_types, ONLY: qs_dispersion_type
52 : USE qs_dispersion_utils, ONLY: qs_dispersion_env_set
53 : USE qs_environment_types, ONLY: get_qs_env,&
54 : qs_environment_type
55 : USE qs_interactions, ONLY: init_interaction_radii_orb_basis
56 : USE qs_kind_types, ONLY: get_qs_kind,&
57 : get_qs_kind_set,&
58 : qs_kind_type
59 : USE qs_rho_types, ONLY: qs_rho_type
60 : USE string_utilities, ONLY: uppercase
61 : USE xc, ONLY: xc_uses_kinetic_energy_density,&
62 : xc_uses_norm_drho
63 : USE xc_input_constants, ONLY: xc_deriv_collocate
64 : #include "./base/base_uses.f90"
65 :
66 : IMPLICIT NONE
67 :
68 : PRIVATE
69 :
70 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'ec_environment'
71 :
72 : PUBLIC :: ec_env_create
73 : PUBLIC :: ec_write_input
74 :
75 : CONTAINS
76 :
77 : ! **************************************************************************************************
78 : !> \brief Allocates and intitializes ec_env
79 : !> \param qs_env The QS environment
80 : !> \param ec_env The energy correction environment (the object to create)
81 : !> \param dft_section The DFT section
82 : !> \param ec_section The energy correction input section
83 : !> \par History
84 : !> 2019.09 created
85 : !> \author JGH
86 : ! **************************************************************************************************
87 6586 : SUBROUTINE ec_env_create(qs_env, ec_env, dft_section, ec_section)
88 : TYPE(qs_environment_type), POINTER :: qs_env
89 : TYPE(energy_correction_type), POINTER :: ec_env
90 : TYPE(section_vals_type), POINTER :: dft_section
91 : TYPE(section_vals_type), OPTIONAL, POINTER :: ec_section
92 :
93 6586 : CPASSERT(.NOT. ASSOCIATED(ec_env))
94 6586 : ALLOCATE (ec_env)
95 6586 : CALL init_ec_env(qs_env, ec_env, dft_section, ec_section)
96 :
97 6586 : END SUBROUTINE ec_env_create
98 :
99 : ! **************************************************************************************************
100 : !> \brief Initializes energy correction environment
101 : !> \param qs_env The QS environment
102 : !> \param ec_env The energy correction environment
103 : !> \param dft_section The DFT section
104 : !> \param ec_section The energy correction input section
105 : !> \par History
106 : !> 2019.09 created
107 : !> \author JGH
108 : ! **************************************************************************************************
109 6586 : SUBROUTINE init_ec_env(qs_env, ec_env, dft_section, ec_section)
110 : TYPE(qs_environment_type), POINTER :: qs_env
111 : TYPE(energy_correction_type), POINTER :: ec_env
112 : TYPE(section_vals_type), POINTER :: dft_section
113 : TYPE(section_vals_type), OPTIONAL, POINTER :: ec_section
114 :
115 : CHARACTER(LEN=*), PARAMETER :: routineN = 'init_ec_env'
116 :
117 : INTEGER :: handle, ikind, maxlgto, nkind, unit_nr
118 : LOGICAL :: explicit
119 : REAL(KIND=dp) :: eps_pgf_orb
120 6586 : TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
121 : TYPE(cp_logger_type), POINTER :: logger
122 : TYPE(dft_control_type), POINTER :: dft_control
123 : TYPE(gto_basis_set_type), POINTER :: basis_set, harris_basis
124 : TYPE(mp_para_env_type), POINTER :: para_env
125 : TYPE(qs_dispersion_type), POINTER :: dispersion_env
126 6586 : TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
127 : TYPE(qs_kind_type), POINTER :: qs_kind
128 : TYPE(qs_rho_type), POINTER :: rho
129 : TYPE(section_vals_type), POINTER :: ec_hfx_section, nl_section, pp_section, &
130 : section1, section2, xc_fun_section, &
131 : xc_section
132 :
133 6586 : CALL timeset(routineN, handle)
134 :
135 6586 : NULLIFY (atomic_kind_set, dispersion_env, ec_env%ls_env, para_env)
136 6586 : NULLIFY (ec_env%sab_orb, ec_env%sac_ppl, ec_env%sap_ppnl)
137 6586 : NULLIFY (ec_env%matrix_ks, ec_env%matrix_h, ec_env%matrix_s)
138 6586 : NULLIFY (ec_env%matrix_t, ec_env%matrix_p, ec_env%matrix_w)
139 6586 : NULLIFY (ec_env%task_list)
140 6586 : NULLIFY (ec_env%mao_coef)
141 6586 : NULLIFY (ec_env%force)
142 6586 : NULLIFY (ec_env%dispersion_env)
143 6586 : NULLIFY (ec_env%xc_section)
144 6586 : NULLIFY (ec_env%matrix_z)
145 6586 : NULLIFY (ec_env%matrix_hz)
146 6586 : NULLIFY (ec_env%matrix_wz)
147 6586 : NULLIFY (ec_env%z_admm)
148 6586 : NULLIFY (ec_env%p_env)
149 6586 : NULLIFY (ec_env%vxc_rspace)
150 6586 : NULLIFY (ec_env%vtau_rspace)
151 6586 : NULLIFY (ec_env%vadmm_rspace)
152 6586 : NULLIFY (ec_env%rhoout_r, ec_env%rhoz_r)
153 6586 : NULLIFY (ec_env%x_data)
154 6586 : ec_env%should_update = .TRUE.
155 6586 : ec_env%mao = .FALSE.
156 6586 : ec_env%do_ec_admm = .FALSE.
157 6586 : ec_env%do_ec_hfx = .FALSE.
158 6586 : ec_env%reuse_hfx = .FALSE.
159 :
160 6586 : IF (qs_env%energy_correction) THEN
161 :
162 232 : CPASSERT(PRESENT(ec_section))
163 : ! get a useful output_unit
164 232 : logger => cp_get_default_logger()
165 232 : IF (logger%para_env%is_source()) THEN
166 116 : unit_nr = cp_logger_get_default_unit_nr(logger, local=.TRUE.)
167 : ELSE
168 : unit_nr = -1
169 : END IF
170 :
171 : CALL section_vals_val_get(ec_section, "ALGORITHM", &
172 232 : i_val=ec_env%ks_solver)
173 : CALL section_vals_val_get(ec_section, "ENERGY_FUNCTIONAL", &
174 232 : i_val=ec_env%energy_functional)
175 : CALL section_vals_val_get(ec_section, "FACTORIZATION", &
176 232 : i_val=ec_env%factorization)
177 : CALL section_vals_val_get(ec_section, "OT_INITIAL_GUESS", &
178 232 : i_val=ec_env%ec_initial_guess)
179 : CALL section_vals_val_get(ec_section, "EPS_DEFAULT", &
180 232 : r_val=ec_env%eps_default)
181 : CALL section_vals_val_get(ec_section, "HARRIS_BASIS", &
182 232 : c_val=ec_env%basis)
183 : CALL section_vals_val_get(ec_section, "MAO", &
184 232 : l_val=ec_env%mao)
185 : CALL section_vals_val_get(ec_section, "MAO_MAX_ITER", &
186 232 : i_val=ec_env%mao_max_iter)
187 : CALL section_vals_val_get(ec_section, "MAO_EPS_GRAD", &
188 232 : r_val=ec_env%mao_eps_grad)
189 : CALL section_vals_val_get(ec_section, "MAO_EPS1", &
190 232 : r_val=ec_env%mao_eps1)
191 : CALL section_vals_val_get(ec_section, "MAO_IOLEVEL", &
192 232 : i_val=ec_env%mao_iolevel)
193 : ! Skip EC calculation if ground-state calculation did not converge
194 : CALL section_vals_val_get(ec_section, "SKIP_EC", &
195 232 : l_val=ec_env%skip_ec)
196 : ! Debug output
197 : CALL section_vals_val_get(ec_section, "DEBUG_FORCES", &
198 232 : l_val=ec_env%debug_forces)
199 : CALL section_vals_val_get(ec_section, "DEBUG_STRESS", &
200 232 : l_val=ec_env%debug_stress)
201 : ! ADMM
202 232 : CALL section_vals_val_get(ec_section, "ADMM", l_val=ec_env%do_ec_admm)
203 :
204 232 : ec_env%do_skip = .FALSE.
205 :
206 : ! set basis
207 232 : CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set, nkind=nkind)
208 232 : CALL uppercase(ec_env%basis)
209 376 : SELECT CASE (ec_env%basis)
210 : CASE ("ORBITAL")
211 306 : DO ikind = 1, nkind
212 162 : qs_kind => qs_kind_set(ikind)
213 162 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type="ORB")
214 306 : IF (ASSOCIATED(basis_set)) THEN
215 162 : NULLIFY (harris_basis)
216 162 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=harris_basis, basis_type="HARRIS")
217 162 : IF (ASSOCIATED(harris_basis)) THEN
218 6 : CALL remove_basis_from_container(qs_kind%basis_sets, basis_type="HARRIS")
219 : END IF
220 162 : NULLIFY (harris_basis)
221 162 : CALL copy_gto_basis_set(basis_set, harris_basis)
222 162 : CALL add_basis_set_to_container(qs_kind%basis_sets, harris_basis, "HARRIS")
223 : END IF
224 : END DO
225 : CASE ("PRIMITIVE")
226 6 : DO ikind = 1, nkind
227 4 : qs_kind => qs_kind_set(ikind)
228 4 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type="ORB")
229 6 : IF (ASSOCIATED(basis_set)) THEN
230 4 : NULLIFY (harris_basis)
231 4 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=harris_basis, basis_type="HARRIS")
232 4 : IF (ASSOCIATED(harris_basis)) THEN
233 0 : CALL remove_basis_from_container(qs_kind%basis_sets, basis_type="HARRIS")
234 : END IF
235 4 : NULLIFY (harris_basis)
236 4 : CALL create_primitive_basis_set(basis_set, harris_basis)
237 4 : CALL get_qs_env(qs_env, dft_control=dft_control)
238 4 : eps_pgf_orb = dft_control%qs_control%eps_pgf_orb
239 4 : CALL init_interaction_radii_orb_basis(harris_basis, eps_pgf_orb)
240 4 : harris_basis%kind_radius = basis_set%kind_radius
241 4 : CALL add_basis_set_to_container(qs_kind%basis_sets, harris_basis, "HARRIS")
242 : END IF
243 : END DO
244 : CASE ("HARRIS")
245 212 : DO ikind = 1, nkind
246 126 : qs_kind => qs_kind_set(ikind)
247 126 : NULLIFY (harris_basis)
248 126 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=harris_basis, basis_type="HARRIS")
249 212 : IF (.NOT. ASSOCIATED(harris_basis)) THEN
250 0 : CPWARN("Harris Basis not defined for all types of atoms.")
251 : END IF
252 : END DO
253 : CASE DEFAULT
254 232 : CPABORT("Unknown basis set for energy correction (Harris functional)")
255 : END SELECT
256 : !
257 232 : CALL get_qs_kind_set(qs_kind_set, maxlgto=maxlgto, basis_type="HARRIS")
258 232 : CALL init_orbital_pointers(maxlgto + 1)
259 : !
260 232 : CALL uppercase(ec_env%basis)
261 :
262 : ! Basis may only differ from ground-state if explicitly added
263 232 : ec_env%basis_inconsistent = .FALSE.
264 232 : IF (ec_env%basis == "HARRIS") THEN
265 212 : DO ikind = 1, nkind
266 126 : qs_kind => qs_kind_set(ikind)
267 : ! Basis sets of ground-state
268 126 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=basis_set, basis_type="ORB")
269 : ! Basis sets of energy correction
270 126 : CALL get_qs_kind(qs_kind=qs_kind, basis_set=harris_basis, basis_type="HARRIS")
271 :
272 212 : IF (basis_set%name .NE. harris_basis%name) THEN
273 64 : ec_env%basis_inconsistent = .TRUE.
274 : END IF
275 : END DO
276 : END IF
277 :
278 : !Density-corrected DFT must be performed with the same basis as ground-state
279 232 : IF (ec_env%energy_functional == ec_functional_dc .AND. ec_env%basis_inconsistent) THEN
280 : CALL cp_abort(__LOCATION__, &
281 : "DC-DFT: Correction and ground state need to use the same basis. "// &
282 0 : "Checked by comparing basis set names only.")
283 : END IF
284 : !
285 : ! set functional
286 378 : SELECT CASE (ec_env%energy_functional)
287 : CASE (ec_functional_harris)
288 146 : ec_env%ec_name = "Harris"
289 : CASE (ec_functional_dc)
290 86 : ec_env%ec_name = "DC-DFT"
291 : CASE DEFAULT
292 232 : CPABORT("unknown energy correction")
293 : END SELECT
294 : ! select the XC section
295 232 : NULLIFY (xc_section)
296 232 : xc_section => section_vals_get_subs_vals(dft_section, "XC")
297 232 : section1 => section_vals_get_subs_vals(ec_section, "XC")
298 232 : section2 => section_vals_get_subs_vals(ec_section, "XC%XC_FUNCTIONAL")
299 232 : CALL section_vals_get(section2, explicit=explicit)
300 232 : IF (explicit) THEN
301 232 : CALL xc_functionals_expand(section2, section1)
302 232 : ec_env%xc_section => section1
303 : ELSE
304 0 : ec_env%xc_section => xc_section
305 : END IF
306 : ! Check whether energy correction requires the kinetic energy density and rebuild rho if necessary
307 232 : CALL get_qs_env(qs_env, dft_control=dft_control, rho=rho)
308 232 : xc_fun_section => section_vals_get_subs_vals(ec_env%xc_section, "XC_FUNCTIONAL")
309 : dft_control%use_kinetic_energy_density = dft_control%use_kinetic_energy_density .OR. &
310 232 : xc_uses_kinetic_energy_density(xc_fun_section, dft_control%lsd)
311 : ! Same for density gradient
312 : dft_control%drho_by_collocation = dft_control%drho_by_collocation .OR. &
313 : (xc_uses_norm_drho(xc_fun_section, dft_control%lsd) .AND. &
314 232 : (section_get_ival(xc_section, "XC_GRID%XC_DERIV") == xc_deriv_collocate))
315 : ! dispersion
316 1160 : ALLOCATE (dispersion_env)
317 : NULLIFY (xc_section)
318 232 : xc_section => ec_env%xc_section
319 232 : CALL get_qs_env(qs_env, atomic_kind_set=atomic_kind_set, para_env=para_env)
320 232 : CALL qs_dispersion_env_set(dispersion_env, xc_section)
321 232 : IF (dispersion_env%type == xc_vdw_fun_pairpot) THEN
322 0 : NULLIFY (pp_section)
323 0 : pp_section => section_vals_get_subs_vals(xc_section, "VDW_POTENTIAL%PAIR_POTENTIAL")
324 0 : CALL qs_dispersion_pairpot_init(atomic_kind_set, qs_kind_set, dispersion_env, pp_section, para_env)
325 232 : ELSE IF (dispersion_env%type == xc_vdw_fun_nonloc) THEN
326 0 : CPABORT("nl-vdW functionals not available for EC calculations")
327 0 : NULLIFY (nl_section)
328 0 : nl_section => section_vals_get_subs_vals(xc_section, "VDW_POTENTIAL%NON_LOCAL")
329 0 : CALL qs_dispersion_nonloc_init(dispersion_env, para_env)
330 : END IF
331 232 : ec_env%dispersion_env => dispersion_env
332 :
333 : ! Check if hybrid functional are used
334 232 : ec_hfx_section => section_vals_get_subs_vals(ec_section, "XC%HF")
335 232 : CALL section_vals_get(ec_hfx_section, explicit=ec_env%do_ec_hfx)
336 :
337 : ! Initialize Harris LS solver environment
338 232 : ec_env%use_ls_solver = .FALSE.
339 : ec_env%use_ls_solver = (ec_env%ks_solver .EQ. ec_matrix_sign) &
340 : .OR. (ec_env%ks_solver .EQ. ec_matrix_trs4) &
341 232 : .OR. (ec_env%ks_solver .EQ. ec_matrix_tc2)
342 :
343 232 : IF (ec_env%use_ls_solver) THEN
344 22 : CALL ec_ls_create(qs_env, ec_env)
345 : END IF
346 :
347 : END IF
348 :
349 6586 : CALL timestop(handle)
350 :
351 6586 : END SUBROUTINE init_ec_env
352 :
353 : ! **************************************************************************************************
354 : !> \brief Initializes linear scaling environment for LS based solver of
355 : !> Harris energy functional and parses input section
356 : !> \param qs_env ...
357 : !> \param ec_env ...
358 : !> \par History
359 : !> 2020.10 created [Fabian Belleflamme]
360 : !> \author Fabian Belleflamme
361 : ! **************************************************************************************************
362 22 : SUBROUTINE ec_ls_create(qs_env, ec_env)
363 : TYPE(qs_environment_type), POINTER :: qs_env
364 : TYPE(energy_correction_type), POINTER :: ec_env
365 :
366 : CHARACTER(LEN=*), PARAMETER :: routineN = 'ec_ls_create'
367 :
368 : INTEGER :: handle
369 : REAL(KIND=dp) :: mu
370 : TYPE(dft_control_type), POINTER :: dft_control
371 : TYPE(ls_scf_env_type), POINTER :: ls_env
372 22 : TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
373 22 : TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
374 : TYPE(section_vals_type), POINTER :: ec_section, input
375 :
376 22 : CALL timeset(routineN, handle)
377 :
378 858 : ALLOCATE (ec_env%ls_env)
379 22 : ls_env => ec_env%ls_env
380 :
381 22 : NULLIFY (dft_control, input, ls_env%para_env)
382 :
383 : CALL get_qs_env(qs_env, &
384 : dft_control=dft_control, &
385 : input=input, &
386 : molecule_set=molecule_set, &
387 : particle_set=particle_set, &
388 : para_env=ls_env%para_env, &
389 22 : nelectron_spin=ls_env%nelectron_spin)
390 :
391 : ! copy some basic stuff
392 22 : ls_env%nspins = dft_control%nspins
393 22 : ls_env%natoms = SIZE(particle_set, 1)
394 22 : CALL ls_env%para_env%retain()
395 :
396 : ! initialize block to group to defined molecules
397 66 : ALLOCATE (ls_env%ls_mstruct%atom_to_molecule(ls_env%natoms))
398 22 : CALL molecule_of_atom(molecule_set, atom_to_mol=ls_env%ls_mstruct%atom_to_molecule)
399 :
400 22 : ls_env%do_transport = .FALSE.
401 22 : ls_env%do_pao = .FALSE.
402 22 : ls_env%ls_mstruct%do_pao = ls_env%do_pao
403 22 : ls_env%do_pexsi = .FALSE.
404 22 : ls_env%has_unit_metric = .FALSE.
405 :
406 22 : ec_section => section_vals_get_subs_vals(input, "DFT%ENERGY_CORRECTION")
407 22 : CALL section_vals_val_get(ec_section, "EPS_FILTER", r_val=ls_env%eps_filter)
408 22 : CALL section_vals_val_get(ec_section, "MU", r_val=mu)
409 22 : CALL section_vals_val_get(ec_section, "FIXED_MU", l_val=ls_env%fixed_mu)
410 66 : ls_env%mu_spin = mu
411 22 : CALL section_vals_val_get(ec_section, "S_PRECONDITIONER", i_val=ls_env%s_preconditioner_type)
412 22 : CALL section_vals_val_get(ec_section, "MATRIX_CLUSTER_TYPE", i_val=ls_env%ls_mstruct%cluster_type)
413 22 : CALL section_vals_val_get(ec_section, "S_INVERSION", i_val=ls_env%s_inversion_type)
414 22 : CALL section_vals_val_get(ec_section, "CHECK_S_INV", l_val=ls_env%check_s_inv)
415 22 : CALL section_vals_val_get(ec_section, "REPORT_ALL_SPARSITIES", l_val=ls_env%report_all_sparsities)
416 22 : CALL section_vals_val_get(ec_section, "SIGN_METHOD", i_val=ls_env%sign_method)
417 22 : CALL section_vals_val_get(ec_section, "SIGN_ORDER", i_val=ls_env%sign_order)
418 22 : CALL section_vals_val_get(ec_section, "DYNAMIC_THRESHOLD", l_val=ls_env%dynamic_threshold)
419 22 : CALL section_vals_val_get(ec_section, "NON_MONOTONIC", l_val=ls_env%non_monotonic)
420 22 : CALL section_vals_val_get(ec_section, "S_SQRT_METHOD", i_val=ls_env%s_sqrt_method)
421 22 : CALL section_vals_val_get(ec_section, "S_SQRT_ORDER", i_val=ls_env%s_sqrt_order)
422 22 : CALL section_vals_val_get(ec_section, "EPS_LANCZOS", r_val=ls_env%eps_lanczos)
423 22 : CALL section_vals_val_get(ec_section, "MAX_ITER_LANCZOS", i_val=ls_env%max_iter_lanczos)
424 :
425 24 : SELECT CASE (ec_env%ks_solver)
426 : CASE (ec_matrix_sign)
427 : ! S inverse required for Sign matrix algorithm,
428 : ! calculated either by Hotelling or multiplying S matrix sqrt inv
429 24 : SELECT CASE (ls_env%s_inversion_type)
430 : CASE (ls_s_inversion_sign_sqrt)
431 2 : ls_env%needs_s_inv = .TRUE.
432 2 : ls_env%use_s_sqrt = .TRUE.
433 : CASE (ls_s_inversion_hotelling)
434 0 : ls_env%needs_s_inv = .TRUE.
435 0 : ls_env%use_s_sqrt = .FALSE.
436 : CASE (ls_s_inversion_none)
437 0 : ls_env%needs_s_inv = .FALSE.
438 0 : ls_env%use_s_sqrt = .FALSE.
439 : CASE DEFAULT
440 2 : CPABORT("")
441 : END SELECT
442 : CASE (ec_matrix_trs4, ec_matrix_tc2)
443 20 : ls_env%needs_s_inv = .FALSE.
444 20 : ls_env%use_s_sqrt = .TRUE.
445 : CASE DEFAULT
446 22 : CPABORT("")
447 : END SELECT
448 :
449 22 : SELECT CASE (ls_env%s_preconditioner_type)
450 : CASE (ls_s_preconditioner_none)
451 0 : ls_env%has_s_preconditioner = .FALSE.
452 : CASE DEFAULT
453 22 : ls_env%has_s_preconditioner = .TRUE.
454 : END SELECT
455 :
456 : ! buffer for the history of matrices, not needed here
457 22 : ls_env%extrapolation_order = 0
458 22 : ls_env%scf_history%nstore = 0
459 22 : ls_env%scf_history%istore = 0
460 44 : ALLOCATE (ls_env%scf_history%matrix(ls_env%nspins, ls_env%scf_history%nstore))
461 :
462 22 : NULLIFY (ls_env%mixing_store)
463 :
464 22 : CALL timestop(handle)
465 :
466 44 : END SUBROUTINE ec_ls_create
467 :
468 : ! **************************************************************************************************
469 : !> \brief Print out the energy correction input section
470 : !>
471 : !> \param ec_env ...
472 : !> \par History
473 : !> 2020.10 created [Fabian Belleflamme]
474 : !> \author Fabian Belleflamme
475 : ! **************************************************************************************************
476 232 : SUBROUTINE ec_write_input(ec_env)
477 : TYPE(energy_correction_type), POINTER :: ec_env
478 :
479 : CHARACTER(LEN=*), PARAMETER :: routineN = 'ec_write_input'
480 :
481 : INTEGER :: handle, unit_nr
482 : TYPE(cp_logger_type), POINTER :: logger
483 : TYPE(ls_scf_env_type), POINTER :: ls_env
484 :
485 232 : CALL timeset(routineN, handle)
486 :
487 232 : logger => cp_get_default_logger()
488 232 : IF (logger%para_env%is_source()) THEN
489 116 : unit_nr = cp_logger_get_default_unit_nr(logger, local=.TRUE.)
490 : ELSE
491 : unit_nr = -1
492 : END IF
493 :
494 116 : IF (unit_nr > 0) THEN
495 :
496 : WRITE (unit_nr, '(T2,A)') &
497 116 : "!"//REPEAT("-", 29)//" Energy Correction "//REPEAT("-", 29)//"!"
498 :
499 : ! Type of energy correction
500 189 : SELECT CASE (ec_env%energy_functional)
501 : CASE (ec_functional_harris)
502 73 : WRITE (unit_nr, '(T2,A,T61,A20)') "Energy Correction: ", "HARRIS FUNCTIONAL"
503 : CASE (ec_functional_dc)
504 116 : WRITE (unit_nr, '(T2,A,T61,A20)') "Energy Correction: ", "DC-DFT"
505 : END SELECT
506 116 : WRITE (unit_nr, '()')
507 :
508 : ! Energy correction parameters
509 116 : WRITE (unit_nr, '(T2,A,T61,E20.3)') "eps_default:", ec_env%eps_default
510 :
511 116 : CALL uppercase(ec_env%basis)
512 188 : SELECT CASE (ec_env%basis)
513 : CASE ("ORBITAL")
514 72 : WRITE (unit_nr, '(T2,A,T61,A20)') "EC basis: ", "ORBITAL"
515 : CASE ("PRIMITIVE")
516 1 : WRITE (unit_nr, '(T2,A,T61,A20)') "EC basis: ", "PRIMITIVE"
517 : CASE ("HARRIS")
518 116 : WRITE (unit_nr, '(T2,A,T61,A20)') "EC Basis: ", "HARRIS"
519 : END SELECT
520 :
521 : ! Info how HFX in energy correction is treated
522 116 : IF (ec_env%do_ec_hfx) THEN
523 :
524 8 : WRITE (unit_nr, '(T2,A,T61,L20)') "DC-DFT with HFX", ec_env%do_ec_hfx
525 8 : WRITE (unit_nr, '(T2,A,T61,L20)') "Reuse HFX integrals", ec_env%reuse_hfx
526 8 : WRITE (unit_nr, '(T2,A,T61,L20)') "DC-DFT HFX with ADMM", ec_env%do_ec_admm
527 :
528 : END IF ! ec_env%do_ec_hfx
529 :
530 : ! Parameters for Harris functional solver
531 116 : IF (ec_env%energy_functional == ec_functional_harris) THEN
532 :
533 : ! Algorithm
534 133 : SELECT CASE (ec_env%ks_solver)
535 : CASE (ec_diagonalization)
536 60 : WRITE (unit_nr, '(T2,A,T61,A20)') "Algorithm: ", "DIAGONALIZATION"
537 : CASE (ec_ot_diag)
538 2 : WRITE (unit_nr, '(T2,A,T61,A20)') "Algorithm: ", "OT DIAGONALIZATION"
539 : CASE (ec_matrix_sign)
540 1 : WRITE (unit_nr, '(T2,A,T61,A20)') "Algorithm: ", "MATRIX_SIGN"
541 : CASE (ec_matrix_trs4)
542 9 : WRITE (unit_nr, '(T2,A,T61,A20)') "Algorithm: ", "TRS4"
543 9 : CALL cite_reference(Niklasson2003)
544 : CASE (ec_matrix_tc2)
545 1 : WRITE (unit_nr, '(T2,A,T61,A20)') "Algorithm: ", "TC2"
546 74 : CALL cite_reference(Niklasson2014)
547 : END SELECT
548 73 : WRITE (unit_nr, '()')
549 :
550 : ! MAO
551 73 : IF (ec_env%mao) THEN
552 2 : WRITE (unit_nr, '(T2,A,T61,L20)') "MAO:", ec_env%mao
553 2 : WRITE (unit_nr, '(T2,A,T61,L20)') "MAO_IOLEVEL:", ec_env%mao_iolevel
554 2 : WRITE (unit_nr, '(T2,A,T61,I20)') "MAO_MAX_ITER:", ec_env%mao_max_iter
555 2 : WRITE (unit_nr, '(T2,A,T61,E20.3)') "MAO_EPS_GRAD:", ec_env%mao_eps_grad
556 2 : WRITE (unit_nr, '(T2,A,T61,E20.3)') "MAO_EPS1:", ec_env%mao_eps1
557 2 : WRITE (unit_nr, '()')
558 : END IF
559 :
560 : ! Parameters for linear response solver
561 73 : IF (.NOT. ec_env%use_ls_solver) THEN
562 :
563 62 : WRITE (unit_nr, '(T2,A)') "MO Solver"
564 62 : WRITE (unit_nr, '()')
565 :
566 122 : SELECT CASE (ec_env%ks_solver)
567 : CASE (ec_diagonalization)
568 :
569 60 : SELECT CASE (ec_env%factorization)
570 : CASE (kg_cholesky)
571 60 : WRITE (unit_nr, '(T2,A,T61,A20)') "Factorization: ", "CHOLESKY"
572 : END SELECT
573 :
574 : CASE (ec_ot_diag)
575 :
576 : ! OT Diagonalization
577 : ! Initial guess : 1) block diagonal initial guess
578 : ! 2) GS-density matrix (might require trafo if basis diff)
579 :
580 2 : SELECT CASE (ec_env%ec_initial_guess)
581 : CASE (ec_ot_atomic)
582 1 : WRITE (unit_nr, '(T2,A,T61,A20)') "OT Diag initial guess: ", "ATOMIC"
583 : CASE (ec_ot_gs)
584 1 : WRITE (unit_nr, '(T2,A,T61,A20)') "OT Diag initial guess: ", "GROUND STATE DM"
585 : END SELECT
586 :
587 : CASE DEFAULT
588 62 : CPABORT("Unknown Diagonalization algorithm for Harris functional")
589 : END SELECT
590 :
591 : ELSE
592 :
593 11 : WRITE (unit_nr, '(T2,A)') "AO Solver"
594 11 : WRITE (unit_nr, '()')
595 :
596 11 : ls_env => ec_env%ls_env
597 11 : WRITE (unit_nr, '(T2,A,T61,E20.3)') "eps_filter:", ls_env%eps_filter
598 11 : WRITE (unit_nr, '(T2,A,T61,L20)') "fixed chemical potential (mu)", ls_env%fixed_mu
599 11 : WRITE (unit_nr, '(T2,A,T61,L20)') "Computing inv(S):", ls_env%needs_s_inv
600 11 : WRITE (unit_nr, '(T2,A,T61,L20)') "Computing sqrt(S):", ls_env%use_s_sqrt
601 11 : WRITE (unit_nr, '(T2,A,T61,L20)') "Computing S preconditioner ", ls_env%has_s_preconditioner
602 :
603 11 : IF (ls_env%use_s_sqrt) THEN
604 21 : SELECT CASE (ls_env%s_sqrt_method)
605 : CASE (ls_s_sqrt_ns)
606 10 : WRITE (unit_nr, '(T2,A,T61,A20)') "S sqrt method:", "NEWTONSCHULZ"
607 : CASE (ls_s_sqrt_proot)
608 1 : WRITE (unit_nr, '(T2,A,T61,A20)') "S sqrt method:", "PROOT"
609 : CASE DEFAULT
610 11 : CPABORT("Unknown sqrt method.")
611 : END SELECT
612 11 : WRITE (unit_nr, '(T2,A,T61,I20)') "S sqrt order:", ls_env%s_sqrt_order
613 : END IF
614 :
615 11 : SELECT CASE (ls_env%s_preconditioner_type)
616 : CASE (ls_s_preconditioner_none)
617 0 : WRITE (unit_nr, '(T2,A,T61,A20)') "S preconditioner type ", "NONE"
618 : CASE (ls_s_preconditioner_atomic)
619 11 : WRITE (unit_nr, '(T2,A,T61,A20)') "S preconditioner type ", "ATOMIC"
620 : CASE (ls_s_preconditioner_molecular)
621 11 : WRITE (unit_nr, '(T2,A,T61,A20)') "S preconditioner type ", "MOLECULAR"
622 : END SELECT
623 :
624 22 : SELECT CASE (ls_env%ls_mstruct%cluster_type)
625 : CASE (ls_cluster_atomic)
626 11 : WRITE (unit_nr, '(T2,A,T61,A20)') "Cluster type", ADJUSTR("ATOMIC")
627 : CASE (ls_cluster_molecular)
628 0 : WRITE (unit_nr, '(T2,A,T61,A20)') "Cluster type", ADJUSTR("MOLECULAR")
629 : CASE DEFAULT
630 11 : CPABORT("Unknown cluster type")
631 : END SELECT
632 :
633 : END IF
634 :
635 : END IF ! if ec_functional_harris
636 :
637 116 : WRITE (unit_nr, '(T2,A)') REPEAT("-", 79)
638 116 : WRITE (unit_nr, '()')
639 :
640 : END IF ! unit_nr
641 :
642 232 : CALL timestop(handle)
643 :
644 232 : END SUBROUTINE ec_write_input
645 :
646 : END MODULE ec_environment
|