IMP logo
IMP Reference Guide  2.6.1
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-2016 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 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  are 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 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 /** All of the passed particles are not contained in an ofthe Subsets
80  in excluded, then return a a list of indices given the location of
81  each passed particle in the passed subset or -1 if it is missing.
82 
83  This function is designed to be used for implementing SubsetFilterTable
84  classes.
85 */
86 IMPDOMINOEXPORT Ints get_partial_index(const ParticlesTemp &particles,
87  const Subset &subset,
88  const Subsets &excluded);
89 
90 /** Return the list of interactions implied by the passed balls
91  given the allowed positions specified by the ParticleStatesTable.
92 */
94  const ParticlesTemp &ps, double max_distance,
95  ParticleStatesTable *pst);
96 
97 //! Return an embedding for an assignment
98 IMPDOMINOEXPORT algebra::VectorKD get_embedding(const Subset &s,
99  const Assignment &a,
100  ParticleStatesTable *pst);
101 
102 //! Return the nearest assignment from an embedding
103 IMPDOMINOEXPORT Assignment
104  get_nearest_assignment(const Subset &s, const algebra::VectorKD &embedding,
105  ParticleStatesTable *pst);
106 
107 /** Return a distance between two assignments if they are less than
108  a threshold. The distance returned is the l2 norm on the distances
109  between each state as given by the corresponding metric. If no
110  metric is passed, then the l2 norm on the embedding is used.
111  \unstable{get_distance_if_close}
112  */
113 inline double get_distance_if_smaller_than(const Subset &s, const Assignment &a,
114  const Assignment &b,
115  ParticleStatesTable *pst,
116  const statistics::Metrics &metrics,
117  double max) {
118  IMP_USAGE_CHECK(a.size() == b.size(),
119  "Dimensions of embeddings don't match.");
120  double d = 0;
121  for (unsigned int i = 0; i < a.size(); ++i) {
122  double cur;
123  if (!metrics.empty() && metrics[i]) {
124  cur = square(metrics[i]->get_distance(a[i], b[i]));
125  } else {
126  algebra::VectorKD ea =
127  pst->get_particle_states(s[i])->get_embedding(a[i]);
128  algebra::VectorKD eb =
129  pst->get_particle_states(s[i])->get_embedding(b[i]);
130  cur = (ea - eb).get_squared_magnitude();
131  }
132  d += cur;
133  if (d > square(max)) {
134  IMP_LOG_VERBOSE("Returning " << std::sqrt(d) << " > " << max << " for "
135  << a << " and " << b << std::endl);
136  return std::sqrt(d);
137  }
138  }
139  IMP_LOG_VERBOSE("Distance between " << a << " and " << b << " is "
140  << std::sqrt(d) << std::endl);
141  return std::sqrt(d);
142 }
143 
144 IMPDOMINO_END_NAMESPACE
145 
146 #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
ParticlePairsTemp get_possible_interactions(const ParticlesTemp &ps, double max_distance, ParticleStatesTable *pst)
Cluster sets of points.
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:63
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:411
void load_particle_states(const Subset &s, const Assignment &ss, const ParticleStatesTable *pst)
A Bayesian inference-based sampler.
Build dependency graphs on models.