IMP logo
IMP Reference Guide  2.19.0
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  //! Add an int value referenced by the given key
52  void add_int(std::string key, int value);
53 
54  //! Get the number of int that have been added
55  unsigned get_number_of_int() const { return int_.size(); }
56 
57  //! Get the key for the ith int mapping
58  std::string get_int_key(unsigned i) const { return int_[i].first; }
59 
60  //! Get the value for the ith int mapping
61  int get_int_value(unsigned i) const {
62  return int_[i].second;
63  }
64 
65  //! Add a float value referenced by the given key
66  void add_float(std::string key, double value);
67 
68  //! Get the number of float that have been added
69  unsigned get_number_of_float() const { return float_.size(); }
70 
71  //! Get the key for the ith float mapping
72  std::string get_float_key(unsigned i) const { return float_[i].first; }
73 
74  //! Get the value for the ith float mapping
75  double get_float_value(unsigned i) const {
76  return float_[i].second;
77  }
78 
79  //! Add a string value referenced by the given key
80  void add_string(std::string key, std::string value);
81 
82  //! Get the number of string that have been added
83  unsigned get_number_of_string() const { return string_.size(); }
84 
85  //! Get the key for the ith string mapping
86  std::string get_string_key(unsigned i) const { return string_[i].first; }
87 
88  //! Get the value for the ith string mapping
89  std::string get_string_value(unsigned i) const {
90  return string_[i].second;
91  }
92 
93  //! Add a filename value referenced by the given key
94  /** Filenames are treated similarly to strings but the caller is expected
95  to make them absolute paths before adding them here. When written to
96  file they may be converted to paths relative to the file.
97  */
98  void add_filename(std::string key, std::string value);
99 
100  //! Get the number of filename that have been added
101  unsigned get_number_of_filename() const { return filename_.size(); }
102 
103  //! Get the key for the ith filename mapping
104  std::string get_filename_key(unsigned i) const { return filename_[i].first; }
105 
106  //! Get the value for the ith filename mapping
107  std::string get_filename_value(unsigned i) const {
108  return filename_[i].second;
109  }
110 
111  //! Add a list of Float values referenced by the given key
112  void add_floats(std::string key, Floats value);
113 
114  //! Get the number of Floats that have been added
115  unsigned get_number_of_floats() const { return floats_.size(); }
116 
117  //! Get the key for the ith Floats mapping
118  std::string get_floats_key(unsigned i) const { return floats_[i].first; }
119 
120  //! Get the value for the ith Floats mapping
121  Floats get_floats_value(unsigned i) const {
122  return floats_[i].second;
123  }
124 
125  //! Add a list of Int values referenced by the given key
126  void add_ints(std::string key, Ints value);
127 
128  //! Get the number of Ints that have been added
129  unsigned get_number_of_ints() const { return ints_.size(); }
130 
131  //! Get the key for the ith Ints mapping
132  std::string get_ints_key(unsigned i) const { return ints_[i].first; }
133 
134  //! Get the value for the ith Ints mapping
135  Ints get_ints_value(unsigned i) const {
136  return ints_[i].second;
137  }
138 
139  //! Add a list of string values referenced by the given key
140  void add_strings(std::string key, Strings value);
141 
142  //! Get the number of strings that have been added
143  unsigned get_number_of_strings() const { return strings_.size(); }
144 
145  //! Get the key for the ith strings mapping
146  std::string get_strings_key(unsigned i) const {
147  return strings_[i].first;
148  }
149 
150  //! Get the value for the ith strings mapping
151  Strings get_strings_value(unsigned i) const {
152  return strings_[i].second;
153  }
154 
155  //! Add a list of filename values referenced by the given key
156  /** Filenames are treated similarly to strings but the caller is expected
157  to make them absolute paths before adding them here. When written to
158  file they may be converted to paths relative to the file.
159  */
160  void add_filenames(std::string key, Strings value);
161 
162  //! Get the number of filenames that have been added
163  unsigned get_number_of_filenames() const { return filenames_.size(); }
164 
165  //! Get the key for the ith filenames mapping
166  std::string get_filenames_key(unsigned i) const {
167  return filenames_[i].first;
168  }
169 
170  //! Get the value for the ith filenames mapping
171  Strings get_filenames_value(unsigned i) const {
172  return filenames_[i].second;
173  }
174 
175  //! Add ParticleIndexes referenced by the given key
176  void add_particle_indexes(std::string key, ParticleIndexes value);
177 
178  //! Get the number of ParticleIndexes that have been added
179  unsigned get_number_of_particle_indexes() const { return pis_.size(); }
180 
181  //! Get the key for the ith ParticleIndexes mapping
182  std::string get_particle_indexes_key(unsigned i) const {
183  return pis_[i].first;
184  }
185 
186  //! Get the value for the ith ParticleIndexes mapping
188  return pis_[i].second;
189  }
190 
192 
193 private:
194  typedef std::pair<std::string, int> IntData;
195  std::vector<IntData> int_;
196 
197  typedef std::pair<std::string, double> FloatData;
198  std::vector<FloatData> float_;
199 
200  typedef std::pair<std::string, std::string> StringData;
201  std::vector<StringData> string_, filename_;
202 
203  typedef std::pair<std::string, Floats> FloatsData;
204  std::vector<FloatsData> floats_;
205 
206  typedef std::pair<std::string, Ints> IntsData;
207  std::vector<IntsData> ints_;
208 
209  typedef std::pair<std::string, Strings> StringsData;
210  std::vector<StringsData> strings_;
211  std::vector<StringsData> filenames_;
212 
213  typedef std::pair<std::string, ParticleIndexes> ParticleIndexesData;
214  std::vector<ParticleIndexesData> pis_;
215 };
216 
217 IMPKERNEL_END_NAMESPACE
218 
219 #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.
Definition: RestraintInfo.h:89
double get_float_value(unsigned i) const
Get the value for the ith float mapping.
Definition: RestraintInfo.h:75
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:61
std::string get_float_key(unsigned i) const
Get the key for the ith float mapping.
Definition: RestraintInfo.h:72
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:69
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:83
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:58
unsigned get_number_of_int() const
Get the number of int that have been added.
Definition: RestraintInfo.h:55
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:86
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.