Merge branch 'multichain' into lipid
[unres.git] / source / xdrfpdb / src-M / xdrf2pdb-m.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       real*4 coord(3,5000)
7       real*4 prec,time,potE,uconst,t_bath,qfrag(100)
8       real*8 etot
9       character*80 arg,seqfile,pdbfile
10       character*3 sequenc(maxres)
11       character*50 tytul
12       character*8 onethree,cfreq,cntraj,citraj
13       character*3 licz
14       character*8 ucase
15       external ucase
16       logical oneletter,iblnk
17       integer rescode
18       external rescode
19       
20       ifreq=1
21       if (iargc().lt.5) then
22         print '(2a)',
23      &   "Usage: xdrf2pdb-m one/three seqfile cxfile ntraj itraj",
24      &   " [pdbfile] [freq]"
25         stop
26       endif
27       call getarg(1,onethree)
28       onethree = ucase(onethree)
29       if (onethree.eq.'ONE') then
30         oneletter = .true.
31       else if (onethree.eq.'THREE') then
32         oneletter = .false.
33       else
34         print *,"ONE or THREE must be specified"
35       endif
36       call getarg(2,seqfile)
37       open (1,file=seqfile,status='old')
38       if (oneletter) then
39         read(1,'(80a1)',end=10,err=10) (sequenc(i)(1:1),i=1,maxres)
40    10   continue
41         nres=i
42         i=0
43         do while (.not.iblnk(sequenc(i+1)(1:1)))
44           i=i+1
45         enddo 
46         nres=i
47         do i=1,nres
48           itype(i)=rescode(i,sequenc(i),1)
49         enddo
50       else
51         read(1,'(20(a3,1x))',end=11,err=11) (sequenc(i),i=1,maxres)
52    11   continue
53         nres=i
54         i=0
55         do while (.not.iblnk(sequenc(i+1)(1:1)))
56           i=i+1
57         enddo 
58         nres=i
59         do i=1,nres
60           itype(i)=rescode(i,sequenc(i),0)
61         enddo
62         print *,nres
63         print '(20(a3,1x))',(sequenc(i),i=1,nres)
64       endif
65       call getarg(3,arg)
66       iext = index(arg,'.cx') - 1
67       if (iext.lt.0) then
68         print *,"Error - not a cx file"
69         stop
70       endif
71       call getarg(4,cntraj)
72       read (cntraj,*) ntraj
73       call getarg(5,citraj)
74       read (citraj,*) itraj
75       if (iargc().gt.5) then
76         call getarg(6,pdbfile)
77       else
78         write(licz,'(bz,i3.3)') itraj
79         pdbfile=arg(:iext)//'_'//licz//'.pdb'
80       endif
81       if (iargc().gt.6) then
82         call getarg(7,cfreq)
83         read (cfreq,*) ifreq
84       endif
85 c      print *,"ifreq",ifreq," ntraj",ntraj," itraj",itraj
86       open(9,file=pdbfile)
87       nnt = 1
88       if (itype(1).eq.21) nnt = 2
89       nct=nres
90       if (itype(nres).eq.21) nct = nres-1
91       print *,"nnt",nnt," nct",nct
92       call xdrfopen(ixdrf,arg, "r", iret)
93       kk = 0
94       do while(.true.) 
95        call xdrffloat(ixdrf, time, iret)
96        if(iret.eq.0) exit
97        kk = kk + 1
98        call xdrffloat(ixdrf, potE, iret)
99        call xdrffloat(ixdrf, uconst, iret)
100 #ifdef NEWUNRES
101        call xdrffloat(ixdrf, uconst_back, iret)
102 #endif
103        call xdrffloat(ixdrf, t_bath, iret)
104        call xdrfint(ixdrf, nss, iret) 
105        do j=1,nss
106         call xdrfint(ixdrf, ihpb(j), iret)
107         call xdrfint(ixdrf, jhpb(j), iret)
108        enddo
109        call xdrfint(ixdrf, nfrag, iret)
110        do i=1,nfrag
111         call xdrffloat(ixdrf, qfrag(i), iret)
112        enddo
113        prec=10000.0
114
115        isize=0
116        call xdrf3dfcoord(ixdrf, coord, isize, prec, iret)
117
118
119 c       write (*,'(e15.8,2e15.5,f12.5,$)') time,potE,uconst,t_bath
120 c       write (*,'(i4,$)') nss,(ihpb(j),jhpb(j),j=1,nss)
121 c       write (*,'(i4,20f7.4)') nfrag,(qfrag(i),i=1,nfrag)
122 c       write (*,'(8f10.5)') ((coord(k,j),k=1,3),j=1,isize)
123        if (mod(kk/ntraj,ifreq).eq.0 .and. mod(kk,ntraj).eq.itraj) then
124          if (isize .ne. nres+nct-nnt+1) then
125            print *,"Error: inconsistent sizes",isize,nres+nct-nnt+1
126          endif
127          do i=1,nres
128            do j=1,3
129              c(j,i)=coord(j,i)
130            enddo
131          enddo
132          ii = 0
133          do i=nnt,nct
134            ii = ii + 1 
135            do j=1,3
136              c(j,i+nres)=coord(j,ii+nres)
137            enddo
138          enddo
139          etot=potE
140          write (tytul,'(a,i6)') "Structure",kk
141          call pdbout(etot,tytul,9)
142        endif
143       enddo
144      
145       end