gabboud commited on
Commit
b8f3849
·
1 Parent(s): 17127b6

fix results dict in new pipeline, remove double tab logic for config

Browse files
Files changed (3) hide show
  1. app.py +26 -59
  2. utils/handle_events.py +15 -21
  3. utils/pipelines.py +2 -2
app.py CHANGED
@@ -38,9 +38,6 @@ with gr.Blocks(title="RFD3 Test") as demo:
38
 
39
  gr.Image("assets/overview_rfd3_baker.png", width=600)
40
 
41
-
42
-
43
- tab_selected = gr.State("upload") # which tab is selected on the left
44
  config_ready = gr.State(None) # whether the config is ready for running generation, takes values None, "manual", or "upload"
45
  scaffold_ready = gr.State(None) # whether the scaffold is ready for running generation, takes values None, "upload", or "no_input"
46
  gen_directory = gr.State(None) # the directory where generation results are saved, used to trigger the download of results as zip file
@@ -49,54 +46,29 @@ with gr.Blocks(title="RFD3 Test") as demo:
49
  # inputs from user
50
  with gr.Row():
51
  with gr.Column(scale=1): # Left half
52
- gr.Markdown("Set up the configuration for your run through a valid yaml file or by manually setting minimal parameters for an unconditional run.")
53
- with gr.Tabs() as config_tabs:
54
- with gr.TabItem("Upload Config") as upload_tab: # upload a config yaml or json
55
- config_upload = gr.File(label="Config file: .yaml or .json", file_types=[".pdb", ".yaml", ".json"])
56
- num_designs_per_batch_upload = gr.Number(
57
- value=2,
58
- label="Number of Designs per Batch",
59
- precision=0,
60
- minimum=1,
61
- maximum=8
62
- )
63
- num_batches_upload = gr.Number(
64
- value=5,
65
- label="Number of Batches",
66
- precision=0,
67
- minimum=1,
68
- maximum=10
69
- )
70
- with gr.TabItem("Manual Config") as manual_tab: # minimal config for testing unconditional generation
71
- num_designs_per_batch = gr.Number(
72
- value=2,
73
- label="Number of Designs per Batch",
74
- precision=0,
75
- minimum=1,
76
- maximum=8
77
- )
78
- num_batches = gr.Number(
79
- value=5,
80
- label="Number of Batches",
81
- precision=0,
82
- minimum=1,
83
- maximum=10
84
- )
85
- length = gr.Number(
86
- value=40,
87
- label="Length of Protein (number of residues)",
88
- precision=0,
89
- minimum=10,
90
- maximum=200
91
- )
92
  config_validation_btn = gr.Button("Validate Config")
93
  config_textbox = gr.Textbox(value ="Waiting for config validation...")
94
 
95
  with gr.Column(scale=1): # Right half
96
  gr.Markdown("Upload your target/scaffold structure as a PDB file to condition the generation. Press 'No Scaffold/Target' if you want to run an unconditional generation.")
97
- with gr.Tabs():
98
- with gr.TabItem("Scaffold PDB"):
99
- scaffold_upload = gr.File(label="Target/Scaffold PDB", file_types=[".pdb"])
100
  with gr.Row():
101
  scaffold_validation_btn = gr.Button("Validate Scaffold")
102
  no_input_btn = gr.Button("No Scaffold/Target")
@@ -105,18 +77,14 @@ with gr.Blocks(title="RFD3 Test") as demo:
105
  runtextbox = gr.Textbox(value="Waiting for generation run...")
106
 
107
 
108
- # keep track of which tab is selected to determine whether to use uploaded config or manual config parameters for the generation run
109
- upload_tab.select(lambda: "upload", outputs=tab_selected)
110
- manual_tab.select(lambda: "manual", outputs=tab_selected)
111
 
112
  # validate the configuration
113
- config_validation_btn.click(validate_config_ready, inputs=[tab_selected, config_upload, num_designs_per_batch, num_batches, length, num_designs_per_batch_upload, num_batches_upload], outputs=[config_textbox, config_ready])
114
  scaffold_validation_btn.click(validate_scaffold_ready_with_file, inputs=scaffold_upload, outputs=[scaffold_textbox, scaffold_ready])
