Merge branch 'homology' of mmka.chem.univ.gda.pl:unres into homology
[unres.git] / source / unres / src_MD-M / regularize.F
1       subroutine regularize(ncart,etot,rms,cref0,iretcode)
2       implicit real*8 (a-h,o-z)
3       include 'DIMENSIONS'
4       include 'COMMON.SBRIDGE'
5       include 'COMMON.CHAIN'
6       include 'COMMON.INTERACT'
7       include 'COMMON.HEADER'
8       include 'COMMON.IOUNITS'
9       include 'COMMON.MINIM'
10       double precision przes(3),obrot(3,3),fhpb0(maxdim),varia(maxvar)
11       double precision cref0(3,ncart)
12       double precision energia(0:n_ene)
13       logical non_conv
14       link_end0=link_end
15       do i=1,nhpb
16         fhpb0(i)=forcon(i)
17       enddo
18       maxit_reg=2
19       print *,'Enter REGULARIZE: nnt=',nnt,' nct=',nct,' nsup=',nsup,
20      & ' nstart_seq=',nstart_seq,' nstart_sup',nstart_sup
21       write (iout,'(/a/)') 'Initial energies:'
22       call geom_to_var(nvar,varia)
23       call chainbuild
24       call etotal(energia(0))
25       etot=energia(0)
26       call enerprint(energia(0))
27       call fitsq(rms,c(1,nstart_seq),cref0(1,nstart_sup-1),
28      &  nsup,przes,obrot,non_conv)
29       write (iout,'(a,f10.5)') 
30      & 'Enter REGULARIZE: Initial RMS deviation:',dsqrt(dabs(rms))
31       write (*,'(a,f10.5)') 
32      & 'Enter REGULARIZE: Initial RMS deviation:',dsqrt(dabs(rms))
33       maxit0=maxit
34       maxfun0=maxfun
35       rtolf0=rtolf
36       maxit=100
37       maxfun=200
38       rtolf=1.0D-2
39       do it=1,maxit_reg
40         print *,'Regularization: pass:',it
41 C Minimize with distance constraints, gradually relieving the weight.
42         call minimize(etot,varia,iretcode,nfun)
43         print *,'Etot=',Etot
44         if (iretcode.eq.11) return
45         call fitsq(rms,c(1,nstart_seq),cref0(1,nstart_sup-1),
46      &   nsup,przes,obrot,non_conv)
47         rms=dsqrt(rms)
48         write (iout,'(a,i2,a,f10.5,a,1pe14.5,a,i3/)') 
49      &   'Finish pass',it,', RMS deviation:',rms,', energy',etot,
50      &   ' SUMSL convergence',iretcode
51         do i=nss+1,nhpb
52           forcon(i)=0.1D0*forcon(i)
53         enddo
54       enddo
55 C Turn off the distance constraints and re-minimize energy.
56       print *,'Final minimization ... '
57       maxit=maxit0
58       maxfun=maxfun0
59       rtolf=rtolf0
60       link_end=min0(link_end,nss)
61       call minimize(etot,varia,iretcode,nfun)
62       print *,'Etot=',Etot
63       call fitsq(rms,c(1,nstart_seq),cref0(1,nstart_sup-1),nsup,
64      &  przes,obrot,non_conv)
65       rms=dsqrt(rms)
66       write (iout,'(a,f10.5,a,1pe14.5,a,i3/)') 
67      & 'Final RMS deviation:',rms,' energy',etot,' SUMSL convergence',
68      & iretcode
69       link_end=link_end0
70       do i=nss+1,nhpb
71         forcon(i)=fhpb0(i)
72       enddo
73       call var_to_geom(nvar,varia)
74       call chainbuild
75       return
76       end