均方位移python [英] Mean square displacement python

查看:82
本文介绍了均方位移python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个模拟20,000帧的轨迹文件,每帧之间有5 ps的时间,我想做的是计算二维(x和y轴)上的扩散.但是要计算2D扩散,首先我必须计算所研究分子的均方位移.MSD计算分子在随机行走中探索系统所需的平均时间.

I have a trajectory file from simulation of 20,000 frames with 5 ps time in between every frame, what I want to do is to calculate diffusion in 2 dimension (x and y axis). but to calculate diffusion in 2D, first I have to calculate Mean square displacement of the molecule under study. MSD calculates the average time taken by molecule to explore the system in random walks.

我是python编程的新手,我真的想要一些帮助来开始这个问题并解决这个问题.希望得到积极的回应.

I am very new to python programming and I would really want some help to get started this problem and to solve this problem. Hope to get positive response.

推荐答案

MSD确切地说是均方根位移,因此您需要做的是找出位置的差异(r(t + dt)-r(t)),然后将其平方,最后取平均值.首先,您必须从x和y中找到r,这很容易.我要假设您从现在开始一直使用numpy.

Well the MSD is exactly as it sounds it is the mean square displacement so what you need to do is find the difference in the position (r(t + dt) -r(t)) for each position and then square it and finally take the mean. First you must find r from x and y which is easy enough. I am going to assume you are using numpy from here on out.

    import numpy as np
    r = np.sqrt(xdata**2 + ydata**2)
    diff = np.diff(r) #this calculates r(t + dt) - r(t)
    diff_sq = diff**2
    MSD = np.mean(diff_sq)

现在,这是计算MSD的通用方法,然后您可以与布朗运动之类的东西进行比较,其中MSD = 4Dt大约在2维上.

Now this is the general way to calculate MSD then you can compare with things like Brownian motion where MSD = 4Dt approximately in 2 dimensions.

这篇关于均方位移python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