      subroutine rdbrk (mcaaat, atname, atomin, aacod3, hetcod, seqcod, RDBR001
     &                  seqbcd, scaaat, scatin, altcod, aastd,  atpres, RDBR002
CHECK v.3.2-->                                                          RDBR003
C     +                  thmprs, caonly, astruc, headln, hedlen, readok,RDBR004
     &                  thmprs, caonly, astruc, hedlen, readok,         RDBR005
CHECK v.3.2<--                                                          RDBR006
     &                  dudcod, modcod, stdmod, nstdmd, modpl,  seqlen, RDBR007
     &                  nscats, mcser,  scser,  mcocc,  mcthrm, scocc,  RDBR008
     &                  scthrm, scname, altnam, naltmc, naltsc, altmci, RDBR009
     &                  altsci, altmcr, altscr, altmca, altsca, lab,    RDBR010
     &                  extdat, extres, nline,  tphnam, olenam, pphnam, RDBR011
     &                  nrec,   mcalt,  scalt,  altmcc, altscc, pyrnam, RDBR012
CHECK v.3.1-->                                                          RDBR013
C     +                  restot, altdat, altlin, altres, batnam, brcode)RDBR014
     &                  restot, altdat, altlin, altres, batnam, brcode, RDBR015
     &                  NMR)                                            RDBR016
CHECK v.3.1<--                                                          RDBR017
c                                                                       RDBR018
      include 'brkcln.par'                                              RDBR019
c                                                                       RDBR020
      integer   seqlen, seqcod(maxres), hedlen, mcser(mnchna,maxres),   RDBR021
     &          scser(sdchna,maxres), naltmc, naltsc,                   RDBR022
     &          altsci(3,altmax), altmci(3,altmax), extres(maxlin),     RDBR023
     &          nline, nrec, altres(maxalt), altlin                     RDBR024
c                                                                       RDBR025
      character aacod3*(abetsz*3), atname*((mnchna*4)-4),               RDBR026
CHECK v.3.2-->                                                          RDBR027
C     +          seqbcd(maxres)*6, headln*132, altcod(maxres)*1,        RDBR028
     &          seqbcd(maxres)*6, altcod(maxres)*1,                     RDBR029
CHECK v.3.2<--                                                          RDBR030
     &          aastd(maxres)*1, atpres(3,maxres)*1, thmprs(maxres)*1,  RDBR031
     &          hetcod*63, modcod*(nmod*3), stdmod*(nmod+1),            RDBR032
     &          nstdmd*(nmod+1), modpl*(nmod), dudcod*105,              RDBR033
     &          lab(maxres)*1, extdat(maxlin)*66,                       RDBR034
     &          tphnam*((mnchna*4)-4), olenam*((mnchna*4)-4),           RDBR035
     &          pphnam*((mnchna*4)-4), mcalt(mnchna,maxres)*1,          RDBR036
     &          scalt(sdchna,maxres)*1, altmcc(maxres)*1,               RDBR037
     &          altscc(maxres)*1,                                       RDBR038
     &          pyrnam*((mnchna*4)-4), altdat(maxalt)*66,               RDBR039
     &          batnam*((4*mnchna)-4)                                   RDBR040
c                                                                       RDBR041
      real      mcaaat(ncoord,mnchna,maxres),                           RDBR042
     &          scaaat(ncoord,sdchna,maxres), mcocc(mnchna,maxres),     RDBR043
     &          mcthrm(mnchna,maxres),                                  RDBR044
     &          scocc(sdchna,maxres), scthrm(sdchna,maxres),            RDBR045
     &          altmcr(2,altmax), altscr(2,altmax), altmca(3,altmax),   RDBR046
     &          altsca(3,altmax)                                        RDBR047
c                                                                       RDBR048
      logical   atomin(mnchna,maxres), scatin(sdchna,maxres), caonly,   RDBR049
     &          astruc, readok                                          RDBR050
c                                                                       RDBR051
c     local variables                                                   RDBR052
c                                                                       RDBR053
      integer   aaconv, aapln, num                                      RDBR054
      parameter (aapln = 13)                                            RDBR055
c                                                                       RDBR056
      real      acoord(ncoord), oldocc, occup, therm, oldthm, extocc,   RDBR057
     &          altocc                                                  RDBR058
c                                                                       RDBR059
      logical   altset, xney                                            RDBR060
c                                                                       RDBR061
c     integer   nrecs, aathln, rderr, altype, nxaa, nxrec, skipaa,      RDBR062
c    +          hedend                                                  RDBR063
c                                                                       RDBR064
      integer   atcnt, attype, i, j, aacnt, wkpl, clslen, cmplen,       RDBR065
     &          soulen, sctype, altpos(sideaa), respl, scatct, thmcnt,  RDBR066
     &          aacode, nscats(sideaa), sqrsct, restot(sideaa)          RDBR067
c                                                                       RDBR068
      character aain(maxres)*3, atmnam*4, resnam*3, altloc*1,           RDBR069
     &          brkrec*80, oldchn*1, seqnum*6, keywd*(keylen),          RDBR070
     &          oldatm*4, setloc*1, class*40, compnd*50, source*50,     RDBR071
     &          brcode*4, cbet*4, scname(sideaa)*44, altnam(3)*44,      RDBR072
     &          contch*1, incode*4, wkstr*50, inseqr*150, setatm*4,     RDBR073
     &          wkres*3, extatm*4, extnum*6, string*66, altatm*4,       RDBR074
     &          altnum*6                                                RDBR075
CHECK v.3.2-->                                                          RDBR076
      character rname*3                                                 RDBR077
