(git:374b731)
Loading...
Searching...
No Matches
constraint.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!> \par History
10!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
11! **************************************************************************************************
15 USE cell_types, ONLY: cell_type
33 USE constraint_clv, ONLY: &
37 USE constraint_util, ONLY: check_tol,&
50 USE kinds, ONLY: default_string_length,&
51 dp
53 USE message_passing, ONLY: mp_comm_type,&
61 USE simpar_types, ONLY: simpar_type
62#include "./base/base_uses.f90"
63
64 IMPLICIT NONE
65
66 PRIVATE
67 PUBLIC :: shake_control, &
72
73 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'constraint'
74 INTEGER, PARAMETER, PRIVATE :: Max_Shake_Iter = 1000
75
76CONTAINS
77
78! **************************************************************************************************
79!> \brief ...
80!> \param gci ...
81!> \param local_molecules ...
82!> \param molecule_set ...
83!> \param molecule_kind_set ...
84!> \param particle_set ...
85!> \param pos ...
86!> \param vel ...
87!> \param dt ...
88!> \param shake_tol ...
89!> \param log_unit ...
90!> \param lagrange_mult ...
91!> \param dump_lm ...
92!> \param cell ...
93!> \param group ...
94!> \param local_particles ...
95!> \par History
96!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
97! **************************************************************************************************
98 SUBROUTINE shake_control(gci, local_molecules, molecule_set, molecule_kind_set, &
99 particle_set, pos, vel, dt, shake_tol, log_unit, lagrange_mult, dump_lm, &
100 cell, group, local_particles)
101
102 TYPE(global_constraint_type), POINTER :: gci
103 TYPE(distribution_1d_type), POINTER :: local_molecules
104 TYPE(molecule_type), POINTER :: molecule_set(:)
105 TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
106 TYPE(particle_type), POINTER :: particle_set(:)
107 REAL(kind=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
108 REAL(kind=dp), INTENT(in) :: dt, shake_tol
109 INTEGER, INTENT(in) :: log_unit, lagrange_mult
110 LOGICAL, INTENT(IN) :: dump_lm
111 TYPE(cell_type), POINTER :: cell
112
113 CLASS(mp_comm_type), INTENT(in) :: group
114 TYPE(distribution_1d_type), POINTER :: local_particles
115
116 CHARACTER(LEN=*), PARAMETER :: routinen = 'shake_control'
117
118 INTEGER :: handle, i, ikind, imol, ishake_ext, &
119 ishake_int, k, n3x3con, n4x6con, &
120 nconstraint, nkind, nmol_per_kind, &
121 nvsitecon
122 LOGICAL :: do_ext_constraint
123 REAL(kind=dp) :: int_max_sigma, mass, max_sigma
124 REAL(kind=dp), DIMENSION(SIZE(pos, 2)) :: imass
125 TYPE(atomic_kind_type), POINTER :: atomic_kind
126 TYPE(colvar_counters) :: ncolv
127 TYPE(molecule_kind_type), POINTER :: molecule_kind
128 TYPE(molecule_type), POINTER :: molecule
129
130 CALL timeset(routinen, handle)
131 nkind = SIZE(molecule_kind_set)
132 DO k = 1, SIZE(pos, 2)
133 atomic_kind => particle_set(k)%atomic_kind
134 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
135 imass(k) = 1.0_dp/max(mass, epsilon(0.0_dp))
136 END DO
137 do_ext_constraint = (gci%ntot /= 0)
138 ishake_ext = 0
139 max_sigma = -1.0e+10_dp
140 shake_inter_loop: DO WHILE ((abs(max_sigma) >= shake_tol) .AND. (ishake_ext <= max_shake_iter))
141 max_sigma = 0.0_dp
142 ishake_ext = ishake_ext + 1
143 ! Intramolecular Constraints
144 mol: DO ikind = 1, nkind
145 nmol_per_kind = local_molecules%n_el(ikind)
146 DO imol = 1, nmol_per_kind
147 i = local_molecules%list(ikind)%array(imol)
148 molecule => molecule_set(i)
149 molecule_kind => molecule%molecule_kind
150 CALL get_molecule_kind(molecule_kind, ncolv=ncolv, &
151 ng3x3=n3x3con, ng4x6=n4x6con, &
152 nconstraint=nconstraint, nvsite=nvsitecon)
153 IF (nconstraint == 0) cycle
154 ishake_int = 0
155 int_max_sigma = -1.0e+10_dp
156 shake_intra_loop: DO WHILE ((abs(int_max_sigma) >= shake_tol) .AND. (ishake_int <= max_shake_iter))
157 int_max_sigma = 0.0_dp
158 ishake_int = ishake_int + 1
159 ! 3x3
160 IF (n3x3con /= 0) &
161 CALL shake_3x3_int(molecule, particle_set, pos, vel, dt, ishake_int, &
162 int_max_sigma)
163 ! 4x6
164 IF (n4x6con /= 0) &
165 CALL shake_4x6_int(molecule, particle_set, pos, vel, dt, ishake_int, &
166 int_max_sigma)
167 ! Collective Variables
168 IF (ncolv%ntot /= 0) &
169 CALL shake_colv_int(molecule, particle_set, pos, vel, dt, ishake_int, &
170 cell, imass, int_max_sigma)
171 END DO shake_intra_loop
172 max_sigma = max(max_sigma, int_max_sigma)
173 CALL shake_int_info(log_unit, i, ishake_int, max_sigma)
174 ! Virtual Site
175 IF (nvsitecon /= 0) &
176 CALL shake_vsite_int(molecule, pos)
177 END DO
178 END DO mol
179 ! Intermolecular constraints
180 IF (do_ext_constraint) THEN
181 CALL update_temporary_set(group, pos=pos, vel=vel)
182 ! 3x3
183 IF (gci%ng3x3 /= 0) &
184 CALL shake_3x3_ext(gci, particle_set, pos, vel, dt, ishake_ext, &
185 max_sigma)
186 ! 4x6
187 IF (gci%ng4x6 /= 0) &
188 CALL shake_4x6_ext(gci, particle_set, pos, vel, dt, ishake_ext, &
189 max_sigma)
190 ! Collective Variables
191 IF (gci%ncolv%ntot /= 0) &
192 CALL shake_colv_ext(gci, particle_set, pos, vel, dt, ishake_ext, &
193 cell, imass, max_sigma)
194 ! Virtual Site
195 IF (gci%nvsite /= 0) &
196 CALL shake_vsite_ext(gci, pos)
197 CALL restore_temporary_set(particle_set, local_particles, pos=pos, vel=vel)
198 END IF
199 CALL shake_ext_info(log_unit, ishake_ext, max_sigma)
200 END DO shake_inter_loop
201 CALL dump_lagrange_mult(dump_lm, lagrange_mult, local_molecules, molecule_set, gci, &
202 molecule_kind_set, group, "S")
203
204 CALL timestop(handle)
205 END SUBROUTINE shake_control
206
207! **************************************************************************************************
208!> \brief ...
209!> \param gci ...
210!> \param local_molecules ...
211!> \param molecule_set ...
212!> \param molecule_kind_set ...
213!> \param particle_set ...
214!> \param vel ...
215!> \param dt ...
216!> \param rattle_tol ...
217!> \param log_unit ...
218!> \param lagrange_mult ...
219!> \param dump_lm ...
220!> \param cell ...
221!> \param group ...
222!> \param local_particles ...
223!> \par History
224!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
225! **************************************************************************************************
226 SUBROUTINE rattle_control(gci, local_molecules, molecule_set, molecule_kind_set, &
227 particle_set, vel, dt, rattle_tol, log_unit, lagrange_mult, dump_lm, cell, group, &
228 local_particles)
229
230 TYPE(global_constraint_type), POINTER :: gci
231 TYPE(distribution_1d_type), POINTER :: local_molecules
232 TYPE(molecule_type), POINTER :: molecule_set(:)
233 TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
234 TYPE(particle_type), POINTER :: particle_set(:)
235 REAL(kind=dp), INTENT(INOUT) :: vel(:, :)
236 REAL(kind=dp), INTENT(in) :: dt, rattle_tol
237 INTEGER, INTENT(in) :: log_unit, lagrange_mult
238 LOGICAL, INTENT(IN) :: dump_lm
239 TYPE(cell_type), POINTER :: cell
240
241 CLASS(mp_comm_type), INTENT(in) :: group
242 TYPE(distribution_1d_type), POINTER :: local_particles
243
244 CHARACTER(LEN=*), PARAMETER :: routinen = 'rattle_control'
245
246 INTEGER :: handle, i, ikind, imol, irattle_ext, &
247 irattle_int, k, n3x3con, n4x6con, &
248 nconstraint, nkind, nmol_per_kind
249 LOGICAL :: do_ext_constraint
250 REAL(kind=dp) :: int_max_sigma, mass, max_sigma
251 REAL(kind=dp), DIMENSION(SIZE(vel, 2)) :: imass
252 TYPE(atomic_kind_type), POINTER :: atomic_kind
253 TYPE(colvar_counters) :: ncolv
254 TYPE(molecule_kind_type), POINTER :: molecule_kind
255 TYPE(molecule_type), POINTER :: molecule
256
257 CALL timeset(routinen, handle)
258 nkind = SIZE(molecule_kind_set)
259 DO k = 1, SIZE(vel, 2)
260 atomic_kind => particle_set(k)%atomic_kind
261 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
262 imass(k) = 1.0_dp/max(mass, epsilon(0.0_dp))
263 END DO
264 do_ext_constraint = (gci%ntot /= 0)
265 irattle_ext = 0
266 max_sigma = -1.0e+10_dp
267 rattle_inter_loop: DO WHILE (abs(max_sigma) >= rattle_tol)
268 max_sigma = 0.0_dp
269 irattle_ext = irattle_ext + 1
270 ! Intramolecular Constraints
271 mol: DO ikind = 1, nkind
272 nmol_per_kind = local_molecules%n_el(ikind)
273 DO imol = 1, nmol_per_kind
274 i = local_molecules%list(ikind)%array(imol)
275 molecule => molecule_set(i)
276 molecule_kind => molecule%molecule_kind
277 CALL get_molecule_kind(molecule_kind, ncolv=ncolv, ng3x3=n3x3con, &
278 ng4x6=n4x6con, nconstraint=nconstraint)
279 IF (nconstraint == 0) cycle
280 irattle_int = 0
281 int_max_sigma = -1.0e+10_dp
282 rattle_intra_loop: DO WHILE (abs(int_max_sigma) >= rattle_tol)
283 int_max_sigma = 0.0_dp
284 irattle_int = irattle_int + 1
285 ! 3x3
286 IF (n3x3con /= 0) &
287 CALL rattle_3x3_int(molecule, particle_set, vel, dt)
288 ! 4x6
289 IF (n4x6con /= 0) &
290 CALL rattle_4x6_int(molecule, particle_set, vel, dt)
291 ! Collective Variables
292 IF (ncolv%ntot /= 0) &
293 CALL rattle_colv_int(molecule, particle_set, vel, dt, &
294 irattle_int, cell, imass, int_max_sigma)
295 END DO rattle_intra_loop
296 max_sigma = max(max_sigma, int_max_sigma)
297 CALL rattle_int_info(log_unit, i, irattle_int, max_sigma)
298 END DO
299 END DO mol
300 ! Intermolecular Constraints
301 IF (do_ext_constraint) THEN
302 CALL update_temporary_set(group, vel=vel)
303 ! 3x3
304 IF (gci%ng3x3 /= 0) &
305 CALL rattle_3x3_ext(gci, particle_set, vel, dt)
306 ! 4x6
307 IF (gci%ng4x6 /= 0) &
308 CALL rattle_4x6_ext(gci, particle_set, vel, dt)
309 ! Collective Variables
310 IF (gci%ncolv%ntot /= 0) &
311 CALL rattle_colv_ext(gci, particle_set, vel, dt, &
312 irattle_ext, cell, imass, max_sigma)
313 CALL restore_temporary_set(particle_set, local_particles, vel=vel)
314 END IF
315 CALL rattle_ext_info(log_unit, irattle_ext, max_sigma)
316 END DO rattle_inter_loop
317 CALL dump_lagrange_mult(dump_lm, lagrange_mult, local_molecules, molecule_set, gci, &
318 molecule_kind_set, group, "R")
319 CALL timestop(handle)
320
321 END SUBROUTINE rattle_control
322
323! **************************************************************************************************
324!> \brief ...
325!> \param gci ...
326!> \param local_molecules ...
327!> \param molecule_set ...
328!> \param molecule_kind_set ...
329!> \param particle_set ...
330!> \param pos ...
331!> \param vel ...
332!> \param dt ...
333!> \param simpar ...
334!> \param roll_tol ...
335!> \param iroll ...
336!> \param vector_r ...
337!> \param vector_v ...
338!> \param group ...
339!> \param u ...
340!> \param cell ...
341!> \param local_particles ...
342!> \par History
343!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
344! **************************************************************************************************
345 SUBROUTINE shake_roll_control(gci, local_molecules, molecule_set, &
346 molecule_kind_set, particle_set, pos, vel, dt, simpar, roll_tol, iroll, &
347 vector_r, vector_v, group, u, cell, local_particles)
348
349 TYPE(global_constraint_type), POINTER :: gci
350 TYPE(distribution_1d_type), POINTER :: local_molecules
351 TYPE(molecule_type), POINTER :: molecule_set(:)
352 TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
353 TYPE(particle_type), POINTER :: particle_set(:)
354 REAL(kind=dp), INTENT(INOUT) :: pos(:, :), vel(:, :)
355 REAL(kind=dp), INTENT(IN) :: dt
356 TYPE(simpar_type), INTENT(IN) :: simpar
357 REAL(kind=dp), INTENT(OUT) :: roll_tol
358 INTEGER, INTENT(INOUT) :: iroll
359 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: vector_r, vector_v
360
361 CLASS(mp_comm_type), INTENT(IN) :: group
362 REAL(kind=dp), DIMENSION(:, :), INTENT(IN), &
363 OPTIONAL :: u
364 TYPE(cell_type), POINTER :: cell
365 TYPE(distribution_1d_type), POINTER :: local_particles
366
367 CHARACTER(LEN=*), PARAMETER :: routinen = 'shake_roll_control'
368
369 INTEGER :: handle, i, ikind, imol, ishake_ext, ishake_int, k, lagrange_mult, log_unit, &
370 n3x3con, n4x6con, nconstraint, nkind, nmol_per_kind, nvsitecon
371 LOGICAL :: do_ext_constraint, dump_lm
372 REAL(kind=dp) :: int_max_sigma, mass, max_sigma, shake_tol
373 REAL(kind=dp), DIMENSION(3, 3) :: r_shake, v_shake
374 REAL(kind=dp), DIMENSION(SIZE(pos, 2)) :: imass
375 TYPE(atomic_kind_type), POINTER :: atomic_kind
376 TYPE(colvar_counters) :: ncolv
377 TYPE(molecule_kind_type), POINTER :: molecule_kind
378 TYPE(molecule_type), POINTER :: molecule
379
380 CALL timeset(routinen, handle)
381 nkind = SIZE(molecule_kind_set)
382 shake_tol = simpar%shake_tol
383 log_unit = simpar%info_constraint
384 lagrange_mult = simpar%lagrange_multipliers
385 dump_lm = simpar%dump_lm
386 ! setting up for roll
387 IF (simpar%ensemble == npt_i_ensemble .OR. simpar%ensemble == npt_ia_ensemble) THEN
388 CALL get_roll_matrix('SHAKE', r_shake, v_shake, vector_r, vector_v)
389 ELSE IF (simpar%ensemble == npt_f_ensemble) THEN
390 CALL get_roll_matrix('SHAKE', r_shake, v_shake, vector_r, vector_v, u)
391 END IF
392 DO k = 1, SIZE(pos, 2)
393 atomic_kind => particle_set(k)%atomic_kind
394 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
395 imass(k) = 1.0_dp/max(mass, epsilon(0.0_dp))
396 END DO
397 do_ext_constraint = (gci%ntot /= 0)
398 ishake_ext = 0
399 max_sigma = -1.0e+10_dp
400 shake_inter_loop: DO WHILE (abs(max_sigma) >= shake_tol)
401 max_sigma = 0.0_dp
402 ishake_ext = ishake_ext + 1
403 ! Intramolecular Constraints
404 mol: DO ikind = 1, nkind
405 nmol_per_kind = local_molecules%n_el(ikind)
406 DO imol = 1, nmol_per_kind
407 i = local_molecules%list(ikind)%array(imol)
408 molecule => molecule_set(i)
409 molecule_kind => molecule%molecule_kind
410 CALL get_molecule_kind(molecule_kind, ncolv=ncolv, &
411 ng3x3=n3x3con, ng4x6=n4x6con, &
412 nconstraint=nconstraint, nvsite=nvsitecon)
413 IF (nconstraint == 0) cycle
414 ishake_int = 0
415 int_max_sigma = -1.0e+10_dp
416 shake_roll_intra_loop: DO WHILE (abs(int_max_sigma) >= shake_tol)
417 int_max_sigma = 0.0_dp
418 ishake_int = ishake_int + 1
419 ! 3x3
420 IF (n3x3con /= 0) &
421 CALL shake_roll_3x3_int(molecule, particle_set, pos, vel, r_shake, &
422 v_shake, dt, ishake_int, int_max_sigma)
423 ! 4x6
424 IF (n4x6con /= 0) &
425 CALL shake_roll_4x6_int(molecule, particle_set, pos, vel, r_shake, &
426 dt, ishake_int, int_max_sigma)
427 ! Collective Variables
428 IF (ncolv%ntot /= 0) &
429 CALL shake_roll_colv_int(molecule, particle_set, pos, vel, r_shake, &
430 v_shake, dt, ishake_int, cell, imass, int_max_sigma)
431 END DO shake_roll_intra_loop
432 max_sigma = max(max_sigma, int_max_sigma)
433 CALL shake_int_info(log_unit, i, ishake_int, max_sigma)
434 ! Virtual Site
435 IF (nvsitecon /= 0) THEN
436 cpabort("Virtual Site Constraint/Restraint not implemented for SHAKE_ROLL!")
437 END IF
438 END DO
439 END DO mol
440 ! Intermolecular constraints
441 IF (do_ext_constraint) THEN
442 CALL update_temporary_set(group, pos=pos, vel=vel)
443 ! 3x3
444 IF (gci%ng3x3 /= 0) &
445 CALL shake_roll_3x3_ext(gci, particle_set, pos, vel, r_shake, &
446 v_shake, dt, ishake_ext, max_sigma)
447 ! 4x6
448 IF (gci%ng4x6 /= 0) &
449 CALL shake_roll_4x6_ext(gci, particle_set, pos, vel, r_shake, &
450 dt, ishake_ext, max_sigma)
451 ! Collective Variables
452 IF (gci%ncolv%ntot /= 0) &
453 CALL shake_roll_colv_ext(gci, particle_set, pos, vel, r_shake, &
454 v_shake, dt, ishake_ext, cell, imass, max_sigma)
455 ! Virtual Site
456 IF (gci%nvsite /= 0) &
457 cpabort("Virtual Site Constraint/Restraint not implemented for SHAKE_ROLL!")
458 CALL restore_temporary_set(particle_set, local_particles, pos=pos, vel=vel)
459 END IF
460 CALL shake_ext_info(log_unit, ishake_ext, max_sigma)
461 END DO shake_inter_loop
462 CALL dump_lagrange_mult(dump_lm, lagrange_mult, local_molecules, molecule_set, gci, &
463 molecule_kind_set, group, "S")
464 CALL check_tol(roll_tol, iroll, 'SHAKE', r_shake)
465 CALL timestop(handle)
466
467 END SUBROUTINE shake_roll_control
468
469! **************************************************************************************************
470!> \brief ...
471!> \param gci ...
472!> \param local_molecules ...
473!> \param molecule_set ...
474!> \param molecule_kind_set ...
475!> \param particle_set ...
476!> \param vel ...
477!> \param dt ...
478!> \param simpar ...
479!> \param vector ...
480!> \param veps ...
481!> \param roll_tol ...
482!> \param iroll ...
483!> \param para_env ...
484!> \param u ...
485!> \param cell ...
486!> \param local_particles ...
487!> \par History
488!> Teodoro Laino [tlaino] 2007 - Extension to Intermolecular constraints
489! **************************************************************************************************
490 SUBROUTINE rattle_roll_control(gci, local_molecules, molecule_set, &
491 molecule_kind_set, particle_set, vel, dt, simpar, vector, &
492 veps, roll_tol, iroll, para_env, u, cell, local_particles)
493
494 TYPE(global_constraint_type), POINTER :: gci
495 TYPE(distribution_1d_type), POINTER :: local_molecules
496 TYPE(molecule_type), POINTER :: molecule_set(:)
497 TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
498 TYPE(particle_type), POINTER :: particle_set(:)
499 REAL(kind=dp), INTENT(INOUT) :: vel(:, :)
500 REAL(kind=dp), INTENT(IN) :: dt
501 TYPE(simpar_type), INTENT(IN) :: simpar
502 REAL(kind=dp), DIMENSION(:), INTENT(IN) :: vector
503 REAL(kind=dp), DIMENSION(:, :), INTENT(INOUT) :: veps
504 REAL(kind=dp), INTENT(OUT) :: roll_tol
505 INTEGER, INTENT(INOUT) :: iroll
506 TYPE(mp_para_env_type), INTENT(IN) :: para_env
507 REAL(kind=dp), DIMENSION(:, :), INTENT(IN), &
508 OPTIONAL :: u
509 TYPE(cell_type), POINTER :: cell
510 TYPE(distribution_1d_type), POINTER :: local_particles
511
512 CHARACTER(LEN=*), PARAMETER :: routinen = 'rattle_roll_control'
513
514 INTEGER :: handle, i, ikind, imol, irattle_ext, irattle_int, k, lagrange_mult, log_unit, &
515 n3x3con, n4x6con, nconstraint, nkind, nmol_per_kind
516 LOGICAL :: do_ext_constraint, dump_lm
517 REAL(kind=dp) :: int_max_sigma, mass, max_sigma, &
518 rattle_tol
519 REAL(kind=dp), DIMENSION(3, 3) :: r_rattle
520 REAL(kind=dp), DIMENSION(SIZE(vel, 2)) :: imass
521 TYPE(atomic_kind_type), POINTER :: atomic_kind
522 TYPE(colvar_counters) :: ncolv
523 TYPE(molecule_kind_type), POINTER :: molecule_kind
524 TYPE(molecule_type), POINTER :: molecule
525
526 CALL timeset(routinen, handle)
527 ! initialize locals
528 nkind = SIZE(molecule_kind_set)
529 rattle_tol = simpar%shake_tol
530 log_unit = simpar%info_constraint
531 lagrange_mult = simpar%lagrange_multipliers
532 dump_lm = simpar%dump_lm
533 ! setting up for roll
534 IF (simpar%ensemble == npt_i_ensemble .OR. simpar%ensemble == npt_ia_ensemble) THEN
535 CALL get_roll_matrix('RATTLE', v_shake=r_rattle, vector_v=vector)
536 ELSE IF (simpar%ensemble == npt_f_ensemble) THEN
537 CALL get_roll_matrix('RATTLE', v_shake=r_rattle, vector_v=vector, u=u)
538 END IF
539 DO k = 1, SIZE(vel, 2)
540 atomic_kind => particle_set(k)%atomic_kind
541 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
542 imass(k) = 1.0_dp/max(mass, epsilon(0.0_dp))
543 END DO
544 do_ext_constraint = (gci%ntot /= 0)
545 irattle_ext = 0
546 max_sigma = -1.0e+10_dp
547 rattle_inter_loop: DO WHILE (abs(max_sigma) >= rattle_tol)
548 max_sigma = 0.0_dp
549 irattle_ext = irattle_ext + 1
550 ! Intramolecular Constraints
551 mol: DO ikind = 1, nkind
552 nmol_per_kind = local_molecules%n_el(ikind)
553 DO imol = 1, nmol_per_kind
554 i = local_molecules%list(ikind)%array(imol)
555 molecule => molecule_set(i)
556 molecule_kind => molecule%molecule_kind
557 CALL get_molecule_kind(molecule_kind, ncolv=ncolv, &
558 ng3x3=n3x3con, ng4x6=n4x6con, &
559 nconstraint=nconstraint)
560 IF (nconstraint == 0) cycle
561 int_max_sigma = -1.0e+10_dp
562 irattle_int = 0
563 rattle_roll_intramolecular: DO WHILE (abs(int_max_sigma) >= rattle_tol)
564 int_max_sigma = 0.0_dp
565 irattle_int = irattle_int + 1
566 ! 3x3
567 IF (n3x3con /= 0) &
568 CALL rattle_roll_3x3_int(molecule, particle_set, vel, r_rattle, dt, &
569 veps)
570 ! 4x6
571 IF (n4x6con /= 0) &
572 CALL rattle_roll_4x6_int(molecule, particle_set, vel, r_rattle, dt, &
573 veps)
574 ! Collective Variables
575 IF (ncolv%ntot /= 0) &
576 CALL rattle_roll_colv_int(molecule, particle_set, vel, r_rattle, dt, &
577 irattle_int, veps, cell, imass, int_max_sigma)
578 END DO rattle_roll_intramolecular
579 max_sigma = max(max_sigma, int_max_sigma)
580 CALL rattle_int_info(log_unit, i, irattle_int, max_sigma)
581 END DO
582 END DO mol
583 ! Intermolecular Constraints
584 IF (do_ext_constraint) THEN
585 CALL update_temporary_set(para_env, vel=vel)
586 ! 3x3
587 IF (gci%ng3x3 /= 0) &
588 CALL rattle_roll_3x3_ext(gci, particle_set, vel, r_rattle, dt, &
589 veps)
590 ! 4x6
591 IF (gci%ng4x6 /= 0) &
592 CALL rattle_roll_4x6_ext(gci, particle_set, vel, r_rattle, dt, &
593 veps)
594 ! Collective Variables
595 IF (gci%ncolv%ntot /= 0) &
596 CALL rattle_roll_colv_ext(gci, particle_set, vel, r_rattle, dt, &
597 irattle_ext, veps, cell, imass, max_sigma)
598 CALL restore_temporary_set(particle_set, local_particles, vel=vel)
599 END IF
600 CALL rattle_ext_info(log_unit, irattle_ext, max_sigma)
601 END DO rattle_inter_loop
602 CALL dump_lagrange_mult(dump_lm, lagrange_mult, local_molecules, molecule_set, gci, &
603 molecule_kind_set, para_env, "R")
604 CALL check_tol(roll_tol, iroll, 'RATTLE', veps=veps)
605 CALL timestop(handle)
606 END SUBROUTINE rattle_roll_control
607
608! **************************************************************************************************
609!> \brief ...
610!> \param dump_lm ...
611!> \param log_unit ...
612!> \param local_molecules ...
613!> \param molecule_set ...
614!> \param gci ...
615!> \param molecule_kind_set ...
616!> \param group ...
617!> \param id_type ...
618!> \par History
619!> Teodoro Laino [tlaino] 2007 - Dumps lagrange multipliers
620! **************************************************************************************************
621 SUBROUTINE dump_lagrange_mult(dump_lm, log_unit, local_molecules, molecule_set, gci, &
622 molecule_kind_set, group, id_type)
623 LOGICAL, INTENT(IN) :: dump_lm
624 INTEGER, INTENT(IN) :: log_unit
625 TYPE(distribution_1d_type), POINTER :: local_molecules
626 TYPE(molecule_type), POINTER :: molecule_set(:)
627 TYPE(global_constraint_type), POINTER :: gci
628 TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
629
630 CLASS(mp_comm_type), INTENT(IN) :: group
631 CHARACTER(LEN=1), INTENT(IN) :: id_type
632
633 CHARACTER(LEN=*), PARAMETER :: routinen = 'dump_lagrange_mult'
634
635 CHARACTER(LEN=default_string_length) :: label
636 INTEGER :: handle, i, ikind, imol, j, my_index, &
637 n3x3con, n4x6con, nconstraint, nkind
638 LOGICAL :: do_ext_constraint, do_int_constraint
639 REAL(kind=dp), DIMENSION(:), POINTER :: lagr
640 TYPE(colvar_counters) :: ncolv
641 TYPE(molecule_kind_type), POINTER :: molecule_kind
642 TYPE(molecule_type), POINTER :: molecule
643
644 CALL timeset(routinen, handle)
645 ! Total number of intramolecular constraints (distributed)
646 CALL get_molecule_kind_set(molecule_kind_set=molecule_kind_set, &
647 nconstraint=nconstraint)
648 do_int_constraint = (nconstraint > 0)
649 do_ext_constraint = (gci%ntot > 0)
650 IF (dump_lm .AND. (do_int_constraint .OR. do_ext_constraint)) THEN
651 nkind = SIZE(molecule_kind_set)
652 ALLOCATE (lagr(nconstraint))
653 lagr = 0.0_dp
654 ! Dump lagrange multipliers for Intramolecular Constraints
655 my_index = 0
656 IF (do_int_constraint) THEN
657 mol: DO ikind = 1, nkind
658 molecule_kind => molecule_kind_set(ikind)
659 CALL get_molecule_kind(molecule_kind, &
660 ncolv=ncolv, &
661 ng3x3=n3x3con, &
662 ng4x6=n4x6con)
663 DO imol = 1, molecule_kind%nmolecule
664 i = molecule_kind%molecule_list(imol)
665 IF (any(local_molecules%list(ikind)%array == i)) THEN
666 molecule => molecule_set(i)
667 ! Collective Variables
668 DO j = 1, ncolv%ntot
669 lagr(my_index + 1) = molecule%lci%lcolv(j)%lambda
670 my_index = my_index + 1
671 END DO
672 ! 3x3
673 DO j = 1, n3x3con
674 lagr(my_index + 1:my_index + 3) = molecule%lci%lg3x3(j)%lambda(:)
675 my_index = my_index + 3
676 END DO
677 ! 4x6
678 DO j = 1, n4x6con
679 lagr(my_index + 1:my_index + 6) = molecule%lci%lg4x6(j)%lambda(:)
680 my_index = my_index + 6
681 END DO
682 ELSE
683 my_index = my_index + ncolv%ntot + 3*n3x3con + 6*n4x6con
684 END IF
685 END DO
686 END DO mol
687 CALL group%sum(lagr)
688 END IF
689 ! Intermolecular constraints
690 IF (do_ext_constraint) THEN
691 CALL reallocate(lagr, 1, SIZE(lagr) + gci%ntot)
692 ! Collective Variables
693 DO j = 1, gci%ncolv%ntot
694 lagr(my_index + 1) = gci%lcolv(j)%lambda
695 my_index = my_index + 1
696 END DO
697 ! 3x3
698 DO j = 1, gci%ng3x3
699 lagr(my_index + 1:my_index + 3) = gci%lg3x3(j)%lambda(:)
700 my_index = my_index + 3
701 END DO
702 ! 4x6
703 DO j = 1, gci%ng4x6
704 lagr(my_index + 1:my_index + 6) = gci%lg4x6(j)%lambda(:)
705 my_index = my_index + 6
706 END DO
707 END IF
708 IF (log_unit > 0) THEN
709 IF (id_type == "S") THEN
710 label = "Shake Lagrangian Multipliers:"
711 ELSEIF (id_type == "R") THEN
712 label = "Rattle Lagrangian Multipliers:"
713 ELSE
714 cpabort("")
715 END IF
716 WRITE (log_unit, fmt='(A,T40,4F15.9)') trim(label), lagr(1:min(4, SIZE(lagr)))
717 DO j = 5, SIZE(lagr), 4
718 WRITE (log_unit, fmt='(T40,4F15.9)') lagr(j:min(j + 3, SIZE(lagr)))
719 END DO
720 END IF
721 DEALLOCATE (lagr)
722 END IF
723 CALL timestop(handle)
724
725 END SUBROUTINE dump_lagrange_mult
726
727! **************************************************************************************************
728!> \brief Dumps convergence info about shake - intramolecular constraint loop
729!> \param log_unit ...
730!> \param i ...
731!> \param ishake_int ...
732!> \param max_sigma ...
733!> \par History
734!> Teodoro Laino [tlaino] 2007 - University of Zurich
735! **************************************************************************************************
736 SUBROUTINE shake_int_info(log_unit, i, ishake_int, max_sigma)
737 INTEGER, INTENT(IN) :: log_unit, i, ishake_int
738 REAL(kind=dp), INTENT(IN) :: max_sigma
739
740 IF (log_unit > 0) THEN
741 ! Dump info if requested
742 WRITE (log_unit, '("SHAKE_INFO|",2X,2(A,I6),A,F15.9)') &
743 "Molecule Nr.:", i, " Nr. Iterations:", ishake_int, " Max. Err.:", max_sigma
744 END IF
745 ! Notify a not converged SHAKE
746 IF (ishake_int > max_shake_iter) &
747 CALL cp_warn(__location__, &
748 "Shake NOT converged in "//cp_to_string(max_shake_iter)//" iterations in the "// &
749 "intramolecular constraint loop for Molecule nr. "//cp_to_string(i)// &
750 ". CP2K continues but results could be meaningless. ")
751 END SUBROUTINE shake_int_info
752
753! **************************************************************************************************
754!> \brief Dumps convergence info about shake - intermolecular constraint loop
755!> \param log_unit ...
756!> \param ishake_ext ...
757!> \param max_sigma ...
758!> \par History
759!> Teodoro Laino [tlaino] 2007 - University of Zurich
760! **************************************************************************************************
761 SUBROUTINE shake_ext_info(log_unit, ishake_ext, max_sigma)
762 INTEGER, INTENT(IN) :: log_unit, ishake_ext
763 REAL(kind=dp), INTENT(IN) :: max_sigma
764
765 IF (log_unit > 0) THEN
766 ! Dump info if requested
767 WRITE (log_unit, '("SHAKE_INFO|",2X,A,I6,A,F15.9)') &
768 "External Shake Nr. Iterations:", ishake_ext, &
769 " Max. Err.:", max_sigma
770 END IF
771 ! Notify a not converged SHAKE
772 IF (ishake_ext > max_shake_iter) &
773 CALL cp_warn(__location__, &
774 "Shake NOT converged in "//cp_to_string(max_shake_iter)//" iterations in the "// &
775 "intermolecular constraint. CP2K continues but results could be meaningless.")
776 END SUBROUTINE shake_ext_info
777
778! **************************************************************************************************
779!> \brief Dumps convergence info about rattle - intramolecular constraint loop
780!> \param log_unit ...
781!> \param i ...
782!> \param irattle_int ...
783!> \param max_sigma ...
784!> \par History
785!> Teodoro Laino [tlaino] 2007 - University of Zurich
786! **************************************************************************************************
787 SUBROUTINE rattle_int_info(log_unit, i, irattle_int, max_sigma)
788 INTEGER, INTENT(IN) :: log_unit, i, irattle_int
789 REAL(kind=dp), INTENT(IN) :: max_sigma
790
791 IF (log_unit > 0) THEN
792 ! Dump info if requested
793 WRITE (log_unit, '("RATTLE_INFO|",1X,2(A,I6),A,F15.9)') &
794 "Molecule Nr.:", i, " Nr. Iterations:", irattle_int, " Max. Err.:", max_sigma
795 END IF
796 ! Notify a not converged RATTLE
797 IF (irattle_int > max_shake_iter) &
798 CALL cp_warn(__location__, &
799 "Rattle NOT converged in "//cp_to_string(max_shake_iter)//" iterations in the "// &
800 "intramolecular constraint loop for Molecule nr. "//cp_to_string(i)// &
801 ". CP2K continues but results could be meaningless.")
802 END SUBROUTINE rattle_int_info
803
804! **************************************************************************************************
805!> \brief Dumps convergence info about rattle - intermolecular constraint loop
806!> \param log_unit ...
807!> \param irattle_ext ...
808!> \param max_sigma ...
809!> \par History
810!> Teodoro Laino [tlaino] 2007 - University of Zurich
811! **************************************************************************************************
812 SUBROUTINE rattle_ext_info(log_unit, irattle_ext, max_sigma)
813 INTEGER, INTENT(IN) :: log_unit, irattle_ext
814 REAL(kind=dp), INTENT(IN) :: max_sigma
815
816 IF (log_unit > 0) THEN
817 ! Dump info if requested
818 WRITE (log_unit, '("RATTLE_INFO|",1X,A,I6,A,F15.9)') &
819 "External Rattle Nr. Iterations:", irattle_ext, &
820 " Max. Err.:", max_sigma
821 END IF
822 ! Notify a not converged RATTLE
823 IF (irattle_ext > max_shake_iter) &
824 CALL cp_warn(__location__, &
825 "Rattle NOT converged in "//cp_to_string(max_shake_iter)//" iterations in the "// &
826 "intermolecular constraint. CP2K continues but results could be meaningless.")
827 END SUBROUTINE rattle_ext_info
828
829! **************************************************************************************************
830!> \brief Updates the TARGET of the COLLECTIVE constraints if the growth speed
831!> is different from zero.
832!> \param gci ...
833!> \param local_molecules ...
834!> \param molecule_set ...
835!> \param molecule_kind_set ...
836!> \param dt ...
837!> \param root_section ...
838!> \date 02.2008
839!> \author Teodoro Laino [tlaino] - University of Zurich
840! **************************************************************************************************
841 SUBROUTINE shake_update_targets(gci, local_molecules, molecule_set, &
842 molecule_kind_set, dt, root_section)
843
844 TYPE(global_constraint_type), POINTER :: gci
845 TYPE(distribution_1d_type), POINTER :: local_molecules
846 TYPE(molecule_type), POINTER :: molecule_set(:)
847 TYPE(molecule_kind_type), POINTER :: molecule_kind_set(:)
848 REAL(kind=dp), INTENT(in) :: dt
849 TYPE(section_vals_type), POINTER :: root_section
850
851 CHARACTER(LEN=*), PARAMETER :: routinen = 'shake_update_targets'
852
853 INTEGER :: handle, i, ikind, imol, nkind, &
854 nmol_per_kind
855 LOGICAL :: do_ext_constraint
856 TYPE(colvar_counters) :: ncolv
857 TYPE(molecule_kind_type), POINTER :: molecule_kind
858 TYPE(molecule_type), POINTER :: molecule
859 TYPE(section_vals_type), POINTER :: motion_section
860
861 CALL timeset(routinen, handle)
862 motion_section => section_vals_get_subs_vals(root_section, "MOTION")
863 nkind = SIZE(molecule_kind_set)
864 do_ext_constraint = (gci%ntot /= 0)
865 ! Intramolecular Constraints
866 mol: DO ikind = 1, nkind
867 nmol_per_kind = local_molecules%n_el(ikind)
868 DO imol = 1, nmol_per_kind
869 i = local_molecules%list(ikind)%array(imol)
870 molecule => molecule_set(i)
871 molecule_kind => molecule%molecule_kind
872 CALL get_molecule_kind(molecule_kind, ncolv=ncolv)
873
874 ! Updating TARGETS for Collective Variables only
875 IF (ncolv%ntot /= 0) CALL shake_update_colv_int(molecule, dt, motion_section)
876 END DO
877 END DO mol
878 ! Intermolecular constraints
879 IF (do_ext_constraint) THEN
880 ! Collective Variables
881 IF (gci%ncolv%ntot /= 0) CALL shake_update_colv_ext(gci, dt, motion_section)
882 END IF
883 CALL timestop(handle)
884 END SUBROUTINE shake_update_targets
885
886END MODULE constraint
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.
Handles all functions related to the CELL.
Definition cell_types.F:15
Initialize the collective variables types.
subroutine, public shake_3x3_ext(gci, particle_set, pos, vel, dt, ishake, max_sigma)
...
subroutine, public rattle_roll_3x3_ext(gci, particle_set, vel, r_rattle, dt, veps)
...
subroutine, public shake_roll_3x3_int(molecule, particle_set, pos, vel, r_shake, v_shake, dt, ishake, max_sigma)
...
subroutine, public rattle_3x3_int(molecule, particle_set, vel, dt)
...
subroutine, public shake_3x3_int(molecule, particle_set, pos, vel, dt, ishake, max_sigma)
...
subroutine, public rattle_3x3_ext(gci, particle_set, vel, dt)
...
subroutine, public shake_roll_3x3_ext(gci, particle_set, pos, vel, r_shake, v_shake, dt, ishake, max_sigma)
...
subroutine, public rattle_roll_3x3_int(molecule, particle_set, vel, r_rattle, dt, veps)
...
subroutine, public rattle_roll_4x6_int(molecule, particle_set, vel, r_rattle, dt, veps)
Intramolecular rattle_4x6_roll.
subroutine, public rattle_4x6_int(molecule, particle_set, vel, dt)
Intramolecular rattle_4x6.
subroutine, public shake_roll_4x6_ext(gci, particle_set, pos, vel, r_shake, dt, ishake, max_sigma)
Intramolecular shake_4x6_roll.
subroutine, public rattle_4x6_ext(gci, particle_set, vel, dt)
Intramolecular rattle_4x6.
subroutine, public shake_4x6_ext(gci, particle_set, pos, vel, dt, ishake, max_sigma)
Intramolecular shake_4x6.
subroutine, public shake_roll_4x6_int(molecule, particle_set, pos, vel, r_shake, dt, ishake, max_sigma)
Intramolecular shake_4x6_roll.
subroutine, public rattle_roll_4x6_ext(gci, particle_set, vel, r_rattle, dt, veps)
Intramolecular rattle_4x6_roll.
subroutine, public shake_4x6_int(molecule, particle_set, pos, vel, dt, ishake, max_sigma)
Intramolecular shake_4x6.
Module that handles the COLLECTIVE constraints.
subroutine, public shake_colv_int(molecule, particle_set, pos, vel, dt, ishake, cell, imass, max_sigma)
Intramolecular subroutine shake_colv algorithm for collective variables constraints updates the multi...
subroutine, public shake_roll_colv_int(molecule, particle_set, pos, vel, r_shake, v_shake, dt, ishake, cell, imass, max_sigma)
Intramolecular subroutine shake algorithm (box allowed to change) for collective variables constraint...
subroutine, public shake_update_colv_ext(gci, dt, motion_section)
Intermolecular subroutine for updating the TARGET value for collective constraints.
subroutine, public rattle_roll_colv_ext(gci, particle_set, vel, r_rattle, dt, irattle, veps, cell, imass, max_sigma)
Intermolecular subroutine rattle algorithm (box allowed to change) for collective variables constrain...
subroutine, public shake_colv_ext(gci, particle_set, pos, vel, dt, ishake, cell, imass, max_sigma)
Intermolecular subroutine shake_colv algorithm for collective variables constraints updates the multi...
subroutine, public rattle_roll_colv_int(molecule, particle_set, vel, r_rattle, dt, irattle, veps, cell, imass, max_sigma)
Intramolecular subroutine rattle algorithm (box allowed to change) for collective variables constrain...
subroutine, public rattle_colv_int(molecule, particle_set, vel, dt, irattle, cell, imass, max_sigma)
Intramolecular subroutine rattle algorithm for collective variables constraints updates the multiplie...
subroutine, public rattle_colv_ext(gci, particle_set, vel, dt, irattle, cell, imass, max_sigma)
Intermolecular subroutine rattle algorithm for collective variables constraints updates the multiplie...
subroutine, public shake_update_colv_int(molecule, dt, motion_section)
Intramolecular subroutine for updating the TARGET value of collective constraints.
subroutine, public shake_roll_colv_ext(gci, particle_set, pos, vel, r_shake, v_shake, dt, ishake, cell, imass, max_sigma)
Intermolecular subroutine shake algorithm (box allowed to change) for collective variables constraint...
Contains routines useful for the application of constraints during MD.
subroutine, public get_roll_matrix(char, r_shake, v_shake, vector_r, vector_v, u)
...
subroutine, public restore_temporary_set(particle_set, local_particles, pos, vel)
...
subroutine, public update_temporary_set(group, pos, vel)
...
subroutine, public check_tol(roll_tol, iroll, char, matrix, veps)
...
Routines to handle the virtual site constraint/restraint.
subroutine, public shake_vsite_ext(gci, pos)
Intramolecular virtual site.
subroutine, public shake_vsite_int(molecule, pos)
Intramolecular virtual site.
subroutine, public rattle_control(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, vel, dt, rattle_tol, log_unit, lagrange_mult, dump_lm, cell, group, local_particles)
...
Definition constraint.F:229
subroutine, public rattle_roll_control(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, vel, dt, simpar, vector, veps, roll_tol, iroll, para_env, u, cell, local_particles)
...
Definition constraint.F:493
subroutine, public shake_control(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, pos, vel, dt, shake_tol, log_unit, lagrange_mult, dump_lm, cell, group, local_particles)
...
Definition constraint.F:101
subroutine, public shake_roll_control(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, pos, vel, dt, simpar, roll_tol, iroll, vector_r, vector_v, group, u, cell, local_particles)
...
Definition constraint.F:348
subroutine, public shake_update_targets(gci, local_molecules, molecule_set, molecule_kind_set, dt, root_section)
Updates the TARGET of the COLLECTIVE constraints if the growth speed is different from zero.
Definition constraint.F:843
various routines to log and control the output. The idea is that decisions about where to log should ...
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public npt_i_ensemble
integer, parameter, public npt_ia_ensemble
integer, parameter, public npt_f_ensemble
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
Utility routines for the memory handling.
Interface to the message passing library MPI.
Define the molecule kind structure types and the corresponding functionality.
subroutine, public get_molecule_kind(molecule_kind, atom_list, bond_list, bend_list, ub_list, impr_list, opbend_list, colv_list, fixd_list, g3x3_list, g4x6_list, vsite_list, torsion_list, shell_list, name, mass, charge, kind_number, natom, nbend, nbond, nub, nimpr, nopbend, nconstraint, nconstraint_fixd, nfixd, ncolv, ng3x3, ng4x6, nvsite, nfixd_restraint, ng3x3_restraint, ng4x6_restraint, nvsite_restraint, nrestraints, nmolecule, nsgf, nshell, ntorsion, molecule_list, nelectron, nelectron_alpha, nelectron_beta, bond_kind_set, bend_kind_set, ub_kind_set, impr_kind_set, opbend_kind_set, torsion_kind_set, molname_generated)
Get informations about a molecule kind.
subroutine, public get_molecule_kind_set(molecule_kind_set, maxatom, natom, nbond, nbend, nub, ntorsion, nimpr, nopbend, nconstraint, nconstraint_fixd, nmolecule, nrestraints)
Get informations about a molecule kind set.
Define the data structure for the molecule information.
Define the data structure for the particle information.
Type for storing MD parameters.
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:55
structure to store local (to a processor) ordered lists of integers.
stores all the informations relevant to an mpi environment
Simulation parameter type for molecular dynamics.