IMP logo
IMP Reference Guide  2.9.0
The Integrative Modeling Platform
rmf_links.h
Go to the documentation of this file.
1 /**
2  * \file npctransport/rmf_links.h
3  * \brief description
4  *
5  * Copyright 2007-2018 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPNPCTRANSPORT_RMF_LINKS_H
9 #define IMPNPCTRANSPORT_RMF_LINKS_H
10 
11 #include "npctransport_config.h"
12 #include "SimulationData.h"
13 #include <IMP/rmf/atom_links.h>
14 #include <IMP/rmf/link_macros.h>
15 #include <boost/unordered_map.hpp>
16 #include <IMP/WeakPointer.h>
17 
18 IMPNPCTRANSPORT_BEGIN_NAMESPACE
19 
20 //! Load sites data from an RMF file
21 class IMPNPCTRANSPORTEXPORT HierarchyWithSitesLoadLink
22  : public rmf::HierarchyLoadLink {
24  RMF::decorator::BallConstFactory bf_;
25  // Transporting decorator related keys:
26  RMF::IntKey is_last_entry_from_top_key_;
27  RMF::IntKey n_entries_bottom_key_;
28  RMF::IntKey n_entries_top_key_;
29  // optimization data:
30  RMF::IntKey coordinates_are_optimized_key_;
31  // Slab decorator related keys:
32  RMF::FloatKey pore_radius_key_;
33  RMF::IntKey pore_radius_is_optimized_key_;
34  // Spring decorator keys
35  RMF::FloatKey rest_length_key_;
36 
37  boost::unordered_map<ParticleIndex, ParticleIndexes> particles_;
38 
39  protected:
40  /** Called by rmf::HierarchyLoadLink::add_link_recursive()
41 
42  link the specified rmf node to particle cur. In addition, load
43  the list of sites associated with the rmf node together with
44  their coordinates (children of type RMF::Geometry decorated with
45  RMF::BallConst) and associate them with the particle type of cur
46  in the SimulationData of cur.
47  */
48  virtual void do_link_particle(Model *m, ParticleIndex root,
49  ParticleIndex cur,
50  RMF::NodeConstHandle node) IMP_OVERRIDE;
51 
52  virtual void do_setup_particle(Model* m, ParticleIndex root,
53  ParticleIndex cur,
54  RMF::NodeConstHandle node) IMP_OVERRIDE {
56  IMP_UNUSED(m); IMP_UNUSED(root);
57  IMP_UNUSED(cur); IMP_UNUSED(node);
58  }
59 
60  /** load the values of a hierarchy. also
61  loads dynamic Transporting decorator transport directionality
62  information if needed (which is used in
63  ParticleTransportStatisticsOptimizerState)
64  */
65  virtual void do_load_hierarchy(RMF::NodeConstHandle root_node,
66  Model *m,
68 
69  public:
70  HierarchyWithSitesLoadLink(RMF::FileConstHandle fh);
71  static const char *get_name() {return "npctransport load";}
72 };
73 
74 //! Save sites data to an RMF file
75 class IMPNPCTRANSPORTEXPORT HierarchyWithSitesSaveLink
76  : public rmf::HierarchySaveLink {
78  RMF::decorator::BallFactory bf_;
79  RMF::decorator::ColoredFactory cf_;
80  // Transporting decorator related keys:
81  RMF::IntKey is_last_entry_from_top_key_;
82  RMF::IntKey n_entries_bottom_key_;
83  RMF::IntKey n_entries_top_key_;
84  // optimization data:
85  RMF::IntKey coordinates_are_optimized_key_;
86  // Slab decorator related keys:
87  RMF::FloatKey pore_radius_key_;
88  RMF::IntKey pore_radius_is_optimized_key_;
89  // Spring decorator keys
90  RMF::FloatKey rest_length_key_;
91 
92  boost::unordered_map<ParticleIndex, ParticleIndexes> particles_;
93 
94  // for testing without sd - site coords & radii per each particle type
95  boost::unordered_map
97 
98  private:
99  // add sites associated with particle type t to node cur_node, using
100  // sd_->get_sites() if sd_ is initialized, or using internal
101  // test_sites_ table (used for testing only)
102  void add_sites_to_node(RMF::NodeHandle cur_node, core::ParticleType t) const;
103 
104  protected:
105  virtual void do_setup_node(Model *m, ParticleIndex root,
106  ParticleIndex cur,
107  RMF::NodeHandle cur_node) IMP_OVERRIDE;
108 
109  /** save the values of a hierarchy
110  */
111  virtual void do_save_hierarchy(Model *m, ParticleIndex root,
112  RMF::NodeHandle root_node) IMP_OVERRIDE;
113 
114  public:
115  HierarchyWithSitesSaveLink(RMF::FileHandle fh);
116 #ifndef SWIG
117  // for testing
119  algebra::Sphere3Ds sites) {
120  test_sites_[t] = sites;
121  }
122 #endif
123  static const char *get_name() {return "npctransport save";}
124 };
125 
126 //! for testing - adds the list of sites with specified radius, to be
127 //! associated with particle type t. The file handle fh relies on this list
128 //! only if it doesn't have particles with simulation data keys
129 IMPNPCTRANSPORTEXPORT void add_test_sites(RMF::FileHandle fh, core::ParticleType t,
130  double display_radius, algebra::Vector3Ds sites);
131 
132 //! for testing - adds the list of sites with specified display radius, to be
133 //! associated with particle type t. The file handle fh relies on this list
134 //! only if it doesn't have particles with simulation data keys
135 IMPNPCTRANSPORTEXPORT void add_test_sites(RMF::FileHandle fh,
137  algebra::Sphere3Ds sites);
138 
139 // note that the corresponding define macro in the .cpp file implicitly
140 // uses the HierarchyWithSitesLoadLink and HierarchyWithSitesSaveLink
141 // classes
142 /**
143  Functions for adding a hierarchy to an RMF file or linking an RMF
144  file to an existing hierarchy, including support for particles with sites.
145 
146  These functions are practically identical to the add / link
147  methods in modules/rmf/include/hierarchy_io.h, such as
148  IMP::rmf::link_hierarchies(), except here NPC particle sites
149  support is included.
150  */
151 IMP_DECLARE_LINKERS(HierarchyWithSites,
152  hierarchy_with_sites, hierarchies_with_sites,
154  (RMF::FileConstHandle fh, Model *m),
155  See IMP::rmf::link_hierarchies() for more details.
156  The only difference is the addition of particle sites
157  support.
158  );
159 
160 IMPNPCTRANSPORT_END_NAMESPACE
161 
162 #endif /* IMPNPCTRANSPORT_RMF_LINKS_H */
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
Definition: base_types.h:32
Smart pointer to Object-derived classes that does not refcount.
Definition: WeakPointer.h:76
A typed index.
Definition: Index.h:24
Key< 34897493 > ParticleType
An IMP::Key object for identifying types of particles by strings.
Definition: Typed.h:28
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
void add_test_sites(RMF::FileHandle fh, core::ParticleType t, algebra::Sphere3Ds sites)
The standard decorator for manipulating molecular structures.
#define IMP_UNUSED(variable)
Key< 1 > IntKey
The type used to identify int attributes in the Particles.
Definition: base_types.h:36
A nullptr-initialized pointer to an Object.
description
void link_hierarchies(RMF::FileConstHandle fh, const atom::Hierarchies &hs)
#define IMP_NOT_IMPLEMENTED
Use this to mark that the method is not implemented yet.
Definition: check_macros.h:81
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.