Skip to content

Commit

Permalink
Merge pull request #52 from rsdefever/update/make-ensemble-immutable
Browse files Browse the repository at this point in the history
Prevent ensemble property of moves object from being edited
  • Loading branch information
rsdefever authored May 1, 2020
2 parents 335a458 + 741a554 commit 5f77e57
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
4 changes: 4 additions & 0 deletions mosdef_cassandra/core/moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -274,6 +274,10 @@ def ensemble(self):

@ensemble.setter
def ensemble(self, ensemble):
if hasattr(self, "_ensemble"):
raise AttributeError(
"Ensemble cannot be changed. Please create a new Moves object instead."
)
valid_ensembles = ["nvt", "npt", "gcmc", "gemc", "gemc_npt"]
if ensemble not in valid_ensembles:
raise ValueError(
Expand Down
7 changes: 7 additions & 0 deletions mosdef_cassandra/tests/test_moves.py
Original file line number Diff line number Diff line change
Expand Up @@ -554,3 +554,10 @@ def test_add_multiple_restricted_insertions(self, methane_oplsaa):
moves.add_restricted_insertions(
[methane_oplsaa], [["cylinder"]], [[3]]
)

def test_change_ensemble(self, methane_oplsaa):
moves = mc.Moves("gcmc", [methane_oplsaa])
with pytest.raises(
AttributeError, match=r"Ensemble cannot be changed"
):
moves.ensemble = "nvt"

0 comments on commit 5f77e57

Please sign in to comment.