

tell nseg select="ALL"  #tell segments count in the system

iseg=0
while($iseg<$nseg) {     #loop over all segments
  tell segn $iseg select="ALL"   #tell segment name and residues count
  echo -hs "segment $segn has $nres residues"
  ires=0
  while($ires<$nres) {   #loop over all residues in current segment
    tell resn $ires select="segn $segn"  #tell residue name,iseq, and atoms count
    echo -hs  "            $iseq $resn has $natom atoms"
    ia=0
    if(-var tellatom) {
      echo -hsn "               + atom: " 
      while($ia<$natom) {  #loop over all atoms in current residue
        tell atomn $ia select="segn $segn $iseg" #tell atom name
        echo -hsn "$atname "
        ia=$ia+1
      }
      echo -hs " "
    }
    ires++
  }
  iseg++
}

