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
23RMF_ENABLE_WARNINGS
24namespace RMF {
25namespace decorator {
26
27
28 /** See also Scale and ScaleFactory.
29 */
30 class ScaleConst: public Decorator {
31 friend class ScaleFactory;
32 protected:
33 FloatKey scale_;
34FloatKey scale_lower_;
35FloatKey scale_upper_;
36 ScaleConst(NodeConstHandle nh,
37 FloatKey scale,
38FloatKey scale_lower,
39FloatKey scale_upper):
40 Decorator(nh),
41scale_(scale),
42scale_lower_(scale_lower),
43scale_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,
108FloatKey scale_lower,
109FloatKey scale_upper):
110 ScaleConst(nh, scale,
111scale_lower,
112scale_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_;
176FloatKey scale_;
177FloatKey scale_lower_;
178FloatKey scale_upper_;
179
180
181
182 public:
183 ScaleFactory(FileConstHandle fh):
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 }
187 ScaleFactory(FileHandle fh):
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.*/
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_,
197scale_lower_,
198scale_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_,
206scale_lower_,
207scale_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
224struct 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 */
239RMF_DISABLE_WARNINGS
240
241#endif /* RMF_UNCERTAINTY_DECORATORS_H */
Mostly empty base classes for decorators and factories.
Declaration for RMF::FileHandle.
Declaration of NodeHandle.
Represent coordinates.
The base class for Factories.
Definition Decorator.h:46
A handle for a read-only RMF file.
A handle for an RMF file.
Definition FileHandle.h:54
A handle for a particular node in a read-only hierarchy.
NodeType get_type() const
get the type of this node
A handle for a particular node in the hierarchy.
Definition NodeHandle.h:60
Scale get(NodeHandle nh) const
bool get_is(NodeConstHandle nh) const
ScaleConst get(NodeConstHandle nh) const
Various constants.
Various general useful macros for IMP.
See Decorators and Attributes for more information.
The namespace for all functionality in the library.
ID< CategoryTag > Category
Definition ID.h:110
float Float
Definition types.h:33
ID< FloatTag > FloatKey
Definition keys.h:41
const NodeType REPRESENTATION
Represent part of a molecule.