



      SUBROUTINE FBONDI (IAT,JATARR,MAXNUM,NUM)





















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       MAXNUM
      INTEGER       IAT, NUM, JATARR(MAXNUM), JAT, IRT, ICON, J,
     +              IAA, ICYS, JAA, LOCIAT, IO, IH1, IH2, NAT, IERR
      REAL          WIFDST
      LOGICAL       AREBOUND, WIFIRW, WIFIR1, WIFIR3, WIFIRR, WIFIRO







      NUM=0
      IF (MAXNUM.LE.0) THEN
         CALL GVSTTB ('?NEWB254')
         GOTO 998
      END IF
      IAA=ATIAA(IAT)



      CALL GVSIT0 (JATARR,MAXNUM)











      IF (WIFIRW(IAA)) THEN
         CALL WIFWA3 (IAT,IO,IH1,IH2,IERR)
         IF (IERR.NE.0) GOTO 998
         IF (PROTON(IAT)) THEN
           IF (IO.NE.0) THEN
             JATARR(1)=IO
             NUM=1
           END IF
         ELSE
            IF (IH1.NE.0) THEN
               NUM=NUM+1
               JATARR(NUM)=IH1
            END IF
            IF (IH2.NE.0) THEN
               NUM=NUM+1
               JATARR(NUM)=IH2
            END IF
         END IF
      END IF



      IF (WIFPAR(1502).GE.0.AND.PINIAA(IAT).EQ.6) THEN
         DO 20 ICYS=1,NUMCYS
            IF (CYSCYS(1,ICYS).EQ.IAA) THEN
               JAT=PNTAAS(CYSCYS(2,ICYS))+5
               NUM=NUM+1
               JATARR(NUM)=JAT
               IF (NUM.GE.MAXNUM) GOTO 998
               GOTO 30
            END IF
            IF (CYSCYS(2,ICYS).EQ.IAA) THEN
               JAT=PNTAAS(CYSCYS(1,ICYS))+5
               NUM=NUM+1
               JATARR(NUM)=JAT
               IF (NUM.GE.MAXNUM) GOTO 998
               GOTO 30
            END IF
 20      CONTINUE



         DO 21 JAA=1,NUMAAF
            IF (JAA.NE.IAA.AND.RESTYP(JAA).EQ.2.AND.
     +           MODNMB(JAA).EQ.MODNMB(IAA)) THEN
               JAT=PNTAAS(JAA)+5
               IF (.NOT.ISATOK(JAT)) GOTO 21
               IF (AREBOUND(IAT,JAT)) THEN
                  NUM=NUM+1
                  JATARR(NUM)=JAT
                  IF (NUM.GE.MAXNUM) GOTO 998



                  GOTO 30
               END IF
            END IF
   21    CONTINUE
      END IF
 30   CONTINUE



      IF (WIFPAR(1502).GE.0) THEN
         IF (WIFIRR(IAA)) THEN
            IF (PINIAA(IAT).EQ.1) THEN
               IF (.NOT.WIFIR1(IAA)) THEN
                  IF (WIFDST(IAT,PNTAAS(IAA-1)+2).LT.2.0) THEN
                     NUM=NUM+1
                     JATARR(NUM)=PNTAAS(IAA-1)+2
                     IF (NUM.GE.MAXNUM) GOTO 998
                  END IF
               END IF
            END IF
         END IF
      END IF



      IF (RESTYP(IAA).GT.0) THEN



         IRT=RESTYP(IAA)
         LOCIAT=PINIAA(IAT)
         DO 10 ICON=1,MAXTAT
            IF (MUTCON(1,ICON,IRT).EQ.0) GOTO 11
            IF (MUTCON(1,ICON,IRT).EQ.LOCIAT) THEN
               JAT=PNTAAS(IAA)+MUTCON(2,ICON,IRT)-1
               IF (WIFPAR(1502).EQ.0.OR.
     +              (WIFPAR(1502).GT.0.AND..NOT.PROTON(JAT)).OR.
     +              (WIFPAR(1502).LT.0.AND.PROTON(JAT))) THEN
                  NUM=NUM+1
                  JATARR(NUM)=JAT
                  IF (NUM.GE.MAXNUM) GOTO 998
               END IF
            ELSE IF (MUTCON(2,ICON,IRT).EQ.LOCIAT) THEN
               JAT=PNTAAS(IAA)+MUTCON(1,ICON,IRT)-1
               IF (WIFPAR(1502).EQ.0.OR.
     +              (WIFPAR(1502).GT.0.AND..NOT.PROTON(JAT)).OR.
     +              (WIFPAR(1502).LT.0.AND.PROTON(JAT))) THEN
                  NUM=NUM+1
                  JATARR(NUM)=JAT
                  IF (NUM.GE.MAXNUM) GOTO 998
               END IF
            END IF
   10    CONTINUE
   11    CONTINUE
      ELSE IF (.NOT.WIFIRW(IAA)) THEN



         DO 90 JAT=PNTAAS(IAA),PNTAAE(IAA)
            IF (JAT.NE.IAT) THEN
               IF (AREBOUND(IAT,JAT)) THEN
                  IF (WIFPAR(1502).EQ.0.OR.
     +                 (WIFPAR(1502).GT.0.AND..NOT.PROTON(JAT)).OR.
     +                 (WIFPAR(1502).LT.0.AND.PROTON(JAT))) THEN
                     NUM=NUM+1
                     JATARR(NUM)=JAT
                     IF (NUM.GE.MAXNUM) GOTO 998
                  END IF
               END IF
            END IF
   90    CONTINUE
      END IF



      IF (WIFPAR(1502).GE.0) THEN
         IF (WIFIRR(IAA)) THEN
            IF (PINIAA(IAT).EQ.3) THEN
               IF (.NOT.WIFIR3(IAA)) THEN
                  IF (WIFDST(IAT,PNTAAS(IAA+1)).LT.2.0) THEN
                     NUM=NUM+1
                     JATARR(NUM)=PNTAAS(IAA+1)
                     IF (NUM.GE.MAXNUM) GOTO 998
                  END IF
               END IF
            END IF
         END IF
      END IF



      CALL SYMBOUNDIAT (IAT,IERR)



      DO 200 NAT=1,8
         IF (BOUND_TO(NAT,IAT).GT.0) THEN
            J=BOUND_TO(NAT,IAT)


            IF (WIFPAR(1502).EQ.0.OR.
     +       (.NOT.PROTON(BOUND_TO(NAT,IAT)).AND.WIFPAR(1502).GT.0).OR.
     +       (     PROTON(BOUND_TO(NAT,IAT)).AND.WIFPAR(1502).LT.0))THEN



               IF (NUM.EQ.0) THEN
                  NUM=NUM+1
                  JATARR(NUM)=BOUND_TO(NAT,IAT)




               ELSE
                  DO 190 J=1,NUM
                     IF (JATARR(J).EQ.BOUND_TO(NAT,IAT)) then

                        GOTO 200
                     END IF
 190              CONTINUE

                  NUM=NUM+1
                  JATARR(NUM)=BOUND_TO(NAT,IAT)
                  J=JATARR(NUM)








               END IF
               IF (NUM.GE.MAXNUM) GOTO 998
            END IF
         END IF
 200  CONTINUE



  998 CONTINUE

         
      RETURN
      END
      SUBROUTINE FBOND (IAT,JATARR,MAXNUM,NUM)



















      IMPLICIT      NONE
      INTEGER       IAT, MAXNUM, NUM
      INTEGER       JATARR(MAXNUM)




      CALL WIFPUSHPPP (1502,0)
      CALL FBONDI (IAT,JATARR,MAXNUM,NUM)
      CALL WIFPOPPPP (1502)





      RETURN
      END
      SUBROUTINE FBONDA (IAT,JATARR,MAXNUM,NUM)



















      IMPLICIT      NONE
      INTEGER       IAT, MAXNUM, NUM
      INTEGER       JATARR(MAXNUM)





      CALL WIFPUSHPPP (1502,1)
      CALL FBONDI (IAT,JATARR,MAXNUM,NUM)
      CALL WIFPOPPPP (1502)





      RETURN
      END
      SUBROUTINE FBONDH (IAT,JATARR,MAXNUM,NUM)



















      IMPLICIT      NONE
      INTEGER       IAT, MAXNUM, NUM
      INTEGER       JATARR(MAXNUM)





      CALL WIFPUSHPPP (1502,-1)
      CALL FBONDI (IAT,JATARR,MAXNUM,NUM)
      CALL WIFPOPPPP (1502)





      RETURN
      END
      SUBROUTINE FBONDOK (IAT,JATARR,MAXNUM,NUM)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, MAXNUM, NUM, I, J
      INTEGER       JATARR(MAXNUM)





      CALL WIFPUSHPPP (1502,0)
      CALL FBONDI (IAT,JATARR,MAXNUM,NUM)
      CALL WIFPOPPPP (1502)



      IF (NUM.GT.0) THEN
 10      CONTINUE
         IF (NUM.GT.1) THEN
            DO 30 I=1,NUM-1
               IF (.NOT.ISATOK(JATARR(I))) THEN
                  DO 20 J=I,NUM-1
                     JATARR(J)=JATARR(J+1)
 20               CONTINUE
                  NUM=NUM-1
                  GOTO 10
               END IF
 30         CONTINUE
         END IF
         IF (.NOT.ISATOK(JATARR(NUM))) THEN
            NUM=NUM-1
            GOTO 998
         END IF
      END IF        



 998  CONTINUE


      RETURN
      END
      SUBROUTINE FBONDHOK (IAT,JATARR,MAXNUM,NUM)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, MAXNUM, NUM, I, J
      INTEGER       JATARR(MAXNUM)





      CALL WIFPUSHPPP (1502,-1)
      CALL FBONDI (IAT,JATARR,MAXNUM,NUM)
      CALL WIFPOPPPP (1502)



      IF (NUM.GT.0) THEN
 10      CONTINUE
         IF (NUM.GT.1) THEN
            DO 30 I=1,NUM-1
               IF (.NOT.ISATOK(JATARR(I))) THEN
                  DO 20 J=I,NUM-1
                     JATARR(J)=JATARR(J+1)
 20               CONTINUE
                  NUM=NUM-1
                  GOTO 10
               END IF
 30         CONTINUE
         END IF
         IF (.NOT.ISATOK(JATARR(NUM))) THEN
            NUM=NUM-1
            GOTO 998
         END IF
      END IF
      IF (NUM.EQ.0) JATARR(1)=0



 998  CONTINUE


      RETURN
      END
      SUBROUTINE FBONDAOK (IAT,JATARR,MAXNUM,NUM)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAT, MAXNUM, NUM, I, J
      INTEGER       JATARR(MAXNUM)





      CALL WIFPUSHPPP (1502,1)
      CALL FBONDI (IAT,JATARR,MAXNUM,NUM)
      CALL WIFPOPPPP (1502)



      IF (NUM.GT.0) THEN
 10      CONTINUE
         IF (NUM.GT.1) THEN
            DO 30 I=1,NUM-1
               IF (.NOT.ISATOK(JATARR(I))) THEN
                  DO 20 J=I,NUM-1
                     JATARR(J)=JATARR(J+1)
 20               CONTINUE
                  NUM=NUM-1
                  GOTO 10
               END IF
 30         CONTINUE
         END IF
         IF (.NOT.ISATOK(JATARR(NUM))) THEN
            NUM=NUM-1
            GOTO 998
         END IF
      END IF        



 998  CONTINUE


      RETURN
      END
      SUBROUTINE FBONDS (IAT,JATARR,JATSYM,MAXNUM,NUM)
























      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'SYMINC.INC'
      INTEGER       MAX
      PARAMETER     (MAX=50)
      INTEGER       IND, IAT, MAXNUM, NUM, JATARR(MAXNUM), ICON,
     +              JATSYM(MAXNUM), CONIAT(MAX), CONSYM(MAX), N2
      REAL          CONDST(MAX)
      LOGICAL       AREBOUNDS, T54EQUAL









      CALL FBOND (IAT,JATARR,MAXNUM,NUM)


      DO 10 IND=1,MAXNUM
         JATSYM(IND)=1
 10   CONTINUE
      IF (T54EQUAL(ONESAT(IAT),' SG ').OR.RESTYP(ATIAA(IAT)).NE.2) 
     +  GOTO 998
      IF (NUM.EQ.MAXNUM) GOTO 998
      IF (.NOT.SYMHAS) GOTO 998





      CALL FCONATI (IAT,0.0,CONIAT,CONSYM,CONDST,N2,MAX)



      DO 20 ICON=1,N2



         IF (CONSYM(ICON).GT.1) THEN



            IF (AREBOUNDS(IAT,CONIAT(ICON),CONSYM(ICON))) THEN
               NUM=NUM+1
               JATARR(NUM)=CONIAT(ICON)
               JATSYM(NUM)=CONSYM(ICON)
               IF (NUM.EQ.MAXNUM) GOTO 998
            END IF
         END IF
 20   CONTINUE



  998 CONTINUE


      RETURN
      END
