IMP  2.0.0
The Integrative Modeling Platform
simplify_restraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/restrainer/simplify_restraint.h
3  * \brief Restrainer functions for restraints
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPRESTRAINER_SIMPLIFY_RESTRAINT_H
9 #define IMPRESTRAINER_SIMPLIFY_RESTRAINT_H
10 
11 #include <IMP/restrainer/restrainer_config.h>
12 #include <IMP/SingletonContainer.h>
13 #include <IMP/atom.h>
14 #include <IMP/core.h>
15 #include <IMP/em/FitRestraint.h>
16 #include <IMP/em/DensityMap.h>
17 #include <IMP/core/rigid_bodies.h>
18 
19 IMPRESTRAINER_BEGIN_NAMESPACE
20 
21 class SimpleConnectivity;
22 class SimpleDistance;
23 class SimpleDiameter;
24 class SimpleExcludedVolume;
25 class SimpleEMFit;
26 
27 
28 /* Having the default be RigidMembersRefiner is most likely a bad
29  idea, but it is needed to make things work. The refiner should
30  probably be exposed, otherwise this method cannot be used with the
31  rigid bodies created from molecular hierarchies, which is kind of
32  an unintuitive result. A better solution may be to ensure that
33  everything is an atom.Hierarchy and use the LeavesRefiner
34  implicitly.
35 
36  */
37 IMPRESTRAINEREXPORT SimpleConnectivity
38 create_simple_connectivity_on_rigid_bodies(const core::RigidBodies &rbs,
39  Refiner
40  *ref=IMP::core::internal::get_rigid_members_refiner());
41 
42 
43 /** Creates ConnectivityRestraint on molecules using LowestRefinedPairScore
44  and LeavesRefiner.
45 
46  \see LowestRefinedPairScore
47  \see SphereDistancePairScore
48  \see HarmonicUpperBound
49  \see LeavesRefiner
50  \relates SimpleConnectivity
51  */
52 IMPRESTRAINEREXPORT SimpleConnectivity create_simple_connectivity_on_molecules(
53  const atom::Hierarchies &mhs);
54 
55 
56 /** Creates DistanceRestraint using HarmonicUpperBound scoring function
57  as default.
58  \param[in] ps Pointer to two particles in distance restraint.
59  \relates SimpleDistance
60 */
61 IMPRESTRAINEREXPORT SimpleDistance create_simple_distance(const Particles &ps);
62 
63 
64 
65 /** Creates DiameterRestraint using HarmonicUpperBound scoring function
66  as default.
67  \param[in] ps Pointer to particles in diameter restraint.
68  \param[in] diameter Diameter.
69  \see ListSingletonContainer
70  \relates SimpleDiameter
71  */
72 IMPRESTRAINEREXPORT SimpleDiameter create_simple_diameter(
73  const Particles &ps, Float diameter);
74 
75 
76 /* Having the default be RigidMembersRefiner is most likely a bad
77  idea, but it is needed to make things work. The refiner should
78  probably be exposed, otherwise this method cannot be used with the
79  rigid bodies created from molecular hierarchies, which is kind of
80  an unintuitive result. A better solution may be to ensure that
81  everything is an atom.Hierarchy and use the LeavesRefiner
82  implicitly (as the docs say, but not as it was doing before).
83  */
84 
85 /** Creates ExcludedVolumeRestraint using LeavesRefiner.
86  \see ListSingletonContainer
87  \relates SimpleExcludedVolume
88 */
89 IMPRESTRAINEREXPORT SimpleExcludedVolume
91  const core::RigidBodies &rbs,
92  Refiner *ref= IMP::core::internal::get_rigid_members_refiner());
93 
94 
95 
96 /** Creates ExcludedVolumeRestraint using RigidMembersRefiner.
97  \see RigidMembersRefiner
98  \relates SimpleExcludedVolume
99 */
100 IMPRESTRAINEREXPORT SimpleExcludedVolume
102  const atom::Hierarchies &mhs);
103 
104 
105 
106 /** Creates EM FitRestraint.
107  \see FitRestraint
108  \see DensityMap
109  \relates SimpleEMFit
110 */
111 IMPRESTRAINEREXPORT SimpleEMFit create_simple_em_fit(
112  atom::Hierarchies const &mhs, em::DensityMap *dmap);
113 //! Creates EM FitRestraint.
114 /**
115  \param[in] mh a molecule to fit in the density
116  \param[in] dmap the density map
117  \see FitRestraint
118  \see DensityMap
119  \relates SimpleEMFit
120 */
121 IMPRESTRAINEREXPORT SimpleEMFit create_simple_em_fit(
122  atom::Hierarchy const &mh, em::DensityMap *dmap);
123 
124 /** Load EM density file (.mrc or .em file). */
125 IMPRESTRAINEREXPORT em::DensityMap *load_em_density_map(
126  char const *map_fn, float spacing, float resolution);
127 
128 IMPRESTRAINEREXPORT core::RigidBodies set_rigid_bodies(
129  atom::Hierarchies const &mhs);
130 
131 //! Simple connectivity restraint.
132 /**
133  \note SimpleConnectivity stores pointers to ConnectivityRestraint,
134  HarmonicUpperBound, and SphereDistancePairScore.
135  \note It provides convenient methods to change mean, k,
136  and standard deviation.
137  \see ConnectivityRestraint
138  */
139 class IMPRESTRAINEREXPORT SimpleConnectivity
140 {
141  IMP_NO_SWIG(
142  friend IMPRESTRAINEREXPORT SimpleConnectivity
143  create_simple_connectivity_on_rigid_bodies(
144  const core::RigidBodies &rbs, Refiner *ref);
145  friend IMPRESTRAINEREXPORT SimpleConnectivity
146  create_simple_connectivity_on_molecules(
147  atom::Hierarchies const &mhs);
148  )
149  public:
150  core::ConnectivityRestraint *get_restraint()
151  {
152  return connectivity_restraint_;
153  }
154 
155  core::HarmonicUpperBound *get_harmonic_upper_bound()
156  {
157  return harmonic_upper_bound_;
158  }
159 
160  core::SphereDistancePairScore *get_sphere_distance_pair_score()
161  {
162  return sphere_distance_pair_score_;
163  }
164 
165  //! Set the mean for the HarmonicUpperBound.
166  /** The default mean is 0.
167  */
168  void set_mean(Float mean)
169  {
170  harmonic_upper_bound_->set_mean(mean);
171  }
172 
173  //! Set the standard deviation for the HarmonicUpperBound.
174  void set_standard_deviation(Float sd)
175  {
176  static Float k = harmonic_upper_bound_->get_k_from_standard_deviation(sd);
177  harmonic_upper_bound_->set_k(k);
178  }
179 
180  //! Set the spring constant for the HarmonicUpperBound.
181  /** The default k is 1.
182  */
183  void set_k(Float k)
184  {
185  harmonic_upper_bound_->set_k(k);
186  }
187 
188  VersionInfo get_version_info() const
189  {
190  return IMP::VersionInfo("restrainer",
191  get_module_version());
192  }
193 
194  void show(std::ostream &out = std::cout) const
195  {
196  out << "SimpleConnectivity(";
197  if ( connectivity_restraint_ )
198  connectivity_restraint_->show(out);
199  out << ")";
200  }
201 
202 private:
203  // prevent unauthorized creation
204  SimpleConnectivity(
205  core::ConnectivityRestraint *connectivity_restraint,
206  core::HarmonicUpperBound *harmonic_upper_bound,
207  core::SphereDistancePairScore *sphere_distance_pair_score)
208  : connectivity_restraint_(connectivity_restraint)
209  , harmonic_upper_bound_(harmonic_upper_bound)
210  , sphere_distance_pair_score_(sphere_distance_pair_score)
211  {}
212 
213  IMP::Pointer<core::ConnectivityRestraint> connectivity_restraint_;
214  IMP::Pointer<core::HarmonicUpperBound> harmonic_upper_bound_;
215  IMP::Pointer<core::SphereDistancePairScore> sphere_distance_pair_score_;
216 };
218 
219 //! Simple distance restraint between two particles.
220 /**
221  \note SimpleDistance stores pointers to DistanceRestraint, and
222  HarmonicUpperBound.
223  \note It provides convenient methods to change mean, k, and
224  standard deviation.
225 
226  \see DistanceRestraint
227  */
228 class IMPRESTRAINEREXPORT SimpleDistance
229 {
230  IMP_NO_SWIG(friend IMPRESTRAINEREXPORT SimpleDistance
231  create_simple_distance(const Particles &ps));
232  public:
233  core::DistanceRestraint *get_restraint()
234  {
235  return distance_restraint_;
236  }
237 
238  core::HarmonicUpperBound *get_harmonic_upper_bound()
239  {
240  return harmonic_upper_bound_;
241  }
242 
243  //! Set the mean for the HarmonicUpperBound.
244  /** The default mean is 0.
245  */
246  void set_mean(Float mean)
247  {
248  harmonic_upper_bound_->set_mean(mean);
249  }
250 
251  //! Set the standard deviation for the HarmonicUpperBound.
252  void set_standard_deviation(Float sd)
253  {
254  static Float k = harmonic_upper_bound_->get_k_from_standard_deviation(sd);
255  harmonic_upper_bound_->set_k(k);
256  }
257 
258  //! Set the spring constant for the HarmonicUpperBound.
259  /** The default k is 1.
260  */
261  void set_k(Float k)
262  {
263  harmonic_upper_bound_->set_k(k);
264  }
265 
266  VersionInfo get_version_info() const
267  {
268  return VersionInfo("restrainer",
269  get_module_version());
270  }
271 
272  void show(std::ostream &out = std::cout) const
273  {
274  out << "SimpleDistance(";
275  if ( distance_restraint_ )
276  distance_restraint_->show(out);
277  out << ")";
278  }
279 
280 private:
281  // prevent unauthorized creation
282  SimpleDistance(
283  core::DistanceRestraint *distance_restraint,
284  core::HarmonicUpperBound *harmonic_upper_bound)
285  : distance_restraint_(distance_restraint)
286  , harmonic_upper_bound_(harmonic_upper_bound)
287  {}
288 
289  IMP::Pointer<core::DistanceRestraint> distance_restraint_;
290  IMP::Pointer<core::HarmonicUpperBound> harmonic_upper_bound_;
291 };
293 
294 //! Simple diameter restraint.
295 /**
296  \note SimpleDiameter stores pointers to DiameterRestraint, and
297  HarmonicUpperBound.
298  \note It provides convenient methods to change mean, k, and
299  standard deviation.
300  \see DiameterRestraint
301  */
302 class IMPRESTRAINEREXPORT SimpleDiameter
303 {
304  IMP_NO_SWIG(friend IMPRESTRAINEREXPORT SimpleDiameter
305  create_simple_diameter(const Particles &ps,
306  Float diameter));
307  public:
308 
309  core::DiameterRestraint *get_restraint()
310  {
311  return diameter_restraint_;
312  }
313 
314  core::HarmonicUpperBound *get_harmonic_upper_bound()
315  {
316  return harmonic_upper_bound_;
317  }
318 
319  //! Set the mean for the HarmonicUpperBound.
320  /** The default mean is 0.
321  */
322  void set_mean(Float mean)
323  {
324  harmonic_upper_bound_->set_mean(mean);
325  }
326 
327  //! Set the standard deviation for the HarmonicUpperBound.
328  void set_standard_deviation(Float sd)
329  {
330  static Float k = harmonic_upper_bound_->get_k_from_standard_deviation(sd);
331  harmonic_upper_bound_->set_k(k);
332  }
333 
334  //! Set the spring constant for the HarmonicUpperBound.
335  /** The default k is 1.
336  */
337  void set_k(Float k)
338  {
339  harmonic_upper_bound_->set_k(k);
340  }
341 
342  VersionInfo get_version_info() const
343  {
344  return VersionInfo("restrainer",
345  get_module_version());
346  }
347 
348  void show(std::ostream &out = std::cout) const
349  {
350  out << "SimpleDiameter(";
351  if ( diameter_restraint_ )
352  diameter_restraint_->show(out);
353  out << ")";
354  }
355 
356 private:
357  // prevent unauthorized creation
358  SimpleDiameter(
359  core::DiameterRestraint *diameter_restraint,
360  core::HarmonicUpperBound *harmonic_upper_bound)
361  : diameter_restraint_(diameter_restraint)
362  , harmonic_upper_bound_(harmonic_upper_bound)
363  {}
364 
365  IMP::Pointer<core::DiameterRestraint> diameter_restraint_;
366  IMP::Pointer<core::HarmonicUpperBound> harmonic_upper_bound_;
367 };
369 
370 //! Simple excluded volume restraint.
371 /**
372  \see ExcludedVolumeRestraint
373  */
374 class IMPRESTRAINEREXPORT SimpleExcludedVolume
375 {
376  IMP_NO_SWIG(friend IMPRESTRAINEREXPORT SimpleExcludedVolume
377  create_simple_excluded_volume_on_rigid_bodies(
378  const core::RigidBodies &rbs, Refiner*ref)
379  );
380  IMP_NO_SWIG(friend IMPRESTRAINEREXPORT SimpleExcludedVolume
381  create_simple_excluded_volume_on_molecules(
382  atom::Hierarchies const &mhs)
383  );
384  public:
385 
386  core::ExcludedVolumeRestraint *get_restraint()
387  {
388  return excluded_volume_restraint_;
389  }
390 
391  VersionInfo get_version_info() const
392  {
393  return VersionInfo("restrainer",
394  get_module_version());
395  }
396 
397  void show(std::ostream &out = std::cout) const
398  {
399  out << "SimpleExcludedVolume(";
400  if ( excluded_volume_restraint_ )
401  excluded_volume_restraint_->show(out);
402  out << ")";
403  }
404 
405 private:
406  // prevent unauthorized creation
408  core::ExcludedVolumeRestraint *excluded_volume_restraint)
409  : excluded_volume_restraint_(excluded_volume_restraint)
410  {}
411 
412  IMP::Pointer<core::ExcludedVolumeRestraint> excluded_volume_restraint_;
413 };
415 
416 //! Simple EM fit restraint.
417 /**
418  \note SimpleEMFit stores pointer to FitRestraint.
419  \see FitRestraint
420  */
421 class IMPRESTRAINEREXPORT SimpleEMFit
422 {
423  IMP_NO_SWIG(friend IMPRESTRAINEREXPORT SimpleEMFit create_simple_em_fit(
424  atom::Hierarchies const &mhs, em::DensityMap *dmap));
425 public:
426  em::FitRestraint *get_restraint()
427  {
428  return fit_restraint_;
429  }
430 
431  VersionInfo get_version_info() const
432  {
433  return VersionInfo("restrainer",
434  get_module_version());
435  }
436 
437  void show(std::ostream &out = std::cout) const
438  {
439  out << "SimpleEMFit(";
440  if ( fit_restraint_ )
441  fit_restraint_->show(out);
442  out << ")";
443  }
444 
445 private:
446  // prevent unauthorized creation
447  SimpleEMFit(
448  em::FitRestraint *fit_restraint)
449  : fit_restraint_(fit_restraint)
450  {}
451 
452  IMP::Pointer<em::FitRestraint> fit_restraint_;
453 };
455 
456 IMPRESTRAINER_END_NAMESPACE
457 
458 #endif /* IMPRESTRAINER_SIMPLIFY_RESTRAINT_H */