IMP logo
IMP Reference Guide  2.12.0
The Integrative Modeling Platform
domino/utility.h
Go to the documentation of this file.
1 /**
2  * \file IMP/domino/utility.h
3  * \brief Functions for helping optimize and understand DOMINO-based sampling.
4  *
5  * Copyright 2007-2019 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPDOMINO_UTILITY_H
9 #define IMPDOMINO_UTILITY_H
10 
11 #include <IMP/domino/domino_config.h>
12 #include "Assignment.h"
13 #include "Subset.h"
14 #include "particle_states.h"
15 #include <IMP/Particle.h>
16 #include <IMP/SingletonContainer.h>
17 #include <IMP/RestraintSet.h>
18 #include <IMP/Model.h>
19 #include <IMP/container/internal/ClosePairContainer.h>
20 #include <IMP/display/Writer.h>
21 #include <IMP/dependency_graph.h>
23 
24 #ifdef IMP_DOMINO_USE_IMP_RMF
25 #include <RMF/HDF5/Group.h>
26 #endif
27 
28 IMPKERNEL_BEGIN_NAMESPACE
29 class Model;
30 class Particle;
31 IMPKERNEL_END_NAMESPACE
32 
33 IMPDOMINO_BEGIN_NAMESPACE
34 
35 class AssignmentsTable;
36 class AssignmentContainer;
37 class SubsetFilterTable;
38 
39 /** \name Debug tools
40 
41  We provide a number of different functions for helping
42  optimize and understand domino-based sampling. These functions
43  expose part of the implementation and are liable to change
44  without notice.
45  @{
46  */
47 
48 class ParticleStatesTable;
49 
50 //! Load the appropriate state for each particle in a Subset.
51 IMPDOMINOEXPORT void load_particle_states(const Subset &s, const Assignment &ss,
52  const ParticleStatesTable *pst);
53 
54 /** Return a list of all restraints from rs that
55  do not depend on any particle in pst->get_particles() that is not in s.
56  The dependency graph is passed for efficiency.
57 */
58 IMPDOMINOEXPORT RestraintsTemp get_restraints(
59  const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg,
60  RestraintSet *rs);
61 
62 /** @} */
63 
64 /** If the passed particles are all contained in the Subset and are
65  not contained any of the Subsets in excluded, then return a list
66  of indices given the location of each passed particle in the passed subset.
67  That is
68  \code
69  particles[i]==subset[returned[i]];
70  \endcode
71  Otherwise return an empty list.
72 
73  This function is designed to be used for implementing SubsetFilterTable
74  classes.
75 */
76 IMPDOMINOEXPORT Ints get_index(const ParticlesTemp &particles,
77  const Subset &subset, const Subsets &excluded);
78 
79 /** For each of the passed particles, if it is contained in the Subset and
80  not contained in any of the Subsets in excluded, return the index of that
81  particle in the passed subset; otherwise, return -1. A list of all such
82  indexes is returned. Compare with get_index().
83 
84  This function is designed to be used for implementing SubsetFilterTable
85  classes.
86 */
87 IMPDOMINOEXPORT Ints get_partial_index(const ParticlesTemp &particles,
88  const Subset &subset,
89  const Subsets &excluded);
90 
91 /** Return the list of interactions implied by the passed balls
92  given the allowed positions specified by the ParticleStatesTable.
93 */
95  const ParticlesTemp &ps, double max_distance,
96  ParticleStatesTable *pst);
97 
98 //! Return an embedding for an assignment
99 IMPDOMINOEXPORT algebra::VectorKD get_embedding(const Subset &s,
100  const Assignment &a,
101  ParticleStatesTable *pst);
102 
103 //! Return the nearest assignment from an embedding
104 IMPDOMINOEXPORT Assignment
105  get_nearest_assignment(const Subset &s, const algebra::VectorKD &embedding,
106  ParticleStatesTable *pst);
107 
108 /** Return a distance between two assignments if they are less than
109  a threshold. The distance returned is the l2 norm on the distances
110  between each state as given by the corresponding metric. If no
111  metric is passed, then the l2 norm on the embedding is used.
112  \unstable{get_distance_if_close}
113  */
114 inline double get_distance_if_smaller_than(const Subset &s, const Assignment &a,
115  const Assignment &b,
116  ParticleStatesTable *pst,
117  const statistics::Metrics &metrics,
118  double max) {
119  IMP_USAGE_CHECK(a.size() == b.size(),
120  "Dimensions of embeddings don't match.");
121  double d = 0;
122  for (unsigned int i = 0; i < a.size(); ++i) {
123  double cur;
124  if (!metrics.empty() && metrics[i]) {
125  cur = square(metrics[i]->get_distance(a[i], b[i]));
126  } else {
127  algebra::VectorKD ea =
128  pst->get_particle_states(s[i])->get_embedding(a[i]);
129  algebra::VectorKD eb =
130  pst->get_particle_states(s[i])->get_embedding(b[i]);
131  cur = (ea - eb).get_squared_magnitude();
132  }
133  d += cur;
134  if (d > square(max)) {
135  IMP_LOG_VERBOSE("Returning " << std::sqrt(d) << " > " << max << " for "
136  << a << " and " << b << std::endl);
137  return std::sqrt(d);
138  }
139  }
140  IMP_LOG_VERBOSE("Distance between " << a << " and " << b << " is "
141  << std::sqrt(d) << std::endl);
142  return std::sqrt(d);
143 }
144 
145 IMPDOMINO_END_NAMESPACE
146 
147 #endif /* IMPDOMINO_UTILITY_H */
A container for Singletons.
Used to hold a set of related restraints.
A Bayesian inference-based sampler.
IMP::Vector< Subset > Subsets
Definition: Subset.h:76
RestraintsTemp get_restraints(const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg, RestraintSet *rs)
boost::graph DependencyGraph
A directed graph on the interactions between the various objects in the model.
Storage of a model, its restraints, constraints and particles.
Assignment get_nearest_assignment(const Subset &s, const algebra::VectorKD &embedding, ParticleStatesTable *pst)
Return the nearest assignment from an embedding.
double get_distance_if_smaller_than(const Subset &s, const Assignment &a, const Assignment &b, ParticleStatesTable *pst, const statistics::Metrics &metrics, double max)
#define IMP_LOG_VERBOSE(expr)
Definition: log_macros.h:94
Represent a subset of the particles being optimized.
Definition: Subset.h:33
IMP::Vector< IMP::WeakPointer< Restraint > > RestraintsTemp
Definition: base_types.h:80
A more IMP-like version of the std::vector.
Definition: Vector.h:39
ParticlePairsTemp get_possible_interactions(const ParticlesTemp &ps, double max_distance, ParticleStatesTable *pst)
Cluster sets of points.
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
virtual algebra::VectorKD get_embedding(unsigned int i) const
Return an embedding of the state.
Ints get_partial_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Base class for writing geometry to a file.
algebra::VectorKD get_embedding(const Subset &s, const Assignment &a, ParticleStatesTable *pst)
Return an embedding for an assignment.
A Bayesian inference-based sampler.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Store a configuration of a subset.
Definition: Assignment.h:32
IMP::Vector< ParticlePair > ParticlePairsTemp
Definition: base_types.h:139
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition: types.h:49
VectorD<-1 > VectorKD
Definition: VectorD.h:437
void load_particle_states(const Subset &s, const Assignment &ss, const ParticleStatesTable *pst)
Load the appropriate state for each particle in a Subset.
A Bayesian inference-based sampler.
Build dependency graphs on models.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.