Skip to content

Commit

Permalink
Use std::get to access Array elements
Browse files Browse the repository at this point in the history
  • Loading branch information
benmwebb committed Feb 6, 2024
1 parent 57e470d commit 5e539ec
Show file tree
Hide file tree
Showing 31 changed files with 144 additions and 125 deletions.
7 changes: 4 additions & 3 deletions modules/atom/src/BondedPairFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,12 @@ BondedPairFilter::BondedPairFilter() : PairPredicate("BondedPairFilter%1%") {}

int BondedPairFilter::get_value_index(
Model *m, const ParticleIndexPair &pip) const {
if (!Bonded::get_is_setup(m, pip[0]) || !Bonded::get_is_setup(m, pip[1])) {
if (!Bonded::get_is_setup(m, std::get<0>(pip))
|| !Bonded::get_is_setup(m, std::get<1>(pip))) {
return false;
}
Bonded ba(m, pip[0]);
Bonded bb(m, pip[1]);
Bonded ba(m, std::get<0>(pip));
Bonded bb(m, std::get<1>(pip));
Bond bd = get_bond(ba, bb);
return bd != Bond();
}
Expand Down
4 changes: 2 additions & 2 deletions modules/atom/src/CoulombPairScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ void CoulombPairScore::calculate_multiplication_factor() {
double CoulombPairScore::evaluate_index(Model *m,
const ParticleIndexPair &p,
DerivativeAccumulator *da) const {
Charged c0(m, p[0]);
Charged c1(m, p[1]);
Charged c0(m, std::get<0>(p));
Charged c1(m, std::get<1>(p));
algebra::Vector3D delta = c0.get_coordinates() - c1.get_coordinates();
double dist = delta.get_magnitude();
double score =
Expand Down
4 changes: 2 additions & 2 deletions modules/atom/src/HelixRestraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,8 @@ ModelObjectsTemp HelixRestraint::do_get_inputs() const {
}
for (ParticleIndexPairs::const_iterator tb = bonds_ON_.begin();
tb != bonds_ON_.end(); ++tb) {
ps.push_back(m->get_particle((*tb)[0]));
ps.push_back(m->get_particle((*tb)[1]));
ps.push_back(m->get_particle(std::get<0>(*tb)));
ps.push_back(m->get_particle(std::get<1>(*tb)));
}

return ps;
Expand Down
4 changes: 2 additions & 2 deletions modules/atom/src/LennardJonesPairScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ IMPATOM_BEGIN_NAMESPACE
Float LennardJonesPairScore::evaluate_index(Model *m,
const ParticleIndexPair &p,
DerivativeAccumulator *da) const {
LennardJones lj0(m, p[0]);
LennardJones lj1(m, p[1]);
LennardJones lj0(m, std::get<0>(p));
LennardJones lj1(m, std::get<1>(p));

algebra::Vector3D delta = lj0.get_coordinates() - lj1.get_coordinates();
double distsqr = delta.get_squared_magnitude();
Expand Down
3 changes: 2 additions & 1 deletion modules/atom/src/SameResiduePairFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ SameResiduePairFilter::SameResiduePairFilter() {}

int SameResiduePairFilter::get_value_index(
Model *m, const ParticleIndexPair &p) const {
return Hierarchy(m, p[0]).get_parent() == Hierarchy(m, p[1]).get_parent();
return Hierarchy(m, std::get<0>(p)).get_parent()
== Hierarchy(m, std::get<1>(p)).get_parent();
}

ModelObjectsTemp SameResiduePairFilter::do_get_inputs(
Expand Down
5 changes: 3 additions & 2 deletions modules/atom/src/StereochemistryPairFilter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ StereochemistryPairFilter::StereochemistryPairFilter() {}

int StereochemistryPairFilter::get_value_index(
Model *m, const ParticleIndexPair &pp) const {
return excluded_map_.find(internal::ExcludedPair(m->get_particle(pp[0]),
m->get_particle(pp[1]))) !=
return excluded_map_.find(
internal::ExcludedPair(m->get_particle(std::get<0>(pp)),
m->get_particle(std::get<1>(pp)))) !=
excluded_map_.end();
}

Expand Down
19 changes: 10 additions & 9 deletions modules/container/include/ConsecutivePairContainer.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,10 +37,10 @@ class IMPCONTAINEREXPORT ConsecutivePairContainer : public PairContainer {
void init();

bool get_contains(const ParticleIndexPair &p) const {
if (!get_model()->get_has_attribute(key_, p[0])) return false;
int ia = get_model()->get_attribute(key_, p[0]);
if (!get_model()->get_has_attribute(key_, p[1])) return false;
int ib = get_model()->get_attribute(key_, p[1]);
if (!get_model()->get_has_attribute(key_, std::get<0>(p))) return false;
int ia = get_model()->get_attribute(key_, std::get<0>(p));
if (!get_model()->get_has_attribute(key_, std::get<1>(p))) return false;
int ib = get_model()->get_attribute(key_, std::get<1>(p));
return std::abs(ia - ib) == 1;
}

Expand Down Expand Up @@ -117,16 +117,17 @@ class IMPCONTAINEREXPORT ExclusiveConsecutivePairContainer
const ParticleIndexPair &pp) {
ObjectKey ok =
ExclusiveConsecutivePairContainer::get_exclusive_object_key();
bool has_eok_0 = m->get_has_attribute(ok, pp[0]);
bool has_eok_1= m->get_has_attribute(ok, pp[1]);
bool has_eok_0 = m->get_has_attribute(ok, std::get<0>(pp));
bool has_eok_1= m->get_has_attribute(ok, std::get<1>(pp));
if ( !has_eok_0 || !has_eok_1 )
return false;
if (m->get_attribute(ok, pp[0]) != m->get_attribute(ok, pp[1])) {
if (m->get_attribute(ok, std::get<0>(pp))
!= m->get_attribute(ok, std::get<1>(pp))) {
return false;
}
IntKey k = ExclusiveConsecutivePairContainer::get_exclusive_key();
int ia = m->get_attribute(k, pp[0]);
int ib = m->get_attribute(k, pp[1]);
int ia = m->get_attribute(k, std::get<0>(pp));
int ib = m->get_attribute(k, std::get<1>(pp));
return std::abs(ia - ib) == 1;
}
void init();
Expand Down
9 changes: 5 additions & 4 deletions modules/container/src/internal/ClosePairContainer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,15 +140,16 @@ void ClosePairContainer::check_list(bool check_slack) const {
core::internal::filter_close_pairs(this, found);
IMP_LOG_TERSE("In check found " << found << std::endl);
for (unsigned int i = 0; i < found.size(); ++i) {
ParticleIndexPair pi(found[i][0], found[i][1]);
ParticleIndexPair pii(found[i][1], found[i][0]);
ParticleIndexPair pi(std::get<0>(found[i]), std::get<1>(found[i]));
ParticleIndexPair pii(std::get<1>(found[i]), std::get<0>(found[i]));
IMP_INTERNAL_CHECK(
existings.find(pi) != existings.end() ||
existings.find(pii) != existings.end(),
"Pair " << pi << " not found in close pairs list"
<< " at distance "
<< core::get_distance(core::XYZR(get_model(), found[i][0]),
core::XYZR(get_model(), found[i][1])));
<< core::get_distance(
core::XYZR(get_model(), std::get<0>(found[i])),
core::XYZR(get_model(), std::get<1>(found[i]))));
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions modules/container/test/test_non_rigid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ void check_close_pairs(IMP::Model *m,
for (unsigned int j = 0; j < i; ++j) {
IMP::ParticleIndexPair pp(ps[i], ps[j]);
IMP::ParticleIndexPair ppi(ps[j], ps[i]);
IMP::core::XYZR d0(m, pp[0]);
IMP::core::XYZR d1(m, pp[1]);
IMP::core::XYZR d0(m, std::get<0>(pp));
IMP::core::XYZR d1(m, std::get<1>(pp));
if (IMP::core::RigidMember::get_is_setup(m, ps[i]) &&
IMP::core::RigidMember::get_is_setup(m, ps[j]) &&
IMP::core::RigidMember(m, ps[i]).get_rigid_body() ==
Expand Down
10 changes: 6 additions & 4 deletions modules/core/include/ClosePairsPairScore.h
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,9 @@ class IMPCOREEXPORT KClosePairsPairScore : public PairScore {
ParticlePairsTemp get_close_pairs(const ParticlePair &pp)
const {
return IMP::internal::get_particle(
pp[0]->get_model(),
get_close_pairs(pp[0]->get_model(), IMP::internal::get_index(pp)));
std::get<0>(pp)->get_model(),
get_close_pairs(std::get<0>(pp)->get_model(),
IMP::internal::get_index(pp)));
}

Restraints create_current_decomposition(
Expand Down Expand Up @@ -88,8 +89,9 @@ class IMPCOREEXPORT ClosePairsPairScore : public PairScore {
ParticlePairsTemp get_close_pairs(const ParticlePair &pp)
const {
return IMP::internal::get_particle(
pp[0]->get_model(),
get_close_pairs(pp[0]->get_model(), IMP::internal::get_index(pp)));
std::get<0>(pp)->get_model(),
get_close_pairs(std::get<0>(pp)->get_model(),
IMP::internal::get_index(pp)));
}
Restraints create_current_decomposition(
Model *m, const ParticleIndexPair &vt) const;
Expand Down
12 changes: 7 additions & 5 deletions modules/core/include/SphereDistancePairScore.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,18 +109,20 @@ inline double HarmonicUpperBoundSphereDiameterPairScore::evaluate_index(
Model *m, const ParticleIndexPair &p,
DerivativeAccumulator *da) const {
algebra::Vector3D delta =
m->get_sphere(p[0]).get_center() - m->get_sphere(p[1]).get_center();
m->get_sphere(std::get<0>(p)).get_center()
- m->get_sphere(std::get<1>(p)).get_center();
static const double MIN_DISTANCE = .00001;
double distance = delta.get_magnitude();
double shifted_distance = distance - x0_ + m->get_sphere(p[0]).get_radius() +
m->get_sphere(p[1]).get_radius();
double shifted_distance
= distance - x0_ + m->get_sphere(std::get<0>(p)).get_radius() +
m->get_sphere(std::get<1>(p)).get_radius();
if (shifted_distance < 0) return 0;
double score = .5 * k_ * square(shifted_distance);
if (da && distance > MIN_DISTANCE) {
double deriv = k_ * shifted_distance;
algebra::Vector3D uv = delta / distance;
m->add_to_coordinate_derivatives(p[0], uv * deriv, *da);
m->add_to_coordinate_derivatives(p[1], -uv * deriv, *da);
m->add_to_coordinate_derivatives(std::get<0>(p), uv * deriv, *da);
m->add_to_coordinate_derivatives(std::get<1>(p), -uv * deriv, *da);
}
return score;
}
Expand Down
12 changes: 6 additions & 6 deletions modules/core/include/internal/close_pairs_helpers.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,8 @@ inline void filter_close_pairs(C *c, ParticleIndexPairs &pips) {
//! canonize pairs index order in pips, such that pi1>=pi0 for each pair (pi0,pi1)
inline void fix_order(ParticleIndexPairs &pips) {
for (unsigned int i = 0; i < pips.size(); ++i) {
if (pips[i][0] > pips[i][1]) {
pips[i] = ParticleIndexPair(pips[i][1], pips[i][0]);
if (std::get<0>(pips[i]) > std::get<1>(pips[i])) {
pips[i] = ParticleIndexPair(std::get<1>(pips[i]), std::get<0>(pips[i]));
}
}
}
Expand Down Expand Up @@ -116,8 +116,8 @@ FarParticle
{}

bool operator()(const ParticleIndexPair &pp) const {
int index0= pp[0].get_index();
int index1= pp[1].get_index();
int index0 = std::get<0>(pp).get_index();
int index1 = std::get<1>(pp).get_index();
return !get_are_close(model_spheres_table_[index0],
model_spheres_table_[index1],
d_);
Expand Down Expand Up @@ -148,9 +148,9 @@ struct InList {
}*/
}
bool operator()(const ParticlePair &pp) const {
if (std::binary_search(ps_.begin(), ps_.end(), pp[0]))
if (std::binary_search(ps_.begin(), ps_.end(), std::get<0>(pp)))
return true;
else if (std::binary_search(ps_.begin(), ps_.end(), pp[1]))
else if (std::binary_search(ps_.begin(), ps_.end(), std::get<1>(pp)))
return true;
return false;
// return pp[0]->has_attribute(key_) || pp[1]->has_attribute(key_);
Expand Down
6 changes: 3 additions & 3 deletions modules/core/src/AngleTripletScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ Float AngleTripletScore::evaluate_index(Model *m,
const ParticleIndexTriplet &pi,
DerivativeAccumulator *da) const {
IMP_CHECK_OBJECT(f_.get());
XYZ d0 = XYZ(m, pi[0]);
XYZ d1 = XYZ(m, pi[1]);
XYZ d2 = XYZ(m, pi[2]);
XYZ d0 = XYZ(m, std::get<0>(pi));
XYZ d1 = XYZ(m, std::get<1>(pi));
XYZ d2 = XYZ(m, std::get<2>(pi));

Float score;

Expand Down
21 changes: 12 additions & 9 deletions modules/core/src/ClosePairsPairScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,8 @@ ParticleIndexPairs ClosePairsPairScore::get_close_pairs(
Model *m, const ParticleIndexPair &p) const {
ParticleIndexPairs ppt;
Floats dists;
ParticleIndexes ps0 = expand(m->get_particle(p[0]), r_);
ParticleIndexes ps1 = expand(m->get_particle(p[1]), r_);
ParticleIndexes ps0 = expand(m->get_particle(std::get<0>(p)), r_);
ParticleIndexes ps1 = expand(m->get_particle(std::get<1>(p)), r_);
fill_close_pairs(cpf_, m, th_, ps0, ps1, ppt);
return ppt;
}
Expand All @@ -98,14 +98,16 @@ ParticleIndexPairs KClosePairsPairScore::get_close_pairs(
IMP_OBJECT_LOG;
// double mr= std::max(max_radius(psa), max_radius(psb));
ParticleIndexPairs ppt;
ParticleIndexes ps0 = expand(m->get_particle(p[0]), r_);
ParticleIndexes ps1 = expand(m->get_particle(p[1]), r_);
ParticleIndexes ps0 = expand(m->get_particle(std::get<0>(p)), r_);
ParticleIndexes ps1 = expand(m->get_particle(std::get<1>(p)), r_);

if (ps0.size() + ps1.size() > 50) {
Floats dists;
double dist = last_distance_;
IMP_USAGE_CHECK(ps0.size() > 0, "Empty set of particles used for " << p[0]);
IMP_USAGE_CHECK(ps1.size() > 0, "Empty set of particles used for " << p[1]);
IMP_USAGE_CHECK(ps0.size() > 0, "Empty set of particles used for "
<< std::get<0>(p));
IMP_USAGE_CHECK(ps1.size() > 0, "Empty set of particles used for "
<< std::get<1>(p));
do {
IMP_LOG_VERBOSE("Searching for close pairs " << dist << std::endl);
fill_close_pairs(cpf_, m, dist, ps0, ps1, ppt);
Expand All @@ -115,8 +117,8 @@ ParticleIndexPairs KClosePairsPairScore::get_close_pairs(
} while (ppt.size() < static_cast<unsigned int>(k_));
algebra::internal::MinimalSet<double, ParticleIndexPair> ms(k_);
for (unsigned int i = 0; i < ppt.size(); ++i) {
double d = algebra::get_distance(m->get_sphere(ppt[i][0]),
m->get_sphere(ppt[i][1]));
double d = algebra::get_distance(m->get_sphere(std::get<0>(ppt[i])),
m->get_sphere(std::get<1>(ppt[i])));
// std::cout << "Trying " << d << " " << ppt[i] << std::endl;
ms.insert(d, ppt[i]);
}
Expand All @@ -136,7 +138,8 @@ ParticleIndexPairs KClosePairsPairScore::get_close_pairs(
IMP_IF_CHECK(USAGE) {
if (k_ == 1) {
double distance =
get_distance(XYZR(m, retps[0][0]), XYZR(m, retps[0][1]));
get_distance(XYZR(m, std::get<0>(retps[0])),
XYZR(m, std::get<1>(retps[0])));
for (unsigned int i = 0; i < ps0.size(); ++i) {
for (unsigned int j = 0; j < ps1.size(); ++j) {
double cdistance = get_distance(XYZR(m, ps0[i]), XYZR(m, ps1[j]));
Expand Down
3 changes: 2 additions & 1 deletion modules/core/src/ExcludedVolumeRestraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -246,7 +246,8 @@ double ExcludedVolumeRestraint::unprotected_evaluate_if_good(
for (unsigned int i = 0; i < cur_list_.size(); ++i) {
double c = ssps_->evaluate_index(
get_model(),
ParticleIndexPair(cur_list_[i][0], cur_list_[i][1]), da);
ParticleIndexPair(std::get<0>(cur_list_[i]),
std::get<1>(cur_list_[i])), da);
cur += c;
max -= c;
if (max < 0) {
Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/NeighborsTable.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ void NeighborsTable::do_before_evaluate() {
data_.clear();

IMP_CONTAINER_FOREACH(PairContainer, input_, {
data_[_1[0]].push_back(_1[1]);
data_[_1[1]].push_back(_1[0]);
data_[std::get<0>(_1)].push_back(std::get<1>(_1));
data_[std::get<1>(_1)].push_back(std::get<0>(_1));
});
}

Expand Down
4 changes: 2 additions & 2 deletions modules/core/src/RefinedPairsPairScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ ParticlesTemp get_set(Particle *a, Refiner *r) {
Float RefinedPairsPairScore::evaluate_index(Model *m,
const ParticleIndexPair &p,
DerivativeAccumulator *da) const {
ParticlesTemp ps[2] = {get_set(m->get_particle(p[0]), r_),
get_set(m->get_particle(p[1]), r_)};
ParticlesTemp ps[2] = {get_set(m->get_particle(std::get<0>(p)), r_),
get_set(m->get_particle(std::get<1>(p)), r_)};
double ret = 0;
for (unsigned int i = 0; i < ps[0].size(); ++i) {
for (unsigned int j = 0; j < ps[1].size(); ++j) {
Expand Down
10 changes: 6 additions & 4 deletions modules/core/src/RigidBodyAnglePairScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,20 @@ Float RigidBodyAnglePairScore::evaluate_index(Model *m,
IMP_USAGE_CHECK(!da, "Derivatives not implemented");

// check if rigid body
IMP_USAGE_CHECK(RigidBody::get_is_setup(m, pi[0]),
IMP_USAGE_CHECK(RigidBody::get_is_setup(m, std::get<0>(pi)),
"Particle is not a rigid body");
IMP_USAGE_CHECK(RigidBody::get_is_setup(m, pi[1]),
IMP_USAGE_CHECK(RigidBody::get_is_setup(m, std::get<1>(pi)),
"Particle is not a rigid body");

// principal axis of inertia is aligned to z axis when creating rigid body
algebra::Vector3D inertia=algebra::Vector3D(1.0,0.0,0.0);
algebra::Vector3D origin=algebra::Vector3D(0.0,0.0,0.0);

// get the two references frames
algebra::ReferenceFrame3D rf0 = RigidBody(m, pi[0]).get_reference_frame();
algebra::ReferenceFrame3D rf1 = RigidBody(m, pi[1]).get_reference_frame();
algebra::ReferenceFrame3D rf0
= RigidBody(m, std::get<0>(pi)).get_reference_frame();
algebra::ReferenceFrame3D rf1
= RigidBody(m, std::get<1>(pi)).get_reference_frame();

// rigid body 0
algebra::Vector3D i0 = rf0.get_global_coordinates(inertia);
Expand Down
16 changes: 8 additions & 8 deletions modules/core/src/SphereDistancePairScore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,12 +33,12 @@ NormalizedSphereDistancePairScore::NormalizedSphereDistancePairScore(
double NormalizedSphereDistancePairScore::evaluate_index(
Model *m, const ParticleIndexPair &pip,
DerivativeAccumulator *da) const {
Float ra = m->get_attribute(radius_, pip[0]);
Float rb = m->get_attribute(radius_, pip[1]);
Float ra = m->get_attribute(radius_, std::get<0>(pip));
Float rb = m->get_attribute(radius_, std::get<1>(pip));
Float mr = std::min(ra, rb);
// lambda is inefficient due to laziness
return internal::evaluate_distance_pair_score(
XYZ(m, pip[0]), XYZ(m, pip[1]), da, f_.get(),
XYZ(m, std::get<0>(pip)), XYZ(m, std::get<1>(pip)), da, f_.get(),
boost::lambda::_1 / mr - (ra + rb) / mr);
}

Expand All @@ -54,13 +54,13 @@ WeightedSphereDistancePairScore::WeightedSphereDistancePairScore(
double WeightedSphereDistancePairScore::evaluate_index(
Model *m, const ParticleIndexPair &p,
DerivativeAccumulator *da) const {
Float ra = m->get_attribute(radius_, p[0]);
Float rb = m->get_attribute(radius_, p[1]);
Float wa = m->get_attribute(weight_, p[0]);
Float wb = m->get_attribute(weight_, p[1]);
Float ra = m->get_attribute(radius_, std::get<0>(p));
Float rb = m->get_attribute(radius_, std::get<1>(p));
Float wa = m->get_attribute(weight_, std::get<0>(p));
Float wb = m->get_attribute(weight_, std::get<1>(p));
// lambda is inefficient due to laziness
return internal::evaluate_distance_pair_score(
XYZ(m, p[0]), XYZ(m, p[1]), da, f_.get(),
XYZ(m, std::get<0>(p)), XYZ(m, std::get<1>(p)), da, f_.get(),
(boost::lambda::_1 - (ra + rb)) * (wa + wb));
}

Expand Down
Loading

0 comments on commit 5e539ec

Please sign in to comment.