Commit 05ad28f2 authored by one's avatar one
Browse files

Merge OpenMM master into dtk26.04

parents 97239ca6 fc21fd19
......@@ -4709,7 +4709,7 @@ void CommonCalcCustomCPPForceKernel::initialize(const ContextImpl& context, Cust
forceGroupFlag = (1<<force.getOwner().getForceGroup());
useWorkerThread = (cc.getNumContexts() == 1);
for (const ForceImpl* impl : context.getForceImpls())
if (dynamic_cast<const CustomCPPForceImpl*>(impl) != NULL || dynamic_cast<const PythonForceImpl*>(impl) != NULL)
if (impl != &force && (dynamic_cast<const CustomCPPForceImpl*>(impl) != NULL || dynamic_cast<const PythonForceImpl*>(impl) != NULL))
useWorkerThread = false;
if (useWorkerThread) {
cc.addPreComputation(new StartCalculationPreComputation(*this));
......@@ -4871,7 +4871,7 @@ void CommonCalcPythonForceKernel::initialize(const ContextImpl& context, const P
forceGroupFlag = (1<<force.getForceGroup());
useWorkerThread = (cc.getNumContexts() == 1);
for (const ForceImpl* impl : context.getForceImpls())
if (dynamic_cast<const CustomCPPForceImpl*>(impl) != NULL || dynamic_cast<const PythonForceImpl*>(impl) != NULL)
if (&impl->getOwner() != &force && (dynamic_cast<const CustomCPPForceImpl*>(impl) != NULL || dynamic_cast<const PythonForceImpl*>(impl) != NULL))
useWorkerThread = false;
if (useWorkerThread) {
cc.addPreComputation(new StartCalculationPreComputation(*this));
......
......@@ -547,7 +547,11 @@ void CommonMinimizeKernel::evaluateGpu(ContextImpl& context) {
// Evaluate the forces and energy for the desired interactions as well as
// harmonic restraints to emulate the constraints.
energy = context.calcForcesAndEnergy(true, true, forceGroups);
{
ContextDeselector deselector(cc);
energy = context.calcForcesAndEnergy(true, true, forceGroups);
}
if (numConstraints) {
if (mixedIsDouble) {
getConstraintEnergyForcesKernel->setArg(8, kRestraint);
......@@ -592,7 +596,11 @@ double CommonMinimizeKernel::evaluateCpu(ContextImpl& context) {
cpuContext->setState(context.getOwner().getState(State::Parameters));
cpuContext->setPositions(hostPositions);
cpuContext->computeVirtualSites();
State state = cpuContext->getState(State::Energy | State::Forces, false, forceGroups);
State state;
{
ContextDeselector deselector(cc);
state = cpuContext->getState(State::Energy | State::Forces, false, forceGroups);
}
double hostEnergy = state.getPotentialEnergy();
const vector<Vec3>& hostForces = state.getForces();
......@@ -676,7 +684,10 @@ bool CommonMinimizeKernel::report(ContextImpl& context, int iteration) {
args["system energy"] = energy - restraintEnergy;
args["restraint strength"] = kRestraint;
args["max constraint error"] = maxError;
return reporter->report(iteration - 1, hostX, hostGrad, args);
{
ContextDeselector deselector(cc);
return reporter->report(iteration - 1, hostX, hostGrad, args);
}
}
void CommonMinimizeKernel::downloadReturnFlagStart() {
......
......@@ -461,8 +461,11 @@ void CudaContext::pushAsCurrent() {
void CudaContext::popAsCurrent() {
CUcontext popped;
if (contextIsValid)
if (contextIsValid) {
cuCtxPopCurrent(&popped);
if (popped != context)
throw OpenMMException("Called popAsCurrent() on a context that is not current");
}
}
CUmodule CudaContext::createModule(const string source, const char* optimizationFlags) {
......@@ -886,4 +889,4 @@ void CudaContext::ensureCudaInitialized() {
CHECK_RESULT2(cuInit(0), "Error initializing CUDA");
hasInitializedCuda = true;
}
}
\ No newline at end of file
}
This diff is collapsed.
......@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2025 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -34,13 +34,14 @@
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/MonteCarloMembraneBarostat.h"
#include "openmm/Context.h"
#include "ReferencePlatform.h"
#include "openmm/CustomIntegrator.h"
#include "openmm/HarmonicAngleForce.h"
#include "openmm/HarmonicBondForce.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "openmm/VerletIntegrator.h"
#include "ReferencePlatform.h"
#include "sfmt/SFMT.h"
#include "SimTKOpenMMRealType.h"
#include <iostream>
......@@ -118,6 +119,73 @@ void testIdealGas(MonteCarloMembraneBarostat::XYMode xymode, MonteCarloMembraneB
}
}
void testMoleculeScaling(bool rigid) {
int numMolecules = 10;
double initialWidth = 3.0;
// Create a system of diatomic molecules.
System system;
Vec3 initialBox[] = {Vec3(initialWidth, 0, 0), Vec3(0, initialWidth, 0), Vec3(0, 0, initialWidth)};
system.setDefaultPeriodicBoxVectors(initialBox[0], initialBox[1], initialBox[2]);
HarmonicBondForce* bonds = new HarmonicBondForce();
system.addForce(bonds);
NonbondedForce* nonbonded = new NonbondedForce();
nonbonded->setNonbondedMethod(NonbondedForce::CutoffPeriodic);
system.addForce(nonbonded);
MonteCarloMembraneBarostat* barostat = new MonteCarloMembraneBarostat(1.0, 0.0, 300.0, MonteCarloMembraneBarostat::XYAnisotropic, MonteCarloMembraneBarostat::ZFree, 1, rigid);
system.addForce(barostat);
vector<Vec3> positions;
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
for (int i = 0; i < numMolecules; i++) {
system.addParticle(1.0);
system.addParticle(1.0);
bonds->addBond(2*i, 2*i+1, 0.2, 1000.0);
nonbonded->addParticle(0.0, 0.1, 1.0);
nonbonded->addParticle(0.0, 0.1, 1.0);
Vec3 pos1(initialWidth*genrand_real2(sfmt), initialWidth*genrand_real2(sfmt), initialWidth*genrand_real2(sfmt));
Vec3 delta(genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5, genrand_real2(sfmt)-0.5);
delta /= sqrt(delta.dot(delta));
positions.push_back(pos1);
positions.push_back(pos1+delta);
}
// Use an integrator that applies the barostat but nothing else.
CustomIntegrator integrator(1.0);
integrator.addUpdateContextState();
// Let the barostat make some moves.
Context context(system, integrator, platform);
context.setPositions(positions);
integrator.step(100);
State state = context.getState(State::Positions);
// The box size should have changed.
Vec3 finalBox[3];
state.getPeriodicBoxVectors(finalBox[0], finalBox[1], finalBox[2]);
for (int i = 0; i < 3; i++)
ASSERT(finalBox[i][i] != initialBox[i][i]);
// See if the molecules were scaled correctly.
Vec3 boxScale(finalBox[0][0]/initialBox[0][0], finalBox[1][1]/initialBox[1][1], finalBox[2][2]/initialBox[2][2]);
for (int i = 0; i < numMolecules; i++) {
Vec3 delta1 = positions[2*i+1]-positions[2*i];
Vec3 delta2 = state.getPositions()[2*i+1]-state.getPositions()[2*i];
if (rigid) {
ASSERT_EQUAL_VEC(delta1, delta2, 1e-5);
}
else {
Vec3 expected(delta1[0]*boxScale[0], delta1[1]*boxScale[1], delta1[2]*boxScale[2]);
ASSERT_EQUAL_VEC(expected, delta2, 1e-5);
}
}
}
void testRandomSeed() {
const int numParticles = 8;
const double temp = 100.0;
......@@ -256,6 +324,8 @@ int main() {
testIdealGas(MonteCarloMembraneBarostat::XYAnisotropic, MonteCarloMembraneBarostat::ZFree);
testIdealGas(MonteCarloMembraneBarostat::XYAnisotropic, MonteCarloMembraneBarostat::ZFixed);
testIdealGas(MonteCarloMembraneBarostat::XYAnisotropic, MonteCarloMembraneBarostat::ConstantVolume);
testMoleculeScaling(true);
testMoleculeScaling(false);
testRandomSeed();
testCrystal();
}
......
......@@ -7,7 +7,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2012 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman *
* Contributors: *
* *
......@@ -59,9 +59,7 @@ public:
/**
* Get the number of particles in the system.
*/
int getNumParticles() const {
return particles.size();
}
int getNumParticles() const;
/**
* Add the parameters for a particle. This should be called once for each particle
......
......@@ -7,7 +7,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2016 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman *
* Contributors: *
* *
......@@ -105,9 +105,7 @@ public:
/**
* Get the number of particles in the potential function
*/
int getNumMultipoles() const {
return multipoles.size();
}
int getNumMultipoles() const;
/**
* Get the method used for handling long-range nonbonded interactions.
......
......@@ -7,7 +7,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2016 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman *
* Contributors: *
* *
......@@ -59,16 +59,12 @@ public:
/**
* Get the number of torsion-torsion terms in the potential function
*/
int getNumTorsionTorsions(void) const {
return torsionTorsions.size();
}
int getNumTorsionTorsions(void) const;
/**
* Get the number of torsion-torsion grids
*/
int getNumTorsionTorsionGrids(void) const {
return torsionTorsionGrids.size();
}
int getNumTorsionTorsionGrids(void) const;
/**
* Add a torsion-torsion term to the force field.
......
......@@ -7,7 +7,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2020 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman *
* Contributors: *
* *
......@@ -143,23 +143,17 @@ public:
/**
* Get the number of particles
*/
int getNumParticles() const {
return parameters.size();
}
int getNumParticles() const;
/**
* Get the number of particle types.
*/
int getNumParticleTypes() const {
return types.size();
}
int getNumParticleTypes() const;
/**
* Get the number of type pairs.
*/
int getNumTypePairs() const {
return pairs.size();
}
int getNumTypePairs() const;
/**
* Set the force field parameters for a vdw particle.
......
......@@ -7,7 +7,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2012 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Mark Friedrichs, Peter Eastman *
* Contributors: *
* *
......@@ -57,9 +57,7 @@ public:
/**
* Get the number of particles
*/
int getNumParticles() const {
return parameters.size();
}
int getNumParticles() const;
/**
* Set the force field parameters for a WCA dispersion particle.
......
......@@ -7,7 +7,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Peter Eastman, Mark Friedrichs *
* Contributors: *
* *
......@@ -79,15 +79,11 @@ public:
/**
* Get the number of particles in the potential function.
*/
int getNumParticles() const {
return particles.size();
}
int getNumParticles() const;
/**
* Get the number of exceptions.
*/
int getNumExceptions() const {
return exceptions.size();
}
int getNumExceptions() const;
/**
* Get the method used for handling long-range nonbonded interactions.
*/
......
......@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2009 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -40,6 +40,10 @@ AmoebaGeneralizedKirkwoodForce::AmoebaGeneralizedKirkwoodForce() :
surfaceAreaFactor = -6.0* 3.1415926535*0.0216*1000.0*0.4184;
}
int AmoebaGeneralizedKirkwoodForce::getNumParticles() const {
return particles.size();
}
int AmoebaGeneralizedKirkwoodForce::addParticle(double charge, double radius, double scalingFactor) {
particles.push_back(ParticleInfo(charge, radius, scalingFactor, radius, 0.0));
return particles.size()-1;
......
......@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2016 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: *
* Contributors: *
* *
......@@ -46,6 +46,10 @@ AmoebaMultipoleForce::AmoebaMultipoleForce() : nonbondedMethod(NoCutoff), polari
extrapolationCoefficients.push_back(0.474);
}
int AmoebaMultipoleForce::getNumMultipoles() const {
return multipoles.size();
}
AmoebaMultipoleForce::NonbondedMethod AmoebaMultipoleForce::getNonbondedMethod() const {
return nonbondedMethod;
}
......
......@@ -39,6 +39,13 @@ using namespace std;
AmoebaTorsionTorsionForce::AmoebaTorsionTorsionForce() : usePeriodic(false) {
}
int AmoebaTorsionTorsionForce::getNumTorsionTorsions(void) const {
return torsionTorsions.size();
}
int AmoebaTorsionTorsionForce::getNumTorsionTorsionGrids(void) const {
return torsionTorsionGrids.size();
}
int AmoebaTorsionTorsionForce::addTorsionTorsion(int particle1, int particle2, int particle3,
int particle4, int particle5, int chiralCheckAtomIndex,
int gridIndex) {
......
......@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2020 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: *
* Contributors: *
* *
......@@ -42,6 +42,18 @@ AmoebaVdwForce::AmoebaVdwForce() : nonbondedMethod(NoCutoff), potentialFunction(
useTypes(false), alchemicalMethod(None), n(5), alpha(0.7) {
}
int AmoebaVdwForce::getNumParticles() const {
return parameters.size();
}
int AmoebaVdwForce::getNumParticleTypes() const {
return types.size();
}
int AmoebaVdwForce::getNumTypePairs() const {
return pairs.size();
}
int AmoebaVdwForce::addParticle(int parentIndex, double sigma, double epsilon, double reductionFactor, bool isAlchemical, double scaleFactor) {
if (useTypes)
throw OpenMMException("AmoebaVdwForce: must use the same version of addParticle() for all particles");
......
......@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2009 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: *
* Contributors: *
* *
......@@ -54,6 +54,10 @@ AmoebaWcaDispersionForce::AmoebaWcaDispersionForce() {
shctd = 0.82;
}
int AmoebaWcaDispersionForce::getNumParticles() const {
return parameters.size();
}
int AmoebaWcaDispersionForce::addParticle(double radius, double epsilon) {
parameters.push_back(WcaDispersionInfo(radius, epsilon));
return parameters.size()-1;
......
......@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2008-2019 Stanford University and the Authors. *
* Portions copyright (c) 2008-2026 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -42,6 +42,14 @@ HippoNonbondedForce::HippoNonbondedForce() : nonbondedMethod(NoCutoff), cutoffDi
extrapolationCoefficients = {0.042, 0.635, 0.414};
}
int HippoNonbondedForce::getNumParticles() const {
return particles.size();
}
int HippoNonbondedForce::getNumExceptions() const {
return exceptions.size();
}
HippoNonbondedForce::NonbondedMethod HippoNonbondedForce::getNonbondedMethod() const {
return nonbondedMethod;
}
......
......@@ -1399,8 +1399,10 @@ void CommonCalcAmoebaMultipoleForceKernel::ensureMultipolesValid(ContextImpl& co
}
}
}
if (!multipolesAreValid)
if (!multipolesAreValid) {
ContextDeselector deselector(cc);
context.calcForcesAndEnergy(false, false, context.getIntegrator().getIntegrationForceGroups());
}
}
void CommonCalcAmoebaMultipoleForceKernel::getLabFramePermanentDipoles(ContextImpl& context, vector<Vec3>& dipoles) {
......@@ -3487,8 +3489,10 @@ void CommonCalcHippoNonbondedForceKernel::ensureMultipolesValid(ContextImpl& con
}
}
}
if (!multipolesAreValid)
if (!multipolesAreValid) {
ContextDeselector deselector(cc);
context.calcForcesAndEnergy(false, false, context.getIntegrator().getIntegrationForceGroups());
}
}
void CommonCalcHippoNonbondedForceKernel::getLabFramePermanentDipoles(ContextImpl& context, vector<Vec3>& dipoles) {
......
......@@ -7,7 +7,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2013-2024 Stanford University and the Authors. *
* Portions copyright (c) 2013-2026 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -59,15 +59,11 @@ public:
/**
* Get the number of particles for which force field parameters have been defined.
*/
int getNumParticles() const {
return particles.size();
}
int getNumParticles() const;
/**
* Get the number of special interactions that should be calculated differently from other interactions.
*/
int getNumScreenedPairs() const {
return screenedPairs.size();
}
int getNumScreenedPairs() const;
/**
* Add a Drude particle to which forces should be applied.
*
......
......@@ -4,7 +4,7 @@
* This is part of the OpenMM molecular simulation toolkit. *
* See https://openmm.org/development. *
* *
* Portions copyright (c) 2013-2024 Stanford University and the Authors. *
* Portions copyright (c) 2013-2026 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
......@@ -39,6 +39,14 @@ using namespace std;
DrudeForce::DrudeForce() : usePeriodic(false) {
}
int DrudeForce::getNumParticles() const {
return particles.size();
}
int DrudeForce::getNumScreenedPairs() const {
return screenedPairs.size();
}
int DrudeForce::addParticle(int particle, int particle1, int particle2, int particle3, int particle4, double charge, double polarizability, double aniso12, double aniso34) {
if (polarizability <= 0)
throw OpenMMException("Polarizability must be positive");
......
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