RDKit: AtomIterators.h Source File

| RDKit Open-source cheminformatics and machine learning.

Loading...
Searching...
No Matches
AtomIterators.h
Go to the documentation of this file.
1//
2// Copyright (C) 2002-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/*! \file AtomIterators.h
11
12 \brief various tools for iterating over a molecule's Atoms.
13
14 <b>WARNING:</b> If you go changing the molecule underneath one of
15 these iterators you will be sad...
16*/
17#include <RDGeneral/export.h>
18#ifndef __RD_ATOM_ITERATORS_H__
19#define __RD_ATOM_ITERATORS_H__
20
21#ifdef _MSC_VER
22#pragma warning(disable : 4661) // no suitable definition provided for explicit
23 // template instantiation request
24#endif
25
26namespace RDKit {
27class QueryAtom;
28
29//! A general random access iterator
30template <class Atom_, class Mol_>
31 class RDKIT_GRAPHMOL_EXPORT AtomIterator_ {
32 public:
33 typedef AtomIterator_<Atom_, Mol_> ThisType;
34 AtomIterator_() : _mol(nullptr) {}
35 AtomIterator_(Mol_ *mol);
36 AtomIterator_(Mol_ *mol, int pos);
37 AtomIterator_(const ThisType &other);
38 AtomIterator_ &operator=(const ThisType &other);
39 AtomIterator_ &operator+=(int val);
40 AtomIterator_ &operator-=(int val);
41 AtomIterator_ operator+(int val) const;
42 AtomIterator_ operator-(int val) const;
43
44 // iterator subtraction
45 int operator-(ThisType &other) const;
46
47 // dereference
48 Atom_ *operator*() const;
49 // random access
50 Atom_ *operator[](const int which) const;
51 bool operator==(const ThisType &other) const;
52 bool operator!=(const ThisType &other) const;
53 bool operator<(const ThisType &other) const;
54 bool operator<=(const ThisType &other) const;
55 bool operator>(const ThisType &other) const;
56 bool operator>=(const ThisType &other) const;
57
58 // pre-increment
59 ThisType &operator++();
60 ThisType operator++(int);
61
62 // pre-decrement
63 ThisType &operator--();
64 ThisType operator--(int);
65
66 private:
67 int _pos{-1};
68 int _max{-1};
69 Mol_ *_mol;
70};
71
72//! Iterate over heteroatoms, this is bidirectional
73template <class Atom_, class Mol_>
74 class RDKIT_GRAPHMOL_EXPORT HeteroatomIterator_ {
75 public:
76 typedef HeteroatomIterator_<Atom_, Mol_> ThisType;
77 HeteroatomIterator_() : _mol(nullptr) {}
78 HeteroatomIterator_(Mol_ *mol);
79 HeteroatomIterator_(Mol_ *mol, int pos);
80 ~HeteroatomIterator_();
81 HeteroatomIterator_(const ThisType &other);
82 HeteroatomIterator_ &operator=(const ThisType &other);
83 bool operator==(const ThisType &other) const;
84 bool operator!=(const ThisType &other) const;
85
86 Atom_ *operator*() const;
87
88 // pre-increment
89 ThisType &operator++();
90 ThisType operator++(int);
91
92 // pre-decrement
93 ThisType &operator--();
94 ThisType operator--(int);
95
96 private:
97 int _end{-1};
98 int _pos{-1};
99 Mol_ *_mol;
100 // FIX: somehow changing the following to a pointer make the regression test
101 // pass
102 // QueryAtom _qA;
103 QueryAtom *_qA;
104
105 int _findNext(int from);
106 int _findPrev(int from);
107};
108
109//! Iterate over aromatic atoms, this is bidirectional
110template <class Atom_, class Mol_>
111 class RDKIT_GRAPHMOL_EXPORT AromaticAtomIterator_ {
112 public:
113 typedef AromaticAtomIterator_<Atom_, Mol_> ThisType;
114 AromaticAtomIterator_() : _mol(nullptr) {}
115 AromaticAtomIterator_(Mol_ *mol);
116 AromaticAtomIterator_(Mol_ *mol, int pos);
117 ~AromaticAtomIterator_();
118 AromaticAtomIterator_(const ThisType &other);
119 AromaticAtomIterator_ &operator=(const ThisType &other);
120 bool operator==(const ThisType &other) const;
121 bool operator!=(const ThisType &other) const;
122
123 Atom_ *operator*() const;
124
125 // pre-increment
126 ThisType &operator++();
127 ThisType operator++(int);
128
129 // pre-decrement
130 ThisType &operator--();
131 ThisType operator--(int);
132
133 private:
134 int _end{-1};
135 int _pos{-1};
136 Mol_ *_mol;
137
138 int _findNext(int from);
139 int _findPrev(int from);
140};
141
142//! Iterate over atoms matching a query. This is bidirectional.
143template <class Atom_, class Mol_>
144 class RDKIT_GRAPHMOL_EXPORT QueryAtomIterator_ {
145 public:
146 typedef QueryAtomIterator_<Atom_, Mol_> ThisType;
147 QueryAtomIterator_() : _mol(nullptr) {}
148 QueryAtomIterator_(Mol_ *mol, QueryAtom const *what);
149 QueryAtomIterator_(Mol_ *mol, int pos);
150 ~QueryAtomIterator_();
151 QueryAtomIterator_(const ThisType &other);
152 QueryAtomIterator_ &operator=(const ThisType &other);
153 bool operator==(const ThisType &other) const;
154 bool operator!=(const ThisType &other) const;
155
156 Atom_ *operator*() const;
157
158 // pre-increment
159 ThisType &operator++();
160 ThisType operator++(int);
161
162 // pre-decrement
163 ThisType &operator--();
164 ThisType operator--(int);
165
166 private:
167 int _end{-1};
168 int _pos{-1};
169 Mol_ *_mol;
170 QueryAtom *_qA{nullptr};
171
172 int _findNext(int from);
173 int _findPrev(int from);
174};
175
176//! Iterate over atoms matching a query function. This is bidirectional.
177template <class Atom_, class Mol_>
178 class RDKIT_GRAPHMOL_EXPORT MatchingAtomIterator_ {
179 public:
180 typedef MatchingAtomIterator_<Atom_, Mol_> ThisType;
181 MatchingAtomIterator_() : _mol(nullptr), _qF(nullptr) {}
182 MatchingAtomIterator_(Mol_ *mol, bool (*fn)(Atom_ *));
183 MatchingAtomIterator_(Mol_ *mol, int pos);
184 ~MatchingAtomIterator_();
185 MatchingAtomIterator_(const ThisType &other);
186 MatchingAtomIterator_ &operator=(const ThisType &other);
187 bool operator==(const ThisType &other) const;
188 bool operator!=(const ThisType &other) const;
189
190 Atom_ *operator*() const;
191
192 // pre-increment
193 ThisType &operator++();
194 ThisType operator++(int);
195
196 // pre-decrement
197 ThisType &operator--();
198 ThisType operator--(int);
199
200 private:
201 int _end{-1};
202 int _pos{-1};
203 Mol_ *_mol;
204 bool (*_qF)(Atom_ *);
205
206 int _findNext(int from);
207 int _findPrev(int from);
208};
209
210} // namespace RDKit
211
212#endif
RDKit::AromaticAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::AromaticAtomIterator_::operator=
AromaticAtomIterator_ & operator=(const ThisType &other)
RDKit::AromaticAtomIterator_::ThisType
AromaticAtomIterator_< Atom_, Mol_ > ThisType
Definition AtomIterators.h:113
RDKit::AromaticAtomIterator_::operator--
ThisType & operator--()
RDKit::AromaticAtomIterator_::operator*
Atom_ * operator*() const
RDKit::AromaticAtomIterator_::operator++
ThisType operator++(int)
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_(const ThisType &other)
RDKit::AromaticAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::AromaticAtomIterator_::operator++
ThisType & operator++()
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_(Mol_ *mol)
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_(Mol_ *mol, int pos)
RDKit::AromaticAtomIterator_::AromaticAtomIterator_
AromaticAtomIterator_()
Definition AtomIterators.h:114
RDKit::AromaticAtomIterator_::~AromaticAtomIterator_
~AromaticAtomIterator_()
RDKit::AromaticAtomIterator_::operator--
ThisType operator--(int)
RDKit::AtomIterator_::operator-
AtomIterator_ operator-(int val) const
RDKit::AtomIterator_::operator+
AtomIterator_ operator+(int val) const
RDKit::AtomIterator_::operator-
int operator-(ThisType &other) const
RDKit::AtomIterator_::ThisType
AtomIterator_< Atom_, Mol_ > ThisType
Definition AtomIterators.h:33
RDKit::AtomIterator_::operator<=
bool operator<=(const ThisType &other) const
RDKit::AtomIterator_::operator-=
AtomIterator_ & operator-=(int val)
RDKit::AtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::AtomIterator_::operator--
ThisType operator--(int)
RDKit::AtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::AtomIterator_::operator>
bool operator>(const ThisType &other) const
RDKit::AtomIterator_::AtomIterator_
AtomIterator_(const ThisType &other)
RDKit::AtomIterator_::operator*
Atom_ * operator*() const
RDKit::AtomIterator_::AtomIterator_
AtomIterator_(Mol_ *mol, int pos)
RDKit::AtomIterator_::operator++
ThisType operator++(int)
RDKit::AtomIterator_::AtomIterator_
AtomIterator_()
Definition AtomIterators.h:34
RDKit::AtomIterator_::operator+=
AtomIterator_ & operator+=(int val)
RDKit::AtomIterator_::AtomIterator_
AtomIterator_(Mol_ *mol)
RDKit::AtomIterator_::operator<
bool operator<(const ThisType &other) const
RDKit::AtomIterator_::operator=
AtomIterator_ & operator=(const ThisType &other)
RDKit::AtomIterator_::operator[]
Atom_ * operator[](const int which) const
RDKit::AtomIterator_::operator++
ThisType & operator++()
RDKit::AtomIterator_::operator>=
bool operator>=(const ThisType &other) const
RDKit::AtomIterator_::operator--
ThisType & operator--()
RDKit::HeteroatomIterator_::operator--
ThisType & operator--()
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_(Mol_ *mol)
RDKit::HeteroatomIterator_::operator=
HeteroatomIterator_ & operator=(const ThisType &other)
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_(Mol_ *mol, int pos)
RDKit::HeteroatomIterator_::operator++
ThisType & operator++()
RDKit::HeteroatomIterator_::ThisType
HeteroatomIterator_< Atom_, Mol_ > ThisType
Definition AtomIterators.h:76
RDKit::HeteroatomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::HeteroatomIterator_::operator--
ThisType operator--(int)
RDKit::HeteroatomIterator_::operator++
ThisType operator++(int)
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_(const ThisType &other)
RDKit::HeteroatomIterator_::~HeteroatomIterator_
~HeteroatomIterator_()
RDKit::HeteroatomIterator_::HeteroatomIterator_
HeteroatomIterator_()
Definition AtomIterators.h:77
RDKit::HeteroatomIterator_::operator*
Atom_ * operator*() const
RDKit::HeteroatomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::MatchingAtomIterator_::operator++
ThisType operator++(int)
RDKit::MatchingAtomIterator_::operator--
ThisType & operator--()
RDKit::MatchingAtomIterator_::operator--
ThisType operator--(int)
RDKit::MatchingAtomIterator_::ThisType
MatchingAtomIterator_< Atom_, Mol_ > ThisType
Definition AtomIterators.h:180
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_(Mol_ *mol, bool(*fn)(Atom_ *))
RDKit::MatchingAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::MatchingAtomIterator_::~MatchingAtomIterator_
~MatchingAtomIterator_()
RDKit::MatchingAtomIterator_::operator*
Atom_ * operator*() const
RDKit::MatchingAtomIterator_::operator++
ThisType & operator++()
RDKit::MatchingAtomIterator_::operator=
MatchingAtomIterator_ & operator=(const ThisType &other)
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_(Mol_ *mol, int pos)
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_()
Definition AtomIterators.h:181
RDKit::MatchingAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::MatchingAtomIterator_::MatchingAtomIterator_
MatchingAtomIterator_(const ThisType &other)
RDKit::QueryAtomIterator_::operator=
QueryAtomIterator_ & operator=(const ThisType &other)
RDKit::QueryAtomIterator_::~QueryAtomIterator_
~QueryAtomIterator_()
RDKit::QueryAtomIterator_::operator!=
bool operator!=(const ThisType &other) const
RDKit::QueryAtomIterator_::operator--
ThisType operator--(int)
RDKit::QueryAtomIterator_::operator==
bool operator==(const ThisType &other) const
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_(Mol_ *mol, QueryAtom const *what)
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_(Mol_ *mol, int pos)
RDKit::QueryAtomIterator_::operator*
Atom_ * operator*() const
RDKit::QueryAtomIterator_::operator--
ThisType & operator--()
RDKit::QueryAtomIterator_::operator++
ThisType operator++(int)
RDKit::QueryAtomIterator_::ThisType
QueryAtomIterator_< Atom_, Mol_ > ThisType
Definition AtomIterators.h:146
RDKit::QueryAtomIterator_::operator++
ThisType & operator++()
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_()
Definition AtomIterators.h:147
RDKit::QueryAtomIterator_::QueryAtomIterator_
QueryAtomIterator_(const ThisType &other)
RDKit::QueryAtom
Class for storing atomic queries.
Definition QueryAtom.h:28
export.h
RDKIT_GRAPHMOL_EXPORT
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:249
RDKit
Std stuff.
Definition Abbreviations.h:19