RDKit: QueryAtom.h Source File

| RDKit Open-source cheminformatics and machine learning.

- Main Page
- Namespaces
- Classes
- Files

- File List
- File Members

QueryAtom.h
Go to the documentation of this file.
1 //
2 // Copyright (C) 2001-2017 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_QUERYATOM_H_
11 #define _RD_QUERYATOM_H_
12
13 #include "Atom.h"
14 #include <Query/QueryObjects.h>
15 #include <GraphMol/QueryOps.h>
16
17 namespace RDKit {
18
19 //! Class for storing atomic queries
20 /*!
21 QueryAtom objects are derived from Atom objects, so they can be
22 added to molecules and the like, but they have much fancier
23 querying capabilities.
24
25 */
26 class QueryAtom : public Atom {
27 public:
28 typedef Queries::Query<int, Atom const *, true> QUERYATOM_QUERY;
29
30 QueryAtom() : Atom(), dp_query(NULL){};
31 explicit QueryAtom(int num) : Atom(num), dp_query(makeAtomNumQuery(num)){};
32 explicit QueryAtom(const Atom &other)
33 : Atom(other), dp_query(makeAtomNumQuery(other.getAtomicNum())){};
34 QueryAtom(const QueryAtom &other) : Atom(other) {
35 dp_query = other.dp_query->copy();
36 };
37 ~QueryAtom();
38
39 //! returns a copy of this query, owned by the caller
40 Atom *copy() const;
41
42 // This method can be used to distinguish query atoms from standard atoms:
43 bool hasQuery() const { return dp_query != 0; };
44
45 //! replaces our current query with the value passed in
46 void setQuery(QUERYATOM_QUERY *what) {
47 delete dp_query;
48 dp_query = what;
49 }
50 //! returns our current query
51 QUERYATOM_QUERY *getQuery() const { return dp_query; };
52
53 //! expands our current query
54 /*!
55 \param what the Queries::Query to be added
56 \param how the operator to be used in the expansion
57 \param maintainOrder (optional) flags whether the relative order of
58 the queries needs to be maintained, if this is
59 false, the order is reversed
60 <b>Notes:</b>
61 - \c what should probably be constructed using one of the functions
62 defined in QueryOps.h
63 - the \c maintainOrder option can be useful because the combination
64 operators short circuit when possible.
65
66 */
67 void expandQuery(QUERYATOM_QUERY *what,
68 Queries::CompositeQueryType how = Queries::COMPOSITE_AND,
69 bool maintainOrder = true);
70
71 //! returns true if we match Atom \c what
72 bool Match(const Atom::ATOM_SPTR &what) const;
73 //! \overload
74 bool Match(Atom const *what) const;
75
76 //! returns true if our query details match those of QueryAtom \c what
77 bool QueryMatch(QueryAtom const *what) const;
78
79 private:
80 QUERYATOM_QUERY *dp_query;
81
82 }; // end o' class
83
84 namespace detail {
85 inline std::string qhelper(Atom::QUERYATOM_QUERY *q, unsigned int depth) {
86 std::string res = "";
87 if (q) {
88 for (unsigned int i = 0; i < depth; ++i) res += " ";
89 res += q->getFullDescription() + "\n";
90 for (Atom::QUERYATOM_QUERY::CHILD_VECT_CI ci = q->beginChildren();
91 ci != q->endChildren(); ++ci) {
92 res += qhelper((*ci).get(), depth + 1);
93 }
94 }
95 return res;
96 }
97 } // end of detail namespace
98 inline std::string describeQuery(const Atom *atom) {
99 PRECONDITION(atom, "bad atom");
100 std::string res = "";
101 if (atom->hasQuery()) {
102 res = detail::qhelper(atom->getQuery(), 0);
103 }
104 return res;
105 }
106
107 }; // end o' namespace
108
109 #endif
RDKit::QueryAtom::QueryAtom
QueryAtom()
Definition: QueryAtom.h:30
Queries::Query::beginChildren
CHILD_VECT_CI beginChildren() const
returns an iterator for the beginning of our child vector
Definition: Query.h:101
RDKit::QueryAtom::QueryAtom
QueryAtom(int num)
Definition: QueryAtom.h:31
Queries::CompositeQueryType
CompositeQueryType
Definition: QueryObjects.h:35
RDKit::QueryAtom::copy
Atom * copy() const
returns a copy of this query, owned by the caller
RDKit::QueryAtom::hasQuery
bool hasQuery() const
Definition: QueryAtom.h:43
Queries::Query::endChildren
CHILD_VECT_CI endChildren() const
returns an iterator for the end of our child vector
Definition: Query.h:103
RDKit::QueryAtom::Match
bool Match(const Atom::ATOM_SPTR &what) const
returns true if we match Atom what
RDKit::detail::qhelper
std::string qhelper(Atom::QUERYATOM_QUERY *q, unsigned int depth)
Definition: QueryAtom.h:85
RDKit::QueryAtom
Class for storing atomic queries.
Definition: QueryAtom.h:26
RDKit::QueryAtom::QueryMatch
bool QueryMatch(QueryAtom const *what) const
returns true if our query details match those of QueryAtom what
RDKit::QueryAtom::setQuery
void setQuery(QUERYATOM_QUERY *what)
replaces our current query with the value passed in
Definition: QueryAtom.h:46
RDKit::QueryAtom::QUERYATOM_QUERY
Queries::Query< int, Atom const *, true > QUERYATOM_QUERY
Definition: QueryAtom.h:28
RDKit::describeQuery
std::string describeQuery(const Atom *atom)
Definition: QueryAtom.h:98
RDKit::Atom::hasQuery
virtual bool hasQuery() const
Definition: Atom.h:260
RDKit::QueryAtom::~QueryAtom
~QueryAtom()
RDKit::Atom::getAtomicNum
int getAtomicNum() const
returns our atomic number
Definition: Atom.h:116
RDKit::QueryAtom::QueryAtom
QueryAtom(const QueryAtom &other)
Definition: QueryAtom.h:34
RDKit
Std stuff.
Definition: Atom.h:29
RDKit::makeAtomNumQuery
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
Definition: QueryOps.h:226
RDKit::Atom::getQuery
virtual QUERYATOM_QUERY * getQuery() const
NOT CALLABLE.
QueryOps.h
RDKit::Atom::ATOM_SPTR
boost::shared_ptr< Atom > ATOM_SPTR
Definition: Atom.h:74
Queries::Query::CHILD_VECT_CI
CHILD_VECT::const_iterator CHILD_VECT_CI
Definition: Query.h:51
PRECONDITION
#define PRECONDITION(expr, mess)
Definition: Invariant.h:107
Queries::Query::getFullDescription
virtual std::string getFullDescription() const
returns a fuller text description
Definition: Query.h:76
RDKit::QueryAtom::getQuery
QUERYATOM_QUERY * getQuery() const
returns our current query
Definition: QueryAtom.h:51
Atom.h
Defines the Atom class and associated typedefs.
QueryObjects.h
Pulls in all the query types.
RDKit::QueryAtom::QueryAtom
QueryAtom(const Atom &other)
Definition: QueryAtom.h:32
Queries::Query
Base class for all queries.
Definition: Query.h:45
Queries::COMPOSITE_AND
Definition: QueryObjects.h:35
RDKit::Atom
The class for representing atoms.
Definition: Atom.h:68
RDKit::QueryAtom::expandQuery
void expandQuery(QUERYATOM_QUERY *what, Queries::CompositeQueryType how=Queries::COMPOSITE_AND, bool maintainOrder=true)
expands our current query
Queries::Query::copy
virtual Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query
Definition: Query.h:125