def assemble_model(stmts): pa = PysbAssembler() pa.add_statements(stmts) model = pa.make_model(policies='one_step') pa.add_default_initial_conditions(100.0) try: targeted_agents = get_targeted_agents(stmts) no_upstream_active_agents = get_no_upstream_active_agents(stmts) except: targeted_agents = [] no_upstream_active_agents = [] try: chemical_agents = get_chemical_agents(stmts) except: chemical_agents = [] for m in model.monomers: try: if m.name in targeted_agents or m.name in no_upstream_active_agents: pysb_assembler.set_base_initial_condition(model, model.monomers[m.name], 50.0) pysb_assembler.set_extended_initial_condition(model, m, 50.0) elif m.name in chemical_agents: pysb_assembler.set_base_initial_condition(model, model.monomers[m.name], 10000.0) else: pysb_assembler.set_extended_initial_condition(model, m, 0) except: pysb_assembler.set_extended_initial_condition(model, m, 0) # Tweak parameters for param in model.parameters: if 'kf' in param.name and 'bind' in param.name: param.value = param.value * 100 return model
def apply_condition(model, condition): agent = condition.quantity.entity try: monomer = model.monomers[pa._n(agent.name)] except KeyError: raise MissingMonomerError('%s is not in the model ' % agent.name, agent) site_pattern = pa.get_site_pattern(agent) # TODO: handle modified patterns if site_pattern: logger.warning('Cannot handle initial conditions on' + ' modified monomers.') if condition.condition_type == 'exact': ic_name = monomer.name + '_0' if condition.value.quant_type == 'number': pa.set_base_initial_condition(model, monomer, condition.value.value) else: logger.warning('Cannot handle non-number initial conditions') elif condition.condition_type == 'multiple': # TODO: refer to annotations for the IC name ic_name = monomer.name + '_0' model.parameters[ic_name].value *= condition.value elif condition.condition_type == 'decrease': ic_name = monomer.name + '_0' model.parameters[ic_name].value *= 0.9 elif condition.condition_type == 'increase': ic_name = monomer.name + '_0' model.parameters[ic_name].value *= 1.1 logger.info('New initial condition: %s' % model.parameters[ic_name])
def apply_condition(model, condition): agent = condition.quantity.entity try: monomer = model.monomers[pa._n(agent.name)] except KeyError: raise MissingMonomerError('%s is not in the model ' % agent.name) site_pattern = pa.get_site_pattern(agent) # TODO: handle modified patterns if site_pattern: logger.warning('Cannot handle initial conditions on' + ' modified monomers.') if condition.condition_type == 'exact': ic_name = monomer.name + '_0' if condition.value.quant_type == 'number': pa.set_base_initial_condition(model, monomer, condition.value.value) else: logger.warning('Cannot handle non-number initial conditions') elif condition.condition_type == 'multiple': # TODO: refer to annotations for the IC name ic_name = monomer.name + '_0' model.parameters[ic_name].value *= condition.value elif condition.condition_type == 'decrease': ic_name = monomer.name + '_0' model.parameters[ic_name].value *= 0.9 elif condition.condition_type == 'increase': ic_name = monomer.name + '_0' model.parameters[ic_name].value *= 1.1 logger.info('New initial condition: %s' % model.parameters[ic_name])