addforce on the com of a group of atoms and loadforces command

From: Vlad Cojocaru (
Date: Tue Dec 23 2008 - 07:57:29 CST

Dear namd users,

I have a tcl script which adds a force on the center of mass of a group
of atoms using "addforce $groupid $force"

However, when I try to check the force applied on each atom of the group
using the "loadforces forces" command, the "forces" array is always
empty. However, from the trajectory it seems as my external force is
applied .

To test, I also modified the push.tcl script from the namd tutorial to
apply the force on the com of the group of atoms and got the same behavior.

Is there a known problem of the tcl interface that "loadforces" does not
store external forces when they are applied on groupids rather than
individual atoms ?
If not, maybe I am doing something wrong ... Below is my modified
push.tcl script from the tutorial (which always produces an empty
"forces" array but a correct "totalforces" array) . Does anybody spot
anything wrong in it ?


# Want to force all atoms
set numatoms 1231

set atoms {}
for { set i 1 } { $i <= $numatoms } { incr i } {
    lappend atoms $i

foreach atom $atoms {
    addatom $atom

set groupid [addgroup $atoms]

# Convert input to NAMD units: kcal/(mol*Ang*amu)
set linaccel_namd [vecscale [expr 1.0/418.68] $linaccel]

print "Linear acceleration applied: ($linaccel) Ang*ps^-2"

proc calcforces { } {
    global atoms groupid numatoms linaccel_namd
    loadcoords coords
    loadmasses masses
    loadforces forces
    loadtotalforces totalforces

    set totalmass 0
    foreach atom $atoms {
     set totalmass [expr $totalmass + $masses($atom)]

    set force [vecscale $totalmass $linaccel_namd]
    addforce $groupid $force
    if { [array exists forces] } {
     print "forces array exists"
    } else {
     print "forces array EMPTY"
    if { [array exists totalforces] } {
     print "totalforces array exists"
    } else {
     print "totalforces array EMPTY"

Dr. Vlad Cojocaru
EML Research gGmbH
Schloss-Wolfsbrunnenweg 33
69118 Heidelberg
Tel: ++49-6221-533202
Fax: ++49-6221-533298
EML Research gGmbH
Amtgericht Mannheim / HRB 337446
Managing Partner: Dr. h.c. Klaus Tschira
Scientific and Managing Director: Prof. Dr.-Ing. Andreas Reuter

This archive was generated by hypermail 2.1.6 : Wed Feb 29 2012 - 15:50:18 CST