IMP logo
IMP Reference Guide  2.14.0
The Integrative Modeling Platform
pmi1/CompositeRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/pmi1/CompositeRestraint.h
3  * \brief A restraint for ambiguous cross-linking MS data and multiple
4  * state approach.
5  *
6  * Copyright 2007-2018 IMP Inventors. All rights reserved.
7  *
8  */
9 
10 #ifndef IMPPMI1_COMPOSITE_RESTRAINT_H
11 #define IMPPMI1_COMPOSITE_RESTRAINT_H
12 #include "pmi1_config.h"
13 #include <IMP/Restraint.h>
14 #include <IMP/Particle.h>
15 #include <IMP/tuple_macros.h>
16 //#include <IMP/container/CloseBipartitePairContainer.h>
17 
18 IMPPMI1_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 class IMPPMI1EXPORT CompositeRestraint : public Restraint
24 {
25  //particle indexes in the composite
27  ParticleIndexes handle_particle_indexes_;
28  double coffd_;
29  double l_;
30  IMP_NAMED_TUPLE_2(CacheKey, CacheKeys,
31  Int, ipart, Ints, excluded, );
32 
33  IMP_NAMED_TUPLE_2(CacheKeyPot, CacheKeyPots,
34  Int, ipart, Int, kpart, );
35 
36  typedef boost::unordered_map<CacheKey, double> Cache;
37  typedef boost::unordered_map<CacheKeyPot, double> CachePot;
38 
39  //variables needed to tabulate the exponential
40  Floats prob_grid_;
41  double invdx_;
42  double argmax_;
43  double argmin_;
44  bool tabprob_;
45  double plateau_;
46  int exparg_grid_size_;
47 
48  inline double calc_prob (double dist) const{
49  double argvalue=(dist-coffd_)/l_;
50  double prob;
51  if (tabprob_){
52  //this prevents something being below the lower value of the array
53  double maxarg=std::max(argvalue,argmin_);
54  //this prevents something being above the upper value of the array
55  double minarg=std::min(maxarg,argmax_);
56  unsigned k = static_cast<unsigned>( std::floor(minarg*invdx_)+exparg_grid_size_);
57  prob=prob_grid_[k];
58 
59  }
60  else{
61  prob=(1.0-plateau_)/(1.0+std::exp(-argvalue));
62  }
63  return prob;
64  }
65 
66 
67  //boost::unordered_map<std::tuple<unsigned int,unsigned int>,
68  // Pointer<container::CloseBipartitePairContainer>> map_cont_;
69 
70  /* call for probability */
71  double get_probability_per_particle_excluding(unsigned int ipart,
72  Ints excluded_ps, Cache& cache, CachePot& cachepot) const;
73 
74 public:
75 
76 
77  //! Create the restraint.
79  ParticleIndexesAdaptor handle_particle_indexes,
80  double coffd, double l, bool tabprob, double plateau,
81  std::string name="CompositeRestraint%1%");
82 
83  void add_composite_particle(ParticleIndexesAdaptor pi){pis_.push_back(pi);}
84 
85 
86  unsigned int get_number_of_elements() const {return pis_.size();}
87 
88 
89 
90  //double get_probability() const {return 0.0;}
91 
92  virtual double
93  unprotected_evaluate(DerivativeAccumulator *accum)
94  const IMP_OVERRIDE;
97 
98  virtual double get_probability() const
99  {
100  return exp(-unprotected_evaluate(nullptr));
101  }
102 
103 
104 };
105 
106 IMPPMI1_END_NAMESPACE
107 
108 #endif /* IMPPMI1_COMPOSITE_RESTRAINT_H */
#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 more IMP-like version of the std::vector.
Definition: Vector.h:39
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:72
A restraint for ambiguous cross-linking MS data and multiple state approach.
Classes to handle individual model particles. (Note that implementation of inline functions is in int...
Abstract base class for all restraints.
int Int
Basic integer value.
Definition: types.h:35
virtual ModelObjectsTemp do_get_inputs() const =0
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for adding derivatives from restraints to the model.
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:54