34#include "./base/base_uses.f90"
46 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'constraint_util'
61 SUBROUTINE getold(gci, local_molecules, molecule_set, molecule_kind_set, &
71 INTEGER :: first_atom, i, ikind, imol, n3x3con, &
72 n4x6con, nkind, nmol_per_kind
85 nkind =
SIZE(molecule_kind_set)
87 mol:
DO ikind = 1, nkind
88 nmol_per_kind = local_molecules%n_el(ikind)
89 DO imol = 1, nmol_per_kind
90 i = local_molecules%list(ikind)%array(imol)
91 molecule => molecule_set(i)
92 molecule_kind => molecule%molecule_kind
94 colv_list=colv_list, g3x3_list=g3x3_list, g4x6_list=g4x6_list, &
97 IF (.NOT.
ASSOCIATED(lci)) cycle
99 lcolv=lcolv, lg3x3=lg3x3, lg4x6=lg4x6)
100 CALL getold_low(n3x3con, n4x6con, colv_list, g3x3_list, g4x6_list, fixd_list, &
101 lcolv, lg3x3, lg4x6, first_atom, particle_set, cell)
105 IF (gci%ntot > 0)
THEN
108 colv_list => gci%colv_list
109 g3x3_list => gci%g3x3_list
110 g4x6_list => gci%g4x6_list
111 fixd_list => gci%fixd_list
115 CALL getold_low(n3x3con, n4x6con, colv_list, g3x3_list, g4x6_list, fixd_list, &
116 lcolv, lg3x3, lg4x6, 1, particle_set, cell)
137 SUBROUTINE getold_low(n3x3con, n4x6con, colv_list, g3x3_list, g4x6_list, fixd_list, &
138 lcolv, lg3x3, lg4x6, first_atom, particle_set, cell)
140 INTEGER,
INTENT(IN) :: n3x3con, n4x6con
148 INTEGER,
INTENT(IN) :: first_atom
152 INTEGER :: iconst, index
154 IF (
ASSOCIATED(colv_list))
THEN
156 DO iconst = 1,
SIZE(colv_list)
158 particles=particle_set, fixd_list=fixd_list)
162 DO iconst = 1, n3x3con
163 index = g3x3_list(iconst)%a + first_atom - 1
164 lg3x3(iconst)%ra_old = particle_set(index)%r
165 index = g3x3_list(iconst)%b + first_atom - 1
166 lg3x3(iconst)%rb_old = particle_set(index)%r
167 index = g3x3_list(iconst)%c + first_atom - 1
168 lg3x3(iconst)%rc_old = particle_set(index)%r
171 DO iconst = 1, n4x6con
172 index = g4x6_list(iconst)%a + first_atom - 1
173 lg4x6(iconst)%ra_old = particle_set(index)%r
174 index = g4x6_list(iconst)%b + first_atom - 1
175 lg4x6(iconst)%rb_old = particle_set(index)%r
176 index = g4x6_list(iconst)%c + first_atom - 1
177 lg4x6(iconst)%rc_old = particle_set(index)%r
178 index = g4x6_list(iconst)%d + first_atom - 1
179 lg4x6(iconst)%rd_old = particle_set(index)%r
182 END SUBROUTINE getold_low
196 SUBROUTINE pv_constraint(gci, local_molecules, molecule_set, molecule_kind_set, &
197 particle_set, virial, group)
208 INTEGER :: first_atom, i, ikind, imol, ng3x3, &
209 ng4x6, nkind, nmol_per_kind
210 REAL(kind=
dp) :: pv(3, 3)
222 nkind =
SIZE(molecule_kind_set)
224 mol:
DO ikind = 1, nkind
225 nmol_per_kind = local_molecules%n_el(ikind)
226 DO imol = 1, nmol_per_kind
227 i = local_molecules%list(ikind)%array(imol)
228 molecule => molecule_set(i)
229 molecule_kind => molecule%molecule_kind
231 ng4x6=ng4x6, g3x3_list=g3x3_list, g4x6_list=g4x6_list, &
234 IF (.NOT.
ASSOCIATED(lci)) cycle
235 CALL get_molecule(molecule, first_atom=first_atom, lg3x3=lg3x3, &
236 lg4x6=lg4x6, lcolv=lcolv)
237 CALL pv_constraint_low(ng3x3, ng4x6, g3x3_list, g4x6_list, colv_list, &
238 first_atom, lg3x3, lg4x6, lcolv, particle_set, pv)
242 IF (gci%ntot > 0)
THEN
245 colv_list => gci%colv_list
246 g3x3_list => gci%g3x3_list
247 g4x6_list => gci%g4x6_list
251 CALL pv_constraint_low(ng3x3, ng4x6, g3x3_list, g4x6_list, colv_list, &
252 1, lg3x3, lg4x6, lcolv, particle_set, pv)
256 pv(1, 2) = 0.5_dp*(pv(1, 2) + pv(2, 1))
258 pv(1, 3) = 0.5_dp*(pv(1, 3) + pv(3, 1))
260 pv(3, 2) = 0.5_dp*(pv(3, 2) + pv(2, 3))
263 virial%pv_constraint = pv
283 SUBROUTINE pv_constraint_low(ng3x3, ng4x6, g3x3_list, g4x6_list, colv_list, &
284 first_atom, lg3x3, lg4x6, lcolv, particle_set, pv)
286 INTEGER,
INTENT(IN) :: ng3x3, ng4x6
290 INTEGER,
INTENT(IN) :: first_atom
295 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(INOUT) :: pv
297 INTEGER :: iconst, index_a, index_b, index_c, &
299 REAL(kind=
dp) :: fc1(3), fc2(3), fc3(3), fc4(3), &
300 lambda_3x3(3), lambda_4x6(6)
302 IF (
ASSOCIATED(colv_list))
THEN
304 DO iconst = 1,
SIZE(colv_list)
305 CALL pv_colv_eval(pv, lcolv(iconst), particle_set)
311 lambda_3x3 = lg3x3(iconst)%lambda
313 fc1 = lambda_3x3(1)*lg3x3(iconst)%fa + &
314 lambda_3x3(2)*lg3x3(iconst)%fb
315 fc2 = -lambda_3x3(1)*lg3x3(iconst)%fa + &
316 lambda_3x3(3)*lg3x3(iconst)%fc
317 fc3 = -lambda_3x3(2)*lg3x3(iconst)%fb - &
318 lambda_3x3(3)*lg3x3(iconst)%fc
319 index_a = g3x3_list(iconst)%a + first_atom - 1
320 index_b = g3x3_list(iconst)%b + first_atom - 1
321 index_c = g3x3_list(iconst)%c + first_atom - 1
324 pv(1, 1) = pv(1, 1) + fc1(1)*particle_set(index_a)%r(1)
325 pv(1, 1) = pv(1, 1) + fc2(1)*particle_set(index_b)%r(1)
326 pv(1, 1) = pv(1, 1) + fc3(1)*particle_set(index_c)%r(1)
328 pv(1, 2) = pv(1, 2) + fc1(1)*particle_set(index_a)%r(2)
329 pv(1, 2) = pv(1, 2) + fc2(1)*particle_set(index_b)%r(2)
330 pv(1, 2) = pv(1, 2) + fc3(1)*particle_set(index_c)%r(2)
332 pv(1, 3) = pv(1, 3) + fc1(1)*particle_set(index_a)%r(3)
333 pv(1, 3) = pv(1, 3) + fc2(1)*particle_set(index_b)%r(3)
334 pv(1, 3) = pv(1, 3) + fc3(1)*particle_set(index_c)%r(3)
336 pv(2, 1) = pv(2, 1) + fc1(2)*particle_set(index_a)%r(1)
337 pv(2, 1) = pv(2, 1) + fc2(2)*particle_set(index_b)%r(1)
338 pv(2, 1) = pv(2, 1) + fc3(2)*particle_set(index_c)%r(1)
340 pv(2, 2) = pv(2, 2) + fc1(2)*particle_set(index_a)%r(2)
341 pv(2, 2) = pv(2, 2) + fc2(2)*particle_set(index_b)%r(2)
342 pv(2, 2) = pv(2, 2) + fc3(2)*particle_set(index_c)%r(2)
344 pv(2, 3) = pv(2, 3) + fc1(2)*particle_set(index_a)%r(3)
345 pv(2, 3) = pv(2, 3) + fc2(2)*particle_set(index_b)%r(3)
346 pv(2, 3) = pv(2, 3) + fc3(2)*particle_set(index_c)%r(3)
348 pv(3, 1) = pv(3, 1) + fc1(3)*particle_set(index_a)%r(1)
349 pv(3, 1) = pv(3, 1) + fc2(3)*particle_set(index_b)%r(1)
350 pv(3, 1) = pv(3, 1) + fc3(3)*particle_set(index_c)%r(1)
352 pv(3, 2) = pv(3, 2) + fc1(3)*particle_set(index_a)%r(2)
353 pv(3, 2) = pv(3, 2) + fc2(3)*particle_set(index_b)%r(2)
354 pv(3, 2) = pv(3, 2) + fc3(3)*particle_set(index_c)%r(2)
356 pv(3, 3) = pv(3, 3) + fc1(3)*particle_set(index_a)%r(3)
357 pv(3, 3) = pv(3, 3) + fc2(3)*particle_set(index_b)%r(3)
358 pv(3, 3) = pv(3, 3) + fc3(3)*particle_set(index_c)%r(3)
364 lambda_4x6 = lg4x6(iconst)%lambda
366 fc1 = lambda_4x6(1)*lg4x6(iconst)%fa + &
367 lambda_4x6(2)*lg4x6(iconst)%fb + &
368 lambda_4x6(3)*lg4x6(iconst)%fc
369 fc2 = -lambda_4x6(1)*lg4x6(iconst)%fa + &
370 lambda_4x6(4)*lg4x6(iconst)%fd + &
371 lambda_4x6(5)*lg4x6(iconst)%fe
372 fc3 = -lambda_4x6(2)*lg4x6(iconst)%fb - &
373 lambda_4x6(4)*lg4x6(iconst)%fd + &
374 lambda_4x6(6)*lg4x6(iconst)%ff
375 fc4 = -lambda_4x6(3)*lg4x6(iconst)%fc - &
376 lambda_4x6(5)*lg4x6(iconst)%fe - &
377 lambda_4x6(6)*lg4x6(iconst)%ff
378 index_a = g4x6_list(iconst)%a + first_atom - 1
379 index_b = g4x6_list(iconst)%b + first_atom - 1
380 index_c = g4x6_list(iconst)%c + first_atom - 1
381 index_d = g4x6_list(iconst)%d + first_atom - 1
384 pv(1, 1) = pv(1, 1) + fc1(1)*particle_set(index_a)%r(1)
385 pv(1, 1) = pv(1, 1) + fc2(1)*particle_set(index_b)%r(1)
386 pv(1, 1) = pv(1, 1) + fc3(1)*particle_set(index_c)%r(1)
387 pv(1, 1) = pv(1, 1) + fc4(1)*particle_set(index_d)%r(1)
389 pv(1, 2) = pv(1, 2) + fc1(1)*particle_set(index_a)%r(2)
390 pv(1, 2) = pv(1, 2) + fc2(1)*particle_set(index_b)%r(2)
391 pv(1, 2) = pv(1, 2) + fc3(1)*particle_set(index_c)%r(2)
392 pv(1, 2) = pv(1, 2) + fc4(1)*particle_set(index_d)%r(2)
394 pv(1, 3) = pv(1, 3) + fc1(1)*particle_set(index_a)%r(3)
395 pv(1, 3) = pv(1, 3) + fc2(1)*particle_set(index_b)%r(3)
396 pv(1, 3) = pv(1, 3) + fc3(1)*particle_set(index_c)%r(3)
397 pv(1, 3) = pv(1, 3) + fc4(1)*particle_set(index_d)%r(3)
399 pv(2, 1) = pv(2, 1) + fc1(2)*particle_set(index_a)%r(1)
400 pv(2, 1) = pv(2, 1) + fc2(2)*particle_set(index_b)%r(1)
401 pv(2, 1) = pv(2, 1) + fc3(2)*particle_set(index_c)%r(1)
402 pv(2, 1) = pv(2, 1) + fc4(2)*particle_set(index_d)%r(1)
404 pv(2, 2) = pv(2, 2) + fc1(2)*particle_set(index_a)%r(2)
405 pv(2, 2) = pv(2, 2) + fc2(2)*particle_set(index_b)%r(2)
406 pv(2, 2) = pv(2, 2) + fc3(2)*particle_set(index_c)%r(2)
407 pv(2, 2) = pv(2, 2) + fc4(2)*particle_set(index_d)%r(2)
409 pv(2, 3) = pv(2, 3) + fc1(2)*particle_set(index_a)%r(3)
410 pv(2, 3) = pv(2, 3) + fc2(2)*particle_set(index_b)%r(3)
411 pv(2, 3) = pv(2, 3) + fc3(2)*particle_set(index_c)%r(3)
412 pv(2, 3) = pv(2, 3) + fc4(2)*particle_set(index_d)%r(3)
414 pv(3, 1) = pv(3, 1) + fc1(3)*particle_set(index_a)%r(1)
415 pv(3, 1) = pv(3, 1) + fc2(3)*particle_set(index_b)%r(1)
416 pv(3, 1) = pv(3, 1) + fc3(3)*particle_set(index_c)%r(1)
417 pv(3, 1) = pv(3, 1) + fc4(3)*particle_set(index_d)%r(1)
419 pv(3, 2) = pv(3, 2) + fc1(3)*particle_set(index_a)%r(2)
420 pv(3, 2) = pv(3, 2) + fc2(3)*particle_set(index_b)%r(2)
421 pv(3, 2) = pv(3, 2) + fc3(3)*particle_set(index_c)%r(2)
422 pv(3, 2) = pv(3, 2) + fc4(3)*particle_set(index_d)%r(2)
424 pv(3, 3) = pv(3, 3) + fc1(3)*particle_set(index_a)%r(3)
425 pv(3, 3) = pv(3, 3) + fc2(3)*particle_set(index_b)%r(3)
426 pv(3, 3) = pv(3, 3) + fc3(3)*particle_set(index_c)%r(3)
427 pv(3, 3) = pv(3, 3) + fc4(3)*particle_set(index_d)%r(3)
430 END SUBROUTINE pv_constraint_low
440 SUBROUTINE pv_colv_eval(pv, lcolv, particle_set)
441 REAL(kind=
dp),
DIMENSION(3, 3),
INTENT(INOUT) :: pv
445 INTEGER :: i, iatm, ind, j
446 REAL(kind=
dp) :: lambda, tmp
447 REAL(kind=
dp),
DIMENSION(3) :: f
449 DO iatm = 1,
SIZE(lcolv%colvar_old%i_atom)
450 ind = lcolv%colvar_old%i_atom(iatm)
451 f = -lcolv%colvar_old%dsdr(:, iatm)
453 lambda = lcolv%lambda
455 tmp = lambda*particle_set(ind)%r(i)
457 pv(j, i) = pv(j, i) + f(j)*tmp
462 END SUBROUTINE pv_colv_eval
474 SUBROUTINE check_tol(roll_tol, iroll, char, matrix, veps)
476 REAL(kind=
dp),
INTENT(OUT) :: roll_tol
477 INTEGER,
INTENT(INOUT) :: iroll
478 CHARACTER(LEN=*),
INTENT(IN) :: char
479 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
480 OPTIONAL :: matrix, veps
482 REAL(kind=
dp) :: local_tol
483 REAL(kind=
dp),
DIMENSION(3, 3) :: diff_rattle, diff_shake
484 REAL(kind=
dp),
DIMENSION(3, 3),
SAVE :: matrix_old, veps_old
493 diff_shake = abs(matrix_old - matrix)
494 local_tol = maxval(diff_shake)
495 roll_tol = max(roll_tol, local_tol)
502 roll_tol = -1.e+10_dp
506 diff_rattle = abs(veps - veps_old)
507 local_tol = maxval(diff_rattle)
508 roll_tol = max(roll_tol, local_tol)
529 CHARACTER(len=*),
INTENT(IN) :: char
530 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(OUT), &
531 OPTIONAL :: r_shake, v_shake
532 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN),
OPTIONAL :: vector_r, vector_v
533 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(IN), &
537 REAL(kind=
dp),
DIMENSION(3, 3) :: diag
539 IF (
PRESENT(r_shake)) r_shake = 0.0_dp
540 IF (
PRESENT(v_shake)) v_shake = 0.0_dp
545 IF (
PRESENT(u) .AND.
PRESENT(vector_v) .AND. &
546 PRESENT(vector_r))
THEN
547 diag(1, 1) = vector_r(1)
548 diag(2, 2) = vector_r(2)
549 diag(3, 3) = vector_r(3)
550 r_shake = matmul(matmul(u, diag), transpose(u))
551 diag(1, 1) = vector_v(1)
552 diag(2, 2) = vector_v(2)
553 diag(3, 3) = vector_v(3)
554 v_shake = matmul(matmul(u, diag), transpose(u))
555 diag = matmul(r_shake, v_shake)
557 ELSEIF (.NOT.
PRESENT(u) .AND.
PRESENT(vector_v) .AND. &
558 PRESENT(vector_r))
THEN
560 r_shake(i, i) = vector_r(i)*vector_v(i)
561 v_shake(i, i) = vector_v(i)
564 cpabort(
"Not sufficient parameters")
567 IF (
PRESENT(u) .AND.
PRESENT(vector_v))
THEN
568 diag(1, 1) = vector_v(1)
569 diag(2, 2) = vector_v(2)
570 diag(3, 3) = vector_v(3)
571 v_shake = matmul(matmul(u, diag), transpose(u))
572 ELSEIF (.NOT.
PRESENT(u) .AND.
PRESENT(vector_v))
THEN
574 v_shake(i, i) = vector_v(i)
577 cpabort(
"Not sufficient parameters")
595 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT), &
598 INTEGER :: iparticle, iparticle_kind, &
599 iparticle_local, nparticle_local
600 LOGICAL,
ALLOCATABLE,
DIMENSION(:) :: wrk
602 ALLOCATE (wrk(
SIZE(particle_set)))
604 DO iparticle_kind = 1,
SIZE(local_particles%n_el)
605 nparticle_local = local_particles%n_el(iparticle_kind)
606 DO iparticle_local = 1, nparticle_local
607 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
608 wrk(iparticle) = .false.
611 IF (
PRESENT(vel))
THEN
612 DO iparticle = 1,
SIZE(particle_set)
613 IF (wrk(iparticle))
THEN
614 vel(:, iparticle) = 0.0_dp
618 IF (
PRESENT(pos))
THEN
619 DO iparticle = 1,
SIZE(particle_set)
620 IF (wrk(iparticle))
THEN
621 pos(:, iparticle) = 0.0_dp
638 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT), &
641 IF (
PRESENT(pos))
THEN
644 IF (
PRESENT(vel))
THEN
Handles all functions related to the CELL.
defines collective variables s({R}) and the derivative of this variable wrt R these can then be used ...
subroutine, public colvar_eval_mol_f(colvar, cell, particles, pos, fixd_list)
evaluates the derivatives (dsdr) given and due to the given colvar variables in a molecular environme...
Contains routines useful for the application of constraints during MD.
subroutine, public pv_constraint(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, virial, group)
...
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 getold(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, cell)
saves all of the old variables
subroutine, public check_tol(roll_tol, iroll, char, matrix, veps)
...
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Defines the basic variable types.
integer, parameter, public dp
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.
Define the data structure for the molecule information.
subroutine, public get_molecule(molecule, molecule_kind, lmi, lci, lg3x3, lg4x6, lcolv, first_atom, last_atom, first_shell, last_shell)
Get components from a molecule data set.
Define the data structure for the particle information.
Type defining parameters related to the simulation cell.
structure to store local (to a processor) ordered lists of integers.