c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ###############################################################
c     ##                                                           ##
c     ##  subroutine makepdb  --  convert Cartesian to PDB format  ##
c     ##                                                           ##
c     ###############################################################
c
c
c     "makexyz" converts a set of Cartesian coordinates to Protein
c     Data Bank format with special handling for systems consisting
c     of polypeptide chains, ligands and water molecules
c
c
      subroutine makepdb
      implicit none
      include 'sizes.i'
      include 'aminos.i'
      include 'atmtyp.i'
      include 'atoms.i'
      include 'couple.i'
      include 'files.i'
      include 'molcul.i'
      include 'pdb.i'
      include 'sequen.i'
      integer i,j,k,m,kp,iseq,start,stop
      integer pdbnum,justify,freeunit
      integer noxy,nhydro,nres,cbi
      integer ni(maxatm),cai(maxatm)
      integer ci(maxatm),oi(maxatm)
      character*3 pdbres
      character*4 pdbnam
      character*7 moltyp
      character*60 seqfile
      logical exist,nbone,obone
      logical water(maxatm),hetmol(maxatm)
c
c
c     get atomic number of each atom and count the molecules
c
c     call katom
c     call molecule
c
c     assume molecule is a polypeptide if sequence file exists
c
      iseq = freeunit ()
      seqfile = filename(1:leng)//'.seq'
      call version (seqfile,'old')
      inquire (file=seqfile,exist=exist)
      if (exist) then
         moltyp = 'peptide'
         open (unit=iseq,file=seqfile,status='old')
         rewind (unit=iseq)
         call readseq (iseq)
         close (unit=iseq)
      else
         moltyp = 'generic'
      end if
c
c     check each molecule to see if it is a water molecule
c
      do i = 1, nmol
         water(i) = .false.
         if (imol(2,i)-imol(1,i) .eq. 2) then
            noxy = 0
            nhydro = 0
            do j = imol(1,i), imol(2,i)
               k = kmol(j)
               if (atomic(k) .eq. 8)  noxy = noxy + 1
               if (atomic(k) .eq. 1)  nhydro = nhydro + 1
            end do
            if (noxy.eq.1 .and. nhydro.eq.2)  water(i) = .true.
         end if
      end do
c
c     for general structures, transfer each atom to the PDB format
c
      if (moltyp .eq. 'generic') then
         do i = 1, nmol
            do j = imol(1,i), imol(2,i)
               k = kmol(j)
               pdbnam = ' '//name(k)
               if (water(i)) then
                  pdbres = 'HOH'
               else
                  justify = 0
                  call numeral (type(k),pdbres,justify)
               end if
               pdbnum = i
               call pdbatm (pdbnam,pdbres,pdbnum,k)
               pdbtyp(npdb) = 'HETATM'
            end do
         end do
         do i = 1, nmol
            do j = imol(1,i), imol(2,i)
               k = kmol(j)
               kp = pdblist(k)
               npdb12(kp) = n12(k)
               do m = 1, n12(k)
                  ipdb12(m,kp) = pdblist(i12(m,k))
               end do
            end do
         end do
      end if
c
c     find the amide nitrogens and then the other backbone atoms
c
      if (moltyp .eq. 'peptide') then
         nres = 0
         call attach
         do i = 1, n
            if (atomic(i) .eq. 7) then
               nbone = .false.
               obone = .false.
               do j = 1, n14(i)
                  k = i14(j,i)
                  if (atomic(k) .eq. 7) then
                     nbone = .true.
                  else if (atomic(k) .eq. 8) then
                     obone = .true.
                  end if
               end do
               if (nbone .and. obone) then
                  nres = nres + 1
                  ni(nres) = i
                  cai(nres) = i + 1
                  ci(nres) = i + 2
                  oi(nres) = i + 3
               end if
            end if
         end do
