(git:591cf04)
Loading...
Searching...
No Matches
optimize_basis.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
14 USE cp_fm_types, ONLY: cp_fm_release,&
31 USE input_cp2k_read, ONLY: empty_initial_variables,&
41 USE kinds, ONLY: default_path_length,&
43 dp
44 USE machine, ONLY: m_chdir,&
45 m_getcwd,&
47 USE message_passing, ONLY: mp_comm_type,&
74 USE physcon, ONLY: evolt
75 USE powell, ONLY: powell_optimize
76 USE qs_environment, ONLY: qs_init
84 USE qs_ks_types, ONLY: get_ks_env,&
87 USE qs_mo_types, ONLY: allocate_mo_set,&
96#include "./base/base_uses.f90"
97
98 IMPLICIT NONE
99 PRIVATE
100
101 PUBLIC :: run_optimize_basis
102
103 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'optimize_basis'
104
105CONTAINS
106
107! **************************************************************************************************
108!> \brief main entry point for methods aimed at optimizing basis sets
109!> \param input_declaration ...
110!> \param root_section ...
111!> \param para_env ...
112!> \param globenv ...
113!> \author Florian Schiffmann
114!> Jan Wilhelm, 08/2026: Add run_frontier_orbital_screening
115! **************************************************************************************************
116 SUBROUTINE run_optimize_basis(input_declaration, root_section, para_env, globenv)
117 TYPE(section_type), POINTER :: input_declaration
118 TYPE(section_vals_type), POINTER :: root_section
119 TYPE(mp_para_env_type), POINTER :: para_env
120 TYPE(global_environment_type), POINTER :: globenv
121
122 CHARACTER(len=*), PARAMETER :: routinen = 'run_optimize_basis'
123
124 INTEGER :: handle
125 LOGICAL :: frontier_orbitals_explicit, &
126 frontier_screening_explicit
127 TYPE(basis_optimization_type) :: opt_bas
128 TYPE(section_vals_type), POINTER :: frontier_orbitals_section, &
129 frontier_screening_section, &
130 optbas_section
131
132 CALL timeset(routinen, handle)
133
134 optbas_section => section_vals_get_subs_vals(root_section, "OPTIMIZE_BASIS")
135 frontier_orbitals_section => section_vals_get_subs_vals(optbas_section, "FRONTIER_ORBITALS")
136 frontier_screening_section => &
137 section_vals_get_subs_vals(optbas_section, "FRONTIER_ORBITAL_SCREENING")
138 CALL section_vals_get(frontier_orbitals_section, explicit=frontier_orbitals_explicit)
139 CALL section_vals_get(frontier_screening_section, explicit=frontier_screening_explicit)
140
141 IF (frontier_orbitals_explicit .AND. frontier_screening_explicit) THEN
142 cpabort("FRONTIER_ORBITALS and FRONTIER_ORBITAL_SCREENING cannot be activated together")
143 END IF
144
145 IF (frontier_screening_explicit) THEN
147 input_declaration, root_section, para_env, globenv, frontier_screening_section, driver_para_opt_basis)
148 ELSE
149 CALL optimize_basis_init_read_input(opt_bas, root_section, para_env)
150 CALL driver_para_opt_basis(opt_bas, input_declaration, para_env, globenv)
152 END IF
153
154 CALL timestop(handle)
155
156 END SUBROUTINE run_optimize_basis
157
158! **************************************************************************************************
159!> \brief driver routine for the parallel part of the method
160!> \param opt_bas ...
161!> \param input_declaration ...
162!> \param para_env ...
163!> \param globenv ...
164!> \param training_input ...
165!> \param reference ...
166!> \author Florian Schiffmann
167! **************************************************************************************************
168
169 SUBROUTINE driver_para_opt_basis(opt_bas, input_declaration, para_env, globenv, training_input, reference)
170 TYPE(basis_optimization_type) :: opt_bas
171 TYPE(section_type), POINTER :: input_declaration
172 TYPE(mp_para_env_type), POINTER :: para_env
173 TYPE(global_environment_type), POINTER :: globenv
174 TYPE(section_vals_type), OPTIONAL, POINTER :: training_input
176 DIMENSION(:), INTENT(IN), OPTIONAL, TARGET :: reference
177
178 CHARACTER(len=*), PARAMETER :: routinen = 'driver_para_opt_basis'
179
180 INTEGER :: handle, n_groups_created
181 TYPE(mp_comm_type) :: opt_group
182 INTEGER, DIMENSION(:), POINTER :: group_distribution_p
183 INTEGER, DIMENSION(0:para_env%num_pe-1), TARGET :: group_distribution
184
185 CALL timeset(routinen, handle)
186 group_distribution_p => group_distribution
187 CALL opt_group%from_split(para_env, n_groups_created, group_distribution_p, &
188 n_subgroups=SIZE(opt_bas%group_partition), group_partition=opt_bas%group_partition)
189 opt_bas%opt_id = group_distribution(para_env%mepos) + 1
190 opt_bas%n_groups_created = n_groups_created
191 ALLOCATE (opt_bas%sub_sources(0:para_env%num_pe - 1))
192
193 IF (PRESENT(training_input)) THEN
194 cpassert(PRESENT(reference))
195 CALL driver_optimization_para_low(opt_bas, input_declaration, para_env, opt_group, &
196 globenv, training_input, reference)
197 ELSE
198 CALL driver_optimization_para_low(opt_bas, input_declaration, para_env, opt_group, globenv)
199 END IF
200
201 CALL opt_group%free()
202 CALL timestop(handle)
203
204 END SUBROUTINE driver_para_opt_basis
205
206! **************************************************************************************************
207!> \brief low level optimization routine includes initialization of the subsytems
208!> powell optimizer and deallocation of the various force envs
209!> \param opt_bas ...
210!> \param input_declaration ...
211!> \param para_env_top ...
212!> \param mpi_comm_opt ...
213!> \param globenv ...
214!> \param training_input ...
215!> \param reference ...
216!> \author Florian Schiffmann
217! **************************************************************************************************
218
219 SUBROUTINE driver_optimization_para_low(opt_bas, input_declaration, para_env_top, mpi_comm_opt, &
220 globenv, training_input, reference)
221 TYPE(basis_optimization_type) :: opt_bas
222 TYPE(section_type), POINTER :: input_declaration
223 TYPE(mp_para_env_type), POINTER :: para_env_top
224 TYPE(mp_comm_type), INTENT(IN) :: mpi_comm_opt
225 TYPE(global_environment_type), POINTER :: globenv
226 TYPE(section_vals_type), OPTIONAL, POINTER :: training_input
228 DIMENSION(:), INTENT(IN), OPTIONAL, TARGET :: reference
229
230 CHARACTER(len=*), PARAMETER :: routinen = 'driver_optimization_para_low'
231
232 INTEGER :: handle, icalc, iopt, is, mp_id, &
233 outer_print_level, stat
234 INTEGER, ALLOCATABLE, DIMENSION(:) :: f_env_id
235 LOGICAL :: use_direct_qs, write_basis
236 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: tot_time
237 TYPE(cp_fm_type), ALLOCATABLE, DIMENSION(:) :: matrix_s_inv
238 TYPE(cp_logger_type), POINTER :: logger
239 TYPE(f_env_type), POINTER :: f_env
241 ALLOCATABLE, DIMENSION(:), TARGET :: local_reference
243 DIMENSION(:), POINTER :: active_reference
244 TYPE(frontier_orbitals_result_type), ALLOCATABLE, &
245 DIMENSION(:) :: initial_info, optimized_info
246 TYPE(mp_para_env_type), POINTER :: para_env
247 TYPE(qs_environment_type), ALLOCATABLE, &
248 DIMENSION(:), TARGET :: training_qs_env
249
250 NULLIFY (active_reference, f_env, logger)
251
252 CALL timeset(routinen, handle)
253
254 ! ====== initialize the f_env and precompute some matrices =====
255 mp_id = opt_bas%opt_id
256 use_direct_qs = opt_bas%method == method_mo_fit_occ_virtual
257 NULLIFY (para_env, f_env)
258 ALLOCATE (f_env_id(SIZE(opt_bas%comp_group(mp_id)%member_list)), source=-1)
259 ALLOCATE (tot_time(opt_bas%ncombinations*opt_bas%ntraining_sets))
260 IF (opt_bas%method == method_mo_fit_occ) THEN
261 ALLOCATE (matrix_s_inv(SIZE(opt_bas%comp_group(mp_id)%member_list)))
262 ELSE
263 ALLOCATE (initial_info(opt_bas%ncombinations*opt_bas%ntraining_sets))
264 ALLOCATE (optimized_info(opt_bas%ncombinations*opt_bas%ntraining_sets))
265 IF (PRESENT(reference)) THEN
266 active_reference => reference
267 ELSE
268 ALLOCATE (local_reference(SIZE(opt_bas%comp_group(mp_id)%member_list)))
269 active_reference => local_reference
270 END IF
271 END IF
272
273 ALLOCATE (para_env)
274 para_env = mpi_comm_opt
275
276 is = -1
277 IF (para_env%is_source()) is = para_env_top%mepos
278 CALL para_env_top%allgather(is, opt_bas%sub_sources)
279
280 IF (use_direct_qs) THEN
281 ALLOCATE (training_qs_env(SIZE(opt_bas%comp_group(mp_id)%member_list)))
282 logger => cp_get_default_logger()
283 outer_print_level = logger%iter_info%print_level
284 logger%iter_info%print_level = silent_print_level
285 IF (PRESENT(training_input)) THEN
286 CALL init_training_qs_envs(opt_bas, training_qs_env, input_declaration, para_env, globenv, &
287 training_input=training_input)
288 ELSE
289 CALL init_training_qs_envs(opt_bas, training_qs_env, input_declaration, para_env, globenv, &
290 reference=local_reference)
291 END IF
292 ELSE
293 CALL init_training_force_envs(opt_bas, f_env_id, input_declaration, para_env, mpi_comm_opt, &
294 matrix_s_inv=matrix_s_inv)
295 END IF
296
297 CALL init_free_vars(opt_bas)
298 IF (opt_bas%method == method_mo_fit_occ_virtual) THEN
299 ! Store the normalized coefficient representation used by the basis code.
300 CALL update_free_vars(opt_bas)
301 CALL init_free_vars(opt_bas)
302 ALLOCATE (opt_bas%x_initial, source=opt_bas%x_opt)
303 END IF
304 tot_time = 0.0_dp
305
306 ! ======= The real optimization loop =======
307 DO iopt = 0, opt_bas%powell_param%maxfun
308 SELECT CASE (opt_bas%method)
309 CASE (method_mo_fit_occ)
310 CALL compute_residuum_vectors(opt_bas, f_env_id, matrix_s_inv, tot_time, &
311 para_env_top, para_env, iopt)
313 IF (iopt == 0) THEN
314 CALL compute_frontier_orbitals_objective( &
315 opt_bas, f_env_id, active_reference, tot_time, &
316 para_env_top, para_env, initial_info, training_qs_env)
317 ELSE
318 CALL compute_frontier_orbitals_objective( &
319 opt_bas, f_env_id, active_reference, tot_time, &
320 para_env_top, para_env, qs_envs=training_qs_env)
321 END IF
322 CASE DEFAULT
323 cpabort("Unknown basis optimization method")
324 END SELECT
325 IF (para_env_top%is_source()) THEN
326 CALL powell_optimize(opt_bas%powell_param%nvar, opt_bas%x_opt, opt_bas%powell_param)
327 END IF
328 CALL para_env_top%bcast(opt_bas%powell_param%state)
329 CALL para_env_top%bcast(opt_bas%x_opt)
330 CALL update_free_vars(opt_bas)
331 write_basis = opt_bas%method == method_mo_fit_occ .AND. &
332 mod(iopt, opt_bas%write_frequency) == 0
333 CALL update_derived_basis_sets(opt_bas, write_basis, opt_bas%output_basis_file, &
334 para_env_top)
335 IF (opt_bas%powell_param%state == -1) EXIT
336 END DO
337
338 ! ======= Update the basis set and print the final basis =======
339 IF (para_env_top%is_source()) THEN
340 opt_bas%powell_param%state = 8
341 CALL powell_optimize(opt_bas%powell_param%nvar, opt_bas%x_opt, opt_bas%powell_param)
342 END IF
343
344 CALL para_env_top%bcast(opt_bas%x_opt)
345 CALL update_free_vars(opt_bas)
346 IF (opt_bas%method == method_mo_fit_occ_virtual) THEN
347 ! Report the actual best Powell vector, rather than the final trial point.
348 CALL compute_frontier_orbitals_objective( &
349 opt_bas, f_env_id, active_reference, tot_time, &
350 para_env_top, para_env, optimized_info, training_qs_env)
351 IF (.NOT. opt_bas%quiet_output) THEN
352 CALL print_frontier_orbitals_info( &
353 opt_bas, active_reference, initial_info, optimized_info, &
354 para_env_top, para_env)
355 END IF
356 END IF
357 CALL update_derived_basis_sets(opt_bas,.NOT. opt_bas%quiet_output, opt_bas%output_basis_file, &
358 para_env_top)
359
360 ! ====== get rid of the f_env again =====
361
362 DO icalc = SIZE(opt_bas%comp_group(mp_id)%member_list), 1, -1
363 IF (opt_bas%method == method_mo_fit_occ_virtual .AND. ALLOCATED(local_reference)) THEN
364 CALL frontier_orbitals_reference_release(local_reference(icalc))
365 END IF
366 IF (use_direct_qs) THEN
367 CALL qs_env_release(training_qs_env(icalc))
368 ELSE
369 CALL f_env_get_from_id(f_env_id(icalc), f_env)
370 CALL destroy_force_env(f_env_id(icalc), stat)
371 END IF
372 END DO
373 IF (ALLOCATED(training_qs_env)) THEN
374 DEALLOCATE (training_qs_env)
375 logger%iter_info%print_level = outer_print_level
376 END IF
377 DEALLOCATE (f_env_id); DEALLOCATE (tot_time)
378 IF (ALLOCATED(initial_info)) DEALLOCATE (initial_info)
379 IF (ALLOCATED(optimized_info)) DEALLOCATE (optimized_info)
380 IF (ALLOCATED(local_reference)) DEALLOCATE (local_reference)
381 CALL cp_fm_release(matrix_s_inv)
382 CALL mp_para_env_release(para_env)
383 CALL timestop(handle)
384
385 END SUBROUTINE driver_optimization_para_low
386
387! **************************************************************************************************
388!> \brief compute all ingredients for powell optimizer. Rho_diff,
389!> condition number, energy,... for all ttraining sets in
390!> the computational group
391!> \param opt_bas ...
392!> \param f_env_id ...
393!> \param matrix_S_inv ...
394!> \param tot_time ...
395!> \param para_env_top ...
396!> \param para_env ...
397!> \param iopt ...
398! **************************************************************************************************
399
400 SUBROUTINE compute_residuum_vectors(opt_bas, f_env_id, matrix_S_inv, tot_time, &
401 para_env_top, para_env, iopt)
402 TYPE(basis_optimization_type) :: opt_bas
403 INTEGER, ALLOCATABLE, DIMENSION(:) :: f_env_id
404 TYPE(cp_fm_type), DIMENSION(:), INTENT(IN) :: matrix_s_inv
405 REAL(kind=dp), DIMENSION(:) :: tot_time
406 TYPE(mp_para_env_type), POINTER :: para_env_top, para_env
407 INTEGER :: iopt
408
409 CHARACTER(len=*), PARAMETER :: routinen = 'compute_residuum_vectors'
410
411 CHARACTER(len=8) :: basis_type
412 INTEGER :: bas_id, handle, icalc, icomb, ispin, &
413 mp_id, my_id, nao, ncalc, nelectron, &
414 nmo, nspins, set_id
415 REAL(kind=dp) :: flexible_electron_count, maxocc, n_el_f
416 REAL(kind=dp), DIMENSION(:), POINTER :: cond_vec, energy, f_vec, my_time, &
417 start_time
418 REAL(kind=dp), DIMENSION(:, :), POINTER :: gdata
419 TYPE(cp_fm_struct_type), POINTER :: fm_struct
420 TYPE(cp_fm_type), POINTER :: mo_coeff
421 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_ks, matrix_s_aux, matrix_s_aux_orb
422 TYPE(f_env_type), POINTER :: f_env
423 TYPE(force_env_type), POINTER :: force_env
424 TYPE(mo_set_type), ALLOCATABLE, DIMENSION(:) :: mos_aux
425 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
426 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
427 POINTER :: sab_aux, sab_aux_orb
428 TYPE(qs_environment_type), POINTER :: qs_env
429 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
430 TYPE(qs_ks_env_type), POINTER :: ks_env
431
432 CALL timeset(routinen, handle)
433
434 basis_type = "AUX_OPT"
435 !
436 ncalc = opt_bas%ncombinations*opt_bas%ntraining_sets
437 ALLOCATE (gdata(ncalc, 4))
438 f_vec => gdata(:, 1)
439 my_time => gdata(:, 2)
440 cond_vec => gdata(:, 3)
441 energy => gdata(:, 4)
442 !
443 f_vec = 0.0_dp; cond_vec = 0.0_dp; my_time = 0.0_dp; energy = 0.0_dp
444 mp_id = opt_bas%opt_id
445 ALLOCATE (start_time(SIZE(opt_bas%comp_group(mp_id)%member_list)))
446 !
447 DO icalc = 1, SIZE(opt_bas%comp_group(mp_id)%member_list)
448 my_id = opt_bas%comp_group(mp_id)%member_list(icalc) + 1
449 ! setup timings
450 start_time(icalc) = m_walltime()
451
452 NULLIFY (matrix_s_aux_orb, matrix_s_aux)
453 CALL get_set_and_basis_id(opt_bas%comp_group(mp_id)%member_list(icalc), opt_bas, set_id, bas_id)
454 CALL f_env_get_from_id(f_env_id(icalc), f_env)
455 force_env => f_env%force_env
456 CALL force_env_get(force_env, qs_env=qs_env)
457 CALL get_qs_env(qs_env, ks_env=ks_env)
458 CALL update_basis_set(opt_bas, bas_id, basis_type, qs_env)
459 NULLIFY (sab_aux, sab_aux_orb)
460 CALL optbas_build_neighborlist(qs_env, sab_aux, sab_aux_orb, basis_type)
461 CALL build_overlap_matrix(ks_env, matrix_s=matrix_s_aux, &
462 basis_type_a=basis_type, &
463 basis_type_b=basis_type, &
464 sab_nl=sab_aux)
465 CALL build_overlap_matrix(ks_env, matrix_s=matrix_s_aux_orb, &
466 basis_type_a=basis_type, &
467 basis_type_b="ORB", &
468 sab_nl=sab_aux_orb)
469 CALL release_neighbor_list_sets(sab_aux)
470 CALL release_neighbor_list_sets(sab_aux_orb)
471 CALL get_qs_env(qs_env, mos=mos, matrix_ks=matrix_ks)
472
473 nspins = SIZE(mos)
474 ALLOCATE (mos_aux(nspins))
475 CALL get_qs_env(qs_env, qs_kind_set=qs_kind_set)
476 CALL get_qs_kind_set(qs_kind_set, nsgf=nao, basis_type=basis_type)
477 DO ispin = 1, nspins
478 CALL get_mo_set(mo_set=mos(ispin), mo_coeff=mo_coeff, maxocc=maxocc, nelectron=nelectron, &
479 n_el_f=n_el_f, nmo=nmo, flexible_electron_count=flexible_electron_count)
480 CALL cp_fm_struct_create(fm_struct, nrow_global=nao, ncol_global=nmo, &
481 context=mo_coeff%matrix_struct%context, &
482 para_env=mo_coeff%matrix_struct%para_env)
483 CALL allocate_mo_set(mos_aux(ispin), nao, nmo, nelectron, &
484 n_el_f, maxocc, flexible_electron_count)
485 CALL init_mo_set(mo_set=mos_aux(ispin), fm_struct=fm_struct, name="MO_AUX")
486 CALL cp_fm_struct_release(fm_struct)
487 END DO
488
489 CALL fit_mo_coeffs(matrix_s_aux, matrix_s_aux_orb, mos, mos_aux)
490 CALL evaluate_optvals(mos, mos_aux, matrix_ks, matrix_s_aux_orb(1)%matrix, &
491 matrix_s_aux(1)%matrix, matrix_s_inv(icalc), &
492 f_vec(my_id), energy(my_id), cond_vec(my_id))
493
494 DO ispin = 1, nspins
495 CALL deallocate_mo_set(mos_aux(ispin))
496 END DO
497 DEALLOCATE (mos_aux)
498 IF (ASSOCIATED(matrix_s_aux)) CALL dbcsr_deallocate_matrix_set(matrix_s_aux)
499 IF (ASSOCIATED(matrix_s_aux_orb)) CALL dbcsr_deallocate_matrix_set(matrix_s_aux_orb)
500
501 my_time(my_id) = m_walltime() - start_time(icalc)
502 END DO
503
504 DEALLOCATE (start_time)
505
506 IF (.NOT. para_env%is_source()) THEN
507 f_vec = 0.0_dp; cond_vec = 0.0_dp; my_time = 0.0_dp; energy = 0.0_dp
508 END IF
509 ! collect date from all subgroup ionodes on the main ionode
510 CALL para_env_top%sum(gdata)
511
512 opt_bas%powell_param%f = 0.0_dp
513 IF (para_env_top%is_source()) THEN
514 DO icalc = 1, SIZE(f_vec)
515 icomb = mod(icalc - 1, opt_bas%ncombinations)
516 opt_bas%powell_param%f = opt_bas%powell_param%f + &
517 (f_vec(icalc) + energy(icalc))*opt_bas%fval_weight(icomb)
518 IF (opt_bas%use_condition_number) THEN
519 opt_bas%powell_param%f = opt_bas%powell_param%f + &
520 log(cond_vec(icalc))*opt_bas%condition_weight(icomb)
521 END IF
522 END DO
523 ELSE
524 f_vec = 0.0_dp; cond_vec = 0.0_dp; my_time = 0.0_dp; energy = 0.0_dp
525 END IF
526 CALL para_env_top%bcast(opt_bas%powell_param%f)
527
528 ! output info if required
529 CALL output_opt_info(f_vec, cond_vec, my_time, tot_time, opt_bas, iopt, para_env_top)
530 DEALLOCATE (gdata)
531
532 CALL para_env_top%sync()
533
534 CALL timestop(handle)
535
536 END SUBROUTINE compute_residuum_vectors
537
538! **************************************************************************************************
539!> \brief Evaluate the frozen-density frontier-orbital objective.
540!> \param opt_bas basis optimization settings and current parameters
541!> \param f_env_id force environments for locally assigned calculations
542!> \param reference cached full reference eigensystems
543!> \param tot_time accumulated timings for output
544!> \param para_env_top top-level communicator
545!> \param para_env calculation-group communicator
546!> \param info ...
547!> \param qs_envs ...
548! **************************************************************************************************
549 SUBROUTINE compute_frontier_orbitals_objective(opt_bas, f_env_id, reference, tot_time, &
550 para_env_top, para_env, info, qs_envs)
551 TYPE(basis_optimization_type) :: opt_bas
552 INTEGER, ALLOCATABLE, DIMENSION(:) :: f_env_id
554 DIMENSION(:), INTENT(IN) :: reference
555 REAL(kind=dp), DIMENSION(:) :: tot_time
556 TYPE(mp_para_env_type), POINTER :: para_env_top, para_env
558 DIMENSION(:), INTENT(OUT), OPTIONAL :: info
559 TYPE(qs_environment_type), DIMENSION(:), &
560 OPTIONAL, TARGET :: qs_envs
561
562 CHARACTER(len=*), PARAMETER :: routinen = 'compute_frontier_orbitals_objective'
563
564 CHARACTER(len=8) :: basis_type
565 INTEGER :: bas_id, handle, icalc, icomb, icont, &
566 ikind, ipgf, iset, ix, mp_id, my_id, &
567 ncalc, set_id
568 REAL(kind=dp) :: coefficient_loss, contribution
569 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: coefficients_current
570 REAL(kind=dp), DIMENSION(:), POINTER :: start_time
571 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s_aux, matrix_s_aux_orb
572 TYPE(f_env_type), POINTER :: f_env
573 TYPE(force_env_type), POINTER :: force_env
574 TYPE(frontier_orbitals_result_type), ALLOCATABLE, &
575 DIMENSION(:) :: results
576 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
577 POINTER :: sab_aux, sab_aux_orb
578 TYPE(qs_environment_type), POINTER :: qs_env
579 TYPE(qs_ks_env_type), POINTER :: ks_env
580
581 CALL timeset(routinen, handle)
582
583 basis_type = "AUX_OPT"
584 ncalc = opt_bas%ncombinations*opt_bas%ntraining_sets
585 ALLOCATE (results(ncalc))
586 ALLOCATE (coefficients_current, source=opt_bas%x_opt)
587 DO ikind = 1, opt_bas%nkind
588 DO iset = 1, opt_bas%kind_basis(ikind)%flex_basis(0)%nsets
589 DO ipgf = 1, opt_bas%kind_basis(ikind)%flex_basis(0)%subset(iset)%nexp
590 DO icont = 1, opt_bas%kind_basis(ikind)%flex_basis(0)%subset(iset)%ncon_tot
591 IF (opt_bas%kind_basis(ikind)%flex_basis(0)%subset(iset)%opt_coeff(ipgf, icont)) THEN
592 ix = opt_bas%kind_basis(ikind)%flex_basis(0)%subset(iset)%coeff_x_ind(ipgf, icont)
593 coefficients_current(ix) = &
594 opt_bas%kind_basis(ikind)%flex_basis(0)%subset(iset)%coeff(ipgf, icont)
595 END IF
596 END DO
597 END DO
598 END DO
599 END DO
600 coefficient_loss = 0.0_dp
601 IF (sum(opt_bas%x_initial**2) > tiny(1.0_dp)) THEN
602 coefficient_loss = sum((coefficients_current - opt_bas%x_initial)**2)/ &
603 sum(opt_bas%x_initial**2)
604 END IF
605 mp_id = opt_bas%opt_id
606 ALLOCATE (start_time(SIZE(opt_bas%comp_group(mp_id)%member_list)))
607
608 DO icalc = 1, SIZE(opt_bas%comp_group(mp_id)%member_list)
609 my_id = opt_bas%comp_group(mp_id)%member_list(icalc) + 1
610 start_time(icalc) = m_walltime()
611
612 NULLIFY (ks_env, matrix_s_aux, matrix_s_aux_orb, sab_aux, sab_aux_orb)
613 CALL get_set_and_basis_id(opt_bas%comp_group(mp_id)%member_list(icalc), opt_bas, &
614 bas_id=bas_id, set_id=set_id)
615 IF (PRESENT(qs_envs)) THEN
616 qs_env => qs_envs(icalc)
617 ELSE
618 CALL f_env_get_from_id(f_env_id(icalc), f_env)
619 force_env => f_env%force_env
620 CALL force_env_get(force_env, qs_env=qs_env)
621 END IF
622 CALL update_basis_set(opt_bas, bas_id, basis_type, qs_env)
623 CALL optbas_build_neighborlist(qs_env, sab_aux, sab_aux_orb, basis_type)
624 CALL get_qs_env(qs_env, ks_env=ks_env)
625 CALL build_overlap_matrix(ks_env, matrix_s=matrix_s_aux, &
626 basis_type_a=basis_type, basis_type_b=basis_type, sab_nl=sab_aux)
627 CALL build_overlap_matrix(ks_env, matrix_s=matrix_s_aux_orb, &
628 basis_type_a=basis_type, basis_type_b="ORB", sab_nl=sab_aux_orb)
629 CALL release_neighbor_list_sets(sab_aux)
630 CALL release_neighbor_list_sets(sab_aux_orb)
631
633 reference(icalc), matrix_s_aux(1)%matrix, matrix_s_aux_orb(1)%matrix, &
634 opt_bas%virtual_energy_cutoff, opt_bas%virtual_energy_smoothing, &
635 opt_bas%gap_energy_scale, results(my_id))
636 results(my_id)%reference_condition_number = reference(icalc)%condition_number
637 results(my_id)%number_reference_orbitals = reference(icalc)%number_reference_orbitals
638 results(my_id)%calculation_time = m_walltime() - start_time(icalc)
639
640 IF (ASSOCIATED(matrix_s_aux)) CALL dbcsr_deallocate_matrix_set(matrix_s_aux)
641 IF (ASSOCIATED(matrix_s_aux_orb)) CALL dbcsr_deallocate_matrix_set(matrix_s_aux_orb)
642 END DO
643 DEALLOCATE (start_time)
644
645 CALL reduce_frontier_orbitals_results(results, para_env_top, para_env)
646 IF (PRESENT(info)) THEN
647 cpassert(SIZE(info) == ncalc)
648 info = results
649 END IF
650
651 opt_bas%powell_param%f = 0.0_dp
652 IF (para_env_top%is_source()) THEN
653 DO icalc = 1, ncalc
654 icomb = mod(icalc - 1, opt_bas%ncombinations)
655 contribution = opt_bas%occupied_weight*results(icalc)%loss_occupied_subspace + &
656 opt_bas%virtual_weight*results(icalc)%loss_virtual_subspace + &
657 opt_bas%empty_overlap_weight*results(icalc)%loss_empty_subspace + &
658 opt_bas%gap_weight*results(icalc)%loss_gap + &
659 opt_bas%coefficient_weight*coefficient_loss
660 IF (opt_bas%use_condition_number) THEN
661 contribution = contribution + opt_bas%condition_weight(icomb)* &
662 log10(results(icalc)%condition_number)
663 END IF
664 opt_bas%powell_param%f = opt_bas%powell_param%f + &
665 opt_bas%fval_weight(icomb)*contribution
666 tot_time(icalc) = tot_time(icalc) + results(icalc)%calculation_time
667 END DO
668 END IF
669 CALL para_env_top%bcast(opt_bas%powell_param%f)
670 DEALLOCATE (coefficients_current, results)
671
672 CALL para_env_top%sync()
673 CALL timestop(handle)
674
675 END SUBROUTINE compute_frontier_orbitals_objective
676
677! **************************************************************************************************
678!> \brief Collect frontier-orbital results from all calculation groups.
679!> \param results frontier-orbital results for every training calculation
680!> \param para_env_top top-level communicator
681!> \param para_env calculation-group communicator
682! **************************************************************************************************
683 SUBROUTINE reduce_frontier_orbitals_results(results, para_env_top, para_env)
685 DIMENSION(:), INTENT(INOUT) :: results
686 TYPE(mp_para_env_type), POINTER :: para_env_top, para_env
687
688 IF (.NOT. para_env%is_source()) results = frontier_orbitals_result_type()
689 CALL para_env_top%sum(results%loss_occupied_subspace)
690 CALL para_env_top%sum(results%loss_virtual_subspace)
691 CALL para_env_top%sum(results%loss_empty_subspace)
692 CALL para_env_top%sum(results%loss_gap)
693 CALL para_env_top%sum(results%occupied_subspace_overlap)
694 CALL para_env_top%sum(results%virtual_subspace_similarity)
695 CALL para_env_top%sum(results%empty_subspace_overlap)
696 CALL para_env_top%sum(results%gap_reference)
697 CALL para_env_top%sum(results%gap_candidate)
698 CALL para_env_top%sum(results%condition_number)
699 CALL para_env_top%sum(results%reference_condition_number)
700 CALL para_env_top%sum(results%calculation_time)
701 CALL para_env_top%sum(results%number_candidate_orbitals)
702 CALL para_env_top%sum(results%number_reference_orbitals)
703
704 END SUBROUTINE reduce_frontier_orbitals_results
705
706! **************************************************************************************************
707!> \brief Print initial-to-optimized frontier-orbital information for every training calculation.
708!> \param opt_bas basis optimization settings
709!> \param reference locally held reference data and basis metadata
710!> \param initial initial-small-basis results
711!> \param optimized optimized-small-basis results
712!> \param para_env_top top-level communicator
713!> \param para_env calculation-group communicator
714! **************************************************************************************************
715 SUBROUTINE print_frontier_orbitals_info(opt_bas, reference, initial, optimized, &
716 para_env_top, para_env)
717 TYPE(basis_optimization_type), INTENT(IN) :: opt_bas
719 DIMENSION(:), INTENT(IN) :: reference
721 DIMENSION(:), INTENT(IN) :: initial, optimized
722 TYPE(mp_para_env_type), POINTER :: para_env_top, para_env
723
724 CHARACTER(LEN=17) :: basis_label
725 CHARACTER(LEN=default_string_length), &
726 ALLOCATABLE, DIMENSION(:) :: candidate_basis, element, reference_basis
727 INTEGER :: bas_id, icalc, ikind, iset, max_kinds, &
728 my_id, ncalc, unit_nr
729 INTEGER, ALLOCATABLE, DIMENSION(:) :: kind_count
730 INTEGER, ALLOCATABLE, DIMENSION(:, :, :, :) :: metadata
731 TYPE(cp_logger_type), POINTER :: logger
732
733 ncalc = opt_bas%ncombinations*opt_bas%ntraining_sets
734 cpassert(SIZE(initial) == ncalc)
735 cpassert(SIZE(optimized) == ncalc)
736
737 max_kinds = 0
738 DO icalc = 1, SIZE(reference)
739 max_kinds = max(max_kinds, reference(icalc)%number_kinds)
740 END DO
741 CALL para_env_top%max(max_kinds)
742 ALLOCATE (kind_count(ncalc), source=0)
743 ALLOCATE (metadata(ncalc, max_kinds, 3, default_string_length), source=0)
744
745 IF (para_env%is_source()) THEN
746 DO icalc = 1, SIZE(reference)
747 my_id = opt_bas%comp_group(opt_bas%opt_id)%member_list(icalc) + 1
748 kind_count(my_id) = reference(icalc)%number_kinds
749 DO ikind = 1, reference(icalc)%number_kinds
750 CALL encode_string(reference(icalc)%element_symbol(ikind), metadata(my_id, ikind, 1, :))
751 CALL encode_string(reference(icalc)%reference_basis_name(ikind), metadata(my_id, ikind, 2, :))
752 CALL encode_string(reference(icalc)%candidate_basis_name(ikind), metadata(my_id, ikind, 3, :))
753 END DO
754 END DO
755 END IF
756 CALL para_env_top%sum(kind_count)
757 CALL para_env_top%sum(metadata)
758
759 logger => cp_get_default_logger()
760 unit_nr = -1
761 IF (para_env_top%is_source()) unit_nr = cp_logger_get_default_unit_nr(logger)
762 IF (unit_nr > 0) THEN
763 WRITE (unit_nr, '(A)') ""
764 WRITE (unit_nr, '(A)') repeat("=", 78)
765 WRITE (unit_nr, '(A)') "BASIS OPTIMIZATION SUMMARY"
766 WRITE (unit_nr, '(A)') repeat("=", 78)
767
768 DO my_id = 1, ncalc
769 CALL get_set_and_basis_id(my_id - 1, opt_bas, set_id=iset, bas_id=bas_id)
770 WRITE (unit_nr, '(A)') ""
771 WRITE (unit_nr, '(A,A,A,A)') "Reference calculation: ", &
772 trim(opt_bas%training_dir(iset)), "/", trim(opt_bas%training_input(iset))
773 IF (opt_bas%ncombinations > 1) THEN
774 WRITE (unit_nr, '(A,I0)') "Basis combination: ", bas_id
775 END IF
776 WRITE (unit_nr, '(A)') ""
777 WRITE (unit_nr, '(A)') "Atomic kind basis sets"
778 WRITE (unit_nr, '(A)') repeat("-", 78)
779 ALLOCATE (candidate_basis(kind_count(my_id)), element(kind_count(my_id)), &
780 reference_basis(kind_count(my_id)))
781 DO ikind = 1, kind_count(my_id)
782 CALL decode_string(metadata(my_id, ikind, 1, :), element(ikind))
783 CALL decode_string(metadata(my_id, ikind, 2, :), reference_basis(ikind))
784 CALL decode_string(metadata(my_id, ikind, 3, :), candidate_basis(ikind))
785 END DO
786 CALL print_frontier_orbital_basis_sets(unit_nr, element, reference_basis, candidate_basis)
787 DEALLOCATE (candidate_basis, element, reference_basis)
788 WRITE (unit_nr, '(A)') ""
789 WRITE (unit_nr, '(A,A)') "Optimized basis file: ", trim(opt_bas%output_basis_file)
790 WRITE (unit_nr, '(A)') ""
791
792 WRITE (unit_nr, '(A)') "Overall subspace quality and conditioning"
793 WRITE (unit_nr, '(A)') repeat("-", 78)
794 basis_label = "Basis"
795 WRITE (unit_nr, '(A17,1X,A4,2(1X,A11),1X,A12,1X,A9,1X,A6)') basis_label, "N_AO", &
796 "Occ.overlap", "Vir.overlap", "Emp.coverage", "κ(S)", "Gap/eV"
797 WRITE (unit_nr, '(A)') repeat("-", 78)
798 basis_label = "Ref. basis"
799 WRITE (unit_nr, '(A17,1X,I4,2(1X,F10.1,A),1X,F11.1,A,1X,ES9.2,1X,F6.3)') &
800 basis_label, initial(my_id)%number_reference_orbitals, &
801 100.0_dp, "%", 100.0_dp, "%", 100.0_dp, "%", &
802 initial(my_id)%reference_condition_number, &
803 initial(my_id)%gap_reference*evolt
804 basis_label = "Init. small basis"
805 WRITE (unit_nr, '(A17,1X,I4,2(1X,F10.1,A),1X,F11.1,A,1X,ES9.2,1X,F6.3)') &
806 basis_label, initial(my_id)%number_candidate_orbitals, &
807 100.0_dp*initial(my_id)%occupied_subspace_overlap, "%", &
808 100.0_dp*initial(my_id)%virtual_subspace_similarity, "%", &
809 100.0_dp*initial(my_id)%empty_subspace_overlap, "%", &
810 initial(my_id)%condition_number, initial(my_id)%gap_candidate*evolt
811 basis_label = "Opt. small basis"
812 WRITE (unit_nr, '(A17,1X,I4,2(1X,F10.1,A),1X,F11.1,A,1X,ES9.2,1X,F6.3)') &
813 basis_label, optimized(my_id)%number_candidate_orbitals, &
814 100.0_dp*optimized(my_id)%occupied_subspace_overlap, "%", &
815 100.0_dp*optimized(my_id)%virtual_subspace_similarity, "%", &
816 100.0_dp*optimized(my_id)%empty_subspace_overlap, "%", &
817 optimized(my_id)%condition_number, optimized(my_id)%gap_candidate*evolt
818 WRITE (unit_nr, '(A)') repeat("-", 78)
819
820 END DO
821
822 WRITE (unit_nr, '(A)') repeat("=", 78)
823 WRITE (unit_nr, '(A)') ""
824 END IF
825
826 DEALLOCATE (kind_count, metadata)
827
828 END SUBROUTINE print_frontier_orbitals_info
829
830! **************************************************************************************************
831!> \brief Encode a string as integers so basis metadata can be reduced across optimizer groups.
832!> \param string ...
833!> \param encoded ...
834! **************************************************************************************************
835 PURE SUBROUTINE encode_string(string, encoded)
836 CHARACTER(LEN=*), INTENT(IN) :: string
837 INTEGER, DIMENSION(:), INTENT(OUT) :: encoded
838
839 INTEGER :: i
840
841 encoded = 0
842 DO i = 1, min(len_trim(string), SIZE(encoded))
843 encoded(i) = iachar(string(i:i))
844 END DO
845
846 END SUBROUTINE encode_string
847
848! **************************************************************************************************
849!> \brief Decode integer character codes used to communicate basis metadata.
850!> \param encoded ...
851!> \param string ...
852! **************************************************************************************************
853 PURE SUBROUTINE decode_string(encoded, string)
854 INTEGER, DIMENSION(:), INTENT(IN) :: encoded
855 CHARACTER(LEN=*), INTENT(OUT) :: string
856
857 INTEGER :: i
858
859 string = ""
860 DO i = 1, min(len(string), SIZE(encoded))
861 IF (encoded(i) == 0) EXIT
862 string(i:i) = achar(encoded(i))
863 END DO
864
865 END SUBROUTINE decode_string
866
867! **************************************************************************************************
868!> \brief Initialize Quickstep environments without starting nested CP2K runs.
869!> \param opt_bas ...
870!> \param qs_envs ...
871!> \param input_declaration ...
872!> \param para_env ...
873!> \param globenv ...
874!> \param training_input ...
875!> \param reference ...
876! **************************************************************************************************
877 SUBROUTINE init_training_qs_envs(opt_bas, qs_envs, input_declaration, para_env, globenv, &
878 training_input, reference)
879 TYPE(basis_optimization_type) :: opt_bas
880 TYPE(qs_environment_type), DIMENSION(:), &
881 INTENT(OUT), TARGET :: qs_envs
882 TYPE(section_type), POINTER :: input_declaration
883 TYPE(mp_para_env_type), POINTER :: para_env
884 TYPE(global_environment_type), POINTER :: globenv
885 TYPE(section_vals_type), OPTIONAL, POINTER :: training_input
887 DIMENSION(:), INTENT(OUT), OPTIONAL :: reference
888
889 CHARACTER(len=*), PARAMETER :: routinen = 'init_training_qs_envs'
890
891 CHARACTER(len=default_path_length) :: main_dir, restart_file
892 CHARACTER(len=default_string_length) :: project_name
893 INTEGER :: bas_id, handle, icalc, ierr, mp_id, &
894 n_rep_val, set_id
895 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
896 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
897 POINTER :: sab_orb
898 TYPE(qs_environment_type), POINTER :: qs_env, reference_qs_env
899 TYPE(qs_ks_env_type), POINTER :: ks_env
900 TYPE(section_vals_type), POINTER :: dft_section, force_env_section, &
901 input_file, subsys_section
902
903 CALL timeset(routinen, handle)
904
905 mp_id = opt_bas%opt_id
906 CALL m_getcwd(main_dir)
907 DO icalc = 1, SIZE(opt_bas%comp_group(mp_id)%member_list)
908 NULLIFY (dft_section, force_env_section, input_file, ks_env, matrix_s, qs_env, &
909 reference_qs_env, sab_orb, subsys_section)
910 CALL get_set_and_basis_id(opt_bas%comp_group(mp_id)%member_list(icalc), opt_bas, &
911 set_id=set_id, bas_id=bas_id)
912 IF (PRESENT(training_input)) THEN
913 CALL section_vals_duplicate(training_input, input_file)
914 ELSE
915 CALL m_chdir(trim(opt_bas%training_dir(set_id)), ierr)
916 IF (ierr /= 0) THEN
917 CALL cp_abort(__location__, &
918 "Could not change to directory <"//trim(opt_bas%training_dir(set_id))//">")
919 END IF
920 input_file => read_input(input_declaration, &
921 opt_bas%training_input(set_id), &
922 initial_variables=empty_initial_variables, &
923 para_env=para_env)
924 CALL check_cp2k_input(input_declaration, input_file, para_env=para_env, &
925 output_unit=-1)
926 END IF
927
928 CALL section_vals_val_set(input_file, "GLOBAL%PRINT_LEVEL", i_val=silent_print_level)
929 IF (PRESENT(reference)) THEN
930 force_env_section => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
931 dft_section => section_vals_get_subs_vals(force_env_section, "DFT")
932 CALL section_vals_val_get(dft_section, "WFN_RESTART_FILE_NAME", n_rep_val=n_rep_val)
933 IF (n_rep_val == 0) THEN
934 CALL section_vals_val_get(input_file, "GLOBAL%PROJECT_NAME", c_val=project_name)
935 restart_file = trim(project_name)//"-RESTART.wfn"
936 CALL section_vals_val_set(dft_section, "WFN_RESTART_FILE_NAME", &
937 c_val=trim(restart_file))
938 END IF
939 CALL section_vals_val_set(dft_section, "SCF%SCF_GUESS", i_val=restart_guess)
940 subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
941 ALLOCATE (reference_qs_env)
942 CALL qs_env_create(reference_qs_env, globenv)
943 CALL qs_init(reference_qs_env, para_env, input_file, globenv=globenv, &
944 force_env_section=force_env_section, subsys_section=subsys_section, &
945 use_motion_section=.true., silent=.true.)
946 CALL allocate_mo_sets(reference_qs_env)
947 CALL get_qs_env(reference_qs_env, ks_env=ks_env)
948 CALL build_qs_neighbor_lists(reference_qs_env, para_env, molecular=.false., &
949 force_env_section=reference_qs_env%input)
950 CALL get_ks_env(ks_env, matrix_s=matrix_s, sab_orb=sab_orb)
951 CALL build_overlap_matrix(ks_env, matrix_s=matrix_s, &
952 matrix_name="OVERLAP", &
953 basis_type_a="ORB", &
954 basis_type_b="ORB", &
955 sab_nl=sab_orb)
956 CALL set_ks_env(ks_env, matrix_s=matrix_s)
957 CALL calculate_ks_matrix(reference_qs_env)
958 CALL frontier_orbitals_reference_init(reference_qs_env, reference(icalc))
959 CALL qs_env_release(reference_qs_env)
960 DEALLOCATE (reference_qs_env)
961 END IF
962
963 CALL modify_input_settings(opt_bas, bas_id, input_file)
964 force_env_section => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
965 subsys_section => section_vals_get_subs_vals(force_env_section, "SUBSYS")
966 qs_env => qs_envs(icalc)
967 CALL qs_env_create(qs_env, globenv)
968 CALL qs_init(qs_env, para_env, input_file, globenv=globenv, &
969 force_env_section=force_env_section, subsys_section=subsys_section, &
970 use_motion_section=.true., silent=.true.)
971
972 CALL section_vals_release(input_file)
973 IF (.NOT. PRESENT(training_input)) CALL m_chdir(trim(adjustl(main_dir)), ierr)
974 END DO
975
976 CALL timestop(handle)
977
978 END SUBROUTINE init_training_qs_envs
979
980! **************************************************************************************************
981!> \brief create the force_envs for every input in the computational group
982!> \param opt_bas ...
983!> \param f_env_id ...
984!> \param input_declaration ...
985!> \param para_env ...
986!> \param mpi_comm_opt ...
987!> \param matrix_s_inv ...
988!> \param training_input ...
989!> \param reference ...
990! **************************************************************************************************
991
992 SUBROUTINE init_training_force_envs(opt_bas, f_env_id, input_declaration, para_env, mpi_comm_opt, &
993 matrix_s_inv, training_input, reference)
994
995 TYPE(basis_optimization_type) :: opt_bas
996 INTEGER, ALLOCATABLE, DIMENSION(:) :: f_env_id
997 TYPE(section_type), POINTER :: input_declaration
998 TYPE(mp_para_env_type), POINTER :: para_env
999 TYPE(mp_comm_type) :: mpi_comm_opt
1000 TYPE(cp_fm_type), DIMENSION(:), INTENT(OUT), &
1001 OPTIONAL :: matrix_s_inv
1002 TYPE(section_vals_type), OPTIONAL, POINTER :: training_input
1004 DIMENSION(:), INTENT(OUT), OPTIONAL :: reference
1005
1006 CHARACTER(len=*), PARAMETER :: routinen = 'init_training_force_envs'
1007
1008 CHARACTER(len=default_path_length) :: input_path, main_dir
1009 INTEGER :: bas_id, f_env_output_unit, handle, &
1010 icalc, ierr, mp_id, set_id, stat
1011 TYPE(cp_blacs_env_type), POINTER :: blacs_env
1012 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: matrix_s
1013 TYPE(f_env_type), POINTER :: f_env
1014 TYPE(force_env_type), POINTER :: force_env
1015 TYPE(neighbor_list_set_p_type), DIMENSION(:), &
1016 POINTER :: sab_orb
1017 TYPE(qs_environment_type), POINTER :: qs_env
1018 TYPE(qs_ks_env_type), POINTER :: ks_env
1019 TYPE(section_vals_type), POINTER :: input_file
1020
1021 CALL timeset(routinen, handle)
1022
1023 NULLIFY (matrix_s, blacs_env, ks_env)
1024
1025 mp_id = opt_bas%opt_id
1026 CALL m_getcwd(main_dir)
1027
1028 ! ======= Create f_env for all calculations in MPI group =======
1029 DO icalc = 1, SIZE(opt_bas%comp_group(mp_id)%member_list)
1030 NULLIFY (input_file)
1031 ! Parse an external training input or duplicate the embedded screening input.
1032 CALL get_set_and_basis_id(opt_bas%comp_group(mp_id)%member_list(icalc), opt_bas, set_id, bas_id)
1033 IF (PRESENT(training_input)) THEN
1034 CALL section_vals_duplicate(training_input, input_file)
1035 input_path = "embedded frontier-orbital screening input"
1036 ELSE
1037 CALL m_chdir(trim(opt_bas%training_dir(set_id)), ierr)
1038 IF (ierr /= 0) THEN
1039 CALL cp_abort(__location__, &
1040 "Could not change to directory <"//trim(opt_bas%training_dir(set_id))//">")
1041 END IF
1042 input_file => read_input(input_declaration, &
1043 opt_bas%training_input(set_id), &
1044 initial_variables=empty_initial_variables, &
1045 para_env=para_env)
1046 input_path = opt_bas%training_input(set_id)
1047 END IF
1048
1049 CALL modify_input_settings(opt_bas, bas_id, input_file)
1050 IF (opt_bas%quiet_output .OR. opt_bas%method == method_mo_fit_occ_virtual) THEN
1051 IF (opt_bas%quiet_output) THEN
1052 CALL section_vals_val_set(input_file, "GLOBAL%PRINT_LEVEL", i_val=silent_print_level)
1053 END IF
1054 f_env_output_unit = -1
1055 IF (para_env%is_source()) f_env_output_unit = cp_logger_get_default_unit_nr()
1056 CALL create_force_env(f_env_id(icalc), &
1057 input_declaration=input_declaration, &
1058 input_path=input_path, &
1059 input=input_file, &
1060 output_unit=f_env_output_unit, &
1061 owns_out_unit=.false., &
1062 mpi_comm=mpi_comm_opt, &
1063 ierr=stat)
1064 ELSE
1065 CALL create_force_env(f_env_id(icalc), &
1066 input_declaration=input_declaration, &
1067 input_path=input_path, &
1068 input=input_file, &
1069 output_path="scrap_information", &
1070 mpi_comm=mpi_comm_opt, &
1071 ierr=stat)
1072 END IF
1073
1074 ! some weirdness with the default stacks defaults have to be addded to get the
1075 ! correct default program name this causes trouble with the timer stack if kept
1076 CALL f_env_add_defaults(f_env_id(icalc), f_env)
1077 force_env => f_env%force_env
1078 CALL force_env_get(force_env, qs_env=qs_env)
1079 IF (.NOT. PRESENT(training_input)) CALL allocate_mo_sets(qs_env)
1080 CALL f_env_rm_defaults(f_env, stat)
1081 IF (.NOT. PRESENT(training_input)) THEN
1082 CALL get_qs_env(qs_env, ks_env=ks_env)
1083 CALL build_qs_neighbor_lists(qs_env, para_env, molecular=.false., &
1084 force_env_section=qs_env%input)
1085 CALL get_ks_env(ks_env, &
1086 matrix_s=matrix_s, &
1087 sab_orb=sab_orb)
1088 CALL build_overlap_matrix(ks_env, matrix_s=matrix_s, &
1089 matrix_name="OVERLAP", &
1090 basis_type_a="ORB", &
1091 basis_type_b="ORB", &
1092 sab_nl=sab_orb)
1093 CALL set_ks_env(ks_env, matrix_s=matrix_s)
1094 IF (PRESENT(matrix_s_inv)) THEN
1095 CALL get_qs_env(qs_env, matrix_s=matrix_s, blacs_env=blacs_env)
1096 CALL calculate_overlap_inverse(matrix_s(1)%matrix, matrix_s_inv(icalc), &
1097 para_env, blacs_env)
1098 END IF
1099 CALL calculate_ks_matrix(qs_env)
1100 END IF
1101 IF (opt_bas%method == method_mo_fit_occ_virtual .AND. PRESENT(reference)) THEN
1102 CALL frontier_orbitals_reference_init(qs_env, reference(icalc))
1103 END IF
1104
1105 CALL section_vals_release(input_file)
1106
1107 CALL qs_env_part_release(qs_env)
1108
1109 IF (.NOT. PRESENT(training_input)) CALL m_chdir(trim(adjustl(main_dir)), ierr)
1110 END DO
1111
1112 CALL timestop(handle)
1113
1114 END SUBROUTINE init_training_force_envs
1115
1116! **************************************************************************************************
1117!> \brief variable update from the powell vector for all sets
1118!> \param opt_bas ...
1119!> \author Florian Schiffmann
1120! **************************************************************************************************
1121
1122 SUBROUTINE update_free_vars(opt_bas)
1123 TYPE(basis_optimization_type) :: opt_bas
1124
1125 CHARACTER(len=*), PARAMETER :: routinen = 'update_free_vars'
1126
1127 INTEGER :: handle, ikind, iset, ix
1128
1129 CALL timeset(routinen, handle)
1130 ix = 0
1131 DO ikind = 1, opt_bas%nkind
1132 DO iset = 1, opt_bas%kind_basis(ikind)%flex_basis(0)%nsets
1133 CALL update_subset_freevars(opt_bas%kind_basis(ikind)%flex_basis(0)%subset(iset), ix, opt_bas%x_opt)
1134 END DO
1135 END DO
1136 CALL timestop(handle)
1137
1138 END SUBROUTINE update_free_vars
1139
1140! **************************************************************************************************
1141!> \brief low level update for the basis sets. Exponents are transformed according to constraint
1142!> \param subset ...
1143!> \param ix ...
1144!> \param x ...
1145!> \author Florian Schiffmann
1146! **************************************************************************************************
1147
1148 SUBROUTINE update_subset_freevars(subset, ix, x)
1149 TYPE(subset_type) :: subset
1150 INTEGER :: ix
1151 REAL(kind=dp), DIMENSION(:) :: x
1152
1153 CHARACTER(len=*), PARAMETER :: routinen = 'update_subset_freevars'
1154
1155 INTEGER :: handle, icon1, icon2, icont, iexp, il, &
1156 istart
1157 REAL(kind=dp) :: fermi_f, gs_scale
1158
1159 CALL timeset(routinen, handle)
1160 DO iexp = 1, subset%nexp
1161 IF (subset%opt_exps(iexp)) THEN
1162 ix = ix + 1
1163 subset%exps(iexp) = abs(x(ix))
1164 IF (subset%exp_has_const(iexp)) THEN
1165 !use a fermi function to keep exponents in a given range around their initial value
1166 fermi_f = 1.0_dp/(exp((x(ix) - 1.0_dp)/0.5_dp) + 1.0_dp)
1167 subset%exps(iexp) = (2.0_dp*fermi_f - 1.0_dp)*subset%exp_const(iexp)%var_fac*subset%exp_const(iexp)%init + &
1168 subset%exp_const(iexp)%init
1169 ELSE
1170
1171 END IF
1172 END IF
1173 DO icont = 1, subset%ncon_tot
1174 IF (subset%opt_coeff(iexp, icont)) THEN
1175 ix = ix + 1
1176 subset%coeff(iexp, icont) = x(ix)
1177 END IF
1178 END DO
1179 END DO
1180
1181 ! orthonormalize contraction coefficients using gram schmidt
1182 istart = 1
1183 DO il = 1, subset%nl
1184 DO icon1 = istart, istart + subset%l(il) - 2
1185 DO icon2 = icon1 + 1, istart + subset%l(il) - 1
1186 gs_scale = dot_product(subset%coeff(:, icon2), subset%coeff(:, icon1))/ &
1187 dot_product(subset%coeff(:, icon1), subset%coeff(:, icon1))
1188 subset%coeff(:, icon2) = subset%coeff(:, icon2) - gs_scale*subset%coeff(:, icon1)
1189 END DO
1190 END DO
1191 istart = istart + subset%l(il)
1192 END DO
1193
1194 DO icon1 = 1, subset%ncon_tot
1195 subset%coeff(:, icon1) = subset%coeff(:, icon1)/norm2(subset%coeff(:, icon1))
1196 END DO
1197 CALL timestop(handle)
1198
1199 END SUBROUTINE update_subset_freevars
1200
1201! **************************************************************************************************
1202!> \brief variable initialization for the powell vector for all sets
1203!> \param opt_bas ...
1204!> \author Florian Schiffmann
1205! **************************************************************************************************
1206
1207 SUBROUTINE init_free_vars(opt_bas)
1208 TYPE(basis_optimization_type) :: opt_bas
1209
1210 CHARACTER(len=*), PARAMETER :: routinen = 'init_free_vars'
1211
1212 INTEGER :: handle, ikind, iset, ix
1213
1214 CALL timeset(routinen, handle)
1215 ix = 0
1216 DO ikind = 1, opt_bas%nkind
1217 DO iset = 1, opt_bas%kind_basis(ikind)%flex_basis(0)%nsets
1218 CALL init_subset_freevars(opt_bas%kind_basis(ikind)%flex_basis(0)%subset(iset), ix, opt_bas%x_opt)
1219 END DO
1220 END DO
1221 CALL timestop(handle)
1222
1223 END SUBROUTINE init_free_vars
1224
1225! **************************************************************************************************
1226!> \brief variable initialization for the powell vector from low level informations
1227!> constraint exponents will be mapped on a fermi function
1228!> \param subset ...
1229!> \param ix ...
1230!> \param x ...
1231!> \author Florian Schiffmann
1232! **************************************************************************************************
1233
1234 SUBROUTINE init_subset_freevars(subset, ix, x)
1235 TYPE(subset_type) :: subset
1236 INTEGER :: ix
1237 REAL(kind=dp), DIMENSION(:) :: x
1238
1239 CHARACTER(len=*), PARAMETER :: routinen = 'init_subset_freevars'
1240
1241 INTEGER :: handle, icont, iexp
1242 REAL(kind=dp) :: fract
1243
1244 CALL timeset(routinen, handle)
1245
1246 DO iexp = 1, subset%nexp
1247 IF (subset%opt_exps(iexp)) THEN
1248 ix = ix + 1
1249 x(ix) = subset%exps(iexp)
1250 IF (subset%exp_has_const(iexp)) THEN
1251 IF (subset%exp_const(iexp)%const_type == 0) THEN
1252 fract = 1.0_dp + (subset%exps(iexp) - subset%exp_const(iexp)%init)/ &
1253 (subset%exp_const(iexp)%init*subset%exp_const(iexp)%var_fac)
1254 x(ix) = 0.5_dp*log((2.0_dp/fract - 1.0_dp)) + 1.0_dp
1255 END IF
1256 IF (subset%exp_const(iexp)%const_type == 1) THEN
1257 x(ix) = 1.0_dp
1258 END IF
1259 END IF
1260 END IF
1261 DO icont = 1, subset%ncon_tot
1262 IF (subset%opt_coeff(iexp, icont)) THEN
1263 ix = ix + 1
1264 x(ix) = subset%coeff(iexp, icont)
1265 END IF
1266 END DO
1267 END DO
1268 CALL timestop(handle)
1269
1270 END SUBROUTINE init_subset_freevars
1271
1272! **************************************************************************************************
1273!> \brief commuticates all info to the master and assembles the output
1274!> \param f_vec ...
1275!> \param cond_vec ...
1276!> \param my_time ...
1277!> \param tot_time ...
1278!> \param opt_bas ...
1279!> \param iopt ...
1280!> \param para_env_top ...
1281!> \author Florian Schiffmann
1282! **************************************************************************************************
1283
1284 SUBROUTINE output_opt_info(f_vec, cond_vec, my_time, tot_time, opt_bas, iopt, para_env_top)
1285 REAL(kind=dp), DIMENSION(:) :: f_vec, cond_vec, my_time, tot_time
1286 TYPE(basis_optimization_type) :: opt_bas
1287 INTEGER :: iopt
1288 TYPE(mp_para_env_type), POINTER :: para_env_top
1289
1290 CHARACTER(len=*), PARAMETER :: routinen = 'output_opt_info'
1291
1292 INTEGER :: handle, ibasis, icalc, iset, unit_nr
1293 TYPE(cp_logger_type), POINTER :: logger
1294
1295 CALL timeset(routinen, handle)
1296 logger => cp_get_default_logger()
1297
1298 tot_time = tot_time + my_time
1299
1300 unit_nr = -1
1301 IF (para_env_top%is_source() .AND. (mod(iopt, opt_bas%write_frequency) == 0 .OR. iopt == opt_bas%powell_param%maxfun)) THEN
1302 unit_nr = cp_logger_get_default_unit_nr(logger)
1303 END IF
1304
1305 IF (unit_nr > 0) THEN
1306 WRITE (unit_nr, '(1X,A,I8)') "BASOPT| Information at iteration number:", iopt
1307 WRITE (unit_nr, '(1X,A)') "BASOPT| Training set | Combination | Rho difference | Condition num. | Time"
1308 WRITE (unit_nr, '(1X,A)') "BASOPT| -----------------------------------------------------------------------"
1309 icalc = 0
1310 DO iset = 1, opt_bas%ntraining_sets
1311 DO ibasis = 1, opt_bas%ncombinations
1312 icalc = icalc + 1
1313 WRITE (unit_nr, '(1X,A,2(5X,I3,5X,A),2(1X,E14.8,1X,A),1X,F8.1)') &
1314 'BASOPT| ', iset, "|", ibasis, "|", f_vec(icalc), "|", cond_vec(icalc), "|", tot_time(icalc)
1315 END DO
1316 END DO
1317 WRITE (unit_nr, '(1X,A)') "BASOPT| -----------------------------------------------------------------------"
1318 WRITE (unit_nr, '(1X,A,E14.8)') "BASOPT| Total residuum value: ", opt_bas%powell_param%f
1319 WRITE (unit_nr, '(A)') ""
1320 END IF
1321 CALL timestop(handle)
1322 END SUBROUTINE output_opt_info
1323
1324END MODULE optimize_basis
methods related to the blacs parallel environment
DBCSR operations in CP2K.
represent the structure of a full matrix
subroutine, public cp_fm_struct_create(fmstruct, para_env, context, nrow_global, ncol_global, nrow_block, ncol_block, descriptor, first_p_pos, local_leading_dimension, template_fmstruct, square_blocks, force_block)
allocates and initializes a full matrix structure
subroutine, public cp_fm_struct_release(fmstruct)
releases a full matrix structure
represent a full matrix distributed on many processors
Definition cp_fm_types.F:15
various routines to log and control the output. The idea is that decisions about where to log should ...
recursive integer function, public cp_logger_get_default_unit_nr(logger, local, skip_not_ionode)
asks the default unit number of the given logger. try to use cp_logger_get_unit_nr
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public silent_print_level
interface to use cp2k as library
recursive subroutine, public destroy_force_env(env_id, ierr, q_finalize)
deallocates the force_env with the given id
subroutine, public f_env_get_from_id(f_env_id, f_env)
...
subroutine, public f_env_add_defaults(f_env_id, f_env, handle)
adds the default environments of the f_env to the stack of the defaults, and returns a new error and ...
recursive subroutine, public create_force_env(new_env_id, input_declaration, input_path, output_path, mpi_comm, output_unit, owns_out_unit, input, ierr, work_dir, initial_variables)
creates a new force environment using the given input, and writing the output to the given output uni...
subroutine, public f_env_rm_defaults(f_env, ierr, handle)
removes the default environments of the f_env to the stack of the defaults, and sets ierr accordingly...
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
Define type storing the global information of a run. Keep the amount of stored data small....
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public restart_guess
checks the input and perform some automatic "magic" on it
subroutine, public check_cp2k_input(input_declaration, input_file, para_env, output_unit)
performs further checks on an input that parsed successfully
parse cp2k input files
type(section_vals_type) function, pointer, public read_input(input_declaration, file_path, initial_variables, para_env)
reads the cp2k input from the given filepath and returns a section_vals containing the input
objects that represent the structure of input sections and the data contained in an input section
subroutine, public section_vals_val_set(section_vals, keyword_name, i_rep_section, i_rep_val, val, l_val, i_val, r_val, c_val, l_vals_ptr, i_vals_ptr, r_vals_ptr, c_vals_ptr)
sets the requested value
recursive type(section_vals_type) function, pointer, public section_vals_get_subs_vals(section_vals, subsection_name, i_rep_section, can_return_null)
returns the values of the requested subsection
subroutine, public section_vals_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
subroutine, public section_vals_duplicate(section_vals_in, section_vals_out, i_rep_start, i_rep_end)
creates a deep copy from section_vals_in to section_vals_out
subroutine, public section_vals_val_get(section_vals, keyword_name, i_rep_section, i_rep_val, n_rep_val, val, l_val, i_val, r_val, c_val, l_vals, i_vals, r_vals, c_vals, explicit)
returns the requested value
recursive subroutine, public section_vals_release(section_vals)
releases the given object
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public dp
Definition kinds.F:34
integer, parameter, public default_string_length
Definition kinds.F:57
integer, parameter, public default_path_length
Definition kinds.F:58
Machine interface based on Fortran 2003 and POSIX.
Definition machine.F:17
subroutine, public m_getcwd(curdir)
...
Definition machine.F:607
subroutine, public m_chdir(dir, ierror)
...
Definition machine.F:636
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
Definition machine.F:141
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
subroutine, public update_basis_set(opt_bas, bas_id, basis_type, qs_env)
...
subroutine, public modify_input_settings(basis_optimization, bas_id, input_file)
change settings in the training input files to initialize all needed structures and adjust settings t...
subroutine, public calculate_ks_matrix(qs_env)
...
subroutine, public calculate_overlap_inverse(matrix_s, matrix_s_inv, para_env, context)
...
subroutine, public allocate_mo_sets(qs_env)
...
Automatic screening of frontier-orbital basis optimizations.
subroutine, public run_frontier_orbital_screening(input_declaration, section, para_env, globenv, frontier_screening_section, optimize_basis_driver)
Run serial frontier-orbital optimizations and evaluate their HOMO-LUMO gaps with new SCFs.
Utilities for frontier-orbital basis optimization.
subroutine, public frontier_orbitals_reference_init(qs_env, reference)
Diagonalize and store the frozen reference Hamiltonian.
subroutine, public frontier_orbitals_reference_release(reference)
Release the stored reference eigenvalues and eigenvectors.
subroutine, public evaluate_frontier_orbitals_objective(reference, matrix_s_candidate, matrix_s_candidate_reference, virtual_cutoff, virtual_smoothing, gap_scale, objective_result)
Construct and diagonalize the candidate Hamiltonian and evaluate the loss function.
subroutine, public print_frontier_orbital_basis_sets(unit_nr, element_symbols, reference_basis_names, initial_basis_names)
Print reference and initial basis-set names for every fitted atom kind.
subroutine, public optbas_build_neighborlist(qs_env, sab_aux, sab_aux_orb, basis_type)
rebuilds neighborlist for absis sets
subroutine, public evaluate_optvals(mos, mos_aux_fit, matrix_ks, q, snew, s_inv_orb, fval, energy, s_cond_number)
...
subroutine, public fit_mo_coeffs(saux, sauxorb, mos, mosaux)
...
integer, parameter, public method_mo_fit_occ
subroutine, public deallocate_basis_optimization_type(opt_bas)
Deallocate everything which was allocated before. Note not all arrays are used depending on the type ...
integer, parameter, public method_mo_fit_occ_virtual
subroutine, public get_set_and_basis_id(calc_id, opt_bas, set_id, bas_id)
returns a mapping from the calculation id to the trainings set id and basis combination id
subroutine, public optimize_basis_init_read_input(opt_bas, root_section, para_env, quiet_output, embedded_training)
initialize all parts of the optimization type and read input settings
subroutine, public write_basis(basis, element, unit_nr)
Write a basis set file which can be used from CP2K.
subroutine, public update_derived_basis_sets(opt_bas, write_it, output_file, para_env)
Regenerate the basis sets from reference 0 after an update from the optimizer to reference was perfor...
subroutine, public run_optimize_basis(input_declaration, root_section, para_env, globenv)
main entry point for methods aimed at optimizing basis sets
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public evolt
Definition physcon.F:183
Definition powell.F:9
subroutine, public powell_optimize(n, x, optstate)
...
Definition powell.F:52
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, mimic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs, do_rixs, tb_tblite)
Get the QUICKSTEP environment.
subroutine, public qs_env_release(qs_env)
releases the given qs_env (see doc/ReferenceCounting.html)
subroutine, public qs_env_part_release(qs_env)
releases part of the given qs_env in order to save memory
subroutine, public qs_env_create(qs_env, globenv)
allocates and intitializes a qs_env
subroutine, public qs_init(qs_env, para_env, root_section, globenv, cp_subsys, kpoint_env, qmmm, qmmm_env_qm, force_env_section, subsys_section, use_motion_section, silent, multip, charge)
Read the input and the database files for the setup of the QUICKSTEP environment.
Define the quickstep kind type and their sub types.
subroutine, public get_qs_kind_set(qs_kind_set, all_potential_present, tnadd_potential_present, gth_potential_present, sgp_potential_present, paw_atom_present, dft_plus_u_atom_present, maxcgf, maxsgf, maxco, maxco_proj, maxgtops, maxlgto, maxlprj, maxnset, maxsgf_set, ncgf, npgf, nset, nsgf, nshell, maxpol, maxlppl, maxlppnl, maxppnl, nelectron, maxder, max_ngrid_rad, max_sph_harm, maxg_iso_not0, lmax_rho0, basis_rcut, do_mtlr_present, basis_type, total_zeff_corr, npgf_seg, cneo_potential_present, nkind_q, natom_q)
Get attributes of an atomic kind set.
subroutine, public set_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, kpoints, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, subsys, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env)
...
subroutine, public get_ks_env(ks_env, v_hartree_rspace, s_mstruct_changed, rho_changed, exc_accint, potential_changed, forces_up_to_date, complex_ks, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, kinetic, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, matrix_vhxc, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_ks_im_kp, rho, rho_xc, vppl, xcint_weights, rho_core, rho_nlcc, rho_nlcc_g, vee, neighbor_list_id, sab_orb, sab_all, sac_ae, sac_ppl, sac_lri, sap_ppnl, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_vdw, sab_scp, sab_almo, sab_kp, sab_kp_nosym, sab_cneo, task_list, task_list_soft, kpoints, do_kpoints, atomic_kind_set, qs_kind_set, cell, cell_ref, use_ref_cell, particle_set, energy, force, local_particles, local_molecules, molecule_kind_set, molecule_set, subsys, cp_subsys, virial, results, atprop, nkind, natom, dft_control, dbcsr_dist, distribution_2d, pw_env, para_env, blacs_env, nelectron_total, nelectron_spin)
...
Definition and initialisation of the mo data type.
Definition qs_mo_types.F:22
subroutine, public init_mo_set(mo_set, fm_pool, fm_ref, fm_struct, name, counter)
initializes an allocated mo_set. eigenvalues, mo_coeff, occupation_numbers are valid only after this ...
subroutine, public allocate_mo_set(mo_set, nao, nmo, nelectron, n_el_f, maxocc, flexible_electron_count)
Allocates a mo set and partially initializes it (nao,nmo,nelectron, and flexible_electron_count are v...
subroutine, public deallocate_mo_set(mo_set)
Deallocate a wavefunction data structure.
subroutine, public get_mo_set(mo_set, maxocc, homo, lfomo, nao, nelectron, n_el_f, nmo, eigenvalues, occupation_numbers, mo_coeff, mo_coeff_b, uniform_occupation, kts, mu, flexible_electron_count)
Get the components of a MO set data structure.
Define the neighbor list data types and the corresponding functionality.
subroutine, public release_neighbor_list_sets(nlists)
releases an array of neighbor_list_sets
Generate the atomic neighbor lists.
subroutine, public build_qs_neighbor_lists(qs_env, para_env, molecular, force_env_section)
Build all the required neighbor lists for Quickstep.
Calculation of overlap matrix, its derivatives and forces.
Definition qs_overlap.F:19
subroutine, public build_overlap_matrix(ks_env, matrix_s, matrixkp_s, matrix_name, nderivative, basis_type_a, basis_type_b, sab_nl, calculate_forces, matrix_p, matrixkp_p, ext_kpoints)
Calculation of the overlap matrix over Cartesian Gaussian functions.
Definition qs_overlap.F:121
represent a blacs multidimensional parallel environment (for the mpi corrispective see cp_paratypes/m...
keeps the information about the structure of a full matrix
represent a full matrix
type of a logger, at the moment it contains just a print level starting at which level it should be l...
wrapper to abstract the force evaluation of the various methods
contains the initially parsed file and the initial parallel environment
represent a section of the input file
stores all the informations relevant to an mpi environment
type containing all information needed for basis matching
Provides all information about a quickstep kind.
calculation environment to calculate the ks matrix, holds all the needed vars. assumes that the core ...