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, public_link): print(input_pdb) print(public_link+'/file='+os.path.basename(input_pdb)) link = public_link+"/file="+os.path.basename(input_pdb) x =""" PDBe Molstar - Helper functions
""" return f"""""" def update(inp, file, public_link): pdb_path = get_pdb(inp, file) print("public link", public_link) return molecule(pdb_path, public_link) demo = gr.Blocks() with demo: gr.Markdown("# PDB viewer using Mol*") 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.""") public_link = gr.Variable(value="https://simonduerr-molstar-gradio.hf.space") 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, public_link], outputs=mol) _, _, pl = demo.launch() # use public link with share=True locally