c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     #############################################################
c     ##                                                         ##
c     ##  program pdbxyz  --  Brookhaven PDB to XYZ-Coordinates  ##
c     ##                                                         ##
c     #############################################################
c
c
c     "pdbxyz" takes as input a Protein Data Bank file and
c     then converts to and writes out a Cartesian coordinates
c     file and, for polypeptides, a sequence file
c
c
      program pdbxyz
      implicit none
      include 'sizes.i'
      include 'aminos.i'
      include 'atmtyp.i'
      include 'atoms.i'
      include 'couple.i'
      include 'files.i'
      include 'pdb.i'
      integer i,j,ixyz,last,freeunit
      integer next,nhij,nh(maxatm)
      real*8 rij
      character*3 resname,reslast
      character*60 coordfile
      logical peptide
c
c
c     get the Protein Data Bank file and a parameter set
c
      call initial
      call getpdb
      call field
c
c     decide whether the system contains only polypeptides
c
      peptide = .false.
      reslast = '***'
      do i = 1, npdb
         if (pdbtyp(i) .eq. 'ATOM  ') then
            resname = resnam(i)
            if (resname .ne. reslast) then
               reslast = resname
               do j = 1, maxamino
                  if (resname .eq. amino(j)) then
                     peptide = .true.
                     goto 10
                  end if
               end do
               peptide = .false.
               goto 20
   10          continue
            end if
         end if
      end do
   20 continue
c
c     special translation mechanism used for polypeptides
c
      if (peptide) then
         call ribosome
         last = n
         do i = last, 1, -1
            if (type(i) .eq. 0)  call delete (i)
         end do
c
c     use distance-based connectivity for general molecules
c
      else
         n = npdb
         do i = 1, n
            x(i) = xpdb(i)
            y(i) = ypdb(i)
            z(i) = zpdb(i)
            name(i) = atmnam(i)(2:4)
            n12(i) = 0
            next = 1
            call getnumb (resnam(i),type(i),next)
            nh(i) = 0
            if (name(i)(1:1) .eq. 'H')  nh(i) = 1
         end do
         do i = 1, n-1
            do j = i+1, n
               nhij = nh(i) + nh(j)
               rij = (x(i)-x(j))**2 + (y(i)-y(j))**2 + (z(i)-z(j))**2
               rij = sqrt(max(0.0d0,rij))
               if ((rij.lt.2.0d0 .and. nhij.eq.0) .or.
     &             (rij.lt.1.6d0 .and. nhij.eq.1)) then
                  n12(i) = n12(i) + 1
                  i12(n12(i),i) = j
                  n12(j) = n12(j) + 1
                  i12(n12(j),j) = i
               end if
            end do
         end do
      end if
c
c     sort the attached atom lists into ascending order
c
      do i = 1, n
         call sort (n12(i),i12(1,i))
      end do
c
c     write out the coordinates file
c
      ixyz = freeunit ()
      coordfile = filename(1:leng)//'.xyz'
      call version (coordfile,'new')
      open (unit=ixyz,file=coordfile,status='new')
      call prtxyz (ixyz)
      close (unit=ixyz)
      end
c
c
c     ############################################################
c     ##                                                        ##
c     ##  subroutine oldatm  --  transfer coordinates from PDB  ##
c     ##                                                        ##
c     ############################################################
c
c
c     "oldatm" get the Cartesian coordinates for an atom from
c     the Protein Data Bank file, then assigns the atom type
c     and atomic connectivities
c
c
      subroutine oldatm (i,bionum,i1,ires)
      implicit none
      include 'sizes.i'
      include 'atmtyp.i'
      include 'atoms.i'
      include 'fields.i'
      include 'iounit.i'
      include 'katoms.i'
      include 'sequen.i'
      include 'pdb.i'
      integer i,bionum,i1,ires
c
c
c     get coordinates, assign atom type, and update connectivities
c
      type(n) = biotyp(bionum)
      if (type(n) .ne. 0) then
         name(n) = symbol(type(n))
      else
         name(n) = '   '
      end if
      if (i .eq. 0) then
         write (iout,10)  bionum,ires,seq(ires)
   10    format (/,' OLDATM  --  A PDB Atom of Biotype',i4,
     &              ' is Missing in Residue',i5,'-',a1)
         call fatal
      else
         x(n) = xpdb(i)
         y(n) = ypdb(i)
         z(n) = zpdb(i)
      end if
      call addbond (n,i1)
      n = n + 1
      return
      end
c
c
c     ###########################################################
c     ##                                                       ##
c     ##  subroutine newatm  --  create and define a new atom  ##
c     ##                                                       ##
c     ###########################################################
c
c
c     "newatm" creates and defines an atom needed for the
c     Cartesian coordinates file, but which may not present
c     in the original Protein Data Bank file
c
c
      subroutine newatm (i,bionum,i1,bond,i2,angle1,i3,angle2,chiral)
      implicit none
      include 'sizes.i'
      include 'atmtyp.i'
      include 'atoms.i'
      include 'fields.i'
      include 'katoms.i'
      include 'pdb.i'
      integer i,bionum,i1,i2,i3,chiral
      real*8 bond,angle1,angle2
c
c
c     set the atom type, compute coordinates, assign
c     connectivities and increment the atom counter
c
      type(n) = biotyp(bionum)
      if (type(n) .ne. 0) then
         name(n) = symbol(type(n))
      else
         name(n) = '   '
      end if
      if (i .eq. 0) then
         call xyzatm (n,i1,bond,i2,angle1,i3,angle2,chiral)
      else
         x(n) = xpdb(i)
         y(n) = ypdb(i)
         z(n) = zpdb(i)
      end if
      call addbond (n,i1)
      n = n + 1
      return
      end
c
c
c     ############################################################
c     ##                                                        ##
c     ##  subroutine addbond  --  add a bond between two atoms  ##
c     ##                                                        ##
c     ############################################################
c
c
c     "addbond" adds entries to the attached atoms list in
c     order to generate a direct connection between two atoms
c
c
      subroutine addbond (i,j)
      implicit none
      include 'sizes.i'
      include 'couple.i'
      integer i,j
c
c
c     add connectivity between the two atoms
c
      if (i.ne.0 .and. j.ne.0) then
         n12(i) = n12(i) + 1
         i12(n12(i),i) = j
         n12(j) = n12(j) + 1
         i12(n12(j),j) = i
      end if
      return
      end
c
c
c     ############################################################
c     ##                                                        ##
c     ##  subroutine findatm  --  locate PDB atom in a residue  ##
c     ##                                                        ##
c     ############################################################
c
c
c     "findatm" locates a specific PDB atom name type within a
c     range of atoms from the PDB file, returns zero if the name
c     type was not found
c
c
      subroutine findatm (name,start,stop,ipdb)
      implicit none
      include 'sizes.i'
      include 'pdb.i'
      integer i,ipdb,start,stop
      character*4 name
