问题
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