Possible to access OpenBabel library from Avogadro Python interface

I’m wondering whether I can access the OpenBabel library through the
Python interface to Avogadro. For example, let’s suppose I create a
new Avogadro molecule and add a couple of atoms. Can I then call
ConnectTheDots() and PerceiveBondOrders() somehow? (I can workaround
this by using the OB Python interface directly, of course - I’m just
wondering whether I can go through Avogadro somehow)

  • Noel

new Avogadro molecule and add a couple of atoms. Can I then call
ConnectTheDots() and PerceiveBondOrders() somehow? (I can workaround

What you would do is call the OBMol() method from the Avogadro
molecule. Think of it a bit like Pybel. An Avogadro molecule isn’t
directly an Open Babel molecule, but you can get an OBMol easily.

Cheers,
-Geoff

2009/10/27 Geoffrey Hutchison geoff.hutchison@gmail.com:

new Avogadro molecule and add a couple of atoms. Can I then call
ConnectTheDots() and PerceiveBondOrders() somehow? (I can workaround

What you would do is call the OBMol() method from the Avogadro molecule.
Think of it a bit like Pybel. An Avogadro molecule isn’t directly an Open
Babel molecule, but you can get an OBMol easily.

I saw that. But the result seems to just be a pointer to the OBMol,
without any way to access any of its methods (presumably this is
different in C++).

print mol
<Avogadro.Molecule object at 0x0BE1B260>

print mol.OBMol
_d84b0f0f_p_OpenBabel__OBMol

print dir(mol.OBMol)
[‘class’, ‘cmp’, ‘delattr’, ‘doc’, ‘format’,
getattribute’, ‘hash’, ‘hex’, ‘init’, ‘int’,
long’, ‘new’, ‘oct’, ‘reduce’, ‘reduce_ex’,
repr’, ‘setattr’, ‘sizeof’, ‘str’,
subclasshook’, ‘acquire’, ‘append’, ‘disown’, ‘next’, ‘own’]

print mol.OBMol()
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘PySwigObject’ object is not callable

  • Noel

On Tue, Oct 27, 2009 at 12:49 PM, Noel O’Boyle baoilleach@gmail.com wrote:

2009/10/27 Geoffrey Hutchison geoff.hutchison@gmail.com:

new Avogadro molecule and add a couple of atoms. Can I then call
ConnectTheDots() and PerceiveBondOrders() somehow? (I can workaround

What you would do is call the OBMol() method from the Avogadro molecule.
Think of it a bit like Pybel. An Avogadro molecule isn’t directly an Open
Babel molecule, but you can get an OBMol easily.

I saw that. But the result seems to just be a pointer to the OBMol,
without any way to access any of its methods (presumably this is
different in C++).

print mol
<Avogadro.Molecule object at 0x0BE1B260>

print mol.OBMol
_d84b0f0f_p_OpenBabel__OBMol

print dir(mol.OBMol)
[‘class’, ‘cmp’, ‘delattr’, ‘doc’, ‘format’,
getattribute’, ‘hash’, ‘hex’, ‘init’, ‘int’,
long’, ‘new’, ‘oct’, ‘reduce’, ‘reduce_ex’,
repr’, ‘setattr’, ‘sizeof’, ‘str’,
subclasshook’, ‘acquire’, ‘append’, ‘disown’, ‘next’, ‘own’]

print mol.OBMol()
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘PySwigObject’ object is not callable

This should normally allow you to set/get the OBMol but seems to be
broken :frowning: I’ll have another look at this tonight together with some
other python stuff tonight. The python bindings have been a bit
neglected for 1.0 but this can be fixed for 1.0.1 now.

Cheers,
Tim

  • Noel

Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference


Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avogadro-discuss

2009/10/29 Tim Vandermeersch tim.vandermeersch@gmail.com:

On Tue, Oct 27, 2009 at 12:49 PM, Noel O’Boyle baoilleach@gmail.com wrote:

2009/10/27 Geoffrey Hutchison geoff.hutchison@gmail.com:

new Avogadro molecule and add a couple of atoms. Can I then call
ConnectTheDots() and PerceiveBondOrders() somehow? (I can workaround

What you would do is call the OBMol() method from the Avogadro molecule.
Think of it a bit like Pybel. An Avogadro molecule isn’t directly an Open
Babel molecule, but you can get an OBMol easily.

I saw that. But the result seems to just be a pointer to the OBMol,
without any way to access any of its methods (presumably this is
different in C++).

print mol
<Avogadro.Molecule object at 0x0BE1B260>

print mol.OBMol
_d84b0f0f_p_OpenBabel__OBMol

print dir(mol.OBMol)
[‘class’, ‘cmp’, ‘delattr’, ‘doc’, ‘format’,
getattribute’, ‘hash’, ‘hex’, ‘init’, ‘int’,
long’, ‘new’, ‘oct’, ‘reduce’, ‘reduce_ex’,
repr’, ‘setattr’, ‘sizeof’, ‘str’,
subclasshook’, ‘acquire’, ‘append’, ‘disown’, ‘next’, ‘own’]

print mol.OBMol()
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘PySwigObject’ object is not callable

This should normally allow you to set/get the OBMol but seems to be
broken :frowning: I’ll have another look at this tonight together with some
other python stuff tonight. The python bindings have been a bit
neglected for 1.0 but this can be fixed for 1.0.1 now.

That would be great. BTW, this was on Windows. I saw a note on
Launchpad that Ubuntu are going to compile Avogadro without Python
support. That would be a real shame. Also, I note that I wasn’t able
to compile Avogadro with the packages available in Ubuntu 9.04 (the
current release) which is also a shame (it misses out on the required
Qt by 0.02). This considerably reduces the number of users who will
compile Avogadro themselves.

Cheers,
Tim

  • Noel

Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference


Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avogadro-discuss

On Thu, Oct 29, 2009 at 12:14 PM, Tim Vandermeersch
tim.vandermeersch@gmail.com wrote:

On Tue, Oct 27, 2009 at 12:49 PM, Noel O’Boyle baoilleach@gmail.com wrote:

2009/10/27 Geoffrey Hutchison geoff.hutchison@gmail.com:

new Avogadro molecule and add a couple of atoms. Can I then call
ConnectTheDots() and PerceiveBondOrders() somehow? (I can workaround

What you would do is call the OBMol() method from the Avogadro molecule.
Think of it a bit like Pybel. An Avogadro molecule isn’t directly an Open
Babel molecule, but you can get an OBMol easily.

I saw that. But the result seems to just be a pointer to the OBMol,
without any way to access any of its methods (presumably this is
different in C++).

print mol
<Avogadro.Molecule object at 0x0BE1B260>

print mol.OBMol
_d84b0f0f_p_OpenBabel__OBMol

Try this, I forgot how the OBMol worked in python :s You need to use
the openbabel.OBMol(OBMol) copy constructor with the Avogadro
molecule’s OBMol as argument. I’ll update the documentation but this
is still very experimental.

print Avogadro.molecule.OBMol
_c0721d0200000000_p_OpenBabel__OBMol

import openbabel
print openbabel.OBMol(Avogadro.molecule.OBMol) <------------------------------------------------- this line
<openbabel.OBMol; proxy of <Swig Object of type 'OpenBabel::OBMol *'
at 0x42cc3b0> >

print openbabel.OBMol(Avogadro.molecule.OBMol).NumAtoms()
10

This requires the openbabel python package to be installed in the same
python installation (i.e. the C:\Program
Files\Avogadro\bin\lib\site-packages) For future versions we could
include the openbabel python package to make it easier but for now you
can probably copy the needed files.

Cheers,
Tim

print dir(mol.OBMol)
[‘class’, ‘cmp’, ‘delattr’, ‘doc’, ‘format’,
getattribute’, ‘hash’, ‘hex’, ‘init’, ‘int’,
long’, ‘new’, ‘oct’, ‘reduce’, ‘reduce_ex’,
repr’, ‘setattr’, ‘sizeof’, ‘str’,
subclasshook’, ‘acquire’, ‘append’, ‘disown’, ‘next’, ‘own’]

print mol.OBMol()
Traceback (most recent call last):
File “”, line 1, in
TypeError: ‘PySwigObject’ object is not callable

This should normally allow you to set/get the OBMol but seems to be
broken :frowning: I’ll have another look at this tonight together with some
other python stuff tonight. The python bindings have been a bit
neglected for 1.0 but this can be fixed for 1.0.1 now.

Cheers,
Tim

  • Noel

Come build with us! The BlackBerry® Developer Conference in SF, CA
is the only developer event you need to attend this year. Jumpstart your
developing skills, take BlackBerry mobile applications to market and stay
ahead of the curve. Join us from November 9 - 12, 2009. Register now!
http://p.sf.net/sfu/devconference


Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/avogadro-discuss

2009/10/29 Tim Vandermeersch tim.vandermeersch@gmail.com:

On Thu, Oct 29, 2009 at 12:14 PM, Tim Vandermeersch
tim.vandermeersch@gmail.com wrote:

On Tue, Oct 27, 2009 at 12:49 PM, Noel O’Boyle baoilleach@gmail.com wrote:

2009/10/27 Geoffrey Hutchison geoff.hutchison@gmail.com:

new Avogadro molecule and add a couple of atoms. Can I then call
ConnectTheDots() and PerceiveBondOrders() somehow? (I can workaround

What you would do is call the OBMol() method from the Avogadro molecule.
Think of it a bit like Pybel. An Avogadro molecule isn’t directly an Open
Babel molecule, but you can get an OBMol easily.

I saw that. But the result seems to just be a pointer to the OBMol,
without any way to access any of its methods (presumably this is
different in C++).

print mol
<Avogadro.Molecule object at 0x0BE1B260>

print mol.OBMol
_d84b0f0f_p_OpenBabel__OBMol

Try this, I forgot how the OBMol worked in python :s You need to use
the openbabel.OBMol(OBMol) copy constructor with the Avogadro
molecule’s OBMol as argument. I’ll update the documentation but this
is still very experimental.

print Avogadro.molecule.OBMol
_c0721d0200000000_p_OpenBabel__OBMol

import openbabel
print openbabel.OBMol(Avogadro.molecule.OBMol) <------------------------------------------------- this line
<openbabel.OBMol; proxy of <Swig Object of type 'OpenBabel::OBMol *'
at 0x42cc3b0> >

print openbabel.OBMol(Avogadro.molecule.OBMol).NumAtoms()
10

This requires the openbabel python package to be installed in the same
python installation (i.e. the C:\Program
Files\Avogadro\bin\lib\site-packages) For future versions we could
include the openbabel python package to make it easier but for now you
can probably copy the needed files.

Ah, right - that’s great - that’s all I need. Actually, you can add
folders to sys.path and then there’s no problem importing packages
from the standard Python installation.