c
c     get all of the atoms for each amino acid residue in order
c
         npdb = 0
         do m = 1, nchain
            start = ichain(1,m)
            stop = ichain(2,m)
            do i = start, stop
               pdbres = amino(seqtyp(i))
               call pdbatm (' N  ',pdbres,i,ni(i))
               call pdbatm (' CA ',pdbres,i,cai(i))
               call pdbatm (' C  ',pdbres,i,ci(i))
               call pdbatm (' O  ',pdbres,i,oi(i))
               call getside (i,pdbres,ci(i),cai(i),cbi)
               if (i .eq. stop) then
                  do j = 1, n12(ci(i))
                     k = i12(j,ci(i))
                     if (atomic(k).eq.8 .and. k.ne.oi(i)) then
                        call pdbatm (' OXT',pdbres,i,k)
                        goto 10
                     end if
                  end do
   10             continue
               end if
               call gethydro (i,m,pdbres,ni(i),cai(i),cbi)
            end do
         end do
      end if
c
c     find any ligands and waters in a polypeptide system
c
      if (moltyp .eq. 'peptide') then
         do i = 1, nmol
            hetmol(i) = .true.
         end do
         do i = 1, npdb
            hetmol(molcule(i)) = .false.
         end do
         do i = 1, nmol
            if (hetmol(i)) then
               do j = imol(1,i), imol(2,i)
                  k = kmol(j)
                  pdbnam = ' '//name(k)
                  if (water(i)) then
                     pdbres = 'HOH'
                  else
                     justify = 0
                     call numeral (type(k),pdbres,justify)
                  end if
                  pdbnum = nseq + i - 1
                  call pdbatm (pdbnam,pdbres,pdbnum,k)
                  pdbtyp(npdb) = 'HETATM'
               end do
            end if
         end do
         do i = 1, nmol
            if (hetmol(i)) then
               do j = imol(1,i), imol(2,i)
                  k = kmol(j)
                  kp = pdblist(k)
                  npdb12(kp) = n12(k)
                  do m = 1, n12(k)
                     ipdb12(m,kp) = pdblist(i12(m,k))
                  end do
               end do
            end if
         end do
      end if
      return
      end
c
c
c     #######################################################
c     ##                                                   ##
c     ##  subroutine pdbatm  --  add atom to the PDB file  ##
c     ##                                                   ##
c     #######################################################
c
c
c     "pdbatm" adds an atom to the Protein Data Bank file
c
c
      subroutine pdbatm (pdbnam,pdbres,ires,icoord)
      implicit none
      include 'sizes.i'
      include 'atoms.i'
      include 'pdb.i'
      integer ires,icoord
      character*3 pdbres
      character*4 pdbnam
c
c
c     for each atom set the sequential number, record type, atom
c     name, residue name, residue number and atomic coordinates
c
      npdb = npdb + 1
      pdbtyp(npdb) = 'ATOM  '
      atmnam(npdb) = pdbnam
      resnam(npdb) = pdbres
      resnum(npdb) = ires
      xpdb(npdb) = x(icoord)
      ypdb(npdb) = y(icoord)
      zpdb(npdb) = z(icoord)
      npdb12(npdb) = 0
      pdblist(icoord) = npdb
      return
      end
c
c
c     ########################################################
c     ##                                                    ##
c     ##  subroutine getside  --  extract side chain atoms  ##
c     ##                                                    ##
c     ########################################################
c
c
c     "getside" finds the side chain heavy atoms for a single
c     amino acid residue and copies the names and coordinates
c     to the Protein Data Bank file
c
c
      subroutine getside (ires,pdbres,ci,cai,cbi)
      implicit none
      include 'sizes.i'
      include 'atmtyp.i'
      include 'atoms.i'
      include 'couple.i'
      include 'sequen.i'
      integer i,j,ires,ci,cai,cbi
      character*3 pdbres
c
c
c     if the residue is a glycine, there is no side chain
c
      cbi = 0
      if (seq(ires).eq.'G' .or. seq(ires).eq.'X')  return
