Python

I am learning Python (slowly) in order to be able to hopefully construct a
plugin which will allow me to adjust the shape of molecules.

Although I haven’t progressed too far yet, I wanted to play with the Python
display engine, shown as an example at
http://avogadro.openmolecules.net/wiki/Python_Engines

What is the environment to test this

import Avogadro

class Engine():
def renderOpaque(self, pd):
pd.painter.drawText(50, 50, “Hello World”)

Is it in my terminal?

Thank you.

You can put in .py file the following code :

from PyQt4.Qt import * # Import Qt library
import Avogadro

class Engine(QObject):

constructor

def init(self):
QObject.init(self)

def name(self):
return “Hello World plugin”

def renderOpaque(self, pd):

  • pd : type* Avogadro.painterDevice.

pd.painter.drawText( 50, 50, "Hello world" )

In :

  • /usr/local/share/libavogadro/engineScripts (need sudo for ubuntu)
  • or /home/user_name/.avogadro/engineScripts/

Then you must active it : in “Render Type” menu (I do not sure for the
vocabulary, I do not work with english version) where you can select
wireframe render & co, add it, then active it.
For error, verifies the messages in the message window in Avogadro.

If you search features on Avogadro methods in Python, in Python terminal,
put :
import Avogadro
help( Avogadro )
And copy it in a file (it is not a great method, but after this file will be
very practical).

I find that working directly in the terminal is not pratical, exect for
testing few lines, methods … (not class).

Mickaël Gadroy

I put Testfile.py (my .py file for the above file) into
/home/user_name/.avogadro/engineScripts/ however the Display Types menu is
not showing it (to be able to add it)

On Mon, May 24, 2010 at 5:28 AM, Mickaël Gadroy mickael.gadroy@gmail.comwrote:

You can put in .py file the following code :

from PyQt4.Qt import * # Import Qt library
import Avogadro

class Engine(QObject):

constructor

def init(self):
QObject.init(self)

def name(self):
return “Hello World plugin”

def renderOpaque(self, pd):

  • pd : type* Avogadro.painterDevice.

pd.painter.drawText( 50, 50, "Hello world" )

In :

  • /usr/local/share/libavogadro/engineScripts (need sudo for ubuntu)
  • or /home/user_name/.avogadro/engineScripts/

Then you must active it : in “Render Type” menu (I do not sure for the
vocabulary, I do not work with english version) where you can select
wireframe render & co, add it, then active it.
For error, verifies the messages in the message window in Avogadro.

If you search features on Avogadro methods in Python, in Python terminal,
put :
import Avogadro
help( Avogadro )
And copy it in a file (it is not a great method, but after this file will
be very practical).

I find that working directly in the terminal is not pratical, exect for
testing few lines, methods … (not class).

Mickaël Gadroy

Try step by step :

  1. Verify if there are no errors (in Avogadro, at the bottom, click on
    Messages)
  2. If the plugin is integrated, it should be visible in Parameter
    ->Configure Avogadro -> Plugin manager -> Plugin -> Display type
    • If no present, verify your path, or/and try the other path (to be
      sure, a Python engine plugin, wireframe.py, is already present)
  3. Then, in Display Types menu, you can add/remove/duplicate render plugin,
    click on Add button …
    • if it is not present in combo box … I hope that someone has a idea.

Mickaël Gadroy