00001
00002
00003
00004
00005
00006
00007
00008
00009
00010 #ifndef IMP_PAIR_CONTAINER_H
00011 #define IMP_PAIR_CONTAINER_H
00012
00013 #include "kernel_config.h"
00014 #include "internal/IndexingIterator.h"
00015 #include "Particle.h"
00016 #include "container_base.h"
00017 #include "utility.h"
00018 #include "VersionInfo.h"
00019 #include "base_types.h"
00020 #include "Pointer.h"
00021 #include "VectorOfRefCounted.h"
00022 #include "VersionInfo.h"
00023 #include "DerivativeAccumulator.h"
00024 #include "internal/OwnerPointer.h"
00025 #include "macros.h"
00026
00027 IMP_BEGIN_NAMESPACE
00028 class PairModifier;
00029 class PairScore;
00030
00031
00032
00033
00034
00035
00036
00037
00038 class IMPEXPORT PairContainer : public Container
00039 {
00040 internal::OwnerPointer<Container> added_, removed_;
00041 struct Accessor {
00042 typedef Accessor This;
00043 typedef ParticlePair result_type;
00044 typedef unsigned int argument_type;
00045 result_type operator()(argument_type i) const {
00046 return o_->get_particle_pair(i);
00047 }
00048 Accessor(PairContainer *pc): o_(pc){}
00049 Accessor(): o_(NULL){}
00050 IMP_COMPARISONS_1(o_);
00051 private:
00052
00053 PairContainer* o_;
00054 };
00055 protected:
00056
00057
00058
00059
00060
00061
00062
00063 void set_added_and_removed_containers(PairContainer* added,
00064 PairContainer* removed) {
00065 added_=added;
00066 removed_=removed;
00067 }
00068
00069 public:
00070 #ifndef IMP_DOXYGEN
00071 bool get_is_added_or_removed_container() {
00072 return !added_;
00073 }
00074 #endif
00075
00076 PairContainer(std::string name="PairContainer %1%");
00077
00078
00079
00080
00081 virtual bool get_contains_particle_pair(const ParticlePair& v) const =0;
00082
00083
00084
00085 virtual unsigned int get_number_of_particle_pairs() const =0;
00086
00087 ParticlePairsTemp get_particle_pairs() const {
00088 return ParticlePairsTemp(particle_pairs_begin(),
00089 particle_pairs_end());
00090 }
00091 virtual ParticlePair get_particle_pair(unsigned int i) const=0;
00092
00093 #ifdef IMP_DOXYGEN
00094
00095 class ParticlePairIterator;
00096 #else
00097 typedef internal::IndexingIterator<Accessor> ParticlePairIterator;
00098 #endif
00099
00100 ParticlePairIterator particle_pairs_begin() const {
00101
00102 return
00103 ParticlePairIterator(Accessor(const_cast<PairContainer*>(this)),
00104 0);
00105 }
00106
00107 ParticlePairIterator particle_pairs_end() const {
00108 return
00109 ParticlePairIterator(Accessor(const_cast<PairContainer*>(this)),
00110 get_number_of_particle_pairs());
00111 }
00112
00113
00114 virtual void apply(const PairModifier *sm)=0;
00115
00116
00117 virtual void apply(const PairModifier *sm, DerivativeAccumulator &da)=0;
00118
00119
00120 virtual double evaluate(const PairScore *s,
00121 DerivativeAccumulator *da) const=0;
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131 PairContainer* get_removed_pairs_container() const {
00132 IMP_USAGE_CHECK(added_, "The containers returned by "
00133 << " get_added_pairs_container() do not "
00134 << " track their own added and removed contents.");
00135 PairContainer *ret= dynamic_cast<PairContainer*>(removed_.get());
00136 IMP_INTERNAL_CHECK(ret, "Cannot cast object " << removed_->get_name()
00137 << " to a PairContainer.");
00138 return ret;
00139 }
00140 PairContainer* get_added_pairs_container() const {
00141 IMP_USAGE_CHECK(added_, "The containers returned by "
00142 << " get_added_pairs_container() do not "
00143 << " track their own added and removed contents.");
00144 PairContainer *ret= dynamic_cast<PairContainer*>(added_.get());
00145 IMP_INTERNAL_CHECK(ret, "Cannot cast object " << added_->get_name()
00146 << " to a PairContainer.");
00147 return ret;
00148 }
00149
00150
00151
00152 virtual double evaluate_change(const PairScore *o,
00153 DerivativeAccumulator *da) const = 0;
00154
00155
00156
00157
00158
00159 virtual double evaluate_prechange(const PairScore *o,
00160 DerivativeAccumulator *da) const = 0;
00161
00162
00163 #ifndef IMP_DOXYGEN
00164 ParticlePair get(unsigned int i) const {return get_particle_pair(i);}
00165 bool get_contains(const ParticlePair& v) const {
00166 return get_contains_particle_pair(v);
00167 }
00168 unsigned int get_number() const {return get_number_of_particle_pairs();}
00169 #endif
00170
00171 IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(PairContainer);
00172 };
00173
00174 IMP_OUTPUT_OPERATOR(PairContainer);
00175
00176
00177 IMP_OBJECTS(PairContainer);
00178
00179
00180
00181
00182
00183 IMP_END_NAMESPACE
00184
00185 #endif