-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapp.py
58 lines (45 loc) · 1.76 KB
/
app.py
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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import streamlit as st
from stmol import showmol
import py3Dmol
import requests
import biotite.structure.io as bsio
st.sidebar.title('ESM-Stream')
def render_mol(pdb):
pdbview = py3Dmol.view()
pdbview.addModel(pdb,'pdb')
pdbview.setStyle({'cartoon':{'color':'spectrum'}})
pdbview.setBackgroundColor('white')
pdbview.zoomTo()
pdbview.zoom(2, 800)
pdbview.spin(True)
showmol(pdbview, height = 500,width=800)
DEFAULT_SEQ = "KVFGRCELAAAMKRHGLDNYRGYSLGNWVCAAKFESNFNTQATNRNTDGSTDYGILQINSRWWCNDGRTPGSRNLCNIPCSALLSSDITASVNCAKKIVSDGNGMNAWVAWRNRCKGTDVQAWIRGCRL"
txt = st.sidebar.text_area('Input sequence', DEFAULT_SEQ, height=275)
def update(sequence=txt):
headers = {
'Content-Type': 'application/x-www-form-urlencoded',
}
response = requests.post('https://api.esmatlas.com/foldSequence/v1/pdb/', headers=headers, data=sequence)
if response.status_code != 200:
st.warning("Unable to predict protein structure. Please try again later.")
return
name = sequence[:3] + sequence[-3:]
pdb_string = response.content.decode('utf-8')
with open('predicted.pdb', 'w') as f:
f.write(pdb_string)
struct = bsio.load_structure('predicted.pdb', extra_fields=["b_factor"])
b_value = round(struct.b_factor.mean(), 4)
st.subheader('Visualization of predicted protein structure')
render_mol(pdb_string)
st.subheader('plDDT')
st.write('plDDT is the confidence in prediction on a scale from 0-100.')
st.info(f'plDDT: {b_value * 100}')
st.download_button(
label="Download PDB",
data=pdb_string,
file_name='predicted.pdb',
mime='text/plain',
)
predict = st.sidebar.button('Predict', on_click=update)
if not predict:
st.warning('Enter protein sequence')