Skip to content

Commit

Permalink
Use range-based for loops
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Oct 16, 2023
1 parent 0311700 commit fb179b3
Show file tree
Hide file tree
Showing 6 changed files with 31 additions and 31 deletions.
6 changes: 3 additions & 3 deletions modules/algebra/src/Triangle3D.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,11 +56,11 @@ Triangle3D get_largest_triangle(const Vector3Ds &points) {
}
algebra::Segment3D seg(triple[0], triple[1]);
max_dist = 0;
for (unsigned int i = 0; i < points.size(); i++) {
double dist = algebra::get_distance(seg, points[i]);
for (const auto &point : points) {
double dist = algebra::get_distance(seg, point);
if (dist > max_dist) {
max_dist = dist;
triple[2] = points[i];
triple[2] = point;
}
}
return Triangle3D(triple[0], triple[1], triple[2]);
Expand Down
4 changes: 2 additions & 2 deletions modules/atom/src/DopePairScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ void add_dope_score_data(Atom atom) {

void add_dope_score_data(Hierarchy h) {
Hierarchies atoms = get_by_type(h, ATOM_TYPE);
for (unsigned int i = 0; i < atoms.size(); ++i) {
add_dope_score_data(Atom(atoms[i]));
for (const auto &atom : atoms) {
add_dope_score_data(Atom(atom));
}
}

Expand Down
10 changes: 5 additions & 5 deletions modules/core/src/FixedRefiner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,10 @@ FixedRefiner::FixedRefiner(const ParticlesTemp &ps)
IMP_LOG_VERBOSE("Created fixed particle refiner with "
<< ps.size() << " particles" << std::endl);
m_ = ps[0]->get_model();
for(unsigned int i = 0; i < ps.size(); i++){
IMP_USAGE_CHECK(m_ == ps[i]->get_model(),
for (const auto &p : ps) {
IMP_USAGE_CHECK(m_ == p->get_model(),
"refiner assumes all particles are from the same model");
pis_.push_back(ps[i]->get_index());
pis_.push_back(p->get_index());
}
}

Expand All @@ -34,8 +34,8 @@ const ParticlesTemp
FixedRefiner::get_refined(Particle *) const
{
ParticlesTemp ps;
for(unsigned int i=0; i < pis_.size(); i++){
ps.push_back(m_->get_particle(pis_[i]));
for (const auto &pi : pis_) {
ps.push_back(m_->get_particle(pi));
}
return ps;
}
Expand Down
6 changes: 3 additions & 3 deletions modules/misc/src/CommonEndpointPairFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ int CommonEndpointPairFilter::get_value_index(
ModelObjectsTemp CommonEndpointPairFilter::do_get_inputs(
Model *m, const ParticleIndexes &pis) const {
ModelObjectsTemp ret = IMP::get_particles(m, pis);
for (unsigned int i = 0; i < pis.size(); ++i) {
if (IMP::atom::Bond::get_is_setup(m, pis[i])) {
IMP::atom::Bond b(m, pis[i]);
for (auto pi : pis) {
if (IMP::atom::Bond::get_is_setup(m, pi)) {
IMP::atom::Bond b(m, pi);
ret.push_back(b.get_bonded(0));
ret.push_back(b.get_bonded(1));
}
Expand Down
14 changes: 7 additions & 7 deletions modules/saxs/bin/compute_vr.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,22 +60,22 @@ int main(int argc, char **argv) {
if (vm.count("offset")) use_offset = true;

IMP::saxs::Profiles exp_profiles;
for (unsigned int i = 0; i < files.size(); i++) {
for (const auto &file : files) {
// check if file exists
std::ifstream in_file(files[i].c_str());
std::ifstream in_file(file.c_str());
if (!in_file) {
std::cerr << "Can't open file " << files[i] << std::endl;
std::cerr << "Can't open file " << file << std::endl;
exit(1);
}

IMP_NEW(IMP::saxs::Profile, profile, (files[i]));
IMP_NEW(IMP::saxs::Profile, profile, (file));
if (profile->size() == 0) {
std::cerr << "can't parse input file " << files[i] << std::endl;
std::cerr << "can't parse input file " << file << std::endl;
return 1;
} else {
dat_files.push_back(files[i]);
dat_files.push_back(file);
exp_profiles.push_back(profile);
std::cout << "Profile read from file " << files[i]
std::cout << "Profile read from file " << file
<< " size = " << profile->size() << std::endl;
}
}
Expand Down
22 changes: 11 additions & 11 deletions modules/saxs/src/utility.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ Profile* compute_profile(Particles particles, double min_q,
double average_radius = 0.0;
if (hydration_layer) {
// add radius
for (unsigned int i = 0; i < particles.size(); i++) {
double radius = ft->get_radius(particles[i], ff_type);
core::XYZR::setup_particle(particles[i], radius);
for (auto &particle : particles) {
double radius = ft->get_radius(particle, ff_type);
core::XYZR::setup_particle(particle, radius);
average_radius += radius;
}
surface_area = s.get_solvent_accessibility(core::XYZRs(particles));
Expand Down Expand Up @@ -121,28 +121,28 @@ void read_files(Model *m, const std::vector<std::string>& files,
bool heavy_atoms_only, int multi_model_pdb,
bool explicit_water, float max_q, int units) {

for (unsigned int i = 0; i < files.size(); i++) {
for (const auto &file : files) {
// check if file exists
std::ifstream in_file(files[i].c_str());
std::ifstream in_file(file.c_str());
if (!in_file) {
IMP_WARN("Can't open file " << files[i] << std::endl);
IMP_WARN("Can't open file " << file << std::endl);
return;
}
// 1. try as pdb or mmcif
try {
read_pdb(m, files[i], pdb_file_names, particles_vec, residue_level,
read_pdb(m, file, pdb_file_names, particles_vec, residue_level,
heavy_atoms_only, multi_model_pdb, explicit_water);
}
catch (const IMP::ValueException &e) { // not a pdb file
// 2. try as a dat profile file
IMP_NEW(Profile, profile, (files[i], false, max_q, units));
IMP_NEW(Profile, profile, (file, false, max_q, units));
if (profile->size() == 0) {
IMP_WARN("can't parse input file " << files[i] << std::endl);
IMP_WARN("can't parse input file " << file << std::endl);
return;
} else {
dat_files.push_back(files[i]);
dat_files.push_back(file);
exp_profiles.push_back(profile);
IMP_LOG_TERSE("Profile read from file " << files[i]
IMP_LOG_TERSE("Profile read from file " << file
<< " size = " << profile->size() << std::endl);
}
}
Expand Down

0 comments on commit fb179b3

Please sign in to comment.