|
import os |
|
import time |
|
import py3Dmol |
|
import gradio as gr |
|
|
|
|
|
def display_pdb_by_pdb(pdb): |
|
|
|
|
|
view = py3Dmol.view(width=500, height=500) |
|
view.addModel(pdb, "pdb") |
|
view.setStyle({'cartoon': {'color': 'spectrum'}}) |
|
|
|
view.zoomTo() |
|
output = view._make_html().replace("'", '"') |
|
x = f"""<!DOCTYPE html><html></center> {output} </center></html>""" |
|
|
|
return f"""<iframe height="500px" width="100%" 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>""" |
|
|
|
|
|
def show_gif(): |
|
path = 'output' |
|
pdb_files = sorted(os.listdir(path), key=lambda x: int(x.split('_')[1])) |
|
num = len(pdb_files) |
|
i = 0 |
|
while True: |
|
if i >= num: break |
|
time.sleep(0.5) |
|
p = os.path.join(path, pdb_files[i]) |
|
with open(p,'r') as f: |
|
f_pdb = f.readlines() |
|
|
|
i += 1 |
|
yield display_pdb_by_pdb(''.join(f_pdb)), pdb_files[i] |
|
|
|
|
|
|
|
if __name__ == "__main__": |
|
title = "Artificial Intelligence Generated Protein" |
|
|
|
css = "footer {visibility: hidden}" |
|
|
|
with gr.Blocks(title=title, css=css) as demo: |
|
output_viewer = gr.HTML() |
|
with gr.Row(): |
|
gif = gr.HTML() |
|
it = gr.Textbox(label="Iteraton") |
|
btn3 = gr.Button("GIF") |
|
btn3.click(show_gif, [], [gif, it]) |
|
|
|
demo.queue() |
|
demo.launch(show_api=False, server_name="0.0.0.0") |
|
|