RSS

Tag Archives: 3D modeling

Relaxing before weekend – PDB file and Panda3D

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")
protein.reparentTo(render)
protein.setScale(1.4)
protein.setPos(0,0,2)

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

light2 = PointLight('pointlight')
plnp2 = render.attachNewNode(light2)
plnp2.setPos(0,0,2)
render.setLight(plnp2)

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

base.setBackgroundColor(0.0,0.0,0.0)
taskMgr.add(SpinCameraTask, "SpinCameraTask")

run()

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]
 
2 Comments

Posted by on August 15, 2008 in Visualization

 

Tags: , , , ,