gabboud commited on
Commit
5d306a8
·
1 Parent(s): 65e7711

fix interface of Molecule3D after testing

Browse files
Files changed (2) hide show
  1. app.py +37 -24
  2. utils/pipelines.py +3 -1
app.py CHANGED
@@ -54,57 +54,70 @@ with gr.Blocks(title="RFD3 Test") as demo:
54
  gen_directory = gr.State(None)
55
  gen_results = gr.State(None)
56
  gen_btn = gr.Button("Run Unconditional Generation")
57
- #gen_output = gr.Textbox(label="Generation Result")
58
- gen_btn.click(unconditional_generation, inputs=[num_batches, num_designs_per_batch, length], outputs=[gen_directory, gen_results])
59
 
60
 
61
  # New visualize section
62
  with gr.Row():
63
- viz_btn = gr.Button("Visualize", visible=True)
64
  batch_dropdown = gr.Dropdown(
65
  choices=[],
66
  label="Select Batch",
67
- visible=False
68
  )
69
  design_dropdown = gr.Dropdown(
70
  choices=[],
71
  label="Select Design",
72
- visible=False
73
  )
74
- viewer = Molecule3D(visible=False)
 
 
 
 
75
 
76
- def toggle_visualize(result):
77
  if result is None:
78
- return gr.Dropdown(visible=False), gr.Dropdown(visible=False), Molecule3D(visible=False)
79
  batches = sorted(list({d["batch"] for d in result}))
80
- return (
81
- gr.update(choices=batches, visible=True), # Batch dropdown
82
- gr.update(choices=[], visible=True), # Design empty initially
83
- gr.update(visible=False)
84
- )
 
 
 
 
85
 
86
  def update_designs(batch, result):
87
  if batch is None:
88
  return gr.update(choices=[])
89
  designs = sorted(list({d["design"] for d in result if d["batch"] == batch}))
90
  return gr.update(choices=designs)
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
91
 
92
  def load_viewer(batch, design, result):
93
  if batch is None or design is None:
94
- return gr.update(visible=False)
95
  pdb_data = next(d["pdb"] for d in result if d["batch"] == int(batch) and d["design"] == int(design))
96
  return gr.update(value=pdb_data, visible=True, reps=[{"style": "cartoon"}]) # Customize style
97
 
98
- # Events
99
- viz_btn.click(toggle_visualize, inputs=gen_directory, outputs=[batch_dropdown, design_dropdown, viewer])
100
- batch_dropdown.change(update_designs, inputs=[batch_dropdown, gen_directory], outputs=design_dropdown)
101
- batch_dropdown.select(fn=update_designs, inputs=[batch_dropdown, gen_directory], outputs=design_dropdown) # For selection
102
- gr.Dropdown.select(update_designs, batch_dropdown, design_dropdown).then( # Chain
103
- lambda b, d, r: load_viewer(b, d, r),
104
- inputs=[batch_dropdown, design_dropdown, gen_directory],
105
- outputs=viewer
106
- )
107
-
108
 
109
  if __name__ == "__main__":
110
  demo.launch()
 
54
  gen_directory = gr.State(None)
55
  gen_results = gr.State(None)
56
  gen_btn = gr.Button("Run Unconditional Generation")
57
+
58
+
59
 
60
 
61
  # New visualize section
62
  with gr.Row():
 
63
  batch_dropdown = gr.Dropdown(
64
  choices=[],
65
  label="Select Batch",
66
+ visible=True
67
  )
68
  design_dropdown = gr.Dropdown(
69
  choices=[],
70
  label="Select Design",
71
+ visible=True
72
  )
73
+ visualize_btn = gr.Button("Visualize", visible=True)
74
+
75
+ display_state = gr.Textbox(label="Selected Batch and Design", visible=True)
76
+ display_state.value = "Please Select a Batch and Design number to visualize."
77
+ viewer = Molecule3D(visible=True)
78
 
79
+ def update_batch_choices(result):
80
  if result is None:
81
+ return gr.Dropdown(choices = [])
82
  batches = sorted(list({d["batch"] for d in result}))
83
+ return gr.update(choices=batches, visible=True)
84
+
85
+ gen_btn.click(unconditional_generation, inputs=[num_batches, num_designs_per_batch, length], outputs=[gen_directory, gen_results]).then(
86
+ update_batch_choices,
87
+ inputs=gen_results,
88
+ outputs=batch_dropdown)
89
+
90
+
91
+
92
 
93
  def update_designs(batch, result):
94
  if batch is None:
95
  return gr.update(choices=[])
96
  designs = sorted(list({d["design"] for d in result if d["batch"] == batch}))
97
  return gr.update(choices=designs)
98
+
99
+
100
+
101
+ batch_dropdown.change(update_designs, inputs=[batch_dropdown, gen_results], outputs=[design_dropdown])
102
+ design_dropdown.change()
103
+
104
+ def visualize_selection(batch, design):
105
+ if batch is None or design is None:
106
+ return gr.update(value="**Please select both batch and design.**", visible=True)
107
+ return gr.update(value=f"**Selected Batch: {batch}, Design: {design}**", visible=True)
108
+
109
+
110
+
111
+ visualize_btn.click(visualize_selection, inputs=[batch_dropdown, design_dropdown], outputs=display_state)
112
+
113
 
114
  def load_viewer(batch, design, result):
115
  if batch is None or design is None:
116
+ return gr.update()
117
  pdb_data = next(d["pdb"] for d in result if d["batch"] == int(batch) and d["design"] == int(design))
118
  return gr.update(value=pdb_data, visible=True, reps=[{"style": "cartoon"}]) # Customize style
119
 
120
+ visualize_btn.click(load_viewer, inputs=[batch_dropdown, design_dropdown, gen_results], outputs=viewer)
 
 
 
 
 
 
 
 
 
121
 
122
  if __name__ == "__main__":
123
  demo.launch()
utils/pipelines.py CHANGED
@@ -104,4 +104,6 @@ def mcif_gz_to_pdb_string_gemmi(file_path: str) -> str:
104
  """
105
  st = gemmi.read_structure(file_path)
106
  st.setup_entities() # Recommended for consistent entity handling [web:18]
107
- return st.make_pdb_string(gemmi.PdbWriteOptions(minimal=True))
 
 
 
104
  """
105
  st = gemmi.read_structure(file_path)
106
  st.setup_entities() # Recommended for consistent entity handling [web:18]
107
+ pdb_path = file_path.replace(".cif.gz", ".pdb")
108
+ st.write_minimal_pdb(pdb_path)
109
+ return pdb_path