73e83846e1addea0cc54521386f928bea071ab78
[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) goto 18
19 c       do i=1,nres
20 c c       do intertyp=1,3
21 c          write (iout,*) "przed tosyjnymi",i,intertyp,gcart(intertyp,i)
22 c     &,gloc_sc(1,i,icg),gloc(i,icg)
23 c          enddo
24 c       enddo
25        do j=1,3
26          gcart(j,1)=gcart(j,1)+gloc(1,icg)*dphi(j,1,4)
27      &     +gloc(nres-2,icg)*dtheta(j,1,3)       
28          if(itype(2).ne.10) then
29           gcart(j,1)=gcart(j,1)+gloc(ialph(2,1),icg)*dalpha(j,1,2)+
30      &    gloc(ialph(2,1)+nside,icg)*domega(j,1,2)              
31         endif
32        enddo
33 c     Calculating the remainder of dE/ddc2
34        do j=1,3
35          gcart(j,2)=gcart(j,2)+gloc(1,icg)*dphi(j,2,4)+
36      &   gloc(nres-2,icg)*dtheta(j,2,3)+gloc(nres-1,icg)*dtheta(j,1,4)
37         if(itype(2).ne.10) then
38           gcart(j,2)=gcart(j,2)+gloc(ialph(2,1),icg)*dalpha(j,2,2)+
39      &    gloc(ialph(2,1)+nside,icg)*domega(j,2,2)
40         endif
41         if(itype(3).ne.10) then
42           gcart(j,2)=gcart(j,2)+gloc(ialph(3,1),icg)*dalpha(j,1,3)+
43      &    gloc(ialph(3,1)+nside,icg)*domega(j,1,3)
44         endif
45         if(nres.gt.4) then
46           gcart(j,2)=gcart(j,2)+gloc(2,icg)*dphi(j,1,5)
47         endif                   
48        enddo
49 c  If there are only five residues       
50        if(nres.eq.5) then
51          do j=1,3
52            gcart(j,3)=gcart(j,3)+gloc(1,icg)*dphi(j,3,4)+gloc(2,icg)*
53      &     dphi(j,2,5)+gloc(nres-1,icg)*dtheta(j,2,4)+gloc(nres,icg)*
54      &     dtheta(j,1,5)
55          if(itype(3).ne.10) then
56            gcart(j,3)=gcart(j,3)+gloc(ialph(3,1),icg)*
57      &     dalpha(j,2,3)+gloc(ialph(3,1)+nside,icg)*domega(j,2,3)
58          endif
59          if(itype(4).ne.10) then
60            gcart(j,3)=gcart(j,3)+gloc(ialph(4,1),icg)*
61      &     dalpha(j,1,4)+gloc(ialph(4,1)+nside,icg)*domega(j,1,4)
62          endif
63         enddo
64        endif
65 c    If there are more than five residues
66       if(nres.gt.5) then                           
67         do i=3,nres-3
68          do j=1,3
69           gcart(j,i)=gcart(j,i)+gloc(i-2,icg)*dphi(j,3,i+1)
70      &    +gloc(i-1,icg)*dphi(j,2,i+2)+
71      &    gloc(i,icg)*dphi(j,1,i+3)+gloc(nres+i-4,icg)*dtheta(j,2,i+1)+
72      &    gloc(nres+i-3,icg)*dtheta(j,1,i+2)
73           if(itype(i).ne.10) then
74            gcart(j,i)=gcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,2,i)+
75      &     gloc(ialph(i,1)+nside,icg)*domega(j,2,i)
76           endif
77           if(itype(i+1).ne.10) then
78            gcart(j,i)=gcart(j,i)+gloc(ialph(i+1,1),icg)*dalpha(j,1,i+1)
79      &     +gloc(ialph(i+1,1)+nside,icg)*domega(j,1,i+1)
80           endif
81          enddo
82         enddo
83       endif     
84 c  Setting dE/ddnres-2       
85       if(nres.gt.5) then
86          do j=1,3
87            gcart(j,nres-2)=gcart(j,nres-2)+gloc(nres-4,icg)*
88      &     dphi(j,3,nres-1)+gloc(nres-3,icg)*dphi(j,2,nres)
89      &     +gloc(2*nres-6,icg)*
90      &     dtheta(j,2,nres-1)+gloc(2*nres-5,icg)*dtheta(j,1,nres)
91           if(itype(nres-2).ne.10) then
92               gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-2,1),icg)*
93      &        dalpha(j,2,nres-2)+gloc(ialph(nres-2,1)+nside,icg)*
94      &        domega(j,2,nres-2)
95           endif
96           if(itype(nres-1).ne.10) then
97              gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-1,1),icg)*
98      &       dalpha(j,1,nres-1)+gloc(ialph(nres-1,1)+nside,icg)*
99      &       domega(j,1,nres-1)
100           endif
101          enddo
102       endif 
103 c  Settind dE/ddnres-1       
104        do j=1,3
105         gcart(j,nres-1)=gcart(j,nres-1)+gloc(nres-3,icg)*dphi(j,3,nres)+
106      &  gloc(2*nres-5,icg)*dtheta(j,2,nres)
107         if(itype(nres-1).ne.10) then
108           gcart(j,nres-1)=gcart(j,nres-1)+gloc(ialph(nres-1,1),icg)*
109      &    dalpha(j,2,nres-1)+gloc(ialph(nres-1,1)+nside,icg)*
110      &    domega(j,2,nres-1)
111         endif
112         enddo
113 c   The side-chain vector derivatives
114         do i=2,nres-1
115          if(itype(i).ne.10) then        
116             do j=1,3    
117               gxcart(j,i)=gxcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,3,i)
118      &        +gloc(ialph(i,1)+nside,icg)*domega(j,3,i)
119             enddo
120          endif      
121        enddo                                                                                                                                                    
122 c----------------------------------------------------------------------
123 C INTERTYP=1 SC...Ca...Ca...Ca
124 C INTERTYP=2 Ca...Ca...Ca...SC
125 C INTERTYP=3 SC...Ca...Ca...SC
126 c   calculating dE/ddc1      
127   18   continue
128 c       do i=1,nres
129 c       gloc(i,icg)=0.0D0
130 c          write (iout,*) "poczotkoawy",i,gloc_sc(1,i,icg)
131 c       enddo
132        if (nres.lt.2) return
133        if ((nres.lt.3).and.(itype(1).eq.10)) return
134        if ((itype(1).ne.10).and.(itype(1).ne.21)) then
135         do j=1,3
136 cc Derviative was calculated for oposite vector of side chain therefore
137 c there is "-" sign before gloc_sc
138          gxcart(j,1)=gxcart(j,1)-gloc_sc(1,0,icg)*
139      &     dtauangle(j,1,1,3)
140          gcart(j,1)=gcart(j,1)+gloc_sc(1,0,icg)*
141      &     dtauangle(j,1,2,3)
142           if ((itype(2).ne.10).and.(itype(2).ne.21)) then
143          gxcart(j,1)= gxcart(j,1)
144      &               -gloc_sc(3,0,icg)*dtauangle(j,3,1,3)
145          gcart(j,1)=gcart(j,1)+gloc_sc(3,0,icg)*
146      &       dtauangle(j,3,2,3)
147           endif
148        enddo
149        endif
150          if ((nres.ge.3).and.(itype(3).ne.10).and.(itype(3).ne.21))
151      & then
152          do j=1,3
153          gcart(j,1)=gcart(j,1)+gloc_sc(2,1,icg)*dtauangle(j,2,1,4)
154          enddo
155          endif
156 c   As potetnial DO NOT depend on omicron anlge their derivative is
157 c   ommited 
158 c     &     +gloc_sc(intertyp,nres-2,icg)*dtheta(j,1,3)  
159      
160 c     Calculating the remainder of dE/ddc2
161        do j=1,3
162          if((itype(2).ne.10).and.(itype(2).ne.21)) then
163            if (itype(1).ne.10) gxcart(j,2)=gxcart(j,2)+
164      &                         gloc_sc(3,0,icg)*dtauangle(j,3,3,3)
165         if ((itype(3).ne.10).and.(nres.ge.3).and.(itype(3).ne.21)) 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.21)) 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) 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
207           if (itype(i-1).ne.10) then
208            gxcart(j,i)=gxcart(j,i)+gloc_sc(3,i-2,icg)
209      &*dtauangle(j,3,3,i+1)
210           endif
211           if (itype(i+1).ne.10) then
212            gxcart(j,i)=gxcart(j,i)-gloc_sc(3,i-1,icg)
213      &*dtauangle(j,3,1,i+2)
214            gcart(j,i)=gcart(j,i)+gloc_sc(3,i-1,icg)
215      &*dtauangle(j,3,2,i+2)
216           endif
217           endif
218           if (itype(i-1).ne.10) then
219            gcart(j,i)=gcart(j,i)+gloc_sc(1,i-2,icg)*
220      &     dtauangle(j,1,3,i+1)
221           endif
222           if (itype(i+1).ne.10) then
223            gcart(j,i)=gcart(j,i)+gloc_sc(2,i-1,icg)*
224      &     dtauangle(j,2,2,i+2)
225 c          write(iout,*) "numer",i,gloc_sc(2,i-1,icg),
226 c     &    dtauangle(j,2,2,i+2)
227           endif
228           if (itype(i+2).ne.10) then
229            gcart(j,i)=gcart(j,i)+gloc_sc(2,i,icg)*
230      &     dtauangle(j,2,1,i+3)
231           endif
232          enddo
233         enddo
234       endif     
235 c  Setting dE/ddnres-1       
236       if(nres.ge.4) then
237          do j=1,3
238          if ((itype(nres-1).ne.10).and.(itype(nres-1).ne.21)) then
239          gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(2,nres-3,icg)
240      &    *dtauangle(j,2,3,nres)
241 c          write (iout,*) "gxcart(nres-1)", gloc_sc(2,nres-3,icg),
242 c     &     dtauangle(j,2,3,nres), gxcart(j,nres-1)
243          if (itype(nres-2).ne.10) then
244         gxcart(j,nres-1)=gxcart(j,nres-1)+gloc_sc(3,nres-3,icg)
245      &    *dtauangle(j,3,3,nres)
246           endif
247          if ((itype(nres).ne.10).and.(itype(nres).ne.21)) then
248         gxcart(j,nres-1)=gxcart(j,nres-1)-gloc_sc(3,nres-2,icg)
249      &    *dtauangle(j,3,1,nres+1)
250         gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(3,nres-2,icg)
251      &    *dtauangle(j,3,2,nres+1)
252           endif
253          endif
254          if ((itype(nres-2).ne.10).and.(itype(nres-2).ne.21)) then
255             gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(1,nres-3,icg)*
256      &   dtauangle(j,1,3,nres)
257          endif
258           if ((itype(nres).ne.10).and.(itype(nres).ne.21)) then
259             gcart(j,nres-1)=gcart(j,nres-1)+gloc_sc(2,nres-2,icg)*
260      &     dtauangle(j,2,2,nres+1)
261 c           write (iout,*) "gcart(nres-1)", gloc_sc(2,nres-2,icg),
262 c     &     dtauangle(j,2,2,nres+1), itype(nres-1),itype(nres)
263            endif
264          enddo
265       endif 
266 c  Settind dE/ddnres       
267        if ((nres.ge.3).and.(itype(nres).ne.10))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