IMP logo
IMP Reference Guide  develop.d97d4ead1f,2024/11/21
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-2022 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 override;
64  virtual Assignments do_get_sample_assignments(const Subset &all) const = 0;
65 
67  if (restraints_set_) {
68  return rs_;
69  } else {
70  IMP_THROW("No restraints have been set. Use set_restraints().",
72  }
73  }
74 
75  public:
76  DiscreteSampler(Model *m, ParticleStatesTable *pst, std::string name);
77 
78  ~DiscreteSampler();
79 
80  //! Set the Restraints to use in the RestraintScoreSubsetFilterTable.
81  /** The default RestraintScoreSubsetFilterTable filters based on a set
82  of Restraints, which can be set here.
83  */
85  rs_ = rs;
86  restraints_set_ = true;
87  }
88 
89  /** Particle states can be set either using this method,
90  or equivalently, by accessing the table itself
91  using get_particle_states_table(). This method
92  is provided for users who want to use the default values
93  and want a simple interface.*/
95  pst_->set_particle_states(p, se);
96  }
97 
98  /** Return the Assignment objects describing the subsets fitting
99  the description.
100 
101  \note At the moment, Subset must be equal to
102  Subset(ParticleStatesTable::get_particles()).
103  */
104  Assignments get_sample_assignments(const Subset &s) const;
105 
106  /** \name Advanced
107  Default values are provided, you only need to replace these
108  if you want to do something special. See the overview of
109  the module for a general description.
110  @{
111  */
112  void set_particle_states_table(ParticleStatesTable *cse) { pst_ = cse; }
113  void set_assignments_table(AssignmentsTable *sst) { sst_ = sst; }
114  ParticleStatesTable *get_particle_states_table() const { return pst_; }
115  IMP_LIST_ACTION(public, SubsetFilterTable, SubsetFilterTables,
116  subset_filter_table, subset_filter_tables,
117  SubsetFilterTable *, SubsetFilterTables,
118  obj->set_was_used(true), , );
119  /** @} */
120 
121  /** Limit the number of states that is ever produced for any
122  set of particles.
123 
124  Doing this can be useful to get some feedback when too
125  many states would otherwise be produced. A warning
126  will be emitted whenever the limit eliminates states.
127  */
128  void set_maximum_number_of_assignments(unsigned int mx) { max_ = mx; }
129  unsigned int get_maximum_number_of_assignments() const { return max_; }
130 };
131 
133 
134 IMPDOMINO_END_NAMESPACE
135 
136 #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
Various general useful macros for IMP.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
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:362
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:143
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 lists of object pointers.
Definition: object_macros.h:44
#define IMP_THROW(message, exception_name)
Throw an exception with a message.
Definition: check_macros.h:50
A nullptr-initialized pointer to an IMP Object.
Class to handle individual particles of a Model object.
Definition: Particle.h:43
A Bayesian inference-based sampler.
An exception for an invalid value being passed to IMP.
Definition: exception.h:136