From de0875b0b72df1f093502dccc8cf9f4404c3d028 Mon Sep 17 00:00:00 2001 From: William Heymann Date: Tue, 8 Jun 2021 16:47:30 +0200 Subject: [PATCH] Using a metaclass this version of the python interface no longer has class_cadet_path and has the older interface again The previous version was never pushed to PyPI so very few things should be using the 0.9 version interface --- cadet/cadet.py | 95 +++++++++++++++++++++++++++++++------------- examples/dll_test.py | 7 ++-- setup.py | 2 +- 3 files changed, 72 insertions(+), 32 deletions(-) diff --git a/cadet/cadet.py b/cadet/cadet.py index 8f32ada..949878c 100644 --- a/cadet/cadet.py +++ b/cadet/cadet.py @@ -121,45 +121,82 @@ def is_dll(value): suffix = Path(value).suffix return suffix in {'.so', '.dll'} -class Cadet(H5): - #cadet_path must be set in order for simulations to run - cadet_runner = None - return_information = None - is_file = None +class CadetMeta(type): + _cadet_runner_class = None + _is_file_class = None @property - def cadet_path(self): - if self.cadet_runner is not None: - return self.cadet_runner.cadet_path + def is_file(cls): + return bool(cls._is_file_class) + + @property + def cadet_path(cls): + if cls.cadet_runner is not None: + return cls.cadet_runner.cadet_path @cadet_path.setter - def cadet_path(self, value): - if self.cadet_runner is not None and self.cadet_runner.cadet_path != value: - del self.cadet_runner + def cadet_path(cls, value): + def __init__(cls): + cls._cadet_runner_class = None + cls._is_file_class = True + + if cls._cadet_runner_class is not None and cls._cadet_runner_class.cadet_path != value: + del cls._cadet_runner_class if is_dll(value): - self.cadet_runner = CadetDLL(value) - self.is_file = False + cls._cadet_runner_class = CadetDLL(value) + cls._is_file_class = False else: - self.cadet_runner = CadetFile(value) - self.is_file = True + cls._cadet_runner_class = CadetFile(value) + cls._is_file_class = True @cadet_path.deleter + def cadet_path(cls): + del cls._cadet_runner_class + +class Cadet(H5, metaclass=CadetMeta): + #cadet_path must be set in order for simulations to run + def __init__(self, *data): + super().__init__(*data) + self._cadet_runner = None + self.return_information = None + self._is_file = None + + @property + def is_file(self): + if self._is_file is not None: + return bool(self._is_file) + if self._is_file_class is not None: + return bool(self._is_file_class) + + @property + def cadet_runner(self): + if self._cadet_runner is not None: + return self._cadet_runner + if self._cadet_runner_class is not None: + return self._cadet_runner_class + + @property def cadet_path(self): - del self.cadet_runner + runner = self.cadet_runner + if runner is not None: + return runner.cadet_path - @classmethod - def class_cadet_path(cls, value): - if cls.cadet_runner is not None and cls.cadet_runner.cadet_path != value: - del cls.cadet_runner + @cadet_path.setter + def cadet_path(self, value): + if self._cadet_runner is not None and self._cadet_runner.cadet_path != value: + del self._cadet_runner if is_dll(value): - cls.cadet_runner = CadetDLL(value) - cls.is_file = False + self._cadet_runner = CadetDLL(value) + self._is_file = False else: - cls.cadet_runner = CadetFile(value) - cls.is_file = True + self._cadet_runner = CadetFile(value) + self._is_file = True + @cadet_path.deleter + def cadet_path(self): + del self._cadet_runner def transform(self, x): return str.upper(x) @@ -168,8 +205,9 @@ def inverse_transform(self, x): return str.lower(x) def load_results(self): - if self.cadet_runner is not None: - self.cadet_runner.load_results(self) + runner = self.cadet_runner + if runner is not None: + runner.load_results(self) def run(self, timeout = None, check=None): data = self.cadet_runner.run(simulation=self.root.input, filename=self.filename, timeout=timeout, check=check) @@ -185,8 +223,9 @@ def run_load(self, timeout = None, check=None, clear=True): return data def clear(self): - if self.cadet_runner is not None: - self.cadet_runner.clear() + runner = self.cadet_runner + if runner is not None: + runner.clear() class CadetFile: diff --git a/examples/dll_test.py b/examples/dll_test.py index 7a05015..a9ca4d2 100644 --- a/examples/dll_test.py +++ b/examples/dll_test.py @@ -12,24 +12,25 @@ #sim.load_results() #print(sim) -cadet.cadet.Cadet.class_cadet_path("C:/Users/kosh_000/cadet_build/CADET/VCPKG_4/bin/cadet.dll") +cadet.cadet.Cadet.cadet_path = "C:/Users/kosh_000/cadet_build/CADET/VCPKG_4/bin/cadet.dll" sim = cadet.cadet.Cadet() sim.filename = r"C:\Users\kosh_000\cadet_build\CADET\VCPKG_4\bin\LWE.h5" +#sim.cadet_path = "C:/Users/kosh_000/cadet_build/CADET/VCPKG_4/bin/cadet-cli.exe" #sim.filename = r"F:\match_examples\transforms\auto\dextran.h5" sim.load() print("isFile", sim.is_file) sim.filename = "L:/temp.h5" +#sim.save() #sim.cadet_path = r"C:\Users\kosh_000\cadet_build\CADET\VCPKG_4\bin\cadet-cli.exe" #sim.save() -sim.run() -sim.load_results() +sim.run_load() plt.figure(figsize=[15,15]) plt.plot(sim.root.output.solution.solution_times, sim.root.output.solution.unit_000.solution_outlet_comp_001) diff --git a/setup.py b/setup.py index a409077..483d3a4 100644 --- a/setup.py +++ b/setup.py @@ -5,7 +5,7 @@ setuptools.setup( name="CADET", - version="0.9", + version="0.10", author="William Heymann", author_email="w.heymann@fz-juelich.de", description="CADET is a python interface to the CADET chromatography simulator",