IMP  2.0.0
The Integrative Modeling Platform
IMP::example::ExampleSubsetFilterTable Class Reference

#include <IMP/example/ExampleSubsetFilterTable.h>

+ Inheritance diagram for IMP::example::ExampleSubsetFilterTable:

Public Member Functions

 ExampleSubsetFilterTable (unsigned int max_diff, const ParticlesTemp &pt)
 
virtual void do_show (std::ostream &out) const
 
- Public Member Functions inherited from IMP::domino::SubsetFilterTable
 SubsetFilterTable (std::string name="SubsetFilterTable%1%")
 
virtual double get_strength (const Subset &s, const Subsets &prior_subsets) const =0
 The strength is a rough metric of how this filter restricts the subset. More...
 
virtual SubsetFilterget_subset_filter (const Subset &s, const Subsets &prior_subsets) const =0
 
- Public Member Functions inherited from IMP::base::Object
virtual void clear_caches ()
 
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. More...
 
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)
 

Additional Inherited Members

- Protected Member Functions inherited from IMP::base::Object
 Object (std::string name)
 Construct an object with the given name. More...
 

Detailed Description

Filter a set of particles based on the maximum difference in state indexes between them (a completely silly criteria). The thing to note is how the filter table determines when it should be applied and how it sets up the filters.

/**
* \file IMP/example/ExampleSubsetFilterTable.h
* \brief A Score on the distance between a pair of particles.
*
* Copyright 2007-2013 IMP Inventors. All rights reserved.
*/
#ifndef IMPEXAMPLE_EXAMPLE_SUBSET_FILTER_TABLE_H
#define IMPEXAMPLE_EXAMPLE_SUBSET_FILTER_TABLE_H
#include <IMP/example/example_config.h>
IMPEXAMPLE_BEGIN_NAMESPACE
/** Filter a set of particles based on the maximum difference
in state indexes between them (a completely silly criteria).
The thing to note is how the filter table determines when
it should be applied and how it sets up the filters.
\include ExampleSubsetFilterTable.h
\include ExampleSubsetFilterTable.cpp
*/
class IMPEXAMPLEEXPORT ExampleSubsetFilterTable:
public domino::SubsetFilterTable
{
int max_diff_;
const Particles ps_;
Ints get_indexes(const domino::Subset &s,
const domino::Subsets& prior_subsets) const;
public:
ExampleSubsetFilterTable(unsigned int max_diff, const ParticlesTemp &pt);
IMP_SUBSET_FILTER_TABLE(ExampleSubsetFilterTable);
};
IMPEXAMPLE_END_NAMESPACE
#endif /* IMPEXAMPLE_EXAMPLE_SUBSET_FILTER_TABLE_H */
/**
* \file ExampleSubsetFilterTable.cpp
* \brief A Score on the distance between a pair of particles.
*
* Copyright 2007-2013 IMP Inventors. All rights reserved.
*/
#include <iterator>
IMPEXAMPLE_BEGIN_NAMESPACE
namespace {
class ExampleSubsetFilter: public domino::SubsetFilter {
Ints indices_;
int max_;
public:
ExampleSubsetFilter(const Ints &indices, unsigned int max):
domino::SubsetFilter("ExampleSubsetFilter%1%"), indices_(indices),
max_(max){}
IMP_SUBSET_FILTER(ExampleSubsetFilter);
};
bool ExampleSubsetFilter::get_is_ok(const domino::Assignment &a) const {
for (unsigned int i=0; i< indices_.size(); ++i) {
if (indices_[i]==-1) continue; // for the non-all case
for (unsigned int j=0; j < i; ++j) {
if (indices_[j]==-1) continue; // for the non-all case
if (std::abs(a[indices_[i-1]]- a[indices_[i]]) > max_) return false;
}
}
return true;
}
void ExampleSubsetFilter::do_show(std::ostream &) const {
}
}
ExampleSubsetFilterTable::ExampleSubsetFilterTable(unsigned int max_diff,
const ParticlesTemp &ps):
domino::SubsetFilterTable("ExampleSubsetFilterTable%1%"),
max_diff_(max_diff), ps_(ps.begin(), ps.end()){}
::get_indexes(const domino::Subset &s,
const domino::Subsets& prior_subsets) const {
// this method is only called from setup code, so it doesn't
// have to be too fast
Ints ret(ps_.size(), -1);
for (unsigned int i=0; i< s.size(); ++i) {
for (unsigned int j=0; j< ps_.size(); ++j) {
if (s[i]== ps_[j]) {
ret[j]=i;
break;
}
}
}
for (unsigned int i=0; i< ret.size(); ++i) {
if (ret[i]==-1) return Ints();
}
// check if we have seen them already).
for (unsigned int i=0; i< prior_subsets.size(); ++i) {
unsigned int count=0;
for (unsigned j=0; j< prior_subsets[i].size(); ++j) {
for (unsigned int k=0; k< ps_.size(); ++k) {
if (prior_subsets[i][j]== ps_[k]) {
++count;
break;
}
}
}
if (count == ps_.size()) {
return Ints();
}
}
return ret;
}
double ExampleSubsetFilterTable::
get_strength(const domino::Subset& cur_subset,
const domino::Subsets& prior_subsets) const {
if (get_indexes(cur_subset, prior_subsets).size()!= ps_.size()) {
return 0;
} else {
// pick some number
return .5;
}
}
domino::SubsetFilter* ExampleSubsetFilterTable::
get_subset_filter(const domino::Subset& cur_subset,
const domino::Subsets& prior_subsets) const {
Ints its= get_indexes(cur_subset, prior_subsets);
if (its.size() != ps_.size()) {
// either the subset doesn't contain the needed particles or the prior does
return nullptr;
} else {
IMP_NEW(ExampleSubsetFilter, ret, (its, max_diff_));
// remember to release
return ret.release();
}
}
void ExampleSubsetFilterTable::do_show(std::ostream &) const {}
IMPEXAMPLE_END_NAMESPACE

Definition at line 24 of file ExampleSubsetFilterTable.h.


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