Python molecular viewer

Paul McGuire ptmcg at austin.rr.com
Thu Aug 30 09:22:27 CEST 2007


On Aug 29, 8:31 am, Andy Cheesman <Andy.chees... at bristol.ac.uk> wrote:
> Dear People,
>
> I was wondering if people could recommend a simple molecular viewing
> package written in python. I'm working in Theoretical chemistry and I'm
> not after an all-singing dancing molecular rendering package(pymol does
> that rather well) but a program which reads XYZ files and displays
> simple structures which can be rotated in 3D
>
> Thanks
>
> Andy

slut is an OpenGL wrapper that I found to be very intuitive to use,
and comes with some simple "moving ball" animations, but the
animations also can be panned, zoomed, and rotated.  In your case, you
wouldn't need to do the animation, just plot the balls in 3D and then
pan and zoom to your heart's content.

Here is a simple program that plots a series of points on a sphere:

from slut import *

# points on a sphere
data = [
(1.0, 0.0, 0.0),
 (0.945, 0.0, -0.325),
 (0.789, 0.0, -0.613),
 (0.547, 0.0, -0.836),
 (0.246, 0.0, -0.968),
 (-0.083, 0.0, -0.997),
 (-0.402, 0.0, -0.916),
 (-0.677, 0.0, -0.735),
...
 (-0.078, 0.027, 0.997),
 (0.232, -0.080, 0.968),
 (0.517, -0.177, 0.836),
 (0.746, -0.256, 0.613),
 (0.895, -0.307, 0.325),
 (0.945, -0.325, 0.0) ]

from slut import *

class SphereViewer(World):
    def onSetup(self):
        self.width = 400
        self.height = 400
        self.name = "Points on a Sphere"

    def onDraw(self):
        # draw translucent sphere
        glColor4f(0.7, 0.7, 0.7, 0.5)
        sphere(0, 0, 0, 1.0)
        glColor4f(0.3, 0.3, 0.4, 1.0)

        # plot points on surface
        glPointSize(4)
        for d in data:
            point(*d)

        # connect points with path
        glLineWidth(1.5)
        lastd = data[-1]
        for d in data:
            line( *(lastd + d) )
            lastd = d

viewer = SphereViewer()
viewer.run()

And here is a short Wink video showing me working with a simplified
version of this sphere: http://www.geocities.com/ptmcg/python/sphere1.htm.

If you have your molecules' 3D coordinates, you should be able to just
plot them, and then use slut to view the molecule.

-- Paul




More information about the Python-list mailing list