IMP  2.2.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-2014 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/kernel/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(kernel::Model *m,
28  const kernel::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(kernel::Model *m, const kernel::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(kernel::Model *m,
40  const kernel::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(kernel::Model *m,
45  const kernel::ParticleIndexPair &pi) const {
46  return P::get_maximum_range(m, pi) + get_rsum(m, pi);
47  }
48  bool get_is_trivially_zero(kernel::Model *m,
49  const kernel::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 */
A class to store an fixed array of same-typed values.
Definition: base/Array.h:33
Functions to deal with very common math operations.
Storage of a model, its restraints, constraints and particles.
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: base/types.h:23
Exception definitions and assertions.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72