Loading [MathJax]/extensions/tex2jax.js
IMP logo
IMP Reference Guide  develop.ae08f42f4a,2025/04/06
The Integrative Modeling Platform
pair_macros.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-383/imp-20250406.develop.ae08f42f4a/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-383/imp-20250406.develop.ae08f42f4a/tools/build/container_templates/kernel/classname_macros.h
3 // Do not edit - any changes will be lost!
4 
5 /**
6  * \file IMP/pair_macros.h
7  * \brief Macros for various classes.
8  *
9  * Copyright 2007-2025 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPKERNEL_PAIR_MACROS_H
13 #define IMPKERNEL_PAIR_MACROS_H
14 
15 #include "internal/TupleRestraint.h"
16 #include "internal/functors.h"
17 #include "container_macros.h"
18 #include <IMP/object_macros.h>
19 #include <algorithm>
20 
21 /** Define
22  - IMP::PairScore::evaluate_indexes()
23  - IMP::PairScore::evaluate_if_good_indexes()
24  */
25 #define IMP_PAIR_SCORE_METHODS(Name) \
26  double evaluate_indexes(Model *m, const ParticleIndexPairs &p, \
27  DerivativeAccumulator *da, unsigned int lower_bound, \
28  unsigned int upper_bound, \
29  bool all_indexes_checked=false) \
30  const override final { \
31  IMP_UNUSED(all_indexes_checked); \
32  double ret = 0; \
33  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
34  ret += evaluate_index(m, p[i], da); \
35  } \
36  return ret; \
37  } \
38  double evaluate_indexes_scores( \
39  Model *m, const ParticleIndexPairs &p, \
40  DerivativeAccumulator *da, unsigned int lower_bound, \
41  unsigned int upper_bound, \
42  std::vector<double> &score, \
43  bool all_indexes_checked=false) \
44  const override final { \
45  IMP_UNUSED(all_indexes_checked); \
46  double ret = 0; \
47  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
48  double s = evaluate_index(m, p[i], da); \
49  score[i] = s; \
50  ret += s; \
51  } \
52  return ret; \
53  } \
54  double evaluate_indexes_delta( \
55  Model *m, const ParticleIndexPairs &p, \
56  DerivativeAccumulator *da, \
57  const std::vector<unsigned> &indexes, \
58  std::vector<double> &score, \
59  bool all_indexes_checked=false) \
60  const override final { \
61  IMP_UNUSED(all_indexes_checked); \
62  double ret = 0; \
63  for (std::vector<unsigned>::const_iterator it = indexes.begin(); \
64  it != indexes.end(); ++it) { \
65  double s = evaluate_index(m, p[*it], da); \
66  ret = ret - score[*it] + s; \
67  score[*it] = s; \
68  } \
69  return ret; \
70  } \
71  double evaluate_if_good_indexes( \
72  Model *m, const ParticleIndexPairs &p, DerivativeAccumulator *da, \
73  double max, unsigned int lower_bound, \
74  unsigned int upper_bound, \
75  bool all_indexes_checked=false) const override { \
76  IMP_UNUSED(all_indexes_checked); \
77  double ret = 0; \
78  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
79  ret += evaluate_if_good_index(m, p[i], da, max - ret); \
80  if (ret > max) return std::numeric_limits<double>::max(); \
81  } \
82  return ret; \
83  }
84 
85 /** Like IMP_PAIR_SCORE_METHODS but the Evaluate method can be overridden
86  when checks are disabled (it should use the Model, m; the particle
87  index(es), p[i]; and the DerivativeAccumulator, da). Additionally,
88  some one-time unchecked setup can be done. This should be used in
89  combination with an override of check_indexes().
90  */
91 #define IMP_PAIR_SCORE_METHODS_UNCHECKED(Name, Setup, Evaluate) \
92  double evaluate_indexes(Model *m, const ParticleIndexPairs &p, \
93  DerivativeAccumulator *da, unsigned int lower_bound, \
94  unsigned int upper_bound, \
95  bool all_indexes_checked=false) \
96  const override final { \
97  double ret = 0; \
98  if (all_indexes_checked) { \
99  Setup; \
100  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
101  ret += Evaluate; \
102  } \
103  } else { \
104  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
105  ret += evaluate_index(m, p[i], da); \
106  } \
107  } \
108  return ret; \
109  } \
110  double evaluate_indexes_scores( \
111  Model *m, const ParticleIndexPairs &p, \
112  DerivativeAccumulator *da, unsigned int lower_bound, \
113  unsigned int upper_bound, \
114  std::vector<double> &score, \
115  bool all_indexes_checked=false) \
116  const override final { \
117  double ret = 0; \
118  if (all_indexes_checked) { \
119  Setup; \
120  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
121  double s = Evaluate; \
122  score[i] = s; \
123  ret += s; \
124  } \
125  } else { \
126  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
127  double s = evaluate_index(m, p[i], da); \
128  score[i] = s; \
129  ret += s; \
130  } \
131  } \
132  return ret; \
133  } \
134  double evaluate_indexes_delta( \
135  Model *m, const ParticleIndexPairs &p, \
136  DerivativeAccumulator *da, \
137  const std::vector<unsigned> &indexes, \
138  std::vector<double> &score, \
139  bool all_indexes_checked=false) \
140  const override final { \
141  double ret = 0; \
142  if (all_indexes_checked) { \
143  Setup; \
144  for (unsigned int i : indexes) { \
145  double s = Evaluate; \
146  ret = ret - score[i] + s; \
147  score[i] = s; \
148  } \
149  } else { \
150  for (std::vector<unsigned>::const_iterator it = indexes.begin(); \
151  it != indexes.end(); ++it) { \
152  double s = evaluate_index(m, p[*it], da); \
153  ret = ret - score[*it] + s; \
154  score[*it] = s; \
155  } \
156  } \
157  return ret; \
158  } \
159  double evaluate_if_good_indexes( \
160  Model *m, const ParticleIndexPairs &p, DerivativeAccumulator *da, \
161  double max, unsigned int lower_bound, unsigned int upper_bound, \
162  bool all_indexes_checked=false) const override { \
163  IMP_UNUSED(all_indexes_checked); \
164  double ret = 0; \
165  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
166  ret += evaluate_if_good_index(m, p[i], da, max - ret); \
167  if (ret > max) return std::numeric_limits<double>::max(); \
168  } \
169  return ret; \
170  }
171 
172 //! Define extra the functions needed for a PairPredicate
173 #define IMP_PAIR_PREDICATE_METHODS(Name) \
174  int get_value(const ParticlePair& a) const { \
175  return get_value_index(IMP::internal::get_model(a), \
176  IMP::internal::get_index(a)); \
177  } \
178  Ints get_value(const ParticlePairsTemp &o) const { \
179  Ints ret(o.size()); \
180  for (unsigned int i = 0; i < o.size(); ++i) { \
181  ret[i] += Name::get_value(o[i]); \
182  } \
183  return ret; \
184  } \
185  Ints get_value_index(Model *m, const ParticleIndexPairs &o) const override { \
186  Ints ret(o.size()); \
187  for (unsigned int i = 0; i < o.size(); ++i) { \
188  ret[i] += Name::get_value_index(m, o[i]); \
189  } \
190  return ret; \
191  } \
192  IMP_IMPLEMENT_INLINE_NO_SWIG( \
193  void remove_if_equal(Model *m, ParticleIndexPairs &ps, \
194  int value) const, \
195  { \
196  ps.erase( \
197  std::remove_if(ps.begin(), ps.end(), \
198  IMP::internal::PredicateEquals<Name, true>( \
199  this, m, value)), \
200  ps.end()); \
201  }); \
202  IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_not_equal(Model *m, \
203  ParticleIndexPairs &ps, \
204  int value) const, \
205  { \
206  ps.erase( \
207  std::remove_if(ps.begin(), ps.end(), \
208  IMP::internal::PredicateEquals<Name, false>( \
209  this, m, value)), \
210  ps.end()); \
211  });
212 
213 //! Use IMP_PAIR_MODIFIER() instead
214 #define IMP_PAIR_DERIVATIVE_MODIFIER(Name) IMP_PAIR_MODIFIER(Name)
215 
216 /** Define
217  - IMP::PairModifier::apply_indexes()
218 */
219 #define IMP_PAIR_MODIFIER_METHODS(Name) \
220  virtual void apply_indexes(Model *m, const ParticleIndexPairs &o, \
221  unsigned int lower_bound, \
222  unsigned int upper_bound) \
223  const override final { \
224  for (unsigned int i = lower_bound; i < upper_bound; ++i) { \
225  apply_index(m, o[i]); \
226  } \
227  }
228 
229 //! Use IMP_INDEX_PAIR_MODIFIER instead
230 #define IMP_INDEX_PAIR_DERIVATIVE_MODIFIER(Name) \
231  IMP_INDEX_PAIR_MODIFIER(Name)
232 
233 #ifndef IMP_DOXYGEN
234 #define IMP_IMPLEMENT_PAIR_CONTAINER(Name) \
235  IMP_IMPLEMENT_INLINE(void do_apply(const PairModifier *sm) const, \
236  { apply_generic(sm); }); \
237  IMP_IMPLEMENT_INLINE(void do_apply_moved(const PairModifier *sm, \
238  const ParticleIndexes &moved_pis, \
239  const ParticleIndexes &reset_pis) const, \
240  { apply_generic_moved(sm, moved_pis, reset_pis); }); \
241  virtual ParticleIndexes get_all_possible_indexes() const override; \
242  IMP_OBJECT_METHODS(Name)
243 #endif
244 
245 /** Use this to fill in container methods
246  IMP::PairContainer::do_apply()
247  IMP::PairContainer::do_apply_moved()
248 */
249 #define IMP_PAIR_CONTAINER_METHODS(Name) \
250  void do_apply(const PairModifier *sm) const override { \
251  apply_generic(sm); } \
252  void do_apply_moved(const PairModifier *sm, \
253  const ParticleIndexes &moved_pis, \
254  const ParticleIndexes &reset_pis) const override { \
255  apply_generic_moved(sm, moved_pis, reset_pis); }
256 
257 #endif /* IMPKERNEL_PAIR_MACROS_H */
Helper macros for implementing IMP Objects.
Macros to define containers of objects.