-
Notifications
You must be signed in to change notification settings - Fork 0
/
intcoords.f90
477 lines (416 loc) · 11.7 KB
/
intcoords.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
! analyse bonds,angles,dihedral deviations
! 2 task are handled:
! 1) 'all' unique bonds/angles/torsions. detailed output in *.dat files
! 2) user defined bonds/angles/torsions.
subroutine analyse_primitives(mol1,mol2,basename)
use parm
use constant, only: au2ang
use internals
use logic, only: thresh_bond,thresh_ang,thresh_tor, excludeH
use omp_lib
use atomdata,only: el
implicit none
type(molecule) :: mol1,mol2
integer bond(nat,nat),kk
real(8) s,db(nat),x,rab,xs
real(8) ang1,ang2,anggrad1,anggrad2
integer ii,jj
integer io,tot,it
integer iat(nat)
real(8) dummy(max_dummy),thresh
real(8), allocatable :: tvec(:)
character(*) basename
character(200) file_out
!character(2) esym
print*,'************************'
print*,'* PRIMITIVE ANALYSIS *'
print*,'************************'
file_out=trim(basename)//'_internals.dat'
print*,' Output: ',trim(file_out)
dummy=0
! bonding from molecule 1
call bondmatrix(mol1%xyz,mol1%iat,bond)
call read_intcoord('struca.control',mol1%xyz)
if(excludeH) print*,'* IGNORING ALL H-ATOMS *'
print*,'******************'
print*,'* BOND LENGTHS *'
print*,'******************'
thresh=thresh_bond
!open(newunit=io,file='bonds.dat')
open(newunit=io,file=file_out)
k=0
s=0
kk=0
do i=1,nat-1
do j=i+1,nat
k=k+1
if(excludeH.and.mol1%iat(i)==1) cycle
if(excludeH.and.mol1%iat(j)==1) cycle
if(i==j) cycle
if(bond(i,j)==1) then
kk=kk+1
x=mol1%dist(k)-mol2%dist(k)
s=s+x
dummy(kk)=x
if(abs(x)>=thresh) then
write(io,'(a,x,I5,''['',a2,'']'',I5,''['',a2,'']'',x,F8.4,a3)'),'delta_bond',i,el(mol1%iat(i)),j,el(mol2%iat(j)),x,' * '
else
write(io,'(a,x,I5,''['',a2,'']'',I5,''['',a2,'']'',x,F8.4)'),'delta_bond',i,el(mol1%iat(i)),j,el(mol2%iat(j)),x
endif
endif
enddo
enddo
if(int_nb>0) print*,' custom bonds: '
do i=1,int_nb
ii=int_bcast(i,1)
jj=int_bcast(i,2)
x=int_bval(i)-rab(mol2%xyz(1,ii),mol2%xyz(1,jj))
kk=kk+1
dummy(kk)=x
write(*,'(2x,a,x,I5,''['',a2,'']'',I5,''['',a2,'']'',x,F8.4,a3)'),'delta_bond',ii,el(mol1%iat(ii)),jj,el(mol2%iat(jj)),x
enddo
print*,''
!tot=int_nb+kk
!tot=kk+int_nb
tot=kk
allocate(tvec(tot))
tvec=0d0
tvec(1:tot)=dummy(1:tot)
print*, ' # covalent bonds ', kk
print'(a,F8.4)',' mean abs bond deviation [A] : ', sum(abs(tvec))/dble(kk)
print'(a,F8.4)',' mean bond deviation [A] : ', sum(tvec)/dble(kk)
print'(a,F8.4)',' max (+) deviation [A] : ', maxval(tvec)
print'(a,F8.4)',' max (-) deviation [A] : ', minval(tvec)
print'(a,F8.4)',' deviation range [A] : ', maxval(tvec)-minval(tvec)
!close(io)
!print'(2x,a,F6.2,a)','|deviations| above ',thresh,' A are marked (*)'
print'(2x,a,F6.2,a)','|deviations| above ',thresh,' A are marked (*) '
!do i=1,tot
! if(abs(tvec(i))>=thresh) then
! print '(1x,a,x,2(I4,x),F8.2)',tvec(i)
! print '(1x,x,F8.3)',tvec(i)
! endif
!enddo
!call print_threshold(tot,tvec,0.1d0)
deallocate(tvec)
print*,'******************'
print*,'* VALENCE ANGLES *'
print*,'******************'
thresh=thresh_ang
!open(newunit=io,file='angles.dat')
dummy=0d0
s=0
kk=0
do i=1,nat-1
if(excludeH.and.mol1%iat(i)==1) cycle
do j=1,nat
if(excludeH.and.mol1%iat(j)==1) cycle
ii=nat*(i-1)+j
if(i==j) cycle
do k=i+1,nat
if(excludeH.and.mol1%iat(k)==1) cycle
jj=nat*(j-1)+l
if(k==j.or.k==i) cycle
if(bond(i,j)==1.and.bond(j,k)==1) then
kk=kk+1
call angle(mol1%xyz,i,j,k,ang1,anggrad1)
call angle(mol2%xyz,i,j,k,ang2,anggrad2)
x=anggrad1-anggrad2
dummy(kk)=x
s=s+abs(x)
if(abs(x)>=thresh) then
write(io,'(a,x,3(I5,''['',a2,'']''),x,F8.4,a)'),'delta_angle',i,el(mol1%iat(i)),j,el(mol2%iat(j)),k,el(mol1%iat(k)),x,' * '
else
write(io,'(a,x,3(I5,''['',a2,'']''),x,F8.4)'),'delta_angle',i,el(mol1%iat(i)),j,el(mol2%iat(j)),k,el(mol1%iat(k)),x
endif
endif
enddo
enddo
enddo
!ToDo: custom angles
if(int_na>0) print*,' custom angless: '
do it=1,int_na
i=int_acast(it,1)
j=int_acast(it,2)
k=int_acast(it,3)
call angle(mol2%xyz,i,j,k,ang2,anggrad2)
x=int_aval(i)-anggrad2
kk=kk+1
dummy(kk)=x
write(*,'(2x,a,x,3(I5,''['',a2,'']''),x,F8.4)'),'delta_angle',i,el(mol1%iat(i)),j,el(mol1%iat(j)),k,el(mol1%iat(k)),x
enddo
print*,''
tot=kk
allocate(tvec(tot))
tvec=0d0
tvec(1:tot)=dummy(1:tot)
if(kk>1) then
print*, ' # valence angles ', kk
!print'(a,F8.1)',' mean abs angle deviation [deg] : ', s/dble(kk)
print'(a,F8.1)',' mean abs angle deviation [deg] : ', sum(abs(tvec))/dble(kk)
print'(a,F8.1)',' mean angle deviation [deg] : ', sum(tvec)/dble(kk)
print'(a,F8.1)',' max (+) deviation [deg] : ', maxval(tvec)
print'(a,F8.1)',' max (-) deviation [deg] : ', minval(tvec)
print'(a,F8.1)',' deviation range [deg] : ', maxval(tvec)-minval(tvec)
!print*, ' output: angles.dat'
print'(2x,a,F6.2,a)','|deviations| above ',thresh,' deg are marked (*) '
!close(io)
endif
deallocate(tvec)
print*,'******************'
print*,'* TORSIONS *'
print*,'******************'
thresh=thresh_tor
!open(newunit=io,file='torsions.dat')
dummy=0d0
! checking for bonds earlier is obviously MUCH faster :-)
s=0
kk=0
do i=1,nat-1
if(excludeH.and.mol1%iat(i)==1) cycle
do j=1,nat
if(excludeH.and.mol1%iat(j)==1) cycle
if(i==j) cycle
if(bond(i,j)==0) cycle
do k=1,nat
ii=nat*(i-1)*k
if(k==j.or.k==i) cycle
if(excludeH.and.mol1%iat(k)==1) cycle
if(bond(j,k)==0) cycle
do l=i+1,nat
if(excludeH.and.mol1%iat(l)==1) cycle
jj=nat*(j-1)*l
if(l==k.or.l==j.or.l==i) cycle
! if(bond(i,j)==1.and.bond(j,k)==1.and.bond(k,l)==1) then
if(bond(k,l)==1) then
kk=kk+1
call dihed(mol1%xyz,i,j,k,l,ang1,anggrad1)
call dihed(mol2%xyz,i,j,k,l,ang2,anggrad2)
call torsionfix(anggrad1,anggrad2,x)
! x=anggrad1-anggrad2
dummy(kk)=x
s=s+abs(x)
if(abs(x)>=thresh) then
write(io,'(a,x,4(I5,''['',a2,'']''),x,F8.4,a)'),'delta_tors',i,el(mol1%iat(i)),j,el(mol2%iat(j)),k,el(mol1%iat(k)),l,el(mol1%iat(l)),x,' * '
else
write(io,'(a,x,4(I5,''['',a2,'']''),x,F8.4)'),'delta_tors',i,el(mol1%iat(i)),j,el(mol2%iat(j)),k,el(mol1%iat(k)),l,el(mol1%iat(l)),x
endif
endif
enddo
enddo
enddo
enddo
! ToDo: custom torsions
if(int_nt>0) print*,' custom torsions: '
do it=1,int_nt
i=int_tcast(it,1)
j=int_tcast(it,2)
k=int_tcast(it,3)
l=int_tcast(it,4)
call dihed(mol2%xyz,i,j,k,l,ang2,anggrad2)
call torsionfix(int_tval(it),anggrad2,x)
kk=kk+1
dummy(kk)=x
write(*,'(2x,a,x,4(I5,''['',a2,'']''),x,F8.4)'),'delta_tors',i,el(mol1%iat(i)),j,el(mol2%iat(j)),k,el(mol1%iat(k)),l,el(mol1%iat(l)),x
enddo
print*,''
tot=kk
allocate(tvec(tot))
tvec=0d0
tvec(1:tot)=dummy(1:tot)
if(kk>1) then
print*, ' # torsions ', kk
!print'(a,F8.1)',' mean abs torsion deviation [deg]: ', s/dble(kk)
print'(a,F8.1)',' mean abs dihedral deviation [deg] : ', sum(abs(tvec))/dble(kk)
print'(a,F8.1)',' mean dihedral deviation [deg] : ', sum(tvec)/dble(kk)
print'(a,F8.1)',' max (+) deviation [deg] : ', maxval(tvec)
print'(a,F8.1)',' max (-) deviation [deg] : ', minval(tvec)
print'(a,F8.1)',' deviation range [deg] : ', maxval(tvec)-minval(tvec)
!print*, ' output: torsions.dat'
print'(2x,a,F6.2,a)','|deviations| above ',thresh,' deg are marked (*) '
endif
close(io)
deallocate(tvec)
end subroutine
! fixed 0/360 switches in torsion differences
subroutine torsionfix(t0,t1,dt)
use constant, only: pi
implicit none
logical qI,qIV,shift
real(8) t0,t1,dt
! Check for the case that the torsion goes from the I to the IV quadrant and adjust accordingly
! we check for "greater/less equal" since we might want to reach 0 as target value
! IV to I
qI=.false.
qIV=.false.
shift=.false.
if(t1.ge.0.and.t1.le.90) qI=.true.
if(t0.ge.270.and.t0.le.360) qIV=.true.
if(qI.and.qIV) shift=.true.
if(shift) then
t1=t1+360
dt=t1-t0
goto 999
endif
qI=.false.
qIV=.false.
! I to VI
qI=.false.
qIV=.false.
shift=.false.
if(t0.ge.0.and.t0.le.90) qI=.true.
if(t1.ge.270.and.t1.le.360) qIV=.true.
if(qI.and.qIV) shift=.true.
if(shift) then
t1=t1-360
dt=t1-t0
goto 999
endif
999 continue
if(.not.shift) dt=t1-t0
return
end
! UNFINISHED
! read user defined bonds/angles/torsions
! modified from xopt
subroutine read_intcoord(infile,xyz0)
use constant, only:au2ang
use internals
implicit none
real(8) xyz0(3,*) ! coordinate that will serve as reference
character(80) aa,bb,cc
logical da
integer ii,jj,kk,ll
integer s2i,io
real(8) s2r,dih,dgrad,ang,dang,bl,di360,anggrad,grad2rad
real(8) bdist,dbond
character(*) infile
logical fstr
!real(8) val0()
!integer n_bond(*),n_ang(*),n_dihed(*),ires
integer iint,n_ints
! internal arrays
!integer int_nb,int_na,int_nt
!real(8), allocatable :: int_bval(:)
!integer, allocatable :: int_bcast(:,:)
!real(8), allocatable :: int_aval(:)
!integer, allocatable :: int_acast(:,:,:)
!real(8), allocatable :: int_tval(:)
!integer, allocatable :: int_tcast(:,:,:,:)
da=.false.
inquire(file=infile,exist=da)
if(.not.da) return
open(newunit=io,file=infile,status='old')
! determine size
int_nb=0
int_na=0
int_nt=0
do
read(io,'(a)',end=125) aa
if(index(aa,'$prim').ne.0) then
do
read(io,'(a)',end=126) aa
if(index(aa,'#').ne.0) cycle
if(fstr(aa,'bond')) int_nb=int_nb+1
if(fstr(aa,'ang')) int_na=int_na+1
if(fstr(aa,'dihed').or.fstr(aa,'torsion')) int_nt=int_nt+1
enddo
endif
enddo
125 continue
126 continue
n_ints=int_nb+int_na+int_nt
print*,''
print*, '# custom primitives:', n_ints
print*, ' # bonds :', int_nb
print*, ' # angles :', int_na
print*, ' # torsions :', int_nt
print*,''
allocate(int_bval(int_nb),int_bcast(int_nb,2))
allocate(int_aval(int_na),int_acast(int_na,3))
allocate(int_tval(int_nt),int_tcast(int_nt,4))
rewind(io)
iint=0
int_nb=0
int_na=0
int_nt=0
do
read(io,'(a)',end=124) aa
if(index(aa,'$prim').ne.0) then
print*,''
print*,' user definied internal coordinates: '
print*,''
do
read(io,'(a)',end=123) aa
if(index(aa,'#').ne.0) cycle
if(fstr(aa,'bond')) then
iint=iint+1
int_nb=int_nb+1
call charXsplit(aa,bb,2)
ii=s2i(bb)
call charXsplit(aa,bb,3)
jj=s2i(bb)
bdist=dbond(xyz0(1,ii),xyz0(1,jj))
int_bval(int_nb)=bdist
int_bcast(int_nb,1)=ii
int_bcast(int_nb,2)=jj
write(*,'(2x,a,2I4,2x,a,F7.2)') 'bond [A] ', ii,jj,' | value: ',bdist
endif
if(fstr(aa,'ang')) then
iint=iint+1
int_na=int_na+1
call charXsplit(aa,bb,2)
ii=s2i(bb)
call charXsplit(aa,bb,3)
jj=s2i(bb)
call charXsplit(aa,bb,4)
kk=s2i(bb)
call angle(xyz0,ii,jj,kk,ang,dang)
int_aval(int_na)=dang
int_acast(int_na,1)=ii
int_acast(int_na,2)=jj
int_acast(int_na,3)=kk
write(*,'(2x,a,3I4,2x,a,F7.2)') 'angle [deg] ', ii,jj,kk,' | value: ',dang
endif
if(fstr(aa,'dihed').or.fstr(aa,'torsion')) then
iint=iint+1
int_nt=int_nt+1
call charXsplit(aa,bb,2)
ii=s2i(bb)
call charXsplit(aa,bb,3)
jj=s2i(bb)
call charXsplit(aa,bb,4)
kk=s2i(bb)
call charXsplit(aa,bb,5)
ll=s2i(bb)
call dihed(xyz0,ii,jj,kk,ll,dih,dgrad)
int_tval(int_nt)=dgrad
int_tcast(int_nt,1)=ii
int_tcast(int_nt,2)=jj
int_tcast(int_nt,3)=kk
int_tcast(int_nt,4)=ll
write(*,'(2x,a,4I4,2x,a,F7.2)') 'torsion [deg] ',ii,jj,kk,ll,' | value: ',dgrad
endif
if(index(aa,'$').ne.0) then
backspace(io)
exit
endif
enddo
endif
enddo
123 continue
124 continue
close(io)
! should not happen
if(iint/=n_ints) stop 'I/O error in custom internals'
print*,''
end subroutine
! print all values about thresh for an input vector
subroutine print_threshold(n,vec,thresh)
implicit none
real(8) vec(*), thresh
integer i,n
do i=1,n
if(vec(i)>=thresh) print '(1x,F8.2)',vec(i)
enddo
end subroutine