def score_compounds(db, compounds, model_id, parent_frac=0.75,
    reaction_frac=0.25):
    """This function validates compounds against a metabolic model, returning
    only the compounds which pass.

    Parameters
    ----------
    db : Mongo DB
        Should contain a "models" collection with compound and reaction IDs
        listed.
    compounds : list
        Each element is a dict describing that compound. Should have an '_id'
        field.
    model_id : str
        KEGG organism code (e.g. 'hsa').
    parent_frac : float, optional (default: 0.75)
        Weighting for compounds derived from compounds in the provided model.
    reaction_frac : float, optional (default: 0.25)
        Weighting for compounds derived from known compounds not in the model.

    Returns
    -------
    compounds : list
        Modified version of input compounds list, where each compound now has
        a 'Likelihood_score' key and value between 0 and 1.
    """
    if not model_id:
        return compounds
    model = db.models.find_one({'_id': model_id})
    if not model:
        return compounds
    parents = set(model['Compounds'])
    for comp in compounds:
        try:
            if set(comp['DB_links']['KEGG']) & parents:
                comp['Likelihood_score'] = parent_frac + reaction_frac
                continue
        except KeyError:
            pass
        if comp['Generation'] == 0:
            comp['Likelihood_score'] = reaction_frac
            continue
        comp['Likelihood_score'] = 0.0
        for source in comp['Sources']:
            likelihood_score = reaction_frac
            try:
                for s_comp in source['Compounds']:
                    if 'DB_links' in s_comp and 'KEGG' in s_comp['DB_links']:
                        if set(s_comp['DB_links']['KEGG']) & parents:
                            likelihood_score += parent_frac
            except KeyError:
                s_comp = source['Compound']
                if 'DB_links' in s_comp and 'KEGG' in s_comp['DB_links']:
                    if set(s_comp['DB_links']['KEGG']) & parents:
                        likelihood_score += parent_frac
            if likelihood_score > comp['Likelihood_score']:
                comp['Likelihood_score'] = likelihood_score
    return compounds
