      Subroutine MkHBnd(Mcaaat, atomin, Hbond, Hbonde, seqcod, chnend,  MKHB001
     &                  seqlen)                                         MKHB002
c                                                                       MKHB003
c     Procedure to discover the possible hydrogen bonds between two     MKHB004
c     amino acids. Each amino acid is allowed 4 bonds - 2 from the      MKHB005
c     C=O and 2 from the N-H. Should it be that 3 or more bonds are     MKHB006
c     possible the most favourable are kept. A hydrogen                 MKHB007
c     bond is deemed to exist if the Kabsch and Sander energy formula   MKHB008
c     gives a value less than the cutoff. The angle and distance        MKHB009
c     approach is implicitly built in to this method. The formula       MKHB010
c     corresponds to a maximum distance of 5.2 A for in line atoms      MKHB011
c     and a maximum angular deviation of 63 degrees. A check on the     MKHB012
c     maximum distance is used to abandon unnecessary calculations.     MKHB013
c     the formula is                                                    MKHB014
c     E = q1*q2*(1/d(ON)+1/d(CH)-1/d(OH)-1/d(CN))*f                     MKHB015
c     Residues must be separated by at least one residue to bond        MKHB016
c     Proline cannot be a donor of a hydrogen bond                      MKHB017
c                                                                       MKHB018
      INCLUDE 'sstruc.par'                                              MKHB019
                                                                        MKHB020
      Integer Seqlen                                                    MKHB021
      Real    Mcaaat(ncoord,mnchna,maxres), Hbonde(maxbnd,maxres)       MKHB022
      Integer Hbond(maxbnd,maxres), seqcod(maxres), chnend(maxchn)      MKHB023
      logical Atomin(mnchna,maxres)                                     MKHB024
      Real    Atdist                                                    MKHB025
c                                                                       MKHB026
c     local variables                                                   MKHB027
c                                                                       MKHB028
CHECK v.3.2-->                                                          MKHB029
C      integer    ksf, mndist                                           MKHB030
C      real       mxdist, maxeng, ksq1, ksq2, maxcad, englim            MKHB031
      integer    ksf                                                    MKHB032
      real       mxdist, maxeng, ksq1, ksq2, maxcad, englim, mndist     MKHB033
CHECK v.3.2<--                                                          MKHB034
      parameter (mxdist = 5.2, maxeng = -0.5, mndist = 0.5,             MKHB035
     &           englim = -9.9, ksq1 = 0.42, ksq2 = 0.2, ksf = 332,     MKHB036
     &           maxcad = 8.0)                                          MKHB037
      Integer    Nxres, Othres, i, nbonds, fstchn, othchn               MKHB038
      logical    nhpres, xeqy                                           MKHB039
      real       don, doh, dch, dcn, energy, cadist                     MKHB040
                                                                        MKHB041
      do 200 nxres = 1, seqlen                                          MKHB042
      do 200 i = 1,maxbnd                                               MKHB043
      hbond(i,nxres) = 0                                                MKHB044
      hbonde(i,nxres) = 0.0                                             MKHB045
  200 continue                                                          MKHB046
      nbonds = 0                                                        MKHB047
      fstchn = 1                                                        MKHB048
      do 2000 nxres = 1, seqlen                                         MKHB049
      if (nxres .gt. chnend(fstchn)) fstchn = fstchn + 1                MKHB050
      nhpres = .false.                                                  MKHB051
      if (atomin(nmain,nxres) .and. atomin(nhyd,nxres) .and.            MKHB052
     &   seqcod(nxres) .ne. procod) nhpres = .true.                     MKHB053
      if (nhpres) then                                                  MKHB054
         othchn = 1                                                     MKHB055
         do 1900 othres = 1, seqlen                                     MKHB056
         if (othres .gt. chnend(othchn)) othchn = othchn + 1            MKHB057
         If ((iabs(nxres - othres) .eq. 1 .and. fstchn .ne. othchn)     MKHB058
     &      .or. iabs(nxres - othres) .ge. 2) then                      MKHB059
            If (atomin(calph,nxres) .and. atomin(calph,othres)) then    MKHB060
               cadist = atdist(mcaaat(1,calph,othres),                  MKHB061
     &                  mcaaat(1,calph,nxres))                          MKHB062
               If (cadist .lt. maxcad) then                             MKHB063
                  If (atomin(carb,othres) .and.                         MKHB064
     &               atomin(oxyg,othres))then                           MKHB065
                     don = atdist(mcaaat(1,oxyg,othres),                MKHB066
     &                     mcaaat(1,nmain,nxres))                       MKHB067
                     doh = atdist(mcaaat(1,oxyg,othres),                MKHB068
     &                     mcaaat(1,nhyd,nxres))                        MKHB069
                     dch = atdist(mcaaat(1,carb,othres),                MKHB070
     &                     mcaaat(1,nhyd,nxres))                        MKHB071
                     dcn = atdist(mcaaat(1,carb,othres),                MKHB072
     &                     mcaaat(1,nmain,nxres))                       MKHB073
                     If (xeqy(don,0.0).or.xeqy(doh,0.0).or.             MKHB074
     &                   xeqy(dch,0.0).or.xeqy(dcn,0.0)) then           MKHB075
                        write(errfi,250)nxres, othres                   MKHB076
CHECK v.3.4-->                                                          MKHB077
C  250                   format('coincident atoms in hydrogen bonding'  MKHB078
  250                   format('coincident atoms in hydrogen bonding',  MKHB079
CHECK v.3.4<--                                                          MKHB080
     &                         ' donor ',I4,' acceptor ',i4)            MKHB081
                     else                                               MKHB082
                        energy = ksq1 * ksq2 * ksf *                    MKHB083
     &                          (1.0/don + 1.0/dch - 1.0/doh - 1.0/dcn) MKHB084
                        If (energy .lt. englim) then                    MKHB085
                           write(errfi,300) nxres, othres, don, dch,    MKHB086
     &                                doh, dcn                          MKHB087
  300                      format('atoms too close ',I4,2x,i4,          MKHB088
     &                           2x,4(2x,f8.3))                         MKHB089
                           energy = englim                              MKHB090
                        end if                                          MKHB091
                        If (energy .lt. maxeng) call engset(hbonde,     MKHB092
     &                     hbond, energy, nxres, othres, nbonds)        MKHB093
                     end if                                             MKHB094
                  end if                                                MKHB095
               end if                                                   MKHB096
            end if                                                      MKHB097
         end if                                                         MKHB098
 1900    continue                                                       MKHB099
      end if                                                            MKHB100
 2000 continue                                                          MKHB101
      write(errfi,2100) 'number of hydrogen bonds is ',nbonds           MKHB102
 2100 format(a,i5)                                                      MKHB103
      END                                                               MKHB104