CHECK v.3.2<--                                                          RDBR078
c                                                                       RDBR079
c     character chid*1, chnid(maxchn)*1, innum*6                        RDBR080
c                                                                       RDBR081
      integer   strlen, resfnd, kount                                   RDBR082
                                                                        RDBR083
CHECK v.3.1-->                                                          RDBR084
      LOGICAL   NMR                                                     RDBR085
CHECK v.3.1<--                                                          RDBR086
c                                                                       RDBR087
c     Routine to read the brookhaven data file and extract the sequence RDBR088
c     and the atom names and coordinates. Checking is also done for     RDBR089
c     residue compatibility between sequence and atom. C-alpha only     RDBR090
c     files are flagged. The sequence residues are expected together,   RDBR091
c     then the secondary structure records (sheets together), and then  RDBR092
c     the atom records which are expected in residue order.             RDBR093
c                                                                       RDBR094
      save altpos                                                       RDBR095
      data altpos / 7*0, 1, 5*0, 2, 2*0, 3, 33*0 /                      RDBR096
      data cbet / ' CB ' /                                              RDBR097
c                                                                       RDBR098
  220 format (18x, 13(x,a3))                                            RDBR099
  520 format (9x, a1, a40, 12x, a4)                                     RDBR100
  620 format (9x, a1, a50)                                              RDBR101
  720 format (9x, a1, a50)                                              RDBR102
 1080 format (21x, a1)                                                  RDBR103
 1120 format (12x, a4, a1, a3, 1x, a6, 27x, 2f6.2)                      RDBR104
 1121 format (12x, a4, 5x,         a6, 27x, f6.2)                       RDBR105
 1320 format (6x, i5, 1x, a4, a1, 4x, a6, 3x, 3f8.3, 2f6.2)             RDBR106
CHECK v.2.1.3-->                                                        RDBR107
C 1374 format('WARNING: This side chain atom (',a4,') not found for',   RDBR108
C     + ' this residue ',a3, 1x, i4)                                    RDBR109
CHECK v.3.0.1-->                                                        RDBR110
C 1374 format('* WARNING: This side chain atom (',a4,') not found for', RDBR111
C     + ' this residue ',a3, 1x, i4)                                    RDBR112
CHECK v.3.0.1<--                                                        RDBR113
CHECK v.2.1.3<--                                                        RDBR114
 6000 format (A)                                                        RDBR115
CHECK v.2.1.3-->                                                        RDBR116
C 6010 format (' Too many amino acids - input terminated.')             RDBR117
 6010 format (' **** Too many amino acids - input terminated.')         RDBR118
CHECK v.2.1.3<--                                                        RDBR119
c                                                                       RDBR120
      kount  = 0                                                        RDBR121
      altlin = 0                                                        RDBR122
      naltmc = 0                                                        RDBR123
      naltsc = 0                                                        RDBR124
      seqlen = 0                                                        RDBR125
      hedlen = 0                                                        RDBR126
      inseqr = space                                                    RDBR127
      sqrsct = 0                                                        RDBR128
      brcode = '    '                                                   RDBR129
      astruc = .false.                                                  RDBR130
      do 50 i = 1, mnchna                                               RDBR131
      do 49 j = 1, maxres                                               RDBR132
      mcocc(i,j) = 0.0                                                  RDBR133
   49 continue                                                          RDBR134
   50 continue                                                          RDBR135
      do 52 i = 1, sdchna                                               RDBR136
      do 51 j = 1, maxres                                               RDBR137
      scocc(i,j) = 0.0                                                  RDBR138
   51 continue                                                          RDBR139
   52 continue                                                          RDBR140
c                                                                       RDBR141
  100 continue                                                          RDBR142
      read (brkfi, 6000, end=3000) brkrec                               RDBR143
      kount = kount + 1                                                 RDBR144
      keywd = brkrec(1:keylen)                                          RDBR145
      if (keywd .ne. atmkey .and.                                       RDBR146
     &    keywd .ne. htakey) write (outfi, 6000) brkrec                 RDBR147
      if (keywd .eq. seqkey) goto 200                                   RDBR148
      if (keywd .eq. hedkey) goto 500                                   RDBR149
      if (keywd .eq. cmpkey) goto 600                                   RDBR150
      if (keywd .eq. soukey) goto 700                                   RDBR151
      if (keywd .eq. atmkey) goto 900                                   RDBR152
      if (keywd .eq. htakey) goto 900                                   RDBR153
CHECK v.3.1-->                                                          RDBR154
      IF (KEYWD .EQ. ENDMDL) GO TO 3000                                 RDBR155
CHECK v.3.1<--                                                          RDBR156
      if (keywd .eq. modkey) then                                       RDBR157
         readok = .false.                                               RDBR158
         seqlen = 0                                                     RDBR159
CHECK v.3.1-->                                                          RDBR160
         PRINT*, '*** ERROR: MODEL record encountered unexpectedly ',   RDBR161
     &       'in PDB file'                                              RDBR162
CHECK v.3.1<--                                                          RDBR163
         goto 3000                                                      RDBR164
      end if                                                            RDBR165
      if (keywd .eq. hlxkey .or. keywd .eq. shtkey .or.                 RDBR166
     &    keywd .eq. trnkey .or. keywd .eq. dsfkey) then                RDBR167
         if (.not. astruc) then                                         RDBR168
            open (authfi, status='SCRATCH')                             RDBR169
            astruc = .true.                                             RDBR170
         end if                                                         RDBR171
         write (authfi, 6000) brkrec                                    RDBR172
      end if                                                            RDBR173
      goto 100                                                          RDBR174
