IMP  2.0.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 to get report statistics about the used attributes.
4  *
5  * Copyright 2007-2013 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/core/internal/CoreClosePairContainer.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 
29 IMPKERNEL_BEGIN_NAMESPACE
30 class Model;
31 class Particle;
32 IMPKERNEL_END_NAMESPACE
33 
34 IMPDOMINO_BEGIN_NAMESPACE
35 
36 class AssignmentsTable;
37 class AssignmentContainer;
38 class SubsetFilterTable;
39 
40 /** \name Debug tools
41 
42  We provide a number of different functions for helpering
43  optimize and understand domino-based sampling. These functions
44  are expose part of the implementation and are liable to change
45  without notice.
46  @{
47  */
48 
49 class ParticleStatesTable;
50 
51 
52 /** Load the appropriate state for each particle in a Subset. */
53 IMPDOMINOEXPORT void load_particle_states(const Subset &s,
54  const Assignment &ss,
55  const ParticleStatesTable *pst);
56 
57 
58 
59 /** Return a list of all restraints from rs that
60  - do not depend on any particle in pst->get_particles() that is not in s
61  The dependency graph is passed for efficiency.
62 */
63 IMPDOMINOEXPORT RestraintsTemp get_restraints(const Subset &s,
64  const ParticleStatesTable *pst,
65  const DependencyGraph &dg,
66  RestraintSet *rs);
67 
68 
69 /** @} */
70 
71 
72 /** If the passed particles are all contained in the Subset and are
73  not contained any of the Subsets in excluded, then return a a list
74  of indices given the location of each passed particle in the passed subset.
75  That is
76  \code
77  particles[i]==subset[returned[i]];
78  \endcode
79  Otherwise return an empty list.
80 
81  This function is designed to be used for implementing SubsetFilterTable
82  classes.
83 */
84 IMPDOMINOEXPORT Ints get_index(const ParticlesTemp &particles,
85  const Subset &subset, const Subsets &excluded);
86 
87 /** All of the passed particles are not contained in an ofthe Subsets
88  in excluded, then return a a list of indices given the location of
89  each passed particle in the passed subset or -1 if it is missing.
90 
91  This function is designed to be used for implementing SubsetFilterTable
92  classes.
93 */
94 IMPDOMINOEXPORT Ints get_partial_index(const ParticlesTemp &particles,
95  const Subset &subset, const Subsets &excluded);
96 
97 
98 
99 /** Return the list of interactions implied by the passed balls
100  given the allowed positions specified by the ParticleStatesTable.
101 */
102 IMPDOMINOEXPORT
103 ParticlePairsTemp get_possible_interactions(const ParticlesTemp &ps,
104  double max_distance,
105  ParticleStatesTable *pst);
106 
107 //! Return an embedding for an assignment
108 IMPDOMINOEXPORT algebra::VectorKD get_embedding(const Subset &s,
109  const Assignment &a,
110  ParticleStatesTable *pst);
111 
112 //! Return the nearest assignment from an embedding
113 IMPDOMINOEXPORT Assignment
114 get_nearest_assignment(const Subset &s,
115  const algebra::VectorKD &embedding,
116  ParticleStatesTable *pst);
117 
118 
119 /** Return a distance between two assignments if they are less than
120  a threshold. The distance returned is the l2 norm on the distances
121  between each state as given by the corresponding metric. If no
122  metric is passed, then the l2 norm on the embedding is used.
123  \unstable{get_distance_if_close}
124  */
125 inline double get_distance_if_smaller_than(const Subset &s,
126  const Assignment &a,
127  const Assignment &b,
128  ParticleStatesTable *pst,
129  const statistics::Metrics &metrics,
130  double max) {
131  IMP_USAGE_CHECK(a.size()==b.size(),
132  "Dimensions of embeddings don't match.");
133  double d=0;
134  for (unsigned int i=0; i< a.size(); ++i) {
135  double cur;
136  if (!metrics.empty() && metrics[i]) {
137  cur= square(metrics[i]->get_distance(a[i], b[i]));
138  } else {
140  = pst->get_particle_states(s[i])->get_embedding(a[i]);
142  = pst->get_particle_states(s[i])->get_embedding(b[i]);
143  cur= (ea-eb).get_squared_magnitude();
144  }
145  d+= cur;
146  if (d > square(max)) {
147  IMP_LOG_VERBOSE( "Returning " << std::sqrt(d) << " > " << max
148  << " for " << a << " and " << b
149  << std::endl);
150  return std::sqrt(d);
151  }
152  }
153  IMP_LOG_VERBOSE( "Distance between " << a << " and "
154  << b << " is " << std::sqrt(d) << std::endl);
155  return std::sqrt(d);
156 }
157 
158 IMPDOMINO_END_NAMESPACE
159 
160 #endif /* IMPDOMINO_UTILITY_H */