Zmina 21 na ntyp1 w wham src i src-M
[unres.git] / source / unres / src_CSA / econstr_local.F
1       subroutine Econstr_back
2 c     MD with umbrella_sampling using Wolyne's distance measure as a constraint
3       implicit real*8 (a-h,o-z)
4       include 'DIMENSIONS'
5       include 'COMMON.CONTROL'
6       include 'COMMON.VAR'
7       include 'COMMON.MD_'
8 c#ifndef LANG0
9 c      include 'COMMON.LANGEVIN'
10 c#else
11 c      include 'COMMON.LANGEVIN.lang0'
12 c#endif
13       include 'COMMON.CHAIN'
14       include 'COMMON.DERIV'
15       include 'COMMON.GEO'
16       include 'COMMON.LOCAL'
17       include 'COMMON.INTERACT'
18       include 'COMMON.IOUNITS'
19       include 'COMMON.NAMES'
20       include 'COMMON.TIME1'
21       Uconst_back=0.0d0
22       do i=1,nres
23         dutheta(i)=0.0d0
24         dugamma(i)=0.0d0
25         do j=1,3
26           duscdiff(j,i)=0.0d0
27           duscdiffx(j,i)=0.0d0
28         enddo
29       enddo
30       do i=1,nfrag_back
31         ii = ifrag_back(2,i,iset)-ifrag_back(1,i,iset)
32 c
33 c Deviations from theta angles
34 c
35         utheta_i=0.0d0
36         do j=ifrag_back(1,i,iset)+2,ifrag_back(2,i,iset)
37           dtheta_i=theta(j)-thetaref(j)
38           utheta_i=utheta_i+0.5d0*dtheta_i*dtheta_i
39           dutheta(j-2)=dutheta(j-2)+wfrag_back(1,i,iset)*dtheta_i/(ii-1)
40         enddo
41         utheta(i)=utheta_i/(ii-1)
42 c
43 c Deviations from gamma angles
44 c
45         ugamma_i=0.0d0
46         do j=ifrag_back(1,i,iset)+3,ifrag_back(2,i,iset)
47           dgamma_i=pinorm(phi(j)-phiref(j))
48 c          write (iout,*) j,phi(j),phi(j)-phiref(j)
49           ugamma_i=ugamma_i+0.5d0*dgamma_i*dgamma_i
50           dugamma(j-3)=dugamma(j-3)+wfrag_back(2,i,iset)*dgamma_i/(ii-2)
51 c          write (iout,*) i,j,dgamma_i,wfrag_back(2,i,iset),dugamma(j-3)
52         enddo
53         ugamma(i)=ugamma_i/(ii-2)
54 c
55 c Deviations from local SC geometry
56 c
57         uscdiff(i)=0.0d0
58         do j=ifrag_back(1,i,iset)+1,ifrag_back(2,i,iset)-1
59           dxx=xxtab(j)-xxref(j)
60           dyy=yytab(j)-yyref(j)
61           dzz=zztab(j)-zzref(j)
62           uscdiff(i)=uscdiff(i)+dxx*dxx+dyy*dyy+dzz*dzz
63           do k=1,3
64             duscdiff(k,j-1)=duscdiff(k,j-1)+wfrag_back(3,i,iset)*
65      &       (dXX_C1tab(k,j)*dxx+dYY_C1tab(k,j)*dyy+dZZ_C1tab(k,j)*dzz)/
66      &       (ii-1)
67             duscdiff(k,j)=duscdiff(k,j)+wfrag_back(3,i,iset)*
68      &       (dXX_Ctab(k,j)*dxx+dYY_Ctab(k,j)*dyy+dZZ_Ctab(k,j)*dzz)/
69      &       (ii-1)
70             duscdiffx(k,j)=duscdiffx(k,j)+wfrag_back(3,i,iset)*
71      &     (dXX_XYZtab(k,j)*dxx+dYY_XYZtab(k,j)*dyy+dZZ_XYZtab(k,j)*dzz)
72      &      /(ii-1)
73           enddo
74 c          write (iout,'(i5,6f10.5)') j,xxtab(j),yytab(j),zztab(j),
75 c     &      xxref(j),yyref(j),zzref(j)
76         enddo
77         uscdiff(i)=0.5d0*uscdiff(i)/(ii-1)
78 c        write (iout,*) i," uscdiff",uscdiff(i)
79 c
80 c Put together deviations from local geometry
81 c
82         Uconst_back=Uconst_back+wfrag_back(1,i,iset)*utheta(i)+
83      &    wfrag_back(2,i,iset)*ugamma(i)+wfrag_back(3,i,iset)*uscdiff(i)
84 c        write(iout,*) "i",i," utheta",utheta(i)," ugamma",ugamma(i),
85 c     &   " uconst_back",uconst_back
86         utheta(i)=dsqrt(utheta(i))
87         ugamma(i)=dsqrt(ugamma(i))
88         uscdiff(i)=dsqrt(uscdiff(i))
89       enddo
90       return
91       end