17#if defined (__PLUMED2)
18 USE iso_c_binding,
ONLY: c_int, c_double, c_char
20 pbc_cp2k_plumed_getset_cell
56#if defined (__PLUMED2)
71#if defined (__PLUMED2)
74#include "./base/base_uses.f90"
79 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'metadynamics'
85#if defined (__PLUMED2)
87 FUNCTION plumed_installed()
RESULT(res)
BIND(C, name="plumed_installed")
89 INTEGER(KIND=C_INT) :: res
90 END FUNCTION plumed_installed
92 SUBROUTINE plumed_gcreate()
BIND(C, name="plumed_gcreate")
93 END SUBROUTINE plumed_gcreate
95 SUBROUTINE plumed_gfinalize()
BIND(C, name="plumed_gfinalize")
96 END SUBROUTINE plumed_gfinalize
98 SUBROUTINE plumed_gcmd_int(key, value)
BIND(C, name="plumed_gcmd")
99 IMPORT :: c_char, c_int
100 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: key
101 INTEGER(KIND=C_INT) :: value
102 END SUBROUTINE plumed_gcmd_int
104 SUBROUTINE plumed_gcmd_double(key, value)
BIND(C, name="plumed_gcmd")
105 IMPORT :: c_char, c_double
106 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: key
108 REAL(KIND=c_double),
TARGET ::
value
109 END SUBROUTINE plumed_gcmd_double
111 SUBROUTINE plumed_gcmd_doubles(key, value)
BIND(C, name="plumed_gcmd")
112 IMPORT :: c_char, c_double
113 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: key
114 REAL(KIND=c_double),
TARGET,
DIMENSION(*) ::
value
115 END SUBROUTINE plumed_gcmd_doubles
117 SUBROUTINE plumed_gcmd_char(key, value)
BIND(C, name="plumed_gcmd")
119 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: key, value
120 END SUBROUTINE plumed_gcmd_char
136 INTEGER,
INTENT(IN) :: itimes
138 CHARACTER(LEN=*),
PARAMETER :: routinen =
'metadyn_initialise_plumed'
142#if defined (__PLUMED2)
143 INTEGER :: natom_plumed
144 REAL(kind=
dp) :: timestep_plumed
149#if defined (__PLUMED2)
150 INTEGER :: plumedavailable
153 CALL timeset(routinen, handle)
154 cpassert(
ASSOCIATED(force_env))
155 cpassert(
ASSOCIATED(simpar))
157#if defined (__PLUMED2)
158 NULLIFY (cell, subsys)
160 CALL pbc_cp2k_plumed_getset_cell(cell, set=.true.)
161 timestep_plumed = simpar%dt
162 natom_plumed = subsys%particles%n_els
168#if !defined (__PLUMED2)
171#if defined (__PLUMED2)
172 plumedavailable = plumed_installed()
174 IF (plumedavailable <= 0)
THEN
175 cpabort(
"NO PLUMED IN YOUR LD_LIBRARY_PATH?")
177 CALL plumed_gcreate()
178 IF (
cp2k_is_parallel)
CALL plumed_gcmd_int(
"setMPIFComm"//char(0), force_env%para_env%get_handle())
179 CALL plumed_gcmd_int(
"setRealPrecision"//char(0), 8)
180 CALL plumed_gcmd_double(
"setMDEnergyUnits"//char(0),
kjmol)
181 CALL plumed_gcmd_double(
"setMDLengthUnits"//char(0),
angstrom*0.1_dp)
182 CALL plumed_gcmd_double(
"setMDTimeUnits"//char(0),
picoseconds)
183 CALL plumed_gcmd_char(
"setPlumedDat"//char(0), force_env%meta_env%plumed_input_file//char(0))
184 CALL plumed_gcmd_char(
"setLogFile"//char(0),
"PLUMED.OUT"//char(0))
185 CALL plumed_gcmd_int(
"setNatoms"//char(0), natom_plumed)
186 CALL plumed_gcmd_char(
"setMDEngine"//char(0),
"cp2k"//char(0))
187 CALL plumed_gcmd_double(
"setTimestep"//char(0), timestep_plumed)
189 IF (simpar%temp_ext > 0.0_dp)
CALL plumed_gcmd_double(
"setKbT"//char(0), simpar%temp_ext)
190 IF (itimes > 0)
CALL plumed_gcmd_int(
"setRestart"//char(0), 1)
191 CALL plumed_gcmd_int(
"init"//char(0), 0)
195#if !defined (__PLUMED2)
196 CALL cp_abort(__location__, &
197 "Requested to use plumed for metadynamics, but cp2k was"// &
198 " not compiled with plumed support.")
201 CALL timestop(handle)
210 CHARACTER(LEN=*),
PARAMETER :: routinen =
'metadyn_finalise_plumed'
214 CALL timeset(routinen, handle)
216#if defined (__PLUMED2)
217 CALL plumed_gfinalize()
220 CALL timestop(handle)
237 INTEGER,
INTENT(IN) :: itimes
238 REAL(kind=
dp),
DIMENSION(:, :), &
239 INTENT(INOUT),
OPTIONAL :: vel
240 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL, &
243 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_integrator'
245 INTEGER :: handle, plumed_itimes
246#if defined (__PLUMED2)
247 INTEGER :: i_part, natom_plumed
252#if defined (__PLUMED2)
254 REAL(kind=
dp),
ALLOCATABLE,
TARGET,
DIMENSION(:) :: mass_plumed
255 REAL(kind=
dp),
TARGET,
DIMENSION(3, 3) :: plu_vir, celltbt
256 REAL(kind=
dp),
TARGET :: stpcfg
257 REAL(kind=
dp),
ALLOCATABLE,
TARGET, &
258 DIMENSION(:) :: pos_plumed_x, pos_plumed_y, pos_plumed_z
259 REAL(kind=
dp),
ALLOCATABLE,
TARGET, &
260 DIMENSION(:) :: force_plumed_x, force_plumed_y, force_plumed_z
263 CALL timeset(routinen, handle)
266 IF (
ASSOCIATED(force_env%meta_env))
THEN
267 IF (force_env%meta_env%use_plumed .EQV. .true.)
THEN
268 plumed_itimes = itimes
269#if defined (__PLUMED2)
270 CALL force_env_get(force_env, meta_env=meta_env, subsys=subsys, cell=cell)
272 natom_plumed = subsys%particles%n_els
273 ALLOCATE (pos_plumed_x(natom_plumed))
274 ALLOCATE (pos_plumed_y(natom_plumed))
275 ALLOCATE (pos_plumed_z(natom_plumed))
277 ALLOCATE (force_plumed_x(natom_plumed))
278 ALLOCATE (force_plumed_y(natom_plumed))
279 ALLOCATE (force_plumed_z(natom_plumed))
281 ALLOCATE (mass_plumed(natom_plumed))
283 DO i_part = 1, natom_plumed
284 pos_plumed_x(i_part) = subsys%particles%els(i_part)%r(1)
285 pos_plumed_y(i_part) = subsys%particles%els(i_part)%r(2)
286 pos_plumed_z(i_part) = subsys%particles%els(i_part)%r(3)
287 mass_plumed(i_part) = subsys%particles%els(i_part)%atomic_kind%mass
289 force_plumed_x(i_part) = subsys%particles%els(i_part)%f(1)
290 force_plumed_y(i_part) = subsys%particles%els(i_part)%f(2)
291 force_plumed_z(i_part) = subsys%particles%els(i_part)%f(3)
295 celltbt(1, 1) = cell%hmat(1, 1)
296 celltbt(1, 2) = cell%hmat(1, 2)
297 celltbt(1, 3) = cell%hmat(1, 3)
298 celltbt(2, 1) = cell%hmat(2, 1)
299 celltbt(2, 2) = cell%hmat(2, 2)
300 celltbt(2, 3) = cell%hmat(2, 3)
301 celltbt(3, 1) = cell%hmat(3, 1)
302 celltbt(3, 2) = cell%hmat(3, 2)
303 celltbt(3, 3) = cell%hmat(3, 3)
306 plu_vir(:, :) = 0.0d0
307 IF (virial%pv_availability) plu_vir = -virial%pv_virial
310 meta_env%plumed_bias = 0.0_dp
313 CALL plumed_gcmd_int(
"setStep"//char(0), plumed_itimes)
314 CALL plumed_gcmd_doubles(
"setPositionsX"//char(0), pos_plumed_x(:))
315 CALL plumed_gcmd_doubles(
"setPositionsY"//char(0), pos_plumed_y(:))
316 CALL plumed_gcmd_doubles(
"setPositionsZ"//char(0), pos_plumed_z(:))
317 CALL plumed_gcmd_doubles(
"setMasses"//char(0), mass_plumed(:))
318 CALL plumed_gcmd_doubles(
"setBox"//char(0), celltbt)
319 CALL plumed_gcmd_doubles(
"setVirial"//char(0), plu_vir)
320 CALL plumed_gcmd_double(
"setEnergy"//char(0), stpcfg)
321 CALL plumed_gcmd_doubles(
"setForcesX"//char(0), force_plumed_x(:))
322 CALL plumed_gcmd_doubles(
"setForcesY"//char(0), force_plumed_y(:))
323 CALL plumed_gcmd_doubles(
"setForcesZ"//char(0), force_plumed_z(:))
325 CALL plumed_gcmd_int(
"prepareCalc"//char(0), 0)
327 CALL plumed_gcmd_int(
"performCalcNoUpdate"//char(0), 0)
328 CALL plumed_gcmd_double(
"getBias"//char(0), meta_env%plumed_bias)
329 CALL plumed_gcmd_int(
"update"//char(0), 0)
332 CALL force_env%para_env%bcast(plu_vir, source=0)
333 IF (virial%pv_availability) virial%pv_virial = -plu_vir
335 DO i_part = 1, natom_plumed
336 subsys%particles%els(i_part)%f(1) = force_plumed_x(i_part)
337 subsys%particles%els(i_part)%f(2) = force_plumed_y(i_part)
338 subsys%particles%els(i_part)%f(3) = force_plumed_z(i_part)
341 DEALLOCATE (pos_plumed_x, pos_plumed_y, pos_plumed_z)
342 DEALLOCATE (force_plumed_x, force_plumed_y, force_plumed_z)
343 DEALLOCATE (mass_plumed)
349#if !defined (__PLUMED2)
350 CALL cp_abort(__location__, &
351 "Requested to use plumed for metadynamics, but cp2k was"// &
352 " not compiled with plumed support.")
356 IF (force_env%meta_env%langevin)
THEN
357 IF (.NOT.
PRESENT(rand))
THEN
358 cpabort(
"Langevin on COLVAR not implemented for this MD ensemble!")
361 CALL metadyn_position_colvar(force_env)
374 CALL timestop(handle)
388 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT), &
391 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_forces'
393 INTEGER :: handle, i, i_c, icolvar, ii, iwall
395 REAL(kind=
dp) :: check_val, diff_ss, dt, ekin_w, fac_t, &
396 fft, norm, rval, scal, scalf, &
406 NULLIFY (logger, meta_env)
407 meta_env => force_env%meta_env
408 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
410 CALL timeset(routinen, handle)
412 NULLIFY (colvar_p, subsys, cv, ss0_section, vvp_section)
416 IF (.NOT. meta_env%restart) meta_env%n_steps = meta_env%n_steps + 1
419 IF (meta_env%restart .AND. meta_env%extended_lagrange)
THEN
420 meta_env%ekin_s = 0.0_dp
421 DO i_c = 1, meta_env%n_colvar
422 cv => meta_env%metavar(i_c)
423 cv%vvp = force_env%globenv%gaussian_rng_stream%next()
424 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
426 ekin_w = 0.5_dp*meta_env%temp_wanted*real(meta_env%n_colvar, kind=
dp)
427 fac_t = sqrt(ekin_w/max(meta_env%ekin_s, 1.0e-8_dp))
428 DO i_c = 1, meta_env%n_colvar
429 cv => meta_env%metavar(i_c)
430 cv%vvp = cv%vvp*fac_t
432 meta_env%ekin_s = 0.0_dp
437 DO i_c = 1, meta_env%n_colvar
438 cv => meta_env%metavar(i_c)
441 cv%ss = subsys%colvar_p(icolvar)%colvar%ss
447 IF (meta_env%restart)
THEN
453 i_rep_val=i_c, r_val=rval)
462 i_rep_val=i_c, r_val=rval)
467 IF (.NOT. meta_env%extended_lagrange)
THEN
473 IF (meta_env%do_hills)
CALL hills(meta_env)
478 meta_env%restart = .false.
479 IF (.NOT. meta_env%extended_lagrange)
THEN
480 meta_env%ekin_s = 0.0_dp
481 meta_env%epot_s = 0.0_dp
482 meta_env%epot_walls = 0.0_dp
483 DO i_c = 1, meta_env%n_colvar
484 cv => meta_env%metavar(i_c)
487 meta_env%epot_walls = meta_env%epot_walls + cv%epot_walls
492 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
493 i = colvar_p(icolvar)%colvar%i_atom(ii)
494 fft = cv%ff_hills + cv%ff_walls
495 particles%els(i)%f = particles%els(i)%f + fft*colvar_p(icolvar)%colvar%dsdr(:, ii)
499 meta_env%ekin_s = 0.0_dp
500 meta_env%epot_s = 0.0_dp
501 meta_env%epot_walls = 0.0_dp
502 DO i_c = 1, meta_env%n_colvar
503 cv => meta_env%metavar(i_c)
504 diff_ss = cv%ss - cv%ss0
505 IF (cv%periodic)
THEN
507 diff_ss = sign(1.0_dp, asin(sin(diff_ss)))*acos(cos(diff_ss))
509 cv%epot_s = 0.5_dp*cv%lambda*(diff_ss)**2.0_dp
510 cv%ff_s = cv%lambda*(diff_ss)
516 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
517 i = colvar_p(icolvar)%colvar%i_atom(ii)
518 particles%els(i)%f = particles%els(i)%f - cv%ff_s*colvar_p(icolvar)%colvar%dsdr(:, ii)
521 IF (.NOT. meta_env%langevin)
THEN
522 fft = cv%ff_s + cv%ff_hills + cv%ff_walls
523 cv%vvp = cv%vvp + dt*fft/cv%mass
524 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
525 meta_env%epot_s = meta_env%epot_s + cv%epot_s
526 meta_env%epot_walls = meta_env%epot_walls + cv%epot_walls
530 IF (meta_env%tempcontrol .AND. (.NOT. meta_env%langevin))
THEN
531 ekin_w = 0.5_dp*meta_env%temp_wanted*real(meta_env%n_colvar, kind=
dp)
532 tol_ekin = 0.5_dp*meta_env%toll_temp*real(meta_env%n_colvar, kind=
dp)
533 IF (abs(ekin_w - meta_env%ekin_s) > tol_ekin)
THEN
534 fac_t = sqrt(ekin_w/max(meta_env%ekin_s, 1.0e-8_dp))
535 DO i_c = 1, meta_env%n_colvar
536 cv => meta_env%metavar(i_c)
537 cv%vvp = cv%vvp*fac_t
539 meta_env%ekin_s = ekin_w
543 DO i_c = 1, meta_env%n_colvar
544 cv => meta_env%metavar(i_c)
546 DO iwall = 1,
SIZE(cv%walls)
547 SELECT CASE (cv%walls(iwall)%id_type)
549 ss0_test = cv%ss0 + dt*cv%vvp
550 IF (cv%periodic)
THEN
552 ss0_test = sign(1.0_dp, asin(sin(ss0_test)))*acos(cos(ss0_test))
554 SELECT CASE (cv%walls(iwall)%id_direction)
556 IF ((ss0_test > cv%walls(iwall)%pos) .AND. (cv%vvp > 0)) cv%vvp = -cv%vvp
558 IF ((ss0_test < cv%walls(iwall)%pos) .AND. (cv%vvp < 0)) cv%vvp = -cv%vvp
565 IF (.NOT. meta_env%langevin)
THEN
566 DO i_c = 1, meta_env%n_colvar
567 cv => meta_env%metavar(i_c)
568 cv%ss0 = cv%ss0 + dt*cv%vvp
569 IF (cv%periodic)
THEN
571 cv%ss0 = sign(1.0_dp, asin(sin(cv%ss0)))*acos(cos(cv%ss0))
580 DO i_c = 1, meta_env%n_colvar
581 cv => meta_env%metavar(i_c)
583 DO iwall = 1,
SIZE(cv%walls)
584 SELECT CASE (cv%walls(iwall)%id_type)
586 SELECT CASE (cv%walls(iwall)%id_direction)
588 IF (cv%ss < cv%walls(iwall)%pos) cycle
591 IF (cv%ss > cv%walls(iwall)%pos) cycle
596 CALL cp_subsys_get(subsys, colvar_p=colvar_p, particles=particles)
600 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
601 i = colvar_p(icolvar)%colvar%i_atom(ii)
602 IF (
PRESENT(vel))
THEN
603 scal = scal + vel(1, i)*colvar_p(icolvar)%colvar%dsdr(1, ii)
604 scal = scal + vel(2, i)*colvar_p(icolvar)%colvar%dsdr(2, ii)
605 scal = scal + vel(3, i)*colvar_p(icolvar)%colvar%dsdr(3, ii)
607 scal = scal + particles%els(i)%v(1)*colvar_p(icolvar)%colvar%dsdr(1, ii)
608 scal = scal + particles%els(i)%v(2)*colvar_p(icolvar)%colvar%dsdr(2, ii)
609 scal = scal + particles%els(i)%v(3)*colvar_p(icolvar)%colvar%dsdr(3, ii)
611 scalf = scalf + particles%els(i)%f(1)*colvar_p(icolvar)%colvar%dsdr(1, ii)
612 scalf = scalf + particles%els(i)%f(2)*colvar_p(icolvar)%colvar%dsdr(2, ii)
613 scalf = scalf + particles%els(i)%f(3)*colvar_p(icolvar)%colvar%dsdr(3, ii)
614 norm = norm + colvar_p(icolvar)%colvar%dsdr(1, ii)**2
615 norm = norm + colvar_p(icolvar)%colvar%dsdr(2, ii)**2
616 norm = norm + colvar_p(icolvar)%colvar%dsdr(3, ii)**2
618 IF (norm /= 0.0_dp) scal = scal/norm
619 IF (norm /= 0.0_dp) scalf = scalf/norm
621 IF (scal*check_val > 0.0_dp) cycle
622 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
623 i = colvar_p(icolvar)%colvar%i_atom(ii)
624 IF (
PRESENT(vel))
THEN
625 vel(:, i) = vel(:, i) - 2.0_dp*colvar_p(icolvar)%colvar%dsdr(:, ii)*scal
627 particles%els(i)%v(:) = particles%els(i)%v(:) - 2.0_dp*colvar_p(icolvar)%colvar%dsdr(:, ii)*scal
630 particles%els(i)%f(:) = particles%els(i)%f(:) - colvar_p(icolvar)%colvar%dsdr(:, ii)*scalf
637 CALL timestop(handle)
650 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT), &
653 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_velocities_colvar'
655 INTEGER :: handle, i_c
656 REAL(kind=
dp) :: diff_ss, dt, fft, sigma
661 NULLIFY (logger, meta_env, cv)
662 meta_env => force_env%meta_env
663 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
665 CALL timeset(routinen, handle)
672 IF (meta_env%do_hills)
CALL hills(meta_env)
675 meta_env%ekin_s = 0.0_dp
676 meta_env%epot_walls = 0.0_dp
677 DO i_c = 1, meta_env%n_colvar
678 cv => meta_env%metavar(i_c)
679 diff_ss = cv%ss - cv%ss0
680 IF (cv%periodic)
THEN
682 diff_ss = sign(1.0_dp, asin(sin(diff_ss)))*acos(cos(diff_ss))
684 cv%epot_s = 0.5_dp*cv%lambda*(diff_ss)**2.0_dp
685 cv%ff_s = cv%lambda*(diff_ss)
687 fft = cv%ff_s + cv%ff_hills
689 cv%vvp = cv%vvp + 0.5_dp*dt*fft/cv%mass - 0.5_dp*dt*cv%gamma*cv%vvp + &
690 0.5_dp*sqrt(dt)*sigma*rand(i_c)
691 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
692 meta_env%epot_walls = meta_env%epot_walls + cv%epot_walls
694 CALL timestop(handle)
705 SUBROUTINE metadyn_position_colvar(force_env)
708 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_position_colvar'
710 INTEGER :: handle, i_c
716 NULLIFY (logger, meta_env, cv)
717 meta_env => force_env%meta_env
718 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
720 CALL timeset(routinen, handle)
728 DO i_c = 1, meta_env%n_colvar
729 cv => meta_env%metavar(i_c)
730 cv%ss0 = cv%ss0 + dt*cv%vvp
731 IF (cv%periodic)
THEN
733 cv%ss0 = sign(1.0_dp, asin(sin(cv%ss0)))*acos(cos(cv%ss0))
736 CALL timestop(handle)
738 END SUBROUTINE metadyn_position_colvar
750 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_write_colvar'
752 INTEGER :: handle, i, i_c, iw
753 REAL(kind=
dp) :: diff_ss, temp
758 NULLIFY (logger, meta_env, cv)
759 meta_env => force_env%meta_env
760 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
762 CALL timeset(routinen, handle)
770 IF (meta_env%langevin)
THEN
771 meta_env%ekin_s = 0.0_dp
772 meta_env%epot_s = 0.0_dp
773 DO i_c = 1, meta_env%n_colvar
774 cv => meta_env%metavar(i_c)
775 diff_ss = cv%ss - cv%ss0
776 IF (cv%periodic)
THEN
778 diff_ss = sign(1.0_dp, asin(sin(diff_ss)))*acos(cos(diff_ss))
780 cv%epot_s = 0.5_dp*cv%lambda*(diff_ss)**2.0_dp
781 cv%ff_s = cv%lambda*(diff_ss)
783 meta_env%epot_s = meta_env%epot_s + cv%epot_s
784 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
790 "PRINT%COLVAR", extension=
".metadynLog")
792 IF (meta_env%extended_lagrange)
THEN
793 WRITE (iw,
'(f16.8,70f15.8)') meta_env%time*
femtoseconds, &
794 (meta_env%metavar(i)%ss0, i=1, meta_env%n_colvar), &
795 (meta_env%metavar(i)%ss, i=1, meta_env%n_colvar), &
796 (meta_env%metavar(i)%ff_s, i=1, meta_env%n_colvar), &
797 (meta_env%metavar(i)%ff_hills, i=1, meta_env%n_colvar), &
798 (meta_env%metavar(i)%ff_walls, i=1, meta_env%n_colvar), &
799 (meta_env%metavar(i)%vvp, i=1, meta_env%n_colvar), &
801 meta_env%hills_env%energy, &
802 meta_env%epot_walls, &
803 (meta_env%ekin_s)*2.0_dp/(real(meta_env%n_colvar, kind=
dp))*
kelvin
805 WRITE (iw,
'(f16.8,40f13.5)') meta_env%time*
femtoseconds, &
806 (meta_env%metavar(i)%ss0, i=1, meta_env%n_colvar), &
807 (meta_env%metavar(i)%ff_hills, i=1, meta_env%n_colvar), &
808 (meta_env%metavar(i)%ff_walls, i=1, meta_env%n_colvar), &
809 meta_env%hills_env%energy, &
817 IF (meta_env%extended_lagrange)
THEN
818 temp = meta_env%ekin_s*2.0_dp/(real(meta_env%n_colvar, kind=
dp))*
kelvin
819 meta_env%avg_temp = (meta_env%avg_temp*real(meta_env%n_steps, kind=
dp) + &
820 temp)/real(meta_env%n_steps + 1, kind=
dp)
822 "PRINT%TEMPERATURE_COLVAR", extension=
".metadynLog")
824 WRITE (iw,
'(T2,79("-"))')
825 WRITE (iw,
'( A,T51,f10.2,T71,f10.2)')
' COLVARS INSTANTANEOUS/AVERAGE TEMPERATURE ', &
826 temp, meta_env%avg_temp
827 WRITE (iw,
'(T2,79("-"))')
830 "PRINT%TEMPERATURE_COLVAR")
832 CALL timestop(handle)
845 SUBROUTINE hills(meta_env)
848 CHARACTER(len=*),
PARAMETER :: routinen =
'hills'
850 INTEGER :: handle, i, i_hills, ih, intermeta_steps, &
851 iter_nr, iw, n_colvar, n_hills_start, &
853 LOGICAL :: force_gauss
854 REAL(kind=
dp) :: cut_func, dfunc, diff, dp2, frac, &
855 slow_growth, v_now_here, v_to_fes, &
857 REAL(kind=
dp),
DIMENSION(:),
POINTER :: ddp, denf, diff_ss, local_last_hills, &
864 CALL timeset(routinen, handle)
866 NULLIFY (hills_env, multiple_walkers, logger, colvars, ddp, local_last_hills)
867 hills_env => meta_env%hills_env
869 colvars => meta_env%metavar
870 n_colvar = meta_env%n_colvar
871 n_step = meta_env%n_steps
876 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=iter_nr)
879 IF (meta_env%hills_env%restart)
THEN
880 meta_env%hills_env%restart = .false.
881 IF (meta_env%well_tempered)
THEN
882 CALL restart_hills(hills_env%ss_history, hills_env%delta_s_history, hills_env%ww_history, &
883 hills_env%ww, hills_env%n_hills, n_colvar, colvars, meta_env%metadyn_section, &
884 invdt_history=hills_env%invdt_history)
886 CALL restart_hills(hills_env%ss_history, hills_env%delta_s_history, hills_env%ww_history, &
887 hills_env%ww, hills_env%n_hills, n_colvar, colvars, meta_env%metadyn_section)
892 intermeta_steps = n_step - hills_env%old_hill_step
893 force_gauss = .false.
894 IF ((hills_env%min_disp > 0.0_dp) .AND. (hills_env%old_hill_number > 0) .AND. &
895 (intermeta_steps >= hills_env%min_nt_hills))
THEN
896 ALLOCATE (ddp(meta_env%n_colvar))
897 ALLOCATE (local_last_hills(meta_env%n_colvar))
899 local_last_hills(1:n_colvar) = hills_env%ss_history(1:n_colvar, hills_env%old_hill_number)
904 ddp(i) = colvars(i)%ss0 - local_last_hills(i)
905 IF (colvars(i)%periodic)
THEN
907 ddp(i) = sign(1.0_dp, asin(sin(ddp(i))))*acos(cos(ddp(i)))
909 dp2 = dp2 + ddp(i)**2
912 IF (dp2 > hills_env%min_disp)
THEN
915 "PRINT%PROGRAM_RUN_INFO", extension=
".metadynLog")
917 WRITE (unit=iw, fmt=
"(A,F0.6,A,F0.6)") &
918 " METADYN| Threshold value for COLVAR displacement exceeded: ", &
919 dp2,
" > ", hills_env%min_disp
922 "PRINT%PROGRAM_RUN_INFO")
925 DEALLOCATE (local_last_hills)
929 IF (((
modulo(intermeta_steps, hills_env%nt_hills) == 0) .OR. force_gauss) &
930 .AND. (.NOT. meta_env%restart) .AND. (hills_env%nt_hills > 0))
THEN
931 IF (meta_env%do_multiple_walkers) multiple_walkers => meta_env%multiple_walkers
933 n_hills_start = hills_env%n_hills
935 IF (meta_env%well_tempered)
THEN
938 DO ih = 1, hills_env%n_hills
941 diff = colvars(i)%ss0 - hills_env%ss_history(i, ih)
942 IF (colvars(i)%periodic)
THEN
944 diff = sign(1.0_dp, asin(sin(diff)))*acos(cos(diff))
946 diff = (diff)/hills_env%delta_s_history(i, ih)
949 v_to_fes = 1.0_dp + meta_env%wttemperature*hills_env%invdt_history(ih)
950 v_now_here = v_now_here + hills_env%ww_history(ih)/v_to_fes*exp(-0.5_dp*dp2)
952 wtww = hills_env%ww*exp(-v_now_here*meta_env%invdt)
953 ww = wtww*(1.0_dp + meta_env%wttemperature*meta_env%invdt)
954 CALL add_hill_single(hills_env, colvars, ww, hills_env%n_hills, n_colvar, meta_env%invdt)
956 CALL add_hill_single(hills_env, colvars, hills_env%ww, hills_env%n_hills, n_colvar)
959 IF (meta_env%do_multiple_walkers) multiple_walkers%n_hills_local = multiple_walkers%n_hills_local + 1
961 hills_env%old_hill_number = hills_env%n_hills
962 hills_env%old_hill_step = n_step
966 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=iter_nr)
970 "PRINT%PROGRAM_RUN_INFO", extension=
".metadynLog")
972 IF (meta_env%do_multiple_walkers)
THEN
973 WRITE (iw,
'(/,1X,"METADYN|",A,I0,A,I0,A,/)') &
974 ' Global/Local Hills number (', hills_env%n_hills,
'/', multiple_walkers%n_hills_local, &
977 WRITE (iw,
'(/,1X,"METADYN|",A,I0,A,/)')
' Hills number (', hills_env%n_hills,
') added.'
981 "PRINT%PROGRAM_RUN_INFO")
984 IF (meta_env%do_multiple_walkers)
THEN
987 "PRINT%HILLS", middle_name=
"LOCAL", extension=
".metadynLog")
989 WRITE (iw,
'(f12.1,30f13.5)') meta_env%time*
femtoseconds, &
990 (hills_env%ss_history(ih, hills_env%n_hills), ih=1, n_colvar), &
991 (hills_env%delta_s_history(ih, hills_env%n_hills), ih=1, n_colvar), &
992 hills_env%ww_history(hills_env%n_hills)
999 n_colvar, meta_env%metadyn_section)
1005 "PRINT%HILLS", extension=
".metadynLog")
1007 DO i_hills = n_hills_start + 1, hills_env%n_hills
1008 WRITE (iw,
'(f12.1,30f13.5)') meta_env%time*
femtoseconds, &
1009 (hills_env%ss_history(ih, i_hills), ih=1, n_colvar), &
1010 (hills_env%delta_s_history(ih, i_hills), ih=1, n_colvar), &
1011 hills_env%ww_history(i_hills)
1019 ALLOCATE (ddp(meta_env%n_colvar))
1020 ALLOCATE (diff_ss(meta_env%n_colvar))
1021 ALLOCATE (numf(meta_env%n_colvar))
1022 ALLOCATE (denf(meta_env%n_colvar))
1024 hills_env%energy = 0.0_dp
1026 colvars(ih)%ff_hills = 0.0_dp
1028 DO ih = 1, hills_env%n_hills
1029 slow_growth = 1.0_dp
1030 IF (hills_env%slow_growth .AND. (ih == hills_env%n_hills))
THEN
1031 slow_growth = real(n_step - hills_env%old_hill_step,
dp)/real(hills_env%nt_hills,
dp)
1036 diff_ss(i) = colvars(i)%ss0 - hills_env%ss_history(i, ih)
1037 IF (colvars(i)%periodic)
THEN
1039 diff_ss(i) = sign(1.0_dp, asin(sin(diff_ss(i))))*acos(cos(diff_ss(i)))
1041 IF (hills_env%delta_s_history(i, ih) == 0.0_dp)
THEN
1048 ddp(i) = (diff_ss(i))/hills_env%delta_s_history(i, ih)
1050 dp2 = dp2 + ddp(i)**2
1051 IF (hills_env%tail_cutoff > 0.0_dp)
THEN
1052 frac = abs(ddp(i))/hills_env%tail_cutoff
1053 numf(i) = frac**hills_env%p_exp
1054 denf(i) = frac**hills_env%q_exp
1055 cut_func = cut_func*(1.0_dp - numf(i))/(1.0_dp - denf(i))
1059 dfunc = hills_env%ww_history(ih)*exp(-0.5_dp*dp2)*slow_growth
1060 IF (meta_env%well_tempered) dfunc = dfunc/(1.0_dp + meta_env%wttemperature*hills_env%invdt_history(ih))
1061 hills_env%energy = hills_env%energy + dfunc*cut_func
1063 IF (hills_env%delta_s_history(i, ih) /= 0.0_dp)
THEN
1066 colvars(i)%ff_hills = colvars(i)%ff_hills + &
1067 ddp(i)/hills_env%delta_s_history(i, ih)*dfunc*cut_func
1068 IF (hills_env%tail_cutoff > 0.0_dp .AND. abs(diff_ss(i)) > 10.e-5_dp)
THEN
1069 colvars(i)%ff_hills = colvars(i)%ff_hills + &
1070 (hills_env%p_exp*numf(i)/(1.0_dp - numf(i)) - hills_env%q_exp*denf(i)/(1.0_dp - denf(i)))* &
1071 dfunc*cut_func/abs(diff_ss(i))
1077 DEALLOCATE (diff_ss)
1083 CALL timestop(handle)
1085 END SUBROUTINE hills
static GRID_HOST_DEVICE int modulo(int a, int m)
Equivalent of Fortran's MODULO, which always return a positive number. https://gcc....
collects all references to literature in CP2K as new algorithms / method are included from literature...
integer, save, public vandencic2006
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_glob_f(icolvar, force_env)
evaluates the derivatives (dsdr) given and due to the given colvar
Initialize the collective variables types.
integer, parameter, public torsion_colvar_id
subroutine, public fix_atom_control(force_env, w)
allows for fix atom constraints
various routines to log and control the output. The idea is that decisions about where to log should ...
type(cp_logger_type) function, pointer, public cp_get_default_logger()
returns the default logger
routines to handle the output, The idea is to remove the decision of wheter to output and what to out...
integer function, public cp_print_key_unit_nr(logger, basis_section, print_key_path, extension, middle_name, local, log_filename, ignore_should_output, file_form, file_position, file_action, file_status, do_backup, on_file, is_new_file, mpi_io, fout)
...
subroutine, public cp_print_key_finished_output(unit_nr, logger, basis_section, print_key_path, local, ignore_should_output, on_file, mpi_io)
should be called after you finish working with a unit obtained with cp_print_key_unit_nr,...
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
subroutine, public cp_rm_iter_level(iteration_info, level_name, n_rlevel_att)
Removes an iteration level.
subroutine, public cp_add_iter_level(iteration_info, level_name, n_rlevel_new)
Adds an iteration level.
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, cell_ref, use_ref_cell)
returns information about various attributes of the given subsys
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
Defines the basic variable types.
integer, parameter, public dp
Interface to the message passing library MPI.
logical, parameter, public cp2k_is_parallel
represent a simple array based list of the given type
Definition of physical constants:
real(kind=dp), parameter, public boltzmann
real(kind=dp), parameter, public femtoseconds
real(kind=dp), parameter, public joule
real(kind=dp), parameter, public kelvin
real(kind=dp), parameter, public angstrom
real(kind=dp), parameter, public picoseconds
real(kind=dp), parameter, public kjmol
provides a uniform framework to add references to CP2K cite and output these
subroutine, public cite_reference(key)
marks a given reference as cited.
Type for storing MD parameters.
Type defining parameters related to the simulation cell.
type of a logger, at the moment it contains just a print level starting at which level it should be l...
represents a system: atoms, molecules, their pos,vel,...
wrapper to abstract the force evaluation of the various methods
represent a list of objects
Simulation parameter type for molecular dynamics.