Skip to content

Commit

Permalink
Merge pull request #136 from OpenBioSim/backport_133_135
Browse files Browse the repository at this point in the history
Backport fixes from PRs #133 and #135
  • Loading branch information
lohedges authored Jul 24, 2023
2 parents 511cb6b + efbcbee commit 60e0884
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 13 deletions.
6 changes: 3 additions & 3 deletions nodes/playground/BSSEqBoundNode.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,8 @@
" process = BSS.Process.Amber(system, protocol, exe=pmemd_path)\n",
" elif engine == \"GROMACS\":\n",
" process = BSS.Process.Gromacs(system, protocol)\n",
"\n",
" elif engine == \"OpenMM\":\n",
" process = BSS.Process.OpenMM(system, protocol)\n",
" # Start the process.\n",
" process.start()\n",
"\n",
Expand Down Expand Up @@ -296,8 +297,7 @@
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.9.15"
"pygments_lexer": "ipython3"
}
},
"nbformat": 4,
Expand Down
23 changes: 19 additions & 4 deletions python/BioSimSpace/Process/_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,10 @@ def _generate_config(self):
self.addToConfig("simulation.context.setPositions(prm.positions)")
self.addToConfig("if prm.box_vectors is not None:")
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*prm.box_vectors)"
" box_vectors = reducePeriodicBoxVectors(prm.box_vectors)"
)
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*box_vectors)"
)
self.addToConfig(
f"simulation.minimizeEnergy(maxIterations={self._protocol.getSteps()})"
Expand Down Expand Up @@ -452,7 +455,10 @@ def _generate_config(self):
self.addToConfig("simulation.context.setPositions(prm.positions)")
self.addToConfig("if prm.box_vectors is not None:")
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*prm.box_vectors)"
" box_vectors = reducePeriodicBoxVectors(prm.box_vectors)"
)
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*box_vectors)"
)

# Set initial velocities from temperature distribution.
Expand Down Expand Up @@ -633,7 +639,10 @@ def _generate_config(self):
self.addToConfig("simulation.context.setPositions(prm.positions)")
self.addToConfig("if prm.box_vectors is not None:")
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*prm.box_vectors)"
" box_vectors = reducePeriodicBoxVectors(prm.box_vectors)"
)
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*box_vectors)"
)

# Set initial velocities from temperature distribution.
Expand Down Expand Up @@ -1006,7 +1015,10 @@ def _generate_config(self):
self.addToConfig("simulation.context.setPositions(prm.positions)")
self.addToConfig("if prm.box_vectors is not None:")
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*prm.box_vectors)"
" box_vectors = reducePeriodicBoxVectors(prm.box_vectors)"
)
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*box_vectors)"
)

# Set initial velocities from temperature distribution.
Expand Down Expand Up @@ -1922,6 +1934,9 @@ def _add_config_imports(self):
self.addToConfig("from openmm import *")
self.addToConfig("from openmm.app import *")
self.addToConfig("from openmm.unit import *")
self.addToConfig(
"from openmm.app.internal.unitcell import reducePeriodicBoxVectors"
)
self.addToConfig("import parmed")

def _add_config_platform(self):
Expand Down
2 changes: 1 addition & 1 deletion python/BioSimSpace/Sandpit/Exscientia/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@
_alchemlyb = _try_import("alchemlyb")

if _have_imported(_alchemlyb):
from alchemlyb.parsing.amber import extract as _extract
from alchemlyb.parsing.gmx import extract as _extract

from .. import _gmx_exe
from .. import _isVerbose
Expand Down
23 changes: 19 additions & 4 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,10 @@ def _generate_config(self):
self.addToConfig("simulation.context.setPositions(prm.positions)")
self.addToConfig("if prm.box_vectors is not None:")
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*prm.box_vectors)"
" box_vectors = reducePeriodicBoxVectors(prm.box_vectors)"
)
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*box_vectors)"
)
self.addToConfig(
f"simulation.minimizeEnergy(maxIterations={self._protocol.getSteps()})"
Expand Down Expand Up @@ -448,7 +451,10 @@ def _generate_config(self):
self.addToConfig("simulation.context.setPositions(prm.positions)")
self.addToConfig("if prm.box_vectors is not None:")
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*prm.box_vectors)"
" box_vectors = reducePeriodicBoxVectors(prm.box_vectors)"
)
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*box_vectors)"
)

# Set initial velocities from temperature distribution.
Expand Down Expand Up @@ -624,7 +630,10 @@ def _generate_config(self):
self.addToConfig("simulation.context.setPositions(prm.positions)")
self.addToConfig("if prm.box_vectors is not None:")
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*prm.box_vectors)"
" box_vectors = reducePeriodicBoxVectors(prm.box_vectors)"
)
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*box_vectors)"
)

# Set initial velocities from temperature distribution.
Expand Down Expand Up @@ -1006,7 +1015,10 @@ def _generate_config(self):
self.addToConfig("simulation.context.setPositions(prm.positions)")
self.addToConfig("if prm.box_vectors is not None:")
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*prm.box_vectors)"
" box_vectors = reducePeriodicBoxVectors(prm.box_vectors)"
)
self.addToConfig(
" simulation.context.setPeriodicBoxVectors(*box_vectors)"
)

# Set initial velocities from temperature distribution.
Expand Down Expand Up @@ -1922,6 +1934,9 @@ def _add_config_imports(self):
self.addToConfig("from openmm import *")
self.addToConfig("from openmm.app import *")
self.addToConfig("from openmm.unit import *")
self.addToConfig(
"from openmm.app.internal.unitcell import reducePeriodicBoxVectors"
)
self.addToConfig("import parmed")

def _add_config_platform(self):
Expand Down
15 changes: 15 additions & 0 deletions tests/Process/test_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,21 @@ def test_rhombic_dodecahedron():
run_process(solvated, protocol)


def test_parmed_triclinic():
"""Test the workaround for fixing ParmEd triclinic lattice reduction."""

# Load the test system.
system = BSS.IO.readMolecules(
BSS.IO.expand(url, ["parmed_issue.rst7", "parmed_issue.prm7"])
)

# Create a short minimisation protocol.
protocol = BSS.Protocol.Minimisation(steps=100)

# Run the process, check that it finished without error, and returns a system.
run_process(system, protocol)


def run_process(system, protocol):
"""Helper function to run various simulation protocols."""

Expand Down
17 changes: 16 additions & 1 deletion tests/Sandpit/Exscientia/Process/test_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ def test_production(system, restraint):
)

# Run the process, check that it finished without error, and returns a system.
run_process(system, protocol, restraint=restraint, tolerance=1)
run_process(system, protocol, restraint=restraint, tolerance=1.1)


@pytest.mark.skipif(
Expand All @@ -151,6 +151,21 @@ def test_rhombic_dodecahedron():
run_process(solvated, protocol)


def test_parmed_triclinic():
"""Test the workaround for fixing ParmEd triclinic lattice reduction."""

# Load the test system.
system = BSS.IO.readMolecules(
BSS.IO.expand(url, ["parmed_issue.rst7", "parmed_issue.prm7"])
)

# Create a short minimisation protocol.
protocol = BSS.Protocol.Minimisation(steps=100)

# Run the process, check that it finished without error, and returns a system.
run_process(system, protocol)


def run_process(system, protocol, restraint="none", tolerance=0.05):
"""Helper function to run various simulation protocols.
Expand Down

0 comments on commit 60e0884

Please sign in to comment.