Skip to content
Draft
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
6 changes: 3 additions & 3 deletions MPP/MPP.py
Original file line number Diff line number Diff line change
Expand Up @@ -272,9 +272,9 @@ def _add_feature(
self.mean_feature_trajectory = self.multi_feature_trajectory_bool.mean(axis=1)
self.mean_feature = np.zeros(self.n_states)
for i in range(self.n_states):
self.mean_feature[i] = self.mean_feature_trajectory[
self.trajectory == i
].mean()
state_mask = self.trajectory == i
if np.any(state_mask):
self.mean_feature[i] = self.mean_feature_trajectory[state_mask].mean()

def run_mpp(
self,
Expand Down
Binary file modified tests/data/PDZ3/expected_output/kl/Z.npy
Binary file not shown.
32 changes: 13 additions & 19 deletions tests/data/lumpings.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,18 @@
fnc/:
feature kernel: fnc
kernel similarity: F
js/:
js:
feature kernel: JS
kernel similarity: F
kl/:
feature kernel: null
kernel similarity: none
kl:
feature kernel: none
kernel similarity: KL
kl_fnc/:
feature kernel: fnc
kernel similarity: KL
kl_js/:
kl_js:
feature kernel: JS
kernel similarity: KL
ref/:
feature kernel: null
kernel similarity: P
ref_fnc/:
feature kernel: fnc
kernel similarity: P
ref_js/:
t:
feature kernel: none
kernel similarity: T
t_js:
feature kernel: JS
kernel similarity: P
kernel similarity: T
gpcca:
feature kernel: ref
kernel similarity: gpcca
13 changes: 9 additions & 4 deletions tests/test_plots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
from pathlib import Path
import yaml
import hashlib
from matplotlib import pyplot as plt
import MPP.run as run_module


Expand All @@ -30,13 +31,15 @@ def _run_main_with_args(args_list):
saved_argv = sys.argv
sys.argv = ["run.py"] + args_list
stdout, stderr = StringIO(), StringIO()
plt.close("all")
try:
with redirect_stdout(stdout), redirect_stderr(stderr):
run_module.main()
return 0, stdout.getvalue(), stderr.getvalue()
except SystemExit as e:
return e.code, stdout.getvalue(), stderr.getvalue()
finally:
plt.close("all")
sys.argv = saved_argv


Expand All @@ -51,7 +54,7 @@ def setUp(self):
with open(MAPPING_FILE, "r") as f:
self.param_map = yaml.safe_load(f)

def _run_plot(self, config, d, g, kind, output_file, stochastic=False):
def _run_plot(self, dataset, config, d, g, kind, output_file, stochastic=False):
key = self._get_key(d, g)
args = [
str(config),
Expand All @@ -65,7 +68,7 @@ def _run_plot(self, config, d, g, kind, output_file, stochastic=False):
str(
Path(__file__).parent
/ "data"
/ config.parent.name
/ dataset
/ "expected_output"
/ key
/ f"Z{'_stochastic' if stochastic else ''}.npy"
Expand All @@ -85,6 +88,7 @@ def run_single_plot_test(
config = (
self.data_root
/ dataset
/ "input"
/ f"config{'_stochastic' if stochastic else ''}.yml"
)
key = self._get_key(d, g)
Expand All @@ -103,11 +107,12 @@ def run_single_plot_test(
/ expected_file.name
)
plot_path.unlink(missing_ok=True)
plot_path.parent.mkdir(parents=True, exist_ok=True)
else:
plot_path = tmpdir / expected_file.name

exit_code, stdout, stderr = self._run_plot(
config, d, g, kind, plot_path, stochastic=stochastic
dataset, config, d, g, kind, plot_path, stochastic=stochastic
)
self.assertEqual(exit_code, 0, f"Plot command failed: {stderr}")
if manual_inspection:
Expand Down Expand Up @@ -156,7 +161,7 @@ def test_manual_macrotraj_ref(self):

def test_manual_macrotraj_PDZ3(self):
dataset = "PDZ3"
d, g = "T", "none"
d, g = "KL", "none"
kind = "macrotraj"
self.run_single_plot_test(dataset, kind, d, g, manual_inspection=True)

Expand Down
6 changes: 3 additions & 3 deletions tests/test_properties.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@

SYSTEMS = [
"HP35",
"PDZ3_7",
"aSyn_rdc_200ns",
"PDZ3",
"aSyn",
"HP35_stoch",
]
SETUPS = [
Expand Down Expand Up @@ -55,4 +55,4 @@ def test_gmrq(self):
np.testing.assert_allclose(self.mpp.gmrq[0], 2.65830228)

def test_davies_bouldin_index(self):
np.testing.assert_allclose(self.mpp.davies_bouldin_index[0], 2.18738)
np.testing.assert_allclose(self.mpp.davies_bouldin_index[0], 2.18738, atol=1e-6)
4 changes: 2 additions & 2 deletions tests/test_rmsd.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

SYSTEMS = [
"HP35",
"PDZ3_7",
"aSyn_rdc_200ns",
"PDZ3",
"aSyn",
"HP35_stoch",
]
SETUPS = [
Expand Down
3 changes: 2 additions & 1 deletion tests/test_run.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ def run_and_validate_output(self, dataset, d, g, stochastic=False):
config_file = (
self.base_data_dir
/ dataset
/ "input"
/ f"config{'_stochastic' if stochastic else ''}.yml"
)
key = self._get_key(d, g)
Expand Down Expand Up @@ -176,7 +177,7 @@ def assert_same_file_count(self, expected_dir, actual_dir, pattern="*"):
def _run_random_frames_indices(self, dataset, d, g, r=20):
key = self._get_key(d, g)
z_file = self.base_data_dir / dataset / "expected_output" / key / "Z.npy"
config_file = self.base_data_dir / dataset / "config.yml"
config_file = self.base_data_dir / dataset / "input" / "config.yml"
with self.subTest(dataset=dataset, d=d, g=g, r=r):
with tempfile.TemporaryDirectory() as tmpdir:
output_dir = Path(tmpdir)
Expand Down
4 changes: 2 additions & 2 deletions tests/test_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@

SYSTEMS = [
"HP35",
"PDZ3_7",
"aSyn_rdc_200ns",
"PDZ3",
"aSyn",
"HP35_stoch",
]
SETUPS = [
Expand Down