Skip to content

Commit

Permalink
make it a full mappings
Browse files Browse the repository at this point in the history
  • Loading branch information
dwhswenson committed Apr 1, 2022
1 parent 543eb99 commit b4e093a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
9 changes: 8 additions & 1 deletion gufe/chemicalsystem.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# This code is part of OpenFE and is licensed under the MIT license.
# For details, see https://github.com/OpenFreeEnergy/gufe

from collections import abc
from typing import Dict, Optional

import numpy as np
Expand All @@ -9,7 +10,7 @@
from .component import Component


class ChemicalSystem(Serializable):
class ChemicalSystem(Serializable, abc.Mapping):
"""A node of an alchemical network.
Attributes
Expand Down Expand Up @@ -130,6 +131,12 @@ def total_charge(self):
def __getitem__(self, item):
return self.components[item]

def __iter__(self):
return iter(self.components)

def __len__(self):
return len(self.components)

@classmethod
def as_protein_smallmolecule_solvent(cls):
""" """
Expand Down
6 changes: 6 additions & 0 deletions gufe/tests/test_chemicalsystem.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,9 @@ def test_ligand_construction(solv_comp, toluene_ligand_comp):
)

assert len(state.components) == 2
assert len(state) == 2

assert list(state) == ['solvent', 'ligand']

assert state.components['solvent'] == solv_comp
assert state.components['ligand'] == toluene_ligand_comp
Expand All @@ -71,6 +74,9 @@ def test_complex_construction(prot_comp, solv_comp, toluene_ligand_comp):
)

assert len(state.components) == 3
assert len(state) == 3

assert list(state) == ['protein', 'solvent', 'ligand']

assert state.components['protein'] == prot_comp
assert state.components['solvent'] == solv_comp
Expand Down

0 comments on commit b4e093a

Please sign in to comment.