Relaxing before weekend – PDB file and Panda3D

15 Aug

Software for visualization of molecules is in majority of cases very focused on its job and rarely allows for something outside its scope (one of exceptions is VMD – you can plot 3d surfaces using its graphic engine). Every couple of months I check status of various 3D engines to see how they are suited for molecular visualization. Recently, I had another look at Panda3D, free 3D engine Disney is using to do some of its games. As an exercise in Python I’m learning right now, I’ve tried to import a PDB file into Panda3D and rotate it.

Panda3D doesn’t have a native support for molecules, instead it supports its own egg format for models. Fortunately, there’s an egg format exporter for Blender, so I imported hemoglobin molecule in cartoon representation into Blender (procedure described at the bottom of this page) and then exported in Panda3D format. The rest was pure Python (and extensive copy/paste from tutorials found on the web). Following code will load model from hbg.egg file, set up some lights and rotate camera around it.

import direct.directbase.DirectStart
from direct.showbase.DirectObject import DirectObject
from pandac.PandaModules import *
from direct.task import Task
import math

#Load the protein model
protein = loader.loadModel("hbg")

#setup lights
light1 = AmbientLight('light1')
light1.setColor(VBase4(0.12, 0.12, 0.12, 1))
plnp = render.attachNewNode(light1)

light2 = PointLight('pointlight')
plnp2 = render.attachNewNode(light2)

#Task to move the camera
def SpinCameraTask(task):
  angledegrees = task.time * 6.0
  angleradians = angledegrees * (math.pi / 180.0)*math.sin(angleradians),-20.0*math.cos(angleradians),2), 0, 0)
  return Task.cont

taskMgr.add(SpinCameraTask, "SpinCameraTask")


Not so impressive screenshot is shown at the top. It’s not a rocket science and state-of-the art visualization, but I’m positively surprised how easy is today to get such thing up and running. Game industry is a large one and even proprietary engines are quite cheap (for non-commercial purposes one can have them for small hundreds of dollars), so I expect quite a few scientific projects built on such platforms coming soon. SL engine is not the last one to be used for such purpose.

Reblog this post [with Zemanta]

Posted by on August 15, 2008 in Visualization


Tags: , , , ,

2 responses to “Relaxing before weekend – PDB file and Panda3D

  1. Joerg Kurt Wegner

    August 15, 2008 at 20:09

    Is there already a full overview about all the 3D visualization tools for PDB structures?
    Might be something interesting to see.

    Beside the visualization, some ‘general purpose’ number crunching seems to have benefits, too.

  2. Pawel Szczesny

    August 15, 2008 at 20:35

    Joerg, I’m not aware of any such overview. SDSC hosts a molecular visualization resources page: but any in depth of analysis or comparison is not available. Thanks for the links. People from TCBG from Urbana-Champaign do some of the coolest things in this area.

%d bloggers like this: