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
c7441b96
Unverified
Commit
c7441b96
authored
Oct 24, 2019
by
peastman
Committed by
GitHub
Oct 24, 2019
Browse files
Merge pull request #2436 from peastman/baoab
Create BAOABLangevinIntegrator
parents
8ac16493
6333db3a
Changes
43
Show whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1057 additions
and
4 deletions
+1057
-4
platforms/cuda/src/CudaKernelFactory.cpp
platforms/cuda/src/CudaKernelFactory.cpp
+3
-1
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+89
-0
platforms/cuda/src/CudaPlatform.cpp
platforms/cuda/src/CudaPlatform.cpp
+2
-1
platforms/cuda/src/kernels/baoab.cu
platforms/cuda/src/kernels/baoab.cu
+129
-0
platforms/cuda/tests/TestCudaBAOABLangevinIntegrator.cpp
platforms/cuda/tests/TestCudaBAOABLangevinIntegrator.cpp
+36
-0
platforms/opencl/include/OpenCLKernels.h
platforms/opencl/include/OpenCLKernels.h
+41
-0
platforms/opencl/src/OpenCLKernelFactory.cpp
platforms/opencl/src/OpenCLKernelFactory.cpp
+2
-0
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+105
-0
platforms/opencl/src/OpenCLPlatform.cpp
platforms/opencl/src/OpenCLPlatform.cpp
+1
-0
platforms/opencl/src/kernels/baoab.cl
platforms/opencl/src/kernels/baoab.cl
+120
-0
platforms/opencl/tests/TestOpenCLBAOABLangevinIntegrator.cpp
platforms/opencl/tests/TestOpenCLBAOABLangevinIntegrator.cpp
+36
-0
platforms/reference/include/ReferenceBAOABDynamics.h
platforms/reference/include/ReferenceBAOABDynamics.h
+141
-0
platforms/reference/include/ReferenceKernels.h
platforms/reference/include/ReferenceKernels.h
+43
-1
platforms/reference/src/ReferenceKernelFactory.cpp
platforms/reference/src/ReferenceKernelFactory.cpp
+2
-0
platforms/reference/src/ReferenceKernels.cpp
platforms/reference/src/ReferenceKernels.cpp
+45
-1
platforms/reference/src/ReferencePlatform.cpp
platforms/reference/src/ReferencePlatform.cpp
+1
-0
platforms/reference/src/SimTKReference/ReferenceBAOABDynamics.cpp
...s/reference/src/SimTKReference/ReferenceBAOABDynamics.cpp
+148
-0
platforms/reference/tests/TestReferenceBAOABLangevinIntegrator.cpp
.../reference/tests/TestReferenceBAOABLangevinIntegrator.cpp
+36
-0
serialization/include/openmm/serialization/BAOABLangevinIntegratorProxy.h
...clude/openmm/serialization/BAOABLangevinIntegratorProxy.h
+17
-0
serialization/src/BAOABLangevinIntegratorProxy.cpp
serialization/src/BAOABLangevinIntegratorProxy.cpp
+60
-0
No files found.
platforms/cuda/src/CudaKernelFactory.cpp
View file @
c7441b96
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,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-201
6
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -120,6 +120,8 @@ KernelImpl* CudaKernelFactory::createKernelImpl(std::string name, const Platform
...
@@ -120,6 +120,8 @@ KernelImpl* CudaKernelFactory::createKernelImpl(std::string name, const Platform
return
new
CudaIntegrateVerletStepKernel
(
name
,
platform
,
cu
);
return
new
CudaIntegrateVerletStepKernel
(
name
,
platform
,
cu
);
if
(
name
==
IntegrateLangevinStepKernel
::
Name
())
if
(
name
==
IntegrateLangevinStepKernel
::
Name
())
return
new
CudaIntegrateLangevinStepKernel
(
name
,
platform
,
cu
);
return
new
CudaIntegrateLangevinStepKernel
(
name
,
platform
,
cu
);
if
(
name
==
IntegrateBAOABStepKernel
::
Name
())
return
new
CudaIntegrateBAOABStepKernel
(
name
,
platform
,
cu
);
if
(
name
==
IntegrateBrownianStepKernel
::
Name
())
if
(
name
==
IntegrateBrownianStepKernel
::
Name
())
return
new
CudaIntegrateBrownianStepKernel
(
name
,
platform
,
cu
);
return
new
CudaIntegrateBrownianStepKernel
(
name
,
platform
,
cu
);
if
(
name
==
IntegrateVariableVerletStepKernel
::
Name
())
if
(
name
==
IntegrateVariableVerletStepKernel
::
Name
())
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
c7441b96
...
@@ -7143,6 +7143,95 @@ double CudaIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& contex
...
@@ -7143,6 +7143,95 @@ double CudaIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& contex
return cu.getIntegrationUtilities().computeKineticEnergy(0.5*integrator.getStepSize());
return cu.getIntegrationUtilities().computeKineticEnergy(0.5*integrator.getStepSize());
}
}
void CudaIntegrateBAOABStepKernel::initialize(const System& system, const BAOABLangevinIntegrator& integrator) {
cu.getPlatformData().initializeContexts(system);
cu.setAsCurrent();
cu.getIntegrationUtilities().initRandomNumberGenerator(integrator.getRandomNumberSeed());
map<string, string> defines;
CUmodule module = cu.createModule(CudaKernelSources::baoab, defines, "");
kernel1 = cu.getKernel(module, "integrateBAOABPart1");
kernel2 = cu.getKernel(module, "integrateBAOABPart2");
kernel3 = cu.getKernel(module, "integrateBAOABPart3");
kernel4 = cu.getKernel(module, "integrateBAOABPart4");
if (cu.getUseDoublePrecision() || cu.getUseMixedPrecision()) {
params.initialize<double>(cu, 3, "baoabParams");
oldDelta.initialize<double4>(cu, cu.getPaddedNumAtoms(), "oldDelta");
}
else {
params.initialize<float>(cu, 3, "baoabParams");
oldDelta.initialize<float4>(cu, cu.getPaddedNumAtoms(), "oldDelta");
}
prevStepSize = -1.0;
}
void CudaIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOABLangevinIntegrator& integrator, bool& forcesAreValid) {
CudaIntegrationUtilities& integration = cu.getIntegrationUtilities();
int numAtoms = cu.getNumAtoms();
int paddedNumAtoms = cu.getPaddedNumAtoms();
if (!forcesAreValid) {
context.calcForcesAndEnergy(true, false);
forcesAreValid = true;
}
double temperature = integrator.getTemperature();
double friction = integrator.getFriction();
double stepSize = integrator.getStepSize();
cu.getIntegrationUtilities().setNextStepSize(stepSize);
if (temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
// Calculate the integration parameters.
double kT = BOLTZ*temperature;
double vscale = exp(-stepSize*friction);
double noisescale = sqrt(kT*(1-vscale*vscale));
vector<double> p(params.getSize());
p[0] = vscale;
p[1] = noisescale;
params.upload(p, true);
prevTemp = temperature;
prevFriction = friction;
prevStepSize = stepSize;
}
// Perform the integrator.
int randomIndex = integration.prepareRandomNumbers(cu.getPaddedNumAtoms());
CUdeviceptr posCorrection = (cu.getUseMixedPrecision() ? cu.getPosqCorrection().getDevicePointer() : 0);
void* args1[] = {&numAtoms, &paddedNumAtoms, &cu.getVelm().getDevicePointer(), &cu.getForce().getDevicePointer(), &integration.getPosDelta().getDevicePointer(),
&oldDelta.getDevicePointer(), &integration.getStepSize().getDevicePointer()};
cu.executeKernel(kernel1, args1, numAtoms, 128);
integration.applyConstraints(integrator.getConstraintTolerance());
void* args2[] = {&numAtoms, &cu.getPosq().getDevicePointer(), &posCorrection, &cu.getVelm().getDevicePointer(), &integration.getPosDelta().getDevicePointer(),
&oldDelta.getDevicePointer(), ¶ms.getDevicePointer(), &integration.getStepSize().getDevicePointer(), &integration.getRandom().getDevicePointer(), &randomIndex};
cu.executeKernel(kernel2, args2, numAtoms, 128);
integration.applyConstraints(integrator.getConstraintTolerance());
void* args3[] = {&numAtoms, &cu.getPosq().getDevicePointer(), &posCorrection, &cu.getVelm().getDevicePointer(),
&integration.getPosDelta().getDevicePointer(), &oldDelta.getDevicePointer(), &integration.getStepSize().getDevicePointer()};
cu.executeKernel(kernel3, args3, numAtoms, 128);
context.calcForcesAndEnergy(true, false);
void* args4[] = {&numAtoms, &paddedNumAtoms, &cu.getVelm().getDevicePointer(),
&cu.getForce().getDevicePointer(), &integration.getStepSize().getDevicePointer()};
cu.executeKernel(kernel4, args4, numAtoms, 128);
integration.applyVelocityConstraints(integrator.getConstraintTolerance());
integration.computeVirtualSites();
// Update the time and step count.
cu.setTime(cu.getTime()+stepSize);
cu.setStepCount(cu.getStepCount()+1);
cu.reorderAtoms();
if (cu.getAtomsWereReordered())
forcesAreValid = false;
// Reduce UI lag.
#ifdef WIN32
cu.getQueue().flush();
#endif
}
double CudaIntegrateBAOABStepKernel::computeKineticEnergy(ContextImpl& context, const BAOABLangevinIntegrator& integrator) {
return cu.getIntegrationUtilities().computeKineticEnergy(0.0);
}
void CudaIntegrateBrownianStepKernel::initialize(const System& system, const BrownianIntegrator& integrator) {
void CudaIntegrateBrownianStepKernel::initialize(const System& system, const BrownianIntegrator& integrator) {
cu.getPlatformData().initializeContexts(system);
cu.getPlatformData().initializeContexts(system);
cu.setAsCurrent();
cu.setAsCurrent();
...
...
platforms/cuda/src/CudaPlatform.cpp
View file @
c7441b96
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,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-201
7
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -97,6 +97,7 @@ CudaPlatform::CudaPlatform() {
...
@@ -97,6 +97,7 @@ CudaPlatform::CudaPlatform() {
registerKernelFactory
(
CalcGayBerneForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcGayBerneForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBAOABStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBrownianStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBrownianStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableLangevinStepKernel
::
Name
(),
factory
);
...
...
platforms/cuda/src/kernels/baoab.cu
0 → 100644
View file @
c7441b96
enum
{
VelScale
,
NoiseScale
};
/**
* Perform the first part of BAOAB integration: velocity half step, then position half step.
*/
extern
"C"
__global__
void
integrateBAOABPart1
(
int
numAtoms
,
int
paddedNumAtoms
,
mixed4
*
__restrict__
velm
,
const
long
long
*
__restrict__
force
,
mixed4
*
__restrict__
posDelta
,
mixed4
*
__restrict__
oldDelta
,
const
mixed2
*
__restrict__
dt
)
{
mixed
halfdt
=
0.5
*
dt
[
0
].
y
;
mixed
fscale
=
halfdt
/
(
mixed
)
0x100000000
;
for
(
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
index
<
numAtoms
;
index
+=
blockDim
.
x
*
gridDim
.
x
)
{
mixed4
velocity
=
velm
[
index
];
if
(
velocity
.
w
!=
0.0
)
{
velocity
.
x
+=
fscale
*
velocity
.
w
*
force
[
index
];
velocity
.
y
+=
fscale
*
velocity
.
w
*
force
[
index
+
paddedNumAtoms
];
velocity
.
z
+=
fscale
*
velocity
.
w
*
force
[
index
+
paddedNumAtoms
*
2
];
velm
[
index
]
=
velocity
;
mixed4
delta
=
make_mixed4
(
halfdt
*
velocity
.
x
,
halfdt
*
velocity
.
y
,
halfdt
*
velocity
.
z
,
0
);
posDelta
[
index
]
=
delta
;
oldDelta
[
index
]
=
delta
;
}
}
}
/**
* Perform the second part of BAOAB integration: apply constraint forces to velocities, then interact with heat bath,
* then position half step.
*/
extern
"C"
__global__
void
integrateBAOABPart2
(
int
numAtoms
,
real4
*
__restrict__
posq
,
real4
*
__restrict__
posqCorrection
,
mixed4
*
__restrict__
velm
,
mixed4
*
__restrict__
posDelta
,
mixed4
*
__restrict__
oldDelta
,
const
mixed
*
__restrict__
paramBuffer
,
const
mixed2
*
__restrict__
dt
,
const
float4
*
__restrict__
random
,
unsigned
int
randomIndex
)
{
mixed
vscale
=
paramBuffer
[
VelScale
];
mixed
noisescale
=
paramBuffer
[
NoiseScale
];
mixed
halfdt
=
0.5
*
dt
[
0
].
y
;
mixed
invHalfdt
=
1
/
halfdt
;
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
randomIndex
+=
index
;
while
(
index
<
numAtoms
)
{
mixed4
velocity
=
velm
[
index
];
if
(
velocity
.
w
!=
0.0
)
{
mixed4
delta
=
posDelta
[
index
];
mixed
sqrtInvMass
=
SQRT
(
velocity
.
w
);
velocity
.
x
+=
(
delta
.
x
-
oldDelta
[
index
].
x
)
*
invHalfdt
;
velocity
.
y
+=
(
delta
.
y
-
oldDelta
[
index
].
y
)
*
invHalfdt
;
velocity
.
z
+=
(
delta
.
z
-
oldDelta
[
index
].
z
)
*
invHalfdt
;
velocity
.
x
=
vscale
*
velocity
.
x
+
noisescale
*
sqrtInvMass
*
random
[
randomIndex
].
x
;
velocity
.
y
=
vscale
*
velocity
.
y
+
noisescale
*
sqrtInvMass
*
random
[
randomIndex
].
y
;
velocity
.
z
=
vscale
*
velocity
.
z
+
noisescale
*
sqrtInvMass
*
random
[
randomIndex
].
z
;
velm
[
index
]
=
velocity
;
#ifdef USE_MIXED_PRECISION
real4
pos1
=
posq
[
index
];
real4
pos2
=
posqCorrection
[
index
];
mixed4
pos
=
make_mixed4
(
pos1
.
x
+
(
mixed
)
pos2
.
x
,
pos1
.
y
+
(
mixed
)
pos2
.
y
,
pos1
.
z
+
(
mixed
)
pos2
.
z
,
pos1
.
w
);
#else
real4
pos
=
posq
[
index
];
#endif
pos
.
x
+=
delta
.
x
;
pos
.
y
+=
delta
.
y
;
pos
.
z
+=
delta
.
z
;
#ifdef USE_MIXED_PRECISION
posq
[
index
]
=
make_real4
((
real
)
pos
.
x
,
(
real
)
pos
.
y
,
(
real
)
pos
.
z
,
(
real
)
pos
.
w
);
posqCorrection
[
index
]
=
make_real4
(
pos
.
x
-
(
real
)
pos
.
x
,
pos
.
y
-
(
real
)
pos
.
y
,
pos
.
z
-
(
real
)
pos
.
z
,
0
);
#else
posq
[
index
]
=
pos
;
#endif
delta
=
make_mixed4
(
halfdt
*
velocity
.
x
,
halfdt
*
velocity
.
y
,
halfdt
*
velocity
.
z
,
0
);
posDelta
[
index
]
=
delta
;
oldDelta
[
index
]
=
delta
;
}
randomIndex
+=
blockDim
.
x
*
gridDim
.
x
;
index
+=
blockDim
.
x
*
gridDim
.
x
;
}
}
/**
* Perform the third part of BAOAB integration: apply constraint forces to velocities, then record
* the constrained positions in preparation for computing forces.
*/
extern
"C"
__global__
void
integrateBAOABPart3
(
int
numAtoms
,
real4
*
__restrict__
posq
,
real4
*
__restrict__
posqCorrection
,
mixed4
*
__restrict__
velm
,
mixed4
*
__restrict__
posDelta
,
mixed4
*
__restrict__
oldDelta
,
const
mixed2
*
__restrict__
dt
)
{
mixed
halfdt
=
0.5
*
dt
[
0
].
y
;
mixed
invHalfdt
=
1
/
halfdt
;
for
(
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
index
<
numAtoms
;
index
+=
blockDim
.
x
*
gridDim
.
x
)
{
mixed4
velocity
=
velm
[
index
];
if
(
velocity
.
w
!=
0.0
)
{
mixed4
delta
=
posDelta
[
index
];
velocity
.
x
+=
(
delta
.
x
-
oldDelta
[
index
].
x
)
*
invHalfdt
;
velocity
.
y
+=
(
delta
.
y
-
oldDelta
[
index
].
y
)
*
invHalfdt
;
velocity
.
z
+=
(
delta
.
z
-
oldDelta
[
index
].
z
)
*
invHalfdt
;
velm
[
index
]
=
velocity
;
#ifdef USE_MIXED_PRECISION
real4
pos1
=
posq
[
index
];
real4
pos2
=
posqCorrection
[
index
];
mixed4
pos
=
make_mixed4
(
pos1
.
x
+
(
mixed
)
pos2
.
x
,
pos1
.
y
+
(
mixed
)
pos2
.
y
,
pos1
.
z
+
(
mixed
)
pos2
.
z
,
pos1
.
w
);
#else
real4
pos
=
posq
[
index
];
#endif
pos
.
x
+=
delta
.
x
;
pos
.
y
+=
delta
.
y
;
pos
.
z
+=
delta
.
z
;
#ifdef USE_MIXED_PRECISION
posq
[
index
]
=
make_real4
((
real
)
pos
.
x
,
(
real
)
pos
.
y
,
(
real
)
pos
.
z
,
(
real
)
pos
.
w
);
posqCorrection
[
index
]
=
make_real4
(
pos
.
x
-
(
real
)
pos
.
x
,
pos
.
y
-
(
real
)
pos
.
y
,
pos
.
z
-
(
real
)
pos
.
z
,
0
);
#else
posq
[
index
]
=
pos
;
#endif
}
}
}
/**
* Perform the fourth part of BAOAB integration: velocity half step.
*/
extern
"C"
__global__
void
integrateBAOABPart4
(
int
numAtoms
,
int
paddedNumAtoms
,
mixed4
*
__restrict__
velm
,
const
long
long
*
__restrict__
force
,
const
mixed2
*
__restrict__
dt
)
{
mixed
halfdt
=
0.5
*
dt
[
0
].
y
;
mixed
fscale
=
halfdt
/
(
mixed
)
0x100000000
;
for
(
int
index
=
blockIdx
.
x
*
blockDim
.
x
+
threadIdx
.
x
;
index
<
numAtoms
;
index
+=
blockDim
.
x
*
gridDim
.
x
)
{
mixed4
velocity
=
velm
[
index
];
if
(
velocity
.
w
!=
0.0
)
{
velocity
.
x
+=
fscale
*
velocity
.
w
*
force
[
index
];
velocity
.
y
+=
fscale
*
velocity
.
w
*
force
[
index
+
paddedNumAtoms
];
velocity
.
z
+=
fscale
*
velocity
.
w
*
force
[
index
+
paddedNumAtoms
*
2
];
velm
[
index
]
=
velocity
;
}
}
}
platforms/cuda/tests/TestCudaBAOABLangevinIntegrator.cpp
0 → 100644
View file @
c7441b96
/* -------------------------------------------------------------------------- *
* 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) 2019 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. *
* -------------------------------------------------------------------------- */
#include "CudaTests.h"
#include "TestBAOABLangevinIntegrator.h"
void
runPlatformTests
()
{
}
platforms/opencl/include/OpenCLKernels.h
View file @
c7441b96
...
@@ -1383,6 +1383,47 @@ private:
...
@@ -1383,6 +1383,47 @@ private:
cl
::
Kernel
kernel1
,
kernel2
;
cl
::
Kernel
kernel1
,
kernel2
;
};
};
/**
* This kernel is invoked by BAOABLangevinIntegrator to take one time step.
*/
class
OpenCLIntegrateBAOABStepKernel
:
public
IntegrateBAOABStepKernel
{
public:
OpenCLIntegrateBAOABStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
OpenCLContext
&
cl
)
:
IntegrateBAOABStepKernel
(
name
,
platform
),
cl
(
cl
),
hasInitializedKernels
(
false
)
{
}
/**
* Initialize the kernel, setting up the particle masses.
*
* @param system the System this kernel will be applied to
* @param integrator the BAOABLangevinIntegrator this kernel will be used for
*/
void
initialize
(
const
System
&
system
,
const
BAOABLangevinIntegrator
&
integrator
);
/**
* Execute the kernel.
*
* @param context the context in which to execute this kernel
* @param integrator the BAOABLangevinIntegrator this kernel is being used for
* @param forcesAreValid if the context has been modified since the last time step, this will be
* false to show that cached forces are invalid and must be recalculated.
* On exit, this should specify whether the cached forces are valid at the
* end of the step.
*/
void
execute
(
ContextImpl
&
context
,
const
BAOABLangevinIntegrator
&
integrator
,
bool
&
forcesAreValid
);
/**
* Compute the kinetic energy.
*
* @param context the context in which to execute this kernel
* @param integrator the BAOABLangevinIntegrator this kernel is being used for
*/
double
computeKineticEnergy
(
ContextImpl
&
context
,
const
BAOABLangevinIntegrator
&
integrator
);
private:
OpenCLContext
&
cl
;
double
prevTemp
,
prevFriction
,
prevStepSize
;
bool
hasInitializedKernels
;
OpenCLArray
params
,
oldDelta
;
cl
::
Kernel
kernel1
,
kernel2
,
kernel3
,
kernel4
;
};
/**
/**
* This kernel is invoked by BrownianIntegrator to take one time step.
* This kernel is invoked by BrownianIntegrator to take one time step.
*/
*/
...
...
platforms/opencl/src/OpenCLKernelFactory.cpp
View file @
c7441b96
...
@@ -118,6 +118,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo
...
@@ -118,6 +118,8 @@ KernelImpl* OpenCLKernelFactory::createKernelImpl(std::string name, const Platfo
return
new
OpenCLIntegrateVerletStepKernel
(
name
,
platform
,
cl
);
return
new
OpenCLIntegrateVerletStepKernel
(
name
,
platform
,
cl
);
if
(
name
==
IntegrateLangevinStepKernel
::
Name
())
if
(
name
==
IntegrateLangevinStepKernel
::
Name
())
return
new
OpenCLIntegrateLangevinStepKernel
(
name
,
platform
,
cl
);
return
new
OpenCLIntegrateLangevinStepKernel
(
name
,
platform
,
cl
);
if
(
name
==
IntegrateBAOABStepKernel
::
Name
())
return
new
OpenCLIntegrateBAOABStepKernel
(
name
,
platform
,
cl
);
if
(
name
==
IntegrateBrownianStepKernel
::
Name
())
if
(
name
==
IntegrateBrownianStepKernel
::
Name
())
return
new
OpenCLIntegrateBrownianStepKernel
(
name
,
platform
,
cl
);
return
new
OpenCLIntegrateBrownianStepKernel
(
name
,
platform
,
cl
);
if
(
name
==
IntegrateVariableVerletStepKernel
::
Name
())
if
(
name
==
IntegrateVariableVerletStepKernel
::
Name
())
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
c7441b96
...
@@ -7473,6 +7473,111 @@ double OpenCLIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& cont
...
@@ -7473,6 +7473,111 @@ double OpenCLIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& cont
return
cl
.
getIntegrationUtilities
().
computeKineticEnergy
(
0.5
*
integrator
.
getStepSize
());
return
cl
.
getIntegrationUtilities
().
computeKineticEnergy
(
0.5
*
integrator
.
getStepSize
());
}
}
void
OpenCLIntegrateBAOABStepKernel
::
initialize
(
const
System
&
system
,
const
BAOABLangevinIntegrator
&
integrator
)
{
cl
.
getPlatformData
().
initializeContexts
(
system
);
cl
.
getIntegrationUtilities
().
initRandomNumberGenerator
(
integrator
.
getRandomNumberSeed
());
map
<
string
,
string
>
defines
;
defines
[
"NUM_ATOMS"
]
=
cl
.
intToString
(
cl
.
getNumAtoms
());
defines
[
"PADDED_NUM_ATOMS"
]
=
cl
.
intToString
(
cl
.
getPaddedNumAtoms
());
cl
::
Program
program
=
cl
.
createProgram
(
OpenCLKernelSources
::
baoab
,
defines
,
""
);
kernel1
=
cl
::
Kernel
(
program
,
"integrateBAOABPart1"
);
kernel2
=
cl
::
Kernel
(
program
,
"integrateBAOABPart2"
);
kernel3
=
cl
::
Kernel
(
program
,
"integrateBAOABPart3"
);
kernel4
=
cl
::
Kernel
(
program
,
"integrateBAOABPart4"
);
if
(
cl
.
getUseDoublePrecision
()
||
cl
.
getUseMixedPrecision
())
{
params
.
initialize
<
cl_double
>
(
cl
,
2
,
"baoabParams"
);
oldDelta
.
initialize
<
mm_double4
>
(
cl
,
cl
.
getPaddedNumAtoms
(),
"oldDelta"
);
}
else
{
params
.
initialize
<
cl_float
>
(
cl
,
2
,
"baoabParams"
);
oldDelta
.
initialize
<
mm_float4
>
(
cl
,
cl
.
getPaddedNumAtoms
(),
"oldDelta"
);
}
prevStepSize
=
-
1.0
;
}
void
OpenCLIntegrateBAOABStepKernel
::
execute
(
ContextImpl
&
context
,
const
BAOABLangevinIntegrator
&
integrator
,
bool
&
forcesAreValid
)
{
OpenCLIntegrationUtilities
&
integration
=
cl
.
getIntegrationUtilities
();
int
numAtoms
=
cl
.
getNumAtoms
();
if
(
!
hasInitializedKernels
)
{
hasInitializedKernels
=
true
;
kernel1
.
setArg
<
cl
::
Buffer
>
(
0
,
cl
.
getVelm
().
getDeviceBuffer
());
kernel1
.
setArg
<
cl
::
Buffer
>
(
1
,
cl
.
getForce
().
getDeviceBuffer
());
kernel1
.
setArg
<
cl
::
Buffer
>
(
2
,
integration
.
getPosDelta
().
getDeviceBuffer
());
kernel1
.
setArg
<
cl
::
Buffer
>
(
3
,
oldDelta
.
getDeviceBuffer
());
kernel1
.
setArg
<
cl
::
Buffer
>
(
4
,
integration
.
getStepSize
().
getDeviceBuffer
());
kernel2
.
setArg
<
cl
::
Buffer
>
(
0
,
cl
.
getPosq
().
getDeviceBuffer
());
setPosqCorrectionArg
(
cl
,
kernel2
,
1
);
kernel2
.
setArg
<
cl
::
Buffer
>
(
2
,
cl
.
getVelm
().
getDeviceBuffer
());
kernel2
.
setArg
<
cl
::
Buffer
>
(
3
,
integration
.
getPosDelta
().
getDeviceBuffer
());
kernel2
.
setArg
<
cl
::
Buffer
>
(
4
,
oldDelta
.
getDeviceBuffer
());
kernel2
.
setArg
<
cl
::
Buffer
>
(
5
,
params
.
getDeviceBuffer
());
kernel2
.
setArg
<
cl
::
Buffer
>
(
6
,
integration
.
getStepSize
().
getDeviceBuffer
());
kernel2
.
setArg
<
cl
::
Buffer
>
(
7
,
integration
.
getRandom
().
getDeviceBuffer
());
kernel3
.
setArg
<
cl
::
Buffer
>
(
0
,
cl
.
getPosq
().
getDeviceBuffer
());
setPosqCorrectionArg
(
cl
,
kernel3
,
1
);
kernel3
.
setArg
<
cl
::
Buffer
>
(
2
,
cl
.
getVelm
().
getDeviceBuffer
());
kernel3
.
setArg
<
cl
::
Buffer
>
(
3
,
integration
.
getPosDelta
().
getDeviceBuffer
());
kernel3
.
setArg
<
cl
::
Buffer
>
(
4
,
oldDelta
.
getDeviceBuffer
());
kernel3
.
setArg
<
cl
::
Buffer
>
(
5
,
integration
.
getStepSize
().
getDeviceBuffer
());
kernel4
.
setArg
<
cl
::
Buffer
>
(
0
,
cl
.
getVelm
().
getDeviceBuffer
());
kernel4
.
setArg
<
cl
::
Buffer
>
(
1
,
cl
.
getForce
().
getDeviceBuffer
());
kernel4
.
setArg
<
cl
::
Buffer
>
(
2
,
integration
.
getStepSize
().
getDeviceBuffer
());
}
if
(
!
forcesAreValid
)
{
context
.
calcForcesAndEnergy
(
true
,
false
);
forcesAreValid
=
true
;
}
double
temperature
=
integrator
.
getTemperature
();
double
friction
=
integrator
.
getFriction
();
double
stepSize
=
integrator
.
getStepSize
();
cl
.
getIntegrationUtilities
().
setNextStepSize
(
stepSize
);
if
(
temperature
!=
prevTemp
||
friction
!=
prevFriction
||
stepSize
!=
prevStepSize
)
{
// Calculate the integration parameters.
double
kT
=
BOLTZ
*
temperature
;
double
vscale
=
exp
(
-
stepSize
*
friction
);
double
noisescale
=
sqrt
(
kT
*
(
1
-
vscale
*
vscale
));
vector
<
cl_double
>
p
(
params
.
getSize
());
p
[
0
]
=
vscale
;
p
[
1
]
=
noisescale
;
params
.
upload
(
p
,
true
,
true
);
prevTemp
=
temperature
;
prevFriction
=
friction
;
prevStepSize
=
stepSize
;
}
// Perform the integrator.
kernel2
.
setArg
<
cl_uint
>
(
8
,
integration
.
prepareRandomNumbers
(
cl
.
getPaddedNumAtoms
()));
cl
.
executeKernel
(
kernel1
,
numAtoms
);
integration
.
applyConstraints
(
integrator
.
getConstraintTolerance
());
cl
.
executeKernel
(
kernel2
,
numAtoms
);
integration
.
applyConstraints
(
integrator
.
getConstraintTolerance
());
cl
.
executeKernel
(
kernel3
,
numAtoms
);
context
.
calcForcesAndEnergy
(
true
,
false
);
cl
.
executeKernel
(
kernel4
,
numAtoms
);
integration
.
applyVelocityConstraints
(
integrator
.
getConstraintTolerance
());
integration
.
computeVirtualSites
();
// Update the time and step count.
cl
.
setTime
(
cl
.
getTime
()
+
stepSize
);
cl
.
setStepCount
(
cl
.
getStepCount
()
+
1
);
cl
.
reorderAtoms
();
if
(
cl
.
getAtomsWereReordered
())
forcesAreValid
=
false
;
// Reduce UI lag.
#ifdef WIN32
cl
.
getQueue
().
flush
();
#endif
}
double
OpenCLIntegrateBAOABStepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
BAOABLangevinIntegrator
&
integrator
)
{
return
cl
.
getIntegrationUtilities
().
computeKineticEnergy
(
0.0
);
}
OpenCLIntegrateBrownianStepKernel
::~
OpenCLIntegrateBrownianStepKernel
()
{
OpenCLIntegrateBrownianStepKernel
::~
OpenCLIntegrateBrownianStepKernel
()
{
}
}
...
...
platforms/opencl/src/OpenCLPlatform.cpp
View file @
c7441b96
...
@@ -88,6 +88,7 @@ OpenCLPlatform::OpenCLPlatform() {
...
@@ -88,6 +88,7 @@ OpenCLPlatform::OpenCLPlatform() {
registerKernelFactory
(
CalcGayBerneForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcGayBerneForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBAOABStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBrownianStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBrownianStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableLangevinStepKernel
::
Name
(),
factory
);
...
...
platforms/opencl/src/kernels/baoab.cl
0 → 100644
View file @
c7441b96
enum
{VelScale,
NoiseScale}
;
/**
*
Perform
the
first
part
of
BAOAB
integration:
velocity
half
step,
then
position
half
step.
*/
__kernel
void
integrateBAOABPart1
(
__global
mixed4*
restrict
velm,
__global
const
real4*
restrict
force,
__global
mixed4*
restrict
posDelta,
__global
mixed4*
restrict
oldDelta,
__global
const
mixed2*
restrict
dt
)
{
mixed
halfdt
=
0.5*dt[0].y
;
for
(
int
index
=
get_global_id
(
0
)
; index < NUM_ATOMS; index += get_global_size(0)) {
mixed4
velocity
=
velm[index]
;
if
(
velocity.w
!=
0.0
)
{
velocity.x
+=
halfdt*velocity.w*force[index].x
;
velocity.y
+=
halfdt*velocity.w*force[index].y
;
velocity.z
+=
halfdt*velocity.w*force[index].z
;
velm[index]
=
velocity
;
mixed4
delta
=
halfdt*velocity
;
posDelta[index]
=
delta
;
oldDelta[index]
=
delta
;
}
}
}
/**
*
Perform
the
second
part
of
BAOAB
integration:
apply
constraint
forces
to
velocities,
then
interact
with
heat
bath,
*
then
position
half
step.
*/
__kernel
void
integrateBAOABPart2
(
__global
real4*
restrict
posq,
__global
real4*
restrict
posqCorrection,
__global
mixed4*
restrict
velm,
__global
mixed4*
restrict
posDelta,
__global
mixed4*
restrict
oldDelta,
__global
const
mixed*
restrict
paramBuffer,
__global
const
mixed2*
restrict
dt,
__global
const
float4*
restrict
random,
unsigned
int
randomIndex
)
{
mixed
vscale
=
paramBuffer[VelScale]
;
mixed
noisescale
=
paramBuffer[NoiseScale]
;
mixed
halfdt
=
0.5*dt[0].y
;
mixed
invHalfdt
=
1/halfdt
;
int
index
=
get_global_id
(
0
)
;
randomIndex
+=
index
;
while
(
index
<
NUM_ATOMS
)
{
mixed4
velocity
=
velm[index]
;
if
(
velocity.w
!=
0.0
)
{
mixed4
delta
=
posDelta[index]
;
mixed
sqrtInvMass
=
SQRT
(
velocity.w
)
;
velocity.xyz
+=
(
delta.xyz-oldDelta[index].xyz
)
*invHalfdt
;
velocity.x
=
vscale*velocity.x
+
noisescale*sqrtInvMass*random[randomIndex].x
;
velocity.y
=
vscale*velocity.y
+
noisescale*sqrtInvMass*random[randomIndex].y
;
velocity.z
=
vscale*velocity.z
+
noisescale*sqrtInvMass*random[randomIndex].z
;
velm[index]
=
velocity
;
#
ifdef
USE_MIXED_PRECISION
real4
pos1
=
posq[index]
;
real4
pos2
=
posqCorrection[index]
;
mixed4
pos
=
(
mixed4
)
(
pos1.x+
(
mixed
)
pos2.x,
pos1.y+
(
mixed
)
pos2.y,
pos1.z+
(
mixed
)
pos2.z,
pos1.w
)
;
#
else
real4
pos
=
posq[index]
;
#
endif
pos.xyz
+=
delta.xyz
;
#
ifdef
USE_MIXED_PRECISION
posq[index]
=
convert_real4
(
pos
)
;
posqCorrection[index]
=
(
real4
)
(
pos.x-
(
real
)
pos.x,
pos.y-
(
real
)
pos.y,
pos.z-
(
real
)
pos.z,
0
)
;
#
else
posq[index]
=
pos
;
#
endif
delta
=
halfdt*velocity
;
posDelta[index]
=
delta
;
oldDelta[index]
=
delta
;
}
randomIndex
+=
get_global_size
(
0
)
;
index
+=
get_global_size
(
0
)
;
}
}
/**
*
Perform
the
third
part
of
BAOAB
integration:
apply
constraint
forces
to
velocities,
then
record
*
the
constrained
positions
in
preparation
for
computing
forces.
*/
__kernel
void
integrateBAOABPart3
(
__global
real4*
restrict
posq,
__global
real4*
restrict
posqCorrection,
__global
mixed4*
restrict
velm,
__global
mixed4*
restrict
posDelta,
__global
mixed4*
restrict
oldDelta,
__global
const
mixed2*
restrict
dt
)
{
mixed
halfdt
=
0.5*dt[0].y
;
mixed
invHalfdt
=
1/halfdt
;
for
(
int
index
=
get_global_id
(
0
)
; index < NUM_ATOMS; index += get_global_size(0)) {
mixed4
velocity
=
velm[index]
;
if
(
velocity.w
!=
0.0
)
{
mixed4
delta
=
posDelta[index]
;
velocity.x
+=
(
delta.x-oldDelta[index].x
)
*invHalfdt
;
velocity.y
+=
(
delta.y-oldDelta[index].y
)
*invHalfdt
;
velocity.z
+=
(
delta.z-oldDelta[index].z
)
*invHalfdt
;
velm[index]
=
velocity
;
#
ifdef
USE_MIXED_PRECISION
real4
pos1
=
posq[index]
;
real4
pos2
=
posqCorrection[index]
;
mixed4
pos
=
(
mixed4
)
(
pos1.x+
(
mixed
)
pos2.x,
pos1.y+
(
mixed
)
pos2.y,
pos1.z+
(
mixed
)
pos2.z,
pos1.w
)
;
#
else
real4
pos
=
posq[index]
;
#
endif
pos.xyz
+=
delta.xyz
;
#
ifdef
USE_MIXED_PRECISION
posq[index]
=
convert_real4
(
pos
)
;
posqCorrection[index]
=
(
real4
)
(
pos.x-
(
real
)
pos.x,
pos.y-
(
real
)
pos.y,
pos.z-
(
real
)
pos.z,
0
)
;
#
else
posq[index]
=
pos
;
#
endif
}
}
}
/**
*
Perform
the
fourth
part
of
BAOAB
integration:
velocity
half
step.
*/
__kernel
void
integrateBAOABPart4
(
__global
mixed4*
restrict
velm,
__global
const
real4*
restrict
force,
__global
const
mixed2*
restrict
dt
)
{
mixed
halfdt
=
0.5*dt[0].y
;
for
(
int
index
=
get_global_id
(
0
)
; index < NUM_ATOMS; index += get_global_size(0)) {
mixed4
velocity
=
velm[index]
;
if
(
velocity.w
!=
0.0
)
{
velocity.x
+=
halfdt*velocity.w*force[index].x
;
velocity.y
+=
halfdt*velocity.w*force[index].y
;
velocity.z
+=
halfdt*velocity.w*force[index].z
;
velm[index]
=
velocity
;
}
}
}
platforms/opencl/tests/TestOpenCLBAOABLangevinIntegrator.cpp
0 → 100644
View file @
c7441b96
/* -------------------------------------------------------------------------- *
* 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) 2019 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. *
* -------------------------------------------------------------------------- */
#include "OpenCLTests.h"
#include "TestBAOABLangevinIntegrator.h"
void
runPlatformTests
()
{
}
platforms/reference/include/ReferenceBAOABDynamics.h
0 → 100644
View file @
c7441b96
/* Portions copyright (c) 2006-2019 Stanford University and Simbios.
* Contributors: Pande Group
*
* 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.
*/
#ifndef __ReferenceBAOABDynamics_H__
#define __ReferenceBAOABDynamics_H__
#include "ReferenceDynamics.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/internal/windowsExport.h"
namespace
OpenMM
{
class
OPENMM_EXPORT
ReferenceBAOABDynamics
:
public
ReferenceDynamics
{
protected:
std
::
vector
<
OpenMM
::
Vec3
>
xPrime
,
oldx
;
std
::
vector
<
double
>
inverseMasses
;
double
friction
;
public:
/**---------------------------------------------------------------------------------------
Constructor
@param numberOfAtoms number of atoms
@param deltaT delta t for dynamics
@param friction friction coefficient
@param temperature temperature
--------------------------------------------------------------------------------------- */
ReferenceBAOABDynamics
(
int
numberOfAtoms
,
double
deltaT
,
double
friction
,
double
temperature
);
/**---------------------------------------------------------------------------------------
Destructor
--------------------------------------------------------------------------------------- */
~
ReferenceBAOABDynamics
();
/**---------------------------------------------------------------------------------------
Get friction coefficient
--------------------------------------------------------------------------------------- */
double
getFriction
()
const
;
/**---------------------------------------------------------------------------------------
Update
@param context the context this integrator is updating
@param system the System to be integrated
@param atomCoordinates atom coordinates
@param velocities velocities
@param masses atom masses
@param forcesAreValid whether the current forces are valid or need to be recomputed
@param tolerance the constraint tolerance
--------------------------------------------------------------------------------------- */
void
update
(
OpenMM
::
ContextImpl
&
context
,
std
::
vector
<
OpenMM
::
Vec3
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
Vec3
>&
velocities
,
std
::
vector
<
double
>&
masses
,
bool
&
forcesAreValid
,
double
tolerance
);
/**---------------------------------------------------------------------------------------
First update; based on code in update.c do_update_sd() Gromacs 3.1.4
@param numberOfAtoms number of atoms
@param atomCoordinates atom coordinates
@param velocities velocities
@param forces forces
@param inverseMasses inverse atom masses
@param xPrime xPrime
--------------------------------------------------------------------------------------- */
virtual
void
updatePart1
(
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
Vec3
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
Vec3
>&
velocities
,
std
::
vector
<
OpenMM
::
Vec3
>&
forces
,
std
::
vector
<
double
>&
inverseMasses
,
std
::
vector
<
OpenMM
::
Vec3
>&
xPrime
);
/**---------------------------------------------------------------------------------------
Second update
@param numberOfAtoms number of atoms
@param atomCoordinates atom coordinates
@param velocities velocities
@param inverseMasses inverse atom masses
@param xPrime xPrime
--------------------------------------------------------------------------------------- */
virtual
void
updatePart2
(
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
Vec3
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
Vec3
>&
velocities
,
std
::
vector
<
double
>&
inverseMasses
,
std
::
vector
<
OpenMM
::
Vec3
>&
xPrime
);
/**---------------------------------------------------------------------------------------
Third update
@param context the context this integrator is updating
@param numberOfAtoms number of atoms
@param atomCoordinates atom coordinates
@param velocities velocities
@param forces forces
@param inverseMasses inverse atom masses
@param xPrime xPrime
--------------------------------------------------------------------------------------- */
virtual
void
updatePart3
(
OpenMM
::
ContextImpl
&
context
,
int
numberOfAtoms
,
std
::
vector
<
OpenMM
::
Vec3
>&
atomCoordinates
,
std
::
vector
<
OpenMM
::
Vec3
>&
velocities
,
std
::
vector
<
OpenMM
::
Vec3
>&
forces
,
std
::
vector
<
double
>&
inverseMasses
,
std
::
vector
<
OpenMM
::
Vec3
>&
xPrime
);
};
}
// namespace OpenMM
#endif // __ReferenceBAOABDynamics_H__
platforms/reference/include/ReferenceKernels.h
View file @
c7441b96
...
@@ -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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -45,6 +45,7 @@ namespace OpenMM {
...
@@ -45,6 +45,7 @@ namespace OpenMM {
class
ReferenceObc
;
class
ReferenceObc
;
class
ReferenceAndersenThermostat
;
class
ReferenceAndersenThermostat
;
class
ReferenceBAOABDynamics
;
class
ReferenceCustomBondIxn
;
class
ReferenceCustomBondIxn
;
class
ReferenceCustomAngleIxn
;
class
ReferenceCustomAngleIxn
;
class
ReferenceCustomTorsionIxn
;
class
ReferenceCustomTorsionIxn
;
...
@@ -1170,6 +1171,47 @@ private:
...
@@ -1170,6 +1171,47 @@ private:
double
prevTemp
,
prevFriction
,
prevStepSize
;
double
prevTemp
,
prevFriction
,
prevStepSize
;
};
};
/**
* This kernel is invoked by BAOABLangevinIntegrator to take one time step.
*/
class
ReferenceIntegrateBAOABStepKernel
:
public
IntegrateBAOABStepKernel
{
public:
ReferenceIntegrateBAOABStepKernel
(
std
::
string
name
,
const
Platform
&
platform
,
ReferencePlatform
::
PlatformData
&
data
)
:
IntegrateBAOABStepKernel
(
name
,
platform
),
data
(
data
),
dynamics
(
0
)
{
}
~
ReferenceIntegrateBAOABStepKernel
();
/**
* Initialize the kernel, setting up the particle masses.
*
* @param system the System this kernel will be applied to
* @param integrator the BAOABLangevinIntegrator this kernel will be used for
*/
void
initialize
(
const
System
&
system
,
const
BAOABLangevinIntegrator
&
integrator
);
/**
* Execute the kernel.
*
* @param context the context in which to execute this kernel
* @param integrator the BAOABLangevinIntegrator this kernel is being used for
* @param forcesAreValid if the context has been modified since the last time step, this will be
* false to show that cached forces are invalid and must be recalculated.
* On exit, this should specify whether the cached forces are valid at the
* end of the step.
*/
void
execute
(
ContextImpl
&
context
,
const
BAOABLangevinIntegrator
&
integrator
,
bool
&
forcesAreValid
);
/**
* Compute the kinetic energy.
*
* @param context the context in which to execute this kernel
* @param integrator the BAOABLangevinIntegrator this kernel is being used for
*/
double
computeKineticEnergy
(
ContextImpl
&
context
,
const
BAOABLangevinIntegrator
&
integrator
);
private:
ReferencePlatform
::
PlatformData
&
data
;
ReferenceBAOABDynamics
*
dynamics
;
std
::
vector
<
double
>
masses
;
double
prevTemp
,
prevFriction
,
prevStepSize
;
};
/**
/**
* This kernel is invoked by BrownianIntegrator to take one time step.
* This kernel is invoked by BrownianIntegrator to take one time step.
*/
*/
...
...
platforms/reference/src/ReferenceKernelFactory.cpp
View file @
c7441b96
...
@@ -90,6 +90,8 @@ KernelImpl* ReferenceKernelFactory::createKernelImpl(std::string name, const Pla
...
@@ -90,6 +90,8 @@ KernelImpl* ReferenceKernelFactory::createKernelImpl(std::string name, const Pla
return
new
ReferenceIntegrateVerletStepKernel
(
name
,
platform
,
data
);
return
new
ReferenceIntegrateVerletStepKernel
(
name
,
platform
,
data
);
if
(
name
==
IntegrateLangevinStepKernel
::
Name
())
if
(
name
==
IntegrateLangevinStepKernel
::
Name
())
return
new
ReferenceIntegrateLangevinStepKernel
(
name
,
platform
,
data
);
return
new
ReferenceIntegrateLangevinStepKernel
(
name
,
platform
,
data
);
if
(
name
==
IntegrateBAOABStepKernel
::
Name
())
return
new
ReferenceIntegrateBAOABStepKernel
(
name
,
platform
,
data
);
if
(
name
==
IntegrateBrownianStepKernel
::
Name
())
if
(
name
==
IntegrateBrownianStepKernel
::
Name
())
return
new
ReferenceIntegrateBrownianStepKernel
(
name
,
platform
,
data
);
return
new
ReferenceIntegrateBrownianStepKernel
(
name
,
platform
,
data
);
if
(
name
==
IntegrateVariableLangevinStepKernel
::
Name
())
if
(
name
==
IntegrateVariableLangevinStepKernel
::
Name
())
...
...
platforms/reference/src/ReferenceKernels.cpp
View file @
c7441b96
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,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-201
8
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
9
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -33,6 +33,7 @@
...
@@ -33,6 +33,7 @@
#include "ReferenceObc.h"
#include "ReferenceObc.h"
#include "ReferenceAndersenThermostat.h"
#include "ReferenceAndersenThermostat.h"
#include "ReferenceAngleBondIxn.h"
#include "ReferenceAngleBondIxn.h"
#include "ReferenceBAOABDynamics.h"
#include "ReferenceBondForce.h"
#include "ReferenceBondForce.h"
#include "ReferenceBrownianDynamics.h"
#include "ReferenceBrownianDynamics.h"
#include "ReferenceCCMAAlgorithm.h"
#include "ReferenceCCMAAlgorithm.h"
...
@@ -2149,6 +2150,49 @@ double ReferenceIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& c
...
@@ -2149,6 +2150,49 @@ double ReferenceIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& c
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
());
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
());
}
}
ReferenceIntegrateBAOABStepKernel
::~
ReferenceIntegrateBAOABStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
}
void
ReferenceIntegrateBAOABStepKernel
::
initialize
(
const
System
&
system
,
const
BAOABLangevinIntegrator
&
integrator
)
{
int
numParticles
=
system
.
getNumParticles
();
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
system
.
getParticleMass
(
i
);
SimTKOpenMMUtilities
::
setRandomNumberSeed
((
unsigned
int
)
integrator
.
getRandomNumberSeed
());
}
void
ReferenceIntegrateBAOABStepKernel
::
execute
(
ContextImpl
&
context
,
const
BAOABLangevinIntegrator
&
integrator
,
bool
&
forcesAreValid
)
{
double
temperature
=
integrator
.
getTemperature
();
double
friction
=
integrator
.
getFriction
();
double
stepSize
=
integrator
.
getStepSize
();
vector
<
Vec3
>&
posData
=
extractPositions
(
context
);
vector
<
Vec3
>&
velData
=
extractVelocities
(
context
);
if
(
dynamics
==
0
||
temperature
!=
prevTemp
||
friction
!=
prevFriction
||
stepSize
!=
prevStepSize
)
{
// Recreate the computation objects with the new parameters.
if
(
dynamics
)
delete
dynamics
;
dynamics
=
new
ReferenceBAOABDynamics
(
context
.
getSystem
().
getNumParticles
(),
stepSize
,
friction
,
temperature
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractConstraints
(
context
));
prevTemp
=
temperature
;
prevFriction
=
friction
;
prevStepSize
=
stepSize
;
}
dynamics
->
update
(
context
,
posData
,
velData
,
masses
,
forcesAreValid
,
integrator
.
getConstraintTolerance
());
data
.
time
+=
stepSize
;
data
.
stepCount
++
;
}
double
ReferenceIntegrateBAOABStepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
BAOABLangevinIntegrator
&
integrator
)
{
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.0
);
}
ReferenceIntegrateBrownianStepKernel
::~
ReferenceIntegrateBrownianStepKernel
()
{
ReferenceIntegrateBrownianStepKernel
::~
ReferenceIntegrateBrownianStepKernel
()
{
if
(
dynamics
)
if
(
dynamics
)
delete
dynamics
;
delete
dynamics
;
...
...
platforms/reference/src/ReferencePlatform.cpp
View file @
c7441b96
...
@@ -67,6 +67,7 @@ ReferencePlatform::ReferencePlatform() {
...
@@ -67,6 +67,7 @@ ReferencePlatform::ReferencePlatform() {
registerKernelFactory
(
CalcGayBerneForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcGayBerneForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBAOABStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBrownianStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBrownianStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableVerletStepKernel
::
Name
(),
factory
);
...
...
platforms/reference/src/SimTKReference/ReferenceBAOABDynamics.cpp
0 → 100644
View file @
c7441b96
/* Portions copyright (c) 2006-2019 Stanford University and Simbios.
* Contributors: Pande Group
*
* 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.
*/
#include <cstring>
#include <sstream>
#include "SimTKOpenMMUtilities.h"
#include "ReferenceBAOABDynamics.h"
#include "ReferencePlatform.h"
#include "ReferenceVirtualSites.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
using
std
::
vector
;
using
namespace
OpenMM
;
ReferenceBAOABDynamics
::
ReferenceBAOABDynamics
(
int
numberOfAtoms
,
double
deltaT
,
double
friction
,
double
temperature
)
:
ReferenceDynamics
(
numberOfAtoms
,
deltaT
,
temperature
),
friction
(
friction
)
{
xPrime
.
resize
(
numberOfAtoms
);
oldx
.
resize
(
numberOfAtoms
);
inverseMasses
.
resize
(
numberOfAtoms
);
}
ReferenceBAOABDynamics
::~
ReferenceBAOABDynamics
()
{
}
double
ReferenceBAOABDynamics
::
getFriction
()
const
{
return
friction
;
}
void
ReferenceBAOABDynamics
::
updatePart1
(
int
numberOfAtoms
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
Vec3
>&
forces
,
vector
<
double
>&
inverseMasses
,
vector
<
Vec3
>&
xPrime
)
{
const
double
halfdt
=
0.5
*
getDeltaT
();
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
{
if
(
inverseMasses
[
i
]
!=
0.0
)
{
velocities
[
i
]
+=
(
halfdt
*
inverseMasses
[
i
])
*
forces
[
i
];
xPrime
[
i
]
=
atomCoordinates
[
i
]
+
velocities
[
i
]
*
halfdt
;
oldx
[
i
]
=
xPrime
[
i
];
}
}
}
void
ReferenceBAOABDynamics
::
updatePart2
(
int
numberOfAtoms
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
double
>&
inverseMasses
,
vector
<
Vec3
>&
xPrime
)
{
const
double
halfdt
=
0.5
*
getDeltaT
();
const
double
kT
=
BOLTZ
*
getTemperature
();
const
double
friction
=
getFriction
();
const
double
vscale
=
exp
(
-
getDeltaT
()
*
friction
);
const
double
noisescale
=
sqrt
(
1
-
vscale
*
vscale
);
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
{
if
(
inverseMasses
[
i
]
!=
0.0
)
{
velocities
[
i
]
+=
(
xPrime
[
i
]
-
oldx
[
i
])
/
halfdt
;
velocities
[
i
]
=
vscale
*
velocities
[
i
]
+
noisescale
*
sqrt
(
kT
*
inverseMasses
[
i
])
*
Vec3
(
SimTKOpenMMUtilities
::
getNormallyDistributedRandomNumber
(),
SimTKOpenMMUtilities
::
getNormallyDistributedRandomNumber
(),
SimTKOpenMMUtilities
::
getNormallyDistributedRandomNumber
());
atomCoordinates
[
i
]
=
xPrime
[
i
];
xPrime
[
i
]
=
atomCoordinates
[
i
]
+
velocities
[
i
]
*
halfdt
;
oldx
[
i
]
=
xPrime
[
i
];
}
}
}
void
ReferenceBAOABDynamics
::
updatePart3
(
OpenMM
::
ContextImpl
&
context
,
int
numberOfAtoms
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
Vec3
>&
forces
,
vector
<
double
>&
inverseMasses
,
vector
<
Vec3
>&
xPrime
)
{
const
double
halfdt
=
0.5
*
getDeltaT
();
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
{
if
(
inverseMasses
[
i
]
!=
0.0
)
{
velocities
[
i
]
+=
(
xPrime
[
i
]
-
oldx
[
i
])
/
halfdt
;
atomCoordinates
[
i
]
=
xPrime
[
i
];
}
}
context
.
calcForcesAndEnergy
(
true
,
false
);
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
{
if
(
inverseMasses
[
i
]
!=
0.0
)
velocities
[
i
]
+=
(
halfdt
*
inverseMasses
[
i
])
*
forces
[
i
];
}
}
void
ReferenceBAOABDynamics
::
update
(
ContextImpl
&
context
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
double
>&
masses
,
bool
&
forcesAreValid
,
double
tolerance
)
{
int
numberOfAtoms
=
context
.
getSystem
().
getNumParticles
();
ReferenceConstraintAlgorithm
*
referenceConstraintAlgorithm
=
getReferenceConstraintAlgorithm
();
if
(
getTimeStep
()
==
0
)
{
// Invert masses
for
(
int
ii
=
0
;
ii
<
numberOfAtoms
;
ii
++
)
{
if
(
masses
[
ii
]
==
0.0
)
inverseMasses
[
ii
]
=
0.0
;
else
inverseMasses
[
ii
]
=
1.0
/
masses
[
ii
];
}
}
if
(
!
forcesAreValid
)
{
context
.
calcForcesAndEnergy
(
true
,
false
);
forcesAreValid
=
true
;
}
ReferencePlatform
::
PlatformData
*
data
=
reinterpret_cast
<
ReferencePlatform
::
PlatformData
*>
(
context
.
getPlatformData
());
vector
<
Vec3
>&
forces
=
*
data
->
forces
;
// 1st update
updatePart1
(
numberOfAtoms
,
atomCoordinates
,
velocities
,
forces
,
inverseMasses
,
xPrime
);
if
(
referenceConstraintAlgorithm
)
referenceConstraintAlgorithm
->
apply
(
atomCoordinates
,
xPrime
,
inverseMasses
,
tolerance
);
// 2nd update
updatePart2
(
numberOfAtoms
,
atomCoordinates
,
velocities
,
inverseMasses
,
xPrime
);
if
(
referenceConstraintAlgorithm
)
referenceConstraintAlgorithm
->
apply
(
atomCoordinates
,
xPrime
,
inverseMasses
,
tolerance
);
// 3rd update
updatePart3
(
context
,
numberOfAtoms
,
atomCoordinates
,
velocities
,
forces
,
inverseMasses
,
xPrime
);
if
(
referenceConstraintAlgorithm
)
referenceConstraintAlgorithm
->
applyToVelocities
(
atomCoordinates
,
velocities
,
inverseMasses
,
tolerance
);
ReferenceVirtualSites
::
computePositions
(
context
.
getSystem
(),
atomCoordinates
);
incrementTimeStep
();
}
platforms/reference/tests/TestReferenceBAOABLangevinIntegrator.cpp
0 → 100644
View file @
c7441b96
/* -------------------------------------------------------------------------- *
* 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) 2019 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. *
* -------------------------------------------------------------------------- */
#include "ReferenceTests.h"
#include "TestBAOABLangevinIntegrator.h"
void
runPlatformTests
()
{
}
serialization/include/openmm/serialization/BAOABLangevinIntegratorProxy.h
0 → 100644
View file @
c7441b96
#ifndef OPENMM_BAOAB_LANGEVIN_INTEGRATOR_PROXY_H_
#define OPENMM_BAOAB_LANGEVIN_INTEGRATOR_PROXY_H_
#include "openmm/serialization/XmlSerializer.h"
namespace
OpenMM
{
class
BAOABLangevinIntegratorProxy
:
public
SerializationProxy
{
public:
BAOABLangevinIntegratorProxy
();
void
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
;
void
*
deserialize
(
const
SerializationNode
&
node
)
const
;
};
}
#endif
/*OPENMM_BAOAB_LANGEVIN_INTEGRATOR_PROXY_H_*/
\ No newline at end of file
serialization/src/BAOABLangevinIntegratorProxy.cpp
0 → 100644
View file @
c7441b96
/* -------------------------------------------------------------------------- *
* 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) 2010-2019 Stanford University and the Authors. *
* Authors: Peter Eastman, Yutong Zhao *
* 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. *
* -------------------------------------------------------------------------- */
#include "openmm/serialization/BAOABLangevinIntegratorProxy.h"
#include <OpenMM.h>
using
namespace
std
;
using
namespace
OpenMM
;
BAOABLangevinIntegratorProxy
::
BAOABLangevinIntegratorProxy
()
:
SerializationProxy
(
"BAOABLangevinIntegrator"
)
{
}
void
BAOABLangevinIntegratorProxy
::
serialize
(
const
void
*
object
,
SerializationNode
&
node
)
const
{
node
.
setIntProperty
(
"version"
,
1
);
const
BAOABLangevinIntegrator
&
integrator
=
*
reinterpret_cast
<
const
BAOABLangevinIntegrator
*>
(
object
);
node
.
setDoubleProperty
(
"stepSize"
,
integrator
.
getStepSize
());
node
.
setDoubleProperty
(
"constraintTolerance"
,
integrator
.
getConstraintTolerance
());
node
.
setDoubleProperty
(
"temperature"
,
integrator
.
getTemperature
());
node
.
setDoubleProperty
(
"friction"
,
integrator
.
getFriction
());
node
.
setIntProperty
(
"randomSeed"
,
integrator
.
getRandomNumberSeed
());
}
void
*
BAOABLangevinIntegratorProxy
::
deserialize
(
const
SerializationNode
&
node
)
const
{
if
(
node
.
getIntProperty
(
"version"
)
!=
1
)
throw
OpenMMException
(
"Unsupported version number"
);
BAOABLangevinIntegrator
*
integrator
=
new
BAOABLangevinIntegrator
(
node
.
getDoubleProperty
(
"temperature"
),
node
.
getDoubleProperty
(
"friction"
),
node
.
getDoubleProperty
(
"stepSize"
));
integrator
->
setConstraintTolerance
(
node
.
getDoubleProperty
(
"constraintTolerance"
));
integrator
->
setRandomNumberSeed
(
node
.
getIntProperty
(
"randomSeed"
));
return
integrator
;
}
\ No newline at end of file
Prev
1
2
3
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