IMP logo
IMP Reference Guide  develop.63b38c487d,2024/12/22
The Integrative Modeling Platform
AVNetworkRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/bff/AVNetworkRestraint.h
3  * \brief Simple restraint for networks of accessible volumes.
4  *
5  * \authors Thomas-Otavio Peulen
6  * Copyright 2007-2022 IMP Inventors. All rights reserved.
7  *
8  */
9 
10 #ifndef IMPBFF_AVNETWORKRESTRAINT_H
11 #define IMPBFF_AVNETWORKRESTRAINT_H
12 
13 #include <IMP/bff/bff_config.h>
15 
16 #include <IMP/Model.h>
17 #include <IMP/Restraint.h>
18 #include <IMP/Object.h>
19 #include <IMP/Pointer.h>
20 #include <IMP/atom/Hierarchy.h>
21 #include <IMP/UnaryFunction.h>
22 
23 #include <IMP/bff/AV.h>
24 #include <IMP/bff/internal/FPSReaderWriter.h>
25 #include <IMP/bff/internal/json.h>
26 
27 #include <vector>
28 #include <algorithm>
29 
30 IMPBFF_BEGIN_NAMESPACE
31 
32 
33 
34 /**
35  * @class AVNetworkRestraint
36  * @brief A restraint that uses an annotated volumetric network to score particle distances.
37  *
38  * The AVNetworkRestraint class represents a restraint that utilizes an annotated volumetric network
39  * to score distances between particles. It is designed to be used with the IMP library.
40  *
41  * The restraint is initialized with a hierarchy, a filename of a fps.json file, a name, and an optional
42  * score set. The hierarchy is used to obtain the particles involved in the restraint. The fps.json file
43  * contains the annotated volumetric network data. The name parameter is used to assign a name to the restraint.
44  * The score set parameter specifies the name of the score in the fps.json file to be used for scoring. If no
45  * score set is provided, all distances are used for scoring.
46  */
47 class IMPBFFEXPORT AVNetworkRestraint : public IMP::Restraint {
48 
49 private:
50 
51  /**
52  * @brief Number of random samples in distance computation
53  *
54  * The number of random samples used to compute a distance.
55  * larger numbers increase the precision of the distance computation.
56  */
57  int n_samples = 50000;
58 
59  /**
60  * @brief Map of AVs used to compute the score.
61  *
62  * This map stores the AVs used to compute the score. The keys are the names of the AVs,
63  * and the values are pointers to the AV objects.
64  */
65  std::map<std::string, IMP::bff::AV*> avs_{};
66 
67  /**
68  * @brief ParticleIndexes of AVs used to compute the score.
69  *
70  * This list stores the ParticleIndexes of AVs used to compute the score. These ParticleIndexes
71  * correspond to the AVs stored in the `avs_` map.
72  */
73  IMP::ParticleIndexes av_pi_;
74 
75  /**
76  * @brief ParticleIndexes of particles contributing to the score.
77  *
78  * This list stores the ParticleIndexes of particles that contribute to the score computation.
79  * These particles are not necessarily AVs.
80  */
81  IMP::ParticleIndexes model_ps_;
82 
83  /// Map of experimental distance measurements (incl. errors)
84  std::map<std::string, AVPairDistanceMeasurement> distances_;
85 
86  /// Find and decorate labeled particles with accessible volume (AVs)
87  /** This is method is automatically called by the constructor.
88  * You only need to call this if you change parameters of
89  * AVs (e.g., the linker length).
90  */
91  std::map<std::string, IMP::bff::AV*> create_av_decorated_particles(
92  nlohmann::json used_positions,
93  const IMP::core::Hierarchy &hier);
94 
95  /**
96  * Get the accessible volume (AV) for a labeled particle.
97  * @param name The name of the labeled particle.
98  * @return The AV associated with the labeled particle.
99  */
100  IMP::bff::AV* get_av(std::string name) const;
101 
102 public:
103 
104  /**
105  * @brief Constructs an AVNetworkRestraint object.
106  * @param[in] hier The hierarchy used to obtain particles.
107  * @param[in] fps_json_fn The filename of the fps.json file.
108  * @param[in] name The name of this restraint. Default is "AVNetworkRestraint%1%".
109  * @param[in] score_set The name of the score in the fps.json file. If not provided, all distances are used for scoring.
110  */
112  const IMP::core::Hierarchy &hier,
113  std::string fps_json_fn,
114  std::string name = "AVNetworkRestraint%1%",
115  std::string score_set = "",
116  int n_samples = 50000
117  );
118 
119  /**
120  * @brief Returns exp(score).
121  * @return The exponential of the score.
122  */
123  double get_probability() const {
124  return exp(-unprotected_evaluate(nullptr));
125  }
126 
127  /**
128  * @brief Returns the used Atom::AVs.
129  * @return The used Atom::AVs.
130  */
131  const IMP::bff::AVs get_used_avs();
132 
133  /**
134  * @brief Returns the used experimental distances.
135  * @return The used experimental distances.
136  */
137  const std::map<std::string, AVPairDistanceMeasurement> get_used_distances(){
138  return distances_;
139  }
140 
141  /**
142  * @brief Returns the model distance (or FRET efficiency) between two dyes.
143  * @param[in] position1_name The name of the first dye position.
144  * @param[in] position2_name The name of the second dye position.
145  * @param[in] forster_radius The Förster radius.
146  * @param[in] distance_type The type of distance calculation.
147  * @return The model distance (or FRET efficiency) between the two dyes.
148  */
149  double get_model_distance(
150  std::string position1_name,
151  std::string position2_name,
152  double forster_radius,
153  int distance_type
154  ) const;
155 
156 
157  /**
158  * @brief Returns the particle indexes of the AVs.
159  * @return The particle indexes.
160  */
162  return av_pi_;
163  }
164 
165  /**
166  * @brief Evaluates the restraint.
167  * @param[in] accum The derivative accumulator.
168  * @return The score of the restraint.
169  */
170  virtual double unprotected_evaluate(IMP::DerivativeAccumulator *accum) const override;
171 
172  /**
173  * @brief Returns the inputs required by the restraint.
174  * @return The inputs required by the restraint.
175  */
176  virtual IMP::ModelObjectsTemp do_get_inputs() const override;
177 
178  /**
179  * @brief Prints a description of the restraint.
180  * @param[in] out The output stream.
181  */
182  void show(std::ostream &out) const {out << "AVNetwork restraint";}
183 
185 
186 };
187 
188 
189 IMPBFF_END_NAMESPACE
190 
191 
192 #endif //IMPBFF_AVNETWORKRESTRAINT_H
Various important macros for implementing decorators.
A decorator for a particle with accessible volume (AV).
Definition: AV.h:94
Simple Accessible Volume decorator.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Single variable function.
Storage of a model, its restraints, constraints and particles.
virtual double unprotected_evaluate(DerivativeAccumulator *da) const
Return the unweighted score for the restraint.
void show(std::ostream &out) const
Prints a description of the restraint.
A restraint that uses an annotated volumetric network to score particle distances.
Decorator for helping deal with a hierarchy of molecules.
ParticleIndexes const get_indexes()
Returns the particle indexes of the AVs.
double get_probability() const
Returns exp(score).
A nullptr-initialized pointer to an IMP Object.
const std::map< std::string, AVPairDistanceMeasurement > get_used_distances()
Returns the used experimental distances.
A shared base class to help in debugging and things.
Abstract base class for all restraints.
A decorator for helping deal with a generalized hierarchy.
virtual ModelObjectsTemp do_get_inputs() const =0
Class for adding derivatives from restraints to the model.
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:56