Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.1k views
in Technique[技术] by (71.8m points)

statistics - Mean square displacement python

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...