File: chempy_model03.py

package info (click to toggle)
pymol 1.8.4.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: stretch
  • size: 42,248 kB
  • ctags: 24,095
  • sloc: cpp: 474,635; python: 75,034; ansic: 22,888; sh: 236; makefile: 78; csh: 21
file content (45 lines) | stat: -rw-r--r-- 1,219 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
from pymol import cmd
from random import random
import time

# this shows how you can efficiently update the coordinates
# of an existing model for viewing as a PyMOL trajectory (from RAM)

# first we need a model

if os.path.exists("$PYMOL_PATH/test/dat/pept.pdb"):
    cmd.load("$PYMOL_PATH/test/dat/pept.pdb","demo")
else:
    from inspect import getsourcefile
    current_file_dir = os.path.dirname(os.path.abspath(getsourcefile(lambda:0)))
    cmd.load(os.path.join(current_file_dir, "../../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")

# now loop, updating the coordinates and appending the model
# onto 99 subsequent frames...

m = cmd.get_model()
for a in range(1,100):
   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") # NOTE: no state number provided -> appends

# now define the movie with short pauses at beginning and and

cmd.mset("1 x15 1 -100 100 x15")

# now play the movie...

cmd.mplay()

# by default, PyMOL plays ~30 fps.
# "set movie_delay=0" to see maximum speed...