1 subroutine add_angpair(ici,icj,nang_pair,iang_pair)
2 implicit real*8 (a-h,o-z)
4 include 'COMMON.IOUNITS'
6 integer ici,icj,nang_pair,iang_pair(2,maxres)
8 c write (iout,*) "add_angpair: ici",ici," icj",icj,
9 c & " nang_pair",nang_pair
11 if (ian1.lt.4 .or. ian1.gt.nres) return
13 c write (iout,*) "ian1",ian1," ian2",ian2
14 if (ian2.lt.4 .or. ian2.gt.nres) return
16 if (ian1.eq.iang_pair(1,i) .and. ian2.eq.iang_pair(2,i)) return
19 iang_pair(1,nang_pair)=ian1
20 iang_pair(2,nang_pair)=ian2
23 c-------------------------------------------------------------------------
24 subroutine angnorm(jfrag,ishif1,ishif2,diffang_max,angn,fract,
26 implicit real*8 (a-h,o-z)
28 include 'DIMENSIONS.ZSCOPT'
29 include 'DIMENSIONS.COMPAR'
30 include 'COMMON.IOUNITS'
32 include 'COMMON.COMPAR'
33 include 'COMMON.CHAIN'
35 double precision pinorm,deltang
37 if (lprn) write (iout,'(80(1h*))')
41 npart = npiece(jfrag,1)
43 nne = min0(nend_sup,nres)
44 if (lprn) write (iout,*) "nn4",nn4," nne",nne
46 nbeg = ifrag(1,i,jfrag) + 3 - ishif1
47 if (nbeg.lt.nn4) nbeg=nn4
48 nend = ifrag(2,i,jfrag) + 1 - ishif2
49 if (nend.gt.nne) nend=nne
50 if (nend.ge.nbeg) then
51 nn = nn + nend - nbeg + 1
52 if (lprn) write (iout,*) "i=",i," nbeg",nbeg," nend",nend,
53 & " nn",nn," ishift1",ishif1," ishift2",ishif2
54 if (lprn) write (iout,*) "angles"
58 c deltang = pinorm(phi(j)-phi_ref(j+ishif1))
59 deltang=spherang(phi_ref(j+ishif1),theta_ref(j-1+ishif1),
60 & theta_ref(j+ishif1),phi(j),theta(j-1),theta(j))
61 if (dabs(deltang).gt.diffang_max) then
62 if (ll.gt.longest) longest = ll
67 if (ll.gt.longest) longest = ll
68 if (lprn) write (iout,'(i5,3f10.5)')j,rad2deg*phi(j),
69 & rad2deg*phi_ref(j+ishif1),rad2deg*deltang
70 angn=angn+dabs(deltang)
73 ff = dfloat(longest)/dfloat(nend - nbeg + 4)
74 if (lprn) write (iout,*)"segment",i," longest fragment within",
75 & diffang_max*rad2deg,":",longest," fraction",ff
76 if (ff.lt.fract) fract = ff
84 if (lprn) write (iout,*) "nn",nn," norm",rad2deg*angn,
88 c-------------------------------------------------------------------------
89 subroutine angnorm2(jfrag,ishif1,ishif2,ncont,icont,lprn,
90 & diffang_max,anorm,fract)
91 implicit real*8 (a-h,o-z)
93 include 'DIMENSIONS.ZSCOPT'
94 include 'DIMENSIONS.COMPAR'
95 include 'COMMON.IOUNITS'
97 include 'COMMON.COMPAR'
98 include 'COMMON.CHAIN'
100 integer ncont,icont(2,ncont),longest
101 double precision anorm,diffang_max,fract
102 integer npiece_c,ifrag_c(2,maxpiece),ishift_c(maxpiece)
103 double precision pinorm
105 if (lprn) write (iout,'(80(1h*))')
107 c Determine the segments for which angles will be compared
110 nne = min0(nend_sup,nres)
111 if (lprn) write (iout,*) "nn4",nn4," nne",nne
112 npart=npiece(jfrag,1)
115 c write (iout,*) "i",i," ifrag",ifrag(1,i,jfrag),ifrag(2,i,jfrag)
116 if (icont(1,ncont).lt.ifrag(1,i,jfrag) .or.
117 & icont(1,1).gt.ifrag(2,i,jfrag)) goto 11
119 do while (jstart.lt.ncont .and.
120 & icont(1,jstart).lt.ifrag(1,i,jfrag))
121 c write (iout,*) "jstart",jstart," icont",icont(1,jstart),
122 c & " ifrag",ifrag(1,i,jfrag)
125 c write (iout,*) "jstart",jstart," icont",icont(1,jstart),
126 c & " ifrag",ifrag(1,i,jfrag)
127 if (icont(1,jstart).lt.ifrag(1,i,jfrag)) goto 11
130 ifrag_c(1,npiece_c)=icont(1,jstart)
132 do while (jend.gt.1 .and. icont(1,jend).gt.ifrag(2,i,jfrag))
133 c write (iout,*) "jend",jend," icont",icont(1,jend),
134 c & " ifrag",ifrag(2,i,jfrag)
137 c write (iout,*) "jend",jend," icont",icont(1,jend),
138 c & " ifrag",ifrag(2,i,jfrag)
140 ifrag_c(2,npiece_c)=icont(1,jend)+1
141 ishift_c(npiece_c)=ishif1
142 c write (iout,*) "1: i",i," jstart:",jstart," jend",jend,
143 c & " ic1",ic1," ic2",ic2,
144 c & " ifrag",ifrag(1,i,jfrag),ifrag(2,i,jfrag)
146 if (ncont.eq.1 .or. icont(2,ncont).gt.icont(2,1)) then
151 c write (iout,*) "idi",idi
153 if (icont(2,1).gt.ifrag(2,i,jfrag) .or.
154 & icont(2,ncont).lt.ifrag(1,i,jfrag)) goto 12
156 do while (jstart.lt.ncont .and.
157 & icont(2,jstart).lt.ifrag(1,i,jfrag))
158 c write (iout,*) "jstart",jstart," icont",icont(2,jstart),
159 c & " ifrag",ifrag(1,i,jfrag)
162 c write (iout,*) "jstart",jstart," icont",icont(2,jstart),
163 c & " ifrag",ifrag(1,i,jfrag)
164 if (icont(2,jstart).lt.ifrag(1,i,jfrag)) goto 12
167 ifrag_c(2,npiece_c)=icont(2,jstart)+1
169 do while (jend.gt.1 .and. icont(2,jend).gt.ifrag(2,i,jfrag))
170 c write (iout,*) "jend",jend," icont",icont(2,jend),
171 c & " ifrag",ifrag(2,i,jfrag)
174 c write (iout,*) "jend",jend," icont",icont(2,jend),
175 c & " ifrag",ifrag(2,i,jfrag)
176 else if (idi.eq.-1) then
177 if (icont(2,ncont).gt.ifrag(2,i,jfrag) .or.
178 & icont(2,1).lt.ifrag(1,i,jfrag)) goto 12
180 do while (jstart.gt.ncont .and.
181 & icont(2,jstart).lt.ifrag(1,i,jfrag))
182 c write (iout,*) "jstart",jstart," icont",icont(2,jstart),
183 c & " ifrag",ifrag(1,i,jfrag)
186 c write (iout,*) "jstart",jstart," icont",icont(2,jstart),
187 c & " ifrag",ifrag(1,i,jfrag)
188 if (icont(2,jstart).lt.ifrag(1,i,jfrag)) goto 12
191 ifrag_c(2,npiece_c)=icont(2,jstart)+1
193 do while (jend.lt.ncont .and.
194 & icont(2,jend).gt.ifrag(2,i,jfrag))
195 c write (iout,*) "jend",jend," icont",icont(2,jend),
196 c & " ifrag",ifrag(2,i,jfrag)
199 c write (iout,*) "jend",jend," icont",icont(2,jend),
200 c & " ifrag",ifrag(2,i,jfrag)
208 c write (iout,*) "2: i",i," ic1",ic1," ic2",ic2,
209 c & " jstart:",jstart," jend",jend,
210 c & " ifrag",ifrag(1,i,jfrag),ifrag(2,i,jfrag)
211 ifrag_c(1,npiece_c)=ic1
212 ifrag_c(2,npiece_c)=ic2+1
213 ishift_c(npiece_c)=ishif2
217 write (iout,*) "Before merge: npiece_c",npiece_c
219 write (iout,*) ifrag_c(1,i),ifrag_c(2,i),ishift_c(i)
223 c Merge overlapping segments (e.g., avoid splitting helices)
226 do while (i .lt. npiece_c)
227 if (ishift_c(i).eq.ishift_c(i+1) .and.
228 & ifrag_c(2,i).gt.ifrag_c(1,i+1)) then
229 ifrag_c(2,i)=ifrag_c(2,i+1)
231 ishift_c(j)=ishift_c(j+1)
232 ifrag_c(1,j)=ifrag_c(1,j+1)
233 ifrag_c(2,j)=ifrag_c(2,j+1)
241 write (iout,*) "After merge: npiece_c",npiece_c
243 write (iout,*) ifrag_c(1,i),ifrag_c(2,i),ishift_c(i)
256 nbeg = ifrag_c(1,i) + 3 - ishifc
257 if (nbeg.lt.nn4) nbeg=nn4
258 nend = ifrag_c(2,i) - ishifc + 1
259 if (nend.gt.nne) nend=nne
260 if (nend.ge.nbeg) then
261 nn = nn + nend - nbeg + 1
262 if (lprn) write (iout,*) "i=",i," nbeg",nbeg," nend",nend,
263 & " nn",nn," ishifc",ishifc
264 if (lprn) write (iout,*) "angles"
268 c deltang = pinorm(phi(j)-phi_ref(j+ishifc))
269 deltang=spherang(phi_ref(j+ishifc),theta_ref(j-1+ishifc),
270 & theta_ref(j+ishifc),phi(j),theta(j-1),theta(j))
271 if (dabs(deltang).gt.diffang_max) then
272 if (ll.gt.longest) longest = ll
277 if (ll.gt.longest) longest = ll
278 if (lprn) write (iout,'(i5,3f10.5)')j,rad2deg*phi(j),
279 & rad2deg*phi_ref(j+ishifc),rad2deg*deltang
280 angn=angn+dabs(deltang)
283 ff = dfloat(longest)/dfloat(nend - nbeg + 4)
284 if (lprn) write (iout,*)"segment",i," longest fragment within",
285 & diffang_max*rad2deg,":",longest," fraction",ff
286 if (ff.lt.fract) fract = ff
289 if (nn.gt.0) anorm = angn/nn
290 if (lprn) write (iout,*) "nn",nn," norm",anorm," fract:",fract
293 c-------------------------------------------------------------------------
294 double precision function angnorm1(nang_pair,iang_pair,lprn)
295 implicit real*8 (a-h,o-z)
297 include 'DIMENSIONS.ZSCOPT'
298 include 'DIMENSIONS.COMPAR'
299 include 'COMMON.IOUNITS'
301 include 'COMMON.COMPAR'
302 include 'COMMON.CHAIN'
305 integer nang_pair,iang_pair(2,maxres)
306 double precision pinorm
308 if (lprn) write (iout,'(80(1h*))')
309 if (lprn) write (iout,*) "nang_pair",nang_pair
310 if (lprn) write (iout,*) "angles"
314 c deltang = pinorm(phi(ia1)-phi_ref(ia2))
315 deltang=spherang(phi_ref(ia2),theta_ref(ia2-1),
316 & theta_ref(ia2),phi(ia2),theta(ia2-1),theta(ia2))
317 if (lprn) write (iout,'(3i5,3f10.5)')j,ia1,ia2,rad2deg*phi(ia1),
318 & rad2deg*phi_ref(ia2),rad2deg*deltang
319 angn=angn+dabs(deltang)
322 &write (iout,*)"nang_pair",nang_pair," angn",rad2deg*angn/nang_pair
323 angnorm1 = angn/nang_pair
326 c------------------------------------------------------------------------------
327 subroutine angnorm12(diff)
328 implicit real*8 (a-h,o-z)
330 include 'DIMENSIONS.ZSCOPT'
331 include 'DIMENSIONS.COMPAR'
332 include 'COMMON.IOUNITS'
334 include 'COMMON.COMPAR'
335 include 'COMMON.CHAIN'
337 double precision pinorm
340 nne = min0(nend_sup,nres)
342 c diff = diff+rad2deg*dabs(pinorm(theta(j)-theta_ref(j)))
345 c diff = diff+rad2deg*dabs(pinorm(phi(j)-phi_ref(j)))
346 diff=diff+spherang(phi_ref(j),theta_ref(j-1),
347 & theta_ref(j),phi(j),theta(j-1),theta(j))
351 c--------------------------------------------------------------------------------
352 double precision function spherang(gam1,theta11,theta12,
353 & gam2,theta21,theta22)
355 double precision gam1,theta11,theta12,gam2,theta21,theta22,
356 & x1,x2,xmed,f1,f2,fmed
357 double precision tolx /1.0d-4/, tolf /1.0d-4/
358 double precision sumcos
359 double precision arcos,pinorm,sumangp
360 integer it,maxit /100/
361 c Calculate the difference of the angles of two superposed 4-redidue fragments
369 c The fragment O'-C-C-P' is rotated by angle fi about the C-C axis
370 c to achieve the minimum difference between the O'-C-O and P-C-P angles;
371 c the sum of these angles is the difference returned by the function.
374 c If thetas match, take the difference of gamma and exit.
375 if (dabs(theta11-theta12).lt.tolx
376 & .and. dabs(theta21-theta22).lt.tolx) then
377 spherang=dabs(pinorm(gam2-gam1))
380 c If the gammas are the same, take the difference of thetas and exit.
382 x2=0.5d0*pinorm(gam2-gam1)
383 if (dabs(x2) .lt. tolx) then
384 spherang=dabs(theta11-theta21)+dabs(theta12-theta22)
386 else if (x2.lt.0.0d0) then
390 c Else apply regula falsi method to compute optimum overlap of the terminal Calphas
391 f1=sumangp(gam1,theta11,theta12,gam2,theta21,theta22,x1)
392 f2=sumangp(gam1,theta11,theta12,gam2,theta21,theta22,x2)
394 xmed=x1-f1*(x2-x1)/(f2-f1)
395 fmed=sumangp(gam1,theta11,theta12,gam2,theta21,theta22,xmed)
396 c write (*,*) 'it',it,' xmed ',xmed,' fmed ',fmed
397 if ( (dabs(xmed-x1).lt.tolx .or. dabs(x2-xmed).lt.tolx)
398 & .and. dabs(fmed).lt.tolf ) then
402 else if ( fmed*f1.lt.0.0d0 ) then
411 spherang=arcos(dcos(theta11)*dcos(theta12)
412 & +dsin(theta11)*dsin(theta12)*dcos(x1))+
413 & arcos(dcos(theta21)*dcos(theta22)+
414 & dsin(theta21)*dsin(theta22)*dcos(gam2-gam1+x1))
417 c--------------------------------------------------------------------------------
418 double precision function sumangp(gam1,theta11,theta12,gam2,
419 & theta21,theta22,fi)
421 double precision gam1,theta11,theta12,gam2,theta21,theta22,fi,
422 & cost11,cost12,cost21,cost22,sint11,sint12,sint21,sint22,cosd1,
424 c derivarive of the sum of the difference of the angles of a 4-residue fragment.
425 double precision arcos
434 cosd1=cost11*cost12+sint11*sint12*dcos(fi)
435 cosd2=cost21*cost22+sint21*sint22*dcos(gam2-gam1+fi)
436 sumangp=sint11*sint12*dsin(fi)/dsqrt(1.0d0-cosd1*cosd1)
437 & +sint21*sint22*dsin(gam2-gam1+fi)/dsqrt(1.0d0-cosd2*cosd2)