Skip to content

Commit

Permalink
Resolving Truncation of resids for GRO file writing (Issue 886) (#887)
Browse files Browse the repository at this point in the history
* Fixes #886. When .gro files are written their resids will now be properly truncated to 5 digits.
* Added a new unit test for Issue 886 -- dealing with residue number truncation when writing GRO files.


* The fix for Issue #886 has now been added to the CHANGELOG.

* Added a comment regarding usage of class-level fixtures for the unit test covering Issue 886.

* output file specification in unit test for Issue 886 has been fixed.

* Fixed the formatting of CHANGELOG following fixes to Issue 886.
  • Loading branch information
tylerjereddy authored and orbeckst committed Jul 6, 2016
1 parent 16cd195 commit 7220db5
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 9 deletions.
3 changes: 2 additions & 1 deletion package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,12 @@ The rules for this file:
* release numbers follow "Semantic Versioning" http://semver.org

------------------------------------------------------------------------------
??/??/16 kain88-de,jdetle, fiona-naughton, richardjgowers
??/??/16 kain88-de, jdetle, fiona-naughton, richardjgowers, tyler.je.reddy

* 0.15.1

Fixes
* GROWriter resids now truncated properly (Issue #886)
* reading/writing lambda value in trr files (Issue #859)
* fix __iter__/next redundancy (Issue #869)
* SingleFrameReader now raises StopIteration instead of IOError on calling
Expand Down
5 changes: 3 additions & 2 deletions package/MDAnalysis/coordinates/GRO.py
Original file line number Diff line number Diff line change
Expand Up @@ -297,9 +297,10 @@ def write(self, selection, frame=None):
# Atom descriptions and coords
for atom_index, atom in enumerate(atoms):
truncated_atom_index = int(str(atom_index + 1)[-5:])
truncated_resid = int(str(atom.resid)[:5])
if has_velocities:
output_gro.write(self.fmt['xyz_v'].format(
resid=atom.resid,
resid=truncated_resid,
resname=atom.resname,
index=truncated_atom_index,
name=atom.name,
Expand All @@ -308,7 +309,7 @@ def write(self, selection, frame=None):
))
else:
output_gro.write(self.fmt['xyz'].format(
resid=atom.resid,
resid=truncated_resid,
resname=atom.resname,
index=truncated_atom_index,
name=atom.name,
Expand Down
39 changes: 33 additions & 6 deletions testsuite/MDAnalysisTests/coordinates/test_gro.py
Original file line number Diff line number Diff line change
Expand Up @@ -260,13 +260,18 @@ def test_check_coordinate_limits_max_noconversion(self):


class TestGROWriterLarge(TestCase, tempdir.TempDir):
def setUp(self):
self.tmpdir = tempdir.TempDir()
self.large_universe = mda.Universe(GRO_large)

def tearDown(self):
del self.tmpdir
del self.large_universe
# not normally recommended to use class-level
# setup for universe (special case here)
@classmethod
def setUpClass(cls):
cls.tmpdir = tempdir.TempDir()
cls.large_universe = mda.Universe(GRO_large)

@classmethod
def tearDownClass(cls):
del cls.tmpdir
del cls.large_universe

@dec.slow
@attr('issue')
Expand All @@ -284,6 +289,28 @@ def test_writer_large(self):
err_msg="Writing GRO file with > 100 000 "
"coords does not truncate properly.")

@dec.slow
@attr('issue')
def test_writer_large_residue_count(self):
"""Ensure large residue number truncation for
GRO files (Issue 886)."""
outfile = os.path.join(self.tmpdir.name, 'outfile2.gro')
target_resname = self.large_universe.residues[-1].resname
resid_value = 999999999999999999999
self.large_universe.residues[-1].atoms.resids = resid_value
self.large_universe.atoms.write(outfile)
with open(outfile, 'rt') as mda_output:
output_lines = mda_output.readlines()
produced_resid = output_lines[-2].split(target_resname)[0]
expected_resid = str(resid_value)[:5]
assert_equal(produced_resid,
expected_resid,
err_msg="Writing GRO file with > 99 999 "
"resids does not truncate properly.")




class TestGROWriterVels(object):
def setUp(self):
self.tmpdir = tempdir.TempDir()
Expand Down

0 comments on commit 7220db5

Please sign in to comment.