code: def grounded_monomer_patterns(model, agent, ignore_activities=False):
      if not isinstance(agent, ist.Agent):
          monomer = model.monomers.get(agent.name)
          if not monomer:
              return
          yield monomer()
      monomer = None
      for ann in model.annotations:
          if monomer:
              break
          if not ann.predicate == 'is':
              continue
          if not isinstance(ann.subject, Monomer):
              continue
          (ns, id) = parse_identifiers_url(ann.object)
          if ns is None and id is None:
              continue
          for db_ns, db_id in agent.db_refs.items():
              if db_ns == ns and db_id == id:
                  monomer = ann.subject
                  break
      if monomer is None:
          logger.info('No monomer found corresponding to agent %s' % agent)
          return
      sc_list = []
      for mod in agent.mods:
          mod_sites = {}
          res_sites = set([])
          pos_sites = set([])
          for ann in monomer.site_annotations:
              if ann.predicate == 'is_modification' and \
                 ann.object == mod.mod_type:
                  site_state = ann.subject
                  assert isinstance(site_state, tuple)
                  assert len(site_state) == 2
                  mod_sites[site_state[0]] = site_state[1]
              elif ann.predicate == 'is_residue' and \
                   ann.object == mod.residue:
                  res_sites.add(ann.subject)
              elif ann.predicate == 'is_position' and \
                   ann.object == mod.position:
                  pos_sites.add(ann.subject)
          viable_sites = set(mod_sites.keys())
          if mod.residue is not None:
              viable_sites = viable_sites.intersection(res_sites)
          if mod.position is not None:
              viable_sites = viable_sites.intersection(pos_sites)
          if not viable_sites:
              return
          pattern_list = []
          for site_name in viable_sites:
              pattern_list.append({site_name: (mod_sites[site_name], WILD)})
          sc_list.append(pattern_list)
      if agent.activity and not ignore_activities:
          rel_type = 'has_active_pattern' if agent.activity.is_active \
                                          else 'has_inactive_pattern'
          active_form_list = []
          for ann in model.annotations:
              if ann.subject == monomer and ann.predicate == rel_type:
                  active_form_list.append(ann.object)
          sc_list.append(active_form_list)
      for pattern_combo in itertools.product(*sc_list):
          mp_sc = {}
          for pattern in pattern_combo:
              mp_sc.update(pattern)
          if mp_sc:
              yield monomer(**mp_sc)
      if not sc_list:
          yield monomer()