IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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
18IMPSCOREFUNCTOR_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. */
24struct ScoreWithCache {
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>
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>
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>
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
89IMPSCOREFUNCTOR_END_NAMESPACE
90
91#endif /* IMPSCORE_FUNCTOR_SCORE_WITH_CACHE_H */
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Basic types used by IMP.
A class to store a fixed array of same-typed values.
Definition Array.h:40
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
std::pair< double, double > DerivativePair
A pair representing a function value with its first derivative.
Definition types.h:22
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition base_types.h:122
Functions and adaptors for dealing with particle indexes.
double get_maximum_range(Model *m, const Array< D, ParticleIndex > &p) const
DerivativePair get_score_and_derivative_with_cache(Model *m, const Array< D, ParticleIndex > &p, double distance) const
Return the score and derivative at the passed feature size (eg distance).
void check_cache_valid(Model *m) const
Make sure the cache is up to date.
ModelObjectsTemp get_inputs(Model *m, const ParticleIndexes &pis) const
bool get_is_trivially_zero_with_cache(Model *m, const Array< D, ParticleIndex > &p, double squared_distance) const
double get_score_with_cache(Model *m, const Array< D, ParticleIndex > &p, double distance) const
Return the score at the passed feature size (eg distance).
Macros to control compiler warnings.
#define IMP_UNUSED(variable)