IMP  2.1.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-2013 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_global_coordinates.h"
16 #include "internal/atom_links_static_coordinates.h"
17 #include "internal/atom_links_local_coordinates.h"
18 #include <IMP/base/object_macros.h>
20 #include <RMF/NodeHandle.h>
21 #include <RMF/FileHandle.h>
22 #include <IMP/atom/Hierarchy.h>
23 #include <IMP/rmf/links.h>
24 #include <IMP/rmf/link_macros.h>
25 #include <IMP/base/tuple_macros.h>
26 #include <RMF/decorators.h>
27 #include <IMP/base/map.h>
28 IMPRMF_BEGIN_NAMESPACE
29 
30 /** Manage the loading link between an RMF file and an atom::Hierarchy.
31 
32  \unstable{HierarchyLoadLink}
33  */
34 class IMPRMFEXPORT HierarchyLoadLink : public SimpleLoadLink<kernel::Particle> {
36  RMF::IntermediateParticleConstFactory intermediate_particle_factory_;
37  RMF::ReferenceFrameConstFactory reference_frame_factory_;
38  struct Data {
39  internal::HierarchyLoadStatic load_static;
40  internal::HierarchyLoadBonds load_bonds;
41  internal::HierarchyLoadLocalCoordinates load_local_coordinates;
42  internal::HierarchyLoadStaticCoordinates load_static_coordinates;
43  internal::HierarchyLoadGlobalCoordinates load_global_coordinates;
44  Data(RMF::FileConstHandle h)
45  : load_static(h),
46  load_bonds(h),
47  load_local_coordinates(h),
48  load_static_coordinates(h),
49  load_global_coordinates(h) {}
50  };
52  DM data_;
53  virtual bool get_is(RMF::NodeConstHandle nh) const IMP_OVERRIDE {
54  return nh.get_type() == RMF::REPRESENTATION;
55  }
56  virtual void add_link_recursive(kernel::Model *m, kernel::ParticleIndex root,
58  RMF::NodeConstHandle node,
59  kernel::ParticleIndexes rigid_bodies,
60  Data &data);
61 
62  virtual void do_add_link(kernel::Particle *o,
63  RMF::NodeConstHandle node) IMP_FINAL
64  IMP_OVERRIDE;
65  virtual kernel::Particle *do_create(RMF::NodeConstHandle name,
66  kernel::Model *m) IMP_FINAL
67  IMP_OVERRIDE;
68  void create_recursive(kernel::Model *m, kernel::ParticleIndex root,
69  kernel::ParticleIndex cur, RMF::NodeConstHandle name,
70  kernel::ParticleIndexes rigid_bodies, Data &data);
71  virtual void do_load_one(RMF::NodeConstHandle nh,
72  kernel::Particle *o) IMP_FINAL
73  IMP_OVERRIDE;
74 
75  protected:
76  /** This method is called for the hierarchy.*/
77  virtual void do_load_hierarchy(RMF::NodeConstHandle root_node,
79  }
80  /** Overload this to take specific action on creating
81  a member of the hierarchy.
82  \unstable{do_create_recursive} */
85  RMF::NodeConstHandle node) {}
86 
87  /** Overload this to take specific action on linking
88  a member of the hierarchy.
89  \unstable{do_add_link_recursive} */
92  RMF::NodeConstHandle node) {}
93 
94  public:
95  HierarchyLoadLink(RMF::FileConstHandle fh);
96 
97  static const char *get_name() { return "atom load"; }
98 
100 };
101 
102 /** Manage the save link between an RMF file and an atom::Hierarchy.
103 
104  \unstable{HierarchySaveLink}
105  */
106 class IMPRMFEXPORT HierarchySaveLink : public SimpleSaveLink<kernel::Particle> {
108  struct Data {
109  internal::HierarchySaveStatic save_static;
110  internal::HierarchySaveBonds save_bonds;
111  internal::HierarchySaveLocalCoordinates save_local_coordinates;
112  internal::HierarchySaveStaticCoordinates save_static_coordinates;
113  internal::HierarchySaveGlobalCoordinates save_global_coordinates;
114  Data(RMF::FileHandle h)
115  : save_static(h),
116  save_bonds(h),
117  save_local_coordinates(h),
118  save_static_coordinates(h),
119  save_global_coordinates(h) {}
120  };
122  DM data_;
123 
124  void add_recursive(Model *m, kernel::ParticleIndex root,
126  kernel::ParticleIndexes rigid_bodies, RMF::NodeHandle cur,
127  Data &data);
128  virtual void do_add(kernel::Particle *p, RMF::NodeHandle cur) IMP_OVERRIDE;
129  virtual void do_save_one(kernel::Particle *o,
130  RMF::NodeHandle nh) IMP_OVERRIDE;
131  RMF::NodeType get_type(kernel::Particle *) const {
132  return RMF::REPRESENTATION;
133  }
134 
135  protected:
136  /** Override to add extra data for nodes. */
138  kernel::ParticleIndex p, RMF::NodeHandle n) {}
139  /** Override to add extra data for nodes. */
141  RMF::NodeHandle root_node) {}
142 
143  public:
144  HierarchySaveLink(RMF::FileHandle fh);
145  static const char *get_name() { return "atom save"; }
147 };
148 
149 IMPRMF_END_NAMESPACE
150 
151 #endif /* IMPRMF_ATOM_LINKS_H */
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.
Declare an efficient stl-compatible map.
Class for storing model, its restraints, constraints, and particles.