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
08e8b206
Commit
08e8b206
authored
Mar 31, 2017
by
peastman
Committed by
GitHub
Mar 31, 2017
Browse files
Merge pull request #1769 from peastman/loops
Use C++11 style loops
parents
55ee0b9f
083bc501
Changes
96
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
716 additions
and
711 deletions
+716
-711
openmmapi/src/ThreadPool.cpp
openmmapi/src/ThreadPool.cpp
+4
-4
platforms/cpu/src/CpuBondForce.cpp
platforms/cpu/src/CpuBondForce.cpp
+2
-2
platforms/cpu/src/CpuCustomGBForce.cpp
platforms/cpu/src/CpuCustomGBForce.cpp
+50
-50
platforms/cpu/src/CpuCustomManyParticleForce.cpp
platforms/cpu/src/CpuCustomManyParticleForce.cpp
+26
-35
platforms/cpu/src/CpuCustomNonbondedForce.cpp
platforms/cpu/src/CpuCustomNonbondedForce.cpp
+12
-12
platforms/cpu/src/CpuKernels.cpp
platforms/cpu/src/CpuKernels.cpp
+14
-14
platforms/cpu/src/CpuNeighborList.cpp
platforms/cpu/src/CpuNeighborList.cpp
+3
-3
platforms/cpu/src/CpuNonbondedForce.cpp
platforms/cpu/src/CpuNonbondedForce.cpp
+3
-3
platforms/cpu/src/CpuRandom.cpp
platforms/cpu/src/CpuRandom.cpp
+2
-2
platforms/cpu/src/CpuSETTLE.cpp
platforms/cpu/src/CpuSETTLE.cpp
+2
-2
platforms/cuda/src/CudaContext.cpp
platforms/cuda/src/CudaContext.cpp
+32
-33
platforms/cuda/src/CudaExpressionUtilities.cpp
platforms/cuda/src/CudaExpressionUtilities.cpp
+4
-4
platforms/cuda/src/CudaKernels.cpp
platforms/cuda/src/CudaKernels.cpp
+229
-217
platforms/opencl/src/OpenCLBondedUtilities.cpp
platforms/opencl/src/OpenCLBondedUtilities.cpp
+1
-2
platforms/opencl/src/OpenCLContext.cpp
platforms/opencl/src/OpenCLContext.cpp
+44
-45
platforms/opencl/src/OpenCLExpressionUtilities.cpp
platforms/opencl/src/OpenCLExpressionUtilities.cpp
+4
-4
platforms/opencl/src/OpenCLKernels.cpp
platforms/opencl/src/OpenCLKernels.cpp
+240
-231
platforms/reference/src/ReferenceKernels.cpp
platforms/reference/src/ReferenceKernels.cpp
+38
-38
platforms/reference/src/SimTKReference/ReferenceAndersenThermostat.cpp
...erence/src/SimTKReference/ReferenceAndersenThermostat.cpp
+2
-3
platforms/reference/src/SimTKReference/ReferenceCCMAAlgorithm.cpp
...s/reference/src/SimTKReference/ReferenceCCMAAlgorithm.cpp
+4
-7
No files found.
openmmapi/src/ThreadPool.cpp
View file @
08e8b206
...
...
@@ -89,13 +89,13 @@ ThreadPool::ThreadPool(int numThreads) : currentTask(NULL) {
}
ThreadPool
::~
ThreadPool
()
{
for
(
int
i
=
0
;
i
<
(
int
)
threadData
.
size
();
i
++
)
threadData
[
i
]
->
isDeleted
=
true
;
for
(
auto
data
:
threadData
)
data
->
isDeleted
=
true
;
pthread_mutex_lock
(
&
lock
);
pthread_cond_broadcast
(
&
startCondition
);
pthread_mutex_unlock
(
&
lock
);
for
(
int
i
=
0
;
i
<
(
int
)
thread
.
size
();
i
++
)
pthread_join
(
t
hread
[
i
]
,
NULL
);
for
(
auto
t
:
thread
)
pthread_join
(
t
,
NULL
);
pthread_mutex_destroy
(
&
lock
);
pthread_cond_destroy
(
&
startCondition
);
pthread_cond_destroy
(
&
endCondition
);
...
...
platforms/cpu/src/CpuBondForce.cpp
View file @
08e8b206
...
...
@@ -159,8 +159,8 @@ void CpuBondForce::assignBond(int bond, int thread, vector<int>& atomThread, vec
if
(
atom
!=
-
1
)
throw
OpenMMException
(
"CpuBondForce: Internal error: atoms assigned to threads incorrectly"
);
atom
=
thread
;
for
(
set
<
int
>::
const_iterator
iter
=
atomBonds
[
atom
].
begin
();
iter
!=
atomBonds
[
atom
]
.
end
();
++
iter
)
candidateBonds
.
push_back
(
*
iter
);
for
(
int
bond
:
atomBonds
[
atom
])
candidateBonds
.
push_back
(
bond
);
}
}
...
...
platforms/cpu/src/CpuCustomGBForce.cpp
View file @
08e8b206
...
...
@@ -74,48 +74,48 @@ CpuCustomGBForce::ThreadData::ThreadData(int numAtoms, int numThreads, int threa
variableLocations
[
name
.
str
()]
=
&
particleValue
[
2
*
i
+
j
];
}
}
for
(
int
i
=
0
;
i
<
(
int
)
valueExpressions
.
size
();
i
++
)
{
this
->
valueE
xpression
s
[
i
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
valueE
xpression
s
[
i
]
);
for
(
auto
&
expression
:
this
->
valueExpressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
for
(
int
i
=
0
;
i
<
(
int
)
valueDerivExpressions
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
valueDerivExpressions
[
i
].
size
();
j
++
)
{
this
->
valueDerivE
xpression
s
[
i
][
j
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
valueDerivE
xpression
s
[
i
][
j
]
);
for
(
auto
&
expressions
:
this
->
valueDerivExpressions
)
for
(
auto
&
expression
:
expressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
for
(
int
i
=
0
;
i
<
(
int
)
valueGradientExpressions
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
valueGradientExpressions
[
i
].
size
();
j
++
)
{
this
->
valueGradientE
xpression
s
[
i
][
j
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
valueGradientE
xpression
s
[
i
][
j
]
);
for
(
auto
&
expressions
:
this
->
valueGradientExpressions
)
for
(
auto
&
expression
:
expressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
for
(
int
i
=
0
;
i
<
(
int
)
valueParamDerivExpressions
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
valueParamDerivExpressions
[
i
].
size
();
j
++
)
{
this
->
valueParamDerivE
xpression
s
[
i
][
j
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
valueParamDerivE
xpression
s
[
i
][
j
]
);
for
(
auto
&
expressions
:
this
->
valueParamDerivExpressions
)
for
(
auto
&
expression
:
expressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
for
(
int
i
=
0
;
i
<
(
int
)
energyExpressions
.
size
();
i
++
)
{
this
->
energyE
xpression
s
[
i
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
energyE
xpression
s
[
i
]
);
for
(
auto
&
expression
:
this
->
energyExpressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
for
(
int
i
=
0
;
i
<
(
int
)
energyDerivExpressions
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
energyDerivExpressions
[
i
].
size
();
j
++
)
{
this
->
energyDerivE
xpression
s
[
i
][
j
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
energyDerivE
xpression
s
[
i
][
j
]
);
for
(
auto
&
expressions
:
this
->
energyDerivExpressions
)
for
(
auto
&
expression
:
expressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
for
(
int
i
=
0
;
i
<
(
int
)
energyGradientExpressions
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
energyGradientExpressions
[
i
].
size
();
j
++
)
{
this
->
energyGradientE
xpression
s
[
i
][
j
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
energyGradientE
xpression
s
[
i
][
j
]
);
for
(
auto
&
expressions
:
this
->
energyGradientExpressions
)
for
(
auto
&
expression
:
expressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
for
(
int
i
=
0
;
i
<
(
int
)
energyParamDerivExpressions
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
energyParamDerivExpressions
[
i
].
size
();
j
++
)
{
this
->
energyParamDerivE
xpression
s
[
i
][
j
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
energyParamDerivE
xpression
s
[
i
][
j
]
);
for
(
auto
&
expressions
:
this
->
energyParamDerivExpressions
)
for
(
auto
&
expression
:
expressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
value0
.
resize
(
numAtoms
);
dEdV
.
resize
(
valueNames
.
size
());
for
(
int
i
=
0
;
i
<
(
int
)
dEdV
.
size
();
i
++
)
dEdV
[
i
]
.
resize
(
numAtoms
);
for
(
auto
&
v
:
dEdV
)
v
.
resize
(
numAtoms
);
dVdX
.
resize
(
valueDerivExpressions
.
size
());
dVdY
.
resize
(
valueDerivExpressions
.
size
());
dVdZ
.
resize
(
valueDerivExpressions
.
size
());
...
...
@@ -155,8 +155,8 @@ CpuCustomGBForce::CpuCustomGBForce(int numAtoms, const std::vector<std::set<int>
}
CpuCustomGBForce
::~
CpuCustomGBForce
()
{
for
(
int
i
=
0
;
i
<
(
int
)
threadData
.
size
();
i
++
)
delete
threadData
[
i
]
;
for
(
auto
data
:
threadData
)
delete
data
;
}
void
CpuCustomGBForce
::
setUseCutoff
(
float
distance
,
const
CpuNeighborList
&
neighbors
)
{
...
...
@@ -256,16 +256,16 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
ThreadData
&
data
=
*
threadData
[
threadIndex
];
fvec4
boxSize
(
periodicBoxSize
[
0
],
periodicBoxSize
[
1
],
periodicBoxSize
[
2
],
0
);
fvec4
invBoxSize
((
1
/
periodicBoxSize
[
0
]),
(
1
/
periodicBoxSize
[
1
]),
(
1
/
periodicBoxSize
[
2
]),
0
);
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
->
begin
();
iter
!=
globalParameters
->
end
();
++
iter
)
data
.
expressionSet
.
setVariable
(
data
.
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
for
(
auto
&
param
:
*
globalParameters
)
data
.
expressionSet
.
setVariable
(
data
.
expressionSet
.
getVariableIndex
(
param
.
first
),
param
.
second
);
// Calculate the first computed value.
for
(
int
i
=
0
;
i
<
(
int
)
data
.
value0
.
size
();
i
++
)
data
.
value0
[
i
]
=
0.0
f
;
for
(
int
i
=
0
;
i
<
(
int
)
data
.
dValue0dParam
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
data
.
dValue0dParam
[
i
].
size
();
j
++
)
data
.
dValue0dParam
[
i
][
j
]
=
0.0
;
for
(
auto
&
v
:
data
.
value0
)
v
=
0.0
f
;
for
(
auto
&
vals
:
data
.
dValue0dParam
)
for
(
auto
&
v
:
vals
)
v
=
0.0
f
;
if
(
valueTypes
[
0
]
==
CustomGBForce
::
ParticlePair
)
calculateParticlePairValue
(
0
,
data
,
numberOfAtoms
,
posq
,
atomParameters
,
true
,
boxSize
,
invBoxSize
);
else
...
...
@@ -291,8 +291,8 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
int
numValues
=
valueTypes
.
size
();
for
(
int
atom
=
data
.
firstAtom
;
atom
<
data
.
lastAtom
;
atom
++
)
{
float
sum
=
0.0
f
;
for
(
int
j
=
0
;
j
<
(
int
)
threadData
.
size
();
j
++
)
sum
+=
threadData
[
j
]
->
value0
[
atom
];
for
(
auto
&
data
:
threadData
)
sum
+=
data
->
value0
[
atom
];
values
[
0
][
atom
]
=
sum
;
data
.
x
=
posq
[
4
*
atom
];
data
.
y
=
posq
[
4
*
atom
+
1
];
...
...
@@ -320,11 +320,11 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
// Now calculate the energy and its derivatives.
for
(
int
i
=
0
;
i
<
(
int
)
data
.
dEdV
.
size
();
i
++
)
for
(
int
j
=
0
;
j
<
(
int
)
data
.
dEdV
[
i
].
size
();
j
++
)
data
.
dEdV
[
i
][
j
]
=
0.0
f
;
for
(
int
i
=
0
;
i
<
(
int
)
data
.
energyParamDerivs
.
size
();
i
++
)
data
.
energyParamDerivs
[
i
]
=
0.0
f
;
for
(
auto
&
vals
:
data
.
dEdV
)
for
(
auto
&
v
:
vals
)
v
=
0.0
f
;
for
(
auto
&
v
:
data
.
energyParamDerivs
)
v
=
0.0
f
;
for
(
int
termIndex
=
0
;
termIndex
<
(
int
)
data
.
energyExpressions
.
size
();
termIndex
++
)
{
if
(
energyTypes
[
termIndex
]
==
CustomGBForce
::
SingleParticle
)
calculateSingleParticleEnergyTerm
(
termIndex
,
data
,
numberOfAtoms
,
posq
,
atomParameters
,
forces
,
energy
);
...
...
@@ -340,8 +340,8 @@ void CpuCustomGBForce::threadComputeForce(ThreadPool& threads, int threadIndex)
for
(
int
atom
=
data
.
firstAtom
;
atom
<
data
.
lastAtom
;
atom
++
)
{
for
(
int
i
=
0
;
i
<
(
int
)
dEdV
.
size
();
i
++
)
{
float
sum
=
0.0
f
;
for
(
int
j
=
0
;
j
<
(
int
)
threadData
.
size
();
j
++
)
sum
+=
threadData
[
j
]
->
dEdV
[
i
][
atom
];
for
(
auto
&
data
:
threadData
)
sum
+=
data
->
dEdV
[
i
][
atom
];
dEdV
[
i
][
atom
]
=
sum
;
}
}
...
...
platforms/cpu/src/CpuCustomManyParticleForce.cpp
View file @
08e8b206
...
...
@@ -63,8 +63,8 @@ CpuCustomManyParticleForce::CpuCustomManyParticleForce(const CustomManyParticleF
// Delete the custom functions.
for
(
map
<
string
,
Lepton
::
CustomFunction
*>::
iterator
iter
=
functions
.
begin
();
iter
!=
functions
.
end
();
iter
++
)
delete
iter
->
second
;
for
(
auto
&
function
:
functions
)
delete
function
.
second
;
// Record exclusions.
...
...
@@ -84,8 +84,8 @@ CpuCustomManyParticleForce::CpuCustomManyParticleForce(const CustomManyParticleF
CpuCustomManyParticleForce
::~
CpuCustomManyParticleForce
()
{
if
(
neighborList
!=
NULL
)
delete
neighborList
;
for
(
int
i
=
0
;
i
<
(
int
)
threadData
.
size
();
i
++
)
delete
threadData
[
i
]
;
for
(
auto
data
:
threadData
)
delete
data
;
}
void
CpuCustomManyParticleForce
::
calculateIxn
(
AlignedArray
<
float
>&
posq
,
double
**
particleParameters
,
...
...
@@ -150,8 +150,8 @@ void CpuCustomManyParticleForce::threadComputeForce(ThreadPool& threads, int thr
float
*
forces
=
&
(
*
threadForce
)[
threadIndex
][
0
];
ThreadData
&
data
=
*
threadData
[
threadIndex
];
data
.
energy
=
0
;
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
->
begin
();
iter
!=
globalParameters
->
end
();
++
iter
)
data
.
expressionSet
.
setVariable
(
data
.
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
for
(
auto
&
param
:
*
globalParameters
)
data
.
expressionSet
.
setVariable
(
data
.
expressionSet
.
getVariableIndex
(
param
.
first
),
param
.
second
);
if
(
useCutoff
)
{
// Loop over interactions from the neighbor list.
...
...
@@ -287,18 +287,12 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, doubl
// Compute all of the variables the energy can depend on.
for
(
int
i
=
0
;
i
<
(
int
)
data
.
particleTerms
.
size
();
i
++
)
{
const
ParticleTermInfo
&
term
=
data
.
particleTerms
[
i
];
for
(
auto
&
term
:
data
.
particleTerms
)
expressionSet
.
setVariable
(
term
.
variableIndex
,
posq
[
4
*
permutedParticles
[
term
.
atom
]
+
term
.
component
]);
}
for
(
int
i
=
0
;
i
<
(
int
)
data
.
distanceTerms
.
size
();
i
++
)
{
const
DistanceTermInfo
&
term
=
data
.
distanceTerms
[
i
];
for
(
auto
&
term
:
data
.
distanceTerms
)
expressionSet
.
setVariable
(
term
.
variableIndex
,
normDelta
[
term
.
delta
]);
}
for
(
int
i
=
0
;
i
<
(
int
)
data
.
angleTerms
.
size
();
i
++
)
{
const
AngleTermInfo
&
term
=
data
.
angleTerms
[
i
];
for
(
auto
&
term
:
data
.
angleTerms
)
expressionSet
.
setVariable
(
term
.
variableIndex
,
computeAngle
(
delta
[
term
.
delta1
],
delta
[
term
.
delta2
],
norm2Delta
[
term
.
delta1
],
norm2Delta
[
term
.
delta2
],
term
.
delta1Sign
*
term
.
delta2Sign
));
}
for
(
int
i
=
0
;
i
<
(
int
)
data
.
dihedralTerms
.
size
();
i
++
)
{
const
DihedralTermInfo
&
term
=
data
.
dihedralTerms
[
i
];
expressionSet
.
setVariable
(
term
.
variableIndex
,
getDihedralAngleBetweenThreeVectors
(
delta
[
term
.
delta1
],
delta
[
term
.
delta2
],
delta
[
term
.
delta3
],
cross1
[
i
],
cross2
[
i
],
delta
[
term
.
delta1
]));
...
...
@@ -310,8 +304,7 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, doubl
AlignedArray
<
fvec4
>&
f
=
data
.
f
;
for
(
int
i
=
0
;
i
<
numParticlesPerSet
;
i
++
)
f
[
i
]
=
fvec4
(
0.0
f
);
for
(
int
i
=
0
;
i
<
(
int
)
data
.
particleTerms
.
size
();
i
++
)
{
const
ParticleTermInfo
&
term
=
data
.
particleTerms
[
i
];
for
(
auto
&
term
:
data
.
particleTerms
)
{
float
temp
[
4
];
f
[
term
.
atom
].
store
(
temp
);
temp
[
term
.
component
]
-=
term
.
forceExpression
.
evaluate
();
...
...
@@ -320,8 +313,7 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, doubl
// Apply forces based on distances.
for
(
int
i
=
0
;
i
<
(
int
)
data
.
distanceTerms
.
size
();
i
++
)
{
const
DistanceTermInfo
&
term
=
data
.
distanceTerms
[
i
];
for
(
auto
&
term
:
data
.
distanceTerms
)
{
float
dEdR
=
(
float
)
(
term
.
forceExpression
.
evaluate
()
*
term
.
deltaSign
/
(
normDelta
[
term
.
delta
]));
fvec4
force
=
-
dEdR
*
delta
[
term
.
delta
];
f
[
term
.
p1
]
-=
force
;
...
...
@@ -330,8 +322,7 @@ void CpuCustomManyParticleForce::calculateOneIxn(vector<int>& particleSet, doubl
// Apply forces based on angles.
for
(
int
i
=
0
;
i
<
(
int
)
data
.
angleTerms
.
size
();
i
++
)
{
const
AngleTermInfo
&
term
=
data
.
angleTerms
[
i
];
for
(
auto
&
term
:
data
.
angleTerms
)
{
float
dEdTheta
=
(
float
)
term
.
forceExpression
.
evaluate
();
fvec4
thetaCross
=
cross
(
delta
[
term
.
delta1
],
delta
[
term
.
delta2
]);
float
lengthThetaCross
=
sqrtf
(
dot3
(
thetaCross
,
thetaCross
));
...
...
@@ -482,20 +473,20 @@ CpuCustomManyParticleForce::ThreadData::ThreadData(const CustomManyParticleForce
particleParamIndices
[
i
].
push_back
(
expressionSet
.
getVariableIndex
(
paramname
.
str
()));
}
}
for
(
map
<
string
,
vector
<
int
>
>::
const_iterator
iter
=
dihedrals
.
begin
();
iter
!=
dihedrals
.
end
();
++
iter
)
dihedralTerms
.
push_back
(
CpuCustomManyParticleForce
::
DihedralTermInfo
(
i
ter
->
first
,
i
ter
->
second
,
energyExpr
.
differentiate
(
i
ter
->
first
).
optimize
().
createCompiledExpression
(),
*
this
));
for
(
map
<
string
,
vector
<
int
>
>::
const_iterator
iter
=
distances
.
begin
();
iter
!=
distances
.
end
();
++
iter
)
distanceTerms
.
push_back
(
CpuCustomManyParticleForce
::
DistanceTermInfo
(
i
ter
->
first
,
i
ter
->
second
,
energyExpr
.
differentiate
(
i
ter
->
first
).
optimize
().
createCompiledExpression
(),
*
this
));
for
(
map
<
string
,
vector
<
int
>
>::
const_iterator
iter
=
angles
.
begin
();
iter
!=
angles
.
end
();
++
iter
)
angleTerms
.
push_back
(
CpuCustomManyParticleForce
::
AngleTermInfo
(
i
ter
->
first
,
i
ter
->
second
,
energyExpr
.
differentiate
(
i
ter
->
first
).
optimize
().
createCompiledExpression
(),
*
this
));
for
(
int
i
=
0
;
i
<
particleTerms
.
size
();
i
++
)
expressionSet
.
registerExpression
(
particleTerms
[
i
]
.
forceExpression
);
for
(
int
i
=
0
;
i
<
distanceTerms
.
size
();
i
++
)
expressionSet
.
registerExpression
(
distanceTerms
[
i
]
.
forceExpression
);
for
(
int
i
=
0
;
i
<
angleTerms
.
size
();
i
++
)
expressionSet
.
registerExpression
(
angleTerms
[
i
]
.
forceExpression
);
for
(
int
i
=
0
;
i
<
dihedralTerms
.
size
();
i
++
)
expressionSet
.
registerExpression
(
dihedralTerms
[
i
]
.
forceExpression
);
for
(
auto
&
term
:
dihedrals
)
dihedralTerms
.
push_back
(
CpuCustomManyParticleForce
::
DihedralTermInfo
(
ter
m
.
first
,
ter
m
.
second
,
energyExpr
.
differentiate
(
ter
m
.
first
).
optimize
().
createCompiledExpression
(),
*
this
));
for
(
auto
&
term
:
distances
)
distanceTerms
.
push_back
(
CpuCustomManyParticleForce
::
DistanceTermInfo
(
ter
m
.
first
,
ter
m
.
second
,
energyExpr
.
differentiate
(
ter
m
.
first
).
optimize
().
createCompiledExpression
(),
*
this
));
for
(
auto
&
term
:
angles
)
angleTerms
.
push_back
(
CpuCustomManyParticleForce
::
AngleTermInfo
(
ter
m
.
first
,
ter
m
.
second
,
energyExpr
.
differentiate
(
ter
m
.
first
).
optimize
().
createCompiledExpression
(),
*
this
));
for
(
auto
&
term
:
particleTerms
)
expressionSet
.
registerExpression
(
term
.
forceExpression
);
for
(
auto
&
term
:
distanceTerms
)
expressionSet
.
registerExpression
(
term
.
forceExpression
);
for
(
auto
&
term
:
angleTerms
)
expressionSet
.
registerExpression
(
term
.
forceExpression
);
for
(
auto
&
term
:
dihedralTerms
)
expressionSet
.
registerExpression
(
term
.
forceExpression
);
int
numDeltas
=
deltaPairs
.
size
();
delta
.
resize
(
numDeltas
);
normDelta
.
resize
(
numDeltas
);
...
...
platforms/cpu/src/CpuCustomNonbondedForce.cpp
View file @
08e8b206
...
...
@@ -51,9 +51,9 @@ CpuCustomNonbondedForce::ThreadData::ThreadData(const Lepton::CompiledExpression
this
->
forceExpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
energyExpression
);
expressionSet
.
registerExpression
(
this
->
forceExpression
);
for
(
int
i
=
0
;
i
<
this
->
energyParamDerivExpressions
.
size
();
i
++
)
{
this
->
energyParamDerivE
xpression
s
[
i
]
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
this
->
energyParamDerivE
xpression
s
[
i
]
);
for
(
auto
&
expression
:
this
->
energyParamDerivExpressions
)
{
e
xpression
.
setVariableLocations
(
variableLocations
);
expressionSet
.
registerExpression
(
e
xpression
);
}
}
...
...
@@ -66,8 +66,8 @@ CpuCustomNonbondedForce::CpuCustomNonbondedForce(const Lepton::CompiledExpressio
}
CpuCustomNonbondedForce
::~
CpuCustomNonbondedForce
()
{
for
(
int
i
=
0
;
i
<
(
int
)
threadData
.
size
();
i
++
)
delete
threadData
[
i
]
;
for
(
auto
data
:
threadData
)
delete
data
;
}
void
CpuCustomNonbondedForce
::
setUseCutoff
(
double
distance
,
const
CpuNeighborList
&
neighbors
)
{
...
...
@@ -78,9 +78,9 @@ void CpuCustomNonbondedForce::setUseCutoff(double distance, const CpuNeighborLis
void
CpuCustomNonbondedForce
::
setInteractionGroups
(
const
vector
<
pair
<
set
<
int
>
,
set
<
int
>
>
>&
groups
)
{
useInteractionGroups
=
true
;
for
(
int
group
=
0
;
group
<
(
int
)
groups
.
size
();
group
++
)
{
const
set
<
int
>&
set1
=
group
s
[
group
]
.
first
;
const
set
<
int
>&
set2
=
group
s
[
group
]
.
second
;
for
(
auto
&
group
:
groups
)
{
const
set
<
int
>&
set1
=
group
.
first
;
const
set
<
int
>&
set2
=
group
.
second
;
for
(
set
<
int
>::
const_iterator
atom1
=
set1
.
begin
();
atom1
!=
set1
.
end
();
++
atom1
)
{
for
(
set
<
int
>::
const_iterator
atom2
=
set2
.
begin
();
atom2
!=
set2
.
end
();
++
atom2
)
{
if
(
*
atom1
==
*
atom2
||
exclusions
[
*
atom1
].
find
(
*
atom2
)
!=
exclusions
[
*
atom1
].
end
())
...
...
@@ -167,10 +167,10 @@ void CpuCustomNonbondedForce::threadComputeForce(ThreadPool& threads, int thread
double
&
energy
=
threadEnergy
[
threadIndex
];
float
*
forces
=
&
(
*
threadForce
)[
threadIndex
][
0
];
ThreadData
&
data
=
*
threadData
[
threadIndex
];
for
(
map
<
string
,
double
>::
const_iterator
iter
=
globalParameters
->
begin
();
iter
!=
globalParameters
->
end
();
++
iter
)
data
.
expressionSet
.
setVariable
(
data
.
expressionSet
.
getVariableIndex
(
iter
->
first
),
iter
->
second
);
for
(
int
i
=
0
;
i
<
data
.
energyParamDerivs
.
size
();
i
++
)
d
ata
.
energyParamDerivs
[
i
]
=
0.0
;
for
(
auto
&
param
:
*
globalParameters
)
data
.
expressionSet
.
setVariable
(
data
.
expressionSet
.
getVariableIndex
(
param
.
first
),
param
.
second
);
for
(
auto
&
deriv
:
data
.
energyParamDerivs
)
d
eriv
=
0.0
;
fvec4
boxSize
(
periodicBoxVectors
[
0
][
0
],
periodicBoxVectors
[
1
][
1
],
periodicBoxVectors
[
2
][
2
],
0
);
fvec4
invBoxSize
(
recipBoxSize
[
0
],
recipBoxSize
[
1
],
recipBoxSize
[
2
],
0
);
if
(
useInteractionGroups
)
{
...
...
platforms/cpu/src/CpuKernels.cpp
View file @
08e8b206
...
...
@@ -98,8 +98,8 @@ static void validateVariables(const Lepton::ExpressionTreeNode& node, const set<
const
Lepton
::
Operation
&
op
=
node
.
getOperation
();
if
(
op
.
getId
()
==
Lepton
::
Operation
::
VARIABLE
&&
variables
.
find
(
op
.
getName
())
==
variables
.
end
())
throw
OpenMMException
(
"Unknown variable in expression: "
+
op
.
getName
());
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
()
.
size
();
i
++
)
validateVariables
(
node
.
getChildren
()[
i
]
,
variables
);
for
(
auto
&
child
:
node
.
getChildren
())
validateVariables
(
child
,
variables
);
}
/**
...
...
@@ -867,8 +867,8 @@ void CpuCalcCustomNonbondedForceKernel::initialize(const System& system, const C
// Delete the custom functions.
for
(
map
<
string
,
Lepton
::
CustomFunction
*>::
iterator
iter
=
functions
.
begin
();
iter
!=
functions
.
end
();
iter
++
)
delete
iter
->
second
;
for
(
auto
&
function
:
functions
)
delete
function
.
second
;
// Record information for the long range correction.
...
...
@@ -909,11 +909,11 @@ double CpuCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bool inc
nonbonded
->
setPeriodic
(
boxVectors
);
}
bool
globalParamsChanged
=
false
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
{
double
value
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
if
(
globalParamValues
[
globalParameterNames
[
i
]
]
!=
value
)
for
(
auto
&
name
:
globalParameterNames
)
{
double
value
=
context
.
getParameter
(
name
);
if
(
globalParamValues
[
name
]
!=
value
)
globalParamsChanged
=
true
;
globalParamValues
[
globalParameterNames
[
i
]
]
=
value
;
globalParamValues
[
name
]
=
value
;
}
if
(
useSwitchingFunction
)
nonbonded
->
setUseSwitchingFunction
(
switchingDistance
);
...
...
@@ -1155,8 +1155,8 @@ void CpuCalcCustomGBForceKernel::initialize(const System& system, const CustomGB
// Delete the custom functions.
for
(
map
<
string
,
Lepton
::
CustomFunction
*>::
iterator
iter
=
functions
.
begin
();
iter
!=
functions
.
end
();
iter
++
)
delete
iter
->
second
;
for
(
auto
&
function
:
functions
)
delete
function
.
second
;
ixn
=
new
CpuCustomGBForce
(
numParticles
,
exclusions
,
valueExpressions
,
valueDerivExpressions
,
valueGradientExpressions
,
valueParamDerivExpressions
,
valueNames
,
valueTypes
,
energyExpressions
,
energyDerivExpressions
,
energyGradientExpressions
,
energyParamDerivExpressions
,
energyTypes
,
particleParameterNames
,
data
.
threads
);
...
...
@@ -1174,8 +1174,8 @@ double CpuCalcCustomGBForceKernel::execute(ContextImpl& context, bool includeFor
ixn
->
setUseCutoff
(
nonbondedCutoff
,
*
data
.
neighborList
);
}
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
vector
<
double
>
energyParamDerivValues
(
energyParamDerivNames
.
size
()
+
1
,
0.0
);
ixn
->
calculateIxn
(
numParticles
,
&
data
.
posq
[
0
],
particleParamArray
,
globalParameters
,
data
.
threadForce
,
includeForces
,
includeEnergy
,
energy
,
&
energyParamDerivValues
[
0
]);
map
<
string
,
double
>&
energyParamDerivs
=
extractEnergyParameterDerivatives
(
context
);
...
...
@@ -1236,8 +1236,8 @@ void CpuCalcCustomManyParticleForceKernel::initialize(const System& system, cons
double
CpuCalcCustomManyParticleForceKernel
::
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
{
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
if
(
nonbondedMethod
==
CutoffPeriodic
)
{
Vec3
*
boxVectors
=
extractBoxVectors
(
context
);
double
minAllowedSize
=
2
*
cutoffDistance
;
...
...
platforms/cpu/src/CpuNeighborList.cpp
View file @
08e8b206
...
...
@@ -577,10 +577,10 @@ void CpuNeighborList::threadComputeNeighborList(ThreadPool& threads, int threadI
for
(
int
j
=
0
;
j
<
atomsInBlock
;
j
++
)
{
const
set
<
int
>&
atomExclusions
=
(
*
exclusions
)[
sortedAtoms
[
firstIndex
+
j
]];
char
mask
=
1
<<
j
;
for
(
set
<
int
>::
const_iterator
iter
=
atomExclusions
.
begin
();
iter
!=
atomExclusions
.
end
();
++
iter
)
{
map
<
int
,
char
>::
iterator
thisAtomFlags
=
atomFlags
.
find
(
*
iter
);
for
(
int
exclusion
:
atomExclusions
)
{
map
<
int
,
char
>::
iterator
thisAtomFlags
=
atomFlags
.
find
(
exclusion
);
if
(
thisAtomFlags
==
atomFlags
.
end
())
atomFlags
[
*
iter
]
=
mask
;
atomFlags
[
exclusion
]
=
mask
;
else
thisAtomFlags
->
second
|=
mask
;
}
...
...
platforms/cpu/src/CpuNonbondedForce.cpp
View file @
08e8b206
...
...
@@ -447,9 +447,9 @@ void CpuNonbondedForce::threadComputeDirect(ThreadPool& threads, int threadIndex
for
(
int
i
=
start
;
i
<
end
;
i
++
)
{
fvec4
posI
((
float
)
atomCoordinates
[
i
][
0
],
(
float
)
atomCoordinates
[
i
][
1
],
(
float
)
atomCoordinates
[
i
][
2
],
0.0
f
);
float
scaledChargeI
=
(
float
)
(
ONE_4PI_EPS0
*
posq
[
4
*
i
+
3
]);
for
(
set
<
int
>::
const_iterator
iter
=
exclusions
[
i
].
begin
();
iter
!=
exclusions
[
i
].
end
();
++
iter
)
{
if
(
*
iter
>
i
)
{
int
j
=
*
iter
;
for
(
int
excluded
:
exclusions
[
i
]
)
{
if
(
excluded
>
i
)
{
int
j
=
excluded
;
fvec4
deltaR
;
fvec4
posJ
((
float
)
atomCoordinates
[
j
][
0
],
(
float
)
atomCoordinates
[
j
][
1
],
(
float
)
atomCoordinates
[
j
][
2
],
0.0
f
);
float
r2
;
...
...
platforms/cpu/src/CpuRandom.cpp
View file @
08e8b206
...
...
@@ -34,8 +34,8 @@ CpuRandom::CpuRandom() : hasInitialized(false) {
}
CpuRandom
::~
CpuRandom
()
{
for
(
int
i
=
0
;
i
<
(
int
)
threadRandom
.
size
();
i
++
)
delete
threadR
andom
[
i
]
;
for
(
auto
random
:
threadRandom
)
delete
r
andom
;
}
void
CpuRandom
::
initialize
(
int
seed
,
int
numThreads
)
{
...
...
platforms/cpu/src/CpuSETTLE.cpp
View file @
08e8b206
...
...
@@ -56,8 +56,8 @@ CpuSETTLE::CpuSETTLE(const System& system, const ReferenceSETTLEAlgorithm& settl
}
CpuSETTLE
::~
CpuSETTLE
()
{
for
(
int
i
=
0
;
i
<
(
int
)
threadSettle
.
size
();
i
++
)
delete
threadS
ettle
[
i
]
;
for
(
auto
settle
:
threadSettle
)
delete
s
ettle
;
}
void
CpuSETTLE
::
apply
(
vector
<
OpenMM
::
Vec3
>&
atomCoordinates
,
vector
<
OpenMM
::
Vec3
>&
atomCoordinatesP
,
vector
<
double
>&
inverseMasses
,
double
tolerance
)
{
...
...
platforms/cuda/src/CudaContext.cpp
View file @
08e8b206
...
...
@@ -385,14 +385,14 @@ CudaContext::CudaContext(const System& system, int deviceIndex, bool useBlocking
CudaContext
::~
CudaContext
()
{
setAsCurrent
();
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
i
++
)
delete
force
s
[
i
]
;
for
(
int
i
=
0
;
i
<
(
int
)
reorderListeners
.
size
();
i
++
)
delete
reorderL
istener
s
[
i
]
;
for
(
int
i
=
0
;
i
<
(
int
)
preComputations
.
size
();
i
++
)
delete
preC
omputation
s
[
i
]
;
for
(
int
i
=
0
;
i
<
(
int
)
postComputations
.
size
();
i
++
)
delete
postC
omputation
s
[
i
]
;
for
(
auto
force
:
forces
)
delete
force
;
for
(
auto
listener
:
reorderListeners
)
delete
l
istener
;
for
(
auto
computation
:
preComputations
)
delete
c
omputation
;
for
(
auto
computation
:
postComputations
)
delete
c
omputation
;
if
(
pinnedBuffer
!=
NULL
)
cuMemFreeHost
(
pinnedBuffer
);
if
(
posq
!=
NULL
)
...
...
@@ -498,17 +498,17 @@ string CudaContext::replaceStrings(const string& input, const std::map<std::stri
symbolChars
.
insert
(
c
);
}
string
result
=
input
;
for
(
map
<
string
,
string
>::
const_iterator
iter
=
replacements
.
begin
();
iter
!=
replacements
.
end
();
iter
++
)
{
for
(
auto
&
pair
:
replacements
)
{
int
index
=
0
;
int
size
=
iter
->
first
.
size
();
int
size
=
pair
.
first
.
size
();
do
{
index
=
result
.
find
(
iter
->
first
,
index
);
index
=
result
.
find
(
pair
.
first
,
index
);
if
(
index
!=
result
.
npos
)
{
if
((
index
==
0
||
symbolChars
.
find
(
result
[
index
-
1
])
==
symbolChars
.
end
())
&&
(
index
==
result
.
size
()
-
size
||
symbolChars
.
find
(
result
[
index
+
size
])
==
symbolChars
.
end
()))
{
// We have found a complete symbol, not part of a longer symbol.
result
.
replace
(
index
,
size
,
iter
->
second
);
index
+=
iter
->
second
.
size
();
result
.
replace
(
index
,
size
,
pair
.
second
);
index
+=
pair
.
second
.
size
();
}
else
index
++
;
...
...
@@ -528,10 +528,10 @@ CUmodule CudaContext::createModule(const string source, const map<string, string
stringstream
src
;
if
(
!
options
.
empty
())
src
<<
"// Compilation Options: "
<<
options
<<
endl
<<
endl
;
for
(
map
<
string
,
string
>::
const_iterator
iter
=
compilationDefines
.
begin
();
iter
!=
compilationDefines
.
end
();
++
iter
)
{
src
<<
"#define "
<<
iter
->
first
;
if
(
!
iter
->
second
.
empty
())
src
<<
" "
<<
iter
->
second
;
for
(
auto
&
pair
:
compilationDefines
)
{
src
<<
"#define "
<<
pair
.
first
;
if
(
!
pair
.
second
.
empty
())
src
<<
" "
<<
pair
.
second
;
src
<<
endl
;
}
if
(
!
compilationDefines
.
empty
())
...
...
@@ -561,10 +561,10 @@ CUmodule CudaContext::createModule(const string source, const map<string, string
src
<<
"typedef float4 mixed4;
\n
"
;
}
src
<<
"typedef unsigned int tileflags;
\n
"
;
for
(
map
<
string
,
string
>::
const_iterator
ite
r
=
defines
.
begin
();
iter
!=
defines
.
end
();
++
iter
)
{
src
<<
"#define "
<<
iter
->
first
;
if
(
!
iter
->
second
.
empty
())
src
<<
" "
<<
iter
->
second
;
for
(
auto
&
pai
r
:
defines
)
{
src
<<
"#define "
<<
pair
.
first
;
if
(
!
pair
.
second
.
empty
())
src
<<
" "
<<
pair
.
second
;
src
<<
endl
;
}
if
(
!
defines
.
empty
())
...
...
@@ -966,10 +966,10 @@ void CudaContext::findMoleculeGroups() {
atomBonds
[
particle1
].
push_back
(
particle2
);
atomBonds
[
particle2
].
push_back
(
particle1
);
}
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
i
++
)
{
for
(
int
j
=
0
;
j
<
force
s
[
i
]
->
getNumParticleGroups
();
j
++
)
{
for
(
auto
force
:
forces
)
{
for
(
int
j
=
0
;
j
<
force
->
getNumParticleGroups
();
j
++
)
{
vector
<
int
>
particles
;
force
s
[
i
]
->
getParticlesInGroup
(
j
,
particles
);
force
->
getParticlesInGroup
(
j
,
particles
);
for
(
int
k
=
0
;
k
<
(
int
)
particles
.
size
();
k
++
)
for
(
int
m
=
0
;
m
<
(
int
)
particles
.
size
();
m
++
)
if
(
k
!=
m
)
...
...
@@ -1187,8 +1187,8 @@ bool CudaContext::invalidateMolecules(CudaForceInfo* force) {
}
atomIndexDevice
->
upload
(
atomIndex
);
findMoleculeGroups
();
for
(
int
i
=
0
;
i
<
(
int
)
reorderListeners
.
size
();
i
++
)
reorderL
istener
s
[
i
]
->
execute
();
for
(
auto
listener
:
reorderListeners
)
l
istener
->
execute
();
reorderAtoms
();
return
true
;
}
...
...
@@ -1250,10 +1250,9 @@ void CudaContext::reorderAtomsImpl() {
vector
<
Real4
>
newPosqCorrection
(
paddedNumAtoms
);
vector
<
Mixed4
>
newVelm
(
paddedNumAtoms
);
vector
<
int4
>
newCellOffsets
(
numAtoms
);
for
(
int
group
=
0
;
group
<
(
int
)
moleculeGroups
.
size
();
group
++
)
{
for
(
auto
&
mol
:
moleculeGroups
)
{
// Find the center of each molecule.
MoleculeGroup
&
mol
=
moleculeGroups
[
group
];
int
numMolecules
=
mol
.
offsets
.
size
();
vector
<
int
>&
atoms
=
mol
.
atoms
;
vector
<
Real4
>
molPos
(
numMolecules
);
...
...
@@ -1347,9 +1346,9 @@ void CudaContext::reorderAtomsImpl() {
// Reorder the atoms.
for
(
int
i
=
0
;
i
<
numMolecules
;
i
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
atoms
.
size
();
j
++
)
{
int
oldIndex
=
mol
.
offsets
[
molBins
[
i
].
second
]
+
atom
s
[
j
]
;
int
newIndex
=
mol
.
offsets
[
i
]
+
atom
s
[
j
]
;
for
(
int
atom
:
atoms
)
{
int
oldIndex
=
mol
.
offsets
[
molBins
[
i
].
second
]
+
atom
;
int
newIndex
=
mol
.
offsets
[
i
]
+
atom
;
originalIndex
[
newIndex
]
=
atomIndex
[
oldIndex
];
newPosq
[
newIndex
]
=
oldPosq
[
oldIndex
];
if
(
useMixedPrecision
)
...
...
@@ -1371,8 +1370,8 @@ void CudaContext::reorderAtomsImpl() {
posqCorrection
->
upload
(
newPosqCorrection
);
velm
->
upload
(
newVelm
);
atomIndexDevice
->
upload
(
atomIndex
);
for
(
int
i
=
0
;
i
<
(
int
)
reorderListeners
.
size
();
i
++
)
reorderL
istener
s
[
i
]
->
execute
();
for
(
auto
listener
:
reorderListeners
)
l
istener
->
execute
();
}
void
CudaContext
::
addReorderListener
(
ReorderListener
*
listener
)
{
...
...
platforms/cuda/src/CudaExpressionUtilities.cpp
View file @
08e8b206
...
...
@@ -456,12 +456,12 @@ void CudaExpressionUtilities::processExpression(stringstream& out, const Express
vector
<
bool
>
hasAssigned
(
powers
.
size
(),
false
);
exponents
.
push_back
((
int
)
fabs
(
exponent
));
names
.
push_back
(
name
);
for
(
map
<
int
,
const
ExpressionTreeNode
*>::
const_iterator
iter
=
powers
.
begin
();
iter
!=
powers
.
end
();
++
iter
)
{
if
(
iter
->
first
!=
exponent
)
{
exponents
.
push_back
(
iter
->
first
>=
0
?
iter
->
first
:
-
iter
->
first
);
for
(
auto
&
power
:
powers
)
{
if
(
power
.
first
!=
exponent
)
{
exponents
.
push_back
(
power
.
first
>=
0
?
power
.
first
:
-
power
.
first
);
string
name2
=
prefix
+
context
.
intToString
(
temps
.
size
());
names
.
push_back
(
name2
);
temps
.
push_back
(
make_pair
(
*
iter
->
second
,
name2
));
temps
.
push_back
(
make_pair
(
*
power
.
second
,
name2
));
out
<<
tempType
<<
" "
<<
name2
<<
" = 0.0f;
\n
"
;
}
}
...
...
platforms/cuda/src/CudaKernels.cpp
View file @
08e8b206
This diff is collapsed.
Click to expand it.
platforms/opencl/src/OpenCLBondedUtilities.cpp
View file @
08e8b206
...
...
@@ -184,8 +184,7 @@ void OpenCLBondedUtilities::initialize(const System& system) {
// Create the kernels.
for
(
vector
<
vector
<
int
>
>::
const_iterator
iter
=
forceSets
.
begin
();
iter
!=
forceSets
.
end
();
++
iter
)
{
const
vector
<
int
>&
set
=
*
iter
;
for
(
auto
&
set
:
forceSets
)
{
int
setSize
=
set
.
size
();
stringstream
s
;
s
<<
"#ifdef SUPPORTS_64_BIT_ATOMICS
\n
"
;
...
...
platforms/opencl/src/OpenCLContext.cpp
View file @
08e8b206
...
...
@@ -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) 2009-201
6
Stanford University and the Authors. *
* Portions copyright (c) 2009-201
7
Stanford University and the Authors. *
* Authors: Peter Eastman *
* Contributors: *
* *
...
...
@@ -318,8 +318,8 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
OpenCLArray
valuesArray
(
*
this
,
20
,
sizeof
(
mm_float8
),
"values"
);
vector
<
mm_float8
>
values
(
valuesArray
.
getSize
());
float
nextValue
=
1e-4
f
;
for
(
int
i
=
0
;
i
<
(
int
)
values
.
size
();
++
i
)
{
val
ues
[
i
]
.
s0
=
nextValue
;
for
(
auto
&
val
:
values
)
{
val
.
s0
=
nextValue
;
nextValue
*=
(
float
)
M_PI
;
}
valuesArray
.
upload
(
values
);
...
...
@@ -328,14 +328,14 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
executeKernel
(
accuracyKernel
,
values
.
size
());
valuesArray
.
download
(
values
);
double
maxSqrtError
=
0.0
,
maxRsqrtError
=
0.0
,
maxRecipError
=
0.0
,
maxExpError
=
0.0
,
maxLogError
=
0.0
;
for
(
int
i
=
0
;
i
<
(
int
)
values
.
size
();
++
i
)
{
double
v
=
val
ues
[
i
]
.
s0
;
for
(
auto
&
val
:
values
)
{
double
v
=
val
.
s0
;
double
correctSqrt
=
sqrt
(
v
);
maxSqrtError
=
max
(
maxSqrtError
,
fabs
(
correctSqrt
-
val
ues
[
i
]
.
s1
)
/
correctSqrt
);
maxRsqrtError
=
max
(
maxRsqrtError
,
fabs
(
1.0
/
correctSqrt
-
val
ues
[
i
]
.
s2
)
*
correctSqrt
);
maxRecipError
=
max
(
maxRecipError
,
fabs
(
1.0
/
v
-
val
ues
[
i
]
.
s3
)
/
val
ues
[
i
]
.
s3
);
maxExpError
=
max
(
maxExpError
,
fabs
(
exp
(
v
)
-
val
ues
[
i
]
.
s4
)
/
val
ues
[
i
]
.
s4
);
maxLogError
=
max
(
maxLogError
,
fabs
(
log
(
v
)
-
val
ues
[
i
]
.
s5
)
/
val
ues
[
i
]
.
s5
);
maxSqrtError
=
max
(
maxSqrtError
,
fabs
(
correctSqrt
-
val
.
s1
)
/
correctSqrt
);
maxRsqrtError
=
max
(
maxRsqrtError
,
fabs
(
1.0
/
correctSqrt
-
val
.
s2
)
*
correctSqrt
);
maxRecipError
=
max
(
maxRecipError
,
fabs
(
1.0
/
v
-
val
.
s3
)
/
val
.
s3
);
maxExpError
=
max
(
maxExpError
,
fabs
(
exp
(
v
)
-
val
.
s4
)
/
val
.
s4
);
maxLogError
=
max
(
maxLogError
,
fabs
(
log
(
v
)
-
val
.
s5
)
/
val
.
s5
);
}
compilationDefines
[
"SQRT"
]
=
(
maxSqrtError
<
1e-6
)
?
"native_sqrt"
:
"sqrt"
;
compilationDefines
[
"RSQRT"
]
=
(
maxRsqrtError
<
1e-6
)
?
"native_rsqrt"
:
"rsqrt"
;
...
...
@@ -412,14 +412,14 @@ OpenCLContext::OpenCLContext(const System& system, int platformIndex, int device
}
OpenCLContext
::~
OpenCLContext
()
{
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
i
++
)
delete
force
s
[
i
]
;
for
(
int
i
=
0
;
i
<
(
int
)
reorderListeners
.
size
();
i
++
)
delete
reorderL
istener
s
[
i
]
;
for
(
int
i
=
0
;
i
<
(
int
)
preComputations
.
size
();
i
++
)
delete
preC
omputation
s
[
i
]
;
for
(
int
i
=
0
;
i
<
(
int
)
postComputations
.
size
();
i
++
)
delete
postC
omputation
s
[
i
]
;
for
(
auto
force
:
forces
)
delete
force
;
for
(
auto
listener
:
reorderListeners
)
delete
l
istener
;
for
(
auto
computation
:
preComputations
)
delete
c
omputation
;
for
(
auto
computation
:
postComputations
)
delete
c
omputation
;
if
(
pinnedBuffer
!=
NULL
)
delete
pinnedBuffer
;
if
(
posq
!=
NULL
)
...
...
@@ -458,8 +458,8 @@ void OpenCLContext::initialize() {
bonded
->
initialize
(
system
);
numForceBuffers
=
platformData
.
contexts
.
size
();
numForceBuffers
=
std
::
max
(
numForceBuffers
,
bonded
->
getNumForceBuffers
());
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
i
++
)
numForceBuffers
=
std
::
max
(
numForceBuffers
,
force
s
[
i
]
->
getRequiredForceBuffers
());
for
(
auto
force
:
forces
)
numForceBuffers
=
std
::
max
(
numForceBuffers
,
force
->
getRequiredForceBuffers
());
int
energyBufferSize
=
max
(
numThreadBlocks
*
ThreadBlockSize
,
nonbonded
->
getNumEnergyBuffers
());
if
(
useDoublePrecision
)
{
forceBuffers
=
OpenCLArray
::
create
<
mm_double4
>
(
*
this
,
paddedNumAtoms
*
numForceBuffers
,
"forceBuffers"
);
...
...
@@ -525,17 +525,17 @@ string OpenCLContext::replaceStrings(const string& input, const std::map<std::st
symbolChars
.
insert
(
c
);
}
string
result
=
input
;
for
(
map
<
string
,
string
>::
const_iterator
iter
=
replacements
.
begin
();
iter
!=
replacements
.
end
();
iter
++
)
{
for
(
auto
&
pair
:
replacements
)
{
int
index
=
0
;
int
size
=
iter
->
first
.
size
();
int
size
=
pair
.
first
.
size
();
do
{
index
=
result
.
find
(
iter
->
first
,
index
);
index
=
result
.
find
(
pair
.
first
,
index
);
if
(
index
!=
result
.
npos
)
{
if
((
index
==
0
||
symbolChars
.
find
(
result
[
index
-
1
])
==
symbolChars
.
end
())
&&
(
index
==
result
.
size
()
-
size
||
symbolChars
.
find
(
result
[
index
+
size
])
==
symbolChars
.
end
()))
{
// We have found a complete symbol, not part of a longer symbol.
result
.
replace
(
index
,
size
,
iter
->
second
);
index
+=
iter
->
second
.
size
();
result
.
replace
(
index
,
size
,
pair
.
second
);
index
+=
pair
.
second
.
size
();
}
else
index
++
;
...
...
@@ -554,10 +554,10 @@ cl::Program OpenCLContext::createProgram(const string source, const map<string,
stringstream
src
;
if
(
!
options
.
empty
())
src
<<
"// Compilation Options: "
<<
options
<<
endl
<<
endl
;
for
(
map
<
string
,
string
>::
const_iterator
iter
=
compilationDefines
.
begin
();
iter
!=
compilationDefines
.
end
();
++
iter
)
{
src
<<
"#define "
<<
iter
->
first
;
if
(
!
iter
->
second
.
empty
())
src
<<
" "
<<
iter
->
second
;
for
(
auto
&
pair
:
compilationDefines
)
{
src
<<
"#define "
<<
pair
.
first
;
if
(
!
pair
.
second
.
empty
())
src
<<
" "
<<
pair
.
second
;
src
<<
endl
;
}
if
(
!
compilationDefines
.
empty
())
...
...
@@ -588,10 +588,10 @@ cl::Program OpenCLContext::createProgram(const string source, const map<string,
src
<<
"typedef float3 mixed3;
\n
"
;
src
<<
"typedef float4 mixed4;
\n
"
;
}
for
(
map
<
string
,
string
>::
const_iterator
ite
r
=
defines
.
begin
();
iter
!=
defines
.
end
();
++
iter
)
{
src
<<
"#define "
<<
iter
->
first
;
if
(
!
iter
->
second
.
empty
())
src
<<
" "
<<
iter
->
second
;
for
(
auto
&
pai
r
:
defines
)
{
src
<<
"#define "
<<
pair
.
first
;
if
(
!
pair
.
second
.
empty
())
src
<<
" "
<<
pair
.
second
;
src
<<
endl
;
}
if
(
!
defines
.
empty
())
...
...
@@ -856,10 +856,10 @@ void OpenCLContext::findMoleculeGroups() {
atomBonds
[
particle1
].
push_back
(
particle2
);
atomBonds
[
particle2
].
push_back
(
particle1
);
}
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
i
++
)
{
for
(
int
j
=
0
;
j
<
force
s
[
i
]
->
getNumParticleGroups
();
j
++
)
{
for
(
auto
force
:
forces
)
{
for
(
int
j
=
0
;
j
<
force
->
getNumParticleGroups
();
j
++
)
{
vector
<
int
>
particles
;
force
s
[
i
]
->
getParticlesInGroup
(
j
,
particles
);
force
->
getParticlesInGroup
(
j
,
particles
);
for
(
int
k
=
0
;
k
<
(
int
)
particles
.
size
();
k
++
)
for
(
int
m
=
0
;
m
<
(
int
)
particles
.
size
();
m
++
)
if
(
k
!=
m
)
...
...
@@ -1076,8 +1076,8 @@ bool OpenCLContext::invalidateMolecules(OpenCLForceInfo* force) {
}
atomIndexDevice
->
upload
(
atomIndex
);
findMoleculeGroups
();
for
(
int
i
=
0
;
i
<
(
int
)
reorderListeners
.
size
();
i
++
)
reorderL
istener
s
[
i
]
->
execute
();
for
(
auto
listener
:
reorderListeners
)
l
istener
->
execute
();
reorderAtoms
();
return
true
;
}
...
...
@@ -1138,10 +1138,9 @@ void OpenCLContext::reorderAtomsImpl() {
vector
<
Real4
>
newPosqCorrection
(
paddedNumAtoms
,
Real4
(
0
,
0
,
0
,
0
));
vector
<
Mixed4
>
newVelm
(
paddedNumAtoms
,
Mixed4
(
0
,
0
,
0
,
0
));
vector
<
mm_int4
>
newCellOffsets
(
numAtoms
);
for
(
int
group
=
0
;
group
<
(
int
)
moleculeGroups
.
size
();
group
++
)
{
for
(
auto
&
mol
:
moleculeGroups
)
{
// Find the center of each molecule.
MoleculeGroup
&
mol
=
moleculeGroups
[
group
];
int
numMolecules
=
mol
.
offsets
.
size
();
vector
<
int
>&
atoms
=
mol
.
atoms
;
vector
<
Real4
>
molPos
(
numMolecules
);
...
...
@@ -1235,9 +1234,9 @@ void OpenCLContext::reorderAtomsImpl() {
// Reorder the atoms.
for
(
int
i
=
0
;
i
<
numMolecules
;
i
++
)
{
for
(
int
j
=
0
;
j
<
(
int
)
atoms
.
size
();
j
++
)
{
int
oldIndex
=
mol
.
offsets
[
molBins
[
i
].
second
]
+
atom
s
[
j
]
;
int
newIndex
=
mol
.
offsets
[
i
]
+
atom
s
[
j
]
;
for
(
int
atom
:
atoms
)
{
int
oldIndex
=
mol
.
offsets
[
molBins
[
i
].
second
]
+
atom
;
int
newIndex
=
mol
.
offsets
[
i
]
+
atom
;
originalIndex
[
newIndex
]
=
atomIndex
[
oldIndex
];
newPosq
[
newIndex
]
=
oldPosq
[
oldIndex
];
if
(
useMixedPrecision
)
...
...
@@ -1259,8 +1258,8 @@ void OpenCLContext::reorderAtomsImpl() {
posqCorrection
->
upload
(
newPosqCorrection
);
velm
->
upload
(
newVelm
);
atomIndexDevice
->
upload
(
atomIndex
);
for
(
int
i
=
0
;
i
<
(
int
)
reorderListeners
.
size
();
i
++
)
reorderL
istener
s
[
i
]
->
execute
();
for
(
auto
listener
:
reorderListeners
)
l
istener
->
execute
();
}
void
OpenCLContext
::
addReorderListener
(
ReorderListener
*
listener
)
{
...
...
platforms/opencl/src/OpenCLExpressionUtilities.cpp
View file @
08e8b206
...
...
@@ -448,12 +448,12 @@ void OpenCLExpressionUtilities::processExpression(stringstream& out, const Expre
vector
<
bool
>
hasAssigned
(
powers
.
size
(),
false
);
exponents
.
push_back
((
int
)
fabs
(
exponent
));
names
.
push_back
(
name
);
for
(
map
<
int
,
const
ExpressionTreeNode
*>::
const_iterator
iter
=
powers
.
begin
();
iter
!=
powers
.
end
();
++
iter
)
{
if
(
iter
->
first
!=
exponent
)
{
exponents
.
push_back
(
iter
->
first
>=
0
?
iter
->
first
:
-
iter
->
first
);
for
(
auto
&
power
:
powers
)
{
if
(
power
.
first
!=
exponent
)
{
exponents
.
push_back
(
power
.
first
>=
0
?
power
.
first
:
-
power
.
first
);
string
name2
=
prefix
+
context
.
intToString
(
temps
.
size
());
names
.
push_back
(
name2
);
temps
.
push_back
(
make_pair
(
*
iter
->
second
,
name2
));
temps
.
push_back
(
make_pair
(
*
power
.
second
,
name2
));
out
<<
tempType
<<
" "
<<
name2
<<
" = 0.0f;
\n
"
;
}
}
...
...
platforms/opencl/src/OpenCLKernels.cpp
View file @
08e8b206
This diff is collapsed.
Click to expand it.
platforms/reference/src/ReferenceKernels.cpp
View file @
08e8b206
...
...
@@ -159,8 +159,8 @@ static void validateVariables(const Lepton::ExpressionTreeNode& node, const set<
const
Lepton
::
Operation
&
op
=
node
.
getOperation
();
if
(
op
.
getId
()
==
Lepton
::
Operation
::
VARIABLE
&&
variables
.
find
(
op
.
getName
())
==
variables
.
end
())
throw
OpenMMException
(
"Unknown variable in expression: "
+
op
.
getName
());
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
()
.
size
();
i
++
)
validateVariables
(
node
.
getChildren
()[
i
]
,
variables
);
for
(
auto
&
child
:
node
.
getChildren
())
validateVariables
(
child
,
variables
);
}
/**
...
...
@@ -214,8 +214,8 @@ void ReferenceCalcForcesAndEnergyKernel::beginComputation(ContextImpl& context,
}
else
savedForces
=
forceData
;
for
(
map
<
string
,
double
>::
const_iterator
iter
=
context
.
getParameters
().
begin
();
iter
!=
context
.
getParameters
()
.
end
();
++
iter
)
extractEnergyParameterDerivatives
(
context
)[
iter
->
first
]
=
0
;
for
(
auto
&
param
:
context
.
getParameters
())
extractEnergyParameterDerivatives
(
context
)[
param
.
first
]
=
0
;
}
double
ReferenceCalcForcesAndEnergyKernel
::
finishComputation
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
,
int
groups
,
bool
&
valid
)
{
...
...
@@ -466,8 +466,8 @@ double ReferenceCalcCustomBondForceKernel::execute(ContextImpl& context, bool in
vector
<
Vec3
>&
forceData
=
extractForces
(
context
);
double
energy
=
0
;
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
ReferenceCustomBondIxn
bond
(
energyExpression
,
forceExpression
,
parameterNames
,
globalParameters
,
energyParamDerivExpressions
);
if
(
usePeriodic
)
bond
.
setPeriodic
(
extractBoxVectors
(
context
));
...
...
@@ -600,8 +600,8 @@ double ReferenceCalcCustomAngleForceKernel::execute(ContextImpl& context, bool i
vector
<
Vec3
>&
forceData
=
extractForces
(
context
);
double
energy
=
0
;
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
ReferenceCustomAngleIxn
customAngle
(
energyExpression
,
forceExpression
,
parameterNames
,
globalParameters
,
energyParamDerivExpressions
);
if
(
usePeriodic
)
customAngle
.
setPeriodic
(
extractBoxVectors
(
context
));
...
...
@@ -870,8 +870,8 @@ double ReferenceCalcCustomTorsionForceKernel::execute(ContextImpl& context, bool
vector
<
Vec3
>&
forceData
=
extractForces
(
context
);
double
energy
=
0
;
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
ReferenceCustomTorsionIxn
customTorsion
(
energyExpression
,
forceExpression
,
parameterNames
,
globalParameters
,
energyParamDerivExpressions
);
if
(
usePeriodic
)
customTorsion
.
setPeriodic
(
extractBoxVectors
(
context
));
...
...
@@ -1165,8 +1165,8 @@ void ReferenceCalcCustomNonbondedForceKernel::initialize(const System& system, c
// Delete the custom functions.
for
(
map
<
string
,
Lepton
::
CustomFunction
*>::
iterator
iter
=
functions
.
begin
();
iter
!=
functions
.
end
();
iter
++
)
delete
iter
->
second
;
for
(
auto
&
function
:
functions
)
delete
function
.
second
;
// Record information for the long range correction.
...
...
@@ -1208,11 +1208,11 @@ double ReferenceCalcCustomNonbondedForceKernel::execute(ContextImpl& context, bo
if
(
interactionGroups
.
size
()
>
0
)
ixn
.
setInteractionGroups
(
interactionGroups
);
bool
globalParamsChanged
=
false
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
{
double
value
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
if
(
globalParamValues
[
globalParameterNames
[
i
]
]
!=
value
)
for
(
auto
&
name
:
globalParameterNames
)
{
double
value
=
context
.
getParameter
(
name
);
if
(
globalParamValues
[
name
]
!=
value
)
globalParamsChanged
=
true
;
globalParamValues
[
globalParameterNames
[
i
]
]
=
value
;
globalParamValues
[
name
]
=
value
;
}
if
(
useSwitchingFunction
)
ixn
.
setUseSwitchingFunction
(
switchingDistance
);
...
...
@@ -1459,8 +1459,8 @@ void ReferenceCalcCustomGBForceKernel::initialize(const System& system, const Cu
// Delete the custom functions.
for
(
map
<
string
,
Lepton
::
CustomFunction
*>::
iterator
iter
=
functions
.
begin
();
iter
!=
functions
.
end
();
iter
++
)
delete
iter
->
second
;
for
(
auto
&
function
:
functions
)
delete
function
.
second
;
}
double
ReferenceCalcCustomGBForceKernel
::
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
{
...
...
@@ -1477,8 +1477,8 @@ double ReferenceCalcCustomGBForceKernel::execute(ContextImpl& context, bool incl
ixn
.
setUseCutoff
(
nonbondedCutoff
,
*
neighborList
);
}
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
vector
<
double
>
energyParamDerivValues
(
energyParamDerivNames
.
size
()
+
1
,
0.0
);
ixn
.
calculateIxn
(
numParticles
,
posData
,
particleParamArray
,
exclusions
,
globalParameters
,
forceData
,
includeEnergy
?
&
energy
:
NULL
,
&
energyParamDerivValues
[
0
]);
map
<
string
,
double
>&
energyParamDerivs
=
extractEnergyParameterDerivatives
(
context
);
...
...
@@ -1593,8 +1593,8 @@ double ReferenceCalcCustomExternalForceKernel::execute(ContextImpl& context, boo
boxVectors
=
extractBoxVectors
(
context
);
double
energy
=
0
;
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
ReferenceCustomExternalIxn
force
(
energyExpression
,
forceExpressionX
,
forceExpressionY
,
forceExpressionZ
,
parameterNames
,
globalParameters
);
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
force
.
calculateForce
(
particles
[
i
],
posData
,
particleParamArray
[
i
],
forceData
,
includeEnergy
?
&
energy
:
NULL
);
...
...
@@ -1699,8 +1699,8 @@ void ReferenceCalcCustomHbondForceKernel::initialize(const System& system, const
// Delete the custom functions.
for
(
map
<
string
,
Lepton
::
CustomFunction
*>::
iterator
iter
=
functions
.
begin
();
iter
!=
functions
.
end
();
iter
++
)
delete
iter
->
second
;
for
(
auto
&
function
:
functions
)
delete
function
.
second
;
}
double
ReferenceCalcCustomHbondForceKernel
::
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
{
...
...
@@ -1710,8 +1710,8 @@ double ReferenceCalcCustomHbondForceKernel::execute(ContextImpl& context, bool i
ixn
->
setPeriodic
(
extractBoxVectors
(
context
));
double
energy
=
0
;
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
ixn
->
calculatePairIxn
(
posData
,
donorParamArray
,
acceptorParamArray
,
exclusions
,
globalParameters
,
forceData
,
includeEnergy
?
&
energy
:
NULL
);
return
energy
;
}
...
...
@@ -1803,8 +1803,8 @@ void ReferenceCalcCustomCentroidBondForceKernel::initialize(const System& system
// Delete the custom functions.
for
(
map
<
string
,
Lepton
::
CustomFunction
*>::
iterator
iter
=
functions
.
begin
();
iter
!=
functions
.
end
();
iter
++
)
delete
iter
->
second
;
for
(
auto
&
function
:
functions
)
delete
function
.
second
;
}
double
ReferenceCalcCustomCentroidBondForceKernel
::
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
{
...
...
@@ -1812,8 +1812,8 @@ double ReferenceCalcCustomCentroidBondForceKernel::execute(ContextImpl& context,
vector
<
Vec3
>&
forceData
=
extractForces
(
context
);
double
energy
=
0
;
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
if
(
usePeriodic
)
ixn
->
setPeriodic
(
extractBoxVectors
(
context
));
vector
<
double
>
energyParamDerivValues
(
energyParamDerivNames
.
size
()
+
1
,
0.0
);
...
...
@@ -1893,8 +1893,8 @@ void ReferenceCalcCustomCompoundBondForceKernel::initialize(const System& system
// Delete the custom functions.
for
(
map
<
string
,
Lepton
::
CustomFunction
*>::
iterator
iter
=
functions
.
begin
();
iter
!=
functions
.
end
();
iter
++
)
delete
iter
->
second
;
for
(
auto
&
function
:
functions
)
delete
function
.
second
;
}
double
ReferenceCalcCustomCompoundBondForceKernel
::
execute
(
ContextImpl
&
context
,
bool
includeForces
,
bool
includeEnergy
)
{
...
...
@@ -1902,8 +1902,8 @@ double ReferenceCalcCustomCompoundBondForceKernel::execute(ContextImpl& context,
vector
<
Vec3
>&
forceData
=
extractForces
(
context
);
double
energy
=
0
;
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
if
(
usePeriodic
)
ixn
->
setPeriodic
(
extractBoxVectors
(
context
));
vector
<
double
>
energyParamDerivValues
(
energyParamDerivNames
.
size
()
+
1
,
0.0
);
...
...
@@ -1966,8 +1966,8 @@ double ReferenceCalcCustomManyParticleForceKernel::execute(ContextImpl& context,
vector
<
Vec3
>&
forceData
=
extractForces
(
context
);
double
energy
=
0
;
map
<
string
,
double
>
globalParameters
;
for
(
int
i
=
0
;
i
<
(
int
)
globalParameterNames
.
size
();
i
++
)
globalParameters
[
globalParameterNames
[
i
]
]
=
context
.
getParameter
(
globalParameterNames
[
i
]
);
for
(
auto
&
name
:
globalParameterNames
)
globalParameters
[
name
]
=
context
.
getParameter
(
name
);
if
(
nonbondedMethod
==
CutoffPeriodic
)
{
Vec3
*
boxVectors
=
extractBoxVectors
(
context
);
double
minAllowedSize
=
2
*
cutoffDistance
;
...
...
@@ -2232,8 +2232,8 @@ void ReferenceIntegrateCustomStepKernel::initialize(const System& system, const
for
(
int
i
=
0
;
i
<
numParticles
;
++
i
)
masses
[
i
]
=
system
.
getParticleMass
(
i
);
perDofValues
.
resize
(
integrator
.
getNumPerDofVariables
());
for
(
int
i
=
0
;
i
<
(
int
)
perDofValues
.
size
();
i
++
)
perDofV
alues
[
i
]
.
resize
(
numParticles
);
for
(
auto
&
values
:
perDofValues
)
v
alues
.
resize
(
numParticles
);
// Create the computation objects.
...
...
platforms/reference/src/SimTKReference/ReferenceAndersenThermostat.cpp
View file @
08e8b206
...
...
@@ -66,13 +66,12 @@ using namespace OpenMM;
double
temperature
,
double
collisionFrequency
,
double
stepSize
)
const
{
const
double
collisionProbability
=
1.0
f
-
exp
(
-
collisionFrequency
*
stepSize
);
for
(
int
i
=
0
;
i
<
(
int
)
atomGroups
.
size
();
++
i
)
{
for
(
auto
&
group
:
atomGroups
)
{
if
(
SimTKOpenMMUtilities
::
getUniformlyDistributedRandomNumber
()
<
collisionProbability
)
{
// A collision occurred, so set the velocities to new values chosen from a Boltzmann distribution.
for
(
int
j
=
0
;
j
<
(
int
)
atomGroups
[
i
].
size
();
j
++
)
{
int
atom
=
atomGroups
[
i
][
j
];
for
(
int
atom
:
group
)
{
if
(
atomMasses
[
atom
]
!=
0
)
{
const
double
velocityScale
=
static_cast
<
double
>
(
sqrt
(
BOLTZ
*
temperature
/
atomMasses
[
atom
]));
atomVelocities
[
atom
][
0
]
=
velocityScale
*
SimTKOpenMMUtilities
::
getNormallyDistributedRandomNumber
();
...
...
platforms/reference/src/SimTKReference/ReferenceCCMAAlgorithm.cpp
View file @
08e8b206
...
...
@@ -127,8 +127,8 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
// We didn't find one, so look for an angle force field term.
const
vector
<
int
>&
angleCandidates
=
atomAngles
[
atomb
];
for
(
vector
<
int
>::
const_iterator
iter
=
angleCandidates
.
begin
();
iter
!=
angleCandidates
.
end
();
iter
++
)
{
const
AngleInfo
&
angle
=
angles
[
*
i
te
r
];
for
(
int
candidate
:
angleCandidates
)
{
const
AngleInfo
&
angle
=
angles
[
candida
te
];
if
((
angle
.
atom1
==
atoma
&&
angle
.
atom3
==
atomc
)
||
(
angle
.
atom3
==
atoma
&&
angle
.
atom1
==
atomc
))
{
matrix
[
j
].
push_back
(
pair
<
int
,
double
>
(
k
,
scale
*
cos
(
angle
.
angle
)));
break
;
...
...
@@ -145,8 +145,7 @@ ReferenceCCMAAlgorithm::ReferenceCCMAAlgorithm(int numberOfAtoms,
vector
<
double
>
matrixValue
;
for
(
int
i
=
0
;
i
<
numberOfConstraints
;
i
++
)
{
matrixRowStart
.
push_back
(
matrixValue
.
size
());
for
(
int
j
=
0
;
j
<
(
int
)
matrix
[
i
].
size
();
j
++
)
{
pair
<
int
,
double
>
element
=
matrix
[
i
][
j
];
for
(
auto
&
element
:
matrix
[
i
])
{
matrixColIndex
.
push_back
(
element
.
first
);
matrixValue
.
push_back
(
element
.
second
);
}
...
...
@@ -292,10 +291,8 @@ void ReferenceCCMAAlgorithm::applyConstraints(vector<Vec3>& atomCoordinates,
if
(
_matrix
.
size
()
>
0
)
{
for
(
int
i
=
0
;
i
<
_numberOfConstraints
;
i
++
)
{
double
sum
=
0.0
;
for
(
int
j
=
0
;
j
<
(
int
)
_matrix
[
i
].
size
();
j
++
)
{
pair
<
int
,
double
>
element
=
_matrix
[
i
][
j
];
for
(
auto
&
element
:
_matrix
[
i
])
sum
+=
element
.
second
*
constraintDelta
[
element
.
first
];
}
tempDelta
[
i
]
=
sum
;
}
constraintDelta
=
tempDelta
;
...
...
Prev
1
2
3
4
5
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