c
c     find the beta carbon atom for the current residue
c
      do i = 1, n
         if (i.ne.ci .and. atomic(i).eq.6) then
            do j = 1, 4
               if (i12(j,i) .eq. cai) then
                  cbi = i
                  if (seq(ires) .ne. 'B') then
                     call pdbatm (' CB ',pdbres,ires,i)
                  else
                     call pdbatm (' CB1',pdbres,ires,i)
                  end if
                  goto 10
               end if
            end do
         end if
      end do
c
c     now hunt for the other side chain atoms
c
   10 continue
      goto (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,270), seqtyp(ires)
c
c     glycine residue  (GLY)
c
   20 continue
      return
c
c     alanine residue  (ALA)
c
   30 continue
      return
c
c     valine residue  (VAL)
c
   40 continue
      call pdbatm (' CG1',pdbres,ires,cbi+1)
      call pdbatm (' CG2',pdbres,ires,cbi+2)
      return
c
c     leucine residue  (LEU)
c
   50 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD1',pdbres,ires,cbi+2)
      call pdbatm (' CD2',pdbres,ires,cbi+3)
      return
c
c     isoleucine residue  (ILE)
c
   60 continue
      call pdbatm (' CG1',pdbres,ires,cbi+1)
      call pdbatm (' CG2',pdbres,ires,cbi+2)
      call pdbatm (' CD1',pdbres,ires,cbi+3)
      return
c
c     serine residue  (SER)
c
   70 continue
      call pdbatm (' OG ',pdbres,ires,cbi+1)
      return
c
c     threonine residue  (THR)
c
   80 continue
      call pdbatm (' OG1',pdbres,ires,cbi+1)
      call pdbatm (' CG2',pdbres,ires,cbi+2)
      return
c
c     cysteine residue  (CYS)
c
   90 continue
      call pdbatm (' SG ',pdbres,ires,cbi+1)
      return
c
c     proline residue  (PRO)
c
  100 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD ',pdbres,ires,cbi+2)
      return
c
c     phenylalanine residue  (PHE)
c
  110 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD1',pdbres,ires,cbi+2)
      call pdbatm (' CD2',pdbres,ires,cbi+3)
      call pdbatm (' CE1',pdbres,ires,cbi+4)
      call pdbatm (' CE2',pdbres,ires,cbi+5)
      call pdbatm (' CZ ',pdbres,ires,cbi+6)
      return
c
c     tyrosine residue  (TYR)
c
  120 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD1',pdbres,ires,cbi+2)
      call pdbatm (' CD2',pdbres,ires,cbi+3)
      call pdbatm (' CE1',pdbres,ires,cbi+4)
      call pdbatm (' CE2',pdbres,ires,cbi+5)
      call pdbatm (' CZ ',pdbres,ires,cbi+6)
      call pdbatm (' OH ',pdbres,ires,cbi+7)
      return
c
c     tryptophan residue  (TRP)
c
  130 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD1',pdbres,ires,cbi+2)
      call pdbatm (' CD2',pdbres,ires,cbi+3)
      call pdbatm (' NE1',pdbres,ires,cbi+4)
      call pdbatm (' CE2',pdbres,ires,cbi+5)
      call pdbatm (' CE3',pdbres,ires,cbi+6)
      call pdbatm (' CZ2',pdbres,ires,cbi+7)
      call pdbatm (' CZ3',pdbres,ires,cbi+8)
      call pdbatm (' CH2',pdbres,ires,cbi+9)
      return
c
c     histidine (HD and HE) residue  (HIS)
c
  140 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' ND1',pdbres,ires,cbi+2)
      call pdbatm (' CD2',pdbres,ires,cbi+3)
      call pdbatm (' CE1',pdbres,ires,cbi+4)
      call pdbatm (' NE2',pdbres,ires,cbi+5)
      return
c
c     histidine (HD only) residue  (HID)
c
  150 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' ND1',pdbres,ires,cbi+2)
      call pdbatm (' CD2',pdbres,ires,cbi+3)
      call pdbatm (' CE1',pdbres,ires,cbi+4)
      call pdbatm (' NE2',pdbres,ires,cbi+5)
      return
