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
Original file line number Diff line number Diff line change
Expand Up @@ -1472,9 +1472,7 @@ def translate(self, vector, property_map={}):
if self._sire_object.has_property(coord_prop):
_property_map["coordinates"] = coord_prop
mol = (
self._sire_object.move()
.translate(_SireMaths.Vector(vec), _property_map)
.commit()
mol.move().translate(_SireMaths.Vector(vec), _property_map).commit()
)

else:
Expand Down
4 changes: 1 addition & 3 deletions src/BioSimSpace/_SireWrappers/_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -1412,9 +1412,7 @@ def translate(self, vector, property_map={}):
if self._sire_object.has_property(coord_prop):
_property_map["coordinates"] = coord_prop
mol = (
self._sire_object.move()
.translate(_SireMaths.Vector(vec), _property_map)
.commit()
mol.move().translate(_SireMaths.Vector(vec), _property_map).commit()
)

else:
Expand Down
51 changes: 51 additions & 0 deletions tests/Sandpit/Exscientia/_SireWrappers/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,54 @@ def test_makeCompatibleWith_regression():

# Make sure the energies are approximately equal.
assert nrg_compatible == pytest.approx(nrg_leap, rel=1e-5)


def test_translate_custom_coordinates_property(perturbable_system):
"""
Regresson test to ensure that a molecule with a custom
coordinates property gets translated correctly.
"""

from sire.maths import Vector

# Extract a copy of the perturbable molecule.
mol = perturbable_system.getPerturbableMolecules()[0].copy()

# Copy the "coordinates0" property to a custom property installed
# "test"
cursor = mol._sire_object.cursor()
cursor["test"] = cursor["coordinates0"]
mol._sire_object = cursor.commit()

# Store the existing coordinates.
coords0 = mol._sire_object.property("coordinates0").to_vector()
coords1 = mol._sire_object.property("coordinates1").to_vector()
coords_test = mol._sire_object.property("test").to_vector()

# Translate the molecule.
mol.translate(3 * [BSS.Units.Length.angstrom], property_map={"coordinates": "test"})

# Get the new coordinates.
new_coords0 = mol._sire_object.property("coordinates0").to_vector()
new_coords1 = mol._sire_object.property("coordinates1").to_vector()
new_coords_test = mol._sire_object.property("test").to_vector()

# Create a vector of the displacement.
v_ref = Vector(1.0, 1.0, 1.0)

# Check that the coordinates have been translated correctly.
for c_new, c_old in zip(new_coords0, coords0):
v = c_new - c_old
assert pytest.approx(v.x().value(), abs=1e-5) == v_ref.x().value()
assert pytest.approx(v.y().value(), abs=1e-5) == v_ref.y().value()
assert pytest.approx(v.z().value(), abs=1e-5) == v_ref.z().value()
for c_new, c_old in zip(new_coords1, coords1):
v = c_new - c_old
assert pytest.approx(v.x().value(), abs=1e-5) == v_ref.x().value()
assert pytest.approx(v.y().value(), abs=1e-5) == v_ref.y().value()
assert pytest.approx(v.z().value(), abs=1e-5) == v_ref.z().value()
for c_new, c_old in zip(new_coords_test, coords_test):
v = c_new - c_old
assert pytest.approx(v.x().value(), abs=1e-5) == v_ref.x().value()
assert pytest.approx(v.y().value(), abs=1e-5) == v_ref.y().value()
assert pytest.approx(v.z().value(), abs=1e-5) == v_ref.z().value()
11 changes: 11 additions & 0 deletions tests/Sandpit/Exscientia/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,14 @@ def merged_benzene_pyrrole(benzene, pyrrole, mapping_benzene_pyrrole):
allow_ring_breaking=True,
allow_ring_size_change=True,
)


@pytest.fixture(scope="module")
def perturbable_system():
"""A vacuum perturbable system."""
return BSS.IO.readPerturbableSystem(
f"{url}/perturbable_system0.prm7",
f"{url}/perturbable_system0.rst7",
f"{url}/perturbable_system1.prm7",
f"{url}/perturbable_system1.rst7",
)
51 changes: 51 additions & 0 deletions tests/_SireWrappers/test_molecule.py
Original file line number Diff line number Diff line change
Expand Up @@ -145,3 +145,54 @@ def test_makeCompatibleWith_regression():

# Make sure the energies are approximately equal.
assert nrg_compatible == pytest.approx(nrg_leap, rel=1e-5)


def test_translate_custom_coordinates_property(perturbable_system):
"""
Regresson test to ensure that a molecule with a custom
coordinates property gets translated correctly.
"""

from sire.maths import Vector

# Extract a copy of the perturbable molecule.
mol = perturbable_system.getPerturbableMolecules()[0].copy()

# Copy the "coordinates0" property to a custom property installed
# "test"
cursor = mol._sire_object.cursor()
cursor["test"] = cursor["coordinates0"]
mol._sire_object = cursor.commit()

# Store the existing coordinates.
coords0 = mol._sire_object.property("coordinates0").to_vector()
coords1 = mol._sire_object.property("coordinates1").to_vector()
coords_test = mol._sire_object.property("test").to_vector()

# Translate the molecule.
mol.translate(3 * [BSS.Units.Length.angstrom], property_map={"coordinates": "test"})

# Get the new coordinates.
new_coords0 = mol._sire_object.property("coordinates0").to_vector()
new_coords1 = mol._sire_object.property("coordinates1").to_vector()
new_coords_test = mol._sire_object.property("test").to_vector()

# Create a vector of the displacement.
v_ref = Vector(1.0, 1.0, 1.0)

# Check that the coordinates have been translated correctly.
for c_new, c_old in zip(new_coords0, coords0):
v = c_new - c_old
assert pytest.approx(v.x().value(), abs=1e-5) == v_ref.x().value()
assert pytest.approx(v.y().value(), abs=1e-5) == v_ref.y().value()
assert pytest.approx(v.z().value(), abs=1e-5) == v_ref.z().value()
for c_new, c_old in zip(new_coords1, coords1):
v = c_new - c_old
assert pytest.approx(v.x().value(), abs=1e-5) == v_ref.x().value()
assert pytest.approx(v.y().value(), abs=1e-5) == v_ref.y().value()
assert pytest.approx(v.z().value(), abs=1e-5) == v_ref.z().value()
for c_new, c_old in zip(new_coords_test, coords_test):
v = c_new - c_old
assert pytest.approx(v.x().value(), abs=1e-5) == v_ref.x().value()
assert pytest.approx(v.y().value(), abs=1e-5) == v_ref.y().value()
assert pytest.approx(v.z().value(), abs=1e-5) == v_ref.z().value()