|
From: Tim V. <tim...@gm...> - 2008-04-29 23:45:45
|
On Wed, Apr 30, 2008 at 1:33 AM, Rahul Nabar <rp...@gm...> wrote:
> On Tue, Apr 29, 2008 at 12:30 PM, Noel O'Boyle <bao...@gm...> wrote:
> > The Python API *is* the OpenBabel API. However, you are probably
> > confused by Pybel, which is a layer on top of the Python API.
> > OBMol::ConnectTheDots() needs an OBMol to begin with. You can access
> > the OBMol behind a Pybel Molecule as follows:
> >
> > import pybel
> > mol = pybel.readfile("xyz", "myfile.xyz").next()
> > obmol = mol.OBMol
> > obmol.ConnectTheDots()
> > obmol.PerceiveBondOrders()
>
> Thanks Noel. I did that now. But there is no apparent output. I
> suspect the obmol data-structure already has the information I need
> but how do I manage to query it? My purpose is pretty straightforward:
> Find and print all bonds (and perhaps bond-lengths) in this set of
> atoms. I'm sorry if this is elementary and I hat to bother you guys
> for something that might be easily understood from a tutorial perhaps?
> Are there any of this sort?
>
> I looked up http://openbabel.org/wiki/Python but most of the examples
> seem to be oriented towards setting up the molecules rather than
> importing and querying a preexisting .xyz file.
Check the "Using iterators" part:
Once you have the mol, you can do
for bond in openbabel.OBMolBondIter(mol):
print "bond ", bond.GetIdx(), ": length = ", bond.GetLength()
Tim
|