biasmv / pv

WebGL protein viewer
https://pv.readthedocs.org
MIT License
319 stars 86 forks source link

Using Python CGI to create PV instances on the fly #195

Open WCawdell opened 1 year ago

WCawdell commented 1 year ago

I would like to use some Python code to write PV instances on the fly for my website. So far I have written the code to create a new .html file for a given PDB file, with the PV code. I believe it's all correct but unfortunately the PV window on the website is blank. I've attached the new HTML file function below:

def PV_Viewer_Page_Writer(title): with open(f"pvviewer{title}.html", "w") as f: f.write(''''''+"\n") f.write(''''''+"\n") f.write('''Dengue Virus Methyl Transferase'''+"\n") f.write(''''''+"\n") f.write(''''''+"\n") f.write(''''''+"\n") f.write('''

'''+"\n") f.write(''''''+"\n") f.write(''''''+"\n") f.write(''''''+"\n") f.write(''''''+"\n")

mizuchi3 commented 1 year ago

The code will work, you simply need an element in the page with id='viewer'.

Also note that browsers will not load this directly from your PC with a file browser for security reasons, you would need to run at least a simple python -m http.server and view the page via http://localhost:8000

WCawdell commented 1 year ago

Thank you very much for your reply.

I currently use this line of code to embed the PV instance into an inline frame of my page:

print('<iframe src="pv_viewer_220_alt_pose_3.html" height="600" width="600" name="menu" title="menu"></iframe>')

Do I need to use a div with id='viewer' inside the iframe? Or do I need to ditch the iframes entirely? I used iframes before I properly understood divs and I could get rid of them if they're causing an issue.

Cheers!