(git:f2099e5)
Loading...
Searching...
No Matches
optimize_basis_types.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!--------------------------------------------------------------------------------------------------!
8
9 USE kinds, ONLY: default_path_length,&
11 dp
12 USE powell, ONLY: opt_state_type
13#include "./base/base_uses.f90"
14
15 IMPLICIT NONE
16 PRIVATE
17
18 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'optimize_basis_types'
19
23
24 INTEGER, PARAMETER :: method_mo_fit_occ = 1
25 INTEGER, PARAMETER :: method_mo_fit_occ_virtual = 2
26
27 ! constraint information for a single constraing. boundary is translateed into a fermi function
28 ! like setting as for variational limited case
29 TYPE exp_constraint_type
30 INTEGER :: const_type = -1
31 REAL(kind=dp) :: llim = -1.0_dp, ulim = -1.0_dp
32 REAL(kind=dp) :: init = -1.0_dp, var_fac = -1.0_dp
33 END TYPE exp_constraint_type
34
35 ! Subset of a basis+ additional information on what to optimize.
36 ! *_x_ind maps to the index in the optimization vector
37 ! opt_* logical whether quantity ahould be optimized
38 ! *_const information for exponents used to constrain them
40 INTEGER :: lmin = -1, lmax = -1, nexp = -1
41 INTEGER :: n = -1, ncon_tot = -1, nl = -1
42 INTEGER, DIMENSION(:), ALLOCATABLE :: l
43 REAL(kind=dp), DIMENSION(:, :), ALLOCATABLE :: coeff
44 LOGICAL, DIMENSION(:, :), ALLOCATABLE :: opt_coeff
45 INTEGER, DIMENSION(:, :), ALLOCATABLE :: coeff_x_ind
46 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: exps
47 LOGICAL, DIMENSION(:), ALLOCATABLE :: opt_exps
48 INTEGER, DIMENSION(:), ALLOCATABLE :: exp_x_ind
49 LOGICAL, DIMENSION(:), ALLOCATABLE :: exp_has_const
50 TYPE(exp_constraint_type), DIMENSION(:), &
51 ALLOCATABLE :: exp_const
52 END TYPE subset_type
53
54 ! Top level information for basis sets+ vector subset with the real information
56 CHARACTER(LEN=default_string_length) :: basis_name = ""
57 INTEGER :: nopt = -1
58 INTEGER :: nsets = -1
59 TYPE(subset_type), DIMENSION(:), ALLOCATABLE :: subset
60 END TYPE flex_basis_type
61
62 ! information for optimization: whether coeff has to be optimized or not
63 TYPE use_contr_type
64 LOGICAL, DIMENSION(:), ALLOCATABLE :: in_use
65 END TYPE use_contr_type
66
67 ! information about how to generate the derived basis sets
69 CHARACTER(LEN=default_string_length) :: basis_name = ""
70 INTEGER :: reference_set = -1
71 INTEGER, DIMENSION(:, :), ALLOCATABLE :: remove_contr
72 INTEGER :: nsets = -1, ncontr = -1
73 INTEGER, DIMENSION(:), ALLOCATABLE :: remove_set
74 LOGICAL, DIMENSION(:), ALLOCATABLE :: in_use_set
75 TYPE(use_contr_type), DIMENSION(:), ALLOCATABLE :: use_contr
76 END TYPE derived_basis_info
77
78 ! some usual stuff for basis information and an info type containing the
79 ! the translated input on how to genrate the derived basis sets
80 ! a flexible basis type for every derived basis
81 ! ATTENTION: both vectors go from 0:nbasis_deriv. entry 0 is the one specified
82 ! in the template basis file
83 TYPE kind_basis_type
84 CHARACTER(LEN=default_string_length) :: basis_name = ""
85 CHARACTER(LEN=default_string_length) :: element = ""
86 INTEGER :: nbasis_deriv = -1
87 TYPE(derived_basis_info), DIMENSION(:), &
88 ALLOCATABLE :: deriv_info
89 TYPE(flex_basis_type), DIMENSION(:), ALLOCATABLE :: flex_basis
90 END TYPE kind_basis_type
91
92 ! vector of length nparallel_groups containing the id's of the calculations in the group
93 TYPE comp_group_type
94 INTEGER, DIMENSION(:), ALLOCATABLE :: member_list
95 END TYPE comp_group_type
96
97! **************************************************************************************************
98!> \brief type containing all information needed for basis matching
99!> \author Florian Schiffmann
100! **************************************************************************************************
102 TYPE(comp_group_type), DIMENSION(:), ALLOCATABLE :: comp_group
103 INTEGER :: ntraining_sets = -1
104 INTEGER :: ncombinations = -1
105 LOGICAL :: use_condition_number = .false.
106 INTEGER, DIMENSION(:), POINTER :: group_partition => null()
107 INTEGER :: n_groups_created = -1
108 INTEGER, DIMENSION(:), ALLOCATABLE :: sub_sources
109 INTEGER, DIMENSION(:, :), ALLOCATABLE :: combination
110 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: fval_weight
111 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: condition_weight
112 INTEGER :: method = method_mo_fit_occ
113 REAL(kind=dp) :: occupied_weight = 1.0_dp
114 REAL(kind=dp) :: virtual_weight = 1.0_dp
115 REAL(kind=dp) :: empty_overlap_weight = 1.0_dp
116 REAL(kind=dp) :: gap_weight = 1.0e-3_dp
117 REAL(kind=dp) :: coefficient_weight = 1.0e-3_dp
118 REAL(kind=dp) :: gap_energy_scale = 0.0_dp
119 REAL(kind=dp) :: virtual_energy_cutoff = 0.0_dp
120 REAL(kind=dp) :: virtual_energy_smoothing = 0.0_dp
121 LOGICAL :: quiet_output = .false.
122 INTEGER :: nkind = -1
123 INTEGER :: write_frequency = -1
124 INTEGER :: nbasis_deriv_types = -1
125 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: x_opt
126 REAL(kind=dp), DIMENSION(:), ALLOCATABLE :: x_initial
127 TYPE(opt_state_type) :: powell_param = opt_state_type()
128 CHARACTER(LEN=default_path_length), DIMENSION(:), ALLOCATABLE :: training_input
129 CHARACTER(LEN=default_path_length), DIMENSION(:), ALLOCATABLE :: training_dir
130 CHARACTER(LEN=default_path_length) :: work_basis_file = ""
131 CHARACTER(LEN=default_path_length) :: output_basis_file = ""
132 CHARACTER(LEN=default_path_length) :: template_basis_file = ""
133 TYPE(kind_basis_type), DIMENSION(:), ALLOCATABLE :: kind_basis
134 INTEGER :: opt_id = -1
136
137CONTAINS
138
139! **************************************************************************************************
140!> \brief Deallocate everything which was allocated before.
141!> Note not all arrays are used depending on the type of basis
142!> i.e derived or reference basis set
143!> \param opt_bas ...
144!> \author Florian Schiffmann
145! **************************************************************************************************
146
148 TYPE(basis_optimization_type) :: opt_bas
149
150 INTEGER :: igroup, ikind
151
152 IF (ASSOCIATED(opt_bas%group_partition)) DEALLOCATE (opt_bas%group_partition)
153 IF (ALLOCATED(opt_bas%sub_sources)) DEALLOCATE (opt_bas%sub_sources)
154 IF (ALLOCATED(opt_bas%combination)) DEALLOCATE (opt_bas%combination)
155 IF (ALLOCATED(opt_bas%x_opt)) DEALLOCATE (opt_bas%x_opt)
156 IF (ALLOCATED(opt_bas%x_initial)) DEALLOCATE (opt_bas%x_initial)
157 IF (ALLOCATED(opt_bas%training_input)) DEALLOCATE (opt_bas%training_input)
158 IF (ALLOCATED(opt_bas%training_dir)) DEALLOCATE (opt_bas%training_dir)
159 IF (ALLOCATED(opt_bas%fval_weight)) DEALLOCATE (opt_bas%fval_weight)
160 IF (ALLOCATED(opt_bas%condition_weight)) DEALLOCATE (opt_bas%condition_weight)
161
162 IF (ALLOCATED(opt_bas%comp_group)) THEN
163 DO igroup = 1, SIZE(opt_bas%comp_group)
164 IF (ALLOCATED(opt_bas%comp_group(igroup)%member_list)) DEALLOCATE (opt_bas%comp_group(igroup)%member_list)
165 END DO
166 DEALLOCATE (opt_bas%comp_group)
167 END IF
168
169 IF (ALLOCATED(opt_bas%kind_basis)) THEN
170 DO ikind = 1, SIZE(opt_bas%kind_basis)
171 CALL deallocate_kind_basis(opt_bas%kind_basis(ikind))
172 END DO
173 DEALLOCATE (opt_bas%kind_basis)
174 END IF
175
177
178! **************************************************************************************************
179!> \brief Some more deallocation of the subtypes of optimize_absis type
180!> \param kind ...
181!> \author Florian Schiffmann
182! **************************************************************************************************
183
184 SUBROUTINE deallocate_kind_basis(kind)
185 TYPE(kind_basis_type) :: kind
186
187 INTEGER :: ibasis, icont, iinfo, iset
188
189 IF (ALLOCATED(kind%deriv_info)) THEN
190 DO iinfo = 0, SIZE(kind%deriv_info) - 1
191 IF (ALLOCATED(kind%deriv_info(iinfo)%remove_contr)) DEALLOCATE (kind%deriv_info(iinfo)%remove_contr)
192 IF (ALLOCATED(kind%deriv_info(iinfo)%remove_set)) DEALLOCATE (kind%deriv_info(iinfo)%remove_set)
193 IF (ALLOCATED(kind%deriv_info(iinfo)%in_use_set)) DEALLOCATE (kind%deriv_info(iinfo)%in_use_set)
194 IF (ALLOCATED(kind%deriv_info(iinfo)%use_contr)) THEN
195 DO icont = 1, SIZE(kind%deriv_info(iinfo)%use_contr)
196 IF (ALLOCATED(kind%deriv_info(iinfo)%use_contr(icont)%in_use)) THEN
197 DEALLOCATE (kind%deriv_info(iinfo)%use_contr(icont)%in_use)
198 END IF
199 END DO
200 DEALLOCATE (kind%deriv_info(iinfo)%use_contr)
201 END IF
202 END DO
203 DEALLOCATE (kind%deriv_info)
204 END IF
205
206 IF (ALLOCATED(kind%flex_basis)) THEN
207 DO ibasis = 0, SIZE(kind%flex_basis) - 1
208 IF (ALLOCATED(kind%flex_basis(ibasis)%subset)) THEN
209 DO iset = 1, SIZE(kind%flex_basis(ibasis)%subset)
210 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%l)) THEN
211 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%l)
212 END IF
213 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%coeff)) THEN
214 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%coeff)
215 END IF
216 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%opt_coeff)) THEN
217 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%opt_coeff)
218 END IF
219 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%coeff_x_ind)) THEN
220 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%coeff_x_ind)
221 END IF
222 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%exps)) THEN
223 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%exps)
224 END IF
225 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%opt_exps)) THEN
226 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%opt_exps)
227 END IF
228 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%exp_x_ind)) THEN
229 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%exp_x_ind)
230 END IF
231 IF (ALLOCATED(kind%flex_basis(ibasis)%subset(iset)%exp_const)) THEN
232 DEALLOCATE (kind%flex_basis(ibasis)%subset(iset)%exp_const)
233 END IF
234 END DO
235 DEALLOCATE (kind%flex_basis(ibasis)%subset)
236 END IF
237 END DO
238 DEALLOCATE (kind%flex_basis)
239 END IF
240
241 END SUBROUTINE deallocate_kind_basis
242
243END MODULE optimize_basis_types
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
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
Definition powell.F:9
type containing all information needed for basis matching