Commit 5151d502 authored by peastman's avatar peastman
Browse files

Merge pull request #1226 from rmcgibbo/forcegroup-31

Fix force group 31
parents 596a4197 6a50de8a
%inline %{
typedef int bitmask32t;
%}
%typemap(in) bitmask32t %{
$1 = 0;
#if PY_VERSION_HEX >= 0x03000000
if (PyLong_Check($input)) {
unsigned long u = PyLong_AsUnsignedLongMask($input);
#else
if (PyInt_Check($input)) {
unsigned long u = PyInt_AsUnsignedLongMask($input);
#endif
// 64-bit Windows has 32-bit longs, but other platforms have
// 64-bit longs
$1 = u & 0xffffffff;
} else {
PyErr_SetString(PyExc_ValueError, "in method $symname, argument $argnum could not be converted to type $type");
SWIG_fail;
}
%}
%extend OpenMM::Context {
PyObject *_getStateAsLists(int getPositions,
int getVelocities,
......@@ -5,7 +29,7 @@
int getEnergy,
int getParameters,
int enforcePeriodic,
int groups) {
bitmask32t groups) {
State state;
PyThreadState* _savePythonThreadState = PyEval_SaveThread();
int types = 0;
......@@ -36,15 +60,9 @@
enforcePeriodicBox=False,
groups=-1):
"""
getState(self,
getPositions = False,
getVelocities = False,
getForces = False,
getEnergy = False,
getParameters = False,
enforcePeriodicBox = False,
groups = -1)
-> State
getState(self, getPositions=False, getVelocities=False, getForces=False,
getEnergy=False, getParameters=False, enforcePeriodicBox=False,
groups=-1) -> State
Get a State object recording the current state information stored in this context.
......
......@@ -20,7 +20,7 @@ class TestForceGroups(unittest.TestCase):
self.context = context
def test1(self):
n = 31 # Should be 32, but github issue #1198
n = 32
for (i,j) in itertools.combinations(range(n), 2):
groups = 1<<i | 1<<j
e_0 = self.context.getState(getEnergy=True, groups=groups).getPotentialEnergy()._value
......@@ -34,6 +34,12 @@ class TestForceGroups(unittest.TestCase):
# groups must be an int or set
self.context.getState(getEnergy=True, groups=(1, 2))
def test3(self):
e_0 = self.context.getState(getEnergy=True, groups=-1).getPotentialEnergy()._value
e_ref = sum(range(32))
self.assertEqual(e_0, e_ref)
if __name__ == '__main__':
unittest.main()
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment