IMP logo
IMP Reference Guide  develop.1a86c4215a,2024/04/24
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-2022 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(Model *m, 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(Model *m, 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(Model *m, 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
54  static bool get_is_setup(Model *m, ParticleIndex pi,
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 */
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
SphereD< 3 > Sphere3D
Typedef for Python.
Definition: SphereD.h:104
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()
Get the key for the radius.
Definition: XYZR.h:76
const algebra::Sphere3D get_sphere_d_geometry(CustomXYZR d)
Definition: CustomXYZR.h:90
static bool get_is_setup(Model *m, ParticleIndex pi, FloatKey radius_key=get_default_radius_key())
Check if the particle has the required attributes.
Definition: CustomXYZR.h:54
#define IMP_DECORATOR_TRAITS_SETUP_1(Name, FirstArgumentType,first_argument_name)
static XYZ setup_particle(Model *m, ParticleIndex pi)
Definition: XYZ.h:51
Simple XYZ decorator.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
void set_sphere(const algebra::Sphere3D &s)
Set the attributes from a sphere.
Definition: CustomXYZR.h:66
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
add particle attribute with the specified key and initial value
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
Definition: XYZ.h:62
#define IMP_DECORATOR_TRAITS_SETUP_0(Name)
algebra::Sphere3D get_sphere() const
Return a sphere object.
Definition: CustomXYZR.h:61
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:109
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:194
#define IMP_DECORATOR_WITH_TRAITS_METHODS(Name, Parent, TraitsType,traits_name, default_traits)
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: types.h:19
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
bool get_has_attribute(TypeKey attribute_key, ParticleIndex particle) const
return true if particle has attribute with the specified key
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.
double get_distance(const Line3D &s, const Vector3D &p)
Get closest distance between a line and a point.
Class for adding derivatives from restraints to the model.