IMP  2.1.1
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-2013 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 "internal/dihedral_helpers.h"
14 
15 #include <IMP/Decorator.h>
16 #include <IMP/algebra/Vector3D.h>
18 #include <vector>
19 #include <limits>
20 
21 IMPCORE_BEGIN_NAMESPACE
22 
23 //! A decorator for a particle with x,y,z coordinates.
24 /** \inlineimage{xyz.png, 50} Using the decorator one can
25  get and set coordinates and modify derivatives.
26 
27  \ingroup helper
28  \ingroup decorators
29  \include XYZ_Decorator.py
30  \see XYZR
31  */
32 class IMPCOREEXPORT XYZ : public Decorator {
33  static void do_setup_particle(
35  // This method and the next one need to take a vector (not a ref)
36  // as otherwise, you can pass the vector from one and use it to
37  // create another. But this would resize the vector and so invalidate
38  // the passed reference. Ick.
39  const algebra::Vector3D v = algebra::Vector3D(0, 0, 0)) {
40  m->add_attribute(get_coordinate_key(0), pi, v[0]);
41  m->add_attribute(get_coordinate_key(1), pi, v[1]);
42  m->add_attribute(get_coordinate_key(2), pi, v[2]);
43  }
44 
45  public:
46  static FloatKey get_coordinate_key(unsigned int i) {
47  IMP_USAGE_CHECK(i < 3, "Out of range coordinate");
48  return IMP::internal::xyzr_keys[i];
49  }
50 
52  /** Setup the particle with unspecified coordinates. */
55 
56  IMP_DECORATOR_GET_SET(x, get_coordinate_key(0), Float, Float);
57  IMP_DECORATOR_GET_SET(y, get_coordinate_key(1), Float, Float);
58  IMP_DECORATOR_GET_SET(z, get_coordinate_key(2), Float, Float);
59  //! set the ith coordinate
60  void set_coordinate(unsigned int i, Float v) {
61  get_model()->get_sphere(get_particle_index())[i] = v;
62  }
63  //! set all coordinates from a vector
65  get_model()->get_sphere(get_particle_index())[0] = v[0];
66  get_model()->get_sphere(get_particle_index())[1] = v[1];
67  get_model()->get_sphere(get_particle_index())[2] = v[2];
68  }
69 
70  //! Get the ith coordinate
71  Float get_coordinate(int i) const {
72  return get_model()->get_sphere(get_particle_index())[i];
73  }
74  //! Get the ith coordinate derivative
75  Float get_derivative(int i) const { return get_derivatives()[i]; }
76  //! Add something to the derivative of the ith coordinate
78  get_particle()->add_to_derivative(get_coordinate_key(i), v, d);
79  }
80  //! Add something to the derivative of the coordinates
83  get_model()->add_to_coordinate_derivatives(get_particle_index(), v, d);
84  }
85  //! Get whether the coordinates are optimized
86  /** \return true only if all of them are optimized.
87  */
89  return get_particle()->get_is_optimized(get_coordinate_key(0)) &&
90  get_particle()->get_is_optimized(get_coordinate_key(1)) &&
91  get_particle()->get_is_optimized(get_coordinate_key(2));
92  }
93  //! Set whether the coordinates are optimized
94  void set_coordinates_are_optimized(bool tf) const {
95  get_particle()->set_is_optimized(get_coordinate_key(0), tf);
96  get_particle()->set_is_optimized(get_coordinate_key(1), tf);
97  get_particle()->set_is_optimized(get_coordinate_key(2), tf);
98  }
99 
100  //! Get the vector from this particle to another
102  return b.get_coordinates() - get_coordinates();
103  ;
104  }
105 
106  //! Convert it to a vector.
107  /** Somewhat suspect based on wanting a Point/Vector differentiation
108  but we don't have points */
110  return get_model()->get_sphere(get_particle_index()).get_center();
111  }
112 
113  //! Get the vector of derivatives.
114  /** Somewhat suspect based on wanting a Point/Vector differentiation
115  but we don't have points */
117  return get_model()->get_coordinate_derivatives(get_particle_index());
118  }
119 
120  static bool get_is_setup(kernel::Model *m, kernel::ParticleIndex pi) {
121  return m->get_has_attribute(get_coordinate_key(2), pi);
122  }
123 
124  //! Get a vector containing the keys for x,y,z
125  /** This is quite handy for initializing movers and things.
126  */
127  static const FloatKeys &get_xyz_keys();
128 };
129 
130 //! Compute the distance between a pair of particles
131 /** compute the ditance between the x,y,z coordinates of a and b
132  \ingroup helper
133  See XYZ
134  */
135 inline double get_distance(XYZ a, XYZ b) {
137 }
138 
139 //! Compute the dihedral angle (in radians) between the four particles
140 /** \ingroup helper
141  See XYZ
142  */
143 inline double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d) {
144  return internal::dihedral(a, b, c, d, nullptr, nullptr, nullptr, nullptr);
145 }
146 
147 //! Apply a transformation to the particle
148 /** See XYZ
149  See algebra::Transformation3D
150 */
151 IMPCOREEXPORT void transform(XYZ a, const algebra::Transformation3D &tr);
152 
153 /** \genericgeometry */
154 inline const algebra::Vector3D get_vector_d_geometry(XYZ d) {
155  return d.get_coordinates();
156 }
157 /** \genericgeometry */
158 inline void set_vector_d_geometry(XYZ d, const algebra::Vector3D &v) {
159  d.set_coordinates(v);
160 }
161 
163 
164 IMPCORE_END_NAMESPACE
165 
166 #ifndef SWIG
167 // use koenig lookup
168 // swig doesn't like having the overloads in different namespaces
169 // it will do the conversion implicitly anyway
170 IMPKERNEL_BEGIN_NAMESPACE
171 /** \genericgeometry */
172 inline const algebra::Vector3D get_vector_d_geometry(kernel::Particle *p) {
173  return core::XYZ(p).get_coordinates();
174 }
175 /** \genericgeometry */
177  const algebra::Vector3D &v) {
179 }
180 
181 IMPKERNEL_END_NAMESPACE
182 #endif
183 
184 #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:81
Simple 3D transformation class.
Class for adding derivatives from restraints to the model.
Particle * get_particle() const
void set_vector_d_geometry(VectorD< D > &g, const VectorD< D > &v)
Definition: VectorD.h:614
double get_dihedral(XYZ a, XYZ b, XYZ c, XYZ d)
Compute the dihedral angle (in radians) between the four particles.
Definition: XYZ.h:143
#define IMP_DECORATOR_METHODS(Name, Parent)
Model * get_model() const
Returns the Model containing the particle.
bool get_coordinates_are_optimized() const
Get whether the coordinates are optimized.
Definition: XYZ.h:88
void set_coordinate(unsigned int i, Float v)
set the ith coordinate
Definition: XYZ.h:60
#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:75
double get_distance(const Plane3D &pln, const Vector3D &p)
Return the distance between a plane and a point in 3D.
Definition: Plane3D.h:68
void transform(Hierarchy h, const algebra::Transformation3D &tr)
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
Definition: XYZ.h:64
static bool get_is_setup(Particle *p)
Return true if the particle can be cast to the decorator.
#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:32
Float get_coordinate(int i) const
Get the ith coordinate.
Definition: XYZ.h:71
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
Definition: XYZ.h:109
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:101
void set_coordinates_are_optimized(bool tf) const
Set whether the coordinates are optimized.
Definition: XYZ.h:94
algebra::Vector3D get_derivatives() const
Get the vector of derivatives.
Definition: XYZ.h:116
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:77
#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.