40#include "./base/base_uses.f90"
46 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'force_env_utils'
72 SUBROUTINE force_env_shake(force_env, dt, shake_tol, log_unit, lagrange_mult, dump_lm, &
73 pos, vel, compold, reset)
76 REAL(kind=
dp),
INTENT(IN),
OPTIONAL :: dt
77 REAL(kind=
dp),
INTENT(IN) :: shake_tol
78 INTEGER,
INTENT(in),
OPTIONAL :: log_unit, lagrange_mult
79 LOGICAL,
INTENT(IN),
OPTIONAL :: dump_lm
80 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT), &
81 OPTIONAL,
TARGET :: pos, vel
82 LOGICAL,
INTENT(IN),
OPTIONAL :: compold, reset
84 CHARACTER(len=*),
PARAMETER :: routinen =
'force_env_shake'
86 INTEGER :: handle, i, iparticle, iparticle_kind, iparticle_local, j, my_lagrange_mult, &
87 my_log_unit, nparticle_kind, nparticle_local
88 LOGICAL :: has_pos, has_vel, my_dump_lm
90 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: my_pos, my_vel
100 CALL timeset(routinen, handle)
101 cpassert(
ASSOCIATED(force_env))
102 cpassert(force_env%ref_count > 0)
104 IF (
PRESENT(log_unit)) my_log_unit = log_unit
105 my_lagrange_mult = -1
106 IF (
PRESENT(lagrange_mult)) my_lagrange_mult = lagrange_mult
108 IF (
PRESENT(dump_lm)) my_dump_lm = dump_lm
109 NULLIFY (subsys, cell, molecules, molecule_kinds, local_molecules, particles, &
111 IF (
PRESENT(pos)) my_pos => pos
112 IF (
PRESENT(vel)) my_vel => vel
114 IF (
PRESENT(dt)) mydt = dt
117 atomic_kinds=atomic_kinds, &
118 local_molecules=local_molecules, &
119 local_particles=local_particles, &
120 molecules=molecules, &
121 molecule_kinds=molecule_kinds, &
122 particles=particles, &
124 nparticle_kind = atomic_kinds%n_els
125 IF (
PRESENT(compold))
THEN
127 CALL getold(gci, local_molecules, molecules%els, molecule_kinds%els, &
132 IF (.NOT.
ASSOCIATED(my_pos))
THEN
134 ALLOCATE (my_pos(3, particles%n_els))
136 DO iparticle_kind = 1, nparticle_kind
137 nparticle_local = local_particles%n_el(iparticle_kind)
138 DO iparticle_local = 1, nparticle_local
139 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
140 my_pos(:, iparticle) = particles%els(iparticle)%r(:)
145 IF (.NOT.
ASSOCIATED(my_vel))
THEN
147 ALLOCATE (my_vel(3, particles%n_els))
149 DO iparticle_kind = 1, nparticle_kind
150 nparticle_local = local_particles%n_el(iparticle_kind)
151 DO iparticle_local = 1, nparticle_local
152 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
153 my_vel(:, iparticle) = particles%els(iparticle)%v(:)
158 CALL shake_control(gci=gci, local_molecules=local_molecules, &
159 molecule_set=molecules%els, molecule_kind_set=molecule_kinds%els, &
160 particle_set=particles%els, pos=my_pos, vel=my_vel, dt=mydt, &
161 shake_tol=shake_tol, log_unit=my_log_unit, lagrange_mult=my_lagrange_mult, &
162 dump_lm=my_dump_lm, cell=cell, group=force_env%para_env, &
163 local_particles=local_particles)
166 IF (
PRESENT(reset))
THEN
169 DO i = 1,
SIZE(molecules%els)
170 IF (
ASSOCIATED(molecules%els(i)%lci%lcolv))
THEN
171 DO j = 1,
SIZE(molecules%els(i)%lci%lcolv)
173 molecules%els(i)%lci%lcolv(j)%lambda = 0.0_dp
176 IF (
ASSOCIATED(molecules%els(i)%lci%lg3x3))
THEN
177 DO j = 1,
SIZE(molecules%els(i)%lci%lg3x3)
179 molecules%els(i)%lci%lg3x3(j)%lambda = 0.0_dp
182 IF (
ASSOCIATED(molecules%els(i)%lci%lg4x6))
THEN
183 DO j = 1,
SIZE(molecules%els(i)%lci%lg4x6)
185 molecules%els(i)%lci%lg4x6(j)%lambda = 0.0_dp
190 IF (
ASSOCIATED(gci))
THEN
191 IF (
ASSOCIATED(gci%lcolv))
THEN
192 DO j = 1,
SIZE(gci%lcolv)
194 gci%lcolv(j)%lambda = 0.0_dp
197 IF (
ASSOCIATED(gci%lg3x3))
THEN
198 DO j = 1,
SIZE(gci%lg3x3)
200 gci%lg3x3(j)%lambda = 0.0_dp
203 IF (
ASSOCIATED(gci%lg4x6))
THEN
204 DO j = 1,
SIZE(gci%lg4x6)
206 gci%lg4x6(j)%lambda = 0.0_dp
221 CALL timestop(handle)
244 REAL(kind=
dp),
INTENT(in),
OPTIONAL :: dt
245 REAL(kind=
dp),
INTENT(in) :: shake_tol
246 INTEGER,
INTENT(in),
OPTIONAL :: log_unit, lagrange_mult
247 LOGICAL,
INTENT(IN),
OPTIONAL :: dump_lm
248 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT), &
249 OPTIONAL,
TARGET :: vel
250 LOGICAL,
INTENT(IN),
OPTIONAL :: reset
252 CHARACTER(len=*),
PARAMETER :: routinen =
'force_env_rattle'
254 INTEGER :: handle, i, iparticle, iparticle_kind, iparticle_local, j, my_lagrange_mult, &
255 my_log_unit, nparticle_kind, nparticle_local
256 LOGICAL :: has_vel, my_dump_lm
257 REAL(kind=
dp) :: mydt
258 REAL(kind=
dp),
DIMENSION(:, :),
POINTER :: my_vel
268 CALL timeset(routinen, handle)
269 cpassert(
ASSOCIATED(force_env))
270 cpassert(force_env%ref_count > 0)
272 IF (
PRESENT(log_unit)) my_log_unit = log_unit
273 my_lagrange_mult = -1
274 IF (
PRESENT(lagrange_mult)) my_lagrange_mult = lagrange_mult
276 IF (
PRESENT(dump_lm)) my_dump_lm = dump_lm
277 NULLIFY (subsys, cell, molecules, molecule_kinds, local_molecules, particles, &
279 IF (
PRESENT(vel)) my_vel => vel
281 IF (
PRESENT(dt)) mydt = dt
284 atomic_kinds=atomic_kinds, &
285 local_molecules=local_molecules, &
286 local_particles=local_particles, &
287 molecules=molecules, &
288 molecule_kinds=molecule_kinds, &
289 particles=particles, &
291 nparticle_kind = atomic_kinds%n_els
293 IF (.NOT.
ASSOCIATED(my_vel))
THEN
295 ALLOCATE (my_vel(3, particles%n_els))
297 DO iparticle_kind = 1, nparticle_kind
298 nparticle_local = local_particles%n_el(iparticle_kind)
299 DO iparticle_local = 1, nparticle_local
300 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
301 my_vel(:, iparticle) = particles%els(iparticle)%v(:)
307 molecule_set=molecules%els, molecule_kind_set=molecule_kinds%els, &
308 particle_set=particles%els, vel=my_vel, dt=mydt, &
309 rattle_tol=shake_tol, log_unit=my_log_unit, lagrange_mult=my_lagrange_mult, &
310 dump_lm=my_dump_lm, cell=cell, group=force_env%para_env, &
311 local_particles=local_particles)
314 IF (
PRESENT(reset))
THEN
317 DO i = 1,
SIZE(molecules%els)
318 IF (
ASSOCIATED(molecules%els(i)%lci%lcolv))
THEN
319 DO j = 1,
SIZE(molecules%els(i)%lci%lcolv)
321 molecules%els(i)%lci%lcolv(j)%lambda = 0.0_dp
324 IF (
ASSOCIATED(molecules%els(i)%lci%lg3x3))
THEN
325 DO j = 1,
SIZE(molecules%els(i)%lci%lg3x3)
327 molecules%els(i)%lci%lg3x3(j)%lambda = 0.0_dp
330 IF (
ASSOCIATED(molecules%els(i)%lci%lg4x6))
THEN
331 DO j = 1,
SIZE(molecules%els(i)%lci%lg4x6)
333 molecules%els(i)%lci%lg4x6(j)%lambda = 0.0_dp
338 IF (
ASSOCIATED(gci))
THEN
339 IF (
ASSOCIATED(gci%lcolv))
THEN
340 DO j = 1,
SIZE(gci%lcolv)
342 gci%lcolv(j)%lambda = 0.0_dp
345 IF (
ASSOCIATED(gci%lg3x3))
THEN
346 DO j = 1,
SIZE(gci%lg3x3)
348 gci%lg3x3(j)%lambda = 0.0_dp
351 IF (
ASSOCIATED(gci%lg4x6))
THEN
352 DO j = 1,
SIZE(gci%lg4x6)
354 gci%lg4x6(j)%lambda = 0.0_dp
365 CALL timestop(handle)
376 CHARACTER(len=*),
PARAMETER :: routinen =
'rescale_forces'
378 INTEGER :: handle, iparticle
380 REAL(kind=
dp) :: force(3), max_value, mod_force
385 CALL timeset(routinen, handle)
386 cpassert(
ASSOCIATED(force_env))
387 cpassert(force_env%ref_count > 0)
394 DO iparticle = 1,
SIZE(particles%els)
395 force = particles%els(iparticle)%f(:)
396 mod_force = sqrt(dot_product(force, force))
397 IF ((mod_force > max_value) .AND. (mod_force /= 0.0_dp))
THEN
398 force = force/mod_force*max_value
399 particles%els(iparticle)%f(:) = force
403 CALL timestop(handle)
418 SUBROUTINE write_forces(particles, iw, label, ndigits, unit_string, total_force, &
419 grand_total_force, zero_force_core_shell_atom)
422 INTEGER,
INTENT(IN) :: iw
423 CHARACTER(LEN=*),
INTENT(IN) :: label
424 INTEGER,
INTENT(IN) :: ndigits
425 CHARACTER(LEN=default_string_length),
INTENT(IN) :: unit_string
426 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: total_force
427 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT), &
428 OPTIONAL :: grand_total_force
429 LOGICAL,
INTENT(IN),
OPTIONAL :: zero_force_core_shell_atom
432 CALL write_forces_to_screen(particles, iw, label, ndigits, unit_string, total_force, &
433 grand_total_force, zero_force_core_shell_atom)
435 CALL write_forces_to_file(particles, iw, label, ndigits, total_force, &
436 grand_total_force, zero_force_core_shell_atom)
453 SUBROUTINE write_forces_to_screen(particles, iw, label, ndigits, unit_string, total_force, &
454 grand_total_force, zero_force_core_shell_atom)
457 INTEGER,
INTENT(IN) :: iw
458 CHARACTER(LEN=*),
INTENT(IN) :: label
459 INTEGER,
INTENT(IN) :: ndigits
460 CHARACTER(LEN=default_string_length),
INTENT(IN) :: unit_string
461 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: total_force
462 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT), &
463 OPTIONAL :: grand_total_force
464 LOGICAL,
INTENT(IN),
OPTIONAL :: zero_force_core_shell_atom
466 CHARACTER(LEN=18) :: fmtstr4
467 CHARACTER(LEN=29) :: fmtstr3
468 CHARACTER(LEN=38) :: fmtstr2
469 CHARACTER(LEN=49) :: fmtstr1
470 CHARACTER(LEN=7) :: tag
471 CHARACTER(LEN=LEN_TRIM(label)) :: lc_label
472 INTEGER :: i, iparticle, n
473 LOGICAL :: zero_force
474 REAL(kind=
dp) :: fconv
475 REAL(kind=
dp),
DIMENSION(3) :: f
478 cpassert(
ASSOCIATED(particles))
480 lc_label = trim(label)
482 n = min(max(1, ndigits), 20)
483 fmtstr1 =
"(/,T2,A,1X,A,/,T2,A,3X,A,T20,A3,2( X,A3), X,A3)"
484 WRITE (unit=fmtstr1(35:36), fmt=
"(I2)") n + 5
485 WRITE (unit=fmtstr1(43:44), fmt=
"(I2)") n + 6
486 fmtstr2 =
"(T2,A,I7,T16,3(1X,ES . ),2X,ES . )"
487 WRITE (unit=fmtstr2(21:22), fmt=
"(I2)") n + 7
488 WRITE (unit=fmtstr2(24:25), fmt=
"(I2)") n
489 WRITE (unit=fmtstr2(33:34), fmt=
"(I2)") n + 7
490 WRITE (unit=fmtstr2(36:37), fmt=
"(I2)") n
491 fmtstr3 =
"(T2,A,T16,3(1X,ES . ))"
492 WRITE (unit=fmtstr3(18:19), fmt=
"(I2)") n + 7
493 WRITE (unit=fmtstr3(21:22), fmt=
"(I2)") n
494 fmtstr4 =
"(T2,A,T ,ES . )"
495 WRITE (unit=fmtstr4(8:9), fmt=
"(I2)") 3*(n + 8) + 18
496 WRITE (unit=fmtstr4(13:14), fmt=
"(I2)") n + 7
497 WRITE (unit=fmtstr4(16:17), fmt=
"(I2)") n
498 IF (
PRESENT(zero_force_core_shell_atom))
THEN
499 zero_force = zero_force_core_shell_atom
504 WRITE (unit=iw, fmt=fmtstr1) &
505 tag, label//
" forces ["//trim(adjustl(unit_string))//
"]", &
506 tag,
"Atom",
" x ",
" y ",
" z ",
"|f|"
507 total_force(1:3) = 0.0_dp
508 DO iparticle = 1, particles%n_els
509 IF (particles%els(iparticle)%atom_index /= 0)
THEN
510 i = particles%els(iparticle)%atom_index
514 IF (zero_force .AND. (particles%els(iparticle)%shell_index /= 0))
THEN
517 f(1:3) = particles%els(iparticle)%f(1:3)*fconv
519 WRITE (unit=iw, fmt=fmtstr2) &
520 tag, i, f(1:3), sqrt(sum(f(1:3)**2))
521 total_force(1:3) = total_force(1:3) + f(1:3)
523 WRITE (unit=iw, fmt=fmtstr3) &
524 tag//
" Sum", total_force(1:3)
525 WRITE (unit=iw, fmt=fmtstr4) &
526 tag//
" Total "//trim(adjustl(lc_label))//
" force", &
527 sqrt(sum(total_force(1:3)**2))
530 IF (
PRESENT(grand_total_force))
THEN
531 grand_total_force(1:3) = grand_total_force(1:3) + total_force(1:3)
532 WRITE (unit=iw, fmt=
"(A)")
""
533 WRITE (unit=iw, fmt=fmtstr4) &
534 tag//
" Grand total force ["//trim(adjustl(unit_string))//
"]", &
535 sqrt(sum(grand_total_force(1:3)**2))
538 END SUBROUTINE write_forces_to_screen
552 SUBROUTINE write_forces_to_file(particles, iw, label, ndigits, total_force, &
553 grand_total_force, zero_force_core_shell_atom)
556 INTEGER,
INTENT(IN) :: iw
557 CHARACTER(LEN=*),
INTENT(IN) :: label
558 INTEGER,
INTENT(IN) :: ndigits
559 REAL(kind=
dp),
DIMENSION(3),
INTENT(OUT) :: total_force
560 REAL(kind=
dp),
DIMENSION(3),
INTENT(INOUT), &
561 OPTIONAL :: grand_total_force
562 LOGICAL,
INTENT(IN),
OPTIONAL :: zero_force_core_shell_atom
564 CHARACTER(LEN=23) :: fmtstr3
565 CHARACTER(LEN=36) :: fmtstr2
566 CHARACTER(LEN=46) :: fmtstr1
567 CHARACTER(LEN=LEN_TRIM(label)) :: uc_label
568 INTEGER :: i, ikind, iparticle, n
569 LOGICAL :: zero_force
570 REAL(kind=
dp),
DIMENSION(3) :: f
573 cpassert(
ASSOCIATED(particles))
574 n = min(max(1, ndigits), 20)
575 fmtstr1 =
"(/,T2,A,/,/,T2,A,T11,A,T18,A,T35,A1,2( X,A1))"
576 WRITE (unit=fmtstr1(39:40), fmt=
"(I2)") n + 6
577 fmtstr2 =
"(T2,I6,1X,I6,T21,A,T28,3(1X,F . ))"
578 WRITE (unit=fmtstr2(33:34), fmt=
"(I2)") n
579 WRITE (unit=fmtstr2(30:31), fmt=
"(I2)") n + 6
580 fmtstr3 =
"(T2,A,T28,4(1X,F . ))"
581 WRITE (unit=fmtstr3(20:21), fmt=
"(I2)") n
582 WRITE (unit=fmtstr3(17:18), fmt=
"(I2)") n + 6
583 IF (
PRESENT(zero_force_core_shell_atom))
THEN
584 zero_force = zero_force_core_shell_atom
588 uc_label = trim(label)
590 WRITE (unit=iw, fmt=fmtstr1) &
591 uc_label//
" FORCES in [a.u.]",
"# Atom",
"Kind",
"Element",
"X",
"Y",
"Z"
592 total_force(1:3) = 0.0_dp
593 DO iparticle = 1, particles%n_els
594 ikind = particles%els(iparticle)%atomic_kind%kind_number
595 IF (particles%els(iparticle)%atom_index /= 0)
THEN
596 i = particles%els(iparticle)%atom_index
600 IF (zero_force .AND. (particles%els(iparticle)%shell_index /= 0))
THEN
603 f(1:3) = particles%els(iparticle)%f(1:3)
605 WRITE (unit=iw, fmt=fmtstr2) &
606 i, ikind, particles%els(iparticle)%atomic_kind%element_symbol, f(1:3)
607 total_force(1:3) = total_force(1:3) + f(1:3)
609 WRITE (unit=iw, fmt=fmtstr3) &
610 "SUM OF "//uc_label//
" FORCES", total_force(1:3), sqrt(sum(total_force(:)**2))
613 IF (
PRESENT(grand_total_force))
THEN
614 grand_total_force(1:3) = grand_total_force(1:3) + total_force(1:3)
615 WRITE (unit=iw, fmt=
"(A)")
""
616 WRITE (unit=iw, fmt=fmtstr3) &
617 "GRAND TOTAL FORCE", grand_total_force(1:3), sqrt(sum(grand_total_force(:)**2))
620 END SUBROUTINE write_forces_to_file
634 INTEGER,
INTENT(IN) :: iounit
636 REAL(kind=
dp),
DIMENSION(:),
INTENT(IN) :: atener
637 CHARACTER(LEN=*),
INTENT(IN) :: label
642 WRITE (unit=iounit, fmt=
"(/,T2,A)") trim(label)
643 WRITE (unit=iounit, fmt=
"(T4,A,T30,A,T42,A,T54,A,T69,A)") &
644 "Atom Element",
"X",
"Y",
"Z",
"Energy[a.u.]"
645 natom = particles%n_els
647 WRITE (iounit,
"(I6,T12,A2,T24,3F12.6,F21.10)") i, &
648 trim(adjustl(particles%els(i)%atomic_kind%element_symbol)), &
649 particles%els(i)%r(1:3)*
angstrom, atener(i)
651 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)
...
various routines to log and control the output. The idea is that decisions about where to log should ...
integer function, public cp_logger_get_default_io_unit(logger)
returns the unit nr for the ionode (-1 on all other processors) skips as well checks if the procs cal...
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 either to the screen or to a file.
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.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper 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