IMP  2.4.0
The Integrative Modeling Platform
TypedPairScore.h
Go to the documentation of this file.
1 /**
2  * \file IMP/core/TypedPairScore.h
3  * \brief Delegate to another PairScore depending on particle types.
4  *
5  * Copyright 2007-2015 IMP Inventors. All rights reserved.
6  */
7 
8 #ifndef IMPCORE_TYPED_PAIR_SCORE_H
9 #define IMPCORE_TYPED_PAIR_SCORE_H
10 
11 #include <IMP/core/core_config.h>
12 #include <IMP/PairScore.h>
13 #include <IMP/pair_macros.h>
14 
15 IMPCORE_BEGIN_NAMESPACE
16 
17 //! Delegate to another PairScore depending on particle types.
18 /** Each particle is given an integer type, which is used at evaluate time
19  to select a PairScore to use for a given pair of particles. (The ordering
20  of the particles does not matter.) After creating the object, call
21  set_pair_score() to tell it the PairScore objects you want to use for each
22  pair of particle types.
23 
24  \note For efficiency, you should probably use the
25  container::PredicatePairRestraint instead.
26  */
27 class IMPCOREEXPORT TypedPairScore : public PairScore {
28  // The key used for the particle types.
29  IntKey typekey_;
30  typedef std::map<std::pair<Int, Int>, IMP::base::PointerMember<PairScore> >
31  ScoreMap;
32  // Mapping from particle types to PairScores.
33  ScoreMap score_map_;
34  // Whether to throw an exception for invalid particle types.
35  bool allow_invalid_types_;
36 
37  PairScore *get_pair_score(const kernel::ParticlePair &pp) const;
38 
39  public:
40  //! Constructor.
41  /** \param[in] typekey The IntKey used to denote the type of each particle.
42  \param[in] allow_invalid_types Desired behavior for particle pairs that
43  have types not covered by set_pair_score(). If true, the score
44  returned for these pairs is zero. If false, evaluate() raises
45  a ValueException.
46  */
47  TypedPairScore(IntKey typekey, bool allow_invalid_types = true);
48 
49  //! Set the particle's type.
50  /** At evaluate time, if a given particle does not have the typekey
51  attribute, this method is called. Here it does nothing, but it could
52  be overridden in a subclass to automatically set the type of a particle,
53  e.g. from other particle attributes such as an atom or residue name.
54  */
55  virtual void set_particle_type(kernel::Particle *) const {}
56 
57  //! Set the PairScore to delegate to for a given pair of particle types.
58  /** \param[in] ps PairScore to use at evaluate time.
59  \param[in] atype First particle type.
60  \param[in] btype Second particle type.
61  */
62  void set_pair_score(PairScore *ps, Int atype, Int btype) {
63  score_map_
64  [std::pair<Int, Int>(std::min(atype, btype), std::max(atype, btype))] =
66  }
67 
68  virtual double evaluate_index(kernel::Model *m,
75  ;
76 };
77 
78 IMPCORE_END_NAMESPACE
79 
80 #endif /* IMPCORE_TYPED_PAIR_SCORE_H */
A base class for Keys.
Definition: kernel/Key.h:46
Class for adding derivatives from restraints to the model.
Import IMP/kernel/pair_macros.h in the namespace.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Definition: object_macros.h:25
void set_pair_score(PairScore *ps, Int atype, Int btype)
Set the PairScore to delegate to for a given pair of particle types.
#define IMP_PAIR_SCORE_METHODS(Name)
virtual double evaluate_index(kernel::Model *m, const kernel::ParticleIndexPair &vt, DerivativeAccumulator *da) const
Compute the score and the derivative if needed.
A class to store an fixed array of same-typed values.
Definition: Array.h:33
Abstract class for scoring object(s) of type ParticlePair.
virtual ModelObjectsTemp do_get_inputs(kernel::Model *m, const ParticleIndexes &pis) const
Import IMP/kernel/PairScore.h in the namespace.
Class to handle individual model particles.
int Int
Basic integer value.
Definition: types.h:35
Delegate to another PairScore depending on particle types.
virtual void set_particle_type(kernel::Particle *) const
Set the particle's type.
#define IMP_OVERRIDE
Cause a compile error if this method does not override a parent method.
Class for storing model, its restraints, constraints, and particles.
Definition: kernel/Model.h:73