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 replace_agent(self, agent_name, agent_replacement_names, model_id): """Replace an agent in a model with other agents. This is used, for instance, to expand a protein family to multiple specific proteins. """ for stmt in self.statements[model_id-1]: agent_key = [i for i, m in enumerate(stmt.agent_list()) if m is not None and m.name == agent_name] if agent_key: self.statements[model_id-1].remove(stmt) for p in agent_replacement_names: s = copy.deepcopy(stmt) if isinstance(stmt, Complex): s.members[agent_key[0]].name = p else: s.__dict__[agent_key[0]].name = p self.extend_statements([s], model_id) pa = PysbAssembler() pa.add_statements(self.statements[model_id-1]) model = pa.make_model() pa.add_default_initial_conditions(self.default_initial_amount) return model
def assemble_pysb(self, stmts): pa = PysbAssembler() pa.add_statements(stmts) pa.make_model(policies=self.default_policy) pa.add_default_initial_conditions(self.default_initial_amount) return pa.model