IMP logo
IMP Reference Guide  2.15.0
The Integrative Modeling Platform
direction.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/direction.h
3  * \brief Decorators for directions and the angle between them.
4  *
5  * Copyright 2007-2021 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPCORE_DIRECTION_H
10 #define IMPCORE_DIRECTION_H
11 
12 #include <IMP/core/core_config.h>
13 #include <IMP/decorator_macros.h>
14 #include <IMP/Decorator.h>
15 #include <IMP/Constraint.h>
16 #include <IMP/algebra/VectorD.h>
17 
18 IMPCORE_BEGIN_NAMESPACE
19 
20 //! A decorator for a particle that represents a direction in 3D.
21 /** \ingroup decorators
22 */
23 class IMPCOREEXPORT Direction : public Decorator {
24  public:
25  static void do_setup_particle(Model *m, ParticleIndex pi,
26  const algebra::Vector3D &v);
27 
30 
31  //! Check if particle is setup as a direction.
32  static bool get_is_setup(Model *m, ParticleIndex pi);
33 
34  //! Get key for direction attribute.
35  static FloatKey get_direction_key(unsigned int i);
36 
37  //! Get the derivative added to the ith coordinate of the direction.
39  return get_particle()->get_derivative(get_direction_key(i));
40  }
41 
42  //! Get the vector of derivatives added to the direction.
43  algebra::Vector3D get_direction_derivatives() const;
44 
45  //! Add v to the derivative of the ith coordinate of the direction.
47  get_particle()->add_to_derivative(get_direction_key(i), v, d);
48  }
49 
50  //! Add v to the derivatives of the x,y,z coordinates of the direction.
51  void add_to_direction_derivatives(const algebra::Vector3D &v,
53 
54  //! Get whether direction is optimized.
55  bool get_direction_is_optimized() const;
56 
57  //! Set whether direction is optimized.
58  void set_direction_is_optimized(bool tf) const;
59 
60  //! Get direction.
61  algebra::Vector3D get_direction() const;
62 
63  //! Set direction.
64  void set_direction(const algebra::Vector3D &v);
65 
66  //! Flip direction so direction is reversed.
67  void reflect() { set_direction(-get_direction()); }
68 
69  private:
70  static ObjectKey get_constraint_key();
71 };
72 
73 IMP_DECORATORS(Direction, Directions, Decorators);
74 
75 //! Get angle between directions.
76 IMPCOREEXPORT double get_angle(Direction a, Direction b);
77 
78 //! A decorator for an angle between two directions.
79 /** \ingroup decorators
80  \see Direction
81  \note A Constraint is used to maintain the angle and propagate its
82  derivatives to its Directions.
83 */
84 class IMPCOREEXPORT DirectionAngle : public Decorator {
85  static void do_setup_particle(Model *m, ParticleIndex pi,
86  const ParticleIndexPair &ds);
87  static void do_setup_particle(Model *m, ParticleIndex pi,
90  void create_constraint();
91  static ObjectKey get_constraint_key();
92 
93  public:
98 
99  //! Check if particle is setup as an angle.
100  static bool get_is_setup(Model *m, ParticleIndex pi);
101 
102  //! Get key for angle attribute.
103  static FloatKey get_angle_key();
104 
105  //! Get key for ith direction particle.
106  static ParticleIndexKey get_particle_key(unsigned int i);
107 
108  //! Get ith direction particle.
109  Particle* get_particle(unsigned int i) const;
110 
111  Particle* get_particle() const {
112  return Decorator::get_particle();
113  }
114 
115  //! Get ith direction particle index.
116  ParticleIndex get_particle_index(unsigned int i) const;
117 
120  }
121 
122  //! Get angle.
123  Float get_angle() const;
124 
125  //! Get the derivative added to the angle.
126  Float get_angle_derivative() const;
127 
128  //! Add to the derivative of the angle.
129  void add_to_angle_derivative(Float v, DerivativeAccumulator &d);
130 
131 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
132  //! Recalculate and store the angle.
133  void update_angle();
134 #endif
135 
136 };
137 
138 IMP_DECORATORS(DirectionAngle, DirectionAngles, Decorators);
139 
140 
141 #if !defined(IMP_DOXYGEN) && !defined(SWIG)
142 //! Constrain a direction as unit.
143 class IMPCOREEXPORT DirectionUnitConstraint : public IMP::Constraint {
144  private:
145  ParticleIndex pi_;
146 
147  private:
148  DirectionUnitConstraint(Particle *p)
149  : IMP::Constraint(p->get_model(), "DirectionUnitConstraint%1%")
150  , pi_(p->get_index()) {}
151 
152  public:
153  friend class Direction;
154  virtual void do_update_attributes() IMP_OVERRIDE;
155  virtual void do_update_derivatives(DerivativeAccumulator *da) IMP_OVERRIDE;
156  virtual ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
157  virtual ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE;
158  IMP_OBJECT_METHODS(DirectionUnitConstraint);
159 };
160 
161 //! Constrain an angle between two directions.
162 class IMPCOREEXPORT DirectionAngleConstraint : public IMP::Constraint {
163  private:
164  ParticleIndex pi_;
165 
166  private:
167  DirectionAngleConstraint(Particle *p)
168  : IMP::Constraint(p->get_model(), "DirectionAngleConstraint%1%")
169  , pi_(p->get_index()) {}
170 
171  public:
172  friend class DirectionAngle;
173  virtual void do_update_attributes() IMP_OVERRIDE;
174  virtual void do_update_derivatives(DerivativeAccumulator *da) IMP_OVERRIDE;
175  virtual ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
176  virtual ModelObjectsTemp do_get_outputs() const IMP_OVERRIDE;
177  IMP_OBJECT_METHODS(DirectionAngleConstraint);
178 };
179 
180 #endif
181 
182 IMPCORE_END_NAMESPACE
183 
184 #endif /* IMPCORE_DIRECTION_H */
The base class for decorators.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Definition: Decorator.h:188
A decorator for an angle between two directions.
Definition: direction.h:84
void add_to_direction_derivative(int i, Float v, DerivativeAccumulator &d)
Add v to the derivative of the ith coordinate of the direction.
Definition: direction.h:46
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
double get_angle(Direction a, Direction b)
Get angle between directions.
Take Decorator, Particle or ParticleIndex.
A decorator for a particle that represents a direction in 3D.
Definition: direction.h:23
Constraint * create_constraint(Before *b, After *a, const typename Before::Argument &t, std::string name=std::string())
Definition: generic.h:63
Index< ParticleIndexTag > ParticleIndex
Definition: base_types.h:158
Implement a constraint on the Model.
Definition: Constraint.h:49
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Definition: base_types.h:86
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
Ints get_index(const ParticlesTemp &particles, const Subset &subset, const Subsets &excluded)
Helper macros for implementing Decorators.
Simple D vector class.
#define IMP_DECORATOR_SETUP_2(Name, FirstArgumentType, first_argument_name,SecondArgumentType, second_argument_name)
void reflect()
Flip direction so direction is reversed.
Definition: direction.h:67
A base class for constraints.
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
#define IMP_DECORATOR_METHODS(Name, Parent)
VectorD< 3 > Vector3D
Definition: VectorD.h:421
double Float
Basic floating-point value (could be float, double...)
Definition: types.h:20
Class to handle individual particles of a Model object.
Definition: Particle.h:41
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
Float get_direction_derivative(int i) const
Get the derivative added to the ith coordinate of the direction.
Definition: direction.h:38
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.