From: Liu, Zhanwu (LiuxZx_at_anes.upmc.edu)
Date: Fri Mar 22 2002 - 14:16:53 CST

Dear John,

In fact, what I want to do is to wrap molecules into a well defined
box, because namd2 does not do this job. The script is enclosed.

Thanks

Zhanwu

# WRAP.tcl
# This script is used to wrap all the molcules
# into one well-defined box centered at {0 0 0 }, this will facilitate the
# calculation of Radial distribution function.
# By Zhanwu Liu, Mar 22 2002

# The main program, called with the periodical cell dimension
proc wrap {boxx boxy boxz } {
        set totalframe [molinfo top get numframes]
        for { set i 150 } { $i < $totalframe } { incr i 1 } {
                animate goto $i
                display update ui
                puts "Now processing frame $i"
                rapidwrap $boxx $boxy $boxz
# wrap_frame $boxx $boxy $boxz $i
        }
}

# This procedure move more quickly because is do not operate individua
atoms.
# Used as the first step
proc rapidwrap { x y z } {
        set minx [expr [expr 0 - $x ]/2]
        set maxx [expr $x/2]
        set miny [expr [expr 0 - $y ]/2]
        set maxy [expr $y/2]
        set minz [expr [expr 0 - $z ]/2]
        set maxz [expr $z/2]

# Permutation of 26 neighbouring images, select atoms and their
cooresponding
# residues (or segments, etc), then move
        foreach xx { -1 0 1 } {
                foreach yy { -1 0 1 } {
                        foreach zz { -1 0 1 } {
                                set xxx [expr $xx * $maxx ]
                                set yyy [expr $yy * $maxy ]
                                set zzz [expr $zz * $maxz ]

                                if {$xx == -1 } {
                                        set selstringx " x < $xxx "
                                } elseif { $xx == 0 } {
                                        set selstringx " all "
                                } else {
                                        set selstringx " x > $xxx "
                                }

                                if {$yy == -1 } {
                                        if { $xx == 0 } {
                                                set selstringy "and y < $yyy
"
                                        } else {
                                        set selstringy "and y < $yyy "
                                        }
                                } elseif { $yy == 0 } {
                                        set selstringy " "
                                } else {
                                        if { $xx == 0 } {
                                                set selstringy " and y >
$yyy "
                                        } else {
                                        set selstringy "and y > $yyy "
                                        }

                                }

                                if {$zz == -1 } {
                                        set selstringz " and z < $zzz "
                                } elseif { $zz == 0 } {
                                        set selstringz " "
                                } else {
                                        set selstringz " and z > $zzz "
                                }

                                set selectstring " same residue as
($selstringx $selstringy $selstringz) "
                                set atoms [atomselect top "$selectstring"]
                                set tempvector "[expr $xxx*2] [expr $yyy*2]
[expr $zzz*2]"
                                set movevector [vecsub { 0 0 0 }
$tempvector ]
                                $atoms moveby $movevector
                        }
                }
        }
}

# The slow method to wrap molecules
# This procedure work very very slowly, it could be combined with
# rapidwrap, process the remaining atoms after rapidwrap.
# x y z are the box dimension
proc wrap_frame { x y z } {
        set minx [expr [expr 0 - $x ]/2]
        set maxx [expr $x/2]
        set miny [expr [expr 0 - $y ]/2]
        set maxy [expr $y/2]
        set minz [expr [expr 0 - $z ]/2]
        set maxz [expr $z/2]
        animate goto $framenum
        set wraplist [atomselect top " x < $minx or x > $maxx or y < $miny
or y > $maxy or z < $minz or z > $maxz"]
        set indexlist [$wraplist list ]
        set atomxlist [$wraplist get x ]
        set atomylist [$wraplist get y ]
        set atomzlist [$wraplist get z ]

        foreach atom $indexlist atomx $atomxlist atomy $atomylist atomz
$atomzlist {
                set targetatom [atomselect top "index $atom"]
                set vecx [expr $x * [expr 0- [expr int([expr $atomx /
$maxx])]]]
                set vecy [expr $y * [expr 0- [expr int([expr $atomy /
$maxy])]]]
                set vecz [expr $z * [expr 0- [expr int([expr $atomz /
$maxz])]]]
                set movevector " $vecx $vecy $vecz"
                $targetatom moveby $movevector
        }

}

-----Original Message-----
From: John Stone
To: Liu, Zhanwu
Cc: vmd_at_ks.uiuc.edu
Sent: 03/22/2002 14:42
Subject: Re: Help on script

Dear Zhanwu,
  I believe that its curing your problem because it is forcing
parts of VMD to update themselves and realize what frame is
active. Without knowing what you're doing in the myproc routine,
I can't guess what the detailed behavioral problem you're having
is, but doing the display update ui is a way to force VMD to
redraw the display, as well as recalculate various things based
on the new animation frame. I can't give much more detail about
how this interacts with your myproc routine without knowing what
it does.

Thanks,
  John