c
c
c     search for the specified atom within the residue
c
      ipdb = 0
      do i = start, stop
         if (atmnam(i) .eq. name) then
            ipdb = i
            goto 10
         end if
      end do
   10 continue
      return
      end
c
c
c     #################################################################
c     ##                                                             ##
c     ##  subroutine ribosome  --  coordinate file from PDB protein  ##
c     ##                                                             ##
c     #################################################################
c
c
c     "ribosome" translates a polypeptide structure in Protein Data
c     Bank format to a Cartesian coordinate file and sequence file
c
c
      subroutine ribosome
      implicit none
      include 'sizes.i'
      include 'aminos.i'
      include 'atoms.i'
      include 'files.i'
      include 'iounit.i'
      include 'pdb.i'
      include 'sequen.i'
      integer i,k,iseq,nres,freeunit
      integer start,stop,resatm(2,maxres)
      integer na(maxres),ca(maxres),c(maxres)
      integer ncys,icys(maxres)
      integer ndisulf,idisulf(2,maxres)
      integer ntyp(maxamino),catyp(maxamino),ctyp(maxamino)
      integer hntyp(maxamino),otyp(maxamino),hatyp(maxamino)
      real*8 rik,xcys(maxres),ycys(maxres),zcys(maxres)
      character*3 resname
      character*60 seqfile
      logical newchain,midchain,endchain
c
c     biopolymer atom types for amino acid backbone atoms
c
      data ntyp   /   1,   7,  15,  25,  37,  51,  61,  73,  92,
     &              103, 118, 134, 157, 174, 190, 206, 216, 228,
     &              240, 254, 267, 283, 300, 314, 321,   1 /
      data catyp  /   2,   8,  16,  26,  38,  52,  62,  74,  93,
     &              104, 119, 135, 158, 175, 191, 207, 217, 229,
     &              241, 255, 268, 284, 301, 315, 322,   2 /
      data ctyp   /   3,   9,  17,  27,  39,  53,  63,  75,  94,
     &              105, 120, 136, 159, 176, 192, 208, 218, 230,
     &              242, 256, 269, 285, 302, 316, 323,   3 /
      data hntyp  /   4,  10,  18,  28,  40,  54,  64,  76,   0,
     &              106, 121, 137, 160, 177, 193, 209, 219, 231,
     &              243, 257, 270, 286, 303, 317, 324,   4 /
      data otyp   /   5,  11,  19,  29,  41,  55,  65,  77,  95,
     &              107, 122, 138, 161, 178, 194, 210, 220, 232,
     &              244, 258, 271, 287, 304, 318, 325,   5 /
      data hatyp  /   6,  12,  20,  30,  42,  56,  66,  78,  96,
     &              108, 123, 139, 162, 179, 195, 211, 221, 233,
     &              245, 259, 272, 288, 305,   0, 326,   6 /
c
c
c     set a pointer to the first and last atom of each residue
c
      nres = 0
      k = 0
      do i = 1, npdb
         if (pdbtyp(i) .eq. 'ATOM  ') then
            if (resnum(i) .ne. k) then
               k = resnum(i)
               if (nres .ne. 0)  resatm(2,nres) = i - 1
               nres = nres + 1
               resatm(1,nres) = i
            end if
         end if
      end do
      if (nres .ne. 0)  resatm(2,nres) = npdb
c
c     get the one-letter sequence and code for each residue
c
      nseq = nres
      do i = 1, nres
         start = resatm(1,i)
         resname = resnam(start)
         seq(i) = 'X'
         seqtyp(i) = maxamino
         do k = 1, maxamino
            if (resname .eq. amino(k)) then
               seq(i) = amino1(k)
               seqtyp(i) = k
               goto 10
            end if
         end do
   10    continue
      end do
c
c     search for potential disulfide bonds between CYS residues
c
      ncys = 0
      do i = 1, nres
         start = resatm(1,i)
         resname = resnam(start)
         if (resname .eq. 'CYS') then
            stop = resatm(2,i)
            call findatm (' SG ',start,stop,k)
            ncys = ncys + 1
            icys(ncys) = i
            xcys(ncys) = xpdb(k)
            ycys(ncys) = ypdb(k)
            zcys(ncys) = zpdb(k)
         end if
      end do
      ndisulf = 0
      do i = 1, ncys-1
         do k = i+1, ncys
            rik = sqrt((xcys(i)-xcys(k))**2 + (ycys(i)-ycys(k))**2
     &                         + (zcys(i)-zcys(k))**2)
            if (rik .le. 3.0d0) then
               ndisulf = ndisulf + 1
               idisulf(1,ndisulf) = min(icys(i),icys(k))
               idisulf(2,ndisulf) = max(icys(i),icys(k))
            end if
         end do
      end do
      do i = 1, nres
         icys(i) = 0
      end do
      do i = 1, ndisulf
         icys(idisulf(1,i)) = 1
         icys(idisulf(2,i)) = 1
      end do
c
c     set the current atom to be the first atom
c
      n = 1
      newchain = .true.
c
c     locate and assign the atoms that make up each residue
c
      do i = 1, nres
         start = resatm(1,i)
         stop = resatm(2,i)
         resname = resnam(start)
c
c     check that the maximum allowed atoms is not exceeded
c
         if (n+25 .gt. maxatm) then
            write (iout,20)  maxatm
   20       format (/,' RIBOSOME  --  The Maximum of',i6,' Atoms',
     &                 ' has been Exceeded')
            call fatal
         end if
c
c     test for the final residue of a peptide chain
c
         call findatm (' OXT',start,stop,k)
         if (k .eq. 0)  call findatm (' OT2',start,stop,k)
         if (k .eq. 0) then
            endchain = .false.
         else
            endchain = .true.
         end if
         if (newchain .or. endchain) then
            midchain = .false.
         else
            midchain = .true.
         end if
c
c     assign the amide nitrogen of the current residue
c
         na(i) = n
         call findatm (' N  ',start,stop,k)
         if (midchain) then
            if (resname.eq.'CYS' .and. icys(i).ne.0) then
               call oldatm (k,83,c(i-1),i)
            else
               call oldatm (k,ntyp(seqtyp(i)),c(i-1),i)
            end if
         else if (newchain) then
            if (resname .eq. 'GLY') then
               call oldatm (k,339,0,i)
            else if (resname .eq. 'PRO') then
               call oldatm (k,345,0,i)
            else if (resname .eq. 'PCA') then
               call oldatm (k,321,0,i)
            else
               call oldatm (k,333,0,i)
            end if
         else if (endchain) then
            if (resname .eq. 'GLY') then
               call oldatm (k,359,0,i)
            else if (resname .eq. 'PRO') then
               call oldatm (k,365,0,i)
            else
               call oldatm (k,353,c(i-1),i)
            end if
         end if
