1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
|
from pymol.opengl.gl import *
from pymol.callback import Callback
from pymol import cmd
# this is an example of creating a callback object which
# uses GL arrays. Requires Numeric Python:
from Numeric import *
# define a callback object
class myCallback(Callback):
def __init__(self,b):
self.vert = zeros([126,3],Float)
self.norm = zeros([126,3],Float)
for a in range(0,63):
x = a/10.0+b/10.0
self.vert[2*a][0]=a/10.0
self.vert[2*a][1]=math.sin(x)
self.vert[2*a][2]=0.0
self.vert[2*a+1][0]=self.vert[2*a][0]
self.vert[2*a+1][1]=self.vert[2*a][1]
self.vert[2*a+1][2]=1.0
dydx = -math.cos(x)*sqrt(2)/2.0# is this right? I can't remember...
self.norm[2*a][0]=dydx
self.norm[2*a][1]=math.sqrt(1.0-dydx*dydx)
self.norm[2*a][2]=0.0
self.norm[2*a+1][0]=self.norm[2*a][0]
self.norm[2*a+1][1]=self.norm[2*a][1]
self.norm[2*a+1][2]=self.norm[2*a][2]
def __call__(self):
glColor3f(1.0,1.0,1.0)
glVertexPointer(3,0,self.vert)
glNormalPointer(3,0,self.norm)
glEnable(GL_VERTEX_ARRAY)
glEnable(GL_NORMAL_ARRAY)
glDisable(GL_COLOR_ARRAY)
glDrawArrays(GL_TRIANGLE_STRIP,0,126)
def get_extent(self):
return [[0.0,0.0,-1.0],
[6.3,1.0,1.0]]
# load it into PyMOL
for b in range(0,63):
cmd.load_callback(myCallback(b),'gl03',b+1)
# give us a nice view
cmd.turn('z',20)
cmd.turn('y',20)
cmd.turn('x',20)
cmd.mplay()
|