       !************************************************************************
       !   A Subroutine of Main, Puting the coordinates in a sequence          *
       !   Return a Array SeqIndex(Site#,1~4) /Model#/Chain#/Residue#/Atom#/   *
       !************************************************************************
       
       Subroutine SequPDB(PDBid, MinModel, MaxModel, MinChain, MaxChain, MinResidue, MaxResidue, MinAtom, MaxAtom, ATM, AANm, vd, Site, SeqIndex, Seq )
       
       Implicit None
       
! ---- Variables : -------------------------------------------------------------- !       
       Character*4 PDBid
       
       Integer    MinModel, MinChain, MinResidue, MinAtom  ! The initial Min value is set to an extreme big value
       Integer    MaxModel, MaxChain, MaxResidue, MaxAtom  ! The initial Max value is set to an extreme small value
       
! ---- Variables : -------------------------------------------------------------- !       
       Character   ATM(   MinModel:MaxModel, MinChain:MaxChain, MinResidue:MaxResidue, MinAtom:MaxAtom )*4    ! The Name of atom
       Character   AANm(  MinModel:MaxModel, MinChain:MaxChain, MinResidue:MaxResidue, MinAtom:MaxAtom )*3    ! The Name of residue
       
       Integer     vd(  MinModel:MaxModel, MinChain:MaxChain, MinResidue:MaxResidue, MinAtom:MaxAtom )        ! Record the existence of the ATOM :
                                                                                                              ! Amino Acids Atom   : vd=1
                                                                                                              ! Nucleic Acids Atom : vd=2
       Integer      Site
       
       Integer      SeqIndex(1:Site, 1:4)     ! Array SeqIndex(Site#,1/2/3/4) /Model#/Chain#/Residue#/Atom#/  
       Integer      Seq( MinModel:MaxModel, MinChain:MaxChain, MinResidue:MaxResidue, MinAtom:MaxAtom ) ! The sequential number of a certain node at (k,j,i,s)
       
! ---- Variables : -------------------------------------------------------------- !      
       Character*4  ATNAME       
       Integer      i, j, k, s, ct
       
! ---- Variables : -------------------------------------------------------------- !      
       Logical      NodeExist
       Character*4  NodeAtom(MaxAtom)
       Integer      m, MaxNode
       
! =============================================================================== !

! ------------------------------------------------------- Read in the 'PDB Nodes Atoms.inp' File
       INQUIRE (FILE='PDB Nodes Atoms.inp', EXIST=NodeExist) 
       If(NodeExist==.False.) Then
            Write(*,*) PDBid, '  Error! Can not find the [PDB Nodes Atoms.inp] file. '
            Stop
       EndIf
       
       Open (111, FILE='PDB Nodes Atoms.inp')
       
       m=0
       Read(111,'(A4)')  ATNAME
       Do While(ATNAME.NE.'====')
          m=m+1
          NodeAtom(m) = ATNAME
          Read(111,'(A4)')  ATNAME
       Enddo
       MaxNode=m
       
       Close(111) ! FILE='PDB Nodes Atoms.inp'
            

! ------------------------------------------------------------------------------- !
       
       Do k=MinModel, MaxModel ! *-*-*-*-*-* Initializing 
          Do j=MinChain, MaxChain
            Do i=MinResidue, MaxResidue
              Do s=MinAtom, MaxAtom 
                 Seq(k,j,i,s)=0
              Enddo  ! s
            Enddo  ! i
          Enddo  ! j       
       Enddo ! k ! *-*-*-*-*-*-*-*-*-*-*-*-* Initializing                 
       
       Open(31, File=PDBid//'_Sequence.dat')
       
       Write(31,'(A)') '     Sequence#   Model#   Chain#  Residue#   Atom#  '
       
       
       ct=0  ! ===================================== Puting the coordinates in a sequence
       Do k=MinModel, MaxModel
          Do j=MinChain, MaxChain
            Do i=MinResidue, MaxResidue
              Do s=MinAtom, MaxAtom                
              
                 IF(vd(k,j,i,s)>0) Then
                 
                    ATNAME=ATM(k,j,i,s)                 
                    
                    Do m=1, MaxNode
                    
                        If( ATNAME==NodeAtom(m) ) Then 
                        
                            ct = ct+1                                     
                               
                            SeqIndex(ct,1) = k
                            SeqIndex(ct,2) = j
                            SeqIndex(ct,3) = i
                            SeqIndex(ct,4) = s
                            
                            Seq(k,j,i,s)=ct
                       
                            Write(31,'(I12,4(4x,I5))') ct, k, j, i, s

                        EndIF
                        
                    Enddo  ! m                                                                             
                    
                 EndIF  ! IF(vd(k,j,i,s)>0)
                 
              Enddo  ! s
            Enddo  ! i
          Enddo  ! j       
       Enddo ! k ! ===================================== Puting the coordinates in a sequence
              
       Close(31) ! PDBid//'_Sequence.dat'
       
       
! =====E==N===D================================================================== !
       Return
       End           
        
                                                                         