c
c     histidine (HE only) residue  (HIE)
c
  160 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' ND1',pdbres,ires,cbi+2)
      call pdbatm (' CD2',pdbres,ires,cbi+3)
      call pdbatm (' CE1',pdbres,ires,cbi+4)
      call pdbatm (' NE2',pdbres,ires,cbi+5)
      return
c
c     aspartic acid residue  (ASP)
c
  170 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' OD1',pdbres,ires,cbi+2)
      call pdbatm (' OD2',pdbres,ires,cbi+3)
      return
c
c     asparagine residue  (ASN)
c
  180 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' OD1',pdbres,ires,cbi+2)
      call pdbatm (' ND2',pdbres,ires,cbi+3)
      return
c
c     glutamic acid residue  (GLU)
c
  190 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD ',pdbres,ires,cbi+2)
      call pdbatm (' OE1',pdbres,ires,cbi+3)
      call pdbatm (' OE2',pdbres,ires,cbi+4)
      return
c
c     glutamine residue  (GLN)
c
  200 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD ',pdbres,ires,cbi+2)
      call pdbatm (' OE1',pdbres,ires,cbi+3)
      call pdbatm (' NE2',pdbres,ires,cbi+4)
      return
c
c     methionine residue  (MET)
c
  210 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' SD ',pdbres,ires,cbi+2)
      call pdbatm (' CE ',pdbres,ires,cbi+3)
      return
c
c     lysine residue  (LYS)
c
  220 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD ',pdbres,ires,cbi+2)
      call pdbatm (' CE ',pdbres,ires,cbi+3)
      call pdbatm (' NZ ',pdbres,ires,cbi+4)
      return
c
c     arginine residue  (ARG)
c
  230 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD ',pdbres,ires,cbi+2)
      call pdbatm (' NE ',pdbres,ires,cbi+3)
      call pdbatm (' CZ ',pdbres,ires,cbi+4)
      call pdbatm (' NH1',pdbres,ires,cbi+5)
      call pdbatm (' NH2',pdbres,ires,cbi+6)
      return
c
c     ornithine residue  (ORN)
c
  240 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD ',pdbres,ires,cbi+2)
      call pdbatm (' NE ',pdbres,ires,cbi+3)
      return
c
c     methylalanine residue  (AIB)
c
  250 continue
      call pdbatm (' CB2',pdbres,ires,cbi+1)
      return
c
c     pyroglutamic acid residue  (PCA)
c
  260 continue
      call pdbatm (' CG ',pdbres,ires,cbi+1)
      call pdbatm (' CD ',pdbres,ires,cbi+2)
      call pdbatm (' OE ',pdbres,ires,cbi+3)
      return
c
c     unknown residue  (UNK)
c
  270 continue
      return
      end
c
c
c     #######################################################
c     ##                                                   ##
c     ##  subroutine gethydro  --  extract hydrogen atoms  ##
c     ##                                                   ##
c     #######################################################
c
c
c     "gethydro" finds the side chain hydrogen atoms for
c     a single amino acid residue and copies the names
c     and coordinates to the Protein Data Bank file
c
c
      subroutine gethydro (ires,jchain,pdbres,ni,cai,cbi)
      implicit none
      include 'sizes.i'
      include 'atmtyp.i'
      include 'atoms.i'
      include 'couple.i'
      include 'sequen.i'
      integer i,nh,hca
      integer ires,jchain
      integer ni,cai,cbi
      character*3 pdbres
      character*4 pdbnam
      logical allatom,disulf
c
c
c     get any terminal hydrogen atoms for an N-terminal residue
c
      if (ires .ne. ichain(1,jchain)) then
         if (seq(ires) .ne. 'P') then
            do i = 1, n
               if (atomic(i).eq.1 .and. i12(1,i).eq.ni) then
                  call pdbatm (' H  ',pdbres,ires,i)
                  goto 10
               end if
            end do
         end if