c
c     assign the alpha carbon of the current residue
c
         ca(i) = n
         call findatm (' CA ',start,stop,k)
         if (midchain .or. nres.eq.1) then
            if (resname.eq.'CYS' .and. icys(i).ne.0) then
               call oldatm (k,84,na(i),i)
            else
               call oldatm (k,catyp(seqtyp(i)),na(i),i)
            end if
         else if (newchain) then
            if (resname .eq. 'GLY') then
                call oldatm (k,340,na(i),i)
            else if (resname .eq. 'PRO') then
                call oldatm (k,346,na(i),i)
            else if (resname .eq. 'PCA') then
                call oldatm (k,322,na(i),i)
            else
                call oldatm (k,334,na(i),i)
            end if
         else if (endchain) then
            if (resname .eq. 'GLY') then
               call oldatm (k,360,na(i),i)
            else if (resname .eq. 'PRO') then
               call oldatm (k,366,na(i),i)
            else
               call oldatm (k,354,na(i),i)
            end if
         end if
c
c     assign the carbonyl carbon of the current residue
c
         c(i) = n
         call findatm (' C  ',start,stop,k)
         if (midchain) then
            if (resname.eq.'CYS' .and. icys(i).ne.0) then
               call oldatm (k,85,ca(i),i)
            else
               call oldatm (k,ctyp(seqtyp(i)),ca(i),i)
            end if
         else if (newchain) then
            if (resname .eq. 'GLY') then
               call oldatm (k,341,ca(i),i)
            else if (resname .eq. 'PRO') then
               call oldatm (k,347,ca(i),i)
            else if (resname .eq. 'PCA') then
               call oldatm (k,323,ca(i),i)
            else
               call oldatm (k,335,ca(i),i)
            end if
         else if (endchain) then
            if (resname .eq. 'GLY') then
               call oldatm (k,361,ca(i),i)
            else if (resname .eq. 'PRO') then
               call oldatm (k,367,ca(i),i)
            else
               call oldatm (k,355,ca(i),i)
            end if
         end if
c
c     assign the carbonyl oxygen of the current residue
c
         call findatm (' O  ',start,stop,k)
         if (midchain) then
            if (resname.eq.'CYS' .and. icys(i).ne.0) then
               call oldatm (k,87,c(i),i)
            else
               call oldatm (k,otyp(seqtyp(i)),c(i),i)
            end if
         else if (newchain) then
            if (resname .eq. 'GLY') then
               call oldatm (k,343,c(i),i)
            else if (resname .eq. 'PRO') then
               call oldatm (k,349,c(i),i)
            else if (resname .eq. 'PCA') then
               call oldatm (k,325,c(i),i)
            else
               call oldatm (k,337,c(i),i)
            end if
         else if (endchain) then
            if (resname .eq. 'GLY') then
               call oldatm (k,363,c(i),i)
            else if (resname .eq. 'PRO') then
               call oldatm (k,368,c(i),i)
            else
               call oldatm (k,357,c(i),i)
            end if
         end if
c
c     assign the amide hydrogens of the current residue
c
         if (midchain) then
            if (resname.eq.'CYS' .and. icys(i).ne.0) then
               call findatm (' H  ',start,stop,k)
               call newatm (k,86,na(i),1.01d0,c(i-1),119.0d0,
     &                      ca(i),119.0d0,1)
            else if (resname .ne. 'PRO') then
               call findatm (' H  ',start,stop,k)
               call newatm (k,hntyp(seqtyp(i)),na(i),1.01d0,
     &                      c(i-1),119.0d0,ca(i),119.0d0,1)
            end if
         else if (newchain) then
            if (resname .eq. 'GLY') then
               call findatm ('1H  ',start,stop,k)
               call newatm (k,342,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),180.0d0,0)
               call findatm ('2H  ',start,stop,k)
               call newatm (k,342,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),60.0d0,0)
               call findatm ('3H  ',start,stop,k)
               call newatm (k,342,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),-60.0d0,0)
            else if (resname .eq. 'PRO') then
               call findatm ('1H  ',start,stop,k)
               call newatm (k,348,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),0.0d0,0)
               call findatm ('2H  ',start,stop,k)
               call newatm (k,348,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),-120.0d0,0)
            else if (resname .eq. 'PCA') then
               call findatm (' H  ',start,stop,k)
               call newatm (k,324,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),-60.0d0,0)
            else
               call findatm ('1H  ',start,stop,k)
               call newatm (k,336,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),180.0d0,0)
               call findatm ('2H  ',start,stop,k)
               call newatm (k,336,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),60.0d0,0)
               call findatm ('3H  ',start,stop,k)
               call newatm (k,336,na(i),1.01d0,ca(i),109.5d0,
     &                      c(i),-60.0d0,0)
            end if
         else if (endchain) then
            if (resname .eq. 'GLY') then
               call findatm (' H  ',start,stop,k)
               call newatm (k,362,na(i),1.01d0,c(i-1),119.0d0,
     &                      ca(i),119.0d0,1)
            else if (resname .ne. 'PRO') then
               call findatm (' H  ',start,stop,k)
               call newatm (k,356,na(i),1.01d0,c(i-1),119.0d0,
     &                      ca(i),119.0d0,1)
            end if
         end if
c
c     assign the alpha hydrogen of the current residue
c
         if (resname .ne. 'AIB') then
            if (resname .eq. 'GLY') then
               call findatm ('1HA ',start,stop,k)
            else
               call findatm (' HA ',start,stop,k)
            end if
            if (midchain) then
               if (resname.eq.'CYS' .and. icys(i).ne.0) then
                  call newatm (k,88,ca(i),1.10d0,na(i),109.5d0,
     &                         c(i),109.5d0,-1)
               else
                  call newatm (k,hatyp(seqtyp(i)),ca(i),1.10d0,
     &                         na(i),109.5d0,c(i),109.5d0,-1)
               end if
            else if (newchain) then
               if (resname .eq. 'GLY') then
                  call newatm (k,344,ca(i),1.10d0,na(i),109.5d0,
     &                         c(i),109.5d0,-1)
               else if (resname .eq. 'PRO') then
                  call newatm (k,350,ca(i),1.10d0,na(i),109.5d0,
     &                         c(i),109.5d0,-1)
               else if (resname .eq. 'PCA') then
                  call newatm (k,326,ca(i),1.10d0,na(i),109.5d0,
     &                         c(i),109.5d0,-1)
               else
                  call newatm (k,338,ca(i),1.10d0,na(i),109.5d0,
     &                         c(i),109.5d0,-1)
               end if
            else if (endchain) then
               if (resname .eq. 'GLY') then
                  call newatm (k,364,ca(i),1.10d0,na(i),109.5d0,
     &                         c(i),109.5d0,-1)
               else if (resname .eq. 'PRO') then
                  call newatm (k,369,ca(i),1.10d0,na(i),109.5d0,
     &                         c(i),109.5d0,-1)
               else
                  call newatm (k,358,ca(i),1.10d0,na(i),109.5d0,
     &                         c(i),109.5d0,-1)
               end if
            end if
         end if
