IMP logo
Public Member Functions | Static Public Member Functions
IMP::examplesystemlocal::ExampleSingletonModifier Class Reference

Detailed Description

An local singleton modifer.

A simple singleton modifier which restrains the x,y,z coordinates to a box by wrapping them.

Such a class could be coupled with an IMP::core::SingletonRestraint or IMP::core::SingletonsRestraint to keep a set of particles in a box.

import IMP.core
bb= IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0),
# apply the range restriction modifier to each each particle in sc
m.add_score_state(ss)
# now optimize and things
# ...

The source code is as follows:

/**
* \file local/ExampleRestraint.h
* \brief A restraint on a list of particle pairs.
*
* Copyright 2007-2012 IMP Inventors. All rights reserved.
*
*/
#ifndef IMP_EXAMPLE_SYSTEM_LOCAL_EXAMPLE_RESTRAINT_H
#define IMP_EXAMPLE_SYSTEM_LOCAL_EXAMPLE_RESTRAINT_H
#include "example_system_local_config.h"
#include <IMP/Restraint.h>
#include <IMP/PairScore.h>
IMPEXAMPLESYSTEMLOCAL_BEGIN_NAMESPACE
//! Constraint a particle to be in the x,y plane
/** \note Be sure to check out the swig wrapper file and how it
wraps this class.
The source code is as follows:
\include ExampleRestraint.h
\include ExampleRestraint.cpp
*/
class IMPEXAMPLESYSTEMLOCALEXPORT ExampleRestraint : public Restraint
{
Pointer<Particle> p_;
double k_;
public:
//! Create the restraint.
/** Restraints should store the particles they are to act on,
preferably in a Singleton or PairContainer as appropriate.
*/
ExampleRestraint(Particle *p, double k);
/** This macro declares the basic needed methods: evaluate and show
*/
IMP_RESTRAINT(ExampleRestraint);
};
IMPEXAMPLESYSTEMLOCAL_END_NAMESPACE
#endif /* IMP_EXAMPLE_SYSTEM_LOCAL_EXAMPLE_RESTRAINT_H */
/**
* \file example/ExampleRestraint.cpp
* \brief Restrain a list of particle pairs.
*
* Copyright 2007-2012 IMP Inventors. All rights reserved.
*
*/
#include <IMP/core/XYZ.h>
IMPEXAMPLE_BEGIN_NAMESPACE
double k) :
Restraint(p->get_model(), "ExampleRestraint%1%"), p_(p),
k_(k) {
}
/* Apply the pair score to each particle pair listed in the container.
*/
double
ExampleRestraint::unprotected_evaluate(DerivativeAccumulator *accum) const
{
core::XYZ d(p_);
IMP_LOG(VERBOSE, "The z coordinate of " << d->get_name()
<< " is " << d.get_z() << std::endl);
double score= .5*k_*square(d.get_z());
if (accum) {
double deriv= k_*d.get_z();
d.add_to_derivative(2, deriv, *accum);
}
return score;
}
/* Return all particles whose attributes are read by the restraints. To
do this, ask the pair score what particles it uses.*/
ParticlesTemp ExampleRestraint::get_input_particles() const
{
return ParticlesTemp(1,p_);
}
/* The only container used is pc_. */
ContainersTemp ExampleRestraint::get_input_containers() const
{
return ContainersTemp();
}
void ExampleRestraint::do_show(std::ostream& out) const
{
out << "particle= " << p_->get_name() << std::endl;
out << "k= " << k_ << std::endl;
}
IMPEXAMPLE_END_NAMESPACE
+ Inheritance diagram for IMP::examplesystemlocal::ExampleSingletonModifier:

List of all members.

Public Member Functions

 ExampleSingletonModifier (const algebra::BoundingBoxD< 3 > &bb)
- Public Member Functions inherited from IMP::SingletonModifier
 SingletonModifier (std::string name="SingletonModifier %1%")
virtual void apply (Particle *) const =0
virtual void apply_index (Model *m, ParticleIndex v) const
virtual void apply_indexes (Model *m, const ParticleIndexes &o) const
virtual ContainersTemp get_input_containers (Particle *p) const =0
virtual ParticlesTemp get_input_particles (Particle *p) const =0
virtual ContainersTemp get_output_containers (Particle *p) const =0
virtual ParticlesTemp get_output_particles (Particle *p) const =0
- Public Member Functions inherited from IMP::base::Object
std::size_t __hash__ () const
virtual std::string get_type_name () const =0
 Return a string identifying the type of the object.
virtual IMP::base::VersionInfo get_version_info () const =0
 Get information about the module and version of the object.
void set_check_level (CheckLevel l)
void set_log_level (LogLevel l)
 Set the logging level used in this object.
void set_was_used (bool tf) const
void show (std::ostream &out=std::cout) const
const std::string & get_name () const
void set_name (std::string name)

Static Public Member Functions

static ExampleSingletonModifierget_from (IMP::base::Object *o)

Additional Inherited Members

- Public Types inherited from IMP::SingletonModifier
typedef ParticleArgument
typedef ParticleIndex IndexArgument

The documentation for this class was generated from the following file:

Generated on Tue May 22 2012 23:33:35 for IMP by doxygen 1.8.1