Re: Is it a bug? TCL Script may Lead to Overflow

From: Fred (Rui FENG) (
Date: Mon Nov 09 2009 - 14:04:25 CST

Hi Jim,

Yes. By changing to "main" in SimParameters.C the problem is solved. Thanks.

I compiled the NAMD with TCL 8.5.7 yesterday and found the problem was
still there. Then I changed the TCL scripts: removed the lines like
"set f "1 0. 0."" and changed the addforce lines as "addforce "0.01 0.
0."". That is, in every "elseif" there's only one statement. The
problem disappeared. But with TCL 8.4.14 such changes didn't help.

I just guess that there's a fixed-length array which stores the TCL
scripts. I didn't find it either.

Here's how I found the bug:
My projects need me to output the mean velocity of all particles and I
modified the code. When the TCL scripts are just 20 lines, the
velocity output is good. But when scripts are more than 35 or 40
lines, the velocity is too big. I found the mass calculation in the
function "Sequencer::submitMomentum()" was not correct because
"simParams->zeroMomentumAlt" was not zero as default. Even I
explicitly turned off the "zeroMomentumAlt" and "zeroMomentum" in the
parameter file, "zeroMomentumAlt" in the Sequencer::submitMomentum is
still overflowed.


On Mon, Nov 9, 2009 at 12:55 PM, Jim Phillips <> wrote:
> Hi Fred,
> Thanks for reporting this.  Something about the raw attachments was killing
> majordomo and chopping off the message when I tried to approve it.
> The zeroMomentumAlt variable in SimParameters is only initialized if a value
> is explicitly given for zeroMomentum.  This is the code:
>   opts.optionalB("main", "zeroMomentum", "constrain center of mass",
>      &zeroMomentum, FALSE);
>   opts.optionalB("zeroMomentum", "zeroMomentumAlt", "constrain center of
> mass",      &zeroMomentumAlt, FALSE);
> The first string in each line is the dependency for the second string.  I am
> changing this to initialize everything that has a default, since there have
> been several bugs related to this behavior in the past.
> If you switch "zeroMomentum" to "main" in the zeroMomentumAlt declaration
> you should see this behavior go away.
> I can't find any fixed-length arrays in the code that handles tclBCScript.
> Have you observed any functional errors?  How did you find this?
> -Jim
> On Sat, 7 Nov 2009, Fred (Rui FENG) wrote:
>> Hi Axel,
>> Maybe the attachments exceed the size limit? I compressed them and
>> hope everyone could get it. Thanks.
>> Regards,
>> Fred
>> On Sat, Nov 7, 2009 at 3:47 PM, Axel Kohlmeyer <> wrote:
>>> On Sat, 2009-11-07 at 15:01 -0500, Fred (Rui FENG) wrote:
>>>> Hi All,
>>>> The modified Controller.C and apoa1.namd are attached. Please backup
>>>> the original Controller.C and replace it with the new one. The change
>>>> is only at the line 1073 to 1075. Thanks.
>>> fred,
>>> there are no attachments...
>>> axel.
>>>> Regards,
>>>> Fred
>>>> On Sat, Nov 7, 2009 at 4:09 AM, Fred (Rui FENG) <>
>>>> wrote:
>>>>> Hi All,
>>>>> I found that if TCL script lines are more than a certain value (maybe
>>>>> 35 to 40) in the parameter file, some variables will overflow and
>>>>> impact the variable (at least) called "zeroMomentumAlt". For example,
>>>>> the code below is to add a gradient force. To reproduce this error,
>>>>> just append the code below to the popular ApoA1 parameter file which
>>>>> can be download here:
>>>>> The variable "zeroMomentumAlt" is only set in SimParameters.C and
>>>>> referenced by Sequencer.C.  Its value can be printed in Controller.C
>>> --
>>> Dr. Axel Kohlmeyer
>>> Institute for Computational Molecular Science
>>> College of Science and Technology
>>> Temple University, Philadelphia PA, USA.

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