c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1993  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ################################################################
c     ##                                                            ##
c     ##  subroutine solvate  --  macroscopic solvation parameters  ##
c     ##                                                            ##
c     ################################################################
c
c
c     "solvate" assigns macroscopic solvation energy parameters
c     for the Eisenberg-McLachlan ASP, Ooi-Scheraga SASA or 
c     Macromodel GB/SA solvation models
c
c     literature references :
c
c     L. Wesson and D. Eisenberg, "Atomic Solvation Parameters
c     Applied to Molecular Dynamics of Proteins in Solution",
c     Protein Science, 1, 227-235 (1992)  (Eisenberg-McLachlan)
c
c     T. Ooi, M. Oobatake, G. Nemethy and H. A. Scheraga, "Accessible
c     Surface Areas as a Measure of the Thermodynamic Parameters of
c     Hydration of Peptides", PNAS, 84, 3086-3090 (1987)  (SASA)
c
c     W. C. Still, A. Tempczyk, R. C. Hawley and T. Hendrickson,
c     "A Semianalytical Treatment of Solvation for Molecular
c     Mechanics and Dynamics", J. Amer. Chem. Soc., 112, 6127-6129
c     (1990)  (Macromodel GB/SA)
c
c
      subroutine solvate
      implicit none
      include 'sizes.i'
      include 'atmtyp.i'
      include 'atoms.i'
      include 'couple.i'
      include 'keys.i'
      include 'potent.i'
      include 'solute.i'
      integer i,j,k,next
      integer atmnum,brn
      character*4 solvtyp
      character*8 value
      character*20 keyword
      character*80 record,string
c
c
c     default is to not use the macroscopic solvation term
c
      use_solv = .false.
      use_gbsa = .false.
      nsolv = 0
c
c     set default values for the GB/SA solvation model
c
      reborn = 1
      bornmax = 300
c
c     search keywords for macroscopic solvation commands
c
      do i = 1, nkey
         next = 1
         record = keyline(i)
         call gettext (record,keyword,next)
         call upcase (keyword)
         if (keyword(1:8) .eq. 'SOLVATE ') then
            use_solv = .true.
            call gettext (record,value,next)
            call upcase (value)
            if (value(1:5) .eq. 'GBSA ') then
               use_gbsa = .true.
               solvtyp = 'GBSA'
               string = record(next:80)
               read (string,*,err=10,end=10)  brn
               bornmax = brn
   10          continue
            else if (value(1:5) .eq. 'SASA ') then
               solvtyp = 'SASA'
            else
               solvtyp = 'E-M'
            end if
         end if
      end do
c
c     assign the Eisenberg-McLachlan ASP solvation parameters;
c     parameters only available for protein-peptide groups
c
      if (use_solv .and. solvtyp.eq.'E-M') then
         do i = 1, n
            atmnum = atomic(i)
            if (atmnum .eq. 6) then
               nsolv = nsolv + 1
               rsolv(i) = 1.9d0
               vsolv(i) = 0.004d0
            else if (atmnum .eq. 7) then
               nsolv = nsolv + 1
               rsolv(i) = 1.7d0
               vsolv(i) = -0.113d0
               if (n12(i) .eq. 4) then
                  vsolv(i) = -0.169d0
               end if
            else if (atmnum .eq. 8) then
               nsolv = nsolv + 1
               rsolv(i) = 1.4d0
               vsolv(i) = -0.113d0
               if (n12(i).eq.1 .and. atomic(i12(1,i)).eq.6) then
                  do j = 1, n13(i)
                     k = i13(j,i)
                     if (n12(k).eq.1 .and. atomic(k).eq.8) then
                        vsolv(i) = -0.166d0
                     end if
                  end do
               end if
               do j = 1, n12(i)
                  k = i12(j,i)
                  if (atomic(k) .eq. 15)  vsolv(i) = -0.140d0
               end do
            else if (atmnum .eq. 15) then
               nsolv = nsolv + 1
               rsolv(i) = 1.9d0
               vsolv(i) = -0.140d0
            else if (atmnum .eq. 16) then
               nsolv = nsolv + 1
               rsolv(i) = 1.8d0
               vsolv(i) = -0.017d0
            else
               rsolv(i) = 0.0d0
               vsolv(i) = 0.0d0
            end if
         end do
