IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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-2022 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
17IMPSCOREFUNCTOR_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*/
31template <class DistanceScoreT>
32class SurfaceDistancePairScore : public PairScore {
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
47 SurfaceDistancePairScore(
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,
58 DerivativeAccumulator *da) const override;
59
61 Model *m, const ParticleIndexes &pis) const override;
62
63 DistanceScoreT& get_score_functor()
64 { return ds_; }
65
66 IMP_PAIR_SCORE_METHODS(SurfaceDistancePairScore);
67 IMP_OBJECT_METHODS(SurfaceDistancePairScore);
68};
69
70#ifndef IMP_DOXYGEN
71template <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(
78 m->get_sphere(std::get<0>(p)).get_center(),
79 internal::get_direction(m, std::get<0>(p)),
80 m->get_sphere(std::get<1>(p)).get_center(), &delta);
81
82 // Using squared distance for trivial check currently doesn't work for surfaces
83 // if (ds_.get_is_trivially_zero(m, p, dist * dist)) {
84 // return 0;
85 // }
86
87 if (da) {
88 std::pair<double, double> sp = ds_.get_score_and_derivative(m, p, dist);
89 m->add_to_coordinate_derivatives(std::get<0>(p), -delta * sp.second, *da);
90 m->add_to_coordinate_derivatives(std::get<1>(p), delta * sp.second, *da);
91 return sp.first;
92 } else {
93 return ds_.get_score(m, p, dist);
94 }
95}
96
97template <class DistanceScore>
98inline ModelObjectsTemp SurfaceDistancePairScore<
99 DistanceScore>::do_get_inputs(
100 Model *m, const ParticleIndexes &pis) const {
102 ret += ds_.get_inputs(m, pis);
103 return ret;
104}
105#endif
106
107
108//! Create efficient surface height-based pair scores.
109/** This class allows one to create efficient height-based
110 pair scores between a surface and a point in C++ by simply
111 writing a functor (Score) that does the scoring.
112
113 \note In the passed `ParticleIndexPair`, the first particle must
114 be for the surface.
115
116 \see SurfaceDistancePairScore
117 \see DistancePairScore
118 \see Score
119*/
120#if defined(SWIG) || defined(IMP_DOXYGEN)
121template <class DistanceScoreT>
122class SurfaceHeightPairScore : public PairScore {
123 public:
124 SurfaceHeightPairScore(
125 const DistanceScore &t0,
126 std::string name = "FunctorSurfaceHeightPairScore %1%");
127};
128#else
129template <class DistanceScore>
131 DistanceScore> {
132 virtual double get_distance(const algebra::Vector3D &center,
133 const algebra::Vector3D &normal,
134 const algebra::Vector3D &point,
135 algebra::Vector3D *delta) const override {
136 return internal::get_height_above_surface(center, normal, point, delta);
137 }
138 public:
139 SurfaceHeightPairScore(
140 const DistanceScore &t0,
141 std::string name = "FunctorSurfaceHeightPairScore %1%")
142 : SurfaceDistancePairScore<DistanceScore>(t0, name) {}
143};
144#endif
145
146
147//! Create efficient surface depth-based pair scores.
148/** This class allows one to create efficient depth-based
149 pair scores between a surface and a point in C++ by simply
150 writing a functor (Score) that does the scoring.
151
152 \note In the passed `ParticleIndexPair`, the first particle must
153 be for the surface.
154
155 \see SurfaceDistancePairScore
156 \see DistancePairScore
157 \see Score
158*/
159#if defined(SWIG) || defined(IMP_DOXYGEN)
160template <class DistanceScoreT>
161class SurfaceDepthPairScore : public PairScore {
162 public:
163 SurfaceDepthPairScore(
164 const DistanceScore &t0,
165 std::string name = "FunctorSurfaceDepthPairScore %1%");
166};
167#else
168template <class DistanceScore>
170 DistanceScore> {
171 virtual double get_distance(const algebra::Vector3D &center,
172 const algebra::Vector3D &normal,
173 const algebra::Vector3D &point,
174 algebra::Vector3D *delta) const override {
175 return internal::get_depth_below_surface(center, normal, point, delta);
176 }
177 public:
178 SurfaceDepthPairScore(
179 const DistanceScore &t0,
180 std::string name = "FunctorSurfaceDepthPairScore %1%")
181 : SurfaceDistancePairScore<DistanceScore>(t0, name) {}
182};
183#endif
184
185IMPSCOREFUNCTOR_END_NAMESPACE
186
187#endif /* IMPSCORE_FUNCTOR_SURFACE_DISTANCE_PAIR_SCORE_H */
Define PairScore.
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Create efficient surface depth-based pair scores.
Create efficient surface distance-based pair scores.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
virtual double evaluate_index(Model *m, const ParticleIndexPair &pip, DerivativeAccumulator *da) const override
Compute the score and the derivative if needed.
Create efficient surface height-based pair scores.
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
VectorD< 3 > Vector3D
Definition VectorD.h:407
Array< 2, ParticleIndex > ParticleIndexPair
An ordered pair of particles, each identified by its ParticleIndex.
Definition base_types.h:202
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
double get_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the distance between two vectors.
Definition VectorD.h:195
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Macros for various classes.
#define IMP_PAIR_SCORE_METHODS(Name)
Definition pair_macros.h:25