115
  no_input_btn.click(lambda: ("No scaffold/target will be used. Ready for unconditional generation!", "no_input"), outputs=[scaffold_textbox, scaffold_ready])
116
 
117
  output_file = gr.File(label="Download RFD3 results as zip", visible=True)
118
- #
119
- #
120
  # Section to inspect PDB of generated structures
121
  with gr.Row():
122
  batch_dropdown = gr.Dropdown(
@@ -134,18 +102,17 @@ with gr.Blocks(title="RFD3 Test") as demo:
134
  display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
135
  display_state.value = "Please Select a Batch and Design number to show sequence"
136
 
137
- def generate(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload, num_designs_per_batch_upload, num_batches_upload):
138
  if config_ready is None or scaffold_ready is None:
139
  return None, None
140
  if config_ready == "upload" and scaffold_ready == "no_input":
141
- gen_directory, gen_results = unconditional_generation_with_input_config(config_upload, num_batches_upload, num_designs_per_batch_upload)
142
- return gen_directory, gen_results
143
- if config_ready=="manual" and scaffold_ready=="no_input":
144
- gen_directory, gen_results = unconditional_generation(num_batches, num_designs_per_batch, length)
145
  return gen_directory, gen_results
 
 
146
 
147
- run_btn.click(give_run_status, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload], outputs=runtextbox).then(
148
- generate, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload, num_designs_per_batch_upload, num_batches_upload], outputs=[gen_directory, gen_results]
149
  ).then(
150
  update_batch_choices,
151
  inputs=gen_results,
 
38
 
39
  gr.Image("assets/overview_rfd3_baker.png", width=600)
40
 
 
 
 
41
  config_ready = gr.State(None) # whether the config is ready for running generation, takes values None, "manual", or "upload"
42
  scaffold_ready = gr.State(None) # whether the scaffold is ready for running generation, takes values None, "upload", or "no_input"
43
  gen_directory = gr.State(None) # the directory where generation results are saved, used to trigger the download of results as zip file
 
46
  # inputs from user
47
  with gr.Row():
48
  with gr.Column(scale=1): # Left half
49
+ gr.Markdown("Set up the configuration for your run through a valid yaml file. Choose the number of batches and designs per batch for your run.")
50
+ config_upload = gr.File(label="Config file: .yaml or .json", file_types=[".pdb", ".yaml", ".json"])
51
+ num_designs_per_batch = gr.Number(
52
+ value=2,
53
+ label="Number of Designs per Batch",
54
+ precision=0,
55
+ minimum=1,
56
+ maximum=8
57
+ )
58
+ num_batches= gr.Number(
59
+ value=5,
60
+ label="Number of Batches",
61
+ precision=0,
62
+ minimum=1,
63
+ maximum=10
64
+ )
65
+
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
66
  config_validation_btn = gr.Button("Validate Config")
67
  config_textbox = gr.Textbox(value ="Waiting for config validation...")
68
 
69
  with gr.Column(scale=1): # Right half
70
  gr.Markdown("Upload your target/scaffold structure as a PDB file to condition the generation. Press 'No Scaffold/Target' if you want to run an unconditional generation.")
71
+ scaffold_upload = gr.File(label="Target/Scaffold PDB", file_types=[".pdb"])
 
 
72
  with gr.Row():
73
  scaffold_validation_btn = gr.Button("Validate Scaffold")
74
  no_input_btn = gr.Button("No Scaffold/Target")
 
77
  runtextbox = gr.Textbox(value="Waiting for generation run...")
78
 
79
 
 
 
 
80
 
81
  # validate the configuration
82
+ config_validation_btn.click(validate_config_ready, inputs=[config_upload, num_designs_per_batch, num_batches], outputs=[config_textbox, config_ready])
83
  scaffold_validation_btn.click(validate_scaffold_ready_with_file, inputs=scaffold_upload, outputs=[scaffold_textbox, scaffold_ready])
84
  no_input_btn.click(lambda: ("No scaffold/target will be used. Ready for unconditional generation!", "no_input"), outputs=[scaffold_textbox, scaffold_ready])
85
 
86
  output_file = gr.File(label="Download RFD3 results as zip", visible=True)
87
+
 
88
  # Section to inspect PDB of generated structures
89
  with gr.Row():
90
  batch_dropdown = gr.Dropdown(
 
102
  display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
103
  display_state.value = "Please Select a Batch and Design number to show sequence"
104
 
105
+ def generate(config_ready, scaffold_ready, num_batches, num_designs_per_batch, config_upload):
106
  if config_ready is None or scaffold_ready is None:
107
  return None, None
108
  if config_ready == "upload" and scaffold_ready == "no_input":
109
+ gen_directory, gen_results = unconditional_generation_with_input_config(config_upload, num_batches, num_designs_per_batch)
 
 
 
110
  return gen_directory, gen_results
111
+ else:
112
+ return None, None
113
 
114
+ run_btn.click(give_run_status, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, config_upload], outputs=runtextbox).then(
115
+ generate, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, config_upload], outputs=[gen_directory, gen_results]
116
  ).then(
117
  update_batch_choices,
118
  inputs=gen_results,
utils/handle_events.py CHANGED
@@ -1,5 +1,6 @@
1
  import gradio as gr
2
  from utils.handle_files import *
 
3
 
4
  def update_batch_choices(result):
5
  """
@@ -58,38 +59,33 @@ def show_pdb(batch, design, result):
58
  print(pdb_str)
59
  return gr.update(value=f"Selected Batch: {batch}, Design: {design}, saved at {pdb_path}:\n {pdb_str}", visible=True)
60
 
61
- def validate_config_ready(tab_selected, config_upload, num_designs_per_batch, num_batches, length, num_designs_per_batch_upload, num_batches_upload):
62
  """
63
  Once the user presses on the Validate Config button, this function checks whether the config is really ready to go.
64
- It is ready, either if the user has selected the manual config tab, or if they have uploaded a config file in the upload config tab and have it open.
65
 
66
  Parameters:
67
  ----------
68
- tab_selected: str or gr.State
69
- takes the value "manual" or "upload" depending on which config tab the user has selected, used to determine whether to check for uploaded config file or not.
70
  config_upload: gr.File
71
  uploaded config file, is None if no file is uploaded
72
- numbers: list of gr.Number
73
- list of gr.Number input components for the manual config parameters, used to check that all parameters are filled.
 
 
74
 
75
  Returns:
76
  -------
77
  str: message to the user about the status of the config validation
78
  str: status string. "manual" if manual config is selected and valid, "upload" if upload, and None if config is not ready for generation.
79
  """
80
-
81
- if tab_selected == "manual":
82
- for num in [num_designs_per_batch, num_batches, length]:
83
  if num is None:
84
  return "Please fill in all the parameters for manual config to be ready for generation.", None
85
- return "Manual parameters selected and valid!", "manual"
86
- elif tab_selected == "upload" and config_upload is None:
87
- return "Please upload a config file or switch to manual config for uncondition generation.", None
88
- elif tab_selected == "upload" and config_upload is not None:
89
- for num in [num_designs_per_batch_upload, num_batches_upload]:
90
- if num is None:
91
- return "Please specify the number of batches and designs per batch for your configuration based on the uploaded config file", None
92
- return "Config file uploaded and valid! Number of batches and designs validated!", "upload"
93
 
94
  def validate_scaffold_ready_with_file(scaffold_upload):
95
  """
@@ -110,7 +106,7 @@ def validate_scaffold_ready_with_file(scaffold_upload):
110
  else:
111
  return "Please upload a scaffold file or press 'No Scaffold/Target' for unconditional generation.", None
112
 
113
- def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload):
114
  """
115
  Once the user presses on the Run Generation button, this function checks whether both config and scaffold are ready, and gives a status message about the generation run that is about to happen. If both config and scaffold are not ready, it prompts the user to ensure they are both validated before running the generation.
116
 
@@ -137,9 +133,7 @@ def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_b
137
  """
