00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMP_MACROS_H
00009 #define IMP_MACROS_H
00010
00011 #ifdef IMP_DOXYGEN
00012
00013
00014 #define IMP_NO_DOXYGEN(x)
00015
00016
00017 #define IMP_ONLY_DOXYGEN(x) x
00018 #define IMP_SWITCH_DOXYGEN(x,y) x
00019 #else
00020 #define IMP_NO_DOXYGEN(x) x
00021 #define IMP_ONLY_DOXYGEN(x)
00022 #define IMP_SWITCH_DOXYGEN(x,y) y
00023 #endif
00024
00025 #if defined(SWIG)
00026 #define IMP_NO_SWIG(x)
00027 #else
00028
00029
00030 #define IMP_NO_SWIG(x) x
00031 #endif
00032
00033 #if defined(SWIG) || defined(IMP_DOXYGEN)
00034
00035
00036
00037
00038
00039 #define IMP_COMPARISONS
00040
00041
00042
00043
00044 #define IMP_COMPARISONS_1(field)
00045
00046
00047
00048
00049 #define IMP_COMPARISONS_2(f0, f1)
00050
00051
00052
00053
00054 #define IMP_COMPARISONS_3(f0, f1, f2)
00055
00056 #else
00057
00058 #define IMP_COMPARISONS \
00059 bool operator==(const This &o) const { \
00060 return (compare(o) == 0); \
00061 } \
00062 bool operator!=(const This &o) const { \
00063 return (compare(o) != 0); \
00064 } \
00065 bool operator<(const This &o) const { \
00066 return (compare(o) <0); \
00067 } \
00068 bool operator>(const This &o) const { \
00069 return (compare(o) > 0); \
00070 } \
00071 bool operator>=(const This &o) const { \
00072 return !(compare(o) < 0); \
00073 } \
00074 bool operator<=(const This &o) const { \
00075 return !(compare(o) > 0); \
00076 } \
00077 IMP_NO_SWIG(template <class T> friend int compare(const T&a, const T&b));
00078
00079 #define IMP_COMPARISONS_1(field) \
00080 bool operator==(const This &o) const { \
00081 return (field== o.field); \
00082 } \
00083 bool operator!=(const This &o) const { \
00084 return (field!= o.field); \
00085 } \
00086 bool operator<(const This &o) const { \
00087 return (field< o.field); \
00088 } \
00089 bool operator>(const This &o) const { \
00090 return (field> o.field); \
00091 } \
00092 bool operator>=(const This &o) const { \
00093 return (field>= o.field); \
00094 } \
00095 bool operator<=(const This &o) const { \
00096 return (field<= o.field); \
00097 } \
00098 int compare(const This &o) const { \
00099 if (operator<(o)) return -1; \
00100 else if (operator>(o)) return 1; \
00101 else return 0; \
00102 }
00103
00104
00105
00106
00107 #define IMP_COMPARISONS_2(f0, f1) \
00108 bool operator==(const This &o) const { \
00109 return (f0== o.f0 && f1==o.f1); \
00110 } \
00111 bool operator!=(const This &o) const { \
00112 return (f0!= o.f0 || f1 != o.f1); \
00113 } \
00114 bool operator<(const This &o) const { \
00115 if (f0< o.f0) return true; \
00116 else if (f0 > o.f0) return false; \
00117 else return f1 < o.f1; \
00118 } \
00119 bool operator>(const This &o) const { \
00120 if (f0 > o.f0) return true; \
00121 else if (f0 < o.f0) return false; \
00122 else return f1 > o.f1; \
00123 } \
00124 bool operator>=(const This &o) const { \
00125 return operator>(o) || operator==(o); \
00126 } \
00127 bool operator<=(const This &o) const { \
00128 return operator<(o) || operator==(o); \
00129 } \
00130 int compare(const This &o) const { \
00131 if (operator<(o)) return -1; \
00132 else if (operator>(o)) return 1; \
00133 else return 0; \
00134 }
00135
00136 #define IMP_COMPARISONS_3(f0, f1, f2) \
00137 bool operator==(const This &o) const { \
00138 return (f0== o.f0 && f1==o.f1 && f2 == o.f2); \
00139 } \
00140 bool operator!=(const This &o) const { \
00141 return (f0!= o.f0 || f1 != o.f1 || f2 != o.f2); \
00142 } \
00143 bool operator<(const This &o) const { \
00144 if (f0< o.f0) return true; \
00145 else if (f0 > o.f0) return false; \
00146 if (f1< o.f1) return true; \
00147 else if (f1 > o.f1) return false; \
00148 else return f2 < o.f2; \
00149 } \
00150 bool operator>(const This &o) const { \
00151 if (f0 > o.f0) return true; \
00152 else if (f0 < o.f0) return false; \
00153 if (f1 > o.f1) return true; \
00154 else if (f1 < o.f1) return false; \
00155 else return f2 > o.f2; \
00156 } \
00157 bool operator>=(const This &o) const { \
00158 return operator>(o) || operator==(o); \
00159 } \
00160 bool operator<=(const This &o) const { \
00161 return operator<(o) || operator==(o); \
00162 } \
00163 int compare(const This &o) const { \
00164 if (operator<(o)) return -1; \
00165 else if (operator>(o)) return 1; \
00166 else return 0; \
00167 }
00168 #endif
00169
00170 #if defined(IMP_DOXYGEN) || defined(SWIG)
00171
00172
00173
00174 #define IMP_OUTPUT_OPERATOR_1(name)
00175
00176
00177
00178 #define IMP_OUTPUT_OPERATOR_2(name)
00179
00180
00181
00182
00183 #define IMP_OUTPUT_OPERATOR(name)
00184
00185
00186
00187
00188
00189 #define IMP_OUTPUT_OPERATOR_D(name)
00190
00191 #else
00192 #define IMP_OUTPUT_OPERATOR_1(name) \
00193 template <class L> \
00194 inline std::ostream& operator<<(std::ostream &out, const name<L> &i) \
00195 { \
00196 i.show(out); \
00197 return out; \
00198 } \
00199 template <class L> \
00200 inline void show(std::ostream &out, const name<L, M> &i) \
00201 i.show(out); \
00202 }
00203
00204 #define IMP_OUTPUT_OPERATOR_2(name) \
00205 template <class L, class M> \
00206 inline std::ostream& operator<<(std::ostream &out, const name<L, M> &i) \
00207 { \
00208 i.show(out); \
00209 return out; \
00210 } \
00211 template <class L, class M> \
00212 inline void show(std::ostream &out, const name<L, M> &i) \
00213 i.show(out); \
00214 }
00215
00216 #define IMP_OUTPUT_OPERATOR(name) \
00217 inline std::ostream &operator<<(std::ostream &out, const name &i) \
00218 { \
00219 i.show(out); \
00220 return out; \
00221 } \
00222 inline void show(std::ostream &out, const name &i) { \
00223 i.show(out); \
00224 }
00225
00226 #define IMP_OUTPUT_OPERATOR_D(name) \
00227 template <unsigned int D> \
00228 inline std::ostream &operator<<(std::ostream &out, const name<D> &i) \
00229 { \
00230 i.show(out); \
00231 return out; \
00232 } \
00233 template <unsigned int D> \
00234 void show(std::ostream &out, const name<D> &i) { \
00235 i.show(out); \
00236 }
00237 #endif
00238
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249 #define IMP_SWAP(Name) \
00250 inline void swap(Name &a, Name &b) {a.swap_with(b);}
00251
00252 #define IMP_SWAP_1(Name) \
00253 template <class A> \
00254 inline void swap(Name<A> &a, Name<A> &b) {a.swap_with(b);}
00255
00256
00257 #define IMP_SWAP_2(Name) \
00258 template <class A, class B> \
00259 inline void swap(Name<A,B> &a, Name<A,B> &b) { \
00260 a.swap_with(b); \
00261 }
00262
00263 #define IMP_SWAP_3(Name) \
00264 template <class A, class B, class C> \
00265 inline void swap(Name<A,B,C> &a, Name<A,B,C> &b) { \
00266 a.swap_with(b); \
00267 }
00268
00269
00270
00271
00272
00273
00274 #define IMP_SWAP_MEMBER(var_name) \
00275 std::swap(var_name, o.var_name);
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286
00287
00288
00289
00290 #define IMP_COPY_CONSTRUCTOR(TC) TC(const TC &o){copy_from(o);} \
00291 TC& operator=(const TC &o) {copy_from(o); return *this;}
00292
00293
00294
00295
00296 #ifdef _MSC_VER
00297
00298 #define IMP_REF_COUNTED_DESTRUCTOR(Name) \
00299 public: \
00300 virtual ~Name(){}
00301
00302 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name) \
00303 public: \
00304 virtual ~Name()
00305
00306 #else
00307
00308 #if defined(SWIG) || defined(IMP_SWIG_WRAPPER)
00309
00310 #define IMP_REF_COUNTED_DESTRUCTOR(Name) \
00311 public: \
00312 virtual ~Name(){}
00313 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name) \
00314 public: \
00315 virtual ~Name()
00316
00317
00318 #else
00319
00320
00321
00322
00323
00324
00325
00326
00327
00328
00329
00330
00331
00332
00333 #define IMP_REF_COUNTED_DESTRUCTOR(Name) \
00334 protected: \
00335 template <class T> friend void IMP::internal::unref(T*); \
00336 virtual ~Name(){}
00337
00338
00339
00340
00341 #define IMP_REF_COUNTED_NONTRIVIAL_DESTRUCTOR(Name) \
00342 protected: \
00343 template <class T> friend void IMP::internal::unref(T*); \
00344 virtual ~Name()
00345
00346 #endif // SWIG
00347 #endif // _MSC_VER
00348
00349
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370
00371
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384
00385
00386 #define IMP_DECORATOR(Name, Parent) \
00387 public: \
00388
00389 \
00390 IMP_NO_DOXYGEN(typedef Name This); \
00391 Name(): Parent(){} \
00392 explicit Name(::IMP::Particle *p): Parent(p) { \
00393 IMP_INTERNAL_CHECK(particle_is_instance(p), \
00394 "Particle missing required attributes for decorator " \
00395 << #Name << *p << std::endl); \
00396 } \
00397 static Name decorate_particle(::IMP::Particle *p) { \
00398 IMP_CHECK_OBJECT(p); \
00399 if (!particle_is_instance(p)) { \
00400 return Name(); \
00401 } \
00402 return Name(p); \
00403 } \
00404 IMP_SHOWABLE
00405
00406
00407
00408
00409
00410
00411
00412
00413
00414
00415
00416
00417
00418
00419 #define IMP_DECORATOR_TRAITS(Name, Parent, TraitsType, traits_name, \
00420 default_traits) \
00421 private: \
00422 TraitsType traits_name##_; \
00423 public: \
00424 IMP_NO_DOXYGEN(typedef Name This;) \
00425 Name(): Parent(){} \
00426 Name(::IMP::Particle *p, \
00427 const TraitsType &tr=default_traits): Parent(p), \
00428 traits_name##_(tr) { \
00429 IMP_INTERNAL_CHECK(particle_is_instance(p, tr), \
00430 "Particle missing required attributes " \
00431 << " for decorator " \
00432 << #Name << *p << std::endl); \
00433 } \
00434 static Name decorate_particle(::IMP::Particle *p, \
00435 const TraitsType &tr=default_traits) { \
00436 if (!particle_is_instance(p, tr)) return Name(); \
00437 else return Name(p, tr); \
00438 } \
00439 IMP_SHOWABLE; \
00440 const TraitsType &get_##traits_name() const { \
00441 return traits_name##_; \
00442 }
00443
00444
00445
00446
00447
00448
00449
00450
00451
00452
00453
00454
00455
00456
00457
00458
00459
00460 #define IMP_DECORATOR_GET(AttributeKey, Type, has_action, not_has_action) \
00461 if (get_particle()->has_attribute(AttributeKey)) { \
00462 Type VALUE = get_particle()->get_value(AttributeKey); \
00463 has_action; \
00464 } else { \
00465 not_has_action; \
00466 }
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476 #define IMP_DECORATOR_SET(AttributeKey, value) \
00477 if (get_particle()->has_attribute(AttributeKey)) { \
00478 get_particle()->set_value(AttributeKey, value) ; \
00479 } else { \
00480 get_particle()->add_attribute(AttributeKey, value); \
00481 }
00482
00483
00484
00485
00486
00487
00488
00489
00490
00491
00492
00493
00494 #define IMP_DECORATOR_GET_SET(name, AttributeKey, Type, ReturnType) \
00495 ReturnType get_##name() const { \
00496 return static_cast<ReturnType>(get_particle()->get_value(AttributeKey)); \
00497 } \
00498 void set_##name(ReturnType t) { \
00499 get_particle()->set_value(AttributeKey, t); \
00500 }
00501
00502
00503
00504
00505
00506
00507
00508
00509
00510
00511
00512 #define IMP_DECORATOR_GET_SET_OPT(name, AttributeKey, Type, \
00513 ReturnType, default_value) \
00514 ReturnType get_##name() const { \
00515 IMP_DECORATOR_GET(AttributeKey, Type, \
00516 return static_cast<ReturnType>(VALUE), \
00517 return default_value); \
00518 } \
00519 void set_##name(ReturnType t) { \
00520 IMP_DECORATOR_SET(AttributeKey, t); \
00521 }
00522
00523 #ifdef IMP_DOXYGEN
00524
00525
00526
00527 #define IMP_DECORATORS(Name, Parent) \
00528 class Name##s: public Parent {}; \
00529 class Name##sTemp: public Parent##Temp {}
00530 #else
00531 #define IMP_DECORATORS(Name, Parent) \
00532 typedef IMP::Decorators<Name, Parent> Name##s; \
00533 typedef IMP::Decorators<Name, Parent##Temp> Name##sTemp
00534 #endif
00535
00536
00537
00538
00539
00540
00541
00542 #define IMP_SUMMARY_DECORATOR_DECL(Name, Parent, Members) \
00543 class IMPCOREEXPORT Name: public Parent { \
00544 IMP_CONSTRAINT_DECORATOR_DECL(Name); \
00545 public: \
00546 IMP_DECORATOR(Name, Parent); \
00547 static Name setup_particle(Particle *p, \
00548 const Members &members); \
00549 static Name setup_particle(Particle *p, \
00550 Refiner *ref); \
00551 ~Name(); \
00552 static bool particle_is_instance(Particle *p) { \
00553 return p->has_attribute(get_constraint_key()); \
00554 } \
00555 private: \
00556 \
00557 void set_coordinates() {}; \
00558 void set_coordinates_are_optimized()const{} \
00559 void set_coordinate() const {} \
00560 void set_radius()const{} \
00561 };
00562
00563
00564
00565
00566
00567
00568
00569
00570
00571 #define IMP_SUMMARY_DECORATOR_DEF(Name, Parent, Members, create_modifier) \
00572 IMP_CONSTRAINT_DECORATOR_DEF(Name) \
00573 Name Name::setup_particle(Particle *p, const Members &ps) { \
00574 Refiner *ref=new FixedRefiner(ps); \
00575 create_modifier; \
00576 if (!Parent::particle_is_instance(p)) Parent::setup_particle(p); \
00577 set_constraint(mod, new DerivativesToRefined(ref), p); \
00578 return Name(p); \
00579 } \
00580 Name Name::setup_particle(Particle *p, Refiner *ref) { \
00581 create_modifier; \
00582 if (!Parent::particle_is_instance(p)) Parent::setup_particle(p); \
00583 set_constraint(mod, new DerivativesToRefined(ref), p); \
00584 return Name(p); \
00585 } \
00586 Name::~Name(){} \
00587 IMP_NO_DOXYGEN(void Name::show(std::ostream &out) const { \
00588 out << #Name << " at " << static_cast<Parent>(*this); \
00589 })
00590
00591
00592
00593
00594
00595
00596
00597
00598
00599
00600
00601
00602
00603
00604
00605
00606
00607
00608
00609
00610
00611
00612
00613
00614
00615
00616
00617 #define IMP_DECORATOR_ARRAY_DECL(protection, Class, \
00618 Name, name, plural, \
00619 traits, ExternalType, ExternalTypes) \
00620 private: \
00621 template <class T> \
00622 static bool has_required_attributes_for_##name(Particle *p, \
00623 const T &traits) { \
00624 return traits.has_required_attributes(p); \
00625 } \
00626 template <class T> \
00627 static void add_required_attributes_for_##name(Particle *p, \
00628 const T &traits) { \
00629 return traits.add_required_attributes(p); \
00630 } \
00631 struct Name##AttrArrayAccessor { \
00632 const Class *d_; \
00633 Name##AttrArrayAccessor(const Class *d): d_(d){} \
00634 Name##AttrArrayAccessor(): d_(NULL){} \
00635 typedef ExternalType result_type; \
00636 result_type operator()(unsigned int i) const { \
00637 return d_->get_##name(i); \
00638 } \
00639 bool operator==(const Name##AttrArrayAccessor &o) const { \
00640 return d_== o.d_; \
00641 } \
00642 }; \
00643 protection: \
00644 IMP_NO_SWIG(typedef IMP::internal \
00645 ::IndexingIterator<Name##AttrArrayAccessor> \
00646 Name##Iterator;) \
00647 IMP_NO_SWIG(Name##Iterator plural##_begin() const { \
00648 return Name##Iterator(Name##AttrArrayAccessor(this)); \
00649 } \
00650 Name##Iterator plural##_end() const { \
00651 return Name##Iterator(Name##AttrArrayAccessor(this), \
00652 get_number_of_##plural()); \
00653 }) \
00654 ExternalType get_##name(unsigned int i) const { \
00655 return traits.wrap(traits.get_value(get_particle(), i)); \
00656 } \
00657 unsigned int get_number_of_##plural() const { \
00658 return traits.get_size(get_particle()); \
00659 } \
00660 unsigned int add_##name(ExternalType t) { \
00661 traits.audit_value(t); \
00662 unsigned int i= traits.push_back(get_particle(), \
00663 traits.get_value(t)); \
00664 traits.on_add(get_particle(), t, i); \
00665 return i; \
00666 } \
00667 void add_##name##_at(ExternalType t, unsigned int idx) { \
00668 traits.audit_value(t); \
00669 traits.insert(get_particle(), \
00670 idx, \
00671 traits.get_value(t)); \
00672 traits.on_add(get_particle(), t, idx); \
00673 for (unsigned int i= idx+1; i < get_number_of_##plural(); ++i) { \
00674 traits.on_change(get_particle(), \
00675 traits.get_value( get_particle(), i), \
00676 i-1, i); \
00677 } \
00678 } \
00679 ExternalTypes get_##plural() const { \
00680 ExternalTypes ret; \
00681 for (unsigned int i=0; i< get_number_of_##plural(); ++i) { \
00682 ret.push_back(get_##name(i)); \
00683 } \
00684 return ret; \
00685 } \
00686 void add_##plural(const ExternalTypes &et) { \
00687 for (unsigned int i=0; i< et.size(); ++i) { \
00688 add_##name(et[i]); \
00689 } \
00690 } \
00691 void remove_##name(ExternalType t) { \
00692 traits.audit_value(t); \
00693 unsigned int idx= traits.get_index(get_particle(), t); \
00694 traits.on_remove(get_particle(), t); \
00695 traits.erase(get_particle(), \
00696 idx); \
00697 for (unsigned int i= idx; i < get_number_of_##plural(); ++i) { \
00698 traits.on_change(get_particle(), \
00699 traits.get_value(get_particle(), i), \
00700 i+1, i); \
00701 } \
00702 } \
00703 void clear_##plural() { \
00704 traits.clear(get_particle()); \
00705 }
00706
00707
00708
00709 #ifdef IMP_DOXYGEN
00710
00711
00712
00713 #define IMP_OBJECTS(Name) \
00714 class Name##sTemp {}; \
00715 class Name##s:public Name##sTemp{};
00716 #else
00717 #define IMP_OBJECTS(Name) \
00718 typedef IMP::VectorOfRefCounted<Name*> Name##s; \
00719 typedef std::vector<Name*> Name##sTemp
00720 #endif
00721
00722 #ifdef IMP_DOXYGEN
00723
00724
00725
00726 #define IMP_VALUES(Name) \
00727 class Name##s;
00728 #else
00729 #define IMP_VALUES(Name) \
00730 typedef std::vector<Name> Name##s;
00731 #endif
00732
00733 #ifdef IMP_DOXYGEN
00734
00735
00736
00737
00738
00739
00740
00741
00742
00743
00744
00745
00746
00747 #define IMP_SHOWABLE
00748 #else
00749 #define IMP_SHOWABLE \
00750 void show(std::ostream &out=std::cout) const; \
00751 std::string __str__() const { \
00752 std::ostringstream out; \
00753 show(out); \
00754 return out.str(); \
00755 }
00756 #endif
00757
00758 #ifdef IMP_DOXYGEN
00759
00760
00761
00762
00763
00764
00765
00766
00767
00768
00769 #define IMP_SHOWABLE_INLINE(how_to_show)
00770 #else
00771 #define IMP_SHOWABLE_INLINE(how_to_show) \
00772 void show(std::ostream &out=std::cout) const{ \
00773 how_to_show; \
00774 } \
00775 std::string __str__() const { \
00776 std::ostringstream out; \
00777 show(out); \
00778 return out.str(); \
00779 }
00780 #endif
00781
00782
00783
00784
00785
00786
00787
00788
00789
00790
00791
00792
00793
00794
00795
00796
00797
00798
00799
00800
00801
00802
00803
00804
00805
00806
00807
00808
00809
00810
00811
00812
00813
00814
00815
00816 #define IMP_OBJECT(Name) \
00817 public: \
00818 virtual std::string get_type_name() const {return #Name;} \
00819 virtual ::IMP::VersionInfo get_version_info() const { \
00820 return get_module_version_info(); \
00821 } \
00822 IMP_REF_COUNTED_DESTRUCTOR(Name) \
00823 IMP_NO_DOXYGEN(virtual void do_show(std::ostream &out) const); \
00824 public:
00825
00826
00827
00828
00829
00830
00831
00832
00833
00834 #define IMP_OBJECT_INLINE(Name, show, destructor) \
00835 public: \
00836 virtual std::string get_type_name() const {return #Name;} \
00837 virtual ::IMP::VersionInfo get_version_info() const { \
00838 return get_module_version_info(); \
00839 } \
00840 IMP_NO_DOXYGEN (virtual void do_show(std::ostream &out) const { \
00841 show; \
00842 }); \
00843 ~Name() {destructor;} \
00844 public:
00845
00846
00847
00848
00849
00850 #define IMP_INTERNAL_OBJECT(Name) \
00851 public: \
00852 virtual ::IMP::VersionInfo get_version_info() const { \
00853 return get_module_version_info(); \
00854 } \
00855 virtual std::string get_type_name() const { \
00856 return #Name; \
00857 } \
00858 IMP_REF_COUNTED_DESTRUCTOR(Name); \
00859 private: \
00860 virtual void do_show(std::ostream &out=std::cout) const { \
00861 } \
00862 public:
00863
00864
00865
00866
00867
00868
00869
00870
00871
00872
00873
00874
00875
00876
00877 #define IMP_RESTRAINT(Name) \
00878 virtual double unprotected_evaluate(DerivativeAccumulator *accum) const; \
00879 ContainersTemp get_input_containers() const; \
00880 ParticlesList get_interacting_particles() const; \
00881 ParticlesTemp get_input_particles() const; \
00882 IMP_OBJECT(Name);
00883
00884
00885
00886
00887
00888
00889
00890
00891
00892
00893
00894
00895 #define IMP_INCREMENTAL_RESTRAINT(Name) \
00896 virtual double unprotected_evaluate(DerivativeAccumulator *accum) const; \
00897 virtual bool get_is_incremental() const {return true;} \
00898 virtual double \
00899 unprotected_incremental_evaluate(DerivativeAccumulator *accum) const; \
00900 ContainersTemp get_input_containers() const; \
00901 ParticlesList get_interacting_particles() const; \
00902 ParticlesTemp get_input_particles() const; \
00903 IMP_OBJECT(Name);
00904
00905
00906
00907
00908
00909
00910
00911 #define IMP_OPTIMIZER(Name) \
00912 virtual Float optimize(unsigned int max_steps); \
00913 IMP_OBJECT(Name);
00914
00915
00916
00917
00918
00919
00920
00921 #define IMP_SAMPLER(Name) \
00922 IMP_OBJECT(Name); \
00923 protected: \
00924 ConfigurationSet* do_sample() const;
00925
00926
00927
00928
00929
00930
00931
00932 #define IMP_OPTIMIZER_STATE(Name) \
00933 virtual void update(); \
00934 IMP_OBJECT(Name);
00935
00936
00937
00938
00939
00940
00941
00942
00943
00944
00945
00946
00947 #define IMP_PERIODIC_OPTIMIZER_STATE(Name) \
00948 virtual void update() { \
00949 if (call_number_%(skip_steps_+1) ==0) { \
00950 do_update(update_number_); \
00951 ++update_number_; \
00952 } \
00953 ++call_number_; \
00954 } \
00955 void do_update(unsigned int call_number); \
00956 void set_skip_steps(unsigned int k) { \
00957 skip_steps_=k; \
00958 call_number_=0; \
00959 } \
00960 IMP_OBJECT(Name) \
00961 private: \
00962 ::IMP::internal::Counter skip_steps_, call_number_, update_number_; \
00963 \
00964 \
00965
00966
00967
00968
00969
00970
00971
00972
00973
00974 #define IMP_SCORE_STATE(Name) \
00975 protected: \
00976 virtual void do_before_evaluate(); \
00977 virtual void do_after_evaluate(DerivativeAccumulator *da); \
00978 virtual ContainersTemp get_input_containers() const; \
00979 virtual ContainersTemp get_output_containers() const; \
00980 virtual ParticlesTemp get_input_particles() const; \
00981 virtual ParticlesTemp get_output_particles() const; \
00982 virtual ParticlesList get_interacting_particles() const; \
00983 IMP_OBJECT(Name)
00984
00985
00986
00987
00988
00989
00990
00991 #define IMP_CONSTRAINT(Name) \
00992 protected: \
00993 void do_update_attributes(); \
00994 void do_update_derivatives(DerivativeAccumulator *da); \
00995 IMP_NO_DOXYGEN(void do_before_evaluate() { Name::do_update_attributes();}) \
00996 IMP_NO_DOXYGEN(void do_after_evaluate(DerivativeAccumulator*da) { \
00997 if (da) Name::do_update_derivatives(da);}) \
00998 virtual ContainersTemp get_input_containers() const; \
00999 virtual ContainersTemp get_output_containers() const; \
01000 virtual ParticlesTemp get_input_particles() const; \
01001 virtual ParticlesTemp get_output_particles() const; \
01002 virtual ParticlesList get_interacting_particles() const; \
01003 IMP_OBJECT(Name)
01004
01005
01006
01007
01008
01009
01010
01011
01012
01013
01014 #define IMP_REFINER(Name) \
01015 virtual bool get_can_refine(Particle*) const; \
01016 virtual Particle* get_refined(Particle *, unsigned int) const; \
01017 virtual const ParticlesTemp get_refined(Particle *) const; \
01018 virtual unsigned int get_number_of_refined(Particle *) const; \
01019 virtual ParticlesTemp get_input_particles(Particle *p) const; \
01020 virtual ContainersTemp get_input_containers(Particle *p) const; \
01021 IMP_OBJECT(Name);
01022
01023
01024
01025
01026
01027
01028
01029
01030
01031
01032 #define IMP_SIMPLE_REFINER(Name) \
01033 virtual bool get_can_refine(Particle*) const; \
01034 virtual Particle* get_refined(Particle *, unsigned int) const; \
01035 virtual const ParticlesTemp get_refined(Particle *a) const { \
01036 ParticlesTemp ret(get_number_of_refined(a)); \
01037 for (unsigned int i=0; i< ret.size(); ++i) { \
01038 ret[i]= get_refined(a,i); \
01039 } \
01040 return ret; \
01041 } \
01042 virtual unsigned int get_number_of_refined(Particle *) const; \
01043 virtual ParticlesTemp get_input_particles(Particle *p) const; \
01044 virtual ContainersTemp get_input_containers(Particle *p) const; \
01045 IMP_OBJECT(Name);
01046
01047
01048 #ifndef IMP_DOXYGEN
01049 #define IMP_SINGLETON_SCORE_BASE(Name) \
01050 double evaluate(Particle *a, DerivativeAccumulator *da) const; \
01051 double evaluate(const ParticlesTemp &ps, \
01052 DerivativeAccumulator *da) const { \
01053 double ret=0; \
01054 for (unsigned int i=0; i< ps.size(); ++i) { \
01055 ret+=Name::evaluate(ps[i], da); \
01056 } \
01057 return ret; \
01058 } \
01059 double evaluate_change(Particle *a, \
01060 DerivativeAccumulator *da) const { \
01061 if (get_is_changed(a)) { \
01062 DerivativeAccumulator nda; \
01063 if (da) nda= DerivativeAccumulator(*da, -1); \
01064 double v= Name::evaluate(a->get_prechange_particle(), \
01065 da? &nda:NULL); \
01066 double rv= Name::evaluate(a, da)-v; \
01067 return rv; \
01068 } else { \
01069 return 0; \
01070 } \
01071 } \
01072 double evaluate_change(const ParticlesTemp &ps, \
01073 DerivativeAccumulator *da) const { \
01074 double ret=0; \
01075 for (unsigned int i=0; i< ps.size(); ++i) { \
01076 ret+=Name::evaluate_change(ps[i], da); \
01077 } \
01078 return ret; \
01079 } \
01080 double evaluate_prechange(Particle *a, \
01081 DerivativeAccumulator *da) const { \
01082 return Name::evaluate(a->get_prechange_particle(), \
01083 da); \
01084 } \
01085 double evaluate_prechange(const ParticlesTemp &ps, \
01086 DerivativeAccumulator *da) const { \
01087 double ret=0; \
01088 for (unsigned int i=0; i< ps.size(); ++i) { \
01089 ret+=Name::evaluate_prechange(ps[i], da); \
01090 } \
01091 return ret; \
01092 } \
01093 IMP_OBJECT(Name);
01094 #endif
01095
01096
01097
01098
01099
01100
01101
01102
01103
01104
01105
01106
01107
01108
01109
01110
01111
01112
01113
01114 #define IMP_SINGLETON_SCORE(Name) \
01115 bool get_is_changed(Particle *p) const; \
01116 ParticlesList get_interacting_particles(Particle*) const; \
01117 ParticlesTemp get_input_particles(Particle*) const; \
01118 ContainersTemp get_input_containers(Particle *) const; \
01119 IMP_SINGLETON_SCORE_BASE(Name);
01120
01121
01122
01123
01124
01125
01126
01127
01128
01129
01130
01131 #define IMP_SIMPLE_SINGLETON_SCORE(Name) \
01132 bool get_is_changed(Particle *p) const { \
01133 return p->get_is_changed(); \
01134 } \
01135 ParticlesList get_interacting_particles(Particle*) const { \
01136 return ParticlesList(); \
01137 } \
01138 ParticlesTemp get_input_particles(Particle*p) const { \
01139 return ParticlesTemp(1,p); \
01140 } \
01141 ContainersTemp get_input_containers(Particle *) const { \
01142 return ContainersTemp(); \
01143 } \
01144 IMP_SINGLETON_SCORE_BASE(Name)
01145
01146
01147 #ifndef IMP_DOXYGEN
01148 #define IMP_PAIR_SCORE_BASE(Name) \
01149 double evaluate(const ParticlePair &p, \
01150 DerivativeAccumulator *da) const; \
01151 IMP_NO_DOXYGEN(double evaluate(Particle *a, Particle *b, \
01152 DerivativeAccumulator *da) const { \
01153 return evaluate(ParticlePair(a,b), da); \
01154 }) \
01155 double evaluate(const ParticlePairsTemp &ps, \
01156 DerivativeAccumulator *da) const { \
01157 double ret=0; \
01158 for (unsigned int i=0; i< ps.size(); ++i) { \
01159 ret+=Name::evaluate(ps[i], da); \
01160 } \
01161 return ret; \
01162 } \
01163 double evaluate_change(const ParticlePair &p, \
01164 DerivativeAccumulator *da) const { \
01165 if (get_is_changed(p)){ \
01166 DerivativeAccumulator nda; \
01167 if (da) nda= DerivativeAccumulator(*da, -1); \
01168 double v= Name::evaluate(IMP::internal::prechange(p), \
01169 da? &nda:NULL); \
01170 double rv= Name::evaluate(p, da)-v; \
01171 return rv; \
01172 } else { \
01173 return 0; \
01174 } \
01175 } \
01176 double evaluate_change(const ParticlePairsTemp &ps, \
01177 DerivativeAccumulator *da) const { \
01178 double ret=0; \
01179 for (unsigned int i=0; i< ps.size(); ++i) { \
01180 ret+=Name::evaluate_change(ps[i], da); \
01181 } \
01182 return ret; \
01183 } \
01184 double evaluate_prechange(const ParticlePair &p, \
01185 DerivativeAccumulator *da) const { \
01186 return Name::evaluate(IMP::internal::prechange(p), \
01187 da); \
01188 } \
01189 double evaluate_prechange(const ParticlePairsTemp &ps, \
01190 DerivativeAccumulator *da) const { \
01191 double ret=0; \
01192 for (unsigned int i=0; i< ps.size(); ++i) { \
01193 ret+=Name::evaluate_prechange(ps[i], da); \
01194 } \
01195 return ret; \
01196 } \
01197 IMP_OBJECT(Name);
01198 #endif
01199
01200
01201
01202
01203
01204
01205
01206
01207
01208
01209
01210
01211
01212
01213
01214
01215 #define IMP_PAIR_SCORE(Name) \
01216 bool get_is_changed(const ParticlePair &pp) const; \
01217 ParticlesList get_interacting_particles(const ParticlePair &p) const; \
01218 ParticlesTemp get_input_particles(const ParticlePair &p) const; \
01219 ContainersTemp get_input_containers(const ParticlePair &p) const; \
01220 IMP_PAIR_SCORE_BASE(Name)
01221
01222
01223
01224
01225
01226
01227
01228
01229
01230
01231
01232 #define IMP_SIMPLE_PAIR_SCORE(Name) \
01233 bool get_is_changed(const ParticlePair &p) const { \
01234 return p[0]->get_is_changed() || p[1]->get_is_changed(); \
01235 } \
01236 ParticlesList get_interacting_particles(const ParticlePair &p) const { \
01237 ParticlesTemp r(2); r[0]=p[0]; r[1]=p[1]; \
01238 return ParticlesList(1, r); \
01239 } \
01240 ParticlesTemp get_input_particles(const ParticlePair &p) const { \
01241 ParticlesTemp r(2); r[0]=p[0]; r[1]=p[1]; \
01242 return r; \
01243 } \
01244 ContainersTemp get_input_containers(const ParticlePair &p) const { \
01245 return ContainersTemp(); \
01246 } \
01247 IMP_PAIR_SCORE_BASE(Name); \
01248
01249 #ifndef IMP_DOXYGEN
01250 #define IMP_TRIPLET_SCORE_BASE(Name) \
01251 double evaluate(const ParticleTriplet &p, \
01252 DerivativeAccumulator *da) const; \
01253 double evaluate(const ParticleTripletsTemp &ps, \
01254 DerivativeAccumulator *da) const { \
01255 double ret=0; \
01256 for (unsigned int i=0; i< ps.size(); ++i) { \
01257 ret+=Name::evaluate(ps[i],da); \
01258 } \
01259 return ret; \
01260 } \
01261 IMP_NO_DOXYGEN(double evaluate(Particle *a, Particle *b, Particle *c, \
01262 DerivativeAccumulator *da) const { \
01263 return evaluate(ParticleTriplet(a,b,c), da); \
01264 }) \
01265 double evaluate_change(const ParticleTriplet &p, \
01266 DerivativeAccumulator *da) const { \
01267 if (get_is_changed(p)) { \
01268 DerivativeAccumulator nda; \
01269 if (da) nda= DerivativeAccumulator(*da, -1); \
01270 double v= Name::evaluate(IMP::internal::prechange(p), \
01271 da? &nda:NULL); \
01272 double rv= Name::evaluate(p, da)-v; \
01273 return rv; \
01274 } else { \
01275 return 0; \
01276 } \
01277 } \
01278 double evaluate_change(const ParticleTripletsTemp &ps, \
01279 DerivativeAccumulator *da) const { \
01280 double ret=0; \
01281 for (unsigned int i=0; i< ps.size(); ++i) { \
01282 ret+=Name::evaluate_change(ps[i], da); \
01283 } \
01284 return ret; \
01285 } \
01286 double evaluate_prechange(const ParticleTriplet &p, \
01287 DerivativeAccumulator *da) const { \
01288 return Name::evaluate(p, \
01289 da); \
01290 } \
01291 double evaluate_prechange(const ParticleTripletsTemp &ps, \
01292 DerivativeAccumulator *da) const { \
01293 double ret=0; \
01294 for (unsigned int i=0; i< ps.size(); ++i) { \
01295 ret+=Name::evaluate_prechange(ps[i], da); \
01296 } \
01297 return ret; \
01298 } \
01299 IMP_OBJECT(Name)
01300 #endif
01301
01302
01303
01304
01305
01306
01307
01308
01309
01310
01311
01312
01313
01314
01315
01316
01317 #define IMP_TRIPLET_SCORE(Name) \
01318 bool get_is_changed(const ParticleTriplet &p) const; \
01319 ParticlesList get_interacting_particles(const ParticleTriplet &p) const; \
01320 ParticlesTemp get_input_particles(const ParticleTriplet &p) const; \
01321 ContainersTemp get_input_containers(const ParticleTriplet &p) const; \
01322 IMP_TRIPLET_SCORE_BASE(Name)
01323
01324
01325
01326
01327
01328
01329
01330
01331
01332
01333
01334
01335 #define IMP_SIMPLE_TRIPLET_SCORE(Name) \
01336 bool get_is_changed(const ParticleTriplet &p) const { \
01337 return p[0]->get_is_changed() || p[1]->get_is_changed() \
01338 || p[1]->get_is_changed(); \
01339 } \
01340 ParticlesList get_interacting_particles(const ParticleTriplet &p) const { \
01341 ParticlesTemp r(3); r[0]=p[0]; r[1]=p[1]; r[2]=p[2]; \
01342 return ParticlesList(1,r); \
01343 } \
01344 ParticlesTemp get_input_particles(const ParticleTriplet &p) const { \
01345 ParticlesTemp r(3); r[0]=p[0]; r[1]=p[1]; r[2]=p[2]; \
01346 return r; \
01347 } \
01348 ContainersTemp get_input_containers(const ParticleTriplet &p) const { \
01349 return ContainersTemp(); \
01350 } \
01351 IMP_TRIPLET_SCORE_BASE(Name); \
01352 \
01353 \
01354
01355
01356
01357
01358
01359
01360
01361
01362
01363
01364
01365 #define IMP_QUAD_SCORE(Name) \
01366 double evaluate(const ParticleQuad &p, \
01367 DerivativeAccumulator *da) const; \
01368 double evaluate(Particle *a, Particle *b, Particle *c, Particle *d, \
01369 DerivativeAccumulator *da) const { \
01370 return evaluate(ParticleQuad(a,b,c,d), da); \
01371 } \
01372 double evaluate(const ParticleQuadsTemp &ps, \
01373 DerivativeAccumulator *da) const { \
01374 double ret=0; \
01375 for (unsigned int i=0; i< ps.size(); ++i) { \
01376 ret+=Name::evaluate(ps[i], da); \
01377 } \
01378 return ret; \
01379 } \
01380 double evaluate_change(const ParticleQuad &p, \
01381 DerivativeAccumulator *da) const { \
01382 if (IMP::internal::is_dirty(p)) { \
01383 DerivativeAccumulator nda; \
01384 if (da) nda= DerivativeAccumulator(*da, -1); \
01385 double v= Name::evaluate(IMP::internal::prechange(p), \
01386 da? &nda:NULL); \
01387 double rv= Name::evaluate(p, da)-v; \
01388 return rv; \
01389 } else { \
01390 return 0; \
01391 } \
01392 } \
01393 double evaluate_change(const ParticleQuadsTemp &ps, \
01394 DerivativeAccumulator *da) const { \
01395 double ret=0; \
01396 for (unsigned int i=0; i< ps.size(); ++i) { \
01397 ret+=Name::evaluate_change(ps[i], da); \
01398 } \
01399 return ret; \
01400 } \
01401 double evaluate_prechange(const ParticleQuad &p, \
01402 DerivativeAccumulator *da) const { \
01403 return Name::evaluate(IMP::internal::prechange(p), \
01404 da); \
01405 } \
01406 double evaluate_prechange(const ParticleQuadsTemp &ps, \
01407 DerivativeAccumulator *da) const { \
01408 double ret=0; \
01409 for (unsigned int i=0; i< ps.size(); ++i) { \
01410 ret+=Name::evaluate_prechange(ps[i], da); \
01411 } \
01412 return ret; \
01413 } \
01414 bool get_is_changed(const ParticleQuad &p) const; \
01415 ParticlesList get_interacting_particles(const ParticleQuad &p) const; \
01416 ParticlesTemp get_input_particles(const ParticleQuad &p) const; \
01417 ContainersTemp get_input_containers(const ParticleQuad &p) const; \
01418 IMP_OBJECT(Name);
01419
01420
01421
01422
01423
01424
01425
01426
01427
01428
01429
01430 #define IMP_SINGLETON_MODIFIER(Name) \
01431 void apply(Particle *a) const; \
01432 void apply(Particle *a, DerivativeAccumulator&) const{ \
01433 apply(a); \
01434 } \
01435 void apply(const ParticlesTemp &ps) const { \
01436 for (unsigned int i=0; i< ps.size(); ++i) { \
01437 Name::apply(ps[i]); \
01438 } \
01439 } \
01440 void apply(const ParticlesTemp &ps, DerivativeAccumulator &) const { \
01441 for (unsigned int i=0; i< ps.size(); ++i) { \
01442 Name::apply(ps[i]); \
01443 } \
01444 } \
01445 ParticlesList get_interacting_particles(Particle*) const; \
01446 ParticlesTemp get_input_particles(Particle*) const; \
01447 ParticlesTemp get_output_particles(Particle*) const; \
01448 ContainersTemp get_input_containers(Particle*) const; \
01449 ContainersTemp get_output_containers(Particle*) const; \
01450 IMP_OBJECT(Name);
01451
01452
01453
01454
01455
01456
01457
01458
01459
01460
01461
01462 #define IMP_PAIR_MODIFIER(Name) \
01463 void apply(const ParticlePair &p) const; \
01464 void apply(const ParticlePair &p, DerivativeAccumulator&) const{ \
01465 apply(p); \
01466 } \
01467 void apply(const ParticlePairsTemp &ps) const { \
01468 for (unsigned int i=0; i< ps.size(); ++i) { \
01469 Name::apply(ps[i]); \
01470 } \
01471 } \
01472 void apply(const ParticlePairsTemp &ps, \
01473 DerivativeAccumulator &) const { \
01474 for (unsigned int i=0; i< ps.size(); ++i) { \
01475 Name::apply(ps[i]); \
01476 } \
01477 } \
01478 ParticlesList get_interacting_particles(const ParticlePair &p) const; \
01479 ParticlesTemp get_input_particles(const ParticlePair &p) const; \
01480 ParticlesTemp get_output_particles(const ParticlePair &p) const; \
01481 ContainersTemp get_input_containers(const ParticlePair &p) const; \
01482 ContainersTemp get_output_containers(const ParticlePair &p) const; \
01483 IMP_OBJECT(Name);
01484
01485
01486
01487
01488
01489
01490
01491
01492
01493
01494
01495
01496 #define IMP_SINGLETON_MODIFIER_DA(Name) \
01497 void apply(Particle *a, DerivativeAccumulator &da) const; \
01498 void apply(Particle *) const{ \
01499 IMP_LOG(VERBOSE, "This modifier requires a derivative accumulator " \
01500 << *this << std::endl); \
01501 } \
01502 void apply(const ParticlesTemp &ps) const { \
01503 IMP_LOG(VERBOSE, "This modifier requires a derivative accumulator " \
01504 << *this << std::endl); \
01505 } \
01506 void apply(const ParticlesTemp &ps, \
01507 DerivativeAccumulator &da) const { \
01508 for (unsigned int i=0; i< ps.size(); ++i) { \
01509 Name::apply(ps[i], da); \
01510 } \
01511 } \
01512 ParticlesList get_interacting_particles(Particle*) const; \
01513 ParticlesTemp get_input_particles(Particle*) const; \
01514 ParticlesTemp get_output_particles(Particle*) const; \
01515 ContainersTemp get_input_containers(Particle*) const; \
01516 ContainersTemp get_output_containers(Particle*) const; \
01517 IMP_OBJECT(Name);
01518
01519
01520
01521
01522
01523
01524
01525
01526
01527
01528
01529
01530 #define IMP_SINGLETON_MODIFIER_FROM_REFINED(Name, refiner) \
01531 ParticlesList Name::get_interacting_particles(Particle *p) const { \
01532 ParticlesTemp pt= refiner->get_input_particles(p); \
01533 return ParticlesList(1,pt); \
01534 } \
01535 ParticlesTemp Name::get_input_particles(Particle *p) const { \
01536 ParticlesTemp ret= refiner->get_refined(p); \
01537 ParticlesTemp ret1= refiner->get_input_particles(p); \
01538 ret.insert(ret.end(), ret1.begin(), ret1.end()); \
01539 return ret; \
01540 } \
01541 ParticlesTemp Name::get_output_particles(Particle *p) const { \
01542 ParticlesTemp ret(1,p); \
01543 return ret; \
01544 } \
01545 ContainersTemp Name::get_input_containers(Particle *p) const { \
01546 return refiner->get_input_containers(p); \
01547 } \
01548 ContainersTemp Name::get_output_containers(Particle *p) const { \
01549 return ContainersTemp(); \
01550 } \
01551 IMP_NO_DOXYGEN(void Name::do_show(std::ostream &out) const { \
01552 out <<"refiner " << *refiner << std::endl; \
01553 }) \
01554 \
01555 \
01556
01557
01558
01559
01560
01561
01562
01563
01564
01565
01566
01567
01568
01569 #define IMP_SINGLETON_MODIFIER_TO_REFINED(Name, refiner) \
01570 ParticlesList Name::get_interacting_particles(Particle *p) const { \
01571 ParticlesTemp pt= refiner->get_refined(p); \
01572 return ParticlesList(1,pt); \
01573 } \
01574 ParticlesTemp Name::get_input_particles(Particle *p) const { \
01575 ParticlesTemp ret= refiner->get_input_particles(p); \
01576 ParticlesTemp ret2= refiner->get_refined(p); \
01577 ret.push_back(p); \
01578 ret.insert(ret.end(), ret2.begin(), ret2.end()); \
01579 return ret; \
01580 } \
01581 ParticlesTemp Name::get_output_particles(Particle *p) const { \
01582 ParticlesTemp ret= refiner->get_refined(p); \
01583 return ret; \
01584 } \
01585 ContainersTemp Name::get_input_containers(Particle *p) const { \
01586 return refiner->get_input_containers(p); \
01587 } \
01588 ContainersTemp Name::get_output_containers(Particle *p) const { \
01589 return ContainersTemp(); \
01590 } \
01591 IMP_NO_DOXYGEN(void Name::do_show(std::ostream &out) const { \
01592 out << "refiner " << *refiner << std::endl; \
01593 }) \
01594 \
01595 \
01596
01597
01598
01599
01600
01601
01602
01603
01604 #define IMP_PAIR_MODIFIER_DA(Name) \
01605 void apply(const ParticlePair &p, DerivativeAccumulator *da) const; \
01606 void apply(const ParticlePair &p) const{ \
01607 IMP_LOG(VERBOSE, "This modifier requires a derivative accumulator " \
01608 << *this << std::endl); \
01609 } \
01610 void apply(const ParticlePairsTemp &ps) const { \
01611 IMP_LOG(VERBOSE, "This modifier requires a derivative accumulator " \
01612 << *this << std::endl); \
01613 } \
01614 void apply(const ParticlePairsTemp &ps, \
01615 DerivativeAccumulator &da) const { \
01616 for (unsigned int i=0; i< ps.size(); ++i) { \
01617 Name::apply(ps[i], da); \
01618 } \
01619 } \
01620 ParticlesList get_interacting_particles(const ParticlePair &p) const; \
01621 ParticlesTemp get_input_particles(const ParticlePair &p) const; \
01622 ParticlesTemp get_output_particles(const ParticlePair &p) const; \
01623 ContainersTemp get_input_containers(const ParticlePair &p) const; \
01624 ContainersTemp get_output_containers(const ParticlePair &p) const; \
01625 IMP_OBJECT(Name)
01626
01627
01628
01629
01630
01631
01632
01633
01634
01635
01636
01637
01638
01639
01640
01641 #define IMP_INTERNAL_SINGLETON_MODIFIER(Name, \
01642 apply_expr) \
01643 void apply(Particle *p) const { \
01644 apply_expr; \
01645 } \
01646 void apply(Particle *a, DerivativeAccumulator&) const{ \
01647 apply(a); \
01648 } \
01649 void apply(const ParticlesTemp &ps) const { \
01650 for (unsigned int i=0; i< ps.size(); ++i) { \
01651 Name::apply(ps[i]); \
01652 } \
01653 } \
01654 void apply(const ParticlesTemp &ps, DerivativeAccumulator &) const { \
01655 for (unsigned int i=0; i< ps.size(); ++i) { \
01656 Name::apply(ps[i]); \
01657 } \
01658 } \
01659 ParticlesList get_interacting_particles(Particle*) const { \
01660 return ParticlesList(); \
01661 } \
01662 ParticlesTemp get_input_particles(Particle*p) const { \
01663 return ParticlesTemp(1,p); \
01664 } \
01665 ParticlesTemp get_output_particles(Particle*p) const { \
01666 return ParticlesTemp(1,p); \
01667 } \
01668 ContainersTemp get_input_containers(Particle*p) const { \
01669 return ContainersTemp(); \
01670 } \
01671 ContainersTemp get_output_containers(Particle*p) const { \
01672 return ContainersTemp(); \
01673 } \
01674 IMP_INTERNAL_OBJECT(Name);
01675
01676
01677
01678
01679
01680
01681
01682
01683
01684
01685
01686
01687 #define IMP_SINGLETON_CONTAINER(Name) \
01688 bool get_contains_particle(Particle* p) const; \
01689 unsigned int get_number_of_particles() const; \
01690 Particle* get_particle(unsigned int i) const; \
01691 void apply(const SingletonModifier *sm); \
01692 void apply(const SingletonModifier *sm, \
01693 DerivativeAccumulator &da); \
01694 double evaluate(const SingletonScore *s, \
01695 DerivativeAccumulator *da) const; \
01696 double evaluate_change(const SingletonScore *s, \
01697 DerivativeAccumulator *da) const; \
01698 double evaluate_prechange(const SingletonScore *s, \
01699 DerivativeAccumulator *da) const; \
01700 ParticlesTemp get_contained_particles() const; \
01701 bool get_contained_particles_changed() const; \
01702 ContainersTemp get_input_containers() const; \
01703 IMP_OBJECT(Name);
01704
01705
01706
01707
01708
01709
01710
01711
01712
01713
01714
01715 #define IMP_PAIR_CONTAINER(Name) \
01716 bool get_contains_particle_pair(const ParticlePair &p) const; \
01717 unsigned int get_number_of_particle_pairs() const; \
01718 ParticlePair get_particle_pair(unsigned int i) const; \
01719 void apply(const PairModifier *sm); \
01720 void apply(const PairModifier *sm, \
01721 DerivativeAccumulator &da); \
01722 double evaluate(const PairScore *s, \
01723 DerivativeAccumulator *da) const; \
01724 double evaluate_change(const PairScore *s, \
01725 DerivativeAccumulator *da) const; \
01726 double evaluate_prechange(const PairScore *s, \
01727 DerivativeAccumulator *da) const; \
01728 ParticlesTemp get_contained_particles() const; \
01729 bool get_contained_particles_changed() const; \
01730 ContainersTemp get_input_containers() const; \
01731 IMP_OBJECT(Name)
01732
01733
01734
01735
01736
01737
01738
01739
01740
01741
01742
01743
01744 #define IMP_TRIPLET_CONTAINER(Name) \
01745 bool get_contains_particle_triplet(const ParticleTriplet &p) const; \
01746 unsigned int get_number_of_particle_triplets() const; \
01747 ParticleTriplet get_particle_triplet(unsigned int i) const; \
01748 void apply(const TripletModifier *sm); \
01749 void apply(const TripletModifier *sm, \
01750 DerivativeAccumulator &da); \
01751 double evaluate(const TripletScore *s, \
01752 DerivativeAccumulator *da) const; \
01753 double evaluate_change(const TripletScore *s, \
01754 DerivativeAccumulator *da) const; \
01755 double evaluate_prechange(const TripletScore *s, \
01756 DerivativeAccumulator *da) const; \
01757 ParticlesTemp get_contained_particles() const; \
01758 bool get_contained_particles_changed() const; \
01759 ContainersTemp get_input_containers() const; \
01760 IMP_OBJECT(Name)
01761
01762
01763
01764
01765
01766
01767
01768
01769
01770
01771
01772
01773 #define IMP_QUAD_CONTAINER(Name) \
01774 bool get_contains_particle_quad(const ParticleQuad &p) const; \
01775 unsigned int get_number_of_particle_quads() const; \
01776 ParticleQuad get_particle_quad(unsigned int i) const; \
01777 void apply(const QuadModifier *sm); \
01778 void apply(const QuadModifier *sm, \
01779 DerivativeAccumulator &da); \
01780 double evaluate(const QuadScore *s, \
01781 DerivativeAccumulator *da) const; \
01782 double evaluate_change(const QuadScore *s, \
01783 DerivativeAccumulator *da) const; \
01784 double evaluate_prechange(const QuadScore *s, \
01785 DerivativeAccumulator *da) const; \
01786 ParticlesTemp get_contained_particles() const; \
01787 bool get_contained_particles_changed() const; \
01788 ContainersTemp get_input_containers() const; \
01789 IMP_OBJECT(Name)
01790
01791
01792
01793
01794
01795
01796
01797
01798
01799 #define IMP_SINGLETON_FILTER(Name) \
01800 bool get_contains_particle(Particle* p) const; \
01801 ParticlesTemp get_input_particles(Particle*t) const; \
01802 ObjectsTemp get_input_objects(Particle*t) const; \
01803 IMP_OBJECT(Name)
01804
01805
01806
01807
01808
01809
01810
01811 #define IMP_PAIR_FILTER(Name) \
01812 bool get_contains_particle_pair(const ParticlePair& p) const; \
01813 ParticlesTemp get_input_particles(const ParticlePair& t) const; \
01814 ObjectsTemp get_input_objects(const ParticlePair& t) const; \
01815 IMP_OBJECT(Name);
01816
01817
01818
01819
01820
01821
01822
01823
01824 #define IMP_TRIPLET_FILTER(Name) \
01825 bool get_contains_particle_triplet(ParticleTriplet p) const; \
01826 ParticlesTemp get_input_particles(ParticleTriplet t) const; \
01827 ObjectsTemp get_input_objects(ParticleTriplet t) const; \
01828 IMP_OBJECT(Name);
01829
01830
01831
01832
01833
01834
01835
01836
01837 #define IMP_QUAD_FILTER(Name) \
01838 bool get_contains_particle_quad(ParticleQuad p) const; \
01839 ParticlesTemp get_input_particles(ParticleQuad t) const; \
01840 ObjectsTemp get_input_objects(ParticleQuad t) const; \
01841 IMP_OBJECT(Name);
01842
01843
01844
01845
01846
01847
01848
01849
01850
01851
01852 #define IMP_UNARY_FUNCTION(Name) \
01853 virtual DerivativePair evaluate_with_derivative(double feature) const; \
01854 virtual double evaluate(double feature) const; \
01855 IMP_OBJECT(Name)
01856
01857
01858
01859
01860
01861
01862
01863
01864
01865
01866
01867
01868
01869
01870 #define IMP_UNARY_FUNCTION_INLINE(Name, value_expression, \
01871 derivative_expression, show_expression) \
01872 virtual DerivativePair evaluate_with_derivative(double feature) const { \
01873 return DerivativePair((value_expression), (derivative_expression)); \
01874 } \
01875 virtual double evaluate(double feature) const { \
01876 return (value_expression); \
01877 } \
01878 IMP_OBJECT_INLINE(Name, out << show_expression, )
01879
01880
01881
01882
01883
01884
01885
01886 #define IMP_FAILURE_HANDLER(Name) \
01887 void handle_failure(); \
01888 IMP_OBJECT(Name)
01889
01890
01891
01892
01893
01894
01895
01896
01897
01898
01899
01900
01901
01902
01903 #define IMP_RAII(Name, args, Initialize, Set, Reset) \
01904 Name() {Initialize;} \
01905 explicit Name args {Initialize; Set} \
01906 void set args {reset(); \
01907 Set;} \
01908 void reset() {Reset;} \
01909 ~Name () {reset();}
01910
01911
01912
01913
01914
01915
01916
01917
01918
01919
01920
01921
01922
01923 #define IMP_NEW(Typename, varname, args) \
01924 IMP::Pointer<Typename> varname(new Typename args)
01925
01926 #ifdef IMP_DOXYGEN
01927
01928
01929
01930
01931
01932
01933
01934
01935
01936
01937
01938
01939
01940
01941
01942 #define IMP_DECLARE_KEY_TYPE(Name, Tag) \
01943 class Name { \
01944 public: \
01945 Name(std::string nm); \
01946 }; \
01947 typedef std::vector<Name> Name##s
01948
01949 #else
01950 #define IMP_DECLARE_KEY_TYPE(Name, Tag) \
01951 struct Name: public ::IMP::KeyBase<Tag, true> { \
01952 typedef ::IMP::KeyBase<Tag, true> P; \
01953 typedef Name This; \
01954 Name(){}; \
01955 explicit Name(unsigned int i): P(i){} \
01956 Name(std::string nm): P(nm){} \
01957 static Name add_alias(Name nm, std::string new_name) { \
01958 ::IMP::KeyBase<Tag, true>:: add_alias(nm, new_name); \
01959 IMP_INTERNAL_CHECK(Name(new_name) == nm, \
01960 "Keys don't match after alias."); \
01961 return Name(new_name); \
01962 } \
01963 std::string __str__() const {return get_string();} \
01964 }; \
01965 typedef std::vector<Name> Name##s
01966 #endif
01967
01968 #ifdef IMP_DOXYGEN
01969
01970
01971
01972
01973
01974 #define IMP_DECLARE_CONTROLLED_KEY_TYPE(Name, Tag) \
01975 class Name { \
01976 public: \
01977 Name(std::string nm); \
01978 }; \
01979 typedef std::vector<Name> Name##s
01980
01981 #else
01982 #define IMP_DECLARE_CONTROLLED_KEY_TYPE(Name, Tag) \
01983 struct Name: public ::IMP::KeyBase<Tag, false> { \
01984 typedef ::IMP::KeyBase<Tag, false> P; \
01985 typedef Name This; \
01986 Name(){}; \
01987 Name(unsigned int i): P(i){} \
01988 Name(std::string nm): P(nm){} \
01989 static Name add_alias(Name nm, std::string new_name) { \
01990 ::IMP::KeyBase<Tag, false>:: add_alias(nm, new_name); \
01991 IMP_INTERNAL_CHECK(Name(new_name) == nm, \
01992 "Keys don't match after alias."); \
01993 return Name(nm.get_index()); \
01994 } \
01995 }; \
01996 typedef std::vector<Name> Name##s
01997 #endif
01998
01999 #ifndef IMP_DOXYGEN
02000
02001
02002 #ifdef __GNU__
02003 #define IMP_NO_SIDEEFFECTS __attribute__ ((pure))
02004 #else
02005 #define IMP_NO_SIDEEFFECTS
02006 #endif
02007
02008
02009
02010
02011 #ifdef __GNU__
02012 #define IMP_WARN_UNUSED_RESULT __attribute__ ((warn_unused_result))
02013 #else
02014 #define IMP_WARN_UNUSED_RESULT
02015 #endif
02016
02017 #endif
02018
02019 #endif