Skip to content

Commit

Permalink
Merge pull request #69 from drorlab/68-recognize-single-string-trj-ex…
Browse files Browse the repository at this point in the history
…tract_coordinates

make extract_coordinates work with a single string as trajectory input
  • Loading branch information
martinvoegele authored Jan 25, 2025
2 parents 7685bc2 + 757e10c commit 7c67c45
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions pensa/preprocessing/coordinates.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ def extract_coordinates(top, pdb, trj_list, out_name, sel_string, start_frame=0,
Can read all MDAnalysis-compatible topology formats.
pdb : str
File name for the reference PDB file.
trj_list : list of str
File names for the input trajectory.
trj_list : str or list of str
File name(s) for the input trajectory.
Can read all MDAnalysis-compatible trajectory formats.
out_name : str
Core of the file names for the output files.
Expand All @@ -29,6 +29,9 @@ def extract_coordinates(top, pdb, trj_list, out_name, sel_string, start_frame=0,
First frame to read from the trajectory.
"""
# Convert the trajectory input to a list if it is a single string
if type(trj_list) is str:
trj_list = [trj_list]
# Read the topology+PDB files and extract selected parts.
u = mda.Universe(top, pdb)
u.residues.resids -= residues_offset
Expand Down
5 changes: 4 additions & 1 deletion tests/test_workflow.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,14 +100,17 @@ def setUp(self):
)

# Extract the coordinates of the TM region from the trajectory
# - Test using a single trajectory directly
self.file_tm_single_a = extract_coordinates(
self.ref_file_a, self.pdb_file_a, [self.trj_file_a],
self.ref_file_a, self.pdb_file_a, self.trj_file_a,
self.trj_name_a + "_tm", sel_string_a
)
# - Test using a single trajectory as a list
self.file_tm_single_b = extract_coordinates(
self.ref_file_b, self.pdb_file_b, [self.trj_file_b],
self.trj_name_b + "_tm", sel_string_b
)
# - Test using multiple trajectories
self.file_tm_combined = extract_coordinates_combined(
[self.ref_file_a] * 3 + [self.ref_file_b] * 3,
self.trj_file_a + self.trj_file_b,
Expand Down

0 comments on commit 7c67c45

Please sign in to comment.