



      SUBROUTINE SC4001

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      LOGICAL       CHKTODO







      CALL TEXSECT ('?CHKM02')



      CALL GVSRT0 (PRPVAL,NUMAAT)
      CALL GVSBTF (WRK3TF,NUMAAT)
      CALL CDB013 ('NOMENBAD',' ','NOMENOK')
      CALL CDB012



      IF (CHKTODO('NAM')) CALL SC4002



      IF (WIFPAR(1102).EQ.0) THEN
         IF (CHKTODO('CHN')) CALL SC4003
      END IF





      RETURN
      END   
      SUBROUTINE SC4002



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, IAT, NIT1, NIT2, GVFNIT, IERR1, IERR2, GVFLEN
      REAL          V1(3), V2(3), V3(3), GVFDV3
      LOGICAL       WIFCOK, WIFIRW, WIFIRN, WIFIC2, OLDHNAM, 
     +              CH5EQCH5, HASPROTEIN







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



      CALL GVSRT0 (PRPVAL,NUMAAT)
      CALL GVSBTF (WRK3TF,NUMAAT)



      CALL CDB013 ('VALNAMES',' ','VALNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 10 IAA=1,NUMAAT



         IF (RESTYP(IAA).EQ.18) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 10
            IF (ORGNAM(PNTAAS(IAA)+5).EQ.ONESAT(PNTAAS(IAA)+6)) THEN
               PRPVAL(IAA)=2.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   10 CONTINUE



      CALL CDB012



      CALL CDB013 ('THRNAMES',' ','THRNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 20 IAA=1,NUMAAT



         IF (RESTYP(IAA).EQ.17) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 20
            IF (ORGNAM(PNTAAS(IAA)+5).EQ.ONESAT(PNTAAS(IAA)+6)) THEN
               PRPVAL(IAA)=2.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   20 CONTINUE



      CALL CDB012



      CALL CDB013 ('ILENAMES',' ','ILENAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 30 IAA=1,NUMAAT



         IF (RESTYP(IAA).EQ.8) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 30



            V1(1)=XCOORD(PNTAAS(IAA)+4)-XCOORD(PNTAAC(IAA))
            V1(2)=YCOORD(PNTAAS(IAA)+4)-YCOORD(PNTAAC(IAA))
            V1(3)=ZCOORD(PNTAAS(IAA)+4)-ZCOORD(PNTAAC(IAA))



            V2(1)=(XCOORD(PNTAAS(IAA)+5)+XCOORD(PNTAAS(IAA)+6))/2.0-
     +       XCOORD(PNTAAS(IAA)+4)
            V2(2)=(YCOORD(PNTAAS(IAA)+5)+YCOORD(PNTAAS(IAA)+6))/2.0-
     +       YCOORD(PNTAAS(IAA)+4)
            V2(3)=(ZCOORD(PNTAAS(IAA)+5)+ZCOORD(PNTAAS(IAA)+6))/2.0-
     +       ZCOORD(PNTAAS(IAA)+4)



            CALL GVSCP3 (V3,V2,V1)



            V1(1)=XCOORD(PNTAAS(IAA)+5)-XCOORD(PNTAAS(IAA)+4)
            V1(2)=YCOORD(PNTAAS(IAA)+5)-YCOORD(PNTAAS(IAA)+4)
            V1(3)=ZCOORD(PNTAAS(IAA)+5)-ZCOORD(PNTAAS(IAA)+4)



            V2(1)=XCOORD(PNTAAS(IAA)+6)-XCOORD(PNTAAS(IAA)+4)
            V2(2)=YCOORD(PNTAAS(IAA)+6)-YCOORD(PNTAAS(IAA)+4)
            V2(3)=ZCOORD(PNTAAS(IAA)+6)-ZCOORD(PNTAAS(IAA)+4)



            IF (GVFDV3(V1,V3).LT.GVFDV3(V2,V3)) THEN
               PRPVAL(IAA)=2.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   30 CONTINUE



      CALL CDB012



      CALL CDB013 ('LEUNAMES',' ','LEUNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 40 IAA=1,NUMAAT
         IF (RESTYP(IAA).EQ.10) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 40
            IF (ORGNAM(PNTAAS(IAA)+6).EQ.ONESAT(PNTAAS(IAA)+7)) THEN
               PRPVAL(IAA)=2.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   40 CONTINUE



      CALL CDB012



      CALL CDB013 ('ARGNAMES',' ','ARGNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 50 IAA=1,NUMAAT
         IF (RESTYP(IAA).EQ.15) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 50
            IF (ORGNAM(PNTAAS(IAA)+9).EQ.ONESAT(PNTAAS(IAA)+10)) THEN
               PRPVAL(IAA)=1.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   50 CONTINUE



      CALL CDB012



      CALL CDB013 ('TYRNAMES',' ','TYRNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 60 IAA=1,NUMAAT
         IF (RESTYP(IAA).EQ.20) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 60
            IF (ORGNAM(PNTAAS(IAA)+6).EQ.ONESAT(PNTAAS(IAA)+7)) THEN
               PRPVAL(IAA)=1.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   60 CONTINUE



      CALL CDB012



      CALL CDB013 ('PHENAMES',' ','PHENAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 70 IAA=1,NUMAAT
         IF (RESTYP(IAA).EQ.5) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 70
            IF (ORGNAM(PNTAAS(IAA)+6).EQ.ONESAT(PNTAAS(IAA)+7)) THEN
               PRPVAL(IAA)=1.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   70 CONTINUE



      CALL CDB012



      CALL CDB013 ('ASPNAMES',' ','ASPNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 80 IAA=1,NUMAAT
         IF (RESTYP(IAA).EQ.3) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 80
            IF (ORGNAM(PNTAAS(IAA)+6).EQ.ONESAT(PNTAAS(IAA)+7)) THEN
               PRPVAL(IAA)=1.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   80 CONTINUE



      CALL CDB012



      CALL CDB013 ('GLUNAMES',' ','GLUNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 90 IAA=1,NUMAAT



         IF (RESTYP(IAA).EQ.4) THEN
            IF (.NOT.WIFCOK(IAA)) GOTO 90
            IF (ORGNAM(PNTAAS(IAA)+7).EQ.ONESAT(PNTAAS(IAA)+8)) THEN
               PRPVAL(IAA)=1.0
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   90 CONTINUE



      CALL CDB012



      CALL CDB013 ('PNAMES',' ','PNAMOK')
      DO 93 IAA=1,NUMAAT



         IF (WIFIRN(IAA)) THEN
            NIT1=GVFNIT(ORGNAM(PNTAAS(IAA)+3),IERR1)
            NIT2=GVFNIT(ONESAT(PNTAAS(IAA)+4),IERR2)
            IF (IERR1.EQ.0.AND.IERR2.EQ.0.AND.NIT1.EQ.NIT2) THEN
               CALL PDBC92 (IAA,0)
            END IF
         END IF
   93 CONTINUE



      CALL CDB012



      CALL CDB013 ('ATNAMES',' ','ATNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 100 IAA=1,NUMAAT
         IF (WRK3TF(IAA)) GOTO 100
         IF (PRPVAL(IAA).EQ.0.AND..NOT.WIFIRW(IAA).AND.WIFCOK(IAA)) THEN
            DO 105 IAT=PNTAAS(IAA),PNTAAE(IAA)
               IF (GVFLEN(ORGNAM(IAT)).LE.0) GOTO 105
               IF (ORGNAM(IAT).NE.ONESAT(IAT).AND..NOT.PROTON(IAT).AND.
     +             ISATOK(IAT)) THEN



                 IF ((ONESAT(IAT).EQ.' ND2 '.AND.
     +                ORGNAM(IAT).EQ.' AD2 ').OR.
     +               (ONESAT(IAT).EQ.' NE2 '.AND.
     +                ORGNAM(IAT).EQ.' AE2 ').OR.
     +               (ONESAT(IAT).EQ.' OD1 '.AND.
     +                ORGNAM(IAT).EQ.' AD1 ').OR.
     +               (ONESAT(IAT).EQ.' OE1 '.AND.
     +                ORGNAM(IAT).EQ.' AE1 ')) THEN
                    GOTO 105
                 END IF



                  IF (WIFIC2(ONESAT(IAT)).AND.
     +                WIFIC2(ORGNAM(IAT))) THEN
                     GOTO 105
                  END IF



                  IF (WIFIRN(IAA)) THEN
                     IF ((ONESAT(IAT).EQ.' OP1 '.OR.
     +                    ONESAT(IAT).EQ.' OP2 ').AND.
     +                   (ORGNAM(IAT).EQ.' OP1 '.OR.
     +                    ORGNAM(IAT).EQ.' OP2 '.OR.
     +                    ORGNAM(IAT).EQ.' O1P '.OR.
     +                    ORGNAM(IAT).EQ.' O2P ')) THEN
                        GOTO 105
                     END IF
                  END IF



                  IF (ORGNAM(IAT)(4:4).EQ.'*'.AND.
     +                ONESAT(IAT)(4:4).EQ.''''.AND.
     +                ONESAT(IAT)(1:3).EQ.ORGNAM(IAT)(1:3)) THEN
                     GOTO 105
                  END IF



                  IF (CH5EQCH5(ONESAT(IAT),ORGNAM(IAT))) THEN
                     GOTO 105
                  END IF



                  PRPVAL(IAA)=3.0
                  CALL PDBC92A (IAA,IAT)
                  IF (GVFLEN(ORGNAM(IAT)).LE.0) THEN
                     PRINT*,'No ORGNAM for',iaa,onesa3(iaa),onesat(iat)
                  ELSE
                     CALL GVSSTX (LINE92(32:36),ORGNAM(IAT))
                  END IF
                  CALL PDBC93 (LINE92)
               END IF
  105       CONTINUE
         END IF
  100 CONTINUE



      CALL CDB012



      IF (WIFPAR(84).EQ.0) GOTO 998
      CALL CDB013 ('HATNAMES',' ','HATNAMOK')
      CALL CDB014 (1,'TORSION','POOR')
      CALL CDB014 (2,'SWAPPED','BAD')
      CALL CDB014 (3,'WRONG','BAD')
      CALL CDB014 (4,'H-WRONG','POOR')
      DO 110 IAA=1,NUMAAT
         IF (.NOT.WIFIRW(IAA).AND.WIFCOK(IAA)) THEN
            DO 115 IAT=PNTAAS(IAA),PNTAAE(IAA)
               CALL SC4005 (IAT,OLDHNAM)
               IF (OLDHNAM) GOTO 115
               IF (ORGNAM(IAT).NE.ONESAT(IAT).AND.
     +             PROTON(IAT).AND.ISATOK(IAT).AND.
     +             ORGNAM(IAT).NE.'     ') THEN
                  PRPVAL(IAA)=4.0
                  CALL PDBC92A (IAA,IAT)
                  CALL GVSCBC (LINE92,ORGNAM(IAT))
                  CALL PDBC93 (LINE92)
               END IF
  115       CONTINUE
         END IF
  110 CONTINUE







      CALL CDB012



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC4003



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'RESULT.INC'
      INCLUDE       'PDBINC.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IAA, OLDTYP, L, GVFLEN, OLDMOD
      LOGICAL       INUSE(256,0:MAXMODEL), MENTIONED(256), WIFIRZ
      CHARACTER*1   OLDCHA
      CHARACTER*80  DUPS
      EQUIVALENCE   (INUSE,ESPACE(10001))







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



      CALL ESPSET (10001,10000+256*(MAXMODEL+1),72)



      CALL GVSBTF (INUSE,(MAXMODEL+1)*256)
      CALL GVSBTF (MENTIONED,256)
      GENIVL(12)=0



      OLDCHA=CHANAM(1)
      OLDMOD=MODNMB(1)
      OLDTYP=SOUADM(5,CHAINN(2,1))
      INUSE(ICHAR(OLDCHA),MIN(MAXMODEL,MODNMB(1)))=.TRUE.



      DUPS=' '
      DO 100 IAA=2,NUMAAF
         IF (WIFIRZ(IAA)) GOTO 100



         IF (CHANAM(IAA).NE.OLDCHA.OR.MODNMB(IAA).NE.OLDMOD.OR.
     +       SOUADM(5,CHAINN(2,IAA)).NE.OLDTYP) THEN



            IF (INUSE(ICHAR(CHANAM(IAA)),MIN(MAXMODEL,MODNMB(IAA))).AND.
     +           .NOT.MENTIONED(ICHAR(CHANAM(IAA)))) THEN
               L=GVFLEN(DUPS)
               IF (L.GT.0) THEN
                  DUPS(L+1:L+1)=','
                  IF (CHANAM(IAA).EQ.' ') THEN
                     DUPS(L+3:L+3)='-'
                  ELSE
                     DUPS(L+3:L+3)=CHANAM(IAA)
                  END IF
               ELSE
                  IF (CHANAM(IAA).EQ.' ') THEN
                     DUPS(1:1)='-'
                  ELSE
                     DUPS(1:1)=CHANAM(IAA)
                  END IF
               END IF
               MENTIONED(ICHAR(CHANAM(IAA)))=.TRUE.
            END IF
            OLDCHA=CHANAM(IAA)
            OLDMOD=MODNMB(IAA)
            OLDTYP=SOUADM(5,CHAINN(2,IAA))
            INUSE(ICHAR(OLDCHA),MIN(MAXMODEL,OLDMOD))=.TRUE.
         END IF
 100  CONTINUE
      IF (GVFLEN(DUPS).GT.0) THEN
         FILNMS(72)=DUPS
         CALL PDBMES ('CUNIQER')
         GENIVL(12)=1
      ELSE



         CALL SC4004
      END IF



      CALL ESPKIL (10001,10000+256*(MAXMODEL+1),72,'PDBC18')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SC4004



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, OLDTYP, L, GVFLEN, IVAL, LASTIVAL, AANUMN,
     +              IERR, NERR, OLDMOD
      LOGICAL       MENTIONED(256), WIFIRZ
      CHARACTER     OLDCHA
      CHARACTER*80  DUPS
      CHARACTER*1   LASTIC







      CALL GVSBTF (MENTIONED,256)
      NERR=0



      OLDCHA=CHANAM(1)
      OLDMOD=MODNMB(1)
      OLDTYP=SOUADM(5,CHAINN(2,1))
      LASTIVAL=AANUMN(1,IERR)
      IF (IERR.EQ.1) NERR=NERR+1
      LASTIC=INSRTC(1)



      DUPS=' '
      DO 100 IAA=2,NUMAAF
         IF (WIFIRZ(IAA)) GOTO 100
         IVAL=AANUMN(IAA,IERR)
         IF (IERR.EQ.1) NERR=NERR+1



         IF (CHANAM(IAA).EQ.OLDCHA.AND.MODNMB(IAA).EQ.OLDMOD.AND.
     +       SOUADM(5,CHAINN(2,IAA)).EQ.OLDTYP.AND.
     +        ((IVAL.LT.LASTIVAL).OR.
     +         (IVAL.EQ.LASTIVAL.AND.INSRTC(IAA).LE.LASTIC.and.
     +          LASTIC.NE.' '))) THEN



            IF (.NOT.MENTIONED(ICHAR(CHANAM(IAA)))) THEN
               L=GVFLEN(DUPS)
               IF (L.GT.0) THEN
                  DUPS(L+1:L+1)=','
                  IF (CHANAM(IAA).EQ.' ') THEN
                     DUPS(L+3:L+3)='-'
                  ELSE
                     DUPS(L+3:L+3)=CHANAM(IAA)
                  END IF
               ELSE
                  IF (CHANAM(IAA).EQ.' ') THEN
                     DUPS(1:1)='-'
                  ELSE
                     DUPS(1:1)=CHANAM(IAA)
                  END IF
               END IF
               MENTIONED(ICHAR(CHANAM(IAA)))=.TRUE.
            END IF
         END IF
         OLDCHA=CHANAM(IAA)
         OLDMOD=MODNMB(IAA)
         OLDTYP=SOUADM(5,CHAINN(2,IAA))
         LASTIVAL=IVAL
         LASTIC=INSRTC(IAA)
 100  CONTINUE
      IF (NERR.GT.0) THEN
         CALL PDBMES ('CNUMERR')
      ELSE
         IF (GVFLEN(DUPS).GT.0) THEN
            FILNMS(72)=DUPS
            CALL PDBMES ('CCONTER')
         ELSE
            CALL PDBMES ('CHANAMOK')
         END IF
      END IF





      RETURN
      END
      SUBROUTINE SC4005 (IAT,OLDHNAM)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, I
      LOGICAL       OLDHNAM, CH4EQCH4, CH5EQCH5
      CHARACTER*4   T4
      CHARACTER*5   TMPNOW, TMPORG
      CHARACTER*12  CONVERT(54), CON1(27), CON2(27)
      EQUIVALENCE   (CON1(1),CONVERT(1))
      EQUIVALENCE   (CON2(1),CONVERT(28))
      DATA CON1     /'ARG HB1 HB2 ','ARG HB2 HB3 ','ARG HD1 HD2 ',
     +               'ARG HD2 HD3 ','ARG HG1 HG2 ','ARG HG2 HG3 ',
     +               'ASN HB1 HB2 ','ASN HB2 HB3 ','ASP HB1 HB2 ',
     +               'ASP HB2 HB3 ','CYS HB1 HB2 ','CYS HB2 HB3 ',
     +               'GLN HB1 HB2 ','GLN HB2 HB3 ','GLN HG1 HG2 ',
     +               'GLN HG2 HG3' ,'GLU HB1 HB2 ','GLU HB2 HB3 ',
     +               'GLU HG1 HG2 ','GLU HG2 HG3 ','GLY HA1 HA2 ',
     +               'GLY HA2 HA3 ','HIS HB1 HB2 ','HIS HB2 HB3 ',
     +               'ILE 1HG12HG1','LYS HB1 HB2 ','LYS HB2 HB3 '/
      DATA CON2     /'ILE HG12HG13','LEU HB1 HB2 ','LEU HB2 HB3 ',
     +               'LYS HD1 HD2 ','LYS HD2 HD3 ','LYS HE1 HE2 ',
     +               'LYS HE2 HE3 ','LYS HG1 HG2 ','LYS HG2 HG3 ',
     +               'MET HB1 HB2 ','MET HB2 HB3 ','MET HG1 HG2 ',
     +               'MET HG2 HG3 ','PHE HB1 HB2 ','PHE HB2 HB3 ',
     +               'PRO HB1 HB2 ','PRO HB2 HB3 ','PRO HD1 HD2 ',
     +               'PRO HD2 HD3 ','PRO HG1 HG2 ','PRO HG2 HG3 ',
     +               'SER HB1 HB2 ','SER HB2 HB3 ','TRP HB1 HB2 ',
     +               'TRP HB2 HB3 ','TYR HB1 HB2 ','TYR HB2 HB3 '/







      OLDHNAM=.FALSE.



      CALL GVSSTX (TMPNOW,ONESAT(IAT))
      CALL GVSSTX (TMPORG,ORGNAM(IAT))
      DO 10 I=1,5
         IF (TMPNOW(I:I).EQ.'''') TMPNOW(I:I)='*'
         IF (TMPORG(I:I).EQ.'''') TMPORG(I:I)='*'
   10 CONTINUE
      IF (CH5EQCH5(TMPNOW,TMPORG)) THEN
         OLDHNAM=.TRUE.
         GOTO 998
      END IF



      DO 20 I=1,54
         IF (CH4EQCH4(ONESA3(ATIAA(IAT)),CONVERT(I)(1:4))) THEN
            IF (CH4EQCH4(T4(ORGNAM(IAT)),CONVERT(I)(5:8)).AND.
     +          CH4EQCH4(T4(ONESAT(IAT)),CONVERT(I)(9:12))) THEN
               OLDHNAM=.TRUE.
               GOTO 998
            END IF
         END IF
   20 CONTINUE



  998 CONTINUE


      RETURN
      END   
