You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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")
The text was updated successfully, but these errors were encountered:
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
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.
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):
'''+"\n")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('''
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")
The text was updated successfully, but these errors were encountered: