IMP logo
IMP Reference Guide  2.7.0
The Integrative Modeling Platform
score_functor/SurfaceDistancePairScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/SurfaceDistancePairScore.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_SURFACE_DISTANCE_PAIR_SCORE_H
9 #define IMPSCORE_FUNCTOR_SURFACE_DISTANCE_PAIR_SCORE_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include <IMP/score_functor/internal/surface_helpers.h>
13 #include <IMP/PairScore.h>
14 #include <IMP/pair_macros.h>
15 
16 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
17 
18 //! Create efficient surface distance-based pair scores.
19 /** This class allows one to create efficient distance-based
20  pair scores between a surface and a point in C++ by simply
21  writing a functor (Score) that does the scoring.
22 
23  \note In the passed `ParticleIndexPair`, the first particle must
24  be for the surface.
25 
26  \see SurfaceDistancePairScore
27  \see DistancePairScore
28  \see Score
29 */
30 template <class DistanceScoreT>
32  private:
33  DistanceScoreT ds_;
34 
35  //! Get the distance from the surface to the point.
36  virtual double get_distance(const algebra::Vector3D &center,
37  const algebra::Vector3D &normal,
38  const algebra::Vector3D &point,
39  algebra::Vector3D *delta) const {
40  return internal::get_distance_from_surface(center, normal, point, delta);
41  }
42 
43  public:
44  typedef DistanceScoreT DistanceScore;
45 
47  const DistanceScore &t0,
48  std::string name = "FunctorSurfaceDistancePairScore %1%")
49  : PairScore(name), ds_(t0) {}
50 
51  //! Compute the score and the derivative if needed
52  /** \note In the passed `ParticleIndexPair`, the first particle must
53  be for the surface.
54  */
55  virtual double evaluate_index(Model *m,
56  const ParticleIndexPair &pip,
58 
59  virtual ModelObjectsTemp do_get_inputs(
60  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE;
61 
62  DistanceScoreT& get_score_functor()
63  { return ds_; }
64 
67 };
68 
69 #ifndef IMP_DOXYGEN
70 template <class DistanceScore>
72  Model *m, const ParticleIndexPair &p,
73  DerivativeAccumulator *da) const {
74  algebra::Vector3D delta; // normal vector from surface to point
75 
76  double dist = get_distance(m->get_sphere(p[0]).get_center(),
77  internal::get_surface_normal(m, p[0]),
78  m->get_sphere(p[1]).get_center(), &delta);
79 
80  // Using squared distance for trivial check currently doesn't work for surfaces
81  // if (ds_.get_is_trivially_zero(m, p, dist * dist)) {
82  // return 0;
83  // }
84 
85  if (da) {
86  std::pair<double, double> sp = ds_.get_score_and_derivative(m, p, dist);
87  m->add_to_coordinate_derivatives(p[0], -delta * sp.second, *da);
88  m->add_to_coordinate_derivatives(p[1], delta * sp.second, *da);
89  return sp.first;
90  } else {
91  return ds_.get_score(m, p, dist);
92  }
93 }
94 
95 template <class DistanceScore>
96 inline ModelObjectsTemp SurfaceDistancePairScore<
97  DistanceScore>::do_get_inputs(
98  Model *m, const ParticleIndexes &pis) const {
99  ModelObjectsTemp ret;
100  ret += ds_.get_inputs(m, pis);
101  return ret;
102 }
103 #endif
104 
105 
106 //! Create efficient surface height-based pair scores.
107 /** This class allows one to create efficient height-based
108  pair scores between a surface and a point in C++ by simply
109  writing a functor (Score) that does the scoring.
110 
111  \note In the passed `ParticleIndexPair`, the first particle must
112  be for the surface.
113 
114  \see SurfaceDistancePairScore
115  \see DistancePairScore
116  \see Score
117 */
118 #if defined(SWIG) || defined(IMP_DOXYGEN)
119 template <class DistanceScoreT>
121  public:
123  const DistanceScore &t0,
124  std::string name = "FunctorSurfaceHeightPairScore %1%");
125 };
126 #else
127 template <class DistanceScore>
129  DistanceScore> {
130  virtual double get_distance(const algebra::Vector3D &center,
131  const algebra::Vector3D &normal,
132  const algebra::Vector3D &point,
133  algebra::Vector3D *delta) const IMP_OVERRIDE {
134  return internal::get_height_above_surface(center, normal, point, delta);
135  }
136  public:
137  SurfaceHeightPairScore(
138  const DistanceScore &t0,
139  std::string name = "FunctorSurfaceHeightPairScore %1%")
140  : SurfaceDistancePairScore<DistanceScore>(t0, name) {}
141 };
142 #endif
143 
144 
145 //! Create efficient surface depth-based pair scores.
146 /** This class allows one to create efficient depth-based
147  pair scores between a surface and a point in C++ by simply
148  writing a functor (Score) that does the scoring.
149 
150  \note In the passed `ParticleIndexPair`, the first particle must
151  be for the surface.
152 
153  \see SurfaceDistancePairScore
154  \see DistancePairScore
155  \see Score
156 */
157 #if defined(SWIG) || defined(IMP_DOXYGEN)
158 template <class DistanceScoreT>
160  public:
162  const DistanceScore &t0,
163  std::string name = "FunctorSurfaceDepthPairScore %1%");
164 };
165 #else
166 template <class DistanceScore>
168  DistanceScore> {
169  virtual double get_distance(const algebra::Vector3D &center,
170  const algebra::Vector3D &normal,
171  const algebra::Vector3D &point,
172  algebra::Vector3D *delta) const IMP_OVERRIDE {
173  return internal::get_depth_below_surface(center, normal, point, delta);
174  }
175  public:
176  SurfaceDepthPairScore(
177  const DistanceScore &t0,
178  std::string name = "FunctorSurfaceDepthPairScore %1%")
179  : SurfaceDistancePairScore<DistanceScore>(t0, name) {}
180 };
181 #endif
182 
183 IMPSCOREFUNCTOR_END_NAMESPACE
184 
185 #endif /* IMPSCORE_FUNCTOR_SURFACE_DISTANCE_PAIR_SCORE_H */
Abstract class for scoring object(s) of type ParticleIndexPair.
Definition: PairScore.h:37
Macros for various classes.
Create efficient surface distance-based pair scores.
#define IMP_PAIR_SCORE_METHODS(Name)
Definition: pair_macros.h:25
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Create efficient surface depth-based pair scores.
Create efficient surface height-based pair scores.
A more IMP-like version of the std::vector.
Definition: Vector.h:39
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:82
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Define PairScore.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.