Skip to content

Commit

Permalink
Backport fix from PR #173. [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Sep 22, 2023
1 parent 5e26d8e commit 8f088a2
Show file tree
Hide file tree
Showing 14 changed files with 173 additions and 36 deletions.
7 changes: 4 additions & 3 deletions python/BioSimSpace/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -440,9 +440,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2533,9 +2533,10 @@ def _getFrame(self, time):
and space_prop in new_system._sire_object.propertyKeys()
):
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

# If this is a vacuum simulation, then translate the centre of mass
# of the system back to the origin.
Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Process/_namd.py
Original file line number Diff line number Diff line change
Expand Up @@ -789,9 +789,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Process/_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
10 changes: 8 additions & 2 deletions python/BioSimSpace/Process/_somd.py
Original file line number Diff line number Diff line change
Expand Up @@ -538,6 +538,13 @@ def getSystem(self, block="AUTO"):

new_system = _IO.readMolecules(self._restart_file)

# Try loading the trajectory file to get the box information.
try:
frame = self.getTrajectory().getFrames(-1)
box = frame._sire_object.property("space")
except:
box = None

# Since SOMD requires specific residue and water naming we copy the
# coordinates back into the original system.
old_system = self._system.copy()
Expand All @@ -562,8 +569,7 @@ def getSystem(self, block="AUTO"):
self._mapping = mapping

# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
if box and box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -687,9 +687,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2579,9 +2579,10 @@ def _getFrame(self, time):
and space_prop in new_system._sire_object.propertyKeys()
):
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

# If this is a vacuum simulation, then translate the centre of mass
# of the system back to the origin.
Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_namd.py
Original file line number Diff line number Diff line change
Expand Up @@ -787,9 +787,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
7 changes: 4 additions & 3 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1316,9 +1316,10 @@ def getSystem(self, block="AUTO"):
# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
if box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)

return old_system

Expand Down
10 changes: 8 additions & 2 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_somd.py
Original file line number Diff line number Diff line change
Expand Up @@ -553,6 +553,13 @@ def getSystem(self, block="AUTO"):

new_system = _IO.readMolecules(self._restart_file)

# Try loading the trajectory file to get the box information.
try:
frame = self.getTrajectory().getFrames(-1)
box = frame._sire_object.property("space")
except:
box = None

# Since SOMD requires specific residue and water naming we copy the
# coordinates back into the original system.
old_system = self._system.copy()
Expand All @@ -577,8 +584,7 @@ def getSystem(self, block="AUTO"):
self._mapping = mapping

# Update the box information in the original system.
if "space" in new_system._sire_object.propertyKeys():
box = new_system._sire_object.property("space")
if box and box.isPeriodic():
old_system._sire_object.setProperty(
self._property_map.get("space", "space"), box
)
Expand Down
56 changes: 54 additions & 2 deletions python/BioSimSpace/Sandpit/Exscientia/Trajectory/_trajectory.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@
from sire.legacy import Base as _SireBase
from sire.legacy import IO as _SireIO
from sire.legacy import Mol as _SireMol
from sire.legacy import Units as _SireUnits
from sire.legacy import Vol as _SireVol

from sire import load as _sire_load
from sire._load import _resolve_path
Expand Down Expand Up @@ -202,15 +204,25 @@ def getFrame(trajectory, topology, index, system=None, property_map={}):
if system is not None:
if is_sire and frame.current().num_molecules() > 1:
try:
new_system = frame.current()._system

sire_system, _ = _SireIO.updateCoordinatesAndVelocities(
system._sire_object,
frame.current()._system,
new_system,
mapping,
False,
property_map,
{},
)

# Update the box information in the original system.
if "space" in new_system.propertyKeys():
box = new_system.property("space")
if box.isPeriodic():
sire_system.setProperty(
self._property_map.get("space", "space"), box
)

new_system = _System(sire_system)

except Exception as e:
Expand Down Expand Up @@ -260,6 +272,14 @@ def getFrame(trajectory, topology, index, system=None, property_map={}):
system._sire_object, new_system, mapping, False, property_map, {}
)

# Update the box information in the original system.
if "space" in new_system.propertyKeys():
box = new_system.property("space")
if box.isPeriodic():
sire_system.setProperty(
self._property_map.get("space", "space"), box
)

new_system = _System(sire_system)
except Exception as e:
msg = "Failed to copy trajectory coordinates/velocities into BioSimSpace system!"
Expand Down Expand Up @@ -756,15 +776,25 @@ def getFrames(self, indices=None):
if self._system is not None:
if self._backend == "SIRE" and frame.current().num_molecules() > 1:
try:
new_system = frame.current()._system

sire_system, _ = _SireIO.updateCoordinatesAndVelocities(
self._system._sire_object,
frame.current()._system,
new_system,
self._mapping,
False,
self._property_map,
{},
)

# Update the box information in the original system.
if "space" in new_system.propertyKeys():
box = new_system.property("space")
if box.isPeriodic():
sire_system.setProperty(
self._property_map.get("space", "space"), box
)

new_system = _System(sire_system)
except Exception as e:
msg = "Failed to copy trajectory coordinates/velocities into BioSimSpace system!"
Expand Down Expand Up @@ -822,6 +852,14 @@ def getFrames(self, indices=None):
{},
)

# Update the box information in the original system.
if "space" in new_system.propertyKeys():
box = new_system.property("space")
if box.isPeriodic():
sire_system.setProperty(
self._property_map.get("space", "space"), box
)

new_system = _System(sire_system)
except Exception as e:
msg = "Failed to copy trajectory coordinates/velocities into BioSimSpace system!"
Expand Down Expand Up @@ -1059,6 +1097,17 @@ def _split_molecules(frame, pdb, reference, work_dir, property_map={}):
# Whether we've parsed as a PDB file.
is_pdb = False

# Create a triclinic space from the information in the frame file.
if isinstance(frame, _SireIO.AmberRst7):
# Get the box dimensions and angles. Take the values, since the
# units are wrong.
degree = _SireUnits.degree
dimensions = [x.value() for x in frame.box_dimensions()]
angles = [x.value() * degree for x in frame.box_angles()]
box = _SireVol.TriclinicBox(*dimensions, *angles)
else:
box = _SireVol.TriclinicBox(frame.box_v1(), frame.box_v2(), frame.box_v3())

if "PRM7" in formats:
try:
top = _SireIO.AmberPrm(reference._sire_object)
Expand Down Expand Up @@ -1133,6 +1182,9 @@ def _split_molecules(frame, pdb, reference, work_dir, property_map={}):
else:
raise IOError(msg) from None

# Add the space property.
split_system.setProperty(property_map.get("space", "space"), box)

return split_system


Expand Down
Loading

0 comments on commit 8f088a2

Please sign in to comment.