Commit b4548b77 authored by Jens Wehner's avatar Jens Wehner

replaced old for loops with c++11

parent 3f44c038
Pipeline #89562744 passed with stages
in 464 minutes and 55 seconds
......@@ -100,9 +100,8 @@ inline CGMoleculeDef *CGEngine::getMoleculeDef(std::string name) {
}
inline bool CGEngine::IsIgnored(std::string ident) {
for (std::list<std::string>::iterator iter = _ignores.begin();
iter != _ignores.end(); ++iter) {
if (tools::wildcmp(iter->c_str(), ident.c_str())) {
for (auto &_ignore : _ignores) {
if (tools::wildcmp(_ignore.c_str(), ident.c_str())) {
return true;
}
}
......
......@@ -348,21 +348,20 @@ void TabulatedPotential::BoltzmannInvert_(vector<double> &data) {
_min = numeric_limits<double>::max();
_max = numeric_limits<double>::min();
for (size_t i = 0; i < data.size(); i++) {
_max = max(data[i], _max);
if (data[i] > 0) {
_min = min(data[i], _min);
for (double i : data) {
_max = max(i, _max);
if (i > 0) {
_min = min(i, _min);
}
}
_max = -conv::kB * conv::ev2kj_per_mol * _Temperature * log(_max);
_min = -conv::kB * conv::ev2kj_per_mol * _Temperature * log(_min) - _max;
for (size_t i = 0; i < data.size(); i++) {
if (data[i] == 0) {
data[i] = _min;
for (double &i : data) {
if (i == 0) {
i = _min;
} else {
data[i] =
-conv::kB * conv::ev2kj_per_mol * _Temperature * log(data[i]) - _max;
i = -conv::kB * conv::ev2kj_per_mol * _Temperature * log(i) - _max;
}
}
}
......
......@@ -194,23 +194,22 @@ Map *CGMoleculeDef::CreateMap(Molecule &in, Molecule &out) {
}
Map *map = new Map(in, out);
for (vector<beaddef_t *>::iterator def = _beads.begin(); def != _beads.end();
++def) {
for (auto &_bead : _beads) {
int iout = out.getBeadByName((*def)->_name);
int iout = out.getBeadByName(_bead->_name);
if (iout < 0) {
throw runtime_error(string("mapping error: reference molecule " +
(*def)->_name + " does not exist"));
_bead->_name + " does not exist"));
}
tools::Property *mdef = getMapByName((*def)->_mapping);
tools::Property *mdef = getMapByName(_bead->_mapping);
if (!mdef) {
throw runtime_error(string("mapping " + (*def)->_mapping + " not found"));
throw runtime_error(string("mapping " + _bead->_mapping + " not found"));
}
/// TODO: change this to factory, do not hardcode!!
BeadMap *bmap;
switch ((*def)->_symmetry) {
switch (_bead->_symmetry) {
case 1:
bmap = new Map_Sphere();
break;
......@@ -222,7 +221,7 @@ Map *CGMoleculeDef::CreateMap(Molecule &in, Molecule &out) {
}
////////////////////////////////////////////////////
bmap->Initialize(&in, out.getBead(iout), ((*def)->_options), mdef);
bmap->Initialize(&in, out.getBead(iout), (_bead->_options), mdef);
map->AddBeadMap(bmap);
}
return map;
......
......@@ -362,8 +362,8 @@ void CsgApplication::Run(void) {
myMutexOut->Lock();
}
}
for (size_t thread = 0; thread < _myWorkers.size(); thread++) {
_myWorkers[thread]->Start();
for (auto &_myWorker : _myWorkers) {
_myWorker->Start();
}
if (SynchronizeThreads()) {
......@@ -373,14 +373,14 @@ void CsgApplication::Run(void) {
}
// mutex needed for merging if SynchronizeThreads()==False
tools::Mutex mergeMutex;
for (size_t thread = 0; thread < _myWorkers.size(); thread++) {
_myWorkers[thread]->WaitDone();
for (auto &_myWorker : _myWorkers) {
_myWorker->WaitDone();
if (!SynchronizeThreads()) {
mergeMutex.Lock();
MergeWorker(_myWorkers[thread]);
MergeWorker(_myWorker);
mergeMutex.Unlock();
}
delete _myWorkers[thread];
delete _myWorker;
}
for (size_t thread = 0; thread < _threadsMutexesIn.size(); ++thread) {
delete _threadsMutexesIn[thread];
......
......@@ -351,27 +351,26 @@ bool DLPOLYTopologyReader::ReadTopology(string file, Topology &top) {
}
matoms += mi->BeadCount();
InteractionContainer ics = mi->Interactions();
for (vector<Interaction *>::iterator ic = ics.begin(); ic != ics.end();
++ic) {
for (auto &ic : ics) {
Interaction *ic_replica = nullptr;
int offset =
mi_replica->getBead(0)->getId() - mi->getBead(0)->getId();
if ((*ic)->BeadCount() == 2) {
ic_replica = new IBond((*ic)->getBeadId(0) + offset,
(*ic)->getBeadId(1) + offset);
} else if ((*ic)->BeadCount() == 3) {
ic_replica = new IAngle((*ic)->getBeadId(0) + offset,
(*ic)->getBeadId(1) + offset,
(*ic)->getBeadId(2) + offset);
} else if ((*ic)->BeadCount() == 4) {
if (ic->BeadCount() == 2) {
ic_replica =
new IBond(ic->getBeadId(0) + offset, ic->getBeadId(1) + offset);
} else if (ic->BeadCount() == 3) {
ic_replica =
new IAngle(ic->getBeadId(0) + offset, ic->getBeadId(1) + offset,
ic->getBeadId(2) + offset);
} else if (ic->BeadCount() == 4) {
ic_replica = new IDihedral(
(*ic)->getBeadId(0) + offset, (*ic)->getBeadId(1) + offset,
(*ic)->getBeadId(2) + offset, (*ic)->getBeadId(3) + offset);
ic->getBeadId(0) + offset, ic->getBeadId(1) + offset,
ic->getBeadId(2) + offset, ic->getBeadId(3) + offset);
} else {
throw std::runtime_error("Error: BeadCount not equal 2, 3 or 4");
}
ic_replica->setGroup((*ic)->getGroup());
ic_replica->setIndex((*ic)->getIndex());
ic_replica->setGroup(ic->getGroup());
ic_replica->setIndex(ic->getIndex());
ic_replica->setMolecule(mi_replica->getId());
top.AddBondedInteraction(ic_replica);
mi_replica->AddInteraction(ic_replica);
......
......@@ -175,9 +175,8 @@ bool PDBReader::NextFrame(Topology &top) {
int at1 = boost::lexical_cast<int>(atm1);
row.at(0) = at1;
for (auto bonded_atm = bonded_atms.begin();
bonded_atm != bonded_atms.end(); bonded_atm++) {
int at2 = boost::lexical_cast<int>(*bonded_atm);
for (auto &bonded_atm : bonded_atms) {
int at2 = boost::lexical_cast<int>(bonded_atm);
row.at(1) = at2;
// Because every bond will be counted twice in a .pdb file
// we will only add bonds where the id (atm1) is less than the
......@@ -375,10 +374,10 @@ bool PDBReader::NextFrame(Topology &top) {
int mol_index = 0;
// Cycle through all bonds
for (auto row = bond_pairs.begin(); row != bond_pairs.end(); row++) {
for (auto &bond_pair : bond_pairs) {
int atm_id1 = row->at(0);
int atm_id2 = row->at(1);
int atm_id1 = bond_pair.at(0);
int atm_id2 = bond_pair.at(1);
// Check to see if either atm referred to in the bond is already
// attached to a molecule
auto mol_iter1 = atm_molecule.find(atm_id1);
......@@ -428,10 +427,9 @@ bool PDBReader::NextFrame(Topology &top) {
// Now we will proceed to cycle through the atms that were in the now
// obsolete molecule and make sure they are pointing to the new molecule
for (auto atm_temp = molecule_atms[obsolete_mol].begin();
atm_temp != molecule_atms[obsolete_mol].end(); atm_temp++) {
for (int &atm_temp : molecule_atms[obsolete_mol]) {
atm_molecule[*atm_temp] = chosen_mol;
atm_molecule[atm_temp] = chosen_mol;
}
// Splicing will remove atoms from the now obsolete molecule and place
......@@ -484,22 +482,20 @@ bool PDBReader::NextFrame(Topology &top) {
// Add all the atoms to the appropriate molecule object
list<int> atm_list = molecule_atms[mol->first];
for (auto atm_temp = atm_list.begin(); atm_temp != atm_list.end();
atm_temp++) {
for (int &atm_temp : atm_list) {
string residuename = "DUM";
mi->AddBead(bead_vec.at(*atm_temp - 1), residuename);
mi->AddBead(bead_vec.at(atm_temp - 1), residuename);
}
ind++;
}
int bond_indx = 0;
// Cyle through the bonds and add them to the appropriate molecule
for (auto bond_pair = bond_pairs.begin(); bond_pair != bond_pairs.end();
bond_pair++) {
for (auto &bond_pair : bond_pairs) {
int atm_id1 = bond_pair->at(0);
int atm_id2 = bond_pair->at(1);
int atm_id1 = bond_pair.at(0);
int atm_id2 = bond_pair.at(1);
// Should be able to just look at one of the atoms the bond is attached
// too because the other will also be attached to the same molecule.
int mol_ind = atm_molecule[atm_id1];
......
......@@ -59,22 +59,21 @@ void XMLTopologyReader::ParseRoot(tools::Property &property) {
}
// Iterate over keys at first level.
for (tools::Property::iterator it = property.begin(); it != property.end();
++it) {
if (it->name() == "h5md_particle_group") {
_top->setParticleGroup(it->getAttribute<string>("name"));
} else if (it->name() == "molecules") {
for (auto &it : property) {
if (it.name() == "h5md_particle_group") {
_top->setParticleGroup(it.getAttribute<string>("name"));
} else if (it.name() == "molecules") {
_mol_index = 1;
_bead_index = 0;
ParseMolecules(*it);
} else if (it->name() == "bonded") {
ParseBonded(*it);
} else if (it->name() == "box") {
ParseBox(*it);
} else if (it->name() == "beadtypes") {
ParseBeadTypes(*it);
ParseMolecules(it);
} else if (it.name() == "bonded") {
ParseBonded(it);
} else if (it.name() == "box") {
ParseBox(it);
} else if (it.name() == "beadtypes") {
ParseBeadTypes(it);
} else {
throw runtime_error("unknown tag: topology." + it->name());
throw runtime_error("unknown tag: topology." + it.name());
}
}
}
......@@ -88,37 +87,37 @@ void XMLTopologyReader::ParseBox(tools::Property &p) {
}
void XMLTopologyReader::ParseMolecules(tools::Property &p) {
for (tools::Property::iterator it = p.begin(); it != p.end(); ++it) {
if (it->name() == "clear") {
for (auto &it : p) {
if (it.name() == "clear") {
_top->ClearMoleculeList();
} else if (it->name() == "rename") {
string molname = it->getAttribute<string>("name");
string range = it->getAttribute<string>("range");
} else if (it.name() == "rename") {
string molname = it.getAttribute<string>("name");
string range = it.getAttribute<string>("range");
_top->RenameMolecules(range, molname);
} else if (it->name() == "define" || it->name() == "molecule") {
string molname = it->getAttribute<string>("name");
} else if (it.name() == "define" || it.name() == "molecule") {
string molname = it.getAttribute<string>("name");
int first = 0;
if (it->name() == "define") {
first = it->getAttribute<int>("first");
if (it.name() == "define") {
first = it.getAttribute<int>("first");
}
int nbeads = it->getAttribute<int>("nbeads");
int nmols = it->getAttribute<int>("nmols");
if (it->name() == "define" && first < 1) {
int nbeads = it.getAttribute<int>("nbeads");
int nmols = it.getAttribute<int>("nmols");
if (it.name() == "define" && first < 1) {
throw std::runtime_error(
"Attribute first is suppose to be > 0, but found " +
boost::lexical_cast<string>(it->getAttribute<string>("first")));
boost::lexical_cast<string>(it.getAttribute<string>("first")));
}
if (nbeads < 1) {
throw std::runtime_error(
"Attribute nbeads is suppose to be > 0, but found " +
boost::lexical_cast<string>(it->getAttribute<string>("nbeads")));
boost::lexical_cast<string>(it.getAttribute<string>("nbeads")));
}
if (nmols < 1) {
throw std::runtime_error(
"Attribute nmols is suppose to be > 0, but found " +
boost::lexical_cast<string>(it->getAttribute<string>("nmols")));
boost::lexical_cast<string>(it.getAttribute<string>("nmols")));
}
if (it->name() == "define") {
if (it.name() == "define") {
_top->CreateMoleculesByRange(molname, first, nbeads, nmols);
} else {
if (_has_base_topology) {
......@@ -126,7 +125,7 @@ void XMLTopologyReader::ParseMolecules(tools::Property &p) {
"The defined list of beads only works for pure xml topology, "
"without 'base' attribute.");
}
ParseMolecule(*it, molname, nbeads, nmols);
ParseMolecule(it, molname, nbeads, nmols);
}
}
}
......@@ -136,24 +135,24 @@ void XMLTopologyReader::ParseMolecule(tools::Property &p, string molname,
int nbeads, int nmols) {
vector<XMLBead *> xmlBeads;
vector<int> xmlResidues;
for (tools::Property::iterator it = p.begin(); it != p.end(); ++it) {
if (it->name() == "bead") {
string atname = it->getAttribute<string>("name");
string attype = it->getAttribute<string>("type");
for (auto &it : p) {
if (it.name() == "bead") {
string atname = it.getAttribute<string>("name");
string attype = it.getAttribute<string>("type");
double atmass, atq;
int resid;
try {
atmass = it->getAttribute<double>("mass");
atmass = it.getAttribute<double>("mass");
} catch (runtime_error &) {
atmass = 1.0;
}
try {
atq = it->getAttribute<double>("q");
atq = it.getAttribute<double>("q");
} catch (runtime_error &) {
atq = 0.0;
}
try {
resid = it->getAttribute<int>("resid");
resid = it.getAttribute<int>("resid");
if (resid <= 0) {
throw std::invalid_argument(
"Residue count for beads in topology.molecules.molecule has to "
......@@ -179,7 +178,7 @@ void XMLTopologyReader::ParseMolecule(tools::Property &p, string molname,
xmlBeads.push_back(xmlBead);
} else {
throw std::runtime_error(
"Wrong element under topology.molecules.molecule: " + it->name());
"Wrong element under topology.molecules.molecule: " + it.name());
}
}
if (xmlResidues.size() != xmlBeads.size()) {
......@@ -237,41 +236,40 @@ void XMLTopologyReader::ParseMolecule(tools::Property &p, string molname,
}
// clean up
for (std::vector<XMLBead *>::iterator itb = xmlBeads.begin();
itb != xmlBeads.end(); ++itb) {
delete (*itb);
for (auto &xmlBead : xmlBeads) {
delete xmlBead;
}
}
void XMLTopologyReader::ParseBeadTypes(tools::Property &el) {
for (tools::Property::iterator it = el.begin(); it != el.end(); ++it) {
if (it->name() == "rename") {
string name = it->getAttribute<string>("name");
string newname = it->getAttribute<string>("newname");
for (auto &it : el) {
if (it.name() == "rename") {
string name = it.getAttribute<string>("name");
string newname = it.getAttribute<string>("newname");
if (name == "" || newname == "") {
throw runtime_error("invalid rename tag, name or newname are empty.");
}
_top->RenameBeadType(name, newname);
} else if (it->name() == "mass") {
string name = it->getAttribute<string>("name");
double value = it->getAttribute<double>("value");
} else if (it.name() == "mass") {
string name = it.getAttribute<string>("name");
double value = it.getAttribute<double>("value");
_top->SetBeadTypeMass(name, value);
} else {
throw std::runtime_error("Wrong element under beadtypes: " + it->name());
throw std::runtime_error("Wrong element under beadtypes: " + it.name());
}
}
}
void XMLTopologyReader::ParseBonded(tools::Property &el) {
for (tools::Property::iterator it = el.begin(); it != el.end(); ++it) {
if (it->name() == "bond") {
ParseBond(*it);
} else if (it->name() == "angle") {
ParseAngle(*it);
} else if (it->name() == "dihedral") {
ParseDihedral(*it);
for (auto &it : el) {
if (it.name() == "bond") {
ParseBond(it);
} else if (it.name() == "angle") {
ParseAngle(it);
} else if (it.name() == "dihedral") {
ParseDihedral(it);
} else {
throw std::runtime_error("Wrong element under bonded: " + it->name());
throw std::runtime_error("Wrong element under bonded: " + it.name());
}
}
}
......@@ -399,12 +397,10 @@ void XMLTopologyReader::ParseDihedral(tools::Property &p) {
XMLTopologyReader::~XMLTopologyReader() {
// Clean _molecules map
for (MoleculesMap::iterator it = _molecules.begin(); it != _molecules.end();
++it) {
XMLMolecule *xmlMolecule = it->second;
for (vector<XMLBead *>::iterator itb = xmlMolecule->beads.begin();
itb != xmlMolecule->beads.end(); ++itb) {
delete (*itb);
for (auto &_molecule : _molecules) {
XMLMolecule *xmlMolecule = _molecule.second;
for (auto &bead : xmlMolecule->beads) {
delete bead;
}
xmlMolecule->beads.clear();
delete xmlMolecule;
......
......@@ -169,9 +169,8 @@ NBListGrid::cell_t &NBListGrid::getCell(const Eigen::Vector3d &r) {
void NBListGrid::TestBead(NBListGrid::cell_t &cell, Bead *bead) {
TestCell(cell, bead);
for (vector<cell_t *>::iterator iter = cell._neighbours.begin();
iter != cell._neighbours.end(); ++iter) {
TestCell(*(*iter), bead);
for (auto &_neighbour : cell._neighbours) {
TestCell(*_neighbour, bead);
}
}
......
......@@ -95,9 +95,8 @@ void NBListGrid_3Body::Generate(BeadList &list1, BeadList &list2,
}
// In this case type2 and type3 are the same
for (vector<cell_t>::iterator iter = _grid.begin(); iter != _grid.end();
++iter) {
(*iter)._beads3 = (*iter)._beads2;
for (auto &iter : _grid) {
iter._beads3 = iter._beads2;
}
// loop over beads of list 1 again to get the correlations
......@@ -123,10 +122,9 @@ void NBListGrid_3Body::Generate(BeadList &list, bool do_exclusions) {
getCell((*iter)->getPos())._beads1.push_back(*iter);
}
for (vector<cell_t>::iterator iter = _grid.begin(); iter != _grid.end();
++iter) {
(*iter)._beads2 = (*iter)._beads1;
(*iter)._beads3 = (*iter)._beads1;
for (auto &iter : _grid) {
iter._beads2 = iter._beads1;
iter._beads3 = iter._beads1;
}
// loop over beads again to get the correlations (as all of the same type
......@@ -253,10 +251,9 @@ void NBListGrid_3Body::TestBead(NBListGrid_3Body::cell_t &cell, Bead *bead) {
// loop again over all neighbors (this now includes the cell itself!)
// to iterate over all beads of type3 of the cell and its neighbors
for (vector<cell_t *>::iterator iterc3 = cell._neighbours.begin();
iterc3 != cell._neighbours.end(); ++iterc3) {
for (iter3 = (*(*iterc3))._beads3.begin();
iter3 != (*(*iterc3))._beads3.end(); ++iter3) {
for (auto &_neighbour : cell._neighbours) {
for (iter3 = (*_neighbour)._beads3.begin();
iter3 != (*_neighbour)._beads3.end(); ++iter3) {
// do not include the same beads twice in one triple!
if (bead == *iter3) {
......
......@@ -30,10 +30,7 @@ void NematicOrder::Process(Topology &top, const string &filter) {
bool bU, bV, bW;
bU = bV = bW = false;
for (BeadContainer::iterator iter = top.Beads().begin();
iter != top.Beads().end(); ++iter) {
Bead *bead = *iter;
for (auto bead : top.Beads()) {
if (!tools::wildcmp(filter.c_str(), bead->getName().c_str())) {
continue;
......
......@@ -146,11 +146,11 @@ bool DLPTopolApp::EvaluateTopology(Topology *top, Topology *top_ref) {
0,
bead_name1.find_first_of("#")); // skip #index of atom from its name
for (unsigned int imt = 0; imt < MolecularTypes.size(); imt++) {
for (auto &MolecularType : MolecularTypes) {
for (int ib2 = 0; ib2 < MolecularTypes[imt]->BeadCount(); ib2++) {
for (int ib2 = 0; ib2 < MolecularType->BeadCount(); ib2++) {
string bead_name2 = MolecularTypes[imt]->getBead(ib2)->getType();
string bead_name2 = MolecularType->getBead(ib2)->getType();
bead_name2 = bead_name2.substr(
0, bead_name2.find_first_of("#")); // skip #index of atom from
// its name
......@@ -162,9 +162,8 @@ bool DLPTopolApp::EvaluateTopology(Topology *top, Topology *top_ref) {
bool is_new_pair = true;
for (unsigned int ibp = 0; ibp < vdw_pairs.size(); ibp++) {
if (ss_bp1.str() == vdw_pairs[ibp] ||
ss_bp2.str() == vdw_pairs[ibp]) {
for (const auto &vdw_pair : vdw_pairs) {
if (ss_bp1.str() == vdw_pair || ss_bp2.str() == vdw_pair) {
is_new_pair = false;
break;
}
......@@ -204,8 +203,8 @@ bool DLPTopolApp::EvaluateTopology(Topology *top, Topology *top_ref) {
fl << "vdw " << vdw_pairs.size() << endl;
for (unsigned int ibp = 0; ibp < vdw_pairs.size(); ibp++) {
fl << vdw_pairs[ibp] << " tab 1.00000 0.00000\n";
for (const auto &vdw_pair : vdw_pairs) {
fl << vdw_pair << " tab 1.00000 0.00000\n";
}
}
......
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