c
c     get any amide hydrogen atoms for other current residues
c
      else
         if (seq(ires) .eq. 'P') then
            nh = 0
            do i = 1, n
               if (atomic(i).eq.1 .and. i12(1,i).eq.ni) then
                  nh = nh + 1
                  if (nh .eq. 1) then
                     pdbnam = '1H  '
                  else if (nh .eq. 2) then
                     pdbnam = '2H  '
                  end if
                  call pdbatm (pdbnam,pdbres,ires,i)
                  if (nh .eq. 2)  goto 10
               end if
            end do
         else if (seq(ires) .eq. 'J') then
            do i = 1, n
               if (atomic(i).eq.1 .and. i12(1,i).eq.ni) then
                  pdbnam = ' H  '
                  call pdbatm (pdbnam,pdbres,ires,i)
                  goto 10
               end if
            end do
         else
            nh = 0
            do i = 1, n
               if (atomic(i).eq.1 .and. i12(1,i).eq.ni) then
                  nh = nh + 1
                  if (nh .eq. 1) then
                     pdbnam = '1H  '
                  else if (nh .eq. 2) then
                     pdbnam = '2H  '
                  else if (nh .eq. 3) then
                     pdbnam = '3H  '
                  end if
                  call pdbatm (pdbnam,pdbres,ires,i)
                  if (nh .eq. 3)  goto 10
               end if
            end do
         end if
      end if
   10 continue
c
c     get the alpha hydrogen atom for the current residue
c
      hca = 0
      do i = 1, n
         if (atomic(i).eq.1 .and. i12(1,i).eq.cai) then
            hca = i
            if (seq(ires) .eq. 'G') then
               pdbnam = '1HA '
            else
               pdbnam = ' HA '
            end if
            call pdbatm (pdbnam,pdbres,ires,i)
            goto 20
         end if
      end do
   20 continue
c
c     if no alpha hydrogen, then united atom force field
c
      if (hca .ne. 0) then
         allatom = .true.
      else if (seq(ires) .eq. 'B') then
         if (n12(cbi) .eq. 1) then
            allatom = .false.
         else
            allatom = .true.
         end if
      else
         allatom = .false.
      end if
c
c     now hunt for the other side chain hydrogen atoms
c
      goto (30,40,50,60,70,80,90,100,110,120,
     &      130,140,150,160,170,180,190,200,
     &      210,220,230,240,250,260,270,280), seqtyp(ires)
c
c     glycine residue  (GLY)
c
   30 continue
      if (allatom) then
         call pdbatm ('2HA ',pdbres,ires,hca+1)
      end if
      return
c
c     alanine residue  (ALA)
c
   40 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+2)
         call pdbatm ('2HB ',pdbres,ires,hca+3)
         call pdbatm ('3HB ',pdbres,ires,hca+4)
      end if
      return
c
c     valine residue  (VAL)
c
   50 continue
      if (allatom) then
         call pdbatm (' HB ',pdbres,ires,hca+4)
         call pdbatm ('1HG1',pdbres,ires,hca+5)
         call pdbatm ('2HG1',pdbres,ires,hca+6)
         call pdbatm ('3HG1',pdbres,ires,hca+7)
         call pdbatm ('1HG2',pdbres,ires,hca+8)
         call pdbatm ('2HG2',pdbres,ires,hca+9)
         call pdbatm ('3HG2',pdbres,ires,hca+10)
      end if
      return
c
c     leucine residue  (LEU)
c
   60 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+5)
         call pdbatm ('2HB ',pdbres,ires,hca+6)
         call pdbatm (' HG ',pdbres,ires,hca+7)
         call pdbatm ('1HD1',pdbres,ires,hca+8)
         call pdbatm ('2HD1',pdbres,ires,hca+9)
         call pdbatm ('3HD1',pdbres,ires,hca+10)
         call pdbatm ('1HD2',pdbres,ires,hca+11)
         call pdbatm ('2HD2',pdbres,ires,hca+12)
         call pdbatm ('3HD2',pdbres,ires,hca+13)
      end if
      return
