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
588a4c9d
Commit
588a4c9d
authored
Dec 10, 2013
by
peastman
Browse files
Merged changes from main branch
parents
bbf3de23
ff6af025
Changes
77
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
220 additions
and
239 deletions
+220
-239
platforms/cpu/tests/TestCpuSettle.cpp
platforms/cpu/tests/TestCpuSettle.cpp
+116
-0
platforms/cuda/sharedTarget/CMakeLists.txt
platforms/cuda/sharedTarget/CMakeLists.txt
+4
-2
platforms/cuda/tests/CMakeLists.txt
platforms/cuda/tests/CMakeLists.txt
+3
-1
platforms/opencl/sharedTarget/CMakeLists.txt
platforms/opencl/sharedTarget/CMakeLists.txt
+1
-1
platforms/opencl/tests/CMakeLists.txt
platforms/opencl/tests/CMakeLists.txt
+3
-4
platforms/reference/include/ReferenceBrownianDynamics.h
platforms/reference/include/ReferenceBrownianDynamics.h
+2
-1
platforms/reference/include/ReferenceCCMAAlgorithm.h
platforms/reference/include/ReferenceCCMAAlgorithm.h
+6
-16
platforms/reference/include/ReferenceConstraintAlgorithm.h
platforms/reference/include/ReferenceConstraintAlgorithm.h
+4
-12
platforms/reference/include/ReferenceConstraints.h
platforms/reference/include/ReferenceConstraints.h
+8
-19
platforms/reference/include/ReferenceCustomDynamics.h
platforms/reference/include/ReferenceCustomDynamics.h
+2
-1
platforms/reference/include/ReferenceDynamics.h
platforms/reference/include/ReferenceDynamics.h
+2
-1
platforms/reference/include/ReferenceKernels.h
platforms/reference/include/ReferenceKernels.h
+7
-23
platforms/reference/include/ReferencePlatform.h
platforms/reference/include/ReferencePlatform.h
+3
-1
platforms/reference/include/ReferenceSETTLEAlgorithm.h
platforms/reference/include/ReferenceSETTLEAlgorithm.h
+17
-10
platforms/reference/include/ReferenceStochasticDynamics.h
platforms/reference/include/ReferenceStochasticDynamics.h
+2
-1
platforms/reference/include/ReferenceVariableStochasticDynamics.h
...s/reference/include/ReferenceVariableStochasticDynamics.h
+2
-1
platforms/reference/include/ReferenceVariableVerletDynamics.h
...forms/reference/include/ReferenceVariableVerletDynamics.h
+2
-1
platforms/reference/include/ReferenceVerletDynamics.h
platforms/reference/include/ReferenceVerletDynamics.h
+2
-1
platforms/reference/src/ReferenceKernels.cpp
platforms/reference/src/ReferenceKernels.cpp
+29
-141
platforms/reference/src/ReferencePlatform.cpp
platforms/reference/src/ReferencePlatform.cpp
+5
-2
No files found.
platforms/cpu/tests/TestCpuSettle.cpp
0 → 100644
View file @
588a4c9d
/* -------------------------------------------------------------------------- *
* OpenMM *
* -------------------------------------------------------------------------- *
* This is part of the OpenMM molecular simulation toolkit originating from *
* Simbios, the NIH National Center for Physics-Based Simulation of *
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-2013 Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
* Permission is hereby granted, free of charge, to any person obtaining a *
* copy of this software and associated documentation files (the "Software"), *
* to deal in the Software without restriction, including without limitation *
* the rights to use, copy, modify, merge, publish, distribute, sublicense, *
* and/or sell copies of the Software, and to permit persons to whom the *
* Software is furnished to do so, subject to the following conditions: *
* *
* The above copyright notice and this permission notice shall be included in *
* all copies or substantial portions of the Software. *
* *
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR *
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, *
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL *
* THE AUTHORS, CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, *
* DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR *
* OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE *
* USE OR OTHER DEALINGS IN THE SOFTWARE. *
* -------------------------------------------------------------------------- */
/**
* This tests the CPU implementation of the SETTLE algorithm.
*/
#include "openmm/internal/AssertionUtilities.h"
#include "openmm/Context.h"
#include "CpuPlatform.h"
#include "openmm/NonbondedForce.h"
#include "openmm/System.h"
#include "openmm/LangevinIntegrator.h"
#include "sfmt/SFMT.h"
#include <iostream>
#include <vector>
using
namespace
OpenMM
;
using
namespace
std
;
void
testConstraints
()
{
const
int
numMolecules
=
10
;
const
int
numParticles
=
numMolecules
*
3
;
const
int
numConstraints
=
numMolecules
*
3
;
const
double
temp
=
100.0
;
CpuPlatform
platform
;
System
system
;
LangevinIntegrator
integrator
(
temp
,
2.0
,
0.001
);
integrator
.
setConstraintTolerance
(
1e-5
);
NonbondedForce
*
forceField
=
new
NonbondedForce
();
for
(
int
i
=
0
;
i
<
numMolecules
;
++
i
)
{
system
.
addParticle
(
16.0
);
system
.
addParticle
(
1.0
);
system
.
addParticle
(
1.0
);
forceField
->
addParticle
(
-
0.82
,
0.317
,
0.65
);
forceField
->
addParticle
(
0.41
,
1.0
,
0.0
);
forceField
->
addParticle
(
0.41
,
1.0
,
0.0
);
system
.
addConstraint
(
i
*
3
,
i
*
3
+
1
,
0.1
);
system
.
addConstraint
(
i
*
3
,
i
*
3
+
2
,
0.1
);
system
.
addConstraint
(
i
*
3
+
1
,
i
*
3
+
2
,
0.163
);
}
system
.
addForce
(
forceField
);
Context
context
(
system
,
integrator
,
platform
);
vector
<
Vec3
>
positions
(
numParticles
);
vector
<
Vec3
>
velocities
(
numParticles
);
OpenMM_SFMT
::
SFMT
sfmt
;
init_gen_rand
(
0
,
sfmt
);
for
(
int
i
=
0
;
i
<
numMolecules
;
++
i
)
{
positions
[
i
*
3
]
=
Vec3
((
i
%
4
)
*
0.4
,
(
i
/
4
)
*
0.4
,
0
);
positions
[
i
*
3
+
1
]
=
positions
[
i
*
3
]
+
Vec3
(
0.1
,
0
,
0
);
positions
[
i
*
3
+
2
]
=
positions
[
i
*
3
]
+
Vec3
(
-
0.03333
,
0.09428
,
0
);
velocities
[
i
*
3
]
=
Vec3
(
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
);
velocities
[
i
*
3
+
1
]
=
Vec3
(
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
);
velocities
[
i
*
3
+
2
]
=
Vec3
(
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
,
genrand_real2
(
sfmt
)
-
0.5
);
}
context
.
setPositions
(
positions
);
context
.
setVelocities
(
velocities
);
// Simulate it and see whether the constraints remain satisfied.
for
(
int
i
=
0
;
i
<
1000
;
++
i
)
{
integrator
.
step
(
1
);
State
state
=
context
.
getState
(
State
::
Positions
|
State
::
Forces
);
for
(
int
j
=
0
;
j
<
numConstraints
;
++
j
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
j
,
particle1
,
particle2
,
distance
);
Vec3
p1
=
state
.
getPositions
()[
particle1
];
Vec3
p2
=
state
.
getPositions
()[
particle2
];
double
dist
=
std
::
sqrt
((
p1
[
0
]
-
p2
[
0
])
*
(
p1
[
0
]
-
p2
[
0
])
+
(
p1
[
1
]
-
p2
[
1
])
*
(
p1
[
1
]
-
p2
[
1
])
+
(
p1
[
2
]
-
p2
[
2
])
*
(
p1
[
2
]
-
p2
[
2
]));
ASSERT_EQUAL_TOL
(
distance
,
dist
,
1e-5
);
}
}
}
int
main
(
int
argc
,
char
*
argv
[])
{
try
{
testConstraints
();
}
catch
(
const
exception
&
e
)
{
cout
<<
"exception: "
<<
e
.
what
()
<<
endl
;
return
1
;
}
cout
<<
"Done"
<<
endl
;
return
0
;
}
platforms/cuda/sharedTarget/CMakeLists.txt
View file @
588a4c9d
...
...
@@ -19,9 +19,11 @@ ELSE (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET
(
MAIN_OPENMM_LIB
${
OPENMM_LIBRARY_NAME
}
)
ENDIF
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
TARGET_LINK_LIBRARIES
(
${
SHARED_TARGET
}
${
MAIN_OPENMM_LIB
}
${
CUDA_CUDA_LIBRARY
}
${
CUDA_cufft_LIBRARY
}
${
PTHREADS_LIB
}
)
SET_TARGET_PROPERTIES
(
${
SHARED_TARGET
}
PROPERTIES COMPILE_FLAGS
"-DOPENMM_CUDA_BUILDING_SHARED_LIBRARY"
)
SET_TARGET_PROPERTIES
(
${
SHARED_TARGET
}
PROPERTIES COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-DOPENMM_CUDA_BUILDING_SHARED_LIBRARY"
)
IF
(
APPLE
)
SET_TARGET_PROPERTIES
(
${
SHARED_TARGET
}
PROPERTIES LINK_FLAGS
"-F/Library/Frameworks -framework CUDA"
)
SET_TARGET_PROPERTIES
(
${
SHARED_TARGET
}
PROPERTIES LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-F/Library/Frameworks -framework CUDA"
)
ELSE
(
APPLE
)
SET_TARGET_PROPERTIES
(
${
SHARED_TARGET
}
PROPERTIES LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
)
ENDIF
(
APPLE
)
INSTALL_TARGETS
(
/lib/plugins RUNTIME_DIRECTORY /lib/plugins
${
SHARED_TARGET
}
)
platforms/cuda/tests/CMakeLists.txt
View file @
588a4c9d
...
...
@@ -26,7 +26,9 @@ FOREACH(TEST_PROG ${TEST_PROGS})
ADD_EXECUTABLE
(
${
TEST_ROOT
}
${
TEST_PROG
}
)
TARGET_LINK_LIBRARIES
(
${
TEST_ROOT
}
${
SHARED_TARGET
}
)
IF
(
APPLE
)
SET_TARGET_PROPERTIES
(
${
TEST_ROOT
}
PROPERTIES LINK_FLAGS
"-F/Library/Frameworks -framework CUDA"
)
SET_TARGET_PROPERTIES
(
${
TEST_ROOT
}
PROPERTIES LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-F/Library/Frameworks -framework CUDA"
COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
)
ELSE
(
APPLE
)
SET_TARGET_PROPERTIES
(
${
TEST_ROOT
}
PROPERTIES LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
)
ENDIF
(
APPLE
)
IF
(
${
TEST_ROOT
}
STREQUAL
"TestCUDAGBSAOBCForce2"
)
...
...
platforms/opencl/sharedTarget/CMakeLists.txt
View file @
588a4c9d
...
...
@@ -19,6 +19,6 @@ ELSE (UNIX AND CMAKE_BUILD_TYPE MATCHES Debug)
SET
(
MAIN_OPENMM_LIB
${
OPENMM_LIBRARY_NAME
}
)
ENDIF
(
UNIX AND CMAKE_BUILD_TYPE MATCHES Debug
)
TARGET_LINK_LIBRARIES
(
${
SHARED_TARGET
}
${
MAIN_OPENMM_LIB
}
${
OPENCL_LIBRARIES
}
${
PTHREADS_LIB
}
)
SET_TARGET_PROPERTIES
(
${
SHARED_TARGET
}
PROPERTIES
COMPILE_FLAGS
"
-msse2 -DOPENMM_OPENCL_BUILDING_SHARED_LIBRARY"
)
SET_TARGET_PROPERTIES
(
${
SHARED_TARGET
}
PROPERTIES
LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
-msse2 -DOPENMM_OPENCL_BUILDING_SHARED_LIBRARY"
)
INSTALL_TARGETS
(
/lib/plugins RUNTIME_DIRECTORY /lib/plugins
${
SHARED_TARGET
}
)
platforms/opencl/tests/CMakeLists.txt
View file @
588a4c9d
...
...
@@ -25,6 +25,7 @@ FOREACH(TEST_PROG ${TEST_PROGS})
# Link with shared library
ADD_EXECUTABLE
(
${
TEST_ROOT
}
${
TEST_PROG
}
)
TARGET_LINK_LIBRARIES
(
${
TEST_ROOT
}
${
SHARED_TARGET
}
)
SET_TARGET_PROPERTIES
(
${
TEST_ROOT
}
PROPERTIES LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
)
IF
(
${
TEST_ROOT
}
STREQUAL
"TestOpenCLGBSAOBCForce2"
)
...
...
@@ -39,13 +40,13 @@ FOREACH(TEST_PROG ${TEST_PROGS})
SET
(
NONBOND_TEST
"TestOpenCLNonbondedForce2"
)
ADD_EXECUTABLE
(
${
NONBOND_TEST
}
${
TEST_PROG
}
)
SET_TARGET_PROPERTIES
(
${
NONBOND_TEST
}
PROPERTIES
COMPILE_FLAGS
"-msse2
${
NONBOND_DEFINE_STRING
}
"
)
SET_TARGET_PROPERTIES
(
${
NONBOND_TEST
}
PROPERTIES
LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
${
NONBOND_DEFINE_STRING
}
"
)
ADD_TEST
(
${
NONBOND_TEST
}
${
EXECUTABLE_OUTPUT_PATH
}
/
${
NONBOND_TEST
}
)
# OBC
SET
(
DEFINE_STRING
"
${
DEFINE_STRING
}
-DIMPLICIT_SOLVENT=1"
)
SET_TARGET_PROPERTIES
(
${
TEST_ROOT
}
PROPERTIES
COMPILE_FLAGS
"-msse2
${
DEFINE_STRING
}
"
)
SET_TARGET_PROPERTIES
(
${
TEST_ROOT
}
PROPERTIES
LINK_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
"
COMPILE_FLAGS
"
${
EXTRA_COMPILE_FLAGS
}
${
DEFINE_STRING
}
"
)
IF
(
INCLUDE_SERIALIZATION
)
TARGET_LINK_LIBRARIES
(
${
NONBOND_TEST
}
${
SHARED_TARGET
}
${
SHARED_OPENMM_SERIALIZATION
}
)
...
...
@@ -54,8 +55,6 @@ FOREACH(TEST_PROG ${TEST_PROGS})
TARGET_LINK_LIBRARIES
(
${
NONBOND_TEST
}
${
SHARED_TARGET
}
)
ENDIF
(
INCLUDE_SERIALIZATION
)
ELSE
(
${
TEST_ROOT
}
STREQUAL
"TestOpenCLGBSAOBCForce2"
)
SET_TARGET_PROPERTIES
(
${
TEST_ROOT
}
PROPERTIES COMPILE_FLAGS -msse2
)
ENDIF
(
${
TEST_ROOT
}
STREQUAL
"TestOpenCLGBSAOBCForce2"
)
ADD_TEST
(
${
TEST_ROOT
}
Single
${
EXECUTABLE_OUTPUT_PATH
}
/
${
TEST_ROOT
}
single
)
IF
(
OPENMM_BUILD_OPENCL_DOUBLE_PRECISION_TESTS
)
...
...
platforms/reference/include/ReferenceBrownianDynamics.h
View file @
588a4c9d
...
...
@@ -79,11 +79,12 @@ class ReferenceBrownianDynamics : public ReferenceDynamics {
@param velocities velocities
@param forces forces
@param masses atom masses
@param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */
void
update
(
const
OpenMM
::
System
&
system
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
);
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
tolerance
);
};
...
...
platforms/reference/include/ReferenceCCMAAlgorithm.h
View file @
588a4c9d
...
...
@@ -37,7 +37,6 @@ class OPENMM_EXPORT ReferenceCCMAAlgorithm : public ReferenceConstraintAlgorithm
protected:
int
_maximumNumberOfIterations
;
RealOpenMM
_tolerance
;
int
_numberOfConstraints
;
std
::
vector
<
std
::
pair
<
int
,
int
>
>
_atomIndices
;
...
...
@@ -53,7 +52,7 @@ protected:
private:
void
applyConstraints
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
bool
constrainingVelocities
);
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
bool
constrainingVelocities
,
RealOpenMM
tolerance
);
public:
class
AngleInfo
;
...
...
@@ -67,9 +66,8 @@ public:
* @param distance distances for constraints
* @param masses atom masses
* @param angles angle force field terms
* @param tolerance constraint tolerance
*/
ReferenceCCMAAlgorithm
(
int
numberOfAtoms
,
int
numberOfConstraints
,
const
std
::
vector
<
std
::
pair
<
int
,
int
>
>&
atomIndices
,
const
std
::
vector
<
RealOpenMM
>&
distance
,
std
::
vector
<
RealOpenMM
>&
masses
,
std
::
vector
<
AngleInfo
>&
angles
,
RealOpenMM
tolerance
);
ReferenceCCMAAlgorithm
(
int
numberOfAtoms
,
int
numberOfConstraints
,
const
std
::
vector
<
std
::
pair
<
int
,
int
>
>&
atomIndices
,
const
std
::
vector
<
RealOpenMM
>&
distance
,
std
::
vector
<
RealOpenMM
>&
masses
,
std
::
vector
<
AngleInfo
>&
angles
);
~
ReferenceCCMAAlgorithm
(
);
...
...
@@ -88,25 +86,16 @@ public:
*/
void
setMaximumNumberOfIterations
(
int
maximumNumberOfIterations
);
/**
* Get the constraint tolerance.
*/
RealOpenMM
getTolerance
(
void
)
const
;
/**
* Set the constraint tolerance.
*/
void
setTolerance
(
RealOpenMM
tolerance
);
/**
* Apply the constraint algorithm.
*
* @param atomCoordinates the original atom coordinates
* @param atomCoordinatesP the new atom coordinates
* @param inverseMasses 1/mass
* @param tolerance the constraint tolerance
*/
void
apply
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
);
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
);
/**
* Apply the constraint algorithm to velocities.
...
...
@@ -114,9 +103,10 @@ public:
* @param atomCoordinates the atom coordinates
* @param atomCoordinatesP the velocities to modify
* @param inverseMasses 1/mass
* @param tolerance the constraint tolerance
*/
void
applyToVelocities
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
);
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
);
};
class
ReferenceCCMAAlgorithm
::
AngleInfo
...
...
platforms/reference/include/ReferenceConstraintAlgorithm.h
View file @
588a4c9d
...
...
@@ -36,25 +36,16 @@ public:
virtual
~
ReferenceConstraintAlgorithm
()
{};
/**
* Get the constraint tolerance.
*/
virtual
RealOpenMM
getTolerance
()
const
=
0
;
/**
* Set the constraint tolerance.
*/
virtual
void
setTolerance
(
RealOpenMM
tolerance
)
=
0
;
/**
* Apply the constraint algorithm.
*
* @param atomCoordinates the original atom coordinates
* @param atomCoordinatesP the new atom coordinates
* @param inverseMasses 1/mass
* @param tolerance the constraint tolerance
*/
virtual
void
apply
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
)
=
0
;
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
)
=
0
;
/**
* Apply the constraint algorithm to velocities.
...
...
@@ -62,9 +53,10 @@ public:
* @param atomCoordinates the atom coordinates
* @param atomCoordinatesP the velocities to modify
* @param inverseMasses 1/mass
* @param tolerance the constraint tolerance
*/
virtual
void
applyToVelocities
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
)
=
0
;
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
)
=
0
;
};
// ---------------------------------------------------------------------------------------
...
...
platforms/reference/include/ReferenceConstraints.h
View file @
588a4c9d
...
...
@@ -33,8 +33,6 @@
* -------------------------------------------------------------------------- */
#include "ReferenceConstraintAlgorithm.h"
#include "ReferenceCCMAAlgorithm.h"
#include "ReferenceSETTLEAlgorithm.h"
#include "openmm/System.h"
namespace
OpenMM
{
...
...
@@ -46,17 +44,8 @@ namespace OpenMM {
*/
class
OPENMM_EXPORT
ReferenceConstraints
:
public
ReferenceConstraintAlgorithm
{
public:
ReferenceConstraints
(
const
System
&
system
,
RealOpenMM
tolerance
);
~
ReferenceConstraints
();
/**
* Get the constraint tolerance.
*/
RealOpenMM
getTolerance
()
const
;
/**
* Set the constraint tolerance.
*/
void
setTolerance
(
RealOpenMM
tolerance
);
ReferenceConstraints
(
const
System
&
system
);
virtual
~
ReferenceConstraints
();
/**
* Apply the constraint algorithm.
...
...
@@ -64,8 +53,9 @@ public:
* @param atomCoordinates the original atom coordinates
* @param atomCoordinatesP the new atom coordinates
* @param inverseMasses 1/mass
* @param tolerance the constraint tolerance
*/
void
apply
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
);
void
apply
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
);
/**
* Apply the constraint algorithm to velocities.
...
...
@@ -73,12 +63,11 @@ public:
* @param atomCoordinates the atom coordinates
* @param atomCoordinatesP the velocities to modify
* @param inverseMasses 1/mass
* @param tolerance the constraint tolerance
*/
void
applyToVelocities
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
);
private:
RealOpenMM
tolerance
;
ReferenceCCMAAlgorithm
*
ccma
;
ReferenceSETTLEAlgorithm
*
settle
;
void
applyToVelocities
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
);
ReferenceConstraintAlgorithm
*
ccma
;
ReferenceConstraintAlgorithm
*
settle
;
};
}
// namespace OpenMM
...
...
platforms/reference/include/ReferenceCustomDynamics.h
View file @
588a4c9d
...
...
@@ -92,12 +92,13 @@ public:
@param globals a map containing values of global variables
@param perDof the values of per-DOF variables
@param forcesAreValid whether the current forces are valid or need to be recomputed
@param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */
void
update
(
OpenMM
::
ContextImpl
&
context
,
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
std
::
map
<
std
::
string
,
RealOpenMM
>&
globals
,
std
::
vector
<
std
::
vector
<
OpenMM
::
RealVec
>
>&
perDof
,
bool
&
forcesAreValid
);
std
::
map
<
std
::
string
,
RealOpenMM
>&
globals
,
std
::
vector
<
std
::
vector
<
OpenMM
::
RealVec
>
>&
perDof
,
bool
&
forcesAreValid
,
RealOpenMM
tolerance
);
/**---------------------------------------------------------------------------------------
...
...
platforms/reference/include/ReferenceDynamics.h
View file @
588a4c9d
...
...
@@ -145,11 +145,12 @@ class OPENMM_EXPORT ReferenceDynamics {
@param velocities velocities
@param forces forces
@param masses atom masses
@param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */
virtual
void
update
(
const
OpenMM
::
System
&
system
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
);
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
tolerance
);
/**---------------------------------------------------------------------------------------
...
...
platforms/reference/include/ReferenceKernels.h
View file @
588a4c9d
...
...
@@ -191,7 +191,7 @@ private:
class
ReferenceApplyConstraintsKernel
:
public
ApplyConstraintsKernel
{
public:
ReferenceApplyConstraintsKernel
(
std
::
string
name
,
const
Platform
&
platform
,
ReferencePlatform
::
PlatformData
&
data
)
:
ApplyConstraintsKernel
(
name
,
platform
),
data
(
data
)
,
constraints
(
0
)
{
ApplyConstraintsKernel
(
name
,
platform
),
data
(
data
)
{
}
~
ReferenceApplyConstraintsKernel
();
/**
...
...
@@ -216,12 +216,8 @@ public:
void
applyToVelocities
(
ContextImpl
&
context
,
double
tol
);
private:
ReferencePlatform
::
PlatformData
&
data
;
ReferenceConstraintAlgorithm
*
constraints
;
std
::
vector
<
RealOpenMM
>
masses
;
std
::
vector
<
RealOpenMM
>
inverseMasses
;
std
::
vector
<
std
::
pair
<
int
,
int
>
>
constraintIndices
;
std
::
vector
<
RealOpenMM
>
constraintDistances
;
int
numConstraints
;
};
/**
...
...
@@ -871,7 +867,7 @@ private:
class
ReferenceIntegrateVerletStepKernel
:
public
IntegrateVerletStepKernel
{
public:
ReferenceIntegrateVerletStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
ReferencePlatform
::
PlatformData
&
data
)
:
IntegrateVerletStepKernel
(
name
,
platform
),
data
(
data
),
dynamics
(
0
)
,
constraints
(
0
)
{
data
(
data
),
dynamics
(
0
)
{
}
~
ReferenceIntegrateVerletStepKernel
();
/**
...
...
@@ -898,9 +894,7 @@ public:
private:
ReferencePlatform
::
PlatformData
&
data
;
ReferenceVerletDynamics
*
dynamics
;
ReferenceConstraintAlgorithm
*
constraints
;
std
::
vector
<
RealOpenMM
>
masses
;
int
numConstraints
;
double
prevStepSize
;
};
...
...
@@ -910,7 +904,7 @@ private:
class
ReferenceIntegrateLangevinStepKernel
:
public
IntegrateLangevinStepKernel
{
public:
ReferenceIntegrateLangevinStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
ReferencePlatform
::
PlatformData
&
data
)
:
IntegrateLangevinStepKernel
(
name
,
platform
),
data
(
data
),
dynamics
(
0
)
,
constraints
(
0
)
{
data
(
data
),
dynamics
(
0
)
{
}
~
ReferenceIntegrateLangevinStepKernel
();
/**
...
...
@@ -937,9 +931,7 @@ public:
private:
ReferencePlatform
::
PlatformData
&
data
;
ReferenceStochasticDynamics
*
dynamics
;
ReferenceConstraintAlgorithm
*
constraints
;
std
::
vector
<
RealOpenMM
>
masses
;
int
numConstraints
;
double
prevTemp
,
prevFriction
,
prevStepSize
;
};
...
...
@@ -949,7 +941,7 @@ private:
class
ReferenceIntegrateBrownianStepKernel
:
public
IntegrateBrownianStepKernel
{
public:
ReferenceIntegrateBrownianStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
ReferencePlatform
::
PlatformData
&
data
)
:
IntegrateBrownianStepKernel
(
name
,
platform
),
data
(
data
),
dynamics
(
0
)
,
constraints
(
0
)
{
data
(
data
),
dynamics
(
0
)
{
}
~
ReferenceIntegrateBrownianStepKernel
();
/**
...
...
@@ -976,9 +968,7 @@ public:
private:
ReferencePlatform
::
PlatformData
&
data
;
ReferenceBrownianDynamics
*
dynamics
;
ReferenceConstraintAlgorithm
*
constraints
;
std
::
vector
<
RealOpenMM
>
masses
;
int
numConstraints
;
double
prevTemp
,
prevFriction
,
prevStepSize
;
};
...
...
@@ -988,7 +978,7 @@ private:
class
ReferenceIntegrateVariableLangevinStepKernel
:
public
IntegrateVariableLangevinStepKernel
{
public:
ReferenceIntegrateVariableLangevinStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
ReferencePlatform
::
PlatformData
&
data
)
:
IntegrateVariableLangevinStepKernel
(
name
,
platform
),
data
(
data
),
dynamics
(
0
)
,
constraints
(
0
)
{
data
(
data
),
dynamics
(
0
)
{
}
~
ReferenceIntegrateVariableLangevinStepKernel
();
/**
...
...
@@ -1017,9 +1007,7 @@ public:
private:
ReferencePlatform
::
PlatformData
&
data
;
ReferenceVariableStochasticDynamics
*
dynamics
;
ReferenceConstraintAlgorithm
*
constraints
;
std
::
vector
<
RealOpenMM
>
masses
;
int
numConstraints
;
double
prevTemp
,
prevFriction
,
prevErrorTol
;
};
...
...
@@ -1029,7 +1017,7 @@ private:
class
ReferenceIntegrateVariableVerletStepKernel
:
public
IntegrateVariableVerletStepKernel
{
public:
ReferenceIntegrateVariableVerletStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
ReferencePlatform
::
PlatformData
&
data
)
:
IntegrateVariableVerletStepKernel
(
name
,
platform
),
data
(
data
),
dynamics
(
0
)
,
constraints
(
0
)
{
data
(
data
),
dynamics
(
0
)
{
}
~
ReferenceIntegrateVariableVerletStepKernel
();
/**
...
...
@@ -1058,9 +1046,7 @@ public:
private:
ReferencePlatform
::
PlatformData
&
data
;
ReferenceVariableVerletDynamics
*
dynamics
;
ReferenceConstraintAlgorithm
*
constraints
;
std
::
vector
<
RealOpenMM
>
masses
;
int
numConstraints
;
double
prevErrorTol
;
};
...
...
@@ -1070,7 +1056,7 @@ private:
class
ReferenceIntegrateCustomStepKernel
:
public
IntegrateCustomStepKernel
{
public:
ReferenceIntegrateCustomStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
ReferencePlatform
::
PlatformData
&
data
)
:
IntegrateCustomStepKernel
(
name
,
platform
),
data
(
data
),
dynamics
(
0
)
,
constraints
(
0
)
{
data
(
data
),
dynamics
(
0
)
{
}
~
ReferenceIntegrateCustomStepKernel
();
/**
...
...
@@ -1135,10 +1121,8 @@ public:
private:
ReferencePlatform
::
PlatformData
&
data
;
ReferenceCustomDynamics
*
dynamics
;
ReferenceConstraintAlgorithm
*
constraints
;
std
::
vector
<
RealOpenMM
>
masses
,
globalValues
;
std
::
vector
<
std
::
vector
<
OpenMM
::
RealVec
>
>
perDofValues
;
int
numConstraints
;
};
/**
...
...
platforms/reference/include/ReferencePlatform.h
View file @
588a4c9d
...
...
@@ -33,6 +33,7 @@
* -------------------------------------------------------------------------- */
#include "openmm/Platform.h"
#include "openmm/System.h"
#include "openmm/internal/windowsExport.h"
namespace
OpenMM
{
...
...
@@ -57,7 +58,7 @@ public:
class
ReferencePlatform
::
PlatformData
{
public:
PlatformData
(
int
numParticles
);
PlatformData
(
const
System
&
system
);
~
PlatformData
();
int
numParticles
,
stepCount
;
double
time
;
...
...
@@ -65,6 +66,7 @@ public:
void
*
velocities
;
void
*
forces
;
void
*
periodicBoxSize
;
void
*
constraints
;
};
}
// namespace OpenMM
...
...
platforms/reference/include/ReferenceSETTLEAlgorithm.h
View file @
588a4c9d
...
...
@@ -44,25 +44,32 @@ namespace OpenMM {
class
OPENMM_EXPORT
ReferenceSETTLEAlgorithm
:
public
ReferenceConstraintAlgorithm
{
public:
ReferenceSETTLEAlgorithm
(
const
std
::
vector
<
int
>&
atom1
,
const
std
::
vector
<
int
>&
atom2
,
const
std
::
vector
<
int
>&
atom3
,
const
std
::
vector
<
RealOpenMM
>&
distance1
,
const
std
::
vector
<
RealOpenMM
>&
distance2
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
tolerance
);
const
std
::
vector
<
RealOpenMM
>&
distance1
,
const
std
::
vector
<
RealOpenMM
>&
distance2
,
std
::
vector
<
RealOpenMM
>&
masses
);
/**
* Get the
constraint tolerance
.
* Get the
number of clusters
.
*/
RealOpenMM
getTolerance
()
const
;
int
getNumClusters
()
const
;
/**
* Set the constraint tolerance.
* Get the parameters describing one cluster.
*
* @param index the index of the cluster to get
* @param atom1 the index of the first atom in the cluster
* @param atom2 the index of the second atom in the cluster
* @param atom3 the index of the third atom in the cluster
* @param distance1 the distance between atoms 1 and 2
* @param distance2 the distance between atoms 2 and 3
*/
void
setTolerance
(
RealOpenMM
tolerance
);
void
getClusterParameters
(
int
index
,
int
&
atom1
,
int
&
atom2
,
int
&
atom3
,
RealOpenMM
&
distance1
,
RealOpenMM
&
distance2
)
const
;
/**
* Apply the constraint algorithm.
*
* @param atomCoordinates the original atom coordinates
* @param atomCoordinatesP the new atom coordinates
* @param inverseMasses 1/mass
* @param tolerance the constraint tolerance
*/
void
apply
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
);
void
apply
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinatesP
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
);
/**
* Apply the constraint algorithm to velocities.
...
...
@@ -70,10 +77,10 @@ public:
* @param atomCoordinates the atom coordinates
* @param atomCoordinatesP the velocities to modify
* @param inverseMasses 1/mass
* @param tolerance the constraint tolerance
*/
void
applyToVelocities
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
);
void
applyToVelocities
(
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
RealOpenMM
>&
inverseMasses
,
RealOpenMM
tolerance
);
private:
RealOpenMM
tolerance
;
std
::
vector
<
int
>
atom1
;
std
::
vector
<
int
>
atom2
;
std
::
vector
<
int
>
atom3
;
...
...
platforms/reference/include/ReferenceStochasticDynamics.h
View file @
588a4c9d
...
...
@@ -79,11 +79,12 @@ class ReferenceStochasticDynamics : public ReferenceDynamics {
@param velocities velocities
@param forces forces
@param masses atom masses
@param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */
void
update
(
const
OpenMM
::
System
&
system
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
);
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
tolerance
);
/**---------------------------------------------------------------------------------------
...
...
platforms/reference/include/ReferenceVariableStochasticDynamics.h
View file @
588a4c9d
...
...
@@ -98,11 +98,12 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
@param forces forces
@param masses atom masses
@param maxStepSize maximum time step
@param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */
void
update
(
const
OpenMM
::
System
&
system
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
maxStepSize
);
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
maxStepSize
,
RealOpenMM
tolerance
);
/**---------------------------------------------------------------------------------------
...
...
platforms/reference/include/ReferenceVariableVerletDynamics.h
View file @
588a4c9d
...
...
@@ -86,11 +86,12 @@ class ReferenceVariableVerletDynamics : public ReferenceDynamics {
@param forces forces
@param masses atom masses
@param maxStepSize maximum time step
@param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */
void
update
(
const
OpenMM
::
System
&
system
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
maxStepSize
);
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
maxStepSize
,
RealOpenMM
tolerance
);
};
...
...
platforms/reference/include/ReferenceVerletDynamics.h
View file @
588a4c9d
...
...
@@ -68,11 +68,12 @@ class ReferenceVerletDynamics : public ReferenceDynamics {
@param velocities velocities
@param forces forces
@param masses atom masses
@param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */
void
update
(
const
OpenMM
::
System
&
system
,
std
::
vector
<
OpenMM
::
RealVec
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
);
std
::
vector
<
OpenMM
::
RealVec
>&
velocities
,
std
::
vector
<
OpenMM
::
RealVec
>&
forces
,
std
::
vector
<
RealOpenMM
>&
masses
,
RealOpenMM
tolerance
);
};
...
...
platforms/reference/src/ReferenceKernels.cpp
View file @
588a4c9d
...
...
@@ -133,11 +133,16 @@ static RealVec& extractBoxSize(ContextImpl& context) {
return
*
(
RealVec
*
)
data
->
periodicBoxSize
;
}
static
ReferenceConstraints
&
extractConstraints
(
ContextImpl
&
context
)
{
ReferencePlatform
::
PlatformData
*
data
=
reinterpret_cast
<
ReferencePlatform
::
PlatformData
*>
(
context
.
getPlatformData
());
return
*
(
ReferenceConstraints
*
)
data
->
constraints
;
}
/**
* Compute the kinetic energy of the system, possibly shifting the velocities in time to account
* for a leapfrog integrator.
*/
static
double
computeShiftedKineticEnergy
(
ContextImpl
&
context
,
vector
<
double
>&
masses
,
double
timeShift
,
ReferenceConstraintAlgorithm
*
constraints
)
{
static
double
computeShiftedKineticEnergy
(
ContextImpl
&
context
,
vector
<
double
>&
masses
,
double
timeShift
)
{
vector
<
RealVec
>&
posData
=
extractPositions
(
context
);
vector
<
RealVec
>&
velData
=
extractVelocities
(
context
);
vector
<
RealVec
>&
forceData
=
extractForces
(
context
);
...
...
@@ -155,13 +160,10 @@ static double computeShiftedKineticEnergy(ContextImpl& context, vector<double>&
// Apply constraints to them.
if
(
constraints
!=
NULL
)
{
vector
<
double
>
inverseMasses
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
inverseMasses
[
i
]
=
(
masses
[
i
]
==
0
?
0
:
1
/
masses
[
i
]);
constraints
->
setTolerance
(
1e-4
);
constraints
->
applyToVelocities
(
posData
,
shiftedVel
,
inverseMasses
);
}
vector
<
double
>
inverseMasses
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
i
++
)
inverseMasses
[
i
]
=
(
masses
[
i
]
==
0
?
0
:
1
/
masses
[
i
]);
extractConstraints
(
context
).
applyToVelocities
(
posData
,
shiftedVel
,
inverseMasses
,
1e-4
);
// Compute the kinetic energy.
...
...
@@ -302,39 +304,21 @@ void ReferenceApplyConstraintsKernel::initialize(const System& system) {
masses
[
i
]
=
static_cast
<
RealOpenMM
>
(
system
.
getParticleMass
(
i
));
inverseMasses
[
i
]
=
1.0
/
masses
[
i
];
}
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
numConstraints
=
constraintIndices
.
size
();
}
ReferenceApplyConstraintsKernel
::~
ReferenceApplyConstraintsKernel
()
{
if
(
constraints
)
delete
constraints
;
}
void
ReferenceApplyConstraintsKernel
::
apply
(
ContextImpl
&
context
,
double
tol
)
{
if
(
constraints
==
NULL
)
constraints
=
new
ReferenceConstraints
(
context
.
getSystem
(),
(
RealOpenMM
)
tol
);
vector
<
RealVec
>&
positions
=
extractPositions
(
context
);
constraints
->
setTolerance
(
tol
);
constraints
->
apply
(
positions
,
positions
,
inverseMasses
);
extractConstraints
(
context
).
apply
(
positions
,
positions
,
inverseMasses
,
tol
);
ReferenceVirtualSites
::
computePositions
(
context
.
getSystem
(),
positions
);
}
void
ReferenceApplyConstraintsKernel
::
applyToVelocities
(
ContextImpl
&
context
,
double
tol
)
{
if
(
constraints
==
NULL
)
constraints
=
new
ReferenceConstraints
(
context
.
getSystem
(),
(
RealOpenMM
)
tol
);
vector
<
RealVec
>&
positions
=
extractPositions
(
context
);
vector
<
RealVec
>&
velocities
=
extractVelocities
(
context
);
constraints
->
setTolerance
(
tol
);
constraints
->
applyToVelocities
(
positions
,
velocities
,
inverseMasses
);
extractConstraints
(
context
).
applyToVelocities
(
positions
,
velocities
,
inverseMasses
,
tol
);
}
void
ReferenceVirtualSitesKernel
::
initialize
(
const
System
&
system
)
{
...
...
@@ -1686,8 +1670,6 @@ void ReferenceCalcCustomCompoundBondForceKernel::copyParametersToContext(Context
ReferenceIntegrateVerletStepKernel
::~
ReferenceIntegrateVerletStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
if
(
constraints
)
delete
constraints
;
}
void
ReferenceIntegrateVerletStepKernel
::
initialize
(
const
System
&
system
,
const
VerletIntegrator
&
integrator
)
{
...
...
@@ -1695,19 +1677,6 @@ void ReferenceIntegrateVerletStepKernel::initialize(const System& system, const
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
static_cast
<
RealOpenMM
>
(
system
.
getParticleMass
(
i
));
vector
<
pair
<
int
,
int
>
>
constraintIndices
;
vector
<
RealOpenMM
>
constraintDistances
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
numConstraints
=
constraintIndices
.
size
();
constraints
=
new
ReferenceConstraints
(
system
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
}
void
ReferenceIntegrateVerletStepKernel
::
execute
(
ContextImpl
&
context
,
const
VerletIntegrator
&
integrator
)
{
...
...
@@ -1721,24 +1690,21 @@ void ReferenceIntegrateVerletStepKernel::execute(ContextImpl& context, const Ver
if
(
dynamics
)
delete
dynamics
;
dynamics
=
new
ReferenceVerletDynamics
(
context
.
getSystem
().
getNumParticles
(),
static_cast
<
RealOpenMM
>
(
stepSize
)
);
dynamics
->
setReferenceConstraintAlgorithm
(
c
onstraints
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractC
onstraints
(
context
)
);
prevStepSize
=
stepSize
;
}
constraints
->
setTolerance
(
integrator
.
getConstraintTolerance
());
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
);
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
,
integrator
.
getConstraintTolerance
());
data
.
time
+=
stepSize
;
data
.
stepCount
++
;
}
double
ReferenceIntegrateVerletStepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
VerletIntegrator
&
integrator
)
{
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
()
,
constraints
);
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
());
}
ReferenceIntegrateLangevinStepKernel
::~
ReferenceIntegrateLangevinStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
if
(
constraints
)
delete
constraints
;
}
void
ReferenceIntegrateLangevinStepKernel
::
initialize
(
const
System
&
system
,
const
LangevinIntegrator
&
integrator
)
{
...
...
@@ -1746,20 +1712,7 @@ void ReferenceIntegrateLangevinStepKernel::initialize(const System& system, cons
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
static_cast
<
RealOpenMM
>
(
system
.
getParticleMass
(
i
));
vector
<
pair
<
int
,
int
>
>
constraintIndices
;
vector
<
RealOpenMM
>
constraintDistances
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
numConstraints
=
constraintIndices
.
size
();
SimTKOpenMMUtilities
::
setRandomNumberSeed
((
unsigned
int
)
integrator
.
getRandomNumberSeed
());
constraints
=
new
ReferenceConstraints
(
system
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
}
void
ReferenceIntegrateLangevinStepKernel
::
execute
(
ContextImpl
&
context
,
const
LangevinIntegrator
&
integrator
)
{
...
...
@@ -1780,26 +1733,23 @@ void ReferenceIntegrateLangevinStepKernel::execute(ContextImpl& context, const L
static_cast
<
RealOpenMM
>
(
stepSize
),
static_cast
<
RealOpenMM
>
(
tau
),
static_cast
<
RealOpenMM
>
(
temperature
)
);
dynamics
->
setReferenceConstraintAlgorithm
(
c
onstraints
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractC
onstraints
(
context
)
);
prevTemp
=
temperature
;
prevFriction
=
friction
;
prevStepSize
=
stepSize
;
}
constraints
->
setTolerance
(
integrator
.
getConstraintTolerance
());
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
);
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
,
integrator
.
getConstraintTolerance
());
data
.
time
+=
stepSize
;
data
.
stepCount
++
;
}
double
ReferenceIntegrateLangevinStepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
LangevinIntegrator
&
integrator
)
{
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
()
,
constraints
);
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
());
}
ReferenceIntegrateBrownianStepKernel
::~
ReferenceIntegrateBrownianStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
if
(
constraints
)
delete
constraints
;
}
void
ReferenceIntegrateBrownianStepKernel
::
initialize
(
const
System
&
system
,
const
BrownianIntegrator
&
integrator
)
{
...
...
@@ -1807,20 +1757,7 @@ void ReferenceIntegrateBrownianStepKernel::initialize(const System& system, cons
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
static_cast
<
RealOpenMM
>
(
system
.
getParticleMass
(
i
));
vector
<
pair
<
int
,
int
>
>
constraintIndices
;
vector
<
RealOpenMM
>
constraintDistances
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
numConstraints
=
constraintIndices
.
size
();
SimTKOpenMMUtilities
::
setRandomNumberSeed
((
unsigned
int
)
integrator
.
getRandomNumberSeed
());
constraints
=
new
ReferenceConstraints
(
system
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
}
void
ReferenceIntegrateBrownianStepKernel
::
execute
(
ContextImpl
&
context
,
const
BrownianIntegrator
&
integrator
)
{
...
...
@@ -1840,26 +1777,23 @@ void ReferenceIntegrateBrownianStepKernel::execute(ContextImpl& context, const B
static_cast
<
RealOpenMM
>
(
stepSize
),
static_cast
<
RealOpenMM
>
(
friction
),
static_cast
<
RealOpenMM
>
(
temperature
)
);
dynamics
->
setReferenceConstraintAlgorithm
(
c
onstraints
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractC
onstraints
(
context
)
);
prevTemp
=
temperature
;
prevFriction
=
friction
;
prevStepSize
=
stepSize
;
}
constraints
->
setTolerance
(
integrator
.
getConstraintTolerance
());
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
);
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
,
integrator
.
getConstraintTolerance
());
data
.
time
+=
stepSize
;
data
.
stepCount
++
;
}
double
ReferenceIntegrateBrownianStepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
BrownianIntegrator
&
integrator
)
{
return
computeShiftedKineticEnergy
(
context
,
masses
,
0
,
constraints
);
return
computeShiftedKineticEnergy
(
context
,
masses
,
0
);
}
ReferenceIntegrateVariableLangevinStepKernel
::~
ReferenceIntegrateVariableLangevinStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
if
(
constraints
)
delete
constraints
;
}
void
ReferenceIntegrateVariableLangevinStepKernel
::
initialize
(
const
System
&
system
,
const
VariableLangevinIntegrator
&
integrator
)
{
...
...
@@ -1867,20 +1801,7 @@ void ReferenceIntegrateVariableLangevinStepKernel::initialize(const System& syst
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
static_cast
<
RealOpenMM
>
(
system
.
getParticleMass
(
i
));
vector
<
pair
<
int
,
int
>
>
constraintIndices
;
vector
<
RealOpenMM
>
constraintDistances
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
numConstraints
=
constraintIndices
.
size
();
SimTKOpenMMUtilities
::
setRandomNumberSeed
((
unsigned
int
)
integrator
.
getRandomNumberSeed
());
constraints
=
new
ReferenceConstraints
(
system
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
}
double
ReferenceIntegrateVariableLangevinStepKernel
::
execute
(
ContextImpl
&
context
,
const
VariableLangevinIntegrator
&
integrator
,
double
maxTime
)
{
...
...
@@ -1897,14 +1818,13 @@ double ReferenceIntegrateVariableLangevinStepKernel::execute(ContextImpl& contex
delete
dynamics
;
RealOpenMM
tau
=
static_cast
<
RealOpenMM
>
(
friction
==
0.0
?
0.0
:
1.0
/
friction
);
dynamics
=
new
ReferenceVariableStochasticDynamics
(
context
.
getSystem
().
getNumParticles
(),
(
RealOpenMM
)
tau
,
(
RealOpenMM
)
temperature
,
(
RealOpenMM
)
errorTol
);
dynamics
->
setReferenceConstraintAlgorithm
(
c
onstraints
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractC
onstraints
(
context
)
);
prevTemp
=
temperature
;
prevFriction
=
friction
;
prevErrorTol
=
errorTol
;
}
constraints
->
setTolerance
(
integrator
.
getConstraintTolerance
());
RealOpenMM
maxStepSize
=
(
RealOpenMM
)
(
maxTime
-
data
.
time
);
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
,
maxStepSize
);
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
,
maxStepSize
,
integrator
.
getConstraintTolerance
()
);
data
.
time
+=
dynamics
->
getDeltaT
();
if
(
dynamics
->
getDeltaT
()
==
maxStepSize
)
data
.
time
=
maxTime
;
// Avoid round-off error
...
...
@@ -1913,14 +1833,12 @@ double ReferenceIntegrateVariableLangevinStepKernel::execute(ContextImpl& contex
}
double
ReferenceIntegrateVariableLangevinStepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
VariableLangevinIntegrator
&
integrator
)
{
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
()
,
constraints
);
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
());
}
ReferenceIntegrateVariableVerletStepKernel
::~
ReferenceIntegrateVariableVerletStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
if
(
constraints
)
delete
constraints
;
}
void
ReferenceIntegrateVariableVerletStepKernel
::
initialize
(
const
System
&
system
,
const
VariableVerletIntegrator
&
integrator
)
{
...
...
@@ -1928,19 +1846,6 @@ void ReferenceIntegrateVariableVerletStepKernel::initialize(const System& system
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
static_cast
<
RealOpenMM
>
(
system
.
getParticleMass
(
i
));
vector
<
pair
<
int
,
int
>
>
constraintIndices
;
vector
<
RealOpenMM
>
constraintDistances
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
numConstraints
=
constraintIndices
.
size
();
constraints
=
new
ReferenceConstraints
(
system
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
}
double
ReferenceIntegrateVariableVerletStepKernel
::
execute
(
ContextImpl
&
context
,
const
VariableVerletIntegrator
&
integrator
,
double
maxTime
)
{
...
...
@@ -1954,12 +1859,11 @@ double ReferenceIntegrateVariableVerletStepKernel::execute(ContextImpl& context,
if
(
dynamics
)
delete
dynamics
;
dynamics
=
new
ReferenceVariableVerletDynamics
(
context
.
getSystem
().
getNumParticles
(),
(
RealOpenMM
)
errorTol
);
dynamics
->
setReferenceConstraintAlgorithm
(
c
onstraints
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractC
onstraints
(
context
)
);
prevErrorTol
=
errorTol
;
}
constraints
->
setTolerance
(
integrator
.
getConstraintTolerance
());
RealOpenMM
maxStepSize
=
(
RealOpenMM
)
(
maxTime
-
data
.
time
);
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
,
maxStepSize
);
dynamics
->
update
(
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
,
maxStepSize
,
integrator
.
getConstraintTolerance
()
);
data
.
time
+=
dynamics
->
getDeltaT
();
if
(
dynamics
->
getDeltaT
()
==
maxStepSize
)
data
.
time
=
maxTime
;
// Avoid round-off error
...
...
@@ -1968,14 +1872,12 @@ double ReferenceIntegrateVariableVerletStepKernel::execute(ContextImpl& context,
}
double
ReferenceIntegrateVariableVerletStepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
VariableVerletIntegrator
&
integrator
)
{
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
()
,
constraints
);
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
());
}
ReferenceIntegrateCustomStepKernel
::~
ReferenceIntegrateCustomStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
if
(
constraints
)
delete
constraints
;
}
void
ReferenceIntegrateCustomStepKernel
::
initialize
(
const
System
&
system
,
const
CustomIntegrator
&
integrator
)
{
...
...
@@ -1983,18 +1885,6 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
static_cast
<
RealOpenMM
>
(
system
.
getParticleMass
(
i
));
vector
<
pair
<
int
,
int
>
>
constraintIndices
;
vector
<
RealOpenMM
>
constraintDistances
;
for
(
int
i
=
0
;
i
<
system
.
getNumConstraints
();
++
i
)
{
int
particle1
,
particle2
;
double
distance
;
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
if
(
system
.
getParticleMass
(
particle1
)
!=
0
||
system
.
getParticleMass
(
particle2
)
!=
0
)
{
constraintIndices
.
push_back
(
make_pair
(
particle1
,
particle2
));
constraintDistances
.
push_back
(
distance
);
}
}
numConstraints
=
constraintIndices
.
size
();
perDofValues
.
resize
(
integrator
.
getNumPerDofVariables
());
for
(
int
i
=
0
;
i
<
(
int
)
perDofValues
.
size
();
i
++
)
perDofValues
[
i
].
resize
(
numParticles
);
...
...
@@ -2003,8 +1893,6 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const
dynamics
=
new
ReferenceCustomDynamics
(
system
.
getNumParticles
(),
integrator
);
SimTKOpenMMUtilities
::
setRandomNumberSeed
((
unsigned
int
)
integrator
.
getRandomNumberSeed
());
constraints
=
new
ReferenceConstraints
(
system
,
(
RealOpenMM
)
integrator
.
getConstraintTolerance
());
dynamics
->
setReferenceConstraintAlgorithm
(
constraints
);
}
void
ReferenceIntegrateCustomStepKernel
::
execute
(
ContextImpl
&
context
,
CustomIntegrator
&
integrator
,
bool
&
forcesAreValid
)
{
...
...
@@ -2021,8 +1909,8 @@ void ReferenceIntegrateCustomStepKernel::execute(ContextImpl& context, CustomInt
// Execute the step.
constraint
s
->
set
Tol
er
a
nce
(
integrator
.
ge
tConstraint
Tolerance
(
));
dynamics
->
update
(
context
,
context
.
getSystem
().
getNumParticles
(),
posData
,
velData
,
forceData
,
masses
,
globals
,
perDofValues
,
forcesAreValid
);
dynamic
s
->
set
Ref
er
e
nce
ConstraintAlgorithm
(
&
extrac
tConstraint
s
(
context
));
dynamics
->
update
(
context
,
context
.
getSystem
().
getNumParticles
(),
posData
,
velData
,
forceData
,
masses
,
globals
,
perDofValues
,
forcesAreValid
,
integrator
.
getConstraintTolerance
()
);
// Record changed global variables.
...
...
platforms/reference/src/ReferencePlatform.cpp
View file @
588a4c9d
...
...
@@ -30,6 +30,7 @@
* -------------------------------------------------------------------------- */
#include "ReferencePlatform.h"
#include "ReferenceConstraints.h"
#include "ReferenceKernelFactory.h"
#include "ReferenceKernels.h"
#include "openmm/internal/ContextImpl.h"
...
...
@@ -82,7 +83,7 @@ bool ReferencePlatform::supportsDoublePrecision() const {
}
void
ReferencePlatform
::
contextCreated
(
ContextImpl
&
context
,
const
map
<
string
,
string
>&
properties
)
const
{
context
.
setPlatformData
(
new
PlatformData
(
context
.
getSystem
()
.
getNumParticles
()
));
context
.
setPlatformData
(
new
PlatformData
(
context
.
getSystem
()));
}
void
ReferencePlatform
::
contextDestroyed
(
ContextImpl
&
context
)
const
{
...
...
@@ -90,11 +91,12 @@ void ReferencePlatform::contextDestroyed(ContextImpl& context) const {
delete
data
;
}
ReferencePlatform
::
PlatformData
::
PlatformData
(
int
numParticles
)
:
time
(
0.0
),
stepCount
(
0
),
numParticles
(
n
umParticles
)
{
ReferencePlatform
::
PlatformData
::
PlatformData
(
const
System
&
system
)
:
time
(
0.0
),
stepCount
(
0
),
numParticles
(
system
.
getN
umParticles
()
)
{
positions
=
new
vector
<
RealVec
>
(
numParticles
);
velocities
=
new
vector
<
RealVec
>
(
numParticles
);
forces
=
new
vector
<
RealVec
>
(
numParticles
);
periodicBoxSize
=
new
RealVec
();
constraints
=
new
ReferenceConstraints
(
system
);
}
ReferencePlatform
::
PlatformData
::~
PlatformData
()
{
...
...
@@ -102,4 +104,5 @@ ReferencePlatform::PlatformData::~PlatformData() {
delete
(
vector
<
RealVec
>*
)
velocities
;
delete
(
vector
<
RealVec
>*
)
forces
;
delete
(
RealVec
*
)
periodicBoxSize
;
delete
(
ReferenceConstraints
*
)
constraints
;
}
Prev
1
2
3
4
Next
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