(git:a90b72f)
Loading...
Searching...
No Matches
cp_lbfgs_geo.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 Main driver for L-BFGS optimizer
10!> \par History
11!> 01.2020 Space Group Symmetry introduced by Pierre-André Cazade [pcazade]
12! **************************************************************************************************
14 USE cell_types, ONLY: cell_type
30 USE gopt_f_methods, ONLY: gopt_f_ii,&
34 USE gopt_f_types, ONLY: gopt_f_type
40 USE kinds, ONLY: dp
46#include "../base/base_uses.f90"
47
48 IMPLICIT NONE
49 PRIVATE
50
51 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_lbfgs_geo'
52
53 PUBLIC :: geoopt_lbfgs
54
55CONTAINS
56
57! **************************************************************************************************
58!> \brief ...
59!> \param force_env ...
60!> \param gopt_param ...
61!> \param globenv ...
62!> \param geo_section ...
63!> \param gopt_env ...
64!> \param x0 ...
65!> \par History
66!> 08.2003 created [fawzi]
67!> 01.2020 modified [pcazade]
68!> \author Fawzi Mohamed
69! **************************************************************************************************
70 SUBROUTINE geoopt_lbfgs(force_env, gopt_param, globenv, geo_section, gopt_env, &
71 x0)
72 TYPE(force_env_type), POINTER :: force_env
73 TYPE(gopt_param_type), POINTER :: gopt_param
74 TYPE(global_environment_type), POINTER :: globenv
75 TYPE(section_vals_type), POINTER :: geo_section
76 TYPE(gopt_f_type), POINTER :: gopt_env
77 REAL(kind=dp), DIMENSION(:), POINTER :: x0
78
79 CHARACTER(len=*), PARAMETER :: routinen = 'geoopt_lbfgs'
80
81 INTEGER :: handle, iter_nr, its, output_unit
82 LOGICAL :: converged, should_stop
83 TYPE(cell_type), POINTER :: cell
84 TYPE(cp_lbfgs_opt_gopt_type), POINTER :: optimizer
85 TYPE(cp_logger_type), POINTER :: logger
86 TYPE(cp_subsys_type), POINTER :: subsys
87 TYPE(mp_para_env_type), POINTER :: para_env
88 TYPE(section_vals_type), POINTER :: root_section
89 TYPE(spgr_type), POINTER :: spgr
90
91 CALL timeset(routinen, handle)
92
93 NULLIFY (optimizer, para_env, spgr)
94 logger => cp_get_default_logger()
95 spgr => gopt_env%spgr
96 root_section => force_env%root_section
97 cpassert(ASSOCIATED(force_env))
98 cpassert(ASSOCIATED(gopt_param))
99
100 ! collecting subsys
101 CALL force_env_get(force_env, para_env=para_env, cell=cell, subsys=subsys)
102
103 ! Geometry optimization starts now
104 output_unit = cp_print_key_unit_nr(logger, geo_section, "PRINT%PROGRAM_RUN_INFO", &
105 extension=".geoLog")
106 CALL print_geo_opt_header(gopt_env, output_unit, "L-BFGS")
107
108 ! finds space group
109 CALL section_vals_val_get(geo_section, "KEEP_SPACE_GROUP", l_val=spgr%keep_space_group)
110 IF (spgr%keep_space_group) THEN
111 CALL identify_space_group(subsys, geo_section, gopt_env, output_unit)
112 CALL spgr_apply_rotations_coord(spgr, x0)
113 CALL print_spgr(spgr)
114 END IF
115
116 ! Stop if not implemented
117 IF (gopt_env%type_id == default_ts_method_id) &
118 cpabort("BFGS method not yet working with DIMER")
119
120 ALLOCATE (optimizer)
121 CALL cp_opt_gopt_create(optimizer, para_env=para_env, obj_funct=gopt_env, &
122 x0=x0, m=gopt_param%max_h_rank, &
123 print_every=gopt_param%print_control, &
124 wanted_relative_f_delta=gopt_param%wanted_rel_f_error, &
125 wanted_projected_gradient=gopt_param%wanted_proj_gradient, &
126 max_f_per_iter=gopt_param%max_f_per_iter, &
127 trust_radius=gopt_param%trust_radius)
128 CALL cp_iterate(logger%iter_info, increment=0, iter_nr_out=iter_nr)
129 converged = .false.
130
131 DO its = iter_nr + 1, gopt_param%max_iter
132 CALL cp_iterate(logger%iter_info, last=(its == gopt_param%max_iter))
133 CALL section_vals_val_set(geo_section, "STEP_START_VAL", i_val=its)
134 CALL gopt_f_ii(its, output_unit)
135
136 ! Real optimization step..
137 IF (.NOT. cp_opt_gopt_next(optimizer, geo_section=geo_section, &
138 force_env=force_env, gopt_param=gopt_param, &
139 converged=converged, spgr=spgr)) EXIT
140
141 ! Check for an external exit command
142 CALL external_control(should_stop, "GEO", globenv=globenv)
143 IF (should_stop) THEN
144 CALL cp_opt_gopt_stop(optimizer)
145 EXIT
146 END IF
147 IF (its == gopt_param%max_iter) EXIT
148 END DO
149
150 IF ((its == gopt_param%max_iter) .AND. (.NOT. converged)) THEN
151 CALL print_geo_opt_nc(gopt_env, output_unit)
152 END IF
153
154 ! show space_group
155 CALL section_vals_val_get(geo_section, "SHOW_SPACE_GROUP", l_val=spgr%show_space_group)
156 IF (spgr%show_space_group) THEN
157 CALL identify_space_group(subsys, geo_section, gopt_env, output_unit)
158 CALL print_spgr(spgr)
159 END IF
160
161 ! Write final output information, if converged
162 CALL cp_iterate(logger%iter_info, last=.true., increment=0)
163 CALL gopt_f_io_finalize(gopt_env, force_env, optimizer%x, converged, its, root_section, &
164 optimizer%para_env, optimizer%master, output_unit)
165
166 CALL cp_opt_gopt_release(optimizer)
167 DEALLOCATE (optimizer)
168 CALL cp_print_key_finished_output(output_unit, logger, geo_section, &
169 "PRINT%PROGRAM_RUN_INFO")
170
171 CALL timestop(handle)
172
173 END SUBROUTINE geoopt_lbfgs
174
175END MODULE cp_lbfgs_geo
Handles all functions related to the CELL.
Definition cell_types.F:15
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
Main driver for L-BFGS optimizer.
subroutine, public geoopt_lbfgs(force_env, gopt_param, globenv, geo_section, gopt_env, x0)
...
routines that optimize a functional using the limited memory bfgs quasi-newton method....
subroutine, public cp_opt_gopt_create(optimizer, para_env, obj_funct, x0, m, print_every, wanted_relative_f_delta, wanted_projected_gradient, lower_bound, upper_bound, kind_of_bound, master, max_f_per_iter, trust_radius)
initializes the optimizer
logical function, public cp_opt_gopt_next(optimizer, n_iter, f, last_f, projected_gradient, converged, geo_section, force_env, gopt_param, spgr)
goes to the next optimal point (after an optimizer iteration) returns true if converged
subroutine, public cp_opt_gopt_stop(optimizer)
stops the optimization
subroutine, public cp_opt_gopt_release(optimizer)
releases the optimizer (see doc/ReferenceCounting.html)
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...
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)
...
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
types that represent a subsys, i.e. a part of the system
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
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 print_geo_opt_header(gopt_env, output_unit, label)
...
recursive subroutine, public gopt_f_io_finalize(gopt_env, force_env, x0, conv, its, root_section, para_env, master, output_unit)
Handles the Output at the end of an optimization run.
subroutine, public print_geo_opt_nc(gopt_env, output_unit)
...
subroutine, public gopt_f_ii(its, output_unit)
Prints iteration step of the optimization procedure on screen.
contains a functional that calculates the energy and its derivatives for the geometry optimizer
contains typo and related routines to handle parameters controlling the GEO_OPT module
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public default_ts_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
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
Interface to the message passing library MPI.
Space Group Symmetry Type Module (version 1.0, Ferbruary 12, 2021)
Space Group Symmetry Module (version 1.0, January 16, 2020)
subroutine, public print_spgr(spgr)
routine prints Space Group Information.
subroutine, public spgr_apply_rotations_coord(spgr, coord)
routine applies the rotation matrices to the coordinates.
subroutine, public identify_space_group(subsys, geo_section, gopt_env, iunit)
routine indentifies the space group and finds rotation matrices.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
info for the optimizer (see the description of this module)
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
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
stores all the informations relevant to an mpi environment