xdrf2pdb-m-mult time t_bath printout
[unres.git] / source / unres / src_MD / convert.f
1       subroutine geom_to_var(n,x)
2 C
3 C Transfer the geometry parameters to the variable array.
4 C The positions of variables are as follows:
5 C 1. Virtual-bond torsional angles: 1 thru nres-3
6 C 2. Virtual-bond valence angles: nres-2 thru 2*nres-5
7 C 3. The polar angles alpha of local SC orientation: 2*nres-4 thru 
8 C    2*nres-4+nside
9 C 4. The torsional angles omega of SC orientation: 2*nres-4+nside+1
10 C    thru 2*nre-4+2*nside 
11 C
12       implicit real*8 (a-h,o-z)
13       include 'DIMENSIONS'
14       include 'COMMON.VAR'
15       include 'COMMON.GEO'
16       include 'COMMON.CHAIN'
17       double precision x(n)
18 c      print *,'nres',nres,' nphi',nphi,' ntheta',ntheta,' nvar',nvar
19 c      print *,"n",n
20       do i=4,nres
21         x(i-3)=phi(i)
22 cd      print *,i,i-3,phi(i)
23       enddo
24       if (n.eq.nphi) return
25       do i=3,nres
26         x(i-2+nphi)=theta(i)
27 cd      print *,i,i-2+nphi,theta(i)
28       enddo
29       if (n.eq.nphi+ntheta) return
30       do i=2,nres-1
31         if (ialph(i,1).gt.0) then
32 c          print *,i,ialph(i,1),ialph(i,1)+nside,alph(i),omeg(i)
33           x(ialph(i,1))=alph(i)
34           x(ialph(i,1)+nside)=omeg(i)
35         endif
36       enddo      
37       return
38       end
39 C--------------------------------------------------------------------
40       subroutine var_to_geom(n,x)
41 C
42 C Update geometry parameters according to the variable array.
43 C
44       implicit real*8 (a-h,o-z)
45       include 'DIMENSIONS'
46       include 'COMMON.VAR'
47       include 'COMMON.CHAIN'
48       include 'COMMON.GEO'
49       include 'COMMON.IOUNITS'
50       dimension x(n)
51       logical change,reduce
52       change=reduce(x)
53       if (n.gt.nphi+ntheta) then
54         do i=1,nside
55           ii=ialph(i,2)
56           alph(ii)=x(nphi+ntheta+i)
57           omeg(ii)=pinorm(x(nphi+ntheta+nside+i))
58         enddo      
59       endif
60       do i=4,nres
61         phi(i)=x(i-3)
62       enddo
63       if (n.eq.nphi) return
64       do i=3,nres
65         theta(i)=x(i-2+nphi)
66         if (theta(i).eq.pi) theta(i)=0.99d0*pi
67         x(i-2+nphi)=theta(i)
68       enddo
69       return
70       end
71 c-------------------------------------------------------------------------
72       logical function convert_side(alphi,omegi)
73       implicit none
74       double precision alphi,omegi
75       double precision pinorm
76       include 'COMMON.GEO'
77       convert_side=.false.
78 C Apply periodicity restrictions.
79       if (alphi.gt.pi) then
80         alphi=dwapi-alphi
81         omegi=pinorm(omegi+pi)
82         convert_side=.true.
83       endif
84       return
85       end
86 c-------------------------------------------------------------------------
87       logical function reduce(x)
88 C
89 C Apply periodic restrictions to variables.
90 C
91       implicit real*8 (a-h,o-z)
92       include 'DIMENSIONS'
93       include 'COMMON.VAR'
94       include 'COMMON.CHAIN'
95       include 'COMMON.GEO'
96       logical zm,zmiana,convert_side
97       dimension x(nvar)
98       zmiana=.false.
99       do i=4,nres
100         x(i-3)=pinorm(x(i-3))
101       enddo
102       if (nvar.gt.nphi+ntheta) then
103         do i=1,nside
104           ii=nphi+ntheta+i
105           iii=ii+nside
106           x(ii)=thetnorm(x(ii))
107           x(iii)=pinorm(x(iii))
108 C Apply periodic restrictions.
109           zm=convert_side(x(ii),x(iii))
110           zmiana=zmiana.or.zm
111         enddo      
112       endif
113       if (nvar.eq.nphi) return
114       do i=3,nres
115         ii=i-2+nphi
116         iii=i-3
117         x(ii)=dmod(x(ii),dwapi)
118 C Apply periodic restrictions.
119         if (x(ii).gt.pi) then
120           zmiana=.true.
121           x(ii)=dwapi-x(ii)
122           if (iii.gt.0) x(iii)=pinorm(x(iii)+pi)
123           if (i.lt.nres) x(iii+1)=pinorm(x(iii+1)+pi)
124           ii=ialph(i-1,1)
125           if (ii.gt.0) then
126             x(ii)=dmod(pi-x(ii),dwapi)
127             x(ii+nside)=pinorm(-x(ii+nside))
128             zm=convert_side(x(ii),x(ii+nside))
129           endif
130         else if (x(ii).lt.-pi) then
131           zmiana=.true.
132           x(ii)=dwapi+x(ii)
133           ii=ialph(i-1,1)
134           if (ii.gt.0) then
135             x(ii)=dmod(pi-x(ii),dwapi)
136             x(ii+nside)=pinorm(-pi-x(ii+nside))
137             zm=convert_side(x(ii),x(ii+nside))
138           endif
139         else if (x(ii).lt.0.0d0) then
140           zmiana=.true.
141           x(ii)=-x(ii)
142           if (iii.gt.0) x(iii)=pinorm(x(iii)+pi)
143           if (i.lt.nres) x(iii+1)=pinorm(x(iii+1)+pi)
144           ii=ialph(i-1,1)
145           if (ii.gt.0) then
146             x(ii+nside)=pinorm(-x(ii+nside))
147             zm=convert_side(x(ii),x(ii+nside))
148           endif
149         endif 
150       enddo
151       reduce=zmiana
152       return
153       end
154 c--------------------------------------------------------------------------
155       double precision function thetnorm(x)
156 C This function puts x within [0,2Pi].
157       implicit none
158       double precision x,xx
159       include 'COMMON.GEO'
160       xx=dmod(x,dwapi)
161       if (xx.lt.0.0d0) xx=xx+dwapi
162       if (xx.gt.0.9999d0*pi) xx=0.9999d0*pi
163       thetnorm=xx
164       return
165       end 
166 C--------------------------------------------------------------------
167       subroutine var_to_geom_restr(n,xx)
168 C
169 C Update geometry parameters according to the variable array.
170 C
171       implicit real*8 (a-h,o-z)
172       include 'DIMENSIONS'
173       include 'COMMON.VAR'
174       include 'COMMON.CHAIN'
175       include 'COMMON.GEO'
176       include 'COMMON.IOUNITS'
177       dimension x(maxvar),xx(maxvar)
178       logical change,reduce
179
180       call xx2x(x,xx)
181       change=reduce(x)
182       do i=1,nside
183           ii=ialph(i,2)
184           alph(ii)=x(nphi+ntheta+i)
185           omeg(ii)=pinorm(x(nphi+ntheta+nside+i))
186       enddo      
187       do i=4,nres
188         phi(i)=x(i-3)
189       enddo
190       do i=3,nres
191         theta(i)=x(i-2+nphi)
192         if (theta(i).eq.pi) theta(i)=0.99d0*pi
193         x(i-2+nphi)=theta(i)
194       enddo
195       return
196       end
197 c-------------------------------------------------------------------------