RDKit: QueryBond.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

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:
29 typedef Queries::Query<int, Bond const *, true> QUERYBOND_QUERY;
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,
88 Queries::CompositeQueryType how = Queries::COMPOSITE_AND,
89 bool maintainOrder = true);
90
91 protected:
92 QUERYBOND_QUERY *dp_query;
93 };
94 };
95
96 #endif
RDKit::QueryBond::QueryMatch
bool QueryMatch(QueryBond const *what) const
returns true if our query details match those of QueryBond what
RDKit::QueryBond::setBondDir
void setBondDir(BondDir bD)
sets the BondDir of this query:
Queries::CompositeQueryType
CompositeQueryType
Definition: QueryObjects.h:35
RDKit::QueryBond::QueryBond
QueryBond(const QueryBond &other)
Definition: QueryBond.h:37
RDKit::makeBondOrderEqualsQuery
BOND_EQUALS_QUERY * makeBondOrderEqualsQuery(Bond::BondType what)
returns a Query for matching bond orders
RDKit::QueryBond::operator=
QueryBond & operator=(const QueryBond &other)
RDKit::QueryBond::getQuery
QUERYBOND_QUERY * getQuery() const
returns our current query
Definition: QueryBond.h:64
RDKit::Bond::BondType
BondType
the type of Bond
Definition: Bond.h:56
RDKit::QueryBond::expandQuery
void expandQuery(QUERYBOND_QUERY *what, Queries::CompositeQueryType how=Queries::COMPOSITE_AND, bool maintainOrder=true)
expands our current query
RDKit::QueryBond::dp_query
QUERYBOND_QUERY * dp_query
Definition: QueryBond.h:92
Bond.h
RDKit
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:28
RDKit::QueryBond::hasQuery
bool hasQuery() const
Definition: QueryBond.h:61
RDKit::Bond
class for representing a bond
Definition: Bond.h:46
QueryOps.h
RDKit::Bond::BondDir
BondDir
the bond's direction (for chirality)
Definition: Bond.h:83
RDKit::QueryBond::~QueryBond
~QueryBond()
RDKit::QueryBond::QUERYBOND_QUERY
Queries::Query< int, Bond const *, true > QUERYBOND_QUERY
Definition: QueryBond.h:29
RDKit::QueryBond::setBondType
void setBondType(BondType bT)
sets the BondType of this query:
RDKit::QueryBond::Match
bool Match(const Bond::BOND_SPTR what) const
returns true if we match Bond what
RDKit::Bond::BOND_SPTR
boost::shared_ptr< Bond > BOND_SPTR
Definition: Bond.h:51
QueryObjects.h
Pulls in all the query types.
RDKit::QueryBond::QueryBond
QueryBond(const Bond &other)
initialize from a bond
Definition: QueryBond.h:35
RDKit::QueryBond::QueryBond
QueryBond()
Definition: QueryBond.h:31
RDKit::QueryBond::copy
virtual Bond * copy() const
returns a copy of this query, owned by the caller
RDKit::QueryBond
Class for storing Bond queries.
Definition: QueryBond.h:27
Queries::Query
Base class for all queries.
Definition: Query.h:45
RDKit::QueryBond::setQuery
void setQuery(QUERYBOND_QUERY *what)
replaces our current query with the value passed in
Definition: QueryBond.h:66
Queries::COMPOSITE_AND
Definition: QueryObjects.h:35
RDKit::Bond::getBondType
BondType getBondType() const
returns our bondType
Definition: Bond.h:119