IUBio GIL .. BIOSCI/Bionet News .. Biosequences .. Software .. FTP

PDB MODELS

Chris Haydock haydock at DIRAC.MAYO.EDU
Wed Aug 9 16:10:43 EST 1995


Here is a FORTRAN program to extract PDB models.
Each model is written into a separate file.
I wrote it and used it once.
It may require slight modification for your PDB file.
Chris Haydock  (haydock at mayo.edu)
c--------- cut here --------------------------------
      program models
c     Extract models from PDB format file.
      implicit none
      integer iargc,nmodel
      character*(80) filein,filout,st,idmod
      logical eof,done,gotit
      if (iargc().ge.1) then
        call getarg(1,filein)
      else
        write(6,'(a)') '$Input file: '
        read(5,'(a)') filein
      endif
      open(file=filein,form='formatted',status='old',
     1    access='sequential',unit=1)
      nmodel=0
   20 continue ! Repeat until (loop over models).
        gotit=.false.
   30   continue ! Repeat until (scan down to MODEL card).
          call getrec(1,st,eof)
          if (eof) then
            gotit=.true.
          elseif (st(1:5).eq.'MODEL') then
            gotit=.true.
          else
            continue
          endif
        if (.not.gotit) goto 30
        if (.not.eof) then
          nmodel=nmodel+1
          idmod=st(6:)
          call stleft(idmod)
          call nameit(filein,idmod,filout)
          open(file=filout,form='formatted',status='unknown',
     1      access='sequential',unit=2)
          done=.false.
   40     continue ! Repeat until (output down to ENDMDL card).
            call getrec(1,st,eof)
            if (eof) then
              write(6,'(a,i6,a)') ' %%ERROR, Model',nmodel,' eof.'
              stop '<models>'
            elseif (st.eq.'ENDMDL') then
              done=.true.
            else
              call fixpdb(st)
              write(2,'(a)') st
            endif
          if (.not.done) goto 40
          close (unit=2)
        endif ! (.not.eof)
      if (.not.eof) goto 20
      close (unit=1)
      write(6,'(a,i6,)') ' Number models =',nmodel
      end
      subroutine getrec(unit,st,eof)
      implicit none
      integer unit,iostat
      character*(*) st
      logical eof
      eof=.false.
      read(unit,'(a)',end=20,iostat=iostat) st
   20 if (iostat.lt.0) then
        eof=.true.
      elseif (iostat.eq.0) then
        continue
      else
        write(6,'(a,i6)') ' i/0 STATUS =',iostat
        stop '<getrec>'
      endif
      return
      end
      subroutine fixpdb(st)
      implicit none
      character*(*) st
      character*(4) atom
      character*(80) temp
      atom=st(14:index(st(14:),' ')+12)//st(13:13)
      temp=st(1:12)//atom//' '//st(18:)
      st=temp
      if (st(73:76).eq.' ') st(73:76)='XXXX'
      return
      end
      subroutine nameit(filein,fileid,filout)
      implicit none
      character*(*) filein,fileid,filout
      integer in,id
      in=min0(index(filein,' '),index(filein,'.'))
      id=index(fileid,' ')
      if ((in.eq.0).and.(id.eq.0)) then
        filout='nameit.dat'
      elseif (id.eq.0) then
        filout=filein
      elseif (in.eq.0) then
        filout=fileid
      else
        filout=filein(1:in-1)//'_'//fileid(1:id-1)//filein(in:)
      endif
      return
      end
      subroutine stleft(st)
c     Left justify character string.
      implicit none
      character*(*) st
      character*(80) temp
      integer idx
      logical gotit
      idx=0
      gotit=.false.
   20 continue ! Repeat until
        idx=idx+1
        if (idx.gt.len(st)) then
          gotit=.true.
        elseif (st(idx:idx).ne.' ') then
          gotit=.true.
        else
          continue
        endif
      if (.not.gotit) goto 20
      if (idx.gt.len(st)) then
        return
      else
        temp(1:)=st(idx:)
        st=temp
      endif
      return
      end




More information about the X-plor mailing list

Send comments to us at archive@iubioarchive.bio.net