Skip to content

Fix incorrect unit conversion factors in units.py#5053

Merged
orbeckst merged 18 commits intoMDAnalysis:developfrom
raulloiscuns:develop
Oct 14, 2025
Merged

Fix incorrect unit conversion factors in units.py#5053
orbeckst merged 18 commits intoMDAnalysis:developfrom
raulloiscuns:develop

Conversation

@raulloiscuns
Copy link
Contributor

@raulloiscuns raulloiscuns commented May 28, 2025

Fixes #5051

Changes made in this Pull Request:

The conversion factors for A/fs, A/ms and A/us have been revised and corrected in units.py.

PR Checklist

  • Issue raised/referenced?
  • Tests updated/added?
  • Documentation updated/added?
  • package/CHANGELOG file updated?
  • Is your name in package/AUTHORS? (If it is not, add it!)

Developers Certificate of Origin

I certify that I can submit this code contribution as described in the Developer Certificate of Origin, under the MDAnalysis LICENSE.


📚 Documentation preview 📚: https://mdanalysis--5053.org.readthedocs.build/en/5053/

Copy link

@github-actions github-actions bot left a comment

Choose a reason for hiding this comment

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

Hello there first time contributor! Welcome to the MDAnalysis community! We ask that all contributors abide by our Code of Conduct and that first time contributors introduce themselves on GitHub Discussions so we can get to know you. You can learn more about participating here. Please also add yourself to package/AUTHORS as part of this PR.

@codecov
Copy link

codecov bot commented Jun 5, 2025

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 92.67%. Comparing base (19e675b) to head (e9f24c2).
⚠️ Report is 24 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff             @@
##           develop    #5053      +/-   ##
===========================================
- Coverage    92.68%   92.67%   -0.01%     
===========================================
  Files          180      180              
  Lines        22452    22452              
  Branches      3186     3186              
===========================================
- Hits         20810    20808       -2     
- Misses        1167     1170       +3     
+ Partials       475      474       -1     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

Thank you VERY much for finding this very old bug. I assume you found it while working with LAMMPS files? Great work fixing and also updating the tests.

