From e9d594527fef7c888f96e6e7883ac5354e0d63e1 Mon Sep 17 00:00:00 2001 From: "Pablo M. Blanco" <75744061+pm-blanco@users.noreply.github.com> Date: Wed, 20 Nov 2024 14:53:08 +0100 Subject: [PATCH] fix output for trajectory files for globular proteins for CI testing (#105) * fix output for trajectory files for globular proteins for CI testing * make pylint happy --- samples/Beyer2024/globular_protein.py | 14 ++--- .../globular_protein_functional_tests.py | 52 +++++++++---------- 2 files changed, 33 insertions(+), 33 deletions(-) diff --git a/samples/Beyer2024/globular_protein.py b/samples/Beyer2024/globular_protein.py index 0347fa7..4e9a312 100644 --- a/samples/Beyer2024/globular_protein.py +++ b/samples/Beyer2024/globular_protein.py @@ -132,8 +132,12 @@ WCA=False Electrostatics=False +data_path = args.output +if data_path is None: + data_path=pmb.get_resource(path="samples/Beyer2024/")+"/time_series/globular_protein" + # The trajectories of the simulations will be stored using espresso built-up functions in separed files in the folder 'frames' -Path("./frames").mkdir(parents=True, +Path(f"{data_path}/frames").mkdir(parents=True, exist_ok=True) espresso_system = espressomd.System(box_l=[Box_L.to('reduced_length').magnitude] * 3) @@ -265,7 +269,7 @@ #Save the initial state n_frame = 0 -with open('frames/trajectory'+str(n_frame)+'.vtf', mode='w+t') as coordinates: +with open(f'{data_path}/frames/trajectory'+str(n_frame)+'.vtf', mode='w+t') as coordinates: vtf.writevsf(espresso_system, coordinates) vtf.writevcf(espresso_system, coordinates) # Setup the potential energy @@ -337,7 +341,7 @@ if step % stride_traj == 0 : n_frame +=1 - with open('frames/trajectory'+str(n_frame)+'.vtf', mode='w+t') as coordinates: + with open(f'{data_path}/frames/trajectory'+str(n_frame)+'.vtf', mode='w+t') as coordinates: vtf.writevsf(espresso_system, coordinates) vtf.writevcf(espresso_system, coordinates) @@ -349,9 +353,7 @@ charge_amino = np.mean(charge_residues_per_type[label]) time_series[label].append(charge_amino) -data_path = args.output -if data_path is None: - data_path=pmb.get_resource(path="samples/Beyer2024/")+"/time_series/globular_protein" + Path(data_path).mkdir(parents=True, exist_ok=True) diff --git a/testsuite/globular_protein_functional_tests.py b/testsuite/globular_protein_functional_tests.py index 4eace2d..6d9b78c 100644 --- a/testsuite/globular_protein_functional_tests.py +++ b/testsuite/globular_protein_functional_tests.py @@ -26,13 +26,11 @@ import pandas as pd import unittest as ut import glob -import re - + root = pathlib.Path(__file__).parent.parent.resolve() data_root = root / "testsuite" / "globular_protein_tests_data" script_path = root / "samples" / "Beyer2024" / "globular_protein.py" -frame_folder = root / "frames" test_pH_values = [2, 5, 7] tasks = ["1beb", "1f6s"] mode = "test" @@ -67,7 +65,25 @@ def kernel_move (protein_pdb): "--mode", "test", "--output", time_series_path, "--move_protein", "--no_verbose", "--ideal" ] print(subprocess.list2cmdline(run_command)) subprocess.check_output(run_command) - return + frame_folder = f"{time_series_path}/frames" + list_files = glob.glob(f"{frame_folder}/*.vtf") + coords={"first_frame": [], + "last_frame": []} + # Read the first and the last trajectory to check that the protein has moved + for frame in list_files: + num = int(frame[-5]) + with open(frame) as f: + for line in f: + line_clean = line.split() + if line_clean: + header = line_clean[0] + if header.isnumeric(): + coord_part = line_clean[1:] + if int (num) == 0: + coords["first_frame"].append(coord_part) + elif int (num) == (len(list_files)-1): + coords["last_frame"].append(coord_part) + return coords @@ -97,29 +113,11 @@ def test_globular_protein(self): def test_globular_protein_enable_motion(self): - kernel_move("1beb") - - list_files = glob.glob(f"{frame_folder}/*.vtf") - first_trajectory_coord_list = [] - last_trajectory_coord_list = [] - - for frame in list_files: - num = re.findall(r'\d+', frame) - with open(frame) as f: - for line in f: - line_clean = line.split() - if line_clean: - header = line_clean[0] - if header.isnumeric(): - coord_part = line_clean[1:] - if int (num[0]) == 0: - first_trajectory_coord_list.append(coord_part) - elif int (num[0]) == (len(list_files)-1): - last_trajectory_coord_list.append(coord_part) - - print(first_trajectory_coord_list) - print(last_trajectory_coord_list) - np.testing.assert_raises(AssertionError, np.testing.assert_array_equal, first_trajectory_coord_list, last_trajectory_coord_list) + coords=kernel_move("1beb") + np.testing.assert_raises(AssertionError, + np.testing.assert_array_equal, + coords["first_frame"], + coords["last_frame"]) if __name__ == "__main__": ut.main()