simonduerr commited on
Commit
10b1be2
·
verified ·
1 Parent(s): db8bc43

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -5
app.py CHANGED
@@ -1,30 +1,49 @@
1
 
 
 
 
2
  import gradio as gr
3
  from gradio_moleculeview import moleculeview
4
 
5
 
6
-
7
 
8
  def predict(input_mol, view_str, chains):
9
- return "svg"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
10
 
11
 
12
 
13
 
14
 
15
  with gr.Blocks() as demo:
16
- gr.Markdown("# Molecule3D")
17
  inp = moleculeview(label="Molecule3D")
18
 
19
  view_str = gr.Textbox("viewMatrixResult", label="View Matrix", visible=False)
20
  chains = gr.Textbox("chainsResult", label="Chains", visible=False)
21
 
22
 
23
- btn = gr.Button("Predict")
24
  html = gr.HTML("")
 
25
  btn.click(None, [], [view_str, chains], js="() => [document.getElementById('viewMatrixResult').value, document.getElementById('chains').value]") #
26
  # on change of chains trigger, rendering
27
- chains.change(predict, [inp, view_str, chains], html)
28
 
29
 
30
  if __name__ == "__main__":
 
1
 
2
+ import os
3
+ import json
4
+
5
  import gradio as gr
6
  from gradio_moleculeview import moleculeview
7
 
8
 
9
+ import cellscape
10
 
11
  def predict(input_mol, view_str, chains):
12
+ # write view to file
13
+ with open("view_matrix", "w") as f:
14
+ f.write(view_str)
15
+
16
+ chain_str = ""
17
+ chain_dict = json.reads(chains)
18
+
19
+ # sort keys in dict and add colors to chain_str
20
+ for chain in sorted(chain_dict.keys()):
21
+ chain_str += f" {chain_dict[chain]}"
22
+
23
+ os.system(f"cellscape cartoon --pdb {input_mol.name} --outline chain --colors {chain_str} --depth flat --back_outline --view view_matrix --save outline_all.svg")
24
+
25
+ #read content of file
26
+ with open("outline_all.svg", "r") as f:
27
+ return f.read(), "outline_all.svg"
28
 
29
 
30
 
31
 
32
 
33
  with gr.Blocks() as demo:
34
+ gr.Markdown("# PDB2Vector")
35
  inp = moleculeview(label="Molecule3D")
36
 
37
  view_str = gr.Textbox("viewMatrixResult", label="View Matrix", visible=False)
38
  chains = gr.Textbox("chainsResult", label="Chains", visible=False)
39
 
40
 
41
+ btn = gr.Button("Vectorize")
42
  html = gr.HTML("")
43
+ out_file = gr.File(label="Download SVG")
44
  btn.click(None, [], [view_str, chains], js="() => [document.getElementById('viewMatrixResult').value, document.getElementById('chains').value]") #
45
  # on change of chains trigger, rendering
46
+ chains.change(predict, [inp, view_str, chains], [html, out_file])
47
 
48
 
49
  if __name__ == "__main__":