Commit 6ed5bc4e authored by Rafal Wiewiora's avatar Rafal Wiewiora Committed by GitHub
Browse files

Merge branch 'master' into master

parents 656d0e3b fbf193fe
......@@ -73,6 +73,7 @@ matrix:
addons: {apt: {packages: []}}
- sudo: false
dist: trusty
python: 2.7_with_system_site_packages
env: ==STATIC_LIB==
OPENCL=false
......@@ -82,6 +83,7 @@ matrix:
CMAKE_FLAGS="-DOPENMM_BUILD_STATIC_LIB=ON"
- sudo: false
dist: trusty
python: 2.7_with_system_site_packages
env: ==PYTHON_2==
OPENCL=false
......@@ -92,6 +94,7 @@ matrix:
CMAKE_FLAGS="-DOPENMM_GENERATE_API_DOCS=ON"
- sudo: false
dist: trusty
python: 3.4
env: ==PYTHON_3==
OPENCL=false
......@@ -102,7 +105,7 @@ matrix:
before_install:
- START_TIME=$(date +%s)
- wget https://anaconda.org/omnia/ccache/3.2.4/download/${TRAVIS_OS_NAME}-64/ccache-3.2.4-0.tar.bz2
- wget http://anaconda.org/omnia/ccache/3.2.4/download/${TRAVIS_OS_NAME}-64/ccache-3.2.4-0.tar.bz2
- mkdir -p $HOME/ccache && tar xf ccache-3.2.4-0.tar.bz2 -C $HOME/ccache
- if [[ "$TRAVIS_OS_NAME" == "osx" ]]; then
brew install fftw;
......@@ -110,7 +113,7 @@ before_install:
sudo easy_install pytest;
fi
- if [[ "${TRAVIS_OS_NAME}" == "linux" ]]; then
CMAKE_URL="https://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz";
CMAKE_URL="http://cmake.org/files/v3.7/cmake-3.7.2-Linux-x86_64.tar.gz";
mkdir $HOME/cmake && travis_retry wget --no-check-certificate --quiet -O - ${CMAKE_URL} | tar --strip-components=1 -xz -C $HOME/cmake;
export PATH=${HOME}/cmake/bin:${PATH};
fi
......@@ -131,14 +134,14 @@ before_install:
# but this is a fast way to get an apparently functional precompiled
# build of swig that's more modern than what's in apt.
- if [[ "$OPENCL" == "false" && "$CUDA" == "false" && "$TRAVIS_OS_NAME" == "linux" ]]; then
wget https://anaconda.org/omnia/swig/3.0.7/download/linux-64/swig-3.0.7-0.tar.bz2;
wget http://anaconda.org/omnia/swig/3.0.7/download/linux-64/swig-3.0.7-0.tar.bz2;
mkdir $HOME/swig;
tar -xjvf swig-3.0.7-0.tar.bz2 -C $HOME/swig;
export PATH=$HOME/swig/bin:$PATH;
export SWIG_LIB=$HOME/swig/share/swig/3.0.7;
fi
- if [[ "$OPENCL" == "false" && "$CUDA" == "false" && "$TRAVIS_OS_NAME" == "osx" ]]; then
wget https://anaconda.org/omnia/swig/3.0.7/download/osx-64/swig-3.0.7-0.tar.bz2;
wget http://anaconda.org/omnia/swig/3.0.7/download/osx-64/swig-3.0.7-0.tar.bz2;
mkdir $HOME/swig;
tar -xjvf swig-3.0.7-0.tar.bz2 -C $HOME/swig;
export PATH=$HOME/swig/bin:$PATH;
......
......@@ -185,10 +185,16 @@ latex_elements = {
\\usepackage{caption}
\\setcounter{tocdepth}{3}
\\captionsetup[figure]{labelformat=empty}
% Backwards compatibility for sphinx < 1.5
\\let\\DUspan\\null % force DUspan to be defined
\\renewcommand{\DUspan}[2]{%
\\IfEqCase{#1}{%
{code}{\\small{}\\texttt{#2}\\normalsize{}}%
{code}{\\small{}\\texttt{#2}\\normalsize{}}
}[\\PackageError{DUspan}{Unrecognized option passed to DUspan: #1}{}]%
}%
% Sphinx > 1.5 compatibility (github.com/sphinx-doc/sphinx/issues/2231)
\\newcommand{\\DUrolecode}[1]{%
\\small{}\\texttt{#1}\\normalsize{}%
}%""",
}
......
......@@ -775,6 +775,8 @@ File Force Field
:code:`amber99sbnmr.xml` Amber99SB with modifications to fit NMR data\ :cite:`Li2010`
:code:`amber03.xml` Amber03\ :cite:`Duan2003`
:code:`amber10.xml` Amber10 (documented in the AmberTools_ manual as `ff10`)
:code:`amberfb15.xml` AMBER-FB15\ :cite:`Wang2017`. Intramolecular parameters optimized with
ForceBalance using high-level ab initio data.
:code:`amoeba2009.xml` AMOEBA 2009\ :cite:`Ren2002`. This force field is deprecated. It is
recommended to use AMOEBA 2013 instead.
:code:`amoeba2013.xml` AMOEBA 2013\ :cite:`Shi2013`
......@@ -2935,6 +2937,32 @@ need to be specified once for each class. The atom charges, which are different
for each type, are taken from the residue template instead.
Including Other Files
=====================
Sometimes it is useful to split a force field definition into multiple files,
but still be able to use the force field by specifying only a single file. You
can accomplish this with the :code:`<Include>` tag. For example:
.. code-block:: xml
<ForceField>
<Include file="definitions.xml"/>
...
</ForceField>
The :code:`file` attribute gives the path of the file to include. It may be
relative either to the directory containing the parent XML file (the one with
the :code:`<Include>` tag) or the OpenMM data directory (the one containing
built in force fields).
The included file is fully processed before any other tags in the parent file
are processed, and its definitions are added to the force field. This means the
parent file can refer to atom types defined in the included file, but not the
other way around. If there are multiple :code:`<Include>` tags, they are processed
in the order they appear in the file.
Using Multiple Files
********************
......
......@@ -185,10 +185,16 @@ latex_elements = {
\\usepackage{caption}
\\setcounter{tocdepth}{3}
\\captionsetup[figure]{labelformat=empty}
% Backwards compatibility for sphinx < 1.5
\\let\\DUspan\\null % force DUspan to be defined
\\renewcommand{\DUspan}[2]{%
\\IfEqCase{#1}{%
{code}{\\small{}\\texttt{#2}\\normalsize{}}%
{code}{\\small{}\\texttt{#2}\\normalsize{}}
}[\\PackageError{DUspan}{Unrecognized option passed to DUspan: #1}{}]%
}%
% Sphinx > 1.5 compatibility (github.com/sphinx-doc/sphinx/issues/2231)
\\newcommand{\\DUrolecode}[1]{%
\\small{}\\texttt{#1}\\normalsize{}%
}%""",
# Omit the index.
......
......@@ -518,6 +518,18 @@
type = {Journal Article}
}
@article{Wang2017
author = {Wang, Lee-Ping and McKiernan, Keri A. and Gomes, Joseph and Beauchamp, Kyle A. and Head-Gordon, Teresa and Rice, Julia E. and Swope, William C. and Martínez, Todd J. and Pande, Vijay S.},
title = {Building a More Predictive Protein Force Field: A Systematic and Reproducible Route to AMBER-FB15},
journal = {Journal of Physical Chemistry B},
volume = {0},
number = {ja},
pages = {null},
year = {2017},
type = {Journal Article},
doi = {10.1021/acs.jpcb.7b02320},
}
@article{Wennberg2015
author = {Wennberg, Christian L. and Murtola, Teemu and Páll, Szilárd and Abraham, Mark J. and Hess, Berk and Lindahl, Erik},
title = {Direct-Space Corrections Enable Fast and Accurate {Lorentz–Berthelot} Combination Rule {Lennard-Jones} Lattice Summation},
......@@ -528,4 +540,3 @@
year = {2015},
type = {Journal Article}
}
......@@ -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 (platformProperties[i] == propertyName) {
for (auto& prop : platformProperties)
if (prop == 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 (platforms[i]->supportsKernels(kernelNames) && platforms[i]->getSpeed() > speed) {
best = platforms[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(plugins[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(plugins[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(plugins[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(plugins[i], "registerKernelFactories");
*(void **)(&init) = dlsym(plugin, "registerKernelFactories");
if (init != NULL)
(*init)();
}
......
......@@ -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);
}
......@@ -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 (expressions[i]->getVariables().find(name) != expressions[i]->getVariables().end())
variableReferences[index].push_back(&expressions[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 {
......
......@@ -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/molecules[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) {
......
......@@ -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 (platformProperties[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 forceImpls[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 += forceImpls[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)
forceImpls[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 = forceImpls[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[bonds[i].first].push_back(bonds[i].second);
particleBonds[bonds[i].second].push_back(bonds[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();
......
......@@ -52,8 +52,8 @@ CustomCentroidBondForce::CustomCentroidBondForce(int numGroups, const string& en
}
CustomCentroidBondForce::~CustomCentroidBondForce() {
for (int i = 0; i < (int) functions.size(); i++)
delete functions[i].function;
for (auto function : functions)
delete function.function;
}
const string& CustomCentroidBondForce::getEnergyFunction() const {
......
......@@ -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 (particles[j] < 0 || particles[j] >= system.getNumParticles()) {
for (int particle : particles)
if (particle < 0 || particle >= system.getNumParticles()) {
stringstream msg;
msg << "CustomCentroidBondForce: Illegal particle index for a group: ";
msg << particles[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 (groups[j] < 0 || groups[j] >= owner.getNumGroups()) {
for (int group : groups)
if (group < 0 || group >= owner.getNumGroups()) {
stringstream msg;
msg << "CustomCentroidBondForce: Illegal group index for a bond: ";
msg << groups[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);
......
......@@ -53,8 +53,8 @@ CustomCompoundBondForce::CustomCompoundBondForce(int numParticles, const string&
CustomCompoundBondForce::~CustomCompoundBondForce() {
for (int i = 0; i < (int) functions.size(); i++)
delete functions[i].function;
for (auto function : functions)
delete function.function;
}
const string& CustomCompoundBondForce::getEnergyFunction() const {
......
......@@ -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 (particles[j] < 0 || particles[j] >= system.getNumParticles()) {
for (int particle : particles)
if (particle < 0 || particle >= system.getNumParticles()) {
stringstream msg;
msg << "CustomCompoundBondForce: Illegal particle index for a bond: ";
msg << particles[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);
......
......@@ -51,8 +51,8 @@ CustomGBForce::CustomGBForce() : nonbondedMethod(NoCutoff), cutoffDistance(1.0)
}
CustomGBForce::~CustomGBForce() {
for (int i = 0; i < (int) functions.size(); i++)
delete functions[i].function;
for (auto function : functions)
delete function.function;
}
CustomGBForce::NonbondedMethod CustomGBForce::getNonbondedMethod() const {
......@@ -60,6 +60,8 @@ CustomGBForce::NonbondedMethod CustomGBForce::getNonbondedMethod() const {
}
void CustomGBForce::setNonbondedMethod(NonbondedMethod method) {
if (method < 0 || method > 2)
throw OpenMMException("CustomGBForce: Illegal value for nonbonded method");
nonbondedMethod = method;
}
......
......@@ -52,8 +52,8 @@ CustomHbondForce::CustomHbondForce(const string& energy) : energyExpression(ener
CustomHbondForce::~CustomHbondForce() {
for (int i = 0; i < (int) functions.size(); i++)
delete functions[i].function;
for (auto function : functions)
delete function.function;
}
const string& CustomHbondForce::getEnergyFunction() const {
......@@ -69,6 +69,8 @@ CustomHbondForce::NonbondedMethod CustomHbondForce::getNonbondedMethod() const {
}
void CustomHbondForce::setNonbondedMethod(NonbondedMethod method) {
if (method < 0 || method > 2)
throw OpenMMException("CustomHbondForce: Illegal value for nonbonded method");
nonbondedMethod = method;
}
......
......@@ -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);
......
......@@ -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);
......
......@@ -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.
......
......@@ -48,8 +48,8 @@ CustomManyParticleForce::CustomManyParticleForce(int particlesPerSet, const stri
}
CustomManyParticleForce::~CustomManyParticleForce() {
for (int i = 0; i < (int) functions.size(); i++)
delete functions[i].function;
for (auto function : functions)
delete function.function;
}
const string& CustomManyParticleForce::getEnergyFunction() const {
......@@ -65,6 +65,8 @@ CustomManyParticleForce::NonbondedMethod CustomManyParticleForce::getNonbondedMe
}
void CustomManyParticleForce::setNonbondedMethod(NonbondedMethod method) {
if (method < 0 || method > 2)
throw OpenMMException("CustomManyParticleForce: Illegal value for nonbonded method");
nonbondedMethod = method;
}
......@@ -162,9 +164,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 = bonds[i].first;
int p2 = bonds[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 +174,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 {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment