IMP  2.0.0
The Integrative Modeling Platform
kernel/PairPredicate.h
Go to the documentation of this file.
1 /**
2  * \file IMP/kernel/PairPredicate.h
3  * \brief Define PairPredicate.
4  *
5  * WARNING This file was generated from PairPredicate.h
6  * in /tmp/nightly-build-5687/imp-2.0.0/tools/build/container_templates/kernel
7  * by tools/maintenance/setup_containers.py.
8  *
9  * Copyright 2007-2013 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPKERNEL_PAIR_PREDICATE_H
13 #define IMPKERNEL_PAIR_PREDICATE_H
14 
15 #include <IMP/kernel/kernel_config.h>
16 #include "base_types.h"
17 #include "ParticleTuple.h"
18 #include "DerivativeAccumulator.h"
19 #include "internal/container_helpers.h"
20 #include "input_output_macros.h"
21 
22 IMPKERNEL_BEGIN_NAMESPACE
23 
24 //! Abstract predicate function
25 /** A predicate is a function which returns one of a discrete set of
26  values (eg -1, 0, 1 depending on whether a value is negative, zero
27  or positive). PairPredicates will evaluate the predicate for the passed
28  particles.
29 
30  Implementers should check out IMP_PAIR_PREDICATE().
31 */
32 class IMPKERNELEXPORT PairPredicate : public base::Object
33 {
34  public:
35  typedef ParticlePair Argument;
37  PairPredicate(std::string name="PairPredicate %1%");
38  //! Compute the predicate.
39  virtual int get_value(const ParticlePair& vt) const =0;
40 
41  /** Implementations
42  for these are provided by the IMP_PAIR_PREDICATE()
43  macro.
44  */
45  virtual Ints get_value(const ParticlePairsTemp &o) const {
46  Ints ret(o.size());
47  for (unsigned int i=0; i< o.size(); ++i) {
48  ret[i]+= get_value(o[i]);
49  }
50  return ret;
51  }
52 
53 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
54  virtual void remove_if_equal(Model *m,
55  ParticleIndexPairs& ps, int v) const;
56  virtual void remove_if_not_equal(Model *m,
57  ParticleIndexPairs& ps, int v) const;
58 #endif
59 
60  //! Compute the predicate and the derivative if needed.
61  virtual int get_value_index(Model *m, const ParticleIndexPair& vt) const {
62  return get_value(internal::get_particle(m, vt));
63  }
64 
65  //! Enable them to be use as functors
66  /** But beware of slicing.
67  */
68  int operator()(Model *m, const ParticleIndexPair& vt) const {
69  return get_value_index(m, vt);
70  }
71 
72  /** Implementations
73  for these are provided by the IMP_PAIR_PREDICATE()
74  macro.
75  */
76  virtual Ints get_value_index(Model *m,
77  const ParticleIndexPairs &o) const {
78  Ints ret(o.size());
79  for (unsigned int i=0; i< o.size(); ++i) {
80  ret[i]+= get_value_index(m, o[i]);
81  }
82  return ret;
83  }
84 
86 
88 };
89 
90 
91 IMPKERNEL_END_NAMESPACE
92 
93 #endif /* IMPKERNEL_PAIR_PREDICATE_H */