Skip to content

Commit

Permalink
Merge pull request #226 from OpenBioSim/fix_225
Browse files Browse the repository at this point in the history
Fix issue #225
  • Loading branch information
lohedges authored Dec 14, 2023
2 parents d86dc9f + 02ca3bf commit b17b7c2
Show file tree
Hide file tree
Showing 6 changed files with 298 additions and 168 deletions.
76 changes: 35 additions & 41 deletions python/BioSimSpace/Parameters/_Protocol/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ def __init__(
tolerance=1.2,
max_distance=_Length(6, "A"),
water_model=None,
custom_parameters=None,
leap_commands=None,
pre_mol_commands=None,
post_mol_commands=None,
bonds=None,
ensure_compatible=True,
property_map={},
Expand Down Expand Up @@ -155,14 +155,17 @@ def __init__(
Run 'BioSimSpace.Solvent.waterModels()' to see the supported
water models.
custom_parameters: [str]
A list of paths to custom parameter files. When this option is set,
we can no longer fall back on GROMACS's pdb2gmx.
pre_mol_commands : [str]
A list of custom LEaP commands to be executed before loading the molecule.
This can be used for loading custom parameter files, or sourcing additional
scripts. Make sure to use absolute paths when specifying any external files.
When this option is set, we can no longer fall back on GROMACS's pdb2gmx.
leap_commands : [str]
An optional list of extra commands for the LEaP program. These
will be added after any default commands. When this option is set,
we can no longer fall back on GROMACS's pdb2gmx.
post_mol_commands : [str]
A list of custom LEaP commands to be executed after loading the molecule.
This allows the use of additional commands that operate on the molecule,
which is named "mol". When this option is set, we can no longer fall
back on GROMACS's pdb2gmx.
bonds : ((class:`Atom <BioSimSpace._SireWrappers.Atom>`, class:`Atom <BioSimSpace._SireWrappers.Atom>`))
An optional tuple of atom pairs to specify additional atoms that
Expand Down Expand Up @@ -218,34 +221,25 @@ def __init__(
else:
self._water_model = water_model

# Validate the custom parameter file list.
if custom_parameters is not None:
if not isinstance(custom_parameters, (list, tuple)):
raise TypeError("'custom_parameters' must be a 'list' of 'str' types.")
# Validate the additional leap commands.
if pre_mol_commands is not None:
if not isinstance(pre_mol_commands, (list, tuple)):
raise TypeError("'pre_mol_commands must be a 'list' of 'str' types.")
else:
if not all(isinstance(x, str) for x in custom_parameters):
if not all(isinstance(x, str) for x in pre_mol_commands):
raise TypeError(
"'custom_parameters' must be a 'list' of 'str' types."
"'pre_mol_commands' must be a 'list' of 'str' types."
)
for x in custom_parameters:
if not os.path.isfile(x):
raise ValueError(f"Custom parameter file does not exist: '{x}'")

# Convert to absolute paths.
self._custom_parameters = []
for x in enumerate(custom_parameters):
self._custom_parameters.append(_os.path.abspath(x))
else:
self._custom_parameters = None

# Validate the additional leap commands.
if leap_commands is not None:
if not isinstance(leap_commands, (list, tuple)):
raise TypeError("'leap_commands' must be a 'list' of 'str' types.")
self._pre_mol_commands = pre_mol_commands
if post_mol_commands is not None:
if not isinstance(post_mol_commands, (list, tuple)):
raise TypeError("'post_mol_commands must be a 'list' of 'str' types.")
else:
if not all(isinstance(x, str) for x in leap_commands):
raise TypeError("'leap_commands' must be a 'list' of 'str' types.")
self._leap_commands = leap_commands
if not all(isinstance(x, str) for x in post_mol_commands):
raise TypeError(
"'post_mol_commands' must be a 'list' of 'str' types."
)
self._post_mol_commands = post_mol_commands

# Validate the bond records.
if bonds is not None:
Expand Down Expand Up @@ -273,7 +267,7 @@ def __init__(

# Set the compatibility flags.
self._tleap = True
if self._custom_parameters is not None or self._leap_commands is not None:
if self._pre_mol_commands is not None or self._post_mol_commands is not None:
self._pdb2gmx = False

def run(self, molecule, work_dir=None, queue=None):
Expand Down Expand Up @@ -512,20 +506,20 @@ def _run_tleap(self, molecule, work_dir):
file.write("source leaprc.water.tip4pew\n")
else:
file.write("source leaprc.water.%s\n" % self._water_model)
# Write custom parameters.
if self._custom_parameters is not None:
for param in self._custom_parameters:
file.write("%s\n" % param)
# Write pre-mol user leap commands.
if self._pre_mol_commands is not None:
for command in self._pre_mol_commands:
file.write("%s\n" % command)
file.write("mol = loadPdb leap.pdb\n")
# Add any disulphide bond records.
for bond in disulphide_bonds:
file.write("%s\n" % bond)
# Add any additional bond records.
for bond in pruned_bond_records:
file.write("%s\n" % bond)
# Write user leap commands.
if self._leap_commands is not None:
for command in self._leap_commands:
# Write post-mol user leap commands.
if self._post_mol_commands is not None:
for command in self._post_mol_commands:
file.write("%s\n" % command)
file.write("saveAmberParm mol leap.top leap.crd\n")
file.write("quit")
Expand Down
97 changes: 54 additions & 43 deletions python/BioSimSpace/Parameters/_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,8 +135,8 @@ def _parameterise_amber_protein(
tolerance=1.2,
max_distance=_Length(6, "A"),
water_model=None,
custom_parameters=None,
leap_commands=None,
pre_mol_commands=None,
post_mol_commands=None,
bonds=None,
ensure_compatible=True,
work_dir=None,
Expand Down Expand Up @@ -172,14 +172,17 @@ def _parameterise_amber_protein(
or lone oxygen atoms corresponding to structural (crystal) water
molecules.
custom_parameters: [str]
A list of paths to custom parameter files. When this option is set,
we can no longer fall back on GROMACS's pdb2gmx.
pre_mol_commands : [str]
A list of custom LEaP commands to be executed before loading the molecule.
This can be used for loading custom parameter files, or sourcing additional
scripts. Make sure to use absolute paths when specifying any external files.
When this option is set, we can no longer fall back on GROMACS's pdb2gmx.
leap_commands : [str]
An optional list of extra commands for the LEaP program. These
will be added after any default commands. When this option is set,
we can no longer fall back on GROMACS's pdb2gmx.
post_mol_commands : [str]
A list of custom LEaP commands to be executed after loading the molecule.
This allows the use of additional commands that operate on the molecule,
which is named "mol". When this option is set, we can no longer fall
back on GROMACS's pdb2gmx.
bonds : ((class:`Atom <BioSimSpace._SireWrappers.Atom>`, class:`Atom <BioSimSpace._SireWrappers.Atom>`))
An optional tuple of atom pairs to specify additional atoms that
Expand Down Expand Up @@ -241,8 +244,8 @@ def _parameterise_amber_protein(
max_distance=max_distance,
water_model=water_model,
check_ions=True,
custom_parameters=custom_parameters,
leap_commands=leap_commands,
pre_mol_commands=pre_mol_commands,
post_mol_commands=post_mol_commands,
bonds=bonds,
ensure_compatible=ensure_compatible,
property_map=property_map,
Expand All @@ -255,8 +258,8 @@ def _parameterise_amber_protein(
tolerance=tolerance,
water_model=water_model,
max_distance=max_distance,
custom_parameters=custom_parameters,
leap_commands=leap_commands,
pre_mol_commands=pre_mol_commands,
post_mol_commands=post_mol_commands,
bonds=bonds,
ensure_compatible=ensure_compatible,
property_map=property_map,
Expand Down Expand Up @@ -802,8 +805,8 @@ def _validate(
max_distance=None,
water_model=None,
check_ions=False,
custom_parameters=None,
leap_commands=None,
pre_mol_commands=None,
post_mol_commands=None,
bonds=None,
ensure_compatible=True,
work_dir=None,
Expand Down Expand Up @@ -839,14 +842,17 @@ def _validate(
Whether to check for the presence of structural ions. This is only
required when parameterising with protein force fields.
custom_parameters: [str]
A list of paths to custom parameter files. When this option is set,
we can no longer fall back on GROMACS's pdb2gmx.
pre_mol_commands : [str]
A list of custom LEaP commands to be executed before loading the molecule.
This can be used for loading custom parameter files, or sourcing additional
scripts. Make sure to use absolute paths when specifying any external files.
When this option is set, we can no longer fall back on GROMACS's pdb2gmx.
leap_commands : [str]
An optional list of extra commands for the LEaP program. These
will be added after any default commands. When this option is set,
we can no longer fall back on GROMACS's pdb2gmx.
post_mol_commands : [str]
A list of custom LEaP commands to be executed after loading the molecule.
This allows the use of additional commands that operate on the molecule,
which is named "mol". When this option is set, we can no longer fall
back on GROMACS's pdb2gmx.
bonds : ((class:`Atom <BioSimSpace._SireWrappers.Atom>`, class:`Atom <BioSimSpace._SireWrappers.Atom>`))
An optional tuple of atom pairs to specify additional atoms that
Expand Down Expand Up @@ -905,22 +911,19 @@ def _validate(
"Please choose a 'water_model' for the ion parameters."
)

if custom_parameters is not None:
if not isinstance(custom_parameters, (list, tuple)):
raise TypeError("'custom_parameters' must be a 'list' of 'str' types.")
if pre_mol_commands is not None:
if not isinstance(pre_mol_commands, (list, tuple)):
raise TypeError("'pre_mol_commands' must be a 'list' of 'str' types.")
else:
if not all(isinstance(x, str) for x in custom_parameters):
raise TypeError("'custom_parameters' must be a 'list' of 'str' types.")
for x in custom_parameters:
if not os.path.isfile(x):
raise ValueError(f"Custom parameter file does not exist: '{x}'")

if leap_commands is not None:
if not isinstance(leap_commands, (list, tuple)):
raise TypeError("'leap_commands' must be a 'list' of 'str' types.")
if not all(isinstance(x, str) for x in pre_mol_commands):
raise TypeError("'pre_mol_commands' must be a 'list' of 'str' types.")

if post_mol_commands is not None:
if not isinstance(post_mol_commands, (list, tuple)):
raise TypeError("'post_mol_commands' must be a 'list' of 'str' types.")
else:
if not all(isinstance(x, str) for x in leap_commands):
raise TypeError("'leap_commands' must be a 'list' of 'str' types.")
if not all(isinstance(x, str) for x in post_mol_commands):
raise TypeError("'post_mol_commands' must be a 'list' of 'str' types.")

if bonds is not None:
if molecule is None:
Expand Down Expand Up @@ -981,7 +984,8 @@ def _function(
tolerance=1.2,
max_distance=_Length(6, "A"),
water_model=None,
leap_commands=None,
pre_mol_commands=None,
post_mol_commands=None,
bonds=None,
ensure_compatible=True,
work_dir=None,
Expand Down Expand Up @@ -1013,11 +1017,17 @@ def _function(
or lone oxygen atoms corresponding to structural (crystal) water
molecules.
leap_commands : [str]
An optional list of extra commands for the LEaP program. These
will be added after any default commands and can be used to, e.g.,
load additional parameter files. When this option is set, we can no
longer fall back on GROMACS's pdb2gmx.
pre_mol_commands : [str]
A list of custom LEaP commands to be executed before loading the molecule.
This can be used for loading custom parameter files, or sourcing additional
scripts. Make sure to use absolute paths when specifying any external files.
When this option is set, we can no longer fall back on GROMACS's pdb2gmx.
post_mol_commands : [str]
A list of custom LEaP commands to be executed after loading the molecule.
This allows the use of additional commands that operate on the molecule,
which is named "mol". When this option is set, we can no longer fall
back on GROMACS's pdb2gmx.
bonds : ((class:`Atom <BioSimSpace._SireWrappers.Atom>`, class:`Atom <BioSimSpace._SireWrappers.Atom>`))
An optional tuple of atom pairs to specify additional atoms that
Expand Down Expand Up @@ -1052,7 +1062,8 @@ def _function(
tolerance=tolerance,
max_distance=max_distance,
water_model=water_model,
leap_commands=leap_commands,
pre_mol_commands=pre_mol_commands,
post_mol_commands=post_mol_commands,
bonds=bonds,
ensure_compatible=ensure_compatible,
work_dir=work_dir,
Expand Down
Loading

0 comments on commit b17b7c2

Please sign in to comment.