IMP  2.1.0
The Integrative Modeling Platform
kernel/triplet_macros.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/triplet_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_TRIPLET_MACROS_H
12 #define IMPKERNEL_TRIPLET_MACROS_H
13 
14 #include "internal/TupleRestraint.h"
15 #include "internal/functors.h"
16 #include "container_macros.h"
17 #include <IMP/base/object_macros.h>
18 #include "input_output_macros.h"
19 #include <algorithm>
20 
21 
22 /** \deprecated_at{2.1} Declare methods youself and use
23  IMP_TRIPLET_SCORE_METHODS() to fill in the rest.
24 */
25 #define IMP_TRIPLET_SCORE(Name) \
26  IMPKERNEL_DEPRECATED_MACRO(2.1, "Declare methods yourself and use " \
27  "IMP_TRIPLET_SCORE_METHODS() to fill in the rest."); \
28  IMP_IMPLEMENT(double evaluate(const ParticleTriplet& p,\
29  DerivativeAccumulator *da) const); \
30  IMP_IMPLEMENT_INLINE(double evaluate_index(kernel::Model *m, \
31  const ParticleIndexTriplet& p, \
32  DerivativeAccumulator *da) const, { \
33  return evaluate(IMP::kernel::internal::get_particle(m,p), da); \
34  }); \
35  IMP_IMPLEMENT_INLINE(double evaluate_if_good_index(kernel::Model *m, \
36  const ParticleIndexTriplet& p, \
37  DerivativeAccumulator *da, \
38  double max) const, { \
39  IMP_UNUSED(max); \
40  return evaluate_index(m, p, da); \
41  }); \
42  IMP_BACKWARDS_MACRO_INPUTS; \
43  IMP_OBJECT_NO_WARNING(Name)
44 
45 /** \deprecated_at{2.1} Declare methods youself and use
46  IMP_TRIPLET_SCORE_METHODS() to fill in the rest.
47 */
48 #define IMP_SIMPLE_TRIPLET_SCORE(Name) \
49  IMPKERNEL_DEPRECATED_MACRO(2.1, "Declare methods yourself and use " \
50  "IMP_TRIPLET_SCORE_METHODS() to fill in the rest."); \
51  IMP_IMPLEMENT(double evaluate(const ParticleTriplet& p, \
52  DerivativeAccumulator *da) const); \
53  IMP_IMPLEMENT_INLINE(kernel::ModelObjectsTemp \
54  do_get_inputs(kernel::Model *m, \
55  const ParticleIndexes &pis) const, { \
56  kernel::ModelObjectsTemp ret; \
57  ret+=IMP::kernel::get_particles(m, pis); \
58  return ret; \
59  }); \
60  IMP_IMPLEMENT_INLINE(Restraints do_create_current_decomposition \
61  (kernel::Model *m, \
62  const ParticleIndexTriplet& vt) const, { \
63  return IMP::kernel::internal \
64  ::create_score_current_decomposition(this, m, vt); \
65  }); \
66  IMP_OBJECT_NO_WARNING(Name)
67 
68 
69 
70 /** \deprecated_at{2.1} Do it yourself.
71 */
72 #define IMP_COMPOSITE_TRIPLET_SCORE(Name) \
73  IMPKERNEL_DEPRECATED_MACRO(2.1, "Do it yourself."); \
74  IMP_IMPLEMENT_INLINE(double evaluate(const ParticleTriplet& p, \
75  DerivativeAccumulator *da) const, { \
76  return evaluate_index(IMP::kernel::internal::get_model(p), \
77  IMP::kernel::internal::get_index(p), da); \
78  }); \
79  IMP_IMPLEMENT(double evaluate_index(kernel::Model *m, const ParticleIndexTriplet& p,\
80  DerivativeAccumulator *da) const); \
81  IMP_IMPLEMENT(double evaluate_if_good_index(kernel::Model *m, \
82  const ParticleIndexTriplet& p, \
83  DerivativeAccumulator *da, \
84  double max) const); \
85  IMP_IMPLEMENT_INLINE(double evaluate_indexes(kernel::Model *m, \
86  const ParticleIndexTriplets &p, \
87  DerivativeAccumulator *da, \
88  unsigned int lower_bound, \
89  unsigned int upper_bound) const,\
90  { \
91  double ret=0; \
92  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
93  ret+= evaluate_index(m, p[i], da); \
94  } \
95  return ret; \
96  }); \
97  IMP_IMPLEMENT_INLINE(double \
98  evaluate_if_good_indexes(kernel::Model *m, \
99  const ParticleIndexTriplets &p, \
100  DerivativeAccumulator *da, \
101  double max, \
102  unsigned int lower_bound, \
103  unsigned int upper_bound) const, { \
104  double ret=0; \
105  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
106  ret+= evaluate_if_good_index(m, p[i], da, max-ret); \
107  if (ret>max) return std::numeric_limits<double>::max(); \
108  } \
109  return ret; \
110  }); \
111  IMP_IMPLEMENT(kernel::ModelObjectsTemp \
112  do_get_inputs(kernel::Model *m, \
113  const ParticleIndexes &pis) const ); \
114  IMP_OBJECT_NO_WARNING(Name)
115 
116 /** Define
117  - IMP::kernel::TripletScore::evaluate_indexes()
118  - IMP::kernel::TripletScore::evaluate_if_good_indexes()
119  */
120 #define IMP_TRIPLET_SCORE_METHODS(Name) \
121  double evaluate_indexes(kernel::Model *m, \
122  const ParticleIndexTriplets &p, \
123  DerivativeAccumulator *da, \
124  unsigned int lower_bound, \
125  unsigned int upper_bound) const IMP_FINAL { \
126  double ret=0; \
127  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
128  ret+= evaluate_index(m, p[i], da); \
129  } \
130  return ret; \
131  } \
132  double evaluate_if_good_indexes(kernel::Model *m, \
133  const ParticleIndexTriplets &p, \
134  DerivativeAccumulator *da, \
135  double max, \
136  unsigned int lower_bound, \
137  unsigned int upper_bound) const { \
138  double ret=0; \
139  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
140  ret+= evaluate_if_good_index(m, p[i], da, max-ret); \
141  if (ret>max) return std::numeric_limits<double>::max(); \
142  } \
143  return ret; \
144  } \
145 
146 
147 /** \deprecated_at{2.1} Declare methods youself and use
148  IMP_TRIPLET_SCORE_METHODS() to fill in the rest.
149 */
150 #define IMP_INDEX_TRIPLET_SCORE(Name) \
151  IMPKERNEL_DEPRECATED_MACRO(2.1, "Declare methods yourself and use "\
152  "IMP_TRIPLET_SCORE_METHODS() to fill in the rest."); \
153  double evaluate(const ParticleTriplet& p, DerivativeAccumulator *da) const { \
154  return evaluate_index(IMP::kernel::internal::get_model(p), \
155  IMP::kernel::internal::get_index(p), \
156  da); \
157  } \
158  double evaluate_index(kernel::Model *m, const ParticleIndexTriplet& p, \
159  DerivativeAccumulator *da) const IMP_FINAL; \
160  double evaluate_if_good_index(kernel::Model *m, const ParticleIndexTriplet& p, \
161  DerivativeAccumulator *da, \
162  double max) const { \
163  IMP_UNUSED(max); \
164  return evaluate_index(m, p, da); \
165  } \
166  double evaluate_indexes(kernel::Model *m, \
167  const ParticleIndexTriplets &p, \
168  DerivativeAccumulator *da, \
169  unsigned int lower_bound, \
170  unsigned int upper_bound) const IMP_FINAL { \
171  double ret=0; \
172  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
173  ret+= evaluate_index(m, p[i], da); \
174  } \
175  return ret; \
176  } \
177  double evaluate_if_good_indexes(kernel::Model *m, \
178  const ParticleIndexTriplets &p, \
179  DerivativeAccumulator *da, \
180  double max, \
181  unsigned int lower_bound, \
182  unsigned int upper_bound) const { \
183  double ret=0; \
184  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
185  ret+= evaluate_if_good_index(m, p[i], da, max-ret); \
186  if (ret>max) return std::numeric_limits<double>::max(); \
187  } \
188  return ret; \
189  } \
190  kernel::ModelObjectsTemp do_get_inputs(kernel::Model *m, \
191  const ParticleIndexes &pis) const; \
192  IMP_OBJECT_METHODS(Name)
193 
194 
195 
196 /** \deprecated_at{2.1} Use IMP_TRIPLET_PREDICATE_METHODS instead and declare
197  the methods you implement.
198  */
199 #define IMP_TRIPLET_PREDICATE(Name) \
200  IMPKERNEL_DEPRECATED_MACRO(2.1, "Use IMP_TRIPLET_PREDICATE_METHODS"\
201  " and declare the methods you implement."); \
202  IMP_IMPLEMENT(int get_value(const ParticleTriplet& a) const); \
203  IMP_IMPLEMENT_INLINE(Ints get_value(const \
204  ParticleTripletsTemp &o) const, { \
205  Ints ret(o.size()); \
206  for (unsigned int i=0; i< o.size(); ++i) { \
207  ret[i]+= Name::get_value(o[i]); \
208  } \
209  return ret; \
210  }); \
211  IMP_IMPLEMENT_INLINE(int get_value_index(kernel::Model *m, \
212  const ParticleIndexTriplet& vt)\
213  const, { \
214  return Name::get_value(IMP::kernel::internal::get_particle(m, vt)); \
215  }); \
216  IMP_IMPLEMENT_INLINE(Ints get_value_index(kernel::Model *m, \
217  const ParticleIndexTriplets &o) const, { \
218  Ints ret(o.size()); \
219  for (unsigned int i=0; i< o.size(); ++i) { \
220  ret[i]+= Name::get_value_index(m, o[i]); \
221  } \
222  return ret; \
223  }); \
224  IMP_BACKWARDS_MACRO_INPUTS; \
225  IMP_OBJECT_NO_WARNING(Name)
226 
227 
228 //! Define extra the functions needed for a TripletPredicate
229 #define IMP_TRIPLET_PREDICATE_METHODS(Name) \
230  int get_value(const ParticleTriplet& a) const { \
231  return get_value_index(IMP::kernel::internal::get_model(a), \
232  IMP::kernel::internal::get_index(a)); \
233  } \
234  Ints get_value(const ParticleTripletsTemp &o) const { \
235  Ints ret(o.size()); \
236  for (unsigned int i=0; i< o.size(); ++i) { \
237  ret[i]+= Name::get_value(o[i]); \
238  } \
239  return ret; \
240  } \
241  Ints get_value_index(kernel::Model *m, const ParticleIndexTriplets &o) const { \
242  Ints ret(o.size()); \
243  for (unsigned int i=0; i< o.size(); ++i) { \
244  ret[i]+= Name::get_value_index(m, o[i]); \
245  } \
246  return ret; \
247  } \
248  IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_equal(kernel::Model *m, \
249  ParticleIndexTriplets& ps, \
250  int value) const, { \
251  ps.erase(std::remove_if(ps.begin(), ps.end(), \
252  IMP::kernel::internal::PredicateEquals<Name, true>(this, \
253  m, value)), \
254  ps.end()); \
255  }); \
256  IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_not_equal(kernel::Model *m, \
257  ParticleIndexTriplets& ps, \
258  int value) const, { \
259  ps.erase(std::remove_if(ps.begin(), ps.end(), \
260  IMP::kernel::internal::PredicateEquals<Name, false>(this, \
261  m, value)), \
262  ps.end()); \
263  });
264 
265 /** \deprecated_at{2.1} Declare methods yourself and use
266  IMP_TRIPLET_PREDICATE_METHODS to fill in the rest.
267 */
268 #define IMP_INDEX_TRIPLET_PREDICATE(Name, return_value, return_inputs) \
269  IMPKERNEL_DEPRECATED_MACRO(2.1, "Declare the methods yourself and use" \
270  " IMP_TRIPLET_PREDICATE_METHODS to fill in the rest."); \
271  int get_value(const ParticleTriplet& a) const { \
272  return get_value_index(IMP::kernel::internal::get_model(a), \
273  IMP::kernel::internal::get_index(a)); \
274  } \
275  Ints get_value(const ParticleTripletsTemp &o) const { \
276  Ints ret(o.size()); \
277  for (unsigned int i=0; i< o.size(); ++i) { \
278  ret[i]+= Name::get_value(o[i]); \
279  } \
280  return ret; \
281  } \
282  int get_value_index(kernel::Model *m, const ParticleIndexTriplet& pi) const { \
283  return_value; \
284  } \
285  Ints get_value_index(kernel::Model *m, const ParticleIndexTriplets &o) const { \
286  Ints ret(o.size()); \
287  for (unsigned int i=0; i< o.size(); ++i) { \
288  ret[i]+= Name::get_value_index(m, o[i]); \
289  } \
290  return ret; \
291  } \
292  IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_equal(kernel::Model *m, \
293  ParticleIndexTriplets& ps, \
294  int value) const, { \
295  ps.erase(std::remove_if(ps.begin(), ps.end(), \
296  IMP::kernel::internal::PredicateEquals<Name, true>(this, \
297  m, value)), \
298  ps.end()); \
299  }); \
300  IMP_IMPLEMENT_INLINE_NO_SWIG(void remove_if_not_equal(kernel::Model *m, \
301  ParticleIndexTriplets& ps, \
302  int value) const, { \
303  ps.erase(std::remove_if(ps.begin(), ps.end(), \
304  IMP::kernel::internal::PredicateEquals<Name, false>(this, \
305  m, value)), \
306  ps.end()); \
307  }); \
308  kernel::ModelObjectsTemp do_get_inputs(kernel::Model *m, \
309  const ParticleIndexes &pi) const { \
310  return_inputs; \
311  } \
312  IMP_OBJECT_METHODS(Name)
313 
314 
315 /** \deprecated_at{2.1} Declare methods yourself and use IMP_TRIPLET_MODIFIER_METHODS
316  to fill in the rest.
317 */
318 #define IMP_TRIPLET_MODIFIER(Name) \
319  IMPKERNEL_DEPRECATED_MACRO(2.1, "Declare methods yourself and" \
320  " use IMP_TRIPLET_MODIFIER_METHODS to fill in the rest"); \
321  IMP_IMPLEMENT(void apply(const ParticleTriplet& a) const); \
322  IMP_IMPLEMENT_INLINE(void apply_index(kernel::Model *m, \
323  const ParticleIndexTriplet& a) const, { \
324  return Name::apply(IMP::kernel::internal::get_particle(m,a)); \
325  }) \
326  IMP_BACKWARDS_MACRO_INPUTS; \
327  IMP_BACKWARDS_MACRO_OUTPUTS; \
328  IMP_OBJECT_NO_WARNING(Name)
329 
330 //! Use IMP_TRIPLET_MODIFIER() instead
331 #define IMP_TRIPLET_DERIVATIVE_MODIFIER(Name) \
332  IMP_TRIPLET_MODIFIER(Name)
333 
334 
335 /** Define
336  - IMP::kernel::TripletModifier::apply_indexes()
337 */
338 #define IMP_TRIPLET_MODIFIER_METHODS(Name) \
339  virtual void apply_indexes(kernel::Model *m, const ParticleIndexTriplets &o, \
340  unsigned int lower_bound, \
341  unsigned int upper_bound) const IMP_FINAL { \
342  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
343  apply_index(m, o[i]); \
344  } \
345  } \
346 
347 
348 
349 /** \deprecated_at{2.1} Declare methods yourself and use IMP_TRIPLET_MODIFIER_METHODS
350  to fill in the rest.
351 */
352 #define IMP_INDEX_TRIPLET_MODIFIER(Name) \
353  IMPKERNEL_DEPRECATED_MACRO(2.1, "Declare methods yourself and" \
354  " use IMP_TRIPLET_MODIFIER_METHODS to fill in the rest"); \
355  void apply(const ParticleTriplet& a) const { \
356  apply_index(IMP::kernel::internal::get_model(a), \
357  IMP::kernel::internal::get_index(a)); \
358  } \
359  void apply_index(kernel::Model *m, const ParticleIndexTriplet& a) const IMP_FINAL; \
360  void apply_indexes(kernel::Model *m, const ParticleIndexTriplets &o, \
361  unsigned int lower_bound, \
362  unsigned int upper_bound) const IMP_FINAL { \
363  for (unsigned int i=lower_bound; i < upper_bound; ++i) { \
364  apply_index(m, o[i]); \
365  } \
366  } \
367  kernel::ModelObjectsTemp do_get_inputs(kernel::Model *m, const ParticleIndexes &pis) const; \
368  kernel::ModelObjectsTemp do_get_outputs(kernel::Model *m, \
369  const ParticleIndexes &pis) const; \
370  IMP_OBJECT_METHODS(Name)
371 
372 //! Use IMP_INDEX_TRIPLET_MODIFIER instead
373 #define IMP_INDEX_TRIPLET_DERIVATIVE_MODIFIER(Name) \
374  IMP_INDEX_TRIPLET_MODIFIER(Name)
375 
376 
377 
378 
379 #ifndef IMP_DOXYGEN
380 #define IMP_IMPLEMENT_TRIPLET_CONTAINER(Name) \
381  IMP_IMPLEMENT_INLINE(void do_apply(const TripletModifier *sm) const, {\
382  apply_generic(sm); \
383  }); \
384  virtual ParticleIndexes get_all_possible_indexes() const IMP_OVERRIDE; \
385  IMP_OBJECT_NO_WARNING(Name)
386 #endif
387 
388 
389 /** Use this to fill in container methods
390  IMP::kernel::TripletContainer::do_apply()
391 */
392 #define IMP_TRIPLET_CONTAINER_METHODS(Name) \
393  void do_apply(const TripletModifier *sm) const { \
394  apply_generic(sm); \
395  }
396 
397 
398 /** \deprecated_at{2.1} Declare the methods directly and use
399  IMP_TRIPLET_CONTAINER_METHODS
400 */
401 #define IMP_TRIPLET_CONTAINER(Name) \
402  IMPKERNEL_DEPRECATED_MACRO(2.1, "Declare the methods yourself and use "\
403  "IMP_TRIPLET_CONTAINER_METHODS"); \
404  IMP_IMPLEMENT(ParticleIndexTriplets get_indexes() const); \
405  IMP_IMPLEMENT(ParticleIndexTriplets get_range_indexes() const); \
406  IMP_IMPLEMENT(void do_before_evaluate()); \
407  IMP_IMPLEMENT(ParticlesTemp get_input_particles() const); \
408  IMP_IMPLEMENT(ContainersTemp get_input_containers() const); \
409  IMP_IMPLEMENT_INLINE(kernel::ModelObjectsTemp do_get_inputs() const, { \
410  kernel::ModelObjects ret; \
411  ret+=get_input_containers(); \
412  ret+=get_input_particles(); \
413  return ret; \
414  }); \
415  IMP_IMPLEMENT_TRIPLET_CONTAINER(Name)
416 
417 
418 /** \deprecated_at{2.1} Declare the methods directly and use
419  IMP_TRIPLET_CONTAINER_METHODS
420 */
421 #define IMP_ACTIVE_TRIPLET_CONTAINER(Name) \
422  IMP_TRIPLET_CONTAINER(name)
423 
424 /** Use IMP_CONTAINER_FOREACH() instead.
425 */
426 #define IMP_FOREACH_TRIPLET(sequence, operation) do { \
427  IMPKERNEL_DEPRECATED_MACRO(2.1, "Use IMP_CONTAINER_FOREACH instead"); \
428  IMP::kernel::ParticleTripletsTemp imp_all=sequence->get(); \
429  for (unsigned int _2=0; \
430  _2 != imp_all.size(); \
431  ++_2) { \
432  IMP::kernel::ParticleTriplet _1= imp_all[_2]; \
433  bool imp_foreach_break=false; \
434  operation \
435  if (imp_foreach_break) break; \
436  } \
437  } while (false)
438 
439 
440 
441 /** Use IMP_CONTAINER_FOREACH() instead.
442 */
443 #define IMP_FOREACH_TRIPLET_INDEX(sequence, operation) \
444  IMPKERNEL_DEPRECATED_MACRO(2.1, "Use IMP_CONTAINER_FOREACH instead"); \
445  IMP_CONTAINER_FOREACH(TripletContainer, sequence, operation)
446 
447 #endif /* IMPKERNEL_TRIPLET_MACROS_H */
macros for inputs and outputs.
Various general useful macros for IMP.
Macros to define containers of objects.