# 8.5.3. Trajectory Coordinate Averaging — MDAnalysis.transformations.positionaveraging¶

Averages the coordinates of a given trajectory with the N previous frames. For frames < N, the average of the frames iterated up to that point will be returned.

class MDAnalysis.transformations.positionaveraging.PositionAverager(avg_frames, check_reset=True)[source]

Averages the coordinates of a given timestep so that the coordinates of the AtomGroup correspond to the average positions of the N previous frames. For frames < N, the average of the frames iterated up to that point will be returned.

Example

Average the coordinates of a given AtomGroup over the course of the previous N frames. For N=3, the output will correspond to the average of the coordinates over the last 3 frames. When check_reset=True, the averager will be reset once the iteration is complete, or if the frames iterated are not sequential.

N=3
transformation = PositionAverager(N, check_reset=True)
for ts in u.trajectory:
print(ts.positions)

In this case, ts.positions will return the average coordinates of the last N iterated frames.

When check_reset=False, the average of coordinates from non sequential timesteps can also be computed. However, the averager must be manually reset before restarting an iteration. In this case, ts.positions will return the average coordinates of the last N iterated frames, despite them not being sequential (frames = [0, 7, 1, 6]).

N=3
transformation = PositionAverager(N, check_reset=False)
frames = [0, 7, 1, 6]
transformation.resetarrays()
for ts in u.trajectory[frames]:
print(ts.positions)

If check_reset=True, the PositionAverager would have automatically reset after detecting a non sequential iteration (i.e. when iterating from frame 7 to frame 1 or when resetting the iterator from frame 6 back to frame 0).

For frames < N, the average is calculated with the frames iterated up to that point and thus will not follow the same behaviour as for frames > N. This can be followed by comparing the number of frames being used to compute the current averaged frame (current_avg) to the one requested when calling PositionAverager (avg_frames) which in these examples corresponds to N=3.

N=3
transformation = PositionAverager(N, check_reset=True)