IMP  2.3.0
The Integrative Modeling Platform
CompositeRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/pmi/CompositeRestraint.h
3  * \brief A pmf based likelihood function
4  * with prior knowledge on the flase positive rate.
5  *
6  * Copyright 2007-2014 IMP Inventors. All rights reserved.
7  *
8  */
9 
10 #ifndef IMPPMI_COMPOSITE_RESTRAINT_H
11 #define IMPPMI_COMPOSITE_RESTRAINT_H
12 #include "pmi_config.h"
13 #include <IMP/Restraint.h>
14 #include <IMP/kernel/Particle.h>
15 #include <IMP/base/tuple_macros.h>
16 //#include <IMP/container/CloseBipartitePairContainer.h>
17 
18 IMPPMI_BEGIN_NAMESPACE
19 /** A restraint for ambiguous cross-linking MS data and multiple state approach.
20  It marginalizes the false positive rate and depends on the expected fpr and
21  an uncertainty parameter beta.
22  */
23 
24 class IMPPMIEXPORT CompositeRestraint : public Restraint
25 {
26  //particle indexes in the composite
28  kernel::ParticleIndexes handle_particle_indexes_;
29  double coffd_;
30  double l_;
31  IMP_NAMED_TUPLE_2(CacheKey, CacheKeys,
32  Int, ipart, Ints, excluded, );
33 
34  IMP_NAMED_TUPLE_2(CacheKeyPot, CacheKeyPots,
35  Int, ipart, Int, kpart, );
36 
37  typedef boost::unordered_map<CacheKey, double> Cache;
38  typedef boost::unordered_map<CacheKeyPot, double> CachePot;
39 
40  //variables needed to tabulate the exponential
41  Floats prob_grid_;
42  double invdx_;
43  double argmax_;
44  double argmin_;
45  bool tabprob_;
46  double plateau_;
47  int exparg_grid_size_;
48 
49  inline double calc_prob (double dist) const{
50  double argvalue=(dist-coffd_)/l_;
51  double prob;
52  if (tabprob_){
53  //this prevents something being below the lower value of the array
54  double maxarg=std::max(argvalue,argmin_);
55  //this prevents something being above the upper value of the array
56  double minarg=std::min(maxarg,argmax_);
57  unsigned k = static_cast<unsigned>( std::floor(minarg*invdx_)+exparg_grid_size_);
58  prob=prob_grid_[k];
59 
60  }
61  else{
62  prob=(1.0-plateau_)/(1.0+std::exp(-argvalue));
63  }
64  return prob;
65  }
66 
67 
68  //boost::unordered_map<std::tuple<unsigned int,unsigned int>,
69  // base::Pointer<container::CloseBipartitePairContainer>> map_cont_;
70 
71  /* call for probability */
72  double get_probability_per_particle_excluding(unsigned int ipart,
73  Ints excluded_ps, Cache& cache, CachePot& cachepot) const;
74 
75 public:
76 
77 
78  //! Create the restraint.
79  /** Restraints should store the particles they are to act on,
80  preferably in a Singleton or PairContainer as appropriate.
81  */
82 
84  kernel::ParticleIndexesAdaptor handle_particle_indexes,
85  double coffd, double l, bool tabprob, double plateau,
86  std::string name="CompositeRestraint%1%");
87 
88  void add_composite_particle(kernel::ParticleIndexesAdaptor pi){pis_.push_back(pi);}
89 
90 
91  unsigned int get_number_of_elements() const {return pis_.size();}
92 
93 
94 
95  //double get_probability() const {return 0.0;}
96 
97  /** This macro declares the basic needed methods: evaluate and show
98  */
99  virtual double
100  unprotected_evaluate(kernel::DerivativeAccumulator *accum)
101  const IMP_OVERRIDE;
104 
105  virtual double get_probability() const
106  {
107  return exp(-unprotected_evaluate(nullptr));
108  }
109 
110 
111 };
112 
113 IMPPMI_END_NAMESPACE
114 
115 #endif /* IMPPMI_COMPOSITE_RESTRAINT_H */
Class for adding derivatives from restraints to the model.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Various general useful macros for IMP.
A restraint is a term in an IMP ScoringFunction.
Classes to handle individual model particles. (Note that implementation of inline functions in in int...
virtual ModelObjectsTemp do_get_inputs() const =0
Import IMP/kernel/Restraint.h in the namespace.
int Int
Basic integer value.
Definition: types.h:35
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73