IMP logo
IMP Reference Guide  develop.7482b7c7af, 2026/12/05
The Integrative Modeling Platform
IMP::example::ExamplePairScore Class Reference

Apply a harmonic to the distance between two particles. More...

#include <IMP/example/ExamplePairScore.h>

Inheritance diagram for IMP::example::ExamplePairScore:

Detailed Description

Apply a harmonic to the distance between two particles.

The source code is as follows:

/**
* \file IMP/example/ExamplePairScore.h
* \brief A Score on the distance between a pair of particles.
*
* Copyright 2007-2026 IMP Inventors. All rights reserved.
*/
#ifndef IMPEXAMPLE_EXAMPLE_PAIR_SCORE_H
#define IMPEXAMPLE_EXAMPLE_PAIR_SCORE_H
#include <IMP/example/example_config.h>
#include <IMP/core/XYZ.h>
#include <IMP/PairScore.h>
#include <IMP/Pointer.h>
#include <cereal/access.hpp>
IMPEXAMPLE_BEGIN_NAMESPACE
//! Apply a harmonic to the distance between two particles.
/** The source code is as follows:
\include ExamplePairScore.h
\include ExamplePairScore.cpp
*/
class IMPEXAMPLEEXPORT ExamplePairScore : public PairScore {
double x0_, k_;
public:
ExamplePairScore(double x0, double k);
ExamplePairScore() {}
double get_mean() const { return x0_; }
double get_force_constant() const { return k_; }
virtual double evaluate_index(Model *m,
const ParticleIndexPair &p,
DerivativeAccumulator *da) const override;
virtual ModelObjectsTemp do_get_inputs(
Model *m, const ParticleIndexes &pis) const override;
IMP_PAIR_SCORE_METHODS(ExamplePairScore);
IMP_OBJECT_METHODS(ExamplePairScore);
// Serialization support
private:
friend class cereal::access;
template<class Archive> void serialize(Archive &ar) {
ar(cereal::base_class<PairScore>(this), x0_, k_);
}
IMP_OBJECT_SERIALIZE_DECL(ExamplePairScore);
};
IMP_OBJECTS(ExamplePairScore, ExamplePairScores);
IMPEXAMPLE_END_NAMESPACE
#endif /* IMPEXAMPLE_EXAMPLE_PAIR_SCORE_H */
Define PairScore.
A nullptr-initialized pointer to an IMP Object.
Single variable function.
Simple XYZ decorator.
#define IMP_OBJECT_SERIALIZE_DECL(Name)
Declare methods needed for serialization of Object pointers.
#define IMP_OBJECTS(Name, PluralName)
Define the types for storing lists of object pointers.
#define IMP_OBJECT_METHODS(Name)
Define the basic things needed by any Object.
Macros for various classes.
#define IMP_PAIR_SCORE_METHODS(Name)
Definition pair_macros.h:25
/**
* \file ExamplePairScore.cpp
* \brief A Score on the distance between a pair of particles.
*
* Copyright 2007-2022 IMP Inventors. All rights reserved.
*/
#include <IMP/core/XYZ.h>
#include <boost/lambda/lambda.hpp>
IMPEXAMPLE_BEGIN_NAMESPACE
ExamplePairScore::ExamplePairScore(double x0, double k) : x0_(x0), k_(k) {}
const ParticleIndexPair &pip,
DerivativeAccumulator *da) const {
// turn on logging for this method
// assume they have coordinates
core::XYZ d0(m, pip[0]);
core::XYZ d1(m, pip[1]);
// log something
double diff =
(d0.get_coordinates() - d1.get_coordinates()).get_magnitude() - x0_;
IMP_LOG_VERBOSE("The distance off from x0 is " << diff << std::endl);
double score = .5 * k_ * square(diff);
if (da) {
// derivatives are requested
algebra::Vector3D delta = d0.get_coordinates() - d1.get_coordinates();
algebra::Vector3D udelta = delta.get_unit_vector();
double dv = k_ * diff;
// add to the particle derivatives
d0.add_to_derivatives(udelta * dv, *da);
d1.add_to_derivatives(-udelta * dv, *da);
}
return score;
}
ModelObjectsTemp ExamplePairScore::do_get_inputs(
Model *m, const ParticleIndexes &pis) const {
return IMP::get_particles(m, pis);
}
IMPEXAMPLE_END_NAMESPACE
A Score on the distance between a pair of particles.
Class for adding derivatives from restraints to the model.
Class for storing model, its restraints, constraints, and particles.
Definition Model.h:111
A decorator for a particle with x,y,z coordinates.
Definition XYZ.h:30
Apply a harmonic to the distance between two particles.
virtual double evaluate_index(Model *m, const ParticleIndexPair &p, DerivativeAccumulator *da) const override
Compute the score and the derivative if needed.
#define IMP_LOG_VERBOSE(expr)
Definition log_macros.h:83
#define IMP_OBJECT_LOG
Set the log level to the object's log level.
Definition log_macros.h:284
ParticlesTemp get_particles(Model *m, const ParticleIndexes &ps)
Get the particles from a list of indexes.
double Float
Basic floating-point value (could be float, double...).
Definition types.h:19
VectorD< 3 > Vector3D
Definition VectorD.h:407
Array< 2, ParticleIndex > ParticleIndexPair
An ordered pair of particles, each identified by its ParticleIndex.
Definition base_types.h:202
#define IMP_OBJECT_SERIALIZE_IMPL(Name)
Add machinery needed for serialization of Object pointers.

