Skip to content

Commit

Permalink
Merge pull request #214 from OpenBioSim/backport_210
Browse files Browse the repository at this point in the history
Backport fixes from PR #210.
  • Loading branch information
lohedges authored Dec 14, 2023
2 parents f27817e + 3f97e00 commit f273b68
Show file tree
Hide file tree
Showing 23 changed files with 462 additions and 219 deletions.
19 changes: 19 additions & 0 deletions doc/source/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,25 @@ company supporting open-source development of fostering academic/industrial coll
within the biomolecular simulation community. Our software is hosted via the `OpenBioSim`
`GitHub <https://github.com/OpenBioSim/biosimspace>`__ organisation.

`2023.4.1 <https://github.com/openbiosim/biosimspace/compare/2023.4.0...2023.4.1>`_ - Dec 14 2023
-------------------------------------------------------------------------------------------------

* Make sure ``match_water`` keyword argument is passed to specialised solvation functions (`#190 <https://github.com/OpenBioSim/biosimspace/pull/190>`__).
* Check perturbable molecules for velocities when combining molecules (`#192 <https://github.com/OpenBioSim/biosimspace/pull/192>`__).
* Make sure velocities are double counted when searching for velocity properties when combining molecules (`#197 <https://github.com/OpenBioSim/biosimspace/pull/197>`__).
* Remove redundant ``BioSimSpace.Types.Type.__ne__`` operator (`#201 <https://github.com/OpenBioSim/biosimspace/pull/201>`__).
* Minor internal updates due to Sire API fixes (`#203 <https://github.com/OpenBioSim/biosimspace/pull/203>`__).
* Fixed bug in the BSS Boresch restraint search code (`@fjclark <https://github.com/fjclark>`_) (`#204 <https://github.com/OpenBioSim/biosimspace/pull/204>`__).
* Fixed ``renumber`` option in :meth:`extract <BioSimSpace._SireWrappers.Molecule.extract>` method (`#210 <https://github.com/OpenBioSim/biosimspace/pull/210>`__).
* Add workaround for fixing reconstruction of intrascale matrix in :func:`readPerturbableSystem <BioSimSpace.IO.readPerturbableSystem>` function (`#210 <https://github.com/OpenBioSim/biosimspace/pull/210>`__).
* Remove incorrect ``try_import`` statement in metadynamics driver script and make sure that global parameters in OpenMM script are unique (`#217 <https://github.com/OpenBioSim/biosimspace/pull/217>`__).
* Ensure the existing trajectory backend is used when getting the number of trajectory frames from a running process (`#219 <https://github.com/OpenBioSim/biosimspace/pull/219>`__).
* Fixed setting of ``igb`` config parameter for PMEMD simulations (`@annamherz <https://github.com/annamherz>`_) (`#220 <https://github.com/OpenBioSim/biosimspace/pull/220>`__).
* Make sure AMBER restraint mask matches all hydrogen atoms (`#222 <https://github.com/OpenBioSim/biosimspace/pull/222>`__).
* Ensure all searches for disulphide bonds are convert to a ``SelectorBond`` object (`#224 <https://github.com/OpenBioSim/biosimspace/pull/224>`__).
* Fix injection of custom commands into ``LEaP`` script (`#226 <https://github.com/OpenBioSim/biosimspace/pull/226>`__).


`2023.4.0 <https://github.com/openbiosim/biosimspace/compare/2023.3.1...2023.4.0>`_ - Oct 13 2023
-------------------------------------------------------------------------------------------------

Expand Down
25 changes: 23 additions & 2 deletions python/BioSimSpace/IO/_io.py
Original file line number Diff line number Diff line change
Expand Up @@ -1100,9 +1100,13 @@ def readPerturbableSystem(top0, coords0, top1, coords1, property_map={}):
# Flag that the molecule is perturbable.
mol.setProperty("is_perturbable", _SireBase.wrap(True))

# Get the two molecules.
mol0 = system0[idx]._sire_object
mol1 = system1[idx]._sire_object

# Add the molecule0 and molecule1 properties.
mol.setProperty("molecule0", system0[idx]._sire_object)
mol.setProperty("molecule1", system1[idx]._sire_object)
mol.setProperty("molecule0", mol0)
mol.setProperty("molecule1", mol1)

# Get the connectivity property name.
conn_prop = property_map.get("connectivity", "connectivity")
Expand All @@ -1121,6 +1125,23 @@ def readPerturbableSystem(top0, coords0, top1, coords1, property_map={}):
mol = mol.removeProperty(conn_prop + "0").molecule()
mol = mol.removeProperty(conn_prop + "1").molecule()

# Reconstruct the intrascale matrices using the GroTop parser.
intra0 = (
_SireIO.GroTop(_Molecule(mol0).toSystem()._sire_object)
.toSystem()[0]
.property("intrascale")
)
intra1 = (
_SireIO.GroTop(_Molecule(mol1).toSystem()._sire_object)
.toSystem()[0]
.property("intrascale")
)

# Set the "intrascale" properties.
intrascale_prop = property_map.get("intrascale", "intrascale")
mol.setProperty(intrascale_prop + "0", intra0)
mol.setProperty(intrascale_prop + "1", intra0)

# Commit the changes.
mol = _Molecule(mol.commit())

Expand Down
6 changes: 2 additions & 4 deletions python/BioSimSpace/Metadynamics/_aux/metadynamics.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,8 @@
USE OR OTHER DEALINGS IN THE SOFTWARE.
"""

from ..._Utils import _try_import

mm = _try_import("openmm")
unit = _try_import("openmm.unit", "conda install -c conda-forge openmm")
import openmm as mm
from openmm import unit

from collections import namedtuple
from functools import reduce
Expand Down
78 changes: 36 additions & 42 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 Expand Up @@ -725,7 +719,7 @@ def _get_disulphide_bonds(

# Try searching for disulphide bonds.
try:
disulphides = query(mol, property_map)
disulphides = query(mol, property_map).bonds()
except:
disulphides = []

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 f273b68

Please sign in to comment.