code: def get_im(self, force_update=False):
          if self._im and not force_update:
              return self._im
          if not self.model:
              raise Exception("Cannot get influence map if there is no model.")
          def add_obs_for_agent(agent):
              obj_mps = list(pa.grounded_monomer_patterns(self.model, agent))
              if not obj_mps:
                  logger.debug('No monomer patterns found in model for agent %s, '
                              'skipping' % agent)
                  return
              obs_list = []
              for obj_mp in obj_mps:
                  obs_name = _monomer_pattern_label(obj_mp) + '_obs'
                  obj_obs = Observable(obs_name, obj_mp, _export=False)
                  obs_list.append(obs_name)
                  try:
                      self.model.add_component(obj_obs)
                  except ComponentDuplicateNameError as e:
                      pass
              return obs_list
          self.model.observables = ComponentSet([])
          for stmt in self.statements:
              if isinstance(stmt, Modification):
                  mod_condition_name = modclass_to_modtype[stmt.__class__]
                  if isinstance(stmt, RemoveModification):
                      mod_condition_name = modtype_to_inverse[mod_condition_name]
                  modified_sub = _add_modification_to_agent(stmt.sub,
                                      mod_condition_name, stmt.residue,
                                      stmt.position)
                  obs_list = add_obs_for_agent(modified_sub)
                  self.stmt_to_obs[stmt] = obs_list
              elif isinstance(stmt, RegulateActivity):
                  regulated_obj, polarity = \
                          _add_activity_to_agent(stmt.obj, stmt.obj_activity,
                                                 stmt.is_activation)
                  obs_list = add_obs_for_agent(regulated_obj)
                  self.stmt_to_obs[stmt] = obs_list
              elif isinstance(stmt, RegulateAmount):
                  obs_list = add_obs_for_agent(stmt.obj)
                  self.stmt_to_obs[stmt] = obs_list
              elif isinstance(stmt, Influence):
                  obs_list = add_obs_for_agent(stmt.obj.concept)
                  self.stmt_to_obs[stmt] = obs_list
          for ag in self.agent_obs:
              obs_list = add_obs_for_agent(ag)
              self.agent_to_obs[ag] = obs_list
          logger.info("Generating influence map")
          self._im = self.generate_im(self.model)
          node_attributes = nx.get_node_attributes(self._im, 'node_type')
          for rule in self.model.rules:
              obs_list = []
              for neighb in self._im.neighbors(rule.name):
                  if node_attributes[neighb] != 'variable':
                      continue
                  edge_sign = _get_edge_sign(self._im, (rule.name, neighb))
                  obs_list.append((neighb, edge_sign))
              self.rule_obs_dict[rule.name] = obs_list
          return self._im