From: Nima Nouri (
Date: Thu Jan 22 2015 - 03:40:31 CST

Hi every body

I am currently trying to average a parameter along the length of the
simulation cell in neighboring bins. the code I am using is as follows.
Please note that the only parameter required for the script is the "stepx"
which defines the bin width along the x direction. The problem is the first
two atomselect commands works correctly and I get the maximum and minimum X
values for each atom correctly but in the third atomselect command the
returned proc always says that its has no atom inside. and also the third
atomselect works correctly if I replace the variables inside it with
numbers and use it inside the tk console separately. Please tell me what I
am doing wrong?

*set* molid *[*molinfo top*]*

*set* my_numframes *[*molinfo top get numframes*]*

*set* stepx *[expr* 3.57*/*2.0*]*

*set* CSYMFRAMES *{}*

*for* *{set* i 0*}* *{*$i *<* $my_numframes*}* *{incr* i*}* *{*

* puts* *"Computing Frame **$i"*;

* set* CSYM *{}*; *puts* *"creating the new CSYM List"*;

     *set* sel *[*atomselect top all*]*; *puts* *"Selecting a total of **[$sel
num] Atoms"*;

     $sel frame $i

     *set* xmin *[lindex* *[lsort* -real -increasing *[*$sel get x*]]* 0*]*;
*puts* *"xmin = **$xmin"*;

     *set* xmin *[expr* $xmin-*(*$stepx*/*2.0*)]*; *puts* *"Nxmin = *

        *set* x1 $xmin; *puts* *"x1=**$x1"*;

      *set* xmax *[lindex* *[lsort* -real -decreasing *[*$sel get x*]]* 0*]*;
*puts* *"xmax = **$xmax"*;

     *set* xmax *[expr* $xmax*+(*$stepx*/*2.0*)]*; *puts* *"Nxmax = *

         *for* *{set* x2 *[expr* $xmin *+* $stepx*]}* *{*$x2 *<=* $xmax*}*
*{set* x2 *[expr* $x2 *+* $stepx*]}* *{*

             *puts* *"x2=**$x2"*;

          *set* mysel *[*atomselect top *{*x*>*$x1 and x*<*$x2*}]* ;
*puts* *"number
of atoms in the bin \[x1=**$x1,x2=$x2\] is [$mysel num]"*;

          *if* *{[*$mysel num*]* *!=* 0*}* *{*

              *set* y *[expr* *{[*::tcl::mathop::*+* *{*}[*$mysel get user
*]]* */* *[*$mysel num*]}]*; *puts* *"Average CSYM is **$y"*;

              *lappend* CSYM *{[expr* *(*$x1*+*$x2*)/*2.0*]* $y*}*; *puts* 0


          *set* x1 $x2; *puts* *"x1=**$x1"*;


     *lappend* $CSYMFRAMES $CSYM ; *puts* 0;

Best Regards

Ph.D Student
Department of Mechanical Engineering
Isfahan University of Technology
Isfahan, Iran