-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathNormalModes.f90
executable file
·343 lines (293 loc) · 11.8 KB
/
NormalModes.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
!-----------------------------------------------------------------------------------
!-----------------Normal mode calculation module -----------------------------------
!-----------------This module is self contained ------------------------------------
!-----------------------------------------------------------------------------------
! Copyright (c) 2014 Daniel C. Elton
!
! This software is licensed under The MIT License (MIT)
! Permission is hereby granted, free of charge, to any person obtaining a copy of this
! software and associated documentation files (the "Software"), to deal in the Software
! without restriction, including without limitation the rights to use, copy, modify, merge,
! publish, distribute, sublicense, and/or sell copies of the Software, and to permit
! persons to whom the Software is furnished to do so, subject to the following conditions:
!
! The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
!
! THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
! BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
! NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
! DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
! OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
!-------------------------------------------------------------------------------------
module NormalModes
use consts
Implicit none
double precision, dimension(:), allocatable, save :: A11, A12, A21, A22
double precision, dimension(:), allocatable, save :: omegalist, MassScaleFactor
double precision, dimension(:,:), allocatable, save :: C
contains
!---------------------------------------------------------------------
!----------- Evolve one ring a time period delta --------------------
!---------------------------------------------------------------------
subroutine EvolveRing(RR, PP, Nbeads, mass)
Implicit none
double precision, dimension(3,Nbeads), intent(inout) :: RR, PP
double precision, dimension(3,Nbeads) :: RRtr, PPtr
double precision, dimension(3) :: temp2
double precision, intent(in) :: mass
integer, intent(in) :: Nbeads
integer :: i, j, k
!Transform into normal mode representation
RRtr = real2NM(RR,Nbeads)
PPtr = real2NM(PP,Nbeads)
!Propagate Normal Modes
!j = the normal mode index. The number of normal modes always equals the number of beads
do j = 1, Nbeads
!The normal mode evolution is simply the evolution of a harmonic oscillator
!The matrix elements of the propagation matrix are stored in Aij(j) (minus the mass terms)
!this may not be the best way to do this , but ... I wanted to avoid matrix multiplication
temp2 = A11(j)*RRtr(:,j) + A12(j)*PPtr(:,j)/(mass*MassScaleFactor(j))
PPtr(:,j) = A21(j)*mass*MassScaleFactor(j)*RRtr(:,j) + A22(j)*PPtr(:,j)
RRtr(:,j) = temp2
enddo
!Transform normal modes back into real space
RR = NM2real(RRtr,Nbeads)
PP = NM2real(PPtr,Nbeads)
end subroutine EvolveRing
!--------------------------------------------------------------------------
!------------ Initialize Normal Mode matrices ----------------------------
!--------------------------------------------------------------------------
subroutine InitNormalModes(Nbeads,omegan,delta,setNMfreq, lunTP_out)
use consts
Implicit None
double precision, intent(in) :: omegan, delta, setNMfreq
double precision :: omega
integer, intent(in) :: Nbeads
integer :: i, j, k, l, lunTP_out
allocate(A11(Nbeads))
allocate(A12(Nbeads))
allocate(A21(Nbeads))
allocate(A22(Nbeads))
allocate(omegalist(Nbeads))
allocate(MassScaleFactor(Nbeads))
allocate(C(Nbeads,Nbeads))
if (mod(Nbeads,2) .eq. 0) then
l = (Nbeads-2)/2 !even Nbeads case
else
l = (Nbeads-1)/2 !odd Nbeads case
endif
!---------------- construct matrix --------------------------------------------
!The modes are stored in the following order:
!--zero mode
!--negative modes
!--positive modes
!--extra mode for when Nbeads is even
! This is maybe a bit confusing to index when generating the matrix,
! etc, but is a nice ordering for later on.
do i = 1, Nbeads !i = column index
C(1,i) = Sqrt(1d0/Nbeads) !zero mode
do k = 1, l
C(k+1 ,i) = Sqrt(2d0/Nbeads)*Cos(k*i*2d0*PI/Nbeads) !-k modes
C(k+l+1,i) = Sqrt(2d0/Nbeads)*Sin(k*i*2d0*PI/Nbeads) !+k modes
enddo
!extra mode for even Nbeads case only
if (mod(Nbeads,2) .eq. 0) then
C(2*l+2,i) = Sqrt(1d0/Nbeads)*((-1)**i)
endif
enddo
!-------------- RPMD frequencies (setNMfreq = 0) --------------------------------------
!-------------- This case is always done for reference --------------------------------
!correct omega=0 mode for the omega-> 0 limit
omegalist(1) = 0d0
A11(1) = 1d0
A12(1) = delta
A21(1) = 0d0
A22(1) = 1d0
!negative k modes
do k = 1,l
omega = 2*omegan*Sin(PI*( abs(k)/real(Nbeads)) )
omegalist(k+1) = omega
A11(k+1) = Cos(omega*delta)
A12(k+1) = (1/omega)*Sin(omega*delta)
A21(k+1) = -omega*Sin(omega*delta)
A22(k+1) = Cos(omega*delta)
enddo
!positive k modes
do k = 1,l
omega = 2*omegan*Sin(PI*( abs(k)/real(Nbeads)) )
omegalist(k+l+1) = omega
A11(k+l+1) = Cos(omega*delta)
A12(k+l+1) = (1/omega)*Sin(omega*delta)
A21(k+l+1) = -omega*Sin(omega*delta)
A22(k+l+1) = Cos(omega*delta)
enddo
!extra mode for even Nbeads case only
if (mod(Nbeads,2) .eq. 0) then
k = l+1
omega = 2*omegan*Sin(PI*( abs(k)/real(Nbeads)) )
omegalist(2*l + 2) = omega
A11(2*l+2) = Cos(omega*delta)
A12(2*l+2) = (1/omega)*Sin(omega*delta)
A21(2*l+2) = -omega*Sin(omega*delta)
A22(2*l+2) = Cos(omega*delta)
endif
MassScaleFactor = 1
if (setNMfreq .eq. 0) then
write(lunTP_out,*) "Running usuing RPMD. All beads have physical mass."
write(lunTP_out,*) "Normal mode frequencies: (cm^-1)"
do k = 1,Nbeads
omega = omegalist(k)
write(lunTP_out,'(f10.2)') 33.33333d0*omega/(2*PI)
enddo
endif
!------------------------- ACMD / CMD / PIMD case (adiabaticity > 1) ------------------------------------
if (.not. (setNMfreq .eq. 0)) then
!correct omega=0 mode for the omega-> 0 limit
omegalist(1) = 0d0
A11(1) = 1d0
A12(1) = delta
A21(1) = 0d0
A22(1) = 1d0
omega = (2*PI)*setNMfreq/33.33333d0 !conv. cm-1 -> 1/ps
do i = 1,Nbeads
if (omegalist(i) == 0) then
MassScaleFactor(i) = 1d0
else
MassScaleFactor(i) = (omegalist(i)/omega)**2
endif
!write(lunTP_out,*) "mass scale factor", i, " = ", massScaleFactor(i)
enddo
write(lunTP_out,*) "Adiabaticity = ", omegan/omega
write(lunTP_out,'(a,f8.3,a8,f10.2,a6)') "All normal modes scaled to ", omega/(2*PI), " 1/ps = ", 33.33333d0*omega/(2*PI), " cm^-1"
write(lunTP_out,'(a,f8.2,a)') "Timestep should probably not be larger than ", (((2*PI)/omega)/4d0)*1000, " fs"
omegalist(2:2*l+1) = omega
A11(2:2*l+1) = Cos(omega*delta)
A12(2:2*l+1) = (1/omega)*Sin(omega*delta)
A21(2:2*l+1) = -omega*Sin(omega*delta)
A22(2:2*l+1) = Cos(omega*delta)
!extra mode for even Nbeads case only
if (mod(Nbeads,2) .eq. 0) then
omegalist(2*l + 2) = omega
A11(2*l+2) = Cos(omega*delta)
A12(2*l+2) = (1/omega)*Sin(omega*delta)
A21(2*l+2) = -omega*Sin(omega*delta)
A22(2*l+2) = Cos(omega*delta)
endif
endif
!check for resonances
do i = 1, Nbeads
if ( abs(1/delta - omegalist(i)/TWOPI)/(1/delta) .lt. .01 ) then
write(lunTP_out,'(a,i2,a)') "WARNING: normal mode frequency", i, " differs from 1/timestep by less than 1 percent"
write(lunTP_out,'(a,f10.4,a,f10.4)') "WARNING: Normal mode frequency ", i, " = ", omegalist(i)/TWOPI, " 1/timestep = ", 1/delta
write(lunTP_out,*) "WARNING: You may encounter resonances which cause the simulation to fail"
endif
enddo
end subroutine InitNormalModes
!-----------------------------------------------------------------------------------------
!---------------- generate one ring polymer sampled from the-----------------------------
!---------------- free ring distribution at temperature T -------------------------------
!-----------------------------------------------------------------------------------------
subroutine gen_rand_ring(RR,mass,temp,Nbeads)
use math
Implicit None
double precision, parameter :: hbar=6.35077993041d0 !hbar in amu*ang^2/ps
double precision, parameter :: KB_amuA2ps2perK = .831447148d0
double precision, dimension(3,Nbeads), intent(out) :: RR
double precision, dimension(3,Nbeads) :: RRtr
double precision, intent(in) :: mass, temp
double precision :: std_dev, omega, omegan
integer :: j, k, l
integer, intent(in) :: Nbeads
omegan = KB_amuA2ps2perK*temp*Nbeads/hbar
do j = 1,Nbeads
omega = omegalist(j)
if (omega .eq. 0d0) then
RRtr(:,j) = 0d0
else
std_dev = Sqrt((omegan*hbar)/(mass*MassScaleFactor(j)*omega**2))
RRtr(:,j) = (/ rand_norm(std_dev), rand_norm(std_dev), rand_norm(std_dev) /)
endif
enddo
RR = NM2real(RRtr, Nbeads)
end subroutine gen_rand_ring
!-----------------------------------------------------------------------------------------
!---------------- generage one ring polymer momenta from the-----------------------------
!---------------- free ring distribution at temperature T -------------------------------
!-----------------------------------------------------------------------------------------
subroutine gen_rand_ring_momenta(PP,mass,temp,Nbeads)
use math
Implicit None
double precision, parameter :: KB_amuA2ps2perK = .831447148d0
double precision, dimension(3,Nbeads), intent(out) :: PP
double precision, dimension(3,Nbeads) :: PPtr
double precision, intent(in) :: mass, temp
integer :: j, k
integer, intent(in) :: Nbeads
do j = 1,Nbeads
do k = 1, 3
PPtr(k,j) = rand_norm(Sqrt(KB_amuA2ps2perK*mass*MassScaleFactor(j)*temp))
enddo
enddo
PP = NM2real(PPtr, Nbeads)
end subroutine gen_rand_ring_momenta
!---------------------------------------------------------------------
!------------ generate initial coordinates for a pure normal mode ---
!------------ (extra code for testing / visualization) --------------
!---------------------------------------------------------------------
!
!subroutine MakeNormalMode(RR, i, Nbeads)
! Implicit none
! double precision, dimension(3,Nbeads), intent(out) :: RR
! double precision, dimension(3,Nbeads) :: RRtr
! integer, intent(in) :: i, Nbeads
! integer :: j,k
!
! RRtr = 0
! RRtr(:,i) = 6d0
!
! do j = 1,Nbeads
! do k = 1, Nbeads
! RR(1,j) = RR(1,j) + C(k,j)*RRtr(1,k)
! RR(2,j) = RR(2,j) + C(k,j)*RRtr(2,k)
! RR(3,j) = RR(3,j) + C(k,j)*RRtr(3,k)
! enddo
! enddo
!
!end subroutine MakeNormalMode
!---------------------------------------------------------------------
!-------------------- convert real to normal mode coordinates --------
!---------------------------------------------------------------------
function real2NM(AA,Nbeads)
Implicit none
double precision, dimension(3,Nbeads), intent(in) ::AA
double precision, dimension(3,Nbeads) :: real2NM
integer, intent(in) :: Nbeads
integer :: j, k
real2NM = 0
do j = 1,Nbeads
do k = 1, Nbeads
real2NM(1,j) = real2NM(1,j) + C(j,k)*AA(1,k)
real2NM(2,j) = real2NM(2,j) + C(j,k)*AA(2,k)
real2NM(3,j) = real2NM(3,j) + C(j,k)*AA(3,k)
enddo
enddo
end function real2NM
!---------------------------------------------------------------------
!-------------------- normal mode to real coordinates ----------------
!---------------------------------------------------------------------
function NM2real(AAtr, Nbeads)
Implicit none
double precision, dimension(3,Nbeads), intent(in) :: AAtr
double precision, dimension(3,Nbeads) :: NM2real
integer, intent(in) :: Nbeads
integer :: j, k
NM2real = 0
do j = 1,Nbeads
do k = 1, Nbeads
NM2real(1,j) = NM2real(1,j) + C(k,j)*AAtr(1,k)
NM2real(2,j) = NM2real(2,j) + C(k,j)*AAtr(2,k)
NM2real(3,j) = NM2real(3,j) + C(k,j)*AAtr(3,k)
enddo
enddo
end function NM2real
end module