IMP  2.1.1
The Integrative Modeling Platform
PredicateTripletsRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/container/PredicateTripletsRestraint.h
3  * \brief Apply a TripletScore to each Triplet in a list.
4  *
5  * WARNING This file was generated from PredicateTripletsRestraint.h
6  * in /tmp/nightly-build-61576/imp-2.1.1/tools/build/container_templates/container
7  * by tools/maintenance/setup_containers.py.
8  *
9  * Copyright 2007-2013 IMP Inventors. All rights reserved.
10  *
11  */
12 
13 #ifndef IMPCONTAINER_PREDICATE_TRIPLETS_RESTRAINT_H
14 #define IMPCONTAINER_PREDICATE_TRIPLETS_RESTRAINT_H
15 
16 #include <IMP/container/container_config.h>
17 
18 #include <IMP/kernel/internal/InternalDynamicListTripletContainer.h>
19 #include <IMP/base/map.h>
20 #include <IMP/TripletPredicate.h>
21 #include <IMP/restraint_macros.h>
22 #include "generic.h"
23 
24 #include <iostream>
25 
26 IMPCONTAINER_BEGIN_NAMESPACE
27 
28 //! Applies a TripletScore to each Triplet in a list based on a predicate
29 /** This restraint uses a passed predicate to choose which score to apply
30  to each tuple in the input container. The selections are cached, making it
31  substantially faster than using a core::TypedPairScore.
32 
33  \note The ordering of particles within a tuple may vary depending on the
34  input container used. You may need to call set_score() with several
35  different predicate values for different orderings.
36 */
37 class IMPCONTAINEREXPORT PredicateTripletsRestraint : public Restraint {
40  typedef IMP::kernel::internal::InternalDynamicListTripletContainer List;
42  Map containers_;
43  base::Pointer<List> unknown_container_;
44  Restraints restraints_;
45  mutable int input_version_;
46  bool error_on_unknown_;
47  void update_lists_if_necessary() const;
48  bool assign_pair(const ParticleIndexTriplet& index) const;
49 
50  public:
52  TripletContainerAdaptor input,
53  std::string name =
54  "PredicateTripletsRestraint %1%");
55 
56  /** Apply the passed score to all pairs whose predicate values match
57  the passed value.
58 
59  This version uses the container::create_restraint() function and so
60  is more efficient than the non-template version.*/
61  template <class Score> void set_score(int predicate_value, Score *score) {
62  IMP_USAGE_CHECK(get_model(),
63  "You must add this restraint to the model"
64  << " first, sorry, this can be fixed.");
65  IMP_NEW(List, c, (input_, score->get_name() + " input"));
66  restraints_.push_back(container::create_restraint(score, c.get()));
67  restraints_.back()->set_was_used(true);
68  containers_[predicate_value] = c;
69  }
70 
71  /** Apply this score to any pair whose predicate value does not match
72  one passed to set_score().*/
73  template <class Score> void set_unknown_score(Score *score) {
74  // make sure it gets cleaned up if it is a temporary
75  base::Pointer<Score> pscore(score);
76  IMP_USAGE_CHECK(get_model(),
77  "You must add this restraint to the model"
78  << " first, sorry, this can be fixed.");
79  IMP_NEW(List, c, (input_, score->get_name() + " input"));
80  restraints_.push_back(container::create_restraint(score, c.get()));
81  unknown_container_ = c;
82  }
83 #ifndef IMP_DOXYGEN
84  void set_score(int predicate_value, TripletScore *score) {
85  set_score<TripletScore>(predicate_value, score);
86  }
87  void set_unknown_score(TripletScore *score) {
88  set_unknown_score<TripletScore>(score);
89  }
90 #endif
91  /** By default, it is an error if the predicate returns a value that is
92  not known. If this is false, then they are silently skipped.
93  */
94  void set_is_complete(bool tf) { error_on_unknown_ = tf; }
95 
96  IMP_IMPLEMENT(double get_last_score() const);
97 
98  /** return the indexes of all particles for a given predicate value.*/
99  ParticleIndexTriplets get_indexes(int predicate_value) const {
100  return containers_.find(predicate_value)->second->get_indexes();
101  }
102 
103  public:
105  IMP_OVERRIDE;
106  IMP::kernel::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
108  ;
109 
110  private:
111  Restraints do_create_current_decomposition() const;
112 };
113 
114 IMPCONTAINER_END_NAMESPACE
115 
116 #endif /* IMPCONTAINER_PREDICATE_TRIPLETS_RESTRAINT_H */
Applies a TripletScore to each Triplet in a list based on a predicate.
Various important functionality for implementing decorators.
A smart pointer to a ref-counted Object that is a class memeber.
Definition: base/Pointer.h:147
Import IMP/kernel/TripletPredicate.h in the namespace.
void set_score(int predicate_value, Score *score)
IMP::base::Vector< IMP::base::Pointer< Restraint > > Restraints
virtual void do_add_score_and_derivatives(ScoreAccumulator sa) const
#define IMP_NEW(Typename, varname, args)
Declare a ref counted pointer to a new object.
Import IMP/kernel/restraint_macros.h in the namespace.
#define IMP_USAGE_CHECK(expr, message)
A runtime test for incorrect usage of a class or method.
#define IMP_IMPLEMENT(signature)
Abstract predicate function.
virtual double get_last_score() const
ParticleIndexTriplets get_indexes(int predicate_value) const
Class for adding up scores during ScoringFunction evaluation.
A restraint is a term in an IMP ScoringFunction.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
virtual ModelObjectsTemp do_get_inputs() const =0
Abstract score function.
kernel::Restraint * create_restraint(Score *s, Container *c, std::string name=std::string())
Declare an efficient stl-compatible map.