diff --git a/chebi_utils/sdf_extractor.py b/chebi_utils/sdf_extractor.py index 5d961d7..98607e5 100644 --- a/chebi_utils/sdf_extractor.py +++ b/chebi_utils/sdf_extractor.py @@ -160,12 +160,14 @@ def extract_molecules(filepath: str | Path) -> pd.DataFrame: df["mol"] = [_parse_molblock(mb, cid) for mb, cid in zip(molblocks, chebi_ids, strict=False)] df["chebi_id"] = df["chebi_id"].apply(_chebi_id_to_str) - # exclude records without a valid mol, but keep the same columns for consistency + # exclude records without a valid molecule df = df[df["mol"].notna()] + # some molecule records are valid, but have no atoms (e.g. CHEBI:192499 in v251, cf. https://github.com/ebi-chebi/ChEBI/issues/4915) + df = df[[mol.GetNumAtoms() > 0 for mol in df["mol"]]] return df if __name__ == "__main__": - df = extract_molecules("data/chebi.sdf.gz") + df = extract_molecules("chebi.sdf.gz") print(df.head())