Spaces:
Running
on
L4
Running
on
L4
Update app.py
Browse files
app.py
CHANGED
|
@@ -6,8 +6,11 @@ from gradio_molecule3d import Molecule3D
|
|
| 6 |
from gradio_cofoldinginput import CofoldingInput
|
| 7 |
|
| 8 |
import os
|
|
|
|
| 9 |
import urllib.request
|
| 10 |
|
|
|
|
|
|
|
| 11 |
CCD_URL = "https://huggingface.co/boltz-community/boltz-1/resolve/main/ccd.pkl"
|
| 12 |
MODEL_URL = "https://huggingface.co/boltz-community/boltz-1/resolve/main/boltz1.ckpt"
|
| 13 |
|
|
@@ -34,12 +37,76 @@ if not os.path.exists(model):
|
|
| 34 |
|
| 35 |
@spaces.GPU(duration=120)
|
| 36 |
def predict(jobname, inputs, recycling_steps, sampling_steps, diffusion_samples):
|
| 37 |
-
|
| 38 |
-
os.
|
| 39 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 40 |
|
| 41 |
with gr.Blocks() as blocks:
|
| 42 |
gr.Markdown("# Boltz-1")
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
with gr.Tab("Main"):
|
| 44 |
jobname = gr.Textbox(label="Jobname")
|
| 45 |
inp = CofoldingInput(label="Input")
|
|
|
|
| 6 |
from gradio_cofoldinginput import CofoldingInput
|
| 7 |
|
| 8 |
import os
|
| 9 |
+
import re
|
| 10 |
import urllib.request
|
| 11 |
|
| 12 |
+
from msa import run_mmseqs2
|
| 13 |
+
|
| 14 |
CCD_URL = "https://huggingface.co/boltz-community/boltz-1/resolve/main/ccd.pkl"
|
| 15 |
MODEL_URL = "https://huggingface.co/boltz-community/boltz-1/resolve/main/boltz1.ckpt"
|
| 16 |
|
|
|
|
| 37 |
|
| 38 |
@spaces.GPU(duration=120)
|
| 39 |
def predict(jobname, inputs, recycling_steps, sampling_steps, diffusion_samples):
|
| 40 |
+
jobname = re.sub(r'[<>:"/\\|?*]', '_', jobname)
|
| 41 |
+
os.makedirs(jobname)
|
| 42 |
+
"""format Gradio Component:
|
| 43 |
+
# {"chains": [
|
| 44 |
+
# {
|
| 45 |
+
# "class": "DNA",
|
| 46 |
+
# "sequence": "ATGCGT",
|
| 47 |
+
# "chain": "A"
|
| 48 |
+
# }
|
| 49 |
+
# ], "covMods":[]
|
| 50 |
+
# }
|
| 51 |
+
"""
|
| 52 |
+
sequences_for_msa = []
|
| 53 |
+
for chain in inputs["chains"]:
|
| 54 |
+
entity_type = chain["class"].lower()
|
| 55 |
+
sequence_data = {
|
| 56 |
+
entity_type: {
|
| 57 |
+
"id": chain["chain"],
|
| 58 |
+
}
|
| 59 |
+
}
|
| 60 |
+
if entity_type in ["protein", "dna", "rna"]:
|
| 61 |
+
sequence_data[entity_type]["sequence"] = chain["sequence"]
|
| 62 |
+
if entity_type == "protein":
|
| 63 |
+
sequences_for_msa.append(chain["sequence"])
|
| 64 |
+
sequence_data[entity_type]["msa"] = f"{jobname}/msa.a3m"
|
| 65 |
+
if entity_type == "ligand":
|
| 66 |
+
if "sdf" in chains.keys():
|
| 67 |
+
raise gr.Error("Sorry no SDF support yet")
|
| 68 |
+
if "name" in chains.keys():
|
| 69 |
+
sequence_data[entity_type]["ccd"] = chains["name"]
|
| 70 |
+
if "smiles" in chains.keys():
|
| 71 |
+
sequence_data[entity_type]["smiles"] = chains["smiles"]
|
| 72 |
+
|
| 73 |
+
if len(inputs["covMods"])>0:
|
| 74 |
+
raise gr.Error("Sorry, covMods not supported yet. Coming soon. ")
|
| 75 |
+
output["sequences"].append(sequence_data)
|
| 76 |
+
|
| 77 |
+
# Convert the output to YAML
|
| 78 |
+
yaml_file_path = f"{jobname}/{jobname}.yaml"
|
| 79 |
+
|
| 80 |
+
# Write the YAML output to the file
|
| 81 |
+
with open(yaml_file_path, "w") as file:
|
| 82 |
+
yaml.dump(output, file, sort_keys=False, default_flow_style=False)
|
| 83 |
+
|
| 84 |
+
os.system(f"cat {yaml_file_path}")
|
| 85 |
+
a3m_lines_mmseqs2 = run_mmseqs2(
|
| 86 |
+
sequences_for_msa,
|
| 87 |
+
"./",
|
| 88 |
+
use_templates=False,
|
| 89 |
+
)
|
| 90 |
+
with open(f"{jobname}/msa.a3m", "w+") as fp:
|
| 91 |
+
fp.writelines(a3m_lines_mmseqs2)
|
| 92 |
+
|
| 93 |
+
os.system(f"boltz predict {jobname}/{jobname}.yaml --out_dir {jobname} --recycling_steps {recycling_steps} --sampling_steps {sampling_steps} --diffusion_samples {diffusion_samples} --override --output_format pdb")
|
| 94 |
+
print(os.listdir(jobname))
|
| 95 |
+
print(os.listdir(f"{jobname}/boltz_results_{jobname}/predictions/{jobname}/"))
|
| 96 |
+
return f"{jobname}/boltz_results_{jobname}/predictions/{jobname}/{jobname}_model_0.pdb"
|
| 97 |
|
| 98 |
with gr.Blocks() as blocks:
|
| 99 |
gr.Markdown("# Boltz-1")
|
| 100 |
+
gr.Markdown("""Open GUI for running [Boltz-1 model](https://github.com/jwohlwend/boltz/) <br>
|
| 101 |
+
Key components:
|
| 102 |
+
- MMSeqs2 Webserver Mirdita et al.
|
| 103 |
+
- Boltz-1 Model Wohlwend et al.
|
| 104 |
+
- Gradio Custom Components Molecule3D/Cofolding Input Dürr S.
|
| 105 |
+
- 3dmol.js Rego & Koes
|
| 106 |
+
|
| 107 |
+
Note: This is an alpha: Some things like covalent modifications or using sdf files don't work yet. You can a Docker image of this on your local infrastructure easily using:
|
| 108 |
+
`docker run -it -p 7860:7860 --platform=linux/amd64 --gpus all registry.hf.space/simonduerr-boltz-1:latest python app.py`
|
| 109 |
+
""")
|
| 110 |
with gr.Tab("Main"):
|
| 111 |
jobname = gr.Textbox(label="Jobname")
|
| 112 |
inp = CofoldingInput(label="Input")
|