From: fan li (fanliqmul_at_gmail.com)
Date: Tue Aug 14 2018 - 11:32:26 CDT

Hi everyone

I made the following a script to select atoms between the gap of molecule
"sbu1" and molecule "sub2" in each frame

#############################
set zmin 30.3

set nf [molinfo top get numframes]
for {set i 0} {$i < [expr ($nf-1)]} {incr i} {

        #advance to frame i
        animate goto $i

        molinfo top set frame $i

        #select water in the cubic gap between sub1 and sub2
        set sub2 [atomselect top "resname sub2"]
        set cen_sub2 [measure center $sub2]
        set x0 [lindex $cen_sub2 0]
        set y0 [lindex $cen_sub2 1]
        set z0 [lindex $cen_sub2 2]
        set xmin [expr $x0-10]
        set xmax [expr $x0+10]
        set ymin [expr $y0-10]
        set ymax [expr $y0+10]
        set zmax [expr $z0-10]

        puts "i=$i\t"
        puts "xmin=$xmin xmax=$xmax ymin=$ymin ymax=$ymax zmin=$zmin
zmax=$zmax\t"

        set sel_water [atomselect top "resname SOL and (x>$xmin and
x<$xmax) and (y>$ymin and y<$ymax) and (z>$zmin and z<$zmax)"]

        #reset the resname of the selected water
        $sel_water set resname den

        puts "num of interested water=$sel_water\t"

        set system [atomselect top all]
        $system writegro "water_interest$i.gro"

        puts "num of all atoms=$system\t"

        $sel_water delete
        $system delete
}
###########################################

As the position of sub1 and sub2 change over time, I can not put selection
outside the loop. I have compared results from the above script and the
script with the loop removed, the results from the script with the loop are
incorrect, even the output of the $system is not equal to the total atoms
in my system.

Could some one tell me what is wrong?