



      SUBROUTINE SC3001

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       CHKTODO
      EXTERNAL      PDBC53







      CALL TEXSECT ('?R00274')



      IF (CHKTODO('CRD')) THEN



         CALL SC3002



         CALL SC3003



         CALL SC3004
      END IF



      CALL SC3005



      CALL SC1013



      CALL SC3006



      CALL SC3007



      CALL SC3008
      CALL SC3009



      IF (WIFPAR(1102).EQ.0) THEN
         IF (CHKTODO('WGT')) THEN 
            CALL SC3010
            CALL SC3011
         END IF
      END IF



      IF (WIFPAR(1102).EQ.0) THEN
         IF (CHKTODO('XBF').AND.WIFPAR(1503).LE.0) CALL SC3012
         IF (CHKTODO('BFP').AND.WIFPAR(1503).LE.0) CALL PDBC51 (PDBC53)
      END IF





      RETURN
      END   
      SUBROUTINE SC3002



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAT, ICNT, GVFLEN
      CHARACTER*80  LOCLIN







      CALL CDB013 ('CRDERR',' ','CRDOK')



      CALL GVSCTB (LOCLIN,80)
      ICNT=0



      DO 100 IAT=1,NUMATF
         IF (.NOT.ISATOK(IAT)) GOTO 100
         IF (MOD(ABS(XCOORD(IAT)+0.00025),0.1).LT.0.0005.AND.
     +        MOD(ABS(YCOORD(IAT)+0.00025),0.1).LT.0.0005.AND.
     +        MOD(ABS(ZCOORD(IAT)+0.00025),0.1).LT.0.0005) THEN
            IF ((ABS(XCOORD(IAT)).LT.0.0005).AND.
     +           (ABS(YCOORD(IAT)).LT.0.0005).AND.
     +           (ABS(ZCOORD(IAT)).LT.0.0005)) GOTO 100
            CALL PDBC92A (0,IAT)
            WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +           XCOORD(IAT),YCOORD(IAT),ZCOORD(IAT)
            ICNT=ICNT+1
            IF (ICNT.EQ.2) CALL PDBC93 (LOCLIN)
            IF (ICNT.EQ.1) THEN
               CALL GVSSTX (LOCLIN,LINE2)
            ELSE
               CALL PDBC93 (LINE2)
            END IF
         END IF
  100 CONTINUE



      CALL CDB012
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('SC3002')



 998  CONTINUE


      RETURN
      END
      SUBROUTINE SC3003



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'CHIANG.INC'
      INTEGER       IAA, ICNT
      CHARACTER*4   CHAR4
      CHARACTER*80  LOCLIN
      LOGICAL       HASPROTEIN, WIFROK, WIFIRA
      REAL          GVFRTD, V







      IF (.NOT.HASPROTEIN()) GOTO 998



      CALL CDB013 ('CHI0ERR',' ','CHI0OK')



      CALL CHI004



      ICNT=0
      CALL GVSCTB (LOCLIN,80)



      DO 100 IAA=1,NUMAAF
         CALL GVSSTX (CHAR4,ONESA3(IAA))
         CALL GVSSHL (CHAR4)
         IF (.NOT.WIFROK(IAA)) GOTO 100
         IF (.NOT.WIFIRA(IAA)) GOTO 100
         IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.1.OR.
     +       RESTYP(IAA).EQ.6.OR.CHAR4.EQ.'HYP '.OR.
     +       CHAR4.EQ.'AIB ') GOTO 100
         V=ABS(GVFRTD(CHIANG(4,IAA)))
         IF (V.GT.90.0) V=180.0-V
         IF (V.LT.0.01) THEN
            CALL PDBC92A (IAA,0)
            ICNT=ICNT+1
            IF (ICNT.EQ.2) CALL PDBC93 (LOCLIN)
            IF (ICNT.EQ.1) THEN
               CALL GVSSTX (LOCLIN,LINE92)
            ELSE
               CALL PDBC93 (LINE92)
            END IF
         END IF
  100 CONTINUE



      CALL CDB012



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC3004



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'





      IF (WIFPAR(144).GT.0) THEN
         CALL PDBMES ('WROATOM')
         PRINT*,'144=',WIFPAR(144)
         PRINT*,'926=',WIFPAR(926)
         CALL GVSCODA ('WROATOM')
      END IF
      IF (WIFPAR(927).GT.0) THEN
         CALL PDBMES ('DUPATOM')
      END IF
      IF (WIFPAR(1030).GT.0) THEN
         CALL PDBMES ('MISWBF')
      END IF





      RETURN
      END
      SUBROUTINE SC3005

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, NUM, JATARR(4), METAL, ISYM, ILOOP, ICNT
      LOGICAL       HASPROTON, T54EQUAL, CH4EQCH4, WIFIRNO, WIFIR3







      IF (NUMAAT.LT.1) THEN
         CALL GVSTT6 ('?SOUEMT')
         GOTO 998
      END IF



      CALL GVSRT0 (ATTVAL,NUMATF)



      CALL ENVTOT



      IF (WIFPAR(84).NE.0.AND.HASPROTON()) THEN
         CALL CDB013 ('MISATOM','NEUATOM','NOMISATMH')
      ELSE
         CALL CDB013 ('MISATOM','NEUATOM','NOMISATOM')
      END IF
      CALL CDB014 (1,'MISSING','POOR')



      DO 20 IAA=1,NUMAAF
         IF (WIFIRNO(IAA).AND.WIFIR3(IAA)) GOTO 20
         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT)) THEN
               IF (CHAINN(1,IAA).NE.2.AND.
     +            (T54EQUAL(ONESAT(IAT),' P  ').OR.
     +             T54EQUAL(ONESAT(IAT),' OP1').OR.
     +             T54EQUAL(ONESAT(IAT),' OP2').OR.
     +             T54EQUAL(ONESAT(IAT),' O3*').OR.
     +             T54EQUAL(ONESAT(IAT),' O5*'))) THEN



                  CONTINUE
               ELSE IF (CH4EQCH4(ONESA3(IAA),'UNK ')) THEN



                  CONTINUE
               ELSE IF (PROTON(IAT)) THEN



                  IF (.NOT.HASPROTON()) GOTO 10



                  IF (RESTYP(IAA).EQ.2.AND.PINIAA(IAT).EQ.11) THEN





                     CALL FBONDA (PNTAAS(IAA)+5,JATARR,4,NUM)
                     IF (NUM.NE.2) THEN
                        CALL PDBC04C (PNTAAS(IAA)+5,METAL,ISYM)
                        IF (METAL.EQ.0) THEN
                           CALL PDBC92 (IAA,IAT)
                        END IF
                     END IF
                  ELSE IF (RESTYP(IAA).EQ.7.AND.PINIAA(IAT).EQ.15) THEN




                     IF (.NOT.ISATOK(IAT+3)) THEN
                        CALL PDBC04C (PNTAAS(IAA)+6,METAL,ISYM)
                        IF (METAL.EQ.0) THEN
                           CALL PDBC92 (IAA,IAT)
                           ATTVAL(IAT)=1.0
                        END IF
                     END IF
                  ELSE IF (RESTYP(IAA).EQ.7.AND.PINIAA(IAT).EQ.18) THEN




                     IF (.NOT.ISATOK(IAT-3)) THEN
                        CALL PDBC04C (PNTAAS(IAA)+9,METAL,ISYM)
                        IF (METAL.EQ.0) THEN
                           CALL PDBC92 (IAA,IAT)
                           ATTVAL(IAT)=1.0
                        END IF
                     END IF
                  ELSE IF (RESTYP(IAA).EQ.9.AND.PINIAA(IAT).EQ.22) THEN



                     IF ((.NOT.ISATOK(IAT-1)).OR.
     +                   (.NOT.ISATOK(IAT-2))) CALL PDBC92 (IAA,IAT)
                  ELSE IF (RESTYP(IAA).EQ.15.AND.PINIAA(IAT).GE.20) THEN



                     ICNT=0
                     DO 5 ILOOP=PNTAAS(IAA)+19,PNTAAS(IAA)+23
                        IF (ISATOK(ILOOP)) ICNT=ICNT+1
    5                CONTINUE
                     IF (ICNT.LT.4) THEN
                        CALL PDBC92 (IAA,IAT)
                     END IF
                  ELSE



                     CALL PDBC92 (IAA,IAT)
                     ATTVAL(IAT)=1.0
                  END IF
               ELSE



                  CALL PDBC92 (IAA,IAT)
                  ATTVAL(IAT)=1.0
               END IF
            END IF
   10    CONTINUE
   20 CONTINUE



      CALL CDB012


  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC3005A

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, NUM, JATARR(4), METAL, ISYM, ILOOP, ICNT
      LOGICAL       HASPROTON, T54EQUAL, CH4EQCH4, WIFIRNO, WIFIR3







      IF (NUMAAT.LT.1) THEN
         CALL GVSTT6 ('?SOUEMT')
         GOTO 998
      END IF



      CALL GVSRT0 (ATTVAL,NUMATF)



      CALL ENVTOT



      IF (WIFPAR(84).NE.0.AND.HASPROTON()) THEN
         CALL CDB013 ('MISATOM','NEUATOM','NOMISATMH')
      ELSE
         CALL CDB013 ('MISATOM','NEUATOM','NOMISATOM')
      END IF
      CALL CDB014 (1,'MISSING','POOR')



      DO 20 IAA=1,NUMAAF
         IF (WIFIRNO(IAA).AND.WIFIR3(IAA)) GOTO 20
         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT)) THEN
               IF (CHAINN(1,IAA).NE.2.AND.
     +            (T54EQUAL(ONESAT(IAT),' P  ').OR.
     +             T54EQUAL(ONESAT(IAT),' OP1').OR.
     +             T54EQUAL(ONESAT(IAT),' OP2').OR.
     +             T54EQUAL(ONESAT(IAT),' O3*').OR.
     +             T54EQUAL(ONESAT(IAT),' O5*'))) THEN



                  CONTINUE
               ELSE IF (CH4EQCH4(ONESA3(IAA),'UNK ')) THEN



                  CONTINUE
               ELSE IF (PROTON(IAT)) THEN



                  IF (.NOT.HASPROTON()) GOTO 10



                  IF (RESTYP(IAA).EQ.2.AND.PINIAA(IAT).EQ.11) THEN





                     CALL FBONDA (PNTAAS(IAA)+5,JATARR,4,NUM)
                     IF (NUM.NE.2) THEN
                        CALL PDBC04C (PNTAAS(IAA)+5,METAL,ISYM)
                        IF (METAL.EQ.0) THEN
                           CALL PDBC92 (IAA,IAT)
                        END IF
                     END IF
                  ELSE IF (RESTYP(IAA).EQ.7.AND.PINIAA(IAT).EQ.15) THEN




                     IF (.NOT.ISATOK(IAT+3)) THEN
                        CALL PDBC04C (PNTAAS(IAA)+6,METAL,ISYM)
                        IF (METAL.EQ.0) THEN
                           CALL PDBC92 (IAA,IAT)
                           ATTVAL(IAT)=1.0
                        END IF
                     END IF
                  ELSE IF (RESTYP(IAA).EQ.7.AND.PINIAA(IAT).EQ.18) THEN




                     IF (.NOT.ISATOK(IAT-3)) THEN
                        CALL PDBC04C (PNTAAS(IAA)+9,METAL,ISYM)
                        IF (METAL.EQ.0) THEN
                           CALL PDBC92 (IAA,IAT)
                           ATTVAL(IAT)=1.0
                        END IF
                     END IF
                  ELSE IF (RESTYP(IAA).EQ.9.AND.PINIAA(IAT).EQ.22) THEN



                     IF ((.NOT.ISATOK(IAT-1)).OR.
     +                   (.NOT.ISATOK(IAT-2))) CALL PDBC92 (IAA,IAT)
                  ELSE IF (RESTYP(IAA).EQ.15.AND.PINIAA(IAT).GE.20) THEN



                     ICNT=0
                     DO 5 ILOOP=PNTAAS(IAA)+19,PNTAAS(IAA)+23
                        IF (ISATOK(ILOOP)) ICNT=ICNT+1
    5                CONTINUE
                     IF (ICNT.LT.4) THEN
                        CALL PDBC92 (IAA,IAT)
                     END IF
                  ELSE



                     CALL PDBC92 (IAA,IAT)
                     ATTVAL(IAT)=1.0
                  END IF
               ELSE



                  CALL PDBC92 (IAA,IAT)
                  ATTVAL(IAT)=1.0
               END IF
            END IF
   10    CONTINUE
   20 CONTINUE



      CALL CDB012



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC3006



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, IAT, JAT, JAA
      LOGICAL       HASPROTEIN, WIFIR3, WIFIRO, WIFOXO, HASBOUND,
     +              WIFOXE, WIFOXN, WIFIRA, WIFIRX
      CHARACTER*2   REASN
      CHARACTER*28  IATS, JATS







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



      CALL CDB013 ('CAPO2','CAPO2NEU','NOCAPO2')
      CALL CDB014 (1,'NO-OXT','OK')
      CALL CDB014 (2,'HAS-OXT','BAD')
      CALL CDB014 (3,'HAS-ENT','POOR')
      CALL CDB014 (4,'HAS-N','POOR')



      DO 10 IAA=1,NUMAAF
         IF (WIFIR3(IAA).AND.WIFIRA(IAA)) THEN
            IF (WIFIRO(IAA).OR.WIFIRX(IAA).OR.PRPVAL(IAA).GT.0.5)GOTO 10
            IAT=PNTAAS(IAA)+2
            IF (HASBOUND(IAT,JAT)) THEN
               JAA=0
               IF (JAT.NE.0) JAA=ATIAA(JAT)



               IF (WIFOXO(IAA)) THEN
                  PRPVAL(IAA)=2
                  REASN='OX'
                  CALL DIF008 ('?NEWZ114',IAA)
               ELSE IF (WIFOXE(IAA)) THEN
                  PRPVAL(IAA)=3
                  REASN='OT'
                  CALL DIF008 ('?NEWZ115',IAA)
               ELSE IF (WIFOXN(IAA)) THEN
                  PRPVAL(IAA)=4
                  REASN='ON'
                  CALL DIF008 ('?NEWZ115A',IAA)
               END IF
               IF (PRPVAL(IAA).NE.0) THEN
                  IF (JAT.LE.0.OR.JAA.LE.0) THEN
                     CALL GVSCOD ('?M4639')
                  ELSE
                     CALL PDBC92A (IAA,IAT)
                     CALL GVSSTX (IATS,LINE92(1:28))
                     CALL PDBC92A (JAA,JAT)
                     CALL GVSSTX (JATS,LINE92(1:28))
                     WRITE (LINE92,PDBFMT,ERR=999) IATS,JATS,REASN
                     CALL PDBC93 (LINE92)
                  END IF
               END IF
            END IF
         END IF
 10   CONTINUE



      CALL CDB012



      CALL CDB013 ('HASNO2','HASO2NEU','HASO2')
      CALL CDB014 (1,'NO-OXT','POOR')
      DO 20 IAA=1,NUMAAF
         IF (PRPVAL(IAA).GT.0.5) THEN
            PRPVAL(IAA)=0
            GOTO 20
         END IF
         IF (WIFIRA(IAA).AND.WIFIRX(IAA)) THEN
            IF (WIFIRO(IAA)) GOTO 20
            IAT=PNTAAS(IAA)+2
            IF (HASBOUND(IAT,JAT)) GOTO 20
            PRPVAL(IAA)=1
            CALL PDBC92A (IAA,0)
            CALL PDBC93 (LINE92)
         END IF
 20   CONTINUE



      CALL CDB012



      CALL GVSRT0 (PRPVAL,NUMAAF)
      CALL CDB013 ('EXTO2','EXTO2NEU','EXTO2OK')
      CALL CDB014 (1,'EXT-OXT','BAD')
      DO 30 IAA=1,NUMAAF
         IF (.NOT.WIFIR3(IAA).AND.WIFIRA(IAA)) THEN
            IF (WIFIRO(IAA)) GOTO 30
            IF (.NOT.HASBOUND(PNTAAS(IAA)+2,JAT)) GOTO 30
            IF (JAT.LE.0) GOTO 30
            JAA=ATIAA(JAT)
            IF (.NOT.WIFIRO(JAA)) GOTO 30



            PRPVAL(IAA)=1
            CALL PDBC92A (IAA,0)
            CALL PDBC93 (LINE92)
            FIXRES(IAA)=FIXRES(IAA)+2.5
         END IF
 30   CONTINUE



      CALL CDB012
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('SC3006')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC3007



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ISOUP, IAA, IAT, JAT, LUN, NLUN, ILUN, IERR, IBND,
     +              IMIS
      LOGICAL       GVFIBN, WIFISA, HASPROTEIN, WIFIR1, HASPROTON







      IF (.NOT.HASPROTON()) GOTO 998
      IF (.NOT.HASPROTEIN()) THEN
         CALL PDBMES ('R00242')
         GOTO 998
      END IF
      CALL GVSRT0 (ATTVAL,NUMATF)



      CALL CDB013 ('MISHT','TESTHT','NOMISHT')
      CALL CDB014 (1,'NO-HT','POOR')
      CALL CDB014 (2,'HAS-HT','POOR')



      CALL GVSROF (LUN,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSOPF ('HTCHK.DAT',LUN,'UNKNOWN')
      NLUN=0



      DO 100 ISOUP=1,NUMSOU
         IF (WIFISA(ISOUP)) THEN
            IAA=SOUADM(1,ISOUP)
            IAT=PNTAAS(IAA)



            IF (.NOT.WIFIR1(IAA)) GOTO 100




            IF (IAA.GT.1) THEN
               IF (CHANAM(IAA).EQ.CHANAM(IAA-1).AND.
     +              MODNMB(IAA).EQ.MODNMB(IAA-1)) THEN
                  IF (BOUND_TO(1,IAT).GT.0.OR.BOUND_TO(2,IAT).GT.0.OR.
     +                BOUND_TO(3,IAT).GT.0.OR.BOUND_TO(4,IAT).GT.0.OR.
     +                BOUND_TO(5,IAT).GT.0.OR.BOUND_TO(6,IAT).GT.0.OR.
     +                BOUND_TO(7,IAT).GT.0.OR.BOUND_TO(8,IAT).GT.0) THEN



                     ATTVAL(IAT)=2.0
                     CALL DIF008 ('?R00243',IAA)



                     CALL GVSFMT ('?FMT022')
                     WRITE (LUN,FMT,ERR=997) IAT
                     NLUN=NLUN+1
                  END IF
                  GOTO 100
               END IF
            END IF



            IMIS=0
            DO 200 IBND=1,8
               JAT=BOUND_TO(IBND,IAT)



               IF (.NOT.GVFIBN(JAT,1,NUMATF)) IMIS=IMIS+1
  200       CONTINUE



            IF (IMIS.EQ.2) THEN
               ATTVAL(IAT)=1.0
               CALL PDBC92 (IAA,IAT)
            END IF
         END IF
  100 CONTINUE



      CALL CDB012



      CALL CDB013 ('HASHT',' ','HASHTOK')
      IF (NLUN.GT.0) THEN
         CALL GVSREW (LUN)
         CALL GVSFMT ('?FMT022')
         DO 210 ILUN=1,NLUN
            READ (LUN,FMT,ERR=999,END=999) IAT
            CALL PDBC92 (0,IAT)
  210    CONTINUE
      END IF



      CALL CDB012
      CALL GVSCLF (LUN)
      CALL GVSDEL ('HTCHK.DAT')
      GOTO 998



  997 CONTINUE
      CALL GVSEIW ('SC3007')
      GOTO 998



  999 CONTINUE
      CALL GVSCLF (LUN)
      CALL GVSDEL ('HTCHK.DAT')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC3008



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'RESULT.INC'
      LOGICAL       HASPROTON, WIFIR1, WIFIRA, HASPROTEIN
      INTEGER       LOWPH, HIGHPH, IAA, IAT1, IAT2







      IF (.NOT.HASPROTON()) GOTO 998
      IF (.NOT.HASPROTEIN()) GOTO 998



      LOWPH=0
      HIGHPH=0



      DO 100 IAA=1,NUMAAF
         IF (WIFIR1(IAA).AND.WIFIRA(IAA)) THEN
            IAT1=BOUND_TO(1,PNTAAS(IAA))
            IAT2=BOUND_TO(2,PNTAAS(IAA))
            IF (IAT1.NE.0.AND.IAT2.EQ.0) HIGHPH=HIGHPH+1
         END IF
         IF (RESTYP(IAA).EQ.9) THEN
            IAT1=PNTAAS(IAA)+21
            IAT2=PNTAAS(IAA)+20
            IF (.NOT.ISATOK(IAT1).AND.ISATOK(IAT2)) HIGHPH=HIGHPH+1
         ELSE IF (RESTYP(IAA).EQ.3) THEN
            IAT1=BOUND_TO(1,PNTAAS(IAA)+7)
            IF (IAT1.NE.0) THEN
               IF (ISATOK(IAT1).AND.PROTON(IAT1)) LOWPH=LOWPH+1
            END IF
         ELSE IF (RESTYP(IAA).EQ.4) THEN
            IAT1=BOUND_TO(1,PNTAAS(IAA)+8)
            IF (IAT1.NE.0) THEN
               IF (ISATOK(IAT1).AND.PROTON(IAT1)) LOWPH=LOWPH+1
            END IF
         END IF
  100 CONTINUE



      GENIVL(9)=LOWPH
      GENIVL(10)=HIGHPH



      IF (LOWPH.GT.0.AND.HIGHPH.GT.0) THEN
         CALL PDBMES ('LOHIERR')
      ELSE IF (LOWPH.GT.0) THEN
         CALL PDBMES ('LOWPH')
      ELSE IF (HIGHPH.GT.0) THEN
         CALL PDBMES ('HIGHPH')
      ELSE
         CALL PDBMES ('NEUPH')
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC3009

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       IAA, IAT1, IAT2, ICNT
      LOGICAL       HASPROTON, WIFIR1, WIFIRA, HASPROTEIN, FIRST







      IF (.NOT.HASPROTON()) GOTO 998
      IF (.NOT.HASPROTEIN()) GOTO 998



      GENIVL(9)=0
      FIRST=.TRUE.



      DO 100 IAA=1,NUMAAF



         IF (WIFIR1(IAA).AND.WIFIRA(IAA)) THEN
            IF (IAA.NE.1) THEN
               IF (CHANAM(IAA).EQ.CHANAM(IAA-1).AND.
     +             MODNMB(IAA).EQ.MODNMB(IAA-1)) GOTO 10
            END IF
            IAT1=BOUND_TO(1,PNTAAS(IAA))
            IAT2=BOUND_TO(2,PNTAAS(IAA))
            IF (RESTYP(IAA).EQ.13.OR.RESTYP(IAA).EQ.21) THEN
               IF (IAT1.EQ.0) THEN
                  IF (FIRST) THEN
                     FIRST=.FALSE.
                     CALL CDB013 ('FUNPH',' ','FUNPHOK')
                  END IF
                  CALL PDBC92 (IAA,0)
               END IF
            ELSE IF (IAT1.EQ.0.AND.IAT2.EQ.0) THEN
                  IF (FIRST) THEN
                     FIRST=.FALSE.
                     CALL CDB013 ('FUNPH',' ','FUNPHOK')
                  END IF
                  CALL PDBC92 (IAA,0)
               END IF
            END IF
   10    CONTINUE



         IF (RESTYP(IAA).EQ.9) THEN
            ICNT=0
            IF (ISATOK(PNTAAS(IAA)+19)) ICNT=ICNT+1
            IF (ISATOK(PNTAAS(IAA)+20)) ICNT=ICNT+1
            IF (ISATOK(PNTAAS(IAA)+21)) ICNT=ICNT+1
            IF (ICNT.LE.1) THEN
               IF (FIRST) THEN
                  FIRST=.FALSE.
                  CALL CDB013 ('FUNPH',' ','FUNPHOK')
               END IF
               CALL PDBC92 (IAA,0)
            END IF



         ELSE IF (RESTYP(IAA).EQ.12) THEN
            ICNT=0
            IF (ISATOK(PNTAAS(IAA)+12)) ICNT=ICNT+1
            IF (ISATOK(PNTAAS(IAA)+13)) ICNT=ICNT+1
            IF (ICNT.LE.1) THEN
               IF (FIRST) THEN
                  FIRST=.FALSE.
                  CALL CDB013 ('FUNPH',' ','FUNPHOK')
               END IF
               CALL PDBC92 (IAA,0)
            END IF



         ELSE IF (RESTYP(IAA).EQ.14) THEN
            ICNT=0
            IF (ISATOK(PNTAAS(IAA)+15)) ICNT=ICNT+1
            IF (ISATOK(PNTAAS(IAA)+16)) ICNT=ICNT+1
            IF (ICNT.LE.1) THEN
               IF (FIRST) THEN
                  FIRST=.FALSE.
                  CALL CDB013 ('FUNPH',' ','FUNPHOK')
               END IF
               CALL PDBC92 (IAA,0)
            END IF



         ELSE IF (RESTYP(IAA).EQ.15) THEN
            ICNT=0
            IF (ISATOK(PNTAAS(IAA)+19)) ICNT=ICNT+1
            IF (ISATOK(PNTAAS(IAA)+20)) ICNT=ICNT+1
            IF (ISATOK(PNTAAS(IAA)+21)) ICNT=ICNT+1
            IF (ISATOK(PNTAAS(IAA)+22)) ICNT=ICNT+1
            IF (ISATOK(PNTAAS(IAA)+23)) ICNT=ICNT+1
            IF (ICNT.LE.3) THEN
               IF (FIRST) THEN
                  FIRST=.FALSE.
                  CALL CDB013 ('FUNPH',' ','FUNPHOK')
               END IF
               CALL PDBC92 (IAA,0)
            END IF



         ELSE IF (RESTYP(IAA).EQ.16) THEN
            IF (.NOT.ISATOK(PNTAAS(IAA)+10)) THEN
               IF (FIRST) THEN
                  FIRST=.FALSE.
                  CALL CDB013 ('FUNPH',' ','FUNPHOK')
               END IF
               CALL PDBC92 (IAA,0)
            END IF



         ELSE IF (RESTYP(IAA).EQ.17) THEN
            IF (.NOT.ISATOK(PNTAAS(IAA)+10)) THEN
               IF (FIRST) THEN
                  FIRST=.FALSE.
                  CALL CDB013 ('FUNPH',' ','FUNPHOK')
               END IF
               CALL PDBC92 (IAA,0)
            END IF



         ELSE IF (RESTYP(IAA).EQ.20) THEN
            IF (.NOT.ISATOK(PNTAAS(IAA)+20)) THEN
               IF (FIRST) THEN
                  FIRST=.FALSE.
                  CALL CDB013 ('FUNPH',' ','FUNPHOK')
               END IF
               CALL PDBC92 (IAA,0)
            END IF
         END IF
  100 CONTINUE



      CALL CDB012



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC3010

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       ISEQ, IAT, ITAG(MAXAT), GVFLEN
      REAL          BIGVAL(MAXAT)
      EQUIVALENCE   (ITAG,ESPACE(200001))
      EQUIVALENCE   (BIGVAL,ESPACE(200001+MAXAT))







      IF (WIFPAR(1102).NE.0) GOTO 998



      CALL GVSRT0 (ATTVAL,MAXAT)



      CALL ESPSET (200001,200000+2*MAXAT,44)



      CALL CDB013 ('WEIGHTS','WEIGHTNEU','WEIGHTSOK')



      CALL CDB014 (1,'OVER','POOR')
      CALL CDB014 (2,'NEGATIVE','BAD')
      CALL CDB014 (3,'HIGH','BAD')



      DO 10 IAT=1,NUMATF
         BIGVAL(IAT)=ABS(0.5-WEIGHT(IAT))
         ITAG(IAT)=IAT
   10 CONTINUE



      CALL GVSDRT (BIGVAL,NUMATF,ITAG)
      DO 300 ISEQ=1,NUMATF
         IAT=ITAG(ISEQ)
         IF (WEIGHT(IAT).GT.1.0.OR.WEIGHT(IAT).LT.0.0) THEN
            IF (WEIGHT(IAT).GT.1.0) ATTVAL(IAT)=1.0
            IF (WEIGHT(IAT).LT.0.0) THEN
               ATTVAL(IAT)=2.0
               FIXRES(ATIAA(IAT))=FIXRES(ATIAA(IAT))-WEIGHT(IAT)-1.0
            END IF
            IF (WEIGHT(IAT).GT.1.1) THEN
               ATTVAL(IAT)=3.0
               FIXRES(ATIAA(IAT))=FIXRES(ATIAA(IAT))+WEIGHT(IAT)
            END IF
            CALL PDBC92A (0,IAT)
            WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +       WEIGHT(IAT)
            CALL PDBC93 (LINE2)
         ELSE
            GOTO 310
         END IF
  300 CONTINUE
  310 CONTINUE



      CALL CDB012



      CALL ESPKIL (200001,200000+2*MAXAT,44,'SC3010')
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('SC3010')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC3011

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       IC1, IC2, IC3, IAA, IAT, GVFLEN
      REAL          SCO, OCCSUM
      LOGICAL       WIFIRW







      IC1=0
      IC2=0
      IC3=0



      DO 20 IAA=1,NUMAAF
         IF (ISSHIT(IAA)) GOTO 20
         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT)) GOTO 10
            IC1=IC1+1
            IF (WEIGHT(IAT).GT.0.999) THEN
               IC2=IC2+1
            ELSE IF (WEIGHT(IAT).LT.0.500.OR.WEIGHT(IAT).GT.1.0001) THEN
               IC3=IC3+1
            END IF
 10      CONTINUE
 20   CONTINUE



      IF (IC1.LE.0) THEN
         GENRVL(45)=0.0
         GENRVL(46)=0.0
         GOTO 997
      ELSE
         GENRVL(45)=FLOAT(IC2)/FLOAT(IC1)
         GENRVL(46)=FLOAT(IC3)/FLOAT(IC1)
      END IF



      CALL CDB013 ('MA22BAD',' ','MA22OK')



      IF (WIFPAR(919).EQ.0) THEN
         GENRVL(45)=(GENRVL(45)-SIGMAP(9))/SIGMAP(10)
         GENRVL(46)=(GENRVL(46)-SIGMAP(11))/SIGMAP(12)
         SCO=ABS(GENRVL(45))+ABS(GENRVL(46))



         IF (SCO.LT.4.0.AND.ABS(GENRVL(45)).LT.2.0.AND.
     +       ABS(GENRVL(46)).LT.2.0) THEN
            CALL PDBMES ('OCCOK')
         ELSE IF (SCO.GT.7.0.OR.ABS(GENRVL(45)).GT.4.0.OR.
     +       ABS(GENRVL(46)).GT.4.0) THEN
            CALL PDBMES ('OCCBAD')
         ELSE
            CALL PDBMES ('OCCODD')
         END IF
      END IF



      DO 100 IAA=1,NUMAAF
         IF (WIFIRW(IAA)) GOTO 100
         DO 90 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT)) GOTO 90
            OCCSUM=WEIGHT(IAT)
            IF (ALALAT(IAT).NE.' ') OCCSUM=OCCSUM+ALTWGT(IAT)
            IF ((OCCSUM.GT.0.02.AND.OCCSUM.LT.0.98).OR.OCCSUM.GT.1.02) 
     +          THEN
               IF (WIFPAR(279).NE.0) THEN
                  CALL PDBC92A (IAA,0)
                  WRITE (LINE2,PDBFMT,ERR=999) LINE92(1:GVFLEN(LINE92)),
     +             OCCSUM
                  CALL PDBC93 (LINE2)
               ELSE
                  CALL DIF008E (6,'?MA22TXT',IAA,OCCSUM)
               END IF
               GOTO 100
            END IF
 90      CONTINUE
 100  CONTINUE



 997  CONTINUE
      CALL CDB012
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('SC3011')



 998  CONTINUE


      RETURN
      END   
      SUBROUTINE SC3012





















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'RESULT.INC'
      INTEGER       IAA, IAT, JAT, NUM, IRT, ICON, NUML5, NUMBUR, IERR,
     +              LUN
      REAL          M, S, MEAN(20,MAXTAT), SIGMA(20,MAXTAT), SCORE,
     +              DI, WD, SUM, DELTA, DELTA2, AVE, SDEV
      LOGICAL       GVFFOP, GVFRIN, WIFIRA
      CHARACTER*2   CALCTYP
      CHARACTER*80  FILNAM







      IF (WIFPAR(1102).NE.0) GOTO 998



      FIXLST(8)=0.0
      NUMBUR=0
      NUML5=0
      SUM=0.0
      GENRVL(5)=0.0
      GENRVL(6)=0.0



      



      IF (.NOT.TLSFND) THEN
         IF (NUMTLS.LE.0) THEN
            CALL PDBMES ('TLSNOT1')
         ELSE
            CALL PDBMES ('TLSNOT2')
         END IF
      ELSE
         CALL PDBMES ('TLSNOT3')
      END IF




      CALL XBF020



      CALL OTH203 (AVE,SDEV)
      GENRVL(50)=SDEV
      IF (SDEV.GT.-1.0) THEN
         IF (SDEV.LT.0.06) THEN
            CALL PDBMES ('MFVHIGH')
         ELSE IF (SDEV.LT.0.09) THEN
            CALL PDBMES ('MFHIGH')
         END IF
      END IF




      DO 100 IAA=1,NUMAAF
         IF (WIFIRA(IAA)) THEN
            DO 70 IAT=PNTAAS(IAA),PNTAAE(IAA)
               IF (.NOT.ISATOK(IAT).OR.WEIGHT(IAT).EQ.0.0.OR.
     +          XBFACT(IAT).GT.99.5) GOTO 70
               IF (ACCESS(IAT).LE.0.01) THEN
                  NUMBUR=NUMBUR+1
                  IF (XBFACT(IAT).LT.5.0) NUML5=NUML5+1
                  SUM=SUM+XBFACT(IAT)
               END IF
 70         CONTINUE
         END IF
 100  CONTINUE



      IF (NUMBUR.GT.0) THEN
         GENRVL(5)=FLOAT(NUML5)/NUMBUR
         GENRVL(6)=SUM/NUMBUR



      ELSE IF (GVFRIN(GENRVL(6),3.0,10.0).AND.
     +         GVFRIN(PDTEMP,1.1,150.0)) THEN
         CALL PDBMES ('XBFCOK')



      ELSE IF (GVFRIN(GENRVL(6),10.0,30.0).AND.
     +         GVFRIN(PDTEMP,250.0,350.0)) THEN
         CALL PDBMES ('XBFWOK')



      ELSE IF (.NOT.GVFRIN(GENRVL(6),3.0,10.0).AND.
     +              GVFRIN(PDTEMP,1.1,150.0)) THEN
         CALL PDBMES ('XBFRNGE')
         FIXLST(8)=2.0
         GOTO 998



      ELSE IF (.NOT.GVFRIN(GENRVL(6),10.0,30.0).AND.
     +              GVFRIN(PDTEMP,250.0,350.0)) THEN
         CALL PDBMES ('XBFRNGE')
         FIXLST(8)=2.0
         GOTO 998



      ELSE 
         CALL PDBMES ('XBFRNGOK')
         FIXLST(8)=2.0
      END IF



      IF (GENRVL(5).GT.0.05) THEN
         CALL PDBMES ('XBFLT5E')
         GENRVL(7)=0.0
         GOTO 998
      ELSE IF (GENRVL(5).GT.0.02) THEN
         CALL PDBMES ('XBFLT5W')
      ELSE
         CALL PDBMES ('XBFLT5OK')
      END IF



      CALL GVSCCC (FILNAM,WHERIS,'XBFACT.DAT')
      CALL GVSROF (LUN,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSOPF (FILNAM,LUN,'OLD')
      IF (.NOT.GVFFOP(LUN)) GOTO 997
      CALL GVSRT0 (MEAN,20*MAXTAT)
      CALL GVSRT0 (SIGMA,20*MAXTAT)
 10   CONTINUE
         CALL GVSFMT ('?FMT1138')
         READ (LUN,FMT,ERR=999,END=20) IRT,ICON,CALCTYP,M,S
         IF (CALCTYP.EQ.'wd') THEN
            MEAN(IRT,ICON)=M
            SIGMA(IRT,ICON)=S
         END IF
      GOTO 10
 20   CONTINUE
      CALL GVSCLF (LUN)



      NUM=0
      SUM=0.0
      DELTA=0.0
      DELTA2=0.0
      DO 200 IAA=1,NUMAAF
         IRT=RESTYP(IAA)
         IF (IRT.LT.1.OR.IRT.GT.20) GOTO 200
         DO 90 ICON=1,MAXTAT
            IF (MUTCON(1,ICON,IRT).EQ.0) GOTO 200
            IAT=PNTAAS(IAA)+MUTCON(1,ICON,IRT)-1
            JAT=PNTAAS(IAA)+MUTCON(2,ICON,IRT)-1
            IF (.NOT.ISATOK(IAT).OR.WEIGHT(IAT).LT.0.01.OR.
     +       PROTON(IAT).OR.XBFACT(IAT).GT.99.5.OR.XBFACT(IAT).LT.1.0) 
     +       GOTO 90
            IF (.NOT.ISATOK(JAT).OR.WEIGHT(JAT).EQ.0.0.OR.
     +       PROTON(JAT).OR.XBFACT(JAT).GT.99.5.OR.XBFACT(JAT).LT.1.0) 
     +       GOTO 90
            DI=XBFACT(IAT)-XBFACT(JAT)
            WD=SQRT(XBFACT(IAT))-SQRT(XBFACT(JAT))
            SCORE=(WD-MEAN(IRT,ICON))/SIGMA(IRT,ICON)
            DELTA=DELTA+ABS(DI)
            DELTA2=DELTA2+DI*DI
            SUM=SUM+SCORE**2
            NUM=NUM+1
 90      CONTINUE
 200  CONTINUE



      IF (NUM.GT.0) THEN
         STRVAL(1)=SQRT(SUM/NUM)
         GENRVL(7)=SQRT(SUM/NUM)
         GENRVL(26)=DELTA/NUM
         GENRVL(28)=SQRT(DELTA2/NUM)
         GENIVL(5)=NUM
         IF (GENRVL(7).GT.1.5) THEN
            CALL PDBMES ('XBFBONNOK')
         ELSE
            CALL PDBMES ('XBFBONOK')
         END IF
      ELSE
         GENRVL(7)=0.0
         GENIVL(5)=0
      END IF



      GOTO 998



 997  CONTINUE
      CALL GVSTTE ('?R00286')
      GOTO 998
 999  CONTINUE
      CALL GVSTTE ('?R00287')



  998 CONTINUE


      RETURN
      END
