"...ssh:/git@developer.sourcefind.cn:2222/tsoc/openmm.git" did not exist on "076f8d7b71e8ed6c47a67aed3aab9cdf2bd6edf0"
Commit b815ce03 authored by peastman's avatar peastman
Browse files

setVelocitiesToTemperature() applies offset for leapfrog integrators

parent 7398e5a3
...@@ -187,6 +187,13 @@ protected: ...@@ -187,6 +187,13 @@ protected:
* The implementation calls computeKineticEnergy() on whichever Integrator has been set as current. * The implementation calls computeKineticEnergy() on whichever Integrator has been set as current.
*/ */
double computeKineticEnergy(); double computeKineticEnergy();
/**
* Get the time interval by which velocities are offset from positions. This is used to
* adjust velocities when setVelocitiesToTemperature() is called on a Context.
*/
double getVelocityTimeOffset() const {
return getIntegrator(0).getVelocityTimeOffset();
}
private: private:
int currentIntegrator; int currentIntegrator;
std::vector<Integrator*> integrators; std::vector<Integrator*> integrators;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * 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 * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -144,6 +144,13 @@ protected: ...@@ -144,6 +144,13 @@ protected:
* @param randomSeed the random number seed to use when selecting velocities * @param randomSeed the random number seed to use when selecting velocities
*/ */
virtual std::vector<Vec3> getVelocitiesForTemperature(const System &system, double temperature, int randomSeed) const; virtual std::vector<Vec3> getVelocitiesForTemperature(const System &system, double temperature, int randomSeed) const;
/**
* Get the time interval by which velocities are offset from positions. This is used to
* adjust velocities when setVelocitiesToTemperature() is called on a Context.
*/
virtual double getVelocityTimeOffset() const {
return 0.0;
}
private: private:
double stepSize, constraintTol; double stepSize, constraintTol;
}; };
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2008-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2020 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -133,6 +133,13 @@ protected: ...@@ -133,6 +133,13 @@ protected:
* Compute the kinetic energy of the system at the current time. * Compute the kinetic energy of the system at the current time.
*/ */
double computeKineticEnergy(); double computeKineticEnergy();
/**
* Get the time interval by which velocities are offset from positions. This is used to
* adjust velocities when setVelocitiesToTemperature() is called on a Context.
*/
double getVelocityTimeOffset() const {
return getStepSize()/2;
}
private: private:
double temperature, friction; double temperature, friction;
int randomNumberSeed; int randomNumberSeed;
......
...@@ -140,6 +140,13 @@ protected: ...@@ -140,6 +140,13 @@ protected:
* Computing kinetic energy for this integrator does not require forces. * Computing kinetic energy for this integrator does not require forces.
*/ */
bool kineticEnergyRequiresForce() const; bool kineticEnergyRequiresForce() const;
/**
* Get the time interval by which velocities are offset from positions. This is used to
* adjust velocities when setVelocitiesToTemperature() is called on a Context.
*/
double getVelocityTimeOffset() const {
return getStepSize()/2;
}
private: private:
double temperature, friction; double temperature, friction;
int randomNumberSeed; int randomNumberSeed;
......
...@@ -9,7 +9,7 @@ ...@@ -9,7 +9,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for * * Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. * * Medical Research, grant U54 GM072970. See https://simtk.org. *
* * * *
* Portions copyright (c) 2008-2012 Stanford University and the Authors. * * Portions copyright (c) 2008-2020 Stanford University and the Authors. *
* Authors: Peter Eastman * * Authors: Peter Eastman *
* Contributors: * * Contributors: *
* * * *
...@@ -76,6 +76,13 @@ protected: ...@@ -76,6 +76,13 @@ protected:
* Compute the kinetic energy of the system at the current time. * Compute the kinetic energy of the system at the current time.
*/ */
double computeKineticEnergy(); double computeKineticEnergy();
/**
* Get the time interval by which velocities are offset from positions. This is used to
* adjust velocities when setVelocitiesToTemperature() is called on a Context.
*/
double getVelocityTimeOffset() const {
return getStepSize()/2;
}
private: private:
Kernel kernel; Kernel kernel;
}; };
......
...@@ -183,7 +183,19 @@ void Context::setVelocities(const vector<Vec3>& velocities) { ...@@ -183,7 +183,19 @@ void Context::setVelocities(const vector<Vec3>& velocities) {
void Context::setVelocitiesToTemperature(double temperature, int randomSeed) { void Context::setVelocitiesToTemperature(double temperature, int randomSeed) {
const Integrator& integrator = impl->getIntegrator(); const Integrator& integrator = impl->getIntegrator();
const System& system = impl->getSystem(); const System& system = impl->getSystem();
setVelocities(integrator.getVelocitiesForTemperature(system, temperature, randomSeed)); vector<Vec3> velocities = integrator.getVelocitiesForTemperature(system, temperature, randomSeed);
double offset = integrator.getVelocityTimeOffset();
if (offset != 0.0) {
impl->calcForcesAndEnergy(true, false, -1);
vector<Vec3> forces;
impl->getForces(forces);
for (int i = 0; i < system.getNumParticles(); i++) {
double mass = system.getParticleMass(i);
if (mass != 0.0)
velocities[i] -= (offset/mass)*forces[i];
}
}
setVelocities(velocities);
impl->applyVelocityConstraints(1e-5); impl->applyVelocityConstraints(1e-5);
} }
......
...@@ -121,12 +121,12 @@ void CommonCalcDrudeForceKernel::initialize(const System& system, const DrudeFor ...@@ -121,12 +121,12 @@ void CommonCalcDrudeForceKernel::initialize(const System& system, const DrudeFor
double k1 = ONE_4PI_EPS0*charge*charge/(polarizability*a1) - k3; double k1 = ONE_4PI_EPS0*charge*charge/(polarizability*a1) - k3;
double k2 = ONE_4PI_EPS0*charge*charge/(polarizability*a2) - k3; double k2 = ONE_4PI_EPS0*charge*charge/(polarizability*a2) - k3;
if (atoms[i][2] == -1) { if (atoms[i][2] == -1) {
atoms[i][2] = 0; atoms[i][2] = atoms[i][0];
k1 = 0; k1 = 0;
} }
if (atoms[i][3] == -1 || atoms[i][4] == -1) { if (atoms[i][3] == -1 || atoms[i][4] == -1) {
atoms[i][3] = 0; atoms[i][3] = atoms[i][0];
atoms[i][4] = 0; atoms[i][4] = atoms[i][0];
k2 = 0; k2 = 0;
} }
paramVector[i] = mm_float4((float) k1, (float) k2, (float) k3, 0.0f); paramVector[i] = mm_float4((float) k1, (float) k2, (float) k3, 0.0f);
......
...@@ -231,7 +231,7 @@ void testForceEnergyConsistency() { ...@@ -231,7 +231,7 @@ void testForceEnergyConsistency() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numRealParticles = 500000; const int numRealParticles = 50000;
const int numParticles = 2 * numRealParticles; const int numParticles = 2 * numRealParticles;
const int nDoF = 3 * numRealParticles; const int nDoF = 3 * numRealParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
......
...@@ -227,7 +227,7 @@ double testWaterBoxWithHardWallConstraint(double hardWallConstraint){ ...@@ -227,7 +227,7 @@ double testWaterBoxWithHardWallConstraint(double hardWallConstraint){
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numRealParticles = 500000; const int numRealParticles = 50000;
const int numParticles = 2 * numRealParticles; const int numParticles = 2 * numRealParticles;
const int nDoF = 3 * numRealParticles; const int nDoF = 3 * numRealParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
......
...@@ -135,7 +135,7 @@ void testWater() { ...@@ -135,7 +135,7 @@ void testWater() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numRealParticles = 500000; const int numRealParticles = 50000;
const int numParticles = 2 * numRealParticles; const int numParticles = 2 * numRealParticles;
const int nDoF = 3 * numRealParticles; const int nDoF = 3 * numRealParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
......
...@@ -253,7 +253,7 @@ void testRandomSeed() { ...@@ -253,7 +253,7 @@ void testRandomSeed() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numParticles = 500000; const int numParticles = 50000;
const int nDoF = 3 * numParticles; const int nDoF = 3 * numParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
System system; System system;
......
...@@ -1130,7 +1130,7 @@ void testRecordEnergy() { ...@@ -1130,7 +1130,7 @@ void testRecordEnergy() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numParticles = 500000; const int numParticles = 50000;
const int nDoF = 3 * numParticles; const int nDoF = 3 * numParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
System system; System system;
......
...@@ -260,7 +260,7 @@ void testRandomSeed() { ...@@ -260,7 +260,7 @@ void testRandomSeed() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numParticles = 500000; const int numParticles = 50000;
const int nDoF = 3 * numParticles; const int nDoF = 3 * numParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
System system; System system;
......
...@@ -263,7 +263,7 @@ void testRandomSeed() { ...@@ -263,7 +263,7 @@ void testRandomSeed() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numParticles = 500000; const int numParticles = 50000;
const int nDoF = 3 * numParticles; const int nDoF = 3 * numParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
System system; System system;
......
...@@ -271,7 +271,7 @@ void testThreeParticleVirtualSite() { ...@@ -271,7 +271,7 @@ void testThreeParticleVirtualSite() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numParticles = 500000; const int numParticles = 50000;
const int nDoF = 3 * numParticles; const int nDoF = 3 * numParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
System system; System system;
......
...@@ -332,7 +332,7 @@ void testArgonBox() { ...@@ -332,7 +332,7 @@ void testArgonBox() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numParticles = 500000; const int numParticles = 50000;
const int nDoF = 3 * numParticles; const int nDoF = 3 * numParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
System system; System system;
......
...@@ -311,7 +311,7 @@ void testArgonBox() { ...@@ -311,7 +311,7 @@ void testArgonBox() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numParticles = 500000; const int numParticles = 50000;
const int nDoF = 3 * numParticles; const int nDoF = 3 * numParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
System system; System system;
......
...@@ -228,7 +228,7 @@ void testConstrainedMasslessParticles() { ...@@ -228,7 +228,7 @@ void testConstrainedMasslessParticles() {
void testInitialTemperature() { void testInitialTemperature() {
// Check temperature initialization for a collection of randomly placed particles // Check temperature initialization for a collection of randomly placed particles
const int numParticles = 500000; const int numParticles = 50000;
const int nDoF = 3 * numParticles; const int nDoF = 3 * numParticles;
const double targetTemperature = 300; const double targetTemperature = 300;
System system; System system;
......
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