Page 1 of 1

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

Posted: Thu Apr 14, 2016 7:50 pm
by negelis
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

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

Posted: Fri Apr 15, 2016 5:12 am
by jswails1
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

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

Posted: Fri Apr 15, 2016 7:18 am
by negelis
Thanks, Jason! It works.

Xinqiang