Interacting with surfaces extension from python

Hi!
I’m writing a python extension (pyquante) that can perform molecular orbital
calculations and I want to display the orbitals in the glwidget.I’ve seen
navigating the code that the surfaces extension has the purpose to display
generic surfaces like molecular orbitals, so I thought that may exist a way
to interact with the extension.
However I’m looking for a way to display molecular orbitals, any suggestion?

Regards,

  • Gabriele

On Sunday 07 March 2010 09:17:44 Gabriele Lanaro wrote:

Hi!
I’m writing a python extension (pyquante) that can perform molecular
orbital calculations and I want to display the orbitals in the
glwidget.I’ve seen navigating the code that the surfaces extension has the
purpose to display generic surfaces like molecular orbitals, so I thought
that may exist a way to interact with the extension.
However I’m looking for a way to display molecular orbitals, any
suggestion?

I think the answer depends upon what data you have. There is no mechanism to
interact with extensions from other extensions. It is something we discussed,
which would then require extra API to handle the dependencies and retrieving
the relevant plugin. I certainly think that this would be interesting, but not
sure how easy it would be to add.

If you have a volumetric data set (cube with density) then you could generate
isosurfaces from your code. If you just have GTOs, then it would require more
calcualation, and most of that logic is in the surfaces extension. I have had
far less free time to hack on code, but am working on splitting out a small
library to do these calculations.

If you let me know what kind of output you have to hand off to Avogadro, I can
likely give you a better ideas of what the best way to proceed might be. It
may involve some additional C++ code, but we could probably wrap it in Python.

Marcus

In these days I’ve studied the surfaceextension.cpp code. I found that a way
to display surfaces would be (correct me if I’m wrong):

  1. Generate a Cube instance from my data
  2. Using MeshGenerator to generate an isosurface ( a mesh?)
  3. Display the mesh obtained with the Surface Engine. This is done setting
    the mesh obtained as the “mesh2d” option.

I’m not sure about this path, I’m just guessing this after reading some
code.

My problem now is that I can’t instantiate a Cube object:
import Avogadro
cube = Avogadro.Cube()
RuntimeError: This class cannot be instantiated from Python

I really need some suggestions!

  • Gabriele

2010/3/7 Marcus D. Hanwell marcus@cryos.org

On Sunday 07 March 2010 09:17:44 Gabriele Lanaro wrote:

Hi!
I’m writing a python extension (pyquante) that can perform molecular
orbital calculations and I want to display the orbitals in the
glwidget.I’ve seen navigating the code that the surfaces extension has
the
purpose to display generic surfaces like molecular orbitals, so I thought
that may exist a way to interact with the extension.
However I’m looking for a way to display molecular orbitals, any
suggestion?

I think the answer depends upon what data you have. There is no mechanism
to
interact with extensions from other extensions. It is something we
discussed,
which would then require extra API to handle the dependencies and
retrieving
the relevant plugin. I certainly think that this would be interesting, but
not
sure how easy it would be to add.

If you have a volumetric data set (cube with density) then you could
generate
isosurfaces from your code. If you just have GTOs, then it would require
more
calcualation, and most of that logic is in the surfaces extension. I have
had
far less free time to hack on code, but am working on splitting out a small
library to do these calculations.

If you let me know what kind of output you have to hand off to Avogadro, I
can
likely give you a better ideas of what the best way to proceed might be. It
may involve some additional C++ code, but we could probably wrap it in
Python.

Marcus

On Wed, Mar 10, 2010 at 2:01 PM, Gabriele Lanaro
gabriele.lanaro@gmail.com wrote:

In these days I’ve studied the surfaceextension.cpp code. I found that a way
to display surfaces would be (correct me if I’m wrong):

  1. Generate a Cube instance from my data
  2. Using MeshGenerator to generate an isosurface ( a mesh?)
  3. Display the mesh obtained with the Surface Engine. This is done setting
    the mesh obtained as the “mesh2d” option.
    I’m not sure about this path, I’m just guessing this after reading some
    code.
    My problem now is that I can’t instantiate a Cube object:
    import Avogadro
    cube = Avogadro.Cube()
    RuntimeError: This class cannot be instantiated from Python

If you have a molecule, you can create a new cube by calling the
addCube() function:

cube = molecule.addCube()

I’m not sure if it is currently possible to generate surfaces from
python though.

Tim

I really need some suggestions!

On Sunday 07 March 2010 09:17:44 Gabriele Lanaro wrote:

Hi!
I’m writing a python extension (pyquante) that can perform molecular
orbital calculations and I want to display the orbitals in the
glwidget.I’ve seen navigating the code that the surfaces extension has
the
purpose to display generic surfaces like molecular orbitals, so I
thought
that may exist a way to interact with the extension.
However I’m looking for a way to display molecular orbitals, any
suggestion?

I think the answer depends upon what data you have. There is no mechanism
to
interact with extensions from other extensions. It is something we
discussed,
which would then require extra API to handle the dependencies and
retrieving
the relevant plugin. I certainly think that this would be interesting, but
not
sure how easy it would be to add.

If you have a volumetric data set (cube with density) then you could
generate
isosurfaces from your code. If you just have GTOs, then it would require
more
calcualation, and most of that logic is in the surfaces extension. I have
had
far less free time to hack on code, but am working on splitting out a
small
library to do these calculations.

If you let me know what kind of output you have to hand off to Avogadro, I
can
likely give you a better ideas of what the best way to proceed might be.
It
may involve some additional C++ code, but we could probably wrap it in
Python.

Marcus


Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

I’ve tried a small script to test if I could generate surfaces… please
read comments


… in performAction …
engines = glwidget.engines
for i,engine in enumerate(glwidget.engines):
print “Name”,engine.name # Bug, it gives nothing intelligible
print “Alias”,engine.alias # Bug, same as before
print “Primitives”, engine.primitiveTypes # Gives Surface, 3, Atoms
etc…
print “index”,i

cube = glwidget.molecule.addCube()

dim = array([5,5,5])
min = -array([10.0,10.0,10.0])
max = array([10.0,10.0,10.0])
cube.setLimits(min,max,dim)

data = []
for i in range(125):
  data.append(sin(i/5.0))
cube.setData(data)

ID = 12
mesh = glwidget.molecule.addMesh(ID)

iso = 1.0
mesh_gen = Avogadro.MeshGenerator()
initialized = mesh_gen.initialize(cube,mesh,iso)

mesh_gen.run()

import time
time.sleep(1) # wait 1 second to get the mesh generated

surface_engine=glwidget.engines[1] # The one with primitiveType =

Surfaces
settings = QSettings(“mesh1Id”,ID)
surface_engine.readSettings(settings)
# Segmentation fault

surface_engine.enabled = True
glwidget.molecule.update()

So… there are some bugs you may be interested, and a segfault.

I’ve done something wrong?
Will be supported the python surface generation someday? Is something easily
fixable?

Thank you,

  • Gabriele

2010/3/10 Tim Vandermeersch tim.vandermeersch@gmail.com

On Wed, Mar 10, 2010 at 2:01 PM, Gabriele Lanaro
gabriele.lanaro@gmail.com wrote:

In these days I’ve studied the surfaceextension.cpp code. I found that a
way
to display surfaces would be (correct me if I’m wrong):

  1. Generate a Cube instance from my data
  2. Using MeshGenerator to generate an isosurface ( a mesh?)
  3. Display the mesh obtained with the Surface Engine. This is done
    setting
    the mesh obtained as the “mesh2d” option.
    I’m not sure about this path, I’m just guessing this after reading some
    code.
    My problem now is that I can’t instantiate a Cube object:
    import Avogadro
    cube = Avogadro.Cube()
    RuntimeError: This class cannot be instantiated from Python

If you have a molecule, you can create a new cube by calling the
addCube() function:

cube = molecule.addCube()

I’m not sure if it is currently possible to generate surfaces from
python though.

Tim

I really need some suggestions!

On Sunday 07 March 2010 09:17:44 Gabriele Lanaro wrote:

Hi!
I’m writing a python extension (pyquante) that can perform molecular
orbital calculations and I want to display the orbitals in the
glwidget.I’ve seen navigating the code that the surfaces extension has
the
purpose to display generic surfaces like molecular orbitals, so I
thought
that may exist a way to interact with the extension.
However I’m looking for a way to display molecular orbitals, any
suggestion?

I think the answer depends upon what data you have. There is no
mechanism
to
interact with extensions from other extensions. It is something we
discussed,
which would then require extra API to handle the dependencies and
retrieving
the relevant plugin. I certainly think that this would be interesting,
but
not
sure how easy it would be to add.

If you have a volumetric data set (cube with density) then you could
generate
isosurfaces from your code. If you just have GTOs, then it would require
more
calcualation, and most of that logic is in the surfaces extension. I
have
had
far less free time to hack on code, but am working on splitting out a
small
library to do these calculations.