Definition at line 26 of file ExamplePairScore.h.

Public Member Functions

 ExamplePairScore (double x0, double k)
virtual ModelObjectsTemp do_get_inputs (Model *m, const ParticleIndexes &pis) const override
 Overload this method to specify the inputs.
double evaluate_if_good_indexes (Model *m, const ParticleIndexPairs &p, DerivativeAccumulator *da, double max, unsigned int lower_bound, unsigned int upper_bound, bool all_indexes_checked=false) const override
virtual double evaluate_index (Model *m, const ParticleIndexPair &p, DerivativeAccumulator *da) const override
 Compute the score and the derivative if needed.
double evaluate_indexes (Model *m, const ParticleIndexPairs &p, DerivativeAccumulator *da, unsigned int lower_bound, unsigned int upper_bound, bool all_indexes_checked=false) const override final
 Compute the score and the derivative if needed over a set.
double evaluate_indexes_delta (Model *m, const ParticleIndexPairs &p, DerivativeAccumulator *da, const std::vector< unsigned > &indexes, std::vector< double > &score, bool all_indexes_checked=false) const override final
 Compute the change in score and the derivative if needed over a set.
double evaluate_indexes_scores (Model *m, const ParticleIndexPairs &p, DerivativeAccumulator *da, unsigned int lower_bound, unsigned int upper_bound, std::vector< double > &score, bool all_indexes_checked=false) const override final
 Compute the score and the derivative if needed over a set.
double get_force_constant () const
double get_mean () const
virtual std::string get_type_name () const override
virtual ::IMP::VersionInfo get_version_info () const override
 Get information about the module and version of the object.
Public Member Functions inherited from IMP::PairScore
 PairScore (std::string name="PairScore %1%")
virtual bool check_indexes (Model *m, const ParticleIndexes &pis) const
 Check the given particle indexes for necessary attributes.
Restraints create_current_decomposition (Model *m, const ParticleIndexPair &vt) const
virtual double evaluate_if_good_index (Model *m, const ParticleIndexPair &vt, DerivativeAccumulator *da, double max) const
 Compute the score and the derivative if needed, only if "good".
Public Member Functions inherited from IMP::ParticleInputs
ModelObjectsTemp get_inputs (Model *m, const ParticleIndexes &pis) const
 Get the ModelObjects read when the given list of particles is used.
Public Member Functions inherited from IMP::Object
CheckLevel get_check_level () const
 get_derived_object (self)
 Return this object cast to the most derived subclass.
LogLevel get_log_level () const
void set_check_level (CheckLevel l)
void set_log_level (LogLevel l)
 Set the logging level used in this object.
const std::string & get_name () const
 Get the (not necessarily unique) name of this object.
void set_name (std::string name)
void set_was_used (bool tf) const
void show (std::ostream &out=std::cout) const
virtual void clear_caches ()

Additional Inherited Members

Public Types inherited from IMP::PairScore
typedef ParticlePair Argument
typedef ParticleIndexPair IndexArgument
typedef PairModifier Modifier
typedef const ParticlePair & PassArgument
typedef const ParticleIndexPair & PassIndexArgument
Protected Member Functions inherited from IMP::PairScore
virtual Restraints do_create_current_decomposition (Model *m, const ParticleIndexPair &vt) const
 Override this to return your own decomposition.
Protected Member Functions inherited from IMP::Object
 Object (std::string name)
 Construct an object with the given name.
virtual void do_destroy ()

Constructor & Destructor Documentation

◆ ExamplePairScore()

IMP::example::ExamplePairScore::ExamplePairScore ( )

Definition at line 31 of file ExamplePairScore.h.

◆ ~ExamplePairScore()

virtual IMP::example::ExamplePairScore::~ExamplePairScore ( )
virtual

Definition at line 42 of file ExamplePairScore.h.