c
c     assign the side chain atoms of the current residue
c
         call addside (i,start,stop,ca(i),na(i),c(i),icys(i))
c
c     assign the terminal oxygen at the end of each peptide chain
c
         if (endchain) then
            call findatm (' OXT',start,stop,k)
            if (k .eq. 0)  call findatm (' OT2',start,stop,k)
            if (resname .eq. 'GLY') then
               call oldatm (k,363,c(i),i)
            else if (resname .eq. 'PRO') then
               call oldatm (k,368,c(i),i)
            else
               call oldatm (k,357,c(i),i)
            end if
         end if
c
c     next residue starts a new chain if current one just ended
c
         if (endchain) then
            newchain = .true.
         else
            newchain = .false.
         end if
      end do
c
c     connect the sulfur atoms involved in disulfide bonds
c
      do i = 1, ndisulf
         call addbond (icys(idisulf(1,i)),icys(idisulf(2,i)))
         if (i .eq. 1) then
            write (iout,30)
   30       format ()
         end if
         write (iout,40)  idisulf(1,i),idisulf(2,i)
   40    format (' Disulfide Bond formed between Residues :  ',2i5)
      end do
c
c     total number of atoms is one less than the current atom
c
      n = n - 1
c
c     write out the sequence file
c
      iseq = freeunit ()
      seqfile = filename(1:leng)//'.seq'
      call version (seqfile,'new')
      open (unit=iseq,file=seqfile,status='new')
      call prtseq (iseq)
      close (unit=iseq)
      return
      end
c
c
c     ################################################################
c     ##                                                            ##
c     ##  subroutine addside  --  build the amino acid side chains  ##
c     ##                                                            ##
c     ################################################################
c
c
c     "addside" builds the Cartesian coordinates file information
c     for a single amino acid sidechain; coordinates are read from
c     the Protein Data Bank file or found from internal coordinates;
c     atom types are assigned and connectivity data generated
c
c
      subroutine addside (ires,start,stop,cai,ni,ci,cystype)
      implicit none
      include 'sizes.i'
      include 'atoms.i'
      include 'sequen.i'
      integer i,ires,start,stop,cai,ni,ci,cystype
c
c
c     jump to appropriate section for the amino acid
c
      goto (10,20,30,40,50,60,70,80,90,100,
     &      110,120,130,140,150,160,170,180,
     &      190,200,210,220,230,240,250,260),  seqtyp(ires)
c
c     glycine residue  (GLY)
c
   10 continue
      call findatm ('2HA ',start,stop,i)
      if (ires .eq. 1) then
         call newatm (i,344,cai,1.10d0,ni,109.5d0,ci,109.5d0,1)
      else if (ires .eq. nseq) then
         call newatm (i,364,cai,1.10d0,ni,109.5d0,ci,109.5d0,1)
      else
         call newatm (i,6,cai,1.10d0,ni,109.5d0,ci,109.5d0,1)
      end if
      return
c
c     alanine residue  (ALA)
c
   20 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,13,cai,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,14,n-1,1.10d0,cai,110.2d0,ni,180.0d0,0)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,14,n-2,1.10d0,cai,110.2d0,ni,60.0d0,0)
      call findatm ('3HB ',start,stop,i)
      call newatm (i,14,n-3,1.10d0,cai,110.2d0,ni,-60.0d0,0)
      return
c
c     valine residue  (VAL)
c
   30 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,21,cai,ires)
      call findatm (' CG1',start,stop,i)
      call oldatm (i,23,n-1,ires)
      call findatm (' CG2',start,stop,i)
      call oldatm (i,23,n-2,ires)
      call findatm (' HB ',start,stop,i)
      call newatm (i,22,n-3,1.10d0,cai,107.0d0,n-2,108.2d0,1)
      call findatm ('1HG1',start,stop,i)
      call newatm (i,24,n-3,1.10d0,n-4,111.6d0,cai,180.0d0,0)
      call findatm ('2HG1',start,stop,i)
      call newatm (i,24,n-4,1.10d0,n-5,111.6d0,cai,60.0d0,0)
      call findatm ('3HG1',start,stop,i)
      call newatm (i,24,n-5,1.10d0,n-6,111.6d0,cai,-60.0d0,0)
      call findatm ('1HG2',start,stop,i)
      call newatm (i,24,n-5,1.10d0,n-7,111.6d0,cai,180.0d0,0)
      call findatm ('2HG2',start,stop,i)
      call newatm (i,24,n-6,1.10d0,n-8,111.6d0,cai,60.0d0,0)
      call findatm ('3HG2',start,stop,i)
      call newatm (i,24,n-7,1.10d0,n-9,111.6d0,cai,-60.0d0,0)
      return
c
c     leucine residue  (LEU)
c
   40 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,31,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,33,n-1,ires)
      call findatm (' CD1',start,stop,i)
      call oldatm (i,35,n-1,ires)
      call findatm (' CD2',start,stop,i)
      call oldatm (i,35,n-2,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,32,n-4,1.10d0,cai,107.9d0,n-3,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,32,n-5,1.10d0,cai,107.9d0,n-4,110.0d0,-1)
      call findatm (' HG ',start,stop,i)
      call newatm (i,34,n-5,1.10d0,n-6,107.0d0,n-4,108.2d0,1)
      call findatm ('1HD1',start,stop,i)
      call newatm (i,36,n-5,1.10d0,n-6,111.6d0,n-7,180.0d0,0)
      call findatm ('2HD1',start,stop,i)
      call newatm (i,36,n-6,1.10d0,n-7,111.6d0,n-8,60.0d0,0)
      call findatm ('3HD1',start,stop,i)
      call newatm (i,36,n-7,1.10d0,n-8,111.6d0,n-9,-60.0d0,0)
      call findatm ('1HD2',start,stop,i)
      call newatm (i,36,n-7,1.10d0,n-9,111.6d0,n-10,180.0d0,0)
      call findatm ('2HD2',start,stop,i)
      call newatm (i,36,n-8,1.10d0,n-10,111.6d0,n-11,60.0d0,0)
      call findatm ('3HD2',start,stop,i)
      call newatm (i,36,n-9,1.10d0,n-11,111.6d0,n-12,-60.0d0,0)
      return
