Skip to content

Commit

Permalink
Merge pull request #11 from mattwthompson/fix-pint-1
Browse files Browse the repository at this point in the history
Parse SimTK units with get_name instead of get_symbol
  • Loading branch information
mattwthompson authored Jun 5, 2020
2 parents b8d7a92 + 4c0490c commit dce1059
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 6 deletions.
20 changes: 15 additions & 5 deletions system/tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,23 @@

u = pint.UnitRegistry()

def test_simtk_to_pint():
simtk_quantitites = [
4.0 * simtk_unit.nanometer,
5.0 * simtk_unit.angstrom,
]
pint_quantities = [
4.0 * u.nanometer,
5.0 * u.angstrom,
]
@pytest.mark.parametrize(
'simtk_quantity,pint_quantity',
[(s, p) for s, p in zip(simtk_quantitites, pint_quantities)]
)
def test_simtk_to_pint(simtk_quantity, pint_quantity):
"""Test conversion from SimTK Quantity to pint Quantity."""
simtk_quantity = 10.0 * simtk_unit.nanometer

pint_quantity = simtk_to_pint(simtk_quantity)
converted_pint_quantity = simtk_to_pint(simtk_quantity)

assert pint_quantity == 10.0 * u.nanometer
assert pint_quantity == converted_pint_quantity

def test_pint_to_simtk():
"""Test conversion from pint Quantity to SimTK Quantity."""
Expand Down
2 changes: 1 addition & 1 deletion system/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ def simtk_to_pint(simtk_quantity):
simtk_value = simtk_quantity.value_in_unit(simtk_unit)

u = pint.UnitRegistry()
pint_unit = u(simtk_unit.get_symbol())
pint_unit = u(simtk_unit.get_name())
pint_quantity = simtk_value * pint_unit

return pint_quantity
Expand Down

0 comments on commit dce1059

Please sign in to comment.