IMP  2.3.1
The Integrative Modeling Platform
score_functor/DistancePairScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/DistancePairScore.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_DISTANCE_PAIR_SCORE_H
9 #define IMPSCORE_FUNCTOR_DISTANCE_PAIR_SCORE_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include <IMP/PairScore.h>
13 #include <IMP/pair_macros.h>
14 
15 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
16 
17 //! Create efficient distance-based pair scores.
18 /** This class allows one to create efficient distance-based
19  pair scores in C++ by simply writing a functor (Score) that
20  does the scoring.
21 
22  \see Score
23 
24  \note we can add arguments to get the list of input
25  particles and containers later, for now the former
26  is assumed to just be the input and the latter empty.
27 */
28 template <class DistanceScoreT>
29 class DistancePairScore : public PairScore {
30  DistanceScoreT ds_;
31 
32  public:
33  typedef DistanceScoreT DistanceScore;
34 
35  // for backwards compat
36  DistancePairScore(const DistanceScore &t0,
37  std::string name = "FunctorDistancePairScore %1%")
38  : PairScore(name), ds_(t0) {}
39 
40  virtual double evaluate_index(kernel::Model *m,
41  const kernel::ParticleIndexPair &pip,
43 
44  virtual kernel::ModelObjectsTemp do_get_inputs(
46 
47  /**
48  return a reference to the functor that is applied on a pair of particles
49  in order to compute their distances
50  */
51  DistanceScoreT& get_score_functor()
52  {return ds_; }
53 
56 };
57 
58 #ifndef IMP_DOXYGEN
59 template <class DistanceScore>
62  DerivativeAccumulator *da) const {
63  algebra::Vector3D delta =
64  m->get_sphere(p[0]).get_center() - m->get_sphere(p[1]).get_center();
65  double sq = delta.get_squared_magnitude();
66  if (ds_.get_is_trivially_zero(m, p, sq)) {
67  return 0;
68  }
69  double dist = std::sqrt(sq);
70  if (da) {
71  std::pair<double, double> sp = ds_.get_score_and_derivative(m, p, dist);
72  static const double MIN_DISTANCE = .00001;
74  if (dist > MIN_DISTANCE) {
75  uv = delta / dist;
76  } else {
77  uv = algebra::get_zero_vector_d<3>();
78  }
79  m->add_to_coordinate_derivatives(p[0], uv * sp.second, *da);
80  m->add_to_coordinate_derivatives(p[1], -uv * sp.second, *da);
81  return sp.first;
82  } else {
83  return ds_.get_score(m, p, dist);
84  }
85 }
86 template <class DistanceScore>
87 inline kernel::ModelObjectsTemp DistancePairScore<DistanceScore>::do_get_inputs(
88  kernel::Model *m, const kernel::ParticleIndexes &pis) const {
90  ret += ds_.get_inputs(m, pis);
91  return ret;
92 }
93 #endif
94 
95 IMPSCOREFUNCTOR_END_NAMESPACE
96 
97 #endif /* IMPSCORE_FUNCTOR_DISTANCE_PAIR_SCORE_H */
Class for adding derivatives from restraints to the model.
Import IMP/kernel/pair_macros.h in the namespace.
IMP::kernel::PairScore PairScore
IMP::base::Vector< IMP::base::WeakPointer< kernel::ModelObject > > ModelObjectsTemp
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
#define IMP_PAIR_SCORE_METHODS(Name)
Create efficient distance-based pair scores.
A class to store an fixed array of same-typed values.
Definition: Array.h:33
Abstract class for scoring object(s) of type ParticlePair.
IMP::kernel::Model Model
Import IMP/kernel/PairScore.h in the namespace.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73