Commit 6776f49e authored by peastman's avatar peastman
Browse files

A few more changes related to setIntegrationForceGroups()

parent 4a30156a
......@@ -43,6 +43,10 @@ namespace OpenMM {
* force to the potential function. The strength of the restraining force is steadily increased
* until the minimum energy configuration satisfies all constraints to within the tolerance
* specified by the Context's Integrator.
*
* Energy minimization is done using the force groups defined by the Integrator.
* If you have called setIntegrationForceGroups() on it to restrict the set of forces
* used for integration, only the energy of the included forces will be minimized.
*/
class OPENMM_EXPORT LocalEnergyMinimizer {
......
......@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2015 Stanford University and the Authors. *
* Portions copyright (c) 2008-2020 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -31,6 +31,7 @@
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "openmm/CustomExternalForce.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
......@@ -279,6 +280,31 @@ void testInitialTemperature() {
ASSERT_USUALLY_EQUAL_TOL(targetTemperature, temperature, 0.01);
}
void testForceGroups() {
System system;
system.addParticle(1.0);
BrownianIntegrator integrator(0, 1.0, 0.001);
integrator.setIntegrationForceGroups(1<<1);
CustomExternalForce* f1 = new CustomExternalForce("x");
f1->addParticle(0);
f1->setForceGroup(1);
CustomExternalForce* f2 = new CustomExternalForce("y");
f2->addParticle(0);
f2->setForceGroup(2);
system.addForce(f1);
system.addForce(f2);
Context context(system, integrator, platform);
context.setPositions(vector<Vec3>(1));
// Take one step and verify that the position was updated based only on f1.
integrator.step(1);
Vec3 pos = context.getState(State::Positions).getPositions()[0];
ASSERT(pos[0] < 0);
ASSERT(pos[1] == 0);
ASSERT(pos[2] == 0);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
......@@ -290,6 +316,7 @@ int main(int argc, char* argv[]) {
testConstrainedMasslessParticles();
testRandomSeed();
testInitialTemperature();
testForceGroups();
runPlatformTests();
}
catch(const exception& e) {
......
......@@ -106,6 +106,33 @@ Parameters:
}
}
%extend OpenMM::Integrator {
%pythoncode %{
def setIntegrationForceGroups(self, groups):
"""Set which force groups to use for integration. By default, all force groups are included.
Parameters
----------
groups : set or int
a set of indices for which force groups to include when integrating the equations of motion.
Alternatively, the groups can be passed as a single unsigned integer interpreted as a bitmask,
in which case group i will be included if (groups&(1<<i)) != 0.
"""
try:
# is the input integer-like?
groups_mask = int(groups)
except TypeError:
if isinstance(groups, set):
groups_mask = functools.reduce(operator.or_,
((1<<x) & 0xffffffff for x in groups))
else:
raise TypeError('%s is neither an int nor set' % groups)
if groups_mask >= 0x80000000:
groups_mask -= 0x100000000
_openmm.Integrator_setIntegrationForceGroups(self, groups_mask)
%}
}
%extend OpenMM::RPMDIntegrator {
%pythoncode %{
def getState(self,
......
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