IMP logo
IMP Reference Guide  2.11.0
The Integrative Modeling Platform
pair_predicates.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-82993/imp-2.11.0/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-82993/imp-2.11.0/tools/build/container_templates/core/classname_predicates.h
3 // Do not edit - any changes will be lost!
4 
5 /**
6  * \file IMP/core/pair_predicates.h
7  * \brief Define some predicates.
8  *
9  * Copyright 2007-2019 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPCORE_PAIR_PREDICATES_H
13 #define IMPCORE_PAIR_PREDICATES_H
14 
15 #include <IMP/core/core_config.h>
16 #include <IMP/core/Typed.h>
17 #include <IMP/PairPredicate.h>
18 #include <IMP/pair_macros.h>
19 #include <boost/random.hpp>
20 #include "internal/container_helpers.h"
21 
22 IMPCORE_BEGIN_NAMESPACE
23 
24 /** Always return a constant value.
25  */
26 class IMPCOREEXPORT ConstantPairPredicate : public PairPredicate {
27  int v_;
28 
29  public:
31  std::string name = "ConstPairPredicate%1%");
32  virtual int get_value_index(Model *, const ParticleIndexPair&) const
33  IMP_OVERRIDE {
34  return v_;
35  }
37  Model *, const ParticleIndexes &) const IMP_OVERRIDE {
38  return ModelObjectsTemp();
39  }
42 };
43 
44 /** Return a unique predicate value for each unordered set of
45  ParticleTypes
46  (see Typed).
47 */
48 
49 class IMPCOREEXPORT UnorderedTypePairPredicate
50  : public PairPredicate {
51  public:
52  UnorderedTypePairPredicate(std::string name =
53  "UnorderedTypePairPredicate%1%");
54  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
55  IMP_OVERRIDE {
56  return internal::get_type_hash(m, pi);
57  }
59  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE {
60  ModelObjectsTemp ret;
61  ret += IMP::get_particles(m, pis);
62  return ret;
63  }
66 };
67 
68 /** Return a unique predicate value for each ordered pair of
69  ParticleTypes (see Typed).
70 */
71 class IMPCOREEXPORT OrderedTypePairPredicate : public PairPredicate {
72  private:
73  mutable int const* cached_particle_type_ids_table_;
74  mutable int cached_n_particle_types_;
75  public:
76  OrderedTypePairPredicate(std::string name =
77  "OrderedTypePairPredicate%1%");
78 #ifndef SWIG
80 #endif
81  //! Compute the predicate for specified types
82  int get_value(const core::ParticleTypes &types) {
83  return internal::get_ordered_type_hash(types);
84  }
85  //! Compute the predicate for types of specific pi
86  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
87  IMP_OVERRIDE {
88  return internal::get_ordered_type_hash(m, pi);
89  }
90 
91  //! Setup for a batch of calls to get_value_index_in_batch()
92  //! (used for improving performance)
95  cached_particle_type_ids_table_=
96  m->IMP::internal::IntAttributeTable::access_attribute_data(Typed::get_type_key());
97  cached_n_particle_types_= ParticleType::get_number_unique();
98  };
99 
100  //! Same as get_value_index, but with optimizations
101  //! for a batch of calls. Call setup_for_get_value_index_in_batch()
102  //! right before calling a batch of those, otherwise unexpected behavior.
103  virtual int get_value_index_in_batch(Model* m, const ParticleIndexPair& pi) const
104  IMP_OVERRIDE{
105  IMP_UNUSED(m);
106  return internal::get_ordered_type_hash( pi,
107  cached_particle_type_ids_table_,
108  cached_n_particle_types_);
109  }
110 
112  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE {
113  ModelObjectsTemp ret;
114  ret += IMP::get_particles(m, pis);
115  return ret;
116  }
119 };
120 
121 /** Return true if all members of the tuple are the same. */
122 class IMPCOREEXPORT AllSamePairPredicate : public PairPredicate {
123  public:
124  AllSamePairPredicate(std::string name = "AllSamePairPredicate%1%");
125  virtual int get_value_index(Model *m, const ParticleIndexPair& pi) const
126  IMP_OVERRIDE {
127  return internal::get_all_same(m, pi);
128  }
130  Model *, const ParticleIndexes &) const IMP_OVERRIDE {
131  return ModelObjectsTemp();
132  }
135 };
136 
137 /** Return true with a fixed probability. */
138 class IMPCOREEXPORT CoinFlipPairPredicate : public PairPredicate {
139  double p_;
140  mutable boost::uniform_real<double> rng_;
141 
142  public:
143  CoinFlipPairPredicate(double p, std::string name =
144  "CoinFlipPairPredicate%1%");
145  virtual int get_value_index(Model *, const ParticleIndexPair&) const
146  IMP_OVERRIDE {
147  if (rng_(random_number_generator) < p_)
148  return 1;
149  else
150  return 0;
151  }
153  Model *, const ParticleIndexes &) const IMP_OVERRIDE {
154  return ModelObjectsTemp();
155  }
158 };
159 
160 IMPCORE_END_NAMESPACE
161 
162 #endif /* IMPCORE_PAIR_PREDICATES_H */
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const
Overload this method to specify the inputs.
virtual int get_value_index(Model *m, const ParticleIndexPair &pi) const
Compute the predicate for types of specific pi.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const
Overload this method to specify the inputs.
Macros for various classes.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
virtual void setup_for_get_value_index_in_batch(Model *m) const
A more IMP-like version of the std::vector.
Definition: Vector.h:39
A particle with a user-defined type.
virtual int get_value_index(Model *m, const ParticleIndexPair &pi) const
Compute the predicate and the derivative if needed.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:82
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
virtual int get_value_index(Model *, const ParticleIndexPair &) const
Compute the predicate and the derivative if needed.
#define IMP_UNUSED(variable)
Define PairPredicate.
int get_value(const core::ParticleTypes &types)
Compute the predicate for specified types.
Abstract predicate function.
Definition: PairPredicate.h:31
virtual int get_value_index(Model *m, const ParticleIndexPair &pi) const
Compute the predicate and the derivative if needed.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const
Overload this method to specify the inputs.
virtual int get_value_index_in_batch(Model *m, const ParticleIndexPair &pi) const
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Overload this method to specify the inputs.
virtual int get_value(const ParticlePair &vt) const
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
RandomNumberGenerator random_number_generator
A shared non-GPU random number generator.
virtual int get_value_index(Model *, const ParticleIndexPair &) const
Compute the predicate and the derivative if needed.
#define IMP_PAIR_PREDICATE_METHODS(Name)
Define extra the functions needed for a PairPredicate.
Definition: pair_macros.h:47
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Overload this method to specify the inputs.