Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
tsoc
openmm
Commits
9cad8b27
"platforms/opencl/vscode:/vscode.git/clone" did not exist on "baf7942c74ad90a2f67ad189250a9bd3cb42fca7"
Commit
9cad8b27
authored
Jun 25, 2009
by
Peter Eastman
Browse files
Improved algorithm for VariableVerletIntegrator
parent
4eb99b87
Changes
6
Show whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
34 additions
and
84 deletions
+34
-84
openmmapi/include/openmm/VariableVerletIntegrator.h
openmmapi/include/openmm/VariableVerletIntegrator.h
+1
-2
openmmapi/src/VariableVerletIntegrator.cpp
openmmapi/src/VariableVerletIntegrator.cpp
+1
-2
platforms/reference/src/ReferenceKernels.cpp
platforms/reference/src/ReferenceKernels.cpp
+2
-2
platforms/reference/src/SimTKReference/ReferenceVariableVerletDynamics.cpp
...ce/src/SimTKReference/ReferenceVariableVerletDynamics.cpp
+25
-62
platforms/reference/src/SimTKReference/ReferenceVariableVerletDynamics.h
...ence/src/SimTKReference/ReferenceVariableVerletDynamics.h
+2
-13
platforms/reference/tests/TestReferenceVariableVerletIntegrator.cpp
...reference/tests/TestReferenceVariableVerletIntegrator.cpp
+3
-3
No files found.
openmmapi/include/openmm/VariableVerletIntegrator.h
View file @
9cad8b27
...
@@ -63,10 +63,9 @@ public:
...
@@ -63,10 +63,9 @@ public:
/**
/**
* Create a VariableVerletIntegrator.
* Create a VariableVerletIntegrator.
*
*
* @param stepSize the initial step size to use (in picoseconds)
* @param tol the error tolerance
* @param tol the error tolerance
*/
*/
VariableVerletIntegrator
(
double
stepSize
,
double
errorTol
);
VariableVerletIntegrator
(
double
errorTol
);
/**
/**
* Get the error tolerance.
* Get the error tolerance.
*/
*/
...
...
openmmapi/src/VariableVerletIntegrator.cpp
View file @
9cad8b27
...
@@ -39,8 +39,7 @@ using namespace OpenMM;
...
@@ -39,8 +39,7 @@ using namespace OpenMM;
using
std
::
string
;
using
std
::
string
;
using
std
::
vector
;
using
std
::
vector
;
VariableVerletIntegrator
::
VariableVerletIntegrator
(
double
stepSize
,
double
errorTol
)
:
errorTol
(
errorTol
)
{
VariableVerletIntegrator
::
VariableVerletIntegrator
(
double
errorTol
)
:
errorTol
(
errorTol
)
{
setStepSize
(
stepSize
);
setConstraintTolerance
(
1e-4
);
setConstraintTolerance
(
1e-4
);
}
}
...
...
platforms/reference/src/ReferenceKernels.cpp
View file @
9cad8b27
...
@@ -814,7 +814,7 @@ void ReferenceIntegrateVariableVerletStepKernel::execute(OpenMMContextImpl& cont
...
@@ -814,7 +814,7 @@ void ReferenceIntegrateVariableVerletStepKernel::execute(OpenMMContextImpl& cont
delete
dynamics
;
delete
dynamics
;
delete
constraints
;
delete
constraints
;
}
}
dynamics
=
new
ReferenceVariableVerletDynamics
(
context
.
getSystem
().
getNumParticles
(),
static_cast
<
RealOpenMM
>
(
stepSize
),
errorTol
);
dynamics
=
new
ReferenceVariableVerletDynamics
(
context
.
getSystem
().
getNumParticles
(),
(
RealOpenMM
)
errorTol
);
vector
<
ReferenceCCMAAlgorithm
::
AngleInfo
>
angles
;
vector
<
ReferenceCCMAAlgorithm
::
AngleInfo
>
angles
;
findAnglesForCCMA
(
context
.
getSystem
(),
angles
);
findAnglesForCCMA
(
context
.
getSystem
(),
angles
);
constraints
=
new
ReferenceCCMAAlgorithm
(
context
.
getSystem
().
getNumParticles
(),
numConstraints
,
constraintIndices
,
constraintDistances
,
masses
,
angles
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
constraints
=
new
ReferenceCCMAAlgorithm
(
context
.
getSystem
().
getNumParticles
(),
numConstraints
,
constraintIndices
,
constraintDistances
,
masses
,
angles
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
...
@@ -823,7 +823,7 @@ void ReferenceIntegrateVariableVerletStepKernel::execute(OpenMMContextImpl& cont
...
@@ -823,7 +823,7 @@ void ReferenceIntegrateVariableVerletStepKernel::execute(OpenMMContextImpl& cont
prevErrorTol
=
errorTol
;
prevErrorTol
=
errorTol
;
}
}
dynamics
->
update
(
context
.
getSystem
().
getNumParticles
(),
posData
,
velData
,
forceData
,
masses
);
dynamics
->
update
(
context
.
getSystem
().
getNumParticles
(),
posData
,
velData
,
forceData
,
masses
);
data
.
time
+=
dynamics
->
get
LastStepSize
();
data
.
time
+=
dynamics
->
get
DeltaT
();
}
}
ReferenceApplyAndersenThermostatKernel
::~
ReferenceApplyAndersenThermostatKernel
()
{
ReferenceApplyAndersenThermostatKernel
::~
ReferenceApplyAndersenThermostatKernel
()
{
...
...
platforms/reference/src/SimTKReference/ReferenceVariableVerletDynamics.cpp
View file @
9cad8b27
...
@@ -40,9 +40,8 @@
...
@@ -40,9 +40,8 @@
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceVariableVerletDynamics
::
ReferenceVariableVerletDynamics
(
int
numberOfAtoms
,
ReferenceVariableVerletDynamics
::
ReferenceVariableVerletDynamics
(
int
numberOfAtoms
,
RealOpenMM
accuracy
)
:
RealOpenMM
deltaT
,
RealOpenMM
accuracy
)
:
ReferenceDynamics
(
numberOfAtoms
,
0.0
f
,
0.0
f
),
_accuracy
(
accuracy
)
{
ReferenceDynamics
(
numberOfAtoms
,
deltaT
,
0.0
),
_accuracy
(
accuracy
)
{
// ---------------------------------------------------------------------------------------
// ---------------------------------------------------------------------------------------
...
@@ -96,18 +95,6 @@ void ReferenceVariableVerletDynamics::setAccuracy( RealOpenMM accuracy ) {
...
@@ -96,18 +95,6 @@ void ReferenceVariableVerletDynamics::setAccuracy( RealOpenMM accuracy ) {
_accuracy
=
accuracy
;
_accuracy
=
accuracy
;
}
}
/**---------------------------------------------------------------------------------------
Get the actual size of the last step that was taken
@return step size
--------------------------------------------------------------------------------------- */
RealOpenMM
ReferenceVariableVerletDynamics
::
getLastStepSize
(
void
)
const
{
return
_lastStepSize
;
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
Print parameters
Print parameters
...
@@ -195,58 +182,34 @@ int ReferenceVariableVerletDynamics::update( int numberOfAtoms, RealOpenMM** ato
...
@@ -195,58 +182,34 @@ int ReferenceVariableVerletDynamics::update( int numberOfAtoms, RealOpenMM** ato
}
}
}
}
// Try different step sizes until the accuracy is acceptable.
bool
success
=
false
;
RealOpenMM
maxStepSize
=
5.0
f
*
getDeltaT
();
while
(
!
success
)
{
// Perform the integration and estimate the error.
_lastStepSize
=
getDeltaT
();
RealOpenMM
error
=
zero
;
RealOpenMM
error
=
zero
;
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
++
i
)
{
for
(
int
j
=
0
;
j
<
3
;
++
j
)
{
for
(
int
j
=
0
;
j
<
3
;
++
j
)
{
RealOpenMM
xref
=
atomCoordinates
[
i
][
j
]
+
velocities
[
i
][
j
]
*
getDeltaT
();
RealOpenMM
xerror
=
inverseMasses
[
i
]
*
forces
[
i
][
j
];
RealOpenMM
vPrime
=
velocities
[
i
][
j
]
+
inverseMasses
[
i
]
*
forces
[
i
][
j
]
*
getDeltaT
();
xPrime
[
i
][
j
]
=
atomCoordinates
[
i
][
j
]
+
vPrime
*
getDeltaT
();
RealOpenMM
xerror
=
xPrime
[
i
][
j
]
-
xref
;
error
+=
xerror
*
xerror
;
error
+=
xerror
*
xerror
;
}
}
}
}
error
=
SQRT
(
error
/
(
numberOfAtoms
*
3
));
error
=
SQRT
(
error
/
(
numberOfAtoms
*
3
));
RealOpenMM
newStepSize
=
SQRT
(
getAccuracy
()
/
error
);
// Select a new step size.
if
(
getDeltaT
()
>
0.0
f
)
newStepSize
=
std
::
min
(
newStepSize
,
getDeltaT
()
*
2.0
f
);
// For safety, limit how quickly dt can increase.
const
RealOpenMM
Safety
=
0.9
f
,
MinShrink
=
0.1
f
;
if
(
newStepSize
>
getDeltaT
()
&&
newStepSize
<
1.2
f
*
getDeltaT
())
const
RealOpenMM
HysteresisLow
=
0.9
f
,
HysteresisHigh
=
1.0
f
,
ErrorOrder
=
2.0
f
;
newStepSize
=
getDeltaT
();
// Keeping dt constant between steps improves the behavior of the integrator.
RealOpenMM
vstep
=
0.5
f
*
(
newStepSize
+
getDeltaT
());
// The time interval by which to advance the velocities
RealOpenMM
newStepSize
=
Safety
*
getDeltaT
()
*
POW
(
getAccuracy
()
/
error
,
1.0
f
/
ErrorOrder
);
setDeltaT
(
newStepSize
);
if
(
newStepSize
>
getDeltaT
())
{
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
++
i
)
{
if
(
newStepSize
<
HysteresisHigh
*
getDeltaT
())
for
(
int
j
=
0
;
j
<
3
;
++
j
)
{
newStepSize
=
getDeltaT
();
RealOpenMM
vPrime
=
velocities
[
i
][
j
]
+
inverseMasses
[
i
]
*
forces
[
i
][
j
]
*
vstep
;
xPrime
[
i
][
j
]
=
atomCoordinates
[
i
][
j
]
+
vPrime
*
getDeltaT
();
}
}
}
if
(
newStepSize
<
getDeltaT
()
&&
error
<=
getAccuracy
())
newStepSize
=
getDeltaT
();
newStepSize
=
std
::
min
(
newStepSize
,
maxStepSize
);
newStepSize
=
std
::
max
(
newStepSize
,
MinShrink
*
getDeltaT
());
if
(
newStepSize
<
getDeltaT
())
newStepSize
=
std
::
min
(
newStepSize
,
HysteresisLow
*
getDeltaT
());
success
=
(
newStepSize
>=
getDeltaT
());
if
(
success
)
{
ReferenceConstraintAlgorithm
*
referenceConstraintAlgorithm
=
getReferenceConstraintAlgorithm
();
ReferenceConstraintAlgorithm
*
referenceConstraintAlgorithm
=
getReferenceConstraintAlgorithm
();
if
(
referenceConstraintAlgorithm
)
if
(
referenceConstraintAlgorithm
)
success
=
(
referenceConstraintAlgorithm
->
apply
(
numberOfAtoms
,
atomCoordinates
,
xPrime
,
inverseMasses
)
!=
ErrorReturn
);
referenceConstraintAlgorithm
->
apply
(
numberOfAtoms
,
atomCoordinates
,
xPrime
,
inverseMasses
);
if
(
!
success
)
{
newStepSize
*=
0.5
f
;
maxStepSize
=
newStepSize
;
}
}
setDeltaT
(
newStepSize
);
}
// Update the positions and velocities.
// Update the positions and velocities.
RealOpenMM
velocityScale
=
static_cast
<
RealOpenMM
>
(
1.0
/
_lastStepSize
);
RealOpenMM
velocityScale
=
one
/
getDeltaT
(
);
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
++
i
)
{
for
(
int
j
=
0
;
j
<
3
;
++
j
)
{
for
(
int
j
=
0
;
j
<
3
;
++
j
)
{
velocities
[
i
][
j
]
=
velocityScale
*
(
xPrime
[
i
][
j
]
-
atomCoordinates
[
i
][
j
]);
velocities
[
i
][
j
]
=
velocityScale
*
(
xPrime
[
i
][
j
]
-
atomCoordinates
[
i
][
j
]);
...
...
platforms/reference/src/SimTKReference/ReferenceVariableVerletDynamics.h
View file @
9cad8b27
...
@@ -35,7 +35,7 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
...
@@ -35,7 +35,7 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
enum
TwoDArrayIndicies
{
xPrime2D
,
Max2DArrays
};
enum
TwoDArrayIndicies
{
xPrime2D
,
Max2DArrays
};
enum
OneDArrayIndicies
{
InverseMasses
,
Max1DArrays
};
enum
OneDArrayIndicies
{
InverseMasses
,
Max1DArrays
};
RealOpenMM
_accuracy
,
_lastStepSize
;
RealOpenMM
_accuracy
;
public:
public:
...
@@ -44,12 +44,11 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
...
@@ -44,12 +44,11 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
Constructor
Constructor
@param numberOfAtoms number of atoms
@param numberOfAtoms number of atoms
@param deltaT initial delta t for dynamics
@param accuracy required accuracy
@param accuracy required accuracy
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceVariableVerletDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
accuracy
);
ReferenceVariableVerletDynamics
(
int
numberOfAtoms
,
RealOpenMM
accuracy
);
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -77,16 +76,6 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
...
@@ -77,16 +76,6 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
void
setAccuracy
(
RealOpenMM
accuracy
);
void
setAccuracy
(
RealOpenMM
accuracy
);
/**---------------------------------------------------------------------------------------
Get the actual size of the last step that was taken
@return step size
--------------------------------------------------------------------------------------- */
RealOpenMM
getLastStepSize
(
void
)
const
;
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
Print parameters
Print parameters
...
...
platforms/reference/tests/TestReferenceVariableVerletIntegrator.cpp
View file @
9cad8b27
...
@@ -55,7 +55,7 @@ void testSingleBond() {
...
@@ -55,7 +55,7 @@ void testSingleBond() {
System
system
;
System
system
;
system
.
addParticle
(
2.0
);
system
.
addParticle
(
2.0
);
system
.
addParticle
(
2.0
);
system
.
addParticle
(
2.0
);
VariableVerletIntegrator
integrator
(
0.01
,
1e-6
);
VariableVerletIntegrator
integrator
(
1e-6
);
HarmonicBondForce
*
forceField
=
new
HarmonicBondForce
();
HarmonicBondForce
*
forceField
=
new
HarmonicBondForce
();
forceField
->
addBond
(
0
,
1
,
1.5
,
1
);
forceField
->
addBond
(
0
,
1
,
1.5
,
1
);
system
.
addForce
(
forceField
);
system
.
addForce
(
forceField
);
...
@@ -91,7 +91,7 @@ void testConstraints() {
...
@@ -91,7 +91,7 @@ void testConstraints() {
const
double
temp
=
500.0
;
const
double
temp
=
500.0
;
ReferencePlatform
platform
;
ReferencePlatform
platform
;
System
system
;
System
system
;
VariableVerletIntegrator
integrator
(
0.002
,
1e-5
);
VariableVerletIntegrator
integrator
(
1e-5
);
integrator
.
setConstraintTolerance
(
1e-5
);
integrator
.
setConstraintTolerance
(
1e-5
);
NonbondedForce
*
forceField
=
new
NonbondedForce
();
NonbondedForce
*
forceField
=
new
NonbondedForce
();
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
...
@@ -141,7 +141,7 @@ void testConstrainedClusters() {
...
@@ -141,7 +141,7 @@ void testConstrainedClusters() {
const
double
temp
=
500.0
;
const
double
temp
=
500.0
;
ReferencePlatform
platform
;
ReferencePlatform
platform
;
System
system
;
System
system
;
VariableVerletIntegrator
integrator
(
0.002
,
1e-5
);
VariableVerletIntegrator
integrator
(
1e-5
);
integrator
.
setConstraintTolerance
(
1e-5
);
integrator
.
setConstraintTolerance
(
1e-5
);
NonbondedForce
*
forceField
=
new
NonbondedForce
();
NonbondedForce
*
forceField
=
new
NonbondedForce
();
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
{
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment