IMP logo
IMP Reference Guide  2.20.1
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-2022 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 #include <cereal/access.hpp>
22 #include <cereal/types/base_class.hpp>
23 
24 IMPCORE_BEGIN_NAMESPACE
25 
26 //! Apply a function to the distance to a fixed point.
27 /** A particle is scored based on the distance between it and a constant
28  point as passed to a UnaryFunction. This is useful for anchoring
29  constraining particles within a sphere.
30 
31  To restrain a set of particles store in SingletonContainer pc in a sphere
32  do the following:
33  \include core/restrain_in_sphere.py
34  */
35 template <class UF>
39  struct StaticD {
41  StaticD(algebra::Vector3D v) : v_(v) {}
42  Float get_coordinate(unsigned int i) { return v_[i]; }
43  void add_to_derivatives(algebra::Vector3D v, DerivativeAccumulator) {
44  // The fixed point is not a real particle, so derivatives aren't used
45  IMP_UNUSED(v);
46  }
47  };
48 
49  friend class cereal::access;
50 
51  template<class Archive> void serialize(Archive &ar) {
52  ar(cereal::base_class<SingletonScore>(this), f_, pt_);
53  }
55 
56  public:
59  virtual double evaluate_index(Model *m, ParticleIndex p,
60  DerivativeAccumulator *da) const override;
62  Model *m, const ParticleIndexes &pis) const override {
63  return IMP::get_particles(m, pis);
64  }
67  ;
68 };
69 
70 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
71 
72 template <class UF>
74  UF *f, const algebra::Vector3D &v)
75  : f_(f), pt_(v) {}
76 template <class UF>
78  Model *m, ParticleIndex pi,
79  DerivativeAccumulator *da) const {
80  double v = internal::evaluate_distance_pair_score(
81  XYZ(m, pi), StaticD(pt_), da, f_.get(), boost::lambda::_1);
82  IMP_LOG_VERBOSE("DistanceTo from " << XYZ(m, pi) << " to " << pt_
83  << " scored " << v << std::endl);
84  return v;
85 }
86 
87 #endif
88 
89 /** Use an IMP::UnaryFunction to score a distance to a point.*/
90 IMP_GENERIC_OBJECT(DistanceToSingletonScore, distance_to_singleton_score,
91  UnaryFunction,
92  (UnaryFunction *f, const algebra::Vector3D &pt), (f, pt));
93 
94 //! Apply a function to the distance to a fixed point.
95 /** A particle is scored based on the distance between it and a constant
96  point as passed to a UnaryFunction. This is useful for anchoring
97  constraining particles within a sphere.
98 
99  To restrain a set of particles store in SingletonContainer pc in a sphere
100  do the following:
101  \include core/restrain_in_sphere.py
102  */
103 class IMPCOREEXPORT SphereDistanceToSingletonScore : public SingletonScore {
105  algebra::Vector3D pt_;
106  struct StaticD {
108  StaticD(algebra::Vector3D v) : v_(v) {}
109  Float get_coordinate(unsigned int i) { return v_[i]; }
110  void add_to_derivatives(algebra::Vector3D v, DerivativeAccumulator) {
111  // The fixed point is not a real particle, so derivatives aren't used
112  IMP_UNUSED(v);
113  }
114  };
115 
116  public:
118  virtual double evaluate_index(Model *m, ParticleIndex p,
119  DerivativeAccumulator *da) const override;
121  Model *m, const ParticleIndexes &pis) const override {
122  return IMP::get_particles(m, pis);
123  }
126  ;
127 };
128 
129 IMPCORE_END_NAMESPACE
130 
131 #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.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const override
Overload this method to specify the inputs.
Macros for various classes.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
#define IMP_LOG_VERBOSE(expr)
Definition: log_macros.h:83
A more IMP-like version of the std::vector.
Definition: Vector.h:42
Simple XYZ decorator.
#define IMP_GENERIC_OBJECT(Name, lcname, targument, carguments, cparguments)
Typedefs a default instantiation for a generic (templated) object.
Definition: object_macros.h:60
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
#define IMP_UNUSED(variable)
Abstract class for scoring object(s) of type ParticleIndex.
#define IMP_SINGLETON_SCORE_METHODS(Name)
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, ParticleIndex p, DerivativeAccumulator *da) const override
Compute the score and the derivative if needed.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
Definition: object_macros.h:95
Apply a function to the distance to a fixed point.
Define SingletonScore.
A nullptr-initialized pointer to an IMP Object.
VectorD< 3 > Vector3D
Definition: VectorD.h:425
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:19
Simple 3D vector class.
Apply a function to the distance to a fixed point.
Abstract single variable functor class for score functions.
Definition: UnaryFunction.h:27
Class for adding derivatives from restraints to the model.
Compile-time generic restraint and constraint support.