Skip to content

Commit

Permalink
Have amber process write binary RST file instead of text rst7 file (#22)
Browse files Browse the repository at this point in the history
Co-authored-by: William (Zhiyi) Wu <zwu@exscientia.co.uk>
  • Loading branch information
xiki-tempula and xiki-tempula committed Sep 18, 2023
1 parent f1f5276 commit 55bb6fc
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
13 changes: 9 additions & 4 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
__all__ = ["Amber"]

import os
import shutil
from pathlib import Path as _Path

from .._Utils import _try_import
Expand Down Expand Up @@ -303,9 +304,11 @@ def _write_system(self, system, coord_file=None, topol_file=None, ref_file=None)
if coord_file is not None:
try:
file = _os.path.splitext(coord_file)[0]
_IO.saveMolecules(file, system, "rst7", property_map=self._property_map)
_IO.saveMolecules(file, system, "rst", property_map=self._property_map)
# To keep the file extension the same.
shutil.move(f"{file}.rst", f"{file}.rst7")
except Exception as e:
msg = "Failed to write system to 'RST7' format."
msg = "Failed to write system to 'rst7' format."
if _isVerbose():
raise IOError(msg) from e
else:
Expand All @@ -315,9 +318,11 @@ def _write_system(self, system, coord_file=None, topol_file=None, ref_file=None)
if ref_file is not None:
try:
file = _os.path.splitext(ref_file)[0]
_IO.saveMolecules(file, system, "rst7", property_map=self._property_map)
_IO.saveMolecules(file, system, "rst", property_map=self._property_map)
# To keep the file extension the same.
shutil.move(f"{file}.rst", f"{file}.rst7")
except Exception as e:
msg = "Failed to write system to 'RST7' format."
msg = "Failed to write system to 'rst7' format."
if _isVerbose():
raise IOError(msg) from e
else:
Expand Down
16 changes: 8 additions & 8 deletions tests/Sandpit/Exscientia/Process/test_position_restraint.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@

import pandas as pd
import pytest
from sire.legacy.IO import AmberRst

import BioSimSpace.Sandpit.Exscientia as BSS
from BioSimSpace.Sandpit.Exscientia.Units.Energy import kj_per_mol
Expand Down Expand Up @@ -121,8 +122,8 @@ def test_gromacs(protocol, system, ref_system, tmp_path):


@pytest.mark.skipif(
has_gromacs is False or has_openff is False,
reason="Requires AMBER and openff to be installed",
has_openff is False,
reason="Requires openff to be installed",
)
def test_amber(protocol, system, ref_system, tmp_path):
proc = BSS.Process.Amber(
Expand All @@ -137,12 +138,11 @@ def test_amber(protocol, system, ref_system, tmp_path):

# We have generated a separate restraint reference
assert os.path.exists(proc._ref_file)
contents_ref, contents_rst = (
open(proc._ref_file).readlines(),
open(proc._rst_file).readlines(),
)
diff = list(unified_diff(contents_ref, contents_rst))
assert len(diff)

ref = AmberRst(proc._ref_file).getFrame(0)
rst = AmberRst(proc._rst_file).getFrame(0)

assert ref != rst

# We are pointing the reference to the correct file
assert f"{proc._work_dir}/{proc.getArgs()['-ref']}" == proc._ref_file

0 comments on commit 55bb6fc

Please sign in to comment.