Skip to content

Commit

Permalink
Merge pull request #173 from OpenBioSim/fix_172
Browse files Browse the repository at this point in the history
Fix issue #172
  • Loading branch information
lohedges authored Sep 20, 2023
2 parents 65045f0 + a2619d8 commit e3014dc
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 @@ -442,9 +442,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 @@ -2537,9 +2537,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 @@ -1318,9 +1318,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 @@ -540,6 +540,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 @@ -564,8 +571,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 @@ -693,9 +693,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 @@ -2597,9 +2597,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 @@ -1322,9 +1322,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 @@ -559,6 +559,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 @@ -583,8 +590,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 @@ -41,6 +41,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 @@ -203,15 +205,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 @@ -261,6 +273,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 @@ -762,15 +782,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 @@ -828,6 +858,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 @@ -1080,6 +1118,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 @@ -1154,6 +1203,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 e3014dc

Please sign in to comment.