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#include "./base/base_uses.f90"
76 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'metadynamics'
82#if defined (__PLUMED2)
84 FUNCTION plumed_installed()
RESULT(res)
BIND(C, name="plumed_installed")
86 INTEGER(KIND=C_INT) :: res
87 END FUNCTION plumed_installed
89 SUBROUTINE plumed_gcreate()
BIND(C, name="plumed_gcreate")
90 END SUBROUTINE plumed_gcreate
92 SUBROUTINE plumed_gfinalize()
BIND(C, name="plumed_gfinalize")
93 END SUBROUTINE plumed_gfinalize
95 SUBROUTINE plumed_gcmd_int(key, value)
BIND(C, name="plumed_gcmd")
96 IMPORT :: c_char, c_int
97 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: key
98 INTEGER(KIND=C_INT) :: value
99 END SUBROUTINE plumed_gcmd_int
101 SUBROUTINE plumed_gcmd_double(key, value)
BIND(C, name="plumed_gcmd")
102 IMPORT :: c_char, c_double
103 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: key
104 REAL(KIND=c_double) ::
value
105 END SUBROUTINE plumed_gcmd_double
107 SUBROUTINE plumed_gcmd_doubles(key, value)
BIND(C, name="plumed_gcmd")
108 IMPORT :: c_char, c_double
109 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: key
110 REAL(KIND=c_double),
DIMENSION(*) ::
value
111 END SUBROUTINE plumed_gcmd_doubles
113 SUBROUTINE plumed_gcmd_char(key, value)
BIND(C, name="plumed_gcmd")
115 CHARACTER(KIND=C_CHAR),
DIMENSION(*) :: key, value
116 END SUBROUTINE plumed_gcmd_char
132 INTEGER,
INTENT(IN) :: itimes
134 CHARACTER(LEN=*),
PARAMETER :: routinen =
'metadyn_initialise_plumed'
138#if defined (__PLUMED2)
139 INTEGER :: natom_plumed
140 REAL(kind=
dp) :: timestep_plumed
145#if defined (__PLUMED2)
146 INTEGER :: plumedavailable
149 CALL timeset(routinen, handle)
150 cpassert(
ASSOCIATED(force_env))
151 cpassert(
ASSOCIATED(simpar))
153#if defined (__PLUMED2)
154 NULLIFY (cell, subsys)
156 CALL pbc_cp2k_plumed_getset_cell(cell, set=.true.)
157 timestep_plumed = simpar%dt
158 natom_plumed = subsys%particles%n_els
165#if defined (__PLUMED2)
166 plumedavailable = plumed_installed()
168 IF (plumedavailable <= 0)
THEN
169 cpabort(
"NO PLUMED IN YOUR LD_LIBRARY_PATH?")
171 CALL plumed_gcreate()
172 IF (
cp2k_is_parallel)
CALL plumed_gcmd_int(
"setMPIFComm"//char(0), force_env%para_env%get_handle())
173 CALL plumed_gcmd_int(
"setRealPrecision"//char(0), 8)
174 CALL plumed_gcmd_double(
"setMDEnergyUnits"//char(0),
kjmol)
175 CALL plumed_gcmd_double(
"setMDLengthUnits"//char(0),
angstrom*0.1_dp)
176 CALL plumed_gcmd_double(
"setMDTimeUnits"//char(0),
picoseconds)
177 CALL plumed_gcmd_char(
"setPlumedDat"//char(0), force_env%meta_env%plumed_input_file//char(0))
178 CALL plumed_gcmd_char(
"setLogFile"//char(0),
"PLUMED.OUT"//char(0))
179 CALL plumed_gcmd_int(
"setNatoms"//char(0), natom_plumed)
180 CALL plumed_gcmd_char(
"setMDEngine"//char(0),
"cp2k"//char(0))
181 CALL plumed_gcmd_double(
"setTimestep"//char(0), timestep_plumed)
182 CALL plumed_gcmd_int(
"init"//char(0), 0)
186#if !defined (__PLUMED2)
187 CALL cp_abort(__location__, &
188 "Requested to use plumed for metadynamics, but cp2k was"// &
189 " not compiled with plumed support.")
192 CALL timestop(handle)
201 CHARACTER(LEN=*),
PARAMETER :: routinen =
'metadyn_finalise_plumed'
205 CALL timeset(routinen, handle)
207#if defined (__PLUMED2)
208 CALL plumed_gfinalize()
211 CALL timestop(handle)
228 INTEGER,
INTENT(IN) :: itimes
229 REAL(kind=
dp),
DIMENSION(:, :), &
230 INTENT(INOUT),
OPTIONAL :: vel
231 REAL(kind=
dp),
DIMENSION(:),
OPTIONAL, &
234 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_integrator'
236 INTEGER :: handle, plumed_itimes
237#if defined (__PLUMED2)
238 INTEGER :: i_part, natom_plumed
242#if defined (__PLUMED2)
244 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: mass_plumed
245 REAL(kind=
dp),
DIMENSION(3, 3) :: plu_vir, celltbt
246 REAL(kind=
dp) :: stpcfg
247 REAL(kind=
dp),
ALLOCATABLE, &
248 DIMENSION(:) :: pos_plumed_x, pos_plumed_y, pos_plumed_z
249 REAL(kind=
dp),
ALLOCATABLE, &
250 DIMENSION(:) :: force_plumed_x, force_plumed_y, force_plumed_z
253 CALL timeset(routinen, handle)
256 IF (
ASSOCIATED(force_env%meta_env))
THEN
257 IF (force_env%meta_env%use_plumed .EQV. .true.)
THEN
258 plumed_itimes = itimes
259#if defined (__PLUMED2)
260 CALL force_env_get(force_env, meta_env=meta_env, subsys=subsys, cell=cell)
261 natom_plumed = subsys%particles%n_els
262 ALLOCATE (pos_plumed_x(natom_plumed))
263 ALLOCATE (pos_plumed_y(natom_plumed))
264 ALLOCATE (pos_plumed_z(natom_plumed))
266 ALLOCATE (force_plumed_x(natom_plumed))
267 ALLOCATE (force_plumed_y(natom_plumed))
268 ALLOCATE (force_plumed_z(natom_plumed))
270 ALLOCATE (mass_plumed(natom_plumed))
272 force_plumed_x(:) = 0.0d0
273 force_plumed_y(:) = 0.0d0
274 force_plumed_z(:) = 0.0d0
276 DO i_part = 1, natom_plumed
277 pos_plumed_x(i_part) = subsys%particles%els(i_part)%r(1)
278 pos_plumed_y(i_part) = subsys%particles%els(i_part)%r(2)
279 pos_plumed_z(i_part) = subsys%particles%els(i_part)%r(3)
280 mass_plumed(i_part) = subsys%particles%els(i_part)%atomic_kind%mass
284 celltbt(1, 1) = cell%hmat(1, 1)
285 celltbt(1, 2) = cell%hmat(1, 2)
286 celltbt(1, 3) = cell%hmat(1, 3)
287 celltbt(2, 1) = cell%hmat(2, 1)
288 celltbt(2, 2) = cell%hmat(2, 2)
289 celltbt(2, 3) = cell%hmat(2, 3)
290 celltbt(3, 1) = cell%hmat(3, 1)
291 celltbt(3, 2) = cell%hmat(3, 2)
292 celltbt(3, 3) = cell%hmat(3, 3)
295 plu_vir(:, :) = 0.0d0
299 CALL plumed_gcmd_int(
"setStep"//char(0), plumed_itimes)
300 CALL plumed_gcmd_doubles(
"setPositionsX"//char(0), pos_plumed_x(:))
301 CALL plumed_gcmd_doubles(
"setPositionsY"//char(0), pos_plumed_y(:))
302 CALL plumed_gcmd_doubles(
"setPositionsZ"//char(0), pos_plumed_z(:))
303 CALL plumed_gcmd_doubles(
"setMasses"//char(0), mass_plumed(:))
304 CALL plumed_gcmd_doubles(
"setBox"//char(0), celltbt)
305 CALL plumed_gcmd_doubles(
"setVirial"//char(0), plu_vir)
306 CALL plumed_gcmd_double(
"setEnergy"//char(0), stpcfg)
307 CALL plumed_gcmd_doubles(
"setForcesX"//char(0), force_plumed_x(:))
308 CALL plumed_gcmd_doubles(
"setForcesY"//char(0), force_plumed_y(:))
309 CALL plumed_gcmd_doubles(
"setForcesZ"//char(0), force_plumed_z(:))
311 CALL plumed_gcmd_int(
"prepareCalc"//char(0), 0)
312 CALL plumed_gcmd_int(
"prepareDependencies"//char(0), 0)
313 CALL plumed_gcmd_int(
"shareData"//char(0), 0)
315 CALL plumed_gcmd_int(
"performCalc"//char(0), 0)
317 DO i_part = 1, natom_plumed
318 subsys%particles%els(i_part)%f(1) = subsys%particles%els(i_part)%f(1) + force_plumed_x(i_part)
319 subsys%particles%els(i_part)%f(2) = subsys%particles%els(i_part)%f(2) + force_plumed_y(i_part)
320 subsys%particles%els(i_part)%f(3) = subsys%particles%els(i_part)%f(3) + force_plumed_z(i_part)
323 DEALLOCATE (pos_plumed_x, pos_plumed_y, pos_plumed_z)
324 DEALLOCATE (force_plumed_x, force_plumed_y, force_plumed_z)
325 DEALLOCATE (mass_plumed)
331#if !defined (__PLUMED2)
332 CALL cp_abort(__location__, &
333 "Requested to use plumed for metadynamics, but cp2k was"// &
334 " not compiled with plumed support.")
338 IF (force_env%meta_env%langevin)
THEN
339 IF (.NOT.
PRESENT(rand))
THEN
340 cpabort(
"Langevin on COLVAR not implemented for this MD ensemble!")
343 CALL metadyn_position_colvar(force_env)
356 CALL timestop(handle)
370 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT), &
373 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_forces'
375 INTEGER :: handle, i, i_c, icolvar, ii, iwall
377 REAL(kind=
dp) :: check_val, diff_ss, dt, ekin_w, fac_t, &
378 fft, norm, rval, scal, scalf, &
388 NULLIFY (logger, meta_env)
389 meta_env => force_env%meta_env
390 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
392 CALL timeset(routinen, handle)
394 NULLIFY (colvar_p, subsys, cv, ss0_section, vvp_section)
398 IF (.NOT. meta_env%restart) meta_env%n_steps = meta_env%n_steps + 1
401 IF (meta_env%restart .AND. meta_env%extended_lagrange)
THEN
402 meta_env%ekin_s = 0.0_dp
403 DO i_c = 1, meta_env%n_colvar
404 cv => meta_env%metavar(i_c)
405 cv%vvp = force_env%globenv%gaussian_rng_stream%next()
406 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
408 ekin_w = 0.5_dp*meta_env%temp_wanted*real(meta_env%n_colvar, kind=
dp)
409 fac_t = sqrt(ekin_w/max(meta_env%ekin_s, 1.0e-8_dp))
410 DO i_c = 1, meta_env%n_colvar
411 cv => meta_env%metavar(i_c)
412 cv%vvp = cv%vvp*fac_t
414 meta_env%ekin_s = 0.0_dp
419 DO i_c = 1, meta_env%n_colvar
420 cv => meta_env%metavar(i_c)
423 cv%ss = subsys%colvar_p(icolvar)%colvar%ss
429 IF (meta_env%restart)
THEN
435 i_rep_val=i_c, r_val=rval)
444 i_rep_val=i_c, r_val=rval)
449 IF (.NOT. meta_env%extended_lagrange)
THEN
455 IF (meta_env%do_hills)
CALL hills(meta_env)
460 meta_env%restart = .false.
461 IF (.NOT. meta_env%extended_lagrange)
THEN
462 meta_env%ekin_s = 0.0_dp
463 meta_env%epot_s = 0.0_dp
464 meta_env%epot_walls = 0.0_dp
465 DO i_c = 1, meta_env%n_colvar
466 cv => meta_env%metavar(i_c)
469 meta_env%epot_walls = meta_env%epot_walls + cv%epot_walls
474 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
475 i = colvar_p(icolvar)%colvar%i_atom(ii)
476 fft = cv%ff_hills + cv%ff_walls
477 particles%els(i)%f = particles%els(i)%f + fft*colvar_p(icolvar)%colvar%dsdr(:, ii)
481 meta_env%ekin_s = 0.0_dp
482 meta_env%epot_s = 0.0_dp
483 meta_env%epot_walls = 0.0_dp
484 DO i_c = 1, meta_env%n_colvar
485 cv => meta_env%metavar(i_c)
486 diff_ss = cv%ss - cv%ss0
487 IF (cv%periodic)
THEN
489 diff_ss = sign(1.0_dp, asin(sin(diff_ss)))*acos(cos(diff_ss))
491 cv%epot_s = 0.5_dp*cv%lambda*(diff_ss)**2.0_dp
492 cv%ff_s = cv%lambda*(diff_ss)
498 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
499 i = colvar_p(icolvar)%colvar%i_atom(ii)
500 particles%els(i)%f = particles%els(i)%f - cv%ff_s*colvar_p(icolvar)%colvar%dsdr(:, ii)
503 IF (.NOT. meta_env%langevin)
THEN
504 fft = cv%ff_s + cv%ff_hills + cv%ff_walls
505 cv%vvp = cv%vvp + dt*fft/cv%mass
506 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
507 meta_env%epot_s = meta_env%epot_s + cv%epot_s
508 meta_env%epot_walls = meta_env%epot_walls + cv%epot_walls
512 IF (meta_env%tempcontrol .AND. (.NOT. meta_env%langevin))
THEN
513 ekin_w = 0.5_dp*meta_env%temp_wanted*real(meta_env%n_colvar, kind=
dp)
514 tol_ekin = 0.5_dp*meta_env%toll_temp*real(meta_env%n_colvar, kind=
dp)
515 IF (abs(ekin_w - meta_env%ekin_s) > tol_ekin)
THEN
516 fac_t = sqrt(ekin_w/max(meta_env%ekin_s, 1.0e-8_dp))
517 DO i_c = 1, meta_env%n_colvar
518 cv => meta_env%metavar(i_c)
519 cv%vvp = cv%vvp*fac_t
521 meta_env%ekin_s = ekin_w
525 DO i_c = 1, meta_env%n_colvar
526 cv => meta_env%metavar(i_c)
528 DO iwall = 1,
SIZE(cv%walls)
529 SELECT CASE (cv%walls(iwall)%id_type)
531 ss0_test = cv%ss0 + dt*cv%vvp
532 IF (cv%periodic)
THEN
534 ss0_test = sign(1.0_dp, asin(sin(ss0_test)))*acos(cos(ss0_test))
536 SELECT CASE (cv%walls(iwall)%id_direction)
538 IF ((ss0_test > cv%walls(iwall)%pos) .AND. (cv%vvp > 0)) cv%vvp = -cv%vvp
540 IF ((ss0_test < cv%walls(iwall)%pos) .AND. (cv%vvp < 0)) cv%vvp = -cv%vvp
547 IF (.NOT. meta_env%langevin)
THEN
548 DO i_c = 1, meta_env%n_colvar
549 cv => meta_env%metavar(i_c)
550 cv%ss0 = cv%ss0 + dt*cv%vvp
551 IF (cv%periodic)
THEN
553 cv%ss0 = sign(1.0_dp, asin(sin(cv%ss0)))*acos(cos(cv%ss0))
562 DO i_c = 1, meta_env%n_colvar
563 cv => meta_env%metavar(i_c)
565 DO iwall = 1,
SIZE(cv%walls)
566 SELECT CASE (cv%walls(iwall)%id_type)
568 SELECT CASE (cv%walls(iwall)%id_direction)
570 IF (cv%ss < cv%walls(iwall)%pos) cycle
573 IF (cv%ss > cv%walls(iwall)%pos) cycle
578 CALL cp_subsys_get(subsys, colvar_p=colvar_p, particles=particles)
582 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
583 i = colvar_p(icolvar)%colvar%i_atom(ii)
584 IF (
PRESENT(vel))
THEN
585 scal = scal + vel(1, i)*colvar_p(icolvar)%colvar%dsdr(1, ii)
586 scal = scal + vel(2, i)*colvar_p(icolvar)%colvar%dsdr(2, ii)
587 scal = scal + vel(3, i)*colvar_p(icolvar)%colvar%dsdr(3, ii)
589 scal = scal + particles%els(i)%v(1)*colvar_p(icolvar)%colvar%dsdr(1, ii)
590 scal = scal + particles%els(i)%v(2)*colvar_p(icolvar)%colvar%dsdr(2, ii)
591 scal = scal + particles%els(i)%v(3)*colvar_p(icolvar)%colvar%dsdr(3, ii)
593 scalf = scalf + particles%els(i)%f(1)*colvar_p(icolvar)%colvar%dsdr(1, ii)
594 scalf = scalf + particles%els(i)%f(2)*colvar_p(icolvar)%colvar%dsdr(2, ii)
595 scalf = scalf + particles%els(i)%f(3)*colvar_p(icolvar)%colvar%dsdr(3, ii)
596 norm = norm + colvar_p(icolvar)%colvar%dsdr(1, ii)**2
597 norm = norm + colvar_p(icolvar)%colvar%dsdr(2, ii)**2
598 norm = norm + colvar_p(icolvar)%colvar%dsdr(3, ii)**2
600 IF (norm /= 0.0_dp) scal = scal/norm
601 IF (norm /= 0.0_dp) scalf = scalf/norm
603 IF (scal*check_val > 0.0_dp) cycle
604 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
605 i = colvar_p(icolvar)%colvar%i_atom(ii)
606 IF (
PRESENT(vel))
THEN
607 vel(:, i) = vel(:, i) - 2.0_dp*colvar_p(icolvar)%colvar%dsdr(:, ii)*scal
609 particles%els(i)%v(:) = particles%els(i)%v(:) - 2.0_dp*colvar_p(icolvar)%colvar%dsdr(:, ii)*scal
612 particles%els(i)%f(:) = particles%els(i)%f(:) - colvar_p(icolvar)%colvar%dsdr(:, ii)*scalf
619 CALL timestop(handle)
632 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT), &
635 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_velocities_colvar'
637 INTEGER :: handle, i_c
638 REAL(kind=
dp) :: diff_ss, dt, fft, sigma
643 NULLIFY (logger, meta_env, cv)
644 meta_env => force_env%meta_env
645 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
647 CALL timeset(routinen, handle)
654 IF (meta_env%do_hills)
CALL hills(meta_env)
657 meta_env%ekin_s = 0.0_dp
658 meta_env%epot_walls = 0.0_dp
659 DO i_c = 1, meta_env%n_colvar
660 cv => meta_env%metavar(i_c)
661 diff_ss = cv%ss - cv%ss0
662 IF (cv%periodic)
THEN
664 diff_ss = sign(1.0_dp, asin(sin(diff_ss)))*acos(cos(diff_ss))
666 cv%epot_s = 0.5_dp*cv%lambda*(diff_ss)**2.0_dp
667 cv%ff_s = cv%lambda*(diff_ss)
669 fft = cv%ff_s + cv%ff_hills
671 cv%vvp = cv%vvp + 0.5_dp*dt*fft/cv%mass - 0.5_dp*dt*cv%gamma*cv%vvp + &
672 0.5_dp*sqrt(dt)*sigma*rand(i_c)
673 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
674 meta_env%epot_walls = meta_env%epot_walls + cv%epot_walls
676 CALL timestop(handle)
687 SUBROUTINE metadyn_position_colvar(force_env)
690 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_position_colvar'
692 INTEGER :: handle, i_c
698 NULLIFY (logger, meta_env, cv)
699 meta_env => force_env%meta_env
700 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
702 CALL timeset(routinen, handle)
710 DO i_c = 1, meta_env%n_colvar
711 cv => meta_env%metavar(i_c)
712 cv%ss0 = cv%ss0 + dt*cv%vvp
713 IF (cv%periodic)
THEN
715 cv%ss0 = sign(1.0_dp, asin(sin(cv%ss0)))*acos(cos(cv%ss0))
718 CALL timestop(handle)
720 END SUBROUTINE metadyn_position_colvar
732 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_write_colvar'
734 INTEGER :: handle, i, i_c, iw
735 REAL(kind=
dp) :: diff_ss, temp
740 NULLIFY (logger, meta_env, cv)
741 meta_env => force_env%meta_env
742 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
744 CALL timeset(routinen, handle)
752 IF (meta_env%langevin)
THEN
753 meta_env%ekin_s = 0.0_dp
754 meta_env%epot_s = 0.0_dp
755 DO i_c = 1, meta_env%n_colvar
756 cv => meta_env%metavar(i_c)
757 diff_ss = cv%ss - cv%ss0
758 IF (cv%periodic)
THEN
760 diff_ss = sign(1.0_dp, asin(sin(diff_ss)))*acos(cos(diff_ss))
762 cv%epot_s = 0.5_dp*cv%lambda*(diff_ss)**2.0_dp
763 cv%ff_s = cv%lambda*(diff_ss)
765 meta_env%epot_s = meta_env%epot_s + cv%epot_s
766 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
772 "PRINT%COLVAR", extension=
".metadynLog")
774 IF (meta_env%extended_lagrange)
THEN
775 WRITE (iw,
'(f16.8,70f15.8)') meta_env%time*
femtoseconds, &
776 (meta_env%metavar(i)%ss0, i=1, meta_env%n_colvar), &
777 (meta_env%metavar(i)%ss, i=1, meta_env%n_colvar), &
778 (meta_env%metavar(i)%ff_s, i=1, meta_env%n_colvar), &
779 (meta_env%metavar(i)%ff_hills, i=1, meta_env%n_colvar), &
780 (meta_env%metavar(i)%ff_walls, i=1, meta_env%n_colvar), &
781 (meta_env%metavar(i)%vvp, i=1, meta_env%n_colvar), &
783 meta_env%hills_env%energy, &
784 meta_env%epot_walls, &
785 (meta_env%ekin_s)*2.0_dp/(real(meta_env%n_colvar, kind=
dp))*
kelvin
787 WRITE (iw,
'(f16.8,40f13.5)') meta_env%time*
femtoseconds, &
788 (meta_env%metavar(i)%ss0, i=1, meta_env%n_colvar), &
789 (meta_env%metavar(i)%ff_hills, i=1, meta_env%n_colvar), &
790 (meta_env%metavar(i)%ff_walls, i=1, meta_env%n_colvar), &
791 meta_env%hills_env%energy, &
799 IF (meta_env%extended_lagrange)
THEN
800 temp = meta_env%ekin_s*2.0_dp/(real(meta_env%n_colvar, kind=
dp))*
kelvin
801 meta_env%avg_temp = (meta_env%avg_temp*real(meta_env%n_steps, kind=
dp) + &
802 temp)/real(meta_env%n_steps + 1, kind=
dp)
804 "PRINT%TEMPERATURE_COLVAR", extension=
".metadynLog")
806 WRITE (iw,
'(T2,79("-"))')
807 WRITE (iw,
'( A,T51,f10.2,T71,f10.2)')
' COLVARS INSTANTANEOUS/AVERAGE TEMPERATURE ', &
808 temp, meta_env%avg_temp
809 WRITE (iw,
'(T2,79("-"))')
812 "PRINT%TEMPERATURE_COLVAR")
814 CALL timestop(handle)
827 SUBROUTINE hills(meta_env)
830 CHARACTER(len=*),
PARAMETER :: routinen =
'hills'
832 INTEGER :: handle, i, i_hills, ih, intermeta_steps, &
833 iter_nr, iw, n_colvar, n_hills_start, &
835 LOGICAL :: force_gauss
836 REAL(kind=
dp) :: cut_func, dfunc, diff, dp2, frac, &
837 slow_growth, v_now_here, v_to_fes, &
839 REAL(kind=
dp),
DIMENSION(:),
POINTER :: ddp, denf, diff_ss, local_last_hills, &
846 CALL timeset(routinen, handle)
848 NULLIFY (hills_env, multiple_walkers, logger, colvars, ddp, local_last_hills)
849 hills_env => meta_env%hills_env
851 colvars => meta_env%metavar
852 n_colvar = meta_env%n_colvar
853 n_step = meta_env%n_steps
858 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=iter_nr)
861 IF (meta_env%hills_env%restart)
THEN
862 meta_env%hills_env%restart = .false.
863 IF (meta_env%well_tempered)
THEN
864 CALL restart_hills(hills_env%ss_history, hills_env%delta_s_history, hills_env%ww_history, &
865 hills_env%ww, hills_env%n_hills, n_colvar, colvars, meta_env%metadyn_section, &
866 invdt_history=hills_env%invdt_history)
868 CALL restart_hills(hills_env%ss_history, hills_env%delta_s_history, hills_env%ww_history, &
869 hills_env%ww, hills_env%n_hills, n_colvar, colvars, meta_env%metadyn_section)
874 intermeta_steps = n_step - hills_env%old_hill_step
875 force_gauss = .false.
876 IF ((hills_env%min_disp > 0.0_dp) .AND. (hills_env%old_hill_number > 0) .AND. &
877 (intermeta_steps >= hills_env%min_nt_hills))
THEN
878 ALLOCATE (ddp(meta_env%n_colvar))
879 ALLOCATE (local_last_hills(meta_env%n_colvar))
881 local_last_hills(1:n_colvar) = hills_env%ss_history(1:n_colvar, hills_env%old_hill_number)
886 ddp(i) = colvars(i)%ss0 - local_last_hills(i)
887 IF (colvars(i)%periodic)
THEN
889 ddp(i) = sign(1.0_dp, asin(sin(ddp(i))))*acos(cos(ddp(i)))
891 dp2 = dp2 + ddp(i)**2
894 IF (dp2 > hills_env%min_disp)
THEN
897 "PRINT%PROGRAM_RUN_INFO", extension=
".metadynLog")
899 WRITE (unit=iw, fmt=
"(A,F0.6,A,F0.6)") &
900 " METADYN| Threshold value for COLVAR displacement exceeded: ", &
901 dp2,
" > ", hills_env%min_disp
904 "PRINT%PROGRAM_RUN_INFO")
907 DEALLOCATE (local_last_hills)
911 IF (((
modulo(intermeta_steps, hills_env%nt_hills) == 0) .OR. force_gauss) &
912 .AND. (.NOT. meta_env%restart) .AND. (hills_env%nt_hills > 0))
THEN
913 IF (meta_env%do_multiple_walkers) multiple_walkers => meta_env%multiple_walkers
915 n_hills_start = hills_env%n_hills
917 IF (meta_env%well_tempered)
THEN
920 DO ih = 1, hills_env%n_hills
923 diff = colvars(i)%ss0 - hills_env%ss_history(i, ih)
924 IF (colvars(i)%periodic)
THEN
926 diff = sign(1.0_dp, asin(sin(diff)))*acos(cos(diff))
928 diff = (diff)/hills_env%delta_s_history(i, ih)
931 v_to_fes = 1.0_dp + meta_env%wttemperature*hills_env%invdt_history(ih)
932 v_now_here = v_now_here + hills_env%ww_history(ih)/v_to_fes*exp(-0.5_dp*dp2)
934 wtww = hills_env%ww*exp(-v_now_here*meta_env%invdt)
935 ww = wtww*(1.0_dp + meta_env%wttemperature*meta_env%invdt)
936 CALL add_hill_single(hills_env, colvars, ww, hills_env%n_hills, n_colvar, meta_env%invdt)
938 CALL add_hill_single(hills_env, colvars, hills_env%ww, hills_env%n_hills, n_colvar)
941 IF (meta_env%do_multiple_walkers) multiple_walkers%n_hills_local = multiple_walkers%n_hills_local + 1
943 hills_env%old_hill_number = hills_env%n_hills
944 hills_env%old_hill_step = n_step
948 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=iter_nr)
952 "PRINT%PROGRAM_RUN_INFO", extension=
".metadynLog")
954 IF (meta_env%do_multiple_walkers)
THEN
955 WRITE (iw,
'(/,1X,"METADYN|",A,I0,A,I0,A,/)') &
956 ' Global/Local Hills number (', hills_env%n_hills,
'/', multiple_walkers%n_hills_local, &
959 WRITE (iw,
'(/,1X,"METADYN|",A,I0,A,/)')
' Hills number (', hills_env%n_hills,
') added.'
963 "PRINT%PROGRAM_RUN_INFO")
966 IF (meta_env%do_multiple_walkers)
THEN
969 "PRINT%HILLS", middle_name=
"LOCAL", extension=
".metadynLog")
971 WRITE (iw,
'(f12.1,30f13.5)') meta_env%time*
femtoseconds, &
972 (hills_env%ss_history(ih, hills_env%n_hills), ih=1, n_colvar), &
973 (hills_env%delta_s_history(ih, hills_env%n_hills), ih=1, n_colvar), &
974 hills_env%ww_history(hills_env%n_hills)
981 n_colvar, meta_env%metadyn_section)
987 "PRINT%HILLS", extension=
".metadynLog")
989 DO i_hills = n_hills_start + 1, hills_env%n_hills
990 WRITE (iw,
'(f12.1,30f13.5)') meta_env%time*
femtoseconds, &
991 (hills_env%ss_history(ih, i_hills), ih=1, n_colvar), &
992 (hills_env%delta_s_history(ih, i_hills), ih=1, n_colvar), &
993 hills_env%ww_history(i_hills)
1001 ALLOCATE (ddp(meta_env%n_colvar))
1002 ALLOCATE (diff_ss(meta_env%n_colvar))
1003 ALLOCATE (numf(meta_env%n_colvar))
1004 ALLOCATE (denf(meta_env%n_colvar))
1006 hills_env%energy = 0.0_dp
1008 colvars(ih)%ff_hills = 0.0_dp
1010 DO ih = 1, hills_env%n_hills
1011 slow_growth = 1.0_dp
1012 IF (hills_env%slow_growth .AND. (ih == hills_env%n_hills))
THEN
1013 slow_growth = real(n_step - hills_env%old_hill_step,
dp)/real(hills_env%nt_hills,
dp)
1018 diff_ss(i) = colvars(i)%ss0 - hills_env%ss_history(i, ih)
1019 IF (colvars(i)%periodic)
THEN
1021 diff_ss(i) = sign(1.0_dp, asin(sin(diff_ss(i))))*acos(cos(diff_ss(i)))
1023 IF (hills_env%delta_s_history(i, ih) == 0.0_dp)
THEN
1030 ddp(i) = (diff_ss(i))/hills_env%delta_s_history(i, ih)
1032 dp2 = dp2 + ddp(i)**2
1033 IF (hills_env%tail_cutoff > 0.0_dp)
THEN
1034 frac = abs(ddp(i))/hills_env%tail_cutoff
1035 numf(i) = frac**hills_env%p_exp
1036 denf(i) = frac**hills_env%q_exp
1037 cut_func = cut_func*(1.0_dp - numf(i))/(1.0_dp - denf(i))
1041 dfunc = hills_env%ww_history(ih)*exp(-0.5_dp*dp2)*slow_growth
1042 IF (meta_env%well_tempered) dfunc = dfunc/(1.0_dp + meta_env%wttemperature*hills_env%invdt_history(ih))
1043 hills_env%energy = hills_env%energy + dfunc*cut_func
1045 IF (hills_env%delta_s_history(i, ih) /= 0.0_dp)
THEN
1048 colvars(i)%ff_hills = colvars(i)%ff_hills + &
1049 ddp(i)/hills_env%delta_s_history(i, ih)*dfunc*cut_func
1050 IF (hills_env%tail_cutoff > 0.0_dp .AND. abs(diff_ss(i)) > 10.e-5_dp)
THEN
1051 colvars(i)%ff_hills = colvars(i)%ff_hills + &
1052 (hills_env%p_exp*numf(i)/(1.0_dp - numf(i)) - hills_env%q_exp*denf(i)/(1.0_dp - denf(i)))* &
1053 dfunc*cut_func/abs(diff_ss(i))
1059 DEALLOCATE (diff_ss)
1065 CALL timestop(handle)
1067 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)
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.