Skip to content

Commit

Permalink
Merge pull request #338 from OpenBioSim/feature_remove_space
Browse files Browse the repository at this point in the history
Add method to remove the space property from a system. [ci skip]
  • Loading branch information
lohedges authored Sep 25, 2024
2 parents dc6602e + 74bf757 commit 9775d91
Show file tree
Hide file tree
Showing 4 changed files with 84 additions and 0 deletions.
28 changes: 28 additions & 0 deletions python/BioSimSpace/Sandpit/Exscientia/_SireWrappers/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1670,6 +1670,9 @@ def setBox(self, box, angles=3 * [_Angle(90, "degree")], property_map={}):
if len(box) != 3:
raise ValueError("'angles' must contain three items.")

if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'.")

# Convert sizes to Anstrom.
vec = [x.angstroms().value() for x in box]

Expand Down Expand Up @@ -1720,6 +1723,9 @@ def getBox(self, property_map={}):
The box vector angles: yz, xz, and xy.
"""

if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'.")

# Get the "space" property and convert to a list of BioSimSpace.Type.Length
# objects.
try:
Expand Down Expand Up @@ -1751,6 +1757,28 @@ def getBox(self, property_map={}):

return box, angles

def removeBox(self, property_map={}):
"""
Remove the simulation box from the system.
Parameters
----------
property_map : dict
A dictionary that maps system "properties" to their user defined
values. This allows the user to refer to properties with their
own naming scheme, e.g. { "charge" : "my-charge" }
"""

if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'")

# Remove the "space" property.
try:
self._sire_object.removeProperty(property_map.get("space", "space"))
except:
pass

def makeWhole(self, property_map={}):
"""
Make all molecules in the system "whole", i.e. unwrap any molecules that have
Expand Down
28 changes: 28 additions & 0 deletions python/BioSimSpace/_SireWrappers/_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -1587,6 +1587,9 @@ def setBox(self, box, angles=3 * [_Angle(90, "degree")], property_map={}):
if len(box) != 3:
raise ValueError("'angles' must contain three items.")

if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'")

# Convert sizes to Anstrom.
vec = [x.angstroms().value() for x in box]

Expand Down Expand Up @@ -1637,6 +1640,9 @@ def getBox(self, property_map={}):
The box vector angles: yz, xz, and xy.
"""

if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'")

# Get the "space" property and convert to a list of BioSimSpace.Type.Length
# objects.
try:
Expand Down Expand Up @@ -1668,6 +1674,28 @@ def getBox(self, property_map={}):

return box, angles

def removeBox(self, property_map={}):
"""
Remove the simulation box from the system.
Parameters
----------
property_map : dict
A dictionary that maps system "properties" to their user defined
values. This allows the user to refer to properties with their
own naming scheme, e.g. { "charge" : "my-charge" }
"""

if not isinstance(property_map, dict):
raise TypeError("'property_map' must be of type 'dict'")

# Remove the "space" property.
try:
self._sire_object.removeProperty(property_map.get("space", "space"))
except:
pass

def makeWhole(self, property_map={}):
"""
Make all molecules in the system "whole", i.e. unwrap any molecules that have
Expand Down
14 changes: 14 additions & 0 deletions tests/Sandpit/Exscientia/_SireWrappers/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -494,3 +494,17 @@ def test_set_water_property_preserve(system):

# Make sure the property is preserved.
assert system[-1]._sire_object.hasProperty("test")


def test_remove_box(system):
# Make a copy of the system.
system = system.copy()

# Make sure the box is present.
assert "space" in system._sire_object.propertyKeys()

# Remove the box.
system.removeBox()

# Make sure the box is removed.
assert not "space" in system._sire_object.propertyKeys()
14 changes: 14 additions & 0 deletions tests/_SireWrappers/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -484,3 +484,17 @@ def test_set_water_property_preserve(system):

# Make sure the property is preserved.
assert system[-1]._sire_object.hasProperty("test")


def test_remove_box(system):
# Make a copy of the system.
system = system.copy()

# Make sure the box is present.
assert "space" in system._sire_object.propertyKeys()

# Remove the box.
system.removeBox()

# Make sure the box is removed.
assert not "space" in system._sire_object.propertyKeys()

0 comments on commit 9775d91

Please sign in to comment.