calculate MSD and Lipid diffusion

485 views
Skip to first unread message

contact.life...@gmail.com

unread,
Jul 10, 2015, 11:09:59 AM7/10/15
to mdnalysis-...@googlegroups.com
Hi 

After trying hard to make a small script for calculating lateral lipid diffusion coefficient and MSD and searched different research artilces to get anything to start with but as I am new to this Python and MDAnalysis I was not been able to make a script . But I came with the following idea to calculate MSD 

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)

How to implement it in MD analysis to calculate MSD and diffusion coefficient through this. 

I tried to use leaflet finder to solve the problem but the following program is giving me an error "TypeError: 'generator' object has no attribute '__getitem__'
"

import sys
import MDAnalysis
import numpy as np
import MDAnalysis.coordinates
from MDAnalysis.analysis.leaflet import LeafletFinder

u= MDAnalysis.Universe("/path to psf.psf","/path to.dcd") 

headgroup_atoms= u.selectAtoms("name P*")
coord = headgroup_atoms.coordinates()

#print headgroup_atoms
#print coord

from MDAnalysis.analysis.distances import distance_array
adj = (distance_array(coord,coord))

import networkx as NX
leaflets=NX.connected_components(NX.Graph(adj))


A_lipids = headgroup_atoms[leaflets[0]].residues

B_lipids = headgroup_atoms[leaflets[1]].residues

if anyone can help me , I will be really grateful to you .... 

Michael Lerner

unread,
Jul 10, 2015, 11:38:45 AM7/10/15
to mdnalysis-...@googlegroups.com
I don’t have any tips on the MDAnalysis side of things, but I did recently write some Python code to calculate MSD. I did a decent job speeding things up with numba (see the blog post: http://www.mglerner.com/blog/?p=52). However, in the end, you’ll be happier using an FFT-based algorithm, such as FCA (see the link in the comments).

Cheers,
-Michael

(Likely sent from my phone; please excuse the brevity.)
Michael G. Lerner


--
You received this message because you are subscribed to the Google Groups "MDnalysis discussion" group.
To unsubscribe from this group and stop receiving emails from it, send an email to mdnalysis-discus...@googlegroups.com.
To post to this group, send email to mdnalysis-...@googlegroups.com.
Visit this group at http://groups.google.com/group/mdnalysis-discussion.
For more options, visit https://groups.google.com/d/optout.

Tyler Reddy

unread,
Jul 10, 2015, 12:04:40 PM7/10/15
to mdnalysis-...@googlegroups.com
I have some unit-tested MDAnalysis / Python-based code for calculating lateral diffusion in simulations (repo: https://github.com/tylerjereddy/diffusion_analysis_MD_simulations docs: http://diffusion-analysis-md-simulations.readthedocs.org/en/latest/diffusion_analysis.html).

I should probably upload a sample IPython notebook of the calculation workflow, but the documentation is relatively thorough. Have to be a bit careful to watch the units and the way you select particles, etc.

I've used it for at least one publication now and a few others in the group as using it now as well.

Cheers,
Tyler



--
Message has been deleted

Oliver Beckstein

unread,
Jul 13, 2015, 7:01:15 PM7/13/15
to mdnalysis-...@googlegroups.com

On 13 Jul, 2015, at 07:23, contact.life...@gmail.com wrote:

1) How can I get xmin, xmax, y min and Y max values and delta value for my trajectory

If your trajectory contains unitcell information, look at Timestep.dimensions:

import numpy as np

maxL = np.zeros(3)

for ts in u.trajectory:
L = ts.dimensions[:3]      # Lx, Ly, Lz
angles = ts.dimensions[3:]    # alpha, beta, gamma -- not needed

replace = (maxL < L)
maxL[replace] = L[replace]

print("L: {0}       maxL: {1}".format(L, maxL))

print("maximum dimensions: {}".format(maxL))


If you really need coordinates, use the same idea as above but instead of dimensions look at AtomGroup.bbox() ("bounding box" ). From the help:

Signature: u.atoms.bbox(**kwargs)
Docstring:
Return the bounding box of the selection.

The lengths A,B,C of the orthorhombic enclosing box are::

  L = AtomGroup.bbox()
  A,B,C = L[1] - L[0]

:Keywords:
  *pbc*
    ``True``: Move all atoms within the primary unit cell before calculation [``False``]


In code:

bb = u.atoms.bbox()
L = bb[1] - bb[0]

and then as above.

Hope that helps,
Oliver





--
Oliver Beckstein * orbe...@gmx.net
skype: orbeckst  * orbe...@gmail.com

Reply all
Reply to author
Forward
0 new messages