Please address the following points (see inline comments for details)

  • update CHANGELOG (include your GitHub handle and rewrite/add entries a bit)
  • please add Å/nm to the conversions (I will merge your PR if you don't do it but it would be nice as it fits directly in with your fix)
  • please remove the formatting change to the LAMMPS writer, we'd like to keep PRs focused on one thing

Apologies that it took a while to review your PR.

for index, vel in zip(indices, velocities):
self.f.write(
"{i:d} {x:f} {y:f} {z:f}\n".format(
"{i:d} {x:.8f} {y:.8f} {z:.8f}\n".format(
Copy link
Member

Choose a reason for hiding this comment

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

This may be useful but does not belong into this PR. Please revert and make a separate PR – then people knowledgable about LAMMPS can discuss.

Copy link
Member

Choose a reason for hiding this comment

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

reverted

Copy link
Member

Choose a reason for hiding this comment

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

It seems that the writer test does not pass unless we force higher precision. Our LAMMPS test files have 10 decimals so I am tentatively setting all output to .10f.

@orbeckst orbeckst self-assigned this Jun 11, 2025
@orbeckst
Copy link
Member

@raulloiscuns it would be great to add your fix to MDAnalysis soon. Are you able to address the review comments?

@orbeckst orbeckst mentioned this pull request Oct 14, 2025
Copy link
Member

@orbeckst orbeckst left a comment

Choose a reason for hiding this comment

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

I am finishing the PR so that we can include it in the 2.10.0 release.

for index, vel in zip(indices, velocities):
self.f.write(
"{i:d} {x:f} {y:f} {z:f}\n".format(
"{i:d} {x:.8f} {y:.8f} {z:.8f}\n".format(
Copy link
Member

Choose a reason for hiding this comment

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

reverted

@orbeckst orbeckst added this to the Release 2.10.0 milestone Oct 14, 2025
Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

I'm not reviewing this PR, but please do order the changelog entries properly to save me time on release.

* Fixes the benchmark `SimpleRmsBench` in `benchmarks/analysis/rms.py`
by changing the way weights for RMSD are calculated, instead of
directly passing them. (Issue #3520, PR #5006)
* Fixes incorrect conversion factors for speed units A/fs, A/us, A/ms
Copy link
Member

Choose a reason for hiding this comment

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

Please put things done in this PR at the top of the entry list.

Copy link
Member

Choose a reason for hiding this comment

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

ok, I'll also move the entry from PR #5113 up

@orbeckst
Copy link
Member

I am using pre-commit with black 24 and it passes and then our linters/black fails; I probably need to sync the settings in some way, until then there'll be more micro commits of the type "blackened file xxx" (which I'll squash merge).

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

I might as well actually review rather than just lurk.

Copy link
Member

Choose a reason for hiding this comment

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

Not this PR, just a general comment. We should probably come up with some kind of rule about autoformatting the changelog, personally not sure it makes sense to have black apply to it since it's just free-form text.

Copy link
Member

Choose a reason for hiding this comment

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

Sorry, didn't see that it removed all the trailing whitespace.

This is my fault for not configuring pre-commit hook properly (or disabling it). It won't let me commit until it's happy and I may just not have the right .pre-commit-config.yaml.

Copy link
Member

Choose a reason for hiding this comment

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

I think it wasn't black that touched CHANGELOG because when I only committed CHANGELOG, black did not engage

(mda-develop) mac:MDAnalysisTests oliver$ git commit --amend
black................................................(no files to check)Skipped
flake8...............................................(no files to check)Skipped
trim trailing whitespace.................................................Passed
fix end of files.........................................................Passed
check yaml...........................................(no files to check)Skipped
check for added large files..............................................Passed
check for merge conflicts................................................Passed

Instead it's likely the trim trailing whitespace plugin for pre-commit.

It would be great to have an expert share a pre-commit yaml file for MDA development.

@IAlibay
Copy link
Member

IAlibay commented Oct 14, 2025

I am using pre-commit with black 24 and it passes and then our linters/black fails; I probably need to sync the settings in some way, until then there'll be more micro commits of the type "blackened file xxx" (which I'll squash merge).

cc @RMeli

- add tests for unit conversion with unicode characters
- add additional representations Å/us, Å/µs, Å/fs, Å/ms
Copy link
Member

Choose a reason for hiding this comment

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

Sorry for the noise. When I reverted a change, pre-commit/flake/black were all unhappy about the file so I did some line breaking and a single real fix.

Copy link
Member

@IAlibay IAlibay left a comment

Choose a reason for hiding this comment

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

lgtm, thanks!

- match precision in our test files
- required for tests to pass when round-tripping velocities
- updated CHANGELOG
@orbeckst
Copy link
Member

Thanks @IAlibay , just updated CHANGELOG with output precision changes and ran black locally again. I think I just don't have the right settings for pre-commit black and our black and need to sort that out.

If the latest changes pass our CI, I'll also approve and squash-merge. Thanks a lot for your extra 👀 — much appreciated!

@orbeckst orbeckst enabled auto-merge (squash) October 14, 2025 16:59
@orbeckst orbeckst merged commit 03eef45 into MDAnalysis:develop Oct 14, 2025
16 of 24 checks passed
@orbeckst
Copy link
Member

(This got automerged on approval... I had thought it would wait for all of CI... oops, sorry. All linters and Linux had passed at least. If anything gets messed up on develop I'll fix it.)

@orbeckst
Copy link
Member

@raulloiscuns your PR got merged and your fix will be in 2.10.0. 🎉 Thank you very much for identifying the problem and proposing a solution!

@RMeli
Copy link
Member

RMeli commented Oct 15, 2025

Sorry @orbeckst and @IAlibay, I just noticed the ping. But looks like the linters passed, do you know what changed in order to fix things?

@orbeckst
Copy link
Member

I am using the following .pre-commit.yml

Details
# Pre-commit configuration for MDAnalysis
repos:
  # Black - Python code formatter
  - repo: https://github.com/psf/black
    # workaround https://github.com/psf/black/issues/2493#issuecomment-1081987650
    rev: 'refs/tags/24.10.0:refs/tags/24.10.0'
    hooks:
      - id: black
        language_version: python3
        # Use project's Black configuration from pyproject.toml
        files: \.(py)$

  # Flake8 - Python linter (more lenient for this project)
  - repo: https://github.com/pycqa/flake8
    rev: 7.3.0
    hooks:
      - id: flake8
        args: [
          --max-line-length=88,
          "--extend-ignore=E203,W503,F401,F841,E722,E711,E712,E713,E714,F811"
        ]
        files: \.(py)$

  # Additional useful hooks
  - repo: https://github.com/pre-commit/pre-commit-hooks
    rev: v6.0.0
    hooks:
      - id: trailing-whitespace
      - id: end-of-file-fixer
      - id: check-yaml
      - id: check-added-large-files
      - id: check-merge-conflict

and I would have hoped that it fixes anything that our GH linters would find offensive. Instead, I had to repeatedly manually run black on files that the black linter did not like.

I probably didn't configure my pre-commit exactly the way that MDAnalysis wants it. A sample yaml file that "just works" would be useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug in conversion units of speed

4 participants

Comments