RMF
uncertainty.h
Go to the documentation of this file.
1 /**
2  * \file RMF/decorator/uncertainty.h
3  * \brief Helper functions for manipulating RMF files.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef RMF_UNCERTAINTY_DECORATORS_H
10 #define RMF_UNCERTAINTY_DECORATORS_H
11 
12 #include <RMF/config.h>
14 #include <RMF/NodeHandle.h>
15 #include <RMF/FileHandle.h>
16 #include <RMF/Decorator.h>
17 #include <RMF/constants.h>
18 #include <RMF/Vector.h>
19 #include <RMF/internal/paths.h>
20 #include <array>
21 #include <boost/lexical_cast.hpp>
22 
23 RMF_ENABLE_WARNINGS
24 namespace RMF {
25 namespace decorator {
26 
27 
28  /** See also Scale and ScaleFactory.
29  */
30  class ScaleConst: public Decorator {
31  friend class ScaleFactory;
32  protected:
33  FloatKey scale_;
34 FloatKey scale_lower_;
35 FloatKey scale_upper_;
37  FloatKey scale,
38 FloatKey scale_lower,
39 FloatKey scale_upper):
40  Decorator(nh),
41 scale_(scale),
42 scale_lower_(scale_lower),
43 scale_upper_(scale_upper) {
44  }
45  public:
46 
47  Float get_scale() const {
48  try {
49  return get_node().get_value(scale_);
50  } RMF_DECORATOR_CATCH( );
51  }
52  Float get_frame_scale() const {
53  try {
54  return get_node().get_frame_value(scale_);
55  } RMF_DECORATOR_CATCH( );
56  }
57  Float get_static_scale() const {
58  try {
59  return get_node().get_static_value(scale_);
60  } RMF_DECORATOR_CATCH( );
61  }
62 
63 
64  Float get_lower() const {
65  try {
66  return get_node().get_value(scale_lower_);
67  } RMF_DECORATOR_CATCH( );
68  }
69  Float get_frame_lower() const {
70  try {
71  return get_node().get_frame_value(scale_lower_);
72  } RMF_DECORATOR_CATCH( );
73  }
74  Float get_static_lower() const {
75  try {
76  return get_node().get_static_value(scale_lower_);
77  } RMF_DECORATOR_CATCH( );
78  }
79 
80 
81  Float get_upper() const {
82  try {
83  return get_node().get_value(scale_upper_);
84  } RMF_DECORATOR_CATCH( );
85  }
86  Float get_frame_upper() const {
87  try {
88  return get_node().get_frame_value(scale_upper_);
89  } RMF_DECORATOR_CATCH( );
90  }
91  Float get_static_upper() const {
92  try {
93  return get_node().get_static_value(scale_upper_);
94  } RMF_DECORATOR_CATCH( );
95  }
96 
97  static std::string get_decorator_type_name() {
98  return "ScaleConst";
99  }
100  RMF_SHOWABLE(ScaleConst, "Scale: " << get_node());
101  };
102  /** See also ScaleFactory.
103  */
104  class Scale: public ScaleConst {
105  friend class ScaleFactory;
106  Scale(NodeHandle nh,
107  FloatKey scale,
108 FloatKey scale_lower,
109 FloatKey scale_upper):
110  ScaleConst(nh, scale,
111 scale_lower,
112 scale_upper) {
113  }
114  public:
115 
116  void set_scale(Float v) {
117  try {
118  get_node().set_value(scale_, v);
119  } RMF_DECORATOR_CATCH( );
120  }
121  void set_frame_scale(Float v) {
122  try {
123  get_node().set_frame_value(scale_, v);
124  } RMF_DECORATOR_CATCH( );
125  }
126  void set_static_scale(Float v) {
127  try {
128  get_node().set_static_value(scale_, v);
129  } RMF_DECORATOR_CATCH( );
130  }
131 
132 
133  void set_lower(Float v) {
134  try {
135  get_node().set_value(scale_lower_, v);
136  } RMF_DECORATOR_CATCH( );
137  }
138  void set_frame_lower(Float v) {
139  try {
140  get_node().set_frame_value(scale_lower_, v);
141  } RMF_DECORATOR_CATCH( );
142  }
143  void set_static_lower(Float v) {
144  try {
145  get_node().set_static_value(scale_lower_, v);
146  } RMF_DECORATOR_CATCH( );
147  }
148 
149 
150  void set_upper(Float v) {
151  try {
152  get_node().set_value(scale_upper_, v);
153  } RMF_DECORATOR_CATCH( );
154  }
155  void set_frame_upper(Float v) {
156  try {
157  get_node().set_frame_value(scale_upper_, v);
158  } RMF_DECORATOR_CATCH( );
159  }
160  void set_static_upper(Float v) {
161  try {
162  get_node().set_static_value(scale_upper_, v);
163  } RMF_DECORATOR_CATCH( );
164  }
165 
166  static std::string get_decorator_type_name() {
167  return "Scale";
168  }
169  };
170 
171 
172  /** Create decorators of type Scale.
173  */
174  class ScaleFactory: public Factory {
175  Category cat_;
176 FloatKey scale_;
177 FloatKey scale_lower_;
178 FloatKey scale_upper_;
179 
180 
181 
182  public:
184  cat_(fh.get_category("uncertainty")),
185  scale_(fh.get_key<FloatTag>(cat_, "scale")), scale_lower_(fh.get_key<FloatTag>(cat_, "scale lower")), scale_upper_(fh.get_key<FloatTag>(cat_, "scale upper")) {
186  }
188  cat_(fh.get_category("uncertainty")),
189  scale_(fh.get_key<FloatTag>(cat_, "scale")), scale_lower_(fh.get_key<FloatTag>(cat_, "scale lower")), scale_upper_(fh.get_key<FloatTag>(cat_, "scale upper")) {
190  }
191  /** Get a ScaleConst for nh.*/
192  ScaleConst get(NodeConstHandle nh) const {
193  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
194  + boost::lexical_cast<std::string>(nh.get_type())
195  + "\" in decorator type Scale");
196  return ScaleConst(nh, scale_,
197 scale_lower_,
198 scale_upper_);
199  }
200  /** Get a Scale for nh.*/
201  Scale get(NodeHandle nh) const {
202  RMF_USAGE_CHECK((nh.get_type() == RMF::REPRESENTATION), std::string("Bad node type. Got \"")
203  + boost::lexical_cast<std::string>(nh.get_type())
204  + "\" in decorator type Scale");
205  return Scale(nh, scale_,
206 scale_lower_,
207 scale_upper_);
208  }
209  /** Check whether nh has all the attributes required to be a
210  ScaleConst.*/
211  bool get_is(NodeConstHandle nh) const {
212  return (nh.get_type() == RMF::REPRESENTATION)
213  && !nh.get_value(scale_).get_is_null();
214  }
215  bool get_is_static(NodeConstHandle nh) const {
216  return (nh.get_type() == RMF::REPRESENTATION)
217  && !nh.get_static_value(scale_).get_is_null()
218  && !nh.get_static_value(scale_lower_).get_is_null()
219  && !nh.get_static_value(scale_upper_).get_is_null();
220  }
221  RMF_SHOWABLE(ScaleFactory, "ScaleFactory");
222  };
223  #ifndef RMF_DOXYGEN
224 struct ScaleConstFactory: public ScaleFactory {
225  ScaleConstFactory(FileConstHandle fh):
226  ScaleFactory(fh) {
227  }
228  ScaleConstFactory(FileHandle fh):
229  ScaleFactory(fh) {
230  }
231 
232 };
233  #endif
234 
235 
236 
237 } /* namespace decorator */
238 } /* namespace RMF */
239 RMF_DISABLE_WARNINGS
240 
241 #endif /* RMF_UNCERTAINTY_DECORATORS_H */
Mostly empty base classes for decorators and factories.
const NodeType REPRESENTATION
Represent part of a molecule.
A handle for a particular node in the hierarchy.
Definition: NodeHandle.h:60
float Float
Definition: types.h:33
The base class for decorators.
Definition: Decorator.h:29
NodeType get_type() const
get the type of this node
Various constants.
A handle for a particular node in a read-only hierarchy.
A handle for a read-only RMF file.
void set_value(ID< Tag > k, typename Tag::ArgumentType v) const
Definition: NodeHandle.h:115
A handle for an RMF file.
Definition: FileHandle.h:54
The base class for Factories.
Definition: Decorator.h:46
Declaration for RMF::FileHandle.
Represent coordinates.
Declaration of NodeHandle.
void set_static_value(ID< Tag > k, typename Tag::ArgumentType v) const
set the value of the attribute k for all frames.
Definition: NodeHandle.h:122
ID< Tag > get_key(Category category, std::string name) const
Various general useful macros for IMP.
bool get_is(NodeConstHandle nh) const
Definition: uncertainty.h:211
void set_frame_value(ID< Tag > k, typename Tag::ArgumentType v) const
set the value of the attribute k for this node on the current frame.
Definition: NodeHandle.h:103