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
274 CALL set_md_env(md_env=md_env, simpar=simpar, fe_env=fe_env, cell=cell, &
281 CALL get_md_env(md_env, force_env=force_env, itimes=itimes, constant=constant, &
282 md_ener=md_ener, t=time, used_time=used_time)
288 force_env%meta_env%dt = force_env%meta_env%zdt
294 NULLIFY (mc_env, mc_par, mcaverages)
301 rng_stream_mc =
rng_stream_type(name=
"Random numbers for monte carlo acc/rej", &
311 cpassert(
str_comp(ensemble,
"TRADITIONAL"))
314 cpassert(nmccycles > 0)
318 cpassert(rand2skip >= 0)
321 CALL set_mc_par(mc_par, ensemble=ensemble, nstep=nmccycles, iprint=iprint, temperature=temp, &
322 beta=1.0_dp/temp/
boltzmann*
joule, exp_max_val=0.9_dp*log(huge(0.0_dp)), &
323 exp_min_val=0.9_dp*log(tiny(0.0_dp)), max_val=huge(0.0_dp), min_val=0.0_dp, &
324 source=para_env%source, group=para_env, ionode=para_env%is_source(), rand2skip=rand2skip)
327 IF (output_unit > 0)
THEN
328 WRITE (output_unit,
'(a,a)')
"HMC| Hybrid Monte Carlo Scheme "
329 WRITE (output_unit,
'(a,a)')
"HMC| Ensemble ", adjustl(ensemble)
330 WRITE (output_unit,
'(a,i0)')
"HMC| MC Cycles ", nmccycles
331 WRITE (output_unit,
'(a,i0,a)')
"HMC| Print every ", iprint,
" cycles"
332 WRITE (output_unit,
'(a,i0)')
"HMC| Number of random numbers to skip ", rand2skip
333 WRITE (output_unit,
'(a,f16.8,a)')
"HMC| Temperature ", temp,
"K"
338 CALL cp_subsys_get(subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
339 particles=particles, virial=virial)
342 auxrandom = rng_stream_mc%next()
343 DO j = 1, 3*
SIZE(particles%els)
344 auxrandom = globenv%gaussian_rng_stream%next()
350 CALL set_mc_env(mc_env, mc_par=mc_par, force_env=force_env)
362 check = virial%pv_availability
363 IF (.NOT. check)
THEN
364 CALL cp_abort(__location__, &
365 "Virial evaluation not requested for this run in the input file! "// &
366 "You may consider to switch on the virial evaluation with the keyword: STRESS_TENSOR. "// &
367 "Be sure the method you are using can compute the virial!")
369 IF (
ASSOCIATED(force_env%sub_force_env))
THEN
370 DO i = 1,
SIZE(force_env%sub_force_env)
371 IF (
ASSOCIATED(force_env%sub_force_env(i)%force_env))
THEN
372 CALL force_env_get(force_env%sub_force_env(i)%force_env, subsys=subsys_i)
374 check = check .AND. virial%pv_availability
378 IF (.NOT. check)
THEN
379 CALL cp_abort(__location__, &
380 "Virial evaluation not requested for all the force_eval sections present in"// &
381 " the input file! You have to switch on the virial evaluation with the keyword: STRESS_TENSOR"// &
382 " in each force_eval section. Be sure the method you are using can compute the virial!")
394 CALL cp_iterate(logger%iter_info, iter_nr=itimes)
404 meta_env_saved => force_env%meta_env
405 NULLIFY (force_env%meta_env)
407 force_env%meta_env => meta_env_saved
409 IF (
ASSOCIATED(force_env%qs_env))
THEN
410 force_env%qs_env%sim_time = 0.0_dp
411 force_env%qs_env%sim_step = 0
414 IF (
ASSOCIATED(force_env%meta_env))
THEN
415 IF (force_env%meta_env%langevin)
THEN
417 DO j = 1, (rand2skip - 1)/nmccycles
418 DO i = 1, force_env%meta_env%n_colvar
419 auxrandom = force_env%meta_env%rng(i)%next()
420 auxrandom = force_env%meta_env%rng(i)%next()
424 CALL tamc_force(force_env)
427 IF (simpar%do_respa)
THEN
432 CALL virial_evaluate(atomic_kinds%els, particles%els, local_particles, &
433 virial, force_env%para_env)
440 itimes = reftraj%info%first_snapshot - 1
441 md_stride = reftraj%info%stride
445 constraint_section,
"CONSTRAINT_INFO")
447 constraint_section,
"LAGRANGE_MULTIPLIERS")
450 ALLOCATE (r(1:3,
SIZE(particles%els)))
454 ALLOCATE (xieta(2*force_env%meta_env%n_colvar))
456 ALLOCATE (an(force_env%meta_env%n_colvar))
458 ALLOCATE (fz(force_env%meta_env%n_colvar))
460 ALLOCATE (zbuff(2*force_env%meta_env%n_colvar))
463 IF (output_unit > 0)
THEN
464 WRITE (output_unit,
'(a)')
"HMC|==== Initial average forces"
466 CALL metadyn_write_colvar_header(force_env)
467 moves%hmc%attempts = 0
468 moves%hmc%successes = 0
469 gmoves%hmc%attempts = 0
470 gmoves%hmc%successes = 0
471 IF (initialstep == 0)
THEN
474 DO i = 1, force_env%meta_env%n_colvar
479 i_rep_val=i, r_val=rval)
480 fz(i) = rval*rand2skip
484 CALL hmcsampler(globenv, force_env, mcaverages, r, mc_par, moves, gmoves, rng_stream_mc, output_unit, &
485 fz, zbuff, nskip=rand2skip)
486 CALL cp_iterate(logger%iter_info, last=.false., iter_nr=0)
488 CALL write_restart(md_env=md_env, root_section=force_env%root_section)
490 IF (output_unit > 0)
THEN
491 WRITE (output_unit,
'(a)')
"HMC|==== end initial average forces"
494 CALL metadyn_write_colvar(force_env)
496 DO istep = 1, force_env%meta_env%TAMCSteps
499 time = time + force_env%meta_env%dt
500 IF (output_unit > 0)
THEN
501 WRITE (output_unit,
'(a)')
"HMC|==================================="
502 WRITE (output_unit,
'(a,1x,i0)')
"HMC| on z step ", istep
505 IF (
ASSOCIATED(force_env%qs_env))
THEN
506 force_env%qs_env%sim_time = time
507 force_env%qs_env%sim_step = itimes
508 force_env%meta_env%time = force_env%qs_env%sim_time
511 CALL cp_iterate(logger%iter_info, last=(istep == force_env%meta_env%TAMCSteps), iter_nr=itimes)
514 extension=
".shakeLog", log_filename=.false.)
516 logger, constraint_section, &
517 "LAGRANGE_MULTIPLIERS", extension=
".LagrangeMultLog", log_filename=.false.)
523 moves%hmc%attempts = 0
524 moves%hmc%successes = 0
525 CALL langevinvec(md_env, globenv, mc_env, moves, gmoves, r, &
526 rng_stream_mc, xieta, an, fz, mcaverages, zbuff)
530 constraint_section,
"CONSTRAINT_INFO")
532 constraint_section,
"LAGRANGE_MULTIPLIERS")
533 CALL cp_iterate(logger%iter_info, iter_nr=initialstep)
534 CALL metadyn_write_colvar(force_env)
548 IF (should_stop)
THEN
549 CALL cp_iterate(logger%iter_info, last=.true., iter_nr=itimes)
554 used_time = time_iter_stop - time_iter_start
555 time_iter_start = time_iter_stop
557 IF (output_unit > 0)
THEN
558 WRITE (output_unit,
'(a,1x,i0)')
"HMC| end z step ", istep
559 WRITE (output_unit,
'(a)')
"HMC|==================================="
562 CALL cp_iterate(logger%iter_info, last=.true., iter_nr=itimes)
563 force_env%qs_env%sim_time = 0.0_dp
564 force_env%qs_env%sim_step = 0
565 rand2skip = rand2skip + nmccycles*force_env%meta_env%TAMCSteps
566 IF (initialstep == 0) rand2skip = rand2skip + nmccycles
569 CALL write_restart(md_env=md_env, root_section=force_env%root_section)
593 CALL timestop(handle)
604 SUBROUTINE tamc_velocities_colvar(force_env, An)
606 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: an
608 CHARACTER(len=*),
PARAMETER :: routinen =
'tamc_velocities_colvar'
610 INTEGER :: handle, i_c
611 REAL(kind=
dp) :: dt, fft, sigma
616 NULLIFY (logger, meta_env, cv)
617 meta_env => force_env%meta_env
618 CALL timeset(routinen, handle)
625 meta_env%epot_walls = 0.0_dp
626 DO i_c = 1, meta_env%n_colvar
627 cv => meta_env%metavar(i_c)
628 fft = cv%ff_s + cv%ff_hills
630 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)
631 meta_env%epot_walls = meta_env%epot_walls + cv%epot_walls
633 CALL timestop(handle)
634 END SUBROUTINE tamc_velocities_colvar
643 SUBROUTINE tamc_position_colvar(force_env, xieta)
645 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: xieta
647 CHARACTER(len=*),
PARAMETER :: routinen =
'tamc_position_colvar'
649 INTEGER :: handle, i_c
650 REAL(kind=
dp) :: dt, sigma
655 NULLIFY (logger, meta_env, cv)
656 meta_env => force_env%meta_env
659 CALL timeset(routinen, handle)
667 DO i_c = 1, meta_env%n_colvar
668 cv => meta_env%metavar(i_c)
671 cv%ss0 = cv%ss0 + dt*cv%vvp + dt*sqrt(dt/12.0_dp)*sigma*xieta(i_c + meta_env%n_colvar)
672 IF (cv%periodic)
THEN
674 cv%ss0 = sign(1.0_dp, asin(sin(cv%ss0)))*acos(cos(cv%ss0))
677 CALL timestop(handle)
679 END SUBROUTINE tamc_position_colvar
688 SUBROUTINE tamc_force(force_env, zpot)
690 REAL(kind=
dp),
INTENT(inout),
OPTIONAL :: zpot
692 CHARACTER(len=*),
PARAMETER :: routinen =
'tamc_force'
694 INTEGER :: handle, i, i_c, icolvar, ii
696 REAL(kind=
dp) :: diff_ss, dt, rval
705 NULLIFY (logger, meta_env)
706 meta_env => force_env%meta_env
709 CALL timeset(routinen, handle)
711 NULLIFY (colvar_p, subsys, cv, ss0_section, vvp_section, ss_section)
715 IF (.NOT. meta_env%restart) meta_env%n_steps = meta_env%n_steps + 1
717 DO i_c = 1, meta_env%n_colvar
718 cv => meta_env%metavar(i_c)
721 cv%ss = subsys%colvar_p(icolvar)%colvar%ss
723 IF (meta_env%restart)
THEN
729 i_rep_val=i_c, r_val=rval)
737 CALL setup_velocities_z(force_env)
739 i_rep_val=i_c, r_val=rval)
742 CALL setup_velocities_z(force_env)
748 i_rep_val=i_c, r_val=rval)
759 meta_env%restart = .false.
760 meta_env%epot_s = 0.0_dp
761 meta_env%epot_walls = 0.0_dp
762 DO i_c = 1, meta_env%n_colvar
763 cv => meta_env%metavar(i_c)
764 diff_ss = cv%ss - cv%ss0
765 IF (cv%periodic)
THEN
767 diff_ss = sign(1.0_dp, asin(sin(diff_ss)))*acos(cos(diff_ss))
769 cv%epot_s = 0.5_dp*cv%lambda*diff_ss*diff_ss
770 cv%ff_s = cv%lambda*(diff_ss)
771 meta_env%epot_s = meta_env%epot_s + cv%epot_s
774 DO ii = 1, colvar_p(icolvar)%colvar%n_atom_s
775 i = colvar_p(icolvar)%colvar%i_atom(ii)
776 particles%els(i)%f = particles%els(i)%f - cv%ff_s*colvar_p(icolvar)%colvar%dsdr(:, ii)
780 IF (
PRESENT(zpot)) zpot = meta_env%epot_s
783 CALL timestop(handle)
784 END SUBROUTINE tamc_force
802 SUBROUTINE langevinvec(md_env, globenv, mc_env, moves, gmoves, r, &
803 rng_stream_mc, xieta, An, fz, averages, zbuff)
809 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: r
811 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: xieta, an, fz
813 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: zbuff
815 INTEGER :: iprint, ivar, nparticle, nparticle_kind, &
817 REAL(kind=
dp) :: dt,
gamma, mass, sigma
837 NULLIFY (logger, mc_par)
842 NULLIFY (simpar, force_env, para_env)
844 NULLIFY (subsys, cell)
846 NULLIFY (atomic_kinds, local_particles, particles, local_molecules, molecules, molecule_kinds, gci)
848 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
851 CALL get_mc_par(mc_par, nstep=nstep, iprint=iprint)
854 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
861 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
862 particles=particles, local_molecules=local_molecules, molecules=molecules, &
863 molecule_kinds=molecule_kinds, gci=gci, virial=virial)
865 nparticle_kind = atomic_kinds%n_els
866 atomic_kind_set => atomic_kinds%els
867 molecule_kind_set => molecule_kinds%els
869 nparticle = particles%n_els
870 particle_set => particles%els
871 molecule_set => molecules%els
872 cpassert(
ASSOCIATED(force_env%meta_env))
873 cpassert(force_env%meta_env%langevin)
876 DO ivar = 1, force_env%meta_env%n_colvar
877 xieta(ivar) = force_env%meta_env%rng(ivar)%next()
878 xieta(ivar + force_env%meta_env%n_colvar) = force_env%meta_env%rng(ivar)%next()
879 gamma = force_env%meta_env%metavar(ivar)%gamma
880 mass = force_env%meta_env%metavar(ivar)%mass
882 an(ivar) = 0.5_dp*sqrt(dt)*sigma*(xieta(ivar)*(1.0_dp - 0.5_dp*dt*
gamma) - &
883 dt*
gamma*xieta(ivar + force_env%meta_env%n_colvar)/sqrt(12.0_dp))
886 CALL tamc_velocities_colvar(force_env, an)
888 CALL tamc_position_colvar(force_env, xieta)
890 CALL hmcsampler(globenv, force_env, averages, r, mc_par, moves, gmoves, rng_stream_mc, output_unit, fz, zbuff)
899 CALL tamc_velocities_colvar(force_env, an)
903 END SUBROUTINE langevinvec
923 SUBROUTINE hmcsampler(globenv, force_env, averages, r, mc_par, moves, gmoves, rng_stream_mc, output_unit, &
928 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: r
932 INTEGER,
INTENT(IN) :: output_unit
933 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: fz, zbuff
934 INTEGER,
INTENT(IN),
OPTIONAL :: nskip
936 INTEGER :: i, iprint, ishift, it1, j, nsamples, &
938 REAL(kind=
dp) :: energy_check, old_epx, old_epz, t1
941 IF (
PRESENT(nskip))
THEN
949 CALL get_mc_par(mc_par, nstep=nstep, iprint=iprint)
950 meta_env_saved => force_env%meta_env
951 NULLIFY (force_env%meta_env)
953 force_env%meta_env => meta_env_saved
955 old_epz = force_env%meta_env%epot_s
957 averages%ave_energy = 0.0_dp
958 t1 = force_env%qs_env%sim_time
959 it1 = force_env%qs_env%sim_step
960 IF (output_unit > 0)
THEN
961 WRITE (output_unit,
'(a,l4)')
"HMC|restart? ", force_env%meta_env%restart
962 WRITE (output_unit,
'(a,3(f16.8,1x))') &
963 "HMC|Ep, Epx, Epz ", old_epx + force_env%meta_env%epot_s, old_epx, force_env%meta_env%epot_s
964 WRITE (output_unit,
'(a)')
"#HMC| No | z.. | theta.. | ff_z... | ff_z/n |"
967 IF (mod(i, iprint) == 0 .AND. (output_unit > 0))
THEN
968 WRITE (output_unit,
'(a,1x,i0)')
"HMC|========== On Monte Carlo cycle ", i + ishift
969 WRITE (output_unit,
'(a)')
"HMC| Attempting a minitrajectory move"
970 WRITE (output_unit,
'(a,1x,i0)')
"HMC| start mini-trajectory", i + ishift
971 WRITE (output_unit,
'(a,1x,i0,1x)',
advance=
"no")
"#HMC|0 ", i + ishift
972 DO j = 1, force_env%meta_env%n_colvar
973 WRITE (output_unit,
'(f16.8,1x,f16.8,1x,f16.8)',
advance=
"no") force_env%meta_env%metavar(j)%ss0, &
974 force_env%meta_env%metavar(j)%ss, &
975 force_env%meta_env%metavar(j)%ff_s
977 WRITE (output_unit, *)
980 CALL mc_hmc_move(mc_par, force_env, globenv, moves, gmoves, old_epx, old_epz, energy_check, &
981 r, output_unit, rng_stream_mc, zbuff)
984 averages%ave_energy = averages%ave_energy*real(i - 1,
dp)/real(i,
dp) + &
986 DO j = 1, force_env%meta_env%n_colvar
987 fz(j) = fz(j) + force_env%meta_env%metavar(j)%ff_s
989 IF (output_unit > 0)
THEN
990 WRITE (output_unit,
'(a,1x,i0)')
"HMC|end mini-trajectory", i + ishift
993 WRITE (output_unit,
'(a,1x,i0,1x)',
advance=
"no")
"#HMC|1 ", i + ishift
994 DO j = 1, force_env%meta_env%n_colvar
995 WRITE (output_unit,
'(f16.8,1x,f16.8,1x,f16.8,1x,f16.8)',
advance=
"no") force_env%meta_env%metavar(j)%ss0, &
996 force_env%meta_env%metavar(j)%ss, &
997 force_env%meta_env%metavar(j)%ff_s, fz(j)/real(i + ishift,
dp)
999 WRITE (output_unit, *)
1001 nsamples = nsamples + 1
1002 IF (mod(i, iprint) == 0 .AND. (output_unit > 0))
THEN
1003 WRITE (output_unit,
'(a,f16.8)')
"HMC| Running average for potential energy ", averages%ave_energy
1004 WRITE (output_unit,
'(a,1x,i0)')
"HMC|======== End Monte Carlo cycle ", i + ishift
1007 force_env%qs_env%sim_time = t1
1008 force_env%qs_env%sim_step = it1
1009 IF (output_unit > 0)
THEN
1010 WRITE (output_unit,
'(a,i0,a,i0,a,f16.8)')
"HMC| local acceptance ratio: ", moves%hmc%successes,
"/", &
1011 moves%hmc%attempts,
"=", real(moves%hmc%successes,
dp)/real(moves%hmc%attempts,
dp)
1012 WRITE (output_unit,
'(a,i0,a,i0,a,f16.8)')
"HMC| global acceptance ratio: ", gmoves%hmc%successes,
"/", &
1013 gmoves%hmc%attempts,
"=", real(gmoves%hmc%successes,
dp)/real(gmoves%hmc%attempts,
dp)
1016 DO j = 1, force_env%meta_env%n_colvar
1017 force_env%meta_env%metavar(j)%ff_s = fz(j)/nsamples
1019 END SUBROUTINE hmcsampler
1039 SUBROUTINE mc_hmc_move(mc_par, force_env, globenv, moves, gmoves, old_epx, old_epz, &
1040 energy_check, r, output_unit, rng_stream, zbuff)
1046 REAL(kind=
dp),
INTENT(INOUT) :: old_epx, old_epz, energy_check
1047 REAL(kind=
dp),
DIMENSION(:, :),
INTENT(INOUT) :: r
1048 INTEGER,
INTENT(IN) :: output_unit
1050 REAL(kind=
dp),
DIMENSION(:),
INTENT(INOUT) :: zbuff
1052 CHARACTER(LEN=*),
PARAMETER :: routinen =
'mc_hmc_move'
1054 INTEGER :: handle, iatom, j, natoms, source
1055 LOGICAL :: ionode, localise
1056 REAL(kind=
dp) :: beta, energy_term, exp_max_val, &
1057 exp_min_val, new_energy, new_epx, &
1058 new_epz, rand,
value, w
1068 CALL timeset(routinen, handle)
1070 CALL get_qs_env(force_env%qs_env, input=input)
1075 beta=beta, exp_max_val=exp_max_val, &
1076 exp_min_val=exp_min_val, source=source, group=group)
1080 NULLIFY (particles_set, oldsys, meta_env_saved, hmc_ekin)
1084 natoms =
SIZE(particles_set%els)
1090 moves%hmc%attempts = moves%hmc%attempts + 1
1091 gmoves%hmc%attempts = gmoves%hmc%attempts + 1
1094 DO iatom = 1, natoms
1095 r(1:3, iatom) = particles_set%els(iatom)%r(1:3)
1099 DO j = 1, force_env%meta_env%n_colvar
1100 zbuff(j) = force_env%meta_env%metavar(j)%ss
1101 zbuff(j + force_env%meta_env%n_colvar) = force_env%meta_env%metavar(j)%ff_s
1102 IF ((oldsys%colvar_p(force_env%meta_env%metavar(j)%icolvar)%colvar%type_id ==
hbp_colvar_id) .OR. &
1103 (oldsys%colvar_p(force_env%meta_env%metavar(j)%icolvar)%colvar%type_id ==
wc_colvar_id))
THEN
1109 meta_env_saved => force_env%meta_env
1110 NULLIFY (force_env%meta_env)
1111 force_env%qs_env%sim_time = 0.0_dp
1112 force_env%qs_env%sim_step = 0
1113 IF (.NOT. localise)
THEN
1116 CALL qs_mol_dyn(force_env, globenv, hmc_e_initial=hmc_ekin%initial_ekin, hmc_e_final=hmc_ekin%final_ekin)
1117 IF (.NOT. localise)
THEN
1124 force_env%meta_env => meta_env_saved
1125 CALL tamc_force(force_env, zpot=new_epz)
1126 new_energy = new_epx + new_epz
1127 IF (output_unit > 0)
THEN
1128 WRITE (output_unit,
'(a,4(f16.8,1x))') &
1129 "HMC|old Ep, Ekx, Epz, Epx ", old_epx + old_epz, hmc_ekin%initial_ekin, old_epz, old_epx
1130 WRITE (output_unit,
'(a,4(f16.8,1x))')
"HMC|new Ep, Ekx, Epz, Epx ", new_energy, hmc_ekin%final_ekin, new_epz, new_epx
1132 energy_term = new_energy - old_epx - old_epz + hmc_ekin%final_ekin - hmc_ekin%initial_ekin
1134 value = -beta*(energy_term)
1136 IF (
value > exp_max_val)
THEN
1138 ELSE IF (
value < exp_min_val)
THEN
1144 rand = rng_stream%next()
1147 moves%hmc%successes = moves%hmc%successes + 1
1148 gmoves%hmc%successes = gmoves%hmc%successes + 1
1150 energy_check = energy_check + (new_energy - old_epx - old_epz)
1155 DO iatom = 1, natoms
1156 particles_set%els(iatom)%r(1:3) = r(1:3, iatom)
1158 DO j = 1, force_env%meta_env%n_colvar
1159 force_env%meta_env%metavar(j)%ss = zbuff(j)
1160 force_env%meta_env%metavar(j)%ff_s = zbuff(j + force_env%meta_env%n_colvar)
1165 DEALLOCATE (hmc_ekin)
1168 CALL timestop(handle)
1170 END SUBROUTINE mc_hmc_move
1176 SUBROUTINE metadyn_write_colvar_header(force_env)
1179 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_write_colvar_header'
1181 CHARACTER(len=100) :: aux, fmt
1182 CHARACTER(len=255) :: label1, label2, label3, label4, label5, &
1184 INTEGER :: handle, i, iw, m
1188 NULLIFY (logger, meta_env)
1189 meta_env => force_env%meta_env
1190 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
1192 CALL timeset(routinen, handle)
1196 "PRINT%COLVAR", extension=
".metadynLog")
1204 DO i = 1, meta_env%n_colvar
1205 WRITE (aux,
'(a,i0)')
"z_", i
1206 label1 = trim(label1)//trim(aux)
1207 m = 15*i - len_trim(label1) - 1
1208 label1 = trim(label1)//repeat(
" ", m)//
"|"
1209 WRITE (aux,
'(a,i0)')
"Theta_", i
1210 label2 = trim(label2)//trim(aux)
1211 m = 15*i - len_trim(label2) - 1
1212 label2 = trim(label2)//repeat(
" ", m)//
"|"
1213 WRITE (aux,
'(a,i0)')
"F_z", i
1214 label3 = trim(label3)//trim(aux)
1215 m = 15*i - len_trim(label3) - 1
1216 label3 = trim(label3)//repeat(
" ", m)//
"|"
1217 WRITE (aux,
'(a,i0)')
"F_h", i
1218 label4 = trim(label4)//trim(aux)
1219 m = 15*i - len_trim(label4) - 1
1220 label4 = trim(label4)//repeat(
" ", m)//
"|"
1221 WRITE (aux,
'(a,i0)')
"F_w", i
1222 label5 = trim(label5)//trim(aux)
1223 m = 15*i - len_trim(label5) - 1
1224 label5 = trim(label5)//repeat(
" ", m)//
"|"
1225 WRITE (aux,
'(a,i0)')
"v_z", i
1226 label6 = trim(label6)//trim(aux)
1227 m = 15*i - len_trim(label6) - 1
1228 label6 = trim(label6)//repeat(
" ", m)//
"|"
1230 WRITE (fmt,
'("(a17,6a",i0 ,",4a15)")') meta_env%n_colvar*15
1231 WRITE (iw, trim(fmt))
"#Time[fs] |", &
1247 CALL timestop(handle)
1249 END SUBROUTINE metadyn_write_colvar_header
1255 SUBROUTINE metadyn_write_colvar(force_env)
1258 CHARACTER(len=*),
PARAMETER :: routinen =
'metadyn_write_colvar'
1260 INTEGER :: handle, i, i_c, iw
1261 REAL(kind=
dp) :: temp
1266 NULLIFY (logger, meta_env, cv)
1267 meta_env => force_env%meta_env
1268 IF (.NOT.
ASSOCIATED(meta_env))
RETURN
1270 CALL timeset(routinen, handle)
1273 IF (meta_env%langevin)
THEN
1274 meta_env%ekin_s = 0.0_dp
1276 DO i_c = 1, meta_env%n_colvar
1277 cv => meta_env%metavar(i_c)
1278 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
1284 "PRINT%COLVAR", extension=
".metadynLog")
1286 IF (meta_env%extended_lagrange)
THEN
1287 WRITE (iw,
'(f16.8,70f15.8)') meta_env%time*
femtoseconds, &
1288 (meta_env%metavar(i)%ss0, i=1, meta_env%n_colvar), &
1289 (meta_env%metavar(i)%ss, i=1, meta_env%n_colvar), &
1290 (meta_env%metavar(i)%ff_s, i=1, meta_env%n_colvar), &
1291 (meta_env%metavar(i)%ff_hills, i=1, meta_env%n_colvar), &
1292 (meta_env%metavar(i)%ff_walls, i=1, meta_env%n_colvar), &
1293 (meta_env%metavar(i)%vvp, i=1, meta_env%n_colvar), &
1295 meta_env%hills_env%energy, &
1296 meta_env%epot_walls, &
1297 (meta_env%ekin_s)*2.0_dp/(real(meta_env%n_colvar, kind=
dp))*
kelvin
1299 WRITE (iw,
'(f16.8,40f13.5)') meta_env%time*
femtoseconds, &
1300 (meta_env%metavar(i)%ss0, i=1, meta_env%n_colvar), &
1301 (meta_env%metavar(i)%ff_hills, i=1, meta_env%n_colvar), &
1302 (meta_env%metavar(i)%ff_walls, i=1, meta_env%n_colvar), &
1303 meta_env%hills_env%energy, &
1310 IF (meta_env%extended_lagrange)
THEN
1311 temp = meta_env%ekin_s*2.0_dp/(real(meta_env%n_colvar, kind=
dp))*
kelvin
1312 meta_env%avg_temp = (meta_env%avg_temp*real(meta_env%n_steps, kind=
dp) + &
1313 temp)/real(meta_env%n_steps + 1, kind=
dp)
1315 "PRINT%TEMPERATURE_COLVAR", extension=
".metadynLog")
1317 WRITE (iw,
'(T2,79("-"))')
1318 WRITE (iw,
'( A,T51,f10.2,T71,f10.2)')
' COLVARS INSTANTANEOUS/AVERAGE TEMPERATURE ', &
1319 temp, meta_env%avg_temp
1320 WRITE (iw,
'(T2,79("-"))')
1323 "PRINT%TEMPERATURE_COLVAR")
1325 CALL timestop(handle)
1327 END SUBROUTINE metadyn_write_colvar
1333 SUBROUTINE setup_velocities_z(force_env)
1337 REAL(kind=
dp) :: ekin_w, fac_t
1342 meta_env => force_env%meta_env
1343 meta_env%ekin_s = 0.0_dp
1344 DO i_c = 1, meta_env%n_colvar
1345 cv => meta_env%metavar(i_c)
1346 cv%vvp = force_env%globenv%gaussian_rng_stream%next()
1347 meta_env%ekin_s = meta_env%ekin_s + 0.5_dp*cv%mass*cv%vvp**2
1349 ekin_w = 0.5_dp*meta_env%temp_wanted*real(meta_env%n_colvar, kind=
dp)
1350 fac_t = sqrt(ekin_w/max(meta_env%ekin_s, 1.0e-8_dp))
1351 DO i_c = 1, meta_env%n_colvar
1352 cv => meta_env%metavar(i_c)
1353 cv%vvp = cv%vvp*fac_t
1355 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, cell_ref, use_ref_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, mimic, 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, sab_cneo, 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, matrix_vhxc, 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, xcint_weights, 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, rhoz_cneo_set, ecoul_1c, rho0_s_rs, rho0_s_gs, rhoz_cneo_s_rs, rhoz_cneo_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, do_rixs, tb_tblite)
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.