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
37a87d8a
Commit
37a87d8a
authored
Dec 01, 2016
by
Peter Eastman
Browse files
Langevin integrator supports setting friction to 0
parent
9f717609
Changes
14
Hide whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
75 additions
and
109 deletions
+75
-109
platforms/cpu/include/CpuLangevinDynamics.h
platforms/cpu/include/CpuLangevinDynamics.h
+3
-3
platforms/cpu/src/CpuKernels.cpp
platforms/cpu/src/CpuKernels.cpp
+1
-2
platforms/cpu/src/CpuLangevinDynamics.cpp
platforms/cpu/src/CpuLangevinDynamics.cpp
+8
-7
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+6
-7
platforms/cuda/src/kernels/langevin.cu
platforms/cuda/src/kernels/langevin.cu
+4
-4
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+5
-6
platforms/opencl/src/kernels/langevin.cl
platforms/opencl/src/kernels/langevin.cl
+4
-4
platforms/reference/include/ReferenceStochasticDynamics.h
platforms/reference/include/ReferenceStochasticDynamics.h
+6
-8
platforms/reference/include/ReferenceVariableStochasticDynamics.h
...s/reference/include/ReferenceVariableStochasticDynamics.h
+6
-8
platforms/reference/src/ReferenceKernels.cpp
platforms/reference/src/ReferenceKernels.cpp
+2
-4
platforms/reference/src/SimTKReference/ReferenceStochasticDynamics.cpp
...erence/src/SimTKReference/ReferenceStochasticDynamics.cpp
+12
-25
platforms/reference/src/SimTKReference/ReferenceVariableStochasticDynamics.cpp
...rc/SimTKReference/ReferenceVariableStochasticDynamics.cpp
+12
-25
tests/TestLangevinIntegrator.h
tests/TestLangevinIntegrator.h
+3
-3
tests/TestVariableLangevinIntegrator.h
tests/TestVariableLangevinIntegrator.h
+3
-3
No files found.
platforms/cpu/include/CpuLangevinDynamics.h
View file @
37a87d8a
/* Portions copyright (c) 2013-201
5
Stanford University and Simbios.
/* Portions copyright (c) 2013-201
6
Stanford University and Simbios.
* Authors: Peter Eastman
* Authors: Peter Eastman
* Contributors:
* Contributors:
*
*
...
@@ -43,12 +43,12 @@ public:
...
@@ -43,12 +43,12 @@ public:
*
*
* @param numberOfAtoms number of atoms
* @param numberOfAtoms number of atoms
* @param deltaT delta t for dynamics
* @param deltaT delta t for dynamics
* @param
tau viscosity
* @param
friction friction coefficient
* @param temperature temperature
* @param temperature temperature
* @param threads thread pool for parallelizing computation
* @param threads thread pool for parallelizing computation
* @param random random number generator
* @param random random number generator
*/
*/
CpuLangevinDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
tau
,
RealOpenMM
temperature
,
OpenMM
::
ThreadPool
&
threads
,
OpenMM
::
CpuRandom
&
random
);
CpuLangevinDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
friction
,
RealOpenMM
temperature
,
OpenMM
::
ThreadPool
&
threads
,
OpenMM
::
CpuRandom
&
random
);
/**
/**
* Destructor.
* Destructor.
...
...
platforms/cpu/src/CpuKernels.cpp
View file @
37a87d8a
...
@@ -1285,8 +1285,7 @@ void CpuIntegrateLangevinStepKernel::execute(ContextImpl& context, const Langevi
...
@@ -1285,8 +1285,7 @@ void CpuIntegrateLangevinStepKernel::execute(ContextImpl& context, const Langevi
if
(
dynamics
)
if
(
dynamics
)
delete
dynamics
;
delete
dynamics
;
RealOpenMM
tau
=
(
friction
==
0.0
?
0.0
:
1.0
/
friction
);
dynamics
=
new
CpuLangevinDynamics
(
context
.
getSystem
().
getNumParticles
(),
stepSize
,
friction
,
temperature
,
data
.
threads
,
data
.
random
);
dynamics
=
new
CpuLangevinDynamics
(
context
.
getSystem
().
getNumParticles
(),
stepSize
,
tau
,
temperature
,
data
.
threads
,
data
.
random
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractConstraints
(
context
));
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractConstraints
(
context
));
prevTemp
=
temperature
;
prevTemp
=
temperature
;
prevFriction
=
friction
;
prevFriction
=
friction
;
...
...
platforms/cpu/src/CpuLangevinDynamics.cpp
View file @
37a87d8a
/* Portions copyright (c) 2006-201
5
Stanford University and Simbios.
/* Portions copyright (c) 2006-201
6
Stanford University and Simbios.
* Authors: Peter Eastman
* Authors: Peter Eastman
* Contributors:
* Contributors:
*
*
...
@@ -59,8 +59,8 @@ public:
...
@@ -59,8 +59,8 @@ public:
CpuLangevinDynamics
&
owner
;
CpuLangevinDynamics
&
owner
;
};
};
CpuLangevinDynamics
::
CpuLangevinDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
tau
,
RealOpenMM
temperature
,
ThreadPool
&
threads
,
CpuRandom
&
random
)
:
CpuLangevinDynamics
::
CpuLangevinDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
friction
,
RealOpenMM
temperature
,
ThreadPool
&
threads
,
CpuRandom
&
random
)
:
ReferenceStochasticDynamics
(
numberOfAtoms
,
deltaT
,
tau
,
temperature
),
threads
(
threads
),
random
(
random
)
{
ReferenceStochasticDynamics
(
numberOfAtoms
,
deltaT
,
friction
,
temperature
),
threads
(
threads
),
random
(
random
)
{
}
}
CpuLangevinDynamics
::~
CpuLangevinDynamics
()
{
CpuLangevinDynamics
::~
CpuLangevinDynamics
()
{
...
@@ -120,11 +120,12 @@ void CpuLangevinDynamics::updatePart3(int numberOfAtoms, vector<RealVec>& atomCo
...
@@ -120,11 +120,12 @@ void CpuLangevinDynamics::updatePart3(int numberOfAtoms, vector<RealVec>& atomCo
}
}
void
CpuLangevinDynamics
::
threadUpdate1
(
int
threadIndex
)
{
void
CpuLangevinDynamics
::
threadUpdate1
(
int
threadIndex
)
{
const
RealOpenMM
tau
=
getTau
();
RealOpenMM
dt
=
getDeltaT
();
const
RealOpenMM
vscale
=
EXP
(
-
getDeltaT
()
/
tau
);
RealOpenMM
friction
=
getFriction
();
const
RealOpenMM
fscale
=
(
1
-
vscale
)
*
tau
;
const
RealOpenMM
vscale
=
EXP
(
-
dt
*
friction
);
const
RealOpenMM
fscale
=
(
friction
==
0
?
dt
:
(
1
-
vscale
)
/
friction
);
const
RealOpenMM
kT
=
BOLTZ
*
getTemperature
();
const
RealOpenMM
kT
=
BOLTZ
*
getTemperature
();
const
RealOpenMM
noisescale
=
SQRT
(
2
*
kT
/
tau
)
*
SQRT
(
0.5
*
(
1
-
vscale
*
vscale
)
*
tau
);
const
RealOpenMM
noisescale
=
SQRT
(
kT
*
(
1
-
vscale
*
vscale
));
int
start
=
threadIndex
*
numberOfAtoms
/
threads
.
getNumThreads
();
int
start
=
threadIndex
*
numberOfAtoms
/
threads
.
getNumThreads
();
int
end
=
(
threadIndex
+
1
)
*
numberOfAtoms
/
threads
.
getNumThreads
();
int
end
=
(
threadIndex
+
1
)
*
numberOfAtoms
/
threads
.
getNumThreads
();
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
37a87d8a
...
@@ -6497,11 +6497,10 @@ void CudaIntegrateLangevinStepKernel::execute(ContextImpl& context, const Langev
...
@@ -6497,11 +6497,10 @@ void CudaIntegrateLangevinStepKernel::execute(ContextImpl& context, const Langev
if (temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
if (temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
// Calculate the integration parameters.
// Calculate the integration parameters.
double tau = (friction == 0.0 ? 0.0 : 1.0/friction);
double kT = BOLTZ*temperature;
double kT = BOLTZ*temperature;
double vscale = exp(-stepSize
/tau
);
double vscale = exp(-stepSize
*friction
);
double fscale = (
1-vscale)*tau
;
double fscale = (
friction == 0 ? stepSize : (1-vscale)/friction)
;
double noisescale = sqrt(
2*kT/tau)*sqrt(0.5
*(1-vscale*vscale)
*tau
);
double noisescale = sqrt(
kT
*(1-vscale*vscale));
if (cu.getUseDoublePrecision() || cu.getUseMixedPrecision()) {
if (cu.getUseDoublePrecision() || cu.getUseMixedPrecision()) {
vector<double> p(params->getSize());
vector<double> p(params->getSize());
p[0] = vscale;
p[0] = vscale;
...
@@ -6719,14 +6718,14 @@ double CudaIntegrateVariableLangevinStepKernel::execute(ContextImpl& context, co
...
@@ -6719,14 +6718,14 @@ double CudaIntegrateVariableLangevinStepKernel::execute(ContextImpl& context, co
float maxStepSizeFloat = (float) maxStepSize;
float maxStepSizeFloat = (float) maxStepSize;
double tol = integrator.getErrorTolerance();
double tol = integrator.getErrorTolerance();
float tolFloat = (float) tol;
float tolFloat = (float) tol;
double
tau = integrator.getFriction() == 0.0 ? 0.0 : 1.0/
integrator.getFriction();
double
friction =
integrator.getFriction();
float
tau
Float = (float)
tau
;
float
friction
Float = (float)
friction
;
double kT = BOLTZ*integrator.getTemperature();
double kT = BOLTZ*integrator.getTemperature();
float kTFloat = (float) kT;
float kTFloat = (float) kT;
bool useDouble = cu.getUseDoublePrecision() || cu.getUseMixedPrecision();
bool useDouble = cu.getUseDoublePrecision() || cu.getUseMixedPrecision();
void* argsSelect[] = {&numAtoms, &paddedNumAtoms, useDouble ? (void*) &maxStepSize : (void*) &maxStepSizeFloat,
void* argsSelect[] = {&numAtoms, &paddedNumAtoms, useDouble ? (void*) &maxStepSize : (void*) &maxStepSizeFloat,
useDouble ? (void*) &tol : (void*) &tolFloat,
useDouble ? (void*) &tol : (void*) &tolFloat,
useDouble ? (void*) &
tau
: (void*) &
tau
Float,
useDouble ? (void*) &
friction
: (void*) &
friction
Float,
useDouble ? (void*) &kT : (void*) &kTFloat,
useDouble ? (void*) &kT : (void*) &kTFloat,
&cu.getIntegrationUtilities().getStepSize().getDevicePointer(),
&cu.getIntegrationUtilities().getStepSize().getDevicePointer(),
&cu.getVelm().getDevicePointer(), &cu.getForce().getDevicePointer(), ¶ms->getDevicePointer()};
&cu.getVelm().getDevicePointer(), &cu.getForce().getDevicePointer(), ¶ms->getDevicePointer()};
...
...
platforms/cuda/src/kernels/langevin.cu
View file @
37a87d8a
...
@@ -78,7 +78,7 @@ extern "C" __global__ void integrateLangevinPart2(int numAtoms, real4* __restric
...
@@ -78,7 +78,7 @@ extern "C" __global__ void integrateLangevinPart2(int numAtoms, real4* __restric
* Select the step size to use for the next step.
* Select the step size to use for the next step.
*/
*/
extern
"C"
__global__
void
selectLangevinStepSize
(
int
numAtoms
,
int
paddedNumAtoms
,
mixed
maxStepSize
,
mixed
errorTol
,
mixed
tau
,
mixed
kT
,
mixed2
*
__restrict__
dt
,
extern
"C"
__global__
void
selectLangevinStepSize
(
int
numAtoms
,
int
paddedNumAtoms
,
mixed
maxStepSize
,
mixed
errorTol
,
mixed
friction
,
mixed
kT
,
mixed2
*
__restrict__
dt
,
const
mixed4
*
__restrict__
velm
,
const
long
long
*
__restrict__
force
,
mixed
*
__restrict__
paramBuffer
)
{
const
mixed4
*
__restrict__
velm
,
const
long
long
*
__restrict__
force
,
mixed
*
__restrict__
paramBuffer
)
{
// Calculate the error.
// Calculate the error.
...
@@ -119,9 +119,9 @@ extern "C" __global__ void selectLangevinStepSize(int numAtoms, int paddedNumAto
...
@@ -119,9 +119,9 @@ extern "C" __global__ void selectLangevinStepSize(int numAtoms, int paddedNumAto
// Recalculate the integration parameters.
// Recalculate the integration parameters.
mixed
vscale
=
EXP
(
-
newStepSize
/
tau
);
mixed
vscale
=
EXP
(
-
newStepSize
*
friction
);
mixed
fscale
=
(
1
-
vscale
)
*
tau
;
mixed
fscale
=
(
friction
==
0
?
newStepSize
:
(
1
-
vscale
)
/
friction
)
;
mixed
noisescale
=
SQRT
(
2
*
kT
/
tau
)
*
SQRT
(
0.5
f
*
(
1
-
vscale
*
vscale
)
*
tau
);
mixed
noisescale
=
SQRT
(
kT
*
(
1
-
vscale
*
vscale
));
params
[
VelScale
]
=
vscale
;
params
[
VelScale
]
=
vscale
;
params
[
ForceScale
]
=
fscale
;
params
[
ForceScale
]
=
fscale
;
params
[
NoiseScale
]
=
noisescale
;
params
[
NoiseScale
]
=
noisescale
;
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
37a87d8a
...
@@ -6733,11 +6733,10 @@ void OpenCLIntegrateLangevinStepKernel::execute(ContextImpl& context, const Lang
...
@@ -6733,11 +6733,10 @@ void OpenCLIntegrateLangevinStepKernel::execute(ContextImpl& context, const Lang
if (temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
if (temperature != prevTemp || friction != prevFriction || stepSize != prevStepSize) {
// Calculate the integration parameters.
// Calculate the integration parameters.
double tau = (friction == 0.0 ? 0.0 : 1.0/friction);
double kT = BOLTZ*temperature;
double kT = BOLTZ*temperature;
double vscale = exp(-stepSize
/tau
);
double vscale = exp(-stepSize
*friction
);
double fscale = (
1-vscale)*tau
;
double fscale = (
friction == 0 ? stepSize : (1-vscale)/friction)
;
double noisescale = sqrt(
2*kT/tau)*sqrt(0.5
*(1-vscale*vscale)
*tau
);
double noisescale = sqrt(
kT
*(1-vscale*vscale));
if (cl.getUseDoublePrecision() || cl.getUseMixedPrecision()) {
if (cl.getUseDoublePrecision() || cl.getUseMixedPrecision()) {
vector<cl_double> p(params->getSize());
vector<cl_double> p(params->getSize());
p[0] = vscale;
p[0] = vscale;
...
@@ -7015,13 +7014,13 @@ double OpenCLIntegrateVariableLangevinStepKernel::execute(ContextImpl& context,
...
@@ -7015,13 +7014,13 @@ double OpenCLIntegrateVariableLangevinStepKernel::execute(ContextImpl& context,
if (useDouble) {
if (useDouble) {
selectSizeKernel.setArg<cl_double>(0, maxStepSize);
selectSizeKernel.setArg<cl_double>(0, maxStepSize);
selectSizeKernel.setArg<cl_double>(1, integrator.getErrorTolerance());
selectSizeKernel.setArg<cl_double>(1, integrator.getErrorTolerance());
selectSizeKernel.setArg<cl_double>(2, integrator.getFriction()
== 0.0 ? 0.0 : 1.0/integrator.getFriction()
);
selectSizeKernel.setArg<cl_double>(2, integrator.getFriction());
selectSizeKernel.setArg<cl_double>(3, BOLTZ*integrator.getTemperature());
selectSizeKernel.setArg<cl_double>(3, BOLTZ*integrator.getTemperature());
}
}
else {
else {
selectSizeKernel.setArg<cl_float>(0, maxStepSizeFloat);
selectSizeKernel.setArg<cl_float>(0, maxStepSizeFloat);
selectSizeKernel.setArg<cl_float>(1, (cl_float) integrator.getErrorTolerance());
selectSizeKernel.setArg<cl_float>(1, (cl_float) integrator.getErrorTolerance());
selectSizeKernel.setArg<cl_float>(2, (cl_float)
(
integrator.getFriction()
== 0.0 ? 0.0 : 1.0/integrator.getFriction())
);
selectSizeKernel.setArg<cl_float>(2, (cl_float) integrator.getFriction());
selectSizeKernel.setArg<cl_float>(3, (cl_float) (BOLTZ*integrator.getTemperature()));
selectSizeKernel.setArg<cl_float>(3, (cl_float) (BOLTZ*integrator.getTemperature()));
}
}
cl.executeKernel(selectSizeKernel, blockSize, blockSize);
cl.executeKernel(selectSizeKernel, blockSize, blockSize);
...
...
platforms/opencl/src/kernels/langevin.cl
View file @
37a87d8a
...
@@ -72,7 +72,7 @@ __kernel void integrateLangevinPart2(__global real4* restrict posq, __global rea
...
@@ -72,7 +72,7 @@ __kernel void integrateLangevinPart2(__global real4* restrict posq, __global rea
*
Select
the
step
size
to
use
for
the
next
step.
*
Select
the
step
size
to
use
for
the
next
step.
*/
*/
__kernel
void
selectLangevinStepSize
(
mixed
maxStepSize,
mixed
errorTol,
mixed
tau
,
mixed
kT,
__global
mixed2*
restrict
dt,
__kernel
void
selectLangevinStepSize
(
mixed
maxStepSize,
mixed
errorTol,
mixed
friction
,
mixed
kT,
__global
mixed2*
restrict
dt,
__global
const
mixed4*
restrict
velm,
__global
const
real4*
restrict
force,
__global
mixed*
restrict
paramBuffer,
__local
mixed*
restrict
params,
__local
mixed*
restrict
error
)
{
__global
const
mixed4*
restrict
velm,
__global
const
real4*
restrict
force,
__global
mixed*
restrict
paramBuffer,
__local
mixed*
restrict
params,
__local
mixed*
restrict
error
)
{
//
Calculate
the
error.
//
Calculate
the
error.
...
@@ -110,9 +110,9 @@ __kernel void selectLangevinStepSize(mixed maxStepSize, mixed errorTol, mixed ta
...
@@ -110,9 +110,9 @@ __kernel void selectLangevinStepSize(mixed maxStepSize, mixed errorTol, mixed ta
//
Recalculate
the
integration
parameters.
//
Recalculate
the
integration
parameters.
mixed
vscale
=
exp
(
-newStepSize
/tau
)
;
mixed
vscale
=
EXP
(
-newStepSize
*friction
)
;
mixed
fscale
=
(
1-vscale
)
*tau
;
mixed
fscale
=
(
friction
==
0
?
newStepSize
:
(
1-vscale
)
/friction
)
;
mixed
noisescale
=
sqrt
(
2*kT/tau
)
*sqrt
(
0.5f
*
(
1-vscale*vscale
)
*tau
)
;
mixed
noisescale
=
SQRT
(
kT
*
(
1-vscale*vscale
))
;
params[VelScale]
=
vscale
;
params[VelScale]
=
vscale
;
params[ForceScale]
=
fscale
;
params[ForceScale]
=
fscale
;
params[NoiseScale]
=
noisescale
;
params[NoiseScale]
=
noisescale
;
...
...
platforms/reference/include/ReferenceStochasticDynamics.h
View file @
37a87d8a
/* Portions copyright (c) 2006-201
2
Stanford University and Simbios.
/* Portions copyright (c) 2006-201
6
Stanford University and Simbios.
* Contributors: Pande Group
* Contributors: Pande Group
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* Permission is hereby granted, free of charge, to any person obtaining
...
@@ -36,7 +36,7 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
...
@@ -36,7 +36,7 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
std
::
vector
<
OpenMM
::
RealVec
>
xPrime
;
std
::
vector
<
OpenMM
::
RealVec
>
xPrime
;
std
::
vector
<
RealOpenMM
>
inverseMasses
;
std
::
vector
<
RealOpenMM
>
inverseMasses
;
RealOpenMM
_tau
;
RealOpenMM
friction
;
public:
public:
...
@@ -46,12 +46,12 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
...
@@ -46,12 +46,12 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
@param numberOfAtoms number of atoms
@param numberOfAtoms number of atoms
@param deltaT delta t for dynamics
@param deltaT delta t for dynamics
@param
tau viscosity
@param
friction friction coefficient
@param temperature temperature
@param temperature temperature
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceStochasticDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
tau
,
RealOpenMM
temperature
);
ReferenceStochasticDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
friction
,
RealOpenMM
temperature
);
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -63,13 +63,11 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
...
@@ -63,13 +63,11 @@ class OPENMM_EXPORT ReferenceStochasticDynamics : public ReferenceDynamics {
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
Get tau
Get friction coefficient
@return tau
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
RealOpenMM
get
Tau
()
const
;
RealOpenMM
get
Friction
()
const
;
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
...
platforms/reference/include/ReferenceVariableStochasticDynamics.h
View file @
37a87d8a
/* Portions copyright (c) 2006-201
2
Stanford University and Simbios.
/* Portions copyright (c) 2006-201
6
Stanford University and Simbios.
* Contributors: Pande Group
* Contributors: Pande Group
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* Permission is hereby granted, free of charge, to any person obtaining
...
@@ -35,7 +35,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
...
@@ -35,7 +35,7 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
std
::
vector
<
OpenMM
::
RealVec
>
xPrime
;
std
::
vector
<
OpenMM
::
RealVec
>
xPrime
;
std
::
vector
<
RealOpenMM
>
inverseMasses
;
std
::
vector
<
RealOpenMM
>
inverseMasses
;
RealOpenMM
_tau
,
_accuracy
;
RealOpenMM
friction
,
_accuracy
;
public:
public:
...
@@ -44,13 +44,13 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
...
@@ -44,13 +44,13 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
Constructor
Constructor
@param numberOfAtoms number of atoms
@param numberOfAtoms number of atoms
@param
tau viscosity
@param
friction friction coefficient
@param temperature temperature
@param temperature temperature
@param accuracy required accuracy
@param accuracy required accuracy
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceVariableStochasticDynamics
(
int
numberOfAtoms
,
RealOpenMM
tau
,
RealOpenMM
temperature
,
RealOpenMM
accuracy
);
ReferenceVariableStochasticDynamics
(
int
numberOfAtoms
,
RealOpenMM
friction
,
RealOpenMM
temperature
,
RealOpenMM
accuracy
);
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -62,13 +62,11 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
...
@@ -62,13 +62,11 @@ class ReferenceVariableStochasticDynamics : public ReferenceDynamics {
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
Get tau
Get friction coefficient
@return tau
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
RealOpenMM
get
Tau
()
const
;
RealOpenMM
get
Friction
()
const
;
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
...
platforms/reference/src/ReferenceKernels.cpp
View file @
37a87d8a
...
@@ -2053,11 +2053,10 @@ void ReferenceIntegrateLangevinStepKernel::execute(ContextImpl& context, const L
...
@@ -2053,11 +2053,10 @@ void ReferenceIntegrateLangevinStepKernel::execute(ContextImpl& context, const L
if
(
dynamics
)
if
(
dynamics
)
delete
dynamics
;
delete
dynamics
;
RealOpenMM
tau
=
static_cast
<
RealOpenMM
>
(
friction
==
0.0
?
0.0
:
1.0
/
friction
);
dynamics
=
new
ReferenceStochasticDynamics
(
dynamics
=
new
ReferenceStochasticDynamics
(
context
.
getSystem
().
getNumParticles
(),
context
.
getSystem
().
getNumParticles
(),
static_cast
<
RealOpenMM
>
(
stepSize
),
static_cast
<
RealOpenMM
>
(
stepSize
),
static_cast
<
RealOpenMM
>
(
tau
),
static_cast
<
RealOpenMM
>
(
friction
),
static_cast
<
RealOpenMM
>
(
temperature
));
static_cast
<
RealOpenMM
>
(
temperature
));
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractConstraints
(
context
));
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractConstraints
(
context
));
prevTemp
=
temperature
;
prevTemp
=
temperature
;
...
@@ -2142,8 +2141,7 @@ double ReferenceIntegrateVariableLangevinStepKernel::execute(ContextImpl& contex
...
@@ -2142,8 +2141,7 @@ double ReferenceIntegrateVariableLangevinStepKernel::execute(ContextImpl& contex
if
(
dynamics
)
if
(
dynamics
)
delete
dynamics
;
delete
dynamics
;
RealOpenMM
tau
=
static_cast
<
RealOpenMM
>
(
friction
==
0.0
?
0.0
:
1.0
/
friction
);
dynamics
=
new
ReferenceVariableStochasticDynamics
(
context
.
getSystem
().
getNumParticles
(),
(
RealOpenMM
)
friction
,
(
RealOpenMM
)
temperature
,
(
RealOpenMM
)
errorTol
);
dynamics
=
new
ReferenceVariableStochasticDynamics
(
context
.
getSystem
().
getNumParticles
(),
(
RealOpenMM
)
tau
,
(
RealOpenMM
)
temperature
,
(
RealOpenMM
)
errorTol
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractConstraints
(
context
));
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractConstraints
(
context
));
prevTemp
=
temperature
;
prevTemp
=
temperature
;
prevFriction
=
friction
;
prevFriction
=
friction
;
...
...
platforms/reference/src/SimTKReference/ReferenceStochasticDynamics.cpp
View file @
37a87d8a
/* Portions copyright (c) 2006-201
3
Stanford University and Simbios.
/* Portions copyright (c) 2006-201
6
Stanford University and Simbios.
* Contributors: Pande Group
* Contributors: Pande Group
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* Permission is hereby granted, free of charge, to any person obtaining
...
@@ -41,20 +41,15 @@ using namespace OpenMM;
...
@@ -41,20 +41,15 @@ using namespace OpenMM;
@param numberOfAtoms number of atoms
@param numberOfAtoms number of atoms
@param deltaT delta t for dynamics
@param deltaT delta t for dynamics
@param
tau viscosity(?)
@param
friction friction coefficient
@param temperature temperature
@param temperature temperature
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceStochasticDynamics
::
ReferenceStochasticDynamics
(
int
numberOfAtoms
,
ReferenceStochasticDynamics
::
ReferenceStochasticDynamics
(
int
numberOfAtoms
,
RealOpenMM
deltaT
,
RealOpenMM
tau
,
RealOpenMM
deltaT
,
RealOpenMM
friction
,
RealOpenMM
temperature
)
:
RealOpenMM
temperature
)
:
ReferenceDynamics
(
numberOfAtoms
,
deltaT
,
temperature
),
_tau
(
tau
)
{
ReferenceDynamics
(
numberOfAtoms
,
deltaT
,
temperature
),
friction
(
friction
)
{
if
(
tau
<=
0
)
{
std
::
stringstream
message
;
message
<<
"illegal tau value: "
<<
tau
;
throw
OpenMMException
(
message
.
str
());
}
xPrime
.
resize
(
numberOfAtoms
);
xPrime
.
resize
(
numberOfAtoms
);
inverseMasses
.
resize
(
numberOfAtoms
);
inverseMasses
.
resize
(
numberOfAtoms
);
}
}
...
@@ -77,21 +72,12 @@ ReferenceStochasticDynamics::~ReferenceStochasticDynamics() {
...
@@ -77,21 +72,12 @@ ReferenceStochasticDynamics::~ReferenceStochasticDynamics() {
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
Get tau
Get friction coefficient
@return tau
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
RealOpenMM
ReferenceStochasticDynamics
::
getTau
()
const
{
RealOpenMM
ReferenceStochasticDynamics
::
getFriction
()
const
{
return
friction
;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceStochasticDynamics::getTau";
// ---------------------------------------------------------------------------------------
return
_tau
;
}
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -120,11 +106,12 @@ void ReferenceStochasticDynamics::updatePart1(int numberOfAtoms, vector<RealVec>
...
@@ -120,11 +106,12 @@ void ReferenceStochasticDynamics::updatePart1(int numberOfAtoms, vector<RealVec>
// perform first update
// perform first update
RealOpenMM
tau
=
getTau
();
RealOpenMM
dt
=
getDeltaT
();
const
RealOpenMM
vscale
=
EXP
(
-
getDeltaT
()
/
tau
);
RealOpenMM
friction
=
getFriction
();
const
RealOpenMM
fscale
=
(
1
-
vscale
)
*
tau
;
const
RealOpenMM
vscale
=
EXP
(
-
dt
*
friction
);
const
RealOpenMM
fscale
=
(
friction
==
0
?
dt
:
(
1
-
vscale
)
/
friction
);
const
RealOpenMM
kT
=
BOLTZ
*
getTemperature
();
const
RealOpenMM
kT
=
BOLTZ
*
getTemperature
();
const
RealOpenMM
noisescale
=
SQRT
(
2
*
kT
/
tau
)
*
SQRT
(
0.5
*
(
1
-
vscale
*
vscale
)
*
tau
);
const
RealOpenMM
noisescale
=
SQRT
(
kT
*
(
1
-
vscale
*
vscale
));
for
(
int
ii
=
0
;
ii
<
numberOfAtoms
;
ii
++
)
{
for
(
int
ii
=
0
;
ii
<
numberOfAtoms
;
ii
++
)
{
if
(
inverseMasses
[
ii
]
!=
0.0
)
{
if
(
inverseMasses
[
ii
]
!=
0.0
)
{
...
...
platforms/reference/src/SimTKReference/ReferenceVariableStochasticDynamics.cpp
View file @
37a87d8a
/* Portions copyright (c) 2006-201
3
Stanford University and Simbios.
/* Portions copyright (c) 2006-201
6
Stanford University and Simbios.
* Contributors: Pande Group
* Contributors: Pande Group
*
*
* Permission is hereby granted, free of charge, to any person obtaining
* Permission is hereby granted, free of charge, to any person obtaining
...
@@ -42,21 +42,16 @@ using namespace OpenMM;
...
@@ -42,21 +42,16 @@ using namespace OpenMM;
@param numberOfAtoms number of atoms
@param numberOfAtoms number of atoms
@param deltaT delta t for dynamics
@param deltaT delta t for dynamics
@param
tau viscosity(?)
@param
friction friction coefficient
@param temperature temperature
@param temperature temperature
@param accuracy required accuracy
@param accuracy required accuracy
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
ReferenceVariableStochasticDynamics
::
ReferenceVariableStochasticDynamics
(
int
numberOfAtoms
,
ReferenceVariableStochasticDynamics
::
ReferenceVariableStochasticDynamics
(
int
numberOfAtoms
,
RealOpenMM
tau
,
RealOpenMM
temperature
,
RealOpenMM
friction
,
RealOpenMM
temperature
,
RealOpenMM
accuracy
)
:
RealOpenMM
accuracy
)
:
ReferenceDynamics
(
numberOfAtoms
,
0.0
f
,
temperature
),
_tau
(
tau
),
_accuracy
(
accuracy
)
{
ReferenceDynamics
(
numberOfAtoms
,
0.0
f
,
temperature
),
friction
(
friction
),
_accuracy
(
accuracy
)
{
if
(
tau
<=
0
)
{
std
::
stringstream
message
;
message
<<
"illegal tau value: "
<<
tau
;
throw
OpenMMException
(
message
.
str
());
}
xPrime
.
resize
(
numberOfAtoms
);
xPrime
.
resize
(
numberOfAtoms
);
inverseMasses
.
resize
(
numberOfAtoms
);
inverseMasses
.
resize
(
numberOfAtoms
);
}
}
...
@@ -101,21 +96,12 @@ void ReferenceVariableStochasticDynamics::setAccuracy(RealOpenMM accuracy) {
...
@@ -101,21 +96,12 @@ void ReferenceVariableStochasticDynamics::setAccuracy(RealOpenMM accuracy) {
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
Get tau
Get friction coefficient
@return tau
--------------------------------------------------------------------------------------- */
--------------------------------------------------------------------------------------- */
RealOpenMM
ReferenceVariableStochasticDynamics
::
getTau
()
const
{
RealOpenMM
ReferenceVariableStochasticDynamics
::
getFriction
()
const
{
return
friction
;
// ---------------------------------------------------------------------------------------
// static const char* methodName = "\nReferenceVariableStochasticDynamics::getTau";
// ---------------------------------------------------------------------------------------
return
_tau
;
}
}
/**---------------------------------------------------------------------------------------
/**---------------------------------------------------------------------------------------
...
@@ -178,11 +164,12 @@ void ReferenceVariableStochasticDynamics::updatePart1(int numberOfAtoms, vector<
...
@@ -178,11 +164,12 @@ void ReferenceVariableStochasticDynamics::updatePart1(int numberOfAtoms, vector<
// perform first update
// perform first update
RealOpenMM
tau
=
getTau
();
RealOpenMM
dt
=
getDeltaT
();
const
RealOpenMM
vscale
=
EXP
(
-
getDeltaT
()
/
tau
);
RealOpenMM
friction
=
getFriction
();
const
RealOpenMM
fscale
=
(
1
-
vscale
)
*
tau
;
const
RealOpenMM
vscale
=
EXP
(
-
dt
*
friction
);
const
RealOpenMM
fscale
=
(
friction
==
0
?
dt
:
(
1
-
vscale
)
/
friction
);
const
RealOpenMM
kT
=
BOLTZ
*
getTemperature
();
const
RealOpenMM
kT
=
BOLTZ
*
getTemperature
();
const
RealOpenMM
noisescale
=
SQRT
(
2
*
kT
/
tau
)
*
SQRT
(
0.5
*
(
1
-
vscale
*
vscale
)
*
tau
);
const
RealOpenMM
noisescale
=
SQRT
(
kT
*
(
1
-
vscale
*
vscale
));
for
(
int
ii
=
0
;
ii
<
numberOfAtoms
;
ii
++
)
{
for
(
int
ii
=
0
;
ii
<
numberOfAtoms
;
ii
++
)
{
if
(
masses
[
ii
]
!=
0
)
{
if
(
masses
[
ii
]
!=
0
)
{
...
...
tests/TestLangevinIntegrator.h
View file @
37a87d8a
...
@@ -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
5
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
6
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -74,9 +74,9 @@ void testSingleBond() {
...
@@ -74,9 +74,9 @@ void testSingleBond() {
integrator
.
step
(
1
);
integrator
.
step
(
1
);
}
}
// No
t
set the friction to
a tiny value
and see if it conserves energy.
// No
w
set the friction to
0
and see if it conserves energy.
integrator
.
setFriction
(
5e-5
);
integrator
.
setFriction
(
0.0
);
context
.
setPositions
(
positions
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Energy
);
State
state
=
context
.
getState
(
State
::
Energy
);
double
initialEnergy
=
state
.
getKineticEnergy
()
+
state
.
getPotentialEnergy
();
double
initialEnergy
=
state
.
getKineticEnergy
()
+
state
.
getPotentialEnergy
();
...
...
tests/TestVariableLangevinIntegrator.h
View file @
37a87d8a
...
@@ -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
5
Stanford University and the Authors. *
* Portions copyright (c) 2008-201
6
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Authors: Peter Eastman *
* Contributors: *
* Contributors: *
* *
* *
...
@@ -74,9 +74,9 @@ void testSingleBond() {
...
@@ -74,9 +74,9 @@ void testSingleBond() {
integrator
.
step
(
1
);
integrator
.
step
(
1
);
}
}
// Now set the friction to
a tiny value
and see if it conserves energy.
// Now set the friction to
0
and see if it conserves energy.
integrator
.
setFriction
(
5e-5
);
integrator
.
setFriction
(
0.0
);
context
.
setPositions
(
positions
);
context
.
setPositions
(
positions
);
State
state
=
context
.
getState
(
State
::
Energy
);
State
state
=
context
.
getState
(
State
::
Energy
);
double
initialEnergy
=
state
.
getKineticEnergy
()
+
state
.
getPotentialEnergy
();
double
initialEnergy
=
state
.
getKineticEnergy
()
+
state
.
getPotentialEnergy
();
...
...
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