WARNING: THIS SITE IS A MIRROR OF GITHUB.COM / IT CANNOT LOGIN OR REGISTER ACCOUNTS / THE CONTENTS ARE PROVIDED AS-IS / THIS SITE ASSUMES NO RESPONSIBILITY FOR ANY DISPLAYED CONTENT OR LINKS / IF YOU FOUND SOMETHING MAY NOT GOOD FOR EVERYONE, CONTACT ADMIN AT ilovescratch@foxmail.com
Skip to content
Merged
1 change: 1 addition & 0 deletions package/AUTHORS
Original file line number Diff line number Diff line change
Expand Up @@ -265,6 +265,7 @@ Chronological list of authors
- Raúl Lois-Cuns
- Pranay Pelapkar
- Shreejan Dolai
- Tanisha Dubey

External code
-------------
Expand Down
7 changes: 6 additions & 1 deletion package/MDAnalysis/analysis/msd.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,7 +382,12 @@ def _parse_msd_type(self):
"xyz": [0, 1, 2],
}

self.msd_type = self.msd_type.lower()
# Validate type first
if not isinstance(self.msd_type, str):
raise TypeError("msd_type must be a string")

# strip whitespace + lowercase
self.msd_type = self.msd_type.strip().lower()
Copy link
Contributor Author

@tanii1125 tanii1125 Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added these lines in msd.py , they do -

  1. Explicitly checks that msd_type is a string to avoid unexpected AttributeErrors.
  2. Uses .strip().lower() to handle inputs with leading/trailing whitespace
    (e.g. " xy ", " Xz "), while preserving existing case-insensitive behavior.


try:
self._dim = keys[self.msd_type]
Expand Down
14 changes: 14 additions & 0 deletions testsuite/MDAnalysisTests/analysis/test_msd.py
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,20 @@ def test_msdtype_error(self, u, SELECTION, msdtype):
with pytest.raises(ValueError, match=errmsg):
m = MSD(u, SELECTION, msd_type=msdtype)

def test_msd_type_whitespace(self, u, SELECTION):
m = MSD(u, SELECTION, msd_type=" xy ", fft=False)
assert m.dim_fac == 2
assert m._dim == [0, 1]

def test_msd_type_uppercase(self, u, SELECTION):
m = MSD(u, SELECTION, msd_type=" Xz ", fft=False)
assert m.dim_fac == 2
assert m._dim == [0, 2]

def test_msd_type_nonstring(self, u, SELECTION):
with pytest.raises(TypeError):
MSD(u, SELECTION, msd_type=123, fft=False)

Copy link
Contributor Author

@tanii1125 tanii1125 Dec 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added tests covering msd_type input handling in EinsteinMSD:

  • whitespace handling (e.g. " xy ")
  • case-insensitive parsing (existing behavior)
  • non-string inputs raising TypeError

@pytest.mark.parametrize(
"dim, dim_factor",
[
Expand Down
Loading