Spaces:
Running
on
Zero
Running
on
Zero
move generation scripts to pipelines, only download rfd3, create output directory for run
Browse files- app.py +1 -65
- utils/__init__.py +1 -0
- utils/download_weights.py +2 -1
- utils/pipelines.py +75 -0
app.py
CHANGED
|
@@ -9,44 +9,11 @@ from atomworks.io.utils.visualize import view
|
|
| 9 |
from lightning.fabric import seed_everything
|
| 10 |
from rfd3.engine import RFD3InferenceConfig, RFD3InferenceEngine
|
| 11 |
from utils import download_weights
|
|
|
|
| 12 |
|
| 13 |
|
| 14 |
download_weights()
|
| 15 |
|
| 16 |
-
|
| 17 |
-
|
| 18 |
-
@spaces.GPU(duration=300)
|
| 19 |
-
def test_rfd3_from_notebook():
|
| 20 |
-
# Set seed for reproducibility
|
| 21 |
-
seed_everything(0)
|
| 22 |
-
|
| 23 |
-
# Configure RFD3 inference
|
| 24 |
-
config = RFD3InferenceConfig(
|
| 25 |
-
specification={
|
| 26 |
-
'length': 40, # Generate 80-residue proteins
|
| 27 |
-
},
|
| 28 |
-
diffusion_batch_size=2, # Generate 2 structures per batch
|
| 29 |
-
)
|
| 30 |
-
|
| 31 |
-
# Initialize engine and run generation
|
| 32 |
-
try:
|
| 33 |
-
model = RFD3InferenceEngine(**config)
|
| 34 |
-
outputs = model.run(
|
| 35 |
-
inputs=None, # None for unconditional generation
|
| 36 |
-
out_dir=None, # None to return in memory (no file output)
|
| 37 |
-
n_batches=1, # Generate 1 batch
|
| 38 |
-
)
|
| 39 |
-
return_str = "RDF3 test passed! Generated structures:\n"
|
| 40 |
-
|
| 41 |
-
for idx, data in outputs.items():
|
| 42 |
-
return_str += f"Batch {idx}: {len(data)} structure(s)\n"
|
| 43 |
-
for i, struct in enumerate(data):
|
| 44 |
-
return_str += f"Structure {i+1}: {struct.atom_array.array_length()} Atoms\n"
|
| 45 |
-
#return_str += struct.atom_array
|
| 46 |
-
return return_str
|
| 47 |
-
except Exception as e:
|
| 48 |
-
return f"Error: {str(e)}"
|
| 49 |
-
|
| 50 |
|
| 51 |
# Gradio UI
|
| 52 |
with gr.Blocks(title="RFD3 Test") as demo:
|
|
@@ -82,38 +49,7 @@ with gr.Blocks(title="RFD3 Test") as demo:
|
|
| 82 |
minimum=10,
|
| 83 |
maximum=200
|
| 84 |
)
|
| 85 |
-
# Configure RFD3 inference
|
| 86 |
-
|
| 87 |
-
|
| 88 |
-
# Initialize engine and run generation
|
| 89 |
-
@spaces.GPU(duration=300)
|
| 90 |
-
def unconditional_generation(num_batches, num_designs_per_batch, length):
|
| 91 |
-
|
| 92 |
-
config = RFD3InferenceConfig(
|
| 93 |
-
specification={
|
| 94 |
-
'length': length,
|
| 95 |
-
},
|
| 96 |
-
diffusion_batch_size=num_designs_per_batch, # Generate 2 structures per batch
|
| 97 |
-
)
|
| 98 |
-
try:
|
| 99 |
-
model = RFD3InferenceEngine(**config)
|
| 100 |
-
outputs = model.run(
|
| 101 |
-
inputs=None, # None for unconditional generation
|
| 102 |
-
out_dir=None, # None to return in memory (no file output)
|
| 103 |
-
n_batches=num_batches, # Generate 1 batch
|
| 104 |
-
)
|
| 105 |
-
return_str = "RDF3 test passed! Generated structures:\n"
|
| 106 |
|
| 107 |
-
for idx, data in outputs.items():
|
| 108 |
-
return_str += f"Batch {idx}: {len(data)} structure(s)\n"
|
| 109 |
-
for i, struct in enumerate(data):
|
| 110 |
-
return_str += f"Structure {i+1}: {struct.atom_array.array_length()} Atoms\n"
|
| 111 |
-
#return_str += struct.atom_array
|
| 112 |
-
return return_str
|
| 113 |
-
|
| 114 |
-
except Exception as e:
|
| 115 |
-
return f"Error: {str(e)}"
|
| 116 |
-
|
| 117 |
gen_btn = gr.Button("Run Unconditional Generation")
|
| 118 |
gen_output = gr.Textbox(label="Generation Result")
|
| 119 |
gen_btn.click(unconditional_generation, inputs=[num_batches, num_designs_per_batch, length], outputs=gen_output)
|
|
|
|
| 9 |
from lightning.fabric import seed_everything
|
| 10 |
from rfd3.engine import RFD3InferenceConfig, RFD3InferenceEngine
|
| 11 |
from utils import download_weights
|
| 12 |
+
from utils.pipelines import test_rfd3_from_notebook, unconditional_generation
|
| 13 |
|
| 14 |
|
| 15 |
download_weights()
|
| 16 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 17 |
|
| 18 |
# Gradio UI
|
| 19 |
with gr.Blocks(title="RFD3 Test") as demo:
|
|
|
|
| 49 |
minimum=10,
|
| 50 |
maximum=200
|
| 51 |
)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 52 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 53 |
gen_btn = gr.Button("Run Unconditional Generation")
|
| 54 |
gen_output = gr.Textbox(label="Generation Result")
|
| 55 |
gen_btn.click(unconditional_generation, inputs=[num_batches, num_designs_per_batch, length], outputs=gen_output)
|
utils/__init__.py
CHANGED
|
@@ -1,3 +1,4 @@
|
|
| 1 |
from utils.download_weights import *
|
|
|
|
| 2 |
|
| 3 |
__all__ = ["download_weights"]
|
|
|
|
| 1 |
from utils.download_weights import *
|
| 2 |
+
from utils.pipelines import *
|
| 3 |
|
| 4 |
__all__ = ["download_weights"]
|
utils/download_weights.py
CHANGED
|
@@ -2,7 +2,8 @@ import subprocess
|
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
| 4 |
|
| 5 |
-
MODELS = ["rfd3", "ligandmpnn", "rf3"]
|
|
|
|
| 6 |
|
| 7 |
|
| 8 |
# foundry is a package installed automatically upon Space initialization through the Gradio SDK because it is listed in requirements.txt.
|
|
|
|
| 2 |
import os
|
| 3 |
from pathlib import Path
|
| 4 |
|
| 5 |
+
#MODELS = ["rfd3", "ligandmpnn", "rf3"]
|
| 6 |
+
MODELS = ["rfd3"]
|
| 7 |
|
| 8 |
|
| 9 |
# foundry is a package installed automatically upon Space initialization through the Gradio SDK because it is listed in requirements.txt.
|
utils/pipelines.py
ADDED
|
@@ -0,0 +1,75 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
from rfd3.engine import RFD3InferenceConfig, RFD3InferenceEngine
|
| 2 |
+
import gradio as gr
|
| 3 |
+
from lightning.fabric import seed_everything
|
| 4 |
+
import time
|
| 5 |
+
import os
|
| 6 |
+
|
| 7 |
+
|
| 8 |
+
@spaces.GPU(duration=300)
|
| 9 |
+
def test_rfd3_from_notebook():
|
| 10 |
+
# Set seed for reproducibility
|
| 11 |
+
seed_everything(0)
|
| 12 |
+
|
| 13 |
+
# Configure RFD3 inference
|
| 14 |
+
config = RFD3InferenceConfig(
|
| 15 |
+
specification={
|
| 16 |
+
'length': 40, # Generate 80-residue proteins
|
| 17 |
+
},
|
| 18 |
+
diffusion_batch_size=2, # Generate 2 structures per batch
|
| 19 |
+
)
|
| 20 |
+
|
| 21 |
+
# Initialize engine and run generation
|
| 22 |
+
try:
|
| 23 |
+
model = RFD3InferenceEngine(**config)
|
| 24 |
+
outputs = model.run(
|
| 25 |
+
inputs=None, # None for unconditional generation
|
| 26 |
+
out_dir=None, # None to return in memory (no file output)
|
| 27 |
+
n_batches=1, # Generate 1 batch
|
| 28 |
+
)
|
| 29 |
+
return_str = "RDF3 test passed! Generated structures:\n"
|
| 30 |
+
|
| 31 |
+
for idx, data in outputs.items():
|
| 32 |
+
return_str += f"Batch {idx}: {len(data)} structure(s)\n"
|
| 33 |
+
for i, struct in enumerate(data):
|
| 34 |
+
return_str += f"Structure {i+1}: {struct.atom_array.array_length()} Atoms\n"
|
| 35 |
+
#return_str += struct.atom_array
|
| 36 |
+
return return_str
|
| 37 |
+
except Exception as e:
|
| 38 |
+
return f"Error: {str(e)}"
|
| 39 |
+
|
| 40 |
+
|
| 41 |
+
|
| 42 |
+
# Initialize engine and run generation
|
| 43 |
+
@spaces.GPU(duration=300)
|
| 44 |
+
def unconditional_generation(num_batches, num_designs_per_batch, length):
|
| 45 |
+
|
| 46 |
+
config = RFD3InferenceConfig(
|
| 47 |
+
specification={
|
| 48 |
+
'length': length,
|
| 49 |
+
},
|
| 50 |
+
diffusion_batch_size=num_designs_per_batch, # Generate 2 structures per batch
|
| 51 |
+
)
|
| 52 |
+
|
| 53 |
+
session_hash = gr.Request.session_hash
|
| 54 |
+
time_stamp = time.strftime("%Y-%m-%d-%H-%M-%S")
|
| 55 |
+
directory = f"./outputs/session_{session_hash}_{time_stamp}"
|
| 56 |
+
os.makedirs(directory, exist_ok=False)
|
| 57 |
+
|
| 58 |
+
|
| 59 |
+
try:
|
| 60 |
+
model = RFD3InferenceEngine(**config)
|
| 61 |
+
outputs = model.run(
|
| 62 |
+
inputs=None, # None for unconditional generation
|
| 63 |
+
out_dir=directory, # None to return in memory (no file output)
|
| 64 |
+
n_batches=num_batches, # Generate 1 batch
|
| 65 |
+
)
|
| 66 |
+
|
| 67 |
+
#for idx, data in outputs.items():
|
| 68 |
+
# return_str += f"Batch {idx}: {len(data)} structure(s)\n"
|
| 69 |
+
# for i, struct in enumerate(data):
|
| 70 |
+
# return_str += f"Structure {i+1}: {struct.atom_array.array_length()} Atoms\n"
|
| 71 |
+
# #return_str += struct.atom_array
|
| 72 |
+
return directory
|
| 73 |
+
|
| 74 |
+
except Exception as e:
|
| 75 |
+
return f"Error: {str(e)}"
|