Added Makefiles
[unres.git] / source / xdrfpdb / src / xdrf2ang.f
1       implicit real*8 (a-h,o-z)
2       include 'DIMENSIONS'
3       include 'COMMON.CHAIN'
4       include 'COMMON.INTERACT'
5       include 'COMMON.SBRIDGE'
6       include 'COMMON.NAMES'
7       include 'COMMON.GEO'
8       real*4 coord(3,2*maxres)
9       real*4 prec,time,potE,uconst,t_bath,qfrag(100)
10       real*8 etot
11       character*80 arg,seqfile,angfile
12       character*3 sequenc(maxres)
13       character*50 tytul
14       character*8 onethree,cfreq
15       character*8 ucase
16       external ucase
17       logical oneletter,iblnk
18       integer rescode
19       external rescode
20       
21       pi = 4.0d0*datan(1.0d0)
22       deg2rad=pi/180.0d0
23       rad2deg=1.0d0/deg2rad
24
25       ifreq=1
26       is=1
27       ie=1000000000
28       if (iargc().lt.3) then
29         print '(2a)',
30      &    "Usage: xdrf2ang one/three seqfile cxfile [freq]",
31      &    " [start] [end] [angfile]"
32         stop
33       endif
34       call getarg(1,onethree)
35       onethree = ucase(onethree)
36       if (onethree.eq.'ONE') then
37         oneletter = .true.
38       else if (onethree.eq.'THREE') then
39         oneletter = .false.
40       else
41         print *,"ONE or THREE must be specified"
42       endif
43       call getarg(2,seqfile)
44       open (1,file=seqfile,status='old')
45       if (oneletter) then
46         read(1,'(80a1)',end=10,err=10) (sequenc(i)(1:1),i=1,maxres)
47    10   continue
48         nres=i
49         i=0
50         do while (.not.iblnk(sequenc(i+1)(1:1)))
51 c        do while (.not.(iblnk(sequenc(i+1)(1:1)) == 0) )
52           i=i+1
53         enddo 
54         nres=i
55         do i=1,nres
56           itype(i)=rescode(i,sequenc(i),1)
57         enddo
58       else
59         read(1,'(20(a3,1x))',end=11,err=11) (sequenc(i),i=1,maxres)
60    11   continue
61         nres=i
62         i=0
63         do while (.not.iblnk(sequenc(i+1)(1:1)))
64 c        do while (.not.(iblnk(sequenc(i+1)(1:1)) == 0) )
65           i=i+1
66         enddo 
67         nres=i
68         do i=1,nres
69           itype(i)=rescode(i,sequenc(i),0)
70         enddo
71       endif
72       call getarg(3,arg)
73       iext = index(arg,'.cx') - 1
74       if (iext.lt.0) then
75         print *,"Error - not a cx file"
76         stop
77       endif
78       if (iargc().gt.3) then
79         call getarg(4,cfreq)
80         read (cfreq,*) ifreq
81       endif
82       if (iargc().gt.4) then
83         call getarg(5,cfreq)
84         read (cfreq,*) is
85       endif
86       if (iargc().gt.5) then
87         call getarg(6,cfreq)
88         read (cfreq,*) ie
89       endif
90       if (iargc().gt.6) then
91         call getarg(7,angfile)
92       else
93         angfile=arg(:iext)//'.ang'
94       endif
95       open(9,file=angfile)
96       nnt = 1
97       if (itype(1).eq.21) nnt = 2
98       nct=nres
99       if (itype(nres).eq.21) nct = nres-1
100       print *,"nnt",nnt," nct",nct
101       print *,"file",arg
102       call xdrfopen(ixdrf,arg, "r", iret)
103       if (iret.eq.0) stop
104       print *,"iret",iret
105       print *,"is",is," ie",ie
106       kk = 0
107       do while(is.eq.0 .or. kk.lt.ie) 
108 c       call xdrfint(ixdrf, ic, iret)
109 c       print *,ic
110        call xdrffloat(ixdrf, time, iret)
111        print *,"time",time," iret",iret
112        if(iret.eq.0) exit
113        kk = kk + 1
114        call xdrffloat(ixdrf, potE, iret)
115        call xdrffloat(ixdrf, uconst, iret)
116        call xdrffloat(ixdrf, uconst_back, iret)
117 c       print *,"potE",potE," uconst",uconst," uconst_back",uconst_back
118        call xdrffloat(ixdrf, t_bath, iret)
119 c       print *,"t_bath",t_bath
120        call xdrfint(ixdrf, nss, iret) 
121 c       print *,"nss",nss
122        do j=1,nss
123         call xdrfint(ixdrf, ihpb(j), iret)
124         call xdrfint(ixdrf, jhpb(j), iret)
125        enddo
126        call xdrfint(ixdrf, nfrag, iret)
127 c       print *,"nfrag",nfrag
128        do i=1,nfrag
129         call xdrffloat(ixdrf, qfrag(i), iret)
130        enddo
131        prec=10000.0
132
133        isize=0
134        call xdrf3dfcoord(ixdrf, coord, isize, prec, iret)
135
136
137 c       write (*,'(i4,$)') nss,(ihpb(j),jhpb(j),j=1,nss)
138 c       write (*,'(i4,20f7.4)') nfrag,(qfrag(i),i=1,nfrag)
139 c       write (*,'(8f10.5)') ((coord(k,j),k=1,3),j=1,isize)
140        if (mod(kk,ifreq).eq.0) then
141          if (isize .ne. nres+nct-nnt+1) then
142            print *,"Error: inconsistent sizes",isize,nres+nct-nnt+1
143          endif
144          write (9,'(i10,e15.8,2e15.5,f12.5)') kk,time,potE,uconst,t_bath
145          do i=1,nres
146            do j=1,3
147              c(j,i)=coord(j,i)
148            enddo
149          enddo
150          ii = 0
151          do i=nnt,nct
152            ii = ii + 1 
153            do j=1,3
154              c(j,i+nres)=coord(j,ii+nres)
155            enddo
156          enddo
157          etot=potE
158          do i=2,nres-2
159            write (9,'(a3,1x,2f10.3)')
160      &       restyp(itype(i)),alpha(i-1,i,i+1)*rad2deg,
161      &       beta(i-1,i,i+1,i+2)*rad2deg
162          enddo
163          write (9,'(a3,1x,f10.3)')
164      &       restyp(itype(nres-1)),alpha(nres-2,nres-1,nres)*rad2deg
165        endif
166       enddo
167      
168       end