62
62
font_scale = 3 )
63
63
64
64
65
-
66
- class GetModelVariableFromStringMixin (Mixin ):
65
+ class _Task (object ):
66
+ """
67
+ base class for tasks
68
+ """
67
69
@staticmethod
68
70
def get_variable_from_string (m , v , glob = False ):
69
71
"""
@@ -111,9 +113,6 @@ def get_variable_from_string(m, v, glob=False):
111
113
assert isinstance (v , str ) != True
112
114
return v
113
115
114
-
115
- class UpdatePropertiesMixin (Mixin ):
116
-
117
116
def update_properties (self , kwargs ):
118
117
"""
119
118
method for updating properties from kwargs
@@ -128,21 +127,16 @@ def update_properties(self, kwargs):
128
127
except AttributeError :
129
128
setattr (self , k , kwargs [k ])
130
129
131
-
132
- class Bool2Numeric (Mixin ):
133
- """
134
- CopasiML uses 1's and 0's for True or False in some
135
- but not all places. When one of these options
136
- is required by the user and is specified as bool,
137
- this class converts them into 1's or 0's.
138
-
139
- Use this method in early on in constructor for
140
- all subclasses where this applies.
141
- """
142
-
143
130
@staticmethod
144
131
def convert_bool_to_numeric (dct ):
145
132
"""
133
+ CopasiML uses 1's and 0's for True or False in some
134
+ but not all places. When one of these options
135
+ is required by the user and is specified as bool,
136
+ this class converts them into 1's or 0's.
137
+
138
+ Use this method in early on in constructor for
139
+ all subclasses where this applies.
146
140
:param:
147
141
`dict`. __dict__ or kwargs or options
148
142
@@ -182,15 +176,36 @@ def convert_bool_to_numeric(dct):
182
176
raise Exception ('{} is not True or False' .format (v ))
183
177
return dct
184
178
179
+ @staticmethod
180
+ def check_integrity (allowed , given ):
181
+ """
182
+ Method to raise an error when a wrong
183
+ kwarg is passed to a subclass
184
+ :param allowed:
185
+ `list`. List of allowed kwargs
186
+
187
+ :param given: List of kwargs given by user or default
188
+
189
+ :return:
190
+ None
191
+ """
192
+ for key in given :
193
+ if key not in allowed :
194
+ raise errors .InputError ('{} not in {}' .format (key , allowed ))
195
+
185
196
186
- class Bool2Str ():
197
+ class Bool2Str (object ):
187
198
"""
188
199
copasiML expects strings and we pythoners
189
200
want to use python booleans not strings
190
201
This class quickly converts between them
191
202
"""
192
203
193
204
def __init__ (self , dct ):
205
+ """
206
+
207
+ :param dct: dict[kwarg] = boolean
208
+ """
194
209
self .dct = dct
195
210
if isinstance (self .dct , dict ) != True :
196
211
raise errors .InputError ('Input must be dict' )
@@ -223,26 +238,7 @@ def convert_dct(self):
223
238
return self .dct
224
239
225
240
226
- class CheckIntegrityMixin (Mixin ):
227
- @staticmethod
228
- def check_integrity (allowed , given ):
229
- """
230
- Method to raise an error when a wrong
231
- kwarg is passed to a subclass
232
- :param allowed:
233
- `list`. List of allowed kwargs
234
-
235
- :param given: List of kwargs given by user or default
236
-
237
- :return:
238
- None
239
- """
240
- for key in given :
241
- if key not in allowed :
242
- raise errors .InputError ('{} not in {}' .format (key , allowed ))
243
-
244
-
245
- class CopasiMLParser (object ):
241
+ class CopasiMLParser (_Task ):
246
242
"""
247
243
Parse a copasi file into xml.etree.
248
244
@@ -284,11 +280,8 @@ def write_copasi_file(self, copasi_filename, xml):
284
280
root .write (copasi_filename )
285
281
286
282
287
- @mixin (UpdatePropertiesMixin )
288
- @mixin (Bool2Numeric )
289
283
@mixin (model .ReadModelMixin )
290
- @mixin (CheckIntegrityMixin )
291
- class Run (object ):
284
+ class Run (_Task ):
292
285
"""
293
286
Execute a copasi model using CopasiSE. To
294
287
be operational the environment variable CopasiSE
@@ -517,11 +510,8 @@ def submit_copasi_job_slurm(self):
517
510
518
511
519
512
@mixin (model .GetModelComponentFromStringMixin )
520
- @mixin (UpdatePropertiesMixin )
521
513
@mixin (model .ReadModelMixin )
522
- @mixin (CheckIntegrityMixin )
523
- @mixin (Bool2Numeric )
524
- class RunParallel (object ):
514
+ class RunParallel (_Task ):
525
515
"""
526
516
527
517
@@ -635,12 +625,8 @@ def run_parallel(self):
635
625
636
626
637
627
@mixin (model .GetModelComponentFromStringMixin )
638
- # @mixin(GetModelVariableFromStringMixin)
639
- @mixin (UpdatePropertiesMixin )
640
628
@mixin (model .ReadModelMixin )
641
- @mixin (CheckIntegrityMixin )
642
- @mixin (Bool2Numeric )
643
- class Reports (object ):
629
+ class Reports (_Task ):
644
630
"""
645
631
Creates reports in copasi output specification section. Which report is
646
632
controlled by the report_type key word. The following are valid types of
@@ -1091,12 +1077,8 @@ def clear_all_reports(self):
1091
1077
return self .model
1092
1078
1093
1079
1094
- @mixin (GetModelVariableFromStringMixin )
1095
- @mixin (UpdatePropertiesMixin )
1096
- @mixin (Bool2Numeric )
1097
1080
@mixin (model .ReadModelMixin )
1098
- @mixin (CheckIntegrityMixin )
1099
- class TimeCourse (object ):
1081
+ class TimeCourse (_Task ):
1100
1082
"""
1101
1083
##todo implement arguments that get passed on to report
1102
1084
as **report_kwargs
@@ -1678,12 +1660,8 @@ def get_report_key(self):
1678
1660
return key
1679
1661
1680
1662
1681
- @mixin (GetModelVariableFromStringMixin )
1682
- @mixin (UpdatePropertiesMixin )
1683
- @mixin (Bool2Numeric )
1684
1663
@mixin (model .ReadModelMixin )
1685
- @mixin (CheckIntegrityMixin )
1686
- class Scan (object ):
1664
+ class Scan (_Task ):
1687
1665
"""
1688
1666
Interface to COPASI scan task
1689
1667
@@ -2096,11 +2074,8 @@ def execute(self):
2096
2074
2097
2075
2098
2076
@mixin (model .GetModelComponentFromStringMixin )
2099
- @mixin (UpdatePropertiesMixin )
2100
2077
@mixin (model .ReadModelMixin )
2101
- @mixin (CheckIntegrityMixin )
2102
- @mixin (Bool2Numeric )
2103
- class ExperimentMapper (object ):
2078
+ class ExperimentMapper (_Task ):
2104
2079
"""
2105
2080
Class for mapping variables from file to cps
2106
2081
@@ -2588,13 +2563,9 @@ def map_experiments(self):
2588
2563
return self .model
2589
2564
2590
2565
2591
- @mixin (GetModelVariableFromStringMixin )
2592
2566
@mixin (model .GetModelComponentFromStringMixin )
2593
- @mixin (UpdatePropertiesMixin )
2594
2567
@mixin (model .ReadModelMixin )
2595
- @mixin (CheckIntegrityMixin )
2596
- @mixin (Bool2Numeric )
2597
- class ParameterEstimation (object ):
2568
+ class ParameterEstimation (_Task ):
2598
2569
"""
2599
2570
Set up and run a parameter estimation in copasi.
2600
2571
@@ -3800,7 +3771,7 @@ def setup(self):
3800
3771
# print self.model
3801
3772
3802
3773
3803
- class ChaserParameterEstimations (object ):
3774
+ class ChaserParameterEstimations (_Task ):
3804
3775
"""
3805
3776
Perform secondary hook and jeeves parameter estimations
3806
3777
starting from the best values of a primary global estimator.
@@ -4080,11 +4051,8 @@ def run(self):
4080
4051
Run (mod , task = 'parameter_estimation' , mode = self .run_mode )
4081
4052
4082
4053
4083
- @mixin (UpdatePropertiesMixin )
4084
- @mixin (Bool2Numeric )
4085
4054
@mixin (model .ReadModelMixin )
4086
- @mixin (CheckIntegrityMixin )
4087
- class MultiModelFit (object ):
4055
+ class MultiModelFit (_Task ):
4088
4056
"""
4089
4057
Coordinate a systematic multi model fitting parameter estimation and
4090
4058
compare results using :py:class:`viz.ModelSelection`
@@ -4320,11 +4288,8 @@ def format_data(self):
4320
4288
4321
4289
4322
4290
@mixin (model .GetModelComponentFromStringMixin )
4323
- @mixin (UpdatePropertiesMixin )
4324
- @mixin (Bool2Numeric )
4325
4291
@mixin (model .ReadModelMixin )
4326
- @mixin (CheckIntegrityMixin )
4327
- class ProfileLikelihood (object ):
4292
+ class ProfileLikelihood (_Task ):
4328
4293
"""
4329
4294
4330
4295
@@ -4930,14 +4895,10 @@ def run_analysis(self):
4930
4895
sge_job_filename = re .sub ('[().]' , '' , sge_job_filename )
4931
4896
Run (self .model_dct [m ][param ], task = 'scan' , mode = self .run , sge_job_filename = sge_job_filename + '.sh' )
4932
4897
4898
+
4933
4899
@mixin (model .GetModelComponentFromStringMixin )
4934
- @mixin (UpdatePropertiesMixin )
4935
- @mixin (Bool2Numeric )
4936
4900
@mixin (model .ReadModelMixin )
4937
- @mixin (CheckIntegrityMixin )
4938
- class Sensitivities (object ):
4939
-
4940
-
4901
+ class Sensitivities (_Task ):
4941
4902
4942
4903
4943
4904
def __init__ (self , model , ** kwargs ):
0 commit comments