c                                                                       RDBR175
  200 continue                                                          RDBR176
      read (brkrec, 220) (aain(i), i=1,aapln)                           RDBR177
      do 250 i = 1, aapln                                               RDBR178
      if (aain(i) .ne. '   ') then                                      RDBR179
         if (resfnd(inseqr,aain(i)) .eq. 0) then                        RDBR180
            sqrsct = sqrsct + 1                                         RDBR181
            inseqr(((sqrsct-1)*3)+1:sqrsct*3) = aain(i)                 RDBR182
         end if                                                         RDBR183
      end if                                                            RDBR184
  250 continue                                                          RDBR185
      goto 100                                                          RDBR186
c                                                                       RDBR187
c     set up header records                                             RDBR188
c                                                                       RDBR189
  500 continue                                                          RDBR190
      read (brkrec, 520) contch, wkstr, incode                          RDBR191
      if (contch .eq. space) then                                       RDBR192
         brcode = incode                                                RDBR193
         class = wkstr                                                  RDBR194
         clslen = strlen(class)                                         RDBR195
      end if                                                            RDBR196
      goto 100                                                          RDBR197
c                                                                       RDBR198
  600 continue                                                          RDBR199
      read (brkrec, 620) contch, wkstr                                  RDBR200
      if (contch .eq. space) then                                       RDBR201
         compnd = wkstr                                                 RDBR202
         cmplen = strlen(compnd)                                        RDBR203
      end if                                                            RDBR204
      goto 100                                                          RDBR205
c                                                                       RDBR206
  700 continue                                                          RDBR207
      read (brkrec, 720) contch, wkstr                                  RDBR208
      if (contch .eq. space) then                                       RDBR209
         source = wkstr                                                 RDBR210
         soulen = strlen(source)                                        RDBR211
      end if                                                            RDBR212
      goto 100                                                          RDBR213
c                                                                       RDBR214
c     look for next atom records to process                             RDBR215
c                                                                       RDBR216
  900 continue                                                          RDBR217
 1000 continue                                                          RDBR218
      if (brkrec(1:keylen) .ne. atmkey .and.                            RDBR219
     &    brkrec(1:keylen) .ne. htakey) then                            RDBR220
         read (brkfi, '(A)', end=3000) brkrec                           RDBR221
CHECK v.3.1-->                                                          RDBR222
         IF (BRKREC(1:KEYLEN) .EQ. ENDMDL) GO TO 3000                   RDBR223
CHECK v.3.1<--                                                          RDBR224
         goto 1000                                                      RDBR225
      end if                                                            RDBR226
c                                                                       RDBR227
c     Arrival here implies we have just read in the record for the      RDBR228
c     first atom of a particular amino acid. For each aa get the        RDBR229
c     seqnum and resnam and check against the read in sequence. If      RDBR230
c     ok initialise to no atoms present and get the coords.             RDBR231
c                                                                       RDBR232
      aacnt = 0                                                         RDBR233
      aastd(1) = space                                                  RDBR234
      read (brkrec, 1080) oldchn                                        RDBR235
 1100 continue                                                          RDBR236
      keywd  = brkrec(1:keylen)                                         RDBR237
      aacode = 0                                                        RDBR238
      altset = .false.                                                  RDBR239
      setatm = '    '                                                   RDBR240
      read (brkrec, 1120) oldatm, setloc, resnam, seqnum, oldocc, oldthmRDBR241
CHECK v.2.1.1-->                                                        RDBR242
      IF (brkrec(57:60).EQ.'    ') oldocc = 1.0                         RDBR243
CHECK v.2.1.1<--                                                        RDBR244
      if (sqrsct .ne. 0 .and. resfnd(inseqr,resnam) .eq. 0) then        RDBR245
         if (brkrec(1:keylen) .eq. atmkey .or.                          RDBR246
     &       brkrec(1:keylen) .eq. htakey) then                         RDBR247
            if (setloc .ne. space .and. nline .ne. 0) then              RDBR248
               string = extdat(nline)                                   RDBR249
               read (string, 1121) extatm, extnum, extocc               RDBR250
CHECK v.2.1.1-->                                                        RDBR251
      IF (string(57:60).EQ.'    ') extocc = 1.0                         RDBR252
CHECK v.2.1.1<--                                                        RDBR253
               if (extatm .eq. oldatm .and. extnum .eq. seqnum) then    RDBR254
                  if (extocc .ge. oldocc) then                          RDBR255
                     altlin = altlin + 1                                RDBR256
                     altdat(altlin) = brkrec(1:66)                      RDBR257
                  else                                                  RDBR258
                     altlin = altlin + 1                                RDBR259
                     altdat(altlin) = string                            RDBR260
                     extdat(nline) = brkrec(1:66)                       RDBR261
                  end if                                                RDBR262
                  altres(altlin) = aacnt                                RDBR263
               else                                                     RDBR264
                  nline = nline + 1                                     RDBR265
                  extdat(nline) = brkrec(1:66)                          RDBR266
                  extres(nline) = aacnt                                 RDBR267
               end if                                                   RDBR268
            else                                                        RDBR269
               nline = nline + 1                                        RDBR270
               extdat(nline) = brkrec(1:66)                             RDBR271
               extres(nline) = aacnt                                    RDBR272
            end if                                                      RDBR273
         else                                                           RDBR274
            nline = nline + 1                                           RDBR275
            extdat(nline) = brkrec(1:66)                                RDBR276
            extres(nline) = aacnt                                       RDBR277
         end if                                                         RDBR278
         goto 1400                                                      RDBR279
      end if                                                            RDBR280
