Skip to content

Commit

Permalink
Use std::get for crosslink restraint particle indexes
Browse files Browse the repository at this point in the history
Speed up the crosslink restraint in release mode by
moving the bounds checks for ParticleIndexPair from
runtime to compile time.
  • Loading branch information
benmwebb committed Feb 2, 2024
1 parent 2996e8e commit d8deb4c
Showing 1 changed file with 21 additions and 18 deletions.
39 changes: 21 additions & 18 deletions modules/isd/src/CrossLinkMSRestraint.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,25 +52,28 @@ double CrossLinkMSRestraint::get_probability() const {

for (unsigned int k = 0; k < get_number_of_contributions(); ++k) {
IMP::ParticleIndexPair ppi = ppis_[k];
double dist ;
if (ppi[0] != ppi[1]) {
core::XYZ d0(get_model(), ppi[0]), d1(get_model(), ppi[1]);
double dist;
if (std::get<0>(ppi) != std::get<1>(ppi)) {
core::XYZ d0(get_model(), std::get<0>(ppi));
core::XYZ d1(get_model(), std::get<1>(ppi));
dist =
(d0.get_coordinates() - d1.get_coordinates()).get_magnitude();
} else {
// If the residues are assigned to the same particle-domain
// get the distance as if the residue positions were randomly
// taken from within the sphere representing the domain
// Lund O, Protein Eng. 1997 Nov;10(11):1241-8.
double R=core::XYZR(get_model(), ppi[0]).get_radius();
double R=core::XYZR(get_model(), std::get<0>(ppi)).get_radius();
dist=36.0/35.0*R;
}
if (dist<0.0001){dist=0.0001;}
IMP::ParticleIndexPair sigmas = sigmass_[k];
IMP::ParticleIndex psii = psis_[k];
double psi = isd::Scale(get_model(), psii).get_scale();
double sigmai = isd::Scale(get_model(), sigmas[0]).get_scale();
double sigmaj = isd::Scale(get_model(), sigmas[1]).get_scale();
double sigmai = isd::Scale(get_model(),
std::get<0>(sigmas)).get_scale();
double sigmaj = isd::Scale(get_model(),
std::get<1>(sigmas)).get_scale();

double voli = 4.0 / 3.0 * IMP::PI * sigmai * sigmai * sigmai;
double volj = 4.0 / 3.0 * IMP::PI * sigmaj * sigmaj * sigmaj;
Expand Down Expand Up @@ -162,17 +165,17 @@ double CrossLinkMSRestraint::unprotected_evaluate(DerivativeAccumulator *accum)
ModelObjectsTemp CrossLinkMSRestraint::do_get_inputs() const {
ParticlesTemp ret;
for (unsigned int k = 0; k < get_number_of_contributions(); ++k) {
if (ppis_[k][0] == ppis_[k][1]) {
ret.push_back(get_model()->get_particle(ppis_[k][0]));
if (std::get<0>(ppis_[k]) == std::get<1>(ppis_[k])) {
ret.push_back(get_model()->get_particle(std::get<0>(ppis_[k])));
} else {
ret.push_back(get_model()->get_particle(ppis_[k][0]));
ret.push_back(get_model()->get_particle(ppis_[k][1]));
ret.push_back(get_model()->get_particle(std::get<0>(ppis_[k])));
ret.push_back(get_model()->get_particle(std::get<1>(ppis_[k])));
}
if ( sigmass_[k][0] == sigmass_[k][1]) {
ret.push_back(get_model()->get_particle(sigmass_[k][0]));
if (std::get<0>(sigmass_[k]) == std::get<1>(sigmass_[k])) {
ret.push_back(get_model()->get_particle(std::get<0>(sigmass_[k])));
} else {
ret.push_back(get_model()->get_particle(sigmass_[k][0]));
ret.push_back(get_model()->get_particle(sigmass_[k][1]));
ret.push_back(get_model()->get_particle(std::get<0>(sigmass_[k])));
ret.push_back(get_model()->get_particle(std::get<1>(sigmass_[k])));
}
ret.push_back(get_model()->get_particle(psis_[k]));
}
Expand All @@ -191,17 +194,17 @@ RestraintInfo *CrossLinkMSRestraint::get_static_info() const {

ParticleIndexes ps;
for (const auto &sigma : sigmass_) {
ps.push_back(sigma[0]);
ps.push_back(sigma[1]);
ps.push_back(std::get<0>(sigma));
ps.push_back(std::get<1>(sigma));
}
ri->add_particle_indexes("sigmas", ps);

ri->add_particle_indexes("psis", psis_);

ps.clear();
for (const auto &ppi : ppis_) {
ps.push_back(ppi[0]);
ps.push_back(ppi[1]);
ps.push_back(std::get<0>(ppi));
ps.push_back(std::get<1>(ppi));
}
ri->add_particle_indexes("endpoints", ps);

Expand Down

0 comments on commit d8deb4c

Please sign in to comment.