Unverified Commit c24c619e authored by Peter Eastman's avatar Peter Eastman Committed by GitHub
Browse files

Code cleanup (#5127)

parent b1a5324c
......@@ -58,9 +58,7 @@ public:
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters() {
std::map<std::string, double> parameters;
parameters[AmoebaVdwForce::Lambda()] = 1.0;
return parameters;
return {{AmoebaVdwForce::Lambda(), 1.0}};
}
std::vector<std::string> getKernelNames();
/**
......
......@@ -56,7 +56,7 @@ public:
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
return {}; // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
......
......@@ -55,7 +55,7 @@ public:
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force doesn't define any parameters.
return {}; // This force doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
void getLabFramePermanentDipoles(ContextImpl& context, std::vector<Vec3>& dipoles);
......
......@@ -60,9 +60,7 @@ double AmoebaGeneralizedKirkwoodForceImpl::calcForcesAndEnergy(ContextImpl& cont
}
std::vector<std::string> AmoebaGeneralizedKirkwoodForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcAmoebaGeneralizedKirkwoodForceKernel::Name());
return names;
return {CalcAmoebaGeneralizedKirkwoodForceKernel::Name()};
}
void AmoebaGeneralizedKirkwoodForceImpl::updateParametersInContext(ContextImpl& context) {
......
......@@ -150,9 +150,7 @@ double AmoebaMultipoleForceImpl::calcForcesAndEnergy(ContextImpl& context, bool
}
std::vector<std::string> AmoebaMultipoleForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcAmoebaMultipoleForceKernel::Name());
return names;
return {CalcAmoebaMultipoleForceKernel::Name()};
}
const int* AmoebaMultipoleForceImpl::getCovalentDegrees() {
......
......@@ -152,8 +152,6 @@ void AmoebaTorsionTorsionForceImpl::reorderGrid(const TorsionTorsionGrid& grid,
}
std::vector<std::string> AmoebaTorsionTorsionForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcAmoebaTorsionTorsionForceKernel::Name());
return names;
return {CalcAmoebaTorsionTorsionForceKernel::Name()};
}
......@@ -245,12 +245,6 @@ double AmoebaVdwForceImpl::calcDispersionCorrection(const System& system, const
// Compute the VdW tapering coefficients. Mostly copied from amoebaCudaGpu.cpp.
double cutoff = force.getCutoffDistance();
double vdwTaper = 0.90; // vdwTaper is a scaling factor, it is not a distance.
double c0 = 0.0;
double c1 = 0.0;
double c2 = 0.0;
double c3 = 0.0;
double c4 = 0.0;
double c5 = 0.0;
double vdwCut = cutoff;
double vdwTaperCut = vdwTaper*cutoff;
......@@ -275,12 +269,12 @@ double AmoebaVdwForceImpl::calcDispersionCorrection(const System& system, const
double denom2 = denom*denom;
denom = denom * denom2*denom2;
c0 = vdwCut * vdwCut2 * (vdwCut2 - 5.0 * vdwCut * vdwTaperCut + 10.0 * vdwTaperCut2) * denom;
c1 = -30.0 * vdwCut2 * vdwTaperCut2*denom;
c2 = 30.0 * (vdwCut2 * vdwTaperCut + vdwCut * vdwTaperCut2) * denom;
c3 = -10.0 * (vdwCut2 + 4.0 * vdwCut * vdwTaperCut + vdwTaperCut2) * denom;
c4 = 15.0 * (vdwCut + vdwTaperCut) * denom;
c5 = -6.0 * denom;
double c0 = vdwCut * vdwCut2 * (vdwCut2 - 5.0 * vdwCut * vdwTaperCut + 10.0 * vdwTaperCut2) * denom;
double c1 = -30.0 * vdwCut2 * vdwTaperCut2*denom;
double c2 = 30.0 * (vdwCut2 * vdwTaperCut + vdwCut * vdwTaperCut2) * denom;
double c3 = -10.0 * (vdwCut2 + 4.0 * vdwCut * vdwTaperCut + vdwTaperCut2) * denom;
double c4 = 15.0 * (vdwCut + vdwTaperCut) * denom;
double c5 = -6.0 * denom;
// Loop over all pairs of types to compute the coefficient.
// Copied over from TINKER - numerical integration.
......@@ -347,9 +341,7 @@ double AmoebaVdwForceImpl::calcDispersionCorrection(const System& system, const
}
std::vector<std::string> AmoebaVdwForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcAmoebaVdwForceKernel::Name());
return names;
return {CalcAmoebaVdwForceKernel::Name()};
}
void AmoebaVdwForceImpl::updateParametersInContext(ContextImpl& context) {
......
......@@ -133,9 +133,7 @@ double AmoebaWcaDispersionForceImpl::getTotalMaximumDispersionEnergy(const Amoeb
}
std::vector<std::string> AmoebaWcaDispersionForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcAmoebaWcaDispersionForceKernel::Name());
return names;
return {CalcAmoebaWcaDispersionForceKernel::Name()};
}
void AmoebaWcaDispersionForceImpl::updateParametersInContext(ContextImpl& context) {
......
......@@ -140,9 +140,7 @@ double HippoNonbondedForceImpl::calcForcesAndEnergy(ContextImpl& context, bool i
}
std::vector<std::string> HippoNonbondedForceImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(CalcHippoNonbondedForceKernel::Name());
return names;
return {CalcHippoNonbondedForceKernel::Name()};
}
void HippoNonbondedForceImpl::getLabFramePermanentDipoles(ContextImpl& context, vector<Vec3>& dipoles) {
......
......@@ -58,7 +58,7 @@ public:
}
double calcForcesAndEnergy(ContextImpl& context, bool includeForces, bool includeEnergy, int groups);
std::map<std::string, double> getDefaultParameters() {
return std::map<std::string, double>(); // This force field doesn't define any parameters.
return {}; // This force field doesn't define any parameters.
}
std::vector<std::string> getKernelNames();
void updateParametersInContext(ContextImpl& context);
......
......@@ -120,9 +120,7 @@ double DrudeForceImpl::calcForcesAndEnergy(ContextImpl& context, bool includeFor
}
vector<string> DrudeForceImpl::getKernelNames() {
vector<string> names;
names.push_back(CalcDrudeForceKernel::Name());
return names;
return {CalcDrudeForceKernel::Name()};
}
void DrudeForceImpl::updateParametersInContext(ContextImpl& context) {
......
......@@ -87,9 +87,7 @@ void DrudeLangevinIntegrator::cleanup() {
}
vector<string> DrudeLangevinIntegrator::getKernelNames() {
std::vector<std::string> names;
names.push_back(IntegrateDrudeLangevinStepKernel::Name());
return names;
return {IntegrateDrudeLangevinStepKernel::Name()};
}
double DrudeLangevinIntegrator::computeKineticEnergy() {
......
......@@ -73,9 +73,7 @@ void DrudeSCFIntegrator::cleanup() {
}
vector<string> DrudeSCFIntegrator::getKernelNames() {
std::vector<std::string> names;
names.push_back(IntegrateDrudeSCFStepKernel::Name());
return names;
return {IntegrateDrudeSCFStepKernel::Name()};
}
double DrudeSCFIntegrator::computeKineticEnergy() {
......
......@@ -78,9 +78,7 @@ void RPMDIntegrator::stateChanged(State::DataType changed) {
}
vector<string> RPMDIntegrator::getKernelNames() {
std::vector<std::string> names;
names.push_back(IntegrateRPMDStepKernel::Name());
return names;
return {IntegrateRPMDStepKernel::Name()};
}
void RPMDIntegrator::setPositions(int copy, const vector<Vec3>& positions) {
......
......@@ -155,13 +155,9 @@ void RPMDMonteCarloBarostatImpl::updateRPMDState(ContextImpl& context) {
}
std::map<std::string, double> RPMDMonteCarloBarostatImpl::getDefaultParameters() {
std::map<std::string, double> parameters;
parameters[RPMDMonteCarloBarostat::Pressure()] = getOwner().getDefaultPressure();
return parameters;
return {{RPMDMonteCarloBarostat::Pressure(), getOwner().getDefaultPressure()}};
}
std::vector<std::string> RPMDMonteCarloBarostatImpl::getKernelNames() {
std::vector<std::string> names;
names.push_back(ApplyMonteCarloBarostatKernel::Name());
return names;
return {ApplyMonteCarloBarostatKernel::Name()};
}
......@@ -52,21 +52,9 @@ void testHarmonicBond() {
system.addParticle(5.0);
CustomCentroidBondForce* force = new CustomCentroidBondForce(2, "k*distance(g1,g2)^2");
force->addPerBondParameter("k");
vector<int> particles1;
particles1.push_back(0);
particles1.push_back(1);
vector<int> particles2;
particles2.push_back(2);
particles2.push_back(3);
particles2.push_back(4);
force->addGroup(particles1);
force->addGroup(particles2);
vector<int> groups;
groups.push_back(0);
groups.push_back(1);
vector<double> parameters;
parameters.push_back(1.0);
force->addBond(groups, parameters);
force->addGroup({0, 1});
force->addGroup({2, 3, 4});
force->addBond({0, 1}, {1.0});
system.addForce(force);
ASSERT(!system.usesPeriodicBoundaryConditions());
......@@ -97,8 +85,7 @@ void testHarmonicBond() {
// Update the per-bond parameter and see if the results change.
parameters[0] = 2.0;
force->setBondParameters(0, groups, parameters);
force->setBondParameters(0, {0, 1}, {2.0});
force->updateParametersInContext(context);
state = context.getState(State::Forces | State::Energy);
ASSERT_EQUAL_TOL(2*2.5*2.5, state.getPotentialEnergy(), TOL);
......@@ -236,11 +223,7 @@ void testCustomWeights() {
weights[0] = 2.0;
weights[1] = 1.0;
force->addGroup(particles, weights);
vector<int> groups;
groups.push_back(0);
groups.push_back(1);
vector<double> parameters;
force->addBond(groups, parameters);
force->addBond({0, 1});
system.addForce(force);
// The center of mass of group 0 is (0, 1, 0).
......@@ -272,14 +255,9 @@ void testIllegalVariable() {
system.addParticle(1.0);
system.addParticle(1.0);
CustomCentroidBondForce* force = new CustomCentroidBondForce(2, "1+none");
vector<int> particles;
particles.push_back(0);
force->addGroup(particles);
force->addGroup(particles);
vector<int> groups;
groups.push_back(0);
groups.push_back(1);
force->addBond(groups);
force->addGroup({0});
force->addGroup({0});
force->addBond({0, 1});
system.addForce(force);
VerletIntegrator integrator(0.001);
bool threwException = false;
......@@ -309,21 +287,9 @@ void testPeriodic(bool byGroups) {
expression = "k*pointdistance(x1,y1,z1,x2,y2,z2)^2";
CustomCentroidBondForce* force = new CustomCentroidBondForce(2, expression);
force->addPerBondParameter("k");
vector<int> particles1;
particles1.push_back(0);
particles1.push_back(1);
vector<int> particles2;
particles2.push_back(2);
particles2.push_back(3);
particles2.push_back(4);
force->addGroup(particles1);
force->addGroup(particles2);
vector<int> groups;
groups.push_back(0);
groups.push_back(1);
vector<double> parameters;
parameters.push_back(1.0);
force->addBond(groups, parameters);
force->addGroup({0, 1});
force->addGroup({2, 3, 4});
force->addBond({0, 1}, {1.0});
force->setUsesPeriodicBoundaryConditions(true);
system.addForce(force);
......@@ -365,20 +331,9 @@ void testEnergyParameterDerivatives() {
force->addGlobalParameter("k", 0.0);
force->addEnergyParameterDerivative("r0");
force->addEnergyParameterDerivative("k");
vector<int> particles1;
particles1.push_back(0);
particles1.push_back(1);
vector<int> particles2;
particles2.push_back(2);
particles2.push_back(3);
particles2.push_back(4);
force->addGroup(particles1);
force->addGroup(particles2);
vector<int> groups;
groups.push_back(0);
groups.push_back(1);
vector<double> parameters;
force->addBond(groups, parameters);
force->addGroup({0, 1});
force->addGroup({2, 3, 4});
force->addBond({0, 1});
system.addForce(force);
// The center of mass of group 0 is (1.5, 0, 0).
......
......@@ -342,10 +342,7 @@ void testIllegalVariable() {
system.addParticle(1.0);
system.addParticle(1.0);
CustomCompoundBondForce* force = new CustomCompoundBondForce(2, "1+none");
vector<int> particles;
particles.push_back(0);
particles.push_back(1);
force->addBond(particles);
force->addBond({0, 1});
system.addForce(force);
VerletIntegrator integrator(0.001);
bool threwException = false;
......
......@@ -930,9 +930,7 @@ void testTabulatedFunction() {
integrator.addPerDofVariable("dof", 0.0);
integrator.addComputeGlobal("global", "fn(global)");
integrator.addComputePerDof("dof", "fn(x)");
vector<double> table;
table.push_back(10.0);
table.push_back(20.0);
vector<double> table = {10.0, 20.0};
integrator.addTabulatedFunction("fn", new Continuous1DFunction(table, 1.0, 2.0));
Context context(system, integrator, platform);
vector<Vec3> positions(1);
......
......@@ -358,12 +358,7 @@ void testAllTerms() {
CustomCompoundBondForce* force2 = new CustomCompoundBondForce(4,
"distance(p1,p2)+angle(p1,p3,p4)+dihedral(p1,p4,p2,p3)+x1+y3+z4");
system2.addForce(force2);
vector<int> particles;
particles.push_back(0);
particles.push_back(1);
particles.push_back(2);
particles.push_back(3);
force2->addBond(particles, params);
force2->addBond({0, 1, 2, 3}, params);
for (int i = 0; i < numParticles; i++)
system2.addParticle(1.0);
......@@ -462,9 +457,7 @@ void testTabulatedFunctions() {
// Create two tabulated functions.
vector<double> values;
values.push_back(0.0);
values.push_back(50.0);
vector<double> values = {0.0, 50.0};
Continuous1DFunction* f1 = new Continuous1DFunction(values, 0, 100);
OpenMM_SFMT::SFMT sfmt;
init_gen_rand(0, sfmt);
......
......@@ -102,11 +102,7 @@ void testExclusionsAnd14() {
system.addParticle(1.0);
nonbonded->addParticle(0, 1.5, 0);
}
vector<pair<int, int> > bonds;
bonds.push_back(pair<int, int>(0, 1));
bonds.push_back(pair<int, int>(1, 2));
bonds.push_back(pair<int, int>(2, 3));
bonds.push_back(pair<int, int>(3, 4));
vector<pair<int, int> > bonds = {{0, 1}, {1, 2}, {2, 3}, {3, 4}};
nonbonded->createExceptionsFromBonds(bonds, 0.0, 0.0);
int first14, second14;
for (int i = 0; i < nonbonded->getNumExceptions(); i++) {
......@@ -233,11 +229,7 @@ void testCutoff14() {
nonbonded->setCutoffDistance(cutoff);
const double eps = 30.0;
nonbonded->setReactionFieldDielectric(eps);
vector<pair<int, int> > bonds;
bonds.push_back(pair<int, int>(0, 1));
bonds.push_back(pair<int, int>(1, 2));
bonds.push_back(pair<int, int>(2, 3));
bonds.push_back(pair<int, int>(3, 4));
vector<pair<int, int> > bonds = {{0, 1}, {1, 2}, {2, 3}, {3, 4}};
nonbonded->createExceptionsFromBonds(bonds, 0.0, 0.0);
int first14, second14;
for (int i = 0; i < nonbonded->getNumExceptions(); i++) {
......
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