File size: 3,216 Bytes
7d18a20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
import gradio as gr
import py3Dmol
from Bio.PDB import *
import numpy as np
from Bio.PDB import PDBParser
import pandas as pd
import os, sys
#sys.path.append(os.getcwd())
print('importing...')
from run_gfn import run_gfn2
print('done')
# JavaScript functions
resid_hover = """function(atom,viewer) {{
    if(!atom.label) {{
        atom.label = viewer.addLabel('{0}:'+atom.atom+atom.serial,
            {{position: atom, backgroundColor: 'mintcream', fontColor:'black'}});
    }}
}}"""
hover_func = """
function(atom,viewer) {
    if(!atom.label) {
        atom.label = viewer.addLabel(atom.interaction,
            {position: atom, backgroundColor: 'black', fontColor:'white'});
    }
}"""
unhover_func = """
function(atom,viewer) {
    if(atom.label) {
        viewer.removeLabel(atom.label);
        delete atom.label;
    }
}"""


def predict(input_id, input_file):


    input_f = open(input_file.name, "r").read()
    input_format = input_file.name.split('.')[-1]
    
    #with open('geometry.'+input_format, "w") as oF:
    #    oF.write(input_f)
    #
    #input_f2 = open('geometry.'+input_format, "r").read()
    #print(len(input_f),len(input_f))
    #for c in range(len(input_f)):
    #    if input_f[c] != input_f2[c]:
    #        print(input_f[c], input_f2[c])

    gfn2_output = run_gfn2(["filename","geom=cyclohexane."+input_format])
    print(gfn2_output)
    charges = gfn2_output["fetchatomicprops"]["charges"]
    


    view = py3Dmol.view(width=600, height=400)
    view.setBackgroundColor('white')
    view.addModel(input_f, input_format)
    view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': 'turquoise'}}})
    #view.setStyle({'stick': {'colorscheme': {'prop': 'resi', 'C': '#cccccc'}},'cartoon': {'color': '#4c4e9e', 'alpha':"0.6"}})
    view.zoomTo()

    output = view._make_html().replace("'", '"')
    print("got a view")
    x = f"""<!DOCTYPE html><html> {output} </html>"""  # do not use ' in this input
    return f"""<iframe  style="width: 100%; height:420px" name="result" allow="midi; geolocation; microphone; camera; 
    display-capture; encrypted-media;" sandbox="allow-modals allow-forms 
    allow-scripts allow-same-origin allow-popups 
    allow-top-navigation-by-user-activation allow-downloads" allowfullscreen="" 
    allowpaymentrequest="" frameborder="0" srcdoc='{x}'></iframe>"""   

print('run 1')
callback = gr.CSVLogger()
with gr.Blocks() as demo:
    gr.Markdown("# Protein Adaptability Prediction")
    
    #text_input = gr.Textbox()
    #text_output = gr.Textbox()
    #text_button = gr.Button("Flip")
    inp = gr.Textbox(placeholder="PDB Code or upload file below", label="Input structure")
    pdb_file = gr.File(label="PDB File Upload")
    #with gr.Row():
    #    helix = gr.ColorPicker(label="helix")
    #    sheet = gr.ColorPicker(label="sheet")
    #    loop = gr.ColorPicker(label="loop")
    single_btn = gr.Button(label="Run")
    with gr.Row():
        html = gr.HTML()
    with gr.Row():
        dataframe = gr.Dataframe()
            
    single_btn.click(fn=predict, inputs=[inp, pdb_file], outputs=[html])

#out_d = run_gfn2("geom=cyclohexane.xyz")


#demo.launch(debug=True)
demo.launch(server_name="0.0.0.0", server_port=7860)