IMP logo
IMP Reference Guide  2.22.0
The Integrative Modeling Platform
ScoreWithCache.h
Go to the documentation of this file.
1 /**
2  * \file IMP/score_functor/ScoreWithCache.h
3  * \brief A Score on the distance between a pair of particles, with cache.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPSCORE_FUNCTOR_SCORE_WITH_CACHE_H
9 #define IMPSCORE_FUNCTOR_SCORE_WITH_CACHE_H
10 
11 #include <IMP/score_functor/score_functor_config.h>
12 #include <IMP/base_types.h>
13 #include <IMP/particle_index.h>
14 #include <IMP/warning_macros.h>
15 #include <IMP/Particle.h>
16 #include <limits>
17 
18 IMPSCOREFUNCTOR_BEGIN_NAMESPACE
19 
20 //! A cached functor for computing a distance based score for D particles.
21 /** This is similar to Score but requires callers to call check_cache_valid()
22  in any scoring function evaluation before any of the methods that use
23  the cache. */
25  // swig gets confused otherwise
26  ScoreWithCache() {}
27 #ifdef IMP_DOXYGEN
28  //! Make sure the cache is up to date.
29  /** This must be called in any scoring function evaluation before any
30  of the methods that use the cache. */
31  void check_cache_valid(Model *m) const;
32 
33  //! Return the score at the passed feature size (eg distance).
34  /** The involved particle indexes are passed along.
35 
36  \pre get_is_trivially_zero_with_cache() or get_maximum_range() has
37  been called and get_is_trivially_zero_with_cache() is false.
38  */
39  template <unsigned int D>
40  double get_score_with_cache(Model *m, const Array<D, ParticleIndex> &p,
41  double distance) const;
42 
43  //! Return the score and derivative at the passed feature size (eg distance).
44  /** The derivative is for the feature decreasing.
45 
46  \pre get_is_trivially_zero_with_cache() or get_maximum_range() has
47  been called and get_is_trivially_zero_with_cache() is false.
48  */
49  template <unsigned int D>
50  DerivativePair get_score_and_derivative_with_cache(
51  Model *m, const Array<D, ParticleIndex> &p,
52  double distance) const;
53 #endif
54 
55  /** Return true if the function can be easily determined to be zero at the
56  passed squared distance. The default implementation provided here
57  returns false.
58 
59  \note That it is squared distance, not distance.
60  */
61  template <unsigned int D>
63  const Array<D, ParticleIndex> &p,
64  double squared_distance) const {
65  IMP_UNUSED(m);
66  IMP_UNUSED(p);
67  IMP_UNUSED(squared_distance);
68  return false;
69  }
70  /** Return an upper bound on the distance at which the score can be
71  non-zero. The default implementation provided here returns infinity. */
72  template <unsigned int D>
74  Model *m, const Array<D, ParticleIndex> &p) const {
75  IMP_UNUSED(m);
76  IMP_UNUSED(p);
77  return std::numeric_limits<double>::infinity();
78  }
79  /** Return the set of particles read when particle p is part of the passed
80  tuples. The default implementation provided here just returns the list
81  containing p. */
83  Model *m, const ParticleIndexes &pis) const {
84  return IMP::get_particles(m, pis);
85  }
86  void show(std::ostream &) const {}
87 };
88 
89 IMPSCOREFUNCTOR_END_NAMESPACE
90 
91 #endif /* IMPSCORE_FUNCTOR_SCORE_WITH_CACHE_H */
double get_maximum_range(Model *m, const Array< D, ParticleIndex > &p) const
Basic types used by IMP.
Functions and adaptors for dealing with particle indexes.
A class to store a fixed array of same-typed values.
Definition: Array.h:40
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
A cached functor for computing a distance based score for D particles.
A more IMP-like version of the std::vector.
Definition: Vector.h:50
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
bool get_is_trivially_zero_with_cache(Model *m, const Array< D, ParticleIndex > &p, double squared_distance) const
Macros to control compiler warnings.
#define IMP_UNUSED(variable)
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition: types.h:22
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
std::ostream & show(Hierarchy h, std::ostream &out=std::cout)
Print the hierarchy using a given decorator to display each node.
ModelObjectsTemp get_inputs(Model *m, const ParticleIndexes &pis) const