code: def get_monomer_pattern(model, agent, extra_fields=None):
      
      try:
          monomer = model.monomers[_n(agent.name)]
      except KeyError as e:
          logger.warning('Monomer with name %s not found in model' %
                         _n(agent.name))
          return None
      # Get the agent site pattern
      pattern = get_site_pattern(agent)
      if extra_fields is not None:
          for k, v in extra_fields.items():
              # This is an important assumption, it only sets the given pattern
              # on the monomer if that site/key is not already specified at the
              # Agent level. For instance, if the Agent is specified to have
              # 'activity', that site will not be updated here.
              if k not in pattern:
                  pattern[k] = v
      # If a model is given, return the Monomer with the generated pattern,
      # otherwise just return the pattern
      try:
          monomer_pattern = monomer(**pattern)
      except Exception as e:
          logger.info("Invalid site pattern %s for monomer %s" %
                        (pattern, monomer))
          return None
      return monomer_pattern
docs: Construct a PySB MonomerPattern from an Agent.