6 #if .not. defined WHAM_RUN && .not. defined CLUSTER
7 use minim_data, only: maxfun,rtolf
11 #if .not. defined WHAM_RUN && .not. defined CLUSTER
12 !-----------------------------------------------------------------------------
14 !-----------------------------------------------------------------------------
15 subroutine regularize(ncart,etot,rms,cref0,iretcode)
17 use geometry, only: geom_to_var,chainbuild,var_to_geom
18 use energy, only: etotal,enerprint
19 use minimm, only: minimize
20 ! implicit real*8 (a-h,o-z)
21 ! include 'DIMENSIONS'
22 ! include 'COMMON.SBRIDGE'
23 ! include 'COMMON.CHAIN'
24 ! include 'COMMON.INTERACT'
25 ! include 'COMMON.HEADER'
26 ! include 'COMMON.IOUNITS'
27 ! include 'COMMON.MINIM'
29 real(kind=8) :: przes(3),obrot(3,3)
30 real(kind=8),dimension((nres-1)*(nres-2)/2) :: fhpb0 !(maxdim) (maxdim=(maxres-1)*(maxres-2)/2)
31 real(kind=8),dimension(6*nres) :: varia !(maxvar)(maxvar=6*maxres)
32 real(kind=8),dimension(3,ncart) :: cref0
33 real(kind=8),dimension(0:n_ene) :: energia
35 integer :: link_end0,i,maxit_reg,it
36 real(kind=8) :: etot,rms,rtolf0
37 integer :: iretcode,maxit,maxit0,maxfun0,nfun
44 print *,'Enter REGULARIZE: nnt=',nnt,' nct=',nct,' nsup=',nsup,&
45 ' nstart_seq=',nstart_seq,' nstart_sup',nstart_sup
46 write (iout,'(/a/)') 'Initial energies:'
47 call geom_to_var(nvar,varia)
51 call enerprint(energia)
52 call fitsq(rms,c(1,nstart_seq),cref0(1,nstart_sup-1),&
53 nsup,przes,obrot,non_conv)
54 write (iout,'(a,f10.5)') &
55 'Enter REGULARIZE: Initial RMS deviation:',dsqrt(dabs(rms))
56 write (*,'(a,f10.5)') &
57 'Enter REGULARIZE: Initial RMS deviation:',dsqrt(dabs(rms))
65 print *,'Regularization: pass:',it
66 ! Minimize with distance constraints, gradually relieving the weight.
67 call minimize(etot,varia,iretcode,nfun)
69 if (iretcode.eq.11) return
70 call fitsq(rms,c(1,nstart_seq),cref0(1,nstart_sup-1),&
71 nsup,przes,obrot,non_conv)
73 write (iout,'(a,i2,a,f10.5,a,1pe14.5,a,i3/)') &
74 'Finish pass',it,', RMS deviation:',rms,', energy',etot,&
75 ' SUMSL convergence',iretcode
77 forcon(i)=0.1D0*forcon(i)
80 ! Turn off the distance constraints and re-minimize energy.
81 print *,'Final minimization ... '
85 link_end=min0(link_end,nss)
86 call minimize(etot,varia,iretcode,nfun)
88 call fitsq(rms,c(1,nstart_seq),cref0(1,nstart_sup-1),nsup,&
91 write (iout,'(a,f10.5,a,1pe14.5,a,i3/)') &
92 'Final RMS deviation:',rms,' energy',etot,' SUMSL convergence',&
98 call var_to_geom(nvar,varia)
101 end subroutine regularize
103 !-----------------------------------------------------------------------------
105 !-----------------------------------------------------------------------------
106 subroutine fitsq(rms,x,y,nn,t,b,non_conv)
108 ! implicit real*8 (a-h,o-z)
109 ! include 'COMMON.IOUNITS'
110 ! x and y are the vectors of coordinates (dimensioned (3,n)) of the two
111 ! structures to be superimposed. nn is 3*n, where n is the number of
112 ! points. t and b are respectively the translation vector and the
113 ! rotation matrix that transforms the second set of coordinates to the
114 ! frame of the first set.
115 ! eta = machine-specific variable
116 integer :: nn,i,n,j,nc
117 real(kind=8),dimension(3*nn) :: x,y
118 real(kind=8),dimension(3,3) :: b,q,r,c
119 real(kind=8),dimension(3) :: t,v,xav,yav,e
123 real(kind=8) :: rms,fn,d,sn3
126 ! small=25.0*rmdcon(3)
129 ! the following is a very lenient value for 'small'
130 real(kind=8) :: small = 0.0001D0
142 ! write(iout,*)'x = ',x(nc+i),' y = ',y(nc+i)
143 xav(i)=xav(i)+x(nc+i)/fn
144 20 yav(i)=yav(i)+y(nc+i)/fn
154 rms=rms+(y(3*(n-1)+i)-x(3*(n-1)+i)-t(i))**2
159 ! write(iout,*)'xav = ',(xav(j),j=1,3)
160 ! write(iout,*)'yav = ',(yav(j),j=1,3)
161 ! write(iout,*)'t = ',(t(j),j=1,3)
162 ! write(iout,*)'rms=',rms
163 if (rms.lt.small) return
170 rms=rms+((x(nc+i)-xav(i))**2+(y(nc+i)-yav(i))**2)/fn
172 b(j,i)=b(j,i)+(x(nc+i)-xav(i))*(y(nc+j)-yav(j))/fn
175 call sivade(b,q,r,d,non_conv)
179 120 b(j,i)=-q(j,1)*r(i,1)-q(j,2)*r(i,2)-sn3*q(j,3)*r(i,3)
180 call mvvad(b,xav,yav,t)
183 rms=rms+2.0*c(j,i)*b(j,i)
185 if (dabs(rms).gt.small) go to 140
188 140 if (rms.gt.0.0d0) go to 150
189 ! write (iout,303) rms
192 ! 150 write (iout,302) dsqrt(rms)
195 301 format (5x,'rms deviation negligible')
196 302 format (5x,'rms deviation ',f14.6)
197 303 format (//,5x,'negative ms deviation - ',f14.6)
199 !-----------------------------------------------------------------------------
200 subroutine sivade(x,q,r,dt,non_conv)
202 ! implicit real*8(a-h,o-z)
203 ! computes q,e and r such that q(t)xr = diag(e)
204 real(kind=8),dimension(3,3) :: x,q,r
205 real(kind=8),dimension(3) :: e
206 real(kind=8),dimension(3,3) :: h,p,u
207 real(kind=8),dimension(3) :: d
211 integer :: nit,i,j,n,np,nq,npq,n0,nn
212 real(kind=8) :: dt,small,xnrm,xmax,a,den,s,b,c,dd,xn2,y,z,rt,t,v,w
215 ! write (2,*) "SIVADE"
219 ! small=2.0*rmdcon(3)
223 xnrm=xnrm+x(j,i)*x(j,i)
233 30 if (dabs(x(j,n)).gt.xmax) xmax=dabs(x(j,n))
239 den=a*(a+dabs(h(n,n)))
241 h(n,n)=h(n,n)+dsign(a,h(n,n))
248 60 x(j,i)=x(j,i)-s*h(j,n)
250 if (n.gt.1) go to 110
251 xmax=dmax1(dabs(x(1,2)),dabs(x(1,3)))
254 a=dsqrt(h(2,3)*h(2,3)+h(3,3)*h(3,3))
255 den=a*(a+dabs(h(2,3)))
257 h(2,3)=h(2,3)+sign(a,h(2,3))
264 90 x(i,j)=x(i,j)-s*h(j,3)
269 120 p(j,i)=-d(1)*h(j,1)*h(i,1)
270 130 p(i,i)=1.0+p(i,i)
273 u(j,i)=u(j,i)-d(2)*h(j,2)*h(i,2)
274 140 r(j,i)=r(j,i)-d(3)*h(j,3)*h(i,3)
279 ! write (2,*) "nit",nit," e",(x(i,i),i=1,3)
280 if (nit.gt.10000) then
281 print '(a)','!!!! Over 10000 iterations in SIVADE!!!!!'
285 if (dabs(x(2,3)).gt.small*(dabs(x(2,2))+abs(x(3,3)))) go to 160
288 160 if (dabs(x(1,2)).gt.small*(dabs(x(1,1))+dabs(x(2,2)))) go to 180
290 if (x(2,3).ne.0.0d0) go to 170
294 180 if (nq.eq.3) go to 310
296 ! write (2,*) "np",np," npq",npq
297 if (np.gt.npq) go to 230
301 ! write (2,*) "nn",nn
302 if (dabs(x(nn,nn)).gt.small*xnrm) go to 220
304 if (x(nn,nn+1).eq.0.0d0) go to 220
306 ! write (2,*) "nn",nn
307 go to (190,210,220),nn
309 200 call givns(x,q,1,j)
311 210 call givns(x,q,2,3)
313 ! write (2,*) "nn",nn," np",np," nq",nq," n0",n0
314 ! write (2,*) "x",(x(i,i),i=1,3)
315 if (n0.ne.0) go to 150
318 if (nn.gt.1) a=a+x(nn-1,nn)*x(nn-1,nn)
319 b=x(nn+1,nn+1)*x(nn+1,nn+1)+x(nn,nn+1)*x(nn,nn+1)
320 c=x(nn,nn)*x(nn,nn+1)
323 rt=b-xn2/(dd+sign(dsqrt(dd*dd+xn2),dd))
324 y=x(np,np)*x(np,np)-rt
325 z=x(np,np)*x(np,np+1)
327 ! write (2,*) "n",n," a",a," b",b," c",c," y",y," z",z
328 if (dabs(y).lt.dabs(z)) go to 240
330 c=1.0/dsqrt(1.0d0+t*t)
334 s=1.0/dsqrt(1.0d0+t*t)
344 260 r(j,n+1)=-s*a+c*b
347 if (dabs(y).lt.dabs(z)) go to 270
363 290 q(j,n+1)=-s*a+c*b
364 if (n.ge.nn) go to 300
374 if (nit.gt.10000) then
375 print '(a)','!!!! Over 10000 iterations in SIVADE!!!!!'
379 ! write (2,*) "e",(e(i),i=1,3)
381 if (e(i).ge.0.0d0) go to 350
385 350 if (i.eq.1) go to 360
386 if (dabs(e(i)).lt.dabs(e(i-1))) go to 360
387 call switch(i,1,q,r,e)
390 if (n0.ne.0) go to 330
391 ! write (2,*) "e",(e(i),i=1,3)
392 if (dabs(e(3)).gt.small*xnrm) go to 370
394 if (dabs(e(2)).gt.small*xnrm) go to 370
396 370 dt=det(q(1,1),q(1,2),q(1,3))*det(r(1,1),r(1,2),r(1,3))
397 ! write (2,*) "nit",nit
398 ! write (2,501) (e(i),i=1,3)
400 501 format (/,5x,'singular values - ',3e15.5)
401 end subroutine sivade
402 !-----------------------------------------------------------------------------
403 subroutine givns(a,b,m,n)
405 ! implicit real*8 (a-h,o-z)
406 real(kind=8),dimension(3,3) :: a,b
408 real(kind=8) :: t,c,s,v,w,x,y
410 if (dabs(a(m,n)).lt.dabs(a(n,n))) go to 10
429 !-----------------------------------------------------------------------------
430 subroutine switch(n,m,u,v,d)
432 ! implicit real*8 (a-h,o-z)
433 real(kind=8),dimension(3,3) :: u,v
434 real(kind=8),dimension(3) :: d
450 end subroutine switch
451 !-----------------------------------------------------------------------------
452 subroutine mvvad(b,xav,yav,t)
454 ! implicit real*8 (a-h,o-z)
455 real(kind=8),dimension(3,3) :: b
456 real(kind=8),dimension(3) :: xav,yav,t
458 ! dimension a(3,3),b(3),c(3),d(3)
462 ! 10 d(j)=d(j)+a(j,i)*b(i)
466 10 t(j)=t(j)+b(j,i)*xav(i)
469 !-----------------------------------------------------------------------------
470 real(kind=8) function det(a,b,c)
471 ! implicit real*8 (a-h,o-z)
472 real(kind=8),dimension(3) :: a,b,c
473 det=a(1)*(b(2)*c(3)-b(3)*c(2))+a(2)*(b(3)*c(1)-b(1)*c(3)) &
474 +a(3)*(b(1)*c(2)-b(2)*c(1))
477 !-----------------------------------------------------------------------------
478 subroutine mmmul(a,b,c)
480 ! implicit real*8 (a-h,o-z)
481 real(kind=8),dimension(3,3) :: a,b,c
487 10 c(i,j)=c(i,j)+a(i,k)*b(k,j)
490 #if .not. defined WHAM_RUN || .not. defined CLUSTER
491 !-----------------------------------------------------------------------------
492 subroutine matvec(uvec,tmat,pvec,nback)
494 ! implicit real*8 (a-h,o-z)
495 real(kind=8),dimension(3,3) :: tmat
496 real(kind=8),dimension(3,nback) :: uvec,pvec
497 integer :: nback,i,j,k
503 1 uvec(i,j)=uvec(i,j)+tmat(i,k)*pvec(k,j)
506 end subroutine matvec
507 !-----------------------------------------------------------------------------
509 !-----------------------------------------------------------------------------
510 end module regularize_