Commit 08e8b206 authored by peastman's avatar peastman Committed by GitHub
Browse files

Merge pull request #1769 from peastman/loops

Use C++11 style loops
parents 55ee0b9f 083bc501
......@@ -277,9 +277,8 @@ double AmoebaReferenceVdwForce::calculateForceAndEnergy(int numParticles,
double sigmaI = sigmas[ii];
double epsilonI = epsilons[ii];
for (std::set<int>::const_iterator jj = allExclusions[ii].begin(); jj != allExclusions[ii].end(); jj++) {
exclusions[*jj] = 1;
}
for (int jj : allExclusions[ii])
exclusions[jj] = 1;
for (unsigned int jj = ii+1; jj < static_cast<unsigned int>(numParticles); jj++) {
if (exclusions[jj] == 0) {
......@@ -310,9 +309,8 @@ double AmoebaReferenceVdwForce::calculateForceAndEnergy(int numParticles,
}
}
for (std::set<int>::const_iterator jj = allExclusions[ii].begin(); jj != allExclusions[ii].end(); jj++) {
exclusions[*jj] = 0;
}
for (int jj : allExclusions[ii])
exclusions[jj] = 0;
}
return energy;
......
......@@ -287,8 +287,8 @@ static void check_finite_differences(vector<Vec3> analytic_forces, Context &cont
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
double norm = 0.0;
for (int i = 0; i < (int) analytic_forces.size(); ++i)
norm += analytic_forces[i].dot(analytic_forces[i]);
for (auto& f : analytic_forces)
norm += f.dot(f);
norm = std::sqrt(norm);
const double stepSize = 1e-3;
double step = 0.5*stepSize/norm;
......
......@@ -61,8 +61,8 @@ static void checkFiniteDifferences(vector<Vec3> forces, Context &context, vector
// Take a small step in the direction of the energy gradient and see whether the potential energy changes by the expected amount.
 
double norm = 0.0;
for (int i = 0; i < (int) forces.size(); ++i)
norm += forces[i].dot(forces[i]);
for (auto& f : forces)
norm += f.dot(f);
norm = std::sqrt(norm);
const double stepSize = 1e-3;
double step = 0.5*stepSize/norm;
......
......@@ -72,10 +72,8 @@ void* AmoebaBondForceProxy::deserialize(const SerializationNode& node) const {
force->setAmoebaGlobalBondCubic(node.getDoubleProperty("cubic"));
force->setAmoebaGlobalBondQuartic(node.getDoubleProperty("quartic"));
const SerializationNode& bonds = node.getChildNode("Bonds");
for (unsigned int ii = 0; ii < (int) bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
for (auto& bond : bonds.getChildren())
force->addBond(bond.getIntProperty("p1"), bond.getIntProperty("p2"), bond.getDoubleProperty("d"), bond.getDoubleProperty("k"));
}
}
catch (...) {
delete force;
......
......@@ -67,8 +67,7 @@ void* AmoebaStretchBendForceProxy::deserialize(const SerializationNode& node) co
if (version > 3)
force->setUsesPeriodicBoundaryConditions(node.getBoolProperty("usesPeriodic"));
const SerializationNode& bonds = node.getChildNode("StretchBendAngles");
for (unsigned int ii = 0; ii < (int) bonds.getChildren().size(); ii++) {
const SerializationNode& bond = bonds.getChildren()[ii];
for (auto& bond : bonds.getChildren()) {
double k1, k2;
if (version == 1)
k1 = k2 = bond.getDoubleProperty("k");
......
......@@ -515,8 +515,8 @@ CpuCalcPmeReciprocalForceKernel::~CpuCalcPmeReciprocalForceKernel() {
pthread_mutex_destroy(&lock);
pthread_cond_destroy(&startCondition);
pthread_cond_destroy(&endCondition);
for (int i = 0; i < (int) tempGrid.size(); i++)
fftwf_free(tempGrid[i]);
for (auto grid : tempGrid)
fftwf_free(grid);
if (complexGrid != NULL)
fftwf_free(complexGrid);
if (hasCreatedPlan) {
......@@ -552,8 +552,8 @@ void CpuCalcPmeReciprocalForceKernel::runMainThread() {
if (includeEnergy) {
threads.resumeThreads(); // Signal threads to compute energy.
threads.waitForThreads();
for (int i = 0; i < (int) threadEnergy.size(); i++)
energy += threadEnergy[i];
for (auto e : threadEnergy)
energy += e;
}
threads.resumeThreads(); // Signal threads to perform reciprocal convolution.
threads.waitForThreads();
......@@ -805,8 +805,8 @@ CpuCalcDispersionPmeReciprocalForceKernel::~CpuCalcDispersionPmeReciprocalForceK
pthread_mutex_destroy(&lock);
pthread_cond_destroy(&startCondition);
pthread_cond_destroy(&endCondition);
for (int i = 0; i < (int) tempGrid.size(); i++)
fftwf_free(tempGrid[i]);
for (auto grid : tempGrid)
fftwf_free(grid);
if (complexGrid != NULL)
fftwf_free(complexGrid);
if (hasCreatedPlan) {
......@@ -843,8 +843,8 @@ void CpuCalcDispersionPmeReciprocalForceKernel::runMainThread() {
if (includeEnergy) {
threads.resumeThreads(); // Signal threads to compute energy.
threads.waitForThreads();
for (int i = 0; i < (int) threadEnergy.size(); i++)
energy += threadEnergy[i];
for (auto e : threadEnergy)
energy += e;
}
threads.resumeThreads(); // Signal threads to perform reciprocal convolution.
threads.waitForThreads();
......
......@@ -267,8 +267,7 @@ void ReferenceIntegrateDrudeLangevinStepKernel::execute(ContextImpl& context, co
const double fscale = (1-vscale)/integrator.getFriction();
const double kT = BOLTZ*integrator.getTemperature();
const double noisescale = sqrt(2*kT*integrator.getFriction())*sqrt(0.5*(1-vscale*vscale)/integrator.getFriction());
for (int i = 0; i < (int) normalParticles.size(); i++) {
int index = normalParticles[i];
for (int index : normalParticles) {
double invMass = particleInvMass[index];
if (invMass != 0.0) {
double sqrtInvMass = sqrt(invMass);
......
......@@ -67,16 +67,12 @@ void* DrudeForceProxy::deserialize(const SerializationNode& node) const {
DrudeForce* force = new DrudeForce();
try {
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.getIntProperty("p"), particle.getIntProperty("p1"), particle.getIntProperty("p2"), particle.getIntProperty("p3"), particle.getIntProperty("p4"),
particle.getDoubleProperty("charge"), particle.getDoubleProperty("polarizability"), particle.getDoubleProperty("a12"), particle.getDoubleProperty("a34"));
}
const SerializationNode& pairs = node.getChildNode("ScreenedPairs");
for (int i = 0; i < (int) pairs.getChildren().size(); i++) {
const SerializationNode& pair = pairs.getChildren()[i];
for (auto& pair : pairs.getChildren())
force->addScreenedPair(pair.getIntProperty("p1"), pair.getIntProperty("p2"), pair.getDoubleProperty("thole"));
}
}
catch (...) {
delete force;
......
......@@ -119,13 +119,13 @@ State RPMDIntegrator::getState(int copy, int types, bool enforcePeriodicBox, int
const vector<vector<int> >& molecules = context->getMolecules();
Vec3 periodicBoxSize[3];
state2.getPeriodicBoxVectors(periodicBoxSize[0], periodicBoxSize[1], periodicBoxSize[2]);
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 += refPos[molecules[i][j]];
center *= 1.0/molecules[i].size();
for (int j : mol)
center += refPos[j];
center *= 1.0/mol.size();
// Find the displacement to move it into the first periodic box.
Vec3 diff;
......@@ -134,8 +134,8 @@ State RPMDIntegrator::getState(int copy, int types, bool enforcePeriodicBox, int
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]];
for (int j : mol) {
Vec3& pos = positions[j];
pos -= diff;
}
}
......@@ -188,9 +188,8 @@ void RPMDIntegrator::step(int steps) {
context->getOwner().setPositions(p);
isFirstStep = false;
}
vector<ForceImpl*>& forceImpls = context->getForceImpls();
for (int i = 0; i < (int) forceImpls.size(); i++) {
RPMDUpdater* updater = dynamic_cast<RPMDUpdater*>(forceImpls[i]);
for (auto impl : context->getForceImpls()) {
RPMDUpdater* updater = dynamic_cast<RPMDUpdater*>(impl);
if (updater != NULL)
updater->updateRPMDState(*context);
}
......
......@@ -116,9 +116,9 @@ void CudaIntegrateRPMDStepKernel::initialize(const System& system, const RPMDInt
groupsNotContracted = -1;
const map<int, int>& contractions = integrator.getContractions();
int maxContractedCopies = 0;
for (map<int, int>::const_iterator iter = contractions.begin(); iter != contractions.end(); ++iter) {
int group = iter->first;
int copies = iter->second;
for (auto& c : contractions) {
int group = c.first;
int copies = c.second;
if (group < 0 || group > 31)
throw OpenMMException("RPMDIntegrator: Force group must be between 0 and 31");
if (copies < 0 || copies > numCopies)
......@@ -166,8 +166,8 @@ void CudaIntegrateRPMDStepKernel::initialize(const System& system, const RPMDInt
// Create kernels for doing contractions.
for (map<int, int>::const_iterator iter = groupsByCopies.begin(); iter != groupsByCopies.end(); ++iter) {
int copies = iter->first;
for (auto& g : groupsByCopies) {
int copies = g.first;
replacements.clear();
replacements["NUM_CONTRACTED_COPIES"] = cu.intToString(copies);
replacements["POS_SCALE"] = cu.doubleToString(1.0/numCopies);
......@@ -267,9 +267,9 @@ void CudaIntegrateRPMDStepKernel::computeForces(ContextImpl& context) {
// Now loop over contractions and compute forces from them.
for (map<int, int>::const_iterator iter = groupsByCopies.begin(); iter != groupsByCopies.end(); ++iter) {
int copies = iter->first;
int groupFlags = iter->second;
for (auto& g : groupsByCopies) {
int copies = g.first;
int groupFlags = g.second;
// Find the contracted positions.
......
......@@ -96,9 +96,9 @@ void OpenCLIntegrateRPMDStepKernel::initialize(const System& system, const RPMDI
groupsNotContracted = -1;
const map<int, int>& contractions = integrator.getContractions();
int maxContractedCopies = 0;
for (map<int, int>::const_iterator iter = contractions.begin(); iter != contractions.end(); ++iter) {
int group = iter->first;
int copies = iter->second;
for (auto& c : contractions) {
int group = c.first;
int copies = c.second;
if (group < 0 || group > 31)
throw OpenMMException("RPMDIntegrator: Force group must be between 0 and 31");
if (copies < 0 || copies > numCopies)
......@@ -146,8 +146,8 @@ void OpenCLIntegrateRPMDStepKernel::initialize(const System& system, const RPMDI
// Create kernels for doing contractions.
for (map<int, int>::const_iterator iter = groupsByCopies.begin(); iter != groupsByCopies.end(); ++iter) {
int copies = iter->first;
for (auto& g : groupsByCopies) {
int copies = g.first;
replacements.clear();
replacements["NUM_CONTRACTED_COPIES"] = cl.intToString(copies);
replacements["POS_SCALE"] = cl.doubleToString(1.0/numCopies);
......@@ -182,8 +182,8 @@ void OpenCLIntegrateRPMDStepKernel::initializeKernels(ContextImpl& context) {
copyFromContextKernel.setArg<cl::Buffer>(3, velocities->getDeviceBuffer());
copyFromContextKernel.setArg<cl::Buffer>(4, cl.getPosq().getDeviceBuffer());
copyFromContextKernel.setArg<cl::Buffer>(6, cl.getAtomIndexArray().getDeviceBuffer());
for (map<int, int>::const_iterator iter = groupsByCopies.begin(); iter != groupsByCopies.end(); ++iter) {
int copies = iter->first;
for (auto& g : groupsByCopies) {
int copies = g.first;
positionContractionKernels[copies].setArg<cl::Buffer>(0, positions->getDeviceBuffer());
positionContractionKernels[copies].setArg<cl::Buffer>(1, contractedPositions->getDeviceBuffer());
forceContractionKernels[copies].setArg<cl::Buffer>(0, forces->getDeviceBuffer());
......@@ -286,9 +286,9 @@ void OpenCLIntegrateRPMDStepKernel::computeForces(ContextImpl& context) {
copyToContextKernel.setArg<cl::Buffer>(2, contractedPositions->getDeviceBuffer());
copyFromContextKernel.setArg<cl::Buffer>(1, contractedForces->getDeviceBuffer());
copyFromContextKernel.setArg<cl::Buffer>(5, contractedPositions->getDeviceBuffer());
for (map<int, int>::const_iterator iter = groupsByCopies.begin(); iter != groupsByCopies.end(); ++iter) {
int copies = iter->first;
int groupFlags = iter->second;
for (auto& g : groupsByCopies) {
int copies = g.first;
int groupFlags = g.second;
// Find the contracted positions.
......
......@@ -55,9 +55,9 @@ static vector<Vec3>& extractForces(ContextImpl& context) {
ReferenceIntegrateRPMDStepKernel::~ReferenceIntegrateRPMDStepKernel() {
if (fft != NULL)
fftpack_destroy(fft);
for (map<int, fftpack*>::const_iterator iter = contractionFFT.begin(); iter != contractionFFT.end(); ++iter)
if (iter->second != NULL)
fftpack_destroy(iter->second);
for (auto& c : contractionFFT)
if (c.second != NULL)
fftpack_destroy(c.second);
}
void ReferenceIntegrateRPMDStepKernel::initialize(const System& system, const RPMDIntegrator& integrator) {
......@@ -79,9 +79,9 @@ void ReferenceIntegrateRPMDStepKernel::initialize(const System& system, const RP
groupsNotContracted = -1;
const map<int, int>& contractions = integrator.getContractions();
int maxContractedCopies = 0;
for (map<int, int>::const_iterator iter = contractions.begin(); iter != contractions.end(); ++iter) {
int group = iter->first;
int copies = iter->second;
for (auto& c : contractions) {
int group = c.first;
int copies = c.second;
if (group < 0 || group > 31)
throw OpenMMException("RPMDIntegrator: Force group must be between 0 and 31");
if (copies < 0 || copies > numCopies)
......@@ -290,9 +290,9 @@ void ReferenceIntegrateRPMDStepKernel::computeForces(ContextImpl& context, const
// Now loop over contractions and compute forces from them.
for (map<int, int>::const_iterator iter = groupsByCopies.begin(); iter != groupsByCopies.end(); ++iter) {
int copies = iter->first;
int groupFlags = iter->second;
for (auto& g : groupsByCopies) {
int copies = g.first;
int groupFlags = g.second;
fftpack* shortFFT = contractionFFT[copies];
// Find the contracted positions.
......
......@@ -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,11 +83,9 @@ 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;
......
......@@ -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")));
}
}
......
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