Skip to content

Commit

Permalink
add leaflet_select exception unit test
Browse files Browse the repository at this point in the history
  • Loading branch information
yusuferentunc committed Oct 28, 2024
1 parent d074c2a commit 6c3d085
Showing 1 changed file with 69 additions and 10 deletions.
79 changes: 69 additions & 10 deletions domhmm/tests/test_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ def universe(self):
uni = mda.Universe(path2tpr, path2xtc)
return uni

@pytest.fixture(scope="class")
def analysis(self, universe):
@staticmethod
def base_test_inputs():
"""
Standard analysis options
General inputs for all DomHMM PropertyCalculation class
"""
membrane_select = "resname DPPC DIPC CHOL"
heads = {"DPPC": "PO4",
Expand All @@ -35,6 +35,14 @@ def analysis(self, universe):
"DIPC": [["C1B", "D2B", "D3B", "C4B"], ["C1A", "D2A", "D3A", "C4A"]]}
sterol_heads = {"CHOL": "ROH"}
sterol_tails = {"CHOL": ["ROH", "C1"]}
return membrane_select, heads, tails, sterol_heads, sterol_tails

@pytest.fixture(scope="class")
def analysis(self, universe):
"""
Standard analysis options
"""
membrane_select, heads, tails, sterol_heads, sterol_tails = self.base_test_inputs()

return base.LeafletAnalysisBase(universe_or_atomgroup=universe,
leaflet_kwargs={"select": "name PO4", "pbc": True},
Expand All @@ -49,13 +57,7 @@ def test_gmm_hmm_input(self, universe):
"""
Analysis option with GMM and HMM arguments
"""
membrane_select = "resname DPPC DIPC CHOL"
heads = {"DPPC": "PO4",
"DIPC": "PO4"}
tails = {"DPPC": [["C1B", "C2B", "C3B", "C4B"], ["C1A", "C2A", "C3A", "C4A"]],
"DIPC": [["C1B", "D2B", "D3B", "C4B"], ["C1A", "D2A", "D3A", "C4A"]]}
sterol_heads = {"CHOL": "ROH"}
sterol_tails = {"CHOL": ["ROH", "C1"]}
membrane_select, heads, tails, sterol_heads, sterol_tails = self.base_test_inputs()

gmm_kwargs = {"tol": 1E-4, "init_params": 'k-means++', "verbose": 0,
"max_iter": 10000, "n_init": 20,
Expand All @@ -81,6 +83,63 @@ def test_gmm_hmm_input(self, universe):
assert analysis.sterol_tails_selection.keys() == {"CHOL"}
assert analysis.n_leaflets == 2

def test_leaflet_select_exceptions(self, universe):
"""
Testing leaflet_select parameter
"""
membrane_select, heads, tails, sterol_heads, sterol_tails = self.base_test_inputs()
# Catch errors for wrong leaflet selection option
leaflet_select = None
with pytest.raises(ValueError):
base.LeafletAnalysisBase(universe_or_atomgroup=universe,
leaflet_kwargs={"select": "name PO4", "pbc": True},
membrane_select=membrane_select,
leaflet_select=leaflet_select,
heads=heads,
sterol_heads=sterol_heads,
sterol_tails=sterol_tails,
tails=tails)
leaflet_select = "Wrong String"
with pytest.raises(ValueError):
base.LeafletAnalysisBase(universe_or_atomgroup=universe,
leaflet_kwargs={"select": "name PO4", "pbc": True},
membrane_select=membrane_select,
leaflet_select=leaflet_select,
heads=heads,
sterol_heads=sterol_heads,
sterol_tails=sterol_tails,
tails=tails)
leaflet_select = ["Single Leaflet"]
with pytest.raises(AssertionError):
base.LeafletAnalysisBase(universe_or_atomgroup=universe,
leaflet_kwargs={"select": "name PO4", "pbc": True},
membrane_select=membrane_select,
leaflet_select=leaflet_select,
heads=heads,
sterol_heads=sterol_heads,
sterol_tails=sterol_tails,
tails=tails)
leaflet_select = [[1], [2]]
with pytest.raises(ValueError):
base.LeafletAnalysisBase(universe_or_atomgroup=universe,
leaflet_kwargs={"select": "name PO4", "pbc": True},
membrane_select=membrane_select,
leaflet_select=leaflet_select,
heads=heads,
sterol_heads=sterol_heads,
sterol_tails=sterol_tails,
tails=tails)
leaflet_select = [["Wrong MDA"],["Query"]]
with pytest.raises(ValueError):
base.LeafletAnalysisBase(universe_or_atomgroup=universe,
leaflet_kwargs={"select": "name PO4", "pbc": True},
membrane_select=membrane_select,
leaflet_select=leaflet_select,
heads=heads,
sterol_heads=sterol_heads,
sterol_tails=sterol_tails,
tails=tails)

def test_check_parameters(self, analysis):
"""
Checking initial parameters
Expand Down

0 comments on commit 6c3d085

Please sign in to comment.