Skip to content

Commit

Permalink
More robust phase_path order handling
Browse files Browse the repository at this point in the history
  • Loading branch information
andrrizzi committed Dec 1, 2017
1 parent 5d071df commit d94cbcc
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 27 deletions.
2 changes: 0 additions & 2 deletions Yank/experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -1657,15 +1657,13 @@ def _is_pipeline_solvent_with_receptor(field, solvent_id, error):
type: string
validator: file_exists
validator: supported_system_files
coerce: sort_system_files_by_type
phase2_path:
required: no
type: list
schema:
type: string
validator: file_exists
validator: supported_system_files
coerce: sort_system_files_by_type
gromacs_include_dir:
required: no
type: string
Expand Down
22 changes: 15 additions & 7 deletions Yank/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -857,6 +857,7 @@ def get_system_files_paths(self, system_id):
"""
Paths = collections.namedtuple('Paths', ['position_path', 'parameters_path'])
system_dir = os.path.join(self.setup_dir, self.SYSTEMS_DIR, system_id)

if 'receptor' in self.systems[system_id]:
system_files_paths = [
Paths(position_path=os.path.join(system_dir, 'complex.inpcrd'),
Expand All @@ -872,13 +873,20 @@ def get_system_files_paths(self, system_id):
parameters_path=os.path.join(system_dir, 'solvent2.prmtop'))
]
else:
system_files_paths = [
Paths(position_path=self.systems[system_id]['phase1_path'][0],
parameters_path=self.systems[system_id]['phase1_path'][1]),
Paths(position_path=self.systems[system_id]['phase2_path'][0],
parameters_path=self.systems[system_id]['phase2_path'][1])
]

parameter_file_extensions = {'prmtop', 'top', 'xml'}
system_files_paths = []
for phase_path_name in ['phase1_path', 'phase2_path']:
file_paths = self.systems[system_id][phase_path_name]
assert len(file_paths) == 2

# Make sure that the position file is first.
first_file_extension = os.path.splitext(file_paths[0])[1][1:]
if first_file_extension in parameter_file_extensions:
file_paths = list(reversed(file_paths))

# Append Paths object.
system_files_paths.append(Paths(position_path=file_paths[0],
parameters_path=file_paths[1]))
return system_files_paths

def is_molecule_setup(self, molecule_id):
Expand Down
17 changes: 0 additions & 17 deletions Yank/schema/validator.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,6 @@ def _normalize_coerce_single_str_to_list(self, value):
"""Cast a single string to a list of string"""
return [value] if isinstance(value, str) else value

def _normalize_coerce_sort_system_files_by_type(self, file_paths):
"""Sort the system files path to have positions first and parameters second."""
file_extensions = [os.path.splitext(file_path)[1][1:] for file_path in file_paths]

# In all cases but for the pair (rst7, prmtop) we can just sort alphabetically.
sorted_file_paths = [file_path for ext, file_path in sorted(zip(file_extensions, file_paths))]
if 'rst7' not in file_extensions:
# reversed() return an iterator.
return list(reversed(sorted_file_paths))
return sorted_file_paths

# ====================================================
# DATA VALIDATORS
# ====================================================
Expand Down Expand Up @@ -73,12 +62,6 @@ def _validator_int_or_all_string(self, field, value):

def _validator_supported_system_files(self, field, file_paths):
"""Ensure the input system files are supported."""
# Check that this is a list of two file_paths.
if len(file_paths) != 2:
self._error(field, '{} must be a list of paths to the position '
'and parameter files'.format(field))
return

# Obtain the extension of the system files.
file_extensions = {os.path.splitext(file_path)[1][1:] for file_path in file_paths}

Expand Down
2 changes: 1 addition & 1 deletion Yank/tests/test_experiment.py
Original file line number Diff line number Diff line change
Expand Up @@ -619,7 +619,7 @@ def test_validation_wrong_systems():
{'receptor': 'rec', 'ligand': 'lig', 'solvent': 'solv3',
'parameters': 'leaprc.ff14SB'}),

("list of paths",
("phase1_path: \[must be of list type\]",
{'phase1_path': data_paths['bentol-complex'][0],
'phase2_path': data_paths['bentol-solvent'],
'ligand_dsl': 'resname BEN', 'solvent': 'solv'}),
Expand Down

0 comments on commit d94cbcc

Please sign in to comment.