c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1994  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ################################################################
c     ##                                                            ##
c     ##  subroutine smooth  --  set potential smoothing parameter  ##
c     ##                                                            ##
c     ################################################################
c
c
c     "smooth" sets extent of potential surface smoothing for use
c     with either the diffusion equation method (DEM) or Gaussian
c     density annealing (GDA) procedures
c
c
      subroutine smooth
      implicit none
      include 'sizes.i'
      include 'atoms.i'
      include 'fields.i'
      include 'inform.i'
      include 'iounit.i'
      include 'keys.i'
      include 'warp.i'
      integer i,next
      character*20 keyword
      character*80 record,string
      logical query,exist
c
c
c     set the default value for the deformation parameter
c
      deform = 0.0d0
c
c     set default values for the diffusion coefficients
c
      diffb = 0.000156d0
      diffa = 0.0014d0
      diffid = 0.0225d0
      difft = 0.0225d0
      diffv = 1.0d0
      diffc = 3.5d0
c
c     set a flag to determine use of smoothed potentials
c
      if (forcefield .eq. 'SMOOTH') then
         use_deform = .true.
         query = .true.
      else
         use_deform = .false.
         query = .false.
      end if
c
c     get keyword containing the deformation parameter value
c
      if (query) then
         do i = 1, nkey
            next = 1
            record = keyline(i)
            call gettext (record,keyword,next)
            call upcase (keyword)
            if (keyword(1:7) .eq. 'DEFORM ') then
               query = .false.
               string = record(next:80)
               read (string,*,err=10)  deform
            end if
   10       continue
         end do
      end if
c
c     try to get deformation value from the command line
c
      if (query) then
         call nextarg (string,exist)
         if (exist) then
            read (string,*,err=20,end=20)  deform
            query = .false.
         end if
   20    continue
      end if
c
c     ask directly for the amount of potential smoothing to use
c
      if (query) then
         if (use_gda) then
            deform = 2000.0d0
            write (iout,30)
   30       format (/,' Enter the Initial Mean Squared Gaussian',
     &                 ' Width [2000.0] :  ',$)
         else
            write (iout,40)
   40       format (/,' Enter the Potential Surface Smoothing',
     &                 ' Parameter [0.0] :  ',$)
         end if
         read (input,50)  record
   50    format (a80)
         read (record,*,err=60)  deform
   60    continue
      end if
c
c     get keywords containing diffusion coefficients
c
      do i = 1, nkey
         next = 1
         record = keyline(i)
         call gettext (record,keyword,next)
         call upcase (keyword)
         if (keyword(1:13) .eq. 'DIFFUSE-BOND ') then
            string = record(next:80)
            read (string,*,err=70)  diffb
         else if (keyword(1:14) .eq. 'DIFFUSE-ANGLE ') then
            string = record(next:80)
            read (string,*,err=70)  diffa
         else if (keyword(1:17) .eq. 'DIFFUSE-IMPROPER ') then
            string = record(next:80)
            read (string,*,err=70)  diffid
         else if (keyword(1:16) .eq. 'DIFFUSE-TORSION ') then
            string = record(next:80)
            read (string,*,err=70)  difft
         else if (keyword(1:12) .eq. 'DIFFUSE-VDW ') then
            string = record(next:80)
            read (string,*,err=70)  diffv
         else if (keyword(1:15) .eq. 'DIFFUSE-CHARGE ') then
            string = record(next:80)
            read (string,*,err=70)  diffc
         end if
   70    continue
      end do
c
c     set second moment of Gaussian on each atom for GDA method
c
      if (use_gda) then
         do i = 1, n
            m2(i) = deform
         end do
      end if
      return
      end
