From: Bernardo Sosa Padilla Araujo (
Date: Mon Mar 01 2010 - 21:44:09 CST

Hi all,

I am trying to write a script to measure the distance between a few atoms
for a simulation and write that in a file.
Here is my script:

#opening files to write
set dist1 [open dist1.dat w]
set dist2 [open dist2.dat w]
#getting number of frames
set nf [molinfo top get numframes]
#selecting the atoms
set sub [atomselect top "name H4"]
set base1 [atomselect top "name OE1 and within 6 of name H4"]
set base2 [atomselect top "name OE2 and within 6 of name H4"]
#creating variables with the index from the previous selection
set hydr [$sub get index]
set ox1 [$base1 get index]
set ox2 [$base2 get index]
#outputting the measurements
set a {}
set b {}
for { set i 0} { $i <=$nf } {incr i} {
 lappend a [measure bond {$ox1 $hydr} frame $i]
 lappend b [measure bond {$ox2 $hydr} frame $i]
puts $dist1 "$a"
close $dist1
puts $dist2 "$b"
close $dist2

So, I select three atoms and then from those selections I create 3 different
variables (hydr, ox1 and ox2) that hold the indexes for the three atoms(red
Then I use the measure command to measure the distances between the
atoms(green text).
The measure command should be used:
measure bond {atomid1 atomid2} ex : measure bond {3 5}
What I am doing is to put the name of the variable that holds the atomids
instead of putting the number. And it is not working at all, it gives this
error message "expected integer but got $ox1 measure bond: bad atom index".
But when I put the numbers (instead of the name of the variables that hold
the numbers) it works just fine.
Then my question is if you see any mistake in the script that could be
producing this error or if anyone knows of a different way to do it.
 Thanks a lot in advance.