Skip to content

Commit 1f1677d

Browse files
committed
A bit of cleanup for gromacs engine
1 parent 50b9728 commit 1f1677d

File tree

1 file changed

+9
-36
lines changed

1 file changed

+9
-36
lines changed

src/asyncmd/gromacs/mdengine.py

Lines changed: 9 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,7 @@ def __init__(self,
226226
# Popen handle for gmx mdrun, used to check if we are running
227227
self._proc = None
228228
# these are set by prepare() and used by run_XX()
229-
self._simulation_part = None
229+
self._simulation_part = 0
230230
self._deffnm = None
231231
# tpr for trajectory (part), will become the structure/topology file
232232
self._tpr = None
@@ -247,25 +247,16 @@ def current_trajectory(self) -> Trajectory | None:
247247
Trajectory
248248
Last complete trajectory produced by this engine.
249249
"""
250-
if self._simulation_part == 0:
251-
# we could check if self_proc is set (which prepare sets to None)
252-
# this should make sure that calling current trajectory after
253-
# calling prepare does not return a traj, as soon as we called
254-
# run self._proc will be set, i.e. there is still no gurantee that
255-
# the traj is done, but it will be started always
256-
# (even when accessing simulataneous to the call to run),
257-
# i.e. it is most likely done
258-
# we can also check for simulation part, since it seems
259-
# gmx ignores that if no checkpoint is passed, i.e. we will
260-
# **always** start with part0001 anyways!
261-
# but checking for self._simulation_part == 0 also just makes sure
262-
# we never started a run (i.e. same as checking self._proc)
263-
return None
264250
if (all(v is not None for v in [self._tpr, self._deffnm])
265-
and not self.running):
251+
and self._prepared
252+
and self._simulation_part > 0
253+
):
266254
# self._tpr and self._deffnm are set in prepare, i.e. having them
267255
# set makes sure that we have at least prepared running the traj
268256
# but it might not be done yet
257+
# also check if we ever started a run, i.e. if there might be a
258+
# trajectory to return. If simulation_part == 0 we never executed a
259+
# run method (where it is increased) and also did not (re)start a run
269260
traj = Trajectory(
270261
trajectory_files=os.path.join(
271262
self.workdir,
@@ -280,24 +271,6 @@ def current_trajectory(self) -> Trajectory | None:
280271
return traj
281272
return None
282273

283-
@property
284-
def ready_for_run(self) -> bool:
285-
"""Whether this engine is ready to run, i.e. generate a trajectory."""
286-
return self._prepared and not self.running
287-
288-
@property
289-
def running(self) -> bool:
290-
"""Whether this engine is currently running/generating a trajectory."""
291-
if self._proc is None:
292-
# this happens when we did not call run() yet
293-
return False
294-
if self._proc.returncode is None:
295-
# no return code means it is still running
296-
return True
297-
# dont care for the value of the exit code,
298-
# we are not running anymore if we crashed ;)
299-
return False
300-
301274
@property
302275
def workdir(self) -> str:
303276
"""The current working directory of the engine."""
@@ -850,9 +823,9 @@ async def run(self, nsteps=None, walltime=None, steps_per_part=False):
850823
counted, default False.
851824
"""
852825
# generic run method is actually easier to implement for gmx :D
853-
if not self.ready_for_run:
826+
if not self._prepared:
854827
raise RuntimeError("Engine not ready for run. Call self.prepare() "
855-
+ "and/or check if it is still running.")
828+
+ "before calling a run method.")
856829
if all(kwarg is None for kwarg in [nsteps, walltime]):
857830
raise ValueError("Neither steps nor walltime given.")
858831
if nsteps is not None:

0 commit comments

Comments
 (0)