c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ###############################################################
c     ##                                                           ##
c     ##  subroutine mechanic  --  initialize molecular mechanics  ##
c     ##                                                           ##
c     ###############################################################
c
c
c     "mechanic" sets up needed parameters for the potential energy
c     calculation and reads in many of the user selectable options
c
c
      subroutine mechanic
      implicit none
      include 'inform.i'
      include 'iounit.i'
      include 'potent.i'
c
c
c     set the connectivity, active atoms, and atom groups
c
      call attach
      call active
      call cluster
c
c     find and store each bond, angle and torsion
c
      call bonds
      call angles
      call torsions
c
c     find cutoff values and small ring systems
c
      call cutoffs
      call rings
c
c     get the force field parameters and assign atom types
c
      call field
      call katom
c
c     find any pisystem atoms, bonds and torsional angles
c
      call orbital
c
c     assign local geometry potential function parameters
c
      if (use_bond .or. use_strbnd .or. use_strtor)  call kbond
      if (use_angle .or. use_strbnd .or. use_angang)  call kangle
      if (use_strbnd)  call kstrbnd
      if (use_urey)  call kurey
      if (use_angang)  call kangang
      if (use_angle .or. use_opbend)  call kopbend
      if (use_improp)  call kimprop
      if (use_imptor)  call kimptor
      if (use_tors .or. use_strtor .or. use_tortor)  call ktors
      if (use_strtor)  call kstrtor
c     if (use_tortor)  call ktortor
c
c     assign nonbonded potential function parameters
c
      if (use_vdw)  call kvdw
      if (use_charge .or. use_chgdpl .or. use_solv)  call kcharge
      if (use_dipole .or. use_chgdpl)  call kdipole
      if (use_mpole .or. use_polar .or. use_rxnfld)  call kmpole
      if (use_polar)  call kpolar
c
c     assign macroscopic solvation and pisystem parameters
c
      if (use_solv)  call solvate
      if (use_orbit)  call korbit
c
c     count the number of molcules in the system
c
      call molecule
c
c     find any crystal lattice or periodic box parameters
c
      call unitcell
      call lattice
c
c     set any geometric restraint terms to be applied
c
      call restrain
c
c     set any deformation parameters for potential smoothing
c
      call smooth
c
c     set hybrid parameters for free energy perturbation
c
      call mutate
c
c     quit if essential parameter information is missing
c
      if (abort) then
         write (iout,10)
   10    format (/,' MECHANIC  --  Some Required Potential Energy',
     &              ' Parameters are Undefined')
         call fatal
      end if
      return
      end
