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 namespace RDKit {
18 
19 //! Class for storing Bond queries
20 /*!
21  QueryBond objects are derived from Bond objects, so they can be
22  added to molecules and the like, but they have much fancier
23  querying capabilities.
24 
25  */
26 
27 class QueryBond : public Bond {
28  public:
30 
31  QueryBond() : Bond(), dp_query(NULL){};
32  //! initialize with a particular bond order
33  explicit QueryBond(BondType bT);
34  //! initialize from a bond
35  explicit QueryBond(const Bond &other)
36  : Bond(other), dp_query(makeBondOrderEqualsQuery(other.getBondType())){};
37  QueryBond(const QueryBond &other)
38  : Bond(other), dp_query(other.dp_query->copy()){};
39 
40  ~QueryBond();
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  //! returns true if we match Bond \c what
53  bool Match(const Bond::BOND_SPTR what) const;
54  //! \overload
55  bool Match(Bond const *what) const;
56 
57  //! returns true if our query details match those of QueryBond \c what
58  bool QueryMatch(QueryBond const *what) const;
59 
60  // This method can be used to distinguish query bonds from standard bonds
61  bool hasQuery() const { return dp_query != 0; };
62 
63  //! returns our current query
64  QUERYBOND_QUERY *getQuery() const { return dp_query; };
65  //! replaces our current query with the value passed in
66  void setQuery(QUERYBOND_QUERY *what) {
67  // free up any existing query (Issue255):
68  if (dp_query) delete dp_query;
69  dp_query = what;
70  };
71 
72  //! expands our current query
73  /*!
74  \param what the Queries::Query to be added
75  \param how the operator to be used in the expansion
76  \param maintainOrder (optional) flags whether the relative order of
77  the queries needs to be maintained, if this is
78  false, the order is reversed
79 
80  <b>Notes:</b>
81  - \c what should probably be constructed using one of the functions
82  defined in QueryOps.h
83  - the \c maintainOrder option can be useful because the combination
84  operators short circuit when possible.
85 
86  */
87  void expandQuery(QUERYBOND_QUERY *what,
89  bool maintainOrder = true);
90 
91  protected:
92  QUERYBOND_QUERY *dp_query;
93 };
94 };
95 
96 #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:64
BondType
the type of Bond
Definition: Bond.h:57
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:92
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
bool hasQuery() const
Definition: QueryBond.h:61
class for representing a bond
Definition: Bond.h:47
BondDir
the bond&#39;s direction (for chirality)
Definition: Bond.h:84
Queries::Query< int, Bond const *, true > QUERYBOND_QUERY
Definition: QueryBond.h:29
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:52
Pulls in all the query types.
QueryBond(const Bond &other)
initialize from a bond
Definition: QueryBond.h:35
virtual Bond * copy() const
returns a copy of this query, owned by the caller
Class for storing Bond queries.
Definition: QueryBond.h:27
Base class for all queries.
Definition: Query.h:45
void setQuery(QUERYBOND_QUERY *what)
replaces our current query with the value passed in
Definition: QueryBond.h:66
BondType getBondType() const
returns our bondType
Definition: Bond.h:122