Loading [MathJax]/extensions/tex2jax.js
 (git:aabdcc8)
All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros
cp_subsys_methods.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Initialize a small environment for a particular calculation
10!> \par History
11!> 5.2004 created [fawzi]
12!> 9.2007 cleaned [tlaino] - University of Zurich
13!> \author Teodoro Laino
14! **************************************************************************************************
21 USE cell_types, ONLY: cell_retain,&
29 USE input_constants, ONLY: do_conn_off,&
39 USE kinds, ONLY: default_string_length,&
40 dp
55 USE string_table, ONLY: id2str,&
56 s2s,&
57 str2id
66 USE virial_types, ONLY: virial_set
67#include "./base/base_uses.f90"
68
69 IMPLICIT NONE
70 PRIVATE
71
72 LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
73 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_subsys_methods'
74
76
77CONTAINS
78
79! **************************************************************************************************
80!> \brief Creates allocates and fills subsys from given input.
81!> \param subsys ...
82!> \param para_env ...
83!> \param root_section ...
84!> \param force_env_section ...
85!> \param subsys_section ...
86!> \param use_motion_section ...
87!> \param qmmm ...
88!> \param qmmm_env ...
89!> \param exclusions ...
90!> \param elkind ...
91!> \author Ole Schuett
92! **************************************************************************************************
93 SUBROUTINE cp_subsys_create(subsys, para_env, &
94 root_section, force_env_section, subsys_section, &
95 use_motion_section, qmmm, qmmm_env, exclusions, elkind)
96 TYPE(cp_subsys_type), POINTER :: subsys
97 TYPE(mp_para_env_type), POINTER :: para_env
98 TYPE(section_vals_type), POINTER :: root_section
99 TYPE(section_vals_type), OPTIONAL, POINTER :: force_env_section, subsys_section
100 LOGICAL, INTENT(IN), OPTIONAL :: use_motion_section
101 LOGICAL, OPTIONAL :: qmmm
102 TYPE(qmmm_env_mm_type), OPTIONAL, POINTER :: qmmm_env
103 TYPE(exclusion_type), DIMENSION(:), OPTIONAL, &
104 POINTER :: exclusions
105 LOGICAL, INTENT(IN), OPTIONAL :: elkind
106
107 INTEGER :: stress_tensor
108 INTEGER, DIMENSION(:), POINTER :: seed_vals
109 LOGICAL :: atomic_energy, my_use_motion_section, &
110 pv_availability, pv_diagonal, &
111 pv_numerical
112 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
113 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
114 TYPE(molecule_kind_list_type), POINTER :: mol_kinds
115 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
116 TYPE(molecule_list_type), POINTER :: mols
117 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
118 TYPE(particle_list_type), POINTER :: particles
119 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
120 TYPE(section_vals_type), POINTER :: colvar_section, my_force_env_section, &
121 my_subsys_section
122
123 cpassert(.NOT. ASSOCIATED(subsys))
124 ALLOCATE (subsys)
125
126 CALL para_env%retain()
127 subsys%para_env => para_env
128
129 my_use_motion_section = .false.
130 IF (PRESENT(use_motion_section)) &
131 my_use_motion_section = use_motion_section
132
133 my_force_env_section => section_vals_get_subs_vals(root_section, "FORCE_EVAL")
134 IF (PRESENT(force_env_section)) &
135 my_force_env_section => force_env_section
136
137 my_subsys_section => section_vals_get_subs_vals(my_force_env_section, "SUBSYS")
138 IF (PRESENT(subsys_section)) &
139 my_subsys_section => subsys_section
140
141 CALL section_vals_val_get(my_subsys_section, "SEED", i_vals=seed_vals)
142 IF (SIZE(seed_vals) == 1) THEN
143 subsys%seed(:, :) = real(seed_vals(1), kind=dp)
144 ELSE IF (SIZE(seed_vals) == 6) THEN
145 subsys%seed(1:3, 1:2) = reshape(real(seed_vals(:), kind=dp), (/3, 2/))
146 ELSE
147 cpabort("Supply exactly 1 or 6 arguments for SEED in &SUBSYS only!")
148 END IF
149
150 colvar_section => section_vals_get_subs_vals(my_subsys_section, "COLVAR")
151
152 CALL cp_subsys_read_colvar(subsys, colvar_section)
153
154 ! *** Read the particle coordinates and allocate the atomic kind, ***
155 ! *** the molecule kind, and the molecule data structures ***
156 CALL topology_control(atomic_kind_set, particle_set, molecule_kind_set, molecule_set, &
157 subsys%colvar_p, subsys%gci, root_section, para_env, &
158 force_env_section=my_force_env_section, &
159 subsys_section=my_subsys_section, use_motion_section=my_use_motion_section, &
160 qmmm=qmmm, qmmm_env=qmmm_env, exclusions=exclusions, elkind=elkind)
161
162 CALL particle_list_create(particles, els_ptr=particle_set)
163 CALL atomic_kind_list_create(atomic_kinds, els_ptr=atomic_kind_set)
164 CALL molecule_list_create(mols, els_ptr=molecule_set)
165 CALL molecule_kind_list_create(mol_kinds, els_ptr=molecule_kind_set)
166
167 CALL cp_subsys_set(subsys, particles=particles, atomic_kinds=atomic_kinds, &
168 molecules=mols, molecule_kinds=mol_kinds)
169
170 CALL particle_list_release(particles)
171 CALL atomic_kind_list_release(atomic_kinds)
172 CALL molecule_list_release(mols)
173 CALL molecule_kind_list_release(mol_kinds)
174
175 ! Should we compute the virial?
176 CALL section_vals_val_get(my_force_env_section, "STRESS_TENSOR", i_val=stress_tensor)
177 SELECT CASE (stress_tensor)
178 CASE (do_stress_none)
179 pv_availability = .false.
180 pv_numerical = .false.
181 pv_diagonal = .false.
183 pv_availability = .true.
184 pv_numerical = .false.
185 pv_diagonal = .false.
187 pv_availability = .true.
188 pv_numerical = .true.
189 pv_diagonal = .false.
191 pv_availability = .true.
192 pv_numerical = .false.
193 pv_diagonal = .true.
195 pv_availability = .true.
196 pv_numerical = .true.
197 pv_diagonal = .true.
198 END SELECT
199
200 ALLOCATE (subsys%virial)
201 CALL virial_set(virial=subsys%virial, &
202 pv_availability=pv_availability, &
203 pv_numer=pv_numerical, &
204 pv_diagonal=pv_diagonal)
205
206 ! Should we compute atomic properties?
207 CALL atprop_create(subsys%atprop)
208 CALL section_vals_val_get(my_force_env_section, "PROPERTIES%ATOMIC%ENERGY", l_val=atomic_energy)
209 subsys%atprop%energy = atomic_energy
210
211 CALL cp_result_create(subsys%results)
212 END SUBROUTINE cp_subsys_create
213
214! **************************************************************************************************
215!> \brief reads the colvar section of the colvar
216!> \param subsys ...
217!> \param colvar_section ...
218!> \par History
219!> 2006.01 Joost VandeVondele
220! **************************************************************************************************
221 SUBROUTINE cp_subsys_read_colvar(subsys, colvar_section)
222 TYPE(cp_subsys_type), POINTER :: subsys
223 TYPE(section_vals_type), POINTER :: colvar_section
224
225 INTEGER :: ig, ncol
226
227 CALL section_vals_get(colvar_section, n_repetition=ncol)
228 ALLOCATE (subsys%colvar_p(ncol))
229 DO ig = 1, ncol
230 NULLIFY (subsys%colvar_p(ig)%colvar)
231 CALL colvar_read(subsys%colvar_p(ig)%colvar, ig, colvar_section, subsys%para_env)
232 END DO
233 END SUBROUTINE cp_subsys_read_colvar
234
235! **************************************************************************************************
236!> \brief updates the molecule information of the given subsys
237!> \param small_subsys the subsys to create
238!> \param big_subsys the superset of small_subsys
239!> \param small_cell ...
240!> \param small_para_env the parallel environment for the new (small)
241!> subsys
242!> \param sub_atom_index indexes of the atoms that should be in small_subsys
243!> \param sub_atom_kind_name ...
244!> \param para_env ...
245!> \param force_env_section ...
246!> \param subsys_section ...
247!> \param ignore_outside_box ...
248!> \par History
249!> 05.2004 created [fawzi]
250!> \author Fawzi Mohamed, Teodoro Laino
251!> \note
252!> not really ready to be used with different para_envs for the small
253!> and big part
254! **************************************************************************************************
255 SUBROUTINE create_small_subsys(small_subsys, big_subsys, small_cell, &
256 small_para_env, sub_atom_index, sub_atom_kind_name, &
257 para_env, force_env_section, subsys_section, ignore_outside_box)
258
259 TYPE(cp_subsys_type), POINTER :: small_subsys, big_subsys
260 TYPE(cell_type), POINTER :: small_cell
261 TYPE(mp_para_env_type), POINTER :: small_para_env
262 INTEGER, DIMENSION(:), INTENT(in) :: sub_atom_index
263 CHARACTER(len=default_string_length), &
264 DIMENSION(:), INTENT(in) :: sub_atom_kind_name
265 TYPE(mp_para_env_type), POINTER :: para_env
266 TYPE(section_vals_type), POINTER :: force_env_section, subsys_section
267 LOGICAL, INTENT(in), OPTIONAL :: ignore_outside_box
268
269 CHARACTER(len=default_string_length) :: my_element, strtmp1
270 INTEGER :: iat, id_, nat
271 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
272 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
273 TYPE(molecule_kind_list_type), POINTER :: mol_kinds
274 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
275 TYPE(molecule_list_type), POINTER :: mols
276 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
277 TYPE(particle_list_type), POINTER :: particles
278 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
280
281 NULLIFY (mol_kinds, mols, particles, atomic_kinds, atomic_kind_set, particle_set, &
282 molecule_kind_set, molecule_set, particles, atomic_kinds)
283
284 cpassert(.NOT. ASSOCIATED(small_subsys))
285 cpassert(ASSOCIATED(big_subsys))
286 IF (big_subsys%para_env /= small_para_env) &
287 cpabort("big_subsys%para_env==small_para_env")
288
289 !-----------------------------------------------------------------------------
290 !-----------------------------------------------------------------------------
291 ! 1. Initialize the topology structure type
292 !-----------------------------------------------------------------------------
294
295 !-----------------------------------------------------------------------------
296 !-----------------------------------------------------------------------------
297 ! 2. Get the cell info
298 !-----------------------------------------------------------------------------
299 topology%cell => small_cell
300 CALL cell_retain(small_cell)
301
302 !-----------------------------------------------------------------------------
303 !-----------------------------------------------------------------------------
304 ! 3. Initialize atom coords from the bigger system
305 !-----------------------------------------------------------------------------
306 nat = SIZE(sub_atom_index)
307 topology%natoms = nat
308 cpassert(.NOT. ASSOCIATED(topology%atom_info%r))
309 cpassert(.NOT. ASSOCIATED(topology%atom_info%id_atmname))
310 cpassert(.NOT. ASSOCIATED(topology%atom_info%id_molname))
311 cpassert(.NOT. ASSOCIATED(topology%atom_info%id_resname))
312 cpassert(.NOT. ASSOCIATED(topology%atom_info%atm_mass))
313 cpassert(.NOT. ASSOCIATED(topology%atom_info%atm_charge))
314 ALLOCATE (topology%atom_info%r(3, nat), topology%atom_info%id_atmname(nat), &
315 topology%atom_info%id_molname(nat), topology%atom_info%id_resname(nat), &
316 topology%atom_info%id_element(nat), topology%atom_info%atm_mass(nat), &
317 topology%atom_info%atm_charge(nat))
318
319 CALL cp_subsys_get(big_subsys, particles=particles)
320 DO iat = 1, nat
321 topology%atom_info%r(:, iat) = particles%els(sub_atom_index(iat))%r
322 topology%atom_info%id_atmname(iat) = str2id(s2s(sub_atom_kind_name(iat)))
323 topology%atom_info%id_molname(iat) = topology%atom_info%id_atmname(iat)
324 topology%atom_info%id_resname(iat) = topology%atom_info%id_atmname(iat)
325 !
326 ! Defining element
327 !
328 id_ = index(id2str(topology%atom_info%id_atmname(iat)), "_") - 1
329 IF (id_ == -1) id_ = len_trim(id2str(topology%atom_info%id_atmname(iat)))
330 strtmp1 = id2str(topology%atom_info%id_atmname(iat))
331 strtmp1 = strtmp1(1:id_)
332 CALL check_subsys_element(strtmp1, strtmp1, my_element, &
333 subsys_section, use_mm_map_first=.false.)
334 topology%atom_info%id_element(iat) = str2id(s2s(my_element))
335 topology%atom_info%atm_mass(iat) = 0._dp
336 topology%atom_info%atm_charge(iat) = 0._dp
337 END DO
338 topology%conn_type = do_conn_off
339
340 !-----------------------------------------------------------------------------
341 !-----------------------------------------------------------------------------
342 ! 4. Read in or generate the molecular connectivity
343 !-----------------------------------------------------------------------------
344 CALL connectivity_control(topology, para_env, subsys_section=subsys_section, &
345 force_env_section=force_env_section)
346
347 !-----------------------------------------------------------------------------
348 !-----------------------------------------------------------------------------
349 ! 5. Pack everything into the molecular types
350 !-----------------------------------------------------------------------------
351 CALL topology_connectivity_pack(molecule_kind_set, molecule_set, &
352 topology, subsys_section=subsys_section)
353
354 !-----------------------------------------------------------------------------
355 !-----------------------------------------------------------------------------
356 ! 6. Pack everything into the atomic types
357 !-----------------------------------------------------------------------------
358 CALL topology_coordinate_pack(particle_set, atomic_kind_set, &
359 molecule_kind_set, molecule_set, topology, subsys_section=subsys_section, &
360 force_env_section=force_env_section, ignore_outside_box=ignore_outside_box)
361
362 !-----------------------------------------------------------------------------
363 !-----------------------------------------------------------------------------
364 ! 7. Cleanup the topology structure type
365 !-----------------------------------------------------------------------------
367
368 !-----------------------------------------------------------------------------
369 !-----------------------------------------------------------------------------
370 ! 8. Allocate new subsys
371 !-----------------------------------------------------------------------------
372 ALLOCATE (small_subsys)
373 CALL para_env%retain()
374 small_subsys%para_env => para_env
375 CALL particle_list_create(particles, els_ptr=particle_set)
376 CALL atomic_kind_list_create(atomic_kinds, els_ptr=atomic_kind_set)
377 CALL molecule_list_create(mols, els_ptr=molecule_set)
378 CALL molecule_kind_list_create(mol_kinds, els_ptr=molecule_kind_set)
379 CALL cp_subsys_set(small_subsys, particles=particles, atomic_kinds=atomic_kinds, &
380 molecules=mols, molecule_kinds=mol_kinds)
381 CALL particle_list_release(particles)
382 CALL atomic_kind_list_release(atomic_kinds)
383 CALL molecule_list_release(mols)
384 CALL molecule_kind_list_release(mol_kinds)
385
386 ALLOCATE (small_subsys%virial)
387 CALL atprop_create(small_subsys%atprop)
388 CALL cp_result_create(small_subsys%results)
389 END SUBROUTINE create_small_subsys
390
391END MODULE cp_subsys_methods
represent a simple array based list of the given type
subroutine, public atomic_kind_list_release(list)
releases a list (see doc/ReferenceCounting.html)
subroutine, public atomic_kind_list_create(list, els_ptr, owns_els, n_els)
creates a list
Define the atomic kind types and their sub types.
Holds information on atomic properties.
subroutine, public atprop_create(atprop_env)
...
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public cell_retain(cell)
retains the given cell (see doc/ReferenceCounting.html)
Definition cell_types.F:542
defines collective variables s({R}) and the derivative of this variable wrt R these can then be used ...
recursive subroutine, public colvar_read(colvar, icol, colvar_section, para_env)
reads a colvar from the input
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_result_create(results)
Allocates and intitializes the cp_result.
Initialize a small environment for a particular calculation.
subroutine, public create_small_subsys(small_subsys, big_subsys, small_cell, small_para_env, sub_atom_index, sub_atom_kind_name, para_env, force_env_section, subsys_section, ignore_outside_box)
updates the molecule information of the given subsys
subroutine, public cp_subsys_create(subsys, para_env, root_section, force_env_section, subsys_section, use_motion_section, qmmm, qmmm_env, exclusions, elkind)
Creates allocates and fills subsys from given input.
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_set(subsys, atomic_kinds, particles, local_particles, molecules, molecule_kinds, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, results, cell)
sets various propreties of the subsys
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
an exclusion type
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public do_stress_analytical
integer, parameter, public do_conn_off
integer, parameter, public do_stress_diagonal_anal
integer, parameter, public do_stress_diagonal_numer
integer, parameter, public do_stress_none
integer, parameter, public do_stress_numerical
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
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
Interface to the message passing library MPI.
represent a simple array based list of the given type
subroutine, public molecule_kind_list_create(list, els_ptr, owns_els, n_els)
creates a list
subroutine, public molecule_kind_list_release(list)
releases a list (see doc/ReferenceCounting.html)
Define the molecule kind structure types and the corresponding functionality.
represent a simple array based list of the given type
subroutine, public molecule_list_create(list, els_ptr, owns_els, n_els)
creates a list
subroutine, public molecule_list_release(list)
releases a list (see doc/ReferenceCounting.html)
Define the data structure for the molecule information.
represent a simple array based list of the given type
subroutine, public particle_list_create(list, els_ptr, owns_els, n_els)
creates a list
subroutine, public particle_list_release(list)
releases a list (see doc/ReferenceCounting.html)
Define the data structure for the particle information.
generates a unique id number for a string (str2id) that can be used two compare two strings....
character(len=default_string_length) function, public s2s(str)
converts a string in a string of default_string_length
integer function, public str2id(str)
returns a unique id for a given string, and stores the string for later retrieval using the id.
character(len=default_string_length) function, public id2str(id)
returns the string associated with a given id
Collection of subroutine needed for topology related things.
subroutine, public topology_connectivity_pack(molecule_kind_set, molecule_set, topology, subsys_section)
topology connectivity pack
Collection of subroutine needed for topology related things.
subroutine, public topology_coordinate_pack(particle_set, atomic_kind_set, molecule_kind_set, molecule_set, topology, qmmm, qmmm_env, subsys_section, force_env_section, exclusions, ignore_outside_box)
Take info readin from different file format and stuff it into compatible data structure in cp2k.
subroutine, public deallocate_topology(topology)
Just DEALLOCATE all the stuff
subroutine, public init_topology(topology)
Just NULLIFY and zero all the stuff
Collection of subroutine needed for topology related things.
subroutine, public check_subsys_element(element_in, atom_name_in, element_out, subsys_section, use_mm_map_first)
Check and returns the ELEMENT label.
Control for reading in different topologies and coordinates.
Definition topology.F:13
subroutine, public topology_control(atomic_kind_set, particle_set, molecule_kind_set, molecule_set, colvar_p, gci, root_section, para_env, qmmm, qmmm_env, force_env_section, subsys_section, use_motion_section, exclusions, elkind)
...
Definition topology.F:125
subroutine, public connectivity_control(topology, para_env, qmmm, qmmm_env, subsys_section, force_env_section)
If reading in from external file, make sure its there first
Definition topology.F:285
subroutine, public virial_set(virial, pv_total, pv_kinetic, pv_virial, pv_xc, pv_fock_4c, pv_constraint, pv_overlap, pv_ekinetic, pv_ppl, pv_ppnl, pv_ecore_overlap, pv_ehartree, pv_exc, pv_exx, pv_vdw, pv_mp2, pv_nlcc, pv_gapw, pv_lrigpw, pv_availability, pv_calculate, pv_numer, pv_diagonal)
...
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
represents a system: atoms, molecules, their pos,vel,...
A type used to store lists of exclusions and onfos.
stores all the informations relevant to an mpi environment