Files
pymol-open-source/data/demo/cgo03.py
Thomas Holder d020c80214 PYMOL-1538 Picking support for ObjectCGO
No nice API available yet. Pick event can be captured like this:

>>> cmd.button("single_left", "none", "clik")
>>> cmd.set_key("F1", lambda: print(_cmd.get_click_string(cmd._COb)))

(press "F1" after a pick)

- Add pick colors to CGO demo (for testing/demo)
2020-08-06 13:03:06 +02:00

92 lines
2.2 KiB
Python

from pymol.cgo import *
from pymol import cmd
import math
# a more comple example of using cgo's to create a fancy animation.
# In a real script you'd want to use Numeric Python in order to handle
# the math efficiently.
# create a 30x30 array
z = []
for x in range(0,30):
z.append([0.0]*30)
# create a 63 frame movie inside of PyMOL
for a in range(0,63):
aa = a/9.973
ab = a/4.987
# blank list
obj = []
# generate a flowing mesh
for x in range(0,30):
for y in range(0,30):
z[x][y]=(math.cos((aa)+x/2.0)+math.sin((aa)+(y/2.0)))
obj += [PICK_COLOR, 0, cPickableGadget]
obj.extend( [ COLOR, 0.3, 0.3, 1.0 ] )
for x in range(0,30):
obj.extend( [ BEGIN, LINE_STRIP ] )
for y in range(0,30):
obj.extend( [ VERTEX, float(x), float(y), z[x][y] ] )
obj.append( END )
for y in range(0,30):
obj.extend( [ BEGIN, LINE_STRIP ] )
for x in range(0,30):
obj.extend( [ VERTEX, float(x), float(y), z[x][y] ] )
obj.append( END )
# add into this a couple circulating spheres
obj += [PICK_COLOR, 1, cPickableGadget]
obj.extend( [ COLOR, 1.0, 0.2, 0.2 ] )
obj.extend( [ SPHERE, 5*math.cos(ab)+15.0, 5*math.sin(ab)+15.0, 6.0, 1.0 ] )
obj += [PICK_COLOR, 2, cPickableGadget]
obj.extend( [ COLOR, 1.0, 1.0, 0.2 ] )
obj.extend( [ SPHERE, 5*math.cos(aa)+15.0, 5*math.sin(aa)+15.0, 3.0, 2.0 ] )
# now add a colorful cylinder
obj += [PICK_COLOR, 3, cPickableGadget]
obj.extend( [ CYLINDER,
5.0, 15+math.sin(aa)*10, -5.0, # XYZ 1
25.0, 15+math.sin(aa)*10, -5.0, # XYZ 2
2.0, # Radius
1.0, (1.0+math.sin(aa))/2.0,(1.0+math.cos(aa))/2.0, # RGB Color 1
0.3, (1.0+math.cos(aa))/2.0, 0.5, # RGB Color 2
] )
# load this state into the PyMOL object
cmd.load_cgo(obj,'cgo03',a+1)
# this zooms out a bit more than usual
cmd.reset()
cmd.zoom('cgo03',3.0)
# this moves the rear clipping plane back a bit
cmd.clip('far',-12.0)
# give us a nice view
cmd.turn('z',30)
cmd.turn('x',-60)
# start the movie
cmd.mplay()