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"
23IMPCORE_BEGIN_NAMESPACE
25IMP_DECORATORS_DECL(RigidMember, RigidMembers);
26IMP_DECORATORS_DECL(RigidBodyMember, RigidBodyMembers);
80class IMPCOREEXPORT RigidBody :
public XYZ {
88 void add_member_internal(
Particle *p,
97 static void teardown_constraints(
Particle *p);
112 void setup_score_states();
128 RigidMembers get_rigid_members()
const;
132 return internal::rigid_body_data().quaternion_;
139 if (
get_model()->get_has_attribute(internal::rigid_body_data().members_,
141 return get_model()->get_attribute(internal::rigid_body_data().members_,
191 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(RigidBody);
196 return internal::get_has_required_attributes_for_body(m, pi);
215 get_model()->get_attribute(internal::rigid_body_data().quaternion_,
218 "Rotation is not a unit vector: " << v);
224 bool assume_normalized =
true;
245 tr.get_transformation_to().get_rotation().get_quaternion();
246 get_model()->set_attribute(internal::rigid_body_data().quaternion_,
255 inline void set_rotation_lazy_using_internal_tables
260 rot.get_quaternion();
261 int pi=get_particle_index().get_index();
262 quaternion_table[pi] = v;
267 inline void apply_rotation_lazy_using_internal_tables
271 int pi=get_particle_index().get_index();
273 ( quaternion_table[pi][0],
274 quaternion_table[pi][1],
275 quaternion_table[pi][2],
276 quaternion_table[pi][3] );
278 (cur_rot*rot).get_quaternion();;
279 quaternion_table[pi] = v;
343 algebra::Transformation3DAdjoint &DT,
375 algebra::Transformation3DAdjoint &DTC,
376 algebra::Transformation3DAdjoint &DTA,
377 algebra::Transformation3DAdjoint &DTB,
410#if !defined(SWIG) && !defined(IMP_DOXYGEN)
415 return m->access_derivative_data(k);
422 return m->access_derivative_data(k);
426 static algebra::Vector4D
const* access_quaternion_data(
IMP::Model const* m)
428 Vector4DDerivKey k = internal::rigid_body_data().quaternion_;
429 return m->::IMP::internal::Vector4DDerivAttributeTable::access_attribute_data(k);
433 static algebra::Vector4D *access_quaternion_data(IMP::Model *m)
436 return m->::IMP::internal::Vector4DDerivAttributeTable::access_attribute_data(k);
461 unsigned int get_number_of_members()
const {
518 get_model()->add_to_derivative(internal::rigid_body_data().quaternion_,
519 get_particle_index(), qderiv, da);
526 get_model()->add_to_derivative(internal::rigid_body_data().torque_,
527 get_particle_index(), torque_local, da);
540class IMPCOREEXPORT RigidBodyMember :
public XYZ {
568 "Can only set the internal transformation if member is"
569 <<
" a rigid body itself.");
572 get_model()->set_attribute(internal::rigid_body_data().lquaternion_,
574 v.get_rotation().get_quaternion());
587 "Can only get the internal transformation if member is a "
588 <<
"rigid body itself.");
592 get_model()->get_attribute(internal::rigid_body_data().lquaternion_,
608 set_coordinates(tr.get_transformed(get_internal_coordinates()));
611 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(RigidBodyMember);
615 return internal::get_has_required_attributes_for_member(m, p);
618 static FloatKeys get_internal_coordinate_keys() {
619 return internal::rigid_body_data().child_keys_;
623 return internal::rigid_body_data().lquaternion_;
638class IMPCOREEXPORT RigidMember :
public RigidBodyMember {
642 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(RigidMember);
647 return internal::get_has_required_attributes_for_rigid_member(m, p);
659class IMPCOREEXPORT NonRigidMember :
public RigidBodyMember {
662 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(NonRigidMember);
667 return internal::get_has_required_attributes_for_non_member(m, p);
677 for (
unsigned int i = 0; i < 3; ++i) {
678 get_model()->add_to_derivative(get_internal_coordinate_keys()[i],
694 "Can only set derivatives of internal rotation if member is a "
695 <<
"rigid body itself.");
696 get_model()->add_to_derivative(get_internal_rotation_key(),
704 for (
unsigned int i = 0; i < 3; ++i) {
720class IMPCOREEXPORT RigidMembersRefiner :
public Refiner {
722 RigidMembersRefiner(std::string name =
"RigidMembersRefiner%d")
724 virtual bool get_can_refine(Particle *)
const override;
726 using Refiner::get_refined;
728 virtual const ParticlesTemp get_refined(Particle *)
const
730 virtual ModelObjectsTemp do_get_inputs(
731 Model *m,
const ParticleIndexes &pis)
const override;
736IMPCOREEXPORT RigidMembersRefiner *get_rigid_members_refiner();
749 a.set_reference_frame(get_transformed(a.get_reference_frame(), tr));
758 const ParticlesTemp &ps) {
762 return get_initial_reference_frame(ps[0]->get_model(),
Refine a particle into a list of particles.
Simple 3D rotation class.
Decorator for a sphere-like particle.
#define IMP_USAGE_CHECK_FLOAT_EQUAL(expra, exprb, message)
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
ParticleIndex get_particle_index() const
Returns the particle index decorated by this decorator.
Model * get_model() const
Returns the Model containing the particle.
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Take Decorator, Particle or ParticleIndex.
Take Decorator, Particle or ParticleIndex.
Class to handle individual particles of a Model object.
Abstract class to implement hierarchical methods.
A Cartesian vector in D-dimensions.
void add_to_internal_derivatives(const algebra::Vector3D &deriv_parent, DerivativeAccumulator &da)
Add to derivatives of local coordinates.
void add_to_internal_rotational_derivatives(const algebra::Vector4D &qderiv, DerivativeAccumulator &da)
algebra::Vector3D get_internal_derivatives() const
Get derivatives wrt translation component of internal transformation.
static bool get_is_setup(Model *m, ParticleIndex p)
return true if it is a rigid member
algebra::Vector4D get_internal_rotational_derivatives() const
Get derivatives wrt quaternion component of internal transformation.
A member of a rigid body, it has internal (local) coordinates.
void set_internal_coordinates(const algebra::Vector3D &v) const
set the internal (local) coordinates for this member
void set_internal_transformation(const algebra::Transformation3D &v)
void set_coordinates(const algebra::Vector3D ¢er)
sets the global coordinates of this member using XYZ::set_coordinates()
algebra::Transformation3D get_internal_transformation() const
const algebra::Vector3D & get_internal_coordinates() const
Return the internal (local) coordinates of this member.
static bool get_is_setup(Model *m, ParticleIndexAdaptor p)
return true if it is a rigid member
A decorator for a rigid body.
void set_reference_frame_lazy(const IMP::algebra::ReferenceFrame3D &tr)
Change the reference, delay updating the members until evaluate.
void set_is_rigid_member(ParticleIndex pi, bool tf)
IMP::algebra::ReferenceFrame3D get_reference_frame() const
static bool get_is_setup(Model *m, ParticleIndex pi)
Return true if the particle is a rigid body.
static void teardown_particle(RigidBody rb)
Make the rigid body no longer rigid.
void add_to_rotational_derivatives(const algebra::Vector4D &qderiv, DerivativeAccumulator &da)
void set_coordinates_are_optimized(bool tf)
void pull_back_member_adjoints(ParticleIndex pi, DerivativeAccumulator &da)
Pull back global adjoints from member that is a point.
algebra::VectorD< 4 > get_rotational_derivatives() const
Get the derivatives of the quaternion.
void pull_back_member_adjoints(ParticleIndex pi, const algebra::Transformation3D &T, algebra::Vector3D &x, algebra::Vector3D &Dy, algebra::Vector3D &Dx, algebra::Transformation3DAdjoint &DT, algebra::Vector3D &xtorque, DerivativeAccumulator &da)
bool get_coordinates_are_optimized() const
static Vector4DDerivKey get_rotation_key()
Get key for rotation quaternion.
const ParticleIndexes & get_member_particle_indexes() const
void remove_member(ParticleIndexAdaptor p)
Remove the member from this rigid body.
const ParticleIndexes & get_body_member_particle_indexes() const
void pull_back_members_adjoints(DerivativeAccumulator &da)
Pull back global adjoints from members.
void set_reference_frame(const IMP::algebra::ReferenceFrame3D &tr)
Set the current reference frame.
void add_to_torque(const algebra::Vector3D &torque_local, DerivativeAccumulator &da)
void add_member(ParticleIndexAdaptor p)
algebra::Vector3D get_torque() const
void normalize_rotation()
Normalize the quaternion.
algebra::Vector3D get_coordinates() const
ParticleIndexes get_member_indexes() const
IMP::algebra::Rotation3D get_rotation() const
void set_reference_frame_from_members(const ParticleIndexes &members)
void pull_back_body_member_adjoints(ParticleIndex pi, DerivativeAccumulator &da)
Pull back global adjoints from member that is also a rigid body.
void add_non_rigid_member(ParticleIndexAdaptor p)
void pull_back_body_member_adjoints(ParticleIndex pi, const algebra::Transformation3D &TA, algebra::Transformation3D &TB, algebra::Transformation3DAdjoint &DTC, algebra::Transformation3DAdjoint &DTA, algebra::Transformation3DAdjoint &DTB, algebra::Vector3D &betatorque, DerivativeAccumulator &da)
static bool get_is_setup(Model *m, ParticleIndexAdaptor p)
return true if it is a rigid member
A decorator for a particle with x,y,z coordinates.
const algebra::Vector3D & get_coordinates() const
Convert it to a vector.
void set_coordinates(const algebra::Vector3D &v)
set all coordinates from a vector
#define IMP_DECORATOR_SETUP_1(Name, FirstArgumentType, first_argument_name)
#define IMP_DECORATORS(Name, PluralName, Parent)
Define the types for storing sets of decorators.
#define IMP_DECORATOR_METHODS(Name, Parent)
void add_rigid_body_cache_key(ObjectKey k)
algebra::ReferenceFrame3D get_initial_reference_frame(Model *m, const ParticleIndexes &pis)
void transform(RigidBody a, const algebra::Transformation3D &tr)
Transform a rigid body.
ParticlesTemp create_rigid_bodies(Model *m, unsigned int n, bool no_members=false)
void show_rigid_body_hierarchy(RigidBody rb, TextOutput out=TextOutput(std::cout))
ParticleIndex get_root_rigid_body(RigidMember m)
Return the index of the outer-most rigid body containing the member.
Index< ParticleIndexTag > ParticleIndex
Key< 17 > Vector3DDerivKey
The type used to identify 3D vector attributes&derivatives in the Particles.
Vector< ParticleIndex, std::allocator< ParticleIndex > > ParticleIndexes
A list of particles, each identified by its ParticleIndex.
Key< 19 > Vector4DDerivKey
The type used to identify 4D vector attributes&derivatives in the Particles.
Key< 4 > ObjectKey
The type used to identify an Object attribute.
ParticleIndexes get_indexes(const ParticlesTemp &ps)
Get the indexes from a list of particles.
IMP::Vector< FloatKey > FloatKeys
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Represent an XYZR particle with a sphere.