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_>
32 public:
34 AtomIterator_() : _mol(nullptr) {}
35 AtomIterator_(Mol_ *mol);
36 AtomIterator_(Mol_ *mol, int pos);
37 AtomIterator_(const ThisType &other);
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
61
62 // pre-decrement
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_>
75 public:
77 HeteroatomIterator_() : _mol(nullptr) {}
79 HeteroatomIterator_(Mol_ *mol, int pos);
83 bool operator==(const ThisType &other) const;
84 bool operator!=(const ThisType &other) const;
85
86 Atom_ *operator*() const;
87
88 // pre-increment
91
92 // pre-decrement
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_>
112 public:
114 AromaticAtomIterator_() : _mol(nullptr) {}
116 AromaticAtomIterator_(Mol_ *mol, int pos);
120 bool operator==(const ThisType &other) const;
121 bool operator!=(const ThisType &other) const;
122
123 Atom_ *operator*() const;
124
125 // pre-increment
128
129 // pre-decrement
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_>
145 public:
147 QueryAtomIterator_() : _mol(nullptr) {}
148 QueryAtomIterator_(Mol_ *mol, QueryAtom const *what);
149 QueryAtomIterator_(Mol_ *mol, int pos);
153 bool operator==(const ThisType &other) const;
154 bool operator!=(const ThisType &other) const;
155
156 Atom_ *operator*() const;
157
158 // pre-increment
161
162 // pre-decrement
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_>
179 public:
181 MatchingAtomIterator_() : _mol(nullptr), _qF(nullptr) {}
182 MatchingAtomIterator_(Mol_ *mol, bool (*fn)(Atom_ *));
183 MatchingAtomIterator_(Mol_ *mol, int pos);
187 bool operator==(const ThisType &other) const;
188 bool operator!=(const ThisType &other) const;
189
190 Atom_ *operator*() const;
191
192 // pre-increment
195
196 // pre-decrement
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
Iterate over aromatic atoms, this is bidirectional.
bool operator!=(const ThisType &other) const
AromaticAtomIterator_ & operator=(const ThisType &other)
AromaticAtomIterator_< Atom_, Mol_ > ThisType
AromaticAtomIterator_(const ThisType &other)
bool operator==(const ThisType &other) const
AromaticAtomIterator_(Mol_ *mol, int pos)
A general random access iterator.
AtomIterator_ operator-(int val) const
AtomIterator_ operator+(int val) const
int operator-(ThisType &other) const
AtomIterator_< Atom_, Mol_ > ThisType
bool operator<=(const ThisType &other) const
AtomIterator_ & operator-=(int val)
bool operator!=(const ThisType &other) const
ThisType operator--(int)
bool operator==(const ThisType &other) const
bool operator>(const ThisType &other) const
AtomIterator_(const ThisType &other)
Atom_ * operator*() const
AtomIterator_(Mol_ *mol, int pos)
ThisType operator++(int)
AtomIterator_ & operator+=(int val)
AtomIterator_(Mol_ *mol)
bool operator<(const ThisType &other) const
AtomIterator_ & operator=(const ThisType &other)
Atom_ * operator[](const int which) const
ThisType & operator++()
bool operator>=(const ThisType &other) const
ThisType & operator--()
Iterate over heteroatoms, this is bidirectional.
HeteroatomIterator_ & operator=(const ThisType &other)
HeteroatomIterator_(Mol_ *mol, int pos)
HeteroatomIterator_< Atom_, Mol_ > ThisType
bool operator!=(const ThisType &other) const
HeteroatomIterator_(const ThisType &other)
Atom_ * operator*() const
bool operator==(const ThisType &other) const
Iterate over atoms matching a query function. This is bidirectional.
MatchingAtomIterator_< Atom_, Mol_ > ThisType
MatchingAtomIterator_(Mol_ *mol, bool(*fn)(Atom_ *))
bool operator==(const ThisType &other) const
MatchingAtomIterator_ & operator=(const ThisType &other)
MatchingAtomIterator_(Mol_ *mol, int pos)
bool operator!=(const ThisType &other) const
MatchingAtomIterator_(const ThisType &other)
Iterate over atoms matching a query. This is bidirectional.
QueryAtomIterator_ & operator=(const ThisType &other)
bool operator!=(const ThisType &other) const
bool operator==(const ThisType &other) const
QueryAtomIterator_(Mol_ *mol, QueryAtom const *what)
QueryAtomIterator_(Mol_ *mol, int pos)
Atom_ * operator*() const
QueryAtomIterator_< Atom_, Mol_ > ThisType
QueryAtomIterator_(const ThisType &other)
Class for storing atomic queries.
Definition QueryAtom.h:28
#define RDKIT_GRAPHMOL_EXPORT
Definition export.h:233
Std stuff.