138
  if config_ready is None or scaffold_ready is None:
139
  return gr.update(value="Please ensure both config and scaffold are validated before running the generation.")
140
- elif config_ready=="manual" and scaffold_ready=="no_input":
141
- return gr.update(value=f"Running unconditional generation with minimal configuration: {num_batches} batches of {num_designs_per_batch} designs each, length = {length} aa")
142
  elif config_ready == "upload" and scaffold_ready == "no_input":
143
- return gr.update(value=f"Running unconditional generation with uploaded config file {config_upload}")
144
  else:
145
  return gr.update(value=f"Not implemented yet")
 
1
  import gradio as gr
2
  from utils.handle_files import *
3
+ import os
4
 
5
  def update_batch_choices(result):
6
  """
 
59
  print(pdb_str)
60
  return gr.update(value=f"Selected Batch: {batch}, Design: {design}, saved at {pdb_path}:\n {pdb_str}", visible=True)
61
 
62
+ def validate_config_ready(config_upload, num_designs_per_batch, num_batches):
63
  """
64
  Once the user presses on the Validate Config button, this function checks whether the config is really ready to go.
65
+ It is ready if the config file is uploaded and the number of batches and designs per batch are specified.
66
 
67
  Parameters:
68
  ----------
69
+
 
70
  config_upload: gr.File
