IMP  2.2.1
The Integrative Modeling Platform
atom_links.h
Go to the documentation of this file.
1 /**
2  * \file IMP/rmf/atom_links.h
3  * \brief Handle read/write of kernel::Model data from/to files.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPRMF_ATOM_LINKS_H
10 #define IMPRMF_ATOM_LINKS_H
11 
12 #include <IMP/rmf/rmf_config.h>
13 #include "simple_links.h"
14 #include "internal/atom_links_static.h"
15 #include "internal/atom_links_rigid_bodies.h"
16 #include "internal/atom_links_xyzs.h"
17 #include "internal/atom_links_gaussians.h"
18 #include <RMF/decorator/alternatives.h>
19 #include <IMP/base/object_macros.h>
21 #include <RMF/NodeHandle.h>
22 #include <RMF/FileHandle.h>
23 #include <IMP/atom/Hierarchy.h>
24 #include <IMP/rmf/links.h>
25 #include <IMP/rmf/link_macros.h>
26 #include <IMP/base/tuple_macros.h>
27 #include <RMF/decorators.h>
28 #include <boost/unordered_map.hpp>
29 IMPRMF_BEGIN_NAMESPACE
30 
31 /** Manage the loading link between an RMF file and an atom::Hierarchy.
32 
33  \unstable{HierarchyLoadLink}
34  */
35 class IMPRMFEXPORT HierarchyLoadLink : public SimpleLoadLink<kernel::Particle> {
37  RMF::decorator::IntermediateParticleFactory intermediate_particle_factory_;
38  RMF::decorator::ReferenceFrameFactory reference_frame_factory_;
39  RMF::decorator::AlternativesFactory af_;
40  RMF::IntKey external_rigid_body_key_;
41  struct Data {
42  internal::HierarchyLoadStatic load_static;
43  internal::HierarchyLoadBonds load_bonds;
44  internal::HierarchyLoadXYZs load_xyzs;
45  internal::HierarchyLoadGaussians load_gaussians;
46  internal::HierarchyLoadRigidBodies load_rigid_bodies;
47  Data(RMF::FileConstHandle h)
48  : load_static(h),
49  load_bonds(h),
50  load_xyzs(h),
51  load_gaussians(h),
52  load_rigid_bodies(h) {}
53  };
54  typedef boost::unordered_map<kernel::ParticleIndex, boost::shared_ptr<Data> >
55  DM;
56  DM data_;
57  virtual bool get_is(RMF::NodeConstHandle nh) const IMP_OVERRIDE {
58  return nh.get_type() == RMF::REPRESENTATION;
59  }
60  virtual void add_link_recursive(kernel::Model *m, kernel::ParticleIndex root,
62  RMF::NodeConstHandle node,
63  kernel::ParticleIndexes rigid_bodies,
64  Data &data);
65 
66  virtual void do_add_link(kernel::Particle *o,
67  RMF::NodeConstHandle node) IMP_FINAL IMP_OVERRIDE;
68  using P::do_create;
69  virtual kernel::Particle *do_create(RMF::NodeConstHandle name,
70  kernel::Model *m) IMP_FINAL IMP_OVERRIDE;
71  void create_recursive(kernel::Model *m, kernel::ParticleIndex root,
72  kernel::ParticleIndex cur, RMF::NodeConstHandle name,
73  kernel::ParticleIndexes rigid_bodies, Data &data);
74  virtual void do_load_one(RMF::NodeConstHandle nh,
75  kernel::Particle *o) IMP_FINAL IMP_OVERRIDE;
76 
77  protected:
78  /** This method is called for the hierarchy.*/
79  virtual void do_load_hierarchy(RMF::NodeConstHandle root_node,
81  IMP_UNUSED(root_node);
82  IMP_UNUSED(m);
83  IMP_UNUSED(root);
84  }
85  /** Overload this to take specific action on creating
86  a member of the hierarchy.
87  \unstable{do_create_recursive} */
90  RMF::NodeConstHandle node) {
91  IMP_UNUSED(m);
92  IMP_UNUSED(root);
93  IMP_UNUSED(cur);
94  IMP_UNUSED(node);
95  }
96 
97  /** Overload this to take specific action on linking
98  a member of the hierarchy.
99  \unstable{do_add_link_recursive} */
102  RMF::NodeConstHandle node) {
103  IMP_UNUSED(root);
104  IMP_UNUSED(m);
105  IMP_UNUSED(cur);
106  IMP_UNUSED(node);
107  }
108 
109  public:
110  HierarchyLoadLink(RMF::FileConstHandle fh);
111 
112  static const char *get_name() { return "atom load"; }
113 
115 };
116 
117 /** Manage the save link between an RMF file and an atom::Hierarchy.
118 
119  \unstable{HierarchySaveLink}
120  */
121 class IMPRMFEXPORT HierarchySaveLink : public SimpleSaveLink<kernel::Particle> {
123  struct Data {
124  internal::HierarchySaveStatic save_static;
125  internal::HierarchySaveBonds save_bonds;
126  internal::HierarchySaveXYZs save_xyzs;
127  internal::HierarchySaveGaussians save_gaussians;
128  internal::HierarchySaveRigidBodies save_rigid_bodies;
129  Data(RMF::FileHandle h)
130  : save_static(h),
131  save_bonds(h),
132  save_xyzs(h),
133  save_gaussians(h),
134  save_rigid_bodies(h) {}
135  };
136  typedef boost::unordered_map<kernel::ParticleIndex, boost::shared_ptr<Data> >
137  DM;
138  DM data_;
139  RMF::decorator::AlternativesFactory af_;
140  RMF::IntKey external_rigid_body_key_;
141 
142  void add_recursive(Model *m, kernel::ParticleIndex root,
144  kernel::ParticleIndexes rigid_bodies, RMF::NodeHandle cur,
145  Data &data);
146  virtual void do_add(kernel::Particle *p, RMF::NodeHandle cur) IMP_OVERRIDE;
147  virtual void do_save_one(kernel::Particle *o,
148  RMF::NodeHandle nh) IMP_OVERRIDE;
149  RMF::NodeType get_type(kernel::Particle *) const {
150  return RMF::REPRESENTATION;
151  }
152 
153  protected:
154  /** Override to add extra data for nodes. */
156  kernel::ParticleIndex p, RMF::NodeHandle n) {
157  IMP_UNUSED(m);
158  IMP_UNUSED(root);
159  IMP_UNUSED(p);
160  IMP_UNUSED(n);
161  }
162  /** Override to add extra data for nodes. */
164  RMF::NodeHandle root_node) {
165  IMP_UNUSED(m);
166  IMP_UNUSED(root);
167  IMP_UNUSED(root_node);
168  }
169 
170  public:
171  HierarchySaveLink(RMF::FileHandle fh);
172  static const char *get_name() { return "atom save"; }
174 };
175 
176 IMPRMF_END_NAMESPACE
177 
178 #endif /* IMPRMF_ATOM_LINKS_H */
Key< 1, true > IntKey
The type used to identify int attributes in the Particles.
#define IMP_UNUSED(variable)
Decorator for helping deal with a hierarchy of molecules.
Various general useful macros for IMP.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Various general useful macros for IMP.
Class to handle individual model particles.
Various general useful macros for IMP.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:72