(git:27c966b)
Loading...
Searching...
No Matches
integrator.F
Go to the documentation of this file.
1!--------------------------------------------------------------------------------------------------!
2! CP2K: A general program to perform molecular dynamics simulations !
3! Copyright 2000-2026 CP2K developers group <https://cp2k.org> !
4! !
5! SPDX-License-Identifier: GPL-2.0-or-later !
6!--------------------------------------------------------------------------------------------------!
7
8! **************************************************************************************************
9!> \brief Provides integrator routines (velocity verlet) for all the
10!> ensemble types
11!> \par History
12!> JGH (15-Mar-2001) : Pass logical for box change to force routine
13!> Harald Forbert (Apr-2001): added path integral routine nvt_pimd
14!> CJM (15-Apr-2001) : added coef integrators and energy routines
15!> Joost VandeVondele (Juli-2003): simple version of isokinetic ensemble
16!> Teodoro Laino [tlaino] 10.2007 - University of Zurich: Generalization to
17!> different kind of thermostats
18!> Teodoro Laino [tlaino] 11.2007 - Metadynamics: now part of the MD modules
19!> Marcella Iannuzzi 02.2008 - Collecting common code (VV and creation of
20!> a temporary type)
21!> Teodoro Laino [tlaino] 02.2008 - Splitting integrator module and keeping in
22!> integrator only the INTEGRATORS
23!> Lianheng Tong [LT] 12.2013 - Added regions to Langevin MD
24!> \author CJM
25! **************************************************************************************************
32 USE cell_methods, ONLY: init_cell,&
34 USE cell_types, ONLY: cell_type,&
36 pbc
37 USE constraint, ONLY: rattle_control,&
44 USE constraint_util, ONLY: getold,&
55 USE cp_units, ONLY: cp_unit_to_cp2k
64 USE input_constants, ONLY: ehrenfest,&
68 USE integrator_utils, ONLY: &
72 USE kinds, ONLY: dp,&
87 USE particle_types, ONLY: particle_type,&
89 USE physcon, ONLY: femtoseconds
114 USE simpar_types, ONLY: simpar_type
115 USE string_utilities, ONLY: uppercase
123 USE virial_types, ONLY: virial_type
124#include "../base/base_uses.f90"
125
126 IMPLICIT NONE
127
128 PRIVATE
129
130 CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'integrator'
131
132 PUBLIC :: isokin, langevin, nve, nvt, npt_i, npt_f, nve_respa
134
135CONTAINS
136
137! **************************************************************************************************
138!> \brief Langevin integrator for particle positions & momenta (Brownian dynamics)
139!> \param md_env ...
140!> \par Literature
141!> - A. Ricci and G. Ciccotti, Mol. Phys. 101, 1927-1931 (2003)
142!> - For langevin regions:
143!> - L. Kantorovich, Phys. Rev. B 78, 094304 (2008)
144!> - L. Kantorovich and N. Rompotis, Phys. Rev. B 78, 094305 (2008)
145!> \par History
146!> - Created (01.07.2005,MK)
147!> - Added support for only performing Langevin MD on a region of atoms
148!> (01.12.2013, LT)
149!> \author Matthias Krack
150! **************************************************************************************************
151 SUBROUTINE langevin(md_env)
152
153 TYPE(md_environment_type), POINTER :: md_env
154
155 INTEGER :: iparticle, iparticle_kind, iparticle_local, iparticle_reg, ireg, nparticle, &
156 nparticle_kind, nparticle_local, nshell
157 INTEGER, POINTER :: itimes
158 LOGICAL, ALLOCATABLE, DIMENSION(:) :: do_langevin
159 REAL(kind=dp) :: c, c1, c2, c3, c4, dm, dt, gam, &
160 lambda_mix, mass, noisy_gamma_region, &
161 reg_temp, sigma
162 REAL(kind=dp), ALLOCATABLE, DIMENSION(:) :: var_w
163 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: pos, vel, w
164 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
165 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
166 TYPE(atomic_kind_type), POINTER :: atomic_kind
167 TYPE(cell_type), POINTER :: cell
168 TYPE(cp_subsys_type), POINTER :: subsys
169 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
170 TYPE(force_env_type), POINTER :: force_env
171 TYPE(global_constraint_type), POINTER :: gci
172 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
173 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
174 TYPE(molecule_list_type), POINTER :: molecules
175 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
176 TYPE(mp_para_env_type), POINTER :: para_env
177 TYPE(particle_list_type), POINTER :: particles
178 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
179 TYPE(qs_electrons_type), POINTER :: electrons
180 TYPE(simpar_type), POINTER :: simpar
181 TYPE(thermal_region_type), POINTER :: thermal_region
182 TYPE(thermal_regions_type), POINTER :: thermal_regions
183 TYPE(virial_type), POINTER :: virial
184
185 NULLIFY (cell, para_env, gci, force_env)
186 NULLIFY (atomic_kinds, local_particles, subsys, local_molecules, molecule_kinds, molecules)
187 NULLIFY (molecule_kind_set, molecule_set, particles, particle_set, simpar, virial)
188 NULLIFY (thermal_region, thermal_regions, itimes, electrons)
189
190 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
191 para_env=para_env, thermal_regions=thermal_regions, &
192 itimes=itimes, electrons=electrons)
193
194 dt = simpar%dt
195 gam = simpar%gamma + simpar%shadow_gamma
196 nshell = 0
197
198 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
199
200 ! Do some checks on coordinates and box
201 CALL apply_qmmm_walls_reflective(force_env)
202
203 CALL cp_subsys_get(subsys=subsys, &
204 atomic_kinds=atomic_kinds, &
205 gci=gci, &
206 local_particles=local_particles, &
207 local_molecules=local_molecules, &
208 molecules=molecules, &
209 molecule_kinds=molecule_kinds, &
210 nshell=nshell, &
211 particles=particles, &
212 virial=virial)
213 IF (nshell /= 0) THEN
214 cpabort("Langevin dynamics is not yet implemented for core-shell models")
215 END IF
216
217 nparticle_kind = atomic_kinds%n_els
218 atomic_kind_set => atomic_kinds%els
219 molecule_kind_set => molecule_kinds%els
220
221 nparticle = particles%n_els
222 particle_set => particles%els
223 molecule_set => molecules%els
224
225 ! Setup the langevin regions information
226 ALLOCATE (do_langevin(nparticle))
227 IF (simpar%do_thermal_region) THEN
228 DO iparticle = 1, nparticle
229 do_langevin(iparticle) = thermal_regions%do_langevin(iparticle)
230 END DO
231 ELSE
232 do_langevin(1:nparticle) = .true.
233 END IF
234
235 ! Allocate the temperature dependent variance (var_w) of the
236 ! random variable for each atom. It may be different for different
237 ! atoms because of the possibility of Langevin regions, and var_w
238 ! for each region should depend on the temperature defined in the
239 ! region
240 ! RZK explains: sigma is the variance of the Wiener process associated
241 ! with the stochastic term, sigma = m*var_w = m*(2*k_B*T*gamma*dt),
242 ! noisy_gamma adds excessive noise that is not balanced by the damping term
243 ALLOCATE (var_w(nparticle))
244 var_w(1:nparticle) = simpar%var_w
245 IF (simpar%do_thermal_region) THEN
246 DO ireg = 1, thermal_regions%nregions
247 thermal_region => thermal_regions%thermal_region(ireg)
248 noisy_gamma_region = thermal_region%noisy_gamma_region
249 DO iparticle_reg = 1, thermal_region%npart
250 iparticle = thermal_region%part_index(iparticle_reg)
251 reg_temp = thermal_region%temp_expected
252 var_w(iparticle) = 2.0_dp*reg_temp*simpar%dt*(simpar%gamma + noisy_gamma_region)
253 END DO
254 END DO
255 END IF
256
257 ! Allocate work storage
258 ALLOCATE (pos(3, nparticle))
259 pos(:, :) = 0.0_dp
260
261 ALLOCATE (vel(3, nparticle))
262 vel(:, :) = 0.0_dp
263
264 ALLOCATE (w(3, nparticle))
265 w(:, :) = 0.0_dp
266
267 IF (simpar%constraint) CALL getold(gci, local_molecules, molecule_set, &
268 molecule_kind_set, particle_set, cell)
269
270 ! Generate random variables
271 DO iparticle_kind = 1, nparticle_kind
272 atomic_kind => atomic_kind_set(iparticle_kind)
273 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
274 nparticle_local = local_particles%n_el(iparticle_kind)
275 DO iparticle_local = 1, nparticle_local
276 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
277 IF (do_langevin(iparticle)) THEN
278 sigma = var_w(iparticle)*mass
279 associate(rng_stream => local_particles%local_particle_set(iparticle_kind)% &
280 rng(iparticle_local))
281 w(1, iparticle) = rng_stream%stream%next(variance=sigma)
282 w(2, iparticle) = rng_stream%stream%next(variance=sigma)
283 w(3, iparticle) = rng_stream%stream%next(variance=sigma)
284 END associate
285 END IF
286 END DO
287 END DO
288
289 DEALLOCATE (var_w)
290
291 ! Apply fix atom constraint
292 CALL fix_atom_control(force_env, w)
293
294 ! ---------------------------------------------------------------------
295 ! Constant-potential electronic dynamics, first electronic O half-step.
296 !
297 ! These hooks mirror nvt() one for one. Until they were added, langevin()
298 ! propagated the atoms normally while never calling qs_electrons_kick,
299 ! qs_electrons_drift, charge_mixing_maybe_rebuild or
300 ! push_lambda_to_mixed_env: q(t) stayed frozen at Q_INIT, the mixing weight
301 ! never updated, and the run completed and wrote entirely plausible output
302 ! that meant nothing. nve(), isokin(), nvt_adiabatic() and the npt/nph
303 ! family still have this property -- see the guard in md_run.F.
304 !
305 ! The electronic potentiostat remains CSVR regardless of what the atoms
306 ! use, independent of the atomic thermostat. qs_electrons_thermostat_step computes
307 ! taut = (tau/femtoseconds)/(0.5*dt) on the assumption that it is called
308 ! TWICE per MD step, which is why there is a matching call at the end.
309 IF (ASSOCIATED(electrons)) THEN
310 ! report_only ("&ELECTRONS 0"): q is never propagated, so no O step.
311 IF (.NOT. electrons%report_only) CALL qs_electrons_thermostat_step(electrons, 0.5_dp*dt)
312 END IF
313 ! ---------------------------------------------------------------------
314
315 ! Velocity Verlet (first part)
316 c = exp(-0.25_dp*dt*gam)
317 c2 = c*c
318 c4 = c2*c2
319 c1 = dt*c2
320
321 DO iparticle_kind = 1, nparticle_kind
322 atomic_kind => atomic_kind_set(iparticle_kind)
323 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
324 nparticle_local = local_particles%n_el(iparticle_kind)
325 dm = 0.5_dp*dt/mass
326 c3 = dm/c2
327 DO iparticle_local = 1, nparticle_local
328 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
329 IF (do_langevin(iparticle)) THEN
330 vel(:, iparticle) = particle_set(iparticle)%v(:) + &
331 c3*particle_set(iparticle)%f(:)
332 pos(:, iparticle) = particle_set(iparticle)%r(:) + &
333 c1*particle_set(iparticle)%v(:) + &
334 c*dm*(dt*particle_set(iparticle)%f(:) + &
335 w(:, iparticle))
336 ELSE
337 vel(:, iparticle) = particle_set(iparticle)%v(:) + &
338 dm*particle_set(iparticle)%f(:)
339 pos(:, iparticle) = particle_set(iparticle)%r(:) + &
340 dt*particle_set(iparticle)%v(:) + &
341 dm*dt*particle_set(iparticle)%f(:)
342 END IF
343 END DO
344 END DO
345
346 IF (simpar%constraint) THEN
347 ! Possibly update the target values
348 CALL shake_update_targets(gci, local_molecules, molecule_set, &
349 molecule_kind_set, dt, force_env%root_section)
350
351 CALL shake_control(gci, local_molecules, molecule_set, molecule_kind_set, &
352 particle_set, pos, vel, dt, simpar%shake_tol, &
353 simpar%info_constraint, simpar%lagrange_multipliers, &
354 simpar%dump_lm, cell, para_env, local_particles)
355 END IF
356
357 ! Broadcast the new particle positions
358 CALL update_particle_set(particle_set, para_env, pos=pos)
359
360 DEALLOCATE (pos)
361
362 ! ---------------------------------------------------------------------
363 ! Electronic half-kick (B) and drift (A), then re-bracket and push the new
364 ! mixing weight, so that the force evaluation below sees BOTH the new
365 ! positions and the new q(t) -- the same ordering as nvt().
366 IF (ASSOCIATED(electrons)) THEN
367 ! report_only ("&ELECTRONS 0"): none of this runs. q is not propagated,
368 ! the endpoints are never rebuilt, and apply_ne_core_correction is NOT
369 ! called -- that last one matters, since it would alter the system's
370 ! charge, which in report-only mode must stay exactly as the input set
371 ! it. Only the work-function readback below still runs.
372 IF (.NOT. electrons%report_only) THEN
373 CALL qs_electrons_kick(electrons, 0.5_dp*dt)
374 CALL qs_electrons_drift(electrons, dt)
375 IF (electrons%charge_mixing_enabled) THEN
376 CALL charge_mixing_maybe_rebuild(force_env, electrons)
377 CALL qs_electrons_charge_mixing_lambda(electrons, lambda_mix)
378 CALL push_lambda_to_mixed_env(force_env, lambda_mix)
379 ELSE
380 CALL apply_ne_core_correction(force_env, electrons%q, electrons%neutral_electrons)
381 END IF
382 END IF
383 END IF
384 ! ---------------------------------------------------------------------
385
386 ! Update forces
387 CALL force_env_calc_energy_force(force_env)
388
389 ! Refresh the mixed workfunction and Fermi level from the freshly
390 ! converged density; qs_electrons_force reads current_workfunction, so this
391 ! must precede the closing electronic half-kick below.
392 IF (ASSOCIATED(electrons)) THEN
393 IF (electrons%charge_mixing_enabled) THEN
394 CALL compute_mixed_workfunction(force_env, electrons%potential_average_axis, &
395 electrons%potential_average_min, electrons%potential_average_max, &
396 electrons%q, electrons%charge_mixing_span, &
397 electrons%current_fermi_level_eV, electrons%current_workfunction, &
398 lambda_in=lambda_mix)
399 ELSE
400 CALL qs_electrons_compute_workfunction(force_env, electrons%potential_average_axis, &
401 electrons%potential_average_min, electrons%potential_average_max, &
402 electrons%current_fermi_level_eV, electrons%current_workfunction)
403 END IF
404 END IF
405
406 ! Metadynamics
407 CALL metadyn_integrator(force_env, itimes, vel)
408
409 ! Update Verlet (second part)
410 DO iparticle_kind = 1, nparticle_kind
411 atomic_kind => atomic_kind_set(iparticle_kind)
412 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
413 dm = 0.5_dp*dt/mass
414 c3 = dm/c2
415 nparticle_local = local_particles%n_el(iparticle_kind)
416 DO iparticle_local = 1, nparticle_local
417 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
418 IF (do_langevin(iparticle)) THEN
419 vel(1, iparticle) = vel(1, iparticle) + c3*particle_set(iparticle)%f(1)
420 vel(2, iparticle) = vel(2, iparticle) + c3*particle_set(iparticle)%f(2)
421 vel(3, iparticle) = vel(3, iparticle) + c3*particle_set(iparticle)%f(3)
422 vel(1, iparticle) = c4*vel(1, iparticle) + c2*w(1, iparticle)/mass
423 vel(2, iparticle) = c4*vel(2, iparticle) + c2*w(2, iparticle)/mass
424 vel(3, iparticle) = c4*vel(3, iparticle) + c2*w(3, iparticle)/mass
425 ELSE
426 vel(1, iparticle) = vel(1, iparticle) + dm*particle_set(iparticle)%f(1)
427 vel(2, iparticle) = vel(2, iparticle) + dm*particle_set(iparticle)%f(2)
428 vel(3, iparticle) = vel(3, iparticle) + dm*particle_set(iparticle)%f(3)
429 END IF
430 END DO
431 END DO
432
433 ! Closing electronic half-kick (B), using the workfunction just recomputed
434 ! from the new density.
435 IF (ASSOCIATED(electrons)) THEN
436 ! report_only ("&ELECTRONS 0"): q is never propagated, so no B step.
437 IF (.NOT. electrons%report_only) CALL qs_electrons_kick(electrons, 0.5_dp*dt)
438 END IF
439
440 IF (simpar%temperature_annealing) THEN
441 simpar%temp_ext = simpar%temp_ext*simpar%f_temperature_annealing
442 simpar%var_w = simpar%var_w*simpar%f_temperature_annealing
443 END IF
444
445 IF (simpar%constraint) THEN
446 CALL rattle_control(gci, local_molecules, molecule_set, molecule_kind_set, &
447 particle_set, vel, dt, simpar%shake_tol, &
448 simpar%info_constraint, simpar%lagrange_multipliers, &
449 simpar%dump_lm, cell, para_env, local_particles)
450 END IF
451
452 ! Second electronic O half-step, completing the pair assumed by
453 ! qs_electrons_thermostat_step's taut = (tau/femtoseconds)/(0.5*dt).
454 IF (ASSOCIATED(electrons)) THEN
455 ! report_only ("&ELECTRONS 0"): q is never propagated, so no O step.
456 IF (.NOT. electrons%report_only) CALL qs_electrons_thermostat_step(electrons, 0.5_dp*dt)
457 END IF
458
459 ! Broadcast the new particle velocities
460 CALL update_particle_set(particle_set, para_env, vel=vel)
461
462 DEALLOCATE (vel)
463
464 DEALLOCATE (w)
465
466 DEALLOCATE (do_langevin)
467
468 ! Update virial
469 IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, molecule_set, &
470 molecule_kind_set, particle_set, virial, para_env)
471
472 CALL virial_evaluate(atomic_kind_set, particle_set, local_particles, &
473 virial, para_env)
474
475 END SUBROUTINE langevin
476
477! **************************************************************************************************
478!> \brief nve integrator for particle positions & momenta
479!> \param md_env ...
480!> \param globenv ...
481!> \par History
482!> - the local particle lists are used instead of pnode (Sep. 2003,MK)
483!> - usage of fragments retrieved from the force environment (Oct. 2003,MK)
484!> \author CJM
485! **************************************************************************************************
486 SUBROUTINE nve(md_env, globenv)
487
488 TYPE(md_environment_type), POINTER :: md_env
489 TYPE(global_environment_type), POINTER :: globenv
490
491 INTEGER :: i_iter, n_iter, nparticle, &
492 nparticle_kind, nshell
493 INTEGER, POINTER :: itimes
494 LOGICAL :: deallocate_vel, ehrenfest_md, &
495 shell_adiabatic, shell_check_distance, &
496 shell_present
497 REAL(kind=dp) :: dt
498 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: v_old
499 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
500 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
501 TYPE(cell_type), POINTER :: cell
502 TYPE(cp_subsys_type), POINTER :: subsys
503 TYPE(dft_control_type), POINTER :: dft_control
504 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
505 TYPE(force_env_type), POINTER :: force_env
506 TYPE(global_constraint_type), POINTER :: gci
507 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
508 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
509 TYPE(molecule_list_type), POINTER :: molecules
510 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
511 TYPE(mp_para_env_type), POINTER :: para_env
512 TYPE(particle_list_type), POINTER :: core_particles, particles, &
513 shell_particles
514 TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
515 shell_particle_set
516 TYPE(rt_prop_type), POINTER :: rtp
517 TYPE(simpar_type), POINTER :: simpar
518 TYPE(thermostat_type), POINTER :: thermostat_coeff, thermostat_shell
519 TYPE(tmp_variables_type), POINTER :: tmp
520 TYPE(virial_type), POINTER :: virial
521
522 NULLIFY (thermostat_coeff, tmp)
523 NULLIFY (subsys, simpar, para_env, cell, gci, force_env, virial)
524 NULLIFY (atomic_kinds, local_particles, molecules, molecule_kind_set, molecule_set, particle_set)
525 NULLIFY (shell_particles, shell_particle_set, core_particles, &
526 core_particle_set, thermostat_shell, dft_control, itimes)
527 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
528 thermostat_coeff=thermostat_coeff, thermostat_shell=thermostat_shell, &
529 para_env=para_env, ehrenfest_md=ehrenfest_md, itimes=itimes)
530 dt = simpar%dt
531 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
532
533 ! Do some checks on coordinates and box
534 CALL apply_qmmm_walls_reflective(force_env)
535
536 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
537 particles=particles, local_molecules=local_molecules, molecules=molecules, &
538 molecule_kinds=molecule_kinds, gci=gci, virial=virial)
539
540 nparticle_kind = atomic_kinds%n_els
541 atomic_kind_set => atomic_kinds%els
542 molecule_kind_set => molecule_kinds%els
543
544 nparticle = particles%n_els
545 particle_set => particles%els
546 molecule_set => molecules%els
547
548 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
549 shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
550 shell_check_distance=shell_check_distance)
551
552 IF (shell_present) THEN
553 CALL cp_subsys_get(subsys=subsys, shell_particles=shell_particles, &
554 core_particles=core_particles)
555 shell_particle_set => shell_particles%els
556 nshell = SIZE(shell_particles%els)
557
558 IF (shell_adiabatic) THEN
559 core_particle_set => core_particles%els
560 END IF
561 END IF
562
563 CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
564
565 ! Apply thermostat over the full set of shells if required
566 IF (shell_adiabatic) THEN
567 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
568 local_particles, para_env, shell_particle_set=shell_particle_set, &
569 core_particle_set=core_particle_set)
570 END IF
571
572 IF (simpar%constraint) CALL getold(gci, local_molecules, molecule_set, &
573 molecule_kind_set, particle_set, cell)
574
575 ! Velocity Verlet (first part)
576 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
577 core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
578
579 IF (simpar%variable_dt) CALL variable_timestep(md_env, tmp, dt, simpar, para_env, atomic_kind_set, &
580 local_particles, particle_set, core_particle_set, shell_particle_set, &
581 nparticle_kind, shell_adiabatic)
582
583 IF (simpar%constraint) THEN
584 ! Possibly update the target values
585 CALL shake_update_targets(gci, local_molecules, molecule_set, &
586 molecule_kind_set, dt, force_env%root_section)
587
588 CALL shake_control(gci, local_molecules, molecule_set, &
589 molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, simpar%shake_tol, &
590 simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
591 cell, para_env, local_particles)
592 END IF
593
594 ! Broadcast the new particle positions and deallocate pos part of temporary
595 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
596 core_particle_set, para_env, shell_adiabatic, pos=.true.)
597
598 IF (shell_adiabatic .AND. shell_check_distance) THEN
599 CALL optimize_shell_core(force_env, particle_set, &
600 shell_particle_set, core_particle_set, globenv, tmp=tmp, check=.true.)
601 END IF
602
603 ! Update forces
604 ! In case of ehrenfest dynamics, velocities need to be iterated
605 IF (ehrenfest_md) THEN
606 ALLOCATE (v_old(3, SIZE(tmp%vel, 2)))
607 v_old(:, :) = tmp%vel
608 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
609 core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
610 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
611 core_particle_set, para_env, shell_adiabatic, vel=.true., &
612 should_deall_vel=.false.)
613 tmp%vel = v_old
614 CALL get_qs_env(force_env%qs_env, dft_control=dft_control)
615 n_iter = dft_control%rtp_control%max_iter
616 ELSE
617 n_iter = 1
618 END IF
619
620 DO i_iter = 1, n_iter
621
622 IF (ehrenfest_md) THEN
623 CALL get_qs_env(qs_env=force_env%qs_env, rtp=rtp)
624 rtp%iter = i_iter
625 tmp%vel = v_old
626 CALL propagation_step(force_env%qs_env, rtp, dft_control%rtp_control)
627 END IF
628
629 ![NB] let nve work with force mixing which does not have consistent energies and forces
630 CALL force_env_calc_energy_force(force_env, require_consistent_energy_force=.false.)
631
632 IF (ehrenfest_md) THEN
633 CALL rt_prop_output(force_env%qs_env, ehrenfest, delta_iter=force_env%qs_env%rtp%delta_iter)
634 END IF
635
636 ! Metadynamics
637 CALL metadyn_integrator(force_env, itimes, tmp%vel)
638
639 ! Velocity Verlet (second part)
640 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
641 core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
642
643 IF (simpar%constraint) CALL rattle_control(gci, local_molecules, molecule_set, &
644 molecule_kind_set, particle_set, tmp%vel, dt, simpar%shake_tol, &
645 simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
646 cell, para_env, local_particles)
647
648 ! Apply thermostat over the full set of shell if required
649 IF (shell_adiabatic) THEN
650 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
651 local_particles, para_env, vel=tmp%vel, &
652 shell_vel=tmp%shell_vel, core_vel=tmp%core_vel)
653 END IF
654
655 IF (simpar%annealing) THEN
656 tmp%vel(:, :) = tmp%vel(:, :)*simpar%f_annealing
657 IF (shell_adiabatic) THEN
658 CALL shell_scale_comv(atomic_kind_set, local_particles, particle_set, &
659 tmp%vel, tmp%shell_vel, tmp%core_vel)
660 END IF
661 END IF
662
663 IF (ehrenfest_md) deallocate_vel = force_env%qs_env%rtp%converged
664 IF (i_iter == n_iter) deallocate_vel = .true.
665 ! Broadcast the new particle velocities and deallocate the full temporary
666 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
667 core_particle_set, para_env, shell_adiabatic, vel=.true., &
668 should_deall_vel=deallocate_vel)
669 IF (ehrenfest_md) THEN
670 IF (force_env%qs_env%rtp%converged) EXIT
671 END IF
672
673 END DO
674
675 ! Update virial
676 IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, &
677 molecule_set, molecule_kind_set, particle_set, virial, para_env)
678
679 CALL virial_evaluate(atomic_kind_set, particle_set, &
680 local_particles, virial, para_env)
681
682 END SUBROUTINE nve
683
684! **************************************************************************************************
685!> \brief simplest version of the isokinetic gaussian thermostat
686!> \param md_env ...
687!> \par History
688!> - Created [2004-07]
689!> \author Joost VandeVondele
690!> \note
691!> - time reversible, and conserves the kinetic energy to machine precision
692!> - is not yet supposed to work for e.g. constraints, our the extended version
693!> of this thermostat
694!> see:
695!> - Zhang F. , JCP 106, 6102 (1997)
696!> - Minary P. et al, JCP 118, 2510 (2003)
697! **************************************************************************************************
698 SUBROUTINE isokin(md_env)
699
700 TYPE(md_environment_type), POINTER :: md_env
701
702 INTEGER :: nparticle, nparticle_kind, nshell
703 INTEGER, POINTER :: itimes
704 LOGICAL :: shell_adiabatic, shell_present
705 REAL(kind=dp) :: dt
706 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
707 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
708 TYPE(cp_subsys_type), POINTER :: subsys
709 TYPE(distribution_1d_type), POINTER :: local_particles
710 TYPE(force_env_type), POINTER :: force_env
711 TYPE(mp_para_env_type), POINTER :: para_env
712 TYPE(particle_list_type), POINTER :: core_particles, particles, &
713 shell_particles
714 TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
715 shell_particle_set
716 TYPE(simpar_type), POINTER :: simpar
717 TYPE(tmp_variables_type), POINTER :: tmp
718
719 NULLIFY (force_env, tmp, simpar, itimes)
720 NULLIFY (atomic_kinds, para_env, subsys, local_particles)
721 NULLIFY (core_particles, particles, shell_particles)
722 NULLIFY (core_particle_set, particle_set, shell_particle_set)
723
724 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
725 para_env=para_env, itimes=itimes)
726
727 dt = simpar%dt
728
729 CALL force_env_get(force_env=force_env, subsys=subsys)
730
731 ! Do some checks on coordinates and box
732 CALL apply_qmmm_walls_reflective(force_env)
733
734 IF (simpar%constraint) THEN
735 cpabort("Constraints not yet implemented")
736 END IF
737
738 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, &
739 local_particles=local_particles, &
740 particles=particles)
741
742 nparticle_kind = atomic_kinds%n_els
743 atomic_kind_set => atomic_kinds%els
744 nparticle = particles%n_els
745 particle_set => particles%els
746
747 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
748 shell_present=shell_present, shell_adiabatic=shell_adiabatic)
749
750 IF (shell_present) THEN
751 CALL cp_subsys_get(subsys=subsys, shell_particles=shell_particles, &
752 core_particles=core_particles)
753 shell_particle_set => shell_particles%els
754 nshell = SIZE(shell_particles%els)
755
756 IF (shell_adiabatic) THEN
757 core_particle_set => core_particles%els
758 END IF
759 END IF
760
761 CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
762
763 ! compute s,ds
764 CALL get_s_ds(tmp, nparticle_kind, atomic_kind_set, local_particles, particle_set, &
765 dt, para_env)
766
767 ! Velocity Verlet (first part)
768 tmp%scale_v(1:3) = sqrt(1.0_dp/tmp%ds)
769 tmp%poly_v(1:3) = 2.0_dp*tmp%s/sqrt(tmp%ds)/dt
770 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
771 core_particle_set, shell_particle_set, nparticle_kind, &
772 shell_adiabatic, dt)
773
774 IF (simpar%variable_dt) CALL variable_timestep(md_env, tmp, dt, simpar, para_env, atomic_kind_set, &
775 local_particles, particle_set, core_particle_set, shell_particle_set, &
776 nparticle_kind, shell_adiabatic)
777
778 ! Broadcast the new particle positions and deallocate the pos components of temporary
779 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
780 core_particle_set, para_env, shell_adiabatic, pos=.true.)
781
782 CALL force_env_calc_energy_force(force_env)
783
784 ! Metadynamics
785 CALL metadyn_integrator(force_env, itimes, tmp%vel)
786
787 ! compute s,ds
788 CALL get_s_ds(tmp, nparticle_kind, atomic_kind_set, local_particles, particle_set, &
789 dt, para_env, tmpv=.true.)
790
791 ! Velocity Verlet (second part)
792 tmp%scale_v(1:3) = sqrt(1.0_dp/tmp%ds)
793 tmp%poly_v(1:3) = 2.0_dp*tmp%s/sqrt(tmp%ds)/dt
794 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
795 core_particle_set, shell_particle_set, nparticle_kind, &
796 shell_adiabatic, dt)
797
798 IF (simpar%annealing) tmp%vel(:, :) = tmp%vel(:, :)*simpar%f_annealing
799
800 ! Broadcast the new particle velocities and deallocate the temporary
801 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
802 core_particle_set, para_env, shell_adiabatic, vel=.true.)
803
804 END SUBROUTINE isokin
805! **************************************************************************************************
806!> \brief nvt adiabatic integrator for particle positions & momenta
807!> \param md_env ...
808!> \param globenv ...
809!> \par History
810!> - the local particle lists are used instead of pnode (Sep. 2003,MK)
811!> - usage of fragments retrieved from the force environment (Oct. 2003,MK)
812!> \author CJM
813! **************************************************************************************************
814 SUBROUTINE nvt_adiabatic(md_env, globenv)
815
816 TYPE(md_environment_type), POINTER :: md_env
817 TYPE(global_environment_type), POINTER :: globenv
818
819 INTEGER :: ivar, nparticle, nparticle_kind, nshell
820 INTEGER, POINTER :: itimes
821 LOGICAL :: shell_adiabatic, shell_check_distance, &
822 shell_present
823 REAL(kind=dp) :: dt
824 REAL(kind=dp), DIMENSION(:), POINTER :: rand
825 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
826 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
827 TYPE(cell_type), POINTER :: cell
828 TYPE(cp_subsys_type), POINTER :: subsys
829 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
830 TYPE(force_env_type), POINTER :: force_env
831 TYPE(global_constraint_type), POINTER :: gci
832 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
833 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
834 TYPE(molecule_list_type), POINTER :: molecules
835 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
836 TYPE(mp_para_env_type), POINTER :: para_env
837 TYPE(particle_list_type), POINTER :: core_particles, particles, &
838 shell_particles
839 TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
840 shell_particle_set
841 TYPE(simpar_type), POINTER :: simpar
842 TYPE(thermostat_type), POINTER :: thermostat_coeff, thermostat_fast, &
843 thermostat_shell, thermostat_slow
844 TYPE(tmp_variables_type), POINTER :: tmp
845 TYPE(virial_type), POINTER :: virial
846
847 NULLIFY (gci, force_env, thermostat_coeff, tmp, &
848 thermostat_fast, thermostat_slow, thermostat_shell, cell, shell_particles, &
849 shell_particle_set, core_particles, core_particle_set, rand)
850 NULLIFY (para_env, subsys, local_molecules, local_particles, molecule_kinds, &
851 molecules, molecule_kind_set, molecule_set, atomic_kinds, particles)
852 NULLIFY (simpar, itimes)
853
854 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
855 thermostat_fast=thermostat_fast, thermostat_slow=thermostat_slow, &
856 thermostat_coeff=thermostat_coeff, thermostat_shell=thermostat_shell, &
857 para_env=para_env, itimes=itimes)
858 dt = simpar%dt
859
860 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
861
862 ! Do some checks on coordinates and box
863 CALL apply_qmmm_walls_reflective(force_env)
864
865 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
866 particles=particles, local_molecules=local_molecules, molecules=molecules, &
867 molecule_kinds=molecule_kinds, gci=gci, virial=virial)
868
869 nparticle_kind = atomic_kinds%n_els
870 atomic_kind_set => atomic_kinds%els
871 molecule_kind_set => molecule_kinds%els
872
873 nparticle = particles%n_els
874 particle_set => particles%els
875 molecule_set => molecules%els
876
877 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
878 shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
879 shell_check_distance=shell_check_distance)
880
881 IF (ASSOCIATED(force_env%meta_env)) THEN
882 ! Allocate random number for Langevin Thermostat acting on COLVARS
883 IF (force_env%meta_env%langevin) THEN
884 ALLOCATE (rand(force_env%meta_env%n_colvar))
885 rand(:) = 0.0_dp
886 END IF
887 END IF
888
889 ! Allocate work storage for positions and velocities
890 IF (shell_present) THEN
891 CALL cp_subsys_get(subsys=subsys, shell_particles=shell_particles, &
892 core_particles=core_particles)
893 shell_particle_set => shell_particles%els
894 nshell = SIZE(shell_particles%els)
895
896 IF (shell_adiabatic) THEN
897 core_particle_set => core_particles%els
898 END IF
899 END IF
900
901 CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
902
903 ! Apply Thermostat over the full set of particles
904 IF (shell_adiabatic) THEN
905! CALL apply_thermostat_particles(thermostat_part, molecule_kind_set, molecule_set,&
906! particle_set, local_molecules, para_env, shell_adiabatic=shell_adiabatic,&
907! shell_particle_set=shell_particle_set, core_particle_set=core_particle_set)
908
909 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
910 local_particles, para_env, shell_particle_set=shell_particle_set, &
911 core_particle_set=core_particle_set)
912 ELSE
913 CALL apply_thermostat_particles(thermostat_fast, force_env, molecule_kind_set, molecule_set, &
914 particle_set, local_molecules, local_particles, para_env)
915
916 CALL apply_thermostat_particles(thermostat_slow, force_env, molecule_kind_set, molecule_set, &
917 particle_set, local_molecules, local_particles, para_env)
918 END IF
919
920 IF (simpar%constraint) CALL getold(gci, local_molecules, molecule_set, &
921 molecule_kind_set, particle_set, cell)
922
923 ! *** Velocity Verlet for Langeving *** v(t)--> v(t+1/2)
924 IF (ASSOCIATED(force_env%meta_env)) THEN
925 IF (force_env%meta_env%langevin) THEN
926 DO ivar = 1, force_env%meta_env%n_colvar
927 rand(ivar) = force_env%meta_env%rng(ivar)%next()
928 END DO
929 CALL metadyn_velocities_colvar(force_env, rand)
930 END IF
931 END IF
932
933 ! Velocity Verlet (first part)
934 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
935 core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
936
937 IF (simpar%variable_dt) CALL variable_timestep(md_env, tmp, dt, simpar, para_env, atomic_kind_set, &
938 local_particles, particle_set, core_particle_set, shell_particle_set, &
939 nparticle_kind, shell_adiabatic)
940
941 IF (simpar%constraint) THEN
942 ! Possibly update the target values
943 CALL shake_update_targets(gci, local_molecules, molecule_set, &
944 molecule_kind_set, dt, force_env%root_section)
945
946 CALL shake_control(gci, local_molecules, molecule_set, &
947 molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, simpar%shake_tol, &
948 simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
949 cell, para_env, local_particles)
950 END IF
951
952 ! Broadcast the new particle positions and deallocate pos components of temporary
953 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
954 core_particle_set, para_env, shell_adiabatic, pos=.true.)
955
956 IF (shell_adiabatic .AND. shell_check_distance) THEN
957 CALL optimize_shell_core(force_env, particle_set, &
958 shell_particle_set, core_particle_set, globenv, tmp=tmp, check=.true.)
959 END IF
960
961 ! Update forces
962 CALL force_env_calc_energy_force(force_env)
963
964 ! Metadynamics
965 CALL metadyn_integrator(force_env, itimes, tmp%vel, rand=rand)
966
967 ! Velocity Verlet (second part)
968 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
969 core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
970
971 IF (simpar%constraint) CALL rattle_control(gci, local_molecules, molecule_set, &
972 molecule_kind_set, particle_set, tmp%vel, dt, simpar%shake_tol, &
973 simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
974 cell, para_env, local_particles)
975
976 ! Apply Thermostat over the full set of particles
977 IF (shell_adiabatic) THEN
978 ! CALL apply_thermostat_particles(thermostat_part,molecule_kind_set, molecule_set, &
979 ! particle_set, local_molecules, para_env, shell_adiabatic=shell_adiabatic,&
980 ! vel= tmp%vel, shell_vel= tmp%shell_vel, core_vel= tmp%core_vel)
981
982 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
983 local_particles, para_env, vel=tmp%vel, shell_vel=tmp%shell_vel, &
984 core_vel=tmp%core_vel)
985 ELSE
986 CALL apply_thermostat_particles(thermostat_slow, force_env, molecule_kind_set, molecule_set, &
987 particle_set, local_molecules, local_particles, para_env, vel=tmp%vel)
988
989 CALL apply_thermostat_particles(thermostat_fast, force_env, molecule_kind_set, molecule_set, &
990 particle_set, local_molecules, local_particles, para_env, vel=tmp%vel)
991 END IF
992
993 ! Broadcast the new particle velocities and deallocate temporary
994 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
995 core_particle_set, para_env, shell_adiabatic, vel=.true.)
996
997 IF (ASSOCIATED(force_env%meta_env)) THEN
998 IF (force_env%meta_env%langevin) THEN
999 DEALLOCATE (rand)
1000 END IF
1001 END IF
1002
1003 ! Update constraint virial
1004 IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, &
1005 molecule_set, molecule_kind_set, particle_set, virial, para_env)
1006
1007 ! ** Evaluate Virial
1008 CALL virial_evaluate(atomic_kind_set, particle_set, &
1009 local_particles, virial, para_env)
1010
1011 END SUBROUTINE nvt_adiabatic
1012
1013! **************************************************************************************************
1014!> \brief nvt integrator for particle positions & momenta
1015!> \param md_env ...
1016!> \param globenv ...
1017!> \par History
1018!> - the local particle lists are used instead of pnode (Sep. 2003,MK)
1019!> - usage of fragments retrieved from the force environment (Oct. 2003,MK)
1020!> \author CJM
1021! **************************************************************************************************
1022 SUBROUTINE nvt(md_env, globenv)
1023
1024 TYPE(md_environment_type), POINTER :: md_env
1025 TYPE(global_environment_type), POINTER :: globenv
1026
1027 INTEGER :: ivar, nparticle, nparticle_kind, nshell
1028 INTEGER, POINTER :: itimes
1029 LOGICAL :: shell_adiabatic, shell_check_distance, &
1030 shell_present
1031 REAL(kind=dp) :: dt, lambda_mix
1032 REAL(kind=dp), DIMENSION(:), POINTER :: rand
1033 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
1034 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1035 TYPE(cell_type), POINTER :: cell
1036 TYPE(cp_subsys_type), POINTER :: subsys
1037 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
1038 TYPE(force_env_type), POINTER :: force_env
1039 TYPE(global_constraint_type), POINTER :: gci
1040 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
1041 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
1042 TYPE(molecule_list_type), POINTER :: molecules
1043 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
1044 TYPE(mp_para_env_type), POINTER :: para_env
1045 TYPE(particle_list_type), POINTER :: core_particles, particles, &
1046 shell_particles
1047 TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
1048 shell_particle_set
1049 TYPE(qs_electrons_type), POINTER :: electrons
1050 TYPE(simpar_type), POINTER :: simpar
1051 TYPE(thermostat_type), POINTER :: thermostat_coeff, thermostat_part, &
1052 thermostat_shell
1053 TYPE(tmp_variables_type), POINTER :: tmp
1054 TYPE(virial_type), POINTER :: virial
1055
1056 NULLIFY (gci, force_env, thermostat_coeff, tmp, &
1057 thermostat_part, thermostat_shell, cell, shell_particles, &
1058 shell_particle_set, core_particles, core_particle_set, rand)
1059 NULLIFY (para_env, subsys, local_molecules, local_particles, molecule_kinds, &
1060 molecules, molecule_kind_set, molecule_set, atomic_kinds, particles)
1061 NULLIFY (simpar, thermostat_coeff, thermostat_part, thermostat_shell, itimes, electrons)
1062
1063 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
1064 thermostat_part=thermostat_part, thermostat_coeff=thermostat_coeff, &
1065 thermostat_shell=thermostat_shell, para_env=para_env, &
1066 itimes=itimes, electrons=electrons)
1067 dt = simpar%dt
1068
1069 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
1070
1071 ! Do some checks on coordinates and box
1072 CALL apply_qmmm_walls_reflective(force_env)
1073
1074 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
1075 particles=particles, local_molecules=local_molecules, molecules=molecules, &
1076 molecule_kinds=molecule_kinds, gci=gci, virial=virial)
1077
1078 nparticle_kind = atomic_kinds%n_els
1079 atomic_kind_set => atomic_kinds%els
1080 molecule_kind_set => molecule_kinds%els
1081
1082 nparticle = particles%n_els
1083 particle_set => particles%els
1084 molecule_set => molecules%els
1085
1086 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
1087 shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
1088 shell_check_distance=shell_check_distance)
1089
1090 IF (ASSOCIATED(force_env%meta_env)) THEN
1091 ! Allocate random number for Langevin Thermostat acting on COLVARS
1092 IF (force_env%meta_env%langevin) THEN
1093 ALLOCATE (rand(force_env%meta_env%n_colvar))
1094 rand(:) = 0.0_dp
1095 END IF
1096 END IF
1097
1098 ! Allocate work storage for positions and velocities
1099 IF (shell_present) THEN
1100 CALL cp_subsys_get(subsys=subsys, shell_particles=shell_particles, &
1101 core_particles=core_particles)
1102 shell_particle_set => shell_particles%els
1103 nshell = SIZE(shell_particles%els)
1104
1105 IF (shell_adiabatic) THEN
1106 core_particle_set => core_particles%els
1107 END IF
1108 END IF
1109
1110 CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
1111
1112 ! Apply Thermostat over the full set of particles
1113 IF (shell_adiabatic) THEN
1114 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
1115 particle_set, local_molecules, local_particles, para_env, shell_adiabatic=shell_adiabatic, &
1116 shell_particle_set=shell_particle_set, core_particle_set=core_particle_set)
1117
1118 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
1119 local_particles, para_env, shell_particle_set=shell_particle_set, &
1120 core_particle_set=core_particle_set)
1121 ELSE
1122 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
1123 particle_set, local_molecules, local_particles, para_env)
1124 END IF
1125
1126 ! The potentiostat (O step) fires once per MD step, in the middle of the
1127 ! electronic drift below, giving a B A O A B splitting for the electronic
1128 ! degree of freedom.
1129
1130 IF (simpar%constraint) CALL getold(gci, local_molecules, molecule_set, &
1131 molecule_kind_set, particle_set, cell)
1132
1133 ! *** Velocity Verlet for Langeving *** v(t)--> v(t+1/2)
1134 IF (ASSOCIATED(force_env%meta_env)) THEN
1135 IF (force_env%meta_env%langevin) THEN
1136 DO ivar = 1, force_env%meta_env%n_colvar
1137 rand(ivar) = force_env%meta_env%rng(ivar)%next()
1138 END DO
1139 CALL metadyn_velocities_colvar(force_env, rand)
1140 END IF
1141 END IF
1142
1143 ! Velocity Verlet (first part)
1144 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
1145 core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
1146 IF (ASSOCIATED(electrons)) THEN
1147 ! BAOAB on the electronic coordinate: half kick, half drift, ONE full
1148 ! thermostat step, half drift. The closing half kick is after the force
1149 ! evaluation below. qs_electrons_thermostat_step takes the interval
1150 ! BETWEEN calls, which is now dt (one call per step), not 0.5*dt.
1151 ! report_only ("&ELECTRONS 0"): skip the whole BAOAB block. q is not
1152 ! propagated, the endpoints are never rebuilt, and in particular
1153 ! apply_ne_core_correction is NOT called -- it would alter the system's
1154 ! charge, which in report-only mode must stay exactly as the input set
1155 ! it. Only the work-function readback below still runs.
1156 IF (.NOT. electrons%report_only) THEN
1157 CALL qs_electrons_kick(electrons, 0.5_dp*dt)
1158 CALL qs_electrons_drift(electrons, 0.5_dp*dt)
1159 CALL qs_electrons_thermostat_step(electrons, dt)
1160 CALL qs_electrons_drift(electrons, 0.5_dp*dt)
1161 IF (electrons%charge_mixing_enabled) THEN
1162 CALL charge_mixing_maybe_rebuild(force_env, electrons)
1163 CALL qs_electrons_charge_mixing_lambda(electrons, lambda_mix)
1164 CALL push_lambda_to_mixed_env(force_env, lambda_mix)
1165 ELSE
1166 CALL apply_ne_core_correction(force_env, electrons%q, electrons%neutral_electrons)
1167 END IF
1168 END IF
1169 END IF
1170
1171 IF (simpar%variable_dt) CALL variable_timestep(md_env, tmp, dt, simpar, para_env, atomic_kind_set, &
1172 local_particles, particle_set, core_particle_set, shell_particle_set, &
1173 nparticle_kind, shell_adiabatic)
1174
1175 IF (simpar%constraint) THEN
1176 ! Possibly update the target values
1177 CALL shake_update_targets(gci, local_molecules, molecule_set, &
1178 molecule_kind_set, dt, force_env%root_section)
1179
1180 CALL shake_control(gci, local_molecules, molecule_set, &
1181 molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, simpar%shake_tol, &
1182 simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
1183 cell, para_env, local_particles)
1184 END IF
1185
1186 ! Broadcast the new particle positions and deallocate pos components of temporary
1187 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
1188 core_particle_set, para_env, shell_adiabatic, pos=.true.)
1189
1190 IF (shell_adiabatic .AND. shell_check_distance) THEN
1191 CALL optimize_shell_core(force_env, particle_set, &
1192 shell_particle_set, core_particle_set, globenv, tmp=tmp, check=.true.)
1193 END IF
1194
1195 ![ADAPT] update input structure with new coordinates, make new labels
1196 CALL qmmmx_update_force_env(force_env, force_env%root_section)
1197
1198 ![NB] recreate pointers changed by creation of new subsys in qmmm_update_force_mixing_env
1199 ![NB] ugly hack, which is why adaptivity isn't implemented in most other ensembles
1200 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1201 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
1202
1203 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
1204 particles=particles, local_molecules=local_molecules, molecules=molecules, &
1205 molecule_kinds=molecule_kinds, gci=gci, virial=virial)
1206
1207 nparticle_kind = atomic_kinds%n_els
1208 atomic_kind_set => atomic_kinds%els
1209 molecule_kind_set => molecule_kinds%els
1210
1211 nparticle = particles%n_els
1212 particle_set => particles%els
1213 molecule_set => molecules%els
1214
1215 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
1216 shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
1217 shell_check_distance=shell_check_distance)
1218
1219 ! Allocate work storage for positions and velocities
1220 IF (shell_present) THEN
1221 CALL cp_subsys_get(subsys=subsys, shell_particles=shell_particles, &
1222 core_particles=core_particles)
1223 shell_particle_set => shell_particles%els
1224 nshell = SIZE(shell_particles%els)
1225
1226 IF (shell_adiabatic) THEN
1227 core_particle_set => core_particles%els
1228 END IF
1229 END IF
1230 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
1231
1232 ! Update forces
1233 ![NB] let nvt work with force mixing which does not have consistent energies and forces
1234 CALL force_env_calc_energy_force(force_env, require_consistent_energy_force=.false.)
1235
1236 IF (ASSOCIATED(electrons)) THEN
1237 IF (electrons%charge_mixing_enabled) THEN
1238 CALL compute_mixed_workfunction(force_env, electrons%potential_average_axis, &
1239 electrons%potential_average_min, electrons%potential_average_max, &
1240 electrons%q, electrons%charge_mixing_span, &
1241 electrons%current_fermi_level_eV, electrons%current_workfunction, &
1242 lambda_in=lambda_mix)
1243 ELSE
1244 CALL qs_electrons_compute_workfunction(force_env, electrons%potential_average_axis, &
1245 electrons%potential_average_min, electrons%potential_average_max, &
1246 electrons%current_fermi_level_eV, electrons%current_workfunction)
1247 END IF
1248 END IF
1249
1250 ! Metadynamics
1251 CALL metadyn_integrator(force_env, itimes, tmp%vel, rand=rand)
1252
1253 ! Velocity Verlet (second part)
1254 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
1255 core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
1256
1257 IF (ASSOCIATED(electrons)) THEN
1258 ! report_only ("&ELECTRONS 0"): q is never propagated, so no B step.
1259 IF (.NOT. electrons%report_only) CALL qs_electrons_kick(electrons, 0.5_dp*dt)
1260 END IF
1261
1262 IF (simpar%constraint) CALL rattle_control(gci, local_molecules, molecule_set, &
1263 molecule_kind_set, particle_set, tmp%vel, dt, simpar%shake_tol, &
1264 simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
1265 cell, para_env, local_particles)
1266
1267 ! Apply Thermostat over the full set of particles
1268 IF (shell_adiabatic) THEN
1269 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
1270 particle_set, local_molecules, local_particles, para_env, shell_adiabatic=shell_adiabatic, &
1271 vel=tmp%vel, shell_vel=tmp%shell_vel, core_vel=tmp%core_vel)
1272
1273 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
1274 local_particles, para_env, vel=tmp%vel, shell_vel=tmp%shell_vel, &
1275 core_vel=tmp%core_vel)
1276 ELSE
1277 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
1278 particle_set, local_molecules, local_particles, para_env, vel=tmp%vel)
1279 END IF
1280
1281 ! (no trailing electronic O: BAOAB places the single potentiostat step in
1282 ! the middle of the drift, not at the step boundaries.)
1283
1284 ! Broadcast the new particle velocities and deallocate temporary
1285 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
1286 core_particle_set, para_env, shell_adiabatic, vel=.true.)
1287
1288 IF (ASSOCIATED(force_env%meta_env)) THEN
1289 IF (force_env%meta_env%langevin) THEN
1290 DEALLOCATE (rand)
1291 END IF
1292 END IF
1293
1294 ! Update constraint virial
1295 IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, &
1296 molecule_set, molecule_kind_set, particle_set, virial, para_env)
1297
1298 ! ** Evaluate Virial
1299 CALL virial_evaluate(atomic_kind_set, particle_set, &
1300 local_particles, virial, para_env)
1301
1302 END SUBROUTINE nvt
1303
1304! **************************************************************************************************
1305!> \brief npt_i integrator for particle positions & momenta
1306!> isotropic box changes
1307!> \param md_env ...
1308!> \param globenv ...
1309!> \par History
1310!> none
1311!> \author CJM
1312! **************************************************************************************************
1313 SUBROUTINE npt_i(md_env, globenv)
1314
1315 TYPE(md_environment_type), POINTER :: md_env
1316 TYPE(global_environment_type), POINTER :: globenv
1317
1318 REAL(kind=dp), PARAMETER :: e2 = 1.0_dp/6.0_dp, e4 = e2/20.0_dp, &
1319 e6 = e4/42.0_dp, e8 = e6/72.0_dp
1320
1321 INTEGER :: iroll, ivar, nkind, nparticle, &
1322 nparticle_kind, nshell
1323 INTEGER, POINTER :: itimes
1324 LOGICAL :: first, first_time, shell_adiabatic, &
1325 shell_check_distance, shell_present
1326 REAL(kind=dp) :: dt, infree, kin, roll_tol, roll_tol_thrs
1327 REAL(kind=dp), DIMENSION(3) :: vector_r, vector_v
1328 REAL(kind=dp), DIMENSION(3, 3) :: pv_kin
1329 REAL(kind=dp), DIMENSION(:), POINTER :: rand
1330 REAL(kind=dp), SAVE :: eps_0
1331 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
1332 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1333 TYPE(cell_type), POINTER :: cell
1334 TYPE(cp_subsys_type), POINTER :: subsys
1335 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
1336 TYPE(force_env_type), POINTER :: force_env
1337 TYPE(global_constraint_type), POINTER :: gci
1338 TYPE(local_fixd_constraint_type), DIMENSION(:), &
1339 POINTER :: lfixd_list
1340 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
1341 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
1342 TYPE(molecule_list_type), POINTER :: molecules
1343 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
1344 TYPE(mp_para_env_type), POINTER :: para_env
1345 TYPE(npt_info_type), POINTER :: npt(:, :)
1346 TYPE(old_variables_type), POINTER :: old
1347 TYPE(particle_list_type), POINTER :: core_particles, particles, &
1348 shell_particles
1349 TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
1350 shell_particle_set
1351 TYPE(simpar_type), POINTER :: simpar
1352 TYPE(thermostat_type), POINTER :: thermostat_baro, thermostat_part, &
1353 thermostat_shell
1354 TYPE(tmp_variables_type), POINTER :: tmp
1355 TYPE(virial_type), POINTER :: virial
1356
1357 NULLIFY (gci, thermostat_baro, thermostat_part, thermostat_shell, force_env)
1358 NULLIFY (atomic_kinds, cell, para_env, subsys, local_molecules, local_particles)
1359 NULLIFY (molecule_kinds, molecules, molecule_kind_set, npt)
1360 NULLIFY (core_particles, particles, shell_particles, tmp, old)
1361 NULLIFY (core_particle_set, particle_set, shell_particle_set)
1362 NULLIFY (simpar, virial, rand, itimes, lfixd_list)
1363
1364 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
1365 thermostat_part=thermostat_part, thermostat_baro=thermostat_baro, &
1366 thermostat_shell=thermostat_shell, npt=npt, first_time=first_time, &
1367 para_env=para_env, itimes=itimes)
1368 dt = simpar%dt
1369 infree = 1.0_dp/real(simpar%nfree, kind=dp)
1370
1371 CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
1372
1373 ! Do some checks on coordinates and box
1374 CALL apply_qmmm_walls_reflective(force_env)
1375
1376 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
1377 particles=particles, local_molecules=local_molecules, molecules=molecules, &
1378 gci=gci, molecule_kinds=molecule_kinds, virial=virial)
1379
1380 nparticle_kind = atomic_kinds%n_els
1381 nkind = molecule_kinds%n_els
1382 atomic_kind_set => atomic_kinds%els
1383 molecule_kind_set => molecule_kinds%els
1384
1385 nparticle = particles%n_els
1386 particle_set => particles%els
1387 molecule_set => molecules%els
1388
1389 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
1390 shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
1391 shell_check_distance=shell_check_distance)
1392
1393 IF (first_time) THEN
1394 CALL virial_evaluate(atomic_kind_set, particle_set, &
1395 local_particles, virial, para_env)
1396 END IF
1397
1398 ! Allocate work storage for positions and velocities
1399 CALL allocate_old(old, particle_set, npt)
1400
1401 IF (ASSOCIATED(force_env%meta_env)) THEN
1402 ! Allocate random number for Langevin Thermostat acting on COLVARS
1403 IF (force_env%meta_env%langevin) THEN
1404 ALLOCATE (rand(force_env%meta_env%n_colvar))
1405 rand(:) = 0.0_dp
1406 END IF
1407 END IF
1408
1409 IF (shell_present) THEN
1410 CALL cp_subsys_get(subsys=subsys, &
1411 shell_particles=shell_particles, core_particles=core_particles)
1412 shell_particle_set => shell_particles%els
1413 nshell = SIZE(shell_particles%els)
1414 IF (shell_adiabatic) THEN
1415 core_particle_set => core_particles%els
1416 END IF
1417 END IF
1418
1419 CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
1420
1421 ! Initialize eps_0 the first time through
1422 IF (first_time) eps_0 = npt(1, 1)%eps
1423
1424 ! Apply thermostat to barostat
1425 CALL apply_thermostat_baro(thermostat_baro, npt, para_env)
1426
1427 ! Apply Thermostat over the full set of particles
1428 IF (simpar%ensemble /= npe_i_ensemble) THEN
1429 IF (shell_adiabatic) THEN
1430 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
1431 particle_set, local_molecules, local_particles, para_env, shell_adiabatic=shell_adiabatic, &
1432 shell_particle_set=shell_particle_set, core_particle_set=core_particle_set)
1433
1434 ELSE
1435 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
1436 particle_set, local_molecules, local_particles, para_env)
1437 END IF
1438 END IF
1439
1440 ! Apply Thermostat over the core-shell motion
1441 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
1442 local_particles, para_env, shell_particle_set=shell_particle_set, &
1443 core_particle_set=core_particle_set)
1444
1445 IF (simpar%constraint) THEN
1446 ! Possibly update the target values
1447 CALL shake_update_targets(gci, local_molecules, molecule_set, &
1448 molecule_kind_set, dt, force_env%root_section)
1449 END IF
1450
1451 ! setting up for ROLL: saving old variables
1452 IF (simpar%constraint) THEN
1453 roll_tol_thrs = simpar%roll_tol
1454 iroll = 1
1455 CALL set(old, atomic_kind_set, particle_set, local_particles, cell, npt, 'F')
1456 CALL getold(gci, local_molecules, molecule_set, &
1457 molecule_kind_set, particle_set, cell)
1458 ELSE
1459 roll_tol_thrs = epsilon(0.0_dp)
1460 END IF
1461 roll_tol = -roll_tol_thrs
1462
1463 ! *** Velocity Verlet for Langeving *** v(t)--> v(t+1/2)
1464 IF (ASSOCIATED(force_env%meta_env)) THEN
1465 IF (force_env%meta_env%langevin) THEN
1466 DO ivar = 1, force_env%meta_env%n_colvar
1467 rand(ivar) = force_env%meta_env%rng(ivar)%next()
1468 END DO
1469 CALL metadyn_velocities_colvar(force_env, rand)
1470 END IF
1471 END IF
1472
1473 sr: DO WHILE (abs(roll_tol) >= roll_tol_thrs) ! SHAKE-ROLL LOOP
1474
1475 IF (simpar%constraint) THEN
1476 CALL set(old, atomic_kind_set, particle_set, local_particles, cell, npt, 'B')
1477 END IF
1478
1479 CALL update_pv(gci, simpar, atomic_kind_set, particle_set, &
1480 local_molecules, molecule_set, molecule_kind_set, &
1481 local_particles, kin, pv_kin, virial, para_env)
1482 CALL update_veps(cell, npt, simpar, pv_kin, kin, virial, infree)
1483
1484 tmp%arg_r(1) = (0.5_dp*npt(1, 1)%v*dt)* &
1485 (0.5_dp*npt(1, 1)%v*dt)
1486 tmp%poly_r(1:3) = 1.0_dp + e2*tmp%arg_r(1) + e4*tmp%arg_r(1)*tmp%arg_r(1) + &
1487 e6*tmp%arg_r(1)**3 + e8*tmp%arg_r(1)**4
1488
1489 tmp%arg_v(1) = (0.25_dp*npt(1, 1)%v*dt* &
1490 (1.0_dp + 3.0_dp*infree))*(0.25_dp*npt(1, 1)%v* &
1491 dt*(1.0_dp + 3.0_dp*infree))
1492 tmp%poly_v(1:3) = 1.0_dp + e2*tmp%arg_v(1) + e4*tmp%arg_v(1)*tmp%arg_v(1) + &
1493 e6*tmp%arg_v(1)**3 + e8*tmp%arg_v(1)**4
1494
1495 tmp%scale_r(1:3) = exp(0.5_dp*dt*npt(1, 1)%v)
1496 tmp%scale_v(1:3) = exp(-0.25_dp*dt*npt(1, 1)%v* &
1497 (1.0_dp + 3.0_dp*infree))
1498
1499 ! first half of velocity verlet
1500 IF (simpar%ensemble == npt_ia_ensemble) THEN
1501 CALL create_local_fixd_list(lfixd_list, nkind, molecule_kind_set, local_particles)
1502 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
1503 core_particle_set, shell_particle_set, nparticle_kind, &
1504 shell_adiabatic, dt, lfixd_list=lfixd_list)
1505 CALL release_local_fixd_list(lfixd_list)
1506 ELSE
1507 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
1508 core_particle_set, shell_particle_set, nparticle_kind, &
1509 shell_adiabatic, dt)
1510 END IF
1511
1512 IF (simpar%variable_dt) CALL variable_timestep(md_env, tmp, dt, simpar, para_env, &
1513 atomic_kind_set, local_particles, particle_set, core_particle_set, &
1514 shell_particle_set, nparticle_kind, shell_adiabatic, npt=npt)
1515
1516 roll_tol = 0.0_dp
1517 vector_r(:) = tmp%scale_r(:)*tmp%poly_r(:)
1518 vector_v(:) = tmp%scale_v(:)*tmp%poly_v(:)
1519
1520 IF (simpar%constraint) CALL shake_roll_control(gci, local_molecules, &
1521 molecule_set, molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, simpar, &
1522 roll_tol, iroll, vector_r, vector_v, para_env, cell=cell, &
1523 local_particles=local_particles)
1524 END DO sr
1525
1526 ! Update eps:
1527 npt(:, :)%eps = npt(:, :)%eps + dt*npt(:, :)%v
1528
1529 ! Update h_mat
1530 cell%hmat(:, :) = cell%hmat(:, :)*exp(npt(1, 1)%eps - eps_0)
1531
1532 eps_0 = npt(1, 1)%eps
1533
1534 ! Update the inverse
1535 CALL init_cell(cell)
1536
1537 ! Broadcast the new particle positions and deallocate the pos components of temporary
1538 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
1539 core_particle_set, para_env, shell_adiabatic, pos=.true.)
1540
1541 IF (shell_adiabatic .AND. shell_check_distance) THEN
1542 CALL optimize_shell_core(force_env, particle_set, &
1543 shell_particle_set, core_particle_set, globenv, tmp=tmp, check=.true.)
1544 END IF
1545
1546 ! Update forces
1547 CALL force_env_calc_energy_force(force_env)
1548
1549 ! Metadynamics
1550 CALL metadyn_integrator(force_env, itimes, tmp%vel, rand=rand)
1551
1552 ! Velocity Verlet (second part)
1553 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
1554 core_particle_set, shell_particle_set, nparticle_kind, &
1555 shell_adiabatic, dt)
1556
1557 IF (simpar%constraint) THEN
1558 roll_tol_thrs = simpar%roll_tol
1559 first = .true.
1560 iroll = 1
1561 CALL set(old, atomic_kind_set, particle_set, tmp%vel, local_particles, cell, npt, 'F')
1562 ELSE
1563 roll_tol_thrs = epsilon(0.0_dp)
1564 END IF
1565 roll_tol = -roll_tol_thrs
1566
1567 rr: DO WHILE (abs(roll_tol) >= roll_tol_thrs) ! RATTLE-ROLL LOOP
1568 roll_tol = 0.0_dp
1569 IF (simpar%constraint) CALL rattle_roll_setup(old, gci, atomic_kind_set, &
1570 particle_set, local_particles, molecule_kind_set, molecule_set, &
1571 local_molecules, tmp%vel, dt, cell, npt, simpar, virial, vector_v, &
1572 roll_tol, iroll, infree, first, para_env)
1573
1574 CALL update_pv(gci, simpar, atomic_kind_set, tmp%vel, particle_set, &
1575 local_molecules, molecule_set, molecule_kind_set, &
1576 local_particles, kin, pv_kin, virial, para_env)
1577 CALL update_veps(cell, npt, simpar, pv_kin, kin, virial, infree)
1578 END DO rr
1579
1580 ! Apply Thermostat over the full set of particles
1581 IF (simpar%ensemble /= npe_i_ensemble) THEN
1582 IF (shell_adiabatic) THEN
1583 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
1584 particle_set, local_molecules, local_particles, para_env, shell_adiabatic=shell_adiabatic, &
1585 vel=tmp%vel, shell_vel=tmp%shell_vel, core_vel=tmp%core_vel)
1586 ELSE
1587 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
1588 particle_set, local_molecules, local_particles, para_env, vel=tmp%vel)
1589 END IF
1590 END IF
1591
1592 ! Apply Thermostat over the core-shell motion
1593 IF (ASSOCIATED(thermostat_shell)) THEN
1594 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
1595 local_particles, para_env, vel=tmp%vel, shell_vel=tmp%shell_vel, &
1596 core_vel=tmp%core_vel)
1597 END IF
1598
1599 ! Apply Thermostat to Barostat
1600 CALL apply_thermostat_baro(thermostat_baro, npt, para_env)
1601
1602 ! Annealing of particle velocities is only possible when no thermostat is active
1603 IF (simpar%ensemble == npe_i_ensemble .AND. simpar%annealing) THEN
1604 tmp%vel(:, :) = tmp%vel(:, :)*simpar%f_annealing
1605 IF (shell_adiabatic) THEN
1606 CALL shell_scale_comv(atomic_kind_set, local_particles, particle_set, &
1607 tmp%vel, tmp%shell_vel, tmp%core_vel)
1608 END IF
1609 END IF
1610 ! Annealing of CELL velocities is only possible when no thermostat is active
1611 IF (simpar%ensemble == npe_i_ensemble .AND. simpar%annealing_cell) THEN
1612 npt(1, 1)%v = npt(1, 1)%v*simpar%f_annealing_cell
1613 END IF
1614
1615 ! Broadcast the new particle velocities and deallocate temporary
1616 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
1617 core_particle_set, para_env, shell_adiabatic, vel=.true.)
1618
1619 ! Update constraint virial
1620 IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, &
1621 molecule_set, molecule_kind_set, particle_set, virial, para_env)
1622
1623 CALL virial_evaluate(atomic_kind_set, particle_set, &
1624 local_particles, virial, para_env)
1625
1626 ! Deallocate old variables
1627 CALL deallocate_old(old)
1628
1629 IF (ASSOCIATED(force_env%meta_env)) THEN
1630 IF (force_env%meta_env%langevin) THEN
1631 DEALLOCATE (rand)
1632 END IF
1633 END IF
1634
1635 IF (first_time) THEN
1636 first_time = .false.
1637 CALL set_md_env(md_env, first_time=first_time)
1638 END IF
1639
1640 END SUBROUTINE npt_i
1641
1642! **************************************************************************************************
1643!> \brief uses coordinates in a file and generates frame after frame of these
1644!> \param md_env ...
1645!> \par History
1646!> - 04.2005 created [Joost VandeVondele]
1647!> - modified to make it more general [MI]
1648!> \note
1649!> it can be used to compute some properties on already available trajectories
1650! **************************************************************************************************
1651 SUBROUTINE reftraj(md_env)
1652 TYPE(md_environment_type), POINTER :: md_env
1653
1654 CHARACTER(LEN=2) :: element_kind_ref0, element_symbol, &
1655 element_symbol_ref0
1656 CHARACTER(LEN=max_line_length) :: errmsg
1657 INTEGER :: cell_itimes, i, nparticle, nread, &
1658 trj_itimes
1659 INTEGER, POINTER :: itimes
1660 LOGICAL :: init, my_end, traj_has_cell_info
1661 REAL(kind=dp) :: cell_time, h(3, 3), trj_epot, trj_time, &
1662 vol
1663 REAL(kind=dp), POINTER :: time
1664 TYPE(cell_type), POINTER :: cell
1665 TYPE(cp_logger_type), POINTER :: logger
1666 TYPE(cp_subsys_type), POINTER :: subsys
1667 TYPE(force_env_type), POINTER :: force_env
1668 TYPE(mp_para_env_type), POINTER :: para_env
1669 TYPE(particle_list_type), POINTER :: particles
1670 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
1671 TYPE(reftraj_type), POINTER :: reftraj_env
1672 TYPE(simpar_type), POINTER :: simpar
1673
1674 NULLIFY (reftraj_env, particle_set, particles, force_env, subsys, simpar, para_env, cell, logger, itimes, time)
1675 CALL get_md_env(md_env=md_env, init=init, reftraj=reftraj_env, force_env=force_env, &
1676 para_env=para_env, simpar=simpar)
1677 logger => cp_get_default_logger()
1678
1679 CALL force_env_get(force_env=force_env, cell=cell, subsys=subsys)
1680 reftraj_env%isnap = reftraj_env%isnap + reftraj_env%info%stride
1681
1682 ! Do some checks on coordinates and box
1683 CALL apply_qmmm_walls_reflective(force_env)
1684 CALL cp_subsys_get(subsys=subsys, particles=particles)
1685 nparticle = particles%n_els
1686 particle_set => particles%els
1687
1688 ! SnapShots read from an external file (parsers calls are buffered! please
1689 ! don't put any additional MPI call!) [tlaino]
1690 CALL parser_read_line(reftraj_env%info%traj_parser, 1)
1691 READ (reftraj_env%info%traj_parser%input_line, fmt="(I8)") nread
1692 CALL parser_read_line(reftraj_env%info%traj_parser, 1)
1693 ! Use the same parser for FORCE_EVAL/SUBSYS/CELL which allows for extxyz
1694 ! Escape values for undetected cases is HUGE(0)
1695 CALL read_xyz_comment(reftraj_env%info%traj_parser%input_line, cell, &
1696 traj_has_cell_info, trj_itimes, trj_time, trj_epot)
1697 IF (trj_itimes == huge(0)) THEN
1698 CALL get_md_env(md_env, itimes=itimes)
1699 trj_itimes = itimes
1700 END IF
1701 IF (trj_time == huge(0.0_dp)) trj_time = 0.0_dp
1702 IF (trj_epot == huge(0.0_dp)) trj_epot = 0.0_dp
1703
1704 ! The following parser for XYZ comment line with strict field widths from
1705 ! the dumpdcd format is preserved for historical reference only
1706 ! --------------------
1707 ! LOGICAL :: test_ok
1708 ! REAL(KIND=dp), DIMENSION(3) :: abc, albega
1709 ! abc(:) = 0.0_dp
1710 ! albega(:) = 0.0_dp
1711 ! test_ok = .FALSE.
1712 ! IF (INDEX(reftraj_env%info%traj_parser%input_line, ", a = ") > 60) THEN
1713 ! traj_has_cell_info = .TRUE.
1714 ! READ (reftraj_env%info%traj_parser%input_line, &
1715 ! FMT="(T6,I8,T23,F12.3,T41,F20.10,T67,F14.6,T87,F14.6,T107,F14.6,T131,F8.3,T149,F8.3,T167,F8.3)", &
1716 ! ERR=999) trj_itimes, trj_time, trj_epot, abc(1:3), albega(1:3)
1717 ! ! Convert cell parameters from angstrom and degree to the internal CP2K units
1718 ! DO i = 1, 3
1719 ! abc(i) = cp_unit_to_cp2k(abc(i), "angstrom")
1720 ! albega(i) = cp_unit_to_cp2k(albega(i), "deg")
1721 ! END DO
1722 ! ELSE
1723 ! traj_has_cell_info = .FALSE.
1724 ! READ (reftraj_env%info%traj_parser%input_line, FMT="(T6,I8,T23,F12.3,T41,F20.10)", ERR=999) &
1725 ! trj_itimes, trj_time, trj_epot
1726 ! END IF
1727 ! test_ok = .TRUE.
1728 ! 999 IF (.NOT. test_ok) THEN
1729 ! ! Handling properly the error when reading the title of an XYZ
1730 ! CALL get_md_env(md_env, itimes=itimes)
1731 ! trj_itimes = itimes
1732 ! trj_time = 0.0_dp
1733 ! trj_epot = 0.0_dp
1734 ! END IF
1735 ! --------------------
1736
1737 ! Delayed print of error message until the step number is known
1738 IF (nread /= nparticle) THEN
1739 errmsg = "Number of atoms for step "//trim(adjustl(cp_to_string(trj_itimes)))// &
1740 " in the trajectory file does not match the reference configuration: "// &
1741 trim(adjustl(cp_to_string(nread)))//" != "//trim(adjustl(cp_to_string(nparticle)))
1742 cpabort(errmsg)
1743 END IF
1744 DO i = 1, nread - 1
1745 CALL parser_read_line(reftraj_env%info%traj_parser, 1)
1746 READ (unit=reftraj_env%info%traj_parser%input_line(1:len_trim(reftraj_env%info%traj_parser%input_line)), fmt=*) &
1747 element_symbol, particle_set(i)%r
1748 CALL uppercase(element_symbol)
1749 element_symbol_ref0 = particle_set(i)%atomic_kind%element_symbol
1750 element_kind_ref0 = particle_set(i)%atomic_kind%name(1:2)
1751 CALL uppercase(element_symbol_ref0)
1752 CALL uppercase(element_kind_ref0)
1753 IF (element_symbol /= element_symbol_ref0) THEN
1754 ! Make sure the label also does not match a potential kind alias.
1755 IF (element_symbol /= element_kind_ref0) THEN
1756 errmsg = "Atomic configuration from trajectory file does not match the reference configuration: "// &
1757 "Check atom "//trim(adjustl(cp_to_string(i)))//" of step "// &
1758 trim(adjustl(cp_to_string(trj_itimes)))//". Found trajectory label '"// &
1759 trim(element_symbol)//"', expected element '"//trim(element_symbol_ref0)// &
1760 "' or kind label '"//trim(element_kind_ref0)// &
1761 "'. REFTRAJ trajectories usually contain element labels; check whether the "// &
1762 "trajectory was modified to contain kind aliases instead."
1763 cpabort(errmsg)
1764 END IF
1765 END IF
1766 particle_set(i)%r(1) = cp_unit_to_cp2k(particle_set(i)%r(1), "angstrom")
1767 particle_set(i)%r(2) = cp_unit_to_cp2k(particle_set(i)%r(2), "angstrom")
1768 particle_set(i)%r(3) = cp_unit_to_cp2k(particle_set(i)%r(3), "angstrom")
1769 END DO
1770 ! End of file is properly addressed in the previous call..
1771 ! Let's check directly (providing some info) also for the last
1772 ! line of this frame..
1773 CALL parser_read_line(reftraj_env%info%traj_parser, 1, at_end=my_end)
1774 READ (unit=reftraj_env%info%traj_parser%input_line, fmt=*) element_symbol, particle_set(i)%r
1775 CALL uppercase(element_symbol)
1776 element_symbol_ref0 = particle_set(i)%atomic_kind%element_symbol
1777 element_kind_ref0 = particle_set(i)%atomic_kind%name(1:2)
1778 CALL uppercase(element_symbol_ref0)
1779 CALL uppercase(element_kind_ref0)
1780 IF (element_symbol /= element_symbol_ref0) THEN
1781 ! Make sure the label also does not match a potential kind alias.
1782 IF (element_symbol /= element_kind_ref0) THEN
1783 errmsg = "Atomic configuration from trajectory file does not match the reference configuration: "// &
1784 "Check atom "//trim(adjustl(cp_to_string(i)))//" of step "// &
1785 trim(adjustl(cp_to_string(trj_itimes)))//". Found trajectory label '"// &
1786 trim(element_symbol)//"', expected element '"//trim(element_symbol_ref0)// &
1787 "' or kind label '"//trim(element_kind_ref0)// &
1788 "'. REFTRAJ trajectories usually contain element labels; check whether the "// &
1789 "trajectory was modified to contain kind aliases instead."
1790 cpabort(errmsg)
1791 END IF
1792 END IF
1793 particle_set(i)%r(1) = cp_unit_to_cp2k(particle_set(i)%r(1), "angstrom")
1794 particle_set(i)%r(2) = cp_unit_to_cp2k(particle_set(i)%r(2), "angstrom")
1795 particle_set(i)%r(3) = cp_unit_to_cp2k(particle_set(i)%r(3), "angstrom")
1796
1797 ! Check if we reached the end of the file and provide some info..
1798 IF (my_end) THEN
1799 IF (reftraj_env%isnap /= (simpar%nsteps - 1)) THEN
1800 CALL cp_abort(__location__, &
1801 "Reached the end of the Trajectory frames in the TRAJECTORY file. Number of "// &
1802 "missing frames ("//cp_to_string((simpar%nsteps - 1) - reftraj_env%isnap)//").")
1803 END IF
1804 END IF
1805
1806 ! Read cell parameters from cell file if requested and if not yet available
1807 IF (reftraj_env%info%variable_volume .AND. (.NOT. traj_has_cell_info)) THEN
1808 CALL parser_get_next_line(reftraj_env%info%cell_parser, 1, at_end=my_end)
1809 CALL parse_cell_line(reftraj_env%info%cell_parser%input_line, cell_itimes, cell_time, h, vol)
1810 cpassert(trj_itimes == cell_itimes)
1811 ! Check if we reached the end of the file and provide some info..
1812 IF (my_end) THEN
1813 IF (reftraj_env%isnap /= (simpar%nsteps - 1)) THEN
1814 CALL cp_abort(__location__, &
1815 "Reached the end of the cell info frames in the CELL file. Number of "// &
1816 "missing frames ("//cp_to_string((simpar%nsteps - 1) - reftraj_env%isnap)//").")
1817 END IF
1818 END IF
1819 END IF
1820
1821 IF (init) THEN
1822 reftraj_env%time0 = trj_time
1823 reftraj_env%epot0 = trj_epot
1824 reftraj_env%itimes0 = trj_itimes
1825 END IF
1826
1827 IF (trj_itimes /= 0.0_dp .AND. trj_time /= 0.0_dp) simpar%dt = (trj_time/femtoseconds)/real(trj_itimes, kind=dp)
1828
1829 reftraj_env%epot = trj_epot
1830 reftraj_env%itimes = trj_itimes
1831 reftraj_env%time = trj_time/femtoseconds
1832 CALL get_md_env(md_env, itimes=itimes, t=time)
1833 itimes = reftraj_env%itimes
1834 time = reftraj_env%time
1835 CALL cp_iterate(logger%iter_info, &
1836 last=logger%iter_info%last_iter(logger%iter_info%n_rlevel), &
1837 iter_nr=reftraj_env%itimes)
1838
1839 IF (traj_has_cell_info) THEN
1840 CALL init_cell(cell)
1841 ELSE IF (reftraj_env%info%variable_volume) THEN
1842 cell%hmat = h
1843 CALL init_cell(cell)
1844 END IF
1845
1846 ! Wrap coordinates if requested
1847 SELECT CASE (reftraj_env%info%wrap)
1848 CASE (reftraj_wrap_none)
1849 ! Do Nothing
1850 CASE (reftraj_wrap_positive)
1851 ! Wrap to positive range
1852 DO i = 1, nparticle
1853 particle_set(i)%r(1:3) = pbc(particle_set(i)%r(1:3), cell, positive_range=.true.)
1854 END DO
1855 CASE (reftraj_wrap_central)
1856 ! Wrap to halfway, i.e. origin is at the center
1857 DO i = 1, nparticle
1858 particle_set(i)%r(1:3) = pbc(particle_set(i)%r(1:3), cell)
1859 END DO
1860 CASE DEFAULT
1861 ! Should not reach here
1862 cpabort("Option invalid or unavailable for reftraj_env%info%wrap")
1863 END SELECT
1864
1865 ![ADAPT] update input structure with new coordinates, make new labels
1866 CALL qmmmx_update_force_env(force_env, force_env%root_section)
1867 ! no pointers into force_env%subsys to update
1868
1869 ! Task to perform on the reference trajectory
1870 ! Compute energy and forces
1871 ![NB] let reftraj work with force mixing which does not have consistent energies and forces
1872 CALL force_env_calc_energy_force(force_env, &
1873 calc_force=(reftraj_env%info%eval == reftraj_eval_energy_forces), &
1874 eval_energy_forces=(reftraj_env%info%eval /= reftraj_eval_none), &
1875 require_consistent_energy_force=.false.)
1876
1877 ! Metadynamics
1878 CALL metadyn_integrator(force_env, trj_itimes)
1879
1880 ! Compute MSD with respect to a reference configuration
1881 IF (reftraj_env%info%msd) THEN
1882 CALL compute_msd_reftraj(reftraj_env, md_env, particle_set)
1883 END IF
1884
1885 ! Skip according the stride both Trajectory and Cell (if possible)
1886 CALL parser_get_next_line(reftraj_env%info%traj_parser, (reftraj_env%info%stride - 1)*(nparticle + 2))
1887 IF (reftraj_env%info%variable_volume) THEN
1888 CALL parser_get_next_line(reftraj_env%info%cell_parser, (reftraj_env%info%stride - 1))
1889 END IF
1890 END SUBROUTINE reftraj
1891
1892! **************************************************************************************************
1893!> \brief nph_uniaxial integrator (non-Hamiltonian version)
1894!> for particle positions & momenta undergoing
1895!> uniaxial stress ( in x-direction of orthorhombic cell)
1896!> due to a shock compression:
1897!> Reed et. al. Physical Review Letters 90, 235503 (2003).
1898!> \param md_env ...
1899!> \par History
1900!> none
1901!> \author CJM
1902! **************************************************************************************************
1903 SUBROUTINE nph_uniaxial(md_env)
1904
1905 TYPE(md_environment_type), POINTER :: md_env
1906
1907 REAL(dp), PARAMETER :: e2 = 1._dp/6._dp, e4 = e2/20._dp, &
1908 e6 = e4/42._dp, e8 = e6/72._dp
1909
1910 INTEGER :: iroll, nparticle, nparticle_kind, nshell
1911 INTEGER, POINTER :: itimes
1912 LOGICAL :: first, first_time, shell_adiabatic, &
1913 shell_present
1914 REAL(kind=dp) :: dt, infree, kin, roll_tol, roll_tol_thrs
1915 REAL(kind=dp), DIMENSION(3) :: vector_r, vector_v
1916 REAL(kind=dp), DIMENSION(3, 3) :: pv_kin
1917 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
1918 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
1919 TYPE(cell_type), POINTER :: cell
1920 TYPE(cp_subsys_type), POINTER :: subsys
1921 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
1922 TYPE(force_env_type), POINTER :: force_env
1923 TYPE(global_constraint_type), POINTER :: gci
1924 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
1925 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
1926 TYPE(molecule_list_type), POINTER :: molecules
1927 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
1928 TYPE(mp_para_env_type), POINTER :: para_env
1929 TYPE(npt_info_type), POINTER :: npt(:, :)
1930 TYPE(old_variables_type), POINTER :: old
1931 TYPE(particle_list_type), POINTER :: core_particles, particles, &
1932 shell_particles
1933 TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
1934 shell_particle_set
1935 TYPE(simpar_type), POINTER :: simpar
1936 TYPE(tmp_variables_type), POINTER :: tmp
1937 TYPE(virial_type), POINTER :: virial
1938
1939 NULLIFY (gci, force_env)
1940 NULLIFY (atomic_kinds, cell, para_env, subsys, local_molecules, local_particles)
1941 NULLIFY (molecule_kinds, molecules, molecule_kind_set, npt)
1942 NULLIFY (core_particles, particles, shell_particles, tmp, old)
1943 NULLIFY (core_particle_set, particle_set, shell_particle_set)
1944 NULLIFY (simpar, virial, itimes)
1945
1946 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, npt=npt, &
1947 first_time=first_time, para_env=para_env, itimes=itimes)
1948 dt = simpar%dt
1949 infree = 1.0_dp/real(simpar%nfree, dp)
1950
1951 CALL force_env_get(force_env, subsys=subsys, cell=cell)
1952
1953 ! Do some checks on coordinates and box
1954 CALL apply_qmmm_walls_reflective(force_env)
1955
1956 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
1957 particles=particles, local_molecules=local_molecules, molecules=molecules, gci=gci, &
1958 molecule_kinds=molecule_kinds, virial=virial)
1959
1960 nparticle_kind = atomic_kinds%n_els
1961 atomic_kind_set => atomic_kinds%els
1962 molecule_kind_set => molecule_kinds%els
1963
1964 nparticle = particles%n_els
1965 particle_set => particles%els
1966 molecule_set => molecules%els
1967
1968 IF (first_time) THEN
1969 CALL virial_evaluate(atomic_kind_set, particle_set, &
1970 local_particles, virial, para_env)
1971 END IF
1972
1973 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
1974 shell_present=shell_present, shell_adiabatic=shell_adiabatic)
1975
1976 ! Allocate work storage for positions and velocities
1977 CALL allocate_old(old, particle_set, npt)
1978
1979 IF (shell_present) THEN
1980 CALL cp_subsys_get(subsys=subsys, &
1981 shell_particles=shell_particles, core_particles=core_particles)
1982 shell_particle_set => shell_particles%els
1983 nshell = SIZE(shell_particles%els)
1984 IF (shell_adiabatic) THEN
1985 core_particle_set => core_particles%els
1986 END IF
1987 END IF
1988
1989 CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
1990
1991 IF (simpar%constraint) THEN
1992 ! Possibly update the target values
1993 CALL shake_update_targets(gci, local_molecules, molecule_set, &
1994 molecule_kind_set, dt, force_env%root_section)
1995 END IF
1996
1997 ! setting up for ROLL: saving old variables
1998 IF (simpar%constraint) THEN
1999 roll_tol_thrs = simpar%roll_tol
2000 iroll = 1
2001 CALL set(old, atomic_kind_set, particle_set, local_particles, cell, npt, 'F')
2002 CALL getold(gci, local_molecules, molecule_set, &
2003 molecule_kind_set, particle_set, cell)
2004 ELSE
2005 roll_tol_thrs = epsilon(0.0_dp)
2006 END IF
2007 roll_tol = -roll_tol_thrs
2008
2009 sr: DO WHILE (abs(roll_tol) >= roll_tol_thrs) ! SHAKE-ROLL LOOP
2010
2011 IF (simpar%constraint) THEN
2012 CALL set(old, atomic_kind_set, particle_set, local_particles, cell, npt, 'B')
2013 END IF
2014 CALL update_pv(gci, simpar, atomic_kind_set, particle_set, &
2015 local_molecules, molecule_set, molecule_kind_set, &
2016 local_particles, kin, pv_kin, virial, para_env)
2017 CALL update_veps(cell, npt, simpar, pv_kin, kin, virial, infree)
2018
2019 tmp%arg_r(1) = (0.5_dp*npt(1, 1)%v*dt)* &
2020 (0.5_dp*npt(1, 1)%v*dt)
2021 tmp%poly_r(1) = 1._dp + e2*tmp%arg_r(1) + e4*tmp%arg_r(1)*tmp%arg_r(1) + &
2022 e6*tmp%arg_r(1)**3 + e8*tmp%arg_r(1)**4
2023 tmp%poly_r(2) = 1.0_dp
2024 tmp%poly_r(3) = 1.0_dp
2025
2026 tmp%arg_v(1) = (0.25_dp*npt(1, 1)%v*dt* &
2027 (1._dp + infree))*(0.25_dp*npt(1, 1)%v* &
2028 dt*(1._dp + infree))
2029 tmp%arg_v(2) = (0.25_dp*npt(1, 1)%v*dt*infree)* &
2030 (0.25_dp*npt(1, 1)%v*dt*infree)
2031 tmp%poly_v(1) = 1._dp + e2*tmp%arg_v(1) + e4*tmp%arg_v(1)*tmp%arg_v(1) + &
2032 e6*tmp%arg_v(1)**3 + e8*tmp%arg_v(1)**4
2033 tmp%poly_v(2) = 1._dp + e2*tmp%arg_v(2) + e4*tmp%arg_v(2)*tmp%arg_v(2) + &
2034 e6*tmp%arg_v(2)**3 + e8*tmp%arg_v(2)**4
2035 tmp%poly_v(3) = 1._dp + e2*tmp%arg_v(2) + e4*tmp%arg_v(2)*tmp%arg_v(2) + &
2036 e6*tmp%arg_v(2)**3 + e8*tmp%arg_v(2)**4
2037
2038 tmp%scale_r(1) = exp(0.5_dp*dt*npt(1, 1)%v)
2039 tmp%scale_r(2) = 1.0_dp
2040 tmp%scale_r(3) = 1.0_dp
2041
2042 tmp%scale_v(1) = exp(-0.25_dp*dt*npt(1, 1)%v* &
2043 (1._dp + infree))
2044 tmp%scale_v(2) = exp(-0.25_dp*dt*npt(1, 1)%v*infree)
2045 tmp%scale_v(3) = exp(-0.25_dp*dt*npt(1, 1)%v*infree)
2046
2047 ! first half of velocity verlet
2048 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
2049 core_particle_set, shell_particle_set, nparticle_kind, &
2050 shell_adiabatic, dt)
2051
2052 IF (simpar%variable_dt) CALL variable_timestep(md_env, tmp, dt, simpar, para_env, &
2053 atomic_kind_set, local_particles, particle_set, core_particle_set, &
2054 shell_particle_set, nparticle_kind, shell_adiabatic, npt=npt)
2055
2056 roll_tol = 0._dp
2057 vector_r(:) = 0._dp
2058 vector_v(:) = tmp%scale_v(:)*tmp%poly_v(:)
2059 vector_r(1) = tmp%scale_r(1)*tmp%poly_r(1)
2060
2061 IF (simpar%constraint) CALL shake_roll_control(gci, local_molecules, &
2062 molecule_set, molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, simpar, &
2063 roll_tol, iroll, vector_r, vector_v, para_env, cell=cell, &
2064 local_particles=local_particles)
2065 END DO sr
2066
2067 ! Update h_mat
2068 cell%hmat(1, 1) = cell%hmat(1, 1)*tmp%scale_r(1)*tmp%scale_r(1)
2069
2070 ! Update the cell
2071 CALL init_cell(cell)
2072
2073 ! Broadcast the new particle positions and deallocate the pos component of temporary
2074 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
2075 core_particle_set, para_env, shell_adiabatic, pos=.true.)
2076
2077 ! Update forces (and stress)
2078 CALL force_env_calc_energy_force(force_env)
2079
2080 ! Metadynamics
2081 CALL metadyn_integrator(force_env, itimes, tmp%vel)
2082
2083 ! Velocity Verlet (second part)
2084 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
2085 core_particle_set, shell_particle_set, nparticle_kind, &
2086 shell_adiabatic, dt)
2087
2088 IF (simpar%constraint) THEN
2089 roll_tol_thrs = simpar%roll_tol
2090 first = .true.
2091 iroll = 1
2092 CALL set(old, atomic_kind_set, particle_set, tmp%vel, local_particles, cell, npt, 'F')
2093 ELSE
2094 roll_tol_thrs = epsilon(0.0_dp)
2095 END IF
2096 roll_tol = -roll_tol_thrs
2097
2098 rr: DO WHILE (abs(roll_tol) >= roll_tol_thrs) ! RATTLE-ROLL LOOP
2099 roll_tol = 0._dp
2100 IF (simpar%constraint) CALL rattle_roll_setup(old, gci, atomic_kind_set, &
2101 particle_set, local_particles, molecule_kind_set, molecule_set, &
2102 local_molecules, tmp%vel, dt, cell, npt, simpar, virial, vector_v, &
2103 roll_tol, iroll, infree, first, para_env)
2104
2105 CALL update_pv(gci, simpar, atomic_kind_set, tmp%vel, particle_set, &
2106 local_molecules, molecule_set, molecule_kind_set, &
2107 local_particles, kin, pv_kin, virial, para_env)
2108 CALL update_veps(cell, npt, simpar, pv_kin, kin, virial, infree)
2109 END DO rr
2110
2111 IF (simpar%annealing) tmp%vel(:, :) = tmp%vel(:, :)*simpar%f_annealing
2112
2113 ! Broadcast the new particle velocities and deallocate the temporary
2114 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
2115 core_particle_set, para_env, shell_adiabatic, vel=.true.)
2116
2117 ! Update constraint virial
2118 IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, &
2119 molecule_set, molecule_kind_set, particle_set, virial, para_env)
2120
2121 CALL virial_evaluate(atomic_kind_set, particle_set, &
2122 local_particles, virial, para_env)
2123
2124 ! Deallocate old variables
2125 CALL deallocate_old(old)
2126
2127 IF (first_time) THEN
2128 first_time = .false.
2129 CALL set_md_env(md_env, first_time=first_time)
2130 END IF
2131
2132 END SUBROUTINE nph_uniaxial
2133
2134! **************************************************************************************************
2135!> \brief nph_uniaxial integrator (non-Hamiltonian version)
2136!> for particle positions & momenta undergoing
2137!> uniaxial stress ( in x-direction of orthorhombic cell)
2138!> due to a shock compression:
2139!> Reed et. al. Physical Review Letters 90, 235503 (2003).
2140!> Added damping (e.g. thermostat to barostat)
2141!> \param md_env ...
2142!> \par History
2143!> none
2144!> \author CJM
2145! **************************************************************************************************
2146 SUBROUTINE nph_uniaxial_damped(md_env)
2147
2148 TYPE(md_environment_type), POINTER :: md_env
2149
2150 REAL(dp), PARAMETER :: e2 = 1._dp/6._dp, e4 = e2/20._dp, &
2151 e6 = e4/42._dp, e8 = e6/72._dp
2152
2153 INTEGER :: iroll, nparticle, nparticle_kind, nshell
2154 INTEGER, POINTER :: itimes
2155 LOGICAL :: first, first_time, shell_adiabatic, &
2156 shell_present
2157 REAL(kind=dp) :: aa, aax, dt, gamma1, infree, kin, &
2158 roll_tol, roll_tol_thrs
2159 REAL(kind=dp), DIMENSION(3) :: vector_r, vector_v
2160 REAL(kind=dp), DIMENSION(3, 3) :: pv_kin
2161 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
2162 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2163 TYPE(cell_type), POINTER :: cell
2164 TYPE(cp_subsys_type), POINTER :: subsys
2165 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
2166 TYPE(force_env_type), POINTER :: force_env
2167 TYPE(global_constraint_type), POINTER :: gci
2168 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
2169 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
2170 TYPE(molecule_list_type), POINTER :: molecules
2171 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
2172 TYPE(mp_para_env_type), POINTER :: para_env
2173 TYPE(npt_info_type), POINTER :: npt(:, :)
2174 TYPE(old_variables_type), POINTER :: old
2175 TYPE(particle_list_type), POINTER :: core_particles, particles, &
2176 shell_particles
2177 TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
2178 shell_particle_set
2179 TYPE(simpar_type), POINTER :: simpar
2180 TYPE(tmp_variables_type), POINTER :: tmp
2181 TYPE(virial_type), POINTER :: virial
2182
2183 NULLIFY (gci, force_env)
2184 NULLIFY (atomic_kinds, cell, para_env, subsys, local_molecules, local_particles)
2185 NULLIFY (molecule_kinds, molecules, molecule_kind_set, npt)
2186 NULLIFY (core_particles, particles, shell_particles, tmp, old)
2187 NULLIFY (core_particle_set, particle_set, shell_particle_set)
2188 NULLIFY (simpar, virial, itimes)
2189
2190 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, npt=npt, &
2191 first_time=first_time, para_env=para_env, itimes=itimes)
2192 dt = simpar%dt
2193 infree = 1.0_dp/real(simpar%nfree, dp)
2194 gamma1 = simpar%gamma_nph
2195
2196 CALL force_env_get(force_env, subsys=subsys, cell=cell)
2197
2198 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
2199 particles=particles, local_molecules=local_molecules, molecules=molecules, gci=gci, &
2200 molecule_kinds=molecule_kinds, virial=virial)
2201
2202 nparticle_kind = atomic_kinds%n_els
2203 atomic_kind_set => atomic_kinds%els
2204 molecule_kind_set => molecule_kinds%els
2205
2206 nparticle = particles%n_els
2207 particle_set => particles%els
2208 molecule_set => molecules%els
2209
2210 IF (first_time) THEN
2211 CALL virial_evaluate(atomic_kind_set, particle_set, &
2212 local_particles, virial, para_env)
2213 END IF
2214
2215 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
2216 shell_present=shell_present, shell_adiabatic=shell_adiabatic)
2217
2218 ! Allocate work storage for positions and velocities
2219 CALL allocate_old(old, particle_set, npt)
2220
2221 IF (shell_present) THEN
2222 CALL cp_subsys_get(subsys=subsys, &
2223 shell_particles=shell_particles, core_particles=core_particles)
2224 shell_particle_set => shell_particles%els
2225 nshell = SIZE(shell_particles%els)
2226 IF (shell_adiabatic) THEN
2227 core_particle_set => core_particles%els
2228 END IF
2229 END IF
2230
2231 CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
2232
2233 ! perform damping on velocities
2234 CALL damp_v(molecule_kind_set, molecule_set, particle_set, local_molecules, &
2235 gamma1, npt(1, 1), dt, para_env)
2236
2237 IF (simpar%constraint) THEN
2238 ! Possibly update the target values
2239 CALL shake_update_targets(gci, local_molecules, molecule_set, &
2240 molecule_kind_set, dt, force_env%root_section)
2241 END IF
2242
2243 ! setting up for ROLL: saving old variables
2244 IF (simpar%constraint) THEN
2245 roll_tol_thrs = simpar%roll_tol
2246 iroll = 1
2247 CALL set(old, atomic_kind_set, particle_set, local_particles, cell, npt, 'F')
2248 CALL getold(gci, local_molecules, molecule_set, &
2249 molecule_kind_set, particle_set, cell)
2250 ELSE
2251 roll_tol_thrs = epsilon(0.0_dp)
2252 END IF
2253 roll_tol = -roll_tol_thrs
2254
2255 sr: DO WHILE (abs(roll_tol) >= roll_tol_thrs) ! SHAKE-ROLL LOOP
2256
2257 ! perform damping on the barostat momentum
2258 CALL damp_veps(npt(1, 1), gamma1, dt)
2259
2260 IF (simpar%constraint) THEN
2261 CALL set(old, atomic_kind_set, particle_set, local_particles, cell, npt, 'B')
2262 END IF
2263 CALL update_pv(gci, simpar, atomic_kind_set, particle_set, &
2264 local_molecules, molecule_set, molecule_kind_set, &
2265 local_particles, kin, pv_kin, virial, para_env)
2266 CALL update_veps(cell, npt, simpar, pv_kin, kin, virial, infree)
2267
2268 ! perform damping on the barostat momentum
2269 CALL damp_veps(npt(1, 1), gamma1, dt)
2270
2271 tmp%arg_r(1) = (0.5_dp*npt(1, 1)%v*dt)* &
2272 (0.5_dp*npt(1, 1)%v*dt)
2273 tmp%poly_r(1) = 1._dp + e2*tmp%arg_r(1) + e4*tmp%arg_r(1)*tmp%arg_r(1) + &
2274 e6*tmp%arg_r(1)**3 + e8*tmp%arg_r(1)**4
2275
2276 aax = npt(1, 1)%v*(1.0_dp + infree)
2277 tmp%arg_v(1) = (0.25_dp*dt*aax)*(0.25_dp*dt*aax)
2278 tmp%poly_v(1) = 1._dp + e2*tmp%arg_v(1) + e4*tmp%arg_v(1)*tmp%arg_v(1) + &
2279 e6*tmp%arg_v(1)**3 + e8*tmp%arg_v(1)**4
2280
2281 aa = npt(1, 1)%v*infree
2282 tmp%arg_v(2) = (0.25_dp*dt*aa)*(0.25_dp*dt*aa)
2283 tmp%poly_v(2) = 1._dp + e2*tmp%arg_v(2) + e4*tmp%arg_v(2)*tmp%arg_v(2) + &
2284 e6*tmp%arg_v(2)**3 + e8*tmp%arg_v(2)**4
2285 tmp%poly_v(3) = 1._dp + e2*tmp%arg_v(2) + e4*tmp%arg_v(2)*tmp%arg_v(2) + &
2286 e6*tmp%arg_v(2)**3 + e8*tmp%arg_v(2)**4
2287
2288 tmp%scale_r(1) = exp(0.5_dp*dt*npt(1, 1)%v)
2289 tmp%scale_v(1) = exp(-0.25_dp*dt*aax)
2290 tmp%scale_v(2) = exp(-0.25_dp*dt*aa)
2291 tmp%scale_v(3) = exp(-0.25_dp*dt*aa)
2292
2293 ! first half of velocity verlet
2294 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
2295 core_particle_set, shell_particle_set, nparticle_kind, &
2296 shell_adiabatic, dt)
2297
2298 IF (simpar%variable_dt) CALL variable_timestep(md_env, tmp, dt, simpar, para_env, &
2299 atomic_kind_set, local_particles, particle_set, core_particle_set, &
2300 shell_particle_set, nparticle_kind, shell_adiabatic, npt=npt)
2301
2302 roll_tol = 0._dp
2303 vector_r(:) = 0._dp
2304 vector_v(:) = tmp%scale_v(:)*tmp%poly_v(:)
2305 vector_r(1) = tmp%scale_r(1)*tmp%poly_r(1)
2306
2307 IF (simpar%constraint) CALL shake_roll_control(gci, local_molecules, &
2308 molecule_set, molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, simpar, &
2309 roll_tol, iroll, vector_r, vector_v, para_env, cell=cell, &
2310 local_particles=local_particles)
2311 END DO sr
2312
2313 ! Update h_mat
2314 cell%hmat(1, 1) = cell%hmat(1, 1)*tmp%scale_r(1)*tmp%scale_r(1)
2315
2316 ! Update the inverse
2317 CALL init_cell(cell)
2318
2319 ! Broadcast the new particle positions and deallocate the pos components of temporary
2320 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
2321 core_particle_set, para_env, shell_adiabatic, pos=.true.)
2322
2323 ! Update forces
2324 CALL force_env_calc_energy_force(force_env)
2325
2326 ! Metadynamics
2327 CALL metadyn_integrator(force_env, itimes, tmp%vel)
2328
2329 ! Velocity Verlet (second part)
2330 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
2331 core_particle_set, shell_particle_set, nparticle_kind, &
2332 shell_adiabatic, dt)
2333
2334 IF (simpar%constraint) THEN
2335 roll_tol_thrs = simpar%roll_tol
2336 first = .true.
2337 iroll = 1
2338 CALL set(old, atomic_kind_set, particle_set, tmp%vel, local_particles, cell, npt, 'F')
2339 ELSE
2340 roll_tol_thrs = epsilon(0.0_dp)
2341 END IF
2342 roll_tol = -roll_tol_thrs
2343
2344 rr: DO WHILE (abs(roll_tol) >= roll_tol_thrs) ! RATTLE-ROLL LOOP
2345 roll_tol = 0._dp
2346 IF (simpar%constraint) CALL rattle_roll_setup(old, gci, atomic_kind_set, &
2347 particle_set, local_particles, molecule_kind_set, molecule_set, local_molecules, &
2348 tmp%vel, dt, cell, npt, simpar, virial, vector_v, roll_tol, iroll, infree, first, &
2349 para_env)
2350 ! perform damping on the barostat momentum
2351 CALL damp_veps(npt(1, 1), gamma1, dt)
2352
2353 CALL update_pv(gci, simpar, atomic_kind_set, tmp%vel, particle_set, &
2354 local_molecules, molecule_set, molecule_kind_set, &
2355 local_particles, kin, pv_kin, virial, para_env)
2356 CALL update_veps(cell, npt, simpar, pv_kin, kin, virial, infree)
2357
2358 ! perform damping on the barostat momentum
2359 CALL damp_veps(npt(1, 1), gamma1, dt)
2360
2361 END DO rr
2362
2363 ! perform damping on velocities
2364 CALL damp_v(molecule_kind_set, molecule_set, particle_set, local_molecules, &
2365 tmp%vel, gamma1, npt(1, 1), dt, para_env)
2366
2367 IF (simpar%annealing) tmp%vel(:, :) = tmp%vel(:, :)*simpar%f_annealing
2368
2369 ! Broadcast the new particle velocities and deallocate temporary
2370 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
2371 core_particle_set, para_env, shell_adiabatic, vel=.true.)
2372
2373 ! Update constraint virial
2374 IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, &
2375 molecule_set, molecule_kind_set, particle_set, virial, para_env)
2376
2377 CALL virial_evaluate(atomic_kind_set, particle_set, &
2378 local_particles, virial, para_env)
2379
2380 ! Deallocate old variables
2381 CALL deallocate_old(old)
2382
2383 IF (first_time) THEN
2384 first_time = .false.
2385 CALL set_md_env(md_env, first_time=first_time)
2386 END IF
2387
2388 END SUBROUTINE nph_uniaxial_damped
2389
2390! **************************************************************************************************
2391!> \brief Velocity Verlet integrator for the NPT ensemble with fully flexible cell
2392!> \param md_env ...
2393!> \param globenv ...
2394!> \par History
2395!> none
2396!> \author CJM
2397! **************************************************************************************************
2398 SUBROUTINE npt_f(md_env, globenv)
2399
2400 TYPE(md_environment_type), POINTER :: md_env
2401 TYPE(global_environment_type), POINTER :: globenv
2402
2403 REAL(kind=dp), PARAMETER :: e2 = 1.0_dp/6.0_dp, e4 = e2/20.0_dp, &
2404 e6 = e4/42.0_dp, e8 = e6/72.0_dp
2405
2406 INTEGER :: i, iroll, j, nparticle, nparticle_kind, &
2407 nshell
2408 INTEGER, POINTER :: itimes
2409 LOGICAL :: first, first_time, shell_adiabatic, &
2410 shell_check_distance, shell_present
2411 REAL(kind=dp) :: dt, infree, kin, roll_tol, &
2412 roll_tol_thrs, trvg
2413 REAL(kind=dp), DIMENSION(3) :: vector_r, vector_v
2414 REAL(kind=dp), DIMENSION(3, 3) :: pv_kin, uh
2415 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
2416 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2417 TYPE(barostat_type), POINTER :: barostat
2418 TYPE(cell_type), POINTER :: cell
2419 TYPE(cp_subsys_type), POINTER :: subsys
2420 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
2421 TYPE(force_env_type), POINTER :: force_env
2422 TYPE(global_constraint_type), POINTER :: gci
2423 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
2424 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
2425 TYPE(molecule_list_type), POINTER :: molecules
2426 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
2427 TYPE(mp_para_env_type), POINTER :: para_env
2428 TYPE(npt_info_type), POINTER :: npt(:, :)
2429 TYPE(old_variables_type), POINTER :: old
2430 TYPE(particle_list_type), POINTER :: core_particles, particles, &
2431 shell_particles
2432 TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
2433 shell_particle_set
2434 TYPE(simpar_type), POINTER :: simpar
2435 TYPE(thermostat_type), POINTER :: thermostat_baro, thermostat_part, &
2436 thermostat_shell
2437 TYPE(tmp_variables_type), POINTER :: tmp
2438 TYPE(virial_type), POINTER :: virial
2439
2440 NULLIFY (gci, thermostat_baro, thermostat_part, thermostat_shell, force_env)
2441 NULLIFY (atomic_kinds, cell, para_env, subsys, local_molecules, local_particles)
2442 NULLIFY (molecule_kinds, molecules, molecule_kind_set, npt, barostat)
2443 NULLIFY (core_particles, particles, shell_particles, tmp, old)
2444 NULLIFY (core_particle_set, particle_set, shell_particle_set)
2445 NULLIFY (simpar, virial, itimes)
2446
2447 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
2448 thermostat_part=thermostat_part, thermostat_baro=thermostat_baro, &
2449 thermostat_shell=thermostat_shell, npt=npt, first_time=first_time, &
2450 para_env=para_env, barostat=barostat, itimes=itimes)
2451 dt = simpar%dt
2452 infree = 1.0_dp/real(simpar%nfree, kind=dp)
2453
2454 CALL force_env_get(force_env, subsys=subsys, cell=cell)
2455
2456 ! Do some checks on coordinates and box
2457 CALL apply_qmmm_walls_reflective(force_env)
2458
2459 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
2460 particles=particles, local_molecules=local_molecules, molecules=molecules, &
2461 gci=gci, molecule_kinds=molecule_kinds, virial=virial)
2462
2463 nparticle_kind = atomic_kinds%n_els
2464 atomic_kind_set => atomic_kinds%els
2465 molecule_kind_set => molecule_kinds%els
2466
2467 nparticle = particles%n_els
2468 particle_set => particles%els
2469 molecule_set => molecules%els
2470
2471 CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
2472 shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
2473 shell_check_distance=shell_check_distance)
2474
2475 IF (first_time) THEN
2476 CALL virial_evaluate(atomic_kind_set, particle_set, &
2477 local_particles, virial, para_env)
2478 END IF
2479
2480 ! Allocate work storage for positions and velocities
2481 CALL allocate_old(old, particle_set, npt)
2482
2483 IF (shell_present) THEN
2484 CALL cp_subsys_get(subsys=subsys, &
2485 shell_particles=shell_particles, core_particles=core_particles)
2486 shell_particle_set => shell_particles%els
2487 nshell = SIZE(shell_particles%els)
2488 IF (shell_adiabatic) THEN
2489 core_particle_set => core_particles%els
2490 END IF
2491 END IF
2492
2493 CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
2494
2495 ! Apply Thermostat to Barostat
2496 CALL apply_thermostat_baro(thermostat_baro, npt, para_env)
2497
2498 ! Apply Thermostat over the full set of particles
2499 IF (simpar%ensemble /= npe_f_ensemble) THEN
2500 IF (shell_adiabatic) THEN
2501 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
2502 particle_set, local_molecules, local_particles, para_env, shell_adiabatic=shell_adiabatic, &
2503 shell_particle_set=shell_particle_set, core_particle_set=core_particle_set)
2504 ELSE
2505 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
2506 particle_set, local_molecules, local_particles, para_env)
2507 END IF
2508 END IF
2509
2510 ! Apply Thermostat over the core-shell motion
2511 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
2512 local_particles, para_env, shell_particle_set=shell_particle_set, &
2513 core_particle_set=core_particle_set)
2514
2515 IF (simpar%constraint) THEN
2516 ! Possibly update the target values
2517 CALL shake_update_targets(gci, local_molecules, molecule_set, &
2518 molecule_kind_set, dt, force_env%root_section)
2519 END IF
2520
2521 ! setting up for ROLL: saving old variables
2522 IF (simpar%constraint) THEN
2523 roll_tol_thrs = simpar%roll_tol
2524 iroll = 1
2525 CALL set(old, atomic_kind_set, particle_set, local_particles, cell, npt, 'F')
2526 CALL getold(gci, local_molecules, molecule_set, &
2527 molecule_kind_set, particle_set, cell)
2528 ELSE
2529 roll_tol_thrs = epsilon(0.0_dp)
2530 END IF
2531 roll_tol = -roll_tol_thrs
2532
2533 sr: DO WHILE (abs(roll_tol) >= roll_tol_thrs) ! SHAKE-ROLL LOOP
2534
2535 IF (simpar%constraint) THEN
2536 CALL set(old, atomic_kind_set, particle_set, local_particles, cell, npt, 'B')
2537 END IF
2538 CALL update_pv(gci, simpar, atomic_kind_set, particle_set, &
2539 local_molecules, molecule_set, molecule_kind_set, &
2540 local_particles, kin, pv_kin, virial, para_env)
2541 CALL update_veps(cell, npt, simpar, pv_kin, kin, virial, infree, &
2542 virial_components=barostat%virial_components)
2543
2544 trvg = npt(1, 1)%v + npt(2, 2)%v + npt(3, 3)%v
2545 !
2546 ! find eigenvalues and eigenvectors of npt ( :, : )%v
2547 !
2548
2549 CALL diagonalise(matrix=npt(:, :)%v, mysize=3, &
2550 uplo="U", eigenvalues=tmp%e_val, eigenvectors=tmp%u)
2551
2552 tmp%arg_r(:) = 0.5_dp*tmp%e_val(:)*dt* &
2553 0.5_dp*tmp%e_val(:)*dt
2554 tmp%poly_r = 1.0_dp + e2*tmp%arg_r + e4*tmp%arg_r*tmp%arg_r + &
2555 e6*tmp%arg_r**3 + e8*tmp%arg_r**4
2556 tmp%scale_r(:) = exp(0.5_dp*dt*tmp%e_val(:))
2557
2558 tmp%arg_v(:) = 0.25_dp*dt*(tmp%e_val(:) + trvg*infree)* &
2559 0.25_dp*dt*(tmp%e_val(:) + trvg*infree)
2560 tmp%poly_v = 1.0_dp + e2*tmp%arg_v + e4*tmp%arg_v*tmp%arg_v + &
2561 e6*tmp%arg_v**3 + e8*tmp%arg_v**4
2562 tmp%scale_v(:) = exp(-0.25_dp*dt*(tmp%e_val(:) + trvg*infree))
2563
2564 CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
2565 core_particle_set, shell_particle_set, nparticle_kind, &
2566 shell_adiabatic, dt, u=tmp%u)
2567
2568 IF (simpar%variable_dt) CALL variable_timestep(md_env, tmp, dt, simpar, para_env, &
2569 atomic_kind_set, local_particles, particle_set, core_particle_set, &
2570 shell_particle_set, nparticle_kind, shell_adiabatic, npt=npt)
2571
2572 roll_tol = 0.0_dp
2573 vector_r = tmp%scale_r*tmp%poly_r
2574 vector_v = tmp%scale_v*tmp%poly_v
2575
2576 IF (simpar%constraint) CALL shake_roll_control(gci, local_molecules, &
2577 molecule_set, molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, &
2578 simpar, roll_tol, iroll, vector_r, vector_v, &
2579 para_env, u=tmp%u, cell=cell, &
2580 local_particles=local_particles)
2581 END DO sr
2582
2583 ! Update h_mat
2584 uh = matmul(transpose(tmp%u), cell%hmat)
2585
2586 DO i = 1, 3
2587 DO j = 1, 3
2588 uh(i, j) = uh(i, j)*tmp%scale_r(i)*tmp%scale_r(i)
2589 END DO
2590 END DO
2591
2592 cell%hmat = matmul(tmp%u, uh)
2593 ! Update the inverse
2594 CALL init_cell(cell)
2595
2596 ! Broadcast the new particle positions and deallocate the pos components of temporary
2597 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
2598 core_particle_set, para_env, shell_adiabatic, pos=.true.)
2599
2600 IF (shell_adiabatic .AND. shell_check_distance) THEN
2601 CALL optimize_shell_core(force_env, particle_set, &
2602 shell_particle_set, core_particle_set, globenv, tmp=tmp, check=.true.)
2603 END IF
2604
2605 ! Update forces
2606 CALL force_env_calc_energy_force(force_env)
2607
2608 ! Metadynamics
2609 CALL metadyn_integrator(force_env, itimes, tmp%vel)
2610
2611 ! Velocity Verlet (second part)
2612 CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
2613 core_particle_set, shell_particle_set, nparticle_kind, &
2614 shell_adiabatic, dt, tmp%u)
2615
2616 IF (simpar%constraint) THEN
2617 roll_tol_thrs = simpar%roll_tol
2618 first = .true.
2619 iroll = 1
2620 CALL set(old, atomic_kind_set, particle_set, tmp%vel, local_particles, cell, npt, 'F')
2621 ELSE
2622 roll_tol_thrs = epsilon(0.0_dp)
2623 END IF
2624 roll_tol = -roll_tol_thrs
2625
2626 rr: DO WHILE (abs(roll_tol) >= roll_tol_thrs) ! RATTLE-ROLL LOOP
2627 roll_tol = 0.0_dp
2628 IF (simpar%constraint) CALL rattle_roll_setup(old, gci, atomic_kind_set, &
2629 particle_set, local_particles, molecule_kind_set, molecule_set, &
2630 local_molecules, tmp%vel, dt, cell, npt, simpar, virial, vector_v, &
2631 roll_tol, iroll, infree, first, para_env, u=tmp%u)
2632
2633 CALL update_pv(gci, simpar, atomic_kind_set, tmp%vel, particle_set, &
2634 local_molecules, molecule_set, molecule_kind_set, &
2635 local_particles, kin, pv_kin, virial, para_env)
2636 CALL update_veps(cell, npt, simpar, pv_kin, kin, virial, infree, &
2637 virial_components=barostat%virial_components)
2638 END DO rr
2639
2640 ! Apply Thermostat over the full set of particles
2641 IF (simpar%ensemble /= npe_f_ensemble) THEN
2642 IF (shell_adiabatic) THEN
2643 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
2644 particle_set, local_molecules, local_particles, para_env, shell_adiabatic=shell_adiabatic, &
2645 vel=tmp%vel, shell_vel=tmp%shell_vel, core_vel=tmp%core_vel)
2646
2647 ELSE
2648 CALL apply_thermostat_particles(thermostat_part, force_env, molecule_kind_set, molecule_set, &
2649 particle_set, local_molecules, local_particles, para_env, vel=tmp%vel)
2650 END IF
2651 END IF
2652
2653 ! Apply Thermostat over the core-shell motion
2654 IF (ASSOCIATED(thermostat_shell)) THEN
2655 CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
2656 local_particles, para_env, vel=tmp%vel, shell_vel=tmp%shell_vel, &
2657 core_vel=tmp%core_vel)
2658 END IF
2659
2660 ! Apply Thermostat to Barostat
2661 CALL apply_thermostat_baro(thermostat_baro, npt, para_env)
2662
2663 ! Annealing of particle velocities is only possible when no thermostat is active
2664 IF (simpar%ensemble == npe_f_ensemble .AND. simpar%annealing) THEN
2665 tmp%vel(:, :) = tmp%vel(:, :)*simpar%f_annealing
2666 IF (shell_adiabatic) THEN
2667 CALL shell_scale_comv(atomic_kind_set, local_particles, particle_set, &
2668 tmp%vel, tmp%shell_vel, tmp%core_vel)
2669 END IF
2670 END IF
2671 ! Annealing of CELL velocities is only possible when no thermostat is active
2672 IF (simpar%ensemble == npe_f_ensemble .AND. simpar%annealing_cell) THEN
2673 npt(:, :)%v = npt(:, :)%v*simpar%f_annealing_cell
2674 END IF
2675
2676 ! Broadcast the new particle velocities and deallocate temporary
2677 CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
2678 core_particle_set, para_env, shell_adiabatic, vel=.true.)
2679
2680 ! Update constraint virial
2681 IF (simpar%constraint) THEN
2682 CALL pv_constraint(gci, local_molecules, molecule_set, &
2683 molecule_kind_set, particle_set, virial, para_env)
2684 END IF
2685
2686 CALL virial_evaluate(atomic_kind_set, particle_set, &
2687 local_particles, virial, para_env)
2688
2689 ! Deallocate old variables
2690 CALL deallocate_old(old)
2691
2692 IF (first_time) THEN
2693 first_time = .false.
2694 CALL set_md_env(md_env, first_time=first_time)
2695 END IF
2696
2697 END SUBROUTINE npt_f
2698
2699! **************************************************************************************************
2700!> \brief RESPA integrator for nve ensemble for particle positions & momenta
2701!> \param md_env ...
2702!> \author FS
2703! **************************************************************************************************
2704 SUBROUTINE nve_respa(md_env)
2705
2706 TYPE(md_environment_type), POINTER :: md_env
2707
2708 INTEGER :: i_step, iparticle, iparticle_kind, &
2709 iparticle_local, n_time_steps, &
2710 nparticle, nparticle_kind, &
2711 nparticle_local
2712 INTEGER, POINTER :: itimes
2713 REAL(kind=dp) :: constraint_dt, dm, dt, inner_dt, mass
2714 REAL(kind=dp), ALLOCATABLE, DIMENSION(:, :) :: pos, vel
2715 TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
2716 TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
2717 TYPE(atomic_kind_type), POINTER :: atomic_kind
2718 TYPE(cell_type), POINTER :: cell
2719 TYPE(cp_subsys_type), POINTER :: subsys, subsys_respa
2720 TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
2721 TYPE(force_env_type), POINTER :: force_env
2722 TYPE(global_constraint_type), POINTER :: gci
2723 TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
2724 TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
2725 TYPE(molecule_list_type), POINTER :: molecules
2726 TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
2727 TYPE(mp_para_env_type), POINTER :: para_env
2728 TYPE(particle_list_type), POINTER :: particles, particles_respa
2729 TYPE(particle_type), DIMENSION(:), POINTER :: particle_set, particle_set_respa
2730 TYPE(simpar_type), POINTER :: simpar
2731
2732 NULLIFY (para_env, cell, subsys_respa, particles_respa, particle_set_respa, gci, force_env, atomic_kinds)
2733 NULLIFY (atomic_kind_set, simpar, subsys, particles, particle_set)
2734 NULLIFY (local_molecules, molecule_kinds, molecules, molecule_kind_set, local_particles, itimes)
2735 CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
2736 para_env=para_env, itimes=itimes)
2737 dt = simpar%dt
2738
2739 n_time_steps = simpar%n_time_steps
2740 inner_dt = dt/n_time_steps
2741
2742 CALL force_env_get(force_env, subsys=subsys, cell=cell)
2743 CALL force_env_get(force_env%sub_force_env(1)%force_env, subsys=subsys_respa)
2744
2745 ! Do some checks on coordinates and box
2746 CALL apply_qmmm_walls_reflective(force_env)
2747
2748 CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
2749 particles=particles, local_molecules=local_molecules, molecules=molecules, &
2750 gci=gci, molecule_kinds=molecule_kinds)
2751
2752 CALL cp_subsys_get(subsys=subsys_respa, particles=particles_respa)
2753 particle_set_respa => particles_respa%els
2754
2755 nparticle_kind = atomic_kinds%n_els
2756 atomic_kind_set => atomic_kinds%els
2757 molecule_kind_set => molecule_kinds%els
2758
2759 nparticle = particles%n_els
2760 particle_set => particles%els
2761 molecule_set => molecules%els
2762
2763 ! Allocate work storage for positions and velocities
2764 ALLOCATE (pos(3, nparticle))
2765 ALLOCATE (vel(3, nparticle))
2766 vel(:, :) = 0.0_dp
2767
2768 constraint_dt = dt
2769 IF (simpar%constraint) THEN
2770 IF (gci%joint_colvar_checks) THEN
2771 constraint_dt = inner_dt
2772 ELSE
2773 CALL getold(gci, local_molecules, molecule_set, &
2774 molecule_kind_set, particle_set, cell)
2775 END IF
2776 END IF
2777
2778 ! Multiple time step (first part)
2779 DO iparticle_kind = 1, nparticle_kind
2780 atomic_kind => atomic_kind_set(iparticle_kind)
2781 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
2782 dm = 0.5_dp*dt/mass
2783 nparticle_local = local_particles%n_el(iparticle_kind)
2784 DO iparticle_local = 1, nparticle_local
2785 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
2786 vel(:, iparticle) = particle_set(iparticle)%v(:) + &
2787 dm*(particle_set(iparticle)%f(:) - &
2788 particle_set_respa(iparticle)%f(:))
2789 END DO
2790 END DO
2791
2792 ! Velocity Verlet (first part)
2793 DO i_step = 1, n_time_steps
2794 IF (gci%joint_colvar_checks) CALL getold(gci, local_molecules, molecule_set, &
2795 molecule_kind_set, particle_set, cell)
2796 pos(:, :) = 0.0_dp
2797 DO iparticle_kind = 1, nparticle_kind
2798 atomic_kind => atomic_kind_set(iparticle_kind)
2799 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
2800 dm = 0.5_dp*dt/(n_time_steps*mass)
2801 nparticle_local = local_particles%n_el(iparticle_kind)
2802 DO iparticle_local = 1, nparticle_local
2803 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
2804 vel(:, iparticle) = vel(:, iparticle) + &
2805 dm*particle_set_respa(iparticle)%f(:)
2806 pos(:, iparticle) = particle_set(iparticle)%r(:) + &
2807 (dt/n_time_steps)*vel(:, iparticle)
2808 END DO
2809 END DO
2810
2811 IF (simpar%constraint) THEN
2812 ! Possibly update the target values
2813 CALL shake_update_targets(gci, local_molecules, molecule_set, &
2814 molecule_kind_set, inner_dt, force_env%root_section)
2815
2816 CALL shake_control(gci, local_molecules, molecule_set, &
2817 molecule_kind_set, particle_set, pos, vel, constraint_dt, simpar%shake_tol, &
2818 simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, cell, &
2819 para_env, local_particles)
2820 END IF
2821
2822 ! Broadcast the new particle positions
2823 CALL update_particle_set(particle_set, para_env, pos=pos)
2824 DO iparticle = 1, SIZE(particle_set)
2825 particle_set_respa(iparticle)%r = particle_set(iparticle)%r
2826 END DO
2827
2828 ! Update forces
2829 CALL force_env_calc_energy_force(force_env%sub_force_env(1)%force_env)
2830
2831 ! Metadynamics
2832 CALL metadyn_integrator(force_env, itimes, vel)
2833
2834 ! Velocity Verlet (second part)
2835 DO iparticle_kind = 1, nparticle_kind
2836 atomic_kind => atomic_kind_set(iparticle_kind)
2837 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
2838 dm = 0.5_dp*dt/(n_time_steps*mass)
2839 nparticle_local = local_particles%n_el(iparticle_kind)
2840 DO iparticle_local = 1, nparticle_local
2841 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
2842 vel(1, iparticle) = vel(1, iparticle) + dm*particle_set_respa(iparticle)%f(1)
2843 vel(2, iparticle) = vel(2, iparticle) + dm*particle_set_respa(iparticle)%f(2)
2844 vel(3, iparticle) = vel(3, iparticle) + dm*particle_set_respa(iparticle)%f(3)
2845 END DO
2846 END DO
2847
2848 IF (simpar%constraint) CALL rattle_control(gci, local_molecules, molecule_set, &
2849 molecule_kind_set, particle_set, vel, constraint_dt, simpar%shake_tol, &
2850 simpar%info_constraint, simpar%lagrange_multipliers, &
2851 simpar%dump_lm, cell, para_env, local_particles)
2852
2853 IF (simpar%annealing) vel(:, :) = vel(:, :)*simpar%f_annealing
2854 END DO
2855 DEALLOCATE (pos)
2856
2857 ! Multiple time step (second part)
2858 ! Compute forces for respa force_env
2859 CALL force_env_calc_energy_force(force_env)
2860
2861 ! Metadynamics
2862 CALL metadyn_integrator(force_env, itimes, vel)
2863
2864 DO iparticle_kind = 1, nparticle_kind
2865 atomic_kind => atomic_kind_set(iparticle_kind)
2866 CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
2867 dm = 0.5_dp*dt/mass
2868 nparticle_local = local_particles%n_el(iparticle_kind)
2869 DO iparticle_local = 1, nparticle_local
2870 iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
2871 vel(1, iparticle) = vel(1, iparticle) + dm*(particle_set(iparticle)%f(1) - particle_set_respa(iparticle)%f(1))
2872 vel(2, iparticle) = vel(2, iparticle) + dm*(particle_set(iparticle)%f(2) - particle_set_respa(iparticle)%f(2))
2873 vel(3, iparticle) = vel(3, iparticle) + dm*(particle_set(iparticle)%f(3) - particle_set_respa(iparticle)%f(3))
2874 END DO
2875 END DO
2876
2877 IF (gci%joint_colvar_checks) CALL rattle_control(gci, local_molecules, molecule_set, &
2878 molecule_kind_set, particle_set, vel, dt, simpar%shake_tol, &
2879 simpar%info_constraint, simpar%lagrange_multipliers, &
2880 simpar%dump_lm, cell, para_env, local_particles)
2881
2882 ! Broadcast the new particle velocities
2883 CALL update_particle_set(particle_set, para_env, vel=vel)
2884
2885 DEALLOCATE (vel)
2886
2887 END SUBROUTINE nve_respa
2888
2889END MODULE integrator
represent a simple array based list of the given type
Define the atomic kind types and their sub types.
subroutine, public get_atomic_kind_set(atomic_kind_set, atom_of_kind, kind_of, natom_of_kind, maxatom, natom, nshell, fist_potential_present, shell_present, shell_adiabatic, shell_check_distance, damping_present)
Get attributes of an atomic kind set.
subroutine, public get_atomic_kind(atomic_kind, fist_potential, element_symbol, name, mass, kind_number, natom, atom_list, rcov, rvdw, z, qeff, apol, cpol, mm_radius, shell, shell_active, damping)
Get attributes of an atomic kind.
Barostat structure: module containing barostat available for MD.
Handles all functions related to the CELL.
subroutine, public read_xyz_comment(line, cell, has_cell, step, time, ener)
Reads comment line of XYZ files to get cell, step, time and energy info.
subroutine, public init_cell(cell, hmat, periodic)
Initialise/readjust a simulation cell after hmat has been changed.
Handles all functions related to the CELL.
Definition cell_types.F:15
subroutine, public parse_cell_line(input_line, cell_itimes, cell_time, h, vol)
Read cell info from a line (parsed from a file).
Definition cell_types.F:195
subroutine, public fix_atom_control(force_env, w)
allows for fix atom constraints
subroutine, public release_local_fixd_list(lfixd_list)
destroy the list of local atoms on which to apply constraints/restraints Teodoro Laino [tlaino] - 11....
subroutine, public create_local_fixd_list(lfixd_list, nkind, molecule_kind_set, local_particles)
setup a list of local atoms on which to apply constraints/restraints
Contains routines useful for the application of constraints during MD.
subroutine, public pv_constraint(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, virial, group)
...
subroutine, public getold(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, cell)
saves all of the old variables
subroutine, public rattle_control(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, vel, dt, rattle_tol, log_unit, lagrange_mult, dump_lm, cell, group, local_particles)
...
Definition constraint.F:242
subroutine, public shake_control(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, pos, vel, dt, shake_tol, log_unit, lagrange_mult, dump_lm, cell, group, local_particles)
...
Definition constraint.F:102
subroutine, public shake_roll_control(gci, local_molecules, molecule_set, molecule_kind_set, particle_set, pos, vel, dt, simpar, roll_tol, iroll, vector_r, vector_v, group, u, cell, local_particles)
...
Definition constraint.F:371
subroutine, public shake_update_targets(gci, local_molecules, molecule_set, molecule_kind_set, dt, root_section)
Updates the TARGET of the COLLECTIVE constraints if the growth speed is different from zero.
Definition constraint.F:930
Defines control structures, which contain the parameters and the settings for the DFT-based calculati...
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...
subroutine, public cp_iterate(iteration_info, last, iter_nr, increment, iter_nr_out)
adds one to the actual iteration
Utility routines to read data from files. Kept as close as possible to the old parser because.
subroutine, public parser_read_line(parser, nline, at_end)
Read the next line from a logical unit "unit" (I/O node only). Skip (nline-1) lines and skip also all...
subroutine, public parser_get_next_line(parser, nline, at_end)
Read the next input line and broadcast the input information. Skip (nline-1) lines and skip also all ...
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
unit conversion facility
Definition cp_units.F:30
real(kind=dp) function, public cp_unit_to_cp2k(value, unit_str, defaults, power)
converts to the internal cp2k units to the given unit
Definition cp_units.F:1282
stores a lists of integer that are local to a processor. The idea is that these integers represent ob...
Provides interfaces to LAPACK eigenvalue/SVD routines.
subroutine, public shell_scale_comv(atomic_kind_set, local_particles, particle_set, com_vel, shell_vel, core_vel)
...
Lumps all possible extended system variables into one type for easy access and passing.
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
Define type storing the global information of a run. Keep the amount of stored data small....
collects all constants needed in input so that they can be used without circular dependencies
integer, parameter, public ehrenfest
integer, parameter, public npe_f_ensemble
integer, parameter, public npe_i_ensemble
integer, parameter, public npt_ia_ensemble
Provides integrator utility routines for the integrators.
subroutine, public variable_timestep(md_env, tmp, dt, simpar, para_env, atomic_kind_set, local_particles, particle_set, core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, npt)
Compute the timestep rescaling factor.
subroutine, public rattle_roll_setup(old, gci, atomic_kind_set, particle_set, local_particles, molecule_kind_set, molecule_set, local_molecules, vel, dt, cell, npt, simpar, virial, vector_v, roll_tol, iroll, infree, first, para_env, u)
update veps using multiplier obtained from SHAKE
subroutine, public allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
allocate temporary variables to store positions and velocities used by the velocity-verlet integrator
subroutine, public vv_second(tmp, atomic_kind_set, local_particles, particle_set, core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt, u)
Second half of the velocity-verlet algorithm : update velocity by half step using the new forces.
subroutine, public allocate_old(old, particle_set, npt)
...
subroutine, public update_dealloc_tmp(tmp, particle_set, shell_particle_set, core_particle_set, para_env, shell_adiabatic, pos, vel, should_deall_vel)
update positions and deallocate temporary variable
elemental subroutine, public damp_veps(npt, gamma1, dt)
provides damping for barostat via nph_uniaxial_damped dynamics
subroutine, public update_veps(box, npt, simpar, pv_kin, kin, virial, infree, virial_components)
Routine to compute veps.
subroutine, public get_s_ds(tmp, nparticle_kind, atomic_kind_set, local_particles, particle_set, dt, para_env, tmpv)
...
subroutine, public vv_first(tmp, atomic_kind_set, local_particles, particle_set, core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt, u, lfixd_list)
First half of the velocity-verlet algorithm : update velocity by half step and positions by full step...
subroutine, public deallocate_old(old)
...
Provides integrator routines (velocity verlet) for all the ensemble types.
Definition integrator.F:26
subroutine, public nvt(md_env, globenv)
nvt integrator for particle positions & momenta
subroutine, public isokin(md_env)
simplest version of the isokinetic gaussian thermostat
Definition integrator.F:699
subroutine, public reftraj(md_env)
uses coordinates in a file and generates frame after frame of these
subroutine, public nph_uniaxial(md_env)
nph_uniaxial integrator (non-Hamiltonian version) for particle positions & momenta undergoing uniaxia...
subroutine, public nph_uniaxial_damped(md_env)
nph_uniaxial integrator (non-Hamiltonian version) for particle positions & momenta undergoing uniaxia...
subroutine, public langevin(md_env)
Langevin integrator for particle positions & momenta (Brownian dynamics).
Definition integrator.F:152
subroutine, public npt_f(md_env, globenv)
Velocity Verlet integrator for the NPT ensemble with fully flexible cell.
subroutine, public nve_respa(md_env)
RESPA integrator for nve ensemble for particle positions & momenta.
subroutine, public nvt_adiabatic(md_env, globenv)
nvt adiabatic integrator for particle positions & momenta
Definition integrator.F:815
subroutine, public nve(md_env, globenv)
nve integrator for particle positions & momenta
Definition integrator.F:487
subroutine, public npt_i(md_env, globenv)
npt_i integrator for particle positions & momenta isotropic box changes
Defines the basic variable types.
Definition kinds.F:23
integer, parameter, public max_line_length
Definition kinds.F:59
integer, parameter, public dp
Definition kinds.F:34
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, electrons)
Set the integrator environment to the correct program.
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, electrons)
get components of MD environment type
Interface to the message passing library MPI.
Performs the metadynamics calculation.
subroutine, public metadyn_velocities_colvar(force_env, rand)
Evolves velocities COLVAR according to Vanden-Eijnden Ciccotti C.Phys.Letter 429 (2006) 310-316.
subroutine, public metadyn_integrator(force_env, itimes, vel, rand)
General driver for applying metadynamics.
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.
represent a simple array based list of the given type
Define the data structure for the particle information.
subroutine, public update_particle_set(particle_set, int_group, pos, vel, for, add)
...
Definition of physical constants:
Definition physcon.F:68
real(kind=dp), parameter, public femtoseconds
Definition physcon.F:153
subroutine, public apply_qmmm_walls_reflective(force_env)
Apply reflective QM walls in order to avoid QM atoms escaping from the QM Box.
Definition qmmm_util.F:100
Update a QM/MM calculations with force mixing.
subroutine, public qmmmx_update_force_env(force_env, root_section)
...
Dual integer-electron-endpoint charge mixing for constant-potential MD, built on top of CP2K's stock ...
subroutine, public push_lambda_to_mixed_env(force_env, lambda)
Push a dynamically computed lambda into the MIXED force_eval's input structure. force_env_methods....
subroutine, public charge_mixing_maybe_rebuild(force_env, electrons)
Check whether q(t) has drifted outside the currently-built [N_lo,N_hi] bracket and,...
subroutine, public qs_electrons_charge_mixing_lambda(electrons, lambda, n_lo, n_hi)
Given the current electronic coordinate q and the integer span S, compute the bracketing integers N_l...
subroutine, public compute_mixed_workfunction(force_env, axis, wf_min, wf_max, q, span, fermi_level_ev, workfunction_ev, lambda_in)
Fermi level / workfunction mixing across the two integer-charge endpoints. Stock MIXED only combines ...
Ne-electrode core-charge correction for constant-potential MD: adjusts the Ne pseudopotential core ch...
subroutine, public apply_ne_core_correction(force_env, target_nelect, neutral_electrons_ref)
Apply Ne core correction update from the current total electron number.
State of the fictitious electronic degree of freedom (electron number q, its momentum,...
Propagation of the electronic degree of freedom in constant-potential MD: generalized force,...
subroutine, public qs_electrons_drift(electrons, dt)
Drift of the electronic coordinate (total electron number).
subroutine, public qs_electrons_thermostat_step(electrons, dt)
Stochastic velocity rescaling ("O" step) of the electronic momentum, reusing CP2K's own CSVR rescalin...
subroutine, public qs_electrons_kick(electrons, dt)
Half-kick of the electronic momentum from the current generalized force.
Work function and Fermi level readback from the converged SCF, using the planar average of the Hartre...
subroutine, public qs_electrons_compute_workfunction(force_env, axis, minimum_a, maximum_a, fermi_level_ev, workfunction_ev)
Compute the work function (vacuum Hartree level minus Fermi level, in eV) from the planar average of ...
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.
initialization of the reftraj structure used to analyse previously generated trajectories
integer, parameter, public reftraj_wrap_central
integer, parameter, public reftraj_wrap_positive
integer, parameter, public reftraj_wrap_none
integer, parameter, public reftraj_eval_energy_forces
integer, parameter, public reftraj_eval_none
Initialize the analysis of trajectories to be done by activating the REFTRAJ ensemble.
subroutine, public compute_msd_reftraj(reftraj, md_env, particle_set)
...
Routines for propagating the orbitals.
subroutine, public propagation_step(qs_env, rtp, rtp_control)
performs a single propagation step a(t+Dt)=U(t+Dt,t)*a(0) and calculates the new exponential
Routine for the real time propagation output.
subroutine, public rt_prop_output(qs_env, run_type, delta_iter, used_time)
...
Types and set_get for real time propagation depending on runtype and diagonalization method different...
subroutine, public optimize_shell_core(force_env, particle_set, shell_particle_set, core_particle_set, globenv, tmp, check)
Optimize shell-core positions along an MD run.
Definition shell_opt.F:64
Type for storing MD parameters.
Utilities for string manipulations.
elemental subroutine, public uppercase(string)
Convert all lower case characters in a string to upper case.
Thermal regions type: to initialize and control the temperature of different regions.
Methods for Thermostats.
subroutine, public apply_thermostat_baro(thermostat, npt, group)
...
subroutine, public apply_thermostat_shells(thermostat, atomic_kind_set, particle_set, local_particles, group, shell_particle_set, core_particle_set, vel, shell_vel, core_vel)
...
subroutine, public apply_thermostat_particles(thermostat, force_env, molecule_kind_set, molecule_set, particle_set, local_molecules, local_particles, group, shell_adiabatic, shell_particle_set, core_particle_set, vel, shell_vel, core_vel)
...
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).
Provides all information about an atomic kind.
Type defining parameters related to the simulation cell.
Definition cell_types.F:60
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
Simulation parameter type for molecular dynamics.