File: chempy_model02.py

package info (click to toggle)
pymol 1.2r2-1.1
  • links: PTS, VCS
  • area: main
  • in suites: squeeze
  • size: 38,716 kB
  • ctags: 23,006
  • sloc: ansic: 480,417; python: 70,953; cpp: 12,928; sh: 10,266; makefile: 530; csh: 21
file content (52 lines) | stat: -rw-r--r-- 1,392 bytes parent folder | download | duplicates (3)
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
from pymol import cmd
from random import random
import time

# this shows how you can efficiently update the coordinates
# of an existing model for real-time viewing

# for asychronous execution,  you may want to run this using the "spawn"
# command from inside PyMOL or with the "-l" option from the unix shell

# first we need a model

cmd.load("$PYMOL_PATH/test/dat/pept.pdb","demo")

# let's dress it up a little bit 

cmd.show("sticks","demo")

cmd.show("spheres","resi 10")

cmd.color("yellow","resi 5 and element c")

# turn off some of the chatter about reloading the object...

cmd.feedback("disable","executive","actions")

# now loop, updating the coordinates and reloading the model into
# state 1 of the "demo" object

m = cmd.get_model()
while 1:
   time.sleep(0.05)
   try:
      cmd.set("suspend_updates","1") # only necessary if multithreading...
      for a in m.atom:
         a.coord[0]+=(random()-0.5)*0.1
         a.coord[1]+=(random()-0.5)*0.1
         a.coord[2]+=(random()-0.5)*0.1
      cmd.load_model(m,"demo",1)
   except:
      cmd.set("suspend_updates","0") # only necessary if multithreading...
      traceback.print_exc()
   cmd.refresh()

# Summary: this is portable, safe, but inefficient.  For real-time visualization
# of coordinate changes, there is a way to do this by passing in an opaque
# C data structure...

# Cheers, warren@delanoscientific.com