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
1 change: 0 additions & 1 deletion pixi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ parmed = "*"
pyarrow = "*"
py3dmol = "*"
pydot = "*"
pygtail = "*"
pyyaml = "*"
rdkit = "*"

Expand Down
1 change: 0 additions & 1 deletion recipes/biosimspace/recipe.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ requirements:
- pyarrow
- py3dmol
- pydot
- pygtail
- python
- pyyaml
- rdkit
Expand Down
7 changes: 1 addition & 6 deletions src/BioSimSpace/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@

__all__ = ["Amber"]

from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from . import _process


Expand Down Expand Up @@ -2712,7 +2707,7 @@ def stdout(self, n=10):
self._is_header = False

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())
line = line.strip()

Expand Down
7 changes: 1 addition & 6 deletions src/BioSimSpace/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@

__all__ = ["Gromacs"]

from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from . import _process


Expand Down Expand Up @@ -2104,7 +2099,7 @@ def stdout(self, n=10):
raise ValueError("The number of lines must be positive!")

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())

# Get the current number of lines.
Expand Down
7 changes: 1 addition & 6 deletions src/BioSimSpace/Process/_namd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@

__all__ = ["Namd"]

from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from . import _process


Expand Down Expand Up @@ -2127,7 +2122,7 @@ def stdout(self, n=10):
raise ValueError("The number of lines must be positive!")

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())

# Split the record using whitespace.
Expand Down
9 changes: 2 additions & 7 deletions src/BioSimSpace/Process/_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@

__all__ = ["OpenMM"]

from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from . import _process


Expand Down Expand Up @@ -1988,7 +1983,7 @@ def stdout(self, n=10):
raise ValueError("The number of lines must be positive!")

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())

# Get the current number of lines.
Expand Down Expand Up @@ -2295,7 +2290,7 @@ def _update_stdout_dict(self):
lines = []

# Append any new lines.
for line in _pygtail.Pygtail(self._log_file):
for line in self._tail(self._log_file):
lines.append(line)

# Append any new records to the stdout dictionary.
Expand Down
33 changes: 11 additions & 22 deletions src/BioSimSpace/Process/_plumed.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,12 +26,8 @@

__all__ = ["Plumed"]

from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from .. import Types as _Types
from .._Utils import Tail as _Tail


class Plumed:
Expand Down Expand Up @@ -104,6 +100,8 @@ def __init__(self, work_dir):
# Set the location of the HILLS and COLVAR files.
self._hills_file = _os.path.join(str(self._work_dir), "HILLS")
self._colvar_file = _os.path.join(str(self._work_dir), "COLVAR")
self._hills_tail = _Tail(self._hills_file)
self._colvar_tail = _Tail(self._colvar_file)

# The number of collective variables and total number of components.
self._num_colvar = 0
Expand Down Expand Up @@ -247,15 +245,9 @@ def _createMetadynamicsConfig(self, system, protocol, property_map={}):
self._config = []
self._aux_files = []

# Always remove pygtail offset files.
try:
_os.remove(_os.path.join(str(self._work_dir), "COLVAR.offset"))
except:
pass
try:
_os.remove(_os.path.join(str(self._work_dir), "HILLS.offset"))
except:
pass
# Reset the incremental file readers.
self._colvar_tail = _Tail(self._colvar_file)
self._hills_tail = _Tail(self._hills_file)

# Restart if existing HILLS and COLVAR files are present.
if _os.path.isfile(self._colvar_file) and _os.path.isfile(self._hills_file):
Expand Down Expand Up @@ -959,11 +951,8 @@ def _createSteeringConfig(self, system, protocol, property_map={}):
self._config = []
self._aux_files = []

# Always remove pygtail offset files.
try:
_os.remove(_os.path.join(str(self._work_dir), "COLVAR.offset"))
except:
pass
# Reset the incremental file reader.
self._colvar_tail = _Tail(self._colvar_file)

# Restart if an existing COLVAR files is present.
if _os.path.isfile(self._colvar_file):
Expand Down Expand Up @@ -1610,7 +1599,7 @@ def _update_colvar_dict(self):
# Parse the HILLS file for OpenMM.
if self._use_hills:
# Loop over all new lines in the file.
for line in _pygtail.Pygtail(self._hills_file):
for line in self._hills_tail:
# Is this a header line. If so, store the keys.
if line[3:9] == "FIELDS":
self._colvar_keys = line[10:].split()[: self._num_components + 1]
Expand All @@ -1623,7 +1612,7 @@ def _update_colvar_dict(self):

else:
# Loop over all new lines in the file.
for line in _pygtail.Pygtail(self._colvar_file):
for line in self._colvar_tail:
# Is this a header line. If so, store the keys.
if line[3:9] == "FIELDS":
self._colvar_keys = line[10:].split()
Expand All @@ -1643,7 +1632,7 @@ def _update_hills_dict(self):
return

# Loop over all new lines in the file.
for line in _pygtail.Pygtail(self._hills_file):
for line in self._hills_tail:
# Is this a header line. If so, store the keys.
if line[3:9] == "FIELDS":
self._hills_keys = line[10:].split()
Expand Down
50 changes: 27 additions & 23 deletions src/BioSimSpace/Process/_process.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
__all__ = ["Process"]


from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from .. import Units as _Units
from .. import _is_notebook

