def filter_mol_list_by_prop(mol_list, prop_key, prop_value, wanted=True):
  """Allows for filtering rdkit.Mol list based on property values.

  Args:
    mol_list : list of rdkit.Mol objects to filter
    prop_key : Name of tag in SDF file to filter on.
    prop_value : Value of tag in SDF file to filter on.
    wanted : if true, include values specified by prop_value
             if false, exclude values specified by prop_value
  Returns:
    a filtered mol list.
  """
  if wanted:
    return [
        mol for mol in mol_list
        if mol.HasProp(prop_key) and prop_value in mol.GetProp(prop_key)
    ]
  else:
    return [
        mol for mol in mol_list
        if not mol.HasProp(prop_key) or prop_value not in mol.GetProp(prop_key)
    ]