def add_rule_to_model(model, rule, annotations=None):
    """Add a Rule to a PySB model and handle duplicate component errors."""
    try:
        model.add_component(rule)
        # If the rule was actually added, also add the annotations
        if annotations:
            model.annotations += annotations
    # If this rule is already in the model, issue a warning and continue
    except ComponentDuplicateNameError:
        msg = "Rule %s already in model! Skipping." % rule.name
        logger.debug(msg)
Add a Rule to a PySB model and handle duplicate component errors.