File size: 2,073 Bytes
8adb95d
10b1be2
 
 
8adb95d
 
 
 
10b1be2
8adb95d
fb25f9c
10b1be2
 
4fab10d
10b1be2
 
551d6ff
10b1be2
 
 
ba0c8e7
fb25f9c
 
 
 
 
 
10b1be2
 
 
8adb95d
 
 
 
 
 
10b1be2
fb25f9c
8adb95d
 
 
 
 
 
10b1be2
8adb95d
10b1be2
8adb95d
 
fb25f9c
 
8adb95d
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56

import os
import json

import gradio as gr
from gradio_moleculeview import moleculeview


import cellscape

def predict(input_mol, style, view_str, chains):
    # write view to file
    with open("view_matrix", "w") as f:
        f.write(json.loads(view_str))

    chain_str = ""
    chain_dict = json.loads(chains)

    # sort keys in dict and add colors to chain_str
    for chain in sorted(chain_dict.keys()):
        chain_str += f" '{chain_dict[chain]}'"
    if style == "Goodsell3D":
        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")
    elif style == "Cartoon":
        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")
    else:
        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")
    #read content of file
    with open("outline_all.svg", "r") as f:
        return f.read(), "outline_all.svg"





with gr.Blocks() as demo:
    gr.Markdown("# PDB2Vector")
    style = gr.Radio(values=["Flat", "Contour", "Goodsell3D"], label="Style")
    inp = moleculeview(label="Molecule3D")

    view_str = gr.Textbox("viewMatrixResult", label="View Matrix", visible=False)
    chains = gr.Textbox("chainsResult", label="Chains", visible=False) 
    

    btn = gr.Button("Vectorize")
    html = gr.HTML("")
    out_file = gr.File(label="Download SVG")
    btn.click(None, [], [view_str, chains], js="() => [document.getElementById('viewMatrixResult').value, document.getElementById('chains').value]")  #
    # on change of chains trigger, rendering
    view_str.change(predict, [inp, style, view_str, chains], [html, out_file])
    chains.change(predict, [inp, style, view_str, chains], [html, out_file])
    

if __name__ == "__main__":
    demo.launch()