diff --git a/CHANGES b/CHANGES index 8fa61fad..db99350b 100644 --- a/CHANGES +++ b/CHANGES @@ -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 diff --git a/src/alchemlyb/tests/test_workflow.py b/src/alchemlyb/tests/test_workflow.py index cc31e611..c0a633bf 100644 --- a/src/alchemlyb/tests/test_workflow.py +++ b/src/alchemlyb/tests/test_workflow.py @@ -1,4 +1,5 @@ import os +from pathlib import Path import pandas as pd import pytest @@ -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")) diff --git a/src/alchemlyb/workflows/abfe.py b/src/alchemlyb/workflows/abfe.py index a6d3756f..44c12218 100644 --- a/src/alchemlyb/workflows/abfe.py +++ b/src/alchemlyb/workflows/abfe.py @@ -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 @@ -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 " @@ -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` diff --git a/src/alchemlyb/workflows/base.py b/src/alchemlyb/workflows/base.py index 1b4cbe41..1a7137c2 100644 --- a/src/alchemlyb/workflows/base.py +++ b/src/alchemlyb/workflows/base.py @@ -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. @@ -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.