File size: 1,252 Bytes
1d25e2a
 
 
dfecb5b
79b6488
 
dfecb5b
 
 
 
 
 
 
 
 
79b6488
 
dfecb5b
79b6488
dfecb5b
c3ff85a
dfecb5b
 
 
 
 
 
 
 
 
1d25e2a
 
33eb5d4
1d25e2a
 
 
 
b2a3d53
1d25e2a
b2a3d53
1d11011
1d25e2a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
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