Expand Down Expand Up @@ -332,9 +327,6 @@ def __repr__(self):

def _clear_output(self):
"""Reset stdout and stderr."""
import glob as _glob
import os as _os

# Create the files. This makes sure that the 'stdout' and 'stderr'
# methods can be called when the files are empty.
open(self._stdout_file, "a").close()
Expand All @@ -344,19 +336,31 @@ def _clear_output(self):
self._stdout = []
self._stderr = []

# Clean up any existing offset files.
offset_files = _glob.glob(_os.path.join(str(self._work_dir), "*.offset"))
# Reset the incremental file readers.
self._tails = {}

# Remove any HILLS or COLVAR files from the list. These will be dealt
# with by the PLUMED interface.
try:
offset_files.remove(_os.path.join(str(self._work_dir), "COLVAR.offset"))
offset_files.remove(_os.path.join(str(self._work_dir), "HILLS.offset"))
except:
pass
def _tail(self, filename):
"""
Return the lines appended to a file since it was last read.

Parameters
----------

filename : str
The path to the file.

Returns
-------

lines : iterable
An iterable over the new lines.
"""
from .._Utils import Tail as _Tail

if filename not in self._tails:
self._tails[filename] = _Tail(filename)

for file in offset_files:
_os.remove(file)
return self._tails[filename]

def _getPlumedConfig(self):
"""
Expand Down Expand Up @@ -1018,7 +1022,7 @@ def stdout(self, n=10):
raise ValueError("The number of lines must be positive!")

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())

# Get the current number of lines.
Expand Down Expand Up @@ -1050,7 +1054,7 @@ def stderr(self, n=10):
raise ValueError("The number of lines must be positive!")

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stderr_file):
for line in self._tail(self._stderr_file):
self._stderr.append(line.rstrip())

# Get the current number of lines.
Expand Down Expand Up @@ -1126,7 +1130,7 @@ def getStdout(self, block="AUTO"):
self.wait()

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())

return self._stdout.copy()
Expand Down Expand Up @@ -1155,7 +1159,7 @@ def getStderr(self, block="AUTO"):
self.wait()

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stderr_file):
for line in self._tail(self._stderr_file):
self._stderr.append(line.rstrip())

return self._stderr.copy()
Expand Down
6 changes: 1 addition & 5 deletions src/BioSimSpace/Process/_somd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,6 @@

__all__ = ["Somd"]

from .._Utils import _try_import

_pygtail = _try_import("pygtail")

import string as _string

from . import _process
Expand Down Expand Up @@ -876,7 +872,7 @@ def getGradient(self, time_series=False, block="AUTO"):
return None

# Append any new lines to the gradients list.
for line in _pygtail.Pygtail(self._gradient_file):
for line in self._tail(self._gradient_file):
# Ignore comments.
if line[0] != "#":
self._gradients.append(float(line.rstrip().split()[-1]))
Expand Down
16 changes: 4 additions & 12 deletions src/BioSimSpace/Sandpit/Exscientia/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
__all__ = ["Amber"]


from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from .._Utils import _have_imported, _try_import

# alchemlyb isn't available on all variants of Python that we support, so we
Expand Down Expand Up @@ -2795,7 +2790,7 @@ def stdout(self, n=10):
self._is_header = False

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())
line = line.strip()

Expand Down Expand Up @@ -3053,9 +3048,6 @@ def _init_stdout_dict(self):
into the working directory, start and wait again. In this case, the result will
be a combination of both runs. This function ensures that the results are
regenerated from the new output file."""
import os
from pathlib import Path as _Path

# Initialise dictionaries to hold stdout records for all possible
# degrees of freedom. For regular simulations there will be one,
# for free-energy simulations there will be three, i.e. one for
Expand All @@ -3080,9 +3072,9 @@ def _init_stdout_dict(self):
self._finished_results = False
self._is_header = False

# Initiate the pytails.
for file in _Path(self.workDir()).glob("*.out.offset"):
os.remove(file)
# Reset the incremental readers for the output files.
for file in [f for f in self._tails if f.endswith(".out")]:
del self._tails[file]

def _saveMetric(
self, filename="metric.parquet", u_nk="u_nk.parquet", dHdl="dHdl.parquet"
Expand Down
7 changes: 1 addition & 6 deletions src/BioSimSpace/Sandpit/Exscientia/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,6 @@
__all__ = ["Gromacs"]


from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from .._Utils import _have_imported, _try_import

# alchemlyb isn't available on all variants of Python that we support, so we
Expand Down Expand Up @@ -2187,7 +2182,7 @@ def stdout(self, n=10):
raise ValueError("The number of lines must be positive!")

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())

# Get the current number of lines.
Expand Down
7 changes: 1 addition & 6 deletions src/BioSimSpace/Sandpit/Exscientia/Process/_namd.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,11 +26,6 @@

__all__ = ["Namd"]

from .._Utils import _try_import

_pygtail = _try_import("pygtail")


from . import _process


Expand Down Expand Up @@ -2103,7 +2098,7 @@ def stdout(self, n=10):
raise ValueError("The number of lines must be positive!")

# Append any new lines to the stdout list.
for line in _pygtail.Pygtail(self._stdout_file):
for line in self._tail(self._stdout_file):
self._stdout.append(line.rstrip())

# Split the record using whitespace.
Expand Down
Loading