Problems with python scripts

Hi there,

I have been using avogadro 0.8.x as packaged by debian.
Recently I have upgraded to 0.9.2 as it became available in debian
testing. From 0.8.x to 0.9.x the programming interface has
signifficantly changed and I’ve been trying to adapt my
0.8.x python extension scripts. However, it hasn’t been a
trivial task.

I have been having extreme difficulty on doing such basic
things as getting the coordinates of a molecule’s atom.
As an example of the problems I include as attachment to this
email a script were I attempt to simply do this iteration:

 for bond in mol.bonds:
   beginAtom = mol.atomById(bond.beginAtomId)
   endAtom = mol.atomById(bond.endAtomId)

that I found in the example engine python script wireframe.py
which is included in the avogadro distribution. This wireframe.py
script does work, but mine fails with the message:

Traceback (most recent call last):
File “/home/ajpalace/.avogadro/extensionScripts/MyTest.py”, line 45,
in performAction
for bond in mol.bonds:
TypeError: ‘property’ object is not iterable

What is wrong?
I also include a similarly simple second script, this time with
an iteration over mol.atoms which fails with a similar message.

I have been having quite some trouble in running python scripts
with the new 0.9.x versions! First, I now that is not your fault
but the debian package does not include the Avogrado.so file that
has the python module library!!! It took me some time until I found
out why no python scripts appeared in the menu.
I had to recompile the debian source and get this file from it.
Afterwards I could now get the examples provided with the distribution
but could not run my own scripts. I mean, I could run them but with
these error messages.
I eventually removed the debian packages and compiled the avogadro
source downloaded directly from your site. But the problem, as I
described it, persists.

Now, what I would like to know is if the python module has been tested
with user scripts and is currently working with everybody else, meaning
that there is specifically a problem with my system, and if you
could check on the examples I am including in this message to see
if I am doing anything wrong (I don’t think I am!).

Thank you very much.
Apart from the problems I am having to run python scripts under
the 0.9.x versions, I have been enjoying this program very much.
Congratulations and thanks for your work on avogadro.

Cheers,
Alfredo

On Tue, Apr 7, 2009 at 10:10 AM, Alfredo Palace Carvalho
ajpalace@uevora.pt wrote:

Hi there,

I have been having quite some trouble in running python scripts
with the new 0.9.x versions! First, I now that is not your fault
but the debian package does not include the Avogrado.so file that
has the python module library!!! It took me some time until I found
out why no python scripts appeared in the menu.
I had to recompile the debian source and get this file from it.
Afterwards I could now get the examples provided with the distribution
but could not run my own scripts. I mean, I could run them but with
these error messages.
I eventually removed the debian packages and compiled the avogadro
source downloaded directly from your site. But the problem, as I
described it, persists.

Getting the python extension ready for Debian has turned out to be
non-trivial. It involves creating new python-avogadro packages and
figuring out how to build the python extension for multiple python
versions. We’re working on getting it done for Avogadro 0.9.3.

-Jordan

On Tue, Apr 07, 2009 at 10:53:26AM -0700, Jordan Mantha wrote:

On Tue, Apr 7, 2009 at 10:10 AM, Alfredo Palace Carvalho
ajpalace@uevora.pt wrote:

Hi there,

I have been having quite some trouble in running python scripts
with the new 0.9.x versions! First, I now that is not your fault
but the debian package does not include the Avogrado.so file that
has the python module library!!! It took me some time until I found
out why no python scripts appeared in the menu.
I had to recompile the debian source and get this file from it.
Afterwards I could now get the examples provided with the distribution
but could not run my own scripts. I mean, I could run them but with
these error messages.
I eventually removed the debian packages and compiled the avogadro
source downloaded directly from your site. But the problem, as I
described it, persists.

Getting the python extension ready for Debian has turned out to be
non-trivial. It involves creating new python-avogadro packages and
figuring out how to build the python extension for multiple python
versions. We’re working on getting it done for Avogadro 0.9.3.

This should be available now, at least in Debian unstable.

Michael

Hello,

I am glad to hear those news.
I will try the unstable package as soon as it is available (it is still
not visible after “apt-get update” yet)
Nevertheless, this issue with the python versions in debian does it
affect your ability to run python extension scripts?
The thing is that I recompiled the debian avogadro source, then created
the package and installed it and afterwards I got the Avogrado.so
file which isn’t included in the debian package and copied it
to a directory in the $PYTHONPATH path. After this I expected
python scripts to just work, and in fact the "Python Examples"
menu becomes available. Running the “Clear molecule” example, which
is included in the package, does work and so it does the “Python
Wireframe Engine” example. But my own scripts, which I included in
the last message, do not work. Is this related in any way with
the fact that the Avogrado.so file was copied by hand and, probably
some extra configuration of the python module was needed?
I will try the Avogadro 0.9.3 as soon as I can and will give my
feedback.

Thanks.
Cheers,
Alfredo

On Thu, 16 Apr 2009, Michael Banck wrote:

On Tue, Apr 07, 2009 at 10:53:26AM -0700, Jordan Mantha wrote:

On Tue, Apr 7, 2009 at 10:10 AM, Alfredo Palace Carvalho
ajpalace@uevora.pt wrote:

Hi there,

I have been having quite some trouble in running python scripts
with the new 0.9.x versions! First, I now that is not your fault
but the debian package does not include the Avogrado.so file that
has the python module library!!! It took me some time until I found
out why no python scripts appeared in the menu.
I had to recompile the debian source and get this file from it.
Afterwards I could now get the examples provided with the distribution
but could not run my own scripts. I mean, I could run them but with
these error messages.
I eventually removed the debian packages and compiled the avogadro
source downloaded directly from your site. But the problem, as I
described it, persists.

Getting the python extension ready for Debian has turned out to be
non-trivial. It involves creating new python-avogadro packages and
figuring out how to build the python extension for multiple python
versions. We’re working on getting it done for Avogadro 0.9.3.

This should be available now, at least in Debian unstable.

Michael

Hello,

I have installed the avogadro 0.9.3 .deb
It now includes the Avogadro.so file as expected but I still cannot
run my python scripts.

I have attempted the simple performAction code

mol = Avogadro.Molecule
self.emit(SIGNAL(“message(const QString&)”), “%d” % int(mol.numAtoms) )

I don’t know PyQt4 and don’t understand this SIGNAL stuff very well
but have been guiding from examples and I think it was supposed to
output in “Messages” the number of atoms of the loaded molecule.
I have attempted without the int type conversion and it complained
about the wrong data type. Running these lines fails with the message

TypeError: int() argument must be a string or a number, not ‘property’

A script which I had tried previously (that I included in my first email
a week ago, if you remember), an iteration over the bonds of the
molecule also failed with a similar cause:

TypeError: ‘property’ object is not iterable

So it seems the problem is that most useful data has a ‘property’ data
type and I seem unable to deal with it. Am I missing something in my
scripts? Or is there some problem with my own system (libs,
configuration, whatever)? Do other people’s python scripts work fine?

Cheers,
Alfredo