mdanalysis icon indicating copy to clipboard operation
mdanalysis copied to clipboard

add simple atomic distance analysis to analysis.distances

Open orbeckst opened this issue 3 years ago • 6 comments
trafficstars

Is your feature request related to a problem?

We have many analysis tools for complicated problems, all using the consistent AnalysisBase approach. However, there's no functionality for fairly trivial but nevertheless commonly used analysis tasks, namely calculate the distance (under PBC) between two atom groups, atom by atom.

Describe the solution you'd like

Namely, for AtomGroups g1 and g2, I would like to calculate the distances |g1[i] - g2[i]| for all i with a class such as

d12 = MDAnalysis.analysis.distances.DistanceAnalysis(g1, g2).run()
plt.histogram(d12.results.distances)

The constructor could take pbc=True | False as kwarg, in case someone wants to also calculate distances without PBC.

Using calc_bonds() in the actual implementation should produce good performance.

Describe alternatives you've considered

This is a simple problem so one can always write one's own's code. However, providing well-tested building blocks aids in reproducibility and reduces code duplication. It also makes standard analysis available in mdacli.

Or use the GROMACS tool gmx distance :-p.

Additional context

Code could be similar to https://github.com/MDAnalysis/mdanalysis/issues/3310#issuecomment-1086964719 or NucPairDist https://github.com/MDAnalysis/mdanalysis/blob/3a03af01886977aa53d2a43086cae86c45038738/package/MDAnalysis/analysis/nucleicacids.py#L61

orbeckst avatar Apr 22 '22 22:04 orbeckst

So distance_array but over all frames?

Honestly I'm not really sure it's worth the extra maintenance burden :/

IAlibay avatar Apr 22 '22 22:04 IAlibay

No, not distance_array but calc_bonds.

See gmx distance ...

orbeckst avatar Apr 22 '22 22:04 orbeckst

Could be calc_bonds() to return distances or the new minimize_vectors(g1.positions - g2.positions) to get back vectors, if one wanted to replicate gmx distance functionality.

Btw, minimize_vectors() https://github.com/MDAnalysis/mdanalysis/blob/3a03af01886977aa53d2a43086cae86c45038738/package/MDAnalysis/lib/distances.py#L1565 is missing from the documentation, it's not in https://docs.mdanalysis.org/2.2.0-dev0/documentation_pages/lib/distances.html#module-MDAnalysis.lib.distances

EDIT: opened #3655 for the docs.

orbeckst avatar Apr 22 '22 22:04 orbeckst

I see what you mean now. Might just be me but the gmx tool version naming here seems far too ambiguous. My 2 cents, if it were to exist within core we need to be really careful what we name it.

That being said as above, it's not clear to me that this really should be a core thing or if it should live somewhere else downstream.

IAlibay avatar Apr 22 '22 22:04 IAlibay

Looks simple enough to me that the maintenance burden should be minimal. On the contrary to other analyses, we all have a good understanding of what is happening and there is no question about the correctness of the science.

jbarnoud avatar Apr 23 '22 06:04 jbarnoud

Anyone looking to do this could take inspiration from dist: https://docs.mdanalysis.org/1.1.0/documentation_pages/analysis/distances.html#MDAnalysis.analysis.distances.dist

lilyminium avatar Apr 23 '22 08:04 lilyminium