Skip to content

Commit

Permalink
Using a metaclass this version of the python interface no longer has …
Browse files Browse the repository at this point in the history
…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
  • Loading branch information
Immudzen committed Jun 8, 2021
1 parent 86bed91 commit de0875b
Show file tree
Hide file tree
Showing 3 changed files with 72 additions and 32 deletions.
95 changes: 67 additions & 28 deletions cadet/cadet.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand All @@ -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:

Expand Down
7 changes: 4 additions & 3 deletions examples/dll_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

setuptools.setup(
name="CADET",
version="0.9",
version="0.10",
author="William Heymann",
author_email="[email protected]",
description="CADET is a python interface to the CADET chromatography simulator",
Expand Down

0 comments on commit de0875b

Please sign in to comment.