File: visualiseAtomMobility.py

package info (click to toggle)
ball 1.5.0%2Bgit20180813.37fc53c-11
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 239,924 kB
  • sloc: cpp: 326,149; ansic: 4,208; python: 2,303; yacc: 1,778; lex: 1,099; xml: 958; sh: 322; javascript: 164; makefile: 88
file content (72 lines) | stat: -rw-r--r-- 1,690 bytes parent folder | download | duplicates (9)
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
#  example script to viualise how mobile all atoms from a trajectory are
#  it creates a sphere for every atoms
#  the radius is proportional to the mobility and the color is
#  interpolated between blue (no movement at all) and red (very mobile)
dcd = DCDFile("test.dcd")
system = getSystems()[0]
number_ss = dcd.getNumberOfSnapShots()

ssm = SnapShotManager(system, getMolecularStructure().getForceField(), dcd)

rep = Representation()

positions = []
distances = []

nr_atoms = 0
for atom in atoms(system):
	positions.append(Vector3())
	distances.append(0)
	nr_atoms += 1


# calculate the median position of every atom
while ssm.applyNextSnapShot():
	i = 0
	for atom in atoms(system):
		positions[i] = positions[i] + atom.getPosition()
		i = i + 1

for position in positions:
  position /= number_ss

ssm.applyFirstSnapShot()

# calculate the medium difference in position for every atom
while ssm.applyNextSnapShot():
	i = 0
	for atom in atoms(system):
		distances[i] = distances[i] + (atom.getPosition() - positions[i]).getLength()
		i = i + 1

#normalize distances
max_distance = 0
for distance in distances:
	if distance > max_distance:
		max_distance = distance

i = 0
while i < nr_atoms:
	distances[i] = distances[i] / max_distance
	i = i + 1
 
# create the spheres
i = 0
while i < nr_atoms:
	sphere = Sphere()
	sphere.setPosition(positions[i])
	sphere.setRadius(distances[i])
	sphere.setColor(ColorRGBA(distances[i], 0, 1 -distances[i]))
	rep.insert(sphere)
	i = i + 1

# set the atoms to their median position
i = 0
for atom in atoms(system):
	atom.setPosition(positions[i])
	i = i + 1

getMainControl().insert(rep)
getMainControl().update(rep)
getMainControl().update(system)