protein_binding_search / protein_viz.py
roni
per gene aggregation
33eb5d4
import requests
def render_html(pdb_id, chain):
if pdb_id is None or chain is None:
return ""
html = f"""
"<html>
<header>
<script src="https://3Dmol.org/build/3Dmol-min.js"></script>
<script src="https://3Dmol.org/build/3Dmol.ui-min.js"></script>
</header>
<body>
<div style="height: 400px; position: relative;" class="viewer_3Dmoljs"
data-pdb="{pdb_id}"
data-backgroundalpha="0.0"
data-style="cartoon:color=white"
data-select1="chain:{chain}"
data-zoomto="chain:{chain}"
data-style1="cartoon:color=spectrum"
data-spin="axis:y;speed:0.2"
/>
</body>
</html>
"""
iframe = f"""
<iframe style="width: 100%; height: 480px" name="protein-vis"
frameborder="0" srcdoc='{html}'></iframe>
"""
return iframe
def get_pdb_title(pdb_id: str):
url = f"https://data.rcsb.org/rest/v1/core/entry/{pdb_id}"
response = requests.get(url, timeout=1)
if response.ok:
data = response.json()
protein_name = data["struct"]["title"]
else:
protein_name = "Unknown"
return protein_name