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) x = ( """
""" ) return f"""""" def update(inp, file): pdb_path = get_pdb(inp, file) return molecule(pdb_path) demo = gr.Blocks() with demo: gr.Markdown("# PDB viewer using 3Dmol.js") gr.Markdown("""If using please cite: > 3Dmol.js: molecular visualization with WebGL, Nicholas Rego, David Koes , Bioinformatics, Volume 31, Issue 8, April 2015, Pages 1322–1324, https://doi.org/10.1093/bioinformatics/btu829""") 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()