RMF
TraverseHelper.h
Go to the documentation of this file.
1 /**
2  * \file RMF/TraverseHelper.h
3  * \brief A helper class for managing data when traversing an RMF.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef RMF_TRAVERSE_HELPER_H
10 #define RMF_TRAVERSE_HELPER_H
11 
12 #include <RMF/config.h>
13 #include "CoordinateTransformer.h"
14 #include "Nullable.h"
15 #include <RMF/decorator/physics.h>
16 #include <RMF/decorator/sequence.h>
17 #include <RMF/decorator/shape.h>
19 #include <memory>
20 
21 RMF_ENABLE_WARNINGS
22 
23 namespace RMF {
24 
25 class TraverseHelper;
26 typedef std::vector<TraverseHelper> TraverseHelpers;
27 
28 //! Track common data that one needs to keep as one traverses the hierarchy.
29 /** Things like residue index, chain id, and the local reference frame are all
30  properties of the path taken to reach a given node when traversing. This
31  class helps keep track of them.
32 
33  Feel free to request that other data types be added.
34 
35  \note In the case of non-default resolution with alternatives nodes, the
36  node this inherits from may not be the one you visited. So you should just
37  pass this object when you need to access the node.
38  */
39 class RMFEXPORT TraverseHelper : public NodeConstHandle {
40  struct Index : public RMF_LARGE_UNORDERED_MAP<NodeID, unsigned int> {};
41  std::shared_ptr<Index> active_;
42  struct Data {
43  decorator::ChainFactory chain_factory_;
44  decorator::ResidueFactory residue_factory_;
45  decorator::ReferenceFrameFactory reference_frame_factory_;
46  decorator::ColoredFactory colored_factory_;
47  decorator::AlternativesFactory alternatives_factory_;
48  decorator::StateFactory state_factory_;
49  decorator::CopyFactory copy_factory_;
50  int state_filter_;
51  CoordinateTransformer coordinate_transformer_;
52  Vector3 color_;
53  int residue_index_;
54  std::string residue_type_;
55  std::string chain_id_;
56  std::string molecule_name_;
57  unsigned int state_;
58  int copy_index_;
59  double resolution_;
60  Data(NodeConstHandle root, std::string molecule_name, double resolution,
61  int state_filter);
62  };
63  std::shared_ptr<Data> data_;
64 
65  void visit_impl(NodeConstHandle n);
66 
67  //! Return an updated TraverseHelper after inspecting the passed node.
68  TraverseHelper visit(NodeConstHandle n) const;
69 
70  public:
71  TraverseHelper() {}
72  TraverseHelper(NodeConstHandle root, std::string molecule_name,
73  double resolution = 10000, int state_filter = -1);
74 
75  //! Get the current chain id or None.
77  return Nullable<String>(data_->chain_id_);
78  }
79 
80  //! Get the current residue index or None.
82  return Nullable<Int>(data_->residue_index_);
83  }
84 
85  //! Get the current residue type or None.
87  return Nullable<String>(data_->residue_type_);
88  }
89 
90  //! Get the current molecule name or None.
91  std::string get_molecule_name() const { return data_->molecule_name_; }
92 
93  //! Get the current color or None.
95  return Nullable<Vector3>(data_->color_);
96  }
97 
98  //! Get the current state or 0.
99  unsigned int get_state_index() const { return data_->state_; }
100 
101  //! Get the current copy index or None.
103  return Nullable<Int>(data_->copy_index_);
104  }
105 
106  Vector3 get_global_coordinates(const Vector3 &v) {
107  return data_->coordinate_transformer_.get_global_coordinates(v);
108  }
109 
110  //! Set that the current node is displayed and return its index.
111  unsigned int set_is_displayed();
112 
113  bool get_is_displayed(NodeID n) { return active_->find(n) != active_->end(); }
114 
115  //! Return a unique id for the current particle.
116  unsigned int get_index(NodeID n) const;
117 
118  //! Return other nodes to traverse.
119  TraverseHelpers get_children() const;
120 };
121 
122 } /* namespace RMF */
123 
124 RMF_DISABLE_WARNINGS
125 
126 #endif /* RMF_TRAVERSE_HELPER_H */
std::string get_molecule_name() const
Get the current molecule name or None.
Helper functions for manipulating RMF files.
Nullable< String > get_residue_type() const
Get the current residue type or None.
int Index
Definition: HDF5/types.h:38
Transform coordinates into the global reference frame.
A handle for a particular node in a read-only hierarchy.
Helper functions for manipulating RMF files.
unsigned int get_state_index() const
Get the current state or 0.
Nullable< Vector3 > get_rgb_color() const
Get the current color or None.
Return a possibly null value.
Nullable< Int > get_copy_index() const
Get the current copy index or None.
ID< NodeTag > NodeID
Definition: ID.h:106
Helper functions for manipulating RMF files.
Nullable< Int > get_residue_index() const
Get the current residue index or None.
Nullable< String > get_chain_id() const
Get the current chain id or None.
Helper functions for manipulating RMF files.
Declare the RMF::CoordinateTransformer class.
A helper class for allowing nice return of possibly null values.
Track common data that one needs to keep as one traverses the hierarchy.