Member Function Documentation

◆ do_get_inputs()

virtual ModelObjectsTemp IMP::example::ExamplePairScore::do_get_inputs ( Model * m,
const ParticleIndexes & pis ) const
overridevirtual

Overload this method to specify the inputs.

Implements IMP::ParticleInputs.

◆ evaluate_if_good_indexes()

double IMP::example::ExamplePairScore::evaluate_if_good_indexes ( Model * m,
const ParticleIndexPairs & o,
DerivativeAccumulator * da,
double max,
unsigned int lower_bound,
unsigned int upper_bound,
bool all_indexes_checked = false ) const
overridevirtual

Compute the score and the derivative if needed over a set, only if "good". This functions similarly to evaluate_indexes(), but may terminate the computation early if the total score is higher than max.

Returns
the score if score<= max or some arbitrary value > max otherwise.
Note
An implementation for this is provided by the IMP_PAIR_SCORE_METHODS() macro.

Reimplemented from IMP::PairScore.

Definition at line 41 of file ExamplePairScore.h.

◆ evaluate_index()

virtual double IMP::example::ExamplePairScore::evaluate_index ( Model * m,
const ParticleIndexPair & vt,
DerivativeAccumulator * da ) const
overridevirtual

Compute the score and the derivative if needed.

Parameters
mthe model of vt
vtthe index in m of an object of type ParticlePair
daa DerivativeAccumulator that weights computed derivatives. If nullptr, derivatives will not be computed.

Implements IMP::PairScore.

◆ evaluate_indexes()

double IMP::example::ExamplePairScore::evaluate_indexes ( Model * m,
const ParticleIndexPairs & o,
DerivativeAccumulator * da,
unsigned int lower_bound,
unsigned int upper_bound,
bool all_indexes_checked = false ) const
finaloverridevirtual

Compute the score and the derivative if needed over a set.

Parameters
mthe model of o
oobjects of type ParticlePair, specified by index
daa derivative accumulator that weights computed derivatives. If nullptr, derivatives will not be computed.
lower_boundindex of first item in o to evaluate
upper_boundindex one past last item in o to evaluate
all_indexes_checkedif true, all of the passed indexes have already been checked by check_indexes() for needed particle attributes, so a faster implementation (that doesn't check them again) can be used if available.
Note
An implementation for this is provided by the IMP_PAIR_SCORE_METHODS() macro.

Reimplemented from IMP::PairScore.

Definition at line 41 of file ExamplePairScore.h.

◆ evaluate_indexes_delta()

double IMP::example::ExamplePairScore::evaluate_indexes_delta ( Model * m,
const ParticleIndexPairs & o,
DerivativeAccumulator * da,
const std::vector< unsigned > & indexes,
std::vector< double > & score,
bool all_indexes_checked = false ) const
finaloverridevirtual

Compute the change in score and the derivative if needed over a set.

The score for each o[indexes[x]] is updated in score[indexes[x]] and the total difference between the old and new score values (over the set) is returned.

Note
An implementation for this is provided by the IMP_PAIR_SCORE_METHODS() macro.

Reimplemented from IMP::PairScore.

Definition at line 41 of file ExamplePairScore.h.

◆ evaluate_indexes_scores()

double IMP::example::ExamplePairScore::evaluate_indexes_scores ( Model * m,
const ParticleIndexPairs & o,
DerivativeAccumulator * da,
unsigned int lower_bound,
unsigned int upper_bound,
std::vector< double > & score,
bool all_indexes_checked = false ) const
finaloverridevirtual

Compute the score and the derivative if needed over a set.

Like regular evaluate_indexes(), but the score for each o[x] is also returned as score[x].

Note
An implementation for this is provided by the IMP_PAIR_SCORE_METHODS() macro.

Reimplemented from IMP::PairScore.

Definition at line 41 of file ExamplePairScore.h.

◆ get_force_constant()

double IMP::example::ExamplePairScore::get_force_constant ( ) const

Definition at line 34 of file ExamplePairScore.h.

◆ get_mean()

double IMP::example::ExamplePairScore::get_mean ( ) const

Definition at line 33 of file ExamplePairScore.h.

◆ get_type_name()

virtual std::string IMP::example::ExamplePairScore::get_type_name ( ) const
overridevirtual

Reimplemented from IMP::Object.

Definition at line 42 of file ExamplePairScore.h.

◆ get_version_info()

virtual ::IMP::VersionInfo IMP::example::ExamplePairScore::get_version_info ( ) const
overridevirtual

Get information about the module and version of the object.

Reimplemented from IMP::Object.

Definition at line 42 of file ExamplePairScore.h.


The documentation for this class was generated from the following file: