Skip to content

Commit

Permalink
Backport fixes from PR #128. [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
lohedges committed Jul 7, 2023
1 parent 72022fe commit cbfef2e
Show file tree
Hide file tree
Showing 13 changed files with 153 additions and 29 deletions.
10 changes: 5 additions & 5 deletions demo/interactive_md.ipynb
Original file line number Diff line number Diff line change
Expand Up @@ -336,14 +336,14 @@
"outputs": [],
"source": [
"# Search the system for a residue named ALA. Since there is a single match, we take the first result.\n",
"residue = system.search(\"resname ALA\")[0]\n",
"atoms = system.search(\"resname ALA\")\n",
"\n",
"# Get the indices of the atoms in the molecule, relative to the original system.\n",
"indices = [system.getIndex(x) for x in residue.getAtoms()]\n",
"indices = [system.getIndex(atom) for atom in atoms]\n",
"\n",
"# Compute the RMSD for each frame and plot the result.\n",
"BSS.Notebook.plot(\n",
" y=process.getTrajectory().rmsd(frame=0, atoms=indices),\n",
" y=process.getTrajectory(backend=\"mdtraj\").rmsd(frame=0, atoms=indices),\n",
" xlabel=\"Frame\",\n",
" ylabel=\"RMSD\",\n",
")"
Expand All @@ -352,7 +352,7 @@
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"display_name": "Python 3 (ipykernel)",
"language": "python",
"name": "python3"
},
Expand All @@ -366,7 +366,7 @@
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.7.3"
"version": "3.10.11"
}
},
"nbformat": 4,
Expand Down
15 changes: 13 additions & 2 deletions python/BioSimSpace/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -461,13 +461,18 @@ def getCurrentSystem(self):
"""
return self.getSystem(block=False)

def getTrajectory(self, block="AUTO"):
def getTrajectory(self, backend="AUTO", block="AUTO"):
"""
Return a trajectory object.
Parameters
----------
backend : str
The backend to use for trajectory parsing. To see supported backends,
run BioSimSpace.Trajectory.backends(). Using "AUTO" will try each in
sequence.
block : bool
Whether to block until the process has finished running.
Expand All @@ -478,6 +483,12 @@ def getTrajectory(self, block="AUTO"):
The latest trajectory object.
"""

if not isinstance(backend, str):
raise TypeError("'backend' must be of type 'str'")

if not isinstance(block, (bool, str)):
raise TypeError("'block' must be of type 'bool' or 'str'")

# Wait for the process to finish.
if block is True:
self.wait()
Expand All @@ -489,7 +500,7 @@ def getTrajectory(self, block="AUTO"):
_warnings.warn("The process exited with an error!")

try:
return _Trajectory.Trajectory(process=self)
return _Trajectory.Trajectory(process=self, backend=backend)

except:
return None
Expand Down
15 changes: 13 additions & 2 deletions python/BioSimSpace/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -659,13 +659,18 @@ def getCurrentSystem(self):
"""
return self.getSystem(block=False)

def getTrajectory(self, block="AUTO"):
def getTrajectory(self, backend="AUTO", block="AUTO"):
"""
Return a trajectory object.
Parameters
----------
backend : str
The backend to use for trajectory parsing. To see supported backends,
run BioSimSpace.Trajectory.backends(). Using "AUTO" will try each in
sequence.
block : bool
Whether to block until the process has finished running.
Expand All @@ -676,6 +681,12 @@ def getTrajectory(self, block="AUTO"):
The latest trajectory object.
"""

if not isinstance(backend, str):
raise TypeError("'backend' must be of type 'str'")

if not isinstance(block, (bool, str)):
raise TypeError("'block' must be of type 'bool' or 'str'")

# Wait for the process to finish.
if block is True:
self.wait()
Expand All @@ -695,7 +706,7 @@ def getTrajectory(self, block="AUTO"):
else:
self._traj_file = traj_file

return _Trajectory.Trajectory(process=self)
return _Trajectory.Trajectory(process=self, backend=backend)

