Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.Sign up
NCDFReader velocities can sometimes be improperly scaled #2323
So whilst I was working on a new NCRST reader, I noticed that the NCDFReader appears to not be properly handling the reading of velocities, leading to values that don't adhere to MDAnalysis velocity units standards (usually Angstrom per AKMA time instead of Angstrom per ps).
A little bit of background:
As per the AMBER NetCDF convention (http://ambermd.org/netcdf/nctraj.xhtml) all trajectory data variables can have a
MDAnalysis' NCDFReader current approach to
I am currently working on a temporary hot-fix for this. What I propose to do is to extend the
In the long run, I will see what I can do to write a clean NCDFReader implementation that fully implements handling of
MDAnalysis universe data should always adhere to the units defined here: https://www.mdanalysis.org/mdanalysis/documentation_pages/units.html
Velocities can by off by a factor of
Code to reproduce the behavior
: import MDAnalysis as mda : u = mda.Universe('../../ace_tip3p.parm7', 'mdcrd.nc') # Values stored in universe (should be A/ps) : u.atoms.velocity : array([-0.477188 , -0.8108647 , -0.24172044], dtype=float32) : from scipy.io import netcdf : read_f = netcdf.netcdf_file('mdcrd.nc') # This is how the data is stored in the file : read_f.variables['velocities'] : array([-0.477188 , -0.8108647 , -0.24172044], dtype=float32) # This is the scale factor : read_f.variables['velocities'].scale_factor : 20.455 # This is the intended velocity units (post scaling) : read_f.variables['velocities'].units : b'angstrom/picosecond'
Currently version of MDAnalysis
Unfortunately this is one of those super obscure trajectory format things, I probably would have never noticed if I hadn't spent too long looking at the convention docs.
In cases where the input units aren't specified in the trajectory (or it's API), it might be overkill but maybe we could just throw a warning to users telling them the assumptions being made? It's probably a big undertaking, but if there's a consensus on how best to do it, I'm willing to have a go at it for the trajectory formats I'm more familiar with.