c                                                                       RDBR281
      if (resfnd(dudcod,resnam) .ne. 0) then                            RDBR282
         if (brkrec(1:keylen) .eq. atmkey .or.                          RDBR283
     &       brkrec(1:keylen) .eq. htakey) then                         RDBR284
            if (setloc .ne. space .and. nline .ne. 0) then              RDBR285
               string = extdat(nline)                                   RDBR286
               read (string, 1121) extatm, extnum, extocc               RDBR287
CHECK v.2.1.1-->                                                        RDBR288
               IF (string(57:60).EQ.'    ') extocc = 1.0                RDBR289
CHECK v.2.1.1<--                                                        RDBR290
               if (extatm .eq. oldatm .and. extnum .eq. seqnum) then    RDBR291
                  if (extocc .ge. oldocc) then                          RDBR292
                     altlin = altlin + 1                                RDBR293
                     altdat(altlin) = brkrec(1:66)                      RDBR294
                  else                                                  RDBR295
                     altlin = altlin + 1                                RDBR296
                     altdat(altlin) = string                            RDBR297
                     extdat(nline) = brkrec(1:66)                       RDBR298
                  end if                                                RDBR299
                  altres(altlin) = aacnt                                RDBR300
               else                                                     RDBR301
                  nline = nline + 1                                     RDBR302
                  extdat(nline) = brkrec(1:66)                          RDBR303
                  extres(nline) = aacnt                                 RDBR304
               end if                                                   RDBR305
            else                                                        RDBR306
               nline = nline + 1                                        RDBR307
               extdat(nline) = brkrec(1:66)                             RDBR308
               extres(nline) = aacnt                                    RDBR309
            end if                                                      RDBR310
         else                                                           RDBR311
            nline = nline + 1                                           RDBR312
            extdat(nline) = brkrec(1:66)                                RDBR313
            extres(nline) = aacnt                                       RDBR314
         end if                                                         RDBR315
         goto 1400                                                      RDBR316
      end if                                                            RDBR317
c                                                                       RDBR318
      respl = resfnd(modcod,resnam)                                     RDBR319
      if (respl .ne. 0) then                                            RDBR320
         if (brkrec(1:keylen) .eq. atmkey .or.                          RDBR321
     &       brkrec(1:keylen) .eq. htakey) then                         RDBR322
            if (setloc .ne. space .and. nline .ne. 0) then              RDBR323
               string = extdat(nline)                                   RDBR324
               read (string, 1121) extatm, extnum, extocc               RDBR325
CHECK v.2.1.1-->                                                        RDBR326
               IF (string(57:60).EQ.'    ') extocc = 1.0                RDBR327
CHECK v.2.1.1<--                                                        RDBR328
               if (extatm .eq. oldatm .and. extnum .eq. seqnum) then    RDBR329
                  if (extocc .ge. oldocc) then                          RDBR330
                     altlin = altlin + 1                                RDBR331
                     altdat(altlin) = brkrec(1:66)                      RDBR332
                  else                                                  RDBR333
                     altlin = altlin + 1                                RDBR334
                     altdat(altlin) = string                            RDBR335
                     extdat(nline) = brkrec(1:66)                       RDBR336
                  end if                                                RDBR337
                  altres(altlin) = aacnt                                RDBR338
               else                                                     RDBR339
                  nline = nline + 1                                     RDBR340
                  extdat(nline) = brkrec(1:66)                          RDBR341
                  extres(nline) = aacnt                                 RDBR342
               end if                                                   RDBR343
            else                                                        RDBR344
               nline = nline + 1                                        RDBR345
               extdat(nline) = brkrec(1:66)                             RDBR346
               extres(nline) = aacnt                                    RDBR347
            end if                                                      RDBR348
         else                                                           RDBR349
            nline = nline + 1                                           RDBR350
            extdat(nline) = brkrec(1:66)                                RDBR351
            extres(nline) = aacnt                                       RDBR352
         end if                                                         RDBR353
         respl = ((respl - 1) / 3) + 1                                  RDBR354
         if (modpl(respl:respl) .eq. '+') then                          RDBR355
            aastd(aacnt+1) = stdmod(respl:respl)                        RDBR356
         else                                                           RDBR357
            if (aastd(aacnt) .eq. 'S') then                             RDBR358
               aastd(aacnt) = stdmod(respl:respl)                       RDBR359
            else                                                        RDBR360
               if (aastd(aacnt) .eq. 'O') then                          RDBR361
                  aastd(aacnt) = nstdmd(respl:respl)                    RDBR362
               else                                                     RDBR363
                  if (llt(aastd(aacnt),'a')) then                       RDBR364
                     aastd(aacnt) = stdmod(nmod+1:nmod+1)               RDBR365
                  else                                                  RDBR366
                     aastd(aacnt) = nstdmd(nmod+1:nmod+1)               RDBR367
                  end if                                                RDBR368
               end if                                                   RDBR369
            end if                                                      RDBR370
         end if                                                         RDBR371
         goto 1400                                                      RDBR372
      end if                                                            RDBR373
c                                                                       RDBR374
      aacode = aaconv(resnam,aacod3,hetcod)                             RDBR375
      if (aacode .gt. 0) restot(aacode) = restot(aacode) + 1            RDBR376
      if (aacode .le. 0) then                                           RDBR377
         if (brkrec(1:keylen) .eq. atmkey .or.                          RDBR378
     &       brkrec(1:keylen) .eq. htakey) then                         RDBR379
            if (setloc .ne. space .and. nline .ne. 0) then              RDBR380
               string = extdat(nline)                                   RDBR381
               read (string, 1121) extatm, extnum, extocc               RDBR382
CHECK v.2.1.1-->                                                        RDBR383
               IF (string(57:60).EQ.'    ') extocc = 1.0                RDBR384
