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

fix how number of abtches and designs is passed to rfd3 CLI

Browse files
Files changed (3) hide show
  1. app.py +18 -4
  2. utils/handle_events.py +5 -2
  3. utils/pipelines.py +2 -2
app.py CHANGED
@@ -53,6 +53,20 @@ with gr.Blocks(title="RFD3 Test") as demo:
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
  with gr.TabItem("Manual Config") as manual_tab: # minimal config for testing unconditional generation
57
  num_designs_per_batch = gr.Number(
58
  value=2,
@@ -96,7 +110,7 @@ with gr.Blocks(title="RFD3 Test") as demo:
96
  manual_tab.select(lambda: "manual", outputs=tab_selected)
97
 
98
  # validate the configuration
99
- config_validation_btn.click(validate_config_ready, inputs=[tab_selected, config_upload, num_designs_per_batch, num_batches, length], outputs=[config_textbox, config_ready])
100
  scaffold_validation_btn.click(validate_scaffold_ready_with_file, inputs=scaffold_upload, outputs=[scaffold_textbox, scaffold_ready])
101
  no_input_btn.click(lambda: ("No scaffold/target will be used. Ready for unconditional generation!", "no_input"), outputs=[scaffold_textbox, scaffold_ready])
102
 
@@ -120,18 +134,18 @@ with gr.Blocks(title="RFD3 Test") as demo:
120
  display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
121
  display_state.value = "Please Select a Batch and Design number to show sequence"
122
 
123
- def generate(config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload):
124
  if config_ready is None or scaffold_ready is None:
125
  return None, None
126
  if config_ready == "upload" and scaffold_ready == "no_input":
127
- gen_directory, gen_results = unconditional_generation_with_input_config(config_upload)
128
  return gen_directory, gen_results
129
  if config_ready=="manual" and scaffold_ready=="no_input":
130
  gen_directory, gen_results = unconditional_generation(num_batches, num_designs_per_batch, length)
131
  return gen_directory, gen_results
132
 
133
  run_btn.click(give_run_status, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload], outputs=runtextbox).then(
134
- generate, inputs=[config_ready, scaffold_ready, num_batches, num_designs_per_batch, length, config_upload], outputs=[gen_directory, gen_results]
135
  ).then(
136
  update_batch_choices,
137
  inputs=gen_results,
 
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,
 
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
 
 
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,
utils/handle_events.py CHANGED
@@ -58,7 +58,7 @@ 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):
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.
@@ -86,7 +86,10 @@ def validate_config_ready(tab_selected, config_upload, num_designs_per_batch, nu
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
- return "Config file uploaded and valid!", "upload"
 
 
 
90
 
91
  def validate_scaffold_ready_with_file(scaffold_upload):
92
  """
 
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.
 
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
  """
utils/pipelines.py CHANGED
@@ -99,7 +99,7 @@ def unconditional_generation(num_batches, num_designs_per_batch, length):
99
  raise RuntimeError(f"Error during generation: {str(e)}")
100
 
101
  @spaces.GPU(duration=300)
102
- def unconditional_generation_with_input_config(input_file):
103
  """
104
  Runs an unconditional generation with the specified input config file. Saves the generated structures to a timestamped directory in the outputs folder and returns the path to the directory along with a list of the generated structures' file paths.
105
 
@@ -124,7 +124,7 @@ def unconditional_generation_with_input_config(input_file):
124
 
125
  try:
126
 
127
- command = f"rfd3 design inputs={input_file} out_dir={directory}"
128
  print(f"Running command: {command}")
129
  subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
130
 
 
99
  raise RuntimeError(f"Error during generation: {str(e)}")
100
 
101
  @spaces.GPU(duration=300)
102
+ def unconditional_generation_with_input_config(input_file, num_batches, num_designs_per_batch):
103
  """
104
  Runs an unconditional generation with the specified input config file. Saves the generated structures to a timestamped directory in the outputs folder and returns the path to the directory along with a list of the generated structures' file paths.
105
 
 
124
 
125
  try:
126
 
127
+ command = f"rfd3 design inputs={input_file} out_dir={directory} n_batches={num_batches} diffusion_batch_size={num_designs_per_batch}"
128
  print(f"Running command: {command}")
129
  subprocess.run(command, shell=True, check=True, capture_output=True, text=True)
130