IMP logo
IMP Reference Guide  develop.d4e9f3251e,2024/04/26
The Integrative Modeling Platform
HierarchySaveLink.h
Go to the documentation of this file.
1 /**
2  * \file IMP/rmf/HierarchySaveLink.h
3  * \brief Manage saving links to an RMF file from an atom::Hierarchy.
4  *
5  * Copyright 2007-2022 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPRMF_HIERARCHY_SAVE_LINK_H
10 #define IMPRMF_HIERARCHY_SAVE_LINK_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 <RMF/decorator/provenance.h>
20 #include <IMP/object_macros.h>
21 #include <IMP/utility_macros.h>
22 #include <RMF/NodeHandle.h>
23 #include <RMF/FileHandle.h>
24 #include <IMP/atom/Hierarchy.h>
25 #include <IMP/core/provenance.h>
26 #include <IMP/rmf/links.h>
27 #include <IMP/rmf/link_macros.h>
28 #include <IMP/tuple_macros.h>
29 #include <RMF/decorators.h>
30 #include <boost/unordered_map.hpp>
31 #include <memory>
32 
33 IMPRMF_BEGIN_NAMESPACE
34 
35 /** Manage the save link between an RMF file and an atom::Hierarchy.
36 
37  \unstable{HierarchySaveLink}
38  */
39 class IMPRMFEXPORT HierarchySaveLink : public SimpleSaveLink<Particle> {
41  struct Data {
42  internal::HierarchySaveStatic save_static;
43  internal::HierarchySaveBonds save_bonds;
44  internal::HierarchySaveXYZs save_xyzs;
45  internal::HierarchySaveGaussians save_gaussians;
46  internal::HierarchySaveRigidBodies save_rigid_bodies;
47  Data(RMF::FileHandle h)
48  : save_static(h),
49  save_bonds(h),
50  save_xyzs(h),
51  save_gaussians(h),
52  save_rigid_bodies(h) {}
53  };
54  typedef boost::unordered_map<ParticleIndex, std::shared_ptr<Data> >
55  DM;
56  DM data_;
57  RMF::decorator::AlternativesFactory af_;
58  RMF::decorator::StructureProvenanceFactory strucpf_;
59  RMF::decorator::SampleProvenanceFactory samppf_;
60  RMF::decorator::CombineProvenanceFactory combpf_;
61  RMF::decorator::FilterProvenanceFactory filtpf_;
62  RMF::decorator::ClusterProvenanceFactory clustpf_;
63  RMF::decorator::ScriptProvenanceFactory scriptpf_;
64  RMF::decorator::SoftwareProvenanceFactory softpf_;
65  RMF::decorator::ExplicitResolutionFactory explicit_resolution_factory_;
66  RMF::IntKey external_rigid_body_key_;
67 
68  void add_recursive(Model *m, ParticleIndex root,
69  ParticleIndex p,
70  ParticleIndexes rigid_bodies, RMF::NodeHandle cur,
71  Data &data);
72 
73  // Make RMF PROVENANCE nodes corresponding to those in IMP
74  void add_provenance(Model *m, ParticleIndex p, RMF::NodeHandle cur);
75 
76  virtual void do_add(Particle *p, RMF::NodeHandle cur) override;
77  virtual void do_save_one(Particle *o,
78  RMF::NodeHandle nh) override;
79  RMF::NodeType get_type(Particle *) const override {
80  return RMF::REPRESENTATION;
81  }
82 
83  protected:
84  /** Override to add extra data for nodes. */
85  virtual void do_setup_node(Model *m, ParticleIndex root,
86  ParticleIndex p, RMF::NodeHandle n) {
87  IMP_UNUSED(m);
88  IMP_UNUSED(root);
89  IMP_UNUSED(p);
90  IMP_UNUSED(n);
91  }
92  /** Override to add extra data for nodes. */
93  virtual void do_save_hierarchy(Model *m, ParticleIndex root,
94  RMF::NodeHandle root_node) {
95  IMP_UNUSED(m);
96  IMP_UNUSED(root);
97  IMP_UNUSED(root_node);
98  }
99 
100  public:
101  HierarchySaveLink(RMF::FileHandle fh);
102  static const char *get_name() { return "atom save"; }
104 };
105 
106 IMPRMF_END_NAMESPACE
107 
108 #endif /* IMPRMF_HIERARCHY_SAVE_LINK_H */
Helper macros for implementing IMP Objects.
Classes to track how the model was created.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Macros to help in defining tuple classes.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
Decorator for helping deal with a hierarchy of molecules.
#define IMP_UNUSED(variable)
Various general useful macros for IMP.
Key< 1 > IntKey
The type used to identify int attributes in the Particles.
Definition: base_types.h:36
Class to handle individual particles of a Model object.
Definition: Particle.h:43
void add_provenance(Model *m, ParticleIndex pi, Provenance p)
Add provenance to part of the model.