CHECK v.2.1.1<--                                                        RDBR385
               if (extatm .eq. oldatm .and. extnum .eq. seqnum) then    RDBR386
                  if (extocc .ge. oldocc) then                          RDBR387
                     altlin = altlin + 1                                RDBR388
                     altdat(altlin) = brkrec(1:66)                      RDBR389
                  else                                                  RDBR390
                     altlin = altlin + 1                                RDBR391
                     altdat(altlin) = string                            RDBR392
                     extdat(nline) = brkrec(1:66)                       RDBR393
                  end if                                                RDBR394
                  altres(altlin) = aacnt                                RDBR395
               else                                                     RDBR396
                  nline = nline + 1                                     RDBR397
                  extdat(nline) = brkrec(1:66)                          RDBR398
                  extres(nline) = aacnt                                 RDBR399
               end if                                                   RDBR400
            else                                                        RDBR401
               nline = nline + 1                                        RDBR402
               extdat(nline) = brkrec(1:66)                             RDBR403
               extres(nline) = aacnt                                    RDBR404
            end if                                                      RDBR405
         else                                                           RDBR406
            nline = nline + 1                                           RDBR407
            extdat(nline) = brkrec(1:66)                                RDBR408
            extres(nline) = aacnt                                       RDBR409
         end if                                                         RDBR410
         goto 1400                                                      RDBR411
      end if                                                            RDBR412
c                                                                       RDBR413
      aacnt = aacnt + 1                                                 RDBR414
      if (aastd(aacnt) .eq. space) then                                 RDBR415
         aastd(aacnt) = 'S'                                             RDBR416
         if (aacode .gt. stdaa) aastd(aacnt) = 'O'                      RDBR417
      else                                                              RDBR418
         if (aacode .gt. stdaa) then                                    RDBR419
            wkpl = index(stdmod,aastd(aacnt))                           RDBR420
            aastd(aacnt) = nstdmd(wkpl:wkpl)                            RDBR421
         end if                                                         RDBR422
      end if                                                            RDBR423
c                                                                       RDBR424
      seqcod(aacnt) = aacode                                            RDBR425
      seqbcd(aacnt) = seqnum                                            RDBR426
      atcnt  = 0                                                        RDBR427
      scatct = 0                                                        RDBR428
      thmcnt = 0                                                        RDBR429
      thmprs(aacnt) = space                                             RDBR430
      do 1200 i = 1, mnchna                                             RDBR431
      atomin(i,aacnt) = .false.                                         RDBR432
 1200 continue                                                          RDBR433
      do 1220 i = 1, sdchna                                             RDBR434
      scatin(i,aacnt) = .false.                                         RDBR435
 1220 continue                                                          RDBR436
      do 1240 i = 1, 3                                                  RDBR437
      atpres(i,aacnt) = space                                           RDBR438
 1240 continue                                                          RDBR439
 1300 continue                                                          RDBR440
c                                                                       RDBR441
c     process cordinates find atom type and if main chain set in coords RDBR442
c                                                                       RDBR443
      read (brkrec, 1320) num, atmnam, altloc, altnum,                  RDBR444
     &                   (acoord(i), i=1,3), occup, therm               RDBR445
CHECK v.2.1.1-->                                                        RDBR446
      IF (brkrec(57:60).EQ.'    ') occup = 1.0                          RDBR447
CHECK v.2.1.1<--                                                        RDBR448
      if (atmnam      .eq. ' OXT' .or. atmnam      .eq. ' NXT' .or.     RDBR449
CHECK v.3.2-->                                                          RDBR450
C     +    atmnam(2:2) .eq. 'H'    .or. atmnam(2:2) .eq. 'D') then      RDBR451
     &    atmnam(2:2) .eq. 'H'    .or. atmnam(2:2) .eq. 'D' .or.        RDBR452
     &    atmnam(2:2) .eq. 'Q') then                                    RDBR453
CHECK v.3.2<--                                                          RDBR454
         if (altloc .ne. space .and. nline .ne. 0) then                 RDBR455
            string = extdat(nline)                                      RDBR456
            read (string, 1121) extatm, extnum, extocc                  RDBR457
CHECK v.2.1.1-->                                                        RDBR458
            IF (string(57:60).EQ.'    ') extocc = 1.0                   RDBR459
CHECK v.2.1.1<--                                                        RDBR460
            if (extatm .eq. atmnam .and. extnum .eq. altnum) then       RDBR461
               if (extocc .ge. occup) then                              RDBR462
                  altlin = altlin + 1                                   RDBR463
                  altdat(altlin) = brkrec(1:66)                         RDBR464
               else                                                     RDBR465
                  altlin = altlin + 1                                   RDBR466
                  altdat(altlin) = string                               RDBR467
                  extdat(nline) = brkrec(1:66)                          RDBR468
               end if                                                   RDBR469
               altres(altlin) = aacnt                                   RDBR470
            else                                                        RDBR471
               nline = nline + 1                                        RDBR472
               extdat(nline) = brkrec(1:66)                             RDBR473
               extres(nline) = aacnt                                    RDBR474
            end if                                                      RDBR475
         else                                                           RDBR476
            nline = nline + 1                                           RDBR477
            extdat(nline) = brkrec(1:66)                                RDBR478
            extres(nline) = aacnt                                       RDBR479
         end if                                                         RDBR480
         goto 1400                                                      RDBR481
      end if                                                            RDBR482
