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 65 66 67
|
from OpenGL.GL import *
from OpenGL.GL.ARB.vertex_buffer_object 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:
# NOTE: NUMERIC NOT SUPPORTED BY PYMOL 1.1 and up
from numpy import *
# define a callback object
class myCallback(Callback):
def __init__(self):
self.vert = zeros([126,3],float)
self.norm = zeros([126,3],float)
for a in range(0,63):
x = a/10.0
self.vert[2*a][0]=x
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, GL_FLOAT,0,self.vert)
glNormalPointer(GL_FLOAT,0,self.norm)
glEnableClientState(GL_VERTEX_ARRAY)
glEnableClientState(GL_NORMAL_ARRAY)
glDisableClientState(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
cmd.load_callback(myCallback(),'gl02')
# give us a nice view
cmd.turn('z',20)
cmd.turn('y',20)
cmd.turn('x',20)
|