51#include "./base/base_uses.f90"
57 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'restraint'
70 CHARACTER(LEN=*),
PARAMETER :: routinen =
'restraint_control'
72 INTEGER :: handle, i, ifixd, ii, ikind, imol, &
73 iparticle, n3x3con_restraint, &
74 n4x6con_restraint, n_restraint, nkind, &
76 REAL(kind=
dp) :: energy_3x3, energy_4x6, energy_colv, &
77 energy_fixd, extended_energies, k0, &
79 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: force
94 NULLIFY (cell, subsys, local_molecules, local_particles, fixd_list, molecule_kinds, &
95 molecules, molecule_kind, molecule_kind_set, molecule, molecule_set, particles, &
96 particle_set, gci, lfixd_list)
97 CALL timeset(routinen, handle)
98 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
104 CALL cp_subsys_get(subsys=subsys, particles=particles, molecules=molecules, &
105 local_particles=local_particles, local_molecules=local_molecules, &
106 gci=gci, molecule_kinds=molecule_kinds)
108 nkind = molecule_kinds%n_els
109 particle_set => particles%els
110 molecule_set => molecules%els
111 molecule_kind_set => molecule_kinds%els
114 ALLOCATE (force(3,
SIZE(particle_set)))
120 DO ifixd = 1,
SIZE(lfixd_list)
121 ikind = lfixd_list(ifixd)%ikind
122 ii = lfixd_list(ifixd)%ifixd_index
123 molecule_kind => molecule_kind_set(ikind)
125 IF (fixd_list(ii)%restraint%active)
THEN
126 n_restraint = n_restraint + 1
127 iparticle = fixd_list(ii)%fixd
128 k0 = fixd_list(ii)%restraint%k0
129 targ = fixd_list(ii)%coord
131 SELECT CASE (fixd_list(ii)%itype)
133 rab(1) = particle_set(iparticle)%r(1) - targ(1)
135 rab(2) = particle_set(iparticle)%r(2) - targ(2)
137 rab(3) = particle_set(iparticle)%r(3) - targ(3)
139 rab(1) = particle_set(iparticle)%r(1) - targ(1)
140 rab(2) = particle_set(iparticle)%r(2) - targ(2)
142 rab(1) = particle_set(iparticle)%r(1) - targ(1)
143 rab(3) = particle_set(iparticle)%r(3) - targ(3)
145 rab(2) = particle_set(iparticle)%r(2) - targ(2)
146 rab(3) = particle_set(iparticle)%r(3) - targ(3)
148 rab = particle_set(iparticle)%r - targ
150 rab2 = dot_product(rab, rab)
152 energy_fixd = energy_fixd + k0*rab2
154 force(:, iparticle) = force(:, iparticle) - 2.0_dp*k0*rab
160 mol:
DO ikind = 1, nkind
161 molecule_kind => molecule_kind_set(ikind)
162 nmol_per_kind = local_molecules%n_el(ikind)
163 DO imol = 1, nmol_per_kind
164 i = local_molecules%list(ikind)%array(imol)
165 molecule => molecule_set(i)
166 molecule_kind => molecule%molecule_kind
170 ng3x3_restraint=n3x3con_restraint, &
171 ng4x6_restraint=n4x6con_restraint)
173 IF (n3x3con_restraint /= 0)
THEN
174 n_restraint = n_restraint + n3x3con_restraint
175 CALL restraint_3x3_int(molecule, particle_set, energy_3x3, force)
178 IF (n4x6con_restraint /= 0)
THEN
179 n_restraint = n_restraint + n4x6con_restraint
180 CALL restraint_4x6_int(molecule, particle_set, energy_4x6, force)
183 IF (ncolv%nrestraint /= 0)
THEN
184 n_restraint = n_restraint + ncolv%nrestraint
185 CALL restraint_colv_int(molecule, particle_set, cell, energy_colv, force)
189 CALL force_env%para_env%sum(n_restraint)
190 IF (n_restraint > 0)
THEN
191 CALL force_env%para_env%sum(energy_fixd)
192 CALL force_env%para_env%sum(energy_3x3)
193 CALL force_env%para_env%sum(energy_4x6)
194 CALL force_env%para_env%sum(energy_colv)
200 IF (
ASSOCIATED(gci))
THEN
201 IF (gci%nrestraint > 0)
THEN
203 IF (gci%ng3x3_restraint /= 0)
THEN
204 n_restraint = n_restraint + gci%ng3x3_restraint
205 CALL restraint_3x3_ext(gci, particle_set, energy_3x3, force)
208 IF (gci%ng4x6_restraint /= 0)
THEN
209 n_restraint = n_restraint + gci%ng4x6_restraint
210 CALL restraint_4x6_ext(gci, particle_set, energy_4x6, force)
213 IF (gci%ncolv%nrestraint /= 0)
THEN
214 n_restraint = n_restraint + gci%ncolv%nrestraint
215 CALL restraint_colv_ext(gci, particle_set, cell, energy_colv, force)
217 DO iparticle = 1,
SIZE(particle_set)
218 particle_set(iparticle)%f = particle_set(iparticle)%f + force(:, iparticle)
225 CALL force_env_get(force_env=force_env, additional_potential=extended_energies)
226 extended_energies = extended_energies + energy_3x3 + &
230 CALL force_env_set(force_env=force_env, additional_potential=extended_energies)
231 CALL timestop(handle)
243 SUBROUTINE restraint_3x3_int(molecule, particle_set, energy, force)
247 REAL(kind=
dp),
INTENT(INOUT) :: energy
248 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
250 INTEGER :: first_atom, ng3x3
255 molecule_kind => molecule%molecule_kind
259 CALL restraint_3x3_low(ng3x3, g3x3_list, fixd_list, first_atom, particle_set, &
262 END SUBROUTINE restraint_3x3_int
272 SUBROUTINE restraint_4x6_int(molecule, particle_set, energy, force)
276 REAL(kind=
dp),
INTENT(INOUT) :: energy
277 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
279 INTEGER :: first_atom, ng4x6
284 molecule_kind => molecule%molecule_kind
288 CALL restraint_4x6_low(ng4x6, g4x6_list, fixd_list, first_atom, particle_set, &
291 END SUBROUTINE restraint_4x6_int
302 SUBROUTINE restraint_colv_int(molecule, particle_set, cell, energy, force)
307 REAL(kind=
dp),
INTENT(INOUT) :: energy
308 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
317 molecule_kind => molecule%molecule_kind
320 CALL restraint_colv_low(colv_list, fixd_list, lcolv, particle_set, &
323 END SUBROUTINE restraint_colv_int
333 SUBROUTINE restraint_3x3_ext(gci, particle_set, energy, force)
337 REAL(kind=
dp),
INTENT(INOUT) :: energy
338 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
340 INTEGER :: first_atom, ng3x3
346 g3x3_list => gci%g3x3_list
347 fixd_list => gci%fixd_list
348 CALL restraint_3x3_low(ng3x3, g3x3_list, fixd_list, first_atom, particle_set, &
351 END SUBROUTINE restraint_3x3_ext
361 SUBROUTINE restraint_4x6_ext(gci, particle_set, energy, force)
365 REAL(kind=
dp),
INTENT(INOUT) :: energy
366 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
368 INTEGER :: first_atom, ng4x6
374 g4x6_list => gci%g4x6_list
375 fixd_list => gci%fixd_list
376 CALL restraint_4x6_low(ng4x6, g4x6_list, fixd_list, first_atom, particle_set, &
379 END SUBROUTINE restraint_4x6_ext
390 SUBROUTINE restraint_colv_ext(gci, particle_set, cell, energy, force)
395 REAL(kind=
dp),
INTENT(INOUT) :: energy
396 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
402 colv_list => gci%colv_list
403 fixd_list => gci%fixd_list
405 CALL restraint_colv_low(colv_list, fixd_list, lcolv, particle_set, &
408 END SUBROUTINE restraint_colv_ext
421 SUBROUTINE restraint_3x3_low(ng3x3, g3x3_list, fixd_list, first_atom, &
422 particle_set, energy, force)
427 INTEGER,
INTENT(IN) :: first_atom
429 REAL(kind=
dp),
INTENT(INOUT) :: energy
430 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
432 INTEGER :: iconst, index_a, index_b, index_c
433 REAL(kind=
dp) :: k, rab, rac, rbc, tab, tac, tbc
434 REAL(kind=
dp),
DIMENSION(3) :: r0_12, r0_13, r0_23
437 IF (.NOT. g3x3_list(iconst)%restraint%active) cycle
438 index_a = g3x3_list(iconst)%a + first_atom - 1
439 index_b = g3x3_list(iconst)%b + first_atom - 1
440 index_c = g3x3_list(iconst)%c + first_atom - 1
441 r0_12(:) = particle_set(index_a)%r - particle_set(index_b)%r
442 r0_13(:) = particle_set(index_a)%r - particle_set(index_c)%r
443 r0_23(:) = particle_set(index_b)%r - particle_set(index_c)%r
445 rab = sqrt(dot_product(r0_12, r0_12))
446 rac = sqrt(dot_product(r0_13, r0_13))
447 rbc = sqrt(dot_product(r0_23, r0_23))
448 tab = rab - g3x3_list(ng3x3)%dab
449 tac = rac - g3x3_list(ng3x3)%dac
450 tbc = rbc - g3x3_list(ng3x3)%dbc
451 k = g3x3_list(iconst)%restraint%k0
453 energy = energy + k*(tab**2 + tac**2 + tbc**2)
455 force(:, index_a) = force(:, index_a) - 2.0_dp*k*(r0_12/rab*tab + r0_13/rac*tac)
456 force(:, index_b) = force(:, index_b) - 2.0_dp*k*(-r0_12/rab*tab + r0_23/rbc*tbc)
457 force(:, index_c) = force(:, index_c) - 2.0_dp*k*(-r0_13/rac*tac - r0_23/rbc*tbc)
459 IF (
ASSOCIATED(fixd_list))
THEN
460 IF (
SIZE(fixd_list) > 0)
THEN
461 IF (any(fixd_list(:)%fixd == index_a)) force(:, index_a) = 0.0_dp
462 IF (any(fixd_list(:)%fixd == index_b)) force(:, index_b) = 0.0_dp
463 IF (any(fixd_list(:)%fixd == index_c)) force(:, index_c) = 0.0_dp
468 END SUBROUTINE restraint_3x3_low
481 SUBROUTINE restraint_4x6_low(ng4x6, g4x6_list, fixd_list, first_atom, &
482 particle_set, energy, force)
487 INTEGER,
INTENT(IN) :: first_atom
489 REAL(kind=
dp),
INTENT(INOUT) :: energy
490 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
492 INTEGER :: iconst, index_a, index_b, index_c, &
494 REAL(kind=
dp) :: k, rab, rac, rad, rbc, rbd, rcd, tab, &
495 tac, tad, tbc, tbd, tcd
496 REAL(kind=
dp),
DIMENSION(3) :: r0_12, r0_13, r0_14, r0_23, r0_24, r0_34
499 IF (.NOT. g4x6_list(iconst)%restraint%active) cycle
500 index_a = g4x6_list(iconst)%a + first_atom - 1
501 index_b = g4x6_list(iconst)%b + first_atom - 1
502 index_c = g4x6_list(iconst)%c + first_atom - 1
503 index_d = g4x6_list(iconst)%d + first_atom - 1
504 r0_12(:) = particle_set(index_a)%r - particle_set(index_b)%r
505 r0_13(:) = particle_set(index_a)%r - particle_set(index_c)%r
506 r0_14(:) = particle_set(index_a)%r - particle_set(index_d)%r
507 r0_23(:) = particle_set(index_b)%r - particle_set(index_c)%r
508 r0_24(:) = particle_set(index_b)%r - particle_set(index_d)%r
509 r0_34(:) = particle_set(index_c)%r - particle_set(index_d)%r
511 rab = sqrt(dot_product(r0_12, r0_12))
512 rac = sqrt(dot_product(r0_13, r0_13))
513 rad = sqrt(dot_product(r0_14, r0_14))
514 rbc = sqrt(dot_product(r0_23, r0_23))
515 rbd = sqrt(dot_product(r0_24, r0_24))
516 rcd = sqrt(dot_product(r0_34, r0_34))
518 tab = rab - g4x6_list(ng4x6)%dab
519 tac = rac - g4x6_list(ng4x6)%dac
520 tad = rad - g4x6_list(ng4x6)%dad
521 tbc = rbc - g4x6_list(ng4x6)%dbc
522 tbd = rbd - g4x6_list(ng4x6)%dbd
523 tcd = rcd - g4x6_list(ng4x6)%dcd
525 k = g4x6_list(iconst)%restraint%k0
527 energy = energy + k*(tab**2 + tac**2 + tad**2 + tbc**2 + tbd**2 + tcd**2)
529 force(:, index_a) = force(:, index_a) - 2.0_dp*k*(r0_12/rab*tab + r0_13/rac*tac + r0_14/rad*tad)
530 force(:, index_b) = force(:, index_b) - 2.0_dp*k*(-r0_12/rab*tab + r0_23/rbc*tbc + r0_24/rbd*tbd)
531 force(:, index_c) = force(:, index_c) - 2.0_dp*k*(-r0_13/rac*tac - r0_23/rbc*tbc + r0_34/rcd*tcd)
532 force(:, index_d) = force(:, index_d) - 2.0_dp*k*(-r0_14/rad*tad - r0_24/rbd*tbd - r0_34/rcd*tcd)
534 IF (
ASSOCIATED(fixd_list))
THEN
535 IF (
SIZE(fixd_list) > 0)
THEN
536 IF (any(fixd_list(:)%fixd == index_a)) force(:, index_a) = 0.0_dp
537 IF (any(fixd_list(:)%fixd == index_b)) force(:, index_b) = 0.0_dp
538 IF (any(fixd_list(:)%fixd == index_c)) force(:, index_c) = 0.0_dp
539 IF (any(fixd_list(:)%fixd == index_d)) force(:, index_d) = 0.0_dp
544 END SUBROUTINE restraint_4x6_low
557 SUBROUTINE restraint_colv_low(colv_list, fixd_list, lcolv, &
558 particle_set, cell, energy, force)
565 REAL(kind=
dp),
INTENT(INOUT) :: energy
566 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: force
568 INTEGER :: iatm, iconst, ind
569 REAL(kind=
dp) :: k, tab, targ
571 DO iconst = 1,
SIZE(colv_list)
572 IF (.NOT. colv_list(iconst)%restraint%active) cycle
575 particles=particle_set, fixd_list=fixd_list)
577 k = colv_list(iconst)%restraint%k0
578 targ = colv_list(iconst)%expected_value
581 energy = energy + k*tab**2
583 DO iatm = 1,
SIZE(lcolv(iconst)%colvar%i_atom)
584 ind = lcolv(iconst)%colvar%i_atom(iatm)
585 force(:, ind) = force(:, ind) - 2.0_dp*k*tab*lcolv(iconst)%colvar%dsdr(:, iatm)
589 END SUBROUTINE restraint_colv_low
for(int lxp=0;lxp<=lp;lxp++)
Handles all functions related to the CELL.
integer, parameter, public use_perd_xyz
integer, parameter, public use_perd_y
integer, parameter, public use_perd_xz
integer, parameter, public use_perd_x
integer, parameter, public use_perd_z
integer, parameter, public use_perd_yz
integer, parameter, public use_perd_xy
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...
Initialize the collective variables types.
real(kind=dp) function, public diff_colvar(colvar, b)
subtract b from the ss value of a colvar: general function for handling periodic/non-periodic colvar
subroutine, public release_local_fixd_list(lfixd_list)
destroy the list of local atoms on which to apply constraints/restraints Teodoro Laino [tlaino] - 11....
subroutine, public create_local_fixd_list(lfixd_list, nkind, molecule_kind_set, local_particles)
setup a list of local atoms on which to apply constraints/restraints
types that represent a subsys, i.e. a part of the system
subroutine, public cp_subsys_get(subsys, ref_count, atomic_kinds, atomic_kind_set, particles, particle_set, local_particles, molecules, molecule_set, molecule_kinds, molecule_kind_set, local_molecules, para_env, colvar_p, shell_particles, core_particles, gci, multipoles, natom, nparticle, ncore, nshell, nkind, atprop, virial, results, cell)
returns information about various attributes of the given subsys
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Interface for the force calculations.
recursive subroutine, public force_env_get(force_env, in_use, fist_env, qs_env, meta_env, fp_env, subsys, para_env, potential_energy, additional_potential, kinetic_energy, harmonic_shell, kinetic_shell, cell, sub_force_env, qmmm_env, qmmmx_env, eip_env, pwdft_env, globenv, input, force_env_section, method_name_id, root_section, mixed_env, nnp_env, embed_env, ipi_env)
returns various attributes about the force environment
subroutine, public force_env_set(force_env, meta_env, fp_env, force_env_section, method_name_id, additional_potential)
changes some attributes of the force_env
Defines the basic variable types.
integer, parameter, public dp
represent a simple array based list of the given type
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.
represent a simple array based list of the given type
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.
represent a simple array based list of the given type
Define the data structure for the particle information.
subroutine, public update_particle_set(particle_set, int_group, pos, vel, for, add)
...
Handles all possible kinds of restraints in CP2K.
subroutine, public restraint_control(force_env)
Computes restraints.
Type defining parameters related to the simulation cell.
represents a system: atoms, molecules, their pos,vel,...
structure to store local (to a processor) ordered lists of integers.
wrapper to abstract the force evaluation of the various methods
represent a list of objects
represent a list of objects
represent a list of objects