2 |
|
obiter.cpp - STL-style iterators for Open Babel |
3 |
|
|
4 |
|
Copyright (C) 1998-2001 by OpenEye Scientific Software, Inc. |
5 |
< |
Some portions Copyright (C) 2001-2005 by Geoffrey R. Hutchison |
5 |
> |
Some portions Copyright (C) 2001-2006 by Geoffrey R. Hutchison |
6 |
|
|
7 |
|
This file is part of the Open Babel project. |
8 |
|
For more information, see <http://openbabel.sourceforge.net/> |
31 |
|
|
32 |
|
To facilitate iteration through all atoms in a molecule, without resorting |
33 |
|
to atom indexes (which may change in the future) or the OBMol::BeginAtom() |
34 |
< |
and OBMol::NextAtom() methods which may only be safely used by one method |
35 |
< |
at once (e.g., if a method above your code or underneath your code uses these |
36 |
< |
methods, errors will occur). |
34 |
> |
and OBMol::NextAtom() methods which may be deprecated in the future. |
35 |
|
|
38 |
– |
Therefore, it is <strong>highly recommended</strong> to use the separate |
39 |
– |
STL-style iterator classes. |
40 |
– |
|
36 |
|
This has been made significantly easier by a series of macros in the |
37 |
|
obiter.h header file: |
38 |
|
|
49 |
|
double exactMass = 0.0f; |
50 |
|
FOR_ATOMS_OF_MOL(a, mol) |
51 |
|
{ |
52 |
+ |
// The variable a behaves like OBAtom* when used with -> and * but |
53 |
+ |
// but needs to be explicitly converted when appearing as a parameter |
54 |
+ |
// in a function call - use &*a |
55 |
+ |
|
56 |
|
exactMass += a->GetExactMass(); |
57 |
|
} |
58 |
|
\endcode |
99 |
|
|
100 |
|
To facilitate iteration through all bonds in a molecule, without resorting |
101 |
|
to bond indexes (which may change in the future) or the OBMol::BeginBond() |
102 |
< |
and OBMol::NextBond() methods which may only be safely used by one method |
104 |
< |
at once (e.g., if a method above your code or underneath your code uses these |
105 |
< |
methods, errors will occur). |
102 |
> |
and OBMol::NextBond() methods which may be deprecated in the future. |
103 |
|
|
107 |
– |
Therefore, it is <strong>highly recommended</strong> to use the separate |
108 |
– |
STL-style iterator classes. |
109 |
– |
|
104 |
|
This has been made significantly easier by a series of macros in the |
105 |
|
obiter.h header file: |
106 |
|
|
117 |
|
unsigned int bondOrderSum = 0; |
118 |
|
FOR_BONDS_OF_MOL(b, mol) |
119 |
|
{ |
120 |
+ |
// The variable b behaves like OBBond* when used with -> and * but |
121 |
+ |
// but needs to be explicitly converted when appearing as a parameter |
122 |
+ |
// in a function call - use &*b |
123 |
|
bondOrderSum += b->GetBO(); |
124 |
|
} |
125 |
|
\endcode |
165 |
|
|
166 |
|
To facilitate iteration through all neighbors of an atom, without resorting |
167 |
|
to bond indexes (which may change in the future) or the OBAtom::BeginNbr() |
168 |
< |
and OBAtom::NextNbr() methods which may only be safely used by one method |
172 |
< |
at once (e.g., if a method above your code or underneath your code uses these |
173 |
< |
methods, errors will occur). |
168 |
> |
and OBAtom::NextNbr() methods which may be deprecated in the future. |
169 |
|
|
175 |
– |
Therefore, it is <strong>highly recommended</strong> to use the separate |
176 |
– |
STL-style iterator classes. |
177 |
– |
|
170 |
|
This has been made significantly easier by a series of macros in the |
171 |
|
obiter.h header file: |
172 |
|
|
182 |
|
OBMol mol; |
183 |
|
FOR_ATOMS_OF_MOL(a, mol) |
184 |
|
{ |
185 |
< |
FOR_NBORS_OF_ATOM(b, a) |
185 |
> |
// The variable a behaves like OBAtom* when used with -> and * but |
186 |
> |
// but needs to be explicitly converted when appearing as a parameter |
187 |
> |
// in a function call - use &*a |
188 |
> |
FOR_NBORS_OF_ATOM(b, &*a) |
189 |
|
{ |
190 |
|
... |
191 |
|
} |
233 |
|
|
234 |
|
To facilitate iteration through all bonds on an atom, without resorting |
235 |
|
to bond indexes (which may change in the future) or the OBAtom::BeginBond() |
236 |
< |
and OBAtom::NextBond() methods which may only be safely used by one method |
242 |
< |
at once (e.g., if a method above your code or underneath your code uses these |
243 |
< |
methods, errors will occur). |
236 |
> |
and OBAtom::NextBond() methods which may be deprecated in the future |
237 |
|
|
245 |
– |
Therefore, it is <strong>highly recommended</strong> to use the separate |
246 |
– |
STL-style iterator classes. |
247 |
– |
|
238 |
|
This has been made significantly easier by a series of macros in the |
239 |
|
obiter.h header file: |
240 |
|
|
251 |
|
unsigned int tripleBondCount; |
252 |
|
FOR_BONDS_OF_ATOM(b, atom) |
253 |
|
{ |
254 |
+ |
// The variable b behaves like OBBond* when used with -> and * but |
255 |
+ |
// but needs to be explicitly converted when appearing as a parameter |
256 |
+ |
// in a function call - use &*b |
257 |
|
if (b->GetBO() == 3) |
258 |
|
tripleBondCount++; |
259 |
|
} |
300 |
|
|
301 |
|
To facilitate iteration through all residues in a molecule, without resorting |
302 |
|
to residue indexes (which may change in the future) or the OBMol::BeginResidue() |
303 |
< |
and OBMol::NextResidue() methods which may only be safely used by one method |
311 |
< |
at once (e.g., if a method above your code or underneath your code uses these |
312 |
< |
methods, errors will occur). |
303 |
> |
and OBMol::NextResidue() methods which may be deprecated in the future. |
304 |
|
|
314 |
– |
Therefore, it is <strong>highly recommended</strong> to use the separate |
315 |
– |
STL-style iterator classes. |
316 |
– |
|
305 |
|
This has been made significantly easier by a series of macros in the |
306 |
|
obiter.h header file: |
307 |
|
|
317 |
|
OBMol mol; |
318 |
|
FOR_RESIDUES_OF_MOL(r, mol) |
319 |
|
{ |
320 |
+ |
// The variable r behaves like OBResidue* when used with -> and * but |
321 |
+ |
// but needs to be explicitly converted when appearing as a parameter |
322 |
+ |
// in a function call - use &*r |
323 |
+ |
|
324 |
|
if (r->GetName() == resname && r->GetNum() == rnum) |
325 |
|
{ |
326 |
|
// got a match, let's go to work |
370 |
|
|
371 |
|
To facilitate iteration through all atoms in a residue, without resorting |
372 |
|
to atom indexes (which may change in the future) or the OBResidue::BeginAtom() |
373 |
< |
and OBResidue::NextAtom() methods which may only be safely used by one method |
382 |
< |
at once (e.g., if a method above your code or underneath your code uses these |
383 |
< |
methods, errors will occur). |
373 |
> |
and OBResidue::NextAtom() methods which may be deprecated in the future. |
374 |
|
|
385 |
– |
Therefore, it is <strong>highly recommended</strong> to use the separate |
386 |
– |
STL-style iterator classes. |
387 |
– |
|
375 |
|
This has been made significantly easier by a series of macros in the |
376 |
|
obiter.h header file: |
377 |
|
|
388 |
|
double residueMass = 0.0; |
389 |
|
FOR_RESIDUES_OF_MOL(r, mol) |
390 |
|
{ |
391 |
+ |
// The variable r behaves like OBResidue* when used with -> and * but |
392 |
+ |
// but needs to be explicitly converted when appearing as a parameter |
393 |
+ |
// in a function call - use &*r |
394 |
+ |
|
395 |
|
if (r->GetName() == resname && r->GetNum() == rnum) |
396 |
|
{ |
397 |
< |
FOR_ATOMS_OF_RESIDUE(a, r) |
397 |
> |
FOR_ATOMS_OF_RESIDUE(a, &*r) |
398 |
|
{ |
399 |
|
residueMass += a->GetMass(); |
400 |
|
} |