IMP  2.0.0
The Integrative Modeling Platform
DiscreteSampler.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/DiscreteSampler.h
3  * \brief A beyesian infererence-based sampler.
4  *
5  * Copyright 2007-2013 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"
17 #include <IMP/Sampler.h>
18 #include <IMP/macros.h>
19 #include <IMP/internal/OwnerPointer.h>
20 #include <IMP/base_types.h>
21 IMPDOMINO_BEGIN_NAMESPACE
22 
23 
24 //! A base class for discrete samplers in Domino2
25 /** All the samplers derived from it share some common properties:
26  - each particle is allowed to have one of a discrete set of
27  conformations, as stored in a ParticleStatesTable
28  - there is, optionally, one scoring function, accessed through
29  the SubsetEvaluatorTable
30  - there can be many SubsetFilterTable objects which are
31  used to prune the discrete space.
32 
33  Defaults are provided for all the parameters:
34  - if no SubsetFilterTables are provided, then the
35  ExclusionSubsetFilterTable and the
36  RestraintScoreSubsetFilterTable are used.
37 
38  \note the restraint scores must be non-negative in general.
39  If you are using restraints which can produce negative values,
40  we can provide a restraint which wraps another and makes
41  it non-negative. Ping us.
42 
43  \note The discrete samplers enumerate all acceptable
44  conformations. As a result, users should take care to
45  remove uninteresting degrees of freedom (for example,
46  remove rigid transformations of a complex). Techniques
47  to do this can involve pinning one or more particles (by
48  locking them to a single conformation or to a few
49  degrees of freedom).
50  */
51 class IMPDOMINOEXPORT DiscreteSampler : public Sampler
52 {
53  IMP::OwnerPointer<ParticleStatesTable> pst_;
54  IMP::OwnerPointer<AssignmentsTable> sst_;
55  unsigned int max_;
56 protected:
57  SubsetFilterTables get_subset_filter_tables_to_use
58  (const RestraintsTemp &rs,
59  ParticleStatesTable *pst) const;
60  AssignmentsTable* get_assignments_table_to_use
61  (const SubsetFilterTables &sfts,
62  unsigned int max=std::numeric_limits<int>::max())
63  const;
64  virtual ConfigurationSet* do_sample() const IMP_OVERRIDE;
65  virtual Assignments do_get_sample_assignments(const Subset& all)
66  const=0;
67 public:
68  DiscreteSampler(Model*m, ParticleStatesTable *pst, std::string name);
69 
70  ~DiscreteSampler();
71 
72  /** Particle states can be set either using this method,
73  or equivalently, by accessing the table itself
74  using get_particle_states_table(). This method
75  is provided for users who want to use the default values
76  and want a simple inferface.*/
78  pst_->set_particle_states(p, se);
79  }
80 
81  /** Return the Assignment objects describing the subsets fitting
82  the description.
83 
84  \note At the moment, Subset must be equal to
85  Subset(ParticleStatesTable::get_particles()).
86  */
87  Assignments get_sample_assignments(const Subset &s) const;
88 
89  /** \name Advanced
90  Default values are provided, you only need to replace these
91  if you want to do something special. See the overview of
92  the module for a general description.
93  @{
94  */
95  void set_particle_states_table(ParticleStatesTable *cse) {
96  pst_= cse;
97  }
98  void set_assignments_table(AssignmentsTable *sst) {
99  sst_=sst;
100  }
101  ParticleStatesTable* get_particle_states_table() const {
102  return pst_;
103  }
104  IMP_LIST_ACTION(public, SubsetFilterTable, SubsetFilterTables,
105  subset_filter_table, subset_filter_tables,
106  SubsetFilterTable*, SubsetFilterTables,
107  obj->set_was_used(true),,);
108  /** @} */
109 
110  /** Limit the number of states that is ever produced for any
111  set of particles.
112 
113  Doing this can be useful to get some feedback when too
114  many states would otherwise be produced. A warning
115  will be emitted whenever the limit eliminates states.
116  */
117  void set_maximum_number_of_assignments(unsigned int mx) {
118  max_=mx;
119  }
120  unsigned int get_maximum_number_of_assignments() const {
121  return max_;
122  }
123 };
124 
125 
127 
128 
129 IMPDOMINO_END_NAMESPACE
130 
131 #endif /* IMPDOMINO_DISCRETE_SAMPLER_H */