00001
00002
00003
00004
00005
00006 #ifndef _RD_BOND_H
00007 #define _RD_BOND_H
00008
00009
00010 #include <iostream>
00011
00012
00013
00014 #include <Query/QueryObjects.h>
00015 #include <RDGeneral/types.h>
00016
00017 namespace RDKit{
00018 class ROMol;
00019 class RWMol;
00020 class Atom;
00021 typedef boost::shared_ptr<Atom> ATOM_SPTR;
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040 class Bond {
00041 friend class RWMol;
00042 friend class ROMol;
00043 public:
00044 typedef boost::shared_ptr<Bond> BOND_SPTR;
00045
00046 typedef Queries::Query<int,Bond const *,true> QUERYBOND_QUERY;
00047
00048
00049 typedef enum {
00050 UNSPECIFIED = 0,
00051 SINGLE,
00052 DOUBLE,
00053 TRIPLE,
00054 QUADRUPLE,
00055 QUINTUPLE,
00056 HEXTUPLE,
00057 ONEANDAHALF,
00058 TWOANDAHALF,
00059 THREEANDAHALF,
00060 FOURANDAHALF,
00061 FIVEANDAHALF,
00062 AROMATIC,
00063 IONIC,
00064 HYDROGEN,
00065 THREECENTER,
00066 DATIVEONE,
00067 DATIVE,
00068 DATIVEL,
00069 DATIVER,
00070 OTHER
00071 } BondType;
00072
00073
00074 typedef enum {
00075 NONE=0,
00076 BEGINWEDGE,
00077 BEGINDASH,
00078
00079 ENDDOWNRIGHT,
00080 ENDUPRIGHT,
00081 EITHERDOUBLE,
00082 UNKNOWN,
00083 } BondDir;
00084
00085
00086 typedef enum {
00087 STEREONONE=0,
00088 STEREOANY,
00089
00090
00091 STEREOZ,
00092 STEREOE,
00093 } BondStereo;
00094
00095 Bond();
00096
00097 explicit Bond(BondType bT);
00098 Bond(const Bond &other);
00099 virtual ~Bond();
00100 Bond &operator=(const Bond &other);
00101
00102
00103
00104
00105
00106
00107 virtual Bond *copy() const;
00108
00109
00110 const BondType getBondType() const { return d_bondType; };
00111
00112 void setBondType(BondType bT) { d_bondType = bT; };
00113
00114
00115 double getBondTypeAsDouble() const;
00116
00117
00118
00119
00120
00121
00122 double getValenceContrib(const Atom *at) const;
00123
00124 double getValenceContrib(ATOM_SPTR at) const;
00125
00126
00127 void setIsAromatic( bool what ) { df_isAromatic = what; };
00128
00129 bool getIsAromatic() const { return df_isAromatic; };
00130
00131
00132 void setIsConjugated(bool what) {df_isConjugated = what;};
00133
00134 bool getIsConjugated() const {return df_isConjugated;};
00135
00136
00137 ROMol &getOwningMol() const { return *dp_mol; };
00138
00139 void setOwningMol(ROMol *other);
00140
00141 void setOwningMol(ROMol &other) {setOwningMol(&other);};
00142
00143
00144
00145
00146
00147
00148
00149 unsigned int getIdx() const {return d_index;};
00150
00151
00152
00153
00154
00155
00156 void setIdx(unsigned int index) {d_index=index;};
00157
00158
00159
00160
00161
00162
00163 unsigned int getBeginAtomIdx() const { return d_beginAtomIdx; };
00164
00165
00166
00167
00168
00169
00170 unsigned int getEndAtomIdx() const { return d_endAtomIdx; };
00171
00172
00173
00174
00175
00176
00177 unsigned int getOtherAtomIdx(unsigned int thisIdx) const;
00178
00179
00180
00181
00182
00183
00184 void setBeginAtomIdx(unsigned int what);
00185
00186
00187
00188
00189
00190 void setEndAtomIdx(unsigned int what);
00191
00192
00193
00194
00195
00196
00197 void setBeginAtom(Atom *at);
00198
00199 void setBeginAtom(ATOM_SPTR at);
00200
00201
00202
00203
00204
00205 void setEndAtom(Atom *at);
00206
00207 void setEndAtom(ATOM_SPTR at);
00208
00209
00210
00211
00212
00213
00214
00215 Atom *getBeginAtom() const;
00216
00217
00218
00219
00220
00221 Atom *getEndAtom() const;
00222
00223
00224
00225
00226
00227 Atom *getOtherAtom(Atom const *what) const;
00228
00229
00230
00231
00232
00233
00234
00235 virtual bool hasQuery() const { return false; };
00236
00237
00238
00239 virtual void setQuery(QUERYBOND_QUERY *what);
00240
00241 virtual QUERYBOND_QUERY *getQuery() const;
00242
00243
00244 void expandQuery(QUERYBOND_QUERY *what,
00245 Queries::CompositeQueryType how=Queries::COMPOSITE_AND,
00246 bool maintainOrder=true);
00247
00248
00249
00250
00251
00252
00253
00254
00255 virtual bool Match(Bond const *what) const;
00256
00257 virtual bool Match(const Bond::BOND_SPTR what) const;
00258
00259
00260 void setBondDir(BondDir what) { d_dirTag = what; };
00261
00262 BondDir getBondDir() const { return d_dirTag; };
00263
00264
00265 void setStereo(BondStereo what) { d_stereo = what; };
00266
00267 BondStereo getStereo() const { return d_stereo; };
00268
00269
00270 const INT_VECT &getStereoAtoms() const { return d_stereoAtoms; };
00271
00272 INT_VECT &getStereoAtoms() { return d_stereoAtoms; };
00273
00274
00275
00276
00277
00278
00279 STR_VECT getPropList() const {
00280 return dp_props->keys();
00281 }
00282
00283
00284
00285
00286
00287
00288
00289
00290
00291
00292 template <typename T>
00293 void setProp(const char *key,T val, bool computed=false) const{
00294
00295 std::string what(key);
00296 setProp(what,val, computed);
00297 }
00298
00299 template <typename T>
00300 void setProp(const std::string key,T val, bool computed=false ) const{
00301
00302 if (computed) {
00303 STR_VECT compLst;
00304 if(hasProp("computedProps")) getProp("computedProps", compLst);
00305 if (std::find(compLst.begin(), compLst.end(), key) == compLst.end()) {
00306 compLst.push_back(key);
00307 dp_props->setVal("computedProps", compLst);
00308 }
00309 }
00310 dp_props->setVal(key,val);
00311 }
00312
00313
00314
00315
00316
00317
00318
00319
00320
00321
00322
00323
00324
00325
00326
00327 template <typename T>
00328 void getProp(const char *key,T &res) const {
00329 PRECONDITION(dp_props,"getProp called on empty property dict");
00330 dp_props->getVal(key,res);
00331 }
00332
00333 template <typename T>
00334 void getProp(const std::string key,T &res) const {
00335 PRECONDITION(dp_props,"getProp called on empty property dict");
00336 dp_props->getVal(key,res);
00337
00338 }
00339
00340
00341 bool hasProp(const char *key) const {
00342 if(!dp_props) return false;
00343 return dp_props->hasVal(key);
00344 };
00345
00346 bool hasProp(const std::string key) const {
00347 if(!dp_props) return false;
00348 return dp_props->hasVal(key);
00349 };
00350
00351
00352
00353
00354
00355
00356
00357
00358
00359 void clearProp(const char *key) const {
00360 std::string what(key);
00361 clearProp(what);
00362 };
00363
00364 void clearProp(const std::string key) const {
00365 if(hasProp("computedProps")){
00366 STR_VECT compLst;
00367 getProp("computedProps", compLst);
00368 STR_VECT_I svi = std::find(compLst.begin(), compLst.end(), key);
00369 if (svi != compLst.end()) {
00370 compLst.erase(svi);
00371 dp_props->setVal("computedProps", compLst);
00372 }
00373 }
00374 dp_props->clearVal(key);
00375 };
00376
00377
00378 void clearComputedProps() const {
00379 if(!hasProp("computedProps")) return;
00380 STR_VECT compLst;
00381 getProp("computedProps", compLst);
00382 STR_VECT_CI svi;
00383 for (svi = compLst.begin(); svi != compLst.end(); svi++) {
00384 dp_props->clearVal(*svi);
00385 }
00386 compLst.clear();
00387 dp_props->setVal("computedProps", compLst);
00388 }
00389
00390
00391
00392
00393
00394
00395 void updatePropertyCache(bool strict=true) {;};
00396
00397 protected:
00398
00399
00400
00401
00402 BondType d_bondType;
00403 ROMol *dp_mol;
00404 bool df_isAromatic;
00405 bool df_isConjugated;
00406 unsigned int d_index;
00407 unsigned int d_beginAtomIdx,d_endAtomIdx;
00408 BondDir d_dirTag;
00409 BondStereo d_stereo;
00410 INT_VECT d_stereoAtoms;
00411
00412 Dict *dp_props;
00413
00414 void initBond();
00415 };
00416
00417 };
00418
00419
00420 extern std::ostream & operator<<(std::ostream& target, const RDKit::Bond &b);
00421
00422 #endif