import gradio as gr
import gradio as gr
import os
def get_pdb(pdb_code="", filepath=""):
if pdb_code is None or pdb_code == "":
try:
return filepath.name
except AttributeError as e:
return None
else:
os.system(f"wget -qnc https://files.rcsb.org/view/{pdb_code}.pdb")
return f"{pdb_code}.pdb"
def read_mol(molpath):
with open(molpath, "r") as fp:
lines = fp.readlines()
mol = ""
for l in lines:
mol += l
return mol
def molecule(input_pdb):
mol = read_mol(input_pdb)
html ="""
PDBe Molstar - Helper functions
PDBe Mol* AlphaFold Demo
"""
return f""""""
def update(inp, file, request: gr.Request):
pdb_path = get_pdb(inp, file)
print("Request headers dictionary:", request.headers)
print("IP address:", request.client.host)
return molecule(pdb_path)
demo = gr.Blocks()
with demo:
gr.Markdown("# PDB viewer using Molstar")
gr.Markdown("""If using please cite
> David Sehnal, Sebastian Bittrich, Mandar Deshpande, Radka Svobodová, Karel Berka, Václav Bazgier, Sameer Velankar, Stephen K Burley, Jaroslav Koča, Alexander S Rose: Mol* Viewer: modern web app for 3D visualization and analysis of large biomolecular structures, Nucleic Acids Research, 2021; 10.1093/nar/gkab31.""")
with gr.Row():
with gr.Box():
inp = gr.Textbox(
placeholder="PDB Code or upload file below", label="Input structure"
)
file = gr.File(file_count="single")
gr.Examples(["2CBA", "6VXX"], inp)
btn = gr.Button("View structure")
mol = gr.HTML()
btn.click(fn=update, inputs=[inp, file], outputs=mol)
demo.launch()