c                                                                       RDBR483
      attype = index(atname,atmnam)                                     RDBR484
      if (attype .eq. 0) then                                           RDBR485
         if (aacode .gt. 44 .and. aacode .le. 50) then                  RDBR486
            attype = index(batnam,atmnam)                               RDBR487
         else if (aacode .eq. 42) then                                  RDBR488
            attype = index(tphnam,atmnam)                               RDBR489
         else if (aacode .eq. 41) then                                  RDBR490
            attype = index(olenam,atmnam)                               RDBR491
         else if (aacode .eq. 36) then                                  RDBR492
            attype = index(pyrnam,atmnam)                               RDBR493
         else                                                           RDBR494
            if (aacode .eq. 39) then                                    RDBR495
               attype = index(pphnam,atmnam)                            RDBR496
            end if                                                      RDBR497
         end if                                                         RDBR498
      end if                                                            RDBR499
c                                                                       RDBR500
      if (altloc .ne. space) then                                       RDBR501
         if (setatm .eq. '    ') then                                   RDBR502
            setatm = atmnam                                             RDBR503
            setloc = altloc                                             RDBR504
            oldocc = occup                                              RDBR505
            oldthm = therm                                              RDBR506
         end if                                                         RDBR507
         if (.not. altset) then                                         RDBR508
            if (setatm .eq. atmnam) then                                RDBR509
               if (occup .gt. oldocc) then                              RDBR510
                  setloc = altloc                                       RDBR511
                  oldocc = occup                                        RDBR512
                  if (xney(oldthm,0.0)) thmcnt = thmcnt - 1             RDBR513
                  oldthm = therm                                        RDBR514
                  if (attype .ne. 0) then                               RDBR515
                     atcnt = atcnt - 1                                  RDBR516
                  else                                                  RDBR517
                     scatct = scatct - 1                                RDBR518
                  end if                                                RDBR519
               end if                                                   RDBR520
            else                                                        RDBR521
               altset = .true.                                          RDBR522
            end if                                                      RDBR523
         end if                                                         RDBR524
      end if                                                            RDBR525
c                                                                       RDBR526
      if (xney(therm,0.0) .and. (altloc .eq. setloc .or.                RDBR527
     &                           altloc .eq. space)) thmcnt = thmcnt + 1RDBR528
      if (attype .ne. 0 .and. (altloc .eq. setloc .or.                  RDBR529
     &                         altloc .eq. space)) then                 RDBR530
         attype = (attype / 4) + 1                                      RDBR531
         if (brkrec(1:keylen) .eq. atmkey) then                         RDBR532
            lab(aacnt) = 'A'                                            RDBR533
         else                                                           RDBR534
            lab(aacnt) = 'H'                                            RDBR535
         end if                                                         RDBR536
c        next section applies to cases where first atom has higher      RDBR537
c        occupancy                                                      RDBR538
         if (xney(mcocc(attype,aacnt),0.0)) then                        RDBR539
            if (mcocc(attype,aacnt) .lt. occup) then                    RDBR540
               naltmc = naltmc + 1                                      RDBR541
               altmci(1,naltmc) = aacnt                                 RDBR542
               altmci(2,naltmc) = attype                                RDBR543
               altmci(3,naltmc) = mcser(attype,aacnt)                   RDBR544
               altmcr(1,naltmc) = mcocc(attype,aacnt)                   RDBR545
               altmcr(2,naltmc) = mcthrm(attype,aacnt)                  RDBR546
               altmcc(naltmc)   = mcalt(attype,aacnt)                   RDBR547
               do 1349 i = 1, ncoord                                    RDBR548
               altmca(i,naltmc) = mcaaat(i,attype,aacnt)                RDBR549
 1349          continue                                                 RDBR550
            end if                                                      RDBR551
         end if                                                         RDBR552
         mcser(attype,aacnt)  = num                                     RDBR553
         mcocc(attype,aacnt)  = occup                                   RDBR554
         mcthrm(attype,aacnt) = therm                                   RDBR555
         mcalt(attype,aacnt)  = altloc                                  RDBR556
         do 1350 i = 1, ncoord                                          RDBR557
         mcaaat(i,attype,aacnt) = acoord(i)                             RDBR558
 1350    continue                                                       RDBR559
         atomin(attype,aacnt) = .true.                                  RDBR560
         if (attype .ne. calph) caonly = .false.                        RDBR561
         atcnt = atcnt + 1                                              RDBR562
      else                                                              RDBR563
         if (attype .ne. 0) then                                        RDBR564
c           alternate main chain locations                              RDBR565
            attype = (attype / 4) + 1                                   RDBR566
            naltmc = naltmc + 1                                         RDBR567
            altmci(1,naltmc) = aacnt                                    RDBR568
            altmci(2,naltmc) = attype                                   RDBR569
            altmci(3,naltmc) = num                                      RDBR570
            altmcr(1,naltmc) = occup                                    RDBR571
            altmcr(2,naltmc) = therm                                    RDBR572
            altmcc(naltmc) = altloc                                     RDBR573
            do 1351 i = 1, ncoord                                       RDBR574
            altmca(i,naltmc) = acoord(i)                                RDBR575
 1351       continue                                                    RDBR576
         end if                                                         RDBR577
      end if                                                            RDBR578
c                                                                       RDBR579
      if (attype .eq. 0 .and. (altloc .eq. setloc .or.                  RDBR580
     &                         altloc .eq. space)) then                 RDBR581
         scatct = scatct + 1                                            RDBR582
         if (aacode .le. sideaa) then                                   RDBR583
            if (aacode .ne. 27) then                                    RDBR584
                                                                        RDBR585
