From 5e539ec2ee8b85e4542ca941db80cdb88e1a5858 Mon Sep 17 00:00:00 2001 From: Ben Webb Date: Mon, 5 Feb 2024 16:47:10 -0800 Subject: [PATCH] Use std::get to access Array elements --- modules/atom/src/BondedPairFilter.cpp | 7 +++-- modules/atom/src/CoulombPairScore.cpp | 4 +-- modules/atom/src/HelixRestraint.cpp | 4 +-- modules/atom/src/LennardJonesPairScore.cpp | 4 +-- modules/atom/src/SameResiduePairFilter.cpp | 3 +- .../atom/src/StereochemistryPairFilter.cpp | 5 ++-- .../include/ConsecutivePairContainer.h | 19 ++++++------ .../src/internal/ClosePairContainer.cpp | 9 +++--- modules/container/test/test_non_rigid.cpp | 4 +-- modules/core/include/ClosePairsPairScore.h | 10 ++++--- .../core/include/SphereDistancePairScore.h | 12 ++++---- .../include/internal/close_pairs_helpers.h | 12 ++++---- modules/core/src/AngleTripletScore.cpp | 6 ++-- modules/core/src/ClosePairsPairScore.cpp | 21 +++++++------ modules/core/src/ExcludedVolumeRestraint.cpp | 3 +- modules/core/src/NeighborsTable.cpp | 4 +-- modules/core/src/RefinedPairsPairScore.cpp | 4 +-- modules/core/src/RigidBodyAnglePairScore.cpp | 10 ++++--- modules/core/src/SphereDistancePairScore.cpp | 16 +++++----- .../core/src/SurfaceSymmetryConstraint.cpp | 30 +++++++++---------- .../core/src/TransformedDistancePairScore.cpp | 4 +-- modules/core/src/TypedPairScore.cpp | 19 ++++++------ modules/core/src/direction.cpp | 2 +- modules/misc/src/CommonEndpointPairFilter.cpp | 8 ++--- modules/misc/src/LowestRefinedPairScore.cpp | 4 +-- modules/misc/src/SoftCylinderPairScore.cpp | 3 +- modules/misc/test/test_metric_close_pairs.cpp | 16 +++++----- modules/npc/src/CompositeRestraint.cpp | 4 +-- .../src/MinimumSphereDistancePairScore.cpp | 4 +-- .../include/DistancePairScoreWithCache.h | 7 +++-- .../include/SurfaceDistancePairScore.h | 11 +++---- 31 files changed, 144 insertions(+), 125 deletions(-) diff --git a/modules/atom/src/BondedPairFilter.cpp b/modules/atom/src/BondedPairFilter.cpp index 7a62b820b8..effc437e96 100644 --- a/modules/atom/src/BondedPairFilter.cpp +++ b/modules/atom/src/BondedPairFilter.cpp @@ -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(); } diff --git a/modules/atom/src/CoulombPairScore.cpp b/modules/atom/src/CoulombPairScore.cpp index 18ff703986..3b6f045b3b 100644 --- a/modules/atom/src/CoulombPairScore.cpp +++ b/modules/atom/src/CoulombPairScore.cpp @@ -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 = diff --git a/modules/atom/src/HelixRestraint.cpp b/modules/atom/src/HelixRestraint.cpp index bf625282cd..d9ce7e50b6 100644 --- a/modules/atom/src/HelixRestraint.cpp +++ b/modules/atom/src/HelixRestraint.cpp @@ -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; diff --git a/modules/atom/src/LennardJonesPairScore.cpp b/modules/atom/src/LennardJonesPairScore.cpp index d0f6568926..8c3ba1643e 100644 --- a/modules/atom/src/LennardJonesPairScore.cpp +++ b/modules/atom/src/LennardJonesPairScore.cpp @@ -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(); diff --git a/modules/atom/src/SameResiduePairFilter.cpp b/modules/atom/src/SameResiduePairFilter.cpp index 9af96cfc3f..7aedf89763 100644 --- a/modules/atom/src/SameResiduePairFilter.cpp +++ b/modules/atom/src/SameResiduePairFilter.cpp @@ -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( diff --git a/modules/atom/src/StereochemistryPairFilter.cpp b/modules/atom/src/StereochemistryPairFilter.cpp index a948377223..6821bcbd14 100644 --- a/modules/atom/src/StereochemistryPairFilter.cpp +++ b/modules/atom/src/StereochemistryPairFilter.cpp @@ -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(); } diff --git a/modules/container/include/ConsecutivePairContainer.h b/modules/container/include/ConsecutivePairContainer.h index b3abae4ecd..76fd77a7f6 100644 --- a/modules/container/include/ConsecutivePairContainer.h +++ b/modules/container/include/ConsecutivePairContainer.h @@ -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; } @@ -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(); diff --git a/modules/container/src/internal/ClosePairContainer.cpp b/modules/container/src/internal/ClosePairContainer.cpp index 34240034be..29fd73ef6d 100644 --- a/modules/container/src/internal/ClosePairContainer.cpp +++ b/modules/container/src/internal/ClosePairContainer.cpp @@ -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])))); } } } diff --git a/modules/container/test/test_non_rigid.cpp b/modules/container/test/test_non_rigid.cpp index f8bf7eadc4..d949cf5213 100644 --- a/modules/container/test/test_non_rigid.cpp +++ b/modules/container/test/test_non_rigid.cpp @@ -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() == diff --git a/modules/core/include/ClosePairsPairScore.h b/modules/core/include/ClosePairsPairScore.h index 18dc3f93b4..0e9915660e 100644 --- a/modules/core/include/ClosePairsPairScore.h +++ b/modules/core/include/ClosePairsPairScore.h @@ -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( @@ -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; diff --git a/modules/core/include/SphereDistancePairScore.h b/modules/core/include/SphereDistancePairScore.h index beaaef68b8..5688fd820c 100644 --- a/modules/core/include/SphereDistancePairScore.h +++ b/modules/core/include/SphereDistancePairScore.h @@ -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; } diff --git a/modules/core/include/internal/close_pairs_helpers.h b/modules/core/include/internal/close_pairs_helpers.h index beb2e42b57..4b8d7d0d9c 100644 --- a/modules/core/include/internal/close_pairs_helpers.h +++ b/modules/core/include/internal/close_pairs_helpers.h @@ -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])); } } } @@ -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_); @@ -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_); diff --git a/modules/core/src/AngleTripletScore.cpp b/modules/core/src/AngleTripletScore.cpp index 0f850d7ec9..176cefc1b9 100644 --- a/modules/core/src/AngleTripletScore.cpp +++ b/modules/core/src/AngleTripletScore.cpp @@ -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; diff --git a/modules/core/src/ClosePairsPairScore.cpp b/modules/core/src/ClosePairsPairScore.cpp index e303ae90e1..b65ec49cb9 100644 --- a/modules/core/src/ClosePairsPairScore.cpp +++ b/modules/core/src/ClosePairsPairScore.cpp @@ -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; } @@ -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); @@ -115,8 +117,8 @@ ParticleIndexPairs KClosePairsPairScore::get_close_pairs( } while (ppt.size() < static_cast(k_)); algebra::internal::MinimalSet 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]); } @@ -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])); diff --git a/modules/core/src/ExcludedVolumeRestraint.cpp b/modules/core/src/ExcludedVolumeRestraint.cpp index 97c0be8085..335ffa6837 100644 --- a/modules/core/src/ExcludedVolumeRestraint.cpp +++ b/modules/core/src/ExcludedVolumeRestraint.cpp @@ -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) { diff --git a/modules/core/src/NeighborsTable.cpp b/modules/core/src/NeighborsTable.cpp index 349fde86ce..8003f74cb0 100644 --- a/modules/core/src/NeighborsTable.cpp +++ b/modules/core/src/NeighborsTable.cpp @@ -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)); }); } diff --git a/modules/core/src/RefinedPairsPairScore.cpp b/modules/core/src/RefinedPairsPairScore.cpp index 3f45b464f8..5d131ad3b8 100644 --- a/modules/core/src/RefinedPairsPairScore.cpp +++ b/modules/core/src/RefinedPairsPairScore.cpp @@ -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) { diff --git a/modules/core/src/RigidBodyAnglePairScore.cpp b/modules/core/src/RigidBodyAnglePairScore.cpp index 910c103c4c..572db36c59 100644 --- a/modules/core/src/RigidBodyAnglePairScore.cpp +++ b/modules/core/src/RigidBodyAnglePairScore.cpp @@ -22,9 +22,9 @@ 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 @@ -32,8 +32,10 @@ Float RigidBodyAnglePairScore::evaluate_index(Model *m, 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); diff --git a/modules/core/src/SphereDistancePairScore.cpp b/modules/core/src/SphereDistancePairScore.cpp index 731b2e39f1..07c73e5b3a 100644 --- a/modules/core/src/SphereDistancePairScore.cpp +++ b/modules/core/src/SphereDistancePairScore.cpp @@ -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); } @@ -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)); } diff --git a/modules/core/src/SurfaceSymmetryConstraint.cpp b/modules/core/src/SurfaceSymmetryConstraint.cpp index 61e70629c9..6948f7629f 100644 --- a/modules/core/src/SurfaceSymmetryConstraint.cpp +++ b/modules/core/src/SurfaceSymmetryConstraint.cpp @@ -16,33 +16,33 @@ SurfaceSymmetryConstraint::SurfaceSymmetryConstraint(Model *m, const ParticleIndexPair &rbs) : IMP::Constraint(m, "SurfaceSymmetryConstraint%1%") , spip_(ss), rbpip_(rbs) { - IMP_USAGE_CHECK(Surface::get_is_setup(get_model(), ss[0]) & - Surface::get_is_setup(get_model(), ss[1]), + IMP_USAGE_CHECK(Surface::get_is_setup(get_model(), std::get<0>(ss)) & + Surface::get_is_setup(get_model(), std:get<1>(ss)), "First pair must be Surface particles."); - IMP_USAGE_CHECK(RigidBody::get_is_setup(get_model(), rbs[0]) & - RigidBody::get_is_setup(get_model(), rbs[1]), + IMP_USAGE_CHECK(RigidBody::get_is_setup(get_model(), std::get<0>(rbs)) & + RigidBody::get_is_setup(get_model(), std::get<1>(rbs)), "Second pair must be RigidBody particles."); } algebra::Transformation3D SurfaceSymmetryConstraint::get_transformation() const { return algebra::get_transformation_from_first_to_second( - RigidBody(get_model(), rbpip_[1]).get_reference_frame(), - RigidBody(get_model(), rbpip_[0]).get_reference_frame()); + RigidBody(get_model(), std::get<1>(rbpip_)).get_reference_frame(), + RigidBody(get_model(), std::get<0>(rbpip_)).get_reference_frame()); } void SurfaceSymmetryConstraint::do_update_attributes() { algebra::Transformation3D tf = get_transformation(); Surface s, sref; - s = Surface(get_model(), spip_[0]); - sref = Surface(get_model(), spip_[1]); + s = Surface(get_model(), std::get<0>(spip_)); + sref = Surface(get_model(), std::get<1>(spip_)); s.set_normal(tf.get_rotation().get_rotated(sref.get_normal())); s.set_coordinates(tf.get_transformed(sref.get_coordinates())); } void SurfaceSymmetryConstraint::do_update_derivatives(DerivativeAccumulator *da) { algebra::Rotation3D rot = get_transformation().get_inverse().get_rotation(); - Surface s1 = Surface(get_model(), spip_[0]); - Surface s2 = Surface(get_model(), spip_[1]); + Surface s1 = Surface(get_model(), std::get<0>(spip_)); + Surface s2 = Surface(get_model(), std::get<1>(spip_)); s2.add_to_derivatives(rot.get_rotated(s1.get_derivatives()), *da); s2.add_to_normal_derivatives(rot.get_rotated(s1.get_normal_derivatives()), *da); @@ -50,16 +50,16 @@ void SurfaceSymmetryConstraint::do_update_derivatives(DerivativeAccumulator *da) ModelObjectsTemp SurfaceSymmetryConstraint::do_get_inputs() const { ParticlesTemp ps; - ps.push_back(get_model()->get_particle(spip_[1])); - ps.push_back(get_model()->get_particle(rbpip_[0])); - ps.push_back(get_model()->get_particle(rbpip_[1])); + ps.push_back(get_model()->get_particle(std::get<1>(spip_))); + ps.push_back(get_model()->get_particle(std::get<0>(rbpip_))); + ps.push_back(get_model()->get_particle(std::get<1>(rbpip_))); return ps; } ModelObjectsTemp SurfaceSymmetryConstraint::do_get_outputs() const { ParticlesTemp ps; - ps.push_back(get_model()->get_particle(spip_[0])); - ps.push_back(get_model()->get_particle(spip_[1])); + ps.push_back(get_model()->get_particle(std::get<0>(spip_))); + ps.push_back(get_model()->get_particle(std::get<1>(spip_))); return ps; } diff --git a/modules/core/src/TransformedDistancePairScore.cpp b/modules/core/src/TransformedDistancePairScore.cpp index b2385d59b7..818a97a207 100644 --- a/modules/core/src/TransformedDistancePairScore.cpp +++ b/modules/core/src/TransformedDistancePairScore.cpp @@ -46,12 +46,12 @@ struct TransformParticle { double TransformedDistancePairScore::evaluate_index( Model *m, const ParticleIndexPair &pip, DerivativeAccumulator *da) const { - TransformParticle tb(t_, ri_, m, pip[1]); + TransformParticle tb(t_, ri_, m, std::get<1>(pip)); IMP_LOG_VERBOSE("Transformed particle is " << tb.get_coordinate(0) << " " << tb.get_coordinate(1) << " " << tb.get_coordinate(2) << std::endl); Float ret = internal::evaluate_distance_pair_score( - XYZ(m, pip[0]), tb, da, f_.get(), boost::lambda::_1); + XYZ(m, std::get<0>(pip)), tb, da, f_.get(), boost::lambda::_1); return ret; } diff --git a/modules/core/src/TypedPairScore.cpp b/modules/core/src/TypedPairScore.cpp index c1ef163bba..b4357f3056 100644 --- a/modules/core/src/TypedPairScore.cpp +++ b/modules/core/src/TypedPairScore.cpp @@ -12,15 +12,16 @@ IMPCORE_BEGIN_NAMESPACE Float TypedPairScore::evaluate_index(Model *m, const ParticleIndexPair &pip, DerivativeAccumulator *da) const { - ParticlePair p(m->get_particle(pip[0]), m->get_particle(pip[1])); + ParticlePair p(m->get_particle(std::get<0>(pip)), + m->get_particle(std::get<1>(pip))); PairScore *ps = get_pair_score(p); if (!ps) { if (!allow_invalid_types_) { IMP_THROW( "Attempt to evaluate TypedPairScore on " "particles with invalid types (" - << p[0]->get_value(typekey_) << ", " << p[1]->get_value(typekey_) - << ")", + << std::get<0>(p)->get_value(typekey_) << ", " + << std::get<1>(p)->get_value(typekey_) << ")", ValueException); } else { return 0.0; @@ -31,14 +32,14 @@ Float TypedPairScore::evaluate_index(Model *m, } PairScore *TypedPairScore::get_pair_score(const ParticlePair &p) const { - if (!p[0]->has_attribute(typekey_)) { - set_particle_type(p[0]); + if (!std::get<0>(p)->has_attribute(typekey_)) { + set_particle_type(std::get<0>(p)); } - if (!p[1]->has_attribute(typekey_)) { - set_particle_type(p[1]); + if (!std::get<1>(p)->has_attribute(typekey_)) { + set_particle_type(std::get<1>(p)); } - Int atype = p[0]->get_value(typekey_); - Int btype = p[1]->get_value(typekey_); + Int atype = std::get<0>(p)->get_value(typekey_); + Int btype = std::get<1>(p)->get_value(typekey_); ScoreMap::const_iterator psit = score_map_.find( std::pair(std::min(atype, btype), std::max(atype, btype))); diff --git a/modules/core/src/direction.cpp b/modules/core/src/direction.cpp index e2112aafc5..0ca00c1ac7 100644 --- a/modules/core/src/direction.cpp +++ b/modules/core/src/direction.cpp @@ -90,7 +90,7 @@ ObjectKey Direction::get_constraint_key() { void DirectionAngle::do_setup_particle(Model *m, ParticleIndex pi, const ParticleIndexPair &ds) { - DirectionAngle::do_setup_particle(m, pi, ds[0], ds[1]); + DirectionAngle::do_setup_particle(m, pi, std::get<0>(ds), std::get<1>(ds)); } void DirectionAngle::do_setup_particle(Model *m, ParticleIndex pi, diff --git a/modules/misc/src/CommonEndpointPairFilter.cpp b/modules/misc/src/CommonEndpointPairFilter.cpp index 07f0a3a555..16b818a987 100644 --- a/modules/misc/src/CommonEndpointPairFilter.cpp +++ b/modules/misc/src/CommonEndpointPairFilter.cpp @@ -15,12 +15,12 @@ CommonEndpointPairFilter::CommonEndpointPairFilter() {} int CommonEndpointPairFilter::get_value_index( Model *m, const ParticleIndexPair &p) const { - if (!IMP::atom::Bond::get_is_setup(m, p[0]) || - !IMP::atom::Bond::get_is_setup(m, p[1])) { + if (!IMP::atom::Bond::get_is_setup(m, std::get<0>(p)) || + !IMP::atom::Bond::get_is_setup(m, std::get<1>(p))) { return false; } else { - IMP::atom::Bond b0(m, p[0]); - IMP::atom::Bond b1(m, p[1]); + IMP::atom::Bond b0(m, std::get<0>(p)); + IMP::atom::Bond b1(m, std::get<1>(p)); return b0.get_bonded(0) == b1.get_bonded(1) || b0.get_bonded(1) == b1.get_bonded(0) || b0.get_bonded(0) == b1.get_bonded(0) || diff --git a/modules/misc/src/LowestRefinedPairScore.cpp b/modules/misc/src/LowestRefinedPairScore.cpp index 40f7a2faf7..eb65335fec 100644 --- a/modules/misc/src/LowestRefinedPairScore.cpp +++ b/modules/misc/src/LowestRefinedPairScore.cpp @@ -51,8 +51,8 @@ std::pair get_lowest(ParticlesTemp ps[2], Float LowestRefinedPairScore::evaluate_index( Model *m, const ParticleIndexPair &pi, DerivativeAccumulator *da) const { - ParticlesTemp ps[2] = {get_set(m->get_particle(pi[0]), r_), - get_set(m->get_particle(pi[1]), r_)}; + ParticlesTemp ps[2] = {get_set(m->get_particle(std::get<0>(pi)), r_), + get_set(m->get_particle(std::get<1>(pi)), r_)}; std::pair r = get_lowest(ps, f_); diff --git a/modules/misc/src/SoftCylinderPairScore.cpp b/modules/misc/src/SoftCylinderPairScore.cpp index 5ba7128c13..d6f79a70b3 100644 --- a/modules/misc/src/SoftCylinderPairScore.cpp +++ b/modules/misc/src/SoftCylinderPairScore.cpp @@ -17,7 +17,8 @@ SoftCylinderPairScore::SoftCylinderPairScore(double k) : k_(k) {} Float SoftCylinderPairScore::evaluate_index( Model *m, const ParticleIndexPair &pip, DerivativeAccumulator *da) const { - atom::Bond b[2] = {atom::Bond(m, pip[0]), atom::Bond(m, pip[1])}; + atom::Bond b[2] = {atom::Bond(m, std::get<0>(pip)), + atom::Bond(m, std::get<1>(pip))}; core::XYZR d[2][2] = { {core::XYZR(b[0].get_bonded(0)), core::XYZR(b[0].get_bonded(1))}, diff --git a/modules/misc/test/test_metric_close_pairs.cpp b/modules/misc/test/test_metric_close_pairs.cpp index 556cb75dd5..a4b8db1c7a 100644 --- a/modules/misc/test/test_metric_close_pairs.cpp +++ b/modules/misc/test/test_metric_close_pairs.cpp @@ -19,25 +19,25 @@ namespace { struct LowerBound { double operator()(IMP::Model *m, const IMP::ParticleIndexPair &pip) const { - return IMP::core::get_distance(IMP::core::XYZR(m, pip[0]), - IMP::core::XYZR(m, pip[1])); + return IMP::core::get_distance(IMP::core::XYZR(m, std::get<0>(pip)), + IMP::core::XYZR(m, std::get<1>(pip))); } }; struct UpperBound { double operator()(IMP::Model *m, const IMP::ParticleIndexPair &pip) const { - return IMP::core::get_distance(IMP::core::XYZ(m, pip[0]), - IMP::core::XYZ(m, pip[1])) + - IMP::core::XYZR(m, pip[0]).get_radius() + - IMP::core::XYZR(m, pip[1]).get_radius(); + return IMP::core::get_distance(IMP::core::XYZ(m, std::get<0>(pip)), + IMP::core::XYZ(m, std::get<1>(pip))) + + IMP::core::XYZR(m, std::get<0>(pip)).get_radius() + + IMP::core::XYZR(m, std::get<1>(pip)).get_radius(); } }; void canonicalize(IMP::ParticleIndexPairs &pip) { for (unsigned int i = 0; i < pip.size(); ++i) { - if (pip[i][0] > pip[i][1]) { - pip[i] = IMP::ParticleIndexPair(pip[i][1], pip[i][0]); + if (std::get<0>(pip[i]) > std::get<1>(pip[i])) { + pip[i] = IMP::ParticleIndexPair(std::get<1>(pip[i]), std::get<0>(pip[i])); } } } diff --git a/modules/npc/src/CompositeRestraint.cpp b/modules/npc/src/CompositeRestraint.cpp index 651d2870e0..236e57f40a 100644 --- a/modules/npc/src/CompositeRestraint.cpp +++ b/modules/npc/src/CompositeRestraint.cpp @@ -208,8 +208,8 @@ double CompositeRestraint::unprotected_evaluate(DerivativeAccumulator *accum) IMP_LOG_VERBOSE("Minimum subtree is ["); for (const ParticleIndexPair &it : pis) { IMP_UNUSED(it); - IMP_LOG_VERBOSE("(" << get_model()->get_particle_name(it[0]) - << ", " << get_model()->get_particle_name(it[1]) + IMP_LOG_VERBOSE("(" << get_model()->get_particle_name(std::get<0>(it)) + << ", " << get_model()->get_particle_name(std::get<1>(it)) << ") "); } IMP_LOG_VERBOSE("]" << std::endl); diff --git a/modules/npc/src/MinimumSphereDistancePairScore.cpp b/modules/npc/src/MinimumSphereDistancePairScore.cpp index 4c91c4d529..754d4b8471 100644 --- a/modules/npc/src/MinimumSphereDistancePairScore.cpp +++ b/modules/npc/src/MinimumSphereDistancePairScore.cpp @@ -16,8 +16,8 @@ IMPNPC_BEGIN_NAMESPACE double MinimumSphereDistancePairScore::evaluate_index(Model *m, const ParticleIndexPair &pi, DerivativeAccumulator *da) const { - core::XYZR d0(m, pi[0]); - core::XYZR d1(m, pi[1]); + core::XYZR d0(m, std::get<0>(pi)); + core::XYZR d1(m, std::get<1>(pi)); algebra::Vector3D c0 = d0.get_coordinates(); algebra::Vector3D c1_orig = d1.get_coordinates(), c1_min = c1_orig; double dist2_min = algebra::get_squared_distance(c0, c1_orig); diff --git a/modules/score_functor/include/DistancePairScoreWithCache.h b/modules/score_functor/include/DistancePairScoreWithCache.h index d0b2e022f4..bba3de33b6 100644 --- a/modules/score_functor/include/DistancePairScoreWithCache.h +++ b/modules/score_functor/include/DistancePairScoreWithCache.h @@ -129,7 +129,8 @@ DistancePairScoreWithCache::evaluate_index_with_cache( 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(); double sq = delta.get_squared_magnitude(); if (ds_.get_is_trivially_zero_with_cache(m, p, sq)) { return 0; @@ -145,8 +146,8 @@ DistancePairScoreWithCache::evaluate_index_with_cache( } else { uv = algebra::get_zero_vector_d<3>(); } - m->add_to_coordinate_derivatives(p[0], uv * sp.second, *da); - m->add_to_coordinate_derivatives(p[1], -uv * sp.second, *da); + m->add_to_coordinate_derivatives(std::get<0>(p), uv * sp.second, *da); + m->add_to_coordinate_derivatives(std::get<1>(p), -uv * sp.second, *da); return sp.first; } else { return ds_.get_score_with_cache(m, p, dist); diff --git a/modules/score_functor/include/SurfaceDistancePairScore.h b/modules/score_functor/include/SurfaceDistancePairScore.h index fb3e7f9d35..225f669f55 100644 --- a/modules/score_functor/include/SurfaceDistancePairScore.h +++ b/modules/score_functor/include/SurfaceDistancePairScore.h @@ -74,9 +74,10 @@ inline double SurfaceDistancePairScore::evaluate_index( DerivativeAccumulator *da) const { algebra::Vector3D delta; // normal vector from surface to point - double dist = get_distance(m->get_sphere(p[0]).get_center(), - internal::get_direction(m, p[0]), - m->get_sphere(p[1]).get_center(), &delta); + double dist = get_distance( + m->get_sphere(std::get<0>(p)).get_center(), + internal::get_direction(m, std::get<0>(p)), + m->get_sphere(std::get<1>(p)).get_center(), &delta); // Using squared distance for trivial check currently doesn't work for surfaces // if (ds_.get_is_trivially_zero(m, p, dist * dist)) { @@ -85,8 +86,8 @@ inline double SurfaceDistancePairScore::evaluate_index( if (da) { std::pair sp = ds_.get_score_and_derivative(m, p, dist); - m->add_to_coordinate_derivatives(p[0], -delta * sp.second, *da); - m->add_to_coordinate_derivatives(p[1], delta * sp.second, *da); + m->add_to_coordinate_derivatives(std::get<0>(p), -delta * sp.second, *da); + m->add_to_coordinate_derivatives(std::get<1>(p), delta * sp.second, *da); return sp.first; } else { return ds_.get_score(m, p, dist);