c
c     isoleucine residue  (ILE)
c
   50 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,43,cai,ires)
      call findatm (' CG1',start,stop,i)
      call oldatm (i,45,n-1,ires)
      call findatm (' CG2',start,stop,i)
      call oldatm (i,47,n-2,ires)
      call findatm (' CD1',start,stop,i)
      if (i .eq. 0)  call findatm (' CD ',start,stop,i)
      call oldatm (i,49,n-2,ires)
      call findatm (' HB ',start,stop,i)
      call newatm (i,44,n-4,1.10d0,cai,107.0d0,n-3,108.2d0,-1)
      call findatm ('1HG1',start,stop,i)
      call newatm (i,46,n-4,1.10d0,n-5,109.5d0,n-2,109.5d0,1)
      call findatm ('2HG1',start,stop,i)
      call newatm (i,46,n-5,1.10d0,n-6,109.5d0,n-3,109.5d0,-1)
      call findatm ('1HG2',start,stop,i)
      call newatm (i,48,n-5,1.10d0,n-7,111.6d0,cai,180.0d0,0)
      call findatm ('2HG2',start,stop,i)
      call newatm (i,48,n-6,1.10d0,n-8,111.6d0,cai,60.0d0,0)
      call findatm ('3HG2',start,stop,i)
      call newatm (i,48,n-7,1.10d0,n-9,111.6d0,cai,-60.0d0,0)
      call findatm ('1HD1',start,stop,i)
      call newatm (i,50,n-7,1.10d0,n-9,111.6d0,n-10,180.0d0,0)
      call findatm ('2HD1',start,stop,i)
      call newatm (i,50,n-8,1.10d0,n-10,111.6d0,n-11,60.0d0,0)
      call findatm ('3HD1',start,stop,i)
      call newatm (i,50,n-9,1.10d0,n-11,111.6d0,n-12,-60.0d0,0)
      return
c
c     serine residue  (SER)
c
   60 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,57,cai,ires)
      call findatm (' OG ',start,stop,i)
      call oldatm (i,59,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,58,n-2,1.10d0,cai,109.2d0,n-1,109.5d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,58,n-3,1.10d0,cai,109.2d0,n-2,109.5d0,-1)
      call findatm (' HG ',start,stop,i)
      call newatm (i,60,n-3,0.94d0,n-4,106.9d0,cai,180.0d0,0)
      return
c
c     threonine residue  (THR)
c
   70 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,67,cai,ires)
      call findatm (' OG1',start,stop,i)
      call oldatm (i,69,n-1,ires)
      call findatm (' CG2',start,stop,i)
      call oldatm (i,71,n-2,ires)
      call findatm (' HB ',start,stop,i)
      call newatm (i,68,n-3,1.10d0,cai,107.0d0,n-2,108.2d0,-1)
      call findatm (' HG1',start,stop,i)
      call newatm (i,70,n-3,0.94d0,n-4,106.9d0,cai,180.0d0,0)
      call findatm ('1HG2',start,stop,i)
      call newatm (i,72,n-3,1.10d0,n-5,111.6d0,cai,180.0d0,0)
      call findatm ('2HG2',start,stop,i)
      call newatm (i,72,n-4,1.10d0,n-6,111.6d0,cai,60.0d0,0)
      call findatm ('3HG2',start,stop,i)
      call newatm (i,72,n-5,1.10d0,n-7,111.6d0,cai,-60.0d0,0)
      return
c
c     cysteine residue  (CYS)
c
   80 continue
      if (cystype .eq. 0) then
         call findatm (' CB ',start,stop,i)
         call oldatm (i,79,cai,ires)
         call findatm (' SG ',start,stop,i)
         call oldatm (i,81,n-1,ires)
         call findatm ('1HB ',start,stop,i)
         call newatm (i,80,n-2,1.10d0,cai,109.5d0,n-1,107.5d0,1)
         call findatm ('2HB ',start,stop,i)
         call newatm (i,80,n-3,1.10d0,cai,109.5d0,n-2,107.5d0,-1)
         call findatm (' HG ',start,stop,i)
         call newatm (i,82,n-3,1.34d0,n-4,96.0d0,cai,180.0d0,0)
      else
         call findatm (' CB ',start,stop,i)
         call oldatm (i,89,cai,ires)
         call findatm (' SG ',start,stop,i)
         call oldatm (i,91,n-1,ires)
         call findatm ('1HB ',start,stop,i)
         call newatm (i,90,n-2,1.10d0,cai,109.5d0,n-1,107.5d0,1)
         call findatm ('2HB ',start,stop,i)
         call newatm (i,90,n-3,1.10d0,cai,109.5d0,n-2,107.5d0,-1)
         cystype = n - 3
      end if
      return
c
c     proline residue  (PRO)
c
   90 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,97,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,99,n-1,ires)
      call findatm (' CD ',start,stop,i)
      call addbond (n,ni)
      if (ires .eq. 1) then
         call oldatm (i,351,n-1,ires)
      else if (ires .eq. nseq) then
         call oldatm (i,370,n-1,ires)
      else
         call oldatm (i,101,n-1,ires)
      end if
      call findatm ('1HB ',start,stop,i)
      call newatm (i,98,n-3,1.10d0,cai,111.2d0,n-2,111.2d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,98,n-4,1.10d0,cai,111.2d0,n-3,111.2d0,-1)
      call findatm ('1HG ',start,stop,i)
      call newatm (i,100,n-4,1.10d0,n-5,111.2d0,n-3,111.2d0,1)
      call findatm ('2HG ',start,stop,i)
      call newatm (i,100,n-5,1.10d0,n-6,111.2d0,n-4,111.2d0,-1)
      if (ires .eq. 1) then
         call findatm ('1HD ',start,stop,i)
         call newatm (i,352,n-5,1.10d0,n-6,111.2d0,ni,111.2d0,1)
         call findatm ('2HD ',start,stop,i)
         call newatm (i,352,n-6,1.10d0,n-7,111.2d0,ni,111.2d0,-1)
      else if (ires .eq. nseq) then
         call findatm ('1HD ',start,stop,i)
         call newatm (i,371,n-5,1.10d0,n-6,111.2d0,ni,111.2d0,1)
         call findatm ('2HD ',start,stop,i)
         call newatm (i,371,n-6,1.10d0,n-7,111.2d0,ni,111.2d0,-1)
      else
         call findatm ('1HD ',start,stop,i)
         call newatm (i,102,n-5,1.10d0,n-6,111.2d0,ni,111.2d0,1)
         call findatm ('2HD ',start,stop,i)
         call newatm (i,102,n-6,1.10d0,n-7,111.2d0,ni,111.2d0,-1)
      end if
      return
