LCOV - code coverage report
Current view: top level - src - almo_scf_env_methods.F (source / functions) Coverage Total Hit
Test: CP2K Regtests (git:561f475) Lines: 94.1 % 220 207
Test Date: 2026-06-21 06:48:54 Functions: 100.0 % 2 2

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

Generated by: LCOV version 2.0-1