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
5a06df78
Commit
5a06df78
authored
Mar 04, 2020
by
tic20
Browse files
Merge
https://github.com/openmm/openmm
parents
8dd60914
a9223eea
Changes
335
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
1055 additions
and
91 deletions
+1055
-91
platforms/reference/src/ReferenceKernelFactory.cpp
platforms/reference/src/ReferenceKernelFactory.cpp
+6
-2
platforms/reference/src/ReferenceKernels.cpp
platforms/reference/src/ReferenceKernels.cpp
+282
-10
platforms/reference/src/ReferencePlatform.cpp
platforms/reference/src/ReferencePlatform.cpp
+7
-1
platforms/reference/src/SimTKReference/ReferenceLJCoulomb14.cpp
...rms/reference/src/SimTKReference/ReferenceLJCoulomb14.cpp
+32
-22
platforms/reference/src/SimTKReference/ReferenceLangevinMiddleDynamics.cpp
...ce/src/SimTKReference/ReferenceLangevinMiddleDynamics.cpp
+22
-43
platforms/reference/src/SimTKReference/ReferenceNoseHooverChain.cpp
...reference/src/SimTKReference/ReferenceNoseHooverChain.cpp
+95
-0
platforms/reference/src/SimTKReference/ReferenceVelocityVerletDynamics.cpp
...ce/src/SimTKReference/ReferenceVelocityVerletDynamics.cpp
+262
-0
platforms/reference/tests/TestReferenceLangevinMiddleIntegrator.cpp
...reference/tests/TestReferenceLangevinMiddleIntegrator.cpp
+1
-1
platforms/reference/tests/TestReferenceNoseHooverIntegrator.cpp
...rms/reference/tests/TestReferenceNoseHooverIntegrator.cpp
+36
-0
platforms/reference/tests/TestReferenceNoseHooverThermostat.cpp
...rms/reference/tests/TestReferenceNoseHooverThermostat.cpp
+36
-0
plugins/amoeba/platforms/cuda/CMakeLists.txt
plugins/amoeba/platforms/cuda/CMakeLists.txt
+10
-9
plugins/amoeba/platforms/cuda/src/CudaAmoebaKernelSources.h.in
...ns/amoeba/platforms/cuda/src/CudaAmoebaKernelSources.h.in
+1
-1
plugins/cudacompiler/CMakeLists.txt
plugins/cudacompiler/CMakeLists.txt
+1
-0
plugins/drude/CMakeLists.txt
plugins/drude/CMakeLists.txt
+1
-0
plugins/drude/openmmapi/include/OpenMMDrude.h
plugins/drude/openmmapi/include/OpenMMDrude.h
+1
-0
plugins/drude/openmmapi/include/openmm/DrudeNoseHooverIntegrator.h
...rude/openmmapi/include/openmm/DrudeNoseHooverIntegrator.h
+100
-0
plugins/drude/openmmapi/include/openmm/internal/DrudeForceImpl.h
.../drude/openmmapi/include/openmm/internal/DrudeForceImpl.h
+1
-1
plugins/drude/openmmapi/src/DrudeNoseHooverIntegrator.cpp
plugins/drude/openmmapi/src/DrudeNoseHooverIntegrator.cpp
+145
-0
plugins/drude/platforms/common/CMakeLists.txt
plugins/drude/platforms/common/CMakeLists.txt
+15
-0
plugins/drude/platforms/common/src/CommonDrudeKernelSources.cpp.in
...rude/platforms/common/src/CommonDrudeKernelSources.cpp.in
+1
-1
No files found.
platforms/reference/src/ReferenceKernelFactory.cpp
View file @
5a06df78
...
...
@@ -88,10 +88,14 @@ KernelImpl* ReferenceKernelFactory::createKernelImpl(std::string name, const Pla
return
new
ReferenceCalcGayBerneForceKernel
(
name
,
platform
);
if
(
name
==
IntegrateVerletStepKernel
::
Name
())
return
new
ReferenceIntegrateVerletStepKernel
(
name
,
platform
,
data
);
if
(
name
==
IntegrateVelocityVerletStepKernel
::
Name
())
return
new
ReferenceIntegrateVelocityVerletStepKernel
(
name
,
platform
,
data
);
if
(
name
==
NoseHooverChainKernel
::
Name
())
return
new
ReferenceNoseHooverChainKernel
(
name
,
platform
);
if
(
name
==
IntegrateLangevinStepKernel
::
Name
())
return
new
ReferenceIntegrateLangevinStepKernel
(
name
,
platform
,
data
);
if
(
name
==
Integrate
BAOAB
StepKernel
::
Name
())
return
new
ReferenceIntegrate
BAOAB
StepKernel
(
name
,
platform
,
data
);
if
(
name
==
Integrate
LangevinMiddle
StepKernel
::
Name
())
return
new
ReferenceIntegrate
LangevinMiddle
StepKernel
(
name
,
platform
,
data
);
if
(
name
==
IntegrateBrownianStepKernel
::
Name
())
return
new
ReferenceIntegrateBrownianStepKernel
(
name
,
platform
,
data
);
if
(
name
==
IntegrateVariableLangevinStepKernel
::
Name
())
...
...
platforms/reference/src/ReferenceKernels.cpp
View file @
5a06df78
...
...
@@ -6,7 +6,7 @@
* Biological Structures at Stanford, funded under the NIH Roadmap for *
* Medical Research, grant U54 GM072970. See https://simtk.org. *
* *
* Portions copyright (c) 2008-20
19
Stanford University and the Authors. *
* Portions copyright (c) 2008-20
20
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -33,7 +33,6 @@
#include "ReferenceObc.h"
#include "ReferenceAndersenThermostat.h"
#include "ReferenceAngleBondIxn.h"
#include "ReferenceBAOABDynamics.h"
#include "ReferenceBondForce.h"
#include "ReferenceBrownianDynamics.h"
#include "ReferenceCCMAAlgorithm.h"
...
...
@@ -53,9 +52,11 @@
#include "ReferenceCustomTorsionIxn.h"
#include "ReferenceGayBerneForce.h"
#include "ReferenceHarmonicBondIxn.h"
#include "ReferenceLangevinMiddleDynamics.h"
#include "ReferenceLJCoulomb14.h"
#include "ReferenceLJCoulombIxn.h"
#include "ReferenceMonteCarloBarostat.h"
#include "ReferenceNoseHooverChain.h"
#include "ReferenceProperDihedralBond.h"
#include "ReferenceRbDihedralBond.h"
#include "ReferenceRMSDForce.h"
...
...
@@ -63,6 +64,7 @@
#include "ReferenceTabulatedFunction.h"
#include "ReferenceVariableStochasticDynamics.h"
#include "ReferenceVariableVerletDynamics.h"
#include "ReferenceVelocityVerletDynamics.h"
#include "ReferenceVerletDynamics.h"
#include "ReferenceVirtualSites.h"
#include "openmm/CMMotionRemover.h"
...
...
@@ -125,6 +127,15 @@ static map<string, double>& extractEnergyParameterDerivatives(ContextImpl& conte
return
*
data
->
energyParameterDerivatives
;
}
static
vector
<
vector
<
double
>
>&
extractNoseHooverPositions
(
ContextImpl
&
context
)
{
ReferencePlatform
::
PlatformData
*
data
=
reinterpret_cast
<
ReferencePlatform
::
PlatformData
*>
(
context
.
getPlatformData
());
return
*
((
vector
<
vector
<
double
>
>*
)
data
->
noseHooverPositions
);
}
static
vector
<
vector
<
double
>
>&
extractNoseHooverVelocities
(
ContextImpl
&
context
)
{
ReferencePlatform
::
PlatformData
*
data
=
reinterpret_cast
<
ReferencePlatform
::
PlatformData
*>
(
context
.
getPlatformData
());
return
*
((
vector
<
vector
<
double
>
>*
)
data
->
noseHooverVelocities
);
}
/**
* Make sure an expression doesn't use any undefined variables.
*/
...
...
@@ -277,7 +288,7 @@ void ReferenceUpdateStateDataKernel::setPeriodicBoxVectors(ContextImpl& context,
}
void
ReferenceUpdateStateDataKernel
::
createCheckpoint
(
ContextImpl
&
context
,
ostream
&
stream
)
{
int
version
=
2
;
int
version
=
3
;
stream
.
write
((
char
*
)
&
version
,
sizeof
(
int
));
stream
.
write
((
char
*
)
&
data
.
time
,
sizeof
(
data
.
time
));
vector
<
Vec3
>&
posData
=
extractPositions
(
context
);
...
...
@@ -286,13 +297,27 @@ void ReferenceUpdateStateDataKernel::createCheckpoint(ContextImpl& context, ostr
stream
.
write
((
char
*
)
&
velData
[
0
],
sizeof
(
Vec3
)
*
velData
.
size
());
Vec3
*
vectors
=
extractBoxVectors
(
context
);
stream
.
write
((
char
*
)
vectors
,
3
*
sizeof
(
Vec3
));
auto
&
allNoseHooverPositions
=
extractNoseHooverPositions
(
context
);
auto
&
allNoseHooverVelocities
=
extractNoseHooverVelocities
(
context
);
size_t
numChains
=
allNoseHooverPositions
.
size
();
assert
(
numChains
==
allNoseHooverVelocities
.
size
());
stream
.
write
((
char
*
)
&
numChains
,
sizeof
(
size_t
));
for
(
size_t
i
=
0
;
i
<
numChains
;
i
++
){
auto
&
noseHooverPositions
=
allNoseHooverPositions
.
at
(
i
);
auto
&
noseHooverVelocities
=
allNoseHooverVelocities
.
at
(
i
);
size_t
numBeads
=
noseHooverPositions
.
size
();
assert
(
numBeads
==
noseHooverVelocities
.
size
());
stream
.
write
((
char
*
)
&
numBeads
,
sizeof
(
size_t
));
stream
.
write
((
char
*
)
noseHooverPositions
.
data
(),
sizeof
(
double
)
*
numBeads
);
stream
.
write
((
char
*
)
noseHooverVelocities
.
data
(),
sizeof
(
double
)
*
numBeads
);
}
SimTKOpenMMUtilities
::
createCheckpoint
(
stream
);
}
void
ReferenceUpdateStateDataKernel
::
loadCheckpoint
(
ContextImpl
&
context
,
istream
&
stream
)
{
int
version
;
stream
.
read
((
char
*
)
&
version
,
sizeof
(
int
));
if
(
version
!=
2
)
if
(
version
!=
3
)
throw
OpenMMException
(
"Checkpoint was created with a different version of OpenMM"
);
stream
.
read
((
char
*
)
&
data
.
time
,
sizeof
(
data
.
time
));
vector
<
Vec3
>&
posData
=
extractPositions
(
context
);
...
...
@@ -301,6 +326,21 @@ void ReferenceUpdateStateDataKernel::loadCheckpoint(ContextImpl& context, istrea
stream
.
read
((
char
*
)
&
velData
[
0
],
sizeof
(
Vec3
)
*
velData
.
size
());
Vec3
*
vectors
=
extractBoxVectors
(
context
);
stream
.
read
((
char
*
)
vectors
,
3
*
sizeof
(
Vec3
));
size_t
numChains
,
numBeads
;
auto
&
allNoseHooverPositions
=
extractNoseHooverPositions
(
context
);
auto
&
allNoseHooverVelocities
=
extractNoseHooverVelocities
(
context
);
stream
.
read
((
char
*
)
&
numChains
,
sizeof
(
size_t
));
allNoseHooverPositions
.
clear
();
allNoseHooverVelocities
.
clear
();
for
(
size_t
i
=
0
;
i
<
numChains
;
i
++
){
stream
.
read
((
char
*
)
&
numBeads
,
sizeof
(
size_t
));
std
::
vector
<
double
>
noseHooverPositions
(
numBeads
);
std
::
vector
<
double
>
noseHooverVelocities
(
numBeads
);
stream
.
read
((
char
*
)
&
noseHooverPositions
[
0
],
sizeof
(
double
)
*
numBeads
);
stream
.
read
((
char
*
)
&
noseHooverVelocities
[
0
],
sizeof
(
double
)
*
numBeads
);
allNoseHooverPositions
.
push_back
(
noseHooverPositions
);
allNoseHooverVelocities
.
push_back
(
noseHooverVelocities
);
}
SimTKOpenMMUtilities
::
loadCheckpoint
(
stream
);
}
...
...
@@ -951,6 +991,10 @@ void ReferenceCalcNonbondedForceKernel::initialize(const System& system, const N
ewaldDispersionAlpha
=
alpha
;
useSwitchingFunction
=
false
;
}
if
(
nonbondedMethod
==
NoCutoff
||
nonbondedMethod
==
CutoffNonPeriodic
)
exceptionsArePeriodic
=
false
;
else
exceptionsArePeriodic
=
force
.
getExceptionsUsePeriodicBoundaryConditions
();
rfDielectric
=
force
.
getReactionFieldDielectric
();
if
(
force
.
getUseDispersionCorrection
())
dispersionCoefficient
=
NonbondedForceImpl
::
calcDispersionCorrection
(
system
,
force
);
...
...
@@ -993,6 +1037,10 @@ double ReferenceCalcNonbondedForceKernel::execute(ContextImpl& context, bool inc
if
(
includeDirect
)
{
ReferenceBondForce
refBondForce
;
ReferenceLJCoulomb14
nonbonded14
;
if
(
exceptionsArePeriodic
)
{
Vec3
*
boxVectors
=
extractBoxVectors
(
context
);
nonbonded14
.
setPeriodic
(
boxVectors
);
}
refBondForce
.
calculateForce
(
num14
,
bonded14IndexArray
,
posData
,
bonded14ParamArray
,
forceData
,
includeEnergy
?
&
energy
:
NULL
,
nonbonded14
);
if
(
periodic
||
ewald
||
pme
)
{
Vec3
*
boxVectors
=
extractBoxVectors
(
context
);
...
...
@@ -2106,6 +2154,41 @@ double ReferenceIntegrateVerletStepKernel::computeKineticEnergy(ContextImpl& con
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
());
}
ReferenceIntegrateVelocityVerletStepKernel
::~
ReferenceIntegrateVelocityVerletStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
}
void
ReferenceIntegrateVelocityVerletStepKernel
::
initialize
(
const
System
&
system
,
const
NoseHooverIntegrator
&
integrator
)
{
int
numParticles
=
system
.
getNumParticles
();
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
system
.
getParticleMass
(
i
);
}
void
ReferenceIntegrateVelocityVerletStepKernel
::
execute
(
ContextImpl
&
context
,
const
NoseHooverIntegrator
&
integrator
,
bool
&
forcesAreValid
)
{
double
stepSize
=
integrator
.
getStepSize
();
vector
<
Vec3
>&
posData
=
extractPositions
(
context
);
vector
<
Vec3
>&
velData
=
extractVelocities
(
context
);
vector
<
Vec3
>&
forceData
=
extractForces
(
context
);
if
(
dynamics
==
0
||
stepSize
!=
prevStepSize
)
{
// Recreate the computation objects with the new parameters.
if
(
dynamics
)
delete
dynamics
;
dynamics
=
new
ReferenceVelocityVerletDynamics
(
context
.
getSystem
().
getNumParticles
(),
stepSize
);
dynamics
->
setReferenceConstraintAlgorithm
(
&
extractConstraints
(
context
));
prevStepSize
=
stepSize
;
}
dynamics
->
update
(
context
,
context
.
getSystem
(),
posData
,
velData
,
forceData
,
masses
,
integrator
.
getConstraintTolerance
(),
forcesAreValid
,
integrator
.
getAllThermostatedIndividualParticles
(),
integrator
.
getAllThermostatedPairs
(),
integrator
.
getMaximumPairDistance
());
data
.
time
+=
stepSize
;
data
.
stepCount
++
;
}
double
ReferenceIntegrateVelocityVerletStepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
NoseHooverIntegrator
&
integrator
)
{
return
computeShiftedKineticEnergy
(
context
,
masses
,
0
);
}
ReferenceIntegrateLangevinStepKernel
::~
ReferenceIntegrateLangevinStepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
...
...
@@ -2150,12 +2233,12 @@ double ReferenceIntegrateLangevinStepKernel::computeKineticEnergy(ContextImpl& c
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.5
*
integrator
.
getStepSize
());
}
ReferenceIntegrate
BAOAB
StepKernel
::~
ReferenceIntegrate
BAOAB
StepKernel
()
{
ReferenceIntegrate
LangevinMiddle
StepKernel
::~
ReferenceIntegrate
LangevinMiddle
StepKernel
()
{
if
(
dynamics
)
delete
dynamics
;
}
void
ReferenceIntegrate
BAOAB
StepKernel
::
initialize
(
const
System
&
system
,
const
BAOAB
LangevinIntegrator
&
integrator
)
{
void
ReferenceIntegrate
LangevinMiddle
StepKernel
::
initialize
(
const
System
&
system
,
const
Langevin
Middle
Integrator
&
integrator
)
{
int
numParticles
=
system
.
getNumParticles
();
masses
.
resize
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
...
...
@@ -2163,7 +2246,7 @@ void ReferenceIntegrateBAOABStepKernel::initialize(const System& system, const B
SimTKOpenMMUtilities
::
setRandomNumberSeed
((
unsigned
int
)
integrator
.
getRandomNumberSeed
());
}
void
ReferenceIntegrate
BAOAB
StepKernel
::
execute
(
ContextImpl
&
context
,
const
BAOAB
LangevinIntegrator
&
integrator
,
bool
&
forcesAreValid
)
{
void
ReferenceIntegrate
LangevinMiddle
StepKernel
::
execute
(
ContextImpl
&
context
,
const
Langevin
Middle
Integrator
&
integrator
)
{
double
temperature
=
integrator
.
getTemperature
();
double
friction
=
integrator
.
getFriction
();
double
stepSize
=
integrator
.
getStepSize
();
...
...
@@ -2174,7 +2257,7 @@ void ReferenceIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOA
if
(
dynamics
)
delete
dynamics
;
dynamics
=
new
Reference
BAOAB
Dynamics
(
dynamics
=
new
Reference
LangevinMiddle
Dynamics
(
context
.
getSystem
().
getNumParticles
(),
stepSize
,
friction
,
...
...
@@ -2184,12 +2267,12 @@ void ReferenceIntegrateBAOABStepKernel::execute(ContextImpl& context, const BAOA
prevFriction
=
friction
;
prevStepSize
=
stepSize
;
}
dynamics
->
update
(
context
,
posData
,
velData
,
masses
,
forcesAreValid
,
integrator
.
getConstraintTolerance
());
dynamics
->
update
(
context
,
posData
,
velData
,
masses
,
integrator
.
getConstraintTolerance
());
data
.
time
+=
stepSize
;
data
.
stepCount
++
;
}
double
ReferenceIntegrate
BAOAB
StepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
BAOAB
LangevinIntegrator
&
integrator
)
{
double
ReferenceIntegrate
LangevinMiddle
StepKernel
::
computeKineticEnergy
(
ContextImpl
&
context
,
const
Langevin
Middle
Integrator
&
integrator
)
{
return
computeShiftedKineticEnergy
(
context
,
masses
,
0.0
);
}
...
...
@@ -2430,6 +2513,195 @@ void ReferenceApplyAndersenThermostatKernel::execute(ContextImpl& context) {
context
.
getIntegrator
().
getStepSize
());
}
ReferenceNoseHooverChainKernel
::~
ReferenceNoseHooverChainKernel
()
{
if
(
chainPropagator
)
delete
chainPropagator
;
}
void
ReferenceNoseHooverChainKernel
::
initialize
()
{
this
->
chainPropagator
=
new
ReferenceNoseHooverChain
();
//SimTKOpenMMUtilities::setRandomNumberSeed((unsigned int) thermostat.getRandomNumberSeed());
}
std
::
pair
<
double
,
double
>
ReferenceNoseHooverChainKernel
::
propagateChain
(
ContextImpl
&
context
,
const
NoseHooverChain
&
nhc
,
std
::
pair
<
double
,
double
>
kineticEnergy
,
double
timeStep
)
{
double
absKE
=
kineticEnergy
.
first
;
double
relKE
=
kineticEnergy
.
second
;
if
(
absKE
<
1e-8
)
return
{
1.0
,
1.0
};
// (catches the problem of zero velocities in the first dynamics step, where we have nothing to scale)
// Get the variables describing the NHC
int
chainLength
=
nhc
.
getChainLength
();
int
chainID
=
nhc
.
getChainID
();
int
numDOFs
=
nhc
.
getNumDegreesOfFreedom
();
int
numMTS
=
nhc
.
getNumMultiTimeSteps
();
// Get the state of the NHC from the context
auto
&
allChainPositions
=
extractNoseHooverPositions
(
context
);
auto
&
allChainVelocities
=
extractNoseHooverVelocities
(
context
);
int
nAtoms
=
nhc
.
getThermostatedAtoms
().
size
();
double
absScale
=
0
;
if
(
nAtoms
)
{
if
(
allChainPositions
.
size
()
<
2
*
chainID
+
1
){
allChainPositions
.
resize
(
2
*
chainID
+
1
);
}
if
(
allChainVelocities
.
size
()
<
2
*
chainID
+
1
){
allChainVelocities
.
resize
(
2
*
chainID
+
1
);
}
auto
&
chainPositions
=
allChainPositions
.
at
(
2
*
chainID
);
auto
&
chainVelocities
=
allChainVelocities
.
at
(
2
*
chainID
);
if
(
chainPositions
.
size
()
<
chainLength
){
chainPositions
.
resize
(
chainLength
,
0
);
}
if
(
chainVelocities
.
size
()
<
chainLength
){
chainVelocities
.
resize
(
chainLength
,
0
);
}
double
temperature
=
nhc
.
getTemperature
();
double
collisionFrequency
=
nhc
.
getCollisionFrequency
();
absScale
=
chainPropagator
->
propagate
(
absKE
,
chainVelocities
,
chainPositions
,
numDOFs
,
temperature
,
collisionFrequency
,
timeStep
,
numMTS
,
nhc
.
getYoshidaSuzukiWeights
());
}
double
relScale
=
0
;
int
nPairs
=
nhc
.
getThermostatedPairs
().
size
();
if
(
nPairs
)
{
if
(
allChainPositions
.
size
()
<
2
*
chainID
+
2
){
allChainPositions
.
resize
(
2
*
chainID
+
2
);
}
if
(
allChainVelocities
.
size
()
<
2
*
chainID
+
2
){
allChainVelocities
.
resize
(
2
*
chainID
+
2
);
}
auto
&
chainPositions
=
allChainPositions
.
at
(
2
*
chainID
+
1
);
auto
&
chainVelocities
=
allChainVelocities
.
at
(
2
*
chainID
+
1
);
if
(
chainPositions
.
size
()
<
chainLength
){
chainPositions
.
resize
(
chainLength
,
0
);
}
if
(
chainVelocities
.
size
()
<
chainLength
){
chainVelocities
.
resize
(
chainLength
,
0
);
}
double
temperature
=
nhc
.
getRelativeTemperature
();
double
collisionFrequency
=
nhc
.
getRelativeCollisionFrequency
();
relScale
=
chainPropagator
->
propagate
(
relKE
,
chainVelocities
,
chainPositions
,
3
*
nPairs
,
temperature
,
collisionFrequency
,
timeStep
,
numMTS
,
nhc
.
getYoshidaSuzukiWeights
());
}
return
{
absScale
,
relScale
};
}
double
ReferenceNoseHooverChainKernel
::
computeHeatBathEnergy
(
ContextImpl
&
context
,
const
NoseHooverChain
&
nhc
)
{
double
potentialEnergy
=
0
;
double
kineticEnergy
=
0
;
int
chainLength
=
nhc
.
getChainLength
();
int
chainID
=
nhc
.
getChainID
();
int
nAtoms
=
nhc
.
getThermostatedAtoms
().
size
();
int
nPairs
=
nhc
.
getThermostatedPairs
().
size
();
auto
&
nhcPositions
=
extractNoseHooverPositions
(
context
);
auto
&
nhcVelocities
=
extractNoseHooverVelocities
(
context
);
if
(
nAtoms
)
{
double
temperature
=
nhc
.
getTemperature
();
double
collisionFrequency
=
nhc
.
getCollisionFrequency
();
double
kT
=
temperature
*
BOLTZ
;
int
numDOFs
=
nhc
.
getNumDegreesOfFreedom
();
for
(
int
i
=
0
;
i
<
chainLength
;
++
i
)
{
double
prefac
=
i
?
1
:
numDOFs
;
double
mass
=
prefac
*
kT
/
(
collisionFrequency
*
collisionFrequency
);
double
velocity
=
nhcVelocities
[
2
*
chainID
][
i
];
// The kinetic energy of this bead
kineticEnergy
+=
0.5
*
mass
*
velocity
*
velocity
;
// The potential energy of this bead
double
position
=
nhcPositions
[
2
*
chainID
][
i
];
potentialEnergy
+=
prefac
*
kT
*
position
;
}
}
if
(
nPairs
)
{
double
temperature
=
nhc
.
getRelativeTemperature
();
double
collisionFrequency
=
nhc
.
getRelativeCollisionFrequency
();
double
kT
=
temperature
*
BOLTZ
;
int
numDOFs
=
3
*
nPairs
;
for
(
int
i
=
0
;
i
<
chainLength
;
++
i
)
{
double
prefac
=
i
?
1
:
numDOFs
;
double
mass
=
prefac
*
kT
/
(
collisionFrequency
*
collisionFrequency
);
double
velocity
=
nhcVelocities
[
2
*
chainID
+
1
][
i
];
// The kinetic energy of this bead
kineticEnergy
+=
0.5
*
mass
*
velocity
*
velocity
;
// The potential energy of this bead
double
position
=
nhcPositions
[
2
*
chainID
+
1
][
i
];
potentialEnergy
+=
prefac
*
kT
*
position
;
}
}
return
kineticEnergy
+
potentialEnergy
;
}
std
::
pair
<
double
,
double
>
ReferenceNoseHooverChainKernel
::
computeMaskedKineticEnergy
(
ContextImpl
&
context
,
const
NoseHooverChain
&
noseHooverChain
,
bool
downloadValue
)
{
const
std
::
vector
<
int
>&
atomsList
=
noseHooverChain
.
getThermostatedAtoms
();
const
std
::
vector
<
std
::
pair
<
int
,
int
>>&
pairsList
=
noseHooverChain
.
getThermostatedPairs
();
std
::
vector
<
Vec3
>&
velocities
=
extractVelocities
(
context
);
const
System
&
system
=
context
.
getSystem
();
int
numParticles
=
system
.
getNumParticles
();
std
::
vector
<
double
>
masses
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
system
.
getParticleMass
(
i
);
double
comKE
=
0
;
double
relKE
=
0
;
// kinetic energy of individual atoms
for
(
const
auto
&
m
:
atomsList
){
comKE
+=
0.5
*
masses
[
m
]
*
velocities
[
m
].
dot
(
velocities
[
m
]);
}
// center of mass kinetic energy of pairs
for
(
const
auto
&
p
:
pairsList
){
double
m1
=
masses
[
p
.
first
];
double
m2
=
masses
[
p
.
second
];
Vec3
v1
=
velocities
[
p
.
first
];
Vec3
v2
=
velocities
[
p
.
second
];
double
invMass
=
1.0
/
(
m1
+
m2
);
double
redMass
=
m1
*
m2
*
invMass
;
double
fracM1
=
m1
*
invMass
;
double
fracM2
=
m2
*
invMass
;
Vec3
comVelocity
=
fracM1
*
v1
+
fracM2
*
v2
;
Vec3
relVelocity
=
v2
-
v1
;
comKE
+=
0.5
*
(
m1
+
m2
)
*
comVelocity
.
dot
(
comVelocity
);
relKE
+=
0.5
*
redMass
*
relVelocity
.
dot
(
relVelocity
);
}
// We ignore the downloadValue argument here and always return the correct value
return
{
comKE
,
relKE
};
}
void
ReferenceNoseHooverChainKernel
::
scaleVelocities
(
ContextImpl
&
context
,
const
NoseHooverChain
&
noseHooverChain
,
std
::
pair
<
double
,
double
>
scaleFactors
)
{
const
auto
&
atoms
=
noseHooverChain
.
getThermostatedAtoms
();
const
auto
&
pairs
=
noseHooverChain
.
getThermostatedPairs
();
std
::
vector
<
Vec3
>&
velocities
=
extractVelocities
(
context
);
double
absScale
=
scaleFactors
.
first
;
double
relScale
=
scaleFactors
.
second
;
const
System
&
system
=
context
.
getSystem
();
int
numParticles
=
system
.
getNumParticles
();
std
::
vector
<
double
>
masses
(
numParticles
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
system
.
getParticleMass
(
i
);
// scale absolute velocities
for
(
const
auto
&
a
:
atoms
){
velocities
[
a
]
*=
absScale
;
}
// scale relative velocities and absolute center of mass velocities for each pair
for
(
const
auto
&
p
:
pairs
){
int
p1
=
p
.
first
;
int
p2
=
p
.
second
;
double
m1
=
masses
[
p
.
first
];
double
m2
=
masses
[
p
.
second
];
Vec3
v1
=
velocities
[
p
.
first
];
Vec3
v2
=
velocities
[
p
.
second
];
double
invMass
=
1.0
/
(
m1
+
m2
);
double
fracM1
=
m1
*
invMass
;
double
fracM2
=
m2
*
invMass
;
Vec3
comVelocity
=
fracM1
*
v1
+
fracM2
*
v2
;
Vec3
relVelocity
=
v2
-
v1
;
velocities
[
p1
]
=
absScale
*
comVelocity
-
relScale
*
relVelocity
*
fracM2
;
velocities
[
p2
]
=
absScale
*
comVelocity
+
relScale
*
relVelocity
*
fracM1
;
}
}
ReferenceApplyMonteCarloBarostatKernel
::~
ReferenceApplyMonteCarloBarostatKernel
()
{
if
(
barostat
)
delete
barostat
;
...
...
platforms/reference/src/ReferencePlatform.cpp
View file @
5a06df78
...
...
@@ -66,8 +66,10 @@ ReferencePlatform::ReferencePlatform() {
registerKernelFactory
(
CalcCustomManyParticleForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
CalcGayBerneForceKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVelocityVerletStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
NoseHooverChainKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
Integrate
BAOAB
StepKernel
::
Name
(),
factory
);
registerKernelFactory
(
Integrate
LangevinMiddle
StepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateBrownianStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableLangevinStepKernel
::
Name
(),
factory
);
registerKernelFactory
(
IntegrateVariableVerletStepKernel
::
Name
(),
factory
);
...
...
@@ -102,6 +104,8 @@ ReferencePlatform::PlatformData::PlatformData(const System& system) : time(0.0),
periodicBoxVectors
=
new
Vec3
[
3
];
constraints
=
new
ReferenceConstraints
(
system
);
energyParameterDerivatives
=
new
map
<
string
,
double
>
();
noseHooverPositions
=
new
vector
<
vector
<
double
>
>
();
noseHooverVelocities
=
new
vector
<
vector
<
double
>
>
();
}
ReferencePlatform
::
PlatformData
::~
PlatformData
()
{
...
...
@@ -112,4 +116,6 @@ ReferencePlatform::PlatformData::~PlatformData() {
delete
[]
periodicBoxVectors
;
delete
constraints
;
delete
energyParameterDerivatives
;
delete
noseHooverPositions
;
delete
noseHooverVelocities
;
}
platforms/reference/src/SimTKReference/ReferenceLJCoulomb14.cpp
View file @
5a06df78
...
...
@@ -38,7 +38,7 @@ using namespace OpenMM;
--------------------------------------------------------------------------------------- */
ReferenceLJCoulomb14
::
ReferenceLJCoulomb14
()
{
ReferenceLJCoulomb14
::
ReferenceLJCoulomb14
()
:
periodic
(
false
)
{
}
/**---------------------------------------------------------------------------------------
...
...
@@ -50,6 +50,13 @@ ReferenceLJCoulomb14::ReferenceLJCoulomb14() {
ReferenceLJCoulomb14
::~
ReferenceLJCoulomb14
()
{
}
void
ReferenceLJCoulomb14
::
setPeriodic
(
OpenMM
::
Vec3
*
vectors
)
{
periodic
=
true
;
periodicBoxVectors
[
0
]
=
vectors
[
0
];
periodicBoxVectors
[
1
]
=
vectors
[
1
];
periodicBoxVectors
[
2
]
=
vectors
[
2
];
}
/**---------------------------------------------------------------------------------------
Calculate LJ 1-4 ixn
...
...
@@ -68,33 +75,36 @@ ReferenceLJCoulomb14::~ReferenceLJCoulomb14() {
void
ReferenceLJCoulomb14
::
calculateBondIxn
(
vector
<
int
>&
atomIndices
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
double
>&
parameters
,
vector
<
Vec3
>&
forces
,
double
*
totalEnergy
,
double
*
energyParamDerivs
)
{
double
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
double
deltaR
[
2
][
ReferenceForce
::
LastDeltaRIndex
];
// get deltaR, R2, and R between 2 atoms
// get deltaR, R2, and R between 2 atoms
int
atomAIndex
=
atomIndices
[
0
];
int
atomBIndex
=
atomIndices
[
1
];
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomBIndex
],
atomCoordinates
[
atomAIndex
],
deltaR
[
0
]);
int
atomAIndex
=
atomIndices
[
0
];
int
atomBIndex
=
atomIndices
[
1
];
if
(
periodic
)
ReferenceForce
::
getDeltaRPeriodic
(
atomCoordinates
[
atomBIndex
],
atomCoordinates
[
atomAIndex
],
periodicBoxVectors
,
deltaR
[
0
]);
else
ReferenceForce
::
getDeltaR
(
atomCoordinates
[
atomBIndex
],
atomCoordinates
[
atomAIndex
],
deltaR
[
0
]);
double
inverseR
=
1.0
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
double
sig2
=
inverseR
*
parameters
[
0
];
sig2
*=
sig2
;
double
sig6
=
sig2
*
sig2
*
sig2
;
double
inverseR
=
1.0
/
(
deltaR
[
0
][
ReferenceForce
::
RIndex
]);
double
sig2
=
inverseR
*
parameters
[
0
];
sig2
*=
sig2
;
double
sig6
=
sig2
*
sig2
*
sig2
;
double
dEdR
=
parameters
[
1
]
*
(
12.0
*
sig6
-
6.0
)
*
sig6
;
dEdR
+=
ONE_4PI_EPS0
*
parameters
[
2
]
*
inverseR
;
dEdR
*=
inverseR
*
inverseR
;
double
dEdR
=
parameters
[
1
]
*
(
12.0
*
sig6
-
6.0
)
*
sig6
;
dEdR
+=
ONE_4PI_EPS0
*
parameters
[
2
]
*
inverseR
;
dEdR
*=
inverseR
*
inverseR
;
// accumulate forces
// accumulate forces
for
(
int
ii
=
0
;
ii
<
3
;
ii
++
)
{
double
force
=
dEdR
*
deltaR
[
0
][
ii
];
forces
[
atomAIndex
][
ii
]
+=
force
;
forces
[
atomBIndex
][
ii
]
-=
force
;
}
for
(
int
ii
=
0
;
ii
<
3
;
ii
++
)
{
double
force
=
dEdR
*
deltaR
[
0
][
ii
];
forces
[
atomAIndex
][
ii
]
+=
force
;
forces
[
atomBIndex
][
ii
]
-=
force
;
}
// accumulate energies
// accumulate energies
if
(
totalEnergy
!=
NULL
)
*
totalEnergy
+=
parameters
[
1
]
*
(
sig6
-
1.0
)
*
sig6
+
(
ONE_4PI_EPS0
*
parameters
[
2
]
*
inverseR
);
if
(
totalEnergy
!=
NULL
)
*
totalEnergy
+=
parameters
[
1
]
*
(
sig6
-
1.0
)
*
sig6
+
(
ONE_4PI_EPS0
*
parameters
[
2
]
*
inverseR
);
}
platforms/reference/src/SimTKReference/Reference
BAOAB
Dynamics.cpp
→
platforms/reference/src/SimTKReference/Reference
LangevinMiddle
Dynamics.cpp
View file @
5a06df78
/* Portions copyright (c) 2006-20
19
Stanford University and Simbios.
/* Portions copyright (c) 2006-20
20
Stanford University and Simbios.
* Contributors: Pande Group
*
* Permission is hereby granted, free of charge, to any person obtaining
...
...
@@ -26,7 +26,7 @@
#include <sstream>
#include "SimTKOpenMMUtilities.h"
#include "Reference
BAOAB
Dynamics.h"
#include "Reference
LangevinMiddle
Dynamics.h"
#include "ReferencePlatform.h"
#include "ReferenceVirtualSites.h"
#include "openmm/OpenMMException.h"
...
...
@@ -35,7 +35,7 @@
using
std
::
vector
;
using
namespace
OpenMM
;
Reference
BAOAB
Dynamics
::
Reference
BAOAB
Dynamics
(
int
numberOfAtoms
,
Reference
LangevinMiddle
Dynamics
::
Reference
LangevinMiddle
Dynamics
(
int
numberOfAtoms
,
double
deltaT
,
double
friction
,
double
temperature
)
:
ReferenceDynamics
(
numberOfAtoms
,
deltaT
,
temperature
),
friction
(
friction
)
{
...
...
@@ -44,29 +44,22 @@ ReferenceBAOABDynamics::ReferenceBAOABDynamics(int numberOfAtoms,
inverseMasses
.
resize
(
numberOfAtoms
);
}
Reference
BAOAB
Dynamics
::~
Reference
BAOAB
Dynamics
()
{
Reference
LangevinMiddle
Dynamics
::~
Reference
LangevinMiddle
Dynamics
()
{
}
double
Reference
BAOAB
Dynamics
::
getFriction
()
const
{
double
Reference
LangevinMiddle
Dynamics
::
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
ReferenceLangevinMiddleDynamics
::
updatePart1
(
int
numberOfAtoms
,
vector
<
Vec3
>&
velocities
,
vector
<
Vec3
>&
forces
,
vector
<
double
>&
inverseMasses
)
{
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
if
(
inverseMasses
[
i
]
!=
0.0
)
velocities
[
i
]
+=
(
getDeltaT
()
*
inverseMasses
[
i
])
*
forces
[
i
];
}
void
Reference
BAOAB
Dynamics
::
updatePart2
(
int
numberOfAtoms
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
double
>&
inverseMasses
,
vector
<
Vec3
>&
xPrime
)
{
void
Reference
LangevinMiddle
Dynamics
::
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
();
...
...
@@ -75,37 +68,29 @@ void ReferenceBAOABDynamics::updatePart2(int numberOfAtoms, vector<Vec3>& atomCo
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
{
if
(
inverseMasses
[
i
]
!=
0.0
)
{
velocities
[
i
]
+
=
(
xPrime
[
i
]
-
oldx
[
i
]
)
/
halfdt
;
xPrime
[
i
]
=
atomCoordinates
[
i
]
+
velocities
[
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
;
xPrime
[
i
]
=
xPrime
[
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
();
void
ReferenceLangevinMiddleDynamics
::
updatePart3
(
OpenMM
::
ContextImpl
&
context
,
int
numberOfAtoms
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
double
>&
inverseMasses
,
vector
<
Vec3
>&
xPrime
)
{
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
i
++
)
{
if
(
inverseMasses
[
i
]
!=
0.0
)
{
velocities
[
i
]
+=
(
xPrime
[
i
]
-
oldx
[
i
])
/
halfdt
;
velocities
[
i
]
+=
(
xPrime
[
i
]
-
oldx
[
i
])
/
getDeltaT
()
;
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
Reference
BAOAB
Dynamics
::
update
(
ContextImpl
&
context
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
double
>&
masses
,
bool
&
forcesAreValid
,
double
tolerance
)
{
void
Reference
LangevinMiddle
Dynamics
::
update
(
ContextImpl
&
context
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
double
>&
masses
,
double
tolerance
)
{
int
numberOfAtoms
=
context
.
getSystem
().
getNumParticles
();
ReferenceConstraintAlgorithm
*
referenceConstraintAlgorithm
=
getReferenceConstraintAlgorithm
();
if
(
getTimeStep
()
==
0
)
{
...
...
@@ -118,18 +103,14 @@ void ReferenceBAOABDynamics::update(ContextImpl& context, vector<Vec3>& atomCoor
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
);
updatePart1
(
numberOfAtoms
,
velocities
,
forces
,
inverseMasses
);
if
(
referenceConstraintAlgorithm
)
referenceConstraintAlgorithm
->
apply
(
atomCoordinates
,
xPrime
,
inverseMasses
,
tolerance
);
referenceConstraintAlgorithm
->
apply
ToVelocities
(
atomCoordinates
,
velocities
,
inverseMasses
,
tolerance
);
// 2nd update
...
...
@@ -139,9 +120,7 @@ void ReferenceBAOABDynamics::update(ContextImpl& context, vector<Vec3>& atomCoor
// 3rd update
updatePart3
(
context
,
numberOfAtoms
,
atomCoordinates
,
velocities
,
forces
,
inverseMasses
,
xPrime
);
if
(
referenceConstraintAlgorithm
)
referenceConstraintAlgorithm
->
applyToVelocities
(
atomCoordinates
,
velocities
,
inverseMasses
,
tolerance
);
updatePart3
(
context
,
numberOfAtoms
,
atomCoordinates
,
velocities
,
inverseMasses
,
xPrime
);
ReferenceVirtualSites
::
computePositions
(
context
.
getSystem
(),
atomCoordinates
);
incrementTimeStep
();
...
...
platforms/reference/src/SimTKReference/ReferenceNoseHooverChain.cpp
0 → 100644
View file @
5a06df78
/* Portions copyright (c) 2008-2010 Stanford University and Simbios.
* Contributors: Peter Eastman
*
* 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 <cmath>
#include <string.h>
#include <sstream>
#include <exception>
#include "SimTKOpenMMUtilities.h"
#include "ReferenceNoseHooverChain.h"
using
std
::
vector
;
using
namespace
OpenMM
;
/**---------------------------------------------------------------------------------------
Constructor
--------------------------------------------------------------------------------------- */
ReferenceNoseHooverChain
::
ReferenceNoseHooverChain
()
{
}
/**---------------------------------------------------------------------------------------
Destructor
--------------------------------------------------------------------------------------- */
ReferenceNoseHooverChain
::~
ReferenceNoseHooverChain
()
{
}
double
ReferenceNoseHooverChain
::
propagate
(
double
kineticEnergy
,
vector
<
double
>&
chainVelocities
,
vector
<
double
>&
chainPositions
,
int
numDOFs
,
double
temperature
,
double
collisionFrequency
,
double
timeStep
,
int
numMTS
,
const
vector
<
double
>&
YSWeights
)
const
{
double
scale
=
1
;
const
double
kT
=
BOLTZ
*
temperature
;
const
size_t
chainLength
=
chainPositions
.
size
();
std
::
vector
<
double
>
chainForces
(
chainLength
,
0
);
std
::
vector
<
double
>
chainMasses
(
chainLength
,
kT
/
(
collisionFrequency
*
collisionFrequency
));
chainMasses
[
0
]
*=
numDOFs
;
double
KE2
=
2
*
kineticEnergy
;
chainForces
[
0
]
=
(
KE2
-
numDOFs
*
kT
)
/
chainMasses
[
0
];
for
(
int
bead
=
0
;
bead
<
chainLength
-
1
;
++
bead
)
{
chainForces
[
bead
+
1
]
=
(
chainMasses
[
bead
]
*
chainVelocities
[
bead
]
*
chainVelocities
[
bead
]
-
kT
)
/
chainMasses
[
bead
+
1
];
}
for
(
int
mts
=
0
;
mts
<
numMTS
;
++
mts
)
{
for
(
const
auto
&
ys
:
YSWeights
)
{
double
wdt
=
ys
*
timeStep
/
numMTS
;
chainVelocities
.
back
()
+=
0.25
*
wdt
*
chainForces
.
back
();
for
(
int
bead
=
chainLength
-
2
;
bead
>=
0
;
--
bead
)
{
double
aa
=
exp
(
-
0.125
*
wdt
*
chainVelocities
[
bead
+
1
]);
chainVelocities
[
bead
]
=
aa
*
(
chainVelocities
[
bead
]
*
aa
+
0.25
*
wdt
*
chainForces
[
bead
]);
}
// update particle velocities
double
aa
=
exp
(
-
0.5
*
wdt
*
chainVelocities
[
0
]);
scale
*=
aa
;
// update the thermostat positions
for
(
int
bead
=
0
;
bead
<
chainLength
;
++
bead
)
{
chainPositions
[
bead
]
+=
0.5
*
chainVelocities
[
bead
]
*
wdt
;
}
// update the forces
chainForces
[
0
]
=
(
scale
*
scale
*
KE2
-
numDOFs
*
kT
)
/
chainMasses
[
0
];
// update thermostat velocities
for
(
int
bead
=
0
;
bead
<
chainLength
-
1
;
++
bead
)
{
double
aa
=
exp
(
-
0.125
*
wdt
*
chainVelocities
[
bead
+
1
]);
chainVelocities
[
bead
]
=
aa
*
(
aa
*
chainVelocities
[
bead
]
+
0.25
*
wdt
*
chainForces
[
bead
]);
chainForces
[
bead
+
1
]
=
(
chainMasses
[
bead
]
*
chainVelocities
[
bead
]
*
chainVelocities
[
bead
]
-
kT
)
/
chainMasses
[
bead
+
1
];
}
chainVelocities
[
chainLength
-
1
]
+=
0.25
*
wdt
*
chainForces
.
back
();
}
// YS loop
}
// MTS loop
return
scale
;
}
platforms/reference/src/SimTKReference/ReferenceVelocityVerletDynamics.cpp
0 → 100644
View file @
5a06df78
/* Portions copyright (c) 2006-2013 Stanford University and Simbios.
* Contributors: Peter Eastman, 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 <iostream>
#include <sstream>
#include "openmm/OpenMMException.h"
#include "SimTKOpenMMUtilities.h"
#include "openmm/internal/ContextImpl.h"
#include "ReferenceVelocityVerletDynamics.h"
#include "ReferenceVirtualSites.h"
#include <cstdio>
using
std
::
vector
;
using
namespace
OpenMM
;
/**---------------------------------------------------------------------------------------
ReferenceVelocityVerletDynamics constructor
@param numberOfAtoms number of atoms
@param deltaT delta t for dynamics
@param friction friction coefficient
@param temperature temperature
--------------------------------------------------------------------------------------- */
ReferenceVelocityVerletDynamics
::
ReferenceVelocityVerletDynamics
(
int
numberOfAtoms
,
double
deltaT
)
:
ReferenceDynamics
(
numberOfAtoms
,
deltaT
,
0.0
)
{
xPrime
.
resize
(
numberOfAtoms
);
inverseMasses
.
resize
(
numberOfAtoms
);
}
/**---------------------------------------------------------------------------------------
ReferenceVelocityVerletDynamics destructor
--------------------------------------------------------------------------------------- */
ReferenceVelocityVerletDynamics
::~
ReferenceVelocityVerletDynamics
()
{
}
/**---------------------------------------------------------------------------------------
Update -- driver routine for performing Velocity Verlet dynamics update of coordinates
and velocities
@param system the System to be integrated
@param atomCoordinates atom coordinates
@param velocities velocities
@param forces forces
@param masses atom masses
@param atomList list of all atoms not involved in a Drude-like pair
@param pairList list of all Drude-like pairs
@param maxPairDistance the maximum separation of any Drude-like pairs
--------------------------------------------------------------------------------------- */
void
ReferenceVelocityVerletDynamics
::
update
(
OpenMM
::
ContextImpl
&
context
,
const
OpenMM
::
System
&
system
,
vector
<
Vec3
>&
atomCoordinates
,
vector
<
Vec3
>&
velocities
,
vector
<
Vec3
>&
forces
,
vector
<
double
>&
masses
,
double
tolerance
,
bool
&
forcesAreValid
,
const
std
::
vector
<
int
>
&
atomList
,
const
std
::
vector
<
std
::
tuple
<
int
,
int
,
double
>>
&
pairList
,
double
maxPairDistance
)
{
// first-time-through initialization
if
(
!
forcesAreValid
)
context
.
calcForcesAndEnergy
(
true
,
false
);
int
numberOfAtoms
=
system
.
getNumParticles
();
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
];
}
}
//// Perform the integration.
// Regular atoms
for
(
const
auto
&
atom
:
atomList
)
{
if
(
masses
[
atom
]
!=
0.0
)
{
velocities
[
atom
]
+=
0.5
*
inverseMasses
[
atom
]
*
forces
[
atom
]
*
getDeltaT
();
xPrime
[
atom
]
=
atomCoordinates
[
atom
];
atomCoordinates
[
atom
]
+=
velocities
[
atom
]
*
getDeltaT
();
}
}
// Connected particles
for
(
const
auto
&
pair
:
pairList
)
{
const
auto
&
atom1
=
std
::
get
<
0
>
(
pair
);
const
auto
&
atom2
=
std
::
get
<
1
>
(
pair
);
double
m1
=
system
.
getParticleMass
(
atom1
);
double
m2
=
system
.
getParticleMass
(
atom2
);
double
mass1fract
=
m1
/
(
m1
+
m2
);
double
mass2fract
=
m2
/
(
m1
+
m2
);
double
invRedMass
=
(
m1
*
m2
!=
0.0
)
?
(
m1
+
m2
)
/
(
m1
*
m2
)
:
0.0
;
double
invTotMass
=
(
m1
+
m2
!=
0.0
)
?
1.0
/
(
m1
+
m2
)
:
0.0
;
Vec3
comVel
=
velocities
[
atom1
]
*
mass1fract
+
velocities
[
atom2
]
*
mass2fract
;
Vec3
relVel
=
velocities
[
atom2
]
-
velocities
[
atom1
];
Vec3
comForce
=
forces
[
atom1
]
+
forces
[
atom2
];
Vec3
relForce
=
mass1fract
*
forces
[
atom2
]
-
mass2fract
*
forces
[
atom1
];
comVel
+=
0.5
*
comForce
*
getDeltaT
()
*
invTotMass
;
relVel
+=
0.5
*
relForce
*
getDeltaT
()
*
invRedMass
;
if
(
m1
!=
0.0
)
{
velocities
[
atom1
]
=
comVel
-
relVel
*
mass2fract
;
xPrime
[
atom1
]
=
atomCoordinates
[
atom1
];
atomCoordinates
[
atom1
]
+=
velocities
[
atom1
]
*
getDeltaT
();
}
if
(
m2
!=
0.0
)
{
velocities
[
atom2
]
=
comVel
+
relVel
*
mass1fract
;
xPrime
[
atom2
]
=
atomCoordinates
[
atom2
];
atomCoordinates
[
atom2
]
+=
velocities
[
atom2
]
*
getDeltaT
();
}
}
//
ReferenceConstraintAlgorithm
*
referenceConstraintAlgorithm
=
getReferenceConstraintAlgorithm
();
if
(
referenceConstraintAlgorithm
)
referenceConstraintAlgorithm
->
apply
(
xPrime
,
atomCoordinates
,
inverseMasses
,
tolerance
);
// Apply hard wall constraints.
if
(
maxPairDistance
>
0
)
{
for
(
const
auto
&
pair
:
pairList
)
{
const
int
atom1
=
std
::
get
<
0
>
(
pair
);
const
int
atom2
=
std
::
get
<
1
>
(
pair
);
const
double
hardWallScale
=
sqrt
(
std
::
get
<
2
>
(
pair
)
*
BOLTZ
);
Vec3
delta
=
atomCoordinates
[
atom1
]
-
atomCoordinates
[
atom2
];
double
r
=
sqrt
(
delta
.
dot
(
delta
));
double
rInv
=
1
/
r
;
if
(
rInv
*
maxPairDistance
<
1.0
)
{
// The constraint has been violated, so make the inter-particle distance "bounce"
// off the hard wall.
//if (rInv*maxPairDistance < 0.5)
// throw OpenMMException("Drude particle moved too far beyond hard wall constraint");
// TODO: Review this - I commented it out to make the NoseHooverThermostat test work
Vec3
bondDir
=
delta
*
rInv
;
Vec3
vel1
=
velocities
[
atom1
];
Vec3
vel2
=
velocities
[
atom2
];
double
m1
=
masses
[
atom1
];
double
m2
=
masses
[
atom2
];
double
invTotMass
=
(
m1
+
m2
!=
0.0
)
?
1.0
/
(
m1
+
m2
)
:
0.0
;
double
deltaR
=
r
-
maxPairDistance
;
double
deltaT
=
getDeltaT
();
double
dt
=
getDeltaT
();
double
dotvr1
=
vel1
.
dot
(
bondDir
);
Vec3
vb1
=
bondDir
*
dotvr1
;
Vec3
vp1
=
vel1
-
vb1
;
if
(
m2
==
0
)
{
// The parent particle is massless, so move only the Drude particle.
if
(
dotvr1
!=
0.0
)
deltaT
=
deltaR
/
std
::
abs
(
dotvr1
);
if
(
deltaT
>
getDeltaT
())
deltaT
=
getDeltaT
();
dotvr1
=
-
dotvr1
*
hardWallScale
/
(
std
::
abs
(
dotvr1
)
*
sqrt
(
m1
));
double
dr
=
-
deltaR
+
deltaT
*
dotvr1
;
atomCoordinates
[
atom1
]
+=
bondDir
*
dr
;
velocities
[
atom1
]
=
vp1
+
bondDir
*
dotvr1
;
}
else
{
// Move both particles.
double
dotvr2
=
vel2
.
dot
(
bondDir
);
Vec3
vb2
=
bondDir
*
dotvr2
;
Vec3
vp2
=
vel2
-
vb2
;
double
vbCMass
=
(
m1
*
dotvr1
+
m2
*
dotvr2
)
*
invTotMass
;
dotvr1
-=
vbCMass
;
dotvr2
-=
vbCMass
;
if
(
dotvr1
!=
dotvr2
)
deltaT
=
deltaR
/
std
::
abs
(
dotvr1
-
dotvr2
);
if
(
deltaT
>
dt
)
deltaT
=
dt
;
double
vBond
=
hardWallScale
/
sqrt
(
m1
);
dotvr1
=
-
dotvr1
*
vBond
*
m2
*
invTotMass
/
std
::
abs
(
dotvr1
);
dotvr2
=
-
dotvr2
*
vBond
*
m1
*
invTotMass
/
std
::
abs
(
dotvr2
);
double
dr1
=
-
deltaR
*
m2
*
invTotMass
+
deltaT
*
dotvr1
;
double
dr2
=
deltaR
*
m1
*
invTotMass
+
deltaT
*
dotvr2
;
dotvr1
+=
vbCMass
;
dotvr2
+=
vbCMass
;
atomCoordinates
[
atom1
]
+=
bondDir
*
dr1
;
atomCoordinates
[
atom2
]
+=
bondDir
*
dr2
;
velocities
[
atom1
]
=
vp1
+
bondDir
*
dotvr1
;
velocities
[
atom2
]
=
vp2
+
bondDir
*
dotvr2
;
}
}
}
}
/* end of hard wall constraint part */
ReferenceVirtualSites
::
computePositions
(
system
,
atomCoordinates
);
context
.
calcForcesAndEnergy
(
true
,
false
);
forcesAreValid
=
true
;
for
(
int
i
=
0
;
i
<
numberOfAtoms
;
++
i
)
{
if
(
masses
[
i
]
!=
0.0
)
for
(
int
j
=
0
;
j
<
3
;
++
j
)
{
xPrime
[
i
][
j
]
+=
velocities
[
i
][
j
]
*
getDeltaT
();
}
}
// Update the positions and velocities.
// Regular atoms
for
(
const
auto
&
atom
:
atomList
)
{
if
(
masses
[
atom
]
!=
0.0
)
{
velocities
[
atom
]
+=
0.5
*
inverseMasses
[
atom
]
*
forces
[
atom
]
*
getDeltaT
()
+
(
atomCoordinates
[
atom
]
-
xPrime
[
atom
])
/
getDeltaT
();
}
}
// Connected particles
for
(
const
auto
&
pair
:
pairList
)
{
const
auto
&
atom1
=
std
::
get
<
0
>
(
pair
);
const
auto
&
atom2
=
std
::
get
<
1
>
(
pair
);
double
m1
=
system
.
getParticleMass
(
atom1
);
double
m2
=
system
.
getParticleMass
(
atom2
);
double
mass1fract
=
m1
/
(
m1
+
m2
);
double
mass2fract
=
m2
/
(
m1
+
m2
);
double
invRedMass
=
(
m1
*
m2
!=
0.0
)
?
(
m1
+
m2
)
/
(
m1
*
m2
)
:
0.0
;
double
invTotMass
=
(
m1
+
m2
!=
0.0
)
?
1.0
/
(
m1
+
m2
)
:
0.0
;
Vec3
comVel
=
velocities
[
atom1
]
*
mass1fract
+
velocities
[
atom2
]
*
mass2fract
;
Vec3
relVel
=
velocities
[
atom2
]
-
velocities
[
atom1
];
Vec3
comForce
=
forces
[
atom1
]
+
forces
[
atom2
];
Vec3
relForce
=
mass1fract
*
forces
[
atom2
]
-
mass2fract
*
forces
[
atom1
];
comVel
+=
0.5
*
comForce
*
getDeltaT
()
*
invTotMass
;
relVel
+=
0.5
*
relForce
*
getDeltaT
()
*
invRedMass
;
if
(
m1
!=
0.0
)
{
velocities
[
atom1
]
=
comVel
-
relVel
*
mass2fract
+
(
atomCoordinates
[
atom1
]
-
xPrime
[
atom1
])
/
getDeltaT
();
}
if
(
m2
!=
0.0
)
{
velocities
[
atom2
]
=
comVel
+
relVel
*
mass1fract
+
(
atomCoordinates
[
atom2
]
-
xPrime
[
atom2
])
/
getDeltaT
();
}
}
if
(
referenceConstraintAlgorithm
)
referenceConstraintAlgorithm
->
applyToVelocities
(
atomCoordinates
,
velocities
,
inverseMasses
,
tolerance
);
incrementTimeStep
();
}
platforms/reference/tests/TestReference
BAOAB
LangevinIntegrator.cpp
→
platforms/reference/tests/TestReferenceLangevin
Middle
Integrator.cpp
View file @
5a06df78
...
...
@@ -30,7 +30,7 @@
* -------------------------------------------------------------------------- */
#include "ReferenceTests.h"
#include "Test
BAOAB
LangevinIntegrator.h"
#include "TestLangevin
Middle
Integrator.h"
void
runPlatformTests
()
{
}
platforms/reference/tests/TestReferenceNoseHooverIntegrator.cpp
0 → 100644
View file @
5a06df78
/* -------------------------------------------------------------------------- *
* 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) 2015 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 "TestNoseHooverIntegrator.h"
void
runPlatformTests
()
{
}
platforms/reference/tests/TestReferenceNoseHooverThermostat.cpp
0 → 100644
View file @
5a06df78
/* -------------------------------------------------------------------------- *
* 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: Andreas Krämer and Andrew C. Simmonett *
* 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 "TestNoseHooverThermostat.h"
void
runPlatformTests
()
{
}
plugins/amoeba/platforms/cuda/CMakeLists.txt
View file @
5a06df78
...
...
@@ -65,27 +65,28 @@ INCLUDE_DIRECTORIES(BEFORE ${CMAKE_CURRENT_SOURCE_DIR}/src)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_SOURCE_DIR
}
/platforms/cuda/include
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_SOURCE_DIR
}
/platforms/cuda/src
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_BINARY_DIR
}
/platforms/cuda/src
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_SOURCE_DIR
}
/platforms/common/include
)
# Set variables needed for encoding kernel sources into a C++ class
SET
(
CUDA
_SOURCE_DIR
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
)
SET
(
CUDA
_SOURCE_CLASS CudaAmoebaKernelSources
)
SET
(
CUDA_
KERNELS_CPP
${
CMAKE_CURRENT_BINARY_DIR
}
/src/
${
CUDA
_SOURCE_CLASS
}
.cpp
)
SET
(
CUDA_
KERNELS_H
${
CMAKE_CURRENT_BINARY_DIR
}
/src/
${
CUDA
_SOURCE_CLASS
}
.h
)
SET
(
SOURCE_FILES
${
SOURCE_FILES
}
${
CUDA_
KERNELS_CPP
}
${
CUDA_
KERNELS_H
}
)
SET
(
KERNEL
_SOURCE_DIR
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
)
SET
(
KERNEL
_SOURCE_CLASS CudaAmoebaKernelSources
)
SET
(
KERNELS_CPP
${
CMAKE_CURRENT_BINARY_DIR
}
/src/
${
KERNEL
_SOURCE_CLASS
}
.cpp
)
SET
(
KERNELS_H
${
CMAKE_CURRENT_BINARY_DIR
}
/src/
${
KERNEL
_SOURCE_CLASS
}
.h
)
SET
(
SOURCE_FILES
${
SOURCE_FILES
}
${
KERNELS_CPP
}
${
KERNELS_H
}
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
# Create the library
INCLUDE_DIRECTORIES
(
${
CUDA_TOOLKIT_INCLUDE
}
)
FILE
(
GLOB CUDA_KERNELS
${
CUDA
_SOURCE_DIR
}
/kernels/*.cu
)
ADD_CUSTOM_COMMAND
(
OUTPUT
${
CUDA_
KERNELS_CPP
}
${
CUDA_
KERNELS_H
}
FILE
(
GLOB CUDA_KERNELS
${
KERNEL
_SOURCE_DIR
}
/kernels/*.cu
)
ADD_CUSTOM_COMMAND
(
OUTPUT
${
KERNELS_CPP
}
${
KERNELS_H
}
COMMAND
${
CMAKE_COMMAND
}
ARGS -D
CUDA
_SOURCE_DIR=
${
CUDA
_SOURCE_DIR
}
-D
CUDA_
KERNELS_CPP=
${
CUDA_
KERNELS_CPP
}
-D
CUDA_
KERNELS_H=
${
CUDA_
KERNELS_H
}
-D
CUDA
_SOURCE_CLASS=
${
CUDA
_SOURCE_CLASS
}
-
P
${
CMAKE_SOURCE_DIR
}
/platforms/cuda/EncodeCUDA
Files.cmake
ARGS -D
KERNEL
_SOURCE_DIR=
${
KERNEL
_SOURCE_DIR
}
-D KERNELS_CPP=
${
KERNELS_CPP
}
-D KERNELS_H=
${
KERNELS_H
}
-D
KERNEL
_SOURCE_CLASS=
${
KERNEL
_SOURCE_CLASS
}
-
D KERNEL_FILE_EXTENSION=cu -P
${
CMAKE_SOURCE_DIR
}
/cmake_modules/EncodeKernel
Files.cmake
DEPENDS
${
CUDA_KERNELS
}
)
SET_SOURCE_FILES_PROPERTIES
(
${
CUDA_
KERNELS_CPP
}
${
CUDA_
KERNELS_H
}
PROPERTIES GENERATED TRUE
)
SET_SOURCE_FILES_PROPERTIES
(
${
KERNELS_CPP
}
${
KERNELS_H
}
PROPERTIES GENERATED TRUE
)
# Build the shared plugin library.
...
...
plugins/amoeba/platforms/cuda/src/CudaAmoebaKernelSources.h.in
View file @
5a06df78
...
...
@@ -40,7 +40,7 @@ namespace OpenMM {
class OPENMM_EXPORT CudaAmoebaKernelSources {
public:
@
CUDA
_FILE_DECLARATIONS@
@
KERNEL
_FILE_DECLARATIONS@
};
} // namespace OpenMM
...
...
plugins/cudacompiler/CMakeLists.txt
View file @
5a06df78
...
...
@@ -62,6 +62,7 @@ ENDFOREACH(subdir)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_SOURCE_DIR
}
/src
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_SOURCE_DIR
}
/platforms/cuda/include
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_SOURCE_DIR
}
/platforms/common/include
)
INCLUDE_DIRECTORIES
(
${
CUDA_TOOLKIT_INCLUDE
}
)
# Build the shared plugin library.
...
...
plugins/drude/CMakeLists.txt
View file @
5a06df78
...
...
@@ -101,6 +101,7 @@ ENDIF(OPENMM_BUILD_STATIC_LIB)
# Which hardware platforms to build
ADD_SUBDIRECTORY
(
platforms/reference
)
ADD_SUBDIRECTORY
(
platforms/common
)
IF
(
OPENMM_BUILD_OPENCL_LIB
)
SET
(
OPENMM_BUILD_DRUDE_OPENCL_LIB ON CACHE BOOL
"Build Drude implementation for OpenCL"
)
...
...
plugins/drude/openmmapi/include/OpenMMDrude.h
View file @
5a06df78
...
...
@@ -35,5 +35,6 @@
#include "openmm/DrudeForce.h"
#include "openmm/DrudeLangevinIntegrator.h"
#include "openmm/DrudeSCFIntegrator.h"
#include "openmm/DrudeNoseHooverIntegrator.h"
#endif
/*OPENMM_DRUDE_H_*/
plugins/drude/openmmapi/include/openmm/DrudeNoseHooverIntegrator.h
0 → 100644
View file @
5a06df78
#ifndef OPENMM_DRUDENOSEHOOVERINTEGRATOR_H_
#define OPENMM_DRUDENOSEHOOVERINTEGRATOR_H_
/* -------------------------------------------------------------------------- *
* 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: Andreas Krämer and Andrew C. Simmonett *
* 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/NoseHooverIntegrator.h"
#include "openmm/Kernel.h"
#include "openmm/internal/windowsExportDrude.h"
namespace
OpenMM
{
/**
* This Integrator simulates systems that include Drude particles. It applies two different Nose-Hoover
* chain thermostats to the different parts of the system. The first is applied to ordinary particles (ones
* that are not part of a Drude particle pair), as well as to the center of mass of each Drude particle pair.
* A second thermostat, typically with a much lower temperature, is applied to the relative internal
* displacement of each pair.
*
* This Integrator requires the System to include a DrudeForce, which it uses to identify the Drude
* particles.
*/
class
OPENMM_EXPORT_DRUDE
DrudeNoseHooverIntegrator
:
public
NoseHooverIntegrator
{
public:
/**
* Create a DrudeNoseHooverIntegrator.
*
* @param temperature the target temperature for the system (in Kelvin).
* @param collisionFrequency the frequency of the system's interaction with the heat bath (in inverse picoseconds).
* @param drudeTemperature the target temperature for the Drude particles, relative to their parent atom (in Kelvin).
* @param drudeCollisionFrequency the frequency of the drude particles' interaction with the heat bath (in inverse picoseconds).
* @param stepSize the step size with which to integrator the system (in picoseconds)
* @param chainLength the number of beads in the Nose-Hoover chain.
* @param numMTS the number of step in the multiple time step chain propagation algorithm.
* @param numYoshidaSuzuki the number of terms in the Yoshida-Suzuki multi time step decomposition
* used in the chain propagation algorithm (must be 1, 3, or 5).
*/
DrudeNoseHooverIntegrator
(
double
temperature
,
double
collisionFrequency
,
double
drudeTemperature
,
double
drudeCollisionFrequency
,
double
stepSize
,
int
chainLength
=
3
,
int
numMTS
=
3
,
int
numYoshidaSuzuki
=
3
);
virtual
~
DrudeNoseHooverIntegrator
();
/**
* This will be called by the Context when it is created. It informs the Integrator
* of what context it will be integrating, and gives it a chance to do any necessary initialization.
* It will also get called again if the application calls reinitialize() on the Context.
*/
void
initialize
(
ContextImpl
&
context
);
/**
* Get the maximum distance a Drude particle can ever move from its parent particle, measured in nm. This is implemented
* with a hard wall constraint. If this distance is set to 0 (the default), the hard wall constraint is omitted.
*/
double
getMaxDrudeDistance
()
const
;
/**
* Set the maximum distance a Drude particle can ever move from its parent particle, measured in nm. This is implemented
* with a hard wall constraint. If this distance is set to 0 (the default), the hard wall constraint is omitted.
*/
void
setMaxDrudeDistance
(
double
distance
);
/**
* Compute the kinetic energy of the drude particles at the current time.
*/
double
computeDrudeKineticEnergy
();
/**
* Compute the kinetic energy of all (real and drude) particles at the current time.
*/
double
computeTotalKineticEnergy
();
};
}
// namespace OpenMM
#endif
/*OPENMM_DRUDENOSEHOOVERINTEGRATOR_H_*/
plugins/drude/openmmapi/include/openmm/internal/DrudeForceImpl.h
View file @
5a06df78
...
...
@@ -55,7 +55,7 @@ public:
const
DrudeForce
&
getOwner
()
const
{
return
owner
;
}
void
updateContextState
(
ContextImpl
&
context
)
{
void
updateContextState
(
ContextImpl
&
context
,
bool
&
forcesInvalid
)
{
// This force field doesn't update the state directly.
}
double
calcForcesAndEnergy
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
,
int
groups
);
...
...
plugins/drude/openmmapi/src/DrudeNoseHooverIntegrator.cpp
0 → 100644
View file @
5a06df78
/* -------------------------------------------------------------------------- *
* 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: Andreas Krämer and Andrew C. Simmonett *
* 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/DrudeNoseHooverIntegrator.h"
#include "openmm/Context.h"
#include "openmm/OpenMMException.h"
#include "openmm/internal/ContextImpl.h"
#include "openmm/DrudeKernels.h"
#include "openmm/DrudeForce.h"
#include "openmm/CMMotionRemover.h"
#include "openmm/kernels.h"
#include <ctime>
#include <iostream>
#include <string>
#include <set>
using
namespace
OpenMM
;
using
std
::
string
;
using
std
::
vector
;
DrudeNoseHooverIntegrator
::
DrudeNoseHooverIntegrator
(
double
temperature
,
double
collisionFrequency
,
double
drudeTemperature
,
double
drudeCollisionFrequency
,
double
stepSize
,
int
chainLength
,
int
numMTS
,
int
numYoshidaSuzuki
)
:
NoseHooverIntegrator
(
stepSize
)
{
setMaxDrudeDistance
(
0
);
hasSubsystemThermostats_
=
false
;
addSubsystemThermostat
(
std
::
vector
<
int
>
(),
std
::
vector
<
std
::
pair
<
int
,
int
>>
(),
temperature
,
collisionFrequency
,
drudeTemperature
,
drudeCollisionFrequency
,
chainLength
,
numMTS
,
numYoshidaSuzuki
);
}
DrudeNoseHooverIntegrator
::~
DrudeNoseHooverIntegrator
()
{
}
double
DrudeNoseHooverIntegrator
::
getMaxDrudeDistance
()
const
{
return
maxPairDistance_
;
}
void
DrudeNoseHooverIntegrator
::
setMaxDrudeDistance
(
double
distance
)
{
if
(
distance
<
0
)
throw
OpenMMException
(
"setMaxDrudeDistance: Distance cannot be negative"
);
maxPairDistance_
=
distance
;
}
void
DrudeNoseHooverIntegrator
::
initialize
(
ContextImpl
&
contextRef
)
{
if
(
owner
!=
NULL
&&
&
contextRef
.
getOwner
()
!=
owner
)
throw
OpenMMException
(
"This Integrator is already bound to a context"
);
context
=
&
contextRef
;
owner
=
&
contextRef
.
getOwner
();
vvKernel
=
context
->
getPlatform
().
createKernel
(
IntegrateVelocityVerletStepKernel
::
Name
(),
contextRef
);
vvKernel
.
getAs
<
IntegrateVelocityVerletStepKernel
>
().
initialize
(
contextRef
.
getSystem
(),
*
this
);
nhcKernel
=
context
->
getPlatform
().
createKernel
(
NoseHooverChainKernel
::
Name
(),
contextRef
);
nhcKernel
.
getAs
<
NoseHooverChainKernel
>
().
initialize
();
forcesAreValid
=
false
;
// check for drude particles and build the Nose-Hoover Chains
const
System
&
system
=
context
->
getSystem
();
const
DrudeForce
*
drudeForce
=
NULL
;
bool
hasCMMotionRemover
=
false
;
for
(
int
i
=
0
;
i
<
system
.
getNumForces
();
i
++
){
if
(
dynamic_cast
<
const
DrudeForce
*>
(
&
system
.
getForce
(
i
))
!=
NULL
)
{
if
(
drudeForce
==
NULL
)
drudeForce
=
dynamic_cast
<
const
DrudeForce
*>
(
&
system
.
getForce
(
i
));
else
throw
OpenMMException
(
"The System contains multiple DrudeForces"
);
}
if
(
dynamic_cast
<
const
CMMotionRemover
*>
(
&
system
.
getForce
(
i
)))
{
hasCMMotionRemover
=
true
;
}
}
if
(
drudeForce
==
NULL
)
throw
OpenMMException
(
"The System does not contain a DrudeForce"
);
if
(
!
hasCMMotionRemover
)
{
std
::
cout
<<
"Warning: Did not find a center-of-mass motion remover in the system. "
"This is problematic when using Drude."
<<
std
::
endl
;
}
for
(
auto
&
thermostat
:
noseHooverChains
){
if
(
(
thermostat
.
getThermostatedAtoms
().
size
()
==
0
)
&&
(
thermostat
.
getThermostatedPairs
().
size
()
==
0
)
){
std
::
set
<
int
>
realParticlesSet
;
vector
<
int
>
realParticles
,
drudeParticles
,
drudeParents
;
vector
<
std
::
pair
<
int
,
int
>>
drudePairs
;
for
(
int
i
=
0
;
i
<
system
.
getNumParticles
();
i
++
)
{
if
(
system
.
getParticleMass
(
i
)
>
0.0
)
realParticlesSet
.
insert
(
i
);
}
for
(
int
i
=
0
;
i
<
drudeForce
->
getNumParticles
();
i
++
)
{
int
p
,
p1
,
p2
,
p3
,
p4
;
double
charge
,
polarizability
,
aniso12
,
aniso34
;
drudeForce
->
getParticleParameters
(
i
,
p
,
p1
,
p2
,
p3
,
p4
,
charge
,
polarizability
,
aniso12
,
aniso34
);
realParticlesSet
.
erase
(
p
);
realParticlesSet
.
erase
(
p1
);
drudePairs
.
push_back
({
p
,
p1
});
}
thermostat
.
setThermostatedPairs
(
drudePairs
);
thermostat
.
setThermostatedAtoms
(
std
::
vector
<
int
>
(
realParticlesSet
.
begin
(),
realParticlesSet
.
end
()));
}
}
initializeThermostats
(
system
);
}
double
DrudeNoseHooverIntegrator
::
computeDrudeKineticEnergy
()
{
double
kE
=
0.0
;
for
(
const
auto
&
nhc
:
noseHooverChains
){
if
(
nhc
.
getThermostatedPairs
().
size
()
!=
0
)
{
kE
+=
nhcKernel
.
getAs
<
NoseHooverChainKernel
>
().
computeMaskedKineticEnergy
(
*
context
,
nhc
,
true
).
second
;
}
}
return
kE
;
}
double
DrudeNoseHooverIntegrator
::
computeTotalKineticEnergy
()
{
return
vvKernel
.
getAs
<
IntegrateVelocityVerletStepKernel
>
().
computeKineticEnergy
(
*
context
,
*
this
);
}
plugins/drude/platforms/common/CMakeLists.txt
0 → 100644
View file @
5a06df78
# Encode the kernel sources into a C++ class.
SET
(
KERNEL_SOURCE_DIR
"
${
CMAKE_CURRENT_SOURCE_DIR
}
/src"
)
SET
(
KERNEL_SOURCE_CLASS CommonDrudeKernelSources
)
SET
(
KERNELS_CPP
${
CMAKE_CURRENT_BINARY_DIR
}
/src/
${
KERNEL_SOURCE_CLASS
}
.cpp
)
SET
(
KERNELS_H
${
CMAKE_CURRENT_BINARY_DIR
}
/src/
${
KERNEL_SOURCE_CLASS
}
.h
)
INCLUDE_DIRECTORIES
(
BEFORE
${
CMAKE_CURRENT_BINARY_DIR
}
/src
)
FILE
(
GLOB COMMON_KERNELS
${
KERNEL_SOURCE_DIR
}
/kernels/*.cc
)
ADD_CUSTOM_COMMAND
(
OUTPUT
${
KERNELS_CPP
}
${
KERNELS_H
}
COMMAND
${
CMAKE_COMMAND
}
ARGS -D KERNEL_SOURCE_DIR=
${
KERNEL_SOURCE_DIR
}
-D KERNELS_CPP=
${
KERNELS_CPP
}
-D KERNELS_H=
${
KERNELS_H
}
-D KERNEL_SOURCE_CLASS=
${
KERNEL_SOURCE_CLASS
}
-D KERNEL_FILE_EXTENSION=cc -P
${
CMAKE_SOURCE_DIR
}
/cmake_modules/EncodeKernelFiles.cmake
DEPENDS
${
COMMON_KERNELS
}
)
SET_SOURCE_FILES_PROPERTIES
(
${
KERNELS_CPP
}
${
KERNELS_H
}
PROPERTIES GENERATED TRUE
)
ADD_CUSTOM_TARGET
(
DrudeCommonKernels DEPENDS
${
KERNELS_CPP
}
${
KERNELS_H
}
)
plugins/drude/platforms/
opencl/src/OpenCL
DrudeKernelSources.cpp.in
→
plugins/drude/platforms/
common/src/Common
DrudeKernelSources.cpp.in
View file @
5a06df78
...
...
@@ -24,7 +24,7 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>. *
* -------------------------------------------------------------------------- */
#include "
OpenCL
DrudeKernelSources.h"
#include "
Common
DrudeKernelSources.h"
using namespace OpenMM;
using namespace std;
...
...
Prev
1
…
9
10
11
12
13
14
15
16
17
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