IMP logo
IMP Reference Guide  develop.98ef8da184,2024/04/23
The Integrative Modeling Platform
npc/CompositeRestraint.h
Go to the documentation of this file.
1 /**
2  * \file IMP/npc/CompositeRestraint.h \brief Composite restraint.
3  *
4  * Copyright 2007-2022 IMP Inventors. All rights reserved.
5  *
6  */
7 
8 #ifndef IMPNPC_COMPOSITE_RESTRAINT_H
9 #define IMPNPC_COMPOSITE_RESTRAINT_H
10 
11 #include <IMP/npc/npc_config.h>
12 
13 #include <IMP/SingletonContainer.h>
14 #include <IMP/Restraint.h>
15 #include <IMP/PairScore.h>
16 
17 IMPNPC_BEGIN_NAMESPACE
18 
19 //! Score a set of particles that form a composite
20 /** Similarly to IMP::core::ConnectivityRestraint, this ensures that a set
21  of Particles remains connected, but allows how they are connected to change
22  (for example, A-B-C would score as well as B-A-C). However, unlike that
23  restraint, it acts on Particle type (in the case where there are several
24  distinct Particles of the same type) and allows the stoichiometry to change
25  (For example, A1-B1-C1 would score similarly to A1-B2-C2 or A1-B1-B2-C1).
26 
27  To use, first create the restraint and then call add_type() for each
28  distinct protein type, e.g. to enforce the composite ABC where there are
29  two copies of protein A and B and a single copy of protein C use:
30  \begin{code}
31  add_type([A1, A2])
32  add_type([B1, B2])
33  add_type([C1])
34  \end{code}
35 
36  The restraint scores by computing the complete graph connecting all the
37  particles (where the particles are the vertices and the edges are the
38  value of the PairScore), then calculating the minimum spanning tree, and
39  then using the lowest scoring subgraph that includes at least one of each
40  protein type. This is made much more efficient if the restraint's maximum
41  score is set (set_maximum_score()).
42 
43  \see IMP::core::ConnectivityRestraint
44  \see IMP::core::MSConnectivityRestraint
45  */
46 class IMPNPCEXPORT CompositeRestraint : public Restraint {
47  typedef std::pair<int, ParticleIndex> TypedParticle;
49  std::vector<TypedParticle> tps_;
50  int num_particle_types_;
51 
52  public:
53  //! Create with the given PairScore
55  : Restraint(m, "CompositeRestraint %1%"), ps_(ps),
56  num_particle_types_(0) {}
57 
58  //! Add all Particles of a single type
59  /** The restraint will ensure that at least one Particle of each type
60  is present in the composite. */
62  for (const ParticleIndex &it : ps) {
63  tps_.push_back(TypedParticle(num_particle_types_, it));
64  }
65  ++num_particle_types_;
66  }
67 
68  //! Return the set of pairs which are connected by the restraint
69  /** This set of pairs reflects the current configuration at the time of
70  the get_connected_pairs() call, not the set at the time of the last
71  evaluate() call.
72  */
73  ParticleIndexPairs get_connected_pairs() const;
74 
75  double unprotected_evaluate(DerivativeAccumulator *accum) const override;
76  ModelObjectsTemp do_get_inputs() const override;
78 };
79 
80 IMPNPC_END_NAMESPACE
81 
82 #endif /* IMPNPC_COMPOSITE_RESTRAINT_H */
Abstract class for scoring object(s) of type ParticleIndexPair.
Definition: PairScore.h:44
A container for Singletons.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
virtual double unprotected_evaluate(DerivativeAccumulator *da) const
Return the unweighted score for the restraint.
Class for storing model, its restraints, constraints, and particles.
Definition: Model.h:86
CompositeRestraint(Model *m, PairScore *ps)
Create with the given PairScore.
Define PairScore.
void add_type(ParticleIndexes ps)
Add all Particles of a single type.
Abstract base class for all restraints.
Score a set of particles that form a composite.
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