c
c     assign the Ooi-Scheraga SASA solvation parameters;
c     parameters only available for protein-peptide groups
c
      else if (use_solv .and. solvtyp.eq.'SASA') then
         do i = 1, n
            atmnum = atomic(i)
            if (atmnum .eq. 6) then
               nsolv = nsolv + 1
               rsolv(i) = 2.0d0
               vsolv(i) = 0.008d0
               if (n12(i) .eq. 3) then
                  rsolv(i) = 1.75d0
                  vsolv(i) = -0.008d0
                  do j = 1, n12(i)
                     k = i12(j,i)
                     if (atomic(k) .eq. 8) then
                        rsolv(i) = 1.55d0
                        vsolv(i) = 0.427d0
                     end if
                  end do
               end if
            else if (atmnum .eq. 7) then
               nsolv = nsolv + 1
               rsolv(i) = 1.55d0
               vsolv(i) = -0.132d0
               if (n12(i) .eq. 4)  vsolv(i) = -1.212d0
            else if (atmnum .eq. 8) then
               nsolv = nsolv + 1
               rsolv(i) = 1.4d0
               if (n12(i) .eq. 1) then
                  vsolv(i) = -0.038d0
                  if (atomic(i12(1,i)) .eq. 6) then
                     do j = 1, n13(i)
                        k = i13(j,i)
                        if (n12(k).eq.1 .and. atomic(k).eq.8) then
                           vsolv(i) = -0.770d0
                        end if
                     end do
                  end if
               else if (n12(i) .eq. 2) then
                  vsolv(i) = -0.172d0
               end if
               do j = 1, n12(i)
                  k = i12(j,i)
                  if (atomic(k) .eq. 15)  vsolv(i) = -0.717d0
               end do
            else if (atmnum .eq. 15) then
               nsolv = nsolv + 1
               rsolv(i) = 2.1d0
               vsolv(i) = 0.0d0
            else if (atmnum .eq. 16) then
               nsolv = nsolv + 1
               rsolv(i) = 2.0d0
               vsolv(i) = -0.021d0
            else if (atmnum .eq. 17) then
               nsolv = nsolv + 1
               rsolv(i) = 2.0d0
               vsolv(i) = 0.012d0
            else
               rsolv(i) = 0.0d0
               vsolv(i) = 0.0d0
            end if
         end do
c
c     assign the GB/SA parameters for the surface area term
c
      else if (use_solv .and. solvtyp.eq.'GBSA') then
         do i = 1, n
            atmnum = atomic(i)
            vsolv(i) = 0.0072d0
            if (atmnum .eq. 1) then
               nsolv = nsolv + 1
               rsolv(i) = 1.21d0
               k = i12(1,i)
               if (atomic(k) .eq. 7)  rsolv(i) = 1.15d0
               if (atomic(k) .eq. 8)  rsolv(i) = 1.15d0
            else if (atmnum .eq. 3) then
               nsolv = nsolv + 1
               rsolv(i) = 1.432d0
            else if (atmnum .eq. 6) then
               nsolv = nsolv + 1
               rsolv(i) = 1.90d0
            else if (atmnum .eq. 7) then
               nsolv = nsolv + 1
               rsolv(i) = 1.625d0
            else if (atmnum .eq. 8) then
               nsolv = nsolv + 1
               rsolv(i) = 1.535d0
               if (n12(i) .eq. 1)  rsolv(i) = 1.48d0
            else if (atmnum .eq. 9) then
               nsolv = nsolv + 1
               rsolv(i) = 1.47d0
            else if (atmnum .eq. 11) then
               nsolv = nsolv + 1
               rsolv(i) = 1.992d0
            else if (atmnum .eq. 12) then
               nsolv = nsolv + 1
               rsolv(i) = 1.70d0
            else if (atmnum .eq. 14) then
               nsolv = nsolv + 1
               rsolv(i) = 1.80d0
            else if (atmnum .eq. 15) then
               nsolv = nsolv + 1
               rsolv(i) = 1.87d0
            else if (atmnum .eq. 16) then
               nsolv = nsolv + 1
               rsolv(i) = 1.775d0
            else if (atmnum .eq. 17) then
               nsolv = nsolv + 1
               rsolv(i) = 1.735d0
            else if (atmnum .eq. 19) then
               nsolv = nsolv + 1
               rsolv(i) = 2.123d0
            else if (atmnum .eq. 20) then
               nsolv = nsolv + 1
               rsolv(i) = 1.817d0
            else if (atmnum .eq. 35) then
               nsolv = nsolv + 1
               rsolv(i) = 1.90d0
            else if (atmnum .eq. 37) then
               nsolv = nsolv + 1
               rsolv(i) = 2.26d0
            else if (atmnum .eq. 53) then
               nsolv = nsolv + 1
               rsolv(i) = 2.10d0
            else if (atmnum .eq. 55) then
               nsolv = nsolv + 1
               rsolv(i) = 2.507d0
            else if (atmnum .eq. 56) then
               nsolv = nsolv + 1
               rsolv(i) = 2.188d0
            else
               rsolv(i) = 0.0d0
            end if
         end do
      end if
      return
      end
