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);
83 void add_member_internal(
Particle *p,
88 static void teardown_constraints(
Particle *p);
103 void setup_score_states();
119 if (
get_model()->get_has_attribute(internal::rigid_body_data().members_,
144 return get_member_particle_indexes() + get_body_member_particle_indexes();
167 static void teardown_particle(
RigidBody rb);
169 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(
RigidBody);
174 return internal::get_has_required_attributes_for_body(m, pi);
184 get_model()->get_attribute(internal::rigid_body_data().quaternion_[0],
186 get_model()->get_attribute(internal::rigid_body_data().quaternion_[1],
188 get_model()->get_attribute(internal::rigid_body_data().quaternion_[2],
190 get_model()->get_attribute(internal::rigid_body_data().quaternion_[3],
193 "Rotation is not a unit vector: " << v);
199 bool assume_normalized =
true;
253 for (
unsigned int i = 0; i < 3; ++i) {
269 void normalize_rotation();
273 void update_members();
279 unsigned int get_number_of_members()
const {
280 return get_body_member_particle_indexes().size() +
281 get_member_particle_indexes().size();
284 RigidMember get_member(
unsigned int i)
const;
318 const algebra::Rotation3D &rot,
319 DerivativeAccumulator &da) {
322 algebra::VectorD<4> q(0, 0, 0, 0);
323 for (
unsigned int j = 0; j < 4; ++j) {
325 q[j] = deriv_global * v;
327 XYZ::add_to_derivatives(deriv_global, da);
328 for (
unsigned int j = 0; j < 4; ++j) {
329 get_model()->add_to_derivative(internal::rigid_body_data().quaternion_[j],
330 get_particle_index(), q[j], da);
333 for (
unsigned int i = 0; i < 3; ++i) {
334 get_model()->add_to_derivative(internal::rigid_body_data().torque_[i],
335 get_particle_index(), torque[i], da);
342 DerivativeAccumulator &da) {
343 algebra::Rotation3D rot =
344 get_reference_frame().get_transformation_to().get_rotation();
346 add_to_derivatives(deriv_local, deriv_global, local, rot, da);
386 "Can only set the internal transformation if member is"
387 <<
" a rigid body itself.");
414 "Can only set the internal transformation if member is a "
415 <<
"rigid body itself.");
419 get_model()->get_attribute(internal::rigid_body_data().lquaternion_[0],
421 get_model()->get_attribute(internal::rigid_body_data().lquaternion_[1],
423 get_model()->get_attribute(internal::rigid_body_data().lquaternion_[2],
425 get_model()->get_attribute(internal::rigid_body_data().lquaternion_[3],
444 IMP_CXX11_DEFAULT_COPY_CONSTRUCTOR(RigidBodyMember);
448 return internal::get_has_required_attributes_for_member(m, p);
451 static FloatKeys get_internal_coordinate_keys() {
452 return internal::rigid_body_data().child_keys_;
476 return internal::get_has_required_attributes_for_rigid_member(m, p);
496 return internal::get_has_required_attributes_for_non_member(m, p);
502 class IMPCOREEXPORT RigidMembersRefiner :
public Refiner {
504 RigidMembersRefiner(std::string name =
"RigidMembersRefiner%d")
510 virtual const ParticlesTemp
get_refined(Particle *) const
513 Model *m, const ParticleIndexes &pis) const
IMP_OVERRIDE;
518 IMPCOREEXPORT RigidMembersRefiner *get_rigid_members_refiner();
544 return get_initial_reference_frame(ps[0]->get_model(),
561 IMP_DECORATORS_DEF(RigidMember, RigidMembers);
567 TextOutput(std::cout));
573 IMPCORE_END_NAMESPACE
Key< 4, true > ObjectKey
The type used to identify an Object attribute.
void add_to_derivatives(const algebra::Vector3D &v, DerivativeAccumulator &d)
Add something to the derivative of the 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.
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
Get the coordinates of the particle.
#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)
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)
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)
Returns 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
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)
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)
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 model particles.
#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.
Simple 3D rotation class.
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)
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.
Class for adding derivatives from restraints to the model.
const algebra::Vector3D & get_internal_coordinates() const
Return the internal (local) coordinates of this member.
IMP::algebra::ReferenceFrame3D get_reference_frame() const
Get the reference frame for the local coordinates.