From: Roni Saiba (ronis_at_imsc.res.in)
Date: Thu Jul 18 2024 - 14:26:32 CDT

In the second for loop the atomselect command should be [atomselect
top "same residue as index $l2" frame $i]. The "frame $i" segment
ensures all frames are selected in order.
Regards,
Roni

Quoting Laura X Sepulveda <lsepcl1_at_lsu.edu>:

> Dear all,
>
> I have this script that is selects the closest 15 water molecules
> closer to residue named ACE NME(from the O distance to the N of ACE
> NME) and writes a pdb file per frame with this selection. However,
> I noticed that the molecules written to the pdb file depend on the
> current frame selected in the main window of VMD. Aren't they
> supposed to be in the order of the for loop? I am updating all
> selections and unsetting all variables, but still the pdb for frame
> n is different if the selected frame on the main window is not the
> same always.
>
> Thanks, in advance!
>
>
>
>
> set numframes [molinfo top get numframes]
> set solvent_molecues_num 15
>
> for { set f 0 } { $f < $numframes } { incr f 1} {
>
> set sel_probe [atomselect top "resname ACE NME and name N"]
> set sel_solv [atomselect top "resname WAT and name O and within 6.0
> of resname ACE NME and name N"]
>
> $sel_probe frame $f
> $sel_probe update
> $sel_solv frame $f
> $sel_solv update
>
> set satom_index_list [$sel_solv get index]
> set patom_index [$sel_probe get index]
>
> foreach s_atom $satom_index_list {
> set d [measure bond "$s_atom $patom_index"]
> lappend l1 [list $s_atom $d]
> }
> #puts "l1: $l1"
>
> for { set i 0 } { $i < $solvent_molecues_num } { incr i 1} {
> lappend l2 "[lindex [lsort -index 1 $l1] $i 0]"
> }
> #puts "l2: $l2"
>
> set sel_write [atomselect top "resname ACE NME or same
> residue as index $l2"]
> $sel_write frame $f
> $sel_write update
> $sel_write writepdb nma_h2o_within_$f.pdb
>
> unset l1 l2 d satom_index_list patom_index s_atom
> sel_probe sel_solv
> }