RDKit
Open-source cheminformatics and machine learning.
QueryAtom.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_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:
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) { dp_query = what; }
47  //! returns our current query
48  QUERYATOM_QUERY *getQuery() const { return dp_query; };
49 
50  //! expands our current query
51  /*!
52  \param what the Queries::Query to be added
53  \param how the operator to be used in the expansion
54  \param maintainOrder (optional) flags whether the relative order of
55  the queries needs to be maintained, if this is
56  false, the order is reversed
57  <b>Notes:</b>
58  - \c what should probably be constructed using one of the functions
59  defined in QueryOps.h
60  - the \c maintainOrder option can be useful because the combination
61  operators short circuit when possible.
62 
63  */
64  void expandQuery(QUERYATOM_QUERY *what,
66  bool maintainOrder = true);
67 
68  //! returns true if we match Atom \c what
69  bool Match(const Atom::ATOM_SPTR &what) const;
70  //! \overload
71  bool Match(Atom const *what) const;
72 
73  //! returns true if our query details match those of QueryAtom \c what
74  bool QueryMatch(QueryAtom const *what) const;
75 
76  private:
77  QUERYATOM_QUERY *dp_query;
78 
79 }; // end o' class
80 
81 }; // end o' namespace
82 
83 #endif
QueryAtom(int num)
Definition: QueryAtom.h:31
CompositeQueryType
Definition: QueryObjects.h:35
Atom * copy() const
returns a copy of this query, owned by the caller
bool hasQuery() const
Definition: QueryAtom.h:43
bool Match(const Atom::ATOM_SPTR &what) const
returns true if we match Atom what
Class for storing atomic queries.
Definition: QueryAtom.h:26
bool QueryMatch(QueryAtom const *what) const
returns true if our query details match those of QueryAtom what
void setQuery(QUERYATOM_QUERY *what)
replaces our current query with the value passed in
Definition: QueryAtom.h:46
Queries::Query< int, Atom const *, true > QUERYATOM_QUERY
Definition: QueryAtom.h:28
int getAtomicNum() const
returns our atomic number
Definition: Atom.h:116
QueryAtom(const QueryAtom &other)
Definition: QueryAtom.h:34
Includes a bunch of functionality for handling Atom and Bond queries.
Definition: Atom.h:29
T * makeAtomNumQuery(int what, const std::string &descr)
returns a Query for matching atomic number
Definition: QueryOps.h:226
boost::shared_ptr< Atom > ATOM_SPTR
Definition: Atom.h:74
QUERYATOM_QUERY * getQuery() const
returns our current query
Definition: QueryAtom.h:48
Defines the Atom class and associated typedefs.
Pulls in all the query types.
QueryAtom(const Atom &other)
Definition: QueryAtom.h:32
Base class for all queries.
Definition: Query.h:45
The class for representing atoms.
Definition: Atom.h:68
void expandQuery(QUERYATOM_QUERY *what, Queries::CompositeQueryType how=Queries::COMPOSITE_AND, bool maintainOrder=true)
expands our current query
virtual Query< MatchFuncArgType, DataFuncArgType, needsConversion > * copy() const
returns a copy of this Query
Definition: Query.h:125