Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,14 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
mm/dd/yy ??? This could be you
mm/dd/yy IAlibay

* 0.20.1
Enhancements

Fixes
* The NetCDF writer now writes `cell_angle` units as `degree` instead of
`degrees` in accordance with the AMBER NetCDF convention (Issue #2327).



Expand Down
9 changes: 6 additions & 3 deletions package/MDAnalysis/coordinates/TRJ.py
Original file line number Diff line number Diff line change
Expand Up @@ -847,10 +847,13 @@ class NCDFWriter(base.WriterBase):
.. versionchanged:: 0.17.0
Use fast :mod:`netCDF4` for writing but fall back to slow
:mod:`scipy.io.netcdf` if :mod:`netCDF4` is not available.
.. versionchanged:: 0.20.1
Changes the `cell_angles` unit to the AMBER NetCDF convention standard
of `degree` instead of the `degrees` written in previous version of
MDAnalysis (Issue #2327).

.. TODO:
* Change the `cell_angles` units to `degree`, implement `scale_factor`
handling (Issue #2327).
* Implement `scale_factor` handling (Issue #2327).

"""

Expand Down Expand Up @@ -967,7 +970,7 @@ def _init_netcdf(self, periodic=True):

cell_angles = ncfile.createVariable('cell_angles', 'f8',
('frame', 'cell_angular'))
setattr(cell_angles, 'units', 'degrees')
setattr(cell_angles, 'units', 'degree')

cell_angular = ncfile.createVariable('cell_angular', 'c',
('cell_angular', 'label'))
Expand Down
29 changes: 28 additions & 1 deletion testsuite/MDAnalysisTests/coordinates/test_netcdf.py
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@

from MDAnalysisTests.datafiles import (PFncdf_Top, PFncdf_Trj,
GRO, TRR, XYZ_mini,
PRM_NCBOX, TRJ_NCBOX)
PRM_NCBOX, TRJ_NCBOX, DLP_CONFIG)
from MDAnalysisTests.coordinates.test_trj import _TRJReaderTest
from MDAnalysisTests.coordinates.reference import (RefVGV, RefTZ2)
from MDAnalysisTests import make_Universe
Expand Down Expand Up @@ -875,6 +875,33 @@ def test_write_ts(self, pos, vel, force, tmpdir, ts1, ts2):
u.trajectory.close()


class TestNCDFWriterUnits(object):
"""Tests that the writer adheres to AMBER convention units"""
@pytest.fixture()
def outfile(self, tmpdir):
return str(tmpdir) + 'ncdf-writer-1.ncdf'

@pytest.mark.parametrize('var, expected', (
('coordinates', 'angstrom'),
('time', 'picosecond'),
('cell_lengths', 'angstrom'),
('cell_angles', 'degree'),
('velocities', 'angstrom/picosecond'),
('forces', 'kilocalorie/mole/angstrom')
))
def test_writer_units(self, outfile, var, expected):
trr = mda.Universe(DLP_CONFIG, format='CONFIG')

with mda.Writer(outfile, trr.trajectory.n_atoms, velocities=True,
forces=True, format='ncdf') as W:
for ts in trr.trajectory:
W.write_next_timestep(ts)

with netcdf.netcdf_file(outfile, mode='r') as ncdf:
unit = ncdf.variables[var].units.decode('utf-8')
assert_equal(unit, expected)


class TestNCDFWriterErrors(object):
@pytest.fixture()
def outfile(self, tmpdir):
Expand Down