38#include "./base/base_uses.f90"
44 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'force_env_utils'
70 SUBROUTINE force_env_shake(force_env, dt, shake_tol, log_unit, lagrange_mult, dump_lm, &
71 pos, vel, compold, reset)
74 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: dt
75 REAL(kind=
dp),
INTENT(IN) :: shake_tol
76 INTEGER,
INTENT(in),
OPTIONAL :: log_unit, lagrange_mult
77 LOGICAL,
INTENT(IN),
OPTIONAL :: dump_lm
78 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT), &
79 OPTIONAL,
TARGET :: pos, vel
80 LOGICAL,
INTENT(IN),
OPTIONAL :: compold, reset
82 CHARACTER(len=*),
PARAMETER :: routinen =
'force_env_shake'
84 INTEGER :: handle, i, iparticle, iparticle_kind, iparticle_local, j, my_lagrange_mult, &
85 my_log_unit, nparticle_kind, nparticle_local
86 LOGICAL :: has_pos, has_vel, my_dump_lm
88 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: my_pos, my_vel
98 CALL timeset(routinen, handle)
99 cpassert(
ASSOCIATED(force_env))
100 cpassert(force_env%ref_count > 0)
102 IF (
PRESENT(log_unit)) my_log_unit = log_unit
103 my_lagrange_mult = -1
104 IF (
PRESENT(lagrange_mult)) my_lagrange_mult = lagrange_mult
106 IF (
PRESENT(dump_lm)) my_dump_lm = dump_lm
107 NULLIFY (subsys, cell, molecules, molecule_kinds, local_molecules, particles, &
109 IF (
PRESENT(pos)) my_pos => pos
110 IF (
PRESENT(vel)) my_vel => vel
112 IF (
PRESENT(dt)) mydt = dt
115 atomic_kinds=atomic_kinds, &
116 local_molecules=local_molecules, &
117 local_particles=local_particles, &
118 molecules=molecules, &
119 molecule_kinds=molecule_kinds, &
120 particles=particles, &
122 nparticle_kind = atomic_kinds%n_els
123 IF (
PRESENT(compold))
THEN
125 CALL getold(gci, local_molecules, molecules%els, molecule_kinds%els, &
130 IF (.NOT.
ASSOCIATED(my_pos))
THEN
132 ALLOCATE (my_pos(3, particles%n_els))
134 DO iparticle_kind = 1, nparticle_kind
135 nparticle_local = local_particles%n_el(iparticle_kind)
136 DO iparticle_local = 1, nparticle_local
137 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
138 my_pos(:, iparticle) = particles%els(iparticle)%r(:)
143 IF (.NOT.
ASSOCIATED(my_vel))
THEN
145 ALLOCATE (my_vel(3, particles%n_els))
147 DO iparticle_kind = 1, nparticle_kind
148 nparticle_local = local_particles%n_el(iparticle_kind)
149 DO iparticle_local = 1, nparticle_local
150 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
151 my_vel(:, iparticle) = particles%els(iparticle)%v(:)
156 CALL shake_control(gci=gci, local_molecules=local_molecules, &
157 molecule_set=molecules%els, molecule_kind_set=molecule_kinds%els, &
158 particle_set=particles%els, pos=my_pos, vel=my_vel, dt=mydt, &
159 shake_tol=shake_tol, log_unit=my_log_unit, lagrange_mult=my_lagrange_mult, &
160 dump_lm=my_dump_lm, cell=cell, group=force_env%para_env, &
161 local_particles=local_particles)
164 IF (
PRESENT(reset))
THEN
167 DO i = 1,
SIZE(molecules%els)
168 IF (
ASSOCIATED(molecules%els(i)%lci%lcolv))
THEN
169 DO j = 1,
SIZE(molecules%els(i)%lci%lcolv)
171 molecules%els(i)%lci%lcolv(j)%lambda = 0.0_dp
174 IF (
ASSOCIATED(molecules%els(i)%lci%lg3x3))
THEN
175 DO j = 1,
SIZE(molecules%els(i)%lci%lg3x3)
177 molecules%els(i)%lci%lg3x3(j)%lambda = 0.0_dp
180 IF (
ASSOCIATED(molecules%els(i)%lci%lg4x6))
THEN
181 DO j = 1,
SIZE(molecules%els(i)%lci%lg4x6)
183 molecules%els(i)%lci%lg4x6(j)%lambda = 0.0_dp
188 IF (
ASSOCIATED(gci))
THEN
189 IF (
ASSOCIATED(gci%lcolv))
THEN
190 DO j = 1,
SIZE(gci%lcolv)
192 gci%lcolv(j)%lambda = 0.0_dp
195 IF (
ASSOCIATED(gci%lg3x3))
THEN
196 DO j = 1,
SIZE(gci%lg3x3)
198 gci%lg3x3(j)%lambda = 0.0_dp
201 IF (
ASSOCIATED(gci%lg4x6))
THEN
202 DO j = 1,
SIZE(gci%lg4x6)
204 gci%lg4x6(j)%lambda = 0.0_dp
219 CALL timestop(handle)
242 REAL(kind=
dp),
INTENT(in),
OPTIONAL :: dt
243 REAL(kind=
dp),
INTENT(in) :: shake_tol
244 INTEGER,
INTENT(in),
OPTIONAL :: log_unit, lagrange_mult
245 LOGICAL,
INTENT(IN),
OPTIONAL :: dump_lm
246 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT), &
247 OPTIONAL,
TARGET :: vel
248 LOGICAL,
INTENT(IN),
OPTIONAL :: reset
250 CHARACTER(len=*),
PARAMETER :: routinen =
'force_env_rattle'
252 INTEGER :: handle, i, iparticle, iparticle_kind, iparticle_local, j, my_lagrange_mult, &
253 my_log_unit, nparticle_kind, nparticle_local
254 LOGICAL :: has_vel, my_dump_lm
255 REAL(kind=
dp) :: mydt
256 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: my_vel
266 CALL timeset(routinen, handle)
267 cpassert(
ASSOCIATED(force_env))
268 cpassert(force_env%ref_count > 0)
270 IF (
PRESENT(log_unit)) my_log_unit = log_unit
271 my_lagrange_mult = -1
272 IF (
PRESENT(lagrange_mult)) my_lagrange_mult = lagrange_mult
274 IF (
PRESENT(dump_lm)) my_dump_lm = dump_lm
275 NULLIFY (subsys, cell, molecules, molecule_kinds, local_molecules, particles, &
277 IF (
PRESENT(vel)) my_vel => vel
279 IF (
PRESENT(dt)) mydt = dt
282 atomic_kinds=atomic_kinds, &
283 local_molecules=local_molecules, &
284 local_particles=local_particles, &
285 molecules=molecules, &
286 molecule_kinds=molecule_kinds, &
287 particles=particles, &
289 nparticle_kind = atomic_kinds%n_els
291 IF (.NOT.
ASSOCIATED(my_vel))
THEN
293 ALLOCATE (my_vel(3, particles%n_els))
295 DO iparticle_kind = 1, nparticle_kind
296 nparticle_local = local_particles%n_el(iparticle_kind)
297 DO iparticle_local = 1, nparticle_local
298 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
299 my_vel(:, iparticle) = particles%els(iparticle)%v(:)
305 molecule_set=molecules%els, molecule_kind_set=molecule_kinds%els, &
306 particle_set=particles%els, vel=my_vel, dt=mydt, &
307 rattle_tol=shake_tol, log_unit=my_log_unit, lagrange_mult=my_lagrange_mult, &
308 dump_lm=my_dump_lm, cell=cell, group=force_env%para_env, &
309 local_particles=local_particles)
312 IF (
PRESENT(reset))
THEN
315 DO i = 1,
SIZE(molecules%els)
316 IF (
ASSOCIATED(molecules%els(i)%lci%lcolv))
THEN
317 DO j = 1,
SIZE(molecules%els(i)%lci%lcolv)
319 molecules%els(i)%lci%lcolv(j)%lambda = 0.0_dp
322 IF (
ASSOCIATED(molecules%els(i)%lci%lg3x3))
THEN
323 DO j = 1,
SIZE(molecules%els(i)%lci%lg3x3)
325 molecules%els(i)%lci%lg3x3(j)%lambda = 0.0_dp
328 IF (
ASSOCIATED(molecules%els(i)%lci%lg4x6))
THEN
329 DO j = 1,
SIZE(molecules%els(i)%lci%lg4x6)
331 molecules%els(i)%lci%lg4x6(j)%lambda = 0.0_dp
336 IF (
ASSOCIATED(gci))
THEN
337 IF (
ASSOCIATED(gci%lcolv))
THEN
338 DO j = 1,
SIZE(gci%lcolv)
340 gci%lcolv(j)%lambda = 0.0_dp
343 IF (
ASSOCIATED(gci%lg3x3))
THEN
344 DO j = 1,
SIZE(gci%lg3x3)
346 gci%lg3x3(j)%lambda = 0.0_dp
349 IF (
ASSOCIATED(gci%lg4x6))
THEN
350 DO j = 1,
SIZE(gci%lg4x6)
352 gci%lg4x6(j)%lambda = 0.0_dp
363 CALL timestop(handle)
374 CHARACTER(len=*),
PARAMETER :: routinen =
'rescale_forces'
376 INTEGER :: handle, iparticle
378 REAL(kind=
dp) :: force(3), max_value, mod_force
383 CALL timeset(routinen, handle)
384 cpassert(
ASSOCIATED(force_env))
385 cpassert(force_env%ref_count > 0)
392 DO iparticle = 1,
SIZE(particles%els)
393 force = particles%els(iparticle)%f(:)
394 mod_force = sqrt(dot_product(force, force))
395 IF ((mod_force > max_value) .AND. (mod_force /= 0.0_dp))
THEN
396 force = force/mod_force*max_value
397 particles%els(iparticle)%f(:) = force
401 CALL timestop(handle)
417 SUBROUTINE write_forces(particles, iw, label, ndigits, unit_string, total_force, &
418 grand_total_force, zero_force_core_shell_atom)
421 INTEGER,
INTENT(IN) :: iw
422 CHARACTER(LEN=*),
INTENT(IN) :: label
423 INTEGER,
INTENT(IN) :: ndigits
424 CHARACTER(LEN=default_string_length),
INTENT(IN) :: unit_string
425 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: total_force
426 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT), &
427 OPTIONAL :: grand_total_force
428 LOGICAL,
INTENT(IN),
OPTIONAL :: zero_force_core_shell_atom
430 CHARACTER(LEN=18) :: fmtstr4
431 CHARACTER(LEN=29) :: fmtstr3
432 CHARACTER(LEN=38) :: fmtstr2
433 CHARACTER(LEN=49) :: fmtstr1
434 CHARACTER(LEN=7) :: tag
435 CHARACTER(LEN=LEN_TRIM(label)) :: lc_label
436 INTEGER :: i, iparticle, n
437 LOGICAL :: zero_force
438 REAL(kind=
dp) :: fconv
439 REAL(kind=
dp),
DIMENSION(3) :: f
442 cpassert(
ASSOCIATED(particles))
444 lc_label = trim(label)
446 n = min(max(1, ndigits), 20)
447 fmtstr1 =
"(/,T2,A,1X,A,/,T2,A,3X,A,T20,A3,2( X,A3), X,A3)"
448 WRITE (unit=fmtstr1(35:36), fmt=
"(I2)") n + 5
449 WRITE (unit=fmtstr1(43:44), fmt=
"(I2)") n + 6
450 fmtstr2 =
"(T2,A,I7,T16,3(1X,ES . ),2X,ES . )"
451 WRITE (unit=fmtstr2(21:22), fmt=
"(I2)") n + 7
452 WRITE (unit=fmtstr2(24:25), fmt=
"(I2)") n
453 WRITE (unit=fmtstr2(33:34), fmt=
"(I2)") n + 7
454 WRITE (unit=fmtstr2(36:37), fmt=
"(I2)") n
455 fmtstr3 =
"(T2,A,T16,3(1X,ES . ))"
456 WRITE (unit=fmtstr3(18:19), fmt=
"(I2)") n + 7
457 WRITE (unit=fmtstr3(21:22), fmt=
"(I2)") n
458 fmtstr4 =
"(T2,A,T ,ES . )"
459 WRITE (unit=fmtstr4(8:9), fmt=
"(I2)") 3*(n + 8) + 18
460 WRITE (unit=fmtstr4(13:14), fmt=
"(I2)") n + 7
461 WRITE (unit=fmtstr4(16:17), fmt=
"(I2)") n
462 IF (
PRESENT(zero_force_core_shell_atom))
THEN
463 zero_force = zero_force_core_shell_atom
468 WRITE (unit=iw, fmt=fmtstr1) &
469 tag, label//
" forces ["//trim(adjustl(unit_string))//
"]", &
470 tag,
"Atom",
" x ",
" y ",
" z ",
"|f|"
471 total_force(1:3) = 0.0_dp
472 DO iparticle = 1, particles%n_els
473 IF (particles%els(iparticle)%atom_index /= 0)
THEN
474 i = particles%els(iparticle)%atom_index
478 IF (zero_force .AND. (particles%els(iparticle)%shell_index /= 0))
THEN
481 f(1:3) = particles%els(iparticle)%f(1:3)*fconv
483 WRITE (unit=iw, fmt=fmtstr2) &
484 tag, i, f(1:3), sqrt(sum(f(1:3)**2))
485 total_force(1:3) = total_force(1:3) + f(1:3)
487 WRITE (unit=iw, fmt=fmtstr3) &
488 tag//
" Sum", total_force(1:3)
489 WRITE (unit=iw, fmt=fmtstr4) &
490 tag//
" Total "//trim(adjustl(lc_label))//
" force", &
491 sqrt(sum(total_force(1:3)**2))
494 IF (
PRESENT(grand_total_force))
THEN
495 grand_total_force(1:3) = grand_total_force(1:3) + total_force(1:3)
496 WRITE (unit=iw, fmt=
"(A)")
""
497 WRITE (unit=iw, fmt=fmtstr4) &
498 tag//
" Grand total force ["//trim(adjustl(unit_string))//
"]", &
499 sqrt(sum(grand_total_force(1:3)**2))
516 INTEGER,
INTENT(IN) :: iounit
518 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: atener
519 CHARACTER(LEN=*),
INTENT(IN) :: label
524 WRITE (unit=iounit, fmt=
"(/,T2,A)") trim(label)
525 WRITE (unit=iounit, fmt=
"(T4,A,T30,A,T42,A,T54,A,T69,A)") &
526 "Atom Element",
"X",
"Y",
"Z",
"Energy[a.u.]"
527 natom = particles%n_els
529 WRITE (iounit,
"(I6,T12,A2,T24,3F12.6,F21.10)") i, &
530 trim(adjustl(particles%els(i)%atomic_kind%element_symbol)), &
531 particles%els(i)%r(1:3)*
angstrom, atener(i)
533 WRITE (iounit,
"(A)")
""
represent a simple array based list of the given type
Handles all functions related to the CELL.
Contains routines useful for the application of constraints during MD.
subroutine, public getold(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, cell)
saves all of the old variables
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)
...
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)
...
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
real(kind=dp) function, public cp_unit_from_cp2k(value, unit_str, defaults, power)
converts from the internal cp2k units to the given unit
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 write_forces(particles, iw, label, ndigits, unit_string, total_force, grand_total_force, zero_force_core_shell_atom)
Write forces.
subroutine, public force_env_shake(force_env, dt, shake_tol, log_unit, lagrange_mult, dump_lm, pos, vel, compold, reset)
perform shake (enforcing of constraints)
subroutine, public write_atener(iounit, particles, atener, label)
Write the atomic coordinates, types, and energies.
subroutine, public rescale_forces(force_env)
Rescale forces if requested.
subroutine, public force_env_rattle(force_env, dt, shake_tol, log_unit, lagrange_mult, dump_lm, vel, reset)
perform rattle (enforcing of constraints on velocities) This routine can be easily adapted to perform...
Defines the basic variable types.
integer, parameter, public dp
integer, parameter, public default_string_length
represent a simple array based list of the given type
represent a simple array based list of the given type
Define the data structure for the molecule information.
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)
...
Definition of physical constants:
real(kind=dp), parameter, public angstrom
Utilities for string manipulations.
elemental subroutine, public lowercase(string)
Convert all upper case characters in a string to lower case.
represent a list of objects
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