Mean square displacement python

半腔热情 提交于 2020-11-29 10:46:28

问题


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.

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.


回答1:


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)

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.



来源:https://stackoverflow.com/questions/31264591/mean-square-displacement-python

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!