IMP logo
IMP Reference Guide  2.10.1
The Integrative Modeling Platform
hierarchy_tools.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/hierarchy_tools.h
3  * \brief A set of useful functionality on IMP::atom::Hierarchy decorators
4  *
5  * Copyright 2007-2018 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPATOM_HIERARCHY_TOOLS_H
9 #define IMPATOM_HIERARCHY_TOOLS_H
10 
11 #include <IMP/atom/atom_config.h>
12 #include <IMP/algebra/algebra_config.h>
13 #include "Hierarchy.h"
14 #include "Residue.h"
15 #include "Atom.h"
16 #include <IMP/core/Typed.h>
17 #include <IMP/core/XYZR.h>
18 #include "Selection.h"
19 #include <boost/graph/adjacency_list.hpp>
20 #include <boost/unordered_map.hpp>
21 
22 IMPATOM_BEGIN_NAMESPACE
23 
24 //! Create a coarse grained molecule
25 /** The coarse grained model is created with a number of spheres
26  based on the resolution and the volume. If the volume is not provided
27  it is estimated based on the number of residues. The protein is
28  created as a molecular hierarchy rooted at p. The leaves are Domain
29  particles with appropriate residue indexes stored and are XYZR
30  particles.
31 
32  Volume is, as usual, in cubic angstroms.
33 
34  Currently the function creates a set of balls with radii no greater
35  than target_radius which overlap by 20% and have a volume of their
36  union equal to the passed volume.
37 
38  The coordinates of the balls defining the protein are not optimized
39  by default, and have garbage coordinate values.
40  \untested{create_protein}
41  \unstable{create_protein}
42  \see Hierarchy
43  */
44 IMPATOMEXPORT Hierarchy
45  create_protein(Model *m, std::string name, double target_radius,
46  int number_of_residues, int first_residue_index = 0,
47  double volume = -1
48 #ifndef IMP_DOXYGEN
49  ,
50  bool ismol = true
51 #endif
52  );
53 /** Like the former create_protein(), but it enforces domain splits
54  at the provided domain boundaries. The domain boundaries should be
55  the start of the first domain, any boundaries, and then one past
56  the end of the last domain.
57  */
58 IMPATOMEXPORT Hierarchy create_protein(Model *m, std::string name,
59  double target_radius,
60  const Ints domain_boundaries);
61 
62 /** \name Simplification along backbone
63 
64  These two methods create a simplified version of a molecule by
65  merging residues sequentially. In one case every n residues are
66  merged, in the other, the intervals are passed manually. The
67  resulting molecule is not optimized by default and has no
68  restraints automatically created.
69 
70  At the moment, the calls only support unmodified hierarchies loaded
71  by read_pdb() which have only protein or DNA members.
72 
73  They return Hierarchy() if the input chain is empty.
74 
75  If keep_detailed is true, then the original high resolution structure
76  particles are added as children of the simplified structure.
77  @{
78 */
79 /** Simplify every num_res into one particle.*/
80 IMPATOMEXPORT Hierarchy
81  create_simplified_along_backbone(Hierarchy input, int num_res,
82  bool keep_detailed = false);
83 /** Simplify by breaking at the boundaries provided.*/
84 IMPATOMEXPORT Hierarchy
86  const IntRanges &residue_segments,
87  bool keep_detailed = false);
88 /** @} */
89 
90 /** Create a new hierarchy that approximates the volume occupied by the old one.
91 
92  The new hierarchy will contain a number of Fragment particles whose surface
93  (and hence volume) approximates the input hierarchy in the sense of
94  IMP::algebra::get_simplified_from_volume().
95 
96  The resulting representation has approximately the desired resolution in the
97  sense of get_resolution().
98 
99  Residue indexes are assigned to the created Fragments from the original
100  residue indexes, and particles containing adjacent residues are connected
101  by bonds. */
102 IMPATOMEXPORT Hierarchy
103  create_simplified_from_volume(Hierarchy h, double resolution);
104 
105 /** Create a new hierarchy that approximates the volume occupied by the old one.
106 
107  This function is like create_simplified_from_volume() except that the
108  result is divided into Chain and Molecule bits. It assumes that all
109  geometry is rooted under a chain or a molecule.
110  */
111 IMPATOMEXPORT Hierarchy
112  create_simplified_assembly_from_volume(Hierarchy h, double resolution);
113 
114 /** \name Finding information
115  Get the attribute of the given particle or throw a ValueException
116  if it is not applicable. The particle with the given information
117  must be above the passed node.
118  @{
119 */
120 IMPATOMEXPORT Ints get_residue_indexes(Hierarchy h);
121 IMPATOMEXPORT ResidueType get_residue_type(Hierarchy h);
122 IMPATOMEXPORT AtomType get_atom_type(Hierarchy h);
123 IMPATOMEXPORT std::string get_domain_name(Hierarchy h);
124 /** @} */
125 
126 /** Create an excluded volume restraint for the included molecules. If a
127  value is provided for resolution, then something less than the full
128  resolution representation will be used.
129 
130  If one or more of the selections is a rigid body, this will be used
131  to accelerate the computation.
132  \see Hierarchy
133  */
134 IMPATOMEXPORT Restraint *create_excluded_volume_restraint(
135  const Hierarchies &hs, double resolution = -1);
136 
137 /** Set the mass, radius, residues, and coordinates to approximate the passed
138  particles.
139  */
140 IMPATOMEXPORT void setup_as_approximation(Particle *h,
141  const ParticlesTemp &other
142 #ifndef IMP_DOXYGEN
143  ,
144  double resolution = -1
145 #endif
146  );
147 
148 /** Set the mass, radius, residues, and coordinates to approximate the passed
149  particle based on the leaves of h.
150  \see Hierarchy
151  */
152 IMPATOMEXPORT void setup_as_approximation(Hierarchy h
153 #ifndef IMP_DOXYGEN
154  ,
155  double resolution = -1
156 #endif
157  );
158 
159 //! Transform a hierarchy. This is aware of rigid bodies.
160 IMPATOMEXPORT void transform(Hierarchy h, const algebra::Transformation3D &tr);
161 
162 //! A graph for representing a Hierarchy so you can view it nicely.
163 IMP_GRAPH(HierarchyTree, bidirectional, Hierarchy, int,
164  vertex.show(out, "\n"));
165 
166 //! Get a graph for the passed Hierarchy.
167 /** This can be used,
168  for example, to graphically display the hierarchy in 2D.
169  \see Hierarchy
170 */
172 
173 /** \class HierarchyGeometry
174  \brief Display an IMP::atom::Hierarchy particle as balls.
175 
176  \class HierarchiesGeometry
177  \brief Display an IMP::SingletonContainer of IMP::atom::Hierarchy particles
178  as balls.
179 */
181  double res_;
182  mutable boost::unordered_map<Particle *,
183  Pointer<display::Geometry> > components_;
184 
185  public:
186  HierarchyGeometry(core::Hierarchy d, double resolution = 0)
187  : SingletonGeometry(d), res_(resolution) {}
190  atom::Hierarchy d(get_particle());
191  atom::Selection sel(d);
192  sel.set_resolution(res_);
194  for (unsigned int i = 0; i < ps.size(); ++i) {
195  if (components_.find(ps[i]) == components_.end()) {
196  IMP_NEW(core::XYZRGeometry, g, (core::XYZR(ps[i])));
197  components_[ps[i]] = g;
198  }
199  ret.push_back(components_.find(ps[i])->second);
200  }
201  return ret;
202  }
204 };
206  double res_;
207  mutable boost::unordered_map<ParticleIndex,
208  Pointer<display::Geometry> > components_;
209 
210  public:
211  HierarchiesGeometry(SingletonContainer *sc, double resolution = -1)
212  : SingletonsGeometry(sc), res_(resolution) {}
215  IMP_FOREACH(ParticleIndex pi, get_container()->get_contents()) {
216  Model *m = get_container()->get_model();
217  if (components_.find(pi) == components_.end()) {
218  IMP_NEW(HierarchyGeometry, g, (atom::Hierarchy(m, pi), res_));
219  components_[pi] = g;
220  }
221  ret.push_back(components_.find(pi)->second);
222  }
223  return ret;
224  }
226 };
227 
228 /** Transform a hierarchy, being aware of rigid bodies and intermediate nodes
229  * with coordinates. Rigid bodies must either be completely contained within the
230  * hierarchy or completely disjoint (no rigid bodies that contain particles in
231  * the hierarchy and other particles not in it are allowed). */
232 IMPATOMEXPORT void transform(atom::Hierarchy h,
233  const algebra::Transformation3D &tr);
234 
235 IMPATOM_END_NAMESPACE
236 
237 #endif /* IMPATOM_HIERARCHY_TOOLS_H */
A base class for geometry contained in particles.
display::Geometries get_components() const
Return a set of geometry composing this one.
Simple 3D transformation class.
Hierarchy create_simplified_from_volume(Hierarchy h, double resolution)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
#define IMP_GRAPH(Name, directionality, VertexData, EdgeData, ShowVertex)
Define a graph object in IMP.
Definition: graph_macros.h:29
A base class for geometry from a set of particles.
Simple atom decorator.
void setup_as_approximation(Hierarchy h)
void set_resolution(double r)
Select at a Representation node with a resolution close to r.
Definition: Selection.h:146
Index< ParticleIndexTag > ParticleIndex
Definition: base_types.h:154
HierarchyTree get_hierarchy_tree(Hierarchy h)
Get a graph for the passed Hierarchy.
A particle with a user-defined type.
A smart pointer to a reference counted object.
Definition: Pointer.h:87
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
Definition: object_macros.h:64
Restraint * create_excluded_volume_restraint(const Hierarchies &hs, double resolution=-1)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Decorator for helping deal with a hierarchy of molecules.
ParticlesTemp get_selected_particles(bool with_representation=true) const
Get the selected particles.
Hierarchy create_protein(Model *m, std::string name, double target_radius, const Ints domain_boundaries)
void transform(Hierarchy h, const algebra::Transformation3D &tr)
Transform a hierarchy. This is aware of rigid bodies.
The standard decorator for manipulating molecular structures.
Display an IMP::SingletonContainer of IMP::atom::Hierarchy particles as balls.
A decorator for Residues.
boost::graph HierarchyTree
A graph for representing a Hierarchy so you can view it nicely.
A shared container for Singletons.
IMP::Vector< IntRange > IntRanges
Definition: types.h:38
Hierarchy create_simplified_along_backbone(Chain input, const IntRanges &residue_segments, bool keep_detailed=false)
Class to handle individual particles of a Model object.
Definition: Particle.h:41
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition: types.h:49
A decorator for helping deal with a generalized hierarchy.
Hierarchy create_simplified_assembly_from_volume(Hierarchy h, double resolution)
Select hierarchy particles identified by the biological name.
Definition: Selection.h:66
Decorator for a sphere-like particle.
Select a subset of a hierarchy.
display::Geometries get_components() const
Return a set of geometry composing this one.
Display an IMP::atom::Hierarchy particle as balls.
Display an IMP::core::XYZR particle as a ball.
Definition: XYZR.h:151
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27