IMP
is via a collection of Particle objects. However, since particles are general purpose, they provide a basic set of tools for managing the data (e.g. IMP::Particle::add_attribute(), IMP::Particle::get_value() etc). Decorators wrap (or “decorate”) particles to provide a much richer interface. For example, most particles have Cartesian coordinates. The class IMP::core::XYZ decorates such a particle to provide functions to get and set the Cartesian coordinates as well as compute distances between particles. d0= IMP.core.XYZ(p0) d1= IMP.core.XYZ(p1) print IMP.core.distance(d0,d1) print d0.get_coordinates()
To set up a particle to be used with the IMP::core::XYZ decorator we do
d0= IMP.core.XYZ.setup_particle(p, IMP.algebra.Vector3D(0,2,3))
(0,2,3) by doing print d0.get_coordinates()
d1= IMP.core.XYZ(p)
If you do not know if p
has been set up for the XYZ decorator, you can ask with
if IMP.core.XYZ.particle_is_instance(p):
More abstractly, decorators can be used to
To see a list of all available decorators and to see what functions all decorators have, look at the list of classes which inherit from IMP::Decorator, below.
See the IMP::example::ExampleDecorator example for how to implement a simple decorator.
if
statements.Methods provided by the Decorator class | |
The following methods are provided by the Decorator class. | |
Model * | get_model () const |
Returns the Model containing the particle. | |
Particle * | get_particle () const |
Methods that all decorators must have | |
All decorators must have the following methods. Decorators which are parameterized (for example IMP::core::XYZR) take an (optional) extra parameter after the Particle in setup_particle(), and particle_is_instance().
| |
Decorator () | |
Decorator (Particle *p) | |
static bool | particle_is_instance (Particle *p) |
Return true if the particle can be cast to the decorator. | |
static Decorator | setup_particle (Particle *p, extra_arguments) |
Protected Member Functions | |
Decorator (Particle *p) |
IMP::Decorator::Decorator | ( | Particle * | p | ) |
Create an instance of the Decorator from the particle that has already been set up. The particle must have been set up already (eg particle_is_instance(p) must be true), but this is not necessarily checked.
IMP::Decorator::Decorator | ( | ) |
The default constructor must be defined and create a NULL decorator, analogous to a NULL
pointer in C++ or a None
object in Python.
Particle* IMP::Decorator::get_particle | ( | ) | const |
Returns the particle decorated by this decorator.
static bool IMP::Decorator::particle_is_instance | ( | Particle * | p | ) | [static] |
Return true if the particle can be cast to the decorator.
That is, if particle_is_instance() returns true
, then it is legal to construct an instance of the decorator with that particle. If not, setup_particle() must be called first.
IMP::Particle *p = new IMP::Particle(m); // it is false std::cout << IMP::core::XYZ::particle_is_instance(p) << std::endl; // As a result this is an error IMP::core::XYZ d(p); // now set it up IMP::core::XYZ(p); // now it is true std::cout << IMP::core::XYZ::particle_is_instance(p) << std::endl; // and now this code is OK IMP::core::XYZ d(p);
Reimplemented in IMP::atom::Atom, IMP::atom::CHARMMAtom, IMP::atom::Charged, IMP::atom::Diffusion, IMP::atom::Hierarchy, IMP::atom::LennardJones, IMP::atom::SimulationParameters, IMP::atom::Angle, IMP::atom::Dihedral, IMP::atom::Bond, IMP::atom::Bonded, IMP::core::RigidBody, IMP::core::RigidMember, and IMP::example::ExampleDecorator.
Add the needed attributes to the particle and initialize them with values taken from initial_values.
It is an error to call this twice on the same particle for the same type of decorator.