CHECK v.3.2-->                                                          RDBR586
C----          Check for special cases of non-standard atom-labelling   RDBR587
C              (eg if file created by X-PLOR)                           RDBR588
               rname = aacod3(3*(aacode-1)+1:3*aacode)                  RDBR589
               if (rname.eq.'ILE' .and. atmnam.eq.' CD ')               RDBR590
     &             atmnam = ' CD1'                                      RDBR591
               if (rname.eq.'GLN' .and. atmnam.eq.' OE ')               RDBR592
     &             atmnam = ' OE1'                                      RDBR593
               if (rname.eq.'GLU' .and. atmnam.eq.' OE ')               RDBR594
     &             atmnam = ' OE1'                                      RDBR595
CHECK v.3.2<--                                                          RDBR596
               if (atmnam .eq. cbet) then                               RDBR597
                  sctype = 1                                            RDBR598
               else                                                     RDBR599
                  sctype = index(scname(aacode),atmnam)                 RDBR600
                  if (sctype .eq. 0 .and. altpos(aacode) .ne. 0)        RDBR601
     &                sctype = index(altnam(altpos(aacode)),atmnam)     RDBR602
                  if (sctype .ne. 0) sctype = (sctype / 4) + 2          RDBR603
               end if                                                   RDBR604
c              next section applies to cases where first atom has higherRDBR605
c              occupancy                                                RDBR606
               if (sctype .ne. 0) then                                  RDBR607
                  if (xney(scocc(sctype,aacnt),0.0)) then               RDBR608
                     if (scocc(sctype,aacnt) .lt. occup) then           RDBR609
                        naltsc = naltsc + 1                             RDBR610
                        altsci(1,naltsc) = aacnt                        RDBR611
                        altsci(2,naltsc) = sctype                       RDBR612
                        altsci(3,naltsc) = scser(sctype,aacnt)          RDBR613
                        altscr(1,naltsc) = scocc(sctype,aacnt)          RDBR614
                        altscr(2,naltsc) = scthrm(sctype,aacnt)         RDBR615
                        altscc(naltsc)   = scalt(sctype,aacnt)          RDBR616
                        do 1353 i = 1, ncoord                           RDBR617
                        altsca(i,naltsc) = scaaat(i,sctype,aacnt)       RDBR618
1353                    continue                                        RDBR619
                     end if                                             RDBR620
                  end if                                                RDBR621
                  scatin(sctype,aacnt) = .true.                         RDBR622
                  scocc(sctype,aacnt)  = occup                          RDBR623
                  scthrm(sctype,aacnt) = therm                          RDBR624
                  scser(sctype,aacnt)  = num                            RDBR625
                  scalt(sctype,aacnt)  = altloc                         RDBR626
                  do 1375 i = 1, ncoord                                 RDBR627
                  scaaat(i,sctype,aacnt) = acoord(i)                    RDBR628
 1375             continue                                              RDBR629
               else                                                     RDBR630
                  if (seqcod(aacnt) .le. abetsz) then                   RDBR631
                     wkres = aacod3((seqcod(aacnt)*3)-2:                RDBR632
     &                               seqcod(aacnt)*3)                   RDBR633
                  else                                                  RDBR634
                     wkres = hetcod(((seqcod(aacnt)-abetsz)*3)-2:       RDBR635
     &                               (seqcod(aacnt)-abetsz)*3)          RDBR636
                  end if                                                RDBR637
               end if                                                   RDBR638
            else                                                        RDBR639
               nline = nline + 1                                        RDBR640
               extdat(nline) = brkrec(1:66)                             RDBR641
               extres(nline) = aacnt                                    RDBR642
            end if                                                      RDBR643
         end if                                                         RDBR644
      else                                                              RDBR645
         if (atmnam .eq. cbet) then                                     RDBR646
            sctype = 1                                                  RDBR647
         else                                                           RDBR648
CHECK v.3.2-->                                                          RDBR649
C----        Check for special cases of non-standard atom-labelling     RDBR650
C            (eg if file created by X-PLOR)                             RDBR651
             rname = aacod3(3*(aacode-1)+1:3*aacode)                    RDBR652
             if (rname.eq.'ILE' .and. atmnam.eq.' CD ')                 RDBR653
     &           atmnam = ' CD1'                                        RDBR654
             if (rname.eq.'GLN' .and. atmnam.eq.' OE ')                 RDBR655
     &           atmnam = ' OE1'                                        RDBR656
             if (rname.eq.'GLU' .and. atmnam.eq.' OE ')                 RDBR657
     &           atmnam = ' OE1'                                        RDBR658
CHECK v.3.2<--                                                          RDBR659
            sctype = index(scname(aacode),atmnam)                       RDBR660
            if (sctype .eq. 0 .and. altpos(aacode) .ne. 0)              RDBR661
     &          sctype = index(altnam(altpos(aacode)),atmnam)           RDBR662
            if (sctype .ne. 0) sctype = (sctype / 4) + 2                RDBR663
         end if                                                         RDBR664
c        alternate side chain locations                                 RDBR665
         if (sctype .ne. 0) then                                        RDBR666
            naltsc = naltsc + 1                                         RDBR667
            altsci(1,naltsc) = aacnt                                    RDBR668
            altsci(2,naltsc) = sctype                                   RDBR669
            altsci(3,naltsc) = num                                      RDBR670
            altscr(1,naltsc) = occup                                    RDBR671
            altscr(2,naltsc) = therm                                    RDBR672
            altscc(naltsc)   = altloc                                   RDBR673
            do 1352 i = 1, ncoord                                       RDBR674
            altsca(i,naltsc) = acoord(i)                                RDBR675
 1352       continue                                                    RDBR676
         end if                                                         RDBR677
      end if                                                            RDBR678
c                                                                       RDBR679
c     search for the next atom record and treat as appropriate          RDBR680
c     process coords only if same aa                                    RDBR681
c     if new aa start aa process again after setting the count fields   RDBR682
c                                                                       RDBR683
 1400 continue                                                          RDBR684
      read (brkfi, '(a)', end=2000) brkrec                              RDBR685
