IMP logo

IMP::example::ExampleRestraint Class Reference


Detailed Description

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:
/**
 *  \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::ExampleRestraint:

Inheritance graph
[legend]

Public Member Functions

 ExampleRestraint (PairScore *score_func, PairContainer *pc)
 Create the restraint.
ContainersTemp get_input_containers () const
ParticlesTemp get_input_particles () const
ParticlesList get_interacting_particles () const
virtual std::string get_type_name () const
virtual ::IMP::VersionInfo get_version_info () const
virtual double unprotected_evaluate (DerivativeAccumulator *accum) const

Friends

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

Constructor & Destructor Documentation

IMP::example::ExampleRestraint::ExampleRestraint ( PairScore score_func,
PairContainer pc 
)

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.


Member Function Documentation

virtual double IMP::example::ExampleRestraint::unprotected_evaluate ( DerivativeAccumulator accum  )  const [virtual]

This macro declares the basic needed methods: evaluate and show


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