IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
DistanceToSingletonScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/DistanceToSingletonScore.h
3  * \brief A Score on the distance to a fixed point.
4  *
5  * Copyright 2007-2015 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_DISTANCE_TO_SINGLETON_SCORE_H
9 #define IMPCORE_DISTANCE_TO_SINGLETON_SCORE_H
10 
11 #include <IMP/core/core_config.h>
12 #include "XYZ.h"
13 #include "internal/evaluate_distance_pair_score.h"
14 #include <IMP/generic.h>
15 #include <IMP/algebra/Vector3D.h>
16 #include <IMP/SingletonScore.h>
17 #include <IMP/Pointer.h>
18 #include <IMP/singleton_macros.h>
19 #include <IMP/UnaryFunction.h>
20 #include <boost/lambda/lambda.hpp>
21 
22 IMPCORE_BEGIN_NAMESPACE
23 
24 //! Apply a function to the distance to a fixed point.
25 /** A particle is scored based on the distance between it and a constant
26  point as passed to a UnaryFunction. This is useful for anchoring
27  constraining particles within a sphere.
28 
29  To restrain a set of particles store in SingletonContainer pc in a sphere
30  do the following:
31  \include core/restrain_in_sphere.py
32  */
33 template <class UF>
37  struct StaticD {
39  StaticD(algebra::Vector3D v) : v_(v) {}
40  Float get_coordinate(unsigned int i) { return v_[i]; }
41  void add_to_derivatives(algebra::Vector3D v, DerivativeAccumulator) {
42  IMP_UNUSED(v);
43  IMP_WARN("DistanceTo dropped deriv of " << v << std::endl);
44  }
45  };
46 
47  public:
49  virtual double evaluate_index(Model *m, ParticleIndex p,
52  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE {
53  return IMP::get_particles(m, pis);
54  }
57  ;
58 };
59 
60 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
61 
62 template <class UF>
64  UF *f, const algebra::Vector3D &v)
65  : f_(f), pt_(v) {}
66 template <class UF>
68  Model *m, ParticleIndex pi,
69  DerivativeAccumulator *da) const {
70  double v = internal::evaluate_distance_pair_score(
71  XYZ(m, pi), StaticD(pt_), da, f_.get(), boost::lambda::_1);
72  IMP_LOG_VERBOSE("DistanceTo from " << XYZ(m, pi) << " to " << pt_
73  << " scored " << v << std::endl);
74  return v;
75 }
76 
77 #endif
78 
79 /** Use an IMP::UnaryFunction to score a distance to a point.*/
80 IMP_GENERIC_OBJECT(DistanceToSingletonScore, distance_to_singleton_score,
81  UnaryFunction,
82  (UnaryFunction *f, const algebra::Vector3D &pt), (f, pt));
83 
84 //! Apply a function to the distance to a fixed point.
85 /** A particle is scored based on the distance between it and a constant
86  point as passed to a UnaryFunction. This is useful for anchoring
87  constraining particles within a sphere.
88 
89  To restrain a set of particles store in SingletonContainer pc in a sphere
90  do the following:
91  \include core/restrain_in_sphere.py
92  */
93 class IMPCOREEXPORT SphereDistanceToSingletonScore : public SingletonScore {
96  struct StaticD {
98  StaticD(algebra::Vector3D v) : v_(v) {}
99  Float get_coordinate(unsigned int i) { return v_[i]; }
100  void add_to_derivatives(algebra::Vector3D v, DerivativeAccumulator) {
101  IMP_UNUSED(v);
102  IMP_LOG_VERBOSE("DistanceTo dropped deriv of " << v << std::endl);
103  }
104  };
105 
106  public:
108  virtual double evaluate_index(Model *m, ParticleIndex p,
111  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE {
112  return IMP::get_particles(m, pis);
113  }
116  ;
117 };
118 
119 IMPCORE_END_NAMESPACE
120 
121 #endif /* IMPCORE_DISTANCE_TO_SINGLETON_SCORE_H */
GenericDistanceToSingletonScore< UnaryFunction > DistanceToSingletonScore
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Single variable function.
Macros for various classes.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
#define IMP_LOG_VERBOSE(expr)
Definition: log_macros.h:94
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Simple XYZ decorator.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
#define IMP_WARN(expr)
Write a warning to a log.
Definition: log_macros.h:66
#define IMP_UNUSED(variable)
Abstract class for scoring object(s) of type ParticleIndex.
#define IMP_SINGLETON_SCORE_METHODS(Name)
Apply a function to the distance to a fixed point.
Define SingletonScore.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
A nullptr-initialized pointer to an IMP Object.
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Simple 3D vector class.
Apply a function to the distance to a fixed point.
virtual double evaluate_index(Model *m, ParticleIndex p, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
Abstract single variable functor class for score functions.
Definition: UnaryFunction.h:25
#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.
Various important functionality for implementing decorators.