IMP  2.2.1
The Integrative Modeling Platform
CustomXYZR.h
Go to the documentation of this file.
1 /**
2  * \file IMP/misc/CustomXYZR.h
3  * \brief Decorator for a sphere-like particle.
4  *
5  * Copyright 2007-2014 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPMISC_CUSTOM_XYZ_R_H
10 #define IMPMISC_CUSTOM_XYZ_R_H
11 
12 #include <IMP/misc/misc_config.h>
13 #include <IMP/core/XYZ.h>
14 #include <IMP/core/XYZR.h>
15 #include <IMP/algebra/Sphere3D.h>
16 
17 #include <limits>
18 
19 IMPMISC_BEGIN_NAMESPACE
20 
21 //! A decorator for a particle with x,y,z coordinates and a radius.
22 /** This is mostly just a sample decorator.
23  */
24 class IMPMISCEXPORT CustomXYZR : public core::XYZ {
25  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
26  FloatKey radius_key) {
27  if (!XYZ::get_is_setup(m, pi)) {
28  XYZ::setup_particle(m, pi);
29  }
30  m->add_attribute(radius_key, pi, 0, false);
31  }
32  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
33  Float radius, FloatKey radius_key) {
34  if (!XYZ::get_is_setup(m, pi)) {
35  XYZ::setup_particle(m, pi);
36  }
37  m->add_attribute(radius_key, pi, radius, false);
38  }
39  static void do_setup_particle(kernel::Model *m, kernel::ParticleIndex pi,
40  const algebra::Sphere3D &s,
41  FloatKey radius_key) {
42  XYZ::setup_particle(m, pi, s.get_center());
43  m->add_attribute(radius_key, pi, s.get_radius(), false);
44  }
45 
46  public:
52 
53  //! Check if the particle has the required attributes
55  FloatKey radius_key = get_default_radius_key()) {
56  return m->get_has_attribute(radius_key, pi);
57  }
58  IMP_DECORATOR_GET_SET(radius, get_decorator_traits(), Float, Float);
59 
60  //! Return a sphere object
62  return algebra::Sphere3D(get_coordinates(), get_radius());
63  }
64 
65  //! Set the attributes from a sphere
66  void set_sphere(const algebra::Sphere3D &s) {
67  set_coordinates(s.get_center());
68  set_radius(s.get_radius());
69  }
70  //! Get the default radius key.
72  return IMP::internal::xyzr_keys[3];
73  }
74  void add_to_radius_derivative(double v, DerivativeAccumulator &d) {
75  get_particle()->add_to_derivative(get_decorator_traits(), v, d);
76  }
77  FloatKey get_traits() { return get_decorator_traits(); }
78 };
79 
80 IMP_DECORATORS(CustomXYZR, CustomXYZRs, core::XYZs);
81 
82 //! Compute the distance between a pair of particles
83 /** See XYZR
84  */
85 inline double get_distance(CustomXYZR a, CustomXYZR b) {
87 }
88 
89 /** \genericgeometry */
91  return d.get_sphere();
92 }
93 
94 /** \genericgeometry */
96  d.set_sphere(v);
97 }
98 
99 IMPMISC_END_NAMESPACE
100 
101 #endif /* IMPMISC_CUSTOM_XYZ_R_H */
SphereD< 3 > Sphere3D
Definition: SphereD.h:89
Class for adding derivatives from restraints to the model.
double get_distance(CustomXYZR a, CustomXYZR b)
Compute the distance between a pair of particles.
Definition: CustomXYZR.h:85
A decorator for a particle with x,y,z coordinates and a radius.
Definition: CustomXYZR.h:24
static FloatKey get_radius_key()
Definition: XYZR.h:76
Particle * get_particle() const
const algebra::Sphere3D get_sphere_d_geometry(CustomXYZR d)
Definition: CustomXYZR.h:90
static XYZ setup_particle(kernel::Model *m, ParticleIndex pi)
Definition: XYZ.h:51
#define IMP_DECORATOR_WITH_TRAITS_METHODS(Name, Parent, TraitsType,traits_name, default_traits)
Simple xyz decorator.
#define IMP_DECORATOR_TRAITS_SETUP_1(Name, FirstArgumentType,first_argument_name)
void set_sphere(const algebra::Sphere3D &s)
Set the attributes from a sphere.
Definition: CustomXYZR.h:66
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_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
Definition: XYZ.h:62
static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi, FloatKey radius_key=get_default_radius_key())
Check if the particle has the required attributes.
Definition: CustomXYZR.h:54
algebra::Sphere3D get_sphere() const
Return a sphere object.
Definition: CustomXYZR.h:61
#define IMP_DECORATOR_TRAITS_SETUP_0(Name)
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:107
void set_sphere_d_geometry(CustomXYZR d, const algebra::Sphere3D &v)
Definition: CustomXYZR.h:95
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)
static FloatKey get_default_radius_key()
Get the default radius key.
Definition: CustomXYZR.h:71
Simple 3D sphere class.
Decorator for a sphere-like particle.
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
#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