IMP logo
IMP Reference Guide  develop.73004770ef,2026/11/23
The Integrative Modeling Platform
ExactCrossLinkMSRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/isd/ExactCrossLinkMSRestraint.h
3  * \brief A restraint for ambiguous cross-linking MS data using the exact
4  * forward model for uniform spheres.
5  *
6  * Copyright 2007-2026 IMP Inventors. All rights reserved.
7  *
8  */
9 
10 #ifndef IMPISD_EXACT_CROSS_LINK_MSRESTRAINT_H
11 #define IMPISD_EXACT_CROSS_LINK_MSRESTRAINT_H
12 
13 #include <IMP/isd/isd_config.h>
14 #include <IMP/Restraint.h>
15 #include <IMP/particle_index.h>
16 #include <IMP/isd/Scale.h>
17 #include <cereal/access.hpp>
18 #include <cereal/types/base_class.hpp>
19 #include <cereal/types/polymorphic.hpp>
20 
21 IMPISD_BEGIN_NAMESPACE
22 
23 //! A restraint for ambiguous cross-linking MS data and multiple state approach.
24 /** This has the same interface as CrossLinkMSRestraint, but uses the exact
25  forward model of Erzberger et al. (Cell 2014) and Robinson et al.
26  (eLife 2015). (CrossLinkMSRestraint uses an approximation to this model,
27  and is retained for backwards compatibility.)
28 
29  Each contribution k links two particles. Its forward model f_k is the
30  probability that two points, drawn uniformly from spheres of radius
31  sigma1 and sigma2 centered on the two particles, are closer than the
32  linker length. With psi_k the false positive rate, the restraint returns
33  1 - prod_k (1 - p_k), where p_k = f_k (1 - psi_k) + (1 - f_k) psi_k
34  (multiplied by exp(-slope * d_k) if a slope is given), or the negative
35  log of this if get_log_prob is true.
36 
37  If both ends of a contribution are the same particle, the distance
38  is taken to be 36/35 of its radius.
39 
40  Like CrossLinkMSRestraint, this restraint does not calculate
41  derivatives in C++. Its JAX implementation is differentiable, however.
42  */
43 class IMPISDEXPORT ExactCrossLinkMSRestraint : public Restraint {
44 
46  IMP::ParticleIndexPairs sigmass_;
47  IMP::ParticleIndex lengthi_;
49  double length_;
50  double slope_;
51  int constr_;
52  bool get_log_prob_;
53  std::string protein1_, protein2_;
54  int residue1_, residue2_;
55 
56  friend class cereal::access;
57 
58  template<class Archive> void serialize(Archive &ar) {
59  ar(cereal::base_class<Restraint>(this),
60  ppis_, sigmass_, lengthi_, psis_, length_, slope_,
61  constr_, get_log_prob_, protein1_, protein2_, residue1_, residue2_);
62  }
63 
65 
66  public:
67  //! Create the restraint.
68  ExactCrossLinkMSRestraint(IMP::Model* m, double length,
69  bool get_log_prob = false,
70  std::string name
71  = "ExactCrossLinkMSRestraint%1%");
72 
75  bool get_log_prob = false,
76  std::string name
77  = "ExactCrossLinkMSRestraint%1%");
78 
79  ExactCrossLinkMSRestraint(IMP::Model* m, double length, double slope,
80  bool get_log_prob = false,
81  std::string name
82  = "ExactCrossLinkMSRestraint%1%");
83 
85 
86  /** \name Source information
87  These methods get or set the protein name and residue index of
88  each end of the cross-link, as identified in the experiment
89  (typically these will correspond to the information in a CSV
90  file or similar). This information is not used in modeling, but
91  is written into output RMF files and is needed to generate mmCIF files.
92  %{
93  */
94  //! Set protein name for one end of the cross-link
95  void set_source_protein1(std::string protein1) { protein1_ = protein1; }
96 
97  //! Get protein name for one end of the cross-link
98  std::string get_source_protein1() const { return protein1_; }
99 
100  //! Set protein name for one end of the cross-link
101  void set_source_protein2(std::string protein2) { protein2_ = protein2; }
102 
103  //! Get protein name for one end of the cross-link
104  std::string get_source_protein2() const { return protein2_; }
105 
106  //! Set residue number for one end of the cross-link
107  void set_source_residue1(int residue1) { residue1_ = residue1; }
108 
109  //! Get residue number for one end of the cross-link
110  int get_source_residue1() const { return residue1_; }
111 
112  //! Set residue number for one end of the cross-link
113  void set_source_residue2(int residue2) { residue2_ = residue2; }
114 
115  //! Get residue number for one end of the cross-link
116  int get_source_residue2() const { return residue2_; }
117  /** @} */
118 
119  void add_contribution(const IMP::ParticleIndexPair& pps,
120  const IMP::ParticleIndexPair& sigmas,
121  IMP::ParticleIndex psi) {
122  ppis_.push_back(pps);
123  sigmass_.push_back(sigmas);
124  psis_.push_back(psi);
125  }
126 
127  double get_probability() const;
128 
129  //! Get the length of this restraint
130  /** Note that if the restraint was constructed with a length Scale,
131  this can change during sampling. */
132  double get_length() const {
133  if (constr_ == 1) {
134  return isd::Scale(get_model(), lengthi_).get_scale();
135  } else {
136  return length_;
137  }
138  }
139 
140  //! Return true iff the length is variable (stored in a Scale)
141  bool get_is_length_variable() const {
142  return constr_ == 1;
143  }
144 
145  //! Return true iff the restraint has a slope
146  bool get_has_slope() const {
147  return constr_ == 2;
148  }
149 
150  double get_slope() const { return slope_; }
151 
152  bool get_log_prob() const { return get_log_prob_; }
153 
154  //! Get the sigma particle indexes from a contribution
156  return sigmass_[i];
157  }
158 
159  //! Get the psi particle index from a contribution
161  return psis_[i];
162  }
163 
164  //! Get the particle indexes from a contribution
166  return ppis_[i];
167  }
168 
169  unsigned int get_number_of_contributions() const { return ppis_.size(); }
170 
171  virtual double unprotected_evaluate(
172  IMP::DerivativeAccumulator* accum) const override;
173  virtual IMP::ModelObjectsTemp do_get_inputs() const override;
174 
175  //! \return Information for writing to RMF files
176  RestraintInfo *get_static_info() const override;
177 
179 };
180 
181 IMPISD_END_NAMESPACE
182 
183 #endif /* IMPISD_EXACT_CROSS_LINK_MSRESTRAINT_H */
ParticleIndexPair get_contribution_sigma_indexes(int i) const
Get the sigma particle indexes from a contribution.
int get_source_residue2() const
Get residue number for one end of the cross-link.
int get_source_residue1() const
Get residue number for one end of the cross-link.
virtual RestraintInfo * get_static_info() const
Definition: Restraint.h:189
void set_source_residue1(int residue1)
Set residue number for one end of the cross-link.
Functions and adaptors for dealing with particle indexes.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
Take Decorator, Particle or ParticleIndex.
virtual double unprotected_evaluate(DerivativeAccumulator *da) const
Return the unweighted score for the restraint.
A decorator for scale parameters particles.
Add scale parameter to particle.
Definition: Scale.h:24
A restraint for ambiguous cross-linking MS data and multiple state approach.
ParticleIndex get_contribution_psi_index(int i) const
Get the psi particle index from a contribution.
std::string get_source_protein2() const
Get protein name for one end of the cross-link.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
bool get_has_slope() const
Return true iff the restraint has a slope.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
Definition: object_macros.h:95
double get_length() const
Get the length of this restraint.
void set_source_protein1(std::string protein1)
Set protein name for one end of the cross-link.
Report key:value information on restraints.
Definition: RestraintInfo.h:47
bool get_is_length_variable() const
Return true iff the length is variable (stored in a Scale)
ParticleIndexPair get_contribution_particle_indexes(int i) const
Get the particle indexes from a contribution.
Abstract base class for all restraints.
void set_source_protein2(std::string protein2)
Set protein name for one end of the cross-link.
void set_source_residue2(int residue2)
Set residue number for one end of the cross-link.
virtual ModelObjectsTemp do_get_inputs() const =0
Class for adding derivatives from restraints to the model.
A restraint is a term in an IMP ScoringFunction.
Definition: Restraint.h:56
std::string get_source_protein1() const
Get protein name for one end of the cross-link.