From: Bjørnar Jensen (
Date: Mon Nov 19 2012 - 07:05:21 CST


a quick untested script:
//Selection for the two atoms of choice
set A [atomselect top "index xxx"]
set B [atomselect top "index yyy"]

//Get number of frames loaded into top molecule
set numframes [molinfo top get numframes]

//Open file for writing output
set output [open "Distance.dat" w]
//Write a short header to the file
puts $output "Frame\tDistance"

//Loop over all frames
for {set i 0} {$i < $numframes} {incr i} {
     //Advance to frame $i
     animate goto $i
     //Get the positions, find the vector from B to A, calculate the
length of vector
     set distance [veclength [vecsub [lindex [$A get {x y z}] 0] [lindex
[$B get {x y z}] 0] ]
     //Write the frame number and distance to file. Separated by a
     puts $output "$i\t$distance"
//Close and clean up everything
$output close
$A delete
$B delete
unset numframes
unset output

This is likely to contain a bug or two and may be inefficient.
It should, at least, get you started.

The whole "how do I write a script" is found in the user guide and in
several tutorials. If you are using VMD on a day to day basis learning
to write scripts for VMD should be mandatory.

Best regards,
Bjørnar Jensen

On 2012-11-17 14:33, 肖富贵 wrote:
> Hi guys,
> I have 1000 conformations of a protein, and i want to measure the
> distance between two atoms in this protein.
> I know the "measure bond" command can measure the disance of two
> atoms. However, i have 1000 conformations, and i cannot measure each
> one by one, so can anyone tell me how to write a script?
> Best wishes
> Xiao Fugui