IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
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>
17#include <IMP/RestraintSet.h>
18#include <IMP/Model.h>
19#include <IMP/container/internal/ClosePairContainer.h>
20#include <IMP/display/Writer.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
31IMPKERNEL_BEGIN_NAMESPACE
32class Model;
33class Particle;
34IMPKERNEL_END_NAMESPACE
35
36IMPDOMINO_BEGIN_NAMESPACE
37
38class AssignmentsTable;
39class AssignmentContainer;
40class 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
51class ParticleStatesTable;
52
53//! Load the appropriate state for each particle in a Subset.
54IMPDOMINOEXPORT 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*/
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*/
79IMPDOMINOEXPORT 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*/
90IMPDOMINOEXPORT 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,
100
101//! Return an embedding for an assignment
102IMPDOMINOEXPORT algebra::VectorKD get_embedding(const Subset &s,
103 const Assignment &a,
105
106//! Return the nearest assignment from an embedding
107IMPDOMINOEXPORT Assignment
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 */
117inline double get_distance_if_smaller_than(const Subset &s, const Assignment &a,
118 const Assignment &b,
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 {
131 pst->get_particle_states(s[i])->get_embedding(a[i]);
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
148IMPDOMINO_END_NAMESPACE
149
150#endif /* IMPDOMINO_UTILITY_H */
A Bayesian inference-based sampler.
Storage of a model, its restraints, constraints and particles.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Used to hold a set of related restraints.
A container for Singletons.
A Bayesian inference-based sampler.
Base class for writing geometry to a file.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Object used to hold a set of restraints.
Store a configuration of a subset.
Definition Assignment.h:35
Represent a subset of the particles being optimized.
Definition Subset.h:34
Build dependency graphs on models.
#define IMP_LOG_VERBOSE(expr)
Definition log_macros.h:83
Cluster sets of points.
void load_particle_states(const Subset &s, const Assignment &ss, const ParticleStatesTable *pst)
Load the appropriate state for each particle in a Subset.
algebra::VectorKD get_embedding(const Subset &s, const Assignment &a, ParticleStatesTable *pst)
Return an embedding for an assignment.
double get_distance_if_smaller_than(const Subset &s, const Assignment &a, const Assignment &b, ParticleStatesTable *pst, const statistics::Metrics &metrics, double max)
Ints get_partial_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
ParticlePairsTemp get_possible_interactions(const ParticlesTemp &ps, double max_distance, ParticleStatesTable *pst)
RestraintsTemp get_restraints(const Subset &s, const ParticleStatesTable *pst, const DependencyGraph &dg, RestraintSet *rs)
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Assignment get_nearest_assignment(const Subset &s, const algebra::VectorKD &embedding, ParticleStatesTable *pst)
Return the nearest assignment from an embedding.
IMP::Vector< Subset > Subsets
Definition Subset.h:76
IMP::Vector< IMP::Pointer< Metric > > Metrics
Definition Metric.h:42
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition types.h:48
IMP::Vector< IMP::WeakPointer< Restraint > > RestraintsTemp
Definition base_types.h:120
VectorD<-1 > VectorKD
Definition VectorD.h:423
IMP::Vector< ParticlePair > ParticlePairsTemp
Definition base_types.h:181
boost::graph DependencyGraph
Directed graph on the interactions between the various objects in the model.
double get_distance(const VectorD< D > &v1, const VectorD< D > &v2)
Compute the distance between two vectors.
Definition VectorD.h:195
A Bayesian inference-based sampler.