



      SUBROUTINE KLO000

      IMPLICIT NONE








C





C

C



C


C


C




C





C




C



C


C




C


C


C
      RETURN
      END
      SUBROUTINE KLONKSTART (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR








      IERR=0
      WIFPAR(1214)=0
      MCFPNT=0
      CALL GVSIT0 (MCFCNT,10)



      CALL GVSODF (13,.TRUE.,'MCFJUNK.LOG','UNKNOWN',80,'?MOLC37',IERR)





      RETURN
      END
      SUBROUTINE KLONKUP



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ISOUP1, ISOUP2, IAA, IAT, PNTAAF, IERR, IBND
      LOGICAL       ISPROTON







      IF (WIFPAR(329).NE.0) CALL GVSTT6 ('?M3684')
      IF (NUMAAT.LE.NUMAAF) GOTO 998



      WIFPAR(1504)=WIFPAR(1504)+1



      ISOUP1=CHAINN(2,NUMAAF+1)
      ISOUP2=CHAINN(2,NUMAAT)
      IF (ISOUP2.LT.ISOUP1) THEN
         CALL GVSTTB ('?MOLC50')
         NUMAAT=NUMAAF
         GOTO 998
      END IF



      DO 20 IAA=NUMAAF+1,NUMAAT



         CALL KLONKSET (SOUPNT(IAA),MODNMB(IAA),IERR)
         IF (IERR.NE.0) GOTO 998



         DO 15 IAT=PNTAAS(IAA),PNTAAE(IAA)
            CALL KLONKTO (IAT,IERR)
 15      CONTINUE
 20   CONTINUE



      NUMCOF=0
      IF (NUMAAF.LE.0) THEN
         NUMATF=0
         PNTAAF=0
      ELSE
         NUMATF=PNTAAE(NUMAAF)
         PNTAAF=PNTAAE(NUMAAF)
      END IF
      NUMAAT=NUMAAF
      NUMSOU=ISOUP1-1
      IF (WIFPAR(84).EQ.1) THEN
         DO 40 IAT=1,MAXAT
            DO 30 IBND=2,8
               IF (ISPROTON(IAT)) BOUND_TO(IBND,IAT)=0
 30         CONTINUE
            IF (BOUND_TO(2,IAT).GT.PNTAAF) THEN
               DO 35 IBND=2,8
                  IF (ISPROTON(IAT)) BOUND_TO(IBND,IAT)=0
 35            CONTINUE
            END IF
 40      CONTINUE
      END IF



      DO 60 IAT=1,PNTAAE(NUMAAF)
         DO 50 IBND=1,8
            IF (BOUND_TO(IBND,IAT).GT.PNTAAF) BOUND_TO(IBND,IAT)=0
 50      CONTINUE
 60   CONTINUE



 998  CONTINUE

         CALL MOL219



      RETURN
      END
      SUBROUTINE KLONKTO (IAT,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, IAA, IERR
      REAL          GVFDTR
      LOGICAL       WIFIRW, WIFITI, HASPROTONGB
      CHARACTER*4   T4
      CHARACTER*6   HETATM







      IF (.NOT.WIFITI(IAT)) THEN
         IERR=1
         CALL GVSTTB ('?M3667')
         GOTO 998
      END IF



      IERR=0
      IAA=ATIAA(IAT)



      IF (FAMTYP(RESTYP(IAA)).EQ.1.OR.
     +    FAMTYP(RESTYP(IAA)).EQ.3.OR.
     +    FAMTYP(RESTYP(IAA)).EQ.7) THEN
         CALL GVSSTX (HETATM,'ATOM  ')
      ELSE
         CALL GVSSTX (HETATM,'HETATM')
      END IF

      CALL KLONKTOD (HETATM,T4(ONESAT(IAT)),ORGNAM(IAT),ALTATM(IAT),
     + ONESA3(IAA),CHANAM(IAA),NUMNAM(IAA),' ',XCOORD(IAT),
     + YCOORD(IAT),ZCOORD(IAT),WEIGHT(IAT),XBFACT(IAT),
     + MENDLV(IAT),PDBNUM(IAT),ONEORG(IAA),IAA,IERR)



      IF (.NOT.PROTON(IAT).AND.WIFPAR(138).EQ.1.AND. WIFIRW(IAA).AND.
     +    WRK1TF(IAA).AND.(.NOT.HASPROTONGB(IAA))) THEN
         CALL KLONKTOD (HETATM,SPCATM(7),SPCATM(7),' ',ONESA3(IAA),
     +    CHANAM(IAA),NUMNAM(IAA),' ',XCOORD(IAT)+1.0,YCOORD(IAT),
     +    ZCOORD(IAT),WEIGHT(IAT),XBFACT(IAT),' H',PDBNUM(IAT),
     +    ONEORG(IAA),IAA,IERR)
         CALL KLONKTOD (HETATM,SPCATM(8),SPCATM(8),' ',ONESA3(IAA),
     +    CHANAM(IAA),NUMNAM(IAA),' ',XCOORD(IAT)-COS(GVFDTR(68.0)),
     +    YCOORD(IAT)+SIN(GVFDTR(68.0)),ZCOORD(IAT),WEIGHT(IAT),
     +    XBFACT(IAT),' H',PDBNUM(IAT),ONEORG(IAA),IAA,IERR)
      END IF



      IF (.NOT.HASALT(IAA)) GOTO 998
      IF (ALALAT(IAT).EQ.' ') GOTO 998
      IF (WIFPAR(329).NE.0) PRINT*,'IN KLONKTO:',IAA,ONESA3(IAA),
     + ONESAT(IAT),HASALT(IAA),ALALAT(IAT)




      CALL ALT007 (IAT,IERR)
      IF (IERR.NE.0) GOTO 998



      IF (FAMTYP(RESTYP(IAA)).EQ.1.OR.
     +    FAMTYP(RESTYP(IAA)).EQ.3.OR.
     +    FAMTYP(RESTYP(IAA)).EQ.7) THEN
         CALL GVSSTX (HETATM,'ATOM  ')
      ELSE
         CALL GVSSTX (HETATM,'HETATM')
      END IF
      CALL KLONKTOD (HETATM,T4(ONESAT(IAT)),ORGNAM(IAT),ALTATM(IAT),
     + ONESA3(IAA),CHANAM(IAA),NUMNAM(IAA),' ',XCOORD(IAT),
     + YCOORD(IAT),ZCOORD(IAT),WEIGHT(IAT),XBFACT(IAT),
     + MENDLV(IAT),PDBNUM(IAT),ONEORG(IAA),IAA,IERR)



      IF (.NOT.PROTON(IAT).AND.WIFPAR(138).EQ.1.AND.WIFIRW(IAA).AND.
     +    WRK1TF(IAA).AND.(.NOT.HASPROTONGB(IAA))) THEN
         CALL KLONKTOD (HETATM,SPCATM(7),SPCATM(7),' ',ONESA3(IAA),
     +    CHANAM(IAA),NUMNAM(IAA),' ',XCOORD(IAT)+1.0,YCOORD(IAT),
     +    ZCOORD(IAT),WEIGHT(IAT),XBFACT(IAT),' H',PDBNUM(IAT),
     +    ONEORG(IAA),IAA,IERR)
         CALL KLONKTOD (HETATM,SPCATM(8),SPCATM(8),' ',ONESA3(IAA),
     +    CHANAM(IAA),NUMNAM(IAA),' ',XCOORD(IAT)-COS(GVFDTR(68.0)),
     +    YCOORD(IAT)+SIN(GVFDTR(68.0)),ZCOORD(IAT),WEIGHT(IAT),
     +    XBFACT(IAT),' H',PDBNUM(IAT),ONEORG(IAA),IAA,IERR)
      END IF



      CALL ALT007 (IAT,IERR)
      IF (IERR.NE.0) GOTO 998




  998 CONTINUE


      RETURN
      END   
      SUBROUTINE KLONKTOD (TEXT,THISAT,THISORG,THISAL,THISAA,THISCH,
     + THISNM,ALTRES,THISX,THISY,THISZ,THISWT,THISBF,THISMV,THISPN,
     + THISOA,IAA,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, IAA, LSTSOU, LSTNMB, GVFLEN, I, THISPN
      REAL          THISX, THISY, THISZ, THISWT, THISBF
      LOGICAL       MOL009
      CHARACTER*(*) TEXT
      CHARACTER*5   THISORG
      CHARACTER*4   THISAT, THISAA, THISNM, THISOA, THISAU
      CHARACTER*2   THISMV
      CHARACTER*1   THISCH, THISAL, ALTRES
      SAVE          LSTSOU, LSTNMB
      DATA LSTSOU   /-999/
      DATA LSTNMB   /-999/











































      IF (TEXT.NE.'ATOM  '.AND.TEXT.NE.'HETATM') THEN
         CALL GVSTTI ('?M1263',LEN(TEXT))
         CALL GVST6C ('TEXT=',TEXT,.FALSE.)
         CALL GVSKIL
      END IF



      IERR=0
      WIFPAR(1185)=WIFPAR(1185)+1
      WIFPAR(1214)=WIFPAR(1214)+1



      CALL GVSFMT ('?FMT521')
      IF (IAA.GT.0) THEN
         IF (SOUPNT(IAA).NE.LSTSOU.OR.MODNMB(IAA).NE.LSTNMB) THEN
            DO 1 I=1,80
               LINE(I:I)=' '
 1          CONTINUE
            WRITE (LINE,FMT,ERR=995) SOUPNT(IAA),MODNMB(IAA)
            CALL LINTOKLONK (LINE)
            LSTSOU=SOUPNT(IAA)
            LSTNMB=MODNMB(IAA)
         END IF
      END IF



      CALL GVSFMT ('?FMT1188')







         THISAU=THISOA

      IF (GVFLEN(THISAU).LE.0) THEN







            THISAU=THISAA

      END IF
      IF (MOL009(THISOA)) THEN
         WRITE (LINE,FMT,ERR=993) TEXT,THISPN,THISAT,THISAL,
     +    THISOA,THISCH,THISORG(1:4),ALTRES,THISX,THISY,THISZ,
     +    THISWT,THISBF,THISORG(1:4),THISMV
      ELSE
         WRITE (LINE,FMT,ERR=994) TEXT,THISPN,THISAT,THISAL,
     +    THISAU,THISCH,THISNM,ALTRES,THISX,THISY,THISZ,
     +    THISWT,THISBF,THISORG(1:4),THISMV
      END IF




         LINE(79:80)='  '

      CALL LINTOKLONK (LINE)
      GOTO 998



  993 CONTINUE
      CALL GVSTT6 ('?M3664')
      CALL GVSKIL
      IERR=1
      GOTO 998



  994 CONTINUE
      CALL GVSTT6 ('?M3665')
      CALL GVSKIL
      IERR=1
      GOTO 998



  995 CONTINUE
      CALL GVSTT6 ('?M3666')
      CALL GVSKIL
      IERR=1



  998 CONTINUE


      RETURN
      END
      SUBROUTINE KLONKSET (KSOUPNT,KMODNMB,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       KSOUPNT, KMODNMB, IMODNMB, IERR







      IERR=0



      IF (KMODNMB.EQ.0) THEN
         IF (WIFPAR(847).LE.0) THEN
            IMODNMB=0
         ELSE
            IMODNMB=1
         END IF
      ELSE
         IMODNMB=KMODNMB
      END IF








         LINE=BLNK80

      CALL LINTOKLONK (LINE)
      CALL GVSFMT ('?FMT521')





         LINE=BLNK80


      WRITE (LINE,FMT,ERR=999) KSOUPNT,IMODNMB
      CALL LINTOKLONK (LINE)
      CALL LINTOKLONK (LINE)
      GOTO 998



  999 CONTINUE
      CALL SHOWTEXT ('?MOLBB07')
      IERR=1



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE KLONKTER (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR







      IERR=0



      CALL GVSFMT ('?FMT421')
      CALL GVSCTB (LINE,80)
      WRITE (LINE,FMT,ERR=999) 
      CALL LINTOKLONK (LINE)
      GOTO 998



  999 CONTINUE
      CALL SHOWTEXT ('?MOLBB07')
      IERR=1



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE KLONKDOWN

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'








      WIFPAR(1504)=WIFPAR(1504)+1



      MCFPNT=0




      CALL CHKBOUNDTO ('KLONKDOWN at 1')
      CALL MOL004
      CALL CHKBOUNDTO ('KLONKDOWN at 2')
      CALL MOL005
      CALL CHKBOUNDTO ('KLONKDOWN at 3')





      CALL CHKBOUNDTO ('KLONKDOWN at 4')



      CALL MOL200
      CALL CHKBOUNDTO ('KLONKDOWN at 5')






      CALL CHKBOUNDTO ('KLONKDOWN at 6')





      RETURN
      END
      SUBROUTINE KLONKEND

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'







      CALL GVSCLF (13)



      WIFPAR(1214)=0



      CALL GVSDEL ('MCFJUNK.LOG')





      RETURN
      END
      SUBROUTINE KLONKCLEAN

















      IMPLICIT      NONE







      CALL GVSCLF (11)
      CALL GVSCLF (12)
      CALL GVSCLF (13)



      CALL GVSDEL ('FOR013.DAT')
      CALL GVSDEL ('MCFJUNK.LOG')
      CALL GVSDEL ('fort.13')
      CALL GVSDEL ('FORT.13')





      RETURN
      END
      SUBROUTINE KLONKSHOW (IERR)

















      IMPLICIT      NONE
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR
      CHARACTER*80  LINE







      MCFPNT=0
      IERR=0
      CALL GVSTT6 ('?M1264')



   10 CONTINUE
         CALL GVSCTB (LINE,80)
         MCFPNT=MCFPNT+1
         READ (13,REC=MCFPNT,ERR=30) LINE
         CALL GVST6C ('?M1265',LINE,.FALSE.)
      IF (MCFPNT.LT.MCFCNT(1)) GOTO 10



      CALL GVSTT6 ('?M1266')
      MCFPNT=0
      GOTO 998



   30 CONTINUE
      CALL GVSTT6 ('?M1267')
      MCFPNT=0



  998 CONTINUE


      RETURN
      END   
      LOGICAL FUNCTION KLONKEXIST() 

















      IMPLICIT      NONE
      LOGICAL       GVFFOP







      IF (GVFFOP(13)) THEN
         KLONKEXIST=.TRUE.
      ELSE
         KLONKEXIST=.FALSE.
      END IF





      RETURN
      END   
      SUBROUTINE KLONKSTAT (TEXT)

















      IMPLICIT      NONE
      LOGICAL       GVFFOP
      CHARACTER*(*) TEXT







      IF (GVFFOP(13)) THEN
         CALL GVST6C ('?M2669',TEXT,.TRUE.)
      ELSE
         CALL GVST6C ('?M2670',TEXT,.TRUE.)
      END IF





      RETURN
      END   
      SUBROUTINE LINTOKLONK (LINEIN)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      CHARACTER*80  LINEIN










      CALL GVSSHL (LINEIN)



      MCFCNT(1)=MCFCNT(1)+1
      MCFPNT=MCFCNT(1)
      IF (KLOUNT.EQ.85) THEN






      ELSE
         WRITE (KLOUNT,REC=MCFPNT,ERR=999) LINEIN
      END IF






      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('LINTOKLONK')



  998 CONTINUE


      RETURN
      END   
