IMP  2.2.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-2014 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 /** \inlineimage{xyz.png, 50} 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(
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 
104  //! Convert it to a vector.
105  /** Somewhat suspect based on wanting a Point/Vector differentiation
106  but we don't have points */
108  return get_model()->get_sphere(get_particle_index()).get_center();
109  }
110 
111  //! Get the vector of derivatives.
112  /** Somewhat suspect based on wanting a Point/Vector differentiation
113  but we don't have points */
115  return get_model()->get_coordinate_derivatives(get_particle_index());
116  }
117 
118  static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi) {
119  return m->get_has_attribute(get_coordinate_key(2), pi);
120  }
121 
122  //! Get a vector containing the keys for x,y,z
123  /** This is quite handy for initializing movers and things.
124  */
125  static const FloatKeys &get_xyz_keys();
126 };
127 
128 /** \genericgeometry */
129 inline void set_vector_geometry(XYZ d, const algebra::Vector3D &v) {
130  d.set_coordinates(v);
131 }
132 /** \genericgeometry */
133 inline const algebra::Vector3D get_vector_geometry(XYZ d) {
134  return d.get_coordinates();
135 }
136 
137 IMPCORE_END_NAMESPACE
138 
139 #ifndef SWIG
140 // swig doesn't like having the overloads in different namespaces
141 // it will do the conversion implicitly anyway
142 IMPKERNEL_BEGIN_NAMESPACE
143 
144 /** \genericgeometry */
145 inline const algebra::Vector3D get_vector_geometry(Particle *p) {
146  return core::XYZ(p).get_coordinates();
147 }
148 /** \genericgeometry */
149 inline void set_vector_geometry(Particle *p, const algebra::Vector3D &v) {
151 }
152 
153 inline const algebra::Vector3D get_vector_geometry(Decorator d) {
154  return core::XYZ(d).get_coordinates();
155 }
156 /** \genericgeometry */
159 }
160 
161 IMPKERNEL_END_NAMESPACE
162 IMPBASE_BEGIN_NAMESPACE
163 inline const algebra::Vector3D get_vector_geometry(
165  return core::XYZ(d).get_coordinates();
166 }
167 /** \genericgeometry */
169  const algebra::Vector3D &v) {
171 }
172 inline const algebra::Vector3D get_vector_geometry(
174  return core::XYZ(d).get_coordinates();
175 }
176 /** \genericgeometry */
178  const algebra::Vector3D &v) {
180 }
181 IMPBASE_END_NAMESPACE
182 
183 #endif
184 
185 IMPCORE_BEGIN_NAMESPACE
186 
187 //! Compute the distance between a pair of particles
188 /** compute the ditance between the x,y,z coordinates of a and b
189  \ingroup helper
190  See XYZ
191  */
192 inline double get_distance(XYZ a, XYZ b) {
194 }
195 
196 //! Compute the dihedral angle (in radians) between the four particles
197 /** \ingroup helper
198  See XYZ
199  */
200 IMPCOREEXPORT double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d);
201 
202 //! Apply a transformation to the particle
203 /** See XYZ
204  See algebra::Transformation3D
205 */
206 IMPCOREEXPORT void transform(XYZ a, const algebra::Transformation3D &tr);
207 
209 
210 IMPCORE_END_NAMESPACE
211 
212 #endif /* IMPCORE_XY_Z_H */
Import IMP/kernel/Decorator.h in the namespace.
void add_to_derivatives(const algebra::Vector3D &v, DerivativeAccumulator &d)
Add something to the derivative of the coordinates.
Definition: XYZ.h:79
ParticleIndex get_particle_index() const
Simple 3D transformation class.
Class for adding derivatives from restraints to the model.
Particle * get_particle() const
double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d)
Compute the dihedral angle (in radians) between the four particles.
#define IMP_DECORATOR_METHODS(Name, Parent)
void set_vector_geometry(base::Pointer< kernel::Particle > d, const algebra::Vector3D &v)
Definition: XYZ.h:177
Model * get_model() const
Returns the Model containing the particle.
A smart pointer to a reference counted object.
Definition: base/Pointer.h:87
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
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
Float get_derivative(int i) const
Get the ith coordinate derivative.
Definition: XYZ.h:73
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:192
#define IMP_DECORATOR_SETUP_0(Name)
Import IMP/kernel/decorator_macros.h in the namespace.
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
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:107
Class to handle individual model particles.
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
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:114
VectorD< 3 > Vector3D
Definition: VectorD.h:395
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)
Simple 3D vector class.
void add_to_derivative(int i, Float v, DerivativeAccumulator &d)
Add something to the derivative of the ith coordinate.
Definition: XYZ.h:75
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#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