added source code
[unres.git] / source / unres / src_MD / old_F / int_to_cart.f.org
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       
17 c   calculating dE/ddc1      
18        if (nres.lt.3) return
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      &     +gloc(nres-2,icg)*dtheta(j,1,3)
32         if(itype(2).ne.10) 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) 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    If there are more than five residues
61       if(nres.gt.5) then                           
62         do i=3,nres-3
63          do j=1,3
64           gcart(j,i)=gcart(j,i)+gloc(i-2,icg)*dphi(j,3,i+1)
65      &    +gloc(i-1,icg)*dphi(j,2,i+2)+
66      &    gloc(i,icg)*dphi(j,1,i+3)+gloc(nres+i-4,icg)*dtheta(j,2,i+1)+
67      &    gloc(nres+i-3,icg)*dtheta(j,1,i+2)
68           if(itype(i).ne.10) then
69            gcart(j,i)=gcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,2,i)+
70      &     gloc(ialph(i,1)+nside,icg)*domega(j,2,i)
71           endif
72           if(itype(i+1).ne.10) then
73            gcart(j,i)=gcart(j,i)+gloc(ialph(i+1,1),icg)*dalpha(j,1,i+1)
74      &     +gloc(ialph(i+1,1)+nside,icg)*domega(j,1,i+1)
75           endif
76          enddo
77         enddo
78       endif     
79 c  Setting dE/ddnres-2       
80       if(nres.gt.5) then
81          do j=1,3
82            gcart(j,nres-2)=gcart(j,nres-2)+gloc(nres-4,icg)*
83      &     dphi(j,3,nres-1)+gloc(nres-3,icg)*dphi(j,2,nres)
84      &     +gloc(2*nres-6,icg)*
85      &     dtheta(j,2,nres-1)+gloc(2*nres-5,icg)*dtheta(j,1,nres)
86           if(itype(nres-2).ne.10) then
87               gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-2,1),icg)*
88      &        dalpha(j,2,nres-2)+gloc(ialph(nres-2,1)+nside,icg)*
89      &        domega(j,2,nres-2)
90           endif
91           if(itype(nres-1).ne.10) then
92              gcart(j,nres-2)=gcart(j,nres-2)+gloc(ialph(nres-1,1),icg)*
93      &       dalpha(j,1,nres-1)+gloc(ialph(nres-1,1)+nside,icg)*
94      &       domega(j,1,nres-1)
95           endif
96          enddo
97       endif 
98 c  Settind dE/ddnres-1       
99        do j=1,3
100         gcart(j,nres-1)=gcart(j,nres-1)+gloc(nres-3,icg)*dphi(j,3,nres)+
101      &  gloc(2*nres-5,icg)*dtheta(j,2,nres)
102         if(itype(nres-1).ne.10) then
103           gcart(j,nres-1)=gcart(j,nres-1)+gloc(ialph(nres-1,1),icg)*
104      &    dalpha(j,2,nres-1)+gloc(ialph(nres-1,1)+nside,icg)*
105      &    domega(j,2,nres-1)
106         endif
107         enddo
108 c   The side-chain vector derivatives
109         do i=2,nres-1
110          if(itype(i).ne.10) then        
111             do j=1,3    
112               gxcart(j,i)=gxcart(j,i)+gloc(ialph(i,1),icg)*dalpha(j,3,i)
113      &        +gloc(ialph(i,1)+nside,icg)*domega(j,3,i)
114             enddo
115          endif      
116        enddo                                                                                                                                                    
117       return
118       end       
119         
120