File: cgo03.py

package info (click to toggle)
pymol 2.4.0%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 43,312 kB
  • sloc: cpp: 480,106; python: 79,860; ansic: 28,343; javascript: 6,792; sh: 47; makefile: 30; csh: 8
file content (90 lines) | stat: -rw-r--r-- 2,101 bytes parent folder | download | duplicates (6)
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
from pymol.cgo import *
from pymol import cmd
import math
import time

# 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.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.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.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.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()
   
time.sleep(3)

cmd.mstop()