IMP logo
IMP Reference Guide  develop.29b24c6ad6,2021/05/15
The Integrative Modeling Platform
triplet_predicates.h
Go to the documentation of this file.
1 // Autogenerated by ../../../../tmp/nightly-build-311/imp-20210515.develop.29b24c6ad6/tools/build/make_containers.py
2 // from ../../../../tmp/nightly-build-311/imp-20210515.develop.29b24c6ad6/tools/build/container_templates/core/classname_predicates.h
3 // Do not edit - any changes will be lost!
4 
5 /**
6  * \file IMP/core/triplet_predicates.h
7  * \brief Define some predicates.
8  *
9  * Copyright 2007-2021 IMP Inventors. All rights reserved.
10  */
11 
12 #ifndef IMPCORE_TRIPLET_PREDICATES_H
13 #define IMPCORE_TRIPLET_PREDICATES_H
14 
15 #include <IMP/core/core_config.h>
16 #include <IMP/core/Typed.h>
17 #include <IMP/TripletPredicate.h>
18 #include <IMP/triplet_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 ConstantTripletPredicate : public TripletPredicate {
27  int v_;
28 
29  public:
31  std::string name = "ConstTripletPredicate%1%");
32  virtual int get_value_index(Model *, const ParticleIndexTriplet&) 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 UnorderedTypeTripletPredicate
50  : public TripletPredicate {
51  public:
52  UnorderedTypeTripletPredicate(std::string name =
53  "UnorderedTypeTripletPredicate%1%");
54  virtual int get_value_index(Model *m, const ParticleIndexTriplet& 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 triplet of
69  ParticleTypes (see Typed).
70 */
71 class IMPCOREEXPORT OrderedTypeTripletPredicate : public TripletPredicate {
72  private:
73  mutable int const* cached_particle_type_ids_table_;
74  mutable int cached_n_particle_types_;
75  public:
76  OrderedTypeTripletPredicate(std::string name =
77  "OrderedTypeTripletPredicate%1%");
78  //! Compute the predicate for specified types
79  int get_value(const core::ParticleTypes &types) {
80  return internal::get_ordered_type_hash(types);
81  }
82  //! Compute the predicate for types of specific pi
83  virtual int get_value_index(Model *m, const ParticleIndexTriplet& pi) const
84  IMP_OVERRIDE {
85  return internal::get_ordered_type_hash(m, pi);
86  }
87 
88  //! Setup for a batch of calls to get_value_index_in_batch()
89  //! (used for improving performance)
92  cached_particle_type_ids_table_=
93  m->IMP::internal::IntAttributeTable::access_attribute_data(Typed::get_type_key());
94  cached_n_particle_types_= ParticleType::get_number_unique();
95  };
96 
97  //! Same as get_value_index, but with optimizations
98  //! for a batch of calls. Call setup_for_get_value_index_in_batch()
99  //! right before calling a batch of those, otherwise unexpected behavior.
100  virtual int get_value_index_in_batch(Model* m, const ParticleIndexTriplet& pi) const
101  IMP_OVERRIDE{
102  IMP_UNUSED(m);
103  return internal::get_ordered_type_hash( pi,
104  cached_particle_type_ids_table_,
105  cached_n_particle_types_);
106  }
107 
109  Model *m, const ParticleIndexes &pis) const IMP_OVERRIDE {
110  ModelObjectsTemp ret;
111  ret += IMP::get_particles(m, pis);
112  return ret;
113  }
116 };
117 
118 /** Return true if all members of the tuple are the same. */
119 class IMPCOREEXPORT AllSameTripletPredicate : public TripletPredicate {
120  public:
121  AllSameTripletPredicate(std::string name = "AllSameTripletPredicate%1%");
122  virtual int get_value_index(Model *m, const ParticleIndexTriplet& pi) const
123  IMP_OVERRIDE {
124  return internal::get_all_same(m, pi);
125  }
127  Model *, const ParticleIndexes &) const IMP_OVERRIDE {
128  return ModelObjectsTemp();
129  }
132 };
133 
134 /** Return true with a fixed probability. */
135 class IMPCOREEXPORT CoinFlipTripletPredicate : public TripletPredicate {
136  double p_;
137  mutable boost::uniform_real<double> rng_;
138 
139  public:
140  CoinFlipTripletPredicate(double p, std::string name =
141  "CoinFlipTripletPredicate%1%");
142  virtual int get_value_index(Model *, const ParticleIndexTriplet&) const
143  IMP_OVERRIDE {
144  if (rng_(random_number_generator) < p_)
145  return 1;
146  else
147  return 0;
148  }
150  Model *, const ParticleIndexes &) const IMP_OVERRIDE {
151  return ModelObjectsTemp();
152  }
155 };
156 
157 IMPCORE_END_NAMESPACE
158 
159 #endif /* IMPCORE_TRIPLET_PREDICATES_H */
#define IMP_TRIPLET_PREDICATE_METHODS(Name)
Define extra the functions needed for a TripletPredicate.
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const
Overload this method to specify the inputs.
virtual int get_value_index(Model *, const ParticleIndexTriplet &) 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.
A class to store an fixed array of same-typed values.
Definition: Array.h:33
Macros for various classes.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Define TripletPredicate.
virtual void setup_for_get_value_index_in_batch(Model *m) const
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Overload this method to specify the inputs.
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
A more IMP-like version of the std::vector.
Definition: Vector.h:40
A particle with a user-defined type.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:86
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Abstract predicate function.
int get_value(const core::ParticleTypes &types)
Compute the predicate for specified types.
#define IMP_UNUSED(variable)
virtual int get_value_index(Model *, const ParticleIndexTriplet &) const
Compute the predicate and the derivative if needed.
virtual ModelObjectsTemp do_get_inputs(Model *m, const ParticleIndexes &pis) const
Overload this method to specify the inputs.
virtual int get_value_index(Model *m, const ParticleIndexTriplet &pi) const
Compute the predicate and the derivative if needed.
virtual int get_value_index(Model *m, const ParticleIndexTriplet &pi) const
Compute the predicate for types of specific pi.
virtual int get_value_index(Model *m, const ParticleIndexTriplet &pi) const
Compute the predicate and the derivative if needed.
virtual int get_value_index_in_batch(Model *m, const ParticleIndexTriplet &pi) const
virtual ModelObjectsTemp do_get_inputs(Model *, const ParticleIndexes &) const
Overload this method to specify the inputs.
#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.