IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
TripletScore.h
Go to the documentation of this file.
1// Autogenerated by tools/build/make_containers.py
2// from tools/build/container_templates/kernel/ClassnameScore.h
3// Do not edit - any changes will be lost!
4
5/**
6 * \file IMP/TripletScore.h
7 * \brief Define TripletScore.
8 *
9 * Copyright 2007-2025 IMP Inventors. All rights reserved.
10 */
11
12#ifndef IMPKERNEL_TRIPLET_SCORE_H
13#define IMPKERNEL_TRIPLET_SCORE_H
14
15#include <IMP/kernel_config.h>
16#include "base_types.h"
18#include "internal/container_helpers.h"
19#include <IMP/utility_macros.h>
20#include <cereal/access.hpp>
21#include <cereal/types/base_class.hpp>
23
24IMPKERNEL_BEGIN_NAMESPACE
25
26//! Abstract class for scoring object(s) of type ParticleIndexTriplet.
27/** TripletScore will evaluate the score and derivatives
28 for passed object(s) of type ParticleIndexTriplet.
29
30 Use in conjunction with various
31 restraints such as IMP::container::TripletsRestraint or
32 IMP::core::TripletRestraint. The restraints couple the score
33 functions with appropriate lists of object(s) of type ParticleIndexTriplet.
34
35 It is possible to call the various evaluate* methods directly, but
36 this is not recommended as they do not ensure that Model invariants
37 (e.g. ScoreStates) are preserved. Use a Restraint or ScoringFunction
38 to score the model instead.
39
40 Implementers should check out IMP_TRIPLET_SCORE_METHODS().
41
42 \see PredicateTripletRestraint
43*/
44class IMPKERNELEXPORT TripletScore : public ParticleInputs,
45 public Object {
46 public:
47 typedef ParticleTriplet Argument;
48 typedef ParticleIndexTriplet IndexArgument;
49 typedef const ParticleTriplet& PassArgument;
50 typedef const ParticleIndexTriplet& PassIndexArgument;
51 typedef TripletModifier Modifier;
52 TripletScore(std::string name = "TripletScore %1%");
53
54 //! Compute the score and the derivative if needed.
55 /** @param m the model of vt
56 @param vt the index in m of an object of type ParticleTriplet
57 @param da a DerivativeAccumulator that weights
58 computed derivatives. If nullptr, derivatives
59 will not be computed.
60 */
61 virtual double evaluate_index(Model *m, const ParticleIndexTriplet& vt,
62 DerivativeAccumulator *da) const = 0;
63
64 //! Check the given particle indexes for necessary attributes
65 /** If implemented, this method should return true and should assert
66 that all particles have all attributes needed to evaluate the score
67 (or raise an exception). After successfully calling this method,
68 evaluate_indexes() and similar methods can be called with
69 all_indexes_checked=true, and can opt to skip these checks. It is the
70 caller's responsibility to call check_indexes() again if the set of
71 possible indexes changes, or particles or attributes are removed.
72 */
73 virtual bool check_indexes(Model *m, const ParticleIndexes &pis) const {
74 IMP_UNUSED(m);
75 IMP_UNUSED(pis);
76 return false;
77 }
78
79 //! Compute the score and the derivative if needed over a set.
80 /** @param m the model of o
81 @param o objects of type ParticleTriplet, specified by index
82 @param da a derivative accumulator that weights
83 computed derivatives. If nullptr, derivatives
84 will not be computed.
85 @param lower_bound index of first item in o to evaluate
86 @param upper_bound index one past last item in o to evaluate
87 @param all_indexes_checked if true, all of the passed indexes
88 have already been checked by check_indexes() for needed particle
89 attributes, so a faster implementation (that doesn't check them
90 again) can be used if available.
91
92 @note An implementation for this is provided by
93 the IMP_TRIPLET_SCORE_METHODS() macro.
94 */
95 virtual double evaluate_indexes(Model *m, const ParticleIndexTriplets &o,
97 unsigned int lower_bound,
98 unsigned int upper_bound,
99 bool all_indexes_checked=false) const;
100
101 //! Compute the score and the derivative if needed over a set.
102 /** Like regular evaluate_indexes(), but the score for each o[x] is also
103 returned as score[x].
104
105 @note An implementation for this is provided by
106 the IMP_TRIPLET_SCORE_METHODS() macro.
107 */
109 Model *m, const ParticleIndexTriplets &o,
111 unsigned int lower_bound,
112 unsigned int upper_bound,
113 std::vector<double> &score,
114 bool all_indexes_checked=false) const;
115
116 //! Compute the change in score and the derivative if needed over a set.
117 /** The score for each o[indexes[x]] is updated in score[indexes[x]]
118 and the total difference between the old and new score values (over the
119 set) is returned.
120
121 @note An implementation for this is provided by
122 the IMP_TRIPLET_SCORE_METHODS() macro.
123 */
125 Model *m, const ParticleIndexTriplets &o,
127 const std::vector<unsigned> &indexes,
128 std::vector<double> &score,
129 bool all_indexes_checked=false) const;
130
131 //! Compute the score and the derivative if needed, only if "good".
132 /** This functions similarly to evaluate_index(),
133 but may terminate the computation early if the score is higher than max.
134
135 @return the score if score<= max or some arbitrary value > max otherwise.
136 */
139 double max) const;
140
141 /** Compute the score and the derivative if needed over a set, only if "good".
142 This functions similarly to evaluate_indexes(), but may terminate
143 the computation early if the total score is higher than max.
144
145 @return the score if score<= max or some arbitrary value > max otherwise.
146
147 @note An implementation for this is provided by
148 the IMP_TRIPLET_SCORE_METHODS() macro.
149 */
151 const ParticleIndexTriplets &o,
152 DerivativeAccumulator *da, double max,
153 unsigned int lower_bound,
154 unsigned int upper_bound,
155 bool all_indexes_checked=false) const;
156
157 //! Decompose this TripletScore into a set of
158 //! currently positive restraints over vt.
159 /** The scoring function and derivatives should
160 be equal to the current score. The default implementation
161 returns a single restraint with this score bound to vt,
162 or zero restraints if the score equals zero.
163 */
165 const ParticleIndexTriplet& vt) const;
166
167 protected:
168 //! Override this to return your own decomposition.
170 const ParticleIndexTriplet& vt) const;
171
172 IMP_REF_COUNTED_DESTRUCTOR(TripletScore);
173
174 private:
175 friend class cereal::access;
176
177 template<class Archive> void serialize(Archive &ar) {
178 // Neither we nor ParticleInputs stores data, but Object does
179 ar(cereal::base_class<Object>(this));
180 }
181};
182
183IMPKERNEL_END_NAMESPACE
184
185#endif /* IMPKERNEL_TRIPLET_SCORE_H */
Class for adding derivatives from restraints to the model.
Basic types used by IMP.
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
Object(std::string name)
Construct an object with the given name.
Base class for objects that take particle arguments and read from them.
A base class for modifiers of ParticleTripletsTemp.
virtual double evaluate_index(Model *m, const ParticleIndexTriplet &vt, DerivativeAccumulator *da) const =0
Compute the score and the derivative if needed.
virtual double evaluate_if_good_indexes(Model *m, const ParticleIndexTriplets &o, DerivativeAccumulator *da, double max, unsigned int lower_bound, unsigned int upper_bound, bool all_indexes_checked=false) const
virtual Restraints do_create_current_decomposition(Model *m, const ParticleIndexTriplet &vt) const
Override this to return your own decomposition.
virtual double evaluate_if_good_index(Model *m, const ParticleIndexTriplet &vt, DerivativeAccumulator *da, double max) const
Compute the score and the derivative if needed, only if "good".
virtual bool check_indexes(Model *m, const ParticleIndexes &pis) const
Check the given particle indexes for necessary attributes.
virtual double evaluate_indexes_scores(Model *m, const ParticleIndexTriplets &o, DerivativeAccumulator *da, unsigned int lower_bound, unsigned int upper_bound, std::vector< double > &score, bool all_indexes_checked=false) const
Compute the score and the derivative if needed over a set.
Restraints create_current_decomposition(Model *m, const ParticleIndexTriplet &vt) const
virtual double evaluate_indexes(Model *m, const ParticleIndexTriplets &o, DerivativeAccumulator *da, unsigned int lower_bound, unsigned int upper_bound, bool all_indexes_checked=false) const
Compute the score and the derivative if needed over a set.
virtual double evaluate_indexes_delta(Model *m, const ParticleIndexTriplets &o, DerivativeAccumulator *da, const std::vector< unsigned > &indexes, std::vector< double > &score, bool all_indexes_checked=false) const
Compute the change in score and the derivative if needed over a set.
Classes used in the construction of ModelObjects.
IMP::Vector< IMP::Pointer< Restraint > > Restraints
Definition base_types.h:120
Array< 3, ParticleIndex > ParticleIndexTriplet
An ordered triplet of particles, each identified by its ParticleIndex.
Definition base_types.h:204
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Definition base_types.h:199
Array< 3, WeakPointer< Particle >, Particle * > ParticleTriplet
Definition base_types.h:183
IMP::Vector< ParticleIndexTriplet, std::allocator< ParticleIndexTriplet > > ParticleIndexTriplets
Definition base_types.h:209
#define IMP_REF_COUNTED_DESTRUCTOR(Name)
Set up destructor for a ref counted object.
Various general useful macros for IMP.
#define IMP_UNUSED(variable)