except:
return None
Expand Down
16 changes: 14 additions & 2 deletions python/BioSimSpace/Process/_namd.py
Original file line number Diff line number Diff line change
Expand Up @@ -813,13 +813,18 @@ def getCurrentSystem(self):
"""
return self.getSystem(block=False)

def getTrajectory(self, block="AUTO"):
def getTrajectory(self, backend="AUTO", block="AUTO"):
"""
Return a trajectory object.
Parameters
----------
backend : str
The backend to use for trajectory parsing. To see supported backends,
run BioSimSpace.Trajectory.backends(). Using "AUTO" will try each in
sequence.
block : bool
Whether to block until the process has finished running.
Expand All @@ -829,6 +834,13 @@ def getTrajectory(self, block="AUTO"):
trajectory : :class:`Trajectory <BioSimSpace.Trajectory>`
The latest trajectory object.
"""

if not isinstance(backend, str):
raise TypeError("'backend' must be of type 'str'")

if not isinstance(block, (bool, str)):
raise TypeError("'block' must be of type 'bool' or 'str'")

# Wait for the process to finish.
if block is True:
self.wait()
Expand All @@ -840,7 +852,7 @@ def getTrajectory(self, block="AUTO"):
_warnings.warn("The process exited with an error!")

try:
return _Trajectory.Trajectory(process=self)
return _Trajectory.Trajectory(process=self, backend=backend)

except:
return None
Expand Down
17 changes: 14 additions & 3 deletions python/BioSimSpace/Process/_openmm.py
Original file line number Diff line number Diff line change
Expand Up @@ -1109,7 +1109,7 @@ def _generate_config(self):

# Create a dummy PLUMED input file so that we can bind PLUMED
# analysis functions to this process.
self._plumed = _Plumed(self._work_dir)
self._plumed = _Plumed(str(self._work_dir))
plumed_config, auxillary_files = self._plumed.createConfig(
self._system, self._protocol, self._property_map
)
Expand Down Expand Up @@ -1350,13 +1350,18 @@ def getCurrentSystem(self):
"""
return self.getSystem(block=False)

def getTrajectory(self, block="AUTO"):
def getTrajectory(self, backend="AUTO", block="AUTO"):
"""
Return a trajectory object.
Parameters
----------
backend : str
The backend to use for trajectory parsing. To see supported backends,
run BioSimSpace.Trajectory.backends(). Using "AUTO" will try each in
sequence.
block : bool
Whether to block until the process has finished running.
Expand All @@ -1367,6 +1372,12 @@ def getTrajectory(self, block="AUTO"):
The latest trajectory object.
"""

if not isinstance(backend, str):
raise TypeError("'backend' must be of type 'str'")

if not isinstance(block, (bool, str)):
raise TypeError("'block' must be of type 'bool' or 'str'")

# Wait for the process to finish.
if block is True:
self.wait()
Expand All @@ -1380,7 +1391,7 @@ def getTrajectory(self, block="AUTO"):
if not _os.path.isfile(self._traj_file):
return None
else:
return _Trajectory.Trajectory(process=self)
return _Trajectory.Trajectory(process=self, backend=backend)

def getFrame(self, index):
"""
Expand Down
8 changes: 7 additions & 1 deletion python/BioSimSpace/Process/_plumed.py
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ def __init__(self, work_dir):
"PLUMED version >= 2.5 is required."
)

# Store the major and minor versions.
self._plumed_major = major
self._plumed_minor = minor

else:
raise _Exceptions.IncompatibleError("Could not determine PLUMED version!")

Expand Down Expand Up @@ -377,7 +381,9 @@ def _createMetadynamicsConfig(self, system, protocol, property_map={}):

# The funnel collective variable requires an auxiliary file for
# PLUMED versions < 2.7.
if self._plumed_version < 2.7:
if self._plumed_major < 2 or (
self._plumed_major < 3 and self._plumed_minor < 7
):
aux_file = "ProjectionOnAxis.cpp"
self._config.append(f"LOAD FILE={aux_file}")
aux_file = (
Expand Down
15 changes: 13 additions & 2 deletions python/BioSimSpace/Process/_somd.py
Original file line number Diff line number Diff line change
Expand Up @@ -585,13 +585,18 @@ def getCurrentSystem(self):
"""
return self.getSystem(block=False)

