"vscode:/vscode.git/clone" did not exist on "ecc7e011efcc895bb8d45043ce5f120ffde97762"
Commit 4a30156a authored by peastman's avatar peastman
Browse files

Added Integrator.setIntegrationForceGroups()

parent f902295b
......@@ -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) 2011-2018 Stanford University and the Authors. *
* Portions copyright (c) 2011-2020 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -123,6 +123,7 @@ void CudaIntegrateRPMDStepKernel::initialize(const System& system, const RPMDInt
groupsNotContracted -= 1<<group;
}
}
groupsNotContracted &= integrator.getIntegrationForceGroups();
if (maxContractedCopies > 0) {
contractedForces.initialize<long long>(cu, maxContractedCopies*paddedParticles*3, "rpmdContractedForces");
contractedPositions.initialize(cu, maxContractedCopies*paddedParticles, elementSize, "rpmdContractedPositions");
......
......@@ -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) 2011-2018 Stanford University and the Authors. *
* Portions copyright (c) 2011-2020 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -103,6 +103,7 @@ void OpenCLIntegrateRPMDStepKernel::initialize(const System& system, const RPMDI
groupsNotContracted -= 1<<group;
}
}
groupsNotContracted &= integrator.getIntegrationForceGroups();
if (maxContractedCopies > 0) {
contractedForces.initialize(cl, maxContractedCopies*paddedParticles, forceElementSize, "rpmdContractedForces");
contractedPositions.initialize(cl, maxContractedCopies*paddedParticles, elementSize, "rpmdContractedPositions");
......
......@@ -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) 2011-2013 Stanford University and the Authors. *
* Portions copyright (c) 2011-2020 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -99,6 +99,7 @@ void ReferenceIntegrateRPMDStepKernel::initialize(const System& system, const RP
groupsNotContracted -= 1<<group;
}
}
groupsNotContracted &= integrator.getIntegrationForceGroups();
// Create workspace for doing contractions.
......
......@@ -597,6 +597,7 @@ void testForceGroups() {
integrator.addComputeGlobal("oute", "energy");
integrator.addComputeGlobal("oute1", "energy1");
integrator.addComputeGlobal("oute2", "energy2");
integrator.setIntegrationForceGroups((1<<1) + (1<<2));
HarmonicBondForce* bonds = new HarmonicBondForce();
bonds->addBond(0, 1, 1.5, 1.1);
bonds->setForceGroup(1);
......@@ -606,6 +607,10 @@ void testForceGroups() {
nb->addParticle(0.2, 1, 0);
nb->setForceGroup(2);
system.addForce(nb);
CustomExternalForce* external = new CustomExternalForce("x");
external->addParticle(0);
external->setForceGroup(3);
system.addForce(external);
Context context(system, integrator, platform);
vector<Vec3> positions(2);
positions[0] = Vec3(-1, 0, 0);
......@@ -633,13 +638,13 @@ void testForceGroups() {
// Make sure they also match the values returned by the Context.
State s = context.getState(State::Forces | State::Energy, false);
State s = context.getState(State::Forces | State::Energy, false, 6);
State s1 = context.getState(State::Forces | State::Energy, false, 2);
State s2 = context.getState(State::Forces | State::Energy, false, 4);
vector<Vec3> c, c1, c2;
c = context.getState(State::Forces, false).getForces();
c1 = context.getState(State::Forces, false, 2).getForces();
c2 = context.getState(State::Forces, false, 4).getForces();
c = s.getForces();
c1 = s1.getForces();
c2 = s2.getForces();
ASSERT_EQUAL_VEC(f[0], c[0], 1e-5);
ASSERT_EQUAL_VEC(f[1], c[1], 1e-5);
ASSERT_EQUAL_VEC(f1[0], c1[0], 1e-5);
......
......@@ -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-2016 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"
......@@ -286,6 +287,31 @@ void testInitialTemperature() {
ASSERT_USUALLY_EQUAL_TOL(targetTemperature, temperature, 0.01);
}
void testForceGroups() {
System system;
system.addParticle(1.0);
LangevinIntegrator integrator(0.0, 1.0, 0.01);
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[]) {
......@@ -297,6 +323,7 @@ int main(int argc, char* argv[]) {
testConstrainedMasslessParticles();
testRandomSeed();
testInitialTemperature();
testForceGroups();
runPlatformTests();
}
catch(const exception& e) {
......
......@@ -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-2019 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"
......@@ -289,6 +290,31 @@ void testInitialTemperature() {
ASSERT_USUALLY_EQUAL_TOL(targetTemperature, temperature, 0.01);
}
void testForceGroups() {
System system;
system.addParticle(1.0);
LangevinMiddleIntegrator integrator(0.0, 1.0, 0.01);
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[]) {
......@@ -300,6 +326,7 @@ int main(int argc, char* argv[]) {
testConstrainedMasslessParticles();
testRandomSeed();
testInitialTemperature();
testForceGroups();
runPlatformTests();
}
catch(const exception& e) {
......
......@@ -7,7 +7,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2010-2018 Stanford University and the Authors. *
* Portions copyright (c) 2010-2020 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -231,6 +231,34 @@ void testLargeForces() {
ASSERT(maxdist < 10.0);
}
void testForceGroups() {
// Create a system with two forces, only one of which is in the standard
// integration force groups.
System system;
system.addParticle(1.0);
system.addParticle(1.0);
HarmonicBondForce* bonds1 = new HarmonicBondForce();
HarmonicBondForce* bonds2 = new HarmonicBondForce();
system.addForce(bonds1);
system.addForce(bonds2);
bonds1->addBond(0, 1, 2.0, 1);
bonds2->addBond(0, 1, 4.0, 1);
bonds1->setForceGroup(1);
bonds2->setForceGroup(2);
// Minimize it and check that the bond has the correct length.
VerletIntegrator integrator(0.01);
integrator.setIntegrationForceGroups(1<<1);
Context context(system, integrator, platform);
context.setPositions({Vec3(0, 0, 0), Vec3(5, 0, 0)});
LocalEnergyMinimizer::minimize(context, 1e-5);
State state = context.getState(State::Positions);
Vec3 delta = state.getPositions()[0]-state.getPositions()[1];
ASSERT_EQUAL_TOL(2.0, sqrt(delta.dot(delta)), 1e-4);
}
void runPlatformTests();
int main(int argc, char* argv[]) {
......@@ -240,6 +268,7 @@ int main(int argc, char* argv[]) {
testLargeSystem();
testVirtualSites();
testLargeForces();
testForceGroups();
runPlatformTests();
}
catch(const exception& e) {
......
......@@ -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) 2019 Stanford University and the Authors. *
* Portions copyright (c) 2019-2020 Stanford University and the Authors. *
* Authors: Andreas Krämer and Andrew C. Simmonett *
* Contributors: *
* *
......@@ -510,6 +510,31 @@ void testAPIChangeNumParticles() {
}
void testForceGroups() {
System system;
system.addParticle(1.0);
NoseHooverIntegrator integrator(1, 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[]) {
......@@ -528,6 +553,7 @@ int main(int argc, char* argv[]) {
constrain = false; testDimerBox(constrain);
constrain = true; testDimerBox(constrain);
testCheckpoints();
testForceGroups();
runPlatformTests();
}
catch(const exception& e) {
......
......@@ -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-2016 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"
......@@ -358,6 +359,31 @@ void testInitialTemperature() {
ASSERT_USUALLY_EQUAL_TOL(targetTemperature, temperature, 0.01);
}
void testForceGroups() {
System system;
system.addParticle(1.0);
VariableLangevinIntegrator integrator(0.0, 1.0, 1e-5);
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[]) {
......@@ -370,6 +396,7 @@ int main(int argc, char* argv[]) {
testRandomSeed();
testArgonBox();
testInitialTemperature();
testForceGroups();
runPlatformTests();
}
catch(const exception& e) {
......
......@@ -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"
......@@ -337,6 +338,31 @@ void testInitialTemperature() {
ASSERT_USUALLY_EQUAL_TOL(targetTemperature, temperature, 0.01);
}
void testForceGroups() {
System system;
system.addParticle(1.0);
VariableVerletIntegrator integrator(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[]) {
......@@ -348,6 +374,7 @@ int main(int argc, char* argv[]) {
testConstrainedMasslessParticles();
testArgonBox();
testInitialTemperature();
testForceGroups();
runPlatformTests();
}
catch(const exception& e) {
......
......@@ -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"
......@@ -254,6 +255,31 @@ void testInitialTemperature() {
ASSERT_USUALLY_EQUAL_TOL(targetTemperature, temperature, 0.01);
}
void testForceGroups() {
System system;
system.addParticle(1.0);
VerletIntegrator integrator(0.01);
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[]) {
......@@ -264,6 +290,7 @@ int main(int argc, char* argv[]) {
testConstrainedClusters();
testConstrainedMasslessParticles();
testInitialTemperature();
testForceGroups();
runPlatformTests();
}
catch(const exception& e) {
......
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