Skip to content

Commit

Permalink
Fix OpenMM unit utils API regression (#445)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBoothroyd authored Apr 26, 2022
1 parent b4de632 commit 1078ab3
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions openff/evaluator/utils/openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@

import numpy

from openff.evaluator.attributes.attributes import UndefinedAttribute

try:
import openmm
from openmm import app
Expand Down Expand Up @@ -353,3 +355,51 @@ def extract_positions(
positions = positions[particle_indices]

return positions


def openmm_quantity_to_pint(openmm_quantity):
"""Converts a `openmm.unit.Quantity` to a `openff.evaluator.unit.Quantity`.
Parameters
----------
openmm_quantity: openmm.unit.Quantity
The quantity to convert.
Returns
-------
openff.evaluator.unit.Quantity
The converted quantity.
"""

from openff.units.openmm import from_openmm

if openmm_quantity is None or isinstance(openmm_quantity, UndefinedAttribute):
return None

return from_openmm(openmm_quantity)


def pint_quantity_to_openmm(pint_quantity):
"""Converts a `openff.evaluator.unit.Quantity` to a `openmm.unit.Quantity`.
Notes
-----
Not all pint units are available in OpenMM.
Parameters
----------
pint_quantity: openff.evaluator.unit.Quantity
The quantity to convert.
Returns
-------
openmm.unit.Quantity
The converted quantity.
"""

from openff.units.openmm import to_openmm

if pint_quantity is None or isinstance(pint_quantity, UndefinedAttribute):
return None

return to_openmm(pint_quantity)

0 comments on commit 1078ab3

Please sign in to comment.