c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1996  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     #############################################################
c     ##                                                         ##
c     ##  subroutine prmkey  --  interpret force field keywords  ##
c     ##                                                         ##
c     #############################################################
c
c
c     "field" parses a text string to extract keywords related to
c     force field potential energy functional forms and constants
c
c
      subroutine prmkey (text)
      implicit none
      include 'sizes.i'
      include 'angpot.i'
      include 'bndpot.i'
      include 'chgpot.i'
      include 'fields.i'
      include 'polpot.i'
      include 'potent.i'
      include 'rxnpot.i'
      include 'torpot.i'
      include 'urypot.i'
      include 'vdwpot.i'
      integer next
      character*4 value
      character*20 keyword
      character*80 text,record,string
c
c
c     parse the line to extract any possible keyword
c
      record = text
      next = 1
      call upcase (record)
      call gettext (record,keyword,next)
c
c     select the individual force field potential terms
c
      if (keyword(1:9) .eq. 'BONDTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_bond = .true.
         if (value .eq. 'NONE')  use_bond = .false.
      else if (keyword(1:10) .eq. 'ANGLETERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_angle = .true.
         if (value .eq. 'NONE')  use_angle = .false.
      else if (keyword(1:11) .eq. 'STRBNDTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_strbnd = .true.
         if (value .eq. 'NONE')  use_strbnd = .false.
      else if (keyword(1:9) .eq. 'UREYTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_urey = .true.
         if (value .eq. 'NONE')  use_urey = .false.
      else if (keyword(1:11) .eq. 'ANGANGTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_angang = .true.
         if (value .eq. 'NONE')  use_angang = .false.
      else if (keyword(1:11) .eq. 'OPBENDTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_opbend = .true.
         if (value .eq. 'NONE')  use_opbend = .false.
      else if (keyword(1:13) .eq. 'IMPROPERTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_improp = .true.
         if (value .eq. 'NONE')  use_improp = .false.
      else if (keyword(1:12) .eq. 'IMPTORSTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_imptor = .true.
         if (value .eq. 'NONE')  use_imptor = .false.
      else if (keyword(1:12) .eq. 'TORSIONTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_tors = .true.
         if (value .eq. 'NONE')  use_tors = .false.
      else if (keyword(1:11) .eq. 'STRTORTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_strtor = .true.
         if (value .eq. 'NONE')  use_strtor = .false.
      else if (keyword(1:11) .eq. 'TORTORTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_tortor = .true.
         if (value .eq. 'NONE')  use_tortor = .false.
      else if (keyword(1:8) .eq. 'VDWTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_vdw = .true.
         if (value .eq. 'NONE')  use_vdw = .false.
      else if (keyword(1:11) .eq. 'CHARGETERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_charge = .true.
         if (value .eq. 'NONE')  use_charge = .false.
      else if (keyword(1:11) .eq. 'CHGDPLTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_chgdpl = .true.
         if (value .eq. 'NONE')  use_chgdpl = .false.
      else if (keyword(1:11) .eq. 'DIPOLETERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_dipole = .true.
         if (value .eq. 'NONE')  use_dipole = .false.
      else if (keyword(1:10) .eq. 'MPOLETERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_mpole = .true.
         if (value .eq. 'NONE')  use_mpole = .false.
      else if (keyword(1:13) .eq. 'POLARIZETERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_polar = .true.
         if (value .eq. 'NONE')  use_polar = .false.
      else if (keyword(1:13) .eq. 'RXNFIELDTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_rxnfld = .true.
         if (value .eq. 'NONE')  use_rxnfld = .false.
      else if (keyword(1:12) .eq. 'SOLVATETERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_solv = .true.
         if (value .eq. 'NONE')  use_solv = .false.
      else if (keyword(1:13) .eq. 'RESTRAINTERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_geom = .true.
         if (value .eq. 'NONE')  use_geom = .false.
      else if (keyword(1:10) .eq. 'EXTRATERM ') then
         call getword (record,value,next)
         if (value .eq. 'ONLY')  call potoff
         use_extra = .true.
         if (value .eq. 'NONE')  use_extra = .false.
      end if
c
c     set the name of the force field parameter set
c
      if (keyword(1:11) .eq. 'FORCEFIELD ') then
         call getword (record,forcefield,next)
c
c     definition of the bond stretching potential term
c
      else if (keyword(1:9) .eq. 'BONDTYPE ') then
         call getword (record,bndtyp,next)
      else if (keyword(1:9) .eq. 'BONDUNIT ') then
         string = record(next:80)
         read (string,*,err=10)  bndunit
c jcc
      else if (keyword(1:8) .eq. 'BDEUNIT ') then
         string = record(next:80)
         read (string,*,err=10)  bdeunit
c jcc
      else if (keyword(1:11) .eq. 'BOND-CUBIC ') then
         string = record(next:80)
         read (string,*,err=10)  cbnd
      else if (keyword(1:13) .eq. 'BOND-QUARTIC ') then
         string = record(next:80)
         read (string,*,err=10)  qbnd
c
c     definition of the bond angle bending potential term
c
      else if (keyword(1:10) .eq. 'ANGLETYPE ') then
         call getword (record,angtyp,next)
      else if (keyword(1:10) .eq. 'ANGLEUNIT ') then
         string = record(next:80)
         read (string,*,err=10)  angunit
      else if (keyword(1:12) .eq. 'ANGLE-CUBIC ') then
         string = record(next:80)
         read (string,*,err=10)  cang
      else if (keyword(1:14) .eq. 'ANGLE-QUARTIC ') then
         string = record(next:80)
         read (string,*,err=10)  qang
      else if (keyword(1:13) .eq. 'ANGLE-PENTIC ') then
         string = record(next:80)
         read (string,*,err=10)  pang
      else if (keyword(1:13) .eq. 'ANGLE-SEXTIC ') then
         string = record(next:80)
         read (string,*,err=10)  sang
c
c     definitions for other local geometry potential terms
c
      else if (keyword(1:11) .eq. 'STRBNDUNIT ') then
         string = record(next:80)
         read (string,*,err=10)  stbnunit
      else if (keyword(1:9) .eq. 'UREYUNIT ') then
         string = record(next:80)
         read (string,*,err=10)  ureyunit
      else if (keyword(1:11) .eq. 'ANGANGUNIT ') then
         string = record(next:80)
         read (string,*,err=10)  aaunit
      else if (keyword(1:12) .eq. 'TORSIONUNIT ') then
         string = record(next:80)
         read (string,*,err=10)  torsunit
      else if (keyword(1:11) .eq. 'STRTORUNIT ') then
         string = record(next:80)
         read (string,*,err=10)  storunit
c
c     definition of the van der Waals potential term
c
      else if (keyword(1:8) .eq. 'VDWTYPE ') then
         call getword (record,vdwtyp,next)
         use_lj = .false.
         use_buck = .false.
         use_hal = .false.
         use_gauss = .false.
         if (vdwtyp(1:13) .eq. 'LENNARD-JONES')  use_lj = .true.
         if (vdwtyp(1:11) .eq. 'BUCKINGHAM')  use_buck = .true.
         if (vdwtyp(1:13) .eq. 'BUFFERED-14-7')  use_hal = .true.
         if (vdwtyp(1:8) .eq. 'GAUSSIAN')  use_gauss = .true.
      else if (keyword(1:10) .eq. 'A-EXPTERM ') then
         string = record(next:80)
         read (string,*,err=10)  aterm
      else if (keyword(1:10) .eq. 'B-EXPTERM ') then
         string = record(next:80)
         read (string,*,err=10)  bterm
      else if (keyword(1:10) .eq. 'C-EXPTERM ') then
         string = record(next:80)
         read (string,*,err=10)  cterm
      else if (keyword(1:10) .eq. 'D-EXPTERM ') then
         string = record(next:80)
         read (string,*,err=10)  dterm
      else if (keyword(1:14) .eq. 'VDW-GAUSSIANS ') then
         string = record(next:80)
         read (string,*,err=10)  ngauss
      else if (keyword(1:13) .eq. 'VDW-14-SCALE ') then
         string = record(next:80)
         read (string,*,err=10)  vdwscale
         if (vdwscale .eq. 0.0d0)  vdw14use = 1
      else if (keyword(1:11) .eq. 'VDW-12-USE ') then
         call getword (record,value,next)
         vdw12use = 0
         if (value .eq. 'NONE')  vdw12use = 1
         if (value .eq. 'SCAL')  vdw12use = -1
      else if (keyword(1:11) .eq. 'VDW-13-USE ') then
         call getword (record,value,next)
         vdw13use = 0
         if (value .eq. 'NONE')  vdw13use = 1
         if (value .eq. 'SCAL')  vdw13use = -1
      else if (keyword(1:11) .eq. 'VDW-14-USE ') then
         call getword (record,value,next)
         vdw14use = 0
         if (value .eq. 'NONE')  vdw14use = 1
         if (value .eq. 'SCAL')  vdw14use = -1
      else if (keyword(1:11) .eq. 'RADIUSTYPE ') then
         call getword (record,radtyp,next)
      else if (keyword(1:11) .eq. 'RADIUSSIZE ') then
         call getword (record,radsiz,next)
      else if (keyword(1:11) .eq. 'RADIUSRULE ') then
         call getword (record,radrule,next)
      else if (keyword(1:12) .eq. 'EPSILONRULE ') then
         call getword (record,epsrule,next)
c
c     definition of the electrostatic potential term
c
      else if (keyword(1:11) .eq. 'DIELECTRIC ') then
         string = record(next:80)
         read (string,*,err=10)  dielec
      else if (keyword(1:11) .eq. 'CHG-12-USE ') then
         call getword (record,value,next)
         chg12use = 0
         if (value .eq. 'NONE')  chg12use = 1
         if (value .eq. 'SCAL')  chg12use = -1
      else if (keyword(1:11) .eq. 'CHG-13-USE ') then
         call getword (record,value,next)
         chg13use = 0
         if (value .eq. 'NONE')  chg13use = 1
         if (value .eq. 'SCAL')  chg13use = -1
      else if (keyword(1:11) .eq. 'CHG-14-USE ') then
         call getword (record,value,next)
         chg14use = 0
         if (value .eq. 'NONE')  chg14use = 1
         if (value .eq. 'SCAL')  chg14use = -1
      else if (keyword(1:13) .eq. 'CHG-14-SCALE ') then
         string = record(next:80)
         read (string,*,err=10)  chgscale
         if (chgscale .eq. 0.0d0)  chg14use = 1
      else if (keyword(1:15) .eq. 'NEUTRAL-GROUPS ') then
         neutcut = .true.
      else if (keyword(1:16) .eq. 'GROUP-NEIGHBORS ') then
         neutnbr = .true.
c
c     definition of the polarization potential term
c
      else if (keyword(1:13) .eq. 'POLARIZATION ') then
         call getword (record,poltyp,next)
      else if (keyword(1:10) .eq. 'POLAR-EPS ') then
         string = record(next:80)
         read (string,*,err=10)  poleps
      else if (keyword(1:11) .eq. 'POLAR-DAMP ') then
         string = record(next:80)
         read (string,*,err=10)  pradius,pgamma
c
c     definition of the reaction field potential term
c
      else if (keyword(1:14) .eq. 'REACTIONFIELD ') then
         string = record(next:80)
         read (string,*,err=10)  rfsize,rfbulkd,rfterms
      end if
c
c     jump directly to the end if any error was detected
c
   10 continue
      return
      end
c
c
c     ###############################################################
c     ##                                                           ##
c     ##  subroutine potoff  --  turn off all potential functions  ##
c     ##                                                           ##
c     ###############################################################
c
c
c     "potoff" clears the forcefield definition by turning off
c     the use of each of the potential energy functions
c
c
      subroutine potoff
      implicit none
      include 'potent.i'
c
c
c     turn off the use of each of the potential energy functions
c
      use_bond = .false.
      use_angle = .false.
      use_strbnd = .false.
      use_urey = .false.
      use_angang = .false.
      use_opbend = .false.
      use_improp = .false.
      use_imptor = .false.
      use_tors = .false.
      use_strtor = .false.
      use_vdw = .false.
      use_charge = .false.
      use_chgdpl = .false.
      use_dipole = .false.
      use_mpole = .false.
      use_polar = .false.
      use_rxnfld = .false.
      use_solv = .false.
      use_geom = .false.
      use_extra = .false.
      return
      end
