IMP  2.0.0
The Integrative Modeling Platform
kernel/pair_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/pair_macros.h
3  * \brief Macros for various classes.
4  *
5  * This file is generated by a script (core/tools/make-containers).
6  * Do not edit directly.
7  *
8  * Copyright 2007-2013 IMP Inventors. All rights reserved.
9  */
10 
11 #ifndef IMPKERNEL_PAIR_MACROS_H
12 #define IMPKERNEL_PAIR_MACROS_H
13 
14 #include "internal/TupleRestraint.h"
15 #include "internal/functors.h"
16 #include "container_macros.h"
17 #include "input_output_macros.h"
18 #include <algorithm>
19 
20 
21 //! Declare the functions needed for a PairScore
22 /** In addition to the methods done by IMP_INTERACTON, it declares
23  - IMP::PairScore::evaluate(IMP::Particle*,
24  IMP::DerivativeAccumulator*)
25  - IMP::PairScore::get_input_particles()
26  - IMP::PairScore::get_output_particles()
27 
28  See IMP_SIMPLE_PAIR_SCORE() for a way of providing an
29  implementation of that method.
30 */
31 #define IMP_PAIR_SCORE(Name) \
32  IMP_IMPLEMENT(double evaluate(const ParticlePair& p,\
33  DerivativeAccumulator *da) const); \
34  IMP_IMPLEMENT_INLINE(double evaluate_index(Model *m, \
35  const ParticleIndexPair& p, \
36  DerivativeAccumulator *da) const, { \
37  return evaluate(IMP::kernel::internal::get_particle(m,p), da); \
38  }); \
39  IMP_IMPLEMENT_INLINE(double evaluate_if_good_index(Model *m, \
40  const ParticleIndexPair& p, \
41  DerivativeAccumulator *da, \
42  double max) const, { \
43  IMP_UNUSED(max); \
44  return evaluate_index(m, p, da); \
45  }); \
46  IMP_BACKWARDS_MACRO_INPUTS; \
47  IMP_OBJECT(Name)
48 
49 //! Declare the functions needed for a PairScore
50 /** In addition to the methods declared and defined by IMP_PAIR_SCORE,
51  the macro provides an implementation of
52  - IMP::PairScore::get_input_particles()
53  - IMP::PairScore::get_input_containers()
54  which assume that only the passed particle serves as input to the
55  score.
56 */
57 #define IMP_SIMPLE_PAIR_SCORE(Name) \
58  IMP_IMPLEMENT(double evaluate(const ParticlePair& p, \
59  DerivativeAccumulator *da) const); \
60  IMP_IMPLEMENT_INLINE(ModelObjectsTemp \
61  do_get_inputs(Model *m, \
62  const ParticleIndexes &pis) const, { \
63  ModelObjectsTemp ret; \
64  ret+=IMP::kernel::get_particles(m, pis); \
65  return ret; \
66  }); \
67  IMP_IMPLEMENT_INLINE(Restraints do_create_current_decomposition \
68  (Model *m, \
69  const ParticleIndexPair& vt) const, { \
70  return IMP::kernel::internal \
71  ::create_score_current_decomposition(this, m, vt); \
72  }); \
73  IMP_OBJECT(Name)
74 
75 
76 
77 //! Declare the functions needed for a complex PairScore
78 /** In addition to the methods done by IMP_OBJECT(), it declares
79  - IMP::PairScore::evaluate_index()
80  - IMP::PairScore::do_get_inputs()
81  - IMP::PairScore::evaluate_if_good_index()
82 */
83 #define IMP_COMPOSITE_PAIR_SCORE(Name) \
84  IMP_IMPLEMENT_INLINE(double evaluate(const ParticlePair& p, \
85  DerivativeAccumulator *da) const, { \
86  return evaluate_index(IMP::kernel::internal::get_model(p), \
87  IMP::kernel::internal::get_index(p), da); \
88  }); \
89  IMP_IMPLEMENT(double evaluate_index(Model *m, const ParticleIndexPair& p,\
90  DerivativeAccumulator *da) const); \
91  IMP_IMPLEMENT(double evaluate_if_good_index(Model *m, \
92  const ParticleIndexPair& p, \
93  DerivativeAccumulator *da, \
94  double max) const); \
95  IMP_IMPLEMENT_INLINE(double evaluate_indexes(Model *m, \
96  const ParticleIndexPairs &p, \
97  DerivativeAccumulator *da, \
98  unsigned int lower_bound, \
99  unsigned int upper_bound) const,\
100  { \
101  double ret=0; \
102  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
103  ret+= evaluate_index(m, p[i], da); \
104  } \
105  return ret; \
106  }); \
107  IMP_IMPLEMENT_INLINE(double \
108  evaluate_if_good_indexes(Model *m, \
109  const ParticleIndexPairs &p, \
110  DerivativeAccumulator *da, \
111  double max, \
112  unsigned int lower_bound, \
113  unsigned int upper_bound) const, { \
114  double ret=0; \
115  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
116  ret+= evaluate_if_good_index(m, p[i], da, max-ret); \
117  if (ret>max) return std::numeric_limits<double>::max(); \
118  } \
119  return ret; \
120  }); \
121  IMP_IMPLEMENT(ModelObjectsTemp \
122  do_get_inputs(Model *m, \
123  const ParticleIndexes &pis) const ); \
124  IMP_OBJECT(Name)
125 
126 //! Declare the functions needed for a complex PairScore
127 /** In addition to the methods done by IMP_OBJECT(), it declares
128  - IMP::PairScore::evaluate()
129  - IMP::PairScore::get_input_particles()
130  - IMP::PairScore::get_output_particles()
131  - IMP::PairScore::evaluate_if_good
132 */
133 #define IMP_INDEX_PAIR_SCORE(Name) \
134  IMP_IMPLEMENT_INLINE(double evaluate(const ParticlePair& p,\
135  DerivativeAccumulator *da) const, { \
136  return evaluate_index(IMP::kernel::internal::get_model(p), \
137  IMP::kernel::internal::get_index(p), \
138  da); \
139  }); \
140  IMP_IMPLEMENT(double evaluate_index(Model *m, const ParticleIndexPair& p,\
141  DerivativeAccumulator *da) \
142  const IMP_FINAL); \
143  IMP_IMPLEMENT_INLINE(double evaluate_if_good_index(Model *m, \
144  const ParticleIndexPair& p, \
145  DerivativeAccumulator *da, \
146  double max) const, { \
147  IMP_UNUSED(max); \
148  return evaluate_index(m, p, da); \
149  }); \
150  IMP_IMPLEMENT_INLINE(double \
151  evaluate_indexes(Model *m, \
152  const ParticleIndexPairs &p, \
153  DerivativeAccumulator *da, \
154  unsigned int lower_bound, \
155  unsigned int upper_bound) const IMP_FINAL, \
156  { \
157  double ret=0; \
158  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
159  ret+= evaluate_index(m, p[i], da); \
160  } \
161  return ret; \
162  }); \
163  IMP_IMPLEMENT_INLINE(double \
164  evaluate_if_good_indexes(Model *m, \
165  const ParticleIndexPairs &p, \
166  DerivativeAccumulator *da, \
167  double max, \
168  unsigned int lower_bound, \
169  unsigned int upper_bound) const, { \
170  double ret=0; \
171  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
172  ret+= evaluate_if_good_index(m, p[i], da, max-ret); \
173  if (ret>max) return std::numeric_limits<double>::max(); \
174  } \
175  return ret; \
176  }); \
177  IMP_IMPLEMENT(ModelObjectsTemp \
178  do_get_inputs(Model *m, \
179  const ParticleIndexes &pis) const); \
180  IMP_OBJECT(Name)
181 
182 
183 
184 //! Declare the functions needed for a PairPredicate
185 /** In addition to the methods done by IMP_OBJECT, it declares
186  - IMP::PairPredicate::get_value()
187  - IMP::PairPredicate::get_input_particles()
188  - IMP::PairPredicate::get_output_particles()
189 */
190 #define IMP_PAIR_PREDICATE(Name) \
191  IMP_IMPLEMENT(int get_value(const ParticlePair& a) const); \
192  IMP_IMPLEMENT_INLINE(Ints get_value(const \
193  ParticlePairsTemp &o) const, { \
194  Ints ret(o.size()); \
195  for (unsigned int i=0; i< o.size(); ++i) { \
196  ret[i]+= Name::get_value(o[i]); \
197  } \
198  return ret; \
199  }); \
200  IMP_IMPLEMENT_INLINE(int get_value_index(Model *m, \
201  const ParticleIndexPair& vt)\
202  const, { \
203  return Name::get_value(IMP::kernel::internal::get_particle(m, vt)); \
204  }); \
205  IMP_IMPLEMENT_INLINE(Ints get_value_index(Model *m, \
206  const ParticleIndexPairs &o) const, { \
207  Ints ret(o.size()); \
208  for (unsigned int i=0; i< o.size(); ++i) { \
209  ret[i]+= Name::get_value_index(m, o[i]); \
210  } \
211  return ret; \
212  }); \
213  IMP_BACKWARDS_MACRO_INPUTS; \
214  IMP_OBJECT(Name)
215 
216 
217 //! Declare the functions needed for a PairPredicate
218 /** In addition to the methods done by IMP_OBJECT, it defines
219  - IMP::PairPredicate::get_value_index() based on the return_value
220  parameter
221  - IMP::PairPredicate::do_get_inputs() based on the return_inputs
222  parameter
223 */
224 #define IMP_INDEX_PAIR_PREDICATE(Name, return_value, return_inputs) \
225  IMP_IMPLEMENT_INLINE(int get_value(const ParticlePair& a) const, { \
226  return get_value_index(IMP::kernel::internal::get_model(a), \
227  IMP::kernel::internal::get_index(a)); \
228  }); \
229  IMP_IMPLEMENT_INLINE(Ints get_value(const \
230  ParticlePairsTemp &o) const, { \
231  Ints ret(o.size()); \
232  for (unsigned int i=0; i< o.size(); ++i) { \
233  ret[i]+= Name::get_value(o[i]); \
234  } \
235  return ret; \
236  }) \
237  IMP_IMPLEMENT_INLINE(int get_value_index(Model *m, \
238  const ParticleIndexPair& pi)\
239  const, { \
240  return_value; \
241  }) \
242  IMP_IMPLEMENT_INLINE(Ints get_value_index(Model *m, \
243  const ParticleIndexPairs &o) const, { \
244  Ints ret(o.size()); \
245  for (unsigned int i=0; i< o.size(); ++i) { \
246  ret[i]+= Name::get_value_index(m, o[i]); \
247  } \
248  return ret; \
249  }); \
250  IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_equal(Model *m, \
251  ParticleIndexPairs& ps, \
252  int value) const, { \
253  ps.erase(std::remove_if(ps.begin(), ps.end(), \
254  IMP::kernel::internal::PredicateEquals<Name, true>(this, \
255  m, value)), \
256  ps.end()); \
257  }); \
258  IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_not_equal(Model *m, \
259  ParticleIndexPairs& ps, \
260  int value) const, { \
261  ps.erase(std::remove_if(ps.begin(), ps.end(), \
262  IMP::kernel::internal::PredicateEquals<Name, false>(this, \
263  m, value)), \
264  ps.end()); \
265  }); \
266  IMP_IMPLEMENT_INLINE(ModelObjectsTemp \
267  do_get_inputs(Model *m, \
268  const ParticleIndexes &pi) const, { \
269  return_inputs; \
270  }); \
271  IMP_OBJECT_INLINE(Name,IMP_UNUSED(out),)
272 
273 
274 //! Declare the functions needed for a PairModifier
275 /** In addition to the methods done by IMP_OBJECT, it declares
276  - IMP::PairModifier::apply(IMP::Particle*)
277  - IMP::PairModifier::get_input_particles()
278  - IMP::PairModifier::get_output_particles()
279 */
280 #define IMP_PAIR_MODIFIER(Name) \
281  IMP_IMPLEMENT(void apply(const ParticlePair& a) const); \
282  IMP_IMPLEMENT_INLINE(void apply_index(Model *m, \
283  const ParticleIndexPair& a) const, {\
284  return Name::apply(IMP::kernel::internal::get_particle(m,a)); \
285  }) \
286  IMP_BACKWARDS_MACRO_INPUTS; \
287  IMP_BACKWARDS_MACRO_OUTPUTS; \
288  IMP_OBJECT(Name)
289 
290 //! Use IMP_PAIR_MODIFIER() instead
291 #define IMP_PAIR_DERIVATIVE_MODIFIER(Name) \
292  IMP_PAIR_MODIFIER(Name)
293 
294 
295 //! Declare the functions needed for a PairModifier
296 /** In addition to the methods done by IMP_OBJECT, it declares
297  - IMP::PairModifier::apply(IMP::Particle*)
298  - IMP::PairModifier::get_inputs()
299  - IMP::PairModifier::get_outputs()
300 */
301 #define IMP_INDEX_PAIR_MODIFIER(Name) \
302  IMP_IMPLEMENT_INLINE(void apply(const ParticlePair& a) const, { \
303  apply_index(IMP::kernel::internal::get_model(a), \
304  IMP::kernel::internal::get_index(a)); \
305  }); \
306  IMP_IMPLEMENT(void apply_index(Model *m, \
307  const ParticleIndexPair& a)\
308  const IMP_FINAL); \
309  IMP_IMPLEMENT_INLINE(void apply_indexes(Model *m, \
310  const ParticleIndexPairs &o, \
311  unsigned int lower_bound, \
312  unsigned int upper_bound)\
313  const IMP_FINAL, \
314  { \
315  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
316  apply_index(m, o[i]); \
317  } \
318  }); \
319  IMP_IMPLEMENT(ModelObjectsTemp do_get_inputs(Model *m, \
320  const ParticleIndexes &pis) const); \
321  IMP_IMPLEMENT(ModelObjectsTemp do_get_outputs(Model *m, \
322  const ParticleIndexes &pis) const); \
323  IMP_OBJECT(Name)
324 
325 //! Use IMP_INDEX_PAIR_MODIFIER instead
326 #define IMP_INDEX_PAIR_DERIVATIVE_MODIFIER(Name) \
327  IMP_INDEX_PAIR_MODIFIER(Name)
328 
329 
330 
331 
332 #ifndef IMP_DOXYGEN
333 #define IMP_IMPLEMENT_PAIR_CONTAINER(Name) \
334  IMP_IMPLEMENT_INLINE(void do_apply(const PairModifier *sm) const, {\
335  apply_generic(sm); \
336  }); \
337  IMP_IMPLEMENT(ParticleIndexes get_all_possible_indexes() const); \
338  IMP_OBJECT(Name)
339 #endif
340 
341 
342 
343 
344 
345 //! Declare the needed functions for a PairContainer
346 /** In addition to the methods of IMP_OBJECT, it declares
347  - IMP::PairContainer::get_number_of_particle_particle_pairs()
348  - IMP::PairContainer::get_particle_particle_pair()
349  - IMP::PairContainer::apply()
350  - IMP::PairContainer::evaluate()
351  - IMP::Interaction::get_input_objects()
352 
353  You need to define a template method with the signature
354 \code
355 template <class Functor>
356 Functor for_each(Functor f);
357 \endcode
358  that applied the functor to each thing in the container.
359 */
360 #define IMP_PAIR_CONTAINER(Name) \
361  IMP_IMPLEMENT(ParticleIndexPairs get_indexes() const); \
362  IMP_IMPLEMENT(ParticleIndexPairs get_range_indexes() const); \
363  IMP_IMPLEMENT(void do_before_evaluate()); \
364  IMP_IMPLEMENT(ParticlesTemp get_input_particles() const); \
365  IMP_IMPLEMENT(ContainersTemp get_input_containers() const); \
366  IMP_IMPLEMENT_INLINE(ModelObjectsTemp do_get_inputs() const, { \
367  ModelObjects ret; \
368  ret+=get_input_containers(); \
369  ret+=get_input_particles(); \
370  return ret; \
371  }); \
372  IMP_IMPLEMENT_PAIR_CONTAINER(Name)
373 
374 
375 //! Declare the needed functions for an active PairContainer
376 /** In addition to the methods of IMP_PAIR_CONTAINER(), it declares
377  - IMP::ScoreState::get_input_particles()
378  - IMP::ScoreState::get_input_containers()
379  - IMP::ScoreState::do_before_evaluate()
380 */
381 #define IMP_ACTIVE_PAIR_CONTAINER(Name) \
382  IMP_PAIR_CONTAINER(name)
383 
384 /** Use IMP_CONTAINER_FOREACH() instead.
385 */
386 #define IMP_FOREACH_PAIR(sequence, operation) do { \
387  IMP::kernel::ParticlePairsTemp imp_all=sequence->get(); \
388  for (unsigned int _2=0; \
389  _2 != imp_all.size(); \
390  ++_2) { \
391  IMP::kernel::ParticlePair _1= imp_all[_2]; \
392  bool imp_foreach_break=false; \
393  operation \
394  if (imp_foreach_break) break; \
395  } \
396  } while (false)
397 
398 
399 
400 /** Use IMP_CONTAINER_FOREACH() instead.
401 */
402 #define IMP_FOREACH_PAIR_INDEX(sequence, operation) \
403  IMP_CONTAINER_FOREACH(PairContainer, sequence, operation)
404 
405 #endif /* IMPKERNEL_PAIR_MACROS_H */