IMP logo

IMP::example::ExampleSingletonModifier Class Reference


Detailed Description

An example 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.example
import IMP.core
import IMP.container

bb= IMP.algebra.BoundingBox3D(IMP.algebra.Vector3D(0,0,0),
                              IMP.algebra.Vector3D(10,10,10))

m= IMP.Model()
ps= IMP.core.create_xyzr_particles(m, 20, 1)
sc= IMP.container.ListSingletonContainer(ps)
ss= IMP.container.SingletonsConstraint(sc, IMP.example.ExampleSingletonModifier(bb), None)
m.add_score_state(ss)

# now optimize and things

The source code is as follows:

/**
 *  \file example/ExampleRestraint.h
 *  \brief A restraint on a list of particle pairs.
 *
 *  Copyright 2007-2010 IMP Inventors. All rights reserved.
 *
 */

#ifndef IMPEXAMPLE_EXAMPLE_RESTRAINT_H
#define IMPEXAMPLE_EXAMPLE_RESTRAINT_H

#include "example_config.h"
#include <IMP/SingletonScore.h>
#include <IMP/Restraint.h>
#include <IMP/PairContainer.h>
#include <IMP/PairScore.h>

IMPEXAMPLE_BEGIN_NAMESPACE

//! Apply a PairScore to a list of particle pairs
/** This restraint could be used, in conjunction with a
    ClosePairsScoreState and a SphereDistancePairScore,
    to prevent particles from interpenetrating.

    \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 IMPEXAMPLEEXPORT ExampleRestraint : public Restraint
{
  /** IMP::Objects should be stored using Pointer objects
      to make sure that they are reference counted properly.
  */
  Pointer<PairContainer> pc_;
  Pointer<PairScore> f_;
public:
  //! Create the restraint.
  /** Restraints should store the particles they are to act on,
      preferably in a Singleton or PairContainer as appropriate.
      They should also take a score function or a UnaryFunction
      allowing the form of the scoring function to be changed.
   */
  ExampleRestraint(PairScore* score_func,
                   PairContainer *pc);

  /** This macro declares the basic needed methods: evaluate and show
   */
  IMP_RESTRAINT(ExampleRestraint);
};

IMPEXAMPLE_END_NAMESPACE

#endif  /* IMPEXAMPLE_EXAMPLE_RESTRAINT_H */
/**
 *  \file example/ExampleRestraint.cpp
 *  \brief Restrain a list of particle pairs.
 *
 *  Copyright 2007-2010 IMP Inventors. All rights reserved.
 *
 */

#include <IMP/example/ExampleRestraint.h>
#include <IMP/PairScore.h>
#include <IMP/log.h>

IMPEXAMPLE_BEGIN_NAMESPACE

ExampleRestraint::ExampleRestraint(PairScore* score_func,
                                   PairContainer *pc) : pc_(pc),
                                          f_(score_func) {
  pc_->set_was_used(true);
  f_->set_was_used(true);
}

double
ExampleRestraint::unprotected_evaluate(DerivativeAccumulator *accum) const
{
  double score=0;
  for (PairContainer::ParticlePairIterator
       it= pc_->particle_pairs_begin();
       it != pc_->particle_pairs_end(); ++it) {
    score += f_->evaluate(*it, accum);
  }

  return score;
}

/* Return a list of interacting sets. The PairScore defines
   the interactions so defer to it.*/
ParticlesList ExampleRestraint::get_interacting_particles() const
{
  ParticlesList ret;
  for (PairContainer::ParticlePairIterator it
       = pc_->particle_pairs_begin();
       it != pc_->particle_pairs_end(); ++it) {
    ParticlePair pp= *it;
    ParticlesList all=f_->get_interacting_particles(ParticlePair(pp[0],
                                                                 pp[1]));
    ret.insert(ret.end(), all.begin(), all.end());
  }
  return ret;
}

/* We also need to know which particles are used (as some are
   used, but don't create interactions). */
ParticlesTemp ExampleRestraint::get_input_particles() const
{
  ParticlesTemp ret;
  for (PairContainer::ParticlePairIterator it
       = pc_->particle_pairs_begin();
       it != pc_->particle_pairs_end(); ++it) {
    ParticlePair pp= *it;
    ParticlesTemp t= f_->get_input_particles(pp);
    ret.insert(ret.end(), t.begin(), t.end());
  }
  return ret;
}

ContainersTemp ExampleRestraint::get_input_containers() const
{
  return ContainersTemp(1, pc_);
}

void ExampleRestraint::do_show(std::ostream& out) const
{
  out << "function " << *f_ << std::endl;
  out << "container " << *pc_ << std::endl;
}

IMPEXAMPLE_END_NAMESPACE
Inheritance diagram for IMP::example::ExampleSingletonModifier:

Inheritance graph
[legend]

Public Member Functions

void apply (const ParticlesTemp &ps, DerivativeAccumulator &) const
void apply (const ParticlesTemp &ps) const
void apply (Particle *a, DerivativeAccumulator &) const
void apply (Particle *a) const
 ExampleSingletonModifier (const algebra::BoundingBoxD< 3 > &bb)
ContainersTemp get_input_containers (Particle *) const
ParticlesTemp get_input_particles (Particle *) const
ParticlesList get_interacting_particles (Particle *) const
ContainersTemp get_output_containers (Particle *) const
ParticlesTemp get_output_particles (Particle *) const
virtual std::string get_type_name () const
virtual ::IMP::VersionInfo get_version_info () const

Friends

template<class T >
void IMP::internal::unref (T *)

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

Generated on Mon Mar 8 23:09:01 2010 for IMP by doxygen 1.5.8