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