Skip to content

Commit

Permalink
Merge branch 'devel' into feature_reduce
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Sep 22, 2023
2 parents 8dcc8bc + 44def0b commit 691ad64
Show file tree
Hide file tree
Showing 18 changed files with 297 additions and 64 deletions.
44 changes: 36 additions & 8 deletions python/BioSimSpace/Parameters/_Protocol/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(
tolerance=1.2,
max_distance=_Length(6, "A"),
water_model=None,
custom_parameters=None,
leap_commands=None,
bonds=None,
ensure_compatible=True,
Expand Down Expand Up @@ -154,11 +155,14 @@ 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.
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.
will be added after any default commands. 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 @@ -214,6 +218,26 @@ 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.")
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}'")

# 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)):
Expand Down Expand Up @@ -249,7 +273,7 @@ def __init__(

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

def run(self, molecule, work_dir=None, queue=None):
Expand Down Expand Up @@ -488,17 +512,21 @@ 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 extra user commands.
if self._leap_commands is not None:
for command in self._leap_commands:
file.write("%s\n" % command)
# Write custom parameters.
if self._custom_parameters is not None:
for param in self._custom_parameters:
file.write("%s\n" % param)
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:
file.write("%s\n" % command)
file.write("saveAmberParm mol leap.top leap.crd\n")
file.write("quit")

Expand Down
32 changes: 26 additions & 6 deletions python/BioSimSpace/Parameters/_parameters.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ def _parameterise_amber_protein(
tolerance=1.2,
max_distance=_Length(6, "A"),
water_model=None,
custom_parameters=None,
leap_commands=None,
bonds=None,
ensure_compatible=True,
Expand Down Expand Up @@ -171,11 +172,14 @@ 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.
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.
will be added after any default commands. 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 @@ -237,6 +241,7 @@ def _parameterise_amber_protein(
max_distance=max_distance,
water_model=water_model,
check_ions=True,
custom_parameters=custom_parameters,
leap_commands=leap_commands,
bonds=bonds,
ensure_compatible=ensure_compatible,
Expand All @@ -250,6 +255,7 @@ def _parameterise_amber_protein(
tolerance=tolerance,
water_model=water_model,
max_distance=max_distance,
custom_parameters=custom_parameters,
leap_commands=leap_commands,
bonds=bonds,
ensure_compatible=ensure_compatible,
Expand Down Expand Up @@ -796,6 +802,7 @@ def _validate(
max_distance=None,
water_model=None,
check_ions=False,
custom_parameters=None,
leap_commands=None,
bonds=None,
ensure_compatible=True,
Expand Down Expand Up @@ -832,11 +839,14 @@ 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.
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.
will be added after any default commands. 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 @@ -895,6 +905,16 @@ 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.")
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.")
Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -442,9 +442,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2537,9 +2537,10 @@ def _getFrame(self, time):
and space_prop in new_system._sire_object.propertyKeys()
):
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

# If this is a vacuum simulation, then translate the centre of mass
# of the system back to the origin.
Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Process/_namd.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Process/_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1318,9 +1318,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
10 changes: 8 additions & 2 deletions python/BioSimSpace/Process/_somd.py
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,13 @@ def getSystem(self, block="AUTO"):

new_system = _IO.readMolecules(self._restart_file)

# Try loading the trajectory file to get the box information.
try:
frame = self.getTrajectory().getFrames(-1)
box = frame._sire_object.property("space")
except:
box = None

# Since SOMD requires specific residue and water naming we copy the
# coordinates back into the original system.
old_system = self._system.copy()
Expand All @@ -564,8 +571,7 @@ def getSystem(self, block="AUTO"):
self._mapping = mapping

# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
if box and box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,7 @@ def __init__(
tolerance=1.2,
max_distance=_Length(6, "A"),
water_model=None,
custom_parameters=None,
leap_commands=None,
bonds=None,
ensure_compatible=True,
Expand Down Expand Up @@ -154,11 +155,14 @@ 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.
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.
will be added after any default commands. 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 @@ -214,6 +218,26 @@ 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.")
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}'")

# 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)):
Expand Down Expand Up @@ -249,7 +273,7 @@ def __init__(

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

def run(self, molecule, work_dir=None, queue=None):
Expand Down Expand Up @@ -488,17 +512,21 @@ 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 extra user commands.
if self._leap_commands is not None:
for command in self._leap_commands:
file.write("%s\n" % command)
# Write custom parameters.
if self._custom_parameters is not None:
for param in self._custom_parameters:
file.write("%s\n" % param)
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:
file.write("%s\n" % command)
file.write("saveAmberParm mol leap.top leap.crd\n")
file.write("quit")

Expand Down
Loading

0 comments on commit 691ad64

Please sign in to comment.