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