Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent ensemble property of moves object from being edited #52

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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"