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 almo_scf_env methods
10 : !> \par History
11 : !> 2016.12 created [Rustam Z Khaliullin]
12 : !> \author Rustam Z Khaliullin
13 : ! **************************************************************************************************
14 : MODULE almo_scf_env_methods
15 :
16 : USE almo_scf_types, ONLY: almo_max_cutoff_multiplier,&
17 : almo_scf_env_type
18 : USE cp_control_types, ONLY: dft_control_type
19 : USE input_constants, ONLY: &
20 : almo_constraint_distance, almo_deloc_none, almo_deloc_xalmo_1diag, &
21 : almo_domain_layout_atomic, almo_domain_layout_molecular, almo_frz_crystal, &
22 : almo_mat_distr_molecular, almo_scf_diag, almo_scf_skip, almo_scf_trustr, cg_hager_zhang, &
23 : do_bondparm_vdw, molecular_guess, tensor_orthogonal, virt_full, virt_minimal, virt_number, &
24 : xalmo_trial_r0_out
25 : USE input_section_types, ONLY: section_vals_get_subs_vals,&
26 : section_vals_type,&
27 : section_vals_val_get
28 : USE kinds, ONLY: dp
29 : USE qs_environment_types, ONLY: get_qs_env,&
30 : qs_environment_type,&
31 : set_qs_env
32 : #include "./base/base_uses.f90"
33 :
34 : IMPLICIT NONE
35 :
36 : PRIVATE
37 :
38 : CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'almo_scf_env_methods'
39 :
40 : PUBLIC :: almo_scf_env_create
41 :
42 : CONTAINS
43 :
44 : ! **************************************************************************************************
45 : !> \brief Creation and basic initialization of the almo environment
46 : !> \param qs_env ...
47 : !> \par History
48 : !> 2016.11 created [Rustam Z Khaliullin]
49 : !> \author Rustam Z Khaliullin
50 : ! **************************************************************************************************
51 66 : SUBROUTINE almo_scf_env_create(qs_env)
52 : TYPE(qs_environment_type), POINTER :: qs_env
53 :
54 : CHARACTER(len=*), PARAMETER :: routineN = 'almo_scf_env_create'
55 :
56 : INTEGER :: handle, nallocate
57 : TYPE(almo_scf_env_type), POINTER :: almo_scf_env
58 : TYPE(dft_control_type), POINTER :: dft_control
59 : TYPE(section_vals_type), POINTER :: input
60 :
61 66 : CALL timeset(routineN, handle)
62 :
63 792 : ALLOCATE (almo_scf_env)
64 :
65 : ! get basic quantities from the qs_env
66 66 : CALL get_qs_env(qs_env, input=input, dft_control=dft_control)
67 :
68 : ! parse the almo_scf section and set appropriate quantities
69 66 : CALL almo_scf_init_read_write_input(input, almo_scf_env)
70 :
71 : ! set up the buffer for the history of matrices
72 66 : almo_scf_env%nspins = dft_control%nspins
73 66 : almo_scf_env%almo_history%nstore = almo_scf_env%almo_extrapolation_order
74 66 : almo_scf_env%almo_history%istore = 0
75 : ! do not allocate zero
76 66 : nallocate = MAX(1, almo_scf_env%almo_extrapolation_order)
77 644 : ALLOCATE (almo_scf_env%almo_history%matrix_p_up_down(almo_scf_env%nspins, nallocate))
78 264 : ALLOCATE (almo_scf_env%almo_history%matrix_t(almo_scf_env%nspins))
79 66 : almo_scf_env%xalmo_history%nstore = almo_scf_env%xalmo_extrapolation_order
80 66 : almo_scf_env%xalmo_history%istore = 0
81 66 : nallocate = MAX(1, almo_scf_env%xalmo_extrapolation_order)
82 424 : ALLOCATE (almo_scf_env%xalmo_history%matrix_p_up_down(almo_scf_env%nspins, nallocate))
83 : !ALLOCATE (almo_scf_env%xalmo_history%matrix_x(almo_scf_env%nspins, nallocate))
84 264 : ALLOCATE (almo_scf_env%xalmo_history%matrix_t(almo_scf_env%nspins))
85 :
86 : ! put almo_scf_env in qs_env
87 66 : CALL set_qs_env(qs_env, almo_scf_env=almo_scf_env)
88 :
89 66 : CALL timestop(handle)
90 :
91 66 : END SUBROUTINE almo_scf_env_create
92 :
93 : ! **************************************************************************************************
94 : !> \brief Parses the ALMO input section
95 : !> \param input ...
96 : !> \param almo_scf_env ...
97 : !> \par History
98 : !> 2011.05 created [Rustam Z Khaliullin]
99 : !> \author Rustam Z Khaliullin
100 : ! **************************************************************************************************
101 66 : SUBROUTINE almo_scf_init_read_write_input(input, almo_scf_env)
102 : TYPE(section_vals_type), POINTER :: input
103 : TYPE(almo_scf_env_type), INTENT(INOUT) :: almo_scf_env
104 :
105 : CHARACTER(len=*), PARAMETER :: routineN = 'almo_scf_init_read_write_input'
106 :
107 : INTEGER :: handle
108 : TYPE(section_vals_type), POINTER :: almo_analysis_section, almo_opt_diis_section, &
109 : almo_opt_pcg_section, almo_opt_trustr_section, almo_scf_section, matrix_iterate_section, &
110 : nlmo_opt_pcg_section, penalty_section, xalmo_opt_newton_pcg_section, &
111 : xalmo_opt_pcg_section, xalmo_opt_trustr_section
112 :
113 66 : CALL timeset(routineN, handle)
114 :
115 66 : almo_scf_section => section_vals_get_subs_vals(input, "DFT%ALMO_SCF")
116 : almo_opt_diis_section => section_vals_get_subs_vals(almo_scf_section, &
117 66 : "ALMO_OPTIMIZER_DIIS")
118 : almo_opt_pcg_section => section_vals_get_subs_vals(almo_scf_section, &
119 66 : "ALMO_OPTIMIZER_PCG")
120 : almo_opt_trustr_section => section_vals_get_subs_vals(almo_scf_section, &
121 66 : "ALMO_OPTIMIZER_TRUSTR")
122 : xalmo_opt_pcg_section => section_vals_get_subs_vals(almo_scf_section, &
123 66 : "XALMO_OPTIMIZER_PCG")
124 : xalmo_opt_trustr_section => section_vals_get_subs_vals(almo_scf_section, &
125 66 : "XALMO_OPTIMIZER_TRUSTR")
126 : nlmo_opt_pcg_section => section_vals_get_subs_vals(almo_scf_section, &
127 66 : "NLMO_OPTIMIZER_PCG")
128 66 : almo_analysis_section => section_vals_get_subs_vals(almo_scf_section, "ANALYSIS")
129 : xalmo_opt_newton_pcg_section => section_vals_get_subs_vals(xalmo_opt_pcg_section, &
130 66 : "XALMO_NEWTON_PCG_SOLVER")
131 : matrix_iterate_section => section_vals_get_subs_vals(almo_scf_section, &
132 66 : "MATRIX_ITERATE")
133 :
134 : ! read user input
135 : ! common ALMO options
136 : CALL section_vals_val_get(almo_scf_section, "EPS_FILTER", &
137 66 : r_val=almo_scf_env%eps_filter)
138 : CALL section_vals_val_get(almo_scf_section, "ALMO_SCF_GUESS", &
139 66 : i_val=almo_scf_env%almo_scf_guess)
140 : CALL section_vals_val_get(almo_scf_section, "ALMO_ALGORITHM", &
141 66 : i_val=almo_scf_env%almo_update_algorithm)
142 : CALL section_vals_val_get(almo_scf_section, "XALMO_ALGORITHM", &
143 66 : i_val=almo_scf_env%xalmo_update_algorithm)
144 : CALL section_vals_val_get(almo_scf_section, "XALMO_TRIAL_WF", &
145 66 : i_val=almo_scf_env%xalmo_trial_wf)
146 : CALL section_vals_val_get(almo_scf_section, "MO_OVERLAP_INV_ALG", &
147 66 : i_val=almo_scf_env%sigma_inv_algorithm)
148 : CALL section_vals_val_get(almo_scf_section, "DELOCALIZE_METHOD", &
149 66 : i_val=almo_scf_env%deloc_method)
150 : CALL section_vals_val_get(almo_scf_section, "XALMO_R_CUTOFF_FACTOR", &
151 66 : r_val=almo_scf_env%quencher_r0_factor)
152 : CALL section_vals_val_get(almo_scf_section, "ALMO_EXTRAPOLATION_ORDER", &
153 66 : i_val=almo_scf_env%almo_extrapolation_order)
154 66 : almo_scf_env%almo_extrapolation_order = MAX(0, almo_scf_env%almo_extrapolation_order)
155 : CALL section_vals_val_get(almo_scf_section, "XALMO_EXTRAPOLATION_ORDER", &
156 66 : i_val=almo_scf_env%xalmo_extrapolation_order)
157 66 : almo_scf_env%xalmo_extrapolation_order = MAX(0, almo_scf_env%xalmo_extrapolation_order)
158 : CALL section_vals_val_get(almo_scf_section, "RETURN_ORTHOGONALIZED_MOS", &
159 66 : l_val=almo_scf_env%return_orthogonalized_mos)
160 : CALL section_vals_val_get(almo_scf_section, "CONSTRUCT_NLMOS", &
161 66 : l_val=almo_scf_env%construct_nlmos)
162 :
163 : CALL section_vals_val_get(matrix_iterate_section, "EPS_LANCZOS", &
164 66 : r_val=almo_scf_env%eps_lanczos)
165 : CALL section_vals_val_get(matrix_iterate_section, "ORDER_LANCZOS", &
166 66 : i_val=almo_scf_env%order_lanczos)
167 : CALL section_vals_val_get(matrix_iterate_section, "MAX_ITER_LANCZOS", &
168 66 : i_val=almo_scf_env%max_iter_lanczos)
169 : CALL section_vals_val_get(matrix_iterate_section, "EPS_TARGET_FACTOR", &
170 66 : r_val=almo_scf_env%matrix_iter_eps_error_factor)
171 :
172 : ! optimizers
173 : CALL section_vals_val_get(almo_opt_diis_section, "EPS_ERROR", &
174 66 : r_val=almo_scf_env%opt_block_diag_diis%eps_error)
175 : CALL section_vals_val_get(almo_opt_diis_section, "MAX_ITER", &
176 66 : i_val=almo_scf_env%opt_block_diag_diis%max_iter)
177 : CALL section_vals_val_get(almo_opt_diis_section, "EPS_ERROR_EARLY", &
178 66 : r_val=almo_scf_env%opt_block_diag_diis%eps_error_early)
179 : CALL section_vals_val_get(almo_opt_diis_section, "MAX_ITER_EARLY", &
180 66 : i_val=almo_scf_env%opt_block_diag_diis%max_iter_early)
181 : CALL section_vals_val_get(almo_opt_diis_section, "N_DIIS", &
182 66 : i_val=almo_scf_env%opt_block_diag_diis%ndiis)
183 :
184 : CALL section_vals_val_get(almo_opt_pcg_section, "EPS_ERROR", &
185 66 : r_val=almo_scf_env%opt_block_diag_pcg%eps_error)
186 : CALL section_vals_val_get(almo_opt_pcg_section, "MAX_ITER", &
187 66 : i_val=almo_scf_env%opt_block_diag_pcg%max_iter)
188 : CALL section_vals_val_get(almo_opt_pcg_section, "EPS_ERROR_EARLY", &
189 66 : r_val=almo_scf_env%opt_block_diag_pcg%eps_error_early)
190 : CALL section_vals_val_get(almo_opt_pcg_section, "MAX_ITER_EARLY", &
191 66 : i_val=almo_scf_env%opt_block_diag_pcg%max_iter_early)
192 : CALL section_vals_val_get(almo_opt_pcg_section, "MAX_ITER_OUTER_LOOP", &
193 66 : i_val=almo_scf_env%opt_block_diag_pcg%max_iter_outer_loop)
194 : CALL section_vals_val_get(almo_opt_pcg_section, "LIN_SEARCH_EPS_ERROR", &
195 66 : r_val=almo_scf_env%opt_block_diag_pcg%lin_search_eps_error)
196 : CALL section_vals_val_get(almo_opt_pcg_section, "LIN_SEARCH_STEP_SIZE_GUESS", &
197 66 : r_val=almo_scf_env%opt_block_diag_pcg%lin_search_step_size_guess)
198 : CALL section_vals_val_get(almo_opt_pcg_section, "PRECOND_FILTER_THRESHOLD", &
199 66 : r_val=almo_scf_env%opt_block_diag_pcg%neglect_threshold)
200 : CALL section_vals_val_get(almo_opt_pcg_section, "CONJUGATOR", &
201 66 : i_val=almo_scf_env%opt_block_diag_pcg%conjugator)
202 : CALL section_vals_val_get(almo_opt_pcg_section, "PRECONDITIONER", &
203 66 : i_val=almo_scf_env%opt_block_diag_pcg%preconditioner)
204 :
205 : CALL section_vals_val_get(almo_opt_trustr_section, "EPS_ERROR", &
206 66 : r_val=almo_scf_env%opt_block_diag_trustr%eps_error)
207 : CALL section_vals_val_get(almo_opt_trustr_section, "MAX_ITER", &
208 66 : i_val=almo_scf_env%opt_block_diag_trustr%max_iter)
209 : CALL section_vals_val_get(almo_opt_trustr_section, "ALGORITHM", &
210 66 : i_val=almo_scf_env%opt_block_diag_trustr%trustr_algorithm)
211 : CALL section_vals_val_get(almo_opt_trustr_section, "EPS_ERROR_EARLY", &
212 66 : r_val=almo_scf_env%opt_block_diag_trustr%eps_error_early)
213 : CALL section_vals_val_get(almo_opt_trustr_section, "MAX_ITER_EARLY", &
214 66 : i_val=almo_scf_env%opt_block_diag_trustr%max_iter_early)
215 : CALL section_vals_val_get(almo_opt_trustr_section, "MAX_ITER_OUTER_LOOP", &
216 66 : i_val=almo_scf_env%opt_block_diag_trustr%max_iter_outer_loop)
217 : CALL section_vals_val_get(almo_opt_trustr_section, "ETA", &
218 66 : r_val=almo_scf_env%opt_block_diag_trustr%rho_do_not_update)
219 : almo_scf_env%opt_block_diag_trustr%rho_do_not_update = &
220 66 : MIN(MAX(almo_scf_env%opt_block_diag_trustr%rho_do_not_update, 0.0_dp), 0.25_dp)
221 : CALL section_vals_val_get(almo_opt_trustr_section, "MODEL_GRAD_NORM_RATIO", &
222 66 : r_val=almo_scf_env%opt_block_diag_trustr%model_grad_norm_ratio)
223 : CALL section_vals_val_get(almo_opt_trustr_section, "INITIAL_TRUST_RADIUS", &
224 66 : r_val=almo_scf_env%opt_block_diag_trustr%initial_trust_radius)
225 : CALL section_vals_val_get(almo_opt_trustr_section, "MAX_TRUST_RADIUS", &
226 66 : r_val=almo_scf_env%opt_block_diag_trustr%max_trust_radius)
227 : CALL section_vals_val_get(almo_opt_trustr_section, "CONJUGATOR", &
228 66 : i_val=almo_scf_env%opt_block_diag_trustr%conjugator)
229 : CALL section_vals_val_get(almo_opt_trustr_section, "PRECONDITIONER", &
230 66 : i_val=almo_scf_env%opt_block_diag_trustr%preconditioner)
231 :
232 : CALL section_vals_val_get(xalmo_opt_trustr_section, "EPS_ERROR", &
233 66 : r_val=almo_scf_env%opt_xalmo_trustr%eps_error)
234 : CALL section_vals_val_get(xalmo_opt_trustr_section, "MAX_ITER", &
235 66 : i_val=almo_scf_env%opt_xalmo_trustr%max_iter)
236 : CALL section_vals_val_get(xalmo_opt_trustr_section, "ALGORITHM", &
237 66 : i_val=almo_scf_env%opt_xalmo_trustr%trustr_algorithm)
238 : CALL section_vals_val_get(xalmo_opt_trustr_section, "EPS_ERROR_EARLY", &
239 66 : r_val=almo_scf_env%opt_xalmo_trustr%eps_error_early)
240 : CALL section_vals_val_get(xalmo_opt_trustr_section, "MAX_ITER_EARLY", &
241 66 : i_val=almo_scf_env%opt_xalmo_trustr%max_iter_early)
242 : CALL section_vals_val_get(xalmo_opt_trustr_section, "MAX_ITER_OUTER_LOOP", &
243 66 : i_val=almo_scf_env%opt_xalmo_trustr%max_iter_outer_loop)
244 : CALL section_vals_val_get(xalmo_opt_trustr_section, "ETA", &
245 66 : r_val=almo_scf_env%opt_xalmo_trustr%rho_do_not_update)
246 : almo_scf_env%opt_xalmo_trustr%rho_do_not_update = &
247 66 : MIN(MAX(almo_scf_env%opt_xalmo_trustr%rho_do_not_update, 0.0_dp), 0.25_dp)
248 : CALL section_vals_val_get(xalmo_opt_trustr_section, "MODEL_GRAD_NORM_RATIO", &
249 66 : r_val=almo_scf_env%opt_xalmo_trustr%model_grad_norm_ratio)
250 : CALL section_vals_val_get(xalmo_opt_trustr_section, "INITIAL_TRUST_RADIUS", &
251 66 : r_val=almo_scf_env%opt_xalmo_trustr%initial_trust_radius)
252 : CALL section_vals_val_get(xalmo_opt_trustr_section, "MAX_TRUST_RADIUS", &
253 66 : r_val=almo_scf_env%opt_xalmo_trustr%max_trust_radius)
254 : CALL section_vals_val_get(xalmo_opt_trustr_section, "CONJUGATOR", &
255 66 : i_val=almo_scf_env%opt_xalmo_trustr%conjugator)
256 : CALL section_vals_val_get(xalmo_opt_trustr_section, "PRECONDITIONER", &
257 66 : i_val=almo_scf_env%opt_xalmo_trustr%preconditioner)
258 :
259 : CALL section_vals_val_get(xalmo_opt_pcg_section, "EPS_ERROR", &
260 66 : r_val=almo_scf_env%opt_xalmo_pcg%eps_error)
261 : CALL section_vals_val_get(xalmo_opt_pcg_section, "MAX_ITER", &
262 66 : i_val=almo_scf_env%opt_xalmo_pcg%max_iter)
263 : CALL section_vals_val_get(xalmo_opt_pcg_section, "EPS_ERROR_EARLY", &
264 66 : r_val=almo_scf_env%opt_xalmo_pcg%eps_error_early)
265 : CALL section_vals_val_get(xalmo_opt_pcg_section, "MAX_ITER_EARLY", &
266 66 : i_val=almo_scf_env%opt_xalmo_pcg%max_iter_early)
267 : CALL section_vals_val_get(xalmo_opt_pcg_section, "MAX_ITER_OUTER_LOOP", &
268 66 : i_val=almo_scf_env%opt_xalmo_pcg%max_iter_outer_loop)
269 : CALL section_vals_val_get(xalmo_opt_pcg_section, "LIN_SEARCH_EPS_ERROR", &
270 66 : r_val=almo_scf_env%opt_xalmo_pcg%lin_search_eps_error)
271 : CALL section_vals_val_get(xalmo_opt_pcg_section, "LIN_SEARCH_STEP_SIZE_GUESS", &
272 66 : r_val=almo_scf_env%opt_xalmo_pcg%lin_search_step_size_guess)
273 : CALL section_vals_val_get(xalmo_opt_pcg_section, "PRECOND_FILTER_THRESHOLD", &
274 66 : r_val=almo_scf_env%opt_xalmo_pcg%neglect_threshold)
275 : CALL section_vals_val_get(xalmo_opt_pcg_section, "CONJUGATOR", &
276 66 : i_val=almo_scf_env%opt_xalmo_pcg%conjugator)
277 : CALL section_vals_val_get(xalmo_opt_pcg_section, "PRECONDITIONER", &
278 66 : i_val=almo_scf_env%opt_xalmo_pcg%preconditioner)
279 :
280 66 : penalty_section => section_vals_get_subs_vals(nlmo_opt_pcg_section, "PENALTY")
281 : CALL section_vals_val_get(nlmo_opt_pcg_section, "EPS_ERROR", &
282 66 : r_val=almo_scf_env%opt_nlmo_pcg%eps_error)
283 : CALL section_vals_val_get(nlmo_opt_pcg_section, "MAX_ITER", &
284 66 : i_val=almo_scf_env%opt_nlmo_pcg%max_iter)
285 : CALL section_vals_val_get(nlmo_opt_pcg_section, "EPS_ERROR_EARLY", &
286 66 : r_val=almo_scf_env%opt_nlmo_pcg%eps_error_early)
287 : CALL section_vals_val_get(nlmo_opt_pcg_section, "MAX_ITER_EARLY", &
288 66 : i_val=almo_scf_env%opt_nlmo_pcg%max_iter_early)
289 : CALL section_vals_val_get(nlmo_opt_pcg_section, "MAX_ITER_OUTER_LOOP", &
290 66 : i_val=almo_scf_env%opt_nlmo_pcg%max_iter_outer_loop)
291 : CALL section_vals_val_get(nlmo_opt_pcg_section, "LIN_SEARCH_EPS_ERROR", &
292 66 : r_val=almo_scf_env%opt_nlmo_pcg%lin_search_eps_error)
293 : CALL section_vals_val_get(nlmo_opt_pcg_section, "LIN_SEARCH_STEP_SIZE_GUESS", &
294 66 : r_val=almo_scf_env%opt_nlmo_pcg%lin_search_step_size_guess)
295 : CALL section_vals_val_get(nlmo_opt_pcg_section, "PRECOND_FILTER_THRESHOLD", &
296 66 : r_val=almo_scf_env%opt_nlmo_pcg%neglect_threshold)
297 : CALL section_vals_val_get(nlmo_opt_pcg_section, "CONJUGATOR", &
298 66 : i_val=almo_scf_env%opt_nlmo_pcg%conjugator)
299 : CALL section_vals_val_get(nlmo_opt_pcg_section, "PRECONDITIONER", &
300 66 : i_val=almo_scf_env%opt_nlmo_pcg%preconditioner)
301 : CALL section_vals_val_get(penalty_section, &
302 : "OPERATOR", &
303 66 : i_val=almo_scf_env%opt_nlmo_pcg%opt_penalty%operator_type)
304 : CALL section_vals_val_get(penalty_section, &
305 : "PENALTY_STRENGTH", &
306 66 : r_val=almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength)
307 : CALL section_vals_val_get(penalty_section, &
308 : "PENALTY_STRENGTH_DECREASE_FACTOR", &
309 66 : r_val=almo_scf_env%opt_nlmo_pcg%opt_penalty%penalty_strength_dec_factor)
310 : CALL section_vals_val_get(penalty_section, &
311 : "DETERMINANT_TOLERANCE", &
312 66 : r_val=almo_scf_env%opt_nlmo_pcg%opt_penalty%determinant_tolerance)
313 : CALL section_vals_val_get(penalty_section, &
314 : "FINAL_DETERMINANT", &
315 66 : r_val=almo_scf_env%opt_nlmo_pcg%opt_penalty%final_determinant)
316 : CALL section_vals_val_get(penalty_section, &
317 : "COMPACTIFICATION_FILTER_START", &
318 66 : r_val=almo_scf_env%opt_nlmo_pcg%opt_penalty%compactification_filter_start)
319 : CALL section_vals_val_get(penalty_section, &
320 : "VIRTUAL_NLMOS", &
321 66 : l_val=almo_scf_env%opt_nlmo_pcg%opt_penalty%virtual_nlmos)
322 :
323 : CALL section_vals_val_get(xalmo_opt_newton_pcg_section, "EPS_ERROR", &
324 66 : r_val=almo_scf_env%opt_xalmo_newton_pcg_solver%eps_error)
325 : CALL section_vals_val_get(xalmo_opt_newton_pcg_section, "MAX_ITER", &
326 66 : i_val=almo_scf_env%opt_xalmo_newton_pcg_solver%max_iter)
327 : CALL section_vals_val_get(xalmo_opt_newton_pcg_section, "MAX_ITER_OUTER_LOOP", &
328 66 : i_val=almo_scf_env%opt_xalmo_newton_pcg_solver%max_iter_outer_loop)
329 : CALL section_vals_val_get(xalmo_opt_newton_pcg_section, "PRECONDITIONER", &
330 66 : i_val=almo_scf_env%opt_xalmo_newton_pcg_solver%preconditioner)
331 :
332 : CALL section_vals_val_get(almo_analysis_section, "_SECTION_PARAMETERS_", &
333 66 : l_val=almo_scf_env%almo_analysis%do_analysis)
334 : CALL section_vals_val_get(almo_analysis_section, "FROZEN_MO_ENERGY_TERM", &
335 66 : i_val=almo_scf_env%almo_analysis%frozen_mo_energy_term)
336 :
337 : !CALL section_vals_val_get(almo_scf_section,"DOMAIN_LAYOUT_AOS",&
338 : ! i_val=almo_scf_env%domain_layout_aos)
339 : !CALL section_vals_val_get(almo_scf_section,"DOMAIN_LAYOUT_MOS",&
340 : ! i_val=almo_scf_env%domain_layout_mos)
341 : !CALL section_vals_val_get(almo_scf_section,"MATRIX_CLUSTERING_AOS",&
342 : ! i_val=almo_scf_env%mat_distr_aos)
343 : !CALL section_vals_val_get(almo_scf_section,"MATRIX_CLUSTERING_MOS",&
344 : ! i_val=almo_scf_env%mat_distr_mos)
345 : !CALL section_vals_val_get(almo_scf_section,"CONSTRAINT_TYPE",&
346 : ! i_val=almo_scf_env%constraint_type)
347 : !CALL section_vals_val_get(almo_scf_section,"MU",&
348 : ! r_val=almo_scf_env%mu)
349 : !CALL section_vals_val_get(almo_scf_section,"FIXED_MU",&
350 : ! l_val=almo_scf_env%fixed_mu)
351 : !CALL section_vals_val_get(almo_scf_section,"EPS_USE_PREV_AS_GUESS",&
352 : ! r_val=almo_scf_env%eps_prev_guess)
353 : !CALL section_vals_val_get(almo_scf_section,"MIXING_FRACTION",&
354 : ! r_val=almo_scf_env%mixing_fraction)
355 : !CALL section_vals_val_get(almo_scf_section,"DELOC_CAYLEY_TENSOR_TYPE",&
356 : ! i_val=almo_scf_env%deloc_cayley_tensor_type)
357 : !CALL section_vals_val_get(almo_scf_section,"DELOC_CAYLEY_CONJUGATOR",&
358 : ! i_val=almo_scf_env%deloc_cayley_conjugator)
359 : !CALL section_vals_val_get(almo_scf_section,"DELOC_CAYLEY_MAX_ITER",&
360 : ! i_val=almo_scf_env%deloc_cayley_max_iter)
361 : !CALL section_vals_val_get(almo_scf_section,"DELOC_USE_OCC_ORBS",&
362 : ! l_val=almo_scf_env%deloc_use_occ_orbs)
363 : !CALL section_vals_val_get(almo_scf_section,"DELOC_CAYLEY_USE_VIRT_ORBS",&
364 : ! l_val=almo_scf_env%deloc_cayley_use_virt_orbs)
365 : !CALL section_vals_val_get(almo_scf_section,"DELOC_CAYLEY_LINEAR",&
366 : ! l_val=almo_scf_env%deloc_cayley_linear)
367 : !CALL section_vals_val_get(almo_scf_section,"DELOC_CAYLEY_EPS_CONVERGENCE",&
368 : ! r_val=almo_scf_env%deloc_cayley_eps_convergence)
369 : !CALL section_vals_val_get(almo_scf_section,"DELOC_CAYLEY_OCC_PRECOND",&
370 : ! l_val=almo_scf_env%deloc_cayley_occ_precond)
371 : !CALL section_vals_val_get(almo_scf_section,"DELOC_CAYLEY_VIR_PRECOND",&
372 : ! l_val=almo_scf_env%deloc_cayley_vir_precond)
373 : !CALL section_vals_val_get(almo_scf_section,"ALMO_UPDATE_ALGORITHM_BD",&
374 : ! i_val=almo_scf_env%almo_update_algorithm)
375 : !CALL section_vals_val_get(almo_scf_section,"DELOC_TRUNCATE_VIRTUALS",&
376 : ! i_val=almo_scf_env%deloc_truncate_virt)
377 : !CALL section_vals_val_get(almo_scf_section,"DELOC_VIRT_PER_DOMAIN",&
378 : ! i_val=almo_scf_env%deloc_virt_per_domain)
379 : !
380 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_EPS_CONVERGENCE",&
381 : ! r_val=almo_scf_env%opt_k_eps_convergence)
382 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_MAX_ITER",&
383 : ! i_val=almo_scf_env%opt_k_max_iter)
384 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_OUTER_MAX_ITER",&
385 : ! i_val=almo_scf_env%opt_k_outer_max_iter)
386 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_TRIAL_STEP_SIZE",&
387 : ! r_val=almo_scf_env%opt_k_trial_step_size)
388 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_CONJUGATOR",&
389 : ! i_val=almo_scf_env%opt_k_conjugator)
390 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_TRIAL_STEP_SIZE_MULTIPLIER",&
391 : ! r_val=almo_scf_env%opt_k_trial_step_size_multiplier)
392 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_CONJ_ITER_START",&
393 : ! i_val=almo_scf_env%opt_k_conj_iter_start)
394 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_PREC_ITER_START",&
395 : ! i_val=almo_scf_env%opt_k_prec_iter_start)
396 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_CONJ_ITER_FREQ_RESET",&
397 : ! i_val=almo_scf_env%opt_k_conj_iter_freq)
398 : !CALL section_vals_val_get(almo_scf_section,"OPT_K_PREC_ITER_FREQ_UPDATE",&
399 : ! i_val=almo_scf_env%opt_k_prec_iter_freq)
400 : !
401 : !CALL section_vals_val_get(almo_scf_section,"QUENCHER_RADIUS_TYPE",&
402 : ! i_val=almo_scf_env%quencher_radius_type)
403 : !CALL section_vals_val_get(almo_scf_section,"QUENCHER_R0_FACTOR",&
404 : ! r_val=almo_scf_env%quencher_r0_factor)
405 : !CALL section_vals_val_get(almo_scf_section,"QUENCHER_R1_FACTOR",&
406 : ! r_val=almo_scf_env%quencher_r1_factor)
407 : !!CALL section_vals_val_get(almo_scf_section,"QUENCHER_R0_SHIFT",&
408 : !! r_val=almo_scf_env%quencher_r0_shift)
409 : !!
410 : !!CALL section_vals_val_get(almo_scf_section,"QUENCHER_R1_SHIFT",&
411 : !! r_val=almo_scf_env%quencher_r1_shift)
412 : !!
413 : !!almo_scf_env%quencher_r0_shift = cp_unit_to_cp2k(&
414 : !! almo_scf_env%quencher_r0_shift,"angstrom")
415 : !!almo_scf_env%quencher_r1_shift = cp_unit_to_cp2k(&
416 : !! almo_scf_env%quencher_r1_shift,"angstrom")
417 : !
418 : !CALL section_vals_val_get(almo_scf_section,"QUENCHER_AO_OVERLAP_0",&
419 : ! r_val=almo_scf_env%quencher_s0)
420 : !CALL section_vals_val_get(almo_scf_section,"QUENCHER_AO_OVERLAP_1",&
421 : ! r_val=almo_scf_env%quencher_s1)
422 :
423 : !CALL section_vals_val_get(almo_scf_section,"ENVELOPE_AMPLITUDE",&
424 : ! r_val=almo_scf_env%envelope_amplitude)
425 :
426 : !! how to read lists
427 : !CALL section_vals_val_get(almo_scf_section,"INT_LIST01", &
428 : ! n_rep_val=n_rep)
429 : !counter_i = 0
430 : !DO k = 1,n_rep
431 : ! CALL section_vals_val_get(almo_scf_section,"INT_LIST01",&
432 : ! i_rep_val=k,i_vals=tmplist)
433 : ! DO jj = 1,SIZE(tmplist)
434 : ! counter_i=counter_i+1
435 : ! almo_scf_env%charge_of_domain(counter_i)=tmplist(jj)
436 : ! ENDDO
437 : !ENDDO
438 :
439 66 : almo_scf_env%domain_layout_aos = almo_domain_layout_molecular
440 66 : almo_scf_env%domain_layout_mos = almo_domain_layout_molecular
441 66 : almo_scf_env%mat_distr_aos = almo_mat_distr_molecular
442 66 : almo_scf_env%mat_distr_mos = almo_mat_distr_molecular
443 :
444 66 : almo_scf_env%constraint_type = almo_constraint_distance
445 66 : almo_scf_env%mu = -0.1_dp
446 66 : almo_scf_env%fixed_mu = .FALSE.
447 66 : almo_scf_env%mixing_fraction = 0.45_dp
448 66 : almo_scf_env%eps_prev_guess = almo_scf_env%eps_filter/1000.0_dp
449 :
450 66 : almo_scf_env%deloc_cayley_tensor_type = tensor_orthogonal
451 66 : almo_scf_env%deloc_cayley_conjugator = cg_hager_zhang
452 66 : almo_scf_env%deloc_cayley_max_iter = 100
453 66 : almo_scf_env%deloc_use_occ_orbs = .TRUE.
454 66 : almo_scf_env%deloc_cayley_use_virt_orbs = .FALSE.
455 66 : almo_scf_env%deloc_cayley_linear = .FALSE.
456 66 : almo_scf_env%deloc_cayley_eps_convergence = 1.0E-6_dp
457 66 : almo_scf_env%deloc_cayley_occ_precond = .TRUE.
458 66 : almo_scf_env%deloc_cayley_vir_precond = .TRUE.
459 66 : almo_scf_env%deloc_truncate_virt = virt_full
460 66 : almo_scf_env%deloc_virt_per_domain = -1
461 :
462 66 : almo_scf_env%opt_k_eps_convergence = 1.0E-5_dp
463 66 : almo_scf_env%opt_k_max_iter = 100
464 66 : almo_scf_env%opt_k_outer_max_iter = 1
465 66 : almo_scf_env%opt_k_trial_step_size = 0.05_dp
466 66 : almo_scf_env%opt_k_conjugator = cg_hager_zhang
467 66 : almo_scf_env%opt_k_trial_step_size_multiplier = 1.05_dp
468 66 : almo_scf_env%opt_k_conj_iter_start = 0
469 66 : almo_scf_env%opt_k_prec_iter_start = 0
470 66 : almo_scf_env%opt_k_conj_iter_freq = 10000000
471 66 : almo_scf_env%opt_k_prec_iter_freq = 10000000
472 :
473 66 : almo_scf_env%quencher_radius_type = do_bondparm_vdw
474 66 : almo_scf_env%quencher_r1_factor = almo_scf_env%quencher_r0_factor
475 : !almo_scf_env%quencher_r0_shift=0.0_dp
476 : !almo_scf_env%quencher_r1_shift=0.0_dp
477 : !almo_scf_env%quencher_r0_shift = cp_unit_to_cp2k(&
478 : ! almo_scf_env%quencher_r0_shift,"angstrom")
479 : !almo_scf_env%quencher_r1_shift = cp_unit_to_cp2k(&
480 : ! almo_scf_env%quencher_r1_shift,"angstrom")
481 :
482 66 : almo_scf_env%quencher_s0 = 1.0E-4_dp
483 66 : almo_scf_env%quencher_s1 = 1.0E-6_dp
484 :
485 66 : almo_scf_env%envelope_amplitude = 1.0_dp
486 :
487 66 : almo_scf_env%logical01 = .FALSE. ! md in eDOF space
488 66 : almo_scf_env%logical02 = .TRUE. ! not used
489 66 : almo_scf_env%logical03 = .TRUE. ! not used
490 66 : almo_scf_env%logical04 = .TRUE. ! use preconditioner
491 66 : almo_scf_env%logical05 = .FALSE. ! optimize theta
492 :
493 66 : almo_scf_env%real01 = almo_scf_env%eps_filter/10.0_dp ! skip gradients
494 66 : almo_scf_env%real02 = 0.0_dp ! not used
495 66 : almo_scf_env%real03 = 0.0_dp ! not used
496 66 : almo_scf_env%real04 = 0.5_dp ! mixing s-f precond
497 :
498 66 : almo_scf_env%integer01 = 10 ! start eDOF-md
499 66 : almo_scf_env%integer02 = 4 ! preconditioner type
500 66 : almo_scf_env%integer03 = 0 ! not used
501 66 : almo_scf_env%integer04 = 0 ! fixed number of line searches (no grad)
502 66 : almo_scf_env%integer05 = 0 ! not used
503 :
504 : ! check for conflicts between options
505 66 : IF (almo_scf_env%xalmo_trial_wf .EQ. xalmo_trial_r0_out .AND. &
506 : almo_scf_env%xalmo_update_algorithm .EQ. almo_scf_trustr) THEN
507 0 : CPABORT("Trust region algorithm cannot optimize projected XALMOs")
508 : END IF
509 :
510 : CALL section_vals_val_get(almo_scf_section, "XALMO_ALGORITHM", &
511 66 : i_val=almo_scf_env%xalmo_update_algorithm)
512 : CALL section_vals_val_get(almo_scf_section, "XALMO_TRIAL_WF", &
513 66 : i_val=almo_scf_env%xalmo_trial_wf)
514 66 : IF (almo_scf_env%deloc_method .EQ. almo_deloc_xalmo_1diag .AND. &
515 : almo_scf_env%xalmo_update_algorithm .NE. almo_scf_diag) THEN
516 0 : CPABORT("1-step delocalization correction requires a different algorithm")
517 : END IF
518 :
519 : IF (almo_scf_env%xalmo_trial_wf .EQ. xalmo_trial_r0_out .AND. &
520 66 : almo_scf_env%almo_update_algorithm .EQ. almo_scf_skip .AND. &
521 : almo_scf_env%almo_scf_guess .NE. molecular_guess) THEN
522 0 : CPABORT("R0 projector requires optimized ALMOs")
523 : END IF
524 :
525 66 : IF (almo_scf_env%deloc_method .EQ. almo_deloc_none .AND. &
526 : almo_scf_env%almo_update_algorithm .EQ. almo_scf_skip) THEN
527 0 : CPABORT("No optimization requested")
528 : END IF
529 :
530 66 : IF (almo_scf_env%deloc_truncate_virt .EQ. virt_number .AND. &
531 : almo_scf_env%deloc_virt_per_domain .LE. 0) THEN
532 0 : CPABORT("specify a positive number of virtual orbitals")
533 : END IF
534 :
535 66 : IF (almo_scf_env%deloc_truncate_virt .EQ. virt_minimal) THEN
536 0 : CPABORT("VIRT TRUNCATION TO MINIMAL BASIS IS NIY")
537 : END IF
538 :
539 66 : IF (almo_scf_env%domain_layout_mos .NE. almo_domain_layout_molecular) THEN
540 0 : CPABORT("use MOLECULAR domains")
541 : END IF
542 :
543 66 : IF (almo_scf_env%domain_layout_aos .NE. almo_domain_layout_molecular) THEN
544 0 : CPABORT("use MOLECULAR domains")
545 : END IF
546 :
547 66 : IF (almo_scf_env%mat_distr_mos .NE. almo_mat_distr_molecular) THEN
548 0 : CPABORT("use MOLECULAR distr for MOs")
549 : END IF
550 :
551 66 : IF (almo_scf_env%mat_distr_aos == almo_mat_distr_molecular .AND. &
552 : almo_scf_env%domain_layout_aos == almo_domain_layout_atomic) THEN
553 0 : CPABORT("AO blocks cannot be larger than domains")
554 : END IF
555 :
556 66 : IF (almo_scf_env%mat_distr_mos == almo_mat_distr_molecular .AND. &
557 : almo_scf_env%domain_layout_mos == almo_domain_layout_atomic) THEN
558 0 : CPABORT("MO blocks cannot be larger than domains")
559 : END IF
560 :
561 66 : IF (almo_scf_env%quencher_r1_factor .GT. almo_max_cutoff_multiplier) THEN
562 : CALL cp_abort(__LOCATION__, &
563 : "XALMO_R_CUTOFF_FACTOR is larger than almo_max_cutoff_multiplier. "// &
564 0 : "Increase the hard-coded almo_max_cutoff_multiplier")
565 : END IF
566 :
567 : ! check analysis settings
568 66 : IF (almo_scf_env%almo_analysis%do_analysis) THEN
569 :
570 : IF (almo_scf_env%almo_analysis%frozen_mo_energy_term == almo_frz_crystal &
571 2 : .AND. almo_scf_env%almo_scf_guess .NE. molecular_guess) THEN
572 0 : CPABORT("To compute frozen-MO energy term set ALMO_SCF_GUESS MOLECULAR")
573 : END IF
574 :
575 : END IF ! end analysis settings
576 :
577 66 : CALL timestop(handle)
578 :
579 66 : END SUBROUTINE almo_scf_init_read_write_input
580 :
581 : END MODULE almo_scf_env_methods
582 :
|