IMP logo
IMP Reference Guide  2.6.0
The Integrative Modeling Platform
XYZ.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/XYZ.h \brief Simple XYZ decorator.
3  *
4  * Copyright 2007-2016 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPCORE_XY_Z_H
9 #define IMPCORE_XY_Z_H
10 
11 #include <IMP/core/core_config.h>
12 #include <IMP/decorator_macros.h>
13 #include <IMP/Decorator.h>
14 #include <IMP/algebra/Vector3D.h>
16 #include <vector>
17 #include <limits>
18 
19 IMPCORE_BEGIN_NAMESPACE
20 
21 //! A decorator for a particle with x,y,z coordinates.
22 /** Using the decorator one can
23  get and set coordinates and modify derivatives.
24 
25  \ingroup helper
26  \ingroup decorators
27  \include XYZ_Decorator.py
28  \see XYZR
29  */
30 class IMPCOREEXPORT XYZ : public Decorator {
31  static void do_setup_particle(
32  Model *m, ParticleIndex pi,
33  // This method and the next one need to take a vector (not a ref)
34  // as otherwise, you can pass the vector from one and use it to
35  // create another. But this would resize the vector and so invalidate
36  // the passed reference. Ick.
37  const algebra::Vector3D v = algebra::Vector3D(0, 0, 0)) {
38  m->add_attribute(get_coordinate_key(0), pi, v[0]);
39  m->add_attribute(get_coordinate_key(1), pi, v[1]);
40  m->add_attribute(get_coordinate_key(2), pi, v[2]);
41  }
42 
43  public:
44  static FloatKey get_coordinate_key(unsigned int i) {
45  IMP_USAGE_CHECK(i < 3, "Out of range coordinate");
46  return IMP::internal::xyzr_keys[i];
47  }
48 
50  /** Setup the particle with unspecified coordinates. */
53 
54  IMP_DECORATOR_GET_SET(x, get_coordinate_key(0), Float, Float);
55  IMP_DECORATOR_GET_SET(y, get_coordinate_key(1), Float, Float);
56  IMP_DECORATOR_GET_SET(z, get_coordinate_key(2), Float, Float);
57  //! set the ith coordinate
58  void set_coordinate(unsigned int i, Float v) {
59  get_model()->get_sphere(get_particle_index())[i] = v;
60  }
61  //! set all coordinates from a vector
63  get_model()->get_sphere(get_particle_index())[0] = v[0];
64  get_model()->get_sphere(get_particle_index())[1] = v[1];
65  get_model()->get_sphere(get_particle_index())[2] = v[2];
66  }
67 
68  //! Get the ith coordinate
69  Float get_coordinate(int i) const {
70  return get_model()->get_sphere(get_particle_index())[i];
71  }
72  //! Get the ith coordinate derivative
73  Float get_derivative(int i) const { return get_derivatives()[i]; }
74  //! Add something to the derivative of the ith coordinate
76  get_particle()->add_to_derivative(get_coordinate_key(i), v, d);
77  }
78  //! Add something to the derivative of the coordinates
81  get_model()->add_to_coordinate_derivatives(get_particle_index(), v, d);
82  }
83  //! Get whether the coordinates are optimized
84  /** \return true only if all of them are optimized.
85  */
87  return get_particle()->get_is_optimized(get_coordinate_key(0)) &&
88  get_particle()->get_is_optimized(get_coordinate_key(1)) &&
89  get_particle()->get_is_optimized(get_coordinate_key(2));
90  }
91  //! Set whether the coordinates are optimized
92  void set_coordinates_are_optimized(bool tf) const {
93  get_particle()->set_is_optimized(get_coordinate_key(0), tf);
94  get_particle()->set_is_optimized(get_coordinate_key(1), tf);
95  get_particle()->set_is_optimized(get_coordinate_key(2), tf);
96  }
97 
98  //! Get the vector from this particle to another
100  return b.get_coordinates() - get_coordinates();
101  }
102 
103  //! Convert it to a vector.
104  /** Somewhat suspect based on wanting a Point/Vector differentiation
105  but we don't have points */
107  return get_model()->get_sphere(get_particle_index()).get_center();
108  }
109 
110  //! Get the vector of derivatives.
111  /** Somewhat suspect based on wanting a Point/Vector differentiation
112  but we don't have points */
114  return get_model()->get_coordinate_derivatives(get_particle_index());
115  }
116 
117  static bool get_is_setup(Model *m, ParticleIndex pi) {
118  return m->get_has_attribute(get_coordinate_key(2), pi);
119  }
120 
121  //! Get a vector containing the keys for x,y,z
122  /** This is quite handy for initializing movers and things.
123  */
124  static const FloatKeys &get_xyz_keys();
125 };
126 
127 /** \genericgeometry */
128 inline void set_vector_geometry(XYZ d, const algebra::Vector3D &v) {
129  d.set_coordinates(v);
130 }
131 /** \genericgeometry */
132 inline const algebra::Vector3D get_vector_geometry(XYZ d) {
133  return d.get_coordinates();
134 }
135 
136 IMPCORE_END_NAMESPACE
137 
138 #ifndef SWIG
139 // swig doesn't like having the overloads in different namespaces
140 // it will do the conversion implicitly anyway
141 IMPKERNEL_BEGIN_NAMESPACE
142 
143 /** \genericgeometry */
144 inline const algebra::Vector3D get_vector_geometry(Particle *p) {
145  return core::XYZ(p).get_coordinates();
146 }
147 /** \genericgeometry */
148 inline void set_vector_geometry(Particle *p, const algebra::Vector3D &v) {
150 }
151 
152 inline const algebra::Vector3D get_vector_geometry(Decorator d) {
153  return core::XYZ(d).get_coordinates();
154 }
155 /** \genericgeometry */
158 }
159 
160 inline const algebra::Vector3D get_vector_geometry(
161  WeakPointer<Particle> d) {
162  return core::XYZ(d).get_coordinates();
163 }
164 /** \genericgeometry */
166  const algebra::Vector3D &v) {
168 }
169 inline const algebra::Vector3D get_vector_geometry(
170  Pointer<Particle> d) {
171  return core::XYZ(d).get_coordinates();
172 }
173 /** \genericgeometry */
175  const algebra::Vector3D &v) {
177 }
178 IMPKERNEL_END_NAMESPACE
179 
180 #endif
181 
182 IMPCORE_BEGIN_NAMESPACE
183 
184 //! Compute the distance between a pair of particles
185 /** compute the distance between the x,y,z coordinates of a and b
186  \ingroup helper
187  \see XYZ
188  */
189 inline double get_distance(XYZ a, XYZ b) {
191 }
192 
193 //! Compute the dihedral angle (in radians) between the four particles
194 /** \ingroup helper
195  \see XYZ
196  */
197 IMPCOREEXPORT double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d);
198 
199 //! Apply a transformation to the particle
200 /** \see XYZ
201  \see algebra::Transformation3D
202 */
203 IMPCOREEXPORT void transform(XYZ a, const algebra::Transformation3D &tr);
204 
205 IMP_DECORATORS(XYZ, XYZs, ParticlesTemp);
206 
207 IMPCORE_END_NAMESPACE
208 
209 #endif /* IMPCORE_XY_Z_H */
The base class for decorators.
void add_to_derivatives(const algebra::Vector3D &v, DerivativeAccumulator &d)
Add something to the derivative of the coordinates.
Definition: XYZ.h:79
#define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType)
Define methods for getting and setting a particular simple field.
Simple 3D transformation class.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:188
Smart pointer to Object-derived classes that does not refcount.
Definition: WeakPointer.h:76
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d)
Compute the dihedral angle (in radians) between the four particles.
Model * get_model() const
Returns the Model containing the particle.
Definition: Decorator.h:191
bool get_coordinates_are_optimized() const
Get whether the coordinates are optimized.
Definition: XYZ.h:86
void set_coordinate(unsigned int i, Float v)
set the ith coordinate
Definition: XYZ.h:58
void set_vector_geometry(Pointer< Particle > d, const algebra::Vector3D &v)
Definition: XYZ.h:174
A smart pointer to a reference counted object.
Definition: Pointer.h:87
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Float get_derivative(int i) const
Get the ith coordinate derivative.
Definition: XYZ.h:73
void add_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
Definition: XYZ.h:62
void transform(XYZ a, const algebra::Transformation3D &tr)
Apply a transformation to the particle.
double get_distance(XYZ a, XYZ b)
Compute the distance between a pair of particles.
Definition: XYZ.h:189
Various general useful macros for IMP.
A decorator for a particle with x,y,z coordinates.
Definition: XYZ.h:30
Float get_coordinate(int i) const
Get the ith coordinate.
Definition: XYZ.h:69
#define IMP_DECORATOR_SETUP_0(Name)
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:106
Simple 3D transformation class.
algebra::Vector3D get_vector_to(const XYZ &b) const
Get the vector from this particle to another.
Definition: XYZ.h:99
Particle * get_particle() const
Returns the particle decorated by this decorator.
Definition: Decorator.h:171
Interface to specialized Particle types (e.g. atoms)
Definition: Decorator.h:118
void set_coordinates_are_optimized(bool tf) const
Set whether the coordinates are optimized.
Definition: XYZ.h:92
algebra::Vector3D get_derivatives() const
Get the vector of derivatives.
Definition: XYZ.h:113
#define IMP_DECORATOR_METHODS(Name, Parent)
VectorD< 3 > Vector3D
Definition: VectorD.h:395
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Simple 3D vector class.
Class to handle individual model particles.
Definition: Particle.h:37
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Definition: check_macros.h:168
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
void add_to_derivative(int i, Float v, DerivativeAccumulator &d)
Add something to the derivative of the ith coordinate.
Definition: XYZ.h:75
Class for adding derivatives from restraints to the model.