IMP  2.0.1
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-2013 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/base/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 public:
33  SphereDistance(BaseDistanceScore base):
34  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, const ParticleIndexPair&pi,
40  double distance) const {
41  return P::get_score_and_derivative(m, pi, distance-get_rsum(m, pi));
42  }
43  double get_maximum_range(Model *m, const ParticleIndexPair& pi) const {
44  return P::get_maximum_range(m, pi) + get_rsum(m, pi);
45  }
46  bool get_is_trivially_zero(Model *m, const ParticleIndexPair& pi,
47  double squared_distance) const {
48  return squared_distance
49  > algebra::get_squared(P::get_maximum_range(m, pi) + get_rsum(m, pi));
50  }
51 };
52 
53 IMPSCOREFUNCTOR_END_NAMESPACE
54 
55 #endif /* IMPSCORE_FUNCTOR_SPHERE_DISTANCE_H */