Skip to content

Commit

Permalink
remove box_vector from ChemicalSystem
Browse files Browse the repository at this point in the history
was causing trouble in eq situations
  • Loading branch information
richardjgowers committed Apr 11, 2023
1 parent 2bbaabc commit 1a613e4
Show file tree
Hide file tree
Showing 4 changed files with 5 additions and 57 deletions.
19 changes: 0 additions & 19 deletions gufe/chemicalsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,6 @@ class ChemicalSystem(GufeTokenizable, abc.Mapping):
The molecular representation of the chemical state, including
connectivity and coordinates. This is a frozendict with user-defined
labels as keys, :class:`.Component`\ s as values.
box_vectors
Numpy array indicating shape and size of unit cell for the system. May
be a partial definition to allow for variability on certain dimensions.
name
Optional identifier for the chemical state; used as part of the
(hashable) graph node itself when the chemical state is added to an
Expand All @@ -32,7 +29,6 @@ class ChemicalSystem(GufeTokenizable, abc.Mapping):
def __init__(
self,
components: Dict[str, Component],
box_vectors: Optional[np.ndarray] = None,
name: Optional[str] = "",
):
"""Create a node for an alchemical network.
Expand All @@ -43,10 +39,6 @@ def __init__(
The molecular representation of the chemical state, including
connectivity and coordinates. Given as a dict with user-defined
labels as keys, :class:`.Component`\ s as values.
box_vectors
Optional ``numpy`` array indicating shape and size of unit cell for
the system. May be a partial definition to allow for variability on
certain dimensions.
name
Optional identifier for the chemical state; included with the other
attributes as part of the (hashable) graph node itself when the
Expand All @@ -58,11 +50,6 @@ def __init__(
self._components = components
self._name = name

if box_vectors is None:
self._box_vectors = np.array([np.nan] * 9)
else:
self._box_vectors = box_vectors

def __repr__(self):
return (
f"{self.__class__.__name__}(name={self.name}, components={self.components})"
Expand All @@ -73,7 +60,6 @@ def _to_dict(self):
"components": {
key: value for key, value in sorted(self.components.items())
},
"box_vectors": self.box_vectors.tolist(),
"name": self.name,
}

Expand All @@ -83,18 +69,13 @@ def _from_dict(cls, d):
components={
key: value for key, value in d["components"].items()
},
box_vectors=np.array(d["box_vectors"]),
name=d["name"],
)

@property
def components(self):
return dict(self._components)

@property
def box_vectors(self):
return np.array(self._box_vectors)

@property
def name(self):
return self._name
Expand Down
31 changes: 1 addition & 30 deletions gufe/tests/test_chemicalsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,6 @@ def test_chemical_system_neq_2(solvated_complex, prot_comp, solv_comp,
assert hash(solvated_complex) != hash(complex2)


def test_chemical_system_neq_3(solvated_complex, prot_comp, solv_comp,
toluene_ligand_comp):
# different unit cell size
complex2 = ChemicalSystem(
{'protein': prot_comp,
'solvent': solv_comp,
'ligand': toluene_ligand_comp},
box_vectors=np.array([10, 0, 0] + [np.nan] * 6),
)
assert solvated_complex != complex2
assert hash(solvated_complex) != hash(complex2)


def test_chemical_system_neq_4(solvated_complex, solvated_ligand):
# different component keys
assert solvated_complex != solvated_ligand
Expand Down Expand Up @@ -131,28 +118,12 @@ def test_sorting(solvated_complex, solvated_ligand):
class TestChemicalSystem(GufeTokenizableTestsMixin):

cls = ChemicalSystem
key = "ChemicalSystem-1f244420be5cf662c0f804b052ef2a1e"
repr = "ChemicalSystem(name=, components={'solvent': SolventComponent(name=O, K+, Cl-), 'ligand': SmallMoleculeComponent(name=toluene)})"

@pytest.fixture
def instance(self, solv_comp, toluene_ligand_comp):
return ChemicalSystem(
{'solvent': solv_comp,
'ligand': toluene_ligand_comp},
box_vectors=np.array([10, 10, 10, 90, 90, 90.]),
)


class TestChemicalSystemNanBox(GufeTokenizableTestsMixin):

cls = ChemicalSystem
key = "ChemicalSystem-34f6bd8be97cc184bad334e6f8daa469"
key = "ChemicalSystem-92176395ceb86ecd7787ce2585b24218"
repr = "ChemicalSystem(name=, components={'solvent': SolventComponent(name=O, K+, Cl-), 'ligand': SmallMoleculeComponent(name=toluene)})"

@pytest.fixture
def instance(self, solv_comp, toluene_ligand_comp):
return ChemicalSystem(
{'solvent': solv_comp,
'ligand': toluene_ligand_comp},
box_vectors=np.array([np.nan, 10, 10, 90, 90, 90.]),
)
4 changes: 2 additions & 2 deletions gufe/tests/test_network.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@
class TestAlchemicalNetwork(GufeTokenizableTestsMixin):

cls = AlchemicalNetwork
key = "AlchemicalNetwork-71e52000bd30c7e03857ec8f2abf0f66"
repr = "<AlchemicalNetwork-71e52000bd30c7e03857ec8f2abf0f66>"
key = "AlchemicalNetwork-8c6df17d7ecf5902e2e338984cc11140"
repr = "<AlchemicalNetwork-8c6df17d7ecf5902e2e338984cc11140>"

@pytest.fixture
def instance(self, benzene_variants_star_map):
Expand Down
8 changes: 2 additions & 6 deletions gufe/tests/test_transformation.py
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ def complex_equilibrium(solvated_complex):
class TestTransformation(GufeTokenizableTestsMixin):

cls = Transformation
key = "Transformation-0969b1cd6232bf5d78c47216f0200177"
key = "Transformation-decb5cda54a4092529bd47a2305c3169"
repr = "Transformation(stateA=ChemicalSystem(name=, components={'ligand': SmallMoleculeComponent(name=toluene), 'solvent': SolventComponent(name=O, K+, Cl-)}), stateB=ChemicalSystem(name=, components={'protein': ProteinComponent(name=), 'solvent': SolventComponent(name=O, K+, Cl-), 'ligand': SmallMoleculeComponent(name=toluene)}), protocol=<DummyProtocol-84b834e05f8a280c0c26a161010f52c8>)"

@pytest.fixture
Expand Down Expand Up @@ -126,7 +126,7 @@ def test_dump_load_roundtrip(self, absolute_transformation):
class TestNonTransformation(GufeTokenizableTestsMixin):

cls = NonTransformation
key = "NonTransformation-a3604da309c4016df7c1bd5340626825"
key = "NonTransformation-f82418b1fcc30dc3ec1e8e196a208aa8"
repr = "NonTransformation(stateA=ChemicalSystem(name=, components={'protein': ProteinComponent(name=), 'solvent': SolventComponent(name=O, K+, Cl-), 'ligand': SmallMoleculeComponent(name=toluene)}), stateB=ChemicalSystem(name=, components={'protein': ProteinComponent(name=), 'solvent': SolventComponent(name=O, K+, Cl-), 'ligand': SmallMoleculeComponent(name=toluene)}), protocol=<DummyProtocol-84b834e05f8a280c0c26a161010f52c8>)"

@pytest.fixture
Expand Down Expand Up @@ -203,7 +203,3 @@ def test_equality(self, complex_equilibrium, solvated_ligand, solvated_complex):
solvated_ligand, protocol=DummyProtocol(settings=DummyProtocol.default_settings())
)
assert complex_equilibrium != different_system

def test_dict_roundtrip(self):
# TODO: need registration of `Protocol`s for this to work
...

0 comments on commit 1a613e4

Please sign in to comment.