def getTrajectory(self, block="AUTO"):
def getTrajectory(self, backend="AUTO", block="AUTO"):
"""
Return a trajectory object.
Parameters
----------
backend : str
The backend to use for trajectory parsing. To see supported backends,
run BioSimSpace.Trajectory.backends(). Using "AUTO" will try each in
sequence.
block : bool
Whether to block until the process has finished running.
Expand All @@ -602,6 +607,12 @@ def getTrajectory(self, block="AUTO"):
The latest trajectory object.
"""

if not isinstance(backend, str):
raise TypeError("'backend' must be of type 'str'")

if not isinstance(block, (bool, str)):
raise TypeError("'block' must be of type 'bool' or 'str'")

# Wait for the process to finish.
if block is True:
self.wait()
Expand All @@ -613,7 +624,7 @@ def getTrajectory(self, block="AUTO"):
_warnings.warn("The process exited with an error!")

try:
return _Trajectory.Trajectory(process=self)
return _Trajectory.Trajectory(process=self, backend=backend)

except:
return None
Expand Down
15 changes: 13 additions & 2 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_amber.py
Original file line number Diff line number Diff line change
Expand Up @@ -708,13 +708,18 @@ def getCurrentSystem(self):
"""
return self.getSystem(block=False)

def getTrajectory(self, block="AUTO"):
def getTrajectory(self, backend="AUTO", block="AUTO"):
"""
Return a trajectory object.
Parameters
----------
backend : str
The backend to use for trajectory parsing. To see supported backends,
run BioSimSpace.Trajectory.backends(). Using "AUTO" will try each in
sequence.
block : bool
Whether to block until the process has finished running.
Expand All @@ -725,6 +730,12 @@ def getTrajectory(self, block="AUTO"):
The latest trajectory object.
"""

if not isinstance(backend, str):
raise TypeError("'backend' must be of type 'str'")

if not isinstance(block, (bool, str)):
raise TypeError("'block' must be of type 'bool' or 'str'")

# Wait for the process to finish.
if block is True:
self.wait()
Expand All @@ -736,7 +747,7 @@ def getTrajectory(self, block="AUTO"):
_warnings.warn("The process exited with an error!")

try:
return _Trajectory.Trajectory(process=self)
return _Trajectory.Trajectory(process=self, backend=backend)

except:
return None
Expand Down
15 changes: 13 additions & 2 deletions python/BioSimSpace/Sandpit/Exscientia/Process/_gromacs.py
Original file line number Diff line number Diff line change
Expand Up @@ -704,13 +704,18 @@ def getCurrentSystem(self):
"""
return self.getSystem(block=False)

def getTrajectory(self, block="AUTO"):
def getTrajectory(self, backend="AUTO", block="AUTO"):
"""
Return a trajectory object.
Parameters
----------
backend : str
The backend to use for trajectory parsing. To see supported backends,
run BioSimSpace.Trajectory.backends(). Using "AUTO" will try each in
sequence.
block : bool
Whether to block until the process has finished running.
Expand All @@ -721,6 +726,12 @@ def getTrajectory(self, block="AUTO"):
The latest trajectory object.
"""

if not isinstance(backend, str):
raise TypeError("'backend' must be of type 'str'")

if not isinstance(block, (bool, str)):
raise TypeError("'block' must be of type 'bool' or 'str'")

# Wait for the process to finish.
if block is True:
self.wait()
Expand All @@ -740,7 +751,7 @@ def getTrajectory(self, block="AUTO"):
else:
self._traj_file = traj_file

return _Trajectory.Trajectory(process=self)
return _Trajectory.Trajectory(process=self, backend=backend)

except:
return None
Expand Down
Loading

0 comments on commit cbfef2e

Please sign in to comment.