(git:58e3e09)
shell_opt.F
Go to the documentation of this file.
1 !--------------------------------------------------------------------------------------------------!
2 ! CP2K: A general program to perform molecular dynamics simulations !
3 ! Copyright 2000-2024 CP2K developers group <https://cp2k.org> !
4 ! !
5 ! SPDX-License-Identifier: GPL-2.0-or-later !
6 !--------------------------------------------------------------------------------------------------!
7 
8 ! **************************************************************************************************
9 !> \brief
10 !> \author
11 ! **************************************************************************************************
12 MODULE shell_opt
13 
14  USE atomic_kind_list_types, ONLY: atomic_kind_list_type
15  USE atomic_kind_types, ONLY: atomic_kind_type,&
17  USE cg_optimizer, ONLY: geoopt_cg
19  cp_logger_type
22  USE cp_subsys_types, ONLY: cp_subsys_get,&
23  cp_subsys_type
24  USE distribution_1d_types, ONLY: distribution_1d_type
25  USE force_env_types, ONLY: force_env_get,&
26  force_env_type
27  USE global_types, ONLY: global_environment_type
28  USE gopt_f_types, ONLY: gopt_f_create,&
30  gopt_f_type
32  gopt_param_type
36  section_vals_type
37  USE integrator_utils, ONLY: tmp_variables_type
38  USE kinds, ONLY: dp
39  USE message_passing, ONLY: mp_para_env_type
40  USE particle_types, ONLY: particle_type
41  USE shell_potential_types, ONLY: shell_kind_type
42 #include "../base/base_uses.f90"
43 
44  IMPLICIT NONE
45  PRIVATE
46  PUBLIC :: optimize_shell_core
47  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'shell_opt'
48 
49 CONTAINS
50 
51 ! **************************************************************************************************
52 !> \brief Optimize shell-core positions along an MD run
53 !> \param force_env ...
54 !> \param particle_set ...
55 !> \param shell_particle_set ...
56 !> \param core_particle_set ...
57 !> \param globenv ...
58 !> \param tmp ...
59 !> \param check ...
60 !> \author
61 ! **************************************************************************************************
62 
63  SUBROUTINE optimize_shell_core(force_env, particle_set, shell_particle_set, core_particle_set, globenv, tmp, check)
64  TYPE(force_env_type), POINTER :: force_env
65  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set, shell_particle_set, &
66  core_particle_set
67  TYPE(global_environment_type), POINTER :: globenv
68  TYPE(tmp_variables_type), OPTIONAL, POINTER :: tmp
69  LOGICAL, INTENT(IN), OPTIONAL :: check
70 
71  CHARACTER(len=*), PARAMETER :: routinen = 'optimize_shell_core'
72 
73  INTEGER :: handle, i, iat, nshell
74  LOGICAL :: do_update, explicit, my_check, optimize
75  REAL(dp), DIMENSION(:), POINTER :: dvec_sc, dvec_sc_0
76  TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
77  TYPE(cp_logger_type), POINTER :: logger
78  TYPE(cp_subsys_type), POINTER :: subsys
79  TYPE(distribution_1d_type), POINTER :: local_particles
80  TYPE(gopt_f_type), POINTER :: gopt_env
81  TYPE(gopt_param_type), POINTER :: gopt_param
82  TYPE(mp_para_env_type), POINTER :: para_env
83  TYPE(section_vals_type), POINTER :: force_env_section, geo_section, &
84  root_section
85 
86  NULLIFY (logger)
87  logger => cp_get_default_logger()
88 
89  cpassert(ASSOCIATED(force_env))
90  cpassert(ASSOCIATED(globenv))
91 
92  NULLIFY (gopt_param, force_env_section, gopt_env, dvec_sc, dvec_sc_0, root_section, geo_section)
93  root_section => force_env%root_section
94  force_env_section => force_env%force_env_section
95  geo_section => section_vals_get_subs_vals(root_section, "MOTION%SHELL_OPT")
96 
97  CALL section_vals_get(geo_section, explicit=explicit)
98  IF (.NOT. explicit) RETURN
99 
100  CALL timeset(routinen, handle)
101 
102  optimize = .false.
103  my_check = .false.
104  IF (PRESENT(check)) my_check = check
105  IF (my_check) THEN
106  NULLIFY (subsys, para_env, atomic_kinds, local_particles)
107  CALL force_env_get(force_env=force_env, subsys=subsys, para_env=para_env)
108  CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles)
109  CALL check_shell_core_distance(atomic_kinds, local_particles, particle_set, shell_particle_set, &
110  core_particle_set, para_env, optimize)
111 
112  IF (.NOT. optimize) THEN
113  CALL timestop(handle)
114  RETURN
115  END IF
116  END IF
117 
118  nshell = SIZE(shell_particle_set)
119  ALLOCATE (dvec_sc(3*nshell))
120  ALLOCATE (dvec_sc_0(3*nshell))
121  DO i = 1, nshell
122  dvec_sc(1 + 3*(i - 1)) = core_particle_set(i)%r(1) - shell_particle_set(i)%r(1)
123  dvec_sc(2 + 3*(i - 1)) = core_particle_set(i)%r(2) - shell_particle_set(i)%r(2)
124  dvec_sc(3 + 3*(i - 1)) = core_particle_set(i)%r(3) - shell_particle_set(i)%r(3)
125  END DO
126  dvec_sc_0 = dvec_sc
127 
128  ALLOCATE (gopt_param)
129  CALL gopt_param_read(gopt_param, geo_section, type_id=default_shellcore_method_id)
130  CALL gopt_f_create(gopt_env, gopt_param, force_env=force_env, globenv=globenv, &
131  geo_opt_section=geo_section)
132 
133  CALL cp_add_iter_level(logger%iter_info, "SHELL_OPT")
134  gopt_env%eval_opt_geo = .false.
135  CALL geoopt_cg(force_env, gopt_param, globenv, &
136  geo_section, gopt_env, dvec_sc, do_update=do_update)
137  IF (.NOT. do_update) THEN
138  DO i = 1, nshell
139  shell_particle_set(i)%r(1) = -dvec_sc_0(1 + 3*(i - 1)) + core_particle_set(i)%r(1)
140  shell_particle_set(i)%r(2) = -dvec_sc_0(2 + 3*(i - 1)) + core_particle_set(i)%r(2)
141  shell_particle_set(i)%r(3) = -dvec_sc_0(3 + 3*(i - 1)) + core_particle_set(i)%r(3)
142  END DO
143  END IF
144  CALL cp_rm_iter_level(logger%iter_info, "SHELL_OPT")
145 
146  CALL gopt_f_release(gopt_env)
147  DEALLOCATE (gopt_param)
148  DEALLOCATE (dvec_sc)
149  DEALLOCATE (dvec_sc_0)
150 
151  IF (PRESENT(tmp)) THEN
152  DO i = 1, nshell
153  iat = shell_particle_set(i)%atom_index
154  tmp%shell_vel(1:3, i) = tmp%vel(1:3, iat)
155  tmp%core_vel(1:3, i) = tmp%vel(1:3, iat)
156  END DO
157  ELSE
158  DO i = 1, nshell
159  iat = shell_particle_set(i)%atom_index
160  shell_particle_set(i)%v(1:3) = particle_set(iat)%v(1:3)
161  core_particle_set(i)%v(1:3) = particle_set(iat)%v(1:3)
162  END DO
163  END IF
164 
165  CALL timestop(handle)
166 
167  END SUBROUTINE optimize_shell_core
168 
169 ! **************************************************************************************************
170 !> \brief Check shell_core_distance
171 !> \param atomic_kinds ...
172 !> \param local_particles ...
173 !> \param particle_set ...
174 !> \param shell_particle_set ...
175 !> \param core_particle_set ...
176 !> \param para_env ...
177 !> \param optimize ...
178 !> \par History
179 !> none
180 !> \author MI (October 2008)
181 !> I soliti ignoti
182 ! **************************************************************************************************
183  SUBROUTINE check_shell_core_distance(atomic_kinds, local_particles, particle_set, &
184  shell_particle_set, core_particle_set, para_env, optimize)
185 
186  TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
187  TYPE(distribution_1d_type), POINTER :: local_particles
188  TYPE(particle_type), DIMENSION(:), POINTER :: particle_set, shell_particle_set, &
189  core_particle_set
190  TYPE(mp_para_env_type), POINTER :: para_env
191  LOGICAL, INTENT(INOUT) :: optimize
192 
193  INTEGER :: ikind, iparticle, iparticle_local, &
194  itest, nkind, nparticle_local, &
195  shell_index
196  LOGICAL :: is_shell
197  REAL(dp) :: dsc, rc(3), rs(3)
198  TYPE(atomic_kind_type), POINTER :: atomic_kind
199  TYPE(shell_kind_type), POINTER :: shell
200 
201  nkind = atomic_kinds%n_els
202  itest = 0
203  DO ikind = 1, nkind
204  NULLIFY (atomic_kind)
205  atomic_kind => atomic_kinds%els(ikind)
206  CALL get_atomic_kind(atomic_kind=atomic_kind, shell_active=is_shell, shell=shell)
207  IF (is_shell) THEN
208  IF (shell%max_dist > 0.0_dp) THEN
209  nparticle_local = local_particles%n_el(ikind)
210  DO iparticle_local = 1, nparticle_local
211  iparticle = local_particles%list(ikind)%array(iparticle_local)
212  shell_index = particle_set(iparticle)%shell_index
213 
214  rc(:) = core_particle_set(shell_index)%r(:)
215  rs(:) = shell_particle_set(shell_index)%r(:)
216  dsc = sqrt((rc(1) - rs(1))**2 + (rc(2) - rs(2))**2 + (rc(3) - rs(3))**2)
217  IF (dsc > shell%max_dist) THEN
218  itest = 1
219  END IF
220  END DO
221  END IF
222  END IF
223  END DO
224 
225  CALL para_env%sum(itest)
226  IF (itest > 0) optimize = .true.
227 
228  END SUBROUTINE check_shell_core_distance
229 END MODULE shell_opt
represent a simple array based list of the given type
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Routines for Geometry optimization using Conjugate Gradients.
Definition: cg_optimizer.F:13
recursive subroutine, public geoopt_cg(force_env, gopt_param, globenv, geo_section, gopt_env, x0, do_update)
Driver for conjugate gradient optimization technique.
Definition: cg_optimizer.F:113
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_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.
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)
returns information about various attributes of the given subsys
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
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)
returns various attributes about the force environment
Define type storing the global information of a run. Keep the amount of stored data small....
Definition: global_types.F:21
contains a functional that calculates the energy and its derivatives for the geometry optimizer
Definition: gopt_f_types.F:15
recursive subroutine, public gopt_f_create(gopt_env, gopt_param, force_env, globenv, geo_opt_section, eval_opt_geo)
...
Definition: gopt_f_types.F:95
recursive subroutine, public gopt_f_release(gopt_env)
...
Definition: gopt_f_types.F:200
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
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_get(section_vals, ref_count, n_repetition, n_subs_vals_rep, section, explicit)
returns various attributes about the section_vals
Provides integrator utility routines for the integrators.
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Interface to the message passing library MPI.
Define the data structure for the particle information.
subroutine, public optimize_shell_core(force_env, particle_set, shell_particle_set, core_particle_set, globenv, tmp, check)
Optimize shell-core positions along an MD run.
Definition: shell_opt.F:64