IMP  2.1.0
The Integrative Modeling Platform
Selection.h
Go to the documentation of this file.
1 /**
2  * \file IMP/atom/Selection.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_SELECTION_H
9 #define IMPATOM_SELECTION_H
10 
11 #include <IMP/atom/atom_config.h>
12 #include "Atom.h"
13 #include "Hierarchy.h"
14 #include "Residue.h"
15 #include <IMP/SingletonPredicate.h>
16 #include <IMP/algebra/algebra_config.h>
17 #include <IMP/base/InputAdaptor.h>
18 #include <IMP/core/Typed.h>
19 #include <IMP/core/XYZR.h>
21 
22 IMPATOM_BEGIN_NAMESPACE
23 
24 /** Select a part of an atom.Hiearchy or atom.Hierarchies that is identified
25  by the biological name.
26 
27 
28  For example (in python)
29  \code
30  Selection(hierarchy=h, molecule="myprotein", terminus=Selection.C)
31  Selection(hierarchy=h, molecule="myprotein", residue_index=133)
32  Selection(hierarchy=h, molecule="myprotein", residue_indexes=range(133,138))
33  \endcode
34  each get the C-terminus of the protein "myprotein" (assuming the last
35  residue index is 133).
36 
37  \note Only representational particles are selected. That is, ones
38  with x,y,z coordinates. And the highest resolution representation
39  that fits is returned. If you want lower resolution, use the
40  target_radius parameter to select the desired radius (pass a very large
41  number to get the coarsest representation).
42 */
43 class IMPATOMEXPORT Selection :
44 #ifdef SWIG
46 #else
47  public base::InputAdaptor
48 #endif
49  {
50  public:
51  enum Terminus {
52  NONE,
53  C,
54  N
55  };
56 
57  private:
58  SingletonPredicates predicates_;
59  kernel::Model *m_;
60  double radius_;
61 
63  IMP_NAMED_TUPLE_3(SearchResult, SearchResults, bool, match, double, radius,
64  kernel::ParticleIndexes, indexes, );
65  SearchResult search(kernel::Model *m, kernel::ParticleIndex pi,
66  boost::dynamic_bitset<> parent) const;
67  void set_hierarchies(kernel::Model *m, const kernel::ParticleIndexes &pis);
68 
69  public:
70 #ifdef IMP_DOXYGEN
71  /** When using python, you have much more control over
72  construction due to the use of keyword arguments. You
73  can provide any subset of the arguments (although one
74  of hierarchy or hierarchies must be provided).
75  */
76  Selection(Hierarchy hierarchy = None, Hierarchies hierarchies = [],
77  Strings molecules = [], Ints residue_indexes = [],
78  Strings chains = [], AtomTypes atom_types = [],
79  ResidueTypes residue_types = [], Strings domains = [],
80  double target_radius = 0, std::string molecule = None,
81  int residue_index = None, char chain = None,
82  AtomType atom_type = None, ResidueType residue_type = None,
83  HierarchyType hierarchy_type = None, Terminus terminus = None,
84  std::string domain = None, core::ParticleType particle_type = None,
85  core::ParticleTypes particle_types = [], int copy_index = -1,
86  Ints copy_indexs = []);
87 #endif
88  Selection();
92 #ifndef SWIG
93  Selection(const Hierarchies &h);
94 #endif
96 // for C++
97 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
98  Selection(Hierarchy h, std::string molname, int residue_index);
99 #endif
100  //! Return the hierarchies that the Selection was constructed with
101  Hierarchies get_hierarchies() const;
102  /** Select based on the molecule name.*/
103  void set_molecules(Strings mols);
104 
105  /** Select particles whose radii are close to r.*/
106  void set_target_radius(double r) { radius_ = r; }
107  /** Select the n or c terminus.*/
108  void set_terminus(Terminus t);
109  /** Select particles in chains whose id is
110  in the passed string.*/
111  void set_chains(std::string chains);
112  /** Select residues whose indexes are in the passed list.*/
113  void set_residue_indexes(Ints indexes);
114  /** Select atoms whose types are in the list, eg AT_CA.*/
115  void set_atom_types(AtomTypes types);
116  /** Select residues whose types are in the list. Not sure
117  why you would do this.*/
118  void set_residue_types(ResidueTypes types);
119  /** Select domains with the specificed names. */
120  void set_domains(Strings names);
121  /** Select a molecule with the passed name. */
122  void set_molecule(std::string mol);
123  /** Select a chain with the passed id*/
124  void set_chain(char c);
125  /** Select only residues with the passed index.*/
126  void set_residue_index(int i);
127  /** Select atoms with only the passed type. */
128  void set_atom_type(AtomType types);
129  /** Select only residues with the passed type.*/
130  void set_residue_type(ResidueType type);
131  /** Select only the single domain with that name*/
132  void set_domain(std::string name);
133  /** Select elements with Copy::get_copy_index() that match.*/
134  void set_copy_index(unsigned int copy);
135  /** Select elements with Copy::get_copy_index() that are in the list.*/
136  void set_copy_indexes(Ints copies);
137  /** Select elements that match the core::ParticleType.*/
138  void set_particle_type(core::ParticleType t);
139  /** Select elements that match the core::ParticleType.*/
140  void set_particle_types(core::ParticleTypes t);
141  /** Select only particles whose type matches the passed type, eg
142  Molecule, Fragment, Residue etc. See GetByType for how to
143  specify the types. Ints are used to make swig happy.*/
144  void set_hierarchy_types(Ints types);
145  //! Get the selected particles
146  kernel::ParticlesTemp get_selected_particles() const;
147  //! Get the indexes of the selected particles
148  kernel::ParticleIndexes get_selected_particle_indexes() const;
149 
150 #ifndef SWIG
151  operator ParticleIndexes() const { return get_selected_particle_indexes(); }
152  operator ParticlesTemp() const { return get_selected_particles(); }
153 #endif
154 
155  IMP_SHOWABLE(Selection);
156 };
157 
159 
160 /** Create a distance restraint between the selections.
161 
162  This restraint applies a harmonic to the minimum distance
163  between a particle in selection n0 and a particle in selection
164  n1.
165 
166  If one or more of the selections is a rigid body, this will be used
167  to accelerate the computation.
168  See Selection
169  */
170 IMPATOMEXPORT kernel::Restraint *create_distance_restraint(const Selection &n0,
171  const Selection &n1,
172  double x0, double k,
173  std::string name =
174  "Distance%1%");
175 
176 /** Create a restraint connecting the selections.
177 
178  If one or more of the selections is a rigid body, this will be used
179  to accelerate the computation.
180  See Selection
181 */
183  const Selections &s, double k, std::string name = "Connectivity%1%");
184 
185 /** Create a restraint connecting the selections. The particles are
186  allowed to be appart by x0 and still count as connected.
187 
188  If one or more of the selections is a rigid body, this will be used
189  to accelerate the computation.
190  See Selection
191 */
193  const Selections &s, double x0, double k,
194  std::string name = "Connectivity%1%");
195 
196 /** Create a restraint connecting the selection.
197 
198  If one or more of the selections is a rigid body, this will be used
199  to accelerate the computation.
200 
201  See Selection
202 */
204  const Selection &s, double k, std::string name = "Connectivity%1%");
205 
206 /** Create a restraint connecting the selection. The particles are
207  allowed to be appart by x0 and still count as connected.
208 
209  If one or more of the selections is a rigid body, this will be used
210  to accelerate the computation.
211 
212  See Selection
213 */
215  const Selection &s, double x0, double k,
216  std::string name = "Connectivity%1%");
217 
218 /** Create an XYZR particle which always includes the particles
219  in the selection in its bounding volume. If all the particles
220  in the selection are part of the same rigid body, then the
221  created particle is added as part of that rigid body. Otherwise
222  it uses an IMP::core::Cover to maintain the cover property.
223 
224  Doing this can be a useful way to accelerate computations
225  when it is OK to replace a potential complicated set of
226  geometry represented by the selection with a much simpler
227  one.
228 
229  See Selection
230 */
231 IMPATOMEXPORT core::XYZR create_cover(const Selection &s,
232  std::string name = std::string());
233 
234 /** Get the total mass of a hierarchy. In daltons.
235  See Selection
236  */
237 IMPATOMEXPORT double get_mass(const Selection &s);
238 
239 #ifdef IMP_ALGEBRA_USE_IMP_CGAL
240 /** Get the total volume of a hierarchy. In cubic angstroms.
241  \requires{get_volume, CGAL}
242  See Selection
243 */
244 IMPATOMEXPORT double get_volume(const Selection &s);
245 
246 /** Get the total surface area of a hierarchy. In square angstroms.
247  \requires{get_surface_area, CGAL}
248  See Selection
249 */
250 IMPATOMEXPORT double get_surface_area(const Selection &s);
251 #endif
252 
253 /** See Selection
254  */
255 IMPATOMEXPORT double get_radius_of_gyration(const Selection &s);
256 
257 /** Create an excluded volume restraint for a list of selections.*/
259  const Selections &s);
260 
261 /** See Hierarchy */
262 IMPATOMEXPORT Hierarchies get_leaves(const Selection &h);
263 
264 /** \class SelectionGeometry
265  \brief Display a Selection.
266 */
267 class IMPATOMEXPORT SelectionGeometry : public display::Geometry {
268  atom::Selection res_;
270  components_;
271 
272  public:
273  SelectionGeometry(atom::Selection d, std::string name = "Selection")
274  : display::Geometry(name), res_(d) {}
277 };
278 
279 IMPATOM_END_NAMESPACE
280 
281 #endif /* IMPATOM_SELECTION_H */
Hierarchies get_leaves(Hierarchy h)
double get_surface_area(const BoundingBoxD< 3 > &g)
Definition: BoundingBoxD.h:160
double get_mass(const Selection &s)
IMP::kernel::ParticleIndexes ParticleIndexes
The base class for geometry.
Display a Selection.
Definition: Selection.h:267
#define IMP_VALUES(Name, PluralName)
Define the type for storing sets of values.
The type of an atom.
kernel::Restraint * create_distance_restraint(const Selection &n0, const Selection &n1, double x0, double k, std::string name="Distance%1%")
Implement geometry for the basic shapes from IMP.algebra.
A particle with a user-defined type.
kernel::Restraint * create_connectivity_restraint(const Selections &s, double k, std::string name="Connectivity%1%")
Import IMP/kernel/SingletonPredicate.h in the namespace.
Decorator for helping deal with a hierarchy of molecules.
double get_volume(const BoundingBoxD< D > &bb)
Definition: BoundingBoxD.h:147
core::XYZR create_cover(const Selection &s, std::string name=std::string())
IMP::base::Vector< IMP::base::Pointer< SingletonPredicate > > SingletonPredicates
#define IMP_SHOWABLE(Name)
The standard decorator for manipulating molecular structures.
Basic types used by IMP.
A decorator for Residues.
The type for a residue.
void set_target_radius(double r)
Definition: Selection.h:106
A restraint is a term in an IMP ScoringFunction.
double get_radius_of_gyration(const Vector3Ds &ps)
Return the radius of gyration of a set of points.
Definition: Vector3D.h:65
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Class to handle individual model particles.
kernel::Restraint * create_internal_connectivity_restraint(const Selection &s, double k, std::string name="Connectivity%1%")
Key< 34897493, true > ParticleType
Definition: Typed.h:31
virtual Geometries get_components() const
Return a set of geometry composing this one.
kernel::Restraint * create_excluded_volume_restraint(const Hierarchies &hs, double resolution=-1)
Decorator for a sphere-like particle.
Class for storing model, its restraints, constraints, and particles.
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27