IMP  2.2.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-2014 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 /** \class XYZRGeometry
141  \brief Display an IMP::core::XYZR particle as a ball.
142 
143  \class XYZRsGeometry
144  \brief Display an IMP::SingletonContainer of IMP::core::XYZR particles
145  as balls.
146 */
147 IMP_PARTICLE_GEOMETRY(XYZR, core::XYZR, {
148  display::SphereGeometry *g = new display::SphereGeometry(d.get_sphere());
149  ret.push_back(g);
150 });
151 
152 IMP_PARTICLE_GEOMETRY(XYZDerivative, core::XYZ, {
153  algebra::Segment3D s(d.get_coordinates(),
154  d.get_coordinates() + d.get_derivatives());
156  ret.push_back(g);
157 });
158 
159 /** \class EdgePairGeometry
160  \brief Display a segment connecting a pair of particles.
161 
162  \class EdgePairsGeometry
163  \brief Display a segment for each pair in a
164  IMP::kernel::PairContainer.
165 */
166 IMP_PARTICLE_PAIR_GEOMETRY(EdgePair, core::XYZ, {
167  ret.push_back(new display::SegmentGeometry(
168  algebra::Segment3D(d0.get_coordinates(), d1.get_coordinates())));
169 });
170 
171 IMPCORE_END_NAMESPACE
172 
173 #endif /* IMPCORE_XYZ_R_H */
ParticleIndex get_particle_index() const
Class for adding derivatives from restraints to the model.
static FloatKey get_radius_key()
Definition: XYZR.h:76
Particle * get_particle() const
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:51
double get_distance(XYZR a, XYZR b)
Compute the sphere distance between a and b.
Definition: XYZR.h:88
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:67
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:30
algebra::Sphere3D get_enclosing_sphere(const XYZs &v)
Get a sphere enclosing the set of XYZRs.
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)
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.
Definition: kernel/Model.h:72
A decorator for a particle with x,y,z coordinates and a radius.
Definition: XYZR.h:27