(git:591cf04)
Loading...
Searching...
No Matches
optbas_fenv_manipulation.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!--------------------------------------------------------------------------------------------------!
15 USE cp_dbcsr_api, ONLY: dbcsr_get_info,&
26 USE cp_fm_types, ONLY: cp_fm_create,&
52 USE qs_mo_types, ONLY: init_mo_set,&
55 USE qs_rho_types, ONLY: qs_rho_get,&
58#include "./base/base_uses.f90"
59
60 IMPLICIT NONE
61 PRIVATE
62
63 PUBLIC :: modify_input_settings, &
68
69 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'optbas_fenv_manipulation'
70
71CONTAINS
72
73! **************************************************************************************************
74!> \brief change settings in the training input files to initialize
75!> all needed structures and adjust settings to basis optimization
76!> \param basis_optimization ...
77!> \param bas_id ...
78!> \param input_file ...
79!> \author Florian Schiffmann
80! **************************************************************************************************
81 SUBROUTINE modify_input_settings(basis_optimization, bas_id, input_file)
82 TYPE(basis_optimization_type) :: basis_optimization
83 INTEGER :: bas_id
84 TYPE(section_vals_type), POINTER :: input_file
85
86 CHARACTER(LEN=default_string_length) :: atom
87 CHARACTER(LEN=default_string_length), &
88 DIMENSION(:), POINTER :: abasinfo, obasinfo
89 INTEGER :: ibasis, ikind, jkind, nbasis, nkind
90 TYPE(section_vals_type), POINTER :: dft_section, feval_section, &
91 kind_section, subsys_section
92
93 feval_section => section_vals_get_subs_vals(input_file, "FORCE_EVAL")
94 dft_section => section_vals_get_subs_vals(feval_section, "DFT")
95 subsys_section => section_vals_get_subs_vals(feval_section, "SUBSYS")
96 kind_section => section_vals_get_subs_vals(subsys_section, "KIND")
97
98 CALL section_vals_val_set(feval_section, "PRINT%DISTRIBUTION%_SECTION_PARAMETERS_", &
100 CALL section_vals_val_set(dft_section, "SCF%PRINT%TOTAL_DENSITIES%_SECTION_PARAMETERS_", &
101 i_val=debug_print_level)
102 CALL section_vals_val_set(dft_section, "SCF%PRINT%DETAILED_ENERGY%_SECTION_PARAMETERS_", &
103 i_val=debug_print_level)
104
105 ! Add the basis containing the optimization templates to the basis-file list.
106 CALL section_vals_val_get(dft_section, "BASIS_SET_FILE_NAME", n_rep_val=nbasis)
107 IF (basis_optimization%method == method_mo_fit_occ_virtual) THEN
108 CALL section_vals_val_set(dft_section, "BASIS_SET_FILE_NAME", i_rep_val=nbasis + 1, &
109 c_val=basis_optimization%template_basis_file)
110 ELSE
111 CALL section_vals_val_set(dft_section, "BASIS_SET_FILE_NAME", i_rep_val=nbasis + 1, &
112 c_val=basis_optimization%work_basis_file)
113 END IF
114
115 ! Set the auxilarry basis in the kind sections
116 CALL section_vals_get(kind_section, n_repetition=nkind)
117 DO ikind = 1, nkind
118 CALL section_vals_val_get(kind_section, "_SECTION_PARAMETERS_", &
119 c_val=atom, i_rep_section=ikind)
120 CALL uppercase(atom)
121 CALL section_vals_val_get(kind_section, "BASIS_SET", n_rep_val=nbasis, i_rep_section=ikind)
122 IF (nbasis > 1) THEN
123 CALL cp_abort(__location__, &
124 "Basis set optimization: Only one single BASIS_SET allowed per KIND in the reference input")
125 END IF
126 CALL section_vals_val_get(kind_section, "BASIS_SET", &
127 c_vals=obasinfo, i_rep_val=1, i_rep_section=ikind)
128 ALLOCATE (abasinfo(2))
129 abasinfo(1) = "AUX_OPT"
130 IF (SIZE(obasinfo) == 1) THEN
131 abasinfo(2) = obasinfo(1)
132 ELSE
133 abasinfo(2) = obasinfo(2)
134 END IF
135 CALL section_vals_val_set(kind_section, "BASIS_SET", &
136 c_vals_ptr=abasinfo, i_rep_val=2, i_rep_section=ikind)
137 CALL section_vals_val_get(kind_section, "BASIS_SET", n_rep_val=nbasis, i_rep_section=ikind)
138 cpassert(nbasis == 2)
139
140 DO jkind = 1, basis_optimization%nkind
141 IF (atom == basis_optimization%kind_basis(jkind)%element) THEN
142
143 NULLIFY (abasinfo)
144 CALL section_vals_val_get(kind_section, "BASIS_SET", &
145 c_vals=abasinfo, i_rep_val=2, i_rep_section=ikind)
146 ibasis = basis_optimization%combination(bas_id, jkind)
147 cpassert(SIZE(abasinfo) == 2)
148 cpassert(abasinfo(1) == "AUX_OPT")
149 abasinfo(2) = trim(adjustl(basis_optimization%kind_basis(jkind)%flex_basis(ibasis)%basis_name))
150 EXIT
151 END IF
152 END DO
153 END DO
154
155 END SUBROUTINE modify_input_settings
156
157! **************************************************************************************************
158!> \brief ...
159!> \param qs_env ...
160! **************************************************************************************************
161 SUBROUTINE allocate_mo_sets(qs_env)
162 TYPE(qs_environment_type), POINTER :: qs_env
163
164 INTEGER :: ispin
165 INTEGER, DIMENSION(2) :: nelectron_spin
166 LOGICAL :: natom_mismatch
167 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
168 TYPE(cp_fm_pool_p_type), DIMENSION(:), POINTER :: ao_mo_fm_pools
169 TYPE(dft_control_type), POINTER :: dft_control
170 TYPE(mo_set_type), DIMENSION(:), POINTER :: mos
171 TYPE(mp_para_env_type), POINTER :: para_env
172 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
173 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
174 TYPE(section_vals_type), POINTER :: dft_section
175
176 NULLIFY (para_env)
177 CALL get_qs_env(qs_env=qs_env, &
178 dft_control=dft_control, &
179 mos=mos, nelectron_spin=nelectron_spin, &
180 atomic_kind_set=atomic_kind_set, &
181 qs_kind_set=qs_kind_set, &
182 particle_set=particle_set, &
183 para_env=para_env)
184 dft_section => section_vals_get_subs_vals(qs_env%input, "DFT")
185
186 CALL mpools_get(qs_env%mpools, ao_mo_fm_pools=ao_mo_fm_pools)
187 DO ispin = 1, dft_control%nspins
188 IF (.NOT. ASSOCIATED(mos(ispin)%mo_coeff)) THEN
189 CALL init_mo_set(mos(ispin), &
190 fm_pool=ao_mo_fm_pools(ispin)%pool, &
191 name="qs_env%mo"//trim(adjustl(cp_to_string(ispin))))
192 END IF
193 END DO
194
195 CALL read_mo_set_from_restart(mos, qs_kind_set, particle_set, para_env, id_nr=0, &
196 multiplicity=dft_control%multiplicity, &
197 dft_section=dft_section, &
198 natom_mismatch=natom_mismatch)
199
200 END SUBROUTINE allocate_mo_sets
201
202! **************************************************************************************************
203!> \brief ...
204!> \param qs_env ...
205! **************************************************************************************************
206 SUBROUTINE calculate_ks_matrix(qs_env)
207 TYPE(qs_environment_type), POINTER :: qs_env
208
209 INTEGER :: ispin
210 TYPE(dbcsr_p_type), DIMENSION(:), POINTER :: rho_ao
211 TYPE(dft_control_type), POINTER :: dft_control
212 TYPE(qs_rho_type), POINTER :: rho
213
214 NULLIFY (rho, dft_control, rho_ao)
215
216 CALL qs_energies_init(qs_env, .false.)
217 CALL get_qs_env(qs_env, rho=rho, dft_control=dft_control)
218 CALL qs_rho_get(rho, rho_ao=rho_ao)
219 DO ispin = 1, dft_control%nspins
220 CALL calculate_density_matrix(qs_env%mos(ispin), rho_ao(ispin)%matrix)
221 END DO
222 CALL qs_rho_update_rho(rho, qs_env)
223 CALL qs_ks_did_change(qs_env%ks_env, rho_changed=.true.)
224 qs_env%requires_mo_derivs = .false.
225 CALL qs_ks_update_qs_env(qs_env, calculate_forces=.false.)
226
227 END SUBROUTINE calculate_ks_matrix
228
229! **************************************************************************************************
230!> \brief ...
231!> \param matrix_s ...
232!> \param matrix_s_inv ...
233!> \param para_env ...
234!> \param context ...
235! **************************************************************************************************
236 SUBROUTINE calculate_overlap_inverse(matrix_s, matrix_s_inv, para_env, context)
237 TYPE(dbcsr_type), POINTER :: matrix_s
238 TYPE(cp_fm_type), INTENT(OUT) :: matrix_s_inv
239 TYPE(mp_para_env_type), POINTER :: para_env
240 TYPE(cp_blacs_env_type), POINTER :: context
241
242 INTEGER :: nao
243 TYPE(cp_fm_struct_type), POINTER :: fm_struct_tmp
244 TYPE(cp_fm_type) :: work1
245
246 CALL dbcsr_get_info(matrix_s, nfullrows_total=nao)
247 CALL cp_fm_struct_create(fm_struct_tmp, nrow_global=nao, ncol_global=nao, &
248 para_env=para_env, context=context)
249
250 CALL cp_fm_create(matrix_s_inv, matrix_struct=fm_struct_tmp)
251 CALL cp_fm_create(work1, matrix_struct=fm_struct_tmp)
252 CALL copy_dbcsr_to_fm(matrix_s, matrix_s_inv)
253 CALL cp_fm_uplo_to_full(matrix_s_inv, work1)
254 CALL cp_fm_cholesky_decompose(matrix_s_inv)
255 CALL cp_fm_cholesky_invert(matrix_s_inv)
256 CALL cp_fm_uplo_to_full(matrix_s_inv, work1)
257 CALL cp_fm_struct_release(fm_struct_tmp)
258 CALL cp_fm_release(work1)
259
260 END SUBROUTINE calculate_overlap_inverse
261
262! **************************************************************************************************
263!> \brief ...
264!> \param opt_bas ...
265!> \param bas_id ...
266!> \param basis_type ...
267!> \param qs_env ...
268! **************************************************************************************************
269 SUBROUTINE update_basis_set(opt_bas, bas_id, basis_type, qs_env)
270 TYPE(basis_optimization_type) :: opt_bas
271 INTEGER :: bas_id
272 CHARACTER(*) :: basis_type
273 TYPE(qs_environment_type), POINTER :: qs_env
274
275 CHARACTER(default_string_length) :: elem
276 INTEGER :: ibasis, ikind, jkind
277 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
278 TYPE(dft_control_type), POINTER :: dft_control
279 TYPE(gto_basis_set_type), POINTER :: gto_basis
280 TYPE(qs_kind_type), DIMENSION(:), POINTER :: qs_kind_set
281
282 CALL get_qs_env(qs_env=qs_env, dft_control=dft_control, &
283 atomic_kind_set=atomic_kind_set, qs_kind_set=qs_kind_set)
284 DO ikind = 1, SIZE(qs_kind_set)
285 DO jkind = 1, opt_bas%nkind
286 CALL get_atomic_kind(atomic_kind_set(ikind), name=elem)
287 CALL uppercase(elem)
288 IF (elem == opt_bas%kind_basis(jkind)%element) THEN
289 ibasis = opt_bas%combination(bas_id, jkind)
290 CALL get_basis_from_container(qs_kind_set(ikind)%basis_sets, basis_set=gto_basis, &
291 basis_type=basis_type)
292 CALL transfer_data_to_gto(gto_basis, opt_bas%kind_basis(jkind)%flex_basis(ibasis))
293 CALL init_orb_basis_set(gto_basis)
294 END IF
295 END DO
296 END DO
297
298 CALL init_interaction_radii(dft_control%qs_control, qs_kind_set)
299
300 END SUBROUTINE update_basis_set
301
302! **************************************************************************************************
303!> \brief ...
304!> \param gto_basis ...
305!> \param basis ...
306! **************************************************************************************************
307 SUBROUTINE transfer_data_to_gto(gto_basis, basis)
308 TYPE(gto_basis_set_type), POINTER :: gto_basis
309 TYPE(flex_basis_type) :: basis
310
311 INTEGER :: ipgf, iset, ishell
312
313 DO iset = 1, basis%nsets
314 DO ishell = 1, basis%subset(iset)%ncon_tot
315 DO ipgf = 1, basis%subset(iset)%nexp
316 gto_basis%gcc(ipgf, ishell, iset) = basis%subset(iset)%coeff(ipgf, ishell)
317 END DO
318 END DO
319 DO ipgf = 1, basis%subset(iset)%nexp
320 gto_basis%zet(ipgf, iset) = basis%subset(iset)%exps(ipgf)
321 END DO
322 END DO
323
324 END SUBROUTINE transfer_data_to_gto
325
Definition atom.F:9
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
subroutine, public get_basis_from_container(container, basis_set, inumbas, basis_type)
Retrieve a basis set from the container.
subroutine, public init_orb_basis_set(gto_basis_set)
Initialise a Gaussian-type orbital (GTO) basis set data set.
methods related to the blacs parallel environment
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
subroutine, public dbcsr_get_info(matrix, nblkrows_total, nblkcols_total, nfullrows_total, nfullcols_total, nblkrows_local, nblkcols_local, nfullrows_local, nfullcols_local, my_prow, my_pcol, local_rows, local_cols, proc_row_dist, proc_col_dist, row_blk_size, col_blk_size, row_blk_offset, col_blk_offset, distribution, name, matrix_type, group)
...
DBCSR operations in CP2K.
subroutine, public copy_dbcsr_to_fm(matrix, fm, plan)
Copy a DBCSR matrix to a BLACS matrix.
Basic linear algebra operations for full matrices.
subroutine, public cp_fm_uplo_to_full(matrix, work, uplo)
given a triangular matrix according to uplo, computes the corresponding full matrix
various cholesky decomposition related routines
subroutine, public cp_fm_cholesky_invert(matrix, n, info_out)
used to replace the cholesky decomposition by the inverse
subroutine, public cp_fm_cholesky_decompose(matrix, n, info_out)
used to replace a symmetric positive def. matrix M with its cholesky decomposition U: M = U^T * U,...
pool for for elements that are retained and released
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
subroutine, public cp_fm_create(matrix, matrix_struct, name, nrow, ncol, set_zero)
creates a new full matrix with the given structure
various routines to log and control the output. The idea is that decisions about where to log should ...
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer, parameter, public debug_print_level
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_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
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public default_string_length
Definition kinds.F:57
Interface to the message passing library MPI.
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)
...
integer, parameter, public method_mo_fit_occ_virtual
Define the data structure for the particle information.
collects routines that calculate density matrices
Utility subroutine for qs energy calculation.
subroutine, public qs_energies_init(qs_env, calc_forces)
Refactoring of qs_energies_scf. Driver routine for the initial setup and calculations for a qs energy...
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.
Calculate the interaction radii for the operator matrix calculation.
subroutine, public init_interaction_radii(qs_control, qs_kind_set)
Initialize all the atomic kind radii for a given threshold value.
Define the quickstep kind type and their sub types.
routines that build the Kohn-Sham matrix (i.e calculate the coulomb and xc parts
subroutine, public qs_ks_update_qs_env(qs_env, calculate_forces, just_energy, print_active)
updates the Kohn Sham matrix of the given qs_env (facility method)
subroutine, public qs_ks_did_change(ks_env, s_mstruct_changed, rho_changed, potential_changed, full_reset)
tells that some of the things relevant to the ks calculation did change. has to be called when change...
wrapper for the pools of matrixes
subroutine, public mpools_get(mpools, ao_mo_fm_pools, ao_ao_fm_pools, mo_mo_fm_pools, ao_mosub_fm_pools, mosub_mosub_fm_pools, maxao_maxmo_fm_pool, maxao_maxao_fm_pool, maxmo_maxmo_fm_pool)
returns various attributes of the mpools (notably the pools contained in it)
Definition and initialisation of the mo data type.
Definition qs_mo_io.F:21
subroutine, public read_mo_set_from_restart(mo_array, qs_kind_set, particle_set, para_env, id_nr, multiplicity, dft_section, natom_mismatch, cdft, out_unit)
...
Definition qs_mo_io.F:524
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 ...
methods of the rho structure (defined in qs_rho_types)
subroutine, public qs_rho_update_rho(rho_struct, qs_env, rho_xc_external, local_rho_set, task_list_external, task_list_external_soft, pw_env_external, para_env_external)
updates rho_r and rho_g to the rhorho_ao. if use_kinetic_energy_density also computes tau_r and tau_g...
superstucture that hold various representations of the density and keeps track of which ones are vali...
subroutine, public qs_rho_get(rho_struct, rho_ao, rho_ao_im, rho_ao_kp, rho_ao_im_kp, rho_r, drho_r, rho_g, drho_g, tau_r, tau_g, rho_r_valid, drho_r_valid, rho_g_valid, drho_g_valid, tau_r_valid, tau_g_valid, tot_rho_r, tot_rho_g, rho_r_sccs, soft_valid, complex_rho_ao)
returns info about the density described by this object. If some representation is not available an e...
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
Provides all information about an atomic kind.
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
stores all the informations relevant to an mpi environment
type containing all information needed for basis matching
Provides all information about a quickstep kind.
keeps the density in various representations, keeping track of which ones are valid.