(git:ba1d7ca)
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,&
39 USE kinds, ONLY: default_string_length,&
40 dp
44#include "../base/base_uses.f90"
45
46 IMPLICIT NONE
47 PRIVATE
48
49 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .true.
50 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'gopt_f_types'
51
53
54! **************************************************************************************************
55!> \brief calculates the potential energy of a system, and its derivatives
56!> \par History
57!> none
58! **************************************************************************************************
60 INTEGER :: ref_count = 0
61 INTEGER :: nfree = 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 CALL force_env_retain(force_env)
137 gopt_env%force_env => force_env
138 gopt_env%motion_section => section_vals_get_subs_vals(force_env%root_section, "MOTION")
139 gopt_env%geo_section => geo_opt_section
140 gopt_env%globenv => globenv
141 gopt_env%eval_opt_geo = .true.
142 IF (PRESENT(eval_opt_geo)) gopt_env%eval_opt_geo = eval_opt_geo
143 gopt_env%require_consistent_energy_force = .true.
144
145 CALL force_env_get(force_env, subsys=subsys)
146 gopt_env%type_id = gopt_param%type_id
147 SELECT CASE (gopt_env%type_id)
149 CALL cp_subsys_get(subsys, &
150 particles=particles, &
151 shell_particles=shell_particles)
152 IF (ASSOCIATED(shell_particles)) nshell = shell_particles%n_els
153 ! The same number of shell and core particles is assumed
154 gopt_env%nfree = particles%n_els + nshell
155 gopt_env%label = "GEO_OPT"
156 gopt_env%tag = "GEOMETRY"
157 SELECT CASE (gopt_param%type_id)
159 gopt_env%ts_method_id = gopt_param%ts_method_id
160 SELECT CASE (gopt_param%ts_method_id)
162 ! For the Dimer method we use the same framework of geometry optimizers
163 ! already defined for cp2k..
164 dimer_section => section_vals_get_subs_vals(geo_opt_section, "TRANSITION_STATE%DIMER")
165 CALL dimer_env_create(gopt_env%dimer_env, subsys, globenv, dimer_section, force_env)
166
167 ! Setup the GEO_OPT environment for the rotation of the Dimer
168 rot_opt_section => section_vals_get_subs_vals(dimer_section, "ROT_OPT")
169 ALLOCATE (gopt_env%gopt_dimer_param)
170 CALL gopt_param_read(gopt_env%gopt_dimer_param, rot_opt_section, &
172 gopt_env%gopt_dimer_param%type_id = default_ts_method_id
173
174 CALL gopt_f_create(gopt_env%gopt_dimer_env, gopt_env%gopt_dimer_param, force_env=force_env, &
175 globenv=globenv, geo_opt_section=rot_opt_section, eval_opt_geo=eval_opt_geo)
176 CALL dimer_env_retain(gopt_env%dimer_env)
177 gopt_env%gopt_dimer_env%dimer_env => gopt_env%dimer_env
178 gopt_env%gopt_dimer_env%label = "ROT_OPT"
179 gopt_env%gopt_dimer_env%dimer_rotation = .true.
180 END SELECT
181 END SELECT
183 gopt_env%nfree = 6
184 gopt_env%label = "CELL_OPT"
185 gopt_env%tag = " CELL "
186 ALLOCATE (gopt_env%cell_env)
187 CALL cell_opt_env_create(gopt_env%cell_env, force_env, gopt_env%geo_section)
189 gopt_env%nfree = subsys%shell_particles%n_els
190 gopt_env%label = "SHELL_OPT"
191 gopt_env%tag = " SHELL-CORE "
192 gopt_env%shellcore_method_id = gopt_param%shellcore_method_id
193 END SELECT
194 END SUBROUTINE gopt_f_create
195
196! **************************************************************************************************
197!> \brief ...
198!> \param gopt_env the geometry optimization environment to retain
199!> \par History
200!> none
201! **************************************************************************************************
202 SUBROUTINE gopt_f_retain(gopt_env)
203 TYPE(gopt_f_type), POINTER :: gopt_env
204
205 cpassert(ASSOCIATED(gopt_env))
206 cpassert(gopt_env%ref_count > 0)
207 gopt_env%ref_count = gopt_env%ref_count + 1
208 END SUBROUTINE gopt_f_retain
209
210! **************************************************************************************************
211!> \brief ...
212!> \param gopt_env the geometry optimization environment to release
213!> \par History
214!> none
215! **************************************************************************************************
216 RECURSIVE SUBROUTINE gopt_f_release(gopt_env)
217 TYPE(gopt_f_type), POINTER :: gopt_env
218
219 IF (ASSOCIATED(gopt_env)) THEN
220 cpassert(gopt_env%ref_count > 0)
221 gopt_env%ref_count = gopt_env%ref_count - 1
222 IF (gopt_env%ref_count == 0) THEN
223 CALL force_env_release(gopt_env%force_env)
224 NULLIFY (gopt_env%force_env, &
225 gopt_env%globenv, &
226 gopt_env%motion_section, &
227 gopt_env%geo_section)
228 IF (ASSOCIATED(gopt_env%cell_env)) THEN
229 CALL cell_opt_env_release(gopt_env%cell_env)
230 DEALLOCATE (gopt_env%cell_env)
231 END IF
232 CALL dimer_env_release(gopt_env%dimer_env)
233 CALL gopt_f_release(gopt_env%gopt_dimer_env)
234 IF (ASSOCIATED(gopt_env%gopt_dimer_param)) DEALLOCATE (gopt_env%gopt_dimer_param)
235 CALL release_spgr_type(gopt_env%spgr)
236 DEALLOCATE (gopt_env)
237 END IF
238 END IF
239 END SUBROUTINE gopt_f_release
240
241END 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
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