IMP logo
XYZR.h
Go to the documentation of this file.
1 /**
2  * \file XYZR.h
3  * \brief Decorator for a sphere-like particle.
4  *
5  * Copyright 2007-2012 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPCORE_XYZ_R_H
10 #define IMPCORE_XYZ_R_H
11 
12 #include "XYZ.h"
13 #include <IMP/algebra/Sphere3D.h>
16 #include <limits>
17 
18 IMPCORE_BEGIN_NAMESPACE
19 
20 //! A decorator for a particle with x,y,z coordinates and a radius.
21 /** \ingroup decorators
22 
23  A simple example illustrating some of the functionality.
24  \pythonexample{XYZR_Decorator}
25  */
26 class IMPCOREEXPORT XYZR:
27  public XYZ
28 {
29 public:
31 
32  /** Create a decorator using radius_key to store the FloatKey.
33  \param[in] p The particle to wrap.
34  */
35  static XYZR setup_particle(Particle *p) {
36  if (!XYZ::particle_is_instance(p)) {
37  XYZ::setup_particle(p);
38  }
39  p->add_attribute(get_radius_key(), 0, false);
40  return XYZR(p);
41  }
42 
43 
44  /** Create a decorator using radius_key to store the FloatKey.
45  The particle should already be an XYZ particle.
46  \param[in] p The particle to wrap.
47  \param[in] radius The radius to set initially
48  */
49  static XYZR setup_particle(Particle *p,
50  Float radius) {
51  p->add_attribute(get_radius_key(), radius, false);
52  return XYZR(p);
53  }
54 
55  /** Create a decorator using radius_key to store the FloatKey.
56  \param[in] p The particle to wrap.
57  \param[in] s The sphere to use to set the position and radius
58  */
59  static XYZR setup_particle(Particle *p,
60  const algebra::Sphere3D &s) {
61  XYZ::setup_particle(p, s.get_center());
62  p->add_attribute(get_radius_key(), s.get_radius(), false);
63  return XYZR(p);
64  }
65 
66  //! Check if the particle has the required attributes
67  static bool particle_is_instance(Particle *p) {
68  return p->has_attribute(get_radius_key());
69  }
70  double get_radius() const {
71  return get_sphere().get_radius();
72  }
73  void set_radius(double r) const {
74  get_model()->get_sphere(get_particle_index())[3]=r;
75  }
76 
77 
78  //! Return a sphere object
79  const algebra::Sphere3D& get_sphere() const {
80  return get_model()->get_sphere(get_particle_index());
81  }
82 
83  //! Set the attributes from a sphere
84  void set_sphere(const algebra::Sphere3D &s) {
85  get_model()->get_sphere(get_particle_index())=s;
86  }
87  //! Get the default radius key.
88  static FloatKey get_radius_key() {
89  return IMP::internal::xyzr_keys[3];
90  }
91  void add_to_radius_derivative(double v,
93  get_particle()->add_to_derivative(get_radius_key(), v, d);
94  }
95 };
96 
97 IMP_DECORATORS(XYZR,XYZRs, XYZs);
98 
99 //! Compute the distance between a pair of particles
100 /** \relatesalso XYZR
101  */
102 inline double get_distance(XYZR a, XYZR b) {
104 }
105 
106 //! Set the coordinates and radius of the first to enclose the list
107 /** \param[in] v The vector of XYZ or XYZR particles to enclose
108  \param[out] b The one whose values should be set
109  \param[in] slack An amount to add to the radius.
110  Any particle which does not have the attribute b.get_radius()
111  is assumed to have a radius of 0.
112 
113  \note This function produces tighter bounds if the \ref cgal "CGAL"
114  library is available.
115  \ingroup CGAL
116  \relatesalso XYZR
117  */
118 IMPCOREEXPORT void set_enclosing_sphere(XYZR b,
119  const XYZs &v,
120  double slack=0);
121 
122 //! Set the radius of the first to enclose the list
123 /** \param[in] v The vector of XYZ or XYZR particles to enclose
124  \param[out] b The one whose radius should be set
125  Any particle which does not have the attribute b.get_radius()
126  is assumed to have a radius of 0.
127 
128  \relatesalso XYZR
129  */
130 IMPCOREEXPORT void set_enclosing_radius(XYZR b,
131  const XYZs &v);
132 
133 //! Get a sphere enclosing the set of XYZRs
134 /** \param[in] v The one whose radius should be set
135  Any particle which does not have the attribute b.get_radius()
136  is assumed to have a radius of 0.
137 
138  \relatesalso XYZR
139  */
140 IMPCOREEXPORT algebra::Sphere3D get_enclosing_sphere(const XYZs& v);
141 
142 //! Create a set of particles which random coordinates
143 /** This function is mostly to be used to keep demo code brief.
144  \param[in] m The model to add them to.
145  \param[in] num The number of particles to create.
146  \param[in] radius The radius to give them.
147  \param[in] box_side The particles have coordinates from -box_side
148  to box_side.
149  \relatesalso XYZR
150 
151  The particles coordinates are optimized.
152  */
153 IMPCOREEXPORT XYZRs create_xyzr_particles(Model *m,
154  unsigned int num,
155  Float radius,
156  Float box_side=10);
157 
158 /** \genericgeometry */
159 inline const algebra::Sphere3D get_sphere_d_geometry(XYZR d) {
160  return d.get_sphere();
161 }
162 
163 /** \genericgeometry */
164 inline void set_sphere_d_geometry(XYZR d, const algebra::Sphere3D &v) {
165  d.set_sphere(v);
166 }
167 
168 
169 
170 /** \class XYZRGeometry
171  \brief Display an IMP::core::XYZR particle as a ball.
172 
173  \class XYZRsGeometry
174  \brief Display an IMP::SingletonContainer of IMP::core::XYZR particles
175  as balls.
176 */
177 IMP_PARTICLE_GEOMETRY(XYZR, core::XYZR,
178  {
180  if (display::Colored::particle_is_instance(d)) {
181  g->set_color(display::Colored(d).get_color());
182  }
183  ret.push_back(g);
184  });
185 
186 
187 
188 
189 IMP_PARTICLE_GEOMETRY(XYZDerivative, core::XYZ, {
193  ret.push_back(g);
194  });
195 
196 
197 /** \class EdgePairGeometry
198  \brief Display an IMP::atom::Bond particle as a segment.
199 
200  \class EdgePairsGeometry
201  \brief Display an IMP::SingletonContainer of IMP::atom::Bond particles
202  as segments.
203 */
204 IMP_PARTICLE_PAIR_GEOMETRY(EdgePair, core::XYZ, {
205  ret.push_back(
206  new display::SegmentGeometry(algebra::Segment3D(d0.get_coordinates(),
207  d1.get_coordinates())));
208  });
209 
210 IMPCORE_END_NAMESPACE
211 
212 #ifndef SWIG
213 // swig doesn't like having the overloads in different namespaces
214 // it will do the conversion implicitly anyway
215 IMP_BEGIN_NAMESPACE
216 /** \genericgeometry */
217 inline const algebra::Sphere3D get_sphere_d_geometry(Particle *p) {
218  return core::XYZR(p).get_sphere();
219 }
220 
221 /** \genericgeometry */
222 inline void set_sphere_d_geometry(Particle *p, const algebra::Sphere3D &v) {
223  core::XYZR(p).set_sphere(v);
224 }
225 
226 /** \genericgeometry */
227 inline const algebra::BoundingBoxD<3>
229  return get_bounding_box(core::XYZR(p).get_sphere());
230 }
231 IMP_END_NAMESPACE
232 #endif
233 
234 #endif /* IMPCORE_XYZ_R_H */

Generated on Tue May 22 2012 23:33:17 for IMP by doxygen 1.8.1