c
c     isoleucine residue  (ILE)
c
   70 continue
      if (allatom) then
         call pdbatm (' HB ',pdbres,ires,hca+5)
         call pdbatm ('1HG1',pdbres,ires,hca+6)
         call pdbatm ('2HG1',pdbres,ires,hca+7)
         call pdbatm ('1HG2',pdbres,ires,hca+8)
         call pdbatm ('2HG2',pdbres,ires,hca+9)
         call pdbatm ('3HG2',pdbres,ires,hca+10)
         call pdbatm ('1HD1',pdbres,ires,hca+11)
         call pdbatm ('2HD1',pdbres,ires,hca+12)
         call pdbatm ('3HD1',pdbres,ires,hca+13)
      end if
      return
c
c     serine residue  (SER)
c
   80 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+3)
         call pdbatm ('2HB ',pdbres,ires,hca+4)
         call pdbatm (' HG ',pdbres,ires,hca+5)
      else
         call pdbatm (' HG ',pdbres,ires,cbi+2)
      end if
      return
c
c     threonine residue  (THR)
c
   90 continue
      if (allatom) then
         call pdbatm (' HB ',pdbres,ires,hca+4)
         call pdbatm ('1HG ',pdbres,ires,hca+5)
         call pdbatm ('1HG2',pdbres,ires,hca+6)
         call pdbatm ('2HG2',pdbres,ires,hca+7)
         call pdbatm ('3HG2',pdbres,ires,hca+8)
      else
         call pdbatm ('1HG ',pdbres,ires,cbi+3)
      end if
      return
c
c     cysteine residue  (CYS)
c
  100 continue
      disulf = .false.
      do i = 1, n12(cbi+1)
         if (atomic(i12(i,cbi+1)) .eq. 16)  disulf = .true.
      end do
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+3)
         call pdbatm ('2HB ',pdbres,ires,hca+4)
         if (.not. disulf)  call pdbatm (' HG ',pdbres,ires,hca+5)
      else
         if (.not. disulf)  call pdbatm (' HG ',pdbres,ires,cbi+2)
      end if
      return
c
c     proline residue  (PRO)
c
  110 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+4)
         call pdbatm ('2HB ',pdbres,ires,hca+5)
         call pdbatm ('1HG ',pdbres,ires,hca+6)
         call pdbatm ('2HG ',pdbres,ires,hca+7)
         call pdbatm ('1HD ',pdbres,ires,hca+8)
         call pdbatm ('2HD ',pdbres,ires,hca+9)
      end if
      return
c
c     phenylalanine residue  (PHE)
c
  120 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+8)
         call pdbatm ('2HB ',pdbres,ires,hca+9)
         call pdbatm (' HD1',pdbres,ires,hca+10)
         call pdbatm (' HD2',pdbres,ires,hca+11)
         call pdbatm (' HE1',pdbres,ires,hca+12)
         call pdbatm (' HE2',pdbres,ires,hca+13)
         call pdbatm (' HZ ',pdbres,ires,hca+14)
      end if
      return
c
c     tyrosine residue  (TYR)
c
  130 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+9)
         call pdbatm ('2HB ',pdbres,ires,hca+10)
         call pdbatm (' HD1',pdbres,ires,hca+11)
         call pdbatm (' HD2',pdbres,ires,hca+12)
         call pdbatm (' HE1',pdbres,ires,hca+13)
         call pdbatm (' HE2',pdbres,ires,hca+14)
         call pdbatm (' HH ',pdbres,ires,hca+15)
      else
         call pdbatm (' HH ',pdbres,ires,cbi+8)
      end if
      return
c
c     tryptophan residue  (TRP)
c
  140 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+11)
         call pdbatm ('2HB ',pdbres,ires,hca+12)
         call pdbatm (' HD1',pdbres,ires,hca+13)
         call pdbatm (' HE1',pdbres,ires,hca+14)
         call pdbatm (' HE3',pdbres,ires,hca+15)
         call pdbatm (' HZ2',pdbres,ires,hca+16)
         call pdbatm (' HZ3',pdbres,ires,hca+17)
         call pdbatm (' HH2',pdbres,ires,hca+18)
      else
         call pdbatm (' HE1',pdbres,ires,cbi+10)
      end if
      return
