-
Notifications
You must be signed in to change notification settings - Fork 0
/
Vscan1D.f90
executable file
·268 lines (251 loc) · 8.95 KB
/
Vscan1D.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
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! Program : !
! Produce a serious of structure along a selected !
! reaction coordinate. !
! Input : !
! $1 = Gaussian/Qchem output file; initial structure !
! LM !
! $2 = vector (xyz coordinate) !
! $3 = boundary condition !
! formate of $3 !
! $1=upper BC ; postive integer !
! # of steps in the positive direction !
! $2=lower BC ; positive integer !
! # of step2 in the negative direction !
! $3=# of interval ; positive integer !
! interval=1/$3 !
! i.e. $3=10 ; interval=1/10=0.1 angstrom !
! NM !
! $2 = boundary condition !
! Output : !
! PES.xyz; it can be used in Jmol. !
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
! 2016/04/12, Grace, 1st. ver.
! 2017/10/23, Grace, 2nd. ver. modify input and auxiliary scripts
Program main
implicit none
LOGICAL :: RxnCoord
character(len=100) :: input
integer(4) :: i,NAtoms
real(8),allocatable,dimension(:,:) :: Coord,Vec,Delta
integer(4),dimension(3) :: BC
! The output file of qchem record the atom name as character
character(len=2),allocatable,dimension(:) :: AtomName
! Step 0. Std-out the purpose of this program, and check the
! status of input files.
call print_purpose()
call get_RxnCoord(RxnCoord)
! Step 1. Extract the coordinate and boundary from input file
call GETARG(1,input)
call SYSTEM('getCoord '//TRIM(input)//' initial.xyz')
open(10,file='initial.xyz',status='old',action='read')
read(10,*) NAtoms
read(10,*) input ! this is buffer
allocate(Coord(NAtoms,3))
allocate(AtomName(NAtoms))
allocate(Vec(NAtoms,3))
allocate(Delta(NAtoms,3))
call get_coord(NAtoms,Coord,AtomName)
close(10)
if (RxnCoord) then
! Normal mode
write(*,'(A)') 'Normal mode is not finish yet'
stop ! not yet, 2017/10/24
else
! Local mode; full local mode
call GETARG(2,input)
call get_LM(input,NAtoms,Coord,Vec)
end if
call GETARG(3,input)
open(10,file=input,status='old',action='read')
read(10,*) BC(1:3)
close(10)
! Calculate the interval vector, delta.
do i=1,NAtoms
Delta(i,1)=Vec(i,1)/BC(3)
Delta(i,2)=Vec(i,2)/BC(3)
Delta(i,3)=Vec(i,3)/BC(3)
end do
! Step 2. Construct a serious of structures and then write them
! into the pes.txt file
call write_pes(NAtoms,AtomName,Coord,BC,Delta)
end program main
subroutine print_purpose()
implicit none
write(*,'()')
write(*,'(A)') '-------------------------------------------------'
write(*,'(A)') 'Program Vscan1D produces a serious of structure'
write(*,'(A)') 'along a given reaction coordinate.'
write(*,'(A)') '-------------------------------------------------'
write(*,'()')
write(*,'(A)') 'Auxiliary script and file'
write(*,'(A)') '1. script: getCoord'
write(*,'(A)') ' output: coord.xyz'
write(*,'(A)') ' (afford Gaussian/QChem jobs, 2017/10/23)'
write(*,'(A)') '2. script: getNM'
write(*,'(A)') ' output: NM.dat'
write(*,'(A)') ' (afford QChem jobs only, 2017/10/23)'
write(*,'()')
write(*,'(A)') 'Final output: PES.xyz'
write(*,'(A)') ' (it can be visualized by Jmol)'
write(*,'()')
return
end subroutine print_purpose
subroutine get_RxnCoord(RxnCoord)
implicit none
LOGICAL,intent(out) :: RxnCoord
integer(4) :: i,num
num = IARGC()
if ( num .eq. 2) then
! Normal mode
RxnCoord = .true.
else if (num .eq. 3) then
! Local mode
RxnCoord = .false.
else
write(*,'(A)') 'Wrong amount of input arguments, stop!'
STOP
end if
do i = 1,num ! check the input file status
call check_file(i)
end do
return
end subroutine get_RxnCoord
subroutine check_file(num)
implicit none
integer(4),intent(in) :: num
character(len=100) :: input
LOGICAL :: filestat
call GETARG(num,input)
INQUIRE(file=input,exist=filestat)
if (filestat) then
open(10,file=input,status='old',action='read')
else
write(*,'(A)') TRIM(input)//" doesn't exist"
stop
end if
return
end subroutine check_file
subroutine get_coord(NAtoms,Coord,AtomName)
implicit none
integer(4),intent(in) :: NAtoms
real(8),intent(inout),dimension(NAtoms,3) :: Coord
character(len=2),intent(inout),dimension(NAtoms) :: AtomName
!local variable
integer(4) :: i
do i=1,NAtoms
read(10,*) AtomName(i),Coord(i,1:3)
end do
return
end subroutine get_coord
! two sub-category: full LM and partial LM
subroutine get_LM(input,NAtoms,Coord,Vec)
implicit none
character(len=100),intent(in) :: input
integer(4),intent(in) :: NAtoms
real(8),dimension(NAtoms,3),intent(in) :: Coord
real(8),dimension(NAtoms,3),intent(inout) :: Vec
character(len=100) :: buffer
real(8),dimension(NAtoms,3) :: Coord_final
integer(4) :: i,j,Mode,n
real(4),allocatable,dimension(:) :: movingAtom
write(*,'(A)') 'Is the final state a Gaussian/Qchem output? (y/n)'
read(*,*) buffer
if ( buffer .eq. 'y') then
call SYSTEM('getCoord '//TRIM(input)//' final.xyz')
open(10,file='final.xyz',status='old',action='read')
else if ( buffer .eq. 'n' ) then
open(10,file=input,status='old',action='read')
else
write(*,'(A)') 'Wrong typing! Stop.'
STOP
end if
read(10,*) buffer
read(10,*) buffer
do i=1,NAtoms
read(10,*) buffer,Coord_final(i,1:3)
end do
write(*,'()')
write(*,'(A)') 'This reaction coordinate follow local mode (LM)'
write(*,'()')
write(*,'(A)') 'The order of atom for initial and final'
write(*,'(A)') 'molecules must be the same!'
write(*,'()')
write(*,'(A)') 'Which mode do you prefer: (1 or 2)'
write(*,'(A)') '1. Full LM: move all atoms '
write(*,'(A)') '2. Partial LM: assign certain atom(s)'
read(*,*) Mode
Vec(:,:) = 0.0D0
if ( Mode .eq. 1) then
do i = 1,NAtoms
do j = 1,3
Vec(i,j) = Coord_final(i,j) - Coord(i,j)
end do
end do
else if ( Mode .eq. 2 ) then
write(*,'(A)',advance='no') 'How many atom: '
read(*,*) n
allocate(movingAtom(n))
do i = 1,n
write(*,'(A)') 'Please assign the index of moving atom'
read(*,*) movingAtom(i)
do j = 1, 3
Vec(movingAtom(i),j) = Coord_final(movingAtom(i),j) - Coord(movingAtom(i),j)
end do
end do
end if
close(10)
return
end subroutine get_LM
subroutine write_pes(NAtoms,AtomName,Coord,BC,Delta)
implicit none
integer(4),intent(in) :: NAtoms
character(len=2),intent(inout),dimension(NAtoms) :: AtomName
real(8),dimension(NAtoms,3),intent(in) :: Coord,Delta
integer(4),dimension(3),intent(in) :: BC
integer(4) :: i,j,k
real(8),dimension(NAtoms,3) :: Coord_tmp
real(8) :: indexR ! in order to print the coordinate
character(len=100) :: buffer
open(10,file='PES.xyz',status='replace')
! Upper boundary
do i=BC(1),1,-1
do j=1,NAtoms
do k=1,3
Coord_tmp(j,k)=Coord(j,k)+i*Delta(j,k)
end do
end do
! write the structure into file, coord.txt
write(10,'(I2)') NAtoms
indexR=0.0D0+i*1.0D0/BC(3)
write(10,'(F7.4)') indexR
do j=1,NAtoms
write(10,'(A2,1X,3(F13.10,1X))') AtomName(j),Coord_tmp(j,1:3)
end do
end do
! Original point
write(10,'(I2)') NAtoms
write(10,'(A)') '0.0000'
do i=1,NAtoms
write(10,'(A2,1X,3(F13.10,1X))') AtomName(i),Coord(i,1:3)
end do
! Lower boundary
do i=1,BC(2)
do j=1,NAtoms
do k=1,3
Coord_tmp(j,k)=Coord(j,k)-i*Delta(j,k)
end do
end do
! write the structure into file, coord.txt
write(10,'(I2)') NAtoms
indexR=0.0D0-i*1.0D0/BC(3)
! linux bug that it cannot recognize the negative sign
write(buffer,'(F7.4)') indexR
write(10,'(A)') 'n'//TRIM(ADJUSTL(buffer))
do j=1,NAtoms
write(10,'(A2,1X,3(F13.10,1X))') AtomName(j),Coord_tmp(j,1:3)
end do
end do
close(10)
return
end subroutine write_pes