import click


def generate_mapping(mapper, molA, molB):
    """Utility method to extract a single mapping from a mapper.

    Parameters
    ----------
    mapper : :class:`.LigandAtomMapper`
        the mapper to use to generate the mapping
    molA, molB : :class:`.SmallMoleculeComponent`
        molecules to map between

    Returns
    ------
    :class:`.LigandAtomMapping` :
        the mapping generated by the mapper; errors if there is not exactly
        one mapping generated
    """
    mappings = list(mapper.suggest_mappings(molA, molB))
    if len(mappings) != 1:
        raise click.UsageError(
            f"Found {len(mappings)} mappings; this command requires a mapper "
            "to provide exactly 1 mapping"
        )
    return mappings[0]