Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test unit handling in GMSO for standard unit conversion utilities #747

Merged
merged 12 commits into from
Aug 11, 2023

Conversation

CalCraven
Copy link
Contributor

This PR looks to make a central set of utilities for handling complex unit conversions, such that a given engine or topology can ask for a unyt UnitSystem and easily return a given parameter in that style. Will be useful when trying to perform conversions for a writer that are specified in the writer argument, instead of just always assuming that a specific parameter and unit output is desired.

  • Unit System class with common default conversions
  • utility to convert to a desired dimension
  • proper handling for lj units
  • unit testing
  • Use the LAMMPS_UnitSystems in the lammpswriter
  • Issues raised/addressed

gmso/formats/lammpsdata.py Fixed Show fixed Hide fixed
gmso/tests/test_units.py Fixed Show fixed Hide fixed
gmso/tests/test_units.py Fixed Show fixed Hide fixed
gmso/tests/test_units.py Fixed Show fixed Hide fixed
@codecov
Copy link

codecov bot commented Jul 18, 2023

Codecov Report

Patch coverage: 97.97% and project coverage change: +0.08% 🎉

Comparison is base (8b639c6) 91.95% compared to head (0036e5a) 92.04%.

Additional details and impacted files
@@            Coverage Diff             @@
##             main     #747      +/-   ##
==========================================
+ Coverage   91.95%   92.04%   +0.08%     
==========================================
  Files          67       67              
  Lines        6814     6873      +59     
==========================================
+ Hits         6266     6326      +60     
+ Misses        548      547       -1     
Files Changed Coverage Δ
gmso/core/topology.py 95.73% <75.00%> (-0.34%) ⬇️
gmso/utils/units.py 98.90% <98.79%> (-1.10%) ⬇️
gmso/formats/lammpsdata.py 95.88% <100.00%> (-0.06%) ⬇️

... and 1 file with indirect coverage changes

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

gmso/formats/lammpsdata.py Fixed Show fixed Hide fixed
@CalCraven CalCraven linked an issue Jul 18, 2023 that may be closed by this pull request
Copy link
Member

@daico007 daico007 left a comment

Choose a reason for hiding this comment

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

I reviewed the code and have some comments/suggestions. Looks great overall! The LAMMPSUnitsSystem is quite neat. The tests for units seem to cover all new methods, but I think we should test some of them individually, just so if they fail in the future, it's easier to debug.

gmso/utils/units.py Show resolved Hide resolved
gmso/utils/units.py Outdated Show resolved Hide resolved
gmso/utils/units.py Outdated Show resolved Hide resolved
gmso/tests/test_units.py Outdated Show resolved Hide resolved
gmso/utils/units.py Outdated Show resolved Hide resolved
gmso/tests/test_units.py Show resolved Hide resolved
Copy link
Member

@daico007 daico007 left a comment

Choose a reason for hiding this comment

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

The new changes look great! A few comments (can be discussed more tomorrow) about where some methods should stay (in or out of the LAMMPS_UnitSystem) leftover print, Å, etc.,. Also, we might want to add a bit more documentation/example/tutorials about how the unit system to be used (i.e., one is assigned to the topology, but will only be used during the writing out step, and will have no effect on the current unit that the topology is using).

get_parameter_dimension(1 * u.kJ / u.mol / u.nm, "(length)") == u.nm
)

def test_convert_to_unit_system(self):
Copy link
Member

Choose a reason for hiding this comment

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

Desirable, but may be on a subsequent PR

# convert a whole topology to a specific unit system
pass

def test_generate_unit_styles(self):
Copy link
Member

Choose a reason for hiding this comment

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

Would be useful to have too, or at least show what unit systems we are currently support.

gmso/utils/units.py Outdated Show resolved Hide resolved
gmso/utils/units.py Outdated Show resolved Hide resolved
gmso/utils/units.py Show resolved Hide resolved
gmso/utils/units.py Outdated Show resolved Hide resolved
Copy link
Member

@daico007 daico007 left a comment

Choose a reason for hiding this comment

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

LGTM! I will probably merge this after all the unit tests pass

@daico007 daico007 merged commit 0b9e0c5 into mosdef-hub:main Aug 11, 2023
14 checks passed
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.

Unit conversions in packages should be added to utils.units
2 participants