CHECK v.3.1-->                                                          RDBR686
      IF (BRKREC(1:KEYLEN) .EQ. ENDMDL) GO TO 2000                      RDBR687
CHECK v.3.1<--                                                          RDBR688
      if (brkrec(1:keylen) .ne. endkey) then                            RDBR689
         if (brkrec(1:keylen) .eq. terkey) then                         RDBR690
            nline = nline + 1                                           RDBR691
            extdat(nline) = brkrec(1:66)                                RDBR692
            extres(nline) = aacnt                                       RDBR693
         else if (brkrec(1:keylen) .eq. maskey) then                    RDBR694
            read (brkrec, '(50X,I5)') nrec                              RDBR695
         else                                                           RDBR696
            if (brkrec(1:keylen) .eq. atmkey .or.                       RDBR697
     &          brkrec(1:keylen) .eq. htakey) then                      RDBR698
               read (brkrec, '(12x,a4,a1,4x,a6,27x,f6.2)') altatm,      RDBR699
     &                                     altloc, altnum, altocc       RDBR700
CHECK v.2.1.1-->                                                        RDBR701
               IF (brkrec(57:60).EQ.'    ') altocc = 1.0                RDBR702
CHECK v.2.1.1<--                                                        RDBR703
               if (altnum .eq. seqnum .and.                             RDBR704
     &              keywd .eq. brkrec(1:keylen)) then                   RDBR705
                  if (aacode .le. 0) then                               RDBR706
                     if (nline .gt. 1000 .and. aacnt .eq. 0) then       RDBR707
                        seqlen = 0                                      RDBR708
                        goto 3000                                       RDBR709
                     end if                                             RDBR710
                     if (altloc .ne. space .and. nline .ne. 0) then     RDBR711
                        string = extdat(nline)                          RDBR712
                        read (string, 1121) extatm, extnum, extocc      RDBR713
CHECK v.2.1.1-->                                                        RDBR714
                        IF (string(57:60).EQ.'    ') extocc = 1.0       RDBR715
CHECK v.2.1.1<--                                                        RDBR716
                        if (extatm .eq. altatm .and.                    RDBR717
     &                      extnum .eq. altnum) then                    RDBR718
                           if (extocc .ge. altocc) then                 RDBR719
                              altlin = altlin + 1                       RDBR720
                              altdat(altlin) = brkrec(1:66)             RDBR721
                           else                                         RDBR722
                              altlin = altlin + 1                       RDBR723
                              altdat(altlin) = string                   RDBR724
                              extdat(nline) = brkrec(1:66)              RDBR725
                           end if                                       RDBR726
                           altres(altlin) = aacnt                       RDBR727
                        else                                            RDBR728
                           nline = nline + 1                            RDBR729
                           extdat(nline) = brkrec(1:66)                 RDBR730
                           extres(nline) = aacnt                        RDBR731
                        end if                                          RDBR732
                     else                                               RDBR733
                        nline = nline + 1                               RDBR734
                        extdat(nline) = brkrec(1:66)                    RDBR735
                        extres(nline) = aacnt                           RDBR736
                     end if                                             RDBR737
                     goto 1400                                          RDBR738
                  end if                                                RDBR739
                  goto 1300                                             RDBR740
               else                                                     RDBR741
                  if (aacode .gt. 0) call cntset (atpres, thmprs,       RDBR742
     &                                            altcod, nscats,       RDBR743
     &                                            aacode, aacnt,        RDBR744
     &                                            atcnt,  scatct,       RDBR745
     &                                            thmcnt, setloc)       RDBR746
                  if (aacnt .ge. maxres) then                           RDBR747
CHECK v.1.0-->                                                          RDBR748
C                     write (*, 6010)                                   RDBR749
CHECK v.1.0<--                                                          RDBR750
CHECK v.2.1.3-->                                                        RDBR751
C                     write (logfi, 6010)                               RDBR752
                     write (*, 6010)                                    RDBR753
CHECK v.2.1.3<--                                                        RDBR754
                     goto 2100                                          RDBR755
                  else                                                  RDBR756
                     if (aacode .gt. 0) aastd(aacnt+1) = space          RDBR757
                     goto 1100                                          RDBR758
                  end if                                                RDBR759
               end if                                                   RDBR760
            end if                                                      RDBR761
         end if                                                         RDBR762
         goto 1400                                                      RDBR763
      end if                                                            RDBR764
c                                                                       RDBR765
c     end of input file reached                                         RDBR766
c                                                                       RDBR767
 2000 continue                                                          RDBR768
      if (aacode .gt. 0) call cntset (atpres, thmprs, altcod, nscats,   RDBR769
     &                                aacode, aacnt,  atcnt,  scatct,   RDBR770
     &                                thmcnt, setloc)                   RDBR771
c                                                                       RDBR772
 2100 continue                                                          RDBR773
      seqlen = aacnt                                                    RDBR774
c                                                                       RDBR775
 3000 continue                                                          RDBR776
      if (seqlen .eq. 0) readok = .false.                               RDBR777
CHECK v.3.1-->                                                          RDBR778
C      close (brkfi)                                                    RDBR779
      IF (.NOT.NMR) THEN                                                RDBR780
          close (brkfi)                                                 RDBR781
      ENDIF                                                             RDBR782
CHECK v.3.1<--                                                          RDBR783
c 901 write(*, 3001) brkfi, kount                                       RDBR784
c3001 format (' Error reading input file on unit 'i2,                   RDBR785
c    +        ' after 'i5,' lines')                                     RDBR786
      end                                                               RDBR787
