Thanks a lot for the quick fix! I re-compiled the code and found out that although the variable "temp" now gets updated correctly, another user-defined variable "c" now doesn't. Although I added the step "addComputeGlobal("c", "exp(-dt/tautemp)")", "c" keeps its default value throughout the entire simulation. Could it be because "dt" is not a user-defined variable? The code should be in the file attached to my previous post. I was able to get around this because I realized that "c" should actually be a constant, so no need for the "addComputeGlobal" step. So, the thermostat works for me now, but I thought I should probably let you know about this.
Also, I wonder why the temperature I calculated using the following formula doesn't agree with the temperature from OpenMM.
Code: Select all
df = nAtoms * 3.0 - 6.0
gasconst = 8.314459848e-3
...
self.integrator.addComputeSum("ke", "m*v*v/2.0")
self.integrator.addComputeGlobal("temp", "2.0*ke/(df *gasconst)")
Thank you very much again for your time!!