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-2026 Greg Landrum and other RDKit contributors
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 Atom;
28class QueryAtom;
29
30//! A general random access iterator
31template <class Atom_, class Mol_>
33 public:
35 AtomIterator_() : _mol(nullptr) {}
36 AtomIterator_(Mol_ *mol);
37 AtomIterator_(Mol_ *mol, int pos);
38 AtomIterator_(const ThisType &other);
42 AtomIterator_ operator+(int val) const;
43 AtomIterator_ operator-(int val) const;
44
45 // iterator subtraction
46 int operator-(ThisType &other) const;
47
48 // dereference
49 Atom_ *operator*() const;
50 // random access
51 Atom_ *operator[](const int which) 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 bool operator>=(const ThisType &other) const;
58
59 // pre-increment
62
63 // pre-decrement
66
67 private:
68 int _pos{-1};
69 int _max{-1};
70 Mol_ *_mol;
71};
72
73//! Iterate over heteroatoms, this is bidirectional
74template <class Atom_, class Mol_>
76 public:
78 HeteroatomIterator_() : _mol(nullptr) {}
80 HeteroatomIterator_(Mol_ *mol, int pos);
84 bool operator==(const ThisType &other) const;
85 bool operator!=(const ThisType &other) const;
86
87 Atom_ *operator*() const;
88
89 // pre-increment
92
93 // pre-decrement
96
97 private:
98 int _end{-1};
99 int _pos{-1};
100 Mol_ *_mol;
101 QueryAtom *_qA{nullptr};
102
103 int _findNext(int from);
104 int _findPrev(int from);
105};
106
107//! Iterate over aromatic atoms, this is bidirectional
108template <class Atom_, class Mol_>
110 public:
112 AromaticAtomIterator_() : _mol(nullptr) {}
114 AromaticAtomIterator_(Mol_ *mol, int pos);
118 bool operator==(const ThisType &other) const;
119 bool operator!=(const ThisType &other) const;
120
121 Atom_ *operator*() const;
122
123 // pre-increment
126
127 // pre-decrement
130
131 private:
132 int _end{-1};
133 int _pos{-1};
134 Mol_ *_mol;
135
136 int _findNext(int from);
137 int _findPrev(int from);
138};
139
140//! Iterate over atoms matching a query. This is bidirectional.
141template <class Atom_, class Mol_>
143 public:
145 QueryAtomIterator_() : _mol(nullptr) {}
146 QueryAtomIterator_(Mol_ *mol, Atom const *what);
147 QueryAtomIterator_(Mol_ *mol, int pos);
151 bool operator==(const ThisType &other) const;
152 bool operator!=(const ThisType &other) const;
153
154 Atom_ *operator*() const;
155
156 // pre-increment
159
160 // pre-decrement
163
164 private:
165 int _end{-1};
166 int _pos{-1};
167 Mol_ *_mol;
168 QueryAtom *_qA{nullptr};
169
170 int _findNext(int from);
171 int _findPrev(int from);
172};
173
174//! Iterate over atoms matching a query function. This is bidirectional.
175template <class Atom_, class Mol_>
177 public:
179 MatchingAtomIterator_() : _mol(nullptr), _qF(nullptr) {}
180 MatchingAtomIterator_(Mol_ *mol, bool (*fn)(Atom_ *));
181 MatchingAtomIterator_(Mol_ *mol, int pos);
185 bool operator==(const ThisType &other) const;
186 bool operator!=(const ThisType &other) const;
187
188 Atom_ *operator*() const;
189
190 // pre-increment
193
194 // pre-decrement
197
198 private:
199 int _end{-1};
200 int _pos{-1};
201 Mol_ *_mol;
202 bool (*_qF)(Atom_ *);
203
204 int _findNext(int from);
205 int _findPrev(int from);
206};
207
208} // namespace RDKit
209
210#endif
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)
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--()
The class for representing atoms.
Definition Atom.h:75
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
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)
QueryAtomIterator_ & operator=(const ThisType &other)
bool operator!=(const ThisType &other) const
bool operator==(const ThisType &other) const
QueryAtomIterator_(Mol_ *mol, int pos)
QueryAtomIterator_(Mol_ *mol, Atom const *what)
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:321
Std stuff.