Hey Donald,
Thanks for your reply.
I’ve been away from the project for a while but looking at the API docs, OBMol is a function that returns an OBMol based on the
Avogadro::Molecule. Have you tried:
obmol = mol.OBMol()
I think what I passed along was the last of my efforts and
unfortunately not the whole arsenal. Nonetheless, I tried that, and it
results in
Traceback (most recent call last):
File “/home/cstein/.avogadro/extensionScripts/bare.py”, line 23, in
performAction
obmol = mol.OBMol()
TypeError: ‘PySwigObject’ object is not callable
but this is because it is defined as a property in the source code
.add_property(“OBMol”, &Molecule_OBMol, &Molecule_setOBMol)
In the python code, I can do this instead
mol = glwidget.molecule
obmol = mol.OBMol
print type(mol), type(obmol)
which prints out:
<class ‘Avogadro.Molecule’> <type ‘PySwigObject’>
but parsing the obmol variable to openbabel
myobmol = openbabe.OBMol( obmol )
gives
Traceback (most recent call last):
File “/home/cstein/.avogadro/extensionScripts/bare.py”, line 24, in
performAction
myobmol = openbabel.OBMol( obmol )
File “/usr/local/lib/python2.6/dist-packages/openbabel.py”, line
2061, in init
_openbabel.OBMol_swiginit(self,_openbabel.new_OBMol(*args))
TypeError: in method ‘new_OBMol’, argument 1 of type ‘OpenBabel::OBMol const &’
As a side note, I love C++ but I don’t think anyone thinks it’s necessary to use C++ and would agree with you about writing a python extension.
Yeah well, it was just a spicy comment at a weak moment I’ve never
settled quite with C++ and still have a few issues with it, but it is
getting better. I’d be all over Avogadro (Konstantin style) if I was
any better with C++, but instead, I’m trying to master the Avogadro
API through magical glue of python before I’ll pull out any of the big
guns.
Thanks for your comments though,
On Nov 5, 2010, at 11:32 AM, Casper Steinmann wrote:
Hi,
I’ve written a python script that uses openbabel to calculate some
properties. Now, I’d like to try and get this to work with Avogadro in
an extension using python. The problem is, that while the
Avogadro.Molecule class does a good in covering the basic needs of
most molecule manipulation, you sometimes need access to OpenBabel
features (which can be done if oneuses C++ to program the extension).
It is my understanding (from the API documentation:
http://avogadro.openmolecules.net/wiki/API_Documentation) that there
is no direct link between the python bindings and openbabel, i.e. no
exposed openbabel API through avogadro python bindings. The last
resort is thus to try and get the OBMol object from the
Avogadro.Molecule class
but how can this be done? I’ve tried the following
import openbabel
import Avogadro
from PyQt4.QtCore import *
from PyQt4.QtGui import *
class Extension(QObject):
def init(self):
QObject.init(self)
def actions(self):
actions =
action = QAction(self)
action.setText(“Calculate”)
actions.append(action)
return actions
def menuPath(self, action):
return “E&xtensions”
def performAction(self, action, glwidget):
convert Avogadro.Molecule to OpenBabels OBMol
mol = glwidget.molecule
print mol, mol.OBMol
obmol = openbabel.OBMol( mol )
the print statement reveals the following:
<Avogadro.Molecule object at 0x2b1af30> <Swig Object of type
‘OpenBabel::OBMol *’ at 0x3a90230>
which reveals that mol.OBMol indeed has the correct type(apart from
the asterisk) where the openbabel.OBMol returns the following error
when called:
_openbabel.OBMol_swiginit(self,_openbabel.new_OBMol(*args))
TypeError: in method ‘new_OBMol’, argument 1 of type ‘OpenBabel::OBMol const &’
And now I’m kinda stuck. Any ideas what to do?
There is the obvious: “switch to c++”, but it kinda defeats the whole
purpose of being able to write the extensions in python.
Kind Regards,
Casper
The Next 800 Companies to Lead America’s Growth: New Video Whitepaper
David G. Thomson, author of the best-selling book “Blueprint to a
Billion” shares his insights and actions to help propel your
business during the next growth cycle. Listen Now!
http://p.sf.net/sfu/SAP-dev2dev
Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
avogadro-discuss List Signup and Options
Centralized Desktop Delivery: Dell and VMware Reference Architecture
Simplifying enterprise desktop deployment and management using
Dell EqualLogic storage and VMware View: A highly scalable, end-to-end
client virtualization framework. Read more!
http://p.sf.net/sfu/dell-eql-dev2dev
Avogadro-Discuss mailing list
Avogadro-Discuss@lists.sourceforge.net
avogadro-discuss List Signup and Options