IMP  2.1.1
The Integrative Modeling Platform
XYZR.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/XYZR.h
3  * \brief Decorator for a sphere-like particle.
4  *
5  * Copyright 2007-2013 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>
17 #include <limits>
18 
19 IMPCORE_BEGIN_NAMESPACE
20 
21 //! A decorator for a particle with x,y,z coordinates and a radius.
22 /** \ingroup decorators
23 
24  A simple example illustrating some of the functionality.
25  \include XYZR_Decorator.py
26  */
27 class IMPCOREEXPORT XYZR : public XYZ {
28  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
29  const algebra::Sphere3D s) {
30  XYZ::setup_particle(m, pi, s.get_center());
31  do_setup_particle(m, pi, s.get_radius());
32  }
33 
34  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
35  double r) {
36  m->add_attribute(get_radius_key(), pi, r, false);
37  }
38 
39  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi) {
40  if (!XYZ::get_is_setup(m, pi)) {
41  XYZ::setup_particle(m, pi);
42  }
43  m->add_attribute(get_radius_key(), pi, 0, false);
44  }
45 
46  public:
49  /** Setup an XYZ particle as an XYZR particle. */
52 
53  /** Add the coordinates and radius from the sphere to the particle.
54  */
55 
56  //! Check if the particle has the required attributes
58  return m->get_has_attribute(get_radius_key(), pi);
59  }
60 
61  double get_radius() const { return get_sphere().get_radius(); }
62  void set_radius(double r) const {
63  get_model()->get_sphere(get_particle_index())[3] = r;
64  }
65 
66  //! Return a sphere object
67  const algebra::Sphere3D &get_sphere() const {
68  return get_model()->get_sphere(get_particle_index());
69  }
70 
71  //! Set the attributes from a sphere
72  void set_sphere(const algebra::Sphere3D &s) {
73  get_model()->get_sphere(get_particle_index()) = s;
74  }
75  /** Get the key for the radius. */
76  static FloatKey get_radius_key() { return IMP::internal::xyzr_keys[3]; }
77  void add_to_radius_derivative(double v, DerivativeAccumulator &d) {
78  get_particle()->add_to_derivative(get_radius_key(), v, d);
79  }
80 };
81 
82 IMP_DECORATORS(XYZR, XYZRs, XYZs);
83 
84 //! Compute the sphere distance between a and b
85 /** Compute the spere distance between a and b
86  See XYZR
87  */
88 inline double get_distance(XYZR a, XYZR b) {
90 }
91 
92 //! Set the coordinates and radius of the first to enclose the list
93 /** \param[in] v The vector of XYZ or XYZR particles to enclose
94  \param[out] b The one whose values should be set
95  \param[in] slack An amount to add to the radius.
96  Any particle which does not have the attribute b.get_radius()
97  is assumed to have a radius of 0.
98 
99  \note This function produces tighter bounds if the \ref cgal "CGAL"
100  library is available.
101  \ingroup CGAL
102  See XYZR
103  */
104 IMPCOREEXPORT void set_enclosing_sphere(XYZR b, const XYZs &v,
105  double slack = 0);
106 
107 //! Set the radius of the first to enclose the list
108 /** \param[in] v The vector of XYZ or XYZR particles to enclose
109  \param[out] b The one whose radius should be set
110  Any particle which does not have the attribute b.get_radius()
111  is assumed to have a radius of 0.
112 
113  See XYZR
114  */
115 IMPCOREEXPORT void set_enclosing_radius(XYZR b, const XYZs &v);
116 
117 //! Get a sphere enclosing the set of XYZRs
118 /** \param[in] v The one whose radius should be set
119  Any particle which does not have the attribute b.get_radius()
120  is assumed to have a radius of 0.
121 
122  See XYZR
123  */
124 IMPCOREEXPORT algebra::Sphere3D get_enclosing_sphere(const XYZs &v);
125 
126 //! Create a set of particles with random coordinates
127 /** This function is mostly to be used to keep demo code brief.
128  \param[in] m The model to add them to.
129  \param[in] num The number of particles to create.
130  \param[in] radius The radius to give them.
131  \param[in] box_side The particles have coordinates from -box_side
132  to box_side.
133  See XYZR
134 
135  The particles coordinates are optimized.
136  */
137 IMPCOREEXPORT XYZRs create_xyzr_particles(kernel::Model *m, unsigned int num,
138  Float radius, Float box_side = 10);
139 
140 /** \genericgeometry */
142  return d.get_sphere();
143 }
144 
145 /** \genericgeometry */
146 inline void set_sphere_d_geometry(XYZR d, const algebra::Sphere3D &v) {
147  d.set_sphere(v);
148 }
149 
150 /** \class XYZRGeometry
151  \brief Display an IMP::core::XYZR particle as a ball.
152 
153  \class XYZRsGeometry
154  \brief Display an IMP::SingletonContainer of IMP::core::XYZR particles
155  as balls.
156 */
157 IMP_PARTICLE_GEOMETRY(XYZR, core::XYZR, {
158  display::SphereGeometry *g = new display::SphereGeometry(d.get_sphere());
159  ret.push_back(g);
160 });
161 
162 IMP_PARTICLE_GEOMETRY(XYZDerivative, core::XYZ, {
163  algebra::Segment3D s(d.get_coordinates(),
164  d.get_coordinates() + d.get_derivatives());
166  ret.push_back(g);
167 });
168 
169 /** \class EdgePairGeometry
170  \brief Display a segment connecting a pair of particles.
171 
172  \class EdgePairsGeometry
173  \brief Display a segment for each pair in a
174  IMP::kernel::PairContainer.
175 */
176 IMP_PARTICLE_PAIR_GEOMETRY(EdgePair, core::XYZ, {
177  ret.push_back(new display::SegmentGeometry(
178  algebra::Segment3D(d0.get_coordinates(), d1.get_coordinates())));
179 });
180 
181 IMPCORE_END_NAMESPACE
182 
183 #ifndef SWIG
184 // swig doesn't like having the overloads in different namespaces
185 // it will do the conversion implicitly anyway
186 IMPKERNEL_BEGIN_NAMESPACE
187 /** \genericgeometry */
189  return core::XYZR(p).get_sphere();
190 }
191 
192 /** \genericgeometry */
194  const algebra::Sphere3D &v) {
195  core::XYZR(p).set_sphere(v);
196 }
197 
198 /** \genericgeometry */
200  kernel::Particle *p) {
201  return get_bounding_box(core::XYZR(p).get_sphere());
202 }
203 IMPKERNEL_END_NAMESPACE
204 #endif
205 
206 #endif /* IMPCORE_XYZ_R_H */
Class for adding derivatives from restraints to the model.
static FloatKey get_radius_key()
Definition: XYZR.h:76
Particle * get_particle() const
Sphere3D get_enclosing_sphere(const Sphere3Ds &ss)
Return a sphere containing the listed spheres.
The base class for geometry.
#define IMP_DECORATOR_METHODS(Name, Parent)
Model * get_model() const
Returns the Model containing the particle.
macros for display classes
static XYZ setup_particle(kernel::Model *m, ParticleIndex pi)
Definition: XYZ.h:53
Simple xyz decorator.
static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi)
Check if the particle has the required attributes.
Definition: XYZR.h:57
const algebra::Sphere3D & get_sphere() const
Return a sphere object.
Definition: XYZR.h:67
Implement geometry for the basic shapes from IMP.algebra.
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:68
void set_sphere(const algebra::Sphere3D &s)
Set the attributes from a sphere.
Definition: XYZR.h:72
#define IMP_DECORATOR_SETUP_0(Name)
XYZRs create_xyzr_particles(kernel::Model *m, unsigned int num, Float radius, Float box_side=10)
Create a set of particles with random coordinates.
Represent an XYZR particle with a sphere.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:32
Class to handle individual model particles.
const SphereD< D > & get_sphere_d_geometry(const SphereD< D > &g)
Definition: SphereD.h:89
void set_sphere_d_geometry(SphereD< D > &g, const SphereD< D > &v)
Definition: SphereD.h:89
double Float
Basic floating-point value (could be float, double...)
Definition: base/types.h:20
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
void set_enclosing_radius(XYZR b, const XYZs &v)
Set the radius of the first to enclose the list.
Simple 3D sphere class.
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
const BoundingBoxD< D > & get_bounding_box_d_geometry(const BoundingBoxD< D > &g)
Definition: BoundingBoxD.h:160
void set_enclosing_sphere(XYZR b, const XYZs &v, double slack=0)
Set the coordinates and radius of the first to enclose the list.
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Class for storing model, its restraints, constraints, and particles.
BoundingBoxD< D > get_bounding_box(const BoundingBoxD< D > &g)
Definition: BoundingBoxD.h:160
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27