8 #ifndef IMPCORE_RIGID_BODIES_H
9 #define IMPCORE_RIGID_BODIES_H
11 #include <IMP/core/core_config.h>
12 #include "internal/rigid_bodies.h"
24 IMPCORE_BEGIN_NAMESPACE
26 IMP_DECORATORS_DECL(RigidMember, RigidMembers);
88 void add_member_internal(
Particle *p,
97 static void teardown_constraints(
Particle *p);
112 void setup_score_states();
128 if (
get_model()->get_has_attribute(internal::rigid_body_data().members_,
153 return get_member_particle_indexes() + get_body_member_particle_indexes();
176 static void teardown_particle(
RigidBody rb);
178 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(
RigidBody);
183 return internal::get_has_required_attributes_for_body(m, pi);
194 return get_reference_frame().get_transformation_to().get_rotation();
202 get_model()->get_attribute(internal::rigid_body_data().quaternion_[0],
204 get_model()->get_attribute(internal::rigid_body_data().quaternion_[1],
206 get_model()->get_attribute(internal::rigid_body_data().quaternion_[2],
208 get_model()->get_attribute(internal::rigid_body_data().quaternion_[3],
211 "Rotation is not a unit vector: " << v);
217 bool assume_normalized =
true;
234 inline void set_reference_frame_lazy
239 get_particle()->set_value(internal::rigid_body_data().quaternion_[0], v[0]);
240 get_particle()->set_value(internal::rigid_body_data().quaternion_[1], v[1]);
241 get_particle()->set_value(internal::rigid_body_data().quaternion_[2], v[2]);
242 get_particle()->set_value(internal::rigid_body_data().quaternion_[3], v[3]);
250 inline void set_rotation_lazy_using_internal_tables
252 double* quaternion_tables[])
257 quaternion_tables[0][pi]=v[0];
258 quaternion_tables[1][pi]=v[1];
259 quaternion_tables[2][pi]=v[2];
260 quaternion_tables[3][pi]=v[3];
265 inline void apply_rotation_lazy_using_internal_tables
267 double* quaternion_tables[])
271 ( quaternion_tables[0][pi],
272 quaternion_tables[1][pi],
273 quaternion_tables[2][pi],
274 quaternion_tables[3][pi] );
276 (cur_rot*rot).get_quaternion();;
277 quaternion_tables[0][pi]=v[0];
278 quaternion_tables[1][pi]=v[1];
279 quaternion_tables[2][pi]=v[2];
280 quaternion_tables[3][pi]=v[3];
283 #endif // IMP_DOXYGEN
301 void set_reference_frame_from_members(
const ParticleIndexes &members);
318 DerivativeAccumulator &da);
334 const algebra::Rotation3D &rot_local_to_global,
335 DerivativeAccumulator &da);
346 DerivativeAccumulator &da);
352 for (
unsigned int i = 0; i < 3; ++i) {
359 #if !defined(SWIG) && !defined(IMP_DOXYGEN)
362 static double const* access_torque_i_data
367 internal::rigid_body_data().torque_[i];
368 double const* ret=m->access_derivative_data(k);
374 static double* access_torque_i_data
379 internal::rigid_body_data().torque_[i];
380 double* ret=m->access_derivative_data(k);
385 static double const* access_quaternion_i_data
390 internal::rigid_body_data().quaternion_[i];
391 double const* ret=m->FloatAttributeTable::access_attribute_data(k);
396 static double* access_quaternion_i_data
401 internal::rigid_body_data().quaternion_[i];
402 double* ret=m->FloatAttributeTable::access_attribute_data(k);
418 void normalize_rotation();
422 void update_members();
425 algebra::VectorD<4> get_rotational_derivatives()
const;
428 unsigned int get_number_of_members()
const {
429 return get_body_member_particle_indexes().size() +
430 get_member_particle_indexes().size();
433 RigidMember get_member(
unsigned int i)
const;
448 void add_member(ParticleIndexAdaptor p);
455 void add_non_rigid_member(ParticleIndexAdaptor p);
469 DerivativeAccumulator &da) {
470 for (
unsigned int i = 0; i < 3; ++i) {
471 get_model()->add_to_derivative(internal::rigid_body_data().torque_[i],
472 get_particle_index(), torque_local[i], da);
481 const algebra::Rotation3D &rot_local_to_global,
482 DerivativeAccumulator &da) {
484 XYZ::add_to_derivatives(deriv_global, da);
485 algebra::VectorD<4> q(0, 0, 0, 0);
486 for (
unsigned int j = 0; j < 4; ++j) {
488 q[j] = deriv_global * v;
490 for (
unsigned int j = 0; j < 4; ++j) {
491 get_model()->add_to_derivative(internal::rigid_body_data().quaternion_[j],
492 get_particle_index(), q[j], da);
495 for (
unsigned int i = 0; i < 3; ++i) {
496 get_model()->add_to_derivative(internal::rigid_body_data().torque_[i],
497 get_particle_index(), torque[i], da);
504 DerivativeAccumulator &da) {
505 algebra::Rotation3D rot_local_to_global =
506 get_reference_frame().get_transformation_to().get_rotation();
508 add_to_derivatives(deriv_local, deriv_global, local,
509 rot_local_to_global, da);
549 "Can only set the internal transformation if member is"
550 <<
" a rigid body itself.");
577 "Can only set the internal transformation if member is a "
578 <<
"rigid body itself.");
582 get_model()->get_attribute(internal::rigid_body_data().lquaternion_[0],
584 get_model()->get_attribute(internal::rigid_body_data().lquaternion_[1],
586 get_model()->get_attribute(internal::rigid_body_data().lquaternion_[2],
588 get_model()->get_attribute(internal::rigid_body_data().lquaternion_[3],
607 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(RigidBodyMember);
611 return internal::get_has_required_attributes_for_member(m, p);
614 static FloatKeys get_internal_coordinate_keys() {
615 return internal::rigid_body_data().child_keys_;
639 return internal::get_has_required_attributes_for_rigid_member(m, p);
659 return internal::get_has_required_attributes_for_non_member(m, p);
665 class IMPCOREEXPORT RigidMembersRefiner :
public Refiner {
667 RigidMembersRefiner(std::string name =
"RigidMembersRefiner%d")
673 virtual const ParticlesTemp
get_refined(Particle *) const
676 Model *m, const ParticleIndexes &pis) const
IMP_OVERRIDE;
681 IMPCOREEXPORT RigidMembersRefiner *get_rigid_members_refiner();
707 return get_initial_reference_frame(ps[0]->get_model(),
724 IMP_DECORATORS_DEF(RigidMember, RigidMembers);
730 TextOutput(std::cout));
736 IMPCORE_END_NAMESPACE
void add_to_derivatives(const algebra::Vector3D &v, DerivativeAccumulator &d)
Add the vector v to the derivative vector of the x,y,z coordinates.
void set_internal_coordinates(const algebra::Vector3D &v) const
set the internal (local) coordinates for this member
A Modifier on ParticlesTemp.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Key< 0 > FloatKey
The type used to identify float attributes in the Particles.
A member of a rigid body, it has internal (local) coordinates.
A container for Singletons.
ParticleIndex get_root_rigid_body(RigidMember m)
Return the index of the outer-most rigid body containing the member.
#define IMP_USAGE_CHECK_FLOAT_EQUAL(expra, exprb, message)
algebra::Vector3D get_coordinates() const
IMP::algebra::Rotation3D get_rotation() const
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Model * get_model() const
Returns the Model containing the particle.
ParticlesTemp create_rigid_bodies(Model *m, unsigned int n, bool no_members=false)
Index< ParticleIndexTag > ParticleIndex
bool get_coordinates_are_optimized() const
Get whether the coordinates are optimized.
void add_rigid_body_cache_key(ObjectKey k)
A more IMP-like version of the std::vector.
const Vector4D & get_quaternion() const
Return the quaternion so that it can be stored.
void show_rigid_body_hierarchy(RigidBody rb, TextOutput out=TextOutput(std::cout))
void clear_particle_caches(ParticleIndex pi)
Clear all the cache attributes of a given particle.
IMP::Vector< IMP::WeakPointer< ModelObject > > ModelObjectsTemp
Class for storing model, its restraints, constraints, and particles.
algebra::Vector3D get_torque() const
static bool get_is_setup(Model *m, ParticleIndexAdaptor p)
return true if it is a rigid member
virtual bool get_can_refine(Particle *) const
Return true if this refiner can refine that particle.
Vector3D get_vector_product(const Vector3D &p1, const Vector3D &p2)
Return the vector product (cross product) of two vectors.
void set_reference_frame(const IMP::algebra::ReferenceFrame3D &tr)
Set the current reference frame.
A Cartesian vector in D-dimensions.
Refine a particle into a list of particles.
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
const Transformation3D & get_transformation_to() const
static bool get_is_setup(Model *m, ParticleIndex pi)
Return true if the particle is a rigid body.
const ParticleIndexes & get_member_particle_indexes() const
static bool get_is_setup(Model *m, ParticleIndexAdaptor p)
return true if it is a rigid member
Represent an XYZR particle with a sphere.
void set_attribute(TypeKey attribute_key, ParticleIndex particle, Type value)
set the value of particle attribute with the specified key
A decorator for a particle with x,y,z coordinates.
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
virtual const ParticlesTemp get_refined(Particle *a) const =0
Refine the passed particle into a set of particles.
A decorator for a particle that is part of a rigid body but not rigid.
Simple 3D rotation class.
void set_internal_transformation(const algebra::Transformation3D &v)
Particle * get_particle() const
Returns the particle decorated by this decorator.
Key< 4 > ObjectKey
The type used to identify an Object attribute.
void set_coordinates_are_optimized(bool tf) const
Set whether the coordinates are optimized.
void set_coordinates(const algebra::Vector3D ¢er)
sets the global coordinates of this member using XYZ::set_coordinates()
#define IMP_DECORATOR_METHODS(Name, Parent)
Abstract class to implement hierarchical methods.
Class to handle individual particles of a Model object.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
void transform(RigidBody a, const algebra::Transformation3D &tr)
Transform a rigid body.
ParticleIndexes get_member_indexes() const
const ParticleIndexes & get_body_member_particle_indexes() const
A decorator for a rigid body.
algebra::Transformation3D get_internal_transformation() const
Type get_attribute(TypeKey attribute_key, ParticleIndex particle)
get the value of the particle attribute with the specified key
Decorator for a sphere-like particle.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
static bool get_is_setup(Model *m, ParticleIndex p)
return true if it is a rigid member
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
const algebra::Vector3D & get_internal_coordinates() const
Return the internal (local) coordinates of this member.
IMP::algebra::ReferenceFrame3D get_reference_frame() const