File: particle01.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 (80 lines) | stat: -rw-r--r-- 2,004 bytes parent folder | download | duplicates (4)
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

# demonstration of a particle cloud (non-interacting)

from random import random
from pymol import cmd

particle_count = 1000

box_size = 500.0

# constants

half_box = box_size / 2

# create N particle system [x,y,z,r,vx,vy,vz]

particle = [] 
for resi in range(0,particle_count):
    particle.append([resi] + 
                     map(lambda x:(random()-0.5)*box_size/2,[0]*3) + # x,y,z
                    [random()+0.5] + # r
                    map(lambda x:(random()-0.5),[0]*3) # vx,vy,vz
                    )
        
# create cloud object

for part in particle:
    cmd.pseudoatom("cloud",
                   resi = part[0],
                   pos = part[1:4],
                   vdw = part[4])

# draw spheres efficiently
cmd.show_as("spheres")
cmd.unset("cull_spheres") 

# position the camera

cmd.zoom()
cmd.zoom("center",box_size)

# let there be color

cmd.spectrum()

# this is the main loop

def simulation():
    import traceback
    try:
        while 1:
            for part in particle:
                # simplistic Euler intergration

                # p = p + v
                
                part[1] = (half_box + part[1] + part[5]) % box_size - half_box
                part[2] = (half_box + part[2] + part[6]) % box_size - half_box
                part[3] = (half_box + part[3] + part[7]) % box_size - half_box

                # v = v + pseudo-gravitational acceleration
                
                factor = max(0.1*box_size, 0.1*(part[1]**2+part[2]**2+part[3]**2)**1.5)
                
                part[5] = part[5] - part[1] / factor
                part[6] = part[6] - part[2] / factor
                part[7] = part[7] - part[3] / factor
                
            cmd.alter_state(1,"cloud","(x,y,z) = particle[int(resi)][1:4]",space=globals())
            cmd.refresh()
    except:
        traceback.print_exc()

# launch the main loop in a separate thread

import threading

thread = threading.Thread(target=simulation)
thread.setDaemon(1)
thread.start()