forked from cp2k/cp2k
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathintegrator.F
2672 lines (2235 loc) · 132 KB
/
integrator.F
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
!--------------------------------------------------------------------------------------------------!
! CP2K: A general program to perform molecular dynamics simulations !
! Copyright 2000-2025 CP2K developers group <https://cp2k.org> !
! !
! SPDX-License-Identifier: GPL-2.0-or-later !
!--------------------------------------------------------------------------------------------------!
! **************************************************************************************************
!> \brief Provides integrator routines (velocity verlet) for all the
!> ensemble types
!> \par History
!> JGH (15-Mar-2001) : Pass logical for box change to force routine
!> Harald Forbert (Apr-2001): added path integral routine nvt_pimd
!> CJM (15-Apr-2001) : added coef integrators and energy routines
!> Joost VandeVondele (Juli-2003): simple version of isokinetic ensemble
!> Teodoro Laino [tlaino] 10.2007 - University of Zurich: Generalization to
!> different kind of thermostats
!> Teodoro Laino [tlaino] 11.2007 - Metadynamics: now part of the MD modules
!> Marcella Iannuzzi 02.2008 - Collecting common code (VV and creation of
!> a temporary type)
!> Teodoro Laino [tlaino] 02.2008 - Splitting integrator module and keeping in
!> integrator only the INTEGRATORS
!> Lianheng Tong [LT] 12.2013 - Added regions to Langevin MD
!> \author CJM
! **************************************************************************************************
MODULE integrator
USE atomic_kind_list_types, ONLY: atomic_kind_list_type
USE atomic_kind_types, ONLY: atomic_kind_type,&
get_atomic_kind,&
get_atomic_kind_set
USE barostat_types, ONLY: barostat_type
USE cell_methods, ONLY: init_cell,&
set_cell_param
USE cell_types, ONLY: cell_type,&
parse_cell_line
USE constraint, ONLY: rattle_control,&
shake_control,&
shake_roll_control,&
shake_update_targets
USE constraint_fxd, ONLY: create_local_fixd_list,&
fix_atom_control,&
release_local_fixd_list
USE constraint_util, ONLY: getold,&
pv_constraint
USE cp_control_types, ONLY: dft_control_type
USE cp_log_handling, ONLY: cp_to_string
USE cp_parser_methods, ONLY: parser_get_next_line,&
parser_read_line
USE cp_subsys_types, ONLY: cp_subsys_get,&
cp_subsys_type
USE cp_units, ONLY: cp_unit_to_cp2k
USE distribution_1d_types, ONLY: distribution_1d_type
USE eigenvalueproblems, ONLY: diagonalise
USE extended_system_dynamics, ONLY: shell_scale_comv
USE extended_system_types, ONLY: npt_info_type
USE force_env_methods, ONLY: force_env_calc_energy_force
USE force_env_types, ONLY: force_env_get,&
force_env_type
USE global_types, ONLY: global_environment_type
USE input_constants, ONLY: ehrenfest,&
npe_f_ensemble,&
npe_i_ensemble,&
npt_ia_ensemble
USE integrator_utils, ONLY: &
allocate_old, allocate_tmp, damp_v, damp_veps, deallocate_old, get_s_ds, &
old_variables_type, rattle_roll_setup, set, tmp_variables_type, update_dealloc_tmp, &
update_pv, update_veps, variable_timestep, vv_first, vv_second
USE kinds, ONLY: dp,&
max_line_length
USE md_environment_types, ONLY: get_md_env,&
md_environment_type,&
set_md_env
USE message_passing, ONLY: mp_para_env_type
USE metadynamics, ONLY: metadyn_integrator,&
metadyn_velocities_colvar
USE molecule_kind_list_types, ONLY: molecule_kind_list_type
USE molecule_kind_types, ONLY: local_fixd_constraint_type,&
molecule_kind_type
USE molecule_list_types, ONLY: molecule_list_type
USE molecule_types, ONLY: global_constraint_type,&
molecule_type
USE particle_list_types, ONLY: particle_list_type
USE particle_types, ONLY: particle_type,&
update_particle_set
USE physcon, ONLY: femtoseconds
USE qmmm_util, ONLY: apply_qmmm_walls_reflective
USE qmmmx_update, ONLY: qmmmx_update_force_env
USE qs_environment_types, ONLY: get_qs_env
USE reftraj_types, ONLY: REFTRAJ_EVAL_ENERGY_FORCES,&
REFTRAJ_EVAL_NONE,&
reftraj_type
USE reftraj_util, ONLY: compute_msd_reftraj
USE rt_propagation_methods, ONLY: propagation_step
USE rt_propagation_output, ONLY: rt_prop_output
USE rt_propagation_types, ONLY: rt_prop_type
USE shell_opt, ONLY: optimize_shell_core
USE simpar_types, ONLY: simpar_type
USE string_utilities, ONLY: uppercase
USE thermal_region_types, ONLY: thermal_region_type,&
thermal_regions_type
USE thermostat_methods, ONLY: apply_thermostat_baro,&
apply_thermostat_particles,&
apply_thermostat_shells
USE thermostat_types, ONLY: thermostat_type
USE virial_methods, ONLY: virial_evaluate
USE virial_types, ONLY: virial_type
#include "../base/base_uses.f90"
IMPLICIT NONE
PRIVATE
CHARACTER(len=*), PARAMETER, PRIVATE :: moduleN = 'integrator'
PUBLIC :: isokin, langevin, nve, nvt, npt_i, npt_f, nve_respa
PUBLIC :: nph_uniaxial_damped, nph_uniaxial, nvt_adiabatic, reftraj
CONTAINS
! **************************************************************************************************
!> \brief Langevin integrator for particle positions & momenta (Brownian dynamics)
!> \param md_env ...
!> \par Literature
!> - A. Ricci and G. Ciccotti, Mol. Phys. 101, 1927-1931 (2003)
!> - For langevin regions:
!> - L. Kantorovich, Phys. Rev. B 78, 094304 (2008)
!> - L. Kantorovich and N. Rompotis, Phys. Rev. B 78, 094305 (2008)
!> \par History
!> - Created (01.07.2005,MK)
!> - Added support for only performing Langevin MD on a region of atoms
!> (01.12.2013, LT)
!> \author Matthias Krack
! **************************************************************************************************
SUBROUTINE langevin(md_env)
TYPE(md_environment_type), POINTER :: md_env
INTEGER :: iparticle, iparticle_kind, iparticle_local, iparticle_reg, ireg, nparticle, &
nparticle_kind, nparticle_local, nshell
INTEGER, POINTER :: itimes
LOGICAL, ALLOCATABLE, DIMENSION(:) :: do_langevin
REAL(KIND=dp) :: c, c1, c2, c3, c4, dm, dt, gam, mass, &
noisy_gamma_region, reg_temp, sigma
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:) :: var_w
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: pos, vel, w
TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(atomic_kind_type), POINTER :: atomic_kind
TYPE(cell_type), POINTER :: cell
TYPE(cp_subsys_type), POINTER :: subsys
TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
TYPE(force_env_type), POINTER :: force_env
TYPE(global_constraint_type), POINTER :: gci
TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
TYPE(molecule_list_type), POINTER :: molecules
TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(particle_list_type), POINTER :: particles
TYPE(particle_type), DIMENSION(:), POINTER :: particle_set
TYPE(simpar_type), POINTER :: simpar
TYPE(thermal_region_type), POINTER :: thermal_region
TYPE(thermal_regions_type), POINTER :: thermal_regions
TYPE(virial_type), POINTER :: virial
NULLIFY (cell, para_env, gci, force_env)
NULLIFY (atomic_kinds, local_particles, subsys, local_molecules, molecule_kinds, molecules)
NULLIFY (molecule_kind_set, molecule_set, particles, particle_set, simpar, virial)
NULLIFY (thermal_region, thermal_regions, itimes)
CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
para_env=para_env, thermal_regions=thermal_regions, &
itimes=itimes)
dt = simpar%dt
gam = simpar%gamma + simpar%shadow_gamma
nshell = 0
CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
! Do some checks on coordinates and box
CALL apply_qmmm_walls_reflective(force_env)
CALL cp_subsys_get(subsys=subsys, &
atomic_kinds=atomic_kinds, &
gci=gci, &
local_particles=local_particles, &
local_molecules=local_molecules, &
molecules=molecules, &
molecule_kinds=molecule_kinds, &
nshell=nshell, &
particles=particles, &
virial=virial)
IF (nshell /= 0) &
CPABORT("Langevin dynamics is not yet implemented for core-shell models")
nparticle_kind = atomic_kinds%n_els
atomic_kind_set => atomic_kinds%els
molecule_kind_set => molecule_kinds%els
nparticle = particles%n_els
particle_set => particles%els
molecule_set => molecules%els
! Setup the langevin regions information
ALLOCATE (do_langevin(nparticle))
IF (simpar%do_thermal_region) THEN
DO iparticle = 1, nparticle
do_langevin(iparticle) = thermal_regions%do_langevin(iparticle)
END DO
ELSE
do_langevin(1:nparticle) = .TRUE.
END IF
! Allocate the temperature dependent variance (var_w) of the
! random variable for each atom. It may be different for different
! atoms because of the possibility of Langevin regions, and var_w
! for each region should depend on the temperature defined in the
! region
! RZK explains: sigma is the variance of the Wiener process associated
! with the stochastic term, sigma = m*var_w = m*(2*k_B*T*gamma*dt),
! noisy_gamma adds excessive noise that is not balanced by the damping term
ALLOCATE (var_w(nparticle))
var_w(1:nparticle) = simpar%var_w
IF (simpar%do_thermal_region) THEN
DO ireg = 1, thermal_regions%nregions
thermal_region => thermal_regions%thermal_region(ireg)
noisy_gamma_region = thermal_region%noisy_gamma_region
DO iparticle_reg = 1, thermal_region%npart
iparticle = thermal_region%part_index(iparticle_reg)
reg_temp = thermal_region%temp_expected
var_w(iparticle) = 2.0_dp*reg_temp*simpar%dt*(simpar%gamma + noisy_gamma_region)
END DO
END DO
END IF
! Allocate work storage
ALLOCATE (pos(3, nparticle))
pos(:, :) = 0.0_dp
ALLOCATE (vel(3, nparticle))
vel(:, :) = 0.0_dp
ALLOCATE (w(3, nparticle))
w(:, :) = 0.0_dp
IF (simpar%constraint) CALL getold(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, cell)
! Generate random variables
DO iparticle_kind = 1, nparticle_kind
atomic_kind => atomic_kind_set(iparticle_kind)
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
nparticle_local = local_particles%n_el(iparticle_kind)
DO iparticle_local = 1, nparticle_local
iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
IF (do_langevin(iparticle)) THEN
sigma = var_w(iparticle)*mass
ASSOCIATE (rng_stream => local_particles%local_particle_set(iparticle_kind)% &
rng(iparticle_local))
w(1, iparticle) = rng_stream%stream%next(variance=sigma)
w(2, iparticle) = rng_stream%stream%next(variance=sigma)
w(3, iparticle) = rng_stream%stream%next(variance=sigma)
END ASSOCIATE
END IF
END DO
END DO
DEALLOCATE (var_w)
! Apply fix atom constraint
CALL fix_atom_control(force_env, w)
! Velocity Verlet (first part)
c = EXP(-0.25_dp*dt*gam)
c2 = c*c
c4 = c2*c2
c1 = dt*c2
DO iparticle_kind = 1, nparticle_kind
atomic_kind => atomic_kind_set(iparticle_kind)
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
nparticle_local = local_particles%n_el(iparticle_kind)
dm = 0.5_dp*dt/mass
c3 = dm/c2
DO iparticle_local = 1, nparticle_local
iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
IF (do_langevin(iparticle)) THEN
vel(:, iparticle) = particle_set(iparticle)%v(:) + &
c3*particle_set(iparticle)%f(:)
pos(:, iparticle) = particle_set(iparticle)%r(:) + &
c1*particle_set(iparticle)%v(:) + &
c*dm*(dt*particle_set(iparticle)%f(:) + &
w(:, iparticle))
ELSE
vel(:, iparticle) = particle_set(iparticle)%v(:) + &
dm*particle_set(iparticle)%f(:)
pos(:, iparticle) = particle_set(iparticle)%r(:) + &
dt*particle_set(iparticle)%v(:) + &
dm*dt*particle_set(iparticle)%f(:)
END IF
END DO
END DO
IF (simpar%constraint) THEN
! Possibly update the target values
CALL shake_update_targets(gci, local_molecules, molecule_set, &
molecule_kind_set, dt, force_env%root_section)
CALL shake_control(gci, local_molecules, molecule_set, molecule_kind_set, &
particle_set, pos, vel, dt, simpar%shake_tol, &
simpar%info_constraint, simpar%lagrange_multipliers, &
simpar%dump_lm, cell, para_env, local_particles)
END IF
! Broadcast the new particle positions
CALL update_particle_set(particle_set, para_env, pos=pos)
DEALLOCATE (pos)
! Update forces
CALL force_env_calc_energy_force(force_env)
! Metadynamics
CALL metadyn_integrator(force_env, itimes, vel)
! Update Verlet (second part)
DO iparticle_kind = 1, nparticle_kind
atomic_kind => atomic_kind_set(iparticle_kind)
CALL get_atomic_kind(atomic_kind=atomic_kind, mass=mass)
dm = 0.5_dp*dt/mass
c3 = dm/c2
nparticle_local = local_particles%n_el(iparticle_kind)
DO iparticle_local = 1, nparticle_local
iparticle = local_particles%list(iparticle_kind)%array(iparticle_local)
IF (do_langevin(iparticle)) THEN
vel(1, iparticle) = vel(1, iparticle) + c3*particle_set(iparticle)%f(1)
vel(2, iparticle) = vel(2, iparticle) + c3*particle_set(iparticle)%f(2)
vel(3, iparticle) = vel(3, iparticle) + c3*particle_set(iparticle)%f(3)
vel(1, iparticle) = c4*vel(1, iparticle) + c2*w(1, iparticle)/mass
vel(2, iparticle) = c4*vel(2, iparticle) + c2*w(2, iparticle)/mass
vel(3, iparticle) = c4*vel(3, iparticle) + c2*w(3, iparticle)/mass
ELSE
vel(1, iparticle) = vel(1, iparticle) + dm*particle_set(iparticle)%f(1)
vel(2, iparticle) = vel(2, iparticle) + dm*particle_set(iparticle)%f(2)
vel(3, iparticle) = vel(3, iparticle) + dm*particle_set(iparticle)%f(3)
END IF
END DO
END DO
IF (simpar%temperature_annealing) THEN
simpar%temp_ext = simpar%temp_ext*simpar%f_temperature_annealing
simpar%var_w = simpar%var_w*simpar%f_temperature_annealing
END IF
IF (simpar%constraint) THEN
CALL rattle_control(gci, local_molecules, molecule_set, molecule_kind_set, &
particle_set, vel, dt, simpar%shake_tol, &
simpar%info_constraint, simpar%lagrange_multipliers, &
simpar%dump_lm, cell, para_env, local_particles)
END IF
! Broadcast the new particle velocities
CALL update_particle_set(particle_set, para_env, vel=vel)
DEALLOCATE (vel)
DEALLOCATE (w)
DEALLOCATE (do_langevin)
! Update virial
IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, virial, para_env)
CALL virial_evaluate(atomic_kind_set, particle_set, local_particles, &
virial, para_env)
END SUBROUTINE langevin
! **************************************************************************************************
!> \brief nve integrator for particle positions & momenta
!> \param md_env ...
!> \param globenv ...
!> \par History
!> - the local particle lists are used instead of pnode (Sep. 2003,MK)
!> - usage of fragments retrieved from the force environment (Oct. 2003,MK)
!> \author CJM
! **************************************************************************************************
SUBROUTINE nve(md_env, globenv)
TYPE(md_environment_type), POINTER :: md_env
TYPE(global_environment_type), POINTER :: globenv
INTEGER :: i_iter, n_iter, nparticle, &
nparticle_kind, nshell
INTEGER, POINTER :: itimes
LOGICAL :: deallocate_vel, ehrenfest_md, &
shell_adiabatic, shell_check_distance, &
shell_present
REAL(KIND=dp) :: dt
REAL(KIND=dp), ALLOCATABLE, DIMENSION(:, :) :: v_old
TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(cp_subsys_type), POINTER :: subsys
TYPE(dft_control_type), POINTER :: dft_control
TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
TYPE(force_env_type), POINTER :: force_env
TYPE(global_constraint_type), POINTER :: gci
TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
TYPE(molecule_list_type), POINTER :: molecules
TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(particle_list_type), POINTER :: core_particles, particles, &
shell_particles
TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
shell_particle_set
TYPE(rt_prop_type), POINTER :: rtp
TYPE(simpar_type), POINTER :: simpar
TYPE(thermostat_type), POINTER :: thermostat_coeff, thermostat_shell
TYPE(tmp_variables_type), POINTER :: tmp
TYPE(virial_type), POINTER :: virial
NULLIFY (thermostat_coeff, tmp)
NULLIFY (subsys, simpar, para_env, cell, gci, force_env, virial)
NULLIFY (atomic_kinds, local_particles, molecules, molecule_kind_set, molecule_set, particle_set)
NULLIFY (shell_particles, shell_particle_set, core_particles, &
core_particle_set, thermostat_shell, dft_control, itimes)
CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
thermostat_coeff=thermostat_coeff, thermostat_shell=thermostat_shell, &
para_env=para_env, ehrenfest_md=ehrenfest_md, itimes=itimes)
dt = simpar%dt
CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
! Do some checks on coordinates and box
CALL apply_qmmm_walls_reflective(force_env)
CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
particles=particles, local_molecules=local_molecules, molecules=molecules, &
molecule_kinds=molecule_kinds, gci=gci, virial=virial)
nparticle_kind = atomic_kinds%n_els
atomic_kind_set => atomic_kinds%els
molecule_kind_set => molecule_kinds%els
nparticle = particles%n_els
particle_set => particles%els
molecule_set => molecules%els
CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
shell_check_distance=shell_check_distance)
IF (shell_present) THEN
CALL cp_subsys_get(subsys=subsys, shell_particles=shell_particles, &
core_particles=core_particles)
shell_particle_set => shell_particles%els
nshell = SIZE(shell_particles%els)
IF (shell_adiabatic) THEN
core_particle_set => core_particles%els
END IF
END IF
CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
! Apply thermostat over the full set of shells if required
IF (shell_adiabatic) THEN
CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
local_particles, para_env, shell_particle_set=shell_particle_set, &
core_particle_set=core_particle_set)
END IF
IF (simpar%constraint) CALL getold(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, cell)
! Velocity Verlet (first part)
CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
IF (simpar%variable_dt) CALL 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)
IF (simpar%constraint) THEN
! Possibly update the target values
CALL shake_update_targets(gci, local_molecules, molecule_set, &
molecule_kind_set, dt, force_env%root_section)
CALL shake_control(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, simpar%shake_tol, &
simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
cell, para_env, local_particles)
END IF
! Broadcast the new particle positions and deallocate pos part of temporary
CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
core_particle_set, para_env, shell_adiabatic, pos=.TRUE.)
IF (shell_adiabatic .AND. shell_check_distance) THEN
CALL optimize_shell_core(force_env, particle_set, &
shell_particle_set, core_particle_set, globenv, tmp=tmp, check=.TRUE.)
END IF
! Update forces
! In case of ehrenfest dynamics, velocities need to be iterated
IF (ehrenfest_md) THEN
ALLOCATE (v_old(3, SIZE(tmp%vel, 2)))
v_old(:, :) = tmp%vel
CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
core_particle_set, para_env, shell_adiabatic, vel=.TRUE., &
should_deall_vel=.FALSE.)
tmp%vel = v_old
CALL get_qs_env(force_env%qs_env, dft_control=dft_control)
n_iter = dft_control%rtp_control%max_iter
ELSE
n_iter = 1
END IF
DO i_iter = 1, n_iter
IF (ehrenfest_md) THEN
CALL get_qs_env(qs_env=force_env%qs_env, rtp=rtp)
rtp%iter = i_iter
tmp%vel = v_old
CALL propagation_step(force_env%qs_env, rtp, dft_control%rtp_control)
END IF
![NB] let nve work with force mixing which does not have consistent energies and forces
CALL force_env_calc_energy_force(force_env, require_consistent_energy_force=.FALSE.)
IF (ehrenfest_md) THEN
CALL rt_prop_output(force_env%qs_env, ehrenfest, delta_iter=force_env%qs_env%rtp%delta_iter)
END IF
! Metadynamics
CALL metadyn_integrator(force_env, itimes, tmp%vel)
! Velocity Verlet (second part)
CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
IF (simpar%constraint) CALL rattle_control(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, tmp%vel, dt, simpar%shake_tol, &
simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
cell, para_env, local_particles)
! Apply thermostat over the full set of shell if required
IF (shell_adiabatic) THEN
CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
local_particles, para_env, vel=tmp%vel, &
shell_vel=tmp%shell_vel, core_vel=tmp%core_vel)
END IF
IF (simpar%annealing) THEN
tmp%vel(:, :) = tmp%vel(:, :)*simpar%f_annealing
IF (shell_adiabatic) THEN
CALL shell_scale_comv(atomic_kind_set, local_particles, particle_set, &
tmp%vel, tmp%shell_vel, tmp%core_vel)
END IF
END IF
IF (ehrenfest_md) deallocate_vel = force_env%qs_env%rtp%converged
IF (i_iter .EQ. n_iter) deallocate_vel = .TRUE.
! Broadcast the new particle velocities and deallocate the full temporary
CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
core_particle_set, para_env, shell_adiabatic, vel=.TRUE., &
should_deall_vel=deallocate_vel)
IF (ehrenfest_md) THEN
IF (force_env%qs_env%rtp%converged) EXIT
END IF
END DO
! Update virial
IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, &
molecule_set, molecule_kind_set, particle_set, virial, para_env)
CALL virial_evaluate(atomic_kind_set, particle_set, &
local_particles, virial, para_env)
END SUBROUTINE nve
! **************************************************************************************************
!> \brief simplest version of the isokinetic gaussian thermostat
!> \param md_env ...
!> \par History
!> - Created [2004-07]
!> \author Joost VandeVondele
!> \note
!> - time reversible, and conserves the kinetic energy to machine precision
!> - is not yet supposed to work for e.g. constraints, our the extended version
!> of this thermostat
!> see:
!> - Zhang F. , JCP 106, 6102 (1997)
!> - Minary P. et al, JCP 118, 2510 (2003)
! **************************************************************************************************
SUBROUTINE isokin(md_env)
TYPE(md_environment_type), POINTER :: md_env
INTEGER :: nparticle, nparticle_kind, nshell
INTEGER, POINTER :: itimes
LOGICAL :: shell_adiabatic, shell_present
REAL(KIND=dp) :: dt
TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cp_subsys_type), POINTER :: subsys
TYPE(distribution_1d_type), POINTER :: local_particles
TYPE(force_env_type), POINTER :: force_env
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(particle_list_type), POINTER :: core_particles, particles, &
shell_particles
TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
shell_particle_set
TYPE(simpar_type), POINTER :: simpar
TYPE(tmp_variables_type), POINTER :: tmp
NULLIFY (force_env, tmp, simpar, itimes)
NULLIFY (atomic_kinds, para_env, subsys, local_particles)
NULLIFY (core_particles, particles, shell_particles)
NULLIFY (core_particle_set, particle_set, shell_particle_set)
CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
para_env=para_env, itimes=itimes)
dt = simpar%dt
CALL force_env_get(force_env=force_env, subsys=subsys)
! Do some checks on coordinates and box
CALL apply_qmmm_walls_reflective(force_env)
IF (simpar%constraint) THEN
CPABORT("Constraints not yet implemented")
END IF
CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, &
local_particles=local_particles, &
particles=particles)
nparticle_kind = atomic_kinds%n_els
atomic_kind_set => atomic_kinds%els
nparticle = particles%n_els
particle_set => particles%els
CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
shell_present=shell_present, shell_adiabatic=shell_adiabatic)
IF (shell_present) THEN
CALL cp_subsys_get(subsys=subsys, shell_particles=shell_particles, &
core_particles=core_particles)
shell_particle_set => shell_particles%els
nshell = SIZE(shell_particles%els)
IF (shell_adiabatic) THEN
core_particle_set => core_particles%els
END IF
END IF
CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
! compute s,ds
CALL get_s_ds(tmp, nparticle_kind, atomic_kind_set, local_particles, particle_set, &
dt, para_env)
! Velocity Verlet (first part)
tmp%scale_v(1:3) = SQRT(1.0_dp/tmp%ds)
tmp%poly_v(1:3) = 2.0_dp*tmp%s/SQRT(tmp%ds)/dt
CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
core_particle_set, shell_particle_set, nparticle_kind, &
shell_adiabatic, dt)
IF (simpar%variable_dt) CALL 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)
! Broadcast the new particle positions and deallocate the pos components of temporary
CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
core_particle_set, para_env, shell_adiabatic, pos=.TRUE.)
CALL force_env_calc_energy_force(force_env)
! Metadynamics
CALL metadyn_integrator(force_env, itimes, tmp%vel)
! compute s,ds
CALL get_s_ds(tmp, nparticle_kind, atomic_kind_set, local_particles, particle_set, &
dt, para_env, tmpv=.TRUE.)
! Velocity Verlet (second part)
tmp%scale_v(1:3) = SQRT(1.0_dp/tmp%ds)
tmp%poly_v(1:3) = 2.0_dp*tmp%s/SQRT(tmp%ds)/dt
CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
core_particle_set, shell_particle_set, nparticle_kind, &
shell_adiabatic, dt)
IF (simpar%annealing) tmp%vel(:, :) = tmp%vel(:, :)*simpar%f_annealing
! Broadcast the new particle velocities and deallocate the temporary
CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
core_particle_set, para_env, shell_adiabatic, vel=.TRUE.)
END SUBROUTINE isokin
! **************************************************************************************************
!> \brief nvt adiabatic integrator for particle positions & momenta
!> \param md_env ...
!> \param globenv ...
!> \par History
!> - the local particle lists are used instead of pnode (Sep. 2003,MK)
!> - usage of fragments retrieved from the force environment (Oct. 2003,MK)
!> \author CJM
! **************************************************************************************************
SUBROUTINE nvt_adiabatic(md_env, globenv)
TYPE(md_environment_type), POINTER :: md_env
TYPE(global_environment_type), POINTER :: globenv
INTEGER :: ivar, nparticle, nparticle_kind, nshell
INTEGER, POINTER :: itimes
LOGICAL :: shell_adiabatic, shell_check_distance, &
shell_present
REAL(KIND=dp) :: dt
REAL(KIND=dp), DIMENSION(:), POINTER :: rand
TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(cp_subsys_type), POINTER :: subsys
TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
TYPE(force_env_type), POINTER :: force_env
TYPE(global_constraint_type), POINTER :: gci
TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
TYPE(molecule_list_type), POINTER :: molecules
TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(particle_list_type), POINTER :: core_particles, particles, &
shell_particles
TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
shell_particle_set
TYPE(simpar_type), POINTER :: simpar
TYPE(thermostat_type), POINTER :: thermostat_coeff, thermostat_fast, &
thermostat_shell, thermostat_slow
TYPE(tmp_variables_type), POINTER :: tmp
TYPE(virial_type), POINTER :: virial
NULLIFY (gci, force_env, thermostat_coeff, tmp, &
thermostat_fast, thermostat_slow, thermostat_shell, cell, shell_particles, &
shell_particle_set, core_particles, core_particle_set, rand)
NULLIFY (para_env, subsys, local_molecules, local_particles, molecule_kinds, &
molecules, molecule_kind_set, molecule_set, atomic_kinds, particles)
NULLIFY (simpar, itimes)
CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
thermostat_fast=thermostat_fast, thermostat_slow=thermostat_slow, &
thermostat_coeff=thermostat_coeff, thermostat_shell=thermostat_shell, &
para_env=para_env, itimes=itimes)
dt = simpar%dt
CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
! Do some checks on coordinates and box
CALL apply_qmmm_walls_reflective(force_env)
CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
particles=particles, local_molecules=local_molecules, molecules=molecules, &
molecule_kinds=molecule_kinds, gci=gci, virial=virial)
nparticle_kind = atomic_kinds%n_els
atomic_kind_set => atomic_kinds%els
molecule_kind_set => molecule_kinds%els
nparticle = particles%n_els
particle_set => particles%els
molecule_set => molecules%els
CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
shell_check_distance=shell_check_distance)
IF (ASSOCIATED(force_env%meta_env)) THEN
! Allocate random number for Langevin Thermostat acting on COLVARS
IF (force_env%meta_env%langevin) THEN
ALLOCATE (rand(force_env%meta_env%n_colvar))
rand(:) = 0.0_dp
END IF
END IF
! Allocate work storage for positions and velocities
IF (shell_present) THEN
CALL cp_subsys_get(subsys=subsys, shell_particles=shell_particles, &
core_particles=core_particles)
shell_particle_set => shell_particles%els
nshell = SIZE(shell_particles%els)
IF (shell_adiabatic) THEN
core_particle_set => core_particles%els
END IF
END IF
CALL allocate_tmp(md_env, tmp, nparticle, nshell, shell_adiabatic)
! Apply Thermostat over the full set of particles
IF (shell_adiabatic) THEN
! CALL apply_thermostat_particles(thermostat_part, molecule_kind_set, molecule_set,&
! particle_set, local_molecules, para_env, shell_adiabatic=shell_adiabatic,&
! shell_particle_set=shell_particle_set, core_particle_set=core_particle_set)
CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
local_particles, para_env, shell_particle_set=shell_particle_set, &
core_particle_set=core_particle_set)
ELSE
CALL apply_thermostat_particles(thermostat_fast, force_env, molecule_kind_set, molecule_set, &
particle_set, local_molecules, local_particles, para_env)
CALL apply_thermostat_particles(thermostat_slow, force_env, molecule_kind_set, molecule_set, &
particle_set, local_molecules, local_particles, para_env)
END IF
IF (simpar%constraint) CALL getold(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, cell)
! *** Velocity Verlet for Langeving *** v(t)--> v(t+1/2)
IF (ASSOCIATED(force_env%meta_env)) THEN
IF (force_env%meta_env%langevin) THEN
DO ivar = 1, force_env%meta_env%n_colvar
rand(ivar) = force_env%meta_env%rng(ivar)%next()
END DO
CALL metadyn_velocities_colvar(force_env, rand)
END IF
END IF
! Velocity Verlet (first part)
CALL vv_first(tmp, atomic_kind_set, local_particles, particle_set, &
core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
IF (simpar%variable_dt) CALL 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)
IF (simpar%constraint) THEN
! Possibly update the target values
CALL shake_update_targets(gci, local_molecules, molecule_set, &
molecule_kind_set, dt, force_env%root_section)
CALL shake_control(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, tmp%pos, tmp%vel, dt, simpar%shake_tol, &
simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
cell, para_env, local_particles)
END IF
! Broadcast the new particle positions and deallocate pos components of temporary
CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
core_particle_set, para_env, shell_adiabatic, pos=.TRUE.)
IF (shell_adiabatic .AND. shell_check_distance) THEN
CALL optimize_shell_core(force_env, particle_set, &
shell_particle_set, core_particle_set, globenv, tmp=tmp, check=.TRUE.)
END IF
! Update forces
CALL force_env_calc_energy_force(force_env)
! Metadynamics
CALL metadyn_integrator(force_env, itimes, tmp%vel, rand=rand)
! Velocity Verlet (second part)
CALL vv_second(tmp, atomic_kind_set, local_particles, particle_set, &
core_particle_set, shell_particle_set, nparticle_kind, shell_adiabatic, dt)
IF (simpar%constraint) CALL rattle_control(gci, local_molecules, molecule_set, &
molecule_kind_set, particle_set, tmp%vel, dt, simpar%shake_tol, &
simpar%info_constraint, simpar%lagrange_multipliers, simpar%dump_lm, &
cell, para_env, local_particles)
! Apply Thermostat over the full set of particles
IF (shell_adiabatic) THEN
! CALL apply_thermostat_particles(thermostat_part,molecule_kind_set, molecule_set, &
! particle_set, local_molecules, para_env, shell_adiabatic=shell_adiabatic,&
! vel= tmp%vel, shell_vel= tmp%shell_vel, core_vel= tmp%core_vel)
CALL apply_thermostat_shells(thermostat_shell, atomic_kind_set, particle_set, &
local_particles, para_env, vel=tmp%vel, shell_vel=tmp%shell_vel, &
core_vel=tmp%core_vel)
ELSE
CALL apply_thermostat_particles(thermostat_slow, force_env, molecule_kind_set, molecule_set, &
particle_set, local_molecules, local_particles, para_env, vel=tmp%vel)
CALL apply_thermostat_particles(thermostat_fast, force_env, molecule_kind_set, molecule_set, &
particle_set, local_molecules, local_particles, para_env, vel=tmp%vel)
END IF
! Broadcast the new particle velocities and deallocate temporary
CALL update_dealloc_tmp(tmp, particle_set, shell_particle_set, &
core_particle_set, para_env, shell_adiabatic, vel=.TRUE.)
IF (ASSOCIATED(force_env%meta_env)) THEN
IF (force_env%meta_env%langevin) THEN
DEALLOCATE (rand)
END IF
END IF
! Update constraint virial
IF (simpar%constraint) CALL pv_constraint(gci, local_molecules, &
molecule_set, molecule_kind_set, particle_set, virial, para_env)
! ** Evaluate Virial
CALL virial_evaluate(atomic_kind_set, particle_set, &
local_particles, virial, para_env)
END SUBROUTINE nvt_adiabatic
! **************************************************************************************************
!> \brief nvt integrator for particle positions & momenta
!> \param md_env ...
!> \param globenv ...
!> \par History
!> - the local particle lists are used instead of pnode (Sep. 2003,MK)
!> - usage of fragments retrieved from the force environment (Oct. 2003,MK)
!> \author CJM
! **************************************************************************************************
SUBROUTINE nvt(md_env, globenv)
TYPE(md_environment_type), POINTER :: md_env
TYPE(global_environment_type), POINTER :: globenv
INTEGER :: ivar, nparticle, nparticle_kind, nshell
INTEGER, POINTER :: itimes
LOGICAL :: shell_adiabatic, shell_check_distance, &
shell_present
REAL(KIND=dp) :: dt
REAL(KIND=dp), DIMENSION(:), POINTER :: rand
TYPE(atomic_kind_list_type), POINTER :: atomic_kinds
TYPE(atomic_kind_type), DIMENSION(:), POINTER :: atomic_kind_set
TYPE(cell_type), POINTER :: cell
TYPE(cp_subsys_type), POINTER :: subsys
TYPE(distribution_1d_type), POINTER :: local_molecules, local_particles
TYPE(force_env_type), POINTER :: force_env
TYPE(global_constraint_type), POINTER :: gci
TYPE(molecule_kind_list_type), POINTER :: molecule_kinds
TYPE(molecule_kind_type), DIMENSION(:), POINTER :: molecule_kind_set
TYPE(molecule_list_type), POINTER :: molecules
TYPE(molecule_type), DIMENSION(:), POINTER :: molecule_set
TYPE(mp_para_env_type), POINTER :: para_env
TYPE(particle_list_type), POINTER :: core_particles, particles, &
shell_particles
TYPE(particle_type), DIMENSION(:), POINTER :: core_particle_set, particle_set, &
shell_particle_set
TYPE(simpar_type), POINTER :: simpar
TYPE(thermostat_type), POINTER :: thermostat_coeff, thermostat_part, &
thermostat_shell
TYPE(tmp_variables_type), POINTER :: tmp
TYPE(virial_type), POINTER :: virial
NULLIFY (gci, force_env, thermostat_coeff, tmp, &
thermostat_part, thermostat_shell, cell, shell_particles, &
shell_particle_set, core_particles, core_particle_set, rand)
NULLIFY (para_env, subsys, local_molecules, local_particles, molecule_kinds, &
molecules, molecule_kind_set, molecule_set, atomic_kinds, particles)
NULLIFY (simpar, thermostat_coeff, thermostat_part, thermostat_shell, itimes)
CALL get_md_env(md_env=md_env, simpar=simpar, force_env=force_env, &
thermostat_part=thermostat_part, thermostat_coeff=thermostat_coeff, &
thermostat_shell=thermostat_shell, para_env=para_env, &
itimes=itimes)
dt = simpar%dt
CALL force_env_get(force_env=force_env, subsys=subsys, cell=cell)
! Do some checks on coordinates and box
CALL apply_qmmm_walls_reflective(force_env)
CALL cp_subsys_get(subsys=subsys, atomic_kinds=atomic_kinds, local_particles=local_particles, &
particles=particles, local_molecules=local_molecules, molecules=molecules, &
molecule_kinds=molecule_kinds, gci=gci, virial=virial)
nparticle_kind = atomic_kinds%n_els
atomic_kind_set => atomic_kinds%els
molecule_kind_set => molecule_kinds%els
nparticle = particles%n_els
particle_set => particles%els
molecule_set => molecules%els
CALL get_atomic_kind_set(atomic_kind_set=atomic_kind_set, &
shell_present=shell_present, shell_adiabatic=shell_adiabatic, &
shell_check_distance=shell_check_distance)
IF (ASSOCIATED(force_env%meta_env)) THEN
! Allocate random number for Langevin Thermostat acting on COLVARS
IF (force_env%meta_env%langevin) THEN
ALLOCATE (rand(force_env%meta_env%n_colvar))
rand(:) = 0.0_dp
END IF
END IF