c
c
c     ###################################################
c     ##  COPYRIGHT (C)  1990  by  Jay William Ponder  ##
c     ##              All Rights Reserved              ##
c     ###################################################
c
c     ###############################################################
c     ##                                                           ##
c     ##  subroutine analysis  --  energy components and analysis  ##
c     ##                                                           ##
c     ###############################################################
c
c
c     "analysis" calls the subroutines to calculate the potential
c     energy and perform an energy partitioning analysis in terms
c     of type of interaction and/or atom number
c
c
      subroutine analysis (energy)
      implicit none
C hailin
      include 'iounit.i'
C hailinend
      include 'sizes.i'
      include 'analyz.i'
      include 'atoms.i'
      include 'bound.i'
      include 'energi.i'
      include 'moment.i'
      include 'potent.i'
      include 'warp.i'
      integer i
      real*8 energy
c
c
c     zero out each of the potential energy components
c
      eb = 0.0d0
      ea = 0.0d0
      eba = 0.0d0
      eub = 0.0d0
      eaa = 0.0d0
      eopb = 0.0d0
      eid = 0.0d0
      eit = 0.0d0
      et = 0.0d0
      ebt = 0.0d0
      ett = 0.0d0
      ev = 0.0d0
      e14 = 0.0d0
      ec = 0.0d0
      ecd = 0.0d0
      ed = 0.0d0
      em = 0.0d0
      ep = 0.0d0
      er = 0.0d0
      es = 0.0d0
      eg = 0.0d0
      ex = 0.0d0
c
c     zero out energy partitioning components for each atom
c
      do i = 1, n
         aeb(i) = 0.0d0
         aea(i) = 0.0d0
         aeba(i) = 0.0d0
         aeub(i) = 0.0d0
         aeaa(i) = 0.0d0
         aeopb(i) = 0.0d0
         aeid(i) = 0.0d0
         aeit(i) = 0.0d0
         aet(i) = 0.0d0
         aebt(i) = 0.0d0
         aett(i) = 0.0d0
         aev(i) = 0.0d0
         ae14(i) = 0.0d0
         aec(i) = 0.0d0
         aecd(i) = 0.0d0
         aed(i) = 0.0d0
         aem(i) = 0.0d0
         aep(i) = 0.0d0
         aer(i) = 0.0d0
         aes(i) = 0.0d0
         aeg(i) = 0.0d0
         aex(i) = 0.0d0
      end do
c
c     zero out the net charge and dipole moment components
c
      netchg = 0.0d0
      xdipole = 0.0d0
      ydipole = 0.0d0
      zdipole = 0.0d0
c
c     maintain any periodic boundary conditions
c
      if (use_bounds)  call bounds
c
c     alter bond and torsion constants for pisystem
c
      if (use_orbit)  call piscf
c
c     call the local geometry energy component routines
c
      if (use_bond)  call ebond3
      if (use_angle)  call eangle3
      if (use_strbnd)  call estrbnd3
      if (use_urey)  call eurey3
      if (use_angang)  call eangang3
      if (use_opbend)  call eopbend3
      if (use_improp)  call eimprop3
      if (use_imptor)  call eimptor3
      if (use_tors)  call etors3
      if (use_strtor)  call estrtor3
c     if (use_tortor)  call etortor3
c
c     call the van der Waals energy component routines
c
      if (use_buck)  call ebuck3
      if (use_lj)  call elj3
      if (use_hal)  call ehal3
      if (use_gauss)  call egauss3
c
c     call the electrostatic energy component routines
c
      if (use_charge) then
         if (use_deform) then
            call echarge9
         else
            call echarge3
         end if
      end if
      if (use_chgdpl)  call echgdpl3
      if (use_dipole)  call edipole3
      if (use_mpole .or. use_polar)  call empole3
      if (use_rxnfld)  call erxnfld3
c
c     call any miscellaneous energy component routines
c
      if (use_solv)  call esolv3
      if (use_geom)  call egeom3
      if (use_extra)  call extra3
c
c     sum up to give the total potential energy
c
      energy = eb + ea + eba + eub + eaa + eopb + eid
     &            + eit + et + ebt + ett + ev + e14 + ec
     &            + ecd + ed + em + ep + er + es + eg + ex
c      write (*,*) "Dd", ea,eb,ev
      return
      end