c
c     phenylalanine residue  (PHE)
c
  100 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,109,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,111,n-1,ires)
      call findatm (' CD1',start,stop,i)
      call oldatm (i,112,n-1,ires)
      call findatm (' CD2',start,stop,i)
      call oldatm (i,112,n-2,ires)
      call findatm (' CE1',start,stop,i)
      call oldatm (i,114,n-2,ires)
      call findatm (' CE2',start,stop,i)
      call oldatm (i,114,n-2,ires)
      call findatm (' CZ ',start,stop,i)
      call addbond (n,n-2)
      call oldatm (i,116,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,110,n-7,1.10d0,cai,107.9d0,n-6,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,110,n-8,1.10d0,cai,107.9d0,n-7,110.0d0,-1)
      call findatm (' HD1',start,stop,i)
      call newatm (i,113,n-7,1.09d0,n-8,120.0d0,n-9,0.0d0,0)
      call findatm (' HD2',start,stop,i)
      call newatm (i,113,n-7,1.09d0,n-9,120.0d0,n-10,0.0d0,0)
      call findatm (' HE1',start,stop,i)
      call newatm (i,115,n-7,1.09d0,n-9,120.0d0,n-10,180.0d0,0)
      call findatm (' HE2',start,stop,i)
      call newatm (i,115,n-7,1.09d0,n-9,120.0d0,n-11,180.0d0,0)
      call findatm (' HZ ',start,stop,i)
      call newatm (i,117,n-7,1.09d0,n-8,120.0d0,n-10,180.0d0,0)
      return
c
c     tyrosine residue  (TYR)
c
  110 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,124,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,126,n-1,ires)
      call findatm (' CD1',start,stop,i)
      call oldatm (i,127,n-1,ires)
      call findatm (' CD2',start,stop,i)
      call oldatm (i,127,n-2,ires)
      call findatm (' CE1',start,stop,i)
      call oldatm (i,129,n-2,ires)
      call findatm (' CE2',start,stop,i)
      call oldatm (i,129,n-2,ires)
      call findatm (' CZ ',start,stop,i)
      call addbond (n,n-2)
      call oldatm (i,131,n-1,ires)
      call findatm (' OH ',start,stop,i)
      call oldatm (i,132,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,125,n-8,1.10d0,cai,107.9d0,n-7,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,125,n-9,1.10d0,cai,107.9d0,n-8,110.0d0,-1)
      call findatm (' HD1',start,stop,i)
      call newatm (i,128,n-8,1.09d0,n-9,120.0d0,n-10,0.0d0,0)
      call findatm (' HD2',start,stop,i)
      call newatm (i,128,n-8,1.09d0,n-10,120.0d0,n-11,0.0d0,0)
      call findatm (' HE1',start,stop,i)
      call newatm (i,130,n-8,1.09d0,n-10,120.0d0,n-11,180.0d0,0)
      call findatm (' HE2',start,stop,i)
      call newatm (i,130,n-8,1.09d0,n-10,120.0d0,n-12,180.0d0,0)
      call findatm (' HH ',start,stop,i)
      call newatm (i,133,n-7,0.97d0,n-8,108.0d0,n-9,0.0d0,0)
      return
c
c     tryptophan residue  (TRP)
c
  120 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,140,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,142,n-1,ires)
      call findatm (' CD1',start,stop,i)
      call oldatm (i,143,n-1,ires)
      call findatm (' CD2',start,stop,i)
      call oldatm (i,145,n-2,ires)
      call findatm (' NE1',start,stop,i)
      call oldatm (i,146,n-2,ires)
      call findatm (' CE2',start,stop,i)
      call addbond (n,n-2)
      call oldatm (i,148,n-1,ires)
      call findatm (' CE3',start,stop,i)
      call oldatm (i,149,n-3,ires)
      call findatm (' CZ2',start,stop,i)
      call oldatm (i,151,n-2,ires)
      call findatm (' CZ3',start,stop,i)
      call oldatm (i,153,n-2,ires)
      call findatm (' CH2',start,stop,i)
      call addbond (n,n-2)
      call oldatm (i,155,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,141,n-10,1.10d0,cai,107.9d0,n-9,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,141,n-11,1.10d0,cai,107.9d0,n-10,110.0d0,-1)
      call findatm (' HD1',start,stop,i)
      call newatm (i,144,n-10,1.09d0,n-11,126.0d0,n-12,0.0d0,0)
      call findatm (' HE1',start,stop,i)
      call newatm (i,147,n-9,1.01d0,n-11,126.3d0,n-12,180.0d0,0)
      call findatm (' HE3',start,stop,i)
      call newatm (i,150,n-8,1.09d0,n-6,120.0d0,n-5,180.0d0,0)
      call findatm (' HZ2',start,stop,i)
      call newatm (i,152,n-8,1.09d0,n-6,120.0d0,n-7,180.0d0,0)
      call findatm (' HZ3',start,stop,i)
      call newatm (i,154,n-8,1.09d0,n-7,120.0d0,n-9,180.0d0,0)
      call findatm (' HH2',start,stop,i)
      call newatm (i,156,n-8,1.09d0,n-9,120.0d0,n-11,180.0d0,0)
      return
c
c     histidine (HD and HE) residue  (HIS)
c
  130 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,163,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,165,n-1,ires)
      call findatm (' ND1',start,stop,i)
      call oldatm (i,166,n-1,ires)
      call findatm (' CD2',start,stop,i)
      call oldatm (i,168,n-2,ires)
      call findatm (' CE1',start,stop,i)
      call oldatm (i,170,n-2,ires)
      call findatm (' NE2',start,stop,i)
      call addbond (n,n-2)
      call oldatm (i,172,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,164,n-6,1.10d0,cai,107.9d0,n-5,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,164,n-7,1.10d0,cai,107.9d0,n-6,110.0d0,-1)
      call findatm (' HD1',start,stop,i)
      call newatm (i,167,n-6,1.02d0,n-4,126.0d0,n-3,180.0d0,0)
      call findatm (' HD2',start,stop,i)
      call newatm (i,169,n-6,1.09d0,n-4,126.0d0,n-5,180.0d0,0)
      call findatm (' HE1',start,stop,i)
      call newatm (i,171,n-6,1.09d0,n-5,126.0d0,n-7,180.0d0,0)
      call findatm (' HE2',start,stop,i)
      call newatm (i,173,n-6,1.02d0,n-7,126.0d0,n-9,180.0d0,0)
      return
c
c     histidine (HD only) residue  (HID)
c
  140 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,180,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,182,n-1,ires)
      call findatm (' ND1',start,stop,i)
      call oldatm (i,183,n-1,ires)
      call findatm (' CD2',start,stop,i)
      call oldatm (i,185,n-2,ires)
      call findatm (' CE1',start,stop,i)
      call oldatm (i,187,n-2,ires)
      call findatm (' NE2',start,stop,i)
      call addbond (n,n-2)
      call oldatm (i,189,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,181,n-6,1.10d0,cai,107.9d0,n-5,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,181,n-7,1.10d0,cai,107.9d0,n-6,110.0d0,-1)
      call findatm (' HD1',start,stop,i)
      call newatm (i,184,n-6,1.02d0,n-4,126.0d0,n-3,180.0d0,0)
      call findatm (' HD2',start,stop,i)
      call newatm (i,186,n-6,1.09d0,n-4,126.0d0,n-5,180.0d0,0)
      call findatm (' HE1',start,stop,i)
      call newatm (i,188,n-6,1.09d0,n-5,126.0d0,n-7,180.0d0,0)
      return
