00001
00002
00003
00004
00005
00006
00007
00008 #ifndef IMPATOM_BOND_DECORATORS_H
00009 #define IMPATOM_BOND_DECORATORS_H
00010
00011 #include "atom_config.h"
00012 #include <IMP/core/internal/graph_base.h>
00013 #include "internal/bond_helpers.h"
00014
00015 #include <IMP/Particle.h>
00016 #include <IMP/Model.h>
00017 #include <IMP/Decorator.h>
00018
00019 #include <IMP/internal/IndexingIterator.h>
00020 IMPATOM_BEGIN_NAMESPACE
00021
00022 class Bond;
00023 class Bonded;
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038 class IMPATOMEXPORT Bond: public Decorator
00039 {
00040 friend class Bonded;
00041 public:
00042 IMP_DECORATOR(Bond, Decorator);
00043
00044
00045 static bool particle_is_instance(Particle *p) {
00046 return IMP::core::internal::graph_is_edge(p,
00047 internal::get_bond_data().graph_);
00048 }
00049
00050
00051 enum Type {UNKNOWN=-1,
00052 NONBIOLOGICAL, SINGLE=1, DOUBLE=2, TRIPLE=3, HYDROGEN,
00053 SALT, PEPTIDE,
00054 AMIDE, AROMATIC,
00055 };
00056
00057
00058
00059
00060
00061 Bonded get_bonded(unsigned int i) const ;
00062
00063 IMP_DECORATOR_GET_SET_OPT(type,
00064 internal::get_bond_data().type_, Int, Int,
00065 UNKNOWN);
00066
00067 IMP_DECORATOR_GET_SET_OPT(order,
00068 internal::get_bond_data().order_,
00069 Int, Int, 1);
00070
00071 IMP_DECORATOR_GET_SET_OPT(length,
00072 internal::get_bond_data().length_, Float,
00073 Float, -1);
00074 IMP_DECORATOR_GET_SET_OPT(stiffness,
00075 internal::get_bond_data().stiffness_,
00076 Float,
00077 Float, -1);
00078
00079 static FloatKey get_length_key() {
00080 return internal::get_bond_data().length_;
00081 }
00082 };
00083
00084 IMP_OUTPUT_OPERATOR(Bond);
00085
00086
00087
00088
00089
00090
00091
00092 class IMPATOMEXPORT Bonded: public Decorator
00093 {
00094 struct GetBond {
00095 typedef Bond result_type;
00096 Particle* d_;
00097 GetBond():d_(NULL){}
00098 GetBond(Particle* d): d_(d){}
00099 Bond operator()(unsigned int i) const;
00100 bool operator==(const GetBond &o) const {
00101 return d_== o.d_;
00102 }
00103 };
00104 struct GetBonded {
00105 typedef Bonded result_type;
00106 Particle* d_;
00107 GetBonded():d_(NULL){}
00108 GetBonded(Particle* d): d_(d){}
00109 Bonded operator()(unsigned int i) const;
00110 bool operator==(const GetBonded &o) const {
00111 return d_== o.d_;
00112 }
00113 };
00114 public:
00115 IMP_DECORATOR(Bonded, Decorator);
00116
00117 static bool particle_is_instance(Particle *p) {
00118 return IMP::core::internal::graph_is_node(p,
00119 internal::get_bond_data().graph_);
00120 }
00121
00122 static Bonded setup_particle(Particle *p) {
00123 graph_initialize_node(p, internal::get_bond_data().graph_);
00124 return Bonded(p);
00125 }
00126
00127
00128 unsigned int get_number_of_bonds() const {
00129 return graph_get_number_of_edges(get_particle(),
00130 internal::get_bond_data().graph_);
00131 }
00132
00133
00134
00135
00136
00137
00138 Bond get_bond(unsigned int i) const {
00139 Particle *p= graph_get_edge(get_particle(), i,
00140 internal::get_bond_data().graph_);
00141 return Bond(p);
00142 }
00143
00144
00145
00146
00147
00148
00149
00150
00151
00152
00153
00154 Bonded get_bonded(unsigned int i) const {
00155 Particle *p= graph_get_edge(get_particle(), i,
00156 internal::get_bond_data().graph_);
00157 Bond bd(p);
00158 if (bd.get_bonded(0) == *this) return bd.get_bonded(1);
00159 else return bd.get_bonded(0);
00160 }
00161
00162
00163
00164
00165 #ifdef IMP_DOXYGEN
00166 class BondIterator;
00167 #else
00168 typedef IMP::internal::IndexingIterator<GetBond> BondIterator;
00169 #endif
00170 BondIterator bonds_begin() const {
00171 return BondIterator(GetBond(get_particle()), 0);
00172 }
00173 BondIterator bonds_end() const {
00174 return BondIterator(GetBond(get_particle()), get_number_of_bonds());
00175 }
00176
00177
00178
00179
00180 #ifdef IMP_DOXYGEN
00181 class BondedIterator;
00182 #else
00183 typedef IMP::internal::IndexingIterator<GetBonded> BondedIterator;
00184 #endif
00185 BondedIterator bondeds_begin() const {
00186 return BondedIterator(GetBonded(get_particle()), 0);
00187 }
00188 BondedIterator bondeds_end() const {
00189 return BondedIterator(GetBonded(get_particle()), get_number_of_bonds());
00190 }
00191
00192 };
00193
00194 IMP_OUTPUT_OPERATOR(Bonded);
00195
00196 IMP_DECORATORS(Bonded, Particles);
00197 IMP_DECORATORS(Bond, Particles);
00198
00199
00200
00201
00202
00203
00204
00205
00206
00207
00208 inline Bonded Bond::get_bonded(unsigned int i) const
00209 {
00210 Particle *p= graph_get_node(get_particle(), i,
00211 internal::get_bond_data().graph_);
00212 return Bonded(p);
00213 }
00214
00215 #ifndef IMP_DOXYGEN
00216 inline Bond Bonded::GetBond::operator()(unsigned int i)
00217 const {
00218 return Bonded(d_).get_bond(i);
00219 }
00220 inline Bonded Bonded::GetBonded::operator()(unsigned int i)
00221 const {
00222 return Bonded(d_).get_bonded(i);
00223 }
00224 #endif
00225
00226
00227
00228
00229
00230
00231
00232
00233
00234
00235
00236
00237 IMPATOMEXPORT
00238 Bond create_bond(Bonded a, Bonded b, Int t);
00239
00240
00241
00242
00243
00244
00245
00246
00247
00248
00249
00250
00251
00252 IMPATOMEXPORT
00253 inline Bond create_custom_bond(Bonded a, Bonded b,
00254 Float length, Float stiffness=-1) {
00255 IMP_INTERNAL_CHECK(length>=0, "Length must be positive");
00256 Bond bd=create_bond(a,b, Bond::NONBIOLOGICAL);
00257 bd.set_length(length);
00258 bd.get_particle()->set_name(std::string("bond ")+
00259 a.get_particle()->get_name()
00260 + " and " + b.get_particle()->get_name());
00261 if (stiffness >=0) bd.set_stiffness(stiffness);
00262 return bd;
00263 }
00264
00265
00266
00267
00268
00269
00270
00271
00272
00273 IMPATOMEXPORT
00274 inline Bond copy_bond(Bonded a, Bonded b,
00275 Bond o) {
00276 Bond bd=create_bond(a,b, o.get_type());
00277 if (o.get_length() > 0) bd.set_length(o.get_length());
00278 bd.get_particle()->set_name(std::string("bond ")+
00279 a.get_particle()->get_name()
00280 + " and " + b.get_particle()->get_name());
00281 if (o.get_stiffness() >=0) bd.set_stiffness(o.get_stiffness());
00282 return bd;
00283 }
00284
00285
00286
00287
00288
00289
00290
00291 IMPATOMEXPORT
00292 void destroy_bond(Bond b);
00293
00294
00295
00296
00297
00298
00299
00300 IMPATOMEXPORT
00301 Bond get_bond(Bonded a, Bonded b);
00302
00303 IMPATOM_END_NAMESPACE
00304
00305 #endif