From: Leandro Martínez (leandromartinez98_at_gmail.com)
Date: Mon Mar 13 2006 - 08:10:16 CST

Dear VMD users,
I need to visualize the the kinetic energy in each time-step of my
simulation.
I have written the velocity file for each step with NAMD and converted it
to pdb file. Then I made a simple script that reads this velocity file,
computes
the kinetic energy per atom and puts it in the "user field" of each atom, in
each frame of the trajectory (dcd) file. Everything seems to be working
fine,
unless for the fact that I can't load all data because it seems that using
the "user field" is very memory demanding. In principle what I am loading is
only a single real number for each atom, for each frame, and, therefore, it
should not require much more memory than the trajectory itself, which I
can load very quicky (the system has only 5000 atoms). However,
my computer gets very slow and I cannot pass from frames 30 or 31 while
filling the "user field". Bellow I attach the script I'm using for doing
this, it
is based on a script written by John Stone I got from this mail list. The
reading
of the velocity file is very fast, but the script gets extremely slow in the
next
loop and I cannot finish my analysis. Any help on this subject is
appreciated.
Thank you very much,
Leandro.

-----------The script: ------------------------------------
set numframes [molinfo top get numframes]
set numatoms [molinfo top get numatoms]
puts "Opening velocity file..."
set file [ open ./velocities2.pdb r ]
set file [ read $file ]
set file [ split $file "\n" ]
set i 0
puts "Reading velocity file... "
foreach line $file {
  if { [ string range $line 0 3 ] == "ATOM" } {
    incr i
    set vx [ string range $line 30 37 ]
    set vy [ string range $line 38 46 ]
    set vz [ string range $line 47 54 ]
    set v2 [ expr $vx*$vx + $vy*$vy + $vz*$vz ]
    set kinetic [ expr $v2 / 2. ]
    set ek($i) $kinetic
  }
}
#The next step is slow:
puts "Setting up atom colors..."
set k 0
for {set i 0} {$i<$numframes} {incr i} {
  puts "Setting User data for frame $i ..."
  for {set j 0} {$j<$numatoms} { incr j } {
    incr k
    set sel [atomselect top "index $j"]
    set mass [$sel get mass]
    animate goto $i
    $sel frame $i
    $sel set user [ expr $mass * $ek($k) ]
  }
}
$sel delete
---------------------------------------------------------------------

---------------------------------------------
Leandro Martinez
Institute of Chemistry
State University of Campinas, Brazil
http://www.ime.unicamp.br/~martinez/packmol
--------------------------------------------