|
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 |
|
|
|
print('importing...') |
|
from run_gfn import run_gfn2 |
|
print('done') |
|
|
|
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] |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
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.zoomTo() |
|
|
|
output = view._make_html().replace("'", '"') |
|
print("got a view") |
|
x = f"""<!DOCTYPE html><html> {output} </html>""" |
|
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") |
|
|
|
|
|
|
|
|
|
inp = gr.Textbox(placeholder="PDB Code or upload file below", label="Input structure") |
|
pdb_file = gr.File(label="PDB File Upload") |
|
|
|
|
|
|
|
|
|
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]) |
|
|
|
|
|
|
|
|
|
|
|
demo.launch(server_name="0.0.0.0", server_port=7860) |
|
|