Skip to content

Commit

Permalink
Make output directory when it didn't exist for workflow (#290)
Browse files Browse the repository at this point in the history
- Workflow base class will now create output folder if it doesn't exist (see also
   alchemistry/flamel#24 )
- add test
- update CHANGES
  • Loading branch information
xiki-tempula authored Dec 12, 2022
1 parent a893769 commit 8e9c317
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 9 deletions.
8 changes: 8 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ The rules for this file:
* release numbers follow "Semantic Versioning" https://semver.org

------------------------------------------------------------------------------

*/*/* xiki-tempula, orbeckst

* 2.0.0

Enhancements
- The output folder will be created if not existed in workflows (PR #290).

12/09/2022 DrDomenicoMarson, xiki-tempula, orbeckst

* 1.0.1
Expand Down
6 changes: 5 additions & 1 deletion src/alchemlyb/tests/test_workflow.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import os
from pathlib import Path

import pandas as pd
import pytest
Expand All @@ -10,11 +11,14 @@ class Test_automatic_base:
@staticmethod
@pytest.fixture(scope="session")
def workflow(tmp_path_factory):
outdir = tmp_path_factory.mktemp("out")
outdir = tmp_path_factory.mktemp("out") / "abc" / "def"
workflow = base.WorkflowBase(out=str(outdir))
workflow.run()
return workflow

def test_outdir(self, workflow):
assert Path(workflow.out).is_dir()

def test_write(self, workflow):
"""Patch the output directory to tmpdir"""
workflow.result.to_pickle(os.path.join(workflow.out, "result.pkl"))
Expand Down
11 changes: 3 additions & 8 deletions src/alchemlyb/workflows/abfe.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import pandas as pd

from .base import WorkflowBase
from .. import __version__
from .. import concat
from ..convergence import forward_backward_convergence
from ..estimators import AutoMBAR as MBAR
Expand Down Expand Up @@ -75,16 +74,9 @@ def __init__(
suffix="xvg",
outdirectory=os.path.curdir,
):

super().__init__(units, software, T, outdirectory)
self.logger = logging.getLogger("alchemlyb.workflows.ABFE")
self.logger.info("Initialise Alchemlyb ABFE Workflow")
self.logger.info(f"Alchemlyb Version: f{__version__}")
self.logger.info(f"Set Temperature to {T} K.")
self.logger.info(f"Set Software to {software}.")

self.update_units(units)

self.logger.info(
f"Finding files with prefix: {prefix}, suffix: "
f"{suffix} under directory {dir} produced by "
Expand All @@ -105,6 +97,9 @@ def __init__(
else:
raise NotImplementedError(f"{software} parser not found.")

def _logger_setup(self):
self.logger = logging.getLogger("alchemlyb.workflows.ABFE")

def read(self, read_u_nk=True, read_dHdl=True):
"""Read the u_nk and dHdL data from the
:attr:`~alchemlyb.workflows.ABFE.file_list`
Expand Down
15 changes: 15 additions & 0 deletions src/alchemlyb/workflows/base.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
"""Basic building blocks for free energy workflows."""

import logging
from pathlib import Path

import pandas as pd

from .. import __version__


class WorkflowBase:
"""The base class for the Workflow.
Expand Down Expand Up @@ -42,11 +47,21 @@ class WorkflowBase:
def __init__(
self, units="kT", software="Gromacs", T=298, out="./", *args, **kwargs
):
self._logger_setup()
self.logger.info(f"Alchemlyb Version: f{__version__}")
self.logger.info(f"Set Temperature to {T} K.")
self.T = T
self.logger.info(f"Set Software to {software}.")
self.software = software
self.unit = units
self.file_list = []
self.out = out
if not Path(out).is_dir():
self.logger.info(f"Make output folder {out}.")
Path(out).mkdir(parents=True)

def _logger_setup(self):
self.logger = logging.getLogger("alchemlyb.workflows.WorkflowBase")

def run(self, *args, **kwargs):
"""Run the workflow in an automatic fashion.
Expand Down

0 comments on commit 8e9c317

Please sign in to comment.