Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add method to remove the space property from a system #338

Merged
merged 1 commit into from
Sep 25, 2024
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
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()
Loading