t7morgen
vis
7d18a20
raw
history blame contribute delete
No virus
3.22 kB
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)