Skip to content

Commit

Permalink
Mol2 universe (#2718)
Browse files Browse the repository at this point in the history
* Fixes issue 2717

* Adds tests

* Switched ag safeguard to encode_block
  • Loading branch information
IAlibay authored Jun 8, 2020
1 parent e835b5b commit ae6193e
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 0 deletions.
1 change: 1 addition & 0 deletions package/CHANGELOG
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ mm/dd/yy richardjgowers, kain88-de, lilyminium, p-j-smith, bdice, joaomcteixeira
* 0.21.0

Fixes
* MOL2Writer now accepts both Universes and AtomgGroups (Issue #2717)
* Use user-provided `remark` in `XYZWriter` (Issue #2692)
* Added more informative error messages about topology attributes
(Issue #2565)
Expand Down
2 changes: 2 additions & 0 deletions package/MDAnalysis/coordinates/MOL2.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,8 @@ def encode_block(self, obj):
----------
obj : AtomGroup or Universe
"""
# Issue 2717
obj = obj.atoms
traj = obj.universe.trajectory
ts = traj.ts

Expand Down
17 changes: 17 additions & 0 deletions testsuite/MDAnalysisTests/coordinates/test_mol2.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
from numpy.testing import (
assert_equal, assert_array_equal,
assert_array_almost_equal, TestCase,
assert_almost_equal
)

from MDAnalysisTests.datafiles import (
Expand Down Expand Up @@ -190,3 +191,19 @@ def test_mol2_multi_write(tmpdir):
u = mda.Universe(mol2_molecules)
u.atoms[:4].write('group1.mol2')
u.atoms[:4].write('group1.mol2')


def test_mol2_universe_write(tmpdir):
# see Issue 2717
with tmpdir.as_cwd():
outfile = 'test.mol2'

u = mda.Universe(mol2_comments_header)

with mda.Writer(outfile) as W:
W.write(u)

u2 = mda.Universe(outfile)

assert_almost_equal(u.atoms.positions, u2.atoms.positions)
assert_almost_equal(u.dimensions, u2.dimensions)

0 comments on commit ae6193e

Please sign in to comment.