IMP  2.3.0
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::decorator::ExplicitResolutionFactory explicit_resolution_factory_;
41  RMF::IntKey external_rigid_body_key_;
42  struct Data {
43  internal::HierarchyLoadStatic load_static;
44  internal::HierarchyLoadBonds load_bonds;
45  internal::HierarchyLoadXYZs load_xyzs;
46  internal::HierarchyLoadGaussians load_gaussians;
47  internal::HierarchyLoadRigidBodies load_rigid_bodies;
48  Data(RMF::FileConstHandle h)
49  : load_static(h),
50  load_bonds(h),
51  load_xyzs(h),
52  load_gaussians(h),
53  load_rigid_bodies(h) {}
54  };
55  typedef boost::unordered_map<kernel::ParticleIndex, boost::shared_ptr<Data> >
56  DM;
57  DM data_;
58  virtual bool get_is(RMF::NodeConstHandle nh) const IMP_OVERRIDE {
59  return nh.get_type() == RMF::REPRESENTATION;
60  }
61  virtual void add_link_recursive(kernel::Model *m, kernel::ParticleIndex root,
63  RMF::NodeConstHandle node,
64  kernel::ParticleIndexes rigid_bodies,
65  Data &data);
66 
67  virtual void do_add_link(kernel::Particle *o,
68  RMF::NodeConstHandle node) IMP_FINAL IMP_OVERRIDE;
69  using P::do_create;
70  virtual kernel::Particle *do_create(RMF::NodeConstHandle name,
72  void create_recursive(kernel::Model *m, kernel::ParticleIndex root,
73  kernel::ParticleIndex cur, RMF::NodeConstHandle name,
74  kernel::ParticleIndexes rigid_bodies, Data &data);
75  virtual void do_load_one(RMF::NodeConstHandle nh,
77 
78  protected:
79  /** This method is called for the hierarchy.*/
80  virtual void do_load_hierarchy(RMF::NodeConstHandle root_node,
82  IMP_UNUSED(root_node);
83  IMP_UNUSED(m);
84  IMP_UNUSED(root);
85  }
86  /** Overload this to take specific action on creating
87  a member of the hierarchy.
88  \unstable{do_create_recursive} */
91  RMF::NodeConstHandle node) {
92  IMP_UNUSED(m);
93  IMP_UNUSED(root);
94  IMP_UNUSED(cur);
95  IMP_UNUSED(node);
96  }
97 
98  /** Overload this to take specific action on linking
99  a member of the hierarchy.
100  \unstable{do_add_link_recursive} */
103  RMF::NodeConstHandle node) {
104  IMP_UNUSED(root);
105  IMP_UNUSED(m);
106  IMP_UNUSED(cur);
107  IMP_UNUSED(node);
108  }
109 
110  public:
111  HierarchyLoadLink(RMF::FileConstHandle fh);
112 
113  static const char *get_name() { return "atom load"; }
114 
116 };
117 
118 /** Manage the save link between an RMF file and an atom::Hierarchy.
119 
120  \unstable{HierarchySaveLink}
121  */
122 class IMPRMFEXPORT HierarchySaveLink : public SimpleSaveLink<kernel::Particle> {
124  struct Data {
125  internal::HierarchySaveStatic save_static;
126  internal::HierarchySaveBonds save_bonds;
127  internal::HierarchySaveXYZs save_xyzs;
128  internal::HierarchySaveGaussians save_gaussians;
129  internal::HierarchySaveRigidBodies save_rigid_bodies;
130  Data(RMF::FileHandle h)
131  : save_static(h),
132  save_bonds(h),
133  save_xyzs(h),
134  save_gaussians(h),
135  save_rigid_bodies(h) {}
136  };
137  typedef boost::unordered_map<kernel::ParticleIndex, boost::shared_ptr<Data> >
138  DM;
139  DM data_;
140  RMF::decorator::AlternativesFactory af_;
141  RMF::decorator::ExplicitResolutionFactory explicit_resolution_factory_;
142  RMF::IntKey external_rigid_body_key_;
143 
144  void add_recursive(Model *m, kernel::ParticleIndex root,
146  kernel::ParticleIndexes rigid_bodies, RMF::NodeHandle cur,
147  Data &data);
148  virtual void do_add(kernel::Particle *p, RMF::NodeHandle cur) IMP_OVERRIDE;
149  virtual void do_save_one(kernel::Particle *o,
150  RMF::NodeHandle nh) IMP_OVERRIDE;
151  RMF::NodeType get_type(kernel::Particle *) const {
152  return RMF::REPRESENTATION;
153  }
154 
155  protected:
156  /** Override to add extra data for nodes. */
158  kernel::ParticleIndex p, RMF::NodeHandle n) {
159  IMP_UNUSED(m);
160  IMP_UNUSED(root);
161  IMP_UNUSED(p);
162  IMP_UNUSED(n);
163  }
164  /** Override to add extra data for nodes. */
166  RMF::NodeHandle root_node) {
167  IMP_UNUSED(m);
168  IMP_UNUSED(root);
169  IMP_UNUSED(root_node);
170  }
171 
172  public:
173  HierarchySaveLink(RMF::FileHandle fh);
174  static const char *get_name() { return "atom save"; }
176 };
177 
178 IMPRMF_END_NAMESPACE
179 
180 #endif /* IMPRMF_ATOM_LINKS_H */
Various general useful macros for IMP.
Key< 1, true > IntKey
The type used to identify int attributes in the Particles.
#define IMP_FINAL
Have the compiler report an error if anything overrides this method.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Various general useful macros for IMP.
Decorator for helping deal with a hierarchy of molecules.
#define IMP_UNUSED(variable)
Various general useful macros for IMP.
Class to handle individual model particles.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73