



C


C















C


C


C

















C
      SUBROUTINE MOLINI

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'







      NR280=0
      CALL GVSCTB (CRYSTL,MAXHET*80)
      CALL GVSCTB (EXPDTA,6)
      CALL GVSCTB (HEDCRD,80)
      CALL GVSCTB (HEDDAT,8)
      CALL GVSCTB (HETCRD,MAXHET*80)

      CALL GVSIT0 (HETCNT,MAXHET)





      RETURN
      END   
      SUBROUTINE MOLHST (TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ILIN, I, ILEN, ALEN, GVFLEN
      LOGICAL       CH4EQCH4
      CHARACTER*80  TEXT







      ILIN=0
      DO 10 I=1,MAXHET
         IF (HETCRD(I)(1:14).NE.'              ') THEN
            ILIN=I
         END IF
 10   CONTINUE




      IF (ILIN.GE.MAXHET.AND.TEXT(1:6).EQ.'HET   ') GOTO 998



      IF (TEXT(1:6).EQ.'HET   ') THEN



         IF (ILIN.GE.1) THEN
            DO 20 I=1,ILIN
               IF (CH4EQCH4(HETCRD(I),TEXT(7:10))) THEN
                  HETCNT(ILIN)=HETCNT(ILIN)+1
                  GOTO 998
               END IF
 20         CONTINUE
         END IF



         ILIN=ILIN+1
         CALL GVSSTX (HETCRD(ILIN),TEXT(7:10))
         CALL GVSSTX (HETNAM(ILIN),TEXT(7:10))
         HETCNT(ILIN)=1
         GOTO 998



      ELSE IF (TEXT(1:6).EQ.'HETNAM') THEN
         IF (ILIN.NE.0) THEN
            DO 30 I=1,ILIN
               IF (CH4EQCH4(HETCRD(I),TEXT(11:14))) THEN
                  IF (GVFLEN(HETNAM(I)).GT.248) THEN
                     CALL GVSSTX (HETNAM(I)(248:250),'...')
                     GOTO 998
                  END IF
                  ILEN=GVFLEN(HETNAM(I))
                  ALEN=GVFLEN(TEXT(16:70))
                  IF (ILEN+ALEN.GT.250)THEN
                     CALL GVSCBC(HETNAM(I),TEXT(16:70-(ILEN+ALEN-250)))
                  ELSE
                     CALL GVSCBC (HETNAM(I),TEXT(16:70))
                  END IF
                  GOTO 998
               END IF
 30         CONTINUE
         END IF
         CALL GVSTT6 ('DBG> HETNAM found for unknown HET:')
         CALL GVST6C ('DBG>',TEXT(1:70),.TRUE.)
         GOTO 998



      ELSE IF (TEXT(1:6).EQ.'HETSYN') THEN
         IF (ILIN.NE.0) THEN
            DO 40 I=1,ILIN
               IF (CH4EQCH4(HETCRD(I),TEXT(11:14))) THEN
                  IF (TEXT(10:10).EQ.' ') THEN
                     IF (GVFLEN(HETNAM(I)).LT.225) THEN
                        CALL GVSCBC (HETNAM(I),'or')
                     END IF
                  END IF
                  IF (GVFLEN(HETNAM(I)).GT.248) THEN
                     CALL GVSSTX (HETNAM(I)(248:250),'...')
                     GOTO 998
                  END IF
                  ILEN=GVFLEN(HETNAM(I))
                  ALEN=GVFLEN(TEXT(16:70))
                  IF (ILEN+ALEN.GT.250)THEN
                     CALL GVSCBC(HETNAM(I),TEXT(16:70-(ILEN+ALEN-250)))
                  ELSE
                     CALL GVSCBC (HETNAM(I),TEXT(16:70))
                  END IF
                  GOTO 998
               END IF
 40         CONTINUE
         END IF
         CALL GVSTT6 ('DBG> HETSYN found for unknown HET:')
         CALL GVST6C ('DBG>',TEXT(1:70),.TRUE.)
         GOTO 998
      END IF



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOLDAT (TEXT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       YEAR, FEBDAY, DAYS, IPOS, GVFPOS
      CHARACTER*2   CHAR2
      CHARACTER*3   CHAR3
      CHARACTER*80  TEXT







      CALL GVSSTX (HEDCRD,TEXT)



      CALL GVSCTB (HEDDAT,8)



      CALL GVSSTX (CHAR2,TEXT(58:59))
      IPOS=GVFPOS('6789',CHAR2(1:1))
      IF (IPOS.NE.0) THEN
         CALL GVSSTX (HEDDAT,'19')
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (GVFPOS('0123',CHAR2(1:1)).NE.0) THEN
         CALL GVSSTX (HEDDAT,'20')
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE
         CALL GVSTT6 ('WARNING. Date error on HEADER card:')
         CALL GVSTT6 (TEXT)
         CALL GVSCTB (HEDDAT,8)
         GOTO 998
      END IF
      READ (HEDDAT(1:4),'(I4)',ERR=999,END=999) YEAR
      IF (MOD(YEAR,4).EQ.0) THEN
         FEBDAY=29
      ELSE
         FEBDAY=28
      END IF



      CALL GVSSTX (CHAR3,TEXT(54:56))
      IF (CHAR3.EQ.'JAN') THEN
         CALL GVSCBC (HEDDAT,'01')
      ELSE IF (CHAR3.EQ.'FEB') THEN
         CALL GVSCBC (HEDDAT,'02')
      ELSE IF (CHAR3.EQ.'MAR') THEN
         CALL GVSCBC (HEDDAT,'03')
      ELSE IF (CHAR3.EQ.'APR') THEN
         CALL GVSCBC (HEDDAT,'04')
      ELSE IF (CHAR3.EQ.'MAY') THEN
         CALL GVSCBC (HEDDAT,'05')
      ELSE IF (CHAR3.EQ.'JUN') THEN
         CALL GVSCBC (HEDDAT,'06')
      ELSE IF (CHAR3.EQ.'JUL') THEN
         CALL GVSCBC (HEDDAT,'07')
      ELSE IF (CHAR3.EQ.'AUG') THEN
         CALL GVSCBC (HEDDAT,'08')
      ELSE IF (CHAR3.EQ.'SEP') THEN
         CALL GVSCBC (HEDDAT,'09')
      ELSE IF (CHAR3.EQ.'OCT') THEN
         CALL GVSCBC (HEDDAT,'10')
      ELSE IF (CHAR3.EQ.'NOV') THEN
         CALL GVSCBC (HEDDAT,'11')
      ELSE IF (CHAR3.EQ.'DEC') THEN
         CALL GVSCBC (HEDDAT,'12')
      ELSE
         CALL GVSTT6 ('WARNING. Date error on HEADER card')
         CALL GVSTT6 (TEXT)
         CALL GVSCTB (HEDDAT,8)
         GOTO 998
      END IF



      CALL GVSSTX (CHAR2,TEXT(51:52))
      IF (CHAR3.EQ.'JAN'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'31') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'FEB'.AND.CHAR2.GE.'01') THEN
         READ (CHAR2,'(I2)',ERR=999,END=999) DAYS
         IF (DAYS.LE.FEBDAY) THEN
            CALL GVSCPC (HEDDAT,CHAR2)
         ELSE
            CALL GVSTT6 ('WARNING. Date error on HEADER card')
            CALL GVSTT6 (TEXT)
            CALL GVSCTB (HEDDAT,8)
            GOTO 998
         END IF
      ELSE IF (CHAR3.EQ.'MAR'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'31') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'APR'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'30') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'MAY'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'31') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'JUN'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'30') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'JUL'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'31') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'AUG'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'31') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'SEP'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'30') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'OCT'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'31') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'NOV'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'30') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE IF (CHAR3.EQ.'DEC'.AND.CHAR2.GE.'01'.AND.CHAR2.LE.'31') THEN
         CALL GVSCPC (HEDDAT,CHAR2)
      ELSE
         CALL GVSTT6 ('WARNING. Date error on HEADER card')
         CALL GVSTT6 (TEXT)
         CALL GVSCTB (HEDDAT,8)
         GOTO 998
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOLDAT')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL030 (IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ANISOU.INC'
      INCLUDE       'SUGARS.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR, I, GVFLFI, IMODL, ITYPE, GVFPOS, GVFLFR, 
     +              PARVAL(2), ICNT, IACNT
     +              , INDAA3
      REAL          RESLIM, RESLOC
      LOGICAL       GVFFOP, HASEEN, ROBIE7, RESFND, GVFIBN
      CHARACTER*80  LOCLIN







      IF (.NOT.GVFFOP(11)) THEN
         CALL GVSTTE ('?M2387')
         IERR=1
         CALL GVSKIL
         GOTO 998
      END IF



      IF (WIFPAR(809).GT.1) THEN
         IERR=0
         GOTO 998
      END IF



      IERR=0
      PDBPNT=0
      CALL GVSIT0 (PDBCNT,20)
      CALL GVSDEL ('PDBFILE.PDB')
      HASEEN=.FALSE.
      ROBIE7=.TRUE.
      RESFND=.FALSE.
      PDRESO=-1.0
      RESLOC=-1.0
      PDTEMP=-1.0
      NUMTLS=0
      TLSFND=.FALSE.
      RESLIM=3.5
      IF (WIFPAR(454).GE.1) RESLIM=FLOAT(WIFPAR(454))/100.0
      WIFPAR(466)=9
      WIFPAR(479)=0
      WIFPAR(489)=0
      WIFPAR(497)=0
      WIFCNT=0
      IACNT=0
      CALL GVSCTB (WIFCRD,MAXWCC*80)



      CALL GVSCLF (12)
      CALL GVSODF (12,.TRUE.,'PDBFILE','UNKNOWN',80,' ',IERR)
      IF (IERR.NE.0) GOTO 999



 10   CONTINUE
         CALL GETLINE (11,LOCLIN,IERR)
         IF (IERR.EQ.1) GOTO 998
         IF (LOCLIN(1:10).EQ.'          '.AND.IERR.EQ.2) GOTO 20



         IF (.NOT.RESFND) THEN
            IF (LOCLIN(1:21).EQ.'REMARK   2 RESOLUTION') THEN
               I=GVFLFR(1,PDRESO,LOCLIN(23:30))
               RESFND=.TRUE.
               IF (I.NE.1) THEN
                  IF (GVFPOS(LOCLIN,'NOT APPLICABLE').NE.0) THEN
                     PDRESO=10.0
                  ELSE
                     CALL GVSTT6 ('?M4987')
                     CALL GVSTT6 (LOCLIN(1:79))
                     PDRESO=10.0
                  END IF
               END IF
            END IF
            IF(LOCLIN(1:34).EQ.'REMARK   3   RESOLUTION RANGE HIGH')THEN
               I=GVFLFR(1,RESLOC,LOCLIN(23:60))
               IF (I.NE.1) RESLOC=-1.0
            END IF
         END IF




         IF (LOCLIN(1:33).EQ.'REMARK   3   NUMBER OF TLS GROUPS') THEN
            TLSFND=.TRUE.
            IF (GVFPOS(LOCLIN,'NULL').NE.0) THEN
               NUMTLS=0
            ELSE
               I=GVFLFI(1,NUMTLS,LOCLIN(37:40))
               IF (I.NE.1) NUMTLS=0
               IF (NUMTLS.LT.0) NUMTLS=0
            END IF
         END IF



         IF (LOCLIN(1:21).EQ.'REMARK 200  TEMPERATU') THEN
            IF (GVFPOS(LOCLIN,'NULL').EQ.0) THEN
               I=GVFLFR(1,PDTEMP,LOCLIN(20:80))
               IF (I.NE.1) PDTEMP=0.0
            ELSE
               PDTEMP=0.0
            END IF
         END IF



         IF (LOCLIN(1:19).EQ.'REMARK 600 RESIDUES') THEN
            IF (GVFPOS(LOCLIN,'D-AMINO').NE.0) THEN
               DAMINO=.TRUE.
            END IF
         END IF



         IF (LOCLIN(1:6).EQ.'WHATIF'.AND.WIFCNT.LE.MAXWCC-1) THEN
            IF (GVFPOS(LOCLIN,'NMR').NE.0) THEN
               IF (GVFPOS(LOCLIN,'ALL').NE.0) THEN
                  WIFPAR(368)=999
               END IF
            ELSE IF (GVFPOS(LOCLIN,'SET').NE.0) THEN
               IF (GVFPOS(LOCLIN,'WIF').NE.0) THEN
                  ICNT=GVFLFI(2,PARVAL,LOCLIN)
                  IF (ICNT.EQ.2.AND.GVFIBN(PARVAL(1),1,MAXPAR)) THEN
                     WIFPAR(PARVAL(1))=PARVAL(2)
                     CALL GVSTTI2 ('DBG> PARAMETER,VALUE=',PARVAL(1),
     +                PARVAL(2))
                  END IF
               END IF
            END IF
            WIFCNT=WIFCNT+1
            CALL GVSSTX (WIFCRD(WIFCNT),LOCLIN(7:80))
            CALL GVSSHL (WIFCRD(WIFCNT))
            GOTO 10
         END IF



         IF (LOCLIN(1:10).EQ.'REMARK 280') THEN
            IF (LOCLIN(11:20).NE.'          ') THEN
               NR280=NR280+1
               IF (NR280.LE.25) CALL GVSSTX(CRYSTL(NR280),LOCLIN(12:80))
               IF (WIFPAR(464).NE.0) THEN
                  CALL GVSTT6 (LOCLIN)
                  CALL GVSTTU (WIFPAR(464),LOCLIN)
               END IF
               IF (GVFPOS(LOCLIN,'CONDITIONS:').NE.0) THEN
                  IF (GVFPOS(LOCLIN,'NULL').NE.0) THEN
                     NR280=0
                  END IF
               END IF
            END IF
            GOTO 10
         END IF



         IF (WIFPAR(450).NE.0.AND.WIFPAR(451).NE.0) THEN
            IF (ROBIE7) THEN
               IF (LOCLIN(1:6).NE.'ATOM  '.AND.
     +             LOCLIN(1:6).NE.'HETATM') THEN
                  CALL GVSTTU (WIFPAR(451),LOCLIN)
               ELSE
                  ROBIE7=.FALSE.
               END IF
            END IF
         END IF



         IF (LOCLIN(1:6).EQ.'EXPDTA') THEN
            CALL GVSSTX (EXPDTA,LOCLIN)
            CALL MOLKIL3 (LOCLIN)
            GOTO 10
         END IF



         IF (LOCLIN(1:6).EQ.'HET   '.OR.LOCLIN(1:6).EQ.'HETNAM'.or.
     +       LOCLIN(1:6).EQ.'HETSYN') THEN
            CALL MOLHST (LOCLIN)
            GOTO 10
         END IF



         IF (LOCLIN(1:6).EQ.'HEADER') CALL MOLDAT (LOCLIN)





         ITYPE=0
         IF (LOCLIN(1:6).EQ.'ATOM  '.OR.LOCLIN(1:6).EQ.'HETATM') THEN
            IF (LOCLIN(13:16).EQ.' MW '.AND.LOCLIN(18:21).EQ.'HOH ') 
     +       GOTO 10
            ITYPE=GVFPOS
     +       (' ALA CYS ASP GLE PHE GLY HIS ILE LYS LEU',
     +       LOCLIN(18:21))
            IF (ITYPE.LE.0) THISTP=GVFPOS
     +       (' MET ASN PRO GLN ARG SER THR VAL TRP TYR',
     +       LOCLIN(18:21))
            IF (ITYPE.NE.0) THEN
               ITYPE=(ITYPE+3)/4
            ELSE
               ITYPE=INDAA3(LOCLIN(18:21))
            END IF
         END IF



         IF (.NOT.USEANI.AND.LOCLIN(1:6).EQ.'ANISOU'.AND.
     +    WIFPAR(450).EQ.0) GOTO 10
         IF (LOCLIN(1:6).EQ.'SIGATM') GOTO 10
         IF (LOCLIN(1:6).EQ.'SIGUIJ') GOTO 10



         IF (LOCLIN(18:20).EQ.'UNK') THEN
            IF (GVFPOS(' N   CA  C   O   CB  CG1 CG ',
     +       LOCLIN(13:16)).EQ.0) GOTO 10
         END IF
         IF (WIFPAR(279).GE.1) THEN
            IF (LOCLIN(18:20).EQ.'UNK') GOTO 10
            IF (LOCLIN(18:20).EQ.'UNL') GOTO 10
         END IF



         IF (WIFPAR(84).EQ.0) THEN
            IF (LOCLIN(77:78).EQ.' H'.OR.LOCLIN(77:78).EQ.' D') GOTO 10
         END IF




         IF (LOCLIN(1:4).EQ.'ATOM'.OR.LOCLIN(1:6).EQ.'HETATM') THEN






               LOCLIN(73:76)=LOCLIN(13:16)

            HASEEN=.TRUE.
            IACNT=IACNT+1



            IF (LOCLIN(79:80).NE.'  ') THEN






                  LOCLIN(77:80)='    '

            END IF
         ELSE
            IF (WIFPAR(1156).NE.0) GOTO 10
            IF (.NOT.HASEEN) PDBCNT(8)=PDBCNT(8)+1
         END IF
         PDBCNT(1)=PDBCNT(1)+1
         PRETYP(PDBCNT(1))=ITYPE
         IF (WIFPAR(496).NE.0.AND.IACNT.GT.WIFPAR(496)) THEN
            WIFPAR(497)=1
            GOTO 998
         END IF



         IF (WIFPAR(296).GE.1) THEN
            IF (PDBCNT(1).GT.WIFPAR(296)) THEN
               IERR=1
               CALL GVSBOX ('?M4872')
               GOTO 998
            END IF
         END IF
         IF (WIFPAR(454).GE.1.AND.RESFND) THEN
            IF (PDRESO.LT.0.25.OR.PDRESO.GT.RESLIM) THEN
               IERR=1
               CALL GVSTTR2 ('?M4914',PDRESO,FLOAT(WIFPAR(454))/100.0)
               GOTO 998
            END IF
         END IF



         WRITE (12,REC=PDBCNT(1),ERR=999) LOCLIN
         IF (WIFPAR(365).GE.1) THEN
            IF (LOCLIN(1:6).EQ.'ENDMDL') THEN
               WIFPAR(479)=1
               GOTO 20
            END IF
         END IF



         IF (LOCLIN(1:6).EQ.'MODEL ') THEN
            WIFPAR(489)=WIFPAR(489)+1
            IF (WIFPAR(368).GT.0) THEN
               I=GVFLFI(1,IMODL,LOCLIN)
               IF (IMODL.GT.WIFPAR(368)) GOTO 20
            END IF
         END IF
      GOTO 10 



 20   CONTINUE
      IERR=0



      CALL MOLDBG ('Before D01')
      CALL MOLD01 (IERR)
      CALL MOLDBG ('After D01')



      CALL MOLD02 (IERR)
      CALL MOLDBG ('After D02')
      CALL MOLD03 (IERR)
      CALL MOLDBG ('After D03')
      CALL MOLD04
      CALL MOLDBG ('After D04')



      CALL MOL039
      CALL MOLDBG ('After 039')




      CALL MOL031 (IERR)
      CALL MOLDBG ('After 031')



      CALL MOL034 (IERR)
      CALL MOLDBG ('After 034')



      CALL MOL033 (IERR)
      CALL MOLDBG ('After 033')



      CALL MOL030C
      CALL MOLDBG ('After 030C')







      CALL MOL030B
      CALL MOLDBG ('After 030B')



      CALL MOL032
      CALL MOLDBG ('After 032')
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL030')




  998 CONTINUE
      IF (PDRESO.LT.0.0) PDRESO=RESLOC


      RETURN
      END
      SUBROUTINE MOLD01 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR, COUNTR1, COUNTR2, COUNTR3, COUNTR4, I, IO, IP
      LOGICAL       GVFFOP
      CHARACTER*80  LOCLIN







      IF (.NOT.GVFFOP(12)) THEN
         CALL GVSTTB ('?M3532')
         IERR=1
         GOTO 998
      END IF



      IERR=0
      COUNTR1=0
      COUNTR2=0
      COUNTR3=0
      COUNTR4=0
      IO=0
      IP=0



      DO 10 I=1,PDBCNT(1)
         IO=I
         READ (12,REC=I,ERR=999) LOCLIN



         IF (LOCLIN(1:4).EQ.'ATOM'.OR.LOCLIN(1:6).EQ.'HETATM') THEN
            IF (PDBCNT(10).EQ.0) PDBCNT(10)=I
         ELSE
            IF (PDBCNT(10).GT.0) PDBCNT(11)=I
         END IF



         IF (LOCLIN(1:6).EQ.'ATOM  '.AND.LOCLIN(13:16).EQ.' MW '.AND.
     +    LOCLIN(18:21).EQ.'HOH ') GOTO 10
         IF (LOCLIN(1:4).EQ.'ATOM'.OR.LOCLIN(1:6).EQ.'HETATM') THEN



            IF (LOCLIN(35:35).EQ.'.'.AND.
     +          LOCLIN(43:43).EQ.'.'.AND.
     +          LOCLIN(51:51).EQ.'.'.AND.
     +          LOCLIN(58:58).EQ.'.'.AND.
     +          LOCLIN(64:64).EQ.'.') GOTO 10



            IF (LOCLIN(35:35).EQ.'.'.AND.
     +          LOCLIN(43:43).EQ.'.'.AND.
     +          LOCLIN(51:51).EQ.'.') THEN
               COUNTR1=COUNTR1+1
               IF (COUNTR1.LT.5) THEN
                  CALL GVSTT6 ('?M2369')
                  CALL GVSTT6 (LOCLIN)
               END IF



            ELSE
               IF (LOCLIN(34:34).EQ.'.'.AND.
     +             LOCLIN(42:42).EQ.'.'.AND.
     +             LOCLIN(50:50).EQ.'.') THEN
                  COUNTR2=COUNTR2+1
                  IF (COUNTR2.LT.5) THEN
                     CALL GVSTT6 ('?M2370')
                     CALL GVSTT6 (LOCLIN)
                     GOTO 10
                  END IF
               END IF
               IF (LOCLIN(36:36).EQ.'.'.AND.
     +             LOCLIN(44:44).EQ.'.'.AND.
     +             LOCLIN(52:52).EQ.'.') THEN
                  COUNTR3=COUNTR3+1
                  IF (COUNTR3.LT.5) THEN
                     CALL GVSTT6 ('?M2371')
                     CALL GVSTT6 (LOCLIN)
                     GOTO 10
                  END IF
               END IF
               COUNTR4=COUNTR4+1
               IF (COUNTR4.LT.5) THEN
                  CALL GVSTT6 ('?M2371')
                  CALL GVSTT6 (LOCLIN)
               END IF
            END IF
         END IF
 10   CONTINUE
      IF (PDBCNT(10).EQ.0) PDBCNT(10)=1



      DO 20 I=PDBCNT(10),PDBCNT(11)
         IP=I
         READ (12,REC=I,ERR=999) LOCLIN






            LINE=LOCLIN

         CALL GVSCUC (LINE)
         IF (LINE.NE.LOCLIN) THEN






               LINE(73:76)=LOCLIN(73:76)




               LOCLIN=LINE

            WRITE (12,REC=I,ERR=999) LOCLIN
         END IF



         IF (LOCLIN(13:14).EQ.LOCLIN(77:78)) GOTO 20
         IF (LOCLIN(14:15).EQ.LOCLIN(77:78)) THEN
            IF (LOCLIN(13:13).EQ.' ') THEN
               LOCLIN(13:13)=LOCLIN(14:14)
               LOCLIN(14:14)=LOCLIN(15:15)
               LOCLIN(15:15)=' '
               WRITE (12,REC=I,ERR=999) LOCLIN
            END IF
         END IF
 20   CONTINUE



      IF (COUNTR1.GE.5.OR.COUNTR2.GE.5.OR.COUNTR3.GE.5.OR.
     + COUNTR4.GE.5) CALL GVSTT6 ('?M2415')
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOLD01')



  998 CONTINUE
      IF (PDBCNT(11).LE.0) PDBCNT(11)=PDBCNT(1)


      RETURN
      END   
      SUBROUTINE MOLD02 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IS, IE, IERR, I1, I2, IPNT, IAATYP, IAT
      LOGICAL       CH4EQCH4, GVFIBN, FIRST, FOUND
      CHARACTER*80  LOCLIN







      IERR=0
      IE=PDBCNT(10)-1
      FIRST=.TRUE.




 10   CONTINUE
      IE=IE+1
      DO 40 IPNT=IE,PDBCNT(11)
         IF (IE.GE.PDBCNT(11)) GOTO 998
         READ (12,REC=IPNT,ERR=999) LOCLIN
         IF (LOCLIN(1:4).NE.'ATOM'.AND.LOCLIN(1:6).NE.'HETATM') GOTO 40
         IAATYP=PRETYP(IPNT)
         IF (GVFIBN(IAATYP,1,20)) THEN
            IF (LOCLIN(13:14).EQ.' O'.AND.LOCLIN(15:15).EQ.'''') THEN
               IF (LOCLIN(16:16).EQ.'''') THEN






                     LOCLIN(13:16)=SPCATM(5)


               ELSE






                     LOCLIN(13:16)=SPCATM(4)


               END IF

               WRITE (12,REC=IPNT,ERR=999) LOCLIN
            END IF
            GOTO 40
         END IF
         CALL MOL030D (IPNT,IS,IE,I1,I2,IERR)

         FOUND=.FALSE.
         DO 20 IAT=IS,IE
            READ (12,REC=IAT,ERR=999) LOCLIN
            IF (CH4EQCH4(LOCLIN(18:21),' DA ')) THEN






                  LOCLIN(18:21)='DADE'


            ELSE IF (CH4EQCH4(LOCLIN(18:21),' DC ')) THEN






                  LOCLIN(18:21)='DCYT'


            ELSE IF (CH4EQCH4(LOCLIN(18:21),' DG ')) THEN






                  LOCLIN(18:21)='DGUA'


            ELSE IF (CH4EQCH4(LOCLIN(18:21),' DT ')) THEN






                  LOCLIN(18:21)='DTHY'


               IF (LOCLIN(13:16).EQ.' C5M') CALL GVSSTX 
     +          (LOCLIN(13:16),' C7 ')
            ELSE IF (CH4EQCH4(LOCLIN(18:21),'  A ')) THEN






                  LOCLIN(18:21)='OADE'


            ELSE IF (CH4EQCH4(LOCLIN(18:21),'  C ')) THEN






                  LOCLIN(18:21)='OCYT'


            ELSE IF (CH4EQCH4(LOCLIN(18:21),'  G ')) THEN






                  LOCLIN(18:21)='OGUA'


            ELSE IF (CH4EQCH4(LOCLIN(18:21),'  T ').OR.
     +               CH4EQCH4(LOCLIN(18:21),'  U ')) THEN






                  LOCLIN(18:21)='OURA'


               IF (LOCLIN(13:16).EQ.' C5M') CALL GVSSTX 
     +          (LOCLIN(13:16),' C7 ')
            ELSE

               GOTO 10
            END IF

            WRITE (12,REC=IAT,ERR=999) LOCLIN
            FOUND=FOUND.OR.(LOCLIN(13:16).EQ.' O2*'.OR.
     +       (LOCLIN(13:15).EQ.' O2'.AND.LOCLIN(16:16).EQ.''''))


 20      CONTINUE
         DO 30 IAT=IS,IE
            READ (12,REC=IAT,ERR=999) LOCLIN
            IF (LOCLIN(19:21).EQ.'ADE'.OR.LOCLIN(19:21).EQ.'CYT'.OR.
     +          LOCLIN(19:21).EQ.'GUA'.OR.LOCLIN(19:21).EQ.'THY'.OR.
     +          LOCLIN(19:21).EQ.'URA') THEN
               IF (LOCLIN(16:16).EQ.'*') THEN
                  LOCLIN(16:16)=''''
               END IF
            END IF
            IF (FOUND.AND.LOCLIN(18:18).EQ.'D') THEN
               IF (LOCLIN(18:21).EQ.'DTHY') THEN






                     LOCLIN(18:21)='OURA'


               ELSE
                  LOCLIN(18:18)='O'
               END IF
            END IF
            IF ((.NOT.FOUND).AND.LOCLIN(18:18).EQ.'O') THEN
               IF (LOCLIN(18:21).EQ.'OURA') THEN






                     LOCLIN(18:21)='DTHY'


               ELSE
                  LOCLIN(18:18)='D'
               END IF
            END IF
            WRITE (12,REC=IAT,ERR=999) LOCLIN

 30      CONTINUE
         GOTO 10
 40   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOLD02')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOLD03 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR, IPNT, IAATYP
      LOGICAL       GVFIBN
      CHARACTER*80  LOCLIN







      IERR=0



      DO 10 IPNT=PDBCNT(10),PDBCNT(11)
         READ (12,REC=IPNT,ERR=999) LOCLIN
         IF (LOCLIN(1:4).NE.'ATOM'.AND.LOCLIN(1:6).NE.'HETATM') GOTO 10
         IAATYP=PRETYP(IPNT)



         IF (GVFIBN(IAATYP,1,20)) THEN
            IF (LOCLIN(13:14).EQ.' O') THEN
               IF (LOCLIN(16:16).EQ.' ') THEN
                  IF (LOCLIN(15:15).EQ.''''.OR.LOCLIN(15:15).EQ.'1')THEN
                     LOCLIN(15:15)=' '
                     WRITE (12,REC=IPNT,ERR=999) LOCLIN
                  END IF
               END IF
            END IF
         END IF
 10   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOLD03')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOLD04

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IPNT, ICNT, IAATYP, INDAA3







      ICNT=0



      DO 10 IPNT=PDBCNT(10),PDBCNT(11)
         READ (12,REC=IPNT,ERR=999) LINE
         IF (LINE(1:4).EQ.'ATOM'.OR.LINE(1:6).EQ.'HETATM') THEN
            IF (LINE(18:21).EQ.'SOL ') THEN
               CALL GVSSTX (LINE(18:20),'HOH')
               LINE(21:21)=' '
               WRITE (12,REC=IPNT,ERR=999) LINE
               ICNT=ICNT+1
               GOTO 10
           END IF
            IF (LINE(13:16).EQ.'OXT '.OR.LINE(13:16).EQ.' OXT') THEN
               IAATYP=INDAA3(LINE(18:21))
               IF (IAATYP.LE.0) THEN
                  CALL GVSSTX (LINE(13:16),' O2 ')
                  WRITE (12,REC=IPNT,ERR=999) LINE
               ELSE IF (IAATYP.GE.1.AND.FAMTYP(IAATYP).NE.1) THEN
                  CALL GVSSTX (LINE(13:16),' O2 ')
                  WRITE (12,REC=IPNT,ERR=999) LINE
               END IF
            END IF
         END IF
 10   CONTINUE
      IF (ICNT.GE.1) CALL GVSTTI ('?M4581',ICNT)
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOLD04')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL030B

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IUNIT, IERR, I
      CHARACTER*80  LOCLIN







      IUNIT=0
      IERR=0



      CALL GVSROF (IUNIT,IERR)
      IF (IUNIT.LE.0.OR.IERR.NE.0) GOTO 999
      CALL GVSDEL ('PDBFILE.PDB')
      CALL GETFILN (IUNIT,' ','PDBFILE.PDB',IERR)
      IF (IERR.NE.0) GOTO 999



      CALL GVSFMT ('?FMT111')
      DO 10 I=1,PDBCNT(1)
         READ (12,REC=I,ERR=999) LOCLIN
         WRITE (IUNIT,FMT,ERR=999) LOCLIN
 10   CONTINUE
      CALL GVSTTU (IUNIT,'END')
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL030B')



  998 CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)


      RETURN
      END   
      SUBROUTINE MOL030C

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IPNT, ISTART, IEND, IERR, GVFLFI, IAATYP, IAAM, IL,  
     +              IAAP, MODNR, J, INDAA3
      LOGICAL       GVFIBN, GVFFOP, TXTPROTON
      CHARACTER*1   CHAR1
      CHARACTER*80  LOCLIN







      IF (PDBCNT(1).LE.0) GOTO 998



      MODNR=0







      IPNT=1
 20   CONTINUE
         IPNT=IPNT+1
         IF (IPNT.GE.PDBCNT(1)) GOTO 998
         READ (12,REC=IPNT,ERR=999) LOCLIN

         IF (LOCLIN(1:5).EQ.'MODEL') J=GVFLFI(1,MODNR,LOCLIN)
         IF (LOCLIN(1:6).NE.'ATOM  '.AND.LOCLIN(1:6).NE.'HETATM')GOTO20


         IAATYP=PRETYP(IPNT)
         IF (IAATYP.EQ.0) IAATYP=INDAA3(LOCLIN(18:21))
         IF (IAATYP.NE.0) GOTO 20



         CALL MOL030D (IPNT,ISTART,IEND,IAAM,IAAP,IERR)
         IF (ISTART.EQ.IEND.OR.IERR.NE.0) GOTO 20







         DO 15 IL=ISTART,IEND
            READ (12,REC=IL,ERR=999) LOCLIN

            IF (LOCLIN(13:14).EQ.LOCLIN(77:78)) THEN


            ELSE IF (TXTPROTON(LOCLIN(13:16),LOCLIN(77:78))) THEN
               LOCLIN(77:77)=' '
               LOCLIN(78:78)='H'
               WRITE (12,REC=IL,ERR=999) LOCLIN

            ELSE
               LOCLIN(77:77)=LOCLIN(13:13)
               LOCLIN(78:78)=LOCLIN(14:14)
               WRITE (12,REC=IL,ERR=999) LOCLIN

            END IF
 15      CONTINUE



         IF (GVFIBN(IAAM,1,20).AND.GVFIBN(IAAP,1,20)) THEN
            READ (12,REC=IPNT,ERR=999) LOCLIN
            CHAR1=LOCLIN(17:17)
            DO 5 IPNT=ISTART+1,IEND
               READ (12,REC=IPNT,ERR=999) LOCLIN
               IF (LOCLIN(17:17).NE.CHAR1) THEN
                  CALL GVSTT6 ('?M5161')
                  GOTO 998
               END IF
 5          CONTINUE

            CALL MOL030E (ISTART,IEND)
            CALL MOL030G (ISTART,1,11)
            IF (WIFPAR(493).EQ.0) THEN

               CALL TOP008 (' ')
            END IF
            IF (TOPLOG.NE.0) THEN
               IF (GVFFOP(TOPLOG)) THEN
                  CALL GVSLUN (TOPLOG)
                  CALL GVSTTU (TOPLOG,FILNMS(62))
                  CALL GVSTT6 (FILNMS(62))
                  CALL GVSTT6 (FILNMS(91))
                  DO 10 IPNT=ISTART,IEND
                     READ (12,REC=IPNT,ERR=999) LOCLIN
                     CALL GVSTTU (TOPLOG,LOCLIN)
                     CALL GVSTT6 (LOCLIN)
 10               CONTINUE
                  CALL GVSNLU (TOPLOG,1)
                  CALL GVSNL6 (1)
               END IF
            END IF
         END IF
         IF (ISTART.GT.IPNT) IPNT=ISTART
      GOTO 20



  999 CONTINUE
      CALL GVSEIW ('MOL030C')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL030D (IPNT,ISTART,IEND,IAAM,IAAP,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR, ISTART, IEND, IPNT, JPNT, IAAM, IAAP
      LOGICAL       GVFIBN
      CHARACTER*80  LOCLIN, LOCLN2







      IF (.NOT.GVFIBN(IPNT,PDBCNT(10),PDBCNT(11))) GOTO 999



      IERR=0
      ISTART=IPNT
      IEND=IPNT
      IAAM=0
      IAAP=0
      READ (12,REC=IPNT,ERR=999) LOCLIN



      IF (IPNT.EQ.1) THEN
         ISTART=IPNT
      ELSE
         DO 10 JPNT=IPNT-1,1,-1
            READ (12,REC=JPNT,ERR=999) LOCLN2
            IF (LOCLIN(18:26).NE.LOCLN2(18:26)) THEN
               IAAM=PRETYP(JPNT)
               ISTART=JPNT+1
               GOTO 11
            END IF
 10      CONTINUE
      END IF
 11   CONTINUE



      IF (IPNT.LT.PDBCNT(1)) THEN
         DO 20 JPNT=IPNT+1,PDBCNT(11)
            READ (12,REC=JPNT,ERR=999) LOCLN2
            IF (LOCLIN(18:26).NE.LOCLN2(18:26)) THEN
               IAAP=PRETYP(JPNT)
               IEND=JPNT-1
               GOTO 998
            END IF
 20      CONTINUE
      END IF
      IEND=PDBCNT(1)
      GOTO 998



  999 CONTINUE
      IERR=1
      CALL GVSEIW ('MOL030D')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL030E (ISTART,IEND)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ELMINC.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IPNT, ISTART, IEND, IPOS(8), IBND(8,50), IENDOLD,
     +              ILOC, JLOC, IROW(16), I, J, WBND(2,8*50), IUNIT,
     +              EBND(2*8*50), IERR, IPLS, ERAD, ELMCHR
      REAL          XYZL(3,50), D, CUTOF1, CUTOF2, CUTINI
      LOGICAL       N, CA, C, O, CH4EQCH4, GOTFILE, GVFRIN, GVFISF,
     +              BFOUND, TXTPROTON
      CHARACTER*2   CHAR2(50)
      CHARACTER*4   CHAR4(50), CHAR4_1
      CHARACTER*80  LOCLIN
      EQUIVALENCE   (EBND(1),WBND(1,1))







      IUNIT=0
      IF (IEND-ISTART.LT.4.OR.IEND-ISTART.GE.50) GOTO 998



      N=.FALSE.
      CA=.FALSE.
      C=.FALSE.
      O=.FALSE.
      CUTINI=1.8
      CALL GVSIT0 (IBND,8*50)
      CALL GVSIT0 (WBND,2*8*50)
      CALL GVSIT0 (IPOS,4)
      CALL GVSIT0 (IROW,16)
      CALL GVSRT0 (XYZL,3*50)
      CALL GVSCTB (CHAR4,4*50)
      CALL GVSCTB (CHAR2,2*50)



      IENDOLD=IEND
      CALL MOL030F (ISTART,IEND)



      DO 10 IPNT=ISTART,IEND
         READ (12,REC=IPNT,ERR=999) LOCLIN
         IF (LOCLIN(17:17).NE.' '.AND.LOCLIN(17:17).NE.'A') GOTO 10
         IF (CH4EQCH4(LOCLIN(13:16),' N  ')) THEN
            N=.TRUE.
            IPOS(1)=IPNT
         END IF
         IF (CH4EQCH4(LOCLIN(13:16),' CA ')) THEN
            CA=.TRUE.
            IPOS(2)=IPNT
         END IF
         IF (CH4EQCH4(LOCLIN(13:16),' C  ')) THEN
            C=.TRUE.
            IPOS(3)=IPNT
         END IF
         IF (CH4EQCH4(LOCLIN(13:16),' O  ')) THEN
            O=.TRUE.
            IPOS(4)=IPNT
         END IF
 10   CONTINUE




      IF (.NOT.(N.AND.CA.AND.C.AND.O)) GOTO 998



      CALL MOL030E1 (ISTART,IEND,IPOS)
      IF (IPOS(1).NE.ISTART) THEN
         READ (12,REC=ISTART,ERR=999) LINE
         READ (12,REC=IPOS(1),ERR=999) LINE2
         WRITE (12,REC=ISTART,ERR=999) LINE2
         WRITE (12,REC=IPOS(1),ERR=999) LINE
      END IF
      CALL MOL030E1 (ISTART,IEND,IPOS)
      IF (IPOS(2).NE.ISTART+1) THEN
         READ (12,REC=ISTART+1,ERR=999) LINE
         READ (12,REC=IPOS(2),ERR=999) LINE2
         WRITE (12,REC=ISTART+1,ERR=999) LINE2
         WRITE (12,REC=IPOS(2),ERR=999) LINE
      END IF
      CALL MOL030E1 (ISTART,IEND,IPOS)
      IF (IPOS(3).NE.ISTART+2) THEN
         READ (12,REC=ISTART+2,ERR=999) LINE
         READ (12,REC=IPOS(3),ERR=999) LINE2
         WRITE (12,REC=ISTART+2,ERR=999) LINE2
         WRITE (12,REC=IPOS(3),ERR=999) LINE
      END IF
      CALL MOL030E1 (ISTART,IEND,IPOS)
      IF (IPOS(4).NE.ISTART+3) THEN
         READ (12,REC=ISTART+3,ERR=999) LINE
         READ (12,REC=IPOS(4),ERR=999) LINE2
         WRITE (12,REC=ISTART+3,ERR=999) LINE2
         WRITE (12,REC=IPOS(4),ERR=999) LINE
      END IF




      DO 20 IPNT=ISTART,IEND
         ILOC=IPNT-ISTART+1
         READ (12,REC=IPNT,ERR=999) LOCLIN
         IF (LOCLIN(17:17).NE.' '.AND.LOCLIN(17:17).NE.'A') THEN
            CALL GVSTT6 ('.................123456789012345678901234567')
            CALL GVST6C ('ISTART LINE AT 1=',LOCLIN(1:70),.TRUE.)
            GOTO 999
         END IF
         CALL GVSSTX (CHAR4(ILOC),LOCLIN(13:16))
         CALL GVSSTX (CHAR2(ILOC),LOCLIN(77:78))
         READ (LOCLIN,123,ERR=999)XYZL(1,ILOC),XYZL(2,ILOC),XYZL(3,ILOC)
 123     FORMAT (30X,3F8.3)
         IROW(1)=IROW(1)+1
 20   CONTINUE
      IROW(5)=1




      CUTOF1=CUTINI



      DO 40 ILOC=1,IROW(1)
         CUTOF1=CUTINI-0.1
         BFOUND=.FALSE.
         ERAD=ELMCHR(CHAR4(ILOC)(1:2))
         IF (ARAD(ERAD).GT.0.77) CUTOF1=CUTOF1-0.77+ARAD(ERAD)




         DO 35 IPLS=1,10
            IF (IPLS.GE.2) CALL GVSTTI ('DBG> ROUND:',IPLS)
            CUTOF1=CUTOF1+0.1



            DO 30 JLOC=1,IROW(1)
               CUTOF2=CUTOF1
               ERAD=ELMCHR(CHAR4(JLOC)(1:2))
               IF (ARAD(ERAD).GT.0.77) CUTOF2=CUTOF2-0.77+ARAD(ERAD)

               D=(XYZL(1,ILOC)-XYZL(1,JLOC))**2+
     +           (XYZL(2,ILOC)-XYZL(2,JLOC))**2+
     +           (XYZL(3,ILOC)-XYZL(3,JLOC))**2
               IF (GVFRIN(D,0.6,CUTOF2**2)) THEN
                  BFOUND=.NOT.TXTPROTON(CHAR4(JLOC),CHAR2(JLOC))
                  IF (JLOC.GT.ILOC) THEN

                     CALL MOL030E2 (IBND,ILOC,JLOC)
                     IROW(2)=IROW(2)+1
                  END IF
               END IF
 30         CONTINUE
            IF (BFOUND) GOTO 40
 35      CONTINUE
 40   CONTINUE
      IROW(6)=IROW(2)





      IF (IBND(2,1).NE.0.OR.IBND(2,3).EQ.0.OR.IBND(3,3).NE.0.OR.
     +    IBND(2,4).NE.0) GOTO 998



      IF (GVFISF('DRGWIF.TOP')) CALL GVSDEL ('DRGWIF.TOP')

      IF (.NOT.GOTFILE(IUNIT,'DRGWIF.TOP')) GOTO 998



      DO 50 ILOC=1,IROW(1)
         READ (12,REC=ILOC,ERR=999) LINE
         IF (LINE(77:78).NE.' H'.AND.LINE(77:78).NE.' D') THEN
            IROW(8)=IROW(8)+1
         END IF
 50   CONTINUE





      CALL GVSTTU (IUNIT,'*')
      READ (12,REC=ISTART,ERR=999) LOCLIN
      WRITE (IUNIT,1000,ERR=999) LOCLIN(18:21)
      IF (LOCLIN(17:17).NE.' '.AND.LOCLIN(17:17).NE.'A') THEN
         CALL GVST6C ('ISTART LINE AT 2=',LOCLIN(1:40),.TRUE.)
         GOTO 999
      END IF
      CALL GVSSTX (CHAR4_1,LOCLIN(18:21))
 1000 FORMAT (A4,'Z')




      CALL GVSTTU (IUNIT,
     +'#AT BND CHI TRS CRD #BL HGR HAT ANG 1-3 PAR PC HANG TYP NNA ROT')
      IROW(14)=1
      IROW(15)=1
      IROW(16)=0
      WRITE (IUNIT,1010,ERR=999) IROW
 1010 FORMAT (16I4)






      WRITE (IUNIT,1020,ERR=999) (CHAR4(ILOC),ILOC=1,IROW(1))
 1020 FORMAT (14(A4,1X))




      J=0
      DO 70 ILOC=1,IROW(2)
         DO 60 I=1,8
            IF (IBND(I,ILOC).NE.0) THEN
               IF (IBND(I,ILOC).GT.ILOC) THEN
                  J=J+1
                  WBND(1,J)=ILOC
                  WBND(2,J)=IBND(I,ILOC)
               END IF
            END IF
 60      CONTINUE
 70   CONTINUE
      WRITE (IUNIT,1030,ERR=999) (EBND(I),I=1,2*J)
 1030 FORMAT (10(2I3,1X))





      WRITE (IUNIT,1040,ERR=999) XYZL(1,1),XYZL(2,1),XYZL(3,1)
 1040 FORMAT (F9.4,F9.4,F9.4,'  T+ 1')
      WRITE (IUNIT,1050,ERR=999) XYZL(1,2),XYZL(2,2),XYZL(3,2)
      WRITE (IUNIT,1050,ERR=999) XYZL(1,3),XYZL(2,3),XYZL(3,3)
 1050 FORMAT (F9.4,F9.4,F9.4,'  F')
      WRITE (IUNIT,1060,ERR=999) XYZL(1,4),XYZL(2,4),XYZL(3,4)
 1060 FORMAT (F9.4,F9.4,F9.4,'  T-')
      DO 80 I=5,IROW(1)
         WRITE (IUNIT,1050,ERR=999) XYZL(1,I),XYZL(2,I),XYZL(3,I)
 80   CONTINUE




      DO 90 I=1,8*50
         IF (WBND(1,I).NE.0) THEN
            ILOC=WBND(1,I)
            JLOC=WBND(2,I)
            D=SQRT((XYZL(1,ILOC)-XYZL(1,JLOC))**2+
     +             (XYZL(2,ILOC)-XYZL(2,JLOC))**2+
     +             (XYZL(3,ILOC)-XYZL(3,JLOC))**2)
            WRITE (IUNIT,1070,ERR=999) D
 1070       FORMAT (F6.3,' 0.100')
         END IF
 90   CONTINUE




      CALL GVSTTU (IUNIT,'*END')
      CALL GVSCLF (IUNIT)
      IUNIT=0
      CALL TOP004 (IERR)
      CALL TOP010 (CHAR4_1)



      DO 100 I=ISTART,IENDOLD
         PRETYP(I)=WIFPAR(276)
 100  CONTINUE
      IEND=IENDOLD

      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL030E')



  998 CONTINUE
      IF (IUNIT.NE.0) CALL GVSCLF (IUNIT)


      RETURN
      END   
      SUBROUTINE MOL030E1 (ISTART,IEND,IPOS)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       ISTART, IEND, IPOS(4), IPNT
      LOGICAL       CH4EQCH4
      CHARACTER*80  LOCLIN







      DO 10 IPNT=ISTART,IEND
         READ (12,REC=IPNT,ERR=999) LOCLIN
         IF (LOCLIN(17:17).EQ.' '.OR.LOCLIN(17:17).EQ.'A') THEN
            IF (CH4EQCH4(LOCLIN(13:16),' N  ')) IPOS(1)=IPNT
            IF (CH4EQCH4(LOCLIN(13:16),' CA ')) IPOS(2)=IPNT
            IF (CH4EQCH4(LOCLIN(13:16),' C  ')) IPOS(3)=IPNT
            IF (CH4EQCH4(LOCLIN(13:16),' O  ')) IPOS(4)=IPNT
         END IF
 10   CONTINUE
      GOTO 998



 999  CONTINUE
      CALL GVSEIR ('MOL030E1')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL030E2 (IBND,ILOC,JLOC)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IBND(8,50), ILOC, JLOC, I







      DO 10 I=1,8
         IF (IBND(I,ILOC).LE.0) THEN
            IBND(I,ILOC)=JLOC
            GOTO 11
         END IF
 10   CONTINUE
 11   CONTINUE



      DO 20 I=1,8
         IF (IBND(I,JLOC).LE.0) THEN
            IBND(I,JLOC)=ILOC
            GOTO 998
         END IF
 20   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL030F (ISTART,IEND)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       ISTART, IEND, IS, IE, IENDOLD, I, J, CHACNT
      LOGICAL       CALTFN, MOL009
      CHARACTER*1   CHARS, CHARE, CHAROW(36), SCR1, SCR2







      READ (12,REC=ISTART,ERR=999) READIN(1)
      IF (MOL009(READIN(1)(13:16))) GOTO 998



      IS=ISTART
      IE=IEND
      IENDOLD=IEND
      CHACNT=1
      ITT=IEND-ISTART+1
      CALL GVSCTB (CHAROW,36)



      DO 1 I=IS+1,IEND
         J=I-IS+1
         READ (12,REC=I,ERR=999) READIN(J)
 1    CONTINUE




      CALTFN=.FALSE.
      DO 2 I=1,ITT
         IF (READIN(I)(17:17).NE.' ') CALTFN=.TRUE.
 2    CONTINUE
      IF (.NOT.CALTFN) GOTO 998

      CALL MOL030G (ISTART,13,16)




      DO 6 I=1,ITT
         IF (READIN(I)(17:17).EQ.' ') GOTO 6
         IF (CHACNT.GT.1) THEN
            DO 5 J=1,CHACNT-1
               IF (CHAROW(J).EQ.READIN(I)(17:17)) GOTO 6
 5          CONTINUE
         END IF
         CHAROW(CHACNT)=READIN(I)(17:17)
         CHACNT=CHACNT+1
 6    CONTINUE
      CHACNT=CHACNT-1

      IF (CHACNT.LE.1) GOTO 998





      CALL GVSDT4 (CHAROW,SCR1,SCR2,CHACNT)




      DO 8 I=1,ITT
         DO 7 J=1,CHACNT
            IF (READIN(I)(17:17).EQ.CHAROW(J)) READIN(I)(17:17)=
     +       CHADEF2(J:J)
 7       CONTINUE
         WRITE (12,REC=I+IS-1,ERR=999) READIN(I)

 8    CONTINUE



 10   CONTINUE
         IF (IE.LE.IS) GOTO 21
         READ (12,REC=IS,ERR=999) LINE
         CHARS=LINE(17:17)
         PRINT*,'LINE:',LINE(1:40),'..',IS,'..',CHARS
         IF (CHARS.EQ.' '.OR.CHARS.EQ.'A') THEN
            IS=IS+1
            GOTO 10
         END IF
         PRINT*,'NON BLANK/A, SO SEARCH FOR SWAP PARTNER'
 20      CONTINUE
            IF (IE.LE.IS) GOTO 21
            READ (12,REC=IE,ERR=999) LINE2
            CHARE=LINE2(17:17)
            PRINT*,'LIN2:',LINE2(1:40),'..',IE,'..',CHARE
            IF (CHARE.EQ.' '.OR.CHARE.EQ.'A') THEN
               PRINT*,'SWAP'
               WRITE (12,REC=IS,ERR=999) LINE2
               IS=IS+1
               WRITE (12,REC=IE,ERR=999) LINE
               IE=IE-1
               GOTO 10
            END IF
            IE=IE-1
            GOTO 20


 21   CONTINUE




      DO 30 I=ISTART,IENDOLD
         READ (12,REC=I,ERR=999) LINE

         CHARS=LINE(17:17)
         IF (CHARS.EQ.' '.OR.CHARS.EQ.'A') IEND=I

 30   CONTINUE
         
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL030F')



  998 CONTINUE
      DO 15 I=ISTART,IEND
         READ (12,REC=I,ERR=999) LINE

 15   CONTINUE



      RETURN
      END   
      SUBROUTINE MOL030G (ISTART,A,B)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       A, B, I, J, ISTART
      LOGICAL       BIGR2







      DO 20 I=1,ITT-1
         DO 10 J=I+1,ITT
            BIGR2=.FALSE.
            IF (READIN(J)(A:B).GT.READIN(I)(A:B)) THEN
               BIGR2=.TRUE.
            ELSE IF (READIN(J)(A:B).EQ.READIN(I)(A:B)) THEN
               IF (READIN(J)(57:60).GT.READIN(I)(57:60)) THEN
                  BIGR2=.TRUE.
               ELSE IF (READIN(J)(17:17).GT.READIN(I)(17:17)) THEN
                  BIGR2=.TRUE.
               END IF
            END IF
            IF (.NOT.BIGR2) CALL GVSWCP (READIN(J),READIN(I))
 10      CONTINUE
 20   CONTINUE



      DO 30 I=1,ITT
         WRITE (12,REC=ISTART+I-1,ERR=999) READIN(I)
 30   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL030G')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL031 (IERR)




















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'DATBAS.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       ICNT, JCNT, LAST, PHASE, PRESENT, IERR, ITMP, PRVL
      LOGICAL       GVFFOP, GVFYON, ENDMDL, DIDWRN
      CHARACTER*80  LOCLIN, LOCLN2







      IERR=0
      LAST=0
      PHASE=0
      PRESENT=0
      WIFPAR(846)=0
      WIFPAR(847)=0
      WIFPAR(1503)=0
      PRVL=0
      ENDMDL=.FALSE.
      DIDWRN=.FALSE.
      CALL GVSCTB (LOCLN2,80)



      IF (.NOT.GVFFOP(12)) THEN
         CALL GVSTTB ('?M3389')
         GOTO 998
      END IF







      DO 10 ICNT=1,PDBCNT(1)
         READ (12,REC=ICNT,ERR=999) LOCLIN
         IF (LOCLIN(1:6).EQ.'HETATM') THEN


               LOCLIN(1:6)='ATOM  '

            WRITE (12,REC=ICNT,ERR=999) LOCLIN
         END IF
         IF (.NOT.ENDMDL) THEN
            PDBCNT(4)=PDBCNT(4)+1
            IF (LOCLIN(1:4).EQ.'ATOM') PDBCNT(5)=PDBCNT(5)+1
            IF (LOCLIN(1:6).EQ.'ENDMDL') ENDMDL=.TRUE.
         END IF
         IF (LOCLIN(1:4).EQ.'ATOM') THEN
            PDBCNT(2)=PDBCNT(2)+1
         ELSE IF (LOCLIN(1:5).EQ.'MODEL') THEN



               LOCLN2=LOCLIN

            PDBCNT(3)=PDBCNT(3)+1
            WIFPAR(1503)=1
         ELSE IF (LOCLIN(1:6).EQ.'ENDMDL') THEN
            IF (PDBCNT(2).NE.0) THEN
               IF (PHASE.EQ.0) THEN
                  PRESENT=PDBCNT(2)
                  PHASE=PDBCNT(2)
               ELSE
                  PRESENT=PDBCNT(2)-LAST
               END IF
               LAST=PDBCNT(2)
            END IF
            IF (PRESENT.NE.PHASE) THEN
               CALL GVSTTI ('?M3088',PDBCNT(3))
               CALL GVSTTI ('?M3089',PHASE)
               CALL GVSTTI ('?M3090',PRESENT)
            END IF
            IF (ICNT-PRVL.NE.PDBCNT(4)) THEN
               IF (WIFPAR(279).LE.0) THEN
                  IF (.NOT.DIDWRN) THEN
                     DIDWRN=.TRUE.
                  END IF
               END IF
            END IF
            PRVL=ICNT
         END IF
 10   CONTINUE










      IF (DATLOG.GT.0) THEN
         IF (GVFFOP(DATLOG)) THEN
            CALL GVSTUI (DATLOG,'?M4582',MAXAT)
            CALL GVSTUI (DATLOG,'?M4583',NUMATF)
            CALL GVSTUI (DATLOG,'?M4584',PDBCNT(1))
            CALL GVSTUI (DATLOG,'?M4585',PDBCNT(2))
            CALL GVSTUI (DATLOG,'?M4586',PDBCNT(3))
            CALL GVSTUI (DATLOG,'?M4587',PDBCNT(8))
         END IF
      END IF
      IF (PDBCNT(3).GT.0) THEN
         CALL GVSTTI ('?M4588',PDBCNT(4))
         CALL GVSTTI ('?M4589',PDBCNT(5))
      END IF
      WIFPAR(847)=PDBCNT(3)
      IF (NUMATF+PDBCNT(2).GT.MAXAT) THEN
         IF (PDBCNT(3).GT.0) THEN
            WIFPAR(847)=PDBCNT(3)*(MAXAT-NUMATF-10000)/PDBCNT(2)
            IF (WIFPAR(847).LE.0) THEN
               IERR=1
            ELSE
               CALL GVSTTI ('?M3084',PDBCNT(3))
               CALL GVSTTI ('?M3085',WIFPAR(847))
               GOTO 998
            END IF
         END IF
         CALL GVSTT6 ('?M3086')
         IF (WIFPAR(369).EQ.0) THEN
            IF (.NOT.GVFYON('?M3087',' ')) THEN
               IERR=1
               GOTO 998
            END IF
         ELSE
            IERR=1
            GOTO 998
         END IF
      END IF



      IF (PDBCNT(3).GT.0) THEN



         IF (WIFPAR(438).NE.0) THEN
            WIFPAR(847)=1
            GOTO 998
         END IF



         IF (WIFPAR(1105).GE.1.OR.WIFPAR(279).NE.0) THEN
            WIFPAR(847)=PDBCNT(3)
            GOTO 998
         END IF



         IF (WIFPAR(368).GE.1) THEN
            WIFPAR(847)=WIFPAR(368)
         ELSE
            WIFPAR(847)=1000
            CALL GETINTPAR (847,1,0,99999,'?M0812','?M0813')
         END IF



         IF (WIFPAR(847).LE.0) THEN
            CALL GVSCTB (LOCLIN,80)
            DO 30 ICNT=1,PDBCNT(1)
               WRITE (12,REC=ICNT,ERR=999) LOCLIN
 30         CONTINUE
         ELSE IF (WIFPAR(847).GE.PDBCNT(3)) THEN
            GOTO 998
         ELSE
            ITMP=0
            DO 50 ICNT=1,PDBCNT(1)
               READ (12,REC=ICNT,ERR=999) LOCLIN
               IF (LOCLIN(1:5).EQ.'MODEL') THEN
                  ITMP=ITMP+1
                  IF (ITMP.GT.WIFPAR(847)) THEN
                     CALL GVSCTB (LOCLIN,80)
                     DO 40 JCNT=ICNT,PDBCNT(1)
                        WRITE (12,REC=JCNT,ERR=999) LOCLIN
 40                  CONTINUE
                     GOTO 998
                  END IF
               END IF
 50         CONTINUE
         END IF
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL031')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL032

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR, I, LENS(500), NUMS, NUMNOW, GVFPOS, LOCMUL,
     +              ISOUP, JSOUP
      LOGICAL       FOUND
      CHARACTER*1   CHA, SEQS(1000,500)
      CHARACTER*80  LOCLIN
      CHARACTER*500 CHAS
      EQUIVALENCE   (SEQS(1,1),ESPACE(2000001))
      EQUIVALENCE   (LENS(1),  ESPACE(4000001))
      EQUIVALENCE   (CHAS,     ESPACE(4100001))







      IERR=0
      NUMS=0
      NUMNOW=0
      CELMUL=0
      FOUND=.FALSE.
      CALL GVSIT0 (LENS,500)
      CALL GVSCTB (CHAS,500)



      DO 10 I=1,PDBCNT(1)
         READ (12,REC=I,ERR=999) LOCLIN
         IF (LOCLIN(1:6).EQ.'SEQRES') THEN
            FOUND=.TRUE.
            CHA=LOCLIN(12:12)
            NUMNOW=GVFPOS(CHAS,CHA)
            IF (NUMNOW.EQ.0) THEN
               NUMS=NUMS+1
               NUMNOW=NUMS
               CHAS(NUMNOW:NUMNOW)=CHA
            END IF
            CALL MOL032A (LOCLIN,SEQS(LENS(NUMNOW),NUMNOW),LENS(NUMNOW))
         ELSE
            IF (FOUND) GOTO 11
         END IF
 10   CONTINUE
 11   CONTINUE



      DO 40 ISOUP=1,NUMS-1
         IF (CHAS(ISOUP:ISOUP).EQ.' ') GOTO 40
         LOCMUL=1
         DO 30 JSOUP=ISOUP+1,NUMS
            IF (CHAS(JSOUP:JSOUP).EQ.' ') GOTO 30
            IF (LENS(ISOUP).NE.LENS(JSOUP)) GOTO 30
            DO 20 I=1,1,LENS(ISOUP)
               IF (SEQS(I,ISOUP).NE.SEQS(I,JSOUP)) GOTO 30
 20         CONTINUE
            LOCMUL=LOCMUL+1
            CHAS(JSOUP:JSOUP)=' '
 30      CONTINUE
         CELMUL=MAX(CELMUL,LOCMUL)
         CHAS(ISOUP:ISOUP)=' '
 40   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL032')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL032A (TEXT,SEQS,IPNT)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IPNT, I, IAATYP, INDAA3
      CHARACTER*1   SEQS(1000), SEQAA
      CHARACTER*80  TEXT







      IF (TEXT(1:6).NE.'SEQRES') GOTO 998



      DO 10 I=20,77,4
         IF (TEXT(I:I+3).EQ.'    ') GOTO 998
         IAATYP=INDAA3(TEXT(I:I+3))
         IF (IAATYP.GE.1) THEN
            SEQAA=A1NAME(IAATYP)
         ELSE
            SEQAA='X'
         END IF
         IPNT=IPNT+1
         SEQS(IPNT)=SEQAA
 10   CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL033 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IATT, IERR, IAATYP, IP
      CHARACTER*4   ATTYP
      CHARACTER*80  LIN







      IF (PDBCNT(1).LT.4) GOTO 998



      IERR=0






      DO 30 IP=PDBCNT(10),PDBCNT(11)
         READ (12,REC=IP,ERR=999) LIN

         IF (LIN(1:4).NE.'ATOM'.AND.LIN(1:6).NE.'HETATM') GOTO 30



         IF (LIN(13:14).EQ.'HO'.AND.LIN(15:15).NE.' '.AND.
     +       LIN(16:16).NE.' ') THEN
            IF (LIN(77:78).EQ.'  ') LIN(78:78)='H'
            WRITE (12,REC=IP,ERR=999) LIN
            GOTO 30
         END IF



         IAATYP=PRETYP(IP)

         IF (IAATYP.LE.0) GOTO 30
         IF (NUMNNA(IAATYP).LE.0) GOTO 30






            ATTYP=LIN(13:16)




         DO 10 IATT=1,ATPRAA(IAATYP)
            IF (ATTYP.EQ.MUTSTO4(IATT,IAATYP,1)) THEN



               IF (LIN(77:78).EQ.'  ') THEN
                  IF (IATT.LE.HATPRA(IAATYP)) THEN
                     LIN(77:77)=LIN(13:13)
                     LIN(78:78)=LIN(14:14)
                  ELSE
                     LIN(77:77)=' '
                     LIN(78:78)='H'
                  END IF
               END IF
               WRITE (12,REC=IP,ERR=999) LIN

               GOTO 30
            END IF
 10      CONTINUE
 30   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL033')
      IERR=1



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL034 (IERR)


















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       I, J, IATT, INNA, IERR, IAATP0, IAATP1, IAATP2, 
     +              MODEL, IM1, IP0, IP1, IP2, IP3, LEN0, LEN1, LEN2
      LOGICAL       MOL009, TXTPROTON, GVFISN
      CHARACTER*3   CHAR3
      CHARACTER*4   ATTYPM, ATTYP0, ATTYP1, ATTYP2, ATTYP3
      CHARACTER*80  LINM,   LIN0,   LIN1,   LIN2,   LIN3







      IF (PDBCNT(1).LT.4) GOTO 998
      IF (DINOUT) THEN
         DO 7 I=1,PDBCNT(1)
            READ (12,REC=I,ERR=999) LIN0
            CALL GVSTT6 (LIN0)
 7       CONTINUE
      END IF



      IERR=0
      PDBCNT(6)=0
      MODEL=0
      CALL GVSBTF (USEAT,PDBCNT(1))






      DO 30 I=PDBCNT(10),PDBCNT(11)-2
         IF (DINOU2.AND.MOD(I,100).EQ.0) CALL GVSCOD (' ')



         CALL MOL034B (I,IM1,IP0,IP1,IP2,IP3,LINM,LIN0,LIN1,LIN2,LIN3,
     +    IERR)
         IF (IERR.NE.0) GOTO 30
         IF (DINOU2) THEN
            CALL GVSTT6 ('?M4873')
            CALL GVSTT6 (LIN0)
            CALL GVSTT6 (LIN1)
            CALL GVSTT6 (LIN2)
         END IF




         IAATP0=PRETYP(IP0)
         IAATP1=PRETYP(IP1)
         IAATP2=PRETYP(IP2)
         IF (DINOU2) PRINT*,'AT -2',IAATP0,IAATP1,IAATP2
         IF (IAATP0.LE.0) GOTO 30
         IF (NUMNNA(IAATP0).LE.1) GOTO 30
         IF (IAATP0.NE.IAATP1.OR.IAATP1.NE.IAATP2)GOTO 30
         IF (LIN0(23:26).NE.LIN1(23:26).OR.LIN1(23:26).NE.
     +    LIN2(23:26)) GOTO 30
         IF (DINOU2) PRINT*,'AT 2'



         LEN0=0
         ATTYP0(4:4)=LIN0(16:16)
         IF (ATTYP0(4:4).NE.' ') LEN0=4
         ATTYP0(3:3)=LIN0(15:15)
         IF (LEN0.EQ.0.AND.ATTYP0(3:3).NE.' ') LEN0=3
         ATTYP0(2:2)=LIN0(14:14)
         IF (LEN0.EQ.0.AND.ATTYP0(2:2).NE.' ') LEN0=2
         ATTYP0(1:1)=LIN0(13:13)
         IF (LEN0.EQ.0.AND.ATTYP0(1:1).NE.' ') LEN0=1

         LEN1=0
         ATTYP1(4:4)=LIN1(16:16)
         IF (ATTYP1(4:4).NE.' ') LEN1=4
         ATTYP1(3:3)=LIN1(15:15)
         IF (LEN0.EQ.0.AND.ATTYP1(3:3).NE.' ') LEN1=3
         ATTYP1(2:2)=LIN1(14:14)
         IF (LEN0.EQ.0.AND.ATTYP1(2:2).NE.' ') LEN1=2
         ATTYP1(1:1)=LIN1(13:13)
         IF (LEN0.EQ.0.AND.ATTYP1(1:1).NE.' ') LEN1=1

         LEN2=0
         ATTYP2(4:4)=LIN2(16:16)
         IF (ATTYP2(4:4).NE.' ') LEN2=4
         ATTYP2(3:3)=LIN2(15:15)
         IF (LEN0.EQ.0.AND.ATTYP2(3:3).NE.' ') LEN2=3
         ATTYP2(2:2)=LIN2(14:14)
         IF (LEN0.EQ.0.AND.ATTYP2(2:2).NE.' ') LEN2=2
         ATTYP2(1:1)=LIN2(13:13)
         IF (LEN0.EQ.0.AND.ATTYP2(1:1).NE.' ') LEN2=1
         IF (LEN0.NE.LEN1.AND.LEN1.NE.LEN2) GOTO 30
         IF (LEN0.LE.2) GOTO 30
         IF (DINOU2) PRINT*,'AT 3 |',ATTYP0,'|',ATTYP1,'|',ATTYP2,'|'
         IF (ATTYP0(2:2).EQ.'H') THEN
            IF (ATTYP0(2:3).NE.ATTYP1(2:3).OR.ATTYP1(2:3).NE.
     +       ATTYP2(2:3)) GOTO 30
            IF (ATTYP0(1:1).EQ.' '.AND.(ATTYP1(1:1).NE.' '.OR.
     +       ATTYP2(1:1).NE.' ')) GOTO 30
            IF (ATTYP0(1:1).NE.' '.AND.(ATTYP1(1:1).EQ.' '.OR.
     +       ATTYP2(1:1).EQ.' ')) GOTO 30
         ELSE
            IF (ATTYP0(2:2).NE.ATTYP1(2:2).AND.ATTYP1(2:2).NE.
     +       ATTYP2(2:2)) GOTO 30
         END IF



         IF (IP3.LE.PDBCNT(1)) THEN






               ATTYP3=LIN3(13:16)

            IF (ATTYP2(1:3).EQ.ATTYP3(1:3)) GOTO 30
            IF (GVFISN(ATTYP2(1:1)).AND.ATTYP2(2:4).EQ.ATTYP3(2:4)) 
     +       GOTO 30
         END IF



         IF (IM1.GE.1) THEN






               ATTYPM=LINM(13:16)

            IF (ATTYP0(1:3).EQ.ATTYPM(1:3)) GOTO 30 
            IF (GVFISN(ATTYP0(1:1)).AND.ATTYP0(2:4).EQ.ATTYPM(2:4)) 
     +       GOTO 30
         END IF
         IF (DINOU2) PRINT*,'AT 4 |',ATTYP0,'|',ATTYP1,'|',ATTYP2,'|'



         DO 20 INNA=2,NUMNNA(IAATP0)
            DO 10 IATT=1,ATPRAA(IAATP0)-2
               IF (DINOU2) PRINT*,'TRY INNA=',
     +          INNA,MUTSTO4(IATT+0,IAATP0,INNA),
     +          MUTSTO4(IATT+1,IAATP0,INNA),MUTSTO4(IATT+2,IAATP0,INNA)
               IF (DINOU2) PRINT*,'FITS #1? :',
     +             ATTYP0.NE.MUTSTO4(IATT+0,IAATP0,1).OR.
     +             ATTYP1.NE.MUTSTO4(IATT+1,IAATP0,1).OR.
     +             ATTYP2.NE.MUTSTO4(IATT+2,IAATP0,1),'|',ATTYP0,'|',
     +             ATTYP1,'|',ATTYP2,'||',MUTSTO4(IATT+0,IAATP0,1),'|',
     +             MUTSTO4(IATT+1,IAATP0,1),'|',
     +             MUTSTO4(IATT+2,IAATP0,1),'|'
               IF (ATTYP0.EQ.MUTSTO4(IATT+0,IAATP0,INNA).AND.
     +             ATTYP1.EQ.MUTSTO4(IATT+1,IAATP0,INNA).AND.
     +             ATTYP2.EQ.MUTSTO4(IATT+2,IAATP0,INNA).AND.
     +       .NOT.(ATTYP0.EQ.MUTSTO4(IATT+0,IAATP0,1).AND.
     +             ATTYP1.EQ.MUTSTO4(IATT+1,IAATP0,1).AND.
     +             ATTYP2.EQ.MUTSTO4(IATT+2,IAATP0,1))) THEN

                  IF (DINOUT) THEN
                     CALL GVSTT6 ('?M4874')
                     CALL GVSTT6 (LIN0)
                     CALL GVSTT6 (LIN1)
                     CALL GVSTT6 (LIN2)
                  END IF
                  CALL MOL034A (PDBCNT(6),MODEL,LIN2)



                  LIN0(13:13)=MUTSTO4(IATT+0,IAATP0,1)(1:1)
                  LIN0(14:14)=MUTSTO4(IATT+0,IAATP0,1)(2:2)
                  LIN0(15:15)=MUTSTO4(IATT+0,IAATP0,1)(3:3)
                  LIN0(16:16)=MUTSTO4(IATT+0,IAATP0,1)(4:4)
                  LIN1(13:13)=MUTSTO4(IATT+1,IAATP0,1)(1:1)
                  LIN1(14:14)=MUTSTO4(IATT+1,IAATP0,1)(2:2)
                  LIN1(15:15)=MUTSTO4(IATT+1,IAATP0,1)(3:3)
                  LIN1(16:16)=MUTSTO4(IATT+1,IAATP0,1)(4:4)
                  LIN2(13:13)=MUTSTO4(IATT+2,IAATP0,1)(1:1)
                  LIN2(14:14)=MUTSTO4(IATT+2,IAATP0,1)(2:2)
                  LIN2(15:15)=MUTSTO4(IATT+2,IAATP0,1)(3:3)
                  LIN2(16:16)=MUTSTO4(IATT+2,IAATP0,1)(4:4)
                  WRITE (12,REC=IP0,ERR=999) LIN0
                  WRITE (12,REC=IP1,ERR=999) LIN1
                  WRITE (12,REC=IP2,ERR=999) LIN2
                  PRINT*,'AT 1: LIN2=',LIN0
                  PRINT*,'AT 1: LIN2=',LIN1
                  PRINT*,'AT 1: LIN2=',LIN2
                  USEAT(IP0)=.TRUE.
                  USEAT(IP1)=.TRUE.
                  USEAT(IP2)=.TRUE.
                  IF (DINOUT) THEN
                     CALL GVSTT6 ('?M4875')
                     CALL GVSTT6 (LIN0)
                     CALL GVSTT6 (LIN1)
                     CALL GVSTT6 (LIN2)
                     IF (DINOU2) CALL GVSCOD (' ')
                  END IF
                  PDBCNT(6)=PDBCNT(6)+1
                  GOTO 30
               END IF
 10         CONTINUE
 20      CONTINUE
 30   CONTINUE



      DO 60 I=1,PDBCNT(10),PDBCNT(11)-1



         CALL MOL034C (I,IM1,IP0,IP1,IP2,LINM,LIN0,LIN1,LIN2,IERR)
         IF (IERR.NE.0) GOTO 60
         IF (DINOU2) THEN
            CALL GVSTT6 ('?M4876')
            CALL GVSTT6 (LIN0)
            CALL GVSTT6 (LIN1)
         END IF




         IAATP0=PRETYP(IP0)
         IF (IAATP0.LE.0) GOTO 60
         IF (NUMNNA(IAATP0).LE.1) GOTO 60
         IAATP1=PRETYP(IP1)
         IF (IAATP0.NE.IAATP1.OR.IAATP0.EQ.0) GOTO 60
         IF (LIN0(23:26).NE.LIN1(23:26)) GOTO 60



         LEN0=0
         ATTYP0(4:4)=LIN0(16:16)
         IF (ATTYP0(4:4).NE.' ') LEN0=4
         ATTYP0(3:3)=LIN0(15:15)
         IF (LEN0.EQ.0.AND.ATTYP0(3:3).NE.' ') LEN0=3
         ATTYP0(2:2)=LIN0(14:14)
         IF (LEN0.EQ.0.AND.ATTYP0(2:2).NE.' ') LEN0=2
         ATTYP0(1:1)=LIN0(13:13)
         IF (LEN0.EQ.0.AND.ATTYP0(1:1).NE.' ') LEN0=1
         LEN1=0
         ATTYP1(4:4)=LIN1(16:16)
         IF (ATTYP1(4:4).NE.' ') LEN0=4
         ATTYP1(3:3)=LIN1(15:15)
         IF (LEN1.EQ.0.AND.ATTYP1(3:3).NE.' ') LEN1=3
         ATTYP1(2:2)=LIN1(14:14)
         IF (LEN1.EQ.0.AND.ATTYP1(2:2).NE.' ') LEN1=2
         ATTYP1(1:1)=LIN1(13:13)
         IF (LEN1.EQ.0.AND.ATTYP1(1:1).NE.' ') LEN1=1
         IF (ATTYP0(2:2).EQ.'H') THEN
            IF (ATTYP0(2:3).NE.ATTYP1(2:3)) GOTO 60
            IF (ATTYP0(1:1).EQ.' '.AND.ATTYP1(1:1).NE.' ') GOTO 60
            IF (ATTYP0(1:1).NE.' '.AND.ATTYP1(1:1).EQ.' ') GOTO 60
         END IF



         IF (IP2.LE.PDBCNT(1)) THEN






               ATTYP3(1:4)=LIN2(13:16)

            IF (ATTYP1(1:3).EQ.ATTYP3(1:3)) GOTO 60
         END IF



         IF (IM1.GE.1) THEN






               ATTYPM(1:4)=LINM(13:16)

            IF (ATTYP0(1:3).EQ.ATTYPM(1:3)) GOTO 60
         END IF



         DO 50 INNA=2,NUMNNA(IAATP0)
            DO 40 IATT=1,ATPRAA(IAATP0)-1
               IF (ATTYP0.EQ.MUTSTO4(IATT+0,IAATP0,INNA).AND.
     +             ATTYP1.EQ.MUTSTO4(IATT+1,IAATP0,INNA).AND.
     +            (ATTYP0.NE.MUTSTO4(IATT+0,IAATP0,1).OR.
     +             ATTYP1.NE.MUTSTO4(IATT+1,IAATP0,1))) THEN
                  IF (DINOUT) THEN
                     CALL GVSTT6 ('?M4874')
                     CALL GVSTT6 (LIN0)
                     CALL GVSTT6 (LIN1)
                  END IF
                  CALL MOL034A (PDBCNT(6),MODEL,LIN2)
                  LIN0(13:13)=MUTSTO4(IATT+0,IAATP0,1)(1:1)
                  LIN0(14:14)=MUTSTO4(IATT+0,IAATP0,1)(2:2)
                  LIN0(15:15)=MUTSTO4(IATT+0,IAATP0,1)(3:3)
                  LIN0(16:16)=MUTSTO4(IATT+0,IAATP0,1)(4:4)
                  LIN1(13:13)=MUTSTO4(IATT+1,IAATP0,1)(1:1)
                  LIN1(14:14)=MUTSTO4(IATT+1,IAATP0,1)(2:2)
                  LIN1(15:15)=MUTSTO4(IATT+1,IAATP0,1)(3:3)
                  LIN1(16:16)=MUTSTO4(IATT+1,IAATP0,1)(4:4)
                  WRITE (12,REC=IP0,ERR=999) LIN0
                  WRITE (12,REC=IP1,ERR=999) LIN1
                  PRINT*,'AT 2: LIN2=',LIN0
                  PRINT*,'AT 3: LIN2=',LIN1
                  USEAT(IP0)=.TRUE.
                  USEAT(IP1)=.TRUE.
                  IF (DINOUT) THEN
                     CALL GVSTT6 ('?M4875')
                     CALL GVSTT6 (LIN0)
                     CALL GVSTT6 (LIN1)  
                     IF (DINOU2) CALL GVSCOD (' ')
                  END IF
                  PDBCNT(6)=PDBCNT(6)+1
                  GOTO 60
               END IF
 40         CONTINUE
 50      CONTINUE
 60   CONTINUE



      DO 160 IP0=PDBCNT(10),PDBCNT(11)
         IF (USEAT(IP0)) GOTO 160
         READ (12,REC=IP0,ERR=999) LIN0
         IF (LIN0(1:4).NE.'ATOM') GOTO 160



         IAATP0=PRETYP(IP0)
         IF (IAATP0.LE.0) GOTO 160
         IF (NUMNNA(IAATP0).LE.1) GOTO 160
         IF (DINOU2) THEN
            CALL GVSTT6 ('?M4877')
            CALL GVSTT6 (LIN0)
         END IF



         LEN0=0
         ATTYP0(4:4)=LIN0(16:16)
         IF (ATTYP0(4:4).NE.' ') LEN0=4
         ATTYP0(3:3)=LIN0(15:15)
         IF (LEN0.EQ.0.AND.ATTYP0(3:3).NE.' ') LEN0=3
         ATTYP0(2:2)=LIN0(14:14)
         IF (LEN0.EQ.0.AND.ATTYP0(2:2).NE.' ') LEN0=2
         ATTYP0(1:1)=LIN0(13:13)
         IF (LEN0.EQ.0.AND.ATTYP0(1:1).NE.' ') LEN0=1
         IF (TXTPROTON(ATTYP0,LIN0(77:78))) GOTO 160



         DO 150 INNA=2,NUMNNA(IAATP0)
            DO 140 IATT=1,ATPRAA(IAATP0)-1
               IF (ATTYP0.EQ.MUTSTO4(IATT,IAATP0,INNA)) THEN
                  IF (MUTSTO4(IATT,IAATP0,INNA).EQ.
     +             MUTSTO4(IATT,IAATP0,1)) GOTO 140
                  IF (DINOUT) THEN
                     CALL GVSTT6 ('?M4874')
                     CALL GVSTT6 (LIN0)
                  END IF
                  CALL MOL034A (PDBCNT(6),MODEL,LIN2)
                  LIN0(13:13)=MUTSTO4(IATT+0,IAATP0,1)(1:1)
                  LIN0(14:14)=MUTSTO4(IATT+0,IAATP0,1)(2:2)
                  LIN0(15:15)=MUTSTO4(IATT+0,IAATP0,1)(3:3)
                  LIN0(16:16)=MUTSTO4(IATT+0,IAATP0,1)(4:4)
                  WRITE (12,REC=IP0,ERR=999) LIN0
                  PRINT*,'AT 3: LIN0=',LIN0
                  USEAT(IP0)=.TRUE.
                  IF (DINOUT) THEN
                     CALL GVSTT6 ('?M4875')
                     CALL GVSTT6 (LIN0)
                     IF (DINOU2) CALL GVSCOD (' ')
                  END IF
                  PDBCNT(6)=PDBCNT(6)+1
                  GOTO 160
               END IF
 140        CONTINUE
 150     CONTINUE
 160  CONTINUE



      DO 70 I=PDBCNT(10),PDBCNT(11)
         READ (12,REC=I,ERR=999) LIN0
         IF (LIN0(13:14).EQ.'*H') THEN
            CALL GVSSTX (CHAR3,LIN0(14:16))
            CALL GVSSTX (LIN0(13:15),CHAR3)
            LIN0(16:16)='*'
            CALL MOL034A (PDBCNT(6),MODEL,LIN0)
            PDBCNT(6)=PDBCNT(6)+1
            WRITE (12,REC=I,ERR=999) LIN0
                  PRINT*,'AT 4: LIN0=',LIN0
            IF (DINOUT) PRINT*,'2 OUT',LIN0(1:50)
         END IF
         IF (LIN0(16:16).NE.' ') GOTO 70
         IF (LIN0(13:14).EQ.'P ') THEN
            CALL GVSSTX (CHAR3,LIN0(13:15))
            CALL GVSSTX (LIN0(14:16),CHAR3)
            LIN0(13:13)=' '
            CALL MOL034A (PDBCNT(6),MODEL,LIN0)
            PDBCNT(6)=PDBCNT(6)+1
            WRITE (12,REC=I,ERR=999) LIN0
                  PRINT*,'AT 5: LIN0=',LIN0
            IF (DINOUT) PRINT*,'3 OUT',LIN0(1:50)
            GOTO 70
         END IF
 70   CONTINUE



      IF (WIFPAR(279).EQ.0) THEN
         DO 80 I=1,PDBCNT(10),PDBCNT(11)
            DO 71 J=1,80
               LINM(J:J)=' '
 71         CONTINUE
            READ (12,REC=I,ERR=999) LINM
            IF (LINM(1:6).NE.'ATOM  '.AND.LINM(1:6).NE.'HETATM') GOTO 80
            IF (LINM(27:27).NE.' ') THEN
               IF (MOL009(LINM(18:21))) THEN
                  IF (DINOUT) PRINT*,'4 OUT',LINM(1:50)
                  LINM(27:27)=' '
                  WRITE (12,REC=I,ERR=999) LINM
                  PDBCNT(9)=PDBCNT(9)+1
               END IF
            END IF
 80      CONTINUE
      END IF



      IF (PDBCNT(6).GT.0) THEN
         CALL GVSTTI ('?M4590',PDBCNT(6))
         CALL MOL034A (-1,MODEL,LIN2)
      END IF
      IF (PDBCNT(9).GT.0) THEN
         CALL GVSTTI ('?M4591',PDBCNT(9))
      END IF
      IERR=0
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL034')
      IERR=1



  998 CONTINUE
      IF (DINOUT) THEN
         DO 77 I=1,PDBCNT(1)
            READ (12,REC=I,ERR=999) LIN0
            CALL GVSTT6 (LIN0)
 77      CONTINUE
      END IF


      RETURN
      END   
      SUBROUTINE MOL034A (COUNTR,MODEL,INLINE)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       COUNTR, IUNIT, MODEL
      LOGICAL       GVFIBN, GOTFILE
      CHARACTER*80  INLINE
      SAVE          IUNIT







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



      IF (COUNTR.EQ.0) THEN
         IF (.NOT.GOTFILE(IUNIT,'NMRALT.ATM')) GOTO 999
      END IF



      IF (COUNTR.LT.0) THEN
         IF (.NOT.GVFIBN(IUNIT,1,120)) GOTO 999
         CALL GVSCLF (IUNIT)
      END IF



      IF (COUNTR.GE.1) THEN
         IF (INLINE(17:17).EQ.' ') GOTO 998
         CALL GVSFMT ('?FMT755B')
         WRITE (IUNIT,FMT,ERR=999) INLINE(23:26),MODEL
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIW ('MOL034A')
      CALL GVSKIL



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL034B (I,IM1,IP0,IP1,IP2,IP3,LINM,LIN0,LIN1,LIN2,
     + LIN3,IERR)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       I, J, IM1, IP0, IP1, IP2, IP3, MODEL, IERR, GVFLFI
      CHARACTER*1   CM, C0, C1, C2, C3
      CHARACTER*80  LINM, LIN0, LIN1, LIN2, LIN3







      IERR=0
      IM1=I-1
      IP0=I+0
      IP1=I+1
      IP2=I+2
      IP3=I+3



      READ (12,REC=IP0,ERR=999) LIN0



      IF (LIN0(1:5).EQ.'MODEL') THEN
         J=GVFLFI(1,MODEL,LIN0)
         IF (J.NE.1) CALL GVST6C ('?M4592',LIN0,.TRUE.)
         IERR=1
         GOTO 998
      END IF
      IF (LIN0(1:4).NE.'ATOM') THEN
         IERR=1
         GOTO 998
      END IF
      C0=LIN0(17:17)



 10   CONTINUE
      IF (IP1.GE.PDBCNT(1)) THEN
         IERR=1
         GOTO 998
      END IF
      READ (12,REC=IP1,ERR=999) LIN1
      C1=LIN1(17:17)
      IF (LIN1(1:4).NE.'ATOM'.OR.C1.NE.C0) THEN
         IP1=IP1+1
         IP2=IP2+1
         IP3=IP3+1
         GOTO 10
      END IF



 20   CONTINUE
      IF (IP2.GT.PDBCNT(1)) THEN
         IERR=1
         GOTO 998
      END IF
      READ (12,REC=IP2,ERR=999) LIN2
      C2=LIN2(17:17)
      IF (LIN2(1:4).NE.'ATOM'.OR.C2.NE.C0) THEN
         IP2=IP2+1
         IP3=IP3+1
         GOTO 20
      END IF



 30   CONTINUE
      IF (IM1.LE.0) THEN
         IM1=0
         CALL GVSCTB (LINM,80)
      ELSE
         READ (12,REC=IM1,ERR=999) LINM
         CM=LINM(17:17)
         IF (LINM(1:4).NE.'ATOM'.OR.CM.NE.C0) THEN
            IM1=IM1-1
            GOTO 30
         END IF
      END IF



 40   CONTINUE
      IF (IP3.GT.PDBCNT(1)) THEN
         CALL GVSCTB (LIN3,80)
         GOTO 998
      END IF
      READ (12,REC=IP3,ERR=999) LIN3
      C3=LIN3(17:17)
      IF (LIN3(1:4).NE.'ATOM'.OR.C3.NE.C0) THEN
         IP3=IP3+1
         GOTO 40
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIR ('MOL034B')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL034C (I,IM1,IP0,IP1,IP2,LINM,LIN0,LIN1,LIN2,IERR)

















      IMPLICIT      NONE
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       I, J, IM1, IP0, IP1, IP2, MODEL, IERR, GVFLFI
      CHARACTER*1   CM, C0, C1, C2
      CHARACTER*80  LINM, LIN0, LIN1, LIN2







      IERR=0
      IM1=I-1
      IP0=I+0
      IP1=I+1
      IP2=I+2



      READ (12,REC=IP0,ERR=999) LIN0



      IF (LIN0(1:5).EQ.'MODEL') THEN
         J=GVFLFI(1,MODEL,LIN0)
         IF (J.NE.1) CALL GVST6C ('?M4592',LIN0,.TRUE.)
         IERR=1
         GOTO 998
      END IF
      IF (LIN0(1:4).NE.'ATOM') THEN
         IERR=1
         GOTO 998
      END IF
      C0=LIN0(17:17)



 10   CONTINUE
      IF (IP1.GE.PDBCNT(1)) THEN
         IERR=1
         GOTO 998
      END IF
      READ (12,REC=IP1,ERR=999) LIN1
      C1=LIN1(17:17)
      IF (LIN1(1:4).NE.'ATOM'.OR.C1.NE.C0) THEN
         IP1=IP1+1
         IP2=IP2+1
         GOTO 10
      END IF



 30   CONTINUE
      IF (IM1.LE.0) THEN
         IM1=0
         CALL GVSCTB (LINM,80)
      ELSE
         READ (12,REC=IM1,ERR=999) LINM
         CM=LINM(17:17)
         IF (LINM(1:4).NE.'ATOM'.OR.CM.NE.C0) THEN
            IM1=IM1-1
            GOTO 30
         END IF
      END IF



 40   CONTINUE
      IF (IP2.GT.PDBCNT(1)) THEN
         CALL GVSCTB (LIN2,80)
         GOTO 998
      END IF
      READ (12,REC=IP2,ERR=999) LIN2
      C2=LIN2(17:17)
      IF (LIN2(1:4).NE.'ATOM'.OR.C2.NE.C0) THEN
         IP2=IP2+1
         GOTO 40
      END IF
      GOTO 998



  999 CONTINUE
      CALL GVSEIR ('MOL034C')



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL040 (IERR)

















      IMPLICIT      NONE
      INCLUDE       'GETMOL.INC'
      INCLUDE       'ESPACE.INC'
      INTEGER       IERR, I, J
      LOGICAL       GVFFOP
      CHARACTER*80  LOCLIN, LOCLN2








      IF (.NOT.GVFFOP(12)) THEN
         CALL GVSTTB ('?M3561A')
         IERR=1
         CALL GVSKIL
         GOTO 998
      END IF



      IERR=0



      DO 30 I=PDBCNT(10),PDBCNT(11)
         READ (12,REC=I,ERR=999) LOCLIN
         IF (LOCLIN(1:4).NE.'ATOM'.AND.LOCLIN(1:6).NE.'HETATM') GOTO 30
         IF (LOCLIN(17:17).EQ.' ') GOTO 30



         IF (I.GE.2) THEN
            DO 10 J=I-1,1,-1
               READ (12,REC=J,ERR=999) LOCLN2
               IF (LOCLN2(1:4).NE.'ATOM'.AND.LOCLN2(1:6).NE.'HETATM') 
     +          GOTO 10
               IF (LOCLN2(18:21).NE.LOCLIN(18:21)) GOTO 11
               IF (LOCLN2(22:26).NE.LOCLIN(22:26)) GOTO 11
               IF (LOCLN2(13:16).NE.LOCLIN(13:16)) GOTO 10
               IF (LOCLN2(17:17).EQ.' ') THEN
                  CALL ALT002 ('?M3562A',LOCLIN,LOCLN2)
               ELSE IF (LOCLIN(17:17).EQ.LOCLN2(17:17)) THEN
                  CALL ALT002 ('?M3563',LOCLIN,LOCLN2)
               END IF
               GOTO 30
 10         CONTINUE
 11         CONTINUE
         END IF
         IF (I.LT.PDBCNT(11)) THEN
            DO 20 J=I+1,PDBCNT(11)
               READ (12,REC=J,ERR=999) LOCLN2
               IF (LOCLN2(1:4).NE.'ATOM'.AND.LOCLN2(1:6).NE.'HETATM') 
     +          GOTO 20
               IF (LOCLN2(18:21).NE.LOCLIN(18:21)) GOTO 21
               IF (LOCLN2(22:26).NE.LOCLIN(22:26)) GOTO 21
               IF (LOCLN2(13:16).NE.LOCLIN(13:16)) GOTO 20
               IF (LOCLN2(17:17).EQ.' ') THEN
                  CALL ALT002 ('?M3562A',LOCLIN,LOCLN2)
               ELSE IF (LOCLIN(17:17).EQ.LOCLN2(17:17)) THEN
                  CALL ALT002 ('?M3563',LOCLIN,LOCLN2)
               END IF
               GOTO 30
 20         CONTINUE
 21         CONTINUE
         END IF
         CALL GVSCTB (LOCLN2,80)
         CALL ALT002 ('?M3564',LOCLIN,LOCLN2)
         LOCLIN(17:17)=' '
         WRITE (12,REC=I,ERR=999) LOCLIN
 30   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIR ('MOL040')



  998 CONTINUE



      RETURN
      END   
      SUBROUTINE MOL042

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'










      CALL MOL042A







      CALL MOL043



      CALL GVSRT0 (PRPVAL,NUMAAT)





      RETURN
      END   
      SUBROUTINE MOL042A

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'PDBINC.INC'
      INTEGER       IAA, IUNIT, IKILL, IKEEP
      REAL          C1(3), C2(3), A1(3), A2(3), D12
      LOGICAL       GVFYON, FIRST, WIFIRW, GVFISF, GOTFILE







      CALL WIFPUSHPPP (1071,1)
      IF (WIFPAR(622).EQ.2) GOTO 998
      IF (NUMAAF.LE.1) GOTO 998
      IF (NUMAAT.LE.1) THEN
         CALL GVSCODA ('Strange, NUMAAT <=1 in MOL042A')
         GOTO 998
      END IF



      IF (WIFPAR(1276).GE.1) CALL MOL038



      FIRST=.TRUE.
      IUNIT=0
      FIXLST(13)=0.0
      IF (WIFPAR(622).EQ.3) CALL DRG108
      IF (WIFPAR(279).NE.0) THEN
         IF (GVFISF('REMOVED.LIS')) CALL GVSDEL ('REMOVED.LIS')
      END IF



      CALL SHOSOU
      DO 10 IAA=2,NUMAAT
         IF (WIFIRW(IAA)) GOTO 10
         IF (NOBOND(IAA).OR.NOBOND(IAA-1)) GOTO 10
         IF (MODNMB(IAA).NE.MODNMB(IAA-1)) GOTO 10
         IF (PNTAAE(IAA).EQ.PNTAAS(IAA)) GOTO 10
         CALL WIFELA (IAA,C1,A1)
         CALL WIFELA (IAA-1,C2,A2)
         D12=SQRT((C1(1)-C2(1))**2+(C1(2)-C2(2))**2+(C1(3)-C2(3))**2)
         IF (D12.LT.0.666*A1(3).AND.D12.LT.0.666*A2(3)) THEN



            IF (WIFPAR(622).EQ.1.AND.FIRST) THEN
               IF (.NOT.GVFYON('?M0167',' ')) GOTO 998
               FIRST=.FALSE.
            END IF
            IF (WIFPAR(279).NE.0) THEN
               IF (GVFISF('REMOVED.LIS')) CALL GVSDEL ('REMOVED.LIS')
               IF (.NOT.GOTFILE(IUNIT,'REMOVED.LIS')) THEN
                  CALL GVSTTB ('storing removed residue list')
               END IF
            END IF



            IF (WEIGHT(PNTAAC(IAA)).LE.WEIGHT(PNTAAC(IAA-1))) THEN
               IKILL=IAA
               IKEEP=IAA-1
            ELSE
               IKILL=IAA-1
               IKEEP=IAA
            END IF
            IF (WIFPAR(279).NE.0) THEN
               FIXLST(13)=FIXLST(13)+1.0
               FIXRES(IKEEP)=FIXRES(IKEEP)+10.0
            END IF



            IF (WIFPAR(279).NE.0.AND.IUNIT.NE.0) THEN
               CALL GVSCTB (BIGLIN,132)
               CALL PDBC92A (IKILL,0)
               CALL GVSSTX (BIGLIN,LINE92(1:28))
               CALL PDBC92A (IKEEP,0)
               CALL GVSSTX (BIGLIN(29:56),LINE92(1:28))
               WRITE (BIGLIN(60:65),'(F6.1)',ERR=999) D12
               CALL GVSTTU (IUNIT,BIGLIN)

            END IF
         END IF
 10   CONTINUE



      DO 20 IAA=NUMAAT,1,-1
         IF (FIXRES(IAA).GT.9.5) THEN
            CALL DIF008 ('?M0168',IAA)
            CALL MOL105 (IAA)
            CALL MOL200
         END IF
 20   CONTINUE



      IF (WIFPAR(279).EQ.0) CALL MOL042B
      GOTO 998



 999  CONTINUE
      CALL GVSEIW ('MOL042A')



  998 CONTINUE
      CALL WIFPOPPPP (1071)
      IF (IUNIT.NE.0) THEN
         CALL GVSTTU (IUNIT,'*END')
         CALL GVSCLF (IUNIT)
      END IF


      RETURN
      END   
      SUBROUTINE MOL042B

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INCLUDE       'SYMINC.INC'
      INCLUDE       'CNTINC.INC'
      INCLUDE       'IRIGRA.INC'
      INTEGER       ISYM, SYMNEG, IAA, JAA, IAT, JAT, ICONT, 
     +              JSYM, NUMOUT
      REAL          D12, TMP(3), TMPRAD
      LOGICAL       AREBOUNDS, AREB13, GVFYON, ISMETAL







      NUMOUT=0
      CALL WIFPUSHPPP (56,-100)
      CALL WIFPUSHPPP (590,0)



      IF (WIFPAR(448).GE.1) GOTO 998



      CALL ENVNOWAT



      DO 100 IAA=1,NUMAAT
         CALL FCONAA (IAA,MAX(0.01,FLOAT(WIFPAR(56))/100.0),.TRUE.)
         DO 95 ICONT=1,NUMCONIAA
            JAA=CONIAA(ICONT)



            IF (JAA.LE.IAA) GOTO 95
            IF (ABS(IAA-JAA).LE.1.AND.CHAINN(2,IAA).EQ.
     +       CHAINN(2,JAA)) GOTO 95



            JSYM=CONSYMAA(ICONT)
            ISYM=SYMNEG(JSYM)



            DO 90 IAT=PNTAAS(IAA),PNTAAE(IAA)
               IF (.NOT.ISATOK(IAT).OR.PROTON(IAT)) GOTO 90
               TMP(1)=XCOORD(IAT)
               TMP(2)=YCOORD(IAT)
               TMP(3)=ZCOORD(IAT)
               TMPRAD=FLOAT(WIFPAR(56))/100.0+VDWRAD(IAT)
               DO 85 JAT=PNTAAS(JAA),PNTAAE(JAA)
                  IF (.NOT.ISATOK(JAT).OR.PROTON(JAT)) GOTO 85
                  IF (WEIGHT(IAT)+WEIGHT(JAT).LE.1.01) GOTO 85



                  D12=(TMP(1)-XCOORD(JAT))**2+
     +                (TMP(2)-YCOORD(JAT))**2+
     +                (TMP(3)-ZCOORD(JAT))**2
                  IF (D12.LT.(TMPRAD+VDWRAD(JAT))**2) THEN



                     IF (AREBOUNDS(IAT,JAT,JSYM)) GOTO 85
                     IF (AREB13(IAT,JAT,JSYM)) GOTO 85



                     IF (ISMETAL(IAT).OR.ISMETAL(JAT)) THEN
                        IF (D12.GT.1.0) GOTO 85
                     END IF



                     NUMOUT=NUMOUT+1
                  END IF
   85          CONTINUE
   90       CONTINUE
   95    CONTINUE
  100 CONTINUE



      WIFPAR(1178)=0
      IF (NUMOUT.GT.NUMATF/4) THEN
         CALL SHOWTEXT ('?M2400')
         CALL GVSTTI ('?M2399',NUMOUT)

            STOP 'STRUCTURE FAR TOO BAD          '

      END IF



 998  CONTINUE
      CALL WIFPOPPPP (590)
      CALL WIFPOPPPP (56)


      RETURN
      END
      SUBROUTINE MOL043

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       IAA
      LOGICAL       WIFBOK, WIFIR1







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



      DO 100 IAA=NUMAAF,1,-1
         IF (WIFIR1(IAA)) THEN
            IF (.NOT.WIFBOK(IAA)) THEN
               CALL MOL105 (IAA)
               CALL MOL200
            END IF
         END IF
 100  CONTINUE



  998 CONTINUE


      RETURN
      END   
      SUBROUTINE MOL044 (NUMLIN,NUMCOD)

















      IMPLICIT      NONE
      INCLUDE       'BIGINC.INC'
      INTEGER       NUMLIN, NUMCOD, ILCNT, ILPNT
      LOGICAL       GVFFOP
      CHARACTER*80  LOCLIN







      IF (.NOT.GVFFOP(12)) THEN
         CALL GVSTTB ('Direct access file not open')
         GOTO 998
      END IF



      ILCNT=0



      DO 10 ILPNT=1,10000000
         READ (12,REC=ILPNT,ERR=999) LOCLIN
         IF (LOCLIN(1:4).EQ.'ATOM'.OR.LOCLIN(1:6).EQ.'HETATM') THEN
            ILCNT=ILCNT+1
            CALL GVSTT6 (LOCLIN)
            IF (ILCNT.GE.NUMLIN) GOTO 998
            IF (MOD(ILCNT,NUMCOD).EQ.0) CALL GVSCOD (' ')
         END IF
 10   CONTINUE
      GOTO 998



  999 CONTINUE
      CALL GVSEIR ('MOL044')



  998 CONTINUE


      RETURN
      END   
