(git:6344619)
Loading...
Searching...
No Matches
gopt_f_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!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief contains a functional that calculates the energy and its derivatives
10!> for the geometry optimizer
11!> \par History
12!> 01.2008 - Luca Bellucci and Teodoro Laino - Generalizing for Dimer Method.
13!> 03.2008 - Teodoro Laino [tlaino] - University of Zurich - Cell Optimization
14! **************************************************************************************************
21 USE dimer_types, ONLY: dimer_env_create,&
40 USE kinds, ONLY: default_string_length,&
41 dp
45#include "../base/base_uses.f90"
46
47 IMPLICIT NONE
48 PRIVATE
49
50 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
51 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gopt_f_types'
52
54
55! **************************************************************************************************
56!> \brief calculates the potential energy of a system, and its derivatives
57!> \par History
58!> none
59! **************************************************************************************************
61 INTEGER :: ref_count = 0
62 INTEGER :: type_id = default_cell_method_id
63 INTEGER :: ts_method_id = 0
64 INTEGER :: shellcore_method_id = 0
65 LOGICAL :: dimer_rotation = .false., do_line_search = .false., eval_opt_geo = .false.
66 CHARACTER(LEN=default_string_length) :: label = "", tag = ""
67 TYPE(force_env_type), POINTER :: force_env => null()
68 TYPE(global_environment_type), POINTER :: globenv => null()
69 ! Motion section must be references only for IO of the MOTION%PRINT..
70 TYPE(section_vals_type), POINTER :: motion_section => null(), geo_section => null()
71 TYPE(dimer_env_type), POINTER :: dimer_env => null()
72 TYPE(gopt_f_type), POINTER :: gopt_dimer_env => null()
73 TYPE(gopt_param_type), POINTER :: gopt_dimer_param => null()
74 TYPE(cell_opt_env_type), POINTER :: cell_env => null()
75 TYPE(spgr_type), POINTER :: spgr => null()
76 PROCEDURE(gopt_f_dimer_rotation_optimizer), POINTER, NOPASS :: dimer_rotation_optimizer => null()
77 REAL(kind=dp), DIMENSION(3, 3) :: h_ref = 0.0_dp
78 LOGICAL :: require_consistent_energy_force = .false.
79 END TYPE gopt_f_type
80
81 abstract INTERFACE
82! **************************************************************************************************
83!> \brief ...
84!> \param gopt_env ...
85!> \param x0 ...
86!> \param gopt_param ...
87!> \param geo_section ...
88! **************************************************************************************************
89 SUBROUTINE gopt_f_dimer_rotation_optimizer(gopt_env, x0, gopt_param, geo_section)
91 TYPE(gopt_f_type), POINTER :: gopt_env
92 REAL(kind=dp), DIMENSION(:), POINTER :: x0
93 TYPE(gopt_param_type), POINTER :: gopt_param
94 TYPE(section_vals_type), POINTER :: geo_section
96 END INTERFACE
97
98CONTAINS
99
100! **************************************************************************************************
101!> \brief ...
102!> \param gopt_env the geometry optimization environment to be created
103!> force_env:
104!> \param gopt_param ...
105!> \param force_env ...
106!> \param globenv ...
107!> \param geo_opt_section ...
108!> \param eval_opt_geo ...
109!> \par History
110!> none
111! **************************************************************************************************
112 RECURSIVE SUBROUTINE gopt_f_create(gopt_env, gopt_param, force_env, globenv, geo_opt_section, &
113 eval_opt_geo)
114
115 TYPE(gopt_f_type), POINTER :: gopt_env
116 TYPE(gopt_param_type), POINTER :: gopt_param
117 TYPE(force_env_type), POINTER :: force_env
118 TYPE(global_environment_type), POINTER :: globenv
119 TYPE(section_vals_type), POINTER :: geo_opt_section
120 LOGICAL, INTENT(IN), OPTIONAL :: eval_opt_geo
121
122 INTEGER :: nshell
123 TYPE(cp_subsys_type), POINTER :: subsys
124 TYPE(particle_list_type), POINTER :: particles, shell_particles
125 TYPE(section_vals_type), POINTER :: dimer_section, rot_opt_section
126
127 cpassert(.NOT. ASSOCIATED(gopt_env))
128 ALLOCATE (gopt_env)
129 nshell = 0
130
131 NULLIFY (gopt_env%dimer_env, gopt_env%gopt_dimer_env, gopt_env%gopt_dimer_param, gopt_env%cell_env, gopt_env%spgr)
132 gopt_env%ref_count = 1
133 gopt_env%dimer_rotation = .false.
134 gopt_env%do_line_search = .false.
135 ALLOCATE (gopt_env%spgr)
136 ! This routine reads the space-group flags once. The optimizer
137 ! drivers consume spgr%* only.
138 CALL section_vals_val_get(geo_opt_section, "KEEP_SPACE_GROUP", &
139 l_val=gopt_env%spgr%keep_space_group)
140 CALL section_vals_val_get(geo_opt_section, "SHOW_SPACE_GROUP", &
141 l_val=gopt_env%spgr%show_space_group)
142 CALL force_env_retain(force_env)
143 gopt_env%force_env => force_env
144 gopt_env%motion_section => section_vals_get_subs_vals(force_env%root_section, "MOTION")
145 gopt_env%geo_section => geo_opt_section
146 gopt_env%globenv => globenv
147 gopt_env%eval_opt_geo = .true.
148 IF (PRESENT(eval_opt_geo)) gopt_env%eval_opt_geo = eval_opt_geo
149 gopt_env%require_consistent_energy_force = .true.
150
151 CALL force_env_get(force_env, subsys=subsys)
152 gopt_env%type_id = gopt_param%type_id
153 SELECT CASE (gopt_env%type_id)
155 CALL cp_subsys_get(subsys, &
156 particles=particles, &
157 shell_particles=shell_particles)
158 IF (ASSOCIATED(shell_particles)) nshell = shell_particles%n_els
159 ! The same number of shell and core particles is assumed
160 gopt_env%label = "GEO_OPT"
161 gopt_env%tag = "GEOMETRY"
162 SELECT CASE (gopt_param%type_id)
164 gopt_env%ts_method_id = gopt_param%ts_method_id
165 SELECT CASE (gopt_param%ts_method_id)
167 ! For the Dimer method we use the same framework of geometry optimizers
168 ! already defined for cp2k..
169 dimer_section => section_vals_get_subs_vals(geo_opt_section, "TRANSITION_STATE%DIMER")
170 CALL dimer_env_create(gopt_env%dimer_env, subsys, globenv, dimer_section, force_env)
171
172 ! Setup the GEO_OPT environment for the rotation of the Dimer
173 rot_opt_section => section_vals_get_subs_vals(dimer_section, "ROT_OPT")
174 ALLOCATE (gopt_env%gopt_dimer_param)
175 CALL gopt_param_read(gopt_env%gopt_dimer_param, rot_opt_section, &
177 gopt_env%gopt_dimer_param%type_id = default_ts_method_id
178
179 CALL gopt_f_create(gopt_env%gopt_dimer_env, gopt_env%gopt_dimer_param, force_env=force_env, &
180 globenv=globenv, geo_opt_section=rot_opt_section, eval_opt_geo=eval_opt_geo)
181 CALL dimer_env_retain(gopt_env%dimer_env)
182 gopt_env%gopt_dimer_env%dimer_env => gopt_env%dimer_env
183 gopt_env%gopt_dimer_env%label = "ROT_OPT"
184 gopt_env%gopt_dimer_env%dimer_rotation = .true.
185 END SELECT
186 END SELECT
188 gopt_env%label = "CELL_OPT"
189 gopt_env%tag = " CELL "
190 ALLOCATE (gopt_env%cell_env)
191 CALL cell_opt_env_create(gopt_env%cell_env, force_env, gopt_env%geo_section)
193 gopt_env%label = "SHELL_OPT"
194 gopt_env%tag = " SHELL-CORE "
195 gopt_env%shellcore_method_id = gopt_param%shellcore_method_id
196 END SELECT
197 END SUBROUTINE gopt_f_create
198
199! **************************************************************************************************
200!> \brief ...
201!> \param gopt_env the geometry optimization environment to retain
202!> \par History
203!> none
204! **************************************************************************************************
205 SUBROUTINE gopt_f_retain(gopt_env)
206 TYPE(gopt_f_type), POINTER :: gopt_env
207
208 cpassert(ASSOCIATED(gopt_env))
209 cpassert(gopt_env%ref_count > 0)
210 gopt_env%ref_count = gopt_env%ref_count + 1
211 END SUBROUTINE gopt_f_retain
212
213! **************************************************************************************************
214!> \brief ...
215!> \param gopt_env the geometry optimization environment to release
216!> \par History
217!> none
218! **************************************************************************************************
219 RECURSIVE SUBROUTINE gopt_f_release(gopt_env)
220 TYPE(gopt_f_type), POINTER :: gopt_env
221
222 IF (ASSOCIATED(gopt_env)) THEN
223 cpassert(gopt_env%ref_count > 0)
224 gopt_env%ref_count = gopt_env%ref_count - 1
225 IF (gopt_env%ref_count == 0) THEN
226 CALL force_env_release(gopt_env%force_env)
227 NULLIFY (gopt_env%force_env, &
228 gopt_env%globenv, &
229 gopt_env%motion_section, &
230 gopt_env%geo_section)
231 IF (ASSOCIATED(gopt_env%cell_env)) THEN
232 CALL cell_opt_env_release(gopt_env%cell_env)
233 DEALLOCATE (gopt_env%cell_env)
234 END IF
235 CALL dimer_env_release(gopt_env%dimer_env)
236 CALL gopt_f_release(gopt_env%gopt_dimer_env)
237 IF (ASSOCIATED(gopt_env%gopt_dimer_param)) DEALLOCATE (gopt_env%gopt_dimer_param)
238 CALL release_spgr_type(gopt_env%spgr)
239 DEALLOCATE (gopt_env)
240 END IF
241 END IF
242 END SUBROUTINE gopt_f_release
243
244END MODULE gopt_f_types
Contains type used for a Simulation Cell Optimization.
subroutine, public cell_opt_env_release(cell_env)
...
subroutine, public cell_opt_env_create(cell_env, force_env, geo_section)
...
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell, cell_ref, use_ref_cell)
returns information about various attributes of the given subsys
Contains types used for a Dimer Method calculations.
Definition dimer_types.F:14
subroutine, public dimer_env_retain(dimer_env)
...
subroutine, public dimer_env_release(dimer_env)
...
subroutine, public dimer_env_create(dimer_env, subsys, globenv, dimer_section, force_env)
...
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
subroutine, public force_env_retain(force_env)
retains the given force env
recursive subroutine, public force_env_release(force_env)
releases the given force env
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
recursive subroutine, public gopt_f_create(gopt_env, gopt_param, force_env, globenv, geo_opt_section, eval_opt_geo)
...
subroutine, public gopt_f_retain(gopt_env)
...
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
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public default_shellcore_method_id
integer, parameter, public default_cell_method_id
integer, parameter, public default_minimization_method_id
integer, parameter, public default_ts_method_id
integer, parameter, public default_dimer_method_id
objects that represent the structure of input sections and the data contained in an input section
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
integer, parameter, public default_string_length
Definition kinds.F:57
represent a simple array based list of the given type
Space Group Symmetry Type Module (version 1.0, Ferbruary 12, 2021).
subroutine, public release_spgr_type(spgr)
Release the SPGR type.
Type containing all informations abour the simulation cell optimization.
represents a system: atoms, molecules, their pos,vel,...
Defines the environment for a Dimer Method calculation.
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