(git:9111030)
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
26 USE gopt_f_types, ONLY: gopt_f_create,&
39 USE kinds, ONLY: dp
40#include "../base/base_uses.f90"
41
42 IMPLICIT NONE
43 PRIVATE
44
45 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'geo_opt'
46
47 PUBLIC :: cp_geo_opt, cp_rot_opt
48
49CONTAINS
50
51! **************************************************************************************************
52!> \brief Main driver to perform geometry optimization
53!> \param force_env ...
54!> \param globenv ...
55!> \param eval_opt_geo ...
56!> \param rm_restart_info ...
57! **************************************************************************************************
58 SUBROUTINE cp_geo_opt(force_env, globenv, eval_opt_geo, rm_restart_info)
59
60 TYPE(force_env_type), POINTER :: force_env
61 TYPE(global_environment_type), POINTER :: globenv
62 LOGICAL, INTENT(IN), OPTIONAL :: eval_opt_geo, rm_restart_info
63
64 CHARACTER(len=*), PARAMETER :: routinen = 'cp_geo_opt'
65
66 INTEGER :: handle, step_start_val
67 LOGICAL :: my_rm_restart_info
68 REAL(kind=dp), DIMENSION(:), POINTER :: x0
69 TYPE(cp_logger_type), POINTER :: logger
70 TYPE(gopt_f_type), POINTER :: gopt_env
71 TYPE(gopt_param_type), POINTER :: gopt_param
72 TYPE(section_vals_type), POINTER :: geo_section, root_section
73
74 CALL timeset(routinen, handle)
75 logger => cp_get_default_logger()
76
77 cpassert(ASSOCIATED(force_env))
78 cpassert(ASSOCIATED(globenv))
79 NULLIFY (gopt_param, gopt_env, x0)
80
81 ! Tell ACE that this is a dynamic run: full HFX is used for the
82 ! entire first geometry step so that wavefunction extrapolation
83 ! delivers a near-converged C_occ to step 1, making the ACE
84 ! projector BUILD there accurate.
85 CALL hfx_ace_set_dynamic_mode(.true.)
86
87 root_section => force_env%root_section
88 geo_section => section_vals_get_subs_vals(root_section, "MOTION%GEO_OPT")
89
90 ALLOCATE (gopt_param)
91 CALL gopt_param_read(gopt_param, geo_section)
92 CALL gopt_f_create(gopt_env, gopt_param, force_env=force_env, globenv=globenv, &
93 geo_opt_section=geo_section, eval_opt_geo=eval_opt_geo)
94 CALL gopt_f_create_x0(gopt_env, x0)
95
96 CALL section_vals_val_get(geo_section, "STEP_START_VAL", i_val=step_start_val)
97 CALL cp_add_iter_level(logger%iter_info, "GEO_OPT")
98 CALL cp_iterate(logger%iter_info, iter_nr=step_start_val)
99 CALL cp_geo_opt_low(force_env, globenv, gopt_param, gopt_env, &
100 geo_section, x0)
101 CALL cp_rm_iter_level(logger%iter_info, "GEO_OPT")
102
103 ! Reset counter for next iteration, unless rm_restart_info==.FALSE.
104 my_rm_restart_info = .true.
105 IF (PRESENT(rm_restart_info)) my_rm_restart_info = rm_restart_info
106 IF (my_rm_restart_info) THEN
107 CALL section_vals_val_set(geo_section, "STEP_START_VAL", i_val=0)
108 END IF
109
110 DEALLOCATE (x0)
111 CALL gopt_f_release(gopt_env)
112 DEALLOCATE (gopt_param)
113 CALL timestop(handle)
114
115 END SUBROUTINE cp_geo_opt
116
117! **************************************************************************************************
118!> \brief Main driver to perform rotation optimization for Dimer
119!> \param gopt_env ...
120!> \param x0 ...
121!> \param gopt_param ...
122!> \param geo_section ...
123! **************************************************************************************************
124 SUBROUTINE cp_rot_opt(gopt_env, x0, gopt_param, geo_section)
125 TYPE(gopt_f_type), POINTER :: gopt_env
126 REAL(kind=dp), DIMENSION(:), POINTER :: x0
127 TYPE(gopt_param_type), POINTER :: gopt_param
128 TYPE(section_vals_type), POINTER :: geo_section
129
130 CHARACTER(len=*), PARAMETER :: routinen = 'cp_rot_opt'
131
132 INTEGER :: handle, step_start_val
133 TYPE(cp_logger_type), POINTER :: logger
134
135 CALL timeset(routinen, handle)
136 logger => cp_get_default_logger()
137 cpassert(ASSOCIATED(gopt_env))
138 cpassert(ASSOCIATED(gopt_env%force_env))
139 cpassert(ASSOCIATED(gopt_env%globenv))
140
141 CALL section_vals_val_get(geo_section, "STEP_START_VAL", i_val=step_start_val)
142 CALL cp_add_iter_level(logger%iter_info, "ROT_OPT")
143 CALL cp_iterate(logger%iter_info, iter_nr=step_start_val)
144 CALL cp_geo_opt_low(gopt_env%force_env, gopt_env%globenv, gopt_param, gopt_env, &
145 geo_section, x0)
146 CALL cp_rm_iter_level(logger%iter_info, "ROT_OPT")
147
148 ! Reset counter for next iteration
149 CALL section_vals_val_set(geo_section, "STEP_START_VAL", i_val=0)
150 CALL timestop(handle)
151
152 END SUBROUTINE cp_rot_opt
153
154! **************************************************************************************************
155!> \brief call to low level geometry optimizers
156!> \param force_env ...
157!> \param globenv ...
158!> \param gopt_param ...
159!> \param gopt_env ...
160!> \param geo_section ...
161!> \param x0 ...
162! **************************************************************************************************
163 SUBROUTINE cp_geo_opt_low(force_env, globenv, gopt_param, gopt_env, &
164 geo_section, x0)
165 TYPE(force_env_type), POINTER :: force_env
166 TYPE(global_environment_type), POINTER :: globenv
167 TYPE(gopt_param_type), POINTER :: gopt_param
168 TYPE(gopt_f_type), POINTER :: gopt_env
169 TYPE(section_vals_type), POINTER :: geo_section
170 REAL(kind=dp), DIMENSION(:), POINTER :: x0
171
172 cpassert(ASSOCIATED(force_env))
173 cpassert(ASSOCIATED(globenv))
174 cpassert(ASSOCIATED(gopt_param))
175 cpassert(ASSOCIATED(gopt_env))
176 cpassert(ASSOCIATED(x0))
177 cpassert(ASSOCIATED(geo_section))
178
179 SELECT CASE (gopt_param%method_id)
181 CALL geoopt_bfgs(force_env, gopt_param, globenv, &
182 geo_section, gopt_env, x0)
184 CALL geoopt_lbfgs(force_env, gopt_param, globenv, &
185 geo_section, gopt_env, x0)
187 CALL geoopt_cg(force_env, gopt_param, globenv, &
188 geo_section, gopt_env, x0)
189 CASE DEFAULT
190 cpabort("Invalid or not yet implemented method for optimization")
191 END SELECT
192
193 END SUBROUTINE cp_geo_opt_low
194
195END 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_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
subroutine, public cp_rm_iter_level(iteration_info, level_name, n_rlevel_att)
Removes an iteration level.
subroutine, public cp_add_iter_level(iteration_info, level_name, n_rlevel_new)
Adds an iteration level.
Interface for the force calculations.
performs geometry optimization
Definition geo_opt.F:13
subroutine, public cp_geo_opt(force_env, globenv, eval_opt_geo, rm_restart_info)
Main driver to perform geometry optimization.
Definition geo_opt.F:59
subroutine, public cp_rot_opt(gopt_env, x0, gopt_param, geo_section)
Main driver to perform rotation optimization for Dimer.
Definition geo_opt.F:125
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
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