|
| 1 | +import subprocess |
| 2 | +import sys |
| 3 | +import os |
| 4 | +import pytest |
| 5 | +from pathlib import Path |
| 6 | + |
| 7 | +TEST_DIR = Path(__file__).resolve().parent |
| 8 | +PROJECT_ROOT = (TEST_DIR / "..").resolve() |
| 9 | + |
| 10 | +DEFAULT_CKPT = "weights/train_session2024-07-08_1720455712_BFF_3.00.pt" |
| 11 | + |
| 12 | +# Path to rf_diffusion/run_inference.py |
| 13 | +RUN_INFERENCE = PROJECT_ROOT / "rf_diffusion" / "run_inference.py" |
| 14 | +SCENARIOS = [ |
| 15 | + ( |
| 16 | + "rna_unconditional", |
| 17 | + [ |
| 18 | + "diffuser.T=50", |
| 19 | + "inference.num_designs=1", |
| 20 | + "contigmap.contigs=['9']", |
| 21 | + "contigmap.polymer_chains=['rna']", |
| 22 | + "inference.output_prefix=demo_outputs/RNA_uncond_standard_settings", |
| 23 | + ], |
| 24 | + ), |
| 25 | + ( |
| 26 | + "multi_polymer_unconditional", |
| 27 | + [ |
| 28 | + "diffuser.T=50", |
| 29 | + "inference.num_designs=1", |
| 30 | + "contigmap.contigs=['3 3 3']", |
| 31 | + "contigmap.polymer_chains=['dna','rna','protein']", |
| 32 | + "inference.output_prefix=test_outputs/basic_uncond_test01", |
| 33 | + ], |
| 34 | + ), |
| 35 | + ( |
| 36 | + "dna_binder_unconditional", |
| 37 | + [ |
| 38 | + "diffuser.T=50", |
| 39 | + "inference.num_designs=1", |
| 40 | + "contigmap.contigs=['2 2 5']", |
| 41 | + "contigmap.polymer_chains=['dna','dna','protein']", |
| 42 | + "inference.output_prefix=demo_outputs/DNA_prot_uncond_standard_settings", |
| 43 | + ], |
| 44 | + ), |
| 45 | + ( |
| 46 | + "rna_secondary_structure", |
| 47 | + [ |
| 48 | + "diffuser.T=50", |
| 49 | + "inference.num_designs=1", |
| 50 | + "contigmap.contigs=['9']", |
| 51 | + "contigmap.polymer_chains=['rna']", |
| 52 | + "scaffoldguided.target_ss_string=555...333", |
| 53 | + ], |
| 54 | + ), |
| 55 | + ( |
| 56 | + "motif_scaffolding_v1", |
| 57 | + [ |
| 58 | + "diffuser.T=50", |
| 59 | + "inference.num_designs=1", |
| 60 | + "contigmap.contigs=['1,D8-10,1,B8-10,1 1,B18-20,1,D18-20,1 A1-3,0 C1-3,0']", |
| 61 | + "contigmap.polymer_chains=['dna','dna','protein','protein']", |
| 62 | + "inference.ij_visible=bce-adf", |
| 63 | + "inference.input_pdb=test_data/combo_DBP009_DBP010_DBP011_with_DNA_v2.pdb", |
| 64 | + "inference.output_prefix=demo_outputs/DNA_binders_scaffolding_test1_standard_settings", |
| 65 | + ], |
| 66 | + ), |
| 67 | + ( |
| 68 | + "motif_scaffolding_v2", |
| 69 | + [ |
| 70 | + "diffuser.T=50", |
| 71 | + "inference.num_designs=1", |
| 72 | + "contigmap.contigs=['1,D8-10,1,B8-10,1 1,B18-20,1,D18-20,1 A1-3,3,C1-3,0']", |
| 73 | + "contigmap.polymer_chains=['dna','dna','protein']", |
| 74 | + "scaffoldguided.target_ss_pairs=[\"A1-9,B1-9\"]", |
| 75 | + "inference.ij_visible=bce-adf", |
| 76 | + "inference.input_pdb=test_data/combo_DBP009_DBP010_DBP011_with_DNA_v2.pdb", |
| 77 | + "inference.output_prefix=demo_outputs/DNA_binders_scaffolding_test2_standard_settings", |
| 78 | + ], |
| 79 | + ), |
| 80 | + ( |
| 81 | + "dna_pair_specification", |
| 82 | + [ |
| 83 | + "diffuser.T=50", |
| 84 | + "inference.num_designs=1", |
| 85 | + "contigmap.contigs=['6 6 6 6']", |
| 86 | + "contigmap.polymer_chains=['dna','dna','dna','dna']", |
| 87 | + "scaffoldguided.target_ss_pairs=['A1-2,B1-2','A3-4,C3-4','A5-6,D5-6','B3-4,D3-4','B5-6,C5-6','C1-2,D1-2']", |
| 88 | + "inference.symmetry=d2", |
| 89 | + "inference.output_prefix=demo_outputs/DNA_origami_standard_settings", |
| 90 | + ], |
| 91 | + ), |
| 92 | +] |
| 93 | + |
| 94 | + |
| 95 | +@pytest.mark.parametrize("name, overrides", SCENARIOS) |
| 96 | +def test_multi_polymer_scenarios(name, overrides): |
| 97 | + """ |
| 98 | + Runs rf_diffusion/run_inference.py via subprocess for each scenario |
| 99 | + """ |
| 100 | + # set path to weights, assuming weights have been downloaded in root directory |
| 101 | + os.environ.setdefault("RFDPOLY_CKPT_PATH", DEFAULT_CKPT) |
| 102 | + |
| 103 | + # Build the command |
| 104 | + cmd = [ |
| 105 | + sys.executable, |
| 106 | + str(RUN_INFERENCE), |
| 107 | + # Include this if your Hydra app requires an explicit config name. |
| 108 | + # If run_inference.py already sets config_name in @hydra.main, you |
| 109 | + # can remove the two lines below. |
| 110 | + "--config-name", |
| 111 | + "multi_polymer", |
| 112 | + *overrides, |
| 113 | + ] |
| 114 | + |
| 115 | + result = subprocess.run( |
| 116 | + cmd, |
| 117 | + cwd=str(PROJECT_ROOT), |
| 118 | + capture_output=True, |
| 119 | + text=True, |
| 120 | + ) |
| 121 | + |
| 122 | + # Debug info if something fails |
| 123 | + if result.returncode != 0: |
| 124 | + print(f"\n=== Scenario {name} failed ===") |
| 125 | + print("STDOUT:\n", result.stdout) |
| 126 | + print("STDERR:\n", result.stderr) |
| 127 | + |
| 128 | + assert result.returncode == 0 |
| 129 | + |
0 commit comments