00001
00002
00003
00004
00005
00006
00007
00008
00009 #ifndef IMPATOM_HIERARCHY_H
00010 #define IMPATOM_HIERARCHY_H
00011
00012 #include "atom_config.h"
00013 #include <IMP/core/utility.h>
00014 #include <IMP/core/Hierarchy.h>
00015 #include "bond_decorators.h"
00016 #include "atom_macros.h"
00017 #include <IMP/core/XYZR.h>
00018 #include <IMP/core/rigid_bodies.h>
00019
00020 #include <IMP/Particle.h>
00021 #include <IMP/Model.h>
00022
00023 #include <vector>
00024 #include <deque>
00025
00026
00027 #define IMP_GET_AS_DECL(UCName, lcname, CAPSNAME) \
00028 UCName get_as_##lcname() const;
00029
00030
00031 #define IMP_GET_AS_DEF(UCName, lcname, CAPSNAME) \
00032 UCName Hierarchy::get_as_##lcname() const { \
00033 if (UCName::particle_is_instance(get_particle())) { \
00034 return UCName(get_particle()); \
00035 } else { \
00036 return UCName(); \
00037 } \
00038 }
00039
00040
00041
00042
00043 #define IMP_FOREACH_HIERARCHY_TYPE(macro) \
00044 macro(Atom, atom, ATOM_TYPE) \
00045 macro(Residue, residue, RESIDUE_TYPE) \
00046 macro(Chain, chain, CHAIN_TYPE) \
00047 macro(Domain, domain, DOMAIN_TYPE) \
00048 macro(Fragment, fragment, FRAGMENT_TYPE) \
00049 macro(core::XYZ, xyz, XYZ_TYPE) \
00050 macro(core::XYZR, xyzr, XYZR_TYPE) \
00051 macro(Mass, mass, MASS_TYPE)
00052
00053 #define IMP_CAPS_NAME(UCName, lcname, CAPSNAME) \
00054 CAPSNAME,
00055
00056
00057 IMPATOM_BEGIN_NAMESPACE
00058 class Atom;
00059 class Residue;
00060 class Domain;
00061 class Fragment;
00062 class Chain;
00063 class Mass;
00064
00065 class Hierarchy;
00066
00067 #ifndef SWIG
00068 #ifdef IMP_DOXYGEN
00069
00070
00071
00072
00073
00074 class Hierarchies: public HierarchiesTemp {};
00075
00076
00077
00078
00079
00080
00081 class HierarchiesTemp: public IMP::core::GenericHierarchiesTemp {};
00082
00083 #else
00084 typedef IMP::DecoratorsWithImplicitTraits< Hierarchy,
00085 IMP::core::GenericHierarchies> Hierarchies;
00086 typedef IMP::DecoratorsWithImplicitTraits< Hierarchy,
00087 IMP::core::GenericHierarchiesTemp> HierarchiesTemp;
00088 #endif
00089
00090 #else
00091 class Hierarchies: public IMP::core::GenericHierarchies {
00092 public:
00093 Hierarchies(Hierarchy h);
00094 Hierarchies();
00095 Hierarchies(const Particles &ps);
00096 const Particles &get_particles() const;
00097 void push_back(Hierarchy d);
00098 void push_back(Particle *p);
00099 Hierarchy back() const;
00100 Hierarchy front() const;
00101 };
00102 class HierarchiesTemp: public IMP::core::GenericHierarchiesTemp {
00103 public:
00104 HierarchiesTemp(Hierarchy h);
00105 HierarchiesTemp(Hierarchies h);
00106 HierarchiesTemp();
00107 HierarchiesTemp(const Particles &ps);
00108 const Particles &get_particles() const;
00109 void push_back(Hierarchy d);
00110 void push_back(Particle *p);
00111 Hierarchy back() const;
00112 Hierarchy front() const;
00113 };
00114 #endif
00115
00116
00117
00118
00119
00120
00121
00122
00123
00124
00125
00126
00127
00128
00129
00130
00131
00132
00133
00134
00135
00136
00137
00138
00139
00140
00141
00142
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154
00155
00156
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172
00173
00174
00175
00176
00177
00178
00179
00180
00181
00182
00183
00184
00185
00186
00187
00188
00189
00190
00191
00192
00193
00194
00195
00196
00197
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208
00209
00210
00211
00212
00213
00214
00215
00216
00217
00218
00219 class IMPATOMEXPORT Hierarchy: public ::IMP::core::Hierarchy
00220 {
00221 typedef ::IMP::core::Hierarchy P;
00222 public:
00223
00224
00225 IMP_NO_DOXYGEN(typedef Hierarchy This);
00226
00227
00228 Hierarchy(IMP::core::Hierarchy h): P(h) {
00229 IMP_USAGE_CHECK(h.get_traits() == get_traits(),
00230 "Cannot construct a IMP.atom.Hierarchy from a general "
00231 " IMP.core.Hierarchy");
00232 }
00233
00234 explicit Hierarchy(Particle *p):
00235 P(p,get_traits()){
00236 IMP_INTERNAL_CHECK(particle_is_instance(p),
00237 "Missing required attributes for "
00238 << "Hierarchy" << *p);
00239 }
00240
00241
00242 Hierarchy() {}
00243
00244
00245 static Hierarchy decorate_particle(Particle *p) {
00246 IMP::core::Hierarchy::decorate_particle(p, get_traits());
00247 return Hierarchy(p);
00248 }
00249
00250
00251
00252 static Hierarchy setup_particle(Particle *p) {
00253 IMP::core::Hierarchy::setup_particle(p, get_traits());
00254 return Hierarchy(p);
00255 }
00256
00257
00258
00259 static bool particle_is_instance(Particle *p){
00260 return P::particle_is_instance(p, get_traits());
00261 }
00262
00263
00264
00265 void show(std::ostream &out=std::cout) const;
00266
00267
00268
00269
00270
00271
00272 bool get_is_valid(bool print_info) const;
00273
00274
00275
00276
00277
00278 unsigned int add_child(Hierarchy o) {
00279 IMP_USAGE_CHECK(o.get_particle()->get_model()
00280 == get_particle()->get_model(),
00281 "All particles in hierarchy must have same Model");
00282 unsigned int ret= P::add_child(o);
00283 return ret;
00284 }
00285
00286
00287
00288
00289
00290 void add_child_at(Hierarchy o, unsigned int i) {
00291 IMP_USAGE_CHECK(o.get_particle()->get_model()
00292 == get_particle()->get_model(),
00293 "All particles in hierarchy must have same Model");
00294 P::add_child_at(o, i);
00295 }
00296
00297
00298 Hierarchy get_child(unsigned int i) const {
00299 IMP::core::Hierarchy hd= P::get_child(i);
00300 return decorate_particle(hd.get_particle());
00301 }
00302 HierarchiesTemp get_children() const {
00303 return HierarchiesTemp(IMP::core::Hierarchy::get_children());
00304 }
00305
00306
00307 Hierarchy get_parent() const {
00308 IMP::core::Hierarchy hd= P::get_parent();
00309 if (hd == Hierarchy()) {
00310 return Hierarchy();
00311 } else {
00312 return decorate_particle(hd.get_particle());
00313 }
00314 }
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325 IMP_FOREACH_HIERARCHY_TYPE(IMP_GET_AS_DECL);
00326
00327
00328
00329 static const IMP::core::HierarchyTraits& get_traits();
00330
00331 };
00332
00333 IMP_OUTPUT_OPERATOR(Hierarchy);
00334
00335
00336
00337 #ifdef IMP_DOXYGEN
00338 enum GetByType {ATOM_TYPE, RESIDUE_TYPE, CHAIN_TYPE, DOMAIN_TYPE, FRAGMENT_TYPE,
00339 XYZ_TYPE,XYZR_TYPE,MASS_TYPE};
00340 #else
00341 enum GetByType {
00342 IMP_FOREACH_HIERARCHY_TYPE(IMP_CAPS_NAME)
00343 };
00344 #endif
00345
00346
00347
00348
00349
00350
00351
00352 IMPATOMEXPORT HierarchiesTemp
00353 get_by_type(Hierarchy mhd, GetByType t);
00354
00355
00356
00357
00358
00359
00360
00361
00362
00363
00364
00365
00366
00367
00368
00369
00370 IMPATOMEXPORT Hierarchy
00371 get_residue(Hierarchy mhd, unsigned int index);
00372
00373
00374
00375
00376
00377
00378
00379
00380
00381
00382
00383
00384 IMPATOMEXPORT Hierarchy
00385 create_fragment(const HierarchiesTemp &ps);
00386
00387
00388
00389
00390
00391
00392 IMPATOMEXPORT Bonds
00393 get_internal_bonds(Hierarchy mhd);
00394
00395
00396
00397
00398 inline Hierarchy get_root(Hierarchy h) {
00399 while (h.has_parent()) {
00400 h= h.get_parent();
00401 }
00402 return h;
00403 }
00404
00405
00406 inline HierarchiesTemp get_leaves(Hierarchy h) {
00407 return HierarchiesTemp(IMP::core::get_leaves(h));
00408 }
00409
00410
00411
00412
00413 inline void show(Hierarchy h, std::ostream &out=std::cout) {
00414 IMP::core::show<Hierarchy>(h, out);
00415 }
00416
00417
00418
00419
00420
00421
00422
00423
00424
00425
00426
00427 IMPATOMEXPORT IMP::core::RigidBody setup_as_rigid_body(Hierarchy h);
00428
00429
00430
00431
00432
00433
00434
00435
00436
00437 IMPATOMEXPORT bool get_is_heterogen(Hierarchy h);
00438
00439
00440
00441
00442
00443
00444
00445
00446 IMPATOMEXPORT
00447 Hierarchy create_clone(Hierarchy d);
00448
00449
00450
00451
00452
00453
00454
00455 IMPATOMEXPORT
00456 Hierarchy create_clone_one(Hierarchy d);
00457
00458
00459
00460
00461
00462
00463
00464
00465 IMPATOMEXPORT
00466 void destroy(Hierarchy d);
00467
00468
00469
00470
00471
00472
00473
00474
00475
00476
00477
00478
00479
00480 IMPATOMEXPORT
00481 algebra::BoundingBoxD<3> get_bounding_box(const Hierarchy &h);
00482
00483
00484
00485
00486
00487 IMPATOMEXPORT
00488 algebra::SphereD<3> get_bounding_sphere(const Hierarchy &h);
00489
00490
00491 IMPATOM_END_NAMESPACE
00492
00493
00494 #endif