Accese charge, sigma and epsilon from system C++ object

The functionality of OpenMM will (eventually) include everything that one would need to run modern molecular simulation.
POST REPLY
User avatar
Xinqiang Ding
Posts: 33
Joined: Tue May 05, 2015 2:27 pm

Accese charge, sigma and epsilon from system C++ object

Post by Xinqiang Ding » Thu Apr 14, 2016 7:50 pm

Hi,

I'm writing my C++ application with OpenMM C++ API. Given a system object, what's the easiest way to get the values of charge, sigma, and epsilon for all the particles?

The method I'm using is first getting the force from system, finding out which force is non bonded force and the non-bonded force object has a method called getParticelParameters(). The tricky thing of doing this is to figure out which force index is nonbonded force. Now I'm using force group num 6 and assuming the non bonded force's force group num is always 6. Is this true? I also try to find if there is an enumeration type defining force group numbers and couldn't find it.

Xinqiang Ding

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

Re: Accese charge, sigma and epsilon from system C++ object

Post by Jason Swails » Fri Apr 15, 2016 5:12 am

negelis wrote:Now I'm using force group num 6 and assuming the non bonded force's force group num is always 6. Is this true? I also try to find if there is an enumeration type defining force group numbers and couldn't find it.
You definitely can't rely on this. This happens to be true if you serialize a system from CharmmPsfFile in the OpenMM application layer, but this won't really be true for any other System in general. The reason it's not specified is because this is a user-definable variable. By default, all force groups are 0 unless you change them (the CharmmPsfFile class changes them explicitly).

The appropriate thing to do here is attempt a dynamic cast to NonbondedForce and check against NULL when searching through all of the forces. If it's not NULL, then that's the NonbondedForce. Here are some examples in the OpenMM source code where this type of pattern is used to determine a specific subclass that's being used: https://github.com/pandegroup/openmm/bl ... #L153-L171

User avatar
Xinqiang Ding
Posts: 33
Joined: Tue May 05, 2015 2:27 pm

Re: Accese charge, sigma and epsilon from system C++ object

Post by Xinqiang Ding » Fri Apr 15, 2016 7:18 am

Thanks, Jason! It works.

Xinqiang

POST REPLY