If you let me know what kind of output you have to hand off to Avogadro,
I
can
likely give you a better ideas of what the best way to proceed might be.
It
may involve some additional C++ code, but we could probably wrap it in
Python.

Marcus


Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

On Thu, Mar 11, 2010 at 10:06 PM, Gabriele Lanaro
gabriele.lanaro@gmail.com wrote:

I’ve tried a small script to test if I could generate surfaces… please
read comments

… in performAction …
engines = glwidget.engines
for i,engine in enumerate(glwidget.engines):
print “Name”,engine.name # Bug, it gives nothing intelligible
print “Alias”,engine.alias # Bug, same as before
print “Primitives”, engine.primitiveTypes # Gives Surface, 3, Atoms
etc…
print “index”,i

cube = glwidget.molecule.addCube()
dim = array([5,5,5])
min = -array([10.0,10.0,10.0])
max = array([10.0,10.0,10.0])
cube.setLimits(min,max,dim)
data = []
for i in range(125):
  data.append(sin(i/5.0))
cube.setData(data)
ID = 12
mesh = glwidget.molecule.addMesh(ID)
iso = 1.0
mesh_gen = Avogadro.MeshGenerator()
initialized = mesh_gen.initialize(cube,mesh,iso)
mesh_gen.run()
import time
time.sleep(1) # wait 1 second to get the mesh generated
surface_engine=glwidget.engines[1] # The one with primitiveType =

Surfaces
settings = QSettings(“mesh1Id”,ID)
surface_engine.readSettings(settings)
# Segmentation fault
surface_engine.enabled = True
glwidget.molecule.update()

So… there are some bugs you may be interested, and a segfault.
I’ve done something wrong?
Will be supported the python surface generation someday? Is something easily
fixable?

See the attached script. This requires the latest version from github
though. (I had to add support for MeshGenerator to
Avogadro.toPyQt(…))

Tim

Thank you,

On Wed, Mar 10, 2010 at 2:01 PM, Gabriele Lanaro
gabriele.lanaro@gmail.com wrote:

In these days I’ve studied the surfaceextension.cpp code. I found that a
way
to display surfaces would be (correct me if I’m wrong):

  1. Generate a Cube instance from my data
  2. Using MeshGenerator to generate an isosurface ( a mesh?)
  3. Display the mesh obtained with the Surface Engine. This is done
    setting
    the mesh obtained as the “mesh2d” option.
    I’m not sure about this path, I’m just guessing this after reading some
    code.
    My problem now is that I can’t instantiate a Cube object:
    import Avogadro
    cube = Avogadro.Cube()
    RuntimeError: This class cannot be instantiated from Python

If you have a molecule, you can create a new cube by calling the
addCube() function:

cube = molecule.addCube()

I’m not sure if it is currently possible to generate surfaces from
python though.

Tim

I really need some suggestions!

On Sunday 07 March 2010 09:17:44 Gabriele Lanaro wrote:

Hi!
I’m writing a python extension (pyquante) that can perform molecular
orbital calculations and I want to display the orbitals in the
glwidget.I’ve seen navigating the code that the surfaces extension
has
the
purpose to display generic surfaces like molecular orbitals, so I
thought
that may exist a way to interact with the extension.
However I’m looking for a way to display molecular orbitals, any
suggestion?

I think the answer depends upon what data you have. There is no
mechanism
to
interact with extensions from other extensions. It is something we
discussed,
which would then require extra API to handle the dependencies and
retrieving
the relevant plugin. I certainly think that this would be interesting,
but
not
sure how easy it would be to add.

If you have a volumetric data set (cube with density) then you could
generate
isosurfaces from your code. If you just have GTOs, then it would
require
more
calcualation, and most of that logic is in the surfaces extension. I
have
had
far less free time to hack on code, but am working on splitting out a
small
library to do these calculations.

If you let me know what kind of output you have to hand off to
Avogadro, I
can
likely give you a better ideas of what the best way to proceed might
be.
It
may involve some additional C++ code, but we could probably wrap it in
Python.

Marcus


Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options

Good Work! I’ve tested your code and it works fine.

Thank you very much for your help and I apologize for having troubled you so
much. However I’ll write some documentation about displaying surfaces with
python.

Thank you again!

  • Gabriele

P.S

engine.name doesn’t mach Surfaces on my machine, nor engine.primitiveTypes.
The only way I can match something is that:

  if repr(engine.primitiveTypes) == "Avogadro.PrimitiveTypes.Surfaces":
    surfaceEngine = engine

I append some examples of my output:

Name Ael
Alias Ael
Primitives Fragments
index 0
Name SpriiŹŹ
Alias Sprii＀＀＀
Primitives Surfaces
index 1
Name Fra
Alias Fra
Primitives 3
index 2
Name PlgnŹ
Alias PlgnŹ
Primitives Atoms
index 3

2010/3/11 Tim Vandermeersch tim.vandermeersch@gmail.com

On Thu, Mar 11, 2010 at 10:06 PM, Gabriele Lanaro
gabriele.lanaro@gmail.com wrote:

I’ve tried a small script to test if I could generate surfaces… please
read comments

… in performAction …
engines = glwidget.engines
for i,engine in enumerate(glwidget.engines):
print “Name”,engine.name # Bug, it gives nothing
intelligible
print “Alias”,engine.alias # Bug, same as before
print “Primitives”, engine.primitiveTypes # Gives Surface, 3, Atoms
etc…
print “index”,i

cube = glwidget.molecule.addCube()
dim = array([5,5,5])
min = -array([10.0,10.0,10.0])
max = array([10.0,10.0,10.0])
cube.setLimits(min,max,dim)
data = []
for i in range(125):
  data.append(sin(i/5.0))
cube.setData(data)
ID = 12
mesh = glwidget.molecule.addMesh(ID)
iso = 1.0
mesh_gen = Avogadro.MeshGenerator()
initialized = mesh_gen.initialize(cube,mesh,iso)
mesh_gen.run()
import time
time.sleep(1) # wait 1 second to get the mesh generated
surface_engine=glwidget.engines[1] # The one with primitiveType =

Surfaces
settings = QSettings(“mesh1Id”,ID)
surface_engine.readSettings(settings)
# Segmentation fault
surface_engine.enabled = True
glwidget.molecule.update()

So… there are some bugs you may be interested, and a segfault.
I’ve done something wrong?
Will be supported the python surface generation someday? Is something
easily
fixable?

See the attached script. This requires the latest version from github
though. (I had to add support for MeshGenerator to
Avogadro.toPyQt(…))

Tim

Thank you,

On Wed, Mar 10, 2010 at 2:01 PM, Gabriele Lanaro
gabriele.lanaro@gmail.com wrote:

In these days I’ve studied the surfaceextension.cpp code. I found that
a
way
to display surfaces would be (correct me if I’m wrong):

  1. Generate a Cube instance from my data
  2. Using MeshGenerator to generate an isosurface ( a mesh?)
  3. Display the mesh obtained with the Surface Engine. This is done
    setting
    the mesh obtained as the “mesh2d” option.
    I’m not sure about this path, I’m just guessing this after reading
    some
    code.
    My problem now is that I can’t instantiate a Cube object:
    import Avogadro
    cube = Avogadro.Cube()
    RuntimeError: This class cannot be instantiated from Python

If you have a molecule, you can create a new cube by calling the
addCube() function:

cube = molecule.addCube()

I’m not sure if it is currently possible to generate surfaces from
python though.

Tim

I really need some suggestions!

On Sunday 07 March 2010 09:17:44 Gabriele Lanaro wrote:

Hi!
I’m writing a python extension (pyquante) that can perform
molecular
orbital calculations and I want to display the orbitals in the
glwidget.I’ve seen navigating the code that the surfaces extension
has
the
purpose to display generic surfaces like molecular orbitals, so I
thought
that may exist a way to interact with the extension.
However I’m looking for a way to display molecular orbitals, any
suggestion?

I think the answer depends upon what data you have. There is no
mechanism
to
interact with extensions from other extensions. It is something we
discussed,
which would then require extra API to handle the dependencies and
retrieving
the relevant plugin. I certainly think that this would be
interesting,
but
not
sure how easy it would be to add.

If you have a volumetric data set (cube with density) then you could
generate
isosurfaces from your code. If you just have GTOs, then it would
require
more
calcualation, and most of that logic is in the surfaces extension. I
have
had
far less free time to hack on code, but am working on splitting out a
small
library to do these calculations.

If you let me know what kind of output you have to hand off to
Avogadro, I
can
likely give you a better ideas of what the best way to proceed might
be.
It
may involve some additional C++ code, but we could probably wrap it
in
Python.

Marcus


Download Intel® Parallel Studio Eval
Try the new software tools for yourself. Speed compiling, find bugs
proactively, and fine-tune applications for parallel performance.
See why Intel Parallel Studio got high marks during beta.
http://p.sf.net/sfu/intel-sw-dev


Avogadro-devel mailing list
Avogadro-devel@lists.sourceforge.net
avogadro-devel List Signup and Options