(git:c28f603)
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 :: nfree = 0
63 INTEGER :: type_id = default_cell_method_id
64 INTEGER :: ts_method_id = 0
65 INTEGER :: shellcore_method_id = 0
66 LOGICAL :: dimer_rotation = .false., do_line_search = .false., eval_opt_geo = .false.
67 CHARACTER(LEN=default_string_length) :: label = "", tag = ""
68 TYPE(force_env_type), POINTER :: force_env => null()
69 TYPE(global_environment_type), POINTER :: globenv => null()
70 ! Motion section must be references only for IO of the MOTION%PRINT..
71 TYPE(section_vals_type), POINTER :: motion_section => null(), geo_section => null()
72 TYPE(dimer_env_type), POINTER :: dimer_env => null()
73 TYPE(gopt_f_type), POINTER :: gopt_dimer_env => null()
74 TYPE(gopt_param_type), POINTER :: gopt_dimer_param => null()
75 TYPE(cell_opt_env_type), POINTER :: cell_env => null()
76 TYPE(spgr_type), POINTER :: spgr => 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
81CONTAINS
82
83! **************************************************************************************************
84!> \brief ...
85!> \param gopt_env the geometry optimization environment to be created
86!> force_env:
87!> \param gopt_param ...
88!> \param force_env ...
89!> \param globenv ...
90!> \param geo_opt_section ...
91!> \param eval_opt_geo ...
92!> \par History
93!> none
94! **************************************************************************************************
95 RECURSIVE SUBROUTINE gopt_f_create(gopt_env, gopt_param, force_env, globenv, geo_opt_section, &
96 eval_opt_geo)
97
98 TYPE(gopt_f_type), POINTER :: gopt_env
99 TYPE(gopt_param_type), POINTER :: gopt_param
100 TYPE(force_env_type), POINTER :: force_env
101 TYPE(global_environment_type), POINTER :: globenv
102 TYPE(section_vals_type), POINTER :: geo_opt_section
103 LOGICAL, INTENT(IN), OPTIONAL :: eval_opt_geo
104
105 INTEGER :: natom, nshell
106 TYPE(cp_subsys_type), POINTER :: subsys
107 TYPE(particle_list_type), POINTER :: particles, shell_particles
108 TYPE(section_vals_type), POINTER :: dimer_section, rot_opt_section
109
110 cpassert(.NOT. ASSOCIATED(gopt_env))
111 ALLOCATE (gopt_env)
112 nshell = 0
113
114 NULLIFY (gopt_env%dimer_env, gopt_env%gopt_dimer_env, gopt_env%gopt_dimer_param, gopt_env%cell_env, gopt_env%spgr)
115 gopt_env%ref_count = 1
116 gopt_env%dimer_rotation = .false.
117 gopt_env%do_line_search = .false.
118 ALLOCATE (gopt_env%spgr)
119 CALL force_env_retain(force_env)
120 gopt_env%force_env => force_env
121 gopt_env%motion_section => section_vals_get_subs_vals(force_env%root_section, "MOTION")
122 gopt_env%geo_section => geo_opt_section
123 gopt_env%globenv => globenv
124 gopt_env%eval_opt_geo = .true.
125 IF (PRESENT(eval_opt_geo)) gopt_env%eval_opt_geo = eval_opt_geo
126 gopt_env%require_consistent_energy_force = .true.
127
128 CALL force_env_get(force_env, subsys=subsys)
129 gopt_env%type_id = gopt_param%type_id
130 SELECT CASE (gopt_env%type_id)
132 CALL cp_subsys_get(subsys, &
133 particles=particles, &
134 shell_particles=shell_particles)
135 IF (ASSOCIATED(shell_particles)) nshell = shell_particles%n_els
136 ! The same number of shell and core particles is assumed
137 gopt_env%nfree = particles%n_els + nshell
138 gopt_env%label = "GEO_OPT"
139 gopt_env%tag = "GEOMETRY"
140 SELECT CASE (gopt_param%type_id)
142 gopt_env%ts_method_id = gopt_param%ts_method_id
143 SELECT CASE (gopt_param%ts_method_id)
145 ! For the Dimer method we use the same framework of geometry optimizers
146 ! already defined for cp2k..
147 natom = force_env_get_natom(force_env)
148 dimer_section => section_vals_get_subs_vals(geo_opt_section, "TRANSITION_STATE%DIMER")
149 CALL dimer_env_create(gopt_env%dimer_env, subsys, globenv, dimer_section, force_env)
150
151 ! Setup the GEO_OPT environment for the rotation of the Dimer
152 rot_opt_section => section_vals_get_subs_vals(dimer_section, "ROT_OPT")
153 ALLOCATE (gopt_env%gopt_dimer_param)
154 CALL gopt_param_read(gopt_env%gopt_dimer_param, rot_opt_section, &
156 gopt_env%gopt_dimer_param%type_id = default_ts_method_id
157
158 CALL gopt_f_create(gopt_env%gopt_dimer_env, gopt_env%gopt_dimer_param, force_env=force_env, &
159 globenv=globenv, geo_opt_section=rot_opt_section, eval_opt_geo=eval_opt_geo)
160 CALL dimer_env_retain(gopt_env%dimer_env)
161 gopt_env%gopt_dimer_env%dimer_env => gopt_env%dimer_env
162 gopt_env%gopt_dimer_env%label = "ROT_OPT"
163 gopt_env%gopt_dimer_env%dimer_rotation = .true.
164 END SELECT
165 END SELECT
167 gopt_env%nfree = 6
168 gopt_env%label = "CELL_OPT"
169 gopt_env%tag = " CELL "
170 ALLOCATE (gopt_env%cell_env)
171 CALL cell_opt_env_create(gopt_env%cell_env, force_env, gopt_env%geo_section)
173 gopt_env%nfree = subsys%shell_particles%n_els
174 gopt_env%label = "SHELL_OPT"
175 gopt_env%tag = " SHELL-CORE "
176 gopt_env%shellcore_method_id = gopt_param%shellcore_method_id
177 END SELECT
178 END SUBROUTINE gopt_f_create
179
180! **************************************************************************************************
181!> \brief ...
182!> \param gopt_env the geometry optimization environment to retain
183!> \par History
184!> none
185! **************************************************************************************************
186 SUBROUTINE gopt_f_retain(gopt_env)
187 TYPE(gopt_f_type), POINTER :: gopt_env
188
189 cpassert(ASSOCIATED(gopt_env))
190 cpassert(gopt_env%ref_count > 0)
191 gopt_env%ref_count = gopt_env%ref_count + 1
192 END SUBROUTINE gopt_f_retain
193
194! **************************************************************************************************
195!> \brief ...
196!> \param gopt_env the geometry optimization environment to release
197!> \par History
198!> none
199! **************************************************************************************************
200 RECURSIVE SUBROUTINE gopt_f_release(gopt_env)
201 TYPE(gopt_f_type), POINTER :: gopt_env
202
203 IF (ASSOCIATED(gopt_env)) THEN
204 cpassert(gopt_env%ref_count > 0)
205 gopt_env%ref_count = gopt_env%ref_count - 1
206 IF (gopt_env%ref_count == 0) THEN
207 CALL force_env_release(gopt_env%force_env)
208 NULLIFY (gopt_env%force_env, &
209 gopt_env%globenv, &
210 gopt_env%motion_section, &
211 gopt_env%geo_section)
212 IF (ASSOCIATED(gopt_env%cell_env)) THEN
213 CALL cell_opt_env_release(gopt_env%cell_env)
214 DEALLOCATE (gopt_env%cell_env)
215 END IF
216 CALL dimer_env_release(gopt_env%dimer_env)
217 CALL gopt_f_release(gopt_env%gopt_dimer_env)
218 IF (ASSOCIATED(gopt_env%gopt_dimer_param)) DEALLOCATE (gopt_env%gopt_dimer_param)
219 CALL release_spgr_type(gopt_env%spgr)
220 DEALLOCATE (gopt_env)
221 END IF
222 END IF
223 END SUBROUTINE gopt_f_release
224
225END 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.
integer function, public force_env_get_natom(force_env)
returns the number of atoms
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