



      SUBROUTINE PRP_READ_MUTDB (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       ISEQ, IERR







      CALL GVSIT0 (NAAFIL,MAXSEQ)
      CALL GVSCTB (NAMFIL,4*MAXSEQ)
      CALL GVSCTB (FILCNM,MAXSEQ)
      CALL GVSITC (WIFFAC,2,MAXSEQ)
      CALL GVSIT0 (INDPNT,MAXSEQ+1)
      IERR=0






         IF (WIFPAR(12).EQ.0) THEN
            CALL GVSCCC (LINE,FILDIR(27),'MUTDB.IND')
            CALL GETFILE (11,' ',LINE,IERR)
            IF (IERR.NE.0) GOTO 999
            CALL GVSFMT ('?FMT156')
            DO 10 ISEQ=1,MAXSEQ
               CALL GETLINE (11,LINE,IERR)

               IF (IERR.EQ.1) GOTO 999
               IF (IERR.EQ.2) GOTO 11
               IF (LINE(1:4).EQ.'*END') GOTO 11
               READ (LINE,1000,END=11,ERR=999) NAMFIL(ISEQ),
     +          FILCNM(ISEQ),NAAFIL(ISEQ),ICOFDB(ISEQ),IH2ODB(ISEQ)
               NBINDB=ISEQ

 10         CONTINUE
 11         CONTINUE
            IERR=0



            DO 20 ISEQ=2,NBINDB+1
               INDPNT(ISEQ)=INDPNT(ISEQ-1)+NAAFIL(ISEQ-1)
 20         CONTINUE
         ELSE
            CALL GVSBOX ('?M0064')
         END IF
         GOTO 998



 999     CONTINUE
         CALL GVSTT6 ('?ERF006')
         WIFPAR(12)=1
         IERR=1




 998  CONTINUE
      CALL GVSCLF (11)


 1000 FORMAT (5X,A4,A1,3I8)

      RETURN
      END   
      SUBROUTINE PRP_OPEN_ALCOOR (IERR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR
      LOGICAL       GVFFOP
      CHARACTER*80  LOCLIN







      WIFPAR(12)=0
      IERR=0



      IF (GVFFOP(IU100)) CALL GVSCLF (IU100)



      CALL GVSCCC (LOCLIN,FILDIR(28),'ALCOOR.XYZ')
      CALL GVSODF (IU100,.FALSE.,LOCLIN,'UNKNOWN',280,'?NEWE264',
     + IERR)
      IF (GVFFOP(IU100)) THEN
         CALL GVSTT6 ('?M0064A')
      ELSE
         CALL GVSTTE ('?M0064B')
         IERR=1
      END IF



      IF (IERR.NE.0) THEN
         CALL SHOWTEXT ('?M0063')
         CALL GVSCOD (' ')
      END IF


      RETURN
      END
      SUBROUTINE PRP_SETUP (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR
      LOGICAL       GVFISF







      IERR=0







      CALL CNTOPEN (0)
      CALL WIF023
      WIFPAR(622)=0
      WIFPAR(642)=1
      WIFPAR(825)=0
      WIFPAR(919)=1



      CALL PRP205 (IERR)
      IF (IERR.NE.0) GOTO 999



      CALL PRP140 (IERR)
      IF (IERR.NE.0) GOTO 999



      CALL PRP_ERR_FIL (.FALSE.,IERR)
      IF (IERR.NE.0) GOTO 999



      CALL PRP_OPEN_ALCOOR (IERR)
      IF (IERR.NE.0) GOTO 999



      CALL ALT001 (IERR)
      IF (IERR.NE.0) THEN
         CALL GVSTT6 ('?M3689')
         GOTO 999
      END IF



      CALL GVSCCC (LINE,FILDIR(27),'MUTDB.IND')
      IF (GVFISF(LINE)) THEN
         CALL PRP_READ_MUTDB (IERR)
         IF (IERR.NE.0) GOTO 999
      END IF
      GOTO 998



  999 CONTINUE
      IERR=1
      CALL GVSTTE ('?M5150')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE PRP_ERR_FIL (KILL,IERR)

















      IMPLICIT      NONE
      INCLUDE       'DATBAS.INC'
      INTEGER       IERR, ISEQ, IHIT
      LOGICAL       GVFFOP, GVFISF, NEWFIL, KILL







      IERR=0



      IF (GVFFOP(66)) CALL GVSCLF (66)
      IF (GVFISF('DBERLO.DAC').AND.KILL) CALL GVSDEL ('DBERLO.DAC')



      NEWFIL=.NOT.GVFISF('DBERLO.DAC')
      CALL GVSODF (66,.FALSE.,'DBERLO.DAC','UNKNOWN',MAXDAC,
     + '?M2234',IERR)



      IF (NEWFIL) THEN
         DO 20 ISEQ=1,NBINDB
            DO 10 IHIT=1,MAXDAC
               CALL PRP127 (ISEQ,IHIT,-1)
 10         CONTINUE
 20      CONTINUE
      END IF





      RETURN
      END
      SUBROUTINE PRP_GET_PDB (IUNIT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IERR, IUNIT, GVFLEN
      LOGICAL       GVFFOP
      CHARACTER*4   CHAR4
      CHARACTER*6   CHAR6
      CHARACTER*80  SEQNAM







      IERR=0
      CALL GVSLIN
      NBINDB=NBINDB+1




      CALL MOL100
      CALL GVSDEL ('DAVADRUG.*')
      CALL GVSDEL ('DRGDRG.*')
      CALL GVSDEL ('DRGWIF.*')
      CALL GVSDEL ('DRGGMX.*')
      CALL GVSDEL ('PRODRUG.*')
      WIFPAR(276)=WIFPAR(294)



      CALL GVSFMT ('?FMT156')
      CALL GVSCTB (NAMFIL(NBINDB),4)
      FILCNM(NBINDB)=' '
      READ (IUNIT,FMT,END=996,ERR=997) NAMFIL(NBINDB),FILCNM(NBINDB)

      IF (GVFLEN(NAMFIL(NBINDB)).LE.0.OR.NAMFIL(NBINDB).EQ.'*END') 
     +    THEN
         NBINDB=NBINDB-1
         IERR=1
         GOTO 996
      END IF



      CALL PRP206 (' ')
      CALL PRP206 ('===========================================')
      CALL PRP206 (' ')
      CALL GVSTTI ('?WORKON',NBINDB)
      CALL PRP208 ('?WORKON',NBINDB)
      CALL PRP206 (NAMFIL(NBINDB)//' '//FILCNM(NBINDB))
      CALL PRP206 (' ')



      CALL GVSCUC (NAMFIL(NBINDB))
      CALL GVSCUC (FILCNM(NBINDB))



      CALL GVSSTX (CHAR6,NAMFIL(NBINDB))
      CHAR6(6:6)=FILCNM(NBINDB)



      CALL GVSCTB (SEQNAM,80)
      IF (FOR3DM) THEN






            CALL GVSSTX (CHAR4,NAMFIL(NBINDB))
            CALL GVSCUC (CHAR4)
            CALL GVSCC3 (SEQNAM,FILNMS(61),CHAR4,'.pdb')
            CALL GVST6C ('3DM PDB file name:',SEQNAM,.FALSE.)

      ELSE
         CALL GVSCTB (SEQNAM,80)
         CALL GVSSTX (LINE2,NAMFIL(NBINDB))
         CALL MOL702 (LINE2,SEQNAM,IERR)
         IF (IERR.NE.0) GOTO 998
      END IF
      CALL GVSSTX (FILNMS(39),SEQNAM)



      IF (ALTUNT.GE.1) THEN
         IF (GVFFOP(ALTUNT)) CALL GVSTTU (ALTUNT,SEQNAM)
      END IF



      CALL WIFPUSHPPP (428,1)
      CALL WIFPUSHPPP (825,0)

      CALL PDBL05 (SEQNAM,.TRUE.)
      CALL WIFPOPPPP (825)
      CALL WIFPOPPPP (428)



      IF (FOR3DM) CALL WIF242



      CALL WIFPUSHPPP (111,0)
      CALL MOL037
      CALL WIFPOPPPP (111)



      IF (NUMAAF.LE.0) THEN
         CALL GVST6C ('?M0471',FILNMS(39),.TRUE.)
         IERR=1
      ELSE
         IERR=0
      END IF
      GOTO 998



  996 CONTINUE
      IERR=2
      GOTO 998



  997 CONTINUE
      CALL GVSTTE ('?M3687')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE PRP_CHACLN (CHAINM)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ISOUP, JSOUP, GVFCBT, COUNTR, CSELF, COTHER, IAA
      LOGICAL       WIFISW, WIFISN, WIFISA, WIFISO, KILROW(MAXMOL)
      CHARACTER*1   CHAINM









      IF (CHAINM.EQ.'*') GOTO 998




      IF (CHAINM.EQ.' ') THEN
         DO 10 IAA=1,NUMAAF
            IF (CHANAM(IAA).EQ.' ') GOTO 20
 10      CONTINUE
         CHAINM=CHANAM(1)
         CALL GVST6C ('?M5141',CHAINM,.TRUE.)
      END IF
 20   CONTINUE



      CALL GVSBTF (KILROW,NUMSOU)




      DO 30 ISOUP=NUMSOU,1,-1
         IF (WIFISA(ISOUP).OR.WIFISN(ISOUP).OR.WIFISW(ISOUP)) GOTO 30
         CALL PRP_CHA_CNT (ISOUP,CHAINM,CSELF,COTHER)
         IF (COTHER.GT.CSELF+1.0) THEN
            IAA=SOUADM(1,ISOUP)
            KILROW(ISOUP)=.TRUE.
         END IF
 30   CONTINUE



      DO 40 ISOUP=NUMSOU,1,-1
         IF (WIFISA(ISOUP).OR.WIFISN(ISOUP).OR.WIFISO(ISOUP)) THEN
            IF (CHANAM(SOUADM(1,ISOUP)).NE.CHAINM) THEN
               CALL PRP208 ('?M2957',ISOUP)
               KILROW(ISOUP)=.TRUE.
            END IF
         END IF
 40   CONTINUE




 60   CONTINUE
         COUNTR=GVFCBT(KILROW,NUMSOU)
         DO 70 ISOUP=1,NUMSOU
            CALL PRP_CHA_CNT (ISOUP,CHAINM,CSELF,COTHER)
            IF (COTHER.GT.CSELF+1.0) KILROW(ISOUP)=.TRUE.
 70      CONTINUE
      IF (GVFCBT(KILROW,NUMSOU).GT.COUNTR) GOTO 60



      DO 90 ISOUP=NUMSOU,1,-1
         IF (KILROW(ISOUP)) THEN
            KILROW(ISOUP)=.FALSE.
            DO 80 JSOUP=ISOUP,NUMSOU-1
               KILROW(JSOUP)=KILROW(JSOUP+1)
 80         CONTINUE
            CALL PRP208 ('Go for the kill of:',ISOUP)
            CALL MOL101A (ISOUP)
            CALL MOL200
            CALL PRP202 ('Just after the kill...')
         END IF
 90   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE PRP_CHA_CNT (ISOUP,CHAINM,CNT1,CNT2)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ISOUP, IAA, IAT, JSOUP, JAA, JAT, CNT1, CNT2, IBND
      REAL          D12
      LOGICAL       WIFISN, WIFISA, WIFISW
      CHARACTER*1   CHAINM







      CNT1=0
      CNT2=0



      IF (WIFISN(ISOUP).OR.WIFISA(ISOUP).OR.WIFISW(ISOUP)) GOTO 998
      IF (FUTURE(SOUADM(1,ISOUP)).NE.0) GOTO 998



      DO 50 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)
         DO 40 IAT=PNTAAS(IAA),PNTAAE(IAA)
            DO 30 IBND=1,8
               JAT=BOUND_TO(IBND,IAT)
               IF (JAT.NE.0) THEN
                  JAA=ATIAA(BOUND_TO(IBND,IAT))
                  IF (JAA.EQ.IAA) GOTO 30
                  IF (CHANAM(JAA).EQ.CHAINM) THEN
                     CNT1=CNT1+2
                  ELSE
                     CNT2=CNT2+2
                  END IF
               END IF
 30         CONTINUE
 40      CONTINUE
 50   CONTINUE



      CNT1=0
      CNT2=0
      DO 100 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)



         DO 90 JSOUP=1,NUMSOU
            IF (ISOUP.EQ.JSOUP) GOTO 90
            IF (WIFISW(JSOUP)) GOTO 90
            IF (FUTURE(SOUADM(1,JSOUP)).NE.0) GOTO 90



            DO 80 JAA=SOUADM(1,JSOUP),SOUADM(2,JSOUP)
               IF (IAA.EQ.JAA) GOTO 80



               D12=SQRT((SPHRAD(1,IAA)-SPHRAD(1,JAA))**2+
     +                  (SPHRAD(2,IAA)-SPHRAD(2,JAA))**2+
     +                  (SPHRAD(3,IAA)-SPHRAD(3,JAA))**2)-
     +                   SPHRAD(4,IAA)-SPHRAD(4,JAA)
               IF (D12.GT.FLOAT(WIFPAR(56))/100.0) GOTO 80



               DO 70 IAT=PNTAAS(IAA),PNTAAE(IAA)
                  IF (.NOT.ISATOK(IAT).OR.PROTON(IAT)) GOTO 70
                  DO 60 JAT=PNTAAS(JAA),PNTAAE(JAA)
                     IF (.NOT.ISATOK(JAT).OR.PROTON(JAT)) GOTO 60



                     D12=SQRT((XCOORD(IAT)-XCOORD(JAT))**2+
     +                        (YCOORD(IAT)-YCOORD(JAT))**2+
     +                        (ZCOORD(IAT)-ZCOORD(JAT))**2)-
     +                         VDWRAD(IAT)-VDWRAD(JAT)
                     IF (D12.GT.FLOAT(WIFPAR(56))/100.0) THEN
                        IF (CHANAM(SOUADM(1,JSOUP)).EQ.CHAINM) THEN
                           CNT1=CNT1+1
                        ELSE
                           CNT2=CNT2+1
                        END IF
                        GOTO 70
                     END IF
 60               CONTINUE
 70            CONTINUE
 80         CONTINUE
 90      CONTINUE
 100  CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE PRP_BAD_DIS (NUMBAD,NUMODD,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       NUMBAD, NUMODD, IERR, IAA, JAA, IAT, JAT, ICON
      REAL          D1, D2, ERROR
      LOGICAL       XYZNUL







      IERR=0
      NUMBAD=0
      NUMODD=0



      DO 90 IAA=1,NUMAAF



         CALL GVSBTT (ISATOK,NUMATF)
         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT).OR.PROTON(IAT)) GOTO 10
            IF (XYZNUL(IAT)) ISATOK(IAT)=.FALSE.
 10      CONTINUE




         DO 80 JAA=IAA,MIN(NUMAAF,IAA+1)
            IF (CHAINN(2,IAA).NE.CHAINN(2,JAA)) GOTO 80



            DO 70 IAT=PNTAAS(IAA),PNTAAE(IAA)
               IF (PROTON(IAT)) GOTO 70
               IF (.NOT.ISATOK(IAT)) GOTO 70
               DO 60 JAT=PNTAAS(JAA),PNTAAE(JAA)
                  IF (PROTON(JAT)) GOTO 60
                  IF (IAA.EQ.JAA.AND.IAT.GE.JAT) GOTO 60
                  IF (.NOT.ISATOK(JAT)) GOTO 60



                  CALL BONDOK (IAA,JAA,RESTYP(IAA),IAT,JAT,ICON,D1,
     +             D2,ERROR,IERR)
                  IF (IERR.NE.0) GOTO 60



                  IF (ERROR.GT.0.4) THEN
                     NUMBAD=NUMBAD+1
                     CALL GVSTT6 ('?NEWT305')
                     CALL DIF016A (IAT,JAT,D2)
                     CALL DIF012D (DATLOG,IAT,JAT,'Too close',ERROR)
                     ISATOK(IAT)=.FALSE.
                     ISATOK(JAT)=.FALSE.
                  ELSE IF (ERROR.GT.0.2) THEN
                     NUMODD=NUMODD+1
                     CALL GVSTT6 ('?NEWT306')
                     CALL DIF016A (IAT,JAT,D2)
                     CALL DIF012D (DATLOG,IAT,JAT,'Close',ERROR)
                  END IF
 60            CONTINUE
 70         CONTINUE
 80      CONTINUE
 90   CONTINUE





      RETURN
      END   
      SUBROUTINE PRP_GETPDBDB (ISEQ,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'HISTOG.INC'
      INCLUDE       'HSTINC.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       ISEQ, IERR
      LOGICAL       GVFIBN, GVFFOP








      IF (.NOT.GVFIBN(ISEQ,1,NBINDB)) THEN
         IERR=1
         CALL GVSTTE ('?NEWE920')
         GOTO 998
      END IF
      IF (.NOT.GVFFOP(IU100)) THEN
         CALL GVSTTB ('Database not open in PRP_GETPDBDB')
         IERR=1
         GOTO 998
      END IF




      IERR=0
      CALL MOL100
      WIFPAR(276)=WIFPAR(294)










      CALL WIFPUSHPPP (826,1)
      CALL WIFPUSHPPP (96,1)
      CALL WIF004 (ISEQ)
      CALL WIFPOPPPP (96)
      CALL WIFPOPPPP (826)
      HSTDON=.TRUE.






  998 CONTINUE


      RETURN
      END   
      SUBROUTINE PRP_CLEAN

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INTEGER       IUNIT, IERR
      LOGICAL       GVFISF, GVFYON, GRTFILE, GVFFOP







      PRINT*,'At 1'
      IF (FOR3DM) THEN
         CALL GVSTT6 ('*.brk')
      ELSE
         IF (GVFYON('Local .brk files too',' ')) THEN
            CALL GVSTT6 ('*.brk')
         END IF
      END IF



      PRINT*,'At 2'
      IF (GVFFOP(66)) CALL GVSCLF (66)
      CALL GVSTT6 ('DBERLO.DAC')



      PRINT*,'At 3'
      CALL GVSCCC (LINE,FILDIR(27),'*')
      CALL GVSTT6 (LINE)



      PRINT*,'At 4'
      CALL GVSCCC (LINE,FILDIR(28),'*')
      CALL GVSTT6 (LINE)



      PRINT*,'At 5'
      CALL GVSCCC (LINE,FILNMS(83),'*')
      CALL GVSTT6 (LINE)



      PRINT*,'At 6'
      CALL GVSCCC (LINE,FILDIR(30),'NQABOX.DAT')
      CALL GVSTT6 (LINE)
      CALL GVSCCC (LINE,FILDIR(30),'NQANOR.WAT')
      CALL GVSTT6 (LINE)  
      CALL GVSCCC (LINE,FILDIR(30),'NQAPTR.TXT')
      CALL GVSTT6 (LINE) 
      CALL GVSCCC (LINE,FILDIR(30),'NQASTR.WAT')
      CALL GVSTT6 (LINE)



      PRINT*,'At 7'
      CALL GVSTT6 ('FOR0*.DAT')
      CALL GVSTT6 ('*~')
      CALL GVSTT6 ('*.WPL')
      CALL GVSTT6 ('core*')
      CALL GVSTT6 ('DRGWIF.*')
      CALL GVSTT6 ('DRGDRG.*')
      CALL GVSTT6 ('DRGGMX.*')
      CALL GVSTT6 ('ALTERR.*')
      CALL GVSTT6 ('PDBFIL*')
      CALL GVSTT6 ('TEXSTORE.*')
      CALL GVSTT6 ('DAVADRUG*')
      CALL GVSTT6 ('PRODRUG.*')
      CALL GVSTT6 ('#*')
      CALL GVSTT6 ('.#*')
      CALL SYSTEM ('rm -rf SCRATCH')



      CALL GVSCCC (LINE,WHERIS,'MAKDB.ALL')
      IF (.NOT.GRTFILE(IUNIT,LINE)) GOTO 998



      PRINT*,'At 8'
 10   CONTINUE
         CALL GETLINE (IUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 998

         IF (GVFISF(LINE)) CALL GVSTT6 (LINE)
      GOTO 10



  998 CONTINUE


      RETURN
      END
      SUBROUTINE PRP_IMP_ADM

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IAT, IAA, ATT, MAXALO, NUMOA
      PARAMETER     (MAXALO=2000)
      PARAMETER     (NUMOA=20)
      INTEGER       NUM(MAXTAT,NUMOA)
      REAL          PDBC71, VAL, RA(MAXALO,MAXTAT,NUMOA)
      LOGICAL       GVFIBN, WIFIRA, WIFROK
      EQUIVALENCE   (NUM,   ESPACE(5000001+0*NUMOA*MAXTAT))
      EQUIVALENCE   (RA,    ESPACE(5000001+1*NUMOA*MAXTAT))







      IF (NBINDB.LE.1) THEN
         CALL GVSIT0 (NUM,MAXTAT*NUMOA)
         CALL GVSRT0 (RA,MAXALO*MAXTAT*NUMOA)
      END IF



      DO 20 IAA=1,NUMAAF
         IF (.NOT.WIFIRA(IAA)) GOTO 20
         IF (.NOT.WIFROK(IAA)) GOTO 20
         IF (.NOT.GVFIBN(RESTYP(IAA),1,20)) GOTO 20
         DO 10 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (.NOT.ISATOK(IAT).OR.WEIGHT(IAT).LT.0.8) GOTO 10
            ATT=PINIAA(IAT)
            IF (NUM(ATT,RESTYP(IAA)).GE.MAXALO) GOTO 10
            VAL=PDBC71(IAT)
            IF (VAL.GT.-900.0) THEN
               NUM(ATT,RESTYP(IAA))=NUM(ATT,RESTYP(IAA))+1
               RA(NUM(ATT,RESTYP(IAA)),ATT,RESTYP(IAA))=VAL
            END IF
 10      CONTINUE
 20   CONTINUE





      RETURN
      END   
