From: Noel O'B. <bao...@gm...> - 2006-12-12 12:55:18
|
obiter.h exposes a number of C++ convenience functions for iterating over atoms, bonds, etc. e.g. OBMolAtomIter iterates over the atoms in a molecule. However, these iterator methods don't work very well from scripting languages (I'm not even sure if it's possible to use them as they were designed to be used). It's much easier to use the built-in iterator methods present in the various languages. In Python, the easiest way to do this is to create a list of the atoms of a molecule and then iterate over these: obAtoms = [obMol.GetAtom(i+1) for i in range(obMol.NumAtoms())] for obAtom in obAtoms: # Do something with obAtom It would be very useful to collect such OpenBabel idioms from different scripting languages and put them on the scripting pages (or even include them in the interface files as convenience functions). Could anyone suggest similar code for Perl/Ruby/Java? Noel |