



      SUBROUTINE WIF506


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'SEARCH.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR, IAA, ISPHERE, IAT, JAT, ICNTRL
      REAL          WIFDST, SPHERE
      LOGICAL       WIFIRW, WIFIRD
      SAVE          ISPHERE
      DATA ISPHERE  /10/


      RETURN
      END
      SUBROUTINE WIF508 (TLINEIN,OLINEIN,JFT1,JFT2)





















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAKMOL.INC'
      INCLUDE       'MAPINC.INC'
      INTEGER       ISERIAL, IAT, JFT1, JFT2, IAA, IERR, ISOUP, IBND,
     +              JATARR(10), NUM, ELMZ, JAA, JAT, HASMODEL
      LOGICAL       WASTLN, WIFIRR, DIDWRITE, WIFIRA, WIF508H, 
     +              WIFIRO, WIFIRP, WIFIRL, NEEDTER, WIFISR, WIFIRI,
     +              WIFIRH, WIFISH, WIFISO, WIFIRN
      CHARACTER*4   LTC4
      CHARACTER*6   HETATM
      CHARACTER*80  LOCLIN, TLINE, OLINE
      CHARACTER*(*) TLINEIN, OLINEIN







      IF (NUMAAT.LE.0) THEN
         CALL GVSTTE ('?SOUEMP')
         GOTO 997
      END IF
      IF (JFT1.NE.0.OR.JFT2.NE.0) THEN
         IF (JFT1.GT.NUMAAT.OR.JFT2.GT.NUMAAT) THEN
            CALL GVSTTI2 ('?M1544',JFT1,JFT2)
            CALL GVSKIL
            GOTO 997
         END IF
         IF (JFT1.GT.JFT2) CALL GVSWIP (JFT1,JFT2)
      END IF



      CALL GVSCTB (LTC4,4)
      ISERIAL=0
      CALL GVSBTF (USEAT,MAXAT)
      WASTLN=.FALSE.
      CALL GVSSTX (OLINE,OLINEIN)
      CALL GVSSTX (TLINE,TLINEIN)
      CALL GVSIT0 (MASTER,12)



      CALL WIF513 (4,TLINE,WASTLN,IERR)
      IF (IERR.NE.0) GOTO 997



      CALL GETFILN (3,'?ML4GOF',OLINE,IERR)
      IF (IERR.NE.0) GOTO 997















      CALL WIF508A (IERR)
      IF (IERR.NE.0) GOTO 997
      CALL WIF508B (IERR)
      IF (IERR.NE.0) GOTO 997
      CALL WIF508C
      CALL WIF508D (IERR)
      IF (IERR.NE.0) GOTO 997
      CALL WIF508E (JFT1,JFT2,IERR)
      IF (IERR.NE.0) GOTO 997
      CALL WIF508F
      CALL WIF512 (3,4)
      CALL WIF517
      CALL WIF508G
      CALL WIF514 (WASTLN)
      IF (WIFPAR(298).NE.0) CALL GVSTT6 ('?ML4ACC')



      DO 100 ISOUP=1,NUMSOU






         DO 10 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)
            IF (WRK1TF(IAA)) THEN
               GOTO 11
            END IF
 10      CONTINUE
         GOTO 100
 11      CONTINUE
         CALL WIF516 (ISOUP)



         DIDWRITE=.FALSE.
         DO 40 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)



            IF (.NOT.WRK1TF(IAA)) GOTO 40



            IF (WIFIRR(IAA)) THEN
               CALL GVSSTX (HETATM,'ATOM  ')
            ELSE IF (WIFIRH(IAA)) THEN
               JAA=BOUND_TO(1,PNTAAS(IAA))
               IF (WIFIRI(JAA)) THEN
                  IF (WIFIRR(JAA)) THEN
                     CALL GVSSTX (HETATM,'ATOM  ')
                  END IF
               END IF
            ELSE IF (WIFIRO(IAA)) THEN
               CALL GVSSTX (HETATM,'ATOM  ')
            ELSE IF (WIFIRP(IAA)) THEN
               CALL GVSSTX (HETATM,'ATOM  ')
            ELSE
               CALL GVSSTX (HETATM,'HETATM')
            END IF



            DO 30 IAT=PNTAAS(IAA),PNTAAE(IAA)



               IF (WIFPAR(450).NE.0) THEN
                  IF (ABS(ATTVAL(IAT)).LT.0.1) GOTO 30
               END IF
               IF (USEAT(IAT)) GOTO 30
               IF (PROTON(IAT).AND.OLINE.EQ.'TAPEIN.DAT') GOTO 30



               IF (PROTON(IAT).AND.WIFPAR(945).EQ.1) THEN
                  CALL FBONDA (IAT,JATARR,10,NUM)
                  IF (NUM.EQ.1.AND.ELMZ(JATARR(1)).EQ.6) GOTO 30
               END IF



               DIDWRITE=.TRUE.
               CALL WIF509 (3,IAA,IAT,ISERIAL,HETATM,ONESA3(IAA),
     +          NUMNAM(IAA),LTC4,IERR)



               IF (WIFIRA(IAA)) THEN
                  IF (IAT.EQ.PNTAAS(IAA)+HATPRA(RESTYP(IAA))) THEN
                     DO 20 IBND=1,8
                        JAT=BOUND_TO(IBND,PNTAAS(IAA))
                        IF (JAT.NE.0) THEN
                           IF (PROTON(JAT)) THEN
                              CALL WIF509 (3,IAA,JAT,ISERIAL,HETATM,
     +                         ONESA3(IAA),NUMNAM(IAA),LTC4,IERR)
                           END IF
                        END IF
 20                  CONTINUE
                  END IF
               END IF
 30         CONTINUE




            IF (OLINE.NE.'TAPEIN.DAT') THEN
               CALL WIF511A (IAA,LTC4,ISERIAL,DIDWRITE,IERR)
            END IF
 40      CONTINUE




         IF (MODNMB(SOUADM(2,ISOUP)).NE.0.AND.NUMAAT.GT.NUMAAF) THEN
            DO 60 IAA=NUMAAF+1,NUMAAT
               IF (MODNMB(IAA).EQ.MODNMB(SOUADM(2,ISOUP))) THEN
                  DO 50 IAT=PNTAAS(IAA),PNTAAE(IAA)
                     IF (.NOT.USEAT(IAT)) THEN
                        DIDWRITE=.TRUE.
                        CALL WIF509 (3,ATIAA(IAT),IAT,ISERIAL,HETATM,
     +                   ONESA3(IAA),NUMNAM(IAA),LTC4,IERR)
                     END IF
 50               CONTINUE
               END IF
 60         CONTINUE
         END IF



         IF (WIFPAR(1425).NE.0) THEN
            IAA=SOUADM(2,ISOUP)
            IF ((WIFIRA(IAA).OR.WIFIRN(IAA)).AND.WIF508H(IAA)) THEN
               DO 80 JAA=IAA+1,NUMAAT
                  IF (.NOT.(WIFIRA(JAA).OR.WIFIRN(JAA))) THEN
                     IF (CHANAM(IAA).EQ.CHANAM(JAA)) THEN
                        IF (.NOT.WRK1TF(JAA)) GOTO 80
                        DO 70 JAT=PNTAAS(JAA),PNTAAE(JAA)
                           IF (.NOT.USEAT(JAT)) THEN
                              DIDWRITE=.TRUE.
                              CALL WIF509 (3,ATIAA(JAT),JAT,ISERIAL,
     +                         HETATM,ONESA3(JAA),NUMNAM(JAA),LTC4,IERR)
                           END IF
 70                     CONTINUE
                     END IF
                  END IF
 80            CONTINUE
            END IF
         END IF



         IF (DIDWRITE) THEN
            NEEDTER=.FALSE.
            IF (ISOUP.GE.NUMSOU) THEN 
               NEEDTER=.FALSE.
            ELSE IF (WIFISH(ISOUP)) THEN
               NEEDTER=.FALSE.
            ELSE IF (WIFISO(ISOUP)) THEN
               NEEDTER=.FALSE.
            ELSE IF (.NOT.WIFISR(ISOUP+1).AND.WIFISR(ISOUP)) THEN
               NEEDTER=.TRUE.
            ELSE IF (CHANAM(SOUADM(2,ISOUP)).EQ.
     +          CHANAM(SOUADM(1,ISOUP+1)).AND.
     +          MODNMB(SOUADM(2,ISOUP)).EQ.
     +          MODNMB(SOUADM(1,ISOUP+1))) THEN
               NEEDTER=.FALSE.
            ELSE
               NEEDTER=.TRUE.
            END IF
            IF (ISOUP.NE.NUMSOU) THEN
               IF (SOUPNT(SOUADM(1,ISOUP)).NE.SOUPNT(SOUADM(1,ISOUP+1)))
     +              NEEDTER=.TRUE.
            END IF
            IF (NEEDTER) THEN



               CALL GVSFMT ('?FMT1320')
               CALL GVSCTB (LOCLIN,80)
               ISERIAL=ISERIAL+1
               WRITE (LOCLIN,FMT,ERR=998) ISERIAL
               CALL WIF530 (3,LOCLIN,IERR)
               IF (IERR.NE.0) GOTO 998



               CALL GVSSTX (LOCLIN,'?M2382')
               IF (HASMODEL(ISOUP).GT.0.AND.WIFIRL(SOUADM(2,ISOUP)))
     +          CALL WIF530 (3,LOCLIN,IERR)
               IF (IERR.NE.0) GOTO 998
            END IF
         END IF
  100 CONTINUE



      IF (WIFPAR(450).NE.0) GOTO 997





      CALL WIF520



      CALL GVSFMT ('?FMT772')
      CALL GVSCTB (LINE,80)
      WRITE (LINE,FMT,ERR=998) MASTER
      CALL WIF530 (3,LINE,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSSTX (LOCLIN,'?M2383')
      CALL WIF530 (3,LOCLIN,IERR)
      IF (IERR.NE.0) GOTO 998



      IF (WIFPAR(1057).NE.2) CALL GVSRT0 (ATTVAL,MAXAT)
      GOTO 997



  998 CONTINUE
      CALL GVSTTE ('?M1030')



  997 CONTINUE
      CALL GVSCLF (3)
      CALL GVSCLF (4)


      RETURN
      END
      SUBROUTINE WIF509 (NUMUNT,IAA,IAT,ISERIAL,HETATM,CHA4IN,CH4IN,
     + LTC4,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       NUMUNT, IAA, IAT, ISERIAL, IERR
      CHARACTER*4   CH4IN, CHA4IN, LTC4
      CHARACTER*6   HETATM







      CALL WIF509A (NUMUNT,IAA,IAT,ISERIAL,HETATM,CHA4IN,CH4IN,
     + LTC4,IERR)




         IF (WIFPAR(366).EQ.0.AND.USEALT.AND.ALTATM(IAT).NE.' ') THEN
            CALL ALT007 (IAT,IERR)
            IF (IERR.EQ.0) THEN
               USEAT(IAT)=.FALSE.
               CALL WIF509A (NUMUNT,IAA,IAT,ISERIAL,HETATM,CHA4IN,CH4IN,
     +          LTC4,IERR)
            END IF
            CALL ALT007 (IAT,IERR)
            USEAT(IAT)=.TRUE.
         END IF






      RETURN
      END   
      SUBROUTINE WIF509A (NUMUNT,IAA,IAT,ISERIAL,HETATM,CHA4IN,CH4IN,
     + LTC4,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'ANATRA.INC'
      INCLUDE       'ANISOU.INC'
      INCLUDE       'ESPACE.INC'
      INCLUDE       'GRPINC.INC'
      INCLUDE       'SEARCH.INC'
      INTEGER       ISERIAL, IAT, IAA, ICYS, IERR, NUMUNT, JAA, I, J,
     +              GVFSCP, GVFPOS
      LOGICAL       WIFIRW, WIFIRI, WIFIRO, WIFITI, GVFISN, NUC1LC, 
     +              T54EQUAL, GVFIBN, CH4EQCH4, WIFIR1, WIFIR3, WIFIRA
      CHARACTER*1   CHALOC, CHAR, ALTOUT, INSOUT
      CHARACTER*2   AATTYP
      CHARACTER*4   CH4IN, CHA4IN, LONESAT, LONESA3, LNUMNAM, LTC4, T4,
     +              LSTNNM
      CHARACTER*6   HETATM
      SAVE          LSTNNM








      IF (WIFPAR(1002).NE.0) THEN
         IF (.NOT.ROW1(IAT)) THEN
            IERR=0
            GOTO 998
         END IF
      END IF



      IF (WIFPAR(108).NE.0.AND.PROTON(IAT)) THEN
         IERR=0
         GOTO 998
      END IF



      IF (WIFPAR(1057).EQ.1.OR.WIFPAR(1057).EQ.2) THEN
         IF (GVFSCP(ONESA3(IAA),'ARG',IERR).EQ.0.AND.
     +    T54EQUAL(ONESAT(IAT),' HE ')) GOTO 10
      END IF



      IF (.NOT.ISATOK(IAT).AND.PROTON(IAT)) THEN
         IERR=0
         GOTO 998
      END IF
      IF (.NOT.ISATOK(IAT).AND.WIFPAR(87).GT.0) THEN
         IERR=0
         GOTO 998
      END IF



      IF (WIFPAR(1296).NE.0) THEN
         IF (ONESAT(IAT)(1:2).EQ.' H'.AND.ONESAT(IAT)(3:3).EQ.''''.AND.
     +       ONESAT(IAT)(4:4).EQ.'''') THEN
            IERR=0
            GOTO 998
         END IF
      END IF



   10 CONTINUE
      IF (USEAT(IAT)) THEN
         IERR=0
         GOTO 998
      END IF



      IERR=0



      CALL GVSSTX (LONESA3,CHA4IN)
      CALL GVSSTX (LNUMNAM,CH4IN)
      LONESAT=T4(ONESAT(IAT))



      IF (NUC1LC(IAA)) CALL COMNUC (LONESA3)



      IF (WIFIRW(IAA)) THEN
         CALL GVSSTX (LNUMNAM,ORGNAM(IAT)(1:4))
         CALL GVSSHR (LNUMNAM,4)
         IF (WIFPAR(1425).EQ.0) THEN
            IF (.NOT.PROTON(IAT)) CALL GVSSTX (LONESAT,' O  ')
         ELSE
            IF (.NOT.PROTON(IAT)) CALL GVSSTX (LONESAT,' OW ')
         END IF
         IF (.NOT.PROTON(IAT)) CALL GVSSTX (LSTNNM,LNUMNAM)
         IF (PROTON(IAT)) THEN
            CALL GVSSTX (LNUMNAM,LSTNNM)
            IF (WIFPAR(1425).NE.0) THEN
               IF (GVFPOS(LONESAT,'1').GT.0)CALL GVSSTX(LONESAT,' HW1')
               IF (GVFPOS(LONESAT,'2').GT.0)CALL GVSSTX(LONESAT,' HW2')
            END IF
         END IF



      ELSE
         IF (RESTYP(IAA).GT.0.AND.GVFIBN(IAT,PNTAAS(IAA),PNTAAE(IAA))) 
     +       THEN
         ELSE
            IF (ONESAT(IAT)(5:5).NE.' ') THEN
               LONESAT=T4(ONESAT(IAT))
            ELSE
               CALL GVSSTX (LONESAT,ONESAT(IAT)(1:4))
            END IF
         END IF
      END IF



      IF (WIFIRO(IAA)) THEN
         IF (WIFITI(BOUND_TO(1,PNTAAS(IAA)))) THEN
            JAA=ATIAA(BOUND_TO(1,PNTAAS(IAA)))
            IF (WIFIRI(JAA)) LNUMNAM=NUMNAM(JAA)
         END IF
      END IF



      IF (RESTYP(IAA).EQ.2.AND.PROTON(IAT).AND.
     +    IAT.EQ.PNTAAE(IAA)) THEN
         IF (NUMCYS.GT.0) THEN
            DO 48 ICYS=1,NUMCYS
               IF (CYSCYS(1,ICYS).EQ.IAA.OR.
     +         CYSCYS(2,ICYS).EQ.IAA) GOTO 998
   48       CONTINUE
         END IF  
      END IF



      IF (WIFPAR(1296).NE.0) THEN
         IF (WIFIR1(ATIAA(IAT))) THEN
            IF (CH4EQCH4(LONESAT,' H  ').OR.CH4EQCH4(LONESAT,' H1 ')) 
     +          THEN
               J=BOUND_TO(1,PNTAAS(IAA))
               IF (J.NE.0) THEN
                  IF (.NOT.PROTON(J)) THEN
                     CALL GVSSTX (LONESAT,' H  ')
                  END IF
               END IF
            END IF
         END IF
      END IF










      IF (WIFIR3(IAA)) THEN
         IF (WIFIRA(IAA).AND.IAT.EQ.PNTAAS(IAA)+3) THEN
            CALL GVSSTX (LONESAT,' O  ')
            IF (WIFPAR(1103).EQ.3) THEN
               LONESAT(3:3)=''''
            ELSE IF (WIFPAR(1103).EQ.4) THEN
               CALL GVSSTX (LONESAT,' O1 ')
            END IF
         ELSE IF (WIFIRO(IAA)) THEN
            IF (WIFPAR(1103).EQ.0) THEN
               CALL GVSSTX (LONESAT,' OXT')
            ELSE IF (WIFPAR(1103).EQ.1) THEN
               CALL GVSSTX (LONESAT,' O  ')
            ELSE IF (WIFPAR(1103).EQ.2) THEN
               CALL GVSSTX (LONESAT,' O2 ')
            ELSE IF (WIFPAR(1103).EQ.3) THEN
               CALL GVSSTX (LONESAT,' O  ')
               LONESAT(3:3)=''''
               LONESAT(4:4)=''''
            ELSE IF (WIFPAR(1103).EQ.4) THEN
               CALL GVSSTX (LONESAT,' O2 ')
            END IF
         END IF
      END IF






      CALL GVSSHR (LNUMNAM,4)
      CHALOC=CHANAM(IAA)
      IF (CHALOC.EQ.'+') CHALOC=' '
      IF (WIFPAR(490).EQ.0) THEN
         ISERIAL=ISERIAL+1
      ELSE
         ISERIAL=PDBNUM(IAT)
      END IF
      ATTVAL(IAT)=FLOAT(ISERIAL)
      USEAT(IAT)=.TRUE.
      IF (WIFPAR(366).NE.0) THEN
         INSOUT=' '
         ALTOUT=' '
      ELSE
         INSOUT=INSRTC(IAA)
         ALTOUT=ALTATM(IAT)
      END IF





      IF (WIFPAR(1057).EQ.1) THEN

















         CALL GVSFMT ('?FMT498C')
         WRITE (LINE,FMT,ERR=999) HETATM,ISERIAL,LONESAT,LONESA3,
     +    CHALOC,LNUMNAM,INSOUT,ALTOUT,XCOORD(IAT),YCOORD(IAT),
     +    ZCOORD(IAT),WEIGHT(IAT),XBFACT(IAT),LTC4,MENDLV(IAT)
         LINE(79:80)='  '
         CALL WIF530 (NUMUNT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999



      ELSE IF (WIFPAR(1057).EQ.2) THEN
         IF (GVFISN(LONESAT(1:1))) THEN
            CHAR=LONESAT(1:1)
            LONESAT(1:3)=LONESAT(2:4)
            LONESAT(4:4)=CHAR
            CALL GVSTCP (LONESAT)
         END IF 
         CALL GVSFMT ('?FMT498')
         WRITE (LINE,FMT,ERR=999) HETATM,ISERIAL,LONESAT,ALTOUT,
     +    LONESA3,CHALOC,LNUMNAM,INSOUT,XCOORD(IAT),YCOORD(IAT),
     +    ZCOORD(IAT),WEIGHT(IAT),XBFACT(IAT),LTC4,MENDLV(IAT)
         LINE(79:80)='  '
         CALL WIF530 (NUMUNT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999



      ELSE IF (WIFPAR(1057).EQ.3) THEN
         CALL SETADT (IAT,AATTYP)
         CALL GVSFMT ('?FMT498H')
         WRITE (LINE,FMT,ERR=999) HETATM,ISERIAL,LONESAT,ALTOUT,
     +    LONESA3,CHALOC,LNUMNAM,INSOUT,XCOORD(IAT),YCOORD(IAT),
     +    ZCOORD(IAT),WEIGHT(IAT),XBFACT(IAT),ATTVAL(IAT),AATTYP
         CALL WIF530 (NUMUNT,LINE,IERR)
         IF (IERR.NE.0) GOTO 999




      ELSE
         IF (WIFPAR(298).EQ.0) THEN
            IF (WIFPAR(282).NE.0) THEN
               IF (.NOT.WIFIRW(IAA)) THEN
                  CALL GVSSTX (LONESAT,ORGNAM(IAT))
               END IF
            END IF
            CALL GVSFMT ('?FMT498')
            WRITE (LINE,FMT,ERR=999) HETATM,ISERIAL,LONESAT,
     +       ALTOUT,LONESA3,CHALOC,LNUMNAM,INSOUT,
     +       XCOORD(IAT),YCOORD(IAT),ZCOORD(IAT),WEIGHT(IAT),
     +       XBFACT(IAT),LTC4,MENDLV(IAT)
            LINE(79:80)='  '
            CALL WIF530 (NUMUNT,LINE,IERR)
           IF (IERR.NE.0) GOTO 999
         ELSE
            CALL GVSFMT ('?FMT498A')
            WRITE (LINE,FMT,ERR=999) HETATM,ISERIAL,LONESAT,
     +       ALTOUT,LONESA3,CHALOC,LNUMNAM,INSOUT,
     +       XCOORD(IAT),YCOORD(IAT),ZCOORD(IAT),WEIGHT(IAT),
     +       XBFACT(IAT),ACCESS(IAT),LTC4,MENDLV(IAT)
            LINE(79:80)='  '
            CALL WIF530 (NUMUNT,LINE,IERR)
            IF (IERR.NE.0) GOTO 999
         END IF
         IF (USEANI) THEN
            CALL GVSFMT ('?FMT498B')
            WRITE (LINE,FMT,ERR=999) ISERIAL,LONESAT,ALTOUT,
     +       LONESA3,CHALOC,LNUMNAM,INSOUT,
     +       (NINT(10000.0*ANISOU(I,IAT)),I=1,6),MENDLV(IAT)
            LINE(79:80)='  '
            CALL WIF530 (NUMUNT,LINE,IERR)
         END IF
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSTTE ('?M1306')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE SETADT (IAT,CHAR2)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'REFINC.INC'
      INCLUDE       'HBONDS.INC'
      INCLUDE       'AUDOCK.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IAT, IAA, JAT, NUM, AD_ATN
      LOGICAL       GVFIBN
      CHARACTER*2   CHAR2







      CALL GVSCTB (CHAR2,2)
      IAA=ATIAA(IAT)
      AD_ATN=0


























      IF (PROTON(IAT)) THEN
         CALL FBONDAOK (IAT,JAT,1,NUM)
         IF (NUM.LE.0) GOTO 999
         IF (HBOPOS(RESTYP(ATIAA(IAT)),PINIAA(IAT))) THEN
            CALL GVSSTX (CHAR2,'HD')
            AD_ATN=3
            GOTO 998
         ELSE
            CALL GVSSTX (CHAR2,'H ')
            AD_ATN=4
            GOTO 998
         END IF





         IF (RESTYP(IAA).EQ.2) THEN
            IF (IAT.EQ.PNTAAS(IAA)+10) THEN
               CALL GVSSTX (CHAR2,'HD')
               AD_ATN=3
               GOTO 998
            END IF
         END IF



      ELSE IF (ONESAT(IAT)(1:2).EQ.' F') THEN
         CALL GVSSTX (CHAR2,'F ')
         AD_ATN=9
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.'MG') THEN
         CALL GVSSTX (CHAR2,'MG')
         AD_ATN=10
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.'CA') THEN
         CALL GVSSTX (CHAR2,'CA')
         AD_ATN=11
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.'MN') THEN
         CALL GVSSTX (CHAR2,'MN')
         AD_ATN=12
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.'FE') THEN
         CALL GVSSTX (CHAR2,'FE')
         AD_ATN=13
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.'ZN') THEN
         CALL GVSSTX (CHAR2,'ZN')
         AD_ATN=14
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.' P') THEN
         CALL GVSSTX (CHAR2,'P ')
         AD_ATN=15
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.'CL') THEN
         CALL GVSSTX (CHAR2,'CL')
         AD_ATN=16
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.'BR') THEN
         CALL GVSSTX (CHAR2,'BR')
         AD_ATN=17
         GOTO 998
      ELSE IF (ONESAT(IAT)(1:2).EQ.' I') THEN
         CALL GVSSTX (CHAR2,'I ')
         AD_ATN=18
         GOTO 998
      END IF



      IF (GVFIBN(RESTYP(IAA),1,20)) THEN



         IF (RESTYP(IAA).EQ.7) THEN



            IF (IAT.EQ.PNTAAS(IAA)+6) THEN
               IF (ISATOK(PNTAAS(IAA)+14)) THEN
                  CALL GVSSTX (CHAR2,'N ')
                  AD_ATN=5
                  GOTO 998
               ELSE
                  CALL GVSSTX (CHAR2,'NA')
                  AD_ATN=6
                  GOTO 998
               END IF



            ELSE IF (IAT.EQ.PNTAAS(IAA)+8) THEN
               IF (ISATOK(PNTAAS(IAA)+17)) THEN
                  CALL GVSSTX (CHAR2,'N ')
                  AD_ATN=5
                  GOTO 998
               ELSE
                  CALL GVSSTX (CHAR2,'NA')
                  AD_ATN=6
                  GOTO 998
               END IF
            END IF
         END IF



         IF (RESTYP(IAA).EQ.2) THEN



            IF (IAT.EQ.PNTAAS(IAA)+5) THEN
               CALL GVSSTX (CHAR2,'SA')
               AD_ATN=8
               GOTO 998
            END IF



         ELSE IF (RESTYP(IAA).EQ.11) THEN
            IF (IAT.EQ.PNTAAS(IAA)+6) THEN
               CALL GVSSTX (CHAR2,'S ')
               AD_ATN=19
               GOTO 998
            END IF
         END IF
      END IF





      IF (ONESAT(IAT)(1:2).EQ.' C') THEN
         IF (PLANAR(PINIAA(IAT),1,RESTYP(IAA)).OR.
     +       PLANAR(PINIAA(IAT),2,RESTYP(IAA)).OR.
     +       PLANAR(PINIAA(IAT),3,RESTYP(IAA)).OR.
     +       PLANAR(PINIAA(IAT),4,RESTYP(IAA)).OR.
     +       PLANAR(PINIAA(IAT),5,RESTYP(IAA))) THEN
            CALL GVSSTX (CHAR2,'A ')
            AD_ATN=1
            GOTO 998
         ELSE
            CALL GVSSTX (CHAR2,'C ')
            AD_ATN=2
            GOTO 998
         END IF




      ELSE IF (ONESAT(IAT)(1:2).EQ.' N') THEN
         CALL GVSSTX (CHAR2,'N ')
         AD_ATN=5
         GOTO 998



      ELSE IF (ONESAT(IAT)(1:2).EQ.' O') THEN
         CALL GVSSTX (CHAR2,'OA')
         AD_ATN=7
         GOTO 998
      END IF



      CALL GVST6C ('Atom type forgotten:',ONESAT(IAT),.TRUE.)
      CALL SHOIAA (IAA)
      CALL GVSCODA ('Sukkel')
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('SETADT')



  998 CONTINUE
      IF (AD_ATN.EQ.0) THEN
         CALL GVST6C ('Atom type determination error for:',ONESAT(IAT),
     +    .TRUE.)
         CALL SHOIAA (ATIAA(IAT))
      ELSE
         IF (.NOT.AD_ATL(AD_ATN)) THEN
            AD_ATL(AD_ATN)=.TRUE.

         END IF
      END IF


      RETURN
      END   
      LOGICAL FUNCTION NUC1LC(IAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, IAT, JAA, JAT, IBND, GVFPOS
      LOGICAL       WIFIRN, WIFIRH, WIFIRE, WIFIRO







      NUC1LC=.FALSE.



      IF (WIFIRN(IAA)) THEN
         NUC1LC=.TRUE.
         GOTO 998
      END IF
      IF (GVFPOS('DADE DCYT DTHY DCYG OADE OCYT OURA OCYG',
     +    ONESA3(IAA)).NE.0) THEN
         NUC1LC=.TRUE.
         GOTO 998
      END IF



      IF (WIFIRH(IAA).OR.WIFIRO(IAA).OR.WIFIRE(IAA)) THEN
         DO 20 IAT=PNTAAS(IAA),PNTAAE(IAA)
            DO 10 IBND=1,8
               JAT=BOUND_TO(IBND,IAT)
               IF (JAT.NE.0) THEN
                  JAA=ATIAA(JAT)
                  IF (WIFIRN(JAA)) THEN
                     NUC1LC=.TRUE.
                     GOTO 998
                  END IF
               END IF
   10       CONTINUE
   20    CONTINUE
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF511A (IAA,LTC4,ISERIAL,DIDWRITE,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA, IAT, IBND, JAT, ISERIAL, IERR, KAA
      LOGICAL       DIDWRITE, WIFIRO, WIFIRH, GVFIBN, ISMETAL
      CHARACTER*6   HETATM
      CHARACTER*4   LTC4







      IERR=0
      DO 80 IAT=PNTAAS(IAA),PNTAAE(IAA)
         DO 75 IBND=1,8



            JAT=BOUND_TO(IBND,IAT)
            IF (.NOT.GVFIBN(JAT,1,NUMATF)) GOTO 75
            JAA=ATIAA(JAT)
            IF (.NOT.WRK1TF(JAA).AND.WIFPAR(1820).NE.0.AND.
     +       WIFPAR(1425).NE.0) GOTO 75



            IF (USEAT(JAT)) GOTO 75
            IF (SOUADM(4,CHAINN(2,ATIAA(JAT))).GT.4) GOTO 75
            IF (ISMETAL(JAT)) GOTO 75
            IF (.NOT.ISATOK(JAT)) GOTO 75



            DO 70 JAT=PNTAAS(JAA),PNTAAE(JAA)
               IF (WIFIRO(JAA)) THEN
                  CALL GVSSTX (HETATM,'ATOM  ')
               ELSE IF (WIFIRH(JAA)) THEN
                  CALL GVSSTX (HETATM,'ATOM  ')
               ELSE
                  CALL GVSSTX (HETATM,'HETATM')
               END IF
               DIDWRITE=.TRUE.
               KAA=ATIAA(JAT)
               CALL WIF509 (3,ATIAA(JAT),JAT,ISERIAL,HETATM,
     +          ONESA3(KAA),NUMNAM(KAA),LTC4,IERR)
 70         CONTINUE
            CALL WIF511B (JAA,LTC4,ISERIAL,DIDWRITE,IERR)
 75      CONTINUE
 80   CONTINUE





      RETURN
      END   
      SUBROUTINE WIF511B (IAA,LTC4,ISERIAL,DIDWRITE,IERR)



















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA, IAT, IBND, JAT, ISERIAL, IERR, KAA
      LOGICAL       DIDWRITE, WIFIRO, WIFIRH, GVFIBN, ISMETAL
      CHARACTER*6   HETATM
      CHARACTER*4   LTC4







      IERR=0
      DO 80 IAT=PNTAAS(IAA),PNTAAE(IAA)
         DO 75 IBND=1,8



            JAT=BOUND_TO(IBND,IAT)
            IF (.NOT.GVFIBN(JAT,1,NUMATF)) GOTO 75



            IF (USEAT(JAT)) GOTO 75
            IF (SOUADM(4,CHAINN(2,ATIAA(JAT))).GT.4) GOTO 75
            IF (ISMETAL(JAT)) GOTO 75



            JAA=ATIAA(JAT)
            DO 70 JAT=PNTAAS(JAA),PNTAAE(JAA)
               IF (WIFIRO(JAA)) THEN
                  CALL GVSSTX (HETATM,'ATOM  ')
               ELSE IF (WIFIRH(JAA)) THEN
                  CALL GVSSTX (HETATM,'ATOM  ')
               ELSE
                  CALL GVSSTX (HETATM,'HETATM')
               END IF
               DIDWRITE=.TRUE.
               KAA=ATIAA(JAT)
               CALL WIF509 (3,ATIAA(JAT),JAT,ISERIAL,HETATM,
     +          ONESA3(KAA),NUMNAM(KAA),LTC4,IERR)
 70         CONTINUE
            CALL WIF511A (JAA,LTC4,ISERIAL,DIDWRITE,IERR)
 75      CONTINUE
 80   CONTINUE





      RETURN
      END   
      SUBROUTINE WIF512 (OUNIT,IUNIT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAKMOL.INC'
      INCLUDE       'MAPINC.INC'
      INTEGER       IERR, IUNIT, OUNIT
      CHARACTER*80  LOCLIN
      LOGICAL       GVFFOP, SSBOND







      IF (.NOT.GVFFOP(IUNIT)) THEN
         CALL GVSTTE ('?M1887')
         GOTO 998
      END IF
      IF (.NOT.GVFFOP(OUNIT)) THEN
         CALL GVSTTE ('?M1887A')
         GOTO 998
      END IF



      IF (WIFPAR(1057).EQ.3) GOTO 998



      SSBOND=.FALSE.



 10   CONTINUE
         CALL GVSFMT ('?FMT111')
         READ (IUNIT,FMT,END=998,ERR=999) LOCLIN




         IF (LOCLIN(1:6).EQ.'CRYST1'.OR.LOCLIN(1:5).EQ.'SCALE') THEN
            IF (.NOT.SSBOND) THEN
               CALL WIF515
               SSBOND=.TRUE.
            END IF
            CALL WIF512A (OUNIT,LOCLIN)



         ELSE IF (LOCLIN(1:6).EQ.'SSBOND') THEN
            IF (.NOT.SSBOND) THEN
               CALL WIF515
               SSBOND=.TRUE.
            END IF



         ELSE IF (LOCLIN(1:4).EQ.'ATOM'.OR.LOCLIN(1:6).EQ.'HETATM'.OR.
     +       LOCLIN(1:5).EQ.'MODEL'.OR.LOCLIN(1:6).EQ.'ENDMDL') THEN
            GOTO 998



         ELSE
            CALL WIF530 (OUNIT,LOCLIN,IERR)
            IF (IERR.NE.0) GOTO 998
         END IF
      GOTO 10



  999 CONTINUE
      CALL GVSEIW ('WIF512')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF512A (OUNIT,LOCLIN)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAKMOL.INC'
      INCLUDE       'MAPINC.INC'
      INTEGER       IERR, OUNIT
      CHARACTER*80  LOCLIN







      IF (WIFPAR(191).NE.0) THEN
         CALL GVSFMT ('?FMT631')
         CALL GVSCTB (LINE,80)
         WRITE (LINE,FMT,ERR=998) ACELLM(WIFPAR(191)),
     +    BCELLM(WIFPAR(191)),CCELLM(WIFPAR(191)),ALPHAM(WIFPAR(191)),
     +    BETAM(WIFPAR(191)),GAMMAM(WIFPAR(191))
         CALL WIF530 (OUNIT,LINE,IERR)
         IF (IERR.NE.0) GOTO 998





      ELSE
         IF (WIFPAR(1085).EQ.1.AND.WIFPAR(100).NE.0) THEN
            IF (LOCLIN(1:6).EQ.'CRYST1') THEN
               CALL WIF530 (OUNIT,CRYCRD(WIFPAR(100)),IERR)
               IF (IERR.NE.0) GOTO 998
            ELSE IF (LOCLIN(1:6).EQ.'SCALE1') THEN
               CALL WIF530 (OUNIT,SCLCR1(WIFPAR(100)),IERR)
               IF (IERR.NE.0) GOTO 998
            ELSE IF (LOCLIN(1:6).EQ.'SCALE2') THEN
               CALL WIF530 (OUNIT,SCLCR2(WIFPAR(100)),IERR)
               IF (IERR.NE.0) GOTO 998
            ELSE IF (LOCLIN(1:6).EQ.'SCALE3') THEN
               CALL WIF530 (OUNIT,SCLCR3(WIFPAR(100)),IERR)
               IF (IERR.NE.0) GOTO 998
            ELSE
               CALL GVSTT6 ('?M3060')
            END IF
         ELSE
            CALL WIF530 (OUNIT,LOCLIN,IERR)
            IF (IERR.NE.0) GOTO 998
         END IF
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF513 (IUNIT,TLINE,WASTLN,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN, IUNIT
      CHARACTER*80  LOCLIN
      CHARACTER*(*) TLINE
      LOGICAL       WASTLN







      IF (WIFPAR(1201).NE.-1) THEN

            CALL GVSCCC (LOCLIN,WHERIS,'DUMMY.HED')

      ELSE
         CALL GVSCCC (LOCLIN,WHERIS,'DUMMY.HED')
      END IF
      CALL GETFILE (IUNIT,' ',LOCLIN,IERR)
      CALL GVSSTX (TLINE,LOCLIN)



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF514 (WASTLN)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR, GVFLEN
      LOGICAL       WASTLN
      CHARACTER*80  LOCLIN, LOCLN2







      IF (WIFPAR(1201).NE.-1) THEN

      END IF



 100  CONTINUE






      RETURN
      END   
      SUBROUTINE WIF515

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IOUT, ICYS, IERR
      CHARACTER*1   CHA1, CHA2
      CHARACTER*4   C1, C2







      IF (NUMCYS.LE.0) GOTO 998



      IOUT=0
      IERR=0



      DO 10 ICYS=1,NUMCYS
         IF (CYSCYS(2,ICYS).GT.CYSCYS(1,ICYS)) THEN
            IF (WRK1TF(CYSCYS(1,ICYS)).AND.WRK1TF(CYSCYS(2,ICYS))) THEN
               IOUT=IOUT+1
               CALL GVSSTX (C1,NUMNAM(CYSCYS(1,ICYS)))
               CALL GVSSTX (C2,NUMNAM(CYSCYS(2,ICYS)))
               CALL GVSSHR (C1,4)
               CALL GVSSHR (C2,4)
               CHA1=CHANAM(CYSCYS(1,ICYS))
               CHA2=CHANAM(CYSCYS(2,ICYS))
               IF (CHA1.EQ.'+') CHA1=' '
               IF (CHA2.EQ.'+') CHA2=' '
               CALL GVSCTB (LINE,80)
               CALL GVSFMT ('?FMT495')
               WRITE (LINE,FMT,ERR=998) IOUT,CHA1,C1,CHA2,C2
               CALL WIF530 (3,LINE,IERR)
               IF (IERR.NE.0) GOTO 999
            END IF
         END IF
   10 CONTINUE    
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('WIF515')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF516 (ISOUP)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       HASMODEL, ISOUP, IERR
      LOGICAL       WIFIRO, WIFIRH, WIFIRL







      IF (HASMODEL(ISOUP).LE.0) GOTO 998



      IF (ISOUP.EQ.1) THEN
         CALL GVSFMT ('?FMT496')
         CALL GVSCTB (LINE,80)
         WRITE (LINE,FMT,ERR=998) HASMODEL(ISOUP)
         CALL WIF530 (3,LINE,IERR)
         IF (IERR.NE.0) GOTO 999
      ELSE
         IF (.NOT.WIFIRO(SOUADM(1,ISOUP)).AND.
     +       (.NOT.WIFIRH(SOUADM(1,ISOUP)))) THEN
            IF (WIFIRL(SOUADM(2,ISOUP-1))) THEN
               CALL GVSFMT ('?FMT496')
               CALL GVSCTB (LINE,80)
               WRITE (LINE,FMT,ERR=998) HASMODEL(ISOUP)
               CALL WIF530 (3,LINE,IERR)
               IF (IERR.NE.0) GOTO 999
            END IF
         END IF
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('WIF516')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF517

















      IMPLICIT      NONE


      RETURN
      END   
      SUBROUTINE WIF520

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'







      IF (WIFPAR(1520).LE.0) THEN
         RETURN



      ELSE IF (WIFPAR(1520).GE.1) THEN 
         CALL WIF524



      ELSE IF (WIFPAR(1520).GE.2) THEN 
         CALL WIF521



         CALL WIF523
      END IF





      RETURN
      END   
      SUBROUTINE WIF521

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'HB2INC.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IAA, IAT, IHAT, JAC, JAT, JAA, IDON, ISYM, HAT, IERR
      CHARACTER*4   T4, CHAR4H, CHAR4I, CHAR4J








      CALL HBO010
      CALL HB2RED



      DO 100 IDON=1,NUMDON
         IF (NUXYZH(IDON).GT.0) THEN
            IAT=ARIATD(IDON)
            IAA=ATIAA(IAT)
            IF (.NOT.WRK1TF(IAA)) GOTO 100
            DO 80 IHAT=INXYZH(IDON),INXYZH(IDON)+NUXYZH(IDON)-1
               DO 70 JAC=1,2
                  IF (ARIATA(JAC,IHAT).GT.0) THEN
                     JAT=ARIATA(JAC,IHAT)
                     ISYM=ARSYMA(JAC,IHAT)
                     IF (ISYM.GT.1) GOTO 70
                     JAA=ATIAA(JAT)
                     IF (.NOT.WRK1TF(JAA)) GOTO 70
                     IF (WIFPAR(84).EQ.0) THEN
                        CHAR4I=T4(ONESAT(IAT))
                        CHAR4J=T4(ONESAT(JAT))
                        CALL GVSFMT ('?FMT769')
                        CALL GVSCTB (LINE,80)
                        WRITE (LINE,FMT,ERR=999) CHAR4I,
     +                   ONESA3(IAA)(1:3),CHANAM(IAA),NUMNAM(IAA),
     +                   CHAR4J,ONESA3(JAA)(1:3),CHANAM(JAA),
     +                   NUMNAM(JAA)
                     ELSE
                        CALL WIF522 (IAT,JAT,HAT,ARXYZH(1,IHAT),
     +                   ARXYZH(2,IHAT),ARXYZH(3,IHAT))
                        CHAR4H=T4(ONESAT(HAT))
                        CHAR4I=T4(ONESAT(IAT))
                        CHAR4J=T4(ONESAT(JAT))
                        CALL GVSFMT ('?FMT770')
                        CALL GVSCTB (LINE,80)
                        WRITE (LINE,FMT,ERR=999) CHAR4I,
     +                   ONESA3(IAA)(1:3),CHANAM(IAA),NUMNAM(IAA),
     +                   CHAR4H,CHANAM(IAA),NUMNAM(IAA),CHAR4J,
     +                   ONESA3(JAA)(1:3),CHANAM(JAA),NUMNAM(JAA)
                     END IF
                     CALL WIF530 (3,LINE,IERR)
                     IF (IERR.NE.0) GOTO 999
                  END IF
 70            CONTINUE
 80         CONTINUE
         END IF
 100  CONTINUE

      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('WIF521')



  998 CONTINUE



      RETURN
      END   
      SUBROUTINE WIF522 (IATDON,IATACC,IATH,XH,YH,ZH)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IATDON, IATACC, IATH, HATARR(4), HATNUM, IAT
      REAL          WIFDST, MINDST, XH, YH, ZH, D







      IF (WIFPAR(84).EQ.0) THEN
         IATH=0
         GOTO 998
      END IF



      IATH=0



      CALL FBONDH (IATDON,HATARR,4,HATNUM)
      IF (HATNUM.LE.0) GOTO 998
      IF (HATNUM.EQ.1) THEN
         IATH=HATARR(1)
         GOTO 998
      END IF



      MINDST=9999.9
      DO 10 IAT=1,HATNUM
         D=SQRT((XCOORD(HATARR(IAT))-XH)**2+
     +          (YCOORD(HATARR(IAT))-YH)**2+
     +          (ZCOORD(HATARR(IAT))-ZH)**2)
         IF (D.LT.0.9) THEN
            IF (D.LT.MINDST) THEN
               MINDST=D
               IATH=HATARR(IAT)
            END IF
         END IF
 10   CONTINUE
      IF (IATH.NE.0.AND.MINDST.LT.0.5) THEN
         GOTO 998
      ELSE
         IATH=0
      END IF



      MINDST=9999.9
      DO 20 IAT=1,HATNUM
         IF (WIFDST(HATARR(IAT),IATACC).LT.MINDST) THEN
            MINDST=WIFDST(HATARR(IAT),IATACC)
            IATH=HATARR(IAT)
         END IF
 20   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF523

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA, IAT1, IAT2, IATP, JATP, IERR
      LOGICAL       WIFIRA
      REAL          WIFDST
      CHARACTER*4   T4, CHAR4I, CHAR4J







      DO 100 IAA=1,NUMAAF
         IF (.NOT.WIFIRA(IAA)) GOTO 100
         IF (RESTYP(IAA).NE.3.AND.RESTYP(IAA).NE.4) GOTO 100



         DO 90 JAA=1,NUMAAF
            IF (.NOT.WIFIRA(JAA)) GOTO 90
            IF (IAA.EQ.JAA) GOTO 90
            IF (RESTYP(JAA).NE.9.AND.RESTYP(JAA).NE.15) GOTO 90



            DO 80 IAT1=1,2
               IF (RESTYP(IAA).EQ.4) THEN
                  IATP=PNTAAS(IAA)+6+IAT1
               ELSE
                  IATP=PNTAAS(IAA)+5+IAT1
               END IF



               DO 70 IAT2=1,2
                  IF (RESTYP(JAA).EQ.15) THEN
                     JATP=PNTAAS(JAA)+8+IAT2
                  ELSE
                     IF (IAT2.EQ.2) GOTO 70
                     JATP=PNTAAS(JAA)+8
                  END IF



                  IF (WIFDST(IATP,JATP).LE.6.0) THEN 
                     CHAR4I=T4(ONESAT(IATP))
                     CHAR4J=T4(ONESAT(JATP))
                     CALL GVSFMT ('?FMT771')
                     CALL GVSCTB (LINE,80)
                     WRITE (LINE,FMT,ERR=999) CHAR4I,ONESA3(IAA)(1:3),
     +                CHANAM(IAA),NUMNAM(IAA),CHAR4J,
     +                    ONESA3(JAA)(1:3),CHANAM(JAA),NUMNAM(JAA)
                     CALL WIF530 (3,LINE,IERR)
                     IF (IERR.NE.0) GOTO 999
                  END IF
   70          CONTINUE
   80       CONTINUE
   90    CONTINUE
  100 CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL523')



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF524

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ISOUP, IAA, IAT, IB1, IB2, IB3, IB4, IATCON, IBND,
     +              ICYS, JAA, JAT, JAT1, JAT2
      LOGICAL       WIFISR, WIFISW







      DO 100 ISOUP=1,NUMSOU



         IF (WIFISW(ISOUP)) GOTO 100



         IF (SOUADM(5,ISOUP).EQ.4) THEN
            IAT=PNTAAS(SOUADM(1,ISOUP))

            IF (BOUND_TO(1,IAT).NE.0) THEN
               IF (BOUND_TO(2,IAT).NE.0) THEN
                  CALL MOL524A (IAT,BOUND_TO(1,IAT),BOUND_TO(2,IAT),0,0)
               ELSE
                  CALL MOL524A (IAT,BOUND_TO(1,IAT),0,0,0)
               END IF
            END IF
         END IF



         IF (SOUADM(5,ISOUP).EQ.2.OR.SOUADM(5,ISOUP).EQ.6) THEN
            IAA=SOUADM(1,ISOUP)
            DO 30 IAT=PNTAAS(IAA),PNTAAE(IAA)
               IB1=0
               IB2=0
               IB3=0
               IB4=0



               IF (RESTYP(IAA).GT.0) THEN
                  DO 10 IATCON=1,MAXTAT
                     JAT1=MUTCON(1,IATCON,RESTYP(IAA))
                     JAT2=MUTCON(2,IATCON,RESTYP(IAA))
                     IF (JAT1.NE.0) THEN
                        IF (JAT1.EQ.IAT) THEN
                           IF (IB1.EQ.0) THEN
                              IB1=JAT2
                           ELSE IF (IB2.EQ.0) THEN
                              IB2=JAT2
                           ELSE IF (IB3.EQ.0) THEN
                              IB3=JAT2
                           ELSE IF (IB4.EQ.0) THEN
                              IB4=JAT2
                           ELSE
                              CALL GVSTTE ('?M2376')
                           END IF
                        END IF       
                     END IF
 10               CONTINUE



               ELSE
                  DO 20 IBND=1,8
                     JAT=BOUND_TO(IBND,IAT)
                     IF (JAT.GT.0) THEN
                        IF (IB1.EQ.0) THEN
                           IB1=IAT
                        ELSE IF (IB2.EQ.0) THEN
                           IB2=JAT
                        ELSE IF (IB3.EQ.0) THEN
                           IB3=JAT
                        ELSE IF (IB4.EQ.0) THEN
                           IB4=IAT
                        ELSE
                           CALL GVSTTE ('?M2376')
                        END IF
                     END IF       
 20               CONTINUE
               END IF



               IF (IB1.NE.0) CALL MOL524A (IAT,IB1,IB2,IB3,IB4)





               IF (BOUND_TO(1,IAT).NE.0) THEN
                  IF (BOUND_TO(2,IAT).NE.0) THEN
                     CALL MOL524A (IAT,BOUND_TO(1,IAT),BOUND_TO(2,IAT),
     +                0,0)
                  ELSE
                     CALL MOL524A (IAT,BOUND_TO(1,IAT),0,0,0)
                  END IF
               END IF
 30         CONTINUE
         END IF



         IF (WIFISR(ISOUP)) THEN
            DO 50 IAA=SOUADM(1,ISOUP),SOUADM(2,ISOUP)





               DO 40 IAT=PNTAAS(IAA),PNTAAE(IAA)
                  IF (BOUND_TO(1,IAT).NE.0) THEN
                     IF (BOUND_TO(2,IAT).NE.0) THEN
                        CALL MOL524A (IAT,BOUND_TO(1,IAT),
     +                   BOUND_TO(2,IAT),0,0)
                     ELSE
                        CALL MOL524A (IAT,BOUND_TO(1,IAT),0,0,0)
                     END IF
                  END IF
 40            CONTINUE
 50         CONTINUE
         END IF



         DO 60 ICYS=1,NUMCYS
            IAA=CYSCYS(1,ICYS)
            JAA=CYSCYS(2,ICYS)
            CALL MOL524A (PNTAAS(IAA)+5,PNTAAS(JAA)+5,0,0,0)
 60      CONTINUE
 100  CONTINUE





      RETURN
      END   
      SUBROUTINE MOL524A (IAT,IB1,IB2,IB3,IB4)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, IB1, IB2, IB3, IB4, IERR







      CALL GVSFMT ('?FMT421A')
      CALL GVSCTB (LINE,80)
      IF (IB4.NE.0) THEN
         WRITE (LINE,FMT,ERR=999) IAT,IB1,IB2,IB3,IB4
      ELSE IF (IB3.NE.0) THEN
         WRITE (LINE,FMT,ERR=999) IAT,IB1,IB2,IB3
      ELSE IF (IB2.NE.0) THEN
         WRITE (LINE,FMT,ERR=999) IAT,IB1,IB2
      ELSE IF (IB1.NE.0) THEN
         WRITE (LINE,FMT,ERR=999) IAT,IB1
      ELSE
         CALL GVSTTE ('?M2375')
      END IF
      CALL WIF530 (3,LINE,IERR)
      IF (IERR.NE.0) GOTO 999
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL524A')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE COMNUC(LONESA3)




















      IMPLICIT      NONE
      CHARACTER*4   LONESA3







      IF (LONESA3.EQ.'DADE') CALL GVSSTX (LONESA3,' DA ')
      IF (LONESA3.EQ.'DCYT') CALL GVSSTX (LONESA3,' DC ')
      IF (LONESA3.EQ.'DGUA') CALL GVSSTX (LONESA3,' DG ')
      IF (LONESA3.EQ.'DTHY') CALL GVSSTX (LONESA3,' DT ')
      IF (LONESA3.EQ.'OADE') CALL GVSSTX (LONESA3,'  A ')
      IF (LONESA3.EQ.'OCYT') CALL GVSSTX (LONESA3,'  C ')
      IF (LONESA3.EQ.'OGUA') CALL GVSSTX (LONESA3,'  G ')
      IF (LONESA3.EQ.'OURA') CALL GVSSTX (LONESA3,'  U ')
      IF (LONESA3.EQ.'OINO') CALL GVSSTX (LONESA3,'  I ')





      RETURN
      END
      SUBROUTINE WIF530 (IUNIT,LINEIN,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAKMOL.INC'
      INTEGER       IUNIT, IERR, GVFLEN

      LOGICAL       FIRST
      CHARACTER*80  LOCLIN, LINEIN, LSTLIN
      DATA FIRST    /.TRUE./







      IERR=0
      CALL GVSSTX (LOCLIN,LINEIN)
      IF (FIRST) THEN
         FIRST=.FALSE.
         CALL GVSCTB (LSTLIN,80)
      END IF








      IF (GVFLEN(LINEIN).LT.3) THEN
         IF (WIFPAR(1012).EQ.1) THEN
            CALL GVSTTB ('?M2377')
            CALL GVSTT6 (LOCLIN)
            CALL GVSKIL
            IERR=1
         END IF
         GOTO 998
      END IF
      IF (LINEIN(1:4).EQ.'TER '.AND.LSTLIN(1:4).EQ.'TER ') GOTO 998




      IF (WIFPAR(450).NE.0.AND.WIFPAR(451).NE.0) THEN
         CALL GVSTTU (WIFPAR(451),LOCLIN)
      ELSE
         CALL GVSTTU (IUNIT,LOCLIN)
      END IF
      CALL GVSSTX (LSTLIN,LOCLIN)



      IF (LOCLIN(1:6).EQ.'REMARK') THEN
         MASTER(1)=MASTER(1)+1
      ELSE IF (LOCLIN(1:6).EQ.'HET   ') THEN
         MASTER(3)=MASTER(3)+1
      ELSE IF (LOCLIN(1:6).EQ.'HELIX ') THEN
         MASTER(4)=MASTER(4)+1
      ELSE IF (LOCLIN(1:6).EQ.'SHEET ') THEN
         MASTER(5)=MASTER(5)+1
      ELSE IF (LOCLIN(1:6).EQ.'TURN  ') THEN
         MASTER(6)=MASTER(6)+1
      ELSE IF (LOCLIN(1:6).EQ.'SITE  ') THEN
         MASTER(7)=MASTER(7)+1
      ELSE IF (LOCLIN(1:5).EQ.'SCALE') THEN
         MASTER(8)=MASTER(8)+1
      ELSE IF (LOCLIN(1:4).EQ.'ORIG') THEN
         MASTER(8)=MASTER(8)+1
      ELSE IF (LOCLIN(1:5).EQ.'MTRIX') THEN
         MASTER(8)=MASTER(8)+1
      ELSE IF (LOCLIN(1:6).EQ.'ATOM  ') THEN
         MASTER(9)=MASTER(9)+1
      ELSE IF (LOCLIN(1:6).EQ.'HETATM') THEN
         MASTER(9)=MASTER(9)+1
      ELSE IF (LOCLIN(1:6).EQ.'TER   ') THEN
         MASTER(10)=MASTER(10)+1
      ELSE IF (LOCLIN(1:6).EQ.'CONECT') THEN
         MASTER(11)=MASTER(11)+1
      ELSE IF (LOCLIN(1:6).EQ.'SEQRES') THEN
         MASTER(12)=MASTER(12)+1
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF508A (IERR)

















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







      IERR=0



      IF (GVFISF('MODEL_SYNC.ERROR')) THEN
         CALL GVSCLF (3)
         CALL GVSCLF (4)
         CALL GVSMV (FILNMS(74),'MODEL_SYNC.ERROR',BIGLIN)
         IERR=1
      END IF





      RETURN
      END
      SUBROUTINE WIF508B (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IERR







      IERR=0



      IF (WIFPAR(1002).LE.0) GOTO 998









  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF508C

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAKMOL.INC'
      INTEGER       IERR, GVFLEN
      CHARACTER*4   LTC4







      IF (WIFPAR(134).EQ.0) GOTO 998



      CALL GVSSTX (LTC4,PDB4LC)



      IF (GVFLEN(LTC4).LE.0) THEN
         CALL IPROMPT ('?M2070')
         CALL GETWORD (LTC4,IERR)
         IF (IERR.EQ.1.OR.GVFLEN(LTC4).LE.0) CALL GVSSTX (LTC4,'FILE')
      END IF



  998 CONTINUE


      RETURN
      END
      SUBROUTINE WIF508D (IERR)

















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







      IERR=0



      IF (WIFPAR(1057).NE.1) GOTO 998



      CALL GVSSTX (LOCLIN,'?M2378')
      CALL WIF530 (3,LOCLIN,IERR)
      IF (IERR.NE.0) GOTO 998
      CALL GVSSTX (LOCLIN,'?M2379')
      CALL WIF530 (3,LOCLIN,IERR)



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF508E (JFT1,JFT2,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       JFT1, JFT2, IERR, IAA







      IERR=0



      IF (WIFPAR(1820).NE.0) GOTO 998
      IF (WIFPAR(450).NE.0) GOTO 998



      IF (JFT1.EQ.0.OR.JFT2.EQ.0) THEN

      ELSE
         CALL GVSBTF (WRK1TF,NUMAAT)
         DO 10 IAA=JFT1,JFT2
            WRK1TF(IAA)=.TRUE.
 10      CONTINUE
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF508F

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA







      IF (WIFPAR(1085).EQ.0) GOTO 998



      WIFPAR(100)=0



      DO 10 IAA=NUMAAT,1,-1
         IF (WRK1TF(IAA)) WIFPAR(100)=SOUPNT(IAA)
 10   CONTINUE



      IF (WIFPAR(100).EQ.0) THEN
         CALL SHOWTEXT ('?M2374')
         WIFPAR(1085)=0
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF508G

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'







      IF (WIFPAR(1269).EQ.0) GOTO 998









  998 CONTINUE


      RETURN
      END   
      LOGICAL FUNCTION WIF508H(IAA)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA, JAA
      LOGICAL       WIFIRA, WIFIRN







      WIF508H=.FALSE.



      IF (IAA.GT.NUMAAF) THEN
         GOTO 998
      ELSE IF (IAA.EQ.NUMAAF) THEN
         WIF508H=.TRUE.
         GOTO 998
      ELSE



         DO 10 JAA=IAA+1,NUMAAF
            IF (CHANAM(JAA).EQ.CHANAM(IAA).AND.
     +       (WIFIRA(IAA).OR.WIFIRN(IAA))) GOTO 998
 10      CONTINUE
      END IF



      WIF508H=.TRUE.



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE WIF507 (NUMUNT)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'MAKMOL.INC'
      INTEGER       ISERIAL, IAT, IAA, IERR, NUMUNT, IBND, JAA, JAT
      LOGICAL       GVFFOP, WIFIRW, WIFIR3, MOL009
      CHARACTER*6   HETATM
      CHARACTER*4   CHAA4







      IF (NUMAAT.LE.0) THEN
         CALL GVSTTE ('?SOUEMP')
         GOTO 998
      END IF
      IF (.NOT.GVFFOP(NUMUNT)) THEN
         CALL GVSTTB ('?M1305')
         GOTO 998
      END IF



      ISERIAL=0
      CALL GVSBTF (USEAT,MAXAT)
      CALL MOL200



      DO 70 IAA=1,NUMAAT
         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 GVSSTX (CHAA4,ONESA3(IAA))
         IF (.NOT.MOL009(CHAA4).AND.WIFIRW(IAA)) THEN
            CALL GVSSTX (CHAA4,'HOH ')
         END IF



         DO 50 IAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (USEAT(IAT).OR.ATTVAL(IAT).LE.0.0) GOTO 50
            CALL WIF509 (NUMUNT,IAA,IAT,ISERIAL,HETATM,CHAA4,
     +       NUMNAM(IAA),'    ',IERR)
            USEAT(IAT)=.TRUE.
   50    CONTINUE
         DO 60 IAT=PNTAAS(IAA),PNTAAE(IAA)
            DO 55 IBND=1,8
               JAT=BOUND_TO(IBND,IAT)
               IF (JAT.NE.0) THEN
                  IF (USEAT(JAT).OR.ATTVAL(JAT).LE.0.0) GOTO 55
                  JAA=ATIAA(JAT)
                  CALL GVSSTX (CHAA4,ONESA3(JAA))
                  CALL GVSSTX (CHAA4,ONESA3(JAA))
                  CALL WIF509 (NUMUNT,JAA,JAT,ISERIAL,HETATM,
     +             CHAA4,NUMNAM(JAA),'    ',IERR)
                  USEAT(JAT)=.TRUE.
               END IF
   55       CONTINUE
   60    CONTINUE



         CALL GVSFMT ('?FMT421')
         IF (WIFIR3(IAA)) THEN
            WRITE (NUMUNT,FMT,ERR=70)
            MASTER(10)=MASTER(10)+1
         ELSE
            IF (IAA.GT.1) THEN
               IF (CHAINN(2,IAA).NE.CHAINN(2,IAA-1)) THEN
                  WRITE (NUMUNT,FMT,ERR=70)
               END IF
            END IF
         END IF
   70 CONTINUE



  998 CONTINUE


      RETURN
      END
