From: Josh Vermaas (joshua.vermaas_at_gmail.com)
Date: Thu Apr 16 2020 - 11:42:08 CDT

The bookkeeping is a bit of a pain, but the basic idea is the same.

*set frames [molinfo top get numframes]set fp [open "LIG.txt" w]*

*for {set i 0} {$i < $frames} {incr i} { puts "Frame: $i"*

*for { set r 1 } { $r <= 442 } { incr r } { set a
[atomselect top "(index 6616 to 8155 and same index as within 5 of resid
$r)" frame $i] set num [$a num] puts $fp "$i
$r $num" $a delete*

*}}close $fp*

Note that this will potentially double count ligand atoms that are within 5
angstroms of two (or more) residues. If you wanted to do this more
rigorously to determine the closest residue, I'd look at the "measure
contacts" command in the user guide (
https://www.ks.uiuc.edu/Research/vmd/current/ug/node138.html), and go over
the contact lists and evaluate the contact distances for each pair of atoms--000000000000c4921605a36b1d40--