Question about Custom Thermostat and Barostat

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
User avatar
Kailong Mao
Posts: 16
Joined: Fri Oct 02, 2015 8:56 am

Re: Question about Custom Thermostat and Barostat

Post by Kailong Mao » Thu Feb 04, 2016 11:33 am

No problem! Please see attached for the code. Thank you very much for taking the time to help us!!

Also, what I have right now is a Verlet integrator. But eventually we'd like to implement a multiple time step integrator. I know I can access a Force object and change its group by

Code: Select all

forceIndex = 3
force = system.getForce(forceIndex)
The problem is that for Force object, it doesn't have any attribute like "name". So, I don't know its identity, e.g. whether it's harmonic bond force or electrostatic. How would I know what type of force it is?

Thank you very much!
Attachments
custom_integrator.zip
(1.54 KiB) Downloaded 59 times

User avatar
Peter Eastman
Posts: 2588
Joined: Thu Aug 09, 2007 1:25 pm

Re: Question about Custom Thermostat and Barostat

Post by Peter Eastman » Thu Feb 04, 2016 12:06 pm

Thanks! I'll take a look.

You can use the isinstance() function to check the type of an object. For example,

Code: Select all

if isinstance(force, NonbondedForce):
    # Do something
Peter

User avatar
Peter Eastman
Posts: 2588
Joined: Thu Aug 09, 2007 1:25 pm

Re: Question about Custom Thermostat and Barostat

Post by Peter Eastman » Thu Feb 04, 2016 3:21 pm

I merged the fix:

https://github.com/pandegroup/openmm/pull/1384

Try pulling the latest code from github and see if it works correctly for you now.

Peter

User avatar
Kailong Mao
Posts: 16
Joined: Fri Oct 02, 2015 8:56 am

Re: Question about Custom Thermostat and Barostat

Post by Kailong Mao » Fri Feb 05, 2016 9:27 am

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!!

User avatar
Jason Swails
Posts: 47
Joined: Mon Jan 07, 2013 5:11 pm

Re: Question about Custom Thermostat and Barostat

Post by Jason Swails » Fri Feb 05, 2016 9:32 am

zebra_123456 wrote:Could it be because "dt" is not a user-defined variable?
"dt" is the time-step and is typically constant, I think (except for some kinds of variable integrators perhaps). Were you defining your own "dt" variable for something else? Did this not result in an error?

User avatar
Kailong Mao
Posts: 16
Joined: Fri Oct 02, 2015 8:56 am

Re: Question about Custom Thermostat and Barostat

Post by Kailong Mao » Fri Feb 05, 2016 9:41 am

Hi Jason:

Sorry for the confusion! No, I did not define my own "dt". Before Peter posted the fix, I was not able to update one variable "temp" that I defined when using "CUDA" as my platform. Everything works when I use the reference platform. Now with the fix, I can update "temp", but not another user-defined variable "c". I was able to get around this because c actually should be a constant.

Thanks!

User avatar
Peter Eastman
Posts: 2588
Joined: Thu Aug 09, 2007 1:25 pm

Re: Question about Custom Thermostat and Barostat

Post by Peter Eastman » Fri Feb 05, 2016 5:33 pm

Fixed! Try now.

Peter

User avatar
Peter Eastman
Posts: 2588
Joined: Thu Aug 09, 2007 1:25 pm

Re: Question about Custom Thermostat and Barostat

Post by Peter Eastman » Wed Feb 10, 2016 3:13 pm

Could you confirm whether the change I made on Feb. 5 fixed the problem for you?

Thanks!

Peter

User avatar
Kailong Mao
Posts: 16
Joined: Fri Oct 02, 2015 8:56 am

Re: Question about Custom Thermostat and Barostat

Post by Kailong Mao » Thu Feb 11, 2016 3:06 pm

Hi Peter:

Yes, now I can use "dt" for global computations! Thank you so much!

POST REPLY