RMF
bond.h
Go to the documentation of this file.
1 /**
2  * \file RMF/decorator/bond.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_DECORATOR_BOND_H
10 #define RMF_DECORATOR_BOND_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 /** See also Bond and BondFactory.
28  */
29 class BondConst : public Decorator {
30  friend class BondFactory;
31  friend class Bond;
32  IntKey bonded_0_;
33  IntKey bonded_1_;
34  BondConst(NodeConstHandle nh, IntKey bonded_0, IntKey bonded_1)
35  : Decorator(nh), bonded_0_(bonded_0), bonded_1_(bonded_1) {}
36 
37  public:
38  NodeConstHandle get_bonded_0() const {
39  try {
40  return get_node().get_file().get_node(
41  NodeID(get_node().get_value(bonded_0_)));
42  }
43  RMF_DECORATOR_CATCH();
44  }
45  NodeConstHandle get_frame_bonded_0() const {
46  try {
47  return get_node().get_file().get_node(
48  NodeID(get_node().get_frame_value(bonded_0_)));
49  }
50  RMF_DECORATOR_CATCH();
51  }
52  NodeConstHandle get_static_bonded_0() const {
53  try {
54  return get_node().get_file().get_node(
55  NodeID(get_node().get_static_value(bonded_0_)));
56  }
57  RMF_DECORATOR_CATCH();
58  }
59 
60  NodeConstHandle get_bonded_1() const {
61  try {
62  return get_node().get_file().get_node(
63  NodeID(get_node().get_value(bonded_1_)));
64  }
65  RMF_DECORATOR_CATCH();
66  }
67  NodeConstHandle get_frame_bonded_1() const {
68  try {
69  return get_node().get_file().get_node(
70  NodeID(get_node().get_frame_value(bonded_1_)));
71  }
72  RMF_DECORATOR_CATCH();
73  }
74  NodeConstHandle get_static_bonded_1() const {
75  try {
76  return get_node().get_file().get_node(
77  NodeID(get_node().get_static_value(bonded_1_)));
78  }
79  RMF_DECORATOR_CATCH();
80  }
81 
82  static std::string get_decorator_type_name() { return "BondConst"; }
83  RMF_SHOWABLE(BondConst, "Bond: " << get_node());
84 };
85 /** See also BondFactory.
86  */
87 class Bond : public BondConst {
88  friend class BondFactory;
89  Bond(NodeHandle nh, IntKey bonded_0, IntKey bonded_1)
90  : BondConst(nh, bonded_0, bonded_1) {}
91 
92  public:
93 #ifndef RMF_DOXYGEN
94  void set_bonded_0(Int v) {
95  try {
96  get_node().set_value(bonded_0_, v);
97  }
98  RMF_DECORATOR_CATCH();
99  }
100  void set_frame_bonded_0(Int v) {
101  try {
102  get_node().set_frame_value(bonded_0_, v);
103  }
104  RMF_DECORATOR_CATCH();
105  }
106  void set_static_bonded_0(Int v) {
107  try {
108  get_node().set_static_value(bonded_0_, v);
109  }
110  RMF_DECORATOR_CATCH();
111  }
112 
113  void set_bonded_1(Int v) {
114  try {
115  get_node().set_value(bonded_1_, v);
116  }
117  RMF_DECORATOR_CATCH();
118  }
119  void set_frame_bonded_1(Int v) {
120  try {
121  get_node().set_frame_value(bonded_1_, v);
122  }
123  RMF_DECORATOR_CATCH();
124  }
125  void set_static_bonded_1(Int v) {
126  try {
127  get_node().set_static_value(bonded_1_, v);
128  }
129  RMF_DECORATOR_CATCH();
130  }
131 #endif
132 
133  NodeHandle get_bonded_0() const {
134  try {
135  return get_node().get_file().get_node(
136  NodeID(get_node().get_value(bonded_0_)));
137  }
138  RMF_DECORATOR_CATCH();
139  }
140  NodeHandle get_frame_bonded_0() const {
141  try {
142  return get_node().get_file().get_node(
143  NodeID(get_node().get_frame_value(bonded_0_)));
144  }
145  RMF_DECORATOR_CATCH();
146  }
147  NodeHandle get_static_bonded_0() const {
148  try {
149  return get_node().get_file().get_node(
150  NodeID(get_node().get_static_value(bonded_0_)));
151  }
152  RMF_DECORATOR_CATCH();
153  }
154 
155  NodeHandle get_bonded_1() const {
156  try {
157  return get_node().get_file().get_node(
158  NodeID(get_node().get_value(bonded_1_)));
159  }
160  RMF_DECORATOR_CATCH();
161  }
162  NodeHandle get_frame_bonded_1() const {
163  try {
164  return get_node().get_file().get_node(
165  NodeID(get_node().get_frame_value(bonded_1_)));
166  }
167  RMF_DECORATOR_CATCH();
168  }
169  NodeHandle get_static_bonded_1() const {
170  try {
171  return get_node().get_file().get_node(
172  NodeID(get_node().get_static_value(bonded_1_)));
173  }
174  RMF_DECORATOR_CATCH();
175  }
176 
177  void set_bonded_0(NodeConstHandle v) {
178  try {
179  get_node().set_value(bonded_0_, v.get_id().get_index());
180  }
181  RMF_DECORATOR_CATCH();
182  }
183  void set_frame_bonded_0(NodeConstHandle v) {
184  try {
185  get_node().set_frame_value(bonded_0_, v.get_id().get_index());
186  }
187  RMF_DECORATOR_CATCH();
188  }
189  void set_static_bonded_0(NodeConstHandle v) {
190  try {
191  get_node().set_static_value(bonded_0_, v.get_id().get_index());
192  }
193  RMF_DECORATOR_CATCH();
194  }
195 
196  void set_bonded_1(NodeConstHandle v) {
197  try {
198  get_node().set_value(bonded_1_, v.get_id().get_index());
199  }
200  RMF_DECORATOR_CATCH();
201  }
202  void set_frame_bonded_1(NodeConstHandle v) {
203  try {
204  get_node().set_frame_value(bonded_1_, v.get_id().get_index());
205  }
206  RMF_DECORATOR_CATCH();
207  }
208  void set_static_bonded_1(NodeConstHandle v) {
209  try {
210  get_node().set_static_value(bonded_1_, v.get_id().get_index());
211  }
212  RMF_DECORATOR_CATCH();
213  }
214 
215  static std::string get_decorator_type_name() { return "Bond"; }
216 };
217 
218 /** Create decorators of type Bond.
219  */
220 class BondFactory : public Factory {
221  Category cat_;
222  IntKey bonded_0_;
223  IntKey bonded_1_;
224 
225  public:
227  : cat_(fh.get_category("physics")),
228  bonded_0_(fh.get_key<IntTag>(cat_, "bonded 0")),
229  bonded_1_(fh.get_key<IntTag>(cat_, "bonded 1")) {}
231  : cat_(fh.get_category("physics")),
232  bonded_0_(fh.get_key<IntTag>(cat_, "bonded 0")),
233  bonded_1_(fh.get_key<IntTag>(cat_, "bonded 1")) {}
234  /** Get a BondConst for nh.*/
235  BondConst get(NodeConstHandle nh) const {
236  RMF_USAGE_CHECK((nh.get_type() == RMF::BOND),
237  std::string("Bad node type. Got \"") +
238  boost::lexical_cast<std::string>(nh.get_type()) +
239  "\" in decorator type Bond");
240  return BondConst(nh, bonded_0_, bonded_1_);
241  }
242  /** Get a Bond for nh.*/
243  Bond get(NodeHandle nh) const {
244  RMF_USAGE_CHECK((nh.get_type() == RMF::BOND),
245  std::string("Bad node type. Got \"") +
246  boost::lexical_cast<std::string>(nh.get_type()) +
247  "\" in decorator type Bond");
248  return Bond(nh, bonded_0_, bonded_1_);
249  }
250  /** Check whether nh has all the attributes required to be a
251  BondConst.*/
252  bool get_is(NodeConstHandle nh) const {
253  return (nh.get_type() == RMF::BOND) &&
254  !nh.get_value(bonded_0_).get_is_null();
255  }
256  bool get_is_static(NodeConstHandle nh) const {
257  return (nh.get_type() == RMF::BOND) &&
258  !nh.get_static_value(bonded_0_).get_is_null() &&
259  !nh.get_static_value(bonded_1_).get_is_null();
260  }
261  RMF_SHOWABLE(BondFactory, "BondFactory");
262 };
263 #ifndef RMF_DOXYGEN
264 struct BondConstFactory : public BondFactory {
265  BondConstFactory(FileConstHandle fh) : BondFactory(fh) {}
266  BondConstFactory(FileHandle fh) : BondFactory(fh) {}
267 };
268 #endif
269 
270 } /* namespace decorator */
271 } /* namespace RMF */
272 RMF_DISABLE_WARNINGS
273 
274 #endif /* RMF_DECORATOR_BOND_H */
Mostly empty base classes for decorators and factories.
NodeID get_id() const
A handle for a particular node in the hierarchy.
Definition: NodeHandle.h:60
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
ID< NodeTag > NodeID
Definition: ID.h:106
Declaration for RMF::FileHandle.
Represent coordinates.
Declaration of NodeHandle.
bool get_is(NodeConstHandle nh) const
Definition: bond.h:252
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
int Int
Definition: types.h:29
Various general useful macros for IMP.
const NodeType BOND
A link between two atoms.
NodeHandle get_node(NodeID id) const
Return a NodeHandle from a NodeID.
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