Download scripts/summarize_motifbench.py from HFMI-PROFOUND/BILBY-PRO: direct link, hf CLI and curl.
- Browser
- Download file 3.24 kB
-
https://huggingface.co/datasets/HFMI-PROFOUND/BILBY-PRO/resolve/main/scripts/summarize_motifbench.py
- Command line
-
hf download hf://datasets/HFMI-PROFOUND/BILBY-PRO/scripts/summarize_motifbench.py
-
curl -L -o summarize_motifbench.py https://huggingface.co/datasets/HFMI-PROFOUND/BILBY-PRO/resolve/main/scripts/summarize_motifbench.py
3.24 kB
| #!/usr/bin/env python3 | |
| # Copyright 2026 Emile de Bruyn | |
| # SPDX-License-Identifier: Apache-2.0 | |
| """Reorder MotifBench's case summary before running its group-summary script.""" | |
| import argparse | |
| import csv | |
| import importlib.util | |
| from pathlib import Path | |
| def main(): | |
| parser = argparse.ArgumentParser(description=__doc__) | |
| parser.add_argument("work", type=Path, help="prepared MotifBench working directory") | |
| parser.add_argument("results", type=Path, help="evaluation output directory") | |
| args = parser.parse_args() | |
| with (args.work / "test_cases.csv").open(newline="") as handle: | |
| cases = list(csv.DictReader(handle)) | |
| order = {f"{i:02d}_{row['pdb_id']}": i for i, row in enumerate(cases, 1)} | |
| with (args.results / "summary_by_problem.csv").open(newline="") as handle: | |
| reader = csv.DictReader(handle) | |
| fields, rows = reader.fieldnames, list(reader) | |
| if not rows: | |
| raise ValueError("the upstream summary contains no cases") | |
| names = [row["Problem"] for row in rows] | |
| if len(set(names)) != len(names) or any(name not in order for name in names): | |
| raise ValueError("summary contains duplicate or unknown case names") | |
| for row in rows: | |
| if int(row["Num_Evaluated"]) != 100: | |
| raise ValueError(f"{row['Problem']}: upstream score assumes 100 evaluated designs") | |
| cluster = args.results / row["Problem"] / "esm_successful_backbones/diversity_cluster.tsv" | |
| if int(row["Num_Solutions"]) > 0 and not cluster.is_file(): | |
| raise FileNotFoundError(f"missing diversity clusters: {cluster}") | |
| ordered = args.results / "summary_by_problem_ordered.csv" | |
| overall = args.results / "overall_summary_ordered.csv" | |
| if ordered.exists() or overall.exists(): | |
| raise FileExistsError("ordered summary output already exists") | |
| rows.sort(key=lambda row: order[row["Problem"]]) | |
| with ordered.open("x", newline="") as handle: | |
| writer = csv.DictWriter(handle, fieldnames=fields) | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| source = args.work / "scripts/write_overall_summary.py" | |
| module_spec = importlib.util.spec_from_file_location("motifbench_summary", source) | |
| if module_spec is None or module_spec.loader is None: | |
| raise ImportError(f"cannot load MotifBench summary module: {source}") | |
| module = importlib.util.module_from_spec(module_spec) | |
| module_spec.loader.exec_module(module) | |
| module.np.random.seed(0) | |
| module.main(str(args.work / "test_cases.csv"), str(ordered), str(overall)) | |
| module.np.random.seed(0) | |
| for row in rows: | |
| cluster = module.diversity_cluster_path(str(args.results), row["Problem"]) | |
| successes = module.load_successes_and_cluster(cluster) | |
| row["overall_score"] = module.MBScore_boostrap(successes)[0] | |
| with ordered.open("w", newline="") as handle: | |
| writer = csv.DictWriter(handle, fieldnames=fields + ["overall_score"]) | |
| writer.writeheader() | |
| writer.writerows(rows) | |
| print(f"Summarized {len(rows)}/{len(cases)} cases in {ordered} and {overall}.") | |
| if len(rows) != len(cases): | |
| print("Warning: this is a partial benchmark summary, not a full BILBY-PRO score.") | |
| if __name__ == "__main__": | |
| main() | |