Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions tests/convert/test_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -306,6 +306,25 @@ def test_openmm_options(ala_mols, openmm_platform):
pass


@pytest.mark.skipif(
"openmm" not in sr.convert.supported_formats(),
reason="openmm support is not available",
)
def test_openmm_platform_defaults_unchanged(ala_mols):
import openmm

mol = ala_mols[0]

platform = openmm.Platform.getPlatformByName("CPU")
default = platform.getPropertyDefaultValue("Threads")
threads = "1" if default != "1" else "2"

omm = sr.convert.to(mol, "openmm", map={"platform": "CPU", "threads": threads})

assert omm.getPlatform().getPropertyValue(omm, "Threads") == threads
assert platform.getPropertyDefaultValue("Threads") == default


@pytest.mark.skipif(
"openmm" not in sr.convert.supported_formats(),
reason="openmm support is not available",
Expand Down
3 changes: 2 additions & 1 deletion wrapper/Convert/SireOpenMM/_sommcontext.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ def __init__(
platform=None,
metadata=None,
map=None,
properties=None,
):
"""
Construct from a passed OpenMM Context, the
Expand Down Expand Up @@ -64,7 +65,7 @@ def __init__(
# more than worth it. Note that this is why minimisations
# start running more quickly than dynamics jobs. There
# are no constraints in minimisations
super().__init__(system, integrator, platform)
super().__init__(system, integrator, platform, properties or {})

# place the coordinates and velocities into the context
set_openmm_coordinates_and_velocities(self, metadata)
Expand Down
17 changes: 10 additions & 7 deletions wrapper/Convert/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -448,29 +448,33 @@ def sire_to_openmm(mols, map):

supported_properties = platform.getPropertyNames()

# Passed to the context, since the platform's defaults are shared between
# threads.
properties = {}

if "Precision" in supported_properties and map.specified("precision"):
precision = map.get_string("precision")
platform.setPropertyDefaultValue("Precision", precision)
properties["Precision"] = precision

if "Threads" in supported_properties and map.specified("threads"):
try:
threads = map["threads"].value().as_integer()
except Exception:
threads = map["threads"].source()

platform.setPropertyDefaultValue("Threads", str(threads))
properties["Threads"] = str(threads)

if "DeviceIndex" in supported_properties and map.specified("device"):
try:
device_index = map["device"].value().as_integer()
except Exception:
device_index = map["device"].source()

platform.setPropertyDefaultValue("DeviceIndex", str(device_index))
properties["DeviceIndex"] = str(device_index)

if map.specified("cpu_pme") and "UseCpuPme" in supported_properties:
usecpu = int(map["cpu_pme"].value().as_boolean())
platform.setPropertyDefaultValue("UseCpuPme", str(usecpu).lower())
properties["UseCpuPme"] = str(usecpu).lower()

if "OpenCLPlatformIndex" in supported_properties and map.specified(
"opencl_platform_index"
Expand All @@ -482,9 +486,7 @@ def sire_to_openmm(mols, map):
except Exception:
opencl_platform_index = map["opencl_platform_index"].source()

platform.setPropertyDefaultValue(
"OpenCLPlatformIndex", str(opencl_platform_index)
)
properties["OpenCLPlatformIndex"] = str(opencl_platform_index)

try:
from ._sommcontext import SOMMContext
Expand All @@ -493,6 +495,7 @@ def sire_to_openmm(mols, map):
system=system,
integrator=integrator,
platform=platform,
properties=properties,
metadata=openmm_metadata,
map=map,
)
Expand Down