c
c     histidine (HE only) residue  (HIE)
c
  150 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,196,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,198,n-1,ires)
      call findatm (' ND1',start,stop,i)
      call oldatm (i,199,n-1,ires)
      call findatm (' CD2',start,stop,i)
      call oldatm (i,200,n-2,ires)
      call findatm (' CE1',start,stop,i)
      call oldatm (i,202,n-2,ires)
      call findatm (' NE2',start,stop,i)
      call addbond (n,n-2)
      call oldatm (i,204,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,197,n-6,1.10d0,cai,107.9d0,n-5,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,197,n-7,1.10d0,cai,107.9d0,n-6,110.0d0,-1)
      call findatm (' HD2',start,stop,i)
      call newatm (i,201,n-5,1.09d0,n-3,126.0d0,n-4,180.0d0,0)
      call findatm (' HE1',start,stop,i)
      call newatm (i,203,n-5,1.09d0,n-4,126.0d0,n-6,180.0d0,0)
      call findatm (' HE2',start,stop,i)
      call newatm (i,205,n-5,1.02d0,n-6,126.0d0,n-8,180.0d0,0)
      return
c
c     aspartic acid residue  (ASP)
c
  160 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,212,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,214,n-1,ires)
      call findatm (' OD1',start,stop,i)
      call oldatm (i,215,n-1,ires)
      call findatm (' OD2',start,stop,i)
      call oldatm (i,215,n-2,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,213,n-4,1.10d0,cai,107.9d0,n-3,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,213,n-5,1.10d0,cai,107.9d0,n-4,110.0d0,-1)
      return
c
c     asparagine residue  (ASN)
c
  170 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,222,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,224,n-1,ires)
      call findatm (' OD1',start,stop,i)
      call oldatm (i,225,n-1,ires)
      call findatm (' ND2',start,stop,i)
      call oldatm (i,226,n-2,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,223,n-4,1.10d0,cai,107.9d0,n-3,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,223,n-5,1.10d0,cai,107.9d0,n-4,110.0d0,-1)
      call findatm ('1HD2',start,stop,i)
      call newatm (i,227,n-3,1.01d0,n-5,120.9d0,n-6,0.0d0,0)
      call findatm ('2HD2',start,stop,i)
      call newatm (i,227,n-4,1.01d0,n-6,120.3d0,n-7,180.0d0,0)
      return
c
c     glutamic acid residue  (GLU)
c
  180 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,234,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,236,n-1,ires)
      call findatm (' CD ',start,stop,i)
      call oldatm (i,238,n-1,ires)
      call findatm (' OE1',start,stop,i)
      call oldatm (i,239,n-1,ires)
      call findatm (' OE2',start,stop,i)
      call oldatm (i,239,n-2,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,235,n-5,1.10d0,cai,107.9d0,n-4,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,235,n-6,1.10d0,cai,107.9d0,n-5,110.0d0,-1)
      call findatm ('1HG ',start,stop,i)
      call newatm (i,237,n-6,1.10d0,n-7,109.5d0,n-5,109.5d0,1)
      call findatm ('2HG ',start,stop,i)
      call newatm (i,237,n-7,1.10d0,n-8,109.5d0,n-6,109.5d0,-1)
      return
c
c     glutamine residue  (GLN)
c
  190 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,246,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,248,n-1,ires)
      call findatm (' CD ',start,stop,i)
      call oldatm (i,250,n-1,ires)
      call findatm (' OE1',start,stop,i)
      call oldatm (i,251,n-1,ires)
      call findatm (' NE2',start,stop,i)
      call oldatm (i,252,n-2,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,247,n-5,1.10d0,cai,107.9d0,n-4,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,247,n-6,1.10d0,cai,107.9d0,n-5,110.0d0,-1)
      call findatm ('1HG ',start,stop,i)
      call newatm (i,249,n-6,1.10d0,n-7,109.5d0,n-5,109.5d0,1)
      call findatm ('2HG ',start,stop,i)
      call newatm (i,249,n-7,1.10d0,n-8,109.5d0,n-6,109.5d0,-1)
      call findatm ('1HE2',start,stop,i)
      call newatm (i,253,n-5,1.01d0,n-7,120.9d0,n-8,0.0d0,0)
      call findatm ('2HE2',start,stop,i)
      call newatm (i,253,n-6,1.01d0,n-8,120.3d0,n-9,180.0d0,0)
      return
c
c     methionine residue  (MET)
c
  200 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,260,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,262,n-1,ires)
      call findatm (' SD ',start,stop,i)
      call oldatm (i,264,n-1,ires)
      call findatm (' CE ',start,stop,i)
      call oldatm (i,265,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,261,n-4,1.10d0,cai,107.9d0,n-3,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,261,n-5,1.10d0,cai,107.9d0,n-4,110.0d0,-1)
      call findatm ('1HG ',start,stop,i)
      call newatm (i,263,n-5,1.10d0,n-6,109.5d0,n-4,109.5d0,1)
      call findatm ('2HG ',start,stop,i)
      call newatm (i,263,n-6,1.10d0,n-7,109.5d0,n-5,109.5d0,-1)
      call findatm ('1HE ',start,stop,i)
      call newatm (i,266,n-5,1.10d0,n-6,110.2d0,n-7,180.0d0,0)
      call findatm ('2HE ',start,stop,i)
      call newatm (i,266,n-6,1.10d0,n-7,110.2d0,n-8,60.0d0,0)
      call findatm ('3HE ',start,stop,i)
      call newatm (i,266,n-7,1.10d0,n-8,110.2d0,n-9,-60.0d0,0)
      return
c
c     lysine residue  (LYS)
c
  210 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,273,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,275,n-1,ires)
      call findatm (' CD ',start,stop,i)
      call oldatm (i,277,n-1,ires)
      call findatm (' CE ',start,stop,i)
      call oldatm (i,279,n-1,ires)
      call findatm (' NZ ',start,stop,i)
      call oldatm (i,281,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,274,n-5,1.10d0,cai,107.9d0,n-4,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,274,n-6,1.10d0,cai,107.9d0,n-5,110.0d0,-1)
      call findatm ('1HG ',start,stop,i)
      call newatm (i,276,n-6,1.10d0,n-7,109.5d0,n-5,109.5d0,1)
      call findatm ('2HG ',start,stop,i)
      call newatm (i,276,n-7,1.10d0,n-8,109.5d0,n-6,109.5d0,-1)
      call findatm ('1HD ',start,stop,i)
      call newatm (i,278,n-7,1.10d0,n-8,109.5d0,n-6,109.5d0,1)
      call findatm ('2HD ',start,stop,i)
      call newatm (i,278,n-8,1.10d0,n-9,109.5d0,n-7,109.5d0,-1)
      call findatm ('1HE ',start,stop,i)
      call newatm (i,280,n-8,1.10d0,n-9,110.9d0,n-7,107.3d0,1)
      call findatm ('2HE ',start,stop,i)
      call newatm (i,280,n-9,1.10d0,n-10,110.9d0,n-8,107.3d0,-1)
      call findatm ('1HZ ',start,stop,i)
      call newatm (i,282,n-9,1.04d0,n-10,110.5d0,n-11,180.0d0,0)
      call findatm ('2HZ ',start,stop,i)
      call newatm (i,282,n-10,1.04d0,n-11,110.5d0,n-12,60.0d0,0)
      call findatm ('3HZ ',start,stop,i)
      call newatm (i,282,n-11,1.04d0,n-12,110.5d0,n-13,-60.0d0,0)
      return
