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
Hide whitespace changes
Inline
Side-by-side
Showing
20 changed files
with
145 additions
and
156 deletions
+145
-156
olla/src/Platform.cpp
olla/src/Platform.cpp
+19
-19
openmmapi/src/AndersenThermostatImpl.cpp
openmmapi/src/AndersenThermostatImpl.cpp
+3
-3
openmmapi/src/CompiledExpressionSet.cpp
openmmapi/src/CompiledExpressionSet.cpp
+5
-5
openmmapi/src/Context.cpp
openmmapi/src/Context.cpp
+10
-12
openmmapi/src/ContextImpl.cpp
openmmapi/src/ContextImpl.cpp
+20
-20
openmmapi/src/CustomCentroidBondForce.cpp
openmmapi/src/CustomCentroidBondForce.cpp
+2
-2
openmmapi/src/CustomCentroidBondForceImpl.cpp
openmmapi/src/CustomCentroidBondForceImpl.cpp
+8
-8
openmmapi/src/CustomCompoundBondForce.cpp
openmmapi/src/CustomCompoundBondForce.cpp
+2
-2
openmmapi/src/CustomCompoundBondForceImpl.cpp
openmmapi/src/CustomCompoundBondForceImpl.cpp
+5
-5
openmmapi/src/CustomGBForce.cpp
openmmapi/src/CustomGBForce.cpp
+2
-2
openmmapi/src/CustomHbondForce.cpp
openmmapi/src/CustomHbondForce.cpp
+2
-2
openmmapi/src/CustomHbondForceImpl.cpp
openmmapi/src/CustomHbondForceImpl.cpp
+2
-2
openmmapi/src/CustomIntegrator.cpp
openmmapi/src/CustomIntegrator.cpp
+3
-4
openmmapi/src/CustomIntegratorUtilities.cpp
openmmapi/src/CustomIntegratorUtilities.cpp
+7
-12
openmmapi/src/CustomManyParticleForce.cpp
openmmapi/src/CustomManyParticleForce.cpp
+11
-12
openmmapi/src/CustomManyParticleForceImpl.cpp
openmmapi/src/CustomManyParticleForceImpl.cpp
+5
-5
openmmapi/src/CustomNonbondedForce.cpp
openmmapi/src/CustomNonbondedForce.cpp
+13
-14
openmmapi/src/Force.cpp
openmmapi/src/Force.cpp
+6
-8
openmmapi/src/NonbondedForce.cpp
openmmapi/src/NonbondedForce.cpp
+16
-15
openmmapi/src/System.cpp
openmmapi/src/System.cpp
+4
-4
No files found.
olla/src/Platform.cpp
View file @
08e8b206
...
...
@@ -70,10 +70,10 @@ static int platformInitializer = registerPlatforms();
Platform
::~
Platform
()
{
set
<
KernelFactory
*>
uniqueKernelFactories
;
for
(
map
<
string
,
KernelFactory
*>::
const_iterator
iter
=
kernelFactories
.
begin
();
iter
!=
kernelFactories
.
end
();
++
iter
)
uniqueKernelFactories
.
insert
(
iter
->
second
);
for
(
set
<
KernelFactory
*>::
const_iterator
iter
=
uniqueKernelFactories
.
begin
();
iter
!=
uniqueKernelFactories
.
end
();
++
iter
)
delete
*
iter
;
for
(
auto
&
factory
:
kernelFactories
)
uniqueKernelFactories
.
insert
(
factory
.
second
);
for
(
auto
factory
:
uniqueKernelFactories
)
delete
factory
;
}
const
vector
<
string
>&
Platform
::
getPropertyNames
()
const
{
...
...
@@ -102,8 +102,8 @@ void Platform::setPropertyDefaultValue(const string& property, const string& val
string
propertyName
=
property
;
if
(
deprecatedPropertyReplacements
.
find
(
property
)
!=
deprecatedPropertyReplacements
.
end
())
propertyName
=
deprecatedPropertyReplacements
.
find
(
property
)
->
second
;
for
(
int
i
=
0
;
i
<
(
int
)
platformProperties
.
size
();
i
++
)
if
(
p
latformProperties
[
i
]
==
propertyName
)
{
for
(
auto
&
prop
:
platformProperties
)
if
(
p
rop
==
propertyName
)
{
defaultProperties
[
propertyName
]
=
value
;
return
;
}
...
...
@@ -121,8 +121,8 @@ void Platform::registerKernelFactory(const string& name, KernelFactory* factory)
}
bool
Platform
::
supportsKernels
(
const
vector
<
string
>&
kernelNames
)
const
{
for
(
int
i
=
0
;
i
<
(
int
)
kernelNames
.
size
();
++
i
)
if
(
kernelFactories
.
find
(
kernelNames
[
i
]
)
==
kernelFactories
.
end
())
for
(
auto
&
name
:
kernelNames
)
if
(
kernelFactories
.
find
(
name
)
==
kernelFactories
.
end
())
return
false
;
return
true
;
}
...
...
@@ -167,9 +167,9 @@ Platform& Platform::findPlatform(const vector<string>& kernelNames) {
Platform
*
best
=
0
;
vector
<
Platform
*>&
platforms
=
getPlatforms
();
double
speed
=
0.0
;
for
(
int
i
=
0
;
i
<
(
int
)
platforms
.
size
();
++
i
)
{
if
(
platform
s
[
i
]
->
supportsKernels
(
kernelNames
)
&&
platform
s
[
i
]
->
getSpeed
()
>
speed
)
{
best
=
platform
s
[
i
]
;
for
(
auto
platform
:
platforms
)
{
if
(
platform
->
supportsKernels
(
kernelNames
)
&&
platform
->
getSpeed
()
>
speed
)
{
best
=
platform
;
speed
=
best
->
getSpeed
();
}
}
...
...
@@ -193,15 +193,15 @@ static HMODULE loadOneLibrary(const string& file) {
}
static
void
initializePlugins
(
vector
<
HMODULE
>&
plugins
)
{
for
(
int
i
=
0
;
i
<
(
int
)
plugins
.
size
();
i
++
)
{
for
(
auto
plugin
:
plugins
)
{
void
(
*
init
)();
*
(
void
**
)(
&
init
)
=
(
void
*
)
GetProcAddress
(
plugin
s
[
i
]
,
"registerPlatforms"
);
*
(
void
**
)(
&
init
)
=
(
void
*
)
GetProcAddress
(
plugin
,
"registerPlatforms"
);
if
(
init
!=
NULL
)
(
*
init
)();
}
for
(
int
i
=
0
;
i
<
(
int
)
plugins
.
size
();
i
++
)
{
for
(
auto
plugin
:
plugins
)
{
void
(
*
init
)();
*
(
void
**
)(
&
init
)
=
(
void
*
)
GetProcAddress
(
plugin
s
[
i
]
,
"registerKernelFactories"
);
*
(
void
**
)(
&
init
)
=
(
void
*
)
GetProcAddress
(
plugin
,
"registerKernelFactories"
);
if
(
init
!=
NULL
)
(
*
init
)();
}
...
...
@@ -221,15 +221,15 @@ static void* loadOneLibrary(const string& file) {
static
void
initializePlugins
(
vector
<
void
*>&
plugins
)
{
#ifndef __PNACL__
for
(
int
i
=
0
;
i
<
(
int
)
plugins
.
size
();
i
++
)
{
for
(
auto
plugin
:
plugins
)
{
void
(
*
init
)();
*
(
void
**
)(
&
init
)
=
dlsym
(
plugin
s
[
i
]
,
"registerPlatforms"
);
*
(
void
**
)(
&
init
)
=
dlsym
(
plugin
,
"registerPlatforms"
);
if
(
init
!=
NULL
)
(
*
init
)();
}
for
(
int
i
=
0
;
i
<
(
int
)
plugins
.
size
();
i
++
)
{
for
(
auto
plugin
:
plugins
)
{
void
(
*
init
)();
*
(
void
**
)(
&
init
)
=
dlsym
(
plugin
s
[
i
]
,
"registerKernelFactories"
);
*
(
void
**
)(
&
init
)
=
dlsym
(
plugin
,
"registerKernelFactories"
);
if
(
init
!=
NULL
)
(
*
init
)();
}
...
...
openmmapi/src/AndersenThermostatImpl.cpp
View file @
08e8b206
...
...
@@ -94,7 +94,7 @@ void AndersenThermostatImpl::tagParticlesInGroup(int particle, int group, vector
// Recursively tag particles as belonging to a particular group.
particleGroup
[
particle
]
=
group
;
for
(
int
i
=
0
;
i
<
(
int
)
particleConstraints
[
particle
]
.
size
();
i
++
)
if
(
particleGroup
[
particleConstraints
[
particle
][
i
]
]
==
-
1
)
tagParticlesInGroup
(
particleConstraints
[
particle
][
i
]
,
group
,
particleGroup
,
particleConstraints
);
for
(
int
constrained
:
particleConstraints
[
particle
])
if
(
particleGroup
[
constrained
]
==
-
1
)
tagParticlesInGroup
(
constrained
,
group
,
particleGroup
,
particleConstraints
);
}
openmmapi/src/CompiledExpressionSet.cpp
View file @
08e8b206
...
...
@@ -44,15 +44,15 @@ int CompiledExpressionSet::getVariableIndex(const std::string& name) {
int
index
=
variables
.
size
();
variables
.
push_back
(
name
);
variableReferences
.
push_back
(
vector
<
double
*>
());
for
(
int
i
=
0
;
i
<
(
int
)
expressions
.
size
();
i
++
)
if
(
expression
s
[
i
]
->
getVariables
().
find
(
name
)
!=
expression
s
[
i
]
->
getVariables
().
end
())
variableReferences
[
index
].
push_back
(
&
expression
s
[
i
]
->
getVariableReference
(
name
));
for
(
auto
expression
:
expressions
)
if
(
expression
->
getVariables
().
find
(
name
)
!=
expression
->
getVariables
().
end
())
variableReferences
[
index
].
push_back
(
&
expression
->
getVariableReference
(
name
));
return
index
;
}
void
CompiledExpressionSet
::
setVariable
(
int
index
,
double
value
)
{
for
(
int
i
=
0
;
i
<
(
int
)
variableReferences
[
index
]
.
size
();
i
++
)
*
variableReferences
[
index
][
i
]
=
value
;
for
(
auto
ref
:
variableReferences
[
index
])
*
ref
=
value
;
}
int
CompiledExpressionSet
::
getNumVariables
()
const
{
...
...
openmmapi/src/Context.cpp
View file @
08e8b206
...
...
@@ -97,8 +97,8 @@ State Context::getState(int types, bool enforcePeriodicBox, int groups) const {
}
if
(
types
&
State
::
Parameters
)
{
map
<
string
,
double
>
params
;
for
(
map
<
string
,
double
>::
const_iterator
iter
=
impl
->
parameters
.
begin
();
iter
!=
impl
->
parameters
.
end
();
iter
++
)
params
[
iter
->
first
]
=
iter
->
second
;
for
(
auto
&
param
:
impl
->
parameters
)
params
[
param
.
first
]
=
param
.
second
;
builder
.
setParameters
(
params
);
}
if
(
types
&
State
::
ParameterDerivatives
)
{
...
...
@@ -111,13 +111,13 @@ State Context::getState(int types, bool enforcePeriodicBox, int groups) const {
impl
->
getPositions
(
positions
);
if
(
enforcePeriodicBox
)
{
const
vector
<
vector
<
int
>
>&
molecules
=
impl
->
getMolecules
();
for
(
int
i
=
0
;
i
<
(
int
)
molecules
.
size
();
i
++
)
{
for
(
auto
&
mol
:
molecules
)
{
// Find the molecule center.
Vec3
center
;
for
(
int
j
=
0
;
j
<
(
int
)
molecules
[
i
].
size
();
j
++
)
center
+=
positions
[
molecules
[
i
][
j
]
];
center
*=
1.0
/
mol
ecules
[
i
]
.
size
();
for
(
int
j
:
mol
)
center
+=
positions
[
j
];
center
*=
1.0
/
mol
.
size
();
// Find the displacement to move it into the first periodic box.
Vec3
diff
;
...
...
@@ -126,10 +126,8 @@ State Context::getState(int types, bool enforcePeriodicBox, int groups) const {
diff
+=
periodicBoxSize
[
0
]
*
floor
((
center
[
0
]
-
diff
[
0
])
/
periodicBoxSize
[
0
][
0
]);
// Translate all the particles in the molecule.
for
(
int
j
=
0
;
j
<
(
int
)
molecules
[
i
].
size
();
j
++
)
{
Vec3
&
pos
=
positions
[
molecules
[
i
][
j
]];
pos
-=
diff
;
}
for
(
int
j
:
mol
)
positions
[
j
]
-=
diff
;
}
}
builder
.
setPositions
(
positions
);
...
...
@@ -152,8 +150,8 @@ void Context::setState(const State& state) {
if
((
state
.
getDataTypes
()
&
State
::
Velocities
)
!=
0
)
setVelocities
(
state
.
getVelocities
());
if
((
state
.
getDataTypes
()
&
State
::
Parameters
)
!=
0
)
for
(
map
<
string
,
double
>::
const_iterator
iter
=
state
.
getParameters
().
begin
();
iter
!=
state
.
getParameters
()
.
end
();
++
iter
)
setParameter
(
iter
->
first
,
iter
->
second
);
for
(
auto
&
param
:
state
.
getParameters
())
setParameter
(
param
.
first
,
param
.
second
);
}
void
Context
::
setTime
(
double
time
)
{
...
...
openmmapi/src/ContextImpl.cpp
View file @
08e8b206
...
...
@@ -95,19 +95,19 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ
const
vector
<
string
>&
platformProperties
=
platform
->
getPropertyNames
();
map
<
string
,
string
>
validatedProperties
;
for
(
map
<
string
,
string
>::
const_iterator
iter
=
properties
.
begin
();
iter
!=
properties
.
end
();
++
iter
)
{
string
property
=
iter
->
first
;
for
(
auto
&
prop
:
properties
)
{
string
property
=
prop
.
first
;
if
(
platform
->
deprecatedPropertyReplacements
.
find
(
property
)
!=
platform
->
deprecatedPropertyReplacements
.
end
())
property
=
platform
->
deprecatedPropertyReplacements
[
property
];
bool
valid
=
false
;
for
(
int
i
=
0
;
i
<
(
int
)
platformProperties
.
size
();
i
++
)
if
(
p
latformProperties
[
i
]
==
property
)
{
for
(
auto
&
p
:
platformProperties
)
if
(
p
==
property
)
{
valid
=
true
;
break
;
}
if
(
!
valid
)
throw
OpenMMException
(
"Illegal property name: "
+
iter
->
first
);
validatedProperties
[
property
]
=
iter
->
second
;
throw
OpenMMException
(
"Illegal property name: "
+
prop
.
first
);
validatedProperties
[
property
]
=
prop
.
second
;
}
// Find the list of kernels required.
...
...
@@ -184,8 +184,8 @@ ContextImpl::ContextImpl(Context& owner, const System& system, Integrator& integ
}
ContextImpl
::~
ContextImpl
()
{
for
(
int
i
=
0
;
i
<
(
int
)
forceImpls
.
size
();
++
i
)
delete
force
Impls
[
i
]
;
for
(
auto
force
:
forceImpls
)
delete
force
;
// Make sure all kernels get properly deleted before contextDestroyed() is called.
...
...
@@ -292,8 +292,8 @@ double ContextImpl::calcForcesAndEnergy(bool includeForces, bool includeEnergy,
while
(
true
)
{
double
energy
=
0.0
;
kernel
.
beginComputation
(
*
this
,
includeForces
,
includeEnergy
,
groups
);
for
(
int
i
=
0
;
i
<
(
int
)
forceImpls
.
size
();
++
i
)
energy
+=
force
Impls
[
i
]
->
calcForcesAndEnergy
(
*
this
,
includeForces
,
includeEnergy
,
groups
);
for
(
auto
force
:
forceImpls
)
energy
+=
force
->
calcForcesAndEnergy
(
*
this
,
includeForces
,
includeEnergy
,
groups
);
bool
valid
=
true
;
energy
+=
kernel
.
finishComputation
(
*
this
,
includeForces
,
includeEnergy
,
groups
,
valid
);
if
(
valid
)
...
...
@@ -310,8 +310,8 @@ double ContextImpl::calcKineticEnergy() {
}
void
ContextImpl
::
updateContextState
()
{
for
(
int
i
=
0
;
i
<
(
int
)
forceImpls
.
size
();
++
i
)
force
Impls
[
i
]
->
updateContextState
(
*
this
);
for
(
auto
force
:
forceImpls
)
force
->
updateContextState
(
*
this
);
}
const
vector
<
ForceImpl
*>&
ContextImpl
::
getForceImpls
()
const
{
...
...
@@ -349,8 +349,8 @@ const vector<vector<int> >& ContextImpl::getMolecules() const {
system
.
getConstraintParameters
(
i
,
particle1
,
particle2
,
distance
);
bonds
.
push_back
(
std
::
make_pair
(
particle1
,
particle2
));
}
for
(
int
i
=
0
;
i
<
(
int
)
forceImpls
.
size
();
i
++
)
{
vector
<
pair
<
int
,
int
>
>
forceBonds
=
force
Impls
[
i
]
->
getBondedParticles
();
for
(
auto
force
:
forceImpls
)
{
vector
<
pair
<
int
,
int
>
>
forceBonds
=
force
->
getBondedParticles
();
bonds
.
insert
(
bonds
.
end
(),
forceBonds
.
begin
(),
forceBonds
.
end
());
}
for
(
int
i
=
0
;
i
<
system
.
getNumParticles
();
i
++
)
{
...
...
@@ -365,9 +365,9 @@ const vector<vector<int> >& ContextImpl::getMolecules() const {
int
numParticles
=
system
.
getNumParticles
();
vector
<
vector
<
int
>
>
particleBonds
(
numParticles
);
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
size
();
i
++
)
{
particleBonds
[
bond
s
[
i
]
.
first
].
push_back
(
bond
s
[
i
]
.
second
);
particleBonds
[
bond
s
[
i
]
.
second
].
push_back
(
bond
s
[
i
]
.
first
);
for
(
auto
&
bond
:
bonds
)
{
particleBonds
[
bond
.
first
].
push_back
(
bond
.
second
);
particleBonds
[
bond
.
second
].
push_back
(
bond
.
first
);
}
// Now identify particles by which molecule they belong to.
...
...
@@ -441,9 +441,9 @@ void ContextImpl::createCheckpoint(ostream& stream) {
stream
.
write
((
char
*
)
&
numParticles
,
sizeof
(
int
));
int
numParameters
=
parameters
.
size
();
stream
.
write
((
char
*
)
&
numParameters
,
sizeof
(
int
));
for
(
map
<
string
,
double
>::
const_iterator
iter
=
parameters
.
begin
();
iter
!=
parameters
.
end
();
++
iter
)
{
writeString
(
stream
,
iter
->
first
);
stream
.
write
((
char
*
)
&
iter
->
second
,
sizeof
(
double
));
for
(
auto
&
param
:
parameters
)
{
writeString
(
stream
,
param
.
first
);
stream
.
write
((
char
*
)
&
param
.
second
,
sizeof
(
double
));
}
updateStateDataKernel
.
getAs
<
UpdateStateDataKernel
>
().
createCheckpoint
(
*
this
,
stream
);
stream
.
flush
();
...
...
openmmapi/src/CustomCentroidBondForce.cpp
View file @
08e8b206
...
...
@@ -52,8 +52,8 @@ CustomCentroidBondForce::CustomCentroidBondForce(int numGroups, const string& en
}
CustomCentroidBondForce
::~
CustomCentroidBondForce
()
{
for
(
int
i
=
0
;
i
<
(
int
)
functions
.
size
();
i
++
)
delete
function
s
[
i
]
.
function
;
for
(
auto
function
:
functions
)
delete
function
.
function
;
}
const
string
&
CustomCentroidBondForce
::
getEnergyFunction
()
const
{
...
...
openmmapi/src/CustomCentroidBondForceImpl.cpp
View file @
08e8b206
...
...
@@ -83,11 +83,11 @@ void CustomCentroidBondForceImpl::initialize(ContextImpl& context) {
vector
<
double
>
weights
;
for
(
int
i
=
0
;
i
<
owner
.
getNumGroups
();
i
++
)
{
owner
.
getGroupParameters
(
i
,
particles
,
weights
);
for
(
int
j
=
0
;
j
<
(
int
)
particles
.
size
();
j
++
)
if
(
particle
s
[
j
]
<
0
||
particle
s
[
j
]
>=
system
.
getNumParticles
())
{
for
(
int
particle
:
particles
)
if
(
particle
<
0
||
particle
>=
system
.
getNumParticles
())
{
stringstream
msg
;
msg
<<
"CustomCentroidBondForce: Illegal particle index for a group: "
;
msg
<<
particle
s
[
j
]
;
msg
<<
particle
;
throw
OpenMMException
(
msg
.
str
());
}
if
(
weights
.
size
()
!=
particles
.
size
()
&&
weights
.
size
()
>
0
)
{
...
...
@@ -102,11 +102,11 @@ void CustomCentroidBondForceImpl::initialize(ContextImpl& context) {
int
numBondParameters
=
owner
.
getNumPerBondParameters
();
for
(
int
i
=
0
;
i
<
owner
.
getNumBonds
();
i
++
)
{
owner
.
getBondParameters
(
i
,
groups
,
parameters
);
for
(
int
j
=
0
;
j
<
(
int
)
groups
.
size
();
j
++
)
if
(
group
s
[
j
]
<
0
||
group
s
[
j
]
>=
owner
.
getNumGroups
())
{
for
(
int
group
:
groups
)
if
(
group
<
0
||
group
>=
owner
.
getNumGroups
())
{
stringstream
msg
;
msg
<<
"CustomCentroidBondForce: Illegal group index for a bond: "
;
msg
<<
group
s
[
j
]
;
msg
<<
group
;
throw
OpenMMException
(
msg
.
str
());
}
if
(
parameters
.
size
()
!=
numBondParameters
)
{
...
...
@@ -179,8 +179,8 @@ ExpressionTreeNode CustomCentroidBondForceImpl::replaceFunctions(const Expressio
// This is not an angle or dihedral, so process its children.
vector
<
ExpressionTreeNode
>
children
;
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
()
.
size
();
i
++
)
children
.
push_back
(
replaceFunctions
(
node
.
getChildren
()[
i
]
,
groups
,
distances
,
angles
,
dihedrals
,
variables
));
for
(
auto
&
child
:
node
.
getChildren
())
children
.
push_back
(
replaceFunctions
(
child
,
groups
,
distances
,
angles
,
dihedrals
,
variables
));
return
ExpressionTreeNode
(
op
.
clone
(),
children
);
}
const
Operation
::
Custom
&
custom
=
static_cast
<
const
Operation
::
Custom
&>
(
op
);
...
...
openmmapi/src/CustomCompoundBondForce.cpp
View file @
08e8b206
...
...
@@ -53,8 +53,8 @@ CustomCompoundBondForce::CustomCompoundBondForce(int numParticles, const string&
CustomCompoundBondForce
::~
CustomCompoundBondForce
()
{
for
(
int
i
=
0
;
i
<
(
int
)
functions
.
size
();
i
++
)
delete
function
s
[
i
]
.
function
;
for
(
auto
function
:
functions
)
delete
function
.
function
;
}
const
string
&
CustomCompoundBondForce
::
getEnergyFunction
()
const
{
...
...
openmmapi/src/CustomCompoundBondForceImpl.cpp
View file @
08e8b206
...
...
@@ -88,11 +88,11 @@ void CustomCompoundBondForceImpl::initialize(ContextImpl& context) {
int
numBondParameters
=
owner
.
getNumPerBondParameters
();
for
(
int
i
=
0
;
i
<
owner
.
getNumBonds
();
i
++
)
{
owner
.
getBondParameters
(
i
,
particles
,
parameters
);
for
(
int
j
=
0
;
j
<
(
int
)
particles
.
size
();
j
++
)
if
(
particle
s
[
j
]
<
0
||
particle
s
[
j
]
>=
system
.
getNumParticles
())
{
for
(
int
particle
:
particles
)
if
(
particle
<
0
||
particle
>=
system
.
getNumParticles
())
{
stringstream
msg
;
msg
<<
"CustomCompoundBondForce: Illegal particle index for a bond: "
;
msg
<<
particle
s
[
j
]
;
msg
<<
particle
;
throw
OpenMMException
(
msg
.
str
());
}
if
(
parameters
.
size
()
!=
numBondParameters
)
{
...
...
@@ -165,8 +165,8 @@ ExpressionTreeNode CustomCompoundBondForceImpl::replaceFunctions(const Expressio
// This is not an angle or dihedral, so process its children.
vector
<
ExpressionTreeNode
>
children
;
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
()
.
size
();
i
++
)
children
.
push_back
(
replaceFunctions
(
node
.
getChildren
()[
i
]
,
atoms
,
distances
,
angles
,
dihedrals
,
variables
));
for
(
auto
&
child
:
node
.
getChildren
())
children
.
push_back
(
replaceFunctions
(
child
,
atoms
,
distances
,
angles
,
dihedrals
,
variables
));
return
ExpressionTreeNode
(
op
.
clone
(),
children
);
}
const
Operation
::
Custom
&
custom
=
static_cast
<
const
Operation
::
Custom
&>
(
op
);
...
...
openmmapi/src/CustomGBForce.cpp
View file @
08e8b206
...
...
@@ -51,8 +51,8 @@ CustomGBForce::CustomGBForce() : nonbondedMethod(NoCutoff), cutoffDistance(1.0)
}
CustomGBForce
::~
CustomGBForce
()
{
for
(
int
i
=
0
;
i
<
(
int
)
functions
.
size
();
i
++
)
delete
function
s
[
i
]
.
function
;
for
(
auto
function
:
functions
)
delete
function
.
function
;
}
CustomGBForce
::
NonbondedMethod
CustomGBForce
::
getNonbondedMethod
()
const
{
...
...
openmmapi/src/CustomHbondForce.cpp
View file @
08e8b206
...
...
@@ -52,8 +52,8 @@ CustomHbondForce::CustomHbondForce(const string& energy) : energyExpression(ener
CustomHbondForce
::~
CustomHbondForce
()
{
for
(
int
i
=
0
;
i
<
(
int
)
functions
.
size
();
i
++
)
delete
function
s
[
i
]
.
function
;
for
(
auto
function
:
functions
)
delete
function
.
function
;
}
const
string
&
CustomHbondForce
::
getEnergyFunction
()
const
{
...
...
openmmapi/src/CustomHbondForceImpl.cpp
View file @
08e8b206
...
...
@@ -235,8 +235,8 @@ ExpressionTreeNode CustomHbondForceImpl::replaceFunctions(const ExpressionTreeNo
// This is not an angle or dihedral, so process its children.
vector
<
ExpressionTreeNode
>
children
;
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
()
.
size
();
i
++
)
children
.
push_back
(
replaceFunctions
(
node
.
getChildren
()[
i
]
,
atoms
,
distances
,
angles
,
dihedrals
,
variables
));
for
(
auto
&
child
:
node
.
getChildren
())
children
.
push_back
(
replaceFunctions
(
child
,
atoms
,
distances
,
angles
,
dihedrals
,
variables
));
return
ExpressionTreeNode
(
op
.
clone
(),
children
);
}
const
Operation
::
Custom
&
custom
=
static_cast
<
const
Operation
::
Custom
&>
(
op
);
...
...
openmmapi/src/CustomIntegrator.cpp
View file @
08e8b206
...
...
@@ -55,8 +55,7 @@ void CustomIntegrator::initialize(ContextImpl& contextRef) {
set
<
std
::
string
>
variableSet
;
variableList
.
insert
(
variableList
.
end
(),
globalNames
.
begin
(),
globalNames
.
end
());
variableList
.
insert
(
variableList
.
end
(),
perDofNames
.
begin
(),
perDofNames
.
end
());
for
(
int
i
=
0
;
i
<
(
int
)
variableList
.
size
();
i
++
)
{
string
&
name
=
variableList
[
i
];
for
(
auto
&
name
:
variableList
)
{
if
(
variableSet
.
find
(
name
)
!=
variableSet
.
end
())
throw
OpenMMException
(
"The Integrator defines two variables with the same name: "
+
name
);
variableSet
.
insert
(
name
);
...
...
@@ -66,8 +65,8 @@ void CustomIntegrator::initialize(ContextImpl& contextRef) {
set
<
std
::
string
>
globalTargets
;
globalTargets
.
insert
(
globalNames
.
begin
(),
globalNames
.
end
());
globalTargets
.
insert
(
"dt"
);
for
(
map
<
string
,
double
>::
const_iterator
iter
=
contextRef
.
getParameters
().
begin
();
iter
!=
contextRef
.
getParameters
()
.
end
();
++
iter
)
globalTargets
.
insert
(
iter
->
first
);
for
(
auto
&
param
:
contextRef
.
getParameters
())
globalTargets
.
insert
(
param
.
first
);
for
(
int
i
=
0
;
i
<
computations
.
size
();
i
++
)
{
if
(
computations
[
i
].
type
==
ComputeGlobal
&&
globalTargets
.
find
(
computations
[
i
].
variable
)
==
globalTargets
.
end
())
throw
OpenMMException
(
"Unknown global variable: "
+
computations
[
i
].
variable
);
...
...
openmmapi/src/CustomIntegratorUtilities.cpp
View file @
08e8b206
...
...
@@ -59,8 +59,8 @@ bool CustomIntegratorUtilities::usesVariable(const Lepton::ExpressionTreeNode& n
const
Lepton
::
Operation
&
op
=
node
.
getOperation
();
if
(
op
.
getId
()
==
Lepton
::
Operation
::
VARIABLE
&&
op
.
getName
()
==
variable
)
return
true
;
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
()
.
size
();
i
++
)
if
(
usesVariable
(
node
.
getChildren
()[
i
]
,
variable
))
for
(
auto
&
child
:
node
.
getChildren
())
if
(
usesVariable
(
child
,
variable
))
return
true
;
return
false
;
}
...
...
@@ -107,11 +107,9 @@ void CustomIntegratorUtilities::analyzeComputations(const ContextImpl& context,
set
<
string
>
affectsForce
;
affectsForce
.
insert
(
"x"
);
for
(
vector
<
ForceImpl
*>::
const_iterator
iter
=
context
.
getForceImpls
().
begin
();
iter
!=
context
.
getForceImpls
().
end
();
++
iter
)
{
const
map
<
string
,
double
>
params
=
(
*
iter
)
->
getDefaultParameters
();
for
(
map
<
string
,
double
>::
const_iterator
param
=
params
.
begin
();
param
!=
params
.
end
();
++
param
)
affectsForce
.
insert
(
param
->
first
);
}
for
(
auto
force
:
context
.
getForceImpls
())
for
(
auto
&
param
:
force
->
getDefaultParameters
())
affectsForce
.
insert
(
param
.
first
);
for
(
int
i
=
0
;
i
<
numSteps
;
i
++
)
invalidatesForces
[
i
]
=
(
stepType
[
i
]
==
CustomIntegrator
::
ConstrainPositions
||
affectsForce
.
find
(
stepVariable
[
i
])
!=
affectsForce
.
end
());
...
...
@@ -253,8 +251,7 @@ void CustomIntegratorUtilities::analyzeForceComputationsForPath(vector<int>& ste
const
vector
<
bool
>&
invalidatesForces
,
const
vector
<
int
>&
forceGroup
,
vector
<
bool
>&
computeBoth
)
{
vector
<
int
>
candidatePoints
;
int
currentGroup
=
-
1
;
for
(
int
i
=
0
;
i
<
(
int
)
steps
.
size
();
i
++
)
{
int
step
=
steps
[
i
];
for
(
int
step
:
steps
)
{
if
(
invalidatesForces
[
step
]
||
((
needsForces
[
step
]
||
needsEnergy
[
step
])
&&
forceGroup
[
step
]
!=
currentGroup
))
{
// Forces and energies are invalidated at this step, or it changes to a different force group,
// so anything from this point on won't affect what we do at earlier steps.
...
...
@@ -264,11 +261,9 @@ void CustomIntegratorUtilities::analyzeForceComputationsForPath(vector<int>& ste
if
(
needsForces
[
step
]
||
needsEnergy
[
step
])
{
// See if this step affects what we do at earlier points.
for
(
int
j
=
0
;
j
<
(
int
)
candidatePoints
.
size
();
j
++
)
{
int
candidate
=
candidatePoints
[
j
];
for
(
int
candidate
:
candidatePoints
)
if
((
needsForces
[
candidate
]
&&
needsEnergy
[
step
])
||
(
needsEnergy
[
candidate
]
&&
needsForces
[
step
]))
computeBoth
[
candidate
]
=
true
;
}
// Add this to the list of candidates that might be affected by later steps.
...
...
openmmapi/src/CustomManyParticleForce.cpp
View file @
08e8b206
...
...
@@ -48,8 +48,8 @@ CustomManyParticleForce::CustomManyParticleForce(int particlesPerSet, const stri
}
CustomManyParticleForce
::~
CustomManyParticleForce
()
{
for
(
int
i
=
0
;
i
<
(
int
)
functions
.
size
();
i
++
)
delete
function
s
[
i
]
.
function
;
for
(
auto
function
:
functions
)
delete
function
.
function
;
}
const
string
&
CustomManyParticleForce
::
getEnergyFunction
()
const
{
...
...
@@ -162,9 +162,9 @@ void CustomManyParticleForce::createExclusionsFromBonds(const vector<pair<int, i
return
;
vector
<
set
<
int
>
>
exclusions
(
particles
.
size
());
vector
<
set
<
int
>
>
bonded12
(
exclusions
.
size
());
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
size
();
++
i
)
{
int
p1
=
bond
s
[
i
]
.
first
;
int
p2
=
bond
s
[
i
]
.
second
;
for
(
auto
&
bond
:
bonds
)
{
int
p1
=
bond
.
first
;
int
p2
=
bond
.
second
;
exclusions
[
p1
].
insert
(
p2
);
exclusions
[
p2
].
insert
(
p1
);
bonded12
[
p1
].
insert
(
p2
);
...
...
@@ -172,15 +172,14 @@ void CustomManyParticleForce::createExclusionsFromBonds(const vector<pair<int, i
}
for
(
int
level
=
0
;
level
<
bondCutoff
-
1
;
level
++
)
{
vector
<
set
<
int
>
>
currentExclusions
=
exclusions
;
for
(
int
i
=
0
;
i
<
(
int
)
particles
.
size
();
i
++
)
{
for
(
set
<
int
>::
const_iterator
iter
=
currentExclusions
[
i
].
begin
();
iter
!=
currentExclusions
[
i
].
end
();
++
iter
)
exclusions
[
*
iter
].
insert
(
bonded12
[
i
].
begin
(),
bonded12
[
i
].
end
());
}
for
(
int
i
=
0
;
i
<
(
int
)
particles
.
size
();
i
++
)
for
(
int
j
:
currentExclusions
[
i
])
exclusions
[
j
].
insert
(
bonded12
[
i
].
begin
(),
bonded12
[
i
].
end
());
}
for
(
int
i
=
0
;
i
<
(
int
)
exclusions
.
size
();
++
i
)
for
(
set
<
int
>::
const_iterator
iter
=
exclusions
[
i
].
begin
();
iter
!=
exclusions
[
i
].
end
();
++
iter
)
if
(
*
iter
<
i
)
addExclusion
(
*
iter
,
i
);
for
(
int
j
:
exclusions
[
i
]
)
if
(
j
<
i
)
addExclusion
(
j
,
i
);
}
void
CustomManyParticleForce
::
getTypeFilter
(
int
index
,
set
<
int
>&
types
)
const
{
...
...
openmmapi/src/CustomManyParticleForceImpl.cpp
View file @
08e8b206
...
...
@@ -197,8 +197,8 @@ ExpressionTreeNode CustomManyParticleForceImpl::replaceFunctions(const Expressio
// This is not an angle or dihedral, so process its children.
vector
<
ExpressionTreeNode
>
children
;
for
(
int
i
=
0
;
i
<
(
int
)
node
.
getChildren
()
.
size
();
i
++
)
children
.
push_back
(
replaceFunctions
(
node
.
getChildren
()[
i
]
,
atoms
,
distances
,
angles
,
dihedrals
,
variables
));
for
(
auto
&
child
:
node
.
getChildren
())
children
.
push_back
(
replaceFunctions
(
child
,
atoms
,
distances
,
angles
,
dihedrals
,
variables
));
return
ExpressionTreeNode
(
op
.
clone
(),
children
);
}
const
Operation
::
Custom
&
custom
=
static_cast
<
const
Operation
::
Custom
&>
(
op
);
...
...
@@ -280,9 +280,9 @@ void CustomManyParticleForceImpl::buildFilterArrays(const CustomManyParticleForc
for
(
int
j
=
0
;
j
<
numTypes
;
j
++
)
allowedTypes
[
i
].
insert
(
j
);
else
{
for
(
set
<
int
>::
const_iterator
iter
=
types
.
begin
();
iter
!=
types
.
end
();
++
iter
)
if
(
typeMap
.
find
(
*
iter
)
!=
typeMap
.
end
())
allowedTypes
[
i
].
insert
(
typeMap
[
*
iter
]);
for
(
int
type
:
types
)
if
(
typeMap
.
find
(
type
)
!=
typeMap
.
end
())
allowedTypes
[
i
].
insert
(
typeMap
[
type
]);
if
(
allowedTypes
[
i
].
size
()
<
numTypes
)
anyFilters
=
true
;
}
...
...
openmmapi/src/CustomNonbondedForce.cpp
View file @
08e8b206
...
...
@@ -70,8 +70,8 @@ CustomNonbondedForce::CustomNonbondedForce(const CustomNonbondedForce& rhs) {
}
CustomNonbondedForce
::~
CustomNonbondedForce
()
{
for
(
int
i
=
0
;
i
<
(
int
)
functions
.
size
();
i
++
)
delete
function
s
[
i
]
.
function
;
for
(
auto
function
:
functions
)
delete
function
.
function
;
}
const
string
&
CustomNonbondedForce
::
getEnergyFunction
()
const
{
...
...
@@ -210,14 +210,14 @@ void CustomNonbondedForce::setExclusionParticles(int index, int particle1, int p
void
CustomNonbondedForce
::
createExclusionsFromBonds
(
const
vector
<
pair
<
int
,
int
>
>&
bonds
,
int
bondCutoff
)
{
if
(
bondCutoff
<
1
)
return
;
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
size
();
++
i
)
if
(
bond
s
[
i
]
.
first
<
0
||
bond
s
[
i
]
.
second
<
0
||
bond
s
[
i
]
.
first
>=
particles
.
size
()
||
bond
s
[
i
]
.
second
>=
particles
.
size
())
for
(
auto
&
bond
:
bonds
)
if
(
bond
.
first
<
0
||
bond
.
second
<
0
||
bond
.
first
>=
particles
.
size
()
||
bond
.
second
>=
particles
.
size
())
throw
OpenMMException
(
"createExclusionsFromBonds: Illegal particle index in list of bonds"
);
vector
<
set
<
int
>
>
exclusions
(
particles
.
size
());
vector
<
set
<
int
>
>
bonded12
(
exclusions
.
size
());
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
size
();
++
i
)
{
int
p1
=
bond
s
[
i
]
.
first
;
int
p2
=
bond
s
[
i
]
.
second
;
for
(
auto
&
bond
:
bonds
)
{
int
p1
=
bond
.
first
;
int
p2
=
bond
.
second
;
exclusions
[
p1
].
insert
(
p2
);
exclusions
[
p2
].
insert
(
p1
);
bonded12
[
p1
].
insert
(
p2
);
...
...
@@ -225,15 +225,14 @@ void CustomNonbondedForce::createExclusionsFromBonds(const vector<pair<int, int>
}
for
(
int
level
=
0
;
level
<
bondCutoff
-
1
;
level
++
)
{
vector
<
set
<
int
>
>
currentExclusions
=
exclusions
;
for
(
int
i
=
0
;
i
<
(
int
)
particles
.
size
();
i
++
)
{
for
(
set
<
int
>::
const_iterator
iter
=
currentExclusions
[
i
].
begin
();
iter
!=
currentExclusions
[
i
].
end
();
++
iter
)
exclusions
[
*
iter
].
insert
(
bonded12
[
i
].
begin
(),
bonded12
[
i
].
end
());
}
for
(
int
i
=
0
;
i
<
(
int
)
particles
.
size
();
i
++
)
for
(
int
j
:
currentExclusions
[
i
])
exclusions
[
j
].
insert
(
bonded12
[
i
].
begin
(),
bonded12
[
i
].
end
());
}
for
(
int
i
=
0
;
i
<
(
int
)
exclusions
.
size
();
++
i
)
for
(
set
<
int
>::
const_iterator
iter
=
exclusions
[
i
].
begin
();
iter
!=
exclusions
[
i
].
end
();
++
iter
)
if
(
*
iter
<
i
)
addExclusion
(
*
iter
,
i
);
for
(
int
j
:
exclusions
[
i
]
)
if
(
j
<
i
)
addExclusion
(
j
,
i
);
}
int
CustomNonbondedForce
::
addTabulatedFunction
(
const
std
::
string
&
name
,
TabulatedFunction
*
function
)
{
...
...
openmmapi/src/Force.cpp
View file @
08e8b206
...
...
@@ -54,18 +54,16 @@ bool Force::usesPeriodicBoundaryConditions() const {
}
ForceImpl
&
Force
::
getImplInContext
(
Context
&
context
)
{
const
vector
<
ForceImpl
*>&
impls
=
context
.
getImpl
().
getForceImpls
();
for
(
int
i
=
0
;
i
<
(
int
)
impls
.
size
();
i
++
)
if
(
&
impls
[
i
]
->
getOwner
()
==
this
)
return
*
impls
[
i
];
for
(
auto
impl
:
context
.
getImpl
().
getForceImpls
())
if
(
&
impl
->
getOwner
()
==
this
)
return
*
impl
;
throw
OpenMMException
(
"getImplInContext: This Force is not present in the Context"
);
}
const
ForceImpl
&
Force
::
getImplInContext
(
const
Context
&
context
)
const
{
const
vector
<
ForceImpl
*>&
impls
=
context
.
getImpl
().
getForceImpls
();
for
(
int
i
=
0
;
i
<
(
int
)
impls
.
size
();
i
++
)
if
(
&
impls
[
i
]
->
getOwner
()
==
this
)
return
*
impls
[
i
];
for
(
auto
impl
:
context
.
getImpl
().
getForceImpls
())
if
(
&
impl
->
getOwner
()
==
this
)
return
*
impl
;
throw
OpenMMException
(
"getImplInContext: This Force is not present in the Context"
);
}
...
...
openmmapi/src/NonbondedForce.cpp
View file @
08e8b206
...
...
@@ -203,17 +203,17 @@ ForceImpl* NonbondedForce::createImpl() const {
}
void
NonbondedForce
::
createExceptionsFromBonds
(
const
vector
<
pair
<
int
,
int
>
>&
bonds
,
double
coulomb14Scale
,
double
lj14Scale
)
{
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
size
();
++
i
)
if
(
bond
s
[
i
]
.
first
<
0
||
bond
s
[
i
]
.
second
<
0
||
bond
s
[
i
]
.
first
>=
particles
.
size
()
||
bond
s
[
i
]
.
second
>=
particles
.
size
())
for
(
auto
&
bond
:
bonds
)
if
(
bond
.
first
<
0
||
bond
.
second
<
0
||
bond
.
first
>=
particles
.
size
()
||
bond
.
second
>=
particles
.
size
())
throw
OpenMMException
(
"createExceptionsFromBonds: Illegal particle index in list of bonds"
);
// Find particles separated by 1, 2, or 3 bonds.
vector
<
set
<
int
>
>
exclusions
(
particles
.
size
());
vector
<
set
<
int
>
>
bonded12
(
exclusions
.
size
());
for
(
int
i
=
0
;
i
<
(
int
)
bonds
.
size
();
++
i
)
{
bonded12
[
bond
s
[
i
]
.
first
].
insert
(
bond
s
[
i
]
.
second
);
bonded12
[
bond
s
[
i
]
.
second
].
insert
(
bond
s
[
i
]
.
first
);
for
(
auto
&
bond
:
bonds
)
{
bonded12
[
bond
.
first
].
insert
(
bond
.
second
);
bonded12
[
bond
.
second
].
insert
(
bond
.
first
);
}
for
(
int
i
=
0
;
i
<
(
int
)
exclusions
.
size
();
++
i
)
addExclusionsToSet
(
bonded12
,
exclusions
[
i
],
i
,
i
,
2
);
...
...
@@ -223,33 +223,34 @@ void NonbondedForce::createExceptionsFromBonds(const vector<pair<int, int> >& bo
for
(
int
i
=
0
;
i
<
(
int
)
exclusions
.
size
();
++
i
)
{
set
<
int
>
bonded13
;
addExclusionsToSet
(
bonded12
,
bonded13
,
i
,
i
,
1
);
for
(
set
<
int
>::
const_iterator
iter
=
exclusions
[
i
].
begin
();
iter
!=
exclusions
[
i
].
end
();
++
iter
)
if
(
*
iter
<
i
)
{
if
(
bonded13
.
find
(
*
iter
)
==
bonded13
.
end
())
{
for
(
int
j
:
exclusions
[
i
])
{
if
(
j
<
i
)
{
if
(
bonded13
.
find
(
j
)
==
bonded13
.
end
())
{
// This is a 1-4 interaction.
const
ParticleInfo
&
particle1
=
particles
[
*
iter
];
const
ParticleInfo
&
particle1
=
particles
[
j
];
const
ParticleInfo
&
particle2
=
particles
[
i
];
const
double
chargeProd
=
coulomb14Scale
*
particle1
.
charge
*
particle2
.
charge
;
const
double
sigma
=
0.5
*
(
particle1
.
sigma
+
particle2
.
sigma
);
const
double
epsilon
=
lj14Scale
*
std
::
sqrt
(
particle1
.
epsilon
*
particle2
.
epsilon
);
addException
(
*
iter
,
i
,
chargeProd
,
sigma
,
epsilon
);
addException
(
j
,
i
,
chargeProd
,
sigma
,
epsilon
);
}
else
{
// This interaction should be completely excluded.
addException
(
*
iter
,
i
,
0.0
,
1.0
,
0.0
);
addException
(
j
,
i
,
0.0
,
1.0
,
0.0
);
}
}
}
}
}
void
NonbondedForce
::
addExclusionsToSet
(
const
vector
<
set
<
int
>
>&
bonded12
,
set
<
int
>&
exclusions
,
int
baseParticle
,
int
fromParticle
,
int
currentLevel
)
const
{
for
(
set
<
int
>::
const_iterator
iter
=
bonded12
[
fromParticle
].
begin
();
iter
!=
bonded12
[
fromParticle
]
.
end
();
++
iter
)
{
if
(
*
iter
!=
baseParticle
)
exclusions
.
insert
(
*
iter
);
for
(
int
i
:
bonded12
[
fromParticle
])
{
if
(
i
!=
baseParticle
)
exclusions
.
insert
(
i
);
if
(
currentLevel
>
0
)
addExclusionsToSet
(
bonded12
,
exclusions
,
baseParticle
,
*
iter
,
currentLevel
-
1
);
addExclusionsToSet
(
bonded12
,
exclusions
,
baseParticle
,
i
,
currentLevel
-
1
);
}
}
...
...
openmmapi/src/System.cpp
View file @
08e8b206
...
...
@@ -45,10 +45,10 @@ System::System() {
}
System
::~
System
()
{
for
(
int
i
=
0
;
i
<
(
int
)
forces
.
size
();
++
i
)
delete
force
s
[
i
]
;
for
(
int
i
=
0
;
i
<
(
int
)
virtualSites
.
size
();
++
i
)
delete
virtualSites
[
i
]
;
for
(
auto
force
:
forces
)
delete
force
;
for
(
auto
site
:
virtualSites
)
delete
site
;
}
double
System
::
getParticleMass
(
int
index
)
const
{
...
...
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