Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
WCawdell opened this issue Aug 4, 2023 · 2 comments
Open

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

WCawdell opened this issue Aug 4, 2023 · 2 comments

Comments

@WCawdell
Copy link

WCawdell commented Aug 4, 2023

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"pv_viewer_{title}.html", "w") as f:
f.write(''''''+"\n")
f.write(''''''+"\n")
f.write('''<title>Dengue Virus Methyl Transferase</title>'''+"\n")
f.write(''''''+"\n")
f.write(''''''+"\n")
f.write(''''''+"\n")
f.write('''

'''+"\n")
f.write(''''''+"\n")
f.write('''<script type='text/javascript' src='bio-pv.min.js'></script>'''+"\n")
f.write('''<script type='text/javascript'>'''+"\n")
f.write('''// override the default options with something less restrictive.'''+"\n")
f.write(''' var options = {'''+"\n")
f.write(''' width: 600,'''+"\n")
f.write(''' height: 600,'''+"\n")
f.write(''' antialias: true,'''+"\n")
f.write(''' quality : "high"'''+"\n")
f.write(''' };'''+"\n")
f.write('''// insert the viewer under the Dom element with id 'gl'.'''+"\n")
f.write(''' var viewer = pv.Viewer(document.getElementById('viewer'), options);'''+"\n")
f.write('''</script>'''+"\n")
f.write('''<script type='text/javascript'>'''+"\n")
f.write(''' function loadMethylTransferase() {'''+"\n")
f.write(''' // asynchronously load the PDB file for the dengue methyl transferase'''+"\n")
f.write(''' // from the server and display it in the viewer.'''+"\n")
f.write(''' pv.io.fetchPdb('4n14_pocket_H_with_data.pdb', function(structure) {'''+"\n")
f.write(''' // display the protein as cartoon, coloring the secondary structure'''+"\n")
f.write(''' // elements in a rainbow gradient.'''+"\n")
f.write(''' viewer.cartoon('protein', structure, { color : color.ssSuccession() });'''+"\n")
f.write(''' // there are two ligands in the structure, the co-factor S-adenosyl'''+"\n")
f.write(''' // homocysteine and the inhibitor ribavirin-5' triphosphate. They have'''+"\n")
f.write(''' // the three-letter codes SAH and RVP, respectively. Let's display them'''+"\n")
f.write(''' // with balls and sticks.'''+"\n")
f.write(''' var ligands = structure.select({ rnames : ['WR7'] });'''+"\n")
f.write(''' viewer.ballsAndSticks('ligands', ligands);'''+"\n")
f.write(''' viewer.centerOn(ligands);'''+"\n")
f.write(''' });'''+"\n")
f.write(''' }'''+"\n")
f.write(''' // load the methyl transferase once the DOM has finished loading. That's'''+"\n")
f.write(''' // the earliest point the WebGL context is available.'''+"\n")
f.write(''' document.addEventListener('DOMContentLoaded', loadMethylTransferase);'''+"\n")
f.write(''' </script>'''+"\n")

 
@mizuchi3
Copy link

mizuchi3 commented Aug 5, 2023

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
Copy link
Author

WCawdell commented Aug 7, 2023

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!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants