IMP  2.0.0
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-5687/imp-2.0.0/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/internal/InternalDynamicListTripletContainer.h>
19 #include <IMP/compatibility/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 :
38 public Restraint
39 {
42  typedef IMP::kernel::internal::InternalDynamicListTripletContainer List;
43  typedef compatibility::map<unsigned int, base::Pointer<List> >
44  Map;
45  Map containers_;
46  base::Pointer<List> unknown_container_;
47  Restraints restraints_;
48  mutable bool updated_;
49  bool error_on_unknown_;
50  void update_lists_if_necessary() const;
51  bool assign_pair(const ParticleIndexTriplet& index) const;
52 public:
54  TripletContainerAdaptor input,
55  std::string name="PredicateTripletsRestraint %1%");
56 
57  /** Apply the passed score to all pairs whose predicate values match
58  the passed value.
59 
60  This version uses the container::create_restraint() function and so
61  is more efficient than the non-template version.*/
62  template <class Score>
63  void set_score(int predicate_value, Score *score) {
64  IMP_USAGE_CHECK(get_is_part_of_model(),
65  "You must add this restraint to the model"
66  << " first, sorry, this can be fixed.");
67  IMP_NEW(List, c, (input_,
68  score->get_name()+" input"));
69  restraints_.push_back(container::create_restraint(score, c.get()));
70  restraints_.back()->set_model(get_model());
71  restraints_.back()->set_was_used(true);
72  containers_[predicate_value]=c;
73  }
74 
75  /** Apply this score to any pair whose predicate value does not match
76  one passed to set_score().*/
77  template <class Score>
78  void set_unknown_score( Score *score) {
79  // make sure it gets cleaned up if it is a temporary
80  base::Pointer<Score> pscore(score);
81  IMP_USAGE_CHECK(get_is_part_of_model(),
82  "You must add this restraint to the model"
83  << " first, sorry, this can be fixed.");
84  IMP_NEW(List, c, (input_,
85  score->get_name()+" input"));
86  restraints_.push_back(container::create_restraint(score, c.get()));
87  restraints_.back()->set_model(get_model());
88  unknown_container_=c;
89  }
90 #ifndef IMP_DOXYGEN
91  void set_score(int predicate_value, TripletScore *score) {
92  set_score<TripletScore>(predicate_value, score);
93  }
94  void set_unknown_score(TripletScore *score) {
95  set_unknown_score<TripletScore>(score);
96  }
97 #endif
98  /** By default, it is an error if the predicate returns a value that is
99  not known. If this is false, then they are silently skipped.
100  */
101  void set_is_complete(bool tf) {
102  error_on_unknown_=tf;
103  }
104 
105  IMP_IMPLEMENT(double get_last_score() const);
106 
107  /** return the indexes of all particles for a given predicate value.*/
108  ParticleIndexTriplets get_indexes(int predicate_value) const {
109  return containers_.find(predicate_value)->second
110  ->get_indexes();
111  }
112 
113  public:
115  const IMP_OVERRIDE;
116  IMP::ModelObjectsTemp do_get_inputs() const IMP_OVERRIDE;
118 private:
119  Restraints do_create_current_decomposition() const;
120 };
121 
122 IMPCONTAINER_END_NAMESPACE
123 
124 #endif /* IMPCONTAINER_PREDICATE_TRIPLETS_RESTRAINT_H */