IMP logo
IMP Reference Guide  2.14.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-2020 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/score_functor/internal/direction_helpers.h>
14 #include <IMP/PairScore.h>
15 #include <IMP/pair_macros.h>
16 
17 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
18 
19 //! Create efficient surface distance-based pair scores.
20 /** This class allows one to create efficient distance-based
21  pair scores between a surface and a point in C++ by simply
22  writing a functor (Score) that does the scoring.
23 
24  \note In the passed `ParticleIndexPair`, the first particle must
25  be for the surface.
26 
27  \see SurfaceDistancePairScore
28  \see DistancePairScore
29  \see Score
30 */
31 template <class DistanceScoreT>
33  private:
34  DistanceScoreT ds_;
35 
36  //! Get the distance from the surface to the point.
37  virtual double get_distance(const algebra::Vector3D &center,
38  const algebra::Vector3D &normal,
39  const algebra::Vector3D &point,
40  algebra::Vector3D *delta) const {
41  return internal::get_distance_from_surface(center, normal, point, delta);
42  }
43 
44  public:
45  typedef DistanceScoreT DistanceScore;
46 
48  const DistanceScore &t0,
49  std::string name = "FunctorSurfaceDistancePairScore %1%")
50  : PairScore(name), ds_(t0) {}
51 
52  //! Compute the score and the derivative if needed
53  /** \note In the passed `ParticleIndexPair`, the first particle must
54  be for the surface.
55  */
56  virtual double evaluate_index(Model *m,
57  const ParticleIndexPair &pip,
59 
60  virtual ModelObjectsTemp do_get_inputs(
61  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE;
62 
63  DistanceScoreT& get_score_functor()
64  { return ds_; }
65 
68 };
69 
70 #ifndef IMP_DOXYGEN
71 template <class DistanceScore>
73  Model *m, const ParticleIndexPair &p,
74  DerivativeAccumulator *da) const {
75  algebra::Vector3D delta; // normal vector from surface to point
76 
77  double dist = get_distance(m->get_sphere(p[0]).get_center(),
78  internal::get_direction(m, p[0]),
79  m->get_sphere(p[1]).get_center(), &delta);
80 
81  // Using squared distance for trivial check currently doesn't work for surfaces
82  // if (ds_.get_is_trivially_zero(m, p, dist * dist)) {
83  // return 0;
84  // }
85 
86  if (da) {
87  std::pair<double, double> sp = ds_.get_score_and_derivative(m, p, dist);
88  m->add_to_coordinate_derivatives(p[0], -delta * sp.second, *da);
89  m->add_to_coordinate_derivatives(p[1], delta * sp.second, *da);
90  return sp.first;
91  } else {
92  return ds_.get_score(m, p, dist);
93  }
94 }
95 
96 template <class DistanceScore>
97 inline ModelObjectsTemp SurfaceDistancePairScore<
98  DistanceScore>::do_get_inputs(
99  Model *m, const ParticleIndexes &pis) const {
100  ModelObjectsTemp ret;
101  ret += ds_.get_inputs(m, pis);
102  return ret;
103 }
104 #endif
105 
106 
107 //! Create efficient surface height-based pair scores.
108 /** This class allows one to create efficient height-based
109  pair scores between a surface and a point in C++ by simply
110  writing a functor (Score) that does the scoring.
111 
112  \note In the passed `ParticleIndexPair`, the first particle must
113  be for the surface.
114 
115  \see SurfaceDistancePairScore
116  \see DistancePairScore
117  \see Score
118 */
119 #if defined(SWIG) || defined(IMP_DOXYGEN)
120 template <class DistanceScoreT>
122  public:
124  const DistanceScore &t0,
125  std::string name = "FunctorSurfaceHeightPairScore %1%");
126 };
127 #else
128 template <class DistanceScore>
130  DistanceScore> {
131  virtual double get_distance(const algebra::Vector3D &center,
132  const algebra::Vector3D &normal,
133  const algebra::Vector3D &point,
134  algebra::Vector3D *delta) const IMP_OVERRIDE {
135  return internal::get_height_above_surface(center, normal, point, delta);
136  }
137  public:
138  SurfaceHeightPairScore(
139  const DistanceScore &t0,
140  std::string name = "FunctorSurfaceHeightPairScore %1%")
141  : SurfaceDistancePairScore<DistanceScore>(t0, name) {}
142 };
143 #endif
144 
145 
146 //! Create efficient surface depth-based pair scores.
147 /** This class allows one to create efficient depth-based
148  pair scores between a surface and a point in C++ by simply
149  writing a functor (Score) that does the scoring.
150 
151  \note In the passed `ParticleIndexPair`, the first particle must
152  be for the surface.
153 
154  \see SurfaceDistancePairScore
155  \see DistancePairScore
156  \see Score
157 */
158 #if defined(SWIG) || defined(IMP_DOXYGEN)
159 template <class DistanceScoreT>
161  public:
163  const DistanceScore &t0,
164  std::string name = "FunctorSurfaceDepthPairScore %1%");
165 };
166 #else
167 template <class DistanceScore>
169  DistanceScore> {
170  virtual double get_distance(const algebra::Vector3D &center,
171  const algebra::Vector3D &normal,
172  const algebra::Vector3D &point,
173  algebra::Vector3D *delta) const IMP_OVERRIDE {
174  return internal::get_depth_below_surface(center, normal, point, delta);
175  }
176  public:
177  SurfaceDepthPairScore(
178  const DistanceScore &t0,
179  std::string name = "FunctorSurfaceDepthPairScore %1%")
180  : SurfaceDistancePairScore<DistanceScore>(t0, name) {}
181 };
182 #endif
183 
184 IMPSCOREFUNCTOR_END_NAMESPACE
185 
186 #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:86
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Define PairScore.
VectorD< 3 > Vector3D
Definition: VectorD.h:421
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.