Skip to content

Commit

Permalink
Merge branch 'zst-bytes-compression' of github.com:OpenFreeEnergy/guf…
Browse files Browse the repository at this point in the history
…e into zst-bytes-compression
  • Loading branch information
atravitz committed Dec 10, 2024
2 parents 7c1a21d + 8bee94c commit cc3de40
Show file tree
Hide file tree
Showing 4 changed files with 65 additions and 5 deletions.
2 changes: 2 additions & 0 deletions .git-blame-ignore-revs
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
# https://github.com/OpenFreeEnergy/gufe/pull/421 -- big auto format MMH
d27100a5b7b303df155e2b6d7874883d105e24bf
# https://github.com/OpenFreeEnergy/gufe/pull/431 -- fix some files that didn't get formatted MMH
f8c49d59e756130a995d02dfe04d7a91acb1d791
5 changes: 0 additions & 5 deletions .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,3 @@ repos:
- id: interrogate
args: [--fail-under=28]
pass_filenames: false
- repo: https://github.com/asottile/pyupgrade
rev: v3.15.0
hooks:
- id: pyupgrade
args: ["--py39-plus"]
36 changes: 36 additions & 0 deletions gufe/chemicalsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,42 @@ def components(self) -> dict[str, Component]:
"""
return dict(self._components)

def component_diff(self, other) -> tuple[tuple[Component, ...], tuple[Component, ...]]:
"""Compare the Components of this ChemicalSystem with the Components of another ChemicalSystem.
Parameters
----------
other : ChemicalSystem
The ChemicalSystem to compare to.
Returns
-------
tuple[tuple[Component, ...], tuple[Component, ...]]
A tuple containing two tuples. The first tuple contains
the components that are unique to this ChemicalSystem, and
the second tuple contains the components that are unique
to the other ChemicalSystem.
Raises
------
TypeError
If `other` is not an instance of `ChemicalSystem`.
"""

if not isinstance(other, ChemicalSystem):
raise TypeError(
f"`other` must be an instance of `{ChemicalSystem.__qualname__}`, not `{other.__class__.__qualname__}`"
)

self_comps = set(self._components.values())
other_comps = set(other._components.values())

self_uniques = tuple(self_comps.difference(other_comps))
other_uniques = tuple(other_comps.difference(self_comps))

return (self_uniques, other_uniques)

@property
def name(self):
"""
Expand Down
27 changes: 27 additions & 0 deletions gufe/tests/test_chemicalsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import pytest

from gufe import ChemicalSystem
from gufe.components import ProteinComponent

from .test_tokenization import GufeTokenizableTestsMixin

Expand Down Expand Up @@ -56,6 +57,32 @@ def test_hash_and_eq(prot_comp, solv_comp, toluene_ligand_comp):
assert hash(c1) == hash(c2)


def test_chemical_system_component_diff(solvated_complex, solvated_ligand):
comps_diff = solvated_complex.component_diff(solvated_ligand)

assert isinstance(comps_diff, tuple)

comps_complex, comps_ligand = comps_diff

assert isinstance(comps_complex, tuple)
assert isinstance(comps_ligand, tuple)

assert len(comps_complex) == 1
assert len(comps_ligand) == 0

assert isinstance(comps_complex[0], ProteinComponent)

# A.component_diff(B) equals the reversed output of B.component_diff(A)
assert solvated_complex.component_diff(solvated_ligand) == solvated_ligand.component_diff(solvated_complex)[::-1]


def test_chemical_system_component_diff_incompatible_comparison(solvated_complex, phenol_ligand_comp):
with pytest.raises(
TypeError, match=r"`other` must be an instance of `ChemicalSystem`, not `SmallMoleculeComponent`"
):
solvated_complex.component_diff(phenol_ligand_comp)


def test_chemical_system_neq_1(solvated_complex, prot_comp):
# wrong class
assert solvated_complex != prot_comp
Expand Down

0 comments on commit cc3de40

Please sign in to comment.