def test_exception(self): """ Forget the trailing 'end' and ensure it produces an error :return: """ exception_message = "Antimony: Error in model string, line 19: syntax error, unexpected end of file, expecting '-' or '+' or => or '<'" try: with model.BuildAntimony(self.copasi_file2) as loader: self.mod2 = loader.load(""" model model2 compartment cell = 1.0 var A in cell var B in cell vAProd = 0.1 kADeg = 0.2 kBProd = 0.3 kBDeg = 0.4 vBasalAProd = 0.001 A = 0 B = 0 AProd: => A; cell*vAProd*B+vBasalAProd ADeg: A =>; cell*kADeg*A BProd: => B; cell*kBProd*A BDeg: B => ; cell*kBDeg*B """) except Exception as E: self.assertEqual(str(E), str(exception_message))
def test_build(self): """ Make copasi file from antimony :return: """ with model.BuildAntimony(self.copasi_file1) as loader: self.mod1 = loader.load(""" model model1 compartment cell = 1.0 var A in cell var B in cell vAProd = 0.1 kADeg = 0.2 kBProd = 0.3 kBDeg = 0.4 A = 0 B = 0 AProd: => A; cell*vAProd ADeg: A =>; cell*kADeg*A*B BProd: => B; cell*kBProd*A BDeg: B => ; cell*kBDeg*B end """) self.assertTrue(os.path.isfile(self.copasi_file1))
def setUp(self): ## create model selection directory self.dire = os.path.join(os.path.dirname(__file__), 'AntimonyModels') if not os.path.isdir(self.dire): os.makedirs(self.dire) self.copasi_file1 = os.path.join(self.dire, 'negative_feedback.cps') with model.BuildAntimony(self.copasi_file1) as loader: self.mod = loader.load(""" model model1 compartment cell = 1.0 var A in cell var B in cell vAProd = 0.1 kADeg = 0.2 kBProd = 0.3 kBDeg = 0.4 vBasalAProd = 0.001 A = 0 B = 0 AProd: => A; cell*vAProd*B+vBasalAProd ADeg: A =>; cell*kADeg*A BProd: => B; cell*kBProd*A BDeg: B => ; cell*kBDeg*B end """) assert os.path.isfile(self.copasi_file1)
def setUp(self): ## create model selection directory self.dire = os.path.join(os.path.dirname(__file__), 'AntimonyModels') if not os.path.isdir(self.dire): os.makedirs(self.dire) self.copasi_file1 = os.path.join(self.dire, 'negative_feedback.cps') with model.BuildAntimony(self.copasi_file1) as loader: self.mod = loader.load( """ model model1 compartment cell = 1.0 var A in cell var B in cell vAProd = 0.1 kADeg = 0.2 kBProd = 0.3 kBDeg = 0.4 vBasalAProd = 0.001 A = 0 B = 0 AProd: => A; cell*vAProd*B+vBasalAProd ADeg: A =>; cell*kADeg*A BProd: => B; cell*kBProd*A BDeg: B => ; cell*kBDeg*B end """ ) if not os.path.isfile(self.copasi_file1): raise errors.FileDoesNotExistError('Copasi File "{}" was not created in ' 'setting up the test case'.format(self.copasi_file1))
def test_build_model_to_file_path_which_already_exists(self): with model.BuildAntimony(self.copasi_file1) as loader: mod = loader.load( """ model model1 compartment cell = 1.0 var A in cell var C in cell vAProd = 0.1 kADeg = 0.2 kCProd = 0.3 kCDeg = 0.4 vBasalAProd = 0.001 A = 0 C = 0 AProd: => A; cell*vAProd*B+vBasalAProd ADeg: A =>; cell*kADeg*A CProd: => C; cell*kCProd*A CDeg: C => ; cell*kCDeg*C end """ ) self.assertNotIn('B', [i.name for i in mod.metabolites])
def setUp(self): ant1 = """ model first() compartment Cell = 1; R1: A => B ; Cell * k1 * A; R2: B => C ; Cell * k2 * B; R3: C => A ; Cell * k3 * C; k1 = 0.1; k2 = 0.1; k3 = 0.1; A = 100; B = 0; C = 0; end """ ant2 = """ model second() compartment Cell = 1; R1: A => B ; Cell * k1 * A; R2: B => C ; Cell * k2 * B; R3: B => A ; Cell * k3 * B; k1 = 0.1; k2 = 0.1; k3 = 0.1; A = 100; B = 0; C = 0; end """ self.fname1 = os.path.join(os.path.dirname(__file__), 'first.cps') self.fname2 = os.path.join(os.path.dirname(__file__), 'second.cps') with model.BuildAntimony(self.fname1) as loader: self.mod1 = loader.load(ant1) with model.BuildAntimony(self.fname2) as loader: self.mod2 = loader.load(ant2) self.fname1 = os.path.join(os.path.dirname(__file__), 'dataset1.txt') self.fname2 = os.path.join(os.path.dirname(__file__), 'dataset2.txt') self.mod1.simulate(0, 9, 1, report_name=self.fname1) self.mod2.simulate(0, 9, 1, report_name=self.fname2) with tasks.ParameterEstimation.Context( [self.mod1, self.mod2], [self.fname1, self.fname2], context='s', parameters='g' ) as context: self.config = context.get_config() config_dct = dict( models=dict( first=dict( copasi_file=self.mod1.copasi_file, ), second=dict( copasi_file=self.mod2.copasi_file ) ), datasets=dict( experiments=dict( first_exp=dict( filename=self.fname1 ), second_exp=dict( filename=self.fname2 ) ) ), items=dict( fit_items='g' ), settings=dict( working_directory=os.path.dirname(__file__), run_mode=True, method='genetic_algorithm', population_size=5, number_of_generations=25 ) ) self.config = tasks.ParameterEstimation.Config(**config_dct) self.pe = tasks.ParameterEstimation(self.config)