71
  uploaded config file, is None if no file is uploaded
72
+ num_designs_per_batch: gr.Number
73
+ number of designs per batch input by the user in the manual config.
74
+ num_batches: gr.Number
75
+ number of batches input by the user in the manual config.
76
 
77
  Returns:
78
  -------
79
  str: message to the user about the status of the config validation
80
  str: status string. "manual" if manual config is selected and valid, "upload" if upload, and None if config is not ready for generation.
81
  """
82
+ for num in [num_designs_per_batch, num_batches]:
 
 
83
  if num is None:
84
  return "Please fill in all the parameters for manual config to be ready for generation.", None
85
+ if config_upload is None:
86
+ return "Please upload a config file for the generation to be ready.", None
87
+ return "Config file uploaded and valid! Number of batches and designs validated!", "upload"
88
+
 
 
 
 
89
 
90
  def validate_scaffold_ready_with_file(scaffold_upload):
91
  """
 
106
  else:
107
  return "Please upload a scaffold file or press 'No Scaffold/Target' for unconditional generation.", None
108
 
109
+ def give_run_status(config_ready, scaffold_ready, num_batches, num_designs_per_batch, config_upload):
110
  """
111
  Once the user presses on the Run Generation button, this function checks whether both config and scaffold are ready, and gives a status message about the generation run that is about to happen. If both config and scaffold are not ready, it prompts the user to ensure they are both validated before running the generation.
112
 
 
133
  """
134
  if config_ready is None or scaffold_ready is None:
135
  return gr.update(value="Please ensure both config and scaffold are validated before running the generation.")
 
 
136
  elif config_ready == "upload" and scaffold_ready == "no_input":
137
+ return gr.update(value=f"Running unconditional generation for {num_batches} batches of {num_designs_per_batch}, config uploaded from file {os.path.basename(config_upload)}")
138
  else:
139
  return gr.update(value=f"Not implemented yet")
utils/pipelines.py CHANGED
@@ -134,8 +134,8 @@ def unconditional_generation_with_input_config(input_file, num_batches, num_desi
134
  if file_name.endswith(".cif.gz"):
135
  terms = file_name.split("_")
136
  model_index = terms.index("model")
137
- batch =model_index - 1
138
- design = model_index + 1
139
  cif_path = os.path.join(directory, file_name)
140
  pdb_path = mcif_gz_to_pdb(cif_path)
141
  results.append({"batch": batch, "design": design, "cif_path": cif_path, "pdb_path": pdb_path})
 
134
  if file_name.endswith(".cif.gz"):
135
  terms = file_name.split("_")
136
  model_index = terms.index("model")
137
+ batch = int(terms[model_index - 1])
138
+ design = int(terms[model_index + 1])
139
  cif_path = os.path.join(directory, file_name)
140
  pdb_path = mcif_gz_to_pdb(cif_path)
141
  results.append({"batch": batch, "design": design, "cif_path": cif_path, "pdb_path": pdb_path})