IMP logo
IMP Reference Guide  2.20.2
The Integrative Modeling Platform
RestraintInfo.h
Go to the documentation of this file.
1 /**
2  * \file IMP/RestraintInfo.h
3  * \brief Report key:value information on restraints
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPKERNEL_RESTRAINT_INFO_H
10 #define IMPKERNEL_RESTRAINT_INFO_H
11 
12 #include <IMP/kernel_config.h>
13 #include <IMP/Object.h>
14 #include <IMP/types.h>
15 #include <IMP/base_types.h>
16 
17 IMPKERNEL_BEGIN_NAMESPACE
18 
19 //! Report key:value information on restraints
20 /** These objects are typically returned by Restraint::get_static_info()
21  or Restraint::get_dynamic_info() and are used to report information
22  about a Restraint instance as a set of key:value pairs. The primary
23  purpose is to allow restraints to be written to files, such as RMF.
24 
25  Key names are generally lowercase, full words, space-separated, for
26  example "force constant" rather than "force_constant", "ForceConstant",
27  or "k".
28 
29  Values can be simple types (int, float, string) or lists of them;
30  filename(s) (treated similarly to strings but paths are made relative
31  to that of the output file); or particles.
32 
33  Note that when written to RMF files, RMF stores both string and filename
34  keys as strings. To help it distinguish the two, the convention is
35  for filename key names to end in "filename" or "filenames".
36 
37  Particle index values are generally used for one of two purposes.
38  First, to reference particles that contain restraint
39  information (either static or dynamic) that often exist
40  outside of the molecular hierarchy, such as Bayesian nuisances
41  or Gaussians for an EM density map. Second, to explicitly group or
42  sort restraint particles (as the default list of restraint inputs is
43  unsorted and does not contain duplicates) such as each endpoint of
44  a pairwise restraint, or the two groups of particles in a bipartite
45  restraint. The particles must live in the same model as the restraint.
46  */
47 class IMPKERNELEXPORT RestraintInfo : public Object {
48 public:
49  RestraintInfo(std::string name = "RestraintInfo %1%") : Object(name) {}
50 
51  // Clear all data
52  void clear() {
53  int_.clear();
54  ints_.clear();
55  float_.clear();
56  floats_.clear();
57  string_.clear();
58  strings_.clear();
59  filename_.clear();
60  filenames_.clear();
61  pis_.clear();
62  }
63 
64  //! Add an int value referenced by the given key
65  void add_int(std::string key, int value);
66 
67  //! Get the number of int that have been added
68  unsigned get_number_of_int() const { return int_.size(); }
69 
70  //! Get the key for the ith int mapping
71  std::string get_int_key(unsigned i) const { return int_[i].first; }
72 
73  //! Get the value for the ith int mapping
74  int get_int_value(unsigned i) const {
75  return int_[i].second;
76  }
77 
78  //! Add a float value referenced by the given key
79  void add_float(std::string key, double value);
80 
81  //! Get the number of float that have been added
82  unsigned get_number_of_float() const { return float_.size(); }
83 
84  //! Get the key for the ith float mapping
85  std::string get_float_key(unsigned i) const { return float_[i].first; }
86 
87  //! Get the value for the ith float mapping
88  double get_float_value(unsigned i) const {
89  return float_[i].second;
90  }
91 
92  //! Add a string value referenced by the given key
93  void add_string(std::string key, std::string value);
94 
95  //! Get the number of string that have been added
96  unsigned get_number_of_string() const { return string_.size(); }
97 
98  //! Get the key for the ith string mapping
99  std::string get_string_key(unsigned i) const { return string_[i].first; }
100 
101  //! Get the value for the ith string mapping
102  std::string get_string_value(unsigned i) const {
103  return string_[i].second;
104  }
105 
106  //! Add a filename value referenced by the given key
107  /** Filenames are treated similarly to strings but the caller is expected
108  to make them absolute paths before adding them here. When written to
109  file they may be converted to paths relative to the file.
110  */
111  void add_filename(std::string key, std::string value);
112 
113  //! Get the number of filename that have been added
114  unsigned get_number_of_filename() const { return filename_.size(); }
115 
116  //! Get the key for the ith filename mapping
117  std::string get_filename_key(unsigned i) const { return filename_[i].first; }
118 
119  //! Get the value for the ith filename mapping
120  std::string get_filename_value(unsigned i) const {
121  return filename_[i].second;
122  }
123 
124  //! Add a list of Float values referenced by the given key
125  void add_floats(std::string key, Floats value);
126 
127  //! Get the number of Floats that have been added
128  unsigned get_number_of_floats() const { return floats_.size(); }
129 
130  //! Get the key for the ith Floats mapping
131  std::string get_floats_key(unsigned i) const { return floats_[i].first; }
132 
133  //! Get the value for the ith Floats mapping
134  Floats get_floats_value(unsigned i) const {
135  return floats_[i].second;
136  }
137 
138  //! Add a list of Int values referenced by the given key
139  void add_ints(std::string key, Ints value);
140 
141  //! Get the number of Ints that have been added
142  unsigned get_number_of_ints() const { return ints_.size(); }
143 
144  //! Get the key for the ith Ints mapping
145  std::string get_ints_key(unsigned i) const { return ints_[i].first; }
146 
147  //! Get the value for the ith Ints mapping
148  Ints get_ints_value(unsigned i) const {
149  return ints_[i].second;
150  }
151 
152  //! Add a list of string values referenced by the given key
153  void add_strings(std::string key, Strings value);
154 
155  //! Get the number of strings that have been added
156  unsigned get_number_of_strings() const { return strings_.size(); }
157 
158  //! Get the key for the ith strings mapping
159  std::string get_strings_key(unsigned i) const {
160  return strings_[i].first;
161  }
162 
163  //! Get the value for the ith strings mapping
164  Strings get_strings_value(unsigned i) const {
165  return strings_[i].second;
166  }
167 
168  //! Add a list of filename values referenced by the given key
169  /** Filenames are treated similarly to strings but the caller is expected
170  to make them absolute paths before adding them here. When written to
171  file they may be converted to paths relative to the file.
172  */
173  void add_filenames(std::string key, Strings value);
174 
175  //! Get the number of filenames that have been added
176  unsigned get_number_of_filenames() const { return filenames_.size(); }
177 
178  //! Get the key for the ith filenames mapping
179  std::string get_filenames_key(unsigned i) const {
180  return filenames_[i].first;
181  }
182 
183  //! Get the value for the ith filenames mapping
184  Strings get_filenames_value(unsigned i) const {
185  return filenames_[i].second;
186  }
187 
188  //! Add ParticleIndexes referenced by the given key
189  void add_particle_indexes(std::string key, ParticleIndexes value);
190 
191  //! Get the number of ParticleIndexes that have been added
192  unsigned get_number_of_particle_indexes() const { return pis_.size(); }
193 
194  //! Get the key for the ith ParticleIndexes mapping
195  std::string get_particle_indexes_key(unsigned i) const {
196  return pis_[i].first;
197  }
198 
199  //! Get the value for the ith ParticleIndexes mapping
201  return pis_[i].second;
202  }
203 
205 
206 private:
207  typedef std::pair<std::string, int> IntData;
208  std::vector<IntData> int_;
209 
210  typedef std::pair<std::string, double> FloatData;
211  std::vector<FloatData> float_;
212 
213  typedef std::pair<std::string, std::string> StringData;
214  std::vector<StringData> string_, filename_;
215 
216  typedef std::pair<std::string, Floats> FloatsData;
217  std::vector<FloatsData> floats_;
218 
219  typedef std::pair<std::string, Ints> IntsData;
220  std::vector<IntsData> ints_;
221 
222  typedef std::pair<std::string, Strings> StringsData;
223  std::vector<StringsData> strings_;
224  std::vector<StringsData> filenames_;
225 
226  typedef std::pair<std::string, ParticleIndexes> ParticleIndexesData;
227  std::vector<ParticleIndexesData> pis_;
228 };
229 
230 IMPKERNEL_END_NAMESPACE
231 
232 #endif /* IMPKERNEL_RESTRAINT_INFO_H */
Basic types used by IMP.
Basic types used by IMP.
unsigned get_number_of_filenames() const
Get the number of filenames that have been added.
std::string get_string_value(unsigned i) const
Get the value for the ith string mapping.
double get_float_value(unsigned i) const
Get the value for the ith float mapping.
Definition: RestraintInfo.h:88
unsigned get_number_of_filename() const
Get the number of filename that have been added.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
std::string get_strings_key(unsigned i) const
Get the key for the ith strings mapping.
std::string get_filename_key(unsigned i) const
Get the key for the ith filename mapping.
int get_int_value(unsigned i) const
Get the value for the ith int mapping.
Definition: RestraintInfo.h:74
std::string get_float_key(unsigned i) const
Get the key for the ith float mapping.
Definition: RestraintInfo.h:85
Floats get_floats_value(unsigned i) const
Get the value for the ith Floats mapping.
std::string get_filename_value(unsigned i) const
Get the value for the ith filename mapping.
std::string get_ints_key(unsigned i) const
Get the key for the ith Ints mapping.
ParticleIndexes get_particle_indexes_value(unsigned i) const
Get the value for the ith ParticleIndexes mapping.
Strings get_strings_value(unsigned i) const
Get the value for the ith strings mapping.
std::string get_filenames_key(unsigned i) const
Get the key for the ith filenames mapping.
Common base class for heavy weight IMP objects.
Definition: Object.h:111
std::string get_floats_key(unsigned i) const
Get the key for the ith Floats mapping.
unsigned get_number_of_float() const
Get the number of float that have been added.
Definition: RestraintInfo.h:82
unsigned get_number_of_particle_indexes() const
Get the number of ParticleIndexes that have been added.
unsigned get_number_of_string() const
Get the number of string that have been added.
Definition: RestraintInfo.h:96
unsigned get_number_of_strings() const
Get the number of strings that have been added.
Report key:value information on restraints.
Definition: RestraintInfo.h:47
std::string get_int_key(unsigned i) const
Get the key for the ith int mapping.
Definition: RestraintInfo.h:71
unsigned get_number_of_int() const
Get the number of int that have been added.
Definition: RestraintInfo.h:68
A shared base class to help in debugging and things.
std::string get_particle_indexes_key(unsigned i) const
Get the key for the ith ParticleIndexes mapping.
Object(std::string name)
Construct an object with the given name.
std::string get_string_key(unsigned i) const
Get the key for the ith string mapping.
Definition: RestraintInfo.h:99
unsigned get_number_of_floats() const
Get the number of Floats that have been added.
unsigned get_number_of_ints() const
Get the number of Ints that have been added.
Ints get_ints_value(unsigned i) const
Get the value for the ith Ints mapping.
Strings get_filenames_value(unsigned i) const
Get the value for the ith filenames mapping.