Skip to content

Commit

Permalink
make Measurement model frozen
Browse files Browse the repository at this point in the history
allows hashing, for usage in sets/dicts etc
  • Loading branch information
richardjgowers committed Nov 20, 2023
1 parent 95cca4e commit 0a88952
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
3 changes: 3 additions & 0 deletions cinnabar/measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,9 @@ def __hash__(self):

class Measurement(DefaultModel):
"""The free energy difference of moving from A to B"""
class Config:
frozen = True

labelA: Hashable
labelB: Hashable
DG: FloatQuantity['kilocalorie_per_mole']
Expand Down
27 changes: 27 additions & 0 deletions cinnabar/tests/test_measurements.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,33 @@ def test_ground():
assert g3 == g4


def test_measurement_hash():
m1 = cinnabar.Measurement(
labelA='foo', labelB='bar',
DG=0.1 * unit.kilocalorie_per_mole,
uncertainty=0.01 * unit.kilocalorie_per_mole,
computational=True,
)
m1a = cinnabar.Measurement(
labelA='foo', labelB='bar',
DG=0.1 * unit.kilocalorie_per_mole,
uncertainty=0.01 * unit.kilocalorie_per_mole,
computational=True,
)
m2 = cinnabar.Measurement(
labelA='foo', labelB='bar',
DG=0.11 * unit.kilocalorie_per_mole,
uncertainty=0.01 * unit.kilocalorie_per_mole,
computational=False,
)

thing = set([m1, m1a, m2])

assert len(thing) == 2
assert m1 in thing
assert m2 in thing


@pytest.mark.parametrize('Ki,uncertainty,dG,dG_uncertainty,label,temp', [
[100 * unit.nanomolar, 10 * unit.nanomolar, -9.55 * unit.kilocalorie_per_mole,
0.059 * unit.kilocalorie_per_mole, 'lig', 298.15 * unit.kelvin],
Expand Down

0 comments on commit 0a88952

Please sign in to comment.