From: Olaf Lenz (
Date: Thu Aug 09 2007 - 10:19:22 CDT

Hash: SHA1


My first question is: why do you have to write this yourself? The radial
pair distribution function extension (Main -> Extensions -> Radial Pair
Distibution Function g(r)) provides all that you need.

Anyway, here is a solution to your problem:

Christopher Stiles wrote:
> set wat_sel [atomselect top "water and (z > $NT_min and z < $NT_max and
> sqrt((x*x) + (y*y)) < $NT_radius and sqrt((x*x) + (y*y)) > $NT_radius_old)”]

The problem is that this statement will create the atom selection and
substitute the Tcl-variables $NT_radius etc. ONCE when the above
statement is executed. It will NOT care about the values of $NT_radius when
        $wat_sel update
is called later on.

So I suppose that you will have to put the atom selection into the loop
so that a new one is created for every value of the Tcl variables, as
seen below.
Note that this will create lots of selections, so you might want to
delete some of the selections (something like $sel delete, but I'm not
sure, look into the UG).

Also note that this is definitely one of the most inefficient ways to
compute the radial density, because for every bin, ALL atoms have to be
  [lindex [lindex $l $i] $j]
can be written as
  [lindex $l $i $j]

set nt [atomselect top "resid 1"]
set NT_min [lindex [lindex [measure minmax $nt] 0] 2]
set NT_max [lindex [lindex [measure minmax $nt] 1] 2]
set NT_radius 0
set NT_radius_old 0
set num_frames [molinfo top get numframes]
set x_list {}
set y_list {}

set step_size 7.5
set NT_radius_max 15

while { $NT_radius <= $NT_radius_max } {
  set NT_radius_old $NT_radius
  set NT_radius [ expr { $NT_radius + $step_size } ]
  set holder 0

  set wat_sel [atomselect top "water and (z > $NT_min and z < $NT_max
and sqrt((x*x) + (y*y)) < $NT_radius and sqrt((x*x) + (y*y)) >

  for {set i 0} {$i < $num_frames} {incr i} {
    $wat_sel frame $i
    $wat_sel num
    $wat_sel update
    set holder [ expr { $holder + [ $wat_sel num ] } ]

  lappend x_list $NT_radius
  lappend y_list $holder

Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Mozilla -