IMP logo
IMP Reference Guide  2.8.0
The Integrative Modeling Platform
SphereDistance.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/SphereDistance.h
3  * \brief A Score on the distance between a pair of particles.
4  *
5  * Copyright 2007-2017 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPSCORE_FUNCTOR_SPHERE_DISTANCE_H
9 #define IMPSCORE_FUNCTOR_SPHERE_DISTANCE_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include <IMP/Model.h>
13 #include <IMP/algebra/utility.h>
14 #include <IMP/check_macros.h>
15 
16 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
17 
18 /** Transform the center distance to the sphere distance
19  and pass it off to BaseDistanceScore.*/
20 template <class BaseDistanceScore>
21 class SphereDistance : public BaseDistanceScore {
22  /* Caching the rsum makes things 30% faster with a linear score, but
23  doesn't work in non-trivial cases (eg AddScores where get_maximum_range()
24  isn't necessarily called first). I don't see how to fix the nontrivial
25  cases and, since they are the point of this module, disabled it.*/
26  typedef BaseDistanceScore P;
27  static double get_rsum(Model *m,
28  const ParticleIndexPair &pi) {
29  return m->get_sphere(pi[0]).get_radius() +
30  m->get_sphere(pi[1]).get_radius();
31  }
32 
33  public:
34  SphereDistance(BaseDistanceScore base) : P(base) {}
35  double get_score(Model *m, const ParticleIndexPair &pi,
36  double distance) const {
37  return P::get_score(m, pi, distance - get_rsum(m, pi));
38  }
39  DerivativePair get_score_and_derivative(Model *m,
40  const ParticleIndexPair &pi,
41  double distance) const {
42  return P::get_score_and_derivative(m, pi, distance - get_rsum(m, pi));
43  }
44  double get_maximum_range(Model *m,
45  const ParticleIndexPair &pi) const {
46  return P::get_maximum_range(m, pi) + get_rsum(m, pi);
47  }
48  bool get_is_trivially_zero(Model *m,
49  const ParticleIndexPair &pi,
50  double squared_distance) const {
51  return squared_distance >
52  algebra::get_squared(P::get_maximum_range(m, pi) + get_rsum(m, pi));
53  }
54 };
55 
56 IMPSCOREFUNCTOR_END_NAMESPACE
57 
58 #endif /* IMPSCORE_FUNCTOR_SPHERE_DISTANCE_H */
Storage of a model, its restraints, constraints and particles.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Functions to deal with very common math operations.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:23
Exception definitions and assertions.