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