def apply_condition(model, condition): agent = condition.quantity.entity monomer = model.monomers[pa._n(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])
def get_create_observable(model, agent): site_pattern = pa.get_site_pattern(agent) obs_name = pa.get_agent_rule_str(agent) + '_obs' monomer = model.monomers[pa._n(agent.name)] obs = Observable(obs_name.encode('utf-8'), monomer(site_pattern)) model.add_component(obs) return obs
def _check_regulate_activity(self, stmt): """Check a RegulateActivity statement.""" logger.info('Checking stmt: %s' % stmt) # FIXME Currently this will match rules with the corresponding monomer # pattern from the Activation/Inhibition statement, which will nearly # always have no state conditions on it. In future, this statement foo # should also match rules in which 1) the agent is in its active form, # or 2) the agent is tagged as the enzyme in a rule of the appropriate # activity (e.g., a phosphorylation rule) FIXME subj_mp = pa.get_monomer_pattern(self.model, stmt.subj) target_polarity = 1 if stmt.is_activation else -1 # This may fail, since there may be no rule in the model activating the # object, and the object may not have an "active" site of the # appropriate type obj_obs_name = pa.get_agent_rule_str(stmt.obj) + '_obs' try: obj_site_pattern = pa.get_site_pattern(stmt.obj) obj_site_pattern.update({stmt.obj_activity: 'active'}) obj_monomer = self.model.monomers[stmt.obj.name] obj_mp = obj_monomer(**obj_site_pattern) except Exception as e: logger.info("Could not create obj monomer pattern: %s" % e) return False obj_obs = Observable(obj_obs_name, obj_mp, _export=False) return self._find_im_paths(subj_mp, obj_obs, target_polarity)
def get_create_observable(model, agent): site_pattern = pa.get_site_pattern(agent) obs_name = pa.get_agent_rule_str(agent) + '_obs' monomer = model.monomers[agent.name] obs = Observable(obs_name, monomer(site_pattern)) model.add_component(obs) return obs
def apply_condition(model, condition): agent = condition.quantity.entity monomer = model.monomers[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])
def get_create_observable(model, agent): site_pattern = pa.get_site_pattern(agent) obs_name = pa.get_agent_rule_str(agent) + '_obs' try: monomer = model.monomers[pa._n(agent.name)] except KeyError: raise MissingMonomerError('%s is not in the model ' % agent.name) try: monomer_state = monomer(site_pattern) except Exception as e: msg = 'Site pattern %s invalid for monomer %s' % \ (site_pattern, monomer.name) raise MissingMonomerSiteError(msg) obs = Observable(obs_name, monomer(site_pattern)) model.add_component(obs) return obs