c
c     histidine (HD and HE) residue  (HIS)
c
  150 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+7)
         call pdbatm ('2HB ',pdbres,ires,hca+8)
         call pdbatm (' HD1',pdbres,ires,hca+9)
         call pdbatm (' HD2',pdbres,ires,hca+10)
         call pdbatm (' HE1',pdbres,ires,hca+11)
         call pdbatm (' HE2',pdbres,ires,hca+12)
      else
         call pdbatm (' HD1',pdbres,ires,cbi+6)
         call pdbatm (' HE2',pdbres,ires,cbi+7)
      end if
      return
c
c     histidine (HD only) residue  (HID)
c
  160 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+7)
         call pdbatm ('2HB ',pdbres,ires,hca+8)
         call pdbatm (' HD1',pdbres,ires,hca+9)
         call pdbatm (' HD2',pdbres,ires,hca+10)
         call pdbatm (' HE1',pdbres,ires,hca+11)
      else
         call pdbatm (' HD1',pdbres,ires,cbi+6)
      end if
      return
c
c     histidine (HE only) residue  (HIE)
c
  170 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+7)
         call pdbatm ('2HB ',pdbres,ires,hca+8)
         call pdbatm (' HD2',pdbres,ires,hca+9)
         call pdbatm (' HE1',pdbres,ires,hca+10)
         call pdbatm (' HE2',pdbres,ires,hca+11)
      else
         call pdbatm (' HE2',pdbres,ires,cbi+6)
      end if
      return
c
c     aspartic acid residue  (ASP)
c
  180 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+5)
         call pdbatm ('2HB ',pdbres,ires,hca+6)
      end if
      return
c
c     asparagine residue  (ASN)
c
  190 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+5)
         call pdbatm ('2HB ',pdbres,ires,hca+6)
         call pdbatm ('1HD2',pdbres,ires,hca+7)
         call pdbatm ('2HD2',pdbres,ires,hca+8)
      else
         call pdbatm ('1HD2',pdbres,ires,cbi+4)
         call pdbatm ('2HD2',pdbres,ires,cbi+5)
      end if
      return
c
c     glutamic acid residue  (GLU)
c
  200 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+6)
         call pdbatm ('2HB ',pdbres,ires,hca+7)
         call pdbatm ('1HG ',pdbres,ires,hca+8)
         call pdbatm ('2HG ',pdbres,ires,hca+9)
      end if
      return
c
c     glutamine residue  (GLN)
c
  210 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+6)
         call pdbatm ('2HB ',pdbres,ires,hca+7)
         call pdbatm ('1HG ',pdbres,ires,hca+8)
         call pdbatm ('2HG ',pdbres,ires,hca+9)
         call pdbatm ('1HE2',pdbres,ires,hca+10)
         call pdbatm ('2HE2',pdbres,ires,hca+11)
      else
         call pdbatm ('1HE2',pdbres,ires,cbi+5)
         call pdbatm ('2HE2',pdbres,ires,cbi+6)
      end if
      return
c
c     methionine residue  (MET)
c
  220 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+5)
         call pdbatm ('2HB ',pdbres,ires,hca+6)
         call pdbatm ('1HG ',pdbres,ires,hca+7)
         call pdbatm ('2HG ',pdbres,ires,hca+8)
         call pdbatm ('1HE ',pdbres,ires,hca+9)
         call pdbatm ('2HE ',pdbres,ires,hca+10)
         call pdbatm ('3HE ',pdbres,ires,hca+11)
      end if
      return
