IMP logo
IMP Reference Guide  2.5.0
The Integrative Modeling Platform
DiscreteSampler.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/DiscreteSampler.h
3  * \brief A base class for discrete samplers.
4  *
5  * Copyright 2007-2015 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPDOMINO_DISCRETE_SAMPLER_H
10 #define IMPDOMINO_DISCRETE_SAMPLER_H
11 
12 #include <IMP/domino/domino_config.h>
13 #include "assignment_tables.h"
14 #include "particle_states.h"
15 #include "subset_filters.h"
16 #include <IMP/utility_macros.h>
17 #include <IMP/Sampler.h>
18 #include <IMP/macros.h>
19 #include <IMP/Pointer.h>
20 #include <IMP/base_types.h>
21 IMPDOMINO_BEGIN_NAMESPACE
22 
23 //! A base class for discrete samplers in Domino2
24 /** All the samplers derived from it share some common properties:
25  - each particle is allowed to have one of a discrete set of
26  conformations, as stored in a ParticleStatesTable
27  - there is, optionally, one scoring function, accessed through
28  the SubsetEvaluatorTable
29  - there can be many SubsetFilterTable objects which are
30  used to prune the discrete space.
31 
32  Defaults are provided for all the parameters:
33  - if no SubsetFilterTables are provided, then the
34  ExclusionSubsetFilterTable and the
35  RestraintScoreSubsetFilterTable are used.
36 
37  \note the restraint scores must be non-negative in general.
38  If you are using restraints which can produce negative values,
39  we can provide a restraint which wraps another and makes
40  it non-negative. Ping us.
41 
42  \note The discrete samplers enumerate all acceptable
43  conformations. As a result, users should take care to
44  remove uninteresting degrees of freedom (for example,
45  remove rigid transformations of a complex). Techniques
46  to do this can involve pinning one or more particles (by
47  locking them to a single conformation or to a few
48  degrees of freedom).
49  */
50 class IMPDOMINOEXPORT DiscreteSampler : public Sampler {
53  bool restraints_set_;
54  Restraints rs_;
55  unsigned int max_;
56 
57  protected:
58  SubsetFilterTables get_subset_filter_tables_to_use(
59  const RestraintsTemp &rs, ParticleStatesTable *pst) const;
60  AssignmentsTable *get_assignments_table_to_use(
61  const SubsetFilterTables &sfts,
62  unsigned int max = std::numeric_limits<int>::max()) const;
63  virtual ConfigurationSet *do_sample() const IMP_OVERRIDE;
64  virtual Assignments do_get_sample_assignments(const Subset &all) const = 0;
65 
67  if (restraints_set_) {
68  return rs_;
69  } else {
70 /* Don't warn about deprecated get_root_restraint_set() every time someone
71  includes this header */
72 IMP_HELPER_MACRO_PUSH_WARNINGS
73 #if __GNUC__ > 4 || (__GNUC__ == 4 && __GNUC_MINOR__ > 5)
74 IMP_GCC_PRAGMA(diagnostic ignored "-Wdeprecated-declarations")
75 #endif
76  return RestraintsTemp(1, get_model()->get_root_restraint_set());
77 IMP_HELPER_MACRO_POP_WARNINGS
78  }
79  }
80 
81  public:
82  DiscreteSampler(Model *m, ParticleStatesTable *pst, std::string name);
83 
84  ~DiscreteSampler();
85 
86  //! Set the Restraints to use in the RestraintScoreSubsetFilterTable.
87  /** The default RestraintScoreSubsetFilterTable filters based on a set
88  of Restraints, which can be set here. (If not, the deprecated default
89  behavior is to use all Restraints in the Model.)
90  */
92  rs_ = rs;
93  restraints_set_ = true;
94  }
95 
96  /** Particle states can be set either using this method,
97  or equivalently, by accessing the table itself
98  using get_particle_states_table(). This method
99  is provided for users who want to use the default values
100  and want a simple interface.*/
102  pst_->set_particle_states(p, se);
103  }
104 
105  /** Return the Assignment objects describing the subsets fitting
106  the description.
107 
108  \note At the moment, Subset must be equal to
109  Subset(ParticleStatesTable::get_particles()).
110  */
111  Assignments get_sample_assignments(const Subset &s) const;
112 
113  /** \name Advanced
114  Default values are provided, you only need to replace these
115  if you want to do something special. See the overview of
116  the module for a general description.
117  @{
118  */
119  void set_particle_states_table(ParticleStatesTable *cse) { pst_ = cse; }
120  void set_assignments_table(AssignmentsTable *sst) { sst_ = sst; }
121  ParticleStatesTable *get_particle_states_table() const { return pst_; }
122  IMP_LIST_ACTION(public, SubsetFilterTable, SubsetFilterTables,
123  subset_filter_table, subset_filter_tables,
124  SubsetFilterTable *, SubsetFilterTables,
125  obj->set_was_used(true), , );
126  /** @} */
127 
128  /** Limit the number of states that is ever produced for any
129  set of particles.
130 
131  Doing this can be useful to get some feedback when too
132  many states would otherwise be produced. A warning
133  will be emitted whenever the limit eliminates states.
134  */
135  void set_maximum_number_of_assignments(unsigned int mx) { max_ = mx; }
136  unsigned int get_maximum_number_of_assignments() const { return max_; }
137 };
138 
140 
141 IMPDOMINO_END_NAMESPACE
142 
143 #endif /* IMPDOMINO_DISCRETE_SAMPLER_H */
Basic types used by IMP.
void set_particle_states(Particle *p, ParticleStates *se)
RestraintsTemp get_restraints(const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg, RestraintSet *rs)
A base class for discrete samplers in Domino2.
A Bayesian inference-based sampler.
Base class for all samplers.
Definition: Sampler.h:31
Represent a subset of the particles being optimized.
Definition: Subset.h:33
IMP::Vector< IMP::WeakPointer< Restraint > > RestraintsTemp
Definition: base_types.h:80
Various general useful macros for IMP.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
A Bayesian inference-based sampler.
void set_restraints(RestraintsAdaptor rs)
Set the Restraints to use in the RestraintScoreSubsetFilterTable.
void set_maximum_number_of_assignments(unsigned int mx)
Provide a consistent interface for things that take Restraints as arguments.
Definition: Restraint.h:230
Base class for all samplers.
Various general useful macros for IMP.
A smart pointer to a ref-counted Object that is a class member.
Definition: Pointer.h:146
A class to store a set of configurations of a model.
IMP::Vector< IMP::Pointer< SubsetFilterTable > > SubsetFilterTables
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing sets of objects.
Definition: object_macros.h:42
A nullptr-initialized pointer to an IMP Object.
Class to handle individual model particles.
Definition: Particle.h:37
A Bayesian inference-based sampler.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.