diff --git a/MPP/MPP.py b/MPP/MPP.py index c259672..d7400e9 100755 --- a/MPP/MPP.py +++ b/MPP/MPP.py @@ -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, diff --git a/tests/data/PDZ3/expected_output/kl/Z.npy b/tests/data/PDZ3/expected_output/kl/Z.npy index a084cbc..12161ea 100644 Binary files a/tests/data/PDZ3/expected_output/kl/Z.npy and b/tests/data/PDZ3/expected_output/kl/Z.npy differ diff --git a/tests/data/lumpings.yaml b/tests/data/lumpings.yaml index 4dace28..9e61ed6 100644 --- a/tests/data/lumpings.yaml +++ b/tests/data/lumpings.yaml @@ -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 diff --git a/tests/test_plots.py b/tests/test_plots.py index 1d5409e..ad1a09f 100644 --- a/tests/test_plots.py +++ b/tests/test_plots.py @@ -9,6 +9,7 @@ from pathlib import Path import yaml import hashlib +from matplotlib import pyplot as plt import MPP.run as run_module @@ -30,6 +31,7 @@ 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() @@ -37,6 +39,7 @@ def _run_main_with_args(args_list): except SystemExit as e: return e.code, stdout.getvalue(), stderr.getvalue() finally: + plt.close("all") sys.argv = saved_argv @@ -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), @@ -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" @@ -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) @@ -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: @@ -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) diff --git a/tests/test_properties.py b/tests/test_properties.py index 694d19e..12e6352 100644 --- a/tests/test_properties.py +++ b/tests/test_properties.py @@ -10,8 +10,8 @@ SYSTEMS = [ "HP35", - "PDZ3_7", - "aSyn_rdc_200ns", + "PDZ3", + "aSyn", "HP35_stoch", ] SETUPS = [ @@ -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) diff --git a/tests/test_rmsd.py b/tests/test_rmsd.py index ca9b69b..e5d2fdb 100644 --- a/tests/test_rmsd.py +++ b/tests/test_rmsd.py @@ -13,8 +13,8 @@ SYSTEMS = [ "HP35", - "PDZ3_7", - "aSyn_rdc_200ns", + "PDZ3", + "aSyn", "HP35_stoch", ] SETUPS = [ diff --git a/tests/test_run.py b/tests/test_run.py index fb23a61..7668751 100644 --- a/tests/test_run.py +++ b/tests/test_run.py @@ -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) @@ -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) diff --git a/tests/test_utils.py b/tests/test_utils.py index cc129bb..8f44342 100644 --- a/tests/test_utils.py +++ b/tests/test_utils.py @@ -13,8 +13,8 @@ SYSTEMS = [ "HP35", - "PDZ3_7", - "aSyn_rdc_200ns", + "PDZ3", + "aSyn", "HP35_stoch", ] SETUPS = [