Commit 88313407 authored by peastman's avatar peastman
Browse files

Use C++11 style loops

parent d314e695
......@@ -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)();
}
......
......@@ -52,8 +52,8 @@ void CMAPTorsionForceProxy::serialize(const void* object, SerializationNode& nod
vector<double> energy;
force.getMapParameters(i, size, energy);
SerializationNode& map = maps.createChildNode("Map").setIntProperty("size", size);
for (int i = 0; i < (int) energy.size(); i++)
map.createChildNode("Energy").setDoubleProperty("e", energy[i]);
for (auto e : energy)
map.createChildNode("Energy").setDoubleProperty("e", e);
}
SerializationNode& torsions = node.createChildNode("Torsions");
for (int i = 0; i < force.getNumTorsions(); i++) {
......@@ -73,8 +73,7 @@ void* CMAPTorsionForceProxy::deserialize(const SerializationNode& node) const {
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& maps = node.getChildNode("Maps");
for (int i = 0; i < (int) maps.getChildren().size(); i++) {
const SerializationNode& map = maps.getChildren()[i];
for (auto& map : maps.getChildren()) {
int size = map.getIntProperty("size");
if (size*size != map.getChildren().size())
throw OpenMMException("Wrong number of values specified for CMAP");
......@@ -84,12 +83,10 @@ void* CMAPTorsionForceProxy::deserialize(const SerializationNode& node) const {
force->addMap(size, energy);
}
const SerializationNode& torsions = node.getChildNode("Torsions");
for (int i = 0; i < (int) torsions.getChildren().size(); i++) {
const SerializationNode& torsion = torsions.getChildren()[i];
for (auto& torsion : torsions.getChildren())
force->addTorsion(torsion.getIntProperty("map"), torsion.getIntProperty("a1"), torsion.getIntProperty("a2"), torsion.getIntProperty("a3"), torsion.getIntProperty("a4"),
torsion.getIntProperty("b1"), torsion.getIntProperty("b2"), torsion.getIntProperty("b3"), torsion.getIntProperty("b4"));
}
}
catch (...) {
delete force;
throw;
......
......@@ -85,26 +85,19 @@ void* CustomAngleForceProxy::deserialize(const SerializationNode& node) const {
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& perAngleParams = node.getChildNode("PerAngleParameters");
for (int i = 0; i < (int) perAngleParams.getChildren().size(); i++) {
const SerializationNode& parameter = perAngleParams.getChildren()[i];
for (auto& parameter : perAngleParams.getChildren())
force->addPerAngleParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
for (auto& parameter : energyDerivs.getChildren())
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& angles = node.getChildNode("Angles");
vector<double> params(force->getNumPerAngleParameters());
for (int i = 0; i < (int) angles.getChildren().size(); i++) {
const SerializationNode& angle = angles.getChildren()[i];
for (auto& angle : angles.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......
......@@ -85,26 +85,19 @@ void* CustomBondForceProxy::deserialize(const SerializationNode& node) const {
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& perBondParams = node.getChildNode("PerBondParameters");
for (int i = 0; i < (int) perBondParams.getChildren().size(); i++) {
const SerializationNode& parameter = perBondParams.getChildren()[i];
for (auto& parameter : perBondParams.getChildren())
force->addPerBondParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
for (auto& parameter : energyDerivs.getChildren())
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& bonds = node.getChildNode("Bonds");
vector<double> params(force->getNumPerBondParameters());
for (int i = 0; i < (int) bonds.getChildren().size(); i++) {
const SerializationNode& bond = bonds.getChildren()[i];
for (auto& bond : bonds.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......
......@@ -108,39 +108,31 @@ void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) c
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& perBondParams = node.getChildNode("PerBondParameters");
for (int i = 0; i < (int) perBondParams.getChildren().size(); i++) {
const SerializationNode& parameter = perBondParams.getChildren()[i];
for (auto& parameter : perBondParams.getChildren())
force->addPerBondParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
for (auto& parameter : energyDerivs.getChildren())
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& groups = node.getChildNode("Groups");
for (int i = 0; i < (int) groups.getChildren().size(); i++) {
const SerializationNode& group = groups.getChildren()[i];
for (auto& group : groups.getChildren()) {
vector<int> particles;
vector<double> weights;
for (int j = 0; j < (int) group.getChildren().size(); j++) {
particles.push_back(group.getChildren()[j].getIntProperty("p"));
if (group.getChildren()[j].hasProperty("weight"))
weights.push_back(group.getChildren()[j].getDoubleProperty("weight"));
for (auto& child : group.getChildren()) {
particles.push_back(child.getIntProperty("p"));
if (child.hasProperty("weight"))
weights.push_back(child.getDoubleProperty("weight"));
}
force->addGroup(particles, weights);
}
const SerializationNode& bonds = node.getChildNode("Bonds");
vector<int> bondGroups(force->getNumGroupsPerBond());
vector<double> params(force->getNumPerBondParameters());
for (int i = 0; i < (int) bonds.getChildren().size(); i++) {
const SerializationNode& bond = bonds.getChildren()[i];
for (auto& bond : bonds.getChildren()) {
for (int j = 0; j < (int) bondGroups.size(); j++) {
stringstream key;
key << "g";
......@@ -156,8 +148,7 @@ void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) c
force->addBond(bondGroups, params);
}
const SerializationNode& functions = node.getChildNode("Functions");
for (int i = 0; i < (int) functions.getChildren().size(); i++) {
const SerializationNode& function = functions.getChildren()[i];
for (auto& function : functions.getChildren()) {
if (function.hasProperty("type")) {
force->addTabulatedFunction(function.getStringProperty("name"), function.decodeObject<TabulatedFunction>());
}
......@@ -166,8 +157,8 @@ void* CustomCentroidBondForceProxy::deserialize(const SerializationNode& node) c
const SerializationNode& valuesNode = function.getChildNode("Values");
vector<double> values;
for (int j = 0; j < (int) valuesNode.getChildren().size(); j++)
values.push_back(valuesNode.getChildren()[j].getDoubleProperty("v"));
for (auto& child : valuesNode.getChildren())
values.push_back(child.getDoubleProperty("v"));
force->addTabulatedFunction(function.getStringProperty("name"), new Continuous1DFunction(values, function.getDoubleProperty("min"), function.getDoubleProperty("max")));
}
}
......
......@@ -95,27 +95,20 @@ void* CustomCompoundBondForceProxy::deserialize(const SerializationNode& node) c
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& perBondParams = node.getChildNode("PerBondParameters");
for (int i = 0; i < (int) perBondParams.getChildren().size(); i++) {
const SerializationNode& parameter = perBondParams.getChildren()[i];
for (auto& parameter : perBondParams.getChildren())
force->addPerBondParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
for (auto& parameter : energyDerivs.getChildren())
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& bonds = node.getChildNode("Bonds");
vector<int> particles(force->getNumParticlesPerBond());
vector<double> params(force->getNumPerBondParameters());
for (int i = 0; i < (int) bonds.getChildren().size(); i++) {
const SerializationNode& bond = bonds.getChildren()[i];
for (auto& bond : bonds.getChildren()) {
for (int j = 0; j < (int) particles.size(); j++) {
stringstream key;
key << "p";
......@@ -131,8 +124,7 @@ void* CustomCompoundBondForceProxy::deserialize(const SerializationNode& node) c
force->addBond(particles, params);
}
const SerializationNode& functions = node.getChildNode("Functions");
for (int i = 0; i < (int) functions.getChildren().size(); i++) {
const SerializationNode& function = functions.getChildren()[i];
for (auto& function : functions.getChildren()) {
if (function.hasProperty("type")) {
force->addTabulatedFunction(function.getStringProperty("name"), function.decodeObject<TabulatedFunction>());
}
......@@ -141,8 +133,8 @@ void* CustomCompoundBondForceProxy::deserialize(const SerializationNode& node) c
const SerializationNode& valuesNode = function.getChildNode("Values");
vector<double> values;
for (int j = 0; j < (int) valuesNode.getChildren().size(); j++)
values.push_back(valuesNode.getChildren()[j].getDoubleProperty("v"));
for (auto& child : valuesNode.getChildren())
values.push_back(child.getDoubleProperty("v"));
force->addTabulatedFunction(function.getStringProperty("name"), new Continuous1DFunction(values, function.getDoubleProperty("min"), function.getDoubleProperty("max")));
}
}
......
......@@ -77,19 +77,14 @@ void* CustomExternalForceProxy::deserialize(const SerializationNode& node) const
CustomExternalForce* force = new CustomExternalForce(node.getStringProperty("energy"));
force->setForceGroup(node.getIntProperty("forceGroup", 0));
const SerializationNode& perParticleParams = node.getChildNode("PerParticleParameters");
for (int i = 0; i < (int) perParticleParams.getChildren().size(); i++) {
const SerializationNode& parameter = perParticleParams.getChildren()[i];
for (auto& parameter : perParticleParams.getChildren())
force->addPerParticleParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
const SerializationNode& particles = node.getChildNode("Particles");
vector<double> params(force->getNumPerParticleParameters());
for (int i = 0; i < (int) particles.getChildren().size(); i++) {
const SerializationNode& particle = particles.getChildren()[i];
for (auto& particle : particles.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......
......@@ -107,36 +107,25 @@ void* CustomGBForceProxy::deserialize(const SerializationNode& node) const {
force->setNonbondedMethod((CustomGBForce::NonbondedMethod) node.getIntProperty("method"));
force->setCutoffDistance(node.getDoubleProperty("cutoff"));
const SerializationNode& perParticleParams = node.getChildNode("PerParticleParameters");
for (int i = 0; i < (int) perParticleParams.getChildren().size(); i++) {
const SerializationNode& parameter = perParticleParams.getChildren()[i];
for (auto& parameter : perParticleParams.getChildren())
force->addPerParticleParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
if (version > 1) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
for (auto& parameter : energyDerivs.getChildren())
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& computedValues = node.getChildNode("ComputedValues");
for (int i = 0; i < (int) computedValues.getChildren().size(); i++) {
const SerializationNode& value = computedValues.getChildren()[i];
for (auto& value : computedValues.getChildren())
force->addComputedValue(value.getStringProperty("name"), value.getStringProperty("expression"), (CustomGBForce::ComputationType) value.getIntProperty("type"));
}
const SerializationNode& energyTerms = node.getChildNode("EnergyTerms");
for (int i = 0; i < (int) energyTerms.getChildren().size(); i++) {
const SerializationNode& term = energyTerms.getChildren()[i];
for (auto& term : energyTerms.getChildren())
force->addEnergyTerm(term.getStringProperty("expression"), (CustomGBForce::ComputationType) term.getIntProperty("type"));
}
const SerializationNode& particles = node.getChildNode("Particles");
vector<double> params(force->getNumPerParticleParameters());
for (int i = 0; i < (int) particles.getChildren().size(); i++) {
const SerializationNode& particle = particles.getChildren()[i];
for (auto& particle : particles.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......@@ -146,13 +135,10 @@ void* CustomGBForceProxy::deserialize(const SerializationNode& node) const {
force->addParticle(params);
}
const SerializationNode& exclusions = node.getChildNode("Exclusions");
for (int i = 0; i < (int) exclusions.getChildren().size(); i++) {
const SerializationNode& exclusion = exclusions.getChildren()[i];
for (auto& exclusion : exclusions.getChildren())
force->addExclusion(exclusion.getIntProperty("p1"), exclusion.getIntProperty("p2"));
}
const SerializationNode& functions = node.getChildNode("Functions");
for (int i = 0; i < (int) functions.getChildren().size(); i++) {
const SerializationNode& function = functions.getChildren()[i];
for (auto& function : functions.getChildren()) {
if (function.hasProperty("type")) {
force->addTabulatedFunction(function.getStringProperty("name"), function.decodeObject<TabulatedFunction>());
}
......@@ -161,8 +147,8 @@ void* CustomGBForceProxy::deserialize(const SerializationNode& node) const {
const SerializationNode& valuesNode = function.getChildNode("Values");
vector<double> values;
for (int j = 0; j < (int) valuesNode.getChildren().size(); j++)
values.push_back(valuesNode.getChildren()[j].getDoubleProperty("v"));
for (auto& child : valuesNode.getChildren())
values.push_back(child.getDoubleProperty("v"));
force->addTabulatedFunction(function.getStringProperty("name"), new Continuous1DFunction(values, function.getDoubleProperty("min"), function.getDoubleProperty("max")));
}
}
......
......@@ -107,24 +107,17 @@ void* CustomHbondForceProxy::deserialize(const SerializationNode& node) const {
force->setNonbondedMethod((CustomHbondForce::NonbondedMethod) node.getIntProperty("method"));
force->setCutoffDistance(node.getDoubleProperty("cutoff"));
const SerializationNode& perDonorParams = node.getChildNode("PerDonorParameters");
for (int i = 0; i < (int) perDonorParams.getChildren().size(); i++) {
const SerializationNode& parameter = perDonorParams.getChildren()[i];
for (auto& parameter : perDonorParams.getChildren())
force->addPerDonorParameter(parameter.getStringProperty("name"));
}
const SerializationNode& perAcceptorParams = node.getChildNode("PerAcceptorParameters");
for (int i = 0; i < (int) perAcceptorParams.getChildren().size(); i++) {
const SerializationNode& parameter = perAcceptorParams.getChildren()[i];
for (auto& parameter : perAcceptorParams.getChildren())
force->addPerAcceptorParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
const SerializationNode& donors = node.getChildNode("Donors");
vector<double> params(force->getNumPerDonorParameters());
for (int i = 0; i < (int) donors.getChildren().size(); i++) {
const SerializationNode& donor = donors.getChildren()[i];
for (auto& donor : donors.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......@@ -135,8 +128,7 @@ void* CustomHbondForceProxy::deserialize(const SerializationNode& node) const {
}
const SerializationNode& acceptors = node.getChildNode("Acceptors");
params.resize(force->getNumPerAcceptorParameters());
for (int i = 0; i < (int) acceptors.getChildren().size(); i++) {
const SerializationNode& acceptor = acceptors.getChildren()[i];
for (auto& acceptor : acceptors.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......@@ -146,13 +138,10 @@ void* CustomHbondForceProxy::deserialize(const SerializationNode& node) const {
force->addAcceptor(acceptor.getIntProperty("p1"), acceptor.getIntProperty("p2"), acceptor.getIntProperty("p3"), params);
}
const SerializationNode& exclusions = node.getChildNode("Exclusions");
for (int i = 0; i < (int) exclusions.getChildren().size(); i++) {
const SerializationNode& exclusion = exclusions.getChildren()[i];
for (auto& exclusion : exclusions.getChildren())
force->addExclusion(exclusion.getIntProperty("donor"), exclusion.getIntProperty("acceptor"));
}
const SerializationNode& functions = node.getChildNode("Functions");
for (int i = 0; i < (int) functions.getChildren().size(); i++) {
const SerializationNode& function = functions.getChildren()[i];
for (auto& function : functions.getChildren()) {
if (function.hasProperty("type")) {
force->addTabulatedFunction(function.getStringProperty("name"), function.decodeObject<TabulatedFunction>());
}
......@@ -161,8 +150,8 @@ void* CustomHbondForceProxy::deserialize(const SerializationNode& node) const {
const SerializationNode& valuesNode = function.getChildNode("Values");
vector<double> values;
for (int j = 0; j < (int) valuesNode.getChildren().size(); j++)
values.push_back(valuesNode.getChildren()[j].getDoubleProperty("v"));
for (auto& child : valuesNode.getChildren())
values.push_back(child.getDoubleProperty("v"));
force->addTabulatedFunction(function.getStringProperty("name"), new Continuous1DFunction(values, function.getDoubleProperty("min"), function.getDoubleProperty("max")));
}
}
......
......@@ -74,44 +74,39 @@ void* CustomIntegratorProxy::deserialize(const SerializationNode& node) const {
throw OpenMMException("Unsupported version number");
CustomIntegrator* integrator = new CustomIntegrator(node.getDoubleProperty("stepSize"));
const SerializationNode& globalVariablesNode = node.getChildNode("GlobalVariables");
const map<string, string> &globalVariableProp = globalVariablesNode.getProperties();
for(map<string, string>::const_iterator cit = globalVariableProp.begin(); cit != globalVariableProp.end(); cit++) {
integrator->addGlobalVariable(cit->first, globalVariablesNode.getDoubleProperty(cit->first));
}
for (auto& prop : globalVariablesNode.getProperties())
integrator->addGlobalVariable(prop.first, globalVariablesNode.getDoubleProperty(prop.first));
const SerializationNode& perDofVariablesNode = node.getChildNode("PerDofVariables");
const vector<SerializationNode>& perDofVariableList = perDofVariablesNode.getChildren();
int count = 0;
for(vector<SerializationNode>::const_iterator cit=perDofVariableList.begin(); cit != perDofVariableList.end(); cit++, count++) {
const vector<SerializationNode>& perDofVariableVector = cit->getChildren();
integrator->addPerDofVariable(cit->getName(),0);
for (auto& var : perDofVariablesNode.getChildren()) {
integrator->addPerDofVariable(var.getName(), 0);
vector<Vec3> perDofValues;
for(vector<SerializationNode>::const_iterator dit=perDofVariableVector.begin(); dit!=perDofVariableVector.end(); dit++) {
perDofValues.push_back(Vec3(dit->getDoubleProperty("x"),dit->getDoubleProperty("y"),dit->getDoubleProperty("z")));
}
for (auto& child : var.getChildren())
perDofValues.push_back(Vec3(child.getDoubleProperty("x"), child.getDoubleProperty("y"), child.getDoubleProperty("z")));
integrator->setPerDofVariable(count, perDofValues);
count++;
}
const SerializationNode& computationsNode = node.getChildNode("Computations");
const vector<SerializationNode>& computationsList = computationsNode.getChildren();
for(vector<SerializationNode>::const_iterator cit = computationsList.begin(); cit != computationsList.end(); cit++) {
CustomIntegrator::ComputationType computationType = static_cast<CustomIntegrator::ComputationType>(cit->getIntProperty("computationType"));
for (auto& comp : computationsNode.getChildren()) {
CustomIntegrator::ComputationType computationType = static_cast<CustomIntegrator::ComputationType>(comp.getIntProperty("computationType"));
// make sure that the int casts to a valid enum
if(computationType == CustomIntegrator::ComputeGlobal) {
integrator->addComputeGlobal(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ComputePerDof) {
integrator->addComputePerDof(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ComputeSum) {
integrator->addComputeSum(cit->getStringProperty("computationVariable"), cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::ConstrainPositions) {
if (computationType == CustomIntegrator::ComputeGlobal) {
integrator->addComputeGlobal(comp.getStringProperty("computationVariable"), comp.getStringProperty("computationExpression"));
} else if (computationType == CustomIntegrator::ComputePerDof) {
integrator->addComputePerDof(comp.getStringProperty("computationVariable"), comp.getStringProperty("computationExpression"));
} else if (computationType == CustomIntegrator::ComputeSum) {
integrator->addComputeSum(comp.getStringProperty("computationVariable"), comp.getStringProperty("computationExpression"));
} else if (computationType == CustomIntegrator::ConstrainPositions) {
integrator->addConstrainPositions();
} else if(computationType == CustomIntegrator::ConstrainVelocities) {
} else if (computationType == CustomIntegrator::ConstrainVelocities) {
integrator->addConstrainVelocities();
} else if(computationType == CustomIntegrator::UpdateContextState) {
} else if (computationType == CustomIntegrator::UpdateContextState) {
integrator->addUpdateContextState();
} else if(computationType == CustomIntegrator::IfBlockStart) {
integrator->beginIfBlock(cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::WhileBlockStart) {
integrator->beginWhileBlock(cit->getStringProperty("computationExpression"));
} else if(computationType == CustomIntegrator::BlockEnd) {
} else if (computationType == CustomIntegrator::IfBlockStart) {
integrator->beginIfBlock(comp.getStringProperty("computationExpression"));
} else if (computationType == CustomIntegrator::WhileBlockStart) {
integrator->beginWhileBlock(comp.getStringProperty("computationExpression"));
} else if (computationType == CustomIntegrator::BlockEnd) {
integrator->endBlock();
} else {
throw(OpenMMException("Custom Integrator Deserialization: Unknown computation type"));
......
......@@ -84,10 +84,10 @@ void CustomManyParticleForceProxy::serialize(const void* object, SerializationNo
force.getTypeFilter(i, types);
stringstream list;
bool first = true;
for (set<int>::const_iterator iter = types.begin(); iter != types.end(); ++iter) {
for (int type : types) {
if (!first)
list << ",";
list << *iter;
list << type;
first = false;
}
filters.createChildNode("Filter").setIntProperty("index", i).setStringProperty("types", list.str());
......@@ -108,19 +108,14 @@ void* CustomManyParticleForceProxy::deserialize(const SerializationNode& node) c
force->setPermutationMode((CustomManyParticleForce::PermutationMode) node.getIntProperty("permutationMode"));
force->setCutoffDistance(node.getDoubleProperty("cutoff"));
const SerializationNode& perParticleParams = node.getChildNode("PerParticleParameters");
for (int i = 0; i < (int) perParticleParams.getChildren().size(); i++) {
const SerializationNode& parameter = perParticleParams.getChildren()[i];
for (auto& parameter : perParticleParams.getChildren())
force->addPerParticleParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
const SerializationNode& particles = node.getChildNode("Particles");
vector<double> params(force->getNumPerParticleParameters());
for (int i = 0; i < (int) particles.getChildren().size(); i++) {
const SerializationNode& particle = particles.getChildren()[i];
for (auto& particle : particles.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......@@ -130,13 +125,10 @@ void* CustomManyParticleForceProxy::deserialize(const SerializationNode& node) c
force->addParticle(params, particle.getIntProperty("type"));
}
const SerializationNode& exclusions = node.getChildNode("Exclusions");
for (int i = 0; i < (int) exclusions.getChildren().size(); i++) {
const SerializationNode& exclusion = exclusions.getChildren()[i];
for (auto& exclusion : exclusions.getChildren())
force->addExclusion(exclusion.getIntProperty("p1"), exclusion.getIntProperty("p2"));
}
const SerializationNode& filters = node.getChildNode("TypeFilters");
for (int i = 0; i < (int) filters.getChildren().size(); i++) {
const SerializationNode& filter = filters.getChildren()[i];
for (auto& filter : filters.getChildren()) {
string typesString = filter.getStringProperty("types");
vector<string> splitTypes;
size_t searchPos = 0, nextPos;
......@@ -146,20 +138,18 @@ void* CustomManyParticleForceProxy::deserialize(const SerializationNode& node) c
}
splitTypes.push_back(typesString.substr(searchPos));
set<int> types;
for (int j = 0; j < (int) splitTypes.size(); j++) {
if (splitTypes[j].size() > 0) {
for (auto& t : splitTypes) {
if (t.size() > 0) {
int type;
stringstream(splitTypes[j]) >> type;
stringstream(t) >> type;
types.insert(type);
}
}
force->setTypeFilter(filter.getIntProperty("index"), types);
}
const SerializationNode& functions = node.getChildNode("Functions");
for (int i = 0; i < (int) functions.getChildren().size(); i++) {
const SerializationNode& function = functions.getChildren()[i];
for (auto& function : functions.getChildren())
force->addTabulatedFunction(function.getStringProperty("name"), function.decodeObject<TabulatedFunction>());
}
return force;
}
catch (...) {
......
......@@ -92,11 +92,11 @@ void CustomNonbondedForceProxy::serialize(const void* object, SerializationNode&
std::set<int> set2;
force.getInteractionGroupParameters(i, set1, set2);
SerializationNode& set1node = interactionGroup.createChildNode("Set1");
for (std::set<int>::iterator it = set1.begin(); it != set1.end(); ++it)
set1node.createChildNode("Particle").setIntProperty("index", *it);
for (int p : set1)
set1node.createChildNode("Particle").setIntProperty("index", p);
SerializationNode& set2node = interactionGroup.createChildNode("Set2");
for (std::set<int>::iterator it = set2.begin(); it != set2.end(); ++it)
set2node.createChildNode("Particle").setIntProperty("index", *it);
for (int p : set2)
set2node.createChildNode("Particle").setIntProperty("index", p);
}
}
......@@ -114,26 +114,19 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons
force->setSwitchingDistance(node.getDoubleProperty("switchingDistance", -1.0));
force->setUseLongRangeCorrection(node.getBoolProperty("useLongRangeCorrection", false));
const SerializationNode& perParticleParams = node.getChildNode("PerParticleParameters");
for (int i = 0; i < (int) perParticleParams.getChildren().size(); i++) {
const SerializationNode& parameter = perParticleParams.getChildren()[i];
for (auto& parameter : perParticleParams.getChildren())
force->addPerParticleParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
if (version > 1) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
for (auto& parameter : energyDerivs.getChildren())
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& particles = node.getChildNode("Particles");
vector<double> params(force->getNumPerParticleParameters());
for (int i = 0; i < (int) particles.getChildren().size(); i++) {
const SerializationNode& particle = particles.getChildren()[i];
for (auto& particle : particles.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......@@ -143,13 +136,10 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons
force->addParticle(params);
}
const SerializationNode& exclusions = node.getChildNode("Exclusions");
for (int i = 0; i < (int) exclusions.getChildren().size(); i++) {
const SerializationNode& exclusion = exclusions.getChildren()[i];
for (auto& exclusion : exclusions.getChildren())
force->addExclusion(exclusion.getIntProperty("p1"), exclusion.getIntProperty("p2"));
}
const SerializationNode& functions = node.getChildNode("Functions");
for (int i = 0; i < (int) functions.getChildren().size(); i++) {
const SerializationNode& function = functions.getChildren()[i];
for (auto& function : functions.getChildren()) {
if (function.hasProperty("type")) {
force->addTabulatedFunction(function.getStringProperty("name"), function.decodeObject<TabulatedFunction>());
}
......@@ -158,30 +148,28 @@ void* CustomNonbondedForceProxy::deserialize(const SerializationNode& node) cons
const SerializationNode& valuesNode = function.getChildNode("Values");
vector<double> values;
for (int j = 0; j < (int) valuesNode.getChildren().size(); j++)
values.push_back(valuesNode.getChildren()[j].getDoubleProperty("v"));
for (auto& child : valuesNode.getChildren())
values.push_back(child.getDoubleProperty("v"));
force->addTabulatedFunction(function.getStringProperty("name"), new Continuous1DFunction(values, function.getDoubleProperty("min"), function.getDoubleProperty("max")));
}
}
bool hasInteractionGroups = false; // Older files will be missing this block.
for (int i = 0; i < (int) node.getChildren().size(); i++) {
if (node.getChildren()[i].getName() == "InteractionGroups")
for (auto& child : node.getChildren())
if (child.getName() == "InteractionGroups")
hasInteractionGroups = true;
}
if (hasInteractionGroups) {
const SerializationNode& interactionGroups = node.getChildNode("InteractionGroups");
for (int i = 0; i < (int) interactionGroups.getChildren().size(); i++) {
const SerializationNode& interactionGroup = interactionGroups.getChildren()[i];
for (auto& interactionGroup : interactionGroups.getChildren()) {
// Get set 1.
const SerializationNode& set1node = interactionGroup.getChildNode("Set1");
std::set<int> set1;
for (int j = 0; j < (int) set1node.getChildren().size(); j++)
set1.insert(set1node.getChildren()[j].getIntProperty("index"));
for (auto& child : set1node.getChildren())
set1.insert(child.getIntProperty("index"));
// Get set 2.
const SerializationNode& set2node = interactionGroup.getChildNode("Set2");
std::set<int> set2;
for (int j = 0; j < (int) set2node.getChildren().size(); j++)
set2.insert(set2node.getChildren()[j].getIntProperty("index"));
for (auto& child : set2node.getChildren())
set2.insert(child.getIntProperty("index"));
force->addInteractionGroup(set1, set2);
}
}
......
......@@ -85,26 +85,19 @@ void* CustomTorsionForceProxy::deserialize(const SerializationNode& node) const
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& perTorsionParams = node.getChildNode("PerTorsionParameters");
for (int i = 0; i < (int) perTorsionParams.getChildren().size(); i++) {
const SerializationNode& parameter = perTorsionParams.getChildren()[i];
for (auto& parameter : perTorsionParams.getChildren())
force->addPerTorsionParameter(parameter.getStringProperty("name"));
}
const SerializationNode& globalParams = node.getChildNode("GlobalParameters");
for (int i = 0; i < (int) globalParams.getChildren().size(); i++) {
const SerializationNode& parameter = globalParams.getChildren()[i];
for (auto& parameter : globalParams.getChildren())
force->addGlobalParameter(parameter.getStringProperty("name"), parameter.getDoubleProperty("default"));
}
if (version > 2) {
const SerializationNode& energyDerivs = node.getChildNode("EnergyParameterDerivatives");
for (int i = 0; i < (int) energyDerivs.getChildren().size(); i++) {
const SerializationNode& parameter = energyDerivs.getChildren()[i];
for (auto& parameter : energyDerivs.getChildren())
force->addEnergyParameterDerivative(parameter.getStringProperty("name"));
}
}
const SerializationNode& torsions = node.getChildNode("Torsions");
vector<double> params(force->getNumPerTorsionParameters());
for (int i = 0; i < (int) torsions.getChildren().size(); i++) {
const SerializationNode& torsion = torsions.getChildren()[i];
for (auto& torsion : torsions.getChildren()) {
for (int j = 0; j < (int) params.size(); j++) {
stringstream key;
key << "param";
......
......@@ -72,11 +72,9 @@ void* GBSAOBCForceProxy::deserialize(const SerializationNode& node) const {
if (version > 1)
force->setSurfaceAreaEnergy(node.getDoubleProperty("surfaceAreaEnergy"));
const SerializationNode& particles = node.getChildNode("Particles");
for (int i = 0; i < (int) particles.getChildren().size(); i++) {
const SerializationNode& particle = particles.getChildren()[i];
for (auto& particle : particles.getChildren())
force->addParticle(particle.getDoubleProperty("q"), particle.getDoubleProperty("r"), particle.getDoubleProperty("scale"));
}
}
catch (...) {
delete force;
throw;
......
......@@ -78,18 +78,14 @@ void* GayBerneForceProxy::deserialize(const SerializationNode& node) const {
force->setUseSwitchingFunction(node.getBoolProperty("useSwitchingFunction", false));
force->setSwitchingDistance(node.getDoubleProperty("switchingDistance", -1.0));
const SerializationNode& particles = node.getChildNode("Particles");
for (int i = 0; i < (int) particles.getChildren().size(); i++) {
const SerializationNode& particle = particles.getChildren()[i];
for (auto& particle : particles.getChildren())
force->addParticle(particle.getDoubleProperty("sig"), particle.getDoubleProperty("eps"), particle.getIntProperty("xparticle"),
particle.getIntProperty("yparticle"), particle.getDoubleProperty("sx"), particle.getDoubleProperty("sy"), particle.getDoubleProperty("sz"),
particle.getDoubleProperty("ex"), particle.getDoubleProperty("ey"), particle.getDoubleProperty("ez"));
}
const SerializationNode& exceptions = node.getChildNode("Exceptions");
for (int i = 0; i < (int) exceptions.getChildren().size(); i++) {
const SerializationNode& exception = exceptions.getChildren()[i];
for (auto& exception : exceptions.getChildren())
force->addException(exception.getIntProperty("p1"), exception.getIntProperty("p2"), exception.getDoubleProperty("sig"), exception.getDoubleProperty("eps"));
}
}
catch (...) {
delete force;
throw;
......
......@@ -65,11 +65,9 @@ void* HarmonicAngleForceProxy::deserialize(const SerializationNode& node) const
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& angles = node.getChildNode("Angles");
for (int i = 0; i < (int) angles.getChildren().size(); i++) {
const SerializationNode& angle = angles.getChildren()[i];
for (auto& angle : angles.getChildren())
force->addAngle(angle.getIntProperty("p1"), angle.getIntProperty("p2"), angle.getIntProperty("p3"), angle.getDoubleProperty("a"), angle.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
throw;
......
......@@ -65,11 +65,9 @@ void* HarmonicBondForceProxy::deserialize(const SerializationNode& node) const {
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& bonds = node.getChildNode("Bonds");
for (int i = 0; i < (int) bonds.getChildren().size(); i++) {
const SerializationNode& bond = bonds.getChildren()[i];
for (auto& bond : bonds.getChildren())
force->addBond(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getDoubleProperty("d"), bond.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
throw;
......
......@@ -108,16 +108,12 @@ void* NonbondedForceProxy::deserialize(const SerializationNode& node) const {
}
force->setReciprocalSpaceForceGroup(node.getIntProperty("recipForceGroup", -1));
const SerializationNode& particles = node.getChildNode("Particles");
for (int i = 0; i < (int) particles.getChildren().size(); i++) {
const SerializationNode& particle = particles.getChildren()[i];
for (auto& particle : particles.getChildren())
force->addParticle(particle.getDoubleProperty("q"), particle.getDoubleProperty("sig"), particle.getDoubleProperty("eps"));
}
const SerializationNode& exceptions = node.getChildNode("Exceptions");
for (int i = 0; i < (int) exceptions.getChildren().size(); i++) {
const SerializationNode& exception = exceptions.getChildren()[i];
for (auto& exception : exceptions.getChildren())
force->addException(exception.getIntProperty("p1"), exception.getIntProperty("p2"), exception.getDoubleProperty("q"), exception.getDoubleProperty("sig"), exception.getDoubleProperty("eps"));
}
}
catch (...) {
delete force;
throw;
......
......@@ -65,12 +65,10 @@ void* PeriodicTorsionForceProxy::deserialize(const SerializationNode& node) cons
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& torsions = node.getChildNode("Torsions");
for (int i = 0; i < (int) torsions.getChildren().size(); i++) {
const SerializationNode& torsion = torsions.getChildren()[i];
for (auto& torsion : torsions.getChildren())
force->addTorsion(torsion.getIntProperty("p1"), torsion.getIntProperty("p2"), torsion.getIntProperty("p3"), torsion.getIntProperty("p4"),
torsion.getIntProperty("periodicity"), torsion.getDoubleProperty("phase"), torsion.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
throw;
......
......@@ -65,13 +65,11 @@ void* RBTorsionForceProxy::deserialize(const SerializationNode& node) const {
if (version > 1)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& torsions = node.getChildNode("Torsions");
for (int i = 0; i < (int) torsions.getChildren().size(); i++) {
const SerializationNode& torsion = torsions.getChildren()[i];
for (auto& torsion : torsions.getChildren())
force->addTorsion(torsion.getIntProperty("p1"), torsion.getIntProperty("p2"), torsion.getIntProperty("p3"), torsion.getIntProperty("p4"),
torsion.getDoubleProperty("c0"), torsion.getDoubleProperty("c1"), torsion.getDoubleProperty("c2"),
torsion.getDoubleProperty("c3"), torsion.getDoubleProperty("c4"), torsion.getDoubleProperty("c5"));
}
}
catch (...) {
delete force;
throw;
......
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