diff --git a/package/MDAnalysis/coordinates/DCD.py b/package/MDAnalysis/coordinates/DCD.py index 547e7bc0c9c..b1330dbf2af 100644 --- a/package/MDAnalysis/coordinates/DCD.py +++ b/package/MDAnalysis/coordinates/DCD.py @@ -192,6 +192,7 @@ class DCDWriter(base.Writer): .. _Issue 187: https://github.com/MDAnalysis/mdanalysis/issues/187 """ format = 'DCD' + flavor = 'CHARMM' units = {'time': 'AKMA', 'length': 'Angstrom'} def __init__(self, filename, n_atoms, start=0, step=1, @@ -399,6 +400,7 @@ class DCDReader(base.Reader): Removed skip keyword and functionality """ format = 'DCD' + flavor = 'CHARMM' units = {'time': 'AKMA', 'length': 'Angstrom'} _Timestep = Timestep diff --git a/package/MDAnalysis/coordinates/LAMMPS.py b/package/MDAnalysis/coordinates/LAMMPS.py index 4d28539ebe0..40e3936cd62 100644 --- a/package/MDAnalysis/coordinates/LAMMPS.py +++ b/package/MDAnalysis/coordinates/LAMMPS.py @@ -79,10 +79,11 @@ class DCDWriter(DCD.DCDWriter): "Angstrom". See :mod:`MDAnalysis.units` for other recognized values. """ - format = "DCD" + format = 'DCD' + flavor = 'LAMMPS' def __init__(self, *args, **kwargs): - self.units = {'time': 'ps', 'length': 'Angstrom'} # must be instance level + self.units = {'time': 'fs', 'length': 'Angstrom'} # must be instance level self.units['time'] = kwargs.pop('timeunit', self.units['time']) self.units['length'] = kwargs.pop('lengthunit', self.units['length']) for unit_type, unit in self.units.items(): @@ -105,7 +106,8 @@ class DCDReader(DCD.DCDReader): .. _units style: http://lammps.sandia.gov/doc/units.html .. """ - format = "DCD" + format = 'DCD' + flavor = 'LAMMPS' def __init__(self, dcdfilename, **kwargs): self.units = {'time': 'fs', 'length': 'Angstrom'} # must be instance level diff --git a/testsuite/MDAnalysisTests/coordinates/test_lammps.py b/testsuite/MDAnalysisTests/coordinates/test_lammps.py index 88129b7ac08..d6714b71b3e 100644 --- a/testsuite/MDAnalysisTests/coordinates/test_lammps.py +++ b/testsuite/MDAnalysisTests/coordinates/test_lammps.py @@ -3,7 +3,8 @@ import MDAnalysis as mda -from numpy.testing import (assert_equal, assert_almost_equal, assert_raises) +from numpy.testing import (assert_equal, assert_almost_equal, assert_raises, + assert_) import tempdir from unittest import TestCase @@ -12,7 +13,7 @@ RefLAMMPSDataDCD) -def test_datareader_VE(): +def test_datareader_ValueError(): from MDAnalysis.coordinates.LAMMPS import DATAReader assert_raises(ValueError, DATAReader, 'filename') @@ -73,6 +74,9 @@ def setUp(self): def tearDown(self): del self.u + def test_Reader_is_LAMMPS(self): + assert_(self.u.trajectory.flavor, self.flavor) + def get_frame_from_end(self, offset): iframe = self.u.trajectory.n_frames - 1 - offset iframe = iframe if iframe > 0 else 0 @@ -123,6 +127,8 @@ def wrong_load(unit="GARBAGE"): class TestLAMMPSDCDWriter(TestCase, RefLAMMPSDataDCD): + flavor = 'LAMMPS' + def setUp(self): self.u = mda.Universe(self.topology, self.trajectory, format=self.format) @@ -139,6 +145,11 @@ def tearDown(self): del self.u del self.tmpdir + def test_Writer_is_LAMMPS(self): + with mda.Writer(self.outfile, n_atoms=self.u.atoms.n_atoms, + format=self.format) as W: + assert_(W.flavor, self.flavor) + def test_Writer(self, n_frames=3): W = mda.Writer(self.outfile, n_atoms=self.u.atoms.n_atoms, format=self.format) @@ -152,7 +163,9 @@ def test_Writer(self, n_frames=3): self.u.trajectory[n_frames - 1].positions, 6, err_msg="coordinate mismatch between corresponding frames") - + def test_OtherWriter_is_LAMMPS(self): + with self.u.trajectory.OtherWriter(self.outfile) as W: + assert_(W.flavor, self.flavor) def test_OtherWriter(self): times = [] @@ -174,3 +187,50 @@ def test_OtherWriter(self): assert_almost_equal(reversed.trajectory[-1].positions, self.u.trajectory[0].positions, 6, err_msg="coordinate mismatch between corresponding frames") + +class TestLAMMPSDCDWriterClass(TestCase): + flavor = 'LAMMPS' + + def setUp(self): + # dummy output file + ext = ".dcd" + self.tmpdir = tempdir.TempDir() + self.outfile = os.path.join(self.tmpdir.name, 'lammps-writer-test' + ext) + + def tearDown(self): + try: + os.unlink(self.outfile) + except: + pass + del self.tmpdir + + def test_Writer_is_LAMMPS(self): + with mda.coordinates.LAMMPS.DCDWriter(self.outfile, n_atoms=10) as W: + assert_(W.flavor, self.flavor) + + def test_open(self): + def open_dcd(): + try: + with mda.coordinates.LAMMPS.DCDWriter(self.outfile, n_atoms=10): + pass + except Exception: + return False + else: + return True + assert_(open_dcd(), True) + + def test_wrong_time_unit(self): + def wrong_load(unit="nm"): + with mda.coordinates.LAMMPS.DCDWriter(self.outfile, n_atoms=10, + timeunit=unit): + pass + assert_raises(TypeError, wrong_load) + + def test_wrong_unit(self): + def wrong_load(unit="GARBAGE"): + with mda.coordinates.LAMMPS.DCDWriter(self.outfile, n_atoms=10, + timeunit=unit): + pass + assert_raises(ValueError, wrong_load) + +