Skip to content

Commit 50dc512

Browse files
authored
feat: Add support for reading unit cell dimensions from MOL2 CRYSIN records (#5187)
* fixes #3341 * enable reading unit cell dimensions from MOL2 CRYSIN records * test: add test case for MOL2 CRYSIN unit cell dimensions * docs: update parser docstring * update CHANGELOG * update AUTHORS
1 parent 6a1befe commit 50dc512

5 files changed

Lines changed: 34 additions & 3 deletions

File tree

package/CHANGELOG

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ The rules for this file:
1616
-------------------------------------------------------------------------------
1717
??/??/?? IAlibay, orbeckst, marinegor, tylerjereddy, ljwoods2, marinegor,
1818
spyke7, talagayev, tanii1125, BradyAJohnston, hejamu, jeremyleung521,
19-
harshitgajjela-droid, kunjsinha, aygarwal, jauy123
19+
harshitgajjela-droid, kunjsinha, aygarwal, jauy123, Dreamstick9
2020

2121
* 2.11.0
2222

@@ -42,6 +42,7 @@ Fixes
4242
DSSP by porting upstream PyDSSP 0.9.1 fix (Issue #4913)
4343

4444
Enhancements
45+
* MOL2Parser now reads unit cell dimensions from @<TRIPOS>CRYSIN records (Issue #3341)
4546
* Reduces duplication of code in _apply() function (Issue #5247, PR #5294)
4647
* Added new top-level `MDAnalysis.fetch` module (PR #4943)
4748
* Added new function `MDAnalysis.fetch.from_PDB` to download structure files from wwPDB

package/MDAnalysis/coordinates/MOL2.py

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,11 @@
6969
* The MDAnalysis :class:`MOL2Reader` and :class:`MOL2Writer` only handle the
7070
MOLECULE, SUBSTRUCTURE, ATOM, and BOND record types. Other records are not
7171
currently read or preserved on writing.
72-
* As the CRYSIN record type is not parsed / written, MOL2 systems always have
73-
dimensions set to ``None`` and dimensionless MOL2 files are written.
72+
* The MDAnalysis :class:`MOL2Reader` reads unit cell dimensions from the
73+
@<TRIPOS>CRYSIN record. The space group and setting information (the 7th
74+
and 8th fields) are currently ignored. The unit cell is interpreted in the
75+
common crystallographic convention with box vector **a** parallel to the x-axis,
76+
**b** in the xy-plane, and **c** having a positive z-component.
7477
7578
7679
MOL2 format notes
@@ -246,6 +249,10 @@ def _read_frame(self, frame):
246249
self.ts.data[sect] = sections[sect]
247250
except KeyError:
248251
pass
252+
if "crysin" in sections:
253+
line = sections["crysin"][0].strip()
254+
dims = line.split()[:6]
255+
self.ts.dimensions = np.array(dims, dtype=np.float32)
249256

250257
self.ts.positions = np.array(coords, dtype=np.float32)
251258

testsuite/MDAnalysisTests/coordinates/test_mol2.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
# J. Comput. Chem. 32 (2011), 2319--2327, doi:10.1002/jcc.21787
2222
#
2323
import pytest
24+
import numpy as np
2425

2526
import os
2627
from numpy.testing import (
@@ -29,6 +30,7 @@
2930
assert_array_almost_equal,
3031
TestCase,
3132
assert_almost_equal,
33+
assert_allclose,
3234
)
3335

3436
from MDAnalysisTests.datafiles import (
@@ -39,6 +41,7 @@
3941
mol2_comments_header,
4042
mol2_ligand,
4143
mol2_sodium_ion,
44+
mol2_crysin,
4245
)
4346
from MDAnalysis import Universe
4447
import MDAnalysis as mda
@@ -232,3 +235,11 @@ def test_mol2_universe_write(tmpdir):
232235
assert_almost_equal(u.atoms.positions, u2.atoms.positions)
233236
# MDA does not current implement @<TRIPOS>CRYSIN reading
234237
assert u2.dimensions is None
238+
239+
240+
def test_mol2_crysin_dimensions():
241+
# test that crysin records are read as dimensions
242+
u = mda.Universe(mol2_crysin)
243+
244+
expected = np.array([40.0, 50.0, 60.0, 90.0, 90.0, 90.0], dtype=np.float32)
245+
assert_allclose(u.dimensions, expected, atol=1e-3)
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
@<TRIPOS>MOLECULE
2+
test_structure
3+
1 0 0 0 0
4+
SMALL
5+
USER_CHARGES
6+
@<TRIPOS>ATOM
7+
1 C 0.0000 0.0000 0.0000 C.3 1 ALA 0.0000
8+
@<TRIPOS>CRYSIN
9+
40.0000 50.0000 60.0000 90.0000 90.0000 90.0000 1 1
10+
@<TRIPOS>END

testsuite/MDAnalysisTests/datafiles.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,7 @@
245245
"mol2_comments_header",
246246
"mol2_ligand",
247247
"mol2_sodium_ion",
248+
"mol2_crysin",
248249
"capping_input",
249250
"capping_output",
250251
"capping_ace",
@@ -745,6 +746,7 @@
745746
mol2_zinc = (_data_ref / "mol2/zinc_856218.mol2").as_posix()
746747
# MOL2 file without bonds
747748
mol2_sodium_ion = (_data_ref / "mol2/sodium_ion.mol2").as_posix()
749+
mol2_crysin = (_data_ref / "mol2/test_crysin.mol2").as_posix()
748750

749751
capping_input = (_data_ref / "capping/aaqaa.gro").as_posix()
750752
capping_output = (_data_ref / "capping/maestro_aaqaa_capped.pdb").as_posix()

0 commit comments

Comments
 (0)