set out [open tpbi_num.dat w];
set nf [molinfo top get numframes]
for { set i 1 } { $i<=$nf } { incr i 1} {
set atom [atomselect top "same residue as (resname TPB and within 3 of resname AAP)"]
$atom frame $i
$atom update
set com [$atom num]
puts $out "$i $com"
}
close $out