12ebe530b1b7a340304349a61177617fcbdb6b6c
[unres.git] / int_to_cart.f
1        subroutine int_to_cart
2 c--------------------------------------------------------------         
3 c  This subroutine converts the energy derivatives from internal 
4 c  coordinates to cartesian coordinates
5 c-------------------------------------------------------------
6       implicit real*8 (a-h,o-z)
7       include 'DIMENSIONS'
8       include 'COMMON.VAR'
9       include 'COMMON.CHAIN'
10       include 'COMMON.DERIV'
11       include 'COMMON.GEO'
12       include 'COMMON.LOCAL'
13       include 'COMMON.INTERACT'
14       include 'COMMON.MD'
15       include 'COMMON.IOUNITS'
16       include 'COMMON.SCCOR' 
17 c   calculating dE/ddc1      
18        if (nres.lt.3) go to 18
19        do j=1,3
20          gcart(j,1)=gcart(j,1)+gloc(1,icg)*dphi(j,1,4)
21      &     +gloc(nres-2,icg)*dtheta(j,1,3)       
22          if(itype(2).ne.10) then
23           gcart(j,1)=gcart(j,1)+gloc(ialph(2,1),icg)*dalpha(j,1,2)+
24      &    gloc(ialph(2,1)+nside,icg)*domega(j,1,2)              
25         endif
26        enddo
27 C      write (iout,*) "????A CO TO??"
28 c     Calculating the remainder of dE/ddc2
29        do j=1,3
30          gcart(j,2)=gcart(j,2)+gloc(1,icg)*dphi(j,2,4)+
31      &   gloc(nres-2,icg)*dtheta(j,2,3)+gloc(nres-1,icg)*dtheta(j,1,4)
32         if((itype(2).ne.10).and.(itype(2).ne.ntyp1)) then
33           gcart(j,2)=gcart(j,2)+gloc(ialph(2,1),icg)*dalpha(j,2,2)+
34      &    gloc(ialph(2,1)+nside,icg)*domega(j,2,2)
35         endif
36         if((itype(3).ne.10).and.(itype(3).ne.21)) then
37           gcart(j,2)=gcart(j,2)+gloc(ialph(3,1),icg)*dalpha(j,1,3)+
38      &    gloc(ialph(3,1)+nside,icg)*domega(j,1,3)
39         endif
40         if(nres.gt.4) then
41           gcart(j,2)=gcart(j,2)+gloc(2,icg)*dphi(j,1,5)
42         endif                   
43        enddo
44 c  If there are only five residues       
45        if(nres.eq.5) then
46          do j=1,3
47            gcart(j,3)=gcart(j,3)+gloc(1,icg)*dphi(j,3,4)+gloc(2,icg)*
48      &     dphi(j,2,5)+gloc(nres-1,icg)*dtheta(j,2,4)+gloc(nres,icg)*
49      &     dtheta(j,1,5)
50          if(itype(3).ne.10) then
51            gcart(j,3)=gcart(j,3)+gloc(ialph(3,1),icg)*
52      &     dalpha(j,2,3)+gloc(ialph(3,1)+nside,icg)*domega(j,2,3)
53          endif
54          if(itype(4).ne.10) then
55            gcart(j,3)=gcart(j,3)+gloc(ialph(4,1),icg)*
56      &     dalpha(j,1,4)+gloc(ialph(4,1)+nside,icg)*domega(j,1,4)
57          endif
58         enddo
59        endif
60 C      write (iout,*) "Poniezej blad??",ialph(3,1),nside,ialph(4,1)
61 c    If there are more than five residues
62       if(nres.gt.5) then                           
63         do i=3,nres-3
64          do j=1,3
65           gcart(j,i)=gcart(j,i)+gloc(i-2,icg)*dphi(j,3,i+1)
66      &    +gloc(i-1,icg)*dphi(j,2,i+2)+
67      &    gloc(i,icg)*dphi(j,1,i+3)+gloc(nres+i-4,icg)*dtheta(j,2,i+1)+
68      &    gloc(nres+i-3,icg)*dtheta(j,1,i+2)
69           if((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
70            gcart(j,i)=gcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,2,i)+
71      &     gloc(ialph(i,1)+nside,icg)*domega(j,2,i)
72           endif
73           if((itype(i+1).ne.10).and.(itype(i+1).ne.ntyp1)) then
74            gcart(j,i)=gcart(j,i)+gloc(ialph(i+1,1),icg)*dalpha(j,1,i+1)
75      &     +gloc(ialph(i+1,1)+nside,icg)*domega(j,1,i+1)
76           endif
77          enddo
78         enddo
79       endif     
80 c  Setting dE/ddnres-2      
81 C      write(iout,*) "ATUCHUJ?" 
82       if(nres.gt.5) then
83          do j=1,3
84            gcart(j,nres-2)=gcart(j,nres-2)+gloc(nres-4,icg)*
85      &     dphi(j,3,nres-1)+gloc(nres-3,icg)*dphi(j,2,nres)
86      &     +gloc(2*nres-6,icg)*
87      &     dtheta(j,2,nres-1)+gloc(2*nres-5,icg)*dtheta(j,1,nres)
88           if((itype(nres-2).ne.10).and.(itype(nres-2).ne.ntyp1)) then
89               gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-2,1),icg)*
90      &        dalpha(j,2,nres-2)+gloc(ialph(nres-2,1)+nside,icg)*
91      &        domega(j,2,nres-2)
92           endif
93           if((itype(nres-1).ne.10).and.(itype(nres-1).ne.ntyp1)) then
94              gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-1,1),icg)*
95      &       dalpha(j,1,nres-1)+gloc(ialph(nres-1,1)+nside,icg)*
96      &       domega(j,1,nres-1)
97           endif
98          enddo
99       endif 
100 c  Settind dE/ddnres-1       
101        do j=1,3
102         gcart(j,nres-1)=gcart(j,nres-1)+gloc(nres-3,icg)*dphi(j,3,nres)+
103      &  gloc(2*nres-5,icg)*dtheta(j,2,nres)
104         if((itype(nres-1).ne.10).and.(itype(nres-1).ne.ntyp1)) then
105           gcart(j,nres-1)=gcart(j,nres-1)+gloc(ialph(nres-1,1),icg)*
106      &    dalpha(j,2,nres-1)+gloc(ialph(nres-1,1)+nside,icg)*
107      &    domega(j,2,nres-1)
108         endif
109         enddo
110 c   The side-chain vector derivatives
111         do i=2,nres-1
112          if(itype(i).ne.10 .and. itype(i).ne.ntyp1) then        
113             do j=1,3    
114               gxcart(j,i)=gxcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,3,i)
115      &        +gloc(ialph(i,1)+nside,icg)*domega(j,3,i)
116             enddo
117          endif      
118        enddo
119 C       write(iout,*) "TU DOCHODZE"
120                                                                                                                                                         
121 c----------------------------------------------------------------------
122 C INTERTYP=1 SC...Ca...Ca...Ca
123 C INTERTYP=2 Ca...Ca...Ca...SC
124 C INTERTYP=3 SC...Ca...Ca...SC
125 c   calculating dE/ddc1      
126   18   continue
127 c       do i=1,nres
128 c       gloc(i,icg)=0.0D0
129 c          write (iout,*) "poczotkoawy",i,gloc_sc(1,i,icg)
130 c       enddo
131        if (nres.lt.2) return
132        if ((nres.lt.3).and.(itype(1).eq.10)) return
133        if ((itype(1).ne.10).and.(itype(1).ne.ntyp1)) then
134         do j=1,3
135 cc Derviative was calculated for oposite vector of side chain therefore
136 c there is "-" sign before gloc_sc
137          gxcart(j,1)=gxcart(j,1)-gloc_sc(1,0,icg)*
138      &     dtauangle(j,1,1,3)
139          gcart(j,1)=gcart(j,1)+gloc_sc(1,0,icg)*
140      &     dtauangle(j,1,2,3)
141           if ((itype(2).ne.10).and.(itype(2).ne.ntyp1)) then
142          gxcart(j,1)= gxcart(j,1)
143      &               -gloc_sc(3,0,icg)*dtauangle(j,3,1,3)
144          gcart(j,1)=gcart(j,1)+gloc_sc(3,0,icg)*
145      &       dtauangle(j,3,2,3)
146           endif
147        enddo
148        endif
149          if ((nres.ge.3).and.(itype(3).ne.10).and.(itype(3).ne.ntyp1))
150      & then
151          do j=1,3
152          gcart(j,1)=gcart(j,1)+gloc_sc(2,1,icg)*dtauangle(j,2,1,4)
153          enddo
154          endif
155 c   As potetnial DO NOT depend on omicron anlge their derivative is
156 c   ommited 
157 c     &     +gloc_sc(intertyp,nres-2,icg)*dtheta(j,1,3)  
158
159 c     Calculating the remainder of dE/ddc2
160        do j=1,3
161          if((itype(2).ne.10).and.(itype(2).ne.ntyp1)) then
162            if (itype(1).ne.10) gxcart(j,2)=gxcart(j,2)+
163      &                         gloc_sc(3,0,icg)*dtauangle(j,3,3,3)
164         if ((itype(3).ne.10).and.(nres.ge.3).and.(itype(3).ne.ntyp1))
165      &   then
166            gxcart(j,2)=gxcart(j,2)-gloc_sc(3,1,icg)*dtauangle(j,3,1,4)
167 cc                  the   - above is due to different vector direction
168            gcart(j,2)=gcart(j,2)+gloc_sc(3,1,icg)*dtauangle(j,3,2,4)
169           endif
170           if (nres.gt.3) then
171            gxcart(j,2)=gxcart(j,2)-gloc_sc(1,1,icg)*dtauangle(j,1,1,4)
172 cc                  the   - above is due to different vector direction
173            gcart(j,2)=gcart(j,2)+gloc_sc(1,1,icg)*dtauangle(j,1,2,4)
174 c          write(iout,*) gloc_sc(1,1,icg),dtauangle(j,1,2,4),"gcart"
175 c           write(iout,*) gloc_sc(1,1,icg),dtauangle(j,1,1,4),"gx"
176           endif
177          endif
178          if ((itype(1).ne.10).and.(itype(1).ne.ntyp1)) then
179           gcart(j,2)=gcart(j,2)+gloc_sc(1,0,icg)*dtauangle(j,1,3,3)
180 c           write(iout,*)  gloc_sc(1,0,icg),dtauangle(j,1,3,3)
181         endif
182          if ((itype(3).ne.10).and.(nres.ge.3)) then
183           gcart(j,2)=gcart(j,2)+gloc_sc(2,1,icg)*dtauangle(j,2,2,4)
184 c           write(iout,*) gloc_sc(2,1,icg),dtauangle(j,2,2,4)
185          endif
186          if ((itype(4).ne.10).and.(nres.ge.4)) then
187           gcart(j,2)=gcart(j,2)+gloc_sc(2,2,icg)*dtauangle(j,2,1,5)
188 c           write(iout,*) gloc_sc(2,2,icg),dtauangle(j,2,1,5)
189          endif
190
191 c      write(iout,*) gcart(j,2),itype(2),itype(1),itype(3), "gcart2"
192        enddo
193 c    If there are more than five residues
194       if(nres.ge.5) then                        
195         do i=3,nres-2
196          do j=1,3
197 c          write(iout,*) "before", gcart(j,i)
198           if ((itype(i).ne.10).and.(itype(i).ne.ntyp1)) then
199           gxcart(j,i)=gxcart(j,i)+gloc_sc(2,i-2,icg)
200      &    *dtauangle(j,2,3,i+1)
201      &    -gloc_sc(1,i-1,icg)*dtauangle(j,1,1,i+2)
202           gcart(j,i)=gcart(j,i)+gloc_sc(1,i-1,icg)
203      &    *dtauangle(j,1,2,i+2)
204 c                   write(iout,*) "new",j,i,
205 c     &  gcart(j,i),gloc_sc(1,i-1,icg),dtauangle(j,1,2,i+2)
206           if (itype(i-1).ne.10) then
207            gxcart(j,i)=gxcart(j,i)+gloc_sc(3,i-2,icg)
208      &*dtauangle(j,3,3,i+1)
209           endif
210           if (itype(i+1).ne.10) then
211            gxcart(j,i)=gxcart(j,i)-gloc_sc(3,i-1,icg)
212      &*dtauangle(j,3,1,i+2)
213            gcart(j,i)=gcart(j,i)+gloc_sc(3,i-1,icg)
214      &*dtauangle(j,3,2,i+2)
215           endif
216           endif
217           if (itype(i-1).ne.10) then
218            gcart(j,i)=gcart(j,i)+gloc_sc(1,i-2,icg)*
219      &     dtauangle(j,1,3,i+1)
220           endif
221           if (itype(i+1).ne.10) then
222            gcart(j,i)=gcart(j,i)+gloc_sc(2,i-1,icg)*
223      &     dtauangle(j,2,2,i+2)
224 c          write(iout,*) "numer",i,gloc_sc(2,i-1,icg),
225 c     &    dtauangle(j,2,2,i+2)
226           endif
227           if (itype(i+2).ne.10) then
228            gcart(j,i)=gcart(j,i)+gloc_sc(2,i,icg)*
229      &     dtauangle(j,2,1,i+3)
230           endif
231          enddo
232         enddo
233       endif     
234 c  Setting dE/ddnres-1       
235       if(nres.ge.4) then
236          do j=1,3
237          if ((itype(nres-1).ne.10).and.(itype(nres-1).ne.ntyp1)) then
238          gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(2,nres-3,icg)
239      &    *dtauangle(j,2,3,nres)
240 c          write (iout,*) "gxcart(nres-1)", gloc_sc(2,nres-3,icg),
241 c     &     dtauangle(j,2,3,nres), gxcart(j,nres-1)
242          if (itype(nres-2).ne.10) then
243         gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(3,nres-3,icg)
244      &    *dtauangle(j,3,3,nres)
245           endif
246          if ((itype(nres).ne.10).and.(itype(nres).ne.ntyp1)) then
247         gxcart(j,nres-1)=gxcart(j,nres-1)-gloc_sc(3,nres-2,icg)
248      &    *dtauangle(j,3,1,nres+1)
249         gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(3,nres-2,icg)
250      &    *dtauangle(j,3,2,nres+1)
251           endif
252          endif
253          if ((itype(nres-2).ne.10).and.(itype(nres-2).ne.ntyp1)) then
254             gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(1,nres-3,icg)*
255      &   dtauangle(j,1,3,nres)
256          endif
257           if ((itype(nres).ne.10).and.(itype(nres).ne.ntyp1)) then
258             gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(2,nres-2,icg)*
259      &     dtauangle(j,2,2,nres+1)
260 c           write (iout,*) "gcart(nres-1)", gloc_sc(2,nres-2,icg),
261 c     &     dtauangle(j,2,2,nres+1), itype(nres-1),itype(nres)
262            endif
263          enddo
264       endif
265 c  Settind dE/ddnres       
266        if ((nres.ge.3).and.(itype(nres).ne.10).and.
267      &    (itype(nres).ne.ntyp1))then
268        do j=1,3
269         gxcart(j,nres)=gxcart(j,nres)+gloc_sc(3,nres-2,icg)
270      & *dtauangle(j,3,3,nres+1)+gloc_sc(2,nres-2,icg)
271      & *dtauangle(j,2,3,nres+1)
272         enddo
273        endif
274 c   The side-chain vector derivatives
275       return
276       end       
277         
278