(git:27c966b)
Loading...
Searching...
No Matches
geo_opt.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!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief performs geometry optimization
10!> \par History
11!> none
12! **************************************************************************************************
13MODULE geo_opt
14
16 USE cg_optimizer, ONLY: geoopt_cg
17 USE cp_lbfgs_geo, ONLY: geoopt_lbfgs
29 USE gopt_f_types, ONLY: gopt_f_create,&
42 USE kinds, ONLY: dp
43#include "../base/base_uses.f90"
44
45 IMPLICIT NONE
46 PRIVATE
47
48 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'geo_opt'
49
51
52CONTAINS
53
54! **************************************************************************************************
55!> \brief Main driver to perform geometry optimization
56!> \param force_env ...
57!> \param globenv ...
58!> \param eval_opt_geo ...
59!> \param rm_restart_info ...
60! **************************************************************************************************
61 SUBROUTINE cp_geo_opt(force_env, globenv, eval_opt_geo, rm_restart_info)
62
63 TYPE(force_env_type), POINTER :: force_env
64 TYPE(global_environment_type), POINTER :: globenv
65 LOGICAL, INTENT(IN), OPTIONAL :: eval_opt_geo, rm_restart_info
66
67 CHARACTER(len=*), PARAMETER :: routinen = 'cp_geo_opt'
68
69 INTEGER :: handle, step_start_val
70 LOGICAL :: my_rm_restart_info
71 REAL(kind=dp), DIMENSION(:), POINTER :: x0
72 TYPE(cp_logger_type), POINTER :: logger
73 TYPE(gopt_f_type), POINTER :: gopt_env
74 TYPE(gopt_param_type), POINTER :: gopt_param
75 TYPE(section_vals_type), POINTER :: geo_section, root_section
76
77 CALL timeset(routinen, handle)
78 logger => cp_get_default_logger()
79
80 cpassert(ASSOCIATED(force_env))
81 cpassert(ASSOCIATED(globenv))
82 NULLIFY (gopt_param, gopt_env, x0)
83
84 ! Tell ACE that this is a dynamic run: full HFX is used for the
85 ! entire first geometry step so that wavefunction extrapolation
86 ! delivers a near-converged C_occ to step 1, making the ACE
87 ! projector BUILD there accurate.
88 CALL hfx_ace_set_dynamic_mode(.true.)
89
90 root_section => force_env%root_section
91 geo_section => section_vals_get_subs_vals(root_section, "MOTION%GEO_OPT")
92
93 ALLOCATE (gopt_param)
94 CALL gopt_param_read(gopt_param, geo_section)
95 CALL gopt_f_create(gopt_env, gopt_param, force_env=force_env, globenv=globenv, &
96 geo_opt_section=geo_section, eval_opt_geo=eval_opt_geo)
97 gopt_env%dimer_rotation_optimizer => cp_rot_opt
98 CALL gopt_f_create_x0(gopt_env, x0)
99
100 CALL section_vals_val_get(geo_section, "STEP_START_VAL", i_val=step_start_val)
101 CALL cp_add_iter_level(logger, "GEO_OPT")
102 CALL cp_iterate(logger%iter_info, iter_nr=step_start_val)
103 CALL gopt_dispatch_optimizer(force_env, globenv, gopt_param, gopt_env, &
104 geo_section, x0)
105 CALL cp_rm_iter_level(logger, "GEO_OPT")
106
107 ! Reset counter for next iteration, unless rm_restart_info==.FALSE.
108 my_rm_restart_info = .true.
109 IF (PRESENT(rm_restart_info)) my_rm_restart_info = rm_restart_info
110 IF (my_rm_restart_info) THEN
111 CALL section_vals_val_set(geo_section, "STEP_START_VAL", i_val=0)
112 END IF
113
114 DEALLOCATE (x0)
115 CALL gopt_f_release(gopt_env)
116 DEALLOCATE (gopt_param)
117 CALL timestop(handle)
118
119 END SUBROUTINE cp_geo_opt
120
121! **************************************************************************************************
122!> \brief Main driver to perform rotation optimization for Dimer
123!> \param gopt_env ...
124!> \param x0 ...
125!> \param gopt_param ...
126!> \param geo_section ...
127! **************************************************************************************************
128 SUBROUTINE cp_rot_opt(gopt_env, x0, gopt_param, geo_section)
129 TYPE(gopt_f_type), POINTER :: gopt_env
130 REAL(kind=dp), DIMENSION(:), POINTER :: x0
131 TYPE(gopt_param_type), POINTER :: gopt_param
132 TYPE(section_vals_type), POINTER :: geo_section
133
134 CHARACTER(len=*), PARAMETER :: routinen = 'cp_rot_opt'
135
136 INTEGER :: handle, step_start_val
137 TYPE(cp_logger_type), POINTER :: logger
138
139 CALL timeset(routinen, handle)
140 logger => cp_get_default_logger()
141 cpassert(ASSOCIATED(gopt_env))
142 cpassert(ASSOCIATED(gopt_env%force_env))
143 cpassert(ASSOCIATED(gopt_env%globenv))
144
145 CALL section_vals_val_get(geo_section, "STEP_START_VAL", i_val=step_start_val)
146 CALL cp_add_iter_level(logger, "ROT_OPT")
147 CALL cp_iterate(logger%iter_info, iter_nr=step_start_val)
148 CALL gopt_dispatch_optimizer(gopt_env%force_env, gopt_env%globenv, gopt_param, gopt_env, &
149 geo_section, x0)
150 CALL cp_rm_iter_level(logger, "ROT_OPT")
151
152 ! Reset counter for next iteration
153 CALL section_vals_val_set(geo_section, "STEP_START_VAL", i_val=0)
154 CALL timestop(handle)
155
156 END SUBROUTINE cp_rot_opt
157
158! **************************************************************************************************
159!> \brief dispatch to the selected optimizer (BFGS, L-BFGS or CG)
160!> \param force_env ...
161!> \param globenv ...
162!> \param gopt_param ...
163!> \param gopt_env ...
164!> \param geo_section ...
165!> \param x0 ...
166! **************************************************************************************************
167 SUBROUTINE gopt_dispatch_optimizer(force_env, globenv, gopt_param, gopt_env, &
168 geo_section, x0)
169 TYPE(force_env_type), POINTER :: force_env
170 TYPE(global_environment_type), POINTER :: globenv
171 TYPE(gopt_param_type), POINTER :: gopt_param
172 TYPE(gopt_f_type), POINTER :: gopt_env
173 TYPE(section_vals_type), POINTER :: geo_section
174 REAL(kind=dp), DIMENSION(:), POINTER :: x0
175
176 INTEGER :: output_unit
177 TYPE(cp_logger_type), POINTER :: logger
178
179 cpassert(ASSOCIATED(force_env))
180 cpassert(ASSOCIATED(globenv))
181 cpassert(ASSOCIATED(gopt_param))
182 cpassert(ASSOCIATED(gopt_env))
183 cpassert(ASSOCIATED(x0))
184 cpassert(ASSOCIATED(geo_section))
185
186 SELECT CASE (gopt_param%method_id)
188 CALL geoopt_bfgs(force_env, gopt_param, globenv, &
189 geo_section, gopt_env, x0)
191 CALL geoopt_lbfgs(force_env, gopt_param, globenv, &
192 geo_section, gopt_env, x0)
194 CALL geoopt_cg(force_env, gopt_param, globenv, &
195 geo_section, gopt_env, x0)
196 CASE DEFAULT
197 cpabort("Invalid or not yet implemented method for optimization")
198 END SELECT
199
200 IF ((.NOT. gopt_env%dimer_rotation) .AND. gopt_env%spgr%show_space_group) THEN
201 NULLIFY (logger)
202 logger => cp_get_default_logger()
203 output_unit = cp_print_key_unit_nr(logger, geo_section, "PRINT%PROGRAM_RUN_INFO", &
204 extension=".geoLog")
205 CALL gopt_f_space_group_show(gopt_env, geo_section, output_unit)
206 CALL cp_print_key_finished_output(output_unit, logger, geo_section, &
207 "PRINT%PROGRAM_RUN_INFO")
208 END IF
209
210 END SUBROUTINE gopt_dispatch_optimizer
211
212END MODULE geo_opt
Routines for Geometry optimization using BFGS algorithm.
recursive subroutine, public geoopt_bfgs(force_env, gopt_param, globenv, geo_section, gopt_env, x0)
Main driver for BFGS geometry optimizations.
Routines for Geometry optimization using Conjugate Gradients.
recursive subroutine, public geoopt_cg(force_env, gopt_param, globenv, geo_section, gopt_env, x0, do_update)
Driver for conjugate gradient optimization technique.
Main driver for L-BFGS optimizer.
subroutine, public geoopt_lbfgs(force_env, gopt_param, globenv, geo_section, gopt_env, x0)
...
various routines to log and control the output. The idea is that decisions about where to log should ...
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...
subroutine, public cp_add_iter_level(logger, level_name, n_rlevel_new)
Adds an iteration level.
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
subroutine, public cp_rm_iter_level(logger, level_name, n_rlevel_att)
Removes an iteration level.
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout, file_access)
...
Interface for the force calculations.
performs geometry optimization
Definition geo_opt.F:13
subroutine, public gopt_dispatch_optimizer(force_env, globenv, gopt_param, gopt_env, geo_section, x0)
dispatch to the selected optimizer (BFGS, L-BFGS or CG)
Definition geo_opt.F:169
subroutine, public cp_geo_opt(force_env, globenv, eval_opt_geo, rm_restart_info)
Main driver to perform geometry optimization.
Definition geo_opt.F:62
Define type storing the global information of a run. Keep the amount of stored data small....
contains a functional that calculates the energy and its derivatives for the geometry optimizer
subroutine, public gopt_f_create_x0(gopt_env, x0)
returns the value of the parameters for the actual configuration
subroutine, public gopt_f_space_group_show(gopt_env, geo_section, output_unit)
Identify and print the space group of the current structure (SHOW_SPACE_GROUP).
contains a functional that calculates the energy and its derivatives for the geometry optimizer
recursive subroutine, public gopt_f_create(gopt_env, gopt_param, force_env, globenv, geo_opt_section, eval_opt_geo)
...
recursive subroutine, public gopt_f_release(gopt_env)
...
contains typo and related routines to handle parameters controlling the GEO_OPT module
subroutine, public gopt_param_read(gopt_param, gopt_section, type_id)
reads the parameters of the geopmetry optimizer
Adaptively Compressed Exchange (ACE) operator for HFX. Reference: Lin, J. Chem. Theory Comput....
subroutine, public hfx_ace_set_dynamic_mode(is_dynamic)
Mark this run as dynamic (GEO_OPT/MD) so Bypass C fires for geo step 0. Call this once from the geo_o...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public default_lbfgs_method_id
integer, parameter, public default_bfgs_method_id
integer, parameter, public default_cg_method_id
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_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 dp
Definition kinds.F:34
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
calculates the potential energy of a system, and its derivatives