



      SUBROUTINE SC5001

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       CHKTODO







      CALL TEXSECT ('?CHKM04')



      IF (CHKTODO('BND')) CALL BND003



      IF (CHKTODO('ANG')) THEN
         IF (WIFPAR(84).LE.0) THEN
            CALL SC5002
         ELSE
            CALL SC5003
         END IF
      END IF



      IF (CHKTODO('HND')) CALL SC5008



      IF (CHKTODO('TAU')) CALL SC5011



      IF (CHKTODO('PLN')) CALL PLN005



      IF (CHKTODO('PL2')) CALL PLN011



      IF (WIFPAR(84).NE.0) THEN
         IF (CHKTODO('PLH')) CALL PLN012
      END IF



      IF (CHKTODO('PL3')) CALL PLN005A





      RETURN
      END   
      SUBROUTINE SC5002




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'RESULT.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, IAT, JAT, KAT, NUM, IRT, IANG, IMOD, NUMMDL,
     +              ACTIVE, NNUM(MAXMODEL)
      REAL          SCORE,  SUM2, SUM, SUMA, VALUE, RMSD, MU, SIG,
     +              NSUM2(MAXMODEL)
      LOGICAL       WIFIRA, WIFIRN







      CALL CDB013 ('BANGNOK','BANGNEU','BANGOK')



      CALL GVSRTC (PRPVAL,-1000.0,MAXAA)



      NUM=0
      SUMA=0.0
      SUM2=0.0
      SUM=0.0
      RMSD=0.0
      CALL GVSIT0 (NNUM,MAXMODEL)
      CALL GVSRT0 (NSUM2,MAXMODEL)



      DO 200 IAA=1,NUMAAF
         IRT=RESTYP(IAA)
         IMOD=MODNMB(IAA)
         IF (IRT.LT.1) GOTO 200



         IF (IAA.EQ.1) GOTO 190
         IF (CHAINN(2,IAA).NE.CHAINN(2,IAA-1)) GOTO 190



         IF (WIFIRA(IAA)) THEN






            IAT=PNTAAS(IAA-1)+3
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               MU=122.0
               SIG=1.4
            ELSE
               MU=123.0
               SIG=1.6
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-O  ','-C  ',' N  ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAC(IAA-1)
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               IF (RESTYP(IAA-1).EQ.6) THEN
                  MU=118.2
                  SIG=2.1
               ELSE
                  MU=116.9
                  SIG=1.5
               END IF
            ELSE
               IF (RESTYP(IAA-1).EQ.6) THEN
                  MU=116.4
                  SIG=2.1
               ELSE
                  MU=116.2
                  SIG=2.0
               END IF
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-CA ','-C  ',' N  ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA-1)+2
            JAT=PNTAAS(IAA)
            KAT=PNTAAC(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               MU=122.6
               SIG=5.0
            ELSE IF (RESTYP(IAA).EQ.6) THEN
               MU=120.6
               SIG=1.7
            ELSE
               MU=121.7
               SIG=1.8
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-C  ',' N  ',' CA ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               IAT=PNTAAS(IAA-1)+2
               JAT=PNTAAS(IAA)
               KAT=PNTAAS(IAA)+6
               MU=125.0
               SIG=4.1
               CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
               IF (VALUE.GT.-900.0) THEN
                  CALL SC5102 (IAA,'-C  ',' N  ',' CD ',VALUE,SCORE)
                  CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
                  CALL SC5104 (VALUE-MU,SCORE,RMSD)
               END IF
            END IF
         ELSE IF (WIFIRN(IAA)) THEN



            IAT=PNTAAS(IAA)+3
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=107.4
            SIG=3.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' OP1',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)+4
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=108.3
            SIG=3.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' OP2',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)+5
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=104.0
            SIG=1.9
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' O5*',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA-1)+1
            MU=119.7
            SIG=1.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' P  ','-C3*','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF
         END IF
  190    CONTINUE
         DO 90 IANG=1,MAXANG
            IF (ANGCON(1,IANG,IRT).EQ.0) GOTO 200
            IF (ANGSIG(IANG,IRT).LE.0.0001) GOTO 90
            IAT=PNTAAS(IAA)+ANGCON(1,IANG,IRT)-1
            JAT=PNTAAS(IAA)+ANGCON(2,IANG,IRT)-1
            KAT=PNTAAS(IAA)+ANGCON(3,IANG,IRT)-1
            MU=ANGDEF(IANG,IRT)
            SIG=ANGSIG(IANG,IRT)
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,ONESAT(IAT),ONESAT(JAT),ONESAT(KAT),
     +          VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF
 90      CONTINUE



 200  CONTINUE



      CALL CDB012



      FIXLST(4)=0.0
      IF (NUM.GT.0) THEN
         GENRVL(20)=SQRT(SUM2/NUM)
         GENRVL(22)=SQRT(RMSD/NUM)
         FIXLST(4)=GENRVL(20)



         IF (GENRVL(20).LT.0.6665.AND.WIFPAR(1503).LE.0.AND.
     +        WIFPAR(941).LT.200) THEN
            CALL PDBMES ('BANGZLO')
         ELSE IF (GENRVL(20).GT.2.0) THEN
            CALL PDBMES ('BANGZHI')
         ELSE
            CALL PDBMES ('BANGZOK')
         END IF
      END IF



      ACTIVE=0
      DO 400 IMOD=1,NUMMDL()
         IF (NNUM(IMOD).GT.0) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=SQRT(NSUM2(IMOD)/NNUM(IMOD))
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  400 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1) CALL PDBMES ('ANGNMR')





      RETURN
      END
      SUBROUTINE SC5003


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR
      REAL          HEAVYRMS, PROTRMS








      CALL SC5105 (HEAVYRMS,PROTRMS,IERR)
      IF (IERR.NE.0.OR.ABS(HEAVYRMS).LT.0.0001) THEN
         CALL SC5002
         GOTO 998
      END IF
      CALL GVSTTR ('?M3482',PROTRMS/HEAVYRMS)
      IF (WIFPAR(279).NE.0.AND.PROTRMS/HEAVYRMS.LT.1.5) THEN



         CALL SC5002
      ELSE



         CALL SC5006



         CALL SC5007
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC5101 (IAT,JAT,KAT,AVE,STD,VALUE,SCORE)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, JAT, KAT
      REAL          AVE, STD, VALUE, SCORE, V1(3), V2(3), GVFRTD, GVFANG





      IF (.NOT.ISATOK(IAT)) GOTO 999
      IF (.NOT.ISATOK(JAT)) GOTO 999
      IF (.NOT.ISATOK(KAT)) GOTO 999
      V1(1)=XCOORD(IAT)-XCOORD(JAT)
      V1(2)=YCOORD(IAT)-YCOORD(JAT)
      V1(3)=ZCOORD(IAT)-ZCOORD(JAT)
      V2(1)=XCOORD(KAT)-XCOORD(JAT)
      V2(2)=YCOORD(KAT)-YCOORD(JAT)
      V2(3)=ZCOORD(KAT)-ZCOORD(JAT)
      VALUE=GVFRTD(GVFANG(V1,V2))
      SCORE=(VALUE-AVE)/STD



      CALL PDBS50 (IAT,JAT,KAT,0,ABS(SCORE),4.0,4.0)
      GOTO 998



  999 CONTINUE
      VALUE=-999.9
      SCORE=0.0



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC5102 (IAA,NAM1,NAM2,NAM3,VALUE,SCORE)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA
      REAL          VALUE, SCORE
      CHARACTER*4   NAM1, NAM2, NAM3







      IF (ABS(SCORE).GT.4.0) THEN
         IF (WIFPAR(279).NE.0) THEN
            CALL PDBC92A (IAA,0)
            WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:23),NAM1,NAM2,NAM3,
     +       VALUE,SCORE
            CALL PDBC93 (LINE2)
         ELSE
            IF (WIFPAR(1012).GE.1) THEN
               WRITE (6,'(A,1X,3(A4,1X),F6.2,F6.1)',ERR=999) 
     +          LINE92(1:23),NAM1,NAM2,NAM3,VALUE,SCORE
            END IF
         END IF
      END IF



      PRPVAL(IAA)=MAX(PRPVAL(IAA),ABS(SCORE))
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('SC5102')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)



















      IMPLICIT      NONE
      INCLUDE       'PDBINC.INC'
      REAL          SCORE, SUM, SUM2, SUMA, NSUM2(MAXMODEL)
      INTEGER       NUM, NNUM(MAXMODEL), IMOD





      IF (ABS(SCORE).LT.10.0) THEN
         NUM=NUM+1
         SUM=SUM+SCORE
         SUM2=SUM2+SCORE**2
         SUMA=SUMA+ABS(SCORE)
         IF (IMOD.GT.0.AND.IMOD.LE.MAXMODEL) THEN
            NNUM(IMOD)=NNUM(IMOD)+1
            NSUM2(IMOD)=NSUM2(IMOD)+SCORE**2
         END IF
      END IF





      RETURN
      END
      SUBROUTINE SC5104 (DEVI,SCORE,RMSD)



















      IMPLICIT      NONE
      REAL          DEVI, RMSD, SCORE







      IF (ABS(SCORE).LT.10.0) THEN
         IF (ABS(DEVI).GT.170.0) THEN
            CALL GVSTTB ('?R00292')
            CALL GVSTTR ('?R00293',DEVI)
            CALL GVSTTR ('?M3483',SCORE)
            CALL GVSKIL
         END IF
         RMSD=RMSD+DEVI**2
      END IF





      RETURN
      END
      SUBROUTINE SC5105 (HEAVYRMS,PROTRMS,IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, JAT, KAT, IANG, HEAVYCNT, PROTCNT, IERR,
     +              IAATYP
      REAL          HEAVYRMS, PROTRMS, VALUE, SCORE
      LOGICAL       WIFIRR, HASPROTON







      IF (WIFPAR(84).LE.0) THEN
         IERR=1
         HEAVYRMS=0.0
         PROTRMS=0.0
         GOTO 998
      END IF
      IF (.NOT.HASPROTON()) GOTO 998



      HEAVYRMS=0.0
      PROTRMS=0.0
      HEAVYCNT=0.0
      PROTCNT=0.0
      IERR=0



      DO 100 IAA=1,NUMAAF
         IF (.NOT.WIFIRR(IAA)) GOTO 100
         IAATYP=RESTYP(IAA)



         DO 90 IANG=1,MAXANG
            IF (ANGCON(1,IANG,IAATYP).EQ.0) GOTO 100
            IF (ANGSIG(IANG,IAATYP).LE.0.0001) GOTO 90



            IAT=PNTAAS(IAA)+ANGCON(1,IANG,IAATYP)-1
            IF (.NOT.ISATOK(IAT)) GOTO 90
            JAT=PNTAAS(IAA)+ANGCON(2,IANG,IAATYP)-1
            IF (.NOT.ISATOK(JAT)) GOTO 90
            KAT=PNTAAS(IAA)+ANGCON(3,IANG,IAATYP)-1
            IF (.NOT.ISATOK(KAT)) GOTO 90



            CALL SC5101 (IAT,JAT,KAT,ANGDEF(IANG,IAATYP),
     +       ANGSIG(IANG,IAATYP),VALUE,SCORE)



            IF (PROTON(IAT).OR.PROTON(JAT).OR.PROTON(KAT)) THEN
               PROTCNT=PROTCNT+1
               PROTRMS=PROTRMS+SCORE**2
            ELSE
               HEAVYCNT=HEAVYCNT+1
               HEAVYRMS=HEAVYRMS+SCORE**2
            END IF
   90    CONTINUE
  100 CONTINUE



      IF (HEAVYCNT.LE.0.OR.PROTCNT.LE.0) THEN
         CALL GVSTTE ('?M1756')
         IERR=1
         GOTO 998
      END IF



      PROTRMS=SQRT(PROTRMS/PROTCNT)
      HEAVYRMS=SQRT(HEAVYRMS/HEAVYCNT)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE SC5006


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'RESULT.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, IAT, JAT, KAT, NUM, IRT, IANG, IMOD, NUMMDL,
     +              ACTIVE, NNUM(MAXMODEL)
      REAL          SCORE,  SUM2, SUM, SUMA, VALUE, RMSD, MU, SIG,
     +              NSUM2(MAXMODEL)
      LOGICAL       WIFIRA, WIFIRN







      CALL CDB013 ('BANGNOKH','BANGNEU','BANGOKH')



      CALL GVSRTC (PRPVAL,-1000.0,MAXAA)



      NUM=0
      SUMA=0.0
      SUM2=0.0
      SUM=0.0
      RMSD=0.0
      CALL GVSIT0 (NNUM,MAXMODEL)
      CALL GVSRT0 (NSUM2,MAXMODEL)



      DO 200 IAA=1,NUMAAF
         IRT=RESTYP(IAA)
         IMOD=MODNMB(IAA)
         IF (IRT.LT.1) GOTO 200



         IF (IAA.EQ.1) GOTO 190
         IF (CHAINN(2,IAA).NE.CHAINN(2,IAA-1)) GOTO 190



         IF (WIFIRA(IAA)) THEN






            IAT=PNTAAS(IAA-1)+3
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               MU=122.0
               SIG=1.4
            ELSE
               MU=123.0
               SIG=1.6
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-O  ','-C  ',' N  ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAC(IAA-1)
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               IF (RESTYP(IAA-1).EQ.6) THEN
                  MU=118.2
                  SIG=2.1
               ELSE
                  MU=116.9
                  SIG=1.5
               END IF
            ELSE
               IF (RESTYP(IAA-1).EQ.6) THEN
                  MU=116.4
                  SIG=2.1
               ELSE
                  MU=116.2
                  SIG=2.0
               END IF
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-CA ','-C  ',' N  ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA-1)+2
            JAT=PNTAAS(IAA)
            KAT=PNTAAC(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               MU=122.6
               SIG=5.0
            ELSE IF (RESTYP(IAA).EQ.6) THEN
               MU=120.6
               SIG=1.7
            ELSE
               MU=121.7
               SIG=1.8
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-C  ',' N  ',' CA ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               IAT=PNTAAS(IAA-1)+2
               JAT=PNTAAS(IAA)
               KAT=PNTAAS(IAA)+6
               MU=125.0
               SIG=4.1
               CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
               IF (VALUE.GT.-900.0) THEN
                  CALL SC5102 (IAA,'-C  ',' N  ',' CD ',VALUE,SCORE)
                  CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
                  CALL SC5104 (VALUE-MU,SCORE,RMSD)
               END IF
            END IF
         ELSE IF (WIFIRN(IAA)) THEN



            IAT=PNTAAS(IAA)+3
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=107.4
            SIG=3.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' OP1',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)+4
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=108.3
            SIG=3.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' OP2',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)+5
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=104.0
            SIG=1.9
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' O5*',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA-1)+1
            MU=119.7
            SIG=1.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' P  ','-C3*','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF
         END IF
  190    CONTINUE
         DO 90 IANG=1,MAXANG
            IF (ANGCON(1,IANG,IRT).EQ.0) GOTO 200
            IF (ANGSIG(IANG,IRT).LE.0.0001) GOTO 90
            IAT=PNTAAS(IAA)+ANGCON(1,IANG,IRT)-1
            JAT=PNTAAS(IAA)+ANGCON(2,IANG,IRT)-1
            KAT=PNTAAS(IAA)+ANGCON(3,IANG,IRT)-1
            IF (PROTON(IAT).OR.PROTON(JAT).OR.PROTON(KAT)) GOTO 90
            MU=ANGDEF(IANG,IRT)
            SIG=ANGSIG(IANG,IRT)
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,ONESAT(IAT),ONESAT(JAT),ONESAT(KAT),
     +          VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF
 90      CONTINUE
 200  CONTINUE



      CALL CDB012



      IF (NUM.GT.0) THEN
         GENRVL(20)=SQRT(SUM2/NUM)
         GENRVL(22)=SQRT(RMSD/NUM)



         IF (GENRVL(20).LT.0.6665.AND.WIFPAR(1503).LE.0.AND.
     +        WIFPAR(941).LT.200) THEN
            CALL PDBMES ('BANGZLO')
         ELSE IF (GENRVL(20).GT.2.0) THEN
            CALL PDBMES ('BANGZHI')
         ELSE
            CALL PDBMES ('BANGZOK')
         END IF
      END IF



      ACTIVE=0
      DO 400 IMOD=1,NUMMDL()
         IF (NNUM(IMOD).GT.0) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=SQRT(NSUM2(IMOD)/NNUM(IMOD))
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  400 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1) CALL PDBMES ('ANGNMR')





      RETURN
      END
      SUBROUTINE SC5007


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'RESULT.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, IAT, JAT, KAT, NUM, IRT, IANG, IMOD, NUMMDL,
     +              ACTIVE, NNUM(MAXMODEL)
      REAL          SCORE,  SUM2, SUM, SUMA, VALUE, RMSD, MU, SIG,
     +              NSUM2(MAXMODEL)
      LOGICAL       WIFIRA, WIFIRN
      CHARACTER*4   C1, C2, C3, T4







      CALL CDB013 ('BANGNOKP',' ','BANGOKP')



      CALL GVSRTC (PRPVAL,-1000.0,MAXAA)



      NUM=0
      SUMA=0.0
      SUM2=0.0
      SUM=0.0
      RMSD=0.0
      CALL GVSIT0 (NNUM,MAXMODEL)
      CALL GVSRT0 (NSUM2,MAXMODEL)



      DO 200 IAA=1,NUMAAF
         IRT=RESTYP(IAA)
         IMOD=MODNMB(IAA)
         IF (IRT.LT.1) GOTO 200



         IF (IAA.EQ.1) GOTO 190
         IF (CHAINN(2,IAA).NE.CHAINN(2,IAA-1)) GOTO 190



         IF (WIFIRA(IAA)) THEN






            IAT=PNTAAS(IAA-1)+3
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               MU=122.0
               SIG=1.4
            ELSE
               MU=123.0
               SIG=1.6
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-O  ','-C  ',' N  ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAC(IAA-1)
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               IF (RESTYP(IAA-1).EQ.6) THEN
                  MU=118.2
                  SIG=2.1
               ELSE
                  MU=116.9
                  SIG=1.5
               END IF
            ELSE
               IF (RESTYP(IAA-1).EQ.6) THEN
                  MU=116.4
                  SIG=2.1
               ELSE
                  MU=116.2
                  SIG=2.0
               END IF
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-CA ','-C  ',' N  ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA-1)+2
            JAT=PNTAAS(IAA)
            KAT=PNTAAC(IAA)
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               MU=122.6
               SIG=5.0
            ELSE IF (RESTYP(IAA).EQ.6) THEN
               MU=120.6
               SIG=1.7
            ELSE
               MU=121.7
               SIG=1.8
            END IF
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,'-C  ',' N  ',' CA ',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               IAT=PNTAAS(IAA-1)+2
               JAT=PNTAAS(IAA)
               KAT=PNTAAS(IAA)+6
               MU=125.0
               SIG=4.1
               CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
               IF (VALUE.GT.-900.0) THEN
                  CALL SC5102 (IAA,'-C  ',' N  ',' CD ',VALUE,SCORE)
                  CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
                  CALL SC5104 (VALUE-MU,SCORE,RMSD)
               END IF
            END IF
         ELSE IF (WIFIRN(IAA)) THEN



            IAT=PNTAAS(IAA)+3
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=107.4
            SIG=3.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' OP1',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)+4
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=108.3
            SIG=3.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' OP2',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)+5
            JAT=PNTAAS(IAA)
            KAT=PNTAAS(IAA-1)+2
            MU=104.0
            SIG=1.9
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' O5*',' P  ','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF



            IAT=PNTAAS(IAA)
            JAT=PNTAAS(IAA-1)+2
            KAT=PNTAAS(IAA-1)+1
            MU=119.7
            SIG=1.2
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               CALL SC5102 (IAA,' P  ','-C3*','-O3*',VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF
         END IF
  190    CONTINUE
         DO 90 IANG=1,MAXANG
            IF (ANGCON(1,IANG,IRT).EQ.0) GOTO 200
            IF (ANGSIG(IANG,IRT).LE.0.0001) GOTO 90
            IAT=PNTAAS(IAA)+ANGCON(1,IANG,IRT)-1
            JAT=PNTAAS(IAA)+ANGCON(2,IANG,IRT)-1
            KAT=PNTAAS(IAA)+ANGCON(3,IANG,IRT)-1
            IF (.NOT.(PROTON(IAT).OR.PROTON(JAT).OR.
     +       PROTON(KAT))) GOTO 90
            MU=ANGDEF(IANG,IRT)
            SIG=ANGSIG(IANG,IRT)
            CALL SC5101 (IAT,JAT,KAT,MU,SIG,VALUE,SCORE)
            IF (VALUE.GT.-900.0) THEN
               C1=T4(ONESAT(IAT))
               C2=T4(ONESAT(JAT))
               C3=T4(ONESAT(KAT))
               CALL SC5102 (IAA,C1,C2,C3,VALUE,SCORE)
               CALL SC5103 (SCORE,NUM,SUM,SUM2,SUMA,NNUM,NSUM2,IMOD)
               CALL SC5104 (VALUE-MU,SCORE,RMSD)
            END IF
 90      CONTINUE
 200  CONTINUE



      CALL CDB012



      IF (NUM.GT.0) THEN
         GENRVL(20)=SQRT(SUM2/NUM)
         GENRVL(22)=SQRT(RMSD/NUM)



         IF (GENRVL(20).LT.0.6665.AND.WIFPAR(1503).LE.0.AND.
     +       WIFPAR(941).LT.200) THEN
            CALL PDBMES ('BANGZLO')
         ELSE IF (GENRVL(20).GT.2.0) THEN
            CALL PDBMES ('BANGZHI')
         ELSE
            CALL PDBMES ('BANGZOK')
         END IF
      END IF



      ACTIVE=0
      DO 400 IMOD=1,NUMMDL()
         IF (NNUM(IMOD).GT.0) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=SQRT(NSUM2(IMOD)/NNUM(IMOD))
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  400 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1) CALL PDBMES ('ANGNMR')





      RETURN
      END
      SUBROUTINE SC5008





















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'RESULT.INC'
      INCLUDE       'IMPROP.INC'
      INTEGER       NNUM(MAXMODEL), IMOD, NUMMDL, ATT, IRT, IAA, 
     +              IAT, ACTIVE, INMR
      REAL          PDBC71, VAL, RVAL, SUM2, NUM, NSUM2(MAXMODEL), 
     +              NSUM(MAXMODEL), SUM, LVAL
      LOGICAL       HASPROTEIN, WIFIRA, GVFRIN
      CHARACTER*10  MESS







      IF (.NOT.HASPROTEIN()) GOTO 998



      CALL SC5009



      SUM2=0.0
      SUM=0.0
      NUM=0.0
      CALL GVSIT0 (NNUM,MAXMODEL)
      CALL GVSRT0 (NSUM,MAXMODEL)
      CALL GVSRT0 (NSUM2,MAXMODEL)
      CALL GVSRTC (ATTVAL,-999.99,NUMATF)
      CALL CDB013 ('IMPRERR','IMPRNEU','IMPROK')



      DO 100 IAA=1,NUMAAF
         IF (WIFIRA(IAA).AND.RESTYP(IAA).LE.20) THEN
            DO 110 IAT=PNTAAS(IAA),PNTAAE(IAA)
               IF (BOUND_TO(1,IAT).LE.0) THEN
                  ATTVAL(IAT)=PDBC71(IAT)
               END IF
  110       CONTINUE
         END IF
  100 CONTINUE



      DO 200 IAA=1,NUMAAF
         DO 190 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT).OR.WEIGHT(IAT).LT.0.8.OR.
     +       BOUND_TO(1,IAT).NE.0.OR.ATTVAL(IAT).LT.-900.0) GOTO 190
            ATT=PINIAA(IAT)
            IRT=RESTYP(IAA)
            LVAL=ABS(ATTVAL(IAT)-IMPAVE(ATT,IRT))
            RVAL=(ATTVAL(IAT)-IMPAVE(ATT,IRT))/IMPSIG(ATT,IRT)
            IF (.NOT.GVFRIN(RVAL,-250.0,250.0)) THEN
               CALL GVST6C ('?M3212',ONESAT(IAT),.TRUE.)
               GOTO 190
            END IF



            VAL=ATTVAL(IAT)
            ATTVAL(IAT)=RVAL



            SUM=SUM+LVAL
            SUM2=SUM2+RVAL**2
            NUM=NUM+1.0
            IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
               NSUM(MODNMB(IAA)) =NSUM(MODNMB(IAA))+LVAL
               NSUM2(MODNMB(IAA))=NSUM2(MODNMB(IAA))+RVAL**2
               NNUM(MODNMB(IAA)) =NNUM(MODNMB(IAA))+1
            END IF



            IF (ABS(RVAL).GT.6.0.AND.(ATT.LE.4.OR.
     +          ABS(IMPAVE(ATT,IRT)).GT.10.0)) THEN



               IF ((VAL.GT.0.0.AND.IMPAVE(ATT,IRT).LT.-10.0).OR.
     +             (VAL.LT.0.0.AND.IMPAVE(ATT,IRT).GT.10.0)) THEN
                  CALL GVSSTX (MESS,'?M3484')



                  SUM=SUM-LVAL
                  SUM2=SUM2-RVAL**2
                  NUM=NUM-1.0
                  IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
                     NSUM(MODNMB(IAA)) =NSUM(MODNMB(IAA))-LVAL
                     NSUM2(MODNMB(IAA))=NSUM2(MODNMB(IAA))-RVAL**2
                     NNUM(MODNMB(IAA)) =NNUM(MODNMB(IAA))-1
                  END IF
               ELSE
                  CALL GVSCTB (MESS,10)
               END IF
               IF (WIFPAR(279).NE.0) THEN
                  CALL PDBC92A (IAA,IAT)
                  WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:28),RVAL,VAL,
     +             IMPAVE(ATT,IRT),MESS
                  CALL PDBC93 (LINE2)
                  CALL PDBS50 (IAT,0,0,0,ABS(RVAL),6.0,6.0)
               ELSE
                  IF (WIFPAR(1012).GE.1) THEN
                     WRITE (6,*,ERR=999) LINE92(1:28),RVAL,VAL,
     +                IMPAVE(ATT,IRT),MESS
                  END IF
               END IF
            END IF
 190     CONTINUE
 200  CONTINUE
      CALL CDB012






      IF (NUM.LE.0) THEN
         GENRVL(35)=-999.9
      ELSE
         GENRVL(35)=SQRT(SUM2/NUM)
      END IF
      CALL GVSTTR ('?M3485',SUM/NUM)




      IF (GENRVL(35).GT.2.5) THEN
         CALL PDBMES ('IMPZHI')
      ELSE IF (GENRVL(35).GT.2.0) THEN
         CALL PDBMES ('IMPHI')
      ELSE
         CALL PDBMES ('IMPZOK')
      END IF



      ACTIVE=0
      INMR=NUMMDL()
      DO 300 IMOD=1,INMR
         IF (NNUM(IMOD).GT.0) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=SQRT(NSUM2(IMOD)/NNUM(IMOD))
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  300 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1) CALL PDBMES ('HNDNMR')
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('SC5008')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC5009 

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA
      LOGICAL       WIFIRA







      CALL CDB013 ('HNDONEBD','HNDDONENEU','HNDDONEOK')



      DO 100 IAA=1,NUMAAF
         IF (.NOT.WIFIRA(IAA)) GOTO 100



         IF (RESTYP(IAA).EQ.3) THEN
            CALL SC5010 (PNTAAS(IAA)+6,PNTAAS(IAA)+7)



         ELSE IF (RESTYP(IAA).EQ.4) THEN
            CALL SC5010 (PNTAAS(IAA)+7,PNTAAS(IAA)+8)



         ELSE IF (RESTYP(IAA).EQ.8) THEN
            CALL SC5010 (PNTAAS(IAA)+5,PNTAAS(IAA)+6)



         ELSE IF (RESTYP(IAA).EQ.10) THEN
            CALL SC5010 (PNTAAS(IAA)+5,PNTAAS(IAA)+6)



         ELSE IF (RESTYP(IAA).EQ.15) THEN
            CALL SC5010 (PNTAAS(IAA)+9,PNTAAS(IAA)+10)



         ELSE IF (RESTYP(IAA).EQ.17) THEN
            CALL SC5010 (PNTAAS(IAA)+5,PNTAAS(IAA)+6)



         ELSE IF (RESTYP(IAA).EQ.18) THEN
            CALL SC5010 (PNTAAS(IAA)+5,PNTAAS(IAA)+6)
         END IF
 100  CONTINUE
      CALL CDB012





      RETURN
      END   
      SUBROUTINE SC5010 (IAT,JAT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, JAT, IAA
      LOGICAL       CH5EQCH5







      IF (.NOT.CH5EQCH5(ONESAT(IAT),ORGNAM(JAT))) GOTO 998
      IF (.NOT.CH5EQCH5(ONESAT(JAT),ORGNAM(IAT))) GOTO 998



      IAA=ATIAA(IAT)
      PRPVAL(IAA)=1.0
      CALL PDBC92 (IAA,0)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE SC5011

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'HSTINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       IAA, ITYP, MAXIAA, NUM, IUNIT, IHST, GVFLEN, I,
     +              GVFLFR, IERR
      REAL          AVER(20,3), SIGM(20,3), MAXVAL, SUM2, TEMP(6), 
     +              WIFANG, TAU
      LOGICAL       HASPROTEIN, GRTFILE







      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00014')
         GOTO 998
      END IF



      IUNIT=0
      CALL GVSRTC (PRPVAL,-1000.0,NUMAAT)
      CALL DSP001 (.TRUE.)



      CALL GVSCCC (LINE4,WHERIS,'TAU.VAL')
      IF (.NOT.GRTFILE(IUNIT,LINE4)) GOTO 999
      DO 1 IAA=1,20
         CALL GETLINE (IUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999
         I=GVFLFR(6,TEMP,LINE)
         IF (I.NE.6) GOTO 999
         AVER(IAA,1)=TEMP(1)
         SIGM(IAA,1)=TEMP(2)
         AVER(IAA,2)=TEMP(3)
         SIGM(IAA,2)=TEMP(4)
         AVER(IAA,3)=TEMP(5)
         SIGM(IAA,3)=TEMP(6)
 1    CONTINUE



      CALL CDB013 ('TAUNOK','TAUNEU','TAUOK')



      DO 100 IAA=1,NUMAAF
         IF (ISATOK(PNTAAS(IAA)).AND.ISATOK(PNTAAC(IAA)).AND.
     +       ISATOK(PNTAAC(IAA)+1)) THEN
            ITYP=RESTYP(IAA)
            IF (ITYP.GE.1.AND.ITYP.LE.20) THEN
               IF (LOCHST(IAA).EQ.'H'.OR.LOCHST(IAA).EQ.'3') THEN
                  IHST=1
               ELSE IF (LOCHST(IAA).EQ.'S') THEN
                  IHST=2
               ELSE
                  IHST=3
               END IF
               TAU=WIFANG(PNTAAS(IAA),PNTAAC(IAA),PNTAAC(IAA)+1)
               PRPVAL(IAA)=(ABS(AVER(ITYP,IHST)-TAU))/SIGM(ITYP,IHST)
            END IF
         END IF
 100  CONTINUE



      SUM2=0.0
      NUM=0
      DO 200 IAA=1,NUMAAT
         IF (PRPVAL(IAA).GT.-900.) THEN
            NUM=NUM+1
            SUM2=SUM2+PRPVAL(IAA)**2
         END IF
  200 CONTINUE
      IF (NUM.GT.0) THEN
         GENRVL(49)=SQRT(SUM2/NUM)
      ELSE
         GENRVL(49)=-999.9
      END IF
      GENIVL(13)=NUM



      CALL GVSBTT (WRK1TF,MAXAA)
 10   CONTINUE
      MAXIAA=0
      MAXVAL=4.0
      DO 20 IAA=1,NUMAAF
         IF (WRK1TF(IAA).AND.PRPVAL(IAA).GT.MAXVAL) THEN
            MAXVAL=PRPVAL(IAA)
            MAXIAA=IAA
         END IF
 20   CONTINUE
      IF (MAXIAA.GT.0) THEN
         IAA=MAXIAA
         IF (WIFPAR(279).NE.0) THEN
            CALL PDBC92A (IAA,0)
            WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +       PRPVAL(IAA)
            CALL PDBC93 (LINE2)
            CALL PDBS50 (PNTAAC(IAA),0,0,0,PRPVAL(IAA),4.0,4.0)
         ELSE
            IF (WIFPAR(1012).GE.1) THEN
               WRITE (6,*,ERR=999) LINE92(1:GVFLEN(LINE92)),PRPVAL(IAA)
            END IF
         END IF
         WRK1TF(IAA)=.FALSE.
         GOTO 10
      END IF



      CALL CDB012




      IF (GENRVL(49).GT.1.5) THEN
         CALL PDBMES ('TAUZHI')
      ELSE IF (GENRVL(49).LT.0.5) THEN
         CALL PDBMES ('TAUZLO')
      ELSE
         CALL PDBMES ('TAUZOK')
      END IF
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('SC5011')



  998 CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)


      RETURN
      END
      SUBROUTINE SC5012


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'HSTINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       IAA, ITYP, NUM, IUNIT, IHST, I, GVFLFR, IERR, ISEQ, 
     +              ISEQ1, ISEQ2, AVE, SDEV
      REAL          AVER(20,3), SIGM(20,3), SUM2, TEMP(6), WIFANG, TAU,
     +              BIGROW(1000)
      LOGICAL       GRTFILE







      CALL WIFPUSHPPP (826,2)
      CALL GHS021 (0,0,IERR)
      CALL GVSRT0 (BIGROW,1000)



      CALL GVSCCC (LINE4,WHERIS,'TAU.VAL')
      IF (.NOT.GRTFILE(IUNIT,LINE4)) GOTO 999
      DO 10 IAA=1,20
         CALL GETLINE (IUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999
         I=GVFLFR(6,TEMP,LINE)
         IF (I.NE.6) GOTO 999
         AVER(IAA,1)=TEMP(1)
         SIGM(IAA,1)=TEMP(2)
         AVER(IAA,2)=TEMP(3)
         SIGM(IAA,2)=TEMP(4)
         AVER(IAA,3)=TEMP(5)
         SIGM(IAA,3)=TEMP(6)
 10   CONTINUE



      CALL WIFGPR (ISEQ1,ISEQ2)
      DO 100 ISEQ=ISEQ1,ISEQ2



         CALL GVSTTI ('?WORKON',ISEQ)
         CALL MOL100
         CALL WIF004 (ISEQ)
         CALL GVSRTC (PRPVAL,-1000.0,NUMAAT)
         CALL DSP001 (.TRUE.)



         DO 20 IAA=1,NUMAAF
            IF (ISATOK(PNTAAS(IAA)).AND.ISATOK(PNTAAC(IAA)).AND.
     +          ISATOK(PNTAAC(IAA)+1)) THEN
               ITYP=RESTYP(IAA)
               IF (ITYP.GE.1.AND.ITYP.LE.20) THEN
                  IF (LOCHST(IAA).EQ.'H'.OR.LOCHST(IAA).EQ.'3') THEN
                     IHST=1
                  ELSE IF (LOCHST(IAA).EQ.'S') THEN
                     IHST=2
                  ELSE
                     IHST=3
                  END IF
                  TAU=WIFANG(PNTAAS(IAA),PNTAAC(IAA),PNTAAC(IAA)+1)
                  PRPVAL(IAA)=(ABS(AVER(ITYP,IHST)-TAU))/SIGM(ITYP,IHST)
                  IF (IAA.LE.25) PRINT*,IAA,ONESA3(IAA),LOCHST(IAA),TAU,
     +             PRPVAL(IAA)
               END IF
            END IF
 20      CONTINUE



         SUM2=0.0
         NUM=0
         DO 30 IAA=1,NUMAAT
            IF (PRPVAL(IAA).GT.-900.0) THEN
               NUM=NUM+1
               SUM2=SUM2+PRPVAL(IAA)**2
            END IF
 30      CONTINUE
         SUM2=SQRT(SUM2/NUM)
         BIGROW(ISEQ)=SUM2
         print*,'Structure and RMS-Z=',ISEQ,SUM2
         CALL GHS022 (0,SUM2,IERR)
 100  CONTINUE
      CALL GHS023 (0,0,AVE,SDEV,IERR)
      CALL GVSTTR2 ('Aver and sigma from 023:',AVE,SDEV)
      CALL GHS027 (0,0,IERR)
      CALL GHS028 ('RMS-Z Tau',0,0,IERR)
      PRINT*,(BIGROW(ISEQ),ISEQ=ISEQ1,ISEQ2)
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('SC5012')



  998 CONTINUE
      CALL WIFPOPPPP (826)


      RETURN
      END   
      SUBROUTINE BND003



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'RESULT.INC'
      INCLUDE       'SYMINC.INC'
      INTEGER       IAA, IAT, JAT, NUM, IRT, ICON, I, K, L, J, IERR,
     +              NCOV, ICYS, NNUM(MAXMODEL), ACTIVE, IMOD, NUMMDL
      REAL          SCORE, WD, SUM2, V(3), SUM, SUMA, GVFLNV, IDEAL,
     +              R(3), T(3), D(3,6), COV(6,6), PRIOR(6,6), W, BWIDTH,
     +              RES(6), VEC(6), GUESS(6), RMSD, VCV, NSUM2(MAXMODEL)
      LOGICAL       AREBOUND, HASPROTEIN, WIFIRA
      CHARACTER*4   T4, CHAR4, CHAR4I, CHAR4J










      CALL CDB013 ('BDISTNOK','BDISTNEU','BDISTOK')



      CALL GVSRTC (PRPVAL,-1000.0,MAXAA)




      NUM=0
      SUMA=0.0
      SUM2=0.0
      SUM=0.0
      NCOV=0
      RMSD=0.0
      CALL GVSRT0 (NSUM2,MAXMODEL)
      CALL GVSIT0 (NNUM,MAXMODEL)



      CALL GVSRT0 (PRIOR,36)



      CALL GVSCPR (COV,PRIOR,36)



      CALL GVSRT0 (VEC,6)



      CALL GVSRT0 (GUESS,6)
      GUESS(1)=1.0
      GUESS(2)=1.0
      GUESS(3)=1.0



      DO 200 IAA=1,NUMAAF
         IRT=RESTYP(IAA)
         IF (IRT.LT.1) GOTO 200
         DO 90 ICON=1,MAXTAT
            IF (MUTCON(1,ICON,IRT).EQ.0) GOTO 91
            IF (DSTSIG(ICON,IRT).LE.0.0001) GOTO 90
            IAT=PNTAAS(IAA)+MUTCON(1,ICON,IRT)-1
            JAT=PNTAAS(IAA)+MUTCON(2,ICON,IRT)-1
            IF (.NOT.ISATOK(IAT)) GOTO 90
            IF (.NOT.ISATOK(JAT)) GOTO 90
            V(1)=XCOORD(IAT)-XCOORD(JAT)
            V(2)=YCOORD(IAT)-YCOORD(JAT)
            V(3)=ZCOORD(IAT)-ZCOORD(JAT)
            WD=SQRT(V(1)**2+V(2)**2+V(3)**2)
            IDEAL=DSTCON(ICON,IRT)
            BWIDTH=DSTSIG(ICON,IRT)



            IF (IRT.EQ.3.AND.BOUND_TO(1,PNTAAS(IAA)+7).GT.0) THEN
               IF (PINIAA(IAT).EQ.8.OR.PINIAA(JAT).EQ.8) THEN
                  IDEAL=1.36
                  BWIDTH=0.03
               END IF
            ELSE IF (IRT.EQ.4.AND.BOUND_TO(1,PNTAAS(IAA)+8).GT.0) THEN
               IF (PINIAA(IAT).EQ.9.OR.PINIAA(JAT).EQ.9) THEN
                  IDEAL=1.36
                  BWIDTH=0.03
               END IF
            END IF
            SCORE=(WD-IDEAL)/BWIDTH
            CALL PDBS50 (IAT,JAT,0,0,ABS(SCORE),4.0,4.0)
            IF (ABS(SCORE).GE.0.0.AND.ABS(SCORE).LE.10.0) THEN
               RMSD=RMSD+(WD-DSTCON(ICON,IRT))**2
               SUM2=SUM2+SCORE**2
               SUMA=SUMA+ABS(SCORE)
               SUM=SUM+SCORE
               NUM=NUM+1
               IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
                  NNUM(MODNMB(IAA))=NNUM(MODNMB(IAA))+1
                  NSUM2(MODNMB(IAA))=NSUM2(MODNMB(IAA))+SCORE**2
               END IF
            END IF



            PRPVAL(IAA)=MAX(PRPVAL(IAA),ABS(SCORE))
            IF (ABS(SCORE).GT.4.0) THEN
               CALL PDBC92A (IAA,0)
               CHAR4I=T4(ONESAT(IAT))
               CHAR4J=T4(ONESAT(JAT))
               IF (WIFPAR(279).NE.0) THEN
                  WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:23),CHAR4I,
     +             CHAR4J,WD,SCORE
                  CALL PDBC93 (LINE2)
               ELSE
                  IF (WIFPAR(1012).GE.1) THEN
                     WRITE (6,*,ERR=999) LINE92(1:23),CHAR4I,CHAR4J,
     +                WD,SCORE
                  END IF
               END IF
            ELSE



               R(1)=V(1)/DSTCON(ICON,IRT)
               R(2)=V(2)/DSTCON(ICON,IRT)
               R(3)=V(3)/DSTCON(ICON,IRT)
               CALL GVSCPR (T,R,3)
               CALL GVSNM3 (T)
               CALL GVSRT0 (D,18)
               D(1,1)=T(1)
               D(2,2)=T(2)
               D(3,3)=T(3)
               D(2,4)=T(3)
               D(3,4)=T(2)
               D(1,5)=T(3)
               D(3,5)=T(1)
               D(1,6)=T(2)
               D(2,6)=T(1)



               W=(DSTCON(ICON,IRT)/DSTSIG(ICON,IRT))**2



               DO 50 K=1,6
                  DO 60 L=1,6
                     DO 70 I=1,3
                        DO 75 J=1,3
                           COV(K,L)=COV(K,L)+D(I,L)*T(I)*W*T(J)*D(J,K)
   75                   CONTINUE
   70                CONTINUE
   60             CONTINUE
   50          CONTINUE



               DO 80 K=1,6
                  DO 85 I=1,3
                     VEC(K)=VEC(K)+D(I,K)*W*(T(I)-R(I))
   85             CONTINUE
   80          CONTINUE
               NCOV=NCOV+1
            END IF
   90    CONTINUE
   91    CONTINUE



         IF (WIFIRA(IAA).AND.IAA.GT.1) THEN
            IF (AREBOUND(PNTAAS(IAA-1)+2,PNTAAS(IAA))) THEN
               IAT=PNTAAS(IAA-1)+2
               JAT=PNTAAS(IAA)
               IF (.NOT.ISATOK(IAT)) GOTO 200
               IF (.NOT.ISATOK(JAT)) GOTO 200
               V(1)=XCOORD(PNTAAC(IAA))-XCOORD(PNTAAC(IAA-1))
               V(2)=YCOORD(PNTAAC(IAA))-YCOORD(PNTAAC(IAA-1))
               V(3)=ZCOORD(PNTAAC(IAA))-ZCOORD(PNTAAC(IAA-1))



               IF (GVFLNV(V).LT.1.0) GOTO 200
               V(1)=XCOORD(IAT)-XCOORD(JAT)
               V(2)=YCOORD(IAT)-YCOORD(JAT)
               V(3)=ZCOORD(IAT)-ZCOORD(JAT)
               WD=SQRT(V(1)**2+V(2)**2+V(3)**2)
               SCORE=(WD-1.329)/0.02
               CALL PDBS50 (IAT,JAT,0,0,ABS(SCORE),4.0,4.0)
               IF (ABS(SCORE).GE.0.0.AND.ABS(SCORE).LE.10.0) THEN
                  RMSD=RMSD+(WD-1.329)**2
                  SUM2=SUM2+SCORE**2
                  SUMA=SUMA+ABS(SCORE)
                  SUM=SUM+SCORE
                  NUM=NUM+1
                  IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
                     NNUM(MODNMB(IAA))=NNUM(MODNMB(IAA))+1
                     NSUM2(MODNMB(IAA))=NSUM2(MODNMB(IAA))+SCORE**2
                  END IF
               END IF



               PRPVAL(IAA)=MAX(PRPVAL(IAA),ABS(SCORE))
               IF (ABS(SCORE).GT.4.0) THEN
                  IF (WIFPAR(279).NE.0) THEN
                     CALL PDBC92A (IAA,0)
                     WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:23),
     +                ' N  ','-C  ',WD,SCORE
                     CALL PDBC93 (LINE2)
                  ELSE
                     IF (WIFPAR(1012).GE.1) THEN
                        WRITE (6,*,ERR=999) LINE92(1:23),' N  ','-C  ',
     +                   WD,SCORE
                     END IF
                  END IF
               END IF
            END IF
         END IF
 200  CONTINUE



      DO 300 ICYS=1,NUMCYS
         IAT=PNTAAS(CYSCYS(1,ICYS))+5
         JAT=PNTAAS(CYSCYS(2,ICYS))+5
         IF (.NOT.ISATOK(IAT)) GOTO 300
         IF (.NOT.ISATOK(JAT)) GOTO 300
         V(1)=XCOORD(IAT)-XCOORD(JAT)
         V(2)=YCOORD(IAT)-YCOORD(JAT)
         V(3)=ZCOORD(IAT)-ZCOORD(JAT)
         WD=SQRT(V(1)**2+V(2)**2+V(3)**2)
         SCORE=(WD-2.04)/0.04
         CALL PDBS50 (IAT,JAT,0,0,ABS(SCORE),4.0,4.0)
         IF (ABS(SCORE).GE.0.0.AND.ABS(SCORE).LE.10.0) THEN
            RMSD=RMSD+(WD-2.04)**2
            SUM2=SUM2+SCORE**2
            SUMA=SUMA+ABS(SCORE)
            SUM=SUM+SCORE
            NUM=NUM+1
            IAA=ATIAA(IAT)
            IF (MODNMB(IAA).GT.0.AND.MODNMB(IAA).LE.MAXMODEL) THEN
               NNUM(MODNMB(IAA))=NNUM(MODNMB(IAA))+1
               NSUM2(MODNMB(IAA))=NSUM2(MODNMB(IAA))+SCORE**2
            END IF
         END IF



         PRPVAL(IAA)=MAX(PRPVAL(IAA),ABS(SCORE))
         IF (ABS(SCORE).GT.4.0) THEN
            IF (WIFPAR(279).NE.0) THEN
               CALL PDBC92A (IAA,0)
               CHAR4=T4(ONESAT(IAT))
               WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:23),CHAR4,'-SG*',
     +          WD,SCORE
               CALL PDBC93 (LINE2)
            ELSE
               IF (WIFPAR(1012).GE.1) THEN
                  WRITE (6,*,ERR=999) LINE92(1:23),CHAR4,'-SG*',WD,SCORE
               END IF
            END IF
         END IF
  300 CONTINUE



      CALL CDB012



      GENRVL(8)=0.0
      FIXLST(3)=0.0
      GENRVL(21)=0.0
      IF (NUM.GT.0) THEN
         GENRVL(8)=SQRT(SUM2/NUM)
         FIXLST(3)=GENRVL(8)
         GENRVL(21)=SQRT(RMSD/NUM)



         IF (GENRVL(8).LT.0.6665.AND.WIFPAR(1503).LE.0.AND.
     +        WIFPAR(941).LT.200) THEN
            CALL PDBMES ('BDISZLO')
         ELSE IF (GENRVL(8).GT.1.5) THEN
            CALL PDBMES ('BDISZHI')
         ELSE
            CALL PDBMES ('BDISZOK')
         END IF
      END IF



      ACTIVE=0
      DO 400 IMOD=1,NUMMDL()
         IF (NNUM(IMOD).GT.0) THEN
            ACTIVE=ACTIVE+1
            NMRVAL(1,IMOD)=SQRT(NSUM2(IMOD)/NNUM(IMOD))
         ELSE
            NMRVAL(1,IMOD)=-999.9
         END IF
  400 CONTINUE
      VALACT=1
      IF (ACTIVE.GT.1) CALL PDBMES ('BNDNMR')



      IF (NCOV.GT.3.AND.HASPROTEIN().AND.WIFPAR(1102).EQ.0) THEN
         CALL GVSMIV (COV,6,IERR)
         IF (IERR.NE.0) GOTO 998



         CALL GVSCPR (RES,GUESS,6)
         DO 310 K=1,6
            DO 290 L=1,6
               RES(L)=RES(L)+COV(K,L)*VEC(K)
  290       CONTINUE
  310    CONTINUE



         GENRVL(9)=RES(1)
         GENRVL(10)=RES(2)
         GENRVL(11)=RES(3)
         GENRVL(12)=RES(4)
         GENRVL(13)=RES(5)
         GENRVL(14)=RES(6)
         VCV=0.0
         DO 340 K=1,6
            VCV=VCV+(RES(K)-GUESS(K))*VEC(K)
  340    CONTINUE
         GENRVL(27)=VCV



         IF (VCV.GT.27.8) THEN
            IF (SYMHAS) THEN
               CALL PDBMES ('CELSCALNK')
               FIXLST(5)=1.0
            ELSE IF (WIFPAR(1503).GT.0) THEN
               CALL PDBMES ('NMRDISDIR')
            ELSE
               CALL PDBMES ('BADXDISDI')
               FIXLST(5)=1.0
            END IF
         ELSE
            CALL PDBMES ('CELSCALOK')
            FIXLST(5)=0.0
         END IF
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('BND003')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE BND003A (IAA,Z)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, JAT, NUM, IRT, ICON
      REAL          SUM, IDEAL, BWIDTH, Z, WIFDST







      NUM=0
      SUM=0.0
      IRT=RESTYP(IAA)
      Z=9.999
      IF (IRT.LT.1) GOTO 998



      DO 10 ICON=1,MAXTAT
         IF (MUTCON(1,ICON,IRT).EQ.0) GOTO 11
         IF (DSTSIG(ICON,IRT).LE.0.0001) GOTO 10
         IAT=PNTAAS(IAA)+MUTCON(1,ICON,IRT)-1
         JAT=PNTAAS(IAA)+MUTCON(2,ICON,IRT)-1
         IF (.NOT.ISATOK(IAT)) GOTO 10
         IF (.NOT.ISATOK(JAT)) GOTO 10
         IDEAL=DSTCON(ICON,IRT)
         BWIDTH=DSTSIG(ICON,IRT)



         IF (IRT.EQ.3.AND.BOUND_TO(1,PNTAAS(IAA)+7).GT.0) THEN
            IF (PINIAA(IAT).EQ.8.OR.PINIAA(JAT).EQ.8) THEN
               IDEAL=1.36
               BWIDTH=0.03
            END IF
         ELSE IF (IRT.EQ.4.AND.BOUND_TO(1,PNTAAS(IAA)+8).GT.0) THEN
            IF (PINIAA(IAT).EQ.9.OR.PINIAA(JAT).EQ.9) THEN
               IDEAL=1.36
               BWIDTH=0.03
            END IF
         END IF
         SUM=SUM+(WIFDST(IAT,JAT)-IDEAL)/BWIDTH
         NUM=NUM+1
 10   CONTINUE
 11   CONTINUE
      IF (NUM.LE.0) GOTO 998
      Z=SUM/FLOAT(NUM)



  998 CONTINUE


      RETURN
      END
