126#include "../../base/base_uses.f90"
132 CHARACTER(len=*),
PARAMETER,
PRIVATE :: moduleN =
'tamc_run'
146 SUBROUTINE qs_tamc(force_env, globenv, averages)
152 CHARACTER(LEN=*),
PARAMETER :: routinen =
'qs_tamc'
154 CHARACTER(LEN=20) :: ensemble
155 INTEGER :: handle, i, initialstep, iprint, isos, &
156 istep, j, md_stride, nmccycles, &
157 output_unit, rand2skip, run_type_id
158 INTEGER,
POINTER :: itimes
159 LOGICAL :: check, explicit, my_rm_restart_info, &
160 save_mem, should_stop
161 REAL(kind=
dp) :: auxrandom, inittime, rval, temp, &
162 time_iter_start, time_iter_stop
163 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:) :: an, fz, xieta, zbuff
164 REAL(kind=
dp),
ALLOCATABLE,
DIMENSION(:, :) :: r
165 REAL(kind=
dp),
POINTER :: constant, time, used_time
185 free_energy_section, fs_section, global_section, mc_section, md_section, motion_section, &
186 reftraj_section, subsys_section, work_section
195 CALL timeset(routinen, handle)
196 my_rm_restart_info = .true.
197 NULLIFY (para_env, fs_section, virial)
198 para_env => force_env%para_env
204 CALL md_env_create(md_env, md_section, para_env, force_env=force_env)
205 IF (
PRESENT(averages))
CALL set_md_env(md_env, averages=averages)
207 cpassert(
ASSOCIATED(globenv))
208 cpassert(
ASSOCIATED(force_env))
210 NULLIFY (particles, cell, simpar, itimes, used_time, subsys, &
211 md_ener, thermostats, barostat, reftraj, force_env_section, &
212 reftraj_section, work_section, atomic_kinds, &
213 local_particles, time, fe_env, free_energy_section, &
214 constraint_section, thermal_regions, subsys_i)
216 para_env => force_env%para_env
226 force_env_section => force_env%force_env_section
229 CALL cp_iterate(logger%iter_info, iter_nr=initialstep)
234 "CONSTRAINT_INFO", extension=
".shakeLog", log_filename=.false.)
236 "LAGRANGE_MULTIPLIERS", extension=
".LagrangeMultLog", log_filename=.false.)
247 globenv, global_section)
255 CALL set_md_env(md_env, thermostats=thermostats, barostat=barostat, thermal_regions=thermal_regions)
265 force_env_section=force_env_section)
269 IF (simpar%v0 == 0._dp) simpar%v0 = cell%deth
281 CALL set_md_env(md_env=md_env, simpar=simpar, fe_env=fe_env, cell=cell, &
288 CALL get_md_env(md_env, force_env=force_env, itimes=itimes, constant=constant, &
289 md_ener=md_ener, t=time, used_time=used_time)
295 force_env%meta_env%dt = force_env%meta_env%zdt
302 NULLIFY (mc_env, mc_par, mcaverages)
310 rng_stream_mc =
rng_stream_type(name=
"Random numbers for monte carlo acc/rej", &
322 cpassert(
str_comp(ensemble,
"TRADITIONAL"))
325 cpassert(nmccycles > 0)
329 cpassert(rand2skip >= 0)
333 CALL set_mc_par(mc_par, ensemble=ensemble, nstep=nmccycles, iprint=iprint, temperature=temp, &
334 beta=1.0_dp/temp/
boltzmann*
joule, exp_max_val=0.9_dp*log(huge(0.0_dp)), &
335 exp_min_val=0.9_dp*log(tiny(0.0_dp)), max_val=huge(0.0_dp), min_val=0.0_dp, &
336 source=para_env%source, group=para_env, ionode=para_env%is_source(), rand2skip=rand2skip)
339 IF (output_unit > 0)
THEN
340 WRITE (output_unit,
'(a,a)')
"HMC| Hybrid Monte Carlo Scheme "
341 WRITE (output_unit,
'(a,a)')
"HMC| Ensemble ", adjustl(ensemble)
342 WRITE (output_unit,
'(a,i0)')
"HMC| MC Cycles ", nmccycles
343 WRITE (output_unit,
'(a,i0,a)')
"HMC| Print every ", iprint,
" cycles"
344 WRITE (output_unit,
'(a,i0)')
"HMC| Number of random numbers to skip ", rand2skip
345 WRITE (output_unit,
'(a,f16.8,a)')
"HMC| Temperature ", temp,
"K"
350 CALL cp_subsys_get(subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
351 particles=particles, virial=virial)
354 auxrandom = rng_stream_mc%next()
355 DO j = 1, 3*
SIZE(particles%els)
356 auxrandom = globenv%gaussian_rng_stream%next()
362 CALL set_mc_env(mc_env, mc_par=mc_par, force_env=force_env)
374 check = virial%pv_availability
376 CALL cp_abort(__location__, &
377 "Virial evaluation not requested for this run in the input file! "// &
378 "You may consider to switch on the virial evaluation with the keyword: STRESS_TENSOR. "// &
379 "Be sure the method you are using can compute the virial!")
380 IF (
ASSOCIATED(force_env%sub_force_env))
THEN
381 DO i = 1,
SIZE(force_env%sub_force_env)
382 IF (
ASSOCIATED(force_env%sub_force_env(i)%force_env))
THEN
383 CALL force_env_get(force_env%sub_force_env(i)%force_env, subsys=subsys_i)
385 check = check .AND. virial%pv_availability
390 CALL cp_abort(__location__, &
391 "Virial evaluation not requested for all the force_eval sections present in"// &
392 " the input file! You have to switch on the virial evaluation with the keyword: STRESS_TENSOR"// &
393 " in each force_eval section. Be sure the method you are using can compute the virial!")
404 CALL cp_iterate(logger%iter_info, iter_nr=itimes)
415 meta_env_saved => force_env%meta_env
416 NULLIFY (force_env%meta_env)
418 force_env%meta_env => meta_env_saved
420 IF (
ASSOCIATED(force_env%qs_env))
THEN
423 force_env%qs_env%sim_time = 0.0_dp
424 force_env%qs_env%sim_step = 0
427 IF (
ASSOCIATED(force_env%meta_env))
THEN
428 IF (force_env%meta_env%langevin)
THEN
430 DO j = 1, (rand2skip - 1)/nmccycles
431 DO i = 1, force_env%meta_env%n_colvar
432 auxrandom = force_env%meta_env%rng(i)%next()
433 auxrandom = force_env%meta_env%rng(i)%next()
455 CALL tamc_force(force_env)
459 IF (simpar%do_respa)
THEN
469 CALL virial_evaluate(atomic_kinds%els, particles%els, local_particles, &
470 virial, force_env%para_env)
478 itimes = reftraj%info%first_snapshot - 1
479 md_stride = reftraj%info%stride
483 constraint_section,
"CONSTRAINT_INFO")
485 constraint_section,
"LAGRANGE_MULTIPLIERS")
488 ALLOCATE (r(1:3,
SIZE(particles%els)))
493 ALLOCATE (xieta(2*force_env%meta_env%n_colvar))
495 ALLOCATE (an(force_env%meta_env%n_colvar))
497 ALLOCATE (fz(force_env%meta_env%n_colvar))
499 ALLOCATE (zbuff(2*force_env%meta_env%n_colvar))
502 IF (output_unit > 0)
THEN
503 WRITE (output_unit,
'(a)')
"HMC|==== Initial average forces"
505 CALL metadyn_write_colvar_header(force_env)
506 moves%hmc%attempts = 0
507 moves%hmc%successes = 0
508 gmoves%hmc%attempts = 0
509 gmoves%hmc%successes = 0
510 IF (initialstep == 0)
THEN
513 DO i = 1, force_env%meta_env%n_colvar
518 i_rep_val=i, r_val=rval)
519 fz(i) = rval*rand2skip
523 CALL hmcsampler(globenv, force_env, mcaverages, r, mc_par, moves, gmoves, rng_stream_mc, output_unit, &
524 fz, zbuff, nskip=rand2skip)
525 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=0)
527 CALL write_restart(md_env=md_env, root_section=force_env%root_section)
529 IF (output_unit > 0)
THEN
530 WRITE (output_unit,
'(a)')
"HMC|==== end initial average forces"
534 CALL metadyn_write_colvar(force_env)
536 DO istep = 1, force_env%meta_env%TAMCSteps
539 time = time + force_env%meta_env%dt
540 IF (output_unit > 0)
THEN
541 WRITE (output_unit,
'(a)')
"HMC|==================================="
542 WRITE (output_unit,
'(a,1x,i0)')
"HMC| on z step ", istep
545 IF (
ASSOCIATED(force_env%qs_env))
THEN
546 force_env%qs_env%sim_time = time
547 force_env%qs_env%sim_step = itimes
548 force_env%meta_env%time = force_env%qs_env%sim_time
551 CALL cp_iterate(logger%iter_info, last=(istep == force_env%meta_env%TAMCSteps), iter_nr=itimes)
554 extension=
".shakeLog", log_filename=.false.)
556 logger, constraint_section, &
557 "LAGRANGE_MULTIPLIERS", extension=
".LagrangeMultLog", log_filename=.false.)
563 moves%hmc%attempts = 0
564 moves%hmc%successes = 0
565 CALL langevinvec(md_env, globenv, mc_env, moves, gmoves, r, &
566 rng_stream_mc, xieta, an, fz, mcaverages, zbuff)
570 constraint_section,
"CONSTRAINT_INFO")
572 constraint_section,
"LAGRANGE_MULTIPLIERS")
573 CALL cp_iterate(logger%iter_info, iter_nr=initialstep)
574 CALL metadyn_write_colvar(force_env)
590 IF (should_stop)
THEN
591 CALL cp_iterate(logger%iter_info, last=.true., iter_nr=itimes)
606 used_time = time_iter_stop - time_iter_start
607 time_iter_start = time_iter_stop
616 IF (output_unit > 0)
THEN
617 WRITE (output_unit,
'(a,1x,i0)')
"HMC| end z step ", istep
618 WRITE (output_unit,
'(a)')
"HMC|==================================="
621 CALL cp_iterate(logger%iter_info, last=.true., iter_nr=itimes)
622 force_env%qs_env%sim_time = 0.0_dp
623 force_env%qs_env%sim_step = 0
624 rand2skip = rand2skip + nmccycles*force_env%meta_env%TAMCSteps
625 IF (initialstep == 0) rand2skip = rand2skip + nmccycles
628 CALL write_restart(md_env=md_env, root_section=force_env%root_section)
656 CALL timestop(handle)
667 SUBROUTINE tamc_velocities_colvar(force_env, An)
669 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: an
671 CHARACTER(len=*),
PARAMETER :: routinen =
'tamc_velocities_colvar'
673 INTEGER :: handle, i_c
674 REAL(kind=
dp) :: dt, fft, sigma
679 NULLIFY (logger, meta_env, cv)
680 meta_env => force_env%meta_env
681 CALL timeset(routinen, handle)
688 meta_env%epot_walls = 0.0_dp
689 DO i_c = 1, meta_env%n_colvar
690 cv => meta_env%metavar(i_c)
691 fft = cv%ff_s + cv%ff_hills
693 cv%vvp = cv%vvp + 0.5_dp*dt*(fft/cv%mass - cv%gamma*cv%vvp)*(1.0_dp - 0.25_dp*dt*cv%gamma) + an(i_c)
694 meta_env%epot_walls = meta_env%epot_walls + cv%epot_walls
696 CALL timestop(handle)
697 END SUBROUTINE tamc_velocities_colvar
706 SUBROUTINE tamc_position_colvar(force_env, xieta)
708 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: xieta
710 CHARACTER(len=*),
PARAMETER :: routinen =
'tamc_position_colvar'
712 INTEGER :: handle, i_c
713 REAL(kind=
dp) :: dt, sigma
718 NULLIFY (logger, meta_env, cv)
719 meta_env => force_env%meta_env
722 CALL timeset(routinen, handle)
730 DO i_c = 1, meta_env%n_colvar
731 cv => meta_env%metavar(i_c)
734 cv%ss0 = cv%ss0 + dt*cv%vvp + dt*sqrt(dt/12.0_dp)*sigma*xieta(i_c + meta_env%n_colvar)
735 IF (cv%periodic)
THEN
737 cv%ss0 = sign(1.0_dp, asin(sin(cv%ss0)))*acos(cos(cv%ss0))
740 CALL timestop(handle)
742 END SUBROUTINE tamc_position_colvar
751 SUBROUTINE tamc_force(force_env, zpot)
753 REAL(kind=
dp),
INTENT(inout),
OPTIONAL :: zpot
755 CHARACTER(len=*),
PARAMETER :: routinen =
'tamc_force'
757 INTEGER :: handle, i, i_c, icolvar, ii
759 REAL(kind=
dp) :: diff_ss, dt, rval
768 NULLIFY (logger, meta_env)
769 meta_env => force_env%meta_env
772 CALL timeset(routinen, handle)
774 NULLIFY (colvar_p, subsys, cv, ss0_section, vvp_section, ss_section)
778 IF (.NOT. meta_env%restart) meta_env%n_steps = meta_env%n_steps + 1
780 DO i_c = 1, meta_env%n_colvar
781 cv => meta_env%metavar(i_c)
784 cv%ss = subsys%colvar_p(icolvar)%colvar%ss
786 IF (meta_env%restart)
THEN
792 i_rep_val=i_c, r_val=rval)
800 CALL setup_velocities_z(force_env)
802 i_rep_val=i_c, r_val=rval)
805 CALL setup_velocities_z(force_env)
811 i_rep_val=i_c, r_val=rval)
822 meta_env%restart = .false.
823 meta_env%epot_s = 0.0_dp
824 meta_env%epot_walls = 0.0_dp
825 DO i_c = 1, meta_env%n_colvar
826 cv => meta_env%metavar(i_c)
827 diff_ss = cv%ss - cv%ss0
828 IF (cv%periodic)
THEN
830 diff_ss = sign(1.0_dp, asin(sin(diff_ss)))*acos(cos(diff_ss))
832 cv%epot_s = 0.5_dp*cv%lambda*diff_ss*diff_ss
833 cv%ff_s = cv%lambda*(diff_ss)
834 meta_env%epot_s = meta_env%epot_s + cv%epot_s
837 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
838 i = colvar_p(icolvar)%colvar%i_atom(ii)
839 particles%els(i)%f = particles%els(i)%f - cv%ff_s*colvar_p(icolvar)%colvar%dsdr(:, ii)
843 IF (
PRESENT(zpot)) zpot = meta_env%epot_s
846 CALL timestop(handle)
847 END SUBROUTINE tamc_force
865 SUBROUTINE langevinvec(md_env, globenv, mc_env, moves, gmoves, r, &
866 rng_stream_mc, xieta, An, fz, averages, zbuff)
872 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: r
874 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: xieta, an, fz
876 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: zbuff
878 INTEGER :: iprint, ivar, nparticle, nparticle_kind, &
880 REAL(kind=
dp) :: dt,
gamma, mass, sigma
900 NULLIFY (logger, mc_par)
905 NULLIFY (simpar, force_env, para_env)
907 NULLIFY (subsys, cell)
909 NULLIFY (atomic_kinds, local_particles, particles, local_molecules, molecules, molecule_kinds, gci)
911 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
914 CALL get_mc_par(mc_par, nstep=nstep, iprint=iprint)
917 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
924 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
925 particles=particles, local_molecules=local_molecules, molecules=molecules, &
926 molecule_kinds=molecule_kinds, gci=gci, virial=virial)
928 nparticle_kind = atomic_kinds%n_els
929 atomic_kind_set => atomic_kinds%els
930 molecule_kind_set => molecule_kinds%els
932 nparticle = particles%n_els
933 particle_set => particles%els
934 molecule_set => molecules%els
935 cpassert(
ASSOCIATED(force_env%meta_env))
936 cpassert(force_env%meta_env%langevin)
939 DO ivar = 1, force_env%meta_env%n_colvar
940 xieta(ivar) = force_env%meta_env%rng(ivar)%next()
941 xieta(ivar + force_env%meta_env%n_colvar) = force_env%meta_env%rng(ivar)%next()
942 gamma = force_env%meta_env%metavar(ivar)%gamma
943 mass = force_env%meta_env%metavar(ivar)%mass
945 an(ivar) = 0.5_dp*sqrt(dt)*sigma*(xieta(ivar)*(1.0_dp - 0.5_dp*dt*
gamma) - &
946 dt*
gamma*xieta(ivar + force_env%meta_env%n_colvar)/sqrt(12.0_dp))
949 CALL tamc_velocities_colvar(force_env, an)
951 CALL tamc_position_colvar(force_env, xieta)
953 CALL hmcsampler(globenv, force_env, averages, r, mc_par, moves, gmoves, rng_stream_mc, output_unit, fz, zbuff)
962 CALL tamc_velocities_colvar(force_env, an)
966 END SUBROUTINE langevinvec
986 SUBROUTINE hmcsampler(globenv, force_env, averages, r, mc_par, moves, gmoves, rng_stream_mc, output_unit, &
991 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: r
995 INTEGER,
INTENT(IN) :: output_unit
996 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: fz, zbuff
997 INTEGER,
INTENT(IN),
OPTIONAL :: nskip
999 INTEGER :: i, iprint, ishift, it1, j, nsamples, &
1001 REAL(kind=
dp) :: energy_check, old_epx, old_epz, t1
1004 IF (
PRESENT(nskip))
THEN
1016 CALL get_mc_par(mc_par, nstep=nstep, iprint=iprint)
1017 meta_env_saved => force_env%meta_env
1018 NULLIFY (force_env%meta_env)
1020 force_env%meta_env => meta_env_saved
1022 old_epz = force_env%meta_env%epot_s
1024 averages%ave_energy = 0.0_dp
1025 t1 = force_env%qs_env%sim_time
1026 it1 = force_env%qs_env%sim_step
1027 IF (output_unit > 0)
THEN
1028 WRITE (output_unit,
'(a,l4)')
"HMC|restart? ", force_env%meta_env%restart
1029 WRITE (output_unit,
'(a,3(f16.8,1x))') &
1030 "HMC|Ep, Epx, Epz ", old_epx + force_env%meta_env%epot_s, old_epx, force_env%meta_env%epot_s
1031 WRITE (output_unit,
'(a)')
"#HMC| No | z.. | theta.. | ff_z... | ff_z/n |"
1034 IF (mod(i, iprint) == 0 .AND. (output_unit > 0))
THEN
1035 WRITE (output_unit,
'(a,1x,i0)')
"HMC|========== On Monte Carlo cycle ", i + ishift
1036 WRITE (output_unit,
'(a)')
"HMC| Attempting a minitrajectory move"
1037 WRITE (output_unit,
'(a,1x,i0)')
"HMC| start mini-trajectory", i + ishift
1038 WRITE (output_unit,
'(a,1x,i0,1x)',
advance=
"no")
"#HMC|0 ", i + ishift
1039 DO j = 1, force_env%meta_env%n_colvar
1040 WRITE (output_unit,
'(f16.8,1x,f16.8,1x,f16.8)',
advance=
"no") force_env%meta_env%metavar(j)%ss0, &
1041 force_env%meta_env%metavar(j)%ss, &
1042 force_env%meta_env%metavar(j)%ff_s
1044 WRITE (output_unit, *)
1047 CALL mc_hmc_move(mc_par, force_env, globenv, moves, gmoves, old_epx, old_epz, energy_check, &
1048 r, output_unit, rng_stream_mc, zbuff)
1051 averages%ave_energy = averages%ave_energy*real(i - 1,
dp)/real(i,
dp) + &
1053 DO j = 1, force_env%meta_env%n_colvar
1054 fz(j) = fz(j) + force_env%meta_env%metavar(j)%ff_s
1056 IF (output_unit > 0)
THEN
1057 WRITE (output_unit,
'(a,1x,i0)')
"HMC|end mini-trajectory", i + ishift
1060 WRITE (output_unit,
'(a,1x,i0,1x)',
advance=
"no")
"#HMC|1 ", i + ishift
1061 DO j = 1, force_env%meta_env%n_colvar
1062 WRITE (output_unit,
'(f16.8,1x,f16.8,1x,f16.8,1x,f16.8)',
advance=
"no") force_env%meta_env%metavar(j)%ss0, &
1063 force_env%meta_env%metavar(j)%ss, &
1064 force_env%meta_env%metavar(j)%ff_s, fz(j)/real(i + ishift,
dp)
1066 WRITE (output_unit, *)
1068 nsamples = nsamples + 1
1069 IF (mod(i, iprint) == 0 .AND. (output_unit > 0))
THEN
1070 WRITE (output_unit,
'(a,f16.8)')
"HMC| Running average for potential energy ", averages%ave_energy
1071 WRITE (output_unit,
'(a,1x,i0)')
"HMC|======== End Monte Carlo cycle ", i + ishift
1088 force_env%qs_env%sim_time = t1
1089 force_env%qs_env%sim_step = it1
1090 IF (output_unit > 0)
THEN
1091 WRITE (output_unit,
'(a,i0,a,i0,a,f16.8)')
"HMC| local acceptance ratio: ", moves%hmc%successes,
"/", &
1092 moves%hmc%attempts,
"=", real(moves%hmc%successes,
dp)/real(moves%hmc%attempts,
dp)
1093 WRITE (output_unit,
'(a,i0,a,i0,a,f16.8)')
"HMC| global acceptance ratio: ", gmoves%hmc%successes,
"/", &
1094 gmoves%hmc%attempts,
"=", real(gmoves%hmc%successes,
dp)/real(gmoves%hmc%attempts,
dp)
1097 DO j = 1, force_env%meta_env%n_colvar
1098 force_env%meta_env%metavar(j)%ff_s = fz(j)/nsamples
1100 END SUBROUTINE hmcsampler
1120 SUBROUTINE mc_hmc_move(mc_par, force_env, globenv, moves, gmoves, old_epx, old_epz, &
1121 energy_check, r, output_unit, rng_stream, zbuff)
1127 REAL(kind=
dp),
INTENT(INOUT) :: old_epx, old_epz, energy_check
1128 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: r
1129 INTEGER,
INTENT(IN) :: output_unit
1131 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: zbuff
1133 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mc_hmc_move'
1135 INTEGER :: handle, iatom, j, natoms, source
1136 LOGICAL :: ionode, localise
1137 REAL(kind=
dp) :: beta, energy_term, exp_max_val, &
1138 exp_min_val, new_energy, new_epx, &
1139 new_epz, rand,
value, w
1149 CALL timeset(routinen, handle)
1151 CALL get_qs_env(force_env%qs_env, input=input)
1156 beta=beta, exp_max_val=exp_max_val, &
1157 exp_min_val=exp_min_val, source=source, group=group)
1161 NULLIFY (particles_set, oldsys, meta_env_saved, hmc_ekin)
1165 natoms =
SIZE(particles_set%els)
1171 moves%hmc%attempts = moves%hmc%attempts + 1
1172 gmoves%hmc%attempts = gmoves%hmc%attempts + 1
1175 DO iatom = 1, natoms
1176 r(1:3, iatom) = particles_set%els(iatom)%r(1:3)
1180 DO j = 1, force_env%meta_env%n_colvar
1181 zbuff(j) = force_env%meta_env%metavar(j)%ss
1182 zbuff(j + force_env%meta_env%n_colvar) = force_env%meta_env%metavar(j)%ff_s
1183 IF ((oldsys%colvar_p(force_env%meta_env%metavar(j)%icolvar)%colvar%type_id ==
hbp_colvar_id) .OR. &
1184 (oldsys%colvar_p(force_env%meta_env%metavar(j)%icolvar)%colvar%type_id ==
wc_colvar_id))
THEN
1190 meta_env_saved => force_env%meta_env
1191 NULLIFY (force_env%meta_env)
1192 force_env%qs_env%sim_time = 0.0_dp
1193 force_env%qs_env%sim_step = 0
1194 IF (.NOT. localise)
THEN
1197 CALL qs_mol_dyn(force_env, globenv, hmc_e_initial=hmc_ekin%initial_ekin, hmc_e_final=hmc_ekin%final_ekin)
1198 IF (.NOT. localise)
THEN
1205 force_env%meta_env => meta_env_saved
1206 CALL tamc_force(force_env, zpot=new_epz)
1207 new_energy = new_epx + new_epz
1208 IF (output_unit > 0)
THEN
1209 WRITE (output_unit,
'(a,4(f16.8,1x))') &
1210 "HMC|old Ep, Ekx, Epz, Epx ", old_epx + old_epz, hmc_ekin%initial_ekin, old_epz, old_epx
1211 WRITE (output_unit,
'(a,4(f16.8,1x))')
"HMC|new Ep, Ekx, Epz, Epx ", new_energy, hmc_ekin%final_ekin, new_epz, new_epx
1213 energy_term = new_energy - old_epx - old_epz + hmc_ekin%final_ekin - hmc_ekin%initial_ekin
1215 value = -beta*(energy_term)
1217 IF (
value > exp_max_val)
THEN
1219 ELSEIF (
value < exp_min_val)
THEN
1225 rand = rng_stream%next()
1228 moves%hmc%successes = moves%hmc%successes + 1
1229 gmoves%hmc%successes = gmoves%hmc%successes + 1
1231 energy_check = energy_check + (new_energy - old_epx - old_epz)
1236 DO iatom = 1, natoms
1237 particles_set%els(iatom)%r(1:3) = r(1:3, iatom)
1239 DO j = 1, force_env%meta_env%n_colvar
1240 force_env%meta_env%metavar(j)%ss = zbuff(j)
1241 force_env%meta_env%metavar(j)%ff_s = zbuff(j + force_env%meta_env%n_colvar)
1246 DEALLOCATE (hmc_ekin)
1249 CALL timestop(handle)
1251 END SUBROUTINE mc_hmc_move
1257 SUBROUTINE metadyn_write_colvar_header(force_env)
1260 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_write_colvar_header'
1262 CHARACTER(len=100) :: aux, fmt
1263 CHARACTER(len=255) :: label1, label2, label3, label4, label5, &
1265 INTEGER :: handle, i, iw, m
1269 NULLIFY (logger, meta_env)
1270 meta_env => force_env%meta_env
1271 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
1273 CALL timeset(routinen, handle)
1277 "PRINT%COLVAR", extension=
".metadynLog")
1285 DO i = 1, meta_env%n_colvar
1286 WRITE (aux,
'(a,i0)')
"z_", i
1287 label1 = trim(label1)//trim(aux)
1288 m = 15*i - len_trim(label1) - 1
1289 label1 = trim(label1)//repeat(
" ", m)//
"|"
1290 WRITE (aux,
'(a,i0)')
"Theta_", i
1291 label2 = trim(label2)//trim(aux)
1292 m = 15*i - len_trim(label2) - 1
1293 label2 = trim(label2)//repeat(
" ", m)//
"|"
1294 WRITE (aux,
'(a,i0)')
"F_z", i
1295 label3 = trim(label3)//trim(aux)
1296 m = 15*i - len_trim(label3) - 1
1297 label3 = trim(label3)//repeat(
" ", m)//
"|"
1298 WRITE (aux,
'(a,i0)')
"F_h", i
1299 label4 = trim(label4)//trim(aux)
1300 m = 15*i - len_trim(label4) - 1
1301 label4 = trim(label4)//repeat(
" ", m)//
"|"
1302 WRITE (aux,
'(a,i0)')
"F_w", i
1303 label5 = trim(label5)//trim(aux)
1304 m = 15*i - len_trim(label5) - 1
1305 label5 = trim(label5)//repeat(
" ", m)//
"|"
1306 WRITE (aux,
'(a,i0)')
"v_z", i
1307 label6 = trim(label6)//trim(aux)
1308 m = 15*i - len_trim(label6) - 1
1309 label6 = trim(label6)//repeat(
" ", m)//
"|"
1311 WRITE (fmt,
'("(a17,6a",i0 ,",4a15)")') meta_env%n_colvar*15
1312 WRITE (iw, trim(fmt))
"#Time[fs] |", &
1328 CALL timestop(handle)
1330 END SUBROUTINE metadyn_write_colvar_header
1336 SUBROUTINE metadyn_write_colvar(force_env)
1339 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_write_colvar'
1341 INTEGER :: handle, i, i_c, iw
1342 REAL(kind=
dp) :: temp
1347 NULLIFY (logger, meta_env, cv)
1348 meta_env => force_env%meta_env
1349 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
1351 CALL timeset(routinen, handle)
1354 IF (meta_env%langevin)
THEN
1355 meta_env%ekin_s = 0.0_dp
1357 DO i_c = 1, meta_env%n_colvar
1358 cv => meta_env%metavar(i_c)
1359 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
1365 "PRINT%COLVAR", extension=
".metadynLog")
1367 IF (meta_env%extended_lagrange)
THEN
1368 WRITE (iw,
'(f16.8,70f15.8)') meta_env%time*
femtoseconds, &
1369 (meta_env%metavar(i)%ss0, i=1, meta_env%n_colvar), &
1370 (meta_env%metavar(i)%ss, i=1, meta_env%n_colvar), &
1371 (meta_env%metavar(i)%ff_s, i=1, meta_env%n_colvar), &
1372 (meta_env%metavar(i)%ff_hills, i=1, meta_env%n_colvar), &
1373 (meta_env%metavar(i)%ff_walls, i=1, meta_env%n_colvar), &
1374 (meta_env%metavar(i)%vvp, i=1, meta_env%n_colvar), &
1376 meta_env%hills_env%energy, &
1377 meta_env%epot_walls, &
1378 (meta_env%ekin_s)*2.0_dp/(real(meta_env%n_colvar, kind=
dp))*
kelvin
1380 WRITE (iw,
'(f16.8,40f13.5)') meta_env%time*
femtoseconds, &
1381 (meta_env%metavar(i)%ss0, i=1, meta_env%n_colvar), &
1382 (meta_env%metavar(i)%ff_hills, i=1, meta_env%n_colvar), &
1383 (meta_env%metavar(i)%ff_walls, i=1, meta_env%n_colvar), &
1384 meta_env%hills_env%energy, &
1391 IF (meta_env%extended_lagrange)
THEN
1392 temp = meta_env%ekin_s*2.0_dp/(real(meta_env%n_colvar, kind=
dp))*
kelvin
1393 meta_env%avg_temp = (meta_env%avg_temp*real(meta_env%n_steps, kind=
dp) + &
1394 temp)/real(meta_env%n_steps + 1, kind=
dp)
1396 "PRINT%TEMPERATURE_COLVAR", extension=
".metadynLog")
1398 WRITE (iw,
'(T2,79("-"))')
1399 WRITE (iw,
'( A,T51,f10.2,T71,f10.2)')
' COLVARS INSTANTANEOUS/AVERAGE TEMPERATURE ', &
1400 temp, meta_env%avg_temp
1401 WRITE (iw,
'(T2,79("-"))')
1404 "PRINT%TEMPERATURE_COLVAR")
1406 CALL timestop(handle)
1408 END SUBROUTINE metadyn_write_colvar
1414 SUBROUTINE setup_velocities_z(force_env)
1418 REAL(kind=
dp) :: ekin_w, fac_t
1423 meta_env => force_env%meta_env
1424 meta_env%ekin_s = 0.0_dp
1425 DO i_c = 1, meta_env%n_colvar
1426 cv => meta_env%metavar(i_c)
1427 cv%vvp = force_env%globenv%gaussian_rng_stream%next()
1428 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
1430 ekin_w = 0.5_dp*meta_env%temp_wanted*real(meta_env%n_colvar, kind=
dp)
1431 fac_t = sqrt(ekin_w/max(meta_env%ekin_s, 1.0e-8_dp))
1432 DO i_c = 1, meta_env%n_colvar
1433 cv => meta_env%metavar(i_c)
1434 cv%vvp = cv%vvp*fac_t
1436 END SUBROUTINE setup_velocities_z
represent a simple array based list of the given type
Define the atomic kind types and their sub types.
Handles the type to compute averages during an MD.
Barostat structure: module containing barostat available for MD.
subroutine, public create_barostat_type(barostat, md_section, force_env, simpar, globenv)
...
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 wc_colvar_id
integer, parameter, public hbp_colvar_id
subroutine, public fix_atom_control(force_env, w)
allows for fix atom constraints
Routines to handle the external control of CP2K.
subroutine, public external_control(should_stop, flag, globenv, target_time, start_time, force_check)
External manipulations during a run : when the <PROJECT_NAME>.EXIT_$runtype command is sent the progr...
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...
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,...
integer, parameter, public cp_p_file
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.
integer function, public cp_print_key_should_output(iteration_info, basis_section, print_key_path, used_print_key, first_time)
returns what should be done with the given property if btest(res,cp_p_store) then the property should...
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
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_calc_energy_force(force_env, calc_force, consistent_energies, skip_external_control, eval_energy_forces, require_consistent_energy_force, linres, calc_stress_tensor)
Interface routine for force and energy calculations.
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 types for metadynamics calculation
subroutine, public fe_env_create(fe_env, fe_section)
creates the fe_env
Calculation of the incomplete Gamma function F_n(t) for multi-center integrals over Cartesian Gaussia...
Define type storing the global information of a run. Keep the amount of stored data small....
Defines the basic variable types.
integer, parameter, public dp
Machine interface based on Fortran 2003 and POSIX.
real(kind=dp) function, public m_walltime()
returns time from a real-time clock, protected against rolling early/easily
contains the subroutines for dealing with the mc_env
subroutine, public get_mc_env(mc_env, mc_par, force_env)
provides a method for getting the various structures attached to an mc_env
subroutine, public mc_env_create(mc_env)
creates and initializes an mc_env
subroutine, public set_mc_env(mc_env, mc_par, force_env)
provides a method for attaching various structures to an mc_env
subroutine, public mc_env_release(mc_env)
releases the given mc env
contains miscellaneous subroutines used in the Monte Carlo runs, mostly I/O stuff
subroutine, public mc_averages_release(averages)
deallocates the structure that holds running averages of MC variables
subroutine, public mc_averages_create(averages)
initializes the structure that holds running averages of MC variables
control the handling of the move data in Monte Carlo (MC) simulations
subroutine, public mc_moves_release(moves)
deallocates all the structures and nullifies the pointer
subroutine, public init_mc_moves(moves)
allocates and initializes the structure to record all move attempts/successes
holds all the structure types needed for Monte Carlo, except the mc_environment_type
subroutine, public get_mc_par(mc_par, nstep, nvirial, iuptrans, iupcltrans, iupvolume, nmoves, nswapmoves, rm, cl, diff, nstart, source, group, lbias, ionode, lrestart, lstop, rmvolume, rmcltrans, rmbond, rmangle, rmrot, rmtrans, temperature, pressure, rclus, beta, pmswap, pmvolume, pmtraion, pmtrans, pmcltrans, ensemble, program, restart_file_name, molecules_file, moves_file, coords_file, energy_file, displacement_file, cell_file, dat_file, data_file, box2_file, fft_lib, iprint, rcut, ldiscrete, discrete_step, pmavbmc, pbias, avbmc_atom, avbmc_rmin, avbmc_rmax, rmdihedral, input_file, mc_molecule_info, pmswap_mol, pmavbmc_mol, pmtrans_mol, pmrot_mol, pmtraion_mol, mc_input_file, mc_bias_file, pmvol_box, pmclus_box, virial_temps, exp_min_val, exp_max_val, min_val, max_val, eta, pmhmc, pmhmc_box, lhmc, rand2skip)
...
subroutine, public set_mc_par(mc_par, rm, cl, diff, nstart, rmvolume, rmcltrans, rmbond, rmangle, rmdihedral, rmrot, rmtrans, program, nmoves, nswapmoves, lstop, temperature, pressure, rclus, iuptrans, iupcltrans, iupvolume, pmswap, pmvolume, pmtraion, pmtrans, pmcltrans, beta, rcut, iprint, lbias, nstep, lrestart, ldiscrete, discrete_step, pmavbmc, mc_molecule_info, pmavbmc_mol, pmtrans_mol, pmrot_mol, pmtraion_mol, pmswap_mol, avbmc_rmin, avbmc_rmax, avbmc_atom, pbias, ensemble, pmvol_box, pmclus_box, eta, mc_input_file, mc_bias_file, exp_max_val, exp_min_val, min_val, max_val, pmhmc, pmhmc_box, lhmc, ionode, source, group, rand2skip)
changes the private elements of the mc_parameters_type
Split md_ener module from md_environment_type.
subroutine, public create_md_ener(md_ener)
retains the given md_ener structure
prints all energy info per timestep to the screen or to user defined output files
subroutine, public initialize_md_ener(md_ener, force_env, simpar)
...
subroutine, public md_energy(md_env, md_ener)
...
subroutine, public set_md_env(md_env, itimes, constant, cell, simpar, fe_env, force_env, para_env, init, first_time, thermostats, barostat, reftraj, md_ener, averages, thermal_regions, ehrenfest_md)
Set the integrator environment to the correct program.
subroutine, public md_env_create(md_env, md_section, para_env, force_env)
Creates MD environment Purpose: Initialise the integrator environment. retain the para_env for this e...
subroutine, public md_env_release(md_env)
releases the given md env
subroutine, public get_md_env(md_env, itimes, constant, used_time, cell, simpar, npt, force_env, para_env, reftraj, t, init, first_time, fe_env, thermostats, barostat, thermostat_coeff, thermostat_part, thermostat_shell, thermostat_baro, thermostat_fast, thermostat_slow, md_ener, averages, thermal_regions, ehrenfest_md)
get components of MD environment type
Perform a molecular dynamics (MD) run using QUICKSTEP.
subroutine, public qs_mol_dyn(force_env, globenv, averages, rm_restart_info, hmc_e_initial, hmc_e_final, mdctrl)
Main driver module for Molecular Dynamics.
Interface to the message passing library MPI.
represent a simple array based list of the given type
Define the molecule kind structure types and the corresponding functionality.
represent a simple array based list of the given type
Define the data structure for the molecule information.
Parallel (pseudo)random number generator (RNG) for multiple streams and substreams of random numbers.
subroutine advance(self, e, c)
Advance the state by n steps, i.e. jump n steps forward, if n > 0, or backward if n < 0.
integer, parameter, public uniform
represent a simple array based list of the given type
Define the data structure for the particle information.
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
subroutine, public apply_qmmm_walls_reflective(force_env)
Apply reflective QM walls in order to avoid QM atoms escaping from the QM Box.
subroutine, public get_qs_env(qs_env, atomic_kind_set, qs_kind_set, cell, super_cell, cell_ref, use_ref_cell, kpoints, dft_control, mos, sab_orb, sab_all, qmmm, qmmm_periodic, sac_ae, sac_ppl, sac_lri, sap_ppnl, sab_vdw, sab_scp, sap_oce, sab_lrc, sab_se, sab_xtbe, sab_tbe, sab_core, sab_xb, sab_xtb_pp, sab_xtb_nonbond, sab_almo, sab_kp, sab_kp_nosym, particle_set, energy, force, matrix_h, matrix_h_im, matrix_ks, matrix_ks_im, matrix_vxc, run_rtp, rtp, matrix_h_kp, matrix_h_im_kp, matrix_ks_kp, matrix_ks_im_kp, matrix_vxc_kp, kinetic_kp, matrix_s_kp, matrix_w_kp, matrix_s_ri_aux_kp, matrix_s, matrix_s_ri_aux, matrix_w, matrix_p_mp2, matrix_p_mp2_admm, rho, rho_xc, pw_env, ewald_env, ewald_pw, active_space, mpools, input, para_env, blacs_env, scf_control, rel_control, kinetic, qs_charges, vppl, rho_core, rho_nlcc, rho_nlcc_g, ks_env, ks_qmmm_env, wf_history, scf_env, local_particles, local_molecules, distribution_2d, dbcsr_dist, molecule_kind_set, molecule_set, subsys, cp_subsys, oce, local_rho_set, rho_atom_set, task_list, task_list_soft, rho0_atom_set, rho0_mpole, rhoz_set, ecoul_1c, rho0_s_rs, rho0_s_gs, do_kpoints, has_unit_metric, requires_mo_derivs, mo_derivs, mo_loc_history, nkind, natom, nelectron_total, nelectron_spin, efield, neighbor_list_id, linres_control, xas_env, virial, cp_ddapc_env, cp_ddapc_ewald, outer_scf_history, outer_scf_ihistory, x_data, et_coupling, dftb_potential, results, se_taper, se_store_int_env, se_nddo_mpole, se_nonbond_env, admm_env, lri_env, lri_density, exstate_env, ec_env, harris_env, dispersion_env, gcp_env, vee, rho_external, external_vxc, mask, mp2_env, bs_env, kg_env, wanniercentres, atprop, ls_scf_env, do_transport, transport_env, v_hartree_rspace, s_mstruct_changed, rho_changed, potential_changed, forces_up_to_date, mscfg_env, almo_scf_env, gradient_history, variable_history, embed_pot, spin_embed_pot, polar_env, mos_last_converged, eeq, rhs)
Get the QUICKSTEP environment.
Does all kind of post scf calculations for GPW/GAPW.
subroutine, public scf_post_calculation_gpw(qs_env, wf_type, do_mp2)
collects possible post - scf calculations and prints info / computes properties.
provides a uniform framework to add references to CP2K cite and output these
subroutine, public cite_reference(key)
marks a given reference as cited.
initialization of the reftraj structure used to analyse previously generated trajectories
subroutine, public create_reftraj(reftraj, reftraj_section, para_env)
...
Initialize the analysis of trajectories to be done by activating the REFTRAJ ensemble.
subroutine, public initialize_reftraj(reftraj, reftraj_section, md_env)
...
Methods for storing MD parameters type.
subroutine, public read_md_section(simpar, motion_section, md_section)
Reads the MD section and setup the simulation parameters type.
Type for storing MD parameters.
subroutine, public release_simpar_type(simpar)
Releases the simulation parameters type.
subroutine, public create_simpar_type(simpar)
Creates the simulation parameters type.
Utilities for string manipulations.
elemental logical function, public str_comp(str1, str2)
...
Perform a temperature accelarated hybrid monte carlo (TAHMC) run using QUICKSTEP.
subroutine, public qs_tamc(force_env, globenv, averages)
Driver routine for TAHMC.
Thermal regions type: to initialize and control the temperature of different regions.
Setup of regions with different temperature.
subroutine, public create_thermal_regions(thermal_regions, md_section, simpar, force_env)
create thermal_regions
subroutine, public create_thermostats(thermostats, md_section, force_env, simpar, para_env, globenv, global_section)
...
Thermostat structure: module containing thermostat available for MD.
subroutine, public virial_evaluate(atomic_kind_set, particle_set, local_particles, virial, igroup)
Computes the kinetic part of the pressure tensor and updates the full VIRIAL (PV)
Handling of the Wiener process currently employed in turn of the Langevin dynamics.
subroutine, public create_wiener_process(md_env)
Create a Wiener process for Langevin dynamics and initialize an independent random number generator f...
subroutine, public create_wiener_process_cv(meta_env)
Create a Wiener process for Langevin dynamics used for metadynamics and initialize an independent ran...
represent a list of objects
Provides all information about an atomic kind.
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,...
structure to store local (to a processor) ordered lists of integers.
wrapper to abstract the force evaluation of the various methods
contains the initially parsed file and the initial parallel environment
stores all the informations relevant to an mpi environment
represent a list of objects
represent a list of objects
represent a list of objects
Simulation parameter type for molecular dynamics.