MDAnalysis / mdanalysis

MDAnalysis is a Python library to analyze molecular dynamics simulations.
https://mdanalysis.org
Other
1.3k stars 648 forks source link

Support for Gromacs 2024 tpr #4614

Closed xiki-tempula closed 3 months ago

xiki-tempula commented 3 months ago

Expected behavior

I want to load a Gromacs 2024 tpr.

Code to reproduce the behavior

conda create -n mda -c conda-forge mdanalysis ipython

In [1]: import MDAnalysis as mda

In [2]: u = mda.Universe('gromacs.tpr', 'gromacs_out.gro')
---------------------------------------------------------------------------
NotImplementedError                       Traceback (most recent call last)
File ~/miniconda3/envs/mda/lib/python3.12/site-packages/MDAnalysis/core/universe.py:110, in _topology_from_file_like(topology_file, topology_format, **kwargs)
    109     with parser(topology_file) as p:
--> 110         topology = p.parse(**kwargs)
    111 except (IOError, OSError) as err:
    112     # There are 2 kinds of errors that might be raised here:
    113     # one because the file isn't present
    114     # or the permissions are bad, second when the parser fails

File ~/miniconda3/envs/mda/lib/python3.12/site-packages/MDAnalysis/topology/TPRParser.py:212, in TPRParser.parse(self, tpr_resid_from_one, **kwargs)
    211 try:
--> 212     th = tpr_utils.read_tpxheader(data)                    # tpxheader
    213 except (EOFError, ValueError):

File ~/miniconda3/envs/mda/lib/python3.12/site-packages/MDAnalysis/topology/tpr/utils.py:233, in read_tpxheader(data)
    232 fileVersion = data.unpack_int()  # version of tpx file
--> 233 fileVersion_err(fileVersion)
    235 # This is for backward compatibility with development version 77-79 where
    236 # the tag was, mistakenly, placed before the generation.
    237 # These versions are development versions between the 4.5 and 4.6 series.

File ~/miniconda3/envs/mda/lib/python3.12/site-packages/MDAnalysis/topology/tpr/utils.py:208, in fileVersion_err(fver)
    207 if fver not in setting.SUPPORTED_VERSIONS:
--> 208     raise NotImplementedError(
    209         f"Your tpx version is {fver}, which this parser does not support, yet "
    210     )

NotImplementedError: Your tpx version is 133, which this parser does not support, yet 

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
Cell In[2], line 1
----> 1 u = mda.Universe('gromacs.tpr', 'gromacs_out.gro')

File ~/miniconda3/envs/mda/lib/python3.12/site-packages/MDAnalysis/core/universe.py:356, in Universe.__init__(self, topology, all_coordinates, format, topology_format, transformations, guess_bonds, vdwradii, fudge_factor, lower_bound, in_memory, in_memory_step, *coordinates, **kwargs)
    354 if not isinstance(topology, Topology) and not topology is None:
    355     self.filename = _check_file_like(topology)
--> 356     topology = _topology_from_file_like(self.filename,
    357                                         topology_format=topology_format,
    358                                         **kwargs)
    360 if topology is not None:
    361     self._topology = topology

File ~/miniconda3/envs/mda/lib/python3.12/site-packages/MDAnalysis/core/universe.py:125, in _topology_from_file_like(topology_file, topology_format, **kwargs)
    121         raise IOError("Failed to load from the topology file {0}"
    122                         " with parser {1}.\n"
    123                         "Error: {2}".format(topology_file, parser, err))
    124 except (ValueError, NotImplementedError) as err:
--> 125     raise ValueError(
    126         "Failed to construct topology from file {0}"
    127         " with parser {1}.\n"
    128         "Error: {2}".format(topology_file, parser, err))
    129 return topology

ValueError: Failed to construct topology from file gromacs.tpr with parser <class 'MDAnalysis.topology.TPRParser.TPRParser'>.
Error: Your tpx version is 133, which this parser does not support, yet 

Current version of MDAnalysis

Archive.zip

IAlibay commented 3 months ago

I believe this was already added in the development version - but we haven't had the chance to make a release yet. Plans for the release are roughly mid July.

xiki-tempula commented 3 months ago
    from MDAnalysis.topology.tpr import setting

    setting.SUPPORTED_VERSIONS = (
        58,
        73,
        83,
        100,
        103,
        110,
        112,
        116,
        119,
        122,
        127,
        129,
        133,
    )

solves the problem