File: trajectory_average.py

package info (click to toggle)
mmtk 2.7.9-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 11,788 kB
  • ctags: 6,600
  • sloc: python: 18,050; ansic: 12,400; makefile: 129; csh: 3
file content (30 lines) | stat: -rw-r--r-- 905 bytes parent folder | download
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
# This program reads a trajecory and calculates the average
# configuration, which is then visualized. This is not a particularly
# useful operation, but it illustrates the use of trajectories and
# configuration variables.
#
# Note: In order to create the trajectory file "bala1.nc" which is
#       read by this example, you must run the example
#       MolecularDynamics/protein.py!
#

from MMTK import *
from MMTK.Trajectory import Trajectory
from MMTK.Visualization import view

# Open the input trajectory.
trajectory = Trajectory(None, 'bala1.nc')
universe = trajectory.universe

# Create a zeroed particle vector object.
sum = ParticleVector(universe)

# Loop over all steps and add the configurations to the sum.
for configuration in trajectory.configuration:
    sum = sum + configuration

# Divide by the number of steps.
sum = sum/len(trajectory)

# Visualize the average.
view(universe, sum)