IMP  2.0.0
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-2013 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 
21 IMPATOM_BEGIN_NAMESPACE
22 
23 //! Create a coarse grained molecule
24 /** The coarse grained model is created with a number of spheres
25  based on the resolution and the volume. If the volume is not provided
26  it is estimated based on the number of residues. The protein is
27  created as a molecular hierarchy rooted at p. The leaves are Domain
28  particles with appropriate residue indexes stored and are XYZR
29  particles.
30 
31  Volume is, as usual, in cubic anstroms.
32 
33  Currently the function creates a set of balls with radii no greater
34  than resolution which overlap by 20% and have a volume of their
35  union equal to the passed volume.
36 
37  The coordinates of the balls defining the protein are optimized
38  by default, and have garbage coordinate values.
39  \untested{create_protein}
40  \unstable{create_protein}
41  \relatesalso Hierarchy
42  */
43 IMPATOMEXPORT Hierarchy create_protein(Model *m,
44  std::string name,
45  double resolution,
46  int number_of_residues,
47  int first_residue_index=0,
48  double volume=-1
49 #ifndef IMP_DOXYGEN
50  , bool ismol=true
51 #endif
52 );
53 /** Like the former create_protein(), but it enforces domain splits
54  at the provide domain boundairs. The domain boundaries should be
55  the start of the first domain, any boundies, and then one past
56  the end of the last domain.
57  */
58 IMPATOMEXPORT Hierarchy create_protein(Model *m,
59  std::string name,
60  double resolution,
61  const Ints domain_boundaries);
62 
63 
64 /** \name Simplification along backbone
65 
66  These two methods create a simplified version of a molecule by
67  merging residues sequentially. In one case every n residues are
68  merged, in the other, the intervals are passed manually. The
69  resulting molecule is not optimized by default and has no
70  restraints automatically created.
71 
72  At the moment, the calls only support unmodified hierarchies loaded
73  by read_pdb() which have only protein or DNA members.
74 
75  They return Hierarchy() if the input chain is empty.
76 
77  If keep_detailed is true, then the original high resolution structure
78  particles are added as children of the simplified structure.
79  @{
80 */
81 /** Simplify every num_res into one particle.*/
82 IMPATOMEXPORT Hierarchy create_simplified_along_backbone(Hierarchy input,
83  int num_res,
84  bool keep_detailed=false);
85 /** Simplify by breaking at the boundaries provided.*/
86 IMPATOMEXPORT Hierarchy create_simplified_along_backbone(Chain input,
87  const IntRanges& residue_segments,
88  bool keep_detailed=false);
89 /** @} */
90 
91 
92 /** \name Finding information
93  Get the attribute of the given particle or throw a ValueException
94  if it is not applicable. The particle with the given information
95  must be above the passed node.
96  @{
97 */
98 IMPATOMEXPORT std::string get_molecule_name(Hierarchy h);
99 IMPATOMEXPORT Ints get_residue_indexes(Hierarchy h);
100 IMPATOMEXPORT ResidueType get_residue_type(Hierarchy h);
101 IMPATOMEXPORT int get_chain_id(Hierarchy h);
102 IMPATOMEXPORT AtomType get_atom_type(Hierarchy h);
103 IMPATOMEXPORT std::string get_domain_name(Hierarchy h);
104 IMPATOMEXPORT int get_copy_index(Hierarchy h);
105 /** @} */
106 
107 
108 
109 /** Create an excluded volume restraint for the included molecules. If a
110  value is provided for resolution, then something less than the full
111  resolution representation will be used.
112 
113  If one or more of the selections is a rigid body, this will be used
114  to accelerate the computation.
115  \relatesalso Hierarchy
116  */
117 IMPATOMEXPORT Restraint* create_excluded_volume_restraint(const Hierarchies &hs,
118  double resolution=-1);
119 
120 
121 
122 
123 /** Set the mass, radius, residues, and coordinates to approximate the passed
124  particles.
125  */
126 IMPATOMEXPORT void setup_as_approximation(Particle *h,
127  const ParticlesTemp &other
128 #ifndef IMP_DOXYGEN
129  ,
130  double resolution=-1
131 #endif
132 );
133 
134 /** Set the mass, radius, residues, and coordinates to approximate the passed
135  particle based on the leaves of h.
136  \relatesalso Hierarchy
137  */
138 IMPATOMEXPORT void setup_as_approximation(Hierarchy h
139 #ifndef IMP_DOXYGEN
140  ,
141  double resolution =-1
142 #endif
143 );
144 
145 /** Transform a hierarchy. This is aware of rigid bodies.
146  */
147 IMPATOMEXPORT void transform(Hierarchy h, const algebra::Transformation3D &tr);
148 
149 
150 
151 /** A graph for representing a Hierarchy so you can view it
152  nicely.
153 */
154 IMP_GRAPH(HierarchyTree, bidirectional, Hierarchy, int);
155 /** Get a graph for the passed Hierarchy. This can be used,
156  for example, to graphically display the hierarchy in 2D.
157  \relatesalso Hierarchy
158 */
160 
161 
162 
163 
164 
165 /** \class HierarchyGeometry
166  \brief Display an IMP::atom::Hierarchy particle as balls.
167 
168  \class HierarchiesGeometry
169  \brief Display an IMP::SingletonContainer of IMP::atom::Hierarchy particles
170  as balls.
171 */
173  double res_;
175  components_;
176 public:
177  HierarchyGeometry(core::Hierarchy d, double resolution=-1):
178  SingletonGeometry(d), res_(resolution){}
181  atom::Hierarchy d(get_particle());
182  atom::Selection sel(d);
183  sel.set_target_radius(res_);
184  ParticlesTemp ps= sel.get_selected_particles();
185  for (unsigned int i=0; i< ps.size(); ++i) {
186  if (components_.find(ps[i])== components_.end()) {
187  IMP_NEW(core::XYZRGeometry, g, (core::XYZR(ps[i])));
188  components_[ps[i]]=g;
189  }
190  ret.push_back(components_.find(ps[i])->second);
191  }
192  return ret;
193  }
195  out << atom::Hierarchy(get_particle())<< std::endl;,{});
196 };
198  double res_;
200  components_;
201  public:
202  HierarchiesGeometry(SingletonContainer* sc, double resolution=-1):
203  SingletonsGeometry(sc), res_(resolution){}
206  IMP_FOREACH_SINGLETON(get_container(), {
207  if (components_.find(_1)
208  == components_.end()) {
209  IMP_NEW(HierarchyGeometry, g, (atom::Hierarchy(_1), res_));
210  components_[_1]= g;
211  }
212  ret.push_back(components_.find(_1)->second);
213  });
214  return ret;
215  }
217  out << get_container() << std::endl;,{});
218 };
219 
220 IMPATOM_END_NAMESPACE
221 
222 #endif /* IMPATOM_HIERARCHY_TOOLS_H */