Skip to content

Commit

Permalink
Add regression test analysis (#69)
Browse files Browse the repository at this point in the history
  • Loading branch information
SimonBoothroyd committed Jan 16, 2024
1 parent ff1c8ba commit 7cdd5c8
Show file tree
Hide file tree
Showing 7 changed files with 861 additions and 3,743 deletions.
26 changes: 0 additions & 26 deletions absolv/config.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
"""Configure free energy calculations."""
import math
import typing

import femto.md.config
Expand Down Expand Up @@ -355,28 +354,3 @@ class Result(pydantic.BaseModel):
dg_std_solvent_b: OpenMMQuantity[KCAL_MOL] = pydantic.Field(
description="The standard error in ``dg_solvent_b``."
)

@property
def dg(self) -> openmm.unit.Quantity:
"""The change in free energy of transferring the solute from *solvent-a* to
*solvent-b* in units of kT."""
return self.dg_solvent_b - self.dg_solvent_a

@property
def dg_std(self) -> openmm.unit.Quantity:
"""The standard error in ``ddg``."""

std = math.sqrt(
self.dg_std_solvent_a.value_in_unit(KCAL_MOL) ** 2
+ self.dg_std_solvent_b.value_in_unit(KCAL_MOL) ** 2
)
return std * KCAL_MOL

def __str__(self):
return (
f"ΔG a->b={self.dg.value_in_unit(KCAL_MOL):.3f} kcal/mol "
f"ΔG a->b std={self.dg_std.value_in_unit(KCAL_MOL):.3f} kcal/mol"
)

def __repr__(self):
return f"{self.__repr_name__()}({self.__str__()})"
3 changes: 0 additions & 3 deletions absolv/setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,9 +118,6 @@ def setup_system(
tolerance: The minimum spacing between molecules during packing in units
compatible with angstroms.
Raises:
* PACKMOLRuntimeError
Returns:
A topology containing the molecules the coordinates were generated for and
a unit [A] wrapped numpy array of coordinates with shape=(n_atoms, 3).
Expand Down
28 changes: 1 addition & 27 deletions absolv/tests/test_config.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
import math

import openmm.unit
import pydantic
import pytest

from absolv.config import EquilibriumProtocol, Result, System
from absolv.config import EquilibriumProtocol, System


class TestSystem:
Expand Down Expand Up @@ -80,26 +77,3 @@ def test_validate_lambda_lengths(self, lambda_sterics, lambda_electrostatics):
lambda_sterics=lambda_sterics,
lambda_electrostatics=lambda_electrostatics,
)


class TestResult:
@pytest.fixture
def mock_result(self):
return Result(
dg_solvent_a=1.0 * openmm.unit.kilocalorie_per_mole,
dg_std_solvent_a=0.2 * openmm.unit.kilocalorie_per_mole,
dg_solvent_b=3.0 * openmm.unit.kilocalorie_per_mole,
dg_std_solvent_b=0.4 * openmm.unit.kilocalorie_per_mole,
)

def test_dg(self, mock_result):
assert mock_result.dg == pytest.approx(2.0) * openmm.unit.kilocalorie_per_mole
assert (
mock_result.dg_std
== pytest.approx(math.sqrt(0.2**2 + 0.4**2))
* openmm.unit.kilocalorie_per_mole
)

def test_repr(self, mock_result):
assert repr(mock_result) is not None
assert str(mock_result) is not None
Loading

0 comments on commit 7cdd5c8

Please sign in to comment.