(git:ccc2433)
cp_subsys_types.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 types that represent a subsys, i.e. a part of the system
10 !> \par History
11 !> 07.2003 created [fawzi]
12 !> 09.2007 cleaned [tlaino] - University of Zurich
13 !> 22.11.2010 pack/unpack particle routines added (MK)
14 !> \author Fawzi Mohamed
15 ! **************************************************************************************************
19  atomic_kind_list_type
20  USE atomic_kind_types, ONLY: atomic_kind_type
21  USE atprop_types, ONLY: atprop_release,&
22  atprop_type
23  USE cell_types, ONLY: cell_release,&
24  cell_retain,&
25  cell_type,&
28  USE colvar_types, ONLY: colvar_p_release,&
29  colvar_p_type
32  cp_result_type
35  distribution_1d_type
36  USE kinds, ONLY: dp
38  mp_para_env_type
41  molecule_kind_list_type
42  USE molecule_kind_types, ONLY: molecule_kind_type
45  molecule_list_type
47  global_constraint_type,&
48  molecule_type
49  USE multipole_types, ONLY: multipole_type,&
53  particle_list_type
54  USE particle_types, ONLY: particle_type
55  USE virial_types, ONLY: virial_type
56 #include "../base/base_uses.f90"
57 
58  IMPLICIT NONE
59  PRIVATE
60 
61  CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'cp_subsys_types'
62  LOGICAL, PRIVATE, PARAMETER :: debug_this_module = .false.
63 
64  PUBLIC :: cp_subsys_type, &
65  cp_subsys_p_type
66 
67  PUBLIC :: cp_subsys_retain, &
69  cp_subsys_get, &
70  cp_subsys_set, &
73 
74 ! **************************************************************************************************
75 !> \brief represents a system: atoms, molecules, their pos,vel,...
76 !> \param atomic_kinds list with all the kinds in the actual subsys
77 !> \param particles list with the particles of the actual subsys
78 !> \param local_particles the particles that are local to the actual processor
79 !> \param molecule_kinds list with the molecule kinds
80 !> \param local_molecules the molecule structures of the actual subsys
81 !> that are local to this processor
82 !> \param para_env the parallel environment of the actual subsys
83 !> \param shell_particles list with the shells of the actual subsys if shell-model is used
84 !> \param core_particles list with the shells of the actual subsys if shell-model is used
85 !> \par History
86 !> 07.2003 created [fawzi]
87 !> \author Fawzi Mohamed
88 ! **************************************************************************************************
89  TYPE cp_subsys_type
90  INTEGER :: ref_count = 1
91  REAL(KIND=dp), DIMENSION(3, 2) :: seed = -1
92  TYPE(atomic_kind_list_type), POINTER :: atomic_kinds => null()
93  TYPE(particle_list_type), POINTER :: particles => null()
94  TYPE(particle_list_type), POINTER :: shell_particles => null()
95  TYPE(particle_list_type), POINTER :: core_particles => null()
96  TYPE(distribution_1d_type), POINTER :: local_particles => null()
97  TYPE(mp_para_env_type), POINTER :: para_env => null()
98  ! molecules kinds
99  TYPE(molecule_list_type), POINTER :: molecules => null()
100  TYPE(molecule_kind_list_type), POINTER :: molecule_kinds => null()
101  TYPE(distribution_1d_type), POINTER :: local_molecules => null()
102  ! Definitions of the collective variables
103  TYPE(colvar_p_type), DIMENSION(:), POINTER :: colvar_p => null()
104  ! Intermolecular constraints
105  TYPE(global_constraint_type), POINTER :: gci => null()
106  ! Multipoles
107  TYPE(multipole_type), POINTER :: multipoles => null()
108  TYPE(atprop_type), POINTER :: atprop => null()
109  TYPE(virial_type), POINTER :: virial => null()
110  TYPE(cp_result_type), POINTER :: results => null()
111  TYPE(cell_type), POINTER :: cell => null()
112  END TYPE cp_subsys_type
113 
114 ! **************************************************************************************************
115 !> \brief represent a pointer to a subsys, to be able to create arrays
116 !> of pointers
117 !> \param subsys the pointer to the subsys
118 !> \par History
119 !> 07.2003 created [fawzi]
120 !> \author Fawzi Mohamed
121 ! **************************************************************************************************
122  TYPE cp_subsys_p_type
123  TYPE(cp_subsys_type), POINTER :: subsys => null()
124  END TYPE cp_subsys_p_type
125 
126 CONTAINS
127 
128 ! **************************************************************************************************
129 !> \brief retains a subsys (see doc/ReferenceCounting.html)
130 !> \param subsys the subsys to retain
131 !> \par History
132 !> 07.2003 created [fawzi]
133 !> \author Fawzi Mohamed
134 ! **************************************************************************************************
135  SUBROUTINE cp_subsys_retain(subsys)
136  TYPE(cp_subsys_type), INTENT(INOUT) :: subsys
137 
138  cpassert(subsys%ref_count > 0)
139  subsys%ref_count = subsys%ref_count + 1
140  END SUBROUTINE cp_subsys_retain
141 
142 ! **************************************************************************************************
143 !> \brief releases a subsys (see doc/ReferenceCounting.html)
144 !> \param subsys the subsys to release
145 !> \par History
146 !> 07.2003 created [fawzi]
147 !> \author Fawzi Mohamed
148 ! **************************************************************************************************
149  SUBROUTINE cp_subsys_release(subsys)
150  TYPE(cp_subsys_type), POINTER :: subsys
151 
152  IF (ASSOCIATED(subsys)) THEN
153  cpassert(subsys%ref_count > 0)
154  subsys%ref_count = subsys%ref_count - 1
155  IF (subsys%ref_count == 0) THEN
156  CALL atomic_kind_list_release(subsys%atomic_kinds)
157  CALL particle_list_release(subsys%particles)
158  CALL particle_list_release(subsys%shell_particles)
159  CALL particle_list_release(subsys%core_particles)
160  CALL distribution_1d_release(subsys%local_particles)
161  CALL molecule_kind_list_release(subsys%molecule_kinds)
162  CALL molecule_list_release(subsys%molecules)
163  CALL distribution_1d_release(subsys%local_molecules)
164  CALL mp_para_env_release(subsys%para_env)
165  IF (ASSOCIATED(subsys%multipoles)) THEN
166  CALL release_multipole_type(subsys%multipoles)
167  DEALLOCATE (subsys%multipoles)
168  END IF
169  CALL colvar_p_release(subsys%colvar_p)
170  CALL deallocate_global_constraint(subsys%gci)
171  CALL atprop_release(subsys%atprop)
172  IF (ASSOCIATED(subsys%virial)) DEALLOCATE (subsys%virial)
173  CALL cp_result_release(subsys%results)
174  CALL cell_release(subsys%cell)
175  DEALLOCATE (subsys)
176  END IF
177  NULLIFY (subsys)
178  END IF
179  END SUBROUTINE cp_subsys_release
180 
181 ! **************************************************************************************************
182 !> \brief sets various propreties of the subsys
183 !> \param subsys the subsys you want to modify
184 !> \param atomic_kinds ...
185 !> \param particles ...
186 !> \param local_particles ...
187 !> \param molecules ...
188 !> \param molecule_kinds ...
189 !> \param local_molecules ...
190 !> \param para_env ...
191 !> \param colvar_p ...
192 !> \param shell_particles ...
193 !> \param core_particles ...
194 !> \param gci ...
195 !> \param multipoles ...
196 !> \param results ...
197 !> \param cell ...
198 !> \par History
199 !> 08.2003 created [fawzi]
200 !> \author Fawzi Mohamed
201 ! **************************************************************************************************
202  SUBROUTINE cp_subsys_set(subsys, atomic_kinds, particles, local_particles, &
203  molecules, molecule_kinds, local_molecules, para_env, &
204  colvar_p, shell_particles, core_particles, gci, multipoles, results, cell)
205  TYPE(cp_subsys_type), INTENT(INOUT) :: subsys
206  TYPE(atomic_kind_list_type), OPTIONAL, POINTER :: atomic_kinds
207  TYPE(particle_list_type), OPTIONAL, POINTER :: particles
208  TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles
209  TYPE(molecule_list_type), OPTIONAL, POINTER :: molecules
210  TYPE(molecule_kind_list_type), OPTIONAL, POINTER :: molecule_kinds
211  TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_molecules
212  TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
213  TYPE(colvar_p_type), DIMENSION(:), OPTIONAL, &
214  POINTER :: colvar_p
215  TYPE(particle_list_type), OPTIONAL, POINTER :: shell_particles, core_particles
216  TYPE(global_constraint_type), OPTIONAL, POINTER :: gci
217  TYPE(multipole_type), OPTIONAL, POINTER :: multipoles
218  TYPE(cp_result_type), OPTIONAL, POINTER :: results
219  TYPE(cell_type), OPTIONAL, POINTER :: cell
220 
221  cpassert(subsys%ref_count > 0)
222  IF (PRESENT(multipoles)) THEN
223  IF (ASSOCIATED(subsys%multipoles)) THEN
224  IF (.NOT. ASSOCIATED(subsys%multipoles, multipoles)) THEN
225  CALL release_multipole_type(subsys%multipoles)
226  DEALLOCATE (subsys%multipoles)
227  END IF
228  END IF
229  subsys%multipoles => multipoles
230  END IF
231  IF (PRESENT(atomic_kinds)) THEN
232  CALL atomic_kind_list_retain(atomic_kinds)
233  CALL atomic_kind_list_release(subsys%atomic_kinds)
234  subsys%atomic_kinds => atomic_kinds
235  END IF
236  IF (PRESENT(particles)) THEN
237  CALL particle_list_retain(particles)
238  CALL particle_list_release(subsys%particles)
239  subsys%particles => particles
240  END IF
241  IF (PRESENT(local_particles)) THEN
242  CALL distribution_1d_retain(local_particles)
243  CALL distribution_1d_release(subsys%local_particles)
244  subsys%local_particles => local_particles
245  END IF
246  IF (PRESENT(local_molecules)) THEN
247  CALL distribution_1d_retain(local_molecules)
248  CALL distribution_1d_release(subsys%local_molecules)
249  subsys%local_molecules => local_molecules
250  END IF
251  IF (PRESENT(molecule_kinds)) THEN
252  CALL molecule_kind_list_retain(molecule_kinds)
253  CALL molecule_kind_list_release(subsys%molecule_kinds)
254  subsys%molecule_kinds => molecule_kinds
255  END IF
256  IF (PRESENT(molecules)) THEN
257  CALL molecule_list_retain(molecules)
258  CALL molecule_list_release(subsys%molecules)
259  subsys%molecules => molecules
260  END IF
261  IF (PRESENT(para_env)) THEN
262  CALL para_env%retain()
263  CALL mp_para_env_release(subsys%para_env)
264  subsys%para_env => para_env
265  END IF
266  IF (PRESENT(colvar_p)) THEN
267  cpassert(.NOT. ASSOCIATED(subsys%colvar_p))
268  subsys%colvar_p => colvar_p
269  END IF
270  IF (PRESENT(shell_particles)) THEN
271  IF (ASSOCIATED(shell_particles)) THEN
272  CALL particle_list_retain(shell_particles)
273  CALL particle_list_release(subsys%shell_particles)
274  subsys%shell_particles => shell_particles
275  END IF
276  END IF
277  IF (PRESENT(core_particles)) THEN
278  IF (ASSOCIATED(core_particles)) THEN
279  CALL particle_list_retain(core_particles)
280  CALL particle_list_release(subsys%core_particles)
281  subsys%core_particles => core_particles
282  END IF
283  END IF
284  IF (PRESENT(gci)) THEN
285  cpassert(.NOT. ASSOCIATED(subsys%gci))
286  subsys%gci => gci
287  END IF
288  IF (PRESENT(results)) THEN
289  IF (ASSOCIATED(results)) THEN
290  CALL cp_result_retain(results)
291  CALL cp_result_release(subsys%results)
292  subsys%results => results
293  END IF
294  END IF
295  IF (PRESENT(cell)) THEN
296  IF (ASSOCIATED(cell)) THEN
297  CALL cell_retain(cell)
298  CALL cell_release(subsys%cell)
299  subsys%cell => cell
300  END IF
301  END IF
302  END SUBROUTINE cp_subsys_set
303 
304 ! **************************************************************************************************
305 !> \brief returns information about various attributes of the given subsys
306 !> \param subsys the subsys you want info about
307 !> \param ref_count ...
308 !> \param atomic_kinds ...
309 !> \param atomic_kind_set ...
310 !> \param particles ...
311 !> \param particle_set ...
312 !> \param local_particles ...
313 !> \param molecules ...
314 !> \param molecule_set ...
315 !> \param molecule_kinds ...
316 !> \param molecule_kind_set ...
317 !> \param local_molecules ...
318 !> \param para_env ...
319 !> \param colvar_p ...
320 !> \param shell_particles ...
321 !> \param core_particles ...
322 !> \param gci ...
323 !> \param multipoles ...
324 !> \param natom ...
325 !> \param nparticle ...
326 !> \param ncore ...
327 !> \param nshell ...
328 !> \param nkind ...
329 !> \param atprop ...
330 !> \param virial ...
331 !> \param results ...
332 !> \param cell ...
333 !> \par History
334 !> 08.2003 created [fawzi]
335 !> 22.11.2010 (MK)
336 !> \author Fawzi Mohamed
337 ! **************************************************************************************************
338  SUBROUTINE cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, &
339  particles, particle_set, &
340  local_particles, molecules, molecule_set, molecule_kinds, &
341  molecule_kind_set, local_molecules, para_env, colvar_p, &
342  shell_particles, core_particles, gci, multipoles, &
343  natom, nparticle, ncore, nshell, nkind, atprop, virial, &
344  results, cell)
345  TYPE(cp_subsys_type), INTENT(IN) :: subsys
346  INTEGER, INTENT(out), OPTIONAL :: ref_count
347  TYPE(atomic_kind_list_type), OPTIONAL, POINTER :: atomic_kinds
348  TYPE(atomic_kind_type), DIMENSION(:), OPTIONAL, &
349  POINTER :: atomic_kind_set
350  TYPE(particle_list_type), OPTIONAL, POINTER :: particles
351  TYPE(particle_type), DIMENSION(:), OPTIONAL, &
352  POINTER :: particle_set
353  TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_particles
354  TYPE(molecule_list_type), OPTIONAL, POINTER :: molecules
355  TYPE(molecule_type), DIMENSION(:), OPTIONAL, &
356  POINTER :: molecule_set
357  TYPE(molecule_kind_list_type), OPTIONAL, POINTER :: molecule_kinds
358  TYPE(molecule_kind_type), DIMENSION(:), OPTIONAL, &
359  POINTER :: molecule_kind_set
360  TYPE(distribution_1d_type), OPTIONAL, POINTER :: local_molecules
361  TYPE(mp_para_env_type), OPTIONAL, POINTER :: para_env
362  TYPE(colvar_p_type), DIMENSION(:), OPTIONAL, &
363  POINTER :: colvar_p
364  TYPE(particle_list_type), OPTIONAL, POINTER :: shell_particles, core_particles
365  TYPE(global_constraint_type), OPTIONAL, POINTER :: gci
366  TYPE(multipole_type), OPTIONAL, POINTER :: multipoles
367  INTEGER, INTENT(out), OPTIONAL :: natom, nparticle, ncore, nshell, nkind
368  TYPE(atprop_type), OPTIONAL, POINTER :: atprop
369  TYPE(virial_type), OPTIONAL, POINTER :: virial
370  TYPE(cp_result_type), OPTIONAL, POINTER :: results
371  TYPE(cell_type), OPTIONAL, POINTER :: cell
372 
373  INTEGER :: n_atom, n_core, n_shell
374 
375  n_atom = 0
376  n_core = 0
377  n_shell = 0
378 
379  cpassert(subsys%ref_count > 0)
380 
381  IF (PRESENT(ref_count)) ref_count = subsys%ref_count
382  IF (PRESENT(atomic_kinds)) atomic_kinds => subsys%atomic_kinds
383  IF (PRESENT(atomic_kind_set)) atomic_kind_set => subsys%atomic_kinds%els
384  IF (PRESENT(particles)) particles => subsys%particles
385  IF (PRESENT(particle_set)) particle_set => subsys%particles%els
386  IF (PRESENT(local_particles)) local_particles => subsys%local_particles
387  IF (PRESENT(molecules)) molecules => subsys%molecules
388  IF (PRESENT(molecule_set)) molecule_set => subsys%molecules%els
389  IF (PRESENT(molecule_kinds)) molecule_kinds => subsys%molecule_kinds
390  IF (PRESENT(molecule_kind_set)) molecule_kind_set => subsys%molecule_kinds%els
391  IF (PRESENT(local_molecules)) local_molecules => subsys%local_molecules
392  IF (PRESENT(para_env)) para_env => subsys%para_env
393  IF (PRESENT(colvar_p)) colvar_p => subsys%colvar_p
394  IF (PRESENT(shell_particles)) shell_particles => subsys%shell_particles
395  IF (PRESENT(core_particles)) core_particles => subsys%core_particles
396  IF (PRESENT(gci)) gci => subsys%gci
397  IF (PRESENT(multipoles)) multipoles => subsys%multipoles
398  IF (PRESENT(virial)) virial => subsys%virial
399  IF (PRESENT(atprop)) atprop => subsys%atprop
400  IF (PRESENT(results)) results => subsys%results
401  IF (PRESENT(cell)) cell => subsys%cell
402  IF (PRESENT(nkind)) nkind = SIZE(subsys%atomic_kinds%els)
403 
404  IF (PRESENT(natom) .OR. PRESENT(nparticle) .OR. PRESENT(nshell)) THEN
405  ! An atomic particle set should be present in each subsystem at the moment
406  cpassert(ASSOCIATED(subsys%particles))
407  n_atom = subsys%particles%n_els
408  ! Check if we have other kinds of particles in this subsystem
409  IF (ASSOCIATED(subsys%shell_particles)) THEN
410  n_shell = subsys%shell_particles%n_els
411  cpassert(ASSOCIATED(subsys%core_particles))
412  n_core = subsys%core_particles%n_els
413  ! The same number of shell and core particles is assumed
414  cpassert(n_core == n_shell)
415  ELSE IF (ASSOCIATED(subsys%core_particles)) THEN
416  ! This case should not occur at the moment
417  cpassert(ASSOCIATED(subsys%shell_particles))
418  ELSE
419  n_core = 0
420  n_shell = 0
421  END IF
422  IF (PRESENT(natom)) natom = n_atom
423  IF (PRESENT(nparticle)) nparticle = n_atom + n_shell
424  IF (PRESENT(ncore)) ncore = n_core
425  IF (PRESENT(nshell)) nshell = n_shell
426  END IF
427 
428  END SUBROUTINE cp_subsys_get
429 
430 ! **************************************************************************************************
431 !> \brief Pack components of a subsystem particle sets into a single vector
432 !> \param subsys ...
433 !> \param f ...
434 !> \param r ...
435 !> \param s ...
436 !> \param v ...
437 !> \param fscale ...
438 !> \param cell ...
439 !> \date 19.11.10
440 !> \author Matthias Krack (MK)
441 !> \version 1.0
442 !> \note It is assumed that f, r, s, or v are properly allocated already
443 ! **************************************************************************************************
444  SUBROUTINE pack_subsys_particles(subsys, f, r, s, v, fscale, cell)
445 
446  TYPE(cp_subsys_type), INTENT(IN) :: subsys
447  REAL(kind=dp), DIMENSION(:), INTENT(OUT), OPTIONAL :: f, r, s, v
448  REAL(kind=dp), INTENT(IN), OPTIONAL :: fscale
449  TYPE(cell_type), OPTIONAL, POINTER :: cell
450 
451  INTEGER :: i, iatom, j, k, natom, nparticle, nsize, &
452  shell_index
453  REAL(kind=dp), DIMENSION(3) :: rs
454  TYPE(particle_list_type), POINTER :: core_particles, particles, &
455  shell_particles
456 
457  IF (PRESENT(s)) THEN
458  cpassert(PRESENT(cell))
459  cpassert(ASSOCIATED(cell))
460  END IF
461 
462  NULLIFY (core_particles)
463  NULLIFY (particles)
464  NULLIFY (shell_particles)
465 
466  CALL cp_subsys_get(subsys, &
467  core_particles=core_particles, &
468  natom=natom, &
469  nparticle=nparticle, &
470  particles=particles, &
471  shell_particles=shell_particles)
472 
473  nsize = 3*nparticle
474 
475  ! Pack forces
476 
477  IF (PRESENT(f)) THEN
478  cpassert((SIZE(f) >= nsize))
479  j = 0
480  DO iatom = 1, natom
481  shell_index = particles%els(iatom)%shell_index
482  IF (shell_index == 0) THEN
483  DO i = 1, 3
484  j = j + 1
485  f(j) = particles%els(iatom)%f(i)
486  END DO
487  ELSE
488  DO i = 1, 3
489  j = j + 1
490  f(j) = core_particles%els(shell_index)%f(i)
491  END DO
492  k = 3*(natom + shell_index - 1)
493  DO i = 1, 3
494  f(k + i) = shell_particles%els(shell_index)%f(i)
495  END DO
496  END IF
497  END DO
498  IF (PRESENT(fscale)) f(1:nsize) = fscale*f(1:nsize)
499  END IF
500 
501  ! Pack coordinates
502 
503  IF (PRESENT(r)) THEN
504  cpassert((SIZE(r) >= nsize))
505  j = 0
506  DO iatom = 1, natom
507  shell_index = particles%els(iatom)%shell_index
508  IF (shell_index == 0) THEN
509  DO i = 1, 3
510  j = j + 1
511  r(j) = particles%els(iatom)%r(i)
512  END DO
513  ELSE
514  DO i = 1, 3
515  j = j + 1
516  r(j) = core_particles%els(shell_index)%r(i)
517  END DO
518  k = 3*(natom + shell_index - 1)
519  DO i = 1, 3
520  r(k + i) = shell_particles%els(shell_index)%r(i)
521  END DO
522  END IF
523  END DO
524  END IF
525 
526  ! Pack as scaled coordinates
527 
528  IF (PRESENT(s)) THEN
529  cpassert((SIZE(s) >= nsize))
530  j = 0
531  DO iatom = 1, natom
532  shell_index = particles%els(iatom)%shell_index
533  IF (shell_index == 0) THEN
534  CALL real_to_scaled(rs, particles%els(iatom)%r, cell)
535  DO i = 1, 3
536  j = j + 1
537  s(j) = rs(i)
538  END DO
539  ELSE
540  CALL real_to_scaled(rs, core_particles%els(shell_index)%r, cell)
541  DO i = 1, 3
542  j = j + 1
543  s(j) = rs(i)
544  END DO
545  CALL real_to_scaled(rs, shell_particles%els(shell_index)%r, cell)
546  k = 3*(natom + shell_index - 1)
547  DO i = 1, 3
548  s(k + i) = rs(i)
549  END DO
550  END IF
551  END DO
552  END IF
553 
554  ! Pack velocities
555 
556  IF (PRESENT(v)) THEN
557  cpassert((SIZE(v) >= nsize))
558  j = 0
559  DO iatom = 1, natom
560  shell_index = particles%els(iatom)%shell_index
561  IF (shell_index == 0) THEN
562  DO i = 1, 3
563  j = j + 1
564  v(j) = particles%els(iatom)%v(i)
565  END DO
566  ELSE
567  DO i = 1, 3
568  j = j + 1
569  v(j) = core_particles%els(shell_index)%v(i)
570  END DO
571  k = 3*(natom + shell_index - 1)
572  DO i = 1, 3
573  v(k + i) = shell_particles%els(shell_index)%v(i)
574  END DO
575  END IF
576  END DO
577  END IF
578 
579  END SUBROUTINE pack_subsys_particles
580 
581 ! **************************************************************************************************
582 !> \brief Unpack components of a subsystem particle sets into a single vector
583 !> \param subsys ...
584 !> \param f ...
585 !> \param r ...
586 !> \param s ...
587 !> \param v ...
588 !> \param fscale ...
589 !> \param cell ...
590 !> \date 19.11.10
591 !> \author Matthias Krack (MK)
592 !> \version 1.0
593 ! **************************************************************************************************
594  SUBROUTINE unpack_subsys_particles(subsys, f, r, s, v, fscale, cell)
595 
596  TYPE(cp_subsys_type), INTENT(IN) :: subsys
597  REAL(kind=dp), DIMENSION(:), INTENT(IN), OPTIONAL :: f, r, s, v
598  REAL(kind=dp), INTENT(IN), OPTIONAL :: fscale
599  TYPE(cell_type), OPTIONAL, POINTER :: cell
600 
601  INTEGER :: i, iatom, j, k, natom, nparticle, nsize, &
602  shell_index
603  REAL(kind=dp) :: fc, fs, mass, my_fscale
604  REAL(kind=dp), DIMENSION(3) :: rs
605  TYPE(particle_list_type), POINTER :: core_particles, particles, &
606  shell_particles
607 
608  NULLIFY (core_particles)
609  NULLIFY (particles)
610  NULLIFY (shell_particles)
611 
612  CALL cp_subsys_get(subsys, &
613  core_particles=core_particles, &
614  natom=natom, &
615  nparticle=nparticle, &
616  particles=particles, &
617  shell_particles=shell_particles)
618 
619  nsize = 3*nparticle
620 
621  ! Unpack forces
622 
623  IF (PRESENT(f)) THEN
624  cpassert((SIZE(f) >= nsize))
625  IF (PRESENT(fscale)) THEN
626  my_fscale = fscale
627  ELSE
628  my_fscale = 1.0_dp
629  END IF
630  j = 0
631  DO iatom = 1, natom
632  shell_index = particles%els(iatom)%shell_index
633  IF (shell_index == 0) THEN
634  DO i = 1, 3
635  j = j + 1
636  particles%els(iatom)%f(i) = my_fscale*f(j)
637  END DO
638  ELSE
639  DO i = 1, 3
640  j = j + 1
641  core_particles%els(shell_index)%f(i) = my_fscale*f(j)
642  END DO
643  k = 3*(natom + shell_index - 1)
644  DO i = 1, 3
645  shell_particles%els(shell_index)%f(i) = my_fscale*f(k + i)
646  END DO
647  END IF
648  END DO
649  END IF
650 
651  ! Unpack coordinates
652 
653  IF (PRESENT(r)) THEN
654  cpassert((SIZE(r) >= nsize))
655  j = 0
656  DO iatom = 1, natom
657  shell_index = particles%els(iatom)%shell_index
658  IF (shell_index == 0) THEN
659  DO i = 1, 3
660  j = j + 1
661  particles%els(iatom)%r(i) = r(j)
662  END DO
663  ELSE
664  DO i = 1, 3
665  j = j + 1
666  core_particles%els(shell_index)%r(i) = r(j)
667  END DO
668  k = 3*(natom + shell_index - 1)
669  DO i = 1, 3
670  shell_particles%els(shell_index)%r(i) = r(k + i)
671  END DO
672  ! Update atomic position due to core and shell motion
673  mass = particles%els(iatom)%atomic_kind%mass
674  fc = core_particles%els(shell_index)%atomic_kind%shell%mass_core/mass
675  fs = shell_particles%els(shell_index)%atomic_kind%shell%mass_shell/mass
676  particles%els(iatom)%r(1:3) = fc*core_particles%els(shell_index)%r(1:3) + &
677  fs*shell_particles%els(shell_index)%r(1:3)
678  END IF
679  END DO
680  END IF
681 
682  ! Unpack scaled coordinates
683 
684  IF (PRESENT(s)) THEN
685  cpassert((SIZE(s) >= nsize))
686  cpassert(PRESENT(cell))
687  cpassert(ASSOCIATED(cell))
688  j = 0
689  DO iatom = 1, natom
690  shell_index = particles%els(iatom)%shell_index
691  IF (shell_index == 0) THEN
692  DO i = 1, 3
693  j = j + 1
694  rs(i) = s(j)
695  END DO
696  CALL scaled_to_real(particles%els(iatom)%r, rs, cell)
697  ELSE
698  DO i = 1, 3
699  j = j + 1
700  rs(i) = s(j)
701  END DO
702  CALL scaled_to_real(core_particles%els(shell_index)%r, rs, cell)
703  k = 3*(natom + shell_index - 1)
704  DO i = 1, 3
705  rs(i) = s(k + i)
706  END DO
707  CALL scaled_to_real(shell_particles%els(shell_index)%r, rs, cell)
708  ! Update atomic position due to core and shell motion
709  mass = particles%els(iatom)%atomic_kind%mass
710  fc = core_particles%els(shell_index)%atomic_kind%shell%mass_core/mass
711  fs = shell_particles%els(shell_index)%atomic_kind%shell%mass_shell/mass
712  particles%els(iatom)%r(1:3) = fc*core_particles%els(shell_index)%r(1:3) + &
713  fs*shell_particles%els(shell_index)%r(1:3)
714  END IF
715  END DO
716  END IF
717 
718  ! Unpack velocities
719 
720  IF (PRESENT(v)) THEN
721  cpassert((SIZE(v) >= nsize))
722  j = 0
723  DO iatom = 1, natom
724  shell_index = particles%els(iatom)%shell_index
725  IF (shell_index == 0) THEN
726  DO i = 1, 3
727  j = j + 1
728  particles%els(iatom)%v(i) = v(j)
729  END DO
730  ELSE
731  DO i = 1, 3
732  j = j + 1
733  core_particles%els(shell_index)%v(i) = v(j)
734  END DO
735  k = 3*(natom + shell_index - 1)
736  DO i = 1, 3
737  shell_particles%els(shell_index)%v(i) = v(k + i)
738  END DO
739  ! Update atomic velocity due to core and shell motion
740  mass = particles%els(iatom)%atomic_kind%mass
741  fc = core_particles%els(shell_index)%atomic_kind%shell%mass_core/mass
742  fs = shell_particles%els(shell_index)%atomic_kind%shell%mass_shell/mass
743  particles%els(iatom)%v(1:3) = fc*core_particles%els(shell_index)%v(1:3) + &
744  fs*shell_particles%els(shell_index)%v(1:3)
745  END IF
746  END DO
747  END IF
748 
749  END SUBROUTINE unpack_subsys_particles
750 
751 END MODULE cp_subsys_types
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_retain(list)
retains a list (see doc/ReferenceCounting.html)
Define the atomic kind types and their sub types.
Holds information on atomic properties.
Definition: atprop_types.F:14
subroutine, public atprop_release(atprop_env)
releases the atprop
Definition: atprop_types.F:144
Handles all functions related to the CELL.
Definition: cell_types.F:15
subroutine, public scaled_to_real(r, s, cell)
Transform scaled cell coordinates real coordinates. r=h*s.
Definition: cell_types.F:516
subroutine, public real_to_scaled(s, r, cell)
Transform real to scaled cell coordinates. s=h_inv*r.
Definition: cell_types.F:486
subroutine, public cell_release(cell)
releases the given cell (see doc/ReferenceCounting.html)
Definition: cell_types.F:559
subroutine, public cell_retain(cell)
retains the given cell (see doc/ReferenceCounting.html)
Definition: cell_types.F:542
Initialize the collective variables types.
Definition: colvar_types.F:15
subroutine, public colvar_p_release(colvar_p)
Deallocate a set of colvar_p_type.
set of type/routines to handle the storage of results in force_envs
subroutine, public cp_result_retain(results)
Retains cp_result type.
subroutine, public cp_result_release(results)
Releases cp_result type.
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_release(subsys)
releases a subsys (see doc/ReferenceCounting.html)
subroutine, public unpack_subsys_particles(subsys, f, r, s, v, fscale, cell)
Unpack components of a subsystem particle sets into a single vector.
subroutine, public cp_subsys_retain(subsys)
retains a subsys (see doc/ReferenceCounting.html)
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
subroutine, public pack_subsys_particles(subsys, f, r, s, v, fscale, cell)
Pack components of a subsystem particle sets into a single vector.
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
subroutine, public distribution_1d_retain(distribution_1d)
retains a distribution_1d
subroutine, public distribution_1d_release(distribution_1d)
releases the given distribution_1d
Defines the basic variable types.
Definition: kinds.F:23
integer, parameter, public dp
Definition: kinds.F:34
Interface to the message passing library MPI.
subroutine, public mp_para_env_release(para_env)
releases the para object (to be called when you don't want anymore the shared copy of this object)
represent a simple array based list of the given type
subroutine, public molecule_kind_list_release(list)
releases a list (see doc/ReferenceCounting.html)
subroutine, public molecule_kind_list_retain(list)
retains 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_retain(list)
retains a list (see doc/ReferenceCounting.html)
subroutine, public molecule_list_release(list)
releases a list (see doc/ReferenceCounting.html)
Define the data structure for the molecule information.
subroutine, public deallocate_global_constraint(gci)
Deallocate a global constraint.
Multipole structure: for multipole (fixed and induced) in FF based MD.
subroutine, public release_multipole_type(multipoles)
...
represent a simple array based list of the given type
subroutine, public particle_list_retain(list)
retains a list (see doc/ReferenceCounting.html)
subroutine, public particle_list_release(list)
releases a list (see doc/ReferenceCounting.html)
Define the data structure for the particle information.