simonduerr commited on
Commit
b8836f0
1 Parent(s): d1603c7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +73 -70
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
- jobname = re.sub(r'[<>:"/\\|?*]', '_', jobname)
42
- if jobname == "":
43
- raise gr.Error("Job name empty or only invalid characters. Choose a plaintext name.")
44
- os.makedirs(jobname, exist_ok=True)
45
- """format Gradio Component:
46
- # {"chains": [
47
- # {
48
- # "class": "DNA",
49
- # "sequence": "ATGCGT",
50
- # "chain": "A"
51
- # }
52
- # ], "covMods":[]
53
- # }
54
- """
55
- #sequences_for_msa = []
56
- output = {
57
- "sequences": []
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
- if entity_type in ["protein", "dna", "rna"]:
68
- sequence_data[entity_type]["sequence"] = chain["sequence"]
69
- if entity_type == "protein":
70
- #sequences_for_msa.append(chain["sequence"])
71
- if chain["msa"] == False:
72
- sequence_data[entity_type]["msa"] = f"empty"
73
- representations.append({"model":0, "chain":chain["chain"], "style":"cartoon"})
74
- if entity_type == "ligand":
75
- if "sdf" in chain.keys():
76
- if chain["sdf"]!="" and chain["name"]=="":
77
- raise gr.Error("Sorry, no SDF support yet.")
78
- if "name" in chain.keys() and len(chain["name"])==3:
79
- sequence_data[entity_type]["ccd"] = chain["name"]
80
- elif "smiles" in chain.keys():
81
- sequence_data[entity_type]["smiles"] = chain["smiles"]
82
- else:
83
- raise gr.Error("No ligand found, or not in the right format. CCD codes have 3 letters")
84
-
85
-
86
- representations.append({"model":0, "chain":chain["chain"], "style":"stick", "color":"greenCarbon"})
87
-
88
- if len(inputs["covMods"])>0:
89
- raise gr.Error("Sorry, covMods not supported yet. Coming soon. ")
90
- output["sequences"].append(sequence_data)
91
-
92
- # Convert the output to YAML
93
- yaml_file_path = f"{jobname}/{jobname}.yaml"
94
-
95
- # Write the YAML output to the file
96
- with open(yaml_file_path, "w") as file:
97
- yaml.dump(output, file, sort_keys=False, default_flow_style=False)
98
-
99
- os.system(f"cat {yaml_file_path}")
100
- #a3m_lines_mmseqs2 = run_mmseqs2(
101
- # sequences_for_msa,
102
- # f"./{jobname}",
103
- # use_templates=False,
104
- # )
105
- #with open(f"{jobname}/msa.a3m", "w+") as fp:
106
- # fp.writelines(a3m_lines_mmseqs2)
107
-
108
- 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")
109
- print(os.listdir(jobname))
110
- print(os.listdir(f"{jobname}/boltz_results_{jobname}/predictions/{jobname}/"))
111
- return Molecule3D(f"{jobname}/boltz_results_{jobname}/predictions/{jobname}/{jobname}_model_0.pdb", label="Output", reps=representations)
 
 
 
 
 
 
 
 
 
 
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")