IMP  2.0.1
The Integrative Modeling Platform
SphereDistancePairScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/SphereDistancePairScore.h
3  * \brief A score on the distance between the surfaces of two spheres.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_SPHERE_DISTANCE_PAIR_SCORE_H
9 #define IMPCORE_SPHERE_DISTANCE_PAIR_SCORE_H
10 
11 #include <IMP/core/core_config.h>
12 #include "XYZR.h"
20 
21 IMPCORE_BEGIN_NAMESPACE
22 
23 // needed to keep swig from getting confused or breaking line
24 // lengths
25 typedef score_functor::SphereDistance<score_functor::UnaryFunctionEvaluate>
26 SphereDistanceScore;
27 
28 //! A score on the distance between the surfaces of two spheres.
29 /** \see XYZR
30  \see SphereDistancePairScore
31  \see DistancePairScore
32  \see SoftSpherePairScore
33  */
34 IMP_FUNCTOR_DISTANCE_PAIR_SCORE(SphereDistancePairScore,
35  SphereDistanceScore,
36  (UnaryFunction *uf,
37  std::string name
38  ="SphereDistancePairScore%1%"),
40 
41 
45 
46 
47 //!A harmonic upper bound on the distance between two spheres
48 /** \see XYZR
49  \see SpherePairScore
50  \see SoftSpherePairScore
51  */
52 IMP_FUNCTOR_DISTANCE_PAIR_SCORE(HarmonicUpperBoundSphereDistancePairScore,
53  HarmonicUpperBoundSphereDistanceScore,
54  (double x0, double k,
55  std::string name
56  ="HarmonicUpperBoundSphereDistancePairScore%1%"),
60 
61 //!A harmonic upper bound on the diameter of the span of two spheres
62 /** This restraint restraints how far the furthest points of two spheres
63  are from one another.
64 
65  \see XYZR
66  \see SpherePairScore
67  \see SoftSpherePairScore
68  \see NormalizedSphereDistancePairScore
69  */
71 {
72  double x0_, k_;
73 public:
74  HarmonicUpperBoundSphereDiameterPairScore(double d0, double k);
75  double get_rest_length() const {
76  return x0_;
77  }
78  double get_stiffness() const {
79  return k_;
80  }
82 };
83 
86 
87 
88 
89 
93 
94 
95 //!A harmonic score on the distance between two spheres
96 /** \see XYZR
97  \see SpherePairScore
98  \see SoftSpherePairScore
99  */
100 IMP_FUNCTOR_DISTANCE_PAIR_SCORE(HarmonicSphereDistancePairScore,
101  HarmonicSphereDistanceScore,
102  (double x0, double k,
103  std::string name
104  ="HarmonicSphereDistancePairScore%1%"),
107 
108 
109 
110 
111 #ifndef IMP_DOXYGEN
112 inline double
113 HarmonicUpperBoundSphereDiameterPairScore::evaluate_index(Model *m,
114  const ParticleIndexPair& p,
115  DerivativeAccumulator *da) const {
116  algebra::Vector3D delta=m->get_sphere(p[0]).get_center()
117  - m->get_sphere(p[1]).get_center();
118  static const double MIN_DISTANCE = .00001;
119  double distance= delta.get_magnitude();
120  double shifted_distance = distance- x0_
121  + m->get_sphere(p[0]).get_radius()
122  + m->get_sphere(p[1]).get_radius();
123  if (shifted_distance < 0) return 0;
124  double score= .5*k_*square(shifted_distance);
125  if (da && distance > MIN_DISTANCE) {
126  double deriv= k_*shifted_distance;
127  algebra::Vector3D uv= delta/distance;
128  m->add_to_coordinate_derivatives(p[0], uv*deriv, *da);
129  m->add_to_coordinate_derivatives(p[1], -uv*deriv, *da);
130  }
131  return score;
132 }
133 #endif
134 
135 //! A score on the normalized distance between the surfaces of two spheres
136 /** The distance between the surfaces of the two spheres is divided by the
137  smaller radius to normalize it.
138  \see SphereDistancePairScore
139  \see XYZR
140  \see DistancePairScore
141  */
142 class IMPCOREEXPORT NormalizedSphereDistancePairScore : public PairScore
143 {
144  IMP::OwnerPointer<UnaryFunction> f_;
145  FloatKey radius_;
146 public:
148  FloatKey radius=FloatKey("radius"));
150 };
151 
152 
153 //! A score on a weighted distance between the surfaces of two spheres
154 /** The distance between the surfaces of the two spheres is multiplied by
155  the sum of a specific attribute
156  \see SphereDistancePairScore
157  \see XYZR
158  \see DistancePairScore
159  */
160 class IMPCOREEXPORT WeightedSphereDistancePairScore : public PairScore
161 {
162  IMP::OwnerPointer<UnaryFunction> f_;
163  FloatKey radius_;
164  FloatKey weight_;
165 public:
167  FloatKey weight,
168  FloatKey radius=FloatKey("radius"));
170 };
171 
172 
175 
176 /** This class is equivalent to, but faster than a
177  SphereDistancePairScore with a HarmonicLowerBound.
178 */
179 IMP_FUNCTOR_DISTANCE_PAIR_SCORE(SoftSpherePairScore,
180  SoftSphereDistanceScore,
181  (double k,
182  std::string name
183  ="SoftSpherePairScore%1%"),
185 
186 
187 IMPCORE_END_NAMESPACE
188 
189 #endif /* IMPCORE_SPHERE_DISTANCE_PAIR_SCORE_H */