IMP  2.0.1
The Integrative Modeling Platform
creating_restraints.h
Go to the documentation of this file.
1 /**
2  * \file IMP/example/creating_restraints.h
3  * \brief A simple unary function.
4  *
5  * Copyright 2007-2013 IMP Inventors. All rights reserved.
6  *
7  */
8 
9 #ifndef IMPEXAMPLE_CREATING_RESTRAINTS_H
10 #define IMPEXAMPLE_CREATING_RESTRAINTS_H
11 
12 #include <IMP/example/example_config.h>
14 #include <IMP/container/generic.h>
19 
20 
21 IMPEXAMPLE_BEGIN_NAMESPACE
22 
23 /** Restraint the passed particles to be connected in a chain. The distance
24  between consecutive particles is length_factor*the sum of the radii.
25 
26  Note, this assumes that all such chains will be disjoint and so you can
27  use the container::ExclusiveConsecutivePairFilter if you want to filter
28  out all pairs of particles connected by such chain restraints.
29 
30  The restraint is not added to the model.
31 */
32 inline Restraint* create_chain_restraint(const ParticlesTemp &ps,
33  double length_factor,
34  double k,
35  std::string name) {
36  IMP_USAGE_CHECK(!ps.empty(), "No Particles passed.");
37  double scale = core::XYZR(ps[0]).get_radius();
38  IMP_NEW(core::HarmonicDistancePairScore, hdps, (length_factor*2.0*scale,
39  k, "chain linker %1%"));
40  // Exclusive means that the particles will be in no other
41  // ConsecutivePairContainer
42  // this assumption accelerates certain computations
44  (ps, name+" consecutive pairs"));
45  Pointer<Restraint> r= container::create_restraint(hdps.get(), cpc.get(),
46  "chain restraint %1%");
47  // make sure it is not freed
48  return r.release();
49 }
50 
51 
52 /** Create an excluded-volume style ClosePairsContainer based score. */
54 create_excluded_volume(const ParticlesTemp &ps,
55  double k,
56  std::string name) {
57  IMP_USAGE_CHECK(!ps.empty(), "No Particles passed.");
58  Model *m= ps[0]->get_model();
59  double scale = core::XYZR(ps[0]).get_radius();
61  (ps, name+" list"));
62  // Create a close pair container, with a distance bound of 0 and a slack
63  // that is proportional to the particle radius
65  cpc, (cores_container, 0, scale*.3));
67  Pointer<Restraint> r= container::create_restraint(hlb.get(), cpc.get());
68  m->add_restraint(r);
69  return cpc.release();
70 }
71 
72 IMPEXAMPLE_END_NAMESPACE
73 
74 #endif /* IMPEXAMPLE_CREATING_RESTRAINTS_H */