set rdist 3 set hbdist 3.5 set hbang 180 set acceptor "segname AP1 and name N and resid 143 144 145" set donor "water" set residue 1 if { $residue } { set selectiontxt "same residue as (${donor} and within ${rdist} of ${acceptor})" } else { set selectiontxt "${donor} and within ${rdist} of ${acceptor}" } set accsel [atomselect top "${acceptor}"] set donsel [atomselect top "${selectiontxt}"] set output [open "wat_hbonds.txt" w] set nframes [molinfo top get numframes] for {set i 0} {$i < $nframes} {incr i} { animate goto $i $donsel update set hbcurr [measure hbonds $hbdist $hbang $donsel $accsel] set idxlst [lindex $hbcurr 0] if { [llength $idxlst ] } { set rsel [atomselect top "index ${idxlst}"] set donres [lsort -unique -integer [$rsel get resid]] $rsel delete puts $output "$i $donres" } } $accsel delete $donsel delete close $output