-
Notifications
You must be signed in to change notification settings - Fork 0
/
PIMD_Water_qTIP4Pf.f90
executable file
·1481 lines (1169 loc) · 52 KB
/
PIMD_Water_qTIP4Pf.f90
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
!*****************************************************************************
program PIMD_Water_qTIP4Pf
!*****************************************************************************
!
! Project: MolecularDynamics
!
! Created on: Jan 2020 by Alfonso Gijón
!
! This means to serve as an example of a client program that runs a
! multireplica simulation using the Path Integral interpretation of quantum
! statistical mechanics. A Langevin dynamics is followed by each atom of
! of the extended system, to ensure that the NVT ensemble is correctly sampled
!
! The physical system is a cluster of water molecules, interacting via a SPC/F
! potential.
!
!*****************************************************************************
! modules used
use MD_State_module
use MolecularDynamics
use qTIP4Pf
use omp_lib
!*****************************************************************************
! No implicits please!
implicit none
!*****************************************************************************
! local variables
integer i, j, k
integer i1, i2, ir
integer n, n0
integer nStep
integer iat, imol, jmol, nmol
integer iblock
integer length
integer energ
integer dyntype
integer nSteps
integer nSteps_equi
integer nSteps_prod
integer n_atoms
integer n_mols
integer nReplicas
integer nblocks
integer jat, iox, jox, n_ox
integer istart
integer noutputs, nperiod, nperiod_density
integer nthreads, nthreads_max
integer nThermostats
double precision, dimension(:), allocatable :: tMass
logical fixCellShape
logical periodic
logical start
double precision, parameter :: ang_to_au = one / 0.529177d0
double precision, parameter :: kcalmol_to_au = one / 627.510d0
double precision, parameter :: massConversionFactor = 1822.8885302342505_dp
double precision :: gamma
double precision :: temperature_target
double precision :: delta_t
double precision :: tstart_cpu, tfinish_cpu, cputime
integer :: count_0, count_1, count_rate, count_max
double precision :: walltime
double precision :: kinetic_energy
double precision :: potential_energy
double precision :: thermostat_energy
double precision :: total_energy
double precision :: temperature
double precision :: beta, beta2, kT
double precision :: qKineticEnergy
double precision :: qKineticEnergy_v2
double precision :: qPotentialEnergy
double precision :: qTotalEnergy
double precision :: qTotalEnergy_v2
double precision :: temperature_avrg, kinetic_avrg, potential_avrg, totalenergy_avrg
double precision :: qkinetic_avrg, qkinetic_v2_avrg, qpotential_avrg
double precision :: qtotalenergy_avrg, qtotalenergy_v2_avrg
double precision :: sigma_kinetic, sigma_potential, sigma_totalenergy, sigma_qtotalenergy_v2
double precision :: sigma_qkinetic, sigma_qkinetic_v2, sigma_qpotential, sigma_qtotalenergy
double precision, allocatable, dimension(:) :: gyration2, gyration2_avrg
double precision, allocatable, dimension(:,:) :: g2_avrg
double precision :: radius2, radius2_avrg, radmax2, radmax2_avrg
double precision :: gyration2_o, gyration2_h, gyration2_o_avrg, gyration2_h_avrg
double precision :: sigma_radius2, sigma_gyration2_o, sigma_gyration2_h, sigma_radmax2
double precision:: msd_ox_avrg, msd_hy_avrg, sigma_msd_ox, sigma_msd_hy
double precision:: msd_ox, msd_hy
double precision:: msd_w
double precision :: roh2, theta
double precision :: roh2_avrg, theta_avrg
double precision :: sigma_roh2, sigma_theta
integer, parameter :: nblocks_max = 20
double precision, dimension (nblocks_max) :: kin_avrg, pot_avrg, tote_avrg, qkin_avrg
double precision, dimension (nblocks_max) :: qkin_v2_avrg, qpot_avrg
double precision, dimension(nblocks_max) :: r2_avrg, qtote_avrg, qtote_v2_avrg
double precision, dimension(nblocks_max) :: rmax2_avrg
double precision, dimension(nblocks_max) :: doh2_avrg, hoh_avrg
double precision :: dblock
! integer, parameter :: nbinp = 100
! double precision :: pmin_o, pmax_o, pmin_h, pmax_h, deltap_o, deltap_h
! double precision :: pmin_h2o, pmax_h2o, deltap_h2o, mh2o, px_h2o
! double precision :: norm_ph, norm_po, norm_ph2o
! double precision :: pl, pr, pc, px, gaussian, sigma
! double precision :: sigma_o, sigma_h, sigma_h2o
! double precision, dimension (nbinp) :: pdistro_h_avrg
! double precision, dimension (nbinp) :: pdistro_o_avrg
! double precision, dimension (nbinp) :: pdistro_h2o_avrg
! double precision, dimension (nbinp) :: pdistro_h
! double precision, dimension (nbinp) :: pdistro_o
! double precision, dimension (nbinp) :: pdistro_h2o
! double precision, allocatable, dimension (:,:) :: momentum
integer, parameter :: nbinx = 200
double precision :: x1c, x2c, xmax, xmin, dx
double precision :: dox_xy, dox_yz, dox_zx, dhy_xy, dhy_yz, dhy_zx
double precision, dimension(3,nbinx,nbinx) :: density_o
double precision, dimension(3,nbinx,nbinx) :: density_h
double precision, dimension(3,nbinx,nbinx) :: density_o_avrg
double precision, dimension(3,nbinx,nbinx) :: density_h_avrg
integer:: nbinr
double precision :: rc, rmax_rho, dr_rho, rmax_g, dr_g, rmax_histo
double precision, allocatable, dimension(:) :: rhor_o
double precision, allocatable, dimension(:) :: rhor_h
double precision, allocatable, dimension(:) :: rhor_h2o
double precision, allocatable, dimension(:) :: rhor_o_avrg
double precision, allocatable, dimension(:) :: rhor_h_avrg
double precision, allocatable, dimension(:) :: rhor_h2o_avrg
double precision, allocatable, dimension(:) :: goo, ghh, goh
double precision, allocatable, dimension(:) :: goo_avrg, ghh_avrg, goh_avrg
double precision, dimension(3) :: a, b, c
double precision, dimension(3) :: rcm
double precision, allocatable, dimension (:,:) :: position0
double precision, allocatable, dimension (:,:) :: centroid
double precision, allocatable, dimension (:,:) :: centroid0
double precision, allocatable, dimension (:,:) :: centroid_avrg
double precision, allocatable, dimension (:,:,:) :: ctr_avrg
double precision, allocatable, dimension (:,:) :: ctr2_avrg
double precision, allocatable, dimension (:) :: centroid2_avrg
double precision, allocatable, dimension (:) :: centroid2
double precision, allocatable, dimension (:,:,:) :: polymer
double precision, allocatable, dimension (:) :: mass
double precision, allocatable, dimension (:,:) :: rij, rij2
double precision, allocatable, dimension (:,:,:) :: rij_block, rij2_block
double precision, dimension(3) :: vij
double precision :: dij, dij2, lindemann, linde, sigma_linde
type ( StateChain_type ) :: state_chain
character ( len = 30 ) :: restartFile
character ( len = 30 ) :: newRestartFile
character ( len = 30 ) :: logfile, xyzfile
character ( len = 30 ) :: idat
logical exist
!*****************************************************************************
! begin program
call cpu_time(tstart_cpu)
call system_clock( count_0, count_rate, count_max )
!walltime = omp_get_wtime()
! simulation info
restartFile = 'restartPI'
newRestartFile = 'restartPI_2'
write(*,*) 'Reading input'
write(*,*)
read(5,*)
read(5,*) logfile
logfile = trim(logfile)
write(*,*) '# logfile'
write(*,*) logfile
!logfile = "logfile.dat"
inquire( file = logfile, exist = exist )
if (exist) then
open( unit = 20, file = logfile, status = "old", position = "append", action = "write")
else
open( unit = 20, file = logfile)
end if
read(5,*)
read(5,*) nSteps_equi, nSteps_prod
write(*,*) '# Number of timesteps of equilibration and production'
write(*,*) nSteps_equi, nSteps_prod
write(20,*) '# Number of timesteps of equilibration and production'
write(20,*) nSteps_equi, nSteps_prod
!nSteps = 100000
nSteps = nSteps_equi + nSteps_prod
read(5,*)
read(5,*) noutputs
write(*,*) '# Number of outputs in logfile'
write(*,*) noutputs
write(20,*) '# Number of outputs in logfile'
write(20,*) noutputs
!noutputs = 1000
nperiod = nSteps_prod / noutputs
read(5,*)
read(5,*) nperiod_density, nbinr, rmax_histo
write(*,*) '# Frequency to compute spatial density, number of bins and rmax (in Angstroms)'
write(*,*) nperiod_density, nbinr, rmax_histo
write(20,*) '# Frequency to compute spatial density, number of bins and rmax (in Angstroms)'
write(20,*) nperiod_density, nbinr, rmax_histo
!nperiod_density = 1
!nbinr = 500
dyntype = 4 ! Bussi-Parrinello dynamics for each degree of freedom
read(5,*)
read(5,*) istart
write(*,*) '# Restart label (1 if restart, 0 if not)'
write(*,*) istart
write(20,*) '# Restart label (1 if restart, 0 if not)'
write(20,*) istart
if (istart .eq. 1) then
start = .false.
else
start = .true.
end if
!start = .true. ! this is not a re-start simulation
!start = .false. ! restart simulation
periodic = .false. ! we do not assume periodic-boundary conditions
fixCellShape = .false. ! we do not impose a fixed cell shape
length = 0 ! length units of client are Bohr (atomic units)
energ = 0 ! energy units are Hartree (atomic units)
call setUnits( Bohr, Hartree )
! LATTICE VECTORS ARE NOT USED BY THE PROGRAM, AS WE ARE
! CONSIDERING FINITE WATER CLUSTERS, NOT PERIODIC SYSTEMS.
! a = zero
! b = zero
! c = zero
! read(5,*)
! read(5,*) a(1), b(2), c(3)
! write(*,*) '# Lattice vectors'
! write(*,*) a
! write(*,*) b
! write(*,*) c
! write(20,*) '# Lattice vectors'
! write(20,*) a
! write(20,*) b
! write(20,*) c
a = (/60.55_dp, 0.0_dp, 0.0_dp/)
b = (/0.0_dp, 60.55_dp, 0.0_dp/)
c = (/0.0_dp, 0.0_dp, 60.55_dp/)
if ( length .eq. 1 ) then ! cell parameters and atomic positions
! must be in client units (Angstrom in this case)
a = a / Angstrom
b = b / Angstrom
c = c / Angstrom
end if
nThermostats = 0
!tMass = 1.0_dp
read(5,*)
read(5,*) n_mols
write(*,*) '# Number of water molecules of the cluster'
write(*,*) n_mols
write(20,*) '# Number of water molecules of the cluster'
write(20,*) n_mols
!n_mols = 2
n_atoms = 3 * n_mols
read(5,*)
read(5,*) nReplicas
write(*,*) '# Number of replicas'
write(*,*) nReplicas
write(20,*) '# Number of replicas'
write(20,*) nReplicas
!nReplicas = 120
read(5,*)
read(5,*) gamma
write(*,*) '# Friction parameter of Langevin dynamics (NVE dynamics if zero)'
write(*,*) gamma
write(20,*) '# Friction parameter of Langevin dynamics (NVE dynamics if zero)'
write(20,*) gamma
!gamma = 0.001_dp ! friction parameter of Langevin dynamics
!gamma = zero ! if gamma = zero, NVE dynamics is followed
read(5,*)
read(5,*) temperature_target
write(*,*) '# Target temperature (K)'
write(*,*) temperature_target
write(20,*) '# Target temperature (K)'
write(20,*) temperature_target
!temperature_target = 50.0_dp
beta = one / ( boltzmann_k * temperature_target )
beta2 = beta*beta
kT = one / beta
read(5,*)
read(5,*) delta_t
write(*,*) '# Timestep (fs)'
write(*,*) delta_t
write(20,*) '# Timestep (fs)'
write(20,*) delta_t
!delta_t = 1.0_dp ! 1 fs
! write some information about units, number of atoms...
if ( length .eq. 0 ) then
write(20,*) 'Length units are Bohr (atomic units)'
else if ( length .eq. 1 ) then
write(20,*) 'Length units are Angstrom (puaj!!!)'
else
write(20,*) 'Unrecognised length units!'
stop
end if
if ( energ .eq. 0 ) then
write(20,*) 'Energy units are Hartree (atomic units)'
else if ( energ .eq. 1 ) then
write(20,*) 'Energy units are Rydberg (tutut!)'
else if ( energ .eq. 2 ) then
write(20,*) 'Energy units are eV (puaj!!!!)'
else
write(20,*) 'Unrecognised energy units!'
stop
end if
write(20,*) 'n_atoms = ', n_atoms
! allocate some arrays
allocate( mass( n_atoms ) )
allocate( position0( 3, n_atoms ) )
!allocate( momentum( 3, n_atoms ) )
allocate( centroid( 3, n_atoms ) )
allocate( centroid0( 3, n_atoms ) )
allocate( centroid_avrg( 3, n_atoms ) )
allocate( centroid2( n_atoms ) )
allocate( centroid2_avrg( n_atoms ) )
allocate( polymer( 3, n_atoms, nReplicas ) )
allocate( gyration2( n_atoms ) )
allocate( gyration2_avrg( n_atoms ) )
n_ox = n_mols
allocate( rij( n_ox, n_ox ) )
allocate( rij2( n_ox, n_ox ) )
allocate( rhor_o(nbinr) )
allocate( rhor_h(nbinr) )
allocate( rhor_h2o(nbinr) )
allocate( rhor_o_avrg(nbinr) )
allocate( rhor_h_avrg(nbinr) )
allocate( rhor_h2o_avrg(nbinr) )
allocate( goo(nbinr) )
allocate( ghh(nbinr) )
allocate( goh(nbinr) )
allocate( goo_avrg(nbinr) )
allocate( ghh_avrg(nbinr) )
allocate( goh_avrg(nbinr) )
! parallelization settings
! Choose the number of threads
!nthreads = omp_get_num_threads ( ) ! OMP_NUM_THREADS enviroment variable
nthreads = omp_get_num_procs( ) ! number of processors of my machine
nthreads_max = omp_get_max_threads ( )
call omp_set_num_threads(nthreads)
write(*,*)
write(*,*) 'Number of OpenMP threads'
write(*,*) nthreads
write(*,*)
write(20,*)
write(20,*) 'Number of OpenMP threads'
write(20,*) nthreads
write(20,*)
! state info
read(5,*)
read(5,*) xyzfile
xyzfile = trim(xyzfile)
write(*,*) 'Structures file'
write(*,*) xyzfile
write(20,*) 'Structures file'
write(20,*) xyzfile
close(5)
if ( start ) then
! read positions of atoms
open( unit = 10, file = xyzfile )
read(10,*)
read(10,*)
do imol = 1, n_mols
do j = 1, 3
iat = j + 3 * (imol-1)
read(10,*) idat, position0(1:3,iat)
if ( j .eq. 1) then
mass(iat) = 15.999_dp ! oxygen mass
else
mass(iat) = 1.00784_dp ! hydrogen mass
end if
end do
end do
close(10)
! Translate the center of masses of the cluster to the origin
rcm = zero
do imol = 1, n_mols
do j = 1, 3
iat = j + 3 * (imol-1)
rcm = rcm + mass(iat) * position0(:,iat)
end do
end do
rcm = rcm / sum( mass )
do iat = 1, n_atoms
position0(:,iat) = position0(:,iat) - rcm(:)
end do
position0 = position0 * ang_to_au ! convert Angstrom to atomic units
! now create a chain of replicas (with same positions in each replica but random momenta)
call setupStateChain( state_chain, nReplicas, temperature_target, n_atoms, &
nThermostats, tMass, a, b, c, mass, position0, periodic = periodic )
n0 = 0
else
call readRestartChain( state_chain, restartFile, n0 )
call getMass( state_chain, mass )
end if
! setup qTIP4Pf water potential and compute initial energy and forces
call qTIP4Pf_setup()
call computeForces( state_chain, temperature_target, gyration2, centroid )
! compute initial radius to set size of the spatial mesh
call CentroidProperties( n_atoms, mass, centroid, radius2, radmax2, roh2, theta )
centroid0 = centroid
open(unit=88,file='msd.dat')
call MSD(n_atoms, mass, centroid0, centroid, msd_w)
write(88,*) int(0), msd_w / ang_to_au
! before entering the MD loop, set-up MD and compute initial classical energy
call MDChain_setup( state_chain, dyntype, delta_t, temperature_target, friction = gamma )
call inquireStateChain(state_chain, temperature = temperature, &
kineticEnergy = kinetic_energy, potentialEnergy = potential_energy)
total_energy = kinetic_energy + potential_energy
write(*,*) 'INITIAL STEP'
write(*,'(i10,10f17.8)') n0, temperature, kinetic_energy, potential_energy, &
total_energy, qKineticEnergy, qKineticEnergy_v2, qPotentialEnergy, &
qTotalEnergy, qTotalEnergy_v2
write(*,*)
write(20,*) 'INITIAL STEP'
write(20,'(i10,10f17.8)') n0, temperature, kinetic_energy, potential_energy, &
total_energy, qKineticEnergy, qKineticEnergy_v2, qPotentialEnergy, &
qTotalEnergy, qTotalEnergy_v2
write(20,*)
! initialise some quantities
! initialise momentum distributions
! pdistro_o_avrg = zero
! pdistro_h_avrg = zero
! pdistro_h2o_avrg = zero
! sigma_o = dsqrt( boltzmann_k * temperature_target * mass(1) * massConversionFactor )
! sigma_h = dsqrt( boltzmann_k * temperature_target * mass(2) * massConversionFactor )
! mh2o = ( mass(1) + two*mass(2) ) * massConversionFactor
! sigma_h2o = dsqrt( boltzmann_k * temperature_target * mh2o )
! pmax_o = three * sigma_o
! pmax_h = three * sigma_h
! pmax_h2o = three * sigma_h2o
! pmin_o = -pmax_o
! pmin_h = -pmax_h
! pmin_h2o = - pmax_h2o
! deltap_o = (pmax_o-pmin_o)/dfloat(nbinp)
! deltap_h = (pmax_h-pmin_h)/dfloat(nbinp)
! deltap_h2o = (pmax_h2o-pmin_h2o)/dfloat(nbinp)
! initialise averages
temperature_avrg = zero
kinetic_avrg = zero
potential_avrg = zero
totalenergy_avrg = zero
qtotalenergy_avrg = zero
qtotalenergy_v2_avrg = zero
qkinetic_avrg = zero
qkinetic_v2_avrg = zero
qpotential_avrg = zero
kin_avrg = zero
pot_avrg = zero
tote_avrg = zero
qkin_avrg = zero
qkin_v2_avrg = zero
qpot_avrg = zero
qtote_avrg = zero
qtote_v2_avrg = zero
if( nSteps_prod .gt. nblocks_max ) then
nblocks = nblocks_max
else
nblocks = nSteps_prod
end if
dblock = dfloat(nSteps_prod)/dfloat(nblocks)
allocate( ctr_avrg( 3, n_atoms, nblocks ) )
allocate( ctr2_avrg( n_atoms, nblocks ) )
allocate( g2_avrg( n_atoms, nblocks ) )
allocate(rij_block(n_ox,n_ox,nblocks) )
allocate(rij2_block(n_ox,n_ox,nblocks) )
radius2_avrg = zero
radmax2_avrg = zero
gyration2_avrg = zero
r2_avrg = zero
rmax2_avrg = zero
centroid_avrg = zero
centroid2_avrg = zero
ctr_avrg = zero
ctr2_avrg = zero
g2_avrg = zero
rij_block = zero
rij2_block = zero
roh2_avrg = zero
theta_avrg = zero
doh2_avrg = zero
hoh_avrg = zero
density_o_avrg = zero
density_h_avrg = zero
rhor_o_avrg = zero
rhor_h_avrg = zero
rhor_h2o_avrg = zero
goo_avrg = zero
ghh_avrg = zero
goh_avrg = zero
rij = zero
rij2 = zero
! launch dynamics
do n = 1, nSteps
nStep = n0 + n
! advances positions of every replica by a time step, and momenta by half a time step
call BussiParrinello_A( state_chain )
!call velocityVerlet_StateChain_A( state_chain )
! update forces
call computeForces( state_chain, temperature_target, gyration2, centroid )
! with the new forces, uptade the remaining half a time step of momenta for every replica
call BussiParrinello_B( state_chain )
!call velocityVerlet_StateChain_B( state_chain )
! Compute centroid properties and momentum distribution
if ( n.gt. nSteps_equi ) then
if ( mod(n, nperiod_density) .eq. 0 ) then
call CentroidProperties( n_atoms, mass, centroid, radius2, radmax2, roh2, theta, &
rmax_histo = rmax_histo, density_o = density_o, density_h = density_h, &
rhor_o = rhor_o, rhor_h = rhor_h, rhor_h2o = rhor_h2o, &
goo = goo, ghh = ghh, goh = goh)
call MSD(n_atoms, mass, centroid0, centroid, msd_w)
write(88,*) n, msd_w / ang_to_au
! call CentroidProperties( n_atoms, mass, centroid, radius2, roh2, theta, &
! rmax_histo = rmax_histo, &
! rhor_o = rhor_o, rhor_h = rhor_h, rhor_h2o = rhor_h2o, &
! goo = goo, ghh = ghh, goh = goh)
! call calculateMomentumDistro( state_chain, temperature_target, &
! pdistro_o, pdistro_h, pdistro_h2o )
! pdistro_o_avrg = pdistro_o_avrg + pdistro_o
! pdistro_h_avrg = pdistro_h_avrg + pdistro_h
! pdistro_h2o_avrg = pdistro_h2o_avrg + pdistro_h2o
density_o_avrg = density_o_avrg + density_o
density_h_avrg = density_h_avrg + density_h
rhor_o_avrg = rhor_o_avrg + rhor_o
rhor_h_avrg = rhor_h_avrg + rhor_h
rhor_h2o_avrg = rhor_h2o_avrg + rhor_h2o
goo_avrg = goo_avrg + goo
ghh_avrg = ghh_avrg + ghh
goh_avrg = goh_avrg + goh
else
call CentroidProperties( n_atoms, mass, centroid, radius2, radmax2, roh2, theta )
end if
end if ! end if n > nSteps_equi
! instantaneous State information
call inquireStateChain(state_chain, temperature = temperature, &
kineticEnergy = kinetic_energy, potentialEnergy = potential_energy, &
qKineticEnergy = qKineticEnergy, qPotentialEnergy = qPotentialEnergy, &
qKineticEnergy_v2 = qKineticEnergy_v2)
! accumulate averages
if( n.gt.nSteps_equi ) then
gyration2_avrg = gyration2_avrg + gyration2
radius2_avrg = radius2_avrg + radius2
radmax2_avrg = radmax2_avrg + radmax2
centroid_avrg = centroid_avrg + centroid
roh2_avrg = roh2_avrg + roh2
theta_avrg = theta_avrg + theta
do iat = 1, n_atoms
centroid2(iat) = dot_product( centroid(:,iat), centroid(:,iat) )
end do
centroid2_avrg = centroid2_avrg + centroid2
do iox = 1, n_ox
iat = 1 + 3*(iox-1)
do jox = iox + 1, n_ox
! Total average
jat = 1 + 3*(jox-1)
vij = centroid(:,jat) - centroid(:,iat)
dij2 = dot_product( vij, vij )
dij = dsqrt(dij2)
rij(iox,jox) = rij(iox,jox) + dij
rij2(iox,jox) = rij2(iox,jox) + dij2
! Block average
iblock = int( (n-nSteps_equi-1) / dblock ) + 1
rij_block(iox,jox,iblock) = rij_block(iox,jox,iblock) + dij
rij2_block(iox,jox,iblock) = rij2_block(iox,jox,iblock) + dij2
end do
end do
total_energy = kinetic_energy + potential_energy
qTotalEnergy = qKineticEnergy + qPotentialEnergy
qTotalEnergy_v2 = qKineticEnergy_v2 + qPotentialEnergy
temperature_avrg = temperature_avrg + temperature
kinetic_avrg = kinetic_avrg + kinetic_energy
potential_avrg = potential_avrg + potential_energy
totalenergy_avrg = totalenergy_avrg + total_energy
qtotalenergy_avrg = qtotalenergy_avrg + qTotalEnergy
qtotalenergy_v2_avrg = qtotalenergy_v2_avrg + qTotalEnergy_v2
qkinetic_avrg = qkinetic_avrg + qKineticEnergy
qkinetic_v2_avrg = qkinetic_v2_avrg + qKineticEnergy_v2
qpotential_avrg = qpotential_avrg + qPotentialEnergy
iblock = int( (n-nSteps_equi-1) / dblock ) + 1
kin_avrg(iblock) = kin_avrg(iblock) + kinetic_energy
pot_avrg(iblock) = pot_avrg(iblock) + potential_energy
tote_avrg(iblock) = tote_avrg(iblock) + total_energy
qkin_avrg(iblock) = qkin_avrg(iblock) + qKineticEnergy
qkin_v2_avrg(iblock) = qkin_v2_avrg(iblock) + qKineticEnergy_v2
qpot_avrg(iblock) = qpot_avrg(iblock) + qPotentialEnergy
qtote_avrg(iblock) = qtote_avrg(iblock) + qTotalEnergy
qtote_v2_avrg(iblock) = qtote_v2_avrg(iblock) + qTotalEnergy_v2
r2_avrg(iblock) = r2_avrg(iblock) + radius2
rmax2_avrg(iblock) = rmax2_avrg(iblock) + radmax2
doh2_avrg(iblock) = doh2_avrg(iblock) + roh2
hoh_avrg(iblock) = hoh_avrg(iblock) + theta
ctr_avrg(:,:,iblock) = ctr_avrg(:,:,iblock) + centroid(:,:)
ctr2_avrg(:,iblock) = ctr2_avrg(:,iblock) + centroid2(:)
g2_avrg(:,iblock) = g2_avrg(:,iblock) + gyration2(:)
if ( mod(n, nperiod) .eq. 0 ) then
! current values
!write(*,'(i10,10f17.8)') nStep, temperature, kinetic_energy, potential_energy, &
! total_energy, qKineticEnergy, qKineticEnergy_v2, qPotentialEnergy, &
! qTotalEnergy, qTotalEnergy_v2
! accumulated averages
write(20,'(i10,10f17.8)') nStep, &
temperature_avrg / dfloat(n-nSteps_equi), &
kinetic_avrg / dfloat(n-nSteps_equi), &
potential_avrg / dfloat(n-nSteps_equi), &
totalenergy_avrg / dfloat(n-nSteps_equi), &
qkinetic_avrg / dfloat(n-nSteps_equi), &
qkinetic_v2_avrg / dfloat(n-nSteps_equi), &
qpotential_avrg / dfloat(n-nSteps_equi), &
qtotalenergy_avrg / dfloat(n-nSteps_equi), &
qtotalenergy_v2_avrg / dfloat(n-nSteps_equi)
end if
end if ! end if n > nSteps_prod
if ( mod(n,200000) .eq. 0 ) then
call writeRestartChain( state_chain, newrestartFile, nStep )
end if
end do ! end of dynamics
close(88)
! normalize momenta distribution and averages
! norm_po = zero
! norm_ph = zero
! norm_ph2o = zero
! do j = 1, nbinp
! norm_po = norm_po + pdistro_o_avrg(j)*deltap_o
! norm_ph = norm_ph + pdistro_h_avrg(j)*deltap_h
! norm_ph2o = norm_ph2o + pdistro_h2o_avrg(j)*deltap_h2o
! enddo
! pdistro_o_avrg = pdistro_o_avrg / norm_po
! pdistro_h_avrg = pdistro_h_avrg / norm_ph
! pdistro_h2o_avrg = pdistro_h2o_avrg / norm_ph2o
gyration2_avrg = gyration2_avrg / dfloat(nSteps_prod)
radius2_avrg = radius2_avrg / dfloat(nSteps_prod)
radmax2_avrg = radmax2_avrg / dfloat(nSteps_prod)
centroid_avrg = centroid_avrg / dfloat(nSteps_prod)
centroid2_avrg = centroid2_avrg / dfloat(nSteps_prod)
roh2_avrg = roh2_avrg / dfloat(nSteps_prod)
theta_avrg = theta_avrg / dfloat(nSteps_prod)
rij = rij / dfloat(nSteps_prod)
rij2 = rij2 / dfloat(nSteps_prod)
temperature_avrg = temperature_avrg / dfloat(nSteps_prod)
kinetic_avrg = kinetic_avrg / dfloat(nSteps_prod)
potential_avrg = potential_avrg / dfloat(nSteps_prod)
totalenergy_avrg = totalenergy_avrg / dfloat(nSteps_prod)
qtotalenergy_avrg = qtotalenergy_avrg / dfloat(nSteps_prod)
qtotalenergy_v2_avrg = qtotalenergy_v2_avrg / dfloat(nSteps_prod)
qkinetic_v2_avrg = qkinetic_v2_avrg / dfloat(nSteps_prod)
qkinetic_avrg = qkinetic_avrg / dfloat(nSteps_prod)
qpotential_avrg = qpotential_avrg / dfloat(nSteps_prod)
kin_avrg = kin_avrg / dblock
pot_avrg = pot_avrg / dblock
tote_avrg = tote_avrg / dblock
qkin_avrg = qkin_avrg / dblock
qkin_v2_avrg = qkin_v2_avrg / dblock
qpot_avrg = qpot_avrg / dblock
qtote_avrg = qtote_avrg / dblock
qtote_v2_avrg = qtote_v2_avrg / dblock
r2_avrg = r2_avrg / dblock
rmax2_avrg = rmax2_avrg / dblock
doh2_avrg = doh2_avrg / dblock
hoh_avrg = hoh_avrg / dblock
ctr_avrg = ctr_avrg / dblock
ctr2_avrg = ctr2_avrg / dblock
g2_avrg = g2_avrg / dblock
rij_block = rij_block / dblock
rij2_block = rij2_block / dblock
do k = 1, 3
density_o_avrg(k,:,:) = density_o_avrg(k,:,:) / sum( density_o_avrg(k,:,:) )
density_h_avrg(k,:,:) = density_h_avrg(k,:,:) / sum( density_h_avrg(k,:,:) )
end do
rhor_o_avrg(:) = rhor_o_avrg(:) / sum( rhor_o_avrg(:) )
rhor_h_avrg(:) = rhor_h_avrg(:) / sum( rhor_h_avrg(:) )
rhor_h2o_avrg(:) = rhor_h2o_avrg(:) / sum( rhor_h2o_avrg(:) )
goo_avrg(:) = goo_avrg(:) / sum( goo_avrg(:) )
ghh_avrg(:) = ghh_avrg(:) / sum( ghh_avrg(:) )
goh_avrg(:) = goh_avrg(:) / sum( goh_avrg(:) )
! compute statistical errors
sigma_kinetic = zero
sigma_potential = zero
sigma_totalenergy = zero
sigma_qkinetic = zero
sigma_qkinetic_v2 = zero
sigma_qpotential = zero
sigma_qtotalenergy = zero
sigma_qtotalenergy_v2 = zero
sigma_radius2 = zero
sigma_radmax2 = zero
sigma_roh2 = zero
sigma_theta = zero
do iblock = 1, nblocks
sigma_kinetic = sigma_kinetic + ( kin_avrg(iblock) - kinetic_avrg )**two
sigma_potential = sigma_potential + ( pot_avrg(iblock) - potential_avrg )**two
sigma_totalenergy = sigma_totalenergy + ( tote_avrg(iblock) - totalenergy_avrg )**two
sigma_qkinetic = sigma_qkinetic + ( qkin_avrg(iblock) - qkinetic_avrg )**two
sigma_qkinetic_v2 = sigma_qkinetic_v2 + ( qkin_v2_avrg(iblock) - qkinetic_v2_avrg )**two
sigma_qpotential = sigma_qpotential + ( qpot_avrg(iblock) - qpotential_avrg )**two
sigma_qtotalenergy = sigma_qtotalenergy + ( qtote_avrg(iblock) - qtotalenergy_avrg )**two
sigma_qtotalenergy_v2 = sigma_qtotalenergy_v2 + &
( qtote_v2_avrg(iblock) - qtotalenergy_v2_avrg )**two
sigma_radius2 = sigma_radius2 + ( r2_avrg(iblock) - radius2_avrg )**two
sigma_radmax2 = sigma_radmax2 + ( rmax2_avrg(iblock) - radmax2_avrg )**two
sigma_roh2 = sigma_roh2 + ( doh2_avrg(iblock) - roh2_avrg )**two
sigma_theta = sigma_theta + ( hoh_avrg(iblock) - theta_avrg )**two
end do
sigma_kinetic = dsqrt( sigma_kinetic / dfloat(nblocks) )
sigma_potential = dsqrt( sigma_potential / dfloat(nblocks) )
sigma_totalenergy = dsqrt( sigma_totalenergy / dfloat(nblocks) )
sigma_qkinetic = dsqrt( sigma_qkinetic / dfloat(nblocks) )
sigma_qkinetic_v2 = dsqrt( sigma_qkinetic_v2 / dfloat(nblocks) )
sigma_qpotential = dsqrt( sigma_qpotential / dfloat(nblocks) )
sigma_qtotalenergy = dsqrt( sigma_qtotalenergy / dfloat(nblocks) )
sigma_qtotalenergy_v2 = dsqrt( sigma_qtotalenergy_v2 / dfloat(nblocks) )
sigma_radius2 = dsqrt( sigma_radius2 / dfloat(nblocks) )
sigma_radmax2 = dsqrt( sigma_radmax2 / dfloat(nblocks) )
sigma_roh2 = dsqrt( sigma_roh2 / dfloat(nblocks) )
sigma_theta = dsqrt( sigma_theta / dfloat(nblocks) )
! outputs
! ! momenta distribution
! open(unit=21, file="pdistro-o.dat")
! open(unit=22, file="pdistro-h.dat")
! open(unit=23, file="pdistro-h2o.dat")
! ! p distribution of oxygens
! do j = 1, nbinp
! pc = pmin_o + (dfloat(j)-half)*deltap_o
! gaussian = one / dsqrt( two * pi ) / sigma_o * dexp( -pc*pc /two /sigma_o**two )
! write(21,*) pc, pdistro_o_avrg(j), gaussian
! end do
! ! p distribution of hydrogens
! do j = 1, nbinp
! pc = pmin_h + (dfloat(j)-half)*deltap_h
! gaussian = one / dsqrt( two * pi ) / sigma_h * dexp( -pc*pc /two /sigma_h**two )
! write(22,*) pc, pdistro_h_avrg(j), gaussian
! end do
! ! p distribution of water molecules
! do j = 1, nbinp
! pc = pmin_h2o + (dfloat(j)-half)*deltap_h2o
! gaussian = one / dsqrt( two * pi ) / sigma_h2o * dexp( -pc*pc /two /sigma_h2o**two )
! write(23,*) pc, pdistro_h2o_avrg(j), gaussian
! end do
! close(21)
! close(22)
! close(23)
! Final averages
write(20,*)
write(20,*) 'Temperature average:', temperature_avrg / temperature_target
!write(*,*) 'Kinetic energy average:', kinetic_avrg / ( three / two * kT ) / dfloat(nReplicas)
!write(*,*) 'Potential energy average:', potential_avrg / ( three / two * kT ) / &
! dfloat(nReplicas)
if (nReplicas.gt.1) then
write(20,*)
write(20,*) 'Quantum energies per molecule (in kcalmol)'
write(20,*) 'Total:', qtotalenergy_avrg / dfloat(n_mols) / kcalmol_to_au, &
sigma_qtotalenergy / dfloat(n_mols) / kcalmol_to_au
write(20,*) 'Total_v2:', qtotalenergy_v2_avrg / dfloat(n_mols) / kcalmol_to_au, &
sigma_qtotalenergy_v2 / dfloat(n_mols) / kcalmol_to_au
write(20,*) 'Kinetic:', qkinetic_avrg / dfloat(n_mols) / kcalmol_to_au, &
sigma_qkinetic / dfloat(n_mols) / kcalmol_to_au
write(20,*) 'Kinetic_v2:', qkinetic_v2_avrg / dfloat(n_mols) / kcalmol_to_au, &
sigma_qkinetic_v2 / dfloat(n_mols) / kcalmol_to_au
write(20,*) 'Potential:', qpotential_avrg / dfloat(n_mols) / kcalmol_to_au, &
sigma_qpotential / dfloat(n_mols) / kcalmol_to_au
end if
write(20,*)
write(20,*) 'Extended system classical energies per molecule (in kcalmol)'
write(20,*) 'Total:', totalenergy_avrg / dfloat(n_mols) / kcalmol_to_au, &
sigma_totalenergy / dfloat(n_mols) / kcalmol_to_au
write(20,*) 'Kinetic:', kinetic_avrg / dfloat(n_mols) / kcalmol_to_au, &
sigma_kinetic / dfloat(n_mols) / kcalmol_to_au
write(20,*) 'Potential:', potential_avrg / dfloat(n_mols) / kcalmol_to_au, &
sigma_potential / dfloat(n_mols) / kcalmol_to_au
! squared mean radius and gyration radius
write(20,*)
write(20,*) 'Squared mean radius (in Angstrom)'
write(20,*) dsqrt(radius2_avrg) / ang_to_au, &
half / dsqrt(radius2_avrg) * sigma_radius2 / ang_to_au
write(20,*) 'Root mean square max radius of the cluster (in Angstrom)'
write(20,*) dsqrt(radmax2_avrg) / ang_to_au, &
half / dsqrt(radmax2_avrg) * sigma_radmax2 / ang_to_au
if ( nReplicas.gt.1 ) then
! Mean gyration radius
gyration2_o_avrg = zero
gyration2_h_avrg = zero
do imol = 1, n_mols
do j = 1, 3
iat = j + 3*(imol-1)
if (j.eq.1) then
gyration2_o_avrg = gyration2_o_avrg + gyration2_avrg(iat)
else
gyration2_h_avrg = gyration2_h_avrg + gyration2_avrg(iat)
end if
end do
end do
gyration2_o_avrg = gyration2_o_avrg / dfloat( n_mols )
gyration2_h_avrg = gyration2_h_avrg / ( two*dfloat(n_mols) )
! Uncertainty
sigma_gyration2_o = zero
sigma_gyration2_h = zero
do iblock = 1, nblocks
! Gyration radius of each block
gyration2_o = zero
gyration2_h = zero
do imol = 1, n_mols
do j = 1, 3
iat = j + 3*(imol-1)
if (j.eq.1) then
gyration2_o = gyration2_o + g2_avrg(iat,iblock)
else
gyration2_h = gyration2_h + g2_avrg(iat,iblock)
end if
end do
end do
gyration2_o = gyration2_o / dfloat( n_mols )
gyration2_h = gyration2_h / ( two*dfloat(n_mols) )
! Accumulate deviation
sigma_gyration2_o = sigma_gyration2_o + ( gyration2_o - gyration2_o_avrg )**two
sigma_gyration2_h = sigma_gyration2_h + ( gyration2_h - gyration2_h_avrg )**two
end do
sigma_gyration2_o = dsqrt( sigma_gyration2_o / dfloat(nblocks) )
sigma_gyration2_h = dsqrt( sigma_gyration2_h / dfloat(nblocks) )
! Error(R) = 1 / (2 * R ) * Error(R^2)