# How to specify distance for calculating the msd

**URL:** <https://gromacs.bioexcel.eu/t/how-to-specify-distance-for-calculating-the-msd/10752>\
**Category:** User discussions\
**Created:** [December 9, 2024, 5:47am UTC](https://gromacs.bioexcel.eu/t/how-to-specify-distance-for-calculating-the-msd/10752 "2024-12-09T05:47:36Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![aish.warya\_2024](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@aish.warya\_2024](https://gromacs.bioexcel.eu/u/aish.warya_2024)\
**Post date:** [December 9, 2024, 5:47am UTC](https://gromacs.bioexcel.eu/t/how-to-specify-distance-for-calculating-the-msd/10752/1 "2024-12-09T05:47:36Z")

</div>

GROMACS version:  
GROMACS modification: Yes/No  
Here post your question  
Dear users,  
I need to calculate the mean square displacement (MSD) of polymer units from the oil-water interface using GROMACS. Since the system contains a double interface, I am interested in analyzing the diffusion of the polymer from only one interface, located at z = 2.5 nm, into the aqueous phase. Specifically, I want to calculate the diffusion from z = 2.5 nm to z = 7.5 nm. How can I define this distance range in the `gmx msd` command?

Thank you!

---

<div class="post-metadata">

**Author:** ![hess](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/hess/32/416_2.png) [@hess](https://gromacs.bioexcel.eu/u/hess)\
**Post date:** [December 12, 2024, 8:58am UTC](https://gromacs.bioexcel.eu/t/how-to-specify-distance-for-calculating-the-msd/10752/2 "2024-12-12T08:58:09Z")

</div>

This is a non-trivial problem. Diffusion is about displacement and you want to calculate something localized.

You can select the group of molecules to analyze based on position. I assume this if based on the initial frame. Then you need to take into account that this selection will diffuse.

---

<div class="post-metadata">

**Author:** ![aish.warya\_2024](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@aish.warya\_2024](https://gromacs.bioexcel.eu/u/aish.warya_2024)\
**Post date:** [December 13, 2024, 5:54am UTC](https://gromacs.bioexcel.eu/t/how-to-specify-distance-for-calculating-the-msd/10752/3 "2024-12-13T05:54:15Z")

</div>

Thank you, sir, for your reply. I have calculated the diffusion coefficients using the command: gmx msd -f md.xtc -s md.tpr -o msd-msd.xvg.

I examined two oil-water systems with double interfaces, each containing different types of polymers. In system A, which includes polymer A, the polymer is confined to the interface, while in system B, which contains polymer B, the polymer is more diffused into the water phase.

The diffusion coefficient D of system A (with polymer A) is 0.3508 (+/- 0.0926) × 10⁻⁵ cm²/s, which is higher than that of system B (with polymer B), which has a diffusion coefficient D of 0.1899 (+/- 0.2129) × 10⁻⁵ cm²/s.

However, these values are opposite to what I initially expected, and I am now unsure whether I am on the right path with my calculations. Is there any modification should I do with the command?  
Could you kindly help me address this issue? I am attaching the image of the system after MD run

 ![Picture3](https://europe1.discourse-cdn.com/flex017/uploads/bioexcel1/original/2X/b/b82e14fb56c7f38a9e915da3f80aaa32a627a027.jpeg)

---

<div class="post-metadata">

**Author:** ![hess](https://dub1.discourse-cdn.com/flex017/user_avatar/gromacs.bioexcel.eu/hess/32/416_2.png) [@hess](https://gromacs.bioexcel.eu/u/hess)\
**Post date:** [December 16, 2024, 8:11am UTC](https://gromacs.bioexcel.eu/t/how-to-specify-distance-for-calculating-the-msd/10752/4 "2024-12-16T08:11:07Z")

</div>

Note that for system B your error bar is larger than the value itself. You likely need to simulate much longer.

---

<div class="post-metadata">

**Author:** ![aish.warya\_2024](https://avatars.discourse-cdn.com/v4/letter/a/b5ac83/32.png) [@aish.warya\_2024](https://gromacs.bioexcel.eu/u/aish.warya_2024)\
**Post date:** [December 18, 2024, 4:39am UTC](https://gromacs.bioexcel.eu/t/how-to-specify-distance-for-calculating-the-msd/10752/5 "2024-12-18T04:39:00Z")

</div>

Okay, I will try it. Thank you @hess sir for your assistance
