Spaces:
Running
on
L4
Running
on
L4
simonduerr
commited on
Commit
•
b8836f0
1
Parent(s):
d1603c7
Update app.py
Browse files
app.py
CHANGED
@@ -38,77 +38,80 @@ if not os.path.exists(model):
|
|
38 |
|
39 |
@spaces.GPU(duration=120)
|
40 |
def predict(jobname, inputs, recycling_steps, sampling_steps, diffusion_samples):
|
41 |
-
|
42 |
-
|
43 |
-
|
44 |
-
|
45 |
-
|
46 |
-
|
47 |
-
|
48 |
-
|
49 |
-
|
50 |
-
|
51 |
-
|
52 |
-
|
53 |
-
|
54 |
-
|
55 |
-
|
56 |
-
|
57 |
-
|
58 |
-
|
59 |
-
representations = []
|
60 |
-
for chain in inputs["chains"]:
|
61 |
-
entity_type = chain["class"].lower()
|
62 |
-
sequence_data = {
|
63 |
-
entity_type: {
|
64 |
-
"id": chain["chain"],
|
65 |
-
}
|
66 |
}
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
if "
|
76 |
-
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
|
81 |
-
|
82 |
-
|
83 |
-
|
84 |
-
|
85 |
-
|
86 |
-
|
87 |
-
|
88 |
-
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
-
|
94 |
-
|
95 |
-
|
96 |
-
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
-
|
101 |
-
|
102 |
-
|
103 |
-
|
104 |
-
|
105 |
-
|
106 |
-
|
107 |
-
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
112 |
|
113 |
with gr.Blocks() as blocks:
|
114 |
gr.Markdown("# Boltz-1")
|
|
|
38 |
|
39 |
@spaces.GPU(duration=120)
|
40 |
def predict(jobname, inputs, recycling_steps, sampling_steps, diffusion_samples):
|
41 |
+
try:
|
42 |
+
jobname = re.sub(r'[<>:"/\\|?*]', '_', jobname)
|
43 |
+
if jobname == "":
|
44 |
+
raise gr.Error("Job name empty or only invalid characters. Choose a plaintext name.")
|
45 |
+
os.makedirs(jobname, exist_ok=True)
|
46 |
+
"""format Gradio Component:
|
47 |
+
# {"chains": [
|
48 |
+
# {
|
49 |
+
# "class": "DNA",
|
50 |
+
# "sequence": "ATGCGT",
|
51 |
+
# "chain": "A"
|
52 |
+
# }
|
53 |
+
# ], "covMods":[]
|
54 |
+
# }
|
55 |
+
"""
|
56 |
+
#sequences_for_msa = []
|
57 |
+
output = {
|
58 |
+
"sequences": []
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
59 |
}
|
60 |
+
representations = []
|
61 |
+
for chain in inputs["chains"]:
|
62 |
+
entity_type = chain["class"].lower()
|
63 |
+
sequence_data = {
|
64 |
+
entity_type: {
|
65 |
+
"id": chain["chain"],
|
66 |
+
}
|
67 |
+
}
|
68 |
+
if entity_type in ["protein", "dna", "rna"]:
|
69 |
+
sequence_data[entity_type]["sequence"] = chain["sequence"]
|
70 |
+
if entity_type == "protein":
|
71 |
+
#sequences_for_msa.append(chain["sequence"])
|
72 |
+
if chain["msa"] == False:
|
73 |
+
sequence_data[entity_type]["msa"] = f"empty"
|
74 |
+
representations.append({"model":0, "chain":chain["chain"], "style":"cartoon"})
|
75 |
+
if entity_type == "ligand":
|
76 |
+
if "sdf" in chain.keys():
|
77 |
+
if chain["sdf"]!="" and chain["name"]=="":
|
78 |
+
raise gr.Error("Sorry, no SDF support yet.")
|
79 |
+
if "name" in chain.keys() and len(chain["name"])==3:
|
80 |
+
sequence_data[entity_type]["ccd"] = chain["name"]
|
81 |
+
elif "smiles" in chain.keys():
|
82 |
+
sequence_data[entity_type]["smiles"] = chain["smiles"]
|
83 |
+
else:
|
84 |
+
raise gr.Error("No ligand found, or not in the right format. CCD codes have 3 letters")
|
85 |
+
|
86 |
+
|
87 |
+
representations.append({"model":0, "chain":chain["chain"], "style":"stick", "color":"greenCarbon"})
|
88 |
+
|
89 |
+
if len(inputs["covMods"])>0:
|
90 |
+
raise gr.Error("Sorry, covMods not supported yet. Coming soon. ")
|
91 |
+
output["sequences"].append(sequence_data)
|
92 |
+
|
93 |
+
# Convert the output to YAML
|
94 |
+
yaml_file_path = f"{jobname}/{jobname}.yaml"
|
95 |
+
|
96 |
+
# Write the YAML output to the file
|
97 |
+
with open(yaml_file_path, "w") as file:
|
98 |
+
yaml.dump(output, file, sort_keys=False, default_flow_style=False)
|
99 |
+
|
100 |
+
os.system(f"cat {yaml_file_path}")
|
101 |
+
#a3m_lines_mmseqs2 = run_mmseqs2(
|
102 |
+
# sequences_for_msa,
|
103 |
+
# f"./{jobname}",
|
104 |
+
# use_templates=False,
|
105 |
+
# )
|
106 |
+
#with open(f"{jobname}/msa.a3m", "w+") as fp:
|
107 |
+
# fp.writelines(a3m_lines_mmseqs2)
|
108 |
+
|
109 |
+
os.system(f"boltz predict {jobname}/{jobname}.yaml --use_msa_server --out_dir {jobname} --recycling_steps {recycling_steps} --sampling_steps {sampling_steps} --diffusion_samples {diffusion_samples} --override --output_format pdb")
|
110 |
+
print(os.listdir(jobname))
|
111 |
+
print(os.listdir(f"{jobname}/boltz_results_{jobname}/predictions/{jobname}/"))
|
112 |
+
return Molecule3D(f"{jobname}/boltz_results_{jobname}/predictions/{jobname}/{jobname}_model_0.pdb", label="Output", reps=representations)
|
113 |
+
except Exception as e:
|
114 |
+
raise gr.Error(f"failed with error:{e}")
|
115 |
|
116 |
with gr.Blocks() as blocks:
|
117 |
gr.Markdown("# Boltz-1")
|