Skip to content

RFC: convert_units and sensibility #5378

@tylerjereddy

Description

@tylerjereddy

This came up during the review of gh-5374. self.convert_units in our parser/reader API can be a bit confusing sometimes, and I'm curious to know if:

  1. folks are happy with this design?
  2. it actually makes sense?

If we go to the latest stable release (2.10.0) for example, the GROWriter docs indicate the convert_units argument is converting units to the MDAnalysis base format, which doesn't seem desirable for writing a GRO file that would typically require nm units (and it defaults to True at that).

Image

While that appears to be a docstring error (?), things are still really confusing:

Let's try the default behavior first:

import MDAnalysis as mda
from MDAnalysisTests.datafiles import GRO
from MDAnalysis.coordinates.GRO import GROWriter

u = mda.Universe(GRO)

writer = GROWriter("dummy.gro", convert_units=True)
with writer as w:
    w.write(u.atoms)

The .gro file appears to still be using nm units:

(py_312_mda_dev) treddy@pn2405157 mda % head -5 dummy.gro
Written by MDAnalysis
47681
    1MET      N    1   5.202   4.356   3.155
    1MET     H1    2   5.119   4.411   3.172
    1MET     H2    3   5.155   4.283   3.104

now, let's try the False behavior for unit conversion:

import MDAnalysis as mda
from MDAnalysisTests.datafiles import GRO
from MDAnalysis.coordinates.GRO import GROWriter

u = mda.Universe(GRO)

writer = GROWriter("dummy.gro", convert_units=False)
with writer as w:
    w.write(u.atoms)

It looks like we're now allowing GRO files to be written with invalid A units? Do we really want to allow this?

Written by MDAnalysis
47681
    1MET      N    1  52.020  43.560  31.550
    1MET     H1    2  51.190  44.110  31.720
    1MET     H2    3  51.550  42.830  31.040

The definition of the GRO format (https://manual.gromacs.org/documentation/current/reference-manual/file-formats.html#gro) has clearly specified units (below). I could perhaps see more motivation for ingesting in native nm units, but writing in non-compliant units seems like a footgun. This is all just a bit confusing?

Image

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions