IMP  2.0.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 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 <IMP/base/object_macros.h>
16 #include <RMF/NodeHandle.h>
17 #include <RMF/FileHandle.h>
18 #include <IMP/atom/Hierarchy.h>
19 #include <IMP/rmf/links.h>
20 #include <IMP/rmf/link_macros.h>
21 #include <IMP/base/tuple_macros.h>
22 #include <RMF/decorators.h>
23 #include <IMP/base/map.h>
24 IMPRMF_BEGIN_NAMESPACE
25 
26 class IMPRMFEXPORT HierarchyLoadLink: public SimpleLoadLink<Particle> {
27  IMP_NAMED_TUPLE_2(ConstData, ConstDatas, RMF::NodeIDs, nodes,
28  ParticlesTemp, particles,);
29  typedef SimpleLoadLink<Particle> P;
30  Pointer<Model> m_;
31  RMF::ParticleConstFactory particle_factory_;
32  RMF::IntermediateParticleConstFactory intermediate_particle_factory_;
33  RMF::RigidParticleConstFactory rigid_factory_;
34  RMF::AtomConstFactory atom_factory_;
35  RMF::ResidueConstFactory residue_factory_;
36  RMF::ChainConstFactory chain_factory_;
37  RMF::ColoredConstFactory colored_factory_;
38  RMF::CopyConstFactory copy_factory_;
39  RMF::DiffuserConstFactory diffuser_factory_;
40  RMF::TypedConstFactory typed_factory_;
41  RMF::DomainConstFactory domain_factory_;
42  RMF::ReferenceFrameConstFactory reference_frame_factory_;
43  RMF::IndexKey rigid_body_key_;
44 
45  base::map<Particle*, ConstData> contents_;
46  base::map<unsigned int, ParticlesTemp> rigid_bodies_;
47  /** This method is called for each particle in the hierarchy.*/
48  IMP_PROTECTED_METHOD(virtual void,
49  do_load_node,
50  (RMF::NodeConstHandle nh,
51  Particle *o),,);
52  /** Overload this method to take specific action on loading a hierarchy.
53  */
54  IMP_PROTECTED_METHOD(virtual void, do_load_one,
55  ( RMF::NodeConstHandle nh,
56  Particle *o),,);
57  bool get_is(RMF::NodeConstHandle nh) const {
58  return nh.get_type()==RMF::REPRESENTATION;
59  }
60  bool setup_particle(Particle *root,
61  RMF::NodeConstHandle nh,
62  Particle *p,
63  Particle *rbp);
64  /** Overload this to take specific action on creating
65  a member of the hierarchy.
66  \unstable{do_create_recursive} */
67  IMP_PROTECTED_METHOD(virtual Particle*, do_create_recursive, (Particle *root,
68  RMF::NodeConstHandle name,
69  Particle *rbp=nullptr),,);
70 
71  Particle* do_create(RMF::NodeConstHandle name);
72  /** Overload this to take specific action on linking
73  a member of the hierarchy.
74  \unstable{do_add_link_recursive} */
75  IMP_PROTECTED_METHOD(virtual void, do_add_link_recursive, (Particle *root,
76  Particle *o, RMF::NodeConstHandle node),,);
77 
78  void do_add_link(Particle *o, RMF::NodeConstHandle node);
79 public:
80  HierarchyLoadLink(RMF::FileConstHandle fh, Model *m);
81 
82  IMP_OBJECT_INLINE(HierarchyLoadLink,IMP_UNUSED(out),);
83 };
84 
85 
86 class IMPRMFEXPORT HierarchySaveLink: public SimpleSaveLink<Particle> {
87  typedef SimpleSaveLink<Particle> P;
88  IMP_NAMED_TUPLE_2(Data, Datas, RMF::NodeIDs, nodes,
89  ParticlesTemp, particles,);
90 
91  RMF::ParticleFactory particle_factory_;
92  RMF::IntermediateParticleFactory intermediate_particle_factory_;
93  RMF::RigidParticleFactory rigid_factory_;
94  RMF::AtomFactory atom_factory_;
95  RMF::ResidueFactory residue_factory_;
96  RMF::ChainFactory chain_factory_;
97  RMF::ColoredFactory colored_factory_;
98  RMF::CopyFactory copy_factory_;
99  RMF::DiffuserFactory diffuser_factory_;
100  RMF::TypedFactory typed_factory_;
101  RMF::DomainFactory domain_factory_;
102  RMF::ReferenceFrameFactory reference_frame_factory_;
103  RMF::IndexKey rigid_body_key_;
104 
105  bool forces_;
106  RMF::ForceFactory force_factory_;
107  RMF::TorqueFactory torque_factory_;
108 
109  // ones in this set have their internal coordinates saved
110  base::set<Particle*> internal_;
111  base::map<Particle*, Data> contents_;
112  base::map<Particle*, unsigned int> rigid_bodies_;
113  void setup_node(Particle *p, RMF::NodeHandle n) ;
114  void do_add(Particle *p, RMF::NodeHandle cur);
115  void do_save_one(Particle *o,
116  RMF::NodeHandle nh);
117  RMF::NodeType get_type(Particle*) const {
118  return RMF::REPRESENTATION;
119  }
120  IMP_PROTECTED_METHOD(virtual void, do_add_recursive,
121  (Particle *root, Particle *p,
122  RMF::NodeHandle cur),,);
123  IMP_PROTECTED_METHOD(virtual void, do_save_node, (Particle *p,
124  RMF::NodeHandle n),,);
125 public:
126  HierarchySaveLink(RMF::FileHandle fh);
127  IMP_OBJECT_INLINE(HierarchySaveLink,IMP_UNUSED(out),);
128  void set_save_forces(bool tf) {
129  forces_ = tf;
130  }
131 };
132 
133 
134 IMPRMF_END_NAMESPACE
135 
136 #endif /* IMPRMF_ATOM_LINKS_H */