c
c     lysine residue  (LYS)
c
  230 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+6)
         call pdbatm ('2HB ',pdbres,ires,hca+7)
         call pdbatm ('1HG ',pdbres,ires,hca+8)
         call pdbatm ('2HG ',pdbres,ires,hca+9)
         call pdbatm ('1HD ',pdbres,ires,hca+10)
         call pdbatm ('2HD ',pdbres,ires,hca+11)
         call pdbatm ('1HE ',pdbres,ires,hca+12)
         call pdbatm ('2HE ',pdbres,ires,hca+13)
         call pdbatm ('1HZ ',pdbres,ires,hca+14)
         call pdbatm ('2HZ ',pdbres,ires,hca+15)
         call pdbatm ('3HZ ',pdbres,ires,hca+16)
      else
         call pdbatm ('1HZ ',pdbres,ires,cbi+5)
         call pdbatm ('2HZ ',pdbres,ires,cbi+6)
         call pdbatm ('3HZ ',pdbres,ires,cbi+7)
      end if
      return
c
c     arginine residue  (ARG)
c
  240 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+8)
         call pdbatm ('2HB ',pdbres,ires,hca+9)
         call pdbatm ('1HG ',pdbres,ires,hca+10)
         call pdbatm ('2HG ',pdbres,ires,hca+11)
         call pdbatm ('1HD ',pdbres,ires,hca+12)
         call pdbatm ('2HD ',pdbres,ires,hca+13)
         call pdbatm (' HE ',pdbres,ires,hca+14)
         call pdbatm ('1HH1',pdbres,ires,hca+15)
         call pdbatm ('2HH1',pdbres,ires,hca+16)
         call pdbatm ('1HH2',pdbres,ires,hca+17)
         call pdbatm ('2HH2',pdbres,ires,hca+18)
      else
         call pdbatm (' HE ',pdbres,ires,cbi+7)
         call pdbatm ('1HH1',pdbres,ires,cbi+8)
         call pdbatm ('2HH1',pdbres,ires,cbi+9)
         call pdbatm ('1HH2',pdbres,ires,cbi+10)
         call pdbatm ('2HH2',pdbres,ires,cbi+11)
      end if
      return
c
c     ornithine residue  (ORN)
c
  250 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+5)
         call pdbatm ('2HB ',pdbres,ires,hca+6)
         call pdbatm ('1HG ',pdbres,ires,hca+7)
         call pdbatm ('2HG ',pdbres,ires,hca+8)
         call pdbatm ('1HD ',pdbres,ires,hca+9)
         call pdbatm ('2HD ',pdbres,ires,hca+10)
         call pdbatm ('1HE ',pdbres,ires,hca+11)
         call pdbatm ('2HE ',pdbres,ires,hca+12)
         call pdbatm ('1HE ',pdbres,ires,hca+13)
      else
         call pdbatm ('1HE ',pdbres,ires,cbi+4)
         call pdbatm ('2HE ',pdbres,ires,cbi+5)
         call pdbatm ('3HE ',pdbres,ires,cbi+6)
      end if
      return
c
c     methylalanine residue  (AIB)
c
  260 continue
      if (allatom) then
         call pdbatm ('1HB1',pdbres,ires,cbi+2)
         call pdbatm ('2HB1',pdbres,ires,cbi+3)
         call pdbatm ('3HB1',pdbres,ires,cbi+4)
         call pdbatm ('1HB2',pdbres,ires,cbi+5)
         call pdbatm ('2HB2',pdbres,ires,cbi+6)
         call pdbatm ('3HB2',pdbres,ires,cbi+7)
      end if
      return
c
c     pyroglutamic acid residue  (PCA)
c
  270 continue
      if (allatom) then
         call pdbatm ('1HB ',pdbres,ires,hca+5)
         call pdbatm ('2HB ',pdbres,ires,hca+6)
         call pdbatm ('1HG ',pdbres,ires,hca+7)
         call pdbatm ('2HG ',pdbres,ires,hca+8)
      end if
      return
c
c     unknown residue  (UNK)
c
  280 continue
      if (allatom) then
         call pdbatm ('2HA ',pdbres,ires,hca+1)
      end if
      return
      end