c
c     arginine residue  (ARG)
c
  220 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,289,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,291,n-1,ires)
      call findatm (' CD ',start,stop,i)
      call oldatm (i,293,n-1,ires)
      call findatm (' NE ',start,stop,i)
      call oldatm (i,295,n-1,ires)
      call findatm (' CZ ',start,stop,i)
      call oldatm (i,297,n-1,ires)
      call findatm (' NH1',start,stop,i)
      call oldatm (i,298,n-1,ires)
      call findatm (' NH2',start,stop,i)
      call oldatm (i,298,n-2,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,290,n-7,1.10d0,cai,107.9d0,n-6,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,290,n-8,1.10d0,cai,107.9d0,n-7,110.0d0,-1)
      call findatm ('1HG ',start,stop,i)
      call newatm (i,292,n-8,1.10d0,n-9,109.5d0,n-7,109.5d0,1)
      call findatm ('2HG ',start,stop,i)
      call newatm (i,292,n-9,1.10d0,n-10,109.5d0,n-8,109.5d0,-1)
      call findatm ('1HD ',start,stop,i)
      call newatm (i,294,n-9,1.10d0,n-10,109.5d0,n-8,109.5d0,1)
      call findatm ('2HD ',start,stop,i)
      call newatm (i,294,n-10,1.10d0,n-11,109.5d0,n-9,109.5d0,-1)
      call findatm (' HE ',start,stop,i)
      call newatm (i,296,n-10,1.01d0,n-11,118.5d0,n-9,120.0d0,1)
      call findatm ('1HH1',start,stop,i)
      call newatm (i,299,n-9,1.01d0,n-10,122.5d0,n-11,0.0d0,0)
      call findatm ('2HH1',start,stop,i)
      call newatm (i,299,n-10,1.01d0,n-11,118.8d0,n-12,180.0d0,0)
      call findatm ('1HH2',start,stop,i)
      call newatm (i,299,n-10,1.01d0,n-12,122.5d0,n-13,0.0d0,0)
      call findatm ('2HH2',start,stop,i)
      call newatm (i,299,n-11,1.01d0,n-13,118.8d0,n-14,180.0d0,0)
      return
c
c     ornithine residue  (ORN)
c
  230 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,306,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,308,n-1,ires)
      call findatm (' CD ',start,stop,i)
      call oldatm (i,310,n-1,ires)
      call findatm (' NE ',start,stop,i)
      call oldatm (i,312,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,307,n-4,1.10d0,cai,107.9d0,n-3,110.0d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,307,n-5,1.10d0,cai,107.9d0,n-4,110.0d0,-1)
      call findatm ('1HG ',start,stop,i)
      call newatm (i,309,n-5,1.10d0,n-7,109.5d0,n-4,109.5d0,1)
      call findatm ('2HG ',start,stop,i)
      call newatm (i,309,n-6,1.10d0,n-8,109.5d0,n-5,109.5d0,-1)
      call findatm ('1HD ',start,stop,i)
      call newatm (i,311,n-6,1.10d0,n-8,109.5d0,n-5,109.5d0,1)
      call findatm ('2HD ',start,stop,i)
      call newatm (i,311,n-7,1.10d0,n-9,109.5d0,n-6,109.5d0,-1)
      call findatm ('1HE ',start,stop,i)
      call newatm (i,313,n-7,1.04d0,n-8,110.5d0,n-9,180.0d0,0)
      call findatm ('2HE ',start,stop,i)
      call newatm (i,313,n-8,1.04d0,n-9,110.5d0,n-10,60.0d0,0)
      call findatm ('3HE ',start,stop,i)
      call newatm (i,313,n-9,1.04d0,n-10,110.5d0,n-11,-60.0d0,0)
      return
c
c     methylalanine residue  (AIB)
c
  240 continue
      call findatm (' CB1',start,stop,i)
      call oldatm (i,319,cai,ires)
      call findatm (' CB2',start,stop,i)
      call oldatm (i,319,cai,ires)
      call findatm ('1HB1',start,stop,i)
      call newatm (i,320,n-2,1.10d0,cai,110.2d0,ni,180.0d0,0)
      call findatm ('2HB1',start,stop,i)
      call newatm (i,320,n-3,1.10d0,cai,110.2d0,ni,60.0d0,0)
      call findatm ('3HB1',start,stop,i)
      call newatm (i,320,n-4,1.10d0,cai,110.2d0,ni,-60.0d0,0)
      call findatm ('1HB2',start,stop,i)
      call newatm (i,320,n-4,1.10d0,cai,110.2d0,ni,180.0d0,0)
      call findatm ('2HB2',start,stop,i)
      call newatm (i,320,n-5,1.10d0,cai,110.2d0,ni,60.0d0,0)
      call findatm ('3HB2',start,stop,i)
      call newatm (i,320,n-6,1.10d0,cai,110.2d0,ni,-60.0d0,0)
      return
c
c     pyroglutamic acid residue  (PCA)
c
  250 continue
      call findatm (' CB ',start,stop,i)
      call oldatm (i,327,cai,ires)
      call findatm (' CG ',start,stop,i)
      call oldatm (i,329,n-1,ires)
      call findatm (' CD ',start,stop,i)
      call addbond (n,ni)
      call oldatm (i,331,n-1,ires)
      call findatm (' OE ',start,stop,i)
      call oldatm (i,332,n-1,ires)
      call findatm ('1HB ',start,stop,i)
      call newatm (i,328,n-4,1.10d0,cai,111.2d0,n-3,111.2d0,1)
      call findatm ('2HB ',start,stop,i)
      call newatm (i,328,n-5,1.10d0,cai,111.2d0,n-4,111.2d0,-1)
      call findatm ('1HG ',start,stop,i)
      call newatm (i,330,n-5,1.10d0,n-6,111.2d0,n-4,111.2d0,1)
      call findatm ('2HG ',start,stop,i)
      call newatm (i,330,n-6,1.10d0,n-7,111.2d0,n-5,111.2d0,-1)
      return
c
c     unknown residue  (UNK)
c
  260 continue
      call newatm (0,6,cai,1.10d0,ni,109.5d0,ci,109.5d0,1)
      return
      end
