RDKit
Open-source cheminformatics and machine learning.
QueryBond.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2006 Greg Landrum and Rational Discovery LLC
3 //
4 // @@ All Rights Reserved @@
5 // This file is part of the RDKit.
6 // The contents are covered by the terms of the BSD license
7 // which is included in the file license.txt, found at the root
8 // of the RDKit source tree.
9 //
10 #ifndef _RD_QUERYBOND_H
11 #define _RD_QUERYBOND_H
12 
13 #include <Query/QueryObjects.h>
14 #include "Bond.h"
15 #include "QueryOps.h"
16 
17 
18 namespace RDKit{
19 
20  //! Class for storing Bond queries
21  /*!
22  QueryBond objects are derived from Bond objects, so they can be
23  added to molecules and the like, but they have much fancier
24  querying capabilities.
25 
26  */
27 
28  class QueryBond : public Bond {
29  public:
31 
32  QueryBond() : Bond(), dp_query(NULL) {};
33  //! initialize with a particular bond order
34  explicit QueryBond(BondType bT);
35  //! initialize from a bond
36  explicit QueryBond(const Bond &other) : Bond(other), dp_query(makeBondOrderEqualsQuery(other.getBondType())) {};
37  QueryBond(const QueryBond &other) : Bond(other), dp_query(other.dp_query->copy()) {};
38 
39  ~QueryBond();
40 
41 
42  //! returns a copy of this query, owned by the caller
43  virtual Bond *copy() const;
44 
45  QueryBond &operator=(const QueryBond &other);
46 
47  //! sets the BondType of this query:
48  void setBondType(BondType bT);
49  //! sets the BondDir of this query:
50  void setBondDir(BondDir bD);
51 
52 
53  //! returns true if we match Bond \c what
54  bool Match(const Bond::BOND_SPTR what) const;
55  //! \overload
56  bool Match(Bond const *what) const;
57 
58  //! returns true if our query details match those of QueryBond \c what
59  bool QueryMatch(QueryBond const *what) const;
60 
61 
62  // This method can be used to distinguish query bonds from standard bonds
63  bool hasQuery() const { return dp_query!=0; };
64 
65  //! returns our current query
66  QUERYBOND_QUERY *getQuery() const { return dp_query; };
67  //! replaces our current query with the value passed in
68  void setQuery(QUERYBOND_QUERY *what) {
69  // free up any existing query (Issue255):
70  if(dp_query)delete dp_query;
71  dp_query = what;
72  };
73 
74  //! expands our current query
75  /*!
76  \param what the Queries::Query to be added
77  \param how the operator to be used in the expansion
78  \param maintainOrder (optional) flags whether the relative order of
79  the queries needs to be maintained, if this is
80  false, the order is reversed
81 
82  <b>Notes:</b>
83  - \c what should probably be constructed using one of the functions
84  defined in QueryOps.h
85  - the \c maintainOrder option can be useful because the combination
86  operators short circuit when possible.
87 
88  */
89  void expandQuery(QUERYBOND_QUERY *what,
91  bool maintainOrder=true);
92 
93  protected:
94  QUERYBOND_QUERY *dp_query;
95  };
96 
97 };
98 
99 
100 #endif
bool QueryMatch(QueryBond const *what) const
returns true if our query details match those of QueryBond what
void setBondDir(BondDir bD)
sets the BondDir of this query:
CompositeQueryType
Definition: QueryObjects.h:35
QueryBond(const QueryBond &other)
Definition: QueryBond.h:37
BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
QueryBond & operator=(const QueryBond &other)
QUERYBOND_QUERY * getQuery() const
returns our current query
Definition: QueryBond.h:66
BondType
the type of Bond
Definition: Bond.h:55
void expandQuery(QUERYBOND_QUERY *what, Queries::CompositeQueryType how=Queries::COMPOSITE_AND, bool maintainOrder=true)
expands our current query
QUERYBOND_QUERY * dp_query
Definition: QueryBond.h:94
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
bool hasQuery() const
Definition: QueryBond.h:63
class for representing a bond
Definition: Bond.h:46
BondDir
the bond&#39;s direction (for chirality)
Definition: Bond.h:81
void setBondType(BondType bT)
sets the BondType of this query:
bool Match(const Bond::BOND_SPTR what) const
returns true if we match Bond what
boost::shared_ptr< Bond > BOND_SPTR
Definition: Bond.h:50
Pulls in all the query types.
QueryBond(const Bond &other)
initialize from a bond
Definition: QueryBond.h:36
virtual Bond * copy() const
returns a copy of this query, owned by the caller
Class for storing Bond queries.
Definition: QueryBond.h:28
Base class for all queries.
Definition: Query.h:46
void setQuery(QUERYBOND_QUERY *what)
replaces our current query with the value passed in
Definition: QueryBond.h:68
BondType getBondType() const
returns our bondType
Definition: Bond.h:117
Queries::Query< int, Bond const *, true > QUERYBOND_QUERY
Definition: QueryBond.h:30