Friday, February 25, 2011

Calculating distances with VMD Tk scripting

This post shows how to calculate distances between atoms using Tk scripting.

Assuming you have loaded the molecule 1NEY in VMD we are going to calculate the distance between the atom OE1 of chain A with all of the residues of the protein. We will consider the alpha-Carbon atom to be arbitrary the center of a residue.

Open the Tk Console with menu Extensions > Tk Console.

The following two lines store the coordinates of oxygen named OE1:

% set oe1 [atomselect top "name OE1 and resid 165 and chain A"]
% set OE1coord [lindex [$oe1 get {x y z}] 0]

This will store all alpha-Carbon carbons in the list CASel:

% set CASel [atomselect top "type CA"]

Then to compute the distance between OE1coord an each element of CASel, you just run this script:

% foreach ca [$CASel get {x y z}] {
set distance [veclength [vecsub $OE1coord $ca]]
echo $ca : $distance
}



1 comment: