openforcefield / openff-models

Helper classes for Pydantic compatibility in the OpenFF stack
MIT License
3 stars 2 forks source link

Support dimensionality checking #2

Open mikemhenry opened 2 years ago

mikemhenry commented 2 years ago

It would be nice to support something like:

class Atom(DefaultModel):
    mass: FloatQuantity["mass"]

And then we would accept any unit that has dimensionality "mass". Same would go for "length" so then we would accept "nm", "angstrom", etc

something like https://github.com/hgrecco/pint/issues/1166#issuecomment-1116309404

mattwthompson commented 2 years ago

We could possibly do these as separate classes (ideally with a better name than this):

class Thing(DefaultModel):
    mass: FloatQuantity["mass"]
    some_physical_property: FloatQuantityThatOnlySpecifiesDimensionality['temperature']

It's not clear if these functionalities could be handled by the same class, and maybe it's better if they are handled by separate classes. In general this would be great for situations in which you don't care which unit is used (i.e. you will do the appropriate Quantity.magnitude_as conversions) but it is important that you don't try to measure a mass with Kelving.