simonduerr commited on
Commit
fb25f9c
·
verified ·
1 Parent(s): a53eb47

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +10 -5
app.py CHANGED
@@ -8,7 +8,7 @@ from gradio_moleculeview import moleculeview
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(json.loads(view_str))
@@ -19,8 +19,12 @@ def predict(input_mol, view_str, chains):
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
- 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")
23
-
 
 
 
 
24
  #read content of file
25
  with open("outline_all.svg", "r") as f:
26
  return f.read(), "outline_all.svg"
@@ -31,6 +35,7 @@ def predict(input_mol, view_str, chains):
31
 
32
  with gr.Blocks() as demo:
33
  gr.Markdown("# PDB2Vector")
 
34
  inp = moleculeview(label="Molecule3D")
35
 
36
  view_str = gr.Textbox("viewMatrixResult", label="View Matrix", visible=False)
@@ -42,8 +47,8 @@ with gr.Blocks() as demo:
42
  out_file = gr.File(label="Download SVG")
43
  btn.click(None, [], [view_str, chains], js="() => [document.getElementById('viewMatrixResult').value, document.getElementById('chains').value]") #
44
  # on change of chains trigger, rendering
45
- view_str.change(predict, [inp, view_str, chains], [html, out_file])
46
- chains.change(predict, [inp, view_str, chains], [html, out_file])
47
 
48
 
49
  if __name__ == "__main__":
 
8
 
9
  import cellscape
10
 
11
+ def predict(input_mol, style, view_str, chains):
12
  # write view to file
13
  with open("view_matrix", "w") as f:
14
  f.write(json.loads(view_str))
 
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
+ if style == "Goodsell3D":
23
+ os.system(f"cellscape cartoon --pdb {input_mol.name} --outline residue --depth_shading --depth_lines --colors {chain_str} --depth flat --back_outline --view view_matrix --save outline_all.svg")
24
+ elif style == "Cartoon":
25
+ os.system(f"cellscape cartoon --pdb {input_mol.name} --outline residue --depth_contour_interval 10 --colors {chain_str} --depth contours --back_outline --view view_matrix --save outline_all.svg")
26
+ else:
27
+ 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")
28
  #read content of file
29
  with open("outline_all.svg", "r") as f:
30
  return f.read(), "outline_all.svg"
 
35
 
36
  with gr.Blocks() as demo:
37
  gr.Markdown("# PDB2Vector")
38
+ style = gr.Radio(values=["Flat", "Contour", "Goodsell3D"], label="Style")
39
  inp = moleculeview(label="Molecule3D")
40
 
41
  view_str = gr.Textbox("viewMatrixResult", label="View Matrix", visible=False)
 
47
  out_file = gr.File(label="Download SVG")
48
  btn.click(None, [], [view_str, chains], js="() => [document.getElementById('viewMatrixResult').value, document.getElementById('chains').value]") #
49
  # on change of chains trigger, rendering
50
+ view_str.change(predict, [inp, style, view_str, chains], [html, out_file])
51
+ chains.change(predict, [inp, style, view_str, chains], [html, out_file])
52
 
53
 
54
  if __name__ == "__main__":