8.6.3. 轨迹坐标平均 MDAnalysis.transformations.positionaveraging

将给定轨迹的坐标与前N个帧进行平均。对于小于N的帧,将返回迭代到该点的帧的平均值。

class MDAnalysis.transformations.positionaveraging.PositionAverager(avg_frames, check_reset=True, max_threads=None, parallelizable=False)[源代码]

对给定时间步长的坐标进行平均,以使原子组的坐标对应于前N个帧的平均位置。对于小于N的帧,将返回迭代到该点的帧的平均值。

示例

在前N帧的过程中,对给定的原子组的坐标进行平均。为 N=3 ,则输出将对应于最后3帧中坐标的平均值。什么时候 check_reset=True 一旦迭代完成,或者如果迭代的帧不是连续的,则平均器将被重置。

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

在这种情况下, ts.positions 将返回最后N个迭代帧的平均坐标。

什么时候 check_reset=False ,还可以计算来自非连续时间步长的坐标的平均值。但是,在重新开始迭代之前,必须手动重置平均器。在这种情况下, ts.positions 将返回最后N个迭代帧的平均坐标,尽管它们不是连续的 (frames = [0, 7, 1, 6] )。

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

如果 check_reset=True ,即 PositionAverager 在检测到非顺序迭代后(即,从帧7迭代到帧1或将迭代器从帧6重置回帧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)
u.trajectory.add_transformations(transformation)
for ts in u.trajectory:
    if transformation.current_avg == transformation.avg_frames:
        print(ts.positions)

在.的情况下 N=3 ,因为是使用迭代到当前迭代的帧来计算平均值,所以不会对返回的第一个帧进行平均。在第一次迭代期间,到目前为止没有其他帧存储在存储器中,因此, transformation.current_avg = 1 。迭代的第二个帧将返回帧1和帧2的平均值,其中 transformation.current_avg = 2 。只有在第三次迭代和之后的迭代中才会 ts.positions 开始返回最后3帧的平均值,因此 transformation.current_avg = 3 这些初始帧在分析过程中通常不是所需的,但可以很容易地避免它们,如前面的示例所示 if transformation.current_avg == transformation.avg_frames: 或者通过简单地删除第一个 avg_frames-1 来自分析的框架。

参数:
  • avg_frames (int) -- 确定用于位置平均的帧数量。

  • check_reset (bool, optional) -- 如果 True ,当轨迹迭代方向改变时,位置平均将被重置并发出警告。如果 False ,无论迭代如何,位置平均都不会重置。

返回类型:

MDAnalysis.coordinates.timestep.Timestep

在 2.0.0 版本发生变更: 转换已更改为从基类继承,以限制线程并检查它是否可用于并行分析。

参数:
  • max_threads (int, optional) -- 可以使用最大线程数。默认值为 None ,表示默认设置或外部设置。

  • parallelizable (bool, optional) -- 检查这是否可以用于拆分-应用-合并并行分析方法。默认值为 True