IMP logo
IMP Reference Guide  develop.266d43d110,2026/09/24
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-2026 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  A Model can be specified to create the simplified hierarchy in (if not
79  specified, it will be created in the same Model as the original Hierarchy).
80  A different Model cannot be specified if keep_detailed is true.
81 
82  @{
83 */
84 /** Simplify every num_res into one particle.*/
85 IMPATOMEXPORT Hierarchy
86  create_simplified_along_backbone(Hierarchy input, int num_res,
87  bool keep_detailed=false,
88  Model *m=nullptr);
89 /** Simplify by breaking at the boundaries provided.*/
90 IMPATOMEXPORT Hierarchy
92  const IntRanges &residue_segments,
93  bool keep_detailed=false,
94  Model *m=nullptr);
95 /** @} */
96 
97 /** Create a new hierarchy that approximates the volume occupied by the old one.
98 
99  The new hierarchy will contain a number of Fragment particles whose surface
100  (and hence volume) approximates the input hierarchy in the sense of
101  IMP::algebra::get_simplified_from_volume().
102 
103  The resulting representation has approximately the desired resolution in the
104  sense of get_resolution().
105 
106  Residue indexes are assigned to the created Fragments from the original
107  residue indexes, and particles containing adjacent residues are connected
108  by bonds. */
109 IMPATOMEXPORT Hierarchy
110  create_simplified_from_volume(Hierarchy h, double resolution);
111 
112 /** Create a new hierarchy that approximates the volume occupied by the old one.
113 
114  This function is like create_simplified_from_volume() except that the
115  result is divided into Chain and Molecule bits. It assumes that all
116  geometry is rooted under a chain or a molecule.
117  */
118 IMPATOMEXPORT Hierarchy
119  create_simplified_assembly_from_volume(Hierarchy h, double resolution);
120 
121 /** \name Finding information
122  Get the attribute of the given particle or throw a ValueException
123  if it is not applicable. The particle with the given information
124  must be above the passed node.
125  @{
126 */
127 IMPATOMEXPORT Ints get_residue_indexes(Hierarchy h);
128 IMPATOMEXPORT ResidueType get_residue_type(Hierarchy h);
129 IMPATOMEXPORT AtomType get_atom_type(Hierarchy h);
130 IMPATOMEXPORT std::string get_domain_name(Hierarchy h);
131 /** @} */
132 
133 /** Create an excluded volume restraint for the included molecules. If a
134  value is provided for resolution, then something less than the full
135  resolution representation will be used.
136 
137  If one or more of the selections is a rigid body, this will be used
138  to accelerate the computation.
139  \see Hierarchy
140  */
141 IMPATOMEXPORT Restraint *create_excluded_volume_restraint(
142  const Hierarchies &hs, double resolution = -1);
143 
144 /** Set the mass, radius, residues, and coordinates to approximate the passed
145  particles.
146  */
147 IMPATOMEXPORT void setup_as_approximation(Particle *h,
148  const ParticlesTemp &other
149 #ifndef IMP_DOXYGEN
150  ,
151  double resolution = -1
152 #endif
153  );
154 
155 /** Set the mass, radius, residues, and coordinates to approximate the passed
156  particle based on the leaves of h.
157  \see Hierarchy
158  */
159 IMPATOMEXPORT void setup_as_approximation(Hierarchy h
160 #ifndef IMP_DOXYGEN
161  ,
162  double resolution = -1
163 #endif
164  );
165 
166 //! Transform a hierarchy. This is aware of rigid bodies.
167 IMPATOMEXPORT void transform(Hierarchy h, const algebra::Transformation3D &tr);
168 
169 //! A graph for representing a Hierarchy so you can view it nicely.
170 IMP_GRAPH(HierarchyTree, bidirectional, Hierarchy, int,
171  vertex.show(out, "\n"));
172 
173 //! Get a graph for the passed Hierarchy.
174 /** This can be used,
175  for example, to graphically display the hierarchy in 2D.
176  \see Hierarchy
177 */
179 
180 /** \class HierarchyGeometry
181  \brief Display an IMP::atom::Hierarchy particle as balls.
182 
183  \class HierarchiesGeometry
184  \brief Display an IMP::SingletonContainer of IMP::atom::Hierarchy particles
185  as balls.
186 */
188  double res_;
189  mutable boost::unordered_map<Particle *,
190  Pointer<display::Geometry>> components_;
191 
192  public:
193  HierarchyGeometry(core::Hierarchy d, double resolution = 0)
194  : SingletonGeometry(d), res_(resolution) {}
197  atom::Hierarchy d(get_particle());
198  atom::Selection sel(d);
199  sel.set_resolution(res_);
201  for (unsigned int i = 0; i < ps.size(); ++i) {
202  if (components_.find(ps[i]) == components_.end()) {
203  IMP_NEW(core::XYZRGeometry, g, (core::XYZR(ps[i])));
204  components_[ps[i]] = g;
205  }
206  ret.push_back(components_.find(ps[i])->second);
207  }
208  return ret;
209  }
211 };
213  double res_;
214  mutable boost::unordered_map<ParticleIndex,
215  Pointer<display::Geometry>> components_;
216 
217  public:
218  HierarchiesGeometry(SingletonContainer *sc, double resolution = -1)
219  : SingletonsGeometry(sc), res_(resolution) {}
222  for(ParticleIndex pi : get_container()->get_contents()) {
223  Model *m = get_container()->get_model();
224  if (components_.find(pi) == components_.end()) {
225  IMP_NEW(HierarchyGeometry, g, (atom::Hierarchy(m, pi), res_));
226  components_[pi] = g;
227  }
228  ret.push_back(components_.find(pi)->second);
229  }
230  return ret;
231  }
233 };
234 
235 /** Transform a hierarchy, being aware of rigid bodies and intermediate nodes
236  * with coordinates. Rigid bodies must either be completely contained within the
237  * hierarchy or completely disjoint (no rigid bodies that contain particles in
238  * the hierarchy and other particles not in it are allowed). */
239 IMPATOMEXPORT void transform(atom::Hierarchy h,
240  const algebra::Transformation3D &tr);
241 
242 IMPATOM_END_NAMESPACE
243 
244 #endif /* IMPATOM_HIERARCHY_TOOLS_H */
A base class for geometry contained in particles.
Simple 3D transformation class.
display::Geometries get_components() const override
Return a set of geometry composing this one.
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:150
Index< ParticleIndexTag > ParticleIndex
Definition: base_types.h:194
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:74
Restraint * create_excluded_volume_restraint(const Hierarchies &hs, double resolution=-1)
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
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.
display::Geometries get_components() const override
Return a set of geometry composing this one.
IMP::Vector< IntRange > IntRanges
Definition: types.h:37
Class to handle individual particles of a Model object.
Definition: Particle.h:45
IMP::Vector< Int > Ints
Standard way to pass a bunch of Int values.
Definition: types.h:48
Hierarchy create_simplified_along_backbone(Chain input, const IntRanges &residue_segments, bool keep_detailed=false, Model *m=nullptr)
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:70
Decorator for a sphere-like particle.
Select a subset of a hierarchy.
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